Compare commits
No commits in common. "681176282cdd7da697f1f7e6fdb4d7a80c86924e" and "de3d7e834cc33c8aba46e3d03b9dc25516c5105f" have entirely different histories.
681176282c
...
de3d7e834c
|
@ -286,9 +286,9 @@ fn get_builtin(name: &str, arity: usize) -> Option<Op> {
|
||||||
pub struct Compiler {
|
pub struct Compiler {
|
||||||
pub chunk: Chunk,
|
pub chunk: Chunk,
|
||||||
pub bindings: Vec<Binding>,
|
pub bindings: Vec<Binding>,
|
||||||
pub scope_depth: isize,
|
scope_depth: isize,
|
||||||
pub match_depth: usize,
|
match_depth: usize,
|
||||||
pub stack_depth: usize,
|
stack_depth: usize,
|
||||||
pub spans: Vec<SimpleSpan>,
|
pub spans: Vec<SimpleSpan>,
|
||||||
pub nodes: Vec<&'static Ast>,
|
pub nodes: Vec<&'static Ast>,
|
||||||
pub ast: &'static Ast,
|
pub ast: &'static Ast,
|
||||||
|
@ -837,8 +837,10 @@ impl Compiler {
|
||||||
// visit all the args
|
// visit all the args
|
||||||
// then store them
|
// then store them
|
||||||
// then call the function
|
// then call the function
|
||||||
for arg in args {
|
for (register_slot, arg) in args.iter().enumerate() {
|
||||||
self.visit(arg);
|
self.visit(arg);
|
||||||
|
self.emit_op(Op::StoreAt);
|
||||||
|
self.emit_byte(register_slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.emit_op(Op::PushBinding);
|
self.emit_op(Op::PushBinding);
|
||||||
|
@ -980,7 +982,7 @@ impl Compiler {
|
||||||
Some(compiler) => compiler,
|
Some(compiler) => compiler,
|
||||||
None => {
|
None => {
|
||||||
let mut compiler = Compiler::new(clause, self.name, self.src);
|
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.stack_depth += arity;
|
||||||
compiler.scope_depth += 1;
|
compiler.scope_depth += 1;
|
||||||
compiler.emit_op(Op::ResetMatch);
|
compiler.emit_op(Op::ResetMatch);
|
||||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -57,30 +57,26 @@ pub fn run(src: &'static str) {
|
||||||
println!("\n\n")
|
println!("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
if DEBUG_RUN {
|
// if DEBUG_RUN {
|
||||||
println!("=== vm run: test ===");
|
// println!("=== vm run: test ===");
|
||||||
}
|
// }
|
||||||
|
|
||||||
// TODO: investigate lifeteims and remove this clone
|
// let mut vm = Vm::new(&compiler.chunk);
|
||||||
let show_chunk = compiler.chunk.clone();
|
// let result = vm.run();
|
||||||
let vm_chunk = compiler.chunk;
|
// let output = match result {
|
||||||
|
// Ok(val) => val.show(&compiler.chunk),
|
||||||
let mut vm = Vm::new(vm_chunk);
|
// Err(panic) => format!("Ludus panicked! {panic}"),
|
||||||
let result = vm.run();
|
// };
|
||||||
let output = match result {
|
// vm.print_stack();
|
||||||
Ok(val) => val.show(&show_chunk),
|
// println!("{output}");
|
||||||
Err(panic) => format!("Ludus panicked! {panic}"),
|
|
||||||
};
|
|
||||||
vm.print_stack();
|
|
||||||
println!("{output}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
env::set_var("RUST_BACKTRACE", "1");
|
env::set_var("RUST_BACKTRACE", "1");
|
||||||
let src = "
|
let src = "
|
||||||
fn foo (_) -> [1, 2, 3]
|
fn foo () -> :bar
|
||||||
|
|
||||||
foo (1)
|
foo ()
|
||||||
";
|
";
|
||||||
run(src);
|
run(src);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user