ccgcalls.nim 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. #
  2. #
  3. # The Nim Compiler
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. #
  10. # included from cgen.nim
  11. proc leftAppearsOnRightSide(le, ri: PNode): bool =
  12. if le != nil:
  13. for i in 1 .. <ri.len:
  14. let r = ri[i]
  15. if isPartOf(le, r) != arNo: return true
  16. proc hasNoInit(call: PNode): bool {.inline.} =
  17. result = call.sons[0].kind == nkSym and sfNoInit in call.sons[0].sym.flags
  18. proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc,
  19. callee, params: Rope) =
  20. var pl = callee & ~"(" & params
  21. # getUniqueType() is too expensive here:
  22. var typ = skipTypes(ri.sons[0].typ, abstractInst)
  23. if typ.sons[0] != nil:
  24. if isInvalidReturnType(typ.sons[0]):
  25. if params != nil: pl.add(~", ")
  26. # beware of 'result = p(result)'. We may need to allocate a temporary:
  27. if d.k in {locTemp, locNone} or not leftAppearsOnRightSide(le, ri):
  28. # Great, we can use 'd':
  29. if d.k == locNone: getTemp(p, typ.sons[0], d, needsInit=true)
  30. elif d.k notin {locTemp} and not hasNoInit(ri):
  31. # reset before pass as 'result' var:
  32. resetLoc(p, d)
  33. add(pl, addrLoc(d))
  34. add(pl, ~");$n")
  35. line(p, cpsStmts, pl)
  36. else:
  37. var tmp: TLoc
  38. getTemp(p, typ.sons[0], tmp, needsInit=true)
  39. add(pl, addrLoc(tmp))
  40. add(pl, ~");$n")
  41. line(p, cpsStmts, pl)
  42. genAssignment(p, d, tmp, {}) # no need for deep copying
  43. else:
  44. add(pl, ~")")
  45. if p.module.compileToCpp and lfSingleUse in d.flags:
  46. # do not generate spurious temporaries for C++! For C we're better off
  47. # with them to prevent undefined behaviour and because the codegen
  48. # is free to emit expressions multiple times!
  49. d.k = locCall
  50. d.r = pl
  51. excl d.flags, lfSingleUse
  52. else:
  53. if d.k == locNone: getTemp(p, typ.sons[0], d)
  54. assert(d.t != nil) # generate an assignment to d:
  55. var list: TLoc
  56. initLoc(list, locCall, d.lode, OnUnknown)
  57. list.r = pl
  58. genAssignment(p, d, list, {}) # no need for deep copying
  59. else:
  60. add(pl, ~");$n")
  61. line(p, cpsStmts, pl)
  62. proc isInCurrentFrame(p: BProc, n: PNode): bool =
  63. # checks if `n` is an expression that refers to the current frame;
  64. # this does not work reliably because of forwarding + inlining can break it
  65. case n.kind
  66. of nkSym:
  67. if n.sym.kind in {skVar, skResult, skTemp, skLet} and p.prc != nil:
  68. result = p.prc.id == n.sym.owner.id
  69. of nkDotExpr, nkBracketExpr:
  70. if skipTypes(n.sons[0].typ, abstractInst).kind notin {tyVar,tyPtr,tyRef}:
  71. result = isInCurrentFrame(p, n.sons[0])
  72. of nkHiddenStdConv, nkHiddenSubConv, nkConv:
  73. result = isInCurrentFrame(p, n.sons[1])
  74. of nkHiddenDeref, nkDerefExpr:
  75. # what about: var x = addr(y); callAsOpenArray(x[])?
  76. # *shrug* ``addr`` is unsafe anyway.
  77. result = false
  78. of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
  79. result = isInCurrentFrame(p, n.sons[0])
  80. else: discard
  81. proc openArrayLoc(p: BProc, n: PNode): Rope =
  82. var a: TLoc
  83. let q = skipConv(n)
  84. if getMagic(q) == mSlice:
  85. # magic: pass slice to openArray:
  86. var b, c: TLoc
  87. initLocExpr(p, q[1], a)
  88. initLocExpr(p, q[2], b)
  89. initLocExpr(p, q[3], c)
  90. let fmt =
  91. case skipTypes(a.t, abstractVar+{tyPtr}).kind
  92. of tyOpenArray, tyVarargs, tyArray:
  93. "($1)+($2), ($3)-($2)+1"
  94. of tyString, tySequence:
  95. if skipTypes(n.typ, abstractInst).kind == tyVar and
  96. not compileToCpp(p.module):
  97. "(*$1)->data+($2), ($3)-($2)+1"
  98. else:
  99. "$1->data+($2), ($3)-($2)+1"
  100. else: (internalError("openArrayLoc: " & typeToString(a.t)); "")
  101. result = fmt % [rdLoc(a), rdLoc(b), rdLoc(c)]
  102. else:
  103. initLocExpr(p, n, a)
  104. case skipTypes(a.t, abstractVar).kind
  105. of tyOpenArray, tyVarargs:
  106. result = "$1, $1Len_0" % [rdLoc(a)]
  107. of tyString, tySequence:
  108. if skipTypes(n.typ, abstractInst).kind == tyVar and
  109. not compileToCpp(p.module):
  110. result = "(*$1)->data, (*$1)->$2" % [a.rdLoc, lenField(p)]
  111. else:
  112. result = "$1->data, $1->$2" % [a.rdLoc, lenField(p)]
  113. of tyArray:
  114. result = "$1, $2" % [rdLoc(a), rope(lengthOrd(a.t))]
  115. of tyPtr, tyRef:
  116. case lastSon(a.t).kind
  117. of tyString, tySequence:
  118. result = "(*$1)->data, (*$1)->$2" % [a.rdLoc, lenField(p)]
  119. of tyArray:
  120. result = "$1, $2" % [rdLoc(a), rope(lengthOrd(lastSon(a.t)))]
  121. else:
  122. internalError("openArrayLoc: " & typeToString(a.t))
  123. else: internalError("openArrayLoc: " & typeToString(a.t))
  124. proc genArgStringToCString(p: BProc, n: PNode): Rope {.inline.} =
  125. var a: TLoc
  126. initLocExpr(p, n.sons[0], a)
  127. result = "$1->data" % [a.rdLoc]
  128. proc genArg(p: BProc, n: PNode, param: PSym; call: PNode): Rope =
  129. var a: TLoc
  130. if n.kind == nkStringToCString:
  131. result = genArgStringToCString(p, n)
  132. elif skipTypes(param.typ, abstractVar).kind in {tyOpenArray, tyVarargs}:
  133. var n = if n.kind != nkHiddenAddr: n else: n.sons[0]
  134. result = openArrayLoc(p, n)
  135. elif ccgIntroducedPtr(param):
  136. initLocExpr(p, n, a)
  137. result = addrLoc(a)
  138. elif p.module.compileToCpp and param.typ.kind == tyVar and
  139. n.kind == nkHiddenAddr:
  140. initLocExprSingleUse(p, n.sons[0], a)
  141. # if the proc is 'importc'ed but not 'importcpp'ed then 'var T' still
  142. # means '*T'. See posix.nim for lots of examples that do that in the wild.
  143. let callee = call.sons[0]
  144. if callee.kind == nkSym and
  145. {sfImportC, sfInfixCall, sfCompilerProc} * callee.sym.flags == {sfImportC} and
  146. {lfHeader, lfNoDecl} * callee.sym.loc.flags != {}:
  147. result = addrLoc(a)
  148. else:
  149. result = rdLoc(a)
  150. else:
  151. initLocExprSingleUse(p, n, a)
  152. result = rdLoc(a)
  153. proc genArgNoParam(p: BProc, n: PNode): Rope =
  154. var a: TLoc
  155. if n.kind == nkStringToCString:
  156. result = genArgStringToCString(p, n)
  157. else:
  158. initLocExprSingleUse(p, n, a)
  159. result = rdLoc(a)
  160. template genParamLoop(params) {.dirty.} =
  161. if i < sonsLen(typ):
  162. assert(typ.n.sons[i].kind == nkSym)
  163. let paramType = typ.n.sons[i]
  164. if not paramType.typ.isCompileTimeOnly:
  165. if params != nil: add(params, ~", ")
  166. add(params, genArg(p, ri.sons[i], paramType.sym, ri))
  167. else:
  168. if params != nil: add(params, ~", ")
  169. add(params, genArgNoParam(p, ri.sons[i]))
  170. proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
  171. var op: TLoc
  172. # this is a hotspot in the compiler
  173. initLocExpr(p, ri.sons[0], op)
  174. var params: Rope
  175. # getUniqueType() is too expensive here:
  176. var typ = skipTypes(ri.sons[0].typ, abstractInst)
  177. assert(typ.kind == tyProc)
  178. assert(sonsLen(typ) == sonsLen(typ.n))
  179. var length = sonsLen(ri)
  180. for i in countup(1, length - 1):
  181. genParamLoop(params)
  182. fixupCall(p, le, ri, d, op.r, params)
  183. proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
  184. proc getRawProcType(p: BProc, t: PType): Rope =
  185. result = getClosureType(p.module, t, clHalf)
  186. proc addComma(r: Rope): Rope =
  187. result = if r == nil: r else: r & ~", "
  188. const PatProc = "$1.ClE_0? $1.ClP_0($3$1.ClE_0):(($4)($1.ClP_0))($2)"
  189. const PatIter = "$1.ClP_0($3$1.ClE_0)" # we know the env exists
  190. var op: TLoc
  191. initLocExpr(p, ri.sons[0], op)
  192. var pl: Rope
  193. var typ = skipTypes(ri.sons[0].typ, abstractInst)
  194. assert(typ.kind == tyProc)
  195. var length = sonsLen(ri)
  196. for i in countup(1, length - 1):
  197. assert(sonsLen(typ) == sonsLen(typ.n))
  198. genParamLoop(pl)
  199. template genCallPattern {.dirty.} =
  200. lineF(p, cpsStmts, callPattern & ";$n", [op.r, pl, pl.addComma, rawProc])
  201. let rawProc = getRawProcType(p, typ)
  202. let callPattern = if tfIterator in typ.flags: PatIter else: PatProc
  203. if typ.sons[0] != nil:
  204. if isInvalidReturnType(typ.sons[0]):
  205. if sonsLen(ri) > 1: add(pl, ~", ")
  206. # beware of 'result = p(result)'. We may need to allocate a temporary:
  207. if d.k in {locTemp, locNone} or not leftAppearsOnRightSide(le, ri):
  208. # Great, we can use 'd':
  209. if d.k == locNone:
  210. getTemp(p, typ.sons[0], d, needsInit=true)
  211. elif d.k notin {locTemp} and not hasNoInit(ri):
  212. # reset before pass as 'result' var:
  213. resetLoc(p, d)
  214. add(pl, addrLoc(d))
  215. genCallPattern()
  216. else:
  217. var tmp: TLoc
  218. getTemp(p, typ.sons[0], tmp, needsInit=true)
  219. add(pl, addrLoc(tmp))
  220. genCallPattern()
  221. genAssignment(p, d, tmp, {}) # no need for deep copying
  222. else:
  223. if d.k == locNone: getTemp(p, typ.sons[0], d)
  224. assert(d.t != nil) # generate an assignment to d:
  225. var list: TLoc
  226. initLoc(list, locCall, d.lode, OnUnknown)
  227. list.r = callPattern % [op.r, pl, pl.addComma, rawProc]
  228. genAssignment(p, d, list, {}) # no need for deep copying
  229. else:
  230. genCallPattern()
  231. proc genOtherArg(p: BProc; ri: PNode; i: int; typ: PType): Rope =
  232. if i < sonsLen(typ):
  233. # 'var T' is 'T&' in C++. This means we ignore the request of
  234. # any nkHiddenAddr when it's a 'var T'.
  235. let paramType = typ.n.sons[i]
  236. assert(paramType.kind == nkSym)
  237. if paramType.typ.isCompileTimeOnly:
  238. result = nil
  239. elif typ.sons[i].kind == tyVar and ri.sons[i].kind == nkHiddenAddr:
  240. result = genArgNoParam(p, ri.sons[i][0])
  241. else:
  242. result = genArgNoParam(p, ri.sons[i]) #, typ.n.sons[i].sym)
  243. else:
  244. if tfVarargs notin typ.flags:
  245. localError(ri.info, "wrong argument count")
  246. result = nil
  247. else:
  248. result = genArgNoParam(p, ri.sons[i])
  249. discard """
  250. Dot call syntax in C++
  251. ======================
  252. so c2nim translates 'this' sometimes to 'T' and sometimes to 'var T'
  253. both of which are wrong, but often more convenient to use.
  254. For manual wrappers it can also be 'ptr T'
  255. Fortunately we know which parameter is the 'this' parameter and so can fix this
  256. mess in the codegen.
  257. now ... if the *argument* is a 'ptr' the codegen shall emit -> and otherwise .
  258. but this only depends on the argument and not on how the 'this' was declared
  259. however how the 'this' was declared affects whether we end up with
  260. wrong 'addr' and '[]' ops...
  261. Since I'm tired I'll enumerate all the cases here:
  262. var
  263. x: ptr T
  264. y: T
  265. proc t(x: T)
  266. x[].t() --> (*x).t() is correct.
  267. y.t() --> y.t() is correct
  268. proc u(x: ptr T)
  269. x.u() --> needs to become x->u()
  270. (addr y).u() --> needs to become y.u()
  271. proc v(x: var T)
  272. --> first skip the implicit 'nkAddr' node
  273. x[].v() --> (*x).v() is correct, but might have been eliminated due
  274. to the nkAddr node! So for this case we need to generate '->'
  275. y.v() --> y.v() is correct
  276. """
  277. proc skipAddrDeref(node: PNode): PNode =
  278. var n = node
  279. var isAddr = false
  280. case n.kind
  281. of nkAddr, nkHiddenAddr:
  282. n = n.sons[0]
  283. isAddr = true
  284. of nkDerefExpr, nkHiddenDeref:
  285. n = n.sons[0]
  286. else: return n
  287. if n.kind == nkObjDownConv: n = n.sons[0]
  288. if isAddr and n.kind in {nkDerefExpr, nkHiddenDeref}:
  289. result = n.sons[0]
  290. elif n.kind in {nkAddr, nkHiddenAddr}:
  291. result = n.sons[0]
  292. else:
  293. result = node
  294. proc genThisArg(p: BProc; ri: PNode; i: int; typ: PType): Rope =
  295. # for better or worse c2nim translates the 'this' argument to a 'var T'.
  296. # However manual wrappers may also use 'ptr T'. In any case we support both
  297. # for convenience.
  298. internalAssert i < sonsLen(typ)
  299. assert(typ.n.sons[i].kind == nkSym)
  300. # if the parameter is lying (tyVar) and thus we required an additional deref,
  301. # skip the deref:
  302. var ri = ri[i]
  303. while ri.kind == nkObjDownConv: ri = ri[0]
  304. let t = typ.sons[i].skipTypes({tyGenericInst, tyAlias})
  305. if t.kind == tyVar:
  306. let x = if ri.kind == nkHiddenAddr: ri[0] else: ri
  307. if x.typ.kind == tyPtr:
  308. result = genArgNoParam(p, x)
  309. result.add("->")
  310. elif x.kind in {nkHiddenDeref, nkDerefExpr} and x[0].typ.kind == tyPtr:
  311. result = genArgNoParam(p, x[0])
  312. result.add("->")
  313. else:
  314. result = genArgNoParam(p, x)
  315. result.add(".")
  316. elif t.kind == tyPtr:
  317. if ri.kind in {nkAddr, nkHiddenAddr}:
  318. result = genArgNoParam(p, ri[0])
  319. result.add(".")
  320. else:
  321. result = genArgNoParam(p, ri)
  322. result.add("->")
  323. else:
  324. ri = skipAddrDeref(ri)
  325. if ri.kind in {nkAddr, nkHiddenAddr}: ri = ri[0]
  326. result = genArgNoParam(p, ri) #, typ.n.sons[i].sym)
  327. result.add(".")
  328. proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
  329. var i = 0
  330. var j = 1
  331. while i < pat.len:
  332. case pat[i]
  333. of '@':
  334. if j < ri.len:
  335. result.add genOtherArg(p, ri, j, typ)
  336. for k in j+1 .. < ri.len:
  337. result.add(~", ")
  338. result.add genOtherArg(p, ri, k, typ)
  339. inc i
  340. of '#':
  341. if pat[i+1] in {'+', '@'}:
  342. let ri = ri[j]
  343. if ri.kind in nkCallKinds:
  344. let typ = skipTypes(ri.sons[0].typ, abstractInst)
  345. if pat[i+1] == '+': result.add genArgNoParam(p, ri.sons[0])
  346. result.add(~"(")
  347. if 1 < ri.len:
  348. result.add genOtherArg(p, ri, 1, typ)
  349. for k in j+1 .. < ri.len:
  350. result.add(~", ")
  351. result.add genOtherArg(p, ri, k, typ)
  352. result.add(~")")
  353. else:
  354. localError(ri.info, "call expression expected for C++ pattern")
  355. inc i
  356. elif pat[i+1] == '.':
  357. result.add genThisArg(p, ri, j, typ)
  358. inc i
  359. elif pat[i+1] == '[':
  360. var arg = ri.sons[j].skipAddrDeref
  361. while arg.kind in {nkAddr, nkHiddenAddr, nkObjDownConv}: arg = arg[0]
  362. result.add genArgNoParam(p, arg)
  363. #result.add debugTree(arg, 0, 10)
  364. else:
  365. result.add genOtherArg(p, ri, j, typ)
  366. inc j
  367. inc i
  368. of '\'':
  369. var idx, stars: int
  370. if scanCppGenericSlot(pat, i, idx, stars):
  371. var t = resolveStarsInCppType(typ, idx, stars)
  372. if t == nil: result.add(~"void")
  373. else: result.add(getTypeDesc(p.module, t))
  374. else:
  375. let start = i
  376. while i < pat.len:
  377. if pat[i] notin {'@', '#', '\''}: inc(i)
  378. else: break
  379. if i - 1 >= start:
  380. add(result, substr(pat, start, i - 1))
  381. proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
  382. var op: TLoc
  383. initLocExpr(p, ri.sons[0], op)
  384. # getUniqueType() is too expensive here:
  385. var typ = skipTypes(ri.sons[0].typ, abstractInst)
  386. assert(typ.kind == tyProc)
  387. var length = sonsLen(ri)
  388. assert(sonsLen(typ) == sonsLen(typ.n))
  389. # don't call '$' here for efficiency:
  390. let pat = ri.sons[0].sym.loc.r.data
  391. internalAssert pat != nil
  392. if pat.contains({'#', '(', '@', '\''}):
  393. var pl = genPatternCall(p, ri, pat, typ)
  394. # simpler version of 'fixupCall' that works with the pl+params combination:
  395. var typ = skipTypes(ri.sons[0].typ, abstractInst)
  396. if typ.sons[0] != nil:
  397. if p.module.compileToCpp and lfSingleUse in d.flags:
  398. # do not generate spurious temporaries for C++! For C we're better off
  399. # with them to prevent undefined behaviour and because the codegen
  400. # is free to emit expressions multiple times!
  401. d.k = locCall
  402. d.r = pl
  403. excl d.flags, lfSingleUse
  404. else:
  405. if d.k == locNone: getTemp(p, typ.sons[0], d)
  406. assert(d.t != nil) # generate an assignment to d:
  407. var list: TLoc
  408. initLoc(list, locCall, d.lode, OnUnknown)
  409. list.r = pl
  410. genAssignment(p, d, list, {}) # no need for deep copying
  411. else:
  412. add(pl, ~";$n")
  413. line(p, cpsStmts, pl)
  414. else:
  415. var pl: Rope = nil
  416. #var param = typ.n.sons[1].sym
  417. if 1 < ri.len:
  418. add(pl, genThisArg(p, ri, 1, typ))
  419. add(pl, op.r)
  420. var params: Rope
  421. for i in countup(2, length - 1):
  422. if params != nil: params.add(~", ")
  423. assert(sonsLen(typ) == sonsLen(typ.n))
  424. add(params, genOtherArg(p, ri, i, typ))
  425. fixupCall(p, le, ri, d, pl, params)
  426. proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
  427. # generates a crappy ObjC call
  428. var op: TLoc
  429. initLocExpr(p, ri.sons[0], op)
  430. var pl = ~"["
  431. # getUniqueType() is too expensive here:
  432. var typ = skipTypes(ri.sons[0].typ, abstractInst)
  433. assert(typ.kind == tyProc)
  434. var length = sonsLen(ri)
  435. assert(sonsLen(typ) == sonsLen(typ.n))
  436. # don't call '$' here for efficiency:
  437. let pat = ri.sons[0].sym.loc.r.data
  438. internalAssert pat != nil
  439. var start = 3
  440. if ' ' in pat:
  441. start = 1
  442. add(pl, op.r)
  443. if length > 1:
  444. add(pl, ~": ")
  445. add(pl, genArg(p, ri.sons[1], typ.n.sons[1].sym, ri))
  446. start = 2
  447. else:
  448. if length > 1:
  449. add(pl, genArg(p, ri.sons[1], typ.n.sons[1].sym, ri))
  450. add(pl, ~" ")
  451. add(pl, op.r)
  452. if length > 2:
  453. add(pl, ~": ")
  454. add(pl, genArg(p, ri.sons[2], typ.n.sons[2].sym, ri))
  455. for i in countup(start, length-1):
  456. assert(sonsLen(typ) == sonsLen(typ.n))
  457. if i >= sonsLen(typ):
  458. internalError(ri.info, "varargs for objective C method?")
  459. assert(typ.n.sons[i].kind == nkSym)
  460. var param = typ.n.sons[i].sym
  461. add(pl, ~" ")
  462. add(pl, param.name.s)
  463. add(pl, ~": ")
  464. add(pl, genArg(p, ri.sons[i], param, ri))
  465. if typ.sons[0] != nil:
  466. if isInvalidReturnType(typ.sons[0]):
  467. if sonsLen(ri) > 1: add(pl, ~" ")
  468. # beware of 'result = p(result)'. We always allocate a temporary:
  469. if d.k in {locTemp, locNone}:
  470. # We already got a temp. Great, special case it:
  471. if d.k == locNone: getTemp(p, typ.sons[0], d, needsInit=true)
  472. add(pl, ~"Result: ")
  473. add(pl, addrLoc(d))
  474. add(pl, ~"];$n")
  475. line(p, cpsStmts, pl)
  476. else:
  477. var tmp: TLoc
  478. getTemp(p, typ.sons[0], tmp, needsInit=true)
  479. add(pl, addrLoc(tmp))
  480. add(pl, ~"];$n")
  481. line(p, cpsStmts, pl)
  482. genAssignment(p, d, tmp, {}) # no need for deep copying
  483. else:
  484. add(pl, ~"]")
  485. if d.k == locNone: getTemp(p, typ.sons[0], d)
  486. assert(d.t != nil) # generate an assignment to d:
  487. var list: TLoc
  488. initLoc(list, locCall, ri, OnUnknown)
  489. list.r = pl
  490. genAssignment(p, d, list, {}) # no need for deep copying
  491. else:
  492. add(pl, ~"];$n")
  493. line(p, cpsStmts, pl)
  494. proc genCall(p: BProc, e: PNode, d: var TLoc) =
  495. if e.sons[0].typ.skipTypes({tyGenericInst, tyAlias}).callConv == ccClosure:
  496. genClosureCall(p, nil, e, d)
  497. elif e.sons[0].kind == nkSym and sfInfixCall in e.sons[0].sym.flags:
  498. genInfixCall(p, nil, e, d)
  499. elif e.sons[0].kind == nkSym and sfNamedParamCall in e.sons[0].sym.flags:
  500. genNamedParamCall(p, e, d)
  501. else:
  502. genPrefixCall(p, nil, e, d)
  503. postStmtActions(p)
  504. proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) =
  505. if ri.sons[0].typ.skipTypes({tyGenericInst, tyAlias}).callConv == ccClosure:
  506. genClosureCall(p, le, ri, d)
  507. elif ri.sons[0].kind == nkSym and sfInfixCall in ri.sons[0].sym.flags:
  508. genInfixCall(p, le, ri, d)
  509. elif ri.sons[0].kind == nkSym and sfNamedParamCall in ri.sons[0].sym.flags:
  510. genNamedParamCall(p, ri, d)
  511. else:
  512. genPrefixCall(p, le, ri, d)
  513. postStmtActions(p)