diff lib/js/urweb.js @ 1020:dfe34fad749d

RPC uses VM support for call/cc
author Adam Chlipala <adamc@hcoop.net>
date Sun, 25 Oct 2009 14:07:10 -0400
parents 2cd8c1aa0d3a
children 7a4a55e05081
line wrap: on
line diff
--- a/lib/js/urweb.js	Sun Oct 25 13:12:24 2009 -0400
+++ b/lib/js/urweb.js	Sun Oct 25 14:07:10 2009 -0400
@@ -632,7 +632,7 @@
 
       if (isok) {
         try {
-          execF(k, parse(xhr.responseText));
+          k(parse(xhr.responseText));
         } catch (v) {
           doExn(v);
         }
@@ -854,7 +854,11 @@
 }
 
 function exec0(env, e) {
-  var stack = null;
+  return exec1(env, null, e);
+}
+
+function exec1(env, stack, e) {
+  var stack, usedK = false;
 
   var saveEnv = function() {
     if (stack.next != null && stack.next.data.c != "<")
@@ -883,8 +887,9 @@
       case "f":
         fr.args[fr.pos++] = v;
         if (fr.a == null) {
+          stack = stack.next;
           e = {c: "c", v: fr.f.apply(null, fr.args)};
-          stack = stack.next;
+          if (usedK) return null;
         } else {
           e = fr.a.data;
           fr.a = fr.a.next;
@@ -1014,6 +1019,11 @@
       env = e.env;
       e = e.body;
       break;
+    case "K":
+      { var savedStack = stack.next, savedEnv = env;
+      e = {c: "c", v: function(v) { return exec1(savedEnv, savedStack, {c: "c", v: v}); } };}
+      usedK = true;
+      break;      
     default:
       whine("Unknown Ur expression kind " + e.c);
     }