From 37453a85024d7c12849e5f7bc315688a1f3afd7d Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 16 Mar 2024 14:40:01 +0800 Subject: [PATCH] some fix --- include/pocketpy/frame.h | 11 +++++------ src/ceval.cpp | 2 +- src/compiler.cpp | 10 ++++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/pocketpy/frame.h b/include/pocketpy/frame.h index b11eeb60..564fbf29 100644 --- a/include/pocketpy/frame.h +++ b/include/pocketpy/frame.h @@ -77,8 +77,8 @@ struct ValueStackImpl { using ValueStack = ValueStackImpl; struct Frame { - int _ip = -1; - int _next_ip = 0; + int _ip; + int _next_ip; ValueStack* _s; // This is for unwinding only, use `actual_sp_base()` for value stack access PyObject** _sp_base; @@ -89,17 +89,16 @@ struct Frame { FastLocals _locals; NameDict& f_globals() noexcept { return _module->attr(); } - PyObject* f_closure_try_get(StrName name); Frame(ValueStack* _s, PyObject** p0, const CodeObject* co, PyObject* _module, PyObject* _callable) - : _s(_s), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(co, p0) { } + : _ip(-1), _next_ip(0), _s(_s), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(co, p0) { } Frame(ValueStack* _s, PyObject** p0, const CodeObject* co, PyObject* _module, PyObject* _callable, FastLocals _locals) - : _s(_s), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(_locals) { } + : _ip(-1), _next_ip(0), _s(_s), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(_locals) { } Frame(ValueStack* _s, PyObject** p0, const CodeObject_& co, PyObject* _module) - : _s(_s), _sp_base(p0), co(co.get()), _module(_module), _callable(nullptr), _locals(co.get(), p0) {} + : _ip(-1), _next_ip(0), _s(_s), _sp_base(p0), co(co.get()), _module(_module), _callable(nullptr), _locals(co.get(), p0) {} Bytecode next_bytecode() { _ip = _next_ip++; diff --git a/src/ceval.cpp b/src/ceval.cpp index 9776df50..9fc59fa4 100644 --- a/src/ceval.cpp +++ b/src/ceval.cpp @@ -512,7 +512,7 @@ __NEXT_STEP:; frame->jump_abs(byte.arg); DISPATCH(); TARGET(JUMP_ABSOLUTE_TOP) - frame->jump_abs(_CAST(uint16_t, POPX())); + frame->jump_abs(_CAST(int, POPX())); DISPATCH(); TARGET(POP_JUMP_IF_FALSE){ if(!py_bool(TOP())) frame->jump_abs(byte.arg); diff --git a/src/compiler.cpp b/src/compiler.cpp index 135a47ca..1fff3aed 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -43,10 +43,10 @@ namespace pkpy{ if(ctx()->co->varnames.size() > PK_MAX_CO_VARNAMES){ SyntaxError("maximum number of local variables exceeded"); } - if(ctx()->co->consts.size() > 65535){ + if(ctx()->co->consts.size() > 65530){ SyntaxError("maximum number of constants exceeded"); } - if(codes.size() > 65535 && ctx()->co->src->mode != JSON_MODE){ + if(codes.size() > 65530 && ctx()->co->src->mode != JSON_MODE){ // json mode does not contain jump instructions, so it is safe to ignore this check SyntaxError("maximum number of opcodes exceeded"); } @@ -718,7 +718,8 @@ __EAT_DOTS_END: } // no match, re-raise if(finally_entry != -1){ - ctx()->emit_(OP_LOAD_INTEGER, (uint16_t)ctx()->co->codes.size()+2, BC_KEEPLINE); + i64 target = ctx()->co->codes.size()+2; + ctx()->emit_(OP_LOAD_CONST, ctx()->add_const(VAR(target)), BC_KEEPLINE); ctx()->emit_(OP_JUMP_ABSOLUTE, finally_entry, BC_KEEPLINE); } ctx()->emit_(OP_RE_RAISE, BC_NOARG, BC_KEEPLINE); @@ -726,7 +727,8 @@ __EAT_DOTS_END: // no exception or no match, jump to the end for (int patch : patches) ctx()->patch_jump(patch); if(finally_entry != -1){ - ctx()->emit_(OP_LOAD_INTEGER, (uint16_t)ctx()->co->codes.size()+2, BC_KEEPLINE); + i64 target = ctx()->co->codes.size()+2; + ctx()->emit_(OP_LOAD_CONST, ctx()->add_const(VAR(target)), BC_KEEPLINE); ctx()->emit_(OP_JUMP_ABSOLUTE, finally_entry, BC_KEEPLINE); } }