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

2018-04-03 Thread mratsim
That's actually a regular question (pain point?) regarding macros. The current way is to preprocess using an untyped macro, and then dispatch/getAST from a typed macro when you need type resolution. I remember seeing some discussion to ease that but they are pretty buried.

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

2018-04-03 Thread timothee
> It works when the macro parameter is untyped, thanks @rpowers and @mashingan, using untyped instead of typed works (but I was using typed because of your other answer from [https://forum.nim-lang.org/t/3701/1#23070](https://forum.nim-lang.org/t/3701/1#23070) to allow if x.getTypeInst.typeKind

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

2018-04-03 Thread mashingan
This is from tutorial import macros macro debug(x: varargs[untyped]): typed = result = newStmtList() for s in x: var slit = s.toStrLit var stringExpr = slit.repr echo stringExpr & " okay" result.add newCall("write

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: how to get unmodified / uninterpreted source code/AST of expression in macro?

2018-04-02 Thread timothee
> Perhaps this is what you want, dump > [https://nim-lang.org/docs/future.html#dump.m,typed](https://nim-lang.org/docs/future.html#dump.m,typed) dump does not work at all and in fact the documentation is misleading: as it would appear in source code is not true: dump(1+1) prints 2 = 2 instead of

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

2018-04-02 Thread mashingan
Perhaps this is what you want, dump [https://nim-lang.org/docs/future.html#dump.m,typed](https://nim-lang.org/docs/future.html#dump.m,typed)

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

2018-04-02 Thread timothee
Is there a way to get unmodified / uninterpreted source code (as either string or AST) of an expression in a macro? motivation 1: to allow writing logging functions that show exact expression on left hand side, eg: mylog(1+1) # prints 1+1=2 motivation 2: to allow writing smart assert function t