UXProcsImpl.mesa
Copyright Ó 1988, 1991 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, May 23, 1988 2:54:08 pm PDT
Christian Jacobi, May 23, 1988 2:54:11 pm PDT
Willie-s, August 5, 1991 4:09 pm PDT
DIRECTORY
Basics,
CardTab,
UXProcs;
UXProcsImpl: CEDAR PROGRAM
IMPORTS Basics, CardTab
EXPORTS UXProcs
~ BEGIN OPEN UXProcs;
ProcDescritorPtr: TYPE = POINTER TO ProcDescritorBody;
ProcDescritorBody: TYPE = RECORD [proc: CProc, data: WORD ¬ 0];
FromCedarProc: PUBLIC PROC [proc: PROC ANY RETURNS ANY] RETURNS [CProc] = TRUSTED {
ptr: ProcDescritorPtr = LOOPHOLE[proc];
IF ptr=NIL THEN RETURN [0];
IF ptr.data#0 THEN ERROR; --proc is not a global procedure
RETURN [ptr.proc];
};
descriptorTable: CardTab.Ref ¬ CardTab.Create[];
finite: because there are only a finite number of C procedures
ToCedarProc: PUBLIC PROC [cp: CProc] RETURNS [UnsafeCedarProc¬LOOPHOLE[NIL]] = TRUSTED {
IF cp#0 THEN {
x: REF ANY ¬ CardTab.Fetch[descriptorTable, LOOPHOLE[cp]].val;
IF x#NIL THEN RETURN [LOOPHOLE[x]];
IF Basics.BITAND[cp, 3]#0 THEN ERROR; --this can't be a procedure variable on sun
[] ¬ CardTab.Insert[descriptorTable, LOOPHOLE[cp], NEW[ProcDescritorBody¬[cp]]];
RETURN [LOOPHOLE[CardTab.Fetch[descriptorTable, LOOPHOLE[cp]].val]]
};
};
END.