new tester; all tests categorized

This commit is contained in:
Araq
2014-01-13 02:10:03 +01:00
parent 51ee524109
commit 20b5f31c03
481 changed files with 794 additions and 2506 deletions

View File

@@ -1,7 +1,7 @@
#
#
# Maintenance program for Nimrod
# (c) Copyright 2013 Andreas Rumpf
# (c) Copyright 2014 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@@ -26,7 +26,7 @@ const
+-----------------------------------------------------------------+
| Maintenance program for Nimrod |
| Version $1|
| (c) 2013 Andreas Rumpf |
| (c) 2014 Andreas Rumpf |
+-----------------------------------------------------------------+
Build time: $2, $3
@@ -268,6 +268,11 @@ proc tests(args: string) =
exec(getCurrentDir() / "tests/tester".exe & " compile")
exec(getCurrentDir() / "tests/tester".exe & " run")
exec(getCurrentDir() / "tests/tester".exe & " merge")
when false:
# activate real soon:
exec("nimrod cc --taintMode:on tests/testament/tester")
exec(getCurrentDir() / "tests/testament/tester".exe & " all")
proc temp(args: string) =
var output = "compiler" / "nimrod".exe

View File

@@ -1,6 +0,0 @@
# Test a submodule
#type
# TStringArr = array [0.. *] of string
proc exportme* = nil

View File

@@ -1,68 +0,0 @@
#! stdtmpl
#proc sunsetTemplate*(current, ticker, content: string,
# tabs: openarray[array[0..1, string]]): string =
# result = ""
<!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">
<head>
<title>Nimrod Programming System</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="style/style.css" />
</head>
<body>
<div id="main">
<div id="links">
<!-- **** INSERT LINKS HERE **** -->
</div>
<div id="logo"><h1>Nimrod Programming System</h1></div>
<div id="content">
<div id="menu">
<ul>
#for item in items(tabs):
#var name = item[0]
#var t = item[1]
#if t == current:
<li><a id="selected" href="${t}.html" title = "Nimrod - $name">$name</a></li>
#else:
<li><a href="${t}.html" title = "Nimrod - $name">$name</a></li>
#end if
#end for
</ul>
</div>
<div id="column1">
<div class="sidebaritem">
<div class="sbihead">
<h1>latest news</h1>
</div>
<div class="sbicontent">
$ticker
</div>
</div>
<div class="sidebaritem">
<div class="sbihead">
<h1>additional links</h1>
</div>
<div class="sbilinks">
<!-- **** INSERT ADDITIONAL LINKS HERE **** -->
<ul>
<li><a class="reference" href="http://llvm.org">LLVM</a></li>
<li><a class="reference" href="http://gcc.gnu.org">GCC</a></li>
</ul>
</div>
</div>
</div>
<div id="column2">
$content
</div>
</div>
<div id="footer">
copyright &copy; 2008 Andreas Rumpf | Last update: ${getDateStr()}
| <a class="reference" href="http://validator.w3.org/check?uri=referer">XHTML 1.1</a>
| <a class="reference" href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>
| <a class="reference" href="http://www.dcarter.co.uk">design by dcarter</a>
</div>
</div>
</body>
</html>

View File

