C2CBasics.mesa
Copyright Ó 1987, 1988, 1989, 1990, 1991 by Xerox Corporation. All rights reserved.
Christian Jacobi, 1987
Christian Jacobi, January 15, 1993 11:31 am PST
DIRECTORY
IntCodeDefs,
IO,
Rope;
This definition exports internal basic features of C2C.
It copies some few well defined fields from C2CAccess to prevent too frequent imports of C2CAccess. On the other side only quite stable features are available in C2CBasics, as this is at the root of C2C's dependency graph.
Note that C2C is non re-entrant and uses global per compilation state.
C2CBasics: CEDAR DEFINITIONS =
BEGIN
Globals and state
c2cVersion: READONLY Rope.ROPE;
A text which allows to identify the version of C2C used.
rootNode: IntCodeDefs.Node;
The input node...
labelWithLambda: IntCodeDefs.LabelNode;
The current procedure...
Context mechanism
Today I consider it somewhat questionable
Context: TYPE = RECORD [key: REF ¬ NIL, node: IntCodeDefs.Node¬NIL, data: REF ¬ NIL];
ContextSequence: TYPE = RECORD [
idx: NAT,
seq: SEQUENCE max: NAT OF Context
];
ctxTop: REF ContextSequence;
PushContext: PROC [ctx: Context];
PopContext: PROC [];
Interpretation of context:
Start with C2CBasics.ctxTop.seq[C2CBasics.ctxTop.idx] and go backwards until first unknown key is found
once an unknown key is found interpreting more context is not safe.
Properties
Use rarely, mainly while developing feature
GetProp: PROC [key: REF] RETURNS [val: REF];
Get property from current compilation
PutProp: PROC [key, val: REF];
Put property onto current compilation
Every compilation starts with an empty property list
Errors and prograss
Report: PROC [what: Rope.ROPE ¬ NIL];
Reports some progress. Defaults to a dot.
usa rarely !
FatalError: ERROR [what: Rope.ROPE ¬ NIL];
Signalled on fatal errors which should be told to the client.
There is something wrong in the compiled program, not the compiler.
Compilation aborts when raised.
ErrorStream: PROC [] RETURNS [IO.STREAM];
Returns a stream for error messages
Side effect: this causes C2C to fail but compilation does not yet aborts.
CantHappen: SIGNAL;
Signalled when something is simply not possible (according to our intentions, at least)
CantHappenCedar: SIGNAL;
Signalled when something is simply not possible in the case of Cedar to C
CantHappenPreprocessed: SIGNAL;
Signalled when something is should not be possible according to our preprocessing requirements
CaseMissing: SIGNAL;
Used e.g. as endcase where we think we considered all cases;
Protects from future incomplete introduction of new cases
NotYetImpl: SIGNAL;
Proceed may work or lead to disaster
NotYetImplPreprocessed: SIGNAL;
We intend to require preprocessing which makes this impossible
Proceed may work or lead to disaster
Callbacks
CallbackWhenC2CIsCalled: PROC [p: PROC];
Registers a procedure which is called whenever C2C is newly called
Use this to initialize global per compilation variables
END.