overload resolution for proc vars

This commit is contained in:
Andreas Rumpf 2009-06-24 17:13:22 +02:00
commit 300430fbba
56 changed files with 2772 additions and 2430 deletions

File diff suppressed because it is too large Load diff

View file

@ -45,27 +45,27 @@ type
nnkCurly, nnkBracket, nnkBracketExpr, nnkPragmaExpr,
nnkRange, nnkDotExpr, nnkCheckedFieldExpr, nnkDerefExpr,
nnkIfExpr, nnkElifExpr, nnkElseExpr, nnkLambda,
nnkAccQuoted, nnkHeaderQuoted, nnkTableConstr, nnkQualified,
nnkHiddenStdConv, nnkHiddenSubConv, nnkHiddenCallConv, nnkConv,
nnkCast, nnkAddr, nnkHiddenAddr, nnkHiddenDeref,
nnkObjDownConv, nnkObjUpConv, nnkChckRangeF, nnkChckRange64,
nnkChckRange, nnkStringToCString, nnkCStringToString, nnkPassAsOpenArray,
nnkAsgn, nnkFastAsgn, nnkDefaultTypeParam, nnkGenericParams,
nnkFormalParams, nnkOfInherit, nnkModule, nnkProcDef,
nnkConverterDef, nnkMacroDef, nnkTemplateDef, nnkIteratorDef,
nnkOfBranch, nnkElifBranch, nnkExceptBranch, nnkElse,
nnkMacroStmt, nnkAsmStmt, nnkPragma, nnkIfStmt,
nnkWhenStmt, nnkForStmt, nnkWhileStmt, nnkCaseStmt,
nnkVarSection, nnkConstSection, nnkConstDef, nnkTypeSection,
nnkTypeDef, nnkYieldStmt, nnkTryStmt, nnkFinally,
nnkRaiseStmt, nnkReturnStmt, nnkBreakStmt, nnkContinueStmt,
nnkBlockStmt, nnkDiscardStmt, nnkStmtList, nnkImportStmt,
nnkFromStmt, nnkImportAs, nnkIncludeStmt, nnkCommentStmt,
nnkStmtListExpr, nnkBlockExpr, nnkStmtListType, nnkBlockType,
nnkVm, nnkTypeOfExpr, nnkObjectTy, nnkTupleTy,
nnkRecList, nnkRecCase, nnkRecWhen, nnkRefTy,
nnkPtrTy, nnkVarTy, nnkAbstractTy, nnkProcTy,
nnkEnumTy, nnkEnumFieldDef, nnkReturnToken
nnkAccQuoted, nnkTableConstr, nnkQualified, nnkBind,
nnkSymChoice, nnkHiddenStdConv, nnkHiddenSubConv, nnkHiddenCallConv,
nnkConv, nnkCast, nnkAddr, nnkHiddenAddr,
nnkHiddenDeref, nnkObjDownConv, nnkObjUpConv, nnkChckRangeF,
nnkChckRange64, nnkChckRange, nnkStringToCString, nnkCStringToString,
nnkPassAsOpenArray, nnkAsgn, nnkFastAsgn, nnkDefaultTypeParam,
nnkGenericParams, nnkFormalParams, nnkOfInherit, nnkModule,
nnkProcDef, nnkConverterDef, nnkMacroDef, nnkTemplateDef,
nnkIteratorDef, nnkOfBranch, nnkElifBranch, nnkExceptBranch,
nnkElse, nnkMacroStmt, nnkAsmStmt, nnkPragma,
nnkIfStmt, nnkWhenStmt, nnkForStmt, nnkWhileStmt,
nnkCaseStmt, nnkVarSection, nnkConstSection, nnkConstDef,
nnkTypeSection, nnkTypeDef, nnkYieldStmt, nnkTryStmt,
nnkFinally, nnkRaiseStmt, nnkReturnStmt, nnkBreakStmt,
nnkContinueStmt, nnkBlockStmt, nnkDiscardStmt, nnkStmtList,
nnkImportStmt, nnkFromStmt, nnkImportAs, nnkIncludeStmt,
nnkCommentStmt, nnkStmtListExpr, nnkBlockExpr, nnkStmtListType,
nnkBlockType, nnkVm, nnkTypeOfExpr, nnkObjectTy,
nnkTupleTy, nnkRecList, nnkRecCase, nnkRecWhen,
nnkRefTy, nnkPtrTy, nnkVarTy, nnkAbstractTy,
nnkProcTy, nnkEnumTy, nnkEnumFieldDef, nnkReturnToken
TNimNodeKinds* = set[TNimrodNodeKind]
TNimrodTypeKind* = enum
ntyNone, ntyBool, ntyChar, ntyEmpty,

