diff options
-rw-r--r-- | compiler/semtypes.nim | 1 | ||||
-rw-r--r-- | compiler/typesrenderer.nim | 2 | ||||
-rw-r--r-- | lib/js/jsffi.nim | 10 | ||||
-rw-r--r-- | tests/macros/tmacros_various.nim | 8 |
4 files changed, 19 insertions, 2 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 953801431..d85008342 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1286,6 +1286,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, addParamOrResult(c, arg, kind) styleCheckDef(c.config, a[j].info, arg) onDef(a[j].info, arg) + a[j] = newSymNode(arg) var r: PType if n[0].kind != nkEmpty: diff --git a/compiler/typesrenderer.nim b/compiler/typesrenderer.nim index 60f9f6603..050a057f4 100644 --- a/compiler/typesrenderer.nim +++ b/compiler/typesrenderer.nim @@ -67,7 +67,7 @@ proc renderType(n: PNode): string = let typeStr = renderType(n[typePos]) result = typeStr for i in 1..<typePos: - assert n[i].kind == nkIdent + assert n[i].kind in {nkSym, nkIdent} result.add(',' & typeStr) of nkTupleTy: result = "tuple[" diff --git a/lib/js/jsffi.nim b/lib/js/jsffi.nim index e79e4e20d..0dce6f3b9 100644 --- a/lib/js/jsffi.nim +++ b/lib/js/jsffi.nim @@ -458,6 +458,14 @@ macro `{}`*(typ: typedesc, xs: varargs[untyped]): auto = # Macro to build a lambda using JavaScript's `this` # from a proc, `this` being the first argument. +proc replaceSyms(n: NimNode): NimNode = + if n.kind == nnkSym: + result = newIdentNode($n) + else: + result = n + for i in 0..<n.len: + result[i] = replaceSyms(n[i]) + macro bindMethod*(procedure: typed): auto = ## Takes the name of a procedure and wraps it into a lambda missing the first ## argument, which passes the JavaScript builtin ``this`` as the first @@ -491,7 +499,7 @@ macro bindMethod*(procedure: typed): auto = getImpl(procedure) else: procedure - args = rawProc[3] + args = rawProc[3].copyNimTree.replaceSyms thisType = args[1][1] params = newNimNode(nnkFormalParams).add(args[0]) body = newNimNode(nnkLambda) diff --git a/tests/macros/tmacros_various.nim b/tests/macros/tmacros_various.nim index 64bb7345a..056830837 100644 --- a/tests/macros/tmacros_various.nim +++ b/tests/macros/tmacros_various.nim @@ -237,3 +237,11 @@ noop: makeVar echo tensorY +macro xbenchmark(body: typed): untyped = + result = body + +xbenchmark: + proc fastSHA(inputtest: string) = + discard inputtest + fastSHA("hey") + |