diff options
Diffstat (limited to 'tests/compile')
176 files changed, 0 insertions, 5460 deletions
diff --git a/tests/compile/compilehelpers.nim b/tests/compile/compilehelpers.nim deleted file mode 100644 index cb26ca5b5..000000000 --- a/tests/compile/compilehelpers.nim +++ /dev/null @@ -1,6 +0,0 @@ -template accept(e: expr) = - static: assert(compiles(e)) - -template reject(e: expr) = - static: assert(not compiles(e)) - diff --git a/tests/compile/mdefaultprocparam.nim b/tests/compile/mdefaultprocparam.nim deleted file mode 100644 index 4a17277c0..000000000 --- a/tests/compile/mdefaultprocparam.nim +++ /dev/null @@ -1,5 +0,0 @@ - - -proc p*(f = (proc(): string = "hi")) = - echo f() - diff --git a/tests/compile/mexporta.nim b/tests/compile/mexporta.nim deleted file mode 100644 index b7d4ddec9..000000000 --- a/tests/compile/mexporta.nim +++ /dev/null @@ -1,8 +0,0 @@ -# module A -import mexportb -export mexportb.TMyObject, mexportb.xyz - -export mexportb.q - -proc `$`*(x: TMyObject): string = "my object" - diff --git a/tests/compile/mexportb.nim b/tests/compile/mexportb.nim deleted file mode 100644 index 10d89f388..000000000 --- a/tests/compile/mexportb.nim +++ /dev/null @@ -1,7 +0,0 @@ -# module B -type TMyObject* = object - -const xyz* = 13 - -proc q*(x: int): int = 6 -proc q*(x: string): string = "8" diff --git a/tests/compile/mrecmod.nim b/tests/compile/mrecmod.nim deleted file mode 100644 index fab9654d5..000000000 --- a/tests/compile/mrecmod.nim +++ /dev/null @@ -1 +0,0 @@ -import trecmod diff --git a/tests/compile/mrecmod2.nim b/tests/compile/mrecmod2.nim deleted file mode 100644 index 9557ce729..000000000 --- a/tests/compile/mrecmod2.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Module B -import trecmod2 - -proc p*(x: trecmod2.T1): trecmod2.T1 = - # this works because the compiler has already - # added T1 to trecmod2's interface symbol table - return x + 1 - - diff --git a/tests/compile/mtempl5.nim b/tests/compile/mtempl5.nim deleted file mode 100644 index 51e8461b8..000000000 --- a/tests/compile/mtempl5.nim +++ /dev/null @@ -1,10 +0,0 @@ - -var - gx = 88 - gy = 44 - -template templ*(): int = - bind gx, gy - gx + gy - - diff --git a/tests/compile/mvarious.nim b/tests/compile/mvarious.nim deleted file mode 100644 index 333b34d33..000000000 --- a/tests/compile/mvarious.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Test a submodule - -#type -# TStringArr = array [0.. *] of string - -proc exportme* = nil diff --git a/tests/compile/sunset.tmpl b/tests/compile/sunset.tmpl deleted file mode 100644 index 6475bac4e..000000000 --- a/tests/compile/sunset.tmpl +++ /dev/null @@ -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 © 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> diff --git a/tests/compile/talias.nim b/tests/compile/talias.nim deleted file mode 100644 index 819289c2e..000000000 --- a/tests/compile/talias.nim +++ /dev/null @@ -1,66 +0,0 @@ -# Test the alias analysis - -type - TAnalysisResult* = enum - arNo, arMaybe, arYes - -proc isPartOf*[S, T](a: S, b: T): TAnalysisResult {. - magic: "IsPartOf", noSideEffect.} - ## not yet exported properly. - -template compileTimeAssert(cond: expr) = - when not cond: - {.compile: "is false: " & astToStr(cond).} - -template `<|` (a, b: expr) = - compileTimeAssert isPartOf(a, b) == arYes - -template `!<|` (a, b: expr) = - compileTimeAssert isPartOf(a, b) == arNo - -template `?<|` (a, b: expr) = - compileTimeAssert isPartOf(a, b) == arMaybe - -type - TA {.inheritable.} = object - TC = object of TA - arr: array[0..3, int] - le, ri: ref TC - f: string - c: char - se: seq[TA] - -proc p(param1, param2: TC): TC = - var - local: TC - plocal: ptr TC - plocal2: ptr TA - - local.arr <| local - local.arr[0] <| local - local.arr[2] !<| local.arr[1] - - plocal2[] ?<| local - - param1 ?<| param2 - - local.arr[0] !<| param1 - local.arr !<| param1 - local.le[] ?<| param1 - - param1 !<| local.arr[0] - param1 !<| local.arr - param1 ?<| local.le[] - - result !<| local - result <| result - -var - a, b: int - x: TC - -a <| a -a !<| b - -discard p(x, x) - diff --git a/tests/compile/tambsym2.nim b/tests/compile/tambsym2.nim deleted file mode 100644 index 7758cc31a..000000000 --- a/tests/compile/tambsym2.nim +++ /dev/null @@ -1,6 +0,0 @@ - -from sdl import PSurface - -discard SDL.CreateRGBSurface(SDL.SWSURFACE, 23, 34, - 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xff000000'i32) - diff --git a/tests/compile/tarrindx.nim b/tests/compile/tarrindx.nim deleted file mode 100644 index 13919cc2c..000000000 --- a/tests/compile/tarrindx.nim +++ /dev/null @@ -1,13 +0,0 @@ -# test another strange bug ... (I hate this compiler; it is much too buggy!) - -proc putEnv(key, val: string) = - # XXX: we have to leak memory here, as we cannot - # free it before the program ends (says Borland's - # documentation) - var - env: ptr array[0..500000, char] - env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2)) - for i in 0..len(key)-1: env[i] = key[i] - env[len(key)] = '=' - for i in 0..len(val)-1: - env[len(key)+1+i] = val[i] diff --git a/tests/compile/tassign.nim b/tests/compile/tassign.nim deleted file mode 100644 index f51c20783..000000000 --- a/tests/compile/tassign.nim +++ /dev/null @@ -1,31 +0,0 @@ -# Test the assignment operator for complex types which need RTTI - -type - TRec = object - x, y: int - s: string - seq: seq[string] - arr: seq[seq[array[0..3, string]]] - TRecSeq = seq[TRec] - -proc test() = - var - a, b: TRec - a.x = 1 - a.y = 2 - a.s = "Hallo!" - a.seq = @["abc", "def", "ghi", "jkl"] - a.arr = @[] - setLen(a.arr, 4) - a.arr[0] = @[] - a.arr[1] = @[] - - b = a # perform a deep copy here! - b.seq = @["xyz", "huch", "was", "soll"] - writeln(stdout, len(a.seq)) - writeln(stdout, a.seq[3]) - writeln(stdout, len(b.seq)) - writeln(stdout, b.seq[3]) - writeln(stdout, b.y) - -test() diff --git a/tests/compile/tbindoverload.nim b/tests/compile/tbindoverload.nim deleted file mode 100644 index 6f5bb339e..000000000 --- a/tests/compile/tbindoverload.nim +++ /dev/null @@ -1,12 +0,0 @@ -import strtabs - -template t*() = - block: - bind newStringTable - discard {"Content-Type": "text/html"}.newStringTable() - - discard {:}.newStringTable - -#discard {"Content-Type": "text/html"}.newStringTable() - -t() diff --git a/tests/compile/tbindtypedesc.nim b/tests/compile/tbindtypedesc.nim deleted file mode 100644 index 5ea8cf063..000000000 --- a/tests/compile/tbindtypedesc.nim +++ /dev/null @@ -1,91 +0,0 @@ -discard """ - msg: ''' -int -float -TFoo -TFoo -''' -""" - -import typetraits - -type - TFoo = object - x, y: int - - TBar = tuple - x, y: int - -template accept(e: expr) = - static: assert(compiles(e)) - -template reject(e: expr) = - static: assert(not compiles(e)) - -proc genericParamRepeated[T: typedesc](a: T, b: T) = - static: - echo a.name - echo b.name - -accept genericParamRepeated(int, int) -accept genericParamRepeated(float, float) - -reject genericParamRepeated(string, int) -reject genericParamRepeated(int, float) - -proc genericParamOnce[T: typedesc](a, b: T) = - static: - echo a.name - echo b.name - -accept genericParamOnce(int, int) -accept genericParamOnce(TFoo, TFoo) - -reject genericParamOnce(string, int) -reject genericParamOnce(TFoo, float) - -type - type1 = typedesc - type2 = typedesc - -proc typePairs(A, B: type1; C, D: type2) = nil - -accept typePairs(int, int, TFoo, TFOO) -accept typePairs(TBAR, TBar, TBAR, TBAR) -accept typePairs(int, int, string, string) - -reject typePairs(TBAR, TBar, TBar, TFoo) -reject typePairs(string, int, TBAR, TBAR) - -proc typePairs2[T: typedesc, U: typedesc](A, B: T; C, D: U) = nil - -accept typePairs2(int, int, TFoo, TFOO) -accept typePairs2(TBAR, TBar, TBAR, TBAR) -accept typePairs2(int, int, string, string) - -reject typePairs2(TBAR, TBar, TBar, TFoo) -reject typePairs2(string, int, TBAR, TBAR) - -proc dontBind(a: typedesc, b: typedesc) = - static: - echo a.name - echo b.name - -accept dontBind(int, float) -accept dontBind(TFoo, TFoo) - -proc dontBind2(a, b: typedesc) = nil - -accept dontBind2(int, float) -accept dontBind2(TBar, int) - -proc bindArg(T: typedesc, U: typedesc, a, b: T, c, d: U) = nil - -accept bindArg(int, string, 10, 20, "test", "nest") -accept bindArg(int, int, 10, 20, 30, 40) - -reject bindArg(int, string, 10, "test", "test", "nest") -reject bindArg(int, int, 10, 20, 30, "test") -reject bindArg(int, string, 10.0, 20, "test", "nest") -reject bindArg(int, string, "test", "nest", 10, 20) - diff --git a/tests/compile/tcan_alias_generic.nim b/tests/compile/tcan_alias_generic.nim deleted file mode 100644 index e90bdc6d2..000000000 --- a/tests/compile/tcan_alias_generic.nim +++ /dev/null @@ -1,11 +0,0 @@ -## -## can_alias_generic Nimrod Module -## -## Created by Eric Doughty-Papassideris on 2011-02-16. -## Copyright (c) 2011 FWA. All rights reserved. - -type - TGen[T] = object - TGen2[T] = TGen[T] - - diff --git a/tests/compile/tcan_alias_specialised_generic.nim b/tests/compile/tcan_alias_specialised_generic.nim deleted file mode 100644 index 8d4a29abd..000000000 --- a/tests/compile/tcan_alias_specialised_generic.nim +++ /dev/null @@ -1,17 +0,0 @@ -discard """ - disabled: false -""" - -## -## can_alias_specialised_generic Nimrod Module -## -## Created by Eric Doughty-Papassideris on 2011-02-16. -## Copyright (c) 2011 FWA. All rights reserved. - -type - TGen[T] = object - TSpef = TGen[string] - -var - s: TSpef - diff --git a/tests/compile/tcan_inherit_generic.nim b/tests/compile/tcan_inherit_generic.nim deleted file mode 100644 index a6f4d946b..000000000 --- a/tests/compile/tcan_inherit_generic.nim +++ /dev/null @@ -1,17 +0,0 @@ -## -## can_inherit_generic Nimrod Module -## -## Created by Eric Doughty-Papassideris on 2011-02-16. -## Copyright (c) 2011 FWA. All rights reserved. - -type - TGen[T] = object of TObject - x, y: T - - TSpef[T] = object of TGen[T] - - -var s: TSpef[float] -s.x = 0.4 -s.y = 0.6 - diff --git a/tests/compile/tcan_specialise_generic.nim b/tests/compile/tcan_specialise_generic.nim deleted file mode 100644 index 64d5f56e3..000000000 --- a/tests/compile/tcan_specialise_generic.nim +++ /dev/null @@ -1,11 +0,0 @@ -## -## can_specialise_generic Nimrod Module -## -## Created by Eric Doughty-Papassideris on 2011-02-16. -## Copyright (c) 2011 FWA. All rights reserved. - -type - TGen[T] = object {.inheritable.} - TSpef = object of TGen[string] - - diff --git a/tests/compile/tccgen1.nim b/tests/compile/tccgen1.nim deleted file mode 100644 index 137dd545d..000000000 --- a/tests/compile/tccgen1.nim +++ /dev/null @@ -1,67 +0,0 @@ - - -type - Feature = tuple[name: string, version: string] - PDOMImplementation* = ref DOMImplementation - DOMImplementation = object - Features: seq[Feature] # Read-Only - - PNode* = ref Node - Node = object {.inheritable.} - attributes*: seq[PAttr] - childNodes*: seq[PNode] - FLocalName: string # Read-only - FNamespaceURI: string # Read-only - FNodeName: string # Read-only - nodeValue*: string - FNodeType: int # Read-only - FOwnerDocument: PDocument # Read-Only - FParentNode: PNode # Read-Only - prefix*: string # Setting this should change some values... TODO! - - PElement* = ref Element - Element = object of Node - FTagName: string # Read-only - - PCharacterData = ref CharacterData - CharacterData = object of Node - data*: string - - PDocument* = ref Document - Document = object of Node - FImplementation: PDOMImplementation # Read-only - FDocumentElement: PElement # Read-only - - PAttr* = ref Attr - Attr = object of Node - FName: string # Read-only - FSpecified: bool # Read-only - value*: string - FOwnerElement: PElement # Read-only - - PDocumentFragment* = ref DocumentFragment - DocumentFragment = object of Node - - PText* = ref Text - Text = object of CharacterData - - PComment* = ref comment - Comment = object of CharacterData - - PCDataSection* = ref CDataSection - CDataSection = object of Text - - PProcessingInstruction* = ref ProcessingInstruction - ProcessingInstruction = object of Node - data*: string - FTarget: string # Read-only - -proc `namespaceURI=`*(n: var PNode, value: string) = - n.FNamespaceURI = value - -proc main = - var n: PNode - new(n) - n.namespaceURI = "test" - -main() diff --git a/tests/compile/tclosure4.nim b/tests/compile/tclosure4.nim deleted file mode 100644 index 8e08376b6..000000000 --- a/tests/compile/tclosure4.nim +++ /dev/null @@ -1,13 +0,0 @@ - -import json, tables - -proc run(json_params: TTable) = - let json_elems = json_params["files"].elems - # These fail compilation. - var files = map(json_elems, proc (x: PJsonNode): string = x.str) - #var files = json_elems.map do (x: PJsonNode) -> string: x.str - echo "Hey!" - -when isMainModule: - let text = """{"files": ["a", "b", "c"]}""" - run(toTable((text.parseJson).fields)) diff --git a/tests/compile/tclosurebug2.nim b/tests/compile/tclosurebug2.nim deleted file mode 100644 index ec4f0045b..000000000 --- a/tests/compile/tclosurebug2.nim +++ /dev/null @@ -1,194 +0,0 @@ -import hashes, math - -type - TSlotEnum = enum seEmpty, seFilled, seDeleted - TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B] - TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]] - - TOrderedKeyValuePair[A, B] = tuple[ - slot: TSlotEnum, next: int, key: A, val: B] - TOrderedKeyValuePairSeq[A, B] = seq[TOrderedKeyValuePair[A, B]] - TOrderedTable*[A, B] = object ## table that remembers insertion order - data: TOrderedKeyValuePairSeq[A, B] - counter, first, last: int - -const - growthFactor = 2 - -proc mustRehash(length, counter: int): bool {.inline.} = - assert(length > counter) - result = (length * 2 < counter * 3) or (length - counter < 4) - -proc nextTry(h, maxHash: THash): THash {.inline.} = - result = ((5 * h) + 1) and maxHash - -template rawGetImpl() {.dirty.} = - var h: THash = hash(key) and high(t.data) # start with real hash value - while t.data[h].slot != seEmpty: - if t.data[h].key == key and t.data[h].slot == seFilled: - return h - h = nextTry(h, high(t.data)) - result = -1 - -template rawInsertImpl() {.dirty.} = - var h: THash = hash(key) and high(data) - while data[h].slot == seFilled: - h = nextTry(h, high(data)) - data[h].key = key - data[h].val = val - data[h].slot = seFilled - -template AddImpl() {.dirty.} = - if mustRehash(len(t.data), t.counter): Enlarge(t) - RawInsert(t, t.data, key, val) - inc(t.counter) - -template PutImpl() {.dirty.} = - var index = RawGet(t, key) - if index >= 0: - t.data[index].val = val - else: - AddImpl() - -proc len*[A, B](t: TOrderedTable[A, B]): int {.inline.} = - ## returns the number of keys in `t`. - result = t.counter - -template forAllOrderedPairs(yieldStmt: stmt) {.dirty, immediate.} = - var h = t.first - while h >= 0: - var nxt = t.data[h].next - if t.data[h].slot == seFilled: yieldStmt - h = nxt - -iterator pairs*[A, B](t: TOrderedTable[A, B]): tuple[key: A, val: B] = - ## iterates over any (key, value) pair in the table `t` in insertion - ## order. - forAllOrderedPairs: - yield (t.data[h].key, t.data[h].val) - -iterator mpairs*[A, B](t: var TOrderedTable[A, B]): tuple[key: A, val: var B] = - ## iterates over any (key, value) pair in the table `t` in insertion - ## order. The values can be modified. - forAllOrderedPairs: - yield (t.data[h].key, t.data[h].val) - -iterator keys*[A, B](t: TOrderedTable[A, B]): A = - ## iterates over any key in the table `t` in insertion order. - forAllOrderedPairs: - yield t.data[h].key - -iterator values*[A, B](t: TOrderedTable[A, B]): B = - ## iterates over any value in the table `t` in insertion order. - forAllOrderedPairs: - yield t.data[h].val - -iterator mvalues*[A, B](t: var TOrderedTable[A, B]): var B = - ## iterates over any value in the table `t` in insertion order. The values - ## can be modified. - forAllOrderedPairs: - yield t.data[h].val - -proc RawGet[A, B](t: TOrderedTable[A, B], key: A): int = - rawGetImpl() - -proc `[]`*[A, B](t: TOrderedTable[A, B], key: A): B = - ## retrieves the value at ``t[key]``. If `key` is not in `t`, - ## default empty value for the type `B` is returned - ## and no exception is raised. One can check with ``hasKey`` whether the key - ## exists. - var index = RawGet(t, key) - if index >= 0: result = t.data[index].val - -proc mget*[A, B](t: var TOrderedTable[A, B], key: A): var B = - ## retrieves the value at ``t[key]``. The value can be modified. - ## If `key` is not in `t`, the ``EInvalidKey`` exception is raised. - var index = RawGet(t, key) - if index >= 0: result = t.data[index].val - else: raise newException(EInvalidKey, "key not found: " & $key) - -proc hasKey*[A, B](t: TOrderedTable[A, B], key: A): bool = - ## returns true iff `key` is in the table `t`. - result = rawGet(t, key) >= 0 - -proc RawInsert[A, B](t: var TOrderedTable[A, B], - data: var TOrderedKeyValuePairSeq[A, B], - key: A, val: B) = - rawInsertImpl() - data[h].next = -1 - if t.first < 0: t.first = h - if t.last >= 0: data[t.last].next = h - t.last = h - -proc Enlarge[A, B](t: var TOrderedTable[A, B]) = - var n: TOrderedKeyValuePairSeq[A, B] - newSeq(n, len(t.data) * growthFactor) - var h = t.first - t.first = -1 - t.last = -1 - while h >= 0: - var nxt = t.data[h].next - if t.data[h].slot == seFilled: - RawInsert(t, n, t.data[h].key, t.data[h].val) - h = nxt - swap(t.data, n) - -proc `[]=`*[A, B](t: var TOrderedTable[A, B], key: A, val: B) = - ## puts a (key, value)-pair into `t`. - putImpl() - -proc add*[A, B](t: var TOrderedTable[A, B], key: A, val: B) = - ## puts a new (key, value)-pair into `t` even if ``t[key]`` already exists. - AddImpl() - -proc initOrderedTable*[A, B](initialSize=64): TOrderedTable[A, B] = - ## creates a new ordered hash table that is empty. `initialSize` needs to be - ## a power of two. - assert isPowerOfTwo(initialSize) - result.counter = 0 - result.first = -1 - result.last = -1 - newSeq(result.data, initialSize) - -proc toOrderedTable*[A, B](pairs: openarray[tuple[key: A, - val: B]]): TOrderedTable[A, B] = - ## creates a new ordered hash table that contains the given `pairs`. - result = initOrderedTable[A, B](nextPowerOfTwo(pairs.len+10)) - for key, val in items(pairs): result[key] = val - -proc sort*[A, B](t: var TOrderedTable[A,B], - cmp: proc (x, y: tuple[key: A, val: B]): int {.closure.}) = - ## sorts the ordered table so that the entry with the highest counter comes - ## first. This is destructive (with the advantage of being efficient)! - ## You must not modify `t` afterwards! - ## You can use the iterators `pairs`, `keys`, and `values` to iterate over - ## `t` in the sorted order. - - # we use shellsort here; fast enough and simple - var h = 1 - while true: - h = 3 * h + 1 - if h >= high(t.data): break - while true: - h = h div 3 - for i in countup(h, high(t.data)): - var j = i - #echo(t.data.len, " ", j, " - ", h) - #echo(repr(t.data[j-h])) - proc rawCmp(x, y: TOrderedKeyValuePair[A, B]): int = - if x.slot in {seEmpty, seDeleted} and y.slot in {seEmpty, seDeleted}: - return 0 - elif x.slot in {seEmpty, seDeleted}: - return -1 - elif y.slot in {seEmpty, seDeleted}: - return 1 - else: - let item1 = (x.key, x.val) - let item2 = (y.key, y.val) - return cmp(item1, item2) - - while rawCmp(t.data[j-h], t.data[j]) <= 0: - swap(t.data[j], t.data[j-h]) - j = j-h - if j < h: break - if h == 1: break diff --git a/tests/compile/tcmdline.nim b/tests/compile/tcmdline.nim deleted file mode 100644 index f4ee20d31..000000000 --- a/tests/compile/tcmdline.nim +++ /dev/null @@ -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 diff --git a/tests/compile/tcodegenbug1.nim b/tests/compile/tcodegenbug1.nim deleted file mode 100644 index 7d0fc4ad5..000000000 --- a/tests/compile/tcodegenbug1.nim +++ /dev/null @@ -1,67 +0,0 @@ -import os - -type - TStatusEnum* = enum - sUnknown = -1, sBuildFailure, sBuildInProgress, sBuildSuccess, - sTestFailure, sTestInProgress, sTestSuccess, # ORDER MATTERS! - sDocGenFailure, sDocGenInProgress, sDocGenSuccess, - sCSrcGenFailure, sCSrcGenInProgress, sCSrcGenSuccess - - TStatus* = object - status*: TStatusEnum - desc*: string - hash*: string - -proc initStatus*(): TStatus = - result.status = sUnknown - result.desc = "" - result.hash = "" - -proc isInProgress*(status: TStatusEnum): bool = - return status in {sBuildInProgress, sTestInProgress, sDocGenInProgress, - sCSrcGenInProgress} - -proc `$`*(status: TStatusEnum): string = - case status - of sBuildFailure: - return "build failure" - of sBuildInProgress: - return "build in progress" - of sBuildSuccess: - return "build finished" - of sTestFailure: - return "testing failure" - of sTestInProgress: - return "testing in progress" - of sTestSuccess: - return "testing finished" - of sDocGenFailure: - return "documentation generation failed" - of sDocGenInProgress: - return "generating documentation" - of sDocGenSuccess: - return "documentation generation succeeded" - of sCSrcGenFailure: - return "csource generation failed" - of sCSrcGenInProgress: - return "csource generation in progress" - of sCSrcGenSuccess: - return "csource generation succeeded" - of sUnknown: - return "unknown" - -proc makeCommitPath*(platform, hash: string): string = - return platform / "nimrod_" & hash.substr(0, 11) # 11 Chars. - -type - TFlag = enum - A, B, C, D - - TFlags = set[TFlag] - - TObj = object - x: int - flags: TFlags - -# have a proc taking TFlags as param and returning object having TFlags field -proc foo(flags: TFlags): TObj = nil diff --git a/tests/compile/tcolonisproc.nim b/tests/compile/tcolonisproc.nim deleted file mode 100644 index e55587dfc..000000000 --- a/tests/compile/tcolonisproc.nim +++ /dev/null @@ -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) diff --git a/tests/compile/tcolors.nim b/tests/compile/tcolors.nim deleted file mode 100644 index 9d1034405..000000000 --- a/tests/compile/tcolors.nim +++ /dev/null @@ -1,39 +0,0 @@ -import strutils - -type - TColor = distinct int32 - -proc rgb(r, g, b: range[0..255]): TColor = - result = TColor(r or g shl 8 or b shl 16) - -proc `$`(c: TColor): string = - result = "#" & toHex(int32(c), 6) - -echo rgb(34, 55, 255) - -when false: - type - TColor = distinct int32 - TColorComponent = distinct int8 - - proc red(a: TColor): TColorComponent = - result = TColorComponent(int32(a) and 0xff'i32) - - proc green(a: TColor): TColorComponent = - result = TColorComponent(int32(a) shr 8'i32 and 0xff'i32) - - proc blue(a: TColor): TColorComponent = - result = TColorComponent(int32(a) shr 16'i32 and 0xff'i32) - - proc rgb(r, g, b: range[0..255]): TColor = - result = TColor(r or g shl 8 or b shl 8) - - proc `+!` (a, b: TColorComponent): TColorComponent = - ## saturated arithmetic: - result = TColorComponent(min(ze(int8(a)) + ze(int8(b)), 255)) - - proc `+` (a, b: TColor): TColor = - ## saturated arithmetic for colors makes sense, I think: - return rgb(red(a) +! red(b), green(a) +! green(b), blue(a) +! blue(b)) - - rgb(34, 55, 255) diff --git a/tests/compile/tcommontype.nim b/tests/compile/tcommontype.nim deleted file mode 100644 index 8215ebd5e..000000000 --- a/tests/compile/tcommontype.nim +++ /dev/null @@ -1,20 +0,0 @@ -type - TAnimal=object {.inheritable.} - PAnimal=ref TAnimal - - TDog=object of TAnimal - PDog=ref TDog - - TCat=object of TAnimal - PCat=ref TCat - - TAnimalArray=array[0..2,PAnimal] - -proc newDog():PDog = new(result) -proc newCat():PCat = new(result) -proc test(a:openarray[PAnimal])= - echo("dummy") - -#test(newDog(),newCat()) #does not work -var myarray:TAnimalArray=[newDog(),newCat(),newDog()] #does not work -#var myarray2:TAnimalArray=[newDog(),newDog(),newDog()] #does not work either diff --git a/tests/compile/tcompiles.nim b/tests/compile/tcompiles.nim deleted file mode 100644 index d0fccdaff..000000000 --- a/tests/compile/tcompiles.nim +++ /dev/null @@ -1,26 +0,0 @@ -# test the new 'compiles' feature: - -template supports(opr, x: expr): bool {.immediate.} = - compiles(opr(x)) or compiles(opr(x, x)) - -template ok(x: expr): stmt = - static: assert(x) - -template no(x: expr): stmt = - static: assert(not x) - -type - TObj = object - -var - myObj {.compileTime.}: TObj - -ok supports(`==`, myObj) -ok supports(`==`, 45) - -no supports(`++`, 34) -ok supports(`not`, true) -ok supports(`+`, 34) - -no compiles(4+5.0 * "hallo") - diff --git a/tests/compile/tcompositetypeclasses.nim b/tests/compile/tcompositetypeclasses.nim deleted file mode 100644 index a2db73769..000000000 --- a/tests/compile/tcompositetypeclasses.nim +++ /dev/null @@ -1,59 +0,0 @@ -template accept(e) = - static: assert(compiles(e)) - -template reject(e) = - static: assert(not compiles(e)) - -type - TFoo[T, U] = tuple - x: T - y: U - - TBar[K] = TFoo[K, K] - - TUserClass = int|string - - TBaz = TBar[TUserClass] - -var - vfoo: TFoo[int, string] - vbar: TFoo[string, string] - vbaz: TFoo[int, int] - vnotbaz: TFoo[TObject, TObject] - -proc foo(x: TFoo) = echo "foo" -proc bar(x: TBar) = echo "bar" -proc baz(x: TBaz) = echo "baz" - -accept foo(vfoo) -accept bar(vbar) -accept baz(vbar) -accept baz(vbaz) - -reject baz(vnotbaz) -reject bar(vfoo) - -# https://github.com/Araq/Nimrod/issues/517 -type - TVecT*[T] = array[0..1, T]|array[0..2, T]|array[0..3, T] - TVec2* = array[0..1, float32] - -proc f[T](a: TVecT[T], b: TVecT[T]): T = discard - -var x: float = f([0.0'f32, 0.0'f32], [0.0'f32, 0.0'f32]) -var y = f(TVec2([0.0'f32, 0.0'f32]), TVec2([0.0'f32, 0.0'f32])) - -# https://github.com/Araq/Nimrod/issues/602 -type - TTest = object - TTest2* = object - TUnion = TTest | TTest2 - -proc f(src: ptr TUnion, dst: ptr TUnion) = - echo("asd") - -var tx: TTest -var ty: TTest2 - -accept f(addr tx, addr tx) -reject f(addr tx, addr ty) diff --git a/tests/compile/tcomputedgoto.nim b/tests/compile/tcomputedgoto.nim deleted file mode 100644 index b21fc07a3..000000000 --- a/tests/compile/tcomputedgoto.nim +++ /dev/null @@ -1,47 +0,0 @@ -discard """ - output: '''yeah A enumB -yeah A enumB -yeah CD enumD -yeah CD enumE -yeah A enumB -yeah CD enumE -yeah CD enumD -yeah A enumB -yeah B enumC -yeah A enumB -yeah A enumB -yeah A enumB''' -""" - -type - MyEnum = enum - enumA, enumB, enumC, enumD, enumE - -proc vm() = - var instructions: array [0..100, MyEnum] - instructions[2] = enumC - instructions[3] = enumD - instructions[4] = enumA - instructions[5] = enumD - instructions[6] = enumC - instructions[7] = enumA - instructions[8] = enumB - - instructions[12] = enumE - var pc = 0 - while true: - {.computedGoto.} - let instr = instructions[pc] - let ra = instr.succ # instr.regA - case instr - of enumA: - echo "yeah A ", ra - of enumC, enumD: - echo "yeah CD ", ra - of enumB: - echo "yeah B ", ra - of enumE: - break - inc(pc) - -vm() diff --git a/tests/compile/tconsteval.nim b/tests/compile/tconsteval.nim deleted file mode 100644 index 16fd8f4b8..000000000 --- a/tests/compile/tconsteval.nim +++ /dev/null @@ -1,31 +0,0 @@ -discard """ -""" - -import strutils - -const - HelpText = """ -+-----------------------------------------------------------------+ -| Maintenance program for Nimrod | -| Version $1| -| (c) 2012 Andreas Rumpf | -+-----------------------------------------------------------------+ -Compiled at: $2, $3 - -Usage: - koch [options] command [options for command] -Options: - --force, -f, -B, -b forces rebuild - --help, -h shows this help and quits -Possible Commands: - boot [options] bootstraps with given command line options - clean cleans Nimrod project; removes generated files - web generates the website - csource [options] builds the C sources for installation - zip builds the installation ZIP package - inno builds the Inno Setup installer -""" % [NimrodVersion & repeatChar(44-len(NimrodVersion)), - CompileDate, CompileTime] - -echo helpText - diff --git a/tests/compile/tconstraints.nim b/tests/compile/tconstraints.nim deleted file mode 100644 index 7aef0d645..000000000 --- a/tests/compile/tconstraints.nim +++ /dev/null @@ -1,15 +0,0 @@ - - -proc myGenericProc[T: object|tuple|int|ptr|ref|distinct](x: T): string = - result = $x - -type - TMyObj = tuple[x, y: int] - -var - x: TMyObj - -assert myGenericProc(232) == "232" -assert myGenericProc(x) == "(x: 0, y: 0)" - - diff --git a/tests/compile/tconvcolors.nim b/tests/compile/tconvcolors.nim deleted file mode 100644 index 07e829550..000000000 --- a/tests/compile/tconvcolors.nim +++ /dev/null @@ -1,5 +0,0 @@ - -import colors - -echo int32(colWhite), 'A' - diff --git a/tests/compile/tconvert.nim b/tests/compile/tconvert.nim deleted file mode 100644 index a8ddcf119..000000000 --- a/tests/compile/tconvert.nim +++ /dev/null @@ -1,46 +0,0 @@ -import - Cairo - -converter FloatConversion64(x: int): float64 = return toFloat(x) -converter FloatConversion32(x: int): float32 = return toFloat(x) -converter FloatConversionPlain(x: int): float = return toFloat(x) - -const width = 500 -const height = 500 -const outFile = "CairoTest.png" - -var surface = Cairo.ImageSurfaceCreate(CAIRO.FORMAT_RGB24, width, height) -var ç = Cairo.Create(surface) - -ç.SetSourceRGB(1, 1, 1) -ç.Paint() - -ç.SetLineWidth(10) -ç.SetLineCap(CAIRO.LINE_CAP_ROUND) - -const count = 12 -var winc = width / count -var hinc = width / count -for i in 1 .. count-1: - var amount = i / count - ç.SetSourceRGB(0, 1 - amount, amount) - ç.MoveTo(i * winc, hinc) - ç.LineTo(width - i * winc, height - hinc) - ç.Stroke() - - ç.SetSourceRGB(1 - amount, 0, amount) - ç.MoveTo(winc, i * hinc) - ç.LineTo(width - winc, height - i * hinc) - ç.Stroke() - -echo(surface.WriteToPNG(outFile)) -surface.Destroy() - -type TFoo = object - -converter toPtr*(some: var TFoo): ptr TFoo = (addr some) - - -proc zoot(x: ptr TFoo) = nil -var x: Tfoo -zoot(x) diff --git a/tests/compile/tcputime.nim b/tests/compile/tcputime.nim deleted file mode 100644 index 2fc46ee64..000000000 --- a/tests/compile/tcputime.nim +++ /dev/null @@ -1,13 +0,0 @@ - -import times, os - -var e = epochTime() -var c = cpuTime() - -os.sleep(1500) - -e = epochTime() - e -c = cpuTime() - c - -echo "epochTime: ", e, " cpuTime: ", c - diff --git a/tests/compile/tdatabind.nim b/tests/compile/tdatabind.nim deleted file mode 100644 index afa8aa47b..000000000 --- a/tests/compile/tdatabind.nim +++ /dev/null @@ -1,95 +0,0 @@ -discard """ - disabled: true -""" - -import events -type - TProperty*[T] = object of TObject - getProc: proc(property: TProperty[T]): T {.nimcall.} - setProc: proc(property: var TProperty[T], value: T) {.nimcall.} - value: T - ValueChanged*: TEventHandler - Binders: seq[TProperty[T]] - EEmitter: TEventEmitter - # Not a descriptive name but it was that or TPropertyValueChangeEventArgs. - TValueEventArgs[T] = object of TEventArgs - Property*: TProperty[T] - - -proc newProperty*[T](value: T): TProperty[T] = - var prop: TProperty[T] - - prop.EEmitter = initEventEmitter() - prop.Binders = @[] - prop.ValueChanged = initEventHandler("ValueChanged") - prop.value = value - - proc getter(property: TProperty[T]): T = - return property.value - - prop.getProc = getter - - proc setter(property: var TProperty[T], v: T) = - property.value = v - - # fire event here - var args: TValueEventArgs[T] - args.Property = property - property.EEmitter.emit(property.ValueChanged, args) - - prop.setProc = setter - - return prop - -proc `prop`[T] (p: TProperty[T]): T = - # I'm assuming this is trying to get a value from the property. - # i.e. myVar = myProperty - return p.getProc(p) - -proc `~=`[T] (p: var TProperty[T], v: T) = - # Assuming this is setting the value. - p.setProc(p, v) - -proc `$`[T] (p: TProperty[T]): string = - var value = p.getProc(p) - return $value - -proc propertyBind*[T](p1: var TProperty[T], p2: var TProperty[T]) = - p1.Binders.add(p2) - - # make handler -> handler[T] so trigger even more generics bugs ... - proc handler(e: TEventArgs) = - type TEA = TValueEventArgs[T] - var args = TEA(e) - var val = args.Property.getProc(p1) - for i in countup(0, len(e.Property.ValueChanged.Binders) -1): - var binded = e.Property.ValueChanged.Binders[i] - binded.setProc(binded, val) - - echo("Property 1 has changed to " & $val) - - if p1.ValueChanged.containsHandler(handler) == false: - addHandler(p1.ValueChanged, handler) - -proc `->`[T](p1: var TProperty[T], p2: var TProperty[T]) = - propertyBind(p2,p1) - -when isMainModule: - # Initial value testing - var myProp = newProperty(5) - - echo(myProp) - - myProp ~= 7 # Temp operator until overloading of '=' is implemented. - echo(myProp) - - # Binding testing - - var prop1 = newProperty(9) - var prop2: TProperty[int] - - prop2 -> prop1 # Binds prop2 to prop1 - - prop1 ~= 7 - echo(prop2) # Output: 7 - diff --git a/tests/compile/tdefaultprocparam.nim b/tests/compile/tdefaultprocparam.nim deleted file mode 100644 index 23ecf72e9..000000000 --- a/tests/compile/tdefaultprocparam.nim +++ /dev/null @@ -1,4 +0,0 @@ - -import mdefaultprocparam - -p() diff --git a/tests/compile/tdialogs.nim b/tests/compile/tdialogs.nim deleted file mode 100644 index d161a976d..000000000 --- a/tests/compile/tdialogs.nim +++ /dev/null @@ -1,17 +0,0 @@ -# Test the dialogs module - -import dialogs, gtk2 - -gtk2.nimrod_init() - -var x = ChooseFilesToOpen(nil) -for a in items(x): - writeln(stdout, a) - -info(nil, "start with an info box") -warning(nil, "now a warning ...") -error(nil, "... and an error!") - -writeln(stdout, ChooseFileToOpen(nil)) -writeln(stdout, ChooseFileToSave(nil)) -writeln(stdout, ChooseDir(nil)) diff --git a/tests/compile/tdictdestruct.nim b/tests/compile/tdictdestruct.nim deleted file mode 100644 index ec1084105..000000000 --- a/tests/compile/tdictdestruct.nim +++ /dev/null @@ -1,20 +0,0 @@ - -type - TDict[TK, TV] = object - k: TK - v: TV - PDict[TK, TV] = ref TDict[TK, TV] - -proc fakeNew[T](x: var ref T, destroy: proc (a: ref T) {.nimcall.}) = - nil - -proc destroyDict[TK, TV](a: PDict[TK, TV]) = - return -proc newDict[TK, TV](a: TK, b: TV): PDict[TK, TV] = - Fakenew(result, destroyDict[TK, TV]) - -# Problem: destroyDict is not instantiated when newDict is instantiated! - -discard newDict("a", "b") - - diff --git a/tests/compile/tdiscardable.nim b/tests/compile/tdiscardable.nim deleted file mode 100644 index c0551ba2f..000000000 --- a/tests/compile/tdiscardable.nim +++ /dev/null @@ -1,13 +0,0 @@ -# Test the discardable pragma - -proc p(x, y: int): int {.discardable.} = - return x + y - -# test that it is inherited from generic procs too: -proc q[T](x, y: T): T {.discardable.} = - return x + y - - -p(8, 2) -q[float](0.8, 0.2) - diff --git a/tests/compile/tdllvar.nim b/tests/compile/tdllvar.nim deleted file mode 100644 index ab767770c..000000000 --- a/tests/compile/tdllvar.nim +++ /dev/null @@ -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) - - diff --git a/tests/compile/tdumpast.nim b/tests/compile/tdumpast.nim deleted file mode 100644 index 55a964327..000000000 --- a/tests/compile/tdumpast.nim +++ /dev/null @@ -1,33 +0,0 @@ -# Dump the contents of a PNimrodNode - -import macros - -template plus(a, b: expr): expr = - a + b - -macro call(e: expr): expr = - result = newCall("foo", newStrLitNode("bar")) - -macro dumpAST(n: stmt): stmt {.immediate.} = - # dump AST as a side-effect and return the inner node - let n = callsite() - echo n.lispRepr - echo n.treeRepr - - var plusAst = getAst(plus(1, 2)) - echo plusAst.lispRepr - - var callAst = getAst(call()) - echo callAst.lispRepr - - var e = parseExpr("foo(bar + baz)") - echo e.lispRepr - - result = n[1] - -dumpAST: - proc add(x, y: int): int = - return x + y - - proc sub(x, y: int): int = return x - y - diff --git a/tests/compile/tdumpast2.nim b/tests/compile/tdumpast2.nim deleted file mode 100644 index c6eab39a9..000000000 --- a/tests/compile/tdumpast2.nim +++ /dev/null @@ -1,36 +0,0 @@ -# Dump the contents of a PNimrodNode - -import macros - -proc dumpit(n: PNimrodNode): string {.compileTime.} = - if n == nil: return "nil" - result = $n.kind - add(result, "(") - case n.kind - of nnkEmpty: nil # same as nil node in this representation - of nnkNilLit: add(result, "nil") - of nnkCharLit..nnkInt64Lit: add(result, $n.intVal) - of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal) - of nnkStrLit..nnkTripleStrLit: add(result, $n.strVal) - of nnkIdent: add(result, $n.ident) - of nnkSym, nnkNone: assert false - else: - add(result, dumpit(n[0])) - for j in 1..n.len-1: - add(result, ", ") - add(result, dumpit(n[j])) - add(result, ")") - -macro dumpAST(n: stmt): stmt {.immediate.} = - # dump AST as a side-effect and return the inner node - let n = callsite() - echo dumpit(n) - result = n[1] - -dumpAST: - proc add(x, y: int): int = - return x + y - - proc sub(x, y: int): int = return x - y - - diff --git a/tests/compile/techo.nim b/tests/compile/techo.nim deleted file mode 100644 index 0fa4b5fe0..000000000 --- a/tests/compile/techo.nim +++ /dev/null @@ -1,3 +0,0 @@ -# Simplest Nimrod program - -echo "Hello, World!" diff --git a/tests/compile/teffects1.nim b/tests/compile/teffects1.nim deleted file mode 100644 index 54200f2c3..000000000 --- a/tests/compile/teffects1.nim +++ /dev/null @@ -1,31 +0,0 @@ - -type - PMenu = ref object - PMenuItem = ref object - -proc createMenuItem*(menu: PMenu, label: string, - action: proc (i: PMenuItem, p: pointer) {.cdecl.}) = nil - -var s: PMenu -createMenuItem(s, "Go to definition...", - proc (i: PMenuItem, p: pointer) {.cdecl.} = - try: - echo(i.repr) - except EInvalidValue: - echo("blah") -) - - -proc noRaise(x: proc()) {.raises: [].} = - # unknown call that might raise anything, but valid: - x() - -proc doRaise() {.raises: [EIO].} = - raise newException(EIO, "IO") - -proc use*() = - noRaise(doRaise) - # Here the compiler inferes that EIO can be raised. - - -use() diff --git a/tests/compile/temptyecho.nim b/tests/compile/temptyecho.nim deleted file mode 100644 index 5f1aa6515..000000000 --- a/tests/compile/temptyecho.nim +++ /dev/null @@ -1,2 +0,0 @@ -echo() - diff --git a/tests/compile/tendian.nim b/tests/compile/tendian.nim deleted file mode 100644 index 256e2653c..000000000 --- a/tests/compile/tendian.nim +++ /dev/null @@ -1,3 +0,0 @@ -# test the new endian magic - -writeln(stdout, repr(system.cpuEndian)) diff --git a/tests/compile/tenum.nim b/tests/compile/tenum.nim deleted file mode 100644 index 6e53b9c08..000000000 --- a/tests/compile/tenum.nim +++ /dev/null @@ -1,8 +0,0 @@ -# Test enums - -type - E = enum a, b, c, x, y, z - -var - en: E -en = a diff --git a/tests/compile/tenum2.nim b/tests/compile/tenum2.nim deleted file mode 100644 index feba36dd6..000000000 --- a/tests/compile/tenum2.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Test that enum with holes is handled correctly by case statement - -type - TEnumHole = enum - eA = 0, - eB = 4, - eC = 5 - -var - e: TEnumHole = eB - -case e -of eA: echo "A" -of eB: echo "B" -of eC: echo "C" - diff --git a/tests/compile/tenum3.nim b/tests/compile/tenum3.nim deleted file mode 100644 index 09a516932..000000000 --- a/tests/compile/tenum3.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Test enum with explicit size - -type - TEnumHole {.size: sizeof(int).} = enum - eA = 0, - eB = 4, - eC = 5 - -var - e: TEnumHole = eB - -case e -of eA: echo "A" -of eB: echo "B" -of eC: echo "C" - diff --git a/tests/compile/teval1.nim b/tests/compile/teval1.nim deleted file mode 100644 index a02f26592..000000000 --- a/tests/compile/teval1.nim +++ /dev/null @@ -1,19 +0,0 @@ -import macros - -proc testProc: string {.compileTime.} = - result = "" - result = result & "" - -when true: - macro test(n: stmt): stmt {.immediate.} = - result = newNimNode(nnkStmtList) - echo "#", testProc(), "#" - test: - "hi" - -const - x = testProc() - -echo "##", x, "##" - - diff --git a/tests/compile/texport.nim b/tests/compile/texport.nim deleted file mode 100644 index 99228dfce..000000000 --- a/tests/compile/texport.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ - output: "my object68" -""" - -import mexporta - -# B.TMyObject has been imported implicitly here: -var x: TMyObject -echo($x, q(0), q"0") - diff --git a/tests/compile/tfib.nim b/tests/compile/tfib.nim deleted file mode 100644 index 09a4d5038..000000000 --- a/tests/compile/tfib.nim +++ /dev/null @@ -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 - - diff --git a/tests/compile/tforwardgeneric.nim b/tests/compile/tforwardgeneric.nim deleted file mode 100644 index c5943b966..000000000 --- a/tests/compile/tforwardgeneric.nim +++ /dev/null @@ -1,13 +0,0 @@ -discard """ - output: "1.1000000000000001e+00 11" - ccodecheck: "!@'ClEnv'" -""" - -proc p[T](a, b: T): T - -echo p(0.9, 0.1), " ", p(9, 1) - -proc p[T](a, b: T): T = - let c = b - result = a + b + c - diff --git a/tests/compile/tforwty.nim b/tests/compile/tforwty.nim deleted file mode 100644 index 0f1d3697f..000000000 --- a/tests/compile/tforwty.nim +++ /dev/null @@ -1,9 +0,0 @@ -# Test 13: forward types - -type - PSym = ref TSym - - TSym = object - next: PSym - -var s: PSym diff --git a/tests/compile/tforwty2.nim b/tests/compile/tforwty2.nim deleted file mode 100644 index 5d15e112a..000000000 --- a/tests/compile/tforwty2.nim +++ /dev/null @@ -1,22 +0,0 @@ -# Test for a hard to fix internal error -# occured in the SDL library - -{.push dynlib: "SDL.dll", callconv: cdecl.} - -type - PSDL_semaphore = ptr TSDL_semaphore - TSDL_semaphore {.final.} = object - sem: Pointer #PSem_t; - when not defined(USE_NAMED_SEMAPHORES): - sem_data: int - when defined(BROKEN_SEMGETVALUE): - # This is a little hack for MacOS X - - # It's not thread-safe, but it's better than nothing - sem_value: cint - -type - PSDL_Sem = ptr TSDL_Sem - TSDL_Sem = TSDL_Semaphore - -proc SDL_CreateSemaphore(initial_value: Int32): PSDL_Sem {. - importc: "SDL_CreateSemaphore".} diff --git a/tests/compile/tgeneric.nim b/tests/compile/tgeneric.nim deleted file mode 100644 index 9292b729f..000000000 --- a/tests/compile/tgeneric.nim +++ /dev/null @@ -1,19 +0,0 @@ -import tables - -type - TX = TTable[string, int] - -proc foo(models: seq[TTable[string, float]]): seq[float] = - result = @[] - for model in models.items: - result.add model["foobar"] - -# bug #686 -type TType[T; A] = array[A, T] - -proc foo[T](p: TType[T, range[0..1]]) = - echo "foo" -proc foo[T](p: TType[T, range[0..2]]) = - echo "bar" - - diff --git a/tests/compile/tgeneric2.nim b/tests/compile/tgeneric2.nim deleted file mode 100644 index 56803017a..000000000 --- a/tests/compile/tgeneric2.nim +++ /dev/null @@ -1,15 +0,0 @@ -import tables - -type - TX = TTable[string, int] - -proc foo(models: seq[TX]): seq[int] = - result = @[] - for model in models.items: - result.add model["foobar"] - -type - obj = object - field: TTable[string, string] -var t: Obj -discard initTable[type(t.field), string]() diff --git a/tests/compile/tgeneric3.nim b/tests/compile/tgeneric3.nim deleted file mode 100644 index 3c543ecfa..000000000 --- a/tests/compile/tgeneric3.nim +++ /dev/null @@ -1,474 +0,0 @@ -import strutils - -type - PNode[T,D] = ref TNode[T,D] - TItem {.acyclic, pure, final, shallow.} [T,D] = object - key: T - value: D - node: PNode[T,D] - when not (D is string): - val_set: Bool - - TItems[T,D] = seq[ref TItem[T,D]] - TNode {.acyclic, pure, final, shallow.} [T,D] = object - slots: TItems[T,D] - left: PNode[T,D] - count: Int32 - - - RPath[T,D] = tuple[ - Xi: Int, - Nd: PNode[T,D] ] - -const - cLen1 = 2 - cLen2 = 16 - cLen3 = 32 - cLenCenter = 80 - clen4 = 96 - cLenMax = 128 - cCenter = cLenMax div 2 - -proc len[T,D] (n:PNode[T,D]): Int {.inline.} = - return n.Count - -proc clean[T: TOrdinal|TNumber](o: var T) {.inline.} = nil - -proc clean[T: string|seq](o: var T) {.inline.} = - o = nil - -proc clean[T,D] (o: ref TItem[T,D]) {.inline.} = - when (D is string) : - o.Value = nil - else : - o.val_set = false - -proc isClean[T,D] (it: ref TItem[T,D]): Bool {.inline.} = - when (D is string) : - return it.Value == nil - else : - return not it.val_set - -proc isClean[T,D] (n: PNode[T,D], x: Int): Bool {.inline.} = - when (D is string) : - return n.slots[x].Value == nil - else : - return not n.slots[x].val_set - -proc setItem[T,D] (AKey: T, AValue: D, ANode: PNode[T,D]): ref TItem[T,D] {.inline.} = - new(Result) - Result.Key = AKey - Result.Value = AValue - Result.Node = ANode - when not (D is string) : - Result.val_set = true - -proc cmp[T:Int8|Int16|Int32|Int64|Int] (a,b: T): T {.inline.} = - return a-b - -template binSearchImpl *(docmp: expr) {.immediate.} = - var bFound = false - result = 0 - var H = haystack.len -1 - while result <= H : - var I {.inject.} = (result + H) shr 1 - var SW = docmp - if SW < 0: result = I + 1 - else: - H = I - 1 - if SW == 0 : bFound = True - if bFound: inc(result) - else: result = - result - -proc bSearch[T,D] (haystack: PNode[T,D], needle:T): Int {.inline.} = - binSearchImpl(haystack.slots[I].key.cmp(needle)) - -proc DeleteItem[T,D] (n: PNode[T,D], x: Int): PNode[T,D] {.inline.} = - var w = n.slots[x] - if w.Node != nil : - clean(w) - return n - dec(n.Count) - if n.Count > 0 : - for i in countup(x, n.Count -1) : n.slots[i] = n.slots[i + 1] - n.slots[n.Count] = nil - case n.Count - of cLen1 : setLen(n.slots, cLen1) - of cLen2 : setLen(n.slots, cLen2) - of cLen3 : setLen(n.slots, cLen3) - of cLenCenter : setLen(n.slots, cLenCenter) - of cLen4 : setLen(n.slots, cLen4) - else: nil - Result = n - - else : - Result = n.Left - n.slots = nil - n.Left = nil - -proc InternalDelete[T,D] (ANode: PNode[T,D], key: T, AValue: var D): PNode[T,D] = - var Path: array[0..20, RPath[T,D]] - var n = ANode - Result = n - clean(AValue) - var h = 0 - while n != nil: - var x = bSearch(n, key) - if x <= 0 : - Path[h].Nd = n - Path[h].Xi = - x - inc(h) - if x == 0 : - n = n.Left - else : - x = (-x) -1 - if x < n.Count : - n = n.slots[x].Node - else : - n = nil - else : - dec(x) - if isClean(n, x) : return - AValue = n.slots[x].Value - var n2 = DeleteItem(n, x) - dec(h) - while (n2 != n) and (h >=0) : - n = n2 - var w = addr Path[h] - x = w.Xi -1 - if x >= 0 : - if (n == nil) and isClean(w.Nd, x) : - n = w.Nd - n.slots[x].Node = nil - n2 = DeleteItem(n, x) - else : - w.Nd.slots[x].Node = n - return - else : - w.Nd.Left = n - return - dec(h) - if h < 0: - Result = n2 - return - -proc InternalFind[T,D] (n: PNode[T,D], key: T): ref TItem[T,D] {.inline.} = - var wn = n - while wn != nil : - var x = bSearch(wn, key) - if x <= 0 : - if x == 0 : - wn = wn.Left - else : - x = (-x) -1 - if x < wn.Count : - wn = wn.slots[x].Node - else : - return nil - - else : - return wn.slots[x - 1] - return nil - -proc traceTree[T,D](root: PNode[T,D]) = - proc traceX(x: Int) = - write stdout, "(" - write stdout, x - write stdout, ") " - - proc traceEl(el: ref TItem[T,D]) = - write stdout, " key: " - write stdout, el.Key - write stdout, " value: " - write stdout, el.Value - - - proc traceln(space: string) = - writeln stdout, "" - write stdout, space - - proc doTrace(n: PNode[T,D], level: Int) = - var space = repeatChar(2 * level) - traceln(space) - write stdout, "node: " - if n == nil: - writeln stdout, "is empty" - return - write stdout, n.Count - write stdout, " elements: " - if n.Left != nil: - traceln(space) - write stdout, "left: " - doTrace(n.left, level +1) - for i, el in n.slots : - if el != nil and not isClean(el): - traceln(space) - traceX(i) - if i >= n.Count: - write stdout, "error " - else: - traceEl(el) - if el.Node != nil: doTrace(el.Node, level +1) - else : write stdout, " empty " - elif i < n.Count : - traceln(space) - traceX(i) - write stdout, "clean: " - when T is string : - if el.Key != nil: write stdout, el.Key - else : write stdout, el.Key - if el.Node != nil: doTrace(el.Node, level +1) - else : write stdout, " empty " - writeln stdout,"" - - doTrace(root, 0) - -proc InsertItem[T,D](APath: RPath[T,D], ANode:PNode[T,D], AKey: T, AValue: D) = - var x = - APath.Xi - inc(APath.Nd.Count) - case APath.Nd.Count - of cLen1: setLen(APath.Nd.slots, cLen2) - of cLen2: setLen(APath.Nd.slots, cLen3) - of cLen3: setLen(APath.Nd.slots, cLenCenter) - of cLenCenter: setLen(APath.Nd.slots, cLen4) - of cLen4: setLen(APath.Nd.slots, cLenMax) - else: nil - for i in countdown(APath.Nd.Count.int - 1, x + 1): shallowCopy(APath.Nd.slots[i], APath.Nd.slots[i - 1]) - APath.Nd.slots[x] = setItem(AKey, AValue, ANode) - - -proc SplitPage[T,D](n, left: PNode[T,D], xi: Int, AKey:var T, AValue:var D): PNode[T,D] = - var x = -Xi - var it1: TItems[T,D] - it1.newSeq(cLenCenter) - new(Result) - Result.slots.newSeq(cLenCenter) - Result.Count = cCenter - if x == cCenter: - for i in 0..cCenter -1: shallowCopy(it1[i], left.slots[i]) - for i in 0..cCenter -1: shallowCopy(Result.slots[i], left.slots[cCenter + i]) - Result.Left = n - else : - if x < cCenter : - for i in 0..x-1: shallowCopy(it1[i], left.slots[i]) - it1[x] = setItem(AKey, AValue, n) - for i in x+1 .. cCenter -1: shallowCopy(it1[i], left.slots[i-1]) - var w = left.slots[cCenter -1] - AKey = w.Key - AValue = w.Value - Result.Left = w.Node - for i in 0..cCenter -1: shallowCopy(Result.slots[i], left.slots[cCenter + i]) - else : - for i in 0..cCenter -1: shallowCopy(it1[i], left.slots[i]) - x = x - (cCenter + 1) - for i in 0..x-1: shallowCopy(Result.slots[i], left.slots[cCenter + i + 1]) - Result.slots[x] = setItem(AKey, AValue, n) - for i in x+1 .. cCenter -1: shallowCopy(Result.slots[i], left.slots[cCenter + i]) - var w = left.slots[cCenter] - AKey = w.Key - AValue = w.Value - Result.Left = w.Node - left.Count = cCenter - shallowCopy(left.slots, it1) - - -proc InternalPut[T,D](ANode: ref TNode[T,D], AKey: T, AValue: D, OldValue: var D): ref TNode[T,D] = - var h: Int - var Path: array[0..30, RPath[T,D]] - var left: PNode[T,D] - var n = ANode - - - Result = ANode - h = 0 - while n != nil: - var x = bSearch[T,D](n, AKey) - if x <= 0 : - Path[h].Nd = n - Path[h].Xi = x - inc(h) - if x == 0 : - n = n.Left - else : - x = (-x) -1 - if x < n.Count : - n = n.slots[x].Node - else : - n = nil - else : - var w = n.slots[x - 1] - OldValue = w.Value - w.Value = AValue - return - - dec(h) - left = nil - var lKey = AKey - var lValue = AValue - while h >= 0 : - if Path[h].Nd.Count < cLenMax : - InsertItem(Path[h], n, lKey, lValue) - return - else : - left = Path[h].Nd - n = SplitPage(n, left, Path[h].Xi, lKey, lValue) - dec(h) - - new(Result) - Result.slots.newSeq(cLen1) - Result.Count = 1 - Result.Left = left - Result.slots[0] = setItem(lKey, lValue, n) - - -proc CleanTree[T,D](n: PNode[T,D]): PNode[T,D] = - if n.Left != nil : - n.Left = CleanTree(n.Left) - for i in 0 .. n.Count - 1 : - var w = n.slots[i] - if w.Node != nil : - w.Node = CleanTree(w.Node) - clean(w.Value) - clean(w.Key) - n.slots = nil - return nil - - -proc VisitAllNodes[T,D](n: PNode[T,D], visit: proc(n: PNode[T,D]): PNode[T,D] {.closure.} ): PNode[T,D] = - if n != nil : - if n.Left != nil : - n.Left = VisitAllNodes(n.Left, visit) - for i in 0 .. n.Count - 1 : - var w = n.slots[i] - if w.Node != nil : - w.Node = VisitAllNodes(w.Node, visit) - return visit(n) - return nil - -proc VisitAllNodes[T,D](n: PNode[T,D], visit: proc(n: PNode[T,D]) {.closure.} ) = - if n != nil: - if n.Left != nil : - VisitAllNodes(n.Left, visit) - for i in 0 .. n.Count - 1 : - var w = n.slots[i] - if w.Node != nil : - VisitAllNodes(w.Node, visit) - visit(n) - -proc VisitAll[T,D](n: PNode[T,D], visit: proc(AKey: T, AValue: D) {.closure.} ) = - if n != nil: - if n.Left != nil : - VisitAll(n.Left, visit) - for i in 0 .. n.Count - 1 : - var w = n.slots[i] - if not w.isClean : - visit(w.Key, w.Value) - if w.Node != nil : - VisitAll(w.Node, visit) - -proc VisitAll[T,D](n: PNode[T,D], visit: proc(AKey: T, AValue: var D):Bool {.closure.} ): PNode[T,D] = - if n != nil: - var n1 = n.Left - if n1 != nil : - var n2 = VisitAll(n1, visit) - if n1 != n2 : - n.Left = n2 - var i = 0 - while i < n.Count : - var w = n.slots[i] - if not w.isClean : - if visit(w.Key, w.Value) : - Result = DeleteItem(n, i) - if Result == nil : return - dec(i) - n1 = w.Node - if n1 != nil : - var n2 = VisitAll(n1, visit) - if n1 != n2 : - w.Node = n2 - inc(i) - return n - -iterator keys* [T,D] (n: PNode[T,D]): T = - if n != nil : - var Path: array[0..20, RPath[T,D]] - var level = 0 - var nd = n - var i = -1 - while true : - if i < nd.Count : - Path[level].Nd = nd - Path[level].Xi = i - if i < 0 : - if nd.Left != nil : - nd = nd.Left - inc(level) - else : inc(i) - else : - var w = nd.slots[i] - if not w.isClean() : - yield w.Key - if w.Node != nil : - nd = w.Node - i = -1 - inc(level) - else : inc(i) - else : - dec(level) - if level < 0 : break - nd = Path[level].Nd - i = Path[level].Xi - inc(i) - - -when isMainModule: - - proc test() = - var oldValue: Int - var root = InternalPut[int, int](nil, 312, 312, oldValue) - var someOtherRoot = InternalPut[string, int](nil, "312", 312, oldValue) - var it1 = InternalFind(root, 312) - echo it1.Value - - for i in 1..1_000_000: - root = InternalPut(root, i, i, oldValue) - - var cnt = 0 - oldValue = -1 - when true : # code compiles, when this or the other when is switched to false - for k in root.keys : - if k <= oldValue : - echo k - oldValue = k - inc(cnt) - echo cnt - when true : - cnt = 0 - VisitAll(root, proc(key, val: int) = inc(cnt)) - echo cnt - when true : - root = VisitAll(root, proc(key: int, value: var int): bool = - return key mod 2 == 0 ) - cnt = 0 - oldValue = -1 - VisitAll(root, proc(key: int, value: int) {.closure.} = - if key <= oldValue : - echo key - oldValue = key - inc(cnt) ) - echo cnt - root = VisitAll(root, proc(key: int, value: var int): bool = - return key mod 2 != 0 ) - cnt = 0 - oldValue = -1 - VisitAll(root, proc(key: int, value: int) {.closure.} = - if key <= oldValue : - echo "error ", key - oldValue = key - inc(cnt) ) - echo cnt - #traceTree(root) - - - - test() \ No newline at end of file diff --git a/tests/compile/tgeneric4.nim b/tests/compile/tgeneric4.nim deleted file mode 100644 index f79096636..000000000 --- a/tests/compile/tgeneric4.nim +++ /dev/null @@ -1,10 +0,0 @@ -type - TIDGen*[A: Ordinal] = object - next: A - free: seq[A] - -proc newIDGen*[A]: TIDGen[A] = - newSeq result.free, 0 - -var x = newIDGen[int]() - diff --git a/tests/compile/tgenericdefaults.nim b/tests/compile/tgenericdefaults.nim deleted file mode 100644 index ad96f1851..000000000 --- a/tests/compile/tgenericdefaults.nim +++ /dev/null @@ -1,29 +0,0 @@ -type - TFoo[T, U, R = int] = object - x: T - y: U - z: R - - TBar[T] = TFoo[T, array[4, T], T] - -var x1: TFoo[int, float] - -static: - assert type(x1.x) is int - assert type(x1.y) is float - assert type(x1.z) is int - -var x2: TFoo[string, R = float, U = seq[int]] - -static: - assert type(x2.x) is string - assert type(x2.y) is seq[int] - assert type(x2.z) is float - -var x3: TBar[float] - -static: - assert type(x3.x) is float - assert type(x3.y) is array[4, float] - assert type(x3.z) is float - diff --git a/tests/compile/tgenericmatcher.nim b/tests/compile/tgenericmatcher.nim deleted file mode 100644 index edd0c4cf1..000000000 --- a/tests/compile/tgenericmatcher.nim +++ /dev/null @@ -1,22 +0,0 @@ -discard """ - disabled: false -""" - -type - TMatcherKind = enum - mkTerminal, mkSequence, mkAlternation, mkRepeat - TMatcher[T] = object - case kind: TMatcherKind - of mkTerminal: - value: T - of mkSequence, mkAlternation: - matchers: seq[TMatcher[T]] - of mkRepeat: - matcher: PMatcher[T] - min, max: int - PMatcher[T] = ref TMatcher[T] - -var - m: PMatcher[int] - - diff --git a/tests/compile/tgenericmatcher2.nim b/tests/compile/tgenericmatcher2.nim deleted file mode 100644 index aa2f9dbb3..000000000 --- a/tests/compile/tgenericmatcher2.nim +++ /dev/null @@ -1,18 +0,0 @@ - -type - TMatcherKind = enum - mkTerminal, mkSequence, mkAlternation, mkRepeat - TMatcher[T] = object - case kind: TMatcherKind - of mkTerminal: - value: T - of mkSequence, mkAlternation: - matchers: seq[TMatcher[T]] - of mkRepeat: - matcher: ref TMatcher[T] - min, max: int - -var - m: ref TMatcher[int] - - diff --git a/tests/compile/tgenericprocvar.nim b/tests/compile/tgenericprocvar.nim deleted file mode 100644 index e642e3577..000000000 --- a/tests/compile/tgenericprocvar.nim +++ /dev/null @@ -1,5 +0,0 @@ -proc foo[T](thing: T) = - discard thing - -var a: proc (thing: int) {.nimcall.} = foo[int] - diff --git a/tests/compile/tgenericprop.nim b/tests/compile/tgenericprop.nim deleted file mode 100644 index 7cddf5617..000000000 --- a/tests/compile/tgenericprop.nim +++ /dev/null @@ -1,12 +0,0 @@ - -type - TProperty[T] = object of TObject - getProc: proc(property: TProperty[T]): T {.nimcall.} - setProc: proc(property: TProperty[T], value: T) {.nimcall.} - value: T - -proc newProperty[T](value: TObject): TProperty[T] = - result.getProc = proc (property: TProperty[T]) = - return property.value - - diff --git a/tests/compile/tgenericrefs.nim b/tests/compile/tgenericrefs.nim deleted file mode 100644 index ef931dfa7..000000000 --- a/tests/compile/tgenericrefs.nim +++ /dev/null @@ -1,26 +0,0 @@ -type - PA[T] = ref TA[T] - TA[T] = object - field: T -var a: PA[string] -new(a) -a.field = "some string" - -when false: - # Compiles unless you use var a: PA[string] - type - PA = ref TA - TA[T] = object - - - # Cannot instantiate: - type - TA[T] = object - a: PA[T] - PA[T] = ref TA[T] - - type - PA[T] = ref TA[T] - TA[T] = object - - diff --git a/tests/compile/tgenericshardcases.nim b/tests/compile/tgenericshardcases.nim deleted file mode 100644 index 2ef63bc20..000000000 --- a/tests/compile/tgenericshardcases.nim +++ /dev/null @@ -1,36 +0,0 @@ -discard """ - file: "tgenericshardcases.nim" - output: "2\n5\n126\n3" -""" - -import typetraits - -proc typeNameLen(x: typedesc): int {.compileTime.} = - result = x.name.len - -macro selectType(a, b: typedesc): typedesc = - result = a - -type - Foo[T] = object - data1: array[T.high, int] - data2: array[typeNameLen(T), float] # data3: array[0..T.typeNameLen, selectType(float, int)] - - MyEnum = enum A, B, C, D - -var f1: Foo[MyEnum] -var f2: Foo[int8] - -echo high(f1.data1) # (D = 3) - 1 == 2 -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 - -# assert high(f2.data1) == 127 -# assert high(f2.data2) == 4 # length of int8 - diff --git a/tests/compile/tgenerictmpl.nim b/tests/compile/tgenerictmpl.nim deleted file mode 100644 index a749e6570..000000000 --- a/tests/compile/tgenerictmpl.nim +++ /dev/null @@ -1,12 +0,0 @@ - -template tmp[T](x: var seq[T]) = - #var yz: T # XXX doesn't work yet - x = @[1, 2, 3] - -macro tmp2[T](x: var seq[T]): stmt = - nil - -var y: seq[int] -tmp(y) -tmp(y) -echo y.repr diff --git a/tests/compile/tgenericvariant.nim b/tests/compile/tgenericvariant.nim deleted file mode 100644 index 51d01355a..000000000 --- a/tests/compile/tgenericvariant.nim +++ /dev/null @@ -1,23 +0,0 @@ -type - TMaybe[T] = object - case empty: Bool - of False: value: T - else: nil - -proc Just*[T](val: T): TMaybe[T] = - result.empty = False - result.value = val - -proc Nothing[T](): TMaybe[T] = - result.empty = True - -proc safeReadLine(): TMaybe[string] = - var r = stdin.readLine() - if r == "": return Nothing[string]() - else: return Just(r) - -when isMainModule: - var Test = Just("Test") - echo(Test.value) - var mSomething = safeReadLine() - echo(mSomething.value) diff --git a/tests/compile/tgensymgeneric.nim b/tests/compile/tgensymgeneric.nim deleted file mode 100644 index 54390a4ef..000000000 --- a/tests/compile/tgensymgeneric.nim +++ /dev/null @@ -1,31 +0,0 @@ -# We need to open the gensym'ed symbol again so that the instantiation -# creates a fresh copy; but this is wrong the very first reason for gensym -# is that scope rules cannot be used! So simply removing 'sfGenSym' does -# not work. Copying the symbol does not work either because we're already -# the owner of the symbol! What we need to do is to copy the symbol -# in the generic instantiation process... - -type - TA = object - x: int - TB = object - x: string - -template genImpl() = - var gensymed: T - when T is TB: - gensymed.x = "abc" - else: - gensymed.x = 123 - shallowCopy(result, gensymed) - -proc gen[T](x: T): T = - genImpl() - -var - a: TA - b: TB -let x = gen(a) -let y = gen(b) - -echo x.x, " ", y.x diff --git a/tests/compile/tgetstartmilsecs.nim b/tests/compile/tgetstartmilsecs.nim deleted file mode 100644 index 5a3368e0f..000000000 --- a/tests/compile/tgetstartmilsecs.nim +++ /dev/null @@ -1,7 +0,0 @@ -# -import times, os - -var start = epochTime() -os.sleep(1000) - -echo epochTime() - start #OUT 1000 diff --git a/tests/compile/tglobalforvar.nim b/tests/compile/tglobalforvar.nim deleted file mode 100644 index af75df5c8..000000000 --- a/tests/compile/tglobalforvar.nim +++ /dev/null @@ -1,7 +0,0 @@ - -var funcs: seq[proc (): int {.nimcall.}] = @[] -for i in 0..10: - funcs.add((proc (): int = return i * i)) - -echo(funcs[3]()) - diff --git a/tests/compile/tgtk.nim b/tests/compile/tgtk.nim deleted file mode 100644 index 7febb0ab8..000000000 --- a/tests/compile/tgtk.nim +++ /dev/null @@ -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() diff --git a/tests/compile/thallo.nim b/tests/compile/thallo.nim deleted file mode 100644 index 7244c27a1..000000000 --- a/tests/compile/thallo.nim +++ /dev/null @@ -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".} - diff --git a/tests/compile/theaproots.nim b/tests/compile/theaproots.nim deleted file mode 100644 index aec140f42..000000000 --- a/tests/compile/theaproots.nim +++ /dev/null @@ -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) diff --git a/tests/compile/thexrange.nim b/tests/compile/thexrange.nim deleted file mode 100644 index e5e4c10c6..000000000 --- a/tests/compile/thexrange.nim +++ /dev/null @@ -1,8 +0,0 @@ - -type - TArray = array[0x0012..0x0013, int] - -var a: TArray - -echo a[0x0012] #OUT 0 - diff --git a/tests/compile/thygienictempl.nim b/tests/compile/thygienictempl.nim deleted file mode 100644 index 3cdbac40e..000000000 --- a/tests/compile/thygienictempl.nim +++ /dev/null @@ -1,18 +0,0 @@ - -var - e = "abc" - -raise newException(EIO, e & "ha!") - -template t() = echo(foo) - -var foo = 12 -t() - - -template test_in(a, b, c: expr): bool {.immediate, dirty.} = - var result {.gensym.}: bool = false - false - -when isMainModule: - assert test_in(ret2, "test", str_val) diff --git a/tests/compile/tident.nim b/tests/compile/tident.nim deleted file mode 100644 index 1ed9894c6..000000000 --- a/tests/compile/tident.nim +++ /dev/null @@ -1,22 +0,0 @@ - -type - TIdObj* = object of TObject - id*: int # unique id; use this for comparisons and not the pointers - - PIdObj* = ref TIdObj - PIdent* = ref TIdent - TIdent*{.acyclic.} = object - s*: string - -proc myNewString(L: int): string {.inline.} = - result = newString(L) - if result.len == L: echo("Length correct") - else: echo("bug") - for i in 0..L-1: - if result[i] == '\0': - echo("Correct") - else: - echo("Wrong") - -var s = myNewString(8) - diff --git a/tests/compile/timplicititems.nim b/tests/compile/timplicititems.nim deleted file mode 100644 index dbe321cb6..000000000 --- a/tests/compile/timplicititems.nim +++ /dev/null @@ -1,4 +0,0 @@ - -for x in [1, 2, 3, 4]: - echo x - diff --git a/tests/compile/timplictderef.nim b/tests/compile/timplictderef.nim deleted file mode 100644 index 99b0b645b..000000000 --- a/tests/compile/timplictderef.nim +++ /dev/null @@ -1,18 +0,0 @@ -discard """ - output: "2" -""" - -type - TValue* {.pure, final.} = object of TObject - a: int - PValue = ref TValue - PPValue = ptr PValue - - -var x: PValue -new x -var sp: PPValue = addr x - -sp.a = 2 -if sp.a == 2: echo 2 # with sp[].a the error is gone - diff --git a/tests/compile/tinheritref.nim b/tests/compile/tinheritref.nim deleted file mode 100644 index e5de6a4be..000000000 --- a/tests/compile/tinheritref.nim +++ /dev/null @@ -1,27 +0,0 @@ -discard """ - output: "23" -""" - -# bug #554, #179 - -type T[E] = - ref object - elem: E - -var ob: T[int] - -ob = T[int](elem: 23) -echo ob.elem - -type - TTreeIteratorA* = ref object {.inheritable.} - - TKeysIteratorA* = ref object of TTreeIteratorA #compiles - - TTreeIterator* [T,D] = ref object {.inheritable.} - - TKeysIterator* [T,D] = ref object of TTreeIterator[T,D] #this not - -var - it: TKeysIterator[int, string] = nil - diff --git a/tests/compile/tio.nim b/tests/compile/tio.nim deleted file mode 100644 index 5ae119f77..000000000 --- a/tests/compile/tio.nim +++ /dev/null @@ -1,7 +0,0 @@ -# test the file-IO - -proc main() = - for line in lines("thello.nim"): - writeln(stdout, line) - -main() diff --git a/tests/compile/tircbot.nim b/tests/compile/tircbot.nim deleted file mode 100644 index 6008838ff..000000000 --- a/tests/compile/tircbot.nim +++ /dev/null @@ -1,452 +0,0 @@ -import irc, sockets, asyncio, json, os, strutils, times, redis - -type - TDb* = object - r*: TRedis - lastPing: float - - TBuildResult* = enum - bUnknown, bFail, bSuccess - - TTestResult* = enum - tUnknown, tFail, tSuccess - - TEntry* = tuple[c: TCommit, p: seq[TPlatform]] - - TCommit* = object - commitMsg*, username*, hash*: string - date*: TTime - - TPlatform* = object - buildResult*: TBuildResult - testResult*: TTestResult - failReason*, platform*: string - total*, passed*, skipped*, failed*: biggestInt - csources*: bool - -const - listName = "commits" - failOnExisting = False - -proc open*(host = "localhost", port: TPort): TDb = - result.r = redis.open(host, port) - result.lastPing = epochTime() - -discard """proc customHSet(database: TDb, name, field, value: string) = - if database.r.hSet(name, field, value).int == 0: - if failOnExisting: - assert(false) - else: - echo("[Warning:REDIS] ", field, " already exists in ", name)""" - -proc updateProperty*(database: TDb, commitHash, platform, property, - value: string) = - var name = platform & ":" & commitHash - if database.r.hSet(name, property, value).int == 0: - echo("[INFO:REDIS] '$1' field updated in hash" % [property]) - else: - echo("[INFO:REDIS] '$1' new field added to hash" % [property]) - -proc globalProperty*(database: TDb, commitHash, property, value: string) = - if database.r.hSet(commitHash, property, value).int == 0: - echo("[INFO:REDIS] '$1' field updated in hash" % [property]) - else: - echo("[INFO:REDIS] '$1' new field added to hash" % [property]) - -proc addCommit*(database: TDb, commitHash, commitMsg, user: string) = - # Add the commit hash to the `commits` list. - discard database.r.lPush(listName, commitHash) - # Add the commit message, current date and username as a property - globalProperty(database, commitHash, "commitMsg", commitMsg) - globalProperty(database, commitHash, "date", $int(getTime())) - globalProperty(database, commitHash, "username", user) - -proc keepAlive*(database: var TDb) = - ## Keep the connection alive. Ping redis in this case. This functions does - ## not guarantee that redis will be pinged. - var t = epochTime() - if t - database.lastPing >= 60.0: - echo("PING -> redis") - assert(database.r.ping() == "PONG") - database.lastPing = t - -proc getCommits*(database: TDb, - plStr: var seq[string]): seq[TEntry] = - result = @[] - var commitsRaw = database.r.lrange("commits", 0, -1) - for c in items(commitsRaw): - var commit: TCommit - commit.hash = c - for key, value in database.r.hPairs(c): - case normalize(key) - of "commitmsg": commit.commitMsg = value - of "date": commit.date = TTime(parseInt(value)) - of "username": commit.username = value - else: - echo(key) - assert(false) - - var platformsRaw = database.r.lrange(c & ":platforms", 0, -1) - var platforms: seq[TPlatform] = @[] - for p in items(platformsRaw): - var platform: TPlatform - for key, value in database.r.hPairs(p & ":" & c): - case normalize(key) - of "buildresult": - platform.buildResult = parseInt(value).TBuildResult - of "testresult": - platform.testResult = parseInt(value).TTestResult - of "failreason": - platform.failReason = value - of "total": - platform.total = parseBiggestInt(value) - of "passed": - platform.passed = parseBiggestInt(value) - of "skipped": - platform.skipped = parseBiggestInt(value) - of "failed": - platform.failed = parseBiggestInt(value) - of "csources": - platform.csources = if value == "t": true else: false - else: - echo(normalize(key)) - assert(false) - - platform.platform = p - - platforms.add(platform) - if p notin plStr: - plStr.add(p) - result.add((commit, platforms)) - -proc commitExists*(database: TDb, commit: string, starts = false): bool = - # TODO: Consider making the 'commits' list a set. - for c in items(database.r.lrange("commits", 0, -1)): - if starts: - if c.startsWith(commit): return true - else: - if c == commit: return true - return false - -proc platformExists*(database: TDb, commit: string, platform: string): bool = - for p in items(database.r.lrange(commit & ":" & "platforms", 0, -1)): - if p == platform: return true - -proc expandHash*(database: TDb, commit: string): string = - for c in items(database.r.lrange("commits", 0, -1)): - if c.startsWith(commit): return c - assert false - -proc isNewest*(database: TDb, commit: string): bool = - return database.r.lIndex("commits", 0) == commit - -proc getNewest*(database: TDb): string = - return database.r.lIndex("commits", 0) - -proc addPlatform*(database: TDb, commit: string, platform: string) = - assert database.commitExists(commit) - assert (not database.platformExists(commit, platform)) - var name = platform & ":" & commit - if database.r.exists(name): - if failOnExisting: quit("[FAIL] " & name & " already exists!", 1) - else: echo("[Warning] " & name & " already exists!") - - discard database.r.lPush(commit & ":" & "platforms", platform) - -proc `[]`*(p: seq[TPlatform], name: string): TPlatform = - for platform in items(p): - if platform.platform == name: - return platform - raise newException(EInvalidValue, name & " platforms not found in commits.") - -proc contains*(p: seq[TPlatform], s: string): bool = - for i in items(p): - if i.platform == s: - return True - - -type - PState = ref TState - TState = object of TObject - dispatcher: PDispatcher - sock: PAsyncSocket - ircClient: PAsyncIRC - hubPort: TPort - database: TDb - dbConnected: bool - - TSeenType = enum - PSeenJoin, PSeenPart, PSeenMsg, PSeenNick, PSeenQuit - - TSeen = object - nick: string - channel: string - timestamp: TTime - case kind*: TSeenType - of PSeenJoin: nil - of PSeenPart, PSeenQuit, PSeenMsg: - msg: string - of PSeenNick: - newNick: string - -const - ircServer = "irc.freenode.net" - joinChans = @["#nimrod"] - botNickname = "NimBot" - -proc setSeen(d: TDb, s: TSeen) = - discard d.r.del("seen:" & s.nick) - - var hashToSet = @[("type", $s.kind.int), ("channel", s.channel), - ("timestamp", $s.timestamp.int)] - case s.kind - of PSeenJoin: nil - of PSeenPart, PSeenMsg, PSeenQuit: - hashToSet.add(("msg", s.msg)) - of PSeenNick: - hashToSet.add(("newnick", s.newNick)) - - d.r.hMSet("seen:" & s.nick, hashToSet) - -proc getSeen(d: TDb, nick: string, s: var TSeen): bool = - if d.r.exists("seen:" & nick): - result = true - s.nick = nick - # Get the type first - s.kind = d.r.hGet("seen:" & nick, "type").parseInt.TSeenType - - for key, value in d.r.hPairs("seen:" & nick): - case normalize(key) - of "type": - #s.kind = value.parseInt.TSeenType - of "channel": - s.channel = value - of "timestamp": - s.timestamp = TTime(value.parseInt) - of "msg": - s.msg = value - of "newnick": - s.newNick = value - -template createSeen(typ: TSeenType, n, c: string): stmt {.immediate, dirty.} = - var seenNick: TSeen - seenNick.kind = typ - seenNick.nick = n - seenNick.channel = c - seenNick.timestamp = getTime() - -proc parseReply(line: string, expect: string): Bool = - var jsonDoc = parseJson(line) - return jsonDoc["reply"].str == expect - -proc limitCommitMsg(m: string): string = - ## Limits the message to 300 chars and adds ellipsis. - var m1 = m - if NewLines in m1: - m1 = m1.splitLines()[0] - - if m1.len >= 300: - m1 = m1[0..300] - - if m1.len >= 300 or NewLines in m: m1.add("... ") - - if NewLines in m: m1.add($m.splitLines().len & " more lines") - - return m1 - -proc handleWebMessage(state: PState, line: string) = - echo("Got message from hub: " & line) - var json = parseJson(line) - if json.hasKey("payload"): - for i in 0..min(4, json["payload"]["commits"].len-1): - var commit = json["payload"]["commits"][i] - # Create the message - var message = "" - message.add(json["payload"]["repository"]["owner"]["name"].str & "/" & - json["payload"]["repository"]["name"].str & " ") - message.add(commit["id"].str[0..6] & " ") - message.add(commit["author"]["name"].str & " ") - message.add("[+" & $commit["added"].len & " ") - message.add("±" & $commit["modified"].len & " ") - message.add("-" & $commit["removed"].len & "]: ") - message.add(limitCommitMsg(commit["message"].str)) - - # Send message to #nimrod. - state.ircClient.privmsg(joinChans[0], message) - elif json.hasKey("redisinfo"): - assert json["redisinfo"].hasKey("port") - #let redisPort = json["redisinfo"]["port"].num - state.dbConnected = true - -proc hubConnect(state: PState) -proc handleConnect(s: PAsyncSocket, state: PState) = - try: - # Send greeting - var obj = newJObject() - obj["name"] = newJString("irc") - obj["platform"] = newJString("?") - state.sock.send($obj & "\c\L") - - # Wait for reply. - var line = "" - sleep(1500) - if state.sock.recvLine(line): - assert(line != "") - doAssert parseReply(line, "OK") - echo("The hub accepted me!") - else: - raise newException(EInvalidValue, - "Hub didn't accept me. Waited 1.5 seconds.") - - # ask for the redis info - var riobj = newJObject() - riobj["do"] = newJString("redisinfo") - state.sock.send($riobj & "\c\L") - - except EOS: - echo(getCurrentExceptionMsg()) - s.close() - echo("Waiting 5 seconds...") - sleep(5000) - state.hubConnect() - -proc handleRead(s: PAsyncSocket, state: PState) = - var line = "" - if state.sock.recvLine(line): - if line != "": - # Handle the message - state.handleWebMessage(line) - else: - echo("Disconnected from hub: ", OSErrorMsg()) - s.close() - echo("Reconnecting...") - state.hubConnect() - else: - echo(OSErrorMsg()) - -proc hubConnect(state: PState) = - state.sock = AsyncSocket() - state.sock.connect("127.0.0.1", state.hubPort) - state.sock.handleConnect = - proc (s: PAsyncSocket) = - handleConnect(s, state) - state.sock.handleRead = - proc (s: PAsyncSocket) = - handleRead(s, state) - - state.dispatcher.register(state.sock) - -proc handleIrc(irc: PAsyncIRC, event: TIRCEvent, state: PState) = - case event.typ - of EvConnected: nil - of EvDisconnected: - while not state.ircClient.isConnected: - try: - state.ircClient.connect() - except: - echo("Error reconnecting: ", getCurrentExceptionMsg()) - - echo("Waiting 5 seconds...") - sleep(5000) - echo("Reconnected successfully!") - of EvMsg: - echo("< ", event.raw) - case event.cmd - of MPrivMsg: - let msg = event.params[event.params.len-1] - let words = msg.split(' ') - template pm(msg: string): stmt = - state.ircClient.privmsg(event.origin, msg) - case words[0] - of "!ping": pm("pong") - of "!lag": - if state.ircClient.getLag != -1.0: - var lag = state.ircClient.getLag - lag = lag * 1000.0 - pm($int(lag) & "ms between me and the server.") - else: - pm("Unknown.") - of "!seen": - if words.len > 1: - let nick = words[1] - if nick == botNickname: - pm("Yes, I see myself.") - echo(nick) - var seenInfo: TSeen - if state.database.getSeen(nick, seenInfo): - #var mSend = "" - case seenInfo.kind - of PSeenMsg: - pm("$1 was last seen on $2 in $3 saying: $4" % - [seenInfo.nick, $seenInfo.timestamp, - seenInfo.channel, seenInfo.msg]) - of PSeenJoin: - pm("$1 was last seen on $2 joining $3" % - [seenInfo.nick, $seenInfo.timestamp, seenInfo.channel]) - of PSeenPart: - pm("$1 was last seen on $2 leaving $3 with message: $4" % - [seenInfo.nick, $seenInfo.timestamp, seenInfo.channel, - seenInfo.msg]) - of PSeenQuit: - pm("$1 was last seen on $2 quitting with message: $3" % - [seenInfo.nick, $seenInfo.timestamp, seenInfo.msg]) - of PSeenNick: - pm("$1 was last seen on $2 changing nick to $3" % - [seenInfo.nick, $seenInfo.timestamp, seenInfo.newNick]) - - else: - pm("I have not seen " & nick) - else: - pm("Syntax: !seen <nick>") - - # TODO: ... commands - - # -- Seen - # Log this as activity. - createSeen(PSeenMsg, event.nick, event.origin) - seenNick.msg = msg - state.database.setSeen(seenNick) - of MJoin: - createSeen(PSeenJoin, event.nick, event.origin) - state.database.setSeen(seenNick) - of MPart: - createSeen(PSeenPart, event.nick, event.origin) - let msg = event.params[event.params.high] - seenNick.msg = msg - state.database.setSeen(seenNick) - of MQuit: - createSeen(PSeenQuit, event.nick, event.origin) - let msg = event.params[event.params.high] - seenNick.msg = msg - state.database.setSeen(seenNick) - of MNick: - createSeen(PSeenNick, event.nick, "#nimrod") - seenNick.newNick = event.params[0] - state.database.setSeen(seenNick) - else: - nil # TODO: ? - -proc open(port: TPort = TPort(5123)): PState = - var res: PState - new(res) - res.dispatcher = newDispatcher() - - res.hubPort = port - res.hubConnect() - let hirc = - proc (a: PAsyncIRC, ev: TIRCEvent) = - handleIrc(a, ev, res) - # Connect to the irc server. - res.ircClient = AsyncIrc(ircServer, nick = botNickname, user = botNickname, - joinChans = joinChans, ircEvent = hirc) - res.ircClient.connect() - res.dispatcher.register(res.ircClient) - - res.dbConnected = false - result = res - -var state = tircbot.open() # Connect to the website and the IRC server. - -while state.dispatcher.poll(): - if state.dbConnected: - state.database.keepAlive() diff --git a/tests/compile/tisop.nim b/tests/compile/tisop.nim deleted file mode 100644 index 509cc4e95..000000000 --- a/tests/compile/tisop.nim +++ /dev/null @@ -1,42 +0,0 @@ -import typetraits - -type - TRecord = (tuple) or (object) - - TFoo[T, U] = object - x: int - - when T is string: - y: float - else: - y: string - - when U is TRecord: - z: float - - E = enum A, B, C - -macro m(t: typedesc): typedesc = - if t is enum: - result = string - else: - result = int - -var f: TFoo[int, int] -static: assert(f.y.type.name == "string") - -when compiles(f.z): - {.error: "Foo should not have a `z` field".} - -proc p(a, b) = - when a.type is int: - static: assert false - - var f: TFoo[m(a.type), b.type] - static: - assert f.x.type.name == "int" - assert f.y.type.name == "float" - assert f.z.type.name == "float" - -p(A, f) - diff --git a/tests/compile/titer.nim b/tests/compile/titer.nim deleted file mode 100644 index 19a11dc4e..000000000 --- a/tests/compile/titer.nim +++ /dev/null @@ -1,44 +0,0 @@ -# Test the new iterators - -iterator xrange(fromm, to: int, step = 1): int = - var a = fromm - while a <= to: - yield a - inc(a, step) - -iterator interval[T](a, b: T): T = - var x = a - while x <= b: - yield x - inc(x) - -# -#iterator lines(filename: string): (line: string) = -# var -# f: tTextfile -# shouldClose = open(f, filename) -# if shouldClose: -# setSpace(line, 256) -# while readTextLine(f, line): -# yield line -# finally: -# if shouldClose: close(f) -# - -for i in xrange(0, 5): - for k in xrange(1, 7): - write(stdout, "test") - -for j in interval(45, 45): - write(stdout, "test2!") - write(stdout, "test3?") - -for x in items(["hi", "what's", "your", "name"]): - echo(x) - -const - stringArray = ["hi", "what's", "your", "name"] - -for i in 0..len(stringArray)-1: - echo(stringArray[i]) - diff --git a/tests/compile/titer2.nim b/tests/compile/titer2.nim deleted file mode 100644 index dab2713e8..000000000 --- a/tests/compile/titer2.nim +++ /dev/null @@ -1,51 +0,0 @@ -discard """ - output: '''true''' - cmd: "nimrod cc --gc:none --hints:on $# $#" -""" - -import hashes - -type - TSlotEnum = enum seEmpty, seFilled, seDeleted - TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B] - TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]] - TTable* {.final.}[A, B] = object - data: TKeyValuePairSeq[A, B] - counter: int - -iterator mycountup(a, b: int): int = - var res = a - while res <= b: - yield res - inc(res) - -when true: - iterator pairs*[A, B](t: TTable[A, B]): tuple[key: A, val: B] = - ## iterates over any (key, value) pair in the table `t`. - for h in mycountup(0, high(t.data)): - var k = t.data[h].key - if t.data[h].slot == seFilled: yield (k, t.data[h].val) -else: - iterator pairs*(t: TTable[int, string]): tuple[key: int, val: string] = - ## iterates over any (key, value) pair in the table `t`. - for h in mycountup(0, high(t.data)): - var k = t.data[h].key - if t.data[h].slot == seFilled: yield (k, t.data[h].val) - -proc initTable*[A, B](initialSize=64): TTable[A, B] = - ## creates a new hash table that is empty. `initialSize` needs to be - ## a power of two. - result.counter = 0 - newSeq(result.data, initialSize) - -block Test1: - # generic cache does not instantiate the same iterator[types] twice. This - # means we have only one instantiation of 'h'. However, this is the same for - # a non-generic iterator! - - var t = initTable[int, string]() - for k, v in t.pairs: nil - for k, v in t.pairs: nil - -echo "true" - diff --git a/tests/compile/titer_no_tuple_unpack.nim b/tests/compile/titer_no_tuple_unpack.nim deleted file mode 100644 index da5e1bc46..000000000 --- a/tests/compile/titer_no_tuple_unpack.nim +++ /dev/null @@ -1,13 +0,0 @@ - -iterator xrange(fromm, to: int, step = 1): tuple[x, y: int] = - var a = fromm - while a <= to: - yield (a, a+1) - inc(a, step) - -for a, b in xrange(3, 7): - echo a, " ", b - -for tup in xrange(3, 7): - echo tup - diff --git a/tests/compile/titerovl.nim b/tests/compile/titerovl.nim deleted file mode 100644 index be665b2b7..000000000 --- a/tests/compile/titerovl.nim +++ /dev/null @@ -1,21 +0,0 @@ -discard """ - output: '''9 -1 -2 -3 -''' -""" - -# Test the new overloading rules for iterators: - -# test that iterator 'p' is preferred: -proc p(): seq[int] = @[1, 2, 3] -iterator p(): int = yield 9 - -for x in p(): echo x - -# test that 'q' works in this position: -proc q(): seq[int] = @[1, 2, 3] - -for x in q(): echo x - diff --git a/tests/compile/tlastmod.nim b/tests/compile/tlastmod.nim deleted file mode 100644 index 75b047fc8..000000000 --- a/tests/compile/tlastmod.nim +++ /dev/null @@ -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() diff --git a/tests/compile/tlexer.nim b/tests/compile/tlexer.nim deleted file mode 100644 index 10a8ab51d..000000000 --- a/tests/compile/tlexer.nim +++ /dev/null @@ -1,60 +0,0 @@ -discard """ - disabled: true -""" - -# We start with a comment -# This is the same comment - -# This is a new one! - -import - lexbase, os, strutils - -type - TMyRec {.final.} = object - x, y: int # coordinates - c: char # a character - a: int32 # an integer - - PMyRec = ref TMyRec # a reference to `TMyRec` - -proc splitText(txt: string): seq[string] # splits a text into several lines - # the comment continues here - # this is not easy to parse! - -proc anotherSplit(txt: string): seq[string] = - # the comment should belong to `anotherSplit`! - # another problem: comments are statements! - -const - x = 0B0_10001110100_0000101001000111101011101111111011000101001101001001'f64 # x ~~ 1.72826e35 - myNan = 0B01111111100000101100000000001000'f32 # NAN - y = """ - a rather long text. - Over many - lines. - """ - s = "\xff" - a = {0..234} - b = {0..high(int)} - v = 0'i32 - z = 6767566'f32 - -# small test program for lexbase - -proc main*(infile: string, a, b: int, someverylongnamewithtype = 0, - anotherlongthingie = 3) = - var - myInt: int = 0 - s: seq[string] - # this should be an error! - if initBaseLexer(L, infile, 30): nil - else: - writeln(stdout, "could not open: " & infile) - writeln(stdout, "Success!") - call(3, # we use 3 - 12, # we use 12 - 43) # we use 43 - - -main(ParamStr(1), 9, 0) diff --git a/tests/compile/tlibs.nim b/tests/compile/tlibs.nim deleted file mode 100644 index 971b2b836..000000000 --- a/tests/compile/tlibs.nim +++ /dev/null @@ -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") diff --git a/tests/compile/tlinearscanend.nim b/tests/compile/tlinearscanend.nim deleted file mode 100644 index 15fd0c70a..000000000 --- a/tests/compile/tlinearscanend.nim +++ /dev/null @@ -1,24 +0,0 @@ - -import strutils - -var x = 343 - -case stdin.readline.parseInt -of 0: - echo "most common case" -of 1: - {.linearScanEnd.} - echo "second most common case" -of 2: echo "unlikely: use branch table" -else: - echo "unlikely too: use branch table" - - -case x -of 23: echo "23" -of 343: echo "343" -of 21: echo "21" -else: - {.linearScanEnd.} - echo "default" - diff --git a/tests/compile/tloops.nim b/tests/compile/tloops.nim deleted file mode 100644 index f6f939769..000000000 --- a/tests/compile/tloops.nim +++ /dev/null @@ -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]() - diff --git a/tests/compile/tmacro1.nim b/tests/compile/tmacro1.nim deleted file mode 100644 index 3a67c2611..000000000 --- a/tests/compile/tmacro1.nim +++ /dev/null @@ -1,23 +0,0 @@ -import macros - -from uri import `/` - -macro test*(a: stmt): stmt {.immediate.} = - var nodes: tuple[a, b: int] - nodes.a = 4 - nodes[1] = 45 - - type - TTypeEx = object - x, y: int - case b: bool - of false: nil - of true: z: float - - var t: TTypeEx - t.b = true - t.z = 4.5 - -test: - "hi" - diff --git a/tests/compile/tmacro2.nim b/tests/compile/tmacro2.nim deleted file mode 100644 index 39324e497..000000000 --- a/tests/compile/tmacro2.nim +++ /dev/null @@ -1,59 +0,0 @@ -import macros,json - -var decls{.compileTime.}: seq[PNimrodNode] = @[] -var impls{.compileTime.}: seq[PNimrodNode] = @[] - -macro importImpl_forward(name, returns): stmt {.immediate.} = - result = newNimNode(nnkEmpty) - var func_name = newNimNode(nnkAccQuoted) - func_name.add newIdentNode("import") - func_name.add name - - var res = newNimNode(nnkProcDef) - res.add newNimNode(nnkPostfix) - res[0].add newIdentNode("*") - res[0].add func_name - res.add newNimNode(nnkEmpty) - res.add newNimNode(nnkEmpty) - res.add newNimNode(nnkFormalParams) - res[3].add returns - var p1 = newNimNode(nnkIdentDefs) - p1.add newIdentNode("dat") - p1.add newIdentNOde("PJsonNode") - p1.add newNimNode(nnkEmpty) - res[3].add p1 - var p2 = newNimNode(nnkIdentDefs) - p2.add newIdentNode("errors") - p2.add newNimNode(nnkVarTy) - p2.add newNimNode(nnkEmpty) - p2[1].add newNimNode(nnkBracketExpr) - p2[1][0].add newIdentNode("seq") - p2[1][0].add newIdentNode("string") - res[3].add p2 - - res.add newNimNode(nnkEmpty) - res.add newNimNode(nnkEmpty) - res.add newNimNode(nnkEmpty) - - decls.add res - echo(repr(res)) - -macro importImpl(name, returns: expr, body: stmt): stmt {.immediate.} = - #var res = getAST(importImpl_forward(name, returns)) - discard getAST(importImpl_forward(name, returns)) - var res = copyNimTree(decls[decls.high]) - res[6] = body - echo repr(res) - impls.add res - -macro okayy:stmt = - result = newNimNode(nnkStmtList) - for node in decls: result.add node - for node in impls: result.add node - -importimpl(Item, int): - echo 42 -importImpl(Foo, int16): - echo 77 - -okayy \ No newline at end of file diff --git a/tests/compile/tmacroaspragma.nim b/tests/compile/tmacroaspragma.nim deleted file mode 100644 index 0e5c352b3..000000000 --- a/tests/compile/tmacroaspragma.nim +++ /dev/null @@ -1,8 +0,0 @@ -import macros - -macro foo(x: stmt): stmt = - echo treerepr(callsite()) - result = newNimNode(nnkStmtList) - -proc zoo() {.foo.} = echo "hi" - diff --git a/tests/compile/tmacrostmt.nim b/tests/compile/tmacrostmt.nim deleted file mode 100644 index d9c70197d..000000000 --- a/tests/compile/tmacrostmt.nim +++ /dev/null @@ -1,26 +0,0 @@ -import macros -macro case_token(n: stmt): stmt {.immediate.} = - # creates a lexical analyzer from regular expressions - # ... (implementation is an exercise for the reader :-) - nil - -case_token: # this colon tells the parser it is a macro statement -of r"[A-Za-z_]+[A-Za-z_0-9]*": - return tkIdentifier -of r"0-9+": - return tkInteger -of r"[\+\-\*\?]+": - return tkOperator -else: - return tkUnknown - -case_token: inc i - -#bug #488 - -macro foo: stmt = - var exp = newCall("whatwhat", newIntLitNode(1)) - if compiles(getAst(exp)): return exp - else: echo "Does not compute!" - -foo() diff --git a/tests/compile/tmacrotypes.nim b/tests/compile/tmacrotypes.nim deleted file mode 100644 index 7697dba27..000000000 --- a/tests/compile/tmacrotypes.nim +++ /dev/null @@ -1,12 +0,0 @@ -import macros, typetraits - -macro checkType(ex, expected: expr): stmt {.immediate.} = - var t = ex.typ - assert t.name == expected.strVal - -proc voidProc = echo "hello" -proc intProc(a, b): int = 10 - -checkType(voidProc(), "void") -checkType(intProc(10, 20.0), "int") -checkType(noproc(10, 20.0), "Error Type") diff --git a/tests/compile/tmandelbrot.nim b/tests/compile/tmandelbrot.nim deleted file mode 100644 index 1e39c8756..000000000 --- a/tests/compile/tmandelbrot.nim +++ /dev/null @@ -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 - diff --git a/tests/compile/tmarshal.nim b/tests/compile/tmarshal.nim deleted file mode 100644 index 5471d347a..000000000 --- a/tests/compile/tmarshal.nim +++ /dev/null @@ -1,65 +0,0 @@ -discard """ - output: "" -""" - -import marshal - -template testit(x: expr) = echo($$to[type(x)]($$x)) - -var x: array[0..4, array[0..4, string]] = [ - ["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"], - ["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"], - ["test", "1", "2", "3", "4"]] -testit(x) -var test2: tuple[name: string, s: int] = ("tuple test", 56) -testit(test2) - -type - TE = enum - blah, blah2 - - TestObj = object - test, asd: int - case test2: TE - of blah: - help: string - else: - nil - - PNode = ref TNode - TNode = object - next, prev: PNode - data: string - -proc buildList(): PNode = - new(result) - new(result.next) - new(result.prev) - result.data = "middle" - result.next.data = "next" - result.prev.data = "prev" - result.next.next = result.prev - result.next.prev = result - result.prev.next = result - result.prev.prev = result.next - -var test3: TestObj -test3.test = 42 -test3.test2 = blah -testit(test3) - -var test4: ref tuple[a, b: string] -new(test4) -test4.a = "ref string test: A" -test4.b = "ref string test: B" -testit(test4) - -var test5 = @[(0,1),(2,3),(4,5)] -testit(test5) - -var test7 = buildList() -testit(test7) - -var test6: set[char] = {'A'..'Z', '_'} -testit(test6) - diff --git a/tests/compile/tmath.nim b/tests/compile/tmath.nim deleted file mode 100644 index 6a1dae54d..000000000 --- a/tests/compile/tmath.nim +++ /dev/null @@ -1,85 +0,0 @@ -# tests for the interpreter - -proc loops(a: var int) = - nil - #var - # b: int - #b = glob - #while b != 0: - # b = b + 1 - #a = b - -proc mymax(a, b: int): int = - #loops(result) - result = a - if b > a: result = b - -proc test(a, b: int) = - var - x, y: int - x = 0 - y = 7 - if x == a + b * 3 - 7 or - x == 8 or - x == y and y > -56 and y < 699: - y = 0 - elif y == 78 and x == 0: - y = 1 - elif y == 0 and x == 0: - y = 2 - else: - y = 3 - -type - TTokType = enum - tkNil, tkType, tkConst, tkVar, tkSymbol, tkIf, - tkWhile, tkFor, tkLoop, tkCase, tkLabel, tkGoto - -proc testCase(t: TTokType): int = - case t - of tkNil, tkType, tkConst: result = 0 - of tkVar: result = 1 - of tkSymbol: result = 2 - of tkIf..tkFor: result = 3 - of tkLoop: result = 56 - else: result = -1 - test(0, 9) # test the call - -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 - - -var - glob: int - a: array [0..5, int] - -proc main() = - #glob = 0 - #loops( glob ) - var - res: int - s: string - #write(stdout, mymax(23, 45)) - write(stdout, "Hallo! Wie heißt du? ") - s = readLine(stdin) - # test the case statement - case s - of "Andreas": write(stdout, "Du bist mein Meister!\n") - of "Rumpf": write(stdout, "Du bist in der Familie meines Meisters!\n") - else: write(stdout, "ich kenne dich nicht!\n") - write(stdout, "Du heisst " & s & "\n") - -main() diff --git a/tests/compile/tmatrix1.nim b/tests/compile/tmatrix1.nim deleted file mode 100644 index 0adf30b57..000000000 --- a/tests/compile/tmatrix1.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ - output: "right proc called" -""" - -type - TMatrixNM*[M, N, T] = object - aij*: array[M, array[N, T]] - TMatrix2x2*[T] = TMatrixNM[range[0..1], range[0..1], T] - TMatrix3x3*[T] = TMatrixNM[range[0..2], range[0..2], T] - -proc test*[T] (matrix: TMatrix2x2[T]) = - echo "wrong proc called" - -proc test*[T] (matrix: TMatrix3x3[T]) = - echo "right proc called" - -var matrix: TMatrix3x3[float] - -matrix.test diff --git a/tests/compile/tmatrix2.nim b/tests/compile/tmatrix2.nim deleted file mode 100644 index 442096e93..000000000 --- a/tests/compile/tmatrix2.nim +++ /dev/null @@ -1,22 +0,0 @@ -discard """ - output: "5.0000000000000000e+00" -""" - -type - TMatrixNM*[M, N, T] = object - aij*: T - TVectorN*[N, T] = TMatrixNM[range[0..0], N, T] - TVector3*[T] = TVectorN[range[0..2], T] - -proc coeffRef*[M, N, T] (matrix: var TMatrixNM[M, N, T], a: M, b: N): var T = - return matrix.aij - -proc coeffRef*[N, T] (vector: var TVectorN[N, T], i: N): var T = vector.aij - -var - testVar: TVector3[float] - -testVar.aij = 2.0 -testVar.coeffRef(1) = 5.0 - -echo testVar.aij diff --git a/tests/compile/tmatrix3.nim b/tests/compile/tmatrix3.nim deleted file mode 100644 index 900404524..000000000 --- a/tests/compile/tmatrix3.nim +++ /dev/null @@ -1,41 +0,0 @@ -discard """ - output: '''0.0000000000000000e+00 -0.0000000000000000e+00 -0 -0 -0 -''' -""" - -include compilehelpers - -type - Matrix*[M, N, T] = object - aij*: array[M, array[N, T]] - - Matrix2*[T] = Matrix[range[0..1], range[0..1], T] - - Matrix3*[T] = Matrix[range[0..2], range[0..2], T] - -proc mn(x: Matrix): Matrix.T = x.aij[0][0] - -proc m2(x: Matrix2): Matrix2.T = x.aij[0][0] - -proc m3(x: Matrix3): auto = x.aij[0][0] - -var - matn: Matrix[range[0..3], range[0..2], int] - mat2: Matrix2[int] - mat3: Matrix3[float] - -echo m3(mat3) -echo mn(mat3) -echo m2(mat2) -echo mn(mat2) -echo mn(matn) - -reject m3(mat2) -reject m3(matn) -reject m2(mat3) -reject m2(matn) - diff --git a/tests/compile/tmodulealias.nim b/tests/compile/tmodulealias.nim deleted file mode 100644 index a7d155e51..000000000 --- a/tests/compile/tmodulealias.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ - disabled: true -""" - -when defined(windows): - import winlean -else: - import posix - -when defined(Windows): - template orig: expr = - winlean -else: - template orig: expr = - posix - -proc socket(domain, typ, protocol: int): int = - result = orig.socket(ord(domain), ord(typ), ord(protocol))) - diff --git a/tests/compile/tmongo.nim b/tests/compile/tmongo.nim deleted file mode 100644 index 1c4c0f4e6..000000000 --- a/tests/compile/tmongo.nim +++ /dev/null @@ -1,16 +0,0 @@ - -import mongo, db_mongo, oids, json - -var conn = db_mongo.open() - -var data = %{"a": %13, "b": %"my string value", - "inner": %{"i": %71} } - -var id = insertID(conn, "test.test", data) - -for v in find(conn, "test.test", "this.a == 13"): - print v - -delete(conn, "test.test", id) - -close(conn) diff --git a/tests/compile/tnamedparamanonproc.nim b/tests/compile/tnamedparamanonproc.nim deleted file mode 100644 index 272b84e91..000000000 --- a/tests/compile/tnamedparamanonproc.nim +++ /dev/null @@ -1,14 +0,0 @@ - -type - PButton = ref object - TButtonClicked = proc(button: PButton) {.nimcall.} - -proc newButton*(onClick: TButtonClicked) = - nil - -proc main() = - newButton(onClick = proc(b: PButton) = - var requestomat = 12 - ) - -main() diff --git a/tests/compile/tnamedparams.nim b/tests/compile/tnamedparams.nim deleted file mode 100644 index 4b0cd5361..000000000 --- a/tests/compile/tnamedparams.nim +++ /dev/null @@ -1,8 +0,0 @@ -import pegs - -discard parsePeg( - pattern = "input", - filename = "filename", - line = 1, - col = 23) - diff --git a/tests/compile/tnestedproc.nim b/tests/compile/tnestedproc.nim deleted file mode 100644 index 49ec6f9a7..000000000 --- a/tests/compile/tnestedproc.nim +++ /dev/null @@ -1,12 +0,0 @@ -discard """ - output: "11" -""" - -proc p(x, y: int): int = - result = x + y - -echo p((proc (): int = - var x = 7 - return x)(), - (proc (): int = return 4)()) - diff --git a/tests/compile/tnew.nim b/tests/compile/tnew.nim deleted file mode 100644 index 6527541a2..000000000 --- a/tests/compile/tnew.nim +++ /dev/null @@ -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() diff --git a/tests/compile/tnewlibs.nim b/tests/compile/tnewlibs.nim deleted file mode 100644 index bdb53ae0b..000000000 --- a/tests/compile/tnewlibs.nim +++ /dev/null @@ -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") diff --git a/tests/compile/tnewsets.nim b/tests/compile/tnewsets.nim deleted file mode 100644 index 415fe8f7e..000000000 --- a/tests/compile/tnewsets.nim +++ /dev/null @@ -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 ) diff --git a/tests/compile/tnewuns.nim b/tests/compile/tnewuns.nim deleted file mode 100644 index 5181e467c..000000000 --- a/tests/compile/tnewuns.nim +++ /dev/null @@ -1,12 +0,0 @@ -# test the new unsigned operations: - -import - strutils - -var - x, y: int - -x = 1 -y = high(int) - -writeln(stdout, $ ( x +% y ) ) diff --git a/tests/compile/tnimrodnode_for_runtime.nim b/tests/compile/tnimrodnode_for_runtime.nim deleted file mode 100644 index e73c8430f..000000000 --- a/tests/compile/tnimrodnode_for_runtime.nim +++ /dev/null @@ -1,13 +0,0 @@ -discard """ - output: "bla" - disabled: true -""" - -import macros -proc makeMacro: PNimrodNode = - result = nil - -var p = makeMacro() - -echo "bla" - diff --git a/tests/compile/tnoargopenarray.nim b/tests/compile/tnoargopenarray.nim deleted file mode 100644 index 872ec86d2..000000000 --- a/tests/compile/tnoargopenarray.nim +++ /dev/null @@ -1,7 +0,0 @@ - -import db_sqlite - -var db: TDbConn -Exec(db, sql"create table blabla()") - - diff --git a/tests/compile/tnoforward.nim b/tests/compile/tnoforward.nim deleted file mode 100644 index 0359ff348..000000000 --- a/tests/compile/tnoforward.nim +++ /dev/null @@ -1,10 +0,0 @@ -{. noforward: on .} - -proc foo(x: int) = - bar x - -proc bar(x: int) = - echo x - -foo(10) - diff --git a/tests/compile/tobjconstr2.nim b/tests/compile/tobjconstr2.nim deleted file mode 100644 index cb47e146d..000000000 --- a/tests/compile/tobjconstr2.nim +++ /dev/null @@ -1,22 +0,0 @@ -type TFoo{.exportc.} = object - x:int - -var s{.exportc.}: seq[TFoo] = @[] - -s.add TFoo(x: 42) - -echo s[0].x - - -# bug #563 -type - Foo = - object {.inheritable.} - x: int - - Bar = - object of Foo - y: int - -var a = Bar(y: 100, x: 200) # works -var b = Bar(x: 100, y: 200) # used to fail diff --git a/tests/compile/tobjcov.nim b/tests/compile/tobjcov.nim deleted file mode 100644 index fc44edf8e..000000000 --- a/tests/compile/tobjcov.nim +++ /dev/null @@ -1,17 +0,0 @@ -# Covariance is not type safe: - -type - TA = object of TObject - a: int - TB = object of TA - b: array[0..5000_000, int] - -proc ap(x: var TA) = x.a = -1 -proc bp(x: var TB) = x.b[high(x.b)] = -1 - -# in Nimrod proc (x: TB) is compatible to proc (x: TA), -# but this is not type safe: -var f = cast[proc (x: var TA) {.nimcall.}](bp) -var a: TA -f(a) # bp expects a TB, but gets a TA - diff --git a/tests/compile/tobject2.nim b/tests/compile/tobject2.nim deleted file mode 100644 index 0f1869695..000000000 --- a/tests/compile/tobject2.nim +++ /dev/null @@ -1,21 +0,0 @@ -# Tests the object implementation - -type - TPoint2d {.inheritable.} = object - x, y: int - - TPoint3d = object of TPoint2d - z: int # added a field - -proc getPoint( p: var TPoint2d) = - {.breakpoint.} - writeln(stdout, p.x) - -var - p: TPoint3d - -TPoint2d(p).x = 34 -p.y = 98 -p.z = 343 - -getPoint(p) diff --git a/tests/compile/tobject3.nim b/tests/compile/tobject3.nim deleted file mode 100644 index 935e6ca8c..000000000 --- a/tests/compile/tobject3.nim +++ /dev/null @@ -1,28 +0,0 @@ -type - TFoo = ref object of TObject - Data: int - TBar = ref object of TFoo - nil - TBar2 = ref object of TBar - d2: int - -template super(self: TBar): TFoo = self - -template super(self: TBar2): TBar = self - -proc Foo(self: TFoo) = - echo "TFoo" - -#proc Foo(self: TBar) = -# echo "TBar" -# Foo(super(self)) -# works when this code is uncommented - -proc Foo(self: TBar2) = - echo "TBar2" - Foo(super(self)) - -var b: TBar2 -new(b) - -Foo(b) diff --git a/tests/compile/tobjects.nim b/tests/compile/tobjects.nim deleted file mode 100644 index 06fa15583..000000000 --- a/tests/compile/tobjects.nim +++ /dev/null @@ -1,52 +0,0 @@ -type - TBase = object of TObject - x, y: int - - TSubclassKind = enum ka, kb, kc, kd, ke, kf - TSubclass = object of TBase - case c: TSubclassKind - of ka, kb, kc, kd: - a, b: int - of ke: - d, e, f: char - else: nil - n: bool - -type - TMyObject = object of TObject - case disp: range[0..4] - of 0: arg: char - of 1: s: string - else: wtf: bool - -var - x: TMyObject - -var - global: int - -var - s: string - r: float = 0.0 - i: int = 500 + 400 - -case i -of 500..999: write(stdout, "ha!\n") -of 1000..3000, 12: write(stdout, "ganz schön groß\n") -of 1, 2, 3: write(stdout, "1 2 oder 3\n") -else: write(stdout, "sollte nicht passieren\n") - -case readLine(stdin) -of "Rumpf": write(stdout, "Hallo Meister!\n") -of "Andreas": write(stdout, "Hallo Meister!\n") -else: write(stdout, "Nicht mein Meister!\n") - -global = global + 1 -write(stdout, "Hallo wie heißt du? \n") -s = readLine(stdin) -i = 0 -while i < len(s): - if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") - i = i + 1 - -write(stdout, "Du heißt " & s) diff --git a/tests/compile/toop.nim b/tests/compile/toop.nim deleted file mode 100644 index 0b42c2c22..000000000 --- a/tests/compile/toop.nim +++ /dev/null @@ -1,21 +0,0 @@ -discard """ - output: "b" -""" - -type - TA = object of TObject - x, y: int - - TB = object of TA - z: int - - TC = object of TB - whatever: string - -proc p(a: var TA) = echo "a" -proc p(b: var TB) = echo "b" - -var c: TC - -p(c) - diff --git a/tests/compile/toptions.nim b/tests/compile/toptions.nim deleted file mode 100644 index 3c841de2c..000000000 --- a/tests/compile/toptions.nim +++ /dev/null @@ -1,18 +0,0 @@ - -type - # please make sure we have under 32 options (improves code efficiency!) - TOption = enum - optNone, optForceFullMake, optBoehmGC, optRefcGC, optRangeCheck, - optBoundsCheck, optOverflowCheck, optNilCheck, optAssert, optLineDir, - optWarns, optHints, optDeadCodeElim, optListCmd, optCompileOnly, - optSafeCode, # only allow safe code - optStyleCheck, optOptimizeSpeed, optOptimizeSize, optGenDynLib, - optGenGuiApp, optStackTrace - - TOptionset = set[TOption] - -var - gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck, - optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace} - compilerArgs: int - gExitcode: int8 diff --git a/tests/compile/tos.nim b/tests/compile/tos.nim deleted file mode 100644 index fa9993cc9..000000000 --- a/tests/compile/tos.nim +++ /dev/null @@ -1,12 +0,0 @@ -# test some things of the os module - -import os - -proc walkDirTree(root: string) = - for k, f in walkDir(root): - case k - of pcFile, pcLinkToFile: echo(f) - of pcDir: walkDirTree(f) - of pcLinkToDir: nil - -walkDirTree(".") diff --git a/tests/compile/toverprc.nim b/tests/compile/toverprc.nim deleted file mode 100644 index 22b64ed48..000000000 --- a/tests/compile/toverprc.nim +++ /dev/null @@ -1,39 +0,0 @@ -# Test overloading of procs when used as function pointers - -import strutils - -proc parseInt(x: float): int {.noSideEffect.} = nil -proc parseInt(x: bool): int {.noSideEffect.} = nil -proc parseInt(x: float32): int {.noSideEffect.} = nil -proc parseInt(x: int8): int {.noSideEffect.} = nil -proc parseInt(x: TFile): int {.noSideEffect.} = nil -proc parseInt(x: char): int {.noSideEffect.} = nil -proc parseInt(x: int16): int {.noSideEffect.} = nil - -proc parseInt[T](x: T): int = echo x; 34 - -type - TParseInt = proc (x: string): int {.noSideEffect.} - -var - q = TParseInt(parseInt) - p: TParseInt = parseInt - -proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int = - result = x("123") - -echo "Give a list of numbers (separated by spaces): " -var x = stdin.readline.split.map(parseInt).max -echo x, " is the maximum!" -echo "another number: ", takeParseInt(parseInt) - - -type - TFoo[a,b] = object - lorem: a - ipsum: b - -proc bar[a,b](f: TFoo[a,b], x: a) = echo(x, " ", f.lorem, f.ipsum) -proc bar[a,b](f: TFoo[a,b], x: b) = echo(x, " ", f.lorem, f.ipsum) - -discard parseInt[string]("yay") diff --git a/tests/compile/tparedef.nim b/tests/compile/tparedef.nim deleted file mode 100644 index dedebf6b7..000000000 --- a/tests/compile/tparedef.nim +++ /dev/null @@ -1,4 +0,0 @@ -# This test is now superfluous: - -proc a(a: int) = - return diff --git a/tests/compile/tparscfg.nim b/tests/compile/tparscfg.nim deleted file mode 100644 index 618ecadd6..000000000 --- a/tests/compile/tparscfg.nim +++ /dev/null @@ -1,25 +0,0 @@ - -import - os, parsecfg, strutils, streams - -var f = newFileStream(paramStr(1), fmRead) -if f != nil: - var p: TCfgParser - open(p, f, paramStr(1)) - while true: - var e = next(p) - case e.kind - of cfgEof: - echo("EOF!") - break - of cfgSectionStart: ## a ``[section]`` has been parsed - echo("new section: " & e.section) - of cfgKeyValuePair: - echo("key-value-pair: " & e.key & ": " & e.value) - of cfgOption: - echo("command: " & e.key & ": " & e.value) - of cfgError: - echo(e.msg) - close(p) -else: - echo("cannot open: " & paramStr(1)) diff --git a/tests/compile/tparsefloat.nim b/tests/compile/tparsefloat.nim deleted file mode 100644 index 38ed2db6d..000000000 --- a/tests/compile/tparsefloat.nim +++ /dev/null @@ -1,3 +0,0 @@ -import strutils - -echo ParseFloat("5000") / ParseFloat("10") diff --git a/tests/compile/tparsopt.nim b/tests/compile/tparsopt.nim deleted file mode 100644 index 2b2da7e51..000000000 --- a/tests/compile/tparsopt.nim +++ /dev/null @@ -1,27 +0,0 @@ -# Test the new parseopt module - -import - parseopt - -proc writeHelp() = - writeln(stdout, "Usage: tparsopt [options] filename [options]") - -proc writeVersion() = - writeln(stdout, "Version: 1.0.0") - -var - filename = "" -for kind, key, val in getopt(): - case kind - of cmdArgument: - filename = key - of cmdLongOption, cmdShortOption: - case key - of "help", "h": writeHelp() - of "version", "v": writeVersion() - else: - writeln(stdout, "Unknown command line option: ", key, ": ", val) - of cmdEnd: assert(false) # cannot happen -if filename == "": - # no filename has been given, so we show the help: - writeHelp() diff --git a/tests/compile/tposix.nim b/tests/compile/tposix.nim deleted file mode 100644 index bf0b49586..000000000 --- a/tests/compile/tposix.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Test Posix interface - -when not defined(windows): - - import posix - - var - u: Tutsname - - discard uname(u) - - writeln(stdout, u.sysname) - writeln(stdout, u.nodename) - writeln(stdout, u.release) - writeln(stdout, u.machine) - diff --git a/tests/compile/tprep.nim b/tests/compile/tprep.nim deleted file mode 100644 index 4ef9e2543..000000000 --- a/tests/compile/tprep.nim +++ /dev/null @@ -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() diff --git a/tests/compile/tprocvars.nim b/tests/compile/tprocvars.nim deleted file mode 100644 index dc7592526..000000000 --- a/tests/compile/tprocvars.nim +++ /dev/null @@ -1,6 +0,0 @@ -proc doSomething(v: Int, x: proc(v:Int):Int): Int = return x(v) -proc doSomething(v: Int, x: proc(v:Int)) = x(v) - - -echo doSomething(10, proc(v: Int): Int = return v div 2) - diff --git a/tests/compile/tpush.nim b/tests/compile/tpush.nim deleted file mode 100644 index 5fb411a79..000000000 --- a/tests/compile/tpush.nim +++ /dev/null @@ -1,15 +0,0 @@ -# test the new pragmas - -{.push warnings: off, hints: off.} -proc noWarning() = - var - x: int - echo(x) - -{.pop.} - -proc WarnMe() = - var - x: int - echo(x) - diff --git a/tests/compile/tquicksort.nim b/tests/compile/tquicksort.nim deleted file mode 100644 index 6706a185e..000000000 --- a/tests/compile/tquicksort.nim +++ /dev/null @@ -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) - - diff --git a/tests/compile/tquit.nim b/tests/compile/tquit.nim deleted file mode 100644 index d4dc1522d..000000000 --- a/tests/compile/tquit.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Test the new beforeQuit variable: - -proc myExit() {.noconv.} = - write(stdout, "just exiting...\n") - -addQuitProc(myExit) diff --git a/tests/compile/tradix.nim b/tests/compile/tradix.nim deleted file mode 100644 index e5998ee12..000000000 --- a/tests/compile/tradix.nim +++ /dev/null @@ -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 diff --git a/tests/compile/treadln.nim b/tests/compile/treadln.nim deleted file mode 100644 index 1117ab5f9..000000000 --- a/tests/compile/treadln.nim +++ /dev/null @@ -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) diff --git a/tests/compile/treadx.nim b/tests/compile/treadx.nim deleted file mode 100644 index 49b6ad691..000000000 --- a/tests/compile/treadx.nim +++ /dev/null @@ -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 - diff --git a/tests/compile/trecmod.nim b/tests/compile/trecmod.nim deleted file mode 100644 index 9d39d3ff7..000000000 --- a/tests/compile/trecmod.nim +++ /dev/null @@ -1,2 +0,0 @@ -# recursive module -import mrecmod diff --git a/tests/compile/trecmod2.nim b/tests/compile/trecmod2.nim deleted file mode 100644 index 85fe2215f..000000000 --- a/tests/compile/trecmod2.nim +++ /dev/null @@ -1,10 +0,0 @@ -type - T1* = int # Module A exports the type ``T1`` - -import mrecmod2 # the compiler starts parsing B - -proc main() = - var i = p(3) # works because B has been parsed completely here - -main() - diff --git a/tests/compile/trectuple.nim b/tests/compile/trectuple.nim deleted file mode 100644 index 7c43ec5ba..000000000 --- a/tests/compile/trectuple.nim +++ /dev/null @@ -1,11 +0,0 @@ - -type - PNode = ref TNode - TNode = tuple # comment - self: PNode # comment - a, b: int # comment - -var node: PNode -new(node) -node.self = node - diff --git a/tests/compile/trectuples.nim b/tests/compile/trectuples.nim deleted file mode 100644 index c59cfe880..000000000 --- a/tests/compile/trectuples.nim +++ /dev/null @@ -1,10 +0,0 @@ - -type Node = tuple[left: ref Node] - -proc traverse(root: ref Node) = - if root.left != nil: traverse(root.left) - -type A = tuple[B: ptr A] -proc C(D: ptr A) = C(D.B) - - diff --git a/tests/compile/tredef.nim b/tests/compile/tredef.nim deleted file mode 100644 index 02d1f7776..000000000 --- a/tests/compile/tredef.nim +++ /dev/null @@ -1,29 +0,0 @@ -template foo(a: int, b: string) = nil -foo(1, "test") - -proc bar(a: int, b: string) = nil -bar(1, "test") - -template foo(a: int, b: string) = bar(a, b) -foo(1, "test") - -block: - proc bar(a: int, b: string) = nil - template foo(a: int, b: string) = nil - foo(1, "test") - bar(1, "test") - -proc baz = - proc foo(a: int, b: string) = nil - proc foo(b: string) = - template bar(a: int, b: string) = nil - bar(1, "test") - - foo("test") - - block: - proc foo(b: string) = nil - foo("test") - foo(1, "test") - -baz() diff --git a/tests/compile/trepr.nim b/tests/compile/trepr.nim deleted file mode 100644 index b15081e48..000000000 --- a/tests/compile/trepr.nim +++ /dev/null @@ -1,32 +0,0 @@ -# test the new "repr" built-in proc - -type - TEnum = enum - en1, en2, en3, en4, en5, en6 - - TPoint {.final.} = object - x, y, z: int - s: array [0..1, string] - e: TEnum - -var - p: TPoint - q: ref TPoint - s: seq[ref TPoint] - -p.x = 0 -p.y = 13 -p.z = 45 -p.s[0] = "abc" -p.s[1] = "xyz" -p.e = en6 - -new(q) -q[] = p - -s = @[q, q, q, q] - -writeln(stdout, repr(p)) -writeln(stdout, repr(q)) -writeln(stdout, repr(s)) -writeln(stdout, repr(en4)) diff --git a/tests/compile/tsecondarrayproperty.nim b/tests/compile/tsecondarrayproperty.nim deleted file mode 100644 index 07fdac1c4..000000000 --- a/tests/compile/tsecondarrayproperty.nim +++ /dev/null @@ -1,28 +0,0 @@ - -type - TFoo = object - data: array[0..100, int] - TSecond = distinct TFoo - -proc `[]` (self: var TFoo, x: int): var int = - return self.data[x] - -proc `[]=` (self: var TFoo, x, y: int) = - # only `[]` returning a 'var T' seems to not work for now :-/ - self.data[x] = y - -proc second(self: var TFoo): var TSecond = - return TSecond(self) - -proc `[]`(self: var TSecond, x: int): var int = - return TFoo(self).data[2*x] - -var f: TFoo - -for i in 0..f.data.high: f[i] = 2 * i - -echo f.second[1] - -#echo `second[]`(f,1) -# this is the only way I could use it, but not what I expected - diff --git a/tests/compile/tseq2.nim b/tests/compile/tseq2.nim deleted file mode 100644 index e1271964c..000000000 --- a/tests/compile/tseq2.nim +++ /dev/null @@ -1,11 +0,0 @@ -proc `*` *(a, b: seq[int]): seq[int] = - # allocate a new sequence: - newSeq(result, len(a)) - # multiply two int sequences: - for i in 0..len(a)-1: result[i] = a[i] * b[i] - -when isMainModule: - # test the new ``*`` operator for sequences: - assert(@[1, 2, 3] * @[1, 2, 3] == @[1, 4, 9]) - - diff --git a/tests/compile/tseqcon2.nim b/tests/compile/tseqcon2.nim deleted file mode 100644 index 4f2763ffe..000000000 --- a/tests/compile/tseqcon2.nim +++ /dev/null @@ -1,9 +0,0 @@ -import os - -proc rec_dir(dir: string): seq[string] = - result = @[] - for kind, path in walk_dir(dir): - if kind == pcDir: - add(result, rec_dir(path)) - else: - add(result, path) diff --git a/tests/compile/tshadow_magic_type.nim b/tests/compile/tshadow_magic_type.nim deleted file mode 100644 index 5cd27435e..000000000 --- a/tests/compile/tshadow_magic_type.nim +++ /dev/null @@ -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) diff --git a/tests/compile/tsizeof.nim b/tests/compile/tsizeof.nim deleted file mode 100644 index f7b70dd4d..000000000 --- a/tests/compile/tsizeof.nim +++ /dev/null @@ -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)) diff --git a/tests/compile/tslurp.nim b/tests/compile/tslurp.nim deleted file mode 100644 index f9456ce6b..000000000 --- a/tests/compile/tslurp.nim +++ /dev/null @@ -1,6 +0,0 @@ - -const - myRes = slurp"../../readme.txt" - -echo myRes - diff --git a/tests/compile/tsockets.nim b/tests/compile/tsockets.nim deleted file mode 100644 index 6078504f5..000000000 --- a/tests/compile/tsockets.nim +++ /dev/null @@ -1,11 +0,0 @@ -import sockets -var s: TSocket -s = socket() - -s.connect("www.google.com", TPort(80)) - -var data: string = "" -s.readLine(data) -echo(data) - - diff --git a/tests/compile/tsortcall.nim b/tests/compile/tsortcall.nim deleted file mode 100644 index efe1d0b8b..000000000 --- a/tests/compile/tsortcall.nim +++ /dev/null @@ -1,5 +0,0 @@ -import algorithm - -proc foosort(ships: var seq[int]) = sort(ships, system.cmp[int]) - - diff --git a/tests/compile/tspecialised_is_equivalent.nim b/tests/compile/tspecialised_is_equivalent.nim deleted file mode 100644 index 60b976e90..000000000 --- a/tests/compile/tspecialised_is_equivalent.nim +++ /dev/null @@ -1,15 +0,0 @@ -## -## specialised_is_equivalent Nimrod Module -## -## Created by Eric Doughty-Papassideris on 2011-02-16. -## Copyright (c) 2011 FWA. All rights reserved. - -type - TGen[T] = tuple[a: T] - TSpef = tuple[a: string] - -var - a: TGen[string] - b: TSpef -a = b - diff --git a/tests/compile/tstrace.nim b/tests/compile/tstrace.nim deleted file mode 100644 index 3032a34a3..000000000 --- a/tests/compile/tstrace.nim +++ /dev/null @@ -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) diff --git a/tests/compile/tstrdesc.nim b/tests/compile/tstrdesc.nim deleted file mode 100644 index 1c2e85b4b..000000000 --- a/tests/compile/tstrdesc.nim +++ /dev/null @@ -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 - - diff --git a/tests/compile/tstrdist.nim b/tests/compile/tstrdist.nim deleted file mode 100644 index 3e1939e73..000000000 --- a/tests/compile/tstrdist.nim +++ /dev/null @@ -1,26 +0,0 @@ -# compute the edit distance between two strings - -proc editDistance(a, b: string): int = - var - c: seq[int] - n = a.len - m = b.len - newSeq(c, (n+1)*(m+1)) - for i in 0..n: - c[i*n] = i # [i,0] - for j in 0..m: - c[j] = j # [0,j] - - for i in 1..n: - for j in 1..m: - var x = c[(i-1)*n + j]+1 - var y = c[i*n + j-1]+1 - var z: int - if a[i-1] == b[j-1]: - z = c[(i-1)*n + j-1] - else: - z = c[(i-1)*n + j-1]+1 - c[(i-1)*n + (j-1)] = min(x,min(y,z)) - return c[n*m] - -write(stdout, editDistance("abc", "abd")) diff --git a/tests/compile/tstreams.nim b/tests/compile/tstreams.nim deleted file mode 100644 index 640565a27..000000000 --- a/tests/compile/tstreams.nim +++ /dev/null @@ -1,7 +0,0 @@ -import streams - -var outp = newFileStream(stdout) -var inp = newFileStream(stdin) -write(outp, "Hello! What is your name?") -var line = readLine(inp) -write(outp, "Nice name: " & line) diff --git a/tests/compile/tstrset.nim b/tests/compile/tstrset.nim deleted file mode 100644 index 9cdb5ed35..000000000 --- a/tests/compile/tstrset.nim +++ /dev/null @@ -1,74 +0,0 @@ -# test a simple yet highly efficient set of strings - -type - TRadixNodeKind = enum rnLinear, rnFull, rnLeaf - PRadixNode = ref TRadixNode - TRadixNode = object {.inheritable.} - kind: TRadixNodeKind - TRadixNodeLinear = object of TRadixNode - len: int8 - keys: array [0..31, char] - vals: array [0..31, PRadixNode] - TRadixNodeFull = object of TRadixNode - b: array [char, PRadixNode] - TRadixNodeLeaf = object of TRadixNode - s: string - PRadixNodeLinear = ref TRadixNodeLinear - PRadixNodeFull = ref TRadixNodeFull - PRadixNodeLeaf = ref TRadixNodeLeaf - -proc search(r: PRadixNode, s: string): PRadixNode = - var r = r - var i = 0 - while r != nil: - case r.kind - of rnLinear: - var x = PRadixNodeLinear(r) - for j in 0..ze(x.len)-1: - if x.keys[j] == s[i]: - if s[i] == '\0': return r - r = x.vals[j] - inc(i) - break - break # character not found - of rnFull: - var x = PRadixNodeFull(r) - var y = x.b[s[i]] - if s[i] == '\0': - return if y != nil: r else: nil - r = y - inc(i) - of rnLeaf: - var x = PRadixNodeLeaf(r) - var j = 0 - while true: - if x.s[j] != s[i]: return nil - if s[i] == '\0': return r - inc(j) - inc(i) - -proc contains*(r: PRadixNode, s: string): bool = - return search(r, s) != nil - -proc testOrincl*(r: var PRadixNode, s: string): bool = - nil - -proc incl*(r: var PRadixNode, s: string) = discard testOrIncl(r, s) - -proc excl*(r: var PRadixNode, s: string) = - var x = search(r, s) - if x == nil: return - case x.kind - of rnLeaf: PRadixNodeLeaf(x).s = "" - of rnFull: PRadixNodeFull(x).b['\0'] = nil - of rnLinear: - var x = PRadixNodeLinear(x) - for i in 0..ze(x.len)-1: - if x.keys[i] == '\0': - swap(x.keys[i], x.keys[ze(x.len)-1]) - dec(x.len) - break - -var - root: PRadixNode - diff --git a/tests/compile/tstrtabs.nim b/tests/compile/tstrtabs.nim deleted file mode 100644 index 251ec77ef..000000000 --- a/tests/compile/tstrtabs.nim +++ /dev/null @@ -1,12 +0,0 @@ -import strtabs - -var tab = newStringTable({"key1": "val1", "key2": "val2"}, - modeStyleInsensitive) -for i in 0..80: - tab["key_" & $i] = "value" & $i - -for key, val in pairs(tab): - writeln(stdout, key, ": ", val) -writeln(stdout, "length of table ", $tab.len) - -writeln(stdout, `%`("$key1 = $key2; ${PATH}", tab, {useEnvironment})) diff --git a/tests/compile/ttableconstr.nim b/tests/compile/ttableconstr.nim deleted file mode 100644 index c627e68e8..000000000 --- a/tests/compile/ttableconstr.nim +++ /dev/null @@ -1,16 +0,0 @@ -# Test if the new table constructor syntax works: - -template ignoreExpr(e: expr): stmt {.immediate.} = - nil - -# test first class '..' syntactical citizen: -ignoreExpr x <> 2..4 -# test table constructor: -ignoreExpr({:}) -ignoreExpr({2: 3, "key": "value"}) - -# NEW: -assert 56 in 50..100 - -assert 56 in ..60 - diff --git a/tests/compile/ttempl.nim b/tests/compile/ttempl.nim deleted file mode 100644 index 2c4785325..000000000 --- a/tests/compile/ttempl.nim +++ /dev/null @@ -1,27 +0,0 @@ -# Test the new template file mechanism - -import - os, times - -include "sunset.tmpl" - -const - tabs = [["home", "index"], - ["news", "news"], - ["documentation", "documentation"], - ["download", "download"], - ["FAQ", "question"], - ["links", "links"]] - - -var i = 0 -for item in items(tabs): - var content = $i - var file: TFile - if open(file, changeFileExt(item[1], "html"), fmWrite): - write(file, sunsetTemplate(current=item[1], ticker="", content=content, - tabs=tabs)) - close(file) - else: - write(stdout, "cannot open file for writing") - inc(i) diff --git a/tests/compile/ttempl3.nim b/tests/compile/ttempl3.nim deleted file mode 100644 index 59be24624..000000000 --- a/tests/compile/ttempl3.nim +++ /dev/null @@ -1,58 +0,0 @@ - -template withOpenFile(f: expr, filename: string, mode: TFileMode, - actions: stmt): stmt {.immediate.} = - block: - # test that 'f' is implicitly 'injecting': - var f: TFile - if open(f, filename, mode): - try: - actions - finally: - close(f) - else: - quit("cannot open for writing: " & filename) - -withOpenFile(txt, "ttempl3.txt", fmWrite): - writeln(txt, "line 1") - txt.writeln("line 2") - -var - myVar: array[0..1, int] - -# Test zero argument template: -template ha: expr = myVar[0] - -ha = 1 -echo(ha) - - -# Test identifier generation: -template prefix(name: expr): expr {.immediate.} = `"hu" name` - -var `hu "XYZ"` = "yay" - -echo prefix(XYZ) - -template typedef(name: expr, typ: typeDesc) {.immediate, dirty.} = - type - `T name`* = typ - `P name`* = ref `T name` - -typedef(myint, int) -var x: PMyInt - - -# Test UFCS - -type - Foo = object - arg: int - -proc initFoo(arg: int): Foo = - result.arg = arg - -template create(typ: typeDesc, arg: expr): expr = `init typ`(arg) - -var ff = Foo.create(12) - -echo ff.arg diff --git a/tests/compile/ttempl4.nim b/tests/compile/ttempl4.nim deleted file mode 100644 index 26c82e471..000000000 --- a/tests/compile/ttempl4.nim +++ /dev/null @@ -1,8 +0,0 @@ - -template `:=`(name, val: expr): stmt {.immediate.} = - var name = val - -ha := 1 * 4 -hu := "ta-da" == "ta-da" -echo ha, hu - diff --git a/tests/compile/ttempl5.nim b/tests/compile/ttempl5.nim deleted file mode 100644 index 85692e97b..000000000 --- a/tests/compile/ttempl5.nim +++ /dev/null @@ -1,5 +0,0 @@ - -import mtempl5 - -echo templ() - diff --git a/tests/compile/ttemplreturntype.nim b/tests/compile/ttemplreturntype.nim deleted file mode 100644 index 642fa1b72..000000000 --- a/tests/compile/ttemplreturntype.nim +++ /dev/null @@ -1,4 +0,0 @@ - -template `=~` (a: int, b: int): bool = false -var foo = 2 =~ 3 - diff --git a/tests/compile/tthread_generic.nim b/tests/compile/tthread_generic.nim deleted file mode 100644 index beae4b652..000000000 --- a/tests/compile/tthread_generic.nim +++ /dev/null @@ -1,39 +0,0 @@ -discard """ - cmd: "nimrod cc --hints:on --threads:on $# $#" -""" - -type - TThreadFuncArgs[T] = object of TObject - a: proc(): T {.thread.} - b: proc(val: T) {.thread.} - -proc handleThreadFunc(arg: TThreadFuncArgs[int]){.thread.} = - var func = arg.a - var callback = arg.b - var output = func() - callback(output) - -proc `@||->`*[T](func: proc(): T {.thread.}, - callback: proc(val: T){.thread.}): TThread[TThreadFuncArgs[T]] = - var thr: TThread[TThreadFuncArgs[T]] - var args: TThreadFuncArgs[T] - args.a = func - args.b = callback - createThread(thr, handleThreadFunc, args) - return thr - -proc `||->`*[T](func: proc(): T{.thread.}, callback: proc(val: T){.thread.}) = - discard func @||-> callback - -when isMainModule: - import os - proc testFunc(): int {.thread.} = - return 1 - proc callbackFunc(val: int) {.thread.} = - echo($(val)) - - var thr = (testFunc @||-> callbackFunc) - echo("test") - joinThread(thr) - os.sleep(3000) - diff --git a/tests/compile/ttime.nim b/tests/compile/ttime.nim deleted file mode 100644 index bad818816..000000000 --- a/tests/compile/ttime.nim +++ /dev/null @@ -1,6 +0,0 @@ -# test the new time module - -import - times - -write(stdout, $getTime()) diff --git a/tests/compile/ttuple1.nim b/tests/compile/ttuple1.nim deleted file mode 100644 index 5787cc309..000000000 --- a/tests/compile/ttuple1.nim +++ /dev/null @@ -1,16 +0,0 @@ -const romanNumbers = [ - ("M", 1000), ("D", 500), ("C", 100), - ("L", 50), ("X", 10), ("V", 5), ("I", 1) ] - -var c = 0 -for key, val in items(romanNumbers): - inc(c) - stdout.write(key & "=" & $val) - if c < romanNumbers.len: stdout.write(", ") else: echo"" -#echo"" - -proc PrintBiTuple(t: tuple[k: string, v: int]): int = - stdout.write(t.k & "=" & $t.v & ", ") - return 0 - - diff --git a/tests/compile/ttypeclasses.nim b/tests/compile/ttypeclasses.nim deleted file mode 100644 index 677229868..000000000 --- a/tests/compile/ttypeclasses.nim +++ /dev/null @@ -1,55 +0,0 @@ -type - TFoo[T] = object - val: T - - T1 = expr - T2 = expr - - Numeric = int|float - -proc takesExpr(x, y) = - echo x, y - -proc same(x, y: T1) = - echo x, y - -proc takesFoo(x, y: TFoo) = - echo x.val, y.val - -proc takes2Types(x,y: T1, z: T2) = - echo x, y, z - -takesExpr(1, 2) -takesExpr(1, "xxx") -takesExpr[bool, int](true, 0) - -same(1, 2) -same("test", "test") - -var f: TFoo[int] -f.val = 10 - -takesFoo(f, f) - -takes2Types(1, 1, "string") -takes2Types[string, int]("test", "test", 1) - -proc takesSeq(x: seq) = - echo "seq" - -takesSeq(@[1, 2, 3]) -takesSeq(@["x", "y", "z"]) - -proc takesSeqOfFoos(x: seq[TFoo]) = - echo "foo seq" - -var sf = newSeq[TFoo[int]](3) - -takesSeq(sf) -takesSeqOfFoos(sf) - -proc takesFooOfNumeric(x: TFoo[Numeric]) = - echo "foo of numeric" - -takesFooOfNumeric(sf[0]) - diff --git a/tests/compile/ttypeconverter1.nim b/tests/compile/ttypeconverter1.nim deleted file mode 100644 index b9a5e88ae..000000000 --- a/tests/compile/ttypeconverter1.nim +++ /dev/null @@ -1,8 +0,0 @@ - -converter p(i: int): bool = return i != 0 - -if 1: - echo if 4: "foo" else: "barr" -while 0: - echo "bar" - diff --git a/tests/compile/ttypeselectors.nim b/tests/compile/ttypeselectors.nim deleted file mode 100644 index cca643e1f..000000000 --- a/tests/compile/ttypeselectors.nim +++ /dev/null @@ -1,39 +0,0 @@ -import macros - -template selectType(x: int): typeDesc = - when x < 10: - int - else: - string - -template simpleTypeTempl: typeDesc = - string - -macro typeFromMacro: typedesc = string - -proc t1*(x: int): simpleTypeTempl() = - result = "test" - -proc t2*(x: int): selectType(100) = - result = "test" - -proc t3*(x: int): selectType(1) = - result = 10 - -proc t4*(x: int): typeFromMacro() = - result = "test" - -var x*: selectType(50) = "test" - -proc t5*(x: selectType(5)) = - var y = x + 10 - echo y - -var y*: type(t2(100)) = "test" - -proc t6*(x: type(t3(0))): type(t1(0)) = - result = $x - -proc t7*(x: int): type($x) = - result = "test" - diff --git a/tests/compile/tuserpragma.nim b/tests/compile/tuserpragma.nim deleted file mode 100644 index 784baa176..000000000 --- a/tests/compile/tuserpragma.nim +++ /dev/null @@ -1,7 +0,0 @@ - -{.pragma: rtl, cdecl, exportc.} - -proc myproc(x, y: int): int {.rtl} = - nil - - diff --git a/tests/compile/tvarious.nim b/tests/compile/tvarious.nim deleted file mode 100644 index 5883ba62f..000000000 --- a/tests/compile/tvarious.nim +++ /dev/null @@ -1,63 +0,0 @@ -# Test various aspects - -# bug #572 -var a=12345678901'u64 - -var x = (x: 42, y: (a: 8, z: 10)) -echo x.y - -import - mvarious - -type - PA = ref TA - PB = ref TB - - TB = object - a: PA - - TA = object - b: TB - x: int - -proc getPA(): PA = - var - b: bool - b = not false - return nil - -# bug #501 -proc f(): int = 54 - -var - global: int - -var - s: string - i: int - r: TA - -r.b.a.x = 0 -global = global + 1 -exportme() -write(stdout, "Hallo wie heißt du? ") -write(stdout, getPA().x) -s = readLine(stdin) -i = 0 -while i < s.len: - if s[i] == 'c': write(stdout, "'c' in deinem Namen gefunden\n") - i = i + 1 - -write(stdout, "Du heißt " & s) - -# bug #544 - -type Bar [T; I:range] = array[I, T] -proc foo*[T; I:range](a, b: Bar[T, I]): Bar[T, I] = - when len(a) != 3: - # Error: constant expression expected - {.fatal:"Dimensions have to be 3".} - #... -block: - var a, b: Bar[int, 0..2] - discard foo(a, b) diff --git a/tests/compile/tvoid.nim b/tests/compile/tvoid.nim deleted file mode 100644 index bb569e7f8..000000000 --- a/tests/compile/tvoid.nim +++ /dev/null @@ -1,33 +0,0 @@ -discard """ - output: "he, no return type;abc a string" -""" - -proc ReturnT[T](x: T): T = - when T is void: - echo "he, no return type;" - else: - result = x & " a string" - -proc nothing(x, y: void): void = - echo "ha" - -proc callProc[T](p: proc (x: T) {.nimcall.}, x: T) = - when T is void: - p() - else: - p(x) - -proc intProc(x: int) = - echo x - -proc emptyProc() = - echo "empty" - -callProc[int](intProc, 12) -callProc[void](emptyProc) - - -ReturnT[void]() -echo ReturnT[string]("abc") -nothing() - diff --git a/tests/compile/twalker.nim b/tests/compile/twalker.nim deleted file mode 100644 index 89e6c2b9d..000000000 --- a/tests/compile/twalker.nim +++ /dev/null @@ -1,13 +0,0 @@ -# iterate over all files with a given filter: - -import - "../../lib/pure/os.nim", ../../ lib / pure / times - -proc main(filter: string) = - for filename in walkFiles(filter): - writeln(stdout, filename) - - for key, val in envPairs(): - writeln(stdout, key & '=' & val) - -main("*.nim") diff --git a/tests/compile/typalias.nim b/tests/compile/typalias.nim deleted file mode 100644 index ba9f38ed9..000000000 --- a/tests/compile/typalias.nim +++ /dev/null @@ -1,15 +0,0 @@ - -type - TMyObj = TYourObj - TYourObj = object of TObject - x, y: int - -proc init: TYourObj = - result.x = 0 - result.y = -1 - -proc f(x: var TYourObj) = - nil - -var m: TMyObj = init() -f(m) |