Skip to content

Commit 7da7167

Browse files
committed
aways add None to the co_consts
1 parent 6399db7 commit 7da7167

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

src/org/python/compiler/CodeCompiler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public boolean makeClosure(ScopeInfo scope) throws Exception {
460460
for (int j = 1; j < scope.distance; j++) {
461461
loadf_back();
462462
}
463-
SymInfo symInfo = upTbl.get(scope.freevars.elementAt(i));
463+
SymInfo symInfo = upTbl.get(scope.freevars.get(i));
464464
code.iconst(symInfo.env_index);
465465
code.invokevirtual(p(PyFrame.class), "getclosure", sig(PyObject.class, Integer.TYPE));
466466
code.aastore();

src/org/python/compiler/Module.java

+18-22
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class PyCodeConstant extends Constant implements ClassConstants, Opcodes {
305305

306306
// !classdef only
307307
if (!classBody) {
308-
varnames = toNameAr(scope.names, false);
308+
varnames = toNameAr(scope.varNames, false);
309309
} else {
310310
varnames = null;
311311
}
@@ -698,31 +698,27 @@ public void error(String msg, boolean err, PythonTree node) throws Exception {
698698
}
699699

700700
public int makeConstArray(Code code, java.util.List<? extends PythonTree> nodes) throws IOException {
701-
final int n;
701+
int n = 1;
702702

703-
if (nodes == null) {
704-
n = 0;
705-
} else {
706-
n = nodes.size();
703+
if (nodes != null) {
704+
n += nodes.size();
707705
}
708706

709707
int array = code.getLocal(ci(PyObject[].class));
710-
if (n == 0) {
711-
code.getstatic(p(Py.class), "EmptyObjects", ci(PyObject[].class));
712-
code.astore(array);
713-
} else {
714-
code.iconst(n);
715-
code.anewarray(p(PyObject.class));
716-
code.astore(array);
717-
718-
for (int i = 0; i < n; i++) {
719-
constant(nodes.get(i)).get(code);
720-
code.aload(array);
721-
code.swap();
722-
code.iconst(i);
723-
code.swap();
724-
code.aastore();
725-
}
708+
709+
code.iconst(n);
710+
code.anewarray(p(PyObject.class));
711+
code.astore(array);
712+
code.aload(array);
713+
code.iconst(0);
714+
code.getstatic(p(Py.class), "None", ci(PyObject.class));
715+
code.aastore();
716+
717+
for (int i = 1; i < n; i++) {
718+
code.aload(array);
719+
code.iconst(i);
720+
constant(nodes.get(i - 1)).get(code);
721+
code.aastore();
726722
}
727723
return array;
728724
}

src/org/python/compiler/ScopeInfo.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public ScopeInfo(String name, PythonTree node, int level, int kind,
7171
public ArgListCompiler ac;
7272

7373
public Map<String, SymInfo> tbl = new LinkedHashMap<String, SymInfo>();
74-
public List<String> names = new ArrayList<>();
74+
public List<String> varNames = new ArrayList<>();
7575

7676
public int addNonlocal(String name) {
7777
SymInfo info = tbl.get(name);
@@ -102,7 +102,7 @@ public int addGlobal(String name) {
102102
public void addParam(String name) {
103103
//System.out.println("addParam " + name);
104104
tbl.put(name, new SymInfo(PARAM|BOUND,local++));
105-
names.add(name);
105+
varNames.add(name);
106106
}
107107

108108
public void markFromParam() {
@@ -137,11 +137,10 @@ public void addConst(PythonTree node) {
137137

138138
public Hashtable<String,Object> inner_free = new Hashtable<String,Object>();
139139

140-
// FIXME: names should be varnames, globalNames is names, for corresponding fields in code object
141-
public List<String> globalNames = new ArrayList<>();
140+
public List<String> globalNames = new ArrayList<>(); // co_names
142141
public List<PythonTree> constants = new ArrayList<>(); // co_consts
143-
public List<String> freevars = new ArrayList<>();
144-
public List<String> cellvars = new ArrayList<>();
142+
public List<String> freevars = new ArrayList<>(); // co_freevars
143+
public List<String> cellvars = new ArrayList<>(); // co_cellvars
145144
public List<String> jy_paramcells = new ArrayList<>();
146145

147146
public int jy_npurecell;
@@ -195,7 +194,7 @@ public void cook(ScopeInfo up, int distance, CompilationContext ctxt) throws Exc
195194
if ((flags&(GLOBAL|PARAM|CELL)) == 0) {
196195
if ((flags&BOUND) != 0) { // ?? only func
197196
// System.err.println("local: "+name);
198-
names.add(name);
197+
varNames.add(name);
199198
info.locals_index = local++;
200199
continue;
201200
}
@@ -207,7 +206,7 @@ public void cook(ScopeInfo up, int distance, CompilationContext ctxt) throws Exc
207206
if ((jy_npurecell = purecells.size()) > 0) {
208207
int sz = purecells.size();
209208
for (int i = 0; i < sz; i++) {
210-
names.add(purecells.elementAt(i));
209+
varNames.add(purecells.get(i));
211210
}
212211
}
213212

src/org/python/core/PyTableCode.java

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.python.expose.ExposedType;
1111
import org.python.modules._systemrestart;
1212

13+
import java.util.ArrayList;
14+
1315
@Untraversable
1416
@ExposedType(name = "code", base = PyObject.class, doc = BuiltinDocs.code_doc)
1517
public class PyTableCode extends PyBaseCode

0 commit comments

Comments
 (0)