@@ -1,6 +0,0 @@
from sdl import PSurface
discard SDL.CreateRGBSurface(SDL.SWSURFACE, 23, 34,
32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xff000000'i32)

View File

@@ -1,14 +0,0 @@
# Test the command line
import
os, strutils
var
i: int
params = paramCount()
i = 0
writeln(stdout, "This exe: " & getAppFilename())
writeln(stdout, "Number of parameters: " & $params)
while i <= params:
writeln(stdout, paramStr(i))
i = i + 1

View File

@@ -1,12 +0,0 @@
proc p(a, b: int, c: proc ()) =
c()
p(1, 3):
echo 1
echo 3
p(1, 1, proc() =
echo 1
echo 2)

View File

@@ -1,16 +0,0 @@
import os
proc getDllName: string =
result = "mylib.dll"
if ExistsFile(result): return
result = "mylib2.dll"
if ExistsFile(result): return
quit("could not load dynamic library")
proc myImport(s: cstring) {.cdecl, importc, dynlib: getDllName().}
proc myImport2(s: int) {.cdecl, importc, dynlib: getDllName().}
myImport("test2")
myImport2(12)

View File

@@ -1,2 +0,0 @@
echo()

View File

@@ -1,3 +0,0 @@
# test the new endian magic
writeln(stdout, repr(system.cpuEndian))

View File

@@ -1,11 +0,0 @@
iterator fibonacci(): int =
var a = 0
var b = 1
while true:
yield a
var c = b
b = a
a = a + c

View File

@@ -1,7 +0,0 @@
#
import times, os
var start = epochTime()
os.sleep(1000)
echo epochTime() - start #OUT 1000

View File

@@ -1,51 +0,0 @@
import
gtk2, glib2, atk, gdk2, gdk2pixbuf, libglade2, pango,
pangoutils
proc hello(widget: PWidget, data: pointer) {.cdecl.} =
write(stdout, "Hello World\n")
proc delete_event(widget: PWidget, event: PEvent,
data: pointer): bool {.cdecl.} =
# If you return FALSE in the "delete_event" signal handler,
# GTK will emit the "destroy" signal. Returning TRUE means
# you don't want the window to be destroyed.
# This is useful for popping up 'are you sure you want to quit?'
# type dialogs.
write(stdout, "delete event occurred\n")
# Change TRUE to FALSE and the main window will be destroyed with
# a "delete_event".
return false
# Another callback
proc mydestroy(widget: PWidget, data: pointer) {.cdecl.} =
gtk2.main_quit()
proc mymain() =
# GtkWidget is the storage type for widgets
gtk2.nimrod_init()
var window = window_new(gtk2.WINDOW_TOPLEVEL)
discard g_signal_connect(window, "delete_event",
Gcallback(delete_event), nil)
discard g_signal_connect(window, "destroy", Gcallback(mydestroy), nil)
# Sets the border width of the window.
set_border_width(window, 10)
# Creates a new button with the label "Hello World".
var button = button_new("Hello World")
discard g_signal_connect(button, "clicked", Gcallback(hello), nil)
# This packs the button into the window (a gtk container).
add(window, button)
# The final step is to display this newly created widget.
show(button)
# and the window
show(window)
gtk2.main()
mymain()

View File

@@ -1,85 +0,0 @@
# Hallo
import
os, strutils, macros
type
TMyEnum = enum
meA, meB, meC, meD
when isMainModule:
{.hint: "this is the main file".}
proc fac[T](x: T): T =
# test recursive generic procs
if x <= 1: return 1
else: return x.`*`(fac(x-1))
macro macrotest(n: expr): stmt {.immediate.} =
let n = callsite()
expectKind(n, nnkCall)
expectMinLen(n, 2)
result = newNimNode(nnkStmtList, n)
for i in 2..n.len-1:
result.add(newCall("write", n[1], n[i]))
result.add(newCall("writeln", n[1], newStrLitNode("")))
macro debug(n: expr): stmt {.immediate.} =
let n = callsite()
result = newNimNode(nnkStmtList, n)
for i in 1..n.len-1:
result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i])))
result.add(newCall("write", newIdentNode("stdout"), newStrLitNode(": ")))
result.add(newCall("writeln", newIdentNode("stdout"), n[i]))
macrotest(stdout, "finally", 4, 5, "variable", "argument lists")
macrotest(stdout)
#GC_disable()
echo("This was compiled by Nimrod version " & system.nimrodVersion)
writeln(stdout, "Hello", " World", "!")
echo(["a", "b", "c", "d"].len)
for x in items(["What's", "your", "name", "?", ]):
echo(x)
var `name` = readLine(stdin)
{.breakpoint.}
echo("Hi " & thallo.name & "!\n")
debug(name)
var testseq: seq[string] = @[
"a", "b", "c", "d", "e"
]
echo(repr(testseq))
var dummy = "hello"
echo(substr(dummy, 2, 3))
echo($meC)
# test tuples:
for x, y in items([(1, 2), (3, 4), (6, 1), (5, 2)]):
echo x
echo y
proc simpleConst(): int = return 34
# test constant evaluation:
const
constEval3 = simpleConst()
constEval = "abc".contains('b')
constEval2 = fac(7)
echo(constEval3)
echo(constEval)
echo(constEval2)
echo(1.`+`(2))
for i in 2..6:
for j in countdown(i+4, 2):
echo(fac(i * j))
when isMainModule:
{.hint: "this is the main file".}

