Skip to main content

BytecodeExecutor

Struct BytecodeExecutor 

Source
pub struct BytecodeExecutor { /* private fields */ }
Expand description

Bytecode executor for compiling and running Shape programs.

Core stdlib is loaded via prelude injection (AST inlining) rather than bytecode merging.

Implementations§

Source§

impl BytecodeExecutor

Source

pub fn new() -> Self

Create a new executor

Source

pub fn register_extension(&mut self, module: ModuleExports)

Register an external/user extension module (e.g. loaded from a .so plugin). It will be available in all subsequent executions. Bundled Shape sources are kept for legacy virtual-module imports.

Source

pub fn module_schemas(&self) -> Vec<ParsedModuleSchema>

Return all currently registered extension/extension module schemas.

Source

pub fn enable_bytecode_cache(&mut self) -> bool

Enable bytecode caching. Compiled programs will be stored as .shapec files and reused on subsequent runs if the source hasn’t changed. Returns false if the cache directory could not be created.

Source

pub fn set_interrupt(&mut self, flag: Arc<AtomicU8>)

Set the interrupt flag (shared with Ctrl+C handler).

Source

pub fn set_dependency_paths(&mut self, paths: HashMap<String, PathBuf>)

Set resolved dependency paths from shape.toml [dependencies].

These are mirrored into the module loader so import resolution matches runtime behavior.

Source

pub fn set_native_resolution_context( &mut self, resolutions: NativeResolutionSet, root_package_key: Option<String>, )

Install the package-scoped native library resolutions for the current host.

Source

pub fn clear_native_resolution_context(&mut self)

Clear any previously configured native resolution context.

Source§

impl BytecodeExecutor

Source

pub fn resume_snapshot( &self, engine: &mut ShapeEngine, vm_snapshot: VmSnapshot, bytecode: BytecodeProgram, ) -> Result<ProgramExecutorResult>

Resume execution from a snapshot

Source

pub fn compile_program_for_inspection( &mut self, engine: &mut ShapeEngine, program: &Program, ) -> Result<BytecodeProgram>

Compile a program with the same pipeline as execution, but do not run it.

The returned bytecode includes tooling artifacts such as expanded_function_defs for comptime inspection.

Source

pub fn recompile_and_resume( &mut self, engine: &mut ShapeEngine, vm_snapshot: VmSnapshot, old_bytecode: BytecodeProgram, program: &Program, ) -> Result<ProgramExecutorResult>

Recompile source and resume from a snapshot.

Compiles the new program to bytecode, finds the snapshot() call position in both old and new bytecodes, adjusts the VM snapshot’s instruction pointer, then resumes execution from the snapshot point using the new bytecode.

Source§

impl BytecodeExecutor

Source

pub fn set_module_loader(&mut self, loader: ModuleLoader)

Set a module loader for resolving file-based imports.

When set, imports that don’t match virtual modules will be resolved by the module loader, compiled to bytecode, and merged into the program.

Source

pub fn module_loader_mut(&mut self) -> Option<&mut ModuleLoader>

Get a mutable reference to the module loader (if set).

Source

pub fn resolve_file_imports_with_context( &mut self, program: &Program, context_dir: Option<&Path>, )

Pre-resolve file-based imports from a program using the module loader.

For each import in the program that doesn’t already have a virtual module, the module loader resolves and loads the module graph. Loaded modules are tracked so the unified compile pass can include them.

Call this before compile_program_impl to enable file-based import resolution.

Source

pub fn resolve_file_imports(&mut self, program: &Program)

Backward-compatible wrapper without importer context.

Source

pub fn resolve_file_imports_from_source( &mut self, source: &str, context_dir: Option<&Path>, )

Parse source and pre-resolve file-based imports.

Source

pub fn create_program_from_imports( module_binding_registry: &Arc<RwLock<ModuleBindingRegistry>>, ) -> Result<Program>

Create a Program from imported functions in ModuleBindingRegistry

Trait Implementations§

Source§

impl Default for BytecodeExecutor

Source§

fn default() -> Self

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

impl ExpressionEvaluator for BytecodeExecutor

Source§

fn eval_statements( &self, stmts: &[Statement], ctx: &mut ExecutionContext, ) -> Result<ValueWord>

Evaluate a slice of statements and return the result.
Source§

fn eval_expr( &self, expr: &Expr, ctx: &mut ExecutionContext, ) -> Result<ValueWord>

Evaluate a single expression and return the result.
Source§

impl ProgramExecutor for BytecodeExecutor

Source§

fn execute_program( &mut self, engine: &mut ShapeEngine, program: &Program, ) -> Result<ProgramExecutorResult>

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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