diff options
-rw-r--r-- | compiler/ccgtrav.nim | 3 | ||||
-rw-r--r-- | compiler/renderer.nim | 6 | ||||
-rw-r--r-- | compiler/semexprs.nim | 4 | ||||
-rw-r--r-- | compiler/semtempl.nim | 8 | ||||
-rw-r--r-- | doc/manual/types.txt | 2 | ||||
-rw-r--r-- | lib/nimbase.h | 2 | ||||
-rw-r--r-- | lib/pure/collections/tables.nim | 76 | ||||
-rw-r--r-- | lib/pure/encodings.nim | 13 | ||||
-rw-r--r-- | lib/pure/httpclient.nim | 4 | ||||
-rw-r--r-- | lib/pure/terminal.nim | 2 | ||||
-rw-r--r-- | readme.md | 2 | ||||
-rw-r--r-- | tests/stdlib/tnre.nim | 22 | ||||
-rw-r--r-- | tests/template/tgensymregression.nim | 26 | ||||
-rw-r--r-- | tests/template/tmixin_in_proc.nim | 22 |
14 files changed, 162 insertions, 30 deletions
diff --git a/compiler/ccgtrav.nim b/compiler/ccgtrav.nim index 457093c61..982f88cbd 100644 --- a/compiler/ccgtrav.nim +++ b/compiler/ccgtrav.nim @@ -32,6 +32,9 @@ proc genTraverseProc(c: var TTraversalClosure, accessor: Rope, n: PNode; if (n.sons[0].kind != nkSym): internalError(n.info, "genTraverseProc") var p = c.p let disc = n.sons[0].sym + if disc.loc.r == nil: fillObjectFields(c.p.module, typ) + if disc.loc.t == nil: + internalError(n.info, "genTraverseProc()") lineF(p, cpsStmts, "switch ($1.$2) {$n", [accessor, disc.loc.r]) for i in countup(1, sonsLen(n) - 1): let branch = n.sons[i] diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 5ce8414d6..badcaea66 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -851,7 +851,11 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = put(g, tkRStrLit, '\"' & replace(n[1].strVal, "\"", "\"\"") & '\"') else: gsub(g, n.sons[1]) - of nkHiddenStdConv, nkHiddenSubConv, nkHiddenCallConv: gsub(g, n.sons[1]) + of nkHiddenStdConv, nkHiddenSubConv, nkHiddenCallConv: + if n.len >= 2: + gsub(g, n.sons[1]) + else: + put(g, tkSymbol, "(wrong conv)") of nkCast: put(g, tkCast, "cast") put(g, tkBracketLe, "[") diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index ba60442d6..a419cd000 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2324,12 +2324,16 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = of nkIfExpr, nkIfStmt: result = semIf(c, n) of nkHiddenStdConv, nkHiddenSubConv, nkConv, nkHiddenCallConv: checkSonsLen(n, 2) + considerGenSyms(c, n) of nkStringToCString, nkCStringToString, nkObjDownConv, nkObjUpConv: checkSonsLen(n, 1) + considerGenSyms(c, n) of nkChckRangeF, nkChckRange64, nkChckRange: checkSonsLen(n, 3) + considerGenSyms(c, n) of nkCheckedFieldExpr: checkMinSonsLen(n, 2) + considerGenSyms(c, n) of nkTableConstr: result = semTableConstr(c, n) of nkClosedSymChoice, nkOpenSymChoice: diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index f809b6a50..5ac2e678a 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -144,10 +144,8 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode proc openScope(c: var TemplCtx) = openScope(c.c) - inc c.scopeN proc closeScope(c: var TemplCtx) = - dec c.scopeN closeScope(c.c) proc semTemplBodyScope(c: var TemplCtx, n: PNode): PNode = @@ -172,7 +170,6 @@ proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym = result = newSym(kind, considerQuotedIdent(n), c.owner, n.info) incl(result.flags, sfGenSym) incl(result.flags, sfShadowed) - #if c.scopeN == 0: incl(result.flags, sfFromGeneric) proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) = # locals default to 'gensym': @@ -275,10 +272,12 @@ proc semRoutineInTemplBody(c: var TemplCtx, n: PNode, k: TSymKind): PNode = for i in patternPos..miscPos: n.sons[i] = semTemplBody(c, n.sons[i]) # open scope for locals + inc c.scopeN openScope(c) n.sons[bodyPos] = semTemplBody(c, n.sons[bodyPos]) # close scope for locals closeScope(c) + dec c.scopeN # close scope for parameters closeScope(c) @@ -346,7 +345,8 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = of nkBindStmt: result = semBindStmt(c.c, n, c.toBind) of nkMixinStmt: - result = semMixinStmt(c.c, n, c.toMixin) + if c.scopeN > 0: result = semTemplBodySons(c, n) + else: result = semMixinStmt(c.c, n, c.toMixin) of nkEmpty, nkSym..nkNilLit: discard of nkIfStmt: diff --git a/doc/manual/types.txt b/doc/manual/types.txt index c81bc042b..aed09c951 100644 --- a/doc/manual/types.txt +++ b/doc/manual/types.txt @@ -143,7 +143,7 @@ affected by this rule: ``-``, ``+``, ``*``, ``min``, ``max``, ``succ``, ``pred``, ``mod``, ``div``, ``%%``, ``and`` (bitwise ``and``). Bitwise ``and`` only produces a ``range`` if one of its operands is a -constant *x* so that (x+1) is a number of two. +constant *x* so that (x+1) is a power of two. (Bitwise ``and`` is then a ``%%`` operation.) This means that the following code is accepted: diff --git a/lib/nimbase.h b/lib/nimbase.h index d6763f8ff..df715188f 100644 --- a/lib/nimbase.h +++ b/lib/nimbase.h @@ -96,7 +96,7 @@ __clang__ NIM_THREADVAR declaration based on http://stackoverflow.com/questions/18298280/how-to-declare-a-variable-as-thread-local-portably */ -#if __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__ +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__ # define NIM_THREADVAR _Thread_local #elif defined _WIN32 && ( \ defined _MSC_VER || \ diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 00a81b8d5..b6c00966f 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -618,11 +618,19 @@ proc `$`*[A, B](t: OrderedTable[A, B]): string = proc `==`*[A, B](s, t: OrderedTable[A, B]): bool = ## The `==` operator for ordered hash tables. Returns true iff both the ## content and the order are equal. - if s.counter == t.counter: - forAllOrderedPairs: - if s.data[h] != t.data[h]: return false - result = true - else: result = false + if s.counter != t.counter: + return false + var ht = t.first + var hs = s.first + while ht >= 0 and hs >= 0: + var nxtt = t.data[ht].next + var nxts = s.data[hs].next + if isFilled(t.data[ht].hcode) and isFilled(s.data[hs].hcode): + if (s.data[hs].key != t.data[ht].key) and (s.data[hs].val != t.data[ht].val): + return false + ht = nxtt + hs = nxts + return true proc sort*[A, B](t: var OrderedTable[A, B], cmp: proc (x,y: (A, B)): int) = @@ -754,7 +762,7 @@ proc newOrderedTable*[A, B](initialSize=64): OrderedTableRef[A, B] = proc newOrderedTable*[A, B](pairs: openArray[(A, B)]): OrderedTableRef[A, B] = ## creates a new ordered hash table that contains the given `pairs`. result = newOrderedTable[A, B](rightSize(pairs.len)) - for key, val in items(pairs): result[key] = val + for key, val in items(pairs): result.add(key, val) proc `$`*[A, B](t: OrderedTableRef[A, B]): string = ## The `$` operator for ordered hash tables. @@ -1233,11 +1241,51 @@ when isMainModule: t.inc(testKey,3) doAssert 3 == t.getOrDefault(testKey) - # Clear tests - var clearTable = newTable[int, string]() - clearTable[42] = "asd" - clearTable[123123] = "piuyqwb " - doAssert clearTable[42] == "asd" - clearTable.clear() - doAssert(not clearTable.hasKey(123123)) - doAssert clearTable.getOrDefault(42) == nil + block: + # Clear tests + var clearTable = newTable[int, string]() + clearTable[42] = "asd" + clearTable[123123] = "piuyqwb " + doAssert clearTable[42] == "asd" + clearTable.clear() + doAssert(not clearTable.hasKey(123123)) + doAssert clearTable.getOrDefault(42) == nil + + block: #5482 + var a = [("wrong?","foo"), ("wrong?", "foo2")].newOrderedTable() + var b = newOrderedTable[string, string](initialSize=2) + b.add("wrong?", "foo") + b.add("wrong?", "foo2") + assert a == b + + block: #5482 + var a = {"wrong?": "foo", "wrong?": "foo2"}.newOrderedTable() + var b = newOrderedTable[string, string](initialSize=2) + b.add("wrong?", "foo") + b.add("wrong?", "foo2") + assert a == b + + block: #5487 + var a = {"wrong?": "foo", "wrong?": "foo2"}.newOrderedTable() + var b = newOrderedTable[string, string]() # notice, default size! + b.add("wrong?", "foo") + b.add("wrong?", "foo2") + assert a == b + + block: #5487 + var a = [("wrong?","foo"), ("wrong?", "foo2")].newOrderedTable() + var b = newOrderedTable[string, string]() # notice, default size! + b.add("wrong?", "foo") + b.add("wrong?", "foo2") + assert a == b + + block: + var a = {"wrong?": "foo", "wrong?": "foo2"}.newOrderedTable() + var b = [("wrong?","foo"), ("wrong?", "foo2")].newOrderedTable() + var c = newOrderedTable[string, string]() # notice, default size! + c.add("wrong?", "foo") + c.add("wrong?", "foo2") + assert a == b + assert a == c + + diff --git a/lib/pure/encodings.nim b/lib/pure/encodings.nim index f89786c1c..5840d443d 100644 --- a/lib/pure/encodings.nim +++ b/lib/pure/encodings.nim @@ -277,16 +277,21 @@ else: var errno {.importc, header: "<errno.h>".}: cint + when defined(freebsd) or defined(netbsd): + {.pragma: importIconv, cdecl, header: "<iconv.h>".} + else: + {.pragma: importIconv, cdecl, dynlib: iconvDll.} + proc iconvOpen(tocode, fromcode: cstring): EncodingConverter {. - importc: "iconv_open", cdecl, dynlib: iconvDll.} + importc: "iconv_open", importIconv.} proc iconvClose(c: EncodingConverter) {. - importc: "iconv_close", cdecl, dynlib: iconvDll.} + importc: "iconv_close", importIconv.} proc iconv(c: EncodingConverter, inbuf: var cstring, inbytesLeft: var int, outbuf: var cstring, outbytesLeft: var int): int {. - importc: "iconv", cdecl, dynlib: iconvDll.} + importc: "iconv", importIconv.} proc iconv(c: EncodingConverter, inbuf: pointer, inbytesLeft: pointer, outbuf: var cstring, outbytesLeft: var int): int {. - importc: "iconv", cdecl, dynlib: iconvDll.} + importc: "iconv", importIconv.} proc getCurrentEncoding*(): string = ## retrieves the current encoding. On Unix, always "UTF-8" is returned. diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 662e75471..7f666fb35 100644 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -719,9 +719,9 @@ proc generateHeaders(requestUrl: Uri, httpMethod: string, if requestUrl.query.len > 0: result.add("?" & requestUrl.query) else: - # Remove the 'http://' from the URL for CONNECT requests. + # Remove the 'http://' from the URL for CONNECT requests for TLS connections. var modifiedUrl = requestUrl - modifiedUrl.scheme = "" + if requestUrl.scheme == "https": modifiedUrl.scheme = "" result.add($modifiedUrl) # HTTP/1.1\c\l diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim index 31278eabf..87c663c3d 100644 --- a/lib/pure/terminal.nim +++ b/lib/pure/terminal.nim @@ -589,7 +589,7 @@ macro styledWriteLine*(f: File, m: varargs[expr]): stmt = ## .. code-block:: nim ## ## proc error(msg: string) = - ## styleWriteLine(stderr, fgRed, "Error: ", resetStyle, msg) + ## styledWriteLine(stderr, fgRed, "Error: ", resetStyle, msg) ## let m = callsite() var reset = false diff --git a/readme.md b/readme.md index 865724b71..34208eb5e 100644 --- a/readme.md +++ b/readme.md @@ -43,7 +43,7 @@ Next, to build from source you will need: ``Visual C++`` or ``Intel C++``. It is recommended to use ``gcc`` 3.x or later. * Either ``git`` or ``wget`` to download the needed source repositories. - * The ``build-essentials`` package when using ``gcc`` on Ubuntu (and likely + * The ``build-essential`` package when using ``gcc`` on Ubuntu (and likely other distros as well). Then, if you are on a \*nix system or Windows, the following steps should compile diff --git a/tests/stdlib/tnre.nim b/tests/stdlib/tnre.nim index 85792b81e..030319ebf 100644 --- a/tests/stdlib/tnre.nim +++ b/tests/stdlib/tnre.nim @@ -1,3 +1,25 @@ +discard """ +# Since the tests for nre are all bundled together we treat failure in one test as an nre failure +# When running 'tests/testament/tester' a failed check() in the test suite will cause the exit +# codes to differ and be reported as a failure + + output: + '''[Suite] Test NRE initialization + +[Suite] captures + +[Suite] find + +[Suite] string splitting + +[Suite] match + +[Suite] replace + +[Suite] escape strings + +[Suite] Misc tests''' +""" import nre import nre.init import nre.captures diff --git a/tests/template/tgensymregression.nim b/tests/template/tgensymregression.nim index e758e0d9a..0fadbde41 100644 --- a/tests/template/tgensymregression.nim +++ b/tests/template/tgensymregression.nim @@ -3,7 +3,8 @@ discard """ [0.0, 0.0, 0.0, 0.0] -5050''' +5050 +123''' """ template mathPerComponent(op: untyped): untyped = @@ -47,3 +48,26 @@ proc main2() = echo s main2() + +# bug #5467 +import macros + +converter int2string(x: int): string = $x + +template wrap(body: typed): untyped = + body + +macro makeProc(): typed = + # Make a template tree + result = (quote do: + proc someProc* = + wrap do: + let x = 123 + # Implicit conversion here + let s: string = x + echo s + ) + +makeProc() + +someProc() diff --git a/tests/template/tmixin_in_proc.nim b/tests/template/tmixin_in_proc.nim new file mode 100644 index 000000000..fede9290b --- /dev/null +++ b/tests/template/tmixin_in_proc.nim @@ -0,0 +1,22 @@ +discard """ + output: '''monkey''' +""" +# bug #5478 +template creature*(name: untyped) = + type + name*[T] = object + color: T + + proc `init name`*[T](c: T): name[T] = + mixin transform + transform() + +creature(Lion) + +type Monkey* = object +proc transform*() = + echo "monkey" + +var + m: Monkey + y = initLion(m) #this one failed to compile |