comparison lib/js/urweb.js @ 975:8fe576c0bee9

Quoting JavaScript working
author Adam Chlipala <adamc@hcoop.net>
date Tue, 22 Sep 2009 15:12:09 -0400
parents b851675a2c3d
children 68eda5b0636d
comparison
equal deleted inserted replaced
974:b851675a2c3d 975:8fe576c0bee9
179 closures[n] = null; 179 closures[n] = null;
180 freeClosures = cons(n, freeClosures); 180 freeClosures = cons(n, freeClosures);
181 } 181 }
182 182
183 function cr(n) { 183 function cr(n) {
184 return closures[n](); 184 return closures[n];
185 } 185 }
186 186
187 function flatten(cls, tr) { 187 function flatten(cls, tr) {
188 if (tr.cat1 != null) 188 if (tr.cat1 != null)
189 return flatten(cls, tr.cat1) + flatten(cls, tr.cat2); 189 return flatten(cls, tr.cat1) + flatten(cls, tr.cat2);
861 if (fr.a == null) { 861 if (fr.a == null) {
862 e = {c: "c", v: fr.f.apply(null, fr.args)}; 862 e = {c: "c", v: fr.f.apply(null, fr.args)};
863 stack = stack.next; 863 stack = stack.next;
864 } else { 864 } else {
865 e = fr.a.data; 865 e = fr.a.data;
866 if (e == null) alert("Oh no!");
866 fr.a = fr.a.next; 867 fr.a = fr.a.next;
867 } 868 }
868 break; 869 break;
869 case "a1": 870 case "a1":
870 e = fr.x; 871 e = fr.x;
981 case "m": 982 case "m":
982 stack = cons({c: "m", p: e.p}, stack); 983 stack = cons({c: "m", p: e.p}, stack);
983 e = e.e; 984 e = e.e;
984 break; 985 break;
985 case "e": 986 case "e":
986 var env0 = env; 987 e = {c: "c", v: cs({c: "wc", env: env, body: e.e})};
987 var e0 = e.e; 988 break;
988 e = {c: "c", v: cs(function() { return exec0(env0, e0); })}; 989 case "wc":
990 env = e.env;
991 e = e.body;
989 break; 992 break;
990 default: 993 default:
991 throw ("Unknown Ur expression kind " + e.c); 994 throw ("Unknown Ur expression kind " + e.c);
992 } 995 }
993 } 996 }
994 } 997 }
995 998
996 function exec(e) { 999 function exec(e) {
997 var r = exec0(null, e); 1000 var r = exec0(null, e);
998 1001
999 if (r != null && r.body) 1002 if (r != null && r.body != null)
1000 return function(v) { return exec0(cons(v, r.env), r.body); }; 1003 return function(v) { return exec0(cons(v, r.env), r.body); };
1001 else 1004 else
1002 return r; 1005 return r;
1003 } 1006 }
1004 1007