Skip to content

Commit af9a450

Browse files
committed
Work around circular import - now calls python functions
1 parent 9a79b97 commit af9a450

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

py/function.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import (
1515
"fmt"
1616
)
1717

18+
var (
19+
// Function pointer for vm call to avoid circular reference
20+
VmRun func(StringDict, StringDict, *Code) (error)
21+
)
22+
1823
// A python Function object
1924
type Function struct {
2025
Code *Code // A code object, the __code__ attribute
@@ -86,9 +91,9 @@ func NewFunction(code *Code, globals StringDict, qualname String) *Function {
8691
// Call the function with the given arguments
8792
func (f *Function) Call(self Object, args Tuple) Object {
8893
fmt.Printf("call f %#v with %v and %v\n", f, self, args)
89-
if len(f.Code.Varnames) < len(args) {
90-
panic("Too many args!")
94+
if len(args) != int(f.Code.Argcount) {
9195
// FIXME don't know how to deal with default args
96+
panic("Wrong number of arguments")
9297
}
9398
// FIXME not sure this is right!
9499
// Copy the args into the local variables
@@ -97,7 +102,8 @@ func (f *Function) Call(self Object, args Tuple) Object {
97102
locals[string(f.Code.Varnames[i].(String))] = args[i]
98103
}
99104
fmt.Printf("locals = %v\n", locals)
100-
// FIXME return vm.Run(f.Globals, locals, f.Code)
105+
// FIXME return?
106+
VmRun(f.Globals, locals, f.Code)
101107
return None
102108
}
103109

vm/eval.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,12 @@ func do_CALL_FUNCTION_VAR_KW(vm *Vm, argc int32) {
744744

745745
// NotImplemented
746746
func (vm *Vm) NotImplemented(name string, arg int32) {
747-
fmt.Printf("%s %d Not implemented\n", name, arg)
747+
fmt.Printf("%s %d NOT IMPLEMENTED\n", name, arg)
748+
}
749+
750+
// Poke the vm.Run into py
751+
func init() {
752+
py.VmRun = Run
748753
}
749754

750755
// Run the virtual machine on the code object in the module

0 commit comments

Comments
 (0)