<> <> <> DIRECTORY Alloc: TYPE USING [ Handle, Notifier, TableInfo, AddNotify, Bounds, Create, Destroy, DropNotify, Words], ConvertUnsafe: TYPE USING [SubString], IO: TYPE USING [STREAM, UnsafePutBlock], PGSConDefs: TYPE USING [objectVersion, pgsVersion, sourceVersion, zone], PrincOps: TYPE USING [bytesPerWord, ControlLink], Rope: TYPE USING [Flatten, Length, ROPE], SymbolOps: TYPE USING [ Initialize, Finalize, EnterString, HashBlock, MakeCtxSe, NewCtx, MakeNonCtxSe], SymbolPack: TYPE, 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], Table: TYPE USING [Selector]; PGSSymbols: PROGRAM IMPORTS Alloc, PGSConDefs, IO, Rope, 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: Rope.ROPE, bodyCtx: CTXIndex] = { tSei: CSEIndex; sei: ISEIndex; bti: CBTIndex; <> tSei _ MakeNonCtxSe[SERecord.cons.transfer.SIZE]; seb[tSei] _ SERecord[ mark3: TRUE, mark4: TRUE, body: cons[transfer[ mode: program, safe: FALSE, typeIn: RecordSENull, typeOut: RecordSENull]]]; <> sei _ MakeConstant[moduleId, dirCtx, tSei]; seb[sei].public _ TRUE; seb[sei].idValue _ PrincOps.ControlLink[ 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}; MakeConstant: PROC [name: Rope.ROPE, ctx: CTXIndex, type: SEIndex] RETURNS [sei: ISEIndex] = { <> ss: ConvertUnsafe.SubString; ss.offset _ 0; ss.length _ name.Length[]; ss.base _ LOOPHOLE[Rope.Flatten[name]]; sei _ MakeCtxSe[EnterString[ss], 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: Rope.ROPE] = { ctx: CTXIndex; WHILE (ctx _ NewCtx[lZ]) IN StandardContext DO NULL ENDLOOP; dirCtx _ ctx; EnterModule[moduleId, NewCtx[lG]]}; EnterHashMark: PROC = { <> desc: ConvertUnsafe.SubString _ [base:" "L, offset:1, length:0]; [] _ EnterString[desc]}; WriteSymbols: PUBLIC PROC [s: IO.STREAM, moduleId: Rope.ROPE] = { 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 = PrincOps.bytesPerWord; TableOut: PROC [s: IO.STREAM] = { OPEN SymbolSegment; header: STHeader; d: WordOffset; WriteSubTable: PROC [selector: Table.Selector] = { base: Symbols.Base; size: CARDINAL; [base, size] _ table.Bounds[selector]; s.UnsafePutBlock[[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.UnsafePutBlock[[@header, 0, STHeader.SIZE*BytesPerWord]]; s.UnsafePutBlock[[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}; }.