Skip to content

Commit

Permalink
implementgs readIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Jan 7, 2025
1 parent 5cbd1f5 commit 9069839
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 20 additions & 3 deletions src/lib/nifindexes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Create an index file for a NIF file.

import std / [os, tables, assertions, syncio, formatfloat]
import std / [os, tables, assertions, syncio, formatfloat, sets]

Check warning on line 9 in src/lib/nifindexes.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-nim-devel (master)

imported and not used: 'formatfloat' [UnusedImport]

Check warning on line 9 in src/lib/nifindexes.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-nim-devel (master)

imported and not used: 'formatfloat' [UnusedImport]

Check warning on line 9 in src/lib/nifindexes.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-nim-devel (master)

imported and not used: 'formatfloat' [UnusedImport]

Check warning on line 9 in src/lib/nifindexes.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-nim-devel (master)

imported and not used: 'formatfloat' [UnusedImport]

Check warning on line 9 in src/lib/nifindexes.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

imported and not used: 'formatfloat' [UnusedImport]

Check warning on line 9 in src/lib/nifindexes.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

imported and not used: 'formatfloat' [UnusedImport]
import bitabs, lineinfos, nifreader, nifstreams, nifcursors, nifchecksums

#import std / [sha1]
Expand Down Expand Up @@ -197,8 +197,9 @@ type
info*: PackedLineInfo
NifIndex* = object
public*, private*: Table[string, NifIndexEntry]
hooks*: Table[string, Table[string, NifIndexEntry]]

proc readSection(s: var Stream; tab: var Table[string, NifIndexEntry]) =
proc readSection(s: var Stream; tab: var Table[string, NifIndexEntry]; useAbsoluteOffset = false) =
let KvT = registerTag "kv"
var previousOffset = 0
var t = next(s)
Expand All @@ -220,7 +221,8 @@ proc readSection(s: var Stream; tab: var Table[string, NifIndexEntry]) =
if t.kind == IntLit:
let offset = pool.integers[t.intId] + previousOffset
tab[key] = NifIndexEntry(offset: offset, info: info)
previousOffset = offset
if not useAbsoluteOffset:
previousOffset = offset
else:
assert false, "invalid (kv) construct: IntLit expected"
t = next(s) # skip offset
Expand Down Expand Up @@ -249,6 +251,14 @@ proc readIndex*(indexName: string): NifIndex =
let PrivateT = registerTag "private"
let IndexT = registerTag "index"

let ClonerT = registerTag "cloner"
let TracerT = registerTag "tracer"
let DisarmerT = registerTag "disarmer"
let MoverT = registerTag "mover"
let DtorT = registerTag "dtor"

let hookSet = toHashSet([ClonerT, TracerT, DisarmerT, MoverT, DtorT])

result = default(NifIndex)
var t = next(s)
if t.tag == IndexT:
Expand All @@ -262,6 +272,13 @@ proc readIndex*(indexName: string): NifIndex =
readSection s, result.private
else:
assert false, "'private' expected"
t = next(s)
while t.tag in hookSet:
let tagName = pool.tags[t.tag]
result.hooks[tagName] = initTable[string, NifIndexEntry]()
readSection(s, result.hooks[tagName])
t = next(s)

else:
assert false, "expected 'index' tag"

Expand Down
5 changes: 1 addition & 4 deletions src/nimony/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2659,10 +2659,7 @@ proc checkTypeHook(c: var SemContext; params: seq[TypeCursor]; op: HookOp; info:
buildErr c, info, "signature for '=sink' must be proc[T: object](x: var T; y: T)"

proc expandHook(c: var SemContext; obj: SymId, symId: SymId, op: HookOp) =
if $op in c.hookIndexMap:
c.hookIndexMap[$op].add (obj, symId)
else:
c.hookIndexMap[$op] = @[(obj, symId)]
c.hookIndexMap.mgetOrPut($op, @[]).add (obj, symId)

proc getHookName(symId: SymId): string =
result = pool.syms[symId]
Expand Down

0 comments on commit 9069839

Please sign in to comment.