Skip to content

Language Specification (F) : Library Interfaces

Benjamin Kowarsch edited this page Jan 12, 2024 · 17 revisions

Library Interfaces

Standard Library

Status

INTERFACE MODULE Status;
(* Status Root Type *)
TYPE Status = RECORD ( NIL )
  failed : BOOLEAN
END; (*Status*)
END Status.

StatusCode

INTERFACE MODULE StatusCode;
(* Status−Code Base Type *)
TYPE StatusCode = ( Success, Failure );
END StatusCode.

Characters

ISO646

INTERFACE MODULE ISO646;
CONST (* Control Codes *)
  NUL=0u0; SOH=0u1; STX=0u2; ETX=0u3; EOT=0u4; ENQ=0u5; ACK=0u6; BEL=0u7; BS=0u8; TAB=0u9; LF=0u0A;
  VT=0u0B; FF=0u0C; CR=0u0D; SO=0u0E; SI=0u0F; DLE=0u10; DC1=0u11; DC2=0u12; DC3=0u13; DC4=0u14; NAK=0u15;
  SYN=0u16; ETB=0u17; CAN=0u18; EN=0u19; SUB=0u1A; ESC=0u1B; FS=0u1C; GS=0u1D; RS=0u1E; US=0u1F; DEL=0u7F;
CONST (* Printables *)
  SP=0u20; Exclamation=0u21; DoubleQuote=0u22; Octothorpe=0u23; Dollar=0u24; Percent=0u25; Ampersand=0u26;
  SingleQuote=0u27; LeftParenthesis=0u28; RightParenthesis=0u29; Asterisk=0u2A; Plus=0u2B; Comma=0u2C;
  Minus=0u2D; Period=0u2E; Solidus=0u2F; Colon=0u3A; Semicolon=0u3B; Less=0u3C; Equals=0u3D; Greater=0u3E;
  QuestionMark=0u3F; AtSign=0u40; LeftBracket=0u5B; Backslash=0u5C; RightBracket=0u5D; Caret=0u5E;
  Lowline=0u5F; Backquote=0u60; LeftBrace=0u7B; VerticalBar=0u7C; RightBrace=0u7D; Tilde=0u7E;
CONST (* Common Synonyms *)
  Whitespace=SP; Apostrophe=SingleQuote; LeftParen=LeftParenthesis; RightParen=RightParenthesis;
  HyphenMinus=Minus; Dot=Period; Slash=Solidus; LeftAngularBracket=Less; RightAngularBracket=Greater;
END ISO646.

Char, Unichar

