bugfix: typeinfo.extendSeq

This commit is contained in:
Araq 2013-01-27 19:15:13 +01:00
commit 0758508895
5 changed files with 40 additions and 27 deletions

View file

@ -1,7 +1,7 @@
# #
# #
# Nimrod's Runtime Library # Nimrod's Runtime Library
# (c) Copyright 2012 Dominik Picheta, Andreas Rumpf # (c) Copyright 2013 Dominik Picheta, Andreas Rumpf
# #
# See the file "copying.txt", included in this # See the file "copying.txt", included in this
# distribution, for details about the copyright. # distribution, for details about the copyright.
@ -139,12 +139,15 @@ proc invokeNewSeq*(x: TAny, len: int) =
var z = newSeq(x.rawType, len) var z = newSeq(x.rawType, len)
genericShallowAssign(x.value, addr(z), x.rawType) genericShallowAssign(x.value, addr(z), x.rawType)
proc extendSeq*(x: TAny, elems = 1) = proc extendSeq*(x: TAny) =
## performs ``setLen(x, x.len+elems)``. `x` needs to represent a ``seq``. ## performs ``setLen(x, x.len+1)``. `x` needs to represent a ``seq``.
assert x.rawType.kind == tySequence assert x.rawType.kind == tySequence
var y = cast[ptr PGenSeq](x.value)[] var y = cast[ptr PGenSeq](x.value)[]
var z = incrSeq(y, x.rawType.base.size * elems) var z = incrSeq(y, x.rawType.base.size)
genericShallowAssign(x.value, addr(z), x.rawType) # 'incrSeq' already freed the memory for us and copied over the RC!
# So we simply copy the raw pointer into 'x.value':
cast[ppointer](x.value)[] = z
#genericShallowAssign(x.value, addr(z), x.rawType)
proc setObjectRuntimeType*(x: TAny) = proc setObjectRuntimeType*(x: TAny) =
## this needs to be called to set `x`'s runtime object type field. ## this needs to be called to set `x`'s runtime object type field.

View file

