From 46e9ff61394794245e323034fbb93c24774b8c5c Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 8 Sep 2012 18:51:52 +0200 Subject: [PATCH] tmatrix.nim works now --- compiler/patterns.nim | 30 +++++++++++++++++++++--------- compiler/semtempl.nim | 16 ++++++++++++---- compiler/semtypes.nim | 13 +++++-------- tests/patterns/tmatrix.nim | 4 ++-- todo.txt | 1 - 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/compiler/patterns.nim b/compiler/patterns.nim index 1a2f9b761..7f3bf1556 100644 --- a/compiler/patterns.nim +++ b/compiler/patterns.nim @@ -17,11 +17,20 @@ import type TPatternContext = object owner: PSym - mapping: TIdNodeTable # maps formal parameters to nodes + mapping: seq[PNode] # maps formal parameters to nodes + formals: int c: PContext - subMatch: bool # subnode matches are special + subMatch: bool # subnode matches are special PPatternContext = var TPatternContext +proc getLazy(c: PPatternContext, sym: PSym): PNode = + if not isNil(c.mapping): + result = c.mapping[sym.position] + +proc putLazy(c: PPatternContext, sym: PSym, n: PNode) = + if isNil(c.mapping): newSeq(c.mapping, c.formals) + c.mapping[sym.position] = n + proc matches(c: PPatternContext, p, n: PNode): bool proc canonKind(n: PNode): TNodeKind = @@ -78,22 +87,22 @@ proc matchChoice(c: PPatternContext, p, n: PNode): bool = if matches(c, p.sons[i], n): return true proc bindOrCheck(c: PPatternContext, param: PSym, n: PNode): bool = - var pp = IdNodeTableGetLazy(c.mapping, param) + var pp = GetLazy(c, param) if pp != nil: # check if we got the same pattern (already unified): result = sameTrees(pp, n) #matches(c, pp, n) elif n.kind == nkArgList or checkTypes(c, param, n): - IdNodeTablePutLazy(c.mapping, param, n) + PutLazy(c, param, n) result = true proc gather(c: PPatternContext, param: PSym, n: PNode) = - var pp = IdNodeTableGetLazy(c.mapping, param) + var pp = GetLazy(c, param) if pp != nil and pp.kind == nkArgList: pp.add(n) else: pp = newNodeI(nkArgList, n.info, 1) pp.sons[0] = n - IdNodeTablePutLazy(c.mapping, param, pp) + PutLazy(c, param, pp) proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool = # match ``op * param`` or ``op *| param`` @@ -112,6 +121,9 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool = add(arglist, n) else: result = false + debug p.sons[2].sym.typ + debug n.typ + echo "type check failed!" if n.kind notin nkCallKinds: return false if matches(c, p.sons[1], n.sons[0]): @@ -198,7 +210,7 @@ proc matchStmtList(c: PPatternContext, p, n: PNode): PNode = for j in 0 ..