core-activation.h 3.2 KB

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