basic function calls, still with bugs!

This commit is contained in:
Scott Richmond 2025-06-03 15:48:13 -04:00
parent 22d1ceb3e8
commit 681176282c
3 changed files with 519 additions and 489 deletions

View File

@ -286,9 +286,9 @@ fn get_builtin(name: &str, arity: usize) -> Option<Op> {
pub struct Compiler {
pub chunk: Chunk,
pub bindings: Vec<Binding>,
scope_depth: isize,
match_depth: usize,
stack_depth: usize,
pub scope_depth: isize,
pub match_depth: usize,
pub stack_depth: usize,
pub spans: Vec<SimpleSpan>,
pub nodes: Vec<&'static Ast>,
pub ast: &'static Ast,
@ -837,10 +837,8 @@ impl Compiler {
// visit all the args
// then store them
// then call the function
for (register_slot, arg) in args.iter().enumerate() {
for arg in args {
self.visit(arg);
self.emit_op(Op::StoreAt);
self.emit_byte(register_slot);
}
self.emit_op(Op::PushBinding);
@ -982,7 +980,7 @@ impl Compiler {
Some(compiler) => compiler,
None => {
let mut compiler = Compiler::new(clause, self.name, self.src);
compiler.emit_op(Op::Load);
// compiler.emit_op(Op::Load);
compiler.stack_depth += arity;
compiler.scope_depth += 1;
compiler.emit_op(Op::ResetMatch);

View File

@ -78,7 +78,9 @@ pub fn run(src: &'static str) {
pub fn main() {
env::set_var("RUST_BACKTRACE", "1");
let src = "
(1, 2, 3)
fn foo (_) -> [1, 2, 3]
foo (1)
";
run(src);
}

992
src/vm.rs

File diff suppressed because it is too large Load Diff