Skip to content

Commit e552306

Browse files
committed
Fix VM so calling functions works properly
1 parent 3726302 commit e552306

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

notes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Testing
1616
python3 -m dis hello.py
1717
python3 -mcompileall hello.py
1818
mv __pycache__/hello.cpython-33.pyc hello.pyc
19+
python -c 'import hello; import dis; dis.dis(hello.fn)'
1920

2021
go build ./... && go build
2122
./gpython hello.pyc

vm/eval.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ func (vm *Vm) PushFrame(globals, locals py.StringDict, code *py.Code) {
862862
Builtins: py.Builtins.Globals,
863863
}
864864
vm.frames = append(vm.frames, frame)
865-
vm.frame = &frame
865+
vm.frame = &vm.frames[len(vm.frames)-1]
866866
}
867867

868868
// Drop the current frame
@@ -884,7 +884,6 @@ func Run(globals, locals py.StringDict, code *py.Code) (err error) {
884884
vm := NewVm()
885885
defer func() {
886886
if r := recover(); r != nil {
887-
fmt.Printf("vmstack = %#v\n", vm.stack)
888887
switch x := r.(type) {
889888
case error:
890889
err = x
@@ -918,6 +917,7 @@ func Run(globals, locals py.StringDict, code *py.Code) (err error) {
918917
}
919918
vm.extended = false
920919
jumpTable[opcode](vm, arg)
920+
fmt.Printf("* Stack = %#v\n", vm.stack)
921921
}
922922
if len(vm.stack) != 1 {
923923
fmt.Printf("vmstack = %#v\n", vm.stack)

0 commit comments

Comments
 (0)