@@ -664,11 +664,26 @@ proc buildExportBuf(w: var Writer): TokenBuf =
664664 result .add identToken (pool.strings.getOrIncl (name), NoLineInfo )
665665 result .addParRi ()
666666
667+ proc translateOpsLog (w: var Writer ; opsLog: seq [LogEntry ]): IndexSections =
668+ result = IndexSections (hooks: default array [AttachedOp , seq [HookIndexEntry ]], converters: @ [], classes: @ [])
669+ for entry in opsLog:
670+ let key = pool.syms.getOrIncl (entry.typ.typeKey (w.infos.config))
671+ let sym = pool.syms.getOrIncl (w.toNifSymName (entry.sym))
672+ case entry.kind
673+ of HookEntry :
674+ result .hooks[toAttachedOp (entry.op)].add HookIndexEntry (isGeneric: entry.isGeneric, typ: key, hook: sym)
675+ of ConverterEntry :
676+ result .converters.add (key, sym)
677+ of MethodEntry :
678+ discard " to implement"
679+ of EnumToStrEntry :
680+ discard " to implement"
681+
682+
667683let replayTag = registerTag (" replay" )
668684
669685proc writeNifModule * (config: ConfigRef ; thisModule: int32 ; n: PNode ;
670- hooks: array [AttachedOp , seq [HookIndexEntry ]];
671- converters: seq [(nifstreams.SymId , nifstreams.SymId )];
686+ opsLog: seq [LogEntry ];
672687 classes: seq [ClassIndexEntry ];
673688 replayActions: seq [PNode ] = @ []) =
674689 var w = Writer (infos: LineInfoWriter (config: config), currentModule: thisModule)
@@ -702,17 +717,9 @@ proc writeNifModule*(config: ConfigRef; thisModule: int32; n: PNode;
702717
703718 # Build index with export, hook, converter, and method information
704719 let exportBuf = buildExportBuf (w)
705- createIndex (d, dest[0 ].info, false ,
706- IndexSections (hooks: hooks, converters: converters, classes: classes, exportBuf: exportBuf))
707-
708- # Don't unload symbols/types yet - they may be needed by other modules that haven't
709- # had their NIF files written. For recursive module dependencies (like system.nim),
710- # we need all NIFs to exist before we can safely unload and reload.
711- # TODO : Implement deferred unloading at end of compilation for memory savings.
712- # for typ in w.writtenTypes:
713- # forcePartial(typ)
714- # for sym in w.writtenSyms:
715- # forcePartial(sym)
720+ var sections = translateOpsLog (w, opsLog)
721+ sections.exportBuf = exportBuf
722+ createIndex (d, dest[0 ].info, false , sections)
716723
717724
718725# --------------------------- Loader (lazy!) -----------------------------------------------
@@ -1443,8 +1450,7 @@ proc tryResolveCompilerProc*(c: var DecodeContext; name: string; moduleFileIdx:
14431450 result = resolveSym (c, symName, true )
14441451
14451452proc loadNifModule * (c: var DecodeContext ; f: FileIndex ; interf, interfHidden: var TStrTable ;
1446- hooks: var Table [nifstreams.SymId , HooksPerType ];
1447- converters: var seq [(string , string )];
1453+ logOps: var seq [LogEntry ];
14481454 classes: var seq [ClassIndexEntry ];
14491455 loadFullAst: bool = false ): PNode =
14501456 let suffix = moduleSuffix (c.infos.config, f)
0 commit comments