@@ -15,6 +15,11 @@ import (
15
15
"fmt"
16
16
)
17
17
18
+ var (
19
+ // Function pointer for vm call to avoid circular reference
20
+ VmRun func (StringDict , StringDict , * Code ) (error )
21
+ )
22
+
18
23
// A python Function object
19
24
type Function struct {
20
25
Code * Code // A code object, the __code__ attribute
@@ -86,9 +91,9 @@ func NewFunction(code *Code, globals StringDict, qualname String) *Function {
86
91
// Call the function with the given arguments
87
92
func (f * Function ) Call (self Object , args Tuple ) Object {
88
93
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 ) {
91
95
// FIXME don't know how to deal with default args
96
+ panic ("Wrong number of arguments" )
92
97
}
93
98
// FIXME not sure this is right!
94
99
// Copy the args into the local variables
@@ -97,7 +102,8 @@ func (f *Function) Call(self Object, args Tuple) Object {
97
102
locals [string (f .Code .Varnames [i ].(String ))] = args [i ]
98
103
}
99
104
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 )
101
107
return None
102
108
}
103
109
0 commit comments