Struct ketos::interpreter::Interpreter
[−]
[src]
pub struct Interpreter { /* fields omitted */ }
Provides a context in which to compile and execute code.
Values created by one interpreter are exclusive to that interpreter.
They should not be passed directly into another interpreter.
Specifically, unexpected behavior or a panic may occur if another
interpreter attempts to operate on Name
/Keyword
values created by
another interpreter or any values which may contain arbitrary values
(Struct
, StructDef
, List
, Lambda
, Quote
, etc.).
Methods
impl Interpreter
[src]
fn new() -> Interpreter
Creates a new Interpreter
.
fn with_loader(loader: Box<ModuleLoader>) -> Interpreter
Creates a new Interpreter
using the given ModuleLoader
instance.
fn with_context(context: Context) -> Interpreter
Creates a new Interpreter
using the given Context
instance.
fn with_scope(scope: Scope) -> Interpreter
Creates a new Interpreter
using the given Scope
instance.
fn with_search_paths(paths: Vec<PathBuf>) -> Interpreter
Creates a new Interpreter
that searches for module files in a given
series of directories.
fn clear_codemap(&self)
Clears cached source from the contained CodeMap
.
Note
This will invalidate any previously created ParseError
values.
fn display_error(&self, e: &Error)
Prints an error to stderr
.
fn display_trace(&self, trace: &Trace)
Prints traceback information to stderr
.
fn display_value(&self, value: &Value)
Prints a string representation of a value to stdout
.
fn format_error(&self, e: &Error) -> String
Formats an error into a String
.
fn format_trace(&self, trace: &Trace) -> String
Formats a Trace
into a String
.
The result does not include the "Traceback:"
preamble.
fn get_traceback(&self) -> Option<Trace>
Returns the traceback from the most recent error.
The traceback will remain stored for future calls to get_traceback
.
fn take_traceback(&self) -> Option<Trace>
Removes and returns the traceback from the most recent error.
fn format_value(&self, value: &Value) -> String
Formats a value into a string.
fn execute(&self, code: Code) -> Result<Value, Error>
Executes a bare Code
object taking no parameters.
fn execute_code(&self, code: Rc<Code>) -> Result<Value, Error>
Executes a Rc<Code>
object taking no parameters.
fn execute_program(&self, code: Vec<Code>) -> Result<Value, Error>
Executes a series of code objects sequentially and returns the value
of the final expression. If code
is empty, the value ()
is returned.
fn call(&self, name: &str, args: Vec<Value>) -> Result<Value, Error>
Calls a named function with the given arguments.
fn call_value(&self, value: Value, args: Vec<Value>) -> Result<Value, Error>
Calls a function with the given arguments.
fn get_value(&self, name: &str) -> Option<Value>
Returns a value, if present, in the interpreter scope.
fn context(&self) -> &Context
Returns a borrowed reference to the contained context.
fn scope(&self) -> &Scope
Returns a borrowed reference to the contained scope.
fn set_args<T: AsRef<str>>(&self, args: &[T])
Sets the value of argv
within the execution scope.
fn run_file(&self, path: &Path) -> Result<(), Error>
Compiles and executes the contents of a file.
fn run_single_expr(&self,
input: &str,
path: Option<String>)
-> Result<Value, Error>
input: &str,
path: Option<String>)
-> Result<Value, Error>
Compiles and executes an input expression.
fn run_code(&self, input: &str, path: Option<String>) -> Result<Value, Error>
Parses and executes a series of expressions and return the last value.
fn compile_single_expr(&self,
input: &str,
path: Option<String>)
-> Result<Code, Error>
input: &str,
path: Option<String>)
-> Result<Code, Error>
Compiles and compiles a single expression and returns a code object. If the input string contains more than one expression, an error is returned.
fn compile_exprs(&self, input: &str) -> Result<Vec<Code>, Error>
Compiles and compiles a series of expressions.
fn parse_single_expr(&self,
input: &str,
path: Option<String>)
-> Result<Value, Error>
input: &str,
path: Option<String>)
-> Result<Value, Error>
Parses a single expression and returns it as a Value
.
If input
contains more than one expression, an error is returned.
fn parse_exprs(&self,
input: &str,
path: Option<String>)
-> Result<Vec<Value>, Error>
input: &str,
path: Option<String>)
-> Result<Vec<Value>, Error>
Parses a series of expressions and returns them as Value
s.
fn parse_file(&self,
input: &str,
path: Option<String>)
-> Result<Vec<Value>, Error>
input: &str,
path: Option<String>)
-> Result<Vec<Value>, Error>
Parses a series of expressions from the contents of a file and
returns them as Value
s.
Trait Implementations
impl Clone for Interpreter
[src]
fn clone(&self) -> Interpreter
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more