Formatting

This commit is contained in:
Michael Schimmel
2026-03-02 23:13:36 +01:00
parent 5bc69c267b
commit 2eb7a2e136
22 changed files with 3212 additions and 2813 deletions
+51 -21
View File
@@ -36,7 +36,7 @@ impl CompilationResult {
diagnostics: Diagnostics::new(),
}
}
pub fn error(msg: impl Into<String>) -> Self {
let mut diag = Diagnostics::new();
diag.push_error(msg, None);
@@ -123,11 +123,16 @@ impl MacroEvaluator for RuntimeMacroEvaluator {
let bound_ast = crate::ast::compiler::captures::CapturePass::apply(bound_ast, &captures);
let checker = TypeChecker::new(self.global_types.clone());
let typed_ast = checker.check(bound_ast, &[], &mut diag);
if diag.has_errors() {
return Err(diag.items.into_iter().map(|d| d.message).collect::<Vec<_>>().join("\n"));
return Err(diag
.items
.into_iter()
.map(|d| d.message)
.collect::<Vec<_>>()
.join("\n"));
}
let exec_ast = TCO::optimize(Analyzer::analyze(&typed_ast, &HashMap::new())); // Minimal analysis for macro eval
let mut vm = VM::new(self.global_values.clone());
@@ -191,7 +196,9 @@ impl Environment {
let mut parser = crate::ast::parser::Parser::new(source);
let untyped_ast = parser.parse_expression();
let mut expander = self.get_expander();
let _ = expander.expand(untyped_ast).expect("Failed to expand prelude");
let _ = expander
.expand(untyped_ast)
.expect("Failed to expand prelude");
*self.macro_registry.borrow_mut() = expander.into_registry();
}
@@ -261,7 +268,9 @@ impl Environment {
let untyped_ast = parser.parse_expression();
if !parser.at_eof() {
parser.diagnostics.push_error("Unexpected trailing expressions in script.", None);
parser
.diagnostics
.push_error("Unexpected trailing expressions in script.", None);
return CompilationResult {
ast: None,
diagnostics: parser.diagnostics,
@@ -273,17 +282,24 @@ impl Environment {
Ok(ast) => ast,
Err(e) => {
diagnostics.push_error(e, None);
return CompilationResult { ast: None, diagnostics };
return CompilationResult {
ast: None,
diagnostics,
};
}
};
let (bound_ast, captures) = match Binder::bind_root(self.global_names.clone(), &expanded_ast, &mut diagnostics) {
Ok(res) => res,
Err(e) => {
diagnostics.push_error(e, None);
return CompilationResult { ast: None, diagnostics };
}
};
let (bound_ast, captures) =
match Binder::bind_root(self.global_names.clone(), &expanded_ast, &mut diagnostics) {
Ok(res) => res,
Err(e) => {
diagnostics.push_error(e, None);
return CompilationResult {
ast: None,
diagnostics,
};
}
};
let bound_ast = crate::ast::compiler::captures::CapturePass::apply(bound_ast, &captures);
@@ -373,7 +389,10 @@ impl Environment {
let mut final_res = res;
if let Value::Object(obj) = &final_res
&& obj.as_any().downcast_ref::<crate::ast::vm::Closure>().is_some()
&& obj
.as_any()
.downcast_ref::<crate::ast::vm::Closure>()
.is_some()
{
final_res = match vm.run_with_args(obj.clone(), args) {
Ok(v) => v,
@@ -407,9 +426,14 @@ impl Environment {
let mut diag = Diagnostics::new();
let checker = TypeChecker::new(global_types.clone());
let retyped_ast = checker.check(func_template, arg_types, &mut diag);
if diag.has_errors() {
return Err(diag.items.into_iter().map(|d| d.message).collect::<Vec<_>>().join("\n"));
return Err(diag
.items
.into_iter()
.map(|d| d.message)
.collect::<Vec<_>>()
.join("\n"));
}
let analyzed = Analyzer::analyze(&retyped_ast, &global_purity.borrow());
@@ -465,7 +489,9 @@ impl Environment {
}
res
} else {
self.compile(source).into_result().and_then(|ast| self.run_script_compiled(ast))
self.compile(source)
.into_result()
.and_then(|ast| self.run_script_compiled(ast))
}
}
@@ -492,7 +518,11 @@ impl Environment {
while let Ok(Value::TailCallRequest(payload)) = result {
let (next_obj, next_args) = *payload;
if next_obj.as_any().downcast_ref::<crate::ast::vm::Closure>().is_some() {
if next_obj
.as_any()
.downcast_ref::<crate::ast::vm::Closure>()
.is_some()
{
result = vm.run_with_args_observed(&mut observer, next_obj, next_args);
} else {
result = Err(format!(
@@ -502,9 +532,9 @@ impl Environment {
break;
}
}
self.run_pipeline();
Ok((result, observer.logs))
}
}