Add push raises to shims/macros module (#212)
This commit is contained in:
parent
3aa92ab843
commit
5a792e762f
|
@ -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.}
|
||||||
|
|
Loading…
Reference in New Issue