Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
d72b00cf15
3 changed files with 34 additions and 1 deletions
|
|
@ -209,6 +209,17 @@ proc getAst*(macroOrTemplate: expr): expr {.magic: "ExpandToAst".}
|
||||||
## macro FooMacro() =
|
## macro FooMacro() =
|
||||||
## var ast = getAst(BarTemplate())
|
## var ast = getAst(BarTemplate())
|
||||||
|
|
||||||
|
template emit*(s: expr): stmt =
|
||||||
|
## accepts a single sting argument and treats it as nimrod code
|
||||||
|
## that should be inserted verbatim in the program
|
||||||
|
## Example:
|
||||||
|
##
|
||||||
|
## emit("echo " & '"' & "hello world".toUpper & '"')
|
||||||
|
##
|
||||||
|
block:
|
||||||
|
const evaluated = s
|
||||||
|
eval: result = evaluated.parseStmt
|
||||||
|
|
||||||
proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} =
|
proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} =
|
||||||
## checks that `n` is of kind `k`. If this is not the case,
|
## checks that `n` is of kind `k`. If this is not the case,
|
||||||
## compilation aborts with an error message. This is useful for writing
|
## compilation aborts with an error message. This is useful for writing
|
||||||
|
|
|
||||||
|
|
@ -2213,6 +2213,20 @@ proc shallow*(s: var string) {.noSideEffect, inline.} =
|
||||||
var s = cast[PGenericSeq](s)
|
var s = cast[PGenericSeq](s)
|
||||||
s.reserved = s.reserved or seqShallowFlag
|
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):
|
when defined(initDebugger):
|
||||||
initDebugger()
|
initDebugger()
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,14 @@ Library Additions
|
||||||
- Added ``system.shallow`` that can be used to speed up string and sequence
|
- Added ``system.shallow`` that can be used to speed up string and sequence
|
||||||
assignments.
|
assignments.
|
||||||
|
|
||||||
|
- Added ``system.static`` that can force compile-time evaluation of certain
|
||||||
|
expressions
|
||||||
|
|
||||||
|
- Added ``system.eval`` that can execute an anonymous block of code at
|
||||||
|
compile time as if was a macro
|
||||||
|
|
||||||
|
- Added ``macros.emit`` that can emit an arbitrary computed string as nimrod
|
||||||
|
code during compilation
|
||||||
|
|
||||||
2012-02-09 Version 0.8.14 released
|
2012-02-09 Version 0.8.14 released
|
||||||
==================================
|
==================================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue