-- file PGSSymbols.mesa -- last modified by Satterthwaite, August 2, 1983 9:25 am DIRECTORY Alloc: TYPE USING [ Handle, Notifier, TableInfo, AddNotify, Bounds, Create, Destroy, DropNotify, Words], BcdDefs: TYPE USING [Link], Environment: TYPE USING [bytesPerWord], PGSConDefs: TYPE USING [objectVersion, pgsVersion, sourceVersion, zone], Stream: TYPE USING [Handle, PutBlock], Strings: TYPE USING [String, SubStringDescriptor], Symbols: TYPE USING [ Base, HashVector, SERecord, BodyRecord, StandardContext, SEIndex, ISEIndex, CSEIndex, RecordSEIndex, CTXIndex, CBTIndex, ISENull, CSENull, RecordSENull, CTXNull, BTNull, lG, lZ], SymbolSegment: TYPE USING [ Tables, htType, ssType, ctxType, seType, mdType, bodyType, VersionID, STHeader, WordOffset], SymbolOps: TYPE USING [ Initialize, Finalize, EnterString, HashBlock, MakeCtxSe, NewCtx, MakeNonCtxSe], SymbolPack: TYPE, Table: TYPE USING [Selector]; PGSSymbols: PROGRAM IMPORTS Alloc, PGSConDefs, Stream, SymbolOps, SymbolPack EXPORTS PGSConDefs = { OPEN SymbolOps, Symbols; table: Alloc.Handle _ NIL; seb: Symbols.Base; -- semantic entry base (local copy) ctxb: Symbols.Base; -- context table base (local copy) bb: Symbols.Base; -- body table base (local copy) Notify: Alloc.Notifier = { OPEN SymbolSegment; seb _ base[seType]; ctxb _ base[ctxType]; bb _ base[bodyType]}; dirCtx: CTXIndex; EnterModule: PROC [moduleId: Strings.String, bodyCtx: CTXIndex] = { tSei: CSEIndex; sei: ISEIndex; bti: CBTIndex; -- generate a program type tSei _ MakeNonCtxSe[SERecord.cons.transfer.SIZE]; seb[tSei] _ SERecord[ mark3: TRUE, mark4: TRUE, body: cons[transfer[ mode: program, safe: FALSE, typeIn: RecordSENull, typeOut: RecordSENull]]]; -- generate an id sei _ MakeConstant[moduleId, dirCtx, tSei]; seb[sei].public _ TRUE; seb[sei].idValue _ BcdDefs.Link[procedure[gfi: 1, ep: 0, tag: TRUE]]; bti _ table.Words[SymbolSegment.bodyType, BodyRecord.Callable.Outer.SIZE]; bb[bti] _ BodyRecord[ link: [parent, BTNull], firstSon: BTNull, localCtx: CTXNull, type: RecordSENull, level: lG, sourceIndex: 0, info: [External[0, 0, 0]], extension: Callable[ inline: FALSE, id: ISENull, ioType: CSENull, monitored: FALSE, noXfers: FALSE, resident: FALSE, entry: FALSE, internal: FALSE, entryIndex: 0, hints: [FALSE, FALSE, FALSE, FALSE], closure: Outer[]]]; bb[bti].id _ sei; bb[bti].ioType _ tSei; bb[bti].localCtx _ bodyCtx; seb[sei].idInfo _ bti}; SubStringDescriptor: TYPE = Strings.SubStringDescriptor; MakeConstant: PROC [name: Strings.String, ctx: CTXIndex, type: SEIndex] RETURNS [sei: ISEIndex] = { -- makes an se entry for a built-in constant desc: SubStringDescriptor _ [base:name, offset:0, length:name.length]; sei _ MakeCtxSe[EnterString[@desc], ctx]; seb[sei].idType _ type; seb[sei].immutable _ seb[sei].constant _ TRUE; seb[sei].extended _ seb[sei].public _ seb[sei].linkSpace _ FALSE; seb[sei].mark3 _ seb[sei].mark4 _ TRUE; RETURN}; CreateSymbols: PROC [moduleId: Strings.String] = { ctx: CTXIndex; WHILE (ctx _ NewCtx[lZ]) IN StandardContext DO NULL ENDLOOP; dirCtx _ ctx; EnterModule[moduleId, NewCtx[lG]]}; EnterHashMark: PROC = { -- marks end of symbols from source file in hash table desc: SubStringDescriptor _ [base:" "L, offset:1, length:0]; [] _ EnterString[@desc]}; WriteSymbols: PUBLIC PROC [s: Stream.Handle, moduleId: Strings.String] = { weights: ARRAY SymbolSegment.Tables OF Alloc.TableInfo _ ALL[[1]]; table _ Alloc.Create[weights: DESCRIPTOR[weights]]; table.AddNotify[Notify]; SymbolOps.Initialize[table, PGSConDefs.zone]; CreateSymbols[moduleId]; EnterHashMark[]; table.DropNotify[Notify]; TableOut[s]; SymbolOps.Finalize[]; Alloc.Destroy[table]; table _ NIL}; BytesPerWord: CARDINAL = Environment.bytesPerWord; TableOut: PROC [s: Stream.Handle] = { OPEN SymbolSegment; header: STHeader; d: WordOffset; WriteSubTable: PROC [selector: Table.Selector] = { base: Symbols.Base; size: CARDINAL; [base, size] _ table.Bounds[selector]; s.PutBlock[[base, 0, size*BytesPerWord]]}; BEGIN OPEN header; versionIdent _ SymbolSegment.VersionID; version _ LOOPHOLE[PGSConDefs.objectVersion]; -- for bootstrap sourceVersion _ LOOPHOLE[PGSConDefs.sourceVersion]; creator _ LOOPHOLE[PGSConDefs.pgsVersion]; definitionsFile _ FALSE; directoryCtx _ dirCtx; importCtx _ outerCtx _ CTXNull; d _ STHeader.SIZE; hvBlock.offset _ d; d _ d + (hvBlock.size _ Symbols.HashVector.SIZE); htBlock.offset _ d; d _ d + (htBlock.size _ table.Bounds[htType].size); ssBlock.offset _ d; d _ d + (ssBlock.size _ table.Bounds[ssType].size); seBlock.offset _ d; d _ d + (seBlock.size _ table.Bounds[seType].size); ctxBlock.offset _ d; d _ d + (ctxBlock.size _ table.Bounds[ctxType].size); mdBlock.offset _ d; d _ d + (mdBlock.size _ table.Bounds[mdType].size); bodyBlock.offset _ d; d _ d + (bodyBlock.size _table.Bounds[bodyType].size); treeBlock _ litBlock _ sLitBlock _ extBlock _ [d, 0]; constBlock _ [0, 0]; fgRelPgBase _ fgPgCount _ 0; END; s.PutBlock[[@header, 0, STHeader.SIZE*BytesPerWord]]; s.PutBlock[[SymbolOps.HashBlock[], 0, header.hvBlock.size*BytesPerWord]]; WriteSubTable[htType]; WriteSubTable[ssType]; WriteSubTable[seType]; WriteSubTable[ctxType]; WriteSubTable[mdType]; WriteSubTable[bodyType]}; started: BOOL _ FALSE; IF ~started THEN {START SymbolPack; started _ TRUE}; }.