about summary refs log tree commit diff
path: root/src/Typecheck.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Typecheck.hs')
-rw-r--r--src/Typecheck.hs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/Typecheck.hs b/src/Typecheck.hs
index 7136e64..8c1755f 100644
--- a/src/Typecheck.hs
+++ b/src/Typecheck.hs
@@ -3,8 +3,10 @@ module Typecheck
 (inferExpr,
  checkExpr,
  wellFormed,
+ wfProgram,
  Environment,
- bool
+ bool,
+ Error
  )
   where
 import Syntax
@@ -171,6 +173,26 @@ wellFormed c@(FunctionCall v f args) env fa= do
             argsOk xs ys 
           
   
+getFuncSign :: FuncDecl -> Error (Idnt,FuncSign)
+getFuncSign (Func name arguments locals body ret) = do
+  localTypes <- mapM (\(var,expr)-> (var,) <$> inferExpr expr arguments) locals
+  ret <- inferExpr ret (localTypes++arguments)
+  return $ (name,FuncSign (map snd arguments) ret)
+
+wfFunction :: FuncDecl-> FuncEnv -> Error ()
+wfFunction (Func name params locals body ret) fe = do
+  localTypes <- mapM (\(var,expr)-> (var,) <$> inferExpr expr params) locals
+  wellFormed body (localTypes++params) fe
+  inferExpr ret (localTypes++params)
+  return ()
+
+wfProgram :: Program -> Error ()
+wfProgram (Program decls locals main) =do
+  fe <- mapM getFuncSign decls
+  localTypes <- mapM (\(var,expr)-> (var,) <$> inferExpr expr []) locals
+  wellFormed main localTypes fe
+  
+