pub struct VM { /* private fields */ }Implementations§
Source§impl VM
impl VM
pub fn new() -> Self
pub fn with_capacity(compile_cap: usize, path_cap: usize) -> Self
Sourcepub fn with_registry(registry: Arc<MethodRegistry>) -> Self
pub fn with_registry(registry: Arc<MethodRegistry>) -> Self
Build a VM that shares an existing method registry.
Sourcepub fn register_arc(&mut self, name: &str, method: Arc<dyn Method>)
pub fn register_arc(&mut self, name: &str, method: Arc<dyn Method>)
Register a method already wrapped in Arc.
Sourcepub fn set_pass_config(&mut self, config: PassConfig)
pub fn set_pass_config(&mut self, config: PassConfig)
Replace the pass configuration. The compile cache is not purged, but future lookups key off the new config hash so old entries are effectively invalidated for the new regime.
pub fn pass_config(&self) -> PassConfig
Sourcepub fn register(
&mut self,
name: impl Into<String>,
method: impl Method + 'static,
)
pub fn register( &mut self, name: impl Into<String>, method: impl Method + 'static, )
Register a custom method (callable via .method_name(...) in expressions).
Sourcepub fn run_str(&mut self, expr: &str, doc: &Value) -> Result<Value, EvalError>
pub fn run_str(&mut self, expr: &str, doc: &Value) -> Result<Value, EvalError>
Parse, compile (cached), and execute expr against doc.
Sourcepub fn run_str_with_raw(
&mut self,
expr: &str,
doc: &Value,
raw_bytes: Arc<[u8]>,
) -> Result<Value, EvalError>
pub fn run_str_with_raw( &mut self, expr: &str, doc: &Value, raw_bytes: Arc<[u8]>, ) -> Result<Value, EvalError>
Parse, compile, and execute with raw JSON source bytes retained so
that SIMD byte-scan can short-circuit Opcode::Descendant at the
document root.
Sourcepub fn execute(
&mut self,
program: &Program,
doc: &Value,
) -> Result<Value, EvalError>
pub fn execute( &mut self, program: &Program, doc: &Value, ) -> Result<Value, EvalError>
Execute a pre-compiled Program against doc.
Sourcepub fn execute_with_raw(
&mut self,
program: &Program,
doc: &Value,
raw_bytes: Arc<[u8]>,
) -> Result<Value, EvalError>
pub fn execute_with_raw( &mut self, program: &Program, doc: &Value, raw_bytes: Arc<[u8]>, ) -> Result<Value, EvalError>
Execute with raw JSON source bytes retained on the environment so that descendant opcodes at document root can take the SIMD byte-scan fast path instead of walking the tree.
Sourcepub fn execute_val_with_raw(
&mut self,
program: &Program,
root: Val,
raw_bytes: Arc<[u8]>,
) -> Result<Value, EvalError>
pub fn execute_val_with_raw( &mut self, program: &Program, root: Val, raw_bytes: Arc<[u8]>, ) -> Result<Value, EvalError>
Execute against a pre-built Val root (skips the Val::from(&Value)
conversion on every call). With raw bytes, the doc_hash pointer-
cache path is also skipped — byte-scan handles descendants directly
and RootChain reads are O(chain length) against the already-built
tree.
Sourcepub fn execute_val(
&mut self,
program: &Program,
root: Val,
) -> Result<Value, EvalError>
pub fn execute_val( &mut self, program: &Program, root: Val, ) -> Result<Value, EvalError>
Execute against a pre-built Val root without raw bytes. Skips the
Val::from conversion only — path cache and doc hash still behave
as in execute().
Sourcepub fn execute_val_raw(
&mut self,
program: &Program,
root: Val,
) -> Result<Val, EvalError>
pub fn execute_val_raw( &mut self, program: &Program, root: Val, ) -> Result<Val, EvalError>
Execute against a pre-built Val root and return the raw Val —
no serde_json::Value materialisation. Use when the caller will
consume results structurally (further queries, custom walk) and
wants to skip a potentially expensive Val → Value conversion.
Sourcepub fn execute_with_schema(
&mut self,
program: &Program,
doc: &Value,
shape: &Shape,
) -> Result<Value, EvalError>
pub fn execute_with_schema( &mut self, program: &Program, doc: &Value, shape: &Shape, ) -> Result<Value, EvalError>
Execute a compiled program against a document, first specialising
against the given shape (turns OptField → GetField where safe,
folds KindCheck where type is known, etc.).
Sourcepub fn execute_with_inferred_schema(
&mut self,
program: &Program,
doc: &Value,
) -> Result<Value, EvalError>
pub fn execute_with_inferred_schema( &mut self, program: &Program, doc: &Value, ) -> Result<Value, EvalError>
Execute a program; infer the shape from the document itself. Costs an O(doc) shape walk before execution; useful when the same compiled program is reused across many docs with similar shapes.
Sourcepub fn get_or_compile(&mut self, expr: &str) -> Result<Arc<Program>, EvalError>
pub fn get_or_compile(&mut self, expr: &str) -> Result<Arc<Program>, EvalError>
Get or compile an expression string (compile cache). Cache key is (pass_config_hash, expr) so that different pass configurations yield different compiled programs.
Sourcepub fn cache_stats(&self) -> (usize, usize)
pub fn cache_stats(&self) -> (usize, usize)
Cache statistics: (compile_entries, path_entries).