diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-07-24 22:39:29 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-07-24 22:39:29 +0200 |
commit | ee3788d35edd1a6107a2b5e0c1d7172234f7a640 (patch) | |
tree | d1e70f1a8d1cebdc1125013db6ceb9dfa23ae502 /typecheck | |
parent | 96c29e2a5e2c97d2c40c46222d4593c366de953e (diff) |
Define builtins in backend
Diffstat (limited to 'typecheck')
-rw-r--r-- | typecheck/CC/Typecheck.hs | 10 |
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 |