Преглед изворни кода

feat: 特殊的变量访问函数也可以处理变量式函数

link #6
SongZihuan пре 4 година
родитељ
комит
637b64c94d

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

@@ -6,7 +6,7 @@ LinkValue *registeredFunctionCore(OfficialFunction of, wchar_t *name, INTER_FUNC
     value = result->value;
     result->value = NULL;
     freeResult(result);
-    addStrVar(name, false, true, value, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    addStrVar(name, false, true, value, 0, "sys", false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     gc_freeTmpLink(&value->gc_status);
     return value;
 }
@@ -117,7 +117,7 @@ bool checkSlice(vnum *first, vnum *second, const vnum *stride, vnum size, INTER_
 void addBaseClassVar(wchar_t *name, LinkValue *obj, LinkValue *belong, Inter *inter) {
     Result result;
     setResultCore(&result);
-    addStrVar(name, false, true, obj, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(inter->var_list, &result, belong));
+    addStrVar(name, false, true, obj, 0, "sys", false, CALL_INTER_FUNCTIONSIG_NOT_ST(inter->var_list, &result, belong));
     if (!RUN_TYPE(result.type))
         printError(&result, inter, true);
     freeResult(&result);

+ 2 - 2
VirtulMathCore/ofunc/src/dictiter.c

@@ -57,9 +57,9 @@ ResultType dictiter_init(OFFICAL_FUNCTIONSIG){
         gc_freeTmpLink(&listiter_class->gc_status);
     }
     freeResult(result);
-    if (addAttributes(L"__list", false, list_iter, 0, "dictiter.init", ap[0].value, result, inter, var_list)) {
+    if (addAttributes(L"__list", false, list_iter, 0, "dictiter.init", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value))) {
         freeResult(result);
-        addAttributes(L"__dict", false, ap[1].value, 0, "dictiter.init", ap[0].value, result, inter, var_list);
+        addAttributes(L"__dict", false, ap[1].value, 0, "dictiter.init", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
     }
     gc_freeTmpLink(&list_iter->gc_status);
     setResult(result, inter);

+ 2 - 2
VirtulMathCore/ofunc/src/error_.c

@@ -16,8 +16,8 @@ ResultType base_exception_init(OFFICAL_FUNCTIONSIG){
     if (!CHECK_RESULT(result))
         return result->type;
     freeResult(result);
-    if (addAttributes(inter->data.object_message, false, ap[1].value, 0, "BaseException.init", ap[0].value, result,
-                      inter, var_list))
+    if (addAttributes(inter->data.object_message, false, ap[1].value, 0, "BaseException.init", true,
+                      CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value)))
         setResult(result, inter);
     return result->type;
 }

+ 2 - 2
VirtulMathCore/ofunc/src/function.c

@@ -90,8 +90,8 @@ void functionPresettingLast(LinkValue *func, LinkValue *func_new, LinkValue *fun
     VarList *object_var = func->value->object.var;
     setResultCore(&result);
 
-    addStrVar(inter->data.object_new, false, true, func_new, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(object_var, &result, func));
+    addStrVar(inter->data.object_new, false, true, func_new, 0, "sys", false, CALL_INTER_FUNCTIONSIG_NOT_ST(object_var, &result, func));
     freeResult(&result);
-    addStrVar(inter->data.object_init, false, true, func_init, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(object_var, &result, func));
+    addStrVar(inter->data.object_init, false, true, func_init, 0, "sys", false, CALL_INTER_FUNCTIONSIG_NOT_ST(object_var, &result, func));
     freeResult(&result);
 }

+ 3 - 3
VirtulMathCore/ofunc/src/listiter.c

@@ -20,9 +20,9 @@ ResultType listiter_init(OFFICAL_FUNCTIONSIG){
         return result->type;
 
     freeResult(result);
-    if (addAttributes(L"__list", false, ap[1].value, 0, "listiter.init", ap[0].value, result, inter, var_list)) {
+    if (addAttributes(L"__list", false, ap[1].value, 0, "listiter.init", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value))) {
         freeResult(result);
-        addAttributes(L"__index", false, index, 0, "listiter.init", ap[0].value, result, inter, var_list);
+        addAttributes(L"__index", false, index, 0, "listiter.init", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, ap[0].value));
     }
 
     setResult(result, inter);
@@ -62,7 +62,7 @@ ResultType listiter_next(OFFICAL_FUNCTIONSIG){
         Result tmp_result;
         setResultCore(&tmp_result);
         index->value->data.num.num ++;
-        if (addAttributes(L"__index", false, index, 0, "listiter.next", ap[0].value, &tmp_result, inter, var_list))
+        if (addAttributes(L"__index", false, index, 0, "listiter.next", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &tmp_result, ap[0].value)))
             freeResult(&tmp_result);
         else {
             freeResult(result);

+ 22 - 11
VirtulMathCore/src/__run.c

@@ -290,7 +290,7 @@ LinkValue *checkStrVar(wchar_t *name, bool free_old, INTER_FUNCTIONSIG_CORE){
     return tmp;
 }
 
-void addStrVarCore(int setting, wchar_t *var_name, LinkValue *name_, LinkValue *value, fline line, char *file, VarList *out_var, INTER_FUNCTIONSIG_NOT_ST) {
+static void addStrVarCore(int setting, wchar_t *var_name, LinkValue *name_, LinkValue *value, fline line, char *file, VarList *out_var, INTER_FUNCTIONSIG_NOT_ST) {
     addFromVarList(var_name, name_, 0, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
     out_var = out_var == NULL ? var_list : out_var;
     if (setting)
@@ -299,11 +299,17 @@ void addStrVarCore(int setting, wchar_t *var_name, LinkValue *name_, LinkValue *
         setResult(result, inter);
 }
 
-void addStrVar(wchar_t *name, bool free_old, bool setting, LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+void addStrVar(wchar_t *name, bool free_old, bool setting, LinkValue *value, fline line, char *file, bool run, INTER_FUNCTIONSIG_NOT_ST) {
     LinkValue *name_;
     wchar_t *var_name = setStrVarName(name, free_old, inter);
     setResultCore(result);
 
+    if (run) {
+        LinkValue *tmp = findFromVarList(name, 0, read_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+        if (tmp != NULL && !setVarFunc(tmp, value, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
+            goto return_;
+    }
+
     makeStringValue(name, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         goto return_;
@@ -311,26 +317,31 @@ void addStrVar(wchar_t *name, bool free_old, bool setting, LinkValue *value, fli
     name_ = result->value;
     result->value = NULL;
     freeResult(result);
-
     addStrVarCore(setting, var_name, name_, value, line, file, NULL, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-
     gc_freeTmpLink(&name_->gc_status);
+
     return_:
     memFree(var_name);
 }
 
-LinkValue *findAttributes(wchar_t *name, bool free_old, LinkValue *value, Inter *inter) {
+LinkValue *findAttributes(wchar_t *name, bool free_old, LinkValue *value, Inter *inter) {  // TODO-szh 此处使用findStrVar替代findStrVarOnly
     LinkValue *attr = findStrVarOnly(name, free_old, CALL_INTER_FUNCTIONSIG_CORE(value->value->object.var));
     if (attr != NULL && (attr->belong == NULL || attr->belong->value != value->value && checkAttribution(value->value, attr->belong->value)))
         attr->belong = value;
     return attr;
 }
 
-bool addAttributes(wchar_t *name, bool free_old, LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+bool addAttributes(wchar_t *name, bool free_old, LinkValue *value, fline line, char *file, bool run, INTER_FUNCTIONSIG_NOT_ST) {
     wchar_t *var_name = setStrVarName(name, free_old, inter);
     LinkValue *name_;
     setResultCore(result);
 
+    if (run) {
+        LinkValue *tmp = findFromVarList(name, 0, read_var, CALL_INTER_FUNCTIONSIG_CORE(belong->value->object.var));
+        if (tmp != NULL && !setVarFunc(tmp, value, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(belong->value->object.var, result, belong)))
+            goto return_;
+    }
+
     makeStringValue(name, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         goto return_;
@@ -351,15 +362,15 @@ bool addAttributes(wchar_t *name, bool free_old, LinkValue *value, fline line, c
 
 void newObjectSetting(LinkValue *name, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     setResultCore(result);
-    addAttributes(inter->data.object_name, false, name, line, file, belong, result, inter, var_list);
+    addAttributes(inter->data.object_name, false, name, line, file, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (CHECK_RESULT(result))
         return;
     freeResult(result);
-    addAttributes(inter->data.object_self, false, belong, line, file, belong, result, inter, var_list);
+    addAttributes(inter->data.object_self, false, belong, line, file, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (CHECK_RESULT(result) && belong->value->object.inherit != NULL) {
         freeResult(result);
-        addAttributes(inter->data.object_father, false, belong->value->object.inherit->value, line, file, belong,
-                      result, inter, var_list);
+        addAttributes(inter->data.object_father, false, belong->value->object.inherit->value, line, file, false,
+                      CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     }
 }
 
@@ -521,7 +532,7 @@ bool setBoolAttrible(bool value, wchar_t *var, fline line, char *file, LinkValue
         return false;
     bool_value = result->value;
     freeResult(result);
-    if (!addAttributes(var, false, bool_value, line, file, obj, result, inter, var_list))
+    if (!addAttributes(var, false, bool_value, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, obj)))
         return false;
     freeResult(result);
     return true;

+ 2 - 2
VirtulMathCore/src/include/__run.h

@@ -16,10 +16,10 @@ void freeFunctionArgument(Argument *arg, Argument *base);
 LinkValue *findStrVar(wchar_t *name, bool free_old, fline line, char *file, bool nowrun, INTER_FUNCTIONSIG_NOT_ST);
 LinkValue *findStrVarOnly(wchar_t *name, bool free_old, INTER_FUNCTIONSIG_CORE);
 LinkValue *checkStrVar(wchar_t *name, bool free_old, INTER_FUNCTIONSIG_CORE);
-void addStrVar(wchar_t *name, bool free_old, bool setting, LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+void addStrVar(wchar_t *name, bool free_old, bool setting, LinkValue *value, fline line, char *file, bool run, INTER_FUNCTIONSIG_NOT_ST);
 LinkValue *findAttributes(wchar_t *name, bool free_old, LinkValue *value, Inter *inter);
 
-bool addAttributes(wchar_t *name, bool free_old, LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+bool addAttributes(wchar_t *name, bool free_old, LinkValue *value, fline line, char *file, bool run, INTER_FUNCTIONSIG_NOT_ST);
 void newObjectSetting(LinkValue *name, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
 ResultType getElement(LinkValue *from, LinkValue *index, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
 ResultType getIter(LinkValue *value, int status, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);

+ 1 - 1
VirtulMathCore/src/parameter.c

@@ -308,7 +308,7 @@ ResultType argumentToVar(Argument **call_ad, vnum *num, INTER_FUNCTIONSIG_NOT_ST
 
     for (*num = 0; call != NULL && call->type == name_arg; (*num)++, call = call->next){
         if (call->name_type == name_char){
-            addFromVarList(call->data.name_, call->data.name_value, 0, call->data.value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+            addFromVarList(call->data.name_, call->data.name_value, 0, call->data.value, CALL_INTER_FUNCTIONSIG_CORE(var_list));  // 参数赋值不需要处理变量式参数
             continue;
         }
         freeResult(result);

+ 0 - 1
VirtulMathCore/src/runbranch.c

@@ -463,7 +463,6 @@ static void setForResult(bool yield_run, StatementList *sl, Statement *st, Resul
     }
 }
 
-// TODO-szh 简化函数
 ResultType forBranch(INTER_FUNCTIONSIG) {
     StatementList *for_list = st->u.for_branch.for_list;
     Statement *first = st->u.for_branch.first_do;

+ 1 - 1
VirtulMathCore/src/runfile.c

@@ -258,7 +258,7 @@ ResultType importFile(INTER_FUNCTIONSIG) {
     freeResult(result);
     if (st->u.import_file.as == NULL) {
         wchar_t *name_ = memStrToWcs(split_path, false);
-        addStrVar(name_, false, is_new, imp_value, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        addStrVar(name_, false, is_new, imp_value, 0, "sys", false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         memFree(name_);
     }
     else

+ 2 - 3
VirtulMathCore/src/runoperation.c

@@ -320,7 +320,7 @@ ResultType varAss(Statement *name, LinkValue *value, bool check_aut, bool settin
     } else if (name->aut != auto_aut && tmp != NULL)
         tmp->aut = value->aut;
 
-    if (tmp == NULL || !run || !setVarFunc(tmp, value, name->line, name->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))  // TODO-szh 其他变量获取函数也使用改方法
+    if (tmp == NULL || !run || !setVarFunc(tmp, value, name->line, name->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
         addFromVarList(str_name, name_, int_times, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
     if (CHECK_RESULT(result))
         goto error_;
@@ -388,8 +388,7 @@ ResultType downAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST)
             goto daerror_;
 
         freeResult(result);
-        callBackCore(_func_, arg, name->line, name->code_file, 0,
-                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_func_, arg, name->line, name->code_file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
         daerror_:
         freeArgument(arg, true);