Explorar o código

feat: 函数调用的隐藏参数

SongZihuan %!s(int64=4) %!d(string=hai) anos
pai
achega
d729f26c81
Modificáronse 8 ficheiros con 43 adicións e 27 borrados
  1. 2 2
      include/__macro.h
  2. 1 2
      include/ofunc.h
  3. 8 0
      ofunc/include/__ofunc.h
  4. 16 0
      ofunc/src/__ofunc.c
  5. 3 3
      ofunc/src/io.c
  6. 0 15
      src/ofunc.c
  7. 6 2
      src/parameter.c
  8. 7 3
      src/runcall.c

+ 2 - 2
include/__macro.h

@@ -22,8 +22,8 @@
 
 #define freeBase(element, return_) do{if(element == NULL)goto return_;}while(0)
 
-#define OfficialFunctionSig struct LinkValue *self, struct Argument *arg, INTER_FUNCTIONSIG_NOT_ST
-#define CALL_OfficialFunction(self, arg, var_list, result, father) self, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father)
+#define OfficialFunctionSig struct Argument *arg, INTER_FUNCTIONSIG_NOT_ST
+#define CALL_OfficialFunction(arg, var_list, result, father) arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father)
 #define RegisteredFunctionSig struct LinkValue *father, INTER_FUNCTIONSIG_CORE
 #define CALL_RegisteredFunction(father, var_list) father, CALL_INTER_FUNCTIONSIG_CORE(var_list)
 

+ 1 - 2
include/ofunc.h

@@ -14,8 +14,7 @@ struct NameFunc{
 };
 typedef struct NameFunc NameFunc;
 
-void registeredFunctionCore(OfficialFunction of, char *name, struct LinkValue *father, INTER_FUNCTIONSIG_CORE);
-void iterNameFunc(NameFunc list[],struct LinkValue *father, INTER_FUNCTIONSIG_CORE);
+
 void registeredBaseFunction(struct LinkValue *father, Inter *inter);
 
 #endif //VIRTUALMATH_OFUNC_H

+ 8 - 0
ofunc/include/__ofunc.h

@@ -0,0 +1,8 @@
+#ifndef VIRTUALMATH___OFUNC_H
+#define VIRTUALMATH___OFUNC_H
+#include "__virtualmath.h"
+
+void registeredFunctionCore(OfficialFunction of, char *name, struct LinkValue *father, INTER_FUNCTIONSIG_CORE);
+void iterNameFunc(NameFunc list[],struct LinkValue *father, INTER_FUNCTIONSIG_CORE);
+
+#endif //VIRTUALMATH___OFUNC_H

+ 16 - 0
ofunc/src/__ofunc.c

