PyBytecode codeobj = new PyBytecode(2, 2, 10, 64, "", consts, names, new String[]{ "", "" }, "noname", "<module>", 0, ""); Reflections.setFieldValue(codeobj, "co_code", new BigInteger(code, 16).toByteArray());
get_dis().invoke("disassemble", this); opcode = getUnsigned(co_code, next_instr); if (opcode >= Opcode.HAVE_ARGUMENT) { next_instr += 2; oparg = (getUnsigned(co_code, next_instr) << 8) + getUnsigned(co_code, next_instr - 1); print_debug(count, next_instr, line, opcode, oparg, stack, f); PyTryBlock b = popBlock(f); while (stack.size() > b.b_level) { stack.pop(); unpack_iterable(oparg, stack); break; case Opcode.SETUP_EXCEPT: case Opcode.SETUP_FINALLY: pushBlock(f, new PyTryBlock(opcode, next_instr + oparg, stack.size())); break; call_function(na, stack); } else { call_function(na, nk, stack); int nk = (oparg >> 8) & 0xff; int flags = (opcode - Opcode.CALL_FUNCTION) & 3; call_function(na, nk, (flags & CALL_FLAG_VAR) != 0,
private void print_debug(int count, int next_instr, int line, int opcode, int oparg, PyStack stack, PyFrame f) { if (debug) { System.err.println(co_name + " " + line + ":" + count + "," + f.f_lasti + "> " + get_opname().__getitem__(Py.newInteger(opcode)) + (opcode >= Opcode.HAVE_ARGUMENT ? " " + oparg : "") + ", stack: " + stack.toString() + ", blocks: " + stringify_blocks(f)); } }
public PyObject __findattr_ex__(String name) { return toPyStringTuple(co_varnames); return toPyStringTuple(co_cellvars); return toPyStringTuple(co_freevars); return new PyString(getString(co_code)); return new PyString(getString(co_lnotab));
@Override protected int getline(PyFrame f) { int addrq = f.f_lasti; int size = co_lnotab.length / 2; int p = 0; int line = co_firstlineno; int addr = 0; while (--size >= 0) { addr += getUnsigned(co_lnotab, p++); if (addr > addrq) { break; } line += getUnsigned(co_lnotab, p++); } return line; }
private static synchronized PyObject get_opname() { if (opname == null) { opname = get_dis().__getattr__("opname"); } return opname; } private boolean debug;
public PyBytecode(int argcount, int nlocals, int stacksize, int flags, String codestring, PyObject[] constants, String[] names, String varnames[], String filename, String name, int firstlineno, String lnotab, String[] cellvars, String[] freevars) { debug = defaultDebug; co_argcount = nargs = argcount; co_varnames = varnames; co_nlocals = nlocals; // maybe assert = varnames.length; co_filename = filename; co_firstlineno = firstlineno; co_cellvars = cellvars; co_freevars = freevars; co_name = name; co_flags = new CompilerFlags(flags); varargs = co_flags.isFlagSet(CodeFlag.CO_VARARGS); varkwargs = co_flags.isFlagSet(CodeFlag.CO_VARKEYWORDS); co_stacksize = stacksize; co_consts = constants; co_names = names; co_code = getBytes(codestring); co_lnotab = getBytes(lnotab); } private static final String[] __members__ = {
private static String getString(byte[] x) { StringBuilder buffer = new StringBuilder(x.length); for (int i = 0; i < x.length; i++) { buffer.append(getUnsigned(x, i)); } return buffer.toString(); }
String lnotab = read_object_notnull(depth + 1).toString(); return new PyBytecode( argcount, nlocals, stacksize, flags, code, consts, names, varnames,