mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-10 15:04:59 +00:00
made tests green again
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -8,7 +8,7 @@ import macros
|
||||
|
||||
var gid {.compileTime.} = 3
|
||||
|
||||
macro genId(invokation: expr): expr =
|
||||
macro genId(): expr =
|
||||
result = newIntLitNode(gid)
|
||||
inc gid
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user