Skip to content

Commit

Permalink
Add push raises to shims/macros module
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Feb 12, 2024
1 parent 3aa92ab commit a9ceabc
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions stew/shims/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type
const
nnkPragmaCallKinds = {nnkExprColonExpr, nnkCall, nnkCallStrLit}

{.push raises: [].}

proc hash*(x: LineInfo): Hash =
!$(hash(x.filename) !& hash(x.line) !& hash(x.column))

Expand All @@ -26,7 +28,7 @@ var
macroLocations {.compileTime.} = newSeq[LineInfo]()
macroOutputs {.compileTime.} = newSeq[NimNode]()

proc writeMacroResultsNow* {.compileTime.} =
proc writeMacroResultsNow* {.compileTime, raises: [IOError].} =
var files = initTable[string, NimNode]()

proc addToFile(file: var NimNode, location: LineInfo, macroOutput: NimNode) =
Expand All @@ -47,19 +49,22 @@ proc writeMacroResultsNow* {.compileTime.} =

proc storeMacroResult*(callSite: LineInfo,
macroResult: NimNode,
writeOutputImmediately = false) =
writeOutputImmediately = false) {.raises: [IOError].} =
macroLocations.add callSite
macroOutputs.add macroResult
if writeOutputImmediately:
# echo macroResult.repr
writeMacroResultsNow()

proc storeMacroResult*(macroResult: NimNode, writeOutputImmediately = false) =
proc storeMacroResult*(macroResult: NimNode, writeOutputImmediately = false) {.raises: [IOError].} =
let usageSite = callsite().lineInfoObj
storeMacroResult(usageSite, macroResult, writeOutputImmediately)

macro dumpMacroResults*: untyped =
writeMacroResultsNow()
try:
writeMacroResultsNow()
except IOError as exc:
doAssert(false, exc.msg)

proc findPragma*(pragmas: NimNode, pragmaSym: NimNode): NimNode =
for p in pragmas:
Expand Down Expand Up @@ -449,3 +454,5 @@ template genStmtList*(body: untyped) =
template genSimpleExpr*(body: untyped): untyped =
macro payload: untyped = body
payload()

{.pop.}

0 comments on commit a9ceabc

Please sign in to comment.