From 20a0aeadef40b5d44f10e41b64be4d9a6df360e0 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 8 Nov 2021 19:35:25 +1100 Subject: [PATCH] oceani: update min_depth promptly. 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 --- csrc/oceani-tests.mdc | 3 +++ csrc/oceani.mdc | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index 6be6a15..794d918 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -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 diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index af24d9b..04cae63 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -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; -- 2.43.0