浏览代码

added a function to check for errors without clearing them

Kolten Pearson 2 年之前
父节点
当前提交
3d8627410f
共有 4 个文件被更改,包括 15 次插入1 次删除
  1. 9 0
      c_bindings/pocketpy_c.cpp
  2. 3 0
      c_bindings/pocketpy_c.h
  3. 2 0
      c_bindings/test.c
  4. 1 1
      run_c_binding_test.sh

+ 9 - 0
c_bindings/pocketpy_c.cpp

@@ -504,6 +504,15 @@ bool pkpy_check_global(pkpy_vm* vm_handle, const char* name) {
     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) {
     CVM* vm = (CVM*) vm_handle;

+ 3 - 0
c_bindings/pocketpy_c.h

@@ -87,6 +87,9 @@ bool pkpy_is_none(pkpy_vm*, int index);
 //will return true if global exists
 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
 bool pkpy_check_stack(pkpy_vm*, int free);
 

+ 2 - 0
c_bindings/test.c

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

+ 1 - 1
run_c_binding_test.sh

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