001: // Copyright (c) Corporation for National Research Initiatives
002: package org.python.core;
003:
004: import java.util.Stack;
005:
006: public class ThreadState {
007: // public InterpreterState interp;
008: public PySystemState systemState;
009:
010: public PyFrame frame;
011:
012: // public PyObject curexc_type, curexc_value, curexc_traceback;
013: // public PyObject exc_type, exc_value, exc_traceback;
014: public PyException exception;
015:
016: public Thread thread;
017:
018: public boolean tracing;
019:
020: public PyList reprStack = null;
021:
022: // public PyInstance initializingProxy = null;
023: private Stack initializingProxies = null;
024:
025: public int compareStateNesting = 0;
026:
027: private PyDictionary compareStateDict;
028:
029: public int recursion_depth = 0;
030:
031: public PyInstance getInitializingProxy() {
032: if (this .initializingProxies == null
033: || this .initializingProxies.empty()) {
034: return null;
035: }
036: return (PyInstance) this .initializingProxies.peek();
037: }
038:
039: public void pushInitializingProxy(PyInstance proxy) {
040: if (this .initializingProxies == null) {
041: this .initializingProxies = new Stack();
042: }
043: this .initializingProxies.push(proxy);
044: }
045:
046: public void popInitializingProxy() {
047: if (this .initializingProxies == null
048: || this .initializingProxies.empty()) {
049: throw Py.RuntimeError("invalid initializing proxies state");
050: }
051: this .initializingProxies.pop();
052: }
053:
054: public ThreadState(Thread t, PySystemState systemState) {
055: this .thread = t;
056: // Fake multiple interpreter states for now
057: /*
058: * if (Py.interp == null) { Py.interp =
059: * InterpreterState.getInterpreterState(); }
060: */
061: this .systemState = systemState;
062: // interp = Py.interp;
063: this .tracing = false;
064: // System.out.println("new thread state");
065: }
066:
067: public boolean enterRepr(PyObject obj) {
068: // if (reprStack == null) System.err.println("reprStack: null");
069: // else System.err.println("reprStack: "+reprStack.__len__());
070: if (this .reprStack == null) {
071: this .reprStack = new PyList(new PyObject[] { obj });
072: return true;
073: }
074: for (int i = this .reprStack.size() - 1; i >= 0; i--) {
075: if (obj == this .reprStack.pyget(i)) {
076: return false;
077: }
078: }
079: this .reprStack.append(obj);
080: return true;
081: }
082:
083: public void exitRepr(PyObject obj) {
084: if (this .reprStack == null) {
085: return;
086: }
087:
088: for (int i = this .reprStack.size() - 1; i >= 0; i--) {
089: if (this .reprStack.pyget(i) == obj) {
090: this .reprStack.delRange(i, this .reprStack.size(), 1);
091: }
092: }
093: }
094:
095: public PyDictionary getCompareStateDict() {
096: if (this .compareStateDict == null) {
097: this .compareStateDict = new PyDictionary();
098: }
099: return this.compareStateDict;
100: }
101: }
|