View file

@ -556,9 +556,9 @@ proc sameFileContent*(path1, path2: string): bool =
bufSize = 8192 # 8K buffer
var
a, b: TFile
if not openFile(a, path1): return false
if not openFile(b, path2):
closeFile(a)
if not open(a, path1): return false
if not open(b, path2):
close(a)
return false
var bufA = alloc(bufsize)
var bufB = alloc(bufsize)
@ -576,8 +576,8 @@ proc sameFileContent*(path1, path2: string): bool =
if readA != bufSize: break # end of file
dealloc(bufA)
dealloc(bufB)
closeFile(a)
closeFile(b)
close(a)
close(b)
proc copyFile*(dest, source: string) =
## Copies a file from `source` to `dest`. If this fails,
@ -590,9 +590,9 @@ proc copyFile*(dest, source: string) =
bufSize = 8192 # 8K buffer
var
d, s: TFile
if not openFile(s, source): OSError()
if not openFile(d, dest, fmWrite):
closeFile(s)
if not open(s, source): OSError()
if not open(d, dest, fmWrite):
close(s)
OSError()
var
buf: Pointer = alloc(bufsize)
@ -603,8 +603,8 @@ proc copyFile*(dest, source: string) =
if bytesread != bufSize: break
if bytesread != bytesWritten: OSError()
dealloc(buf)
closeFile(s)
closeFile(d)
close(s)
close(d)
proc moveFile*(dest, source: string) =
## Moves a file from `source` to `dest`. If this fails, `EOS` is raised.
@ -954,7 +954,7 @@ proc getHomeDir*(): string =
when defined(windows): return getEnv("USERPROFILE") & "\\"
else: return getEnv("HOME") & "/"
proc getConfigDir*(): string {.noSideEffect.} =
proc getConfigDir*(): string =
## Returns the config directory of the current user for applications.
when defined(windows): return getEnv("APPDATA") & "\\"
else: return getEnv("HOME") & "/.config/"

View file

@ -405,17 +405,17 @@ else:
proc inputStream(p: PProcess): PStream =
var f: TFile
if not openFile(f, p.inputHandle, fmWrite): OSError()
if not open(f, p.inputHandle, fmWrite): OSError()
result = newFileStream(f)
proc outputStream(p: PProcess): PStream =
var f: TFile
if not openFile(f, p.outputHandle, fmRead): OSError()
if not open(f, p.outputHandle, fmRead): OSError()
result = newFileStream(f)
proc errorStream(p: PProcess): PStream =
var f: TFile
if not openFile(f, p.errorHandle, fmRead): OSError()
if not open(f, p.errorHandle, fmRead): OSError()
result = newFileStream(f)
proc csystem(cmd: cstring): cint {.nodecl, importc: "system".}

View file

@ -152,3 +152,25 @@ const ## common regular expressions
reURL* = r"\b(http(s)?|ftp|gopher|telnet|file|notes|ms\-help):" &
r"((//)|(\\\\))+[\w\d:#@%/;$()~_?\+\-\=\\\.\&]*\b"
## describes an URL
proc verbose*(pattern: string): string {.noSideEffect.} =
## deletes whitespace from a pattern that is not escaped or in a character
## class. This is modelled after Perl's ``/x`` modifier.
result = ""
var i = 0
while i < pattern.len:
case pattern[i]
of ' ', '\t':
inc i
of '\\':
add result, '\\'
add result, pattern[i+1]
inc i, 2
of '[':
while pattern[i] != ']' and pattern[i] != '\0':
add result, pattern[i]
inc i
else:
add result, pattern[i]
inc i

View file

@ -144,7 +144,7 @@ type
TFileStream* = object of TStream
f: TFile
proc fsClose(s: PFileStream) = closeFile(s.f)
proc fsClose(s: PFileStream) = close(s.f)
proc fsAtEnd(s: PFileStream): bool = return EndOfFile(s.f)
proc fsSetPosition(s: PFileStream, pos: int) = setFilePos(s.f, pos)
proc fsGetPosition(s: PFileStream): int = return int(getFilePos(s.f))
@ -171,7 +171,7 @@ proc newFileStream*(filename: string, mode: TFileMode): PFileStream =
## creates a new stream from the file named `filename` with the mode `mode`.
## If the file cannot be opened, nil is returned.
var f: TFile
if OpenFile(f, filename, mode): result = newFileStream(f)
if Open(f, filename, mode): result = newFileStream(f)
when true:

