Skip to content

Commit 0ac7a86

Browse files
authored
distinct names for template and proc in decode (#97)
there can only be so many `decodeImpl`
1 parent de6c74b commit 0ac7a86

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

serialization.nim

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ template decodeImpl[InputType](
4848
# past any usage in the unsafe memory input - crucially, proc parameters are
4949
# also compatible with `openArray`
5050
type ReturnType = instantiate(RecordType)
51-
proc decodeImpl(
51+
# TODO `proc decodeProc .. {.gensym.} causes duplicate symbols
52+
let decodeProc = proc(
5253
input: InputType
5354
): ReturnType {.
5455
nimcall,
55-
gensym,
5656
raises: [SerializationError],
5757
forward: (params),
5858
noxcannotraisey,
@@ -86,27 +86,30 @@ template decodeImpl[InputType](
8686
else:
8787
raiseAssert "memory input doesn't raise IOError"
8888
89-
unpackForwarded(decodeImpl, [inputParam, params])
89+
unpackForwarded(decodeProc, [inputParam, params])
9090
9191
template decode*(
9292
Format: type SerializationFormat,
9393
inputParam: string,
9494
RecordType: type,
95-
params: varargs[untyped]): auto =
95+
params: varargs[untyped],
96+
): auto =
9697
decodeImpl(Format, inputParam, RecordType, params)
9798
9899
template decode*(
99100
Format: type SerializationFormat,
100101
inputParam: openArray[char],
101102
RecordType: type,
102-
params: varargs[untyped]): auto =
103+
params: varargs[untyped],
104+
): auto =
103105
decodeImpl(Format, inputParam, RecordType, params)
104106
105107
template decode*(
106108
Format: type SerializationFormat,
107109
inputParam: openArray[byte],
108110
RecordType: type,
109-
params: varargs[untyped]): auto =
111+
params: varargs[untyped],
112+
): auto =
110113
# TODO, this is duplicated only due to a Nim bug:
111114
# If `input` was `string|openArray[byte]`, it won't match `seq[byte]`
112115
decodeImpl(Format, inputParam, RecordType, params)

serialization/macros.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ macro forward*(args, prc: untyped): untyped =
5656
# need $ here to ensure it's a freshly looked up identifier, in case there
5757
# are symbol conflicts - would be nice if `unpackForwarded` could reuse
5858
# this exact ident instance ..
59-
prc.params.add nnkIdentDefs.newTree(ident $arg[0], autoKeyword, newEmptyNode())
59+
prc.params.add nnkIdentDefs.newTree(ident $arg[0], nnkCall.newTree(ident "typeof", arg[1]), newEmptyNode())
6060
else:
61-
prc.params.add nnkIdentDefs.newTree(ident "fwd" & $i, autoKeyword, newEmptyNode())
61+
prc.params.add nnkIdentDefs.newTree(ident "fwd" & $i, nnkCall.newTree(ident "typeof", arg[0]), newEmptyNode())
6262
i += 1
6363
prc
6464

0 commit comments

Comments
 (0)