Explorar o código

add `py_resetallvm`

blueloveTH hai 8 meses
pai
achega
f9debd804e
Modificáronse 2 ficheiros con 10 adicións e 0 borrados
  1. 2 0
      include/pocketpy/pocketpy.h
  2. 8 0
      src/public/internal.c

+ 2 - 0
include/pocketpy/pocketpy.h

@@ -108,6 +108,8 @@ PK_API int py_currentvm();
 PK_API void py_switchvm(int index);
 PK_API void py_switchvm(int index);
 /// Reset the current VM.
 /// Reset the current VM.
 PK_API void py_resetvm();
 PK_API void py_resetvm();
+/// Reset All VMs.
+PK_API void py_resetallvm();
 /// Get the current VM context. This is used for user-defined data.
 /// Get the current VM context. This is used for user-defined data.
 PK_API void* py_getvmctx();
 PK_API void* py_getvmctx();
 /// Set the current VM context. This is used for user-defined data.
 /// Set the current VM context. This is used for user-defined data.

+ 8 - 0
src/public/internal.c

@@ -94,6 +94,14 @@ void py_resetvm() {
     VM__ctor(vm);
     VM__ctor(vm);
 }
 }
 
 
+void py_resetallvm() {
+    for(int i = 0; i < 16; i++) {
+        py_switchvm(i);
+        py_resetvm();
+    }
+    py_switchvm(0);
+}
+
 int py_currentvm() {
 int py_currentvm() {
     for(int i = 0; i < 16; i++) {
     for(int i = 0; i < 16; i++) {
         if(pk_all_vm[i] == pk_current_vm) return i;
         if(pk_all_vm[i] == pk_current_vm) return i;