Browse Source

style: 添加了vstruct为int8_t的别名

SongZihuan 4 years ago
parent
commit
8fc1016f77

+ 1 - 1
CMakeLists.txt

@@ -32,7 +32,7 @@ SET(HELLOVM_INCLUDE_DICT
 IF (GC)
     ADD_DEFINITIONS(-DSTART_GC=1)
 ELSE()
-    ADD_DEFINITIONS(-DSTART_GC=0)  # TODO-szh 处理不启动gc
+    ADD_DEFINITIONS(-DSTART_GC=0)
 ENDIF()
 
 ADD_DEFINITIONS(-DCC=\"${CMAKE_C_COMPILER}\")

+ 1 - 1
vmcore/include/__macro.h

@@ -51,6 +51,6 @@ typedef long long vint;
 typedef long double vdou;
 typedef unsigned long long vhashn;
 typedef unsigned long long fline;
-
+typedef int8_t vstruct;
 
 #endif //VIRTUALMATH___MACRO_H

+ 1 - 1
vmcore/include/value.h

@@ -78,7 +78,7 @@ struct String {
 };
 
 struct Struct_ {
-    int8_t *data;  // 列表
+    vstruct *data;  // 列表
     vint len;  // 长度
 };
 

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

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

+ 2 - 2
vmcore/ofunc/src/dou.c

@@ -62,7 +62,7 @@ static ResultType dou_init(O_FUNC){
             base->value->data.dou.num = 0;
             break;
         case V_struct:
-            if (ap[1].value->value->data.struct_.len * sizeof(int8_t) >= sizeof(vdou))
+            if (ap[1].value->value->data.struct_.len * sizeof(vstruct) >= sizeof(vdou))
                 base->value->data.dou.num = *(vdou *)ap[1].value->value->data.struct_.data;  // 转换为 vdou
             else
                 setResultError(E_ValueException, NOT_ENOUGH_LEN(dou), LINEFILE, true, CNEXT_NT);  // 出现错误
@@ -83,7 +83,7 @@ void registeredDou(R_FUNC){
                       {inter->data.mag_func[M_INIT], dou_init, fp_obj, .var=nfv_notpush},
                       {NULL, NULL}};
     gc_addTmpLink(&object->gc_status);
-    addBaseClassVar(L"dou", object, belong, inter);
+    addBaseClassVar(L"double", object, belong, inter);
     iterBaseClassFunc(tmp, object, CFUNC_CORE(inter->var_list));
     gc_freeTmpLink(&object->gc_status);
 }

+ 8 - 8
vmcore/ofunc/src/file_.c

@@ -155,18 +155,18 @@ static ResultType file_read_bit(O_FUNC){
             setResultError(E_TypeException, ONLY_ACC(n, num), LINEFILE, true, CNEXT_NT);
             return R_error;
         }
-        data = memCalloc(n, sizeof(int8_t));  // TODO-szh in8_t 使用typedef
-        count = fread(data, sizeof(int8_t), n, file->value->data.file.file);
+        data = memCalloc(n, sizeof(vstruct));
+        count = fread(data, sizeof(vstruct), n, file->value->data.file.file);
     } else {
         void *bak = NULL;
         size_t get;
         do {  // 全部读取
-            void *tmp = memCalloc(5, sizeof(int8_t));
-            get = fread(tmp, sizeof(int8_t), 5, file->value->data.file.file);
+            void *tmp = memCalloc(5, sizeof(vstruct));
+            get = fread(tmp, sizeof(vstruct), 5, file->value->data.file.file);
             bak = data;
-            data = memCalloc(count, sizeof(int8_t));
-            memcpy(data, bak, count * sizeof(int8_t));  // 复制
-            memcpy(data + count * sizeof(int8_t), tmp, get * sizeof(int8_t));
+            data = memCalloc(count, sizeof(vstruct));
+            memcpy(data, bak, count * sizeof(vstruct));  // 复制
+            memcpy(data + count * sizeof(vstruct), tmp, get * sizeof(vstruct));
             memFree(bak);
             memFree(tmp);
             count += get;
@@ -237,7 +237,7 @@ static ResultType file_write(O_FUNC){
             re = memWidelen(ap[1].value->value->data.str.str);
             break;
         case V_struct:
-            re = (vint)fwrite(ap[1].value->value->data.struct_.data, sizeof(int8_t), ap[1].value->value->data.struct_.len, file->value->data.file.file);
+            re = (vint)fwrite(ap[1].value->value->data.struct_.data, sizeof(vstruct), ap[1].value->value->data.struct_.len, file->value->data.file.file);
             break;
         default:
             setResultError(E_TypeException, ONLY_ACC(str, str), LINEFILE, true, CNEXT_NT);

+ 1 - 1
vmcore/ofunc/src/int.c

@@ -62,7 +62,7 @@ static ResultType int_init(O_FUNC){
             base->value->data.int_.num = 0;
             break;
         case V_struct:
-            if (ap[1].value->value->data.struct_.len * sizeof(int8_t) >= sizeof(vint))
+            if (ap[1].value->value->data.struct_.len * sizeof(vstruct) >= sizeof(vint))
                 base->value->data.int_.num = *(vint *)ap[1].value->value->data.struct_.data;  // 转换为 vint
             else
                 setResultError(E_ValueException, NOT_ENOUGH_LEN(int), LINEFILE, true, CNEXT_NT);  // 出现错误

+ 0 - 71
vmcore/ofunc/src/str.c

@@ -206,77 +206,6 @@ void registeredStr(R_FUNC){
     gc_freeTmpLink(&object->gc_status);
 }
 
-LinkValue *callClassOf(LinkValue *obj, Inter *inter, LinkValue *new_func, LinkValue *init_func) {
-    Argument *arg;
-    Argument *init_arg;
-    Result result;
-    LinkValue *new_name;
-    setResultCore(&result);
-
-    arg = makeValueArgument(obj);
-    new_func->value->data.function.of(arg, obj, &result, inter, new_func->value->object.out_var);
-    new_name = result.value;
-    freeResult(&result);
-    freeArgument(arg, true);
-
-    init_arg = makeValueArgument(new_name);
-    init_func->value->data.function.of(init_arg, new_name, &result, inter, init_func->value->object.out_var);
-    freeResult(&result);
-    freeArgument(init_arg, true);
-
-    return new_name;
-}
-
-LinkValue *makeStrFromOf(LinkValue *str, LinkValue *new, LinkValue *init, wchar_t *str_, Inter *inter) {
-    LinkValue *return_;
-    return_ = callClassOf(str, inter, new, init);
-    memFree(return_->value->data.str.str);
-    return_->value->data.str.str = memWidecpy(str_);
-    return return_;
-}
-
-static 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_func;
-    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 != NULL; vl = freeVarList(vl))
-        PASS;
-    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) {
-    LinkValue *obj = inter->data.base_obj[B_STR];
-
-    LinkValue *new_func = NULL;
-    LinkValue *new_name = NULL;
-    wchar_t *new_name_ = setStrVarName(inter->data.mag_func[M_NEW], false, inter);
-
-    LinkValue *init_func = NULL;
-    LinkValue *init_name = NULL;
-    wchar_t *init_name_ = setStrVarName(inter->data.mag_func[M_INIT], false, inter);
-
-    new_func = makeFunctionFromValue(func, func_new, func_init, str_new, obj, NULL, inter);  // 声明为内联函数
-    init_func = makeFunctionFromValue(func, func_new, func_init, str_init, obj, NULL, inter);
-    new_func->value->data.function.function_data.pt_type = fp_class;
-    init_func->value->data.function.function_data.pt_type = fp_obj;
-
-
-    new_name = makeStrFromOf(obj, new_func, init_func, inter->data.mag_func[M_NEW], inter);
-    init_name = makeStrFromOf(obj, new_func, init_func, inter->data.mag_func[M_INIT], inter);
-
-    addFromVarList(new_name_, new_name, 0, new_func, CFUNC_CORE(obj->value->object.var));
-    addFromVarList(init_name_, init_name, 0, init_func, CFUNC_CORE(obj->value->object.var));
-
-    newObjectSettingPresetting(new_func, new_name, inter);
-    newObjectSettingPresetting(init_func, init_name, inter);
-    memFree(new_name_);
-    memFree(init_name_);
-}
-
 void makeBaseStr(Inter *inter){
     LinkValue *str = makeBaseChildClass(inter->data.base_obj[B_VOBJECT], inter);
     gc_addStatementLink(&str->gc_status);

+ 4 - 4
vmcore/ofunc/src/struct_.c

@@ -48,19 +48,19 @@ static ResultType struct_init(O_FUNC){
         switch (data->value->type) {
             case V_int:
                 MEM_CPY(base->value->data.struct_.data, &(data->value->data.int_.num), sizeof(vint));
-                base->value->data.struct_.len = sizeof(vint) / sizeof(int8_t);
+                base->value->data.struct_.len = sizeof(vint) / sizeof(vstruct);
                 break;
             case V_dou:
                 MEM_CPY(base->value->data.struct_.data, &(data->value->data.dou.num), sizeof(vdou));
-                base->value->data.struct_.len = sizeof(vdou) / sizeof(int8_t);
+                base->value->data.struct_.len = sizeof(vdou) / sizeof(vstruct);
                 break;
             case V_struct:
-                MEM_CPY(base->value->data.struct_.data, &data->value->data.struct_.data, data->value->data.struct_.len * sizeof(int8_t));
+                MEM_CPY(base->value->data.struct_.data, &data->value->data.struct_.data, data->value->data.struct_.len * sizeof(vstruct));
                 base->value->data.struct_.len = data->value->data.struct_.len;
                 break;
             case V_str:
                 MEM_CPY(base->value->data.struct_.data, &data->value->data.str.str, memWidelen(data->value->data.str.str) * sizeof(wchar_t));
-                base->value->data.struct_.len = (sizeof(wchar_t) * memWidelen(data->value->data.str.str)) / sizeof(int8_t);
+                base->value->data.struct_.len = (sizeof(wchar_t) * memWidelen(data->value->data.str.str)) / sizeof(vstruct);
                 break;
             default:
                 setResultError(E_ArgumentException, ONLY_ACC(data, int/str/struct), LINEFILE, true, CNEXT_NT);

+ 1 - 1
vmcore/src/value.c

@@ -59,7 +59,7 @@ Value *makeStructValue(void *data, vint len, fline line, char *file, FUNC_NT) {
         setResultOperation(result, structCore(belong, inter->data.base_obj[B_STRUCT], inter));
     tmp = result->value->value;
     if (data != NULL) {
-        tmp->data.struct_.data = MEM_CPY(tmp->data.struct_.data, data, len * sizeof(int8_t));
+        tmp->data.struct_.data = MEM_CPY(tmp->data.struct_.data, data, len * sizeof(vstruct));
         tmp->data.struct_.len = len;
     }
     return tmp;