Skip to content

Commit

Permalink
fixes #545 (#560)
Browse files Browse the repository at this point in the history
* fixes #545

* make tests green again
  • Loading branch information
Araq authored Feb 15, 2025
1 parent bdcc890 commit c7dc817
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/hastur.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import std / [syncio, assertions, parseopt, strutils, times, os, osproc, algorithm]

import lib / nifindexes
import lib / [nifindexes, lineinfos]
import gear2 / modnames

const
Expand Down Expand Up @@ -394,8 +394,8 @@ proc nifctests(overwrite: bool) =
proc hexertests(overwrite: bool) =
let mod1 = "tests/hexer/mod1"
let helloworld = "tests/hexer/hexer_helloworld"
createIndex helloworld & ".nif", false
createIndex mod1 & ".nif", false
createIndex helloworld & ".nif", false, NoLineInfo
createIndex mod1 & ".nif", false, NoLineInfo
execHexer mod1 & ".nif"
execHexer helloworld & ".nif"
execNifc " c -r " & mod1 & ".c.nif " & helloworld & ".c.nif"
Expand Down
20 changes: 10 additions & 10 deletions src/lib/nifindexes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ proc getSymbolSection(tag: TagId; values: seq[(SymId, SymId)]): TokenBuf =

result.addParRi()

proc createIndex*(infile: string; buildChecksum: bool; sections: IndexSections) =
proc createIndex*(infile: string; root: PackedLineInfo; buildChecksum: bool; sections: IndexSections) =
let indexName = changeFileExt(infile, ".idx.nif")

var s = nifstreams.open(infile)
Expand All @@ -142,8 +142,8 @@ proc createIndex*(infile: string; buildChecksum: bool; sections: IndexSections)

var public = createTokenBuf(30)
var private = createTokenBuf(30)
public.addParLe TagId(PublicIdx)
private.addParLe TagId(PrivateIdx)
public.addParLe TagId(PublicIdx), root
private.addParLe TagId(PrivateIdx), root
var buf = createTokenBuf(100)
var symToOffsetMap = initTable[SymId, int]()

Expand All @@ -155,7 +155,7 @@ proc createIndex*(infile: string; buildChecksum: bool; sections: IndexSections)
if t.kind == ParLe:
target = offs
elif t.kind == SymbolDef:
let info = t.info
#let info = t.info
let sym = t.symId
if pool.syms[sym].isImportant:
let tb = next(s)
Expand All @@ -169,7 +169,7 @@ proc createIndex*(infile: string; buildChecksum: bool; sections: IndexSections)
symToOffsetMap[sym] = target
let diff = if isPublic: target - previousPublicTarget
else: target - previousPrivateTarget
dest[].buildTree TagId(KvIdx), info:
dest[].buildTree TagId(KvIdx), NoLineInfo:
dest[].add symToken(sym, NoLineInfo)
dest[].add intToken(pool.integers.getOrIncl(diff), NoLineInfo)
if isPublic:
Expand Down Expand Up @@ -200,9 +200,8 @@ proc createIndex*(infile: string; buildChecksum: bool; sections: IndexSections)
content.add toString(converterSectionBuf)
content.add "\n"

let buildT = registerTag "build"
var buildBuf = createTokenBuf()
buildBuf.addParLe buildT
buildBuf.addParLe TagId(BuildIdx)
buildBuf.add sections.toBuild
buildBuf.addParRi
content.add toString(buildBuf)
Expand All @@ -219,8 +218,9 @@ proc createIndex*(infile: string; buildChecksum: bool; sections: IndexSections)
else:
writeFile(indexName, content)

proc createIndex*(infile: string; buildChecksum: bool) =
createIndex(infile, buildChecksum, IndexSections(hooks: initTable[string, seq[(SymId, SymId)]](), toBuild: default(TokenBuf)))
proc createIndex*(infile: string; buildChecksum: bool; root: PackedLineInfo) =
createIndex(infile, root, buildChecksum,
IndexSections(hooks: initTable[string, seq[(SymId, SymId)]](), toBuild: default(TokenBuf)))

