1 implementation module gen
9 from Data.Func import $
10 from Text import class Text(join), instance Text String
11 from Data.List import intersperse
15 //Instruction is an instruction, with possible arguments and a possible comment
17 :: Instr = Instr String [Arg] String
19 :: Arg = L String | Lit Int
20 :: SSMProgram :== [Instr]
24 gen _ = toString [Label "Test"
25 ,Instr "ldc" [Lit 1] "Eerste instructie"
26 ,Instr "ldc" [Lit 2] "Tweede instructie"]
29 //Scrap this, we'll need shared state when generating
30 //i.e. to figure out the positions of vars relative to the
31 //SP/MP/whatever or in which register they are
32 //and to supply with fresh labels
33 class g a :: a -> SSMProgram
40 class print a :: a -> [String]
42 instance print Instr where
43 print (Label l) = [l, ":", "\n"]
44 print (Instr i args com) = ["\t", i] ++ print args ++ [" ;", com, "\n"]
46 instance print [Arg] where
47 print args = (map toString args)
49 instance toString Arg where
51 toString (Lit int) = toString int
53 instance toString SSMProgram where
54 toString p = join " " $ map (\i-> join " " $ print i) p