Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
9abbd6c880
7 changed files with 46 additions and 34 deletions
|
|
@ -187,3 +187,6 @@ let
|
||||||
mySeq = @[1, 2, 1, 3, 1, 4]
|
mySeq = @[1, 2, 1, 3, 1, 4]
|
||||||
myCounter = mySeq.toCountTable()
|
myCounter = mySeq.toCountTable()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Added support for casting between integers of same bitsize in VM (compile time and nimscript).
|
||||||
|
This allow to among other things to reinterpret signed integers as unsigned.
|
||||||
|
|
|
||||||
|
|
@ -2051,10 +2051,10 @@ proc genConv(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
return
|
return
|
||||||
case dest.kind:
|
case dest.kind:
|
||||||
of tyBool:
|
of tyBool:
|
||||||
r.res = "(($1)? 1:0)" % [r.res]
|
r.res = "(!!($1))" % [r.res]
|
||||||
r.kind = resExpr
|
r.kind = resExpr
|
||||||
of tyInt:
|
of tyInt:
|
||||||
r.res = "($1|0)" % [r.res]
|
r.res = "(($1)|0)" % [r.res]
|
||||||
else:
|
else:
|
||||||
# TODO: What types must we handle here?
|
# TODO: What types must we handle here?
|
||||||
discard
|
discard
|
||||||
|
|
|
||||||
2
koch.nim
2
koch.nim
|
|
@ -260,7 +260,7 @@ proc buildTools(latest: bool) =
|
||||||
" nimsuggest/nimsuggest.nim"
|
" nimsuggest/nimsuggest.nim"
|
||||||
|
|
||||||
let nimgrepExe = "bin/nimgrep".exe
|
let nimgrepExe = "bin/nimgrep".exe
|
||||||
nimexec "c -o:" & nimgrepExe & " tools/nimgrep.nim"
|
nimexec "c -d:release -o:" & nimgrepExe & " tools/nimgrep.nim"
|
||||||
when defined(windows): buildVccTool()
|
when defined(windows): buildVccTool()
|
||||||
|
|
||||||
#nimexec "c -o:" & ("bin/nimresolve".exe) & " tools/nimresolve.nim"
|
#nimexec "c -o:" & ("bin/nimresolve".exe) & " tools/nimresolve.nim"
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ type
|
||||||
{.deprecated: [TSocketHandle: SocketHandle].}
|
{.deprecated: [TSocketHandle: SocketHandle].}
|
||||||
|
|
||||||
type
|
type
|
||||||
Time* {.importc: "time_t", header: "<time.h>".} = distinct int
|
Time* {.importc: "time_t", header: "<time.h>".} = distinct clong
|
||||||
|
|
||||||
Timespec* {.importc: "struct timespec",
|
Timespec* {.importc: "struct timespec",
|
||||||
header: "<time.h>", final, pure.} = object ## struct timespec
|
header: "<time.h>", final, pure.} = object ## struct timespec
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ proc toRational*[T:SomeInteger](x: T): Rational[T] =
|
||||||
result.num = x
|
result.num = x
|
||||||
result.den = 1
|
result.den = 1
|
||||||
|
|
||||||
proc toRational*(x: float, n: int = high(int32)): Rational[int] =
|
proc toRational*(x: float, n: int = high(int) shr (sizeof(int) div 2 * 8)): Rational[int] =
|
||||||
## Calculates the best rational numerator and denominator
|
## Calculates the best rational numerator and denominator
|
||||||
## that approximates to `x`, where the denominator is
|
## that approximates to `x`, where the denominator is
|
||||||
## smaller than `n` (default is the largest possible
|
## smaller than `n` (default is the largest possible
|
||||||
|
|
@ -323,8 +323,13 @@ when isMainModule:
|
||||||
assert abs(toFloat(y) - 0.4814814814814815) < 1.0e-7
|
assert abs(toFloat(y) - 0.4814814814814815) < 1.0e-7
|
||||||
assert toInt(z) == 0
|
assert toInt(z) == 0
|
||||||
|
|
||||||
|
when sizeof(int) == 8:
|
||||||
assert toRational(0.98765432) == 2111111029 // 2137499919
|
assert toRational(0.98765432) == 2111111029 // 2137499919
|
||||||
assert toRational(PI) == 817696623 // 260280919
|
assert toRational(PI) == 817696623 // 260280919
|
||||||
|
when sizeof(int) == 4:
|
||||||
|
assert toRational(0.98765432) == 80 // 81
|
||||||
|
assert toRational(PI) == 355 // 113
|
||||||
|
|
||||||
assert toRational(0.1) == 1 // 10
|
assert toRational(0.1) == 1 // 10
|
||||||
assert toRational(0.9) == 9 // 10
|
assert toRational(0.9) == 9 // 10
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -743,6 +743,18 @@ proc newSeqOfCap*[T](cap: Natural): seq[T] {.
|
||||||
## ``cap``.
|
## ``cap``.
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
when not defined(JS):
|
||||||
|
proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] =
|
||||||
|
## creates a new sequence of type ``seq[T]`` with length ``len``.
|
||||||
|
##
|
||||||
|
## Only available for numbers types. Note that the sequence will be
|
||||||
|
## uninitialized. After the creation of the sequence you should assign
|
||||||
|
## entries to the sequence instead of adding them.
|
||||||
|
|
||||||
|
result = newSeqOfCap[T](len)
|
||||||
|
var s = cast[PGenericSeq](result)
|
||||||
|
s.len = len
|
||||||
|
|
||||||
proc len*[TOpenArray: openArray|varargs](x: TOpenArray): int {.
|
proc len*[TOpenArray: openArray|varargs](x: TOpenArray): int {.
|
||||||
magic: "LengthOpenArray", noSideEffect.}
|
magic: "LengthOpenArray", noSideEffect.}
|
||||||
proc len*(x: string): int {.magic: "LengthStr", noSideEffect.}
|
proc len*(x: string): int {.magic: "LengthStr", noSideEffect.}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,9 @@ type
|
||||||
TOptions = set[TOption]
|
TOptions = set[TOption]
|
||||||
TConfirmEnum = enum
|
TConfirmEnum = enum
|
||||||
ceAbort, ceYes, ceAll, ceNo, ceNone
|
ceAbort, ceYes, ceAll, ceNo, ceNone
|
||||||
|
Pattern = Regex | Peg
|
||||||
|
|
||||||
|
using pattern: Pattern
|
||||||
|
|
||||||
var
|
var
|
||||||
filenames: seq[string] = @[]
|
filenames: seq[string] = @[]
|
||||||
|
|
@ -118,7 +121,7 @@ proc highlight(s, match, repl: string, t: tuple[first, last: int],
|
||||||
stdout.write("\n")
|
stdout.write("\n")
|
||||||
stdout.flushFile()
|
stdout.flushFile()
|
||||||
|
|
||||||
proc processFile(filename: string) =
|
proc processFile(pattern; filename: string) =
|
||||||
var filenameShown = false
|
var filenameShown = false
|
||||||
template beforeHighlight =
|
template beforeHighlight =
|
||||||
if not filenameShown and optVerbose notin options:
|
if not filenameShown and optVerbose notin options:
|
||||||
|
|
@ -135,18 +138,8 @@ proc processFile(filename: string) =
|
||||||
if optVerbose in options:
|
if optVerbose in options:
|
||||||
stdout.writeLine(filename)
|
stdout.writeLine(filename)
|
||||||
stdout.flushFile()
|
stdout.flushFile()
|
||||||
var pegp: Peg
|
|
||||||
var rep: Regex
|
|
||||||
var result: string
|
var result: string
|
||||||
|
|
||||||
if optRegex in options:
|
|
||||||
if {optIgnoreCase, optIgnoreStyle} * options != {}:
|
|
||||||
rep = re(pattern, {reExtended, reIgnoreCase})
|
|
||||||
else:
|
|
||||||
rep = re(pattern)
|
|
||||||
else:
|
|
||||||
pegp = peg(pattern)
|
|
||||||
|
|
||||||
if optReplace in options:
|
if optReplace in options:
|
||||||
result = newStringOfCap(buffer.len)
|
result = newStringOfCap(buffer.len)
|
||||||
|
|
||||||
|
|
@ -156,11 +149,7 @@ proc processFile(filename: string) =
|
||||||
for j in 0..high(matches): matches[j] = ""
|
for j in 0..high(matches): matches[j] = ""
|
||||||
var reallyReplace = true
|
var reallyReplace = true
|
||||||
while i < buffer.len:
|
while i < buffer.len:
|
||||||
var t: tuple[first, last: int]
|
let t = findBounds(buffer, pattern, matches, i)
|
||||||
if optRegex notin options:
|
|
||||||
t = findBounds(buffer, pegp, matches, i)
|
|
||||||
else:
|
|
||||||
t = findBounds(buffer, rep, matches, i)
|
|
||||||
if t.first < 0: break
|
if t.first < 0: break
|
||||||
inc(line, countLines(buffer, i, t.first-1))
|
inc(line, countLines(buffer, i, t.first-1))
|
||||||
|
|
||||||
|
|
@ -170,11 +159,7 @@ proc processFile(filename: string) =
|
||||||
if optReplace notin options:
|
if optReplace notin options:
|
||||||
highlight(buffer, wholeMatch, "", t, line, showRepl=false)
|
highlight(buffer, wholeMatch, "", t, line, showRepl=false)
|
||||||
else:
|
else:
|
||||||
var r: string
|
let r = replace(wholeMatch, pattern, replacement % matches)
|
||||||
if optRegex notin options:
|
|
||||||
r = replace(wholeMatch, pegp, replacement % matches)
|
|
||||||
else:
|
|
||||||
r = replace(wholeMatch, rep, replacement % matches)
|
|
||||||
if optConfirm in options:
|
if optConfirm in options:
|
||||||
highlight(buffer, wholeMatch, r, t, line, showRepl=true)
|
highlight(buffer, wholeMatch, r, t, line, showRepl=true)
|
||||||
case confirm()
|
case confirm()
|
||||||
|
|
@ -246,17 +231,17 @@ proc styleInsensitive(s: string): string =
|
||||||
addx()
|
addx()
|
||||||
else: addx()
|
else: addx()
|
||||||
|
|
||||||
proc walker(dir: string) =
|
proc walker(pattern; dir: string) =
|
||||||
for kind, path in walkDir(dir):
|
for kind, path in walkDir(dir):
|
||||||
case kind
|
case kind
|
||||||
of pcFile:
|
of pcFile:
|
||||||
if extensions.len == 0 or path.hasRightExt(extensions):
|
if extensions.len == 0 or path.hasRightExt(extensions):
|
||||||
processFile(path)
|
processFile(pattern, path)
|
||||||
of pcDir:
|
of pcDir:
|
||||||
if optRecursive in options:
|
if optRecursive in options:
|
||||||
walker(path)
|
walker(pattern, path)
|
||||||
else: discard
|
else: discard
|
||||||
if existsFile(dir): processFile(dir)
|
if existsFile(dir): processFile(pattern, dir)
|
||||||
|
|
||||||
proc writeHelp() =
|
proc writeHelp() =
|
||||||
stdout.write(Usage)
|
stdout.write(Usage)
|
||||||
|
|
@ -332,11 +317,18 @@ else:
|
||||||
pattern = "\\y " & pattern
|
pattern = "\\y " & pattern
|
||||||
elif optIgnoreCase in options:
|
elif optIgnoreCase in options:
|
||||||
pattern = "\\i " & pattern
|
pattern = "\\i " & pattern
|
||||||
|
let pegp = peg(pattern)
|
||||||
|
for f in items(filenames):
|
||||||
|
walker(pegp, f)
|
||||||
else:
|
else:
|
||||||
|
var reflags = {reStudy, reExtended}
|
||||||
if optIgnoreStyle in options:
|
if optIgnoreStyle in options:
|
||||||
pattern = styleInsensitive(pattern)
|
pattern = styleInsensitive(pattern)
|
||||||
if optWord in options:
|
if optWord in options:
|
||||||
pattern = r"\b (:?" & pattern & r") \b"
|
pattern = r"\b (:?" & pattern & r") \b"
|
||||||
|
if {optIgnoreCase, optIgnoreStyle} * options != {}:
|
||||||
|
reflags.incl reIgnoreCase
|
||||||
|
let rep = re(pattern, reflags)
|
||||||
for f in items(filenames):
|
for f in items(filenames):
|
||||||
walker(f)
|
walker(rep, f)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue