typedesc and expr params
types are now valid proc/template/macro params and you can overload over them:
proc foo(T: typedesc) # accept any type
proc foo(T: typedesc{int}) # overload specifically for int
proc foo(T: typedesc{int or float or Callable}) # overload for any type matching the constraints
expr{type} is a param expecting compile time value of the designated type (or type class).
when typedesc or expr params are used with a proc, the proc will be instantiated once
for each unique type/value used as parameter.
This commit is contained in:
parent
6216046bc6
commit
22dc76a361
14 changed files with 218 additions and 45 deletions
|
|
@ -180,14 +180,16 @@ proc addToLib(lib: PLib, sym: PSym) =
|
|||
sym.annex = lib
|
||||
|
||||
proc makePtrType(c: PContext, baseType: PType): PType =
|
||||
if (baseType == nil): InternalError("makePtrType")
|
||||
result = newTypeS(tyPtr, c)
|
||||
addSon(result, baseType)
|
||||
addSon(result, baseType.AssertNotNil)
|
||||
|
||||
proc makeVarType(c: PContext, baseType: PType): PType =
|
||||
if (baseType == nil): InternalError("makeVarType")
|
||||
result = newTypeS(tyVar, c)
|
||||
addSon(result, baseType)
|
||||
addSon(result, baseType.AssertNotNil)
|
||||
|
||||
proc makeTypeDesc*(c: PContext, typ: PType): PType =
|
||||
result = newTypeS(tyTypeDesc, c)
|
||||
result.addSon(typ.AssertNotNil)
|
||||
|
||||
proc newTypeS(kind: TTypeKind, c: PContext): PType =
|
||||
result = newType(kind, getCurrOwner())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue