Kaynağa Gözat

feat: error支持宽字符串

result的Error的message和type使用宽字符串保存

link #8
SongZihuan 4 yıl önce
ebeveyn
işleme
1ab35484e4

+ 0 - 1
VirtulMathCore/include/__virtualmath.h

@@ -30,7 +30,6 @@ void printLinkValueGC(char *tag, Inter *inter, long *tmp_link, long *st_link);
 void printValueGC(char *tag, Inter *inter, long *tmp_link, long *st_link);
 void printVarGC(char *tag, Inter *inter);
 void printHashTableGC(char *tag, Inter *inter, long *tmp_link);
-void printTokenStream(TokenStream *ts);
 #endif
 
 #endif //VIRTUALMATH___VIRTUALMATH_H

+ 2 - 5
VirtulMathCore/include/mem.h

@@ -10,17 +10,14 @@ void *memCalloc(size_t num, size_t size);
 void *memRealloc(void *old, size_t size);
 char *memStrcpy(const char *str);
 wchar_t *memWidecpy(const wchar_t *str);
-char *memStrCharcpy(char *str, size_t nsize, bool free_old, bool write, ...);
 wchar_t *memWideCharcpy(wchar_t *str, size_t nsize, bool free_old, bool write, ...);
 char *memStrcatIter(char *base, bool free_base, ...);
 char *memStrcat(char *first, char *second, bool free_first, bool free_last);
 wchar_t *memWidecat(wchar_t *first, wchar_t *second, bool free_first, bool free_last);
-char *memStrcpySelf(char *str, long times);
 wchar_t *memWidecpySelf(wchar_t *str, long times);
-char *memStrrev(const char *str);
 wchar_t *memWiderev(wchar_t *str);
-char *wcsToStr(wchar_t *wcs, bool free_old);
-wchar_t *strToWcs(char *str, bool free_old);
+char *memWcsToStr(wchar_t *wcs, bool free_old);
+wchar_t *memStrToWcs(char *str, bool free_old);
 
 #define memFree(p) ((p)=((p) != NULL ? (free(p), NULL) : NULL))
 #define eqString(str1, str2) (!strcmp(str1, str2))

+ 15 - 15
VirtulMathCore/include/value.h

@@ -3,16 +3,16 @@
 #include "__macro.h"
 
 // 标准错误信息定义
-#define INSTANCE_ERROR(class) "Instance error when calling function, call non-"#class" "#class" method"
-#define VALUE_ERROR(value, acc) #value" value is not a "#acc" (may be modified by an external program)"
-#define ONLY_ACC(var, value) #var" only accepts "#value
-#define ERROR_INIT(class) #class" get wrong initialization parameters"
-#define MANY_ARG "Too many parameters"
-#define FEW_ARG "Too few parameters"
-#define CUL_ERROR(opt) #opt" operation gets incorrect value"
-#define OBJ_NOTSUPPORT(opt) "Object does not support "#opt" operation"
-#define RETURN_ERROR(func, type) #func" function should return "#type" type data"
-#define KEY_INTERRUPT "KeyInterrupt"
+#define INSTANCE_ERROR(class) L##"Instance error when calling function, call non-"#class" "#class" method"
+#define VALUE_ERROR(value, acc) L###value" value is not a "#acc" (may be modified by an external program)"
+#define ONLY_ACC(var, value) L###var" only accepts "#value
+#define ERROR_INIT(class) L###class" get wrong initialization parameters"
+#define MANY_ARG L##"Too many parameters"
+#define FEW_ARG L##"Too few parameters"
+#define CUL_ERROR(opt) L###opt" operation gets incorrect value"
+#define OBJ_NOTSUPPORT(opt) L##"Object does not support "#opt" operation"
+#define RETURN_ERROR(func, type) L###func" function should return "#type" type data"
+#define KEY_INTERRUPT L##"KeyInterrupt"
 
 typedef struct Argument Argument;
 typedef struct Inter Inter;
