next up previous
Next: Pervasive Interfaces Up: Linkage in the Nemesis Previous: Runtime issues

A Concrete Example

Consider a body of code to implement a hash table. A programmer's interface to the table might be specified in Middl as followsgif:

HashTable : INTERFACE =
BEGIN
  Enter : PROC [ n : INTEGER, key : STRING ]
    RETURNS [ ];

     [...]      

END.
The Middl compiler would generate C defining the following data structures:
struct HashTable_op {
  void (*Enter)(struct HashTable_cl *self, int32 n, char *key);
  ..
};

struct HashTable_cl {
  struct HashTable_op *ms; /* ptr to method suite */
  void                *st; /* ptr to state        */
};
An instance of the hash table would be identified by a pointer to a HashTable_cl structure. This structure's ms pointer would point to a constant HashTable_ms structure, whose fields in turn would point to the code implementing the table. A method invocation in C might would look like:

ht->ms->Enter(ht, 10, "Token");

--where ht is a pointer to a Hash Table closuregif.

The code implementing the hash table might reside in a module called HTMod. This would include the code for the methods, the method suite struct, and a further method suite and closure (with null state pointer) for the following interface:

HTMod : INTERFACE =
  NEEDS HashTable;
  NEEDS Heap;
BEGIN
  New : PROC [ h : IREF Heap ]
    RETURNS [ ht : IREF HashTable ];
END.
(To create a Hash Table we need to supply a closure for a Heap object, and we are returned a closure to the newly created hash table).

The only externally visible symbol in the module would be the HTMod closure. The address of this struct is registered with the operating system's name server when the module is loaded. The code for the New method of the HTMod interface is completely stateless, thus it can be executed in any domain.



T. Roscoe