From 6e3d1dced55229309a85849a45c877a798080453 Mon Sep 17 00:00:00 2001 From: andri lim Date: Mon, 6 Aug 2018 04:38:21 +0700 Subject: fixes #5617, 'copyLineInfo' addition (#8523) --- tests/macros/tlineinfo.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tests/macros/tlineinfo.nim (limited to 'tests/macros') diff --git a/tests/macros/tlineinfo.nim b/tests/macros/tlineinfo.nim new file mode 100644 index 000000000..2ab0e1ee8 --- /dev/null +++ b/tests/macros/tlineinfo.nim @@ -0,0 +1,14 @@ +# issue #5617, feature request +# Ability to set a NimNode's lineinfo +import macros + +type + Test = object + +macro mixer(n: typed): untyped = + let x = newIdentNode("echo") + x.copyLineInfo(n) + result = newLit(x.lineInfo == n.lineInfo) + +var z = mixer(Test) +doAssert z -- cgit 1.4.1-2-gfad0 From da41fc18018058e01ac11132f7ff29651e3fdaa7 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 15 Aug 2018 17:45:57 +0200 Subject: put the new for loop macros under an experimental switch named 'forLoopMacros' --- compiler/options.nim | 6 ++++-- compiler/semstmts.nim | 5 +++-- doc/manual.rst | 5 +++++ tests/macros/tforloop_macro1.nim | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) (limited to 'tests/macros') diff --git a/compiler/options.nim b/compiler/options.nim index 6de32bfad..bc5545488 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -111,14 +111,16 @@ type ideNone, ideSug, ideCon, ideDef, ideUse, ideDus, ideChk, ideMod, ideHighlight, ideOutline, ideKnown, ideMsg - Feature* = enum ## experimental features + Feature* = enum ## experimental features; DO NOT RENAME THESE! implicitDeref, dotOperators, callOperator, parallel, destructor, notnil, - dynamicBindSym + dynamicBindSym, + forLoopMacros + #caseStmtMacros SymbolFilesOption* = enum disabledSf, writeOnlySf, readOnlySf, v2Sf diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index b1e39d2db..7eb915dad 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -720,8 +720,9 @@ proc handleForLoopMacro(c: PContext; n: PNode): PNode = proc semFor(c: PContext, n: PNode): PNode = checkMinSonsLen(n, 3, c.config) var length = sonsLen(n) - result = handleForLoopMacro(c, n) - if result != nil: return result + if forLoopMacros in c.features: + result = handleForLoopMacro(c, n) + if result != nil: return result openScope(c) result = n n.sons[length-2] = semExprNoDeref(c, n.sons[length-2], {efWantIterator}) diff --git a/doc/manual.rst b/doc/manual.rst index db610f8f8..935db34ac 100644 --- a/doc/manual.rst +++ b/doc/manual.rst @@ -5380,6 +5380,7 @@ type ``system.ForLoopStmt`` can rewrite the entirety of a ``for`` loop: :test: "nim c $1" import macros + {.experimental: "forLoopMacros".} macro enumerate(x: ForLoopStmt): untyped = expectKind x, nnkForStmt @@ -5406,6 +5407,10 @@ type ``system.ForLoopStmt`` can rewrite the entirety of a ``for`` loop: echo a2, " ", b2 +Currently for loop macros must be enabled explicitly +via ``{.experimental: "forLoopMacros".}``. + + Special Types ============= diff --git a/tests/macros/tforloop_macro1.nim b/tests/macros/tforloop_macro1.nim index a8f45c7ac..49918563d 100644 --- a/tests/macros/tforloop_macro1.nim +++ b/tests/macros/tforloop_macro1.nim @@ -12,7 +12,7 @@ discard """ """ import macros - +{.experimental: "forLoopMacros".} macro mymacro(): untyped = result = newLit([1, 2, 3]) -- cgit 1.4.1-2-gfad0