,Lab "read"
]
-//helper functions for the gen monad
getAdressbook :: Gen Addressbook
getAdressbook = gets fst
,Instr "ldc" [Lit 0] ""
,Instr "sth" [] ""]
g (FunExpr _ k es fs) = getAdressbook >>= \ab->case 'Map'.get k ab of
+ //Identifier points to function
Just (LAB l arity fn) = if (arity <> (length es))
( tell
- [Instr "ldc" [Lit fn] ""
+ [Instr "ldc" [Lit fn] "Store function number"
,Instr "sth" [] ""
- ,Instr "ldc" [Lit $ length es] ""
+ ,Instr "ldc" [Lit $ length es] "Store arity"
,Instr "sth" [] ""
,Instr "ajs" [Lit -1] ""]
>>| mapM_ g es
>>| if (isEmpty es) (pure ()) (tell
- [Instr "stmh" [Lit $ length es] ""
+ [Instr "stmh" [Lit $ length es] "Store arguments"
,Instr "ajs" [Lit -1] ""]))
( mapM_ g es
>>| jump "bsr" k
- >>| mapM_ (const $ tell [Instr "ajs" [Lit -1] ""]) es //clean up args
- >>| tell [Instr "ldr" [Raw "RR"] ""])
- Nothing = liftT (Left $ Error "Undefined function!!!")
+ >>| tell
+ [Instr "ajs" [Lit $ ~(length es)] "Clean arguments"
+ ,Instr "ldr" [Raw "RR"] ""])
+ //Identifier points to variable, thus higher order function
Just (ADDR t) = liftT (Left $ Error "FunExpr to addr")
+ Nothing = liftT (Left $ Error "Undefined function!!!")
jump :: String String -> Gen ()
jump instr k = getAdressbook >>= \ab->case 'Map'.get k ab of