瀏覽代碼

refactor & feat: 调整部分API

SongZihuan 3 年之前
父節點
當前提交
13be52a046
共有 6 個文件被更改,包括 24 次插入24 次删除
  1. 7 7
      include/core/msg.h
  2. 4 4
      include/core/value.h
  3. 1 1
      include/core/value.inline.h
  4. 7 7
      src/core/activation.cpp
  5. 2 2
      src/core/msg.cpp
  6. 3 3
      test/src/run-code.cpp

+ 7 - 7
include/core/msg.h

@@ -22,21 +22,21 @@ namespace aFuncore {
         Message *next;  // 下一条消息
     };
 
+    class Object;
+    class Activation;
+    class Inter;
+
     class TopMessage : public Message {
     public:
         explicit inline TopMessage(const std::string &type_);
-        virtual void topProgress() = 0;
+        virtual void topProgress(Inter &inter, Activation &activation) = 0;
     };
 
-    class Object;
-    class Activation;
-    class Inter;
-
     class AFUN_CORE_EXPORT NormalMessage : public TopMessage {
     public:
         explicit inline NormalMessage(Object *obj_);
         ~NormalMessage() override;
-        void topProgress() override;
+        void topProgress(Inter &inter, Activation &activation) override;
         inline Object *getObject();
 
     private:
@@ -46,7 +46,7 @@ namespace aFuncore {
     class AFUN_CORE_EXPORT ErrorMessage : public TopMessage {
     public:
         explicit ErrorMessage(const std::string &error_type_, const std::string &error_info_, Activation *activation);
-        void topProgress() override;
+        void topProgress(Inter &inter_, Activation &activation) override;
         inline std::string getErrorType();
         inline std::string getErrorInfo();
 

+ 4 - 4
include/core/value.h

@@ -36,7 +36,7 @@ namespace aFuncore {
         CallFunction(const CallFunction &)=delete;
         CallFunction &operator=(const CallFunction &)=delete;
 
-        virtual std::list<ArgCodeList> *getArgCodeList() = 0;
+        virtual std::list<ArgCodeList> *getArgCodeList(Inter &inter, Activation &activation, Code::ByteCode *call) = 0;
         virtual void runFunction() = 0;
     };
 
@@ -48,14 +48,14 @@ namespace aFuncore {
     class AFUN_CORE_EXPORT Literaler : public Object {
     public:
         inline Literaler(const std::string &type_, Inter &inter_);
-        virtual void getObject(const std::string &literal, char prefix, Inter &inter) = 0;
+        virtual void getObject(const std::string &literal, char prefix, Inter &inter, Activation &activation) = 0;
     };
 
     class AFUN_CORE_EXPORT CallBackVar : public Object {
     public:
         inline CallBackVar(const std::string &type_, Inter &inter_);
-        virtual inline bool isCallBack();
-        virtual void callBack(Inter &inter) = 0;
+        virtual inline bool isCallBack(Inter &inte, Activation &activation);
+        virtual void callBack(Inter &inte, Activation &activation) = 0;
     };
 };
 

+ 1 - 1
include/core/value.inline.h

@@ -19,7 +19,7 @@ namespace aFuncore {
 
     }
 
-    inline bool CallBackVar::isCallBack() {
+    inline bool CallBackVar::isCallBack(Inter &inter, Activation &activation) {
         return true;
     }
 };

+ 7 - 7
src/core/activation.cpp

@@ -77,7 +77,7 @@ namespace aFuncore {
                 obj = varlist->findObject(literaler_name);
             auto literaler = dynamic_cast<Literaler *>(obj);
             if (literaler != nullptr)
-                literaler->getObject(code->getElement(), code->getPrefix(), inter);
+                literaler->getObject(code->getElement(), code->getPrefix(), inter, *this);
             else
                 down.pushMessage(new ErrorMessage("TypeError", "Error type of literal.", this));
         } else {
@@ -85,8 +85,8 @@ namespace aFuncore {
                 obj = varlist->findObject(code->getElement());
             if (obj != nullptr) {
                 auto cbv = dynamic_cast<CallBackVar *>(obj);
-                if (cbv != nullptr && cbv->isCallBack())
-                    cbv->callBack(inter);
+                if (cbv != nullptr && cbv->isCallBack(inter, *this))
+                    cbv->callBack(inter, *this);
                 else
                     down.pushMessage(new NormalMessage(obj));
             } else
@@ -133,14 +133,14 @@ namespace aFuncore {
         varlist->connect(inter_.getGlobalVarlist());
     }
 
-    static void ActivationTopProgress(Message *msg, void *){
+    static void ActivationTopProgress(Message *msg, Inter &inter, Activation &activation){
         auto *t = dynamic_cast<TopMessage *>(msg);
         if (t)
-            t->topProgress();
+            t->topProgress(inter, activation);
     };
 
     TopActivation::~TopActivation(){
-        down.forEach(ActivationTopProgress, nullptr);
+        down.forEach(ActivationTopProgress, std::ref(inter), std::ref(*this));
     }
 
     FuncActivation::~FuncActivation(){
@@ -218,7 +218,7 @@ namespace aFuncore {
             /* Label: 执行变量获取前的准备 */
             status = func_get_arg;
             call_func = func->getCallFunction(call, inter);
-            acl = call_func->getArgCodeList();
+            acl = call_func->getArgCodeList(inter, *this, call);
             acl_begin = acl->begin();
             acl_end = acl->end();
             if (acl_begin != acl_end) {  // 如果有参数需要计算

+ 2 - 2
src/core/msg.cpp

@@ -8,7 +8,7 @@ namespace aFuncore {
         this->obj = nullptr;
     }
 
-    void NormalMessage::topProgress(){
+    void NormalMessage::topProgress(Inter &inter, Activation &activation){
         aFuntool::printf_stdout(0, "NORMAL: %p\n", obj);  // TODO-szh 使用 Event
     }
 
@@ -20,7 +20,7 @@ namespace aFuncore {
         }
     }
 
-    void ErrorMessage::topProgress(){
+    void ErrorMessage::topProgress(Inter &inter_, Activation &activation){
         int32_t error_std = 0;
         inter.getEnvVarSpace().findNumber("sys:error_std", error_std);
         if (error_std == 0) {

+ 3 - 3
test/src/run-code.cpp

@@ -16,7 +16,7 @@ class Func1 : public Function {
             acl->push_front(agr1);
         }
 
-        std::list<ArgCodeList> *getArgCodeList() override {
+        std::list<ArgCodeList> *getArgCodeList(Inter &inter_, Activation &activation, Code::ByteCode *call) override {
             return acl;
         }
 
@@ -58,7 +58,7 @@ public:
 
     ~Literaler1() override = default;
 
-    void getObject(const std::string &literal, char prefix, Inter &inter) override {
+    void getObject(const std::string &literal, char prefix, Inter &inter, Activation &activation) override {
         aFuntool::cout << "Literaler1: " << literal << (prefix == NUL ? '-' : prefix) << "\n";
         new ExeActivation(func_code, inter);
     }
@@ -75,7 +75,7 @@ public:
 
     ~CBV1() override = default;
 
-    void callBack(Inter &inter) override {
+    void callBack(Inter &inter, Activation &activation) override {
         aFuntool::cout << "CallBackVar callback\n";
         new ExeActivation(func_code, inter);
     }