| 30 | | |
| 31 | | {-| |
| 32 | | The plan here is to first compile the environment (subroutines, |
| 33 | | statements, etc.) to an abstract syntax tree ('PIL' -- Pugs Intermediate |
| 34 | | Language) using the 'compile' function and 'Compile' class. |
| 35 | | -} |
| 36 | | |
| 37 | | data PIL_Stmts = PNil |
| 38 | | | PStmts |
| 39 | | { pStmt :: !PIL_Stmt |
| 40 | | , pStmts :: !PIL_Stmts |
| 41 | | } |
| 42 | | | PPad |
| 43 | | { pScope :: !Scope |
| 44 | | , pSyms :: ![(VarName, PIL_Expr)] |
| 45 | | , pStmts :: !PIL_Stmts |
| 46 | | } |
| 47 | | deriving (Show, Eq, Ord, Typeable) |
| 48 | | |
| 49 | | data PIL_Stmt = PNoop | PStmt { pExpr :: !PIL_Expr } | PPos |
| 50 | | { pPos :: !Pos |
| 51 | | , pExp :: !Exp |
| 52 | | , pNode :: !PIL_Stmt |
| 53 | | } |
| 54 | | deriving (Show, Eq, Ord, Typeable) |
| 55 | | |
| 56 | | data PIL_Expr |
| 57 | | = PRawName { pRawName :: !VarName } |
| 58 | | | PExp { pLV :: !PIL_LValue } |
| 59 | | | PLit { pLit :: !PIL_Literal } |
| 60 | | | PThunk { pThunk :: !PIL_Expr } |
| 61 | | | PCode |
| 62 | | { pType :: !SubType |
| 63 | | , pParams :: ![TParam] |
| 64 | | , pBody :: !PIL_Stmts |
| 65 | | } |
| 66 | | deriving (Show, Eq, Ord, Typeable) |
| 67 | | |
| 68 | | data PIL_Decl = PSub |
| 69 | | { pSubName :: !SubName |
| 70 | | , pSubType :: !SubType |
| 71 | | , pSubParams :: ![TParam] |
| 72 | | , pSubBody :: !PIL_Stmts |
| 73 | | } |
| 74 | | deriving (Show, Eq, Ord, Typeable) |
| 75 | | |
| 76 | | data PIL_Literal = PVal { pVal :: Val } |
| 77 | | deriving (Show, Eq, Ord, Typeable) |
| 78 | | |
| 79 | | data PIL_LValue = PVar { pVarName :: !VarName } |
| 80 | | | PApp |
| 81 | | { pCxt :: !TCxt |
| 82 | | , pFun :: !PIL_Expr |
| 83 | | , pInv :: !(Maybe PIL_Expr) |
| 84 | | , pArgs :: ![PIL_Expr] |
| 85 | | } |
| 86 | | | PAssign |
| 87 | | { pLHS :: ![PIL_LValue] |
| 88 | | , pRHS :: !PIL_Expr |
| 89 | | } |
| 90 | | | PBind |
| 91 | | { pLHS :: ![PIL_LValue] |
| 92 | | , pRHS :: !PIL_Expr |
| 93 | | } |
| 94 | | deriving (Show, Eq, Ord, Typeable) |
| 95 | | |
| 96 | | data TParam = MkTParam |
| 97 | | { tpParam :: !Param |
| 98 | | , tpDefault :: !(Maybe (PIL_Expr)) |
| 99 | | } |
| 100 | | deriving (Show, Eq, Ord, Typeable) |
| 101 | | |
| 102 | | data TCxt |
| 103 | | = TCxtVoid | TCxtLValue !Type | TCxtItem !Type | TCxtSlurpy !Type |
| 104 | | | TTailCall !TCxt |
| 105 | | deriving (Show, Eq, Ord, Typeable) |
| 116 | | |
| 117 | | data TEnv = MkTEnv |
| 118 | | { tLexDepth :: !Int -- ^ Lexical scope depth |
| 119 | | , tTokDepth :: !Int -- ^ Exp nesting depth |
| 120 | | , tCxt :: !TCxt -- ^ Current context |
| 121 | | , tReg :: !(TVar (Int, String))-- ^ Register name supply |
| 122 | | , tLabel :: !(TVar Int) -- ^ Label name supply |
| 123 | | } |
| 124 | | deriving (Show, Eq, Ord, Typeable) |