From a562de2d9189706a9b7b9045c8abf9b821549692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Wed, 21 Aug 2019 19:15:15 +0200 Subject: [PATCH 1/7] squashed and merged with devel --- compiler/astalgo.nim | 6 ++-- compiler/lexer.nim | 2 +- compiler/semexprs.nim | 2 +- compiler/semtypes.nim | 2 +- compiler/types.nim | 11 +++---- lib/system.nim | 2 +- tests/arithm/tarithm.nim | 1 + tests/converter/tstatic_range_checks.nim | 42 ++++++++++++++++++++++++ 8 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 tests/converter/tstatic_range_checks.nim diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index 4100c3629..632f00f4d 100644 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -117,7 +117,7 @@ proc sameValue*(a, b: PNode): bool = result = false case a.kind of nkCharLit..nkUInt64Lit: - if b.kind in {nkCharLit..nkUInt64Lit}: result = a.intVal == b.intVal + if b.kind in {nkCharLit..nkUInt64Lit}: result = getInt(a) == getInt(b) of nkFloatLit..nkFloat64Lit: if b.kind in {nkFloatLit..nkFloat64Lit}: result = a.floatVal == b.floatVal of nkStrLit..nkTripleStrLit: @@ -131,8 +131,8 @@ proc leValue*(a, b: PNode): bool = # a <= b? result = false case a.kind - of nkCharLit..nkUInt32Lit: - if b.kind in {nkCharLit..nkUInt32Lit}: result = a.intVal <= b.intVal + of nkCharLit..nkUInt64Lit: + if b.kind in {nkCharLit..nkUInt64Lit}: result = getInt(a) <= getInt(b) of nkFloatLit..nkFloat64Lit: if b.kind in {nkFloatLit..nkFloat64Lit}: result = a.floatVal <= b.floatVal of nkStrLit..nkTripleStrLit: diff --git a/compiler/lexer.nim b/compiler/lexer.nim index c2b95c481..d1e75d314 100644 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -565,7 +565,7 @@ proc getNumber(L: var TLexer, result: var TToken) = case result.tokType of floatTypes: result.fNumber = parseFloat(result.literal) - of tkUInt64Lit: + of tkUInt64Lit, tkUIntLit: var iNumber: uint64 var len: int try: diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index b80c4c8cb..5a4811770 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -341,7 +341,7 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode = n.typ = getSysType(c.graph, n.info, tyInt) of tyArray: n.typ = typ.sons[0] # indextype - of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt8, tyUInt16, tyUInt32, tyFloat..tyFloat64: + of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt..tyUInt64, tyFloat..tyFloat64: n.typ = n.sons[1].typ.skipTypes({tyTypeDesc}) of tyGenericParam: # prepare this for resolving in semtypinst: diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 3038a1a6b..33285e6f4 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -223,7 +223,7 @@ proc semRangeAux(c: PContext, n: PNode, prev: PType): PType = if not hasUnknownTypes: if not sameType(rangeT[0].skipTypes({tyRange}), rangeT[1].skipTypes({tyRange})): localError(c.config, n.info, "type mismatch") - elif not rangeT[0].isOrdinalType and rangeT[0].kind notin tyFloat..tyFloat128 or + elif not rangeT[0].isOrdinalType(allowUint=true) and rangeT[0].kind notin tyFloat..tyFloat128 or rangeT[0].kind == tyBool: localError(c.config, n.info, "ordinal or float type expected") elif enumHasHoles(rangeT[0]): diff --git a/compiler/types.nim b/compiler/types.nim index 61fbffd60..671ee622c 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -155,14 +155,13 @@ proc enumHasHoles*(t: PType): bool = var b = t.skipTypes({tyRange, tyGenericInst, tyAlias, tySink}) result = b.kind == tyEnum and tfEnumHasHoles in b.flags -proc isOrdinalType*(t: PType, allowEnumWithHoles = false): bool = +proc isOrdinalType*(t: PType, allowEnumWithHoles: bool = false): bool = assert(t != nil) const - # caution: uint, uint64 are no ordinal types! - baseKinds = {tyChar,tyInt..tyInt64,tyUInt8..tyUInt32,tyBool,tyEnum} + baseKinds = {tyChar,tyInt..tyUInt64,tyBool,tyEnum} parentKinds = {tyRange, tyOrdinal, tyGenericInst, tyAlias, tySink, tyDistinct} - (t.kind in baseKinds and not (t.enumHasHoles and not allowEnumWithHoles)) or - (t.kind in parentKinds and isOrdinalType(t.lastSon)) + result = (t.kind in baseKinds and not (t.enumHasHoles and not allowEnumWithHoles)) or + (t.kind in parentKinds and isOrdinalType(t.lastSon, allowEnumWithHoles)) proc iterOverTypeAux(marker: var IntSet, t: PType, iter: TTypeIter, closure: RootRef): bool @@ -1284,7 +1283,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, result = typeAllowedAux(marker, lastSon(t), kind, flags) of tyRange: if skipTypes(t.sons[0], abstractInst-{tyTypeDesc}).kind notin - {tyChar, tyEnum, tyInt..tyFloat128, tyUInt8..tyUInt32}: result = t + {tyChar, tyEnum, tyInt..tyFloat128, tyInt..tyUInt64}: result = t of tyOpenArray, tyVarargs, tySink: if kind != skParam: result = t diff --git a/lib/system.nim b/lib/system.nim index 7e23b5188..61c9ee57f 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -97,7 +97,7 @@ type SomeInteger* = SomeSignedInt|SomeUnsignedInt ## Type class matching all integer types. - SomeOrdinal* = int|int8|int16|int32|int64|bool|enum|uint8|uint16|uint32 + SomeOrdinal* = int|int8|int16|int32|int64|bool|enum|uint|uint8|uint16|uint32|uint64 ## Type class matching all ordinal types; however this includes enums with ## holes. diff --git a/tests/arithm/tarithm.nim b/tests/arithm/tarithm.nim index 1150af951..e20b159f8 100644 --- a/tests/arithm/tarithm.nim +++ b/tests/arithm/tarithm.nim @@ -54,6 +54,7 @@ block tcast: crossCheck(uint16, uint16.high + 5'u16) crossCheck(uint32, uint32.high + 5'u32) crossCheck(uint64, 0xFFFFFFFFFFFFFFFF'u64 + 5'u64) + crossCheck(uint64, uint64.high + 5'u64) doAssert $sub1(0'u8) == "255" doAssert $sub1(0'u16) == "65535" diff --git a/tests/converter/tstatic_range_checks.nim b/tests/converter/tstatic_range_checks.nim new file mode 100644 index 000000000..ea61fd88d --- /dev/null +++ b/tests/converter/tstatic_range_checks.nim @@ -0,0 +1,42 @@ +template reject(e) = + static: assert(not compiles(e)) + +template accept(e) = + static: assert(compiles(e)) + +type + UnsignedRange = 0'u64 .. 100'u64 + SemiOutOfBounds = 0x7ffffffffffffe00'u64 .. 0x8000000000000100'u64 + FullOutOfBounds = 0x8000000000000000'u64 .. 0x8000000000000200'u64 + + FullNegativeRange = -200 .. -100 + HalfNegativeRange = -50 .. 50 + FullPositiveRange = 100 .. 200 + +reject(int32(0x80000000'i64)) +accept(int32(0x7fffffff'i64)) + +reject(uint64(-1'i64)) +accept(uint64(0'i64)) + +reject(FullNegativeRange(0xff'u32)) +reject(HalfNegativeRange(0xffffffffffffffff'u64)) # internal `intVal` is `-1` which would be in range. +accept(HalfNegativeRange(25'u64)) +reject(FullPositiveRange(300'u64)) + +accept(UnsignedRange(50'u64)) +reject(UnsignedRange(101'u64)) + +accept(SemiOutOfBounds(0x7ffffffffffffe00'i64)) +reject(SemiOutOfBounds(0x8000000000000000'i64)) # +accept(SemiOutOfBounds(0x8000000000000000'u64)) # the last two literals have internally the same `intVal`. + +reject(int32(NaN)) +reject(int64(1e100)) +reject(uint64(1e100)) + +# removed cross checks from tarithm.nim +reject(int64(0xFFFFFFFFFFFFFFFF'u64)) +reject(int32(0xFFFFFFFFFFFFFFFF'u64)) +reject(int16(0xFFFFFFFFFFFFFFFF'u64)) +reject( int8(0xFFFFFFFFFFFFFFFF'u64)) From ab8241ad42635693df8a50326ebb24d52343059a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20D=C3=B6ring?= Date: Tue, 27 Aug 2019 12:21:04 +0200 Subject: [PATCH 2/7] minor stuff --- compiler/semtypes.nim | 2 +- compiler/transf.nim | 2 +- compiler/types.nim | 4 ++-- compiler/vmgen.nim | 14 ++++---------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 33285e6f4..84611a0bc 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -223,7 +223,7 @@ proc semRangeAux(c: PContext, n: PNode, prev: PType): PType = if not hasUnknownTypes: if not sameType(rangeT[0].skipTypes({tyRange}), rangeT[1].skipTypes({tyRange})): localError(c.config, n.info, "type mismatch") - elif not rangeT[0].isOrdinalType(allowUint=true) and rangeT[0].kind notin tyFloat..tyFloat128 or + elif not isOrdinalType(rangeT[0]) and rangeT[0].kind notin tyFloat..tyFloat128 or rangeT[0].kind == tyBool: localError(c.config, n.info, "ordinal or float type expected") elif enumHasHoles(rangeT[0]): diff --git a/compiler/transf.nim b/compiler/transf.nim index 555583685..6be688ace 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -718,7 +718,7 @@ proc transformCase(c: PTransf, n: PNode): PTransNode = result.add(elseBranch) elif result.PNode.lastSon.kind != nkElse and not ( skipTypes(n.sons[0].typ, abstractVarRange).kind in - {tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt32}): + {tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt64}): # fix a stupid code gen bug by normalizing: var elseBranch = newTransNode(nkElse, n.info, 1) elseBranch[0] = newTransNode(nkNilLit, n.info, 0) diff --git a/compiler/types.nim b/compiler/types.nim index 671ee622c..17df70f27 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -158,9 +158,9 @@ proc enumHasHoles*(t: PType): bool = proc isOrdinalType*(t: PType, allowEnumWithHoles: bool = false): bool = assert(t != nil) const - baseKinds = {tyChar,tyInt..tyUInt64,tyBool,tyEnum} + baseKinds = {tyChar,tyInt..tyInt64,tyUInt..tyUInt64,tyBool,tyEnum} parentKinds = {tyRange, tyOrdinal, tyGenericInst, tyAlias, tySink, tyDistinct} - result = (t.kind in baseKinds and not (t.enumHasHoles and not allowEnumWithHoles)) or + result = (t.kind in baseKinds and (not t.enumHasHoles or allowEnumWithHoles)) or (t.kind in parentKinds and isOrdinalType(t.lastSon, allowEnumWithHoles)) proc iterOverTypeAux(marker: var IntSet, t: PType, iter: TTypeIter, diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 9cd3b841e..33ba471bd 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -682,6 +682,7 @@ proc genUnaryABI(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode; imm: BiggestI c.gABI(n, opc, dest, tmp, imm) c.freeTemp(tmp) + proc genBinaryABC(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) = let tmp = c.genx(n.sons[1]) @@ -999,22 +1000,15 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mMulF64: genBinaryABC(c, n, dest, opcMulFloat) of mDivF64: genBinaryABC(c, n, dest, opcDivFloat) of mShrI: - # the idea here is to narrow type if needed before executing right shift - # inlined modified: genNarrowU(c, n, dest) - let t = skipTypes(n.typ, abstractVar-{tyTypeDesc}) - # uint is uint64 in the VM, we we only need to mask the result for - # other unsigned types: + # modified: genBinaryABC(c, n, dest, opcShrInt) + # narrowU is applied to the left operandthe idea here is to narrow the left operand let tmp = c.genx(n.sons[1]) - if t.kind in {tyUInt8..tyUInt32, tyInt8..tyInt32}: - c.gABC(n, opcNarrowU, tmp, TRegister(t.size*8)) - - # inlined modified: genBinaryABC(c, n, dest, opcShrInt) + c.genNarrowU(n, tmp) let tmp2 = c.genx(n.sons[2]) if dest < 0: dest = c.getTemp(n.typ) c.gABC(n, opcShrInt, dest, tmp, tmp2) c.freeTemp(tmp) c.freeTemp(tmp2) - of mShlI: genBinaryABC(c, n, dest, opcShlInt) # genNarrowU modified From e6ec88d4c39c458404061198b2a2f6b86c2caeaf Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 2 Sep 2019 10:27:33 +0200 Subject: [PATCH 3/7] renamed and moved test --- .../tcompiletime_range_checks.nim} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{converter/tstatic_range_checks.nim => range/tcompiletime_range_checks.nim} (100%) diff --git a/tests/converter/tstatic_range_checks.nim b/tests/range/tcompiletime_range_checks.nim similarity index 100% rename from tests/converter/tstatic_range_checks.nim rename to tests/range/tcompiletime_range_checks.nim From 2396f0ee71a939d6305c829610dfb24f55e53c1c Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 2 Sep 2019 10:56:51 +0200 Subject: [PATCH 4/7] make test green --- compiler/semexprs.nim | 2 +- compiler/semfold.nim | 5 +- tests/range/tcompiletime_range_checks.nim | 78 +++++++++++++---------- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 643580ff2..2d33c742b 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -149,7 +149,7 @@ proc checkConvertible(c: PContext, targetTyp: PType, src: PNode): TConvStatus = (srcBaseTyp.kind in IntegralTypes): if targetTyp.isOrdinalType: if src.kind in nkCharLit..nkUInt64Lit and - src.intVal notin firstOrd(c.config, targetTyp)..lastOrd(c.config, targetTyp): + src.getInt notin firstOrd(c.config, targetTyp)..lastOrd(c.config, targetTyp): result = convNotInRange elif src.kind in nkFloatLit..nkFloat64Lit and (classify(src.floatVal) in {fcNan, fcNegInf, fcInf} or diff --git a/compiler/semfold.nim b/compiler/semfold.nim index bfb5077d6..a1732ebb4 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -206,8 +206,9 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode = of mSubI: result = foldSub(getInt(a), getInt(b), n, g) of mMulI: result = foldMul(getInt(a), getInt(b), n, g) of mMinI: - if getInt(a) > getInt(b): result = newIntNodeT(getInt64(b), n, g) - else: result = newIntNodeT(getInt64(a), n, g) + let argA = getInt(a) + let argB = getInt(b) + result = newIntNodeT(if argA < argB: argA else: argB, n, g) of mMaxI: let argA = getInt(a) let argB = getInt(b) diff --git a/tests/range/tcompiletime_range_checks.nim b/tests/range/tcompiletime_range_checks.nim index ea61fd88d..37095e0b7 100644 --- a/tests/range/tcompiletime_range_checks.nim +++ b/tests/range/tcompiletime_range_checks.nim @@ -1,42 +1,52 @@ -template reject(e) = - static: assert(not compiles(e)) - -template accept(e) = - static: assert(compiles(e)) +discard """ + cmd: "nim check --hint[Processing]:off --hint[Conf]:off $file" + errormsg: "18446744073709551615 can't be converted to int8" + nimout: '''tcompiletime_range_checks.nim(36, 21) Error: 2147483648 can't be converted to int32 +tcompiletime_range_checks.nim(37, 23) Error: -1 can't be converted to uint64 +tcompiletime_range_checks.nim(38, 34) Error: 255 can't be converted to FullNegativeRange +tcompiletime_range_checks.nim(39, 34) Error: 18446744073709551615 can't be converted to HalfNegativeRange +tcompiletime_range_checks.nim(40, 34) Error: 300 can't be converted to FullPositiveRange +tcompiletime_range_checks.nim(41, 30) Error: 101 can't be converted to UnsignedRange +tcompiletime_range_checks.nim(42, 32) Error: -9223372036854775808 can't be converted to SemiOutOfBounds +tcompiletime_range_checks.nim(44, 22) Error: nan can't be converted to int32 +tcompiletime_range_checks.nim(46, 23) Error: 1e+100 can't be converted to uint64 +tcompiletime_range_checks.nim(49, 22) Error: 18446744073709551615 can't be converted to int64 +tcompiletime_range_checks.nim(50, 22) Error: 18446744073709551615 can't be converted to int32 +tcompiletime_range_checks.nim(51, 22) Error: 18446744073709551615 can't be converted to int16 +tcompiletime_range_checks.nim(52, 21) Error: 18446744073709551615 can't be converted to int8 + ''' +""" type - UnsignedRange = 0'u64 .. 100'u64 - SemiOutOfBounds = 0x7ffffffffffffe00'u64 .. 0x8000000000000100'u64 - FullOutOfBounds = 0x8000000000000000'u64 .. 0x8000000000000200'u64 + UnsignedRange* = range[0'u64 .. 100'u64] + SemiOutOfBounds* = range[0x7ffffffffffffe00'u64 .. 0x8000000000000100'u64] + FullOutOfBounds* = range[0x8000000000000000'u64 .. 0x8000000000000200'u64] - FullNegativeRange = -200 .. -100 - HalfNegativeRange = -50 .. 50 - FullPositiveRange = 100 .. 200 + FullNegativeRange* = range[-200 .. -100] + HalfNegativeRange* = range[-50 .. 50] + FullPositiveRange* = range[100 .. 200] -reject(int32(0x80000000'i64)) -accept(int32(0x7fffffff'i64)) +let acceptA* = int32(0x7fffffff'i64) +let acceptB* = (uint64(0'i64)) +let acceptD* = (HalfNegativeRange(25'u64)) +let acceptE* = (UnsignedRange(50'u64)) +let acceptF* = (SemiOutOfBounds(0x7ffffffffffffe00'i64)) +let acceptH* = (SemiOutOfBounds(0x8000000000000000'u64)) -reject(uint64(-1'i64)) -accept(uint64(0'i64)) +let rejectA* = int32(0x80000000'i64) +let rejectB* = (uint64(-1'i64)) +let rejectC* = (FullNegativeRange(0xff'u32)) +let rejectD* = (HalfNegativeRange(0xffffffffffffffff'u64)) # internal `intVal` is `-1` which would be in range. +let rejectE* = (FullPositiveRange(300'u64)) +let rejectF* = (UnsignedRange(101'u64)) +let rejectG* = (SemiOutOfBounds(0x8000000000000000'i64)) # -reject(FullNegativeRange(0xff'u32)) -reject(HalfNegativeRange(0xffffffffffffffff'u64)) # internal `intVal` is `-1` which would be in range. -accept(HalfNegativeRange(25'u64)) -reject(FullPositiveRange(300'u64)) - -accept(UnsignedRange(50'u64)) -reject(UnsignedRange(101'u64)) - -accept(SemiOutOfBounds(0x7ffffffffffffe00'i64)) -reject(SemiOutOfBounds(0x8000000000000000'i64)) # -accept(SemiOutOfBounds(0x8000000000000000'u64)) # the last two literals have internally the same `intVal`. - -reject(int32(NaN)) -reject(int64(1e100)) -reject(uint64(1e100)) +let rejectH* = (int32(NaN)) +let rejectI* = (int64(1e100)) +let rejectJ* = (uint64(1e100)) # removed cross checks from tarithm.nim -reject(int64(0xFFFFFFFFFFFFFFFF'u64)) -reject(int32(0xFFFFFFFFFFFFFFFF'u64)) -reject(int16(0xFFFFFFFFFFFFFFFF'u64)) -reject( int8(0xFFFFFFFFFFFFFFFF'u64)) +let rejectK* = (int64(0xFFFFFFFFFFFFFFFF'u64)) +let rejectL* = (int32(0xFFFFFFFFFFFFFFFF'u64)) +let rejectM* = (int16(0xFFFFFFFFFFFFFFFF'u64)) +let rejectN* = (int8(0xFFFFFFFFFFFFFFFF'u64)) From 755c4428fe3a58e53baeff7df714ab660b9a3060 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 2 Sep 2019 11:03:08 +0200 Subject: [PATCH 5/7] added more tests and updated the changelog --- changelog.md | 3 +++ tests/misc/tlowhigh.nim | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/changelog.md b/changelog.md index 57820c81f..35639adc4 100644 --- a/changelog.md +++ b/changelog.md @@ -71,6 +71,9 @@ iterator mypairs[T](x: openarray[T]): tuple[idx: int, val: lent T] ## Language changes +- `uint64` is now finally a regular ordinal type. This means `high(uint64)` compiles + and yields the correct value. + ### Tool changes diff --git a/tests/misc/tlowhigh.nim b/tests/misc/tlowhigh.nim index 76f298a4a..6ae871255 100644 --- a/tests/misc/tlowhigh.nim +++ b/tests/misc/tlowhigh.nim @@ -1,5 +1,12 @@ discard """ action: run + output: ''' +18446744073709551615 +9223372036854775807 +4294967295 +0 +0 +''' """ var x: range[-1'f32..1'f32] @@ -16,3 +23,10 @@ doAssert y.type.high == 1'f64 # bug #11972 var num: uint8 doAssert num.high.float == 255.0 + +echo high(uint64) +echo high(int64) +echo high(uint32) + +echo low(uint64) +echo low(uint32) From 18ca1788f028aee0d01893b91c5568797830030d Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 2 Sep 2019 14:23:05 +0200 Subject: [PATCH 6/7] makes test green again --- tests/vm/tzero_extend.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/vm/tzero_extend.nim b/tests/vm/tzero_extend.nim index 76aa9ee67..1fed5d419 100644 --- a/tests/vm/tzero_extend.nim +++ b/tests/vm/tzero_extend.nim @@ -18,9 +18,9 @@ proc get_values(): (seq[int8], seq[int16], seq[int32]) = let i32 = -(1'i64 shl 33) + offset # higher bits are masked. these should be exactly equal to offset. - result[0].add cast[int8 ](uint8 cast[uint64](i8 )) - result[1].add cast[int16](uint16 cast[uint64](i16)) - result[2].add cast[int32](uint32 cast[uint64](i32)) + result[0].add cast[int8](cast[uint64](i8)) + result[1].add cast[int16](cast[uint64](i16)) + result[2].add cast[int32](cast[uint64](i32)) # these values this computed by VM From d70e292571754f1c00baf9651c558378537cdba8 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 2 Sep 2019 22:03:06 +0200 Subject: [PATCH 7/7] makes more tests green --- compiler/int128.nim | 8 -------- compiler/semfold.nim | 4 ++-- tests/stdlib/tbitops.nim | 14 +++++++------- tests/vm/ttouintconv.nim | 4 ++-- 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/compiler/int128.nim b/compiler/int128.nim index efa55f9c7..5d326ccab 100644 --- a/compiler/int128.nim +++ b/compiler/int128.nim @@ -16,13 +16,6 @@ template sdata(arg: Int128, idx: int): int32 = # encoding least significant int first (like LittleEndian) -type - InvalidArgument = object of Exception - -template require(cond: bool) = - if unlikely(not cond): - raise newException(InvalidArgument, "") - const Zero* = Int128(udata: [0'u32,0,0,0]) One* = Int128(udata: [1'u32,0,0,0]) @@ -378,7 +371,6 @@ proc `*`*(lhs,rhs: Int128): Int128 = result = result + toInt128(a00 * b32) shl 32 if isNegative != isNegative(result): - echo result assert(false, "overflow") proc `*=`*(a: var Int128, b: Int128) = diff --git a/compiler/semfold.nim b/compiler/semfold.nim index a1732ebb4..cf1586144 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -396,13 +396,13 @@ proc leValueConv*(a, b: PNode): bool = case a.kind of nkCharLit..nkUInt64Lit: case b.kind - of nkCharLit..nkUInt64Lit: result = a.intVal <= b.intVal + of nkCharLit..nkUInt64Lit: result = a.getInt <= b.getInt of nkFloatLit..nkFloat128Lit: result = a.intVal <= round(b.floatVal).int else: result = false #internalError(a.info, "leValueConv") of nkFloatLit..nkFloat128Lit: case b.kind of nkFloatLit..nkFloat128Lit: result = a.floatVal <= b.floatVal - of nkCharLit..nkUInt64Lit: result = a.floatVal <= toFloat(int(b.intVal)) + of nkCharLit..nkUInt64Lit: result = a.floatVal <= toFloat64(b.getInt) else: result = false # internalError(a.info, "leValueConv") else: result = false # internalError(a.info, "leValueConv") diff --git a/tests/stdlib/tbitops.nim b/tests/stdlib/tbitops.nim index b2393b755..e4461345e 100644 --- a/tests/stdlib/tbitops.nim +++ b/tests/stdlib/tbitops.nim @@ -211,15 +211,15 @@ proc main() = proc testReverseBitsPerType(x, reversed: uint64) = doAssert reverseBits(x) == reversed - doAssert reverseBits(uint32(x)) == uint32(reversed shr 32) - doAssert reverseBits(uint32(x shr 16)) == uint32(reversed shr 16) - doAssert reverseBits(uint16(x)) == uint16(reversed shr 48) - doAssert reverseBits(uint8(x)) == uint8(reversed shr 56) + doAssert reverseBits(cast[uint32](x)) == cast[uint32](reversed shr 32) + doAssert reverseBits(cast[uint32](x shr 16)) == cast[uint32](reversed shr 16) + doAssert reverseBits(cast[uint16](x)) == cast[uint16](reversed shr 48) + doAssert reverseBits(cast[uint8](x)) == cast[uint8](reversed shr 56) testReverseBitsInvo(x) - testReverseBitsInvo(uint32(x)) - testReverseBitsInvo(uint16(x)) - testReverseBitsInvo(uint8(x)) + testReverseBitsInvo(cast[uint32](x)) + testReverseBitsInvo(cast[uint16](x)) + testReverseBitsInvo(cast[uint8](x)) proc testReverseBitsRefl(x, reversed: uint64) = testReverseBitsPerType(x, reversed) diff --git a/tests/vm/ttouintconv.nim b/tests/vm/ttouintconv.nim index 403de8f41..ff2187a36 100644 --- a/tests/vm/ttouintconv.nim +++ b/tests/vm/ttouintconv.nim @@ -69,8 +69,8 @@ macro foo2() = echo zz var ww = -9 - var vv = ww.uint - var kk = vv.uint32 + var vv = cast[uint](ww) + var kk = cast[uint32](vv) echo kk foo()