From: Samuele P. <ped...@us...> - 2001-05-15 18:53:38
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv2169/core Modified Files: Py.java PyFrame.java PyTableCode.java parser.java Log Message: - fixed bug #415963 UnboundLocalError not raised on delete . - fixed bug related to free+bound vars in class scope . - incresead CPython compatibility: * code supports co_nlocals, co_flags have CO_OPTIMIZED set when meaningful * def f(): locals()['a']=1 print a now raises a NameError (like in CPython) * co_varnames == () and co_nlocals = 0 for classdef code ! Py.newCode and related funcs signatures have been changed - PyFrame.getf_locals() now deals with cell and free vars and handles the classdef case - compiler tiny mods for use by jythonc nested scopes support Index: Py.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/Py.java,v retrieving revision 2.42 retrieving revision 2.43 diff -C2 -r2.42 -r2.43 *** Py.java 2001/04/13 18:43:41 2.42 --- Py.java 2001/05/15 18:53:35 2.43 *************** *** 433,437 **** } ! // nested scopes: String[] cellvars,String[] freevars,int xxx_npurecell public static PyCode newCode(int argcount, String varnames[], --- 433,437 ---- } ! // nested scopes: String[] cellvars,String[] freevars,int xxx_npurecell & int moreflags public static PyCode newCode(int argcount, String varnames[], *************** *** 439,447 **** boolean args, boolean keywords, PyFunctionTable funcs, int func_id, ! String[] cellvars,String[] freevars,int xxx_npurecell) { return new PyTableCode(argcount, varnames, filename, name, 0, args, keywords, funcs, ! func_id, cellvars, freevars, xxx_npurecell); } --- 439,447 ---- boolean args, boolean keywords, PyFunctionTable funcs, int func_id, ! String[] cellvars,String[] freevars,int xxx_npurecell,int moreflags) { return new PyTableCode(argcount, varnames, filename, name, 0, args, keywords, funcs, ! func_id, cellvars, freevars, xxx_npurecell,moreflags); } *************** *** 451,460 **** boolean args, boolean keywords, PyFunctionTable funcs, int func_id, ! String[] cellvars,String[] freevars,int xxx_npurecell) { return new PyTableCode(argcount, varnames, filename, name, firstlineno, args, keywords, ! funcs, func_id, cellvars, freevars, xxx_npurecell); } --- 451,460 ---- boolean args, boolean keywords, PyFunctionTable funcs, int func_id, ! String[] cellvars,String[] freevars,int xxx_npurecell,int moreflags) { return new PyTableCode(argcount, varnames, filename, name, firstlineno, args, keywords, ! funcs, func_id, cellvars, freevars, xxx_npurecell,moreflags); } Index: PyFrame.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyFrame.java,v retrieving revision 2.7 retrieving revision 2.8 diff -C2 -r2.7 -r2.8 *** PyFrame.java 2001/03/08 23:43:51 2.7 --- PyFrame.java 2001/05/15 18:53:35 2.8 *************** *** 39,44 **** f_builtins = builtins; // This needs work to be efficient with multiple interpreter states ! if (locals == null && code != null && code.co_varnames.length > 0) { ! f_fastlocals = new PyObject[code.co_varnames.length-code.xxx_npurecell]; // internal: may change } if (code != null) { // reserve space for env --- 39,46 ---- f_builtins = builtins; // This needs work to be efficient with multiple interpreter states ! if (locals == null && code != null) { ! if ((code.co_flags&PyTableCode.CO_OPTIMIZED)!=0) { ! if (code.co_nlocals>0) f_fastlocals = new PyObject[code.co_nlocals-code.xxx_npurecell]; // internal: may change ! } else f_locals = new PyStringMap(); } if (code != null) { // reserve space for env *************** *** 112,124 **** if (f_locals == null) f_locals = new PyStringMap(); ! if (f_fastlocals != null && f_code != null) { ! for (int i=0; i<f_fastlocals.length; i++) { ! PyObject o = f_fastlocals[i]; ! if (o != null) ! f_locals.__setitem__(f_code.co_varnames[i], o); } ! // This should turn off fast_locals optimization after somebody ! // gets the locals dict ! f_fastlocals = null; } return f_locals; --- 114,138 ---- if (f_locals == null) f_locals = new PyStringMap(); ! if (f_code!=null && f_code.co_nlocals>0) { ! int i; ! if (f_fastlocals != null) { ! for (i=0; i<f_fastlocals.length; i++) { ! PyObject o = f_fastlocals[i]; ! if (o != null) f_locals.__setitem__(f_code.co_varnames[i], o); ! } ! /* ?? xxx_ ! // This should turn off fast_locals optimization after somebody ! // gets the locals dict ! f_fastlocals = null; */ } ! int j = 0; ! for (i=0; i<f_ncells; i++,j++) { ! PyObject v = f_env[j].ob_ref; ! if (v != null) f_locals.__setitem__(f_code.co_cellvars[i],v); ! } ! for (i=0; i<f_nfreevars; i++,j++) { ! PyObject v = f_env[j].ob_ref; ! if (v != null) f_locals.__setitem__(f_code.co_freevars[i],v); ! } } return f_locals; *************** *** 199,205 **** public void dellocal(int index) { ! if (f_fastlocals != null) ! f_fastlocals[index] = null; ! else dellocal(f_code.co_varnames[index]); } --- 213,222 ---- public void dellocal(int index) { ! if (f_fastlocals != null) { ! if (f_fastlocals[index] == null) { ! throw Py.UnboundLocalError("local: '"+f_code.co_varnames[index]+"'"); ! } ! f_fastlocals[index] = null; ! } else dellocal(f_code.co_varnames[index]); } *************** *** 208,212 **** if (f_locals == null) getf_locals(); ! f_locals.__delitem__(index); } --- 225,234 ---- if (f_locals == null) getf_locals(); ! try { ! f_locals.__delitem__(index); ! } catch(PyException e) { ! if (!Py.matchException(e,Py.KeyError)) throw e; ! throw Py.UnboundLocalError("local: '"+index+"'"); ! } } Index: PyTableCode.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/PyTableCode.java,v retrieving revision 2.12 retrieving revision 2.13 diff -C2 -r2.12 -r2.13 *** PyTableCode.java 2001/03/08 23:43:51 2.12 --- PyTableCode.java 2001/05/15 18:53:35 2.13 *************** *** 18,25 **** public String co_filename; public int co_flags; public boolean args, keywords; PyFunctionTable funcs; int func_id; ! public PyTableCode(int argcount, String varnames[], --- 18,32 ---- public String co_filename; public int co_flags; + public int co_nlocals; public boolean args, keywords; PyFunctionTable funcs; int func_id; ! ! final public static int CO_OPTIMIZED = 0x0001; ! //final public static int CO_NEWLOCALS = 0x0002 ! final public static int CO_VARARGS = 0x0004; ! final public static int CO_VARKEYWORDS = 0x0008; ! final public static int CO_NESTED = 0x0010; ! public PyTableCode(int argcount, String varnames[], *************** *** 29,33 **** PyFunctionTable funcs, int func_id) { ! this(argcount,varnames,filename,name,firstlineno,args,keywords,funcs,func_id,null,null,0); } --- 36,40 ---- PyFunctionTable funcs, int func_id) { ! this(argcount,varnames,filename,name,firstlineno,args,keywords,funcs,func_id,null,null,0,0); } *************** *** 37,44 **** boolean args, boolean keywords, PyFunctionTable funcs, int func_id, ! String[] cellvars,String[] freevars,int xxx_npurecell) // may change { co_argcount = nargs = argcount; co_varnames = varnames; co_filename = filename; co_firstlineno = firstlineno; --- 44,52 ---- boolean args, boolean keywords, PyFunctionTable funcs, int func_id, ! String[] cellvars,String[] freevars,int xxx_npurecell,int moreflags) // may change { co_argcount = nargs = argcount; co_varnames = varnames; + co_nlocals = varnames.length; co_filename = filename; co_firstlineno = firstlineno; *************** *** 50,60 **** if (args) { co_argcount -= 1; ! co_flags |= 0x04; } this.keywords = keywords; if (keywords) { co_argcount -= 1; ! co_flags |= 0x08; } this.funcs = funcs; this.func_id = func_id; --- 58,69 ---- if (args) { co_argcount -= 1; ! co_flags |= CO_VARARGS; } this.keywords = keywords; if (keywords) { co_argcount -= 1; ! co_flags |= CO_VARKEYWORDS; } + co_flags |= moreflags; this.funcs = funcs; this.func_id = func_id; *************** *** 64,69 **** "co_name", "co_argcount", "co_varnames", "co_filename", "co_firstlineno", ! "co_flags","co_cellvars","co_freevars" ! // not supported: co_nlocals, co_code, co_consts, co_names, // co_lnotab, co_stacksize }; --- 73,78 ---- "co_name", "co_argcount", "co_varnames", "co_filename", "co_firstlineno", ! "co_flags","co_cellvars","co_freevars","co_nlocals" ! // not supported: co_code, co_consts, co_names, // co_lnotab, co_stacksize }; Index: parser.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/parser.java,v retrieving revision 2.8 retrieving revision 2.9 diff -C2 -r2.8 -r2.9 *** parser.java 2001/02/25 16:52:54 2.8 --- parser.java 2001/05/15 18:53:35 2.9 *************** *** 27,31 **** } ! static PyException fixParseError(BufferedReader reader, Throwable t, String filename) { --- 27,31 ---- } ! static public PyException fixParseError(BufferedReader reader, Throwable t, String filename) { |