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 | |
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')
-rw-r--r-- | compiler/ast.nim | 2 | ||||
-rw-r--r-- | compiler/ccgexprs.nim | 4 | ||||
-rw-r--r-- | compiler/condsyms.nim | 1 | ||||
-rw-r--r-- | compiler/vmgen.nim | 22 |
4 files changed, 19 insertions, 10 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 607b497fb..b325e6d42 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -635,7 +635,7 @@ type mSwap, mIsNil, mArrToSeq, mCopyStr, mCopyStrLast, mNewString, mNewStringOfCap, mParseBiggestFloat, mMove, mWasMoved, mDestroy, - mReset, + mDefault, mReset, mArray, mOpenArray, mRange, mSet, mSeq, mOpt, mVarargs, mRef, mPtr, mVar, mDistinct, mVoid, mTuple, mOrdinal, diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 99b658d46..406528845 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1153,6 +1153,9 @@ proc genReset(p: BProc, n: PNode) = addrLoc(p.config, a), genTypeInfo(p.module, skipTypes(a.t, {tyVar}), n.info)) +proc genDefault(p: BProc; n: PNode; d: var TLoc) = + resetLoc(p, d) + proc rawGenNew(p: BProc, a: TLoc, sizeExpr: Rope) = var sizeExpr = sizeExpr let typ = a.t @@ -2063,6 +2066,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = addf(p.module.s[cfsDynLibInit], "\t$1 = ($2) hcrGetProc($3, \"$1\");$n", [mangleDynLibProc(prc), getTypeDesc(p.module, prc.loc.t), getModuleDllPath(p.module, prc)]) genCall(p, e, d) + of mDefault: genDefault(p, e, d) of mReset: genReset(p, e) of mEcho: genEcho(p, e[1].skipConv) of mArrToSeq: genArrToSeq(p, e, d) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 57dd55132..15127e108 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -85,6 +85,7 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimHasHotCodeReloading") defineSymbol("nimHasNilSeqs") defineSymbol("nimHasSignatureHashInMacro") + defineSymbol("nimHasDefault") for f in low(Feature)..high(Feature): defineSymbol("nimHas" & $f) 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 |