Rename PNimrodNode to NimNode

This commit is contained in:
def 2015-03-17 17:50:32 +01:00
commit fd4e629905
30 changed files with 508 additions and 518 deletions

View file

@ -46,13 +46,13 @@ echotest()
# bug #1103
type
type
Td = tuple
a:string
b:int
proc get_data(d: Td) : string {.compileTime.} =
result = d.a # Works if a literal string is used here.
result = d.a # Works if a literal string is used here.
# Bugs if line A or B is active. Works with C
result &= "aa" # A
#result.add("aa") # B
@ -69,7 +69,7 @@ m(s)
# bug #933
proc nilcheck(): PNimrodNode {.compileTime.} =
proc nilcheck(): NimNode {.compileTime.} =
echo(result == nil) # true
echo(result.isNil) # true
echo(repr(result)) # nil

View file

@ -1,4 +1,4 @@
# Dump the contents of a PNimrodNode
# Dump the contents of a NimNode
import macros
@ -7,7 +7,7 @@ template plus(a, b: expr): expr {.dirty} =
macro call(e: expr): expr =
result = newCall("foo", newStrLitNode("bar"))
macro dumpAST(n: stmt): stmt {.immediate.} =
# dump AST as a side-effect and return the inner node
let n = callsite()
@ -24,10 +24,10 @@ macro dumpAST(n: stmt): stmt {.immediate.} =
echo e.lispRepr
result = n[1]
dumpAST:
proc add(x, y: int): int =
return x + y
proc sub(x, y: int): int = return x - y

View file

@ -1,13 +1,13 @@
# Dump the contents of a PNimrodNode
# Dump the contents of a NimNode
import macros
proc dumpit(n: PNimrodNode): string {.compileTime.} =
proc dumpit(n: NimNode): string {.compileTime.} =
if n == nil: return "nil"
result = $n.kind
add(result, "(")
case n.kind
of nnkEmpty: discard # same as nil node in this representation
of nnkEmpty: discard # same as nil node in this representation
of nnkNilLit: add(result, "nil")
of nnkCharLit..nnkInt64Lit: add(result, $n.intVal)
of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal)
@ -20,17 +20,17 @@ proc dumpit(n: PNimrodNode): string {.compileTime.} =
add(result, ", ")
add(result, dumpit(n[j]))
add(result, ")")
macro dumpAST(n: stmt): stmt {.immediate.} =
macro dumpAST(n: stmt): stmt {.immediate.} =
# dump AST as a side-effect and return the inner node
let n = callsite()
echo dumpit(n)
result = n[1]
dumpAST:
proc add(x, y: int): int =
return x + y
proc sub(x, y: int): int = return x - y

View file

