checkpoint

This commit is contained in:
2024-04-22 20:49:44 -07:00
parent c8d6719eb7
commit 52d5c9252b
15 changed files with 1528 additions and 1358 deletions

View File

@@ -84,9 +84,6 @@ impl Program {
let mut warnings = vec![];
for stmt in self.items.iter() {
if let TopLevel::Function(Some(name), _, _, _) = stmt {
bound_variables.insert(name.to_string(), name.location.clone());
}
let (mut new_errors, mut new_warnings) = stmt.validate_with_bindings(bound_variables);
errors.append(&mut new_errors);
warnings.append(&mut new_warnings);
@@ -119,18 +116,6 @@ impl TopLevel {
bound_variables: &mut ScopedMap<String, Location>,
) -> (Vec<Error>, Vec<Warning>) {
match self {
TopLevel::Function(name, arguments, _, body) => {
bound_variables.new_scope();
if let Some(name) = name {
bound_variables.insert(name.name.clone(), name.location.clone());
}
for (arg, _) in arguments.iter() {
bound_variables.insert(arg.name.clone(), arg.location.clone());
}
let result = body.validate(bound_variables);
bound_variables.release_scope();
result
}
TopLevel::Expression(expr) => expr.validate(bound_variables),
TopLevel::Structure(_, _, _) => (vec![], vec![]),
}
@@ -214,6 +199,18 @@ impl Expression {
(errors, warnings)
}
Expression::Function(_, name, arguments, _, body) => {
if let Some(name) = name {
variable_map.insert(name.name.clone(), name.location.clone());
}
variable_map.new_scope();
for (arg, _) in arguments.iter() {
variable_map.insert(arg.name.clone(), arg.location.clone());
}
let result = body.validate(variable_map);
variable_map.release_scope();
result
}
}
}
}