Update obj.h

Update vm.h

Update vm.h
This commit is contained in:
blueloveTH 2022-12-01 20:09:19 +08:00
parent 8d152c225f
commit c3dc23dc64
3 changed files with 16 additions and 11 deletions

View File

@ -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);

View File

@ -112,6 +112,7 @@ int main(int argc, char** argv){
vm->execAsync(code);
_tvm_dispatch(vm);
});
pkpy_delete(vm);
return 0;
}

View File

@ -44,13 +44,13 @@
typedef void(*PrintFn)(const VM*, const char*);
class VM: public PkExportedResource{
std::atomic<bool> _stopFlag = false;
protected:
std::deque< std::unique_ptr<Frame> > callstack;
PyVarDict _modules; // loaded modules
std::map<_Str, _Code> _lazyModules; // lazy loaded modules
PyVar __py2py_call_signal;
std::atomic<bool> _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(){