activation.h 2.6 KB

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