Эх сурвалжийг харах

feat: 调整了gc启动的机制

SongZihuan 4 жил өмнө
parent
commit
312aea43ff

+ 2 - 0
.gitignore

@@ -233,3 +233,5 @@ vgcore.*
 .vs
 /bin*
 /lib*
+gmon.out
+profile.txt

+ 3 - 3
CMakeLists.txt

@@ -15,16 +15,16 @@ SET(HELLOVM_INCLUDE_DICT
         ${CMAKE_CURRENT_SOURCE_DIR}/vmcore/include
         )
 
-IF (${SET_DEBUG})
+IF (SET_DEBUG)
     ADD_DEFINITIONS(-DDEBUG=1)
 ELSE()
     ADD_DEFINITIONS(-DDEBUG=0)
 ENDIF()
 
-IF (${GC})
+IF (GC)
     ADD_DEFINITIONS(-DSTART_GC=1)
 ELSE()
-    ADD_DEFINITIONS(-DSTART_GC=0)
+    ADD_DEFINITIONS(-DSTART_GC=0)  # TODO-szh 处理不启动gc
 ENDIF()
 
 ADD_DEFINITIONS(-DCC=\"${CMAKE_C_COMPILER}\")

+ 2 - 0
vmcore/CMakeLists.txt

@@ -52,6 +52,8 @@ ELSE()
     MESSAGE(FATAL_ERROR "not found libdl")
 ENDIF()
 
+ADD_COMPILE_OPTIONS(-pg)
+ADD_LINK_OPTIONS(-pg)
 ADD_LIBRARY(vmcore SHARED ${SRC})
 TARGET_LINK_LIBRARIES(vmcore ${libffi} ${libdl} m)
 TARGET_INCLUDE_DIRECTORIES(vmcore PRIVATE VMCORE_INCLUDE_DICT)

+ 1 - 0
vmcore/include/__macro.h

@@ -2,6 +2,7 @@
 #define VIRTUALMATH___MACRO_H
 #include "macro.h"
 
+
 // PASS语句的定义
 #define PASS
 

+ 8 - 8
vmcore/include/gc.h

@@ -38,14 +38,14 @@ void gc_runDelAll(struct Inter *inter);
 void gc_freeze(struct Inter *inter, struct VarList *freeze, struct VarList *base, bool is_lock);
 void gc_run(struct Inter *inter, struct VarList *run_var, int var_list, int link_value, int value, ...);
 #else
-#define gc_freeze(...)
-#define gc_run(...)
-#define setGC(...)
-#define gc_addTmpLink(...)
-#define gc_addStatementLink(...)
-#define gc_freeTmpLink(...)
-#define gc_freeStatementLink(...)
-#define gc_runDelAll(...)
+#define gc_freeze(...) ((void)0)
+#define gc_run(...) ((void)0)
+#define setGC(...) ((void)0)
+#define gc_addTmpLink(...) ((void)0)
+#define gc_addStatementLink(...) ((void)0)
+#define gc_freeTmpLink(...) ((void)0)
+#define gc_freeStatementLink(...) ((void)0)
+#define gc_runDelAll(...) ((void)0)
 #endif
 
 #endif //VIRTUALMATH_GC_H

+ 6 - 6
vmcore/include/macro.h

@@ -22,9 +22,7 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <dlfcn.h>
-#include "ffi.h"
-
-
+#include <ffi.h>
 
 // 布尔逻辑的定义
 #define bool int
@@ -35,12 +33,14 @@
 
 #ifdef NDEBUG
 #define errasert(e) ((void)0)
-#elifdef __assert_fail
+#else
+#ifdef __assert_fail
 #define errasert(e) __assert_fail(#e, __FILE__, __LINE__, __ASSERT_FUNCTION)
-#elifdef _assert
+#elif defined(_assert)
 #define errasert(e) _assert(#e, __FILE__, __LINE__)
 #else
 #define errasert(e) fprintf(stderr, "%s %s %s %s\n", #e, __FILE__, __LINE__)
 #endif
+#endif
 
-#endif //VIRTUALMATH_MACRO_H
+#endif //VIRTUALMATH_MACRO_H

+ 16 - 1
vmcore/src/run.c

@@ -9,6 +9,7 @@
  */
 ResultType runStatement(FUNC) {
     ResultType type = R_not;
+    bool run_gc = st->next == NULL;  // 若st已经没有下一部了则执行gc
     setResultCore(result);
     gc_addTmpLink(&belong->gc_status);
 
@@ -33,33 +34,43 @@ ResultType runStatement(FUNC) {
             break;
         case operation:
             type = operationStatement(CNEXT);
+            run_gc = true;
             break;
         case set_class:
             type = setClass(CNEXT);
+            run_gc = true;
             break;
         case set_function:
             type = setFunction(CNEXT);
+            run_gc = true;
             break;
         case slice_:
             type = elementSlice(CNEXT);
+            run_gc = true;
             break;
         case call_function:
             type = callBack(CNEXT);
+            run_gc = true;
             break;
         case if_branch:
             type = ifBranch(CNEXT);
+            run_gc = true;
             break;
         case while_branch:
             type = whileBranch(CNEXT);
+            run_gc = true;
             break;
         case for_branch:
             type = forBranch(CNEXT);
+            run_gc = true;
             break;
         case with_branch:
             type = withBranch(CNEXT);
+            run_gc = true;
             break;
         case try_branch:
             type = tryBranch(CNEXT);
+            run_gc = true;
             break;
         case break_cycle:
             type = breakCycle(CNEXT);
@@ -84,12 +95,15 @@ ResultType runStatement(FUNC) {
             break;
         case include_file:
             type = includeFile(CNEXT);
+            run_gc = true;
             break;
         case import_file:
             type = importFile(CNEXT);
+            run_gc = true;
             break;
         case from_import_file:
             type = fromImportFile(CNEXT);
+            run_gc = true;
             break;
         case default_var:
             type = setDefault(CNEXT);
@@ -113,7 +127,8 @@ ResultType runStatement(FUNC) {
     result->node = st;
     gc_freeTmpLink(&belong->gc_status);
 #if START_GC
-    gc_run(inter, var_list, 1, 2, 0, var_list, belong, result->value);
+    if (run_gc)
+        gc_run(inter, var_list, 1, 2, 0, var_list, belong, result->value);
 #endif
     return type;
 }