made tests green again

This commit is contained in:
Araq
2012-08-31 00:00:14 +02:00
parent 1d14cb1ad8
commit b56df72a32
11 changed files with 16 additions and 8 deletions

View File

@@ -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:

View File

@@ -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

View File

@@ -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"

View File

@@ -8,7 +8,7 @@ import macros
var gid {.compileTime.} = 3
macro genId(invokation: expr): expr =
macro genId(): expr =
result = newIntLitNode(gid)
inc gid

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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)

View File

@@ -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"

View File

@@ -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