module Compiler.CompilerState
( CompilerState(..)
, SymTable
, ScopeType(..)
, createCompilerState
) where
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Sequence (Seq)
import qualified Data.Sequence as Seq
import Data.Text (Text)
import Compiler.PsInstruction (PsInstruction(..))
data ScopeType
= ScopeGlobal
| ScopeLocal
| ScopeCapture
deriving (Int -> ScopeType -> ShowS
[ScopeType] -> ShowS
ScopeType -> String
(Int -> ScopeType -> ShowS)
-> (ScopeType -> String)
-> ([ScopeType] -> ShowS)
-> Show ScopeType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScopeType -> ShowS
showsPrec :: Int -> ScopeType -> ShowS
$cshow :: ScopeType -> String
show :: ScopeType -> String
$cshowList :: [ScopeType] -> ShowS
showList :: [ScopeType] -> ShowS
Show, ScopeType -> ScopeType -> Bool
(ScopeType -> ScopeType -> Bool)
-> (ScopeType -> ScopeType -> Bool) -> Eq ScopeType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScopeType -> ScopeType -> Bool
== :: ScopeType -> ScopeType -> Bool
$c/= :: ScopeType -> ScopeType -> Bool
/= :: ScopeType -> ScopeType -> Bool
Eq)
type SymTable = Map Text (ScopeType, Int, Text)
data CompilerState = CompilerState
{ CompilerState -> Seq PsInstruction
csCode :: (Seq PsInstruction)
, CompilerState -> Seq PsInstruction
csFuncs :: Seq PsInstruction
, CompilerState -> SymTable
csSymbols :: SymTable
, CompilerState -> Map Text [(Text, Text)]
csStructs :: Map Text [(Text, Text)]
, CompilerState -> Int
csNextIndex :: Int
, CompilerState -> Int
csLabelCnt :: Int
, CompilerState -> ScopeType
csScopeContext :: ScopeType
, CompilerState -> Int
csCurrentArgCount :: Int
, CompilerState -> [Text]
csLoopExits :: [Text]
} deriving (Int -> CompilerState -> ShowS
[CompilerState] -> ShowS
CompilerState -> String
(Int -> CompilerState -> ShowS)
-> (CompilerState -> String)
-> ([CompilerState] -> ShowS)
-> Show CompilerState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CompilerState -> ShowS
showsPrec :: Int -> CompilerState -> ShowS
$cshow :: CompilerState -> String
show :: CompilerState -> String
$cshowList :: [CompilerState] -> ShowS
showList :: [CompilerState] -> ShowS
Show, CompilerState -> CompilerState -> Bool
(CompilerState -> CompilerState -> Bool)
-> (CompilerState -> CompilerState -> Bool) -> Eq CompilerState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CompilerState -> CompilerState -> Bool
== :: CompilerState -> CompilerState -> Bool
$c/= :: CompilerState -> CompilerState -> Bool
/= :: CompilerState -> CompilerState -> Bool
Eq)
createCompilerState :: CompilerState
createCompilerState :: CompilerState
createCompilerState = CompilerState
{ csCode :: Seq PsInstruction
csCode = Seq PsInstruction
forall a. Seq a
Seq.empty
, csFuncs :: Seq PsInstruction
csFuncs = Seq PsInstruction
forall a. Seq a
Seq.empty
, csSymbols :: SymTable
csSymbols = SymTable
forall k a. Map k a
Map.empty
, csStructs :: Map Text [(Text, Text)]
csStructs = Map Text [(Text, Text)]
forall k a. Map k a
Map.empty
, csNextIndex :: Int
csNextIndex = Int
0
, csLabelCnt :: Int
csLabelCnt = Int
0
, csScopeContext :: ScopeType
csScopeContext = ScopeType
ScopeGlobal
, csCurrentArgCount :: Int
csCurrentArgCount = Int
0
, csLoopExits :: [Text]
csLoopExits = [] }