defaultAddressBook fd = extend "1printint" (LAB "1printint" 1 0)
$ extend "1printchar" (LAB "1printchar" 1 1)
$ extend "read" (LAB "read" 0 2)
- $ extend "1readint" (LAB "1readint" 0 3)
- $ extend "isEmpty" (LAB "isempty" 1 4)
- $ addFuncs fd 5
+ $ extend "isEmpty" (LAB "isEmpty" 1 3)
+ $ addFuncs fd 4
where
addFuncs [] _ = 'Map'.newMap
addFuncs [(FunDecl _ k args _ _ _):xs] n =
programContext :: [FunDecl] -> SSMProgram
programContext x = [Lab "1func"
- :fS ["1printint" ,"1printchar"
- ,"read" ,"1readint"
+ :fS ["1printint" ,"1printchar","read"
,"isEmpty":map (\(FunDecl _ k _ _ _ _)->k) x] 0] ++ context
where
,Instr "ldr" [Raw "R5"] ""
,Instr "ldc" [Lit n] $ "branch to: " +++ k
,Instr "eq" [] ""
- ,Instr "brf" [L $ "1next" +++ (toString $ n + 1)] ""
+ ,if (isEmpty xs)
+ (Instr "nop" [] "")
+ (Instr "brf" [L $ "1next" +++ (toString $ n + 1)] "")
,Instr "bra" [L k] ""
:fS xs $ n+1]
context :: SSMProgram
,Instr "str" [Raw "RR"] ""
,Instr "unlink" [] ""
,Instr "ret" [] ""
- ,Lab "isempty"
+ ,Lab "isEmpty"
,Instr "link" [Lit 0] ""
,Instr "ldl" [Lit -2] "load prt to list"
,Instr "lda" [Lit 0] "derefrence ptr"