Pascal III: Intrinsic Units

Pascal III: Intrinsic Units

Intrinsic Units in Pascal allow the programmer to write and compile code in
modules.  The progammer can put the modules in a library; several different
programs can then use them without a separate linking step.  The unit is
automatically loaded with the program code file when the program is executed.
 
The following is a simple example of how to write an intrinsic unit. It is a
supplement to the information in chapter 14 of the Programmer's Manual.
 
First let's enter the unit.  This unit has one function that asks for an
integer number and returns that number doubled. From the editor, enter:
 
        UNIT LIB2;
        INTRINSIC CODE 10;
 
        INTERFACE
        FUNCTION DOUBLE (NUM:INTEGER):INTEGER;
 
        IMPLEMENTATION
        FUNCTION DOUBLE;
        BEGIN
           DOUBLE := NUM + NUM;
        END;
 
        BEGIN
          WRITELN ('LIB2 INITIALIZATION');
        END.
 
Save the file as LIB2, quit the Editor and compile the unit.
 
Now put the unit in a library.  We suggest you use a program library for this
test so that you won't have to modify the SYSTEM.LIBRARY. Here's how to do it:
 
        Execute /PASCAL3/LIBRARY
        The destination will be TEST2.LIB
        The source is LIB2.CODE
        Enter "=" to copy the entire codefile into the library
        Enter "Q" to save the library and exit the program
        Press return when asked for Notice?
 
When that's done, go back to the Editor and enter:
 
        PROGRAM TEST2;
 
        USES {$USING TEST2.LIB} LIB2;
 
        VAR INT:INTEGER;
 
        BEGIN
          READLN (INT);
          WRITELN (INT, ' times 2 equals ', DOUBLE (INT));
        END.
 
Save the file as TEST2 and quit the Editor.  Compile the program.  The unit
will be loaded automatically when the program is executed.