implement basic control flow, error handling from functions, many tests

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-02-27 22:53:54 -08:00
parent ae365ad63c
commit 09e3546ba6
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
14 changed files with 315 additions and 488 deletions

View file

@ -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))
},
)),
};