-- file OSMiscOps.mesa
-- last modified by Satterthwaite, December 10, 1982 10:45 am

DIRECTORY
  Environment: TYPE USING [wordsPerPage],
  File: TYPE USING [
    Capability, Permissions, nullCapability, delete, grow, read, shrink, write],
  Strings: TYPE USING [String],
  TimeStamp: TYPE USING [Stamp];

OSMiscOps: DEFINITIONS = {

 -- utilities
 
  Address: TYPE = LONG POINTER;
  pageSize: CARDINAL = Environment.wordsPerPage;

  Pages: PROC [n: CARDINAL] RETURNS [Address];
  FreePages: PROC [base: Address];

  Words: PROC [nWords: CARDINAL] RETURNS [base: Address] = INLINE {
    RETURN [Pages[(nWords + (pageSize-1)) / pageSize]]};
  FreeWords: PROC [base: Address] = INLINE {FreePages[base]};

  SignalArgs: PROC RETURNS [signal, message: UNSPECIFIED];


 -- table bases
 
  GetTableBase: PROC [PROGRAM] RETURNS [LONG POINTER];
  
  
 -- functional version stamps
 
  Stamp: TYPE [3];

  MergeStamps: PROC [sum, item: Stamp] RETURNS [Stamp];
  TimeToStamp: PROC [time: TimeStamp.Stamp] RETURNS [Stamp] = INLINE {
    RETURN [LOOPHOLE[time]]};
  StampToTime: PROC [s: Stamp] RETURNS [TimeStamp.Stamp] = INLINE {
    RETURN [LOOPHOLE[s]]};
 
 
 -- unique ids
 
  GenerateUniqueId: PROC RETURNS [TimeStamp.Stamp];
  
  BcdCreateTime: PROC RETURNS [LONG CARDINAL];
  ImageId: PROC RETURNS [TimeStamp.Stamp];


 -- directory interface
 
  FileAccess: TYPE = {read, write, both};
  Permissions: ARRAY FileAccess OF File.Permissions = [
    read: File.read,
    write: File.write+File.grow+File.shrink+File.delete,
    both: File.read+File.write+File.grow+File.shrink+File.delete];

  FindFile: PROC [Strings.String, FileAccess←$read] RETURNS [File.Capability];
  RenameFile: PROC [newName, oldName: Strings.String];
  UnnameFile: PROC [oldName: Strings.String, file: File.Capability←File.nullCapability];
  DeleteFile: PROC [name: Strings.String];
  
  FileError: ERROR [name: Strings.String];

  }.