# HG changeset patch # User Adam Chlipala # Date 1215995045 14400 # Node ID 91027db5a07cb31c7158d610d694272343eb01de # Parent 6230bdd122e71100cb9376db60121e63d9612aa2 Multiple arguments to web functions diff -r 6230bdd122e7 -r 91027db5a07c src/cjr.sml --- 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 diff -r 6230bdd122e7 -r 91027db5a07c src/cjr_env.sml --- 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 diff -r 6230bdd122e7 -r 91027db5a07c src/cjr_print.sml --- 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 "{", diff -r 6230bdd122e7 -r 91027db5a07c src/cjrize.sml --- 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) diff -r 6230bdd122e7 -r 91027db5a07c src/monoize.sml --- 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 diff -r 6230bdd122e7 -r 91027db5a07c tests/plink2.lac --- /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 => + Hello World! + + +val main = fn () => +
  • Size 5
  • +
  • Size 10
  • +