activation.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. public:
  16. Inter *const inter;
  17. StringFilePath path;
  18. FileLine line;
  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. };
  29. class ExeActivation : public Activation {
  30. Code *start;
  31. Code *next;
  32. bool first=true;
  33. public:
  34. explicit ExeActivation(Code *code, Inter *inter_) : Activation(inter_), start{code}, next{code} {}
  35. ActivationStatus getCode(Code *&code) override;
  36. [[nodiscard]] Code *getStart() const {return start;}
  37. };
  38. class TopActivation : public ExeActivation {
  39. public:
  40. explicit TopActivation(Code *code, Inter *inter_);
  41. ~TopActivation() override;
  42. };
  43. class FuncActivation : public Activation {
  44. enum {
  45. func_first = 0,
  46. func_get_func = 1,
  47. func_get_arg = 2,
  48. } status = func_first;
  49. bool on_tail = false;
  50. Code *call;
  51. Function *func = nullptr;
  52. Function::CallFunction *call_func = nullptr;
  53. std::list<Function::CallFunction::ArgCodeList> *acl = nullptr;
  54. std::list<Function::CallFunction::ArgCodeList>::iterator acl_begin;
  55. std::list<Function::CallFunction::ArgCodeList>::iterator acl_end;
  56. public:
  57. explicit FuncActivation(Code *code, Inter *inter_) : Activation(inter_), call{code,} {}
  58. ~FuncActivation() override;
  59. ActivationStatus getCode(Code *&code) override;
  60. void endRun() override;
  61. };
  62. }
  63. #endif //AFUN_ACTIVATION_HPP