activation.hpp 2.5 KB

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