added a function to check for errors without clearing them

This commit is contained in:
Kolten Pearson 2023-05-02 23:11:41 -06:00
parent cbe99e6089
commit 3d8627410f
4 changed files with 15 additions and 1 deletions

View File

@ -504,6 +504,15 @@ bool pkpy_check_global(pkpy_vm* vm_handle, const char* name) {
SAFEGUARD_CLOSE SAFEGUARD_CLOSE
} }
bool pkpy_check_error(pkpy_vm* vm_handle) {
CVM* vm = (CVM*) vm_handle;
SAFEGUARD_OPEN
if (vm->c_data->size() > 0 && vm->c_data->top() == nullptr)
return true;
return false;
SAFEGUARD_CLOSE
}
bool pkpy_check_stack(pkpy_vm* vm_handle, int free) { bool pkpy_check_stack(pkpy_vm* vm_handle, int free) {
CVM* vm = (CVM*) vm_handle; CVM* vm = (CVM*) vm_handle;

View File

@ -87,6 +87,9 @@ bool pkpy_is_none(pkpy_vm*, int index);
//will return true if global exists //will return true if global exists
bool pkpy_check_global(pkpy_vm*, const char* name); bool pkpy_check_global(pkpy_vm*, const char* name);
//will return true if the vm is currently in an error state
bool pkpy_check_error(pkpy_vm*);
//will return true if at least free empty slots remain on the stack //will return true if at least free empty slots remain on the stack
bool pkpy_check_stack(pkpy_vm*, int free); bool pkpy_check_stack(pkpy_vm*, int free);

View File

@ -293,6 +293,8 @@ int main(int argc, char** argv) {
check(pkpy_check_global(vm, "test_error_propagate")); check(pkpy_check_global(vm, "test_error_propagate"));
fail(pkpy_check_global(vm, "nonexistant")); fail(pkpy_check_global(vm, "nonexistant"));
pkpy_vm_run(vm, "test_error_propagate()");
check(pkpy_check_error(vm));
return 0; return 0;
} }

View File

@ -19,7 +19,7 @@ echo "checking results (they should be identical)"
diff -q -s binding_test_scratch c_bindings/test_answers.txt diff -q -s binding_test_scratch c_bindings/test_answers.txt
echo "cleaning up" echo "cleaning up"
#rm pocketpy_c.o rm pocketpy_c.o
rm test.o rm test.o
rm binding_test_scratch rm binding_test_scratch