Lambda WIP
authorpimjager <pim@pimjager.nl>
Thu, 26 May 2016 13:22:02 +0000 (15:22 +0200)
committerpimjager <pim@pimjager.nl>
Thu, 26 May 2016 13:22:02 +0000 (15:22 +0200)
gen.icl
sem.icl

diff --git a/gen.icl b/gen.icl
index f96840b..c85643e 100644 (file)
--- a/gen.icl
+++ b/gen.icl
@@ -176,7 +176,7 @@ instance g Expr where
                        [Instr "ldc" [Lit fn] ""
                        ,Instr "ldc" [Lit 0] ""
                        ,Instr "stmh" [Lit 2] ""]
-    g (LambdaExpr _ _ _) = liftT $ Left $ Error "PANIC: Lambdas should be transformed"
+    g (LambdaExpr _ _ _) = liftT $ Left $ Error "PANIC: Lambdas should be Unfolded"
     g (FunExpr _ k es fs) = getAdressbook >>= \ab->case 'Map'.get k ab of
                //Identifier points to function
                Just (LAB l arity fn) = if (arity <> (length es))
diff --git a/sem.icl b/sem.icl
index 5cf0520..9d9b5fe 100644 (file)
--- a/sem.icl
+++ b/sem.icl
@@ -88,6 +88,19 @@ where
                                _ = Left $ SanityError p "main has to return Void")
                isNiceMain _ = pure ()
 
+unfoldLambda :: [FunDecl] -> Typing [FunDecl]
+unfoldLambda [fd:fds] = unf_ fd >>= \fds1-> 
+                        unfoldLambda fds2 >>= \fds2->
+                        pure $ fds1 ++ fds2
+where
+    unf_ fd=:(FunDecl _ _ _ _ vds stmts) = 
+        mapM_ unfv_ vds >>= \fds1->
+        mapM_ unfs_ stmts >>= \fds2->
+        pure [fd:fds] ++ fds2
+    unfv_ :: Typing [FunDecl]
+    unfv_ (VarDecl _ _ _ e) = abort ""
+    unfs_ _ = abort ""
+
 class Typeable a where
     ftv :: a -> [TVar]
     subst :: Substitution a -> a
@@ -225,7 +238,7 @@ instance infer Expr where
         infer e2 >>= \(s2, t2, e2_) ->
         pure (compose s2 s1, TupleType (t1,t2), TupleExpr p (e1_,e2_))
 
-    LambdaExpr _ _ _ = liftT $ Left $ Error "PANIC: lambdas should be tasnformed"
+    LambdaExpr _ _ _ = liftT $ Left $ Error "PANIC: lambdas should be Unfolded"
 
     FunExpr p f args fs =
         lookup f >>= \expected ->