Helpers for building interface-style wrappers and concrete implementations over named method descriptions.


Model

Method descriptions declare parameters and results. interface turns them into a factory with a vtable of function addresses; its CALL constructs interface base objects with forwarding members.

implement turns an interface-base supplier ([Mover]) and a concrete-object supplier into a factory; its CALL constructs concrete objects containing base and the supplied fields.

obj.base is the borrowed interface view accepted where the interface is expected.

The factory owns the vtable; keep it alive and unmoved while its objects or views use it.


interface

(getMethods -- interfaceFactory) Builds a callable factory from a method-description supplier.

Generated interface shape

Method-description grammar

Generated fields

Interface factory

Vtable

Interface base


implement

(getBase getObject -- implementationFactory) Builds a callable implementation factory using an interface-base supplier and a concrete-object supplier.

Remarks


Generated implementation shape

Implementation factory

Concrete object and base adapter

Result and view rules

Implementation lifetime

Validation and reserved names


Examples

Example: generated implementation call

move of MoverImpl returns 42 for 41, both when called directly and through a Mover Cref passed to another function.

"String"    use
"control"   use
"interface" use

Mover: [move: [{value: Int32;} Int32];] interface;
MoverImpl: [Mover] [{
  move: {value: Int32;} Int32 {} codeRef;
  [1 +] !move
}] implement;

{base: Mover Cref;} Int32 {} [
  base:;
  41 base.move
] "useMover" exportFunction

{} Int32 {} [
  obj: MoverImpl;
  ("direct: " 41 obj.base.move LF) printList
  ("through a Mover Cref: " obj.base useMover LF) printList
  0
] "main" exportFunction

Expected Output

direct: 42
through a Mover Cref: 42

Example: method as a Block reading a concrete field

The Block method add reads the implementation's baseValue field, so adding 41 gives 51.

"String"    use
"control"   use
"interface" use

Adder: [add: [{amount: Int32;} Int32];] interface;
AdderImpl: [Adder] [{
  baseValue: 10;
  add: [baseValue +];
}] implement;

{} Int32 {} [
  object: AdderImpl;
  ("result=" 41 @object.base.add LF) printList
  0
] "main" exportFunction

Expected Output

result=51

Module helper

sameImplementation

(object0 object1 -- cond) Returns TRUE when both objects use the vtable of one factory; returns FALSE otherwise.
  • Each input is a concrete object, its base view, or an interface base object.
  • The result is unknown at compile time.

See also