Tcl Source Code

Check-in [7d4bfdea1c]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:amend with new tests: now contains all tests affected from [723a2f4ac3] as well as executed non-compiled in global frame directly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sebres-bug-723a2f4ac3
Files: files | file ages | folders
SHA3-256: 7d4bfdea1cf00dabb7949a22d07d6728ea4d4acb1070ffaaebb9909e3b254e18
User & Date: sebres 2018-08-03 11:15:01
Context
2018-08-03
12:59
experimental: same fix for yield into coro as [3950bbd3d0] for tailcall. check-in: 596751cc2e user: sebres tags: sebres-bug-723a2f4ac3
11:15
amend with new tests: now contains all tests affected from [723a2f4ac3] as well as executed non-comp... check-in: 7d4bfdea1c user: sebres tags: sebres-bug-723a2f4ac3
2018-08-02
17:30
amend with fix (init of counter "i") and same tests for coro check-in: 085cbe212c user: sebres tags: sebres-bug-723a2f4ac3
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tests/coroutine.test.

    15     15   }
    16     16   
    17     17   ::tcltest::loadTestedCommands
    18     18   catch [list package require -exact Tcltest [info patchlevel]]
    19     19   
    20     20   testConstraint testnrelevels [llength [info commands testnrelevels]]
    21     21   testConstraint memory [llength [info commands memory]]
           22  +testConstraint testevalobjv [llength [info commands testevalobjv]]
    22     23   
    23     24   set lambda [list {{start 0} {stop 10}} {
    24     25       # init
    25     26       set i    $start
    26     27       set imax $stop
    27     28       yield
    28     29       while {$i < $imax} {
................................................................................
   777    778       slave eval demo
   778    779       set result [slave eval {set ::result}]
   779    780   
   780    781       interp delete slave
   781    782       set result
   782    783   } -result {inject-executed}
   783    784   
          785  +# following tests cover direct break/return from coroutine into proc,
          786  +# coro or top-level up-scope loop, in case of "infinite" loop the result is 10 or 
          787  +# `invalid command name "c"`, in case of broken scope - `invoked "break" outside of a loop`
          788  +# (expected 1 for break and "" for return), test with "-nc" suffix are non-compiled.
          789  +test coroutine-9.1a {as direct return from proc: break into proc up-scope loop} -setup {
          790  +    proc p {} {yield; return -code break}
          791  +} -body {
          792  +    coroutine c p;
          793  +    proc t {} {while {[incr i] < 10} {c}; set i}
          794  +    t
          795  +} -cleanup {
          796  +    rename p {}; rename t {}
          797  +} -result 1
          798  +test coroutine-9.1b {as direct return from proc: break into top-level up-scope loop} -setup {
          799  +    proc p {} {yield; return -code break}
          800  +    set i 0
          801  +} -body {
          802  +    coroutine c p;
          803  +    while {[incr i] < 10} {c}; set i
          804  +} -cleanup {
          805  +    rename p {}
          806  +} -result 1
          807  +test coroutine-9.1b-nc {as direct return from proc: break into top-level up-scope loop (non-compiled)} \
          808  +-constraints {testevalobjv} -body {
          809  +    exec [info nameofexecutable] << {
          810  +	proc p {} {yield; return -code break}
          811  +	set i 0
          812  +	coroutine c p;
          813  +	testevalobjv 1 while {[incr i] < 10} c; puts $i
          814  +    }
          815  +} -result 1
          816  +test coroutine-9.1c {as direct return from coro: break into lambda up-scope loop} -setup {
          817  +    proc p {} {yield; return -code break}
          818  +    set i 0
          819  +} -body {
          820  +    apply {{} {coroutine c p; while {[incr i] < 10} c; set i}}
          821  +} -cleanup {
          822  +    rename p {}
          823  +} -result 1
          824  +test coroutine-9.1d {no yield, as direct return from proc: break into proc up-scope loop} -setup {
          825  +    proc p {} {return -code break}
          826  +} -body {
          827  +    proc t {} {while {[incr i] < 10} {coroutine c p}; set i}
          828  +    t
          829  +} -cleanup {
          830  +    rename p {}; rename t {}
          831  +} -result 1
          832  +test coroutine-9.1e {no yield, as direct return from proc: break into top-level up-scope loop} -setup {
          833  +    proc p {} {return -code break}
          834  +    set i 0
          835  +} -body {
          836  +    while {[incr i] < 10} {coroutine c p}; set i
          837  +} -cleanup {
          838  +    rename p {}
          839  +} -result 1
          840  +test coroutine-9.1e-nc {no yield, as direct return from proc: break into top-level up-scope loop (non-compiled)} \
          841  +-constraints {testevalobjv} -body {
          842  +    exec [info nameofexecutable] << {
          843  +	proc p {} {return -code break}
          844  +	set i 0
          845  +	testevalobjv 1 while {[incr i] < 10} {coroutine c p}; puts $i
          846  +    }
          847  +} -result 1
          848  +
          849  +test coroutine-9.2a {as direct return from proc: return into proc up-scope loop} -setup {
          850  +    proc p {} {yield; return -code return}
          851  +} -body {
          852  +    coroutine c p;
          853  +    proc t {} {while {[incr i] < 10} {c}; set i}
          854  +    t
          855  +} -cleanup {
          856  +    rename p {}; rename t {}
          857  +} -result ""
          858  +test coroutine-9.2b {as direct return from proc: return into top-level up-scope loop} -setup {
          859  +    proc p {} {yield; return -code return}
          860  +    set i 0
          861  +} -body {
          862  +    coroutine c p;
          863  +    while {[incr i] < 10} {c}; set i
          864  +} -cleanup {
          865  +    rename p {}
          866  +} -result ""
          867  +test coroutine-9.2b-nc {as direct return from proc: return into top-level up-scope loop (non-compiled)} \
          868  +-constraints {testevalobjv} -body {
          869  +    exec [info nameofexecutable] << {
          870  +	proc p {} {yield; return -code return}
          871  +	set i 0
          872  +	coroutine c p;
          873  +	testevalobjv 1 while {[incr i] < 10} c; puts $i
          874  +    }
          875  +} -result ""
          876  +test coroutine-9.2c {as direct return from coro: return into lambda up-scope loop} -setup {
          877  +    proc p {} {yield; return -code return}
          878  +    set i 0
          879  +} -body {
          880  +    apply {{} {coroutine c p; while {[incr i] < 10} c; set i}}
          881  +} -cleanup {
          882  +    rename p {}
          883  +} -result ""
          884  +test coroutine-9.2d {no yield, as direct return from proc: return into proc up-scope loop} -setup {
          885  +    proc p {} {return -code return}
          886  +} -body {
          887  +    proc t {} {while {[incr i] < 10} {coroutine c p}; set i}
          888  +    t
          889  +} -cleanup {
          890  +    rename p {}; rename t {}
          891  +} -result ""
          892  +test coroutine-9.2e {no yield, as direct return from proc: return into top-level up-scope loop} -setup {
          893  +    proc p {} {return -code return}
          894  +    set i 0
          895  +} -body {
          896  +    while {[incr i] < 10} {coroutine c p}; set i
          897  +} -cleanup {
          898  +    rename p {}
          899  +} -result ""
          900  +test coroutine-9.2e-nc {no yield, as direct return from proc: return into top-level up-scope loop (non-compiled)} \
          901  +-constraints {testevalobjv} -body {
          902  +    exec [info nameofexecutable] << {
          903  +	proc p {} {return -code return}
          904  +	set i 0
          905  +	testevalobjv 1 while {[incr i] < 10} {coroutine c p}; puts $i
          906  +    }
          907  +} -result ""
   784    908   
   785    909   
   786    910   # cleanup
   787    911   unset lambda
   788    912   ::tcltest::cleanupTests
   789    913   
   790    914   return
   791    915   
   792    916   # Local Variables:
   793    917   # mode: tcl
   794    918   # End:

Changes to tests/tailcall.test.

    14     14       namespace import -force ::tcltest::*
    15     15   }
    16     16   
    17     17   ::tcltest::loadTestedCommands
    18     18   catch [list package require -exact Tcltest [info patchlevel]]
    19     19   
    20     20   testConstraint testnrelevels [llength [info commands testnrelevels]]
           21  +testConstraint testevalobjv [llength [info commands testevalobjv]]
    21     22   
    22     23   #
    23     24   # The tests that risked blowing the C stack on failure have been removed: we
    24     25   # can now actually measure using testnrelevels.
    25     26   #
    26     27   
    27     28   if {[testConstraint testnrelevels]} {
................................................................................
   704    705   	    tailcall [namespace current] {*}$args
   705    706   	}
   706    707   	namespace delete [namespace current]
   707    708   	p
   708    709       }
   709    710   } -returnCodes 1 -result {namespace "::ns" not found}
   710    711   
   711         -# following tests cover tailcall as direct break/return from proc into proc
   712         -# coro or top-level upscope loop, in case of "infinite" loop the result is 10
   713         -# (expected 1 for break and "" for return)
   714         -test tailcall-15.1a {as direct return from proc: break into proc upscope loop} -setup {
          712  +# following tests cover tailcall as direct break/return from proc into proc,
          713  +# coro or top-level up-scope loop, in case of "infinite" loop the result is 10
          714  +# (expected 1 for break and "" for return), test with "-nc" suffix are non-compiled.
          715  +test tailcall-15.1a {as direct return from proc: break into proc up-scope loop} -setup {
   715    716       proc p {} {tailcall break}
   716    717   } -body {
   717    718       proc t {} {while {[incr i] < 10} p; set i}
   718    719       t
          720  +} -cleanup {
          721  +    rename p {}; rename t {}
   719    722   } -result 1
   720         -test tailcall-15.1b {as direct return from proc: break into top-level upscope loop} -setup {
          723  +test tailcall-15.1b {as direct return from proc: break into top-level up-scope loop} -setup {
   721    724       proc p {} {tailcall break}
   722    725       set i 0
   723    726   } -body {
   724    727       while {[incr i] < 10} p; set i
          728  +} -cleanup {
          729  +    rename p {}
          730  +} -result 1
          731  +test tailcall-15.1b-nc {as direct return from proc: break into top-level up-scope loop (non-compiled)} \
          732  +-constraints {testevalobjv} -body {
          733  +    exec [info nameofexecutable] << {
          734  +	proc p {} {tailcall break}
          735  +	set i 0
          736  +	while {[incr i] < 10} p; puts $i
          737  +    }
   725    738   } -result 1
   726         -test tailcall-15.1c {as direct return from proc: break into top-level upscope loop} -setup {
          739  +test tailcall-15.1c {as direct return from coro: break into lambda up-scope loop} -setup {
   727    740       proc p {} {yield; tailcall break}
   728    741       set i 0
   729    742   } -body {
   730    743       apply {{} {coroutine c p}}
   731    744       while {[incr i] < 10} c; set i
          745  +} -cleanup {
          746  +    rename p {}
          747  +} -result 1
          748  +test tailcall-15.1d {as direct return from proc: break into coro up-scope loop} -setup {
          749  +    proc p {} {tailcall break}
          750  +    set i 0
          751  +} -body {
          752  +    apply {{} {while {[incr i] < 10} {coroutine c p}; set i}}
          753  +} -cleanup {
          754  +    rename p {}
   732    755   } -result 1
   733    756   
   734         -test tailcall-15.2a {as direct return from proc: return into proc upscope loop} -setup {
          757  +test tailcall-15.2a {as direct return from proc: return into proc up-scope loop} -setup {
   735    758       proc p {} {tailcall return}
   736    759   } -body {
   737    760       proc t {} {while {[incr i] < 10} p; set i}
   738    761       t
          762  +} -cleanup {
          763  +    rename p {}; rename t {}
   739    764   } -result ""
   740         -test tailcall-15.2b {as direct return from proc: return into top-level upscope loop} -setup {
          765  +test tailcall-15.2b {as direct return from proc: return into top-level up-scope loop} -setup {
   741    766       proc p {} {tailcall return}
   742    767       set i 0
   743    768   } -body {
   744    769       while {[incr i] < 10} p; set i
          770  +} -cleanup {
          771  +    rename p {}
          772  +} -result ""
          773  +test tailcall-15.2b-nc {as direct return from proc: return into top-level up-scope loop (non-compiled)} \
          774  +-constraints {testevalobjv} -body {
          775  +    exec [info nameofexecutable] << {
          776  +	proc p {} {tailcall return}
          777  +	set i 0
          778  +	while {[incr i] < 10} p; puts $i
          779  +    }
   745    780   } -result ""
   746         -test tailcall-15.2c {as direct return from proc: return into top-level upscope loop} -setup {
          781  +test tailcall-15.2c {as direct return from coro: return into lambda up-scope loop} -setup {
   747    782       proc p {} {yield; tailcall return}
   748    783       set i 0
   749    784   } -body {
   750    785       apply {{} {coroutine c p}}
   751    786       while {[incr i] < 10} c; set i
          787  +} -cleanup {
          788  +    rename p {}
          789  +} -result ""
          790  +test tailcall-15.2d {as direct return from proc: return into coro up-scope loop} -setup {
          791  +    proc p {} {tailcall return}
          792  +    set i 0
          793  +} -body {
          794  +    apply {{} {while {[incr i] < 10} {coroutine c p}; set i}}
          795  +} -cleanup {
          796  +    rename p {}
   752    797   } -result ""
   753    798   
   754    799   # cleanup
   755    800   ::tcltest::cleanupTests
   756    801   
   757    802   # Local Variables:
   758    803   # mode: tcl
   759    804   # End: