comparison lib/js/urweb.js @ 978:e1f3f1ea8cff

demo/increment works with interpretation
author Adam Chlipala <adamc@hcoop.net>
date Thu, 24 Sep 2009 10:42:59 -0400
parents 2ecf308772ba
children 3612ff0c6a10
comparison
equal deleted inserted replaced
977:2ecf308772ba 978:e1f3f1ea8cff
616 } 616 }
617 617
618 xhr.send(null); 618 xhr.send(null);
619 } 619 }
620 620
621 function rc(uri, parse, k, needsSig) { 621 function rc(prefix, uri, parse, k, needsSig) {
622 uri = cat(prefix, uri);
622 uri = flattenLocal(uri); 623 uri = flattenLocal(uri);
623 var xhr = getXHR(); 624 var xhr = getXHR();
624 625
625 xhr.onreadystatechange = function() { 626 xhr.onreadystatechange = function() {
626 if (xhr.readyState == 4) { 627 if (xhr.readyState == 4) {
786 execF(execF(k, parse(msg)), null); 787 execF(execF(k, parse(msg)), null);
787 } catch (v) { 788 } catch (v) {
788 doExn(v); 789 doExn(v);
789 } 790 }
790 } 791 }
792 }
793
794 function sl(ms, k) {
795 window.setTimeout(function() { execF(k, null); }, ms);
791 } 796 }
792 797
793 798
794 // Key events 799 // Key events
795 800
852 857
853 function exec0(env, e) { 858 function exec0(env, e) {
854 var stack = null; 859 var stack = null;
855 860
856 while (true) { 861 while (true) {
857 if (!e.c)
858 throw ("Trace: " + trace);
859 trace += "|" + e.c;
860 switch (e.c) { 862 switch (e.c) {
861 case "c": 863 case "c":
862 var v = e.v; 864 var v = e.v;
863 if (stack == null) 865 if (stack == null)
864 return v; 866 return v;
877 fr.args[fr.pos++] = v; 879 fr.args[fr.pos++] = v;
878 if (fr.a == null) { 880 if (fr.a == null) {
879 e = {c: "c", v: fr.f.apply(null, fr.args)}; 881 e = {c: "c", v: fr.f.apply(null, fr.args)};
880 stack = stack.next; 882 stack = stack.next;
881 } else { 883 } else {
884 trace += "" + fr.pos;
882 e = fr.a.data; 885 e = fr.a.data;
883 fr.a = fr.a.next; 886 fr.a = fr.a.next;
884 } 887 }
885 break; 888 break;
886 case "a1": 889 case "a1":
889 break; 892 break;
890 case "a2": 893 case "a2":
891 if (fr.f == null) 894 if (fr.f == null)
892 throw "Ur: applying null function"; 895 throw "Ur: applying null function";
893 else if (fr.f.body) { 896 else if (fr.f.body) {
894 stack = cons({c: "a3", env: env}, stack.next); 897 stack = cons({c: "<", env: env}, stack.next);
895 env = cons(v, fr.f.env); 898 env = cons(v, fr.f.env);
896 e = fr.f.body; 899 e = fr.f.body;
897 } else { 900 } else {
898 e = {c: "c", v: fr.f(v)}; 901 e = {c: "c", v: fr.f(v)};
899 stack = stack.next; 902 stack = stack.next;
900 } 903 }
901 break; 904 break;
902 case "a3": 905 case "<":
903 env = fr.env; 906 env = fr.env;
904 stack = stack.next; 907 stack = stack.next;
905 break; 908 break;
906 case "r": 909 case "r":
907 fr.fs["_" + fr.n] = v; 910 fr.fs["_" + fr.n] = v;
921 case ";": 924 case ";":
922 e = fr.e2; 925 e = fr.e2;
923 stack = stack.next; 926 stack = stack.next;
924 break; 927 break;
925 case "=": 928 case "=":
926 stack = cons({c: "a3", env: env}, stack.next); 929 stack = cons({c: "<", env: env}, stack.next);
927 env = cons(v, env); 930 env = cons(v, env);
928 e = fr.e2; 931 e = fr.e2;
929 break; 932 break;
930 case "m": 933 case "m":
931 var ps; 934 var ps;
932 for (ps = fr.p; ps != null; ps = ps.next) { 935 for (ps = fr.p; ps != null; ps = ps.next) {
933 var r = execP(env, ps.data.p, v); 936 var r = execP(env, ps.data.p, v);
934 if (r != false) { 937 if (r != false) {
935 stack = cons({c: "a3", env: env}, stack.next); 938 stack = cons({c: "<", env: env}, stack.next);
936 env = r; 939 env = r;
937 e = ps.data.b; 940 e = ps.data.b;
938 break; 941 break;
939 } 942 }
940 } 943 }