tcl: Phase 6 — namespace, list ops, dict additions, scan/format, exec [WIP]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 50s

Phase 6a (namespace `::` prefix):
- tcl-global-ref?/strip-global helpers
- tcl-var-get/set route ::name to root frame
- tokenizer parse-var-sub accepts `::` start so $::var works
- tcl-call-proc forwards :fileevents/:timers/:procs/:commands
- char-at fast-path optimization on var-get/set hot path

Phase 6b (list ops): added lassign, lrepeat, lset, lmap.

Phase 6c (dict additions): added dict lappend, remove, filter -key.

Phase 6d (scan/format):
- printf-spec SX primitive wrapping OCaml Printf via Scanf.format_from_string
- scan-spec SX primitive (manual scanner for d/i/u/x/X/o/c/s/f/e/g)
- Tcl format dispatches via printf-spec; tcl-cmd-scan walks fmt and dispatches

Phase 6e (exec):
- exec-process SX primitive wraps Unix.create_process + waitpid
- Tcl `exec cmd arg...` returns trimmed stdout; raises on non-zero exit

test.sh inner timeout 3600s → 7200s (post-merge JIT recursion is slow).

+27 idiom tests covering ns, list ops, dict, format, scan, exec.

[WIP — full suite verification still pending]

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-08 08:28:05 +00:00
parent 63ad4563cb
commit 2fa0bb4df1
5 changed files with 763 additions and 88 deletions

View File

@@ -415,6 +415,115 @@
:result)
"")
; 60-63. Phase 6a namespace :: prefix
(ok "ns-set-from-proc-reaches-global"
(get
(run
"proc f {x} { set ::g $x }\nf hello\nset ::g")
:result)
"hello")
(ok "ns-read-from-proc"
(get
(run
"set ::v 42\nproc f {} { return $::v }\nf")
:result)
"42")
(ok "ns-incr-via-prefix"
(get
(run
"set ::n 5\nproc bump {} { incr ::n }\nbump\nbump\nset ::n")
:result)
"7")
(ok "ns-different-from-local"
(get
(run
"set x outer\nproc f {} { set x inner; set ::x global; return $x }\nf")
:result)
"inner")
; 64-69. Phase 6b list ops (lassign, lrepeat, lset, lmap)
(ok "lassign-three"
(get (run "lassign {a b c d e} x y z\nlist $x $y $z") :result)
"a b c")
(ok "lassign-leftover"
(get (run "lassign {1 2 3 4 5} a b") :result)
"3 4 5")
(ok "lrepeat-basic"
(get (run "lrepeat 3 a") :result)
"a a a")
(ok "lrepeat-multi"
(get (run "lrepeat 2 x y") :result)
"x y x y")
(ok "lset-replaces"
(get (run "set L {a b c d}\nlset L 2 ZZ\nset L") :result)
"a b ZZ d")
(ok "lmap-square"
(get (run "lmap n {1 2 3 4} {expr {$n * $n}}") :result)
"1 4 9 16")
; 70-72. Phase 6c dict additions (lappend, remove, filter)
(ok "dict-lappend-extends"
(get (run "set d {tags {a b}}\ndict lappend d tags c d\nset d") :result)
"tags {a b c d}")
(ok "dict-remove"
(get (run "dict remove {a 1 b 2 c 3} b") :result)
"a 1 c 3")
(ok "dict-filter-key"
(get (run "dict filter {alpha 1 beta 2 gamma 3} key a*") :result)
"alpha 1")
; 73-79. Phase 6d format and scan
(ok "format-int-padded"
(get (run "format {%05d} 42") :result)
"00042")
(ok "format-float-precision"
(get (run "format {%.2f} 3.14159") :result)
"3.14")
(ok "format-hex"
(get (run "format {%x} 255") :result)
"ff")
(ok "format-char"
(get (run "format {%c} 65") :result)
"A")
(ok "format-string-left"
(get (run "format {%-5s|} hi") :result)
"hi |")
(ok "scan-two-ints"
(get (run "scan {12 34} {%d %d} a b\nlist $a $b") :result)
"12 34")
(ok "scan-count"
(get (run "scan {hello 42} {%s %d}") :result)
"hello 42")
; 80-82. Phase 6e exec
(ok "exec-echo"
(get (run "exec echo hello world") :result)
"hello world")
(ok "exec-printf-no-newline"
(get (run "exec /bin/printf x") :result)
"x")
(ok "exec-with-args"
(get (run "exec /bin/echo -n test") :result)
"test")
(dict
"passed"
tcl-idiom-pass