inter.h 2.8 KB

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