Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hinting the compiler with magic hinting comments #5

Open
lehenbauer opened this issue Jul 29, 2015 · 2 comments
Open

hinting the compiler with magic hinting comments #5

lehenbauer opened this issue Jul 29, 2015 · 2 comments

Comments

@lehenbauer
Copy link

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]
}
@bovine
Copy link
Contributor

bovine commented Aug 7, 2015

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.

@lehenbauer
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants