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:
parent
0c2aad2cb6
commit
d6a0e68460
26 changed files with 493 additions and 288 deletions
|
|
@ -9,7 +9,7 @@ mod decl_lib_tests {
|
|||
let result = "(1)";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||
|
|
@ -23,7 +23,7 @@ mod decl_lib_tests {
|
|||
let result = "((1))";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||
|
|
@ -37,7 +37,7 @@ mod decl_lib_tests {
|
|||
let result = "1";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||
|
|
@ -52,7 +52,7 @@ mod decl_lib_tests {
|
|||
let result = "(\"2\")";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||
|
|
@ -68,7 +68,7 @@ mod decl_lib_tests {
|
|||
let doc3 = "(test)";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||
|
|
@ -95,7 +95,7 @@ mod decl_lib_tests {
|
|||
let res2 = "(\"2\")";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||
|
|
@ -117,7 +117,7 @@ mod decl_lib_tests {
|
|||
(eq? test \"one\")))";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||
|
|
@ -135,7 +135,7 @@ mod decl_lib_tests {
|
|||
let result = "1";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
|
||||
let res = *eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
|
||||
|
|
@ -148,7 +148,7 @@ mod decl_lib_tests {
|
|||
let doc2 = "(set? test)";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
|
||||
let def_tree = lex(&doc1.to_string()).unwrap();
|
||||
let set_tree = lex(&doc2.to_string()).unwrap();
|
||||
|
|
@ -162,7 +162,7 @@ mod decl_lib_tests {
|
|||
fn test_isset_false() {
|
||||
let doc = "(set? test)";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let set_tree = lex(&doc.to_string()).unwrap();
|
||||
if let Ctr::Bool(b) = *eval(&set_tree, &mut syms).unwrap() {
|
||||
assert!(!b);
|
||||
|
|
@ -175,7 +175,7 @@ mod decl_lib_tests {
|
|||
let doc2 = "(env)";
|
||||
let doc3 = "t";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let set_tree = lex(&doc1.to_string()).unwrap();
|
||||
let env_tree = lex(&doc2.to_string()).unwrap();
|
||||
let tst_tree = lex(&doc3.to_string()).unwrap();
|
||||
|
|
@ -189,7 +189,7 @@ mod decl_lib_tests {
|
|||
let document = "(quote (add 1 2))";
|
||||
let result = "(add 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()
|
||||
|
|
@ -205,7 +205,7 @@ mod decl_lib_tests {
|
|||
(eval stored-tree)))";
|
||||
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()
|
||||
|
|
@ -219,7 +219,7 @@ mod decl_lib_tests {
|
|||
let document = "(eval (1 2 3))";
|
||||
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()
|
||||
|
|
@ -232,7 +232,7 @@ mod decl_lib_tests {
|
|||
fn test_lambda_str_equivalency_list() {
|
||||
let document = "(lambda (x y) (add x y))";
|
||||
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()
|
||||
|
|
@ -245,7 +245,7 @@ mod decl_lib_tests {
|
|||
fn test_lambda_str_equivalency_no_args() {
|
||||
let document = "(lambda () (add 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()
|
||||
|
|
@ -258,7 +258,7 @@ mod decl_lib_tests {
|
|||
fn test_lambda_inline_call() {
|
||||
let document = "((lambda (x y) (add x y)) 1 2)";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let it = *eval(
|
||||
&lex(&document.to_string()).unwrap(),
|
||||
&mut syms).unwrap();
|
||||
|
|
@ -274,7 +274,7 @@ mod decl_lib_tests {
|
|||
let document = "(let ((adder (lambda (x y) (add x y))))
|
||||
(adder 1 2))";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let it = *eval(
|
||||
&lex(&document.to_string()).unwrap(),
|
||||
&mut syms).unwrap();
|
||||
|
|
@ -291,7 +291,7 @@ mod decl_lib_tests {
|
|||
(def adder \"my adder\" (lambda (x y) (add x y)))
|
||||
(adder 1 2))";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let it = *eval(
|
||||
&lex(&document.to_string()).unwrap(),
|
||||
&mut syms).unwrap();
|
||||
|
|
@ -309,7 +309,7 @@ mod decl_lib_tests {
|
|||
(def adder \"my adder\" (lambda (x) (add x 1)))
|
||||
(appl adder 2))";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let it = *eval(
|
||||
&lex(&document.to_string()).unwrap(),
|
||||
&mut syms).unwrap();
|
||||
|
|
@ -326,7 +326,7 @@ mod decl_lib_tests {
|
|||
let highly_inadvisable = "(set-doc (q help) \"help\")";
|
||||
let document = "(get-doc (q help))";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let _ = *eval(
|
||||
&lex(&highly_inadvisable.to_string()).unwrap(),
|
||||
&mut syms).unwrap();
|
||||
|
|
@ -344,7 +344,7 @@ mod decl_lib_tests {
|
|||
fn test_eval_quote() {
|
||||
let doc = "(eval (quote (add 1 1)))";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
assert_eq!(
|
||||
*eval(&lex(&doc.to_string()).unwrap(), &mut syms).unwrap().to_string(),
|
||||
2.to_string()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue