]> ocean-lang.org Git - ocean/commitdiff
oceani: update min_depth promptly.
authorNeilBrown <neil@brown.name>
Mon, 8 Nov 2021 08:35:25 +0000 (19:35 +1100)
committerNeilBrown <neil@brown.name>
Mon, 8 Nov 2021 09:56:36 +0000 (20:56 +1100)
As the loop in var_block_close() continues until min_depth is too low,
we need to set it promptly to stop the same variable being processed
again before it has been merged.

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

index 6be6a153f008e7e3f1300e592c7ea3f3d69ef350..794d918c246d76f27e95f00d645edff4bdeba0ec 100644 (file)
@@ -331,6 +331,7 @@ Here I break it into two parts, keeping the array code separate.
                a : number
                a = A;
                b:number = B
+               print "still", bigger // check for regression in scoping
                if a > 0 and b > 0:
                        while a != b:
                                if a < b:
@@ -386,6 +387,7 @@ Here I break it into two parts, keeping the array code separate.
        Hello World, what lovely oceans you have!
        Is 55 bigger than 33 ?  yes
        double 33 is 66
+       still yes
        GCD of 55 and 33 is 11
        Fibonacci: 1 1 2 3 5 8 13 21 34 55 89 144
        hello was the str
@@ -395,6 +397,7 @@ Here I break it into two parts, keeping the array code separate.
        Hello World, what lovely oceans you have!
        Is 12 bigger than 60 ?  no
        double 60 is 120
+       still no
        GCD of 12 and 60 is 12
        Fibonacci: 1 1 2 3 5 8 13 21 34 55 89 144
        I found the str over there
index af24d9becd86326c48633e66cd0718a5510479da..04cae63a944360db4e963e1f43a622b05b785854 100644 (file)
@@ -953,13 +953,13 @@ Each variable records a scope depth and is in one of four states:
   enclosed the declaration, and that has closed.
 
 - "conditionally in scope".  The "in scope" block and all parallel
-  scopes have closed, and no further mention of the name has been
-  seen.  This state includes a secondary nest depth which records the
-  outermost scope seen since the variable became conditionally in
-  scope.  If a use of the name is found, the variable becomes "in
-  scope" and that secondary depth becomes the recorded scope depth.
-  If the name is declared as a new variable, the old variable becomes
-  "out of scope" and the recorded scope depth stays unchanged.
+  scopes have closed, and no further mention of the name has been seen.
+  This state includes a secondary nest depth (`min_depth`) which records
+  the outermost scope seen since the variable became conditionally in
+  scope.  If a use of the name is found, the variable becomes "in scope"
+  and that secondary depth becomes the recorded scope depth.  If the
+  name is declared as a new variable, the old variable becomes "out of
+  scope" and the recorded scope depth stays unchanged.
 
 - "out of scope".  The variable is neither in scope nor conditionally
   in scope.  It is permanently out of scope now and can be removed from
@@ -1150,6 +1150,7 @@ all pending-scope variables become conditionally scoped.
                     (v->scope == OutScope || v->name->var != v)
                     ? (*vp =  v->in_scope, 0)
                     : ( vp = &v->in_scope, 0)) {
+                       v->min_depth = c->scope_depth;
                        if (v->name->var != v) {
                                /* This is still in scope, but we haven't just
                                 * closed the scope.
@@ -1208,7 +1209,6 @@ all pending-scope variables become conditionally scoped.
                                             v2 = v2->previous)
                                                if (v2->type == Tlabel) {
                                                        v2->scope = CondScope;
-                                                       v2->min_depth = c->scope_depth;
                                                } else
                                                        v2->scope = OutScope;
                                        break;