newruntime: progress

This commit is contained in:
Araq
2019-04-02 00:46:38 +02:00
parent 3b14f0ed10
commit b77a2037f8
4 changed files with 18 additions and 12 deletions

View File

@@ -324,7 +324,7 @@ proc isComplexValueType(t: PType): bool {.inline.} =
(t.kind == tyProc and t.callConv == ccClosure)
proc resetLoc(p: BProc, loc: var TLoc) =
let containsGcRef = containsGarbageCollectedRef(loc.t)
let containsGcRef = p.config.selectedGc != gcDestructors and containsGarbageCollectedRef(loc.t)
let typ = skipTypes(loc.t, abstractVarRange)
if isImportedCppType(typ): return
if p.config.selectedGc == gcDestructors and typ.kind in {tyString, tySequence}:

View File

@@ -263,12 +263,19 @@ proc newSeqCall(g: ModuleGraph; x, y: PNode): PNode =
lenCall.typ = getSysType(g, x.info, tyInt)
result.add lenCall
proc setLenCall(g: ModuleGraph; x, y: PNode; m: TMagic): PNode =
let lenCall = genBuiltin(g, mLengthSeq, "len", y)
proc setLenStrCall(g: ModuleGraph; x, y: PNode): PNode =
let lenCall = genBuiltin(g, mLengthStr, "len", y)
lenCall.typ = getSysType(g, x.info, tyInt)
result = genBuiltin(g, m, "setLen", genAddr(g, x))
result = genBuiltin(g, mSetLengthStr, "setLen", genAddr(g, x))
result.add lenCall
proc setLenSeqCall(c: var TLiftCtx; t: PType; x, y: PNode): PNode =
let lenCall = genBuiltin(c.graph, mLengthSeq, "len", y)
lenCall.typ = getSysType(c.graph, x.info, tyInt)
var op = getSysMagic(c.graph, x.info, "setLen", mSetLengthSeq)
op = c.c.instTypeBoundOp(c.c, op, t, c.info, attachedAsgn, 1)
result = newTree(nkCall, newSymNode(op, x.info), genAddr(c.graph, x), lenCall)
proc forallElements(c: var TLiftCtx; t: PType; body, x, y: PNode) =
let i = declareCounter(c, body, firstOrd(c.graph.config, t))
let whileLoop = genWhileLoop(c, i, x)
@@ -286,7 +293,7 @@ proc seqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
# var i = 0
# while i < y.len: dest[i] = y[i]; inc(i)
# This is usually more efficient than a destroy/create pair.
body.add setLenCall(c.graph, x, y, mSetLengthSeq)
body.add setLenSeqCall(c, t, x, y)
forallElements(c, t, body, x, y)
of attachedSink:
let moveCall = genBuiltin(c.graph, mMove, "move", x)
@@ -307,7 +314,7 @@ proc strOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
# var i = 0
# while i < y.len: dest[i] = y[i]; inc(i)
# This is usually more efficient than a destroy/create pair.
body.add setLenCall(c.graph, x, y, mSetLengthStr)
body.add setLenStrCall(c.graph, x, y)
forallElements(c, t, body, x, y)
of attachedSink:
let moveCall = genBuiltin(c.graph, mMove, "move", x)

View File

@@ -145,8 +145,7 @@ proc setLen[T](s: var seq[T], newlen: Natural) =
if newlen < s.len:
shrink(s, newLen)
else:
var v: T # get the default value of 'v'
grow(s, newLen, v)
grow(s, newLen, default(T))
when false:
proc resize[T](s: var NimSeqV2[T]) =

View File

@@ -1706,6 +1706,10 @@ proc `@`* [IDX, T](a: array[IDX, T]): seq[T] {.
## echo @a # => @[1, 3, 5]
## echo @b # => @['f', 'o', 'o']
when defined(nimHasDefault):
proc default*(T: typedesc): T {.magic: "Default", noSideEffect.}
## returns the default value of the type ``T``.
proc setLen*[T](s: var seq[T], newlen: Natural) {.
magic: "SetLengthSeq", noSideEffect.}
## Sets the length of seq `s` to `newlen`. ``T`` may be any sequence type.
@@ -4400,10 +4404,6 @@ when defined(genode):
# and return to thread entrypoint.
when defined(nimHasDefault):
proc default*(T: typedesc): T {.magic: "Default", noSideEffect.}
## returns the default value of the type ``T``.
import system/widestrs
export widestrs