Use more Natural and Positive numbers in proc parameters

- Didn't go through all modules, only the main ones I thought of
- Building the compiler and tests still work
This commit is contained in:
def 2015-04-06 01:51:28 +02:00
commit 22b4e4c2f2
10 changed files with 1196 additions and 1196 deletions

View file

@ -16,7 +16,7 @@
# of the standard library!
proc fputs(c: cstring, f: File) {.importc: "fputs", header: "<stdio.h>",
proc fputs(c: cstring, f: File) {.importc: "fputs", header: "<stdio.h>",
tags: [WriteIOEffect].}
proc fgets(c: cstring, n: int, f: File): cstring {.
importc: "fgets", header: "<stdio.h>", tags: [ReadIOEffect].}
@ -26,7 +26,7 @@ proc ungetc(c: cint, f: File) {.importc: "ungetc", header: "<stdio.h>",
tags: [].}
proc putc(c: char, stream: File) {.importc: "putc", header: "<stdio.h>",
tags: [WriteIOEffect].}
proc fprintf(f: File, frmt: cstring) {.importc: "fprintf",
proc fprintf(f: File, frmt: cstring) {.importc: "fprintf",
header: "<stdio.h>", varargs, tags: [WriteIOEffect].}
proc strlen(c: cstring): int {.
importc: "strlen", header: "<string.h>", tags: [].}
@ -88,18 +88,18 @@ proc readLine(f: File): TaintedString =
result = TaintedString(newStringOfCap(80))
if not readLine(f, result): raiseEIO("EOF reached")
proc write(f: File, i: int) =
proc write(f: File, i: int) =
when sizeof(int) == 8:
fprintf(f, "%lld", i)
else:
fprintf(f, "%ld", i)
proc write(f: File, i: BiggestInt) =
proc write(f: File, i: BiggestInt) =
when sizeof(BiggestInt) == 8:
fprintf(f, "%lld", i)
else:
fprintf(f, "%ld", i)
proc write(f: File, b: bool) =
if b: write(f, "true")
else: write(f, "false")
@ -110,7 +110,7 @@ proc write(f: File, c: char) = putc(c, f)
proc write(f: File, a: varargs[string, `$`]) =
for x in items(a): write(f, x)
proc readAllBuffer(file: File): string =
proc readAllBuffer(file: File): string =
# This proc is for File we want to read but don't know how many
# bytes we need to read before the buffer is empty.
result = ""
@ -123,8 +123,8 @@ proc readAllBuffer(file: File): string =
buffer.setLen(bytesRead)
result.add(buffer)
break
proc rawFileSize(file: File): int =
proc rawFileSize(file: File): int =
# this does not raise an error opposed to `getFileSize`
var oldPos = ftell(file)
discard fseek(file, 0, 2) # seek the end of the file
@ -141,8 +141,8 @@ proc readAllFile(file: File, len: int): string =
proc readAllFile(file: File): string =
var len = rawFileSize(file)
result = readAllFile(file, len)
proc readAll(file: File): TaintedString =
proc readAll(file: File): TaintedString =
# Separate handling needed because we need to buffer when we
# don't know the overall length of the File.
let len = if file != stdin: rawFileSize(file) else: -1
@ -150,7 +150,7 @@ proc readAll(file: File): TaintedString =
result = readAllFile(file, len).TaintedString
else:
result = readAllBuffer(file).TaintedString
proc readFile(filename: string): TaintedString =
var f = open(filename)
try:
@ -229,7 +229,7 @@ proc open(f: var File, filename: string,
elif bufSize == 0:
discard setvbuf(f, nil, IONBF, 0)
proc reopen(f: File, filename: string, mode: FileMode = fmRead): bool =
proc reopen(f: File, filename: string, mode: FileMode = fmRead): bool =
var p: pointer = freopen(filename, FormatOpen[mode], f)
result = p != nil
@ -243,23 +243,23 @@ proc open(f: var File, filehandle: FileHandle, mode: FileMode): bool =
proc fwrite(buf: pointer, size, n: int, f: File): int {.
importc: "fwrite", noDecl.}
proc readBuffer(f: File, buffer: pointer, len: int): int =
proc readBuffer(f: File, buffer: pointer, len: Natural): int =
result = fread(buffer, 1, len, f)
proc readBytes(f: File, a: var openArray[int8|uint8], start, len: int): int =
proc readBytes(f: File, a: var openArray[int8|uint8], start, len: Natural): int =
result = readBuffer(f, addr(a[start]), len)
proc readChars(f: File, a: var openArray[char], start, len: int): int =
proc readChars(f: File, a: var openArray[char], start, len: Natural): int =
result = readBuffer(f, addr(a[start]), len)
{.push stackTrace:off, profiler:off.}
proc writeBytes(f: File, a: openArray[int8|uint8], start, len: int): int =
proc writeBytes(f: File, a: openArray[int8|uint8], start, len: Natural): int =
var x = cast[ptr array[0..1000_000_000, int8]](a)
result = writeBuffer(f, addr(x[start]), len)
proc writeChars(f: File, a: openArray[char], start, len: int): int =
proc writeChars(f: File, a: openArray[char], start, len: Natural): int =
var x = cast[ptr array[0..1000_000_000, int8]](a)
result = writeBuffer(f, addr(x[start]), len)
proc writeBuffer(f: File, buffer: pointer, len: int): int =
proc writeBuffer(f: File, buffer: pointer, len: Natural): int =
result = fwrite(buffer, 1, len, f)
proc write(f: File, s: string) =