type
NifIndexEntry* = object
Expand Down Expand Up @@ -365,4 +365,4 @@ proc readIndex*(indexName: string): NifIndex =
assert false, "expected 'index' tag"

when isMainModule:
createIndex paramStr(1), false
createIndex paramStr(1), false, NoLineInfo
3 changes: 2 additions & 1 deletion src/nimony/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5471,7 +5471,8 @@ proc writeOutput(c: var SemContext; outfile: string) =
#b.addRaw toString(c.dest)
#b.close()
writeFile outfile, "(.nif24)\n" & toString(c.dest)
createIndex outfile, true, IndexSections(hooks: c.hookIndexMap, converters: c.converterIndexMap, toBuild: c.toBuild)
let root = c.dest[0].info
createIndex outfile, root, true, IndexSections(hooks: c.hookIndexMap, converters: c.converterIndexMap, toBuild: c.toBuild)

proc phaseX(c: var SemContext; n: Cursor; x: SemPhase): TokenBuf =
assert n == "stmts"
Expand Down
4 changes: 2 additions & 2 deletions tests/nimony/nosystem/timportfromexcept.nif
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
(.nif24)
0,1,tests/nimony/nosystem/timportfromexcept.nim(stmts 4,4
(let :allImported.0.timhjtr28 . .
(array 15,3,tests/nimony/nosystem/deps/modexcept.nim
(array 11,2,tests/nimony/nosystem/deps/modexcept.nim
(i -1)
(rangetype
(i -1) +0 +2)) 14
(aconstr ~14
(array 15,3,tests/nimony/nosystem/deps/modexcept.nim
(array 11,2,tests/nimony/nosystem/deps/modexcept.nim
(i -1)
(rangetype
(i -1) +0 +2)) 1 exceptB.0.modvx9hpf 10 fromA.0.modepjal 17 fromC.0.modepjal)) 4,5
Expand Down
10 changes: 5 additions & 5 deletions tests/nimony/sysbasics/tbasics.nif
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@
(dot ~1 x.1 a.0.tbawx6nu81 +0)))) 4,42
(var :a.1.tbawx6nu81 . . 12,~3 Foo1314.0.tbawx6nu81 11
(oconstr 1,~3 Foo1314.0.tbawx6nu81
(kv a.0.tbawx6nu81 52,841,lib/std/system.nim
(kv a.0.tbawx6nu81 43,421,lib/std/system.nim
(expr
(expr +0)))
(kv b.0.tbawx6nu81 52,841,lib/std/system.nim
(kv b.0.tbawx6nu81 43,421,lib/std/system.nim
(expr
(expr +0)))
(kv c.0.tbawx6nu81 52,841,lib/std/system.nim
(kv c.0.tbawx6nu81 43,421,lib/std/system.nim
(expr
(expr +0)))
(kv d.0.tbawx6nu81 52,841,lib/std/system.nim
(kv d.0.tbawx6nu81 43,421,lib/std/system.nim
(expr
(expr +0)))
(kv e.0.tbawx6nu81 52,841,lib/std/system.nim
(kv e.0.tbawx6nu81 43,421,lib/std/system.nim
(expr
(expr +0))))) 7,43
(call ~7 foo1314.0.tbawx6nu81 1 a.1.tbawx6nu81))
4 changes: 2 additions & 2 deletions tests/nimony/sysbasics/tconstarrlen.nif
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
(i -1) +0 +99)) .) ,7
(if 3
(elif 6
(eq 24,603,lib/std/system.nim
(i +64) 11,940,lib/std/system.nim
(eq 15,134,lib/std/system.nim
(i +64) 2,471,lib/std/system.nim
(expr
(expr ,~4
(expr
Expand Down
14 changes: 7 additions & 7 deletions tests/nimony/sysbasics/tforloops1.nif
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(mul
(i -1) ~1 i.0 1 i.0)) ,2
(yld 9
(mul 20,279,lib/std/system.nim
(mul 15,140,lib/std/system.nim
(i +64) ~2
(mul
(i -1) ~1 i.0 1 i.0) 1 i.0)) 2,3
Expand Down Expand Up @@ -75,7 +75,7 @@
(hconv 11,~16
(cstring) "countup start\3A %ld\0A") 25 m.1) ,2
(if 3
(elif 11,830,lib/std/system.nim
(elif 2,416,lib/std/system.nim
(expr 2,1
(lt
(i -1) 9,26,tests/nimony/sysbasics/tforloops1.nim +5 5,26,tests/nimony/sysbasics/tforloops1.nim x.1)) ~1,1
Expand Down Expand Up @@ -121,7 +121,7 @@
(mul ~1,~9
(i -1) ~1 i.4 1 i.4)) ,2
(yld 9
(mul 20,279,lib/std/system.nim
(mul 15,140,lib/std/system.nim
(i +64) ~2
(mul ~1,~10
(i -1) ~1 i.4 1 i.4) 1 i.4)))))) 4,43
Expand Down Expand Up @@ -171,15 +171,15 @@
(cstring) "Hello, world\3A %ld\0A") 25
(add ~25,~6
(i -1) ~1 m.2 1 n.3)))))) 4,20
(proc :inc.0.tfo6yv57p . 5,551,lib/std/system.nim .
(proc :inc.0.tfo6yv57p . 0,276,lib/std/system.nim .
(at inc.1.sys9azlf 19,~4
(i -1)) 26,551,lib/std/system.nim
(i -1)) 21,276,lib/std/system.nim
(params 1
(param :x.2 . . 3
(mut 23,17,tests/nimony/sysbasics/tforloops1.nim
(i -1)) .)) 5,551,lib/std/system.nim . 37,551,lib/std/system.nim
(i -1)) .)) 0,276,lib/std/system.nim . 32,276,lib/std/system.nim
(pragmas 2
(inline)) 5,551,lib/std/system.nim . 7,553,lib/std/system.nim
(inline)) 0,276,lib/std/system.nim . 2,278,lib/std/system.nim
(stmts 2
(asgn ~2
(hderef x.2) 4
Expand Down
12 changes: 6 additions & 6 deletions tests/nimony/sysbasics/tintlitmatch.nif
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
(discard 10
(eq ~3,~4
(i +32) ~2
(hconv 22,685,lib/std/system.nim
(hconv 17,343,lib/std/system.nim
(i +64) x.0.tin4pj0od1) 3 y.0.tin4pj0od1)) ,14
(discard 10
(eq ~3,~4
(i -1) ~2 y.0.tin4pj0od1 6
(hconv 22,685,lib/std/system.nim
(hconv 17,343,lib/std/system.nim
(i +64)
(conv 1
(i +32) ~3 +123)))) ,15
(discard 18
(eq ~1,~1
(i +32) ~7
(hconv 22,685,lib/std/system.nim
(hconv 17,343,lib/std/system.nim
(i +64)
(conv 6,~1
(i +32) ~3 +123)) 3 y.0.tin4pj0od1)) ,16
Expand All @@ -73,17 +73,17 @@
(i +32) ~7
(conv 6,~6
(i +32) ~3 +123) 3
(hconv 22,683,lib/std/system.nim
(hconv 17,342,lib/std/system.nim
(i +32) +123))) ,21
(discard 12
(eq
(i -1) ~4
(hconv 22,683,lib/std/system.nim
(hconv 17,342,lib/std/system.nim
(i +32) +123) 6
(conv ~1,~7
(i +32) ~3 +123))) ,22
(discard 10
(eq ~3,~13
(i +32) ~2 x.0.tin4pj0od1 3
(hconv 22,683,lib/std/system.nim
(hconv 17,342,lib/std/system.nim
(i +32) +123))))

0 comments on commit c7dc817

Please sign in to comment.