Merge branch 'devel' of https://github.com/Araq/Nimrod into devel
This commit is contained in:
commit
3270676e77
34 changed files with 567 additions and 167 deletions
|
|
@ -15,16 +15,24 @@ const
|
|||
var clientCount = 0
|
||||
|
||||
proc sendMessages(disp: PDispatcher, client: TSocketHandle): PFuture[int] {.async.} =
|
||||
echo("entering sendMessages")
|
||||
for i in 0 .. <messagesToSend:
|
||||
discard await disp.send(client, "Message " & $i & "\c\L")
|
||||
discard await disp.send(client, "Message " & $i & "\c\L")
|
||||
echo("returning sendMessages")
|
||||
|
||||
proc launchSwarm(disp: PDispatcher, port: TPort): PFuture[int] {.async.} =
|
||||
for i in 0 .. <swarmSize:
|
||||
var sock = socket()
|
||||
# TODO: We may need to explicitly register and unregister the fd.
|
||||
# This is because when the socket is closed, selectors is not aware
|
||||
# that it has been closed. While epoll is. Perhaps we should just unregister
|
||||
# in close()?
|
||||
echo(sock.cint)
|
||||
#disp.register(sock)
|
||||
discard await disp.connect(sock, "localhost", port)
|
||||
when true:
|
||||
discard await sendMessages(disp, sock)
|
||||
echo("Calling close")
|
||||
sock.close()
|
||||
else:
|
||||
# Issue #932: https://github.com/Araq/Nimrod/issues/932
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ macro selectType(a, b: typedesc): typedesc =
|
|||
type
|
||||
Foo[T] = object
|
||||
data1: array[T.high, int]
|
||||
data2: array[typeNameLen(T), float] # data3: array[0..T.typeNameLen, selectType(float, int)]
|
||||
data2: array[typeNameLen(T), float]
|
||||
data3: array[0..T.typeNameLen, selectType(float, int)]
|
||||
|
||||
MyEnum = enum A, B, C, D
|
||||
|
||||
|
|
@ -27,10 +28,15 @@ echo high(f1.data2) # (MyEnum.len = 6) - 1 == 5
|
|||
echo high(f2.data1) # 127 - 1 == 126
|
||||
echo high(f2.data2) # int8.len - 1 == 3
|
||||
|
||||
#static:
|
||||
# assert high(f1.data1) == ord(D)
|
||||
# assert high(f1.data2) == 6 # length of MyEnum
|
||||
static:
|
||||
assert high(f1.data1) == ord(C)
|
||||
assert high(f1.data2) == 5 # length of MyEnum minus one, because we used T.high
|
||||
|
||||
# assert high(f2.data1) == 127
|
||||
# assert high(f2.data2) == 4 # length of int8
|
||||
assert high(f2.data1) == 126
|
||||
assert high(f2.data2) == 3
|
||||
|
||||
assert high(f1.data3) == 6 # length of MyEnum
|
||||
assert high(f2.data3) == 4 # length of int8
|
||||
|
||||
assert f2.data3[0] is float
|
||||
|
||||
|
|
|
|||
38
tests/iter/tchainediterators.nim
Normal file
38
tests/iter/tchainediterators.nim
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
discard """
|
||||
output: '''16
|
||||
32
|
||||
48
|
||||
64
|
||||
128
|
||||
192
|
||||
'''
|
||||
"""
|
||||
|
||||
iterator gaz(it: iterator{.inline.}): type(it) =
|
||||
for x in it:
|
||||
yield x*2
|
||||
|
||||
iterator baz(it: iterator{.inline.}) =
|
||||
for x in gaz(it):
|
||||
yield x*2
|
||||
|
||||
type T1 = auto
|
||||
|
||||
iterator bar(it: iterator: T1{.inline.}): T1 =
|
||||
for x in baz(it):
|
||||
yield x*2
|
||||
|
||||
iterator foo[T](x: iterator: T{.inline.}): T =
|
||||
for e in bar(x):
|
||||
yield e*2
|
||||
|
||||
var s = @[1, 2, 3]
|
||||
|
||||
# pass an interator several levels deep:
|
||||
for x in s.items.foo:
|
||||
echo x
|
||||
|
||||
# use some complex iterator as an input for another one:
|
||||
for x in s.items.baz.foo:
|
||||
echo x
|
||||
|
||||
26
tests/iter/titerable.nim
Normal file
26
tests/iter/titerable.nim
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
discard """
|
||||
output: '''2
|
||||
4
|
||||
6
|
||||
4
|
||||
8
|
||||
12
|
||||
'''
|
||||
"""
|
||||
|
||||
iterator map[T, U](s: iterator:T{.inline.}, f: proc(x: T): U): U =
|
||||
for e in s: yield f(e)
|
||||
|
||||
template toSeq(s: expr): expr =
|
||||
var res = newSeq[type(s)](0)
|
||||
for e in s: res.add(e)
|
||||
res
|
||||
|
||||
var s1 = @[1, 2, 3]
|
||||
for x in map(s1.items, proc (a:int): int = a*2):
|
||||
echo x
|
||||
|
||||
var s2 = toSeq(map(s1.items, proc (a:int): int = a*4))
|
||||
for x in s2:
|
||||
echo x
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
file: "tstaticparams.nim"
|
||||
output: "abracadabra\ntest\n3"
|
||||
output: "abracadabra\ntest\n3\n15\4"
|
||||
"""
|
||||
|
||||
type
|
||||
|
|
@ -11,8 +11,8 @@ type
|
|||
data: array[I, T]
|
||||
|
||||
TA1[T; I: static[int]] = array[I, T]
|
||||
# TA2[T; I: static[int]] = array[0..I, T]
|
||||
# TA3[T; I: static[int]] = array[I-1, T]
|
||||
TA2[T; I: static[int]] = array[0..I, T]
|
||||
TA3[T; I: static[int]] = array[I-1, T]
|
||||
|
||||
proc takeFoo(x: TFoo) =
|
||||
echo "abracadabra"
|
||||
|
|
@ -26,6 +26,22 @@ echo high(y.data)
|
|||
|
||||
var
|
||||
t1: TA1[float, 1]
|
||||
# t2: TA2[string, 4]
|
||||
# t3: TA3[int, 10]
|
||||
t2: TA2[string, 4]
|
||||
t3: TA3[int, 10]
|
||||
|
||||
# example from the manual:
|
||||
type
|
||||
Matrix[M,N: static[int]; T] = array[0..(M*N - 1), T]
|
||||
# Note how `Number` is just a type constraint here, while
|
||||
# `static[int]` requires us to supply a compile-time int value
|
||||
|
||||
AffineTransform2D[T] = Matrix[3, 3, T]
|
||||
AffineTransform3D[T] = Matrix[4, 4, T]
|
||||
|
||||
var m: AffineTransform3D[float]
|
||||
echo high(m)
|
||||
|
||||
proc getRows(mtx: Matrix): int =
|
||||
result = mtx.M
|
||||
|
||||
echo getRows(m)
|
||||
|
|
|
|||
12
tests/overload/tissue966.nim
Normal file
12
tests/overload/tissue966.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
discard """
|
||||
msg: 'type mismatch: got (PTest)'
|
||||
"""
|
||||
|
||||
type
|
||||
PTest = ref object
|
||||
|
||||
proc test(x: PTest, y: int) = nil
|
||||
|
||||
var buf: PTest
|
||||
buf.test()
|
||||
|
||||
52
tests/static/tstaticparammacro.nim
Normal file
52
tests/static/tstaticparammacro.nim
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
discard """
|
||||
msg: '''letters
|
||||
aa
|
||||
bb
|
||||
numbers
|
||||
11
|
||||
22
|
||||
AST a
|
||||
[(11, 22), (33, 44)]
|
||||
AST b
|
||||
(e: [55, 66], f: [77, 88])
|
||||
55
|
||||
'''
|
||||
"""
|
||||
|
||||
import macros
|
||||
|
||||
type
|
||||
TConfig = tuple
|
||||
letters: seq[string]
|
||||
numbers:seq[int]
|
||||
|
||||
const data: Tconfig = (@["aa", "bb"], @[11, 22])
|
||||
|
||||
macro mymacro(data: static[TConfig]): stmt =
|
||||
echo "letters"
|
||||
for s in items(data.letters):
|
||||
echo s
|
||||
echo "numbers"
|
||||
for n in items(data.numbers):
|
||||
echo n
|
||||
|
||||
mymacro(data)
|
||||
|
||||
type
|
||||
Ta = seq[tuple[c:int, d:int]]
|
||||
Tb = tuple[e:seq[int], f:seq[int]]
|
||||
|
||||
const
|
||||
a : Ta = @[(11, 22), (33, 44)]
|
||||
b : Tb = (@[55,66], @[77, 88])
|
||||
|
||||
macro mA(data: static[Ta]): stmt =
|
||||
echo "AST a \n", repr(data)
|
||||
|
||||
macro mB(data: static[Tb]): stmt =
|
||||
echo "AST b \n", repr(data)
|
||||
echo data.e[0]
|
||||
|
||||
mA(a)
|
||||
mB(b)
|
||||
|
||||
|
|
@ -2,44 +2,51 @@ var x: ptr int
|
|||
|
||||
x = cast[ptr int](alloc(7))
|
||||
assert x != nil
|
||||
|
||||
x = alloc(int, 3)
|
||||
x = cast[ptr int](x.realloc(2))
|
||||
assert x != nil
|
||||
x.dealloc()
|
||||
|
||||
x = alloc0(int, 4)
|
||||
x = createU(int, 3)
|
||||
assert x != nil
|
||||
x.free()
|
||||
|
||||
x = create(int, 4)
|
||||
assert cast[ptr array[4, int]](x)[0] == 0
|
||||
assert cast[ptr array[4, int]](x)[1] == 0
|
||||
assert cast[ptr array[4, int]](x)[2] == 0
|
||||
assert cast[ptr array[4, int]](x)[3] == 0
|
||||
|
||||
x = cast[ptr int](x.realloc(2))
|
||||
x = x.resize(4)
|
||||
assert x != nil
|
||||
|
||||
x = x.reallocType(4)
|
||||
assert x != nil
|
||||
x.dealloc()
|
||||
x.free()
|
||||
|
||||
x = cast[ptr int](allocShared(100))
|
||||
assert x != nil
|
||||
deallocShared(x)
|
||||
|
||||
x = allocShared(int, 3)
|
||||
x = createSharedU(int, 3)
|
||||
assert x != nil
|
||||
x.deallocShared()
|
||||
x.freeShared()
|
||||
|
||||
x = allocShared0(int, 3)
|
||||
x = createShared(int, 3)
|
||||
assert x != nil
|
||||
assert cast[ptr array[3, int]](x)[0] == 0
|
||||
assert cast[ptr array[3, int]](x)[1] == 0
|
||||
assert cast[ptr array[3, int]](x)[2] == 0
|
||||
|
||||
x = cast[ptr int](reallocShared(x, 2))
|
||||
assert x != nil
|
||||
x = cast[ptr int](x.resizeShared(2))
|
||||
assert x != nil
|
||||
x.freeShared()
|
||||
|
||||
x = reallocType(x, 12)
|
||||
x = create(int, 10)
|
||||
assert x != nil
|
||||
x = x.resize(12)
|
||||
assert x != nil
|
||||
x.dealloc()
|
||||
|
||||
x = reallocSharedType(x, 1)
|
||||
x = createShared(int, 1)
|
||||
assert x != nil
|
||||
x.deallocShared()
|
||||
x = x.resizeShared(1)
|
||||
assert x != nil
|
||||
x.freeShared()
|
||||
|
|
|
|||
16
tests/template/tissue909.nim
Normal file
16
tests/template/tissue909.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import macros
|
||||
|
||||
template baz() =
|
||||
proc bar() =
|
||||
var x = 5
|
||||
iterator foo(): int {.closure.} =
|
||||
echo x
|
||||
var y = foo
|
||||
discard y()
|
||||
|
||||
macro test(): stmt =
|
||||
result = getAst(baz())
|
||||
echo(treeRepr(result))
|
||||
|
||||
test()
|
||||
bar()
|
||||
|
|
@ -174,6 +174,10 @@ proc generateJson*(filename: string, commit: int) =
|
|||
on A.name = B.name and A.category = B.category
|
||||
where A.[commit] = ? and B.[commit] = ? and A.machine = ?
|
||||
and A.result != B.result"""
|
||||
selResults = """select
|
||||
name, category, target, action, result, expected, given
|
||||
from TestResult
|
||||
where [commit] = ?"""
|
||||
var db = open(connection="testament.db", user="testament", password="",
|
||||
database="testament")
|
||||
let lastCommit = db.getCommit(commit)
|
||||
|
|
@ -189,6 +193,20 @@ proc generateJson*(filename: string, commit: int) =
|
|||
|
||||
outfile.writeln("""{"total": $#, "passed": $#, "skipped": $#""" % data)
|
||||
|
||||
let results = newJArray()
|
||||
for row in db.rows(sql(selResults), lastCommit):
|
||||
var obj = newJObject()
|
||||
obj["name"] = %row[0]
|
||||
obj["category"] = %row[1]
|
||||
obj["target"] = %row[2]
|
||||
obj["action"] = %row[3]
|
||||
obj["result"] = %row[4]
|
||||
obj["expected"] = %row[5]
|
||||
obj["given"] = %row[6]
|
||||
results.add(obj)
|
||||
outfile.writeln(""", "results": """)
|
||||
outfile.write(results.pretty)
|
||||
|
||||
if not previousCommit.isNil:
|
||||
let diff = newJArray()
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,17 @@ discard """
|
|||
3
|
||||
1
|
||||
2
|
||||
3'''
|
||||
3
|
||||
1
|
||||
2
|
||||
3
|
||||
1
|
||||
2
|
||||
3
|
||||
aa
|
||||
bb
|
||||
aa
|
||||
bb'''
|
||||
"""
|
||||
|
||||
const s = @[1,2,3]
|
||||
|
|
@ -19,3 +29,27 @@ static:
|
|||
for e in s:
|
||||
echo e
|
||||
|
||||
macro bar(x: static[seq[int]]): stmt =
|
||||
for e in x:
|
||||
echo e
|
||||
|
||||
bar s
|
||||
bar(@[1, 2, 3])
|
||||
|
||||
type
|
||||
TData = tuple
|
||||
letters: seq[string]
|
||||
numbers: seq[int]
|
||||
|
||||
const data: TData = (@["aa", "bb"], @[11, 22])
|
||||
|
||||
static:
|
||||
var m = data
|
||||
for x in m.letters:
|
||||
echo x
|
||||
|
||||
macro ff(d: static[TData]): stmt =
|
||||
for x in d.letters:
|
||||
echo x
|
||||
|
||||
ff(data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue