styleCheck: make the compiler and large parts of the stdlib compatible with --styleCheck:error
This commit is contained in:
parent
96523cdd3e
commit
c94647aeca
90 changed files with 680 additions and 652 deletions
|
|
@ -1007,7 +1007,7 @@ template instantiateForRegion(allocator: untyped) =
|
|||
dealloc(allocator, p)
|
||||
|
||||
proc realloc(p: pointer, newsize: Natural): pointer =
|
||||
result = realloc(allocator, p, newSize)
|
||||
result = realloc(allocator, p, newsize)
|
||||
|
||||
when false:
|
||||
proc countFreeMem(): int =
|
||||
|
|
@ -1060,7 +1060,7 @@ template instantiateForRegion(allocator: untyped) =
|
|||
result = realloc(sharedHeap, p, newsize)
|
||||
releaseSys(heapLock)
|
||||
else:
|
||||
result = realloc(p, newSize)
|
||||
result = realloc(p, newsize)
|
||||
|
||||
when hasThreadSupport:
|
||||
template sharedMemStatsShared(v: int) =
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ proc c_signal*(sign: cint, handler: proc (a: cint) {.noconv.}): CSighandlerT {.
|
|||
|
||||
type
|
||||
CFile {.importc: "FILE", header: "<stdio.h>",
|
||||
incompletestruct.} = object
|
||||
incompleteStruct.} = object
|
||||
CFilePtr* = ptr CFile ## The type representing a file handle.
|
||||
|
||||
var
|
||||
|
|
@ -142,7 +142,7 @@ proc c_realloc*(p: pointer, newsize: csize): pointer {.
|
|||
proc c_fwrite*(buf: pointer, size, n: csize, f: CFilePtr): cint {.
|
||||
importc: "fwrite", header: "<stdio.h>".}
|
||||
|
||||
proc rawWrite*(f: CFilePtr, s: cstring) {.compilerproc, nonreloadable, inline.} =
|
||||
proc rawWrite*(f: CFilePtr, s: cstring) {.compilerproc, nonReloadable, inline.} =
|
||||
# we cannot throw an exception here!
|
||||
discard c_fwrite(s, 1, s.len, f)
|
||||
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@ when defined(builtinOverflow):
|
|||
proc mulIntOverflow(a, b: int, c: var int): bool {.
|
||||
importc: "__builtin_smul_overflow", nodecl, nosideeffect.}
|
||||
|
||||
proc addInt64(a, b: int64): int64 {.compilerProc, inline.} =
|
||||
proc addInt64(a, b: int64): int64 {.compilerproc, inline.} =
|
||||
if addInt64Overflow(a, b, result):
|
||||
raiseOverflow()
|
||||
|
||||
proc subInt64(a, b: int64): int64 {.compilerProc, inline.} =
|
||||
proc subInt64(a, b: int64): int64 {.compilerproc, inline.} =
|
||||
if subInt64Overflow(a, b, result):
|
||||
raiseOverflow()
|
||||
|
||||
|
|
@ -71,13 +71,13 @@ when defined(builtinOverflow):
|
|||
if mulInt64Overflow(a, b, result):
|
||||
raiseOverflow()
|
||||
else:
|
||||
proc addInt64(a, b: int64): int64 {.compilerProc, inline.} =
|
||||
proc addInt64(a, b: int64): int64 {.compilerproc, inline.} =
|
||||
result = a +% b
|
||||
if (result xor a) >= int64(0) or (result xor b) >= int64(0):
|
||||
return result
|
||||
raiseOverflow()
|
||||
|
||||
proc subInt64(a, b: int64): int64 {.compilerProc, inline.} =
|
||||
proc subInt64(a, b: int64): int64 {.compilerproc, inline.} =
|
||||
result = a -% b
|
||||
if (result xor a) >= int64(0) or (result xor not b) >= int64(0):
|
||||
return result
|
||||
|
|
@ -126,29 +126,29 @@ else:
|
|||
return result
|
||||
raiseOverflow()
|
||||
|
||||
proc negInt64(a: int64): int64 {.compilerProc, inline.} =
|
||||
proc negInt64(a: int64): int64 {.compilerproc, inline.} =
|
||||
if a != low(int64): return -a
|
||||
raiseOverflow()
|
||||
|
||||
proc absInt64(a: int64): int64 {.compilerProc, inline.} =
|
||||
proc absInt64(a: int64): int64 {.compilerproc, inline.} =
|
||||
if a != low(int64):
|
||||
if a >= 0: return a
|
||||
else: return -a
|
||||
raiseOverflow()
|
||||
|
||||
proc divInt64(a, b: int64): int64 {.compilerProc, inline.} =
|
||||
proc divInt64(a, b: int64): int64 {.compilerproc, inline.} =
|
||||
if b == int64(0):
|
||||
raiseDivByZero()
|
||||
if a == low(int64) and b == int64(-1):
|
||||
raiseOverflow()
|
||||
return a div b
|
||||
|
||||
proc modInt64(a, b: int64): int64 {.compilerProc, inline.} =
|
||||
proc modInt64(a, b: int64): int64 {.compilerproc, inline.} =
|
||||
if b == int64(0):
|
||||
raiseDivByZero()
|
||||
return a mod b
|
||||
|
||||
proc absInt(a: int): int {.compilerProc, inline.} =
|
||||
proc absInt(a: int): int {.compilerproc, inline.} =
|
||||
if a != low(int):
|
||||
if a >= 0: return a
|
||||
else: return -a
|
||||
|
|
@ -164,7 +164,7 @@ const
|
|||
when asmVersion and not defined(gcc) and not defined(llvm_gcc):
|
||||
# assembler optimized versions for compilers that
|
||||
# have an intel syntax assembler:
|
||||
proc addInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
||||
proc addInt(a, b: int): int {.compilerproc, asmNoStackFrame.} =
|
||||
# a in eax, and b in edx
|
||||
asm """
|
||||
mov eax, ecx
|
||||
|
|
@ -175,7 +175,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc):
|
|||
ret
|
||||
"""
|
||||
|
||||
proc subInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
||||
proc subInt(a, b: int): int {.compilerproc, asmNoStackFrame.} =
|
||||
asm """
|
||||
mov eax, ecx
|
||||
sub eax, edx
|
||||
|
|
@ -185,7 +185,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc):
|
|||
ret
|
||||
"""
|
||||
|
||||
proc negInt(a: int): int {.compilerProc, asmNoStackFrame.} =
|
||||
proc negInt(a: int): int {.compilerproc, asmNoStackFrame.} =
|
||||
asm """
|
||||
mov eax, ecx
|
||||
neg eax
|
||||
|
|
@ -195,7 +195,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc):
|
|||
ret
|
||||
"""
|
||||
|
||||
proc divInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
||||
proc divInt(a, b: int): int {.compilerproc, asmNoStackFrame.} =
|
||||
asm """
|
||||
test edx, edx
|
||||
jne L_NOT_ZERO
|
||||
|
|
@ -214,7 +214,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc):
|
|||
ret
|
||||
"""
|
||||
|
||||
proc modInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
||||
proc modInt(a, b: int): int {.compilerproc, asmNoStackFrame.} =
|
||||
asm """
|
||||
test edx, edx
|
||||
jne L_NOT_ZERO
|
||||
|
|
@ -234,7 +234,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc):
|
|||
ret
|
||||
"""
|
||||
|
||||
proc mulInt(a, b: int): int {.compilerProc, asmNoStackFrame.} =
|
||||
proc mulInt(a, b: int): int {.compilerproc, asmNoStackFrame.} =
|
||||
asm """
|
||||
mov eax, ecx
|
||||
mov ecx, edx
|
||||
|
|
@ -247,7 +247,7 @@ when asmVersion and not defined(gcc) and not defined(llvm_gcc):
|
|||
"""
|
||||
|
||||
elif false: # asmVersion and (defined(gcc) or defined(llvm_gcc)):
|
||||
proc addInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc addInt(a, b: int): int {.compilerproc, inline.} =
|
||||
# don't use a pure proc here!
|
||||
asm """
|
||||
"addl %%ecx, %%eax\n"
|
||||
|
|
@ -261,7 +261,7 @@ elif false: # asmVersion and (defined(gcc) or defined(llvm_gcc)):
|
|||
#/* Intel syntax here */
|
||||
#".att_syntax"
|
||||
|
||||
proc subInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc subInt(a, b: int): int {.compilerproc, inline.} =
|
||||
asm """ "subl %%ecx,%%eax\n"
|
||||
"jno 1\n"
|
||||
"call _raiseOverflow\n"
|
||||
|
|
@ -270,7 +270,7 @@ elif false: # asmVersion and (defined(gcc) or defined(llvm_gcc)):
|
|||
:"a"(`a`), "c"(`b`)
|
||||
"""
|
||||
|
||||
proc mulInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc mulInt(a, b: int): int {.compilerproc, inline.} =
|
||||
asm """ "xorl %%edx, %%edx\n"
|
||||
"imull %%ecx\n"
|
||||
"jno 1\n"
|
||||
|
|
@ -281,7 +281,7 @@ elif false: # asmVersion and (defined(gcc) or defined(llvm_gcc)):
|
|||
:"%edx"
|
||||
"""
|
||||
|
||||
proc negInt(a: int): int {.compilerProc, inline.} =
|
||||
proc negInt(a: int): int {.compilerproc, inline.} =
|
||||
asm """ "negl %%eax\n"
|
||||
"jno 1\n"
|
||||
"call _raiseOverflow\n"
|
||||
|
|
@ -290,7 +290,7 @@ elif false: # asmVersion and (defined(gcc) or defined(llvm_gcc)):
|
|||
:"a"(`a`)
|
||||
"""
|
||||
|
||||
proc divInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc divInt(a, b: int): int {.compilerproc, inline.} =
|
||||
asm """ "xorl %%edx, %%edx\n"
|
||||
"idivl %%ecx\n"
|
||||
"jno 1\n"
|
||||
|
|
@ -301,7 +301,7 @@ elif false: # asmVersion and (defined(gcc) or defined(llvm_gcc)):
|
|||
:"%edx"
|
||||
"""
|
||||
|
||||
proc modInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc modInt(a, b: int): int {.compilerproc, inline.} =
|
||||
asm """ "xorl %%edx, %%edx\n"
|
||||
"idivl %%ecx\n"
|
||||
"jno 1\n"
|
||||
|
|
@ -314,42 +314,42 @@ elif false: # asmVersion and (defined(gcc) or defined(llvm_gcc)):
|
|||
"""
|
||||
|
||||
when not declared(addInt) and defined(builtinOverflow):
|
||||
proc addInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc addInt(a, b: int): int {.compilerproc, inline.} =
|
||||
if addIntOverflow(a, b, result):
|
||||
raiseOverflow()
|
||||
|
||||
when not declared(subInt) and defined(builtinOverflow):
|
||||
proc subInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc subInt(a, b: int): int {.compilerproc, inline.} =
|
||||
if subIntOverflow(a, b, result):
|
||||
raiseOverflow()
|
||||
|
||||
when not declared(mulInt) and defined(builtinOverflow):
|
||||
proc mulInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc mulInt(a, b: int): int {.compilerproc, inline.} =
|
||||
if mulIntOverflow(a, b, result):
|
||||
raiseOverflow()
|
||||
|
||||
# Platform independent versions of the above (slower!)
|
||||
when not declared(addInt):
|
||||
proc addInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc addInt(a, b: int): int {.compilerproc, inline.} =
|
||||
result = a +% b
|
||||
if (result xor a) >= 0 or (result xor b) >= 0:
|
||||
return result
|
||||
raiseOverflow()
|
||||
|
||||
when not declared(subInt):
|
||||
proc subInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc subInt(a, b: int): int {.compilerproc, inline.} =
|
||||
result = a -% b
|
||||
if (result xor a) >= 0 or (result xor not b) >= 0:
|
||||
return result
|
||||
raiseOverflow()
|
||||
|
||||
when not declared(negInt):
|
||||
proc negInt(a: int): int {.compilerProc, inline.} =
|
||||
proc negInt(a: int): int {.compilerproc, inline.} =
|
||||
if a != low(int): return -a
|
||||
raiseOverflow()
|
||||
|
||||
when not declared(divInt):
|
||||
proc divInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc divInt(a, b: int): int {.compilerproc, inline.} =
|
||||
if b == 0:
|
||||
raiseDivByZero()
|
||||
if a == low(int) and b == -1:
|
||||
|
|
@ -357,7 +357,7 @@ when not declared(divInt):
|
|||
return a div b
|
||||
|
||||
when not declared(modInt):
|
||||
proc modInt(a, b: int): int {.compilerProc, inline.} =
|
||||
proc modInt(a, b: int): int {.compilerproc, inline.} =
|
||||
if b == 0:
|
||||
raiseDivByZero()
|
||||
return a mod b
|
||||
|
|
@ -383,7 +383,7 @@ when not declared(mulInt):
|
|||
# the only one that can lose catastrophic amounts of information, it's the
|
||||
# native int product that must have overflowed.
|
||||
#
|
||||
proc mulInt(a, b: int): int {.compilerProc.} =
|
||||
proc mulInt(a, b: int): int {.compilerproc.} =
|
||||
var
|
||||
resAsFloat, floatProd: float
|
||||
|
||||
|
|
@ -412,7 +412,7 @@ when not declared(mulInt):
|
|||
proc raiseFloatInvalidOp {.noinline.} =
|
||||
sysFatal(FloatInvalidOpError, "FPU operation caused a NaN result")
|
||||
|
||||
proc nanCheck(x: float64) {.compilerProc, inline.} =
|
||||
proc nanCheck(x: float64) {.compilerproc, inline.} =
|
||||
if x != x: raiseFloatInvalidOp()
|
||||
|
||||
proc raiseFloatOverflow(x: float64) {.noinline.} =
|
||||
|
|
@ -421,5 +421,5 @@ proc raiseFloatOverflow(x: float64) {.noinline.} =
|
|||
else:
|
||||
sysFatal(FloatUnderflowError, "FPU operations caused an underflow")
|
||||
|
||||
proc infCheck(x: float64) {.compilerProc, inline.} =
|
||||
proc infCheck(x: float64) {.compilerproc, inline.} =
|
||||
if x != 0.0 and x*0.5 == x: raiseFloatOverflow(x)
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ proc `$`(x: int): string {.magic: "IntToStr", noSideEffect.}
|
|||
proc `$`(info: InstantiationInfo): string =
|
||||
# The +1 is needed here
|
||||
# instead of overriding `$` (and changing its meaning), consider explicit name.
|
||||
info.fileName & "(" & $info.line & ", " & $(info.column+1) & ")"
|
||||
info.filename & "(" & $info.line & ", " & $(info.column+1) & ")"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
proc raiseAssert*(msg: string) {.noinline, noReturn.} =
|
||||
proc raiseAssert*(msg: string) {.noinline, noreturn.} =
|
||||
sysFatal(AssertionError, msg)
|
||||
|
||||
proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
||||
|
|
|
|||
|
|
@ -107,10 +107,10 @@ proc genericAssignAux(dest, src: pointer, mt: PNimType, shallow: bool) =
|
|||
else:
|
||||
copyMem(dest, src, mt.size) # copy raw bits
|
||||
|
||||
proc genericAssign(dest, src: pointer, mt: PNimType) {.compilerProc.} =
|
||||
proc genericAssign(dest, src: pointer, mt: PNimType) {.compilerproc.} =
|
||||
genericAssignAux(dest, src, mt, false)
|
||||
|
||||
proc genericShallowAssign(dest, src: pointer, mt: PNimType) {.compilerProc.} =
|
||||
proc genericShallowAssign(dest, src: pointer, mt: PNimType) {.compilerproc.} =
|
||||
genericAssignAux(dest, src, mt, true)
|
||||
|
||||
when false:
|
||||
|
|
@ -142,7 +142,7 @@ when false:
|
|||
cprintf("%s %ld\n", k, t.size)
|
||||
debugNimType(t.base)
|
||||
|
||||
proc genericSeqAssign(dest, src: pointer, mt: PNimType) {.compilerProc.} =
|
||||
proc genericSeqAssign(dest, src: pointer, mt: PNimType) {.compilerproc.} =
|
||||
var src = src # ugly, but I like to stress the parser sometimes :-)
|
||||
genericAssign(dest, addr(src), mt)
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ proc genericAssignOpenArray(dest, src: pointer, len: int,
|
|||
genericAssign(cast[pointer](d +% i *% mt.base.size),
|
||||
cast[pointer](s +% i *% mt.base.size), mt.base)
|
||||
|
||||
proc objectInit(dest: pointer, typ: PNimType) {.compilerProc, benign.}
|
||||
proc objectInit(dest: pointer, typ: PNimType) {.compilerproc, benign.}
|
||||
proc objectInitAux(dest: pointer, n: ptr TNimNode) {.benign.} =
|
||||
var d = cast[ByteAddress](dest)
|
||||
case n.kind
|
||||
|
|
@ -188,7 +188,7 @@ proc objectInit(dest: pointer, typ: PNimType) =
|
|||
|
||||
# ---------------------- assign zero -----------------------------------------
|
||||
|
||||
proc genericReset(dest: pointer, mt: PNimType) {.compilerProc, benign.}
|
||||
proc genericReset(dest: pointer, mt: PNimType) {.compilerproc, benign.}
|
||||
proc genericResetAux(dest: pointer, n: ptr TNimNode) =
|
||||
var d = cast[ByteAddress](dest)
|
||||
case n.kind
|
||||
|
|
@ -229,7 +229,7 @@ proc selectBranch(discVal, L: int,
|
|||
|
||||
proc FieldDiscriminantCheck(oldDiscVal, newDiscVal: int,
|
||||
a: ptr array[0x7fff, ptr TNimNode],
|
||||
L: int) {.compilerProc.} =
|
||||
L: int) {.compilerproc.} =
|
||||
let oldBranch = selectBranch(oldDiscVal, L, a)
|
||||
let newBranch = selectBranch(newDiscVal, L, a)
|
||||
when defined(nimOldCaseObjects):
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ proc contains(s: CellSet, cell: PCell): bool =
|
|||
else:
|
||||
result = false
|
||||
|
||||
proc incl(s: var CellSet, cell: PCell) {.noinline.} =
|
||||
proc incl(s: var CellSet, cell: PCell) =
|
||||
var u = cast[uint](cell)
|
||||
var t = cellSetPut(s, u shr PageShift)
|
||||
u = (u mod PageSize) div MemAlign
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ when not defined(nimV2):
|
|||
return true
|
||||
|
||||
proc isObjWithCache(obj, subclass: PNimType;
|
||||
cache: var ObjCheckCache): bool {.compilerProc, inline.} =
|
||||
cache: var ObjCheckCache): bool {.compilerproc, inline.} =
|
||||
if obj == subclass: return true
|
||||
if obj.base == subclass: return true
|
||||
if cache[0] == obj: return false
|
||||
|
|
@ -116,6 +116,6 @@ when not defined(nimV2):
|
|||
return true
|
||||
|
||||
when defined(nimV2):
|
||||
proc nimFieldDiscriminantCheckV2(oldDiscVal, newDiscVal: uint8) {.compilerProc.} =
|
||||
proc nimFieldDiscriminantCheckV2(oldDiscVal, newDiscVal: uint8) {.compilerproc.} =
|
||||
if oldDiscVal != newDiscVal:
|
||||
sysFatal(FieldError, "assignment to discriminant changes object branch")
|
||||
|
|
|
|||
|
|
@ -165,14 +165,14 @@ proc genericDeepCopyAux(dest, src: pointer, mt: PNimType; tab: var PtrTable) =
|
|||
else:
|
||||
copyMem(dest, src, mt.size)
|
||||
|
||||
proc genericDeepCopy(dest, src: pointer, mt: PNimType) {.compilerProc.} =
|
||||
proc genericDeepCopy(dest, src: pointer, mt: PNimType) {.compilerproc.} =
|
||||
GC_disable()
|
||||
var tab = initPtrTable()
|
||||
genericDeepCopyAux(dest, src, mt, tab)
|
||||
deinit tab
|
||||
GC_enable()
|
||||
|
||||
proc genericSeqDeepCopy(dest, src: pointer, mt: PNimType) {.compilerProc.} =
|
||||
proc genericSeqDeepCopy(dest, src: pointer, mt: PNimType) {.compilerproc.} =
|
||||
# also invoked for 'string'
|
||||
var src = src
|
||||
genericDeepCopy(dest, addr(src), mt)
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ when not defined(nimNoArrayToString):
|
|||
## Generic ``$`` operator for arrays that is lifted from the components.
|
||||
collectionToString(x, "[", ", ", "]")
|
||||
|
||||
proc `$`*[T](x: openarray[T]): string =
|
||||
proc `$`*[T](x: openArray[T]): string =
|
||||
## Generic ``$`` operator for openarrays that is lifted from the components
|
||||
## of `x`. Example:
|
||||
##
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ elif defined(nimQuirky) and not defined(nimscript):
|
|||
|
||||
proc name(t: typedesc): string {.magic: "TypeTrait".}
|
||||
|
||||
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noReturn.} =
|
||||
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
|
||||
var buf = newStringOfCap(200)
|
||||
add(buf, "Error: unhandled exception: ")
|
||||
add(buf, message)
|
||||
|
|
@ -25,11 +25,11 @@ elif defined(nimQuirky) and not defined(nimscript):
|
|||
cstderr.rawWrite buf
|
||||
quit 1
|
||||
|
||||
proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} =
|
||||
proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
||||
sysFatal(exceptn, message, "")
|
||||
|
||||
else:
|
||||
proc sysFatal(exceptn: typedesc, message: string) {.inline, noReturn.} =
|
||||
proc sysFatal(exceptn: typedesc, message: string) {.inline, noreturn.} =
|
||||
when declared(owned):
|
||||
var e: owned(ref exceptn)
|
||||
else:
|
||||
|
|
@ -38,7 +38,7 @@ else:
|
|||
e.msg = message
|
||||
raise e
|
||||
|
||||
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noReturn.} =
|
||||
proc sysFatal(exceptn: typedesc, message, arg: string) {.inline, noreturn.} =
|
||||
when declared(owned):
|
||||
var e: owned(ref exceptn)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ proc incRef(c: PCell) {.inline.} =
|
|||
# and not colorMask
|
||||
logCell("incRef", c)
|
||||
|
||||
proc nimGCref(p: pointer) {.compilerProc.} =
|
||||
proc nimGCref(p: pointer) {.compilerproc.} =
|
||||
# we keep it from being collected by pretending it's not even allocated:
|
||||
let c = usrToCell(p)
|
||||
add(gch.additionalRoots, c)
|
||||
|
|
@ -202,7 +202,7 @@ proc decRef(c: PCell) {.inline.} =
|
|||
rtlAddZCT(c)
|
||||
logCell("decRef", c)
|
||||
|
||||
proc nimGCunref(p: pointer) {.compilerProc.} =
|
||||
proc nimGCunref(p: pointer) {.compilerproc.} =
|
||||
let cell = usrToCell(p)
|
||||
var L = gch.additionalRoots.len-1
|
||||
var i = L
|
||||
|
|
@ -223,15 +223,15 @@ template beforeDealloc(gch: var GcHeap; c: PCell; msg: typed) =
|
|||
if gch.decStack.d[i] == c:
|
||||
sysAssert(false, msg)
|
||||
|
||||
proc nimGCunrefNoCycle(p: pointer) {.compilerProc, inline.} =
|
||||
proc nimGCunrefNoCycle(p: pointer) {.compilerproc, inline.} =
|
||||
sysAssert(allocInv(gch.region), "begin nimGCunrefNoCycle")
|
||||
decRef(usrToCell(p))
|
||||
sysAssert(allocInv(gch.region), "end nimGCunrefNoCycle 5")
|
||||
|
||||
proc nimGCunrefRC1(p: pointer) {.compilerProc, inline.} =
|
||||
proc nimGCunrefRC1(p: pointer) {.compilerproc, inline.} =
|
||||
decRef(usrToCell(p))
|
||||
|
||||
proc asgnRef(dest: PPointer, src: pointer) {.compilerProc, inline.} =
|
||||
proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
||||
# the code generator calls this proc!
|
||||
gcAssert(not isOnStack(dest), "asgnRef")
|
||||
# BUGFIX: first incRef then decRef!
|
||||
|
|
@ -242,7 +242,7 @@ proc asgnRef(dest: PPointer, src: pointer) {.compilerProc, inline.} =
|
|||
proc asgnRefNoCycle(dest: PPointer, src: pointer) {.compilerproc, inline,
|
||||
deprecated: "old compiler compat".} = asgnRef(dest, src)
|
||||
|
||||
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerProc.} =
|
||||
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc.} =
|
||||
# unsureAsgnRef updates the reference counters only if dest is not on the
|
||||
# stack. It is used by the code generator if it cannot decide wether a
|
||||
# reference is in the stack or not (this can happen for var parameters).
|
||||
|
|
|
|||
|
|
@ -193,12 +193,12 @@ proc doOperation(p: pointer, op: WalkOp) {.benign.}
|
|||
proc forAllChildrenAux(dest: pointer, mt: PNimType, op: WalkOp) {.benign.}
|
||||
# we need the prototype here for debugging purposes
|
||||
|
||||
proc nimGCref(p: pointer) {.compilerProc.} =
|
||||
proc nimGCref(p: pointer) {.compilerproc.} =
|
||||
let cell = usrToCell(p)
|
||||
markAsEscaped(cell)
|
||||
add(gch.additionalRoots, cell)
|
||||
|
||||
proc nimGCunref(p: pointer) {.compilerProc.} =
|
||||
proc nimGCunref(p: pointer) {.compilerproc.} =
|
||||
let cell = usrToCell(p)
|
||||
var L = gch.additionalRoots.len-1
|
||||
var i = L
|
||||
|
|
@ -210,10 +210,10 @@ proc nimGCunref(p: pointer) {.compilerProc.} =
|
|||
break
|
||||
dec(i)
|
||||
|
||||
proc nimGCunrefNoCycle(p: pointer) {.compilerProc, inline.} =
|
||||
proc nimGCunrefNoCycle(p: pointer) {.compilerproc, inline.} =
|
||||
discard "can we do some freeing here?"
|
||||
|
||||
proc nimGCunrefRC1(p: pointer) {.compilerProc, inline.} =
|
||||
proc nimGCunrefRC1(p: pointer) {.compilerproc, inline.} =
|
||||
discard "can we do some freeing here?"
|
||||
|
||||
template markGrey(x: PCell) =
|
||||
|
|
@ -225,7 +225,7 @@ template markGrey(x: PCell) =
|
|||
x.setColor(rcGrey)
|
||||
add(gch.greyStack, x)
|
||||
|
||||
proc asgnRef(dest: PPointer, src: pointer) {.compilerProc, inline.} =
|
||||
proc asgnRef(dest: PPointer, src: pointer) {.compilerproc, inline.} =
|
||||
# the code generator calls this proc!
|
||||
gcAssert(not isOnStack(dest), "asgnRef")
|
||||
# BUGFIX: first incRef then decRef!
|
||||
|
|
@ -238,7 +238,7 @@ proc asgnRef(dest: PPointer, src: pointer) {.compilerProc, inline.} =
|
|||
proc asgnRefNoCycle(dest: PPointer, src: pointer) {.compilerproc, inline,
|
||||
deprecated: "old compiler compat".} = asgnRef(dest, src)
|
||||
|
||||
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerProc.} =
|
||||
proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerproc.} =
|
||||
# unsureAsgnRef marks 'src' as grey only if dest is not on the
|
||||
# stack. It is used by the code generator if it cannot decide wether a
|
||||
# reference is in the stack or not (this can happen for var parameters).
|
||||
|
|
|
|||
|
|
@ -456,7 +456,7 @@ var
|
|||
threadLocalMarkers {.exportc.}: array[0..3499, GlobalMarkerProc]
|
||||
gHeapidGenerator: int
|
||||
|
||||
proc nimRegisterGlobalMarker(markerProc: GlobalMarkerProc) {.compilerProc.} =
|
||||
proc nimRegisterGlobalMarker(markerProc: GlobalMarkerProc) {.compilerproc.} =
|
||||
if globalMarkersLen <= high(globalMarkers):
|
||||
globalMarkers[globalMarkersLen] = markerProc
|
||||
inc globalMarkersLen
|
||||
|
|
@ -464,7 +464,7 @@ proc nimRegisterGlobalMarker(markerProc: GlobalMarkerProc) {.compilerProc.} =
|
|||
cstderr.rawWrite("[GC] cannot register global variable; too many global variables")
|
||||
quit 1
|
||||
|
||||
proc nimRegisterThreadLocalMarker(markerProc: GlobalMarkerProc) {.compilerProc.} =
|
||||
proc nimRegisterThreadLocalMarker(markerProc: GlobalMarkerProc) {.compilerproc.} =
|
||||
if threadLocalMarkersLen <= high(threadLocalMarkers):
|
||||
threadLocalMarkers[threadLocalMarkersLen] = markerProc
|
||||
inc threadLocalMarkersLen
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ when defined(nimGcRefLeak):
|
|||
|
||||
var ax: array[10_000, GcStackTrace]
|
||||
|
||||
proc nimGCref(p: pointer) {.compilerProc.} =
|
||||
proc nimGCref(p: pointer) {.compilerproc.} =
|
||||
# we keep it from being collected by pretending it's not even allocated:
|
||||
when false:
|
||||
when withBitvectors: excl(gch.allocated, usrToCell(p))
|
||||
|
|
@ -171,7 +171,7 @@ proc nimGCref(p: pointer) {.compilerProc.} =
|
|||
captureStackTrace(framePtr, ax[gch.additionalRoots.len])
|
||||
add(gch.additionalRoots, usrToCell(p))
|
||||
|
||||
proc nimGCunref(p: pointer) {.compilerProc.} =
|
||||
proc nimGCunref(p: pointer) {.compilerproc.} =
|
||||
let cell = usrToCell(p)
|
||||
var L = gch.additionalRoots.len-1
|
||||
var i = L
|
||||
|
|
@ -372,14 +372,14 @@ proc mark(gch: var GcHeap, c: PCell) =
|
|||
c, c.typ.name)
|
||||
inc gch.indentation, 2
|
||||
|
||||
c.refCount = rcBlack
|
||||
c.refcount = rcBlack
|
||||
gcAssert gch.tempStack.len == 0, "stack not empty!"
|
||||
forAllChildren(c, waMarkPrecise)
|
||||
while gch.tempStack.len > 0:
|
||||
dec gch.tempStack.len
|
||||
var d = gch.tempStack.d[gch.tempStack.len]
|
||||
if d.refcount == rcWhite:
|
||||
d.refCount = rcBlack
|
||||
d.refcount = rcBlack
|
||||
forAllChildren(d, waMarkPrecise)
|
||||
|
||||
when defined(nimTracing):
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ type
|
|||
tyVoidHidden
|
||||
|
||||
TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase
|
||||
TNimNode {.compilerProc.} = object
|
||||
TNimNode {.compilerproc.} = object
|
||||
kind: TNimNodeKind
|
||||
offset: int
|
||||
typ: ptr TNimType
|
||||
|
|
@ -86,7 +86,7 @@ type
|
|||
ntfAcyclic = 1, # type cannot form a cycle
|
||||
ntfEnumHole = 2 # enum has holes and thus `$` for them needs the slow
|
||||
# version
|
||||
TNimType {.compilerProc.} = object
|
||||
TNimType {.compilerproc.} = object
|
||||
size: int
|
||||
kind: TNimKind
|
||||
flags: set[TNimTypeFlag]
|
||||
|
|
@ -105,7 +105,7 @@ type
|
|||
when defined(nimTypeNames):
|
||||
# Declare this variable only once in system.nim
|
||||
when declared(ThisIsSystem):
|
||||
var nimTypeRoot {.compilerProc.}: PNimType
|
||||
var nimTypeRoot {.compilerproc.}: PNimType
|
||||
else:
|
||||
var nimTypeRoot {.importc.}: PNimType
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ include inclrtl
|
|||
# ----------------- IO Part ------------------------------------------------
|
||||
type
|
||||
CFile {.importc: "FILE", header: "<stdio.h>",
|
||||
incompletestruct.} = object
|
||||
incompleteStruct.} = object
|
||||
File* = ptr CFile ## The type representing a file handle.
|
||||
|
||||
FileMode* = enum ## The file mode when opening a file.
|
||||
|
|
@ -420,7 +420,7 @@ when defined(windows) and not defined(useWinAnsi):
|
|||
result = wfreopen(f, m, stream)
|
||||
|
||||
else:
|
||||
proc fopen(filename, mode: cstring): pointer {.importc: "fopen", noDecl.}
|
||||
proc fopen(filename, mode: cstring): pointer {.importc: "fopen", nodecl.}
|
||||
proc freopen(filename, mode: cstring, stream: File): File {.
|
||||
importc: "freopen", nodecl.}
|
||||
|
||||
|
|
@ -442,7 +442,7 @@ when defined(posix) and not defined(nimscript):
|
|||
st_mode: Mode ## Mode of file
|
||||
filler_2: array[144 - 24 - 4, char]
|
||||
|
||||
proc S_ISDIR(m: Mode): bool =
|
||||
proc modeIsDir(m: Mode): bool =
|
||||
## Test for a directory.
|
||||
(m and 0o170000) == 0o40000
|
||||
|
||||
|
|
@ -454,7 +454,7 @@ when defined(posix) and not defined(nimscript):
|
|||
header: "<sys/stat.h>", final, pure.} = object ## struct stat
|
||||
st_mode: Mode ## Mode of file
|
||||
|
||||
proc S_ISDIR(m: Mode): bool {.importc, header: "<sys/stat.h>".}
|
||||
proc modeIsDir(m: Mode): bool {.importc: "S_ISDIR", header: "<sys/stat.h>".}
|
||||
## Test for a directory.
|
||||
|
||||
proc c_fstat(a1: cint, a2: var Stat): cint {.
|
||||
|
|
@ -476,7 +476,7 @@ proc open*(f: var File, filename: string,
|
|||
# be opened.
|
||||
var f2 = cast[File](p)
|
||||
var res: Stat
|
||||
if c_fstat(getFileHandle(f2), res) >= 0'i32 and S_ISDIR(res.st_mode):
|
||||
if c_fstat(getFileHandle(f2), res) >= 0'i32 and modeIsDir(res.st_mode):
|
||||
close(f2)
|
||||
return false
|
||||
result = true
|
||||
|
|
@ -550,11 +550,11 @@ when declared(stdout):
|
|||
var echoLock: SysLock
|
||||
initSysLock echoLock
|
||||
|
||||
proc echoBinSafe(args: openArray[string]) {.compilerProc.} =
|
||||
proc echoBinSafe(args: openArray[string]) {.compilerproc.} =
|
||||
# flockfile deadlocks some versions of Android 5.x.x
|
||||
when not defined(windows) and not defined(android) and not defined(nintendoswitch):
|
||||
proc flockfile(f: File) {.importc, noDecl.}
|
||||
proc funlockfile(f: File) {.importc, noDecl.}
|
||||
proc flockfile(f: File) {.importc, nodecl.}
|
||||
proc funlockfile(f: File) {.importc, nodecl.}
|
||||
flockfile(stdout)
|
||||
when defined(windows) and compileOption("threads"):
|
||||
acquireSys echoLock
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
# Compilerprocs for strings that do not depend on the string implementation.
|
||||
|
||||
proc cmpStrings(a, b: string): int {.inline, compilerProc.} =
|
||||
proc cmpStrings(a, b: string): int {.inline, compilerproc.} =
|
||||
let alen = a.len
|
||||
let blen = b.len
|
||||
let minlen = min(alen, blen)
|
||||
|
|
@ -20,7 +20,7 @@ proc cmpStrings(a, b: string): int {.inline, compilerProc.} =
|
|||
else:
|
||||
result = alen - blen
|
||||
|
||||
proc eqStrings(a, b: string): bool {.inline, compilerProc.} =
|
||||
proc eqStrings(a, b: string): bool {.inline, compilerproc.} =
|
||||
let alen = a.len
|
||||
let blen = b.len
|
||||
if alen == blen:
|
||||
|
|
@ -135,7 +135,7 @@ const
|
|||
1e20, 1e21, 1e22]
|
||||
|
||||
proc nimParseBiggestFloat(s: string, number: var BiggestFloat,
|
||||
start = 0): int {.compilerProc.} =
|
||||
start = 0): int {.compilerproc.} =
|
||||
# This routine attempt to parse float that can parsed quickly.
|
||||
# ie whose integer part can fit inside a 53bits integer.
|
||||
# their real exponent must also be <= 22. If the float doesn't follow
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ else:
|
|||
template allocStrNoInit(size: untyped): untyped =
|
||||
cast[NimString](newObjNoInit(addr(strDesc), size))
|
||||
|
||||
proc rawNewStringNoInit(space: int): NimString {.compilerProc.} =
|
||||
proc rawNewStringNoInit(space: int): NimString {.compilerproc.} =
|
||||
var s = space
|
||||
if s < 7: s = 7
|
||||
result = allocStrNoInit(sizeof(TGenericSeq) + s + 1)
|
||||
|
|
@ -49,7 +49,7 @@ proc rawNewStringNoInit(space: int): NimString {.compilerProc.} =
|
|||
when defined(gogc):
|
||||
result.elemSize = 1
|
||||
|
||||
proc rawNewString(space: int): NimString {.compilerProc.} =
|
||||
proc rawNewString(space: int): NimString {.compilerproc.} =
|
||||
var s = space
|
||||
if s < 7: s = 7
|
||||
result = allocStr(sizeof(TGenericSeq) + s + 1)
|
||||
|
|
@ -58,11 +58,11 @@ proc rawNewString(space: int): NimString {.compilerProc.} =
|
|||
when defined(gogc):
|
||||
result.elemSize = 1
|
||||
|
||||
proc mnewString(len: int): NimString {.compilerProc.} =
|
||||
proc mnewString(len: int): NimString {.compilerproc.} =
|
||||
result = rawNewString(len)
|
||||
result.len = len
|
||||
|
||||
proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} =
|
||||
proc copyStrLast(s: NimString, start, last: int): NimString {.compilerproc.} =
|
||||
# This is not used by most recent versions of the compiler anymore, but
|
||||
# required for bootstrapping purposes.
|
||||
let start = max(start, 0)
|
||||
|
|
@ -76,17 +76,17 @@ proc copyStrLast(s: NimString, start, last: int): NimString {.compilerProc.} =
|
|||
else:
|
||||
result = rawNewString(len)
|
||||
|
||||
proc copyStr(s: NimString, start: int): NimString {.compilerProc.} =
|
||||
proc copyStr(s: NimString, start: int): NimString {.compilerproc.} =
|
||||
# This is not used by most recent versions of the compiler anymore, but
|
||||
# required for bootstrapping purposes.
|
||||
if s == nil: return nil
|
||||
result = copyStrLast(s, start, s.len-1)
|
||||
|
||||
proc nimToCStringConv(s: NimString): cstring {.compilerProc, nonReloadable, inline.} =
|
||||
proc nimToCStringConv(s: NimString): cstring {.compilerproc, nonReloadable, inline.} =
|
||||
if s == nil or s.len == 0: result = cstring""
|
||||
else: result = cstring(addr s.data)
|
||||
|
||||
proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} =
|
||||
proc toNimStr(str: cstring, len: int): NimString {.compilerproc.} =
|
||||
result = rawNewStringNoInit(len)
|
||||
result.len = len
|
||||
copyMem(addr(result.data), str, len + 1)
|
||||
|
|
@ -245,7 +245,7 @@ proc setLengthStr(s: NimString, newLen: int): NimString {.compilerRtl.} =
|
|||
|
||||
# ----------------- sequences ----------------------------------------------
|
||||
|
||||
proc incrSeq(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
|
||||
proc incrSeq(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerproc.} =
|
||||
# increments the length by one:
|
||||
# this is needed for supporting ``add``;
|
||||
#
|
||||
|
|
@ -260,7 +260,7 @@ proc incrSeq(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
|
|||
result.reserved = r
|
||||
inc(result.len)
|
||||
|
||||
proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
|
||||
proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerproc.} =
|
||||
# incrSeq version 2
|
||||
result = seq
|
||||
if result.len >= result.space:
|
||||
|
|
@ -272,7 +272,7 @@ proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
|
|||
template `+!`(p: pointer, s: int): pointer =
|
||||
cast[pointer](cast[int](p) +% s)
|
||||
|
||||
proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.} =
|
||||
proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerproc.} =
|
||||
if s == nil:
|
||||
result = cast[PGenericSeq](newSeq(typ, 1))
|
||||
result.len = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue