mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-16 16:14:20 +00:00
fixes #127
This commit is contained in:
@@ -20,7 +20,8 @@ proc hasNoInit(call: PNode): bool {.inline.} =
|
||||
|
||||
proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc, pl: PRope) =
|
||||
var pl = pl
|
||||
var typ = ri.sons[0].typ # getUniqueType() is too expensive here!
|
||||
# getUniqueType() is too expensive here:
|
||||
var typ = skipTypes(ri.sons[0].typ, abstractInst)
|
||||
if typ.sons[0] != nil:
|
||||
if isInvalidReturnType(typ.sons[0]):
|
||||
if sonsLen(ri) > 1: app(pl, ", ")
|
||||
@@ -124,7 +125,8 @@ proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||
# this is a hotspot in the compiler
|
||||
initLocExpr(p, ri.sons[0], op)
|
||||
var pl = con(op.r, "(")
|
||||
var typ = ri.sons[0].typ # getUniqueType() is too expensive here!
|
||||
# getUniqueType() is too expensive here:
|
||||
var typ = skipTypes(ri.sons[0].typ, abstractInst)
|
||||
assert(typ.kind == tyProc)
|
||||
var length = sonsLen(ri)
|
||||
for i in countup(1, length - 1):
|
||||
@@ -150,7 +152,8 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||
var op: TLoc
|
||||
initLocExpr(p, ri.sons[0], op)
|
||||
var pl: PRope
|
||||
var typ = ri.sons[0].typ
|
||||
|
||||
var typ = skipTypes(ri.sons[0].typ, abstractInst)
|
||||
assert(typ.kind == tyProc)
|
||||
var length = sonsLen(ri)
|
||||
for i in countup(1, length - 1):
|
||||
@@ -201,7 +204,8 @@ proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||
var op, a: TLoc
|
||||
initLocExpr(p, ri.sons[0], op)
|
||||
var pl: PRope = nil
|
||||
var typ = ri.sons[0].typ # getUniqueType() is too expensive here!
|
||||
# getUniqueType() is too expensive here:
|
||||
var typ = skipTypes(ri.sons[0].typ, abstractInst)
|
||||
assert(typ.kind == tyProc)
|
||||
var length = sonsLen(ri)
|
||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||
@@ -228,7 +232,8 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||
var op, a: TLoc
|
||||
initLocExpr(p, ri.sons[0], op)
|
||||
var pl = toRope"["
|
||||
var typ = ri.sons[0].typ # getUniqueType() is too expensive here!
|
||||
# getUniqueType() is too expensive here:
|
||||
var typ = skipTypes(ri.sons[0].typ, abstractInst)
|
||||
assert(typ.kind == tyProc)
|
||||
var length = sonsLen(ri)
|
||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
discard """
|
||||
output: "0false"
|
||||
output: "0false12"
|
||||
"""
|
||||
|
||||
# Test multiple generic instantiation of generic proc vars:
|
||||
@@ -17,3 +17,20 @@ proc threadProcWrapper[TMsg]() =
|
||||
threadProcWrapper[int]()
|
||||
threadProcWrapper[bool]()
|
||||
|
||||
type
|
||||
TFilterProc[T,D] = proc (item: T, env:D): bool
|
||||
|
||||
proc filter[T,D](data: seq[T], env:D, pred: TFilterProc[T,D]): seq[T] =
|
||||
result = @[]
|
||||
for e in data:
|
||||
if pred(e, env): result.add(e)
|
||||
|
||||
proc predTest(item: int, value: int): Bool =
|
||||
return item <= value
|
||||
|
||||
proc test(data: seq[int], value: int): seq[int] =
|
||||
return filter(data, value, predTest)
|
||||
|
||||
for x in items(test(@[1,2,3], 2)):
|
||||
stdout.write(x)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user