Compare commits

...

2 Commits

Author SHA1 Message Date
Scott Richmond
681176282c basic function calls, still with bugs! 2025-06-03 15:48:13 -04:00
Scott Richmond
22d1ceb3e8 vm.chunk -> vm.callframe.chunk 2025-06-02 13:34:23 -04:00
3 changed files with 597 additions and 509 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

@ -57,26 +57,30 @@ pub fn run(src: &'static str) {
println!("\n\n")
}
// if DEBUG_RUN {
// println!("=== vm run: test ===");
// }
if DEBUG_RUN {
println!("=== vm run: test ===");
}
// let mut vm = Vm::new(&compiler.chunk);
// let result = vm.run();
// let output = match result {
// Ok(val) => val.show(&compiler.chunk),
// Err(panic) => format!("Ludus panicked! {panic}"),
// };
// vm.print_stack();
// println!("{output}");
// TODO: investigate lifeteims and remove this clone
let show_chunk = compiler.chunk.clone();
let vm_chunk = compiler.chunk;
let mut vm = Vm::new(vm_chunk);
let result = vm.run();
let output = match result {
Ok(val) => val.show(&show_chunk),
Err(panic) => format!("Ludus panicked! {panic}"),
};
vm.print_stack();
println!("{output}");
}
pub fn main() {
env::set_var("RUST_BACKTRACE", "1");
let src = "
fn foo () -> :bar
fn foo (_) -> [1, 2, 3]
foo ()
foo (1)
";
run(src);
}

1064
src/vm.rs

File diff suppressed because it is too large Load Diff