pub struct Engine<State = ()>{
pub state: Arc<State>,
pub type_system: TypeSystem,
pub heap: Heap,
/* private fields */
}Fields§
§state: Arc<State>§type_system: TypeSystem§heap: HeapImplementations§
Source§impl<State> Engine<State>
impl<State> Engine<State>
pub fn new(state: State) -> Engine<State>
pub fn with_prelude(state: State) -> Result<Engine<State>, EngineError>
pub fn with_options( state: State, options: EngineOptions, ) -> Result<Engine<State>, EngineError>
pub fn into_heap(self) -> Heap
Sourcepub fn inject_tracing_log_functions(&mut self) -> Result<(), EngineError>
pub fn inject_tracing_log_functions(&mut self) -> Result<(), EngineError>
Inject debug/info/warn/error logging functions backed by tracing.
Each function has the Rex type a -> str where Show a and logs
show x at the corresponding level, returning the rendered string.
pub fn inject_tracing_log_function( &mut self, name: &str, log: fn(&str), ) -> Result<(), EngineError>
pub fn cancellation_token(&self) -> CancellationToken
pub fn set_default_imports(&mut self, imports: Vec<String>)
pub fn default_imports(&self) -> &[String]
Sourcepub fn registry_markdown(&self) -> String
pub fn registry_markdown(&self) -> String
Return a markdown document that inventories the currently-registered engine state.
The report includes:
- summary counts
- modules and exports
- ADTs
- functions/values in the type environment
- type classes, methods, and instances
- native implementations
§Examples
ⓘ
use rex_engine::Engine;
let engine = Engine::with_prelude(()).unwrap();
let md = engine.registry_markdown();
assert!(md.contains("# Engine Registry"));
assert!(md.contains("## ADTs"));pub fn cancel(&self)
pub fn inject_module( &mut self, module: Module<State>, ) -> Result<(), EngineError>
pub fn export<Sig, H>(
&mut self,
name: impl Into<String>,
handler: H,
) -> Result<(), EngineError>where
H: Handler<State, Sig>,
pub fn export_async<Sig, H>(
&mut self,
name: impl Into<String>,
handler: H,
) -> Result<(), EngineError>where
H: AsyncHandler<State, Sig>,
pub fn export_native<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, handler: F, ) -> Result<(), EngineError>
pub fn inject_rex_default_instance<T>(&mut self) -> Result<(), EngineError>where
T: RexType + RexDefault<State>,
pub fn export_native_async<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, handler: F, ) -> Result<(), EngineError>
pub fn export_value<V>(
&mut self,
name: &str,
value: V,
) -> Result<(), EngineError>where
V: IntoPointer + RexType,
pub fn export_value_typed( &mut self, name: &str, typ: Type, value: Value, ) -> Result<(), EngineError>
pub fn export_native_with_gas_cost<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, gas_cost: u64, handler: F, ) -> Result<(), EngineError>
pub fn export_native_async_with_gas_cost<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, gas_cost: u64, handler: F, ) -> Result<(), EngineError>
pub fn export_native_async_cancellable<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, handler: F, ) -> Result<(), EngineError>
pub fn export_native_async_cancellable_with_gas_cost<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, gas_cost: u64, handler: F, ) -> Result<(), EngineError>
pub fn adt_decl(&mut self, name: &str, params: &[&str]) -> AdtDecl
Sourcepub fn adt_decl_from_type(&mut self, typ: &Type) -> Result<AdtDecl, EngineError>
pub fn adt_decl_from_type(&mut self, typ: &Type) -> Result<AdtDecl, EngineError>
Seed an AdtDecl from a Rex type constructor.
Accepted shapes:
Type::con("Foo", 0)->Foowith no paramsFoo a b(where args are type vars) ->Foowith params inferred from varsType::con("Foo", n)(bare higher-kinded head) ->Foowith generated paramst0..t{n-1}
Sourcepub fn adt_decl_from_type_with_params(
&mut self,
typ: &Type,
params: &[&str],
) -> Result<AdtDecl, EngineError>
pub fn adt_decl_from_type_with_params( &mut self, typ: &Type, params: &[&str], ) -> Result<AdtDecl, EngineError>
Same as adt_decl_from_type, but uses explicit parameter names.
pub fn inject_adt(&mut self, adt: AdtDecl) -> Result<(), EngineError>
pub fn inject_type_decl(&mut self, decl: &TypeDecl) -> Result<(), EngineError>
pub fn inject_class_decl(&mut self, decl: &ClassDecl) -> Result<(), EngineError>
pub fn inject_instance_decl( &mut self, decl: &InstanceDecl, ) -> Result<(), EngineError>
pub fn inject_fn_decl(&mut self, decl: &FnDecl) -> Result<(), EngineError>
pub fn inject_fn_decls(&mut self, decls: &[FnDecl]) -> Result<(), EngineError>
pub fn inject_decls(&mut self, decls: &[Decl]) -> Result<(), EngineError>
pub fn inject_class(&mut self, name: &str, supers: Vec<String>)
pub fn inject_instance(&mut self, class: &str, inst: Instance)
pub async fn eval( &mut self, expr: &Expr, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>
Source§impl<State> Engine<State>
impl<State> Engine<State>
pub fn add_resolver<F>(&mut self, name: impl Into<String>, f: F)
pub fn add_default_resolvers(&mut self)
pub fn add_include_resolver( &mut self, root: impl AsRef<Path>, ) -> Result<(), EngineError>
pub fn infer_module_file( &mut self, path: impl AsRef<Path>, gas: &mut GasMeter, ) -> Result<(Vec<Predicate>, Type), EngineError>
pub fn infer_snippet( &mut self, source: &str, gas: &mut GasMeter, ) -> Result<(Vec<Predicate>, Type), EngineError>
pub fn infer_snippet_at( &mut self, source: &str, importer_path: impl AsRef<Path>, gas: &mut GasMeter, ) -> Result<(Vec<Predicate>, Type), EngineError>
pub async fn eval_module_file( &mut self, path: impl AsRef<Path>, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>
pub async fn eval_module_source( &mut self, source: &str, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>
pub async fn eval_snippet( &mut self, source: &str, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>
pub async fn eval_repl_program( &mut self, program: &Program, state: &mut ReplState, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>
Sourcepub async fn eval_snippet_at(
&mut self,
source: &str,
importer_path: impl AsRef<Path>,
gas: &mut GasMeter,
) -> Result<(Pointer, Type), EngineError>
pub async fn eval_snippet_at( &mut self, source: &str, importer_path: impl AsRef<Path>, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>
Evaluate a non-module snippet (with gas), but use importer_path for resolving local-relative imports.
Trait Implementations§
Auto Trait Implementations§
impl<State = ()> !Freeze for Engine<State>
impl<State = ()> !RefUnwindSafe for Engine<State>
impl<State> Send for Engine<State>
impl<State> Sync for Engine<State>
impl<State> Unpin for Engine<State>
impl<State> UnsafeUnpin for Engine<State>
impl<State = ()> !UnwindSafe for Engine<State>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more