addressToReference (address modelValue -- reconstructedValue)

Inputs

Outputs

addressToReference reconstructs a typed result from a Natx storage address and a model object.

The model object is used only to choose the result schema case and, for a Ref model, the result mutability. Construction does not dereference the model, read storage, validate the address, or make a nonzero address safe for later use; the caller owns address validity and alignment.

For a non-static, non-callable In-place local or field (see selection), NAME or .NAME supplies the immutable Ref model case, while @NAME supplies the mutable case for a local and .@NAME supplies it for a field only when the enclosing Dict is reached through a mutable path.

Behavior

Example

{} () {} [
  value: 7;
  text: "hello";
  code: {} () {} codeRef;

  "-- Ref model value --" printCompilerMessage
  @value storageAddress @value addressToReference printStack _:;
  0nx @value addressToReference printStack _:; # a NIL Ref

  "-- immutable Ref model value --" printCompilerMessage
  @value storageAddress value addressToReference printStack _:;
  0nx value addressToReference printStack _:;

  "-- direct In-place model value --" printCompilerMessage
  0nx 7 addressToReference printStack _:;

  "-- Text and Code model values --" printCompilerMessage
  text storageAddress text addressToReference printStack _:;
  0nx text addressToReference printStack _:;
  0nx @code addressToReference printStack _:;
] "main" exportFunction

Expected Output During Compilation

-- Ref model value --
Int32 Ref
Int32 NIL
-- immutable Ref model value --
Int32 Cref
Int32 CNIL
-- direct In-place model value --
Int32 NIL
-- Text and Code model values --
Text
Text CNIL
{} () {} codeRef CNIL

See also