bugfix: typeinfo.extendSeq

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

View File

@@ -1,7 +1,7 @@
#
#
# 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
# distribution, for details about the copyright.
@@ -139,12 +139,15 @@ proc invokeNewSeq*(x: TAny, len: int) =
var z = newSeq(x.rawType, len)
genericShallowAssign(x.value, addr(z), x.rawType)
proc extendSeq*(x: TAny, elems = 1) =
## performs ``setLen(x, x.len+elems)``. `x` needs to represent a ``seq``.
proc extendSeq*(x: TAny) =
## performs ``setLen(x, x.len+1)``. `x` needs to represent a ``seq``.
assert x.rawType.kind == tySequence
var y = cast[ptr PGenSeq](x.value)[]
var z = incrSeq(y, x.rawType.base.size * elems)
genericShallowAssign(x.value, addr(z), x.rawType)
var z = incrSeq(y, x.rawType.base.size)
# '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) =
## 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
const
tagStrs = [
tagToStr* = [
"a", "abbr", "acronym", "address", "applet", "area",
"b", "base", "basefont", "bdo", "big", "blockquote", "body",
"br", "button", "caption", "center", "cite", "code",
@@ -243,13 +243,13 @@ proc binaryStrSearch(x: openarray[string], y: string): int =
proc htmlTag*(n: PXmlNode): THtmlTag =
## gets `n`'s tag as a ``THtmlTag``.
if n.clientData == 0:
n.clientData = binaryStrSearch(tagStrs, n.tag)+1
n.clientData = binaryStrSearch(tagToStr, n.tag)+1
result = THtmlTag(n.clientData)
proc htmlTag*(s: string): THtmlTag =
## converts `s` to a ``THtmlTag``. If `s` is no HTML tag, ``tagUnknown`` is
## returned.
result = THtmlTag(binaryStrSearch(tagStrs, s.toLower)+1)
result = THtmlTag(binaryStrSearch(tagToStr, s.toLower)+1)
proc entityToUtf8*(entity: string): string =
## converts an HTML entity name like ``Ü`` to its UTF-8 equivalent.

View File

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

View File

@@ -1,7 +1,7 @@
#
#
# Nimrod's Runtime Library
# (c) Copyright 2012 Andreas Rumpf
# (c) Copyright 2013 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
@@ -579,6 +579,10 @@ proc hash(Data: Pointer, Size: int): THash =
Dec(s)
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,
h: THash): THash
proc genericHashAux(dest: Pointer, n: ptr TNimNode, shallow: bool,
@@ -606,20 +610,22 @@ proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool,
result = h
if x != nil:
let s = cast[NimString](x)
when true:
result = result !& hash(x, s.len)
when defined(trackGcHeaders):
result = result !& hashGcHeader(x)
else:
let y = cast[pointer](cast[int](x) -% 2*sizeof(int))
result = result !& hash(y, s.len + 2*sizeof(int))
result = result !& hash(x, s.len)
of tySequence:
var x = cast[ppointer](dest)
var dst = cast[taddress](cast[ppointer](dest)[])
result = h
if dst != 0:
for i in 0..cast[pgenericseq](dst).len-1:
result = result !& genericHashAux(
cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize),
mt.Base, shallow, result)
when defined(trackGcHeaders):
result = result !& hashGcHeader(cast[ppointer](dest)[])
else:
for i in 0..cast[pgenericseq](dst).len-1:
result = result !& genericHashAux(
cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize),
mt.Base, shallow, result)
of tyObject, tyTuple:
# we don't need to copy m_type field for tyObject, as they are equal anyway
result = genericHashAux(dest, mt.node, shallow, h)
@@ -630,13 +636,18 @@ proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool,
result = result !& genericHashAux(cast[pointer](d +% i*% mt.base.size),
mt.base, shallow, result)
of tyRef:
if shallow:
result = h !& hash(dest, mt.size)
else:
result = h
when defined(trackGcHeaders):
var s = cast[ppointer](dest)[]
if s != nil:
result = result !& genericHashAux(s, mt.base, shallow, result)
result = result !& hashGcHeader(s)
else:
if shallow:
result = h !& hash(dest, mt.size)
else:
result = h
var s = cast[ppointer](dest)[]
if s != nil:
result = result !& genericHashAux(s, mt.base, shallow, result)
# hash the object header:
#const headerSize = sizeof(int)*2
#result = result !& hash(cast[pointer](cast[int](s) -% headerSize),

View File

@@ -3,9 +3,8 @@ version 0.9.2
- implement constructors + full 'not nil' checking
- ``restrict`` pragma + backend support
- fix marshal bug
- fix: 'result' is not properly cleaned for NRVO
- fix: exhaustive checking in case statements
version 0.9.4
=============
@@ -13,6 +12,8 @@ version 0.9.4
- make 'bind' default for templates and introduce 'mixin';
special rule for ``[]=``
- 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
@@ -25,8 +26,6 @@ version 0.9.X
* nested iterators
- implement the missing features wrt inheritance
- 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
- macros need access to types and symbols (partially implemented)
- result = result shr 8 for the "system()" wrapper