value.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #ifndef VIRTUALMATH_VALUE_H
  2. #define VIRTUALMATH_VALUE_H
  3. #include "__macro.h"
  4. // 标准错误信息定义
  5. #define INSTANCE_ERROR(class) L##"Instance error when calling V_func, call non-"#class" "#class" method"
  6. #define VALUE_ERROR(value, acc) L###value" value is not a "#acc" (may be modified by an external program)"
  7. #define ONLY_ACC(var, value) L###var" only accepts "#value
  8. #define ERROR_INIT(class) L###class" get wrong initialization parameters"
  9. #define MANY_ARG L##"Too many parameters"
  10. #define FEW_ARG L##"Too few parameters"
  11. #define CUL_ERROR(opt) L###opt" operation gets incorrect value"
  12. #define OBJ_NOTSUPPORT(opt) L##"Object does not support "#opt" operation"
  13. #define RETURN_ERROR(func, type) L###func" V_func should return "#type" type data"
  14. #define KEY_INTERRUPT L##"KeyInterrupt"
  15. typedef struct Argument Argument;
  16. typedef struct Inter Inter;
  17. typedef struct VarList VarList;
  18. typedef enum ResultType ResultType;
  19. typedef enum BaseErrorType BaseErrorType;
  20. typedef struct Value Value;
  21. typedef struct LinkValue LinkValue;
  22. typedef struct Result Result;
  23. typedef struct Error Error;
  24. typedef struct Inherit Inherit;
  25. typedef struct Package Package;
  26. typedef enum ResultType (*OfficialFunction)(OFFICAL_FUNCTIONSIG);
  27. typedef void (*Registered)(REGISTERED_FUNCTIONSIG);
  28. enum ValueAuthority {
  29. auto_aut,
  30. public_aut,
  31. protect_aut,
  32. private_aut
  33. };
  34. enum ValueType {
  35. V_none=0,
  36. V_num=1,
  37. V_str=2,
  38. V_func=3,
  39. V_list=4,
  40. V_dict=5,
  41. V_class=6,
  42. V_obj=7,
  43. V_bool=8,
  44. V_ell=9,
  45. };
  46. struct Number {
  47. vnum num;
  48. };
  49. struct String {
  50. wchar_t *str;
  51. };
  52. struct Function{
  53. enum {
  54. c_func,
  55. vm_func,
  56. } type;
  57. struct Statement *function;
  58. struct Parameter *pt;
  59. OfficialFunction of;
  60. struct {
  61. enum FunctionPtType {
  62. free_, // 不包含任何隐式传递的参数
  63. static_, // 不包含self参数
  64. object_static_, // self参数不允许class
  65. class_static_, // self参数允许一切,但转换为类
  66. all_static_, // self参数允许一切
  67. cls_static_, // 使用function自带的cls作为参数
  68. object_free_, // 同object_static_但不包含func参数
  69. class_free_, // 同object_static_但不包含func参数
  70. all_free_, // 允许class或者object
  71. cls_free_, // 使用function自带的cls作为参数
  72. } pt_type;
  73. LinkValue *cls;
  74. } function_data;
  75. };
  76. struct List {
  77. enum ListType {
  78. L_tuple,
  79. L_list,
  80. } type;
  81. struct LinkValue **list;
  82. vnum size;
  83. };
  84. struct Dict {
  85. struct HashTable *dict;
  86. vnum size;
  87. };
  88. struct Bool{
  89. bool bool_;
  90. };
  91. struct Value{
  92. enum ValueType type;
  93. struct {
  94. struct VarList *var;
  95. struct VarList *out_var;
  96. struct Inherit *inherit;
  97. } object;
  98. union data {
  99. struct Number num;
  100. struct String str;
  101. struct Function function;
  102. struct List list;
  103. struct Dict dict;
  104. struct Bool bool_;
  105. } data;
  106. struct Value *gc_next;
  107. struct Value *gc_last;
  108. struct GCStatus gc_status;
  109. };
  110. struct LinkValue {
  111. enum ValueAuthority aut;
  112. struct Value *value;
  113. struct LinkValue *belong;
  114. struct LinkValue *gc_next;
  115. struct LinkValue *gc_last;
  116. struct GCStatus gc_status;
  117. };
  118. struct Result {
  119. enum ResultType {
  120. R_not = 1, // 无返回值
  121. R_func=2, // 函数返回值
  122. R_opt=3, // 表达式返回值
  123. R_error=4, // 错误
  124. R_break=5,
  125. R_continue=6,
  126. R_rego=7,
  127. R_restart=8,
  128. R_goto=9,
  129. R_yield=10,
  130. } type;
  131. wchar_t *label;
  132. struct LinkValue *value;
  133. struct Error *error;
  134. vnum times;
  135. struct Statement *node;
  136. };
  137. struct Error {
  138. wchar_t *type;
  139. wchar_t *messgae;
  140. char *file;
  141. fline line;
  142. struct Error *next;
  143. };
  144. struct Inherit {
  145. struct LinkValue *value;
  146. struct Inherit *next;
  147. };
  148. struct Package {
  149. struct Value *package;
  150. char *name; // split dir的name
  151. char *md5; // md5地址
  152. struct Package *next;
  153. };
  154. enum BaseErrorType{
  155. E_BaseException,
  156. E_Exception,
  157. E_TypeException,
  158. E_ArgumentException,
  159. E_PermissionsException,
  160. E_GotoException,
  161. E_ResultException,
  162. E_NameExceptiom,
  163. E_AssertException,
  164. E_KeyException,
  165. E_IndexException,
  166. E_StrideException,
  167. E_StopIterException,
  168. E_SuperException,
  169. E_ImportException,
  170. E_IncludeException,
  171. E_SystemException,
  172. E_KeyInterrupt,
  173. E_QuitException,
  174. };
  175. Value *makeObject(Inter *inter, VarList *object, VarList *out_var, Inherit *inherit);
  176. void freeValue(Value **Value);
  177. LinkValue *makeLinkValue(Value *value, LinkValue *belong, Inter *inter);
  178. void freeLinkValue(LinkValue **value);
  179. LinkValue *copyLinkValue(LinkValue *value, Inter *inter);
  180. Value *useNoneValue(Inter *inter, Result *result);
  181. Value *makeBoolValue(bool bool_num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
  182. Value *makePassValue(fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
  183. Value *makeNumberValue(vnum num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
  184. Value *makeStringValue(wchar_t *str, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
  185. Value *makeVMFunctionValue(struct Statement *st, struct Parameter *pt, INTER_FUNCTIONSIG_NOT_ST);
  186. Value *makeCFunctionValue(OfficialFunction of, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
  187. LinkValue *makeCFunctionFromOf(OfficialFunction of, LinkValue *func, OfficialFunction function_new, OfficialFunction function_init, LinkValue *belong, VarList *var_list, Inter *inter);
  188. Value *makeClassValue(VarList *var_list, Inter *inter, Inherit *father);
  189. Value *makeListValue(Argument *arg, fline line, char *file, enum ListType type, INTER_FUNCTIONSIG_NOT_ST);
  190. Value *makeDictValue(Argument *arg, bool new_hash, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST);
  191. void setResultCore(Result *ru);
  192. void setResult(Result *ru, Inter *inter);
  193. void setResultBase(Result *ru, Inter *inter);
  194. void setResultErrorSt(BaseErrorType type, wchar_t *error_message, bool new, INTER_FUNCTIONSIG);
  195. void setResultError(BaseErrorType type, wchar_t *error_message, fline line, char *file, bool new, INTER_FUNCTIONSIG_NOT_ST);
  196. void setResultOperationNone(Result *ru, Inter *inter, LinkValue *belong);
  197. void setResultOperation(Result *ru, LinkValue *value);
  198. void setResultOperationBase(Result *ru, LinkValue *value);
  199. void freeResult(Result *ru);
  200. void freeResultSafe(Result *ru);
  201. Package *makePackage(Value *value, char *md5, char *name, Package *base);
  202. void freePackage(Package *base);
  203. Value *checkPackage(Package *base, char *md5, char *name);
  204. Error *makeError(wchar_t *type, wchar_t *message, fline line, char *file);
  205. void freeError(Result *base);
  206. Error *connectError(Error *new, Error *base);
  207. void printError(Result *result, Inter *inter, bool free);
  208. void printValue(Value *value, FILE *debug, bool print_father, bool print_in);
  209. void printLinkValue(LinkValue *value, char *first, char *last, FILE *debug);
  210. bool isType(Value *value, enum ValueType type);
  211. Inherit *makeInherit(LinkValue *value);
  212. Inherit *copyInherit(Inherit *value);
  213. Inherit *freeInherit(Inherit *value);
  214. Inherit *connectInherit(Inherit *base, Inherit *back);
  215. Inherit *connectSafeInherit(Inherit *base, Inherit *back);
  216. bool checkAttribution(Value *self, Value *father);
  217. Inherit *getInheritFromValueCore(LinkValue *num_father);
  218. bool callDel(Value *object_value, Result *result, Inter *inter, VarList *var_list);
  219. bool needDel(Value *object_value, Inter *inter);
  220. #endif //VIRTUALMATH_VALUE_H