1 package org.python.core; 3 import java.util.Stack ; 4 5 public class ThreadState { 6 public PySystemState systemState; 8 public PyFrame frame; 9 public PyException exception; 12 public Thread thread; 13 public boolean tracing; 14 public PyList reprStack = null; 15 private Stack 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 (); 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 t, PySystemState systemState) { 45 thread = t; 46 50 this.systemState = systemState; 51 tracing = false; 53 } 55 56 public boolean enterRepr(PyObject obj) { 57 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 |