diff --git a/src/obj.h b/src/obj.h index da3f4e69..01e6d581 100644 --- a/src/obj.h +++ b/src/obj.h @@ -5,12 +5,7 @@ typedef int64_t _Int; typedef double _Float; -const _Int _Int_MAX_POS = 9223372036854775807LL; -const _Int _Int_MAX_NEG = -9223372036854775807LL; -const _Float _FLOAT_INF_POS = INFINITY; -const _Float _FLOAT_INF_NEG = -INFINITY; - -#define PK_VERSION "0.3.7" +#define PK_VERSION "0.3.8" class CodeObject; class BasePointer; diff --git a/src/pocketpy.h b/src/pocketpy.h index 38ea2b37..9eed130c 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -253,8 +253,8 @@ void __initializeBuiltinFunctions(VM* _vm) { if (args[0]->isType(vm->_tp_bool)) return vm->PyFloat(vm->PyBool_AS_C(args[0]) ? 1.0 : 0.0); if (args[0]->isType(vm->_tp_str)) { const _Str& s = vm->PyStr_AS_C(args[0]); - if(s == "inf") return vm->PyFloat(_FLOAT_INF_POS); - if(s == "-inf") return vm->PyFloat(_FLOAT_INF_NEG); + if(s == "inf") return vm->PyFloat(INFINITY); + if(s == "-inf") return vm->PyFloat(-INFINITY); try{ _Float val = std::stod(s.str()); return vm->PyFloat(val); @@ -771,4 +771,9 @@ extern "C" { void pkpy_tvm_resume(ThreadedVM* vm, const char* value){ vm->resume(value); } + + __EXPORT + void pkpy_vm_keyboard_interrupt(VM* vm){ + vm->keyboardInterrupt(); + } } \ No newline at end of file diff --git a/src/vm.h b/src/vm.h index 33cd9cbc..2c8483fe 100644 --- a/src/vm.h +++ b/src/vm.h @@ -51,17 +51,16 @@ protected: PyVar __py2py_call_signal; bool _stopFlag = false; - void emitKeyboardInterrupt(){ - _stopFlag = true; + void _checkStopFlag(){ + if(_stopFlag){ + _stopFlag = false; + _error("KeyboardInterrupt", ""); + } } PyVar runFrame(Frame* frame){ while(!frame->isCodeEnd()){ - if(_stopFlag){ - _stopFlag = false; - _error("KeyboardInterrupt", ""); - } - + _checkStopFlag(); const ByteCode& byte = frame->readCode(); //printf("%s (%d) stack_size: %d\n", OP_NAMES[byte.op], byte.arg, frame->stackSize()); @@ -409,6 +408,10 @@ public: initializeBuiltinClasses(); } + void keyboardInterrupt(){ + _stopFlag = true; + } + PyVar asStr(const PyVar& obj){ PyVarOrNull str_fn = getAttr(obj, __str__, false); if(str_fn != nullptr) return call(str_fn, {}); @@ -1104,7 +1107,7 @@ class ThreadedVM : public VM { void __deleteThread(){ if(_thread != nullptr){ - emitKeyboardInterrupt(); + keyboardInterrupt(); _thread->join(); delete _thread; _thread = nullptr; @@ -1134,7 +1137,7 @@ public: _state = THREAD_SUSPENDED; // 50 fps is enough while(_state == THREAD_SUSPENDED){ - if(_stopFlag) break; + _checkStopFlag(); std::this_thread::sleep_for(std::chrono::milliseconds(20)); } }