pub struct Module {
pub source: Source,
pub path: Option<PathBuf>,
pub tokens: Vec<Token>,
pub ast: Ast,
pub functions: Vec<StoredFunction>,
pub exports: Vec<(String, ExportType)>,
pub scopes: Vec<HashMap<String, Value>>,
pub structs: Vec<StoredStruct>,
pub traits: Vec<TraitDef>,
pub consts: Vec<StoredConst>,
pub id: String,
pub lex_comments: bool,
}Fields§
§source: Source§path: Option<PathBuf>§tokens: Vec<Token>§ast: Ast§functions: Vec<StoredFunction>§exports: Vec<(String, ExportType)>§scopes: Vec<HashMap<String, Value>>§structs: Vec<StoredStruct>§traits: Vec<TraitDef>§consts: Vec<StoredConst>§id: String§lex_comments: boolImplementations§
Source§impl Module
impl Module
Sourcepub fn interpret_access(
&mut self,
access: AccessExpr,
ctx: &mut Context,
vm: &mut VM,
) -> Result<Value>
pub fn interpret_access( &mut self, access: AccessExpr, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>
Interpret an access expression.
§Arguments
access- AccessExpr expression to interpret.ctx- The context in which to interpret the access expression.vm- The virtual machine to use.
§Returns
The result of the access expression.
Source§impl Module
impl Module
Source§impl Module
impl Module
Source§impl Module
impl Module
Sourcepub fn interpret_expr(
&mut self,
expr: &Expr,
ctx: &mut Context,
vm: &mut VM,
) -> Result<()>
pub fn interpret_expr( &mut self, expr: &Expr, ctx: &mut Context, vm: &mut VM, ) -> Result<()>
Sourcepub fn interpret_unary(
&mut self,
u: Unary,
ctx: &mut Context,
vm: &mut VM,
) -> Result<Value>
pub fn interpret_unary( &mut self, u: Unary, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>
Sourcepub fn interpret_vec(
&mut self,
vec: VecExpr,
ctx: &mut Context,
vm: &mut VM,
) -> Result<Value>
pub fn interpret_vec( &mut self, vec: VecExpr, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>
Sourcepub fn interpret_binary(
&mut self,
binary_expr: Binary,
ctx: &mut Context,
vm: &mut VM,
) -> Result<Value>
pub fn interpret_binary( &mut self, binary_expr: Binary, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>
Sourcepub fn interpret_spread(
&mut self,
s: Spread,
ctx: &mut Context,
vm: &mut VM,
values: &mut Vec<Value>,
) -> Result<()>
pub fn interpret_spread( &mut self, s: Spread, ctx: &mut Context, vm: &mut VM, values: &mut Vec<Value>, ) -> Result<()>
Sourcepub fn interpret_possible_spread(
&mut self,
exprs: Vec<Expr>,
ctx: &mut Context,
vm: &mut VM,
) -> Result<Vec<Value>>
pub fn interpret_possible_spread( &mut self, exprs: Vec<Expr>, ctx: &mut Context, vm: &mut VM, ) -> Result<Vec<Value>>
Helper function to interpret possible spread expressions.
§Arguments
exprs- The expressions to interpret.ctx- The context in which to interpret the expressions.vm- The virtual machine to use.
Source§impl Module
impl Module
Sourcepub fn execute_native_function(
&mut self,
native: NativeFunction,
args: Vec<Value>,
vm: &mut VM,
) -> Result<()>
pub fn execute_native_function( &mut self, native: NativeFunction, args: Vec<Value>, vm: &mut VM, ) -> Result<()>
Executes a native function with the provided arguments.
Source§impl Module
impl Module
Sourcepub fn handle_loop_result(&mut self, result: Result<()>) -> Result<()>
pub fn handle_loop_result(&mut self, result: Result<()>) -> Result<()>
Handle the result of a loop statement.
RoanError::LoopBreak and RoanError::LoopContinue are handled if they are inside a loop otherwise they are returned as an error.
§Arguments
result- [Result<()>] - The result to handle.
Sourcepub fn interpret_loop(
&mut self,
loop_stmt: Loop,
ctx: &mut Context,
vm: &mut VM,
) -> Result<()>
pub fn interpret_loop( &mut self, loop_stmt: Loop, ctx: &mut Context, vm: &mut VM, ) -> Result<()>
Sourcepub fn interpret_while(
&mut self,
while_stmt: While,
ctx: &mut Context,
vm: &mut VM,
) -> Result<()>
pub fn interpret_while( &mut self, while_stmt: While, ctx: &mut Context, vm: &mut VM, ) -> Result<()>
Source§impl Module
impl Module
Sourcepub fn interpret_struct_impl(
&mut self,
impl_stmt: StructImpl,
ctx: &mut Context,
) -> Result<()>
pub fn interpret_struct_impl( &mut self, impl_stmt: StructImpl, ctx: &mut Context, ) -> Result<()>
Interpret a struct implementation.
§Arguments
impl_stmt-StructImpl- The struct implementation to interpret.
Sourcepub fn interpret_trait_impl(
&mut self,
impl_stmt: TraitImpl,
ctx: &mut Context,
) -> Result<()>
pub fn interpret_trait_impl( &mut self, impl_stmt: TraitImpl, ctx: &mut Context, ) -> Result<()>
pub fn get_trait(&self, name: &str, span: TextSpan) -> Result<TraitDef>
pub fn get_struct(&self, name: &str, span: TextSpan) -> Result<StoredStruct>
Sourcepub fn interpret_struct_constructor(
&mut self,
constructor: StructConstructor,
ctx: &mut Context,
vm: &mut VM,
) -> Result<Value>
pub fn interpret_struct_constructor( &mut self, constructor: StructConstructor, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>
Interpret a struct constructor expression.
§Arguments
constructor- StructConstructor expression to interpret.ctx- The context in which to interpret the struct constructor expression.vm- The virtual machine to use.
§Returns
The result of the struct constructor expression.
Source§impl Module
impl Module
pub fn set_lex_comments(&mut self, lex_comments: bool)
Sourcepub fn parse(&mut self) -> Result<()>
pub fn parse(&mut self) -> Result<()>
Parses the module.
First, the module is lexed into tokens. Then, the tokens are parsed into an AST.
pub fn interpret(&mut self, ctx: &mut Context, vm: &mut VM) -> Result<()>
Sourcepub fn enter_scope(&mut self)
pub fn enter_scope(&mut self)
Enter a new scope by pushing a new HashMap onto the scopes stack.
Sourcepub fn exit_scope(&mut self)
pub fn exit_scope(&mut self)
Exit the current scope by popping the top HashMap from the scopes stack.
Sourcepub fn declare_variable(&mut self, name: String, val: Value)
pub fn declare_variable(&mut self, name: String, val: Value)
Declare a new variable in the current (innermost) scope.
Sourcepub fn set_variable(&mut self, name: &str, val: Value) -> Result<()>
pub fn set_variable(&mut self, name: &str, val: Value) -> Result<()>
Set an existing variable’s value in the nearest enclosing scope.
Sourcepub fn find_variable(&self, name: &str) -> Option<&Value>
pub fn find_variable(&self, name: &str) -> Option<&Value>
Finds a variable by name, searching from the innermost scope outward.
Sourcepub fn find_const(&self, name: &str) -> Option<&StoredConst>
pub fn find_const(&self, name: &str) -> Option<&StoredConst>
Finds a constant by name.
pub fn name(&self) -> String
pub fn extract_variable_name(expr: &Expr) -> Option<String>
Sourcepub fn find_function(&self, name: &str) -> Option<&StoredFunction>
pub fn find_function(&self, name: &str) -> Option<&StoredFunction>
Finds a function by name.