PascalBasic.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
last modified by Ramshaw, February 3, 1984 8:45 pm
written by McCreight, November 17, 1980 3:13 PM
Michael Plass, September 27, 1985 10:04:21 am PDT
The basics of Pascal runtime support in Cedar:
storage, arithmetic, date, time, stringcompare, and CommandProc stuff
DIRECTORY
Basics USING [LongNumber, LowHalf],
Commander USING [Handle, CommandProc],
IO USING [STREAM],
Real USING [RoundLI, Fix, Float],
RealFns USING [SinDeg, CosDeg, ArcTanDeg, Exp, Ln, SqRt],
Rope USING [ROPE];
PascalBasic: CEDAR DEFINITIONS IMPORTS Basics, Real, RealFns =
BEGIN
T Y P E S
PascalInteger: TYPE = LONG INTEGER;
The Alto version uses short integers instead, because of Alto compiler problems
PascalReal: TYPE = REAL;
PascalChar: TYPE = CHARACTER;
PascalBoolean: TYPE = BOOLEAN;
AlfaLength: PascalInteger = 10;
AlfaIndex: TYPE = [1..AlfaLength];
Alfa: TYPE = PACKED ARRAY AlfaIndex OF PascalChar;
The following types are for Pascal strings passed by VAR; the nonspecific
first version is for passing "strings" of any length to the runtime support routines.
CharArrayPtr: TYPE = LONG POINTER;
CharArrayConcretePtr: TYPE = LONG POINTER TO
PACKED ARRAY[1..1) OF PascalChar ← NIL;
CommandProc: TYPE = Commander.CommandProc;
UnsafeCommandProc: TYPE = UNSAFE PROC;
ROPE: TYPE = Rope.ROPE;
C O N S T A N T S
Maxint: PascalInteger = LAST[PascalInteger];
V A R I A B L E S
PascalStaticZone: UNCOUNTED ZONE; -- for static allocations
PascalZone: UNCOUNTED ZONE; -- for dynamic allocations
z: ZONE; -- for the runtime's own use
The Alto version also exports an MDSZone for short pointer allocations.
subsystemName: ROPE;
ProcRec: TYPE = RECORD [p: UnsafeCommandProc];
SubsystemProcRec: ProcRec;
ExclusiveProc: CommandProc;
commandLineTail: ROPE;
clientData: REF ANY;
ttyInputStream: IO.STREAM;
ttyOutputStream: IO.STREAM;
S I G N A L S
NumericInputError: SIGNAL;
PascalHalt: SIGNAL;
AttemptToDisposeInvalidPtr: SIGNAL;
P R O C E D U R E S Called by PasMesa
PascalRegister: PROCEDURE[name: ROPE, proc: UnsafeCommandProc];
PascalHALT: PROCEDURE = INLINE {SIGNAL PascalHalt};
longInt: PROCEDURE [x: INT] RETURNS [INT] = INLINE {RETURN[x]};
card: PROCEDURE [x: CARDINAL] RETURNS [CARDINAL] = INLINE {RETURN[x]};
nat: PROCEDURE [x: NAT] RETURNS [NAT] = INLINE {RETURN[x]};
shortInt: PROCEDURE [x: INTEGER] RETURNS [INTEGER] = INLINE {RETURN[x]};
PascalIntegerSQR: PROCEDURE [x: PascalInteger] RETURNS [PascalInteger] = INLINE
{RETURN[x*x]};
PascalRealSQR: PROCEDURE [x: PascalReal] RETURNS [PascalReal] = INLINE {
RETURN[x*x]};
PascalSIN: PROCEDURE [x: PascalReal] RETURNS [PascalReal] = INLINE {
RETURN[RealFns.SinDeg[x]]};
PascalCOS: PROCEDURE [x: PascalReal] RETURNS [PascalReal] = INLINE {
RETURN[RealFns.CosDeg[x]]};
PascalEXP: PROCEDURE [x: PascalReal] RETURNS [PascalReal] = INLINE {
RETURN[RealFns.Exp[x]]};
PascalLN: PROCEDURE [x: PascalReal] RETURNS [PascalReal] = INLINE {
RETURN[RealFns.Ln[x]]};
PascalSQRT: PROCEDURE [x: PascalReal] RETURNS [PascalReal] = INLINE {
RETURN[RealFns.SqRt[x]]};
PascalARCTAN: PROCEDURE [x: PascalReal] RETURNS [PascalReal] = INLINE {
RETURN[RealFns.ArcTanDeg[y: x, x: 1.0]]};
PascalROUND: PROCEDURE [x: PascalReal] RETURNS [PascalInteger] = Real.RoundLI;
PascalTRUNC: PROCEDURE [x: PascalReal] RETURNS [PascalInteger] = Real.Fix;
PascalFLOAT: PROCEDURE [x: PascalInteger] RETURNS [PascalReal] = Real.Float;
PascalMULPower2: PROC [i: INT, lg: NAT] RETURNS [INT];
PascalDIVPower2: PROC [i: INT, lg: NAT] RETURNS [INT];
PascalMODPower2Mask: PROC [i: INT, mask: --nonneg-- INT] RETURNS [INT];
PascalODD: PROCEDURE [x: PascalInteger] RETURNS [PascalBoolean] = INLINE {
t: Basics.LongNumber = [li[x]];
RETURN[(t.lo MOD 2) # 0]};
PascalORD: PROCEDURE [x: LONG UNSPECIFIED] RETURNS [PascalInteger] = INLINE {
RETURN[LOOPHOLE[x, PascalInteger]]};
PascalCHR: PROCEDURE [x: PascalInteger] RETURNS [PascalChar] = INLINE {
RETURN[LOOPHOLE[Basics.LowHalf[LOOPHOLE[x, LONG CARDINAL]], PascalChar]]};
PascalDATE: PROCEDURE [a: LONG POINTER TO Alfa];
PascalTIME: PROCEDURE [a: LONG POINTER TO Alfa];
PascalReadClock: PROCEDURE RETURNS [PascalInteger];
Warning! The Alto version of this interface defins PascalReadClock to return
a PascalReal instead, since 16 bits isn't enough precision for runtimes in
milliseconds.
PascalStringCompare, PascalLongStringCompare: PROCEDURE [
aa: CharArrayPtr ← NIL, aLen: PascalInteger ← 0, as: ROPENIL,
ba: CharArrayPtr ← NIL, bLen: PascalInteger ← 0, bs: ROPENIL]
RETURNS [[-1..1]];
a and b are either ROPE's (generated as literals) or
LONG POINTERs to packed arrays [1..Len) of
characters, depending on which arguments are NIL.
The result is -1 if a<b, 0 if a=b, and 1 if a>b.
END. -- PascalBasic