View file

@ -150,15 +150,18 @@ proc find*(s: string, chars: set[char], start: int = 0): int {.noSideEffect.}
## Searches for `chars` in `s` starting at position `start`. If `s` contains
## none of the characters in `chars`, -1 is returned.
proc replaceStr*(s, sub, by: string): string {.noSideEffect.}
proc replaceStr*(s, sub, by: string): string {.noSideEffect, deprecated.}
## Replaces `sub` in `s` by the string `by`.
## **Deprecated since version 0.8.0**: Use `replace` instead.
proc replaceStr*(s: string, sub, by: char): string {.noSideEffect.}
proc replaceStr*(s: string, sub, by: char): string {.noSideEffect, deprecated.}
## optimized version for characters.
## **Deprecated since version 0.8.0**: Use `replace` instead.
proc deleteStr*(s: var string, first, last: int)
proc deleteStr*(s: var string, first, last: int) {.deprecated.}
## Deletes in `s` the characters at position `first`..`last`. This modifies
## `s` itself, it does not return a copy.
## **Deprecated since version 0.8.0**: Use `delete` instead.
proc toOctal*(c: char): string
## Converts a character `c` to its octal representation. The resulting
@ -185,7 +188,7 @@ iterator split*(s: string, seps: set[char] = Whitespace): string =
## for word in split(";;this;is;an;;example;;;", {';'}):
## writeln(stdout, word)
##
## produces in the same output.
## produces the same output.
var
first: int = 0
last: int = 0
@ -315,17 +318,15 @@ proc intToStr*(x: int, minchars: int = 1): string
proc ParseInt*(s: string): int {.noSideEffect.}
## Parses a decimal integer value contained in `s`. If `s` is not
## a valid integer, `EInvalidValue` is raised.
# XXX: make this biggestint!
proc ParseBiggestInt*(s: string): biggestInt {.noSideEffect.}
## Parses a decimal integer value contained in `s`. If `s` is not
## a valid integer, `EInvalidValue` is raised.
proc ParseFloat*(s: string, start = 0): float {.noSideEffect.}
proc ParseFloat*(s: string): float {.noSideEffect.}
## Parses a decimal floating point value contained in `s`. If `s` is not
## a valid floating point number, `EInvalidValue` is raised. ``NAN``,
## ``INF``, ``-INF`` are also supported (case insensitive comparison).
# XXX: make this biggestfloat.
# the stringify and format operators:
proc toString*[Ty](x: Ty): string
@ -439,10 +440,15 @@ proc findNormalized(x: string, inArray: openarray[string]): int =
proc addf(s: var string, formatstr: string, a: openarray[string]) =
const PatternChars = {'a'..'z', 'A'..'Z', '0'..'9', '\128'..'\255', '_'}
var i = 0
var num = 0
while i < len(formatstr):
if formatstr[i] == '$':
case formatstr[i+1] # again we use the fact that strings
# are zero-terminated here
of '#':
add s, a[num]
inc i, 2
inc num
of '$':
add s, '$'
inc(i, 2)
@ -452,6 +458,7 @@ proc addf(s: var string, formatstr: string, a: openarray[string]) =
while formatstr[i] in {'0'..'9'}:
j = j * 10 + ord(formatstr[i]) - ord('0')
inc(i)
num = j
add s, a[j - 1]
of '{':
var j = i+1
@ -510,6 +517,31 @@ proc splitSeq(s: string, seps: set[char]): seq[string] =
# ---------------------------------------------------------------------------
proc join*(a: openArray[string], sep: string): string =
## concatenates all strings in `a` separating them with `sep`.
if len(a) > 0:
var L = sep.len * (a.len-1)
for i in 0..high(a): inc(L, a[i].len)
result = newString(L)
setLen(result, 0)
add(result, a[0])
for i in 1..high(a):
add(result, sep)
add(result, a[i])
else:
result = ""
proc join*(a: openArray[string]): string =
## concatenates all strings in `a`.
if len(a) > 0:
var L = 0
for i in 0..high(a): inc(L, a[i].len)
result = newString(L)
setLen(result, 0)
for i in 0..high(a): add(result, a[i])
else:
result = ""
proc strip(s: string, leading = true, trailing = true): string =
const
chars: set[Char] = Whitespace
@ -638,7 +670,8 @@ proc contains(s: string, c: char): bool =
proc contains(s, sub: string): bool =
return find(s, sub) >= 0
proc replaceStr(s, sub, by: string): string =
proc replace*(s, sub, by: string): string =
## Replaces `sub` in `s` by the string `by`.
var a: TSkipTable
result = ""
preprocessSub(sub, a)
@ -652,7 +685,8 @@ proc replaceStr(s, sub, by: string): string =
# copy the rest:
add result, copy(s, i)
proc replaceStr(s: string, sub, by: char): string =
proc replace*(s: string, sub, by: char): string =
## optimized version for characters.
result = newString(s.len)
var i = 0
while i < s.len:
@ -660,17 +694,23 @@ proc replaceStr(s: string, sub, by: char): string =
else: result[i] = s[i]
inc(i)
proc deleteStr(s: var string, first, last: int) =
proc delete*(s: var string, first, last: int) =
## Deletes in `s` the characters at position `first`..`last`. This modifies
## `s` itself, it does not return a copy.
var
i = first
# example: "abc___uvwxyz\0" (___ is to be deleted)
# --> first == 3, last == 5
# s[first..] = s[last+1..]
var
i = first
while last+i+1 < len(s):
s[i] = s[last+i+1]
inc(i)
setlen(s, len(s)-(last-first+1))
proc replaceStr(s, sub, by: string): string = return replace(s, sub, by)
proc replaceStr(s: string, sub, by: char): string = return replace(s, sub, by)
proc deleteStr*(s: var string, first, last: int) = delete(s, first, last)
# parsing numbers:
proc toHex(x: BiggestInt, len: int): string =
@ -734,11 +774,11 @@ proc ParseBiggestInt(s: string): biggestInt =
if index == -1:
raise newException(EInvalidValue, "invalid integer: " & s)
proc ParseFloat(s: string, start = 0): float =
proc ParseFloat(s: string): float =
var
esign = 1.0
sign = 1.0
i = start
i = 0
exponent: int
flags: int
result = 0.0

