Basics.mesa
last edited by Levin on August 8, 1983 10:30 am
DIRECTORY
PrincOps USING [
zAND, zDCOMP, zDIV, zDUCOMP, zINC, zLDIV, zLIN1, zMUL, zOR, zPUSH, zSHIFT, zXOR];
Basics: CEDAR DEFINITIONS =
BEGIN
OPEN PrincOps;
Commonly-used types and values
bytesPerWord, charsPerWord: NAT = 2;
bitsPerByte, bitsPerChar: NAT = 8;
bitsPerWord: NAT = bitsPerByte*bytesPerWord;
logBitsPerByte, logBitsPerChar: NAT = --LogBase2[bitsPerByte]--3;
logBytesPerWord, logCharsPerWord: NAT = --LogBase2[bytesPerWord]--1;
logBitsPerWord: NAT = logBitsPerByte + logBytesPerWord;
Byte, BYTE: TYPE = [0..377B];
Word: TYPE = WORD;
LongNumber: TYPE = MACHINE DEPENDENT RECORD [
SELECT OVERLAID * FROM
lc => [lc: LONG CARDINAL],
li => [li: INT],
num => [lowbits, highbits: CARDINAL],
bytes => [lh, ll, hh, hl: BYTE],
ENDCASE];
BytePair: TYPE = MACHINE DEPENDENT RECORD [high, low: BYTE];
Comparison: TYPE = MACHINE DEPENDENT {less(0), equal(1), greater(2)};
RefSeq: TYPE = RECORD [n: NAT, seq: SEQUENCE length: NAT OF REF ANY];
RawMemory: TYPE = RECORD [SEQUENCE COMPUTED CARDINAL OF WORD];
UnsafeBlock: TYPE = RECORD [base: LONG POINTERNIL, startIndex: INT ← 0, count: INT ← 0];
Arithmetic utilities
CompareLC, CompareCard: PROC [a, b: LONG CARDINAL] RETURNS [Comparison] =
TRUSTED MACHINE CODE {zDUCOMP; zINC};
CompareINT: PROC [a, b: INT] RETURNS [Comparison] = TRUSTED MACHINE CODE
{zDCOMP; zINC};
DIVMOD: PROC [num, den: CARDINAL] RETURNS [quotient, remainder: CARDINAL] =
TRUSTED MACHINE CODE {zDIV; zPUSH};
LDIVMOD: PROC [numlow: WORD, numhigh: CARDINAL, den: CARDINAL]
RETURNS [quotient, remainder: CARDINAL] = TRUSTED MACHINE CODE {zLDIV; zPUSH};
LongMult: PROC [CARDINAL, CARDINAL] RETURNS [product: LONG CARDINAL] =
TRUSTED MACHINE CODE {zMUL; zPUSH};
LongDiv: PROC [num: LONG CARDINAL, den: CARDINAL] RETURNS [CARDINAL] =
TRUSTED MACHINE CODE {zLDIV};
LongDivMod: PROC [num: LONG CARDINAL, den: CARDINAL]
RETURNS [quotient, remainder: CARDINAL] = TRUSTED MACHINE CODE {zLDIV; zPUSH};
Logic utilities
BitOp: TYPE = SAFE PROC [CARDINAL, CARDINAL] RETURNS [CARDINAL];
BITAND: BitOp =
TRUSTED MACHINE CODE {zAND};
BITOR: BitOp =
TRUSTED MACHINE CODE {zOR};
BITXOR: BitOp =
TRUSTED MACHINE CODE {zXOR};
BITNOT: SAFE PROC [CARDINAL] RETURNS [CARDINAL] =
TRUSTED MACHINE CODE {zLIN1; zXOR};
BITSHIFT: SAFE PROC [value: CARDINAL, count: INTEGER] RETURNS [CARDINAL] =
TRUSTED MACHINE CODE {zSHIFT};
Field Extraction
LowHalf: PROC [n: LONG CARDINAL] RETURNS [CARDINAL] = TRUSTED INLINE
{RETURN[LOOPHOLE[n, LongNumber].lowbits]};
HighHalf: PROC [n: LONG CARDINAL] RETURNS [CARDINAL] = TRUSTED INLINE
{RETURN[LOOPHOLE[n, LongNumber].highbits]};
LowByte: PROC [n: CARDINAL] RETURNS [CARDINAL] = TRUSTED INLINE
{RETURN[LOOPHOLE[n, BytePair].low]};
HighByte: PROC [n: CARDINAL] RETURNS [CARDINAL] = TRUSTED INLINE
{RETURN[LOOPHOLE[n, BytePair].high]};
END.