Merge branch 'master' of github.com:Araq/Nimrod

This commit is contained in:
Araq
2012-11-11 22:05:04 +01:00
8 changed files with 130 additions and 15 deletions

View File

@@ -234,6 +234,35 @@ proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst".}
## macro FooMacro() =
## var ast = getAst(BarTemplate())
proc quote*(bl: stmt, op = "``"): PNimrodNode {.magic: "QuoteAst".}
## Quasi-quoting operator.
## Accepts an expression or a block and returns the AST that represents it.
## Within the quoted AST, you are able to interpolate PNimrodNode expressions
## 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
## for any interpolated expression. The original meaning of the interpolation
## operator may be obtained by escaping it (by prefixing it with itself):
## e.g. `@` is escaped as `@@`, `@@` is escaped as `@@@` and so on.
##
## Example:
##
## macro check(ex: expr): stmt =
## # this is a simplified version of the check macro from the
## # unittest module.
##
## # If there is a failed check, we want to make it easy for
## # the user to jump to the faulty line in the code, so we
## # get the line info here:
## var info = ex.lineinfo
##
## # We will also display the code string of the failed check:
## var expString = ex.toStrLit
##
## # Finally we compose the code to implement the check:
## result = quote do:
## if not `ex`:
## echo `info` & ": Check failed: " & `expString`
template emit*(e: expr[string]): stmt =
## accepts a single string argument and treats it as nimrod code
## that should be inserted verbatim in the program

View File

@@ -364,6 +364,10 @@ proc newSeq*[T](s: var seq[T], len: int) {.magic: "NewSeq", noSideEffect.}
## This is equivalent to ``s = @[]; setlen(s, len)``, but more
## efficient since no reallocation is needed.
proc newSeq*[T](len = 0): seq[T] =
## creates a new sequence of type ``seq[T]`` with length ``len``.
newSeq(result, len)
proc len*[TOpenArray: openArray|varargs](x: TOpenArray): int {.
magic: "LengthOpenArray", noSideEffect.}
proc len*(x: string): int {.magic: "LengthStr", noSideEffect.}