Przeglądaj źródła

update: 只有vm代码显式调用函数才会有错误回调

link #15
SongZihuan 4 lat temu
rodzic
commit
1f3634af7b

+ 5 - 5
vmcore/include/value.h

@@ -3,16 +3,16 @@
 #include "__macro.h"
 
 // 标准错误信息定义
-#define INSTANCE_ERROR(class)  (wchar_t *) L"Instance error when calling func, call non-" L###class L" " L###class L" method"
+#define INSTANCE_ERROR(class)  (wchar_t *) L"instance error when calling func, call non-" L###class L" " L###class L" method"
 #define VALUE_ERROR(value, acc) (wchar_t *) L###value L" value is not a " L###acc L" (may be modified by an external program)"
 #define ONLY_ACC(var, value) (wchar_t *) L###var L" only accepts " L###value
 #define ERROR_INIT(class) (wchar_t *) L###class L" get wrong initialization parameters"
-#define MANY_ARG (wchar_t *) L"Too many parameters"
-#define FEW_ARG (wchar_t *) L"Too few parameters"
+#define MANY_ARG (wchar_t *) L"too many parameters"
+#define FEW_ARG (wchar_t *) L"too few parameters"
 #define CUL_ERROR(opt) (wchar_t *) L###opt L" operation gets incorrect value"
-#define OBJ_NOTSUPPORT(opt) (wchar_t *) L"Object does not support " L###opt L" operation"
+#define OBJ_NOTSUPPORT(opt) (wchar_t *) L"object does not support " L###opt L" operation"
 #define RETURN_ERROR(func, type) (wchar_t *) L###func L" func should return " L###type L" type data"
-#define KEY_INTERRUPT (wchar_t *) L"KeyInterrupt"
+#define KEY_INTERRUPT (wchar_t *) L"keyInterrupt"
 
 typedef struct Argument Argument;
 typedef struct Inter Inter;

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

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

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

@@ -13,7 +13,7 @@ ResultType dict_new(O_FUNC){
     }
 
     if (arg != NULL && arg->type == value_arg) {
-        setResultError(E_ArgumentException, L"Too many argument", LINEFILE, true, CNEXT_NT);
+        setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
         return R_error;
     }
 

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

