pub struct Thread { /* private fields */ }Expand description
Representation of the virtual machine
Implementations§
source§impl Thread
 
impl Thread
sourcepub fn new_thread(&self) -> Result<RootedThread, Error>
 
pub fn new_thread(&self) -> Result<RootedThread, Error>
Spawns a new gluon thread with its own stack and heap but while still sharing the same global environment
sourcepub fn root_thread(&self) -> RootedThread
 
pub fn root_thread(&self) -> RootedThread
Roots self, extending the lifetime of this thread until at least the returned
RootedThread is droppped
pub fn spawner(&self) -> Option<&(dyn Spawn + Send + Sync)>
sourcepub fn get_global<'vm, T>(&'vm self, name: &str) -> Result<T, Error>
 
pub fn get_global<'vm, T>(&'vm self, name: &str) -> Result<T, Error>
Retrieves the global called name.
Examples
Bind the (+) function in gluon’s prelude standard library
to an add function in rust
let vm = new_vm_async().await;
vm.run_expr_async::<OpaqueValue<&Thread, Hole>>("example", r#" import! std.int "#)
    .await
    .unwrap_or_else(|err| panic!("{}", err));
let mut add: FunctionRef<fn(i32, i32) -> i32> =
    vm.get_global("std.int.num.(+)").unwrap();
let result = add.call_async(1, 2).await;
assert_eq!(result, Ok(3));Errors
if the global does not exist or it does not have the correct type.
pub fn get_global_type(&self, name: &str) -> Result<ArcType, Error>
sourcepub fn find_type_info(
    &self,
    name: &str
) -> Result<Alias<Symbol, ArcType>, Error>
 
pub fn find_type_info( &self, name: &str ) -> Result<Alias<Symbol, ArcType>, Error>
Retrieves type information about the type name. Types inside records can be accessed
using dot notation (std.prelude.Option)
sourcepub fn register_type<T>(
    &self,
    name: &str,
    args: &[&str]
) -> Result<ArcType, Error>
 
pub fn register_type<T>( &self, name: &str, args: &[&str] ) -> Result<ArcType, Error>
Registers the type T as being a gluon type called name with generic arguments args
pub fn register_type_as( &self, name: Symbol, alias: Alias<Symbol, ArcType>, id: TypeId ) -> Result<ArcType, Error>
pub fn get_cache_alias(&self, name: &str) -> Option<ArcType>
pub fn cache_alias(&self, alias: Alias<Symbol, ArcType>) -> ArcType
sourcepub fn get_env<'b>(&'b self) -> VmEnvInstance<'b>
 
pub fn get_env<'b>(&'b self) -> VmEnvInstance<'b>
Locks and retrieves the global environment of the vm
sourcepub fn get_macros(&self) -> &MacroEnv
 
pub fn get_macros(&self) -> &MacroEnv
Retrieves the macros defined for this vm
sourcepub fn push<'vm, T>(&'vm self, v: T) -> Result<(), Error>where
    T: Pushable<'vm>,
 
pub fn push<'vm, T>(&'vm self, v: T) -> Result<(), Error>where
    T: Pushable<'vm>,
Pushes a value to the top of the stack
pub fn allocated_memory(&self) -> usize
pub fn set_memory_limit(&self, memory_limit: usize)
pub fn interrupt(&self)
pub fn interrupted(&self) -> bool
pub fn current_context(&self) -> ActiveThread<'_>
Trait Implementations§
source§impl<'de, 'gc> DeserializeState<'de, DeSeed<'gc>> for Thread
 
impl<'de, 'gc> DeserializeState<'de, DeSeed<'gc>> for Thread
source§fn deserialize_state<__D>(
    __seed: &mut DeSeed<'gc>,
    __deserializer: __D
) -> Result<Thread, <__D as Deserializer<'de>>::Error>where
    __D: Deserializer<'de>,
 
fn deserialize_state<__D>(
    __seed: &mut DeSeed<'gc>,
    __deserializer: __D
) -> Result<Thread, <__D as Deserializer<'de>>::Error>where
    __D: Deserializer<'de>,
Self using seed and the deserializersource§impl PartialEq for Thread
 
impl PartialEq for Thread
source§impl PostDeserialize for Thread
 
impl PostDeserialize for Thread
source§impl SerializeState<SeSeed> for Thread
 
