diff options
author | Araq <rumpf_a@web.de> | 2015-09-12 10:51:20 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-09-12 10:51:20 +0200 |
commit | 2a797c362a1c70d708eb21a18a227296dcac71a4 (patch) | |
tree | e2123a9b209d21f3ba80fda91b963fcdd2871c14 | |
parent | f1d1ff50e2e6f935b8bfa0f25b3dff023caa2e1a (diff) | |
download | Nim-2a797c362a1c70d708eb21a18a227296dcac71a4.tar.gz |
preparations for better handling of 'a[i]' in generics; stmt lists can be lvalues
-rw-r--r-- | compiler/ast.nim | 10 | ||||
-rw-r--r-- | compiler/parampatterns.nim | 5 |
2 files changed, 13 insertions, 2 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 7b6f39cbc..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, @@ -1586,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/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 |