diff lib/js/urweb.js @ 971:c22e524a6dd3

Basic arithmetic working with interpretation
author Adam Chlipala <adamc@hcoop.net>
date Tue, 22 Sep 2009 13:23:27 -0400
parents 8371d12ae63f
children e30c2409c9d0
line wrap: on
line diff
--- a/lib/js/urweb.js	Tue Sep 22 12:23:21 2009 -0400
+++ b/lib/js/urweb.js	Tue Sep 22 13:23:27 2009 -0400
@@ -834,15 +834,20 @@
         }
         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 @@
       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);