labelStream = ["lbl_" +++ toString i\\i<-[1..]]
defaultAddressBook :: Addressbook
-defaultAddressBook = extend "print" (LAB "print")
- $ extend "read" (LAB "read")
- $ extend "isEmpty" (LAB "isEmpty")
- 'Map'.newMap
+defaultAddressBook = extend "1printint" (LAB "1printint")
+ $ extend "1printchar" (LAB "1printchar")
+ $ extend "1readchar" (LAB "1readchar")
+ $ extend "1readint" (LAB "1readint")
+ $ extend "isEmpty" (LAB "isempty")
+ 'Map'.newMap
gen :: AST -> Either String String
gen (AST fds) = case evalRWST prog () (defaultAddressBook, labelStream) of
>>| mapM_ g fds
programContext :: SSMProgram
-programContext = [Lab "print" //there is no actual IO in SSM
+programContext = [Lab "1printint"
,Instr "link" [Lit 0] ""
+ ,Instr "ldl" [Lit -2] "load first argument"
+ ,Instr "trap" [Lit 0] "print int"
,Instr "unlink" [] ""
,Instr "ret" [] ""
- ,Lab "read" //there is no actual IO in SSM
+ ,Lab "1printchar"
,Instr "link" [Lit 0] ""
- ,Instr "ldc" [Lit 0] ""
- ,Instr "sth" [] ""
+ ,Instr "ldl" [Lit -2] "load first argument"
+ ,Instr "trap" [Lit 1] "print char"
+ ,Instr "unlink" [] ""
+ ,Instr "ret" [] ""
+ ,Lab "1readint"
+ ,Instr "link" [Lit 0] ""
+ ,Instr "trap" [Lit 10] "read int"
+ ,Instr "str" [Raw "RR"] ""
+ ,Instr "unlink" [] ""
+ ,Instr "ret" [] ""
+ ,Lab "1readchar"
+ ,Instr "link" [Lit 0] ""
+ ,Instr "trap" [Lit 11] "read char"
,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"