pub struct BlockState<I: SemanticContextInstruction> {
pub values: HashMap<ValueName, Value>,
pub inner_values_name: HashSet<InnerValueName>,
pub labels: HashSet<LabelName>,
pub last_register_number: u64,
pub manual_return: bool,
pub parent: Option<Rc<RefCell<BlockState<I>>>>,
pub children: Vec<Rc<RefCell<BlockState<I>>>>,
/* private fields */
}
Expand description
§Block state
values
- contains unique values map for current state but not unique for parent states. The map contains key-value:value_name
(unique only for current state); andValue
itself - value parameters.inner_values_name
- is entity that represent inner value name - it can be different fromValue
name because it should be unique for all parent states. For example, of 3 values with namex
, inner value name will be: [x
,x.0
,x.1
]. It mean, inner value name can containvalue counter
as end of the name.labels
- labels set, for conditional operation. Unique for current and all paren states.last_register_number
- represent register counter for current and all parent states forCodegen
. Register represented asu64
and should be linearly incremented.manual_return
- flag indicated, that return was invoked from other state, for example: if-flow, loop-flowparent
- represent parent states.
Fields§
§values: HashMap<ValueName, Value>
State values
inner_values_name: HashSet<InnerValueName>
Used to keep all names in the block state (and parent) as unique
labels: HashSet<LabelName>
State labels for conditional operations
last_register_number: u64
Last register for unique register representation
manual_return: bool
Manual return from other states
parent: Option<Rc<RefCell<BlockState<I>>>>
Parent state
children: Vec<Rc<RefCell<BlockState<I>>>>
children states
Implementations§
Source§impl<I: SemanticContextInstruction> BlockState<I>
impl<I: SemanticContextInstruction> BlockState<I>
Sourcepub fn new(parent: Option<Rc<RefCell<Self>>>) -> Self
pub fn new(parent: Option<Rc<RefCell<Self>>>) -> Self
Init block state with optional parent
state
pub fn get_context(&self) -> SemanticStack<I>
Sourcepub fn inc_register(&mut self)
pub fn inc_register(&mut self)
Increment register
Sourcepub fn set_inner_value_name(&mut self, name: &InnerValueName)
pub fn set_inner_value_name(&mut self, name: &InnerValueName)
Set value inner name to current state and parent states
Sourcepub fn is_inner_value_name_exist(&self, name: &InnerValueName) -> bool
pub fn is_inner_value_name_exist(&self, name: &InnerValueName) -> bool
Check is inner_value_name
exist in current and parent states
Sourcepub fn get_value_name(&self, name: &ValueName) -> Option<Value>
pub fn get_value_name(&self, name: &ValueName) -> Option<Value>
Get Value
by value name from current state.
If not found on current state - recursively find in parent states.
Sourcepub fn is_label_name_exist(&self, name: &LabelName) -> bool
pub fn is_label_name_exist(&self, name: &LabelName) -> bool
Check is label name exist in current and parent states
Sourcepub fn set_label_name(&mut self, name: &LabelName)
pub fn set_label_name(&mut self, name: &LabelName)
Set label name to current and all parent states
Sourcepub fn set_attr_counter(val: &str) -> String
pub fn set_attr_counter(val: &str) -> String
Set attribute counter - increment, if counter exist.
Sourcepub fn get_and_set_next_label(&mut self, label: &LabelName) -> LabelName
pub fn get_and_set_next_label(&mut self, label: &LabelName) -> LabelName
Get and set next label for condition operations
- If label doesn’t exist in State - just insert to State and self return
- if label exists, get label counter
Sourcepub fn get_next_inner_name(&self, val: &InnerValueName) -> InnerValueName
pub fn get_next_inner_name(&self, val: &InnerValueName) -> InnerValueName
Get next inner_value_name
by name counter for current and
parent states. The inner_value_name
should always be unique.
Sourcepub fn set_return(&mut self)
pub fn set_return(&mut self)
Set return status flag for current and parent states