Struct CodeGeneratingVisitor

Source
pub struct CodeGeneratingVisitor<'a> {
Show 13 fields pub state: &'a CompilerState, pub next_register: u64, pub current_function: Option<&'a Function>, pub variable_mapping: IndexMap<Symbol, String>, pub composite_mapping: IndexMap<Vec<Symbol>, (bool, String)>, pub global_mapping: IndexMap<Symbol, String>, pub variant: Option<Variant>, pub program: &'a Program, pub program_id: Option<ProgramId>, pub finalize_caller: Option<Symbol>, pub next_label: u64, pub conditional_depth: u64, pub internal_record_inputs: IndexSet<String>,
}

Fields§

§state: &'a CompilerState§next_register: u64

A counter to track the next available register.

§current_function: Option<&'a Function>

Reference to the current function.

§variable_mapping: IndexMap<Symbol, String>

Mapping of local variables to registers. Because these are local, we can identify them using only a Symbol (i.e. a path is not necessary here).

§composite_mapping: IndexMap<Vec<Symbol>, (bool, String)>

Mapping of composite names to a tuple containing metadata associated with the name. The first element of the tuple indicate whether the composite is a record or not. The second element of the tuple is a string modifier used for code generation.

§global_mapping: IndexMap<Symbol, String>

Mapping of global identifiers to their associated names. Because we only allow mappings in the top level program scope at this stage, we can identify them using only a Symbol (i.e. a path is not necessary here currently).

§variant: Option<Variant>

The variant of the function we are currently traversing.

§program: &'a Program

A reference to program. This is needed to look up external programs.

§program_id: Option<ProgramId>

The program ID of the current program.

§finalize_caller: Option<Symbol>

A reference to the finalize caller. Because async transitions can only appear in the top level program scope at this stage, it’s safe to keep this a Symbol (i.e. a path is not necessary).

§next_label: u64

A counter to track the next available label.

§conditional_depth: u64

The depth of the current conditional block.

§internal_record_inputs: IndexSet<String>

Internal record input registers of the current function. This is necessary as if we output them, we need to clone them.

Implementations§

Source§

impl CodeGeneratingVisitor<'_>

Implement the necessary methods to visit nodes in the AST.

Source

pub fn visit_expression(&mut self, input: &Expression) -> (String, String)

Source

fn visit_path(&mut self, input: &Path) -> (String, String)

Source

fn visit_err(&mut self, _input: &ErrExpression) -> (String, String)

Source

fn visit_value(&mut self, input: &Literal) -> (String, String)

Source

fn visit_locator(&mut self, input: &LocatorExpression) -> (String, String)

Source

fn visit_binary(&mut self, input: &BinaryExpression) -> (String, String)

Source

fn visit_cast(&mut self, input: &CastExpression) -> (String, String)

Source

fn visit_array(&mut self, input: &ArrayExpression) -> (String, String)

Source

fn visit_unary(&mut self, input: &UnaryExpression) -> (String, String)

Source

fn visit_ternary(&mut self, input: &TernaryExpression) -> (String, String)

Source

fn visit_struct_init(&mut self, input: &StructExpression) -> (String, String)

Source

fn visit_array_access(&mut self, input: &ArrayAccess) -> (String, String)

Source

fn visit_member_access(&mut self, input: &MemberAccess) -> (String, String)

Source

fn visit_repeat(&mut self, input: &RepeatExpression) -> (String, String)

Source

fn visit_associated_constant( &mut self, input: &AssociatedConstantExpression, ) -> (String, String)

Source

fn visit_associated_function( &mut self, input: &AssociatedFunctionExpression, ) -> (String, String)

Source

fn visit_async(&mut self, _input: &AsyncExpression) -> (String, String)

Source

fn visit_call(&mut self, input: &CallExpression) -> (String, String)

Source

fn visit_tuple(&mut self, input: &TupleExpression) -> (String, String)

Source

fn visit_unit(&mut self, _input: &UnitExpression) -> (String, String)

Source

pub fn clone_register(&mut self, register: &str, typ: &Type) -> (String, String)

Source§

impl<'a> CodeGeneratingVisitor<'a>

Source

pub fn visit_program(&mut self, input: &'a Program) -> String

Source

fn visit_struct_or_record( &mut self, struct_: &'a Composite, absolute_path: &[Symbol], ) -> String

Source

fn visit_struct( &mut self, struct_: &'a Composite, absolute_path: &[Symbol], ) -> String

Source

fn visit_record( &mut self, record: &'a Composite, absolute_path: &[Symbol], ) -> String

Source

fn visit_function_with( &mut self, function: &'a Function, futures: &[Location], ) -> String

Source

fn visit_function(&mut self, function: &'a Function) -> String

Source

fn visit_constructor(&mut self, constructor: &'a Constructor) -> String

Source

fn visit_mapping(&mut self, mapping: &'a Mapping) -> String

Source§

impl CodeGeneratingVisitor<'_>

Source

fn visit_statement(&mut self, input: &Statement) -> String

Source

fn visit_assert(&mut self, input: &AssertStatement) -> String

Source

fn visit_return(&mut self, input: &ReturnStatement) -> String

Source

fn visit_definition(&mut self, input: &DefinitionStatement) -> String

Source

fn visit_expression_statement(&mut self, input: &ExpressionStatement) -> String

Source

fn visit_assign(&mut self, _input: &AssignStatement) -> String

Source

fn visit_conditional(&mut self, _input: &ConditionalStatement) -> String

Source

fn visit_iteration(&mut self, _input: &IterationStatement) -> String

Source

pub(crate) fn visit_block(&mut self, input: &Block) -> String

Source§

impl CodeGeneratingVisitor<'_>

Source

pub fn visit_type(input: &Type) -> String

Source

pub fn visit_type_with_visibility( &self, type_: &Type, visibility: Mode, ) -> String

Source§

impl CodeGeneratingVisitor<'_>

Source

pub(crate) fn next_register(&mut self) -> String

Source

pub(crate) fn legalize_path(path: &[Symbol]) -> Option<String>

Converts a path into a legal Aleo identifier, if possible.

§Behavior
  • If the path is a single valid Leo identifier ([a-zA-Z][a-zA-Z0-9_]*), it’s returned as-is.
  • If the last segment matches Name::[args] (e.g. Vec3::[3, 4]), it’s converted to a legal identifier using hashing.
  • If the path has multiple segments, and all segments are valid identifiers except the last one (which may be Name::[args]), it’s hashed using the last segment as base.
  • Returns None if:
    • The path is empty
    • Any segment other than the last is not a valid identifier
    • The last segment is invalid and not legalizable
§Parameters
  • path: A slice of Symbols representing a path to an item.
§Returns
  • Some(String): A valid Leo identifier.
  • None: If the path is invalid or cannot be legalized.

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,