activation.hpp 2.3 KB

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