From caadfefc017d5dc93154d78dbccbb86cbd34e4a1 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 4 Jun 2023 21:28:23 +0800 Subject: [PATCH] add `aFalse); // [False] frame->jump_abs(byte.arg); } else POP(); // [b] + DISPATCH(); TARGET(LOOP_CONTINUE) frame->jump_abs(co_blocks[byte.block].start); DISPATCH(); diff --git a/src/common.h b/src/common.h index 56aff1bd..dc5db29a 100644 --- a/src/common.h +++ b/src/common.h @@ -178,9 +178,9 @@ inline PyObject* const PY_OP_CALL = (PyObject*)0b100011; inline PyObject* const PY_OP_YIELD = (PyObject*)0b110011; #ifdef _WIN32 - char kPlatformSep = '\\'; + inline const char kPlatformSep = '\\'; #else - char kPlatformSep = '/'; + inline const char kPlatformSep = '/'; #endif } // namespace pkpy \ No newline at end of file diff --git a/src/expr.h b/src/expr.h index a654f77c..ceda17fc 100644 --- a/src/expr.h +++ b/src/expr.h @@ -716,13 +716,11 @@ struct BinaryExpr: Expr{ } void emit(CodeEmitContext* ctx) override { - + std::vector jmps; if(is_compare() && lhs->is_compare()){ // (a < b) < c - std::vector jmps; static_cast(lhs.get())->_emit_compare(ctx, jmps); // [b, RES] - for(int i: jmps) ctx->patch_jump(i); }else{ // (1 + 2) < c lhs->emit(ctx); @@ -759,6 +757,8 @@ struct BinaryExpr: Expr{ case TK("@"): ctx->emit(OP_BINARY_MATMUL, BC_NOARG, line); break; default: FATAL_ERROR(); } + + for(int i: jmps) ctx->patch_jump(i); } }; diff --git a/src/vm.h b/src/vm.h index afe81a59..604e7f30 100644 --- a/src/vm.h +++ b/src/vm.h @@ -1005,7 +1005,7 @@ inline Str VM::disassemble(CodeObject_ co){ std::vector jumpTargets; for(auto byte : co->codes){ - if(byte.op == OP_JUMP_ABSOLUTE || byte.op == OP_POP_JUMP_IF_FALSE){ + if(byte.op == OP_JUMP_ABSOLUTE || byte.op == OP_POP_JUMP_IF_FALSE || byte.op == OP_POP_JUMP_IF_FALSE || byte.op == OP_SHORTCUT_IF_FALSE_OR_POP){ jumpTargets.push_back(byte.arg); } } @@ -1027,11 +1027,12 @@ inline Str VM::disassemble(CodeObject_ co){ pointer = " "; } ss << pad(line, 8) << pointer << pad(std::to_string(i), 3); - ss << " " << pad(OP_NAMES[byte.op], 20) << " "; + ss << " " << pad(OP_NAMES[byte.op], 25) << " "; // ss << pad(byte.arg == -1 ? "" : std::to_string(byte.arg), 5); std::string argStr = _opcode_argstr(this, byte, co.get()); - ss << pad(argStr, 40); // may overflow - ss << co->blocks[byte.block].type; + ss << argStr; + // ss << pad(argStr, 40); // may overflow + // ss << co->blocks[byte.block].type; if(i != co->codes.size() - 1) ss << '\n'; } diff --git a/tests/31_cmp.py b/tests/31_cmp.py new file mode 100644 index 00000000..8a3a7649 --- /dev/null +++ b/tests/31_cmp.py @@ -0,0 +1,16 @@ +assert 1<2 +assert 1+1==2 +assert 2+1>=2 + +assert 1<2<3 +assert 1<2<3<4 +assert 1<2<3<4<5 + +assert 1<1+1<3 +assert 1<1+1<3<4 +assert 1<1+1<3<2+2<5 + +a = [1,2,3] +assert a[0] < a[1] < a[2] +assert a[0]+1 == a[1] < a[2] +assert a[0]+1 == a[1] < a[2]+1 < 5 \ No newline at end of file