Lines
100 %
Functions
Branches
use nomiscript::{
Compiler, Reader, eval_program,
runtime::{SymbolTable, Value},
};
fn eval_expr(code: &str) -> Result<Value, nomiscript::Error> {
let program = Reader::parse(code)?;
let mut symbols = SymbolTable::with_builtins();
eval_program(&mut symbols, &program)
}
fn compile(code: &str) -> Result<Vec<u8>, nomiscript::Error> {
let mut symbols = SymbolTable::with_builtins_for_wasm();
Compiler::new().compile(&program, &mut symbols)
#[test]
fn test_basic_defstruct() {
let code = r"
(defstruct person name age)
(quote person)
";
let result = eval_expr(code);
assert!(result.is_ok(), "Basic DEFSTRUCT should work");
fn test_defstruct_constructor() {
let code = r#"
(make-person :name "John" :age 30)
"#;
let wasm = compile(code);
assert!(
wasm.is_ok(),
"DEFSTRUCT constructor should compile: {wasm:?}"
);
fn test_setf_with_defstruct() {
(let ((p (make-person :name "John" :age 30)))
(setf (person-name p) "Jane")
(person-name p))
assert!(wasm.is_ok(), "SETF with defstruct should compile: {wasm:?}");
fn test_get_input_entities_is_wasm_only() {
;; GET-INPUT-ENTITIES returns a runtime cons list, which is WASM-only
(get-input-entities)
result.is_err(),
"GET-INPUT-ENTITIES should fail in interpreter (WASM-only)"