merge master
[cc1516.git] / sem.icl
diff --git a/sem.icl b/sem.icl
index f9de4fe..364eac4 100644 (file)
--- a/sem.icl
+++ b/sem.icl
@@ -5,6 +5,7 @@ import qualified Data.Map as Map
 from Data.Func import $
 from StdFunc import o, flip, const, id
 
+import Control.Applicative
 import Control.Monad
 import Control.Monad.Trans
 import Control.Monad.State
@@ -88,6 +89,21 @@ where
                                _ = Left $ SanityError p "main has to return Void")
                isNiceMain _ = pure ()
 
+unfoldLambda :: [FunDecl] -> Typing [FunDecl]
+unfoldLambda [fd:fds] = unf_ fd >>= \fds1-> 
+                        unfoldLambda fds >>= \fds2->
+                        pure $ fds1 ++ fds2
+where
+    unf_ :: FunDecl -> Typing [FunDecl]
+    unf_ fd=:(FunDecl _ _ _ _ vds stmts) = 
+        flatten <$> mapM unfv_ vds >>= \fds1->
+        flatten <$> mapM unfs_ stmts >>= \fds2->
+        pure $ [fd:fds1] ++ fds2
+    unfv_ :: VarDecl -> Typing [FunDecl]
+    unfv_ (VarDecl _ _ _ e) = pure []
+    unfs_ :: Stmt -> Typing [FunDecl]
+    unfs_ _ = pure []
+
 class Typeable a where
     ftv :: a -> [TVar]
     subst :: Substitution a -> a
@@ -225,6 +241,8 @@ 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 Unfolded"
+
     FunExpr p f args fs =
         lookup f >>= \expected ->
         let accST = (\(s,ts,es) e->infer e >>= \(s_,et,e_)-> pure (compose s_ s,ts++[et],es++[e_])) in