Just (ADDR t arity) = tell [Instr "ldl" [Lit t] ""] >>| mapM_ g fs >>| pure ()
Just (LAB l _ fn) = tell
[Instr "ldc" [Lit fn] ""
+ ,Instr "sth" [] ""
,Instr "ldc" [Lit 0] ""
- ,Instr "stmh" [Lit 2] ""]
+ ,Instr "sth" [] ""
+ ,Instr "ajs" [Lit -1] ""]
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))
,Instr "sub" [] ""
,Instr "str" [Raw "SP"] ""
,Instr "ldr" [Raw "RR"] ""
- //RR is nu goed
-// ,Instr "ajs" [Lit $ ~ (length es)] ""
-// ,Instr "ldl" [Lit t] ""
-// ,Instr "ldr" [Raw "RR"] "END OF HIGHERORDERFUNCALL"
- // ,Instr "ldl" [Lit t] ""
- // ,Instr "ldh" [Lit $ 1] ""
- // ,Instr "neg" [] ""
- // ,Instr "ldr" [Raw "SP"] ""
- // ,Instr "add" [] ""
- // ,Instr "ldc" [Lit arity] ""
- // ,Instr "sub" [] ""
- // ,Instr "str" [Raw "SP"] ""
]
)
Nothing = liftT (Left $ Error "Undefined function!!!")