(* Copyright (c) xTech 1992,94. All Rights were Reserved *)
(* Copyright (c) 2000 Excelsior *)
(* XDS (ANSI C) v2.0 *)
DEFINITION MODULE oberonRTS;

IMPORT  SYSTEM;

TYPE
  Module;
  Type;
  Command = PROC;
  CARDINAL = SYSTEM.CARD32;
  Finalizer = PROCEDURE (SYSTEM.ADDRESS);

VAR
  nullModule: Module;
  nullType: Type;

(* ------------------ Garbage Collector ------------------ *)

PROCEDURE Collect;
(* Garbage Collector *)


PROCEDURE CompactHeap;
(* GC invokation with forced heap compaction *)


PROCEDURE GetInfo(VAR objects, busymem: CARDINAL);
(* Returns number of allocated objects and total size
   of allocated memory.
*)

PROCEDURE gcAnchorTrace (on :BOOLEAN);
(* enables/disables printing "heap weight" of global variables
   when garbage collecting
*)


(* ----------------- Object finalization ----------------- *)

PROCEDURE InstallFinalizer(f: Finalizer; obj: SYSTEM.ADDRESS);
(* Sets finalizer "f" for object "obj". The finalizer will be
   called when the object will become unreachable.
   Notes:
        - finalizer is called on GC stack (stack size is limited);
        - finalized object may be became reachable, in this case
          it will not be deleted;
*)

(*--------------- Meta-language facilities --------------- *)

PROCEDURE Search(name: ARRAY OF CHAR): Module;
(* Returns module or "nullModule" *)

PROCEDURE NameOfModule(m: Module; VAR name: ARRAY OF CHAR);
(* Returns the name of module *)

PROCEDURE ThisCommand(m: Module; name: ARRAY OF CHAR): Command;
(* Returns the command or NIL *)

PROCEDURE ThisType(m: Module; name: ARRAY OF CHAR): Type;
(* Returns the type or "nullType" *)

PROCEDURE SizeOf(t: Type): INTEGER;
PROCEDURE BaseOf(t: Type; level: INTEGER): Type;
PROCEDURE LevelOf(t: Type): INTEGER;
PROCEDURE ModuleOf(t: Type): Module;
PROCEDURE NameOfType(t: Type; VAR name: ARRAY OF CHAR);

PROCEDURE TypeOf(obj: SYSTEM.ADDRESS): Type;

PROCEDURE NewObj(type: Type): SYSTEM.ADDRESS;
(* Create a new object of the type. *)

(* -------------- Iterators ------------------- *)

TYPE
  NameIterator = PROCEDURE (SYSTEM.ADDRESS, ARRAY OF CHAR): BOOLEAN;
  (* Return FALSE to stop iteration *)

PROCEDURE IterModules(session: SYSTEM.ADDRESS; iter: NameIterator);
(* Iterates all Oberon-2 modules. *)

PROCEDURE IterCommands(mod: Module; session: SYSTEM.ADDRESS; iter: NameIterator);
(* Iterates all commands in the module *)

PROCEDURE IterTypes(mod: Module; session: SYSTEM.ADDRESS; iter: NameIterator);
(* Iterates all types in the module *)

END oberonRTS.
