tcl: Phase 6 coroutines + clock/file stubs + idiom corpus (+40 tests, 329 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
- Coroutines (generator-style): coroutine/yield/yieldto commands; eager yield collection during body execution, pop-on-call dispatch via registered command closures; coro-yields + coroutines threaded through tcl-call-proc - info exists varname (plus hostname/script/tclversion stubs) - clock seconds/milliseconds/format/scan stubs - File I/O stubs: open/close/read/eof/seek/tell/flush + file subcommands - format command: full %-specifier parsing with flags, width, zero-pad, left-align - Fixed dict set/unset/incr/append/update to use tcl-var-get (upvar alias aware) - Fixed lappend and append to use tcl-var-get for reading (upvar alias aware) - 20 coroutine tests (coro.sx) + 20 idiom corpus tests (idioms.sx) - event-loop.tcl program: cooperative scheduler demo using coroutines - Note: coroutines eagerly collect yields (generator-style, not true suspension) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
22
lib/tcl/tests/programs/event-loop.tcl
Normal file
22
lib/tcl/tests/programs/event-loop.tcl
Normal file
@@ -0,0 +1,22 @@
|
||||
# expected: done
|
||||
# Cooperative scheduler demo using coroutines (generator style)
|
||||
# coroutine eagerly collects all yields; invoking the coroutine name pops values
|
||||
|
||||
proc counter {n max} {
|
||||
while {$n < $max} {
|
||||
yield $n
|
||||
incr n
|
||||
}
|
||||
yield done
|
||||
}
|
||||
|
||||
coroutine gen1 counter 0 3
|
||||
|
||||
# gen1 yields: 0 1 2 done
|
||||
set out {}
|
||||
for {set i 0} {$i < 4} {incr i} {
|
||||
lappend out [gen1]
|
||||
}
|
||||
|
||||
# last val is "done"
|
||||
lindex $out 3
|
||||
Reference in New Issue
Block a user