implementation module gen 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 _ = 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