[−][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 mut CompilerDatabase
) -> ModuleCompiler<'a>
&'a self,
database: &'a mut CompilerDatabase
) -> ModuleCompiler<'a>
fn parse_expr(
&self,
type_cache: &TypeCache<Symbol, ArcType>,
file: &str,
expr_str: &str
) -> StdResult<OwnedExpr<Symbol>, InFile<Error>>
&self,
type_cache: &TypeCache<Symbol, ArcType>,
file: &str,
expr_str: &str
) -> StdResult<OwnedExpr<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<OwnedExpr<Symbol>, InFile<Error>>
&self,
type_cache: &TypeCache<Symbol, ArcType>,
file: &str,
expr_str: &str
) -> SalvageResult<OwnedExpr<Symbol>, InFile<Error>>
Parse input
, returning an expression if successful
fn typecheck_expr<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
file: &'life1 str,
expr_str: &'life2 str,
expr: &'life3 mut OwnedExpr<Symbol>
) -> Pin<Box<dyn Future<Output = Result<ArcType>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
&'life0 self,
file: &'life1 str,
expr_str: &'life2 str,
expr: &'life3 mut OwnedExpr<Symbol>
) -> Pin<Box<dyn Future<Output = Result<ArcType>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
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<OwnedExpr<Symbol>>, ArcType)>
&self,
file: &str,
expr_str: &str,
expected_type: Option<&ArcType>
) -> Result<(Arc<OwnedExpr<Symbol>>, ArcType)>
fn typecheck_str_async<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
file: &'life1 str,
expr_str: &'life2 str,
expected_type: Option<&'life3 ArcType>
) -> Pin<Box<dyn Future<Output = Result<(Arc<OwnedExpr<Symbol>>, ArcType)>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
&'life0 self,
file: &'life1 str,
expr_str: &'life2 str,
expected_type: Option<&'life3 ArcType>
) -> Pin<Box<dyn Future<Output = Result<(Arc<OwnedExpr<Symbol>>, ArcType)>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn compile_script<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
filename: &'life1 str,
expr_str: &'life2 str,
expr: &'life3 OwnedExpr<Symbol>
) -> Pin<Box<dyn Future<Output = Result<CompiledModule>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
&'life0 self,
filename: &'life1 str,
expr_str: &'life2 str,
expr: &'life3 OwnedExpr<Symbol>
) -> Pin<Box<dyn Future<Output = Result<CompiledModule>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Compiles expr
into a function which can be added and run by the vm
fn compile_to_bytecode<'life0, 'life1, 'life2, 'async_trait, S>(
&'life0 self,
name: &'life1 str,
expr_str: &'life2 str,
serializer: S
) -> Pin<Box<dyn Future<Output = StdResult<S::Ok, Either<Error, S::Error>>> + Send + 'async_trait>> where
S: Serializer + Send,
S::Error: 'static,
S: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
&'life0 self,
name: &'life1 str,
expr_str: &'life2 str,
serializer: S
) -> Pin<Box<dyn Future<Output = StdResult<S::Ok, Either<Error, S::Error>>> + Send + 'async_trait>> where
S: Serializer + Send,
S::Error: 'static,
S: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Compiles the source code expr_str
into bytecode serialized using serializer
fn load_bytecode<'vm, 'life0, 'life1, 'async_trait, D, E>(
&'life0 self,
name: &'life1 str,
deserializer: D
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
D: for<'de> Deserializer<'de, Error = E> + Send,
E: Send + Sync,
'vm: 'async_trait,
D: 'async_trait,
E: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
&'life0 self,
name: &'life1 str,
deserializer: D
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
D: for<'de> Deserializer<'de, Error = E> + Send,
E: Send + Sync,
'vm: 'async_trait,
D: 'async_trait,
E: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
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<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
file: &'life1 str,
expr_str: &'life2 str
) -> Pin<Box<dyn Future<Output = Result<(Arc<OwnedExpr<Symbol>>, ArcType, Arc<Metadata>)>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
&'life0 self,
file: &'life1 str,
expr_str: &'life2 str
) -> Pin<Box<dyn Future<Output = Result<(Arc<OwnedExpr<Symbol>>, ArcType, Arc<Metadata>)>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
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<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
filename: &'life1 str,
input: &'life2 str
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
&'life0 self,
filename: &'life1 str,
input: &'life2 str
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
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, 'life0, 'life1, 'async_trait>(
&'life0 self,
filename: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
'vm: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
&'life0 self,
filename: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
'vm: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
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<'vm, 'life0, 'life1, 'async_trait, T>(
&'vm self,
name: &'life0 str,
expr_str: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<(T, ArcType)>> + Send + 'async_trait>> where
T: for<'value> Getable<'vm, 'value> + VmType + Send + 'vm,
'vm: 'async_trait,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
&'vm self,
name: &'life0 str,
expr_str: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<(T, ArcType)>> + Send + 'async_trait>> where
T: for<'value> Getable<'vm, 'value> + VmType + Send + 'vm,
'vm: 'async_trait,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
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_async().await; let result = vm .run_expr_async::<String>("example", " let string = import! \"std/string.glu\" in string.trim \" Hello world \t\" ") .await .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>
fn format_expr_async<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
formatter: &'life1 mut Formatter,
file: &'life2 str,
input: &'life3 str
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
&'life0 self,
formatter: &'life1 mut Formatter,
file: &'life2 str,
input: &'life3 str
) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,