diff options
author | Araq <rumpf_a@web.de> | 2011-06-11 17:03:57 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-06-11 17:03:57 +0200 |
commit | 165302cda44d1a1336e19f2399f9f4a9b917bd59 (patch) | |
tree | 0de7c48b8f2c492004a041d9508520c276bd2c2e | |
parent | ec2bd53ead04bc2ea6b8d6186f5f28f253ff859d (diff) | |
parent | bf685877b567623f14a6c9cf9ba5cfd0b5ab4455 (diff) | |
download | Nim-165302cda44d1a1336e19f2399f9f4a9b917bd59.tar.gz |
Merge branch 'master' of git@github.com:Araq/Nimrod
-rw-r--r-- | lib/core/typeinfo.nim | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim index d6415d6dc..f78f671da 100644 --- a/lib/core/typeinfo.nim +++ b/lib/core/typeinfo.nim @@ -103,6 +103,15 @@ proc `[]=`*(x: TAny, i: int, y: TAny) = genericAssign(cast[pointer](cast[TAddress](s) + GenericSeqSize+i*bs), y.value, y.rawType) +proc len*(x: TAny): int = + assert getType(x) in {TNArray, TNSequence} + if x.getType == TNArray: + var bs = x.rawType.base.size + return (x.rawType.size div bs) + elif x.getType == TNSequence: + var s = cast[ppointer](x.value)[] + return cast[PGenSeq](s).len + proc fieldsAux(p: pointer, n: ptr TNimNode, ret: var seq[tuple[name: cstring, any: TAny]]) = case n.kind @@ -142,17 +151,17 @@ proc `[]`*(x: TAny): TAny = result.value = p result.rawType = x.rawType.base -proc readInt*(x: TAny): int = cast[ptr int](x.value)[] -proc readInt8*(x: TAny): int8 = cast[ptr int8](x.value)[] -proc readInt16*(x: TAny): int16 = cast[ptr int16](x.value)[] -proc readInt32*(x: TAny): int32 = cast[ptr int32](x.value)[] -proc readInt64*(x: TAny): int64 = cast[ptr int64](x.value)[] +proc readInt*(x: TAny): int = return cast[ptr int](x.value)[] +proc readInt8*(x: TAny): int8 = return cast[ptr int8](x.value)[] +proc readInt16*(x: TAny): int16 = return cast[ptr int16](x.value)[] +proc readInt32*(x: TAny): int32 = return cast[ptr int32](x.value)[] +proc readInt64*(x: TAny): int64 = return cast[ptr int64](x.value)[] -proc readFloat*(x: TAny): float = cast[ptr float](x.value)[] -proc readFloat32*(x: TAny): float32 = cast[ptr float32](x.value)[] -proc readFloat64*(x: TAny): float64 = cast[ptr float64](x.value)[] +proc readFloat*(x: TAny): float = return cast[ptr float](x.value)[] +proc readFloat32*(x: TAny): float32 = return cast[ptr float32](x.value)[] +proc readFloat64*(x: TAny): float64 = return cast[ptr float64](x.value)[] -proc readString*(x: TAny): string = cast[ptr string](x.value)[] +proc readString*(x: TAny): string = return cast[ptr string](x.value)[] when isMainModule: type |