KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > core > ThreadState


1 // Copyright (c) Corporation for National Research Initiatives
2
package org.python.core;
3 import java.util.Stack JavaDoc;
4
5 public class ThreadState {
6     //public InterpreterState interp;
7
public PySystemState systemState;
8     public PyFrame frame;
9     //public PyObject curexc_type, curexc_value, curexc_traceback;
10
//public PyObject exc_type, exc_value, exc_traceback;
11
public PyException exception;
12     public Thread JavaDoc thread;
13     public boolean tracing;
14     public PyList reprStack = null;
15     //public PyInstance initializingProxy = null;
16
private Stack JavaDoc initializingProxies = null;
17
18     public int compareStateNesting = 0;
19     private PyDictionary compareStateDict;
20
21     public int recursion_depth = 0;
22
23     public PyInstance getInitializingProxy() {
24         if (initializingProxies == null || initializingProxies.empty()) {
25             return null;
26         }
27         return (PyInstance)initializingProxies.peek();
28     }
29
30     public void pushInitializingProxy(PyInstance proxy) {
31         if (initializingProxies == null) {
32             initializingProxies = new Stack JavaDoc();
33         }
34         initializingProxies.push(proxy);
35     }
36
37     public void popInitializingProxy() {
38         if (initializingProxies == null || initializingProxies.empty()) {
39             throw Py.RuntimeError("invalid initializing proxies state");
40         }
41         initializingProxies.pop();
42     }
43
44     public ThreadState(Thread JavaDoc t, PySystemState systemState) {
45         thread = t;
46         // Fake multiple interpreter states for now
47
/*if (Py.interp == null) {
48           Py.interp = InterpreterState.getInterpreterState();
49           }*/

50         this.systemState = systemState;
51         //interp = Py.interp;
52
tracing = false;
53         //System.out.println("new thread state");
54
}
55
56     public boolean enterRepr(PyObject obj) {
57         //if (reprStack == null) System.err.println("reprStack: null");
58
//else System.err.println("reprStack: "+reprStack.__len__());
59
if (reprStack == null) {
60             reprStack = new PyList(new PyObject[] {obj});
61             return true;
62         }
63         for(int i=reprStack.size()-1; i>=0; i--) {
64             if (obj == reprStack.pyget(i))
65                 return false;
66         }
67         reprStack.append(obj);
68         return true;
69     }
70
71     public void exitRepr(PyObject obj) {
72         if (reprStack == null)
73             return;
74
75         for (int i = reprStack.size()-1; i>=0; i--) {
76             if (reprStack.pyget(i) == obj) {
77                 reprStack.delRange(i, reprStack.size(), 1);
78             }
79         }
80     }
81
82     public PyDictionary getCompareStateDict() {
83         if (compareStateDict == null)
84             compareStateDict = new PyDictionary();
85         return compareStateDict;
86     }
87 }
88
Popular Tags