aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-07-26 09:30:26 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-07-26 09:30:26 +0200
commit494b764274be4db53499fa4eb7decacb93c7bbe9 (patch)
treec8966de4c992ef9755a310435500c475814eae96
parent0503dcb2998ab9dcd0f39e6f264f482a3d2cc7f7 (diff)
Builtins is a Map
-rw-r--r--ast/CC/Context.hs4
-rw-r--r--backend/CC/Backend/Dumb.hs4
-rw-r--r--compcomp.cabal4
-rw-r--r--typecheck/CC/Typecheck.hs2
4 files changed, 9 insertions, 5 deletions
diff --git a/ast/CC/Context.hs b/ast/CC/Context.hs
index b86685d..68378d7 100644
--- a/ast/CC/Context.hs
+++ b/ast/CC/Context.hs
@@ -1,5 +1,7 @@
module CC.Context where
+import Data.Map.Strict (Map)
+
import CC.AST.Typed
@@ -7,4 +9,4 @@ import CC.AST.Typed
data Context = Context FilePath Builtins
-- | Information about builtins supported by the enabled backend
-data Builtins = Builtins [(Name, Type)]
+data Builtins = Builtins (Map Name Type)
diff --git a/backend/CC/Backend/Dumb.hs b/backend/CC/Backend/Dumb.hs
index 7982a06..3210dab 100644
--- a/backend/CC/Backend/Dumb.hs
+++ b/backend/CC/Backend/Dumb.hs
@@ -1,11 +1,13 @@
module CC.Backend.Dumb(builtins) where
+import qualified Data.Map.Strict as Map
+
import CC.AST.Typed
import CC.Context
builtins :: Builtins
-builtins = Builtins
+builtins = Builtins . Map.fromList $
[ ("print", TFun TInt (TTup []))
, ("fst", TFun (TTup [TyVar 1, TyVar 2]) (TyVar 1))
, ("snd", TFun (TTup [TyVar 1, TyVar 2]) (TyVar 2))
diff --git a/compcomp.cabal b/compcomp.cabal
index 0b65ac1..9e941aa 100644
--- a/compcomp.cabal
+++ b/compcomp.cabal
@@ -32,13 +32,13 @@ library cc-typecheck
library cc-backend-dumb
import: deps
hs-source-dirs: backend
- build-depends: cc-ast, cc-utils
+ build-depends: containers, cc-ast, cc-utils
exposed-modules: CC.Backend.Dumb
library cc-ast
import: deps
hs-source-dirs: ast
- build-depends: cc-utils
+ build-depends: containers, cc-utils
exposed-modules: CC.AST.Source, CC.AST.Typed, CC.Context
library cc-utils
diff --git a/typecheck/CC/Typecheck.hs b/typecheck/CC/Typecheck.hs
index 8803a62..f61103e 100644
--- a/typecheck/CC/Typecheck.hs
+++ b/typecheck/CC/Typecheck.hs
@@ -193,7 +193,7 @@ inferList env (expr : exprs) = do
runPass :: Context -> S.Program -> Either TCError T.Program
runPass (Context _ (Builtins builtins)) prog =
- let env = Env (Map.fromList [(name, generalise emptyEnv ty) | (name, ty) <- builtins])
+ let env = Env (Map.map (generalise emptyEnv) builtins)
in runTM (typeCheck env prog)
typeCheck :: Env -> S.Program -> TM T.Program