Merge remote-tracking branch 'nim-lang/devel' into emscripten-support
This commit is contained in:
commit
4c53a3a7a5
35 changed files with 156 additions and 83 deletions
|
|
@ -18,8 +18,9 @@ type Rational*[T] = object
|
|||
## a rational number, consisting of a numerator and denominator
|
||||
num*, den*: T
|
||||
|
||||
proc initRational*[T](num, den: T): Rational[T] =
|
||||
proc initRational*[T:SomeInteger](num, den: T): Rational[T] =
|
||||
## Create a new rational number.
|
||||
assert(den != 0, "a denominator of zero value is invalid")
|
||||
result.num = num
|
||||
result.den = den
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ proc `$`*[T](x: Rational[T]): string =
|
|||
## Turn a rational number into a string.
|
||||
result = $x.num & "/" & $x.den
|
||||
|
||||
proc toRational*[T](x: T): Rational[T] =
|
||||
proc toRational*[T:SomeInteger](x: T): Rational[T] =
|
||||
## Convert some integer `x` to a rational number.
|
||||
result.num = x
|
||||
result.den = 1
|
||||
|
|
@ -47,7 +48,7 @@ proc toInt*[T](x: Rational[T]): int =
|
|||
## `x` does not contain an integer value.
|
||||
x.num div x.den
|
||||
|
||||
proc reduce*[T](x: var Rational[T]) =
|
||||
proc reduce*[T:SomeInteger](x: var Rational[T]) =
|
||||
## Reduce rational `x`.
|
||||
let common = gcd(x.num, x.den)
|
||||
if x.den > 0:
|
||||
|
|
|
|||
|
|
@ -103,15 +103,16 @@ proc readData*(s: Stream, buffer: pointer, bufLen: int): int =
|
|||
|
||||
proc readAll*(s: Stream): string =
|
||||
## Reads all available data.
|
||||
result = newString(1000)
|
||||
const bufferSize = 1000
|
||||
result = newString(bufferSize)
|
||||
var r = 0
|
||||
while true:
|
||||
let readBytes = readData(s, addr(result[r]), 1000)
|
||||
if readBytes < 1000:
|
||||
let readBytes = readData(s, addr(result[r]), bufferSize)
|
||||
if readBytes < bufferSize:
|
||||
setLen(result, r+readBytes)
|
||||
break
|
||||
inc r, 1000
|
||||
setLen(result, r+1000)
|
||||
inc r, bufferSize
|
||||
setLen(result, r+bufferSize)
|
||||
|
||||
proc readData*(s, unused: Stream, buffer: pointer,
|
||||
bufLen: int): int {.deprecated.} =
|
||||
|
|
|
|||
|
|
@ -1256,7 +1256,7 @@ proc compileOption*(option, arg: string): bool {.
|
|||
## echo "compiled with optimization for size and uses Boehm's GC"
|
||||
|
||||
const
|
||||
hasThreadSupport = compileOption("threads")
|
||||
hasThreadSupport = compileOption("threads") and not defined(nimscript)
|
||||
hasSharedHeap = defined(boehmgc) or defined(gogc) # don't share heaps; every thread has its own
|
||||
taintMode = compileOption("taintmode")
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,11 @@ sysAssert(roundup(65, 8) == 72, "roundup broken 2")
|
|||
# some platforms have really weird unmap behaviour: unmap(blockStart, PageSize)
|
||||
# really frees the whole block. Happens for Linux/PowerPC for example. Amd64
|
||||
# and x86 are safe though; Windows is special because MEM_RELEASE can only be
|
||||
# used with a size of 0:
|
||||
const weirdUnmap = not (defined(amd64) or defined(i386)) or defined(windows)
|
||||
# used with a size of 0. We also allow unmapping to be turned off with
|
||||
# -d:nimAllocNoUnmap:
|
||||
const doNotUnmap = not (defined(amd64) or defined(i386)) or
|
||||
defined(windows) or defined(nimAllocNoUnmap)
|
||||
|
||||
|
||||
when defined(emscripten):
|
||||
const
|
||||
|
|
@ -525,7 +528,7 @@ proc freeBigChunk(a: var MemRegion, c: PBigChunk) =
|
|||
excl(a.chunkStarts, pageIndex(c))
|
||||
c = cast[PBigChunk](le)
|
||||
|
||||
if c.size < ChunkOsReturn or weirdUnmap:
|
||||
if c.size < ChunkOsReturn or doNotUnmap:
|
||||
incl(a, a.chunkStarts, pageIndex(c))
|
||||
updatePrevSize(a, c, c.size)
|
||||
listAdd(a.freeChunksList, c)
|
||||
|
|
@ -809,7 +812,7 @@ proc deallocOsPages(a: var MemRegion) =
|
|||
# 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)
|
||||
when not weirdUnmap:
|
||||
when not doNotUnmap:
|
||||
var size = if page.size < PageSize: PageSize else: page.size
|
||||
osDeallocPages(page, size)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue