Browse Source

fix: 修复了yield位置的bug

yield可以位于代码块最后一行中
此前该问题存在于if和with中
因为if和with都是用info_vl来判断当前是否为yield模式
若yield处于代码块最后, 则info_vl会等于NULL
导致判断失误

link #11
SongZihuan 4 years ago
parent
commit
b1ef9b80ce
2 changed files with 10 additions and 6 deletions
  1. 10 5
      VirtulMathCore/src/runbranch.c
  2. 0 1
      VirtulMathCore/src/runfile.c

+ 10 - 5
VirtulMathCore/src/runbranch.c

@@ -160,12 +160,13 @@ ResultType ifBranch(INTER_FUNCTIONSIG) {
             if_list = st->info.branch.sl_node;
             info_vl = st->info.node;
             else_st = st->u.if_branch.else_list;
-        }
-        else if (st->info.branch.status == info_else_branch) {
+            finally = st->u.if_branch.finally;
+            if (info_vl == NULL)
+                if_list = NULL;  // 证明if分支的yield已经到头了
+        } else if (st->info.branch.status == info_else_branch) {
             else_st = st->info.node;
             finally = st->u.if_branch.finally;
-        }
-        else if (st->info.branch.status == info_finally_branch)
+        } else if (st->info.branch.status == info_finally_branch)
             finally = st->info.node;
         else {
             var_list = popVarList(var_list);
@@ -679,13 +680,17 @@ ResultType withBranch(INTER_FUNCTIONSIG) {
             new->next = var_list;
         }
 
-        if (st->info.branch.status == info_vl_branch)
+        if (st->info.branch.status == info_vl_branch) {
             vl_info = st->info.node;
+            if (vl_info == NULL)
+                run_block = false;
+        }
         else if (st->info.branch.status == info_else_branch) {
             run_block = false;
             else_st = st->info.node;
         }
         else if (st->info.branch.status == info_finally_branch){
+            run_block = false;
             else_st = NULL;
             finally = st->info.node;
         }

+ 0 - 1
VirtulMathCore/src/runfile.c

@@ -334,7 +334,6 @@ ResultType fromImportFile(INTER_FUNCTIONSIG) {
     if (pt != NULL) {
         importParameter(st->line, st->code_file, pt, as, var_list, belong, CALL_INTER_FUNCTIONSIG_NOT_ST(imp_var, result, imp_value));
         if (!CHECK_RESULT(result)) {
-            printf("TAG A\n");
             gc_freeTmpLink(&imp_value->gc_status);
             goto return_;
         }