Static[T] fixes (#7333)

* fix the usage of unresolved static[T] parameters in proc signatures
* fix tsametype and tmacrogenerics
* Allow creating composite type classes with concepts and using them in type signatures
* Allow integers to be used in ident concatenations
* Support using imported C++ generic types in proc signatures
* fixes #7230
* closes #7379
* re-enable some metatype tests
This commit is contained in:
zah 2018-03-24 16:28:09 +02:00 • committed by Andreas Rumpf
commit 121b9e26fb
18 changed files with 265 additions and 26 deletions

View file

@ -0,0 +1,44 @@
discard """
output: "Digest[128]\nDigest[256]"
"""
import typetraits
type
Digest[bits: static[int]] = object
data: array[bits div 8, byte]
ContextKind = enum
A, B, C
HashingContext[bits: static[int], kind: static[ContextKind]] = object
ctx: array[bits div 8, byte]
Hash128 = HashingContext[128, A]
Hash256 = HashingContext[256, B]
HMAC[HashType] = object
h: HashType
proc init(c: var HashingContext) = discard
proc update(c: var HashingContext, data: ptr byte, dataLen: uint) = discard
proc finish(c: var HashingContext): Digest[c.bits] = discard
proc digest(T: typedesc, data: ptr byte, dataLen: uint): Digest[T.bits] =
mixin init, update, finish
var ctx: T
ctx.init()
ctx.update(data, dataLen)
result = ctx.finish()
var h = Hash128.digest(nil, 0)
echo h.type.name
proc finish(hmac: var HMAC): Digest[HMAC.HashType.bits] =
discard
var hm: HMAC[Hash256]
var d = hm.finish
echo d.type.name

View file

@ -1,9 +1,9 @@
discard """
targets: "cpp"
output: "[0, 0, 10, 0]\n5\n1.2\n15\ntest"
output: "[0, 0, 10, 0]\n5\n1.2\n15\ntest\n[0, 0, 20, 0]"
"""
{.emit: """
{.emit: """/*TYPESECTION*/
template <int N, class T>
struct GenericIntType {
@ -51,3 +51,9 @@ echo c.field
echo d.field
echo e.field
proc plus(a, b: GenInt4): GenInt4 =
for i in 0 ..< result.data.len:
result.data[i] = a.data[i] + b.data[i]
echo plus(a, a).data