tsp
tsp copied to clipboard
crash; can upvar support #0?
I presume the code below coredumps because tsp upvar accepts but doesn't support #0. Would this be hard to add? We call the routine below a lot and avoid running subst on conclusionCode unless the referenced global variable is true. If analysis_subst_if could be defined as a tsp::proc and since most of the time the referenced variable is false, it seems like this tsp would be a clear performance win.
Alternatively I'm looking for a way to get the contents of a global variable inside a tsp::proc where the name of the global variable is in a variable.
package require tsp
tsp::proc analysis_subst_if {varName ident conclusionCode} {
#tsp::procdef void -args var var var
#tsp::int mute
#tsp::boolean var
#tsp::compile assert
global mute
if {$mute} {
return
}
upvar #0 $varName var
if {!$var} {
return
}
analysis $ident [uplevel [list subst $conclusionCode]] [style_from_var $varName]
}
set var1 0
set var2 1
analysis_subst_if var1 foo "this should not emit"
analysis_subst_if var2 foo "this should emit"
This compiles and works if the upvar target, var, is defined as a var instead of a boolean and a separate boolean var is used...
#tsp::var var
#tsp::boolean bool
...
upvar #0 $varName var
set bool $var
if {!$bool} {
return
}
Perhaps tsp should be using Tcl_UpVar to link a local obj to the correct frame and variable?