From: <pj...@us...> - 2008-10-18 01:58:37
|
Revision: 5460 http://jython.svn.sourceforge.net/jython/?rev=5460&view=rev Author: pjenvey Date: 2008-10-18 01:58:29 +0000 (Sat, 18 Oct 2008) Log Message: ----------- store the symbol name info in a LinkedHashMap to maintain the order they're encountered in. fixes test_code technically this should bump the bytecode magic but it's not that important Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java trunk/jython/src/org/python/compiler/Module.java trunk/jython/src/org/python/compiler/ScopeInfo.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-17 23:56:07 UTC (rev 5459) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-10-18 01:58:29 UTC (rev 5460) @@ -4,6 +4,7 @@ import java.io.IOException; import java.util.Hashtable; +import java.util.Map; import java.util.Stack; import java.util.Vector; @@ -109,7 +110,7 @@ public boolean fast_locals, print_results; - public Hashtable tbl; + public Map<String, SymInfo> tbl; public ScopeInfo my_scope; boolean optimizeGlobals = true; @@ -369,7 +370,7 @@ code.iconst(n); code.anewarray("org/python/core/PyObject"); code.astore(tmp); - Hashtable upTbl = scope.up.tbl; + Map<String, SymInfo> upTbl = scope.up.tbl; for(int i=0; i<n; i++) { code.aload(tmp); code.iconst(i); @@ -377,7 +378,7 @@ for(int j = 1; j < scope.distance; j++) { loadf_back(); } - SymInfo symInfo = (SymInfo)upTbl.get(scope.freevars.elementAt(i)); + SymInfo symInfo = upTbl.get(scope.freevars.elementAt(i)); code.iconst(symInfo.env_index); code.invokevirtual("org/python/core/PyFrame", "getclosure", "(I)" + $pyObj); code.aastore(); @@ -2044,7 +2045,7 @@ else name = getName(node.id); - SymInfo syminf = (SymInfo)tbl.get(name); + SymInfo syminf = tbl.get(name); expr_contextType ctx = node.ctx; if (ctx == expr_contextType.AugStore) { Modified: trunk/jython/src/org/python/compiler/Module.java =================================================================== --- trunk/jython/src/org/python/compiler/Module.java 2008-10-17 23:56:07 UTC (rev 5459) +++ trunk/jython/src/org/python/compiler/Module.java 2008-10-18 01:58:29 UTC (rev 5460) @@ -6,6 +6,7 @@ import java.io.OutputStream; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Map; import java.util.Vector; import org.python.objectweb.asm.Label; @@ -460,11 +461,11 @@ } int nparamcell = scope.jy_paramcells.size(); if(nparamcell > 0) { - Hashtable tbl = scope.tbl; + Map<String, SymInfo> tbl = scope.tbl; Vector paramcells = scope.jy_paramcells; for(int i = 0; i < nparamcell; i++) { c.aload(1); - SymInfo syminf = (SymInfo)tbl.get(paramcells.elementAt(i)); + SymInfo syminf = tbl.get(paramcells.elementAt(i)); c.iconst(syminf.locals_index); c.iconst(syminf.env_index); c.invokevirtual("org/python/core/PyFrame", "to_cell", "(II)V"); Modified: trunk/jython/src/org/python/compiler/ScopeInfo.java =================================================================== --- trunk/jython/src/org/python/compiler/ScopeInfo.java 2008-10-17 23:56:07 UTC (rev 5459) +++ trunk/jython/src/org/python/compiler/ScopeInfo.java 2008-10-18 01:58:29 UTC (rev 5460) @@ -3,6 +3,8 @@ package org.python.compiler; import java.util.Enumeration; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Hashtable; import java.util.Vector; @@ -24,9 +26,9 @@ for(int i=0; i<level; i++) System.err.print(' '); System.err.print(((kind != CLASSSCOPE)?scope_name:"class "+ scope_name)+": "); - for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { - String name = (String)e.nextElement(); - SymInfo info = (SymInfo)tbl.get(name); + for (Map.Entry<String, SymInfo> entry : tbl.entrySet()) { + String name = entry.getKey(); + SymInfo info = entry.getValue(); int flags = info.flags; System.err.print(name); if ((flags&BOUND) != 0) System.err.print('='); @@ -66,13 +68,13 @@ public ArgListCompiler ac; - public Hashtable tbl = new Hashtable(); + public Map<String, SymInfo> tbl = new LinkedHashMap<String, SymInfo>(); public Vector names = new Vector(); public int addGlobal(String name) { // global kind = func vs. class int global = kind==CLASSSCOPE?CLASS_GLOBAL:NGLOBAL; - SymInfo info = (SymInfo)tbl.get(name); + SymInfo info = tbl.get(name); if (info == null) { tbl.put(name,new SymInfo(global|BOUND)); return -1; @@ -91,14 +93,13 @@ } public void markFromParam() { - for (Enumeration e=tbl.elements(); e.hasMoreElements(); ) { - SymInfo info = (SymInfo)e.nextElement(); + for (SymInfo info : tbl.values()) { info.flags |= FROM_PARAM; } } public void addBound(String name) { - SymInfo info = (SymInfo)tbl.get(name); + SymInfo info = tbl.get(name); if (info == null) { tbl.put(name, new SymInfo(BOUND)); return; @@ -140,7 +141,7 @@ for (Enumeration e = inner_free.keys(); e.hasMoreElements(); ) { String name = (String)e.nextElement(); - SymInfo info = (SymInfo)tbl.get(name); + SymInfo info = tbl.get(name); if (info == null) { tbl.put(name,new SymInfo(FREE)); continue; @@ -164,9 +165,9 @@ boolean some_free = false; boolean nested = up.kind != TOPSCOPE; - for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { - String name = (String)e.nextElement(); - SymInfo info = (SymInfo)tbl.get(name); + for (Map.Entry<String, SymInfo> entry : tbl.entrySet()) { + String name = entry.getKey(); + SymInfo info = entry.getValue(); int flags = info.flags; if (nested && (flags&FREE) != 0) up.inner_free.put(name,PRESENT); if ((flags&(GLOBAL|PARAM|CELL)) == 0) { @@ -236,14 +237,14 @@ */ public void setup_closure(ScopeInfo up){ int free = cell; // env = cell...,free... - Hashtable up_tbl = up.tbl; + Map<String, SymInfo> up_tbl = up.tbl; boolean nested = up.kind != TOPSCOPE; - for (Enumeration e = tbl.keys(); e.hasMoreElements(); ) { - String name = (String)e.nextElement(); - SymInfo info = (SymInfo)tbl.get(name); + for (Map.Entry<String, SymInfo> entry : tbl.entrySet()) { + String name = entry.getKey(); + SymInfo info = entry.getValue(); int flags = info.flags; if ((flags&FREE) != 0) { - SymInfo up_info = (SymInfo)up_tbl.get(name); + SymInfo up_info = up_tbl.get(name); // ?? differs from CPython -- what is the intended behaviour? if (up_info != null) { int up_flags = up_info.flags; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |