Struct BlockState

Source
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); and Value itself - value parameters.
  • inner_values_name - is entity that represent inner value name - it can be different from Value name because it should be unique for all parent states. For example, of 3 values with name x, inner value name will be: [x, x.0, x.1]. It mean, inner value name can contain value 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 for Codegen. Register represented as u64 and should be linearly incremented.
  • manual_return - flag indicated, that return was invoked from other state, for example: if-flow, loop-flow
  • parent - 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>

Source

pub fn new(parent: Option<Rc<RefCell<Self>>>) -> Self

Init block state with optional parent state

Source

pub fn get_context(&self) -> SemanticStack<I>

Source

pub fn inc_register(&mut self)

Increment register

Source

pub fn set_child(&mut self, child: Rc<RefCell<Self>>)

Get child Block state

Source

pub fn set_inner_value_name(&mut self, name: &InnerValueName)

Set value inner name to current state and parent states

Source

pub fn is_inner_value_name_exist(&self, name: &InnerValueName) -> bool

Check is inner_value_name exist in current and parent states

Source

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.

Source

pub fn is_label_name_exist(&self, name: &LabelName) -> bool

Check is label name exist in current and parent states

Source

pub fn set_label_name(&mut self, name: &LabelName)

Set label name to current and all parent states

Source

pub fn set_attr_counter(val: &str) -> String

Set attribute counter - increment, if counter exist.

Source

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
Source

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.

Source

pub fn set_return(&mut self)

Set return status flag for current and parent states

Trait Implementations§

Source§

impl<I: Debug + SemanticContextInstruction> Debug for BlockState<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I: SemanticContextInstruction> ExtendedSemanticContext<I> for BlockState<I>

Source§

fn extended_expression(&mut self, expr: &I)

Source§

impl<I: SemanticContextInstruction> SemanticContext for BlockState<I>

Source§

fn expression_value(&mut self, expression: Value, register_number: u64)

Source§

fn expression_const(&mut self, expression: Constant, register_number: u64)

Source§

fn expression_struct_value( &mut self, expression: Value, index: u32, register_number: u64, )

Source§

fn expression_operation( &mut self, operation: ExpressionOperations, left_value: ExpressionResult, right_value: ExpressionResult, register_number: u64, )

Source§

fn call( &mut self, call: Function, params: Vec<ExpressionResult>, register_number: u64, )

Source§

fn let_binding(&mut self, let_decl: Value, expr_result: ExpressionResult)

Source§

fn binding(&mut self, val: Value, expr_result: ExpressionResult)

Source§

fn expression_function_return(&mut self, expr_result: ExpressionResult)

Source§

fn expression_function_return_with_label( &mut self, expr_result: ExpressionResult, )

Source§

fn set_label(&mut self, label: LabelName)

Source§

fn jump_to(&mut self, label: LabelName)

Source§

fn if_condition_expression( &mut self, expr_result: ExpressionResult, label_if_begin: LabelName, label_if_end: LabelName, )

Source§

fn condition_expression( &mut self, left_result: ExpressionResult, right_result: ExpressionResult, condition: Condition, register_number: u64, )

Source§

fn jump_function_return(&mut self, expr_result: ExpressionResult)

Source§

fn logic_condition( &mut self, logic_condition: LogicCondition, left_register_result: u64, right_register_result: u64, register_number: u64, )

Source§

fn if_condition_logic( &mut self, label_if_begin: LabelName, label_if_end: LabelName, result_register: u64, )

Source§

fn function_arg(&mut self, value: Value, func_arg: FunctionParameter)

Auto Trait Implementations§

§

impl<I> Freeze for BlockState<I>

§

impl<I> !RefUnwindSafe for BlockState<I>

§

impl<I> !Send for BlockState<I>

§

impl<I> !Sync for BlockState<I>

§

impl<I> Unpin for BlockState<I>

§

impl<I> !UnwindSafe for BlockState<I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.