* --define:nimQuirky exception handling for Nim; in preparation of a blog post
* make it work with latest system.nim
* make code more readable
* fixes #10702
This commit is contained in:
Andreas Rumpf 2019-02-18 15:23:05 +01:00 • committed by GitHub
commit 2deb1e354f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 118 additions and 50 deletions

View file

@ -14,10 +14,10 @@ macro checkType(ex: typed; expected: string): untyped =
macro checkProcType(fn: typed): untyped =
let fn_sym = if fn.kind == nnkProcDef: fn[0] else: fn
echo fn_sym, "; ", fn_sym.typeKind, "; ", fn_sym.getType.repr, "; ", fn_sym.getTypeImpl.repr
proc voidProc = echo "hello"
proc intProc(a: int, b: float): int {.checkProcType.} = 10
proc intProc(a: int, b: float): int {.checkProcType.} = 10
checkType(voidProc(), "void")
checkType(intProc(10, 20.0), "int")
@ -38,3 +38,33 @@ block:
Club = Blub
static: doAssert(c == 1)
# bug #10702
type
VectorElementType = SomeNumber | bool
Vec*[N : static[int], T: VectorElementType] = object
arr*: array[N, T]
type
Vec4*[T: VectorElementType] = Vec[4,T]
Vec3*[T: VectorElementType] = Vec[3,T]
Vec2*[T: VectorElementType] = Vec[2,T]
template vecGen(U:untyped,V:typed):typed=
## ``U`` suffix
## ``V`` valType
##
type
`Vec2 U`* {.inject.} = Vec2[V]
`Vec3 U`* {.inject.} = Vec3[V]
`Vec4 U`* {.inject.} = Vec4[V]
vecGen(f, float32)
macro foobar(arg: typed): untyped =
let typ = arg.getTypeInst
doAssert typ.getImpl[^1].kind == nnkCall
var x: Vec2f
foobar(x)