From: pimjager Date: Thu, 19 May 2016 14:58:33 +0000 (+0200) Subject: Function calls now clean up the arguments X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=5133b2b81d244d3f05930481366082a00fc95c3b;p=cc1516.git Function calls now clean up the arguments --- diff --git a/examples/codeGen.spl b/examples/codeGen.spl index 30fe668..9f45dfc 100644 --- a/examples/codeGen.spl +++ b/examples/codeGen.spl @@ -4,7 +4,7 @@ f(x, y) { main() { Int x1 = 1; + var x2 = f(x1, 2); x1 = 5; - f(x1, 2); - return x1; + return x2; } diff --git a/gen.icl b/gen.icl index a00275d..59d04e4 100644 --- a/gen.icl +++ b/gen.icl @@ -121,8 +121,9 @@ instance g Expr where Just (LAB t) = liftT (Left $ Error "PANIC: variable and function name clash") //load k >>= \instr-> tell [instr] //note: pure is pure for list, i.e. [] g (FunExpr _ k es fs) = - mapM g es + mapM_ g es >>| jump "bsr" k + >>| mapM_ (const $ tell [Instr "ajs" [Lit -1] ""]) es //clean up args >>| tell [Instr "ldr" [Raw "RR"] ""] jump :: String String -> Gen () @@ -156,7 +157,9 @@ instance g Stmt where Nothing = liftT (Left $ Error $ concat ["PANIC: ", k, " not found as var"]) Just (LAB t) = liftT (Left $ Error $ "PANIC: cannot assign to function") Just (ADDR t) = tell [Instr "stl" [Lit t] ""] - g (FunStmt k es) = mapM g es >>| jump "bsr" k + g (FunStmt k es) = mapM_ g es + >>| mapM_ (const $ tell [Instr "ajs" [Lit -1] ""]) es //clean up args + >>| jump "bsr" k g (ReturnStmt Nothing) = tell [Instr "unlink" [] ""] >>| tell [Instr "ret" [] ""] g (ReturnStmt (Just e)) = g e