core-activation.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef AFUN_CORE_ACTIVATION_H
  2. #define AFUN_CORE_ACTIVATION_H
  3. #include "aFuntool.h"
  4. #include "aFunCoreExport.h"
  5. #include "msg.h"
  6. #include "code.h"
  7. #include "value.h"
  8. #include "var.h"
  9. namespace aFuncore {
  10. class Inter;
  11. class AFUN_CORE_EXPORT Activation {
  12. public:
  13. typedef enum ActivationStatus {
  14. as_run = 0,
  15. as_end = 1,
  16. as_end_run = 2,
  17. } ActivationStatus;
  18. Inter &inter;
  19. template <typename Callable,typename...T>
  20. static void forEach(Activation *activation, Callable func, T...arg);
  21. explicit Activation(Inter &inter_);
  22. virtual ~Activation();
  23. Activation &operator=(const Activation &)=delete;
  24. virtual ActivationStatus getCode(const Code::ByteCode *&code) = 0;
  25. virtual void runCode(const Code::ByteCode *code);
  26. virtual inline void endRun();
  27. [[nodiscard]] inline VarList *getVarlist() const;
  28. [[nodiscard]] inline Activation *toPrev() const;
  29. [[nodiscard]] inline UpMessage &getUpStream();
  30. [[nodiscard]] inline DownMessage &getDownStream();
  31. [[nodiscard]] inline aFuntool::FileLine getFileLine() const;
  32. [[nodiscard]] inline const aFuntool::FilePath &getFilePath() const;
  33. protected:
  34. Activation *prev;
  35. VarList *varlist;
  36. UpMessage up;
  37. DownMessage down;
  38. aFuntool::FilePath path;
  39. aFuntool::FileLine line;
  40. virtual void runCodeElement(const Code::ByteCode *code);
  41. virtual void runCodeBlockP(const Code::ByteCode *code);
  42. virtual void runCodeBlockC(const Code::ByteCode *code);
  43. virtual void runCodeBlockB(const Code::ByteCode *code);
  44. };
  45. class AFUN_CORE_EXPORT ExeActivation : public Activation {
  46. public:
  47. inline ExeActivation(const Code &code, Inter &inter_);
  48. inline ExeActivation(const Code::ByteCode *code, Inter &inter_);
  49. ActivationStatus getCode(const Code::ByteCode *&code) override;
  50. [[nodiscard]] inline const Code::ByteCode *getStart() const;
  51. private:
  52. const Code::ByteCode *start;
  53. const Code::ByteCode *next;
  54. bool first=true;
  55. };
  56. class AFUN_CORE_EXPORT TopActivation : public ExeActivation {
  57. public:
  58. explicit TopActivation(const Code &code, Inter &inter_);
  59. ~TopActivation() override;
  60. [[nodiscard]] inline const Code &getBase() const;
  61. private:
  62. const Code &base;
  63. };
  64. class AFUN_CORE_EXPORT FuncActivation : public Activation {
  65. public:
  66. explicit inline FuncActivation(const Code::ByteCode *code, Inter &inter_);
  67. explicit FuncActivation(Function *func, Inter &inter_);
  68. ~FuncActivation() override;
  69. ActivationStatus getCode(const Code::ByteCode *&code) override;
  70. void endRun() override;
  71. private:
  72. enum {
  73. func_first = 0, // 获取函数体前准备
  74. func_get_func = 1, // 获取函数体后,开始获取参数前
  75. func_get_arg = 2, // 获取参数过程
  76. } status = func_first;
  77. bool on_tail = false;
  78. const Code::ByteCode *call;
  79. Function *func = nullptr;
  80. Function::CallFunction *call_func = nullptr;
  81. std::list<Function::CallFunction::ArgCodeList> *acl = nullptr;
  82. std::list<Function::CallFunction::ArgCodeList>::iterator acl_begin;
  83. std::list<Function::CallFunction::ArgCodeList>::iterator acl_end;
  84. };
  85. }
  86. #include "core-activation.inline.h"
  87. #include "core-activation.template.h"
  88. #endif //AFUN_CORE_ACTIVATION_H