Skip to content

Commit

Permalink
impr(exprRewrite): macrocache for init proc
Browse files Browse the repository at this point in the history
  • Loading branch information
litlighilit committed Jan 1, 2025
1 parent e3d512f commit da8681d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/pylib/pysugar/stmt/exprRewrite.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

import std/macros
import std/macrocache
from std/strutils import toLowerAscii, normalize
import ../../pystring/[strimpl, strprefix]
import ../../builtins/[list_decl, set, dict]

using e: NimNode
proc toPyExpr*(atm: NimNode): NimNode
Expand Down Expand Up @@ -103,9 +105,14 @@ template mapEleCall(
), res
)

const CollectionSyms = CacheSeq"CollectionSyms"
static:
CollectionSyms.add bindSym"list"
CollectionSyms.add bindSym"pyset"
CollectionSyms.add bindSym"toPyDict"

proc toList(e): NimNode = mapEleCall(ident"list", e)
proc toSet (e): NimNode = mapEleCall(ident"pyset", e)
proc toList(e): NimNode = mapEleCall(CollectionSyms[0], e)
proc toSet (e): NimNode = mapEleCall(CollectionSyms[1], e)
proc toDict(e): NimNode =
e.asisIfEmpty

Expand All @@ -123,7 +130,7 @@ proc toDict(e): NimNode =

newCall(
nnkBracketExpr.newTree(
ident"toPyDict",
CollectionSyms[2],
bindSym"PyStr",
eleValTyp
), eles
Expand Down

0 comments on commit da8681d

Please sign in to comment.