Skip to main content

Crate josie_core

Crate josie_core 

Source
Expand description

§josie-core

Core runtime and execution planner for JOSIE (JSON Omni Safe Interactive Expressions).

§Module Roles

ModuleResponsibilityPublic Entry Points
runtimeTree evaluator + operator registryevaluate, Operators, State
programProgram envelope validation, compile planning, pipeline executionparse_program, compile_program, execute_program*
compilerserde_json::Value expression -> typed IRExpr and compile_expr
vmFast typed IR evaluatoreval_expr, IterLocals
jvalInternal value representation for VM executionJVal

§Execution Contract

  1. Parse/validate once.
  2. Compile once into best available strategy.
  3. Execute many times.

Optimization tiers in program:

  1. Specialized internal fast plans.
  2. Specialized typed host-call fast plans.
  3. Compiled pipeline IR path.
  4. Generic tree/pipeline fallback.

Rule: all optimized paths must preserve the same observable semantics as the generic evaluator.

§Hello World (Simple API)

use josie_core::eval;
use serde_json::json;

let out = eval(&json!(["util.concat", "Hello", ", ", "World"])).expect("eval");
assert_eq!(out, json!("Hello, World"));

§Inject Custom x.* Operator

use josie_core::{Context, EvalResult, Operator, Operators, State, evaluate};
use serde_json::{json, Value};

fn op_x_echo(args: &[Value], _ctx: &mut Context) -> EvalResult {
    Ok(args.first().cloned().unwrap_or(Value::Null))
}

let mut operators = Operators::new();
operators.register("x.echo", op_x_echo as Operator);

let mut state = State::new();
let expr = json!(["x.echo", {"ok": true}]);
let mut ctx = Context { state: &mut state, operators: &operators, event: None };
let out = evaluate(&expr, &mut ctx).expect("x.echo");
assert_eq!(out, json!({"ok": true}));

Re-exports§

pub use compiler::Expr;
pub use engine::Engine;
pub use jval::JVal;
pub use reader::ReaderError;
pub use reader::read;
pub use reader::read_program;
pub use runtime::Context;
pub use runtime::EvalError;
pub use runtime::EvalResult;
pub use runtime::EventContext;
pub use runtime::FunctionDef;
pub use runtime::JsonNode;
pub use runtime::Operator;
pub use runtime::Operators;
pub use runtime::State;
pub use runtime::evaluate;
pub use runtime::get_path;
pub use runtime::set_path;
pub use vm::IterLocals;
pub use vm::eval_expr;

Modules§

compiler
Expression compiler from JSON tree nodes to typed Expr IR.
engine
jval
Internal value model used by compiled execution paths.
program
Program-level contract and optimized execution strategies.
reader
runtime
Runtime evaluator and operator registry for JOSIE tree expressions.
vm
Typed VM evaluator for compiled Expr.

Functions§

eval
Evaluate an expression with default runtime components:
eval_with_operators
Evaluate an expression with caller-provided operators and empty state.
eval_with_state
Evaluate an expression with caller-provided state and default operators.