pub struct Environment {
pub builtin_dtables: BuiltinDispatchTables,
/* private fields */
}
Expand description
An environment containing information about declared globals, functions, vtables.
Fields
builtin_dtables: BuiltinDispatchTables
Dispatch tables for builtin types.
Implementations
sourceimpl Environment
impl Environment
sourcepub fn new(builtin_dtables: BuiltinDispatchTables) -> Self
pub fn new(builtin_dtables: BuiltinDispatchTables) -> Self
Creates a new, empty environment.
sourcepub fn create_global(
&mut self,
name: &str
) -> Result<GlobalIndex, LanguageErrorKind>
pub fn create_global(
&mut self,
name: &str
) -> Result<GlobalIndex, LanguageErrorKind>
Tries to create a global. Returns the global slot number, or an error if there are too many globals.
sourcepub fn get_global(&self, name: &str) -> Option<GlobalIndex>
pub fn get_global(&self, name: &str) -> Option<GlobalIndex>
Tries to look up a global. Returns None
if the global doesn’t exist.
sourcepub fn create_function(
&mut self,
function: Function
) -> Result<FunctionIndex, LanguageErrorKind>
pub fn create_function(
&mut self,
function: Function
) -> Result<FunctionIndex, LanguageErrorKind>
Creates a function and returns its ID.
sourcepub fn get_or_create_method_index(
&mut self,
signature: &MethodSignature
) -> Result<MethodIndex, LanguageErrorKind>
pub fn get_or_create_method_index(
&mut self,
signature: &MethodSignature
) -> Result<MethodIndex, LanguageErrorKind>
Tries to look up the index of a method, based on a function signature. Creates a new method
index if there isn’t one for the given signature. Returns Err
if there are too many
function signatures in this environment.
sourcepub fn get_method_signature(
&self,
method_index: MethodIndex
) -> Option<&MethodSignature>
pub fn get_method_signature(
&self,
method_index: MethodIndex
) -> Option<&MethodSignature>
Returns the signature for the method with the given ID, or None
if the method index is
invalid.
sourcepub fn create_trait(
&mut self,
name: Rc<str>
) -> Result<TraitIndex, LanguageErrorKind>
pub fn create_trait(
&mut self,
name: Rc<str>
) -> Result<TraitIndex, LanguageErrorKind>
Creates a trait and returns its ID. Use get_trait_mut
afterwards to modify the trait.
sourcepub fn get_trait(&self, id: TraitIndex) -> Option<&TraitPrototype>
pub fn get_trait(&self, id: TraitIndex) -> Option<&TraitPrototype>
Returns a reference to the trait with the given ID.
sourcepub fn get_trait_mut(&mut self, id: TraitIndex) -> Option<&mut TraitPrototype>
pub fn get_trait_mut(&mut self, id: TraitIndex) -> Option<&mut TraitPrototype>
Returns a mutable reference to the trait with the given ID.
sourcepub fn add_user_dtable<T>(&mut self, dtable: Gc<DispatchTable>)where
T: Any,
pub fn add_user_dtable<T>(&mut self, dtable: Gc<DispatchTable>)where
T: Any,
Adds a dispatch table for a user-defined type.
sourcepub fn get_user_dtable<T>(&self) -> Option<&Gc<DispatchTable>>where
T: Any,
pub fn get_user_dtable<T>(&self) -> Option<&Gc<DispatchTable>>where
T: Any,
Returns the user-defined dispatch table, if available.