diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/os.nim | 56 | ||||
-rw-r--r-- | lib/pure/strutils.nim | 20 | ||||
-rw-r--r-- | lib/pure/times.nim | 2 | ||||
-rw-r--r-- | lib/system.nim | 8 | ||||
-rw-r--r-- | lib/system/alloc.nim | 6 | ||||
-rw-r--r-- | lib/system/assign.nim | 14 | ||||
-rw-r--r-- | lib/system/excpt.nim | 2 | ||||
-rw-r--r-- | lib/system/gc.nim | 12 | ||||
-rw-r--r-- | lib/system/repr.nim | 2 | ||||
-rw-r--r-- | lib/system/sysio.nim | 18 | ||||
-rw-r--r-- | lib/system/sysstr.nim | 10 |
11 files changed, 75 insertions, 75 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index fbca89f52..202052bc6 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -96,8 +96,8 @@ elif defined(macos): CurDir* = ':' ParDir* = "::" Dirsep* = ':' - Altsep* = dirsep - Pathsep* = ',' + Altsep* = Dirsep + PathSep* = ',' FileSystemCaseSensitive* = false ExeExt* = "" ScriptExt* = "" @@ -135,7 +135,7 @@ elif doslike: elif defined(PalmOS) or defined(MorphOS): const Dirsep* = '/' - Altsep* = dirsep + Altsep* = Dirsep PathSep* = ';' Pardir* = ".." FileSystemCaseSensitive* = false @@ -157,7 +157,7 @@ else: # UNIX-like operating system Curdir* = '.' Pardir* = ".." Dirsep* = '/' - Altsep* = dirsep + Altsep* = Dirsep PathSep* = ':' FileSystemCaseSensitive* = true ExeExt* = "" @@ -304,11 +304,11 @@ proc unixToNativePath*(path: string): string {. elif defined(macos): result = "" # must not start with ':' else: - result = $dirSep + result = $DirSep start = 1 elif path[0] == '.' and path[1] == '/': # current directory - result = $curdir + result = $Curdir start = 2 else: result = "" @@ -322,12 +322,12 @@ proc unixToNativePath*(path: string): string {. if result[high(result)] == ':': add result, ':' else: - add result, pardir + add result, ParDir else: - add result, pardir & dirSep + add result, ParDir & DirSep inc(i, 3) elif path[i] == '/': - add result, dirSep + add result, DirSep inc(i) else: add result, path[i] @@ -538,7 +538,7 @@ proc splitPath*(path: string): tuple[head, tail: string] {. ## splitPath("") -> ("", "") var sepPos = -1 for i in countdown(len(path)-1, 0): - if path[i] in {dirsep, altsep}: + if path[i] in {Dirsep, Altsep}: sepPos = i break if sepPos >= 0: @@ -550,9 +550,9 @@ proc splitPath*(path: string): tuple[head, tail: string] {. proc parentDirPos(path: string): int = var q = 1 - if path[len(path)-1] in {dirsep, altsep}: q = 2 + if path[len(path)-1] in {Dirsep, Altsep}: q = 2 for i in countdown(len(path)-q, 0): - if path[i] in {dirsep, altsep}: return i + if path[i] in {Dirsep, Altsep}: return i result = -1 proc parentDir*(path: string): string {. @@ -593,8 +593,8 @@ iterator parentDirs*(path: string, fromRoot=false, inclusive=true): string = else: for i in countup(0, path.len - 2): # ignore the last / # deal with non-normalized paths such as /foo//bar//baz - if path[i] in {dirsep, altsep} and - (i == 0 or path[i-1] notin {dirsep, altsep}): + if path[i] in {Dirsep, Altsep} and + (i == 0 or path[i-1] notin {Dirsep, Altsep}): yield path.substr(0, i) if inclusive: yield path @@ -609,17 +609,17 @@ proc `/../` * (head, tail: string): string {.noSideEffect.} = result = head / tail proc normExt(ext: string): string = - if ext == "" or ext[0] == extSep: result = ext # no copy needed here - else: result = extSep & ext + if ext == "" or ext[0] == ExtSep: result = ext # no copy needed here + else: result = ExtSep & ext proc searchExtPos(s: string): int = # BUGFIX: do not search until 0! .DS_Store is no file extension! result = -1 for i in countdown(len(s)-1, 1): - if s[i] == extsep: + if s[i] == ExtSep: result = i break - elif s[i] in {dirsep, altsep}: + elif s[i] in {Dirsep, Altsep}: break # do not skip over path proc splitFile*(path: string): tuple[dir, name, ext: string] {. @@ -639,7 +639,7 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {. ## If `path` has no extension, `ext` is the empty string. ## If `path` has no directory component, `dir` is the empty string. ## If `path` has no filename component, `name` and `ext` are empty strings. - if path.len == 0 or path[path.len-1] in {dirSep, altSep}: + if path.len == 0 or path[path.len-1] in {DirSep, Altsep}: result = (path, "", "") else: var sepPos = -1 @@ -647,8 +647,8 @@ proc splitFile*(path: string): tuple[dir, name, ext: string] {. for i in countdown(len(path)-1, 0): if path[i] == ExtSep: if dotPos == path.len and i > 0 and - path[i-1] notin {dirsep, altsep}: dotPos = i - elif path[i] in {dirsep, altsep}: + path[i-1] notin {Dirsep, Altsep}: dotPos = i + elif path[i] in {Dirsep, Altsep}: sepPos = i break result.dir = substr(path, 0, sepPos-1) @@ -659,7 +659,7 @@ proc extractFilename*(path: string): string {. noSideEffect, rtl, extern: "nos$1".} = ## Extracts the filename of a given `path`. This is the same as ## ``name & ext`` from ``splitFile(path)``. - if path.len == 0 or path[path.len-1] in {dirSep, altSep}: + if path.len == 0 or path[path.len-1] in {DirSep, Altsep}: result = "" else: result = splitPath(path).tail @@ -816,7 +816,7 @@ proc sameFileContent*(path1, path2: string): bool {.rtl, extern: "nos$1", return false var bufA = alloc(bufsize) var bufB = alloc(bufsize) - while True: + while true: var readA = readBuffer(a, bufA, bufsize) var readB = readBuffer(b, bufB, bufsize) if readA != readB: @@ -1032,7 +1032,7 @@ when defined(windows): env = getEnvironmentStringsW() e = env if e == nil: return # an error occured - while True: + while true: var eend = strEnd(e) add(environment, $e) e = cast[WideCString](cast[TAddress](eend)+2) @@ -1043,7 +1043,7 @@ when defined(windows): env = getEnvironmentStringsA() e = env if e == nil: return # an error occured - while True: + while true: var eend = strEnd(e) add(environment, $e) e = cast[CString](cast[TAddress](eend)+1) @@ -1308,7 +1308,7 @@ proc createDir*(dir: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} = when defined(doslike): omitNext = isAbsolute(dir) for i in 1.. dir.len-1: - if dir[i] in {dirsep, altsep}: + if dir[i] in {Dirsep, Altsep}: if omitNext: omitNext = false else: @@ -1635,10 +1635,10 @@ proc findExe*(exe: string): string {.tags: [FReadDir, FReadEnv].} = ## in directories listed in the ``PATH`` environment variable. ## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe` ## is added an ``.exe`` file extension if it has no extension. - result = addFileExt(exe, os.exeExt) + result = addFileExt(exe, os.ExeExt) if existsFile(result): return var path = string(os.getEnv("PATH")) - for candidate in split(path, pathSep): + for candidate in split(path, PathSep): var x = candidate / result if existsFile(x): return x result = "" diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index b7e3de6cf..2a6d499a7 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -67,7 +67,7 @@ proc toUpper*(c: char): char {.noSideEffect, procvar, ## Converts `c` into upper case. This works only for the letters a-z. ## See `unicode.toUpper` for a version that works for any Unicode character. if c in {'a'..'z'}: - result = chr(ord(c) - (Ord('a') - Ord('A'))) + result = chr(ord(c) - (ord('a') - ord('A'))) else: result = c @@ -497,31 +497,31 @@ iterator tokenize*(s: string, seps: set[char] = Whitespace): tuple[ proc wordWrap*(s: string, maxLineWidth = 80, splitLongWords = true, - seps: set[char] = whitespace, + seps: set[char] = Whitespace, newLine = "\n"): string {. noSideEffect, rtl, extern: "nsuWordWrap".} = ## word wraps `s`. result = newStringOfCap(s.len + s.len shr 6) - var SpaceLeft = maxLineWidth + var spaceLeft = maxLineWidth for word, isSep in tokenize(s, seps): - if len(word) > SpaceLeft: + if len(word) > spaceLeft: if splitLongWords and len(word) > maxLineWidth: - result.add(substr(word, 0, SpaceLeft-1)) - var w = SpaceLeft+1 - var wordLeft = len(word) - SpaceLeft + result.add(substr(word, 0, spaceLeft-1)) + var w = spaceLeft+1 + var wordLeft = len(word) - spaceLeft while wordLeft > 0: result.add(newLine) var L = min(maxLineWidth, wordLeft) - SpaceLeft = maxLineWidth - L + spaceLeft = maxLineWidth - L result.add(substr(word, w, w+L-1)) inc(w, L) dec(wordLeft, L) else: - SpaceLeft = maxLineWidth - len(word) + spaceLeft = maxLineWidth - len(word) result.add(newLine) result.add(word) else: - SpaceLeft = SpaceLeft - len(word) + spaceLeft = spaceLeft - len(word) result.add(word) proc unindent*(s: string, eatAllIndent = false): string {. diff --git a/lib/pure/times.nim b/lib/pure/times.nim index 6dfe80ca1..246126828 100644 --- a/lib/pure/times.nim +++ b/lib/pure/times.nim @@ -593,7 +593,7 @@ proc format*(info: TTimeInfo, f: string): string = result = "" var i = 0 var currentF = "" - while True: + while true: case f[i] of ' ', '-', '/', ':', '\'', '\0', '(', ')', '[', ']', ',': case currentF diff --git a/lib/system.nim b/lib/system.nim index b320f14dd..ebe722680 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1262,13 +1262,13 @@ proc getRefcount*[T](x: seq[T]): int {.importc: "getRefcount", noSideEffect.} ## retrieves the reference count of an heap-allocated object. The ## value is implementation-dependent. -# new constants: + const - inf* {.magic: "Inf".} = 1.0 / 0.0 + Inf* {.magic: "Inf".} = 1.0 / 0.0 ## contains the IEEE floating point value of positive infinity. - neginf* {.magic: "NegInf".} = -inf + NegInf* {.magic: "NegInf".} = -Inf ## contains the IEEE floating point value of negative infinity. - nan* {.magic: "NaN".} = 0.0 / 0.0 + NaN* {.magic: "NaN".} = 0.0 / 0.0 ## contains an IEEE floating point value of *Not A Number*. Note ## that you cannot compare a floating point value to this value ## and expect a reasonable result - use the `classify` procedure diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index 204d98a2c..954485eb4 100644 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -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) diff --git a/lib/system/assign.nim b/lib/system/assign.nim index 6b7ffaf7b..9e3930622 100644 --- a/lib/system/assign.nim +++ b/lib/system/assign.nim @@ -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: diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 5b00afc5b..1964e4d3d 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -253,7 +253,7 @@ proc reraiseException() {.compilerRtl.} = else: raiseExceptionAux(currException) -proc WriteStackTrace() = +proc writeStackTrace() = when hasSomeStackTrace: var s = "" rawWriteStackTrace(s) diff --git a/lib/system/gc.nim b/lib/system/gc.nim index 2a137d7fb..376d1502c 100644 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -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") diff --git a/lib/system/repr.nim b/lib/system/repr.nim index aacf26653..cd3f7c3f4 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -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, diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 9c0b0c589..2b6ad8df1 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -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 = diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index bca14bb9d..4244bae4c 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -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) |