From b7b596955726a65788561d2d69978223d4484c95 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 27 Sep 2024 17:36:35 +0200 Subject: [PATCH] macros: distinct literals (#235) --- stew/shims/macros.nim | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stew/shims/macros.nim b/stew/shims/macros.nim index 7844cf3..f1bd75c 100644 --- a/stew/shims/macros.nim +++ b/stew/shims/macros.nim @@ -1,5 +1,5 @@ import - std/[macros, tables, hashes] + std/[hashes, macros, tables, typetraits] export macros @@ -395,6 +395,11 @@ proc newLitFixed*(arg: tuple): NimNode {.compileTime.} = for a,b in arg.fieldPairs: result.add nnkExprColonExpr.newTree(newIdentNode(a), newLitFixed(b)) +proc newLitFixed*(arg: distinct): NimNode {.compileTime.} = + result = newLitFixed distinctBase(arg) + var typ = getTypeInst(typeof(arg))[1] + result = newCall(typ,result) + iterator typedParams*(n: NimNode, skip = 0): (NimNode, NimNode) = let params = n[3] for i in (1 + skip) ..< params.len: