Re: How to get string representation of int inside of the macros?

2018-03-30 Thread r3d9u11
many thanks, it works! (I'll try to search and read about static types)

Re: Custom pragma on type

2018-03-30 Thread cdome
Looks like a bug, type pragmas are not seen on the user side type User {.exportc, packed.} = object id: int import macros macro test(t: typedesc): untyped = echo t.getType()[1].symbol.getImpl.treerepr test(User) gives

Re: How to get string representation of int inside of the macros?

2018-03-30 Thread mashingan
add static to the type import macros macro initNui(a: static[int]): typed = result = parseStmt("const b = " & $a) initNui 1

Re: Protocol Buffer library for Nim

2018-03-30 Thread timothee
see also [https://github.com/PMunch/protobuf-nim](https://github.com/PMunch/protobuf-nim) (doesn't rely on protoc compiler; cf [https://github.com/oswjk/protobuf-nim/issues/2](https://github.com/oswjk/protobuf-nim/issues/2)) + a discussion of related packages here: [https://github.com/PMunch/p

How to get string representation of int inside of the macros?

2018-03-30 Thread r3d9u11
Hello. I tried to represent int to string inside a macros: import macros macro initNui(a:int): typed = result = parseStmt("const b=" & $a) initNui(1) but I had compilcation error: unhandled exception: false Invalid node kind nnkIntLit for

Re: Protocol Buffer library for Nim

2018-03-30 Thread PMunch
Very nice! I tried to go a different route and make the entire parser in Nim as well. The result is being able to only call the macro with the name of your protobuf specification file and have Nim do the rest. This means that you don't even need the protoc compiler to use protobuf in Nim! I know

Re: use fork() to speed up compilation testing.

2018-03-30 Thread cblake
@twetzel59 - I use fork (and even vfork) all the time. They work just fine. @Krux02 - I have never used compiler-as-a-service mode which seems originally targeted at IDEs, but that feature may apply to testing as well. See `compiler/service.nim` and `tests/testament/caasdriver.nim`..maybe search

Re: Dynamic import of packages at macro-time

2018-03-30 Thread r3d9u11
well, I'm found [similar theme](https://forum.nim-lang.org/t/3061/2). This works: import macros macro load*(modulesSeq: varargs[untyped]): untyped = result = newStmtList() for module in modulesSeq: result.add parseStmt("from " & $module & " import nil")

Re: use fork() to speed up compilation testing.

2018-03-30 Thread twetzel59
Not having worked on the compiler, I can't guarantee anything, but here would be my first 3 questions: * Has anyone successfully used `fork()` from Nim? * Does this memmapping mess up the GC? * What about handling dead processes? Before too many tests are executed the compiler would need t

Re: vtref and vtptr vs method !!!

2018-03-30 Thread twetzel59
Cool! I ran it and got similar results.

Dynamic packages import at macro-time

2018-03-30 Thread r3d9u11
Hi. Does Nim supports anything like a "dynamic packges loading"? For example, I have 3 packages: pack0.nim (root package) contains: var dstBack = 0 # some variable-indetifier (will indicate, from wich poackage someProc will be called) macro init*(back:int) = # so

Re: scope guards

2018-03-30 Thread mratsim
It's a post from 2013 . Anyway the idiomatic way to do scope guard is with a template that does try: body finally: as it's done by Udiknedormin [here](https://forum.nim-lang.org/t/3205/1#20223). There is an example in the [guards and lock section](https://nim-lang.org/docs/manual.html#guards-a

Re: vtref and vtptr vs method !!!

2018-03-30 Thread mratsim
If performance is your concern, use Nim methods. I benchmarked them vs procs and closures and I found out that they are only 3 times slower than regular proc: [Bench](https://github.com/mratsim/Arraymancer/blob/master/benchmarks/implementation/proc_method_closure_bench.nim). Don't run it on the

Re: how to call a function by name?

2018-03-30 Thread r3d9u11
Thanks for clarification regarding Nim! (but, as I know, "reflection" is a conception relating only for runtime. everything else is something different)

SIGSEGV using lines(filename)

2018-03-30 Thread kinkinkijkin
In the following code, with the error line marked with a "119", I get a SIGSEGV. Software distribution is arch linux on this machine. var envs, wavs, fms, macros: seq[tuple[name: string, values: string]] var name, artist: string = "" var tickrate: int16 = 0 ...

Re: Bug (?) with templates

2018-03-30 Thread slangmgh
I think maybe this is template bug. These code doesn't compile from @zielmicha. template bar() {.dirty.} = echo a template foo() = let a = 5 bar() foo() But when we turn foo into proc, the code works. template bar() {.dirt

Custom pragma on type

2018-03-30 Thread doofenstein
Is there a way to check an object type for a custom pragma? In the manual there's an example of a custom annotation on a type, but it isn't ([https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-custom-annotations](https://nim-lang.org/docs/manual.html#implementation-specific-pra

Re: vtref and vtptr vs method !!!

2018-03-30 Thread twetzel59
Araq, should I be avoiding the use of `method`? I generally consider it useful, especially as it allows dynamic dispatch through dispatch trees as opposed to function pointers. Due to performance concerns, I am often (unreasonably?) averse to function pointers. * * * Here's my two cents: I ba

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

2018-03-30 Thread timothee
@Dennis my bad I should've verified the D code I posted; with tuples though we have: import std.stdio:writeln; void fun(T...)(T n) { static foreach (x; n) writeln(x); writeln("L=", T.length); } void main(){ import std.typecons:tuple