inter.hpp 2.6 KB

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