View File

@@ -1,71 +0,0 @@
type
Bar = object
x: int
Foo = object
rheap: ref Bar
rmaybe: ref Bar
rstack: ref Bar
list: seq[ref Bar]
listarr: array[0..5, ref Bar]
nestedtup: Tup
inner: TInner
inref: ref TInner
TInner = object
inref: ref Bar
Tup = tuple
tupbar: ref Bar
inner: TInner
proc acc(x: var Foo): var ref Bar =
result = x.rheap
proc test(maybeFoo: var Foo,
maybeSeq: var seq[ref Bar],
bars: var openarray[ref Bar],
maybeTup: var Tup) =
var bb: ref Bar
maybeFoo.rmaybe = bb
maybeFoo.list[3] = bb
maybeFoo.listarr[3] = bb
acc(maybeFoo) = bb
var localFoo: Foo
localFoo.rstack = bb
localFoo.list[3] = bb
localFoo.listarr[3] = bb
acc(localFoo) = bb
var heapFoo: ref Foo
heapFoo.rheap = bb
heapFoo.list[3] = bb
heapFoo.listarr[3] = bb
acc(heapFoo[]) = bb
heapFoo.nestedtup.tupbar = bb
heapFoo.nestedtup.inner.inref = bb
heapFoo.inner.inref = bb
heapFoo.inref.inref = bb
var locseq: seq[ref Bar]
locseq[3] = bb
var locarr: array[0..4, ref Bar]
locarr[3] = bb
maybeSeq[3] = bb
bars[3] = bb
maybeTup[0] = bb
var
ff: ref Foo
tt: Tup
gseq: seq[ref Bar]
new(ff)
test(ff[], gseq, gseq, tt)

View File

@@ -1,18 +0,0 @@
# test the new LastModificationTime() proc
import
os, times, strutils
proc main() =
var
a, b: TTime
a = getLastModificationTime(ParamStr(1))
b = getLastModificationTime(ParamStr(2))
writeln(stdout, $a)
writeln(stdout, $b)
if a < b:
Write(stdout, "$2 is newer than $1\n" % [ParamStr(1), ParamStr(2)])
else:
Write(stdout, "$1 is newer than $2\n" % [ParamStr(1), ParamStr(2)])
main()

View File

@@ -1,24 +0,0 @@
# Test wether the bindings at least compile...
import
unicode, cgi, terminal, libcurl,
parsexml, parseopt, parsecfg,
osproc, complex,
sdl, smpeg, sdl_gfx, sdl_net, sdl_mixer, sdl_ttf,
sdl_image, sdl_mixer_nosmpeg,
cursorfont, xatom, xf86vmode, xkb, xrandr, xshm, xvlib, keysym, xcms, xi,
xkblib, xrender, xutil, x, xf86dga, xinerama, xlib, xresource, xv,
gtk2, glib2, pango, gdk2,
cairowin32, cairoxlib,
odbcsql,
gl, glut, glu, glx, glext, wingl,
lua, lualib, lauxlib, mysql, sqlite3, python, tcl,
db_postgres, db_mysql, db_sqlite, ropes, sockets, browsers, httpserver,
httpclient, parseutils, unidecode, xmldom, xmldomparser, xmltree, xmlparser,
htmlparser, re, graphics, colors, pegs, subexes, dialogs
when defined(linux):
import
zlib, zipfiles
writeln(stdout, "test compilation of binding modules")

