# HG changeset patch # User Adam Chlipala # Date 1232138950 18000 # Node ID b1064de2b1f9418dc40c2ca29bee05dce781f337 # Parent 1d34d916c206b60f9a8e80e0c542a7760adfe9e0 dlist example working diff -r 1d34d916c206 -r b1064de2b1f9 lib/js/urweb.js --- a/lib/js/urweb.js Tue Jan 13 15:23:48 2009 -0500 +++ b/lib/js/urweb.js Fri Jan 16 15:49:10 2009 -0500 @@ -37,26 +37,53 @@ return s; } -function myParent() { - var pos = document; - +function lastParent(pos) { while (pos.lastChild && pos.lastChild.nodeType == 1) pos = pos.lastChild; return pos.parentNode; } +var parents = null; + +function pushParent(node) { + parents = cons(node, parents); +} + +function popParent() { + if (parents) + parents = parents.n; + else + alert("popParent: stack underflow"); +} + +function curParent() { + return lastParent(parents ? parents.v : document); +} + +function populate(node, html) { + node.innerHTML = html; + + var scripts = node.getElementsByTagName("script"); + var len = scripts.length; + for (var i = 0; i < len; ++i) { + pushParent(scripts[i].parentNode); + eval(scripts[i].textContent); + popParent(); + } +} + function dyn(s) { var x = document.createElement("span"); x.innerHTML = s.v; - myParent().appendChild(x); - s.h = cons(function() { x.innerHTML = s.v }, s.h); + curParent().appendChild(x); + s.h = cons(function() { populate(x, s.v) }, s.h); } function inp(t, s) { var x = document.createElement(t); x.value = s.v; - myParent().appendChild(x); + curParent().appendChild(x); s.h = cons(function() { x.value = s.v }, s.h); x.onkeyup = function() { sv(s, x.value) }; } @@ -70,3 +97,15 @@ function pf() { alert("Pattern match failure") } +var closures = []; + +function ca(f) { + var n = closures.length; + closures[n] = f; + return n; +} + +function cr(n) { + return closures[n](); +} + diff -r 1d34d916c206 -r b1064de2b1f9 src/jscomp.sml --- a/src/jscomp.sml Tue Jan 13 15:23:48 2009 -0500 +++ b/src/jscomp.sml Fri Jan 16 15:49:10 2009 -0500 @@ -486,7 +486,6 @@ maxName = #maxName st} val (e, st) = jsExp mode skip [] 0 (e, st) - val () = Print.prefaces "Pre-e" [("e", MonoPrint.p_exp MonoEnv.empty e)] val e = deStrcat 0 e val sc = "_n" ^ Int.toString n ^ "=" ^ e ^ ";\n" @@ -759,7 +758,11 @@ end | EJavaScript (Source _, _, SOME _) => (e, st) - | EJavaScript (_, _, SOME e) => ((EFfiApp ("Basis", "jsifyString", [e]), loc), st) + | EJavaScript (_, _, SOME e) => + (strcat [str "\"cr(\"+ca(function(){return ", + e, + str "})+\")\""], + st) | EClosure _ => unsupported "EClosure" | EQuery _ => unsupported "Query" @@ -770,7 +773,10 @@ let val (e, st) = jsE inner (e, st) in - ((EFfiApp ("Basis", "jsifyString", [e]), loc), st) + (strcat [str "\"cr(\"+ca(function(){return ", + e, + str "})+\")\""], + st) end | ESignalReturn e => diff -r 1d34d916c206 -r b1064de2b1f9 src/monoize.sml --- a/src/monoize.sml Tue Jan 13 15:23:48 2009 -0500 +++ b/src/monoize.sml Fri Jan 16 15:49:10 2009 -0500 @@ -1910,9 +1910,9 @@ e), _), _)] => (e, fm) | [("Signal", e, _)] => ((L'.EStrcat - ((L'.EPrim (Prim.String ""), loc)), loc)), loc), + (L'.EPrim (Prim.String ")"), loc)), loc)), loc), fm) | _ => raise Fail "Monoize: Bad dyn attributes") @@ -1932,7 +1932,7 @@ loc)), loc), fm) end | SOME (_, src, _) => - (strcat [str ""], fm)) @@ -2002,7 +2002,7 @@ loc), fm) end | SOME (_, src, _) => - (strcat [str ""], fm)) diff -r 1d34d916c206 -r b1064de2b1f9 tests/dlist.ur --- a/tests/dlist.ur Tue Jan 13 15:23:48 2009 -0500 +++ b/tests/dlist.ur Fri Jan 16 15:49:10 2009 -0500 @@ -19,4 +19,5 @@ tl <- get s; s' <- source (Cons (hd, tl)); set s s'}/> +