INTERFACE MODULE <#TitlecasedCharTypeIdent#>;
PROCEDURE isDigit ( ch : <#CharTypeIdent#> ) : BOOLEAN; (* any digit *)
PROCEDURE isLetter ( ch : <#CharTypeIdent#> ) : BOOLEAN; (* any letter *)
PROCEDURE isLower ( ch : <#CharTypeIdent#> ) : BOOLEAN; (* any lowercase letter *)
PROCEDURE isUpper ( ch : <#CharTypeIdent#> ) : BOOLEAN; (* any uppercase letter *)
PROCEDURE isControl ( ch : <#CharTypeIdent#> ) : BOOLEAN; (* 0u0..0u2F or 0u7F *)
PROCEDURE isAlphaNum ( ch : <#CharTypeIdent#> ) : BOOLEAN; (* any digit or letter *)
PROCEDURE isPrintable ( ch : <#CharTypeIdent#> ) : BOOLEAN; (* any non−alpha−numeric printable *)
PROCEDURE toLower ( ch : <#CharTypeIdent#> ) : <#CharTypeIdent#>;
  (* returns argument transformed to lowercase *)
PROCEDURE toUpper ( ch : <#CharTypeIdent#> ) : <#CharTypeIdent#>;
  (* returns argument transformed to uppercase *)
END <#TitlecasedCharTypeIdent#>.

Replace <#TitlecasedCharTypeIdent#> with Char / Unichar , and <#CharTypeIdent#> with CHAR / UNICHAR.

Collation Order

Collation libraries bind custom collation tables to the language processor’s internal table used by function COLLATION().

Library collation tables contain the collation indices for characters in range [0u20..0u7E]. Control characters are excluded.

AsciiCollation

INTERFACE MODULE AsciiCollation;
(* ASCII Collation Order *)
CONST [COLLATION] Order = { 0..94 }; (* 95 values *)
END AsciiCollation.

EbcdicCollation

(* EBCDIC Collation Order *)
CONST [COLLATION] Order = { 0, 6, 25, 21, 7, 15, 5, 23, 3, 9, 8, 4, 14, 11, 1, 12, 85, 86, 87, 88, 89, 90,
  91, 92, 93, 94, 20, 10, 2, 24, 17, 18, 22, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
  72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 54, 84, 55, 53, 16, 19, 26, 27, 28, 29, 30, 31, 32, 33, 34,
  35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 56, 13, 83, 52 }; (* 95 values *)
END EbcdicCollation.

Dynamic Strings

String, UniString

Template for dynamic string libraries String and UniString.

INTERFACE MODULE <#StringTypeIdent#>;
TYPE <#StringTypeIdent#> = OPAQUE POINTER;
CONST [TLIMIT] CapacityLimit = 0;
PROCEDURE [NEW] New ( VAR s : <#StringTypeIdent#> );
PROCEDURE [NEW+] NewWithStr ( VAR s : <#StringTypeIdent#>; CONST initStr : ARRAY OF <#CharTypeIdent#> );
PROCEDURE [NEW#] NewWithCapacity ( VAR s : <#StringTypeIdent#>; capacity : LONGCARD );
PROCEDURE [RETAIN] Retain ( VAR s : <#StringTypeIdent#> );
PROCEDURE [RELEASE] Release ( VAR s : <#StringTypeIdent#> );
PROCEDURE [ATVALUE] charAtIndex ( CONST s : <#StringTypeIdent#>; atIndex : LONGCARD ) : <#CharTypeIdent#>;
PROCEDURE [ATSTORE] storeAtIndex ( VAR s : <#StringTypeIdent#>; atIndex : LONGCARD; ch : <#CharTypeIdent#> );
PROCEDURE [LENGTH] length ( CONST s : <#StringTypeIdent#> ) : LONGCARD;
PROCEDURE [APPEND] AppendChars ( VAR s : <#StringTypeIdent#>; CONST chars : ARRAY OF <#CharTypeIdent#> );
PROCEDURE [ATINSERT] InsertChars
  ( VAR s : <#StringTypeIdent#>; atIndex : LONGCARD; CONST chars : ARRAY OF <#CharTypeIdent#> );
PROCEDURE [ATREMOVE] RemoveChars ( VAR s : <#StringTypeIdent#>; startIndex, endIndex : LONGCARD );
END <#StringTypeIdent#>.

Replace <#StringTypeIdent#> with String or UniString, and <#CharTypeIdent#> with CHAR or UNICHAR respectively.

Key-Value Storage

Template for arbitrary dynamic key-value storage libraries.

INTERFACE MODULE <#TypeIdent#>;
TYPE <#TypeIdent#> = OPAQUE POINTER;
CONST [TLIMIT] CapacityLimit = 0;
PROCEDURE [NEW] New ( VAR dict : <#TypeIdent#> );
PROCEDURE [RETAIN] Retain ( VAR dict : <#TypeIdent#> );
PROCEDURE [RELEASE] Release ( VAR dict : <#TypeIdent#> );
PROCEDURE [VALUE] valueForKey ( CONST dict : <#TypeIdent#>; key : <#KeyTypeIdent#> ) : <#ValueTypeIdent#>;
PROCEDURE [STORE] StoreKV ( VAR dict : <#TypeIdent#>; key : <#KeyTypeIdent#>; value : <#ValueTypeIdent#> );
PROCEDURE [REMOVE] RemoveKeys ( VAR dict : <#TypeIdent#>; keys : ARGLIST OF <#KeyTypeIdent#> );
PROCEDURE [COUNT] count ( CONST dict : <#TypeIdent#> ) : LONGCARD;
(* Use of COPY and FOR statements are supported by bindings to FIRST, LAST, PREV and NEXT *)
PROCEDURE [FIRST] firstKey ( CONST dict : <#TypeIdent#> ) : <#KeyTypeIdent#>;
PROCEDURE [LAST] lastKey ( CONST dict : <#TypeIdent#> ) : <#KeyTypeIdent#>;
PROCEDURE [PREV] prevKey ( CONST dict : <#TypeIdent#>; key : <#KeyTypeIdent#> ) : <#KeyTypeIdent#>;
PROCEDURE [NEXT] nextKey ( CONST dict : <#TypeIdent#>; key : <#KeyTypeIdent#> ) : <#KeyTypeIdent#>;
END <#TypeIdent#>.

Replace <#TypeIdent#> with desired name, <#KeyTypeIdent#> with key type and <#ValueTypeIdent#> with value type.

Math

CardinalMath, LongCardMath

Template* for CARDINAL and LONGCARD math libraries CardinalMath and LongCardMath.

INTERFACE MODULE <#TitlecasedTypeIdent#>Math;
PROCEDURE power ( n, exponent : <#TypeIdent#> ) : <#TypeIdent#>; (* n to the power of exponent *)
PROCEDURE digitCount ( n : <#TypeIdent#> ) : CARDINAL; (* number of digits of n in decimal notation *)
END <#TitlecasedTypeIdent#>Math.

IntegerMath, LongIntMath

Template* for INTEGER and LONGINT math libraries IntegerMath and LongIntMath.

INTERFACE MODULE <#TitlecasedTypeIdent#>Math;
PROCEDURE fdiv ( a, n : <#TypeIdent#> ) : <#TypeIdent#>; (* floored integer division *)
PROCEDURE fmod ( a, n : <#TypeIdent#> ) : <#TypeIdent#>; (* modulus of floored integer division *)
PROCEDURE tdiv ( a, n : <#TypeIdent#> ) : <#TypeIdent#>; (* truncated integer division *)
PROCEDURE tmod ( a, n : <#TypeIdent#> ) : <#TypeIdent#>; (* modulus of truncated integer division *)
PROCEDURE power ( i, exponent : <#TypeIdent#> ) : <#TypeIdent#>; (* i to the power of exponent *)
PROCEDURE digitCount ( i : <#TypeIdent#> ) : CARDINAL; (* number of digits of i in decimal notation *)
END <#TitlecasedTypeIdent#>Math.

RealMath, LongRealMath

Template* for REAL and LONGREAL math libraries RealMath and LongRealMath.

INTERFACE MODULE <#TitlecasedTypeIdent#>Math;
CONST
  e = 2.7182818284590452353602874713526;
  pi = 3.1415926535897932384626433832795;
  phi = 1.6180339887498948482045868343656;
  tau = 6.2831853071795864769252867665590;
PROCEDURE frac ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* fractional part of r*)
PROCEDURE ceil ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* ⌈r⌉ *)
PROCEDURE floor ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* ⌊r⌋ *)
PROCEDURE trunc ( r : <#TypeIdent#>; n : CARDINAL ) : <#TypeIdent#>; (* truncation of r to n places *)
PROCEDURE round ( r : <#TypeIdent#>; n : CARDINAL ) : <#TypeIdent#>; (* rounding of r to n places *)
PROCEDURE inv ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* multiplicative inverse of r *)
PROCEDURE power ( r, exponent : <#TypeIdent#> ) : <#TypeIdent#>; (* r to the power of exponent *)
PROCEDURE sqrt ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* square root of r *)
PROCEDURE ln ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* natural logarithm of r *)
PROCEDURE log ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* base−10 logarithm of r *)
PROCEDURE sin ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* sine of r *)
PROCEDURE cos ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* cosine of r *)
PROCEDURE tan ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* tangent of r *)
PROCEDURE arcsin ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* arcsine of r *)
PROCEDURE arccos ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* arccosine of r *)
PROCEDURE arctan ( r : <#TypeIdent#> ) : <#TypeIdent#>; (* arctangent of r *)
END <#TitlecasedTypeIdent#>Math.

[*] Replace <#TypeIdent#> with type identifier and <#TitlecasedTypeIdent#> with titlecase transformed type identifier.

Memory Allocation

The storage library binds allocation and deallocation procedures to primitives @ALLOC and @DEALLOC.

Storage

INTERFACE MODULE Storage;
(* Allocates memory block of <size> octets and passes its address back in p. *)
PROCEDURE [ALLOC] Allocate ( VAR p : CAST ADDRESS; size : LONGCARD );
(* Deallocates memory block pointed to by p and passes NIL back in p. *)
PROCEDURE [DEALLOC] Deallocate ( VAR p : CAST ADDRESS );
END Storage.

Regular Expressions

Grammar

/* non-terminals */
regex := term+ ( ’|’ term+ )* ;
term := factor ( ’*’ /* 0..n */ | ’+’ /* 1..n */ | ’?’ /* 0..1 */ | arbitraryQuantifier )? ;
arbitraryQuantifier := ’{’ Digit+ ( ’,’ Digit+ )? ’}/* exact occurrences or min..max occurrences */
factor := ( ’~’ /* inverse match */ | ’{aA}/* case insensitive match */ )? simpleFactor ;
simpleFactor := literal | Synonym | ’[’ range ( ’,’ range )* ’]’ | ’(’ regex ’)’ ;
literal := Digit | Letter | RePrintable | CodePointOrRange ;
range := ( Digit ’-’ Digit ) | ( LowerLetter ’-’ LowerLetter ) | ( UpperLetter ’-’ UpperLetter ) ;
/* terminals */
Synonym := ’{start}’ | ’{end}’ | ’{nul}’ | ’{sp}’ | ’{tab}’ | ’{ws}’ | ’{nl}’ | ’{ret}’ | ’{bar}’ |
  ’{tilde}’ | ’{qm}’ | ’{plus}’ | ’{ast}’ | ’{lparen}’ | ’{rparen}’ | ’{lbrack}’ | ’{rbrack}’ |
  ’{lbrace}’ | ’{rbrace}’ |’{q}’ | ’{qq}’ | ’{sign}’ |’{binary}’ | ’{lowerbool}’ | ’{upperbool}’ |
  ’{bool}’ | ’{digit}’ | ’{lowerhex}’ | ’{upperhex}’ | ’{hex}’ | ’{lower}’ | ’{upper}’ | ’{alpha}’ |
  ’{alnum}’ | ’{control}’ | ’{printable}’ | ’{nonalnum}’ | ’{int}’ | ’{real}’ | ’{escseq}’ |
  ’{word}’ | ’{allcaps}’ | ’{ident}’ | ’{camelident}’ | ’{titleident}’ | ’{allcapsident}’ ;
RePrintable := ASCII(0x22..0x27) | ’,’ | ASCII(0x2E..0x3E) | ASCII(0x40..0x5A) | ’\’ | ASCII(0x5E..0x7A) ;
CodePointOrRange := ’{#’ ( Digit | ’A’ .. ’F’ )+ ( ’-’ ( Digit | ’A’ .. ’F’ )+ )? ’}’ ;
Digit := ’0’ .. ’9’ ;
LowerLetter := ’a’ .. ’z’ ;
UpperLetter := ’A’ .. ’Z’ ;
Letter := ’a’ .. ’z’ | ’A’ .. ’Z’ ;
/* verbatim whitespace and control characters are ignored */

Regex

INTERFACE MODULE Regex;
IMPORT CharRE+, UnicharRE+;
END Regex.

CharRE, UnicharRE

INTERFACE MODULE <#TitlecasedCharTypeIdent#>RE;
PROCEDURE matches ( CONST str, re : ARRAY OF <#CharTypeIdent#> ) : BOOLEAN;
END <#TitlecasedCharTypeIdent#>RE.

Replace <#CharTypeIdent#> with CHAR / UNICHAR and <#TitlecasedCharTypeIdent#> with Char / Unichar.

StringRE, UniStringRE

INTERFACE MODULE <#StringTypeIdent#>RE;
IMPORT <#StringTypeIdent#>;
PROCEDURE matches ( CONST str : String; CONST re : ARRAY OF <#CharTypeIdent#> ) : BOOLEAN;
END <#StringTypeIdent#>RE.

Replace <#CharTypeIdent#> with CHAR / UNICHAR and <#StringTypeIdent#> with String / UniString.

CharRegexNFA, UnicharRegexNFA

INTERFACE MODULE <#TitlecasedCharTypeIdent#>RegexNFA;
IMPORT RegexStatus, RegexStatusCode, RegexNotification;
TYPE <#TitlecasedCharTypeIdent#>RegexNFA : OPAQUE POINTER;
  NotificationHandler = PROCEDURE ( VAR (*notifiedEvent:*) RegexNotification;
    VAR (*char:*) <#CharTypeIdent#>; VAR (*index:*) LONGCARD; VAR (*stateCount:*) CARDINAL );
PROCEDURE [NEW] New ( VAR nfa : <#TitlecasedCharTypeIdent#>RegexNFA );
PROCEDURE [RETAIN] Retain ( nfa : <#TitlecasedCharTypeIdent#>RegexNFA );
PROCEDURE [RELEASE] Release ( VAR nfa : <#TitlecasedCharTypeIdent#>RegexNFA );
PROCEDURE installHandler ( nfa : <#TitlecasedCharTypeIdent#>RegexNFA; handler : NotificationHandler );
PROCEDURE matches
  ( nfa : <#TitlecasedCharTypeIdent#>RegexNFA; CONST str : ARRAY OF <#CharTypeIdent#> ) : BOOLEAN;
PROCEDURE status ( nfa : <#TitlecasedCharTypeIdent#>RegexNFA ) : RegexStatus;
END <#TitlecasedCharTypeIdent#>RegexNFA.

Replace <#CharTypeIdent#> with CHAR / UNICHAR, and <#TitlecasedCharTypeIdent#> with Char / Unichar.

RegexNotification

INTERFACE MODULE RegexNotification;
TYPE RegexNotification = ( SizeInfo, NoMatchInfo, IllegalChar, UnknownSynonym, AllocFailed );
END RegexNotification.

RegexStatus

INTERFACE MODULE RegexStatus;
IMPORT Status, RegexStatusCode;
TYPE RegexStatus = RECORD ( Status )
  code : RegexStatusCode
END;
END RegexStatus.

RegexStatusCode

INTERFACE MODULE RegexStatusCode;
IMPORT StatusCode;
TYPE RegexStatusCode =
  ( +StatusCode, InvalidExpr, InvalidStr, InvalidNFA, StackFull, AllocFailed );
END RegexStatusCode.

Hashing

Hash32, UniHash32

INTERFACE MODULE <#LibIdent#>;
CONST KeyBits = 32;
TYPE Key = OPAQUE [KeyBits DIV 8];
(* functions for incremental hashing *)
PROCEDURE initialValue : Key;
PROCEDURE valueForNextChar ( hash : Key; ch : <#CharTypeIdent#> ) : Key;
PROCEDURE finalValue ( hash : Key ) : Key;
(* functions for en−bloc string hashing *)
PROCEDURE valueForArray ( CONST str : ARRAY OF <#CharTypeIdent#> ) : Key;
PROCEDURE valueForSlice ( CONST str : ARRAY OF <#CharTypeIdent#>; startIndex, endIndex : LONGCARD ) : Key;
END <#LibIdent#>.

Replace <#LibIdent#> with Hash32 / UniHash32 and <#CharTypeIdent#> with CHAR / UNICHAR.

Hash64, UniHash64

INTERFACE MODULE <#LibIdent#>;
CONST KeyBits = 64;
TYPE Key = OPAQUE [KeyBits DIV 8];
(* functions for incremental hashing *)
PROCEDURE initialValue : Key;
PROCEDURE valueForNextChar ( hash : Key; ch : <#CharTypeIdent#> ) : Key;
PROCEDURE finalValue ( hash : Key ) : Key;
(* functions for en−bloc string hashing *)
PROCEDURE valueForArray ( CONST str : ARRAY OF <#CharTypeIdent#> ) : Key;
PROCEDURE valueForSlice ( CONST str : ARRAY OF <#CharTypeIdent#>; startIndex, endIndex : LONGCARD ) : Key;
END <#LibIdent#>.

Replace <#LibIdent#> with Hash64 / UniHash64 and <#CharTypeIdent#> with CHAR / UNICHAR.

Filesystem

Filesys

INTERFACE MODULE Filesys;
IMPORT DateTime, IOSize, FilesysStatus, FilesysStatusCode;
TYPE Status = ALIAS OF FilesysStatus; TYPE StatusCode = ALIAS OF FilesysStatusCode;
TYPE Attribute = ( Readable, Writable, Executable, Directory, Other );
TYPE AttrSet = SET OF Attribute;
CONST RO = { Attribute.Readable }; WO = { Attribute.Writable }; EO = { Attribute.Executable };
RW = { Attribute.Readable, Attribute.Writable }; RWE = RW + { Attribute.Executable };
PROCEDURE maxFilenameLength : LONGCARD;
PROCEDURE maxPathnameLength : LONGCARD;
PROCEDURE isFile ( CONST atPath : ARRAY OF CHAR; VAR status : Status ) : BOOLEAN;
PROCEDURE isDirectory ( CONST atPath : ARRAY OF CHAR; VAR status : Status ) : BOOLEAN;
PROCEDURE entryExists ( CONST atPath : ARRAY OF CHAR; VAR status : Status ) : BOOLEAN;
PROCEDURE attrSet ( CONST atPath : ARRAY OF CHAR; VAR status : Status ) : AttrSet;
PROCEDURE SetAttr ( CONST atPath : ARRAY OF CHAR; attr : AttrSet; VAR status : Status );
PROCEDURE GetFileSize ( CONST atPath : ARRAY OF CHAR; VAR size : IOSize; VAR status : Status );
PROCEDURE GetTimeCreated ( CONST atPath : ARRAY OF CHAR; VAR timestamp : DateTime; VAR status : Status );
PROCEDURE GetTimeModified ( CONST atPath : ARRAY OF CHAR; VAR timestamp : DateTime; VAR status : Status );
PROCEDURE CreateEntry ( CONST atPath : ARRAY OF CHAR; attr : AttrSet; VAR status : Status );
PROCEDURE RenameEntry ( CONST atPath, newFilename : ARRAY OF CHAR; VAR status : Status );
PROCEDURE MoveEntry ( CONST fromPath, toPath : ARRAY OF CHAR; VAR status : Status );
PROCEDURE RemoveEntry ( CONST atPath : ARRAY OF CHAR; VAR status : Status );
END Filesys.

FilesysStatus

INTERFACE MODULE FilesysStatus;
IMPORT Status;
TYPE FilesysStatus = RECORD ( Status )
  code : FilesysStatusCode
END;
END FilesysStatus.

FilesysStatusCode

INTERFACE MODULE FilesysStatusCode;
IMPORT StatusCode;
TYPE FilesysStatusCode =
  ( +StatusCode, (* inherits Success and Failure *)
    AlreadyExists,
    InvalidPath,
    PathNotFound,
    PathTooLong,
    InvalidName,
    NameTooLong,
    InvalidAttr,
    AccessDenied,
    SizeOverflow,
    DeviceError );
END FilesysStatusCode.

Runtime System Interface

RTS

INTERFACE MODULE RTS;
TYPE Fault = ( DivByZero, DerefNil, NotRefCounted, InvalidAccessor, TypeOverflow,
  IndexOutOfBounds, CapacityExceeded, StackOverflow, OutOfMemory, LibAbort, UserAbort );
TYPE NotificationHandler = PROCEDURE ( VAR (*PC*) UNSAFE.ADDRESS; VAR (*SP*) UNSAFE.ADDRESS );
(* Callback procedure type for runtime fault notification handlers, passing back two addresses:
   PC = program counter at which the fault event occurred.
   SP = stack pointer at which the fault event occurred. *)
PROCEDURE RaiseFault ( fault : Fault );
(* Raises runtime fault and causes program abort, never returns. *)
PROCEDURE InstallNotificationHandler ( forFault : Fault; handler : NotificationHandler );
(* Installs the given notification handler for the specified runtime fault. *)
PROCEDURE InstallInitHasFinishedHandler ( handler : PROCEDURE );
(* Installs given procedure as the program’s post−initialisation handler. *)
PROCEDURE InstallWillTerminateHandler ( handler : PROCEDURE );
(* Installs given procedure as the program’s pre−termination handler. *)
END RTS.

Host OS Interface

System

INTERFACE MODULE System;
IMPORT Newline, DateTime;
CONST MaxOSNameLength = 65; (* POSIX.1−2001 *)
  MaxHostnameLength = 255; (* RFC 1123 *)
  CountryCodeLength = 2; (* ISO 3166−1 alpha−2 *)
  LanguageCodeLength = 2; (* ISO 639−1 *)
  CurrencyCodeLength = 3; (* ISO 4217 *)
PROCEDURE GetOSName ( VAR str : ARRAY OF CHAR );
PROCEDURE GetHostname ( VAR str : ARRAY OF CHAR );
PROCEDURE GetVersion ( VAR major, minor, subminor : CARDINAL );
PROCEDURE newlineMode : Newline.Mode; (* platform dependent default *)
PROCEDURE GetDateTime ( VAR timestamp : DateTime; VAR tzOffs : DateTime.TZOffset );
PROCEDURE GetSysLocale
  ( VAR tzOffset : DateTime.TZOffset; VAR decimalSep : CHAR;
    VAR countryCode, langCode, currencyCode : ARRAY OF CHAR );
END System.

OSUsrEnv

INTERFACE MODULE OSUsrEnv;
IMPORT DateTime;
PROCEDURE GetCWD ( VAR dirStr : ARRAY OF CHAR ); (* get current working directory *)
PROCEDURE SetCWD ( CONST dirStr : ARRAY OF CHAR ); (* set current working directory *)
PROCEDURE GetUsrLocale
  ( VAR tzOffset : DateTime.TZOffset; VAR decimalSep : CHAR;
    VAR countryCode, langCode, currencyCode : ARRAY OF CHAR );
PROCEDURE SetUsrLocaleTZ ( tzOffs : DateTime.TZOffset; VAR succeeded : BOOLEAN );
PROCEDURE SetUsrLocaleDecSep ( decimalSep : CHAR; VAR succeeded : BOOLEAN ); (* "," or "." *)
PROCEDURE SetUsrLocaleCountry ( CONST countryCode : ARRAY OF CHAR; VAR succeeded : BOOLEAN );
PROCEDURE SetUsrLocaleLanguage ( CONST langCode : ARRAY OF CHAR; VAR succeeded : BOOLEAN );
PROCEDURE SetUsrLocaleCurrency ( CONST currencyCode : ARRAY OF CHAR; VAR succeeded : BOOLEAN );
END OSUsrEnv.

Date and Time

DateTime

INTERFACE MODULE DateTime; IMPORT INTEGER32;
CONST
  OneYear = { 1, 0, 0, 0, 0, 0, 0, 0 };
  OneMonth = { 0, 1, 0, 0, 0, 0, 0, 0 };
  OneDay = { 0, 0, 1, 0, 0, 0, 0, 0 };
  OneHour = { 0, 0, 0, 1, 0, 0, 0, 0 };
  OneMin = { 0, 0, 0, 0, 1, 0, 0, 0 };
TYPE DateTime = RECORD year : Year;
  month : Month;
  day : Day;
  hour : Hour;
  min : Minute;
  sec : Second;
  msec : MilliSecond;
  tzOffs : TimeZoneOffset
END; (* DateTime *)
  Year = ALIAS OF INTEGER32;
  Month = [0..12] OF INTEGER32;
  Day = [0..31] OF INTEGER32;
  Hour = [0..23] OF INTEGER32;
  Minute = [0..59] OF INTEGER32;
  Second = [0..59] OF INTEGER32;
  MilliSecond = [0..999] OF INTEGER32;
  TimeZoneOffset = [-720..720] (*minutes*) OF INTEGER32;
  TZOffset = ALIAS OF TimeZoneOffset;
PROCEDURE isValidAbsoluteDate ( CONST time : DateTime ) : BOOLEAN; (* year, month, day > 0 *)
PROCEDURE isEarlier ( CONST t1, t2 : DateTime ) : BOOLEAN; (* t1 < t2 *)
PROCEDURE sum ( CONST t1, t2 : DateTime ) : DateTime; (* t1 + t2 *)
PROCEDURE diff ( CONST t1, t2 : DateTime ) : DateTime; (* t1 − t2 *)
PROCEDURE toDays ( CONST time : DateTime ) : INTEGER32; (* time −−> days *)
PROCEDURE scalarDelta ( CONST time : DateTime; deltaDays : INTEGER32 ) : DateTime; (* time +/− days *)
PROCEDURE scalarProduct ( CONST time : DateTime; factor : INTEGER32 ) : DateTime; (* time * factor *)
PROCEDURE scalarQuotient ( CONST time : DateTime; divisor : INTEGER32 ) : DateTime; (* time / divisor *)
END DateTime.

DateTimeIO

INTERFACE MODULE DateTimeIO;
IMPORT DateTime, IOChannel;
PROCEDURE [WRITE] Write ( chan : IOChannel; value : DateTime );
PROCEDURE [WRITE#] Write ( chan : IOChannel; CONST fmtStr : ARRAY OF CHAR; value : DateTime );
END DateTimeIO.

Whole Number Types with Fixed Bitwidth

Implementations targeting multiple architectures may require target-specific versions of the library.

CARDINAL32

INTERFACE MODULE CARDINAL32;
TYPE CARDINAL32 = ALIAS OF <#32BitCardinal#>;
END CARDINAL32.

INTEGER32

INTERFACE MODULE INTEGER32;
TYPE INTEGER32 = ALIAS OF <#32BitInteger#>;
END INTEGER32.

For targets

  • where TSIZE(CARDINAL)=32, replace <#32BitCardinal#> with CARDINAL and <#32BitInteger#> with INTEGER
  • where TSIZE(LONGCARD)=32, replace <#32BitCardinal#> with LONGCARD and <#32BitInteger#> with LONGINT
Clone this wiki locally