:= templatable; lexer improvements
This commit is contained in:
parent
e487c0a249
commit
48dd9679bd
11 changed files with 117 additions and 166 deletions
|
|
@ -103,7 +103,7 @@ proc cmpIgnoreCase*(a, b: string): int {.noSideEffect,
|
|||
## | 0 iff a == b
|
||||
## | < 0 iff a < b
|
||||
## | > 0 iff a > b
|
||||
var i = 0
|
||||
var i = 0
|
||||
var m = min(a.len, b.len)
|
||||
while i < m:
|
||||
result = ord(toLower(a[i])) - ord(toLower(b[i]))
|
||||
|
|
@ -406,7 +406,7 @@ proc ParseInt*(s: string): int {.noSideEffect, procvar,
|
|||
## Parses a decimal integer value contained in `s`. If `s` is not
|
||||
## a valid integer, `EInvalidValue` is raised.
|
||||
var L = parseutils.parseInt(s, result, 0)
|
||||
if L != s.len or L == 0:
|
||||
if L != s.len or L == 0:
|
||||
raise newException(EInvalidValue, "invalid integer: " & s)
|
||||
|
||||
proc ParseBiggestInt*(s: string): biggestInt {.noSideEffect, procvar,
|
||||
|
|
@ -414,7 +414,7 @@ proc ParseBiggestInt*(s: string): biggestInt {.noSideEffect, procvar,
|
|||
## Parses a decimal integer value contained in `s`. If `s` is not
|
||||
## a valid integer, `EInvalidValue` is raised.
|
||||
var L = parseutils.parseBiggestInt(s, result, 0)
|
||||
if L != s.len or L == 0:
|
||||
if L != s.len or L == 0:
|
||||
raise newException(EInvalidValue, "invalid integer: " & s)
|
||||
|
||||
proc ParseFloat*(s: string): float {.noSideEffect, procvar,
|
||||
|
|
@ -423,7 +423,7 @@ proc ParseFloat*(s: string): float {.noSideEffect, procvar,
|
|||
## a valid floating point number, `EInvalidValue` is raised. ``NAN``,
|
||||
## ``INF``, ``-INF`` are also supported (case insensitive comparison).
|
||||
var L = parseutils.parseFloat(s, result, 0)
|
||||
if L != s.len or L == 0:
|
||||
if L != s.len or L == 0:
|
||||
raise newException(EInvalidValue, "invalid float: " & s)
|
||||
|
||||
proc ParseHexInt*(s: string): int {.noSideEffect, procvar,
|
||||
|
|
@ -952,7 +952,7 @@ type
|
|||
TFloatFormat* = enum
|
||||
ffDefault, ## use the shorter floating point notation
|
||||
ffDecimal, ## use decimal floating point notation
|
||||
ffScientific ## use scientific notation (using ``e``) character
|
||||
ffScientific ## use scientific notation (using ``e`` character)
|
||||
|
||||
proc formatBiggestFloat*(f: BiggestFloat, format: TFloatFormat = ffDefault,
|
||||
precision = 16): string {.noSideEffect,
|
||||
|
|
@ -1006,6 +1006,6 @@ when isMainModule:
|
|||
it goes""", 10, false)
|
||||
assert formatBiggestFloat(0.00000000001, ffDecimal, 11) == "0.00000000001"
|
||||
assert formatBiggestFloat(0.00000000001, ffScientific, 1) == "1.0e-11"
|
||||
|
||||
|
||||
assert "$# $3 $# $#" % ["a", "b", "c"] == "a c b c"
|
||||
|
||||
|
|
|
|||
|
|
@ -650,13 +650,15 @@ proc setLen*[T](s: var seq[T], newlen: int) {.
|
|||
## 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.
|
||||
## ``s`` will be truncated. `s` cannot be nil! To initialize a sequence with
|
||||
## a size, use ``newSeq`` instead.
|
||||
|
||||
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.
|
||||
## ``s`` will be truncated. `s` cannot be nil! To initialize a string with
|
||||
## a size, use ``newString`` instead.
|
||||
|
||||
proc newString*(len: int): string {.
|
||||
magic: "NewString", importc: "mnewString", noSideEffect.}
|
||||
|
|
|
|||
|
|
@ -642,7 +642,11 @@ proc unmarkStackAndRegisters(gch: var TGcHeap) =
|
|||
var d = gch.decStack.d
|
||||
for i in 0..gch.decStack.len-1:
|
||||
assert isAllocatedPtr(allocator, d[i])
|
||||
decRef(d[i]) # OPT: cannot create a cycle!
|
||||
# decRef(d[i]) inlined: cannot create a cycle
|
||||
var c = d[i]
|
||||
if atomicDec(c.refcount, rcIncrement) <% rcIncrement:
|
||||
rtlAddZCT(c)
|
||||
assert c.typ != nil
|
||||
gch.decStack.len = 0
|
||||
|
||||
proc collectCT(gch: var TGcHeap) =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue