mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 20:17:42 +00:00
l-values are preserved modulo type distinction
This commit is contained in:
@@ -1395,7 +1395,11 @@ proc genRangeChck(p: BProc, n: PNode, d: var TLoc, magic: string) =
|
||||
toRope(magic)]))
|
||||
|
||||
proc genConv(p: BProc, e: PNode, d: var TLoc) =
|
||||
genCast(p, e, d)
|
||||
if equalOrDistinctOf(e.typ, e.sons[1].typ) or
|
||||
equalOrDistinctOf(e.sons[1].typ, e.typ):
|
||||
expr(p, e.sons[1], d)
|
||||
else:
|
||||
genCast(p, e, d)
|
||||
|
||||
proc convStrToCStr(p: BProc, n: PNode, d: var TLoc) =
|
||||
var a: TLoc
|
||||
|
||||
@@ -72,7 +72,7 @@ proc GetUniqueType*(key: PType): PType =
|
||||
if result == nil:
|
||||
IdTablePut(gTypeTable[k], key, key)
|
||||
result = key
|
||||
of tyGenericInst, tyDistinct, tyOrdinal:
|
||||
of tyGenericInst, tyDistinct, tyOrdinal, tyMutable, tyConst, tyIter:
|
||||
result = GetUniqueType(lastSon(key))
|
||||
of tyProc:
|
||||
nil
|
||||
@@ -116,9 +116,8 @@ proc makeCString*(s: string): PRope =
|
||||
# further information.
|
||||
const
|
||||
MaxLineLength = 64
|
||||
var res: string
|
||||
result = nil
|
||||
res = "\""
|
||||
var res = "\""
|
||||
for i in countup(0, len(s) - 1):
|
||||
if (i + 1) mod MaxLineLength == 0:
|
||||
add(res, '\"')
|
||||
@@ -132,9 +131,8 @@ proc makeCString*(s: string): PRope =
|
||||
|
||||
proc makeLLVMString*(s: string): PRope =
|
||||
const MaxLineLength = 64
|
||||
var res: string
|
||||
result = nil
|
||||
res = "c\""
|
||||
var res = "c\""
|
||||
for i in countup(0, len(s) - 1):
|
||||
if (i + 1) mod MaxLineLength == 0:
|
||||
app(result, toRope(res))
|
||||
|
||||
@@ -1316,6 +1316,7 @@ proc complexOrSimpleStmt(p: var TParser): PNode =
|
||||
of tkConverter: result = parseRoutine(p, nkConverterDef)
|
||||
of tkType: result = parseSection(p, nkTypeSection, parseTypeDef)
|
||||
of tkConst: result = parseSection(p, nkConstSection, parseConstant)
|
||||
of tkLet: result = parseSection(p, nkLetSection, parseConstant)
|
||||
of tkWhen: result = parseIfOrWhen(p, nkWhenStmt)
|
||||
of tkVar: result = parseSection(p, nkVarSection, parseVariable)
|
||||
else: result = simpleStmt(p)
|
||||
@@ -1379,7 +1380,7 @@ proc parseString(s: string, filename: string = "", line: int = 0): PNode =
|
||||
var stream = LLStreamOpen(s)
|
||||
stream.lineOffset = line
|
||||
|
||||
var parser : TParser
|
||||
var parser: TParser
|
||||
OpenParser(parser, filename, stream)
|
||||
|
||||
result = parser.parseAll
|
||||
|
||||
@@ -378,6 +378,10 @@ proc isAssignable(c: PContext, n: PNode): TAssignableResult =
|
||||
# Object and tuple conversions are still addressable, so we skip them
|
||||
if skipTypes(n.typ, abstractPtrs).kind in {tyOpenArray, tyTuple, tyObject}:
|
||||
result = isAssignable(c, n.sons[1])
|
||||
elif equalOrDistinctOf(n.typ, n.sons[1].typ) or
|
||||
equalOrDistinctOf(n.sons[1].typ, n.typ):
|
||||
# types that are equal modulo distinction preserve l-value:
|
||||
result = isAssignable(c, n.sons[1])
|
||||
of nkHiddenDeref, nkDerefExpr:
|
||||
result = arLValue
|
||||
of nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr:
|
||||
|
||||
Reference in New Issue
Block a user