X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=gen.icl;h=89af77c4f1cc65bdf9961349e38f0f228478306f;hb=5dd2ffe89b478a4cb1cd060b1196aa3d326dbd77;hp=a00275d6b5d14047dc2e2d8f7173061d2d7b7562;hpb=8472f6d9507fd0116ac85d02e8ed5566ef8e7980;p=cc1516.git diff --git a/gen.icl b/gen.icl index a00275d..89af77c 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 @@ -165,6 +168,7 @@ instance g Stmt where foldVarDecl :: Int VarDecl -> Gen Int foldVarDecl x (VarDecl _ _ k e) = g e + >>| annote x k >>| updateAdressbook (extend k (ADDR x)) >>| pure (x + 1) addVars :: [String] -> (Addressbook -> Addressbook) @@ -179,12 +183,16 @@ instance g FunDecl where updateAdressbook (addVars args) >>| tell [Lab k] >>| tell [Instr "link" [Lit 0] ""] >>| - //then generate functions for the VarDecls + //add the vars foldM foldVarDecl 1 vds >>| - //then the main function + //and the statements mapM_ g stms >>| updateAdressbook (const oldMap) >>| pure () +annote :: Int String -> Gen () +annote pos key = + tell [Instr "annote" [Raw "MP", Lit pos, Lit pos, Raw "green", Raw key] ""] + class print a :: a -> [String] instance print Instr where