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 CNIL suffix is emitted.

formatCondStatic

(cond options -- text) Formats a condition as TRUE, FALSE, or Cond under the formatting contract.
  • A known TRUE or FALSE condition produces that word; an unknown condition produces Cond.

formatDictStatic

(dict options -- text) Formats a dictionary with names, values, references, and virtual markers under the formatting contract.

Remarks

  • All fields are included in ordinal order, including private fields. Field privacy is not indicated. A static non-Meta field receives the literal virtual suffix; Meta fields do not need that suffix.

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 r32 for Real32. This formatter is not an exact round-trip conversion: 10.0 currently produces 9.999999999999997. Negative zero is written as 0.0.
  • Do not use the known-value path for NaN or infinity; it can fail during compilation. With -staticLoopLengthLimit 100, a known infinity fails with Static loop count limit (100) reached, and a known NaN can fail with Matching returned different result. Unknown non-finite values produce the schema name instead, such as Real64.

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; use formatTupleStatic directly 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 follows formatCodeStatic.

Formatting options

Formatting contract


Dictionary reshaping helpers

Reconstruction rules

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.
  • fieldWrapper must be a nonempty Struct; additional wrapper fields are ignored. The inserted field follows the reconstruction rules.
  • name must be known Text. Duplicate names are retained, with name lookup selecting the last definition.
  • The ordinal must be a known Int32 from 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 Int32 from 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.

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