| Crates.io | uni-core |
| lib.rs | uni-core |
| version | 0.0.12 |
| created_at | 2025-10-18 18:33:48.855127+00 |
| updated_at | 2025-10-25 13:47:28.899059+00 |
| description | Core interpreter library for the Uni programming language |
| homepage | |
| repository | https://github.com/edadma/uni |
| max_upload_size | |
| id | 1889513 |
| size | 776,024 |
The core interpreter library for the Uni programming language - a homoiconic stack-based language that unifies code and data.
Add to your Cargo.toml:
[dependencies]
uni-core = "0.0.12"
Basic usage:
use uni_core::{Interpreter, execute_string};
fn main() {
let mut interp = Interpreter::new();
// Execute Uni code
execute_string("5 3 +", &mut interp).unwrap();
// Get result from stack
if let Some(result) = interp.stack.last() {
println!("Result: {}", result); // Output: 8
}
}
use uni_core::{Interpreter, execute_string};
let mut interp = Interpreter::new();
// Define a square function
execute_string("'square [dup *] def", &mut interp).unwrap();
// Use it
execute_string("5 square", &mut interp).unwrap();
println!("{}", interp.stack.last().unwrap()); // Output: 25
std - Standard library support (default: disabled)advanced_math - Trigonometric functions, exp/log, roundingcomplex_numbers - Complex number and Gaussian integer supportrepl - REPL (Read-Eval-Print Loop) with line editing supportdatetime - Date/time operations (requires std)hardware-microbit - micro:bit v2 hardware primitiveshardware-pico2 - Raspberry Pi Pico 2 (RP2350) hardware primitiveshardware-stm32h753zi - STM32H753ZI hardware primitives (async Embassy)To build products with custom primitives and an interactive REPL:
use uni_core::{Interpreter, repl::run_repl, Value, RuntimeError};
use uni_core::interpreter::DictEntry;
use editline::terminals::StdioTerminal;
use std::rc::Rc;
// Your custom primitive
fn my_op(interp: &mut Interpreter) -> Result<(), RuntimeError> {
let n = interp.pop_number()?;
interp.push(Value::Number(n * 42.0));
Ok(())
}
fn main() {
let mut interp = Interpreter::new();
// Register custom primitive
let atom = interp.intern_atom("my-op");
interp.dictionary.insert(atom, DictEntry {
value: Value::Builtin(my_op),
is_executable: true,
doc: Some(Rc::from("Multiply by 42\nUsage: n my-op => result")),
});
// Start REPL with your custom primitives
run_repl(interp, StdioTerminal::new());
}
Enable the repl feature in your Cargo.toml:
[dependencies]
uni-core = { version = "0.0.12", features = ["repl"] }
editline = "0.0.20"
For complete documentation, examples, and the command-line REPL, see the main repository:
GitHub: https://github.com/edadma/uni
Dual-licensed under MIT OR Unlicense.