]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani.mdc
oceani: move var_block_close() calls to the code sections that close the block
[ocean] / csrc / oceani.mdc
index 364ee290ab54ca10d0e825d9d128edd5b15ea0b2..d1967562fdf6f1c94731f151f26c73ba3a1c47a0 100644 (file)
@@ -932,7 +932,6 @@ like "if" and the code following it.
 
        $void
        OpenScope -> ${ scope_push(c); }$
-       ClosePara -> ${ var_block_close(c, CloseParallel); }$
 
 Each variable records a scope depth and is in one of four states:
 
@@ -3846,8 +3845,8 @@ defined.
        // may or may not end with EOL
        // WhilePart and IfPart include an appropriate Suffix
 
-       // Both ForPart and Whilepart open scopes, and CondSuffix only
-       // closes one - so in the first branch here we have another to close.
+       // ForPart, SwitchPart, and IfPart open scopes, o we have to close
+       // them.  WhilePart opens and closes its own scope.
        CondStatement -> ForPart OptNL ThenPart OptNL WhilePart CondSuffix ${
                        $0 = $<CS;
                        $0->forpart = $<FP;
@@ -3873,12 +3872,14 @@ defined.
                        $0->condpart = $<SP;
                        $CP->next = $0->casepart;
                        $0->casepart = $<CP;
+                       var_block_close(c, CloseSequential);
                        }$
                | SwitchPart : IN OptNL CasePart CondSuffix OUT Newlines ${
                        $0 = $<CS;
                        $0->condpart = $<SP;
                        $CP->next = $0->casepart;
                        $0->casepart = $<CP;
+                       var_block_close(c, CloseSequential);
                        }$
                | IfPart IfSuffix ${
                        $0 = $<IS;
@@ -3890,9 +3891,6 @@ defined.
 
        CondSuffix -> IfSuffix ${
                        $0 = $<1;
-                       // This is where we close scope of the whole
-                       // "for" or "while" statement
-                       var_block_close(c, CloseSequential);
                }$
                | Newlines CasePart CondSuffix ${
                        $0 = $<CS;
@@ -3929,7 +3927,7 @@ defined.
                }$
 
        $*exec
-       // These scopes are closed in CondSuffix
+       // These scopes are closed in CondStatement
        ForPart -> for OpenBlock ${
                        $0 = $<Bl;
                }$
@@ -3940,31 +3938,36 @@ defined.
                }$
 
        $cond_statement
-       // This scope is closed in CondSuffix
+       // This scope is closed in CondStatement
        WhilePart -> while UseBlock OptNL do Block ${
                        $0.condpart = $<UB;
                        $0.dopart = $<Bl;
+                       var_block_close(c, CloseSequential);
                }$
                | while OpenScope Expression ColonBlock ${
                        $0.condpart = $<Exp;
                        $0.dopart = $<Bl;
+                       var_block_close(c, CloseSequential);
                }$
 
-       IfPart -> if UseBlock OptNL then OpenBlock ClosePara ${
+       IfPart -> if UseBlock OptNL then OpenBlock ${
                        $0.condpart = $<UB;
-                       $0.thenpart = $<Bl;
+                       $0.thenpart = $<OB;
+                       var_block_close(c, CloseParallel);
                }$
-               | if OpenScope Expression OpenScope ColonBlock ClosePara ${
+               | if OpenScope Expression OpenScope ColonBlock ${
                        $0.condpart = $<Ex;
-                       $0.thenpart = $<Bl;
+                       $0.thenpart = $<CB;
+                       var_block_close(c, CloseParallel);
                }$
-               | if OpenScope Expression OpenScope OptNL then Block ClosePara ${
+               | if OpenScope Expression OpenScope OptNL then Block ${
                        $0.condpart = $<Ex;
                        $0.thenpart = $<Bl;
+                       var_block_close(c, CloseParallel);
                }$
 
        $*exec
-       // This scope is closed in CondSuffix
+       // This scope is closed in CondStatement
        SwitchPart -> switch OpenScope Expression ${
                        $0 = $<Ex;
                }$
@@ -4026,16 +4029,16 @@ defined.
                                do_indent(indent, "if");
                        if (cs->condpart && cs->condpart->type == Xbinode &&
                            cast(binode, cs->condpart)->op == Block) {
-                               if (bracket)    // UNTESTED
-                                       printf(" {\n"); // UNTESTED
+                               if (bracket)
+                                       printf(" {\n");
                                else
-                                       printf(":\n");  // UNTESTED
-                               print_exec(cs->condpart, indent+1, bracket);    // UNTESTED
-                               if (bracket)    // UNTESTED
-                                       do_indent(indent, "}\n");       // UNTESTED
-                               if (cs->thenpart) {     // UNTESTED
-                                       do_indent(indent, "then:\n");   // UNTESTED
-                                       print_exec(cs->thenpart, indent+1, bracket);    // UNTESTED
+                                       printf("\n");
+                               print_exec(cs->condpart, indent+1, bracket);
+                               if (bracket)
+                                       do_indent(indent, "}\n");
+                               if (cs->thenpart) {
+                                       do_indent(indent, "then\n");
+                                       print_exec(cs->thenpart, indent+1, bracket);
                                }
                        } else {
                                printf(" ");
@@ -4574,13 +4577,14 @@ things which will likely grow as the languages grows.
                        else
                                hi = mid
                        if hi - lo < 1:
+                               lo = mid
                                use GiveUp
                        use True
                do pass
                case Found:
                        print "Yay, I found", target
                case GiveUp:
-                       print "Closest I found was", mid
+                       print "Closest I found was", lo
 
                size::= 10
                list:[size]number