@ -2,7 +2,7 @@ import rawsockets, asyncdispatch, macros
var p = newDispatcher()
var sock = newAsyncRawSocket()
proc convertReturns(node, retFutureSym: PNimrodNode): PNimrodNode {.compileTime.} =
proc convertReturns(node, retFutureSym: NimNode): NimNode {.compileTime.} =
case node.kind
of nnkReturnStmt:
result = newCall(newIdentNode("complete"), retFutureSym, node[0])
@ -19,19 +19,19 @@ macro async2(prc: stmt): stmt {.immediate.} =
# -> var retFuture = newFuture[T]()
var retFutureSym = newIdentNode("retFuture") #genSym(nskVar, "retFuture")
outerProcBody.add(
newVarStmt(retFutureSym,
newVarStmt(retFutureSym,
newCall(
newNimNode(nnkBracketExpr).add(
newIdentNode("newFuture"),
prc[3][0][1])))) # Get type from return type of this proc.
# -> iterator nameIter(): PFutureBase {.closure.} = <proc_body>
# -> iterator nameIter(): FutureBase {.closure.} = <proc_body>
# Changing this line to: newIdentNode($prc[0].ident & "Iter") # will make it work.
var iteratorNameSym = genSym(nskIterator, $prc[0].ident & "Iter")
#var iteratorNameSym = newIdentNode($prc[0].ident & "Iter")
var procBody = prc[6].convertReturns(retFutureSym)
var closureIterator = newProc(iteratorNameSym, [newIdentNode("PFutureBase")],
var closureIterator = newProc(iteratorNameSym, [newIdentNode("FutureBase")],
procBody, nnkIteratorDef)
closureIterator[4] = newNimNode(nnkPragma).add(newIdentNode("closure"))
outerProcBody.add(closureIterator)
@ -55,8 +55,8 @@ macro async2(prc: stmt): stmt {.immediate.} =
result[6] = outerProcBody
proc readStuff(): PFuture[string] {.async2.} =
var fut = connect(sock, "irc.freenode.org", TPort(6667))
proc readStuff(): Future[string] {.async2.} =
var fut = connect(sock, "irc.freenode.org", Port(6667))
yield fut
var fut2 = recv(sock, 50)
yield fut2

View file

@ -2,7 +2,7 @@
import parseutils, macros
proc parse_until_symbol(node: PNimrodNode, value: string, index: var int): bool {.compiletime.} =
proc parse_until_symbol(node: NimNode, value: string, index: var int): bool {.compiletime.} =
var splitValue: string
var read = value.parseUntil(splitValue, '$', index)
@ -15,7 +15,7 @@ proc parse_until_symbol(node: PNimrodNode, value: string, index: var int): bool
if splitValue.len > 0:
node.insert node.len, newCall("add", ident("result"), newStrLitNode(splitValue))
proc parse_template(node: PNimrodNode, value: string) {.compiletime.} =
proc parse_template(node: NimNode, value: string) {.compiletime.} =
var index = 0
while index < value.len and
parse_until_symbol(node, value, index): discard

View file

@ -3,17 +3,17 @@ import macros
from uri import `/`
macro test*(a: stmt): stmt {.immediate.} =
var nodes: tuple[a, b: int]
var nodes: tuple[a, b: int]
nodes.a = 4
nodes[1] = 45
type
TTypeEx = object
x, y: int
case b: bool
of false: nil
of true: z: float
var t: TTypeEx
t.b = true
t.z = 4.5

View file

@ -4,7 +4,7 @@ discard """
import macros
type
type
TA = tuple[a: int]
PA = ref TA
@ -19,7 +19,7 @@ test:
macro test2*(a: stmt): stmt {.immediate.} =
proc testproc(recurse: int) =
echo "Thats weird"
var o : PNimrodNode = nil
var o : NimNode = nil
echo " no its not!"
o = newNimNode(nnkNone)
if recurse > 0:

View file

@ -7,7 +7,7 @@ import
macro test_macro*(n: stmt): stmt {.immediate.} =
result = newNimNode(nnkStmtList)
var ass : PNimrodNode = newNimNode(nnkAsgn)
var ass : NimNode = newNimNode(nnkAsgn)
add(ass, newIdentNode("str"))
add(ass, newStrLitNode("after"))
add(result, ass)

View file

@ -1,7 +1,7 @@
import macros,json
var decls{.compileTime.}: seq[PNimrodNode] = @[]
var impls{.compileTime.}: seq[PNimrodNode] = @[]
var decls{.compileTime.}: seq[NimNode] = @[]
var impls{.compileTime.}: seq[NimNode] = @[]
macro importImpl_forward(name, returns): stmt {.immediate.} =
result = newNimNode(nnkEmpty)
@ -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: expr, body: stmt): stmt {.immediate.} =
#var res = getAST(importImpl_forward(name, returns))
discard getAST(importImpl_forward(name, returns))
var res = copyNimTree(decls[decls.high])
@ -56,4 +56,4 @@ importImpl(Item, int):
importImpl(Foo, int16):
echo 77
okayy
okayy

View file

@ -15,10 +15,10 @@ macro outterMacro*(n: stmt): stmt {.immediate.} =
expectKind(n, TNimrodNodeKind.nnkCall)
if n.len != 3 or n[1].kind != TNimrodNodeKind.nnkIdent:
error("Macro " & callNode.repr &
" requires the ident passed as parameter (eg: " & callNode.repr &
" requires the ident passed as parameter (eg: " & callNode.repr &
"(the_name_you_want)): statements.")
result = newNimNode(TNimrodNodeKind.nnkStmtList)
var ass : PNimrodNode = newNimNode(nnkAsgn)
var ass : NimNode = newNimNode(nnkAsgn)
ass.add(newIdentNode(n[1].ident))
ass.add(newStrLitNode(innerProc(4)))
result.add(ass)

View file

@ -3,7 +3,7 @@ discard """
"""
import macros
proc makeMacro: PNimrodNode =
proc makeMacro: NimNode =
result = nil
var p = makeMacro()

View file

@ -19,7 +19,7 @@ template processInterpolations(e: expr) =
macro formatStyleInterpolation(e: expr): expr =
let e = callsite()
var
var
formatString = ""
arrayNode = newNimNode(nnkBracket)
idx = 1
@ -27,14 +27,14 @@ macro formatStyleInterpolation(e: expr): expr =
proc addString(s: string) =
formatString.add(s)
proc addExpr(e: PNimrodNode) =
proc addExpr(e: NimNode) =
arrayNode.add(e)
formatString.add("$" & $(idx))
inc idx
proc addDollar() =
formatString.add("$$")
processInterpolations(e)
result = parseExpr("\"x\" % [y]")
@ -43,11 +43,11 @@ macro formatStyleInterpolation(e: expr): expr =
macro concatStyleInterpolation(e: expr): expr =
let e = callsite()
var args: seq[PNimrodNode]
var args: seq[NimNode]
newSeq(args, 0)
proc addString(s: string) = args.add(newStrLitNode(s))
proc addExpr(e: PNimrodNode) = args.add(e)
proc addExpr(e: NimNode) = args.add(e)
proc addDollar() = args.add(newStrLitNode"$")
processInterpolations(e)
@ -59,7 +59,7 @@ macro concatStyleInterpolation(e: expr): expr =
proc sum(a, b, c: int): int =
return (a + b + c)
var
var
alice = "Alice"
bob = "Bob"
a = 10

View file

@ -6,7 +6,7 @@ discard """
import macros
proc test(f: var PNimrodNode) {.compileTime.} =
proc test(f: var NimNode) {.compileTime.} =
f = newNimNode(nnkStmtList)
f.add newCall(newIdentNode("echo"), newLit(10))