@@ -7,6 +7,13 @@ import (
7
7
)
8
8
9
9
// Code object
10
+ //
11
+ // Freevars are variables declared in the namespace where the
12
+ // code object was defined, they are used when closures are
13
+ // used - these become Cellvars in the function with a closure.
14
+ //
15
+ // Cellvars are names of local variables referenced by functions with
16
+ // a closure.
10
17
type Code struct {
11
18
Argcount int32 // #arguments, except *args
12
19
Kwonlyargcount int32 // #keyword only arguments
@@ -20,7 +27,7 @@ type Code struct {
20
27
Freevars []string // tuple of strings (free variable names)
21
28
Cellvars []string // tuple of strings (cell variable names)
22
29
// The rest doesn't count for hash or comparisons
23
- Cell2arg * byte // Maps cell vars which are arguments.
30
+ Cell2arg [] byte // Maps cell vars which are arguments.
24
31
Filename string // unicode (where it was loaded from)
25
32
Name string // unicode (name, for reference)
26
33
Firstlineno int32 // first source line number
@@ -99,7 +106,7 @@ func NewCode(argcount int32, kwonlyargcount int32,
99
106
filename_ Object , name_ Object , firstlineno int32 ,
100
107
lnotab_ Object ) * Code {
101
108
102
- var cell2arg * byte
109
+ var cell2arg [] byte
103
110
104
111
// Type assert the objects
105
112
consts := consts_ .(Tuple )
@@ -164,15 +171,15 @@ func NewCode(argcount int32, kwonlyargcount int32,
164
171
total_args ++
165
172
}
166
173
used_cell2arg := false
167
- cell2arg : = make ([]byte , n_cellvars )
174
+ cell2arg = make ([]byte , n_cellvars )
168
175
for i := range cell2arg {
169
176
cell2arg [i ] = CO_CELL_NOT_AN_ARG
170
177
}
171
178
// Find cells which are also arguments.
172
179
for i , cell := range cellvars {
173
180
for j := int32 (0 ); j < total_args ; j ++ {
174
181
arg := varnames [j ]
175
- if cell ! = arg {
182
+ if cell = = arg {
176
183
cell2arg [i ] = byte (j )
177
184
used_cell2arg = true
178
185
break
0 commit comments