From b56df72a325e4991128d808dc6c9edade3d0f293 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 31 Aug 2012 00:00:14 +0200 Subject: [PATCH] made tests green again --- lib/pure/unittest.nim | 1 + lib/pure/xmltree.nim | 2 +- tests/reject/tind1.nim | 2 +- tests/run/tidgen.nim | 2 +- tests/run/tmacro2.nim | 1 + tests/run/tmacros1.nim | 3 ++- tests/run/toop1.nim | 3 ++- tests/run/tquotewords.nim | 3 ++- tests/run/tstringinterp.nim | 2 ++ tests/run/tusingstatement.nim | 3 ++- web/news.txt | 2 +- 11 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim index b2cc54cdff..8ba0c79871 100644 --- a/lib/pure/unittest.nim +++ b/lib/pure/unittest.nim @@ -154,6 +154,7 @@ template require*(conditions: stmt): stmt {.dirty.} = check conditions macro expect*(exp: stmt): stmt = + let exp = callsite() template expectBody(errorTypes, lineInfoLit: expr, body: stmt): PNimrodNode {.dirty.} = try: diff --git a/lib/pure/xmltree.nim b/lib/pure/xmltree.nim index b657ee05ca..1a1467e8fb 100755 --- a/lib/pure/xmltree.nim +++ b/lib/pure/xmltree.nim @@ -258,7 +258,7 @@ proc xmlConstructor(e: PNimrodNode): PNimrodNode {.compileTime.} = else: result = newCall("newXmlTree", toStrLit(a)) -macro `<>`*(x: expr): expr = +macro `<>`*(x: expr): expr {.immediate.} = ## Constructor macro for XML. Example usage: ## ## .. code-block:: nimrod diff --git a/tests/reject/tind1.nim b/tests/reject/tind1.nim index e14de09ce1..6c4135d858 100644 --- a/tests/reject/tind1.nim +++ b/tests/reject/tind1.nim @@ -11,7 +11,7 @@ var x = if 4 != 5: else: "no" -macro mymacro(n: expr): expr = result = n[1][0] +macro mymacro(n: expr): expr = result = n[0] mymacro: echo "test" diff --git a/tests/run/tidgen.nim b/tests/run/tidgen.nim index 0e856dc19b..2fe9e0f82d 100644 --- a/tests/run/tidgen.nim +++ b/tests/run/tidgen.nim @@ -8,7 +8,7 @@ import macros var gid {.compileTime.} = 3 -macro genId(invokation: expr): expr = +macro genId(): expr = result = newIntLitNode(gid) inc gid diff --git a/tests/run/tmacro2.nim b/tests/run/tmacro2.nim index 6aa9bb57d6..8515322d52 100755 --- a/tests/run/tmacro2.nim +++ b/tests/run/tmacro2.nim @@ -13,6 +13,7 @@ proc testBlock(): string {.compileTime.} = result = "ta-da" macro mac(n: expr): expr = + let n = callsite() expectKind(n, nnkCall) expectLen(n, 2) expectKind(n[1], nnkStrLit) diff --git a/tests/run/tmacros1.nim b/tests/run/tmacros1.nim index 8cf2a5aa79..a1bb298237 100755 --- a/tests/run/tmacros1.nim +++ b/tests/run/tmacros1.nim @@ -1,11 +1,12 @@ discard """ - output: "Got: 'nnkIntLit' hi" + output: "Got: 'nnkMacroStmt' hi" """ import macros, strutils macro outterMacro*(n: stmt): stmt = + let n = callsite() var j : string = "hi" proc innerProc(i: int): string = echo "Using arg ! " & n.repr diff --git a/tests/run/toop1.nim b/tests/run/toop1.nim index 017facc4c5..350799f51e 100755 --- a/tests/run/toop1.nim +++ b/tests/run/toop1.nim @@ -35,7 +35,8 @@ proc init(my: var TRectangle) = my.height = 10 my.draw = cast[proc (my: var TFigure) {.nimcall.}](drawRectangle) -macro `!` (n: expr): stmt = +macro `!` (n: expr): stmt {.immediate.} = + let n = callsite() result = newNimNode(nnkCall, n) var dot = newNimNode(nnkDotExpr, n) dot.add(n[1]) # obj diff --git a/tests/run/tquotewords.nim b/tests/run/tquotewords.nim index 81f30c9a9a..76b8d8af77 100755 --- a/tests/run/tquotewords.nim +++ b/tests/run/tquotewords.nim @@ -6,7 +6,8 @@ discard """ import macros -macro quoteWords(n: expr): expr = +macro quoteWords(n: expr): expr {.immediate.} = + let n = callsite() result = newNimNode(nnkBracket, n) for i in 1..n.len-1: expectKind(n[i], nnkIdent) diff --git a/tests/run/tstringinterp.nim b/tests/run/tstringinterp.nim index 676e7ea1dc..f030213e0f 100644 --- a/tests/run/tstringinterp.nim +++ b/tests/run/tstringinterp.nim @@ -18,6 +18,7 @@ template ProcessInterpolations(e: expr) = of ikVar, ikExpr: addExpr(newCall("$", parseExpr(f.value))) macro formatStyleInterpolation(e: expr): expr = + let e = callsite() var formatString = "" arrayNode = newNimNode(nnkBracket) @@ -41,6 +42,7 @@ macro formatStyleInterpolation(e: expr): expr = result[2] = arrayNode macro concatStyleInterpolation(e: expr): expr = + let e = callsite() var args: seq[PNimrodNode] newSeq(args, 0) diff --git a/tests/run/tusingstatement.nim b/tests/run/tusingstatement.nim index ff81684a16..f5168dbf51 100644 --- a/tests/run/tusingstatement.nim +++ b/tests/run/tusingstatement.nim @@ -26,7 +26,8 @@ import # `opened` here could be an overloaded proc which any type can define. # A common practice can be returing an Optional[Resource] obj for which # `opened` is defined to `optional.hasValue` -macro using(e: expr): stmt = +macro using(e: expr): stmt {.immediate.} = + let e = callsite() if e.len != 2: error "Using statement: unexpected number of arguments. Got " & $e.len & ", expected: 1 or more variable assignments and a block" diff --git a/web/news.txt b/web/news.txt index 80f74cd1ec..81bf304a52 100755 --- a/web/news.txt +++ b/web/news.txt @@ -112,7 +112,7 @@ Changes affecting backwards compatibility the ``inheritable`` pragma to introduce new object roots apart from ``TObject``. - Macros now receive parameters like templates do; use the ``callsite`` builtin - to gain access to the invokating AST. + to gain access to the invocation AST. Compiler Additions