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 transition
s 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.
impl CodeGeneratingVisitor<'_>
Implement the necessary methods to visit nodes in the AST.
pub fn visit_expression(&mut self, input: &Expression) -> (String, String)
fn visit_path(&mut self, input: &Path) -> (String, String)
fn visit_err(&mut self, _input: &ErrExpression) -> (String, String)
fn visit_value(&mut self, input: &Literal) -> (String, String)
fn visit_locator(&mut self, input: &LocatorExpression) -> (String, String)
fn visit_binary(&mut self, input: &BinaryExpression) -> (String, String)
fn visit_cast(&mut self, input: &CastExpression) -> (String, String)
fn visit_array(&mut self, input: &ArrayExpression) -> (String, String)
fn visit_unary(&mut self, input: &UnaryExpression) -> (String, String)
fn visit_ternary(&mut self, input: &TernaryExpression) -> (String, String)
fn visit_struct_init(&mut self, input: &StructExpression) -> (String, String)
fn visit_array_access(&mut self, input: &ArrayAccess) -> (String, String)
fn visit_member_access(&mut self, input: &MemberAccess) -> (String, String)
fn visit_repeat(&mut self, input: &RepeatExpression) -> (String, String)
fn visit_associated_constant( &mut self, input: &AssociatedConstantExpression, ) -> (String, String)
fn visit_associated_function( &mut self, input: &AssociatedFunctionExpression, ) -> (String, String)
fn visit_async(&mut self, _input: &AsyncExpression) -> (String, String)
fn visit_call(&mut self, input: &CallExpression) -> (String, String)
fn visit_tuple(&mut self, input: &TupleExpression) -> (String, String)
fn visit_unit(&mut self, _input: &UnitExpression) -> (String, String)
pub fn clone_register(&mut self, register: &str, typ: &Type) -> (String, String)
Source§impl<'a> CodeGeneratingVisitor<'a>
impl<'a> CodeGeneratingVisitor<'a>
pub fn visit_program(&mut self, input: &'a Program) -> String
fn visit_struct_or_record( &mut self, struct_: &'a Composite, absolute_path: &[Symbol], ) -> String
fn visit_struct( &mut self, struct_: &'a Composite, absolute_path: &[Symbol], ) -> String
fn visit_record( &mut self, record: &'a Composite, absolute_path: &[Symbol], ) -> String
fn visit_function_with( &mut self, function: &'a Function, futures: &[Location], ) -> String
fn visit_function(&mut self, function: &'a Function) -> String
fn visit_constructor(&mut self, constructor: &'a Constructor) -> String
fn visit_mapping(&mut self, mapping: &'a Mapping) -> String
Source§impl CodeGeneratingVisitor<'_>
impl CodeGeneratingVisitor<'_>
fn visit_statement(&mut self, input: &Statement) -> String
fn visit_assert(&mut self, input: &AssertStatement) -> String
fn visit_return(&mut self, input: &ReturnStatement) -> String
fn visit_definition(&mut self, input: &DefinitionStatement) -> String
fn visit_expression_statement(&mut self, input: &ExpressionStatement) -> String
fn visit_assign(&mut self, _input: &AssignStatement) -> String
fn visit_conditional(&mut self, _input: &ConditionalStatement) -> String
fn visit_iteration(&mut self, _input: &IterationStatement) -> String
pub(crate) fn visit_block(&mut self, input: &Block) -> String
Source§impl CodeGeneratingVisitor<'_>
impl CodeGeneratingVisitor<'_>
pub fn visit_type(input: &Type) -> String
pub fn visit_type_with_visibility( &self, type_: &Type, visibility: Mode, ) -> String
Source§impl CodeGeneratingVisitor<'_>
impl CodeGeneratingVisitor<'_>
pub(crate) fn next_register(&mut self) -> String
Sourcepub(crate) fn legalize_path(path: &[Symbol]) -> Option<String>
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 ofSymbol
s 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§
impl<'a> Freeze for CodeGeneratingVisitor<'a>
impl<'a> !RefUnwindSafe for CodeGeneratingVisitor<'a>
impl<'a> !Send for CodeGeneratingVisitor<'a>
impl<'a> !Sync for CodeGeneratingVisitor<'a>
impl<'a> Unpin for CodeGeneratingVisitor<'a>
impl<'a> !UnwindSafe for CodeGeneratingVisitor<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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