Browse Source

refactor & feat: 调整默认EnvVar设置

SongZihuan 3 years ago
parent
commit
d2e37fb036
4 changed files with 14 additions and 27 deletions
  1. 0 5
      include/core/inter.h
  2. 3 4
      src/core/activation.cpp
  3. 7 5
      src/core/inter.cpp
  4. 4 13
      test/src/run-code.cpp

+ 0 - 5
include/core/inter.h

@@ -59,11 +59,6 @@ namespace aFuncore {
             inter_exit = 3,  // 解释器退出
         } InterStatus;
 
-        typedef enum Prefix {
-            prefix_quote = 0,  // 变量引用
-            prefix_exec_first = 1,
-        } Prefix;
-
         AFUN_STATIC const int PREFIX_COUNT = 2;  // env 记录的前缀  TODO-szh 取消
 
         explicit Inter(Environment &env_);

+ 3 - 4
src/core/activation.cpp

@@ -268,10 +268,9 @@ namespace aFuncore {
                     return as_run;
                 case aFuncode::Code::ByteCode::block_b: {
                     std::string prefix;
-                    if (!inter.getEnvVarSpace().findString("sys:prefix", prefix) ||
-                        prefix.size() != Inter::PREFIX_COUNT)
-                        prefix = "''";
-                    char quote = prefix[Inter::prefix_quote];
+                    if (!inter.getEnvVarSpace().findString("sys:prefix-quote", prefix) || prefix.size() != 1)
+                        prefix = "'";
+                    char quote = prefix[0];
                     for (aFuncode::Code::ByteCode *var = call->getSon(); var != nullptr; var = var->toNext()) {
                         if (var->getType() != aFuncode::Code::ByteCode::code_element || var->getPrefix() == quote ||
                             inter.checkLiteral(var->getElement()))

+ 7 - 5
src/core/inter.cpp

@@ -173,7 +173,12 @@ namespace aFuncore {
             }
             Object::deleteUnreachable(del);
             Object::destructUnreachable(des, gc_inter);
-            aFuntool::safeSleep(1);
+
+            int32_t intervals = 1000;
+            envvar.findNumber("sys:gc-intervals", intervals);
+            if (intervals < 100)
+                intervals = 100;
+            std::this_thread::sleep_for(std::chrono::milliseconds(intervals));
         }
 
         Object::destructAll(gc, gc_inter); /* 不需要mutex锁 */
@@ -183,12 +188,9 @@ namespace aFuncore {
         : reference{0}, destruct{false}, gc_inter{*(new Inter(*this))}, protect{new ProtectVarSpace(*this)} {
         /* 生成 gc_inter 后, reference == 1 */
 
-        envvar.setNumber("sys:gc-runtime", 2);
-        envvar.setString("sys:prefix", "''");  // 引用,顺序执行
+        envvar.setNumber("sys:gc-intervals", 1000);
         envvar.setNumber("sys:exit-code", 0);
         envvar.setNumber("sys:argc", argc);
-        envvar.setNumber("sys:error_std", 0);
-
         for (int i = 0; i < argc; i++) {
             char buf[20];
             snprintf(buf, 10, "sys:arg%d", i);

+ 4 - 13
test/src/run-code.cpp

@@ -158,18 +158,10 @@ void printMessage(const std::string &type, aFuncore::Message *msg, aFuncore::Int
         if (msg_ == nullptr)
             return;
         int32_t error_std = 0;
-        inter.getEnvVarSpace().findNumber("sys:error_std", error_std);
-        if (error_std == 0) {
-            aFuntool::printf_stderr(0, "Error TrackBack\n");
-            for (auto &begin: msg_->getTrackBack())
-                aFuntool::printf_stderr(0, "  File \"%s\", line %d\n", begin.path.c_str(), begin.line);
-            aFuntool::printf_stderr(0, "%s: %s\n", msg_->getErrorType().c_str(), msg_->getErrorInfo().c_str());
-        } else {
-            aFuntool::printf_stdout(0, "Error TrackBack\n");
-            for (auto &begin: msg_->getTrackBack())
-                aFuntool::printf_stdout(0, "  File \"%s\", line %d\n", begin.path.c_str(), begin.line);
-            aFuntool::printf_stdout(0, "%s: %s\n", msg_->getErrorType().c_str(), msg_->getErrorInfo().c_str());
-        }
+        aFuntool::printf_stdout(0, "Error TrackBack\n");
+        for (auto &begin: msg_->getTrackBack())
+            aFuntool::printf_stdout(0, "  File \"%s\", line %d\n", begin.path.c_str(), begin.line);
+        aFuntool::printf_stdout(0, "%s: %s\n", msg_->getErrorType().c_str(), msg_->getErrorInfo().c_str());
     }
 }
 
@@ -219,7 +211,6 @@ int Main() {
     aFuntool::cout << "import: " << import << "\n";
     import->delReference();
 
-    inter.getEnvVarSpace().setNumber("sys:error_std", 1);
     auto tmp = new Func1(inter);
     aFuntool::cout << "tmp: " << tmp << "\n\n";
     tmp->delReference();