aboutsummaryrefslogtreecommitdiff
path: root/typecheck
diff options
context:
space:
mode:
Diffstat (limited to 'typecheck')
-rw-r--r--typecheck/CC/Typecheck.hs10
1 files changed, 6 insertions, 4 deletions
diff --git a/typecheck/CC/Typecheck.hs b/typecheck/CC/Typecheck.hs
index aac7923..bf1d17c 100644
--- a/typecheck/CC/Typecheck.hs
+++ b/typecheck/CC/Typecheck.hs
@@ -181,14 +181,16 @@ inferList env (expr : exprs) = do
runPass :: Context -> Program -> Either TCError ProgramT
-runPass _ prog = runTM (typeCheck prog)
+runPass (Context _ (Builtins builtins)) prog =
+ let env = Env (Map.fromList [(name, generalise emptyEnv ty) | (name, ty) <- builtins])
+ in runTM (typeCheck env prog)
-typeCheck :: Program -> TM ProgramT
-typeCheck (Program decls) =
+typeCheck :: Env -> Program -> TM ProgramT
+typeCheck startEnv (Program decls) =
let defs = [(name, ty)
| Def (Function (Just ty) (name, _) _ _) <- decls]
env = foldl (\env' (name, ty) -> envAdd name (generalise env' (convertType ty)) env')
- emptyEnv defs
+ startEnv defs
in ProgramT <$> mapM (typeCheckDef env . (\(Def def) -> def)) decls
typeCheckDef :: Env -> Def -> TM DefT