fieldRead

fieldRead (structValue ordinal -- selectedItem)

Inputs

Outputs

fieldRead reads one selected item by zero-based item ordinal, with the Struct value before the ordinal. Both inputs are dereferenced first.

Selection happens inside the builtin from data inputs. fieldRead does not call callable items automatically. A mutable Ref result from a non-static In-place item can serve as the already-selected destination for set.

Behavior

fieldIsRef and fieldIsVirtual describe the selected item schema, not the stack result produced by fieldRead. A non-static In-place item can therefore yield a Ref result even when fieldIsRef is FALSE, while a static or Meta item can still yield a copied or newly constructed result even when fieldIsVirtual is TRUE.

Example

{} 0 {} [
  dict: {
    ordinaryField: 0;
    staticField: 1 virtual;
    textField: 0 ("") dynamic @;
    codeField: {} () {} codeRef;
    metaField: ();
  };
  list: (1 2) dynamic;
  ordinal: 0 dynamic;

  "-- In-place field through mutable struct --" printCompilerMessage
  @dict 0 fieldRead printStack _:;

  "-- In-place field through immutable struct --" printCompilerMessage
  dict 0 fieldRead printStack _:;

  "-- static field --" printCompilerMessage
  dict 1 fieldIsVirtual printStack _:;
  @dict 1 fieldRead printStack _:;

  "-- text field --" printCompilerMessage
  @dict 2 fieldRead printStack _:;

  "-- code field --" printCompilerMessage
  @dict 3 fieldRead printStack _:;

  "-- meta field --" printCompilerMessage
  @dict 4 fieldRead printStack _:;

  "-- uniform struct through unknown ordinal --" printCompilerMessage
  @list ordinal fieldRead printStack _:;

  0
] "main" exportFunction

Expected Output During Compilation

-- In-place field through mutable struct --
0 Ref
-- In-place field through immutable struct --
0 Cref
-- static field --
TRUE
1
-- text field --
Text
-- code field --
{} () {} codeRef CNIL
-- meta field --
()
-- uniform struct through unknown ordinal --
Int32 Ref

See also