From 678f3d7f5bf7998816431f38604c0b9e0f27c90a Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 30 Jun 2014 16:45:55 +0200 Subject: fixes constant array indexing bug --- tests/vm/tarrayboundeval.nim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests/vm') diff --git a/tests/vm/tarrayboundeval.nim b/tests/vm/tarrayboundeval.nim index 9b33a2415..07aac4c4e 100644 --- a/tests/vm/tarrayboundeval.nim +++ b/tests/vm/tarrayboundeval.nim @@ -1,6 +1,7 @@ discard """ output: '''7 -8 8''' +8 8 +-2''' """ #bug 1063 @@ -21,3 +22,10 @@ type internal: array[int((KeyMax + 31)/32), cuint] echo myconst, " ", int((KeyMax + 31) / 32) + +#bug 1304 or something: + +const constArray: array [-3..2, int] = [-3, -2, -1, 0, 1, 2] + +echo constArray[-2] + -- cgit 1.4.1-2-gfad0 From 21be7bf85a4d8cdff1acfcc5c8b9bf9c0727b290 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 2 Jul 2014 21:15:29 +0200 Subject: fixes #1310 --- compiler/vm.nim | 7 +++++++ compiler/vmgen.nim | 9 ++++++++- tests/vm/teval1.nim | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/vm') diff --git a/compiler/vm.nim b/compiler/vm.nim index 0c2c23987..7f5e0d1c5 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -138,6 +138,9 @@ proc createStrKeepNode(x: var TFullReg) = template createStr(x) = x.node = newNode(nkStrLit) +template createSet(x) = + x.node = newNode(nkCurly) + proc moveConst(x: var TFullReg, y: TFullReg) = if x.kind != y.kind: myreset(x) @@ -722,18 +725,22 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = regs[ra].intVal = ord(containsSets(a, b) and not equalSets(a, b)) of opcMulSet: decodeBC(rkNode) + createSet(regs[ra]) move(regs[ra].node.sons, nimsets.intersectSets(regs[rb].node, regs[rc].node).sons) of opcPlusSet: decodeBC(rkNode) + createSet(regs[ra]) move(regs[ra].node.sons, nimsets.unionSets(regs[rb].node, regs[rc].node).sons) of opcMinusSet: decodeBC(rkNode) + createSet(regs[ra]) move(regs[ra].node.sons, nimsets.diffSets(regs[rb].node, regs[rc].node).sons) of opcSymdiffSet: decodeBC(rkNode) + createSet(regs[ra]) move(regs[ra].node.sons, nimsets.symdiffSets(regs[rb].node, regs[rc].node).sons) of opcConcatStr: diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 3819bed98..28e0a8fd6 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -14,7 +14,12 @@ # assignments ('x = y'). For simple data types that fit into a register # this doesn't matter. However it matters for strings and other complex # types that use the 'node' field; the reason is that slots are -# re-used in a register based VM. XXX Come up with an example. +# re-used in a register based VM. Example: +# +# .. code-block:: nimrod +# let s = a & b # no matter what, create fresh node +# s = a & b # no matter what, keep the node +# import unsigned, strutils, ast, astalgo, types, msgs, renderer, vmdef, @@ -1335,6 +1340,8 @@ proc genVarSection(c: PCtx; n: PNode) = if a.sons[2].kind == nkEmpty: c.gABx(a, ldNullOpcode(s.typ), s.position, c.genType(s.typ)) else: + if not fitsRegister(s.typ): + c.gABx(a, ldNullOpcode(s.typ), s.position, c.genType(s.typ)) gen(c, a.sons[2], s.position.TRegister) else: # assign to a.sons[0]; happens for closures diff --git a/tests/vm/teval1.nim b/tests/vm/teval1.nim index a02f26592..cdb4ad8e2 100644 --- a/tests/vm/teval1.nim +++ b/tests/vm/teval1.nim @@ -16,4 +16,9 @@ const echo "##", x, "##" +# bug #1310 +static: + var i, j: set[int8] = {} + var k = i + j + -- cgit 1.4.1-2-gfad0