@@ -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
1924type 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
8792func (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
0 commit comments