]> ocean-lang.org Git - ocean/commitdiff
oceani: move var_block_close() calls to the code sections that close the block
authorNeilBrown <neil@brown.name>
Sat, 6 Nov 2021 02:04:54 +0000 (13:04 +1100)
committerNeilBrown <neil@brown.name>
Mon, 8 Nov 2021 09:56:36 +0000 (20:56 +1100)
Rather than calling var_block_close() from common non-terminals, move
the calls into the body of the parent non-terminal.  This places them
after the 'struct exec' which represents the scope has been created.

This is needed to attach the variables to the point where their scope is
closed, so they can be freed.

This change helped me focus on some untested - and broken - code.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index 2433cce68593ee7f01153beec063927f4259b05f..6be6a153f008e7e3f1300e592c7ea3f3d69ef350 100644 (file)
@@ -80,7 +80,7 @@ arguments separated from the name by commas.  For each test, there is a section
                @mv *.gcov coverage ; [ -f .gcov ] && mv .gcov coverage || true
                @ awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
                    END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \
-                        if (ran < (ran + skip) *0.948) exit(1) }' \
+                        if (ran < (ran + skip) *0.956) exit(1) }' \
                        coverage/oceani.mdc.gcov
                @rm -f .tmp*
 
@@ -267,6 +267,13 @@ Now we need to test if/else and some different loops
                else
                        pass
                        print "sum 1..10 is", sum
+               if
+                       PI1 := 22/7
+                       use PI1 < pi
+               then
+                       print "Smaller"
+               else
+                       print 'larger'
 
 ###### output: cond_loop
        Success
@@ -285,6 +292,7 @@ Now we need to test if/else and some different loops
        pi exceeds three
        pi sufficient
        sum 1..10 is 55
+       larger
 
 ## Say Hello
 
index 2a40ff203efa442fa148610521cb016070c13974..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;
@@ -3951,17 +3950,20 @@ defined.
                        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
@@ -4027,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(" ");