tsp icon indicating copy to clipboard operation
tsp copied to clipboard

hinting the compiler with magic hinting comments

Open lehenbauer opened this issue 9 years ago • 2 comments

An idea for your consideration...

Instead of hinting the compiler with comments how about if the same hinting is formally available through tsp::proc itself? If compilation fails tsp::proc can still generate a legal Tcl proc as it does now.

For example, change something like:

tsp::proc tsp_lrandom {list} {
    #tsp::procdef var -args var
    #tsp::compile assert
    #tsp::int len which
    set len [llength $list]
    set which [expr {int(rand() * $len)}]
    return [lindex $list $which]
}

to

tsp::proc tsp_lrandom {var list returning var} {

    #tsp::int len which
    set len [llength $list]
    set which [expr {int(rand() * $len)}]
    return [lindex $list $which]
}

This doesn't cover the variable declarations like "#tsp::int len which", and I can see problems with not using comments there and tsp::proc having to distinguish between hints and code. Maybe it could have a variable declaration section as an additional argument to tsp::proc, something like:

tsp::proc tsp_lrandom {var list returning var} {
    int len which
} {
    set len [llength $list]
    set which [expr {int(rand() * $len)}]
    return [lindex $list $which]
}

lehenbauer avatar Jul 29 '15 13:07 lehenbauer

This would make it more difficult to manually revert a tsp::proc to an uncompiled proc (such as for debugging purposes) by simply removing the "tsp::" part from the proc line.

bovine avatar Aug 07 '15 16:08 bovine

That's a good point. If the proc arguments were kept in the normal style instead of adding the "returning" thing I was proposing but it still had the additional section with the variable declarations and whatnot then the fallback to a normal proc is super simple, where the tsp::proc definition is in "list", execute something like "proc [lindex $list 1] [lindex $list 2] [lindex $list 4]" and you've got your compatible fallback.

lehenbauer avatar Aug 12 '15 13:08 lehenbauer