fixes #1781
This commit is contained in:
parent
010b8f85c7
commit
41587a5339
3 changed files with 27 additions and 6 deletions
|
|
@ -164,7 +164,8 @@ type
|
||||||
slotTempInt, # some temporary int
|
slotTempInt, # some temporary int
|
||||||
slotTempFloat, # some temporary float
|
slotTempFloat, # some temporary float
|
||||||
slotTempStr, # some temporary string
|
slotTempStr, # some temporary string
|
||||||
slotTempComplex # some complex temporary (s.node field is used)
|
slotTempComplex, # some complex temporary (s.node field is used)
|
||||||
|
slotTempPerm # slot is temporary but permanent (hack)
|
||||||
|
|
||||||
PProc* = ref object
|
PProc* = ref object
|
||||||
blocks*: seq[TBlock] # blocks; temp data structure
|
blocks*: seq[TBlock] # blocks; temp data structure
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
# types that use the 'node' field; the reason is that slots are
|
# types that use the 'node' field; the reason is that slots are
|
||||||
# re-used in a register based VM. Example:
|
# re-used in a register based VM. Example:
|
||||||
#
|
#
|
||||||
# .. code-block:: nimrod
|
# .. code-block:: nim
|
||||||
# let s = a & b # no matter what, create fresh node
|
# let s = a & b # no matter what, create fresh node
|
||||||
# s = a & b # no matter what, keep the node
|
# s = a & b # no matter what, keep the node
|
||||||
#
|
#
|
||||||
|
|
@ -58,6 +58,7 @@ proc codeListing(c: PCtx, result: var string, start=0; last = -1) =
|
||||||
if i in jumpTargets: result.addf("L$1:\n", i)
|
if i in jumpTargets: result.addf("L$1:\n", i)
|
||||||
let x = c.code[i]
|
let x = c.code[i]
|
||||||
|
|
||||||
|
result.add($i)
|
||||||
let opc = opcode(x)
|
let opc = opcode(x)
|
||||||
if opc in {opcConv, opcCast}:
|
if opc in {opcConv, opcCast}:
|
||||||
let y = c.code[i+1]
|
let y = c.code[i+1]
|
||||||
|
|
@ -188,7 +189,7 @@ proc getTemp(c: PCtx; typ: PType): TRegister =
|
||||||
|
|
||||||
proc freeTemp(c: PCtx; r: TRegister) =
|
proc freeTemp(c: PCtx; r: TRegister) =
|
||||||
let c = c.prc
|
let c = c.prc
|
||||||
if c.slots[r].kind >= slotSomeTemp: c.slots[r].inUse = false
|
if c.slots[r].kind in {slotSomeTemp..slotTempComplex}: c.slots[r].inUse = false
|
||||||
|
|
||||||
proc getTempRange(c: PCtx; n: int; kind: TSlotKind): TRegister =
|
proc getTempRange(c: PCtx; n: int; kind: TSlotKind): TRegister =
|
||||||
# if register pressure is high, we re-use more aggressively:
|
# if register pressure is high, we re-use more aggressively:
|
||||||
|
|
@ -1074,8 +1075,10 @@ proc genAddrDeref(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode;
|
||||||
c.gABC(n, opcNodeToReg, dest, dest)
|
c.gABC(n, opcNodeToReg, dest, dest)
|
||||||
elif c.prc.slots[tmp].kind >= slotTempUnknown:
|
elif c.prc.slots[tmp].kind >= slotTempUnknown:
|
||||||
gABC(c, n, opcAddrNode, dest, tmp)
|
gABC(c, n, opcAddrNode, dest, tmp)
|
||||||
# XXX this can still be wrong sometimes; hopefully it's only generated
|
# hack ahead; in order to fix bug #1781 we mark the temporary as
|
||||||
# in call contexts, where it is safe
|
# permanent, so that it's not used for anything else:
|
||||||
|
c.prc.slots[tmp].kind = slotTempPerm
|
||||||
|
# XXX this is still a hack
|
||||||
#message(n.info, warnUser, "suspicious opcode used")
|
#message(n.info, warnUser, "suspicious opcode used")
|
||||||
else:
|
else:
|
||||||
gABC(c, n, opcAddrReg, dest, tmp)
|
gABC(c, n, opcAddrReg, dest, tmp)
|
||||||
|
|
|
||||||
17
tests/vm/triangle_array.nim
Normal file
17
tests/vm/triangle_array.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
discard """
|
||||||
|
output: "56"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #1781
|
||||||
|
|
||||||
|
proc initCombinations: array[11, array[11, int]] =
|
||||||
|
result[0] = [1,2,3,4,5,6,7,8,9,10,11]
|
||||||
|
result[1][1 .. 10] = [12,13,14,15,16,17,18,19,20,21]
|
||||||
|
result[2][2 .. 10] = [22,23,24,25,26,27,28,29,30]
|
||||||
|
result[3][3 .. 10] = [31,32,33,34,35,36,37,38]
|
||||||
|
result[4][4 .. 10] = [39,40,41,42,43,44,45]
|
||||||
|
result[5][5 .. 10] = [46,47,48,49,50,51]
|
||||||
|
result[6][6 .. 10] = [52,53,54,55,56]
|
||||||
|
|
||||||
|
const combinations = initCombinations()
|
||||||
|
echo combinations[6][10]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue