X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=gen.icl;h=819da198aa1e3a7c7708dc178870eb88178399ce;hb=2e6ed5e7922ece250543a2d0a0a0adec1c3d4942;hp=9145ee56d8659d0f7db56cc823db54db93aab99c;hpb=2dfaf554d3b448567e41a140d46a27f6dfb5d901;p=cc1516.git diff --git a/gen.icl b/gen.icl index 9145ee5..819da19 100644 --- a/gen.icl +++ b/gen.icl @@ -1,6 +1,5 @@ implementation module gen - import StdMisc import StdList import StdOverloaded @@ -44,12 +43,12 @@ FALSE :== 0 :: Gen a :== RWST Label SSMProgram (GenMap, [Label]) (Either GenError) a labelStream :: [Label] -labelStream = map (\i-> concat ["lbl_", toString i]) [1..] +labelStream = ["lbl_" +++ toString i\\i<-[1..]] -gen :: AST -> String +gen :: AST -> Either String String gen (AST fds) = case evalRWST prog "" ('Map'.newMap, labelStream) of - Left (Error e) = e - Right (_, p) = toString p + Left (Error e) = Left e + Right (_, p) = Right $ toString p where prog = tell [Instr "bra" [L "main"] ""] >>| mapM_ g fds //gen _ = prog @@ -64,12 +63,19 @@ gen (AST fds) = case evalRWST prog "" ('Map'.newMap, labelStream) of // ,Instr "ldc" [Lit 1] "Eerste instructie" // ,Instr "ldc" [Lit 2] "Tweede instructie"] -//TODO: -//For now in the generation we assume all vars fit on the stack... +//Current issues: +//All VarDecls are added as function, how to deal with assignments? +// (And when we deal with assignments, how to deal with assignments to higher order functions?) +//Dealing with arguments +//Dealing with types that do not fit on the Stack +// Probably completely change LoadPlace to a Type and a position relative to *something* +// And where the type determines if this position is a pointer to the heap or an +// unboxed value //helper functions for the gen monad genMap :: Gen GenMap genMap = gets fst + changeGenMap :: (GenMap -> GenMap) -> Gen GenMap changeGenMap f = modify (appFst f) >>| genMap @@ -212,4 +218,4 @@ instance toString Arg where toString (Raw s) = s instance toString SSMProgram where - toString p = concat $ intersperse " " $ map (\i-> concat $ intersperse " " $ print i) p \ No newline at end of file + toString p = concat $ intersperse " " $ map (\i-> concat $ intersperse " " $ print i) p