fix binding bug

This commit is contained in:
Scott Richmond 2025-06-20 00:33:25 -04:00
parent 8b004b45fa
commit fa587e38cd
2 changed files with 8 additions and 10 deletions

View File

@ -75,12 +75,12 @@ pub fn run(src: &'static str) {
pub fn main() {
env::set_var("RUST_BACKTRACE", "1");
let src = "
fn add_one (x) -> add (x, 1)
fn double (x) -> add (x, x)
fn square (x) -> mult (x, x)
double (2)
let whatevs = nil
let mult_factor = 3
fn mymult (x) -> mult (x, mult_factor)
fn thing (x) -> mymult (x)
thing (2)
";
run(src);
}

View File

@ -896,7 +896,7 @@ impl Vm {
let mut frame = CallFrame {
function: val,
arity,
stack_base: self.stack.len() - arity as usize,
stack_base: self.stack.len() - arity as usize - 1,
ip: 0,
};
@ -976,7 +976,7 @@ impl Vm {
let mut frame = CallFrame {
function: val,
arity,
stack_base: self.stack.len() - arity as usize,
stack_base: self.stack.len() - arity as usize - 1,
ip: 0,
};
@ -1057,8 +1057,6 @@ impl Vm {
GetUpvalue => {
let idx = self.chunk().bytecode[self.ip + 1];
self.ip += 2;
println!("getting upvalue {idx}");
dbg!(&self.frame.function);
if let Value::Fn(ref inner) = self.frame.function {
self.push(inner.as_ref().upvalue(idx));
} else {