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))
+ //Function is not complete
( tell
[Instr "ldc" [Lit fn] "Store function number"
,Instr "sth" [] ""
>>| if (isEmpty es) (pure ()) (tell
[Instr "stmh" [Lit $ length es] "Store arguments"
,Instr "ajs" [Lit -1] ""]))
+ //Function is complete
( mapM_ g es
>>| jump "bsr" k
>>| tell
,Instr "ldr" [Raw "RR"] ""])
//Identifier points to variable, thus higher order function
Just (ADDR t arity) = if (arity <> (length es))
- ( fresh >>= \finish->
- fresh >>= \start->
- tell
- [Instr "ldl" [Lit t] ""
- ,Instr "ldma" [Lit 0, Lit 2] "Load funcall and arity"
- ,Instr "ldc" [Lit $ length es] "Push extra arity on stack"
- ,Instr "add" [] "Increase arity"
- ,Instr "ldl" [Lit t] ""
- ,Instr "ldh" [Lit 1] "Load available arguments"
- ,Instr "str" [Raw "R5"] "Save available arguments"
- ,Lab start
- ,Instr "ldr" [Raw "R5"] "Load available arguments"
- ,Instr "ldc" [Lit 0] ""
- ,Instr "eq" [] ""
- ,Instr "brt" [L finish] ""
- ,Instr "ldc" [Lit 1] "Decrement available arguments"
- ,Instr "sub" [] ""
- ,Instr "str" [Raw "R5"] "Push available arguments"
- ,Instr "bra" [L start] ""
- ,Lab finish
- ]
- >>| mapM_ g es )
+ //Function is still not complete
+ ( liftT (Left $ Error "Nope not implemented yet..."))
+ //Function is complete
( fresh >>= \finish->
fresh >>= \start->
tell