diff --git a/src/error.h b/src/error.h index 6a26c630..2ac58fcc 100644 --- a/src/error.h +++ b/src/error.h @@ -22,8 +22,7 @@ struct SourceMetadata { _Str getLine(int lineno) const { if(lineno == -1) return ""; - lineno -= 1; - const char* _start = lineStarts.at(lineno < 0 ? 0 : lineno); + const char* _start = lineStarts.at(lineno-1); const char* i = _start; while(*i != '\n' && *i != '\0') i++; return _Str(_start, i-_start); diff --git a/src/main.cpp b/src/main.cpp index 107ad882..1c3a008d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,6 +112,7 @@ int main(int argc, char** argv){ vm->execAsync(code); _tvm_dispatch(vm); }); + pkpy_delete(vm); return 0; } diff --git a/src/vm.h b/src/vm.h index bef0ba4d..e534e74b 100644 --- a/src/vm.h +++ b/src/vm.h @@ -44,13 +44,13 @@ typedef void(*PrintFn)(const VM*, const char*); class VM: public PkExportedResource{ + std::atomic _stopFlag = false; protected: std::deque< std::unique_ptr > callstack; PyVarDict _modules; // loaded modules std::map<_Str, _Code> _lazyModules; // lazy loaded modules PyVar __py2py_call_signal; - std::atomic _stopFlag = false; - + void _checkStopFlag(){ if(_stopFlag){ _stopFlag = false; @@ -60,10 +60,11 @@ protected: PyVar runFrame(Frame* frame){ while(!frame->isCodeEnd()){ - _checkStopFlag(); const ByteCode& byte = frame->readCode(); //printf("%s (%d) stack_size: %d\n", OP_NAMES[byte.op], byte.arg, frame->stackSize()); + _checkStopFlag(); + switch (byte.op) { case OP_NO_OP: break; // do nothing @@ -1114,7 +1115,10 @@ class ThreadedVM : public VM { void __deleteThread(){ if(_thread != nullptr){ - if(_state == THREAD_RUNNING || _state == THREAD_SUSPENDED) keyboardInterrupt(); + if(_state == THREAD_RUNNING || _state == THREAD_SUSPENDED) { + keyboardInterrupt(); + while(_state != THREAD_FINISHED); + } _thread->join(); delete _thread; _thread = nullptr; @@ -1183,11 +1187,12 @@ public: PyVarOrNull exec(const _Code& code, PyVar _module = nullptr) override { if(_state == THREAD_READY) return VM::exec(code, _module); - auto callstackBackup = std::move(callstack); - callstack.clear(); - PyVarOrNull ret = VM::exec(code, _module); - callstack = std::move(callstackBackup); - return ret; + UNREACHABLE(); + // auto callstackBackup = std::move(callstack); + // callstack.clear(); + // PyVarOrNull ret = VM::exec(code, _module); + // callstack = std::move(callstackBackup); + // return ret; } void resetState(){