From fe335fa16eeaa2ca13f59d202197a209ec9f0800 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Wed, 11 Dec 2024 15:46:25 -0500 Subject: [PATCH] Create TAst --- src/Windows12.hs | 1 + src/Windows12/TAst.hs | 54 +++++++++++++++++++++++++++++++++++++++++++ windows12.cabal | 1 + 3 files changed, 56 insertions(+) create mode 100644 src/Windows12/TAst.hs diff --git a/src/Windows12.hs b/src/Windows12.hs index 0cf5556..185b4a3 100644 --- a/src/Windows12.hs +++ b/src/Windows12.hs @@ -4,3 +4,4 @@ import Windows12.Ast import Windows12.Lexer import Windows12.Parser import Windows12.CodeGen +import Windows12.TAst diff --git a/src/Windows12/TAst.hs b/src/Windows12/TAst.hs new file mode 100644 index 0000000..c8cab74 --- /dev/null +++ b/src/Windows12/TAst.hs @@ -0,0 +1,54 @@ +module Windows12.TAst where + +import Data.Text (Text) + +import Windows12.Ast as Ast + +-- "Typed AST". A second AST that contains more type information +-- Makes verification easier, and is needed to determine type +-- of structs when accessing members in CodeGen + +type TExpr = (Type, TExpr') + +data TExpr' + = TVar Text + | TIntLit Int + | TUIntLit Word + | TFloatLit Double + | TStrLit Text + | TBoolLit Bool + | TCharLit Char + | TBinOp BinOp TExpr TExpr + | TUnOp UnOp TExpr + | TCall Text [TExpr] + | TIndex TExpr TExpr + | TMember TExpr Text + | TCast Type TExpr + | TSizeof Type + | TStructInit Text [(Text, TExpr)] + deriving (Show, Eq) + +type TLVal = (Type, TLVal') + +data TLVal' + = TDeref TExpr + | TId Text + | LTIndex TLVal TExpr + | LTMember TLVal Text + deriving (Show, Eq) + +data TStmt + = TExprStmt TExpr + | TReturn TExpr + | TIf TExpr [TStmt] (Maybe [TStmt]) + | TWhile TExpr [TStmt] + | TAssign AssignOp TLVal TExpr + | TBlock [TStmt] + | TDeclVar Text Type (Maybe TExpr) + deriving (Show, Eq) + +data TTLFunc = TTLFunc {funcName :: Text, funcArgs :: [Bind], funcRetType :: Type, funcBody :: [TStmt]} + deriving (Show, Eq) + +data TProgram = TProgram [TLStruct] [TLEnum] [TTLFunc] + deriving (Show, Eq) diff --git a/windows12.cabal b/windows12.cabal index 028c606..f274cd5 100644 --- a/windows12.cabal +++ b/windows12.cabal @@ -69,6 +69,7 @@ executable windows12 Windows12.Lexer Windows12.Parser Windows12.CodeGen + Windows12.TAst -- LANGUAGE extensions used by modules in this package. -- other-extensions: