Character tables. Emit tables properly.
Cat's Eye Technologies
8 years ago
210 | 210 | TODO |
211 | 211 | ---- |
212 | 212 | |
213 | * Character tables ("strings" to everybody else) | |
214 | 213 | * Addressing modes — indexed mode on more instructions |
215 | 214 | * Rename and lift temporaries in nested blocks |
216 | 215 | * Tail-recursion optimization |
210 | 210 | = .space frequencies 16 |
211 | 211 | = .alias screen 1024 |
212 | 212 | |
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 | ||
213 | 229 | Temporary storage, in the form of block-local declarations. Note that these |
214 | 230 | temporaries are not unioned yet, but they could be. |
215 | 231 |
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 | |
0 | 2 | .org 0 |
1 | 3 | .word $0801 |
2 | 4 | .data |
36 | 36 | name ++ ": .byte " ++ (showList vals) |
37 | 37 | where |
38 | 38 | showList [] = "" |
39 | showList (val:vals) = (show val) ++ " " ++ (showList vals) | |
39 | showList [val] = show val | |
40 | showList (val:vals) = (show val) ++ ", " ++ (showList vals) | |
40 | 41 | |
41 | 42 | emitDecl p (Reserve name typ []) |
42 | 43 | | typ == Byte = ".space " ++ name ++ " 1" |
2 | 2 | module SixtyPical.Parser (parseProgram) where |
3 | 3 | |
4 | 4 | import Numeric (readHex) |
5 | import Data.Char (ord) | |
5 | 6 | |
6 | 7 | import Text.ParserCombinators.Parsec |
7 | 8 | |
114 | 115 | |
115 | 116 | initial_value :: Parser [DataValue] |
116 | 117 | initial_value = |
117 | data_value_list <|> single_literal_data_value | |
118 | data_value_list <|> string_literal <|> single_literal_data_value | |
118 | 119 | where |
119 | 120 | single_literal_data_value = do |
120 | 121 | a <- literal_data_value |
647 | 648 | nspaces |
648 | 649 | return $ read digits |
649 | 650 | |
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 | ||
650 | 658 | -- -- -- driver -- -- -- |
651 | 659 | |
652 | 660 | parseProgram = parse toplevel "" |