Mercurial > urweb
changeset 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 | 733f67bb64e7 |
files | lib/js/urweb.js tests/jscomp.ur tests/jscomp.urp tests/jscomp.urs |
diffstat | 4 files changed, 26 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/js/urweb.js Tue Sep 22 12:23:21 2009 -0400 +++ b/lib/js/urweb.js Tue Sep 22 13:23:27 2009 -0400 @@ -834,15 +834,20 @@ } break; case "a1": - if (v == null || !v.body) - throw "Ur: applying non-function"; - stack = cons({c: "a2", env: v.env, body: v.body}, stack.next); e = fr.x; + stack = cons({c: "a2", f: v}, stack.next); break; case "a2": - stack = cons({c: "a3", env: env}, stack.next); - env = cons(v, fr.env); - e = fr.body; + if (fr.f == null) + throw "Ur: applying null function"; + else if (fr.f.body) { + stack = cons({c: "a3", env: env}, stack.next); + env = cons(v, fr.f.env); + e = fr.f.body; + } else { + e = {c: "c", v: fr.f(v)}; + stack = stack.next; + } break; case "a3": env = fr.env; @@ -886,7 +891,7 @@ e = {c: "c", v: lookup(env, e.n)}; break; case "n": - e = {c: "c", v: urfuncs[e.n]}; + e = urfuncs[e.n]; break; case "s": stack = cons({c: "s"}, stack);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jscomp.ur Tue Sep 22 13:23:27 2009 -0400 @@ -0,0 +1,10 @@ +fun main () = + s <- source ""; + + return <xml><body> + <ctextbox source={s}/><br/> + + <button value="Echo" onclick={s <- get s; alert s}/> + <button value="+1" onclick={s <- get s; alert (show (readError s + 1))}/> + <button value="*3" onclick={s <- get s; alert (show ((readError s) * 3))}/> + </body></xml>