| Crates.io | tabulon_macros |
| lib.rs | tabulon_macros |
| version | 0.1.2 |
| created_at | 2025-10-04 17:49:25.538108+00 |
| updated_at | 2025-10-20 00:18:17.370406+00 |
| description | Internal procedural macros for the tabulon expression engine. |
| homepage | |
| repository | https://github.com/tabulon-rs/tabulon |
| max_upload_size | |
| id | 1868289 |
| size | 18,976 |
A high-performance, JIT-compiled expression evaluation engine for Rust, built on Cranelift.
tabulon parses simple arithmetic and boolean expressions and compiles them to native machine code at runtime. It is designed for applications like game servers, configuration scripts, or anywhere you need to safely and repeatedly evaluate user-provided expressions with maximum performance.
+, -, *, /), comparison (==, !=, <, <=, >, >=), and logical (&&, ||) operators.if(...), &&, and || operators avoids unnecessary computation.Add tabulon to your Cargo.toml:
[dependencies]
tabulon = "0.1.0"
Use the engine to compile and evaluate an expression:
use tabulon::Tabula;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new engine instance
let mut engine = Tabula::new();
// Compile an expression
let expr = engine.compile("power > 9000 && is_angry * 10")?;
// `ordered_vars` shows the order variables must be supplied in.
// Here it would be: ["power", "is_angry"]
assert_eq!(expr.vars(), &["power", "is_angry"]);
// Prepare variables for evaluation
let power_level = 9001.0;
let is_angry_val = 1.0; // Use 1.0 for true, 0.0 for false
// `eval` takes a slice of pointers to your f64 variables
let result = expr.eval(&[&power_level, &is_angry_val])?;
// The expression "(9001 > 9000) && (1.0 * 10)" is true, so the result is 1.0.
assert_eq!(result, 1.0);
println!("It's over 9000! Result: {}", result);
Ok(())
}
You can easily register your own Rust functions to be used in expressions.
use tabulon::{Tabula, function, register_functions};
// Use the `#[function]` attribute to make a function discoverable.
#[function]
pub fn custom_max(a: f64, b: f64) -> f64 {
if a > b { a } else { b }
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut engine = Tabula::new();
// Register the function with the engine instance.
register_functions!(engine, custom_max)?;
let expr = engine.compile("custom_max(player_score, high_score) * 1.1")?;
let player_score = 120.0;
let high_score = 150.0;
let result = expr.eval(&[&player_score, &high_score])?;
assert_eq!(result, 165.0);
println!("Potential new high score: {}", result);
Ok(())
}
tabulon is designed for speed. By compiling expressions down to a few simple machine instructions, it can evaluate them orders of magnitude faster than a tree-walking interpreter. Benchmarks are included in the repository (cargo bench).
This project is licensed under the MIT License.