# HG changeset patch # User Adam Chlipala # Date 1230825849 18000 # Node ID 35471f0679800965cfcf1995d71a544e3e10aeca # Parent 101eb0058136f2556c137a1a756b5ab010313d10 Reactive record pattern diff -r 101eb0058136 -r 35471f067980 jslib/urweb.js --- a/jslib/urweb.js Thu Jan 01 10:49:42 2009 -0500 +++ b/jslib/urweb.js Thu Jan 01 11:04:09 2009 -0500 @@ -2,7 +2,7 @@ return { n : ls, v : v }; } function callAll(ls) { - for (; ls; ls = ls.next) + for (; ls; ls = ls.n) ls.v(); } diff -r 101eb0058136 -r 35471f067980 src/jscomp.sml --- a/src/jscomp.sml Thu Jan 01 10:49:42 2009 -0500 +++ b/src/jscomp.sml Thu Jan 01 11:04:09 2009 -0500 @@ -154,13 +154,13 @@ ^ "\"") | _ => str (Prim.toString p) - fun jsPat inner (p, _) succ fail = + fun jsPat depth inner (p, _) succ fail = case p of PWild => succ - | PVar _ => strcat [str ("(_" ^ Int.toString (len + inner) ^ "=d,"), + | PVar _ => strcat [str ("(_" ^ Int.toString (len + inner) ^ "=d" ^ Int.toString depth ^ ","), succ, str ")"] - | PPrim p => strcat [str "(d==", + | PPrim p => strcat [str ("(d" ^ Int.toString depth ^ "=="), jsPrim p, str "?", succ, @@ -173,18 +173,21 @@ val (_, succ) = foldl (fn ((x, p, _), (inner, succ)) => (inner + E.patBindsN p, - jsPat inner p succ fail)) + strcat [str ("(d" ^ Int.toString (depth+1) ^ "=d" + ^ Int.toString depth ^ "._" ^ x ^ ","), + jsPat (depth+1) inner p succ fail, + str ")"])) (inner, succ) xps in succ end - | PNone _ => strcat [str "(d?", + | PNone _ => strcat [str ("(d" ^ Int.toString depth ^ "?"), fail, str ":", succ, str ")"] - | PSome (_, p) => strcat [str "(d?", - jsPat inner p succ fail, + | PSome (_, p) => strcat [str ("(d" ^ Int.toString depth ^ "?"), + jsPat depth inner p succ fail, str ":", fail, str ")"] @@ -285,7 +288,7 @@ let val locals = List.tabulate (varDepth e, - fn i => str ("var _" ^ Int.toString (len + inner + i) ^ ";")) + fn i => str ("var _" ^ Int.toString (len + inner + i + 1) ^ ";")) val (e, st) = jsE (inner + 1) (e, st) in (strcat (str ("function(_" @@ -369,7 +372,7 @@ str "pf()" else str ("c" ^ Int.toString (i+1) ^ "()") - val c = jsPat inner p e fail + val c = jsPat 0 inner p e fail in (strcat [str ("c" ^ Int.toString i ^ "=function(){return "), c, @@ -382,7 +385,7 @@ in (strcat (str "(" :: List.revAppend (cases, - [str "d=", + [str "d0=", e, str ",c0())"])), st) end diff -r 101eb0058136 -r 35471f067980 tests/stypes.ur --- a/tests/stypes.ur Thu Jan 01 10:49:42 2009 -0500 +++ b/tests/stypes.ur Thu Jan 01 11:04:09 2009 -0500 @@ -10,7 +10,11 @@ {[n + 1.0]}}/> Change
- {[p.1]}, {[p.2]}}/> Change
+ {[p.1]}, {[p.2]}}/>; + return Initial + | (fst, snd) => return {[fst]}, {[snd]}}/> + Change
return None