summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-07-19 16:47:38 +0200
committerGitHub <noreply@github.com>2019-07-19 16:47:38 +0200
commit70e8551e37ab66658f7b45b325ea6b7ac2bf3cb7 (patch)
treed5e9943e7c94ecfa90d29aaa2b137a9739bedf22 /lib
parent903d06bab8ba6c5fd2e30fb29dfc327f304f1ae1 (diff)
downloadNim-70e8551e37ab66658f7b45b325ea6b7ac2bf3cb7.tar.gz
async macro: general stability improvements [bugfix] (#11787)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/asyncmacro.nim23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim
index 477011285..e9c6f9322 100644
--- a/lib/pure/asyncmacro.nim
+++ b/lib/pure/asyncmacro.nim
@@ -129,7 +129,7 @@ proc processBody(node, retFutureSym: NimNode,
     result.add newNimNode(nnkReturnStmt, node).add(newNilLit())
     return # Don't process the children of this return stmt
   of nnkCommand, nnkCall:
-    if node[0].kind == nnkIdent and node[0].eqIdent("await"):
+    if node[0].eqIdent("await"):
       case node[1].kind
       of nnkIdent, nnkInfix, nnkDotExpr, nnkCall, nnkCommand:
         # await x
@@ -142,7 +142,7 @@ proc processBody(node, retFutureSym: NimNode,
       else:
         error("Invalid node kind in 'await', got: " & $node[1].kind)
     elif node.len > 1 and node[1].kind == nnkCommand and
-         node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"):
+         node[1][0].eqIdent("await"):
       # foo await x
       var newCommand = node
       result.createVar("future" & $node[0].toStrLit, node[1][1], newCommand[1],
@@ -151,7 +151,7 @@ proc processBody(node, retFutureSym: NimNode,
   of nnkVarSection, nnkLetSection:
     case node[0][^1].kind
     of nnkCommand:
-      if node[0][^1][0].kind == nnkIdent and node[0][^1][0].eqIdent("await"):
+      if node[0][^1][0].eqIdent("await"):
         # var x = await y
         var newVarSection = node # TODO: Should this use copyNimNode?
         result.createVar("future" & node[0][0].strVal, node[0][^1][1],
@@ -167,7 +167,7 @@ proc processBody(node, retFutureSym: NimNode,
     else: discard
   of nnkDiscardStmt:
     # discard await x
-    if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and
+    if node[0].kind == nnkCommand and
           node[0][0].eqIdent("await"):
       var newDiscard = node
       result.createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1],
@@ -358,16 +358,15 @@ proc stripAwait(node: NimNode): NimNode =
 
   case node.kind
   of nnkCommand, nnkCall:
-    if node[0].kind == nnkIdent and node[0].eqIdent("await"):
+    if node[0].eqIdent("await"):
       node[0] = emptyNoopSym
-    elif node.len > 1 and node[1].kind == nnkCommand and
-         node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"):
+    elif node.len > 1 and node[1].kind == nnkCommand and node[1][0].eqIdent("await"):
       # foo await x
       node[1][0] = emptyNoopSym
   of nnkVarSection, nnkLetSection:
     case node[0][^1].kind
     of nnkCommand:
-      if node[0][^1][0].kind == nnkIdent and node[0][^1][0].eqIdent("await"):
+      if node[0][^1][0].eqIdent("await"):
         # var x = await y
         node[0][^1][0] = emptyNoopSym
     else: discard
@@ -380,8 +379,7 @@ proc stripAwait(node: NimNode): NimNode =
     else: discard
   of nnkDiscardStmt:
     # discard await x
-    if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and
-          node[0][0].eqIdent("await"):
+    if node[0].kind == nnkCommand and node[0][0].eqIdent("await"):
       node[0][0] = emptyNoopSym
   else: discard
 
@@ -441,3 +439,8 @@ macro multisync*(prc: untyped): untyped =
   result = newStmtList()
   result.add(asyncSingleProc(asyncPrc))
   result.add(sync)
+
+proc await*[T](x: T) =
+  ## The 'await' keyword is also defined here for technical
+  ## reasons. (Generic symbol lookup prepass.)
+  {.error: "Await only available within .async".}
7:29 +0100 committer Araq <rumpf_a@web.de> 2013-01-16 19:57:29 +0100 todo.txt changes' href='/ahoang/Nim/commit/todo.txt?h=devel&id=e353737e34eeba6056737fa9e895f69bd56fb3af'>e353737e3 ^
eebee0eff ^
cbf82cad7 ^
eebee0eff ^
225d65701 ^
883fa40cd ^
e353737e3 ^

883fa40cd ^

e353737e3 ^

0d19de18c ^


c73d9fdd4 ^

0d19de18c ^
a64d4dc35 ^
814fcb263 ^
0d19de18c ^

88a441ea8 ^
0d19de18c ^


b5d8e8bfa ^
fd62116f6 ^
0d19de18c ^











76885c754 ^
ba80bd807 ^
2a2b63075 ^

0d19de18c ^

4fa80956b ^

d10973adb ^
580d85d23 ^
a64d4dc35 ^


869a5aa90 ^
4fbba0a65 ^
0d978c4a9 ^
d10973adb ^
d10973adb ^
0d19de18c ^

d10973adb ^
0ef08e49e ^

883fa40cd ^
0ef08e49e ^




0d19de18c ^
dd99fe61c ^
e956abbad ^
0d19de18c ^
3e806a374 ^

299390a58 ^
b4844a189 ^
cb79bf9f1 ^
f191059e5 ^
9fc2bfa79 ^



a64d4dc35 ^

632aece19 ^
990dc2d71 ^
0ef08e49e ^







0d19de18c ^

ec0f982ed ^
4fc575bc2 ^

0d19de18c ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140