Skip to main content

Engine

Struct Engine 

Source
pub struct Engine<State = ()>
where State: Clone + Send + Sync + 'static,
{ pub state: Arc<State>, pub type_system: TypeSystem, pub heap: Heap, /* private fields */ }

Fields§

§state: Arc<State>§type_system: TypeSystem§heap: Heap

Implementations§

Source§

impl<State> Engine<State>
where State: Clone + Send + Sync + 'static,

Source

pub fn new(state: State) -> Engine<State>

Source

pub fn with_prelude(state: State) -> Result<Engine<State>, EngineError>

Source

pub fn with_options( state: State, options: EngineOptions, ) -> Result<Engine<State>, EngineError>

Source

pub fn into_heap(self) -> Heap

Source

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.

Source

pub fn inject_tracing_log_function( &mut self, name: &str, log: fn(&str), ) -> Result<(), EngineError>

Source

pub fn cancellation_token(&self) -> CancellationToken

Source

pub fn set_default_imports(&mut self, imports: Vec<String>)

Source

pub fn default_imports(&self) -> &[String]

Source

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"));
Source

pub fn cancel(&self)

Source

pub fn inject_module( &mut self, module: Module<State>, ) -> Result<(), EngineError>

Source

pub fn export<Sig, H>( &mut self, name: impl Into<String>, handler: H, ) -> Result<(), EngineError>
where H: Handler<State, Sig>,

Source

pub fn export_async<Sig, H>( &mut self, name: impl Into<String>, handler: H, ) -> Result<(), EngineError>
where H: AsyncHandler<State, Sig>,

Source

pub fn export_native<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, handler: F, ) -> Result<(), EngineError>
where F: for<'a> Fn(&'a Engine<State>, &'a Type, &'a [Pointer]) -> Result<Pointer, EngineError> + Send + Sync + 'static,

Source

pub fn inject_rex_default_instance<T>(&mut self) -> Result<(), EngineError>
where T: RexType + RexDefault<State>,

Source

pub fn export_native_async<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, handler: F, ) -> Result<(), EngineError>
where F: for<'a> Fn(&'a Engine<State>, Type, Vec<Pointer>) -> Pin<Box<dyn Future<Output = Result<Pointer, EngineError>> + Send + 'a>> + Send + Sync + 'static,

Source

pub fn export_value<V>( &mut self, name: &str, value: V, ) -> Result<(), EngineError>
where V: IntoPointer + RexType,

Source

pub fn export_value_typed( &mut self, name: &str, typ: Type, value: Value, ) -> Result<(), EngineError>

Source

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>
where F: for<'a> Fn(&'a Engine<State>, &'a Type, &'a [Pointer]) -> Result<Pointer, EngineError> + Send + Sync + 'static,

Source

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>
where F: for<'a> Fn(&'a Engine<State>, Type, Vec<Pointer>) -> Pin<Box<dyn Future<Output = Result<Pointer, EngineError>> + Send + 'a>> + Send + Sync + 'static,

Source

pub fn export_native_async_cancellable<F>( &mut self, name: impl Into<String>, scheme: Scheme, arity: usize, handler: F, ) -> Result<(), EngineError>
where F: for<'a> Fn(&'a Engine<State>, CancellationToken, Type, &'a [Pointer]) -> Pin<Box<dyn Future<Output = Result<Pointer, EngineError>> + Send + 'a>> + Send + Sync + 'static,

Source

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>
where F: for<'a> Fn(&'a Engine<State>, CancellationToken, Type, &'a [Pointer]) -> Pin<Box<dyn Future<Output = Result<Pointer, EngineError>> + Send + 'a>> + Send + Sync + 'static,

Source

pub fn adt_decl(&mut self, name: &str, params: &[&str]) -> AdtDecl

Source

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) -> Foo with no params
  • Foo a b (where args are type vars) -> Foo with params inferred from vars
  • Type::con("Foo", n) (bare higher-kinded head) -> Foo with generated params t0..t{n-1}
Source

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.

Source

pub fn inject_adt(&mut self, adt: AdtDecl) -> Result<(), EngineError>

Source

pub fn inject_type_decl(&mut self, decl: &TypeDecl) -> Result<(), EngineError>

Source

pub fn inject_class_decl(&mut self, decl: &ClassDecl) -> Result<(), EngineError>

Source

pub fn inject_instance_decl( &mut self, decl: &InstanceDecl, ) -> Result<(), EngineError>

Source

pub fn inject_fn_decl(&mut self, decl: &FnDecl) -> Result<(), EngineError>

Source

pub fn inject_fn_decls(&mut self, decls: &[FnDecl]) -> Result<(), EngineError>

Source

pub fn inject_decls(&mut self, decls: &[Decl]) -> Result<(), EngineError>

Source

pub fn inject_class(&mut self, name: &str, supers: Vec<String>)

Source

pub fn inject_instance(&mut self, class: &str, inst: Instance)

Source

pub async fn eval( &mut self, expr: &Expr, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>

Source§

impl<State> Engine<State>
where State: Clone + Send + Sync + 'static,

Source

pub fn add_resolver<F>(&mut self, name: impl Into<String>, f: F)

Source

pub fn add_default_resolvers(&mut self)

Source

pub fn add_include_resolver( &mut self, root: impl AsRef<Path>, ) -> Result<(), EngineError>

Source

pub fn infer_module_file( &mut self, path: impl AsRef<Path>, gas: &mut GasMeter, ) -> Result<(Vec<Predicate>, Type), EngineError>

Source

pub fn infer_snippet( &mut self, source: &str, gas: &mut GasMeter, ) -> Result<(Vec<Predicate>, Type), EngineError>

Source

pub fn infer_snippet_at( &mut self, source: &str, importer_path: impl AsRef<Path>, gas: &mut GasMeter, ) -> Result<(Vec<Predicate>, Type), EngineError>

Source

pub async fn eval_module_file( &mut self, path: impl AsRef<Path>, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>

Source

pub async fn eval_module_source( &mut self, source: &str, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>

Source

pub async fn eval_snippet( &mut self, source: &str, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>

Source

pub async fn eval_repl_program( &mut self, program: &Program, state: &mut ReplState, gas: &mut GasMeter, ) -> Result<(Pointer, Type), EngineError>

Source

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§

Source§

impl<State> Default for Engine<State>
where State: Clone + Send + Sync + 'static + Default,

Source§

fn default() -> Engine<State>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more