View File

@@ -1,87 +0,0 @@
# Test nested loops and some other things
proc andTest() =
var a = 0 == 5 and 6 == 6
proc incx(x: var int) = # is built-in proc
x = x + 1
proc decx(x: var int) =
x = x - 1
proc First(y: var int) =
var x: int
i_ncx(x)
if x == 10:
y = 0
else:
if x == 0:
incx(x)
else:
x=11
proc TestLoops() =
var i, j: int
while i >= 0:
if i mod 3 == 0:
break
i = i + 1
while j == 13:
j = 13
break
break
while True:
break
proc Foo(n: int): int =
var
a, old: int
b, c: bool
F_irst(a)
if a == 10:
a = 30
elif a == 11:
a = 22
elif a == 12:
a = 23
elif b:
old = 12
else:
a = 40
#
b = false or 2 == 0 and 3 == 9
a = 0 + 3 * 5 + 6 + 7 + +8 # 36
while b:
a = a + 3
a = a + 5
write(stdout, "Hello!")
# We should come till here :-)
discard Foo(345)
# test the new type symbol lookup feature:
type
MyType[T] = tuple[
x, y, z: T]
MyType2 = tuple[x, y: float]
proc main[T]() =
var myType: MyType[T]
var b: MyType[T]
b = (1, 2, 3)
myType = b
echo myType
var myType2: MyType2
var c: MyType2
c = (1.0, 2.0)
myType2 = c
echo myType2
main[int]()

View File

@@ -1,57 +0,0 @@
discard """
cmd: "nimrod cc --hints:on -d:release $# $#"
"""
# -*- nimrod -*-
import math
import os
import strutils
type TComplex = tuple[re, im: float]
proc `+` (a, b: TComplex): TComplex =
return (a.re + b.re, a.im + b.im)
proc `*` (a, b: TComplex): TComplex =
result.re = a.re * b.re - a.im * b.im
result.im = a.re * b.im + a.im * b.re
proc abs2 (a: TComplex): float =
return a.re * a.re + a.im * a.im
var size = parseInt (paramStr (1))
var bit = 128
var byteAcc = 0
stdout.writeln ("P4")
stdout.write ($size)
stdout.write (" ")
stdout.writeln ($size)
var fsize = float (size)
for y in 0 .. size-1:
var fy = 2.0 * float (y) / fsize - 1.0
for x in 0 .. size-1:
var z = (0.0, 0.0)
var c = (float (2*x) / fsize - 1.5, fy)
block iter:
for i in 0 .. 49:
z = z*z + c
if abs2 (z) >= 4.0:
break iter
byteAcc = byteAcc + bit
if bit > 1:
bit = bit div 2
else:
stdout.write (chr (byteAcc))
bit = 128
byteAcc = 0
if bit != 128:
stdout.write (chr (byteAcc))
bit = 128
byteAcc = 0

View File

@@ -1,49 +0,0 @@
# Test the implementation of the new operator
# and the code generation for gc walkers
# (and the garbage collector):
type
PNode = ref TNode
TNode = object
data: int
str: string
le, ri: PNode
TStressTest = ref array [0..45, array [1..45, TNode]]
proc finalizer(n: PNode) =
write(stdout, n.data)
write(stdout, " is now freed\n")
proc newNode(data: int, le, ri: PNode): PNode =
new(result, finalizer)
result.le = le
result.ri = ri
result.data = data
# now loop and build a tree
proc main() =
var
i = 0
p: TStressTest
while i < 1000:
var n: PNode
n = newNode(i, nil, newNode(i + 10000, nil, nil))
inc(i)
new(p)
write(stdout, "Simple tree node allocation worked!\n")
i = 0
while i < 1000:
var m = newNode(i + 20000, nil, nil)
var k = newNode(i + 30000, nil, nil)
m.le = m
m.ri = k
k.le = m
k.ri = k
inc(i)
write(stdout, "Simple cycle allocation worked!\n")
main()

