Support system.reset in vm (#10400)

This commit is contained in:
Oscar Nihlgård 2019-01-21 17:00:33 +01:00 • committed by Andreas Rumpf
commit a4cdd25b19
4 changed files with 32 additions and 4 deletions

View file

@ -1249,8 +1249,6 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let newLen = regs[rb].intVal.int let newLen = regs[rb].intVal.int
if regs[ra].node.isNil: stackTrace(c, tos, pc, errNilAccess) if regs[ra].node.isNil: stackTrace(c, tos, pc, errNilAccess)
else: c.setLenSeq(regs[ra].node, newLen, c.debug[pc]) else: c.setLenSeq(regs[ra].node, newLen, c.debug[pc])
of opcReset:
internalError(c.config, c.debug[pc], "too implement")
of opcNarrowS: of opcNarrowS:
decodeB(rkInt) decodeB(rkInt)
let min = -(1.BiggestInt shl (rb-1)) let min = -(1.BiggestInt shl (rb-1))

View file

@ -73,7 +73,7 @@ type
opcContainsSet, opcRepr, opcSetLenStr, opcSetLenSeq, opcContainsSet, opcRepr, opcSetLenStr, opcSetLenSeq,
opcIsNil, opcOf, opcIs, opcIsNil, opcOf, opcIs,
opcSubStr, opcParseFloat, opcConv, opcCast, opcSubStr, opcParseFloat, opcConv, opcCast,
opcQuit, opcReset, opcQuit,
opcNarrowS, opcNarrowU, opcNarrowS, opcNarrowU,
opcAddStrCh, opcAddStrCh,

View file

@ -1105,7 +1105,9 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
of mReset: of mReset:
unused(c, n, dest) unused(c, n, dest)
var d = c.genx(n.sons[1]) var d = c.genx(n.sons[1])
c.gABC(n, opcReset, d) c.gABx(n, opcLdNull, d, c.genType(n.sons[1].typ))
c.gABx(n, opcNodeToReg, d, d)
c.genAsgnPatch(n.sons[1], d)
of mOf, mIs: of mOf, mIs:
if dest < 0: dest = c.getTemp(n.typ) if dest < 0: dest = c.getTemp(n.typ)
var tmp = c.genx(n.sons[1]) var tmp = c.genx(n.sons[1])

28
tests/vm/treset.nim Normal file
View file

@ -0,0 +1,28 @@
static:
type Obj = object
field: int
var o = Obj(field: 1)
reset(o)
doAssert o.field == 0
static:
var i = 2
reset(i)
doAssert i == 0
static:
var i = new int
reset(i)
doAssert i.isNil
static:
var s = @[1, 2, 3]
reset(s)
doAssert s == @[]
static:
proc f() =
var i = 2
reset(i)
doAssert i == 0
f()