GenerateInterface.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Bhargava, August 9, 1986 3:07:06 pm PDT
Bill Jackson (bj) September 25, 1986 3:13:54 am PDT
Demers, December 29, 1986 9:02:09 pm PST
DIRECTORY
BasicTime USING [],
FS USING [StreamOpen],
HashTable USING [EachPairAction, Erase, Fetch, Pairs, Value],
IO USING [STREAM, rope, Close, PutF, PutRope],
Rope USING [ROPE, Cat, Equal, IsEmpty],
SiroccoPrivate USING [AquireState, CComponent, ConstExp, CType, DirectoryEntry, FileHeader, Handle, MakeUpName, Nest, TypeExp, TABLES, UnDo];
GenerateInterface: CEDAR PROGRAM
IMPORTS FS, HashTable, IO, Rope, SiroccoPrivate
EXPORTS SiroccoPrivate ~ {
OPEN SiroccoPrivate;
Copied Types
ROPE: TYPE ~ Rope.ROPE;
Value: TYPE ~ HashTable.Value;
Procs
GenDefs: PUBLIC PROC ~ {
allTheTables: TABLES;
defStream: IO.STREAM;
failure: BOOLEAN;
h: Handle;
initStream: IO.STREAM;
programKey: ROPE;
programKeyWD: ROPE;
GenerateInterfaceItem: HashTable.EachPairAction ~ {
name: ROPENARROW [key];
entry: REF DirectoryEntry ← NARROW [value];
unDoneCanonicalTypeName: ROPE;
constExp: ROPENIL;
setupDecls: LIST OF ROPENIL;
runtime: BOOL;
type: CType;
value1: Value;
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];
[value~ value1] ← HashTable.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 = procedure) 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: HashTable.EachPairAction ~ {
interface: ROPE ~ NARROW [value];
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 ← HashTable.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: HashTable.EachPairAction ~ {
interface: ROPE ~ NARROW [value];
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 ← HashTable.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;
HashTable.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]];
[] ← HashTable.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];
};
}.