impl SerializeState<SeSeed> for Thread
source§fn serialize_state<__S>(
    &self,
    __serializer: __S,
    __seed: &SeSeed
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
    __S: Serializer,
 
fn serialize_state<__S>(
    &self,
    __serializer: __S,
    __seed: &SeSeed
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
    __S: Serializer,
selfsource§impl ThreadExt for Thread
 
impl ThreadExt for Thread
fn get_database(&self) -> Snapshot<CompilerDatabase>
fn get_database_mut(&self) -> DatabaseMut
fn run_io(&self, run: bool)
fn module_compiler<'a, 'b>( &'a self, database: impl IntoDb<'a, 'b> ) -> ModuleCompiler<'a, 'b>
source§fn parse_expr(
    &self,
    type_cache: &TypeCache<Symbol, ArcType>,
    file: &str,
    expr_str: &str
) -> StdResult<OwnedExpr<Symbol>, InFile<Error>>
 
fn parse_expr( &self, type_cache: &TypeCache<Symbol, ArcType>, file: &str, expr_str: &str ) -> StdResult<OwnedExpr<Symbol>, InFile<Error>>
expr_str, returning an expression if successfulsource§fn parse_partial_expr(
    &self,
    type_cache: &TypeCache<Symbol, ArcType>,
    file: &str,
    expr_str: &str
) -> SalvageResult<OwnedExpr<Symbol>, InFile<Error>>
 
fn parse_partial_expr( &self, type_cache: &TypeCache<Symbol, ArcType>, file: &str, expr_str: &str ) -> SalvageResult<OwnedExpr<Symbol>, InFile<Error>>
input, returning an expression if successfulsource§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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
 
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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
expr_str returning the typechecked expression and type of the
expressionfn typecheck_str( &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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
source§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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: '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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
expr into a function which can be added and run by the vmsource§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 + 'async_trait,
    S::Error: 'static,
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
 
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 + 'async_trait,
    S::Error: 'static,
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
expr_str into bytecode serialized using serializersource§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 + 'async_trait,
    E: Send + Sync + 'async_trait,
    Self: 'async_trait,
    'vm: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
 
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 + 'async_trait,
    E: Send + Sync + 'async_trait,
    Self: 'async_trait,
    'vm: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
source§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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
 
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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
expr_str followed by extracting metadata from the created
expressionsource§fn load_script(&self, filename: &str, input: &str) -> Result<()>
 
fn load_script(&self, filename: &str, input: &str) -> Result<()>
input and if it is successful runs the resulting code and stores the resulting
value in the vm. Read morefn 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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
source§fn load_file<'vm>(&'vm self, filename: &str) -> Result<()>
 
fn load_file<'vm>(&'vm self, filename: &str) -> Result<()>
filename and compiles and runs its input by calling load_scriptfn load_file_async<'vm, 'life0, 'life1, 'async_trait>(
    &'life0 self,
    filename: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
    Self: 'async_trait,
    'vm: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
source§fn run_expr<'vm, T>(
    &'vm self,
    name: &str,
    expr_str: &str
) -> Result<(T, ArcType)>
 
fn run_expr<'vm, T>( &'vm self, name: &str, expr_str: &str ) -> Result<(T, ArcType)>
expr_str. If successful the value from running the
expression is returned Read moresource§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>>
 
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>>
expr_str. If successful the value from running the
expression is returned Read morefn format_expr( &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
    Self: 'async_trait,
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    'life3: 'async_trait,
source§impl ThreadInternal for Thread
 
impl ThreadInternal for Thread
source§fn root_value<'vm, T>(&'vm self, value: Variants<'_>) -> RootedValue<T>where
    T: VmRoot<'vm>,
 
fn root_value<'vm, T>(&'vm self, value: Variants<'_>) -> RootedValue<T>where
    T: VmRoot<'vm>,
Roots a value
source§fn execute_io<'life0, 'life1, 'async_trait>(
    &'life0 self,
    value: Variants<'life1>
) -> Pin<Box<dyn Future<Output = Result<RootedValue<RootedThread>, Error>> + Send + 'async_trait>>where
    'life0: 'async_trait,
    'life1: 'async_trait,
    Thread: 'async_trait,
 
fn execute_io<'life0, 'life1, 'async_trait>(
    &'life0 self,
    value: Variants<'life1>
) -> Pin<Box<dyn Future<Output = Result<RootedValue<RootedThread>, Error>> + Send + 'async_trait>>where
    'life0: 'async_trait,
    'life1: 'async_trait,
    Thread: 'async_trait,
Calls a module, allowed to to run IO expressions
source§fn call_function<'b>(
    &'b self,
    cx: &mut Context<'_>,
    context: OwnedContext<'b>,
    args: u32
) -> Poll<Result<Option<OwnedContext<'b>>, Error>>
 
