C2CRunTimeImpl.mesa
Copyright Ó 1987, 1988, 1989, 1990, 1991 by Xerox Corporation. All rights reserved.
Christian Jacobi, March 10, 1988 2:17:57 pm PST
Christian Jacobi, October 5, 1990 11:17:53 am PDT
Willie-s, September 24, 1991 6:14 pm PDT
DIRECTORY
C2CAddressing,
C2CBasics,
C2CCodeUtils,
C2CDefs,
C2CEmit,
C2CNames,
C2CTarget,
C2CRunTime,
Convert,
ConvertUnsafe,
Rope;
C2CRunTimeImpl: CEDAR PROGRAM
IMPORTS Convert, C2CBasics, C2CCodeUtils, C2CEmit, C2CTarget, C2CNames, ConvertUnsafe, Rope
EXPORTS C2CRunTime =
BEGIN
Code: TYPE = C2CDefs.Code;
ROPE: TYPE = Rope.ROPE;
AddressContainer: TYPE = C2CAddressing.AddressContainer;
install: PUBLIC Rope.ROPE ¬ Rope.Concat[C2CTarget.runtimePrefix, "install"];
CodeOrRope: TYPE = REF;
Utilities
ToBits: PROC [c: REF] RETURNS [REF] = INLINE {
IF c=NIL THEN c ¬ " 0";
RETURN [c];
};
MyCat: PROC [key: LONG STRING, p1, p2, p3, p4, p5, p6: CodeOrRope¬NIL] RETURNS [Code] = {
--key logically of type ROPE, but LONG STRING results in better code (higher optimization level possible) Jim Foote found that one out; WOW
r: Code ¬ C2CEmit.Cat[p1];
IF p2#NIL THEN {
r ¬ C2CEmit.Cat[r, ", ", p2];
IF p3#NIL THEN {
r ¬ C2CEmit.Cat[r, ", ", p3];
IF p4#NIL THEN {
r ¬ C2CEmit.Cat[r, ", ", p4];
IF p5#NIL THEN {
r ¬ C2CEmit.Cat[r, ", ", p5];
IF p6#NIL THEN r ¬ C2CEmit.Cat[r, ", ", p6];
}
}
}
};
RETURN [C2CEmit.Cat[C2CTarget.runtimePrefix, ConvertUnsafe.ToRope[key], C2CEmit.Parentize[r]]];
};
SingleCat: PROC [key: CodeOrRope] RETURNS [Code] = {
RETURN [C2CEmit.Cat[C2CTarget.runtimePrefix, key]];
};
Call: PROC [c: Code] RETURNS [Code] = INLINE {
RETURN [C2CEmit.SetPrecedence[c, primaryPrecedence]]
};
Basics
MoveWords: PUBLIC PROC [dst, src: Code, nWords: INT] RETURNS [Code] = {
IF nWords<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["MoveWords", dst, src, Convert.RopeFromInt[nWords]]];
};
MoveWordsDisjoint: PUBLIC PROC [dst, src: Code, nWords: INT] RETURNS [Code] = {
IF nWords<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["MoveWordsDisjoint", dst, src, Convert.RopeFromInt[nWords]]];
};
EqualWords: PUBLIC PROC [x, y: Code, nWords: INT] RETURNS [Code] = {
IF nWords<1 THEN C2CBasics.CantHappen;
RETURN [Call[MyCat["EqualWords", x, y, Convert.RopeFromInt[nWords]]]];
};
MoveBytesDisjoint: PUBLIC PROC [dst, src: Code, nBytes: INT] RETURNS [Code] = {
IF nBytes<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["MoveBytesDisjoint", dst, src, Convert.RopeFromInt[nBytes]]];
};
ExtractField: PUBLIC PROC [src: AddressContainer, bits: INT] RETURNS [Code] = {
IF bits<1 THEN C2CBasics.CantHappen;
RETURN [Call[MyCat["ExtractField", src.words, ToBits[src.bits], Convert.RopeFromInt[bits]]]];
};
DepositField: PUBLIC PROC [dst: AddressContainer, bits: INT, word: Code] RETURNS [Code] = {
IF bits<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["DepositField", dst.words, ToBits[dst.bits], Convert.RopeFromInt[bits], word]];
};
MoveField: PUBLIC PROC [dst, src: AddressContainer, bits: INT] RETURNS [Code] = {
IF bits<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["MoveField", dst.words, ToBits[dst.bits], src.words, ToBits[src.bits], Convert.RopeFromInt[bits]]];
};
EqualFields: PUBLIC PROC [x, y: AddressContainer, bits: INT] RETURNS [Code] = {
IF bits<1 THEN C2CBasics.CantHappen;
RETURN [Call[MyCat["EqualFields", x.words, ToBits[x.bits], y.words, ToBits[y.bits], Convert.RopeFromInt[bits]]]];
};
FillFields: PUBLIC PROC [dst: AddressContainer, bits: INT, times: INT, value: Code] RETURNS [Code] = {
IF bits<1 THEN C2CBasics.CantHappen;
IF times<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["FillFields", dst.words, ToBits[dst.bits], Convert.RopeFromInt[bits], Convert.RopeFromInt[times], value]];
};
FillWords: PUBLIC PROC [dst: Code, times: INT, value: Code] RETURNS [Code] = {
IF times<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["FillWords", dst, Convert.RopeFromInt[times], value]];
};
FillLongFields: PUBLIC PROC [dst, src: AddressContainer, bits: INT, times: INT] RETURNS [Code] = {
IF bits<1 THEN C2CBasics.CantHappen;
IF times<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["FillLongFields", dst.words, ToBits[dst.bits], src.words, ToBits[src.bits], Convert.RopeFromInt[bits], Convert.RopeFromInt[times]]];
};
FillLongWords: PUBLIC PROC [dst, src: Code, times: INT, nWords: NAT] RETURNS [Code] = {
IF nWords<1 THEN C2CBasics.CantHappen;
IF times<1 THEN C2CBasics.CantHappen;
RETURN [MyCat["FillLongWords", dst, src, Convert.RopeFromInt[nWords], Convert.RopeFromInt[times]]];
};
32 bit precision Signed
SignedPwr: PUBLIC PROC [base, exp: Code] RETURNS [Code] = {
RETURN [Call[MyCat["SignedPwr", base, exp]]];
};
32 bit precision Unsigned
UnsignedPwr: PUBLIC PROC [base, exp: Code] RETURNS [Code] = {
RETURN [Call[MyCat["UnsignedPwr", base, exp]]];
};
32 bit precision Floating point
FloatInt: PUBLIC PROC [i: Code] RETURNS [Code] = {
RETURN [Call[MyCat["FloatInt", i]]];
};
FloatCard: PUBLIC PROC [i: Code] RETURNS [Code] = {
RETURN [Call[MyCat["FloatCard", i]]];
};
RealNeg: PUBLIC PROC [f: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealNeg", f]]];
};
RealAbs: PUBLIC PROC [f: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealAbs", f]]];
};
RealAdd: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealAdd", a, b]]];
};
RealSub: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealSub", a, b]]];
};
RealMul: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealMul", a, b]]];
};
RealDiv: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealDiv", a, b]]];
};
RealMin: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealMin", a, b]]];
};
RealMax: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealMax", a, b]]];
};
RealPwr: PUBLIC PROC [base, exp: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealPwr", base, exp]]];
};
RealGt: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealGt", a, b]]];
};
RealGe: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealGe", a, b]]];
};
RealEq: PUBLIC PROC [a, b: Code] RETURNS [Code] = {
RETURN [Call[MyCat["RealEq", a, b]]];
};
Mesa
hasInstKey: REF INT ¬ NEW[INT];
IncludeInstallationSupport: PUBLIC PROC [] = {
IF C2CBasics.GetProp[hasInstKey] = NIL THEN {
C2CEmit.AppendCode[moduleHeader, C2CEmit.Cat["#include <cedar/InstallationSupport.h>\n"]];
C2CBasics.PutProp[hasInstKey, $yes]
};
};
hasCedKey: REF INT ¬ NEW[INT];
IncludeCedarExtra: PUBLIC PROC [] = {
IF C2CBasics.GetProp[hasCedKey] = NIL THEN {
C2CEmit.AppendCode[moduleHeader, C2CEmit.Cat["#include <cedar/CedarExtra.h>\n"]];
C2CBasics.PutProp[hasCedKey, $yes]
};
};
RaiseBoundsFault: PUBLIC PROC [] RETURNS [Code] = {
RETURN [SingleCat["RaiseBoundsFault()"]];
};
RaiseAbstractionFault: PUBLIC PROC [] RETURNS [Code] = {
RETURN [SingleCat["RaiseAbstractionFault()"]];
};
RaiseArithmeticFault: PUBLIC PROC [] RETURNS [Code] = {
RETURN [Call[SingleCat["RaiseArithmeticFault()"]]];
};
RaiseUnnamedError: PUBLIC PROC [] RETURNS [Code] = {
RETURN [Call[SingleCat["RaiseUnnamedError()"]]];
};
CatPrefix: PROC [r: ROPE] RETURNS [ROPE] = {
RETURN [Rope.Concat[C2CTarget.runtimePrefix, r]]
};
nakedBoundsError: PUBLIC ROPE ¬ CatPrefix["BoundsFault"];
nakedUnnamedError: PUBLIC ROPE ¬ CatPrefix["UnnamedError"];
nakedUnwindError: PUBLIC ROPE ¬ CatPrefix["Unwind"];
nakedAbortedError: PUBLIC ROPE ¬ CatPrefix["Aborted"];
nakedUncaughtError: PUBLIC ROPE ¬ CatPrefix["Uncaught"];
nakedNarrowFault: PUBLIC ROPE ¬ CatPrefix["NarrowFault"];
PushHandler: PUBLIC PROC [context, handler: Code] RETURNS [Code] = {
RETURN [Call[MyCat["PushHandler", context, handler]]];
};
PopHandler: PUBLIC PROC [] RETURNS [Code] = {
RETURN [SingleCat["PopHandler()"]];
};
RaiseSignal: PUBLIC PROC [which, rtns, args: Code] RETURNS [Code] = {
RETURN [MyCat["RaiseSignal", which, rtns, args]];
};
RaiseError: PUBLIC PROC [which, args: Code] RETURNS [Code] = {
RETURN [MyCat["RaiseError", which, args]];
};
StartModule: PUBLIC PROC [retPtr, module, args: Code] RETURNS [Code] = {
RETURN [MyCat["StartModule", retPtr, module, args]];
};
ExtensionAlloc: PUBLIC PROC [sz: Code] RETURNS [Code] = {
RETURN [Call[MyCat["ExtensionAlloc", sz]]];
};
ExtensionFree: PUBLIC PROC [ptr: Code] RETURNS [Code] = {
RETURN [Call[MyCat["ExtensionFree", ptr]]];
};
Fork: PUBLIC PROC [processPtr, proc: Code] RETURNS [Code] = {
RETURN [MyCat["Fork", processPtr, proc]];
};
Join: PUBLIC PROC [process: Code] RETURNS [Code] = {
RETURN [Call[MyCat["Join", process]]];
};
Wait: PUBLIC PROC [cond, lock: Code] RETURNS [Code] = {
RETURN [MyCat["Wait", cond, lock]];
};
Notify: PUBLIC PROC [cond: Code] RETURNS [Code] = {
RETURN [MyCat["Notify", cond]];
};
Broadcast: PUBLIC PROC [cond: Code] RETURNS [Code] = {
RETURN [MyCat["Broadcast", cond]];
};
MonitorEntry: PUBLIC PROC [lock: Code] RETURNS [Code] = {
RETURN [MyCat["MonitorEntry", lock]];
};
MonitorExit: PUBLIC PROC [lock: Code] RETURNS [Code] = {
RETURN [MyCat["MonitorExit", lock]];
};
Cedar
AssignRef: PUBLIC PROC [dstPtr: Code, src: Code] RETURNS [Code] = {
RETURN [MyCat["AssignRef", dstPtr, src]]
};
AssignRefInit: PUBLIC PROC [dstPtr: Code, src: Code] RETURNS [Code] = {
RETURN [MyCat["AssignRefInit", dstPtr, src]]
};
AssignRefComposite: PUBLIC PROC [dst: Code, src: Code, type: Code, words: INT] RETURNS [Code] = {
sz: Code ¬ C2CCodeUtils.ConstC[words];
RETURN [MyCat["AssignRefComposite", dst, src, type, sz]];
};
AssignRefCompositeInit: PUBLIC PROC [dst: Code, src: Code, type: Code, words: INT] RETURNS [Code] = {
sz: Code ¬ C2CCodeUtils.ConstC[words];
RETURN [MyCat["AssignRefCompositeInit", dst, src, type, sz]];
};
NewObject: PUBLIC PROC [nWords: Code, type: Code] RETURNS [Code] = {
RETURN [Call[MyCat["NewObject", nWords, type]]];
};
Narrow: PUBLIC PROC [ref: Code, type: Code] RETURNS [Code] = {
RETURN [Call[MyCat["Narrow", ref, type]]];
};
GetReferentType: PUBLIC PROC [ref: Code] RETURNS [Code] = {
RETURN [Call[MyCat["GetReferentType", ref]]];
};
CheckProc: PUBLIC PROC [proc: Code] RETURNS [Code] = {
RETURN [Call[MyCat["CheckProc", proc]]];
};
C
Reserve: PROC [s: LONG STRING] = {
r: Rope.ROPE = ConvertUnsafe.ToRope[s];
[] ¬ C2CNames.Reserve[r];
};
Reserve["auto"];
Reserve["break"];
Reserve["case"];
Reserve["char"];
Reserve["continue"];
Reserve["default"];
Reserve["do"];
Reserve["double"];
Reserve["else"];
Reserve["enum"];
Reserve["extern"];
Reserve["float"];
Reserve["for"];
Reserve["goto"];
Reserve["if"];
Reserve["int"];
Reserve["long"];
Reserve["register"];
Reserve["return"];
Reserve["short"];
Reserve["sizeof"];
Reserve["static"];
Reserve["struct"];
Reserve["switch"];
Reserve["typedef"];
Reserve["union"];
Reserve["unsigned"];
Reserve["void"];
Reserve["while"];
Reserve["main"];
Reserve["null"];
Reserve["volatile"];
Reserve["const"];
PREPROCESSOR
Reserve["define"];
Reserve["defined"];
Reserve["elif"];
Reserve["endif"];
Reserve["error"];
Reserve["ifdef"];
Reserve["ifndef"];
Reserve["include"];
Reserve["line"];
Reserve["pragma"];
Reserve["undef"];
C2C STANDARDS
[] ← C2CNames.Reserve[C2CTarget.word];
[] ← C2CNames.Reserve[C2CTarget.wordPtr];
INSTALLATION
Reserve["DeclareGlobalFrame"];
Reserve["ExportInterface"];
Reserve["ExportProc"];
Reserve["ExportType"];
Reserve["ExportVar"];
Reserve["ForgetName"];
Reserve["GetRCIndex"];
Reserve["GetRefLiteral"];
Reserve["GetTypeIndex"];
Reserve["GlobalFrame"];
Reserve["GlobalFramePtr"];
Reserve["HideNames"];
Reserve["ImportInterface"];
Reserve["ImportProc"];
Reserve["InterfacePtr"];
Reserve["InterfaceRecord"];
Reserve["LiteralDesc"];
Reserve["LiteralDescPtr"];
Reserve["MergeInterface"];
Reserve["nullRCMapIndex"];
Reserve["nullTypeIndex"];
Reserve["PermitDuplicateExports"];
Reserve["PopRename"];
Reserve["PopScope"];
Reserve["ProhibitDuplicateExports"];
Reserve["PushRename"];
Reserve["PushScope"];
Reserve["RCMapDesc"];
Reserve["RCMapIndex"];
Reserve["RCMapPtr"];
Reserve["refRCMapIndex"];
Reserve["TypeDesc"];
Reserve["TypeIndex"];
Reserve["TypeStructure"];
Reserve["TypeStructurePtr"];
Reserve["unknownRCMapIndex"];
Reserve["AddControl"];
Reserve["ClearAllScopes"];
Reserve["ExportSignal"];
Reserve["Start"];
OUTER INSTALLATION
Reserve["firstControl"];
Reserve["load"];
Reserve["run"];
Reserve["unload"];
DEBUGGING
Reserve["printf"];
Reserve["putchar"];
IGC
Reserve["calloc"];
Reserve["cfree"];
Reserve["free"];
Reserve["gcollect"];
Reserve["malloc"];
Reserve["ralloc"];
Reserve["ralloc𡤌omp"];
Reserve["realloc"];
EDUARDO's PREPROCESSOR MAGIC
Reserve["CAT"];
Reserve["CAT2"];
Reserve["CAT3"];
Reserve["QUOTE"];
Reserve["STRING"];
END.