Compare commits
2 Commits
de3d7e834c
...
681176282c
Author | SHA1 | Date | |
---|---|---|---|
|
681176282c | ||
|
22d1ceb3e8 |
|
@ -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);
|
||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user