fn call_function<'b>( &'b self, cx: &mut Context<'_>, context: OwnedContext<'b>, args: u32 ) -> Poll<Result<Option<OwnedContext<'b>>, Error>>
Calls a function on the stack.
When this function is called it is expected that the function exists at
stack.len() - args - 1 and that the arguments are of the correct type
source§fn context(&self) -> OwnedContext<'_>
 
fn context(&self) -> OwnedContext<'_>
source§fn call_thunk<'life0, 'life1, 'async_trait>(
    &'life0 self,
    closure: &'life1 GcPtr<ClosureData>
) -> Pin<Box<dyn Future<Output = Result<RootedValue<RootedThread>, Error>> + Send + 'async_trait>>where
    'life0: 'async_trait,
    'life1: 'async_trait,
    Thread: 'async_trait,
 
fn call_thunk<'life0, 'life1, 'async_trait>(
    &'life0 self,
    closure: &'life1 GcPtr<ClosureData>
) -> Pin<Box<dyn Future<Output = Result<RootedValue<RootedThread>, Error>> + Send + 'async_trait>>where
    'life0: 'async_trait,
    'life1: 'async_trait,
    Thread: 'async_trait,
fn resume(&self, cx: &mut Context<'_>) -> Poll<Result<OwnedContext<'_>, Error>>
fn deep_clone_value( &self, owner: &Thread, value: &Value ) -> Result<RootedValue<&Thread>, Error>
fn call_thunk_top<'life0, 'life1, 'async_trait>( &'life0 self, closure: &'life1 GcPtr<ClosureData> ) -> Pin<Box<dyn Future<Output = Result<RootedValue<RootedThread>, Error>> + Send + 'async_trait>>
fn execute_io_top<'life0, 'life1, 'async_trait>( &'life0 self, value: Variants<'life1> ) -> Pin<Box<dyn Future<Output = Result<RootedValue<RootedThread>, Error>> + Send + 'async_trait>>
source§impl<'a> VmRootInternal for &'a Thread
 
impl<'a> VmRootInternal for &'a Thread
source§impl VmType for Thread
 
impl VmType for Thread
fn make_forall_type(vm: &Thread) -> ArcType
source§const EXTRA_ARGS: u32 = 0u32
 
const EXTRA_ARGS: u32 = 0u32
Auto Trait Implementations§
impl !RefUnwindSafe for Thread
impl Send for Thread
impl Sync for Thread
impl Unpin for Thread
impl !UnwindSafe for Thread
Blanket Implementations§
source§impl<'vm, T> AsyncPushable<'vm> for Twhere
    T: Pushable<'vm>,
 
impl<'vm, T> AsyncPushable<'vm> for Twhere
    T: Pushable<'vm>,
source§fn async_push(
    self,
    context: &mut ActiveThread<'vm>,
    lock: Lock,
    _: u32
) -> Poll<Result<(), Error>>
 
fn async_push( self, context: &mut ActiveThread<'vm>, lock: Lock, _: u32 ) -> Poll<Result<(), Error>>
self to stack. If the call is successful a single element should have been added
to the stack and Ok(()) should be returned. If the call is unsuccessful Status:Error
should be returned and the stack should be left intact. Read morefn async_status_push(
    self,
    context: &mut ActiveThread<'vm>,
    lock: Lock,
    frame_index: u32
) -> Statuswhere
    Self: Sized,
source§impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
 
impl<T> BorrowMut<T> for Twhere
    T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
§impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
 
impl<Choices> CoproductSubsetter<CNil, HNil> for Choices
§impl<T> Downcast for Twhere
    T: Any,
 
impl<T> Downcast for Twhere
    T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
 
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
 
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
 
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
 
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.source§impl<T> DowncastArc for T
 
impl<T> DowncastArc for T
§impl<T> DowncastSync for T
 
impl<T> DowncastSync for T
§impl<T> Instrument for T
 
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
§impl<T, U, I> LiftInto<U, I> for Twhere
    U: LiftFrom<T, I>,
 
impl<T, U, I> LiftInto<U, I> for Twhere
    U: LiftFrom<T, I>,
source§impl<'vm, T> Pushable<'vm> for Twhere
    T: Userdata,
 
impl<'vm, T> Pushable<'vm> for Twhere
    T: Userdata,
source§fn vm_push(self, context: &mut ActiveThread<'vm>) -> Result<(), Error>
 
fn vm_push(self, context: &mut ActiveThread<'vm>) -> Result<(), Error>
self to stack. If the call is successful a single element should have been added
to the stack and Ok(()) should be returned. If the call is unsuccessful Status:Error
should be returned and the stack should be left intact