Support system.reset in vm (#10400)

(cherry picked from commit a4cdd25b19)
This commit is contained in:
Oscar Nihlgård
2019-01-21 17:00:33 +01:00
committed by narimiran
parent 56b26966c8
commit ba68025ce5
4 changed files with 32 additions and 4 deletions

View File

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

View File

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

View File

@@ -1063,7 +1063,9 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
of mReset:
unused(c, n, dest)
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:
if dest < 0: dest = c.getTemp(n.typ)
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()