improvements for 'pretty'
This commit is contained in:
parent
f2b9905b4e
commit
1101a40f91
15 changed files with 99 additions and 91 deletions
|
|
@ -628,12 +628,12 @@ proc rawDealloc(a: var TMemRegion, p: pointer) =
|
|||
# check if it is not in the freeSmallChunks[s] list:
|
||||
if c.free < s:
|
||||
# add it to the freeSmallChunks[s] array:
|
||||
listAdd(a.freeSmallChunks[s div memAlign], c)
|
||||
listAdd(a.freeSmallChunks[s div MemAlign], c)
|
||||
inc(c.free, s)
|
||||
else:
|
||||
inc(c.free, s)
|
||||
if c.free == SmallChunkSize-smallChunkOverhead():
|
||||
listRemove(a.freeSmallChunks[s div memAlign], c)
|
||||
listRemove(a.freeSmallChunks[s div MemAlign], c)
|
||||
c.size = SmallChunkSize
|
||||
freeBigChunk(a, cast[PBigChunk](c))
|
||||
sysAssert(((cast[TAddress](p) and PageMask) - smallChunkOverhead()) %%
|
||||
|
|
@ -739,7 +739,7 @@ proc realloc(allocator: var TMemRegion, p: pointer, newsize: int): pointer =
|
|||
proc deallocOsPages(a: var TMemRegion) =
|
||||
# we free every 'ordinarily' allocated page by iterating over the page bits:
|
||||
for p in elements(a.chunkStarts):
|
||||
var page = cast[PChunk](p shl pageShift)
|
||||
var page = cast[PChunk](p shl PageShift)
|
||||
when not weirdUnmap:
|
||||
var size = if page.size < PageSize: PageSize else: page.size
|
||||
osDeallocPages(page, size)
|
||||
|
|
|
|||
|
|
@ -37,12 +37,12 @@ proc genericAssignAux(dest, src: pointer, n: ptr TNimNode, shallow: bool) =
|
|||
# echo "ugh memory corruption! ", n.kind
|
||||
# quit 1
|
||||
|
||||
proc genericAssignAux(dest, src: Pointer, mt: PNimType, shallow: bool) =
|
||||
proc genericAssignAux(dest, src: pointer, mt: PNimType, shallow: bool) =
|
||||
var
|
||||
d = cast[TAddress](dest)
|
||||
s = cast[TAddress](src)
|
||||
sysAssert(mt != nil, "genericAssignAux 2")
|
||||
case mt.Kind
|
||||
case mt.kind
|
||||
of tyString:
|
||||
var x = cast[PPointer](dest)
|
||||
var s2 = cast[PPointer](s)[]
|
||||
|
|
@ -67,7 +67,7 @@ proc genericAssignAux(dest, src: Pointer, mt: PNimType, shallow: bool) =
|
|||
cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize),
|
||||
cast[pointer](cast[TAddress](s2) +% i *% mt.base.size +%
|
||||
GenericSeqSize),
|
||||
mt.Base, shallow)
|
||||
mt.base, shallow)
|
||||
of tyObject:
|
||||
# we need to copy m_type field for tyObject, as it could be empty for
|
||||
# sequence reallocations:
|
||||
|
|
@ -152,7 +152,7 @@ proc objectInitAux(dest: pointer, n: ptr TNimNode) =
|
|||
var m = selectBranch(dest, n)
|
||||
if m != nil: objectInitAux(dest, m)
|
||||
|
||||
proc objectInit(dest: Pointer, typ: PNimType) =
|
||||
proc objectInit(dest: pointer, typ: PNimType) =
|
||||
# the generic init proc that takes care of initialization of complex
|
||||
# objects on the stack or heap
|
||||
var d = cast[TAddress](dest)
|
||||
|
|
@ -185,7 +185,7 @@ else:
|
|||
for i in countup(0, r.len - 1): destroy(r[i])
|
||||
|
||||
proc genericReset(dest: pointer, mt: PNimType) {.compilerProc.}
|
||||
proc genericResetAux(dest: Pointer, n: ptr TNimNode) =
|
||||
proc genericResetAux(dest: pointer, n: ptr TNimNode) =
|
||||
var d = cast[TAddress](dest)
|
||||
case n.kind
|
||||
of nkNone: sysAssert(false, "genericResetAux")
|
||||
|
|
@ -197,10 +197,10 @@ proc genericResetAux(dest: Pointer, n: ptr TNimNode) =
|
|||
if m != nil: genericResetAux(dest, m)
|
||||
zeroMem(cast[pointer](d +% n.offset), n.typ.size)
|
||||
|
||||
proc genericReset(dest: Pointer, mt: PNimType) =
|
||||
proc genericReset(dest: pointer, mt: PNimType) =
|
||||
var d = cast[TAddress](dest)
|
||||
sysAssert(mt != nil, "genericReset 2")
|
||||
case mt.Kind
|
||||
case mt.kind
|
||||
of tyString, tyRef, tySequence:
|
||||
unsureAsgnRef(cast[PPointer](dest), nil)
|
||||
of tyObject, tyTuple:
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ proc reraiseException() {.compilerRtl.} =
|
|||
else:
|
||||
raiseExceptionAux(currException)
|
||||
|
||||
proc WriteStackTrace() =
|
||||
proc writeStackTrace() =
|
||||
when hasSomeStackTrace:
|
||||
var s = ""
|
||||
rawWriteStackTrace(s)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ var
|
|||
gch {.rtlThreadVar.}: TGcHeap
|
||||
|
||||
when not defined(useNimRtl):
|
||||
InstantiateForRegion(gch.region)
|
||||
instantiateForRegion(gch.region)
|
||||
|
||||
template acquire(gch: TGcHeap) =
|
||||
when hasThreadSupport and hasSharedHeap:
|
||||
|
|
@ -329,11 +329,11 @@ proc forAllSlotsAux(dest: pointer, n: ptr TNimNode, op: TWalkOp) =
|
|||
if m != nil: forAllSlotsAux(dest, m, op)
|
||||
of nkNone: sysAssert(false, "forAllSlotsAux")
|
||||
|
||||
proc forAllChildrenAux(dest: Pointer, mt: PNimType, op: TWalkOp) =
|
||||
proc forAllChildrenAux(dest: pointer, mt: PNimType, op: TWalkOp) =
|
||||
var d = cast[TAddress](dest)
|
||||
if dest == nil: return # nothing to do
|
||||
if ntfNoRefs notin mt.flags:
|
||||
case mt.Kind
|
||||
case mt.kind
|
||||
of tyRef, tyString, tySequence: # leaf:
|
||||
doOperation(cast[PPointer](d)[], op)
|
||||
of tyObject, tyTuple:
|
||||
|
|
@ -341,7 +341,7 @@ proc forAllChildrenAux(dest: Pointer, mt: PNimType, op: TWalkOp) =
|
|||
of tyArray, tyArrayConstr, tyOpenArray:
|
||||
for i in 0..(mt.size div mt.base.size)-1:
|
||||
forAllChildrenAux(cast[pointer](d +% i *% mt.base.size), mt.base, op)
|
||||
else: nil
|
||||
else: discard
|
||||
|
||||
proc forAllChildren(cell: PCell, op: TWalkOp) =
|
||||
gcAssert(cell != nil, "forAllChildren: 1")
|
||||
|
|
@ -352,7 +352,7 @@ proc forAllChildren(cell: PCell, op: TWalkOp) =
|
|||
if marker != nil:
|
||||
marker(cellToUsr(cell), op.int)
|
||||
else:
|
||||
case cell.typ.Kind
|
||||
case cell.typ.kind
|
||||
of tyRef: # common case
|
||||
forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
|
||||
of tySequence:
|
||||
|
|
@ -970,7 +970,7 @@ proc collectCTBody(gch: var TGcHeap) =
|
|||
#discard collectZCT(gch)
|
||||
inc(gch.stat.cycleCollections)
|
||||
gch.cycleThreshold = max(InitialCycleThreshold, getOccupiedMem() *
|
||||
cycleIncrease)
|
||||
CycleIncrease)
|
||||
gch.stat.maxThreshold = max(gch.stat.maxThreshold, gch.cycleThreshold)
|
||||
unmarkStackAndRegisters(gch)
|
||||
sysAssert(allocInv(gch.region), "collectCT: end")
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ when not defined(useNimRtl):
|
|||
for i in 0..cast[PGenericSeq](p).len-1:
|
||||
if i > 0: add result, ", "
|
||||
reprAux(result, cast[pointer](cast[TAddress](p) + GenericSeqSize + i*bs),
|
||||
typ.Base, cl)
|
||||
typ.base, cl)
|
||||
add result, "]"
|
||||
|
||||
proc reprRecordAux(result: var string, p: pointer, n: ptr TNimNode,
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ else:
|
|||
IONBF {.importc: "_IONBF", nodecl.}: cint
|
||||
|
||||
const
|
||||
buf_size = 4000
|
||||
BufSize = 4000
|
||||
|
||||
proc raiseEIO(msg: string) {.noinline, noreturn.} =
|
||||
sysFatal(EIO, msg)
|
||||
|
|
@ -71,7 +71,7 @@ proc readLine(f: TFile, line: var TaintedString): bool =
|
|||
# of course this could be optimized a bit; but IO is slow anyway...
|
||||
# and it was difficult to get this CORRECT with Ansi C's methods
|
||||
setLen(line.string, 0) # reuse the buffer!
|
||||
while True:
|
||||
while true:
|
||||
var c = fgetc(f)
|
||||
if c < 0'i32:
|
||||
if line.len > 0: break
|
||||
|
|
@ -94,8 +94,8 @@ proc write(f: TFile, i: int) =
|
|||
else:
|
||||
fprintf(f, "%ld", i)
|
||||
|
||||
proc write(f: TFile, i: biggestInt) =
|
||||
when sizeof(biggestint) == 8:
|
||||
proc write(f: TFile, i: BiggestInt) =
|
||||
when sizeof(Biggestint) == 8:
|
||||
fprintf(f, "%lld", i)
|
||||
else:
|
||||
fprintf(f, "%ld", i)
|
||||
|
|
@ -104,7 +104,7 @@ proc write(f: TFile, b: bool) =
|
|||
if b: write(f, "true")
|
||||
else: write(f, "false")
|
||||
proc write(f: TFile, r: float32) = fprintf(f, "%g", r)
|
||||
proc write(f: TFile, r: biggestFloat) = fprintf(f, "%g", r)
|
||||
proc write(f: TFile, r: BiggestFloat) = fprintf(f, "%g", r)
|
||||
|
||||
proc write(f: TFile, c: char) = putc(c, f)
|
||||
proc write(f: TFile, a: varargs[string, `$`]) =
|
||||
|
|
@ -114,10 +114,10 @@ proc readAllBuffer(file: TFile): string =
|
|||
# This proc is for TFile we want to read but don't know how many
|
||||
# bytes we need to read before the buffer is empty.
|
||||
result = ""
|
||||
var buffer = newString(buf_size)
|
||||
var bytesRead = buf_size
|
||||
while bytesRead == buf_size:
|
||||
bytesRead = readBuffer(file, addr(buffer[0]), buf_size)
|
||||
var buffer = newString(BufSize)
|
||||
var bytesRead = BufSize
|
||||
while bytesRead == BufSize:
|
||||
bytesRead = readBuffer(file, addr(buffer[0]), BufSize)
|
||||
result.add(buffer)
|
||||
|
||||
proc rawFileSize(file: TFile): int =
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} =
|
|||
if len > 0:
|
||||
result = rawNewString(len)
|
||||
result.len = len
|
||||
c_memcpy(result.data, addr(s.data[start]), len * sizeof(Char))
|
||||
c_memcpy(result.data, addr(s.data[start]), len * sizeof(char))
|
||||
#result.data[len] = '\0'
|
||||
else:
|
||||
result = rawNewString(len)
|
||||
|
|
@ -66,7 +66,7 @@ proc copyStr(s: NimString, start: int): NimString {.compilerProc.} =
|
|||
proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} =
|
||||
result = rawNewString(len)
|
||||
result.len = len
|
||||
c_memcpy(result.data, str, (len+1) * sizeof(Char))
|
||||
c_memcpy(result.data, str, (len+1) * sizeof(char))
|
||||
#result.data[len] = '\0' # readline relies on this!
|
||||
|
||||
proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} =
|
||||
|
|
@ -79,7 +79,7 @@ proc copyString(src: NimString): NimString {.compilerRtl.} =
|
|||
else:
|
||||
result = rawNewString(src.space)
|
||||
result.len = src.len
|
||||
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(Char))
|
||||
c_memcpy(result.data, src.data, (src.len + 1) * sizeof(char))
|
||||
|
||||
proc copyStringRC1(src: NimString): NimString {.compilerRtl.} =
|
||||
if src != nil:
|
||||
|
|
@ -236,7 +236,7 @@ proc nimIntToStr(x: int): string {.compilerRtl.} =
|
|||
result = newString(sizeof(x)*4)
|
||||
var i = 0
|
||||
var y = x
|
||||
while True:
|
||||
while true:
|
||||
var d = y div 10
|
||||
result[i] = chr(abs(int(y - d*10)) + ord('0'))
|
||||
inc(i)
|
||||
|
|
@ -259,7 +259,7 @@ proc nimInt64ToStr(x: int64): string {.compilerRtl.} =
|
|||
result = newString(sizeof(x)*4)
|
||||
var i = 0
|
||||
var y = x
|
||||
while True:
|
||||
while true:
|
||||
var d = y div 10
|
||||
result[i] = chr(abs(int(y - d*10)) + ord('0'))
|
||||
inc(i)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue