Module

Struct Module 

Source
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: bool

Implementations§

Source§

impl Module

Source

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

pub fn access_field( &mut self, value: Value, expr: &Expr, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>

Access a field of a value.

§Arguments
  • value - The Value to access the field of.
  • expr - The Expr representing the field to access.
  • ctx - The context in which to access the field.
§Returns

The value of the field.

Source§

impl Module

Source

pub fn interpret_then_else( &mut self, then_else: ThenElse, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>

Interpret a then-else expression.

§Arguments
  • then_else - ThenElse expression to interpret.
  • ctx - The context in which to interpret the then-else expression.
  • vm - The virtual machine to use.
§Returns

The result of the then-else expression.

Source

pub fn interpret_if( &mut self, if_stmt: If, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Interpret an if statement.

§Arguments
  • if_stmt - If - The if statement to interpret.
  • ctx - Context - The context in which to interpret the statement.
Source§

impl Module

Source

pub fn interpret_try( &mut self, try_stmt: Try, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Interpret TryCatch expression.

§Arguments
  • try_catch - TryCatch expression to interpret.
  • ctx - The context in which to interpret the TryCatch expression.
§Returns

The result of the TryCatch expression.

Source

pub fn interpret_throw( &mut self, throw: Throw, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Interpret a throw statement.

§Arguments
  • throw_stmt - The throw statement to interpret.
  • ctx - The context in which to interpret the statement.
§Returns

The result of the throw statement.

Source§

impl Module

Source

pub fn interpret_expr( &mut self, expr: &Expr, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Interpret an expression.

Result of the expression is pushed onto the stack.

§Arguments
  • expr - Expr to interpret.
  • ctx - The context in which to interpret the expression.
§Returns

The result of the expression.

Source

pub fn interpret_unary( &mut self, u: Unary, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>

Interpret a unary expression.

§Arguments
  • unary - Unary expression to interpret.
  • ctx - The context in which to interpret the unary expression.
  • vm - The virtual machine to use.
§Returns

The result of the unary expression.

Source

pub fn interpret_vec( &mut self, vec: VecExpr, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>

Interpret a vector expression.

§Arguments
  • vec - VecExpr to interpret.
  • ctx - The context in which to interpret the vector expression.
§Returns

The result of the vector expression.

Source

pub fn interpret_binary( &mut self, binary_expr: Binary, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>

Interpret a binary expression.

§Arguments
  • binary_expr - Binary expression to interpret.
  • ctx - The context in which to interpret the binary expression.
§Returns

The result of the binary expression.

Source

pub fn interpret_spread( &mut self, s: Spread, ctx: &mut Context, vm: &mut VM, values: &mut Vec<Value>, ) -> Result<()>

Interpret a spread expression.

This function requires vec of values to push to.

§Arguments
  • expr - Expr to interpret.
  • ctx - The context in which to interpret the expression.
  • values - The vec of values to push to.
§Returns

The result of the expression.

Source

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

pub fn interpret_assignment( &mut self, assign: Assign, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>

Interpret an assignment expression.

§Arguments
  • assign - Assign expression to interpret.
  • ctx - The context in which to interpret the assignment expression.
§Returns

The result of the assignment expression.

Source§

impl Module

Source

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

pub fn execute_user_defined_function( &mut self, function: Fn, def_module: &mut Module, args: Vec<Value>, ctx: &mut Context, vm: &mut VM, call: &CallExpr, ) -> Result<()>

Executes a user-defined function with the provided arguments.

Source

pub fn interpret_call( &mut self, call: &CallExpr, ctx: &mut Context, vm: &mut VM, ) -> Result<Value>

Interpret a call expression.

§Arguments
  • call - CallExpr to interpret.
  • ctx - The context in which to interpret the call.
§Returns

The result of the call.

Source§

impl Module

Source

pub fn interpret_stmt( &mut self, stmt: Stmt, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Interpret statement from the module.

§Arguments
  • stmt - Stmt - The statement to interpret.
  • ctx - Context - The context in which to interpret the statement.
Source

pub fn interpret_let( &mut self, l: Let, vm: &mut VM, ctx: &mut Context, ) -> Result<()>

Interpret a let statement.

§Arguments
  • let_stmt - Let - The let statement to interpret.
  • vm - VM - The virtual machine to use for interpretation.
  • ctx - Context - The context in which to interpret the statement.
Source

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.
Source

pub fn interpret_loop( &mut self, loop_stmt: Loop, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Interpret a loop statement.

§Arguments
  • loop_stmt - Loop - The loop to interpret.
  • ctx - Context - The context in which to interpret the loop.
Source

pub fn interpret_while( &mut self, while_stmt: While, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Interpret a while loop.

§Arguments
  • while_stmt - While - The while loop to interpret.
  • ctx - Context - The context in which to interpret the while loop.
Source

pub fn interpret_function( &mut self, function: Fn, ctx: &mut Context, ) -> Result<()>

Interpret a function declaration.

§Arguments
  • function - Fn - The function to interpret.
  • ctx - Context - The context in which to interpret the function.
Source

pub fn interpret_use( &mut self, u: Use, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Interpret an use statement.

§Arguments
  • use_stmt - Use - The use statement to interpret.
  • ctx - Context - The context in which to interpret the statement.
Source

pub fn execute_block( &mut self, block: Block, ctx: &mut Context, vm: &mut VM, ) -> Result<()>

Execute a block of statements within a new scope.

§Arguments
  • block - Block - The block of statements to execute.
Source§

impl Module

Source

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.
Source

pub fn interpret_trait_impl( &mut self, impl_stmt: TraitImpl, ctx: &mut Context, ) -> Result<()>

Interpret a trait implementation.

§Arguments
  • impl_stmt - TraitImpl - The trait implementation to interpret.
Source

pub fn get_trait(&self, name: &str, span: TextSpan) -> Result<TraitDef>

Source

pub fn get_struct(&self, name: &str, span: TextSpan) -> Result<StoredStruct>

Source

pub fn interpret_struct( &mut self, struct_stmt: Struct, ctx: &mut Context, ) -> Result<()>

Interpret a struct definition.

§Arguments
  • struct_def - Struct - The struct definition to interpret.
  • ctx - Context - The context in which to interpret the struct definition.
§Returns

The result of interpreting the struct definition.

Source

pub fn interpret_trait( &mut self, trait_stmt: TraitDef, ctx: &mut Context, ) -> Result<()>

Interpret trait definition.

§Arguments
  • trait_def - TraitDef - The trait definition to interpret.
  • ctx - Context - The context in which to interpret the trait definition.
§Returns

The result of interpreting the trait definition.

Source

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

Source

pub fn new(source: Source) -> Self

Creates a new Module from the specified Source.

§Parameters
  • source - The source of the module.
§Returns

An Arc<Mutex<Self>> containing the new Module.

Source

pub fn set_lex_comments(&mut self, lex_comments: bool)

Source

pub fn id(&self) -> String

Get module id

Source

pub fn path(&self) -> Option<PathBuf>

Returns the path of the module.

Source

pub fn source(&self) -> &Source

Returns the source of the module.

Source

pub fn tokens(&self) -> &Vec<Token>

Returns tokens of the module.

Source

pub fn parse(&mut self) -> Result<()>

Parses the module.

First, the module is lexed into tokens. Then, the tokens are parsed into an AST.

Source

pub fn interpret(&mut self, ctx: &mut Context, vm: &mut VM) -> Result<()>

Source

pub fn enter_scope(&mut self)

Enter a new scope by pushing a new HashMap onto the scopes stack.

Source

pub fn exit_scope(&mut self)

Exit the current scope by popping the top HashMap from the scopes stack.

Source

pub fn declare_variable(&mut self, name: String, val: Value)

Declare a new variable in the current (innermost) scope.

Source

pub fn set_variable(&mut self, name: &str, val: Value) -> Result<()>

Set an existing variable’s value in the nearest enclosing scope.

Source

pub fn find_variable(&self, name: &str) -> Option<&Value>

Finds a variable by name, searching from the innermost scope outward.

Source

pub fn find_const(&self, name: &str) -> Option<&StoredConst>

Finds a constant by name.

Source

pub fn name(&self) -> String

Source

pub fn extract_variable_name(expr: &Expr) -> Option<String>

Source

pub fn find_function(&self, name: &str) -> Option<&StoredFunction>

Finds a function by name.

Source

pub fn update_variable( &mut self, name: &str, val: Value, func: fn(Value, Value) -> Value, ) -> Result<()>

Trait Implementations§

Source§

impl Clone for Module

Source§

fn clone(&self) -> Module

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Module

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Module

§

impl RefUnwindSafe for Module

§

impl Send for Module

§

impl Sync for Module

§

impl Unpin for Module

§

impl UnwindSafe for Module

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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