From: pimjager Date: Fri, 6 May 2016 15:33:46 +0000 (+0200) Subject: lala codegen X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=4039c774404fffec583dc64a3c95c1c08e9c7deb;p=cc1516.git lala codegen --- diff --git a/examples/codeGen.spl b/examples/codeGen.spl new file mode 100644 index 0000000..a9b650d --- /dev/null +++ b/examples/codeGen.spl @@ -0,0 +1,6 @@ +main() { + var x = 4; + var y = 2; + var z = x + y; + return z; +} \ No newline at end of file diff --git a/gen.icl b/gen.icl index 0d5eb12..eb96982 100644 --- a/gen.icl +++ b/gen.icl @@ -1,7 +1,49 @@ 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"] + + +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