Add push raises to shims/macros module (#212)

This commit is contained in:
andri lim 2024-02-12 12:20:12 +07:00 committed by GitHub
parent 3aa92ab843
commit 5a792e762f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 4 deletions

View File

@ -17,6 +17,8 @@ type
const const
nnkPragmaCallKinds = {nnkExprColonExpr, nnkCall, nnkCallStrLit} nnkPragmaCallKinds = {nnkExprColonExpr, nnkCall, nnkCallStrLit}
{.push raises: [].}
proc hash*(x: LineInfo): Hash = proc hash*(x: LineInfo): Hash =
!$(hash(x.filename) !& hash(x.line) !& hash(x.column)) !$(hash(x.filename) !& hash(x.line) !& hash(x.column))
@ -26,7 +28,7 @@ var
macroLocations {.compileTime.} = newSeq[LineInfo]() macroLocations {.compileTime.} = newSeq[LineInfo]()
macroOutputs {.compileTime.} = newSeq[NimNode]() macroOutputs {.compileTime.} = newSeq[NimNode]()
proc writeMacroResultsNow* {.compileTime.} = proc writeMacroResultsNow* {.compileTime, raises: [IOError].} =
var files = initTable[string, NimNode]() var files = initTable[string, NimNode]()
proc addToFile(file: var NimNode, location: LineInfo, macroOutput: NimNode) = proc addToFile(file: var NimNode, location: LineInfo, macroOutput: NimNode) =
@ -47,19 +49,22 @@ proc writeMacroResultsNow* {.compileTime.} =
proc storeMacroResult*(callSite: LineInfo, proc storeMacroResult*(callSite: LineInfo,
macroResult: NimNode, macroResult: NimNode,
writeOutputImmediately = false) = writeOutputImmediately = false) {.raises: [IOError].} =
macroLocations.add callSite macroLocations.add callSite
macroOutputs.add macroResult macroOutputs.add macroResult
if writeOutputImmediately: if writeOutputImmediately:
# echo macroResult.repr # echo macroResult.repr
writeMacroResultsNow() writeMacroResultsNow()
proc storeMacroResult*(macroResult: NimNode, writeOutputImmediately = false) = proc storeMacroResult*(macroResult: NimNode, writeOutputImmediately = false) {.raises: [IOError].} =
let usageSite = callsite().lineInfoObj let usageSite = callsite().lineInfoObj
storeMacroResult(usageSite, macroResult, writeOutputImmediately) storeMacroResult(usageSite, macroResult, writeOutputImmediately)
macro dumpMacroResults*: untyped = macro dumpMacroResults*: untyped =
writeMacroResultsNow() try:
writeMacroResultsNow()
except IOError as exc:
doAssert(false, exc.msg)
proc findPragma*(pragmas: NimNode, pragmaSym: NimNode): NimNode = proc findPragma*(pragmas: NimNode, pragmaSym: NimNode): NimNode =
for p in pragmas: for p in pragmas:
@ -449,3 +454,5 @@ template genStmtList*(body: untyped) =
template genSimpleExpr*(body: untyped): untyped = template genSimpleExpr*(body: untyped): untyped =
macro payload: untyped = body macro payload: untyped = body
payload() payload()
{.pop.}