View File

@@ -1,17 +0,0 @@
# Test wether the bindings at least compile...
import
tcl,
sdl, smpeg, sdl_gfx, sdl_net, sdl_mixer, sdl_ttf,
sdl_image, sdl_mixer_nosmpeg,
gtk2, glib2, pango, gdk2,
unicode, cgi, terminal, libcurl,
parsexml, parseopt, parsecfg,
osproc,
cairowin32, cairoxlib,
gl, glut, glu, glx, glext, wingl,
lua, lualib, lauxlib, mysql, sqlite3, db_mongo, md5, asyncio, mimetypes,
cookies, events, ftpclient, scgi, irc
writeln(stdout, "test compilation of binding modules")

View File

@@ -1,6 +0,0 @@
# new test for sets:
const elem = ' '
var s: set[char] = {elem}
assert(elem in s and 'a' not_in s and 'c' not_in s )

View File

@@ -1,12 +0,0 @@
# test the new unsigned operations:
import
strutils
var
x, y: int
x = 1
y = high(int)
writeln(stdout, $ ( x +% y ) )

View File

@@ -1,10 +0,0 @@
{. noforward: on .}
proc foo(x: int) =
bar x
proc bar(x: int) =
echo x
foo(10)

View File

@@ -1,4 +0,0 @@
# This test is now superfluous:
proc a(a: int) =
return

View File

@@ -1,30 +0,0 @@
# Test the features that used to belong to the preprocessor
import
times
#{.warning: "This is only a test warning!".}
const
case2 = true
case3 = true
when defined(case1):
{.hint: "Case 1".}
when case3:
{.hint: "Case 1.3".}
elif case2:
{.hint: "Case 2".}
when case3:
{.hint: "Case 2.3".}
elif case3:
{.hint: "Case 3".}
else:
{.hint: "unknown case".}
var
s: string
write(stdout, "compiled at " & system.compileDate &
" " & compileTime & "\n")
echo getDateStr()
echo getClockStr()

View File

@@ -1,26 +0,0 @@
proc QuickSort(list: seq[int]): seq[int] =
if len(list) == 0:
return @[]
var pivot = list[0]
var left: seq[int] = @[]
var right: seq[int] = @[]
for i in low(list)..high(list):
if list[i] < pivot:
left.add(list[i])
elif list[i] > pivot:
right.add(list[i])
result = QuickSort(left) &
pivot &
QuickSort(right)
proc echoSeq(a: seq[int]) =
for i in low(a)..high(a):
echo(a[i])
var
list: seq[int]
list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3])
echoSeq(list)

View File

