implement basic control flow, error handling from functions, many tests
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
ae365ad63c
commit
09e3546ba6
14 changed files with 315 additions and 488 deletions
|
|
@ -1,4 +1,5 @@
|
|||
mod func_tests {
|
||||
use std::rc::Rc;
|
||||
use relish::ast::lex;
|
||||
use relish::ast::{SymTable, Type, UserFn};
|
||||
use relish::ast::{Args, Symbol, Ctr, Seg, ValueType};
|
||||
|
|
@ -10,14 +11,14 @@ mod func_tests {
|
|||
name: String::from("test_func_in"),
|
||||
conditional_branches: false,
|
||||
args: Args::Strict(vec![Type::Bool]),
|
||||
value: ValueType::Internal(Box::new(
|
||||
|a: &Seg, _: &mut SymTable| -> Ctr {
|
||||
value: ValueType::Internal(Rc::new(
|
||||
|a: &Seg, _: &mut SymTable| -> Result<Ctr, String> {
|
||||
let inner = a;
|
||||
let mut is_bool = false;
|
||||
if let Ctr::Bool(_) = *inner.car {
|
||||
is_bool = true;
|
||||
}
|
||||
Ctr::Bool(is_bool)
|
||||
Ok(Ctr::Bool(is_bool))
|
||||
},
|
||||
)),
|
||||
};
|
||||
|
|
@ -123,17 +124,17 @@ mod func_tests {
|
|||
name: String::from("test_inner"),
|
||||
conditional_branches: false,
|
||||
args: Args::Strict(vec![Type::Bool]),
|
||||
value: ValueType::Internal(Box::new(
|
||||
|a: &Seg, _: &mut SymTable| -> Ctr {
|
||||
value: ValueType::Internal(Rc::new(
|
||||
|a: &Seg, _: &mut SymTable| -> Result<Ctr, String> {
|
||||
let inner = a;
|
||||
if let Ctr::Bool(b) = *inner.car {
|
||||
if b {
|
||||
Ctr::String("test".to_string())
|
||||
Ok(Ctr::String("test".to_string()))
|
||||
} else {
|
||||
Ctr::None
|
||||
Ok(Ctr::None)
|
||||
}
|
||||
} else {
|
||||
Ctr::None
|
||||
Err("not a bool".to_string())
|
||||
}
|
||||
},
|
||||
)),
|
||||
|
|
@ -184,14 +185,14 @@ mod func_tests {
|
|||
name: String::from("test_func_in"),
|
||||
conditional_branches: false,
|
||||
args: Args::Strict(vec![Type::Bool]),
|
||||
value: ValueType::Internal(Box::new(
|
||||
|a: &Seg, _: &mut SymTable| -> Ctr {
|
||||
value: ValueType::Internal(Rc::new(
|
||||
|a: &Seg, _: &mut SymTable| -> Result<Ctr, String> {
|
||||
let inner = a;
|
||||
let mut is_bool = false;
|
||||
if let Ctr::Bool(_) = *inner.car {
|
||||
is_bool = true;
|
||||
}
|
||||
Ctr::Bool(is_bool)
|
||||
Ok(Ctr::Bool(is_bool))
|
||||
},
|
||||
)),
|
||||
};
|
||||
|
|
@ -279,14 +280,14 @@ mod func_tests {
|
|||
name: String::from("test_func_in"),
|
||||
conditional_branches: false,
|
||||
args: Args::Strict(vec![Type::Bool]),
|
||||
value: ValueType::Internal(Box::new(
|
||||
|a: &Seg, _: &mut SymTable| -> Ctr {
|
||||
value: ValueType::Internal(Rc::new(
|
||||
|a: &Seg, _: &mut SymTable| -> Result<Ctr, String> {
|
||||
let inner = a;
|
||||
let mut is_bool = false;
|
||||
if let Ctr::Bool(_) = *inner.car {
|
||||
is_bool = true;
|
||||
}
|
||||
Ctr::Bool(is_bool)
|
||||
Ok(Ctr::Bool(is_bool))
|
||||
},
|
||||
)),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue