style usages part one (openarray => openArray) (#19321)
* style usages (openArray) * revert doc changes
This commit is contained in:
parent
1869826668
commit
9df195ef58
49 changed files with 76 additions and 76 deletions
|
|
@ -292,7 +292,7 @@ when false:
|
||||||
|
|
||||||
# bug #13456
|
# bug #13456
|
||||||
|
|
||||||
iterator combinations[T](s: openarray[T], k: int): seq[T] =
|
iterator combinations[T](s: openArray[T], k: int): seq[T] =
|
||||||
let n = len(s)
|
let n = len(s)
|
||||||
assert k >= 0 and k <= n
|
assert k >= 0 and k <= n
|
||||||
var pos = newSeq[int](k)
|
var pos = newSeq[int](k)
|
||||||
|
|
@ -455,7 +455,7 @@ initFoo7(2)
|
||||||
|
|
||||||
|
|
||||||
# bug #14902
|
# bug #14902
|
||||||
iterator zip[T](s: openarray[T]): (T, T) =
|
iterator zip[T](s: openArray[T]): (T, T) =
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < 10:
|
while i < 10:
|
||||||
yield (s[i mod 2], s[i mod 2 + 1])
|
yield (s[i mod 2], s[i mod 2 + 1])
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,7 @@ when false:
|
||||||
|
|
||||||
# bug #13456
|
# bug #13456
|
||||||
|
|
||||||
iterator combinations[T](s: openarray[T], k: int): seq[T] =
|
iterator combinations[T](s: openArray[T], k: int): seq[T] =
|
||||||
let n = len(s)
|
let n = len(s)
|
||||||
assert k >= 0 and k <= n
|
assert k >= 0 and k <= n
|
||||||
var pos = newSeq[int](k)
|
var pos = newSeq[int](k)
|
||||||
|
|
@ -416,7 +416,7 @@ initFoo7(2)
|
||||||
|
|
||||||
|
|
||||||
# bug #14902
|
# bug #14902
|
||||||
iterator zip[T](s: openarray[T]): (T, T) =
|
iterator zip[T](s: openArray[T]): (T, T) =
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < 10:
|
while i < 10:
|
||||||
yield (s[i mod 2], s[i mod 2 + 1])
|
yield (s[i mod 2], s[i mod 2 + 1])
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ block tarray:
|
||||||
arr: TMyarray
|
arr: TMyarray
|
||||||
|
|
||||||
|
|
||||||
proc sum(a: openarray[int]): int =
|
proc sum(a: openArray[int]): int =
|
||||||
result = 0
|
result = 0
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < len(a):
|
while i < len(a):
|
||||||
|
|
|
||||||
|
|
@ -288,8 +288,8 @@ when not defined(windows):
|
||||||
events: set[Event]
|
events: set[Event]
|
||||||
|
|
||||||
proc vnode_test(): bool =
|
proc vnode_test(): bool =
|
||||||
proc validate(test: openarray[ReadyKey],
|
proc validate(test: openArray[ReadyKey],
|
||||||
check: openarray[valType]): bool =
|
check: openArray[valType]): bool =
|
||||||
result = false
|
result = false
|
||||||
if len(test) == len(check):
|
if len(test) == len(check):
|
||||||
for checkItem in check:
|
for checkItem in check:
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,10 @@ joinable: false
|
||||||
|
|
||||||
|
|
||||||
block tclosure:
|
block tclosure:
|
||||||
proc map(n: var openarray[int], fn: proc (x: int): int {.closure}) =
|
proc map(n: var openArray[int], fn: proc (x: int): int {.closure}) =
|
||||||
for i in 0..n.len-1: n[i] = fn(n[i])
|
for i in 0..n.len-1: n[i] = fn(n[i])
|
||||||
|
|
||||||
proc each(n: openarray[int], fn: proc(x: int) {.closure.}) =
|
proc each(n: openArray[int], fn: proc(x: int) {.closure.}) =
|
||||||
for i in 0..n.len-1:
|
for i in 0..n.len-1:
|
||||||
fn(n[i])
|
fn(n[i])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ proc `==`*[T](xs, ys: List[T]): bool =
|
||||||
|
|
||||||
proc asList*[T](xs: varargs[T]): List[T] =
|
proc asList*[T](xs: varargs[T]): List[T] =
|
||||||
## Creates list from varargs
|
## Creates list from varargs
|
||||||
proc initListImpl(i: int, xs: openarray[T]): List[T] =
|
proc initListImpl(i: int, xs: openArray[T]): List[T] =
|
||||||
if i > high(xs):
|
if i > high(xs):
|
||||||
Nil[T]()
|
Nil[T]()
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -324,15 +324,15 @@ block t6691:
|
||||||
block t6782:
|
block t6782:
|
||||||
type
|
type
|
||||||
Reader = concept c
|
Reader = concept c
|
||||||
c.read(openarray[byte], int, int) is int
|
c.read(openArray[byte], int, int) is int
|
||||||
Rdr = concept c
|
Rdr = concept c
|
||||||
c.rd(openarray[byte], int, int) is int
|
c.rd(openArray[byte], int, int) is int
|
||||||
|
|
||||||
type TestFile = object
|
type TestFile = object
|
||||||
|
|
||||||
proc read(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
|
proc read(r: TestFile, dest: openArray[byte], offset: int, limit: int): int =
|
||||||
result = 0
|
result = 0
|
||||||
proc rd(r: TestFile, dest: openarray[byte], offset: int, limit: int): int =
|
proc rd(r: TestFile, dest: openArray[byte], offset: int, limit: int): int =
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
doAssert TestFile is Reader
|
doAssert TestFile is Reader
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ type
|
||||||
converter to_py*(i: int) : PPyRef = nil
|
converter to_py*(i: int) : PPyRef = nil
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
proc to_tuple*(vals: openarray[PPyRef]): PPyRef =
|
proc to_tuple*(vals: openArray[PPyRef]): PPyRef =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc abc(args: varargs[PPyRef]) =
|
proc abc(args: varargs[PPyRef]) =
|
||||||
|
|
|
||||||
|
|
@ -79,16 +79,16 @@ proc wantsCovariantSeq2(s: seq[AnimalRef]) =
|
||||||
proc wantsCovariantSeq3(s: seq[RefAlias[Animal]]) =
|
proc wantsCovariantSeq3(s: seq[RefAlias[Animal]]) =
|
||||||
for a in s: echo a.x
|
for a in s: echo a.x
|
||||||
|
|
||||||
proc wantsCovariantOpenArray(s: openarray[ref Animal]) =
|
proc wantsCovariantOpenArray(s: openArray[ref Animal]) =
|
||||||
for a in s: echo a.x
|
for a in s: echo a.x
|
||||||
|
|
||||||
proc modifiesCovariantOpenArray(s: var openarray[ref Animal]) =
|
proc modifiesCovariantOpenArray(s: var openArray[ref Animal]) =
|
||||||
for a in s: echo a.x
|
for a in s: echo a.x
|
||||||
|
|
||||||
proc modifiesDerivedOpenArray(s: var openarray[ref Dog]) =
|
proc modifiesDerivedOpenArray(s: var openArray[ref Dog]) =
|
||||||
for a in s: echo a.x
|
for a in s: echo a.x
|
||||||
|
|
||||||
proc wantsNonCovariantOpenArray(s: openarray[Animal]) =
|
proc wantsNonCovariantOpenArray(s: openArray[Animal]) =
|
||||||
for a in s: echo a.x
|
for a in s: echo a.x
|
||||||
|
|
||||||
proc wantsCovariantArray(s: array[2, ref Animal]) =
|
proc wantsCovariantArray(s: array[2, ref Animal]) =
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ proc myfuncLoop(x: int): MySeqNonCopyable =
|
||||||
discard myfuncLoop(3)
|
discard myfuncLoop(3)
|
||||||
|
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
# Move into table via openarray
|
# Move into table via openArray
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ discard """
|
||||||
errormsg: "wrong number of variables"
|
errormsg: "wrong number of variables"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
iterator xclusters*[T](a: openarray[T]; s: static[int]): array[s, T] {.inline.} =
|
iterator xclusters*[T](a: openArray[T]; s: static[int]): array[s, T] {.inline.} =
|
||||||
var result: array[s, T] # iterators have no default result variable
|
var result: array[s, T] # iterators have no default result variable
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < len(a):
|
while i < len(a):
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import strscans, strutils
|
||||||
proc raiseTestException*() =
|
proc raiseTestException*() =
|
||||||
raise newException(Exception, "test")
|
raise newException(Exception, "test")
|
||||||
|
|
||||||
proc matchStackTrace(actualEntries: openarray[StackTraceEntry], expected: string) =
|
proc matchStackTrace(actualEntries: openArray[StackTraceEntry], expected: string) =
|
||||||
var expectedEntries = newSeq[StackTraceEntry]()
|
var expectedEntries = newSeq[StackTraceEntry]()
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,12 +132,12 @@ block:
|
||||||
echo foo(fun)
|
echo foo(fun)
|
||||||
|
|
||||||
block:
|
block:
|
||||||
# bug #10285 Function signature don't match when inside seq/array/openarray
|
# bug #10285 Function signature don't match when inside seq/array/openArray
|
||||||
# Note: the error message now shows `closure` which helps debugging the issue
|
# Note: the error message now shows `closure` which helps debugging the issue
|
||||||
# out why it doesn't match
|
# out why it doesn't match
|
||||||
proc takesFunc(f: proc (x: int) {.gcsafe, locks: 0.}) =
|
proc takesFunc(f: proc (x: int) {.gcsafe, locks: 0.}) =
|
||||||
echo "takes single Func"
|
echo "takes single Func"
|
||||||
proc takesFuncs(fs: openarray[proc (x: int) {.gcsafe, locks: 0.}]) =
|
proc takesFuncs(fs: openArray[proc (x: int) {.gcsafe, locks: 0.}]) =
|
||||||
echo "takes multiple Func"
|
echo "takes multiple Func"
|
||||||
takesFunc(proc (x: int) {.gcsafe, locks: 0.} = echo x) # works
|
takesFunc(proc (x: int) {.gcsafe, locks: 0.} = echo x) # works
|
||||||
takesFuncs([proc (x: int) {.gcsafe, locks: 0.} = echo x]) # fails
|
takesFuncs([proc (x: int) {.gcsafe, locks: 0.} = echo x]) # fails
|
||||||
|
|
|
||||||
|
|
@ -603,7 +603,7 @@ block t7854:
|
||||||
|
|
||||||
|
|
||||||
block t5864:
|
block t5864:
|
||||||
proc defaultStatic(s: openarray, N: static[int] = 1): int = N
|
proc defaultStatic(s: openArray, N: static[int] = 1): int = N
|
||||||
proc defaultGeneric[T](a: T = 2): int = a
|
proc defaultGeneric[T](a: T = 2): int = a
|
||||||
|
|
||||||
let a = [1, 2, 3, 4].defaultStatic()
|
let a = [1, 2, 3, 4].defaultStatic()
|
||||||
|
|
|
||||||
|
|
@ -230,8 +230,8 @@ block tvarargs_vs_generics:
|
||||||
echo "direct"
|
echo "direct"
|
||||||
proc withDirectType[T](arg: T) =
|
proc withDirectType[T](arg: T) =
|
||||||
echo "generic"
|
echo "generic"
|
||||||
proc withOpenArray(args: openarray[string]) =
|
proc withOpenArray(args: openArray[string]) =
|
||||||
echo "openarray"
|
echo "openArray"
|
||||||
proc withOpenArray[T](arg: T) =
|
proc withOpenArray[T](arg: T) =
|
||||||
echo "generic"
|
echo "generic"
|
||||||
proc withVarargs(args: varargs[string]) =
|
proc withVarargs(args: varargs[string]) =
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ block:
|
||||||
echo a
|
echo a
|
||||||
|
|
||||||
block t5859:
|
block t5859:
|
||||||
proc flatIterator[T](s: openarray[T]): auto {.noSideEffect.}=
|
proc flatIterator[T](s: openArray[T]): auto {.noSideEffect.}=
|
||||||
result = iterator(): auto =
|
result = iterator(): auto =
|
||||||
when (T is not seq|array):
|
when (T is not seq|array):
|
||||||
for item in s:
|
for item in s:
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ block t3837_chained:
|
||||||
|
|
||||||
|
|
||||||
block t3221_complex:
|
block t3221_complex:
|
||||||
iterator permutations[T](ys: openarray[T]): seq[T] =
|
iterator permutations[T](ys: openArray[T]): seq[T] =
|
||||||
var
|
var
|
||||||
d = 1
|
d = 1
|
||||||
c = newSeq[int](ys.len)
|
c = newSeq[int](ys.len)
|
||||||
|
|
@ -228,7 +228,7 @@ block t2023_objiter:
|
||||||
|
|
||||||
block:
|
block:
|
||||||
# bug #13739
|
# bug #13739
|
||||||
iterator myIter(arg: openarray[int]): int =
|
iterator myIter(arg: openArray[int]): int =
|
||||||
var tmp = 0
|
var tmp = 0
|
||||||
let len = arg.len
|
let len = arg.len
|
||||||
while tmp < len:
|
while tmp < len:
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ proc `=copy`(dst: var NonCopyable, src: NonCopyable) {.error.}
|
||||||
proc `=sink`(dst: var NonCopyable, src: NonCopyable) =
|
proc `=sink`(dst: var NonCopyable, src: NonCopyable) =
|
||||||
dst.x = src.x
|
dst.x = src.x
|
||||||
|
|
||||||
iterator lentItems[T](a: openarray[T]): lent T =
|
iterator lentItems[T](a: openArray[T]): lent T =
|
||||||
for i in 0..a.high:
|
for i in 0..a.high:
|
||||||
yield a[i]
|
yield a[i]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ perm: 6778800.0 det: 0.0
|
||||||
|
|
||||||
import sequtils, sugar
|
import sequtils, sugar
|
||||||
|
|
||||||
iterator permutations*[T](ys: openarray[T]): tuple[perm: seq[T], sign: int] =
|
iterator permutations*[T](ys: openArray[T]): tuple[perm: seq[T], sign: int] =
|
||||||
var
|
var
|
||||||
d = 1
|
d = 1
|
||||||
c = newSeq[int](ys.len)
|
c = newSeq[int](ys.len)
|
||||||
|
|
|
||||||
|
|
@ -447,10 +447,10 @@ template tests =
|
||||||
doAssert seqOfSeqs == @[@[10, 2], @[30, 4]]
|
doAssert seqOfSeqs == @[@[10, 2], @[30, 4]]
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
block: # openarray
|
block: # openArray
|
||||||
# Error: internal error: genAddr: nkStmtListExpr
|
# Error: internal error: genAddr: nkStmtListExpr
|
||||||
var calls = 0
|
var calls = 0
|
||||||
proc getvarint(x: var openarray[int]): var int =
|
proc getvarint(x: var openArray[int]): var int =
|
||||||
calls += 1
|
calls += 1
|
||||||
if true:
|
if true:
|
||||||
x[1]
|
x[1]
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ for x in someGlobal: doAssert(x == 0)
|
||||||
proc tdefault =
|
proc tdefault =
|
||||||
var x = default(int)
|
var x = default(int)
|
||||||
doAssert(x == 0)
|
doAssert(x == 0)
|
||||||
proc inner(v: openarray[string]) =
|
proc inner(v: openArray[string]) =
|
||||||
doAssert(v.len == 0)
|
doAssert(v.len == 0)
|
||||||
|
|
||||||
inner(default(seq[string]))
|
inner(default(seq[string]))
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ proc main =
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
# Test: pass var seq to var openarray
|
# Test: pass var seq to var openArray
|
||||||
var s = @[2, 1]
|
var s = @[2, 1]
|
||||||
proc foo(a: var openarray[int]) = a[0] = 123
|
proc foo(a: var openArray[int]) = a[0] = 123
|
||||||
|
|
||||||
proc bar(s: var seq[int], a: int) =
|
proc bar(s: var seq[int], a: int) =
|
||||||
doAssert(a == 5)
|
doAssert(a == 5)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ template main2 = # bug #15958
|
||||||
p[] = 20.0
|
p[] = 20.0
|
||||||
doAssert byLent(p)[] == 20.0
|
doAssert byLent(p)[] == 20.0
|
||||||
|
|
||||||
proc byLent2[T](a: openarray[T]): lent T = a[0]
|
proc byLent2[T](a: openArray[T]): lent T = a[0]
|
||||||
doAssert byLent2(a) == 11
|
doAssert byLent2(a) == 11
|
||||||
doAssert byLent2(a).unsafeAddr == a[0].unsafeAddr
|
doAssert byLent2(a).unsafeAddr == a[0].unsafeAddr
|
||||||
doAssert byLent2(b) == 21
|
doAssert byLent2(b) == 21
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ block tlowhigh:
|
||||||
for i in low(a) .. high(a):
|
for i in low(a) .. high(a):
|
||||||
a[i] = 0
|
a[i] = 0
|
||||||
|
|
||||||
proc sum(a: openarray[int]): int =
|
proc sum(a: openArray[int]): int =
|
||||||
result = 0
|
result = 0
|
||||||
for i in low(a)..high(a):
|
for i in low(a)..high(a):
|
||||||
inc(result, a[i])
|
inc(result, a[i])
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ else:
|
||||||
const
|
const
|
||||||
glRealType* = cGLfloat
|
glRealType* = cGLfloat
|
||||||
|
|
||||||
proc setUniformV4*[T](loc: GLint, vecs: var openarray[TV4[T]]) =
|
proc setUniformV4*[T](loc: GLint, vecs: var openArray[TV4[T]]) =
|
||||||
glUniform4fv(loc, vecs.len.GLsizei, cast[ptr GLfloat](vecs[0].addr))
|
glUniform4fv(loc, vecs.len.GLsizei, cast[ptr GLfloat](vecs[0].addr))
|
||||||
|
|
||||||
proc setUniformV4*[T](loc: GLint, vec: TV4[T]) =
|
proc setUniformV4*[T](loc: GLint, vec: TV4[T]) =
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ proc newVert*(rect: rect.TRect): seq[TVert] =
|
||||||
proc newVertAttrib(i: GLuint, size: GLint, stride: GLsizei, offset: GLvoid): TVertAttrib =
|
proc newVertAttrib(i: GLuint, size: GLint, stride: GLsizei, offset: GLvoid): TVertAttrib =
|
||||||
TVertAttrib(i: i, size: size, stride: stride, offset: offset)
|
TVertAttrib(i: i, size: size, stride: stride, offset: offset)
|
||||||
|
|
||||||
proc genBuf*[T](vboTarget, objUsage: GLenum, data: var openarray[T]): GLuint =
|
proc genBuf*[T](vboTarget, objUsage: GLenum, data: var openArray[T]): GLuint =
|
||||||
result = 0.GLuint
|
result = 0.GLuint
|
||||||
?glGenBuffers(1, result.addr)
|
?glGenBuffers(1, result.addr)
|
||||||
?glBindBuffer(vboTarget, result)
|
?glBindBuffer(vboTarget, result)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ but expression 'nesting + 1' is of type: int
|
||||||
# line 15
|
# line 15
|
||||||
func default(T: typedesc[array]): T = discard
|
func default(T: typedesc[array]): T = discard
|
||||||
doAssert default(array[3, int]) == [0, 0, 0]
|
doAssert default(array[3, int]) == [0, 0, 0]
|
||||||
func shapeBad*[T: not char](s: openarray[T], rank: static[int], nesting = 0, parent_shape = default(array[rank, int])): array[rank, int] =
|
func shapeBad*[T: not char](s: openArray[T], rank: static[int], nesting = 0, parent_shape = default(array[rank, int])): array[rank, int] =
|
||||||
result = parent_shape
|
result = parent_shape
|
||||||
result[nesting] = s.len
|
result[nesting] = s.len
|
||||||
when (T is seq|array):
|
when (T is seq|array):
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ proc acc(x: var Foo): var ref Bar =
|
||||||
|
|
||||||
proc test(maybeFoo: var Foo,
|
proc test(maybeFoo: var Foo,
|
||||||
maybeSeq: var seq[ref Bar],
|
maybeSeq: var seq[ref Bar],
|
||||||
bars: var openarray[ref Bar],
|
bars: var openArray[ref Bar],
|
||||||
maybeTup: var Tup) =
|
maybeTup: var Tup) =
|
||||||
var bb: ref Bar
|
var bb: ref Bar
|
||||||
maybeFoo.rmaybe = bb
|
maybeFoo.rmaybe = bb
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ proc initTable*[A, B](initialSize=64): TTable[A, B] =
|
||||||
result.counter = 0
|
result.counter = 0
|
||||||
newSeq(result.data, initialSize)
|
newSeq(result.data, initialSize)
|
||||||
|
|
||||||
proc toTable*[A, B](pairs: openarray[tuple[key: A,
|
proc toTable*[A, B](pairs: openArray[tuple[key: A,
|
||||||
val: B]]): TTable[A, B] =
|
val: B]]): TTable[A, B] =
|
||||||
## creates a new hash table that contains the given `pairs`.
|
## creates a new hash table that contains the given `pairs`.
|
||||||
result = initTable[A, B](nextPowerOfTwo(pairs.len+10))
|
result = initTable[A, B](nextPowerOfTwo(pairs.len+10))
|
||||||
|
|
|
||||||
|
|
@ -6,4 +6,4 @@ discard """
|
||||||
# Tests a special bug
|
# Tests a special bug
|
||||||
|
|
||||||
var
|
var
|
||||||
x: ref openarray[string] #ERROR_MSG invalid type
|
x: ref openArray[string] #ERROR_MSG invalid type
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ discard """
|
||||||
output: "5 - [1]"
|
output: "5 - [1]"
|
||||||
"""
|
"""
|
||||||
type
|
type
|
||||||
TProc = proc (n: int, m: openarray[int64]) {.nimcall.}
|
TProc = proc (n: int, m: openArray[int64]) {.nimcall.}
|
||||||
|
|
||||||
proc Foo(x: int, P: TProc) =
|
proc Foo(x: int, P: TProc) =
|
||||||
P(x, [ 1'i64 ])
|
P(x, [ 1'i64 ])
|
||||||
|
|
||||||
proc Bar(n: int, m: openarray[int64]) =
|
proc Bar(n: int, m: openArray[int64]) =
|
||||||
echo($n & " - " & repr(m))
|
echo($n & " - " & repr(m))
|
||||||
|
|
||||||
Foo(5, Bar) #OUT 5 - [1]
|
Foo(5, Bar) #OUT 5 - [1]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ discard """
|
||||||
|
|
||||||
proc choose(b: openArray[string]): string = return b[0]
|
proc choose(b: openArray[string]): string = return b[0]
|
||||||
|
|
||||||
proc p(a, b: openarray[string]): int =
|
proc p(a, b: openArray[string]): int =
|
||||||
result = a.len + b.len - 1
|
result = a.len + b.len - 1
|
||||||
for j in 0 .. a.len: inc(result)
|
for j in 0 .. a.len: inc(result)
|
||||||
discard choose(a)
|
discard choose(a)
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,14 @@ var
|
||||||
raa = [11,12,13]
|
raa = [11,12,13]
|
||||||
|
|
||||||
#bug #3586
|
#bug #3586
|
||||||
proc mutate[T](arr:openarray[T], brr: openArray[T]) =
|
proc mutate[T](arr:openArray[T], brr: openArray[T]) =
|
||||||
for i in 0..arr.len-1:
|
for i in 0..arr.len-1:
|
||||||
doAssert(arr[i] == brr[i])
|
doAssert(arr[i] == brr[i])
|
||||||
|
|
||||||
mutate(arr, arr)
|
mutate(arr, arr)
|
||||||
|
|
||||||
#bug #2240
|
#bug #2240
|
||||||
proc f(a: openarray[int], b: openArray[int]) =
|
proc f(a: openArray[int], b: openArray[int]) =
|
||||||
for i in 0..a.len-1:
|
for i in 0..a.len-1:
|
||||||
doAssert(a[i] == b[i])
|
doAssert(a[i] == b[i])
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ ra[2] = 13
|
||||||
f(ra[], raa)
|
f(ra[], raa)
|
||||||
|
|
||||||
#bug #2240b
|
#bug #2240b
|
||||||
proc fillBuffer(buf: var openarray[char]) =
|
proc fillBuffer(buf: var openArray[char]) =
|
||||||
for i in 0..buf.len-1:
|
for i in 0..buf.len-1:
|
||||||
buf[i] = chr(i)
|
buf[i] = chr(i)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -264,8 +264,8 @@ proc init*[T](hmctx: HMAC[T], key: ptr byte, ulen: uint) =
|
||||||
const sizeBlock = hmctx.sizeBlock
|
const sizeBlock = hmctx.sizeBlock
|
||||||
echo sizeBlock
|
echo sizeBlock
|
||||||
|
|
||||||
proc hmac*[A, B](HashType: typedesc, key: openarray[A],
|
proc hmac*[A, B](HashType: typedesc, key: openArray[A],
|
||||||
data: openarray[B]) =
|
data: openArray[B]) =
|
||||||
var ctx: HMAC[HashType]
|
var ctx: HMAC[HashType]
|
||||||
ctx.init(nil, 0)
|
ctx.init(nil, 0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,12 @@ const msb3999 = mostSignificantBit(3999)
|
||||||
|
|
||||||
echo msb3999, " ", mostSignificantBit(0), " ", square(44)
|
echo msb3999, " ", mostSignificantBit(0), " ", square(44)
|
||||||
|
|
||||||
proc filter[T](a: openarray[T], predicate: proc (x: T): bool): seq[T] =
|
proc filter[T](a: openArray[T], predicate: proc (x: T): bool): seq[T] =
|
||||||
result = @[] # @[] constructs the empty seq
|
result = @[] # @[] constructs the empty seq
|
||||||
for x in a:
|
for x in a:
|
||||||
if predicate(x): result.add(x)
|
if predicate(x): result.add(x)
|
||||||
|
|
||||||
proc map[T, S](a: openarray[T], fn: proc (x: T): S): seq[S] =
|
proc map[T, S](a: openArray[T], fn: proc (x: T): S): seq[S] =
|
||||||
newSeq(result, a.len)
|
newSeq(result, a.len)
|
||||||
for i in 0 ..< a.len: result[i] = fn(a[i])
|
for i in 0 ..< a.len: result[i] = fn(a[i])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ suite "Integration with Nim":
|
||||||
check(input3.toLangSymbol == expected)
|
check(input3.toLangSymbol == expected)
|
||||||
|
|
||||||
test "advanced proc parsing with Nim identifier normalization":
|
test "advanced proc parsing with Nim identifier normalization":
|
||||||
let input = """`proc binarySearch*[T, K](a: openArray[T]; key: K;
|
let input = """`proc binarySearch*[T, K](a: openarray[T]; key: K;
|
||||||
cmp: proc (x: T; y: K): int)`_""".rstParseTest
|
cmp: proc (x: T; y: K): int)`_""".rstParseTest
|
||||||
let expected = LangSymbol(symKind: "proc",
|
let expected = LangSymbol(symKind: "proc",
|
||||||
name: "binarysearch",
|
name: "binarysearch",
|
||||||
|
|
@ -90,7 +90,7 @@ suite "Integration with Nim":
|
||||||
check(input.toLangSymbol == expected)
|
check(input.toLangSymbol == expected)
|
||||||
|
|
||||||
test "the same without proc":
|
test "the same without proc":
|
||||||
let input = """`binarySearch*[T, K](a: openArray[T]; key: K;
|
let input = """`binarySearch*[T, K](a: openarray[T]; key: K;
|
||||||
cmp: proc (x: T; y: K): int {.closure.})`_""".rstParseTest
|
cmp: proc (x: T; y: K): int {.closure.})`_""".rstParseTest
|
||||||
let expected = LangSymbol(symKind: "",
|
let expected = LangSymbol(symKind: "",
|
||||||
name: "binarysearch",
|
name: "binarysearch",
|
||||||
|
|
|
||||||
|
|
@ -210,12 +210,12 @@ const
|
||||||
"::a:b:85:e4d9:252.9.229.056",
|
"::a:b:85:e4d9:252.9.229.056",
|
||||||
]
|
]
|
||||||
|
|
||||||
proc ok(pos: openarray[string]) =
|
proc ok(pos: openArray[string]) =
|
||||||
for p in pos:
|
for p in pos:
|
||||||
if not isIpAddress(p):
|
if not isIpAddress(p):
|
||||||
echo "failure ", p
|
echo "failure ", p
|
||||||
|
|
||||||
proc notok(neg: openarray[string]) =
|
proc notok(neg: openArray[string]) =
|
||||||
for n in neg:
|
for n in neg:
|
||||||
if isIpAddress(n):
|
if isIpAddress(n):
|
||||||
echo "failure ", n
|
echo "failure ", n
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ template main() =
|
||||||
doAssert repr(arr) == "[1, 2, 3]"
|
doAssert repr(arr) == "[1, 2, 3]"
|
||||||
|
|
||||||
block: # bug #7878
|
block: # bug #7878
|
||||||
proc reprOpenarray(variable: var openarray[int]): string = repr(variable)
|
proc reprOpenarray(variable: var openArray[int]): string = repr(variable)
|
||||||
when defined(js): discard # BUG: doesn't work
|
when defined(js): discard # BUG: doesn't work
|
||||||
else:
|
else:
|
||||||
doAssert reprOpenarray(arr) == "[1, 2, 3]"
|
doAssert reprOpenarray(arr) == "[1, 2, 3]"
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ doAssert yy == ""
|
||||||
proc bar(arg: cstring) =
|
proc bar(arg: cstring) =
|
||||||
doAssert arg[0] == '\0'
|
doAssert arg[0] == '\0'
|
||||||
|
|
||||||
proc baz(arg: openarray[char]) =
|
proc baz(arg: openArray[char]) =
|
||||||
doAssert arg.len == 0
|
doAssert arg.len == 0
|
||||||
|
|
||||||
proc stringCompare() =
|
proc stringCompare() =
|
||||||
|
|
|
||||||
|
|
@ -131,12 +131,12 @@ let str = "0123456789"
|
||||||
foo(toOpenArrayByte(str, 0, str.high))
|
foo(toOpenArrayByte(str, 0, str.high))
|
||||||
|
|
||||||
|
|
||||||
template boundedOpenArray[T](x: seq[T], first, last: int): openarray[T] =
|
template boundedOpenArray[T](x: seq[T], first, last: int): openArray[T] =
|
||||||
toOpenarray(x, max(0, first), min(x.high, last))
|
toOpenarray(x, max(0, first), min(x.high, last))
|
||||||
|
|
||||||
# bug #9281
|
# bug #9281
|
||||||
|
|
||||||
proc foo[T](x: openarray[T]) =
|
proc foo[T](x: openArray[T]) =
|
||||||
echo x.len
|
echo x.len
|
||||||
|
|
||||||
let a = @[1, 2, 3]
|
let a = @[1, 2, 3]
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ when true: #embeddingTest
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Expression template
|
# Expression template
|
||||||
proc test_expression(nums: openarray[int] = []): string =
|
proc test_expression(nums: openArray[int] = []): string =
|
||||||
var i = 2
|
var i = 2
|
||||||
tmpli html"""
|
tmpli html"""
|
||||||
$(no_substitution())
|
$(no_substitution())
|
||||||
|
|
@ -171,7 +171,7 @@ when true: #embeddingTest
|
||||||
<div id="age">Age: $($nums[i] & "!!")</div>
|
<div id="age">Age: $($nums[i] & "!!")</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc test_statements(nums: openarray[int] = []): string =
|
proc test_statements(nums: openArray[int] = []): string =
|
||||||
tmpli html"""
|
tmpli html"""
|
||||||
$(test_expression(nums))
|
$(test_expression(nums))
|
||||||
$if true {
|
$if true {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#? stdtmpl
|
#? stdtmpl
|
||||||
#proc sunsetTemplate*(current, ticker, content: string,
|
#proc sunsetTemplate*(current, ticker, content: string,
|
||||||
# tabs: openarray[array[0..1, string]]): string =
|
# tabs: openArray[array[0..1, string]]): string =
|
||||||
# result = ""
|
# result = ""
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ block t2585:
|
||||||
st
|
st
|
||||||
echo "a ", $fb
|
echo "a ", $fb
|
||||||
|
|
||||||
proc render(rdat: var RenderData; passes: var openarray[RenderPass]; proj: Mat2;
|
proc render(rdat: var RenderData; passes: var openArray[RenderPass]; proj: Mat2;
|
||||||
indexType = 1) =
|
indexType = 1) =
|
||||||
for i in 0 ..< len(passes):
|
for i in 0 ..< len(passes):
|
||||||
echo "blah ", repr(passes[i])
|
echo "blah ", repr(passes[i])
|
||||||
|
|
|
||||||
|
|
@ -477,7 +477,7 @@ proc writeformat(o: var Writer; b: bool; fmt: Format) =
|
||||||
else:
|
else:
|
||||||
raise newException(FormatError, "Boolean values must of one of the following types: s,b,o,x,X,d,n")
|
raise newException(FormatError, "Boolean values must of one of the following types: s,b,o,x,X,d,n")
|
||||||
|
|
||||||
proc writeformat(o: var Writer; ary: openarray[system.any]; fmt: Format) =
|
proc writeformat(o: var Writer; ary: openArray[system.any]; fmt: Format) =
|
||||||
## Write array `ary` according to format `fmt` using output object
|
## Write array `ary` according to format `fmt` using output object
|
||||||
## `o` and output function `add`.
|
## `o` and output function `add`.
|
||||||
if ary.len == 0: return
|
if ary.len == 0: return
|
||||||
|
|
@ -657,7 +657,7 @@ proc literal[T](x: T): NimNode {.compiletime, nosideeffect.} =
|
||||||
result = newLit(x)
|
result = newLit(x)
|
||||||
|
|
||||||
proc generatefmt(fmtstr: string;
|
proc generatefmt(fmtstr: string;
|
||||||
args: var openarray[tuple[arg:NimNode, cnt:int]];
|
args: var openArray[tuple[arg:NimNode, cnt:int]];
|
||||||
arg: var int;): seq[tuple[val, fmt:NimNode]] {.compiletime.} =
|
arg: var int;): seq[tuple[val, fmt:NimNode]] {.compiletime.} =
|
||||||
## fmtstr
|
## fmtstr
|
||||||
## the format string
|
## the format string
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ type
|
||||||
|
|
||||||
proc newDog():PDog = new(result)
|
proc newDog():PDog = new(result)
|
||||||
proc newCat():PCat = new(result)
|
proc newCat():PCat = new(result)
|
||||||
proc test(a:openarray[PAnimal])=
|
proc test(a:openArray[PAnimal])=
|
||||||
echo("dummy")
|
echo("dummy")
|
||||||
|
|
||||||
#test(newDog(),newCat()) #does not work
|
#test(newDog(),newCat()) #does not work
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ discard """
|
||||||
|
|
||||||
import json, tables, algorithm
|
import json, tables, algorithm
|
||||||
|
|
||||||
proc outp(a: openarray[int]) =
|
proc outp(a: openArray[int]) =
|
||||||
stdout.write "["
|
stdout.write "["
|
||||||
for i in a: stdout.write($i & " ")
|
for i in a: stdout.write($i & " ")
|
||||||
stdout.write "]\n"
|
stdout.write "]\n"
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,18 @@ discard """
|
||||||
"""
|
"""
|
||||||
var s = "HI"
|
var s = "HI"
|
||||||
|
|
||||||
proc x (zz: openarray[char]) =
|
proc x (zz: openArray[char]) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
x s
|
x s
|
||||||
|
|
||||||
proc z [T] (zz: openarray[T]) =
|
proc z [T] (zz: openArray[T]) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
z s
|
z s
|
||||||
z([s,s,s])
|
z([s,s,s])
|
||||||
|
|
||||||
proc y [T] (arg: var openarray[T]) =
|
proc y [T] (arg: var openArray[T]) =
|
||||||
arg[0] = 'X'
|
arg[0] = 'X'
|
||||||
y s
|
y s
|
||||||
doAssert s == "XI"
|
doAssert s == "XI"
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ echo foo(x)
|
||||||
|
|
||||||
type
|
type
|
||||||
F = object
|
F = object
|
||||||
oa: openarray[int]
|
oa: openArray[int]
|
||||||
|
|
||||||
let s1 = @[1,3,4,5,6]
|
let s1 = @[1,3,4,5,6]
|
||||||
var test = F(oa: toOpenArray(s1, 0, 2))
|
var test = F(oa: toOpenArray(s1, 0, 2))
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ type NodeType* = enum
|
||||||
type TokenType* = enum
|
type TokenType* = enum
|
||||||
ttWhitespace
|
ttWhitespace
|
||||||
|
|
||||||
proc enumTable*[A, B, C](a: openarray[tuple[key: A, val: B]], ret: typedesc[C]): C =
|
proc enumTable*[A, B, C](a: openArray[tuple[key: A, val: B]], ret: typedesc[C]): C =
|
||||||
for item in a:
|
for item in a:
|
||||||
result[item.key] = item.val
|
result[item.key] = item.val
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue