activation.h 2.9 KB

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