mirror of
https://github.com/pocketpy/pocketpy
synced 2026-08-07 06:37:10 +08:00
add py_interrupt
This commit is contained in:
parent
af9dbb39d7
commit
e3255207c3
@ -12,6 +12,8 @@
|
||||
#include "pocketpy/interpreter/line_profiler.h"
|
||||
#include <time.h>
|
||||
|
||||
#include <stdatomic.h>
|
||||
|
||||
// TODO:
|
||||
// 1. __eq__ and __ne__ fallbacks
|
||||
// 2. un-cleared exception detection
|
||||
@ -51,6 +53,7 @@ typedef struct VM {
|
||||
|
||||
py_Callbacks callbacks;
|
||||
py_Capabilities capabilities;
|
||||
atomic_bool is_interrupted;
|
||||
|
||||
py_TValue last_retval;
|
||||
py_TValue unhandled_exc;
|
||||
|
||||
@ -124,6 +124,11 @@ __NEXT_STEP:
|
||||
}
|
||||
#endif
|
||||
|
||||
if(atomic_exchange(&self->is_interrupted, false)) {
|
||||
py_exception(tp_KeyboardInterrupt, "");
|
||||
goto __ERROR;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
pk_print_stack(self, frame, byte);
|
||||
#endif
|
||||
|
||||
@ -94,6 +94,7 @@ void VM__ctor(VM* self) {
|
||||
self->callbacks.getchr = pk_default_getchr;
|
||||
|
||||
memset(&self->capabilities, 0, sizeof(py_Capabilities));
|
||||
atomic_store(&self->is_interrupted, false);
|
||||
|
||||
self->last_retval = *py_NIL();
|
||||
self->unhandled_exc = *py_NIL();
|
||||
|
||||
@ -112,6 +112,8 @@ py_Callbacks* py_callbacks() { return &pk_current_vm->callbacks; }
|
||||
|
||||
py_Capabilities* py_capabilities() { return &pk_current_vm->capabilities; }
|
||||
|
||||
void py_interrupt() { atomic_store(&pk_current_vm->is_interrupted, true); }
|
||||
|
||||
py_AppCallbacks* py_appcallbacks() {
|
||||
static py_AppCallbacks _callbacks = {0};
|
||||
return &_callbacks;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user