Tcl Source Code

Check-in [7d4bfdea1c]
Login

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
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.159
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
Unified Diff Show Whitespace Changes Patch
Changes to tests/coroutine.test.
15
16
17
18
19
20
21

22
23
24
25
26
27
28
}

::tcltest::loadTestedCommands
catch [list package require -exact Tcltest [info patchlevel]]

testConstraint testnrelevels [llength [info commands testnrelevels]]
testConstraint memory [llength [info commands memory]]


set lambda [list {{start 0} {stop 10}} {
    # init
    set i    $start
    set imax $stop
    yield
    while {$i < $imax} {







>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
}

::tcltest::loadTestedCommands
catch [list package require -exact Tcltest [info patchlevel]]

testConstraint testnrelevels [llength [info commands testnrelevels]]
testConstraint memory [llength [info commands memory]]
testConstraint testevalobjv [llength [info commands testevalobjv]]

set lambda [list {{start 0} {stop 10}} {
    # init
    set i    $start
    set imax $stop
    yield
    while {$i < $imax} {
777
778
779
780
781
782
783



























































































































784
785
786
787
788
789
790
791
792
793
794
    slave eval demo
    set result [slave eval {set ::result}]

    interp delete slave
    set result
} -result {inject-executed}






























































































































# cleanup
unset lambda
::tcltest::cleanupTests

return

# Local Variables:
# mode: tcl
# End:







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>











778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
    slave eval demo
    set result [slave eval {set ::result}]

    interp delete slave
    set result
} -result {inject-executed}

# following tests cover direct break/return from coroutine into proc,
# coro or top-level up-scope loop, in case of "infinite" loop the result is 10 or 
# `invalid command name "c"`, in case of broken scope - `invoked "break" outside of a loop`
# (expected 1 for break and "" for return), test with "-nc" suffix are non-compiled.
test coroutine-9.1a {as direct return from proc: break into proc up-scope loop} -setup {
    proc p {} {yield; return -code break}
} -body {
    coroutine c p;
    proc t {} {while {[incr i] < 10} {c}; set i}
    t
} -cleanup {
    rename p {}; rename t {}
} -result 1
test coroutine-9.1b {as direct return from proc: break into top-level up-scope loop} -setup {
    proc p {} {yield; return -code break}
    set i 0
} -body {
    coroutine c p;
    while {[incr i] < 10} {c}; set i
} -cleanup {
    rename p {}
} -result 1
test coroutine-9.1b-nc {as direct return from proc: break into top-level up-scope loop (non-compiled)} \
-constraints {testevalobjv} -body {
    exec [info nameofexecutable] << {
	proc p {} {yield; return -code break}
	set i 0
	coroutine c p;
	testevalobjv 1 while {[incr i] < 10} c; puts $i
    }
} -result 1
test coroutine-9.1c {as direct return from coro: break into lambda up-scope loop} -setup {
    proc p {} {yield; return -code break}
    set i 0
} -body {
    apply {{} {coroutine c p; while {[incr i] < 10} c; set i}}
} -cleanup {
    rename p {}
} -result 1
test coroutine-9.1d {no yield, as direct return from proc: break into proc up-scope loop} -setup {
    proc p {} {return -code break}
} -body {
    proc t {} {while {[incr i] < 10} {coroutine c p}; set i}
    t
} -cleanup {
    rename p {}; rename t {}
} -result 1
test coroutine-9.1e {no yield, as direct return from proc: break into top-level up-scope loop} -setup {
    proc p {} {return -code break}
    set i 0
} -body {
    while {[incr i] < 10} {coroutine c p}; set i
} -cleanup {
    rename p {}
} -result 1
test coroutine-9.1e-nc {no yield, as direct return from proc: break into top-level up-scope loop (non-compiled)} \
-constraints {testevalobjv} -body {
    exec [info nameofexecutable] << {
	proc p {} {return -code break}
	set i 0
	testevalobjv 1 while {[incr i] < 10} {coroutine c p}; puts $i
    }
} -result 1

test coroutine-9.2a {as direct return from proc: return into proc up-scope loop} -setup {
    proc p {} {yield; return -code return}
} -body {
    coroutine c p;
    proc t {} {while {[incr i] < 10} {c}; set i}
    t
} -cleanup {
    rename p {}; rename t {}
} -result ""
test coroutine-9.2b {as direct return from proc: return into top-level up-scope loop} -setup {
    proc p {} {yield; return -code return}
    set i 0
} -body {
    coroutine c p;
    while {[incr i] < 10} {c}; set i
} -cleanup {
    rename p {}
} -result ""
test coroutine-9.2b-nc {as direct return from proc: return into top-level up-scope loop (non-compiled)} \
-constraints {testevalobjv} -body {
    exec [info nameofexecutable] << {
	proc p {} {yield; return -code return}
	set i 0
	coroutine c p;
	testevalobjv 1 while {[incr i] < 10} c; puts $i
    }
} -result ""
test coroutine-9.2c {as direct return from coro: return into lambda up-scope loop} -setup {
    proc p {} {yield; return -code return}
    set i 0
} -body {
    apply {{} {coroutine c p; while {[incr i] < 10} c; set i}}
} -cleanup {
    rename p {}
} -result ""
test coroutine-9.2d {no yield, as direct return from proc: return into proc up-scope loop} -setup {
    proc p {} {return -code return}
} -body {
    proc t {} {while {[incr i] < 10} {coroutine c p}; set i}
    t
} -cleanup {
    rename p {}; rename t {}
} -result ""
test coroutine-9.2e {no yield, as direct return from proc: return into top-level up-scope loop} -setup {
    proc p {} {return -code return}
    set i 0
} -body {
    while {[incr i] < 10} {coroutine c p}; set i
} -cleanup {
    rename p {}
} -result ""
test coroutine-9.2e-nc {no yield, as direct return from proc: return into top-level up-scope loop (non-compiled)} \
-constraints {testevalobjv} -body {
    exec [info nameofexecutable] << {
	proc p {} {return -code return}
	set i 0
	testevalobjv 1 while {[incr i] < 10} {coroutine c p}; puts $i
    }
} -result ""


# cleanup
unset lambda
::tcltest::cleanupTests

return

# Local Variables:
# mode: tcl
# End:
Changes to tests/tailcall.test.
14
15
16
17
18
19
20

21
22
23
24
25
26
27
    namespace import -force ::tcltest::*
}

::tcltest::loadTestedCommands
catch [list package require -exact Tcltest [info patchlevel]]

testConstraint testnrelevels [llength [info commands testnrelevels]]


#
# The tests that risked blowing the C stack on failure have been removed: we
# can now actually measure using testnrelevels.
#

if {[testConstraint testnrelevels]} {







>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    namespace import -force ::tcltest::*
}

::tcltest::loadTestedCommands
catch [list package require -exact Tcltest [info patchlevel]]

testConstraint testnrelevels [llength [info commands testnrelevels]]
testConstraint testevalobjv [llength [info commands testevalobjv]]

#
# The tests that risked blowing the C stack on failure have been removed: we
# can now actually measure using testnrelevels.
#

if {[testConstraint testnrelevels]} {
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718


719
720
721
722
723
724


725
726








727
728
729
730
731


732








733
734
735
736
737
738


739
740
741
742
743
744


745
746








747
748
749
750
751










752
753
754
755
756
757
758
759
	    tailcall [namespace current] {*}$args
	}
	namespace delete [namespace current]
	p
    }
} -returnCodes 1 -result {namespace "::ns" not found}

