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

@ -120,12 +120,10 @@ const
nnkCallKinds* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand, nnkCallKinds* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand,
nnkCallStrLit} nnkCallStrLit}
{.push warning[deprecated]: off.} proc `[]`*(n: NimNode, i: int): NimNode {.magic: "NChild", noSideEffect.}
proc `[]`*(n: PNimrodNode, i: int): PNimrodNode {.magic: "NChild", noSideEffect.}
## get `n`'s `i`'th child. ## get `n`'s `i`'th child.
proc `[]=`*(n: PNimrodNode, i: int, child: PNimrodNode) {.magic: "NSetChild", proc `[]=`*(n: NimNode, i: int, child: NimNode) {.magic: "NSetChild",
noSideEffect.} noSideEffect.}
## set `n`'s `i`'th child to `child`. ## set `n`'s `i`'th child to `child`.
@ -141,34 +139,34 @@ proc `$`*(s: NimSym): string {.magic: "IdentToStr", noSideEffect.}
proc `==`*(a, b: NimIdent): bool {.magic: "EqIdent", noSideEffect.} proc `==`*(a, b: NimIdent): bool {.magic: "EqIdent", noSideEffect.}
## compares two Nim identifiers ## compares two Nim identifiers
proc `==`*(a, b: PNimrodNode): bool {.magic: "EqNimrodNode", noSideEffect.} proc `==`*(a, b: NimNode): bool {.magic: "EqNimrodNode", noSideEffect.}
## compares two Nim nodes ## compares two Nim nodes
proc len*(n: PNimrodNode): int {.magic: "NLen", noSideEffect.} proc len*(n: NimNode): int {.magic: "NLen", noSideEffect.}
## returns the number of children of `n`. ## returns the number of children of `n`.
proc add*(father, child: PNimrodNode): PNimrodNode {.magic: "NAdd", discardable, proc add*(father, child: NimNode): NimNode {.magic: "NAdd", discardable,
noSideEffect, locks: 0.} noSideEffect, locks: 0.}
## Adds the `child` to the `father` node. Returns the ## Adds the `child` to the `father` node. Returns the
## father node so that calls can be nested. ## father node so that calls can be nested.
proc add*(father: PNimrodNode, children: varargs[PNimrodNode]): PNimrodNode {. proc add*(father: NimNode, children: varargs[NimNode]): NimNode {.
magic: "NAddMultiple", discardable, noSideEffect, locks: 0.} magic: "NAddMultiple", discardable, noSideEffect, locks: 0.}
## Adds each child of `children` to the `father` node. ## Adds each child of `children` to the `father` node.
## Returns the `father` node so that calls can be nested. ## Returns the `father` node so that calls can be nested.
proc del*(father: PNimrodNode, idx = 0, n = 1) {.magic: "NDel", noSideEffect.} proc del*(father: NimNode, idx = 0, n = 1) {.magic: "NDel", noSideEffect.}
## deletes `n` children of `father` starting at index `idx`. ## deletes `n` children of `father` starting at index `idx`.
proc kind*(n: PNimrodNode): TNimrodNodeKind {.magic: "NKind", noSideEffect.} proc kind*(n: NimNode): NimNodeKind {.magic: "NKind", noSideEffect.}
## returns the `kind` of the node `n`. ## returns the `kind` of the node `n`.
proc intVal*(n: PNimrodNode): BiggestInt {.magic: "NIntVal", noSideEffect.} proc intVal*(n: NimNode): BiggestInt {.magic: "NIntVal", noSideEffect.}
proc floatVal*(n: PNimrodNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.} proc floatVal*(n: NimNode): BiggestFloat {.magic: "NFloatVal", noSideEffect.}
proc symbol*(n: PNimrodNode): NimSym {.magic: "NSymbol", noSideEffect.} proc symbol*(n: NimNode): NimSym {.magic: "NSymbol", noSideEffect.}
proc ident*(n: PNimrodNode): NimIdent {.magic: "NIdent", noSideEffect.} proc ident*(n: NimNode): NimIdent {.magic: "NIdent", noSideEffect.}
proc getType*(n: PNimrodNode): PNimrodNode {.magic: "NGetType", noSideEffect.} proc getType*(n: NimNode): NimNode {.magic: "NGetType", noSideEffect.}
## with 'getType' you can access the node's `type`:idx:. A Nim type is ## with 'getType' you can access the node's `type`:idx:. A Nim type is
## mapped to a Nim AST too, so it's slightly confusing but it means the same ## mapped to a Nim AST too, so it's slightly confusing but it means the same
## API can be used to traverse types. Recursive types are flattened for you ## API can be used to traverse types. Recursive types are flattened for you
@ -176,30 +174,30 @@ proc getType*(n: PNimrodNode): PNimrodNode {.magic: "NGetType", noSideEffect.}
## resolve recursive types, you have to call 'getType' again. To see what ## resolve recursive types, you have to call 'getType' again. To see what
## kind of type it is, call `typeKind` on getType's result. ## kind of type it is, call `typeKind` on getType's result.
proc typeKind*(n: PNimrodNode): NimTypeKind {.magic: "NGetType", noSideEffect.} proc typeKind*(n: NimNode): NimTypeKind {.magic: "NGetType", noSideEffect.}
## Returns the type kind of the node 'n' that should represent a type, that ## Returns the type kind of the node 'n' that should represent a type, that
## means the node should have been obtained via `getType`. ## means the node should have been obtained via `getType`.
proc strVal*(n: PNimrodNode): string {.magic: "NStrVal", noSideEffect.} proc strVal*(n: NimNode): string {.magic: "NStrVal", noSideEffect.}
proc `intVal=`*(n: PNimrodNode, val: BiggestInt) {.magic: "NSetIntVal", noSideEffect.} proc `intVal=`*(n: NimNode, val: BiggestInt) {.magic: "NSetIntVal", noSideEffect.}
proc `floatVal=`*(n: PNimrodNode, val: BiggestFloat) {.magic: "NSetFloatVal", noSideEffect.} proc `floatVal=`*(n: NimNode, val: BiggestFloat) {.magic: "NSetFloatVal", noSideEffect.}
proc `symbol=`*(n: PNimrodNode, val: NimSym) {.magic: "NSetSymbol", noSideEffect.} proc `symbol=`*(n: NimNode, val: NimSym) {.magic: "NSetSymbol", noSideEffect.}
proc `ident=`*(n: PNimrodNode, val: NimIdent) {.magic: "NSetIdent", noSideEffect.} proc `ident=`*(n: NimNode, val: NimIdent) {.magic: "NSetIdent", noSideEffect.}
#proc `typ=`*(n: PNimrodNode, typ: typedesc) {.magic: "NSetType".} #proc `typ=`*(n: NimNode, typ: typedesc) {.magic: "NSetType".}
# this is not sound! Unfortunately forbidding 'typ=' is not enough, as you # this is not sound! Unfortunately forbidding 'typ=' is not enough, as you
# can easily do: # can easily do:
# let bracket = semCheck([1, 2]) # let bracket = semCheck([1, 2])
# let fake = semCheck(2.0) # let fake = semCheck(2.0)
# bracket[0] = fake # constructs a mixed array with ints and floats! # bracket[0] = fake # constructs a mixed array with ints and floats!
proc `strVal=`*(n: PNimrodNode, val: string) {.magic: "NSetStrVal", noSideEffect.} proc `strVal=`*(n: NimNode, val: string) {.magic: "NSetStrVal", noSideEffect.}
proc newNimNode*(kind: TNimrodNodeKind, proc newNimNode*(kind: NimNodeKind,
n: PNimrodNode=nil): PNimrodNode {.magic: "NNewNimNode", noSideEffect.} n: NimNode=nil): NimNode {.magic: "NNewNimNode", noSideEffect.}
proc copyNimNode*(n: PNimrodNode): PNimrodNode {.magic: "NCopyNimNode", noSideEffect.} proc copyNimNode*(n: NimNode): NimNode {.magic: "NCopyNimNode", noSideEffect.}
proc copyNimTree*(n: PNimrodNode): PNimrodNode {.magic: "NCopyNimTree", noSideEffect.} proc copyNimTree*(n: NimNode): NimNode {.magic: "NCopyNimTree", noSideEffect.}
proc error*(msg: string) {.magic: "NError", benign.} proc error*(msg: string) {.magic: "NError", benign.}
## writes an error message at compile time ## writes an error message at compile time
@ -210,27 +208,27 @@ proc warning*(msg: string) {.magic: "NWarning", benign.}
proc hint*(msg: string) {.magic: "NHint", benign.} proc hint*(msg: string) {.magic: "NHint", benign.}
## writes a hint message at compile time ## writes a hint message at compile time
proc newStrLitNode*(s: string): PNimrodNode {.compileTime, noSideEffect.} = proc newStrLitNode*(s: string): NimNode {.compileTime, noSideEffect.} =
## creates a string literal node from `s` ## creates a string literal node from `s`
result = newNimNode(nnkStrLit) result = newNimNode(nnkStrLit)
result.strVal = s result.strVal = s
proc newIntLitNode*(i: BiggestInt): PNimrodNode {.compileTime.} = proc newIntLitNode*(i: BiggestInt): NimNode {.compileTime.} =
## creates a int literal node from `i` ## creates a int literal node from `i`
result = newNimNode(nnkIntLit) result = newNimNode(nnkIntLit)
result.intVal = i result.intVal = i
proc newFloatLitNode*(f: BiggestFloat): PNimrodNode {.compileTime.} = proc newFloatLitNode*(f: BiggestFloat): NimNode {.compileTime.} =
## creates a float literal node from `f` ## creates a float literal node from `f`
result = newNimNode(nnkFloatLit) result = newNimNode(nnkFloatLit)
result.floatVal = f result.floatVal = f
proc newIdentNode*(i: NimIdent): PNimrodNode {.compileTime.} = proc newIdentNode*(i: NimIdent): NimNode {.compileTime.} =
## creates an identifier node from `i` ## creates an identifier node from `i`
result = newNimNode(nnkIdent) result = newNimNode(nnkIdent)
result.ident = i result.ident = i
proc newIdentNode*(i: string): PNimrodNode {.compileTime.} = proc newIdentNode*(i: string): NimNode {.compileTime.} =
## creates an identifier node from `i` ## creates an identifier node from `i`
result = newNimNode(nnkIdent) result = newNimNode(nnkIdent)
result.ident = !i result.ident = !i
@ -247,7 +245,7 @@ type
{.deprecated: [TBindSymRule: BindSymRule].} {.deprecated: [TBindSymRule: BindSymRule].}
proc bindSym*(ident: string, rule: BindSymRule = brClosed): PNimrodNode {. proc bindSym*(ident: string, rule: BindSymRule = brClosed): NimNode {.
magic: "NBindSym", noSideEffect.} magic: "NBindSym", noSideEffect.}
## creates a node that binds `ident` to a symbol node. The bound symbol ## creates a node that binds `ident` to a symbol node. The bound symbol
## may be an overloaded symbol. ## may be an overloaded symbol.
@ -258,48 +256,48 @@ proc bindSym*(ident: string, rule: BindSymRule = brClosed): PNimrodNode {.
## If ``rule == brForceOpen`` always an ``nkOpenSymChoice`` tree is ## If ``rule == brForceOpen`` always an ``nkOpenSymChoice`` tree is
## returned even if the symbol is not ambiguous. ## returned even if the symbol is not ambiguous.
proc genSym*(kind: NimSymKind = nskLet; ident = ""): PNimrodNode {. proc genSym*(kind: NimSymKind = nskLet; ident = ""): NimNode {.
magic: "NGenSym", noSideEffect.} magic: "NGenSym", noSideEffect.}
## generates a fresh symbol that is guaranteed to be unique. The symbol ## generates a fresh symbol that is guaranteed to be unique. The symbol
## needs to occur in a declaration context. ## needs to occur in a declaration context.
proc callsite*(): PNimrodNode {.magic: "NCallSite", benign.} proc callsite*(): NimNode {.magic: "NCallSite", benign.}
## returns the AST of the invocation expression that invoked this macro. ## returns the AST of the invocation expression that invoked this macro.
proc toStrLit*(n: PNimrodNode): PNimrodNode {.compileTime.} = proc toStrLit*(n: NimNode): NimNode {.compileTime.} =
## converts the AST `n` to the concrete Nim code and wraps that ## converts the AST `n` to the concrete Nim code and wraps that
## in a string literal node ## in a string literal node
return newStrLitNode(repr(n)) return newStrLitNode(repr(n))
proc lineinfo*(n: PNimrodNode): string {.magic: "NLineInfo", noSideEffect.} proc lineinfo*(n: NimNode): string {.magic: "NLineInfo", noSideEffect.}
## returns the position the node appears in the original source file ## returns the position the node appears in the original source file
## in the form filename(line, col) ## in the form filename(line, col)
proc internalParseExpr(s: string): PNimrodNode {. proc internalParseExpr(s: string): NimNode {.
magic: "ParseExprToAst", noSideEffect.} magic: "ParseExprToAst", noSideEffect.}
proc internalParseStmt(s: string): PNimrodNode {. proc internalParseStmt(s: string): NimNode {.
magic: "ParseStmtToAst", noSideEffect.} magic: "ParseStmtToAst", noSideEffect.}
proc internalErrorFlag*(): string {.magic: "NError", noSideEffect.} proc internalErrorFlag*(): string {.magic: "NError", noSideEffect.}
## Some builtins set an error flag. This is then turned into a proper ## Some builtins set an error flag. This is then turned into a proper
## exception. **Note**: Ordinary application code should not call this. ## exception. **Note**: Ordinary application code should not call this.
proc parseExpr*(s: string): PNimrodNode {.noSideEffect, compileTime.} = proc parseExpr*(s: string): NimNode {.noSideEffect, compileTime.} =
## Compiles the passed string to its AST representation. ## Compiles the passed string to its AST representation.
## Expects a single expression. Raises ``ValueError`` for parsing errors. ## Expects a single expression. Raises ``ValueError`` for parsing errors.
result = internalParseExpr(s) result = internalParseExpr(s)
let x = internalErrorFlag() let x = internalErrorFlag()
if x.len > 0: raise newException(ValueError, x) if x.len > 0: raise newException(ValueError, x)
proc parseStmt*(s: string): PNimrodNode {.noSideEffect, compileTime.} = proc parseStmt*(s: string): NimNode {.noSideEffect, compileTime.} =
## Compiles the passed string to its AST representation. ## Compiles the passed string to its AST representation.
## Expects one or more statements. Raises ``ValueError`` for parsing errors. ## Expects one or more statements. Raises ``ValueError`` for parsing errors.
result = internalParseStmt(s) result = internalParseStmt(s)
let x = internalErrorFlag() let x = internalErrorFlag()
if x.len > 0: raise newException(ValueError, x) if x.len > 0: raise newException(ValueError, x)
proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst", noSideEffect.} proc getAst*(macroOrTemplate: expr): NimNode {.magic: "ExpandToAst", noSideEffect.}
## Obtains the AST nodes returned from a macro or template invocation. ## Obtains the AST nodes returned from a macro or template invocation.
## Example: ## Example:
## ##
@ -308,10 +306,10 @@ proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst", noSideE
## macro FooMacro() = ## macro FooMacro() =
## var ast = getAst(BarTemplate()) ## var ast = getAst(BarTemplate())
proc quote*(bl: stmt, op = "``"): PNimrodNode {.magic: "QuoteAst", noSideEffect.} proc quote*(bl: stmt, op = "``"): NimNode {.magic: "QuoteAst", noSideEffect.}
## Quasi-quoting operator. ## Quasi-quoting operator.
## Accepts an expression or a block and returns the AST that represents it. ## Accepts an expression or a block and returns the AST that represents it.
## Within the quoted AST, you are able to interpolate PNimrodNode expressions ## Within the quoted AST, you are able to interpolate NimNode expressions
## from the surrounding scope. If no operator is given, quoting is done using ## from the surrounding scope. If no operator is given, quoting is done using
## backticks. Otherwise, the given operator must be used as a prefix operator ## backticks. Otherwise, the given operator must be used as a prefix operator
## for any interpolated expression. The original meaning of the interpolation ## for any interpolated expression. The original meaning of the interpolation
@ -339,26 +337,26 @@ proc quote*(bl: stmt, op = "``"): PNimrodNode {.magic: "QuoteAst", noSideEffect.
## if not `ex`: ## if not `ex`:
## echo `info` & ": Check failed: " & `expString` ## echo `info` & ": Check failed: " & `expString`
proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} = proc expectKind*(n: NimNode, k: NimNodeKind) {.compileTime.} =
## checks that `n` is of kind `k`. If this is not the case, ## checks that `n` is of kind `k`. If this is not the case,
## compilation aborts with an error message. This is useful for writing ## compilation aborts with an error message. This is useful for writing
## macros that check the AST that is passed to them. ## macros that check the AST that is passed to them.
if n.kind != k: error("Expected a node of kind " & $k & ", got " & $n.kind) if n.kind != k: error("Expected a node of kind " & $k & ", got " & $n.kind)
proc expectMinLen*(n: PNimrodNode, min: int) {.compileTime.} = proc expectMinLen*(n: NimNode, min: int) {.compileTime.} =
## checks that `n` has at least `min` children. If this is not the case, ## checks that `n` has at least `min` children. If this is not the case,
## compilation aborts with an error message. This is useful for writing ## compilation aborts with an error message. This is useful for writing
## macros that check its number of arguments. ## macros that check its number of arguments.
if n.len < min: error("macro expects a node with " & $min & " children") if n.len < min: error("macro expects a node with " & $min & " children")
proc expectLen*(n: PNimrodNode, len: int) {.compileTime.} = proc expectLen*(n: NimNode, len: int) {.compileTime.} =
## checks that `n` has exactly `len` children. If this is not the case, ## checks that `n` has exactly `len` children. If this is not the case,
## compilation aborts with an error message. This is useful for writing ## compilation aborts with an error message. This is useful for writing
## macros that check its number of arguments. ## macros that check its number of arguments.
if n.len != len: error("macro expects a node with " & $len & " children") if n.len != len: error("macro expects a node with " & $len & " children")
proc newCall*(theProc: PNimrodNode, proc newCall*(theProc: NimNode,
args: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = args: varargs[NimNode]): NimNode {.compileTime.} =
## produces a new call node. `theProc` is the proc that is called with ## produces a new call node. `theProc` is the proc that is called with
## the arguments ``args[0..]``. ## the arguments ``args[0..]``.
result = newNimNode(nnkCall) result = newNimNode(nnkCall)
@ -366,7 +364,7 @@ proc newCall*(theProc: PNimrodNode,
result.add(args) result.add(args)
proc newCall*(theProc: NimIdent, proc newCall*(theProc: NimIdent,
args: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = args: varargs[NimNode]): NimNode {.compileTime.} =
## produces a new call node. `theProc` is the proc that is called with ## produces a new call node. `theProc` is the proc that is called with
## the arguments ``args[0..]``. ## the arguments ``args[0..]``.
result = newNimNode(nnkCall) result = newNimNode(nnkCall)
@ -374,35 +372,35 @@ proc newCall*(theProc: NimIdent,
result.add(args) result.add(args)
proc newCall*(theProc: string, proc newCall*(theProc: string,
args: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = args: varargs[NimNode]): NimNode {.compileTime.} =
## produces a new call node. `theProc` is the proc that is called with ## produces a new call node. `theProc` is the proc that is called with
## the arguments ``args[0..]``. ## the arguments ``args[0..]``.
result = newNimNode(nnkCall) result = newNimNode(nnkCall)
result.add(newIdentNode(theProc)) result.add(newIdentNode(theProc))
result.add(args) result.add(args)
proc newLit*(c: char): PNimrodNode {.compileTime.} = proc newLit*(c: char): NimNode {.compileTime.} =
## produces a new character literal node. ## produces a new character literal node.
result = newNimNode(nnkCharLit) result = newNimNode(nnkCharLit)
result.intVal = ord(c) result.intVal = ord(c)
proc newLit*(i: BiggestInt): PNimrodNode {.compileTime.} = proc newLit*(i: BiggestInt): NimNode {.compileTime.} =
## produces a new integer literal node. ## produces a new integer literal node.
result = newNimNode(nnkIntLit) result = newNimNode(nnkIntLit)
result.intVal = i result.intVal = i
proc newLit*(f: BiggestFloat): PNimrodNode {.compileTime.} = proc newLit*(f: BiggestFloat): NimNode {.compileTime.} =
## produces a new float literal node. ## produces a new float literal node.
result = newNimNode(nnkFloatLit) result = newNimNode(nnkFloatLit)
result.floatVal = f result.floatVal = f
proc newLit*(s: string): PNimrodNode {.compileTime.} = proc newLit*(s: string): NimNode {.compileTime.} =
## produces a new string literal node. ## produces a new string literal node.
result = newNimNode(nnkStrLit) result = newNimNode(nnkStrLit)
result.strVal = s result.strVal = s
proc nestList*(theProc: NimIdent, proc nestList*(theProc: NimIdent,
x: PNimrodNode): PNimrodNode {.compileTime.} = x: NimNode): NimNode {.compileTime.} =
## nests the list `x` into a tree of call expressions: ## nests the list `x` into a tree of call expressions:
## ``[a, b, c]`` is transformed into ``theProc(a, theProc(c, d))``. ## ``[a, b, c]`` is transformed into ``theProc(a, theProc(c, d))``.
var L = x.len var L = x.len
@ -413,11 +411,11 @@ proc nestList*(theProc: NimIdent,
# This could easily user code and so should be fixed in evals.nim somehow. # This could easily user code and so should be fixed in evals.nim somehow.
result = newCall(theProc, x[i], copyNimTree(result)) result = newCall(theProc, x[i], copyNimTree(result))
proc treeRepr*(n: PNimrodNode): string {.compileTime, benign.} = proc treeRepr*(n: NimNode): string {.compileTime, benign.} =
## Convert the AST `n` to a human-readable tree-like string. ## Convert the AST `n` to a human-readable tree-like string.
## ##
## See also `repr` and `lispRepr`. ## See also `repr` and `lispRepr`.
proc traverse(res: var string, level: int, n: PNimrodNode) {.benign.} = proc traverse(res: var string, level: int, n: NimNode) {.benign.} =
for i in 0..level-1: res.add " " for i in 0..level-1: res.add " "
res.add(($n.kind).substr(3)) res.add(($n.kind).substr(3))
@ -438,7 +436,7 @@ proc treeRepr*(n: PNimrodNode): string {.compileTime, benign.} =
result = "" result = ""
traverse(result, 0, n) traverse(result, 0, n)
proc lispRepr*(n: PNimrodNode): string {.compileTime, benign.} = proc lispRepr*(n: NimNode): string {.compileTime, benign.} =
## Convert the AST `n` to a human-readable lisp-like string, ## Convert the AST `n` to a human-readable lisp-like string,
## ##
## See also `repr` and `treeRepr`. ## See also `repr` and `treeRepr`.
@ -485,56 +483,56 @@ macro dumpLispImm*(s: stmt): stmt {.immediate, deprecated.} = echo s.lispRepr
## The ``immediate`` version of `dumpLisp`. ## The ``immediate`` version of `dumpLisp`.
proc newEmptyNode*(): PNimrodNode {.compileTime, noSideEffect.} = proc newEmptyNode*(): NimNode {.compileTime, noSideEffect.} =
## Create a new empty node ## Create a new empty node
result = newNimNode(nnkEmpty) result = newNimNode(nnkEmpty)
proc newStmtList*(stmts: varargs[PNimrodNode]): PNimrodNode {.compileTime.}= proc newStmtList*(stmts: varargs[NimNode]): NimNode {.compileTime.}=
## Create a new statement list ## Create a new statement list
result = newNimNode(nnkStmtList).add(stmts) result = newNimNode(nnkStmtList).add(stmts)
proc newPar*(exprs: varargs[PNimrodNode]): PNimrodNode {.compileTime.}= proc newPar*(exprs: varargs[NimNode]): NimNode {.compileTime.}=
## Create a new parentheses-enclosed expression ## Create a new parentheses-enclosed expression
newNimNode(nnkPar).add(exprs) newNimNode(nnkPar).add(exprs)
proc newBlockStmt*(label, body: PNimrodNode): PNimrodNode {.compileTime.} = proc newBlockStmt*(label, body: NimNode): NimNode {.compileTime.} =
## Create a new block statement with label ## Create a new block statement with label
return newNimNode(nnkBlockStmt).add(label, body) return newNimNode(nnkBlockStmt).add(label, body)
proc newBlockStmt*(body: PNimrodNode): PNimrodNode {.compiletime.} = proc newBlockStmt*(body: NimNode): NimNode {.compiletime.} =
## Create a new block: stmt ## Create a new block: stmt
return newNimNode(nnkBlockStmt).add(newEmptyNode(), body) return newNimNode(nnkBlockStmt).add(newEmptyNode(), body)
proc newVarStmt*(name, value: PNimrodNode): PNimrodNode {.compiletime.} = proc newVarStmt*(name, value: NimNode): NimNode {.compiletime.} =
## Create a new var stmt ## Create a new var stmt
return newNimNode(nnkVarSection).add( return newNimNode(nnkVarSection).add(
newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value)) newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value))
proc newLetStmt*(name, value: PNimrodNode): PNimrodNode {.compiletime.} = proc newLetStmt*(name, value: NimNode): NimNode {.compiletime.} =
## Create a new let stmt ## Create a new let stmt
return newNimNode(nnkLetSection).add( return newNimNode(nnkLetSection).add(
newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value)) newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value))
proc newConstStmt*(name, value: PNimrodNode): PNimrodNode {.compileTime.} = proc newConstStmt*(name, value: NimNode): NimNode {.compileTime.} =
## Create a new const stmt ## Create a new const stmt
newNimNode(nnkConstSection).add( newNimNode(nnkConstSection).add(
newNimNode(nnkConstDef).add(name, newNimNode(nnkEmpty), value)) newNimNode(nnkConstDef).add(name, newNimNode(nnkEmpty), value))
proc newAssignment*(lhs, rhs: PNimrodNode): PNimrodNode {.compileTime.} = proc newAssignment*(lhs, rhs: NimNode): NimNode {.compileTime.} =
return newNimNode(nnkAsgn).add(lhs, rhs) return newNimNode(nnkAsgn).add(lhs, rhs)
proc newDotExpr*(a, b: PNimrodNode): PNimrodNode {.compileTime.} = proc newDotExpr*(a, b: NimNode): NimNode {.compileTime.} =
## Create new dot expression ## Create new dot expression
## a.dot(b) -> `a.b` ## a.dot(b) -> `a.b`
return newNimNode(nnkDotExpr).add(a, b) return newNimNode(nnkDotExpr).add(a, b)
proc newColonExpr*(a, b: PNimrodNode): PNimrodNode {.compileTime.} = proc newColonExpr*(a, b: NimNode): NimNode {.compileTime.} =
## Create new colon expression ## Create new colon expression
## newColonExpr(a, b) -> `a: b` ## newColonExpr(a, b) -> `a: b`
newNimNode(nnkExprColonExpr).add(a, b) newNimNode(nnkExprColonExpr).add(a, b)
proc newIdentDefs*(name, kind: PNimrodNode; proc newIdentDefs*(name, kind: NimNode;
default = newEmptyNode()): PNimrodNode {.compileTime.} = default = newEmptyNode()): NimNode {.compileTime.} =
## Creates a new ``nnkIdentDefs`` node of a specific kind and value. ## Creates a new ``nnkIdentDefs`` node of a specific kind and value.
## ##
## ``nnkIdentDefs`` need to have at least three children, but they can have ## ``nnkIdentDefs`` need to have at least three children, but they can have
@ -565,13 +563,13 @@ proc newIdentDefs*(name, kind: PNimrodNode;
## newStrLitNode("Hello")) ## newStrLitNode("Hello"))
newNimNode(nnkIdentDefs).add(name, kind, default) newNimNode(nnkIdentDefs).add(name, kind, default)
proc newNilLit*(): PNimrodNode {.compileTime.} = proc newNilLit*(): NimNode {.compileTime.} =
## New nil literal shortcut ## New nil literal shortcut
result = newNimNode(nnkNilLit) result = newNimNode(nnkNilLit)
proc high*(node: PNimrodNode): int {.compileTime.} = len(node) - 1 proc high*(node: NimNode): int {.compileTime.} = len(node) - 1
## Return the highest index available for a node ## Return the highest index available for a node
proc last*(node: PNimrodNode): PNimrodNode {.compileTime.} = node[node.high] proc last*(node: NimNode): NimNode {.compileTime.} = node[node.high]
## Return the last item in nodes children. Same as `node[node.high()]` ## Return the last item in nodes children. Same as `node[node.high()]`
@ -581,11 +579,11 @@ const
CallNodes* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand, CallNodes* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand,
nnkCallStrLit, nnkHiddenCallConv} nnkCallStrLit, nnkHiddenCallConv}
proc expectKind*(n: PNimrodNode; k: set[TNimrodNodeKind]) {.compileTime.} = proc expectKind*(n: NimNode; k: set[NimNodeKind]) {.compileTime.} =
assert n.kind in k, "Expected one of " & $k & ", got " & $n.kind assert n.kind in k, "Expected one of " & $k & ", got " & $n.kind
proc newProc*(name = newEmptyNode(); params: openArray[PNimrodNode] = [newEmptyNode()]; proc newProc*(name = newEmptyNode(); params: openArray[NimNode] = [newEmptyNode()];
body: PNimrodNode = newStmtList(), procType = nnkProcDef): PNimrodNode {.compileTime.} = body: NimNode = newStmtList(), procType = nnkProcDef): NimNode {.compileTime.} =
## shortcut for creating a new proc ## shortcut for creating a new proc
## ##
## The ``params`` array must start with the return type of the proc, ## The ``params`` array must start with the return type of the proc,
@ -600,8 +598,8 @@ proc newProc*(name = newEmptyNode(); params: openArray[PNimrodNode] = [newEmptyN
newEmptyNode(), newEmptyNode(),
body) body)
proc newIfStmt*(branches: varargs[tuple[cond, body: PNimrodNode]]): proc newIfStmt*(branches: varargs[tuple[cond, body: NimNode]]):
PNimrodNode {.compiletime.} = NimNode {.compiletime.} =
## Constructor for ``if`` statements. ## Constructor for ``if`` statements.
## ##
## .. code-block:: nim ## .. code-block:: nim
@ -616,35 +614,35 @@ proc newIfStmt*(branches: varargs[tuple[cond, body: PNimrodNode]]):
result.add(newNimNode(nnkElifBranch).add(i.cond, i.body)) result.add(newNimNode(nnkElifBranch).add(i.cond, i.body))
proc copyChildrenTo*(src, dest: PNimrodNode) {.compileTime.}= proc copyChildrenTo*(src, dest: NimNode) {.compileTime.}=
## Copy all children from `src` to `dest` ## Copy all children from `src` to `dest`
for i in 0 .. < src.len: for i in 0 .. < src.len:
dest.add src[i].copyNimTree dest.add src[i].copyNimTree
template expectRoutine(node: PNimrodNode): stmt = template expectRoutine(node: NimNode): stmt =
expectKind(node, RoutineNodes) expectKind(node, RoutineNodes)
proc name*(someProc: PNimrodNode): PNimrodNode {.compileTime.} = proc name*(someProc: NimNode): NimNode {.compileTime.} =
someProc.expectRoutine someProc.expectRoutine
result = someProc[0] result = someProc[0]
proc `name=`*(someProc: PNimrodNode; val: PNimrodNode) {.compileTime.} = proc `name=`*(someProc: NimNode; val: NimNode) {.compileTime.} =
someProc.expectRoutine someProc.expectRoutine
someProc[0] = val someProc[0] = val
proc params*(someProc: PNimrodNode): PNimrodNode {.compileTime.} = proc params*(someProc: NimNode): NimNode {.compileTime.} =
someProc.expectRoutine someProc.expectRoutine
result = someProc[3] result = someProc[3]
proc `params=`* (someProc: PNimrodNode; params: PNimrodNode) {.compileTime.}= proc `params=`* (someProc: NimNode; params: NimNode) {.compileTime.}=
someProc.expectRoutine someProc.expectRoutine
assert params.kind == nnkFormalParams assert params.kind == nnkFormalParams
someProc[3] = params someProc[3] = params
proc pragma*(someProc: PNimrodNode): PNimrodNode {.compileTime.} = proc pragma*(someProc: NimNode): NimNode {.compileTime.} =
## Get the pragma of a proc type ## Get the pragma of a proc type
## These will be expanded ## These will be expanded
someProc.expectRoutine someProc.expectRoutine
result = someProc[4] result = someProc[4]
proc `pragma=`*(someProc: PNimrodNode; val: PNimrodNode){.compileTime.}= proc `pragma=`*(someProc: NimNode; val: NimNode){.compileTime.}=
## Set the pragma of a proc type ## Set the pragma of a proc type
someProc.expectRoutine someProc.expectRoutine
assert val.kind in {nnkEmpty, nnkPragma} assert val.kind in {nnkEmpty, nnkPragma}
@ -654,7 +652,7 @@ proc `pragma=`*(someProc: PNimrodNode; val: PNimrodNode){.compileTime.}=
template badNodeKind(k; f): stmt{.immediate.} = template badNodeKind(k; f): stmt{.immediate.} =
assert false, "Invalid node kind " & $k & " for macros.`" & $f & "`" assert false, "Invalid node kind " & $k & " for macros.`" & $f & "`"
proc body*(someProc: PNimrodNode): PNimrodNode {.compileTime.} = proc body*(someProc: NimNode): NimNode {.compileTime.} =
case someProc.kind: case someProc.kind:
of RoutineNodes: of RoutineNodes:
return someProc[6] return someProc[6]
@ -665,7 +663,7 @@ proc body*(someProc: PNimrodNode): PNimrodNode {.compileTime.} =
else: else:
badNodeKind someProc.kind, "body" badNodeKind someProc.kind, "body"
proc `body=`*(someProc: PNimrodNode, val: PNimrodNode) {.compileTime.} = proc `body=`*(someProc: NimNode, val: NimNode) {.compileTime.} =
case someProc.kind case someProc.kind
of RoutineNodes: of RoutineNodes:
someProc[6] = val someProc[6] = val
@ -676,10 +674,10 @@ proc `body=`*(someProc: PNimrodNode, val: PNimrodNode) {.compileTime.} =
else: else:
badNodeKind someProc.kind, "body=" badNodeKind someProc.kind, "body="
proc basename*(a: PNimrodNode): PNimrodNode {.compiletime, benign.} proc basename*(a: NimNode): NimNode {.compiletime, benign.}
proc `$`*(node: PNimrodNode): string {.compileTime.} = proc `$`*(node: NimNode): string {.compileTime.} =
## Get the string of an identifier node ## Get the string of an identifier node
case node.kind case node.kind
of nnkIdent: of nnkIdent:
@ -693,14 +691,14 @@ proc `$`*(node: PNimrodNode): string {.compileTime.} =
else: else:
badNodeKind node.kind, "$" badNodeKind node.kind, "$"
proc ident*(name: string): PNimrodNode {.compileTime,inline.} = newIdentNode(name) proc ident*(name: string): NimNode {.compileTime,inline.} = newIdentNode(name)
## Create a new ident node from a string ## Create a new ident node from a string
iterator children*(n: PNimrodNode): PNimrodNode {.inline.}= iterator children*(n: NimNode): NimNode {.inline.}=
for i in 0 .. high(n): for i in 0 .. high(n):
yield n[i] yield n[i]
template findChild*(n: PNimrodNode; cond: expr): PNimrodNode {. template findChild*(n: NimNode; cond: expr): NimNode {.
immediate, dirty.} = immediate, dirty.} =
## Find the first child node matching condition (or nil). ## Find the first child node matching condition (or nil).
## ##
@ -708,14 +706,14 @@ template findChild*(n: PNimrodNode; cond: expr): PNimrodNode {.
## var res = findChild(n, it.kind == nnkPostfix and ## var res = findChild(n, it.kind == nnkPostfix and
## it.basename.ident == !"foo") ## it.basename.ident == !"foo")
block: block:
var result: PNimrodNode var result: NimNode
for it in n.children: for it in n.children:
if cond: if cond:
result = it result = it
break break
result result
proc insert*(a: PNimrodNode; pos: int; b: PNimrodNode) {.compileTime.} = proc insert*(a: NimNode; pos: int; b: NimNode) {.compileTime.} =
## Insert node B into A at pos ## Insert node B into A at pos
if high(a) < pos: if high(a) < pos:
## add some empty nodes first ## add some empty nodes first
@ -730,7 +728,7 @@ proc insert*(a: PNimrodNode; pos: int; b: PNimrodNode) {.compileTime.} =
a[i + 1] = a[i] a[i + 1] = a[i]
a[pos] = b a[pos] = b
proc basename*(a: PNimrodNode): PNimrodNode = proc basename*(a: NimNode): NimNode =
## Pull an identifier from prefix/postfix expressions ## Pull an identifier from prefix/postfix expressions
case a.kind case a.kind
of nnkIdent: return a of nnkIdent: return a
@ -738,39 +736,39 @@ proc basename*(a: PNimrodNode): PNimrodNode =
else: else:
quit "Do not know how to get basename of ("& treeRepr(a) &")\n"& repr(a) quit "Do not know how to get basename of ("& treeRepr(a) &")\n"& repr(a)
proc `basename=`*(a: PNimrodNode; val: string) {.compileTime.}= proc `basename=`*(a: NimNode; val: string) {.compileTime.}=
case a.kind case a.kind
of nnkIdent: macros.`ident=`(a, !val) of nnkIdent: macros.`ident=`(a, !val)
of nnkPostfix, nnkPrefix: a[1] = ident(val) of nnkPostfix, nnkPrefix: a[1] = ident(val)
else: else:
quit "Do not know how to get basename of ("& treeRepr(a)& ")\n"& repr(a) quit "Do not know how to get basename of ("& treeRepr(a)& ")\n"& repr(a)
proc postfix*(node: PNimrodNode; op: string): PNimrodNode {.compileTime.} = proc postfix*(node: NimNode; op: string): NimNode {.compileTime.} =
newNimNode(nnkPostfix).add(ident(op), node) newNimNode(nnkPostfix).add(ident(op), node)
proc prefix*(node: PNimrodNode; op: string): PNimrodNode {.compileTime.} = proc prefix*(node: NimNode; op: string): NimNode {.compileTime.} =
newNimNode(nnkPrefix).add(ident(op), node) newNimNode(nnkPrefix).add(ident(op), node)
proc infix*(a: PNimrodNode; op: string; proc infix*(a: NimNode; op: string;
b: PNimrodNode): PNimrodNode {.compileTime.} = b: NimNode): NimNode {.compileTime.} =
newNimNode(nnkInfix).add(ident(op), a, b) newNimNode(nnkInfix).add(ident(op), a, b)
proc unpackPostfix*(node: PNimrodNode): tuple[node: PNimrodNode; op: string] {. proc unpackPostfix*(node: NimNode): tuple[node: NimNode; op: string] {.
compileTime.} = compileTime.} =
node.expectKind nnkPostfix node.expectKind nnkPostfix
result = (node[0], $node[1]) result = (node[0], $node[1])
proc unpackPrefix*(node: PNimrodNode): tuple[node: PNimrodNode; op: string] {. proc unpackPrefix*(node: NimNode): tuple[node: NimNode; op: string] {.
compileTime.} = compileTime.} =
node.expectKind nnkPrefix node.expectKind nnkPrefix
result = (node[0], $node[1]) result = (node[0], $node[1])
proc unpackInfix*(node: PNimrodNode): tuple[left: PNimrodNode; op: string; proc unpackInfix*(node: NimNode): tuple[left: NimNode; op: string;
right: PNimrodNode] {.compileTime.} = right: NimNode] {.compileTime.} =
assert node.kind == nnkInfix assert node.kind == nnkInfix
result = (node[0], $node[1], node[2]) result = (node[0], $node[1], node[2])
proc copy*(node: PNimrodNode): PNimrodNode {.compileTime.} = proc copy*(node: NimNode): NimNode {.compileTime.} =
## An alias for copyNimTree(). ## An alias for copyNimTree().
return node.copyNimTree() return node.copyNimTree()
@ -793,7 +791,7 @@ proc cmpIgnoreStyle(a, b: cstring): int {.noSideEffect.} =
proc eqIdent* (a, b: string): bool = cmpIgnoreStyle(a, b) == 0 proc eqIdent* (a, b: string): bool = cmpIgnoreStyle(a, b) == 0
## Check if two idents are identical. ## Check if two idents are identical.
proc hasArgOfName* (params: PNimrodNode; name: string): bool {.compiletime.}= proc hasArgOfName* (params: NimNode; name: string): bool {.compiletime.}=
## Search nnkFormalParams for an argument. ## Search nnkFormalParams for an argument.
assert params.kind == nnkFormalParams assert params.kind == nnkFormalParams
for i in 1 .. <params.len: for i in 1 .. <params.len:
@ -801,7 +799,7 @@ proc hasArgOfName* (params: PNimrodNode; name: string): bool {.compiletime.}=
if name.eqIdent( $ node[0]): if name.eqIdent( $ node[0]):
return true return true
proc addIdentIfAbsent*(dest: PNimrodNode, ident: string) {.compiletime.} = proc addIdentIfAbsent*(dest: NimNode, ident: string) {.compiletime.} =
## Add ident to dest if it is not present. This is intended for use ## Add ident to dest if it is not present. This is intended for use
## with pragmas. ## with pragmas.
for node in dest.children: for node in dest.children:
@ -825,5 +823,3 @@ when not defined(booting):
macro payload: stmt {.gensym.} = macro payload: stmt {.gensym.} =
result = parseStmt(e) result = parseStmt(e)
payload() payload()
{.pop.}

View file

@ -1064,13 +1064,13 @@ proc accept*(socket: TAsyncFD,
# -- Await Macro # -- Await Macro
proc skipUntilStmtList(node: PNimrodNode): PNimrodNode {.compileTime.} = proc skipUntilStmtList(node: NimNode): NimNode {.compileTime.} =
# Skips a nest of StmtList's. # Skips a nest of StmtList's.
result = node result = node
if node[0].kind == nnkStmtList: if node[0].kind == nnkStmtList:
result = skipUntilStmtList(node[0]) result = skipUntilStmtList(node[0])
proc skipStmtList(node: PNimrodNode): PNimrodNode {.compileTime.} = proc skipStmtList(node: NimNode): NimNode {.compileTime.} =
result = node result = node
if node[0].kind == nnkStmtList: if node[0].kind == nnkStmtList:
result = node[0] result = node[0]
@ -1098,11 +1098,11 @@ template createCb(retFutureSym, iteratorNameSym,
cb() cb()
#{.pop.} #{.pop.}
proc generateExceptionCheck(futSym, proc generateExceptionCheck(futSym,
tryStmt, rootReceiver, fromNode: PNimrodNode): PNimrodNode {.compileTime.} = tryStmt, rootReceiver, fromNode: NimNode): NimNode {.compileTime.} =
if tryStmt.kind == nnkNilLit: if tryStmt.kind == nnkNilLit:
result = rootReceiver result = rootReceiver
else: else:
var exceptionChecks: seq[tuple[cond, body: PNimrodNode]] = @[] var exceptionChecks: seq[tuple[cond, body: NimNode]] = @[]
let errorNode = newDotExpr(futSym, newIdentNode("error")) let errorNode = newDotExpr(futSym, newIdentNode("error"))
for i in 1 .. <tryStmt.len: for i in 1 .. <tryStmt.len:
let exceptBranch = tryStmt[i] let exceptBranch = tryStmt[i]
@ -1110,7 +1110,7 @@ proc generateExceptionCheck(futSym,
exceptionChecks.add((newIdentNode("true"), exceptBranch[0])) exceptionChecks.add((newIdentNode("true"), exceptBranch[0]))
else: else:
var exceptIdentCount = 0 var exceptIdentCount = 0
var ifCond: PNimrodNode var ifCond: NimNode
for i in 0 .. <exceptBranch.len: for i in 0 .. <exceptBranch.len:
let child = exceptBranch[i] let child = exceptBranch[i]
if child.kind == nnkIdent: if child.kind == nnkIdent:
@ -1144,10 +1144,10 @@ proc generateExceptionCheck(futSym,
) )
result.add elseNode result.add elseNode
template createVar(result: var PNimrodNode, futSymName: string, template createVar(result: var NimNode, futSymName: string,
asyncProc: PNimrodNode, asyncProc: NimNode,
valueReceiver, rootReceiver: expr, valueReceiver, rootReceiver: expr,
fromNode: PNimrodNode) = fromNode: NimNode) =
result = newNimNode(nnkStmtList, fromNode) result = newNimNode(nnkStmtList, fromNode)
var futSym = genSym(nskVar, "future") var futSym = genSym(nskVar, "future")
result.add newVarStmt(futSym, asyncProc) # -> var future<x> = y result.add newVarStmt(futSym, asyncProc) # -> var future<x> = y
@ -1155,9 +1155,9 @@ template createVar(result: var PNimrodNode, futSymName: string,
valueReceiver = newDotExpr(futSym, newIdentNode("read")) # -> future<x>.read valueReceiver = newDotExpr(futSym, newIdentNode("read")) # -> future<x>.read
result.add generateExceptionCheck(futSym, tryStmt, rootReceiver, fromNode) result.add generateExceptionCheck(futSym, tryStmt, rootReceiver, fromNode)
proc processBody(node, retFutureSym: PNimrodNode, proc processBody(node, retFutureSym: NimNode,
subTypeIsVoid: bool, subTypeIsVoid: bool,
tryStmt: PNimrodNode): PNimrodNode {.compileTime.} = tryStmt: NimNode): NimNode {.compileTime.} =
#echo(node.treeRepr) #echo(node.treeRepr)
result = node result = node
case node.kind case node.kind
@ -1183,7 +1183,7 @@ proc processBody(node, retFutureSym: PNimrodNode,
result = newNimNode(nnkYieldStmt, node).add(node[1]) # -> yield x result = newNimNode(nnkYieldStmt, node).add(node[1]) # -> yield x
of nnkCall, nnkCommand: of nnkCall, nnkCommand:
# await foo(p, x) # await foo(p, x)
var futureValue: PNimrodNode var futureValue: NimNode
result.createVar("future" & $node[1][0].toStrLit, node[1], futureValue, result.createVar("future" & $node[1][0].toStrLit, node[1], futureValue,
futureValue, node) futureValue, node)
else: else:
@ -1232,8 +1232,8 @@ proc processBody(node, retFutureSym: PNimrodNode,
# working in ``except``? # working in ``except``?
tryBody[1] = processBody(n[1], retFutureSym, subTypeIsVoid, nil) tryBody[1] = processBody(n[1], retFutureSym, subTypeIsVoid, nil)
proc processForTry(n: PNimrodNode, i: var int, proc processForTry(n: NimNode, i: var int,
res: PNimrodNode): bool {.compileTime.} = res: NimNode): bool {.compileTime.} =
## Transforms the body of the tryStmt. Does not transform the ## Transforms the body of the tryStmt. Does not transform the
## body in ``except``. ## body in ``except``.
## Returns true if the tryStmt node was transformed into an ifStmt. ## Returns true if the tryStmt node was transformed into an ifStmt.
@ -1275,7 +1275,7 @@ proc processBody(node, retFutureSym: PNimrodNode,
for i in 0 .. <result.len: for i in 0 .. <result.len:
result[i] = processBody(result[i], retFutureSym, subTypeIsVoid, tryStmt) result[i] = processBody(result[i], retFutureSym, subTypeIsVoid, tryStmt)
proc getName(node: PNimrodNode): string {.compileTime.} = proc getName(node: NimNode): string {.compileTime.} =
case node.kind case node.kind
of nnkPostfix: of nnkPostfix:
return $node[1].ident return $node[1].ident

View file

@ -12,7 +12,7 @@
import macros import macros
proc createProcType(p, b: PNimrodNode): PNimrodNode {.compileTime.} = proc createProcType(p, b: NimNode): NimNode {.compileTime.} =
#echo treeRepr(p) #echo treeRepr(p)
#echo treeRepr(b) #echo treeRepr(b)
result = newNimNode(nnkProcTy) result = newNimNode(nnkProcTy)
@ -62,7 +62,7 @@ macro `=>`*(p, b: expr): expr {.immediate.} =
#echo treeRepr(p) #echo treeRepr(p)
#echo(treeRepr(b)) #echo(treeRepr(b))
var params: seq[PNimrodNode] = @[newIdentNode("auto")] var params: seq[NimNode] = @[newIdentNode("auto")]
case p.kind case p.kind
of nnkPar: of nnkPar:

View file

@ -36,7 +36,7 @@ const
"onmouseover onmousemove onmouseout onkeypress onkeydown onkeyup " "onmouseover onmousemove onmouseout onkeypress onkeydown onkeyup "
commonAttr* = coreAttr & eventAttr commonAttr* = coreAttr & eventAttr
proc getIdent(e: PNimrodNode): string {.compileTime.} = proc getIdent(e: NimNode): string {.compileTime.} =
case e.kind case e.kind
of nnkIdent: result = normalize($e.ident) of nnkIdent: result = normalize($e.ident)
of nnkAccQuoted: of nnkAccQuoted:
@ -53,8 +53,8 @@ proc delete[T](s: var seq[T], attr: T): bool =
setLen(s, L-1) setLen(s, L-1)
result = true result = true
proc xmlCheckedTag*(e: PNimrodNode, tag: string, optAttr = "", reqAttr = "", proc xmlCheckedTag*(e: NimNode, tag: string, optAttr = "", reqAttr = "",
isLeaf = false): PNimrodNode {.compileTime.} = isLeaf = false): NimNode {.compileTime.} =
## use this procedure to define a new XML tag ## use this procedure to define a new XML tag
# copy the attributes; when iterating over them these lists # copy the attributes; when iterating over them these lists

View file

@ -644,7 +644,7 @@ proc `%`*(elements: openArray[JsonNode]): JsonNode =
newSeq(result.elems, elements.len) newSeq(result.elems, elements.len)
for i, p in pairs(elements): result.elems[i] = p for i, p in pairs(elements): result.elems[i] = p
proc toJson(x: PNimrodNode): PNimrodNode {.compiletime.} = proc toJson(x: NimNode): NimNode {.compiletime.} =
case x.kind case x.kind
of nnkBracket: of nnkBracket:
result = newNimNode(nnkBracket) result = newNimNode(nnkBracket)

View file

@ -144,7 +144,7 @@ macro check*(conditions: stmt): stmt {.immediate.} =
when compiles(string($value)): when compiles(string($value)):
checkpoint(name & " was " & $value) checkpoint(name & " was " & $value)
proc inspectArgs(exp: PNimrodNode) = proc inspectArgs(exp: NimNode) =
for i in 1 .. <exp.len: for i in 1 .. <exp.len:
if exp[i].kind notin nnkLiterals: if exp[i].kind notin nnkLiterals:
inc counter inc counter
@ -202,7 +202,7 @@ template require*(conditions: stmt): stmt {.immediate, dirty.} =
macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} = macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} =
let exp = callsite() let exp = callsite()
template expectBody(errorTypes, lineInfoLit: expr, template expectBody(errorTypes, lineInfoLit: expr,
body: stmt): PNimrodNode {.dirty.} = body: stmt): NimNode {.dirty.} =
try: try:
body body
checkpoint(lineInfoLit & ": Expect Failed, no exception was thrown.") checkpoint(lineInfoLit & ": Expect Failed, no exception was thrown.")

View file

@ -263,7 +263,7 @@ proc newXmlTree*(tag: string, children: openArray[XmlNode],
for i in 0..children.len-1: result.s[i] = children[i] for i in 0..children.len-1: result.s[i] = children[i]
result.fAttr = attributes result.fAttr = attributes
proc xmlConstructor(e: PNimrodNode): PNimrodNode {.compileTime.} = proc xmlConstructor(e: NimNode): NimNode {.compileTime.} =
expectLen(e, 2) expectLen(e, 2)
var a = e[1] var a = e[1]
if a.kind == nnkCall: if a.kind == nnkCall:

View file

@ -3149,15 +3149,9 @@ proc shallow*(s: var string) {.noSideEffect, inline.} =
type type
NimNodeObj = object NimNodeObj = object
when defined(nimnode): NimNode* {.magic: "PNimrodNode".} = ref NimNodeObj
type ## represents a Nim AST node. Macros operate on this type.
NimNode* {.magic: "PNimrodNode".} = ref NimNodeObj {.deprecated: [PNimrodNode: NimNode].}
## represents a Nim AST node. Macros operate on this type.
{.deprecated: [PNimrodNode: NimNode].}
else:
type
PNimrodNode* {.magic: "PNimrodNode".} = ref NimNodeObj
## represents a Nim AST node. Macros operate on this type.
when false: when false:
template eval*(blk: stmt): stmt = template eval*(blk: stmt): stmt =

View file

@ -58,7 +58,7 @@ macro expect*(exceptions: varargs[expr], body: stmt): stmt {.immediate.} =
## Expect docstrings ## Expect docstrings
let exp = callsite() let exp = callsite()
template expectBody(errorTypes, lineInfoLit: expr, template expectBody(errorTypes, lineInfoLit: expr,
body: stmt): PNimrodNode {.dirty.} = body: stmt): NimNode {.dirty.} =
try: try:
body body
assert false assert false

View file

@ -20,13 +20,13 @@ import strutils
# This serves the same purpose as D's `alias` parameters for types, used heavily # This serves the same purpose as D's `alias` parameters for types, used heavily
# in its popular `ranges` and `algorithm` modules. # in its popular `ranges` and `algorithm` modules.
var exprNodes {.compileTime.} = newSeq[PNimrodNode]() var exprNodes {.compileTime.} = newSeq[NimNode]()
proc refExpr(exprNode: PNimrodNode): string {.compileTime.} = proc refExpr(exprNode: NimNode): string {.compileTime.} =
exprNodes.add exprNode.copy exprNodes.add exprNode.copy
"expr" & $(exprNodes.len - 1) "expr" & $(exprNodes.len - 1)
proc derefExpr(exprRef: string): PNimrodNode {.compileTime.} = proc derefExpr(exprRef: string): NimNode {.compileTime.} =
exprNodes[parseInt(exprRef[4 .. -1])] exprNodes[parseInt(exprRef[4 .. -1])]
#=============================================================================== #===============================================================================

View file

@ -69,7 +69,7 @@ m(s)
# bug #933 # bug #933
proc nilcheck(): PNimrodNode {.compileTime.} = proc nilcheck(): NimNode {.compileTime.} =
echo(result == nil) # true echo(result == nil) # true
echo(result.isNil) # true echo(result.isNil) # true
echo(repr(result)) # nil echo(repr(result)) # nil

View file

@ -1,4 +1,4 @@
# Dump the contents of a PNimrodNode # Dump the contents of a NimNode
import macros import macros

View file

@ -1,8 +1,8 @@
# Dump the contents of a PNimrodNode # Dump the contents of a NimNode
import macros import macros
proc dumpit(n: PNimrodNode): string {.compileTime.} = proc dumpit(n: NimNode): string {.compileTime.} =
if n == nil: return "nil" if n == nil: return "nil"
result = $n.kind result = $n.kind
add(result, "(") add(result, "(")

View file

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

View file

@ -2,7 +2,7 @@
import parseutils, macros 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 splitValue: string
var read = value.parseUntil(splitValue, '$', index) 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: if splitValue.len > 0:
node.insert node.len, newCall("add", ident("result"), newStrLitNode(splitValue)) 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 var index = 0
while index < value.len and while index < value.len and
parse_until_symbol(node, value, index): discard parse_until_symbol(node, value, index): discard

View file

@ -19,7 +19,7 @@ test:
macro test2*(a: stmt): stmt {.immediate.} = macro test2*(a: stmt): stmt {.immediate.} =
proc testproc(recurse: int) = proc testproc(recurse: int) =
echo "Thats weird" echo "Thats weird"
var o : PNimrodNode = nil var o : NimNode = nil
echo " no its not!" echo " no its not!"
o = newNimNode(nnkNone) o = newNimNode(nnkNone)
if recurse > 0: if recurse > 0:

View file

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

View file

@ -1,7 +1,7 @@
import macros,json import macros,json
var decls{.compileTime.}: seq[PNimrodNode] = @[] var decls{.compileTime.}: seq[NimNode] = @[]
var impls{.compileTime.}: seq[PNimrodNode] = @[] var impls{.compileTime.}: seq[NimNode] = @[]
macro importImpl_forward(name, returns): stmt {.immediate.} = macro importImpl_forward(name, returns): stmt {.immediate.} =
result = newNimNode(nnkEmpty) result = newNimNode(nnkEmpty)

View file

@ -18,7 +18,7 @@ macro outterMacro*(n: stmt): stmt {.immediate.} =
" requires the ident passed as parameter (eg: " & callNode.repr & " requires the ident passed as parameter (eg: " & callNode.repr &
"(the_name_you_want)): statements.") "(the_name_you_want)): statements.")
result = newNimNode(TNimrodNodeKind.nnkStmtList) result = newNimNode(TNimrodNodeKind.nnkStmtList)
var ass : PNimrodNode = newNimNode(nnkAsgn) var ass : NimNode = newNimNode(nnkAsgn)
ass.add(newIdentNode(n[1].ident)) ass.add(newIdentNode(n[1].ident))
ass.add(newStrLitNode(innerProc(4))) ass.add(newStrLitNode(innerProc(4)))
result.add(ass) result.add(ass)

View file

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

View file

@ -27,7 +27,7 @@ macro formatStyleInterpolation(e: expr): expr =
proc addString(s: string) = proc addString(s: string) =
formatString.add(s) formatString.add(s)
proc addExpr(e: PNimrodNode) = proc addExpr(e: NimNode) =
arrayNode.add(e) arrayNode.add(e)
formatString.add("$" & $(idx)) formatString.add("$" & $(idx))
inc idx inc idx
@ -43,11 +43,11 @@ macro formatStyleInterpolation(e: expr): expr =
macro concatStyleInterpolation(e: expr): expr = macro concatStyleInterpolation(e: expr): expr =
let e = callsite() let e = callsite()
var args: seq[PNimrodNode] var args: seq[NimNode]
newSeq(args, 0) newSeq(args, 0)
proc addString(s: string) = args.add(newStrLitNode(s)) 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"$") proc addDollar() = args.add(newStrLitNode"$")
processInterpolations(e) processInterpolations(e)

View file

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

View file

@ -206,15 +206,15 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} =
when defined(GenPacketShowOutput): when defined(GenPacketShowOutput):
echo(repr(result)) echo(repr(result))
proc `->`(a: string, b: string): PNimrodNode {.compileTime.} = proc `->`(a: string, b: string): NimNode {.compileTime.} =
result = newNimNode(nnkIdentDefs).und(^a, ^b, newNimNode(nnkEmpty)) result = newNimNode(nnkIdentDefs).und(^a, ^b, newNimNode(nnkEmpty))
proc `->`(a: string, b: PNimrodNode): PNimrodNode {.compileTime.} = proc `->`(a: string, b: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkIdentDefs).und(^a, b, newNimNode(nnkEmpty)) result = newNimNode(nnkIdentDefs).und(^a, b, newNimNode(nnkEmpty))
proc `->`(a, b: PNimrodNode): PNimrodNode {.compileTime.} = proc `->`(a, b: NimNode): NimNode {.compileTime.} =
a[2] = b a[2] = b
result = a result = a
proc newProc*(name: string, params: varargs[PNimrodNode], resultType: PNimrodNode): PNimrodNode {.compileTime.} = proc newProc*(name: string, params: varargs[NimNode], resultType: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkProcDef).und( result = newNimNode(nnkProcDef).und(
^name, ^name,
emptyNode(), emptyNode(),

View file

@ -178,7 +178,7 @@ macro defPacket*(typeNameN: expr, typeFields: expr): stmt {.immediate.} =
when defined(GenPacketShowOutput): when defined(GenPacketShowOutput):
echo(repr(result)) echo(repr(result))
proc newProc*(name: PNimrodNode; params: varargs[PNimrodNode]; resultType: PNimrodNode): PNimrodNode {.compileTime.} = proc newProc*(name: NimNode; params: varargs[NimNode]; resultType: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkProcDef).und( result = newNimNode(nnkProcDef).und(
name, name,
emptyNode(), emptyNode(),
@ -189,15 +189,15 @@ proc newProc*(name: PNimrodNode; params: varargs[PNimrodNode]; resultType: PNimr
newNimNode(nnkStmtList)) newNimNode(nnkStmtList))
result[3].add(params) result[3].add(params)
proc body*(procNode: PNimrodNode): PNimrodNode {.compileTime.} = proc body*(procNode: NimNode): NimNode {.compileTime.} =
assert procNode.kind == nnkProcDef and procNode[6].kind == nnkStmtList assert procNode.kind == nnkProcDef and procNode[6].kind == nnkStmtList
result = procNode[6] result = procNode[6]
proc iddefs*(a, b: string; c: PNimrodNode): PNimrodNode {.compileTime.} = proc iddefs*(a, b: string; c: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkIdentDefs).und(^a, ^b, c) result = newNimNode(nnkIdentDefs).und(^a, ^b, c)
proc iddefs*(a: string; b: PNimrodNode): PNimrodNode {.compileTime.} = proc iddefs*(a: string; b: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkIdentDefs).und(^a, b, emptyNode()) result = newNimNode(nnkIdentDefs).und(^a, b, emptyNode())
proc varTy*(a: PNimrodNode): PNimrodNode {.compileTime.} = proc varTy*(a: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkVarTy).und(a) result = newNimNode(nnkVarTy).und(a)
macro forwardPacket*(typeName: expr, underlyingType: expr): stmt {.immediate.} = macro forwardPacket*(typeName: expr, underlyingType: expr): stmt {.immediate.} =

View file

@ -1,42 +1,42 @@
import macros import macros
{.deadCodeElim: on.} {.deadCodeElim: on.}
#Inline macro.add() to allow for easier nesting #Inline macro.add() to allow for easier nesting
proc und*(a: PNimrodNode; b: PNimrodNode): PNimrodNode {.compileTime.} = proc und*(a: NimNode; b: NimNode): NimNode {.compileTime.} =
a.add(b) a.add(b)
result = a result = a
proc und*(a: PNimrodNode; b: varargs[PNimrodNode]): PNimrodNode {.compileTime.} = proc und*(a: NimNode; b: varargs[NimNode]): NimNode {.compileTime.} =
a.add(b) a.add(b)
result = a result = a
proc `^`*(a: string): PNimrodNode {.compileTime.} = proc `^`*(a: string): NimNode {.compileTime.} =
## new ident node ## new ident node
result = newIdentNode(!a) result = newIdentNode(!a)
proc `[]`*(a, b: PNimrodNode): PNimrodNode {.compileTime.} = proc `[]`*(a, b: NimNode): NimNode {.compileTime.} =
## new bracket expression: node[node] not to be confused with node[indx] ## new bracket expression: node[node] not to be confused with node[indx]
result = newNimNode(nnkBracketExpr).und(a, b) result = newNimNode(nnkBracketExpr).und(a, b)
proc `:=`*(left, right: PNimrodNode): PNimrodNode {.compileTime.} = proc `:=`*(left, right: NimNode): NimNode {.compileTime.} =
## new Asgn node: left = right ## new Asgn node: left = right
result = newNimNode(nnkAsgn).und(left, right) result = newNimNode(nnkAsgn).und(left, right)
proc lit*(a: string): PNimrodNode {.compileTime.} = proc lit*(a: string): NimNode {.compileTime.} =
result = newStrLitNode(a) result = newStrLitNode(a)
proc lit*(a: int): PNimrodNode {.compileTime.} = proc lit*(a: int): NimNode {.compileTime.} =
result = newIntLitNode(a) result = newIntLitNode(a)
proc lit*(a: float): PNimrodNode {.compileTime.} = proc lit*(a: float): NimNode {.compileTime.} =
result = newFloatLitNode(a) result = newFloatLitNode(a)
proc lit*(a: char): PNimrodNode {.compileTime.} = proc lit*(a: char): NimNode {.compileTime.} =
result = newNimNode(nnkCharLit) result = newNimNode(nnkCharLit)
result.intval = a.ord result.intval = a.ord
proc emptyNode*(): PNimrodNode {.compileTime.} = proc emptyNode*(): NimNode {.compileTime.} =
result = newNimNode(nnkEmpty) result = newNimNode(nnkEmpty)
proc dot*(left, right: PNimrodNode): PNimrodNode {.compileTime.} = proc dot*(left, right: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkDotExpr).und(left, right) result = newNimNode(nnkDotExpr).und(left, right)
proc prefix*(a: string, b: PNimrodNode): PNimrodNode {.compileTime.} = proc prefix*(a: string, b: NimNode): NimNode {.compileTime.} =
result = newNimNode(nnkPrefix).und(newIdentNode(!a), b) result = newNimNode(nnkPrefix).und(newIdentNode(!a), b)
proc quoted2ident*(a: PNimrodNode): PNimrodNode {.compileTime.} = proc quoted2ident*(a: NimNode): NimNode {.compileTime.} =
if a.kind != nnkAccQuoted: if a.kind != nnkAccQuoted:
return a return a
var pname = "" var pname = ""

View file

@ -104,7 +104,7 @@ proc pat2kind(pattern: string): FormulaKind =
import macros import macros
proc matchAgainst(n, pattern: PNimrodNode): PNimrodNode {.compileTime.} = proc matchAgainst(n, pattern: NimNode): NimNode {.compileTime.} =
template `@`(current, field: expr): expr = template `@`(current, field: expr): expr =
newDotExpr(current, newIdentNode(astToStr(field))) newDotExpr(current, newIdentNode(astToStr(field)))

View file

@ -18,7 +18,7 @@ const identChars = {'a'..'z', 'A'..'Z', '0'..'9', '_'}
# Procedure Declarations # Procedure Declarations
proc parse_template(node: PNimrodNode, value: string) {.compiletime.} proc parse_template(node: NimNode, value: string) {.compiletime.}
# Procedure Definitions # Procedure Definitions
@ -166,7 +166,7 @@ iterator parse_compound_statements(value, identifier: string, index: int): strin
get_next_ident(["try", "$except", "$finally"]) get_next_ident(["try", "$except", "$finally"])
proc parse_complex_stmt(value, identifier: string, index: var int): PNimrodNode {.compiletime.} = proc parse_complex_stmt(value, identifier: string, index: var int): NimNode {.compiletime.} =
## Parses if/when/try /elif /else /except /finally statements ## Parses if/when/try /elif /else /except /finally statements
# Build up complex statement string # Build up complex statement string
@ -218,7 +218,7 @@ proc parse_complex_stmt(value, identifier: string, index: var int): PNimrodNode
inc(resultIndex) inc(resultIndex)
proc parse_simple_statement(value: string, index: var int): PNimrodNode {.compiletime.} = proc parse_simple_statement(value: string, index: var int): NimNode {.compiletime.} =
## Parses for/while ## Parses for/while
# Detect indentation # Detect indentation
@ -252,7 +252,7 @@ proc parse_simple_statement(value: string, index: var int): PNimrodNode {.compil
inc(index, value.parse_thru_eol(index)) inc(index, value.parse_thru_eol(index))
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.} =
## Parses a string until a $ symbol is encountered, if ## Parses a string until a $ symbol is encountered, if
## two $$'s are encountered in a row, a split will happen ## two $$'s are encountered in a row, a split will happen
## removing one of the $'s from the resulting output ## removing one of the $'s from the resulting output
@ -311,7 +311,7 @@ proc parse_until_symbol(node: PNimrodNode, value: string, index: var int): bool
node.insert insertionPoint, newCall("add", ident("result"), newStrLitNode(splitValue)) node.insert insertionPoint, newCall("add", ident("result"), newStrLitNode(splitValue))
proc parse_template(node: PNimrodNode, value: string) = proc parse_template(node: NimNode, value: string) =
## Parses through entire template, outputing valid ## Parses through entire template, outputing valid
## Nim code into the input `node` AST. ## Nim code into the input `node` AST.
var index = 0 var index = 0

View file

@ -22,8 +22,8 @@ macro autoClose(e: expr): stmt {.immediate.} =
var body = e[2] var body = e[2]
var var
variables : seq[PNimrodNode] variables : seq[NimNode]
closingCalls : seq[PNimrodNode] closingCalls : seq[NimNode]
newSeq(variables, 0) newSeq(variables, 0)
newSeq(closingCalls, 0) newSeq(closingCalls, 0)

View file

@ -8,9 +8,9 @@ type
suiteDesc: string suiteDesc: string
testName: string testName: string
testDesc: string testDesc: string
testBlock: PNimrodNode testBlock: NimNode
proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: PNimrodNode): tuple[tests: seq[SuiteTest]] {.compileTime.} = proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: NimNode): tuple[tests: seq[SuiteTest]] {.compileTime.} =
var var
tests:seq[SuiteTest] = @[] tests:seq[SuiteTest] = @[]