# HG changeset patch # User Adam Chlipala # Date 1238871336 14400 # Node ID 7ea0df9e56b6b342449a5f3022a044fad89aa7fc # Parent 655bcc9b77e0ca27fab5d418585616128fee9b75 spawn diff -r 655bcc9b77e0 -r 7ea0df9e56b6 include/urweb.h --- a/include/urweb.h Sat Apr 04 14:03:39 2009 -0400 +++ b/include/urweb.h Sat Apr 04 14:55:36 2009 -0400 @@ -49,7 +49,7 @@ uw_unit uw_Basis_set_client_source(uw_context, uw_Basis_int, uw_Basis_string); void uw_set_script_header(uw_context, const char*); -const char *uw_Basis_get_settings(uw_context, uw_Basis_string); +const char *uw_Basis_get_settings(uw_context, uw_unit); const char *uw_Basis_get_script(uw_context, uw_unit); void uw_set_needs_push(uw_context, int); diff -r 655bcc9b77e0 -r 7ea0df9e56b6 lib/ur/basis.urs --- a/lib/ur/basis.urs Sat Apr 04 14:03:39 2009 -0400 +++ b/lib/ur/basis.urs Sat Apr 04 14:55:36 2009 -0400 @@ -105,6 +105,7 @@ (** JavaScript-y gadgets *) val alert : string -> transaction unit +val spawn : transaction unit -> transaction unit (** Channels *) diff -r 655bcc9b77e0 -r 7ea0df9e56b6 src/c/urweb.c --- a/src/c/urweb.c Sat Apr 04 14:03:39 2009 -0400 +++ b/src/c/urweb.c Sat Apr 04 14:55:36 2009 -0400 @@ -701,17 +701,16 @@ } } -const char *uw_Basis_get_settings(uw_context ctx, uw_Basis_string onload) { +const char *uw_Basis_get_settings(uw_context ctx, uw_unit u) { if (ctx->client == NULL) return ""; else { - char *r = uw_malloc(ctx, 52 + 3 * INTS_MAX + strlen(ctx->url_prefix) + strlen(onload)); - sprintf(r, " onload='client_id=%u;client_pass=%d;url_prefix=\"%s\";timeout=%d;listener();%s'", + char *r = uw_malloc(ctx, 59 + 3 * INTS_MAX + strlen(ctx->url_prefix)); + sprintf(r, "client_id=%u;client_pass=%d;url_prefix=\"%s\";timeout=%d;listener();", ctx->client->id, ctx->client->pass, ctx->url_prefix, - ctx->timeout, - onload); + ctx->timeout); return r; } } diff -r 655bcc9b77e0 -r 7ea0df9e56b6 src/jscomp.sml --- a/src/jscomp.sml Sat Apr 04 14:03:39 2009 -0400 +++ b/src/jscomp.sml Sat Apr 04 14:55:36 2009 -0400 @@ -50,7 +50,9 @@ (("Basis", "urlifyFloat"), "ts"), (("Basis", "urlifyString"), "uf"), (("Basis", "recv"), "rv"), - (("Basis", "strcat"), "cat")] + (("Basis", "strcat"), "cat"), + (("Basis", "intToString"), "ts"), + (("Basis", "floatToString"), "ts")] structure FM = BinaryMapFn(struct type ord_key = string * string diff -r 655bcc9b77e0 -r 7ea0df9e56b6 src/mono_reduce.sml --- a/src/mono_reduce.sml Sat Apr 04 14:03:39 2009 -0400 +++ b/src/mono_reduce.sml Sat Apr 04 14:55:36 2009 -0400 @@ -61,6 +61,7 @@ | EFfiApp ("Basis", "new_channel", _) => true | EFfiApp ("Basis", "subscribe", _) => true | EFfiApp ("Basis", "send", _) => true + | EFfiApp ("Basis", "recv", _) => true | EFfiApp _ => false | EApp ((EFfi _, _), _) => false | EApp _ => true @@ -281,11 +282,12 @@ | EFfiApp ("Basis", "new_channel", es) => ffi es | EFfiApp ("Basis", "subscribe", es) => ffi es | EFfiApp ("Basis", "send", es) => ffi es + | EFfiApp ("Basis", "recv", es) => ffi es | EFfiApp (_, _, es) => List.concat (map (summarize d) es) | EApp ((EFfi _, _), e) => summarize d e | EApp _ => let - fun unravel (e, ls) = + fun unravel (e, passed, ls) = case e of ENamed n => let @@ -294,10 +296,10 @@ case IM.find (absCounts, n) of NONE => [Unsure] | SOME len => - if length ls < len then + if passed < len then ls else - [Unsure] + ls @ [Unsure] end | ERel n => List.revAppend (ls, if n = d then @@ -305,10 +307,10 @@ else [Unsure]) | EApp (f, x) => - unravel (#1 f, summarize d x @ ls) + unravel (#1 f, passed + 1, summarize d x @ ls) | _ => [Unsure] in - unravel (e, []) + unravel (e, 0, []) end | EAbs (_, _, _, e) => List.filter (fn UseRel => true @@ -386,8 +388,8 @@ | EApp ((EAbs (x, t, _, e1), loc), e2) => ((*Print.prefaces "Considering" [("e1", MonoPrint.p_exp (E.pushERel env x t NONE) e1), - ("e2", MonoPrint.p_exp env e2), - ("sub", MonoPrint.p_exp env (reduceExp env (subExpInExp (0, e2) e1)))];*) + ("e2", MonoPrint.p_exp env e2), + ("sub", MonoPrint.p_exp env (reduceExp env (subExpInExp (0, e2) e1)))];*) if impure e2 then #1 (reduceExp env (ELet (x, t, e2, e1), loc)) else diff -r 655bcc9b77e0 -r 7ea0df9e56b6 src/monoize.sml --- a/src/monoize.sml Sat Apr 04 14:03:39 2009 -0400 +++ b/src/monoize.sml Sat Apr 04 14:55:36 2009 -0400 @@ -1043,6 +1043,13 @@ fm) end + | L.EFfiApp ("Basis", "spawn", [e]) => + let + val (e, fm) = monoExp (env, st, fm) e + in + ((L'.EApp (e, (L'.ERecord [], loc)), loc), fm) + end + | L.EApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "return"), _), _), _), t), _), (L.EFfi ("Basis", "signal_monad"), _)) => let @@ -2005,7 +2012,12 @@ end in normal ("body", - SOME (L'.EFfiApp ("Basis", "get_settings", [onload]), loc), + SOME (L'.EStrcat ((L'.EPrim (Prim.String " onload='"), loc), + (L'.EStrcat ((L'.EFfiApp ("Basis", "get_settings", + [(L'.ERecord [], loc)]), loc), + (L'.EStrcat (onload, + (L'.EPrim (Prim.String "'"), + loc)), loc)), loc)), loc), SOME (L'.EFfiApp ("Basis", "get_script", [(L'.ERecord [], loc)]), loc)) end diff -r 655bcc9b77e0 -r 7ea0df9e56b6 tests/spawn.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/spawn.ur Sat Apr 04 14:55:36 2009 -0400 @@ -0,0 +1,24 @@ +table t : {A : int, Ch : channel string} + +fun listener n ch = + s <- recv ch; + alert (show n ^ ": " ^ s); + listener n ch + +fun speak id msg = + r <- oneRow (SELECT t.Ch FROM t WHERE t.A = {[id]}); + send r.T.Ch msg + +fun main () : transaction page = + ch1 <- channel; + dml (INSERT INTO t (A, Ch) VALUES (1, {[ch1]})); + ch2 <- channel; + dml (INSERT INTO t (A, Ch) VALUES (2, {[ch2]})); + + s1 <- source ""; + s2 <- source ""; + + return + 1: