Browse Source

feat: 添加``struct``转int和dou函数

link #7
SongZihuan 4 years ago
parent
commit
4869594cbf
4 changed files with 19 additions and 0 deletions
  1. 1 0
      vmcore/include/value.h
  2. 6 0
      vmcore/ofunc/src/dou.c
  3. 6 0
      vmcore/ofunc/src/int.c
  4. 6 0
      vmcore/ofunc/src/pointer.c

+ 1 - 0
vmcore/include/value.h

@@ -13,6 +13,7 @@
 #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 NOT_ENOUGH_LEN(for) L"not enough length for" L###for
 
 #define GET_RESULT(val, res) do {(val) = (res)->value; (res)->value=NULL; freeResult(res);} while(0)
 #define GET_RESULTONLY(val, res) do {(val) = (res)->value; (res)->value=NULL;} while(0)

+ 6 - 0
vmcore/ofunc/src/dou.c

@@ -61,6 +61,12 @@ static ResultType dou_init(O_FUNC){
         case V_ell:
             base->value->data.dou.num = 0;
             break;
+        case V_struct:
+            if (ap[1].value->value->data.struct_.len * sizeof(int8_t) >= 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);  // 出现错误
+            break;
         default:
             setResultError(E_TypeException, ERROR_INIT(num), LINEFILE, true, CNEXT_NT);
             return result->type;

+ 6 - 0
vmcore/ofunc/src/int.c

@@ -61,6 +61,12 @@ static ResultType int_init(O_FUNC){
         case V_ell:
             base->value->data.int_.num = 0;
             break;
+        case V_struct:
+            if (ap[1].value->value->data.struct_.len * sizeof(int8_t) >= 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);  // 出现错误
+            break;
         default:
             setResultError(E_TypeException, ERROR_INIT(num), LINEFILE, true, CNEXT_NT);
             return result->type;

+ 6 - 0
vmcore/ofunc/src/pointer.c

@@ -41,6 +41,12 @@ static ResultType pointer_init(O_FUNC){
         case V_ell:
             base->value->data.pointer.pointer = NULL;
             break;
+        case V_struct:
+            base->value->data.pointer.pointer = &ap[1].value->value->data.struct_.data;  // 获取指向结构体指针的指针
+            break;
+        case V_pointer:
+            base->value->data.pointer.pointer = ap[1].value->value->data.pointer.pointer;
+            break;
         default:
             setResultError(E_TypeException, ERROR_INIT(num), LINEFILE, true, CNEXT_NT);
             return result->type;