activation.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. [[nodiscard]] VarList *getVarlist() const {return varlist;}
  24. [[nodiscard]] Activation *toPrev() const {return prev;}
  25. [[nodiscard]] UpMessage *getUpStream() const {return up;}
  26. [[nodiscard]] DownMessage *getDownStream() const {return down;}
  27. };
  28. class ExeActivation : public Activation {
  29. Code *start;
  30. Code *next;
  31. bool first=true;
  32. public:
  33. explicit ExeActivation(Code *code, Inter *inter_) : Activation(inter_), start{code}, next{code} {}
  34. ActivationStatus getCode(Code *&code) override;
  35. [[nodiscard]] Code *getStart() const {return start;}
  36. };
  37. class TopActivation : public ExeActivation {
  38. public:
  39. explicit TopActivation(Code *code, Inter *inter_);
  40. ~TopActivation() override;
  41. };
  42. class FuncActivation : public Activation {
  43. enum {
  44. func_first = 0,
  45. func_get_func = 1,
  46. func_get_arg = 2,
  47. } status = func_first;
  48. bool on_tail = false;
  49. Code *call;
  50. Function *func = nullptr;
  51. Function::CallFunction *call_func = nullptr;
  52. std::list<Function::CallFunction::ArgCodeList> *acl = nullptr;
  53. std::list<Function::CallFunction::ArgCodeList>::iterator acl_begin;
  54. std::list<Function::CallFunction::ArgCodeList>::iterator acl_end;
  55. public:
  56. explicit FuncActivation(Code *code, Inter *inter_) : Activation(inter_), call{code,} {}
  57. ~FuncActivation() override;
  58. ActivationStatus getCode(Code *&code) override;
  59. };
  60. }
  61. #endif //AFUN_ACTIVATION_HPP