On 2022-01-11 20:15, Adriano dos Santos Fernandes wrote:
Hi!
Currently sub routines cannot access the outer (main routine/block)
variables, parameters and cursors - #4769.
There is some details to make that happen safely.
Currently a variable cannot have its value changed while its being
used.
var = var + <expression>
No expression can reset var.
As soon we let sub routines change outer variables, that will be
possible.
Currently VariableNode just returns a descriptor pointing to the
variable's impure_value present in the variable declaration.
To make outer access safe, variables accessed in outer scope would be
flagged and its VariableNode (even in the main routine/block) should
copy the value to its own impure_value. It will be a bit slower, but I
don't see a problem.
What worried me more is how to represent things in BLR. A simple
approach would be to have blr_outer_variable.
But it is not only variables.
There is also parameters, fields, dbkeys, cursor statements.
What seems for me the way to go is to implement single blr_outer_map
that maps main routine's things to sub routines in they own number
space.
blr_outer_map,
blr_outer_map_variable,
0,0,
3,0
It maps main's variable 0,0 to this sub routine's 3,0, so it can access
with blr_variable, 3,0.
blr_outer_map,
blr_outer_map_cursor,
1,0,
2,0
Maps main's cursor 1,0 to this sub routine's 2,0, so it can access with
blr_cursor_stmt, 2,0.
Comments?
It is not entirely clear to me what you're proposing and what the
motivation is for the proposal. Are you proposing to allow local
subroutines to modify their parents variable, or are you proposing
something to allow reading a local variable, but prevent modification?
Mark
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel