[−][src]Trait gluon::ThreadExt
Extension trait which provides methods to load and execute gluon code
Required methods
fn get_database(&self) -> DatabaseSnapshot
fn get_database_mut(&self) -> DatabaseMut
Provided methods
fn run_io(&self, run: bool)
fn module_compiler<'a>(
&'a self,
database: &'a CompilerDatabase
) -> ModuleCompiler<'a>
&'a self,
database: &'a CompilerDatabase
) -> ModuleCompiler<'a>
fn parse_expr(
&self,
type_cache: &TypeCache<Symbol, ArcType>,
file: &str,
expr_str: &str
) -> StdResult<SpannedExpr<Symbol>, InFile<Error>>
&self,
type_cache: &TypeCache<Symbol, ArcType>,
file: &str,
expr_str: &str
) -> StdResult<SpannedExpr<Symbol>, InFile<Error>>
Parse expr_str
, returning an expression if successful
fn parse_partial_expr(
&self,
type_cache: &TypeCache<Symbol, ArcType>,
file: &str,
expr_str: &str
) -> SalvageResult<SpannedExpr<Symbol>, InFile<Error>>
&self,
type_cache: &TypeCache<Symbol, ArcType>,
file: &str,
expr_str: &str
) -> SalvageResult<SpannedExpr<Symbol>, InFile<Error>>
Parse input
, returning an expression if successful
fn typecheck_expr(
&self,
file: &str,
expr_str: &str,
expr: &mut SpannedExpr<Symbol>
) -> Result<ArcType>
&self,
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(
&self,
file: &str,
expr_str: &str,
expected_type: Option<&ArcType>
) -> Result<(Arc<SpannedExpr<Symbol>>, ArcType)>
&self,
file: &str,
expr_str: &str,
expected_type: Option<&ArcType>
) -> Result<(Arc<SpannedExpr<Symbol>>, ArcType)>
fn compile_script(
&self,
filename: &str,
expr_str: &str,
expr: &SpannedExpr<Symbol>
) -> Result<CompiledModule>
&self,
filename: &str,
expr_str: &str,
expr: &SpannedExpr<Symbol>
) -> Result<CompiledModule>
Compiles expr
into a function which can be added and run by the vm
fn compile_to_bytecode<S>(
&self,
name: &str,
expr_str: &str,
serializer: S
) -> StdResult<S::Ok, Either<Error, S::Error>> where
S: Serializer,
S::Error: 'static,
&self,
name: &str,
expr_str: &str,
serializer: S
) -> StdResult<S::Ok, Either<Error, S::Error>> where
S: Serializer,
S::Error: 'static,
Compiles the source code expr_str
into bytecode serialized using serializer
fn load_bytecode<'vm, D>(
&'vm self,
name: &str,
deserializer: D
) -> BoxFuture<'vm, (), Error> where
D: Deserializer<'vm> + 'vm,
D::Error: Send + Sync,
&'vm self,
name: &str,
deserializer: D
) -> BoxFuture<'vm, (), Error> where
D: Deserializer<'vm> + 'vm,
D::Error: Send + Sync,
Loads bytecode from a Deserializer
and stores it into the module name
.
load_script
is equivalent to compile_to_bytecode
followed by load_bytecode
fn extract_metadata(
&self,
file: &str,
expr_str: &str
) -> Result<(Arc<SpannedExpr<Symbol>>, ArcType, Arc<Metadata>)>
&self,
file: &str,
expr_str: &str
) -> Result<(Arc<SpannedExpr<Symbol>>, ArcType, Arc<Metadata>)>
Parses and typechecks expr_str
followed by extracting metadata from the created
expression
fn load_script(&self, 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>(
&self,
filename: &str,
input: &str
) -> BoxFuture<'vm, (), Error>
&self,
filename: &str,
input: &str
) -> BoxFuture<'vm, (), Error>
fn load_file<'vm>(&'vm self, filename: &str) -> Result<()>
Loads filename
and compiles and runs its input by calling load_script
fn load_file_async<'vm>(&self, filename: &str) -> BoxFuture<'static, (), Error>
fn run_expr<'vm, T>(
&'vm self,
name: &str,
expr_str: &str
) -> Result<(T, ArcType)> where
T: for<'value> Getable<'vm, 'value> + VmType + Send + 'vm,
&'vm self,
name: &str,
expr_str: &str
) -> Result<(T, ArcType)> where
T: for<'value> Getable<'vm, 'value> + 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, _) = vm .run_expr::<String>( "example", " let string = import! \"std/string.glu\" in string.trim \" Hello world \t\" " ) .unwrap(); assert_eq!(result, "Hello world");
fn run_expr_async<T>(
&self,
name: &str,
expr_str: &str
) -> BoxFuture<'static, (T, ArcType), Error> where
T: for<'vm, 'value> Getable<'vm, 'value> + VmType + Send + 'static,
&self,
name: &str,
expr_str: &str
) -> BoxFuture<'static, (T, ArcType), Error> where
T: for<'vm, 'value> Getable<'vm, 'value> + VmType + Send + 'static,
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 = vm .run_expr::<String>("example", " let string = import! \"std/string.glu\" in string.trim \" Hello world \t\" ") .unwrap(); let expected = ("Hello world".to_string(), Type::string()); assert_eq!(result, expected); }
fn format_expr(
&self,
formatter: &mut Formatter,
file: &str,
input: &str
) -> Result<String>
&self,
formatter: &mut Formatter,
file: &str,
input: &str
) -> Result<String>