Просмотр исходного кода

feat: 重新设定函数的默认类型

非class的全局函数默认为free_
class的函数默认为object_free_
SongZihuan 4 лет назад
Родитель
Сommit
7a3bdc6be0
4 измененных файлов с 12 добавлено и 8 удалено
  1. 1 0
      include/inter.h
  2. 1 0
      src/inter.c
  3. 3 0
      src/runcall.c
  4. 7 8
      src/value.c

+ 1 - 0
include/inter.h

@@ -36,6 +36,7 @@ struct Inter{
         char *object_sub;
         char *object_mul;
         char *object_div;
+        int default_pt_type;
     } data;
 };
 

+ 1 - 0
src/inter.c

@@ -62,6 +62,7 @@ void setBaseInterData(struct Inter *inter){
     inter->data.object_sub = memStrcpy("__sub__");
     inter->data.object_mul = memStrcpy("__mul__");
     inter->data.object_div = memStrcpy("__div__");
+    inter->data.default_pt_type = free_;
 
 }
 

+ 3 - 0
src/runcall.c

@@ -5,6 +5,7 @@ ResultType setClass(INTER_FUNCTIONSIG) {
     LinkValue *tmp = NULL;
     FatherValue *class_father = NULL;
     VarList *father_var = NULL;
+    enum FunctionPtType pt_type_bak = inter->data.default_pt_type;
     setResultCore(result);
 
     call = getArgument(st->u.set_class.father, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
@@ -19,7 +20,9 @@ ResultType setClass(INTER_FUNCTIONSIG) {
     father_var = tmp->value->object.var->next;
     tmp->value->object.var->next = var_list;
     freeResult(result);
+    inter->data.default_pt_type = object_free_;
     functionSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.set_class.st, tmp->value->object.var, result, tmp));
+    inter->data.default_pt_type = pt_type_bak;
     tmp->value->object.var->next = father_var;
     if (!run_continue(result))
         goto error_;

+ 7 - 8
src/value.c

@@ -80,8 +80,8 @@ Value *makeStringValue(char *str, Inter *inter) {
 }
 
 
-static void setFunctionData(Value *value) {  // TODO-szh 内嵌到 inter 中
-    value->data.function.function_data.pt_type = object_static_;
+static void setFunctionData(Value *value, Inter *inter) {
+    value->data.function.function_data.pt_type = inter->data.default_pt_type;
 }
 
 Value *makeVMFunctionValue(Statement *st, Parameter *pt, VarList *var_list, Inter *inter) {
@@ -93,7 +93,7 @@ Value *makeVMFunctionValue(Statement *st, Parameter *pt, VarList *var_list, Inte
     tmp->data.function.function = copyStatement(st);
     tmp->data.function.pt = copyParameter(pt);
     tmp->data.function.of = NULL;
-    setFunctionData(tmp);
+    setFunctionData(tmp, inter);
     return tmp;
 }
 
@@ -106,7 +106,7 @@ Value *makeCFunctionValue(OfficialFunction of, VarList *var_list, Inter *inter)
     tmp->data.function.function = NULL;
     tmp->data.function.pt = NULL;
     tmp->data.function.of = of;
-    setFunctionData(tmp);
+    setFunctionData(tmp, inter);
     return tmp;
 }
 
@@ -323,8 +323,7 @@ void printValue(Value *value, FILE *debug, bool print_father) {
             for (int i=0;i < value->data.list.size;i++){
                 if (i > 0)
                     fprintf(debug, ", ", NULL);
-
-                printLinkValue(value->data.list.list[i], "", "", debug);
+                printValue(value->data.list.list[i]->value, debug, false);
             }
             fprintf(debug, " ]", NULL);
             break;
@@ -338,9 +337,9 @@ void printValue(Value *value, FILE *debug, bool print_father) {
                         fprintf(debug, ", ", NULL);
                     else
                         print_comma = true;
-                    printLinkValue(tmp->name_, "", "", debug);
+                    printValue(tmp->name_->value, debug, false);
                     fprintf(debug, " ['%s'] : ", tmp->name);
-                    printLinkValue(tmp->value, "", "", debug);
+                    printValue(tmp->value->value, debug, false);
                 }
             }
             fprintf(debug, " }", NULL);