Skip to content

Commit

Permalink
put the new for loop macros under an experimental switch named 'forLo…
Browse files Browse the repository at this point in the history
…opMacros'
  • Loading branch information
Araq committed Aug 15, 2018
1 parent 27e1fbe commit da41fc1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
5 changes: 5 additions & 0 deletions doc/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
=============

Expand Down
2 changes: 1 addition & 1 deletion tests/macros/tforloop_macro1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ discard """
"""

import macros

{.experimental: "forLoopMacros".}
macro mymacro(): untyped =
result = newLit([1, 2, 3])

Expand Down

0 comments on commit da41fc1

Please sign in to comment.