X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=sem.icl;h=0da9c7735cb1ca7d6faca7301aec2dfc8e87511f;hb=f081c2c5e248331eb6e2f090f4afe818fd8259eb;hp=2341eefdef0c6c5da997b89d1f151230976e999e;hpb=29d164f53e029e8133e05b599241eb6c14d7fe47;p=cc1516.git diff --git a/sem.icl b/sem.icl index 2341eef..0da9c77 100644 --- a/sem.icl +++ b/sem.icl @@ -48,11 +48,17 @@ instance zero Gamma where variableStream :: [TVar] variableStream = map toString [1..] +defaultGamma :: Gamma //includes all default functions +defaultGamma = extend "print" (Forall ["a"] ((IdType "a") ->> VoidType)) + $ extend "isEmpty" (Forall ["a"] (ListType (IdType "a") ->> BoolType)) + $ extend "read" (Forall [] (IntType ->> (ListType CharType))) + zero + sem :: AST -> Either [SemError] AST sem (AST fd) = case foldM (const $ hasNoDups fd) () fd >>| foldM (const isNiceMain) () fd >>| hasMain fd - >>| evalStateT (type fd) (zero, variableStream) of + >>| evalStateT (type fd) (defaultGamma, variableStream) of Left e = Left [e] Right (_,fds) = Right (AST fds) where @@ -278,7 +284,7 @@ instance infer Stmt where changeGamma (extend k (Forall [] given)) >>| //todo: fieldselectors pure (s, VoidType) - FunStmt f es = undef //what is this? + FunStmt f es = pure (zero, VoidType) ReturnStmt Nothing = pure (zero, VoidType) ReturnStmt (Just e) = infer e