git @ Cat's Eye Technologies SixtyPical / ad1e159
Character tables. Emit tables properly. Cat's Eye Technologies 7 years ago
5 changed file(s) with 29 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
210210 TODO
211211 ----
212212
213 * Character tables ("strings" to everybody else)
214213 * Addressing modes — indexed mode on more instructions
215214 * Rename and lift temporaries in nested blocks
216215 * Tail-recursion optimization
210210 = .space frequencies 16
211211 = .alias screen 1024
212212
213 Reserving things with initial values.
214
215 | reserve byte lives : 3
216 | reserve word screen : $0400
217 | reserve byte[8] frequencies : (0 1 2 4 5 8 9 10)
218 | reserve byte[13] message : "Hello, world!"
219 | routine main {
220 | }
221 = main:
222 = rts
223 =
224 = lives: .byte 3
225 = screen: .word 1024
226 = frequencies: .byte 0, 1, 2, 4, 5, 8, 9, 10
227 = message: .byte 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33
228
213229 Temporary storage, in the form of block-local declarations. Note that these
214230 temporaries are not unioned yet, but they could be.
215231
0 .charmap 'A, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
1 .charmap 'a, 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
02 .org 0
13 .word $0801
24 .data
3636 name ++ ": .byte " ++ (showList vals)
3737 where
3838 showList [] = ""
39 showList (val:vals) = (show val) ++ " " ++ (showList vals)
39 showList [val] = show val
40 showList (val:vals) = (show val) ++ ", " ++ (showList vals)
4041
4142 emitDecl p (Reserve name typ [])
4243 | typ == Byte = ".space " ++ name ++ " 1"
22 module SixtyPical.Parser (parseProgram) where
33
44 import Numeric (readHex)
5 import Data.Char (ord)
56
67 import Text.ParserCombinators.Parsec
78
114115
115116 initial_value :: Parser [DataValue]
116117 initial_value =
117 data_value_list <|> single_literal_data_value
118 data_value_list <|> string_literal <|> single_literal_data_value
118119 where
119120 single_literal_data_value = do
120121 a <- literal_data_value
647648 nspaces
648649 return $ read digits
649650
651 string_literal :: Parser [DataValue]
652 string_literal = do
653 char '"'
654 s <- manyTill anyChar (char '"')
655 nspaces
656 return $ map (\c -> ord c) s
657
650658 -- -- -- driver -- -- --
651659
652660 parseProgram = parse toplevel ""