# following tests cover tailcall as direct break/return from proc into proc
# coro or top-level upscope loop, in case of "infinite" loop the result is 10
# (expected 1 for break and "" for return)
test tailcall-15.1a {as direct return from proc: break into proc upscope loop} -setup {
    proc p {} {tailcall break}
} -body {
    proc t {} {while {[incr i] < 10} p; set i}
    t


} -result 1
test tailcall-15.1b {as direct return from proc: break into top-level upscope loop} -setup {
    proc p {} {tailcall break}
    set i 0
} -body {
    while {[incr i] < 10} p; set i


} -result 1
test tailcall-15.1c {as direct return from proc: break into top-level upscope loop} -setup {








    proc p {} {yield; tailcall break}
    set i 0
} -body {
    apply {{} {coroutine c p}}
    while {[incr i] < 10} c; set i


} -result 1









test tailcall-15.2a {as direct return from proc: return into proc upscope loop} -setup {
    proc p {} {tailcall return}
} -body {
    proc t {} {while {[incr i] < 10} p; set i}
    t


} -result ""
test tailcall-15.2b {as direct return from proc: return into top-level upscope loop} -setup {
    proc p {} {tailcall return}
    set i 0
} -body {
    while {[incr i] < 10} p; set i


} -result ""
test tailcall-15.2c {as direct return from proc: return into top-level upscope loop} -setup {








    proc p {} {yield; tailcall return}
    set i 0
} -body {
    apply {{} {coroutine c p}}
    while {[incr i] < 10} c; set i










} -result ""

