소스 검색

refactor: 为makeObject添加了gc_tmpLink

SongZihuan 4 년 전
부모
커밋
85d447712b
10개의 변경된 파일22개의 추가작업 그리고 8개의 파일을 삭제
  1. 1 0
      vmcore/include/macro.h
  2. 1 1
      vmcore/include/statement.h
  3. 6 3
      vmcore/ofunc/src/__ofunc.c
  4. 1 0
      vmcore/ofunc/src/function.c
  5. 2 0
      vmcore/ofunc/src/object.c
  6. 3 1
      vmcore/src/__run.c
  7. 1 1
      vmcore/src/run.c
  8. 1 0
      vmcore/src/runcall.c
  9. 4 1
      vmcore/src/runfile.c
  10. 2 1
      vmcore/src/value.c

+ 1 - 0
vmcore/include/macro.h

@@ -24,6 +24,7 @@
 #include "ffi.h"
 
 
+
 // 布尔逻辑的定义
 #define bool int
 #define true 1

+ 1 - 1
vmcore/include/statement.h

@@ -86,7 +86,7 @@ struct Statement{
                 OPT_ASS = 5,
                 OPT_POINT = 6,  // 成员运算
                 OPT_BLOCK = 7,  // 代码块
-                OPT_OUTPOINT = 8,  // 获取外部成员 TODO-szh 该名为OUTPOINT
+                OPT_OUTPOINT = 8,  // 获取外部成员
                 OPT_INTDIV = 9,
                 OPT_MOD = 10,
                 OPT_POW = 11,

+ 6 - 3
vmcore/ofunc/src/__ofunc.c

@@ -66,8 +66,9 @@ void iterBaseClassFunc(NameFunc *list, LinkValue *belong, FUNC_CORE){
 }
 
 LinkValue *makeBaseChildClass(LinkValue *inherit, Inter *inter) {
-    Inherit *father_value = NULL;
-    Value *new = NULL;
+    Inherit *father_value;
+    Value *new;
+    LinkValue *re;
     {
         Argument *arg = makeValueArgument(inherit);
         gc_addTmpLink(&inherit->gc_status);
@@ -76,7 +77,9 @@ LinkValue *makeBaseChildClass(LinkValue *inherit, Inter *inter) {
         gc_freeTmpLink(&inherit->gc_status);
     }
     new = makeClassValue(inter->var_list, inter, father_value);
-    return makeLinkValue(new, inter->base_belong, inter);
+    re = makeLinkValue(new, inter->base_belong, inter);
+    gc_freeTmpLink(&new->gc_status);
+    return re;
 }
 
 bool checkIndex(vint *index, const vint *size, FUNC_NT){

+ 1 - 0
vmcore/ofunc/src/function.c

@@ -23,6 +23,7 @@ ResultType function_new(O_FUNC){
         VarList *new_var = copyVarList(var_list, false, inter);
         Value *new_object = makeObject(inter, NULL, new_var, object_father);
         value = makeLinkValue(new_object, belong, inter);
+        gc_freeTmpLink(&new_object->gc_status);
     }
 
     value->value->type = V_func;

+ 2 - 0
vmcore/ofunc/src/object.c

@@ -90,11 +90,13 @@ void makeBaseObject(Inter *inter, LinkValue *belong){
     {
         Value *global_belong = makeObject(inter, copyVarList(inter->var_list, false, inter), NULL, NULL);
         g_belong = makeLinkValue(global_belong, belong, inter);
+        gc_freeTmpLink(&global_belong->gc_status);
         inter->base_belong = g_belong;
         gc_addStatementLink(&inter->base_belong->gc_status);
     }
 
     inter->data.base_obj[B_OBJECT] = makeLinkValue(object, g_belong, inter);
+    gc_freeTmpLink(&object->gc_status);
     gc_addStatementLink(&inter->data.base_obj[B_OBJECT]->gc_status);
     for (Inherit *ih=g_belong->value->object.inherit; ih != NULL; ih = ih->next) {
         if (ih->value->value == object)

+ 3 - 1
vmcore/src/__run.c

@@ -549,7 +549,9 @@ LinkValue *make_new(Inter *inter, LinkValue *belong, LinkValue *class){
     Inherit *object_father = getInheritFromValueCore(class);
     VarList *new_var = copyVarList(class->value->object.out_var, false, inter);
     Value *new_object = makeObject(inter, NULL, new_var, object_father);
-    return makeLinkValue(new_object, belong, inter);
+    LinkValue *re = makeLinkValue(new_object, belong, inter);
+    gc_freeTmpLink(&new_object->gc_status);
+    return re;
 }
 
 static int init_new(LinkValue *obj, Argument *arg, fline line, char *file, FUNC_NT) {

+ 1 - 1
vmcore/src/run.c

@@ -12,7 +12,7 @@ ResultType runStatement(FUNC) {
     setResultCore(result);
     gc_addTmpLink(&belong->gc_status);
 
-    switch (st->type) {
+    switch (st->type) {  // TODO-list 优化: 只有指定的st需要执行gc
         case base_value:
             type = getBaseValue(CNEXT);
             break;

+ 1 - 0
vmcore/src/runcall.c

@@ -14,6 +14,7 @@ ResultType setClass(FUNC) {
     freeArgument(call, false);
 
     tmp = makeLinkValue(makeClassValue(var_list, inter, class_inherit), belong, inter);
+    gc_freeTmpLink(&tmp->value->gc_status);
     gc_addTmpLink(&tmp->gc_status);
     freeResult(result);
 

+ 4 - 1
vmcore/src/runfile.c

@@ -212,11 +212,14 @@ static bool getPackage(LinkValue **imp_value, char *md5_str, char *split, int st
 
         freeResult(result);
         runImportFile(imp_inter, path, status, CNEXT);
-        if (!CHECK_RESULT(result))
+        if (!CHECK_RESULT(result)) {
+            gc_freeTmpLink(&pg->gc_status);
             return false;
+        }
     } else
         *is_new = false;
     *imp_value = makeLinkValue(pg, belong, inter);
+    gc_freeTmpLink(&pg->gc_status);
     gc_addTmpLink(&(*imp_value)->gc_status);
     return true;
 }

+ 2 - 1
vmcore/src/value.c

@@ -4,6 +4,7 @@ Value *makeObject(Inter *inter, VarList *object, VarList *out_var, Inherit *inhe
     Value *tmp, *list_tmp = inter->base;
     tmp = memCalloc(1, sizeof(Value));
     setGC(&tmp->gc_status);
+    gc_addTmpLink(&tmp->gc_status);
     tmp->type = V_obj;
     tmp->gc_next = NULL;
     if (inter->data.base_obj[B_OBJECT] != NULL && inherit == NULL)
@@ -270,7 +271,7 @@ void freeValue(Value **value) {
     return_: return;
 }
 
-LinkValue *makeLinkValue(Value *value, LinkValue *belong, Inter *inter){
+LinkValue *makeLinkValue(Value *value, LinkValue *belong, Inter *inter){  // TODO-szh 为LinkValue添加gc_tmpLink
     LinkValue *tmp;
     LinkValue *list_tmp = inter->link_base;
     tmp = memCalloc(1, sizeof(Value));