lala codegen
[cc1516.git] / gen.icl
1 implementation module gen
2
3
4 import StdMisc
5 import StdList
6 import StdOverloaded
7 import StdString
8
9 from Data.Func import $
10 from Text import class Text(join), instance Text String
11 from Data.List import intersperse
12
13 import AST
14
15 //Instruction is an instruction, with possible arguments and a possible comment
16 //Or is a label
17 :: Instr = Instr String [Arg] String
18 | Label String
19 :: Arg = L String | Lit Int
20 :: SSMProgram :== [Instr]
21
22 gen :: AST -> String
23 gen _ = toString [Label "Test"
24 ,Instr "ldc" [Lit 1] "Eerste instructie"
25 ,Instr "ldc" [Lit 2] "Tweede instructie"]
26
27
28 class g a :: a -> SSMProgram
29
30 instance g Expr where
31 g _ = undef
32
33
34
35 class print a :: a -> [String]
36
37 instance print Instr where
38 print (Label l) = [l, ":", "\n"]
39 print (Instr i args com) = ["\t", i] ++ print args ++ [" ;", com, "\n"]
40
41 instance print [Arg] where
42 print args = (map toString args)
43
44 instance toString Arg where
45 toString (L l) = l
46 toString (Lit int) = toString int
47
48 instance toString SSMProgram where
49 toString p = join " " $ map (\i-> join " " $ print i) p