@ -123,7 +123,7 @@ type
tagVar ## the HTML ``var`` element tagVar ## the HTML ``var`` element
const const
tagStrs = [ tagToStr* = [
"a", "abbr", "acronym", "address", "applet", "area", "a", "abbr", "acronym", "address", "applet", "area",
"b", "base", "basefont", "bdo", "big", "blockquote", "body", "b", "base", "basefont", "bdo", "big", "blockquote", "body",
"br", "button", "caption", "center", "cite", "code", "br", "button", "caption", "center", "cite", "code",
@ -243,13 +243,13 @@ proc binaryStrSearch(x: openarray[string], y: string): int =
proc htmlTag*(n: PXmlNode): THtmlTag = proc htmlTag*(n: PXmlNode): THtmlTag =
## gets `n`'s tag as a ``THtmlTag``. ## gets `n`'s tag as a ``THtmlTag``.
if n.clientData == 0: if n.clientData == 0:
n.clientData = binaryStrSearch(tagStrs, n.tag)+1 n.clientData = binaryStrSearch(tagToStr, n.tag)+1
result = THtmlTag(n.clientData) result = THtmlTag(n.clientData)
proc htmlTag*(s: string): THtmlTag = proc htmlTag*(s: string): THtmlTag =
## converts `s` to a ``THtmlTag``. If `s` is no HTML tag, ``tagUnknown`` is ## converts `s` to a ``THtmlTag``. If `s` is no HTML tag, ``tagUnknown`` is
## returned. ## returned.
result = THtmlTag(binaryStrSearch(tagStrs, s.toLower)+1) result = THtmlTag(binaryStrSearch(tagToStr, s.toLower)+1)
proc entityToUtf8*(entity: string): string = proc entityToUtf8*(entity: string): string =
## converts an HTML entity name like ``Ü`` to its UTF-8 equivalent. ## converts an HTML entity name like ``Ü`` to its UTF-8 equivalent.

View file

@ -1,7 +1,7 @@
# #
# #
# Nimrod's Runtime Library # Nimrod's Runtime Library
# (c) Copyright 2012 Andreas Rumpf # (c) Copyright 2013 Andreas Rumpf
# #
# See the file "copying.txt", included in this # See the file "copying.txt", included in this
# distribution, for details about the copyright. # distribution, for details about the copyright.

View file

@ -1,7 +1,7 @@
# #
# #
# Nimrod's Runtime Library # Nimrod's Runtime Library
# (c) Copyright 2012 Andreas Rumpf # (c) Copyright 2013 Andreas Rumpf
# #
# See the file "copying.txt", included in this # See the file "copying.txt", included in this
# distribution, for details about the copyright. # distribution, for details about the copyright.
@ -579,6 +579,10 @@ proc hash(Data: Pointer, Size: int): THash =
Dec(s) Dec(s)
result = !$h result = !$h
proc hashGcHeader(data: pointer): THash =
const headerSize = sizeof(int)*2
result = hash(cast[pointer](cast[int](data) -% headerSize), headerSize)
proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool, proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool,
h: THash): THash h: THash): THash
proc genericHashAux(dest: Pointer, n: ptr TNimNode, shallow: bool, proc genericHashAux(dest: Pointer, n: ptr TNimNode, shallow: bool,
@ -606,16 +610,18 @@ proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool,
result = h result = h
if x != nil: if x != nil:
let s = cast[NimString](x) let s = cast[NimString](x)
when true: when defined(trackGcHeaders):
result = result !& hash(x, s.len) result = result !& hashGcHeader(x)
else: else:
let y = cast[pointer](cast[int](x) -% 2*sizeof(int)) result = result !& hash(x, s.len)
result = result !& hash(y, s.len + 2*sizeof(int))
of tySequence: of tySequence:
var x = cast[ppointer](dest) var x = cast[ppointer](dest)
var dst = cast[taddress](cast[ppointer](dest)[]) var dst = cast[taddress](cast[ppointer](dest)[])
result = h result = h
if dst != 0: if dst != 0:
when defined(trackGcHeaders):
result = result !& hashGcHeader(cast[ppointer](dest)[])
else:
for i in 0..cast[pgenericseq](dst).len-1: for i in 0..cast[pgenericseq](dst).len-1:
result = result !& genericHashAux( result = result !& genericHashAux(
cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize), cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize),
@ -630,6 +636,11 @@ proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool,
result = result !& genericHashAux(cast[pointer](d +% i*% mt.base.size), result = result !& genericHashAux(cast[pointer](d +% i*% mt.base.size),
mt.base, shallow, result) mt.base, shallow, result)
of tyRef: of tyRef:
when defined(trackGcHeaders):
var s = cast[ppointer](dest)[]
if s != nil:
result = result !& hashGcHeader(s)
else:
if shallow: if shallow:
result = h !& hash(dest, mt.size) result = h !& hash(dest, mt.size)
else: else:

View file

@ -3,9 +3,8 @@ version 0.9.2
- implement constructors + full 'not nil' checking - implement constructors + full 'not nil' checking
- ``restrict`` pragma + backend support - ``restrict`` pragma + backend support
- fix marshal bug
- fix: 'result' is not properly cleaned for NRVO - fix: 'result' is not properly cleaned for NRVO
- fix: exhaustive checking in case statements
version 0.9.4 version 0.9.4
============= =============
@ -13,6 +12,8 @@ version 0.9.4
- make 'bind' default for templates and introduce 'mixin'; - make 'bind' default for templates and introduce 'mixin';
special rule for ``[]=`` special rule for ``[]=``
- implicit deref for parameter matching; overloading based on 'var T' - implicit deref for parameter matching; overloading based on 'var T'
- ``=`` should be overloadable; requires specialization for ``=``
- optimize genericAssign in the code generator
version 0.9.X version 0.9.X
@ -25,8 +26,6 @@ version 0.9.X
* nested iterators * nested iterators
- implement the missing features wrt inheritance - implement the missing features wrt inheritance
- improve the compiler as a service - improve the compiler as a service
- ``=`` should be overloadable; requires specialization for ``=``
- optimize genericAssign in the code generator
- better support for macros that rewrite procs - better support for macros that rewrite procs
- macros need access to types and symbols (partially implemented) - macros need access to types and symbols (partially implemented)
- result = result shr 8 for the "system()" wrapper - result = result shr 8 for the "system()" wrapper