[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

The Implementation File

The module's implementation is contained in an implementation file, conventionally with the .b suffix. This is the executable statements of the program. It can also be called the source file. Examples of implementation files are in the <inferno_root>/appl directory tree.

Program Listing 3-2 is the implementation file for the module interface file shown in Program Listing 3-1:

Program Listing 3-3 greet.b

  1. implement Greet;
  2. include "sys.m";
  3. include "draw.m";
  4. include "greet.m";
  5. sys: Sys;
  6. init(ctxt: ref Draw->Context, argv: list of string) {
  7. sys = load Sys Sys->PATH;
  8. if ((tl argv) != nil)
  9. sys->print("Hello, %s!\n", hd (tl argv));
  10. else
  11. sys->print("Hello, World!\n");
  12. }

This implementation file contains the function definition that is declared in the module interface file.

The implementation file can also contain private data and function member declarations and definitions. For example, the implementation file for the Random Module (in the <inferno_root>/appl/lib/rand.b file):

Program Listing 3-4 rand.b

  1. implement Rand;
  2. include "rand.m";
  3. rsalt: big;
  4. init(seed: int)
  5. {
  6. rsalt = big seed;
  7. }
  8. MASK: con (big 1<<63)-(big 1);
  9. rand(modulus: int): int
  10. {
  11. rsalt = rsalt * big 1103515245 + big 12345;
  12. if(modulus <= 0)
  13. return 0;
  14. return int (((rsalt&MASK)>>10) % big modulus);
  15. }
  16. bigrand(modulus: big): big
  17. {
  18. rsalt = rsalt * big 1103515245 + big 12345;
  19. if(modulus <= big 0)
  20. return big 0;
  21. return ((rsalt&MASK)>>10) % modulus;
  22. }

This file contains the definitions of the three public members, init, rand, and bigrand, as well as other private members, such as rsalt and MASK.

The Executable File

The compiled implementation file, the Dis executable file (.dis) is conventionally stored in the <inferno_root>/dis directory.

The executable file is the object that is loaded at run-time. This is done with the load statement. For example, to load the rand.dis file, the load statement looks like:

	rand := load Rand Rand->PATH;

This is discussed more in the Using Modules section on page 3-11.



[Contents]
[Prev] [Next] [Limbo Basics] [Limbo Programming] [Language Definition]

Copyright © 1998, Lucent Technologies, Inc. All rights reserved.