소스 검색

refactor & feat: 添加解释器通信数据流

SongZihuan 3 년 전
부모
커밋
f9906d290a
5개의 변경된 파일31개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 0
      include/core/core.h
  2. 3 0
      include/core/inter.h
  3. 8 0
      include/core/msg.h
  4. 15 2
      include/core/msg.inline.h
  5. 4 0
      src/core/inter.cpp

+ 1 - 0
include/core/core.h

@@ -53,6 +53,7 @@ namespace aFuncore {
     class AFUN_CORE_EXPORT MessageStream;
     class AFUN_CORE_EXPORT UpMessage;
     class AFUN_CORE_EXPORT DownMessage;
+    class AFUN_CORE_EXPORT InterMessage;
 
     class AFUN_CORE_EXPORT Activation;
     class AFUN_CORE_EXPORT ExeActivation;

+ 3 - 0
include/core/inter.h

@@ -29,6 +29,9 @@ namespace aFuncore {
         VarSpace *global;  // 全局变量空间
         VarList *global_varlist;  // global + protect
         Activation *activation;  // 活动记录
+        InterMessage *out;
+        InterMessage *in;
+
         void pushActivation(Activation *new_activation);
 
         struct LiteralRegex {

+ 8 - 0
include/core/msg.h

@@ -10,6 +10,7 @@ namespace aFuncore {
         friend class MessageStream;
         friend class UpMessage;
         friend class DownMessage;
+        friend class InterMessage;
 
         Message *next;  // 下一条消息
     public:
@@ -84,6 +85,13 @@ namespace aFuncore {
     public:
         void joinMsg(DownMessage *msg);
     };
+
+    class AFUN_CORE_EXPORT InterMessage : public MessageStream {
+        pthread_mutex_t mutex{};
+    public:
+        InterMessage();
+        ~InterMessage() override ;
+    };
 }
 
 #include "msg.inline.h"

+ 15 - 2
include/core/msg.inline.h

@@ -19,8 +19,21 @@ namespace aFuncore {
         return obj;
     }
 
-    inline std::string ErrorMessage::getErrorType() {return error_type;}
-    inline std::string ErrorMessage::getErrorInfo() {return error_info;}
+    inline std::string ErrorMessage::getErrorType() {
+        return error_type;
+    }
+
+    inline std::string ErrorMessage::getErrorInfo() {
+        return error_info;
+    }
+
+    inline InterMessage::InterMessage() : MessageStream() {  // NOLINT mutex通过pthread_mutex_init初始化
+        pthread_mutex_init(&mutex, nullptr);
+    }
+
+    inline InterMessage::~InterMessage(){
+        pthread_mutex_destroy(&mutex);
+    }
 }
 
 #endif //AFUN_MSG_INLINE_H

+ 4 - 0
src/core/inter.cpp

@@ -47,6 +47,8 @@ Inter::Inter(int argc, char **argv, ExitMode em)
     global = new VarSpace(this);  // 放到最后
     global_varlist = new VarList(protect);
     global_varlist->push(global);
+    out = new InterMessage();
+    in = new InterMessage();
 
     status = inter_init;
 }
@@ -67,6 +69,8 @@ Inter::~Inter(){
         delete gc;
         delete son_inter;
         delete envvar;
+        delete out;
+        delete in;
     }
 }