system.nim: refactoring that removes cyclic dependencies in prep for IC

This commit is contained in:
araq
2025-11-18 17:06:52 +01:00
parent c308363015
commit fff0201c5f
7 changed files with 182 additions and 130 deletions

View File

@@ -19,12 +19,16 @@ import std/private/miscdollars
type InstantiationInfo = tuple[filename: string, line: int, column: int]
{.push overflowChecks: off, rangeChecks: off.}
proc `$`(info: InstantiationInfo): string =
# The +1 is needed here
# instead of overriding `$` (and changing its meaning), consider explicit name.
result = ""
result.toLocation(info.filename, info.line, info.column + 1)
{.pop.}
# ---------------------------------------------------------------------------

View File

@@ -4,7 +4,13 @@ template toLocation*(result: var string, file: string | cstring, line: int, col:
## avoids spurious allocations
# Hopefully this can be re-used everywhere so that if a user needs to customize,
# it can be done in a single place.
result.add file
when file is cstring:
var i = 0
while file[i] != '\0':
add(result, file[i])
inc i
else:
result.add file
if line > 0:
result.add "("
addInt(result, line)