# HG changeset patch # User Adam Chlipala # Date 1322924410 18000 # Node ID 43f22a8f76cc939430736da56b59a63a8eddeed2 # Parent 15e0c935c91bb2c06d49bd7b009c3b5bcdc1d09a Allow sources to be returned by RPCs diff -r 15e0c935c91b -r 43f22a8f76cc include/urweb.h --- a/include/urweb.h Sat Dec 03 09:44:07 2011 -0500 +++ b/include/urweb.h Sat Dec 03 10:00:10 2011 -0500 @@ -121,6 +121,7 @@ char *uw_Basis_urlifyBool(uw_context, uw_Basis_bool); char *uw_Basis_urlifyTime(uw_context, uw_Basis_time); char *uw_Basis_urlifyChannel(uw_context, uw_Basis_channel); +char *uw_Basis_urlifySource(uw_context, uw_Basis_source); uw_unit uw_Basis_urlifyInt_w(uw_context, uw_Basis_int); uw_unit uw_Basis_urlifyFloat_w(uw_context, uw_Basis_float); @@ -128,6 +129,7 @@ uw_unit uw_Basis_urlifyBool_w(uw_context, uw_Basis_bool); uw_unit uw_Basis_urlifyTime_w(uw_context, uw_Basis_time); uw_unit uw_Basis_urlifyChannel_w(uw_context, uw_Basis_channel); +uw_unit uw_Basis_urlifySource_w(uw_context, uw_Basis_source); uw_Basis_unit uw_Basis_unurlifyUnit(uw_context ctx, char **s); uw_Basis_int uw_Basis_unurlifyInt(uw_context, char **); diff -r 15e0c935c91b -r 43f22a8f76cc lib/js/urweb.js --- a/lib/js/urweb.js Sat Dec 03 09:44:07 2011 -0500 +++ b/lib/js/urweb.js Sat Dec 03 10:00:10 2011 -0500 @@ -976,6 +976,10 @@ return null; } +function parseSource(s1, s2) { + return eval("s" + s1 + "_" + s2); +} + function uf(s) { if (s.length == 0) return "_"; diff -r 15e0c935c91b -r 43f22a8f76cc src/c/urweb.c --- a/src/c/urweb.c Sat Dec 03 09:44:07 2011 -0500 +++ b/src/c/urweb.c Sat Dec 03 10:00:10 2011 -0500 @@ -1762,6 +1762,16 @@ return "1"; } +char *uw_Basis_urlifySource(uw_context ctx, uw_Basis_source src) { + char *r; + int len; + uw_check_heap(ctx, 2 * INTS_MAX + 2); + r = ctx->heap.front; + sprintf(r, "%d/%llu%n", src.context, src.source, &len); + ctx->heap.front += len+1; + return r; +} + static void uw_Basis_urlifyInt_w_unsafe(uw_context ctx, uw_Basis_int n) { int len; @@ -1843,6 +1853,16 @@ return uw_unit_v; } +uw_unit uw_Basis_urlifySource_w(uw_context ctx, uw_Basis_source src) { + int len; + + uw_check(ctx, 2 * INTS_MAX + 2); + sprintf(ctx->page.front, "%d/%llu%n", src.context, src.source, &len); + ctx->page.front += len; + + return uw_unit_v; +} + static char *uw_unurlify_advance(char *s) { char *new_s = strchr(s, '/'); diff -r 15e0c935c91b -r 43f22a8f76cc src/jscomp.sml --- a/src/jscomp.sml Sat Dec 03 09:44:07 2011 -0500 +++ b/src/jscomp.sml Sat Dec 03 10:00:10 2011 -0500 @@ -310,6 +310,8 @@ | TFfi ("Basis", "bool") => ("t[i++] == \"1\"", st) + | TSource => ("parseSource(t[i++], t[i++])", st) + | TOption t => let val (e, st) = unurlifyExp loc (t, st) diff -r 15e0c935c91b -r 43f22a8f76cc tests/rpcSource.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/rpcSource.ur Sat Dec 03 10:00:10 2011 -0500 @@ -0,0 +1,13 @@ +fun remote () = + s <- source ; + return (s, ) + +fun main () : transaction page = + x <- source ; + return + +
+