Skip to content

Commit e92090e

Browse files
committed
simplify: do:=>:
1 parent 78be6a2 commit e92090e

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lib/core/macros.nim

+2-2
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ macro genAst*(options: static set[GenAstOpt] = {}, args: varargs[untyped]): unty
13711371
let xignoredLocal = kfoo4
13721372
proc localExposed(): auto = kfoo4 # implicitly captured
13731373
let x3 = newLit kfoo4
1374-
result = genAst({}, s1=2, s2="asdf", x0=newLit x0, x1=x1, x2, x3) do:
1374+
result = genAst({}, s1=2, s2="asdf", x0=newLit x0, x1=x1, x2, x3):
13751375
# echo xignored # would give: Error: undeclared identifier
13761376
# echo s0 # would give: Error: internal error: expr: var not init s0_237159
13771377
(s1, s2, x0, x1, x2, x3, localExposed())
@@ -1381,7 +1381,7 @@ macro genAst*(options: static set[GenAstOpt] = {}, args: varargs[untyped]): unty
13811381
let s1 = "not captured!" ## does not override `s1=2`
13821382
let xignoredLocal = kfoo4
13831383
let x3 = newLit kfoo4
1384-
result = genAst({kNoExposeLocalInjects}, s1=2, s2="asdf", x0=newLit x0, x1=x1, x2, x3) do:
1384+
result = genAst({kNoExposeLocalInjects}, s1=2, s2="asdf", x0=newLit x0, x1=x1, x2, x3):
13851385
## only captures variables from `genAst` argument list
13861386
## uncaptured variables will be set from caller scope (Eg `s0`)
13871387
## `x2` is shortcut for the common `x2=x2`

tests/macros/mgenast.nim

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ type Foo* = enum kfoo0, kfoo1, kfoo2, kfoo3, kfoo4
88
proc myLocalPriv(): auto = kfoo1
99
proc myLocalPriv2(): auto = kfoo1
1010
macro bindme2*(): untyped =
11-
genAst({}) do: myLocalPriv()
11+
genAst({}): myLocalPriv()
1212
macro bindme3*(): untyped =
1313
## myLocalPriv must be captured explicitly
14-
genAst({kNoExposeLocalInjects}, myLocalPriv) do: myLocalPriv()
14+
genAst({kNoExposeLocalInjects}, myLocalPriv): myLocalPriv()
1515

1616
macro bindme4*(): untyped =
1717
## calling this won't compile because `myLocalPriv` isn't captured
18-
genAst({kNoExposeLocalInjects}) do: myLocalPriv()
18+
genAst({kNoExposeLocalInjects}): myLocalPriv()
1919

2020
macro bindme5UseExpose*(): untyped =
21-
genAst({}) do: myLocalPriv2()
21+
genAst({}): myLocalPriv2()
2222

2323
macro bindme5UseExposeFalse*(): untyped =
24-
genAst({kNoExposeLocalInjects}) do: myLocalPriv2()
24+
genAst({kNoExposeLocalInjects}): myLocalPriv2()
2525

2626
## example from https://github.com/nim-lang/Nim/issues/7889
2727
from std/streams import newStringStream, readData, writeData
2828

2929
macro bindme6UseExpose*(): untyped =
30-
genAst({}) do:
30+
genAst({}):
3131
var tst = "sometext"
3232
var ss = newStringStream("anothertext")
3333
writeData(ss, tst[0].addr, 2)
@@ -36,7 +36,7 @@ macro bindme6UseExpose*(): untyped =
3636
macro bindme6UseExposeFalse*(): untyped =
3737
## without kexposeLocalInjects, requires passing all referenced symbols
3838
## which can be tedious
39-
genAst({kNoExposeLocalInjects}, newStringStream, writeData, readData) do:
39+
genAst({kNoExposeLocalInjects}, newStringStream, writeData, readData):
4040
var tst = "sometext"
4141
var ss = newStringStream("anothertext")
4242
writeData(ss, tst[0].addr, 2)

