Skip to main content

ocas_eval/
lib.rs

1//! Evaluation and JIT code generation for oCAS.
2//!
3//! This crate provides a stack-based virtual machine for numeric evaluation
4//! of symbolic expressions, an AST-to-instruction compiler, a Cranelift JIT
5//! backend, and SIMD vectorized evaluation.
6//!
7//! # Architecture
8//!
9//! The evaluation pipeline:
10//!
11//! ```text
12//! Atom (arena-backed)
13//!   → EvalTree (owned intermediate)
14//!   → Instr sequence (compile + optimize)
15//!   → ExpressionEvaluator (stack VM)
16//!   → or JitCompiledFunction (Cranelift, feature = "jit")
17//!   → or VectorEvaluator (SIMD batch)
18//! ```
19//!
20//! # Example
21//!
22//! ```ignore
23//! use ocas_eval::{ExpressionEvaluator, EvaluationDomain};
24//! use ocas_atom::AtomArena;
25//! use ocas_core::arena::Arena;
26//!
27//! let arena = Arena::new();
28//! let ctx = AtomArena::new(&arena);
29//! let expr = ctx.add(&[ctx.var("x"), ctx.num(1)]);
30//!
31//! let eval: ExpressionEvaluator<f64> =
32//!     ExpressionEvaluator::compile(&expr).unwrap();
33//! let result = eval.evaluate(&[2.0]).unwrap();
34//! assert_eq!(result[0], 3.0);
35//! ```
36
37pub mod domain;
38pub mod error;
39pub mod evaluator;
40pub mod function_map;
41pub mod instruction;
42pub mod numeric;
43pub mod tree;
44
45pub mod compile;
46mod optimize;
47pub mod streaming;
48
49#[cfg(feature = "jit")]
50pub mod jit;
51
52#[cfg(feature = "simd")]
53pub mod simd;
54
55#[cfg(feature = "fast-poly")]
56pub mod poly_eval;
57
58pub use compile::{
59    compile_atom, compile_atom_with, compile_atoms_multi, compile_atoms_multi_with, compile_tree,
60    compile_tree_with, compile_trees_multi,
61};
62pub use domain::{EvaluationDomain, PowfExtension};
63pub use error::EvaluationError;
64pub use evaluator::ExpressionEvaluator;
65pub use function_map::FunctionMap;
66pub use instruction::{Instr, Instruction, Slot};
67pub use streaming::StreamingEvaluator;
68pub use tree::EvalTree;
69
70#[cfg(feature = "simd")]
71pub use simd::{VectorEvaluator, VectorEvaluatorF32};