@@ -1,319 +0,0 @@
# implements and tests an efficient radix tree
## another method to store an efficient array of pointers:
## We use a radix tree with node compression.
## There are two node kinds:
const bitsPerUnit = 8*sizeof(int)
type
TRadixNodeKind = enum rnLinear, rnFull, rnLeafBits, rnLeafLinear
PRadixNode = ptr TRadixNode
TRadixNode {.pure, inheritable.} = object
kind: TRadixNodeKind
TRadixNodeLinear = object of TRadixNode
len: int8
keys: array [0..31, int8]
vals: array [0..31, PRadixNode]
TRadixNodeFull = object of TRadixNode
b: array [0..255, PRadixNode]
TRadixNodeLeafBits = object of TRadixNode
b: array [0..7, int]
TRadixNodeLeafLinear = object of TRadixNode
len: int8
keys: array [0..31, int8]
var
root: PRadixNode
proc searchInner(r: PRadixNode, a: int): PRadixNode =
case r.kind
of rnLinear:
var x = cast[ptr TRadixNodeLinear](r)
for i in 0..ze(x.len)-1:
if ze(x.keys[i]) == a: return x.vals[i]
of rnFull:
var x = cast[ptr TRadixNodeFull](r)
return x.b[a]
else: assert(false)
proc testBit(w, i: int): bool {.inline.} =
result = (w and (1 shl (i %% BitsPerUnit))) != 0
proc setBit(w: var int, i: int) {.inline.} =
w = w or (1 shl (i %% bitsPerUnit))
proc resetBit(w: var int, i: int) {.inline.} =
w = w and not (1 shl (i %% bitsPerUnit))
proc testOrSetBit(w: var int, i: int): bool {.inline.} =
var x = (1 shl (i %% bitsPerUnit))
if (w and x) != 0: return true
w = w or x
proc searchLeaf(r: PRadixNode, a: int): bool =
case r.kind
of rnLeafBits:
var x = cast[ptr TRadixNodeLeafBits](r)
return testBit(x.b[a /% BitsPerUnit], a)
of rnLeafLinear:
var x = cast[ptr TRadixNodeLeafLinear](r)
for i in 0..ze(x.len)-1:
if ze(x.keys[i]) == a: return true
else: assert(false)
proc exclLeaf(r: PRadixNode, a: int) =
case r.kind
of rnLeafBits:
var x = cast[ptr TRadixNodeLeafBits](r)
resetBit(x.b[a /% BitsPerUnit], a)
of rnLeafLinear:
var x = cast[ptr TRadixNodeLeafLinear](r)
var L = ze(x.len)
for i in 0..L-1:
if ze(x.keys[i]) == a:
x.keys[i] = x.keys[L-1]
dec(x.len)
return
else: assert(false)
proc contains*(r: PRadixNode, a: TAddress): bool =
if r == nil: return false
var x = searchInner(r, a shr 24 and 0xff)
if x == nil: return false
x = searchInner(x, a shr 16 and 0xff)
if x == nil: return false
x = searchInner(x, a shr 8 and 0xff)
if x == nil: return false
return searchLeaf(x, a and 0xff)
proc excl*(r: PRadixNode, a: TAddress): bool =
if r == nil: return false
var x = searchInner(r, a shr 24 and 0xff)
if x == nil: return false
x = searchInner(x, a shr 16 and 0xff)
if x == nil: return false
x = searchInner(x, a shr 8 and 0xff)
if x == nil: return false
exclLeaf(x, a and 0xff)
proc addLeaf(r: var PRadixNode, a: int): bool =
if r == nil:
# a linear node:
var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear)))
x.kind = rnLeafLinear
x.len = 1'i8
x.keys[0] = toU8(a)
r = x
return false # not already in set
case r.kind
of rnLeafBits:
var x = cast[ptr TRadixNodeLeafBits](r)
return testOrSetBit(x.b[a /% BitsPerUnit], a)
of rnLeafLinear:
var x = cast[ptr TRadixNodeLeafLinear](r)
var L = ze(x.len)
for i in 0..L-1:
if ze(x.keys[i]) == a: return true
if L <= high(x.keys):
x.keys[L] = toU8(a)
inc(x.len)
else:
# transform into a full node:
var y = cast[ptr TRadixNodeLeafBits](alloc0(sizeof(TRadixNodeLeafBits)))
y.kind = rnLeafBits
for i in 0..ze(x.len)-1:
var u = ze(x.keys[i])
setBit(y.b[u /% BitsPerUnit], u)
setBit(y.b[a /% BitsPerUnit], a)
dealloc(r)
r = y
else: assert(false)
proc addInner(r: var PRadixNode, a: int, d: int): bool =
if d == 0:
return addLeaf(r, a and 0xff)
var k = a shr d and 0xff
if r == nil:
# a linear node:
var x = cast[ptr TRadixNodeLinear](alloc(sizeof(TRadixNodeLinear)))
x.kind = rnLinear
x.len = 1'i8
x.keys[0] = toU8(k)
r = x
return addInner(x.vals[0], a, d-8)
case r.kind
of rnLinear:
var x = cast[ptr TRadixNodeLinear](r)
var L = ze(x.len)
for i in 0..L-1:
if ze(x.keys[i]) == k: # already exists
return addInner(x.vals[i], a, d-8)
if L <= high(x.keys):
x.keys[L] = toU8(k)
inc(x.len)
return addInner(x.vals[L], a, d-8)
else:
# transform into a full node:
var y = cast[ptr TRadixNodeFull](alloc0(sizeof(TRadixNodeFull)))
y.kind = rnFull
for i in 0..L-1: y.b[ze(x.keys[i])] = x.vals[i]
dealloc(r)
r = y
return addInner(y.b[k], a, d-8)
of rnFull:
var x = cast[ptr TRadixNodeFull](r)
return addInner(x.b[k], a, d-8)
else: assert(false)
proc incl*(r: var PRadixNode, a: TAddress) {.inline.} =
discard addInner(r, a, 24)
proc testOrIncl*(r: var PRadixNode, a: TAddress): bool {.inline.} =
return addInner(r, a, 24)
iterator innerElements(r: PRadixNode): tuple[prefix: int, n: PRadixNode] =
if r != nil:
case r.kind
of rnFull:
var r = cast[ptr TRadixNodeFull](r)
for i in 0..high(r.b):
if r.b[i] != nil:
yield (i, r.b[i])
of rnLinear:
var r = cast[ptr TRadixNodeLinear](r)
for i in 0..ze(r.len)-1:
yield (ze(r.keys[i]), r.vals[i])
else: assert(false)
iterator leafElements(r: PRadixNode): int =
if r != nil:
case r.kind
of rnLeafBits:
var r = cast[ptr TRadixNodeLeafBits](r)
# iterate over any bit:
for i in 0..high(r.b):
if r.b[i] != 0: # test all bits for zero
for j in 0..BitsPerUnit-1:
if testBit(r.b[i], j):
yield i*BitsPerUnit+j
of rnLeafLinear:
var r = cast[ptr TRadixNodeLeafLinear](r)
for i in 0..ze(r.len)-1:
yield ze(r.keys[i])
else: assert(false)
iterator elements*(r: PRadixNode): TAddress {.inline.} =
for p1, n1 in innerElements(r):
for p2, n2 in innerElements(n1):
for p3, n3 in innerElements(n2):
for p4 in leafElements(n3):
yield p1 shl 24 or p2 shl 16 or p3 shl 8 or p4
proc main() =
const
numbers = [128, 1, 2, 3, 4, 255, 17, -8, 45, 19_000]
var
r: PRadixNode = nil
for x in items(numbers):
echo testOrIncl(r, x)
for x in elements(r): echo(x)
main()
when false:
proc traverse(r: PRadixNode, prefix: int, d: int) =
if r == nil: return
case r.kind
of rnLeafBits:
assert(d == 0)
var x = cast[ptr TRadixNodeLeafBits](r)
# iterate over any bit:
for i in 0..high(x.b):
if x.b[i] != 0: # test all bits for zero
for j in 0..BitsPerUnit-1:
if testBit(x.b[i], j):
visit(prefix or i*BitsPerUnit+j)
of rnLeafLinear:
assert(d == 0)
var x = cast[ptr TRadixNodeLeafLinear](r)
for i in 0..ze(x.len)-1:
visit(prefix or ze(x.keys[i]))
of rnFull:
var x = cast[ptr TRadixNodeFull](r)
for i in 0..high(r.b):
if r.b[i] != nil:
traverse(r.b[i], prefix or (i shl d), d-8)
of rnLinear:
var x = cast[ptr TRadixNodeLinear](r)
for i in 0..ze(x.len)-1:
traverse(x.vals[i], prefix or (ze(x.keys[i]) shl d), d-8)
type
TRadixIter {.final.} = object
r: PRadixNode
p: int
x: int
proc init(i: var TRadixIter, r: PRadixNode) =
i.r = r
i.x = 0
i.p = 0
proc nextr(i: var TRadixIter): PRadixNode =
if i.r == nil: return nil
case i.r.kind
of rnFull:
var r = cast[ptr TRadixNodeFull](i.r)
while i.x <= high(r.b):
if r.b[i.x] != nil:
i.p = i.x
return r.b[i.x]
inc(i.x)
of rnLinear:
var r = cast[ptr TRadixNodeLinear](i.r)
if i.x < ze(r.len):
i.p = ze(r.keys[i.x])
result = r.vals[i.x]
inc(i.x)
else: assert(false)
proc nexti(i: var TRadixIter): int =
result = -1
case i.r.kind
of rnLeafBits:
var r = cast[ptr TRadixNodeLeafBits](i.r)
# iterate over any bit:
for i in 0..high(r.b):
if x.b[i] != 0: # test all bits for zero
for j in 0..BitsPerUnit-1:
if testBit(x.b[i], j):
visit(prefix or i*BitsPerUnit+j)
of rnLeafLinear:
var r = cast[ptr TRadixNodeLeafLinear](i.r)
if i.x < ze(r.len):
result = ze(r.keys[i.x])
inc(i.x)
iterator elements(r: PRadixNode): TAddress {.inline.} =
var
a, b, c, d: TRadixIter
init(a, r)
while true:
var x = nextr(a)
if x != nil:
init(b, x)
while true:
var y = nextr(b)
if y != nil:
init(c, y)
while true:
var z = nextr(c)
if z != nil:
init(d, z)
while true:
var q = nexti(d)
if q != -1:
yield a.p shl 24 or b.p shl 16 or c.p shl 8 or q

