inter.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef AFUN_INTER_H
  2. #define AFUN_INTER_H
  3. #include <list>
  4. #include "aFuntool.h"
  5. #include "aFunCoreExport.h"
  6. #include "core.h"
  7. #include "value.h"
  8. #include "var.h"
  9. #include "activation.h"
  10. namespace aFuncore {
  11. class AFUN_CORE_EXPORT Inter {
  12. public:
  13. explicit Inter(int argc=0, char **argv=nullptr, ExitMode em=em_activity);
  14. Inter(const Inter &base_inter, ExitMode em=em_activity);
  15. ~Inter();
  16. Inter &operator=(const Inter &)=delete;
  17. void enable();
  18. [[nodiscard]] inline InterStatus getStatus() const;
  19. [[nodiscard]] inline bool isExit() const;
  20. [[nodiscard]] inline ProtectVarSpace *getProtectVarSpace() const;
  21. [[nodiscard]] inline VarSpace *getGlobalVarSpace() const;
  22. [[nodiscard]] inline VarList *getGlobalVarlist() const;
  23. [[nodiscard]] inline Activation *getActivation() const;
  24. [[nodiscard]] bool checkLiteral(const std::string &element) const;
  25. [[nodiscard]] bool checkLiteral(const std::string &element, std::string &literaler, bool &in_protect) const;
  26. [[nodiscard]] inline EnvVarSpace &getEnvVarSpace();
  27. bool pushLiteral(const std::string &pattern, const std::string &literaler, bool in_protect);
  28. bool runCode();
  29. bool runCode(Code *code);
  30. private:
  31. /* 解释器原信息记录 */
  32. InterStatus status;
  33. /* GC 记录器 */
  34. struct GcRecord;
  35. struct GcRecord *gc;
  36. [[nodiscard]] inline struct GcRecord *getGcRecord() const;
  37. friend Object::Object(const std::string &type_, Inter &inter_);
  38. friend Var::Var(Object *data_, Inter &inter_);
  39. friend VarSpace::VarSpace(Inter &inter_);
  40. /* 运行相关 */
  41. ProtectVarSpace *protect; // 保护变量空间
  42. VarSpace *global; // 全局变量空间
  43. VarList *global_varlist; // global + protect
  44. Activation *activation; // 活动记录
  45. InterMessage out;
  46. InterMessage in;
  47. inline void pushActivation(Activation *new_activation);
  48. friend Activation::Activation(Inter &inter_);
  49. struct LiteralRegex;
  50. std::list<LiteralRegex> literal;
  51. /* 配置信息记录器 */
  52. EnvVarSpace &envvar;
  53. /* 线程信息 */
  54. public:
  55. const bool is_derive; // 是否派生
  56. Inter &base; // 主线程
  57. private:
  58. Object *result; // 线程执行的结果
  59. std::list<Inter *> *son_inter; // 派生线程链表, 由主线程负责管理
  60. ExitFlat exit_flat; // 外部设置退出
  61. ExitMode exit_mode; // 退出模式
  62. };
  63. struct Inter::GcRecord {
  64. Object *obj;
  65. Var *var;
  66. VarSpace *varspace;
  67. };
  68. struct Inter::LiteralRegex {
  69. Regex rg;
  70. std::string pattern; // 派生 LiteralRegex 时使用
  71. std::string literaler; // 调用的函数
  72. bool in_protect; // 是否在protect空间
  73. };
  74. }
  75. #include "inter.inline.h"
  76. #endif //AFUN_INTER_H