Static formatting helpers operate on known values and supported unknown values; dictionary-shape manipulation utilities are also provided.
Static formatting surface
formatCodeStatic
(block options -- text) Formats a Block as the Text Code when expandCode is absent or FALSE; see the formatting contract.Remarks
Known issue: enabling expandCode with TRUE fails compilation with «codeTokenCount», Name was not found for any Block, including an empty Block. Without the option a Block formats as Code.
formatCodeRefStatic
(codeRef options -- text) Returns the Text CodeRef under the formatting contract.Remarks
- Code knownness, NIL state, and options do not change the result; no
CNILsuffix is emitted.
formatCondStatic
(cond options -- text) Formats a condition as TRUE, FALSE, or Cond under the formatting contract.formatDictStatic
(dict options -- text) Formats a dictionary with names, values, references, and virtual markers under the formatting contract.- Reference suffixes follow the reference-marker rule.
Remarks
formatIntegerStatic
(integer options -- text) Formats an integer value or integer schema name under the formatting contract.- A known value is rendered in the selected base with its schema suffix; an unknown value yields its schema name and ignores
base.
formatRealStatic
(real options -- text) Formats a real value or real schema name under the formatting contract.Remarks
- Known finite values use decimal text, with
r32forReal32. This formatter is not an exact round-trip conversion:10.0currently produces9.999999999999997. Negative zero is written as0.0. - Do not use the known-value path for NaN or infinity; it can fail during compilation. With
-staticLoopLengthLimit 100, a known infinity fails withStatic loop count limit (100) reached, and a known NaN can fail withMatching returned different result. Unknown non-finite values produce the schema name instead, such asReal64.
formatStructStatic
(struct options -- text) Dispatches Struct formatting under the formatting contract.- Uses dictionary formatting for an empty Struct or one with any named field. Otherwise it uses tuple formatting. Thus an empty Tuple produces
{}through this dispatcher; useformatTupleStaticdirectly for().
formatTextStatic
(text options -- text) Formats known Text with quotes or unknown Text as Text under the formatting contract.- For known Text, prepends and appends a quotation mark without escaping or validating the contents. The result need not be a valid source-code or JSON literal. Unknown Text produces the word
Text.
formatTupleStatic
(tuple options -- text) Formats tuple fields with optional indentation under the formatting contract.- Reference fields use the reference-marker rule when their targets satisfy
sized?.
formatObjectStatic
(object options -- text) Formats supported objects by schema under the formatting contract.- It accepts
Cond, Text, Block, Code, integer and real objects, and Structs. Block input formats as the legacy Text Code; Code input formats as the legacy Text CodeRef. Block expansion followsformatCodeStatic.
Formatting options
Formatting contract
- Formatting is resolved during compilation. Supported unknown values are represented by schema names, not by their eventual runtime contents. Successful calls return one known Text object. These are diagnostic formatters, not runtime value serializers.
- Options may omit every field. A used
basemust be a knownInt32from 2 through 16; the default is 10. Base 16 adds0xbefore the magnitude, after any minus sign.Int32has no suffix;Int8,Int16,Int64,Intx,Nat8,Nat16,Nat32,Nat64, andNatxuse their literal suffixes. Unknown integer values ignorebaseand yield their schema name. expandCodeis aCond, normally absent or known FALSE; token expansion is a current limitation (see formatCodeStatic).dictIndentandtupleIndent, when used, are known nonnegativeInt32nesting counters. Presence selects multiline formatting. Each level adds two spaces; each counter advances independently for its own container kind. Empty containers do not add a newline. Caller options are not modified.- Dict/Tuple reference suffixes apply to fields stored as references whose targets satisfy
sized?. The suffix isReforCrefaccording to that field's view. DirectformatObjectStaticof a reference does not add such a suffix or reveal its address/NIL state. Other option fields do not control private, static, or reference markers.
Dictionary reshaping helpers
Reconstruction rules
- These operations reconstruct fields; they are not general runtime data copies. A Ref field retains its referenced object and view. A non-Ref Struct is rebuilt recursively. Other known non-Ref fields use copy/move construction; unknown non-Ref fields produce new variables of the same schema without copying their source values.
- Field order and names are preserved by
cloneDict. Applicable static qualifiers are preserved, but private visibility is not: transferred fields are public. Contained Ref aliases remain aliases. List/Tuple fields can be reconstructed as well as named Dict fields. unwrapFieldreturns one reconstructed field object;unwrapFieldsleaves one result per field in ordinal order.cloneDict,insertField, andremoveFieldreturn new Struct objects, not references.- These are compile-time shape operations even when some field values are unknown.
cloneDict
(dict -- dict) Rebuilds a new Struct with fields in the original order.- See the reconstruction rules; contained references remain aliases and transferred fields are public.
fieldNeedsVirtual
(dict ordinal -- cond) Reports whether the selected field is static and its field object is not Meta.insertField
(dict fieldWrapper name ordinal -- result) Rebuilds dict with field 0 of fieldWrapper inserted at ordinal under name.fieldWrappermust be a nonempty Struct; additional wrapper fields are ignored. The inserted field follows the reconstruction rules.namemust be known Text. Duplicate names are retained, with name lookup selecting the last definition.- The ordinal must be a known
Int32from 0 through fieldCount, inclusive. - An out-of-range ordinal fails with
[ordinal] is out of bounds.
removeField
(dict ordinal -- dict) Rebuilds dict without the field at ordinal.- The ordinal must be a known
Int32from 0 through fieldCount − 1; removing the last field produces an empty Struct. - An out-of-range ordinal fails with
[ordinal] is out of bounds. - The result follows the reconstruction rules.
transferField
(dict ordinal --) Defines the selected field in the surrounding Struct construction.- It preserves the field name and applicable static qualifier. Process it inline, for example
{source 0 @transferField ucall}. - An ordinary call does not add the field to the caller's Struct and does not leave value, name, or condition outputs. Field contents follow the reconstruction rules; private visibility is not preserved.
Unwrap helpers
unwrapField
(dict ordinal -- value) Returns one reconstructed field object.- See the reconstruction rules.
unwrapFields
(dict -- values) Returns one reconstructed value per field in ordinal order.- Unknown non-Ref fields are fresh variables of their schemas. Contained references remain aliases. See the reconstruction rules.
Examples
Formatting options
"control" use
"objectTools" use
{} () {} [
{x: 255n32; y: (1i32 2i32);} {base: 16; dictIndent: 0; tupleIndent: 0;} formatObjectStatic printStack _:;
] "main" exportFunction
Expected Output During Compilation
"{
x: 0xFFn32;
y: (
0x1
0x2
);
}"
insertField
"control" use
"objectTools" use
{} () {} [
{x: 1i32; z: 3i32;} {value: 2i32;} "y" 1 insertField printStack _:;
] "main" exportFunction
Expected Output During Compilation
{
x: 1;
y: 2;
z: 3;
}
removeField
"control" use
"objectTools" use
{} () {} [
{x: 1i32; y: 2i32; z: 3i32;} 1 removeField printStack _:;
] "main" exportFunction
Expected Output During Compilation
{
x: 1;
z: 3;
}
Runtime field rewrite check
"String" use
"control" use
"objectTools" use
{} Int32 {} [
inserted: {x: 1; z: 3;} {value: 2;} "y" 1 insertField;
removed: inserted 1 removeField;
("actual=" inserted.y ",count=" removed fieldCount LF) printList
0
] "main" exportFunction
Expected Output
actual=2,count=2
See also
- String: UTF-8 string views, owned strings, formatting helpers, and text conversion utilities.
- algorithm: Collection interfaces, comparison helpers, iteration adapters, and view slicing utilities.
- Json: JSON value type, parsing helpers, and serialization helpers.
- Xml: XML document, parser, and serialization helpers.