Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Test assigning anonymous procs with macro pragmas.
- import macros
- type
- iiproc = proc (a :int): int
- macro procmacro(actions: stmt): expr {.immediate.} =
- # This macro will eventually do something
- # interesting, if it works at all.
- # When called with a proc expression
- # it should expand to an expression.
- echo()
- echo(treeRepr(actions))
- result = actions
- # Assigning a lambda works.
- var add_one: iiproc
- add_one = proc (a: int): int =
- return a+1
- # Using the procmacro works.
- proc add_two(a: int): int {.procmacro.} =
- return a+2
- # Combine the two into one easy to use statement, fails on 0.10.2
- # with:
- # Error: value of type 'proc (int): int{.gcsafe, locks: 0.}' has to be discarded
- var add_three: iiproc
- add_three = proc (a: int): int {.procmacro.} =
- return a+3
Advertisement
Add Comment
Please, Sign In to add comment