diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-03-05 09:54:59 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-03-05 09:54:59 +0100 |
commit | 142a2d355123155fb6ef600f269687703e554224 (patch) | |
tree | beab41551e33d59601fea19d3a210ef56c1d2dbd /compiler/vmgen.nim | |
parent | 2dc8a323242b639875d24d1baa7c8c9da2055fe2 (diff) | |
download | Nim-142a2d355123155fb6ef600f269687703e554224.tar.gz |
added system.default in order to prevent the abstraction inversion that 'template default(T): untyped = (var x: T; x)' causes
Diffstat (limited to 'compiler/vmgen.nim')
-rw-r--r-- | compiler/vmgen.nim | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 092c25a46..2d9166be0 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -910,6 +910,15 @@ proc genBindSym(c: PCtx; n: PNode; dest: var TDest) = c.gABC(n, opcNDynBindSym, dest, x, n.len) c.freeTempRange(x, n.len) +proc fitsRegister*(t: PType): bool = + assert t != nil + t.skipTypes(abstractInst-{tyTypeDesc}).kind in { + tyRange, tyEnum, tyBool, tyInt..tyUInt64, tyChar} + +proc ldNullOpcode(t: PType): TOpcode = + assert t != nil + if fitsRegister(t): opcLdNullReg else: opcLdNull + proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = case m of mAnd: c.genAndOr(n, opcFJmp, dest) @@ -1129,9 +1138,13 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = of mReset: unused(c, n, dest) var d = c.genx(n.sons[1]) + # XXX use ldNullOpcode() here? c.gABx(n, opcLdNull, d, c.genType(n.sons[1].typ)) c.gABx(n, opcNodeToReg, d, d) c.genAsgnPatch(n.sons[1], d) + of mDefault: + if dest < 0: dest = c.getTemp(n.typ) + c.gABx(n, ldNullOpcode(n.typ), dest, c.genType(n.typ)) of mOf, mIs: if dest < 0: dest = c.getTemp(n.typ) var tmp = c.genx(n.sons[1]) @@ -1332,11 +1345,6 @@ const tyFloat, tyFloat32, tyFloat64, tyFloat128, tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64} -proc fitsRegister*(t: PType): bool = - assert t != nil - t.skipTypes(abstractInst-{tyTypeDesc}).kind in { - tyRange, tyEnum, tyBool, tyInt..tyUInt64, tyChar} - proc unneededIndirection(n: PNode): bool = n.typ.skipTypes(abstractInstOwned-{tyTypeDesc}).kind == tyRef @@ -1766,10 +1774,6 @@ proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode = globalError(conf, info, "cannot create null element for: " & $t.kind) result = newNodeI(nkEmpty, info) -proc ldNullOpcode(t: PType): TOpcode = - assert t != nil - if fitsRegister(t): opcLdNullReg else: opcLdNull - proc genVarSection(c: PCtx; n: PNode) = for a in n: if a.kind == nkCommentStmt: continue |