X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=gen.icl;h=71fe1039bccba39fc47e70e0212c14d89d8ad802;hb=d77201023099377ed4d4559c26d2e02f4f61c114;hp=0d5eb12561982c330dfda1a55e0d669c358b588f;hpb=483bcde4dbb75d1901cffad6cc2c45307b7e90a2;p=cc1516.git diff --git a/gen.icl b/gen.icl index 0d5eb12..71fe103 100644 --- 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