Bläddra i källkod

feat: 添加ValueException

SongZihuan 4 år sedan
förälder
incheckning
d53b384bc9

+ 1 - 1
vmcore/include/inter.h

@@ -9,7 +9,7 @@ struct Result;
 
 #define BASEOBJSZIE (17)
 #define VARNAMESIZE (10)
-#define BASEEXCESIZE (19)
+#define BASEEXCESIZE (20)
 #define MAGFUNCSIZE (46)
 
 #define B_OBJECT (0)

+ 1 - 0
vmcore/include/value.h

@@ -245,6 +245,7 @@ enum BaseErrorType{
     E_SystemException,
     E_KeyInterrupt,
     E_QuitException,
+    E_ValueException,
 };
 
 Value *makeObject(Inter *inter, VarList *object, VarList *out_var, bool set_out_var, Inherit *inherit);

+ 2 - 0
vmcore/ofunc/src/error_.c

@@ -29,6 +29,7 @@ void registeredExcIter(R_FUNC){
                    {L"KeyboardInterrupt", inter->data.base_exc[E_KeyInterrupt]},
                    {L"QuitException", inter->data.base_exc[E_QuitException]},
                    {L"TypeException", inter->data.base_exc[E_TypeException]},
+                   {L"ValueException", inter->data.base_exc[E_ValueException]},
                    {L"ArgumentException", inter->data.base_exc[E_ArgumentException]},
                    {L"PermissionsException", inter->data.base_exc[E_PermissionsException]},
                    {L"ResultException", inter->data.base_exc[E_ResultException]},
@@ -66,6 +67,7 @@ void makeExcIter(Inter *inter){
     inter->data.base_exc[E_QuitException] = makeException(inter->data.base_exc[E_SystemException], inter);
 
     inter->data.base_exc[E_TypeException] = makeException(inter->data.base_exc[E_Exception], inter);
+    inter->data.base_exc[E_ValueException] = makeException(inter->data.base_exc[E_Exception], inter);
     inter->data.base_exc[E_ArgumentException] = makeException(inter->data.base_exc[E_Exception], inter);
     inter->data.base_exc[E_PermissionsException] = makeException(inter->data.base_exc[E_Exception], inter);
     inter->data.base_exc[E_ResultException] = makeException(inter->data.base_exc[E_Exception], inter);

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

@@ -60,7 +60,7 @@ void vobject_mul_base(FUNC_VOBJ) {
 void vobject_div_base(FUNC_VOBJ) {
     setResultCore(result);
     if (right->type == V_int && right->data.int_.num == 0 || right->type == V_dou && !(right->data.dou.num != 0))  // !(right->data.dou.num != 0) 因为long double检查是否位0时容易出错
-        setResultError(E_TypeException, L"divisor mustn't be 0", LINEFILE, true, CNEXT_NT);
+        setResultError(E_ValueException, L"divisor mustn't be 0", LINEFILE, true, CNEXT_NT);
     else if (left->type == V_int && right->type == V_int) {
         lldiv_t div_result = lldiv(left->data.int_.num, right->data.int_.num);
         makeIntValue(div_result.quot, LINEFILE, CNEXT_NT);
@@ -119,7 +119,7 @@ void vobject_pow_base(FUNC_VOBJ) {
         return;
     }
     if (errno != 0)
-        setResultFromERR(E_TypeException, CNEXT_NT);  // TODO-szh 设置计算错误
+        setResultFromERR(E_ValueException, CNEXT_NT);
     else
         makeDouValue(re, LINEFILE, CNEXT_NT);
 }

+ 1 - 1
vmcore/src/value.c

@@ -81,7 +81,7 @@ Value *makeDouValue(vdou num, fline line, char *file, FUNC_NT) {
     Value *tmp = NULL;
     setResultCore(result);
     if (isnan(num) || isinf(num)) {
-        setResultError(E_TypeException, L"decimal exception / [inf/nan]", LINEFILE, true, CNEXT_NT);
+        setResultError(E_ValueException, L"decimal exception / [inf/nan]", LINEFILE, true, CNEXT_NT);
         return NULL;
     }
     if (inter->data.free_mode) {

+ 1 - 1
vmcore/src/var.c

@@ -188,7 +188,7 @@ LinkValue *findVar(wchar_t *name, VarOperation operating, Var **re, HashTable *h
  * @param var_list
  * @return
  */
-LinkValue *findFromVarList(wchar_t *name, vint times, Var **re, VarOperation operating, FUNC_CORE) {  // TODO-szh 去掉对inter的依赖
+LinkValue *findFromVarList(wchar_t *name, vint times, Var **re, VarOperation operating, FUNC_CORE) {
     LinkValue *tmp = NULL;
     vint base = findDefault(var_list->default_var, name) + times;
     for (vint i = 0; i < base && var_list->next != NULL; i++)