1
0

inter.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef VIRTUALMATH_INTER_H
  2. #define VIRTUALMATH_INTER_H
  3. struct Result;
  4. /* 100 大概是最好的值 */
  5. #define RUNGC (100)
  6. #define SHOULD_RUNGC(inter) ((inter)->data.start_gc && (inter)->data.run_gc >= RUNGC)
  7. #define BASEOBJSZIE (18)
  8. #define VARNAMESIZE (10)
  9. #define BASEEXCESIZE (20)
  10. #define MAGFUNCSIZE (46)
  11. #define B_OBJECT (0)
  12. #define B_VOBJECT (1)
  13. #define B_INT_ (2)
  14. #define B_DOU (3)
  15. #define B_STR (4)
  16. #define B_BOOL (5)
  17. #define B_PASS (6)
  18. #define B_LIB (7)
  19. #define B_FILE (8)
  20. #define B_TUPLE (9)
  21. #define B_LIST (10)
  22. #define B_DICT (11)
  23. #define B_FUNCTION (12)
  24. #define B_NONE (13)
  25. #define B_LISTITER (14)
  26. #define B_DICTITER (15)
  27. #define B_POINTER (16)
  28. #define B_STRUCT (17)
  29. #define VN_str (0)
  30. #define VN_num (1)
  31. #define VN_bool (2)
  32. #define VN_file (3)
  33. #define VN_none (4)
  34. #define VN_pass (5)
  35. #define VN_class (6)
  36. #define VN_obj (7)
  37. #define VN_dict (8)
  38. #define VN_tuple (9)
  39. #define M_INIT (0)
  40. #define M_NEW (1)
  41. #define M_CALL (2)
  42. #define M_ENTER (3)
  43. #define M_EXIT (4)
  44. #define M_ADD (5)
  45. #define M_SUB (6)
  46. #define M_MUL (7)
  47. #define M_DIV (8)
  48. #define M_DEL (9)
  49. #define M_DOWN (10)
  50. #define M_SLICE (11)
  51. #define M_ITER (12)
  52. #define M_NEXT (13)
  53. #define M_REPO (14)
  54. #define M_BOOL (15)
  55. #define M_NAME (16)
  56. #define M_SELF (17)
  57. #define M_FATHER (18)
  58. #define M_MESSAGE (19)
  59. #define M_STR (20)
  60. #define M_DOWN_ASSIGMENT (21)
  61. #define M_SLICE_ASSIGMENT (22)
  62. #define M_DOWN_DEL (23)
  63. #define M_SLICE_DEL (24)
  64. #define M_ATTR (25)
  65. #define M_VAL (26)
  66. #define M_INTDIV (27)
  67. #define M_MOD (28)
  68. #define M_POW (29)
  69. #define M_BAND (30)
  70. #define M_BOR (31)
  71. #define M_BXOR (32)
  72. #define M_BNOT (33)
  73. #define M_BL (34)
  74. #define M_BR (35)
  75. #define M_EQ (36)
  76. #define M_MOREEQ (37)
  77. #define M_LESSEQ (38)
  78. #define M_MORE (39)
  79. #define M_LESS (40)
  80. #define M_NOTEQ (41)
  81. #define M_AND (42)
  82. #define M_OR (43)
  83. #define M_NOT (44)
  84. #define M_NEGATE (45)
  85. struct ClibInfo {
  86. void *dl;
  87. struct ClibInfo *next;
  88. };
  89. struct Inter{
  90. struct Value *base;
  91. struct LinkValue *link_base;
  92. struct HashTable *hash_base;
  93. struct Var *base_var;
  94. struct LinkValue *base_belong;
  95. struct Package *package;
  96. struct SignalList *sig_list;
  97. struct ClibInfo *clib_info;
  98. struct VarList *var_list;
  99. struct InterData{
  100. FILE *inter_stdout;
  101. FILE *inter_stderr;
  102. FILE *inter_stdin;
  103. bool is_stdout;
  104. bool is_stderr;
  105. bool is_stdin;
  106. struct LinkValue *base_obj[BASEOBJSZIE];
  107. struct LinkValue *base_exc[BASEEXCESIZE];
  108. wchar_t *var_name[VARNAMESIZE];
  109. wchar_t *mag_func[MAGFUNCSIZE];
  110. int default_pt_type;
  111. size_t var_max;
  112. int var_deep;
  113. enum AssertRunType {
  114. assert_ignore, // 忽略一切
  115. assert_run, // 仅执行
  116. assert_raise, // 执行并生效
  117. } assert_run;
  118. int run_gc; // gc的启动计数
  119. bool start_gc; // 是否启动gc
  120. bool free_mode; // 自由模式(若为true, 则在makeValue的使用完全通过callBack执行)
  121. enum OptMode {
  122. om_free, // 完全通过callBack执行
  123. om_normal, // 只要ValueType不是obj或class就通过静态方法执行
  124. om_simple, // buildin 类型都通过静态方法执行
  125. } opt_mode; // 表达式执行模式
  126. bool value_folding; // 常量折叠[on]
  127. bool opt_folding; // 表达式折叠[on]
  128. bool cyc_folding; // 在循环内部自动打开折叠
  129. bool func_folding; // 在函数内部自动打开
  130. char *env; // 执行目录
  131. } data;
  132. };
  133. typedef struct Inter Inter;
  134. typedef struct Statement Statement;
  135. typedef enum ResultType ResultType;
  136. typedef struct ClibInfo ClibInfo;
  137. Inter *makeInter(char *out, char *error_, char *in, char *env, LinkValue *belong);
  138. void freeInter(Inter *inter, bool show_gc);
  139. void setBaseInterData(struct Inter *inter);
  140. void runCodeStdin(Inter *inter, char *hello_string);
  141. void runCodeFile(Inter *inter, char *file[]);
  142. bool runParser(char *code_file, Inter *inter, bool is_one, Statement **st);
  143. void mergeInter(Inter *new, Inter *base);
  144. Inter *deriveInter(char *env, LinkValue *belong, Inter *inter);
  145. ClibInfo *makeClibInfo();
  146. void makeClibInfoToInter(void *dl, Inter *inter);
  147. ClibInfo *freeClibInfo(ClibInfo *info);
  148. void freeClibInfoFromInter(Inter *inter);
  149. void changeInterEnv(char *env, bool split, Inter *inter);
  150. #endif //VIRTUALMATH_INTER_H