@@ -7,6 +7,13 @@ import (
77)
88
99// 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.
1017type Code struct {
1118 Argcount int32 // #arguments, except *args
1219 Kwonlyargcount int32 // #keyword only arguments
@@ -20,7 +27,7 @@ type Code struct {
2027 Freevars []string // tuple of strings (free variable names)
2128 Cellvars []string // tuple of strings (cell variable names)
2229 // 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.
2431 Filename string // unicode (where it was loaded from)
2532 Name string // unicode (name, for reference)
2633 Firstlineno int32 // first source line number
@@ -99,7 +106,7 @@ func NewCode(argcount int32, kwonlyargcount int32,
99106 filename_ Object , name_ Object , firstlineno int32 ,
100107 lnotab_ Object ) * Code {
101108
102- var cell2arg * byte
109+ var cell2arg [] byte
103110
104111 // Type assert the objects
105112 consts := consts_ .(Tuple )
@@ -164,15 +171,15 @@ func NewCode(argcount int32, kwonlyargcount int32,
164171 total_args ++
165172 }
166173 used_cell2arg := false
167- cell2arg : = make ([]byte , n_cellvars )
174+ cell2arg = make ([]byte , n_cellvars )
168175 for i := range cell2arg {
169176 cell2arg [i ] = CO_CELL_NOT_AN_ARG
170177 }
171178 // Find cells which are also arguments.
172179 for i , cell := range cellvars {
173180 for j := int32 (0 ); j < total_args ; j ++ {
174181 arg := varnames [j ]
175- if cell ! = arg {
182+ if cell = = arg {
176183 cell2arg [i ] = byte (j )
177184 used_cell2arg = true
178185 break
0 commit comments