View File

@@ -1,12 +0,0 @@
# test the improved readline handling that does not care whether its
# Macintosh, Unix or Windows text format.
var
inp: TFile
line: string
if open(inp, "readme.txt"):
while not EndOfFile(inp):
line = readLine(inp)
echo("#" & line & "#")
close(inp)

View File

@@ -1,14 +0,0 @@
when not defined(windows):
import posix
var inp = ""
var buf: array[0..10, char]
while true:
var r = read(0, addr(buf), sizeof(buf)-1)
add inp, $buf
if r != sizeof(buf)-1: break
echo inp
#dafkladskölklödsaf ölksdakölfölksfklwe4iojr389wr 89uweokf sdlkf jweklr jweflksdj fioewjfsdlfsd

View File

@@ -1,24 +0,0 @@
type
TListItemType* = enum
RedisNil, RedisString
TListItem* = object
case kind*: TListItemType
of RedisString:
str*: string
else: nil
TRedisList* = seq[TListItem]
# Caused by this.
proc seq*() =
nil
proc lrange*(key: string): TRedisList =
var foo: TListItem
foo.kind = RedisNil
result = @[foo]
when isMainModule:
var p = lrange("mylist")
for i in items(p):
echo(i.str)

View File

@@ -1,10 +0,0 @@
# Test the sizeof proc
type
TMyRecord {.final.} = object
x, y: int
b: bool
r: float
s: string
write(stdout, sizeof(TMyRecord))

View File

@@ -1,16 +0,0 @@
# Test the new stacktraces (great for debugging!)
{.push stack_trace: on.}
proc recTest(i: int) =
# enter
if i < 10:
recTest(i+1)
else: # should printStackTrace()
var p: ptr int = nil
p[] = 12
# leave
{.pop.}
recTest(0)

View File

@@ -1,14 +0,0 @@
var
x: array [0..2, int]
x = [0, 1, 2]
type
TStringDesc {.final.} = object
len, space: int # len and space without counting the terminating zero
data: array [0..0, char] # for the '\0' character
var
emptyString {.exportc: "emptyString".}: TStringDesc

Some files were not shown because too many files have changed in this diff Show More