diff options
author | Camil Staps | 2018-12-24 14:25:46 +0100 |
---|---|---|
committer | Camil Staps | 2018-12-24 14:25:46 +0100 |
commit | 8cf914defa8030c3beab450e00430959de845fc1 (patch) | |
tree | 6c4c5300c9f01b4b0948b7a8c2dd8a5af8c706e0 /sjit.icl | |
parent | Iterative development (diff) |
Remove Abstr; add fun_args
Diffstat (limited to 'sjit.icl')
-rw-r--r-- | sjit.icl | 23 |
1 files changed, 10 insertions, 13 deletions
@@ -14,11 +14,11 @@ import code from "sjit_c." :: Expr = Int !Int | Var !String - | Abstr ![String] !Expr | App !String ![Expr] :: Function = { fun_name :: !String + , fun_args :: ![String] , fun_expr :: !Expr } @@ -128,12 +128,13 @@ compile :: !Function !CompileState -> CompileState compile f cs # cs & funs = put f.fun_name cs.pc cs.funs # vars = cs.vars -# (is,cs) = expr f.fun_expr {cs & vars=newMap} -# is = {i \\ i <- reverse [Ret:is]} +# cs & vars = foldr (uncurry put) cs.vars [(v,sp) \\ v <- f.fun_args & sp <- [cs.sp+1..]] +# (is,cs) = expr f.fun_expr cs +# is = {i \\ i <- reverse [Ret:Put (max 1 (length f.fun_args)+1):is]} = { cs & vars = vars - , pc = cs.pc+1 + , pc = cs.pc+2 , blocks = cs.blocks ++| [!is!] , jitst = appendProgram (f.fun_name == "main") is cs.jitst } @@ -144,14 +145,10 @@ where Just i -> ([PushRef (i-cs.sp)], {cs & sp=cs.sp+1, pc=cs.pc+1}) Nothing -> abort "undefined variable\n" expr (App f args) cs - # (iss,cs) = mapSt expr args cs + # (iss,cs) = mapSt expr args {cs & sp=cs.sp+1} = case get f cs.funs of - Just f -> ([Pop (length args-1):Call f:flatten iss], {cs & sp=cs.sp+1, pc=cs.pc+2}) + Just f -> ([Pop (length args-1):Call f:flatten iss], {cs & sp=cs.sp+2-length args, pc=cs.pc+2}) Nothing -> abort "undefined function\n" - expr (Abstr vs e) cs - # cs & vars = foldr (uncurry put) cs.vars [(v,sp) \\ v <- vs & sp <- [cs.sp+1..]] - # (is,cs) = expr e cs - = ([Put (max 1 (length vs)+1):is], {cs & sp=cs.sp-1, pc=cs.pc+1}) compile_all :: !(Maybe CompileState) ![Function] -> CompileState compile_all mcs funs @@ -268,7 +265,7 @@ where jit_compiled_result = exec comp_state comp_state =: compile_all Nothing - [ {fun_name="id", fun_expr=Abstr ["x"] (Var "x")} - , {fun_name="const", fun_expr=Abstr ["x","y"] (Var "x")} - , {fun_name="main", fun_expr=Abstr [] (App "+" [App "const" [Int 37, Int 10], App "const" [Int 5, Int 10]])} + [ {fun_name="id", fun_args=["x"], fun_expr=Var "x"} + , {fun_name="const", fun_args=["x","y"], fun_expr=Var "x"} + , {fun_name="main", fun_args=[], fun_expr=App "+" [App "const" [Int 37, Int 10], App "const" [Int 5, Int 10]]} ] |