@@ -154,8 +154,8 @@ struct Result {
 };
 
 struct Error {
-    char *type;  // TODO-szh 此处使用message
-    char *messgae;
+    wchar_t *type;
+    wchar_t *messgae;
     char *file;
     fline line;
     struct Error *next;
@@ -215,8 +215,8 @@ Value *makeDictValue(Argument *arg, bool new_hash, fline line, char *file, INTER
 void setResultCore(Result *ru);
 void setResult(Result *ru, Inter *inter);
 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 setResultErrorSt(BaseErrorType type, wchar_t *error_message, bool new, INTER_FUNCTIONSIG);
+void setResultError(BaseErrorType type, wchar_t *error_message, fline line, char *file, bool new, INTER_FUNCTIONSIG_NOT_ST);
 void setResultOperationNone(Result *ru, Inter *inter, LinkValue *belong);
 void setResultOperation(Result *ru, LinkValue *value);
 void setResultOperationBase(Result *ru, LinkValue *value);
@@ -227,7 +227,7 @@ Package *makePackage(Value *value, char *md5, char *name, Package *base);
 void freePackage(Package *base);
 Value *checkPackage(Package *base, char *md5, char *name);
 
-Error *makeError(char *type, char *message, fline line, char *file);
+Error *makeError(wchar_t *type, wchar_t *message, fline line, char *file);
 void freeError(Result *base);
 Error *connectError(Error *new, Error *base);
 void printError(Result *result, Inter *inter, bool free);

+ 3 - 44
VirtulMathCore/memory/mem.c

@@ -39,24 +39,6 @@ wchar_t *memWidecpy(const wchar_t *str){
     return tmp;
 }
 
-// TODO-szh 检查useage
-char *memStrCharcpy(char *str, size_t nsize, bool free_old, bool write, ...) {  // 复制str到新的空间,nszie是要扩展的大小。该函数支持让str=NULL,则变为单纯的memString
-    char *tmp = memString(memStrlen(str) + nsize);
-    size_t base_len = memStrlen(str);
-    if (base_len != 0)
-        strcpy(tmp, str);
-    if (write){
-        va_list argp;
-        va_start(argp, write);
-        for (int i = 0; i < nsize; i++)
-            tmp[base_len + i] = (char)va_arg(argp, int);
-        va_end(argp);
-    }
-    if (free_old)
-        memFree(str);
-    return tmp;
-}
-
 wchar_t *memWideCharcpy(wchar_t *str, size_t nsize, bool free_old, bool write, ...) {  // 复制str到新的空间,nszie是要扩展的大小。该函数支持让str=NULL,则变为单纯的memString
     size_t base_len = memWidelen(str);
     wchar_t *tmp = memWide(base_len + nsize);
@@ -95,7 +77,7 @@ char *memStrcat(char *first, char *second, bool free_first, bool free_last) {
         free_last = false;
     }
 
-    char *new = memStrCharcpy(first, memStrlen(second), false, false);
+    char *new = memString(memStrlen(first) + memStrlen(second));
     if (second != NULL)
         strcat(new, second);
 
@@ -127,21 +109,6 @@ wchar_t *memWidecat(wchar_t *first, wchar_t *second, bool free_first, bool free_
     return new;
 }
 
-char *memStrcpySelf(char *str, long times){
-    bool need_free = false;
-    char *new_str = NULL;
-    if (times < 0){
-        str = memStrrev(str);
-        times = -times;
-        need_free = true;
-    }
-    for (long i=0; i < times; i++)
-        new_str = memStrcat(new_str, str, true, false);
-    if (need_free)
-        memFree(str);
-    return new_str;
-}
-
 wchar_t *memWidecpySelf(wchar_t *str, long times){
     bool need_free = false;
     wchar_t *new_str = NULL;
@@ -165,15 +132,7 @@ wchar_t *memWiderev(wchar_t *str){
     return new_str;
 }
 
-char *memStrrev(const char * str){
-    size_t len_str = memStrlen(str);
-    char *new_str = memString(len_str);
-    for (int i = 0;i < len_str;i++)
-        new_str[i] = str[len_str - i - 1];
-    return new_str;
-}
-
-wchar_t *strToWcs(char *str, bool free_old) {
+wchar_t *memStrToWcs(char *str, bool free_old) {
     size_t len = memStrlen(str);
     wchar_t *tmp = memWide(len);
     mbstowcs(tmp, str, len);
@@ -182,7 +141,7 @@ wchar_t *strToWcs(char *str, bool free_old) {
     return tmp;
 }
 
-char *wcsToStr(wchar_t *wcs, bool free_old) {
+char *memWcsToStr(wchar_t *wcs, bool free_old) {
     size_t len = memWidelen(wcs);
     char *tmp = memString(len);
     wcstombs(tmp, wcs, len);

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

@@ -86,10 +86,10 @@ bool checkIndex(vnum *index, const vnum *size, INTER_FUNCTIONSIG_NOT_ST){
     if (*index < 0)
         *index = *size + *index;
     if (*index >= *size){
-        setResultError(E_IndexException, "Index too max", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_IndexException, L"Index too max", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return false;
     } else if (*index < 0){
-        setResultError(E_IndexException, "Index is less than 0", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_IndexException, L"Index is less than 0", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return false;
     }
     return true;  // true - 保持result为setResultCore的结果
@@ -100,15 +100,15 @@ bool checkSlice(vnum *first, vnum *second, const vnum *stride, vnum size, INTER_
     *first = *first < 0 ? *first + size : *first;
     *second = *second < 0 ? *second + size : *second;
     if (*second > size || *first >= size){
-        setResultError(E_IndexException, "Index too max", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_IndexException, L"Index too max", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return false;
     } else if (*first < 0 || *second <= 0){
-        setResultError(E_IndexException, "Index is less than 0", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_IndexException, L"Index is less than 0", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return false;
     }
 
     if (*stride == 0 || *first > *second && stride > 0 || *first < *second && stride < 0){
-        setResultError(E_StrideException, "Stride is 0 or Unfinished iteration", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_StrideException, L"Stride is 0 or Unfinished iteration", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return false;
     }
     return true;

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

@@ -13,7 +13,7 @@ ResultType dict_new(OFFICAL_FUNCTIONSIG){
     }
 
     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));
+        setResultError(E_ArgumentException, L"Too many argument", 0, "dict.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     }
 
@@ -63,7 +63,7 @@ ResultType dict_down(OFFICAL_FUNCTIONSIG){
         if (element != NULL)
             setResultOperationBase(result, copyLinkValue(element, inter));
         else {
-            char *message = memStrcat("Dict could not find key value: ", wcsToStr(name, true), false, true);
+            wchar_t *message = memWidecat(L"Dict could not find key value: ", name, false, false);
             setResultError(E_KeyException, message, 0, "dict", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             memFree(message);
         }
@@ -93,7 +93,7 @@ ResultType dict_down_del(OFFICAL_FUNCTIONSIG){
         if (element != NULL)
             setResult(result, inter);
         else{
-            char *message = memStrcat("Cannot delete non-existent keys: ", wcsToStr(name, false), false, true);
+            wchar_t *message = memWidecat(L"Cannot delete non-existent keys: ", name, false, false);
             setResultError(E_KeyException, message, 0, "dict", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             memFree(message);
         }

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

@@ -21,7 +21,7 @@ ResultType dictiter_init(OFFICAL_FUNCTIONSIG){
         LinkValue *listiter_class = NULL;
 
         if (keys == NULL){
-            setResultError(E_TypeException, "Object non-key-value pairs (there is no keys method)", 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            setResultError(E_TypeException, L"Object non-key-value pairs (there is no keys method)", 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             return R_error;
         }
 
@@ -83,7 +83,7 @@ ResultType dictiter_next(OFFICAL_FUNCTIONSIG){
 
     list_next = findAttributes(inter->data.object_next, false, list_, inter);
     if (list_next == NULL){
-        setResultError(E_TypeException, "Object is not iterable", 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_TypeException, L"Object is not iterable", 0, "dictiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     }
 

+ 4 - 4
VirtulMathCore/ofunc/src/list.c

@@ -141,7 +141,7 @@ ResultType list_slice_assignment(OFFICAL_FUNCTIONSIG){
             freeResult(result);
             getIter(iter_obj, 0, 0, "list", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             if (is_iterStop(result->value, inter)){
-                setResultError(E_TypeException, "Iter Object Too Short", 0, "list", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+                setResultError(E_TypeException, L"Iter Object Too Short", 0, "list", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 goto return_;
             }
             else if (!CHECK_RESULT(result))
@@ -151,7 +151,7 @@ ResultType list_slice_assignment(OFFICAL_FUNCTIONSIG){
         freeResult(result);
         getIter(iter_obj, 0, 0, "list", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         if (CHECK_RESULT(result)) {
-            setResultError(E_TypeException, "Iter Object Too Long", 0, "list", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            setResultError(E_TypeException, L"Iter Object Too Long", 0, "list", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             goto return_;
         } else if (!is_iterStop(result->value, inter))
             goto return_;
@@ -247,10 +247,10 @@ ResultType list_down_assignment(OFFICAL_FUNCTIONSIG){
     if (index < 0)
         index = size + index;
     if (index >= size){
-        setResultError(E_IndexException, "Index too max", 0, "list", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_IndexException, L"Index too max", 0, "list", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     } else if (index < 0){
-        setResultError(E_IndexException, "Index less than 0", 0, "list", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_IndexException, L"Index less than 0", 0, "list", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     }
     ap[0].value->value->data.list.list[index] = ap[1].value;

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

@@ -55,7 +55,7 @@ ResultType listiter_next(OFFICAL_FUNCTIONSIG){
     getElement(list_, index, 0, "listiter", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     if (!CHECK_RESULT(result))
         if (is_indexException(result->value, inter))
-            setResultError(E_StopIterException, "Stop Iter", 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            setResultError(E_StopIterException, L"Stop Iter", 0, "listiter", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         else
             return result->type;
     else {

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

@@ -169,7 +169,7 @@ ResultType str_iter(OFFICAL_FUNCTIONSIG){
     freeResult(result);
     to_list = findAttributes(L"to_list", false, ap[0].value, inter);
     if (to_list == NULL){
-        setResultError(E_TypeException, "String cannot be converted to list", 0, "str", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_TypeException, L"String cannot be converted to list", 0, "str", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     }
     gc_addTmpLink(&to_list->gc_status);

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

@@ -21,7 +21,7 @@ ResultType vm_super(OFFICAL_FUNCTIONSIG){
             result->type = R_opt;
             gc_addTmpLink(&result->value->gc_status);
         } else
-            setResultError(E_SuperException, "Object has no next father", 0, "super", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            setResultError(E_SuperException, L"Object has no next father", 0, "super", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return result->type;
     }
 
@@ -39,7 +39,7 @@ ResultType vm_super(OFFICAL_FUNCTIONSIG){
         gc_addTmpLink(&result->value->gc_status);
     }
     else
-        setResultError(E_SuperException, "Object has no next father", 0, "super", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_SuperException, L"Object has no next father", 0, "super", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
     return result->type;
 }
@@ -106,7 +106,7 @@ ResultType vm_quit(OFFICAL_FUNCTIONSIG){
     if (arg != NULL)
         setResultError(E_ArgumentException, MANY_ARG, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     else
-        setResultError(E_QuitException, "VirtualMath Quit", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_QuitException, L"VirtualMath Quit", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return R_error;
 }
 

+ 6 - 6
VirtulMathCore/ofunc/src/vobject.c

@@ -146,7 +146,7 @@ ResultType vobject_repo(OFFICAL_FUNCTIONSIG){
         case number: {
             char str[30] = {};
             snprintf(str, 30, "%lld", value->data.num.num);
-            repo = strToWcs(str, false);
+            repo = memStrToWcs(str, false);
             break;
         }
         case string:
@@ -155,23 +155,23 @@ ResultType vobject_repo(OFFICAL_FUNCTIONSIG){
         case function: {
             char str[30] = {};
             snprintf(str, 30, "(function on %p)", value);
-            repo = strToWcs(str, false);
+            repo = memStrToWcs(str, false);
             break;
         }
         case class: {
             char str[30] = {};
             snprintf(str, 30, "(class on %p)", value);
-            repo = strToWcs(str, false);
+            repo = memStrToWcs(str, false);
             break;
         }
         case bool_:
             if (value->data.bool_.bool_)
-                repo = strToWcs("true", false);
+                repo = memStrToWcs("true", false);
             else
-                repo = strToWcs("false", false);
+                repo = memStrToWcs("false", false);
             break;
         case pass_:
-            repo = strToWcs("...", false);
+            repo = memStrToWcs("...", false);
             break;
         default:
             setResultError(E_TypeException, CUL_ERROR(repo/str), 0, "vobject", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));

+ 7 - 7
VirtulMathCore/src/__run.c

@@ -10,7 +10,7 @@ ResultType getBaseVarInfo(wchar_t **name, int *times, INTER_FUNCTIONSIG){
     if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.base_var.times, var_list, result, belong)))
         return result->type;
     if (!isType(result->value->value, number)){
-        setResultErrorSt(E_TypeException, "Variable operation got unsupported number of layers", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultErrorSt(E_TypeException, L"Variable operation got unsupported number of layers", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return result->type;
     }
     *times = (int)result->value->value->data.num.num;
@@ -31,7 +31,7 @@ ResultType getBaseSVarInfo(wchar_t **name, int *times, INTER_FUNCTIONSIG){
     if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.base_svar.times, var_list, result, belong)))
         return result->type;
     if (!isType(result->value->value, number)){
-        setResultErrorSt(E_TypeException, "Variable operation got unsupported number of layers", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultErrorSt(E_TypeException, L"Variable operation got unsupported number of layers", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return result->type;
     }
     *times = (int)result->value->value->data.num.num;
@@ -179,7 +179,7 @@ ResultType setFunctionArgument(Argument **arg, Argument **base, LinkValue *_func
     }
 
     if (pt_type != free_ && self == NULL) {
-        setResultError(E_ArgumentException, "Function does not belong to anything(not self)", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultError(E_ArgumentException, L"Function does not belong to anything(not self)", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return R_error;
     }
 
@@ -454,9 +454,9 @@ bool is_indexException(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) {
     if ((value == public_aut || (!pri_auto && value == auto_aut)) && (base != public_aut && base != auto_aut)) {
         if (name == NULL)
-            setResultError(E_PermissionsException, "Wrong Permissions: access variables as public", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            setResultError(E_PermissionsException, L"Wrong Permissions: access variables as public", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         else {
-            char *message = memStrcat("Wrong Permissions: access variables as public: ", name, false, false);
+            wchar_t *message = memWidecat(L"Wrong Permissions: access variables as public: ", memStrToWcs(name, false), false, true);
             setResultError(E_PermissionsException, message, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             memFree(message);
         }
@@ -464,9 +464,9 @@ bool checkAut(enum ValueAuthority value, enum ValueAuthority base, fline line, c
     }
     else if ((value == protect_aut) && (base == private_aut)) {
         if (name == NULL)
-            setResultError(E_PermissionsException, "Wrong Permissions: access variables as protect", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+            setResultError(E_PermissionsException, L"Wrong Permissions: access variables as protect", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         else {
-            char *message = memStrcat("Wrong Permissions: access variables as protect: ", name, false, false);
+            wchar_t *message = memWidecat(L"Wrong Permissions: access variables as protect: ", memStrToWcs(name, false), false, true);
             setResultError(E_PermissionsException, message, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
             memFree(message);
         }

+ 1 - 14
VirtulMathCore/src/inter.c

@@ -1,5 +1,5 @@
 #include "__virtualmath.h"
-#define setName(str) strToWcs(str, false);
+#define setName(str) memStrToWcs(str, false)
 
 Inter *makeInter(char *out, char *error_, char *in, LinkValue *belong) {
     Inter *tmp = memCalloc(1, sizeof(Inter));
@@ -371,18 +371,5 @@ void printToken(Token *tk) {
 
 }
 
-void printTokenStream(TokenStream *ts) {
-    printf("token_list: ");
-    Token *tmp = ts->token_list;
-    int i = 0;
-    while (tmp != NULL){
-        if (i > 0)
-            printf("-");
-        printToken(tmp);
-        tmp = tmp->next;
-        i++;
-    }
-    printf("\n");
-}
 #endif  // START_GC
 #endif  // DBUG

+ 1 - 1
VirtulMathCore/src/parameter.c

@@ -661,7 +661,7 @@ ResultType setParameterCore(fline line, char *file, Argument *call, Parameter *f
                 setResultError(E_ArgumentException, OBJ_NOTSUPPORT(**), line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 goto return_;
             case error_unknown:
-                setResultError(E_ArgumentException, "Argument Unknown Exception", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+                setResultError(E_ArgumentException, L"Argument Unknown Exception", line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 goto return_;
             default:
                 goto break_;

+ 3 - 3
VirtulMathCore/src/run.c

@@ -158,7 +158,7 @@ ResultType iterStatement(INTER_FUNCTIONSIG) {
             if (type == R_goto && result->times == 0){
                 Statement *label_st = checkLabel(st, result->label);
                 if (label_st == NULL){
-                    setResultErrorSt(E_GotoException, "Don't find label", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+                    setResultErrorSt(E_GotoException, L"Don't find label", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                     type = R_error;
                     break;
                 }
@@ -218,7 +218,7 @@ ResultType globalIterStatement(Result *result, Inter *inter, Statement *st) {
             if (type == R_goto){
                 Statement *label_st = checkLabel(st, result->label);
                 if (label_st == NULL){
-                    setResultErrorSt(E_GotoException, "Don't find label", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+                    setResultErrorSt(E_GotoException, L"Don't find label", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                     type = R_error;
                     break;
                 }
@@ -254,7 +254,7 @@ bool operationSafeInterStatement(INTER_FUNCTIONSIG){
     if (RUN_TYPE(type))
         return false;
     else if (type != return_code && type != R_error)
-        setResultErrorSt(E_ResultException, "Operation get not support result type", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultErrorSt(E_ResultException, L"Operation get not support result type", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return true;
 }
 

+ 4 - 4
VirtulMathCore/src/runbranch.c

@@ -2,7 +2,7 @@
 
 static bool checkNumber(INTER_FUNCTIONSIG){
     if (!isType(result->value->value, number)) {
-        setResultErrorSt(E_TypeException, "Don't get a number of layers", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultErrorSt(E_TypeException, L"Don't get a number of layers", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         return false;
     }
     return true;
@@ -570,7 +570,7 @@ ResultType withBranch(INTER_FUNCTIONSIG) {
                 _enter_ = NULL;
                 _exit_ = NULL;
                 value = NULL;
-                setResultErrorSt(E_TypeException, "Get Not Support Value to Enter with", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+                setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(__enter__/__exit__), true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
                 set_result = false;
                 goto run_finally;
             }
@@ -941,7 +941,7 @@ ResultType raiseCode(INTER_FUNCTIONSIG){
 
     set_result:
     result->type = R_error;
-    result->error = connectError(makeError("RaiseException", "Exception was raise by user", st->line, st->code_file), result->error);
+    result->error = connectError(makeError(L"RaiseException", L"Exception was raise by user", st->line, st->code_file), result->error);
     return result->type;
 }
 
@@ -957,7 +957,7 @@ ResultType assertCode(INTER_FUNCTIONSIG){
     else if (result_)
         setResult(result, inter);
     else
-        setResultErrorSt(E_AssertException, "Assertion check error", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultErrorSt(E_AssertException, L"Assertion check error", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return result->type;
 }
 

+ 1 - 1
VirtulMathCore/src/runcall.c

@@ -129,7 +129,7 @@ ResultType elementSlice(INTER_FUNCTIONSIG) {
         gc_freeTmpLink(&_func_->gc_status);
     }
     else
-        setResultErrorSt(E_TypeException, "Don't find __down__/__slice__", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(__down__/__slice__), true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 
     gc_freeTmpLink(&element->gc_status);
     return result->type;

+ 10 - 7
VirtulMathCore/src/runfile.c

@@ -5,8 +5,11 @@ bool importRunParser(ParserMessage *pm, fline line, char *file, Statement *run_s
     parserCommandList(pm, inter, true, false, run_st);
     if (pm->status == int_error)
         setResultError(E_KeyInterrupt, KEY_INTERRUPT, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-    else if (pm->status != success)
-        setResultError(E_TypeException, pm->status_message, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    else if (pm->status != success) {
+        wchar_t *wcs_message = memStrToWcs(pm->status_message, false);
+        setResultError(E_TypeException, wcs_message, line, file, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        memFree(wcs_message);
+    }
     return CHECK_RESULT(result);
 }
 
@@ -112,7 +115,7 @@ int checkFileDir(char **file_dir, INTER_FUNCTIONSIG) {
         return 2;
 
     error_:
-    setResultErrorSt(E_ImportException, "import/include file is not readable", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+    setResultErrorSt(E_ImportException, L"import/include file is not readable", true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
     return 0;
 }
 
@@ -130,7 +133,7 @@ ResultType includeFile(INTER_FUNCTIONSIG) {
         goto return_;
     }
 
-    file_dir = wcsToStr(result->value->value->data.str.str, false);
+    file_dir = memWcsToStr(result->value->value->data.str.str, false);
     freeResult(result);
     if (checkFileDir(&file_dir, CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)) != 1)
         goto return_;
@@ -188,7 +191,7 @@ ResultType importFileCore(char **path, char **split, int *status, INTER_FUNCTION
         return R_error;
     }
 
-    *path = wcsToStr(result->value->value->data.str.str, false);
+    *path = memWcsToStr(result->value->value->data.str.str, false);
     *split = splitDir(*path);  // 自动去除末尾路径分隔符
     freeResult(result);
     if ((*status = checkFileDir(path, CALL_INTER_FUNCTIONSIG(st, var_list, result, belong))) == 0)
@@ -254,7 +257,7 @@ ResultType importFile(INTER_FUNCTIONSIG) {
         goto return_;
     freeResult(result);
     if (st->u.import_file.as == NULL) {
-        wchar_t *name_ = strToWcs(split_path, false);
+        wchar_t *name_ = memStrToWcs(split_path, false);
         addStrVar(name_, false, is_new, imp_value, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         memFree(name_);
     }
@@ -315,7 +318,7 @@ ResultType fromImportFile(INTER_FUNCTIONSIG) {
         LinkValue *string;
         freeResult(result);
 
-        wcs = strToWcs(split_path, false);
+        wcs = memStrToWcs(split_path, false);
         makeStringValue(wcs, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, imp_value));
         memFree(wcs);
 

+ 7 - 7
VirtulMathCore/src/runoperation.c

@@ -90,7 +90,7 @@ ResultType pointOperation(INTER_FUNCTIONSIG) {
         object = left->value->object.out_var;
 
     if (object == NULL) {
-        setResultError(E_TypeException, "object not support . / ->", st->line, st->code_file, true,
+        setResultError(E_TypeException, OBJ_NOTSUPPORT(->/.), st->line, st->code_file, true,
                        CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         goto return_;
     }
@@ -175,7 +175,7 @@ ResultType pointDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
     object = name->u.operation.OperationType == OPT_POINT ? left.value->value->object.var : left.value->value->object.out_var;
 
     if (object == NULL) {
-        setResultError(E_TypeException, "object not support . / ->", name->line, name->code_file, true,
+        setResultError(E_TypeException, OBJ_NOTSUPPORT(->/.), name->line, name->code_file, true,
                        CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         goto return_;
     }
@@ -387,7 +387,7 @@ ResultType pointAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST)
     object = name->u.operation.OperationType == OPT_POINT ? left.value->value->object.var : left.value->value->object.out_var;
 
     if (object == NULL) {
-        setResultError(E_TypeException, "object not support . / ->", name->line, name->code_file, true,
+        setResultError(E_TypeException, OBJ_NOTSUPPORT(->/.), name->line, name->code_file, true,
                        CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         goto return_;
     }
@@ -419,9 +419,9 @@ ResultType getVar(INTER_FUNCTIONSIG, VarInfo var_info) {
     freeResult(result);
     var = findFromVarList(name, int_times, get_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
     if (var == NULL) {
-        char *info = memStrcat("Variable not found: ", wcsToStr(name, false), false, true);
-        setResultErrorSt(E_NameExceptiom, info, true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-        memFree(info);
+        wchar_t *message = memWidecat(L"Variable not found: ", name, false, false);
+        setResultErrorSt(E_NameExceptiom, message, true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
+        memFree(message);
     }
     else if (checkAut(st->aut, var->aut, st->line, st->code_file, NULL, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
         setResultOperationBase(result, var);
@@ -560,7 +560,7 @@ ResultType operationCore(INTER_FUNCTIONSIG, wchar_t *name) {
         freeArgument(arg, true);
     }
     else {
-        char *message = memStrcat("Object not support ", wcsToStr(name, false), false, true);
+        wchar_t *message = memWidecat(L"Object not support ", name, false, false);
         setResultErrorSt(E_TypeException, message, true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         memFree(message);
     }

+ 13 - 15
VirtulMathCore/src/value.c

@@ -287,7 +287,7 @@ void setResultBase(Result *ru, Inter *inter) {
     useNoneValue(inter, ru);
 }
 
-void setResultErrorSt(BaseErrorType type, char *error_message, bool new, Statement *st, INTER_FUNCTIONSIG_NOT_ST) {  // TODO-szh 支持宽字符
+void setResultErrorSt(BaseErrorType type, wchar_t *error_message, bool new, Statement *st, INTER_FUNCTIONSIG_NOT_ST) {
     setResultError(type, error_message, st->line, st->code_file, new, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
 }
 
@@ -336,27 +336,25 @@ LinkValue *findBaseError(BaseErrorType type, Inter *inter){
     }
 }
 
-char *getErrorInfo(LinkValue *exc, int type, Inter *inter){
+wchar_t *getErrorInfo(LinkValue *exc, int type, Inter *inter){
     wchar_t *str_name = type == 1 ? inter->data.object_name : inter->data.object_message;
     LinkValue *_info_ = findAttributes(str_name, false, exc, inter);
     if (_info_ != NULL && _info_->value->type == string)
-        return wcsToStr(_info_->value->data.str.str, false);
+        return memWidecpy(_info_->value->data.str.str);
     else
-        return type == 1 ? memStrcpy("Error Type: Unknown") : memStrcpy("Error Message: Unknown");
+        return type == 1 ? memWidecpy(L"Error Type: Unknown") : memWidecpy(L"Error Message: Unknown");
 }
 
-void callException(LinkValue *exc, char *message, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
+void callException(LinkValue *exc, wchar_t *message, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
     LinkValue *_new_ = findAttributes(inter->data.object_new, false, exc, inter);
-    char *type = NULL;
-    char *error_message = NULL;
+    wchar_t *type = NULL;
+    wchar_t *error_message = NULL;
     setResultCore(result);
     gc_addTmpLink(&exc->gc_status);
 
     if (_new_ != NULL){
         Argument *arg = NULL;
-        wchar_t *wcs_message = strToWcs(message, false);
-        makeStringValue(wcs_message, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
-        memFree(wcs_message);
+        makeStringValue(message, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
         if (!CHECK_RESULT(result))
             goto return_;
         arg =  makeValueArgument(result->value);
@@ -381,7 +379,7 @@ void callException(LinkValue *exc, char *message, fline line, char *file, INTER_
     return_: gc_freeTmpLink(&exc->gc_status);
 }
 
-void setResultError(BaseErrorType type, char *error_message, fline line, char *file, bool new, INTER_FUNCTIONSIG_NOT_ST) {
+void setResultError(BaseErrorType type, wchar_t *error_message, fline line, char *file, bool new, INTER_FUNCTIONSIG_NOT_ST) {
     if (!new && result->type != R_error)
         return;
     if (new) {
@@ -429,11 +427,11 @@ void freeResultSafe(Result *ru){
     ru->error = NULL;
 }
 
-Error *makeError(char *type, char *message, fline line, char *file) {
+Error *makeError(wchar_t *type, wchar_t *message, fline line, char *file) {
     Error *tmp = memCalloc(1, sizeof(Error));
     tmp->line = line;
-    tmp->type = memStrcpy(type);
-    tmp->messgae = memStrcpy(message);
+    tmp->type = memWidecpy(type);
+    tmp->messgae = memWidecpy(message);
     tmp->file = memStrcpy(file);
     tmp->next = NULL;
     return tmp;
@@ -461,7 +459,7 @@ void printError(Result *result, Inter *inter, bool free) {
         if (base->next != NULL)
             fprintf(inter->data.inter_stderr, "Error Backtracking:  On Line: %lld In file: %s Error ID: %p\n", base->line, base->file, base);
         else
-            fprintf(inter->data.inter_stderr, "%s\n%s\nOn Line: %lld\nIn File: %s\nError ID: %p\n", base->type, base->messgae, base->line, base->file, base);
+            fprintf(inter->data.inter_stderr, "%ls\n%ls\nOn Line: %lld\nIn File: %s\nError ID: %p\n", base->type, base->messgae, base->line, base->file, base);
     }
     if (free)
         freeError(result);