helper templates static, eval and emit for easier compile-time code evaluation
This commit is contained in:
parent
96e7ee91cc
commit
a3f16968a7
3 changed files with 34 additions and 1 deletions
|
|
@ -2213,6 +2213,20 @@ proc shallow*(s: var string) {.noSideEffect, inline.} =
|
|||
var s = cast[PGenericSeq](s)
|
||||
s.reserved = s.reserved or seqShallowFlag
|
||||
|
||||
template static*(e: expr): expr =
|
||||
## evaluates a given expression `e` at compile-time
|
||||
## even if it has side effects
|
||||
block:
|
||||
const res = e
|
||||
res
|
||||
|
||||
template eval*(blk: stmt): stmt =
|
||||
## executes a block of code at compile time just as if it was a macro
|
||||
## optonally, the block can return an AST tree that will replace the
|
||||
## eval expression
|
||||
block:
|
||||
macro payload(x: stmt): stmt = blk
|
||||
payload()
|
||||
|
||||
when defined(initDebugger):
|
||||
initDebugger()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue