validator validates recursive functions
This commit is contained in:
parent
35e9d0373d
commit
36c5d125fb
|
@ -161,15 +161,16 @@ pub fn run(src: &'static str) {
|
|||
|
||||
match result {
|
||||
Ok(result) => println!("{}", result),
|
||||
Err(LErr { msg, .. }) => println!("Errors!\n{}", msg),
|
||||
Err(LErr { msg, .. }) => println!("Ludus panicked!\n{}", msg),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let src = "
|
||||
let bar = :foo
|
||||
fn foo (foo, bar, ...) -> bar
|
||||
foo (42)
|
||||
fn foo () -> {
|
||||
foo
|
||||
}
|
||||
foo () () () ()
|
||||
";
|
||||
run(src);
|
||||
// struct_scalpel::print_dissection_info::<value::Value>()
|
||||
|
|
|
@ -85,7 +85,9 @@ impl<'a> Validator<'a> {
|
|||
}
|
||||
|
||||
fn define_fn(&mut self, name: String, info: FnInfo) {
|
||||
self.locals.push((name, self.span, info));
|
||||
let i = self.locals.iter().position(|(n, ..)| *n == name).unwrap();
|
||||
let new_binding = (name, self.locals[i].1, info);
|
||||
self.locals[i] = new_binding;
|
||||
}
|
||||
|
||||
fn resolved(&self, name: &str) -> bool {
|
||||
|
@ -415,8 +417,9 @@ impl<'a> Validator<'a> {
|
|||
self.status.tail_position = tailpos;
|
||||
}
|
||||
Fn(name, clauses, ..) => {
|
||||
let mut is_declared = false;
|
||||
match self.bound(name) {
|
||||
Some((_, _, FnInfo::Declared)) => (),
|
||||
Some((_, _, FnInfo::Declared)) => is_declared = true,
|
||||
None => (),
|
||||
_ => {
|
||||
self.err(format!("name `{name}` is already bound"));
|
||||
|
@ -424,6 +427,9 @@ impl<'a> Validator<'a> {
|
|||
}
|
||||
|
||||
// TODO: devise a placeholder binding for recursive functions
|
||||
if !is_declared {
|
||||
self.declare_fn(name.to_string());
|
||||
}
|
||||
|
||||
let from = self.status.used_bindings.len();
|
||||
let mut arities = HashSet::new();
|
||||
|
|
Loading…
Reference in New Issue
Block a user