Create TAst

This commit is contained in:
Ethan Girouard 2024-12-11 15:46:25 -05:00
parent 24cc7d08d9
commit fe335fa16e
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146
3 changed files with 56 additions and 0 deletions

View File

@ -4,3 +4,4 @@ import Windows12.Ast
import Windows12.Lexer import Windows12.Lexer
import Windows12.Parser import Windows12.Parser
import Windows12.CodeGen import Windows12.CodeGen
import Windows12.TAst

54
src/Windows12/TAst.hs Normal file
View File

@ -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)

View File

@ -69,6 +69,7 @@ executable windows12
Windows12.Lexer Windows12.Lexer
Windows12.Parser Windows12.Parser
Windows12.CodeGen Windows12.CodeGen
Windows12.TAst
-- LANGUAGE extensions used by modules in this package. -- LANGUAGE extensions used by modules in this package.
-- other-extensions: -- other-extensions: