Struct gluon::Compiler
[−]
[src]
pub struct Compiler { /* fields omitted */ }
Type which makes parsing, typechecking and compiling an AST into bytecode
Methods
impl Compiler
[src]
fn new() -> Compiler
Creates a new compiler with default settings
fn implicit_prelude(self, implicit_prelude: bool) -> Compiler
Sets whether the implicit prelude should be include when compiling a file using this compiler (default: true)
fn emit_debug_info(self, emit_debug_info: bool) -> Compiler
Sets whether the compiler should emit debug information such as source maps and variable names. (default: true)
fn mut_symbols(&mut self) -> &mut Symbols
fn parse_expr(
&mut self,
file: &str,
expr_str: &str
) -> StdResult<SpannedExpr<Symbol>, InFile<Error>>
&mut self,
file: &str,
expr_str: &str
) -> StdResult<SpannedExpr<Symbol>, InFile<Error>>
Parse expr_str
, returning an expression if successful
fn parse_partial_expr(
&mut self,
file: &str,
expr_str: &str
) -> StdResult<SpannedExpr<Symbol>, (Option<SpannedExpr<Symbol>>, InFile<Error>)>
&mut self,
file: &str,
expr_str: &str
) -> StdResult<SpannedExpr<Symbol>, (Option<SpannedExpr<Symbol>>, InFile<Error>)>
Parse input
, returning an expression if successful
fn typecheck_expr(
&mut self,
vm: &Thread,
file: &str,
expr_str: &str,
expr: &mut SpannedExpr<Symbol>
) -> Result<ArcType>
&mut self,
vm: &Thread,
file: &str,
expr_str: &str,
expr: &mut SpannedExpr<Symbol>
) -> Result<ArcType>
Parse and typecheck expr_str
returning the typechecked expression and type of the
expression
fn typecheck_str(
&mut self,
vm: &Thread,
file: &str,
expr_str: &str,
expected_type: Option<&ArcType>
) -> Result<(SpannedExpr<Symbol>, ArcType)>
&mut self,
vm: &Thread,
file: &str,
expr_str: &str,
expected_type: Option<&ArcType>
) -> Result<(SpannedExpr<Symbol>, ArcType)>
fn compile_script(
&mut self,
vm: &Thread,
filename: &str,
expr_str: &str,
expr: &SpannedExpr<Symbol>
) -> Result<CompiledFunction>
&mut self,
vm: &Thread,
filename: &str,
expr_str: &str,
expr: &SpannedExpr<Symbol>
) -> Result<CompiledFunction>
Compiles expr
into a function which can be added and run by the vm
fn extract_metadata(
&mut self,
vm: &Thread,
file: &str,
expr_str: &str
) -> Result<(SpannedExpr<Symbol>, ArcType, Metadata)>
&mut self,
vm: &Thread,
file: &str,
expr_str: &str
) -> Result<(SpannedExpr<Symbol>, ArcType, Metadata)>
Parses and typechecks expr_str
followed by extracting metadata from the created
expression
fn load_script(
&mut self,
vm: &Thread,
filename: &str,
input: &str
) -> Result<()>
&mut self,
vm: &Thread,
filename: &str,
input: &str
) -> Result<()>
Compiles input
and if it is successful runs the resulting code and stores the resulting
value in the vm.
If at any point the function fails the resulting error is returned and nothing is added to the VM.
fn load_script_async<'vm>(
&mut self,
vm: &'vm Thread,
filename: &str,
input: &str
) -> BoxFutureValue<'vm, (), Error>
&mut self,
vm: &'vm Thread,
filename: &str,
input: &str
) -> BoxFutureValue<'vm, (), Error>
fn load_file<'vm>(&mut self, vm: &'vm Thread, filename: &str) -> Result<()>
Loads filename
and compiles and runs its input by calling load_script
fn load_file_async<'vm>(
&mut self,
vm: &'vm Thread,
filename: &str
) -> BoxFutureValue<'vm, (), Error>
&mut self,
vm: &'vm Thread,
filename: &str
) -> BoxFutureValue<'vm, (), Error>
fn run_expr<'vm, T>(
&mut self,
vm: &'vm Thread,
name: &str,
expr_str: &str
) -> Result<(T, ArcType)> where
T: Getable<'vm> + VmType + Send + 'vm,
&mut self,
vm: &'vm Thread,
name: &str,
expr_str: &str
) -> Result<(T, ArcType)> where
T: Getable<'vm> + VmType + Send + 'vm,
Compiles and runs the expression in expr_str
. If successful the value from running the
expression is returned
Examples
Import from gluon's standard library and evaluate a string
let vm = new_vm(); let (result, _) = Compiler::new() .run_expr::<String>(&vm, "example", " let string = import! \"std/string.glu\" in string.trim \" Hello world \t\" ") .unwrap(); assert_eq!(result, "Hello world");
fn run_expr_async<'vm, T>(
&mut self,
vm: &'vm Thread,
name: &str,
expr_str: &str
) -> BoxFutureValue<'vm, (T, ArcType), Error> where
T: Getable<'vm> + VmType + Send + 'vm,
&mut self,
vm: &'vm Thread,
name: &str,
expr_str: &str
) -> BoxFutureValue<'vm, (T, ArcType), Error> where
T: Getable<'vm> + VmType + Send + 'vm,
Compiles and runs the expression in expr_str
. If successful the value from running the
expression is returned
Examples
Import from gluon's standard library and evaluate a string
let vm = new_vm(); let result = Compiler::new() .run_expr_async::<String>(&vm, "example", " let string = import! \"std/string.glu\" in string.trim \" Hello world \t\" ") .sync_or_error() .unwrap(); let expected = ("Hello world".to_string(), Type::string()); assert_eq!(result, expected); }
fn run_io_expr<'vm, T>(
&mut self,
vm: &'vm Thread,
name: &str,
expr_str: &str
) -> Result<(T, ArcType)> where
T: Getable<'vm> + VmType + Send + 'vm,
T::Type: Sized,
&mut self,
vm: &'vm Thread,
name: &str,
expr_str: &str
) -> Result<(T, ArcType)> where
T: Getable<'vm> + VmType + Send + 'vm,
T::Type: Sized,
Compiles and runs expr_str
. If the expression is of type IO a
the action is evaluated
and a value of type a
is returned
fn run_io_expr_async<'vm, T>(
&mut self,
vm: &'vm Thread,
name: &str,
expr_str: &str
) -> BoxFutureValue<'vm, (T, ArcType), Error> where
T: Getable<'vm> + VmType + Send + 'vm,
T::Type: Sized,
&mut self,
vm: &'vm Thread,
name: &str,
expr_str: &str
) -> BoxFutureValue<'vm, (T, ArcType), Error> where
T: Getable<'vm> + VmType + Send + 'vm,
T::Type: Sized,