diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 11 | ||||
-rw-r--r-- | compiler/ccgexprs.nim | 102 | ||||
-rw-r--r-- | compiler/cgen.nim | 2 | ||||
-rw-r--r-- | compiler/condsyms.nim | 1 | ||||
-rw-r--r-- | compiler/filter_tmpl.nim | 4 | ||||
-rw-r--r-- | compiler/jstypes.nim | 5 | ||||
-rw-r--r-- | compiler/parampatterns.nim | 5 | ||||
-rw-r--r-- | compiler/semfold.nim | 2 | ||||
-rw-r--r-- | compiler/seminst.nim | 3 | ||||
-rw-r--r-- | compiler/semstmts.nim | 2 | ||||
-rw-r--r-- | compiler/semtempl.nim | 36 | ||||
-rw-r--r-- | compiler/semtypes.nim | 1 | ||||
-rw-r--r-- | compiler/syntaxes.nim | 7 | ||||
-rw-r--r-- | compiler/vm.nim | 2 | ||||
-rw-r--r-- | compiler/writetracking.nim | 2 |
15 files changed, 98 insertions, 87 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 177b5c5c7..860bf67e8 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -537,7 +537,7 @@ const type TMagic* = enum # symbols that require compiler magic: mNone, - mDefined, mDefinedInScope, mCompiles, + mDefined, mDefinedInScope, mCompiles, mArrGet, mArrPut, mAsgn, mLow, mHigh, mSizeOf, mTypeTrait, mIs, mOf, mAddr, mTypeOf, mRoof, mPlugin, mEcho, mShallowCopy, mSlurp, mStaticExec, mParseExprToAst, mParseStmtToAst, mExpandToAst, mQuoteAst, @@ -614,6 +614,7 @@ const ctfeWhitelist* = {mNone, mUnaryLt, mSucc, mPred, mInc, mDec, mOrd, mLengthOpenArray, mLengthStr, mLengthArray, mLengthSeq, mXLenStr, mXLenSeq, + mArrGet, mArrPut, mAsgn, mIncl, mExcl, mCard, mChr, mAddI, mSubI, mMulI, mDivI, mModI, mAddF64, mSubF64, mMulF64, mDivF64, @@ -709,6 +710,7 @@ type lfSingleUse # no location yet and will only be used once TStorageLoc* = enum OnUnknown, # location is unknown (stack, heap or static) + OnStatic, # in a static section OnStack, # location is on hardware stack OnHeap # location is on heap or global # (reference counting needed) @@ -1585,3 +1587,10 @@ proc createMagic*(name: string, m: TMagic): PSym = let opNot* = createMagic("not", mNot) opContains* = createMagic("contains", mInSet) + +when false: + proc containsNil*(n: PNode): bool = + # only for debugging + if n.isNil: return true + for i in 0 ..< n.safeLen: + if n[i].containsNil: return true diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index ba8ced52a..54063229f 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -221,7 +221,7 @@ proc optAsgnLoc(a: TLoc, t: PType, field: Rope): TLoc = proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = let newflags = - if src.k == locData: + if src.s == OnStatic: flags + {needToCopy} elif tfShallow in dest.t.flags: flags - {needToCopy} @@ -238,7 +238,7 @@ proc genOptAsgnObject(p: BProc, dest, src: TLoc, flags: TAssignmentFlags, t: PNode) = if t == nil: return let newflags = - if src.k == locData: + if src.s == OnStatic: flags + {needToCopy} elif tfShallow in dest.t.flags: flags - {needToCopy} @@ -287,13 +287,13 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = of tyRef: genRefAssign(p, dest, src, flags) of tySequence: - if needToCopy notin flags and src.k != locData: + if needToCopy notin flags and src.s != OnStatic: genRefAssign(p, dest, src, flags) else: linefmt(p, cpsStmts, "#genericSeqAssign($1, $2, $3);$n", addrLoc(dest), rdLoc(src), genTypeInfo(p.module, dest.t)) of tyString: - if needToCopy notin flags and src.k != locData: + if needToCopy notin flags and src.s != OnStatic: genRefAssign(p, dest, src, flags) else: if dest.s == OnStack or not usesNativeGC(): @@ -413,7 +413,7 @@ proc putDataIntoDest(p: BProc, d: var TLoc, t: PType, r: Rope) = var a: TLoc if d.k != locNone: # need to generate an assignment here - initLoc(a, locData, t, OnUnknown) + initLoc(a, locData, t, OnStatic) a.r = r if lfNoDeepCopy in d.flags: genAssignment(p, d, a, {}) else: genAssignment(p, d, a, {needToCopy}) @@ -424,11 +424,11 @@ proc putDataIntoDest(p: BProc, d: var TLoc, t: PType, r: Rope) = d.t = t d.r = r -proc putIntoDest(p: BProc, d: var TLoc, t: PType, r: Rope) = +proc putIntoDest(p: BProc, d: var TLoc, t: PType, r: Rope; s=OnUnknown) = var a: TLoc if d.k != locNone: # need to generate an assignment here - initLoc(a, locExpr, t, OnUnknown) + initLoc(a, locExpr, t, s) a.r = r if lfNoDeepCopy in d.flags: genAssignment(p, d, a, {}) else: genAssignment(p, d, a, {needToCopy}) @@ -685,7 +685,7 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) = d.s = OnUnknown if tfVarIsPtr notin typ.flags and p.module.compileToCpp and e.kind == nkHiddenDeref: - putIntoDest(p, d, e.typ, rdLoc(a)) + putIntoDest(p, d, e.typ, rdLoc(a), a.s) return of tyPtr: d.s = OnUnknown # BUGFIX! @@ -694,7 +694,7 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) = let typ = skipTypes(a.t, abstractInst) if typ.kind == tyVar and tfVarIsPtr notin typ.flags and e.kind == nkHiddenDeref: - putIntoDest(p, d, e.typ, rdLoc(a)) + putIntoDest(p, d, e.typ, rdLoc(a), a.s) return if enforceDeref and mt == ctPtrToArray: # we lie about the type for better C interop: 'ptr array[3,T]' is @@ -702,23 +702,23 @@ proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) = # See tmissingderef. So we get rid of the deref instead. The codegen # ends up using 'memcpy' for the array assignment, # so the '&' and '*' cancel out: - putIntoDest(p, d, a.t.sons[0], rdLoc(a)) + putIntoDest(p, d, a.t.sons[0], rdLoc(a), a.s) else: - putIntoDest(p, d, e.typ, "(*$1)" % [rdLoc(a)]) + putIntoDest(p, d, e.typ, "(*$1)" % [rdLoc(a)], a.s) proc genAddr(p: BProc, e: PNode, d: var TLoc) = # careful 'addr(myptrToArray)' needs to get the ampersand: if e.sons[0].typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}: var a: TLoc initLocExpr(p, e.sons[0], a) - putIntoDest(p, d, e.typ, "&" & a.r) + putIntoDest(p, d, e.typ, "&" & a.r, a.s) #Message(e.info, warnUser, "HERE NEW &") elif mapType(e.sons[0].typ) == ctArray or isCppRef(p, e.sons[0].typ): expr(p, e.sons[0], d) else: var a: TLoc initLocExpr(p, e.sons[0], a) - putIntoDest(p, d, e.typ, addrLoc(a)) + putIntoDest(p, d, e.typ, addrLoc(a), a.s) template inheritLocation(d: var TLoc, a: TLoc) = if d.k == locNone: d.s = a.s @@ -745,7 +745,7 @@ proc genTupleElem(p: BProc, e: PNode, d: var TLoc) = 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) + putIntoDest(p, d, ty.sons[i], r, a.s) proc genRecordField(p: BProc, e: PNode, d: var TLoc) = var a: TLoc @@ -756,7 +756,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) = # we found a unique tuple type which lacks field information # so we use Field$i addf(r, ".Field$1", [rope(f.position)]) - putIntoDest(p, d, f.typ, r) + putIntoDest(p, d, f.typ, r, a.s) else: var field: PSym = nil while ty != nil: @@ -769,7 +769,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) = if field == nil: internalError(e.info, "genRecordField 2 ") if field.loc.r == nil: internalError(e.info, "genRecordField 3") addf(r, ".$1", [field.loc.r]) - putIntoDest(p, d, field.typ, r) + putIntoDest(p, d, field.typ, r, a.s) #d.s = a.s proc genInExprAux(p: BProc, e: PNode, a, b, d: var TLoc) @@ -824,7 +824,7 @@ proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) = internalError(e.info, "genCheckedRecordField") # generate the checks: genFieldCheck(p, e, r, field) add(r, rfmt(nil, ".$1", field.loc.r)) - putIntoDest(p, d, field.typ, r) + putIntoDest(p, d, field.typ, r, a.s) else: genRecordField(p, e.sons[0], d) @@ -851,7 +851,7 @@ proc genArrayElem(p: BProc, x, y: PNode, d: var TLoc) = localError(x.info, errIndexOutOfBounds) d.inheritLocation(a) putIntoDest(p, d, elemType(skipTypes(ty, abstractVar)), - rfmt(nil, "$1[($2)- $3]", rdLoc(a), rdCharLoc(b), first)) + rfmt(nil, "$1[($2)- $3]", rdLoc(a), rdCharLoc(b), first), a.s) proc genCStringElem(p: BProc, x, y: PNode, d: var TLoc) = var a, b: TLoc @@ -860,7 +860,7 @@ proc genCStringElem(p: BProc, x, y: PNode, d: var TLoc) = var ty = skipTypes(a.t, abstractVarRange) if d.k == locNone: d.s = a.s putIntoDest(p, d, elemType(skipTypes(ty, abstractVar)), - rfmt(nil, "$1[$2]", rdLoc(a), rdCharLoc(b))) + rfmt(nil, "$1[$2]", rdLoc(a), rdCharLoc(b)), a.s) proc genOpenArrayElem(p: BProc, x, y: PNode, d: var TLoc) = var a, b: TLoc @@ -871,7 +871,7 @@ proc genOpenArrayElem(p: BProc, x, y: PNode, d: var TLoc) = rdLoc(b), rdLoc(a)) # BUGFIX: ``>=`` and not ``>``! if d.k == locNone: d.s = a.s putIntoDest(p, d, elemType(skipTypes(a.t, abstractVar)), - rfmt(nil, "$1[$2]", rdLoc(a), rdCharLoc(b))) + rfmt(nil, "$1[$2]", rdLoc(a), rdCharLoc(b)), a.s) proc genSeqElem(p: BProc, x, y: PNode, d: var TLoc) = var a, b: TLoc @@ -894,7 +894,7 @@ proc genSeqElem(p: BProc, x, y: PNode, d: var TLoc) = if skipTypes(a.t, abstractVar).kind in {tyRef, tyPtr}: a.r = rfmt(nil, "(*$1)", a.r) putIntoDest(p, d, elemType(skipTypes(a.t, abstractVar)), - rfmt(nil, "$1->data[$2]", rdLoc(a), rdCharLoc(b))) + rfmt(nil, "$1->data[$2]", rdLoc(a), rdCharLoc(b)), a.s) proc genBracketExpr(p: BProc; n: PNode; d: var TLoc) = var ty = skipTypes(n.sons[0].typ, abstractVarRange) @@ -1272,7 +1272,7 @@ proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) = r = rfmt(p.module, "(($1) && ($2))", nilCheck, genOfHelper(p, dest, r)) else: r = rfmt(p.module, "($1)", genOfHelper(p, dest, r)) - putIntoDest(p, d, getSysType(tyBool), r) + putIntoDest(p, d, getSysType(tyBool), r, a.s) proc genOf(p: BProc, n: PNode, d: var TLoc) = genOf(p, n.sons[1], n.sons[2].typ, d) @@ -1284,47 +1284,47 @@ proc genRepr(p: BProc, e: PNode, d: var TLoc) = case t.kind of tyInt..tyInt64, tyUInt..tyUInt64: putIntoDest(p, d, e.typ, - ropecg(p.module, "#reprInt((NI64)$1)", [rdLoc(a)])) + ropecg(p.module, "#reprInt((NI64)$1)", [rdLoc(a)]), a.s) of tyFloat..tyFloat128: - putIntoDest(p, d, e.typ, ropecg(p.module, "#reprFloat($1)", [rdLoc(a)])) + putIntoDest(p, d, e.typ, ropecg(p.module, "#reprFloat($1)", [rdLoc(a)]), a.s) of tyBool: - putIntoDest(p, d, e.typ, ropecg(p.module, "#reprBool($1)", [rdLoc(a)])) + putIntoDest(p, d, e.typ, ropecg(p.module, "#reprBool($1)", [rdLoc(a)]), a.s) of tyChar: - putIntoDest(p, d, e.typ, ropecg(p.module, "#reprChar($1)", [rdLoc(a)])) + putIntoDest(p, d, e.typ, ropecg(p.module, "#reprChar($1)", [rdLoc(a)]), a.s) of tyEnum, tyOrdinal: putIntoDest(p, d, e.typ, ropecg(p.module, "#reprEnum($1, $2)", [ - rdLoc(a), genTypeInfo(p.module, t)])) + rdLoc(a), genTypeInfo(p.module, t)]), a.s) of tyString: - putIntoDest(p, d, e.typ, ropecg(p.module, "#reprStr($1)", [rdLoc(a)])) + putIntoDest(p, d, e.typ, ropecg(p.module, "#reprStr($1)", [rdLoc(a)]), a.s) of tySet: putIntoDest(p, d, e.typ, ropecg(p.module, "#reprSet($1, $2)", [ - addrLoc(a), genTypeInfo(p.module, t)])) + addrLoc(a), genTypeInfo(p.module, t)]), a.s) of tyOpenArray, tyVarargs: var b: TLoc case a.t.kind of tyOpenArray, tyVarargs: - putIntoDest(p, b, e.typ, "$1, $1Len0" % [rdLoc(a)]) + putIntoDest(p, b, e.typ, "$1, $1Len0" % [rdLoc(a)], a.s) of tyString, tySequence: putIntoDest(p, b, e.typ, - "$1->data, $1->$2" % [rdLoc(a), lenField(p)]) + "$1->data, $1->$2" % [rdLoc(a), lenField(p)], a.s) of tyArray, tyArrayConstr: putIntoDest(p, b, e.typ, - "$1, $2" % [rdLoc(a), rope(lengthOrd(a.t))]) + "$1, $2" % [rdLoc(a), rope(lengthOrd(a.t))], a.s) else: internalError(e.sons[0].info, "genRepr()") putIntoDest(p, d, e.typ, ropecg(p.module, "#reprOpenArray($1, $2)", [rdLoc(b), - genTypeInfo(p.module, elemType(t))])) + genTypeInfo(p.module, elemType(t))]), a.s) of tyCString, tyArray, tyArrayConstr, tyRef, tyPtr, tyPointer, tyNil, tySequence: putIntoDest(p, d, e.typ, ropecg(p.module, "#reprAny($1, $2)", [ - rdLoc(a), genTypeInfo(p.module, t)])) + rdLoc(a), genTypeInfo(p.module, t)]), a.s) of tyEmpty: localError(e.info, "'repr' doesn't support 'void' type") else: putIntoDest(p, d, e.typ, ropecg(p.module, "#reprAny($1, $2)", - [addrLoc(a), genTypeInfo(p.module, t)])) + [addrLoc(a), genTypeInfo(p.module, t)]), a.s) gcUsage(e) proc genGetTypeInfo(p: BProc, e: PNode, d: var TLoc) = @@ -1549,13 +1549,13 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) = let etyp = skipTypes(e.typ, abstractRange) if etyp.kind in ValueTypes and lfIndirect notin a.flags: putIntoDest(p, d, e.typ, "(*($1*) ($2))" % - [getTypeDesc(p.module, e.typ), addrLoc(a)]) + [getTypeDesc(p.module, e.typ), addrLoc(a)], a.s) elif etyp.kind == tyProc and etyp.callConv == ccClosure: putIntoDest(p, d, e.typ, "(($1) ($2))" % - [getClosureType(p.module, etyp, clHalfWithEnv), rdCharLoc(a)]) + [getClosureType(p.module, etyp, clHalfWithEnv), rdCharLoc(a)], a.s) else: putIntoDest(p, d, e.typ, "(($1) ($2))" % - [getTypeDesc(p.module, e.typ), rdCharLoc(a)]) + [getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.s) proc genCast(p: BProc, e: PNode, d: var TLoc) = const floatTypes = {tyFloat..tyFloat128} @@ -1575,7 +1575,7 @@ proc genCast(p: BProc, e: PNode, d: var TLoc) = tmp.s = OnStack tmp.flags = {} expr(p, e.sons[1], tmp) - putIntoDest(p, d, e.typ, "LOC$#.dest" % [lbl]) + putIntoDest(p, d, e.typ, "LOC$#.dest" % [lbl], tmp.s) else: # I prefer the shorter cast version for pointer types -> generate less # C code; plus it's the right thing to do for closures: @@ -1589,13 +1589,13 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) = {tyUInt..tyUInt64}: initLocExpr(p, n.sons[0], a) putIntoDest(p, d, n.typ, "(($1) ($2))" % - [getTypeDesc(p.module, dest), rdCharLoc(a)]) + [getTypeDesc(p.module, dest), rdCharLoc(a)], a.s) else: initLocExpr(p, n.sons[0], a) putIntoDest(p, d, dest, ropecg(p.module, "(($1)#$5($2, $3, $4))", [ getTypeDesc(p.module, dest), rdCharLoc(a), genLiteral(p, n.sons[1], dest), genLiteral(p, n.sons[2], dest), - rope(magic)])) + rope(magic)]), a.s) proc genConv(p: BProc, e: PNode, d: var TLoc) = let destType = e.typ.skipTypes({tyVar, tyGenericInst}) @@ -1607,13 +1607,13 @@ proc genConv(p: BProc, e: PNode, d: var TLoc) = proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) = var a: TLoc initLocExpr(p, n.sons[0], a) - putIntoDest(p, d, skipTypes(n.typ, abstractVar), "$1->data" % [rdLoc(a)]) + putIntoDest(p, d, skipTypes(n.typ, abstractVar), "$1->data" % [rdLoc(a)], a.s) proc convCStrToStr(p: BProc, n: PNode, d: var TLoc) = var a: TLoc initLocExpr(p, n.sons[0], a) putIntoDest(p, d, skipTypes(n.typ, abstractVar), - ropecg(p.module, "#cstrToNimstr($1)", [rdLoc(a)])) + ropecg(p.module, "#cstrToNimstr($1)", [rdLoc(a)]), a.s) gcUsage(n) proc genStrEquals(p: BProc, e: PNode, d: var TLoc) = @@ -1763,7 +1763,7 @@ proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool = var t = getUniqueType(n.typ) discard getTypeDesc(p.module, t) # so that any fields are initialized var id = nodeTableTestOrSet(p.module.dataCache, n, gBackendId) - fillLoc(d, locData, t, "TMP" & rope(id), OnHeap) + fillLoc(d, locData, t, "TMP" & rope(id), OnStatic) if id == gBackendId: # expression not found in the cache: inc(gBackendId) @@ -1849,7 +1849,7 @@ proc genClosure(p: BProc, n: PNode, d: var TLoc) = var tmp = "LOC" & rope(p.labels) addf(p.module.s[cfsData], "NIM_CONST $1 $2 = $3;$n", [getTypeDesc(p.module, n.typ), tmp, genConstExpr(p, n)]) - putIntoDest(p, d, n.typ, tmp) + putIntoDest(p, d, n.typ, tmp, OnStatic) else: var tmp, a, b: TLoc initLocExpr(p, n.sons[0], a) @@ -1903,10 +1903,10 @@ proc upConv(p: BProc, n: PNode, d: var TLoc) = r, genTypeInfo(p.module, dest)) if n.sons[0].typ.kind != tyObject: putIntoDest(p, d, n.typ, - "(($1) ($2))" % [getTypeDesc(p.module, n.typ), rdLoc(a)]) + "(($1) ($2))" % [getTypeDesc(p.module, n.typ), rdLoc(a)], a.s) else: putIntoDest(p, d, n.typ, "(*($1*) ($2))" % - [getTypeDesc(p.module, dest), addrLoc(a)]) + [getTypeDesc(p.module, dest), addrLoc(a)], a.s) proc downConv(p: BProc, n: PNode, d: var TLoc) = if p.module.compileToCpp: @@ -1938,9 +1938,9 @@ proc downConv(p: BProc, n: PNode, d: var TLoc) = linefmt(p, cpsStmts, "$1 = &$2;$n", rdLoc(d), r) else: r = "&" & r - putIntoDest(p, d, n.typ, r) + putIntoDest(p, d, n.typ, r, a.s) else: - putIntoDest(p, d, n.typ, r) + putIntoDest(p, d, n.typ, r, a.s) proc exprComplexConst(p: BProc, n: PNode, d: var TLoc) = var t = getUniqueType(n.typ) @@ -1955,7 +1955,7 @@ proc exprComplexConst(p: BProc, n: PNode, d: var TLoc) = [getTypeDesc(p.module, t), tmp, genConstExpr(p, n)]) if d.k == locNone: - fillLoc(d, locData, t, tmp, OnHeap) + fillLoc(d, locData, t, tmp, OnStatic) else: putDataIntoDest(p, d, t, tmp) @@ -1982,7 +1982,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) = if sfGlobal in sym.flags: genVarPrototype(p.module, sym) putLocIntoDest(p, d, sym.loc) elif isSimpleConst(sym.typ): - putIntoDest(p, d, n.typ, genLiteral(p, sym.ast, sym.typ)) + putIntoDest(p, d, n.typ, genLiteral(p, sym.ast, sym.typ), OnStatic) else: genComplexConst(p, sym, d) of skEnumField: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 13514818e..3f88e63ee 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -760,7 +760,7 @@ proc requestConstImpl(p: BProc, sym: PSym) = var m = p.module useHeader(m, sym) if sym.loc.k == locNone: - fillLoc(sym.loc, locData, sym.typ, mangleName(sym), OnUnknown) + fillLoc(sym.loc, locData, sym.typ, mangleName(sym), OnStatic) if lfNoDecl in sym.loc.flags: return # declare implementation: var q = findPendingModule(m, sym) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 297b865b2..31bd85a06 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -91,3 +91,4 @@ proc initDefines*() = defineSymbol("nimnomagic64") defineSymbol("nimvarargstyped") defineSymbol("nimtypedescfixed") + defineSymbol("nimKnowsNimvm") diff --git a/compiler/filter_tmpl.nim b/compiler/filter_tmpl.nim index d3ab1728c..21810adb9 100644 --- a/compiler/filter_tmpl.nim +++ b/compiler/filter_tmpl.nim @@ -67,9 +67,9 @@ proc parseLine(p: var TTmplParser) = keyw: string j = 0 while p.x[j] == ' ': inc(j) - if (p.x[0] == p.nimDirective) and (p.x[0 + 1] == '!'): + if p.x[0] == p.nimDirective and p.x[1] in {'?', '!'}: newLine(p) - elif (p.x[j] == p.nimDirective): + elif p.x[j] == p.nimDirective: newLine(p) inc(j) while p.x[j] == ' ': inc(j) diff --git a/compiler/jstypes.nim b/compiler/jstypes.nim index 851938327..832d9996c 100644 --- a/compiler/jstypes.nim +++ b/compiler/jstypes.nim @@ -116,8 +116,7 @@ proc genEnumInfo(p: PProc, typ: PType, name: Rope) = [name, genTypeInfo(p, typ.sons[0])]) proc genTypeInfo(p: PProc, typ: PType): Rope = - var t = typ - if t.kind == tyGenericInst: t = lastSon(t) + let t = typ.skipTypes({tyGenericInst}) result = "NTI$1" % [rope(t.id)] if containsOrIncl(p.g.typeInfoGenerated, t.id): return case t.kind @@ -141,7 +140,7 @@ proc genTypeInfo(p: PProc, typ: PType): Rope = [result, rope(ord(t.kind))] prepend(p.g.typeInfo, s) addf(p.g.typeInfo, "$1.base = $2;$n", - [result, genTypeInfo(p, typ.sons[1])]) + [result, genTypeInfo(p, t.sons[1])]) of tyEnum: genEnumInfo(p, t, result) of tyObject: genObjectInfo(p, t, result) of tyTuple: genTupleInfo(p, t, result) diff --git a/compiler/parampatterns.nim b/compiler/parampatterns.nim index ae391945a..978583c14 100644 --- a/compiler/parampatterns.nim +++ b/compiler/parampatterns.nim @@ -225,8 +225,11 @@ proc isAssignable*(owner: PSym, n: PNode; isUnsafeAddr=false): TAssignableResult result = isAssignable(owner, n.sons[0], isUnsafeAddr) of nkCallKinds: # builtin slice keeps lvalue-ness: - if getMagic(n) == mSlice: + if getMagic(n) in {mArrGet, mSlice}: result = isAssignable(owner, n.sons[1], isUnsafeAddr) + of nkStmtList, nkStmtListExpr: + if n.typ != nil: + result = isAssignable(owner, n.lastSon, isUnsafeAddr) else: discard diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 2ab43a9c9..70276a6d4 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -435,7 +435,7 @@ proc evalOp(m: TMagic, n, a, b, c: PNode): PNode = mAppendStrStr, mAppendSeqElem, mSetLengthStr, mSetLengthSeq, mParseExprToAst, mParseStmtToAst, mExpandToAst, mTypeTrait, mDotDot, mNLen..mNError, mEqRef, mSlurp, mStaticExec, mNGenSym, mSpawn, - mParallel, mPlugin, mGetTypeInfo: + mParallel, mPlugin, mGetTypeInfo, mTypeOf: discard of mEqProc: result = newIntNodeT(ord( diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 370990326..42a39d0df 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -221,6 +221,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, # NOTE: for access of private fields within generics from a different module # we set the friend module: c.friendModules.add(getModule(fn)) + let oldInTypeClass = c.inTypeClass + c.inTypeClass = 0 let oldScope = c.currentScope while not isTopLevel(c): c.currentScope = c.currentScope.parent result = copySym(fn, false) @@ -269,4 +271,5 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, c.currentScope = oldScope discard c.friendModules.pop() dec(c.instCounter) + c.inTypeClass = oldInTypeClass if result.kind == skMethod: finishMethod(c, result) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index ffda6a1bb..4399c0ab0 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1425,7 +1425,7 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode = localError(result.info, "type class predicate failed") of tyUnknown: continue else: discard - if n.sons[i].typ == enforceVoidContext or usesResult(n.sons[i]): + if n.sons[i].typ == enforceVoidContext: #or usesResult(n.sons[i]): voidContext = true n.typ = enforceVoidContext if i == last and (length == 1 or efWantValue in flags): diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 4d1eae48f..371abe1e3 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -471,27 +471,6 @@ proc semTemplBodyDirty(c: var TemplCtx, n: PNode): PNode = for i in countup(0, sonsLen(n) - 1): result.sons[i] = semTemplBodyDirty(c, n.sons[i]) -proc transformToExpr(n: PNode): PNode = - var realStmt: int - result = n - case n.kind - of nkStmtList: - realStmt = - 1 - for i in countup(0, sonsLen(n) - 1): - case n.sons[i].kind - of nkCommentStmt, nkEmpty, nkNilLit: - discard - else: - if realStmt == - 1: realStmt = i - else: realStmt = - 2 - if realStmt >= 0: result = transformToExpr(n.sons[realStmt]) - else: n.kind = nkStmtListExpr - of nkBlockStmt: - n.kind = nkBlockExpr - #nkIfStmt: n.kind = nkIfExpr // this is not correct! - else: - discard - proc semTemplateDef(c: PContext, n: PNode): PNode = var s: PSym if isTopLevel(c): @@ -549,9 +528,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode = n.sons[bodyPos] = semTemplBodyDirty(ctx, n.sons[bodyPos]) else: n.sons[bodyPos] = semTemplBody(ctx, n.sons[bodyPos]) - if s.typ.sons[0].kind notin {tyStmt, tyTypeDesc}: - n.sons[bodyPos] = transformToExpr(n.sons[bodyPos]) - # only parameters are resolved, no type checking is performed + # only parameters are resolved, no type checking is performed semIdeForTemplateOrGeneric(c, n.sons[bodyPos], ctx.cursorInBody) closeScope(c) popOwner() @@ -604,6 +581,11 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode = localError(n.info, errInvalidExpression) result = n + proc stupidStmtListExpr(n: PNode): bool = + for i in 0 .. n.len-2: + if n[i].kind notin {nkEmpty, nkCommentStmt}: return false + result = true + result = n case n.kind of nkIdent: @@ -629,6 +611,12 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode = localError(n.info, errInvalidExpression) else: localError(n.info, errInvalidExpression) + of nkStmtList, nkStmtListExpr: + if stupidStmtListExpr(n): + result = semPatternBody(c, n.lastSon) + else: + for i in countup(0, sonsLen(n) - 1): + result.sons[i] = semPatternBody(c, n.sons[i]) of nkCallKinds: let s = qualifiedLookUp(c.c, n.sons[0], {}) if s != nil: diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 5ae3d16c0..2ee17fcaf 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -970,6 +970,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, elif kind == skIterator: # XXX This is special magic we should likely get rid of r = newTypeS(tyExpr, c) + message(n.info, warnDeprecated, "implicit return type for 'iterator'") if r != nil: # turn explicit 'void' return type into 'nil' because the rest of the diff --git a/compiler/syntaxes.nim b/compiler/syntaxes.nim index 91cfdbefd..021910544 100644 --- a/compiler/syntaxes.nim +++ b/compiler/syntaxes.nim @@ -92,10 +92,15 @@ proc parsePipe(filename: string, inputStream: PLLStream): PNode = var line = newStringOfCap(80) discard llStreamReadLine(s, line) var i = utf8Bom(line) + var linenumber = 1 if containsShebang(line, i): discard llStreamReadLine(s, line) i = 0 - if line[i] == '#' and line[i+1] == '!': + inc linenumber + if line[i] == '#' and line[i+1] in {'?', '!'}: + if line[i+1] == '!': + message(newLineInfo(filename, linenumber, 1), + warnDeprecated, "use '#?' instead; '#!'") inc(i, 2) while line[i] in Whitespace: inc(i) var q: TParser diff --git a/compiler/vm.nim b/compiler/vm.nim index 05d00c19f..0db287c6a 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1461,6 +1461,8 @@ proc evalConstExprAux(module, prc: PSym, n: PNode, mode: TEvalMode): PNode = let n = transformExpr(module, n) setupGlobalCtx(module) var c = globalCtx + let oldMode = c.mode + defer: c.mode = oldMode c.mode = mode let start = genExpr(c, n, requiresValue = mode!=emStaticStmt) if c.code[start].opcode == opcEof: return emptyNode diff --git a/compiler/writetracking.nim b/compiler/writetracking.nim index 38258b07a..141b496c1 100644 --- a/compiler/writetracking.nim +++ b/compiler/writetracking.nim @@ -200,7 +200,7 @@ proc deps(w: var W; n: PNode) = proc possibleAliases(w: var W; result: var seq[ptr TSym]) = # this is an expensive fixpoint iteration. We could speed up this analysis - # by a smarter data-structure but we wait until prolifing shows us it's + # by a smarter data-structure but we wait until profiling shows us it's # expensive. Usually 'w.assignments' is small enough. var alreadySeen = initIntSet() template addNoDup(x) = |