如何创建不添加堆栈跟踪的发出宏?
import macros
macro emitWithoutStacktrace(): stmt =
result = newStmtList()
result.add quote do:
{.push stacktrace: off.}
result.add(newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(newIdentNode("emit"), newStrLitNode("foobar"))))
result.add quote do:
{.pop stacktrace: off.}
proc main =
emitWithoutStacktrace()
main()
生产
N_NIMCALL(void, main_104042)(void) {
nimfr("main", "test.nim")
nimln(7, "test.nim");
foobar
popFrame();
}
我更喜欢的地方
N_NIMCALL(void, main_104042)(void) {
foobar
popFrame();
}
没有任何额外的编译器参数,如--stacktrace: off
.