0

How is the Nim capability to be able to produce its source file which has all been normalized, i.e. evaluated/expanded all of the directives, templates, macros, etc.with their same arguments ?

itil memek cantik
  • 1,167
  • 2
  • 11

1 Answers1

2

Yes, via expandMacros. https://nim-lang.org/docs/macros.html#expandMacros.m%2Ctyped

It's possible to implement your own expandMacros macro like this:

import macros

macro myExpandMacros(body: typed): typed =
  template inner(x: typed): typed = x

  result = getAst(inner(body))
  echo result.toStrLit

Usage example:

import macros, asyncdispatch

# Will echo expanded source code
# at compile time.
expandMacros:
  proc test() {.async.} =
    discard
Davide Galilei
  • 484
  • 6
  • 9