diff --git a/demo/test.py b/demo/test.py index b117674..9c4fe5f 100644 --- a/demo/test.py +++ b/demo/test.py @@ -1,9 +1,7 @@ -a = 1 -def b(): - c = 20 - print(c) +a = 10 +def b(x): + # c = "test" + print(x) -b() -print(c) - \ No newline at end of file +b(a) \ No newline at end of file diff --git a/src/vm/Object.zig b/src/vm/Object.zig index 64ef102..e1ea4d7 100644 --- a/src/vm/Object.zig +++ b/src/vm/Object.zig @@ -210,6 +210,7 @@ pub fn format( try writer.writeAll(")"); }, + else => try writer.print("TODO: Object.format '{s}'", .{@tagName(object.tag)}), } } diff --git a/src/vm/Vm.zig b/src/vm/Vm.zig index fa63039..57197af 100644 --- a/src/vm/Vm.zig +++ b/src/vm/Vm.zig @@ -189,13 +189,13 @@ fn execLoadGlobal(vm: *Vm, inst: Instruction) !void { fn execLoadFast(vm: *Vm, inst: Instruction) !void { const var_num = inst.extra; const obj = vm.current_co.varnames[var_num]; + log.debug("LoadFast obj tag: {s}", .{@tagName(obj.tag)}); try vm.stack.append(vm.allocator, obj); } fn execStoreName(vm: *Vm, inst: Instruction) !void { const name = vm.current_co.getName(inst.extra); const tos = vm.stack.pop(); - try vm.scopes.items[vm.depth].put(vm.allocator, name, tos); } @@ -242,6 +242,11 @@ fn execCallFunction(vm: *Vm, inst: Instruction) !void { vm.current_co.* = func.co.*; vm.depth += 1; + + // Set the args. + for (args, 0..) |arg, i| { + vm.current_co.varnames[i] = arg; + } } } @@ -462,6 +467,8 @@ pub fn loadConst(allocator: Allocator, inst: Marshal.Result) !Object { fn lookUpwards(vm: *Vm, name: []const u8) ?Object { const scopes = vm.scopes.items; + log.debug("lookUpwards depth {}", .{vm.depth}); + return obj: { // Check the immediate scope. if (scopes[vm.depth].get(name)) |val| {