Struct gluon_vm::thread::RootedThread
source · pub struct RootedThread(_);
Expand description
An instance of Thread
which is rooted. See the Thread
type for documentation on interacting
with the type.
Implementations
sourceimpl RootedThread
impl RootedThread
sourcepub fn new() -> RootedThread
pub fn new() -> RootedThread
Creates a new virtual machine with an empty global environment
pub fn with_global_state(global_state: GlobalVmState) -> RootedThread
sourcepub fn into_raw(self) -> *const Thread
pub fn into_raw(self) -> *const Thread
Converts a RootedThread
into a raw pointer allowing to be passed through a C api.
The reference count for the thread is not modified
sourcepub unsafe fn from_raw(ptr: *const Thread) -> RootedThread
pub unsafe fn from_raw(ptr: *const Thread) -> RootedThread
Converts a raw pointer into a RootedThread
.
The reference count for the thread is not modified so it is up to the caller to ensure that
the count is correct.
Methods from Deref<Target = Thread>
sourcepub fn new_thread(&self) -> Result<RootedThread>
pub fn new_thread(&self) -> Result<RootedThread>
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
sourcepub fn define_global<'vm, T>(&'vm self, name: &str, value: T) -> Result<()>where
T: Pushable<'vm> + VmType,
👎Deprecated since 0.7.0: Use gluon::import::add_extern_module
instead
pub fn define_global<'vm, T>(&'vm self, name: &str, value: T) -> Result<()>where
T: Pushable<'vm> + VmType,
gluon::import::add_extern_module
insteadCreates a new global value at name
.
Fails if a global called name
already exists.
Examples
Load the factorial
rust function into gluon and evaluate factorial 5
fn factorial(x: i32) -> i32 {
if x <= 1 { 1 } else { x * factorial(x - 1) }
}
let vm = new_vm();
vm.define_global("factorial", primitive!(1, factorial)).unwrap();
let result = Compiler::new()
.run_expr::<i32>(&vm, "example", "factorial 5")
.unwrap_or_else(|err| panic!("{}", err));
let expected = (120, Type::int());
assert_eq!(result, expected);
sourcepub fn get_global<'vm, T>(&'vm self, name: &str) -> Result<T>where
T: for<'value> Getable<'vm, 'value> + VmType,
pub fn get_global<'vm, T>(&'vm self, name: &str) -> Result<T>where
T: for<'value> Getable<'vm, 'value> + VmType,
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();
Compiler::new()
.run_expr::<OpaqueValue<&Thread, Hole>>(&vm, "example",
r#" import! std.int "#)
.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(1, 2);
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>
sourcepub fn find_type_info(&self, name: &str) -> Result<Alias<Symbol, ArcType>>
pub fn find_type_info(&self, name: &str) -> Result<Alias<Symbol, ArcType>>
Retrieves type information about the type name
. Types inside records can be accessed
using dot notation (std.prelude.Option)
sourcepub fn get_type<T: ?Sized + Any>(&self) -> Option<ArcType>
pub fn get_type<T: ?Sized + Any>(&self) -> Option<ArcType>
Returns the gluon type that was bound to T
sourcepub fn register_type<T: ?Sized + Any>(
&self,
name: &str,
args: &[&str]
) -> Result<ArcType>
pub fn register_type<T: ?Sized + Any>(
&self,
name: &str,
args: &[&str]
) -> Result<ArcType>
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>
sourcepub fn get_env<'b>(&'b self) -> RwLockReadGuard<'b, VmEnv>
pub fn get_env<'b>(&'b self) -> RwLockReadGuard<'b, VmEnv>
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<()>where
T: Pushable<'vm>,
pub fn push<'vm, T>(&'vm self, v: T) -> Result<()>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
sourceimpl Clone for RootedThread
impl Clone for RootedThread
sourcefn clone(&self) -> RootedThread
fn clone(&self) -> RootedThread
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for RootedThread
impl Debug for RootedThread
sourceimpl Deref for RootedThread
impl Deref for RootedThread
sourceimpl Drop for RootedThread
impl Drop for RootedThread
sourceimpl<'vm, 'value> Getable<'vm, 'value> for RootedThread
impl<'vm, 'value> Getable<'vm, 'value> for RootedThread
fn from_value(_: &'vm Thread, value: Variants<'value>) -> Self
sourceimpl<'vm> Pushable<'vm> for RootedThread
impl<'vm> Pushable<'vm> for RootedThread
sourcefn push(self, context: &mut ActiveThread<'vm>) -> Result<()>
fn push(self, context: &mut ActiveThread<'vm>) -> Result<()>
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 status_push(self, context: &mut ActiveThread<'vm>) -> Statuswhere
Self: Sized,
unsafe fn marshal_unrooted(self, vm: &'vm Thread) -> Result<Value>where
Self: Sized,
fn marshal<T>(self, vm: &'vm Thread) -> Result<RootedValue<T>>where
Self: Sized,
T: VmRoot<'vm>,
sourceimpl Traverseable for RootedThread
impl Traverseable for RootedThread
sourceimpl<'a> VmRoot<'a> for RootedThread
impl<'a> VmRoot<'a> for RootedThread
fn root(thread: &'a Thread) -> Self
sourcefn root_value_with_self(self, value: Variants<'_>) -> RootedValue<Self>
fn root_value_with_self(self, value: Variants<'_>) -> RootedValue<Self>
sourceimpl VmType for RootedThread
impl VmType for RootedThread
fn make_forall_type(vm: &Thread) -> ArcType
sourcefn extra_args() -> VmIndex
fn extra_args() -> VmIndex
Auto Trait Implementations
impl RefUnwindSafe for RootedThread
impl Send for RootedThread
impl Sync for RootedThread
impl Unpin for RootedThread
impl UnwindSafe for RootedThread
Blanket Implementations
sourceimpl<'vm, T> AsyncPushable<'vm> for Twhere
T: Pushable<'vm>,
impl<'vm, T> AsyncPushable<'vm> for Twhere
T: Pushable<'vm>,
sourcefn async_push(
self,
context: &mut ActiveThread<'vm>,
_: u32
) -> Result<Async<()>, Error>
fn async_push(
self,
context: &mut ActiveThread<'vm>,
_: u32
) -> Result<Async<()>, 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 more