Mref

Address-based non-owning wrapper that reconstructs one referenced value through one schema-supplier helper.


Construction forms

Typical construction forms differ only by the mutability of the schema supplier closure.

myRef: @getSchema Mref;        # mutable result from CALL
myRef: [getSchema Cref] Mref;  # immutable result from CALL

getSchema is one helper that returns one representative value or reference of the required schema.


Stored address model


Lifetime boundary


Methods

CALL (-- ref) Reconstructs the current referenced value from the stored address.

Postconditions

  • The result schema is supplied by getSchema.
  • The result mutability follows the mutability of the wrapper closure.
set (source --) Stores the address of the supplied target in the wrapper.

Preconditions

  • source matches the schema supplied by getSchema.
  • The target remains valid for later CALL reconstruction.

Fields


Examples

Mutable and immutable wrappers

"Mref" use
"control" use

Int32Schema: [0];

{} () {} [
  value: 5;

  mutableHolder: @Int32Schema Mref;
  @value @mutableHolder.set
  mutableHolder printStack _:;

  immutableHolder: [Int32Schema Cref] Mref;
  @value @immutableHolder.set
  immutableHolder printStack _:;
] "main" exportFunction

Expected Output During Compilation

Int32 Ref
Int32 Cref

Runtime example

"Mref" use
"String" use
"control" use

Int32Schema: [0];

{} Int32 {} [
  value0: 5;
  value1: 9;
  holder: @Int32Schema Mref;
  @value0 @holder.set
  ("first=" holder new LF) printList
  @value1 @holder.set
  ("second=" holder new LF) printList
  0
] "main" exportFunction

Expected Output

first=5
second=9

See also