defaultAddressBook :: Addressbook
defaultAddressBook = extend "1printint" (LAB "1printint" 1)
$ extend "1printchar" (LAB "1printchar" 1)
- $ extend "1readchar" (LAB "1readchar" 0)
+ $ extend "read" (LAB "read" 0)
$ extend "1readint" (LAB "1readint" 0)
$ extend "isEmpty" (LAB "isempty" 1)
'Map'.newMap
,Instr "str" [Raw "RR"] ""
,Instr "unlink" [] ""
,Instr "ret" [] ""
- ,Lab "1readchar"
+ ,Lab "read"
,Instr "link" [Lit 0] ""
,Instr "trap" [Lit 11] "read char"
,Instr "str" [Raw "RR"] ""
,Instr "str" [Raw "RR"] ""
,Instr "unlink" [] ""
,Instr "ret" [] ""
+ ,Lab "read"
]
//helper functions for the gen monad
>>| tell [Instr "ajs" [Lit -1] ""]
g (VarExpr _ (VarDef k fs)) = getAdressbook >>= \ab->case 'Map'.get k ab of
Just (ADDR t) = tell [Instr "ldl" [Lit t] ""] >>| mapM_ g fs >>| pure ()
- _ = liftT (Left $ Error "PANIC: variable and function name clash")
- g (FunExpr _ k es fs) =
- mapM_ g es
- >>| jump "bsr" k
- >>| mapM_ (const $ tell [Instr "ajs" [Lit -1] ""]) es //clean up args
- >>| tell [Instr "ldr" [Raw "RR"] ""]
+ _ = liftT (Left $ Error "Higher order functions not implemented")
+ g (FunExpr _ k es fs) = getAdressbook >>= \ab->case 'Map'.get k ab of
+ Just (LAB l arity) = if (arity <> (length es))
+ (liftT $ Left $ Error "Higher order functions not implemented")
+ ( mapM_ g es
+ >>| jump "bsr" k
+ >>| mapM_ (const $ tell [Instr "ajs" [Lit -1] ""]) es //clean up args
+ >>| tell [Instr "ldr" [Raw "RR"] ""])
+ _ = liftT (Left $ Error "Funcall to variable?")
jump :: String String -> Gen ()
jump instr k = getAdressbook >>= \ab->case 'Map'.get k ab of