| Copyright | (c) roki 2019 |
|---|---|
| License | MIT |
| Maintainer | falgon53@yahoo.co.jp |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Htcc.Parser.ConstructionData.Scope.Var
Description
The Data type of variables and its utilities used in parsing
Synopsis
- class Var a where
- vtype :: a i -> StorageClass i
- type SomeVars v = Map Text v
- data GVarInitWith i
- data GVar i = GVar {
- gvtype :: StorageClass i
- initWith :: GVarInitWith i
- data LVar a = LVar {
- lvtype :: StorageClass a
- rbpOffset :: !a
- nestDepth :: !Natural
- data Literal a = Literal {
- litype :: StorageClass a
- ln :: !Natural
- lcts :: ByteString
- type GlobalVars a = SomeVars (GVar a)
- type LocalVars a = SomeVars (LVar a)
- type Literals a = [Literal a]
- data Vars a = Vars {}
- lookupLVar :: Text -> Vars a -> Maybe (LVar a)
- lookupGVar :: Text -> Vars a -> Maybe (GVar a)
- lookupVar :: Text -> Vars a -> Maybe (Either (GVar a) (LVar a))
- addLVar :: (Integral i, Bits i) => Natural -> StorageClass i -> TokenLC i -> Vars i -> Either (ASTError i) (ATree i, Vars i)
- addGVarWith :: Num i => StorageClass i -> TokenLC i -> GVarInitWith i -> Vars i -> Either (ASTError i) (ATree i, Vars i)
- addGVar :: Num i => StorageClass i -> TokenLC i -> Vars i -> Either (ASTError i) (ATree i, Vars i)
- addLiteral :: (Ord i, Num i) => StorageClass i -> TokenLC i -> Vars i -> Either (ASTError i) (ATree i, Vars i)
- initVars :: Vars a
- resetLocal :: Vars a -> Vars a
- fallBack :: Vars a -> Vars a -> Vars a
The classes
The type class of the type representing the variable
Instances
| Var Literal Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var Methods vtype :: Literal i -> StorageClass i Source # | |
| Var LVar Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var Methods vtype :: LVar i -> StorageClass i Source # | |
| Var GVar Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var Methods vtype :: GVar i -> StorageClass i Source # | |
The data type
data GVarInitWith i Source #
The informations type about initial value of the global variable
Constructors
| GVarInitWithZero | |
| GVarInitWithOG Text | |
| GVarInitWithVal i |
Instances
The data type of the global variable
Constructors
| GVar | The constructor of the global variable |
Fields
| |
Instances
| Var GVar Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var Methods vtype :: GVar i -> StorageClass i Source # | |
| Eq i => Eq (GVar i) Source # | |
| Ord i => Ord (GVar i) Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var | |
| Show i => Show (GVar i) Source # | |
| Generic (GVar i) Source # | |
| NFData i => NFData (GVar i) Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var | |
| ManagedScope (GVar i) Source # | |
| type Rep (GVar i) Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var type Rep (GVar i) = D1 ('MetaData "GVar" "Htcc.Parser.ConstructionData.Scope.Var" "htcc-0.0.0.1-I8tHuOdNzco4DzUthNftqr" 'False) (C1 ('MetaCons "GVar" 'PrefixI 'True) (S1 ('MetaSel ('Just "gvtype") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (StorageClass i)) :*: S1 ('MetaSel ('Just "initWith") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (GVarInitWith i)))) | |
The data type of local variable
Constructors
| LVar | The constructor of local variable |
Fields
| |
Instances
| Treealizable LVar Source # | |
| Var LVar Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var Methods vtype :: LVar i -> StorageClass i Source # | |
| Eq a => Eq (LVar a) Source # | |
| Ord a => Ord (LVar a) Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var | |
| Show a => Show (LVar a) Source # | |
| Generic (LVar a) Source # | |
| NFData a => NFData (LVar a) Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var | |
| ManagedScope (LVar a) Source # | |
| type Rep (LVar a) Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var type Rep (LVar a) = D1 ('MetaData "LVar" "Htcc.Parser.ConstructionData.Scope.Var" "htcc-0.0.0.1-I8tHuOdNzco4DzUthNftqr" 'False) (C1 ('MetaCons "LVar" 'PrefixI 'True) (S1 ('MetaSel ('Just "lvtype") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (StorageClass a)) :*: (S1 ('MetaSel ('Just "rbpOffset") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "nestDepth") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural)))) | |
The literal
Constructors
| Literal | The literal constructor |
Fields
| |
Instances
| Var Literal Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var Methods vtype :: Literal i -> StorageClass i Source # | |
| Eq a => Eq (Literal a) Source # | |
| Show a => Show (Literal a) Source # | |
| Generic (Literal a) Source # | |
| NFData a => NFData (Literal a) Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var | |
| type Rep (Literal a) Source # | |
Defined in Htcc.Parser.ConstructionData.Scope.Var type Rep (Literal a) = D1 ('MetaData "Literal" "Htcc.Parser.ConstructionData.Scope.Var" "htcc-0.0.0.1-I8tHuOdNzco4DzUthNftqr" 'False) (C1 ('MetaCons "Literal" 'PrefixI 'True) (S1 ('MetaSel ('Just "litype") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (StorageClass a)) :*: (S1 ('MetaSel ('Just "ln") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural) :*: S1 ('MetaSel ('Just "lcts") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString)))) | |
type GlobalVars a = SomeVars (GVar a) Source #
The type of global variables
The data type of local variables
Constructors
| Vars | The constructor of variables |
Instances
Functions for adding and searching for variables and literals
lookupLVar :: Text -> Vars a -> Maybe (LVar a) Source #
Search for a local variable with a given name
lookupGVar :: Text -> Vars a -> Maybe (GVar a) Source #
Search for a global variable with a given name
lookupVar :: Text -> Vars a -> Maybe (Either (GVar a) (LVar a)) Source #
First, search for local variables, and if not found, search for global variables. If nothing is found, Nothing is returned
addLVar :: (Integral i, Bits i) => Natural -> StorageClass i -> TokenLC i -> Vars i -> Either (ASTError i) (ATree i, Vars i) Source #
addGVarWith :: Num i => StorageClass i -> TokenLC i -> GVarInitWith i -> Vars i -> Either (ASTError i) (ATree i, Vars i) Source #
addGVar :: Num i => StorageClass i -> TokenLC i -> Vars i -> Either (ASTError i) (ATree i, Vars i) Source #
If the specified token is TKIdent and the global variable does not exist in the list, addLVar adds a new global variable that will be initialized by zero to the list,
constructs a pair with the node representing the variable, wraps it in Right and return it. Otherwise, returns an error message and token pair wrapped in Left.
addLiteral :: (Ord i, Num i) => StorageClass i -> TokenLC i -> Vars i -> Either (ASTError i) (ATree i, Vars i) Source #
If the specified token is TKString, addLiteral adds a new literal to the list,
constructs a pair with the node representing the variable, wraps it in Right and return it. Otherwise, returns an error message and token pair wrapped in Left.
Utilities
resetLocal :: Vars a -> Vars a Source #
resetLocal initialize the local variable list for Vars