Commit ff099f36 authored by Damien's avatar Damien
Browse files

py: add more functionality to showbc.

parent d47f9d5a
...@@ -52,12 +52,10 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -52,12 +52,10 @@ void py_show_byte_code(const byte *ip, int len) {
printf("LOAD_CONST_ID %s", qstr_str(qstr)); printf("LOAD_CONST_ID %s", qstr_str(qstr));
break; break;
/*
case PYBC_LOAD_CONST_STRING: case PYBC_LOAD_CONST_STRING:
DECODE_QSTR; DECODE_QSTR;
PUSH(rt_load_const_str(qstr)); printf("LOAD_CONST_STRING %s", qstr_str(qstr));
break; break;
*/
case PYBC_LOAD_FAST_0: case PYBC_LOAD_FAST_0:
printf("LOAD_FAST_0"); printf("LOAD_FAST_0");
...@@ -71,12 +69,10 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -71,12 +69,10 @@ void py_show_byte_code(const byte *ip, int len) {
printf("LOAD_FAST_2"); printf("LOAD_FAST_2");
break; break;
/*
case PYBC_LOAD_FAST_N: case PYBC_LOAD_FAST_N:
DECODE_UINT; DECODE_UINT;
PUSH(fastn[unum]); printf("LOAD_FAST_N %lu", unum);
break; break;
*/
case PYBC_LOAD_NAME: case PYBC_LOAD_NAME:
DECODE_QSTR; DECODE_QSTR;
...@@ -114,12 +110,10 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -114,12 +110,10 @@ void py_show_byte_code(const byte *ip, int len) {
printf("STORE_FAST_2"); printf("STORE_FAST_2");
break; break;
/*
case PYBC_STORE_FAST_N: case PYBC_STORE_FAST_N:
DECODE_UINT; DECODE_UINT;
fastn[unum] = POP(); printf("STORE_FAST_N %lu", unum);
break; break;
*/
case PYBC_STORE_NAME: case PYBC_STORE_NAME:
DECODE_QSTR; DECODE_QSTR;
...@@ -138,23 +132,20 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -138,23 +132,20 @@ void py_show_byte_code(const byte *ip, int len) {
printf("STORE_ATTR %s", qstr_str(qstr)); printf("STORE_ATTR %s", qstr_str(qstr));
break; break;
/*
case PYBC_STORE_SUBSCR: case PYBC_STORE_SUBSCR:
rt_store_subscr(sp[1], sp[0], sp[2]); printf("STORE_SUBSCR");
sp += 3;
break; break;
/*
case PYBC_DUP_TOP: case PYBC_DUP_TOP:
obj1 = *sp; obj1 = *sp;
PUSH(obj1); PUSH(obj1);
break; break;
*/
case PYBC_DUP_TOP_TWO: case PYBC_DUP_TOP_TWO:
sp -= 2; printf("DUP_TOP_TWO");
sp[0] = sp[2];
sp[1] = sp[3];
break; break;
*/
case PYBC_POP_TOP: case PYBC_POP_TOP:
printf("POP_TOP"); printf("POP_TOP");
...@@ -166,14 +157,11 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -166,14 +157,11 @@ void py_show_byte_code(const byte *ip, int len) {
sp[0] = sp[1]; sp[0] = sp[1];
sp[1] = obj1; sp[1] = obj1;
break; break;
*/
case PYBC_ROT_THREE: case PYBC_ROT_THREE:
obj1 = sp[0]; printf("ROT_THREE");
sp[0] = sp[1];
sp[1] = sp[2];
sp[2] = obj1;
break; break;
*/
case PYBC_JUMP: case PYBC_JUMP:
DECODE_SLABEL; DECODE_SLABEL;
...@@ -185,14 +173,12 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -185,14 +173,12 @@ void py_show_byte_code(const byte *ip, int len) {
printf("POP_JUMP_IF_TRUE %lu", ip + unum - ip_start); printf("POP_JUMP_IF_TRUE %lu", ip + unum - ip_start);
break; break;
/*
case PYBC_POP_JUMP_IF_FALSE: case PYBC_POP_JUMP_IF_FALSE:
DECODE_SLABEL; DECODE_SLABEL;
if (!rt_is_true(POP())) { printf("POP_JUMP_IF_FALSE %lu", ip + unum - ip_start);
ip += unum;
}
break; break;
/*
case PYBC_JUMP_IF_TRUE_OR_POP: case PYBC_JUMP_IF_TRUE_OR_POP:
DECODE_SLABEL; DECODE_SLABEL;
if (rt_is_true(*sp)) { if (rt_is_true(*sp)) {
...@@ -225,22 +211,18 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -225,22 +211,18 @@ void py_show_byte_code(const byte *ip, int len) {
// else error // else error
assert(0); assert(0);
break; break;
*/
case PYBC_GET_ITER: case PYBC_GET_ITER:
*sp = rt_getiter(*sp); printf("GET_ITER");
break; break;
case PYBC_FOR_ITER: case PYBC_FOR_ITER:
DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
obj1 = rt_iternext(*sp); printf("FOR_ITER %lu", ip + unum - ip_start);
if (obj1 == py_const_stop_iteration) {
++sp; // pop the exhausted iterator
ip += unum; // jump to after for-block
} else {
PUSH(obj1); // push the next iteration value
}
break; break;
/*
case PYBC_POP_BLOCK: case PYBC_POP_BLOCK:
// pops block and restores the stack // pops block and restores the stack
assert(0); assert(0);
...@@ -272,21 +254,17 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -272,21 +254,17 @@ void py_show_byte_code(const byte *ip, int len) {
printf("COMPARE_OP %lu", unum); printf("COMPARE_OP %lu", unum);
break; break;
/*
case PYBC_BUILD_TUPLE: case PYBC_BUILD_TUPLE:
DECODE_UINT; DECODE_UINT;
obj1 = rt_build_tuple(unum, sp); printf("BUILD_TUPLE %lu", unum);
sp += unum - 1;
*sp = obj1;
break; break;
case PYBC_BUILD_LIST: case PYBC_BUILD_LIST:
DECODE_UINT; DECODE_UINT;
obj1 = rt_build_list(unum, sp); printf("BUILD_LIST %lu", unum);
sp += unum - 1;
*sp = obj1;
break; break;
/*
case PYBC_LIST_APPEND: case PYBC_LIST_APPEND:
DECODE_UINT; DECODE_UINT;
// I think it's guaranteed by the compiler that sp[unum] is a list // I think it's guaranteed by the compiler that sp[unum] is a list
...@@ -326,6 +304,11 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -326,6 +304,11 @@ void py_show_byte_code(const byte *ip, int len) {
break; break;
*/ */
case PYBC_UNPACK_SEQUENCE:
DECODE_UINT;
printf("UNPACK_SEQUENCE %lu", unum);
break;
case PYBC_MAKE_FUNCTION: case PYBC_MAKE_FUNCTION:
DECODE_UINT; DECODE_UINT;
printf("MAKE_FUNCTION %lu", unum); printf("MAKE_FUNCTION %lu", unum);
...@@ -333,16 +316,12 @@ void py_show_byte_code(const byte *ip, int len) { ...@@ -333,16 +316,12 @@ void py_show_byte_code(const byte *ip, int len) {
case PYBC_CALL_FUNCTION: case PYBC_CALL_FUNCTION:
DECODE_UINT; DECODE_UINT;
assert((unum & 0xff00) == 0); // n_keyword printf("CALL_FUNCTION n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
unum &= 0xff; // n_positional
printf("CALL_FUNCTION %lu", unum);
break; break;
case PYBC_CALL_METHOD: case PYBC_CALL_METHOD:
DECODE_UINT; DECODE_UINT;
assert((unum & 0xff00) == 0); // n_keyword printf("CALL_METHOD n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
unum &= 0xff;
printf("CALL_METHOD %lu", unum);
break; break;
case PYBC_RETURN_VALUE: case PYBC_RETURN_VALUE:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment