Mercurial > urweb
changeset 121:91027db5a07c
Multiple arguments to web functions
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sun, 13 Jul 2008 20:24:05 -0400 (2008-07-14) |
parents | 6230bdd122e7 |
children | f7c6ceb87bbd |
files | src/cjr.sml src/cjr_env.sml src/cjr_print.sml src/cjrize.sml src/monoize.sml tests/plink2.lac |
diffstat | 6 files changed, 49 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cjr.sml Sun Jul 13 20:07:10 2008 -0400 +++ b/src/cjr.sml Sun Jul 13 20:24:05 2008 -0400 @@ -57,7 +57,7 @@ datatype decl' = DStruct of int * (string * typ) list | DVal of string * int * typ * exp - | DFun of string * int * string * typ * typ * exp + | DFun of string * int * (string * typ) list * typ * exp withtype decl = decl' located
--- a/src/cjr_env.sml Sun Jul 13 20:07:10 2008 -0400 +++ b/src/cjr_env.sml Sun Jul 13 20:24:05 2008 -0400 @@ -119,7 +119,12 @@ fun declBinds env (d, loc) = case d of DVal (x, n, t, _) => pushENamed env x n t - | DFun (fx, n, _, dom, ran, _) => pushENamed env fx n (TFun (dom, ran), loc) + | DFun (fx, n, args, ran, _) => + let + val t = foldl (fn ((_, arg), t) => (TFun (arg, t), loc)) ran args + in + pushENamed env fx n t + end | DStruct (n, xts) => pushStruct env n xts end
--- a/src/cjr_print.sml Sun Jul 13 20:07:10 2008 -0400 +++ b/src/cjr_print.sml Sun Jul 13 20:24:05 2008 -0400 @@ -149,19 +149,22 @@ space, p_exp env e, string ";"] - | DFun (fx, n, x, dom, ran, e) => + | DFun (fx, n, args, ran, e) => let - val env' = E.pushERel env x dom + val nargs = length args + val env' = foldl (fn ((x, dom), env) => E.pushERel env x dom) env args in box [string "static", space, p_typ env ran, space, string ("__lwn_" ^ fx ^ "_" ^ Int.toString n), - string "(lw_context ctx, ", - p_typ env dom, - space, - p_rel env' 0, + string "(", + p_list_sep (box [string ",", space]) (fn x => x) + (string "lw_context ctx" :: ListUtil.mapi (fn (i, (_, dom)) => + box [p_typ env dom, + space, + p_rel env' (nargs - i - 1)]) args), string ")", space, string "{",
--- a/src/cjrize.sml Sun Jul 13 20:07:10 2008 -0400 +++ b/src/cjrize.sml Sun Jul 13 20:24:05 2008 -0400 @@ -165,16 +165,27 @@ val (t, sm) = cifyTyp (t, sm) val (d, sm) = case #1 t of - L'.TFun (dom, ran) => - (case #1 e of - L.EAbs (ax, _, _, e) => - let - val (e, sm) = cifyExp (e, sm) - in - (L'.DFun (x, n, ax, dom, ran, e), sm) - end - | _ => (ErrorMsg.errorAt loc "Function isn't explicit at code generation"; - (L'.DVal ("", 0, t, (L'.EPrim (Prim.Int 0), ErrorMsg.dummySpan)), sm))) + L'.TFun _ => + let + fun unravel (tAll as (t, _), eAll as (e, _)) = + case (t, e) of + (L'.TFun (dom, ran), L.EAbs (ax, _, _, e)) => + let + val (args, t, e) = unravel (ran, e) + in + ((ax, dom) :: args, t, e) + end + | (L'.TFun _, _) => + (ErrorMsg.errorAt loc "Function isn't explicit at code generation"; + ([], tAll, eAll)) + | _ => ([], tAll, eAll) + + val (args, ran, e) = unravel (t, e) + val (e, sm) = cifyExp (e, sm) + in + (L'.DFun (x, n, args, ran, e), sm) + end + | _ => let val (e, sm) = cifyExp (e, sm)
--- a/src/monoize.sml Sun Jul 13 20:07:10 2008 -0400 +++ b/src/monoize.sml Sun Jul 13 20:24:05 2008 -0400 @@ -98,9 +98,10 @@ case (args, ft) of ([], _) => e | (arg :: args, (L'.TFun (t, ft), _)) => - (L'.EStrcat (e, - (L'.EStrcat ((L'.EPrim (Prim.String "/"), loc), - fooify (arg, t)), loc)), loc) + attrify (args, ft, + (L'.EStrcat (e, + (L'.EStrcat ((L'.EPrim (Prim.String "/"), loc), + fooify (arg, t)), loc)), loc)) | _ => (E.errorAt loc "Type mismatch encoding attribute"; e) in
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/plink2.lac Sun Jul 13 20:24:05 2008 -0400 @@ -0,0 +1,8 @@ +val pA = fn size1 => fn size2 => <html><body> + <font size={size1}>Hello</font> <font size={size2}>World!</font> +</body></html> + +val main = fn () => <html><body> + <li> <a link={pA 5 10}>Size 5</a></li> + <li> <a link={pA 10 5}>Size 10</a></li> +</body></html>