Remove expr/stmt (#5857)
This commit is contained in:
parent
52ff244d5d
commit
000b8afd26
168 changed files with 497 additions and 529 deletions
|
|
@ -11,7 +11,7 @@ type
|
|||
TTextKind = enum
|
||||
TFoo, TBar
|
||||
|
||||
macro test: stmt =
|
||||
macro test: untyped =
|
||||
var x = @[TFoo, TBar]
|
||||
result = newStmtList()
|
||||
for i in x:
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ iterator test2(f: string): Foo =
|
|||
for i in f:
|
||||
yield Foo(s: i)
|
||||
|
||||
macro test(): stmt =
|
||||
macro test(): untyped =
|
||||
for i in test2("asdf"):
|
||||
echo i.s
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ import macros
|
|||
|
||||
type TType = tuple[s: string]
|
||||
|
||||
macro echotest(): stmt =
|
||||
macro echotest(): untyped =
|
||||
var t: TType
|
||||
t.s = ""
|
||||
t.s.add("test")
|
||||
|
|
@ -61,7 +61,7 @@ proc get_data(d: Td) : string {.compileTime.} =
|
|||
#result.add("aa") # B
|
||||
#result = result & "aa" # C
|
||||
|
||||
macro m(s:static[Td]) : stmt =
|
||||
macro m(s:static[Td]) : untyped =
|
||||
echo get_data(s)
|
||||
echo get_data(s)
|
||||
result = newEmptyNode()
|
||||
|
|
@ -77,7 +77,7 @@ proc nilcheck(): NimNode {.compileTime.} =
|
|||
echo(result.isNil) # true
|
||||
echo(repr(result)) # nil
|
||||
|
||||
macro testnilcheck(): stmt =
|
||||
macro testnilcheck(): untyped =
|
||||
result = newNimNode(nnkStmtList)
|
||||
discard nilcheck()
|
||||
|
||||
|
|
@ -95,10 +95,10 @@ echo c[0]
|
|||
|
||||
# bug #3046
|
||||
|
||||
macro sampleMacroInt(i: int): stmt =
|
||||
macro sampleMacroInt(i: int): untyped =
|
||||
echo i.intVal
|
||||
|
||||
macro sampleMacroBool(b: bool): stmt =
|
||||
macro sampleMacroBool(b: bool): untyped =
|
||||
echo b.boolVal
|
||||
|
||||
sampleMacroInt(42)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ OK
|
|||
import macros
|
||||
|
||||
# Bug from the forum
|
||||
macro addEcho1(s: untyped): stmt =
|
||||
macro addEcho1(s: untyped): untyped =
|
||||
s.body.add(newCall("echo", newStrLitNode("OK")))
|
||||
result = s
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ proc foo(): seq[NimNode] {.compiletime.} =
|
|||
result.add test()
|
||||
result.add parseExpr("echo(5+56)")
|
||||
|
||||
macro bar(): stmt =
|
||||
macro bar(): typed =
|
||||
result = newNimNode(nnkStmtList)
|
||||
let x = foo()
|
||||
for xx in x:
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ x: some string'''
|
|||
|
||||
import macros
|
||||
|
||||
macro debug(n: varargs[expr]): stmt =
|
||||
macro debug(n: varargs[untyped]): untyped =
|
||||
# `n` is a Nim AST that contains the whole macro invocation
|
||||
# this macro returns a list of statements:
|
||||
result = newNimNode(nnkStmtList, n)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ proc dumpit(n: NimNode): string {.compileTime.} =
|
|||
add(result, dumpit(n[j]))
|
||||
add(result, ")")
|
||||
|
||||
macro dumpAST(n: stmt): stmt {.immediate.} =
|
||||
macro dumpAST(n): untyped =
|
||||
# dump AST as a side-effect and return the inner node
|
||||
let n = callsite()
|
||||
echo dumpit(n)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ Infix
|
|||
"""
|
||||
import macros
|
||||
|
||||
macro def(x: stmt): stmt {.immediate.} =
|
||||
macro def(x): untyped =
|
||||
echo treeRepr(x)
|
||||
|
||||
def name(a, b:cint) => nil
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ proc convertReturns(node, retFutureSym: NimNode): NimNode {.compileTime.} =
|
|||
for i in 0 .. <node.len:
|
||||
result[i] = convertReturns(node[i], retFutureSym)
|
||||
|
||||
macro async2(prc: stmt): stmt {.immediate.} =
|
||||
macro async2(prc: untyped): untyped =
|
||||
expectKind(prc, nnkProcDef)
|
||||
|
||||
var outerProcBody = newNimNode(nnkStmtList)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ proc parse_template(node: NimNode, value: string) {.compiletime.} =
|
|||
while index < value.len and
|
||||
parse_until_symbol(node, value, index): discard
|
||||
|
||||
macro tmpli*(body: expr): stmt =
|
||||
macro tmpli*(body: untyped): typed =
|
||||
result = newStmtList()
|
||||
result.add parseExpr("result = \"\"")
|
||||
result.parse_template body[1].strVal
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ type
|
|||
name : string
|
||||
password : string
|
||||
|
||||
macro testUser: expr =
|
||||
return newLit(User.getType.lispRepr)
|
||||
macro testUser: string =
|
||||
result = newLit(User.getType.lispRepr)
|
||||
|
||||
macro testGeneric(T: typedesc[Model]): expr =
|
||||
return newLit(T.getType.lispRepr)
|
||||
macro testGeneric(T: typedesc[Model]): string=
|
||||
result = newLit(T.getType.lispRepr)
|
||||
|
||||
echo testUser
|
||||
echo User.testGeneric
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ proc symToIdent(x: NimNode): NimNode =
|
|||
result.add symToIdent(c)
|
||||
|
||||
# check getTypeInst and getTypeImpl for given symbol x
|
||||
macro testX(x,inst0: typed; recurse: static[bool]; implX: stmt): typed =
|
||||
macro testX(x,inst0: typed; recurse: static[bool]; implX: typed): typed =
|
||||
# check that getTypeInst(x) equals inst0
|
||||
let inst = x.getTypeInst
|
||||
let instr = inst.symToIdent.treeRepr
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import macros
|
|||
|
||||
var gid {.compileTime.} = 3
|
||||
|
||||
macro genId(): expr =
|
||||
macro genId(): int =
|
||||
result = newIntLitNode(gid)
|
||||
inc gid
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import macros
|
|||
|
||||
from uri import `/`
|
||||
|
||||
macro test*(a: stmt): stmt {.immediate.} =
|
||||
macro test*(a: untyped): untyped =
|
||||
var nodes: tuple[a, b: int]
|
||||
nodes.a = 4
|
||||
nodes[1] = 45
|
||||
|
|
@ -20,4 +20,3 @@ macro test*(a: stmt): stmt {.immediate.} =
|
|||
|
||||
test:
|
||||
"hi"
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ proc testBlock(): string {.compileTime.} =
|
|||
echo "outer block"
|
||||
result = "ta-da"
|
||||
|
||||
macro mac(n: expr): expr =
|
||||
macro mac(n: typed): string =
|
||||
let n = callsite()
|
||||
expectKind(n, nnkCall)
|
||||
expectLen(n, 2)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ type
|
|||
TA = tuple[a: int]
|
||||
PA = ref TA
|
||||
|
||||
macro test*(a: stmt): stmt {.immediate.} =
|
||||
macro test*(a: untyped): untyped =
|
||||
var val: PA
|
||||
new(val)
|
||||
val.a = 4
|
||||
|
|
@ -16,7 +16,7 @@ macro test*(a: stmt): stmt {.immediate.} =
|
|||
test:
|
||||
"hi"
|
||||
|
||||
macro test2*(a: stmt): stmt {.immediate.} =
|
||||
macro test2*(a: untyped): untyped =
|
||||
proc testproc(recurse: int) =
|
||||
echo "Thats weird"
|
||||
var o : NimNode = nil
|
||||
|
|
@ -28,4 +28,3 @@ macro test2*(a: stmt): stmt {.immediate.} =
|
|||
|
||||
test2:
|
||||
"hi"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ discard """
|
|||
import
|
||||
macros, strutils
|
||||
|
||||
macro test_macro*(s: string, n: stmt): stmt {.immediate.} =
|
||||
macro test_macro*(s: string, n: untyped): untyped =
|
||||
result = newNimNode(nnkStmtList)
|
||||
var ass : NimNode = newNimNode(nnkAsgn)
|
||||
add(ass, newIdentNode("str"))
|
||||
|
|
@ -16,4 +16,3 @@ when isMainModule:
|
|||
test_macro(str):
|
||||
var i : integer = 123
|
||||
echo str
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import macros,json
|
|||
var decls{.compileTime.}: seq[NimNode] = @[]
|
||||
var impls{.compileTime.}: seq[NimNode] = @[]
|
||||
|
||||
macro importImpl_forward(name, returns): stmt {.immediate.} =
|
||||
macro importImpl_forward(name, returns: untyped): untyped =
|
||||
result = newNimNode(nnkEmpty)
|
||||
var func_name = newNimNode(nnkAccQuoted)
|
||||
func_name.add newIdentNode("import")
|
||||
|
|
@ -19,7 +19,7 @@ macro importImpl_forward(name, returns): stmt {.immediate.} =
|
|||
res[3].add returns
|
||||
var p1 = newNimNode(nnkIdentDefs)
|
||||
p1.add newIdentNode("dat")
|
||||
p1.add newIdentNOde("PJsonNode")
|
||||
p1.add newIdentNOde("JsonNode")
|
||||
p1.add newNimNode(nnkEmpty)
|
||||
res[3].add p1
|
||||
var p2 = newNimNode(nnkIdentDefs)
|
||||
|
|
@ -38,7 +38,7 @@ macro importImpl_forward(name, returns): stmt {.immediate.} =
|
|||
decls.add res
|
||||
echo(repr(res))
|
||||
|
||||
macro importImpl(name, returns: expr, body: stmt): stmt {.immediate.} =
|
||||
macro importImpl(name, returns, body: untyped): typed =
|
||||
#var res = getAST(importImpl_forward(name, returns))
|
||||
discard getAST(importImpl_forward(name, returns))
|
||||
var res = copyNimTree(decls[decls.high])
|
||||
|
|
@ -46,7 +46,7 @@ macro importImpl(name, returns: expr, body: stmt): stmt {.immediate.} =
|
|||
echo repr(res)
|
||||
impls.add res
|
||||
|
||||
macro okayy:stmt =
|
||||
macro okayy: typed =
|
||||
result = newNimNode(nnkStmtList)
|
||||
for node in decls: result.add node
|
||||
for node in impls: result.add node
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
# bug #1944
|
||||
import macros
|
||||
|
||||
template t(e: expr): stmt =
|
||||
macro m(eNode: expr): stmt =
|
||||
template t(e: untyped): untyped =
|
||||
macro m(eNode: untyped): untyped =
|
||||
echo eNode.treeRepr
|
||||
m e
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import macros
|
||||
|
||||
macro foo(x: stmt): stmt =
|
||||
macro foo(x: untyped): untyped =
|
||||
echo treerepr(callsite())
|
||||
result = newNimNode(nnkStmtList)
|
||||
|
||||
proc zoo() {.foo.} = echo "hi"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ discard """
|
|||
import
|
||||
macros, strutils
|
||||
|
||||
macro outterMacro*(n: stmt): stmt {.immediate.} =
|
||||
macro outterMacro*(n, blck: untyped): untyped =
|
||||
let n = callsite()
|
||||
var j : string = "hi"
|
||||
proc innerProc(i: int): string =
|
||||
|
|
@ -27,5 +27,3 @@ var str: string
|
|||
outterMacro(str):
|
||||
"hellow"
|
||||
echo str
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import macros
|
||||
macro case_token(n: stmt): stmt {.immediate.} =
|
||||
macro case_token(n: untyped): untyped {.immediate.} =
|
||||
# creates a lexical analyzer from regular expressions
|
||||
# ... (implementation is an exercise for the reader :-)
|
||||
nil
|
||||
|
|
@ -18,7 +18,7 @@ case_token: inc i
|
|||
|
||||
#bug #488
|
||||
|
||||
macro foo: stmt =
|
||||
macro foo: typed =
|
||||
var exp = newCall("whatwhat", newIntLitNode(1))
|
||||
if compiles(getAst(exp)): return exp
|
||||
else: echo "Does not compute!"
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ int'''
|
|||
|
||||
import macros
|
||||
|
||||
macro checkType(ex: stmt; expected: expr): stmt =
|
||||
macro checkType(ex: typed; expected: string): untyped =
|
||||
var t = ex.getType()
|
||||
echo t
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ static:
|
|||
nodeB.strVal = "this is a different comment"
|
||||
doAssert nodeA != nodeB
|
||||
|
||||
macro test(a: typed, b: typed): expr =
|
||||
macro test(a: typed, b: typed): untyped =
|
||||
newLit(a == b)
|
||||
|
||||
doAssert test(1, 1) == true
|
||||
|
|
@ -29,10 +29,10 @@ var a, b: int
|
|||
doAssert test(a, a) == true
|
||||
doAssert test(a, b) == false
|
||||
|
||||
macro test2: expr =
|
||||
macro test2: untyped =
|
||||
newLit(bindSym"Obj" == bindSym"Obj")
|
||||
|
||||
macro test3: expr =
|
||||
macro test3: untyped =
|
||||
newLit(bindSym"Obj" == bindSym"Other")
|
||||
|
||||
doAssert test2() == true
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ discard """
|
|||
|
||||
import macros
|
||||
|
||||
macro quoteWords(n: varargs[expr]): expr {.immediate.} =
|
||||
macro quoteWords(n: varargs[untyped]): untyped =
|
||||
let n = callsite()
|
||||
result = newNimNode(nnkBracket, n)
|
||||
for i in 1..n.len-1:
|
||||
|
|
@ -21,6 +21,3 @@ for w in items(myWordList):
|
|||
s.add(w)
|
||||
|
||||
echo s #OUT thisanexample
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ discard """
|
|||
errormsg: "recursive dependency: 'dump'"
|
||||
"""
|
||||
|
||||
macro dump(n: stmt): stmt =
|
||||
macro dump(n: untyped): untyped =
|
||||
dump(n)
|
||||
if kind(n) == nnkNone:
|
||||
nil
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@ discard """
|
|||
line: 11
|
||||
"""
|
||||
# bug #2372
|
||||
macro foo(dummy: int): stmt =
|
||||
macro foo(dummy: int): untyped =
|
||||
discard
|
||||
|
||||
proc takeStr(s: string) = echo s
|
||||
|
||||
takeStr foo(12)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ false'''
|
|||
|
||||
import macros
|
||||
|
||||
macro same(a: typedesc, b: typedesc): expr =
|
||||
macro same(a: typedesc, b: typedesc): untyped =
|
||||
newLit(a.getType[1].sameType b.getType[1])
|
||||
|
||||
echo same(int, int)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ type
|
|||
|
||||
const data: Tconfig = (@["aa", "bb"], @[11, 22])
|
||||
|
||||
macro mymacro(data: static[TConfig]): stmt =
|
||||
macro mymacro(data: static[TConfig]): untyped =
|
||||
echo "letters"
|
||||
for s in items(data.letters):
|
||||
echo s
|
||||
|
|
@ -43,10 +43,10 @@ const
|
|||
a : Ta = @[(11, 22), (33, 44)]
|
||||
b : Tb = (@[55,66], @[77, 88])
|
||||
|
||||
macro mA(data: static[Ta]): stmt =
|
||||
macro mA(data: static[Ta]): untyped =
|
||||
echo "AST a \n", repr(data)
|
||||
|
||||
macro mB(data: static[Tb]): stmt =
|
||||
macro mB(data: static[Tb]): untyped =
|
||||
echo "AST b \n", repr(data)
|
||||
echo data.e[0]
|
||||
|
||||
|
|
@ -56,13 +56,13 @@ mB(b)
|
|||
type
|
||||
Foo[N: static[int], Z: static[string]] = object
|
||||
|
||||
macro staticIntMacro(f: static[int]): stmt = echo f
|
||||
macro staticIntMacro(f: static[int]): untyped = echo f
|
||||
staticIntMacro 10
|
||||
|
||||
var
|
||||
x: Foo[20, "Test"]
|
||||
|
||||
macro genericMacro[N; Z: static[string]](f: Foo[N, Z], ll = 3, zz = 12): stmt =
|
||||
macro genericMacro[N; Z: static[string]](f: Foo[N, Z], ll = 3, zz = 12): untyped =
|
||||
echo N, Z
|
||||
|
||||
genericMacro x
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ proc concat(strings: varargs[string]): string =
|
|||
result = newString(0)
|
||||
for s in items(strings): result.add(s)
|
||||
|
||||
template processInterpolations(e: expr) =
|
||||
template processInterpolations(e) =
|
||||
var s = e[1].strVal
|
||||
for f in interpolatedFragments(s):
|
||||
case f.kind
|
||||
|
|
@ -17,7 +17,7 @@ template processInterpolations(e: expr) =
|
|||
of ikDollar: addDollar()
|
||||
of ikVar, ikExpr: addExpr(newCall("$", parseExpr(f.value)))
|
||||
|
||||
macro formatStyleInterpolation(e: expr): expr =
|
||||
macro formatStyleInterpolation(e: untyped): untyped =
|
||||
let e = callsite()
|
||||
var
|
||||
formatString = ""
|
||||
|
|
@ -41,7 +41,7 @@ macro formatStyleInterpolation(e: expr): expr =
|
|||
result[1].strVal = formatString
|
||||
result[2] = arrayNode
|
||||
|
||||
macro concatStyleInterpolation(e: expr): expr =
|
||||
macro concatStyleInterpolation(e: untyped): untyped =
|
||||
let e = callsite()
|
||||
var args: seq[NimNode]
|
||||
newSeq(args, 0)
|
||||
|
|
@ -71,4 +71,3 @@ var
|
|||
s2 = formatStyleInterpolation"Hello ${bob}, ${sum(alice.len, bob.len, 2)}$$"
|
||||
|
||||
write(stdout, s1 & " | " & s2)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ discard """
|
|||
# feature request #1473
|
||||
import macros
|
||||
|
||||
macro test(text: string): expr =
|
||||
macro test(text: string): untyped =
|
||||
try:
|
||||
result = parseExpr(text.strVal)
|
||||
except ValueError:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ proc test(f: var NimNode) {.compileTime.} =
|
|||
f = newNimNode(nnkStmtList)
|
||||
f.add newCall(newIdentNode("echo"), newLit(10))
|
||||
|
||||
macro blah(prc: stmt): stmt =
|
||||
macro blah(prc: untyped): untyped =
|
||||
result = prc
|
||||
|
||||
test(result)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ proc (x: int) => typeDesc[proc[void, int]]'''
|
|||
|
||||
import macros
|
||||
|
||||
macro showType(t:stmt): stmt =
|
||||
macro showType(t:typed): untyped =
|
||||
let ty = t.getType
|
||||
echo t.repr, " => ", ty.repr
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# be used as a type
|
||||
import macros
|
||||
|
||||
macro testTypesym (t:stmt): expr =
|
||||
macro testTypesym (t:typed): untyped =
|
||||
var ty = t.getType
|
||||
if ty.typekind == ntyTypedesc:
|
||||
# skip typedesc get to the real type
|
||||
|
|
@ -31,7 +31,7 @@ static: assert(ref int is testTypesym(ref int))
|
|||
static: assert(void is testTypesym(void))
|
||||
|
||||
|
||||
macro tts2 (t:stmt, idx:int): expr =
|
||||
macro tts2 (t:typed, idx:int): untyped =
|
||||
var ty = t.getType
|
||||
if ty.typekind == ntyTypedesc:
|
||||
# skip typedesc get to the real type
|
||||
|
|
@ -46,4 +46,3 @@ static:
|
|||
assert(tts2(TestFN2, 1) is string)
|
||||
assert(tts2(TestFN2, 2) is int)
|
||||
assert(tts2(TestFN2, 3) is float)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue