Forráskód Böngészése

feat: 允许使用;输入指定的特殊形参

SongZihuan 4 éve
szülő
commit
efba3bd84e

+ 1 - 5
VirtulMathCore/include/run.h

@@ -32,12 +32,8 @@ ResultType setLambda(INTER_FUNCTIONSIG);
 ResultType callBack(INTER_FUNCTIONSIG);
 ResultType elementSlice(INTER_FUNCTIONSIG);
 
-ResultType callBackCore(LinkValue *function_value, Argument *arg, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+ResultType callBackCore(LinkValue *function_value, Argument *arg, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST);
 ResultType callBackCorePt(LinkValue *function_value, Parameter *pt, long line, char *file, INTER_FUNCTIONSIG_NOT_ST);
-ResultType callClass(LinkValue *class_value, Argument *arg, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
-ResultType callObject(LinkValue *object_value, Argument *arg, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
-ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int line, char *file, INTER_FUNCTIONSIG_NOT_ST);
-ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line, char *file, INTER_FUNCTIONSIG_NOT_ST);
 
 ResultType setDecoration(DecorationStatement *ds, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST);
 ResultType getVar(INTER_FUNCTIONSIG, VarInfo var_info);

+ 2 - 1
VirtulMathCore/ofunc/src/dict.c

@@ -164,7 +164,8 @@ ResultType dict_iter(OFFICAL_FUNCTIONSIG){
     }
     {
         Argument *dict_iter_arg = makeValueArgument(ap[0].value);
-        callBackCore(inter->data.dict_iter, dict_iter_arg, 0, "dict", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(inter->data.dict_iter, dict_iter_arg, 0, "dict", 0,
+                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         freeArgument(dict_iter_arg, true);
     }
     return result->type;

+ 4 - 3
VirtulMathCore/ofunc/src/dictiter.c

@@ -27,7 +27,7 @@ ResultType dictiter_init(OFFICAL_FUNCTIONSIG){
 
         gc_addTmpLink(&keys->gc_status);
         freeResult(result);
-        callBackCore(keys, NULL, 0, "dictiter", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(keys, NULL, 0, "dictiter", 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&keys->gc_status);
         if (!CHECK_RESULT(result)) {
             return error_return;
@@ -40,7 +40,8 @@ ResultType dictiter_init(OFFICAL_FUNCTIONSIG){
 
         list_arg = makeValueArgument(list);
         freeResult(result);
-        callBackCore(listiter_class, list_arg, 0, "dictiter", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(listiter_class, list_arg, 0, "dictiter", 0,
+                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         freeArgument(list_arg, true);
 
         if (!CHECK_RESULT(result)) {
@@ -86,7 +87,7 @@ ResultType dictiter_next(OFFICAL_FUNCTIONSIG){
         return error_return;
     }
 
-    callBackCore(list_next, NULL, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    callBackCore(list_next, NULL, 0, "sys", 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return result->type;
 }
 

+ 2 - 1
VirtulMathCore/ofunc/src/list.c

@@ -342,7 +342,8 @@ ResultType list_iter(OFFICAL_FUNCTIONSIG){
     }
     {
         Argument *list_iter_arg = makeValueArgument(ap[0].value);
-        callBackCore(inter->data.list_iter, list_iter_arg, 0, "list", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(inter->data.list_iter, list_iter_arg, 0, "list", 0,
+                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         freeArgument(list_iter_arg, true);
     }
     return result->type;

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

@@ -173,7 +173,7 @@ ResultType str_iter(OFFICAL_FUNCTIONSIG){
         return error_return;
     }
     gc_addTmpLink(&to_list->gc_status);
-    callBackCore(to_list, NULL, 0, "str", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    callBackCore(to_list, NULL, 0, "str", 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     gc_freeTmpLink(&to_list->gc_status);
     if (CHECK_RESULT(result)) {
         LinkValue *str_list = NULL;

+ 1 - 1
VirtulMathCore/parser/grammar.c

@@ -1243,7 +1243,7 @@ bool tailCall(PASERSSIGNATURE, Token *left_token, Statement **st){
 
     if (checkToken(pm, MATHER_RP))
         goto not_pt;
-    if (!parserParameter(CALLPASERSSIGNATURE, &pt, true, false, false, false, MATHER_COMMA, MATHER_ASSIGNMENT, -1)) {
+    if (!parserParameter(CALLPASERSSIGNATURE, &pt, true, false, false, false, MATHER_COMMA, MATHER_ASSIGNMENT, MATHER_SEMICOLON)) {
         syntaxError(pm, syntax_error, line, 1, "Don't get call parameter");
         return false;
     }

+ 71 - 26
VirtulMathCore/src/__run.c

@@ -134,27 +134,72 @@ void updateFunctionYield(Statement *function_st, Statement *node){
     function_st->info.have_info = true;
 }
 
-ResultType setFunctionArgument(Argument **arg, LinkValue *function_value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST){
+ResultType setFunctionArgument(Argument **arg, LinkValue *_func, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST){
     Argument *tmp = NULL;
-    enum FunctionPtType pt_type = function_value->value->data.function.function_data.pt_type;
+    LinkValue *self;
+    LinkValue *func;
+    enum FunctionPtType pt_type = _func->value->data.function.function_data.pt_type;
     setResultCore(result);
-    if (function_value->belong == NULL){
+
+    switch (pt_sep) {
+        case 0:
+            func = _func;
+            self = _func->belong;
+            break;
+        case 1: {
+            Argument *backup;
+            func = _func;
+            if (*arg != NULL) {
+                self = (*arg)->data.value;
+                backup = (*arg)->next;
+                (*arg)->next = NULL;
+                freeArgument(*arg, true);
+                *arg = backup;
+            } else {
+                error_:
+                setResultError(E_ArgumentException, FEW_ARG, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+                return error_return;
+            }
+            break;
+        }
+        case 2: {
+            Argument *backup;
+            printf("TAG A\n");
+            if (*arg != NULL && (*arg)->next != NULL) {
+                func = (*arg)->data.value;
+                self = (*arg)->next->data.value;
+
+                backup = (*arg)->next->next;
+                (*arg)->next->next = NULL;
+                freeArgument(*arg, true);
+                *arg = backup;
+                printf("TAG B\n");
+            } else
+                goto error_;
+            break;
+        }
+        default:
+            setResultError(E_ArgumentException, MANY_ARG, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            return error_return;
+    }
+
+    if (pt_type != free_ && self == NULL) {
         setResultError(E_ArgumentException, "Function does not belong to anything(not self)", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return error_return;
     }
 
     switch (pt_type) {
         case static_:
-            tmp = makeValueArgument(function_value);
+            tmp = makeValueArgument(func);
             tmp->next = *arg;
             *arg = tmp;
             break;
         case class_static_:
-            tmp = makeValueArgument(function_value);
-            if (function_value->belong->value->type == class)
-                tmp->next = makeValueArgument(function_value->belong);
-            else if (function_value->value->object.inherit->value != NULL)
-                tmp->next = makeValueArgument(function_value->belong->value->object.inherit->value);
+            tmp = makeValueArgument(func);
+            if (self->value->type == class)
+                tmp->next = makeValueArgument(self);
+            else if (self->value->object.inherit != NULL)  // TODO-szh 使用循环检查
+                tmp->next = makeValueArgument(self->value->object.inherit->value);
             else {
                 tmp->next = *arg;
                 *arg = tmp;
@@ -164,40 +209,40 @@ ResultType setFunctionArgument(Argument **arg, LinkValue *function_value, fline
             *arg = tmp;
             break;
         case all_static_:
-            tmp = makeValueArgument(function_value);
-            tmp->next = makeValueArgument(function_value->belong);
+            tmp = makeValueArgument(func);
+            tmp->next = makeValueArgument(self);
             tmp->next->next = *arg;
             *arg = tmp;
             break;
         case object_static_:
-            tmp = makeValueArgument(function_value);
-            if (function_value->belong->value->type == class)
+            tmp = makeValueArgument(func);
+            if (self->value->type == class)
                 tmp->next = *arg;
             else {
-                tmp->next = makeValueArgument(function_value->belong);
+                tmp->next = makeValueArgument(self);
                 tmp->next->next = *arg;
             }
             *arg = tmp;
             break;
         case class_free_:
-            if (function_value->belong->value->type == class)
-                tmp = makeValueArgument(function_value->belong);
-            else if (function_value->value->object.inherit != NULL)
-                tmp = makeValueArgument(function_value->belong->value->object.inherit->value);
+            if (self->value->type == class)
+                tmp = makeValueArgument(self);
+            else if (self->value->object.inherit != NULL)
+                tmp = makeValueArgument(self->value->object.inherit->value);
             else
                 break;
             tmp->next = *arg;
             *arg = tmp;
             break;
         case object_free_:
-            if (function_value->belong->value->type != class) {
-                tmp = makeValueArgument(function_value->belong);
+            if (self->value->type != class) {
+                tmp = makeValueArgument(self);
                 tmp->next = *arg;
                 *arg = tmp;
             }
             break;
         case all_free_:
-            tmp = makeValueArgument(function_value->belong);
+            tmp = makeValueArgument(self);
             tmp->next = *arg;
             *arg = tmp;
             break;
@@ -318,7 +363,7 @@ ResultType getElement(LinkValue *from, LinkValue *index, fline line, char *file,
         Argument *arg = NULL;
         gc_addTmpLink(&_func_->gc_status);
         arg = makeValueArgument(index);
-        callBackCore(_func_,arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_func_, arg, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_func_->gc_status);
         freeArgument(arg, true);
     }
@@ -340,7 +385,7 @@ ResultType getIter(LinkValue *value, int status, fline line, char *file, INTER_F
 
     if (_func_ != NULL){
         gc_addTmpLink(&_func_->gc_status);
-        callBackCore(_func_, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_func_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_func_->gc_status);
     }
     else
@@ -353,7 +398,7 @@ bool checkBool(LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_S
     LinkValue *_bool_ = findAttributes(inter->data.object_bool, false, value, inter);
     if (_bool_ != NULL){
         gc_addTmpLink(&_bool_->gc_status);
-        callBackCore(_bool_, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_bool_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_bool_->gc_status);
         if (result->value->value->type != bool_)
             setResultError(E_TypeException, RETURN_ERROR(__bool__, bool), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
@@ -372,7 +417,7 @@ char *getRepoStr(LinkValue *value, bool is_repo, fline line, char *file, INTER_F
     if (_repo_ != NULL){
         gc_addTmpLink(&value->gc_status);
         gc_addTmpLink(&_repo_->gc_status);
-        callBackCore(_repo_, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_repo_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_repo_->gc_status);
         gc_freeTmpLink(&value->gc_status);
         if (!CHECK_RESULT(result))
@@ -440,7 +485,7 @@ int init_new(LinkValue *obj, Argument *arg, char *message, INTER_FUNCTIONSIG_NOT
     }
     _init_->belong = obj;
     gc_addTmpLink(&_init_->gc_status);
-    callBackCore(_init_, arg, 0, message, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, obj));
+    callBackCore(_init_, arg, 0, message, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, obj));
     gc_freeTmpLink(&_init_->gc_status);
     return CHECK_RESULT(result) ? 1 : -1;
 }

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

@@ -20,7 +20,7 @@ void newWithBranchYield(Statement *branch_st, Statement *node, StatementList *sl
 void newForBranchYield(Statement *branch_st, Statement *node, StatementList *sl_node, VarList *new_var, enum StatementInfoStatus status,
                        Inter *inter, LinkValue *iter);
 
-ResultType setFunctionArgument(struct Argument **arg, LinkValue *function_value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+ResultType setFunctionArgument(struct Argument **arg, LinkValue *_func, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST);
 void freeFunctionArgument(Argument *arg, Argument *base);
 LinkValue *findStrVar(char *name, bool free_old, INTER_FUNCTIONSIG_CORE);
 LinkValue *checkStrVar(char *name, bool free_old, INTER_FUNCTIONSIG_CORE);

+ 4 - 2
VirtulMathCore/src/runbranch.c

@@ -577,7 +577,8 @@ ResultType withBranch(INTER_FUNCTIONSIG) {
 
             gc_addTmpLink(&_enter_->gc_status);
             gc_addTmpLink(&_exit_->gc_status);
-            callBackCore(_enter_, NULL, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
+            callBackCore(_enter_, NULL, st->line, st->code_file, 0,
+                         CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, value));
             if (!CHECK_RESULT(result)) {
                 set_result = false;
                 gc_freeTmpLink(&value->gc_status);
@@ -627,7 +628,8 @@ ResultType withBranch(INTER_FUNCTIONSIG) {
         freeResult(&else_tmp);
 
     if (_exit_ != NULL) {
-        callBackCore(_exit_, NULL, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &exit_tmp, value));
+        callBackCore(_exit_, NULL, st->line, st->code_file, 0,
+                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &exit_tmp, value));
         if (!RUN_TYPE(exit_tmp.type)) {
             if (!set_result)
                 freeResult(result);

+ 36 - 33
VirtulMathCore/src/runcall.c

@@ -12,11 +12,7 @@ ResultType setClass(INTER_FUNCTIONSIG) {
 
     class_inherit = setFather(call);
     freeArgument(call, false);
-//    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);
@@ -154,15 +150,23 @@ ResultType callBack(INTER_FUNCTIONSIG) {
 
 ResultType callBackCorePt(LinkValue *function_value, Parameter *pt, long line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     Argument *arg = NULL;
+    int pt_sep =1;
+    bool sep = false;
     setResultCore(result);
     gc_addTmpLink(&function_value->gc_status);
 
     arg = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         goto return_;
+    for (Parameter *tmp = pt; tmp != NULL; tmp = tmp->next, pt_sep++) {
+        if (tmp->data.is_sep) {
+            sep = true;
+            break;
+        }
+    }
 
     freeResult(result);
-    callBackCore(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    callBackCore(function_value, arg, line, file, sep ? pt_sep : 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
     return_:
     gc_freeTmpLink(&function_value->gc_status);
@@ -170,29 +174,12 @@ ResultType callBackCorePt(LinkValue *function_value, Parameter *pt, long line, c
     return result->type;
 }
 
-ResultType callBackCore(LinkValue *function_value, Argument *arg, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST){
-    setResultCore(result);
-    gc_addTmpLink(&function_value->gc_status);
-    if (function_value->value->type == function && function_value->value->data.function.type == vm_function)
-        callVMFunction(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    else if (function_value->value->type == function && function_value->value->data.function.type == c_function)
-        callCFunction(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    else if (function_value->value->type == class)
-        callClass(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    else
-        callObject(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    setResultError(E_BaseException, NULL, line, file, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-
-    gc_freeTmpLink(&function_value->gc_status);
-    return result->type;
-}
-
-ResultType callClass(LinkValue *class_value, Argument *arg, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+static ResultType callClass(LinkValue *class_value, Argument *arg, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST) {
     LinkValue *_new_ = findAttributes(inter->data.object_new, false, class_value, inter);
     setResultCore(result);
     if (_new_ != NULL){
         gc_addTmpLink(&_new_->gc_status);
-        callBackCore(_new_, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_new_, arg, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_new_->gc_status);
     }
     else
@@ -202,13 +189,13 @@ ResultType callClass(LinkValue *class_value, Argument *arg, fline line, char *fi
     return result->type;
 }
 
-ResultType callObject(LinkValue *object_value, Argument *arg, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+static ResultType callObject(LinkValue *object_value, Argument *arg, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST) {
     LinkValue *_call_ = findAttributes(inter->data.object_call, false, object_value, inter);
     setResultCore(result);
 
     if (_call_ != NULL){
         gc_addTmpLink(&_call_->gc_status);
-        callBackCore(_call_, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_call_, arg, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_call_->gc_status);
     }
     else
@@ -217,14 +204,14 @@ ResultType callObject(LinkValue *object_value, Argument *arg, fline line, char *
     return result->type;
 }
 
-ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line, char *file, INTER_FUNCTIONSIG_NOT_ST){
+static ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST){
     VarList *function_var = NULL;
     OfficialFunction of = NULL;
     Argument *bak = arg;
     setResultCore(result);
     gc_addTmpLink(&function_value->gc_status);
 
-    setFunctionArgument(&arg, function_value, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    setFunctionArgument(&arg, function_value, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         goto return_;
 
@@ -247,7 +234,7 @@ ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line
     return result->type;
 }
 
-ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+static ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST) {
     VarList *var_func = NULL;
     Statement *st_func = NULL;
     Argument *bak = arg;
@@ -267,10 +254,9 @@ ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int lin
 
     gc_freeze(inter, var_list, var_func, true);
 
-    setFunctionArgument(&arg, function_value, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    setFunctionArgument(&arg, function_value, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         goto return_;
-
     freeResult(result);
     gc_addTmpLink(&var_func->hashtable->gc_status);
     setParameterCore(line, file, arg, pt_func, var_func, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, function_value->belong));
@@ -290,7 +276,7 @@ ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int lin
     functionSafeInterStatement(CALL_INTER_FUNCTIONSIG(st_func, var_func, result, function_value->belong));
     gc_freeze(inter, var_list, var_func, false);
 
-    st_func = function_value->value->data.function.function;
+    st_func = function_value->value->data.function.function;  // TODO-szh 提取函数
     if (yield_run)
         if (result->type == yield_return){
             updateFunctionYield(st_func, result->node);
@@ -310,6 +296,23 @@ ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int lin
     return result->type;
 }
 
+ResultType callBackCore(LinkValue *function_value, Argument *arg, fline line, char *file, int pt_sep, INTER_FUNCTIONSIG_NOT_ST) {
+    setResultCore(result);
+    gc_addTmpLink(&function_value->gc_status);
+    if (function_value->value->type == function && function_value->value->data.function.type == vm_function)
+        callVMFunction(function_value, arg, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    else if (function_value->value->type == function && function_value->value->data.function.type == c_function)
+        callCFunction(function_value, arg, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    else if (function_value->value->type == class)
+        callClass(function_value, arg, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    else
+        callObject(function_value, arg, line, file, pt_sep, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    setResultError(E_BaseException, NULL, line, file, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+
+    gc_freeTmpLink(&function_value->gc_status);
+    return result->type;
+}
+
 ResultType setDecoration(DecorationStatement *ds, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
     LinkValue *decall = NULL;
     Parameter *pt = NULL;

+ 6 - 3
VirtulMathCore/src/runoperation.c

@@ -214,7 +214,8 @@ ResultType downDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
         if (!CHECK_RESULT(result))
             goto dderror_;
         freeResult(result);
-        callBackCore(_func_, arg, name->line, name->code_file, 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));
 
         dderror_:
         gc_freeTmpLink(&_func_->gc_status);
@@ -359,7 +360,8 @@ ResultType downAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST)
             goto daerror_;
 
         freeResult(result);
-        callBackCore(_func_, arg, name->line, name->code_file, 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);
@@ -552,7 +554,8 @@ ResultType operationCore(INTER_FUNCTIONSIG, char *name) {
     if (_func_ != NULL){
         Argument *arg = makeValueArgument(right.value);
         gc_addTmpLink(&_func_->gc_status);
-        callBackCore(_func_, arg, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_func_, arg, st->line, st->code_file, 0,
+                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_func_->gc_status);
         freeArgument(arg, true);
     }

+ 16 - 11
VirtulMathCore/src/value.c

@@ -43,7 +43,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(inter->data.bool_, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    callBackCore(inter->data.bool_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
     tmp = result->value->value;
@@ -54,7 +54,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(inter->data.pass_, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    callBackCore(inter->data.pass_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
     tmp = result->value->value;
@@ -64,7 +64,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(inter->data.num, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    callBackCore(inter->data.num, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
     tmp = result->value->value;
@@ -75,7 +75,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(inter->data.str, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    callBackCore(inter->data.str, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
     tmp = result->value->value;
@@ -86,7 +86,8 @@ Value *makeStringValue(char *str, fline line, char *file, INTER_FUNCTIONSIG_NOT_
 
 Value *makeVMFunctionValue(Statement *st, Parameter *pt, INTER_FUNCTIONSIG_NOT_ST) {  // TODO-szh 设置无var_list的函数 (允许使用装饰器装饰,该功能未测试)
     Value *tmp = NULL;
-    callBackCore(inter->data.function, NULL, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    callBackCore(inter->data.function, NULL, st->line, st->code_file, 0,
+                 CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
     tmp = result->value->value;
@@ -103,7 +104,8 @@ Value *makeVMFunctionValue(Statement *st, Parameter *pt, INTER_FUNCTIONSIG_NOT_S
 
 Value *makeCFunctionValue(OfficialFunction of, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     Value *tmp = NULL;
-    callBackCore(inter->data.function, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    callBackCore(inter->data.function, NULL, line, file, 0,
+                 CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
     tmp = result->value->value;
@@ -160,9 +162,11 @@ Value *makeListValue(Argument *arg, fline line, char *file, enum ListType type,
     Value *tmp = NULL;
     setResultCore(result);
     if (type == value_list)
-        callBackCore(inter->data.list, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+        callBackCore(inter->data.list, arg, line, file, 0,
+                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     else
-        callBackCore(inter->data.tuple, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+        callBackCore(inter->data.tuple, arg, line, file, 0,
+                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
     tmp = result->value->value;
@@ -172,7 +176,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;
     setResultCore(result);
-    callBackCore(inter->data.dict, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    callBackCore(inter->data.dict, arg, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return NULL;
     tmp = result->value->value;
@@ -354,7 +358,7 @@ void callException(LinkValue *exc, char *message, fline line, char *file, INTER_
         freeResult(result);
 
         gc_addTmpLink(&_new_->gc_status);
-        callBackCore(_new_, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        callBackCore(_new_, arg, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_new_->gc_status);
         freeArgument(arg, true);
         type = getErrorInfo(result->value, 1, inter);
@@ -582,7 +586,8 @@ bool callDel(Value *object_value, Result *result, Inter *inter, VarList *var_lis
         gc_addTmpLink(&_del_->gc_status);
         if (_del_->belong == NULL || _del_->belong->value != object_value && checkAttribution(object_value, _del_->belong->value))
             _del_->belong = makeLinkValue(object_value, inter->base_belong, inter);
-        callBackCore(_del_, NULL, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, inter->base_belong));
+        callBackCore(_del_, NULL, 0, "sys", 0,
+                     CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, inter->base_belong));
         gc_freeTmpLink(&_del_->gc_status);
         return true;
     } else

+ 19 - 1
main.c

@@ -20,4 +20,22 @@ int main(int argc, char *argv[]) {
         runCodeStdin(inter, HelloString);
     freeInter(inter, true);
     return 0;
-}
+}
+
+/**
+class A{
+	def __init__(self, n) {
+		self.num = n
+	}
+
+	def printNum(self) {
+		print(self.num)
+	}
+}
+
+a = A(5)
+b = A(10)
+# a.printNum(20, b;)
+a.printNum(b, 20;)  // 运行到此处会内存错误
+
+ */