Merge branch 'master' of github.com:Araq/Nimrod into upstream
This commit is contained in:
commit
b2cc17cde4
4 changed files with 49 additions and 20 deletions
|
|
@ -63,7 +63,7 @@ import
|
||||||
|
|
||||||
const
|
const
|
||||||
CacheLeafs* = true
|
CacheLeafs* = true
|
||||||
countCacheMisses* = False # see what our little optimization gives
|
countCacheMisses* = false # see what our little optimization gives
|
||||||
|
|
||||||
type
|
type
|
||||||
TFormatStr* = string # later we may change it to CString for better
|
TFormatStr* = string # later we may change it to CString for better
|
||||||
|
|
@ -118,7 +118,7 @@ proc newMutableRope*(capacity = 30): PRope =
|
||||||
result.data = newStringOfCap(capacity)
|
result.data = newStringOfCap(capacity)
|
||||||
|
|
||||||
var
|
var
|
||||||
cache: PRope # the root of the cache tree
|
cache: array[0..2048 -1, PRope]
|
||||||
misses, hits: int
|
misses, hits: int
|
||||||
N: PRope # dummy rope needed for splay algorithm
|
N: PRope # dummy rope needed for splay algorithm
|
||||||
|
|
||||||
|
|
@ -208,12 +208,18 @@ proc RopeInvariant(r: PRope): bool =
|
||||||
# if result then result := ropeInvariant(r.right);
|
# if result then result := ropeInvariant(r.right);
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
proc insertInCache(s: string): PRope =
|
||||||
|
var h = hash(s) and high(cache)
|
||||||
|
result = cache[h]
|
||||||
|
if isNil(result) or result.data != s:
|
||||||
|
result = newRope(s)
|
||||||
|
cache[h] = result
|
||||||
|
|
||||||
proc toRope(s: string): PRope =
|
proc toRope(s: string): PRope =
|
||||||
if s == "":
|
if s.len == 0:
|
||||||
result = nil
|
result = nil
|
||||||
elif cacheLeafs:
|
elif cacheLeafs:
|
||||||
result = insertInCache(s, cache)
|
result = insertInCache(s)
|
||||||
cache = result
|
|
||||||
else:
|
else:
|
||||||
result = newRope(s)
|
result = newRope(s)
|
||||||
assert(RopeInvariant(result))
|
assert(RopeInvariant(result))
|
||||||
|
|
@ -292,7 +298,7 @@ proc writeRope*(f: TFile, c: PRope) =
|
||||||
write(f, it.data)
|
write(f, it.data)
|
||||||
|
|
||||||
proc WriteRope(head: PRope, filename: string) =
|
proc WriteRope(head: PRope, filename: string) =
|
||||||
var f: tfile # we use a textfile for automatic buffer handling
|
var f: tfile
|
||||||
if open(f, filename, fmWrite):
|
if open(f, filename, fmWrite):
|
||||||
if head != nil: WriteRope(f, head)
|
if head != nil: WriteRope(f, head)
|
||||||
close(f)
|
close(f)
|
||||||
|
|
@ -326,15 +332,15 @@ proc ropef(frmt: TFormatStr, args: openarray[PRope]): PRope =
|
||||||
internalError("ropes: invalid format string $" & $(j))
|
internalError("ropes: invalid format string $" & $(j))
|
||||||
app(result, args[j - 1])
|
app(result, args[j - 1])
|
||||||
of 'n':
|
of 'n':
|
||||||
if not (optLineDir in gOptions): app(result, tnl)
|
if optLineDir notin gOptions: app(result, tnl)
|
||||||
inc i
|
inc i
|
||||||
of 'N':
|
of 'N':
|
||||||
app(result, tnl)
|
app(result, tnl)
|
||||||
inc(i)
|
inc(i)
|
||||||
else: InternalError("ropes: invalid format string $" & frmt[i])
|
else: InternalError("ropes: invalid format string $" & frmt[i])
|
||||||
var start = i
|
var start = i
|
||||||
while (i <= length - 1):
|
while i < length:
|
||||||
if (frmt[i] != '$'): inc(i)
|
if frmt[i] != '$': inc(i)
|
||||||
else: break
|
else: break
|
||||||
if i - 1 >= start:
|
if i - 1 >= start:
|
||||||
app(result, substr(frmt, start, i - 1))
|
app(result, substr(frmt, start, i - 1))
|
||||||
|
|
@ -347,11 +353,11 @@ const
|
||||||
bufSize = 1024 # 1 KB is reasonable
|
bufSize = 1024 # 1 KB is reasonable
|
||||||
|
|
||||||
proc auxRopeEqualsFile(r: PRope, bin: var tfile, buf: Pointer): bool =
|
proc auxRopeEqualsFile(r: PRope, bin: var tfile, buf: Pointer): bool =
|
||||||
if (r.data != nil):
|
if r.data != nil:
|
||||||
if r.length > bufSize:
|
if r.length > bufSize:
|
||||||
internalError("ropes: token too long")
|
internalError("ropes: token too long")
|
||||||
var readBytes = readBuffer(bin, buf, r.length)
|
var readBytes = readBuffer(bin, buf, r.length)
|
||||||
result = (readBytes == r.length) and
|
result = readBytes == r.length and
|
||||||
equalMem(buf, addr(r.data[0]), r.length) # BUGFIX
|
equalMem(buf, addr(r.data[0]), r.length) # BUGFIX
|
||||||
else:
|
else:
|
||||||
result = auxRopeEqualsFile(r.left, bin, buf)
|
result = auxRopeEqualsFile(r.left, bin, buf)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ proc runeLen*(s: string): int {.rtl, extern: "nuc$1".} =
|
||||||
elif ord(s[i]) shr 3 == 0b11110: inc(i, 4)
|
elif ord(s[i]) shr 3 == 0b11110: inc(i, 4)
|
||||||
elif ord(s[i]) shr 2 == 0b111110: inc(i, 5)
|
elif ord(s[i]) shr 2 == 0b111110: inc(i, 5)
|
||||||
elif ord(s[i]) shr 1 == 0b1111110: inc(i, 6)
|
elif ord(s[i]) shr 1 == 0b1111110: inc(i, 6)
|
||||||
else: assert(false)
|
else: inc i
|
||||||
inc(result)
|
inc(result)
|
||||||
|
|
||||||
proc runeLenAt*(s: string, i: int): int =
|
proc runeLenAt*(s: string, i: int): int =
|
||||||
|
|
@ -45,7 +45,7 @@ proc runeLenAt*(s: string, i: int): int =
|
||||||
elif ord(s[i]) shr 3 == 0b11110: result = 4
|
elif ord(s[i]) shr 3 == 0b11110: result = 4
|
||||||
elif ord(s[i]) shr 2 == 0b111110: result = 5
|
elif ord(s[i]) shr 2 == 0b111110: result = 5
|
||||||
elif ord(s[i]) shr 1 == 0b1111110: result = 6
|
elif ord(s[i]) shr 1 == 0b1111110: result = 6
|
||||||
else: assert(false)
|
else: result = 1
|
||||||
|
|
||||||
template fastRuneAt*(s: string, i: int, result: expr, doInc = true) =
|
template fastRuneAt*(s: string, i: int, result: expr, doInc = true) =
|
||||||
## Returns the unicode character ``s[i]`` in `result`. If ``doInc == true``
|
## Returns the unicode character ``s[i]`` in `result`. If ``doInc == true``
|
||||||
|
|
@ -100,7 +100,8 @@ template fastRuneAt*(s: string, i: int, result: expr, doInc = true) =
|
||||||
(ord(s[i+5]) and ones(6)))
|
(ord(s[i+5]) and ones(6)))
|
||||||
when doInc: inc(i, 6)
|
when doInc: inc(i, 6)
|
||||||
else:
|
else:
|
||||||
assert(false)
|
result = TRune(ord(s[i]))
|
||||||
|
when doInc: inc(i)
|
||||||
|
|
||||||
proc runeAt*(s: string, i: int): TRune =
|
proc runeAt*(s: string, i: int): TRune =
|
||||||
## returns the unicode character in `s` at byte index `i`
|
## returns the unicode character in `s` at byte index `i`
|
||||||
|
|
@ -128,7 +129,8 @@ proc toUTF8*(c: TRune): string {.rtl, extern: "nuc$1".} =
|
||||||
result[2] = chr(i shr 6 and ones(6) or 0b10_0000_00)
|
result[2] = chr(i shr 6 and ones(6) or 0b10_0000_00)
|
||||||
result[3] = chr(i and ones(6) or 0b10_0000_00)
|
result[3] = chr(i and ones(6) or 0b10_0000_00)
|
||||||
else:
|
else:
|
||||||
assert false
|
result = newString(1)
|
||||||
|
result[0] = chr(i)
|
||||||
|
|
||||||
const
|
const
|
||||||
alphaRanges = [
|
alphaRanges = [
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -49,7 +49,7 @@ Bugs
|
||||||
without ``-d:release`` leaks memory?
|
without ``-d:release`` leaks memory?
|
||||||
- bug: object {.pure, final.} does not work again!
|
- bug: object {.pure, final.} does not work again!
|
||||||
- bug: {.error: "msg".} produces invalid pragma message
|
- bug: {.error: "msg".} produces invalid pragma message
|
||||||
- bug: tsortdev does not run with native GC?
|
- bug: tsortdev does not run with native GC!!
|
||||||
- bug: pragma statements in combination with symbol files are evaluated twice
|
- bug: pragma statements in combination with symbol files are evaluated twice
|
||||||
but this can lead to compilation errors
|
but this can lead to compilation errors
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,30 @@
|
||||||
# result = "#! /bin/sh\n# Generated from niminst\n" &
|
# result = "#! /bin/sh\n# Generated from niminst\n" &
|
||||||
# "# Template is in tools/buildsh.tmpl\n" &
|
# "# Template is in tools/buildsh.tmpl\n" &
|
||||||
# "# To regenerate run ``niminst csource`` or ``koch csource``\n"
|
# "# To regenerate run ``niminst csource`` or ``koch csource``\n"
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
--extraBuildArgs)
|
||||||
|
extraBuildArgs=" $2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--) # End of all options
|
||||||
|
shift
|
||||||
|
break;
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
echo "Error: Unknown option: $1" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*) # No more options
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
CC="gcc"
|
CC="gcc"
|
||||||
LINKER="gcc"
|
LINKER="gcc"
|
||||||
COMP_FLAGS="?{c.ccompiler.flags}"
|
COMP_FLAGS="?{c.ccompiler.flags}$extraBuildArgs"
|
||||||
LINK_FLAGS="?{c.linker.flags}"
|
LINK_FLAGS="?{c.linker.flags}"
|
||||||
# add(result, "# platform detection\n")
|
# add(result, "# platform detection\n")
|
||||||
ucpu=`uname -m`
|
ucpu=`uname -m`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue