next steps towards term rewriting macros; simple examples work

This commit is contained in:
Araq 2012-08-30 22:55:32 +02:00
commit 1d14cb1ad8
17 changed files with 124 additions and 56 deletions

View file

@ -770,6 +770,10 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
else:
s.typ = newTypeS(tyProc, c)
rawAddSon(s.typ, nil)
if n.sons[patternPos].kind != nkEmpty:
n.sons[patternPos] = semPattern(c, n.sons[patternPos])
c.patterns.add(s)
var proto = SearchForProc(c, s, c.tab.tos-2) # -2 because we have a scope
# open for parameters
if proto == nil:
@ -1202,17 +1206,7 @@ proc SemStmt(c: PContext, n: PNode): PNode =
result = semPragmaBlock(c, n)
of nkStaticStmt:
result = semStaticStmt(c, n)
of nkPatternStmt:
let pat = semPatternStmt(c, n)
let s = getCurrOwner()
if s.kind in routineKinds and s.ast.sons[patternPos].kind == nkEmpty:
s.ast.sons[patternPos] = pat
c.patterns.add(s)
else:
LocalError(n.info, errXNotAllowedHere, "'as'")
# replace by an empty statement:
result = newNodeI(nkNilLit, n.info)
else:
else:
# in interactive mode, we embed the expression in an 'echo':
if gCmd == cmdInteractive:
result = buildEchoStmt(c, semExpr(c, n))