diff options
-rw-r--r-- | compiler/semcall.nim | 13 | ||||
-rw-r--r-- | compiler/semstmts.nim | 8 | ||||
-rw-r--r-- | doc/manual/threads.txt | 2 | ||||
-rw-r--r-- | lib/pure/net.nim | 2 | ||||
-rw-r--r-- | tests/converter/tgenericconverter2.nim | 49 |
5 files changed, 63 insertions, 11 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 8445b24d9..a0d0db3ad 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -255,12 +255,13 @@ proc resolveOverloads(c: PContext, n, orig: PNode, proc instGenericConvertersArg*(c: PContext, a: PNode, x: TCandidate) = - if a.kind == nkHiddenCallConv and a.sons[0].kind == nkSym and - isGenericRoutine(a.sons[0].sym): - let finalCallee = generateInstance(c, a.sons[0].sym, x.bindings, a.info) - a.sons[0].sym = finalCallee - a.sons[0].typ = finalCallee.typ - #a.typ = finalCallee.typ.sons[0] + if a.kind == nkHiddenCallConv and a.sons[0].kind == nkSym: + let s = a.sons[0].sym + if s.ast != nil and s.ast[genericParamsPos].kind != nkEmpty: + let finalCallee = generateInstance(c, s, x.bindings, a.info) + a.sons[0].sym = finalCallee + a.sons[0].typ = finalCallee.typ + #a.typ = finalCallee.typ.sons[0] proc instGenericConvertersSons*(c: PContext, n: PNode, x: TCandidate) = assert n.kind in nkCallKinds diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index fdf147a2e..edcf079fa 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1101,6 +1101,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, if n[namePos].kind == nkEmpty: s = newSym(kind, idAnon, getCurrOwner(), n.info) + incl(s.flags, sfUsed) isAnon = true else: s = semIdentDef(c, n.sons[0], kind) @@ -1153,9 +1154,10 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, s.typ.flags.incl(tfIterator) var proto = searchForProc(c, oldScope, s) - if proto == nil: - if s.kind == skIterator and s.typ.callConv == ccClosure: - discard + if proto == nil or isAnon: + if s.kind == skIterator: + if s.typ.callConv != ccClosure: + s.typ.callConv = if isAnon: ccClosure else: ccInline else: s.typ.callConv = lastOptionEntry(c).defaultCC # add it here, so that recursive procs are possible: diff --git a/doc/manual/threads.txt b/doc/manual/threads.txt index f2b79a34f..a1895362c 100644 --- a/doc/manual/threads.txt +++ b/doc/manual/threads.txt @@ -130,7 +130,7 @@ that ``spawn`` takes is restricted: programmer to be careful. * ``ref`` parameters are deeply copied which is a subtle semantic change and can cause performance problems but ensures memory safety. This deep copy - is performed via ``system.deepCopy`` and so can be overriden. + is performed via ``system.deepCopy`` and so can be overridden. * For *safe* data exchange between ``f`` and the caller a global ``TChannel`` needs to be used. However, since spawn can return a result, often no further communication is required. diff --git a/lib/pure/net.nim b/lib/pure/net.nim index 1cfaf029f..c3a65fef1 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -829,7 +829,7 @@ proc readLine*(socket: Socket, line: var TaintedString, timeout = -1, template addNLIfEmpty(): stmt = if line.len == 0: - line.add("\c\L") + line.string.add("\c\L") template raiseSockError(): stmt {.dirty, immediate.} = let lastError = getSocketError(socket) diff --git a/tests/converter/tgenericconverter2.nim b/tests/converter/tgenericconverter2.nim new file mode 100644 index 000000000..ae064d852 --- /dev/null +++ b/tests/converter/tgenericconverter2.nim @@ -0,0 +1,49 @@ +# bug #3799 + +import macros + +const nmax = 500 + +type + Complex*[T] = object + re*: T + im*: T + +converter toComplex*[T](x: tuple[re, im: T]): Complex[T] = + result.re = x.re + result.im = x.im + + +proc julia*[T](z0, c: Complex[T], er2: T, nmax: int): int = + result = 0 + var z = z0 + var sre = z0.re * z0.re + var sim = z0.im * z0.im + while (result < nmax) and (sre + sim < er2): + z.im = z.re * z.im + z.im = z.im + z.im + z.im = z.im + c.im + z.re = sre - sim + c.re + sre = z.re * z.re + sim = z.im * z.im + inc result + +template dendriteFractal*[T](z0: Complex[T], er2: T, nmax: int): int = + julia(z0, (T(0.0), T(1.0)), er2, nmax) + +iterator stepIt[T](start, step: T, iterations: int): T = + for i in 0 .. iterations: + yield start + T(i) * step + + +let c = (0.36237, 0.32) +for y in stepIt(2.0, -0.0375, 107): + var row = "" + for x in stepIt(-2.0, 0.025, 160): + #let n = julia((x, y), c, 4.0, nmax) ### this works + let n = dendriteFractal((x, y), 4.0, nmax) + if n < nmax: + row.add($(n mod 10)) + else: + row.add(' ') + echo row |