2
0

core-activation.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef AFUN_CORE_ACTIVATION_H
  2. #define AFUN_CORE_ACTIVATION_H
  3. #include "aFuntool.h"
  4. #include "aFunCoreExport.h"
  5. #include "msg.h"
  6. #include "code.h"
  7. #include "object-value.h"
  8. #include "varlist.h"
  9. namespace aFuncore {
  10. class Inter;
  11. class AFUN_CORE_EXPORT Activation {
  12. public:
  13. typedef enum ActivationStatus {
  14. as_run = 0,
  15. as_end = 1,
  16. as_end_run = 2,
  17. } ActivationStatus;
  18. Inter &inter;
  19. explicit Activation(Inter &inter_);
  20. virtual ~Activation();
  21. Activation &operator=(const Activation &)=delete;
  22. virtual ActivationStatus getCode(const Code::ByteCode *&code) = 0;
  23. virtual void runCode(const Code::ByteCode *code);
  24. virtual void endRun();
  25. [[nodiscard]] inline VarList *getVarlist() const;
  26. [[nodiscard]] inline UpMessage &getUpStream();
  27. [[nodiscard]] inline DownMessage &getDownStream();
  28. [[nodiscard]] inline aFuntool::FileLine getFileLine() const;
  29. [[nodiscard]] inline const aFuntool::FilePath &getFilePath() const;
  30. protected:
  31. VarList *varlist;
  32. UpMessage up;
  33. DownMessage down;
  34. aFuntool::FilePath path;
  35. aFuntool::FileLine line;
  36. virtual void runCodeElement(const Code::ByteCode *code);
  37. virtual void runCodeBlockP(const Code::ByteCode *code);
  38. virtual void runCodeBlockC(const Code::ByteCode *code);
  39. virtual void runCodeBlockB(const Code::ByteCode *code);
  40. };
  41. class AFUN_CORE_EXPORT ExeActivation : public Activation {
  42. public:
  43. inline ExeActivation(const Code &code, Inter &inter_);
  44. inline ExeActivation(const Code::ByteCode *code, Inter &inter_);
  45. ActivationStatus getCode(const Code::ByteCode *&code) override;
  46. [[nodiscard]] inline const Code::ByteCode *getStart() const;
  47. private:
  48. const Code::ByteCode *start;
  49. const Code::ByteCode *next;
  50. bool first=true;
  51. };
  52. class AFUN_CORE_EXPORT TopActivation : public ExeActivation {
  53. public:
  54. explicit TopActivation(const Code &code, Inter &inter_);
  55. ~TopActivation() override = default;
  56. [[nodiscard]] inline const Code &getBase() const;
  57. private:
  58. const Code &base;
  59. };
  60. class AFUN_CORE_EXPORT FuncActivation : public Activation {
  61. public:
  62. explicit inline FuncActivation(const Code::ByteCode *code, Inter &inter_);
  63. explicit FuncActivation(Function *func, Inter &inter_);
  64. ~FuncActivation() override;
  65. ActivationStatus getCode(const Code::ByteCode *&code) override;
  66. void endRun() override;
  67. private:
  68. enum {
  69. func_first = 0, // 获取函数体前准备
  70. func_get_func = 1, // 获取函数体后,开始获取参数前
  71. func_get_arg = 2, // 获取参数过程
  72. } status = func_first;
  73. bool on_tail = false;
  74. const Code::ByteCode *call;
  75. Function *func = nullptr;
  76. Function::CallFunction *call_func = nullptr;
  77. std::list<Function::CallFunction::ArgCodeList> *acl = nullptr;
  78. std::list<Function::CallFunction::ArgCodeList>::iterator acl_begin;
  79. std::list<Function::CallFunction::ArgCodeList>::iterator acl_end;
  80. };
  81. }
  82. #include "core-activation.inline.h"
  83. #endif //AFUN_CORE_ACTIVATION_H