core_inter.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef AFUN_CORE_INTER_H
  2. #define AFUN_CORE_INTER_H
  3. #include <list>
  4. #include <mutex>
  5. #include "aFunCoreExport.h"
  6. #include "aFuntool.h"
  7. #include "aFuncode.h"
  8. #include "core_env_var.h"
  9. #include "core_message_stream.h"
  10. #include "core_activation.h"
  11. #include "core_object.h"
  12. #include "core_environment.h"
  13. namespace aFuncore {
  14. class Inter;
  15. class AFUN_CORE_EXPORT Inter {
  16. friend class Activation;
  17. struct LiteralRegex;
  18. public:
  19. typedef enum InterStatus {
  20. inter_init = 0, // 执行初始化程序
  21. inter_normal = 1, // 正常执行
  22. inter_stop = 2, // 当前运算退出
  23. inter_exit = 3, // 解释器退出
  24. } InterStatus;
  25. explicit Inter(Environment &env_);
  26. Inter(const Inter &base_inter);
  27. ~Inter();
  28. Inter &operator=(const Inter &) = delete;
  29. void enable();
  30. [[nodiscard]] AFUN_INLINE InterStatus getStatus() const;
  31. [[nodiscard]] AFUN_INLINE bool isInterStop() const;
  32. [[nodiscard]] AFUN_INLINE bool isInterExit() const;
  33. [[nodiscard]] AFUN_INLINE Environment &getEnvironment();
  34. [[nodiscard]] AFUN_INLINE const std::list<Activation *> &getStack() const;
  35. [[nodiscard]] AFUN_INLINE Activation *getActivation() const;
  36. [[nodiscard]] bool checkLiteral(const std::string &element) const;
  37. [[nodiscard]] bool checkLiteral(const std::string &element, std::string &literaler, bool &in_protect) const;
  38. [[nodiscard]] AFUN_INLINE EnvVarSpace &getEnvVarSpace();
  39. [[nodiscard]] AFUN_INLINE InterOutMessageStream &getOutMessageStream();
  40. [[nodiscard]] AFUN_INLINE InterInMessageStream &getInMessageStream();
  41. bool pushLiteral(const std::string &pattern, const std::string &literaler, bool in_protect);
  42. AFUN_INLINE void pushActivation(Activation *new_activation);
  43. AFUN_INLINE Activation *popActivation();
  44. bool runCode();
  45. AFUN_INLINE InterStatus setInterStop();
  46. AFUN_INLINE InterStatus setInterExit();
  47. private:
  48. InterStatus status;
  49. Environment &env;
  50. std::list<Activation *> stack;
  51. Activation *activation; // 活动记录
  52. InterOutMessageStream out;
  53. InterInMessageStream in;
  54. std::list<LiteralRegex> literal;
  55. };
  56. struct Inter::LiteralRegex {
  57. aFuntool::Regex rg;
  58. std::string pattern; // 派生 LiteralRegex 时使用
  59. std::string literaler; // 调用的函数
  60. bool in_protect; // 是否在protect空间
  61. };
  62. }
  63. #include "core_inter.inline.h"
  64. #endif //AFUN_CORE_INTER_H