From: <pj...@us...> - 2009-10-02 04:06:12
|
Revision: 6824 http://jython.svn.sourceforge.net/jython/?rev=6824&view=rev Author: pjenvey Date: 2009-10-02 04:05:54 +0000 (Fri, 02 Oct 2009) Log Message: ----------- o convert PyFrame to exposed annotations o specify its cached type during construction to avoid repeated PyType.fromClass calls o fix the f_lineno value while tracing PyByteCode Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/src/org/python/core/PyFrame.java trunk/jython/src/org/python/core/PyTraceback.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2009-10-02 03:45:27 UTC (rev 6823) +++ trunk/jython/CoreExposed.includes 2009-10-02 04:05:54 UTC (rev 6824) @@ -17,6 +17,7 @@ org/python/core/PyEllipsis.class org/python/core/PyFile.class org/python/core/PyFloat.class +org/python/core/PyFrame.class org/python/core/PyFrozenSet.class org/python/core/PyFunction.class org/python/core/PyGenerator.class Modified: trunk/jython/src/org/python/core/PyFrame.java =================================================================== --- trunk/jython/src/org/python/core/PyFrame.java 2009-10-02 03:45:27 UTC (rev 6823) +++ trunk/jython/src/org/python/core/PyFrame.java 2009-10-02 04:05:54 UTC (rev 6824) @@ -4,50 +4,63 @@ */ package org.python.core; +import org.python.expose.ExposedDelete; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; + /** * A Python frame object. */ +@ExposedType(name = "frame", isBaseType = false) public class PyFrame extends PyObject { + public static final PyType TYPE = PyType.fromClass(PyFrame.class); + /** Previous frame or null. */ + @ExposedGet public PyFrame f_back; /** The underyling code object. */ + @ExposedGet public PyBaseCode f_code; - /** Local symbol table. */ - public PyObject f_locals; + /** builtin symbol table. */ + @ExposedGet + public PyObject f_builtins; /** Global symbol table. */ + @ExposedGet public PyObject f_globals; + /** Local symbol table. */ + public PyObject f_locals; + /** Current line number. */ public int f_lineno; - /** builtin symbol table. */ - public PyObject f_builtins; - public PyObject[] f_fastlocals; /** Nested scopes: cell + free env. */ public PyCell[] f_env; + private int env_j = 0; + public int f_ncells; public int f_nfreevars; + @ExposedGet public int f_lasti; public Object[] f_savedlocals; - private int env_j = 0; - private Object generatorInput = Py.None; /** with context exits - used by generated bytecode */ public PyObject[] f_exits; - /** an interface to functions suitable for tracing, e.g. via sys.settrace(). */ + /** An interface to functions suitable for tracing, e.g. via sys.settrace(). */ public TraceFunction tracefunc; private static final String NAME_ERROR_MSG = "name '%.200s' is not defined"; @@ -57,10 +70,8 @@ private static final String UNBOUNDLOCAL_ERROR_MSG = "local variable '%.200s' referenced before assignment"; - private static final String[] __members__ = {"f_back", "f_code", "f_locals", "f_globals", - "f_lineno", "f_builtins", "f_trace"}; - public PyFrame(PyBaseCode code, PyObject locals, PyObject globals, PyObject builtins) { + super(TYPE); f_code = code; f_locals = locals; f_globals = globals; @@ -112,14 +123,6 @@ } } - public PyObject __dir__() { - PyString members[] = new PyString[__members__.length]; - for (int i = 0; i < __members__.length; i++) { - members[i] = new PyString(__members__[i]); - } - return new PyList(members); - } - void setGeneratorInput(Object value) { generatorInput = value; } @@ -134,58 +137,13 @@ return generatorInput; } - private void throwReadonly(String name) { - for (String member : __members__) { - if (member == name) { - throw Py.TypeError("readonly attribute"); - } - } - throw Py.AttributeError(name); - } - - public void __setattr__(String name, PyObject value) { - // In CPython, some of the frame's attributes are read/writeable - if (name == "f_trace") { - tracefunc = new PythonTraceFunction(value); - } else { - throwReadonly(name); - } - // not yet implemented: - // f_exc_type - // f_exc_value - // f_exc_traceback - } - - public void __delattr__(String name) { - if (name == "f_trace") { - tracefunc = null; - } else { - throwReadonly(name); - } - // not yet implemented: - // f_exc_type - // f_exc_value - // f_exc_traceback - } - - public PyObject __findattr_ex__(String name) { - if (name == "f_locals") { - return getLocals(); - } else if (name == "f_trace") { - if (tracefunc instanceof PythonTraceFunction) { - return ((PythonTraceFunction)tracefunc).tracefunc; - } - return Py.None; - } - return super.__findattr_ex__(name); - } - /** * Return the locals dict. First merges the fast locals into * f_locals, then returns the updated f_locals. * * @return a PyObject mapping of locals */ + @ExposedGet(name = "f_locals") public PyObject getLocals() { if (f_locals == null) { f_locals = new PyStringMap(); @@ -218,6 +176,22 @@ return f_locals; } + @ExposedGet(name = "f_trace") + public PyObject getTrace() { + return tracefunc instanceof PythonTraceFunction ? + ((PythonTraceFunction)tracefunc).tracefunc : Py.None; + } + + @ExposedSet(name = "f_trace") + public void setTrace(PyObject trace) { + tracefunc = new PythonTraceFunction(trace); + } + + @ExposedDelete(name = "f_trace") + public void delTrace() { + tracefunc = null; + } + /** * Return the current f_locals dict. * @@ -243,8 +217,9 @@ } } + @ExposedGet(name = "f_lineno") public int getline() { - return f_code.getline(this); + return tracefunc != null ? f_lineno : f_code.getline(this); } public PyObject getlocal(int index) { Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2009-10-02 03:45:27 UTC (rev 6823) +++ trunk/jython/src/org/python/core/PyTraceback.java 2009-10-02 04:05:54 UTC (rev 6824) @@ -26,7 +26,7 @@ super(TYPE); tb_next = next; tb_frame = frame; - tb_lineno = frame.getline(); + tb_lineno = frame.f_code.getline(frame); } private String tracebackInfo() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |