deprecated unary '<'

This commit is contained in:
Andreas Rumpf 2017-10-29 08:37:13 +01:00
commit 70ea45cdba
56 changed files with 259 additions and 258 deletions

View file

@ -20,3 +20,5 @@
recursive types can be created across module boundaries. See recursive types can be created across module boundaries. See
[package level objects](https://nim-lang.org/docs/manual.html#package-level-objects) [package level objects](https://nim-lang.org/docs/manual.html#package-level-objects)
for more information. for more information.
- The **unary** ``<`` is now deprecated, for ``.. <`` use ``..<`` for other usages
use the ``pred`` proc.

View file

@ -809,7 +809,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
var chunkStart = 0 var chunkStart = 0
while i < cppName.data.len: while i < cppName.data.len:
if cppName.data[i] == '\'': if cppName.data[i] == '\'':
var chunkEnd = <i var chunkEnd = i-1
var idx, stars: int var idx, stars: int
if scanCppGenericSlot(cppName.data, i, idx, stars): if scanCppGenericSlot(cppName.data, i, idx, stars):
result.add cppName.data.substr(chunkStart, chunkEnd) result.add cppName.data.substr(chunkStart, chunkEnd)

View file

@ -77,7 +77,7 @@ proc evalTemplateArgs(n: PNode, s: PSym; fromHlo: bool): PNode =
# now that we have working untyped parameters. # now that we have working untyped parameters.
genericParams = if sfImmediate in s.flags or fromHlo: 0 genericParams = if sfImmediate in s.flags or fromHlo: 0
else: s.ast[genericParamsPos].len else: s.ast[genericParamsPos].len
expectedRegularParams = <s.typ.len expectedRegularParams = s.typ.len-1
givenRegularParams = totalParams - genericParams givenRegularParams = totalParams - genericParams
if givenRegularParams < 0: givenRegularParams = 0 if givenRegularParams < 0: givenRegularParams = 0

View file

@ -36,7 +36,7 @@ proc applyPatterns(c: PContext, n: PNode): PNode =
# we apply the last pattern first, so that pattern overriding is possible; # we apply the last pattern first, so that pattern overriding is possible;
# however the resulting AST would better not trigger the old rule then # however the resulting AST would better not trigger the old rule then
# anymore ;-) # anymore ;-)
for i in countdown(<c.patterns.len, 0): for i in countdown(c.patterns.len-1, 0):
let pattern = c.patterns[i] let pattern = c.patterns[i]
if not isNil(pattern): if not isNil(pattern):
let x = applyRule(c, pattern, result) let x = applyRule(c, pattern, result)

View file

@ -1145,7 +1145,7 @@ proc semProcAnnotation(c: PContext, prc: PNode;
validPragmas: TSpecialWords): PNode = validPragmas: TSpecialWords): PNode =
var n = prc.sons[pragmasPos] var n = prc.sons[pragmasPos]
if n == nil or n.kind == nkEmpty: return if n == nil or n.kind == nkEmpty: return
for i in countup(0, <n.len): for i in countup(0, n.len-1):
var it = n.sons[i] var it = n.sons[i]
var key = if it.kind == nkExprColonExpr: it.sons[0] else: it var key = if it.kind == nkExprColonExpr: it.sons[0] else: it
let m = lookupMacro(c, key) let m = lookupMacro(c, key)

View file

@ -275,7 +275,7 @@ proc transformWhile(c: PTransf; n: PNode): PTransNode =
var body = newTransNode(n) var body = newTransNode(n)
for i in 0..n.len-2: for i in 0..n.len-2:
body[i] = transform(c, n.sons[i]) body[i] = transform(c, n.sons[i])
body[<n.len] = transformLoopBody(c, n.sons[<n.len]) body[n.len-1] = transformLoopBody(c, n.sons[n.len-1])
result[1] = body result[1] = body
discard c.breakSyms.pop discard c.breakSyms.pop

View file

