Remove immediate pragma (#11308)
* remove immediate from tests * remove immediate from the compiler
This commit is contained in:
parent
eb471acffb
commit
5b27b263fd
22 changed files with 53 additions and 116 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import macros
|
||||
|
||||
macro macro_bug*(s: stmt): stmt {.immediate.} =
|
||||
macro macro_bug*(s: untyped) =
|
||||
echo s.treeRepr
|
||||
s.expectKind({nnkProcDef, nnkMethodDef})
|
||||
|
||||
var params = s.params
|
||||
|
|
@ -9,9 +10,9 @@ macro macro_bug*(s: stmt): stmt {.immediate.} =
|
|||
result = newNimNode(nnkProcDef).add(
|
||||
s.name, s[1], genericParams, params, pragma(s), newEmptyNode())
|
||||
|
||||
# don't really do anything
|
||||
var body = body(s)
|
||||
|
||||
# Fails here.
|
||||
var call = newCall("macro_bug", s.params[1][0])
|
||||
body.insert(0, call)
|
||||
result.add(body)
|
||||
|
||||
echo "result:"
|
||||
echo result.repr
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
import macro_bug
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ macro macrotest(n: varargs[untyped]): untyped =
|
|||
result.add(newCall("write", n[1], n[i]))
|
||||
result.add(newCall("writeLine", n[1], newStrLitNode("")))
|
||||
|
||||
macro debug(n: untyped): untyped {.immediate.} =
|
||||
macro debug(n: untyped): untyped =
|
||||
let n = callsite()
|
||||
result = newNimNode(nnkStmtList, n)
|
||||
for i in 1..n.len-1:
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ proc init(my: var TRectangle) =
|
|||
my.height = 10
|
||||
my.draw = cast[proc (my: var TFigure) {.nimcall.}](drawRectangle)
|
||||
|
||||
macro `!` (n: untyped): typed {.immediate.}=
|
||||
macro `!` (n: varargs[untyped]): typed =
|
||||
let n = callsite()
|
||||
result = newNimNode(nnkCall, n)
|
||||
var dot = newNimNode(nnkDotExpr, n)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ discard """
|
|||
"""
|
||||
# Test operator precedence:
|
||||
|
||||
template `@` (x: untyped): untyped {.immediate.} =
|
||||
template `@@` (x: untyped): untyped =
|
||||
`self`.x
|
||||
|
||||
template `@!` (x: untyped): untyped = x
|
||||
|
|
@ -15,11 +15,11 @@ type
|
|||
TA = tuple[a, b: int, obj: TO]
|
||||
|
||||
proc init(self: var TA): string =
|
||||
@a = 3
|
||||
=== @b = 4
|
||||
@obj.x = 4
|
||||
@@a = 3
|
||||
=== @@b = 4
|
||||
@@obj.x = 4
|
||||
@! === result = "abc"
|
||||
result = @b.`$`
|
||||
result = @@b.`$`
|
||||
|
||||
assert 3+5*5-2 == 28- -26-28
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ foo55
|
|||
foo8.0
|
||||
fooaha
|
||||
bar7
|
||||
immediate
|
||||
10
|
||||
4true
|
||||
132
|
||||
|
|
@ -123,21 +122,6 @@ block pattern_with_converter:
|
|||
|
||||
|
||||
|
||||
block prefer_immediate:
|
||||
# Test that immediate templates are preferred over non-immediate templates
|
||||
|
||||
template foo(a, b: untyped) = echo "foo expr"
|
||||
template foo(a, b: int) = echo "foo int"
|
||||
template foo(a, b: float) = echo "foo float"
|
||||
template foo(a, b: string) = echo "foo string"
|
||||
template foo(a, b: untyped) {.immediate.} = echo "immediate"
|
||||
template foo(a, b: bool) = echo "foo bool"
|
||||
template foo(a, b: char) = echo "foo char"
|
||||
|
||||
foo(undeclaredIdentifier, undeclaredIdentifier2)
|
||||
|
||||
|
||||
|
||||
|
||||
block procparshadow:
|
||||
template something(name: untyped) =
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ discard """
|
|||
file: "ttempl2.nim"
|
||||
line: 18
|
||||
"""
|
||||
template declareInScope(x: untyped, t: typeDesc): untyped {.immediate.} =
|
||||
template declareInScope(x: untyped, t: typeDesc): untyped =
|
||||
var x: t
|
||||
|
||||
template declareInNewScope(x: untyped, t: typeDesc): untyped {.immediate.} =
|
||||
template declareInNewScope(x: untyped, t: typeDesc): untyped =
|
||||
# open a new scope:
|
||||
block:
|
||||
var x: t
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ var `hu "XYZ"` = "yay"
|
|||
|
||||
echo prefix(XYZ)
|
||||
|
||||
template typedef(name: untyped, typ: typeDesc) {.immediate, dirty.} =
|
||||
template typedef(name: untyped, typ: typeDesc) {.dirty.} =
|
||||
type
|
||||
`T name`* = typ
|
||||
`P name`* = ref `T name`
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ discard """
|
|||
type Foo* {.pure, final.} = object
|
||||
elt: float
|
||||
|
||||
template defineOpAssign(T, op: untyped) {.immediate.} =
|
||||
proc op*(v: var T, w: T) {.inline.} =
|
||||
template defineOpAssign(T, op: untyped) =
|
||||
proc `op`*(v: var T, w: T) {.inline.} =
|
||||
for i in 0..1:
|
||||
op(v.elt, w.elt)
|
||||
`op`(v.elt, w.elt)
|
||||
|
||||
const ATTEMPT = 0
|
||||
|
||||
|
|
|
|||
|
|
@ -18,14 +18,19 @@ test "previous definitions can be further overloaded or hidden in local scopes":
|
|||
check t("test") == "string"
|
||||
|
||||
test "templates can be redefined multiple times":
|
||||
template customAssert(cond: bool, msg: string): typed {.immediate, dirty.} =
|
||||
template customAssert(cond: bool, msg: string): typed {.dirty.} =
|
||||
if not cond: fail(msg)
|
||||
|
||||
template assertion_failed(body: typed) {.immediate, dirty.} =
|
||||
template fail(msg: string): typed = body
|
||||
template assertionFailed(body: untyped) {.dirty.} =
|
||||
template fail(msg: string): typed =
|
||||
body
|
||||
|
||||
assertionFailed:
|
||||
check(msg == "first fail path")
|
||||
|
||||
assertion_failed: check msg == "first fail path"
|
||||
customAssert false, "first fail path"
|
||||
|
||||
assertion_failed: check msg == "second fail path"
|
||||
assertionFailed:
|
||||
check(msg == "second fail path")
|
||||
|
||||
customAssert false, "second fail path"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue