Clean up macros (#14959)

This commit is contained in:
Juan Carlos 2020-07-14 11:44:56 -03:00 • committed by GitHub
commit 9465b5db44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 6 additions and 43 deletions

View file

@ -139,7 +139,7 @@
- Tables, HashSets, SharedTables and deques don't require anymore that the passed - Tables, HashSets, SharedTables and deques don't require anymore that the passed
initial size must be a power of two - this is done internally. initial size must be a power of two - this is done internally.
Proc `rightSize` for Tables and HashSets is deprecated, as it is not needed anymore. Proc `rightSize` for Tables and HashSets is deprecated, as it is not needed anymore.
- Removed deprecated symbols from `macros` module, deprecated as far back as `0.15`.
## Language changes ## Language changes

View file

@ -33,7 +33,7 @@ macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): untyped =
#newCall("&") #newCall("&")
let f = f.strVal let f = f.strVal
formatImpl(newLit) formatImpl(newLit)
result = nestList(!"&", result) result = nestList(newIdentNode("&"), result)
template optAdd1{x = y; add(x, z)}(x, y, z: string) = template optAdd1{x = y; add(x, z)}(x, y, z: string) =
x = y & z x = y & z

View file

@ -140,10 +140,6 @@ const
{.push warnings: off.} {.push warnings: off.}
proc `!`*(s: string): NimIdent {.magic: "StrToIdent", noSideEffect, deprecated:
"Deprecated since version 0.18.0: Use 'ident' or 'newIdentNode' instead.".}
## Constructs an identifier from the string `s`.
proc toNimIdent*(s: string): NimIdent {.magic: "StrToIdent", noSideEffect, deprecated: proc toNimIdent*(s: string): NimIdent {.magic: "StrToIdent", noSideEffect, deprecated:
"Deprecated since version 0.18.0: Use 'ident' or 'newIdentNode' instead.".} "Deprecated since version 0.18.0: Use 'ident' or 'newIdentNode' instead.".}
## Constructs an identifier from the string `s`. ## Constructs an identifier from the string `s`.
@ -393,13 +389,6 @@ proc `ident=`*(n: NimNode, val: NimIdent) {.magic: "NSetIdent", noSideEffect, de
{.pop.} {.pop.}
#proc `typ=`*(n: NimNode, typ: typedesc) {.magic: "NSetType".}
# this is not sound! Unfortunately forbidding 'typ=' is not enough, as you
# can easily do:
# let bracket = semCheck([1, 2])
# let fake = semCheck(2.0)
# bracket[0] = fake # constructs a mixed array with ints and floats!
proc `strVal=`*(n: NimNode, val: string) {.magic: "NSetStrVal", noSideEffect.} proc `strVal=`*(n: NimNode, val: string) {.magic: "NSetStrVal", noSideEffect.}
## Sets the string value of a string literal or comment. ## Sets the string value of a string literal or comment.
## Setting `strVal` is disallowed for `nnkIdent` and `nnkSym` nodes; a new node ## Setting `strVal` is disallowed for `nnkIdent` and `nnkSym` nodes; a new node
@ -830,14 +819,6 @@ proc nestList*(op: NimNode; pack: NimNode; init: NimNode): NimNode {.compileTime
for i in countdown(pack.len - 1, 0): for i in countdown(pack.len - 1, 0):
result = newCall(op, pack[i], result) result = newCall(op, pack[i], result)
{.push warnings: off.}
proc nestList*(theProc: NimIdent, x: NimNode): NimNode {.compileTime, deprecated:
"Deprecated since v0.18.1; use one of 'nestList(NimNode, ...)' instead.".} =
nestList(newIdentNode(theProc), x)
{.pop.}
proc treeTraverse(n: NimNode; res: var string; level = 0; isLisp = false, indented = false) {.benign.} = proc treeTraverse(n: NimNode; res: var string; level = 0; isLisp = false, indented = false) {.benign.} =
if level > 0: if level > 0:
if indented: if indented:
@ -1628,21 +1609,6 @@ macro getCustomPragmaVal*(n: typed, cp: typed{nkSym}): untyped =
if result.kind == nnkEmpty: if result.kind == nnkEmpty:
error(n.repr & " doesn't have a pragma named " & cp.repr()) # returning an empty node results in most cases in a cryptic error, error(n.repr & " doesn't have a pragma named " & cp.repr()) # returning an empty node results in most cases in a cryptic error,
when not defined(booting):
template emit*(e: static[string]): untyped {.deprecated.} =
## Accepts a single string argument and treats it as nim code
## that should be inserted verbatim in the program
## Example:
##
## .. code-block:: nim
## emit("echo " & '"' & "hello world".toUpper & '"')
##
## Deprecated since version 0.15 since it's so rarely useful.
macro payload: untyped {.gensym.} =
result = parseStmt(e)
payload()
macro unpackVarargs*(callee: untyped; args: varargs[untyped]): untyped = macro unpackVarargs*(callee: untyped; args: varargs[untyped]): untyped =
result = newCall(callee) result = newCall(callee)
for i in 0 ..< args.len: for i in 0 ..< args.len:

View file

@ -678,7 +678,7 @@ macro check*(conditions: untyped): untyped =
result = newNimNode(nnkStmtList) result = newNimNode(nnkStmtList)
for node in checked: for node in checked:
if node.kind != nnkCommentStmt: if node.kind != nnkCommentStmt:
result.add(newCall(!"check", node)) result.add(newCall(newIdentNode("check"), node))
else: else:
let lineinfo = newStrLitNode(checked.lineInfo) let lineinfo = newStrLitNode(checked.lineInfo)

View file

@ -9,7 +9,7 @@ var packages2*: seq[tuple[name, cmd: string; hasDeps: bool; url: string, useHead
# packages A-M # packages A-M
pkg1 "alea", true # pkg1 "alea", true
pkg1 "argparse" pkg1 "argparse"
pkg1 "arraymancer", true, "nim c tests/tests_cpu.nim" pkg1 "arraymancer", true, "nim c tests/tests_cpu.nim"
pkg1 "ast_pattern_matching", false, "nim c -r --oldgensym:on tests/test1.nim" pkg1 "ast_pattern_matching", false, "nim c -r --oldgensym:on tests/test1.nim"

View file

@ -1,6 +1,5 @@
discard """ discard """
output: ''' output: '''
HELLO WORLD
c_func c_func
12 12
''' '''
@ -8,8 +7,6 @@ c_func
import macros, strutils import macros, strutils
emit("echo " & '"' & "hello world".toUpperAscii & '"')
# bug #1025 # bug #1025
macro foo(icname): untyped = macro foo(icname): untyped =

View file

@ -37,7 +37,7 @@ macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): untyped =
result = newNimNode(nnkBracket) result = newNimNode(nnkBracket)
let f = f.strVal let f = f.strVal
formatImpl(newLit) formatImpl(newLit)
result = nestList(!"&", result) result = nestList(newIdentNode("&"), result)
template optAdd1{x = y; add(x, z)}(x, y, z: string) = template optAdd1{x = y; add(x, z)}(x, y, z: string) =
x = y & z x = y & z

View file

@ -38,7 +38,7 @@ macro autoClose(args: varargs[untyped]): untyped =
varAssignment.add(varValue) varAssignment.add(varValue)
variables.add(varAssignment) variables.add(varAssignment)
closingCalls.add(newCall(!"close", varName)) closingCalls.add(newCall(newIdentNode("close"), varName))
else: else:
error "Using statement: Unexpected expression. Got " & error "Using statement: Unexpected expression. Got " &
$args[i].kind & " instead of assignment." $args[i].kind & " instead of assignment."