Added some comments on codegen
[cc1516.git] / gen.icl
diff --git a/gen.icl b/gen.icl
index 0d5eb12..71fe103 100644 (file)
--- a/gen.icl
+++ b/gen.icl
@@ -1,7 +1,54 @@
 implementation module gen
 
-import AST
+
 import StdMisc
+import StdList
+import StdOverloaded
+import StdString
+
+from Data.Func import $
+from Text import class Text(join), instance Text String
+from Data.List import intersperse
+
+import AST
+
+//Instruction is an instruction, with possible arguments and a possible comment
+//Or is a label
+:: Instr    = Instr String [Arg] String
+            | Label String
+:: Arg = L String | Lit Int
+:: SSMProgram :== [Instr]
+
 
 gen :: AST -> String
-gen _ = "dummy"
\ No newline at end of file
+gen _ = toString    [Label "Test"
+                    ,Instr "ldc" [Lit 1] "Eerste instructie"
+                    ,Instr "ldc" [Lit 2] "Tweede instructie"]
+
+
+//Scrap this, we'll need shared state when generating
+//i.e. to figure out the positions of vars relative to the 
+//SP/MP/whatever or in which register they are 
+//and to supply with fresh labels 
+class g a :: a -> SSMProgram
+
+instance g Expr where
+    g _ = undef
+
+
+
+class print a :: a -> [String]
+
+instance print Instr where
+    print (Label l) = [l, ":", "\n"]
+    print (Instr i args com) = ["\t", i] ++ print args ++ [" ;", com, "\n"]
+
+instance print [Arg] where
+    print args = (map toString args)
+
+instance toString Arg where
+    toString (L l) = l
+    toString (Lit int) = toString int
+
+instance toString SSMProgram where
+    toString p = join " " $ map (\i-> join " " $ print i) p
\ No newline at end of file