ttypesectioncalls.nim 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. discard """
  2. nimout: '''
  3. StmtList
  4. TypeSection
  5. TypeDef
  6. Ident "A"
  7. Empty
  8. Call
  9. Ident "call"
  10. IntLit 1
  11. TypeSection
  12. TypeDef
  13. Ident "B"
  14. Empty
  15. Command
  16. Ident "call"
  17. IntLit 2
  18. TypeDef
  19. Ident "C"
  20. Empty
  21. Call
  22. Ident "call"
  23. StmtList
  24. IntLit 3
  25. TypeDef
  26. Ident "D"
  27. Empty
  28. Call
  29. Ident "call"
  30. StmtList
  31. IntLit 4
  32. TypeSection
  33. TypeDef
  34. Ident "E"
  35. Empty
  36. Call
  37. Ident "call"
  38. IntLit 5
  39. IntLit 6
  40. TypeDef
  41. Ident "F"
  42. Empty
  43. Command
  44. Ident "call"
  45. IntLit 7
  46. IntLit 8
  47. TypeDef
  48. Ident "G"
  49. Empty
  50. Call
  51. Ident "call"
  52. IntLit 9
  53. StmtList
  54. IntLit 10
  55. TypeDef
  56. Ident "H"
  57. Empty
  58. Call
  59. Ident "call"
  60. IntLit 11
  61. StmtList
  62. IntLit 12
  63. TypeDef
  64. Ident "I"
  65. Empty
  66. Command
  67. Ident "call"
  68. IntLit 13
  69. StmtList
  70. IntLit 14
  71. TypeDef
  72. Ident "J"
  73. Empty
  74. Command
  75. Ident "call"
  76. IntLit 15
  77. StmtList
  78. IntLit 16
  79. TypeSection
  80. TypeDef
  81. Ident "K"
  82. Empty
  83. Call
  84. Ident "call"
  85. IntLit 17
  86. IntLit 18
  87. IntLit 19
  88. TypeDef
  89. Ident "L"
  90. Empty
  91. Command
  92. Ident "call"
  93. IntLit 20
  94. IntLit 21
  95. IntLit 22
  96. TypeDef
  97. Ident "M"
  98. Empty
  99. Call
  100. Ident "call"
  101. IntLit 23
  102. IntLit 24
  103. StmtList
  104. IntLit 25
  105. TypeDef
  106. Ident "N"
  107. Empty
  108. Command
  109. Ident "call"
  110. IntLit 26
  111. IntLit 27
  112. StmtList
  113. IntLit 28
  114. TypeDef
  115. Ident "O"
  116. Empty
  117. Command
  118. Ident "call"
  119. IntLit 29
  120. IntLit 30
  121. StmtList
  122. IntLit 31
  123. TypeSection
  124. TypeDef
  125. Ident "P"
  126. Empty
  127. Command
  128. Ident "call"
  129. TupleConstr
  130. IntLit 32
  131. IntLit 33
  132. Infix
  133. Ident "+"
  134. Infix
  135. Ident "*"
  136. IntLit 34
  137. IntLit 35
  138. IntLit 36
  139. StmtList
  140. IntLit 37
  141. TypeDef
  142. Ident "R"
  143. Empty
  144. Command
  145. Ident "call"
  146. Infix
  147. Ident "@"
  148. TupleConstr
  149. IntLit 38
  150. IntLit 39
  151. Infix
  152. Ident "shl"
  153. IntLit 40
  154. IntLit 41
  155. Infix
  156. Ident "-"
  157. Infix
  158. Ident "*"
  159. IntLit 42
  160. IntLit 43
  161. IntLit 44
  162. StmtList
  163. IntLit 45
  164. TypeDef
  165. Ident "S"
  166. Empty
  167. Command
  168. Ident "call"
  169. IntLit 46
  170. StmtList
  171. IntLit 47
  172. StmtList
  173. IntLit 48
  174. TypeDef
  175. Ident "T"
  176. Empty
  177. Call
  178. Ident "call"
  179. StmtList
  180. IntLit 49
  181. StmtList
  182. IntLit 50
  183. StmtList
  184. IntLit 51
  185. a: IntLit 1
  186. a: IntLit 2
  187. a: StmtList
  188. IntLit 3
  189. a: StmtList
  190. IntLit 4
  191. a: IntLit 5
  192. b: IntLit 6
  193. a: IntLit 7
  194. b: IntLit 8
  195. a: IntLit 9
  196. b: StmtList
  197. IntLit 10
  198. a: IntLit 11
  199. b: StmtList
  200. IntLit 12
  201. a: IntLit 13
  202. b: StmtList
  203. IntLit 14
  204. a: IntLit 15
  205. b: StmtList
  206. IntLit 16
  207. a: IntLit 17
  208. b: IntLit 18
  209. c: IntLit 19
  210. a: IntLit 20
  211. b: IntLit 21
  212. c: IntLit 22
  213. a: IntLit 23
  214. b: IntLit 24
  215. c: StmtList
  216. IntLit 25
  217. a: IntLit 26
  218. b: IntLit 27
  219. c: StmtList
  220. IntLit 28
  221. a: IntLit 29
  222. b: IntLit 30
  223. c: StmtList
  224. IntLit 31
  225. a: TupleConstr
  226. IntLit 32
  227. IntLit 33
  228. b: Infix
  229. Ident "+"
  230. Infix
  231. Ident "*"
  232. IntLit 34
  233. IntLit 35
  234. IntLit 36
  235. c: StmtList
  236. IntLit 37
  237. a: Infix
  238. Ident "@"
  239. TupleConstr
  240. IntLit 38
  241. IntLit 39
  242. Infix
  243. Ident "shl"
  244. IntLit 40
  245. IntLit 41
  246. b: Infix
  247. Ident "-"
  248. Infix
  249. Ident "*"
  250. IntLit 42
  251. IntLit 43
  252. IntLit 44
  253. c: StmtList
  254. IntLit 45
  255. a: IntLit 46
  256. b: StmtList
  257. IntLit 47
  258. c: StmtList
  259. IntLit 48
  260. a: StmtList
  261. IntLit 49
  262. b: StmtList
  263. IntLit 50
  264. c: StmtList
  265. IntLit 51
  266. '''
  267. """
  268. import macros
  269. macro call(a): untyped =
  270. echo "a: ", a.treeRepr
  271. result = ident"int"
  272. macro call(a, b): untyped =
  273. echo "a: ", a.treeRepr
  274. echo "b: ", b.treeRepr
  275. result = ident"int"
  276. macro call(a, b, c): untyped =
  277. echo "a: ", a.treeRepr
  278. echo "b: ", b.treeRepr
  279. echo "c: ", c.treeRepr
  280. result = ident"int"
  281. macro sections(x): untyped =
  282. echo x.treeRepr
  283. result = newStmtList(x)
  284. for ts in x:
  285. for td in ts:
  286. let t = td[0]
  287. result.add quote do:
  288. doAssert `t` is int
  289. sections:
  290. type A = call(1)
  291. type
  292. B = call 2
  293. C = call: 3
  294. D = call(): 4
  295. type
  296. E = call(5, 6)
  297. F = call 7, 8
  298. G = call(9): 10
  299. H = call(11):
  300. 12
  301. I = call 13: 14
  302. J = call 15:
  303. 16
  304. type
  305. K = call(17, 18, 19)
  306. L = call 20, 21, 22
  307. M = call(23, 24): 25
  308. N = call 26, 27: 28
  309. O = call 29, 30:
  310. 31
  311. type
  312. P = call (32, 33), 34 * 35 + 36:
  313. 37
  314. R = call (38, 39) @ 40 shl 41, 42 * 43 - 44:
  315. 45
  316. S = call 46:
  317. 47
  318. do:
  319. 48
  320. T = call:
  321. 49
  322. do:
  323. 50
  324. do:
  325. 51