activation.h 2.7 KB

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