2
0
SongZihuan 3 жил өмнө
parent
commit
a9b539144f

+ 22 - 22
src/core/env.c

@@ -777,7 +777,7 @@ static void mp_NORMAL(af_Message *msg, bool is_top, af_Environment *env) {
     }
     if (is_top)
         writeDebugLog(aFunCoreLogger, "NORMAL Point: %p", *(af_Object **)msg->msg);
-//    gc_delReference(*(af_Object **)msg->msg, env);
+    gc_delReference(*(af_Object **)msg->msg, env);
     *(af_Object **)msg->msg = NULL;
 }
 
@@ -792,7 +792,7 @@ static void mp_NORMALThread(af_Message *msg, bool is_top, af_Environment *env) {
 
     pthread_mutex_lock(&env->thread_lock);
     env->result = *(af_Object **)msg->msg;
-//    gc_delReference(env->result, env);
+    gc_delReference(env->result, env);
     *(af_Object **)msg->msg = NULL;
     pthread_mutex_unlock(&env->thread_lock);
 }
@@ -888,7 +888,7 @@ static af_GuardianList *guardian_Signal(char *type, bool is_guard, void *data, a
             af_Message *msg;
             if (EQ_STR("NORMAL", env->activity->msg_down->type)) {
                 msg = getFirstMessage(env);
-//                gc_delReference(*(af_Object **)msg->msg, env);
+                gc_delReference(*(af_Object **)msg->msg, env);
                 freeMessage(msg);
             } else if (EQ_STR("ERROR", env->activity->msg_down->type)) {
                 msg = getFirstMessage(env);
@@ -961,8 +961,8 @@ af_Environment *makeEnvironment(enum GcRunTime grt) {
     makeVarToProtectVarSpace(mg_sys_cycle, 3, 3, 3, cycle, env);
 
     gc_delReference(env->protect, env);
-//    gc_delReference(env->global, env);
-//    gc_delReference(cycle, env);
+    gc_delReference(env->global, env);
+    gc_delReference(cycle, env);
     return env;
 }
 
@@ -1237,12 +1237,12 @@ static bool isInfixFunc(af_Code *code, af_Environment *env) {
     af_Object *obj = findVarNode(var, NULL, env);
     obj_isInfixFunc *func = findAPI("obj_isInfixFunc", getObjectAPI(obj));
     if (func == NULL) {
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
         return false;
     }
 
     bool res = func(getObjectID(obj), obj);
-//    gc_delReference(obj, env);
+    gc_delReference(obj, env);
     return res;
 }
 
@@ -1401,8 +1401,8 @@ bool pushImportActivity(af_Code *bt, af_Object **obj, char *mark, af_Environment
 
     if (obj != NULL)
         *obj = tmp;
-//    else
-//        gc_delReference(tmp, env);
+    else
+        gc_delReference(tmp, env);
 
     return true;
 }
@@ -1686,14 +1686,14 @@ void popActivity(bool is_normal, af_Message *msg, af_Environment *env) {
     if (env->activity->type == act_func || env->activity->type == act_top || env->activity->type == act_top_import) {
         if (msg != NULL && env->activity->return_first) {  // msg有内容, 并且设定了返回首位, 则清除msg内容, 并压入首位(压入的代码在下面)
             if (EQ_STR(msg->type, "NORMAL")) {
-//                gc_delReference(*(af_Object **) msg->msg, env);
+                gc_delReference(*(af_Object **) msg->msg, env);
                 freeMessage(msg);
                 msg = NULL;
             }
         } else if (env->activity->return_first) {  // msg无内容, 并且设定了返回首位, 则检查msg_down是否有normal, 有则清除
             if (env->activity->msg_down != NULL && EQ_STR(env->activity->msg_down->type, "NORMAL")) {
                 af_Message *tmp = getFirstMessage(env);
-//                gc_delReference(*(af_Object **) (tmp->msg), env);
+                gc_delReference(*(af_Object **) (tmp->msg), env);
                 freeMessage(tmp);
             }
         }
@@ -1702,7 +1702,7 @@ void popActivity(bool is_normal, af_Message *msg, af_Environment *env) {
             if (env->activity->return_obj == NULL)
                 msg = makeERRORMessage(RUN_ERROR, RETURN_OBJ_NOT_FOUND_INFO, env);
             else {
-//                gc_addReference(env->activity->return_obj, env);
+                gc_addReference(env->activity->return_obj, env);
                 msg = makeNORMALMessage(env->activity->return_obj, env);
                 env->activity->return_obj = NULL;
             }
@@ -1715,7 +1715,7 @@ void popActivity(bool is_normal, af_Message *msg, af_Environment *env) {
     if (env->activity->type == act_top_import && /* import模式, 并且msg_down中有normal, 则把normal替换为belong */
         env->activity->msg_down != NULL && EQ_STR(env->activity->msg_down->type, "NORMAL")) {
         af_Message *tmp = getFirstMessage(env);
-//        gc_addReference(env->activity->belong, env);
+        gc_addReference(env->activity->belong, env);
         pushMessageDown(makeIMPORTMessage(env->activity->import_mark, env->activity->belong, env), env);  // 压入belong作为msg
         pushMessageDown(tmp, env);
     }
@@ -1856,8 +1856,8 @@ af_ErrorInfo *makeErrorInfo(char *type, char *error, char *note, FileLine line,
 void freeErrorInfo(af_ErrorInfo *ei, af_Environment *env){
     free(ei->error_type);
     free(ei->error);
-//    if (ei->obj != NULL)
-//        gc_delReference(ei->obj, env);
+    if (ei->obj != NULL)
+        gc_delReference(ei->obj, env);
     freeAllErrorBacktracking(ei->track);
     free(ei);
 }
@@ -2092,8 +2092,8 @@ af_ImportInfo *makeImportInfo(char *mark, af_Object *obj, af_Environment *env){
 
 void freeImportInfo(af_ImportInfo *ii, af_Environment *env){
     free(ii->mark);
-//    if (ii->obj != NULL)
-//        gc_delReference(ii->obj, env);
+    if (ii->obj != NULL)
+        gc_delReference(ii->obj, env);
     free(ii);
 }
 
@@ -2114,9 +2114,9 @@ static af_GuardianList *makeGuardianList(af_Object *obj, af_Object *func, af_Env
 
 static af_GuardianList *freeGuardianList(af_GuardianList *gl, af_Environment *env){
     af_GuardianList *next = gl->next;
-//    if (gl->obj != NULL)
-//        gc_delReference(gl->obj, env);
-//    gc_delReference(gl->func, env);
+    if (gl->obj != NULL)
+        gc_delReference(gl->obj, env);
+    gc_delReference(gl->func, env);
     free(gl);
     return next;
 }
@@ -2205,12 +2205,12 @@ af_Object *getGlobal(af_Environment *env) {
     af_Activity *activity = env->activity;
     for (NULL; activity != NULL; activity = activity->prev) {
         if (activity->type == act_top || activity->type == act_top_import) {
-//            gc_addReference(activity->belong, env);
+            gc_addReference(activity->belong, env);
             return activity->belong;
         }
     }
 
-//    gc_addReference(env->global, env);
+    gc_addReference(env->global, env);
     return env->global;
 }
 

+ 5 - 5
src/core/func.c

@@ -21,8 +21,8 @@ static af_ArgCodeList *freeArgCodeList(af_ArgCodeList *acl, af_Environment *env)
     free(acl->info);
     if (acl->free_code)
         freeAllCode(acl->code);
-//    if (acl->result != NULL)
-//        gc_delReference(acl->result, env);
+    if (acl->result != NULL)
+        gc_delReference(acl->result, env);
     free(acl);
     return next;
 }
@@ -60,8 +60,8 @@ af_ArgList *makeArgList(char *name, af_Object *obj, af_Environment *env){
 static af_ArgList *freeArgList(af_ArgList *al, af_Environment *env){
     af_ArgList *next = al->next;
     free(al->name);
-//    if (al->obj != NULL)
-//        gc_delReference(al->obj, env);
+    if (al->obj != NULL)
+        gc_delReference(al->obj, env);
     free(al);
     return next;
 }
@@ -90,7 +90,7 @@ af_ArgList **pushArgList(af_ArgList **base, af_ArgList *new) {
  */
 af_ArgList *makeArgListFromArgCodeList(char *name, af_ArgCodeList *acl, af_Environment *env) {
     af_Object *obj = getArgCodeListResult(acl);
-//    gc_addReference(obj, env);
+    gc_addReference(obj, env);
 
     af_ArgList *al = makeArgList(name, obj, env);
     return al;

+ 2 - 2
src/core/gc.c

@@ -539,7 +539,7 @@ static pgc_Analyzed checkDestruct(af_Environment *env, paf_GuardianList *pgl, pg
             pthread_rwlock_rdlock(&od->lock);
             af_Object *base = od->base;
             pthread_rwlock_unlock(&od->lock);
-//            gc_addReference(base, env);
+            gc_addReference(base, env);
 
             *pgl = pushGuardianList(base, func, *pgl, env);
             plist = reachableObjectData(od, plist);
@@ -598,7 +598,7 @@ paf_GuardianList checkAllDestruct(af_Environment *env, paf_GuardianList pgl) {
             pthread_rwlock_rdlock(&od->lock);
             af_Object *base_obj = od->base;
             pthread_rwlock_unlock(&od->lock);
-//            gc_addReference(base_obj, env);
+            gc_addReference(base_obj, env);
             pgl = pushGuardianList(base_obj, func, pgl, env);
         }
     }

+ 8 - 8
src/core/run.c

@@ -50,7 +50,7 @@ static bool checkLiteral(af_Message **msg, af_Environment *env) {
     af_Object *obj = *(af_Object **)((*msg)->msg);
     obj_literalSetting *func = findAPI("obj_literalSetting", getObjectAPI(obj));
     if (func == NULL) {
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
         freeMessage(*msg);
         *msg = makeERRORMessage(TYPE_ERROR, API_NOT_FOUND_INFO(obj_literalSetting), env);
         return false;
@@ -82,7 +82,7 @@ static int checkMacro(af_Message *msg, af_Environment *env) {
 
     af_Object *obj = *(af_Object **)(msg->msg);
     bool re = pushMacroFuncActivity(obj, env);
-//    gc_delReference(obj, env);
+    gc_delReference(obj, env);
     freeMessage(msg);
     if (re)
         return 1;
@@ -177,7 +177,7 @@ static bool codeElement(af_Code *code, af_Environment *env) {
         af_Object *obj = findVarNode(var, NULL, env);
         writeTrackLog(aFunCoreLogger, "Get literal %s : %p", code->element.data, obj);
         bool res = pushLiteralActivity(code, code->element.data, obj, env);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
         return res;
     }
 
@@ -198,13 +198,13 @@ static bool codeElement(af_Code *code, af_Environment *env) {
         char *id = getObjectID(obj);
         if ((is_obj = findAPI("obj_isObjFunc", api)) != NULL && is_obj(id, obj)) {
             bool res = pushVariableActivity(code, obj, env);  // 对象函数
-//            gc_delReference(obj, env);
+            gc_delReference(obj, env);
             return res;
         } else if (env->activity->status != act_func_get && // 在act_func_get 模式下不检查是否为is_infix函数 因为本来就要将其作为函数调用
                  (is_infix = findAPI("obj_isInfixFunc", api)) != NULL && is_infix(id, obj)) {
             pushMessageDown(makeERRORMessageFormat(INFIX_PROTECT, env,
                                                    "Infix protect variable: %s.", code->element.data), env);
-//            gc_delReference(obj, env);
+            gc_delReference(obj, env);
             return false;
         }
     }
@@ -313,7 +313,7 @@ bool checkNormalEnd(af_Message *msg, af_Environment *env) {
             pushMessageDown(msg, env);
             return true;
         } else if (msg != NULL) {
-//            gc_delReference(*(af_Object **) (msg->msg), env);  // msg->msg是一个指针, 这个指针的内容是一个af_Object *
+            gc_delReference(*(af_Object **) (msg->msg), env);  // msg->msg是一个指针, 这个指针的内容是一个af_Object *
             freeMessage(msg);
         }
     } else if (msg != NULL) {
@@ -323,7 +323,7 @@ bool checkNormalEnd(af_Message *msg, af_Environment *env) {
             env->activity->parentheses_call = *(af_Object **) (msg->msg);  // 类前缀调用
             pthread_mutex_unlock(env->activity->gc_lock);
         }
-//        gc_delReference(*(af_Object **)(msg->msg), env);  // msg->msg是一个指针, 这个指针的内容是一个af_Object *
+        gc_delReference(*(af_Object **)(msg->msg), env);  // msg->msg是一个指针, 这个指针的内容是一个af_Object *
         freeMessage(msg);
     }
     return false;
@@ -491,7 +491,7 @@ bool iterCode(af_Code *code, int mode, af_Environment *env){
                 af_Object *func = *(af_Object **) (msg->msg);  // func仍保留了msg的gc计数
                 if (!setFuncActivityToArg(func, env))
                     popActivity(false, NULL, env);
-//                gc_delReference(func, env);  // 释放计数 (setFuncActivityToArg 不需要计数)
+                gc_delReference(func, env);  // 释放计数 (setFuncActivityToArg 不需要计数)
                 freeMessage(msg);
                 break;
             }

+ 1 - 1
src/core/thread.c

@@ -26,7 +26,7 @@ af_Environment *startRunThread(af_Environment *env, af_VarSpace *vs, af_Code *co
     if (vs == NULL) {
         af_Object *obj = getGlobal(env);
         vs = makeVarSpace(obj, 3, 3, 3, env);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     new->activity->run_varlist = pushVarList(vs, new->activity->run_varlist);

+ 1 - 1
src/core/var.c

@@ -106,7 +106,7 @@ af_Object *findVarNode(af_Var *var, char *id, af_Environment *env){
     af_Object *obj = NULL;
     if (vn != NULL) {
         obj = vn->obj;
-//        gc_addReference(obj, env);
+        gc_addReference(obj, env);
     }
     pthread_rwlock_unlock(&var->lock);
     return obj;

+ 2 - 2
src/runtime/runtime.c

@@ -83,8 +83,8 @@ void makeObjectFromList(const ObjectDefineList obj_def[], af_Object *visitor, af
 
         if (od->save != NULL)
             *(od->save) = obj;
-//        else
-//            gc_delReference(obj, env);
+        else
+            gc_delReference(obj, env);
     }
 }
 

+ 3 - 3
src/tool/log.c

@@ -266,13 +266,13 @@ static void writeLogToFactory_(LogLevel level, char *id, pid_t tid, char *ti, ti
  * @param info 日志内容
  */
 static void writeLogToConsole_(LogLevel level, char *id, pid_t tid, char *ti, time_t t, char *file, int line, char *func, char *info) {
-#define FORMAT_SHORT "\r* %s[%d] %ld (%s:%d) : %s \n"  // 显示到终端, 添加\r回车符确保顶行显示
+#define FORMAT_SHORT "\r* %s[%d] %s %ld (%s:%d) : %s \n"  // 显示到终端, 添加\r回车符确保顶行显示
 #define STD_BUF_SIZE (STR_LEN(info) + 1024)
     if (level < log_warning) {
-        printf_stdout(STD_BUF_SIZE, FORMAT_SHORT, LogLevelNameLong[level], tid, t, file, line, info);
+        printf_stdout(STD_BUF_SIZE, FORMAT_SHORT, LogLevelNameLong[level], tid, ti, t, file, line, info);
         fflush(stdout);
     } else {
-        printf_stderr(STD_BUF_SIZE, FORMAT_SHORT, LogLevelNameLong[level], tid, t, file, line, info);
+        printf_stderr(STD_BUF_SIZE, FORMAT_SHORT, LogLevelNameLong[level], tid, ti, t, file, line, info);
         fflush(stderr);
     }
 #undef FORMAT_SHORT

+ 15 - 15
test/src/run_code.c

@@ -291,7 +291,7 @@ af_FuncBody *testFunc_GcDestruct_a(af_CallFuncInfo *cfi, af_Environment *env) {
     setObjectAttributes(mg_gc_destruct, 3, 3, 3, des, obj, obj, env);
     pushMessageDown(makeNORMALMessage(obj, env), env);
     printf("testFunc_GcDestruct_a[des](%p, %p): I am testFunc_GcDestruct_a\n", obj, des);
-//    gc_delReference(des, env);  // obj不需要 delReference, 因为他存在于NORMAL_Message中
+    gc_delReference(des, env);  // obj不需要 delReference, 因为他存在于NORMAL_Message中
     return NULL;
 }
 
@@ -345,7 +345,7 @@ af_FuncBody *testFunc_Gc(af_CallFuncInfo *cfi, af_Environment *env) {  // 测试
     setObjectAttributes(mg_gc_destruct, 3, 3, 3, des, obj, obj, env);
     pushMessageDown(makeNORMALMessage(obj, env), env);
     printf("testFunc_Gc(%p, %p): I am testFunc_Gc\n", obj, des);
-//    gc_delReference(des, env);
+    gc_delReference(des, env);
     return NULL;
 }
 
@@ -387,14 +387,14 @@ af_GuardianList *gd_func(char *type, bool is_guard, struct GDData *data, af_Envi
 
     af_GuardianList *gd = NULL;
     data->no_first = true;
-//    gc_addReference(data->func, env);  // data->func 本身有一次gc引用, 此次再使用一次gc引用, gd_destruct和freeGuardianList时各释放一次
+    gc_addReference(data->func, env);  // data->func 本身有一次gc引用, 此次再使用一次gc引用, gd_destruct和freeGuardianList时各释放一次
 
     pushGuardianList(NULL, data->func, &gd, env);
     return gd;
 }
 
 void gd_destruct(char *type, struct GDData *data, af_Environment *env) {
-//    gc_delReference(data->func, env);
+    gc_delReference(data->func, env);
 }
 
 int main(int argc, char **argv) {
@@ -459,7 +459,7 @@ INIT_ERROR:
         FREE_SYMBOL(getShareVS_);
         FREE_SYMBOL(get_gl3);
         printf("object(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     af_Object *af_func = NULL;
@@ -507,7 +507,7 @@ INIT_ERROR:
         FREE_SYMBOL(initData_2);
         FREE_SYMBOL(freeData_2);
         af_func = obj;
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
         printf("func-normal(%p)\n", obj);
     }
 
@@ -554,7 +554,7 @@ INIT_ERROR:
         FREE_SYMBOL(initData_2);
         FREE_SYMBOL(freeData_2);
         printf("macro(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     {
@@ -600,7 +600,7 @@ INIT_ERROR:
         FREE_SYMBOL(initData_2);
         FREE_SYMBOL(freeData_2);
         printf("func-tail(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     {
@@ -650,7 +650,7 @@ INIT_ERROR:
         FREE_SYMBOL(initData_2);
         FREE_SYMBOL(freeData_2);
         printf("func-obj(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     {
@@ -696,7 +696,7 @@ INIT_ERROR:
         FREE_SYMBOL(initData_2);
         FREE_SYMBOL(freeData_2);
         printf("func-gc(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     {
@@ -742,7 +742,7 @@ INIT_ERROR:
         FREE_SYMBOL(initData_2);
         FREE_SYMBOL(freeData_2);
         printf("func-body-dynamic(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     {
@@ -792,7 +792,7 @@ INIT_ERROR:
         FREE_SYMBOL(freeData_2);
         FREE_SYMBOL(infix_func);
         printf("func-brackets(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     {
@@ -838,7 +838,7 @@ INIT_ERROR:
         FREE_SYMBOL(initData_2);
         FREE_SYMBOL(freeData_2);
         printf("func-no-var(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     {
@@ -884,13 +884,13 @@ INIT_ERROR:
         FREE_SYMBOL(initData_2);
         FREE_SYMBOL(freeData_2);
         printf("func-import(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
 
     {
         af_Object *obj = getGlobal(env);
         printf("global(%p)\n", obj);
-//        gc_delReference(obj, env);
+        gc_delReference(obj, env);
     }
     printf("\n");
     sleep(2);