Artifact 3bcbf758e5bd8c078a7bd8052c10845971fb8cfdfb657d827165be5b409cbdd5:
- File typeparse/tests_tclsh/t72_compact_type.tcl — part of check-in [7952bb1028] at 2026-10-24 04:37:06 on branch tip-764_tcl90 — V15q `type def {-compact}T`, `type is {compact?}`, and `type {c!}export` are now in place, following the chosen design—this is version v15q, available in `typeparse.zip`. `type is {compact?}polygone` checks the type, while `type is {compact?}$P` checks the value. I did not need to modify local annotations for value-based checks; the value retains only its content, which is precisely what holds the underlying data cells. tcl type def {-compact}polygone list.point set {polygone}P {0 0} {4 0} {4 3} ;# {0.0 0.0} {4.0 0.0} {4.0 3.0} type is {compact?}polygone ;# 1: the type requires it type is {compact?}$P ;# 1: the value is stored in cells string length $P; type is {compact?}$P ;# still 1 type {c!}export point ;# the C header (replaces `type c`) Normalization upon construction: `0` becomes `0.0`, and `0x10` becomes `16`. A `double(32)` is rounded to a `float`: `0.1` becomes `0.10000000149011612`. This normalization also applies to `set P(i.x)`, `lset`, and `lappend`. Conversions on a copy: core string and byte functions now operate on a string copy, maintained alongside the data cells. This is implemented via the new kernel patch `compact-conversions.patch`, which modifies `tclStringObj.c` and `tclBinary.c`. `tcl::unsupported::content` returns a copy that shares the same underlying data cells. This also applies to the global switch: in v15p, `string length $P` would break the compact form, but that is no longer the case. The following are disallowed in a definition: a type that is not a list of fixed-size elements (the definition is discarded, and the name remains available); an unknown option; `{-compact}` applied to an alias; a parameterized family (which I have not yet implemented). Export: `{llvm!}export` returns "not available yet," and an export without a target—or with an unknown target—is rejected. I discovered a flaw along the way: `string reverse` could modify the content of an annotated value in-place. This is no longer the case. A limitation regarding the `is` type check: if the text of a value also happens to be a type name (a value that is literally a type name), the query is interpreted as a type check. I have noted this in the planning. Tests against v15p: All expected outputs pass, with the exception of `t70_compact.out`; I have regenerated it because `string length` now maintains the compact format there. All tests and examples yield the same output, regardless of whether `TCL_TYPES_COMPACT=1` is set. The Tcl `string*`, `binary`, `stringObj`, `utf`, `dict`, `lset*`, and `list*` test suites show 3,482 passes out of 3,579, with 97 skipped and zero failures—consistent with v15. `valgrind` (PURIFY build) reports no issues for `t70_compact`, `t71_type_c`, and the new `t72_compact_type`. (user: Florentis, size: 2620) [annotate] [blame] [check-ins using]
# t72 : type def {-compact}T : les valeurs du type sont toujours en cases, les # nombres normalisés à la construction ; type is {compact?} ; conversions sur # une copie (la forme compacte reste) ; refus motivés. proc t {l s} { set rc [catch {uplevel 1 $s} m]; puts [format "%-34s %s %s" $l $rc $m] } type def point {{double}x; {double}y} type def {-compact}polygone list.point t "type is {compact?}polygone" {type is {compact?}polygone} t "type is {compact?}list.point" {type is {compact?}list.point} t "type is {compact?}point" {type is {compact?}point} set {polygone}P {0 0} {4 0} {4 3} t "construit, normalisé" {set P} t "type is {compact?}\$P" {type is {compact?}$P} t "string length" {list [string length $P] [type is {compact?}$P]} t "string reverse" {list [string reverse $P] [string reverse $P] [type is {compact?}$P]} t "string range" {list [string range $P 0 8] [type is {compact?}$P]} t "dict size (refus)" {list [catch {dict size $P}] [type is {compact?}$P]} t "set P(1.x) 7" {set P(1.x) 7; list $P [type is {compact?}$P]} t "lappend {1 2}" {lappend P {1 2}; list $P [type is {compact?}$P]} t "lset 0 {5 5}" {lset P 0 {5 5}; list $P [type is {compact?}$P]} t "lappend invalide" {lappend P {a b}} t "contenu puis conversion" {set c [tcl::unsupported::content $P]; string length $c; type is {compact?}$P} t "list.point ordinaire" {set {list.point}L {0 0}; list $L [type is {compact?}$L]} t "cast vers polygone" {set Q [type cast polygone {{1 1} {2 2}}]; list $Q [type is {compact?}$Q]} t "valeur ordinaire" {type is {compact?}{1 2}} type def {-compact}vf list.double(32) t "double(32) arrondi" {set {vf}F 0.1 0.5; set F} type def {-compact}octets list.int(u,8) t "int(u,8)" {set {octets}B 1 2 0x10; list $B [catch {lappend B 256} m] $m} t "refus : list.string" {type def {-compact}noms list.string} t "le nom refusé reste libre" {type def noms list.string; type get [set {noms}n a b]} t "refus : un produit" {type def {-compact}pp {{double}x}} t "refus : option inconnue" {type def {-zz}u list.double} t "refus : alias" {type alias {-compact}w list.double} t "refus : famille" {type def {-compact}{v({int}n)} {list($n).double}} t "question inconnue" {type is {zz?}point} t "sans question" {type is point} t "export : llvm" {type {llvm!}export point} t "export : sans cible" {type export point}