Przeglądaj źródła

refactor: 调整了makeClass的机制

makeClass不需要提前复制VarList
SongZihuan 4 lat temu
rodzic
commit
e63b3f0fc7

+ 1 - 1
VirtulMathCore/ofunc/src/__ofunc.c

@@ -78,7 +78,7 @@ Value *makeBaseChildClass(Value *inherit, Inter *inter) {
         freeArgument(arg, true);
         gc_freeTmpLink(&father_->gc_status);
     }
-    num = makeClassValue(copyVarList(inter->var_list, false, inter), inter, father_value);
+    num = makeClassValue(inter->var_list, inter, father_value);
     return num;
 }
 

+ 1 - 1
VirtulMathCore/ofunc/src/object.c

@@ -83,7 +83,7 @@ void registeredObject(REGISTERED_FUNCTIONSIG){
 }
 
 void makeBaseObject(Inter *inter){
-    Value *object = makeClassValue(copyVarList(inter->var_list, false, inter), inter, NULL);
+    Value *object = makeClassValue(inter->var_list, inter, NULL);
     gc_addStatementLink(&object->gc_status);
     inter->data.object = object;
 }

+ 2 - 4
VirtulMathCore/ofunc/src/str.c

@@ -230,10 +230,8 @@ LinkValue *makeFunctionFromValue(LinkValue *func, LinkValue *new, LinkValue *ini
     new_func->value->data.function.type = c_function;
     new_func->value->data.function.of = of;
     new_func->value->data.function.function_data.pt_type = inter->data.default_pt_type;
-    for (VarList *vl = new_func->value->object.out_var, *vl_next; vl != NULL; vl = vl_next) {
-        vl_next = vl->next;
-        freeVarList(vl);
-    }
+    for (VarList *vl = new_func->value->object.out_var; vl != NULL; vl = freeVarList(vl))
+        PASS;
     new_func->value->object.out_var = copyVarList(var_list, false, inter);
     new_func->belong = belong;
     return new_func;

+ 1 - 1
VirtulMathCore/ofunc/src/vobject.c

@@ -202,7 +202,7 @@ void registeredVObject(REGISTERED_FUNCTIONSIG){
 }
 
 void makeBaseVObject(Inter *inter){
-    Value *vobject = makeClassValue(copyVarList(inter->var_list, false, inter), inter, NULL);
+    Value *vobject = makeBaseChildClass(inter->data.object, inter);
     gc_addStatementLink(&vobject->gc_status);
     inter->data.vobject = vobject;
 }

+ 1 - 2
VirtulMathCore/src/__run.c

@@ -397,8 +397,7 @@ int init_new(LinkValue *obj, Argument *arg, char *message, INTER_FUNCTIONSIG_NOT
 
     if (_init_ == NULL) {
         if (arg != NULL) {
-            setResultError(E_ArgumentException, MANY_ARG, 0, message, true,
-                           CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            setResultError(E_ArgumentException, MANY_ARG, 0, message, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             return 0;
         } else
             return 1;

+ 7 - 2
VirtulMathCore/src/runcall.c

@@ -12,10 +12,15 @@ ResultType setClass(INTER_FUNCTIONSIG) {
 
     class_inherit = setFather(call);
     freeArgument(call, false);
-    tmp = makeLinkValue(makeClassValue(copyVarList(var_list, false, inter), inter, class_inherit), belong, inter);
+//    freeResult(result);
+//
+//    makeClassValue(class_inherit, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+//    tmp = result->value;
+//    result->value = NULL;
+    tmp = makeLinkValue(makeClassValue(var_list, inter, class_inherit), belong, inter);
     gc_addTmpLink(&tmp->gc_status);
-
     freeResult(result);
+
     {
         enum FunctionPtType pt_type_bak = inter->data.default_pt_type;
         VarList *var_backup = tmp->value->object.var->next;

+ 10 - 5
VirtulMathCore/src/value.c

@@ -53,6 +53,7 @@ Value *useNoneValue(Inter *inter, Result *result) {
 
 Value *makeBoolValue(bool bool_num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     Value *tmp = NULL;
+    setResultCore(result);
     callBackCore(makeLinkValue(inter->data.bool_, inter->base_father, inter), NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
     if (!CHECK_RESULT(result))
         return NULL;
@@ -63,6 +64,7 @@ Value *makeBoolValue(bool bool_num, fline line, char *file, INTER_FUNCTIONSIG_NO
 
 Value *makePassValue(fline line, char *file, INTER_FUNCTIONSIG_NOT_ST){  // TODO-szh 让切片支持该语法
     Value *tmp = NULL;
+    setResultCore(result);
     callBackCore(makeLinkValue(inter->data.pass_, inter->base_father, inter), NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
     if (!CHECK_RESULT(result))
         return NULL;
@@ -72,6 +74,7 @@ Value *makePassValue(fline line, char *file, INTER_FUNCTIONSIG_NOT_ST){  // TODO
 
 Value *makeNumberValue(vnum num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     Value *tmp = NULL;
+    setResultCore(result);
     callBackCore(makeLinkValue(inter->data.num, inter->base_father, inter), NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
     if (!CHECK_RESULT(result))
         return NULL;
@@ -82,6 +85,7 @@ Value *makeNumberValue(vnum num, fline line, char *file, INTER_FUNCTIONSIG_NOT_S
 
 Value *makeStringValue(char *str, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     Value *tmp = NULL;
+    setResultCore(result);
     callBackCore(makeLinkValue(inter->data.str, inter->base_father, inter), NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
     if (!CHECK_RESULT(result))
         return NULL;
@@ -147,10 +151,8 @@ LinkValue *makeCFunctionFromOf(OfficialFunction of, LinkValue *func, OfficialFun
     return_->value->data.function.type = c_function;
     return_->value->data.function.of = of;
     return_->value->data.function.function_data.pt_type = inter->data.default_pt_type;
-    for (VarList *vl = return_->value->object.out_var, *vl_next; vl != NULL; vl = vl_next) {
-        vl_next = vl->next;
-        freeVarList(vl);
-    }
+    for (VarList *vl = return_->value->object.out_var; vl != NULL; vl = freeVarList(vl))
+        PASS;
     return_->value->object.out_var = copyVarList(var_list, false, inter);
     return_->belong = belong;
     gc_freeTmpLink(&return_->gc_status);
@@ -159,13 +161,15 @@ LinkValue *makeCFunctionFromOf(OfficialFunction of, LinkValue *func, OfficialFun
 
 Value *makeClassValue(VarList *var_list, Inter *inter, Inherit *father) {
     Value *tmp;
-    tmp = makeObject(inter, NULL, var_list, father);
+    VarList *new_var = copyVarList(var_list, false, inter);
+    tmp = makeObject(inter, NULL, new_var, father);
     tmp->type = class;
     return tmp;
 }
 
 Value *makeListValue(Argument *arg, fline line, char *file, enum ListType type, INTER_FUNCTIONSIG_NOT_ST) {
     Value *tmp = NULL;
+    setResultCore(result);
     if (type == value_list)
         callBackCore(makeLinkValue(inter->data.list, inter->base_father, inter), arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
     else
@@ -179,6 +183,7 @@ Value *makeListValue(Argument *arg, fline line, char *file, enum ListType type,
 Value *makeDictValue(Argument *arg, bool new_hash, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     Value *tmp = NULL;
     LinkValue *dict = makeLinkValue(inter->data.dict, inter->base_father, inter);
+    setResultCore(result);
     callBackCore(dict, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
     if (!CHECK_RESULT(result))
         return NULL;