tests/macros/tgenast.nim

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ block:
88
let s1 = "not captured!"
99
let xignoredLocal = kfoo4
1010
let x3 = newLit kfoo4
11-
result = genAst({kNoExposeLocalInjects}, s1=2, s2="asdf", x0=newLit x0, x1=x1, x2, x3) do:
11+
result = genAst({kNoExposeLocalInjects}, s1=2, s2="asdf", x0=newLit x0, x1=x1, x2, x3):
1212
doAssert not declared(xignored)
1313
doAssert not declared(xignoredLocal)
1414
(s1, s2, s0, x0, x1, x2, x3)
@@ -36,7 +36,7 @@ block:
3636

3737
macro m1(): untyped =
3838
# result = quote do: # Error: undeclared identifier: 'a1'
39-
result = genAst({}) do:
39+
result = genAst({}):
4040
template `a1=`(x: var Foo, val: int) =
4141
x.a = val
4242

@@ -51,7 +51,7 @@ block:
5151
result = newStmtList()
5252
macro foo(c: bool): untyped =
5353
var b = false
54-
result = genAst({}, b = newLit b, c) do:
54+
result = genAst({}, b = newLit b, c):
5555
fun(b, c)
5656

5757
foo(true)
@@ -61,15 +61,15 @@ block:
6161
# since `==` works with genAst, the problem goes away
6262
macro foo2(): untyped =
6363
# result = quote do: # Error: '==' cannot be passed to a procvar
64-
result = genAst({}) do:
64+
result = genAst({}):
6565
`==`(3,4)
6666
doAssert not foo2()
6767

6868
block:
6969
# fix https://github.com/nim-lang/Nim/issues/7726
7070
macro foo(): untyped =
7171
let a = @[1, 2, 3, 4, 5]
72-
result = genAst({}, a, b = a.len) do: # shows 2 ways to get a.len
72+
result = genAst({}, a, b = a.len): # shows 2 ways to get a.len
7373
(a.len, b)
7474
doAssert foo() == (5, 5)
7575

@@ -82,15 +82,15 @@ block:
8282
let info = args.lineInfoObj
8383
let fun1 = bindSym"fun1" # optional; we can remove this and also the
8484
# capture of fun1
85-
result = genAst({}, info = newLit info, fun1) do:
85+
result = genAst({}, info = newLit info, fun1):
8686
(fun1(info), fun2(info.line))
8787
doAssert bar2() == ("bar1", "bar2")
8888

8989
macro bar(args: varargs[untyped]): untyped =
9090
let info = args.lineInfoObj
9191
let fun1 = bindSym"fun1"
9292
let fun2 = bindSym"fun2"
93-
result = genAst({kNoExposeLocalInjects}, info = newLit info) do:
93+
result = genAst({kNoExposeLocalInjects}, info = newLit info):
9494
(fun1(info), fun2(info.line))
9595
doAssert bar() == ("bar1", "bar2")
9696

@@ -118,7 +118,7 @@ block:
118118

119119
proc funLocal(): auto = kfoo4
120120

121-
result = genAst({}, x1=newLit x1, x2, x3, x4 = newLit x4) do:
121+
result = genAst({}, x1=newLit x1, x2, x3, x4 = newLit x4):
122122
# local x1 overrides remote x1
123123
when false:
124124
# one advantage of using `kNoExposeLocalInjects` is that these would hold:
@@ -149,7 +149,7 @@ block:
149149
# fix https://github.com/nim-lang/Nim/issues/8220
150150
macro foo(): untyped =
151151
# kNoExposeLocalInjects needed here
152-
result = genAst({kNoExposeLocalInjects}) do:
152+
result = genAst({kNoExposeLocalInjects}):
153153
let bar = "Hello, World"
154154
&"Let's interpolate {bar} in the string"
155155
doAssert foo() == "Let's interpolate Hello, World in the string"

0 commit comments

Comments
 (0)