fixes 7833 (#8533)
* fixes #7833; still to-do: fix setLen * make tests green again * also fixes setLen and string concats; refs #7833 * change formating to avoid a compiler warning * emit the write barrier also for addChar * fixes yet another regression * make setLengthStr compile for the old version * make growobjcrash complete earlier
This commit is contained in:
parent
cc1fd50b27
commit
c57e320c94
7 changed files with 114 additions and 29 deletions
|
|
@ -1063,7 +1063,7 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
|||
# appendChar(s, 'z');
|
||||
# }
|
||||
var
|
||||
a, dest: TLoc
|
||||
a, dest, call: TLoc
|
||||
appends, lens: Rope
|
||||
assert(d.k == locNone)
|
||||
var L = 0
|
||||
|
|
@ -1082,8 +1082,9 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
|||
addf(lens, "($1 ? $1->$2 : 0) + ", [rdLoc(a), lenField(p)])
|
||||
add(appends, ropecg(p.module, "#appendString($1, $2);$n",
|
||||
rdLoc(dest), rdLoc(a)))
|
||||
linefmt(p, cpsStmts, "$1 = #resizeString($1, $2$3);$n",
|
||||
rdLoc(dest), lens, rope(L))
|
||||
initLoc(call, locCall, e, OnHeap)
|
||||
call.r = ropecg(p.module, "#resizeString($1, $2$3)", [rdLoc(dest), lens, rope(L)])
|
||||
genAssignment(p, dest, call, {})
|
||||
add(p.s(cpsStmts), appends)
|
||||
gcUsage(p.config, e)
|
||||
|
||||
|
|
@ -1092,17 +1093,20 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
|||
# seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x));
|
||||
# seq->data[seq->len-1] = x;
|
||||
let seqAppendPattern = if not p.module.compileToCpp:
|
||||
"$1 = ($2) #incrSeqV3(&($1)->Sup, $3);$n"
|
||||
"($2) #incrSeqV3(&($1)->Sup, $3)"
|
||||
else:
|
||||
"$1 = ($2) #incrSeqV3($1, $3);$n"
|
||||
var a, b, dest, tmpL: TLoc
|
||||
"($2) #incrSeqV3($1, $3)"
|
||||
var a, b, dest, tmpL, call: TLoc
|
||||
initLocExpr(p, e.sons[1], a)
|
||||
initLocExpr(p, e.sons[2], b)
|
||||
let seqType = skipTypes(e.sons[1].typ, {tyVar})
|
||||
lineCg(p, cpsStmts, seqAppendPattern, [
|
||||
rdLoc(a),
|
||||
getTypeDesc(p.module, e.sons[1].typ),
|
||||
genTypeInfo(p.module, seqType, e.info)])
|
||||
initLoc(call, locCall, e, OnHeap)
|
||||
call.r = ropecg(p.module, seqAppendPattern, [rdLoc(a),
|
||||
getTypeDesc(p.module, e.sons[1].typ),
|
||||
genTypeInfo(p.module, seqType, e.info)])
|
||||
# emit the write barrier if required, but we can always move here, so
|
||||
# use 'genRefAssign' for the seq.
|
||||
genRefAssign(p, a, call, {})
|
||||
#if bt != b.t:
|
||||
# echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t)
|
||||
initLoc(dest, locExpr, e.sons[2], OnHeap)
|
||||
|
|
@ -1509,7 +1513,7 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
|||
else: internalError(p.config, e.info, "genArrayLen()")
|
||||
|
||||
proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
||||
var a, b: TLoc
|
||||
var a, b, call: TLoc
|
||||
assert(d.k == locNone)
|
||||
var x = e.sons[1]
|
||||
if x.kind in {nkAddr, nkHiddenAddr}: x = x[0]
|
||||
|
|
@ -1517,17 +1521,27 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
|||
initLocExpr(p, e.sons[2], b)
|
||||
let t = skipTypes(e.sons[1].typ, {tyVar})
|
||||
let setLenPattern = if not p.module.compileToCpp:
|
||||
"$1 = ($3) #setLengthSeqV2(&($1)->Sup, $4, $2);$n"
|
||||
"($3) #setLengthSeqV2(&($1)->Sup, $4, $2)"
|
||||
else:
|
||||
"$1 = ($3) #setLengthSeqV2($1, $4, $2);$n"
|
||||
"($3) #setLengthSeqV2($1, $4, $2)"
|
||||
|
||||
lineCg(p, cpsStmts, setLenPattern, [
|
||||
initLoc(call, locCall, e, OnHeap)
|
||||
call.r = ropecg(p.module, setLenPattern, [
|
||||
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
|
||||
genTypeInfo(p.module, t.skipTypes(abstractInst), e.info)])
|
||||
genAssignment(p, a, call, {})
|
||||
gcUsage(p.config, e)
|
||||
|
||||
proc genSetLengthStr(p: BProc, e: PNode, d: var TLoc) =
|
||||
binaryStmt(p, e, d, "$1 = #setLengthStr($1, $2);$n")
|
||||
var a, b, call: TLoc
|
||||
if d.k != locNone: internalError(p.config, e.info, "genSetLengthStr")
|
||||
initLocExpr(p, e.sons[1], a)
|
||||
initLocExpr(p, e.sons[2], b)
|
||||
|
||||
initLoc(call, locCall, e, OnHeap)
|
||||
call.r = ropecg(p.module, "#setLengthStr($1, $2)", [
|
||||
rdLoc(a), rdLoc(b)])
|
||||
genAssignment(p, a, call, {})
|
||||
gcUsage(p.config, e)
|
||||
|
||||
proc genSwap(p: BProc, e: PNode, d: var TLoc) =
|
||||
|
|
@ -1844,7 +1858,13 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
|||
getTypeDesc(p.module, ranged), res])
|
||||
|
||||
of mConStrStr: genStrConcat(p, e, d)
|
||||
of mAppendStrCh: binaryStmt(p, e, d, "$1 = #addChar($1, $2);$n")
|
||||
of mAppendStrCh:
|
||||
var dest, b, call: TLoc
|
||||
initLoc(call, locCall, e, OnHeap)
|
||||
initLocExpr(p, e.sons[1], dest)
|
||||
initLocExpr(p, e.sons[2], b)
|
||||
call.r = ropecg(p.module, "#addChar($1, $2)", [rdLoc(dest), rdLoc(b)])
|
||||
genAssignment(p, dest, call, {})
|
||||
of mAppendStrStr: genStrAppend(p, e, d)
|
||||
of mAppendSeqElem: genSeqElemAppend(p, e, d)
|
||||
of mEqStr: genStrEquals(p, e, d)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue