Modules

Overview

Compared to EPO, version 8.0, module Modules is changed as follows:

  • pick up the stack size setting from module Kernel
  • remove all freed module slots at the top of the module list

Stack Size

IMPORT Kernel;

PROCEDURE Init*;
BEGIN
  (* ... *)
  DEC(limit, Kernel.stackSize)
  (* was: DEC(limit, 8000H); *) 
END Init;

Modules.Free

In EPO and PO, Modules.Free will just mark the now unallocated memory slots as available, even if they are “at the top” of the module list (at module.root, “top” as in the list via System.ShowModules). Subsequent loading of a new module can thus result in unnecessary fragmentation. The solution below “cleans out” all free module slots at the top: module.root and AllocPtr are “adjusted down” to the first module slot actually in use.

PROCEDURE Free*(name: ARRAY OF CHAR);
  VAR mod, imp: Module; p, q: INTEGER;
BEGIN mod := root; res := 0;
  WHILE (mod # NIL) & (mod.name # name) DO mod := mod.next END ;
  IF mod # NIL THEN
    IF mod.refcnt = 0 THEN
      mod.name[0] := 0X; p := mod.imp; q := mod.cmd;
      WHILE p < q DO SYSTEM.GET(p, imp); DEC(imp.refcnt); INC(p, 4) END ;

      (* clean out any unallocated top slots *)
      IF mod = root THEN
        WHILE root.name[0] = 0X DO
          AllocPtr := SYSTEM.VAL(INTEGER, root); root := root.next
        END
      END
      (* --- *)

    ELSE res := 1
    END
  END
END Free;