diff options
author | Adam Chlipala <adamc@hcoop.net> | 2009-03-08 13:41:55 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2009-03-08 13:41:55 -0400 |
commit | d8d9309a0242408460488de0c44029d74c7b3113 (patch) | |
tree | 340a1e5251d1a16874ce49b5edf487714f45ff7b | |
parent | 654a4218e5122728bcd17bf3cc85e575cdd4fbdc (diff) |
RPC returning an option
-rw-r--r-- | src/cjr_print.sml | 50 | ||||
-rw-r--r-- | src/jscomp.sml | 2 | ||||
-rw-r--r-- | tests/rpcO.ur | 25 | ||||
-rw-r--r-- | tests/rpcO.urp | 5 |
4 files changed, 53 insertions, 29 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml index 73024aa5..aff5efd3 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -1087,42 +1087,36 @@ fun urlify env t = newline] end - | TOption t => box [] - (*box [string "(request[0] == '/' ? ++request : request, ", - string "((!strncmp(request, \"None\", 4) ", - string "&& (request[4] == 0 || request[4] == '/')) ", - string "? (request += 4, NULL) ", - string ": ((!strncmp(request, \"Some\", 4) ", - string "&& request[4] == '/') ", - string "? (request += 5, ", - if isUnboxable t then - unurlify' rf (#1 t) - else - box [string "({", + | TOption t => + box [string "if (it", + string (Int.toString level), + string ") {", + if isUnboxable t then + box [string "uw_write(ctx, \"Some/\");", newline, - p_typ env t, - space, - string "*tmp", - space, - string "=", + urlify' rf level t] + else + box [p_typ env t, space, - string "uw_malloc(ctx, sizeof(", - p_typ env t, - string "));", - newline, - string "*tmp", + string "it", + string (Int.toString (level + 1)), space, string "=", space, - unurlify' rf (#1 t), + string "*it", + string (Int.toString level), string ";", newline, - string "tmp;", + string "uw_write(ctx, \"Some/\");", newline, - string "})"], - string ") :", - space, - string "(uw_error(ctx, FATAL, \"Error unurlifying option type\"), NULL))))"]*) + urlify' rf (level + 1) t, + string ";", + newline], + string "} else {", + box [string "uw_write(ctx, \"None\");", + newline], + string "}", + newline] | _ => (ErrorMsg.errorAt loc "Unable to choose a URL encoding function"; space) diff --git a/src/jscomp.sml b/src/jscomp.sml index 1a85bba2..23b6e936 100644 --- a/src/jscomp.sml +++ b/src/jscomp.sml @@ -338,7 +338,7 @@ fun process file = @ ["}"]), st) end - | TFfi ("Basis", "string") => ("decode(t[i++])", st) + | TFfi ("Basis", "string") => ("unescape(t[i++])", st) | TFfi ("Basis", "int") => ("parseInt(t[i++])", st) | TFfi ("Basis", "float") => ("parseFloat(t[i++])", st) diff --git a/tests/rpcO.ur b/tests/rpcO.ur new file mode 100644 index 00000000..bc4b430e --- /dev/null +++ b/tests/rpcO.ur @@ -0,0 +1,25 @@ +table t : {A : int} + +fun main () : transaction page = + let + fun check () = + r <- oneRow (SELECT SUM(t.A) AS X FROM t); + return (if r.X < 0 then + (Some 3, None) + else + (None, Some "Hi")) + + fun show (t ::: Type) (_ : show t) (opt : option t) = + case opt of + None => <xml>None</xml> + | Some v => <xml>{[v]}</xml> + in + s <- source (None, None); + return <xml><body> + <button value="Get It On!" + onclick={r <- check (); + set s r}/><br/> + <br/> + Current: <dyn signal={p <- signal s; return <xml>{show p.1}, {show p.2}</xml>}/> + </body></xml> + end diff --git a/tests/rpcO.urp b/tests/rpcO.urp new file mode 100644 index 00000000..3a511580 --- /dev/null +++ b/tests/rpcO.urp @@ -0,0 +1,5 @@ +debug +sql rpcO.sql +database dbname=rpco + +rpcO |