Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
1019:68ba074e260f | 1020:dfe34fad749d |
---|---|
630 isok = true; | 630 isok = true; |
631 } catch (e) { } | 631 } catch (e) { } |
632 | 632 |
633 if (isok) { | 633 if (isok) { |
634 try { | 634 try { |
635 execF(k, parse(xhr.responseText)); | 635 k(parse(xhr.responseText)); |
636 } catch (v) { | 636 } catch (v) { |
637 doExn(v); | 637 doExn(v); |
638 } | 638 } |
639 } else { | 639 } else { |
640 conn(); | 640 conn(); |
852 whine("Unknown Ur pattern kind" + p.c); | 852 whine("Unknown Ur pattern kind" + p.c); |
853 } | 853 } |
854 } | 854 } |
855 | 855 |
856 function exec0(env, e) { | 856 function exec0(env, e) { |
857 var stack = null; | 857 return exec1(env, null, e); |
858 } | |
859 | |
860 function exec1(env, stack, e) { | |
861 var stack, usedK = false; | |
858 | 862 |
859 var saveEnv = function() { | 863 var saveEnv = function() { |
860 if (stack.next != null && stack.next.data.c != "<") | 864 if (stack.next != null && stack.next.data.c != "<") |
861 stack = cons({c: "<", env: env}, stack.next); | 865 stack = cons({c: "<", env: env}, stack.next); |
862 else | 866 else |
881 stack = stack.next; | 885 stack = stack.next; |
882 break; | 886 break; |
883 case "f": | 887 case "f": |
884 fr.args[fr.pos++] = v; | 888 fr.args[fr.pos++] = v; |
885 if (fr.a == null) { | 889 if (fr.a == null) { |
890 stack = stack.next; | |
886 e = {c: "c", v: fr.f.apply(null, fr.args)}; | 891 e = {c: "c", v: fr.f.apply(null, fr.args)}; |
887 stack = stack.next; | 892 if (usedK) return null; |
888 } else { | 893 } else { |
889 e = fr.a.data; | 894 e = fr.a.data; |
890 fr.a = fr.a.next; | 895 fr.a = fr.a.next; |
891 } | 896 } |
892 break; | 897 break; |
1012 break; | 1017 break; |
1013 case "wc": | 1018 case "wc": |
1014 env = e.env; | 1019 env = e.env; |
1015 e = e.body; | 1020 e = e.body; |
1016 break; | 1021 break; |
1022 case "K": | |
1023 { var savedStack = stack.next, savedEnv = env; | |
1024 e = {c: "c", v: function(v) { return exec1(savedEnv, savedStack, {c: "c", v: v}); } };} | |
1025 usedK = true; | |
1026 break; | |
1017 default: | 1027 default: |
1018 whine("Unknown Ur expression kind " + e.c); | 1028 whine("Unknown Ur expression kind " + e.c); |
1019 } | 1029 } |
1020 } | 1030 } |
1021 } | 1031 } |