X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=sem.icl;h=dc774cc0791ed11fd9557a716d996cbf332c8dda;hb=e0fd23079f1f63b83431afe78e9ec218d4609e9a;hp=02d01174b1734a3731e3c6d8520eaf7f8a3632ba;hpb=312e268e5861db8228099b57cde2b20edd31be8c;p=cc1516.git diff --git a/sem.icl b/sem.icl index 02d0117..dc774cc 100644 --- a/sem.icl +++ b/sem.icl @@ -1,27 +1,42 @@ implementation module sem import qualified Data.Map as Map + from Data.Func import $ +from StdFunc import o + import Data.Either -import Control.Monad.State -import StdMisc + +import StdString +import StdList +import StdEnum +import RWST +import GenEq + +from Text import class Text(concat), instance Text String import AST -from parse import :: ParserOutput -from yard import :: Error :: Gamma :== 'Map'.Map String Type -:: Env a :== State Gamma a +:: Constraint :== String +:: Infer a :== RWST [String] [Constraint] Gamma (Either SemError) a +:: SemError + = ParseError Pos String + | UnifyError Pos Type Type + | FieldSelectorError Pos Type FieldSelector + | OperatorError Pos Op2 Type + | UndeclaredVariableError Pos String + | ArgumentMisMatchError Pos String + | Error String -sem :: ParserOutput -> SemOutput -sem (Left p) = Left p -sem (Right (AST vd fd)) = Right $ AST vd fd -// foldM semVarDecl vd -// >>= \gamma ->foldM typecheck gamma fd +variableStream :: [String] +variableStream = map toString [1..] -semVarDecl :: VarDecl -> Env VarDecl -semVarDecl (Vardecl pos type ident expr) = undef - +sem :: AST -> SemOutput +sem (AST vd fd) = Right $ (AST vd fd, 'Map'.newMap) +instance toString Gamma where + toString mp = concat [concat [k, ": ", toString v, "\n"]\\(k, v)<-'Map'.toList mp] - +instance toString SemError where + toString se = "SemError: "