From 3b28f390fcc98721af62d6098f0bf28246a99157 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Mon, 11 Mar 2019 11:37:51 +0200 Subject: [PATCH] Added string.add(openarray[char]) and macros.typedParams --- std_shims/macros_shim.nim | 8 ++++++++ std_shims/strings.nim | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 std_shims/strings.nim diff --git a/std_shims/macros_shim.nim b/std_shims/macros_shim.nim index 6d3cee8..636bbb2 100644 --- a/std_shims/macros_shim.nim +++ b/std_shims/macros_shim.nim @@ -226,3 +226,11 @@ proc newLitFixed*(arg: tuple): NimNode {.compileTime.} = for a,b in arg.fieldPairs: result.add nnkExprColonExpr.newTree(newIdentNode(a), newLitFixed(b)) +iterator typedParams*(n: NimNode, skip = 0): (NimNode, NimNode) = + for i in (1 + skip) ..< n.params.len: + let paramNodes = n.params[i] + let paramType = paramNodes[^2] + + for j in 0 ..< paramNodes.len - 2: + yield (paramNodes[j], paramType) + diff --git a/std_shims/strings.nim b/std_shims/strings.nim new file mode 100644 index 0000000..4dca78d --- /dev/null +++ b/std_shims/strings.nim @@ -0,0 +1,6 @@ +proc add*(s: var string, data: openarray[char]) = + if data.len > 0: + let prevEnd = s.len + s.setLen(prevEnd + data.len) + copyMem(addr s[prevEnd], unsafeAddr data[0], data.len) +