This commit is contained in:
Araq
2012-04-16 16:31:15 +02:00
parent a656409286
commit 17d67ab828
7 changed files with 63 additions and 85 deletions

View File

@@ -269,7 +269,9 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var PRope,
var arr = param.typ
if arr.kind == tyVar: arr = arr.sons[0]
var j = 0
while arr.Kind == tyOpenArray:
while arr.Kind == tyOpenArray:
# this fixes the 'sort' bug:
if param.typ.kind == tyVar: param.loc.s = OnUnknown
# need to pass hidden parameter:
appff(params, ", NI $1Len$2", ", @NI $1Len$2", [param.loc.r, j.toRope])
inc(j)
@@ -288,7 +290,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var PRope,
if tfVarargs in t.flags:
if params != nil: app(params, ", ")
app(params, "...")
if (params == nil) and (gCmd != cmdCompileToLLVM): app(params, "void)")
if params == nil and gCmd != cmdCompileToLLVM: app(params, "void)")
else: app(params, ")")
params = con("(", params)

Binary file not shown.

Binary file not shown.

View File

@@ -1,81 +0,0 @@
discard """
disabled: false
"""
import math, algorithm
proc sorted[T](a: openArray[T], order: TSortOrder): bool =
result = true
for i in 0 .. < a.high:
if cmp(a[i], a[i+1]) * order > 0:
echo "Out of order: ", a[i], " ", a[i+1]
result = false
proc bubbleSort[T](a: var openArray[T],
cmp: proc (x, y: T): int,
order = TSortOrder.Ascending) =
while true:
var sorted = true
for i in 0 .. a.len-2:
if cmp(a[i], a[i+1]) * order > 0:
swap(a[i], a[i+1])
sorted = false
if sorted: break
when isMainModule:
proc main() =
const order = Ascending
var data: seq[string] = @[]
var L = random(59)
for i in 0..2:
#echo "loop: ", i
#newSeq(data, L)
setLen(data, L)
for j in 0 .. L-1:
data[j] = $(math.random(90) - 10)
assert getRefcount(data[j]) == 1
{.watchpoint: data.}
var copy = data
for j in 0 .. L-1:
assert getRefcount(copy[j]) == 1
assert(cast[pointer](copy[j]) != cast[pointer](data[j]))
bubblesort(data, system.cmp, order)
if not sorted(data, order):
quit "bubblesort failed"
sort(copy, cmp, order)
for j in 0 .. L-1:
let rc = getRefcount(data[j])
if rc != 1:
echo "RC IST ", rc, " j: ", j
assert getRefcount(data[j]) == 1
when false:
if copy.len != data.len:
quit "lengths differ!"
for i in 0 .. copy.high:
if copy[i] != data[i]:
quit "algorithms differ!"
when false:
for i in 0..10_000:
var data: seq[int]
var L = random(59)
newSeq(data, L)
for j in 0 .. L-1:
data[j] = (math.random(90) - 10)
var copy = data
sort(data, cmp[int], order)
if not sorted(data, order):
quit "sort for seq[int] failed"
bubblesort(copy, system.cmp[int], order)
if copy.len != data.len:
quit "lengths differ!"
for i in 0 .. copy.high:
if copy[i] != data[i]:
quit "algorithms differ!"
main()
echo "done"

59
tests/run/tsortdev.nim Executable file
View File

@@ -0,0 +1,59 @@
discard """
output: "done"
"""
import algorithm, strutils
proc cmpPlatforms(a, b: string): int =
if a == b: return 0
var dashes = a.split('-')
var dashes2 = b.split('-')
if dashes[0] == dashes2[0]:
if dashes[1] == dashes2[1]: return system.cmp(a,b)
case dashes[1]
of "x86":
return 1
of "x86_64":
if dashes2[1] == "x86": return -1
else: return 1
of "ppc64":
if dashes2[1] == "x86" or dashes2[1] == "x86_64": return -1
else: return 1
else:
return system.cmp(dashes[1], dashes2[1])
else:
case dashes[0]
of "linux":
return 1
of "windows":
if dashes2[0] == "linux": return -1
else: return 1
of "macosx":
if dashes2[0] == "linux" or dashes2[0] == "windows": return -1
else: return 1
else:
if dashes2[0] == "linux" or dashes2[0] == "windows" or
dashes2[0] == "macosx": return -1
else:
return system.cmp(a, b)
proc sorted[T](a: openArray[T]): bool =
result = true
for i in 0 .. < a.high:
if cmpPlatforms(a[i], a[i+1]) > 0:
echo "Out of order: ", a[i], " ", a[i+1]
result = false
proc main() =
var testData = @["netbsd-x86_64", "windows-x86", "linux-x86_64", "linux-x86",
"linux-ppc64", "macosx-x86-1058", "macosx-x86-1068"]
sort(testData, cmpPlatforms)
doAssert sorted(testData)
for i in 0..1_000:
main()
echo "done"

View File

@@ -1 +0,0 @@
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

View File

@@ -45,7 +45,6 @@ Bugs
without ``-d:release`` leaks memory?
- bug: object {.pure, final.} does not work again!
- bug: {.error: "msg".} produces invalid pragma message
- bug: tsortdev does not run with native GC!!
- bug: pragma statements in combination with symbol files are evaluated twice
but this can lead to compilation errors