fix some trivial errors in the test suite and some more regressions caused by tyTypeDesc[tyNone]
This commit is contained in:
parent
4d3846e26b
commit
cda92048ba
10 changed files with 68 additions and 37 deletions
|
|
@ -669,7 +669,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
of tyTypeDesc:
|
of tyTypeDesc:
|
||||||
if tfUnresolved notin paramType.flags:
|
if tfUnresolved notin paramType.flags:
|
||||||
# naked typedescs are not bindOnce types
|
# naked typedescs are not bindOnce types
|
||||||
if paramType.sonsLen == 0 and paramTypId != nil and
|
if paramType.base.kind == tyNone and paramTypId != nil and
|
||||||
paramTypId.id == typedescId.id: paramTypId = nil
|
paramTypId.id == typedescId.id: paramTypId = nil
|
||||||
result = addImplicitGeneric(c.newTypeWithSons(tyTypeDesc, paramType.sons))
|
result = addImplicitGeneric(c.newTypeWithSons(tyTypeDesc, paramType.sons))
|
||||||
|
|
||||||
|
|
@ -1011,7 +1011,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
of mOrdinal: result = semOrdinal(c, n, prev)
|
of mOrdinal: result = semOrdinal(c, n, prev)
|
||||||
of mSeq: result = semContainer(c, n, tySequence, "seq", prev)
|
of mSeq: result = semContainer(c, n, tySequence, "seq", prev)
|
||||||
of mVarargs: result = semVarargs(c, n, prev)
|
of mVarargs: result = semVarargs(c, n, prev)
|
||||||
of mExpr, mTypeDesc:
|
of mTypeDesc: result = makeTypeDesc(c, semTypeNode(c, n[1], nil))
|
||||||
|
of mExpr:
|
||||||
result = semTypeNode(c, n.sons[0], nil)
|
result = semTypeNode(c, n.sons[0], nil)
|
||||||
if result != nil:
|
if result != nil:
|
||||||
result = copyType(result, getCurrOwner(), false)
|
result = copyType(result, getCurrOwner(), false)
|
||||||
|
|
|
||||||
|
|
@ -418,76 +418,75 @@ proc modInt64(a, b: int): int {.noStackFrame, compilerproc.} =
|
||||||
return Math.floor(`a` % `b`);
|
return Math.floor(`a` % `b`);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc NegInt(a: int): int {.compilerproc.} =
|
proc negInt(a: int): int {.compilerproc.} =
|
||||||
result = a*(-1)
|
result = a*(-1)
|
||||||
|
|
||||||
proc NegInt64(a: int64): int64 {.compilerproc.} =
|
proc negInt64(a: int64): int64 {.compilerproc.} =
|
||||||
result = a*(-1)
|
result = a*(-1)
|
||||||
|
|
||||||
proc AbsInt(a: int): int {.compilerproc.} =
|
proc absInt(a: int): int {.compilerproc.} =
|
||||||
result = if a < 0: a*(-1) else: a
|
result = if a < 0: a*(-1) else: a
|
||||||
|
|
||||||
proc AbsInt64(a: int64): int64 {.compilerproc.} =
|
proc absInt64(a: int64): int64 {.compilerproc.} =
|
||||||
result = if a < 0: a*(-1) else: a
|
result = if a < 0: a*(-1) else: a
|
||||||
|
|
||||||
proc LeU(a, b: int): bool {.compilerproc.} =
|
proc leU(a, b: int): bool {.compilerproc.} =
|
||||||
result = abs(a) <= abs(b)
|
result = abs(a) <= abs(b)
|
||||||
|
|
||||||
proc LtU(a, b: int): bool {.compilerproc.} =
|
proc ltU(a, b: int): bool {.compilerproc.} =
|
||||||
result = abs(a) < abs(b)
|
result = abs(a) < abs(b)
|
||||||
|
|
||||||
proc LeU64(a, b: int64): bool {.compilerproc.} =
|
proc leU64(a, b: int64): bool {.compilerproc.} =
|
||||||
result = abs(a) <= abs(b)
|
result = abs(a) <= abs(b)
|
||||||
|
proc ltU64(a, b: int64): bool {.compilerproc.} =
|
||||||
proc LtU64(a, b: int64): bool {.compilerproc.} =
|
|
||||||
result = abs(a) < abs(b)
|
result = abs(a) < abs(b)
|
||||||
|
|
||||||
proc AddU(a, b: int): int {.compilerproc.} =
|
proc addU(a, b: int): int {.compilerproc.} =
|
||||||
result = abs(a) + abs(b)
|
result = abs(a) + abs(b)
|
||||||
proc AddU64(a, b: int64): int64 {.compilerproc.} =
|
proc addU64(a, b: int64): int64 {.compilerproc.} =
|
||||||
result = abs(a) + abs(b)
|
result = abs(a) + abs(b)
|
||||||
|
|
||||||
proc SubU(a, b: int): int {.compilerproc.} =
|
proc subU(a, b: int): int {.compilerproc.} =
|
||||||
result = abs(a) - abs(b)
|
result = abs(a) - abs(b)
|
||||||
proc SubU64(a, b: int64): int64 {.compilerproc.} =
|
proc subU64(a, b: int64): int64 {.compilerproc.} =
|
||||||
result = abs(a) - abs(b)
|
result = abs(a) - abs(b)
|
||||||
|
|
||||||
proc MulU(a, b: int): int {.compilerproc.} =
|
proc mulU(a, b: int): int {.compilerproc.} =
|
||||||
result = abs(a) * abs(b)
|
result = abs(a) * abs(b)
|
||||||
proc MulU64(a, b: int64): int64 {.compilerproc.} =
|
proc mulU64(a, b: int64): int64 {.compilerproc.} =
|
||||||
result = abs(a) * abs(b)
|
result = abs(a) * abs(b)
|
||||||
|
|
||||||
proc DivU(a, b: int): int {.compilerproc.} =
|
proc divU(a, b: int): int {.compilerproc.} =
|
||||||
result = abs(a) div abs(b)
|
result = abs(a) div abs(b)
|
||||||
proc DivU64(a, b: int64): int64 {.compilerproc.} =
|
proc divU64(a, b: int64): int64 {.compilerproc.} =
|
||||||
result = abs(a) div abs(b)
|
result = abs(a) div abs(b)
|
||||||
|
|
||||||
proc ModU(a, b: int): int {.compilerproc.} =
|
proc modU(a, b: int): int {.compilerproc.} =
|
||||||
result = abs(a) mod abs(b)
|
result = abs(a) mod abs(b)
|
||||||
proc ModU64(a, b: int64): int64 {.compilerproc.} =
|
proc modU64(a, b: int64): int64 {.compilerproc.} =
|
||||||
result = abs(a) mod abs(b)
|
result = abs(a) mod abs(b)
|
||||||
|
|
||||||
proc Ze(a: int): int {.compilerproc.} =
|
proc ze*(a: int): int {.compilerproc.} =
|
||||||
result = a
|
|
||||||
proc Ze64(a: int64): int64 {.compilerproc.} =
|
|
||||||
result = a
|
result = a
|
||||||
|
|
||||||
proc ToU8(a: int): int8 {.noStackFrame, compilerproc.} =
|
proc ze64*(a: int64): int64 {.compilerproc.} =
|
||||||
|
result = a
|
||||||
|
|
||||||
|
proc toU8*(a: int): int8 {.noStackFrame, compilerproc.} =
|
||||||
asm """
|
asm """
|
||||||
return `a`;
|
return `a`;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc ToU16(a: int): int16 {.noStackFrame, compilerproc.} =
|
proc toU16*(a: int): int16 {.noStackFrame, compilerproc.} =
|
||||||
asm """
|
asm """
|
||||||
return `a`;
|
return `a`;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc ToU32(a: int): int32 {.noStackFrame, compilerproc.} =
|
proc toU32*(a: int64): int32 {.noStackFrame, compilerproc.} =
|
||||||
asm """
|
asm """
|
||||||
return `a`;
|
return `a`;
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
proc nimMin(a, b: int): int {.compilerproc.} = return if a <= b: a else: b
|
proc nimMin(a, b: int): int {.compilerproc.} = return if a <= b: a else: b
|
||||||
proc nimMax(a, b: int): int {.compilerproc.} = return if a >= b: a else: b
|
proc nimMax(a, b: int): int {.compilerproc.} = return if a >= b: a else: b
|
||||||
|
|
||||||
|
|
@ -500,9 +499,9 @@ proc isFatPointer(ti: PNimType): bool =
|
||||||
tyArray, tyArrayConstr, tyTuple,
|
tyArray, tyArrayConstr, tyTuple,
|
||||||
tyOpenArray, tySet, tyVar, tyRef, tyPtr}
|
tyOpenArray, tySet, tyVar, tyRef, tyPtr}
|
||||||
|
|
||||||
proc NimCopy(x: pointer, ti: PNimType): pointer {.compilerproc.}
|
proc nimCopy(x: pointer, ti: PNimType): pointer {.compilerproc.}
|
||||||
|
|
||||||
proc NimCopyAux(dest, src: Pointer, n: ptr TNimNode) {.compilerproc.} =
|
proc nimCopyAux(dest, src: Pointer, n: ptr TNimNode) {.compilerproc.} =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkNone: sysAssert(false, "NimCopyAux")
|
of nkNone: sysAssert(false, "NimCopyAux")
|
||||||
of nkSlot:
|
of nkSlot:
|
||||||
|
|
@ -518,7 +517,7 @@ proc NimCopyAux(dest, src: Pointer, n: ptr TNimNode) {.compilerproc.} =
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc NimCopy(x: pointer, ti: PNimType): pointer =
|
proc nimCopy(x: pointer, ti: PNimType): pointer =
|
||||||
case ti.kind
|
case ti.kind
|
||||||
of tyPtr, tyRef, tyVar, tyNil:
|
of tyPtr, tyRef, tyVar, tyNil:
|
||||||
if not isFatPointer(ti):
|
if not isFatPointer(ti):
|
||||||
|
|
@ -585,7 +584,7 @@ proc genericReset(x: Pointer, ti: PNimType): pointer {.compilerproc.} =
|
||||||
else:
|
else:
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
proc ArrayConstr(len: int, value: pointer, typ: PNimType): pointer {.
|
proc arrayConstr(len: int, value: pointer, typ: PNimType): pointer {.
|
||||||
noStackFrame, compilerproc.} =
|
noStackFrame, compilerproc.} =
|
||||||
# types are fake
|
# types are fake
|
||||||
asm """
|
asm """
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
output: "10\n10"
|
output: "10\n10\n1\n2\n3"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc test(x: proc (a, b: int): int) =
|
proc test(x: proc (a, b: int): int) =
|
||||||
|
|
@ -8,3 +8,11 @@ proc test(x: proc (a, b: int): int) =
|
||||||
test(proc (a, b): auto = a + b)
|
test(proc (a, b): auto = a + b)
|
||||||
|
|
||||||
test do (a, b) -> auto: a + b
|
test do (a, b) -> auto: a + b
|
||||||
|
|
||||||
|
proc foreach[T](s: seq[T], body: proc(x: T)) =
|
||||||
|
for e in s:
|
||||||
|
body(e)
|
||||||
|
|
||||||
|
foreach(@[1,2,3]) do (x):
|
||||||
|
echo x
|
||||||
|
|
||||||
|
|
|
||||||
15
tests/global/globalaux.nim
Normal file
15
tests/global/globalaux.nim
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
type
|
||||||
|
TObj*[T] = object
|
||||||
|
val*: T
|
||||||
|
|
||||||
|
var
|
||||||
|
totalGlobals* = 0
|
||||||
|
|
||||||
|
proc makeObj[T](x: T): TObj[T] =
|
||||||
|
totalGlobals += 1
|
||||||
|
result.val = x
|
||||||
|
|
||||||
|
proc globalInstance*[T]: var TObj[T] =
|
||||||
|
var g {.global.} = when T is int: makeObj(10) else: makeObj("hello")
|
||||||
|
result = g
|
||||||
|
|
||||||
4
tests/global/globalaux2.nim
Normal file
4
tests/global/globalaux2.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
import globalaux
|
||||||
|
|
||||||
|
echo "in globalaux2: ", globalInstance[int]().val
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tests/reject/trecincb.nim"
|
file: "tests/reject/trecincb.nim"
|
||||||
line: 9
|
line: 9
|
||||||
errormsg: "recursive dependency: 'tests/reject/trecincb.nim'"
|
errormsg: "recursive dependency: 'tests/module/trecincb.nim'"
|
||||||
"""
|
"""
|
||||||
# Test recursive includes
|
# Test recursive includes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
file: "trecincb.nim"
|
file: "trecincb.nim"
|
||||||
line: 9
|
line: 9
|
||||||
errormsg: "recursive dependency: 'tests/reject/trecincb.nim'"
|
errormsg: "recursive dependency: 'tests/module/trecincb.nim'"
|
||||||
"""
|
"""
|
||||||
# Test recursive includes
|
# Test recursive includes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ type
|
||||||
channel: string
|
channel: string
|
||||||
timestamp: TTime
|
timestamp: TTime
|
||||||
case kind*: TSeenType
|
case kind*: TSeenType
|
||||||
of PSeenJoin: discard
|
of PSeenJoin: nil
|
||||||
of PSeenPart, PSeenQuit, PSeenMsg:
|
of PSeenPart, PSeenQuit, PSeenMsg:
|
||||||
msg: string
|
msg: string
|
||||||
of PSeenNick:
|
of PSeenNick:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
discard """
|
discard """
|
||||||
output: "he, no return type;abc a string"
|
output: '''12
|
||||||
|
empty
|
||||||
|
he, no return type;
|
||||||
|
abc a string
|
||||||
|
ha'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc ReturnT[T](x: T): T =
|
proc ReturnT[T](x: T): T =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue