File tree 2 files changed +21
-3
lines changed
2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,9 @@ func main() {
62
62
}
63
63
code := obj .(* py.Code )
64
64
v := vm .NewVm ()
65
- v .Run (code )
65
+ err = v .Run (code )
66
+ if err != nil {
67
+ log .Fatal (err )
68
+ }
66
69
67
70
}
Original file line number Diff line number Diff line change 2
2
package vm
3
3
4
4
import (
5
+ "errors"
5
6
"fmt"
6
7
"github.com/ncw/gpython/py"
7
8
)
@@ -777,7 +778,21 @@ func do_CALL_FUNCTION_VAR_KW(vm *Vm, argc int32) {
777
778
}
778
779
779
780
// Run the virtual machine on the code object
780
- func (vm * Vm ) Run (co * py.Code ) {
781
+ //
782
+ // FIXME figure out how we are going to signal exceptions!
783
+ func (vm * Vm ) Run (co * py.Code ) (err error ) {
784
+ defer func () {
785
+ if r := recover (); r != nil {
786
+ switch x := r .(type ) {
787
+ case error :
788
+ err = x
789
+ case string :
790
+ err = errors .New (x )
791
+ default :
792
+ err = errors .New (fmt .Sprintf ("Unknown error '%s'" , x ))
793
+ }
794
+ }
795
+ }()
781
796
vm .co = co
782
797
ip := 0
783
798
var opcode byte
@@ -801,5 +816,5 @@ func (vm *Vm) Run(co *py.Code) {
801
816
vm .extended = false
802
817
jumpTable [opcode ](vm , arg )
803
818
}
804
- // Return something?
819
+ return nil
805
820
}
You can’t perform that action at this time.
0 commit comments