@ -20,7 +20,7 @@ proc renderPlainSymbolName*(n: PNode): string =
result = "" result = ""
case n.kind case n.kind
of nkPostfix, nkAccQuoted: of nkPostfix, nkAccQuoted:
result = renderPlainSymbolName(n[<n.len]) result = renderPlainSymbolName(n[n.len-1])
of nkIdent: of nkIdent:
result = n.ident.s result = n.ident.s
of nkSym: of nkSym:
@ -59,7 +59,7 @@ proc renderType(n: PNode): string =
assert len(params) > 0 assert len(params) > 0
result = "proc(" result = "proc("
for i in 1 ..< len(params): result.add(renderType(params[i]) & ',') for i in 1 ..< len(params): result.add(renderType(params[i]) & ',')
result[<len(result)] = ')' result[len(result)-1] = ')'
else: else:
result = "proc" result = "proc"
of nkIdentDefs: of nkIdentDefs:
@ -73,12 +73,12 @@ proc renderType(n: PNode): string =
of nkTupleTy: of nkTupleTy:
result = "tuple[" result = "tuple["
for i in 0 ..< len(n): result.add(renderType(n[i]) & ',') for i in 0 ..< len(n): result.add(renderType(n[i]) & ',')
result[<len(result)] = ']' result[len(result)-1] = ']'
of nkBracketExpr: of nkBracketExpr:
assert len(n) >= 2 assert len(n) >= 2
result = renderType(n[0]) & '[' result = renderType(n[0]) & '['
for i in 1 ..< len(n): result.add(renderType(n[i]) & ',') for i in 1 ..< len(n): result.add(renderType(n[i]) & ',')
result[<len(result)] = ']' result[len(result)-1] = ']'
else: result = "" else: result = ""
assert(not result.isNil) assert(not result.isNil)

View file