View file

@ -69,11 +69,12 @@ proc `or`*(x, y: bool): bool {.magic: "Or", noSideEffect.}
proc `xor`*(x, y: bool): bool {.magic: "Xor", noSideEffect.}
## Boolean `exclusive or`; returns true iff ``x != y``.
proc new*[T](a: var ref T) {.magic: "New".}
proc new*[T](a: var ref T) {.magic: "New", noSideEffect.}
## creates a new object of type ``T`` and returns a safe (traced)
## reference to it in ``a``.
proc new*[T](a: var ref T, finalizer: proc (x: ref T)) {.magic: "NewFinalize".}
proc new*[T](a: var ref T, finalizer: proc (x: ref T)) {.
magic: "NewFinalize", noSideEffect.}
## creates a new object of type ``T`` and returns a safe (traced)
## reference to it in ``a``. When the garbage collector frees the object,
## `finalizer` is called. The `finalizer` may not keep a reference to the
@ -230,17 +231,17 @@ proc pred*[T](x: ordinal[T], y = 1): T {.magic: "Pred", noSideEffect.}
## an ordinal type. If such a value does not exist, ``EOutOfRange`` is raised
## or a compile time error occurs.
proc inc*[T](x: var ordinal[T], y = 1) {.magic: "Inc".}
proc inc*[T](x: var ordinal[T], y = 1) {.magic: "Inc", noSideEffect.}
## increments the ordinal ``x`` by ``y``. If such a value does not
## exist, ``EOutOfRange`` is raised or a compile time error occurs. This is a
## short notation for: ``x = succ(x, y)``.
proc dec*[T](x: var ordinal[T], y = 1) {.magic: "Dec".}
proc dec*[T](x: var ordinal[T], y = 1) {.magic: "Dec", noSideEffect.}
## decrements the ordinal ``x`` by ``y``. If such a value does not
## exist, ``EOutOfRange`` is raised or a compile time error occurs. This is a
## short notation for: ``x = pred(x, y)``.
proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq".}
proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.}
## creates a new sequence of type ``seq[T]`` with length ``len``.
## This is equivalent to ``s = []; setlen(s, len)``, but more
## efficient since no relocation is needed.
@ -255,11 +256,11 @@ proc len*[T](x: seq[T]): int {.magic: "LengthSeq", noSideEffect.}
## always an int.
# set routines:
proc incl*[T](x: var set[T], y: T) {.magic: "Incl".}
proc incl*[T](x: var set[T], y: T) {.magic: "Incl", noSideEffect.}
## includes element ``y`` to the set ``x``. This is the same as
## ``x = x + {y}``, but it might be more efficient.
proc excl*[T](x: var set[T], y: T) {.magic: "Excl".}
proc excl*[T](x: var set[T], y: T) {.magic: "Excl", noSideEffect.}
## excludes element ``y`` to the set ``x``. This is the same as
## ``x = x - {y}``, but it might be more efficient.
@ -641,8 +642,8 @@ proc `&` * (x: char, y: string): string {.
magic: "ConStrStr", noSideEffect, merge.}
## is the `concatenation operator`. It concatenates `x` and `y`.
proc add*(x: var string, y: char) {.magic: "AppendStrCh".}
proc add*(x: var string, y: string) {.magic: "AppendStrStr".}
proc add*(x: var string, y: char) {.magic: "AppendStrCh", noSideEffect.}
proc add*(x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
when not defined(ECMAScript):
{.push overflow_checks:off}
@ -663,8 +664,8 @@ else:
`x`[0][len] = 0
"""
proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem".}
proc add *[T](x: var seq[T], y: seq[T]) {.magic: "AppendSeqSeq".}
proc add *[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}
proc add *[T](x: var seq[T], y: seq[T]) {.magic: "AppendSeqSeq", noSideEffect.}
## Generic proc for adding a data item `y` to a container `x`.
## For containers that have an order, `add` means *append*. New generic
## containers should also call their adding proc `add` for consistency.
@ -811,7 +812,8 @@ proc copy*(s: string, first, last: int): string {.
## the first and last characters that shall be copied. If ``last``
## is omitted, it is treated as ``high(s)``.
proc setLen*(s: var string, newlen: int) {.magic: "SetLengthStr".}
proc setLen*(s: var string, newlen: int) {.
magic: "SetLengthStr", noSideEffect.}
## sets the length of `s` to `newlen`.
## If the current length is greater than the new length,
## ``s`` will be truncated.
@ -873,20 +875,21 @@ proc dealloc*(p: Pointer) {.noconv.}
## or other memory may be corrupted. So this procedure is really
## *unsafe*.
proc setLen*[T](s: var seq[T], newlen: int) {.magic: "SetLengthSeq".}
proc setLen*[T](s: var seq[T], newlen: int) {.
magic: "SetLengthSeq", noSideEffect.}
## sets the length of `s` to `newlen`.
## ``T`` may be any sequence type.
## If the current length is greater than the new length,
## ``s`` will be truncated.
proc assert*(cond: bool) {.magic: "Assert".}
proc assert*(cond: bool) {.magic: "Assert", noSideEffect.}
## provides a means to implement `programming by contracts` in Nimrod.
## ``assert`` evaluates expression ``cond`` and if ``cond`` is false, it
## raises an ``EAssertionFailure`` exception. However, the compiler may
## not generate any code at all for ``assert`` if it is advised to do so.
## Thus one should use ``assert`` for debugging purposes only.
proc swap*[T](a, b: var T) {.magic: "Swap".}
proc swap*[T](a, b: var T) {.magic: "Swap", noSideEffect.}
## swaps the values `a` and `b`. This is often more efficient than
## ``tmp = a; a = b; b = tmp``. Particularly useful for sorting algorithms.
@ -934,7 +937,7 @@ proc `$` *[T](x: ordinal[T]): string {.magic: "EnumToStr", noSideEffect.}
## used instead. (In other words: *Overwriting* is possible.)
# undocumented:
proc getRefcount*[T](x: ref T): int {.importc: "getRefcount".}
proc getRefcount*[T](x: ref T): int {.importc: "getRefcount", noSideEffect.}
## retrieves the reference count of an heap-allocated object. The
## value is implementation-dependant.
@ -1107,18 +1110,19 @@ proc find*[T, S](a: T, item: S): int {.inline.} =
inc(result)
result = -1
proc pop*[T](s: var seq[T]): T {.inline.} =
proc pop*[T](s: var seq[T]): T {.inline, noSideEffect.} =
## returns the last item of `s` and decreases ``s.len`` by one. This treats
## `s` as a stack and implements the common *pop* operation.
var L = s.len-1
result = s[L]
setLen(s, L)
proc each*[T, S](data: openArray[T], op: proc (x: T): S): seq[S] =
proc each*[T, S](data: openArray[T], op: proc (x: T): S): seq[S] {.
noSideEffect.} =
## The well-known ``map`` operation from functional programming. Applies
## `op` to every item in `data` and returns the result as a sequence.
result = @[]
for d in items(data): add(result, op(d))
newSeq(result, data.len)
for i in 0..data.len-1: result[i] = op(data[i])
# ----------------- FPU ------------------------------------------------------
@ -1293,7 +1297,16 @@ when not defined(EcmaScript) and not defined(NimrodVM):
## does not work because the program writes to ``stderr``.
proc OpenFile*(f: var TFile, filename: string,
mode: TFileMode = fmRead, bufSize: int = -1): Bool
mode: TFileMode = fmRead,
bufSize: int = -1): Bool {.deprecated.}
## **Deprecated since version 0.8.0**: Use `open` instead.
proc OpenFile*(f: var TFile, filehandle: TFileHandle,
mode: TFileMode = fmRead): Bool {.deprecated.}
## **Deprecated since version 0.8.0**: Use `open` instead.
proc Open*(f: var TFile, filename: string,
mode: TFileMode = fmRead, bufSize: int = -1): Bool
## Opens a file named `filename` with given `mode`.
##
## Default mode is readonly. Returns true iff the file could be opened.
@ -1301,14 +1314,19 @@ when not defined(EcmaScript) and not defined(NimrodVM):
## that the programmer needs to provide an appropriate error message anyway
## (yes, even in scripts).
proc OpenFile*(f: var TFile, filehandle: TFileHandle,
mode: TFileMode = fmRead): Bool
proc Open*(f: var TFile, filehandle: TFileHandle,
mode: TFileMode = fmRead): Bool
## Creates a ``TFile`` from a `filehandle` with given `mode`.
##
## Default mode is readonly. Returns true iff the file could be opened.
proc CloseFile*(f: TFile) {.importc: "fclose", nodecl.}
proc CloseFile*(f: TFile) {.importc: "fclose", nodecl, deprecated.}
## Closes the file.
## **Deprecated since version 0.8.0**: Use `close` instead.
proc Close*(f: TFile) {.importc: "fclose", nodecl.}
## Closes the file.
proc EndOfFile*(f: TFile): Bool
## Returns true iff `f` is at the end.
proc readChar*(f: TFile): char {.importc: "fgetc", nodecl.}
@ -1394,13 +1412,13 @@ when not defined(EcmaScript) and not defined(NimrodVM):
## If the file does not exist `EIO` is raised.
var
f: TFile
if not openFile(f, filename):
if not open(f, filename):
raise newException(EIO, "cannot open: " & filename)
var res = ""
while not endOfFile(f):
rawReadLine(f, res)
yield res
CloseFile(f)
Close(f)
proc fileHandle*(f: TFile): TFileHandle {.importc: "fileno",
header: "<stdio.h>"}

View file

@ -13,10 +13,11 @@
{.push hints:off}
proc c_strcmp(a, b: CString): cint {.nodecl, importc: "strcmp".}
proc c_memcmp(a, b: CString, size: cint): cint {.nodecl, importc: "memcmp".}
proc c_strcmp(a, b: CString): cint {.nodecl, noSideEffect, importc: "strcmp".}
proc c_memcmp(a, b: CString, size: cint): cint {.
nodecl, noSideEffect, importc: "memcmp".}
proc c_memcpy(a, b: CString, size: cint) {.nodecl, importc: "memcpy".}
proc c_strlen(a: CString): int {.nodecl, importc: "strlen".}
proc c_strlen(a: CString): int {.nodecl, noSideEffect, importc: "strlen".}
proc c_memset(p: pointer, value: cint, size: int) {.nodecl, importc: "memset".}
type

View file

@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2008 Andreas Rumpf
# (c) Copyright 2009 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@ -10,11 +10,11 @@
# simple integer arithmetic with overflow checking
proc raiseOverflow {.compilerproc, noinline.} =
proc raiseOverflow {.compilerproc, noinline, noreturn.} =
# a single proc to reduce code size to a minimum
raise newException(EOverflow, "over- or underflow")
proc raiseDivByZero {.compilerproc, noinline.} =
proc raiseDivByZero {.compilerproc, noinline, noreturn.} =
raise newException(EDivByZero, "divison by zero")
proc addInt64(a, b: int64): int64 {.compilerProc, inline.} =

View file

@ -81,7 +81,7 @@ proc ListBreakPoints() =
write(stdout, "***\n")
proc openAppend(filename: string): TFile =
if openFile(result, filename, fmAppend):
if open(result, filename, fmAppend):
write(result, "----------------------------------------\n")
proc dbgRepr(p: pointer, typ: PNimType): string =
@ -329,7 +329,7 @@ proc dbgOut(s: string, start: int, currFrame: PExtendedFrame) =
debugOut("[Warning] could not open or create file ")
return
dbgEvaluate(stream, s, i, currFrame)
closeFile(stream)
close(stream)
proc dbgStackFrame(s: string, start: int, currFrame: PExtendedFrame) =
var dbgTemp: string
@ -343,7 +343,7 @@ proc dbgStackFrame(s: string, start: int, currFrame: PExtendedFrame) =
debugOut("[Warning] could not open or create file ")
return
ListFrame(stream, currFrame)
closeFile(stream)
close(stream)
proc CommandPrompt() =
# if we return from this routine, user code executes again

View file

@ -71,13 +71,13 @@ proc write(f: TFile, a: openArray[string]) =
proc readFile(filename: string): string =
var f: TFile
try:
if openFile(f, filename):
if open(f, filename):
var len = getFileSize(f)
if len < high(int):
result = newString(int(len))
if readBuffer(f, addr(result[0]), int(len)) != len:
result = nil
closeFile(f)
close(f)
else:
result = nil
except EIO:
@ -112,9 +112,9 @@ const
# should not be translated.
proc OpenFile(f: var TFile, filename: string,
mode: TFileMode = fmRead,
bufSize: int = -1): Bool =
proc Open(f: var TFile, filename: string,
mode: TFileMode = fmRead,
bufSize: int = -1): Bool =
var
p: pointer
p = fopen(filename, FormatOpen[mode])
@ -129,10 +129,18 @@ proc OpenFile(f: var TFile, filename: string,
proc fdopen(filehandle: TFileHandle, mode: cstring): TFile {.
importc: pccHack & "fdopen", header: "<stdio.h>".}
proc openFile(f: var TFile, filehandle: TFileHandle, mode: TFileMode): bool =
proc open(f: var TFile, filehandle: TFileHandle, mode: TFileMode): bool =
f = fdopen(filehandle, FormatOpen[mode])
result = f != nil
proc OpenFile(f: var TFile, filename: string,
mode: TFileMode = fmRead,
bufSize: int = -1): Bool =
result = open(f, filename, mode, bufSize)
proc openFile(f: var TFile, filehandle: TFileHandle, mode: TFileMode): bool =
result = open(f, filehandle, mode)
# C routine that is used here:
proc fread(buf: Pointer, size, n: int, f: TFile): int {.
importc: "fread", noDecl.}

View file

@ -786,7 +786,7 @@ type
mem_root*: MEM_ROOT # root allocations
mysql*: PMYSQL # connection handle
params*: PMYSQL_BIND # input parameters
bind*: PMYSQL_BIND # input parameters
`bind`*: PMYSQL_BIND # input parameters
fields*: PMYSQL_FIELD # result set metadata
result*: MYSQL_DATA # cached result set
data_cursor*: PMYSQL_ROWS # current row in cached result
@ -1042,7 +1042,7 @@ proc mysql_stmt_execute*(stmt: PMYSQL_STMT): cint{.stdcall, dynlib: mysqllib,
importc: "mysql_stmt_execute".}
proc mysql_stmt_fetch*(stmt: PMYSQL_STMT): cint{.stdcall, dynlib: mysqllib,
importc: "mysql_stmt_fetch".}
proc mysql_stmt_fetch_column*(stmt: PMYSQL_STMT, bind: PMYSQL_BIND,
proc mysql_stmt_fetch_column*(stmt: PMYSQL_STMT, `bind`: PMYSQL_BIND,
column: cuint, offset: int): cint{.stdcall,
dynlib: mysqllib, importc: "mysql_stmt_fetch_column".}
proc mysql_stmt_store_result*(stmt: PMYSQL_STMT): cint{.stdcall,