SiroccoMethods.ThreeC4
Copyright Ó 1986, 1987 by Xerox Corporation. All rights reserved.
Bhargava, August 12, 1986 11: 24: 02 pm PDT
Demers, December 29, 1986 8:05:56 pm PST
Bill Jackson (bj) August 26, 1987 3:44:43 pm PDT
Include [ Sirocco ];
SiroccoMethodsA: Module = Begin
Produce object representation for the Courier Program
Program: AbstractType [ MakeSymbolTable ];
for Program.export: AbstractProduction [ id.export, decimal.pgm, decimal.version,
ImportList, DeclarationList ]
let MakeSymbolTable[tree] ← < name, pgm, version, res >
where res ← typegraph
where tossB ← AssertValueGraphAcyclic[typegraph]
where tossA ← AssertTypeGraphAcyclic[typegraph]
where typegraph ← BuildTypeGraph[DeclarationList, context]
where context ← CreateContext[rib, scope, name, pgm, version]
where scope ← BuildItemTable[DeclarationList]
where rib ← BuildRIB[ImportList]
where name ← TextFromID[id.export]
where pgm ← CardFromDecimal[decimal.pgm]
where version ← CardFromDecimal[decimal.version]
;
Internalize imported Courier Programs
ImportList: AbstractType [ BuildRIB ];
for ImportList.empty: AbstractProduction [ ]
let BuildRIB[tree] ← EmptyRIB[]
;
for ImportList.more: AbstractProduction [ ImportList, Import ]
let BuildRIB[tree] ← newrib
where newrib ← ScopeConcat[rib, scope]
where rib ← BuildRIB[ImportList]
where scope ← BuildScope[Import]
;
Import: AbstractType [ BuildScope ];
for Import.interface: AbstractProduction [ id.interface, decimal.pgm, decimal.version ]
let BuildScope[tree] ← scope
where scope ← DiskToTable[interface, pgm, version]
where interface ← TextFromID[id.interface]
where pgm ← CardFromDecimal[decimal.pgm]
where version ← CardFromDecimal[decimal.version]
;
Identify Items of "this" program
DeclarationList: AbstractType [ BuildItemTable, BuildTypeGraph ];
for DeclarationList.empty: AbstractProduction [ ]
let BuildItemTable[tree] ← EmptyScope[]
let BuildTypeGraph[tree, context] ← CreateEmptyTGN[ context ]
;
for DeclarationList.more: AbstractProduction [ DeclarationList, Declaration ]
let BuildItemTable[tree] ← newscope
where newscope ← ItemConcat[scope, item]
where scope ← BuildItemTable[DeclarationList]
where item ← BuildItem[Declaration]
let BuildTypeGraph[tree, context] ← graphB
where graphB ← UpdateItem[graphA, name, node, value]
where graphA ← BuildTypeGraph[DeclarationList, context]
where < name, node, value > ← BuildNamedItem[Declaration, context]
;
Declaration: AbstractType [ BuildItem, BuildNamedItem ];
for Declaration.type: AbstractProduction [id, Type]
let BuildItem[tree] ← MakeItem[name, index, ItemKind.type]
where index ← SourcePosition[tree]
where name ← TextFromID[id]
let BuildNamedItem[tree, context] ← < name, node, value >
where value ← CreateNullAVN[]
where node ← BuildTGN[Type, context]
where item ← ItemFromContext[context, name]
where name ← TextFromID[id]
;
for Declaration.constant: AbstractProduction [id, Type, Constant]
let BuildItem[tree] ← MakeItem[key, index, ItemKind.const]
where index ← SourcePosition[tree]
where key ← TextFromID[id]
let BuildNamedItem[tree, context] ← < name, node, value >
where value ← BuildAbstractValue[Constant, context]
where node ← BuildTGN[Type, context]
where name ← TextFromID[id]
;
Type: AbstractType [ BuildTGN ];
References
for Type.alias: AbstractProduction [ id ]
let BuildTGN[tree, context] ← node
where node ← CreateDerefTGN[context, item]
where item ← TextFromID[id]
;
for Type.import: AbstractProduction [ id.interface, id.item ]
let BuildTGN[tree, context] ← node
where node ← CreateLinkTGN[context, interface, item]
where interface ← TextFromID[id.interface]
where item ← TextFromID[id.item]
;
Primitives
for Type.bool: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.bool]
;
for Type.card16: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.card16]
;
for Type.card32: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.card32]
;
for Type.int16: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.int16]
;
for Type.int32: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.int32]
;
for Type.sink: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.sink]
;
for Type.source: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.source]
;
for Type.string: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.string]
;
for Type.unspec: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateBaseTypeTGN[BaseTypeKind.unspec]
;
Constructions
for Type.array: AbstractProduction [ Constant, Type ]
let BuildTGN[tree, context] ← node
where node ← CreateArrayTGN[length, subtype]
where length ← BuildAbstractValue[Constant, context]
where subtype ← BuildTGN[Type, context]
;
for Type.choice: AbstractProduction [ Type, Union ]
let BuildTGN[tree, context] ← node
where node ← CreateChoiceTGN[ktype, union]
where ktype ← BuildTGN[Type, context]
where union ← BuildTGN[Union, context]
;
for Type.enum: AbstractProduction [ Enumeration ]
let BuildTGN[tree, context] ← node
where node ← CreateEnumerationTGN[enum]
where enum ← BuildTGN[Enumeration, context]
;
for Type.error: AbstractProduction [ FieldList ]
let BuildTGN[tree, context] ← node
where node ← CreateErrorTGN[fieldlist]
where fieldlist ← BuildTGN[FieldList, context]
;
for Type.proc: AbstractProduction [ FieldList.arg, FieldList.res, NameList ]
let BuildTGN[tree, context] ← node
where node ← CreateProcTGN[args, results, errors]
where args ← BuildTGN[FieldList.arg, context]
where results ← BuildTGN[FieldList.res, context]
where errors ← BuildTGN[NameList, context]
;
for Type.record: AbstractProduction [ FieldList ]
let BuildTGN[tree, context] ← node
where node ← CreateRecordTGN[fieldlist]
where fieldlist ← BuildTGN[FieldList, context]
;
for Type.null: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreateRecordTGN[empty]
where empty ← CreatePrimitiveTGN[Generic.record]
;
for Type.seq: AbstractProduction [ Constant, Type ]
let BuildTGN[tree, context] ← node
where node ← CreateSequenceTGN[maxlength, subtype]
where maxlength ← BuildAbstractValue[Constant, context]
where subtype ← BuildTGN[Type, context]
;
Constant: AbstractType [ BuildAbstractValue ];
References
for Constant.deref: AbstractProduction [ id ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateDerefAVN[context, item]
where item ← TextFromID[id]
;
for Constant.import: AbstractProduction [ id.interface, id.item ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateLinkAVN[context, interface, item]
where interface ← TextFromID[id.interface]
where item ← TextFromID[id.item]
;
Primitives
for Constant.empty: AbstractProduction [ ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateGroupingAVN[node]
where node ← CreateNullAVN[]
;
for Constant.false: AbstractProduction [ ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateLogicalAVN[False[]]
;
for Constant.true: AbstractProduction [ ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateLogicalAVN[True[]]
;
for Constant.unbounded: AbstractProduction [ ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateNumericalAVN[card[65536]]
;
for Constant.inverted: AbstractProduction [ Number ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateNegativeAVN[node]
where node ← BuildAbstractValue[Number, context]
;
for Constant.number: AbstractProduction [ Number ]
let BuildAbstractValue[tree, context] ← value
where value ← BuildAbstractValue[Number, context]
;
for Constant.string: AbstractProduction [ rope ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateRopeAVN[text]
where text ← GetRopeFromRope[rope]
;
Constructions
for Constant.choice: AbstractProduction [ id, Constant ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateVariantAVN[tag, node]
where tag ← TextFromID[id]
where node ← BuildAbstractValue[Constant, context]
;
for Constant.constructor: AbstractProduction [ Constructor ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateConstructorAVN[node]
where node ← BuildAbstractValue[Constructor, context]
;
for Constant.grouping: AbstractProduction [ Grouping ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateGroupingAVN[node]
where node ← BuildAbstractValue[Grouping, context]
;
End;
SiroccoMethodsB: Module = Begin
Enumeration: AbstractType [ BuildTGN ];
for Enumeration.one: AbstractProduction [ id, Constant ]
let BuildTGN[tree, context] ← node
where node ← CreateFieldListTGN[tag, ordinal]
where tag ← TextFromID[id]
where ordinal ← BuildAbstractValue[Constant, context]
;
for Enumeration.more: AbstractProduction [ Enumeration.value, Enumeration.next ]
INVARIANT: Enumeration.value is expanded as Enumeration.one.
let BuildTGN[tree, context] ← nodeC
where nodeC ← FieldListTGNConcat[nodeA, nodeB]
where nodeB ← BuildTGN[Enumeration.next, context]
where nodeA ← BuildTGN[Enumeration.value, context]
;
Union: AbstractType [ BuildTGN ];
for Union.one: AbstractProduction [ NameList, Type ]
let BuildTGN[tree, context] ← nodeC
where nodeC ← CreateUnionTGN[nodeB, nodeA]
where nodeB ← BuildTGN[NameList, context]
where nodeA ← BuildTGN[Type, context]
;
for Union.more: AbstractProduction [ Union.value, Union.next ]
INVARIANT: Union.value is expanded as Union.one.
let BuildTGN[tree, context] ← nodeC
where nodeC ← UnionTGNConcat[nodeA, nodeB]
where nodeB ← BuildTGN[Union.next, context]
where nodeA ← BuildTGN[Union.value, context]
;
FieldList: AbstractType [ BuildTGN ]; -- I want a FIELD type (ajd)
for FieldList.empty: AbstractProduction [ ]
let BuildTGN[tree, context] ← nodeA
where nodeA ← CreateEmptyFieldTGN[]
;
for FieldList.one: AbstractProduction [ NameList, Type ]
let BuildTGN[tree, context] ← nodeC
where nodeC ← CreateFieldTGN[nodeB, nodeA]
where nodeB ← BuildTGN[NameList, context]
where nodeA ← BuildTGN[Type, context]
;
for FieldList.more: AbstractProduction [ FieldList.value, FieldList.rest ]
INVARIANT: FieldList.value is expanded as FieldList.one.
let BuildTGN[tree, context] ← nodeC
where nodeC ← FieldTGNConcat[nodeA, nodeB]
where nodeB ← BuildTGN[FieldList.rest, context]
where nodeA ← BuildTGN[FieldList.value, context]
;
Grouping: AbstractType [ BuildAbstractValue ];
for Grouping.one: AbstractProduction [ Constant ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateGroupingAVN[nodeA]
where nodeA ← BuildAbstractValue[Constant, context]
;
for Grouping.more: AbstractProduction [ Constant, Grouping ]
let BuildAbstractValue[tree, context] ← nodeC
where nodeC ← GroupingAVNConcat[nodeA, nodeB]
where nodeB ← BuildAbstractValue[Constant, context]
where nodeA ← BuildAbstractValue[Grouping, context]
;
Constructor: AbstractType [ BuildAbstractValue ];
for Constructor.one: AbstractProduction [ Binding ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateConstructorAVN[nodeA]
where nodeA ← BuildAbstractValue[Binding, context]
;
for Constructor.more: AbstractProduction [ Binding, Constructor ]
let BuildAbstractValue[tree, context] ← nodeC
where nodeC ← ConstructorAVNConcat[nodeA, nodeB]
where nodeB ← BuildAbstractValue[Binding, context]
where nodeA ← BuildAbstractValue[Constructor, context]
;
Binding: AbstractType [ BuildAbstractValue ];
for Binding: AbstractProduction [ NameList, Constant ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateBindingAVN[nodeA, nodeB]
where nodeA ← BuildTGN[NameList, context]
where nodeB ← BuildAbstractValue[Constant, context]
;
NameList: AbstractType [ BuildTGN ];
for NameList.empty: AbstractProduction [ ]
let BuildTGN[tree, context] ← node
where node ← CreatePrimitiveTGN[Generic.record]
;
for NameList.one: AbstractProduction [ id ]
let BuildTGN[tree, context] ← node
where node ← CreatePrimitiveTGN[Generic.record]
;
for NameList.more: AbstractProduction [ id, NameList ]
let BuildTGN[tree, context] ← node
where node ← CreatePrimitiveTGN[Generic.record]
;
Number: AbstractType [ BuildAbstractValue ];
for Number.decimal: AbstractProduction [ decimal ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateNumericalAVN[card]
where card ← CardFromDecimal[decimal]
;
for Number.hex: AbstractProduction [ hex ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateNumericalAVN[card]
where card ← CardFromHex[hex]
;
for Number.octal: AbstractProduction [ octal ]
let BuildAbstractValue[tree, context] ← value
where value ← CreateNumericalAVN[card]
where card ← CardFromOctal[octal]
;
End.