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 tree;
43
44pub mod compile;
45mod optimize;
46
47#[cfg(feature = "jit")]
48pub mod jit;
49
50#[cfg(feature = "simd")]
51pub mod simd;
52
53#[cfg(feature = "fast-poly")]
54pub mod poly_eval;
55
56pub use compile::{compile_atom, compile_atom_with, compile_tree, compile_tree_with};
57pub use domain::{EvaluationDomain, PowfExtension};
58pub use error::EvaluationError;
59pub use evaluator::ExpressionEvaluator;
60pub use function_map::FunctionMap;
61pub use instruction::{Instr, Instruction, Slot};
62pub use tree::EvalTree;
63
64#[cfg(feature = "simd")]
65pub use simd::VectorEvaluator;