newruntime: progress
This commit is contained in:
parent
3b14f0ed10
commit
b77a2037f8
4 changed files with 18 additions and 12 deletions
|
|
@ -324,7 +324,7 @@ proc isComplexValueType(t: PType): bool {.inline.} =
|
||||||
(t.kind == tyProc and t.callConv == ccClosure)
|
(t.kind == tyProc and t.callConv == ccClosure)
|
||||||
|
|
||||||
proc resetLoc(p: BProc, loc: var TLoc) =
|
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)
|
let typ = skipTypes(loc.t, abstractVarRange)
|
||||||
if isImportedCppType(typ): return
|
if isImportedCppType(typ): return
|
||||||
if p.config.selectedGc == gcDestructors and typ.kind in {tyString, tySequence}:
|
if p.config.selectedGc == gcDestructors and typ.kind in {tyString, tySequence}:
|
||||||
|
|
|
||||||
|
|
@ -263,12 +263,19 @@ proc newSeqCall(g: ModuleGraph; x, y: PNode): PNode =
|
||||||
lenCall.typ = getSysType(g, x.info, tyInt)
|
lenCall.typ = getSysType(g, x.info, tyInt)
|
||||||
result.add lenCall
|
result.add lenCall
|
||||||
|
|
||||||
proc setLenCall(g: ModuleGraph; x, y: PNode; m: TMagic): PNode =
|
proc setLenStrCall(g: ModuleGraph; x, y: PNode): PNode =
|
||||||
let lenCall = genBuiltin(g, mLengthSeq, "len", y)
|
let lenCall = genBuiltin(g, mLengthStr, "len", y)
|
||||||
lenCall.typ = getSysType(g, x.info, tyInt)
|
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
|
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) =
|
proc forallElements(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
let i = declareCounter(c, body, firstOrd(c.graph.config, t))
|
let i = declareCounter(c, body, firstOrd(c.graph.config, t))
|
||||||
let whileLoop = genWhileLoop(c, i, x)
|
let whileLoop = genWhileLoop(c, i, x)
|
||||||
|
|
@ -286,7 +293,7 @@ proc seqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
# var i = 0
|
# var i = 0
|
||||||
# while i < y.len: dest[i] = y[i]; inc(i)
|
# while i < y.len: dest[i] = y[i]; inc(i)
|
||||||
# This is usually more efficient than a destroy/create pair.
|
# 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)
|
forallElements(c, t, body, x, y)
|
||||||
of attachedSink:
|
of attachedSink:
|
||||||
let moveCall = genBuiltin(c.graph, mMove, "move", x)
|
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
|
# var i = 0
|
||||||
# while i < y.len: dest[i] = y[i]; inc(i)
|
# while i < y.len: dest[i] = y[i]; inc(i)
|
||||||
# This is usually more efficient than a destroy/create pair.
|
# 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)
|
forallElements(c, t, body, x, y)
|
||||||
of attachedSink:
|
of attachedSink:
|
||||||
let moveCall = genBuiltin(c.graph, mMove, "move", x)
|
let moveCall = genBuiltin(c.graph, mMove, "move", x)
|
||||||
|
|
|
||||||
|
|
@ -145,8 +145,7 @@ proc setLen[T](s: var seq[T], newlen: Natural) =
|
||||||
if newlen < s.len:
|
if newlen < s.len:
|
||||||
shrink(s, newLen)
|
shrink(s, newLen)
|
||||||
else:
|
else:
|
||||||
var v: T # get the default value of 'v'
|
grow(s, newLen, default(T))
|
||||||
grow(s, newLen, v)
|
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
proc resize[T](s: var NimSeqV2[T]) =
|
proc resize[T](s: var NimSeqV2[T]) =
|
||||||
|
|
|
||||||
|
|
@ -1706,6 +1706,10 @@ proc `@`* [IDX, T](a: array[IDX, T]): seq[T] {.
|
||||||
## echo @a # => @[1, 3, 5]
|
## echo @a # => @[1, 3, 5]
|
||||||
## echo @b # => @['f', 'o', 'o']
|
## 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) {.
|
proc setLen*[T](s: var seq[T], newlen: Natural) {.
|
||||||
magic: "SetLengthSeq", noSideEffect.}
|
magic: "SetLengthSeq", noSideEffect.}
|
||||||
## Sets the length of seq `s` to `newlen`. ``T`` may be any sequence type.
|
## 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.
|
# 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
|
import system/widestrs
|
||||||
export widestrs
|
export widestrs
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue