|
11 | 11 | // executed so far. |
12 | 12 | package py |
13 | 13 |
|
14 | | -import ( |
15 | | - "fmt" |
16 | | -) |
17 | | - |
18 | 14 | // A python Function object |
19 | 15 | type Function struct { |
20 | 16 | Code *Code // A code object, the __code__ attribute |
@@ -87,48 +83,9 @@ func NewFunction(code *Code, globals StringDict, qualname string) *Function { |
87 | 83 | } |
88 | 84 | } |
89 | 85 |
|
90 | | -// Setup locals for calling the function with the given arguments |
91 | | -func (f *Function) LocalsForCall(args Tuple) StringDict { |
92 | | - // fmt.Printf("call f %#v with %v\n", f, args) |
93 | | - max := int(f.Code.Argcount) |
94 | | - min := max - len(f.Defaults) |
95 | | - if len(args) > max || len(args) < min { |
96 | | - if min == max { |
97 | | - panic(ExceptionNewf(TypeError, "%s() takes %d positional arguments but %d were given", f.Name, max, len(args))) |
98 | | - } else { |
99 | | - panic(ExceptionNewf(TypeError, "%s() takes from %d to %d positional arguments but %d were given", f.Name, min, max, len(args))) |
100 | | - } |
101 | | - } |
102 | | - |
103 | | - // FIXME not sure this is right! |
104 | | - // Copy the args into the local variables |
105 | | - locals := NewStringDict() |
106 | | - for i := range args { |
107 | | - locals[f.Code.Varnames[i]] = args[i] |
108 | | - } |
109 | | - for i := len(args); i < max; i++ { |
110 | | - locals[f.Code.Varnames[i]] = f.Defaults[i-min] |
111 | | - } |
112 | | - // fmt.Printf("locals = %v\n", locals) |
113 | | - return locals |
114 | | -} |
115 | | - |
116 | | -// Call the function with the given arguments |
117 | | -func (f *Function) LocalsForCallWithKeywords(args Tuple, kwargs StringDict) StringDict { |
118 | | - locals := NewStringDict() |
119 | | - fmt.Printf("FIXME LocalsForCallWithKeywords NOT IMPLEMENTED\n") |
120 | | - return locals |
121 | | -} |
122 | | - |
123 | 86 | // Call a function |
124 | 87 | func (f *Function) M__call__(args Tuple, kwargs StringDict) Object { |
125 | | - var locals StringDict |
126 | | - if kwargs != nil { |
127 | | - locals = f.LocalsForCallWithKeywords(args, kwargs) |
128 | | - } else { |
129 | | - locals = f.LocalsForCall(args) |
130 | | - } |
131 | | - result, err := Run(f.Globals, locals, f.Code, f.Closure) |
| 88 | + result, err := VmEvalCodeEx(f.Code, f.Globals, NewStringDict(), args, kwargs, f.Defaults, f.KwDefaults, f.Closure) |
132 | 89 | if err != nil { |
133 | 90 | // Propagate the error |
134 | 91 | panic(err) |
|
0 commit comments