Przeglądaj źródła

refactor: makeValue的函数都写入到对应类的__new__

SongZihuan 4 lat temu
rodzic
commit
5a9358bf33

+ 1 - 1
VirtulMathCore/include/ofunc.h

@@ -29,5 +29,5 @@ struct NameFunc{
 typedef struct NameFunc NameFunc;
 
 void registeredBaseFunction(struct LinkValue *father, Inter *inter);
-void registeredFunctionName(Inter *inter);
+void registeredFunctionName(Inter *inter, LinkValue *belong);
 #endif //VIRTUALMATH_OFUNC_H

+ 12 - 11
VirtulMathCore/include/value.h

@@ -172,21 +172,22 @@ void freeValue(Value **Value);
 LinkValue *makeLinkValue(Value *value, LinkValue *belong, Inter *inter);
 void freeLinkValue(LinkValue **value);
 LinkValue *copyLinkValue(LinkValue *value, Inter *inter);
-Value *makeNoneValue(Inter *inter);
-Value *makeBoolValue(bool bool_num, Inter *inter);
-Value *makePassValue(Inter *inter);
-Value *makeNumberValue(vnum num, Inter *inter);
-Value *makeStringValue(char *str, Inter *inter);
-Value *makeVMFunctionFromValue(Value *value, LinkValue *return_value, fline line, char *file, Inter *inter);
-Value *makeVMFunctionValue(struct Statement *st, struct Parameter *pt, struct VarList *var_list, Inter *inter);
-Value *makeCFunctionValue(OfficialFunction of, VarList *var_list, Inter *inter);
+Value *makeNoneValue(fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+Value *useNoneValue(Inter *inter, Result *result);
+Value *makeBoolValue(bool bool_num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+Value *makePassValue(fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+Value *makeNumberValue(vnum num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+Value *makeStringValue(char *str, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+Value *makeVMFunctionValue(struct Statement *st, struct Parameter *pt, INTER_FUNCTIONSIG_NOT_ST);
+Value *makeCFunctionValue(OfficialFunction of, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
+LinkValue *makeCFunctionFromOf(OfficialFunction of, LinkValue *func, OfficialFunction function_new, OfficialFunction function_init, LinkValue *belong, VarList *var_list, Inter *inter);
 Value *makeClassValue(VarList *var_list, Inter *inter, Inherit *father);
-Value *makeListValue(struct Argument **arg_ad, Inter *inter, enum ListType type);
-Value *makeDictValue(struct Argument **arg_ad, bool new_hash, INTER_FUNCTIONSIG_NOT_ST);
+Value *makeListValue(Argument *arg, fline line, char *file, enum ListType type, INTER_FUNCTIONSIG_NOT_ST);
+Value *makeDictValue(Argument *arg, bool new_hash, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
 
 void setResultCore(Result *ru);
 void setResult(Result *ru, Inter *inter, LinkValue *belong);
-void setResultBase(Result *ru, Inter *inter, LinkValue *belong);
+void setResultBase(Result *ru, Inter *inter);
 void setResultErrorSt(BaseErrorType type, char *error_message, bool new, INTER_FUNCTIONSIG);
 void setResultError(BaseErrorType type, char *error_message, fline line, char *file, bool new, INTER_FUNCTIONSIG_NOT_ST);
 void setResultOperationNone(Result *ru, Inter *inter, LinkValue *belong);

+ 9 - 3
VirtulMathCore/ofunc/include/__ofunc.h

@@ -4,10 +4,16 @@
 #include "__base.h"
 #include "__run.h"
 
-LinkValue *registeredFunctionCore(OfficialFunction of, char *name, struct LinkValue *belong, INTER_FUNCTIONSIG_CORE);
-void iterNameFunc(NameFunc list[],struct LinkValue *father, INTER_FUNCTIONSIG_CORE);
-void iterClassFunc(NameFunc list[], LinkValue *father, INTER_FUNCTIONSIG_CORE);
+void newObjectSettingPresetting(LinkValue *func, LinkValue *name, Inter *inter);
+LinkValue *registeredFunctionCore(OfficialFunction of, char *name, INTER_FUNCTIONSIG_NOT_ST);
+
+bool iterNameFunc(NameFunc *list, INTER_FUNCTIONSIG_NOT_ST);
+bool iterClassFunc(NameFunc *list, INTER_FUNCTIONSIG_NOT_ST);
+
+void iterBaseNameFunc(NameFunc *list, struct LinkValue *father, INTER_FUNCTIONSIG_CORE);
+void iterBaseClassFunc(NameFunc *list, LinkValue *father, INTER_FUNCTIONSIG_CORE);
 Value *makeBaseChildClass(Value *inherit, Inter *inter);
 bool checkIndex(vnum *index, const vnum *size, INTER_FUNCTIONSIG_NOT_ST);
 bool checkSlice(vnum *first, vnum *second, const vnum *stride, vnum size, INTER_FUNCTIONSIG_NOT_ST);
+void addBaseClassVar(char *name, LinkValue *obj, LinkValue *belong, Inter *inter);
 #endif //VIRTUALMATH___OFUNC_H

+ 2 - 0
VirtulMathCore/ofunc/include/function.h

@@ -1,5 +1,7 @@
 #ifndef VIRTUALMATH_FUNCTION_H
 #define VIRTUALMATH_FUNCTION_H
 void registeredFunction(REGISTERED_FUNCTIONSIG);
+void functionPresetting(LinkValue *func, LinkValue **func_new, LinkValue **func_init, Inter *inter);
+void functionPresettingLast(LinkValue *func, LinkValue *func_new, LinkValue *func_init, Inter *inter);
 void makeBaseFunction(Inter *inter);
 #endif //VIRTUALMATH_FUNCTION_H

+ 1 - 0
VirtulMathCore/ofunc/include/str.h

@@ -2,4 +2,5 @@
 #define VIRTUALMATH_STR_H
 void registeredStr(REGISTERED_FUNCTIONSIG);
 void makeBaseStr(Inter *inter);
+void strFunctionPresetting(LinkValue *func, LinkValue *func_new, LinkValue *func_init, Inter *inter);
 #endif //VIRTUALMATH_STR_H

+ 65 - 9
VirtulMathCore/ofunc/src/__ofunc.c

@@ -1,32 +1,70 @@
 #include "__ofunc.h"
 
-LinkValue *registeredFunctionCore(OfficialFunction of, char *name, LinkValue *belong, INTER_FUNCTIONSIG_CORE) {
-    LinkValue *value = makeLinkValue(makeCFunctionValue(of, var_list, inter), belong, inter);
-    addStrVar(name, false, true, value, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+LinkValue *registeredFunctionCore(OfficialFunction of, char *name, INTER_FUNCTIONSIG_NOT_ST) {
+    LinkValue *value = NULL;
+    makeCFunctionValue(of, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    value = result->value;
+    result->value = NULL;
+    freeResult(result);
+    addStrVar(name, false, true, value, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    gc_freeTmpLink(&value->gc_status);
     return value;
 }
 
-void iterNameFunc(NameFunc list[], LinkValue *father, INTER_FUNCTIONSIG_CORE){
+bool iterNameFunc(NameFunc *list, INTER_FUNCTIONSIG_NOT_ST){
+    setResultCore(result);
     for (PASS; list->of != NULL; list++) {
-        LinkValue *value = registeredFunctionCore(list->of, list->name, father, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+        LinkValue *value = registeredFunctionCore(list->of, list->name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        if (!CHECK_RESULT(result))
+            return false;
         value->value->data.function.function_data.pt_type = list->type;
+        freeResult(result);
     }
+    return true;
 }
 
-void iterClassFunc(NameFunc list[], LinkValue *father, INTER_FUNCTIONSIG_CORE){
-    VarList *object_backup = father->value->object.var->next;
-    VarList *object_var = father->value->object.var;
+bool iterClassFunc(NameFunc *list, INTER_FUNCTIONSIG_NOT_ST){
+    VarList *object_var = belong->value->object.var;
+    VarList *object_backup = object_var->next;
     enum FunctionPtType bak = inter->data.default_pt_type;
+    bool return_ = true;
+
+    setResultCore(result);
     object_var->next = var_list;
     inter->data.default_pt_type = object_free_;
+
     gc_freeze(inter, object_backup, NULL, true);
     for (PASS; list->of != NULL; list++) {
-        LinkValue *value = registeredFunctionCore(list->of, list->name, father, CALL_INTER_FUNCTIONSIG_CORE(object_var));
+        LinkValue *value = registeredFunctionCore(list->of, list->name, CALL_INTER_FUNCTIONSIG_NOT_ST(object_var, result, belong));
+        if (!CHECK_RESULT(result)) {
+            return_ = false;
+            break;
+        }
         value->value->data.function.function_data.pt_type = list->type;
+        freeResult(result);
     }
     gc_freeze(inter, object_backup, NULL, false);
+
     object_var->next = object_backup;
     inter->data.default_pt_type = bak;
+
+    return return_;
+}
+
+void iterBaseNameFunc(NameFunc *list, LinkValue *father, INTER_FUNCTIONSIG_CORE){
+    Result result;
+    setResultCore(&result);
+    if (!iterNameFunc(list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &result, father)))
+        printError(&result, inter, true);
+    freeResult(&result);
+}
+
+void iterBaseClassFunc(NameFunc *list, LinkValue *father, INTER_FUNCTIONSIG_CORE){
+    Result result;
+    setResultCore(&result);
+    if (!iterClassFunc(list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &result, father)))
+        printError(&result, inter, true);
+    freeResult(&result);
 }
 
 Value *makeBaseChildClass(Value *inherit, Inter *inter) {
@@ -76,3 +114,21 @@ bool checkSlice(vnum *first, vnum *second, const vnum *stride, vnum size, INTER_
     }
     return true;
 }
+
+void addBaseClassVar(char *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));
+    if (!RUN_TYPE(result.type))
+        printError(&result, inter, true);
+    freeResult(&result);
+}
+
+void newObjectSettingPresetting(LinkValue *func, LinkValue *name, Inter *inter) {
+    Result result;
+    setResultCore(&result);
+    newObjectSetting(name, 0, "sys", func, &result, inter);
+    if (RUN_TYPE(result.type))
+        printError(&result, inter, true);
+    freeResult(&result);
+}

+ 39 - 10
VirtulMathCore/ofunc/src/bool.c

@@ -1,11 +1,37 @@
 #include "__ofunc.h"
 
+ResultType bool_new(OFFICAL_FUNCTIONSIG){
+    LinkValue *value = NULL;
+    ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
+                           {.must=-1}};
+    int status = 1;
+    arg = parserValueArgument(ap, arg, &status, NULL);
+    if (status != 1){
+        setResultError(E_ArgumentException, FEW_ARG, 0, "bool.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return error_return;
+    }
+
+    setResultCore(result);
+    value = make_new(inter, belong, ap[0].value);
+    value->value->type = bool_;
+    value->value->data.bool_.bool_ = false;
+    switch (init_new(value, arg, "bool.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+        case 1:
+            freeResult(result);
+            setResultOperation(result, value);
+            break;
+        default:
+            break;
+    }
+    return result->type;
+}
+
 ResultType bool_init(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
-                           {.type=only_value, .must=1, .long_arg=false},
+                           {.type=only_value, .must=0, .long_arg=false},
                            {.must=-1}};
     LinkValue *base;
-    bool new;
+    bool new = false;
     setResultCore(result);
     parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
@@ -13,22 +39,25 @@ ResultType bool_init(OFFICAL_FUNCTIONSIG){
     freeResult(result);
 
     base = ap[0].value;
-    new = checkBool(ap[1].value, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    if (!CHECK_RESULT(result))
-        return result->type;
-    base->value->type = bool_;
+    if (ap[1].value != NULL) {
+        new = checkBool(ap[1].value, 0, "bool.init", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        if (!CHECK_RESULT(result))
+            return result->type;
+        freeResult(result);
+    }
     base->value->data.bool_.bool_ = new;
-    setResult(result, inter, belong);
+    setResultBase(result, inter);
     return result->type;
 }
 
 void registeredBool(REGISTERED_FUNCTIONSIG){
     LinkValue *object = makeLinkValue(inter->data.bool_, inter->base_father, inter);
-    NameFunc tmp[] = {{inter->data.object_init, bool_init, object_free_},
+    NameFunc tmp[] = {{inter->data.object_new, bool_new, class_free_},
+                      {inter->data.object_init, bool_init, object_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("bool", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("bool", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 

+ 62 - 12
VirtulMathCore/ofunc/src/dict.c

@@ -1,5 +1,48 @@
 #include "__ofunc.h"
 
+ResultType dict_new(OFFICAL_FUNCTIONSIG){
+    LinkValue *value = NULL;
+    VarList *hash = NULL;
+    ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
+                           {.must=-1}};
+    int status = 1;
+    arg = parserValueArgument(ap, arg, &status, NULL);
+    if (status != 1){
+        setResultError(E_ArgumentException, FEW_ARG, 0, "bool.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return error_return;
+    }
+
+    if (arg != NULL && arg->type == value_arg) {
+        setResultError(E_ArgumentException, "Too many argument", 0, "dict.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return error_return;
+    }
+
+
+    value = make_new(inter, belong, ap[0].value);
+    hash = pushVarList(var_list, inter);
+    value->value->type = dict;
+    value->value->data.dict.size = 0;
+    value->value->data.dict.dict = hash->hashtable;
+
+    gc_addTmpLink(&value->gc_status);
+    argumentToVar(&arg, &value->value->data.dict.size, CALL_INTER_FUNCTIONSIG_NOT_ST(hash, result, belong));
+    gc_freeTmpLink(&value->gc_status);
+    popVarList(hash);
+
+    freeResult(result);
+    switch (init_new(value, NULL, "dict.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+        case 1:
+            freeResult(result);
+            setResultOperation(result, value);
+            break;
+        default:
+            break;
+    }
+    freeResult(result);
+    setResultOperation(result, value);
+    return result->type;
+}
+
 ResultType dict_down(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.type=only_value, .must=1, .long_arg=false},
@@ -87,8 +130,6 @@ ResultType dict_keys(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.must=-1}};
     Argument *list = NULL;
-    Argument *backup = NULL;
-    LinkValue *element = NULL;
     setResultCore(result);
     parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
@@ -103,10 +144,8 @@ ResultType dict_keys(OFFICAL_FUNCTIONSIG){
         for (PASS; tmp != NULL; tmp = tmp->next)
             list = connectValueArgument(copyLinkValue(tmp->name_, inter), list);
     }
-    backup = list;
-    element = makeLinkValue(makeListValue(&list, inter, value_list), belong, inter);
-    setResultOperationBase(result, element);
-    freeArgument(backup, true);
+    makeListValue(list, 0, "dict", value_list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    freeArgument(list, true);
     return result->type;
 }
 
@@ -157,12 +196,12 @@ ResultType dictRepoStrCore(OFFICAL_FUNCTIONSIG, bool is_repo){
         if (!CHECK_RESULT(result))
             return result->type;
         if (again_) {
-            setResultOperation(result, makeLinkValue(makeStringValue("{...}", inter), belong, inter));
+            makeStringValue("{...}", 0, "dict.repo", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             return result->type;
         }
     }
 
-    addAttributes(is_repo ? "repo_again" : "str_again", false, makeLinkValue(makeBoolValue(true, inter), belong, inter), ap[0].value, inter);
+    setBoolAttrible(true, is_repo ? "repo_again" : "str_again", 0, "dict.repo", ap[0].value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     repo = memStrcpy("{");
     for (int i = 0, count = 0; i < MAX_SIZE; i++) {
         for (Var *var = value->data.dict.dict->hashtable[i]; var != NULL; var = var->next, count++) {
@@ -186,11 +225,21 @@ ResultType dictRepoStrCore(OFFICAL_FUNCTIONSIG, bool is_repo){
         }
     }
 
+    freeResult(result);
     repo = memStrcat(repo, "}", true, false);
-    setResultOperation(result, makeLinkValue(makeStringValue(repo, inter), belong, inter));
+    makeStringValue(repo, 0, "dict.repo", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
     return_:
-    addAttributes(is_repo ? "repo_again" : "str_again", false, makeLinkValue(makeBoolValue(false, inter), belong, inter), ap[0].value, inter);
+    {
+        Result tmp;
+        setResultCore(&tmp);
+        setBoolAttrible(false, is_repo ? "repo_again" : "str_again", 0, "dict.repo", ap[0].value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &tmp, belong));
+        if (!RUN_TYPE(tmp.type)) {
+            freeResult(result);
+            *result = tmp;
+        } else
+            freeResult(&tmp);
+    }
     memFree(repo);
     return result->type;
 }
@@ -206,6 +255,7 @@ ResultType dict_str(OFFICAL_FUNCTIONSIG){
 void registeredDict(REGISTERED_FUNCTIONSIG){
     LinkValue *object = makeLinkValue(inter->data.dict, inter->base_father, inter);
     NameFunc tmp[] = {{"keys", dict_keys, object_free_},
+                      {inter->data.object_new, dict_new, class_free_},
                       {inter->data.object_down, dict_down, object_free_},
                       {inter->data.object_iter, dict_iter, object_free_},
                       {inter->data.object_repo, dict_repo, object_free_},
@@ -214,8 +264,8 @@ void registeredDict(REGISTERED_FUNCTIONSIG){
                       {inter->data.object_down_del, dict_down_del, object_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("dict", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("dict", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 

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

@@ -55,8 +55,11 @@ ResultType dictiter_init(OFFICAL_FUNCTIONSIG){
         gc_freeTmpLink(&list->gc_status);
         gc_freeTmpLink(&listiter_class->gc_status);
     }
-    addAttributes("__list", false, list_iter, ap[0].value, inter);
-    addAttributes("__dict", false, ap[1].value, ap[0].value, inter);
+    freeResult(result);
+    if (addAttributes("__list", false, list_iter, 0, "dictiter.init", ap[0].value, result, inter)) {
+        freeResult(result);
+        addAttributes("__dict", false, ap[1].value, 0, "dictiter.init", ap[0].value, result, inter);
+    }
     gc_freeTmpLink(&list_iter->gc_status);
     setResult(result, inter, belong);
     return result->type;
@@ -114,8 +117,8 @@ void registeredDictIter(REGISTERED_FUNCTIONSIG){
                       {inter->data.object_down, dictiter_down, object_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("dictiter", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("dictiter", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 

+ 6 - 10
VirtulMathCore/ofunc/src/error_.c

@@ -1,16 +1,12 @@
 #include "__ofunc.h"
 
+
 static Value *makeException(Value *father, Inter *inter){
     Value *exc = makeBaseChildClass(father, inter);
     gc_addStatementLink(&exc->gc_status);
     return exc;
 }
 
-static void addException(char *name, Value *exc, LinkValue *belong, Inter *inter){
-    addStrVar(name, false, true, makeLinkValue(exc, inter->base_father, inter),
-              belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-}
-
 ResultType base_exception_init(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.type=name_value, .name="message", .must=0, .long_arg=false},
@@ -20,8 +16,8 @@ ResultType base_exception_init(OFFICAL_FUNCTIONSIG){
     if (!CHECK_RESULT(result))
         return result->type;
     freeResult(result);
-    addAttributes(inter->data.object_message, false, ap[1].value, ap[0].value, inter);
-    setResultBase(result, inter, belong);
+    if (addAttributes(inter->data.object_message, false, ap[1].value, 0, "BaseException.init", ap[0].value, result, inter))
+        setResult(result, inter, belong);
     return result->type;
 }
 
@@ -53,12 +49,12 @@ void registeredExcIter(REGISTERED_FUNCTIONSIG){
         NameFunc tmp[] = {{"__init__", base_exception_init, object_free_},
                           {NULL, NULL}};
         gc_addTmpLink(&object->gc_status);
-        addStrVar("BaseException", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-        iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+        addBaseClassVar("BaseException", object, belong, inter);
+        iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
         gc_freeTmpLink(&object->gc_status);
     }
     for (int i=0; setList[i].name != NULL; i++)
-        addException(setList[i].name, setList[i].value, belong, inter);
+        addBaseClassVar(setList[i].name, makeLinkValue(setList[i].value, inter->base_father, inter), belong, inter);
 }
 
 void makeExcIter(Inter *inter){

+ 65 - 12
VirtulMathCore/ofunc/src/function.c

@@ -1,33 +1,68 @@
 #include "__ofunc.h"
 
+static void setFunctionData(Value *value, Inter *inter) {
+    value->data.function.function_data.pt_type = inter->data.default_pt_type;
+}
+
+ResultType function_new(OFFICAL_FUNCTIONSIG){
+    LinkValue *value = NULL;
+    ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
+                           {.must=-1}};
+    int status = 1;
+    setResultCore(result);
+    arg = parserValueArgument(ap, arg, &status, NULL);
+    if (status != 1){
+        setResultError(E_ArgumentException, FEW_ARG, 0, "function.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return error_return;
+    }
+
+    {
+        Inherit *object_father = getInheritFromValue(inter->data.function, inter);
+        VarList *new_var = copyVarList(var_list, false, inter);
+        Value *new_object = makeObject(inter, NULL, new_var, object_father);
+        value = makeLinkValue(new_object, belong, inter);
+    }
+
+    value->value->type = function;
+    value->value->data.function.type = vm_function;
+    value->value->data.function.function = NULL;
+    value->value->data.function.pt = NULL;
+    value->value->data.function.of = NULL;
+    setFunctionData(value->value, inter);
+
+    switch (init_new(value, arg, "function.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+        case 1:
+            freeResult(result);
+            setResultOperation(result, value);
+            break;
+        default:
+            break;
+    }
+    return result->type;
+}
+
+
+// TODO-szh 函数执行的时候,function的st为NULL的时候, 直接返回null
 ResultType function_init(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.type=only_value, .must=0, .long_arg=false},
                            {.must=-1}};
-    LinkValue *base;
-    LinkValue *func_return;
     setResultCore(result);
     parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         return result->type;
     freeResult(result);
-
-    base = ap[0].value;
-    func_return = ap[1].value;
-    if (func_return == NULL)
-        func_return = makeLinkValue(makeNoneValue(inter), belong, inter);
-    makeVMFunctionFromValue(base->value, func_return, 0, "sys", inter);
+    // TODO-szh 添加操作行为
     setResult(result, inter, belong);
     return result->type;
 }
 
 void registeredFunction(REGISTERED_FUNCTIONSIG){
     LinkValue *object = makeLinkValue(inter->data.function, inter->base_father, inter);
-    NameFunc tmp[] = {{inter->data.object_init, function_init, object_free_},
-                      {NULL, NULL}};
+    NameFunc tmp[] = {{NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("function", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("function", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 
@@ -36,3 +71,21 @@ void makeBaseFunction(Inter *inter){
     gc_addStatementLink(&function->gc_status);
     inter->data.function = function;
 }
+
+void functionPresetting(LinkValue *func, LinkValue **func_new, LinkValue **func_init, Inter *inter) {
+    *func_new = makeCFunctionFromOf(function_new, func, function_new, function_init, inter->base_father, inter->var_list, inter);
+    *func_init = makeCFunctionFromOf(function_init, func, function_new, function_init, inter->base_father, inter->var_list, inter);
+    (*func_new)->value->data.function.function_data.pt_type = class_free_;
+    (*func_init)->value->data.function.function_data.pt_type = object_free_;
+}
+
+void functionPresettingLast(LinkValue *func, LinkValue *func_new, LinkValue *func_init, Inter *inter) {
+    Result result;
+    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));
+    freeResult(&result);
+    addStrVar(inter->data.object_init, false, true, func_init, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(object_var, &result, func));
+    freeResult(&result);
+}

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

@@ -47,7 +47,7 @@ ResultType vm_input(OFFICAL_FUNCTIONSIG){
     while ((ch = fgetc(inter->data.inter_stdin)) != '\n' && ch != EOF)
         str = memStrCharcpy(str, 1, true, true, ch);
 
-    setResultOperationBase(result, makeLinkValue(makeStringValue(str, inter), belong, inter));
+    makeStringValue(str, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     memFree(str);
     return result->type;
 }
@@ -56,5 +56,5 @@ void registeredIOFunction(REGISTERED_FUNCTIONSIG){
     NameFunc tmp[] = {{"print", vm_print, free_},
                       {"input", vm_input, free_},
                       {NULL, NULL}};
-    iterNameFunc(tmp, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    iterBaseNameFunc(tmp, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
 }

+ 66 - 16
VirtulMathCore/ofunc/src/list.c

@@ -1,5 +1,47 @@
 #include "__ofunc.h"
 
+ResultType tuple_list_newCore(OFFICAL_FUNCTIONSIG, enum ListType type){
+    LinkValue *value = NULL;
+    ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
+                           {.type=only_value, .must=0, .long_arg=true},
+                           {.must=-1}};
+    setResultCore(result);
+    parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    if (!CHECK_RESULT(result))
+        return result->type;
+    freeResult(result);
+
+    value = make_new(inter, belong, ap[0].value);
+    value->value->type = list;
+    value->value->data.list.type = type;
+    value->value->data.list.list = NULL;
+    value->value->data.list.size = 0;
+
+    for (Argument *at = ap[1].arg; at != NULL && at->type == value_arg; at = at->next) {
+        value->value->data.list.size++;
+        value->value->data.list.list = memRealloc(value->value->data.list.list, value->value->data.list.size * sizeof(LinkValue *));
+        value->value->data.list.list[value->value->data.list.size - 1] = at->data.value;
+    }
+
+    switch (init_new(value, NULL, "list.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+        case 1:
+            freeResult(result);
+            setResultOperation(result, value);
+            break;
+        default:
+            break;
+    }  // TODO-szh 提取成函数
+    return result->type;
+}
+
+ResultType tuple_new(OFFICAL_FUNCTIONSIG) {
+    return tuple_list_newCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), value_tuple);
+}
+
+ResultType list_new(OFFICAL_FUNCTIONSIG) {
+    return tuple_list_newCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), value_list);
+}
+
 ResultType list_slice(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.type=only_value, .must=1, .long_arg=false},
@@ -39,16 +81,12 @@ ResultType list_slice(OFFICAL_FUNCTIONSIG){
 
     {
         Argument *new_list = NULL;
-        Argument *back_up = NULL;
-        LinkValue *new = NULL;
         for (vnum i = stride > 0 ? first : second; stride > 0 ? (i < second) : (i > first); i += stride) {
             LinkValue *element = ap[0].value->value->data.list.list[i];
             new_list = connectValueArgument(element, new_list);
         }
-        back_up = new_list;
-        new = makeLinkValue(makeListValue(&new_list, inter, ap[0].value->value->data.list.type), belong, inter);
-        setResultOperationBase(result, new);
-        freeArgument(back_up, true);
+        makeListValue(new_list, 0, "list.slice", value_list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        freeArgument(new_list, true);
     }
     return result->type;
 }
@@ -338,12 +376,12 @@ ResultType listRepoStrCore(OFFICAL_FUNCTIONSIG, bool is_repo){
         if (!CHECK_RESULT(result))
             return result->type;
         if (again_) {
-            setResultOperation(result, makeLinkValue(makeStringValue(lt == value_list ? "[...]" : "(...)", inter), belong, inter));
+            makeStringValue(lt == value_list ? "[...]" : "(...)", 0, "list.repo", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             return result->type;
         }
     }
 
-    addAttributes(is_repo ? "repo_again" : "str_again", false, makeLinkValue(makeBoolValue(true, inter), belong, inter), ap[0].value, inter);
+    setBoolAttrible(true, is_repo ? "repo_again" : "str_again", 0, "list.repo", ap[0].value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (lt == value_list)
         repo = memStrcpy("[");
     else
@@ -362,10 +400,20 @@ ResultType listRepoStrCore(OFFICAL_FUNCTIONSIG, bool is_repo){
         repo = memStrcat(repo, "]", true, false);
     else
         repo = memStrcat(repo, ")", true, false);
-    setResultOperation(result, makeLinkValue(makeStringValue(repo, inter), belong, inter));
 
+    freeResult(result);
+    makeStringValue(repo, 0, "list.repo", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return_:
-    addAttributes(is_repo ? "repo_again" : "str_again", false, makeLinkValue(makeBoolValue(false, inter), belong, inter), ap[0].value, inter);
+    {
+        Result tmp;
+        setResultCore(&tmp);
+        setBoolAttrible(false, is_repo ? "repo_again" : "str_again", 0, "list.repo", ap[0].value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, &tmp, belong));
+        if (!RUN_TYPE(tmp.type)) {
+            freeResult(result);
+            *result = tmp;
+        } else
+            freeResult(&tmp);
+    }
     memFree(repo);
     return result->type;
 }
@@ -381,7 +429,8 @@ ResultType list_str(OFFICAL_FUNCTIONSIG){
 void registeredList(REGISTERED_FUNCTIONSIG){
     {
         LinkValue *object = makeLinkValue(inter->data.tuple, inter->base_father, inter);
-        NameFunc tmp[] = {{inter->data.object_down, list_down, object_free_},
+        NameFunc tmp[] = {{inter->data.object_new, tuple_new, class_free_},
+                          {inter->data.object_down, list_down, object_free_},
                           {inter->data.object_slice, list_slice, object_free_},
                           {inter->data.object_iter, list_iter, object_free_},
                           {inter->data.object_repo, list_repo, object_free_},
@@ -390,19 +439,20 @@ void registeredList(REGISTERED_FUNCTIONSIG){
                           {inter->data.object_slice_del, list_slice_del, object_free_},
                           {NULL, NULL}};
         gc_addTmpLink(&object->gc_status);
-        addStrVar("tuple", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-        iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+        addBaseClassVar("tuple", object, belong, inter);
+        iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
         gc_freeTmpLink(&object->gc_status);
     }
 
     {
         LinkValue *object = makeLinkValue(inter->data.list, inter->base_father, inter);
-        NameFunc tmp[] = {{inter->data.object_down_assignment, list_down_assignment, object_free_},
+        NameFunc tmp[] = {{inter->data.object_new, list_new, class_free_},
+                          {inter->data.object_down_assignment, list_down_assignment, object_free_},
                           {inter->data.object_slice_assignment, list_slice_assignment, object_free_},
                           {NULL, NULL}};
         gc_addTmpLink(&object->gc_status);
-        addStrVar("list", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-        iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+        addBaseClassVar("list", object, belong, inter);
+        iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
         gc_freeTmpLink(&object->gc_status);
     }
 }

+ 15 - 6
VirtulMathCore/ofunc/src/listiter.c

@@ -15,9 +15,17 @@ ResultType listiter_init(OFFICAL_FUNCTIONSIG){
         return error_return;
     }
 
-    index = makeLinkValue(makeNumberValue(0, inter), ap[0].value, inter);
-    addAttributes("__list", false, ap[1].value, ap[0].value, inter);
-    addAttributes("__index", false, index, ap[0].value, inter);
+    index = makeLinkValue(makeNumberValue(0, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)), ap[0].value, inter);
+    if (!CHECK_RESULT(result))
+        return result->type;
+
+    freeResult(result);
+    if (addAttributes("__list", false, ap[1].value, 0, "listiter.init", ap[0].value, result, inter)) {
+        freeResult(result);
+        addAttributes("__index", false, index, 0, "listiter.init", ap[0].value, result, inter);
+    }
+
+    setResult(result, inter, belong);
     return result->type;
 }
 
@@ -49,7 +57,8 @@ ResultType listiter_next(OFFICAL_FUNCTIONSIG){
         setResultError(E_StopIterException, "Stop Iter", 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     else {
         index->value->data.num.num ++;
-        addAttributes("__index", false, index, ap[0].value, inter);
+        if (addAttributes("__index", false, index, 0, "listiter.next", ap[0].value, result, inter))
+            setResult(result, inter, belong);
     }
     return result->type;
 }
@@ -60,8 +69,8 @@ void registeredListIter(REGISTERED_FUNCTIONSIG){
                       {inter->data.object_next, listiter_next, object_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("listiter", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("listiter", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 

+ 36 - 6
VirtulMathCore/ofunc/src/num.c

@@ -1,8 +1,34 @@
 #include "__ofunc.h"
 
+ResultType num_new(OFFICAL_FUNCTIONSIG){
+    LinkValue *value = NULL;
+    ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
+                           {.must=-1}};
+    int status = 1;
+    arg = parserValueArgument(ap, arg, &status, NULL);
+    if (status != 1){
+        setResultError(E_ArgumentException, FEW_ARG, 0, "num", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return error_return;
+    }
+
+    setResultCore(result);
+    value = make_new(inter, belong, ap[0].value);
+    value->value->type = number;
+    value->value->data.num.num = 0;
+    switch (init_new(value, arg, "num", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+        case 1:
+            freeResult(result);
+            setResultOperation(result, value);
+            break;
+        default:
+            break;
+    }
+    return result->type;
+}
+
 ResultType num_init(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
-                           {.type=name_value, .name="num", .must=1, .long_arg=false},
+                           {.type=name_value, .name="num", .must=0, .long_arg=false},
                            {.must=-1}};
     LinkValue *base = NULL;
     setResultCore(result);
@@ -12,7 +38,8 @@ ResultType num_init(OFFICAL_FUNCTIONSIG){
     freeResult(result);
 
     base = ap[0].value;
-    base->value->type = number;
+    if (ap[1].value == NULL)
+        goto return_;
     switch (ap[1].value->value->type){
         case number:
             base->value->data.num.num = ap[1].value->value->data.num.num;
@@ -31,17 +58,20 @@ ResultType num_init(OFFICAL_FUNCTIONSIG){
             setResultError(E_TypeException, ERROR_INIT(num), 0, "num", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             return result->type;
     }
-    setResultBase(result, inter, belong);
+
+    return_:
+    setResultBase(result, inter);
     return result->type;
 }
 
 void registeredNum(REGISTERED_FUNCTIONSIG){
     LinkValue *object = makeLinkValue(inter->data.num, inter->base_father, inter);
-    NameFunc tmp[] = {{inter->data.object_init, num_init, object_free_},
+    NameFunc tmp[] = {{inter->data.object_new, num_new, class_free_},
+                      {inter->data.object_init, num_init, object_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("num", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("num", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 

+ 5 - 25
VirtulMathCore/ofunc/src/object.c

@@ -1,38 +1,19 @@
 #include "__ofunc.h"
 
-//ResultType object_new(OFFICAL_FUNCTIONSIG){
-//    LinkValue *value = NULL;
-//    setResultCore(result);
-//    ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
-//                           {.must=-1}};
-//    int status = 1;
-//    arg = parserValueArgument(ap, arg, &status, NULL);
-//    if (status != 1){
-//        setResultError(E_ArgumentException, FEW_ARG, 0, "object", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-//        return error_return;
-//    }
-//
-//    value = make_new(inter, belong, ap[0].value);
-//    init_new(value, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-//    return result->type;
-//}
-
 ResultType object_new(OFFICAL_FUNCTIONSIG){
     LinkValue *value = NULL;
-    LinkValue *_init_ = NULL;
     setResultCore(result);
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.must=-1}};
     int status = 1;
     arg = parserValueArgument(ap, arg, &status, NULL);
     if (status != 1){
-        setResultError(E_ArgumentException, FEW_ARG, 0, "object", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_ArgumentException, FEW_ARG, 0, "object.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return error_return;
     }
 
     value = make_new(inter, belong, ap[0].value);
-
-    switch (init_new(value, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+    switch (init_new(value, arg, "object.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
         case 1:
             freeResult(result);
             setResultOperation(result, value);
@@ -76,9 +57,8 @@ ResultType objectRepoStrCore(OFFICAL_FUNCTIONSIG, bool is_repo){
     len = memStrlen(name) + 30;
     repo = memCalloc(len, sizeof(char ));
     snprintf(repo, len, "(%s: %s on %p)", type, name, ap[0].value->value);
-    setResultOperationBase(result, makeLinkValue(makeStringValue(repo, inter), belong, inter));
+    makeStringValue(repo, 0, "object.repo", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     memFree(repo);
-
     return result->type;
 }
 
@@ -97,8 +77,8 @@ void registeredObject(REGISTERED_FUNCTIONSIG){
                       {inter->data.object_str,  object_str,  all_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("object", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("object", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 

+ 21 - 13
VirtulMathCore/ofunc/src/pass.c

@@ -1,28 +1,36 @@
 #include "__ofunc.h"
 
-ResultType pass_init(OFFICAL_FUNCTIONSIG){
+ResultType pass_new(OFFICAL_FUNCTIONSIG){
+    LinkValue *value = NULL;
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
                            {.must=-1}};
-    LinkValue *base;
+    int status = 1;
     setResultCore(result);
-    parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    if (!CHECK_RESULT(result))
-        return result->type;
-    freeResult(result);
-
-    base = ap[0].value;
-    base->value->type = pass_;
-    setResult(result, inter, belong);
+    arg = parserValueArgument(ap, arg, &status, NULL);
+    if (status != 1){
+        setResultError(E_ArgumentException, FEW_ARG, 0, "pass.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return error_return;
+    }
+    value = make_new(inter, belong, ap[0].value);
+    value->value->type = pass_;
+    switch (init_new(value, arg, "pass.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+        case 1:
+            freeResult(result);
+            setResultOperation(result, value);
+            break;
+        default:
+            break;
+    }
     return result->type;
 }
 
 void registeredEllipisis(REGISTERED_FUNCTIONSIG){
     LinkValue *object = makeLinkValue(inter->data.pass_, inter->base_father, inter);
-    NameFunc tmp[] = {{inter->data.object_init, pass_init, object_free_},
+    NameFunc tmp[] = {{inter->data.object_new, pass_new, class_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("ellipsis", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("ellipsis", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 

+ 113 - 20
VirtulMathCore/ofunc/src/str.c

@@ -1,8 +1,33 @@
 #include "__ofunc.h"
 
+ResultType str_new(OFFICAL_FUNCTIONSIG){
+    LinkValue *value = NULL;
+    ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
+                           {.must=-1}};
+    int status = 1;
+    arg = parserValueArgument(ap, arg, &status, NULL);
+    if (status != 1){
+        setResultError(E_ArgumentException, FEW_ARG, 0, "str.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return error_return;
+    }
+    setResultCore(result);
+    value = make_new(inter, belong, ap[0].value);
+    value->value->type = string;
+    value->value->data.str.str = memStrcpy("");
+    switch (init_new(value, arg, "str.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
+        case 1:
+            freeResult(result);
+            setResultOperation(result, value);
+            break;
+        default:
+            break;
+    }
+    return result->type;
+}
+
 ResultType str_init(OFFICAL_FUNCTIONSIG){
     ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
-                           {.type=only_value, .must=1, .long_arg=false},
+                           {.type=only_value, .must=0, .long_arg=false},
                            {.must=-1}};
     LinkValue *base;
     char *str = NULL;
@@ -13,12 +38,14 @@ ResultType str_init(OFFICAL_FUNCTIONSIG){
     freeResult(result);
 
     base = ap[0].value;
-    str = getRepoStr(ap[1].value, false, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    if (!CHECK_RESULT(result))
-        return result->type;
-    base->value->type = string;
-    base->value->data.str.str = memStrcpy(str);
-    setResult(result, inter, belong);
+    if (ap[1].value != NULL){
+        str = getRepoStr(ap[1].value, false, 0, "str.init", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        if (!CHECK_RESULT(result))
+            return result->type;
+        memFree(base->value->data.str.str);
+        base->value->data.str.str = memStrcpy(str);
+    }
+    setResultBase(result, inter);
     return result->type;
 }
 
@@ -63,7 +90,7 @@ ResultType str_slice(OFFICAL_FUNCTIONSIG){
         char *str = NULL;
         for (vnum i = stride > 0 ? first : second; stride > 0 ? (i < second) : (i > first); i += stride)
             str = memStrCharcpy(str, 1, true, true, ap[0].value->value->data.str.str[i]);
-        setResultOperationBase(result, makeLinkValue(makeStringValue(str, inter), belong, inter));
+        makeStringValue(str, 0, "str.slice", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         memFree(str);
     }
     return result->type;
@@ -96,7 +123,7 @@ ResultType str_down(OFFICAL_FUNCTIONSIG){
     if (!checkIndex(&index, &size, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
         return result->type;
     *element = ap[0].value->value->data.str.str[index];
-    setResultOperationBase(result, makeLinkValue(makeStringValue(element, inter), belong, inter));
+    makeStringValue(element, 0, "str.down", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return result->type;
 }
 
@@ -118,19 +145,16 @@ ResultType str_to_list(OFFICAL_FUNCTIONSIG){
 
     {
         Argument *new_list = NULL;
-        Argument *back_up = NULL;
-        LinkValue *new = NULL;
         for (vnum i = 0; i < size; i ++) {
             char str[2] = {};
             str[0] = ap[0].value->value->data.str.str[i];
-            new_list = connectValueArgument(makeLinkValue(makeStringValue(str, inter), belong, inter), new_list);
+            makeStringValue(str, 0, "str.to_list", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            new_list = connectValueArgument(result->value, new_list);
+            freeResult(result);
         }
-        back_up = new_list;
-        new = makeLinkValue(makeListValue(&new_list, inter, ap[0].value->value->data.list.type), belong, inter);
-        setResultOperationBase(result, new);
-        freeArgument(back_up, true);
+        makeListValue(new_list, 0, "str", value_list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        freeArgument(new_list, true);
     }
-
     return result->type;
 }
 
@@ -165,17 +189,86 @@ ResultType str_iter(OFFICAL_FUNCTIONSIG){
 void registeredStr(REGISTERED_FUNCTIONSIG){
     LinkValue *object = makeLinkValue(inter->data.str, inter->base_father, inter);
     NameFunc tmp[] = {{"to_list", str_to_list, object_free_},
-                      {inter->data.object_init, str_init, object_free_},
                       {inter->data.object_iter, str_iter, object_free_},
                       {inter->data.object_down, str_down, object_free_},
                       {inter->data.object_slice, str_slice, object_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("str", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("str", object, belong, inter);
     gc_freeTmpLink(&object->gc_status);
 }
 
+LinkValue *callClassOf(LinkValue *obj, Inter *inter, LinkValue *new_func, LinkValue *init_func) {
+    Argument *arg = makeValueArgument(obj);
+    Result result;
+    LinkValue *new_name;
+    setResultCore(&result);
+
+    new_func->value->data.function.of(arg, obj, &result, inter, new_func->value->object.out_var);
+    new_name = result.value;
+    freeResult(&result);
+
+    init_func->value->data.function.of(arg, new_name, &result, inter, init_func->value->object.out_var);
+    freeResult(&result);
+    freeArgument(arg, true);
+
+    return new_name;
+}
+
+LinkValue *makeStrFromOf(LinkValue *str, LinkValue *new, LinkValue *init, char *str_, Inter *inter) {
+    LinkValue *return_;
+    return_ = callClassOf(str, inter, new, init);
+    memFree(return_->value->data.str.str);
+    return_->value->data.str.str = memStrcpy(str_);
+    return return_;
+}
+
+LinkValue *makeFunctionFromValue(LinkValue *func, LinkValue *new, LinkValue *init, OfficialFunction of, LinkValue *belong, VarList *var_list, Inter *inter) {
+    LinkValue *new_func;
+    new_func = callClassOf(func, inter, new, init);
+    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);
+    }
+    new_func->value->object.out_var = copyVarList(var_list, false, inter);
+    new_func->belong = belong;
+    return new_func;
+}
+
+void strFunctionPresetting(LinkValue *func, LinkValue *func_new, LinkValue *func_init, Inter *inter) {
+    Value *str = inter->data.str;
+    LinkValue *obj = makeLinkValue(str, inter->base_father, inter);
+
+    LinkValue *new_func = NULL;
+    LinkValue *new_name = NULL;
+    char *new_name_ = setStrVarName(inter->data.object_new, false, inter);
+
+    LinkValue *init_func = NULL;
+    LinkValue *init_name = NULL;
+    char *init_name_ = setStrVarName(inter->data.object_init, false, inter);
+
+    new_func = makeFunctionFromValue(func, func_new, func_init, str_new, obj, str->object.var, inter);
+    new_func->value->data.function.function_data.pt_type = class_free_;
+    init_func = makeFunctionFromValue(func, func_new, func_init, str_init, obj, str->object.var, inter);
+    init_func->value->data.function.function_data.pt_type = object_free_;
+
+
+    new_name = makeStrFromOf(obj, new_func, init_func, inter->data.object_new, inter);
+    init_name = makeStrFromOf(obj, new_func, init_func, inter->data.object_init, inter);
+
+    addFromVarList(new_name_, new_name, 0, new_func, CALL_INTER_FUNCTIONSIG_CORE(str->object.var));
+    addFromVarList(init_name_, init_name, 0, init_func, CALL_INTER_FUNCTIONSIG_CORE(str->object.var));
+
+    newObjectSettingPresetting(new_func, new_name, inter);
+    newObjectSettingPresetting(init_func, init_name, inter);
+    memFree(new_name_);
+    memFree(init_name_);
+}
+
 void makeBaseStr(Inter *inter){
     Value *str = makeBaseChildClass(inter->data.vobject, inter);
     gc_addStatementLink(&str->gc_status);

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

@@ -114,5 +114,5 @@ void registeredSysFunction(REGISTERED_FUNCTIONSIG){
                       {"simplestaticmethod", vm_allstaticmethod, free_},
                       {"quit", vm_quit, free_},
                       {NULL, NULL}};
-    iterNameFunc(tmp, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    iterBaseNameFunc(tmp, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
 }

+ 18 - 21
VirtulMathCore/ofunc/src/vobject.c

@@ -3,30 +3,30 @@
 typedef void (*base_opt)(LinkValue *, Result *, struct Inter *, VarList *var_list, Value *, Value *);
 
 void vobject_add_base(LinkValue *belong, Result *result, struct Inter *inter, VarList *var_list, Value *left, Value *right) {
-    setResultOperationBase(result, makeLinkValue(NULL, belong, inter));
+    setResultCore(result);
     if (left->type == number && right->type == number)
-        result->value->value = makeNumberValue(left->data.num.num + right->data.num.num, inter);
+        makeNumberValue(left->data.num.num + right->data.num.num, 0, "vobject.add", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     else if(left->type == string && right->type == string){
         char *new_string = memStrcat(left->data.str.str, right->data.str.str, false, false);
-        result->value->value = makeStringValue(new_string, inter);
+        makeStringValue(new_string, 0, "vobject.add", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         memFree(new_string);
     }
     else
-        setResultError(E_TypeException, CUL_ERROR(Add), 0, "vobject", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_TypeException, CUL_ERROR(Add), 0, "vobject.add", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 }
 
 void vobject_sub_base(LinkValue *belong, Result *result, struct Inter *inter, VarList *var_list, Value *left, Value *right) {
-    setResultOperationBase(result, makeLinkValue(NULL, belong, inter));
+    setResultCore(result);
     if (left->type == number && right->type == number)
-        result->value->value = makeNumberValue(left->data.num.num - right->data.num.num, inter);
+        makeNumberValue(left->data.num.num - right->data.num.num, 0, "vobject.sub", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     else
-        setResultError(E_TypeException, CUL_ERROR(Sub), 0, "vobject", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_TypeException, CUL_ERROR(Sub), 0, "vobject.sub", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 }
 
 void vobject_mul_base(LinkValue *belong, Result *result, struct Inter *inter, VarList *var_list, Value *left, Value *right) {
-    setResultOperationBase(result, makeLinkValue(NULL, belong, inter));
+    setResultCore(result);
     if (left->type == number && right->type == number)
-        result->value->value = makeNumberValue(left->data.num.num * right->data.num.num, inter);
+        makeNumberValue(left->data.num.num * right->data.num.num, 0, "vobject.mul", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     else if(left->type == number && right->type == string) {
         Value *tmp = left;
         left = right;
@@ -35,21 +35,21 @@ void vobject_mul_base(LinkValue *belong, Result *result, struct Inter *inter, Va
     }
     else if(left->type == string && right->type == number) mul_str: {
         char *new_string = memStrcpySelf(left->data.str.str, right->data.num.num);
-        result->value->value = makeStringValue(new_string, inter);
+        makeStringValue(new_string, 0, "vobject.mul", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         memFree(new_string);
     }
     else
-        setResultError(E_TypeException, CUL_ERROR(Mul), 0, "vobject", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_TypeException, CUL_ERROR(Mul), 0, "vobject.mul", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 }
 
 void vobject_div_base(LinkValue *belong, Result *result, struct Inter *inter, VarList *var_list, Value *left, Value *right) {
-    setResultOperationBase(result, makeLinkValue(NULL, belong, inter));
+    setResultCore(result);
     if (left->type == number && right->type == number) {
         lldiv_t div_result = lldiv(left->data.num.num, right->data.num.num);
-        result->value->value = makeNumberValue(div_result.quot, inter);
+        makeNumberValue(div_result.quot, 0, "vobject.div", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     }
     else
-        setResultError(E_TypeException, CUL_ERROR(Div), 0, "vobject", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_TypeException, CUL_ERROR(Div), 0, "vobject.div", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 }
 
 ResultType vobject_opt_core(OFFICAL_FUNCTIONSIG, base_opt func){
@@ -70,7 +70,6 @@ ResultType vobject_opt_core(OFFICAL_FUNCTIONSIG, base_opt func){
     right = ap[1].value->value;
 
     func(belong, result, inter, var_list, left, right);
-
     return result->type;
 }
 
@@ -95,7 +94,6 @@ ResultType vobject_bool(OFFICAL_FUNCTIONSIG){
                            {.must=-1}};
     bool result_ = false;
     Value *value = NULL;
-    Value *return_value = NULL;
     setResultCore(result);
     {
         parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
@@ -128,8 +126,7 @@ ResultType vobject_bool(OFFICAL_FUNCTIONSIG){
             setResultError(E_TypeException, CUL_ERROR(bool), 0, "vobject", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             return error_return;
     }
-    return_value = makeBoolValue(result_, inter);
-    setResultOperationBase(result, makeLinkValue(return_value, belong, inter));
+    makeBoolValue(result_, 0, "vobject.bool", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return result->type;
 }
 
@@ -183,7 +180,7 @@ ResultType vobject_repo(OFFICAL_FUNCTIONSIG){
             setResultError(E_TypeException, CUL_ERROR(repo/str), 0, "vobject", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             return error_return;
     }
-    setResultOperationBase(result, makeLinkValue(makeStringValue(repo, inter), belong, inter));
+    makeStringValue(repo, 0, "vobject.repo", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     memFree(repo);
     return result->type;
 }
@@ -199,8 +196,8 @@ void registeredVObject(REGISTERED_FUNCTIONSIG){
                       {inter->data.object_str, vobject_repo, object_free_},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addStrVar("vobject", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
-    iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    addBaseClassVar("vobject", object, belong, inter);
+    iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }
 

+ 1 - 1
VirtulMathCore/parser/grammar.c

@@ -202,6 +202,7 @@ void parserCommand(PASERSSIGNATURE){
         case MATHER_PROTECT:
         case MATHER_PRIVATE:
         case MATHER_PUBLIC:
+        case MATHER_PASSVALUE:
             status = callChildStatement(CALLPASERSSIGNATURE, parserOperation, OPERATION, &st, NULL);
             break;
         default:
@@ -1352,7 +1353,6 @@ void parserBaseValue(PASERSSIGNATURE){
         }
 
         case MATHER_STRING:{
-            Value *tmp_value = makeStringValue(value_token->data.str, inter);
             Statement *tmp = NULL;
             tmp = makeBaseStrValueStatement(value_token->data.str, string_str, value_token->line, pm->file);
             if (*value_token->data.second_str == NUL)

+ 52 - 24
VirtulMathCore/src/__run.c

@@ -19,9 +19,7 @@ ResultType getBaseVarInfo(char **name, int *times, INTER_FUNCTIONSIG){
     freeResult(result);
 
     not_times:
-    value = makeLinkValue(makeStringValue(st->u.base_var.name, inter), belong, inter);
-    setResultOperation(result, value);
-
+    makeStringValue(st->u.base_var.name, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return result->type;
 }
 
@@ -205,7 +203,7 @@ ResultType setFunctionArgument(Argument **arg, LinkValue *function_value, fline
         default:
             break;
     }
-    setResultBase(result, inter, belong);
+    setResultBase(result, inter);
     return result->type;
 }
 
@@ -235,13 +233,25 @@ LinkValue *checkStrVar(char *name, bool free_old, INTER_FUNCTIONSIG_CORE){
     return tmp;
 }
 
-void addStrVar(char *name, bool free_old, bool setting, LinkValue *value, LinkValue *belong, INTER_FUNCTIONSIG_CORE){
+void addStrVar(char *name, bool free_old, bool setting, LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     char *var_name = setStrVarName(name, free_old, inter);
-    LinkValue *name_ = makeLinkValue(makeStringValue(name, inter), belong, inter);
-    addFromVarList(var_name, name_, 0, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
-    if (setting)
-        newObjectSetting(name_, value, inter);
-    memFree(var_name);
+    setResultCore(result);
+
+    makeStringValue(name, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    addFromVarList(var_name, result->value, 0, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    if (!CHECK_RESULT(result))
+        goto return_;
+    else if (setting) {
+        LinkValue *name_value = result->value;
+        result->value = NULL;
+        freeResult(result);
+        newObjectSetting(name_value, line, file, value, result, inter);
+        gc_freeTmpLink(&name_value->gc_status);
+    }
+
+    if (CHECK_RESULT(result))
+        freeResult(result);
+    return_: memFree(var_name);
 }
 
 LinkValue *findAttributes(char *name, bool free_old, LinkValue *value, Inter *inter) {
@@ -251,15 +261,17 @@ LinkValue *findAttributes(char *name, bool free_old, LinkValue *value, Inter *in
     return attr;
 }
 
-void addAttributes(char *name, bool free_old, LinkValue *value, LinkValue *belong, Inter *inter) {
-    addStrVar(name, free_old, false, value, belong, inter, belong->value->object.var);
+bool addAttributes(char *name, bool free_old, LinkValue *value, fline line, char *file, LinkValue *belong, Result *result, Inter *inter) {
+    setResultCore(result);
+    addStrVar(name, free_old, false, value, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(belong->value->object.var, result, belong));
+    return CHECK_RESULT(result);
 }
 
-void newObjectSetting(LinkValue *name, LinkValue *belong, Inter *inter) {
-    addAttributes(inter->data.object_name, false, name, belong, inter);
-    addAttributes(inter->data.object_self, false, belong, belong, inter);
+void newObjectSetting(LinkValue *name, fline line, char *file, LinkValue *belong, Result *result, Inter *inter) {
+    addAttributes(inter->data.object_name, false, name, line, file, belong, result, inter);
+    addAttributes(inter->data.object_self, false, belong, line, file, belong, result, inter);
     if (belong->value->object.inherit != NULL)
-        addAttributes(inter->data.object_father, false, belong->value->object.inherit->value, belong, inter);
+        addAttributes(inter->data.object_father, false, belong->value->object.inherit->value, line, file, belong, result, inter);
 }
 
 
@@ -316,7 +328,7 @@ bool checkBool(LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_S
         else
             return result->value->value->data.bool_.bool_;
     } else {
-        setResultOperationBase(result, makeLinkValue(makeBoolValue(true, inter), belong, inter));
+        makeBoolValue(true, 0, "sys.bool", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return true;
     }
     return false;
@@ -331,7 +343,6 @@ char *getRepoStr(LinkValue *value, bool is_repot, fline line, char *file, INTER_
         callBackCore(_repo_, NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_repo_->gc_status);
         gc_freeTmpLink(&value->gc_status);
-
         if (!CHECK_RESULT(result))
             return NULL;
         else if (result->value->value->type != string){
@@ -380,18 +391,35 @@ LinkValue *make_new(Inter *inter, LinkValue *belong, LinkValue *class){
     return makeLinkValue(new_object, belong, inter);
 }
 
-int init_new(LinkValue *obj, Argument *arg, INTER_FUNCTIONSIG_NOT_ST){
+int init_new(LinkValue *obj, Argument *arg, char *message, INTER_FUNCTIONSIG_NOT_ST){
     LinkValue *_init_ = NULL;
     _init_ = findAttributes(inter->data.object_init, false, obj, inter);
 
     if (_init_ == NULL) {
-        setResultError(E_ArgumentException, MANY_ARG, 0, "object", true,
-                       CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-        return 0;
+        if (arg != NULL) {
+            setResultError(E_ArgumentException, MANY_ARG, 0, message, true,
+                           CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            return 0;
+        } else
+            return 1;
     }
     _init_->belong = obj;
     gc_addTmpLink(&_init_->gc_status);
-    callBackCore(_init_, arg, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, obj));
+    callBackCore(_init_, arg, 0, message, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, obj));
     gc_freeTmpLink(&_init_->gc_status);
     return CHECK_RESULT(result) ? 1 : -1;
-}
+}
+
+bool setBoolAttrible(bool value, char *var, fline line, char *file, LinkValue *obj, INTER_FUNCTIONSIG_NOT_ST) {
+    LinkValue *bool_value = NULL;
+    setResultCore(result);
+    makeBoolValue(value, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    if (!CHECK_RESULT(result))
+        return false;
+    bool_value = result->value;
+    freeResult(result);
+    if (!addAttributes(var, false, bool_value, line, file, obj, result, inter))
+        return false;
+    freeResult(result);
+    return true;
+}

+ 6 - 4
VirtulMathCore/src/include/__run.h

@@ -24,10 +24,11 @@ ResultType setFunctionArgument(struct Argument **arg, LinkValue *function_value,
 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);
-void addStrVar(char *name, bool free_old, bool setting, LinkValue *value, LinkValue *father, INTER_FUNCTIONSIG_CORE);
+void addStrVar(char *name, bool free_old, bool setting, LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
 LinkValue *findAttributes(char *name, bool free_old, LinkValue *value, Inter *inter);
-void addAttributes(char *name, bool free_old, LinkValue *value, LinkValue *belong, Inter *inter);
-void newObjectSetting(LinkValue *name, LinkValue *belong, Inter *inter);
+
+bool addAttributes(char *name, bool free_old, LinkValue *value, fline line, char *file, LinkValue *belong,Result *result, Inter *inter);
+void newObjectSetting(LinkValue *name, fline line, char *file, LinkValue *belong,Result *result, Inter *inter);
 ResultType elementDownOne(LinkValue *element, LinkValue *index, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
 ResultType getIter(LinkValue *value, int status, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
 bool checkBool(LinkValue *value, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
@@ -35,5 +36,6 @@ char *getRepoStr(LinkValue *value, bool is_repot, fline line, char *file, INTER_
 bool is_iterStop(LinkValue *value, Inter *inter);
 bool checkAut(enum ValueAuthority value, enum ValueAuthority base, fline line, char *file, char *name, bool pri_auto, INTER_FUNCTIONSIG_NOT_ST);
 LinkValue *make_new(Inter *inter, LinkValue *belong, LinkValue *class);
-int init_new(LinkValue *obj, Argument *arg, INTER_FUNCTIONSIG_NOT_ST);
+int init_new(LinkValue *obj, Argument *arg, char *message, INTER_FUNCTIONSIG_NOT_ST);
+bool setBoolAttrible(bool value, char *var, fline line, char *file, LinkValue *obj, INTER_FUNCTIONSIG_NOT_ST);
 #endif //VIRTUALMATH___RUN_H

+ 1 - 14
VirtulMathCore/src/inter.c

@@ -2,7 +2,6 @@
 
 Inter *makeInter(char *out, char *error_, char *in, LinkValue *belong) {
     Inter *tmp = memCalloc(1, sizeof(Inter));
-    LinkValue *base_father = NULL;
     tmp->base = NULL;
     tmp->link_base = NULL;
     tmp->hash_base = NULL;
@@ -47,19 +46,7 @@ Inter *makeInter(char *out, char *error_, char *in, LinkValue *belong) {
         tmp->data.is_stdin = true;
     }
 
-    registeredFunctionName(tmp);
-
-    tmp->data.none = makeNoneValue(tmp);
-    gc_addStatementLink(&tmp->data.none->gc_status);
-
-    {
-        Value *global_belong = makeObject(tmp, copyVarList(tmp->var_list, false, tmp), NULL, NULL);
-        base_father = makeLinkValue(global_belong, belong, tmp);
-        gc_addStatementLink(&base_father->gc_status);
-        tmp->base_father = base_father;
-    }
-
-    registeredBaseFunction(base_father, tmp);
+    registeredFunctionName(tmp, belong);
     return tmp;
 }
 

+ 37 - 6
VirtulMathCore/src/ofunc.c

@@ -1,9 +1,6 @@
 #include "__run.h"
 
-static Registered base_func_list[] = {registeredIOFunction,
-                                      registeredSysFunction,
-                                      registeredObject,
-                                      registeredVObject,
+static Registered base_func_list[] = {registeredVObject,
                                       registeredNum,
                                       registeredStr,
                                       registeredBool,
@@ -14,6 +11,9 @@ static Registered base_func_list[] = {registeredIOFunction,
                                       registeredListIter,
                                       registeredDictIter,
                                       registeredExcIter,
+
+                                      registeredSysFunction,
+                                      registeredIOFunction,
                                       NULL};
 
 void registeredBaseFunction(struct LinkValue *father, Inter *inter){
@@ -21,11 +21,20 @@ void registeredBaseFunction(struct LinkValue *father, Inter *inter){
         (*list)(CALL_REGISTERED_FUNCTION(father, inter->var_list));
 }
 
-void registeredFunctionName(Inter *inter){
+void presetting(Inter *inter) {
+    LinkValue *func = makeLinkValue(inter->data.function, inter->base_father, inter);
+    LinkValue *func_new = NULL;
+    LinkValue *func_init = NULL;
+
+    functionPresetting(func, &func_new, &func_init, inter);
+    strFunctionPresetting(func, func_new, func_init, inter);
+    functionPresettingLast(func, func_new, func_init, inter);
+}
+
+void registeredFunctionName(Inter *inter, LinkValue *belong){
     makeBaseObject(inter);
     makeBaseVObject(inter);
     makeBaseNum(inter);
-    makeBaseStr(inter);
     makeBaseBool(inter);
     makeBaseEllipisis(inter);
     makeBaseFunction(inter);
@@ -34,4 +43,26 @@ void registeredFunctionName(Inter *inter){
     makeBaseListIter(inter);
     makeBaseDictIter(inter);
     makeExcIter(inter);
+
+    {
+        Value *global_belong = makeObject(inter, copyVarList(inter->var_list, false, inter), NULL, NULL);
+        LinkValue *base_father = makeLinkValue(global_belong, belong, inter);
+        gc_addStatementLink(&base_father->gc_status);
+        inter->base_father = base_father;
+    }
+
+    makeBaseStr(inter);
+    presetting(inter);
+    registeredObject(inter->base_father, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
+    {
+        Result result;
+        setResultCore(&result);
+        inter->data.none = makeNoneValue(0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(inter->var_list, &result, belong));
+        if (!RUN_TYPE(result.type))
+            printError(&result, inter, true);
+        else
+            gc_addStatementLink(&inter->data.none->gc_status);
+        freeResult(&result);
+    }
+    registeredBaseFunction(inter->base_father, inter);
 }

+ 12 - 6
VirtulMathCore/src/parameter.c

@@ -339,7 +339,7 @@ ResultType parameterFromVar(Parameter **function_ad, VarList *function_var, vnum
         get = true;
 
         if (function->type == kwargs_par){
-            value = makeLinkValue(makeDictValue(NULL, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, NULL, belong)), belong, inter);
+            value = makeLinkValue(makeDictValue(NULL, false, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, NULL, belong)), belong, inter);
             value->value->data.dict.dict = var_list->hashtable;
             value->value->data.dict.size = max - *num;
             *status = true;
@@ -605,14 +605,20 @@ ResultType setParameterCore(fline line, char *file, Argument *call, Parameter *f
                 break;
             }
             case mul_par: {
-                LinkValue *tmp = makeLinkValue(makeListValue(&call, inter, value_tuple), belong, inter);
+                LinkValue *tmp = NULL;
+                makeListValue(call, 0, "sys", value_tuple, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+                for (PASS; call != NULL && call->type == value_arg; call = call->next)
+                    PASS;
+                returnResult(result);
+                freeResult(result);
+
                 assCore(function->data.value, tmp, false, false, CALL_INTER_FUNCTIONSIG_NOT_ST(function_var, result, belong));
                 returnResult(result);
                 function = function->next;
                 break;
             }
             case space_kwargs:{
-                LinkValue *tmp = makeLinkValue(makeDictValue(NULL, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)), belong, inter);
+                LinkValue *tmp = makeLinkValue(makeDictValue(NULL, true, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)), belong, inter);
                 returnResult(result);
                 freeResult(result);
 
@@ -750,7 +756,7 @@ int parserNameArgument(ArgumentParser ap[], Argument *arg, ArgumentParser **bak,
 
     gc_freeze(inter, var_list, NULL, true);
     for (PASS; arg != NULL && arg->type != name_arg; arg = arg->next)
-            PASS;
+        PASS;
     if (arg == NULL) {
         return_ = -3;  // 参数缺失
         goto return_;
@@ -762,7 +768,7 @@ int parserNameArgument(ArgumentParser ap[], Argument *arg, ArgumentParser **bak,
         return_ = -1;
         goto return_;
     }
-    setResultBase(result, inter, belong);
+    setResult(result, inter, belong);
 
     for (PASS; ap->must != -1 && (ap->type == only_name || ap->type == name_value); ap++) {
         int status = parserArgumentVar(ap, inter, tmp);
@@ -790,7 +796,7 @@ Argument *parserArgumentValueCore(Argument *arg, ArgumentParser *ap){
     arg = arg->next;
     if (ap->long_arg)
         for (PASS; arg != NULL && arg->type == value_arg; arg = arg->next, count++)
-                PASS;
+            PASS;
     ap->c_count = count;
     return arg;
 }

+ 29 - 39
VirtulMathCore/src/runcall.c

@@ -57,23 +57,23 @@ ResultType setClass(INTER_FUNCTIONSIG) {
 }
 
 ResultType setFunction(INTER_FUNCTIONSIG) {
-    LinkValue *tmp = NULL;
-    Value *func_value = NULL;
-    VarList *func_out_var = NULL;
+    LinkValue *func = NULL;
     setResultCore(result);
 
-    func_out_var = copyVarList(var_list, false, inter);
-    func_value = makeVMFunctionValue(st->u.set_function.function, st->u.set_function.parameter, func_out_var, inter);
-    tmp = makeLinkValue(func_value, belong, inter);
-    gc_addTmpLink(&tmp->gc_status);
+    makeVMFunctionValue(st->u.set_function.function, st->u.set_function.parameter, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    if (!CHECK_RESULT(result))
+        return result->type;
+    func = result->value;
+    result->value = NULL;
+    freeResult(result);
 
     {
         enum FunctionPtType pt_type_bak = inter->data.default_pt_type;
-        VarList *var_backup = func_value->object.var->next;
+        VarList *var_backup = func->value->object.var->next;
         inter->data.default_pt_type = object_free_;
-        func_value->object.var->next = var_list;
-        functionSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.set_function.first_do, func_value->object.var, result, tmp));
-        func_value->object.var->next = var_backup;
+        func->value->object.var->next = var_list;
+        functionSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.set_function.first_do, func->value->object.var, result, func));
+        func->value->object.var->next = var_backup;
         inter->data.default_pt_type = pt_type_bak;
         if (result->type != yield_return && !CHECK_RESULT(result))
             goto error_;
@@ -81,41 +81,31 @@ ResultType setFunction(INTER_FUNCTIONSIG) {
     }
 
     if (st->u.set_function.decoration != NULL){
-        setDecoration(st->u.set_function.decoration, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setDecoration(st->u.set_function.decoration, func, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         if (!CHECK_RESULT(result))
             goto error_;
-        gc_freeTmpLink(&tmp->gc_status);
-        tmp = result->value;
+        gc_freeTmpLink(&func->gc_status);
+        func = result->value;
         result->value = NULL;
         freeResult(result);
     }
-    assCore(st->u.set_function.name, tmp, false, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    if (!CHECK_RESULT(result))
-        goto error_;
-    setResult(result, inter, belong);
-    gc_freeTmpLink(&tmp->gc_status);
-    return result->type;
+    assCore(st->u.set_function.name, func, false, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    if (CHECK_RESULT(result))
+        setResult(result, inter, belong);
 
     error_:
-    gc_freeTmpLink(&tmp->gc_status);
+    gc_freeTmpLink(&func->gc_status);
     return result->type;
 }
 
 ResultType setLambda(INTER_FUNCTIONSIG) {
-    Value *function_value = NULL;
-    VarList *function_var = NULL;
+    Statement *resunt_st = NULL;
     setResultCore(result);
 
-    result->type = operation_return;
-    function_var = copyVarList(var_list, false, inter);
-    {
-        Statement *resunt_st = makeReturnStatement(st->u.base_lambda.function, st->line, st->code_file);
-        function_value = makeVMFunctionValue(resunt_st, st->u.base_lambda.parameter, function_var, inter);
-        resunt_st->u.return_code.value = NULL;
-        freeStatement(resunt_st);
-    }
-    result->value = makeLinkValue(function_value, belong, inter);
-    gc_addTmpLink(&result->value->gc_status);
+    resunt_st = makeReturnStatement(st->u.base_lambda.function, st->line, st->code_file);
+    makeVMFunctionValue(resunt_st, st->u.base_lambda.parameter, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    resunt_st->u.return_code.value = NULL;
+    freeStatement(resunt_st);
     return result->type;
 }
 
@@ -195,14 +185,14 @@ ResultType callBackCore(LinkValue *function_value, Argument *arg, fline line, ch
 ResultType callClass(LinkValue *class_value, Argument *arg, fline line, char *file, 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));
         gc_freeTmpLink(&_new_->gc_status);
     }
     else
-        setResultError(E_TypeException, OBJ_NOTSUPPORT(new(__new__)), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_TypeException, OBJ_NOTSUPPORT(new(__new__)), line, file, true,
+                       CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
     return result->type;
 }
@@ -234,7 +224,7 @@ ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line
         goto return_;
 
     of = function_value->value->data.function.of;
-    function_var = function_value->value->object.out_var;
+    function_var = pushVarList(function_value->value->object.out_var != NULL ? function_value->value->object.out_var : var_list, inter);
     gc_freeze(inter, var_list, function_var, true);
 
     freeResult(result);
@@ -245,10 +235,10 @@ ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line
         setResult(result, inter, function_value->belong);
 
     gc_freeze(inter, var_list, function_var, false);
+    popVarList(function_var);
     freeFunctionArgument(arg, bak);
 
-    return_:
-    gc_freeTmpLink(&function_value->gc_status);
+    return_: gc_freeTmpLink(&function_value->gc_status);
     return result->type;
 }
 
@@ -261,7 +251,7 @@ ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int lin
     setResultCore(result);
     gc_addTmpLink(&function_value->gc_status);
     funtion_st = function_value->value->data.function.function;
-    if ((yield_run = popStatementVarList(funtion_st, &function_var, function_value->value->object.out_var, inter)))
+    if ((yield_run = popStatementVarList(funtion_st, &function_var, (function_value->value->object.out_var != NULL ? function_value->value->object.out_var : var_list), inter)))
         funtion_st = funtion_st->info.node;
 
     gc_freeze(inter, var_list, function_var, true);

+ 8 - 4
VirtulMathCore/src/runfile.c

@@ -123,7 +123,7 @@ ResultType importVMFileCore(VarList **new_object, char *file_dir, fline line, ch
     globalIterStatement(result, import_inter, run_st);
     if (!CHECK_RESULT(result)) {
         freeInter(import_inter, false);
-        result->value = makeLinkValue(makeNoneValue(inter), belong, inter);
+        useNoneValue(inter, result);
         setResultError(E_BaseException, NULL, line, code_file, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         goto return_;
     }
@@ -211,16 +211,20 @@ ResultType importFile(INTER_FUNCTIONSIG) {
     if (!CHECK_RESULT(result))
         goto return_;
 
-    freeResult(result);
     {
         VarList *import_var = copyVarList(var_list, false, inter);
         Value *import_obj = makeObject(inter, new_object, import_var, NULL);
         import_value = makeLinkValue(import_obj, belong, inter);
     }
+
+    freeResult(result);
     if (st->u.import_file.as != NULL)
         assCore(st->u.import_file.as, import_value, false, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    else
-        addStrVar(splitDir(file_dir), true, true, import_value, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    else {
+        addStrVar(splitDir(file_dir), true, true, import_value, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        if (!CHECK_RESULT(result))
+            goto return_;
+    }
     setResult(result, inter, belong);
 
     return_:

+ 44 - 47
VirtulMathCore/src/runoperation.c

@@ -121,7 +121,7 @@ ResultType listDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
         delCore(pt->data.value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         freeResult(result);
     }
-    setResultBase(result, inter, belong);
+    setResultBase(result, inter);
     return result->type;
 }
 
@@ -206,19 +206,19 @@ ResultType downDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
 
 ResultType assOperation(INTER_FUNCTIONSIG) {
     LinkValue *value = NULL;
+    setResultCore(result);
     if (st->u.operation.left->type == call_function){
-        VarList *function_var = NULL;
-        Value *function_value = NULL;
-        LinkValue *tmp = NULL;
-        function_var = copyVarList(var_list, false, inter);
-        {
-            Statement *return_st = makeReturnStatement(st->u.operation.right, st->line, st->code_file);
-            function_value = makeVMFunctionValue(return_st, st->u.operation.left->u.call_function.parameter, function_var, inter);
-            return_st->u.return_code.value = NULL;
-            freeStatement(return_st);
-        }
-        tmp = makeLinkValue(function_value, belong, inter);
-        assCore(st->u.operation.left->u.call_function.function, tmp, false, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        Statement *return_st = makeReturnStatement(st->u.operation.right, st->line, st->code_file);
+        LinkValue *func = NULL;
+        makeVMFunctionValue(return_st, st->u.operation.left->u.call_function.parameter, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        return_st->u.return_code.value = NULL;
+        freeStatement(return_st);
+
+        func = result->value;
+        result->value = NULL;
+        freeResult(result);
+        assCore(st->u.operation.left->u.call_function.function, func, false, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        gc_freeTmpLink(&func->gc_status);
     }
     else{
         if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.right, var_list, result, belong)))
@@ -249,11 +249,6 @@ ResultType assCore(Statement *name, LinkValue *value, bool check_aut, bool setti
     return result->type;
 }
 
-void varAssCore(char *name, LinkValue *name_, vnum times, LinkValue *value, bool setting, INTER_FUNCTIONSIG_CORE) {
-    addFromVarList(name, name_, times, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
-    if (setting)
-        newObjectSetting(name_, value, inter);
-}
 
 ResultType varAss(Statement *name, LinkValue *value, bool check_aut, bool setting, INTER_FUNCTIONSIG_NOT_ST) {
     char *str_name = NULL;
@@ -272,19 +267,29 @@ ResultType varAss(Statement *name, LinkValue *value, bool check_aut, bool settin
     if (check_aut) {
         LinkValue *tmp = findFromVarList(str_name, int_times, read_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
         if (tmp != NULL && !checkAut(value->aut, tmp->aut, name->line, name->code_file, NULL, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
-            goto return_;
+            goto error_;
     } else if (name->aut != auto_aut){
         LinkValue *tmp = findFromVarList(str_name, int_times, read_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
         if (tmp != NULL)
             tmp->aut = name->aut;
     }
-    varAssCore(str_name, result->value, int_times, var_value, setting, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    addFromVarList(str_name, result->value, int_times, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
+    if (setting) {
+        LinkValue *name_value = result->value;
+        result->value = NULL;
+        freeResult(result);
+        newObjectSetting(name_value, name->line, name->code_file, value, result, inter);
+        gc_freeTmpLink(&name_value->gc_status);
+        if (CHECK_RESULT(result))
+            goto error_;
+    }
+
     freeResult(result);
     result->type = operation_return;
     result->value = value;
     gc_addTmpLink(&result->value->gc_status);
 
-    return_:
+    error_:
     memFree(str_name);
     return result->type;
 }
@@ -303,10 +308,8 @@ ResultType listAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST)
     freeResult(result);
     setParameterCore(name->line, name->code_file, call, name->u.base_list.list, var_list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (CHECK_RESULT(result)){
-        Argument *tmp = call;
-        LinkValue *new_value = makeLinkValue(makeListValue(&tmp, inter, value_tuple), belong, inter);
         freeResult(result);
-        setResultOperation(result, new_value);
+        makeListValue(call, name->line, name->code_file, value_tuple, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     }
     return_:
     freeArgument(call, false);
@@ -398,35 +401,32 @@ ResultType getVar(INTER_FUNCTIONSIG, VarInfo var_info) {
 
 ResultType getBaseValue(INTER_FUNCTIONSIG) {
     setResultCore(result);
-    if (st->u.base_value.type == link_value)
+    if (st->u.base_value.type == link_value) {
         result->value = st->u.base_value.value;
-    else {
-        Value *value = NULL;
+        result->type = operation_return;
+        gc_addTmpLink(&result->value->gc_status);
+    }
+    else
         switch (st->u.base_value.type){
             case number_str:
-                value = makeNumberValue(strtol(st->u.base_value.str, NULL, 10), inter);
+                makeNumberValue(strtol(st->u.base_value.str, NULL, 10), st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 break;
             case bool_true:
-                value = makeBoolValue(true, inter);
+                makeBoolValue(true, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 break;
             case bool_false:
-                value = makeBoolValue(false, inter);
+                makeBoolValue(false, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 break;
             case pass_value:
-                value = makePassValue(inter);
+                makePassValue(st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 break;
             case null_value:
-                value = makeNoneValue(inter);
+                useNoneValue(inter, result);
                 break;
             default:
-                value = makeStringValue(st->u.base_value.str, inter);
+                makeStringValue(st->u.base_value.str, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 break;
         }
-        result->value = makeLinkValue(value, belong, inter);
-    }
-
-    result->type = operation_return;
-    gc_addTmpLink(&result->value->gc_status);
     return result->type;
 }
 
@@ -441,9 +441,8 @@ ResultType getList(INTER_FUNCTIONSIG) {
         freeArgument(at_tmp, false);
         return result->type;
     }
-
-    LinkValue *value = makeLinkValue(makeListValue(&at, inter, st->u.base_list.type), belong, inter);
-    setResultOperation(result, value);
+    freeResult(result);
+    makeListValue(at, st->line, st->code_file, st->u.base_list.type, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     freeArgument(at_tmp, false);
 
     return result->type;
@@ -451,27 +450,25 @@ ResultType getList(INTER_FUNCTIONSIG) {
 
 ResultType getDict(INTER_FUNCTIONSIG) {
     Argument *at = NULL;
-    Argument *at_tmp = NULL;
 
     setResultCore(result);
     at = getArgument(st->u.base_dict.dict, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    at_tmp = at;
     if (!CHECK_RESULT(result)){
-        freeArgument(at_tmp, false);
+        freeArgument(at, false);
         return result->type;
     }
 
     freeResult(result);
-    Value *tmp_value = makeDictValue(&at, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    Value *tmp_value = makeDictValue(at, true, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result)) {
-        freeArgument(at_tmp, false);
+        freeArgument(at, false);
         return result->type;
     }
 
     freeResult(result);
     LinkValue *value = makeLinkValue(tmp_value, belong, inter);
     setResultOperation(result, value);
-    freeArgument(at_tmp, false);
+    freeArgument(at, false);
 
     return result->type;
 }

+ 130 - 111
VirtulMathCore/src/value.c

@@ -29,98 +29,134 @@ Value *makeObject(Inter *inter, VarList *object, VarList *out_var, Inherit *inhe
     return tmp;
 }
 
-Value *makeNoneValue(Inter *inter) {
+Value *makeNoneValue(fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     Value *tmp;
-    if (inter->data.none == NULL) {
-        tmp = makeObject(inter, NULL, NULL, NULL);
-        tmp->type = none;
+    setResultCore(result);
+    callBackCore(makeLinkValue(inter->data.object, inter->base_father, inter), NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    if (!CHECK_RESULT(result))
+        return NULL;
+    tmp = result->value->value;
+    tmp->type = none;
+    return tmp;
+}
+
+Value *useNoneValue(Inter *inter, Result *result) {
+    Value *tmp = inter->data.none;
+    if (result != NULL) {
+        setResultCore(result);
+        result->type = operation_return;
+        result->value = makeLinkValue(tmp, inter->base_father, inter);
+        gc_addTmpLink(&result->value->gc_status);
     }
-    else
-        tmp = inter->data.none;
     return tmp;
 }
 
-Value *makeBoolValue(bool bool_num, Inter *inter) {
-    Inherit *object_father = getInheritFromValue(inter->data.bool_, inter);
-    VarList *new_var = copyVarList(inter->data.bool_->object.out_var, false, inter);
-    Value *tmp;
-    tmp = makeObject(inter, NULL, new_var, object_father);
-    tmp->type = bool_;
+Value *makeBoolValue(bool bool_num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+    Value *tmp = NULL;
+    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;
+    tmp = result->value->value;
     tmp->data.bool_.bool_ = bool_num;
     return tmp;
 }
 
-Value *makePassValue(Inter *inter){
-    Inherit *object_father = getInheritFromValue(inter->data.pass_, inter);
-    VarList *new_var = copyVarList(inter->data.pass_->object.out_var, false, inter);
-    Value *tmp;
-    tmp = makeObject(inter, NULL, new_var, object_father);
-    tmp->type = pass_;
+Value *makePassValue(fline line, char *file, INTER_FUNCTIONSIG_NOT_ST){  // TODO-szh 让切片支持该语法
+    Value *tmp = NULL;
+    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;
+    tmp = result->value->value;
     return tmp;
 }
 
-Value *makeNumberValue(vnum num, Inter *inter) {
-    Inherit *object_father = getInheritFromValue(inter->data.num, inter);
-    VarList *new_var = copyVarList(inter->data.num->object.out_var, false, inter);
-    Value *tmp;
-    tmp = makeObject(inter, NULL, new_var, object_father);
-    tmp->type = number;
+Value *makeNumberValue(vnum num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+    Value *tmp = NULL;
+    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;
+    tmp = result->value->value;
     tmp->data.num.num = num;
     return tmp;
 }
 
-Value *makeStringValue(char *str, Inter *inter) {
-    Inherit *object_father = getInheritFromValue(inter->data.str, inter);
-    VarList *new_var = copyVarList(inter->data.str->object.out_var, false, inter);
-    Value *tmp;
-    tmp = makeObject(inter, NULL, new_var, object_father);
-    tmp->type = string;
+Value *makeStringValue(char *str, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+    Value *tmp = NULL;
+    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;
+    tmp = result->value->value;
+    memFree(tmp->data.str.str);
     tmp->data.str.str = memStrcpy(str);
     return tmp;
 }
 
-
-static void setFunctionData(Value *value, Inter *inter) {
-    value->data.function.function_data.pt_type = inter->data.default_pt_type;
-}
-
-Value *makeVMFunctionFromValue(Value *value, LinkValue *return_value, fline line, char *file, Inter *inter) {
-    Statement *st = makeReturnStatement(makeBaseLinkValueStatement(return_value, line, file), line, file);
-    value->type = function;
-    value->data.function.type = vm_function;
-    value->data.function.function = st;
-    value->data.function.pt = NULL;
-    value->data.function.of = NULL;
-    setFunctionData(value, inter);
-    return value;
-}
-
-Value *makeVMFunctionValue(Statement *st, Parameter *pt, VarList *var_list, Inter *inter) {
-    Inherit *object_father = getInheritFromValue(inter->data.function, inter);
-    Value *tmp;
-    tmp = makeObject(inter, NULL, var_list, object_father);
-    tmp->type = function;
-    tmp->data.function.type = vm_function;
+Value *makeVMFunctionValue(Statement *st, Parameter *pt, INTER_FUNCTIONSIG_NOT_ST) {  // TODO-szh 设置无var_list的函数 (允许使用装饰器装饰,该功能未测试)
+    Value *tmp = NULL;
+    callBackCore(makeLinkValue(inter->data.function, inter->base_father, inter), NULL, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    if (!CHECK_RESULT(result))
+        return NULL;
+    tmp = result->value->value;
     tmp->data.function.function = copyStatement(st);
     tmp->data.function.pt = copyParameter(pt);
-    tmp->data.function.of = NULL;
-    setFunctionData(tmp, inter);
+    for (VarList *vl = tmp->object.out_var, *vl_next; vl != NULL; vl = vl_next) {
+        vl_next = vl->next;
+        freeVarList(vl);
+    }
+    tmp->object.out_var = copyVarList(var_list, false, inter);
+    result->value->belong = belong;
     return tmp;
 }
 
-Value *makeCFunctionValue(OfficialFunction of, VarList *var_list, Inter *inter) {
-    Inherit *object_father = getInheritFromValue(inter->data.function, inter);
-    Value *tmp;
-    tmp = makeObject(inter, NULL, copyVarList(var_list, false, inter), object_father);
-    tmp->type = function;
+Value *makeCFunctionValue(OfficialFunction of, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+    Value *tmp = NULL;
+    callBackCore(makeLinkValue(inter->data.function, inter->base_father, inter), NULL, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    if (!CHECK_RESULT(result))
+        return NULL;
+    tmp = result->value->value;
     tmp->data.function.type = c_function;
-    tmp->data.function.function = NULL;
-    tmp->data.function.pt = NULL;
     tmp->data.function.of = of;
-    setFunctionData(tmp, inter);
+    tmp->data.function.function_data.pt_type = inter->data.default_pt_type;
+    for (VarList *vl = tmp->object.out_var, *vl_next; vl != NULL; vl = vl_next) {
+        vl_next = vl->next;
+        freeVarList(vl);
+    }
+    tmp->object.out_var = copyVarList(var_list, false, inter);
+    result->value->belong = belong;
     return tmp;
 }
 
+LinkValue *makeCFunctionFromOf(OfficialFunction of, LinkValue *func, OfficialFunction function_new, OfficialFunction function_init, LinkValue *belong, VarList *var_list, Inter *inter) {
+    Argument *arg = makeValueArgument(func);
+    Argument *init_arg = NULL;
+    LinkValue *return_ = NULL;
+    Result result;
+
+    setResultCore(&result);
+    function_new(CALL_OFFICAL_FUNCTION(arg, func->value->object.var, &result, func));
+    return_ = result.value;
+    result.value = NULL;
+    freeResult(&result);
+
+    init_arg = makeValueArgument(return_);
+    function_init(CALL_OFFICAL_FUNCTION(init_arg, func->value->object.var, &result, func));
+    freeResult(&result);
+    freeArgument(init_arg, true);
+    freeArgument(arg, true);
+
+    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);
+    }
+    return_->value->object.out_var = copyVarList(var_list, false, inter);
+    return_->belong = belong;
+    gc_freeTmpLink(&return_->gc_status);
+    return return_;
+}
+
 Value *makeClassValue(VarList *var_list, Inter *inter, Inherit *father) {
     Value *tmp;
     tmp = makeObject(inter, NULL, var_list, father);
@@ -128,51 +164,29 @@ Value *makeClassValue(VarList *var_list, Inter *inter, Inherit *father) {
     return tmp;
 }
 
-Value *makeListValue(Argument **arg_ad, Inter *inter, enum ListType type) {
-    Inherit *object_father = NULL;
-    VarList *new_var = NULL;
-    Value *tmp;
-    Argument *at = *arg_ad;
-    if (type == value_list) {
-        object_father = getInheritFromValue(inter->data.list, inter);
-        new_var = copyVarList(inter->data.list->object.out_var, false, inter);
-    }
-    else {
-        object_father = getInheritFromValue(inter->data.tuple, inter);
-        new_var = copyVarList(inter->data.tuple->object.out_var, false, inter);
-    }
-    tmp = makeObject(inter, NULL, new_var, object_father);
-    tmp->type = list;
-    tmp->data.list.type = type;
-    tmp->data.list.list = NULL;
-    tmp->data.list.size = 0;
-    for (PASS; at != NULL && at->type == value_arg; at = at->next) {
-        tmp->data.list.size++;
-        tmp->data.list.list = memRealloc(tmp->data.list.list, tmp->data.list.size * sizeof(LinkValue *));
-        tmp->data.list.list[tmp->data.list.size - 1] = at->data.value;
-    }
-    *arg_ad = at;
+Value *makeListValue(Argument *arg, fline line, char *file, enum ListType type, INTER_FUNCTIONSIG_NOT_ST) {
+    Value *tmp = NULL;
+    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
+        callBackCore(makeLinkValue(inter->data.tuple, inter->base_father, inter), arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    if (!CHECK_RESULT(result))
+        return NULL;
+    tmp = result->value->value;
     return tmp;
 }
 
-Value *makeDictValue(Argument **arg_ad, bool new_hash, INTER_FUNCTIONSIG_NOT_ST) {
-    Inherit *object_father = getInheritFromValue(inter->data.dict, inter);
-    VarList *new_var = copyVarList(inter->data.dict->object.out_var, false, inter);
-    Value *tmp;
-    tmp = makeObject(inter, NULL, new_var, object_father);
-    tmp->data.dict.size = 0;
-    tmp->type = dict;
-    if (new_hash) {
-        VarList *hash = pushVarList(var_list, inter);
-        gc_addTmpLink(&tmp->gc_status);
-        tmp->data.dict.dict = hash->hashtable;
-        freeResult(result);
-        argumentToVar(arg_ad, &tmp->data.dict.size, CALL_INTER_FUNCTIONSIG_NOT_ST(hash, result, belong));
-        popVarList(hash);
-        gc_freeTmpLink(&tmp->gc_status);
-    }
-    else
+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);
+    callBackCore(dict, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result ,belong));
+    if (!CHECK_RESULT(result))
+        return NULL;
+    tmp = result->value->value;
+    if (!new_hash) {
         tmp->data.dict.dict = NULL;
+        tmp->data.dict.size = 0;
+    }
     return tmp;
 }
 
@@ -265,13 +279,12 @@ void setResultCore(Result *ru) {
 
 void setResult(Result *ru, Inter *inter, LinkValue *belong) {
     freeResult(ru);
-    setResultBase(ru, inter, belong);
+    setResultBase(ru, inter);
 }
 
-void setResultBase(Result *ru, Inter *inter, LinkValue *belong) {
+void setResultBase(Result *ru, Inter *inter) {
     setResultCore(ru);
-    ru->value = makeLinkValue(makeNoneValue(inter), belong, inter);
-    gc_addTmpLink(&ru->value->gc_status);
+    useNoneValue(inter, ru);
 }
 
 void setResultErrorSt(BaseErrorType type, char *error_message, bool new, Statement *st, INTER_FUNCTIONSIG_NOT_ST) {
@@ -340,7 +353,13 @@ void callException(LinkValue *exc, char *message, fline line, char *file, INTER_
     gc_addTmpLink(&exc->gc_status);
 
     if (_new_ != NULL){
-        Argument *arg = makeValueArgument(makeLinkValue(makeStringValue(message, inter), belong, inter));
+        Argument *arg = NULL;
+        makeStringValue(message, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        if (!CHECK_RESULT(result))
+            goto return_;
+        arg =  makeValueArgument(result->value);
+        freeResult(result);
+
         gc_addTmpLink(&_new_->gc_status);
         callBackCore(_new_, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         gc_freeTmpLink(&_new_->gc_status);
@@ -357,7 +376,7 @@ void callException(LinkValue *exc, char *message, fline line, char *file, INTER_
     result->error = connectError(makeError(type, error_message, line, file), result->error);
     memFree(type);
     memFree(error_message);
-    gc_freeTmpLink(&exc->gc_status);
+    return_: gc_freeTmpLink(&exc->gc_status);
 }
 
 void setResultError(BaseErrorType type, char *error_message, fline line, char *file, bool new, INTER_FUNCTIONSIG_NOT_ST) {
@@ -493,14 +512,14 @@ Inherit *connectInherit(Inherit *base, Inherit *back){
 Inherit *connectSafeInherit(Inherit *base, Inherit *back){
     Inherit **last_node = &base;
     if (back == NULL)
-        goto reutrn_;
+        goto return_;
     for (PASS; *last_node != NULL;)
         if ((*last_node)->value->value == back->value->value)
             *last_node = freeInherit(*last_node);
         else
             last_node = &(*last_node)->next;
     *last_node = back;
-    reutrn_: return base;
+    return_: return base;
 }
 
 Inherit *getInheritFromValue(Value *value, Inter *inter){