Create TAst
This commit is contained in:
parent
24cc7d08d9
commit
fe335fa16e
@ -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
54
src/Windows12/TAst.hs
Normal 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)
|
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user