diff options
Diffstat (limited to 'compiler/semfold.nim')
-rw-r--r-- | compiler/semfold.nim | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim index a6c185fdc..0a33fea7a 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -173,32 +173,41 @@ proc makeRangeF(typ: PType, first, last: BiggestFloat; g: ModuleGraph): PType = result.n = n addSonSkipIntLit(result, skipTypes(typ, {tyRange})) -proc evalIs(n, a: PNode): PNode = +proc evalIs(n: PNode, lhs: PSym, g: ModuleGraph): PNode = # XXX: This should use the standard isOpImpl - #internalAssert a.kind == nkSym and a.sym.kind == skType - #internalAssert n.sonsLen == 3 and - # n[2].kind in {nkStrLit..nkTripleStrLit, nkType} + internalAssert g.config, + n.sonsLen == 3 and + lhs.typ != nil and + n[2].kind in {nkStrLit..nkTripleStrLit, nkType} - let t1 = a.sym.typ + var + res = false + t1 = lhs.typ + t2 = n[2].typ + + if t1.kind == tyTypeDesc and t2.kind != tyTypeDesc: + t1 = t1.base if n[2].kind in {nkStrLit..nkTripleStrLit}: case n[2].strVal.normalize of "closure": let t = skipTypes(t1, abstractRange) - result = newIntNode(nkIntLit, ord(t.kind == tyProc and - t.callConv == ccClosure and - tfIterator notin t.flags)) + res = t.kind == tyProc and + t.callConv == ccClosure and + tfIterator notin t.flags of "iterator": let t = skipTypes(t1, abstractRange) - result = newIntNode(nkIntLit, ord(t.kind == tyProc and - t.callConv == ccClosure and - tfIterator in t.flags)) - else: discard + res = t.kind == tyProc and + t.callConv == ccClosure and + tfIterator in t.flags + else: + res = false else: # XXX semexprs.isOpImpl is slightly different and requires a context. yay. let t2 = n[2].typ - var match = sameType(t1, t2) - result = newIntNode(nkIntLit, ord(match)) + res = sameType(t1, t2) + + result = newIntNode(nkIntLit, ord(res)) result.typ = n.typ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode = @@ -584,6 +593,9 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = result = copyTree(s.ast) of skProc, skFunc, skMethod: result = n + of skParam: + if s.typ != nil and s.typ.kind == tyTypeDesc: + result = newSymNodeTypeDesc(s, n.info) of skType: # XXX gensym'ed symbols can come here and cannot be resolved. This is # dirty, but correct. @@ -651,9 +663,9 @@ proc getConstExpr(m: PSym, n: PNode; g: ModuleGraph): PNode = of mConStrStr: result = foldConStrStr(m, n, g) of mIs: - let a = getConstExpr(m, n[1], g) - if a != nil and a.kind == nkSym and a.sym.kind == skType: - result = evalIs(n, a) + let lhs = getConstExpr(m, n[1], g) + if lhs != nil and lhs.kind == nkSym: + result = evalIs(n, lhs.sym, g) else: result = magicCall(m, n, g) except OverflowError: |