Merge branch 'devel' into araq-big-refactoring
This commit is contained in:
commit
9849808720
9 changed files with 115 additions and 41 deletions
|
|
@ -33,22 +33,22 @@ when declared(echo):
|
||||||
|
|
||||||
template mdbg*: bool {.dirty.} =
|
template mdbg*: bool {.dirty.} =
|
||||||
when compiles(c.module):
|
when compiles(c.module):
|
||||||
c.module.fileIdx.int32 == gProjectMainIdx
|
c.module.fileIdx.int32 == c.config.projectMainIdx
|
||||||
elif compiles(c.c.module):
|
elif compiles(c.c.module):
|
||||||
c.c.module.fileIdx.int32 == gProjectMainIdx
|
c.c.module.fileIdx.int32 == c.c.config.projectMainIdx
|
||||||
elif compiles(m.c.module):
|
elif compiles(m.c.module):
|
||||||
m.c.module.fileIdx.int32 == gProjectMainIdx
|
m.c.module.fileIdx.int32 == m.c.config.projectMainIdx
|
||||||
elif compiles(cl.c.module):
|
elif compiles(cl.c.module):
|
||||||
cl.c.module.fileIdx.int32 == gProjectMainIdx
|
cl.c.module.fileIdx.int32 == cl.c.config.projectMainIdx
|
||||||
elif compiles(p):
|
elif compiles(p):
|
||||||
when compiles(p.lex):
|
when compiles(p.lex):
|
||||||
p.lex.fileIdx.int32 == gProjectMainIdx
|
p.lex.fileIdx.int32 == p.lex.config.projectMainIdx
|
||||||
else:
|
else:
|
||||||
p.module.module.fileIdx.int32 == gProjectMainIdx
|
p.module.module.fileIdx.int32 == p.config.projectMainIdx
|
||||||
elif compiles(m.module.fileIdx):
|
elif compiles(m.module.fileIdx):
|
||||||
m.module.fileIdx.int32 == gProjectMainIdx
|
m.module.fileIdx.int32 == m.config.projectMainIdx
|
||||||
elif compiles(L.fileIdx):
|
elif compiles(L.fileIdx):
|
||||||
L.fileIdx.int32 == gProjectMainIdx
|
L.fileIdx.int32 == L.config.projectMainIdx
|
||||||
else:
|
else:
|
||||||
error()
|
error()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ proc changeType(c: PContext; n: PNode, newType: PType, check: bool)
|
||||||
proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode
|
proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode
|
||||||
proc semTypeNode(c: PContext, n: PNode, prev: PType): PType
|
proc semTypeNode(c: PContext, n: PNode, prev: PType): PType
|
||||||
proc semStmt(c: PContext, n: PNode): PNode
|
proc semStmt(c: PContext, n: PNode): PNode
|
||||||
|
proc semOpAux(c: PContext, n: PNode)
|
||||||
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
|
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym)
|
||||||
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
proc addParams(c: PContext, n: PNode, kind: TSymKind)
|
||||||
proc maybeAddResult(c: PContext, s: PSym, n: PNode)
|
proc maybeAddResult(c: PContext, s: PSym, n: PNode)
|
||||||
|
|
|
||||||
|
|
@ -254,6 +254,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
|
||||||
var f = n.sons[0]
|
var f = n.sons[0]
|
||||||
if f.kind == nkBracketExpr:
|
if f.kind == nkBracketExpr:
|
||||||
# fill in the bindings:
|
# fill in the bindings:
|
||||||
|
semOpAux(c, f)
|
||||||
initialBinding = f
|
initialBinding = f
|
||||||
f = f.sons[0]
|
f = f.sons[0]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ include "system/inclrtl"
|
||||||
{.push debugger:off .} # the user does not want to trace a part
|
{.push debugger:off .} # the user does not want to trace a part
|
||||||
# of the standard library!
|
# of the standard library!
|
||||||
|
|
||||||
|
import bitops
|
||||||
|
|
||||||
proc binom*(n, k: int): int {.noSideEffect.} =
|
proc binom*(n, k: int): int {.noSideEffect.} =
|
||||||
## Computes the binomial coefficient
|
## Computes the binomial coefficient
|
||||||
if k <= 0: return 1
|
if k <= 0: return 1
|
||||||
|
|
@ -455,16 +457,42 @@ proc `^`*[T](x: T, y: Natural): T =
|
||||||
x *= x
|
x *= x
|
||||||
|
|
||||||
proc gcd*[T](x, y: T): T =
|
proc gcd*[T](x, y: T): T =
|
||||||
## Computes the greatest common divisor of ``x`` and ``y``.
|
## Computes the greatest common (positive) divisor of ``x`` and ``y``.
|
||||||
## Note that for floats, the result cannot always be interpreted as
|
## Note that for floats, the result cannot always be interpreted as
|
||||||
## "greatest decimal `z` such that ``z*N == x and z*M == y``
|
## "greatest decimal `z` such that ``z*N == x and z*M == y``
|
||||||
## where N and M are positive integers."
|
## where N and M are positive integers."
|
||||||
var (x,y) = (x,y)
|
var (x, y) = (x, y)
|
||||||
while y != 0:
|
while y != 0:
|
||||||
x = x mod y
|
x = x mod y
|
||||||
swap x, y
|
swap x, y
|
||||||
abs x
|
abs x
|
||||||
|
|
||||||
|
proc gcd*(x, y: SomeInteger): SomeInteger =
|
||||||
|
## Computes the greatest common (positive) divisor of ``x`` and ``y``.
|
||||||
|
## Using binary GCD (aka Stein's) algorithm.
|
||||||
|
when x is SomeSignedInt:
|
||||||
|
var x = abs(x)
|
||||||
|
else:
|
||||||
|
var x = x
|
||||||
|
when y is SomeSignedInt:
|
||||||
|
var y = abs(y)
|
||||||
|
else:
|
||||||
|
var y = y
|
||||||
|
|
||||||
|
if x == 0:
|
||||||
|
return y
|
||||||
|
if y == 0:
|
||||||
|
return x
|
||||||
|
|
||||||
|
let shift = countTrailingZeroBits(x or y)
|
||||||
|
y = y shr countTrailingZeroBits(y)
|
||||||
|
while x != 0:
|
||||||
|
x = x shr countTrailingZeroBits(x)
|
||||||
|
if y > x:
|
||||||
|
swap y, x
|
||||||
|
x -= y
|
||||||
|
y shl shift
|
||||||
|
|
||||||
proc lcm*[T](x, y: T): T =
|
proc lcm*[T](x, y: T): T =
|
||||||
## Computes the least common multiple of ``x`` and ``y``.
|
## Computes the least common multiple of ``x`` and ``y``.
|
||||||
x div gcd(x, y) * y
|
x div gcd(x, y) * y
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,9 @@ proc parseUntil*(s: string, token: var string, until: string,
|
||||||
## parses a token and stores it in ``token``. Returns
|
## parses a token and stores it in ``token``. Returns
|
||||||
## the number of the parsed characters or 0 in case of an error. A token
|
## the number of the parsed characters or 0 in case of an error. A token
|
||||||
## consists of any character that comes before the `until` token.
|
## consists of any character that comes before the `until` token.
|
||||||
|
if until.len == 0:
|
||||||
|
token.setLen(0)
|
||||||
|
return 0
|
||||||
var i = start
|
var i = start
|
||||||
while i < s.len:
|
while i < s.len:
|
||||||
if s[i] == until[0]:
|
if s[i] == until[0]:
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ type
|
||||||
bump: pointer
|
bump: pointer
|
||||||
head, tail: Chunk
|
head, tail: Chunk
|
||||||
nextChunkSize, totalSize: int
|
nextChunkSize, totalSize: int
|
||||||
|
when false:
|
||||||
freeLists: array[MaxSmallObject div MemAlign, FreeEntry]
|
freeLists: array[MaxSmallObject div MemAlign, FreeEntry]
|
||||||
holes: SizedFreeEntry
|
holes: SizedFreeEntry
|
||||||
when hasThreadSupport:
|
when hasThreadSupport:
|
||||||
|
|
@ -145,6 +146,7 @@ proc allocSlowPath(r: var MemRegion; size: int) =
|
||||||
r.remaining = s - sizeof(BaseChunk)
|
r.remaining = s - sizeof(BaseChunk)
|
||||||
|
|
||||||
proc allocFast(r: var MemRegion; size: int): pointer =
|
proc allocFast(r: var MemRegion; size: int): pointer =
|
||||||
|
when false:
|
||||||
if size <= MaxSmallObject:
|
if size <= MaxSmallObject:
|
||||||
var it = r.freeLists[size div MemAlign]
|
var it = r.freeLists[size div MemAlign]
|
||||||
if it != nil:
|
if it != nil:
|
||||||
|
|
@ -184,7 +186,8 @@ proc dealloc(r: var MemRegion; p: pointer; size: int) =
|
||||||
# it is benefitial to not use the free lists here:
|
# it is benefitial to not use the free lists here:
|
||||||
if r.bump -! size == p:
|
if r.bump -! size == p:
|
||||||
dec r.bump, size
|
dec r.bump, size
|
||||||
elif size <= MaxSmallObject:
|
when false:
|
||||||
|
if size <= MaxSmallObject:
|
||||||
let it = cast[FreeEntry](p)
|
let it = cast[FreeEntry](p)
|
||||||
it.next = r.freeLists[size div MemAlign]
|
it.next = r.freeLists[size div MemAlign]
|
||||||
r.freeLists[size div MemAlign] = it
|
r.freeLists[size div MemAlign] = it
|
||||||
|
|
@ -220,6 +223,7 @@ proc setObstackPtr*(r: var MemRegion; sp: StackPtr) =
|
||||||
if sp.current.next != nil:
|
if sp.current.next != nil:
|
||||||
deallocAll(r, sp.current.next)
|
deallocAll(r, sp.current.next)
|
||||||
sp.current.next = nil
|
sp.current.next = nil
|
||||||
|
when false:
|
||||||
# better leak this memory than be sorry:
|
# better leak this memory than be sorry:
|
||||||
for i in 0..high(r.freeLists): r.freeLists[i] = nil
|
for i in 0..high(r.freeLists): r.freeLists[i] = nil
|
||||||
r.holes = nil
|
r.holes = nil
|
||||||
|
|
|
||||||
|
|
@ -750,3 +750,16 @@ when defined(nodejs):
|
||||||
else:
|
else:
|
||||||
# Deprecated. Use `alert` defined in dom.nim
|
# Deprecated. Use `alert` defined in dom.nim
|
||||||
proc alert*(s: cstring) {.importc, nodecl, deprecated.}
|
proc alert*(s: cstring) {.importc, nodecl, deprecated.}
|
||||||
|
|
||||||
|
# Workaround for IE, IE up to version 11 lacks 'Math.trunc'. We produce
|
||||||
|
# 'Math.trunc' for Nim's ``div`` and ``mod`` operators:
|
||||||
|
when not defined(nodejs):
|
||||||
|
{.emit: """
|
||||||
|
if (!Math.trunc) {
|
||||||
|
Math.trunc = function(v) {
|
||||||
|
v = +v;
|
||||||
|
if (!isFinite(v)) return v;
|
||||||
|
|
||||||
|
return (v - v % 1) || (v < 0 ? -0 : v === 0 ? v : 0);
|
||||||
|
};
|
||||||
|
}""".}
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,7 @@ proc ERR_peek_last_error*(): cInt{.cdecl, dynlib: DLLUtilName, importc.}
|
||||||
|
|
||||||
proc OPENSSL_config*(configName: cstring){.cdecl, dynlib: DLLSSLName, importc.}
|
proc OPENSSL_config*(configName: cstring){.cdecl, dynlib: DLLSSLName, importc.}
|
||||||
|
|
||||||
when not useWinVersion and not defined(macosx) and not defined(android):
|
when not useWinVersion and not defined(macosx) and not defined(android) and not defined(nimNoAllocForSSL):
|
||||||
proc CRYPTO_set_mem_functions(a,b,c: pointer){.cdecl,
|
proc CRYPTO_set_mem_functions(a,b,c: pointer){.cdecl,
|
||||||
dynlib: DLLUtilName, importc.}
|
dynlib: DLLUtilName, importc.}
|
||||||
|
|
||||||
|
|
@ -404,7 +404,7 @@ when not useWinVersion and not defined(macosx) and not defined(android):
|
||||||
if p != nil: dealloc(p)
|
if p != nil: dealloc(p)
|
||||||
|
|
||||||
proc CRYPTO_malloc_init*() =
|
proc CRYPTO_malloc_init*() =
|
||||||
when not useWinVersion and not defined(macosx) and not defined(android):
|
when not useWinVersion and not defined(macosx) and not defined(android) and not defined(nimNoAllocForSSL):
|
||||||
CRYPTO_set_mem_functions(allocWrapper, reallocWrapper, deallocWrapper)
|
CRYPTO_set_mem_functions(allocWrapper, reallocWrapper, deallocWrapper)
|
||||||
|
|
||||||
proc SSL_CTX_ctrl*(ctx: SslCtx, cmd: cInt, larg: int, parg: pointer): int{.
|
proc SSL_CTX_ctrl*(ctx: SslCtx, cmd: cInt, larg: int, parg: pointer): int{.
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,27 @@ template someTemplate[T](): tuple[id: int32, obj: T] =
|
||||||
|
|
||||||
let ret = someTemplate[SomeObj]()
|
let ret = someTemplate[SomeObj]()
|
||||||
|
|
||||||
|
# https://github.com/nim-lang/Nim/issues/7829
|
||||||
|
proc inner*[T](): int =
|
||||||
|
discard
|
||||||
|
|
||||||
|
template outer*[A](): untyped =
|
||||||
|
inner[A]()
|
||||||
|
|
||||||
|
template outer*[B](x: int): untyped =
|
||||||
|
inner[B]()
|
||||||
|
|
||||||
|
var i1 = outer[int]()
|
||||||
|
var i2 = outer[int](i1)
|
||||||
|
|
||||||
|
# https://github.com/nim-lang/Nim/issues/7883
|
||||||
|
template t1[T: int|int64](s: string): T =
|
||||||
|
var t: T
|
||||||
|
t
|
||||||
|
|
||||||
|
template t1[T: int|int64](x: int, s: string): T =
|
||||||
|
var t: T
|
||||||
|
t
|
||||||
|
|
||||||
|
var i3: int = t1[int]("xx")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue