core-activation.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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(Code *&code) = 0;
  25. virtual void runCode(Code *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::StringFilePath &getFilePath() const;
  33. protected:
  34. Activation *prev;
  35. VarList *varlist;
  36. UpMessage up;
  37. DownMessage down;
  38. aFuntool::StringFilePath path;
  39. aFuntool::FileLine line;
  40. virtual void runCodeElement(Code *code);
  41. virtual void runCodeBlockP(Code *code);
  42. virtual void runCodeBlockC(Code *code);
  43. virtual void runCodeBlockB(Code *code);
  44. };
  45. class AFUN_CORE_EXPORT ExeActivation : public Activation {
  46. public:
  47. explicit inline ExeActivation(Code *code, Inter &inter_);
  48. ActivationStatus getCode(Code *&code) override;
  49. [[nodiscard]] inline Code *getStart() const;
  50. private:
  51. Code *start;
  52. Code *next;
  53. bool first=true;
  54. };
  55. class AFUN_CORE_EXPORT TopActivation : public ExeActivation {
  56. public:
  57. explicit TopActivation(Code *code, Inter &inter_);
  58. ~TopActivation() override;
  59. };
  60. class AFUN_CORE_EXPORT FuncActivation : public Activation {
  61. public:
  62. explicit inline FuncActivation(Code *code, Inter &inter_);
  63. ~FuncActivation() override;
  64. ActivationStatus getCode(Code *&code) override;
  65. void endRun() override;
  66. private:
  67. enum {
  68. func_first = 0,
  69. func_get_func = 1,
  70. func_get_arg = 2,
  71. } status = func_first;
  72. bool on_tail = false;
  73. Code *call;
  74. Function *func = nullptr;
  75. Function::CallFunction *call_func = nullptr;
  76. std::list<Function::CallFunction::ArgCodeList> *acl = nullptr;
  77. std::list<Function::CallFunction::ArgCodeList>::iterator acl_begin;
  78. std::list<Function::CallFunction::ArgCodeList>::iterator acl_end;
  79. };
  80. }
  81. #include "core-activation.inline.h"
  82. #include "core-activation.template.h"
  83. #endif //AFUN_CORE_ACTIVATION_H