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

@ -7,7 +7,7 @@ mod append_lib_tests {
let document = "(cons () 1)";
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()
@ -22,7 +22,7 @@ mod append_lib_tests {
let result = "(1 \"two\" 3.4)";
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 append_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()
@ -52,7 +52,7 @@ mod append_lib_tests {
let result = "(<nil>)";
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()
@ -67,7 +67,7 @@ mod append_lib_tests {
let result = "(\"test\" 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()
@ -82,7 +82,7 @@ mod append_lib_tests {
let result = "0";
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()
@ -97,7 +97,7 @@ mod append_lib_tests {
let result = "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()
@ -111,7 +111,7 @@ mod append_lib_tests {
let document = "(car ())";
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)
.err()
@ -130,7 +130,7 @@ mod append_lib_tests {
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()
@ -144,7 +144,7 @@ mod append_lib_tests {
let document = "(cdr ())";
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)
@ -164,7 +164,7 @@ mod append_lib_tests {
let result = "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)
@ -183,7 +183,7 @@ mod append_lib_tests {
let result2 = "(2 3)";
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();
let ch1 = lex(&check1.to_string()).unwrap();
@ -209,7 +209,7 @@ mod append_lib_tests {
let result2 = "(<nil>)";
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();
let ch1 = lex(&check1.to_string()).unwrap();
@ -235,7 +235,7 @@ mod append_lib_tests {
let result2 = "(1 2)";
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();
let ch1 = lex(&check1.to_string()).unwrap();
@ -261,7 +261,7 @@ mod append_lib_tests {
let result2 = "(<nil>)";
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();
let ch1 = lex(&check1.to_string()).unwrap();
@ -284,7 +284,7 @@ mod append_lib_tests {
let result = "(3 2 1 \"test\")";
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)
@ -300,7 +300,7 @@ mod append_lib_tests {
let result = "(\"test\")";
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)
@ -316,7 +316,7 @@ mod append_lib_tests {
let result = "(<nil>)";
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)
@ -332,7 +332,7 @@ mod append_lib_tests {
let result = "true";
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)
@ -348,7 +348,7 @@ mod append_lib_tests {
let result = "false";
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)