Compare commits

..

No commits in common. "681176282cdd7da697f1f7e6fdb4d7a80c86924e" and "de3d7e834cc33c8aba46e3d03b9dc25516c5105f" have entirely different histories.

3 changed files with 508 additions and 596 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>,
pub scope_depth: isize,
pub match_depth: usize,
pub stack_depth: usize,
scope_depth: isize,
match_depth: usize,
stack_depth: usize,
pub spans: Vec<SimpleSpan>,
pub nodes: Vec<&'static Ast>,
pub ast: &'static Ast,
@ -837,8 +837,10 @@ impl Compiler {
// visit all the args
// then store them
// then call the function
for arg in args {
for (register_slot, arg) in args.iter().enumerate() {
self.visit(arg);
self.emit_op(Op::StoreAt);
self.emit_byte(register_slot);
}
self.emit_op(Op::PushBinding);
@ -980,7 +982,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,30 +57,26 @@ pub fn run(src: &'static str) {
println!("\n\n")
}
if DEBUG_RUN {
println!("=== vm run: test ===");
}
// if DEBUG_RUN {
// println!("=== vm run: test ===");
// }
// 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}");
// 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}");
}
pub fn main() {
env::set_var("RUST_BACKTRACE", "1");
let src = "
fn foo (_) -> [1, 2, 3]
fn foo () -> :bar
foo (1)
foo ()
";
run(src);
}

1062
src/vm.rs

File diff suppressed because it is too large Load Diff