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
impl BytecodeExecutor
Sourcepub fn register_extension(&mut self, module: ModuleExports)
pub fn register_extension(&mut self, module: ModuleExports)
Register an extension module. It will be available in all subsequent executions. Bundled Shape sources are kept for legacy virtual-module imports.
Sourcepub fn module_schemas(&self) -> Vec<ParsedModuleSchema>
pub fn module_schemas(&self) -> Vec<ParsedModuleSchema>
Return all currently registered extension/extension module schemas.
Sourcepub fn enable_bytecode_cache(&mut self) -> bool
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.
Sourcepub fn set_interrupt(&mut self, flag: Arc<AtomicU8>)
pub fn set_interrupt(&mut self, flag: Arc<AtomicU8>)
Set the interrupt flag (shared with Ctrl+C handler).
Sourcepub fn set_dependency_paths(&mut self, paths: HashMap<String, PathBuf>)
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§impl BytecodeExecutor
impl BytecodeExecutor
Sourcepub fn resume_snapshot(
&self,
engine: &mut ShapeEngine,
vm_snapshot: VmSnapshot,
bytecode: BytecodeProgram,
) -> Result<ProgramExecutorResult>
pub fn resume_snapshot( &self, engine: &mut ShapeEngine, vm_snapshot: VmSnapshot, bytecode: BytecodeProgram, ) -> Result<ProgramExecutorResult>
Resume execution from a snapshot
Sourcepub fn compile_program_for_inspection(
&self,
engine: &mut ShapeEngine,
program: &Program,
) -> Result<BytecodeProgram>
pub fn compile_program_for_inspection( &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.
Sourcepub fn recompile_and_resume(
&self,
engine: &mut ShapeEngine,
vm_snapshot: VmSnapshot,
old_bytecode: BytecodeProgram,
program: &Program,
) -> Result<ProgramExecutorResult>
pub fn recompile_and_resume( &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
impl BytecodeExecutor
Sourcepub fn set_module_loader(&mut self, loader: ModuleLoader)
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.
Sourcepub fn module_loader_mut(&mut self) -> Option<&mut ModuleLoader>
pub fn module_loader_mut(&mut self) -> Option<&mut ModuleLoader>
Get a mutable reference to the module loader (if set).
Sourcepub fn resolve_file_imports_with_context(
&mut self,
program: &Program,
context_dir: Option<&Path>,
)
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.
Sourcepub fn resolve_file_imports(&mut self, program: &Program)
pub fn resolve_file_imports(&mut self, program: &Program)
Backward-compatible wrapper without importer context.
Sourcepub fn resolve_file_imports_from_source(
&mut self,
source: &str,
context_dir: Option<&Path>,
)
pub fn resolve_file_imports_from_source( &mut self, source: &str, context_dir: Option<&Path>, )
Parse source and pre-resolve file-based imports.
Sourcepub fn create_program_from_imports(
module_binding_registry: &Arc<RwLock<ModuleBindingRegistry>>,
) -> Result<Program>
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
impl Default for BytecodeExecutor
Source§impl ExpressionEvaluator for BytecodeExecutor
impl ExpressionEvaluator for BytecodeExecutor
Source§fn eval_statements(
&self,
stmts: &[Statement],
ctx: &mut ExecutionContext,
) -> Result<ValueWord>
fn eval_statements( &self, stmts: &[Statement], ctx: &mut ExecutionContext, ) -> Result<ValueWord>
Source§impl ProgramExecutor for BytecodeExecutor
impl ProgramExecutor for BytecodeExecutor
fn execute_program( &self, engine: &mut ShapeEngine, program: &Program, ) -> Result<ProgramExecutorResult>
Auto Trait Implementations§
impl Freeze for BytecodeExecutor
impl !RefUnwindSafe for BytecodeExecutor
impl Send for BytecodeExecutor
impl Sync for BytecodeExecutor
impl Unpin for BytecodeExecutor
impl UnsafeUnpin for BytecodeExecutor
impl !UnwindSafe for BytecodeExecutor
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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