mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 00:41:28 +00:00
fixes #105
This commit is contained in:
@@ -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.
@@ -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
59
tests/run/tsortdev.nim
Executable 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"
|
||||
|
||||
1
tests/testdata/string
vendored
1
tests/testdata/string
vendored
@@ -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.
|
||||
1
todo.txt
1
todo.txt
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user