inter.h 2.8 KB

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