diff options
Diffstat (limited to 'tests')
44 files changed, 361 insertions, 186 deletions
diff --git a/tests/caas/idetools_api.nim b/tests/caas/idetools_api.nim index 8f1061e27..281e562d7 100644 --- a/tests/caas/idetools_api.nim +++ b/tests/caas/idetools_api.nim @@ -58,7 +58,7 @@ macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} = ## Expect docstrings let exp = callsite() template expectBody(errorTypes, lineInfoLit: expr, - body: stmt): PNimrodNode {.dirty.} = + body: stmt): NimNode {.dirty.} = try: body assert false diff --git a/tests/collections/ttablesref.nim b/tests/collections/ttablesref.nim index b57aedf4a..16b0d831e 100644 --- a/tests/collections/ttablesref.nim +++ b/tests/collections/ttablesref.nim @@ -2,7 +2,7 @@ discard """ output: '''true''' """ -import hashes, tables +import hashes, tables, sequtils const data = { @@ -103,9 +103,10 @@ block countTableTest1: block SyntaxTest: var x = newTable[int, string]({:}) + discard x block nilTest: - var i, j: PTable[int, int] = nil + var i, j: TableRef[int, int] = nil assert i == j j = newTable[int, int]() assert i != j @@ -131,6 +132,10 @@ proc orderedTableSortTest() = # check that insert still works: t["newKeyHere"] = 80 +block anonZipTest: + let keys = @['a','b','c'] + let values = @[1, 2, 3] + doAssert "{a: 1, b: 2, c: 3}" == $ toTable zip(keys, values) orderedTableSortTest() echo "true" diff --git a/tests/metatype/udtcmanual.nim b/tests/concepts/tmanual.nim index dd44298dc..243992aed 100644 --- a/tests/metatype/udtcmanual.nim +++ b/tests/concepts/tmanual.nim @@ -12,6 +12,7 @@ e s t ''' + disabled: "true" """ template accept(e: expr) = diff --git a/tests/metatype/swizzle.nim b/tests/concepts/tswizzle.nim index ce18fa234..9bbdb67e6 100644 --- a/tests/metatype/swizzle.nim +++ b/tests/concepts/tswizzle.nim @@ -3,6 +3,7 @@ discard """ [1, 3] [2, 1, 2] ''' + disabled: "true" """ import macros, strutils @@ -18,14 +19,14 @@ proc swizzleIdx(c: char): int = of 'x': 0 of 'y': 1 of 'z': 2 - of 'w': 3 + of 'w': 3 of 'r': 0 of 'g': 1 of 'b': 2 - of 'a': 3 + of 'a': 3 else: 0 -proc isSwizzle(s: string): bool = +proc isSwizzle(s: string): bool {.compileTime.} = template trySet(name, set) = block search: for c in s: @@ -35,10 +36,10 @@ proc isSwizzle(s: string): bool = trySet coords, {'x', 'y', 'z', 'w'} trySet colors, {'r', 'g', 'b', 'a'} - + return false -type +type StringIsSwizzle = generic value value.isSwizzle @@ -47,33 +48,33 @@ type proc foo(x: SwizzleStr) = echo "sw" -accept foo("xx") +#foo("xx") reject foo("xe") -type +type Vec[N: static[int]; T] = array[N, T] +when false: + proc card(x: Vec): int = x.N + proc `$`(x: Vec): string = x.repr.strip -proc card(x: Vec): int = x.N -proc `$`(x: Vec): string = x.repr.strip + macro `.`(x: Vec, swizzle: SwizzleStr): expr = + var + cardinality = swizzle.len + values = newNimNode(nnkBracket) + v = genSym() -macro `.`(x: Vec, swizzle: SwizzleStr): expr = - var - cardinality = swizzle.len - values = newNimNode(nnkBracket) - v = genSym() + for c in swizzle: + values.add newNimNode(nnkBracketExpr).add( + v, c.swizzleIdx.newIntLitNode) - for c in swizzle: - values.add newNimNode(nnkBracketExpr).add( - v, c.swizzleIdx.newIntLitNode) - - return quote do: - let `v` = `x` - Vec[`cardinality`, `v`.T](`values`) + return quote do: + let `v` = `x` + Vec[`cardinality`, `v`.T](`values`) var z = Vec([1, 2, 3]) -echo z.card -echo z.xz -echo z.yxy +#echo z.card +#echo z.xz +#echo z.yxy diff --git a/tests/metatype/tusertypeclasses.nim b/tests/concepts/tusertypeclasses.nim index 4e5e6221c..4e5e6221c 100644 --- a/tests/metatype/tusertypeclasses.nim +++ b/tests/concepts/tusertypeclasses.nim diff --git a/tests/metatype/tusertypeclasses2.nim b/tests/concepts/tusertypeclasses2.nim index 77c70d7a6..77c70d7a6 100644 --- a/tests/metatype/tusertypeclasses2.nim +++ b/tests/concepts/tusertypeclasses2.nim diff --git a/tests/converter/ttypeconverter1.nim b/tests/converter/ttypeconverter1.nim index fd3a0318a..510b84700 100644 --- a/tests/converter/ttypeconverter1.nim +++ b/tests/converter/ttypeconverter1.nim @@ -1,5 +1,5 @@ discard """ - ouput: '''foo + output: '''foo true''' """ diff --git a/tests/generics/tarray_with_somenumber.nim b/tests/generics/tarray_with_somenumber.nim new file mode 100644 index 000000000..0bf2537a1 --- /dev/null +++ b/tests/generics/tarray_with_somenumber.nim @@ -0,0 +1,11 @@ +discard """ + output: '''@[0.9, 0.1]''' +""" + +# bug #2304 + +type TV2*[T:SomeNumber] = array[0..1, T] +proc newV2T*[T](x, y: T=0): TV2[T] = [x, y] + +let x = newV2T[float](0.9, 0.1) +echo(@x) diff --git a/tests/generics/tunique_type.nim b/tests/generics/tunique_type.nim index 29367181c..e78640caa 100644 --- a/tests/generics/tunique_type.nim +++ b/tests/generics/tunique_type.nim @@ -20,13 +20,13 @@ import strutils # This serves the same purpose as D's `alias` parameters for types, used heavily # in its popular `ranges` and `algorithm` modules. -var exprNodes {.compileTime.} = newSeq[PNimrodNode]() +var exprNodes {.compileTime.} = newSeq[NimNode]() -proc refExpr(exprNode: PNimrodNode): string {.compileTime.} = +proc refExpr(exprNode: NimNode): string {.compileTime.} = exprNodes.add exprNode.copy "expr" & $(exprNodes.len - 1) -proc derefExpr(exprRef: string): PNimrodNode {.compileTime.} = +proc derefExpr(exprRef: string): NimNode {.compileTime.} = exprNodes[parseInt(exprRef[4 .. -1])] #=============================================================================== diff --git a/tests/let/tlet2.nim b/tests/let/tlet2.nim index 8b1ddf940..66dd5a55b 100644 --- a/tests/let/tlet2.nim +++ b/tests/let/tlet2.nim @@ -1,6 +1,6 @@ discard """ line: "13" - errormsg: "for a 'var' type a variable needs to be passed" + errormsg: "type mismatch: got (int literal(8), int literal(5), int, int)" """ proc divmod(a, b: int, res, remainder: var int) = diff --git a/tests/macros/tbugs.nim b/tests/macros/tbugs.nim index 3db851dd1..1ecb0d4cc 100644 --- a/tests/macros/tbugs.nim +++ b/tests/macros/tbugs.nim @@ -46,13 +46,13 @@ echotest() # bug #1103 -type +type Td = tuple a:string b:int proc get_data(d: Td) : string {.compileTime.} = - result = d.a # Works if a literal string is used here. + result = d.a # Works if a literal string is used here. # Bugs if line A or B is active. Works with C result &= "aa" # A #result.add("aa") # B @@ -69,7 +69,7 @@ m(s) # bug #933 -proc nilcheck(): PNimrodNode {.compileTime.} = +proc nilcheck(): NimNode {.compileTime.} = echo(result == nil) # true echo(result.isNil) # true echo(repr(result)) # nil diff --git a/tests/macros/tdumpast.nim b/tests/macros/tdumpast.nim index 160e4e194..e3388591a 100644 --- a/tests/macros/tdumpast.nim +++ b/tests/macros/tdumpast.nim @@ -1,4 +1,4 @@ -# Dump the contents of a PNimrodNode +# Dump the contents of a NimNode import macros @@ -7,7 +7,7 @@ template plus(a, b: expr): expr {.dirty} = 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() @@ -24,10 +24,10 @@ macro dumpAST(n: stmt): stmt {.immediate.} = 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/macros/tdumpast2.nim b/tests/macros/tdumpast2.nim index 2a7024a01..6b694fa77 100644 --- a/tests/macros/tdumpast2.nim +++ b/tests/macros/tdumpast2.nim @@ -1,13 +1,13 @@ -# Dump the contents of a PNimrodNode +# Dump the contents of a NimNode import macros -proc dumpit(n: PNimrodNode): string {.compileTime.} = +proc dumpit(n: NimNode): string {.compileTime.} = if n == nil: return "nil" result = $n.kind add(result, "(") case n.kind - of nnkEmpty: discard # same as nil node in this representation + of nnkEmpty: discard # 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) @@ -20,17 +20,17 @@ proc dumpit(n: PNimrodNode): string {.compileTime.} = add(result, ", ") add(result, dumpit(n[j])) add(result, ")") - -macro dumpAST(n: stmt): stmt {.immediate.} = + +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/macros/tgensym.nim b/tests/macros/tgensym.nim index 3f4140ff4..b3aef0a2c 100644 --- a/tests/macros/tgensym.nim +++ b/tests/macros/tgensym.nim @@ -2,7 +2,7 @@ import rawsockets, asyncdispatch, macros var p = newDispatcher() var sock = newAsyncRawSocket() -proc convertReturns(node, retFutureSym: PNimrodNode): PNimrodNode {.compileTime.} = +proc convertReturns(node, retFutureSym: NimNode): NimNode {.compileTime.} = case node.kind of nnkReturnStmt: result = newCall(newIdentNode("complete"), retFutureSym, node[0]) @@ -19,19 +19,19 @@ macro async2(prc: stmt): stmt {.immediate.} = # -> var retFuture = newFuture[T]() var retFutureSym = newIdentNode("retFuture") #genSym(nskVar, "retFuture") outerProcBody.add( - newVarStmt(retFutureSym, + newVarStmt(retFutureSym, newCall( newNimNode(nnkBracketExpr).add( newIdentNode("newFuture"), prc[3][0][1])))) # Get type from return type of this proc. - # -> iterator nameIter(): PFutureBase {.closure.} = <proc_body> + # -> iterator nameIter(): FutureBase {.closure.} = <proc_body> # Changing this line to: newIdentNode($prc[0].ident & "Iter") # will make it work. var iteratorNameSym = genSym(nskIterator, $prc[0].ident & "Iter") #var iteratorNameSym = newIdentNode($prc[0].ident & "Iter") var procBody = prc[6].convertReturns(retFutureSym) - var closureIterator = newProc(iteratorNameSym, [newIdentNode("PFutureBase")], + var closureIterator = newProc(iteratorNameSym, [newIdentNode("FutureBase")], procBody, nnkIteratorDef) closureIterator[4] = newNimNode(nnkPragma).add(newIdentNode("closure")) outerProcBody.add(closureIterator) @@ -55,8 +55,8 @@ macro async2(prc: stmt): stmt {.immediate.} = result[6] = outerProcBody -proc readStuff(): PFuture[string] {.async2.} = - var fut = connect(sock, "irc.freenode.org", TPort(6667)) +proc readStuff(): Future[string] {.async2.} = + var fut = connect(sock, "irc.freenode.org", Port(6667)) yield fut var fut2 = recv(sock, 50) yield fut2 diff --git a/tests/macros/tgentemplates.nim b/tests/macros/tgentemplates.nim index a7727c597..764b94bc7 100644 --- a/tests/macros/tgentemplates.nim +++ b/tests/macros/tgentemplates.nim @@ -2,7 +2,7 @@ import parseutils, macros -proc parse_until_symbol(node: PNimrodNode, value: string, index: var int): bool {.compiletime.} = +proc parse_until_symbol(node: NimNode, value: string, index: var int): bool {.compiletime.} = var splitValue: string var read = value.parseUntil(splitValue, '$', index) @@ -15,7 +15,7 @@ proc parse_until_symbol(node: PNimrodNode, value: string, index: var int): bool if splitValue.len > 0: node.insert node.len, newCall("add", ident("result"), newStrLitNode(splitValue)) -proc parse_template(node: PNimrodNode, value: string) {.compiletime.} = +proc parse_template(node: NimNode, value: string) {.compiletime.} = var index = 0 while index < value.len and parse_until_symbol(node, value, index): discard diff --git a/tests/macros/tmacro1.nim b/tests/macros/tmacro1.nim index 3a67c2611..2dd5c31df 100644 --- a/tests/macros/tmacro1.nim +++ b/tests/macros/tmacro1.nim @@ -3,17 +3,17 @@ import macros from uri import `/` macro test*(a: stmt): stmt {.immediate.} = - var nodes: tuple[a, b: int] + 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 diff --git a/tests/macros/tmacro3.nim b/tests/macros/tmacro3.nim index 162212326..d7421ff7f 100644 --- a/tests/macros/tmacro3.nim +++ b/tests/macros/tmacro3.nim @@ -4,7 +4,7 @@ discard """ import macros -type +type TA = tuple[a: int] PA = ref TA @@ -19,7 +19,7 @@ test: macro test2*(a: stmt): stmt {.immediate.} = proc testproc(recurse: int) = echo "Thats weird" - var o : PNimrodNode = nil + var o : NimNode = nil echo " no its not!" o = newNimNode(nnkNone) if recurse > 0: diff --git a/tests/macros/tmacro4.nim b/tests/macros/tmacro4.nim index 10a23b159..a56369369 100644 --- a/tests/macros/tmacro4.nim +++ b/tests/macros/tmacro4.nim @@ -7,7 +7,7 @@ import macro test_macro*(n: stmt): stmt {.immediate.} = result = newNimNode(nnkStmtList) - var ass : PNimrodNode = newNimNode(nnkAsgn) + var ass : NimNode = newNimNode(nnkAsgn) add(ass, newIdentNode("str")) add(ass, newStrLitNode("after")) add(result, ass) diff --git a/tests/macros/tmacro5.nim b/tests/macros/tmacro5.nim index 9882ad90d..d7a4fe8c8 100644 --- a/tests/macros/tmacro5.nim +++ b/tests/macros/tmacro5.nim @@ -1,7 +1,7 @@ import macros,json -var decls{.compileTime.}: seq[PNimrodNode] = @[] -var impls{.compileTime.}: seq[PNimrodNode] = @[] +var decls{.compileTime.}: seq[NimNode] = @[] +var impls{.compileTime.}: seq[NimNode] = @[] macro importImpl_forward(name, returns): stmt {.immediate.} = result = newNimNode(nnkEmpty) @@ -38,7 +38,7 @@ macro importImpl_forward(name, returns): stmt {.immediate.} = decls.add res echo(repr(res)) -macro importImpl(name, returns: expr, body: stmt): stmt {.immediate.} = +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]) @@ -56,4 +56,4 @@ importImpl(Item, int): importImpl(Foo, int16): echo 77 -okayy \ No newline at end of file +okayy diff --git a/tests/macros/tmacros1.nim b/tests/macros/tmacros1.nim index 3c814ad6d..1a1073a44 100644 --- a/tests/macros/tmacros1.nim +++ b/tests/macros/tmacros1.nim @@ -15,10 +15,10 @@ macro outterMacro*(n: stmt): stmt {.immediate.} = expectKind(n, TNimrodNodeKind.nnkCall) if n.len != 3 or n[1].kind != TNimrodNodeKind.nnkIdent: error("Macro " & callNode.repr & - " requires the ident passed as parameter (eg: " & callNode.repr & + " requires the ident passed as parameter (eg: " & callNode.repr & "(the_name_you_want)): statements.") result = newNimNode(TNimrodNodeKind.nnkStmtList) - var ass : PNimrodNode = newNimNode(nnkAsgn) + var ass : NimNode = newNimNode(nnkAsgn) ass.add(newIdentNode(n[1].ident)) ass.add(newStrLitNode(innerProc(4))) result.add(ass) diff --git a/tests/macros/tnimnode_for_runtime.nim b/tests/macros/tnimnode_for_runtime.nim index 69c7aedd2..0520cd0dd 100644 --- a/tests/macros/tnimnode_for_runtime.nim +++ b/tests/macros/tnimnode_for_runtime.nim @@ -3,7 +3,7 @@ discard """ """ import macros -proc makeMacro: PNimrodNode = +proc makeMacro: NimNode = result = nil var p = makeMacro() diff --git a/tests/macros/tstringinterp.nim b/tests/macros/tstringinterp.nim index a500ed56e..bc79cdaba 100644 --- a/tests/macros/tstringinterp.nim +++ b/tests/macros/tstringinterp.nim @@ -19,7 +19,7 @@ template processInterpolations(e: expr) = macro formatStyleInterpolation(e: expr): expr = let e = callsite() - var + var formatString = "" arrayNode = newNimNode(nnkBracket) idx = 1 @@ -27,14 +27,14 @@ macro formatStyleInterpolation(e: expr): expr = proc addString(s: string) = formatString.add(s) - proc addExpr(e: PNimrodNode) = + proc addExpr(e: NimNode) = arrayNode.add(e) formatString.add("$" & $(idx)) inc idx proc addDollar() = formatString.add("$$") - + processInterpolations(e) result = parseExpr("\"x\" % [y]") @@ -43,11 +43,11 @@ macro formatStyleInterpolation(e: expr): expr = macro concatStyleInterpolation(e: expr): expr = let e = callsite() - var args: seq[PNimrodNode] + var args: seq[NimNode] newSeq(args, 0) proc addString(s: string) = args.add(newStrLitNode(s)) - proc addExpr(e: PNimrodNode) = args.add(e) + proc addExpr(e: NimNode) = args.add(e) proc addDollar() = args.add(newStrLitNode"$") processInterpolations(e) @@ -59,7 +59,7 @@ macro concatStyleInterpolation(e: expr): expr = proc sum(a, b, c: int): int = return (a + b + c) -var +var alice = "Alice" bob = "Bob" a = 10 diff --git a/tests/macros/tvarnimnode.nim b/tests/macros/tvarnimnode.nim index 73fcc16ea..ab0f66caa 100644 --- a/tests/macros/tvarnimnode.nim +++ b/tests/macros/tvarnimnode.nim @@ -6,7 +6,7 @@ discard """ import macros -proc test(f: var PNimrodNode) {.compileTime.} = +proc test(f: var NimNode) {.compileTime.} = f = newNimNode(nnkStmtList) f.add newCall(newIdentNode("echo"), newLit(10)) diff --git a/tests/manyloc/keineschweine/dependencies/genpacket/genpacket.nim b/tests/manyloc/keineschweine/dependencies/genpacket/genpacket.nim index ae9dfb39f..3026cc4b9 100644 --- a/tests/manyloc/keineschweine/dependencies/genpacket/genpacket.nim +++ b/tests/manyloc/keineschweine/dependencies/genpacket/genpacket.nim @@ -18,9 +18,9 @@ proc `$`*[T](x: seq[T]): string = result.add($x[i]) result.add ']' -macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = +macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = result = newNimNode(nnkStmtList) - let + let typeName = quoted2ident(typeNameN) packetID = ^"p" streamID = ^"s" @@ -66,7 +66,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = readBody = newNimNode(nnkStmtList) lenNames = 0 for i in 0.. typeFields.len - 1: - let + let name = typeFields[i][0] dotName = packetID.dot(name) resName = newIdentNode(!"result").dot(name) @@ -91,11 +91,11 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = newNimNode(nnkDiscardStmt).und( newCall("readData", streamID, newNimNode(nnkAddr).und(resName), newCall("sizeof", resName)))) packBody.add( - newCall("writeData", streamID, newNimNode(nnkAddr).und(dotName), newCall("sizeof", dotName))) + newCall("writeData", streamID, newNimNode(nnkAddr).und(dotName), newCall("sizeof", dotName))) of "seq": ## let lenX = readInt16(s) newLenName() - let + let item = ^"item" ## item name in our iterators seqType = typeFields[i][1][1] ## type of seq readName = newIdentNode("read"& $seqType.ident) @@ -107,7 +107,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = readBody.add( ## result.name = @[] resName := ("@".prefix(newNimNode(nnkBracket))), newNimNode(nnkForStmt).und( ## for item in 1..len: - item, + item, infix(1.lit, "..", lenName), newNimNode(nnkStmtList).und( newCall( ## add(result.name, unpack[seqType](stream)) @@ -117,7 +117,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = newNimNode(nnkVarSection).und(newNimNode(nnkIdentDefs).und( lenName, ## var lenName = int16(len(p.name)) newIdentNode("int16"), - newCall("int16", newCall("len", dotName)))), + newCall("int16", newCall("len", dotName)))), newCall("writeData", streamID, newNimNode(nnkAddr).und(lenName), 2.lit), newNimNode(nnkForStmt).und( ## for item in 0..length - 1: pack(p.name[item], stream) item, @@ -143,8 +143,8 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = readBody.add(resName := newCall("read"& $typeFields[i][1].ident, streamID)) else: error("I dont know what to do with: "& treerepr(typeFields[i])) - - var + + var toStringFunc = newNimNode(nnkProcDef).und( newNimNode(nnkPostfix).und( ^"*", @@ -161,12 +161,12 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = emptyNode(), newNimNode(nnkStmtList).und(#[6] newNimNode(nnkAsgn).und( - ^"result", ## result = + ^"result", ## result = newNimNode(nnkCall).und(#[6][0][1] ^"format", ## format emptyNode())))) ## "[TypeName $1 $2]" formatStr = "["& $typeName.ident - + const emptyFields = {nnkEmpty, nnkNilLit} var objFields = newNimNode(nnkRecList) for i in 0.. < len(typeFields): @@ -186,10 +186,10 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = prefix("$", packetID.dot(fname))) formatStr.add " $" formatStr.add($(i + 1)) - + formatStr.add ']' toStringFunc[6][0][1][1] = formatStr.lit() - + result.add( newNimNode(nnkTypeSection).und( newNimNode(nnkTypeDef).und( @@ -206,15 +206,15 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = when defined(GenPacketShowOutput): echo(repr(result)) -proc `->`(a: string, b: string): PNimrodNode {.compileTime.} = +proc `->`(a: string, b: string): NimNode {.compileTime.} = result = newNimNode(nnkIdentDefs).und(^a, ^b, newNimNode(nnkEmpty)) -proc `->`(a: string, b: PNimrodNode): PNimrodNode {.compileTime.} = +proc `->`(a: string, b: NimNode): NimNode {.compileTime.} = result = newNimNode(nnkIdentDefs).und(^a, b, newNimNode(nnkEmpty)) -proc `->`(a, b: PNimrodNode): PNimrodNode {.compileTime.} = +proc `->`(a, b: NimNode): NimNode {.compileTime.} = a[2] = b result = a -proc newProc*(name: string, params: varargs[PNimrodNode], resultType: PNimrodNode): PNimrodNode {.compileTime.} = +proc newProc*(name: string, params: varargs[NimNode], resultType: NimNode): NimNode {.compileTime.} = result = newNimNode(nnkProcDef).und( ^name, emptyNode(), @@ -227,7 +227,7 @@ proc newProc*(name: string, params: varargs[PNimrodNode], resultType: PNimrodNod macro forwardPacket*(typeName: expr, underlyingType: typedesc): stmt {.immediate.} = result = newNimNode(nnkStmtList).und( newProc( - "read"& $typeName.ident, + "read"& $typeName.ident, ["s" -> "PStream" -> newNimNode(nnkNilLit)], typeName), newProc( @@ -258,21 +258,21 @@ when isMainModule: A = 0'i8, B, C forwardPacket(SomeEnum, int8) - - + + defPacket(Foo, tuple[x: array[0..4, int8]]) var f = newFoo([4'i8, 3'i8, 2'i8, 1'i8, 0'i8]) var s2 = newStringStream("") f.pack(s2) assert s2.data == "\4\3\2\1\0" - + var s = newStringStream() s.flushImpl = proc(s: PStream) = var z = PStringStream(s) z.setPosition(0) z.data.setLen(0) - - + + s.setPosition(0) s.data.setLen(0) var o = B @@ -283,7 +283,7 @@ when isMainModule: o.pack(s) assert s.data == "\1\0\2" s.flush - + defPacket(Y, tuple[z: int8]) proc `$`(z: Y): string = result = "Y("& $z.z &")" defPacket(TestPkt, tuple[x: seq[Y]]) @@ -292,4 +292,4 @@ when isMainModule: for itm in test.x: echo(itm) test.pack(s) - echo(repr(s.data)) \ No newline at end of file + echo(repr(s.data)) diff --git a/tests/manyloc/keineschweine/dependencies/genpacket/genpacket_enet.nim b/tests/manyloc/keineschweine/dependencies/genpacket/genpacket_enet.nim index 4f2fb1ea3..7cfd67c49 100644 --- a/tests/manyloc/keineschweine/dependencies/genpacket/genpacket_enet.nim +++ b/tests/manyloc/keineschweine/dependencies/genpacket/genpacket_enet.nim @@ -9,9 +9,9 @@ template defPacketImports*(): stmt {.immediate, dirty.} = import macros, macro_dsl, estreams from strutils import format -macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = +macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = result = newNimNode(nnkStmtList) - let + let typeName = quoted2ident(typeNameN) packetID = ^"p" streamID = ^"s" @@ -57,7 +57,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = readBody = newNimNode(nnkStmtList) lenNames = 0 for i in 0.. typeFields.len - 1: - let + let name = typeFields[i][0] dotName = packetID.dot(name) resName = newIdentNode(!"result").dot(name) @@ -67,7 +67,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = of "seq": ## let lenX = readInt16(s) newLenName() - let + let item = ^"item" ## item name in our iterators seqType = typeFields[i][1][1] ## type of seq readName = newIdentNode("read"& $seqType.ident) @@ -79,7 +79,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = readBody.add( ## result.name = @[] resName := ("@".prefix(newNimNode(nnkBracket))), newNimNode(nnkForStmt).und( ## for item in 1..len: - item, + item, infix(1.lit, "..", lenName), newNimNode(nnkStmtList).und( newCall( ## add(result.name, unpack[seqType](stream)) @@ -89,7 +89,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = newNimNode(nnkVarSection).und(newNimNode(nnkIdentDefs).und( lenName, ## var lenName = int16(len(p.name)) newIdentNode("int16"), - newCall("int16", newCall("len", dotName)))), + newCall("int16", newCall("len", dotName)))), newCall("writeBE", streamID, lenName), newNimNode(nnkForStmt).und( ## for item in 0..length - 1: pack(p.name[item], stream) item, @@ -115,8 +115,8 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = readBody.add(resName := newCall("read"& $typeFields[i][1].ident, streamID)) else: error("I dont know what to do with: "& treerepr(typeFields[i])) - - var + + var toStringFunc = newNimNode(nnkProcDef).und( newNimNode(nnkPostfix).und( ^"*", @@ -133,12 +133,12 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = emptyNode(), newNimNode(nnkStmtList).und(#[6] newNimNode(nnkAsgn).und( - ^"result", ## result = + ^"result", ## result = newNimNode(nnkCall).und(#[6][0][1] ^"format", ## format emptyNode())))) ## "[TypeName $1 $2]" formatStr = "["& $typeName.ident - + const emptyFields = {nnkEmpty, nnkNilLit} var objFields = newNimNode(nnkRecList) for i in 0.. < len(typeFields): @@ -158,10 +158,10 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = prefix("$", packetID.dot(fname))) formatStr.add " $" formatStr.add($(i + 1)) - + formatStr.add ']' toStringFunc[6][0][1][1] = formatStr.lit() - + result.add( newNimNode(nnkTypeSection).und( newNimNode(nnkTypeDef).und( @@ -178,7 +178,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} = when defined(GenPacketShowOutput): echo(repr(result)) -proc newProc*(name: PNimrodNode; params: varargs[PNimrodNode]; resultType: PNimrodNode): PNimrodNode {.compileTime.} = +proc newProc*(name: NimNode; params: varargs[NimNode]; resultType: NimNode): NimNode {.compileTime.} = result = newNimNode(nnkProcDef).und( name, emptyNode(), @@ -189,15 +189,15 @@ proc newProc*(name: PNimrodNode; params: varargs[PNimrodNode]; resultType: PNimr newNimNode(nnkStmtList)) result[3].add(params) -proc body*(procNode: PNimrodNode): PNimrodNode {.compileTime.} = +proc body*(procNode: NimNode): NimNode {.compileTime.} = assert procNode.kind == nnkProcDef and procNode[6].kind == nnkStmtList result = procNode[6] -proc iddefs*(a, b: string; c: PNimrodNode): PNimrodNode {.compileTime.} = +proc iddefs*(a, b: string; c: NimNode): NimNode {.compileTime.} = result = newNimNode(nnkIdentDefs).und(^a, ^b, c) -proc iddefs*(a: string; b: PNimrodNode): PNimrodNode {.compileTime.} = +proc iddefs*(a: string; b: NimNode): NimNode {.compileTime.} = result = newNimNode(nnkIdentDefs).und(^a, b, emptyNode()) -proc varTy*(a: PNimrodNode): PNimrodNode {.compileTime.} = +proc varTy*(a: NimNode): NimNode {.compileTime.} = result = newNimNode(nnkVarTy).und(a) macro forwardPacket*(typeName: expr, underlyingType: expr): stmt {.immediate.} = @@ -206,7 +206,7 @@ macro forwardPacket*(typeName: expr, underlyingType: expr): stmt {.immediate.} = streamID = ^"s" result = newNimNode(nnkStmtList).und( newProc( - (^("read"& $typeName.ident)).postfix("*"), + (^("read"& $typeName.ident)).postfix("*"), [ iddefs("s", "PBuffer", newNimNode(nnkNilLit)) ], typeName), newProc( @@ -218,7 +218,7 @@ macro forwardPacket*(typeName: expr, underlyingType: expr): stmt {.immediate.} = readBody = result[0][6] packBody = result[1][6] resName = ^"result" - + case underlyingType.kind of nnkBracketExpr: case $underlyingType[0].ident @@ -250,21 +250,21 @@ when isMainModule: A = 0'i8, B, C forwardPacket(SomeEnum, int8) - - + + defPacket(Foo, tuple[x: array[0..4, int8]]) var f = newFoo([4'i8, 3'i8, 2'i8, 1'i8, 0'i8]) var s2 = newStringStream("") f.pack(s2) assert s2.data == "\4\3\2\1\0" - + var s = newStringStream() s.flushImpl = proc(s: PStream) = var z = PStringStream(s) z.setPosition(0) z.data.setLen(0) - - + + s.setPosition(0) s.data.setLen(0) var o = B @@ -275,7 +275,7 @@ when isMainModule: o.pack(s) assert s.data == "\1\0\2" s.flush - + defPacket(Y, tuple[z: int8]) proc `$`(z: Y): string = result = "Y("& $z.z &")" defPacket(TestPkt, tuple[x: seq[Y]]) diff --git a/tests/manyloc/keineschweine/dependencies/genpacket/macro_dsl.nim b/tests/manyloc/keineschweine/dependencies/genpacket/macro_dsl.nim index c7b577b3d..d3a0c701d 100644 --- a/tests/manyloc/keineschweine/dependencies/genpacket/macro_dsl.nim +++ b/tests/manyloc/keineschweine/dependencies/genpacket/macro_dsl.nim @@ -1,42 +1,42 @@ import macros {.deadCodeElim: on.} #Inline macro.add() to allow for easier nesting -proc und*(a: PNimrodNode; b: PNimrodNode): PNimrodNode {.compileTime.} = +proc und*(a: NimNode; b: NimNode): NimNode {.compileTime.} = a.add(b) result = a -proc und*(a: PNimrodNode; b: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = +proc und*(a: NimNode; b: varargs[NimNode]): NimNode {.compileTime.} = a.add(b) result = a -proc `^`*(a: string): PNimrodNode {.compileTime.} = +proc `^`*(a: string): NimNode {.compileTime.} = ## new ident node result = newIdentNode(!a) -proc `[]`*(a, b: PNimrodNode): PNimrodNode {.compileTime.} = +proc `[]`*(a, b: NimNode): NimNode {.compileTime.} = ## new bracket expression: node[node] not to be confused with node[indx] result = newNimNode(nnkBracketExpr).und(a, b) -proc `:=`*(left, right: PNimrodNode): PNimrodNode {.compileTime.} = +proc `:=`*(left, right: NimNode): NimNode {.compileTime.} = ## new Asgn node: left = right result = newNimNode(nnkAsgn).und(left, right) -proc lit*(a: string): PNimrodNode {.compileTime.} = +proc lit*(a: string): NimNode {.compileTime.} = result = newStrLitNode(a) -proc lit*(a: int): PNimrodNode {.compileTime.} = +proc lit*(a: int): NimNode {.compileTime.} = result = newIntLitNode(a) -proc lit*(a: float): PNimrodNode {.compileTime.} = +proc lit*(a: float): NimNode {.compileTime.} = result = newFloatLitNode(a) -proc lit*(a: char): PNimrodNode {.compileTime.} = +proc lit*(a: char): NimNode {.compileTime.} = result = newNimNode(nnkCharLit) result.intval = a.ord -proc emptyNode*(): PNimrodNode {.compileTime.} = +proc emptyNode*(): NimNode {.compileTime.} = result = newNimNode(nnkEmpty) -proc dot*(left, right: PNimrodNode): PNimrodNode {.compileTime.} = +proc dot*(left, right: NimNode): NimNode {.compileTime.} = result = newNimNode(nnkDotExpr).und(left, right) -proc prefix*(a: string, b: PNimrodNode): PNimrodNode {.compileTime.} = +proc prefix*(a: string, b: NimNode): NimNode {.compileTime.} = result = newNimNode(nnkPrefix).und(newIdentNode(!a), b) -proc quoted2ident*(a: PNimrodNode): PNimrodNode {.compileTime.} = +proc quoted2ident*(a: NimNode): NimNode {.compileTime.} = if a.kind != nnkAccQuoted: return a var pname = "" diff --git a/tests/manyloc/named_argument_bug/tri_engine/gfx/color.nim b/tests/manyloc/named_argument_bug/tri_engine/gfx/color.nim index 8e47c1f2f..cdd5aaf03 100644 --- a/tests/manyloc/named_argument_bug/tri_engine/gfx/color.nim +++ b/tests/manyloc/named_argument_bug/tri_engine/gfx/color.nim @@ -5,7 +5,8 @@ import from strutils import formatFloat, TFloatFormat, - `%` + `%`, + ffDecimal from unsigned import `shr`, diff --git a/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/gl.nim b/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/gl.nim index e731969c1..22d36ef4d 100644 --- a/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/gl.nim +++ b/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/gl.nim @@ -54,7 +54,7 @@ else: glRealType* = cGLfloat proc setUniformV4*[T](loc: GLint, vecs: var openarray[TV4[T]]) = - glUniform4fv(loc, vecs.len.GLsizei, cast[PGLfloat](vecs[0].addr)) + glUniform4fv(loc, vecs.len.GLsizei, cast[ptr GLfloat](vecs[0].addr)) proc setUniformV4*[T](loc: GLint, vec: TV4[T]) = var vecs = [vec] diff --git a/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/primitive.nim b/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/primitive.nim index c67748967..8c26c04eb 100644 --- a/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/primitive.nim +++ b/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/primitive.nim @@ -16,7 +16,7 @@ type i* : GLuint size* : GLint stride* : GLsizei - offset* : PGLvoid + offset* : GLvoid TVertMode* = enum vmTriStrip = GLtriangleStrip, vmTriFan = GLtriangleFan @@ -44,7 +44,7 @@ proc newVertQuad*(min, minRight, maxLeft, max: TV2[TR]): seq[TVert] = proc newVert*(rect: rect.TRect): seq[TVert] = newVertQuad(rect.min, newV2(rect.max.x, rect.min.y), newV2(rect.min.x, rect.max.y), rect.max) -proc newVertAttrib(i: GLuint, size: GLint, stride: GLsizei, offset: PGLvoid): TVertAttrib = +proc newVertAttrib(i: GLuint, size: GLint, stride: GLsizei, offset: GLvoid): TVertAttrib = TVertAttrib(i: i, size: size, stride: stride, offset: offset) proc genBuf*[T](vboTarget, objUsage: GLenum, data: var openarray[T]): GLuint = @@ -90,7 +90,7 @@ proc disableVertAttribArrs*() = proc setVertAttribPointers*() = let vertSize {.global.} = TVert.sizeof.GLint ?glVertexAttribPointer(0, 2, glRealType, false, vertSize, nil) - ?glVertexAttribPointer(1, 2, glRealType, false, vertSize, cast[PGLvoid](TR.sizeof * 2)) + ?glVertexAttribPointer(1, 2, glRealType, false, vertSize, cast[GLvoid](TR.sizeof * 2)) proc updVerts*(o: PPrimitive, start, `end`: int, f: proc(i: int, vert: var TVert)) = assert start <= `end` @@ -105,7 +105,7 @@ proc updVerts*(o: PPrimitive, start, `end`: int, f: proc(i: int, vert: var TVert ?glBufferSubData(GLarrayBuffer, byteOffset.GLintptr, # Offset. Is this right? byteLen.GLsizeiptr, # Size. - cast[PGLvoid](cast[int](o.verts[0].addr) + byteOffset)) + cast[GLvoid](cast[int](o.verts[0].addr) + byteOffset)) proc updAllVerts(o: PPrimitive, f: proc(i: int, vert: var TVert)) = for i in 0 .. <o.verts.len: diff --git a/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/shader.nim b/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/shader.nim index 5972aa4fb..89bb76064 100644 --- a/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/shader.nim +++ b/tests/manyloc/named_argument_bug/tri_engine/gfx/gl/shader.nim @@ -25,7 +25,7 @@ proc setSrc*(shader: TShader, src: string) = ?glShaderSource(shader.id, 1, cast[cstringarray](s.addr), nil) proc newShader*(id: GL_handle): TShader = - if id != 0 and not (?glIsShader(id)).bool: + if id.int != 0 and not (?glIsShader(id)).bool: raise newException(E_GL, "Invalid shader ID: " & $id) result.id = id @@ -33,7 +33,7 @@ proc newShader*(id: GL_handle): TShader = proc shaderInfoLog*(o: TShader): string = var log {.global.}: array[0..1024, char] var logLen: GLsizei - ?glGetShaderInfoLog(o.id, log.len.GLsizei, logLen, cast[PGLchar](log.addr)) + ?glGetShaderInfoLog(o.id.GLuint, log.len.GLsizei, addr logLen, cast[cstring](log.addr)) cast[string](log.addr).substr(0, logLen) proc compile*(shader: TShader, path="") = @@ -67,7 +67,7 @@ proc attach*(o: TProgram, shader: TShader) = proc infoLog*(o: TProgram): string = var log {.global.}: array[0..1024, char] var logLen: GLsizei - ?glGetProgramInfoLog(o.id, log.len.GLsizei, logLen, cast[PGLchar](log.addr)) + ?glGetProgramInfoLog(o.id.GLuint, log.len.GLsizei, addr logLen, cast[cstring](log.addr)) cast[string](log.addr).substr(0, logLen) proc link*(o: TProgram) = @@ -86,11 +86,11 @@ proc validate*(o: TProgram) = proc newProgram*(shaders: seq[TShader]): TProgram = result.id = ?glCreateProgram() - if result.id == 0: + if result.id.int == 0: return for shader in shaders: - if shader.id == 0: + if shader.id.int == 0: return ?result.attach(shader) diff --git a/tests/misc/tinc.nim b/tests/misc/tinc.nim index 8038a2a01..b74f85591 100644 --- a/tests/misc/tinc.nim +++ b/tests/misc/tinc.nim @@ -1,7 +1,7 @@ discard """ file: "tinc.nim" line: 8 - errormsg: "for a \'var\' type a variable needs to be passed" + errormsg: "type mismatch: got (int)" """ var x = 0 diff --git a/tests/misc/tinout.nim b/tests/misc/tinout.nim index 034c496f5..4e5908428 100644 --- a/tests/misc/tinout.nim +++ b/tests/misc/tinout.nim @@ -1,7 +1,7 @@ discard """ file: "tinout.nim" line: 12 - errormsg: "for a \'var\' type a variable needs to be passed" + errormsg: "type mismatch: got (int literal(3))" """ # Test in out checking for parameters diff --git a/tests/notnil/tnotnil4.nim b/tests/notnil/tnotnil4.nim index 23968ee48..2fa888357 100644 --- a/tests/notnil/tnotnil4.nim +++ b/tests/notnil/tnotnil4.nim @@ -11,4 +11,10 @@ proc doit() = if x[0] != nil: check(x[0]) -doit() \ No newline at end of file +doit() + +# bug #2352 + +proc p(x: proc() {.noconv.} not nil) = discard +p(proc() {.noconv.} = discard) +# Error: cannot prove 'proc () {.noconv.} = discard ' is not nil diff --git a/tests/objvariant/tadrdisc.nim b/tests/objvariant/tadrdisc.nim index 0e0324562..1afe7d04f 100644 --- a/tests/objvariant/tadrdisc.nim +++ b/tests/objvariant/tadrdisc.nim @@ -1,7 +1,7 @@ discard """ file: "tadrdisc.nim" line: 20 - errormsg: "for a \'var\' type a variable needs to be passed" + errormsg: "type mismatch: got (TKind)" """ # Test that the address of a dicriminants cannot be taken @@ -12,12 +12,9 @@ type of ka: x, y: int of kb: a, b: string of kc: c, d: float - -proc setKind(k: var TKind) = - k = kc - -var a: TA -setKind(a.k) #ERROR_MSG for a 'var' type a variable needs to be passed - +proc setKind(k: var TKind) = + k = kc +var a: TA +setKind(a.k) diff --git a/tests/overload/tspec.nim b/tests/overload/tspec.nim new file mode 100644 index 000000000..685df503a --- /dev/null +++ b/tests/overload/tspec.nim @@ -0,0 +1,81 @@ +discard """ + output: '''not a var +not a var +a var +B +int +T +int16 +T +ref T +123 +2 +1 +@[123, 2, 1]''' +""" + +# Things that's even in the spec now! + +proc byvar(x: var int) = echo "a var" +proc byvar(x: int) = echo "not a var" +byvar(89) + +let letSym = 0 +var varSym = 13 + +byvar(letSym) +byvar(varSym) + +type + A = object of RootObj + B = object of A + C = object of B + +proc p(obj: A) = + echo "A" + +proc p(obj: B) = + echo "B" + +var c = C() +# not ambiguous, calls 'B', not 'A' since B is a subtype of A +# but not vice versa: +p(c) + +proc pp(obj: A, obj2: B) = echo "A B" +proc pp(obj: B, obj2: A) = echo "B A" + +# but this is ambiguous: +#pp(c, c) + +proc takesInt(x: int) = echo "int" +proc takesInt[T](x: T) = echo "T" +proc takesInt(x: int16) = echo "int16" + +takesInt(4) # "int" +var x: int32 +takesInt(x) # "T" +var y: int16 +takesInt(y) # "int16" +var z: range[0..4] = 0 +takesInt(z) # "T" + +proc gen[T](x: ref ref T) = echo "ref ref T" +proc gen[T](x: ref T) = echo "ref T" +proc gen[T](x: T) = echo "T" + +var ri: ref int +gen(ri) # "ref T" + + +template rem(x: expr) = discard +#proc rem[T](x: T) = discard + +rem unresolvedExpression(undeclaredIdentifier) + + +proc takeV[T](a: varargs[T]) = + for x in a: echo x + +takeV([123, 2, 1]) # takeV's T is "int", not "array of int" +echo(@[123, 2, 1]) diff --git a/tests/parallel/tarray_of_channels.nim b/tests/parallel/tarray_of_channels.nim new file mode 100644 index 000000000..11b523401 --- /dev/null +++ b/tests/parallel/tarray_of_channels.nim @@ -0,0 +1,26 @@ +# bug #2257 +import threadpool + +type StringChannel = TChannel[string] +var channels: array[1..3, StringChannel] + +type + MyObject[T] = object + x: T + +var global: MyObject[string] +var globalB: MyObject[float] + +proc consumer(ix : int) {.thread.} = + echo channels[ix].recv() ###### not GC-safe: 'channels' + echo globalB + +proc main = + for ix in 1..3: channels[ix].open() + for ix in 1..3: spawn consumer(ix) + for ix in 1..3: channels[ix].send("test") + sync() + for ix in 1..3: channels[ix].close() + +when isMainModule: + main() diff --git a/tests/parallel/tdont_be_stupid.nim b/tests/parallel/tdont_be_stupid.nim new file mode 100644 index 000000000..a7e82466a --- /dev/null +++ b/tests/parallel/tdont_be_stupid.nim @@ -0,0 +1,15 @@ + +import threadpool, os + +proc single(time: int) = + sleep time + echo time + +proc sleepsort(nums: openArray[int]) = + parallel: + var i = 0 + while i <= len(nums) + -1: + spawn single(nums[i]) + i += 1 + +sleepsort([50,3,40,25]) diff --git a/tests/parallel/tgc_unsafe.nim b/tests/parallel/tgc_unsafe.nim new file mode 100644 index 000000000..6548bbec8 --- /dev/null +++ b/tests/parallel/tgc_unsafe.nim @@ -0,0 +1,32 @@ +discard """ + errormsg: "'consumer' is not GC-safe" + line: 19 +""" + +# bug #2257 +import threadpool + +type StringChannel = TChannel[string] +var channels: array[1..3, StringChannel] + +type + MyObject[T] = object + x: T + +var global: MyObject[string] +var globalB: MyObject[float] + +proc consumer(ix : int) {.thread.} = + echo channels[ix].recv() ###### not GC-safe: 'channels' + echo global + echo globalB + +proc main = + for ix in 1..3: channels[ix].open() + for ix in 1..3: spawn consumer(ix) + for ix in 1..3: channels[ix].send("test") + sync() + for ix in 1..3: channels[ix].close() + +when isMainModule: + main() diff --git a/tests/showoff/tdrdobbs_examples.nim b/tests/showoff/tdrdobbs_examples.nim index 13a685950..78f711325 100644 --- a/tests/showoff/tdrdobbs_examples.nim +++ b/tests/showoff/tdrdobbs_examples.nim @@ -13,7 +13,7 @@ var g = 70 ++g g ++ 7 g.`++`(10, 20) -echo g +echo g #let lv = stdin.readline @@ -56,7 +56,7 @@ type fkLit, ## element is a literal like 0.1 fkAdd, ## element is an addition operation fkMul, ## element is a multiplication operation - fkExp ## element is an exponentiation operation + fkExp ## element is an exponentiation operation type Formula = ref object @@ -78,16 +78,16 @@ proc evaluate(n: Formula, varToVal: proc (name: string): float): float = echo evaluate(Formula(kind: fkLit, value: 0.4), nil) proc isPolyTerm(n: Formula): bool = - n.kind == fkMul and n.left.kind == fkLit and (let e = n.right; + n.kind == fkMul and n.left.kind == fkLit and (let e = n.right; e.kind == fkExp and e.left.kind == fkVar and e.right.kind == fkLit) proc isPolynomial(n: Formula): bool = - isPolyTerm(n) or + isPolyTerm(n) or (n.kind == fkAdd and isPolynomial(n.left) and isPolynomial(n.right)) let myFormula = Formula(kind: fkMul, left: Formula(kind: fkLit, value: 2.0), - right: Formula(kind: fkExp, + right: Formula(kind: fkExp, left: Formula(kind: fkVar, name: "x"), right: Formula(kind: fkLit, value: 5.0))) @@ -104,7 +104,7 @@ proc pat2kind(pattern: string): FormulaKind = import macros -proc matchAgainst(n, pattern: PNimrodNode): PNimrodNode {.compileTime.} = +proc matchAgainst(n, pattern: NimNode): NimNode {.compileTime.} = template `@`(current, field: expr): expr = newDotExpr(current, newIdentNode(astToStr(field))) diff --git a/tests/template/t_otemplates.nim b/tests/template/t_otemplates.nim index 1a9075d20..db535d818 100644 --- a/tests/template/t_otemplates.nim +++ b/tests/template/t_otemplates.nim @@ -18,7 +18,7 @@ const identChars = {'a'..'z', 'A'..'Z', '0'..'9', '_'} # Procedure Declarations -proc parse_template(node: PNimrodNode, value: string) {.compiletime.} +proc parse_template(node: NimNode, value: string) {.compiletime.} # Procedure Definitions @@ -166,7 +166,7 @@ iterator parse_compound_statements(value, identifier: string, index: int): strin get_next_ident(["try", "$except", "$finally"]) -proc parse_complex_stmt(value, identifier: string, index: var int): PNimrodNode {.compiletime.} = +proc parse_complex_stmt(value, identifier: string, index: var int): NimNode {.compiletime.} = ## Parses if/when/try /elif /else /except /finally statements # Build up complex statement string @@ -218,7 +218,7 @@ proc parse_complex_stmt(value, identifier: string, index: var int): PNimrodNode inc(resultIndex) -proc parse_simple_statement(value: string, index: var int): PNimrodNode {.compiletime.} = +proc parse_simple_statement(value: string, index: var int): NimNode {.compiletime.} = ## Parses for/while # Detect indentation @@ -252,7 +252,7 @@ proc parse_simple_statement(value: string, index: var int): PNimrodNode {.compil inc(index, value.parse_thru_eol(index)) -proc parse_until_symbol(node: PNimrodNode, value: string, index: var int): bool {.compiletime.} = +proc parse_until_symbol(node: NimNode, value: string, index: var int): bool {.compiletime.} = ## Parses a string until a $ symbol is encountered, if ## two $$'s are encountered in a row, a split will happen ## removing one of the $'s from the resulting output @@ -311,7 +311,7 @@ proc parse_until_symbol(node: PNimrodNode, value: string, index: var int): bool node.insert insertionPoint, newCall("add", ident("result"), newStrLitNode(splitValue)) -proc parse_template(node: PNimrodNode, value: string) = +proc parse_template(node: NimNode, value: string) = ## Parses through entire template, outputing valid ## Nim code into the input `node` AST. var index = 0 diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index c293be7e8..cb3649a38 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -215,7 +215,7 @@ proc manyLoc(r: var TResults, cat: Category, options: string) = for kind, dir in os.walkDir("tests/manyloc"): if kind == pcDir: let mainfile = findMainFile(dir) - if mainfile != ".nim": + if mainfile != "": testNoSpec r, makeTest(mainfile, options, cat) proc compileExample(r: var TResults, pattern, options: string, cat: Category) = diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index 7cf902704..4c1173fe3 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -146,7 +146,6 @@ proc codegenCheck(test: TTest, check: string, given: var TSpec) = try: let (path, name, ext2) = test.name.splitFile let genFile = generatedFile(path, name, test.target) - echo genFile let contents = readFile(genFile).string if check[0] == '\\': # little hack to get 'match' support: diff --git a/tests/usingstmt/tusingstatement.nim b/tests/usingstmt/tusingstatement.nim index b58478d74..0d76b2423 100644 --- a/tests/usingstmt/tusingstatement.nim +++ b/tests/usingstmt/tusingstatement.nim @@ -3,13 +3,13 @@ discard """ output: "Using test.Closing test." """ -import +import macros # This macro mimics the using statement from C# # # It's kept only as a test for the macro system -# Nim's destructors offer a mechanism for automatic +# Nim's destructors offer a mechanism for automatic # disposal of resources. # macro autoClose(e: expr): stmt {.immediate.} = @@ -20,19 +20,19 @@ macro autoClose(e: expr): stmt {.immediate.} = var args = e var body = e[2] - - var - variables : seq[PNimrodNode] - closingCalls : seq[PNimrodNode] + + var + variables : seq[NimNode] + closingCalls : seq[NimNode] newSeq(variables, 0) newSeq(closingCalls, 0) - + for i in countup(1, args.len-2): if args[i].kind == nnkExprEqExpr: var varName = args[i][0] var varValue = args[i][1] - + var varAssignment = newNimNode(nnkIdentDefs) varAssignment.add(varName) varAssignment.add(newNimNode(nnkEmpty)) # empty means no type @@ -43,7 +43,7 @@ macro autoClose(e: expr): stmt {.immediate.} = else: error "Using statement: Unexpected expression. Got " & $args[i].kind & " instead of assignment." - + var varSection = newNimNode(nnkVarSection) varSection.add(variables) @@ -67,10 +67,10 @@ macro autoClose(e: expr): stmt {.immediate.} = targetAst[0][1][0] = varSection targetAst[0][1][1][0] = body targetAst[0][1][1][1][0] = finallyBlock - + result = targetAst -type +type TResource* = object field*: string diff --git a/tests/vm/tstringnil.nim b/tests/vm/tstringnil.nim index 61ce60ee5..bb546b698 100644 --- a/tests/vm/tstringnil.nim +++ b/tests/vm/tstringnil.nim @@ -8,9 +8,9 @@ type suiteDesc: string testName: string testDesc: string - testBlock: PNimrodNode + testBlock: NimNode -proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: PNimrodNode): tuple[tests: seq[SuiteTest]] {.compileTime.} = +proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: NimNode): tuple[tests: seq[SuiteTest]] {.compileTime.} = var tests:seq[SuiteTest] = @[] @@ -40,7 +40,7 @@ proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: PNimrodNode): tuple[tes discard return (tests: tests) - + macro suite(suiteName, suiteDesc: expr, suiteBloc: stmt): stmt {.immediate.} = let contents = buildSuiteContents(suiteName, suiteDesc, suiteBloc) |