@@ -0,0 +1,16 @@
+#include "__ofunc.h"
+
+void registeredFunctionCore(OfficialFunction of, char *name, struct LinkValue *father, INTER_FUNCTIONSIG_CORE) {
+    LinkValue *value = NULL;
+    LinkValue *name_ = NULL;
+    char *var_name = setStrVarName(name, false, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    name_ = makeLinkValue(makeStringValue(var_name, inter), father, inter);
+    value = makeLinkValue(makeCFunctionValue(of, var_list, inter), father, inter);
+    addFromVarList(var_name, name_, 0, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    memFree(var_name);
+}
+
+void iterNameFunc(NameFunc list[], LinkValue *father, INTER_FUNCTIONSIG_CORE){
+    for (PASS; list->of != NULL; list++)
+        registeredFunctionCore(list->of, list->name, father, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+}

+ 3 - 3
ofunc/src/io.c

@@ -1,12 +1,12 @@
-#include "__virtualmath.h"
+#include "__ofunc.h"
 
 ResultType vm_print(OfficialFunctionSig){
     setResultBase(result, inter, father);
-    if (arg == NULL){
+    if (arg == NULL || arg->next == NULL){
         setResultError(result, inter, "ArgumentException", "Don't get any Argument for print", 0, "sys", father, true);
         return error_return;
     }
-    for (PASS; arg != NULL; arg = arg->next)
+    for (arg = arg->next->next; arg != NULL; arg = arg->next)
         printValue(arg->data.value->value, stdout);
     printf("\n");
     return result->type;

+ 0 - 15
src/ofunc.c

@@ -2,21 +2,6 @@
 
 static Registered base_func_list[] = {registeredIOFunction, NULL};
 
-void registeredFunctionCore(OfficialFunction of, char *name, struct LinkValue *father, INTER_FUNCTIONSIG_CORE) {
-    LinkValue *value = NULL;
-    LinkValue *name_ = NULL;
-    char *var_name = setStrVarName(name, false, CALL_INTER_FUNCTIONSIG_CORE(var_list));
-    name_ = makeLinkValue(makeStringValue(var_name, inter), father, inter);
-    value = makeLinkValue(makeCFunctionValue(of, var_list, inter), father, inter);
-    addFromVarList(var_name, name_, 0, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
-    memFree(var_name);
-}
-
-void iterNameFunc(NameFunc list[], LinkValue *father, INTER_FUNCTIONSIG_CORE){
-    for (PASS; list->of != NULL; list++)
-        registeredFunctionCore(list->of, list->name, father, CALL_INTER_FUNCTIONSIG_CORE(var_list));
-}
-
 void registeredBaseFunction(struct LinkValue *father, Inter *inter){
     for (Registered *list = base_func_list; *list != NULL; list++)
         (*list)(CALL_RegisteredFunction(father, inter->var_list));

+ 6 - 2
src/parameter.c

@@ -444,17 +444,21 @@ Argument * getArgument(Parameter *call, bool is_dict, INTER_FUNCTIONSIG_NOT_ST)
  * @return
  */
 ResultType setParameter(long int line, char *file, Parameter *call_base, Parameter *function_base, VarList *function_var, LinkValue *function_father, INTER_FUNCTIONSIG_NOT_ST) {
+    Argument *self_tmp = makeValueArgument(function_father);
+    Argument *father_tmp = makeValueArgument(function_father->father);
     Argument *call = NULL;
     setResultCore(result);
     call = getArgument(call_base, false, CALL_INTER_FUNCTIONSIG_NOT_ST (var_list, result, father));
+    self_tmp->next = father_tmp;
+    father_tmp->next = call;
     if (!run_continue(result)) {
         freeArgument(call, false);
         return result->type;
     }
 
     freeResult(result);
-    setParameterCore(line, file, call, function_base, function_var, CALL_INTER_FUNCTIONSIG_NOT_ST (var_list, result, function_father));
-    freeArgument(call, false);
+    setParameterCore(line, file, self_tmp, function_base, function_var, CALL_INTER_FUNCTIONSIG_NOT_ST (var_list, result, function_father));
+    freeArgument(self_tmp, false);
     return result->type;
 }
 

+ 7 - 3
src/runcall.c

@@ -165,7 +165,7 @@ ResultType callClass(LinkValue *class_value, Parameter *parameter, long int line
     if (_init_ != NULL){
         Result _init_result;
         setResultCore(&_init_result);
-
+        _init_->father = value;
         gc_addTmpLink(&_init_->gc_status);
         callBackCore(_init_, parameter, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &_init_result, value));
         gc_freeTmpLink(&_init_->gc_status);
@@ -200,6 +200,8 @@ Statement *getRunInfoStatement(Statement *funtion_st){  // TODO-szh 去除该函
 ResultType callCFunction(LinkValue *function_value, Parameter *parameter, INTER_FUNCTIONSIG_NOT_ST){
     VarList *function_var = NULL;
     OfficialFunction of = NULL;
+    Argument *self_tmp = makeValueArgument(function_value);
+    Argument *father_tmp = makeValueArgument(function_value->father);
     Argument *arg = NULL;
     setResultCore(result);
     gc_addTmpLink(&function_value->gc_status);
@@ -209,15 +211,17 @@ ResultType callCFunction(LinkValue *function_value, Parameter *parameter, INTER_
 
     gc_addTmpLink(&function_var->hashtable->gc_status);
     arg = getArgument(parameter, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
+    self_tmp->next = father_tmp;
+    father_tmp->next = arg;
     gc_freeTmpLink(&function_var->hashtable->gc_status);
     if (!run_continue(result))
         goto return_;
 
     freeResult(result);
-    of(CALL_OfficialFunction(function_value, arg, function_var, result, father));
+    of(CALL_OfficialFunction(self_tmp, function_var, result, function_value));
 
     return_:
-    freeArgument(arg, true);
+    freeArgument(self_tmp, true);
     gc_freeze(inter, var_list, function_var, false);
     gc_freeTmpLink(&function_value->gc_status);
     return result->type;