@@ -25,7 +25,7 @@ ResultType dictiter_init(O_FUNC){
         if (!CHECK_RESULT(result))
             return result->type;
         if (keys == NULL){
-            setResultError(E_TypeException, L"Object non-key-value pairs (there is no keys method)", LINEFILE, true, CNEXT_NT);
+            setResultError(E_TypeException, L"object non-key-value pairs (there is no keys method)", LINEFILE, true, CNEXT_NT);
             return R_error;
         }
 
@@ -94,7 +94,7 @@ ResultType dictiter_next(O_FUNC){
     if (!CHECK_RESULT(result))
         return result->type;
     if (list_next == NULL){
-        setResultError(E_TypeException, L"Object is not iterable", LINEFILE, true, CNEXT_NT);
+        setResultError(E_TypeException, OBJ_NOTSUPPORT(iter), LINEFILE, true, CNEXT_NT);
         return R_error;
     }
 

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

@@ -64,7 +64,7 @@ ResultType file_init(O_FUNC){
         mode = memStrcpy("r");
 
     if (checkFileReadble(path) != 1) {
-        setResultError(E_TypeException, L"File is not readable", LINEFILE, true, CNEXT_NT);
+        setResultError(E_TypeException, L"file is not readable", LINEFILE, true, CNEXT_NT);
         return R_error;
     }
     file->value->data.file.path = path;

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

@@ -134,7 +134,7 @@ ResultType list_slice_assignment(O_FUNC){
             freeResult(result);
             getIter(iter_obj, 0, LINEFILE, CNEXT_NT);
             if (is_iterStop(result->value, inter)){
-                setResultError(E_TypeException, L"Iter Object Too Short", LINEFILE, true, CNEXT_NT);
+                setResultError(E_TypeException, L"iter Object Too Short", LINEFILE, true, CNEXT_NT);
                 goto return_;
             }
             else if (!CHECK_RESULT(result))
@@ -144,7 +144,7 @@ ResultType list_slice_assignment(O_FUNC){
         freeResult(result);
         getIter(iter_obj, 0, LINEFILE, CNEXT_NT);
         if (CHECK_RESULT(result)) {  // 若没有出现Exception
-            setResultError(E_TypeException, L"Iter Object Too Long", LINEFILE, true, CNEXT_NT);
+            setResultError(E_TypeException, L"iter Object Too Long", LINEFILE, true, CNEXT_NT);
             goto return_;
         } else if (!is_iterStop(result->value, inter))
             goto return_;
@@ -240,10 +240,10 @@ ResultType list_down_assignment(O_FUNC){
     if (index < 0)
         index = size + index;
     if (index >= size){
-        setResultError(E_IndexException, L"Index too max", LINEFILE, true, CNEXT_NT);
+        setResultError(E_IndexException, L"index too max", LINEFILE, true, CNEXT_NT);
         return R_error;
     } else if (index < 0){
-        setResultError(E_IndexException, L"Index less than 0", LINEFILE, true, CNEXT_NT);
+        setResultError(E_IndexException, L"index less than 0", LINEFILE, true, CNEXT_NT);
         return R_error;
     }
     ap[0].value->value->data.list.list[index] = ap[1].value;

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

@@ -71,7 +71,7 @@ ResultType listiter_next(O_FUNC){
     getElement(list_, index, LINEFILE, CNEXT_NT);
     if (!CHECK_RESULT(result))
         if (is_indexException(result->value, inter))
-            setResultError(E_StopIterException, L"Stop Iter", LINEFILE, true, CNEXT_NT);
+            setResultError(E_StopIterException, L"stop iter", LINEFILE, true, CNEXT_NT);
         else
             return result->type;
     else {

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

@@ -167,7 +167,7 @@ ResultType str_iter(O_FUNC){
     if (!CHECK_RESULT(result))
         return result->type;
     if (to_list == NULL){
-        setResultError(E_TypeException, L"String cannot be converted to list", LINEFILE, true, CNEXT_NT);
+        setResultError(E_TypeException, L"string cannot be converted to list", LINEFILE, true, CNEXT_NT);
         return R_error;
     }
     gc_addTmpLink(&to_list->gc_status);

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

@@ -21,7 +21,7 @@ ResultType vm_super(O_FUNC){
             result->type = R_opt;
             gc_addTmpLink(&result->value->gc_status);
         } else
-            setResultError(E_SuperException, L"Object has no next father", LINEFILE, true, CNEXT_NT);
+            setResultError(E_SuperException, L"object has no next father", LINEFILE, true, CNEXT_NT);
         return result->type;
     }
 
@@ -39,7 +39,7 @@ ResultType vm_super(O_FUNC){
         gc_addTmpLink(&result->value->gc_status);
     }
     else
-        setResultError(E_SuperException, L"Object has no next father", LINEFILE, true, CNEXT_NT);
+        setResultError(E_SuperException, L"object has no next father", LINEFILE, true, CNEXT_NT);
 
     return result->type;
 }
@@ -132,7 +132,7 @@ ResultType vm_quit(O_FUNC){
     if (arg != NULL)
         setResultError(E_ArgumentException, MANY_ARG, LINEFILE, true, CNEXT_NT);
     else
-        setResultError(E_QuitException, L"VirtualMath Quit", LINEFILE, true, CNEXT_NT);
+        setResultError(E_QuitException, L"vmcore quit()", LINEFILE, true, CNEXT_NT);
     return R_error;
 }
 

+ 1 - 2
vmcore/parser/lexical.c

@@ -79,8 +79,7 @@ void freeLexFile(LexFile *file) {
         fclose(file->file);
     memFree(file->str);
     memFree(file);
-    return_:
-    return;
+    return_: return;
 }
 
 /**

+ 6 - 7
vmcore/src/__run.c

@@ -207,7 +207,7 @@ ResultType setFunctionArgument(Argument **arg, Argument **base, LinkValue *_func
     }
 
     if (pt_type != free_ && self == NULL) {
-        setResultError(E_ArgumentException, L"Function does not belong to anything(not self)", line, file, true, CNEXT_NT);
+        setResultError(E_ArgumentException, L"function does not belong to anything(not self)", line, file, true, CNEXT_NT);
         return R_error;
     }
 
@@ -531,19 +531,18 @@ bool is_indexException(LinkValue *value, Inter *inter) {
 bool checkAut(enum ValueAuthority value, enum ValueAuthority base, fline line, char *file, char *name, bool pri_auto, FUNC_NT) {
     if ((value == public_aut || (!pri_auto && value == auto_aut)) && (base != public_aut && base != auto_aut)) {
         if (name == NULL)
-            setResultError(E_PermissionsException, L"Wrong Permissions: access variables as public", line, file, true, CNEXT_NT);
+            setResultError(E_PermissionsException, L"wrong Permissions: access variables as public", line, file, true, CNEXT_NT);
         else {
-            wchar_t *message = memWidecat(L"Wrong Permissions: access variables as public: ", memStrToWcs(name, false), false, true);
+            wchar_t *message = memWidecat(L"wrong Permissions: access variables as public: ", memStrToWcs(name, false), false, true);
             setResultError(E_PermissionsException, message, line, file, true, CNEXT_NT);
             memFree(message);
         }
         return false;
-    }
-    else if ((value == protect_aut) && (base == private_aut)) {
+    } else if ((value == protect_aut) && (base == private_aut)) {
         if (name == NULL)
-            setResultError(E_PermissionsException, L"Wrong Permissions: access variables as protect", line, file, true, CNEXT_NT);
+            setResultError(E_PermissionsException, L"wrong Permissions: access variables as protect", line, file, true, CNEXT_NT);
         else {
-            wchar_t *message = memWidecat(L"Wrong Permissions: access variables as protect: ", memStrToWcs(name, false), false, true);
+            wchar_t *message = memWidecat(L"wrong Permissions: access variables as protect: ", memStrToWcs(name, false), false, true);
             setResultError(E_PermissionsException, message, line, file, true, CNEXT_NT);
             memFree(message);
         }

+ 1 - 1
vmcore/src/parameter.c

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

+ 3 - 3
vmcore/src/runbranch.c

@@ -170,7 +170,7 @@ ResultType ifBranch(FUNC) {
             finally = st->info.node;
         else {
             var_list = popVarList(var_list);
-            setResultError(E_SystemException, L"Yield Info Error", st->line, st->code_file, true, CNEXT_NT);
+            setResultError(E_SystemException, L"yield info error", st->line, st->code_file, true, CNEXT_NT);
             return R_error;
         }
     } else {
@@ -303,7 +303,7 @@ ResultType whileBranch(FUNC) {
             finally = st->info.node;
         } else {
             var_list = popVarList(var_list);
-            setResultError(E_SystemException, L"Yield Info Error", st->line, st->code_file, true, CNEXT_NT);
+            setResultError(E_SystemException, L"yield info error", st->line, st->code_file, true, CNEXT_NT);
             return R_error;
         }
     }
@@ -507,7 +507,7 @@ ResultType forBranch(FUNC) {
             finally = st->info.node;
         } else {
             var_list = popVarList(var_list);
-            setResultError(E_SystemException, L"Yield Info Error", st->line, st->code_file, true, CNEXT_NT);
+            setResultError(E_SystemException, L"yield info error", st->line, st->code_file, true, CNEXT_NT);
             return R_error;
         }
     }

+ 3 - 2
vmcore/src/runcall.c

@@ -152,6 +152,7 @@ ResultType callBack(FUNC) {
     result->value = NULL;
     freeResult(result);
     callBackCorePt(function_value, st->u.call_function.parameter, st->line, st->code_file, CNEXT_NT);
+    setResultErrorSt(E_BaseException, NULL, false, st, CNEXT_NT);  // 显式执行函数才进行错误回溯
     gc_freeTmpLink(&function_value->gc_status);
     return result->type;
 }
@@ -421,7 +422,7 @@ static ResultType callFFunction(LinkValue *function_value, Argument *arg, long i
 
     setResultCore(result);
     if (function_value->value->data.function.function_data.cls->value->type != V_lib) {
-        setResultError(E_ArgumentException, (wchar_t *) L"C function source is not clear", line, file, true, CNEXT_NT);
+        setResultError(E_ArgumentException, (wchar_t *) L"c function source is not clear", line, file, true, CNEXT_NT);
         return R_error;
     }
 
@@ -571,7 +572,7 @@ ResultType callBackCore(LinkValue *function_value, Argument *arg, fline line, ch
         callClass(function_value, arg, line, file, pt_sep, CNEXT_NT);
     else
         callObject(function_value, arg, line, file, pt_sep, CNEXT_NT);
-    setResultError(E_BaseException, NULL, line, file, false, CNEXT_NT);
+    // callBackCore不执行错误回溯
 
     return_:
     gc_freeTmpLink(&function_value->gc_status);