Merge branch 'devel' of github.com:nim-lang/Nim into devel

This commit is contained in:
Araq
2018-09-15 20:32:20 +02:00
5 changed files with 24 additions and 13 deletions

View File

@@ -1596,10 +1596,11 @@ proc genSwap(p: BProc, e: PNode, d: var TLoc) =
genAssignment(p, a, b, {})
genAssignment(p, b, tmp, {})
proc rdSetElemLoc(conf: ConfigRef; a: TLoc, setType: PType): Rope =
proc rdSetElemLoc(conf: ConfigRef; a: TLoc, typ: PType): Rope =
# read a location of an set element; it may need a subtraction operation
# before the set operation
result = rdCharLoc(a)
let setType = typ.skipTypes(abstractPtrs)
assert(setType.kind == tySet)
if firstOrd(conf, setType) != 0:
result = "($1- $2)" % [result, rope(firstOrd(conf, setType))]

View File

@@ -162,9 +162,9 @@ proc mapType(conf: ConfigRef; typ: PType): TCTypeKind =
var base = skipTypes(typ.lastSon, typedescInst)
case base.kind
of tyOpenArray, tyArray, tyVarargs: result = ctPtrToArray
#of tySet:
# if mapSetType(base) == ctArray: result = ctPtrToArray
# else: result = ctPtr
of tySet:
if mapSetType(conf, base) == ctArray: result = ctPtrToArray
else: result = ctPtr
# XXX for some reason this breaks the pegs module
else: result = ctPtr
of tyPointer: result = ctPtr
@@ -641,10 +641,11 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
compileToCpp(m): "&" else: "*"
var et = origTyp.skipTypes(abstractInst).lastSon
var etB = et.skipTypes(abstractInst)
if etB.kind in {tyArray, tyOpenArray, tyVarargs}:
# this is correct! sets have no proper base type, so we treat
# ``var set[char]`` in `getParamTypeDesc`
et = elemType(etB)
if mapType(m.config, t) == ctPtrToArray:
if etB.kind == tySet:
et = getSysType(m.g.graph, unknownLineInfo(), tyUInt8)
else:
et = elemType(etB)
etB = et.skipTypes(abstractInst)
star[0] = '*'
case etB.kind

View File

@@ -114,7 +114,7 @@ proc canon(x: string; result: var string; state: var int) =
if d > 0: setLen(result, d-1)
elif isDot(x, b):
discard "discard the dot"
elif b[1] > b[0]:
elif b[1] >= b[0]:
if result.len > 0 and result[^1] != DirSep:
result.add DirSep
result.add substr(x, b[0], b[1])

View File

@@ -145,10 +145,9 @@ proc readLine(f: File, line: var TaintedString): bool =
var pos = 0
# Use the currently reserved space for a first try
var sp = line.string.len
if sp == 0:
sp = 80
line.string.setLen(sp)
var sp = max(line.string.len, 80)
line.string.setLen(sp)
while true:
# memset to \L so that we can tell how far fgets wrote, even on EOF, where
# fgets doesn't append an \L

10
tests/ccgbugs/t8967.nim Normal file
View File

@@ -0,0 +1,10 @@
discard """
targets: "c cpp"
"""
import marshal
let orig: set[char] = {'A'..'Z'}
let m = $$orig
let old = to[set[char]](m)
doAssert orig - old == {}