From c13e6ac6caa1b0d3578caf9310303920d47cf85f Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Wed, 13 Apr 2016 11:37:10 +0200 Subject: [PATCH] print gamma jowww --- sem.dcl | 6 ++++-- sem.icl | 10 +++++++--- spl.icl | 5 +++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sem.dcl b/sem.dcl index b34bbc3..a2bcd57 100644 --- a/sem.dcl +++ b/sem.dcl @@ -1,5 +1,6 @@ definition module sem +import qualified Data.Map as Map from Data.Either import :: Either from AST import :: AST, :: Pos, :: Type from StdOverloaded import class toString @@ -9,9 +10,10 @@ from StdOverloaded import class toString | UnifyError Pos Type Type | UnifyErrorStub Type Type | Error String -:: SemOutput :== Either [SemError] AST - +:: Gamma +:: SemOutput :== Either [SemError] (AST, Gamma) instance toString SemError +instance toString Gamma sem :: AST -> SemOutput diff --git a/sem.icl b/sem.icl index 8224a4f..c5e14f3 100644 --- a/sem.icl +++ b/sem.icl @@ -59,9 +59,9 @@ instance toString SemError where toString t1, ". Given: ", toString t2] sem :: AST -> SemOutput -sem (AST vd fd) = case evalStateT m ('Map'.newMap, getRandomStream 0) of +sem (AST vd fd) = case runStateT m ('Map'.newMap, getRandomStream 0) of Left e = Left [e] - Right (vds, fds) = Right (AST vds fds) + Right ((vds, fds), gamma) = Right ((AST vds fds), gamma) where m :: Env (([VarDecl], [FunDecl])) m = (mapM semVarDecl vd) >>= \vds -> @@ -155,4 +155,8 @@ extrPos (CharExpr p _) = p extrPos (BoolExpr p _) = p extrPos (FunExpr p _) = p extrPos (EmptyListExpr p) = p -extrPos (TupleExpr p _) = p \ No newline at end of file +extrPos (TupleExpr p _) = p + +instance toString Gamma where + toString (mp, _) = concat + [concat [k, ": ", toString v, "\n"]\\(k, v) <- 'Map'.toList mp] diff --git a/spl.icl b/spl.icl index 1690d71..2a4fb97 100644 --- a/spl.icl +++ b/spl.icl @@ -12,6 +12,7 @@ import Data.Maybe import Data.Func import System.CommandLine import GenPrint +import Data.Map from Text import class Text(concat,join), instance Text String import parse @@ -67,9 +68,9 @@ Start w stdin <<< "//PARSER\n" <<< toString parseOut <<< "//PARSER\n") = case sem parseOut of (Left e) = snd $ fclose (stdin <<< join "\n" (map toString e)) w - (Right semOut) + (Right (semOut, gamma)) # stdin = if (not args.sem) stdin ( - stdin <<< "//SEM\n" <<< toString semOut <<< "//SEM\n") + stdin <<< "//SEM\n" <<< toString gamma <<< "//SEM\n") = snd $ fclose stdin w where printTokens :: [Token] -> String -- 2.20.1