CoreContextImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Created by Pradeep Sindhu, December 12, 1985 10:10:25 pm PST
Pradeep Sindhu December 13, 1985 12:06:56 pm PST
Louis Monier December 13, 1985 4:12:01 pm PST
DIRECTORY
AMModel,
AMTypes USING [TV],
AMBridge USING [SomeRefFromTV, TVForReferent, TVForFrame],
AMModelBridge,
CoreContext,
Interpreter USING [Evaluate],
PrincOpsUtils,
Rope,
SymTab;
CoreContextImpl: CEDAR PROGRAM    
IMPORTS AMBridge, AMModelBridge, Interpreter, PrincOpsUtils, SymTab
EXPORTS CoreContext =
BEGIN
OPEN CoreContext;
Design
Public Procedures
Create: PUBLIC PROC [] RETURNS [cx: Context] = BEGIN
cx ← SymTab.Create[];
END;
Copy: PUBLIC PROC [cx: Context] RETURNS [newCx: Context] = BEGIN
CopyItem: SymTab.EachPairAction = {
[] ← SymTab.Store[newCx, key, val];
quit ← FALSE;
};
IF cx=NIL THEN ERROR;
newCx ← SymTab.Create[];
[] ← SymTab.Pairs[cx, CopyItem];
END;
Store: PUBLIC PROC [cx: Context, var: ROPE, value: REFNIL] = BEGIN
[] ← SymTab.Store[cx, var, TVFromRef[value]];
END;
Eval: PUBLIC PROC [cx: Context, expr: ROPE, cedarCx: AMModel.Context ← NIL] RETURNS [REF] = TRUSTED BEGIN
result: AMTypes.TV;
errorRope: ROPE;
noResult: BOOL;
IF cedarCx=NIL THEN cedarCx ← AMModelBridge.ContextForFrame[
AMBridge.TVForFrame[
PrincOpsUtils.GetReturnFrame[]
]
];
[result, errorRope, noResult] ← Interpreter.Evaluate[rope: expr, context: cedarCx, symTab: cx];
IF errorRope # NIL THEN ERROR;
RETURN[RefFromTV[result]];
END;
Private Procedures
RefFromTV: PROC [tv: REF] RETURNS [REF] = BEGIN
IF tv=NIL THEN RETURN [NIL];
IF ~ISTYPE [tv, AMTypes.TV] THEN ERROR;
TRUSTED {RETURN [AMBridge.SomeRefFromTV[tv]]};
END;
TVFromRef: PROC [ref: REF] RETURNS [AMTypes.TV] = TRUSTED BEGIN
RETURN [AMBridge.TVForReferent[ref]];
END;
END.