diff options
author | Zahary Karadjov <zahary@gmail.com> | 2013-12-19 01:06:38 +0200 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2013-12-19 01:06:38 +0200 |
commit | 027f30610e44633b661befcca1b5dd39e9eaa283 (patch) | |
tree | 45841cac06bf79c512b050791697ce68b36b58ed /compiler/sigmatch.nim | |
parent | 7120491d055c04d838d9539fdf0c42003637ec2d (diff) | |
download | Nim-027f30610e44633b661befcca1b5dd39e9eaa283.tar.gz |
static params: expr[T] is now static[T]
This introduces tyStatic and successfully bootstraps and handles few simple test cases. Static params within macros are no longer treated as PNimrodNodes - they are now equivalent to constants of the designated type.
Diffstat (limited to 'compiler/sigmatch.nim')
-rw-r--r-- | compiler/sigmatch.nim | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index cacf4782e..87f1decf4 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -124,7 +124,7 @@ proc sumGeneric(t: PType): int = result = ord(t.kind == tyGenericInvokation) for i in 0 .. <t.len: result += t.sons[i].sumGeneric break - of tyGenericParam, tyExpr, tyStmt, tyTypeDesc, tyTypeClass: break + of tyGenericParam, tyExpr, tyStatic, tyStmt, tyTypeDesc, tyTypeClass: break else: return 0 proc complexDisambiguation(a, b: PType): int = @@ -894,40 +894,39 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, argType: PType, arg = argSemantized let - a = if c.InTypeClass > 0: argType.skipTypes({tyTypeDesc}) - else: argType - fMaybeExpr = f.skipTypes({tyDistinct}) - - case fMaybeExpr.kind - of tyExpr: - if fMaybeExpr.sonsLen == 0: - r = isGeneric + a0 = if c.InTypeClass > 0: argType.skipTypes({tyTypeDesc}) + else: argType + a = if a0 != nil: a0.skipTypes({tyStatic}) else: a0 + fMaybeStatic = f.skipTypes({tyDistinct}) + + case fMaybeStatic.kind + of tyStatic: + if a.kind == tyStatic: + InternalAssert a.len > 0 + r = typeRel(m, f.lastSon, a.lastSon) else: - if a.kind == tyExpr: - InternalAssert a.len > 0 - r = typeRel(m, f.lastSon, a.lastSon) + let match = matchTypeClass(m.bindings, fMaybeStatic, a) + if not match: r = isNone else: - let match = matchTypeClass(m.bindings, fMaybeExpr, a) - if not match: r = isNone - else: - # XXX: Ideally, this should happen much earlier somewhere near - # semOpAux, but to do that, we need to be able to query the - # overload set to determine whether compile-time value is expected - # for the param before entering the full-blown sigmatch algorithm. - # This is related to the immediate pragma since querying the - # overload set could help there too. - var evaluated = c.semConstExpr(c, arg) - if evaluated != nil: - r = isGeneric - arg.typ = newTypeS(tyExpr, c) - arg.typ.sons = @[evaluated.typ] - arg.typ.n = evaluated + # XXX: Ideally, this should happen much earlier somewhere near + # semOpAux, but to do that, we need to be able to query the + # overload set to determine whether compile-time value is expected + # for the param before entering the full-blown sigmatch algorithm. + # This is related to the immediate pragma since querying the + # overload set could help there too. + var evaluated = c.semConstExpr(c, arg) + if evaluated != nil: + r = isGeneric + arg.typ = newTypeS(tyStatic, c) + arg.typ.sons = @[evaluated.typ] + arg.typ.n = evaluated if r == isGeneric: put(m.bindings, f, arg.typ) + of tyTypeClass, tyParametricTypeClass: - if fMaybeExpr.n != nil: - let match = matchUserTypeClass(c, m, arg, fMaybeExpr, a) + if fMaybeStatic.n != nil: + let match = matchUserTypeClass(c, m, arg, fMaybeStatic, a) if match != nil: r = isGeneric arg = match @@ -935,6 +934,9 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, argType: PType, r = isNone else: r = typeRel(m, f, a) + of tyExpr: + r = isGeneric + put(m.bindings, f, arg.typ) else: r = typeRel(m, f, a) @@ -961,6 +963,8 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, argType: PType, result = argOrig[bodyPos] elif f.kind == tyTypeDesc: result = arg + elif f.kind == tyStatic: + result = arg.typ.n else: result = argOrig else: |