mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
Merge branch 'devel' into faster-nimsuggest
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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, "[")
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 || \
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
22
tests/template/tmixin_in_proc.nim
Normal file
22
tests/template/tmixin_in_proc.nim
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user