@ -1688,8 +1688,7 @@ proc evalMacroCall*(module: PSym; cache: IdentCache, n, nOrig: PNode,
# arity here too: # arity here too:
if sym.typ.len > n.safeLen and sym.typ.len > 1: if sym.typ.len > n.safeLen and sym.typ.len > 1:
globalError(n.info, "in call '$#' got $#, but expected $# argument(s)" % [ globalError(n.info, "in call '$#' got $#, but expected $# argument(s)" % [
n.renderTree, n.renderTree, $(n.safeLen-1), $(sym.typ.len-1)])
$ <n.safeLen, $ <sym.typ.len])
setupGlobalCtx(module, cache) setupGlobalCtx(module, cache)
var c = globalCtx var c = globalCtx

View file

@ -652,13 +652,17 @@ proc sizeof*[T](x: T): int {.magic: "SizeOf", noSideEffect.}
when defined(nimtypedescfixed): when defined(nimtypedescfixed):
proc sizeof*(x: typedesc): int {.magic: "SizeOf", noSideEffect.} proc sizeof*(x: typedesc): int {.magic: "SizeOf", noSideEffect.}
proc `<`*[T](x: Ordinal[T]): T {.magic: "UnaryLt", noSideEffect.} proc `<`*[T](x: Ordinal[T]): T {.magic: "UnaryLt", noSideEffect, deprecated.}
## unary ``<`` that can be used for nice looking excluding ranges: ## unary ``<`` that can be used for nice looking excluding ranges:
## ##
## .. code-block:: nim ## .. code-block:: nim
## for i in 0 .. <10: echo i #=> 0 1 2 3 4 5 6 7 8 9 ## for i in 0 .. <10: echo i #=> 0 1 2 3 4 5 6 7 8 9
## ##
## Semantically this is the same as ``pred``. ## Semantically this is the same as ``pred``.
##
## **Deprecated since version 0.18.0**. For the common excluding range
## write ``0 ..< 10`` instead of ``0 .. < 10`` (look at the spacing).
## For ``<x`` write ``pred(x)``.
proc succ*[T](x: Ordinal[T], y = 1): T {.magic: "Succ", noSideEffect.} proc succ*[T](x: Ordinal[T], y = 1): T {.magic: "Succ", noSideEffect.}
## returns the ``y``-th successor of the value ``x``. ``T`` has to be ## returns the ``y``-th successor of the value ``x``. ``T`` has to be
@ -3410,6 +3414,30 @@ proc `/`*(x, y: int): float {.inline, noSideEffect.} =
## integer division that results in a float. ## integer division that results in a float.
result = toFloat(x) / toFloat(y) result = toFloat(x) / toFloat(y)
proc `^`*[T](x: int; y: openArray[T]): int {.noSideEffect, magic: "Roof".}
proc `^`*(x: int): int {.noSideEffect, magic: "Roof".} =
## builtin `roof`:idx: operator that can be used for convenient array access.
## ``a[^x]`` is rewritten to ``a[a.len-x]``. However currently the ``a``
## expression must not have side effects for this to compile. Note that since
## this is a builtin, it automatically works for all kinds of
## overloaded ``[]`` or ``[]=`` accessors.
discard
template `..^`*(a, b: untyped): untyped =
## a shortcut for '.. ^' to avoid the common gotcha that a space between
## '..' and '^' is required.
a .. ^b
template `..<`*(a, b: untyped): untyped {.dirty.} =
## a shortcut for 'a..pred(b)'.
a .. pred(b)
iterator `..<`*[S,T](a: S, b: T): T =
var i = T(a)
while i < b:
yield i
inc i
template spliceImpl(s, a, L, b: untyped): untyped = template spliceImpl(s, a, L, b: untyped): untyped =
# make room for additional elements or cut: # make room for additional elements or cut:
var shift = b.len - max(0,L) # ignore negative slice size var shift = b.len - max(0,L) # ignore negative slice size
@ -3853,31 +3881,6 @@ proc procCall*(x: untyped) {.magic: "ProcCall", compileTime.} =
## procCall someMethod(a, b) ## procCall someMethod(a, b)
discard discard
proc `^`*[T](x: int; y: openArray[T]): int {.noSideEffect, magic: "Roof".}
proc `^`*(x: int): int {.noSideEffect, magic: "Roof".} =
## builtin `roof`:idx: operator that can be used for convenient array access.
## ``a[^x]`` is rewritten to ``a[a.len-x]``. However currently the ``a``
## expression must not have side effects for this to compile. Note that since
## this is a builtin, it automatically works for all kinds of
## overloaded ``[]`` or ``[]=`` accessors.
discard
template `..^`*(a, b: untyped): untyped =
## a shortcut for '.. ^' to avoid the common gotcha that a space between
## '..' and '^' is required.
a .. ^b
template `..<`*(a, b: untyped): untyped {.dirty.} =
## a shortcut for '.. <' to avoid the common gotcha that a space between
## '..' and '<' is required.
a .. <b
iterator `..<`*[S,T](a: S, b: T): T =
var i = T(a)
while i < b:
yield i
inc i
proc xlen*(x: string): int {.magic: "XLenStr", noSideEffect.} = discard proc xlen*(x: string): int {.magic: "XLenStr", noSideEffect.} = discard
proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect.} = proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect.} =
## returns the length of a sequence or a string without testing for 'nil'. ## returns the length of a sequence or a string without testing for 'nil'.

View file

@ -3,7 +3,6 @@ version 1.0 battle plan
- make nimresolve part of the Nim compiler and add support for - make nimresolve part of the Nim compiler and add support for
'import staticExec()' 'import staticExec()'
- deprecate unary '<'
- remove 'mod x' type rule - remove 'mod x' type rule
- implement x[^1] differently, no compiler magic - implement x[^1] differently, no compiler magic
- fix "high priority" bugs - fix "high priority" bugs
@ -24,8 +23,6 @@ Not critical for 1.0
'static[T]' mess in the compiler! 'static[T]' mess in the compiler!
- ``not`` or ``~`` for the effects system - ``not`` or ``~`` for the effects system
- figure out why C++ bootstrapping is so much slower - figure out why C++ bootstrapping is so much slower
- The bitwise 'not' operator cold be renamed to 'bnot' to
prevent 'not 4 == 5' from compiling. -> requires 'mixin' annotation for procs!
- make 'nil' work for 'add': - make 'nil' work for 'add':
- resizeString - resizeString
- incrSeq - incrSeq