Преглед изворни кода

feat: iterCode新增import模式

SongZihuan пре 3 година
родитељ
комит
b879de990d
5 измењених фајлова са 218 додато и 139 уклоњено
  1. 1 1
      include/core/run.h
  2. 34 7
      src/core/run.c
  3. 89 65
      src/main.c
  4. 1 0
      test/src/CMakeLists.txt
  5. 93 66
      test/src/run_code.c

+ 1 - 1
include/core/run.h

@@ -4,5 +4,5 @@
 #include "tool.h"
 #include "code.h"
 /* 代码运行 相关操作 */
-AFUN_CORE_EXPORT bool iterCode(af_Code *code, af_Environment *env);
+AFUN_CORE_EXPORT bool iterCode(af_Code *code, int mode, af_Environment *env);
 #endif //AFUN_RUN_H

+ 34 - 7
src/core/run.c

@@ -5,7 +5,7 @@
 #include "__env.h"
 
 /* 工具函数: 初始化类型 */
-static bool iterCodeInit(af_Code *code, af_Environment *env);
+static bool iterCodeInit(af_Code *code, int mode, af_Environment *env);
 
 /* 工具函数: Message类函数 */
 static af_Message *getTopMsg(af_Environment *env);
@@ -105,14 +105,41 @@ static bool checkRunGC(af_Environment *env) {
 /*
  * 函数名: iterCodeInit
  * 目标: 初始化activity和environment (若environment中未存在activity则通过code新增一个TopActivity, 否则沿用原activity)
+ *
+ * mode 标识运行模式
+ * 0. 在top运行
+ * 1. 在import运行
+ * 2. 直接运行
  */
-static bool iterCodeInit(af_Code *code, af_Environment *env) {
+static bool iterCodeInit(af_Code *code, int mode, af_Environment *env) {
     if (env == NULL || env->core == NULL || env->activity == NULL || env->core->status == core_exit)
         return false;
     if (env->core->status == core_stop)
         env->core->status = core_normal;
-    setActivityBtTop(code, env->activity);
-    setActivityBtStart(code, env->activity);
+
+    switch (mode) {
+        case 0:
+            if (env->activity->type != act_top || code == NULL || code->path == NULL)
+                return false;
+            setActivityBtTop(code, env->activity);
+            setActivityBtStart(code, env->activity);
+            break;
+        case 1: {
+            if (env->activity->type != act_top || code == NULL || code->path == NULL)
+                return false;
+            char *name = getFileName(code->path);
+            pushImportActivity(code, NULL, name, env);
+            printf("name = %s\n", name);
+            free(name);
+            break;
+        }
+        case 2:
+            if (env->activity->bt_start == NULL || env->activity->bt_next == NULL || code != NULL)
+                return false;
+            break;
+        default:
+            return false;
+    }
     return true;
 }
 
@@ -301,8 +328,8 @@ static bool checkStop(af_Environment *env) {
  *
  *      因为该函数的大部分内容运行在循环中, 因此使用continue表示不在运行后面的代码
  */
-bool iterCode(af_Code *code, af_Environment *env){
-    if (!iterCodeInit(code, env))
+bool iterCode(af_Code *code, int mode, af_Environment *env){
+    if (!iterCodeInit(code, mode, env))
         return false;
 
     /*
@@ -443,7 +470,7 @@ bool iterDestruct(int deep, af_Environment *env) {
         if (dl == NULL)
             return true;
         pushGCActivity(dl, pdl, env);
-        if (!iterCode(NULL, env))
+        if (!iterCode(NULL, 0, env))
             return false;
     }
     return false;

+ 89 - 65
src/main.c

@@ -875,8 +875,8 @@ int main() {
 
     {  // 正常程序
         printf("TAG A:\n");
-        af_Code *bt1 = makeElementCode("object", 0, 1, "Unknown");
-        af_Code *bt2 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("object", 0, 1, "taga.af");
+        af_Code *bt2 = makeElementCode("data", ',', 0, NULL);
         pushCode(&bt1, bt2);
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
@@ -886,14 +886,14 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 宏函数
         printf("TAG L:\n");
-        af_Code *bt1 = makeElementCode("object", 0, 1, NULL);
+        af_Code *bt1 = makeElementCode("object", 0, 1, "tagl.af");
 
         af_Code *bt3 = makeElementCode("func2", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
@@ -902,7 +902,7 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
@@ -910,7 +910,7 @@ int main() {
 
     {  // 尾调递归优化
         printf("TAG B:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "tagb.af");
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
@@ -918,23 +918,23 @@ int main() {
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
         pushCode(&bt2, bt5);
 
-        iterCode(bt5, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 尾调递归优化2
         printf("TAG C:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "tagc.af");
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 测试类前缀调用
         printf("TAG D:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "tagd.af");
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
@@ -945,77 +945,77 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 测试顺序执行 '(xxx)
-        printf("TAG H:\n");
+        printf("TAG E:\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, "tage.af", NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt5, env);
+        iterCode(bt5, 0, env);
         freeAllCode(bt5);
         printf("\n");
     }
 
     {  // 测试顺序执行 ,[xxx]
-        printf("TAG I:\n");
+        printf("TAG F:\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "tagf.af", NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt5, env);
+        iterCode(bt5, 0, env);
         freeAllCode(bt5);
         printf("\n");
     }
 
     {  // 测试顺序执行 '(xxx) 【尾调递归优化】
-        printf("TAG J:\n");
+        printf("TAG G:\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, "tagg.af", NULL);
 
-        iterCode(bt5, env);
+        iterCode(bt5, 0, env);
         freeAllCode(bt5);
         printf("\n");
     }
 
     {  // 测试顺序执行 ,[xxx] 【尾调递归优化】
-        printf("TAG K:\n");
+        printf("TAG H:\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "tagh.af", NULL);
 
-        iterCode(bt5, env);
+        iterCode(bt5, 0, env);
         freeAllCode(bt5);
         printf("\n");
     }
 
     {  // 双层尾调递归优化 (函数内调用函数)
-        printf("TAG M:\n");
+        printf("TAG I:\n");
         af_Code *bt2 = makeElementCode("func3", 0, 1, NULL);
-        af_Code *bt3 = makeBlockCode(curly, bt2, 0, 1, NULL, NULL);
+        af_Code *bt3 = makeBlockCode(curly, bt2, 0, 1, "tagi.af", NULL);
 
         af_Code *bt4 = makeElementCode("func3", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt4, 0, 1, NULL, NULL);
@@ -1024,107 +1024,125 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt3, env);
+        iterCode(bt3, 0, env);
         freeAllCode(bt3);
         printf("\n");
     }
 
     {  // 对象函数的调用
-        printf("TAG N:\n");
-        af_Code *bt1 = makeElementCode("func4", 0, 1, NULL);
+        printf("TAG J:\n");
+        af_Code *bt1 = makeElementCode("func4", 0, 1, "tagj.af");
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 变量引用调用
-        printf("TAG O:\n");
-        af_Code *bt1 = makeElementCode("func4", '\'', 1, NULL);
+        printf("TAG K:\n");
+        af_Code *bt1 = makeElementCode("func4", '\'', 1, "tagk.af");
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 对象函数的调用 (尾调递归优化)
-        printf("TAG P:\n");
-        af_Code *bt1 = makeElementCode("func4", 0, 1, "TagP.af");
+        printf("TAG L:\n");
+        af_Code *bt1 = makeElementCode("func4", 0, 1, "tagl.af");
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 函数调用
-        printf("TAG U:\n");
+        printf("TAG M:\n");
 
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagU.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tagm.af", NULL);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // gc测试
-        printf("TAG Q:\n");
+        printf("TAG N:\n");
 
         af_Code *bt2 = makeElementCode("func5", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagQ.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tagn.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
         pushCode(&bt3, bt4);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // func_body_dynamic 测试
-        printf("TAG R:\n");
+        printf("TAG O:\n");
 
         af_Code *bt2 = makeElementCode("func7", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagR.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tago.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 中缀调用测试
-        printf("TAG S:\n");
+        printf("TAG P:\n");
 
         af_Code *bt2 = makeElementCode("func8", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "TagS.af", NULL);
+        af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "Tagp.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // func_body_import 测试
-        printf("TAG X:\n");
+        printf("TAG Q:\n");
 
         af_Code *bt2 = makeElementCode("func10", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagX.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tagq.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
+        freeAllCode(bt1);
+        printf("\n");
+    }
+
+    {  // 导入式运行
+        printf("TAG R:\n");
+        af_Code *bt1 = makeElementCode("object", 0, 1, "tagr.af");
+        af_Code *bt2 = makeElementCode("data", ',', 0, NULL);
+        pushCode(&bt1, bt2);
+
+        af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
+        af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
+        pushCode(&bt2, bt5);
+
+        af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
+        pushCode(&bt5, bt6);
+
+        iterCode(bt1, 1, env);
         freeAllCode(bt1);
         printf("\n");
     }
@@ -1132,22 +1150,22 @@ int main() {
     /* 错误用例 */
 
     {  // 中缀调用测试
-        printf("TAG T: ERROR\n");
+        printf("TAG a: ERROR\n");
 
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "TagT.error.af", NULL);
+        af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "Taga-error.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 测试错误 (无函数指定)
-        printf("TAG F: ERROR\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        printf("TAG b: ERROR\n");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagb-error.af");
 
         af_Code *bt5 = makeBlockCode(curly, NULL, 0, 1, NULL, NULL);
         pushCode(&bt1, bt5);
@@ -1155,46 +1173,46 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 测试错误 (object2 Var not found)
-        printf("TAG G: ERROR\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        printf("TAG c: ERROR\n");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagc-error.af");
         af_Code *bt2 = makeElementCode("object2", 0, 1, NULL);
 
         pushCode(&bt1, bt2);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 中缀保护测试
-        printf("TAG V: ERROR\n");
+        printf("TAG d: ERROR\n");
 
         af_Code *bt2 = makeElementCode("func8", 0, 2, NULL);
-        af_Code *bt1 = makeElementCode("global", 0, 1, "TagV.error.af");
+        af_Code *bt1 = makeElementCode("global", 0, 1, "Tagd-error.af");
 
         pushCode(&bt1, bt2);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 错误回溯测试
-        printf("TAG W: ERROR\n");
+        printf("TAG e: ERROR\n");
 
         af_Code *bt2 = makeElementCode("func9", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagW.error.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tage-error.af", NULL);
 
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
@@ -1203,16 +1221,22 @@ int main() {
     freeEnvironment(env);
 
     printf("Exit at 0.");
+#ifndef IN_CTEST
     getc(stdin);
+#endif
     return 0;
 
 RETURN_1:
     printf("Exit at 1.");
+#ifndef IN_CTEST
     getc(stdin);
+#endif
     return 1;
 
 RETURN_2:
     printf("Exit at 2.");
+#ifndef IN_CTEST
     getc(stdin);
+#endif
     return 2;
 }

+ 1 - 0
test/src/CMakeLists.txt

@@ -7,6 +7,7 @@ foreach(src IN LISTS src_list)
     target_link_libraries(${file_name} aFun-ct-libs)  # 链接静态库 (导出所有符号)
     set_target_properties(${file_name}
                           PROPERTIES OUTPUT_NAME "test_${file_name}")
+    target_compile_definitions(${file_name} PRIVATE IN_CTEST)
     unset(file_name)
 endforeach()
 

+ 93 - 66
test/src/run_code.c

@@ -370,7 +370,7 @@ bool infixFunc(af_Object *obj) {
 }
 
 int main() {
-    aFunCoreInit();
+    aFunInit();
     printf("Hello World\n");
 
     af_Environment *env = makeEnvironment(grt_always);
@@ -875,8 +875,8 @@ int main() {
 
     {  // 正常程序
         printf("TAG A:\n");
-        af_Code *bt1 = makeElementCode("object", 0, 1, "Unknown");
-        af_Code *bt2 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("object", 0, 1, "taga.af");
+        af_Code *bt2 = makeElementCode("data", ',', 0, NULL);
         pushCode(&bt1, bt2);
 
         af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
@@ -886,14 +886,14 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 宏函数
         printf("TAG L:\n");
-        af_Code *bt1 = makeElementCode("object", 0, 1, NULL);
+        af_Code *bt1 = makeElementCode("object", 0, 1, "tagl.af");
 
         af_Code *bt3 = makeElementCode("func2", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
@@ -902,7 +902,7 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
@@ -910,7 +910,7 @@ int main() {
 
     {  // 尾调递归优化
         printf("TAG B:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "tagb.af");
         af_Code *bt2 = makeElementCode("object", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
@@ -918,23 +918,23 @@ int main() {
         af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
         pushCode(&bt2, bt5);
 
-        iterCode(bt5, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 尾调递归优化2
         printf("TAG C:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "tagc.af");
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 测试类前缀调用
         printf("TAG D:\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "tagd.af");
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
@@ -945,77 +945,77 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 测试顺序执行 '(xxx)
-        printf("TAG H:\n");
+        printf("TAG E:\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, "tage.af", NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt5, env);
+        iterCode(bt5, 0, env);
         freeAllCode(bt5);
         printf("\n");
     }
 
     {  // 测试顺序执行 ,[xxx]
-        printf("TAG I:\n");
+        printf("TAG F:\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "tagf.af", NULL);
 
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt5, env);
+        iterCode(bt5, 0, env);
         freeAllCode(bt5);
         printf("\n");
     }
 
     {  // 测试顺序执行 '(xxx) 【尾调递归优化】
-        printf("TAG J:\n");
+        printf("TAG G:\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(parentheses, bt3, '\'', 1, "tagg.af", NULL);
 
-        iterCode(bt5, env);
+        iterCode(bt5, 0, env);
         freeAllCode(bt5);
         printf("\n");
     }
 
     {  // 测试顺序执行 ,[xxx] 【尾调递归优化】
-        printf("TAG K:\n");
+        printf("TAG H:\n");
         af_Code *bt3 = makeElementCode("data2", 0, 0, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt3, bt4);
 
-        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, NULL, NULL);
+        af_Code *bt5 = makeBlockCode(brackets, bt3, ',', 1, "tagh.af", NULL);
 
-        iterCode(bt5, env);
+        iterCode(bt5, 0, env);
         freeAllCode(bt5);
         printf("\n");
     }
 
     {  // 双层尾调递归优化 (函数内调用函数)
-        printf("TAG M:\n");
+        printf("TAG I:\n");
         af_Code *bt2 = makeElementCode("func3", 0, 1, NULL);
-        af_Code *bt3 = makeBlockCode(curly, bt2, 0, 1, NULL, NULL);
+        af_Code *bt3 = makeBlockCode(curly, bt2, 0, 1, "tagi.af", NULL);
 
         af_Code *bt4 = makeElementCode("func3", 0, 1, NULL);
         af_Code *bt5 = makeBlockCode(curly, bt4, 0, 1, NULL, NULL);
@@ -1024,107 +1024,125 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt3, env);
+        iterCode(bt3, 0, env);
         freeAllCode(bt3);
         printf("\n");
     }
 
     {  // 对象函数的调用
-        printf("TAG N:\n");
-        af_Code *bt1 = makeElementCode("func4", 0, 1, NULL);
+        printf("TAG J:\n");
+        af_Code *bt1 = makeElementCode("func4", 0, 1, "tagj.af");
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 变量引用调用
-        printf("TAG O:\n");
-        af_Code *bt1 = makeElementCode("func4", '\'', 1, NULL);
+        printf("TAG K:\n");
+        af_Code *bt1 = makeElementCode("func4", '\'', 1, "tagk.af");
         af_Code *bt2 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt1, bt2);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 对象函数的调用 (尾调递归优化)
-        printf("TAG P:\n");
-        af_Code *bt1 = makeElementCode("func4", 0, 1, "TagP.af");
+        printf("TAG L:\n");
+        af_Code *bt1 = makeElementCode("func4", 0, 1, "tagl.af");
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 函数调用
-        printf("TAG U:\n");
+        printf("TAG M:\n");
 
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagU.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tagm.af", NULL);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // gc测试
-        printf("TAG Q:\n");
+        printf("TAG N:\n");
 
         af_Code *bt2 = makeElementCode("func5", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagQ.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tagn.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
         af_Code *bt4 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
         pushCode(&bt3, bt4);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // func_body_dynamic 测试
-        printf("TAG R:\n");
+        printf("TAG O:\n");
 
         af_Code *bt2 = makeElementCode("func7", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagR.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tago.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 中缀调用测试
-        printf("TAG S:\n");
+        printf("TAG P:\n");
 
         af_Code *bt2 = makeElementCode("func8", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "TagS.af", NULL);
+        af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "Tagp.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // func_body_import 测试
-        printf("TAG X:\n");
+        printf("TAG Q:\n");
 
         af_Code *bt2 = makeElementCode("func10", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagX.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tagq.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
+        freeAllCode(bt1);
+        printf("\n");
+    }
+
+    {  // 导入式运行
+        printf("TAG R:\n");
+        af_Code *bt1 = makeElementCode("object", 0, 1, "tagr.af");
+        af_Code *bt2 = makeElementCode("data", ',', 0, NULL);
+        pushCode(&bt1, bt2);
+
+        af_Code *bt3 = makeElementCode("func", 0, 1, NULL);
+        af_Code *bt5 = makeBlockCode(curly, bt3, 0, 1, NULL, NULL);
+        pushCode(&bt2, bt5);
+
+        af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
+        pushCode(&bt5, bt6);
+
+        iterCode(bt1, 1, env);
         freeAllCode(bt1);
         printf("\n");
     }
@@ -1132,22 +1150,22 @@ int main() {
     /* 错误用例 */
 
     {  // 中缀调用测试
-        printf("TAG T: ERROR\n");
+        printf("TAG a: ERROR\n");
 
         af_Code *bt2 = makeElementCode("func", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "TagT.error.af", NULL);
+        af_Code *bt1 = makeBlockCode(brackets, bt2, 0, 1, "Taga-error.af", NULL);
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
 
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 测试错误 (无函数指定)
-        printf("TAG F: ERROR\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        printf("TAG b: ERROR\n");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagb-error.af");
 
         af_Code *bt5 = makeBlockCode(curly, NULL, 0, 1, NULL, NULL);
         pushCode(&bt1, bt5);
@@ -1155,46 +1173,46 @@ int main() {
         af_Code *bt6 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt5, bt6);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 测试错误 (object2 Var not found)
-        printf("TAG G: ERROR\n");
-        af_Code *bt1 = makeElementCode("data", ',', 0, "Unknown");
+        printf("TAG c: ERROR\n");
+        af_Code *bt1 = makeElementCode("data", ',', 0, "Tagc-error.af");
         af_Code *bt2 = makeElementCode("object2", 0, 1, NULL);
 
         pushCode(&bt1, bt2);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 中缀保护测试
-        printf("TAG V: ERROR\n");
+        printf("TAG d: ERROR\n");
 
         af_Code *bt2 = makeElementCode("func8", 0, 2, NULL);
-        af_Code *bt1 = makeElementCode("global", 0, 1, "TagV.error.af");
+        af_Code *bt1 = makeElementCode("global", 0, 1, "Tagd-error.af");
 
         pushCode(&bt1, bt2);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
 
     {  // 错误回溯测试
-        printf("TAG W: ERROR\n");
+        printf("TAG e: ERROR\n");
 
         af_Code *bt2 = makeElementCode("func9", 0, 1, NULL);
-        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "TagW.error.af", NULL);
+        af_Code *bt1 = makeBlockCode(curly, bt2, 0, 1, "Tage-error.af", NULL);
 
         af_Code *bt3 = makeElementCode("global", 0, 1, NULL);
         pushCode(&bt1, bt3);
 
-        iterCode(bt1, env);
+        iterCode(bt1, 0, env);
         freeAllCode(bt1);
         printf("\n");
     }
@@ -1203,13 +1221,22 @@ int main() {
     freeEnvironment(env);
 
     printf("Exit at 0.");
+#ifndef IN_CTEST
+    getc(stdin);
+#endif
     return 0;
 
 RETURN_1:
     printf("Exit at 1.");
+#ifndef IN_CTEST
+    getc(stdin);
+#endif
     return 1;
 
 RETURN_2:
     printf("Exit at 2.");
+#ifndef IN_CTEST
+    getc(stdin);
+#endif
     return 2;
 }