From: pimjager Date: Thu, 26 May 2016 14:33:13 +0000 (+0200) Subject: Sem now prints Gamma X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=6ae534152fb8d636bcf3877b8ced05f9be87ed9a;p=cc1516.git Sem now prints Gamma --- diff --git a/examples/tempTest.spl b/examples/tempTest.spl index a62e6e2..3658ca3 100644 --- a/examples/tempTest.spl +++ b/examples/tempTest.spl @@ -40,5 +40,6 @@ main() { var f = plus(1); var z = map(f, 1:2:[]); var x = foldr(plus, 0, 1:2:[]); + print(x); return; } \ No newline at end of file diff --git a/sem.dcl b/sem.dcl index 2b13436..a570597 100644 --- a/sem.dcl +++ b/sem.dcl @@ -13,4 +13,4 @@ from StdOverloaded import class toString instance toString SemError instance toString Gamma -sem :: AST -> Either [SemError] AST +sem :: AST -> Either [SemError] (AST, Gamma) diff --git a/sem.icl b/sem.icl index 484430d..f9de4fe 100644 --- a/sem.icl +++ b/sem.icl @@ -57,13 +57,13 @@ defaultGamma = extend "print" (Forall ["a"] ((IdType "a") ->> VoidType)) $ extend "1printbool" (Forall [] (BoolType ->> VoidType)) zero -sem :: AST -> Either [SemError] AST +sem :: AST -> Either [SemError] (AST, Gamma) sem (AST fd) = case foldM (const $ hasNoDups fd) () fd >>| foldM (const isNiceMain) () fd >>| hasMain fd - >>| evalStateT (type fd) (defaultGamma, variableStream) of + >>| runStateT (type fd) (defaultGamma, variableStream) of Left e = Left [e] - Right (_,fds) = Right (AST fds) + Right ((_,fds),(gam,_)) = Right (AST fds, gam) where hasNoDups :: [FunDecl] FunDecl -> Either SemError () hasNoDups fds (FunDecl p n _ _ _ _) diff --git a/spl.icl b/spl.icl index bdfccc8..4305f8d 100644 --- a/spl.icl +++ b/spl.icl @@ -88,9 +88,10 @@ Start w stdin <<< "//PARSER\n" <<< toString parseOut <<< "//PARSER\n") = case sem (preamble parseOut) of (Left e) = snd $ fclose (stdin <<< join "\n" (map toString e) <<< "\n") w - (Right ast) + (Right (ast, gam)) # stdin = if (not args.sem) stdin (stdin - <<< "//SEM G\n" <<< toString ast <<< "//SEMA\n") + <<< "//SEM AST\n" <<< toString ast <<< "//SEM AST\n" + <<< "//SEM GAMMA\n" <<< toString gam <<< "//SEM GAMMA\n") = case gen ast of (Left e) = snd $ fclose (stdin <<< e) w (Right asm)