mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
use error_stack
instead of try_error_code
This commit is contained in:
parent
d22f0d73ce
commit
20a01a0cca
3
port/linux/.vscode/launch.json
vendored
3
port/linux/.vscode/launch.json
vendored
@ -38,7 +38,8 @@
|
||||
// "--gtest_filter=except.isinstance"
|
||||
// "--gtest_filter=builtin.isinstance"
|
||||
// "--gtest_filter=bytes.bytes_split"
|
||||
"--gtest_filter=except.dict"
|
||||
// "--gtest_filter=except.dict"
|
||||
"--gtest_filter=except.for_loop"
|
||||
],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${workspaceFolder}",
|
||||
|
@ -114,7 +114,6 @@ typedef struct PikaVMError PikaVMError;
|
||||
struct PikaVMError {
|
||||
int8_t code;
|
||||
int8_t line_code;
|
||||
int8_t try_code;
|
||||
PikaVMError* next;
|
||||
};
|
||||
|
||||
|
42
src/PikaVM.c
42
src/PikaVM.c
@ -990,7 +990,7 @@ static Arg* VM_instruction_handler_EXP(PikaObj* self,
|
||||
PikaVMFrame* vm,
|
||||
char* data,
|
||||
Arg* arg_ret_reg) {
|
||||
vm->error.try_code = 0;
|
||||
pikaVMThread_clearErrorStack(vm->vm_thread);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1171,7 +1171,8 @@ static Arg* VM_instruction_handler_GER(PikaObj* self,
|
||||
PikaVMFrame* vm,
|
||||
char* data,
|
||||
Arg* arg_ret_reg) {
|
||||
PIKA_RES err = (PIKA_RES)vm->error.try_code;
|
||||
PikaVMThread* vm_thread = pikaVMThread_require();
|
||||
PIKA_RES err = pikaVMThread_checkErrorCode(vm_thread);
|
||||
Arg* err_arg = arg_newInt(err);
|
||||
return err_arg;
|
||||
}
|
||||
@ -2489,7 +2490,9 @@ static Arg* VM_instruction_handler_SER(PikaObj* self,
|
||||
PikaVMFrame* vm,
|
||||
char* data,
|
||||
Arg* arg_ret_reg) {
|
||||
vm->error.try_code = fast_atoi(data);
|
||||
PikaVMError error = {0};
|
||||
error.code = fast_atoi(data);
|
||||
pikaVMThread_pushError(vm->vm_thread, &error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -4537,7 +4540,7 @@ int PikaVMFrame_destroy(PikaVMFrame* vm) {
|
||||
}
|
||||
|
||||
int pikaVMError_isNone(PikaVMError* error) {
|
||||
return error->code == 0 && error->line_code == 0 && error->try_code == 0;
|
||||
return error->code == 0 && error->line_code == 0;
|
||||
}
|
||||
|
||||
int pikaVMFrame_checkErrorCode(PikaVMFrame* state) {
|
||||
@ -4545,6 +4548,29 @@ int pikaVMFrame_checkErrorCode(PikaVMFrame* state) {
|
||||
return state->error.code;
|
||||
}
|
||||
|
||||
int pikaVMThread_checkErrorCode(PikaVMThread* vmThread) {
|
||||
pika_assert(NULL != vmThread);
|
||||
if (NULL == vmThread->error_stack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if (state->in_del_call) {
|
||||
if (1) {
|
||||
if (0 != vmThread->error_stack->code) {
|
||||
return vmThread->error_stack->code;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (PikaVMError* current = vmThread->error_stack; current != NULL;
|
||||
current = current->next) {
|
||||
if (0 != current->code) {
|
||||
return current->code;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pikaVMThread_pushError(PikaVMThread* state, PikaVMError* error) {
|
||||
pika_assert(NULL != state);
|
||||
pika_assert(NULL != error);
|
||||
@ -4584,7 +4610,7 @@ PikaVMError* pikaVMThread_getErrorCurrent(PikaVMThread* state) {
|
||||
return state->error_stack;
|
||||
}
|
||||
|
||||
int pikaVMThread_clearError(PikaVMThread* state) {
|
||||
int pikaVMThread_clearErrorStack(PikaVMThread* state) {
|
||||
pika_assert(NULL != state);
|
||||
PikaVMError* current = state->error_stack;
|
||||
while (current != NULL) {
|
||||
@ -4651,9 +4677,9 @@ static VMParameters* __pikaVM_runByteCodeFrameWithState(
|
||||
}
|
||||
head_ins_unit--;
|
||||
}
|
||||
if (vm->vm_thread->try_state) {
|
||||
if (vm->vm_thread->try_state == TRY_STATE_INNER) {
|
||||
// Store the error code in the try state
|
||||
vm->error.try_code = vm->error.code;
|
||||
pikaVMThread_pushError(vm->vm_thread, &(vm->error));
|
||||
}
|
||||
/* print inses of a line */
|
||||
if (!vm->vm_thread->try_state) {
|
||||
@ -4783,7 +4809,7 @@ PikaVMThread* pikaVMThread_create(uint64_t thread_id) {
|
||||
}
|
||||
|
||||
void pikaVMThread_destroy(PikaVMThread* state) {
|
||||
pikaVMThread_clearError(state);
|
||||
pikaVMThread_clearErrorStack(state);
|
||||
if (state != NULL) {
|
||||
pikaFree(state, sizeof(PikaVMThread));
|
||||
}
|
||||
|
@ -326,8 +326,9 @@ void pikaVMThread_delete(void);
|
||||
int pikaVMThread_pushError(PikaVMThread* state, PikaVMError* error);
|
||||
PikaVMError* pikaVMThread_popError(PikaVMThread* state);
|
||||
int pikaVMError_isNone(PikaVMError* error);
|
||||
int pikaVMThread_clearError(PikaVMThread* state);
|
||||
int pikaVMThread_clearErrorStack(PikaVMThread* state);
|
||||
int pikaVMFrame_checkErrorCode(PikaVMFrame* state);
|
||||
int pikaVMThread_checkErrorCode(PikaVMThread* state);
|
||||
PikaVMError* pikaVMThread_getErrorCurrent(PikaVMThread* state);
|
||||
InstructUnit* instructArray_getNow(InstructArray* self);
|
||||
InstructUnit* instructArray_getNext(InstructArray* self);
|
||||
|
@ -2,4 +2,4 @@
|
||||
#define PIKA_VERSION_MINOR 13
|
||||
#define PIKA_VERSION_MICRO 3
|
||||
|
||||
#define PIKA_EDIT_TIME "2024/08/08 22:21:06"
|
||||
#define PIKA_EDIT_TIME "2024/08/08 22:29:41"
|
||||
|
Loading…
x
Reference in New Issue
Block a user