signature hashing: more progress
This commit is contained in:
parent
72af7e6821
commit
860cbd3107
7 changed files with 301 additions and 300 deletions
|
|
@ -50,7 +50,7 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
|||
of tyUInt64: result = uint64Literal(uint64(n.intVal))
|
||||
else:
|
||||
result = "(($1) $2)" % [getTypeDesc(p.module,
|
||||
skipTypes(ty, abstractVarRange)), intLiteral(n.intVal)]
|
||||
ty), intLiteral(n.intVal)]
|
||||
of nkNilLit:
|
||||
let t = skipTypes(ty, abstractVarRange)
|
||||
if t.kind == tyProc and t.callConv == ccClosure:
|
||||
|
|
@ -61,7 +61,7 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
|||
inc(p.module.labels)
|
||||
addf(p.module.s[cfsData],
|
||||
"static NIM_CONST $1 $2 = {NIM_NIL,NIM_NIL};$n",
|
||||
[getTypeDesc(p.module, t), result])
|
||||
[getTypeDesc(p.module, ty), result])
|
||||
else:
|
||||
result = rope("NIM_NIL")
|
||||
of nkStrLit..nkTripleStrLit:
|
||||
|
|
@ -266,7 +266,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
|||
# little HACK to support the new 'var T' as return type:
|
||||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
||||
return
|
||||
var ty = skipTypes(dest.t, abstractRange)
|
||||
let ty = skipTypes(dest.t, abstractRange)
|
||||
case ty.kind
|
||||
of tyRef:
|
||||
genRefAssign(p, dest, src, flags)
|
||||
|
|
@ -315,8 +315,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
|||
genGenericAsgn(p, dest, src, flags)
|
||||
elif needsComplexAssignment(ty):
|
||||
if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4:
|
||||
discard getTypeDesc(p.module, ty)
|
||||
ty = getUniqueType(ty)
|
||||
discard getTypeDesc(p.module, dest.t)
|
||||
internalAssert ty.n != nil
|
||||
genOptAsgnObject(p, dest, src, flags, ty.n)
|
||||
else:
|
||||
|
|
@ -330,7 +329,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
|||
useStringh(p.module)
|
||||
linefmt(p, cpsStmts,
|
||||
"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
|
||||
rdLoc(dest), rdLoc(src), getTypeDesc(p.module, ty))
|
||||
rdLoc(dest), rdLoc(src), getTypeDesc(p.module, dest.t))
|
||||
of tyOpenArray, tyVarargs:
|
||||
# open arrays are always on the stack - really? What if a sequence is
|
||||
# passed to an open array?
|
||||
|
|
@ -494,12 +493,12 @@ proc binaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
|||
# later via 'chckRange'
|
||||
let t = e.typ.skipTypes(abstractRange)
|
||||
if optOverflowCheck notin p.options:
|
||||
let res = opr[m] % [getTypeDesc(p.module, t), rdLoc(a), rdLoc(b)]
|
||||
let res = opr[m] % [getTypeDesc(p.module, e.typ), rdLoc(a), rdLoc(b)]
|
||||
putIntoDest(p, d, e.typ, res)
|
||||
else:
|
||||
let res = binaryArithOverflowRaw(p, t, a, b,
|
||||
if t.kind == tyInt64: prc64[m] else: prc[m])
|
||||
putIntoDest(p, d, e.typ, "($#)($#)" % [getTypeDesc(p.module, t), res])
|
||||
putIntoDest(p, d, e.typ, "($#)($#)" % [getTypeDesc(p.module, e.typ), res])
|
||||
|
||||
proc unaryArithOverflow(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
|
||||
const
|
||||
|
|
@ -700,12 +699,11 @@ proc genAddr(p: BProc, e: PNode, d: var TLoc) =
|
|||
template inheritLocation(d: var TLoc, a: TLoc) =
|
||||
if d.k == locNone: d.s = a.s
|
||||
|
||||
proc genRecordFieldAux(p: BProc, e: PNode, d, a: var TLoc): PType =
|
||||
proc genRecordFieldAux(p: BProc, e: PNode, d, a: var TLoc) =
|
||||
initLocExpr(p, e.sons[0], a)
|
||||
if e.sons[1].kind != nkSym: internalError(e.info, "genRecordFieldAux")
|
||||
d.inheritLocation(a)
|
||||
discard getTypeDesc(p.module, a.t) # fill the record's fields.loc
|
||||
result = a.t.getUniqueType
|
||||
|
||||
proc genTupleElem(p: BProc, e: PNode, d: var TLoc) =
|
||||
var
|
||||
|
|
@ -714,13 +712,12 @@ proc genTupleElem(p: BProc, e: PNode, d: var TLoc) =
|
|||
initLocExpr(p, e.sons[0], a)
|
||||
d.inheritLocation(a)
|
||||
discard getTypeDesc(p.module, a.t) # fill the record's fields.loc
|
||||
var ty = a.t.getUniqueType
|
||||
var r = rdLoc(a)
|
||||
case e.sons[1].kind
|
||||
of nkIntLit..nkUInt64Lit: i = int(e.sons[1].intVal)
|
||||
else: internalError(e.info, "genTupleElem")
|
||||
addf(r, ".Field$1", [rope(i)])
|
||||
putIntoDest(p, d, ty.sons[i], r, a.s)
|
||||
putIntoDest(p, d, a.t.sons[i], r, a.s)
|
||||
|
||||
proc lookupFieldAgain(p: BProc, ty: PType; field: PSym; r: var Rope): PSym =
|
||||
var ty = ty
|
||||
|
|
@ -731,14 +728,15 @@ proc lookupFieldAgain(p: BProc, ty: PType; field: PSym; r: var Rope): PSym =
|
|||
result = lookupInRecord(ty.n, field.name)
|
||||
if result != nil: break
|
||||
if not p.module.compileToCpp: add(r, ".Sup")
|
||||
ty = getUniqueType(ty.sons[0])
|
||||
ty = ty.sons[0]
|
||||
if result == nil: internalError(field.info, "genCheckedRecordField")
|
||||
|
||||
proc genRecordField(p: BProc, e: PNode, d: var TLoc) =
|
||||
var a: TLoc
|
||||
var ty = genRecordFieldAux(p, e, d, a)
|
||||
genRecordFieldAux(p, e, d, a)
|
||||
var r = rdLoc(a)
|
||||
var f = e.sons[1].sym
|
||||
let ty = skipTypes(a.t, abstractInst)
|
||||
if ty.kind == tyTuple:
|
||||
# we found a unique tuple type which lacks field information
|
||||
# so we use Field$i
|
||||
|
|
@ -746,7 +744,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) =
|
|||
putIntoDest(p, d, f.typ, r, a.s)
|
||||
else:
|
||||
let field = lookupFieldAgain(p, ty, f, r)
|
||||
if field.loc.r == nil: internalError(e.info, "genRecordField 3")
|
||||
if field.loc.r == nil: internalError(e.info, "genRecordField 3 " & typeToString(ty))
|
||||
addf(r, ".$1", [field.loc.r])
|
||||
putIntoDest(p, d, field.typ, r, a.s)
|
||||
#d.s = a.s
|
||||
|
|
@ -789,7 +787,8 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym;
|
|||
proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) =
|
||||
if optFieldCheck in p.options:
|
||||
var a: TLoc
|
||||
let ty = genRecordFieldAux(p, e.sons[0], d, a)
|
||||
genRecordFieldAux(p, e.sons[0], d, a)
|
||||
let ty = skipTypes(a.t, abstractInst)
|
||||
var r = rdLoc(a)
|
||||
let f = e.sons[0].sons[1].sym
|
||||
let field = lookupFieldAgain(p, ty, f, r)
|
||||
|
|
@ -1029,10 +1028,10 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
|||
var a, b, dest: TLoc
|
||||
initLocExpr(p, e.sons[1], a)
|
||||
initLocExpr(p, e.sons[2], b)
|
||||
let bt = skipTypes(e.sons[2].typ, abstractVar)
|
||||
let bt = skipTypes(e.sons[2].typ, {tyVar})
|
||||
lineCg(p, cpsStmts, seqAppendPattern, [
|
||||
rdLoc(a),
|
||||
getTypeDesc(p.module, skipTypes(e.sons[1].typ, abstractVar)),
|
||||
getTypeDesc(p.module, e.sons[1].typ),
|
||||
getTypeDesc(p.module, bt)])
|
||||
#if bt != b.t:
|
||||
# echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t)
|
||||
|
|
@ -1046,16 +1045,17 @@ proc genReset(p: BProc, n: PNode) =
|
|||
var a: TLoc
|
||||
initLocExpr(p, n.sons[1], a)
|
||||
linefmt(p, cpsStmts, "#genericReset((void*)$1, $2);$n",
|
||||
addrLoc(a), genTypeInfo(p.module, skipTypes(a.t, abstractVarRange)))
|
||||
addrLoc(a), genTypeInfo(p.module, skipTypes(a.t, {tyVar})))
|
||||
|
||||
proc rawGenNew(p: BProc, a: TLoc, sizeExpr: Rope) =
|
||||
var sizeExpr = sizeExpr
|
||||
let refType = skipTypes(a.t, abstractVarRange)
|
||||
let refType = a.t
|
||||
var b: TLoc
|
||||
initLoc(b, locExpr, a.t, OnHeap)
|
||||
let bt = refType.lastSon
|
||||
if sizeExpr.isNil:
|
||||
sizeExpr = "sizeof($1)" %
|
||||
[getTypeDesc(p.module, skipTypes(refType.sons[0], abstractRange))]
|
||||
[getTypeDesc(p.module, bt)]
|
||||
let args = [getTypeDesc(p.module, refType),
|
||||
genTypeInfo(p.module, refType),
|
||||
sizeExpr]
|
||||
|
|
@ -1070,7 +1070,6 @@ proc rawGenNew(p: BProc, a: TLoc, sizeExpr: Rope) =
|
|||
else:
|
||||
b.r = ropecg(p.module, "($1) #newObj($2, $3)", args)
|
||||
genAssignment(p, a, b, {}) # set the object type:
|
||||
let bt = skipTypes(refType.sons[0], abstractRange)
|
||||
genObjectInit(p, cpsStmts, bt, a, false)
|
||||
|
||||
proc genNew(p: BProc, e: PNode) =
|
||||
|
|
@ -1122,7 +1121,7 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) =
|
|||
proc genConstExpr(p: BProc, n: PNode): Rope
|
||||
proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
|
||||
if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr:
|
||||
var t = getUniqueType(n.typ)
|
||||
let t = n.typ
|
||||
discard getTypeDesc(p.module, t) # so that any fields are initialized
|
||||
let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels)
|
||||
fillLoc(d, locData, t, p.module.tmpBase & rope(id), OnStatic)
|
||||
|
|
@ -1322,7 +1321,7 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) =
|
|||
gcUsage(e)
|
||||
|
||||
proc genGetTypeInfo(p: BProc, e: PNode, d: var TLoc) =
|
||||
var t = skipTypes(e.sons[1].typ, abstractVarRange)
|
||||
let t = e.sons[1].typ
|
||||
putIntoDest(p, d, e.typ, genTypeInfo(p.module, t))
|
||||
|
||||
proc genDollar(p: BProc, n: PNode, d: var TLoc, frmt: string) =
|
||||
|
|
@ -1336,7 +1335,7 @@ proc genDollar(p: BProc, n: PNode, d: var TLoc, frmt: string) =
|
|||
proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||
var a = e.sons[1]
|
||||
if a.kind == nkHiddenAddr: a = a.sons[0]
|
||||
var typ = skipTypes(a.typ, abstractVar)
|
||||
let typ = skipTypes(a.typ, abstractVar)
|
||||
case typ.kind
|
||||
of tyOpenArray, tyVarargs:
|
||||
if op == mHigh: unaryExpr(p, e, d, "($1Len0-1)")
|
||||
|
|
@ -1363,7 +1362,7 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
|||
assert(d.k == locNone)
|
||||
initLocExpr(p, e.sons[1], a)
|
||||
initLocExpr(p, e.sons[2], b)
|
||||
var t = skipTypes(e.sons[1].typ, abstractVar)
|
||||
let t = skipTypes(e.sons[1].typ, {tyVar})
|
||||
let setLenPattern = if not p.module.compileToCpp:
|
||||
"$1 = ($3) #setLengthSeq(&($1)->Sup, sizeof($4), $2);$n"
|
||||
else:
|
||||
|
|
@ -1371,7 +1370,7 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
|||
|
||||
lineCg(p, cpsStmts, setLenPattern, [
|
||||
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
|
||||
getTypeDesc(p.module, t.sons[0])])
|
||||
getTypeDesc(p.module, t.skipTypes(abstractInst).sons[0])])
|
||||
gcUsage(e)
|
||||
|
||||
proc genSetLengthStr(p: BProc, e: PNode, d: var TLoc) =
|
||||
|
|
@ -1562,7 +1561,7 @@ proc genCast(p: BProc, e: PNode, d: var TLoc) =
|
|||
var tmp: TLoc
|
||||
tmp.r = "LOC$1.source" % [lbl]
|
||||
linefmt(p, cpsLocals, "union { $1 source; $2 dest; } LOC$3;$n",
|
||||
getTypeDesc(p.module, srct), getTypeDesc(p.module, destt), lbl)
|
||||
getTypeDesc(p.module, e.sons[1].typ), getTypeDesc(p.module, e.typ), lbl)
|
||||
tmp.k = locExpr
|
||||
tmp.t = srct
|
||||
tmp.s = OnStack
|
||||
|
|
@ -1796,7 +1795,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) =
|
|||
proc genTupleConstr(p: BProc, n: PNode, d: var TLoc) =
|
||||
var rec: TLoc
|
||||
if not handleConstExpr(p, n, d):
|
||||
var t = getUniqueType(n.typ)
|
||||
let t = n.typ
|
||||
discard getTypeDesc(p.module, t) # so that any fields are initialized
|
||||
if d.k == locNone: getTemp(p, t, d)
|
||||
for i in countup(0, sonsLen(n) - 1):
|
||||
|
|
@ -1805,11 +1804,6 @@ proc genTupleConstr(p: BProc, n: PNode, d: var TLoc) =
|
|||
initLoc(rec, locExpr, it.typ, d.s)
|
||||
rec.r = "$1.Field$2" % [rdLoc(d), rope(i)]
|
||||
expr(p, it, rec)
|
||||
when false:
|
||||
initLoc(rec, locExpr, it.typ, d.s)
|
||||
if (t.n.sons[i].kind != nkSym): InternalError(n.info, "genTupleConstr")
|
||||
rec.r = "$1.$2" % [rdLoc(d), mangleRecFieldName(t.n.sons[i].sym, t)]
|
||||
expr(p, it, rec)
|
||||
|
||||
proc isConstClosure(n: PNode): bool {.inline.} =
|
||||
result = n.sons[0].kind == nkSym and isRoutine(n.sons[0].sym) and
|
||||
|
|
@ -1863,7 +1857,7 @@ proc genStmtListExpr(p: BProc, n: PNode, d: var TLoc) =
|
|||
proc upConv(p: BProc, n: PNode, d: var TLoc) =
|
||||
var a: TLoc
|
||||
initLocExpr(p, n.sons[0], a)
|
||||
var dest = skipTypes(n.typ, abstractPtrs)
|
||||
let dest = skipTypes(n.typ, abstractPtrs)
|
||||
if optObjCheck in p.options and not isObjLackingTypeField(dest):
|
||||
var r = rdLoc(a)
|
||||
var nilCheck: Rope = nil
|
||||
|
|
@ -1925,7 +1919,7 @@ proc downConv(p: BProc, n: PNode, d: var TLoc) =
|
|||
putIntoDest(p, d, n.typ, r, a.s)
|
||||
|
||||
proc exprComplexConst(p: BProc, n: PNode, d: var TLoc) =
|
||||
var t = getUniqueType(n.typ)
|
||||
let t = n.typ
|
||||
discard getTypeDesc(p.module, t) # so that any fields are initialized
|
||||
let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels)
|
||||
let tmp = p.module.tmpBase & rope(id)
|
||||
|
|
@ -2161,13 +2155,14 @@ proc genConstSeq(p: BProc, n: PNode, t: PType): Rope =
|
|||
data.add("}")
|
||||
|
||||
result = getTempName(p.module)
|
||||
let base = t.skipTypes(abstractInst).sons[0]
|
||||
|
||||
appcg(p.module, cfsData,
|
||||
"NIM_CONST struct {$n" &
|
||||
" #TGenericSeq Sup;$n" &
|
||||
" $1 data[$2];$n" &
|
||||
"} $3 = $4;$n", [
|
||||
getTypeDesc(p.module, t.sons[0]), n.len.rope, result, data])
|
||||
getTypeDesc(p.module, base), n.len.rope, result, data])
|
||||
|
||||
result = "(($1)&$2)" % [getTypeDesc(p.module, t), result]
|
||||
|
||||
|
|
@ -2182,7 +2177,7 @@ proc genConstExpr(p: BProc, n: PNode): Rope =
|
|||
of nkBracket, nkPar, nkClosure, nkObjConstr:
|
||||
var t = skipTypes(n.typ, abstractInst)
|
||||
if t.kind == tySequence:
|
||||
result = genConstSeq(p, n, t)
|
||||
result = genConstSeq(p, n, n.typ)
|
||||
else:
|
||||
result = genConstSimpleList(p, n)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue