Skip to content

Commit 2008d78

Browse files
committed
Fix CALL_FUNCTION opcode
1 parent 7e4713c commit 2008d78

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

py/frame.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ func (f *Frame) Lookup(name string) (obj Object) {
7070
var ok bool
7171

7272
// Lookup in locals
73-
fmt.Printf("locals = %v\n", f.Locals)
73+
// fmt.Printf("locals = %v\n", f.Locals)
7474
if obj, ok = f.Locals[name]; ok {
7575
return
7676
}
7777

7878
// Lookup in globals
79-
fmt.Printf("globals = %v\n", f.Globals)
79+
// fmt.Printf("globals = %v\n", f.Globals)
8080
if obj, ok = f.Globals[name]; ok {
8181
return
8282
}
8383

8484
// Lookup in builtins
85-
fmt.Printf("builtins = %v\n", Builtins.Globals)
85+
// fmt.Printf("builtins = %v\n", Builtins.Globals)
8686
if obj, ok = f.Builtins[name]; ok {
8787
return
8888
}

py/function.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func NewFunction(code *Code, globals StringDict, qualname string) *Function {
8585

8686
// Setup locals for calling the function with the given arguments
8787
func (f *Function) LocalsForCall(args Tuple) StringDict {
88-
fmt.Printf("call f %#v with %v\n", f, args)
88+
// fmt.Printf("call f %#v with %v\n", f, args)
8989
if len(args) != int(f.Code.Argcount) {
9090
// FIXME don't know how to deal with default args
9191
panic("Wrong number of arguments")
@@ -96,7 +96,7 @@ func (f *Function) LocalsForCall(args Tuple) StringDict {
9696
for i := range args {
9797
locals[f.Code.Varnames[i]] = args[i]
9898
}
99-
fmt.Printf("locals = %v\n", locals)
99+
// fmt.Printf("locals = %v\n", locals)
100100
return locals
101101
}
102102

vm/eval.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,9 @@ func do_RAISE_VARARGS(vm *Vm, argc int32) {
683683
// function arguments, and the function itself off the stack, and
684684
// pushes the return value.
685685
func do_CALL_FUNCTION(vm *Vm, argc int32) {
686-
fmt.Printf("Stack: %v\n", vm.stack)
687-
fmt.Printf("Locals: %v\n", vm.frame.Locals)
688-
fmt.Printf("Globals: %v\n", vm.frame.Globals)
686+
// fmt.Printf("Stack: %v\n", vm.stack)
687+
// fmt.Printf("Locals: %v\n", vm.frame.Locals)
688+
// fmt.Printf("Globals: %v\n", vm.frame.Globals)
689689
nargs := int(argc & 0xFF)
690690
nkwargs := int((argc >> 8) & 0xFF)
691691
p, q := len(vm.stack)-2*nkwargs, len(vm.stack)
@@ -695,7 +695,7 @@ func do_CALL_FUNCTION(vm *Vm, argc int32) {
695695
p, q = p-1, p
696696
fn := vm.stack[p]
697697
// Drop everything off the stack
698-
vm.stack = vm.stack[:q]
698+
vm.stack = vm.stack[:p]
699699
vm.Call(fn, args, kwargs)
700700
}
701701

@@ -815,7 +815,7 @@ func (vm *Vm) NotImplemented(name string, arg int32) {
815815
//
816816
// The result is put on the stack
817817
func (vm *Vm) Call(fnObj py.Object, args []py.Object, kwargs []py.Object) {
818-
fmt.Printf("Call %T %v with args = %v, kwargs = %v\n", fnObj, fnObj, args, kwargs)
818+
// fmt.Printf("Call %T %v with args = %v, kwargs = %v\n", fnObj, fnObj, args, kwargs)
819819
var kwargsd py.StringDict
820820
if len(kwargs) > 0 {
821821
// Convert kwargs into dictionary
@@ -881,8 +881,10 @@ func (vm *Vm) PopFrame() {
881881
//
882882
// Any parameters are expected to have been decoded into locals
883883
func Run(globals, locals py.StringDict, code *py.Code) (err error) {
884+
vm := NewVm()
884885
defer func() {
885886
if r := recover(); r != nil {
887+
fmt.Printf("vmstack = %#v\n", vm.stack)
886888
switch x := r.(type) {
887889
case error:
888890
err = x
@@ -893,7 +895,6 @@ func Run(globals, locals py.StringDict, code *py.Code) (err error) {
893895
}
894896
}
895897
}()
896-
vm := NewVm()
897898
vm.PushFrame(globals, locals, code)
898899

899900
var opcode byte

0 commit comments

Comments
 (0)