mark core as nostd

* implement custom hashmap to back symtable
* pass in print and read callbacks to keep stdlib pure
* use core / alloc versions of Box, Rc, Vec, etc
* replace pow func with libm

Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2024-07-26 22:16:21 -07:00
parent 0c2aad2cb6
commit d6a0e68460
26 changed files with 493 additions and 288 deletions

View file

@ -6,7 +6,7 @@ mod control_lib_tests {
fn test_assert_t() {
let document = "(assert true)";
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
}
@ -14,7 +14,7 @@ mod control_lib_tests {
fn test_assert_f() {
let document = "(assert false)";
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
assert!(eval(&lex(&document.to_string()).unwrap(), &mut syms).is_err())
}
@ -23,7 +23,7 @@ mod control_lib_tests {
let document = "(if true 1 2)";
let result = 1;
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
@ -37,7 +37,7 @@ mod control_lib_tests {
let document = "(if false 1 2)";
let result = 2;
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
@ -51,7 +51,7 @@ mod control_lib_tests {
let document = "(if true (cons () 1) 2)";
let result = "(1)";
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
@ -68,7 +68,7 @@ mod control_lib_tests {
temp)";
let result = "(\"1\" \"2\")";
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
@ -86,7 +86,7 @@ mod control_lib_tests {
let document2 = "global";
let result = "(\"hello world\")";
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
eval(&lex(&document1.to_string()).unwrap(), &mut syms).unwrap();
assert_eq!(
*eval(&lex(&document2.to_string()).unwrap(), &mut syms)
@ -101,7 +101,7 @@ mod control_lib_tests {
let document = "(let ((temp \"1\")) temp (cons () temp \"2\"))";
let result = "(\"1\" \"2\")";
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
@ -120,7 +120,7 @@ mod control_lib_tests {
let result = "(\"1\" \"2\" \"3\")";
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
@ -148,7 +148,7 @@ mod control_lib_tests {
let check_tree = lex(&test_check.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
eval(&switch_tree, &mut syms).unwrap();
eval(&while_tree, &mut syms).unwrap();
@ -174,7 +174,7 @@ mod control_lib_tests {
let check_tree = lex(&test_check.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
eval(&switch_tree, &mut syms).unwrap();
eval(&while_tree, &mut syms).unwrap();
@ -200,7 +200,7 @@ mod control_lib_tests {
let check_tree = lex(&test_check.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
eval(&another_tree, &mut syms).unwrap();
eval(&switch_tree, &mut syms).unwrap();
@ -217,7 +217,7 @@ mod control_lib_tests {
let test_tree = lex(&test.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
eval(&doc_tree, &mut syms).unwrap();
let res = eval(&test_tree, &mut syms);
@ -234,7 +234,7 @@ mod control_lib_tests {
let test_tree = lex(&test.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms);
static_stdlib(&mut syms, |_: &String| (), || String::new());
eval(&doc_tree, &mut syms).unwrap();
assert_eq!(