proc params as syms (#15332)
* proc params are now syms * Fix typesrenderer * Add testcase for disrupteks issue * fix test * Trigger build * Trigger build * Trigger build Co-authored-by: Clyybber <darkmine956@gmail.com>
This commit is contained in:
parent
a3e9cc5234
commit
341be0b61c
4 changed files with 19 additions and 2 deletions
|
|
@ -1286,6 +1286,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
addParamOrResult(c, arg, kind)
|
addParamOrResult(c, arg, kind)
|
||||||
styleCheckDef(c.config, a[j].info, arg)
|
styleCheckDef(c.config, a[j].info, arg)
|
||||||
onDef(a[j].info, arg)
|
onDef(a[j].info, arg)
|
||||||
|
a[j] = newSymNode(arg)
|
||||||
|
|
||||||
var r: PType
|
var r: PType
|
||||||
if n[0].kind != nkEmpty:
|
if n[0].kind != nkEmpty:
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ proc renderType(n: PNode): string =
|
||||||
let typeStr = renderType(n[typePos])
|
let typeStr = renderType(n[typePos])
|
||||||
result = typeStr
|
result = typeStr
|
||||||
for i in 1..<typePos:
|
for i in 1..<typePos:
|
||||||
assert n[i].kind == nkIdent
|
assert n[i].kind in {nkSym, nkIdent}
|
||||||
result.add(',' & typeStr)
|
result.add(',' & typeStr)
|
||||||
of nkTupleTy:
|
of nkTupleTy:
|
||||||
result = "tuple["
|
result = "tuple["
|
||||||
|
|
|
||||||
|
|
@ -458,6 +458,14 @@ macro `{}`*(typ: typedesc, xs: varargs[untyped]): auto =
|
||||||
# Macro to build a lambda using JavaScript's `this`
|
# Macro to build a lambda using JavaScript's `this`
|
||||||
# from a proc, `this` being the first argument.
|
# 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 =
|
macro bindMethod*(procedure: typed): auto =
|
||||||
## Takes the name of a procedure and wraps it into a lambda missing the first
|
## 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
|
## argument, which passes the JavaScript builtin ``this`` as the first
|
||||||
|
|
@ -491,7 +499,7 @@ macro bindMethod*(procedure: typed): auto =
|
||||||
getImpl(procedure)
|
getImpl(procedure)
|
||||||
else:
|
else:
|
||||||
procedure
|
procedure
|
||||||
args = rawProc[3]
|
args = rawProc[3].copyNimTree.replaceSyms
|
||||||
thisType = args[1][1]
|
thisType = args[1][1]
|
||||||
params = newNimNode(nnkFormalParams).add(args[0])
|
params = newNimNode(nnkFormalParams).add(args[0])
|
||||||
body = newNimNode(nnkLambda)
|
body = newNimNode(nnkLambda)
|
||||||
|
|
|
||||||
|
|
@ -237,3 +237,11 @@ noop:
|
||||||
makeVar
|
makeVar
|
||||||
echo tensorY
|
echo tensorY
|
||||||
|
|
||||||
|
macro xbenchmark(body: typed): untyped =
|
||||||
|
result = body
|
||||||
|
|
||||||
|
xbenchmark:
|
||||||
|
proc fastSHA(inputtest: string) =
|
||||||
|
discard inputtest
|
||||||
|
fastSHA("hey")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue