Mercurial > urweb
comparison 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 |
comparison
equal
deleted
inserted
replaced
970:8371d12ae63f | 971:c22e524a6dd3 |
---|---|
832 e = fr.a.data; | 832 e = fr.a.data; |
833 fr.a = fr.a.next; | 833 fr.a = fr.a.next; |
834 } | 834 } |
835 break; | 835 break; |
836 case "a1": | 836 case "a1": |
837 if (v == null || !v.body) | |
838 throw "Ur: applying non-function"; | |
839 stack = cons({c: "a2", env: v.env, body: v.body}, stack.next); | |
840 e = fr.x; | 837 e = fr.x; |
838 stack = cons({c: "a2", f: v}, stack.next); | |
841 break; | 839 break; |
842 case "a2": | 840 case "a2": |
843 stack = cons({c: "a3", env: env}, stack.next); | 841 if (fr.f == null) |
844 env = cons(v, fr.env); | 842 throw "Ur: applying null function"; |
845 e = fr.body; | 843 else if (fr.f.body) { |
844 stack = cons({c: "a3", env: env}, stack.next); | |
845 env = cons(v, fr.f.env); | |
846 e = fr.f.body; | |
847 } else { | |
848 e = {c: "c", v: fr.f(v)}; | |
849 stack = stack.next; | |
850 } | |
846 break; | 851 break; |
847 case "a3": | 852 case "a3": |
848 env = fr.env; | 853 env = fr.env; |
849 stack = stack.next; | 854 stack = stack.next; |
850 break; | 855 break; |
884 break; | 889 break; |
885 case "v": | 890 case "v": |
886 e = {c: "c", v: lookup(env, e.n)}; | 891 e = {c: "c", v: lookup(env, e.n)}; |
887 break; | 892 break; |
888 case "n": | 893 case "n": |
889 e = {c: "c", v: urfuncs[e.n]}; | 894 e = urfuncs[e.n]; |
890 break; | 895 break; |
891 case "s": | 896 case "s": |
892 stack = cons({c: "s"}, stack); | 897 stack = cons({c: "s"}, stack); |
893 e = e.v; | 898 e = e.v; |
894 break; | 899 break; |