<FromGitter>
... ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I'd love to remove that requirement. I'm trying to understand if there's a way to keep track of the lengths that have been exhausted by each field *at compile-time* rather than at runtime. Is there a convenient way to do this? Could anyone help me with this or direct me where to find so ... [https://gitter.im/crystal-lang/crystal?at=5f66cf03a857200e6d704bd1]
<FromGitter>
<mattrberry> And hopefully that'll also let me give a compile-time error messages if the inheriting class specifies too few or too many bits in its fields
_whitelogger has joined #crystal-lang
<FromGitter>
<mattrberry> Hmm, I guess I can create a constant `CURRENT_POS = [0]` and just update the value inside the array..
<FromGitter>
<mattrberry> Is there a way to access the size of the generic type in the macro? E.g. in the example above, get the size of `UInt8`?
johnny101 has joined #crystal-lang
<FromGitter>
<mattrberry> Okay I got everything working to my satisfaction except for getting the size of the generic type.. Anybody know how I might do that?
<FromGitter>
<asterite> Julien: blocks and anonymous functions are different
<FromGitter>
<j8r> @asterite The result is similar in my case, no?
<FromGitter>
<j8r> If you prefer, similar to passing procs in Crystal. At the end, using inlined code or calling a function pointer, no much difference I see.
<FromGitter>
<mattrberry> Which errors with the following: `Error: undefined macro method 'SizeOf#-'`
lanodan has quit [Read error: Connection reset by peer]
lanodan has joined #crystal-lang
<FromGitter>
<Blacksmoke16> yea you cant get that in macroland afaik
<FromGitter>
<Blacksmoke16> but did you try just doing `POS = sizeof(T)`?
<FromGitter>
<Blacksmoke16> or try wrapping it in `{% begin %} / {% end %}`?
<FromGitter>
<mattrberry> As far as I can tell, neither of those accomplishes what I'm looking for :/
<FromGitter>
<mattrberry> I can see that at compile-time I can get `@type.superclass.type_vars[0]` to get the generic type var, I just need the size of that. That information should *theoretically* be available at compile time, right?
<FromGitter>
<Blacksmoke16> afaik idt you can get it at compile time like that
<FromGitter>
<Blacksmoke16> i also think `T` is only available in context of a method
<FromGitter>
<mattrberry> Bummer :/ I need to know the size of the generic type in order to know how to pack the bits at compile time
alexherbo2 has joined #crystal-lang
<FromGitter>
<Blacksmoke16> :shrug:
<FromGitter>
<mattrberry> I guess I can just make another macro on the BitField class that allows the inheriting class to just specify a size, assume that's valid at compile time, then verify it when the inheriting class is instantiated
<FromGitter>
<Blacksmoke16> do you need the size for some calculations in a macro at compile time? or you just trying to have a way to expose the size based on `T`?
<FromGitter>
<mattrberry> I need the size for calculations at compile time. At least the way I'm currently approaching it is that I use the POS to determine how many bits to shift off, and that calculation is done at compile time since I don't want the logic to exist at runtime
<FromGitter>
<Blacksmoke16> im not sure if there is a reason why `sizeof` can't be used in macro land, or if it just hasn't been implemented
<FromGitter>
<mattrberry> Seems like a pretty niche use case, so I wouldn't be surprised if it was the latter
<yxhuvud>
the result of sizeof may depend of running other macros in the system.
<yxhuvud>
So there is a lot of potential headache that is avoided by not having it.
ua has quit [Ping timeout: 272 seconds]
<FromGitter>
<asterite> Julien: try doing return inside an anonymous function and compare that do doing return from a block
<FromGitter>
<asterite> sizeof in macros can't work because macros run even before a type hierarchy is defined, or even before instance vars are defined
ua has joined #crystal-lang
<FromGitter>
<j8r> @asterite yep, not the same
<FromGitter>
<mattrberry> Gotcha, thanks for the info @asterite! I got my macro working without having to change the client code, I just had to push a couple of the compile-time error messages into the runtime