Several changes, see commit msg
* clean up all tests * bugfix for zero value functions, and test * removed expand function, put in snippets * added doc strings to Symbol type * added doc strings to symbol declarations * implemented display for Args type * wrote a help function * wrote docstrings for all builtins and config vars
This commit is contained in:
parent
4b587f11ab
commit
dc6342bc74
16 changed files with 575 additions and 677 deletions
29
src/sym.rs
29
src/sym.rs
|
|
@ -19,6 +19,7 @@ use crate::eval::eval;
|
|||
use crate::segment::{Ctr, Seg, Type};
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SymTable(HashMap<String, Symbol>);
|
||||
|
|
@ -66,6 +67,7 @@ pub struct Symbol {
|
|||
// for internal control flow constructs
|
||||
// eval() will not eval the args
|
||||
pub conditional_branches: bool,
|
||||
pub docs: String,
|
||||
}
|
||||
|
||||
impl SymTable {
|
||||
|
|
@ -203,6 +205,23 @@ impl Args {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Args {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Args::None => write!(f, "none"),
|
||||
Args::Infinite => write!(f, "infinite, untyped"),
|
||||
Args::Lazy(n) => write!(f, "{} args of any type", n),
|
||||
Args::Strict(s) => {
|
||||
write!(f, "types: ")?;
|
||||
for arg in s {
|
||||
write!(f, "{} ", arg)?
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Symbol {
|
||||
/* call
|
||||
* routine is called by eval when a symbol is expanded
|
||||
|
|
@ -229,10 +248,7 @@ impl Symbol {
|
|||
evaluated_args = args;
|
||||
}
|
||||
|
||||
if let Err(msg) = self.args.validate_inputs(evaluated_args) {
|
||||
return Err(format!("failure to call {}: {}", self.name, msg));
|
||||
}
|
||||
|
||||
self.args.validate_inputs(evaluated_args)?;
|
||||
match &self.value {
|
||||
ValueType::VarForm(ref f) => Ok(Box::new(*f.clone())),
|
||||
ValueType::Internal(ref f) => Ok(Box::new(f(evaluated_args, syms)?)),
|
||||
|
|
@ -251,6 +267,7 @@ impl Symbol {
|
|||
name: f.arg_syms[n].clone(),
|
||||
value: ValueType::VarForm(Box::new(evaluated_args[n].clone())),
|
||||
args: Args::None,
|
||||
docs: format!("local argument to {}", f.arg_syms[n].clone()),
|
||||
conditional_branches: false,
|
||||
},
|
||||
) {
|
||||
|
|
@ -265,7 +282,7 @@ impl Symbol {
|
|||
if let Ctr::Seg(ref data) = *iterate.car {
|
||||
match eval(data, syms) {
|
||||
Ok(ctr) => result = ctr,
|
||||
Err(e) => return Err(e),
|
||||
Err(e) => return Err(format!("evaluation failure\n{}", e)),
|
||||
}
|
||||
} else {
|
||||
let temp = Seg::from_mono(iterate.car.clone());
|
||||
|
|
@ -277,7 +294,7 @@ impl Symbol {
|
|||
result = ctr;
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
Err(e) => return Err(format!("evaluation failure\n{}", e)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue