replace mutex with rwlock
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
c7d0bba928
commit
e055f26e90
5 changed files with 72 additions and 54 deletions
|
|
@ -51,25 +51,28 @@ mod eval_tests {
|
|||
|
||||
#[test]
|
||||
fn eval_function_call() {
|
||||
let mut table_handle = SYM_TABLE.lock().unwrap();
|
||||
let test_doc = "('one' (echo 'unwrap_me'))".to_string();
|
||||
let output = "('one' 'unwrap_me')";
|
||||
let test_external_func: Symbol = Symbol {
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
has_undefined_symbols: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::new(Ctr::Seg(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None)))),
|
||||
Box::new(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
table_handle.insert(String::from("echo"), test_external_func);
|
||||
{ // we want the write lock to expire before eval
|
||||
let mut table_handle = SYM_TABLE.write().unwrap();
|
||||
let test_external_func: Symbol = Symbol {
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
has_undefined_symbols: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::new(Ctr::Seg(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None)))),
|
||||
Box::new(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
table_handle.insert(String::from("echo"), test_external_func);
|
||||
}
|
||||
match lex(&test_doc) {
|
||||
Err(e) => {
|
||||
println!("Lexing error: {}\n", e);
|
||||
|
|
@ -91,25 +94,28 @@ mod eval_tests {
|
|||
|
||||
#[test]
|
||||
fn eval_embedded_func_calls() {
|
||||
let mut table_handle = SYM_TABLE.lock().unwrap();
|
||||
let test_doc = "('one' (echo (echo 'unwrap_me')))".to_string();
|
||||
let output = "('one' 'unwrap_me')";
|
||||
let test_external_func: Symbol = Symbol{
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
has_undefined_symbols: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::new(Ctr::Seg(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None)))),
|
||||
Box::new(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
table_handle.insert(String::from("echo"), test_external_func);
|
||||
{
|
||||
let mut table_handle = SYM_TABLE.write().unwrap();
|
||||
let test_external_func: Symbol = Symbol{
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
has_undefined_symbols: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::new(Ctr::Seg(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None)))),
|
||||
Box::new(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
table_handle.insert(String::from("echo"), test_external_func);
|
||||
}
|
||||
match lex(&test_doc) {
|
||||
Err(e) => {
|
||||
println!("Lexing error: {}\n", e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue