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
|
|
@ -7,7 +7,7 @@ mod str_lib_tests {
|
|||
let document = "(concat \"test\")";
|
||||
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)
|
||||
.unwrap()
|
||||
|
|
@ -21,7 +21,7 @@ mod str_lib_tests {
|
|||
let document = "(concat \"test\" 1 2 3)";
|
||||
let result = "\"test123\"";
|
||||
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()
|
||||
|
|
@ -35,7 +35,7 @@ mod str_lib_tests {
|
|||
let document = "(concat)";
|
||||
let result = "\"\"";
|
||||
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()
|
||||
|
|
@ -49,7 +49,7 @@ mod str_lib_tests {
|
|||
let document = "(strlen \"test\")";
|
||||
let result = 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()
|
||||
|
|
@ -63,7 +63,7 @@ mod str_lib_tests {
|
|||
let document = "(strlen 1000)";
|
||||
let result = 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()
|
||||
|
|
@ -77,7 +77,7 @@ mod str_lib_tests {
|
|||
let document = "(strlen 10.2)";
|
||||
let result = 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()
|
||||
|
|
@ -91,7 +91,7 @@ mod str_lib_tests {
|
|||
let document = "(strlen (1 2 3))";
|
||||
let result = 7;
|
||||
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()
|
||||
|
|
@ -105,7 +105,7 @@ mod str_lib_tests {
|
|||
let document = "(strlen true)";
|
||||
let result = 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()
|
||||
|
|
@ -119,7 +119,7 @@ mod str_lib_tests {
|
|||
let document = "(string 4)";
|
||||
let result = "\"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()
|
||||
|
|
@ -133,7 +133,7 @@ mod str_lib_tests {
|
|||
let document = "(string (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()
|
||||
|
|
@ -147,7 +147,7 @@ mod str_lib_tests {
|
|||
let document = "(substr? \"bigger\" \"ger\")";
|
||||
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)
|
||||
.unwrap()
|
||||
|
|
@ -161,7 +161,7 @@ mod str_lib_tests {
|
|||
let document = "(substr? \"smaller\" \"ger\")";
|
||||
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)
|
||||
.unwrap()
|
||||
|
|
@ -175,7 +175,7 @@ mod str_lib_tests {
|
|||
let document = "(split \"one.two.three\" \".\")";
|
||||
let result = "(\"one\" \"two\" \"three\")";
|
||||
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()
|
||||
|
|
@ -189,7 +189,7 @@ mod str_lib_tests {
|
|||
let document = "(split \"one:d:two:d:three\" \":d:\")";
|
||||
let result = "(\"one\" \"two\" \"three\")";
|
||||
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()
|
||||
|
|
@ -203,7 +203,7 @@ mod str_lib_tests {
|
|||
let document = "(split \"one.two.three\" \"-\")";
|
||||
let result = "(\"one.two.three\")";
|
||||
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()
|
||||
|
|
@ -217,7 +217,7 @@ mod str_lib_tests {
|
|||
let document = "(substr \"test\" 0 4)";
|
||||
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)
|
||||
.unwrap()
|
||||
|
|
@ -231,7 +231,7 @@ mod str_lib_tests {
|
|||
let document = "(substr \"test\" -1 3)";
|
||||
let result = "start index cannot be negative";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let doc_res= eval(&lex(&document.to_string()).unwrap(), &mut syms);
|
||||
if let Err(e) = doc_res {
|
||||
assert_eq!(
|
||||
|
|
@ -248,7 +248,7 @@ mod str_lib_tests {
|
|||
let document = "(substr \"test\" 1 -3)";
|
||||
let result = "end index cannot be negative";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let doc_res= eval(&lex(&document.to_string()).unwrap(), &mut syms);
|
||||
if let Err(e) = doc_res {
|
||||
assert_eq!(
|
||||
|
|
@ -265,7 +265,7 @@ mod str_lib_tests {
|
|||
let document = "(substr \"test\" 5 3)";
|
||||
let result = "start index larger than source string";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let doc_res= eval(&lex(&document.to_string()).unwrap(), &mut syms);
|
||||
if let Err(e) = doc_res {
|
||||
assert_eq!(
|
||||
|
|
@ -282,7 +282,7 @@ mod str_lib_tests {
|
|||
let document = "(substr \"test\" 1 5)";
|
||||
let result = "end index larger than source string";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let doc_res= eval(&lex(&document.to_string()).unwrap(), &mut syms);
|
||||
if let Err(e) = doc_res {
|
||||
assert_eq!(
|
||||
|
|
@ -299,7 +299,7 @@ mod str_lib_tests {
|
|||
let document = "(substr \"test\" 3 2)";
|
||||
let result = "end index must be larger than start index";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
static_stdlib(&mut syms, |_: &String| (), || String::new());
|
||||
let doc_res= eval(&lex(&document.to_string()).unwrap(), &mut syms);
|
||||
if let Err(e) = doc_res {
|
||||
assert_eq!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue