t3x.org / t3x / t3x-manual / 4I.html
 
T3X - A Minimum Procedural Language
Version 8.1.5, Online Edition
Copyright(C) 1996-2004
Nils M Holm
 
Previous:
4.17.1 Generated Hints
TOC | Index | Back Next:
4.19 Resolving Interface References

4.18 Loading Tcode

The Tcode language provides a set of instructions for binding modules which were compiled separately. External references are limited to procedure calls. This means that a module can call procedures defined in an external module, but it cannot access an external module's data.

To call an external procedure, the label which tags the entry point of the routine must be declared public (using a PUB instruction) in the module containing the called routine. In the module of the caller, it must be declared extern (using EXT).

The PUB instruction provides a symbolic name for a procedure. This symbolic name may be referenced by EXT in a different module. CALX instructions are used to reference an EXT instruction defined in the same module. An external reference is resolved in four steps:

  1. The external label, which is the operand of a CALX instruction, is looked up in the external symbol table (a table holding the EXT records).
  2. The name contained in the matching EXT record is looked up in the public symbol table (a table holding the PUB records).
  3. The label contained in the matching PUB record replaces the external label in the CALX instruction.
  4. CALX is replaced with CALL.

The following figure illustrates the principle of external references.

+----------------------------+      +----------------------------+
|                            |      |                            |
|    ,--> EXT E 4 name >================> PUB L 4 name           |
|    |                       |      |     CLAB L HDR ... END     |
|    '-------.-.-----------, |      |                            |
|            | |           | |      |                            |
|  CALX E >--' |  CALX E >-' |      |                            |
|              |             |      |                            |
|     CALX E >-'             |      |                            |
|                            |      |                            |
+----------------------------+      +----------------------------+
       Caller's Module                     Callee's Module
Fig.8 External References

Annotations

Since labels are represented by integers in Tcode, label collisions will occur when binding two (or more) Tcode modules. Therefore, labels must be renamed: When a module A already has been loaded and a module B is to be loaded, the highest label ID used in A should be added to each (non-external) label in B.

Two or more EXT records with the same name may exist, because the same symbol may be associated with different external labels in different modules.

The existance of two PUB records with the same name is considered an error (redefinition error).

There must be a matching PUB record for each EXT record. Otherwise, an error is signalled (unresolved external).

Previous:
4.17.1 Generated Hints
TOC | Index | Back Next:
4.19 Resolving Interface References