From 3398b403c53401d8161555c848f06bc65d045407 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 22 Sep 2009 13:23:27 -0400 Subject: Basic arithmetic working with interpretation --- lib/js/urweb.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/js/urweb.js b/lib/js/urweb.js index abdf2ab7..c11702a6 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -834,15 +834,20 @@ function exec0(env, e) { } break; case "a1": - if (v == null || !v.body) - throw "Ur: applying non-function"; - stack = cons({c: "a2", env: v.env, body: v.body}, stack.next); e = fr.x; + stack = cons({c: "a2", f: v}, stack.next); break; case "a2": - stack = cons({c: "a3", env: env}, stack.next); - env = cons(v, fr.env); - e = fr.body; + if (fr.f == null) + throw "Ur: applying null function"; + else if (fr.f.body) { + stack = cons({c: "a3", env: env}, stack.next); + env = cons(v, fr.f.env); + e = fr.f.body; + } else { + e = {c: "c", v: fr.f(v)}; + stack = stack.next; + } break; case "a3": env = fr.env; @@ -886,7 +891,7 @@ function exec0(env, e) { e = {c: "c", v: lookup(env, e.n)}; break; case "n": - e = {c: "c", v: urfuncs[e.n]}; + e = urfuncs[e.n]; break; case "s": stack = cons({c: "s"}, stack); -- cgit v1.2.3