home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / obero / oberon-a / source / kernel / kernel_1.4.mod
Encoding:
Text File  |  1994-09-03  |  6.9 KB  |  227 lines

  1. (**************************************************************************
  2.  
  3.      $RCSfile: Kernel_1.4.mod $
  4.   Description: Oberon-A run-time support module.
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 1.1 $
  8.       $Author: fjc $
  9.         $Date: 1994/09/03 16:16:34 $
  10.  
  11.   Copyright © 1994, Frank Copeland.
  12.   This file is part of Oberon-A.
  13.   See Oberon-A.doc for conditions of use and distribution.
  14.   _________________________________________________________________________
  15.  
  16.   Module Kernel will have a unique status in the Oberon-A system,
  17.   starting with Release 1.5. It will implement the startup and exit code
  18.   for each program, as well as the run-time support code for standard
  19.   procedures such as NEW that are too large or complex to be generated
  20.   inline by the compiler. Currently these tasks are handled by the code
  21.   in OberonSys.lib, which is written in assembly language. However, this
  22.   will require changes to the compiler to remove defunct procedures in
  23.   module SYSTEM and to change hard-coded assumptions about the calling
  24.   conventions and linker symbols of procedures in the run-time support
  25.   code.
  26.  
  27.   This module is provided to help smooth the transition, without waiting
  28.   for Release 1.5. It provides what will hopefully be close to the
  29.   interface to the final module Kernel, but uses the features of the
  30.   current Release 1.4 module SYSTEM to implement them.
  31.  
  32.   Existing code should be modified now to use module Kernel instead of
  33.   the extended features that are due to be removed from module SYSTEM.
  34.   These are:
  35.  
  36.     SYSTEM.ARGLEN and SYSTEM.ARGS -- replace with the fromWorkbench,
  37.       dosCmdBuf, dosCmdLen and WBenchMsg variables exported by module
  38.       Kernel.
  39.     SYSTEM.SETCLEANUP -- replace with Kernel.SetCleanup.
  40.     SYSTEM.GC -- replace with Kernel.GC.
  41.     SYSTEM.GETNAME -- replace with Kernel.Name.
  42.     SYSTEM.SIZETAG -- replace with Kernel.Size.
  43.     SYSTEM.NEWTAG -- replace with Kernel.NewFromTag.
  44.     SYSTEM.NEW -- when using the optional memory requirements parameter,
  45.       use Kernel.New.
  46.  
  47. **************************************************************************)
  48.  
  49. MODULE Kernel;
  50.  
  51. (*
  52. ** Turn off ALL compiler checks.
  53. **
  54. ** $C- CaseChk       $I- IndexChk  $L= LongAdr   $N- NilChk
  55. ** $P- PortableCode  $R- RangeChk  $S- StackChk  $T- TypeChk
  56. ** $V- OvflChk       $Z- ZeroVars
  57. *)
  58.  
  59. IMPORT SYS := SYSTEM;
  60.  
  61.  
  62. TYPE
  63.  
  64.   STRPTR = CPOINTER TO ARRAY 32767 OF CHAR;
  65.  
  66. (*-----------------------------------------------------------------------**
  67. ** These variables are used to hold the arguments passed to the program  **
  68. ** by AmigaDOS or Workbench. Do NOT make them writeable.                 **
  69. **-----------------------------------------------------------------------*)
  70.  
  71. VAR
  72.  
  73.   fromWorkbench -: BOOLEAN;  (* TRUE if the program was started from
  74.                              ** Workbench, FALSE if it was started by a
  75.                              ** Shell or CLI.
  76.                              *)
  77.  
  78.   dosCmdBuf     -: STRPTR;   (* When started from a Shell or CLI, this
  79.                              ** variable will hold the command line used
  80.                              ** to run the program. Only valid if
  81.                              ** fromWorkbench is FALSE.
  82.                              *)
  83.  
  84.   dosCmdLen     -: LONGINT;  (* The length in characters of the command
  85.                              ** line. Only valid if fromWorkbench is
  86.                              ** FALSE.
  87.                              *)
  88.  
  89.   WBenchMsg     -: SYS.CPTR; (* The startup message sent to the program
  90.                              ** by Workbench. Only valid if fromWorkbench
  91.                              ** is TRUE. This must be cast to a
  92.                              ** Workbench.WBStartupPtr to gain access to
  93.                              ** the arguments.
  94.                              *)
  95.  
  96.  
  97. (*-----------------------------------------------------------------------**
  98. ** These types are used to implement the automatic cleanup system.       **
  99. **-----------------------------------------------------------------------*)
  100.  
  101. TYPE
  102.  
  103.   CleanupProc * = PROCEDURE (VAR rc : LONGINT);
  104.  
  105.   CleanupPtr = CPOINTER TO CleanupRec;
  106.   CleanupRec = RECORD
  107.     link : CleanupPtr;
  108.     proc : CleanupProc;
  109.   END; (* CleanupRec *)
  110.  
  111.  
  112. (*-----------------------------------------------------------------------**
  113. ** This variable is used to hold the list of installed cleanup           **
  114. ** procedures.                                                           **
  115. **-----------------------------------------------------------------------*)
  116.  
  117. VAR
  118.  
  119.   cleanupList : CleanupPtr;
  120.  
  121. (*-----------------------------------------------------------------------*)
  122.  
  123. PROCEDURE* DoCleanup;
  124.  
  125.   VAR rc : LONGINT; cleanupPtr : CleanupPtr;
  126.  
  127. BEGIN (* DoCleanup *)
  128.   (* Execute any installed cleanup procedures. *)
  129.  
  130.   rc := SYS.RC(); cleanupPtr := cleanupList;
  131.   cleanupList := NIL; (* This avoids loops if an error occurs in a
  132.                       ** cleanup procedure.
  133.                       *)
  134.   WHILE cleanupPtr # NIL DO
  135.     cleanupPtr.proc (rc);
  136.     cleanupPtr := cleanupPtr.link
  137.   END;
  138. END DoCleanup;
  139.  
  140.  
  141. (* SetCleanup() installs a procedure that will be executed automatically
  142. ** when the program exits.
  143. *)
  144.  
  145. PROCEDURE SetCleanup * ( proc : CleanupProc );
  146.  
  147.   VAR newCleanup : CleanupPtr;
  148.  
  149. BEGIN (* SetCleanup *)
  150.   NEW (newCleanup); ASSERT (newCleanup # NIL, 25);
  151.   newCleanup.link := cleanupList; cleanupList := newCleanup;
  152.   newCleanup.proc := proc
  153. END SetCleanup;
  154.  
  155.  
  156. (* Size() returns the size in bytes of the record type whose type tag
  157. ** is passed as a parameter. The type tag is obtained by a call to
  158. ** SYSTEM.TAG.
  159. *)
  160.  
  161. PROCEDURE Size * ( type : SYS.TYPETAG ) : LONGINT;
  162.  
  163.   VAR size : LONGINT;
  164.  
  165. BEGIN (* Size *)
  166.   ASSERT (type # NIL, 132);
  167.   RETURN SYS.SIZETAG (type)
  168. END Size;
  169.  
  170.  
  171. (* Name() copies the name of the type whose type tag is passed as a
  172. ** parameter into a string variable. The type tag is obtained by a call to
  173. ** SYSTEM.TAG.
  174. *)
  175.  
  176. PROCEDURE Name * ( type : SYS.TYPETAG; VAR buf : ARRAY OF CHAR );
  177.  
  178. BEGIN (* Name *)
  179.   ASSERT (type # NIL, 132);
  180.   SYS.GETNAME (type, buf)
  181. END Name;
  182.  
  183.  
  184. (* NewFromTag() allocates a new record from the type tag passed as a
  185. ** parameter. The type tag is obtained by a call to SYSTEM.TAG.
  186. *)
  187.  
  188. PROCEDURE NewFromTag * ( VAR v : SYS.PTR; type : SYS.TYPETAG );
  189. BEGIN (* NewFromTag *)
  190.   ASSERT (type # NIL, 132);
  191.   SYS.NEWTAG (v, type)
  192. END NewFromTag;
  193.  
  194.  
  195. (* New() allocates a block of memory, with a specific set of memory
  196. ** requirements. The memory requirements are the same as those used by
  197. ** Exec.AllocMem().
  198. *)
  199.  
  200. PROCEDURE New * ( VAR v : SYS.CPTR; size : LONGINT; reqs : SET );
  201. BEGIN (* New *)
  202.   SYS.NEW (v, size, reqs)
  203. END New;
  204.  
  205.  
  206. (*
  207. ** GC is a straight replacement for SYSTEM.GC
  208. *)
  209.  
  210. PROCEDURE GC *;
  211. BEGIN
  212.   SYS.GC
  213. END GC;
  214.  
  215. BEGIN (* Kernel *)
  216.   SYS.ARGLEN (dosCmdLen);
  217.   fromWorkbench := (dosCmdLen < 0);
  218.   IF fromWorkbench THEN
  219.     dosCmdBuf := NIL;
  220.     SYS.ARGS (SYS.VAL (LONGINT, WBenchMsg))
  221.   ELSE
  222.     SYS.ARGS (SYS.VAL (LONGINT, dosCmdBuf));
  223.     WBenchMsg := NIL
  224.   END;
  225.   SYS.SETCLEANUP (DoCleanup)
  226. END Kernel.
  227.