summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2011-12-03 10:00:10 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2011-12-03 10:00:10 -0500
commit8e7573e9187d583bcc478676ad92dd94a9ba8387 (patch)
tree999270929063a6966b6a45583e091ce015e612b3
parent0f14aa67e5446391904c6a4d2ee7b4f00b803158 (diff)
Allow sources to be returned by RPCs
-rw-r--r--include/urweb.h2
-rw-r--r--lib/js/urweb.js4
-rw-r--r--src/c/urweb.c20
-rw-r--r--src/jscomp.sml2
-rw-r--r--tests/rpcSource.ur13
5 files changed, 41 insertions, 0 deletions
diff --git a/include/urweb.h b/include/urweb.h
index 219bc207..53f59c5a 100644
--- a/include/urweb.h
+++ b/include/urweb.h
@@ -121,6 +121,7 @@ char *uw_Basis_urlifyString(uw_context, uw_Basis_string);
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_urlifyString_w(uw_context, uw_Basis_string);
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 --git a/lib/js/urweb.js b/lib/js/urweb.js
index f05957a0..015befa6 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -976,6 +976,10 @@ function pflo(s) {
return null;
}
+function parseSource(s1, s2) {
+ return eval("s" + s1 + "_" + s2);
+}
+
function uf(s) {
if (s.length == 0)
return "_";
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 491fb73d..8ebd9a2f 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -1762,6 +1762,16 @@ char *uw_Basis_urlifyBool(uw_context ctx, uw_Basis_bool b) {
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 @@ uw_unit uw_Basis_urlifyBool_w(uw_context ctx, uw_Basis_bool b) {
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 --git a/src/jscomp.sml b/src/jscomp.sml
index 3e475899..16043ba5 100644
--- a/src/jscomp.sml
+++ b/src/jscomp.sml
@@ -310,6 +310,8 @@ fun process file =
| 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 --git a/tests/rpcSource.ur b/tests/rpcSource.ur
new file mode 100644
index 00000000..ad144cd6
--- /dev/null
+++ b/tests/rpcSource.ur
@@ -0,0 +1,13 @@
+fun remote () =
+ s <- source <xml/>;
+ return (s, <xml><dyn signal={signal s}/></xml>)
+
+fun main () : transaction page =
+ x <- source <xml/>;
+ return <xml><body>
+ <dyn signal={signal x}/>
+ <hr/>
+ <button onclick={p <- rpc (remote ());
+ set x p.2;
+ set p.1 <xml>Hi!</xml>}/>
+ </body></xml>