# cleanup
::tcltest::cleanupTests

# Local Variables:
# mode: tcl
# End:







|
|
|
|




>
>

|




>
>

|
>
>
>
>
>
>
>
>





>
>

>
>
>
>
>
>
>
>

|




>
>

|




>
>

|
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>
>








705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
	    tailcall [namespace current] {*}$args
	}
	namespace delete [namespace current]
	p
    }
} -returnCodes 1 -result {namespace "::ns" not found}

# following tests cover tailcall as direct break/return from proc into proc,
# coro or top-level up-scope loop, in case of "infinite" loop the result is 10
# (expected 1 for break and "" for return), test with "-nc" suffix are non-compiled.
test tailcall-15.1a {as direct return from proc: break into proc up-scope loop} -setup {
    proc p {} {tailcall break}
} -body {
    proc t {} {while {[incr i] < 10} p; set i}
    t
} -cleanup {
    rename p {}; rename t {}
} -result 1
test tailcall-15.1b {as direct return from proc: break into top-level up-scope loop} -setup {
    proc p {} {tailcall break}
    set i 0
} -body {
    while {[incr i] < 10} p; set i
} -cleanup {
    rename p {}
} -result 1
test tailcall-15.1b-nc {as direct return from proc: break into top-level up-scope loop (non-compiled)} \
-constraints {testevalobjv} -body {
    exec [info nameofexecutable] << {
	proc p {} {tailcall break}
	set i 0
	while {[incr i] < 10} p; puts $i
    }
} -result 1
test tailcall-15.1c {as direct return from coro: break into lambda up-scope loop} -setup {
    proc p {} {yield; tailcall break}
    set i 0
} -body {
    apply {{} {coroutine c p}}
    while {[incr i] < 10} c; set i
} -cleanup {
    rename p {}
} -result 1
test tailcall-15.1d {as direct return from proc: break into coro up-scope loop} -setup {
    proc p {} {tailcall break}
    set i 0
} -body {
    apply {{} {while {[incr i] < 10} {coroutine c p}; set i}}
} -cleanup {
    rename p {}
} -result 1

test tailcall-15.2a {as direct return from proc: return into proc up-scope loop} -setup {
    proc p {} {tailcall return}
} -body {
    proc t {} {while {[incr i] < 10} p; set i}
    t
} -cleanup {
    rename p {}; rename t {}
} -result ""
test tailcall-15.2b {as direct return from proc: return into top-level up-scope loop} -setup {
    proc p {} {tailcall return}
    set i 0
} -body {
    while {[incr i] < 10} p; set i
} -cleanup {
    rename p {}
} -result ""
test tailcall-15.2b-nc {as direct return from proc: return into top-level up-scope loop (non-compiled)} \
-constraints {testevalobjv} -body {
    exec [info nameofexecutable] << {
	proc p {} {tailcall return}
	set i 0
	while {[incr i] < 10} p; puts $i
    }
} -result ""
test tailcall-15.2c {as direct return from coro: return into lambda up-scope loop} -setup {
    proc p {} {yield; tailcall return}
    set i 0
} -body {
    apply {{} {coroutine c p}}
    while {[incr i] < 10} c; set i
} -cleanup {
    rename p {}
} -result ""
test tailcall-15.2d {as direct return from proc: return into coro up-scope loop} -setup {
    proc p {} {tailcall return}
    set i 0
} -body {
    apply {{} {while {[incr i] < 10} {coroutine c p}; set i}}
} -cleanup {
    rename p {}
} -result ""

# cleanup
::tcltest::cleanupTests

# Local Variables:
# mode: tcl
# End: