Re: how to get unmodified / uninterpreted source code/AST of expression in macro?

2018-04-03 Thread rpowers
It works when the macro parameter is untyped, I guess constant folding happens during the typing process: import macros macro mylog(x:untyped): untyped = result = newNimNode(nnkStmtList, x) result.add(newCall("write", newIdentNode("stdout"), toStrLit(x)))

Re: a proc returning void creates 1 arg, not 0: breaking generic code

2018-03-29 Thread rpowers
Oh, right! I guess it's testing it on untyped rather than the actual type in the macro. Anyways, this one is definitely working, it just tests for void-typed arguments: import macros import typetraits import strformat macro fun*(n: varargs[typed]): typed =

Re: How to call a macro from a template with a constructed identifier argument?

2018-03-23 Thread rpowers
Thanks for the suggestions. @mratsim I had no idea you could put a template inside a macro and get its evaluated AST. Cool! This will be very useful. @Lando Interesting, I guess this works because quote doesn't touch the passed in backticked identifier and this is then returned intact to the

Re: How to call a macro from a template with a constructed identifier argument?

2018-03-22 Thread rpowers
Yes, that compiles, but the macro produces the code let x = 1000 instead of the code let xExtra = 1000 I'm trying to get the identifier to be constructed before passing it into the macro, but I'm not sure if that's possible.

How to call a macro from a template with a constructed identifier argument?

2018-03-21 Thread rpowers
I have a macro that creates a type and associated functions, and I'm calling that from a template. I want to use identifier construction to append a suffix to the template parameter, but the whole backticked AST (instead of the constructed identifier) gets passed in to the macro. Is there some

Re: Emscripten/WebAssembly GC considerations?

2018-03-20 Thread rpowers
@yglukhov Thanks, that makes sense, I can just call GC_step at the start of each emscripten_set_main_loop callback. By the way, thanks for writing jsbind, it has been very helpful! @mashingan I copied most of the nim.cfg from here:

Emscripten/WebAssembly GC considerations?

2018-03-19 Thread rpowers
I've been using Nim to generate WebAssembly using Emscripten and everything seems to be working very well. Are there any special considerations I should make for the GC? I know that it's impossible to scan the stack in WASM, but that shouldn't be much of a problem for Nim due to reference