Struct State

Source
pub struct State<E, I>{
    pub global: GlobalState<I>,
    pub context: Vec<Rc<RefCell<BlockState<I>>>>,
    pub errors: Vec<StateErrorResult>,
    /* private fields */
}
Expand description

§State

Basic entity that contains:

  • Global State - types, constants, functions declaration and most important - context results of Semantic State stack, that can be used for post-verification and/or Codegen.
  • Context stack for Block state of each functions body state
  • Error State contains errors stack as result of Semantic analyzer

Fields§

§global: GlobalState<I>

Global State for current State

§context: Vec<Rc<RefCell<BlockState<I>>>>

Context for all Block State stack that related to concrete functions body.

§errors: Vec<StateErrorResult>

Error state results stack

Implementations§

Source§

impl<E, I> State<E, I>

Source

pub fn new() -> Self

Init new State

Source

pub fn run(&mut self, data: &Main<'_, I, E>)

Run semantic analyzer that covers all flow for AST. It’s do not return any results, but fill results fir the Semantic State.

Source

pub fn import(&self, data: &ImportPath<'_>)

Import analyzer (TBD)

Source

pub fn types(&mut self, data: &StructTypes<'_>)

Types declaration analyzer. Add types to Global State. Currently only one type kind: Structs. And types can’t be part of the Block State.

Source

pub fn check_constant_value_expression( &mut self, data: &Option<(ExpressionOperations, Box<ConstantExpression<'_>>)>, ) -> bool

Check constant value expression. If expression contains Constant check is constant exists. Values doesn’t check as it’s just Primitive Values. Also check all expression tree branches. If ConstantValue doesn’t exist add error to Error State and return false result.

Source

pub fn constant(&mut self, data: &Constant<'_>)

Constant analyzer. Add it to Global State, because constants can be only global for Semantic state, not for Block state.

Source

pub fn function_declaration(&mut self, data: &FunctionStatement<'_, I, E>)

Function declaration analyze. Add it to Global State/M

Source

pub fn function_body(&mut self, data: &FunctionStatement<'_, I, E>)

Function body analyze. It is basic execution entity for program flow. It’s operate sub analyze for function elements. It’s contain Body State for current and child states.

Source

pub fn let_binding( &mut self, data: &LetBinding<'_, I, E>, function_state: &Rc<RefCell<BlockState<I>>>, )

§Let-binding statement

Analyze let-binding statement:

  1. Let value bind from expression. First should be analysed expression for binding value.
  2. Generate value for current state. Special field inner_name that used as name for Codegen should be unique in current state and for all parent states. For that inner_name the inner value name counter incremented.
  3. Set Value parameters: inner_name, type and allocation status
  4. Insert value to current values state map: value name -> Data
  5. Store inner_name in current and parent states
  6. Codegen
Source

pub fn binding( &mut self, data: &Binding<'_, I, E>, function_state: &Rc<RefCell<BlockState<I>>>, )

§Binding statement

Analyze binding statement for mutable variables:

  1. Bind from expression. First should be analysed expression for binding value.
  2. Read value for current state.
  3. Update value to current values state map: value name -> Data
  4. Codegen with Store action
Source

pub fn function_call( &mut self, data: &FunctionCall<'_, I, E>, body_state: &Rc<RefCell<BlockState<I>>>, ) -> Option<Type>

§Function-call

Call function with function parameters arguments. Arguments is expressions.

  1. Check is current function name exists in global state of functions name.
  2. Analyse expressions for function parameters
  3. Inc register
  4. Generate codegen Codegen store always result to register even for void result.
§Errors

Return error if function name doesn’t exist in global state

Source

pub fn condition_expression( &mut self, data: &ExpressionLogicCondition<'_, I, E>, function_body_state: &Rc<RefCell<BlockState<I>>>, ) -> u64

§condition-expression

Analyse condition operations.

§Return

Return result register of condition-expression calculation.

Source

pub fn if_condition_body( &mut self, body: &[IfBodyStatement<'_, I, E>], if_body_state: &Rc<RefCell<BlockState<I>>>, label_end: &LabelName, label_loop: Option<(&LabelName, &LabelName)>, ) -> bool

§If-condition body

Analyze body for ant if condition:

  • if, else, if-else NOTE: label_end - is always already exists
§Return

Return body statement “return” status

Source

pub fn if_condition_loop_body( &mut self, body: &[IfLoopBodyStatement<'_, I, E>], if_body_state: &Rc<RefCell<BlockState<I>>>, label_if_end: &LabelName, label_loop_start: &LabelName, label_loop_end: &LabelName, ) -> bool

§If-condition loop body

Analyze body for ant if condition:

  • if, else, if-else
§Return

Return body statement “return” status

Source

pub fn if_condition_calculation( &mut self, condition: &IfCondition<'_, I, E>, if_body_state: &Rc<RefCell<BlockState<I>>>, label_if_begin: &LabelName, label_if_else: &LabelName, label_if_end: &LabelName, is_else: bool, )

§If conditions calculations

Calculate conditions for if-condition. It can contain simple and logic conditions.

Source

pub fn if_condition( &mut self, data: &IfStatement<'_, I, E>, function_body_state: &Rc<RefCell<BlockState<I>>>, label_end: &Option<LabelName>, label_loop: Option<(&LabelName, &LabelName)>, )

§If-condition

Analyzing includes all variants for if statements:

  1. if
  2. if-else
  3. if-else-if It creates own state, with parent function-state. in that case if-state independent from parent state, but csn get access to parent state. If condition can’t contain else and if-else on the same time.

Special case for label_end - it should be set from previous context, and main goal is to end all of if-condition nodes in the same flow with same if-end label. It’s especially important for else-if condition.

§Panics

label_loop is must be set, it’s special case for the Loop, when label_loop should always be set. If it doesn’t set, it’s unexpected behavior and program algorithm error

Source

pub fn loop_statement( &mut self, data: &[LoopBodyStatement<'_, I, E>], function_body_state: &Rc<RefCell<BlockState<I>>>, )

§Loop

Loop statement contains logic:

  • jump to loop
  • loop body
  • end of loop
  • return, break, continue
Source

pub fn expression( &mut self, data: &Expression<'_, I, E>, body_state: &Rc<RefCell<BlockState<I>>>, ) -> Option<ExpressionResult>

§Expression

Is basic entity for state operation and state usage. State correctness verified by expressions call. Expressions folded by operations priority. For that expressions tree folded each leaf of tree by priority operation level. The most striking image is bracketing an expression with a higher priority, and build tree based on that.

§Return

PrimitiveValue | TmpRegister

Possible algorithm conditions: 1. PrimitiveValue -> PrimitiveValue 2. Value -> load -> TmpRegister 3. FuncCall -> call -> TmpRegister 4. Operations 4.1. PrimitiveValue - PrimitiveValue -> tmp = OP val1, val2 -> TmpRegister - Value -> tmp1 = load -> OP val1, tmp1 -> TmpRegister - FuncCAll -> tmp1 = call -> OP val1, tmp1 -> TmpRegister 4.2. TmpRegister (with name tmp1) - PrimitiveValue -> tmp2 = OP tmp1, val1 -> TmpRegister - Value -> tmp2 = load -> tmp3 = OP tmp1, tmp2 -> TmpRegister - FuncCall -> tmp2 = call -> tmp3 = OP tmp1, tmp2 -> TmpRegister 4.3. Operations -> recursively invoke 4.2.

Source

pub fn expression_operation( &mut self, left_value: Option<&ExpressionResult>, right_expression: &Expression<'_, I, E>, op: Option<&ExpressionOperations>, body_state: &Rc<RefCell<BlockState<I>>>, ) -> Option<ExpressionResult>

Expression operation semantic logic: OP(lhs, rhs) Left-value contains optional Expression result for left side of expression.

Trait Implementations§

Source§

impl<E, I> Debug for State<E, I>

Source§

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

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

impl<E, I> Default for State<E, I>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<E, I> Freeze for State<E, I>

§

impl<E, I> !RefUnwindSafe for State<E, I>

§

impl<E, I> !Send for State<E, I>

§

impl<E, I> !Sync for State<E, I>

§

impl<E, I> Unpin for State<E, I>
where E: Unpin,

§

impl<E, I> !UnwindSafe for State<E, 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.