GenerateInterface.mesa
Copyright Ó 1986, 1987 by Xerox Corporation. All rights reserved.
Bhargava, August 9, 1986 3:07:06 pm PDT
Bill Jackson (bj) June 11, 1987 1:21:35 am PDT
Demers, December 29, 1986 9:02:09 pm PST
DIRECTORY
BasicTime USING [],
FS USING [StreamOpen],
IO USING [STREAM, rope, Close, PutF, PutRope],
Rope USING [ROPE, Cat, Equal, IsEmpty],
SiroccoPrivate USING [AquireState, CComponent, ConstExp, CType, FileHeader, Handle, InterfaceItem, MakeUpName, Nest, TypeExp, TABLES, UnDo],
SymTab USING [EachPairAction, Erase, Fetch, Pairs, Val];
GenerateInterface: CEDAR PROGRAM
IMPORTS FS, IO, Rope, SiroccoPrivate, SymTab
EXPORTS SiroccoPrivate ~ {
OPEN SiroccoPrivate;
ROPE: TYPE ~ Rope.ROPE;
GenDefs: PUBLIC PROC ~ {
allTheTables: TABLES;
defStream: IO.STREAM;
failure: BOOLEAN;
h: Handle;
initStream: IO.STREAM;
programKey: ROPE;
programKeyWD: ROPE;
GenerateInterfaceItem: SymTab.EachPairAction ~ {
name: ROPENARROW [key];
entry: REF InterfaceItem ← NARROW [val];
unDoneCanonicalTypeName: ROPE;
constExp: ROPENIL;
setupDecls: LIST OF ROPENIL;
runtime: BOOL;
type: CType;
value1: SymTab.Val;
PutRopeList: PROC [stream: IO.STREAM, list: LIST OF ROPE] ~ {
WHILE list # NIL DO
IO.PutRope[stream, list.first];
list ← list.rest;
ENDLOOP;
};
EmitNamedType: PROC ~ {
typeExp: ROPE;
objTypeDecls: LIST OF ROPENIL;
[typeExp, objTypeDecls] ← TypeExp[h, type, unDoneCanonicalTypeName, 1];
IO.PutF[defStream, "%g%g: TYPE ~ %g;",
IO.rope[Nest[NIL,1]],
IO.rope[unDoneCanonicalTypeName],
IO.rope[typeExp]
];
IF objTypeDecls # NIL THEN PutRopeList[defStream, objTypeDecls];
};
EmitRenamedType: PROC ~ {
unDoneCanonicalTypeName ← MakeUpName[name, "Type", allTheTables];
EmitNamedType[];
};
unDoneCanonicalTypeNameUnDo[entry.type, programKey];
[val: value1] ← SymTab.Fetch[allTheTables.condensedTypeTable, entry.type];
type ← NARROW[value1];
SELECT TRUE FROM
Rope.IsEmpty[entry.constant] => { -- it's a type declaration
IF Rope.Equal[name, unDoneCanonicalTypeName]
THEN EmitNamedType[]
ELSE IO.PutF[defStream, "%g%g: TYPE ~ %g;",
IO.rope[Nest[NIL,1]],
IO.rope[name],
IO.rope[unDoneCanonicalTypeName]
];
};
(type.class = proc) OR (type.class = error) => { -- it's a proc or error declaration
IF Rope.Equal[name, unDoneCanonicalTypeName] THEN EmitRenamedType[];
IO.PutF[defStream, "%g%g: %g;",
IO.rope[Nest[NIL,1]],
IO.rope[name],
IO.rope[unDoneCanonicalTypeName]
];
};
ENDCASE => { -- it's an initialized constant
IF Rope.Equal[name, unDoneCanonicalTypeName] THEN EmitRenamedType[];
[constExp, setupDecls, runtime] ←
ConstExp[h, entry.constant, type, unDoneCanonicalTypeName, 1];
IF runtime
THEN {
IO.PutF[defStream, "%g%g: READONLY %g;",
IO.rope[Nest[NIL,1]],
IO.rope[name],
IO.rope[unDoneCanonicalTypeName]
];
IO.PutRope[initStream, "\n"];
IF setupDecls # NIL THEN PutRopeList[initStream, setupDecls];
IO.PutF[initStream, "%g%g: PUBLIC %g ← %g;",
IO.rope[Nest[NIL,1]],
IO.rope[name],
IO.rope[unDoneCanonicalTypeName],
IO.rope[constExp]
];
}
ELSE -- not runtime -- {
IO.PutF[defStream, "%g%g: %g ~ %g;",
IO.rope[Nest[NIL,1]],
IO.rope[name],
IO.rope[unDoneCanonicalTypeName],
IO.rope[constExp]
];
};
};
IO.PutRope[defStream, "\n"];
};
Heading: PROC [out: IO.STREAM] ~ {
PutDirectory: SymTab.EachPairAction ~ {
interface: ROPE ~ NARROW [val];
IO.PutF[out, Nest["%g,", 1],
IO.rope[interface]
];
};
SiroccoPrivate.FileHeader[out, Rope.Cat[programKeyWD, ".Mesa"]];
IO.PutF[out, Nest["DIRECTORY", 1]];
IO.PutF[out, Nest["CrRPC,", 1]];
failure ← SymTab.Pairs[allTheTables.directory, PutDirectory];
IO.PutF[out, Nest["Rope;", 0]];
IO.PutF[out, Nest["", 0]];
IO.PutF[out, Nest["%g: CEDAR DEFINITIONS ~ {", 1], IO.rope[programKeyWD]];
};
InitHeading: PROC [out: IO.STREAM] ~ {
PutDirectory: SymTab.EachPairAction ~ {
interface: ROPE ~ NARROW [val];
IO.PutF[out, Nest["%g,", 1],
IO.rope[interface]
];
};
SiroccoPrivate.FileHeader[out, Rope.Cat[programKeyWD, "Init.Mesa"]];
IO.PutF[out, Nest["DIRECTORY", 1]];
IO.PutF[out, Nest["CrRPC,", 1]];
IO.PutF[out, Nest["Rope,", 1]];
failure ← SymTab.Pairs[allTheTables.directory, PutDirectory];
IO.PutF[out, Nest["%g;", 0], IO.rope[programKeyWD]];
IO.PutF[out, Nest["", 0]];
IO.PutF[out, Nest["%gInit: CEDAR PROGRAM", 1], IO.rope[programKeyWD]];
IO.PutF[out, Nest["EXPORTS %g ~ {", 1], IO.rope[programKeyWD]];
IO.PutF[out, Nest["OPEN %g;", 0], IO.rope[programKeyWD]];
};
GenDefs MAIN
h ← SIGNAL AquireState[];
allTheTables ← h.allTheTables;
programKey ← h.programKey;
programKeyWD ← h.programKeyWD;
SymTab.Erase[allTheTables.workTable];
Generate Interface and Constant Initialization Module
defStream ← FS.StreamOpen[Rope.Cat[programKeyWD, ".Mesa"], $create];
initStream ← FS.StreamOpen[Rope.Cat[programKeyWD, "Init.Mesa"], $create];
Heading[defStream];
IO.PutF[defStream, Nest["", 1]];
IO.PutF[defStream, Nest["ROPE: TYPE ~ Rope.ROPE;", 1]];
IO.PutF[defStream, Nest["", 1]];
InitHeading[initStream];
IO.PutF[initStream, Nest["", 1]];
IO.PutF[initStream, Nest["ROPE: TYPE ~ Rope.ROPE;", 1]];
IO.PutF[initStream, Nest["", 1]];
[] ← SymTab.Pairs[allTheTables.localTable, GenerateInterfaceItem];
IO.PutF[defStream, Nest["", 0]];
IO.PutF[defStream, Nest["}...", 0]];
IO.Close[defStream];
IO.PutF[initStream, Nest["", 0]];
IO.PutF[initStream, Nest["}...", 0]];
IO.Close[initStream];
};
}.