dataArg.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * This file is part of the PikaScript project.
  3. * http://github.com/pikastech/pikascript
  4. *
  5. * MIT License
  6. *
  7. * Copyright (c) 2021 lyon 李昂 liang6516@outlook.com
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. */
  27. #ifndef _arg__H
  28. #define _arg__H
  29. #include "dataLink.h"
  30. #include "dataMemory.h"
  31. typedef uint32_t Hash;
  32. typedef enum {
  33. ARG_TYPE_UNDEF = 0,
  34. ARG_TYPE_NONE,
  35. ARG_TYPE_VOID,
  36. ARG_TYPE_NULL,
  37. ARG_TYPE_INT,
  38. ARG_TYPE_FLOAT,
  39. ARG_TYPE_POINTER,
  40. ARG_TYPE_STRING,
  41. ARG_TYPE_OBJECT,
  42. ARG_TYPE_MATE_OBJECT,
  43. ARG_TYPE_FREE_OBJECT,
  44. ARG_TYPE_NATIVE_METHOD,
  45. ARG_TYPE_NATIVE_CONSTRUCTOR_METHOD,
  46. ARG_TYPE_CONSTRUCTOR_METHOD,
  47. ARG_TYPE_OBJECT_METHOD,
  48. ARG_TYPE_STATIC_METHOD,
  49. ARG_TYPE_STRUCT,
  50. ARG_TYPE_HEAP_STRUCT,
  51. } ArgType;
  52. typedef void (*StructDeinitFun)(void* struct_);
  53. typedef struct __arg __arg;
  54. struct __arg {
  55. __arg* next;
  56. uint16_t size;
  57. uint8_t type;
  58. uint8_t __rsvd;
  59. Hash name_hash;
  60. uint8_t content[];
  61. };
  62. typedef uint8_t Arg;
  63. // uint32_t content_getNameHash(uint8_t* content);
  64. #define content_getNameHash(__addr) (((__arg*)(__addr))->name_hash)
  65. ArgType content_getType(uint8_t* self);
  66. #define content_getNext(__addr) ((uint8_t*)(((__arg*)(__addr))->next))
  67. #define content_getSize(__addr) ((uint16_t)(((__arg*)(__addr))->size))
  68. #define content_getContent(__addr) (((__arg*)(__addr))->content)
  69. uint16_t content_totleSize(uint8_t* self);
  70. uint8_t* content_deinit(uint8_t* self);
  71. uint8_t* content_setName(uint8_t* self, char* name);
  72. uint8_t* content_setType(uint8_t* self, ArgType type);
  73. uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size);
  74. // void content_setNext(uint8_t* self, uint8_t* next);
  75. #define content_setNext(__addr, __next) \
  76. do { \
  77. (((__arg*)(__addr))->next) = (__arg*)(__next); \
  78. } while (0)
  79. uint16_t arg_getTotleSize(Arg* self);
  80. void arg_freeContent(Arg* self);
  81. Arg* arg_setName(Arg* self, char* name);
  82. Arg* arg_setContent(Arg* self, uint8_t* content, uint32_t size);
  83. Arg* arg_newContent(Arg* self, uint32_t size);
  84. Arg* arg_setType(Arg* self, ArgType type);
  85. Hash arg_getNameHash(Arg* self);
  86. ArgType arg_getType(Arg* self);
  87. uint16_t arg_getContentSize(Arg* self);
  88. Hash hash_time33(char* str);
  89. Arg* arg_setInt(Arg* self, char* name, int64_t val);
  90. Arg* arg_setFloat(Arg* self, char* name, float val);
  91. Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer);
  92. Arg* arg_setStr(Arg* self, char* name, char* string);
  93. Arg* arg_setNull(Arg* self);
  94. int64_t arg_getInt(Arg* self);
  95. float arg_getFloat(Arg* self);
  96. void* arg_getPtr(Arg* self);
  97. char* arg_getStr(Arg* self);
  98. Arg* arg_copy(Arg* argToBeCopy);
  99. #define arg_getContent(self) ((uint8_t*)content_getContent((self)))
  100. Arg* arg_init(Arg* self, void* voidPointer);
  101. void arg_deinit(Arg* self);
  102. Arg* New_arg(void* voidPointer);
  103. Arg* arg_append(Arg* arg_in, void* new_content, size_t new_size);
  104. Arg* arg_setStruct(Arg* self,
  105. char* name,
  106. void* struct_ptr,
  107. uint32_t struct_size);
  108. Arg* arg_setHeapStruct(Arg* self,
  109. char* name,
  110. void* struct_ptr,
  111. uint32_t struct_size,
  112. void* struct_deinit_fun);
  113. void* arg_getHeapStruct(Arg* self);
  114. #endif