Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 08:23
    caspiano edited #10531
  • Dec 08 23:04
    HertzDevil edited #12623
  • Dec 08 22:57
    Blacksmoke16 edited #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:57
    Blacksmoke16 labeled #9745
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil labeled #12828
  • Dec 08 22:54
    HertzDevil opened #12828
  • Dec 08 22:34
    straight-shoota edited #12827
  • Dec 08 22:32
    straight-shoota edited #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota labeled #12827
  • Dec 08 22:29
    straight-shoota opened #12827
  • Dec 08 22:15
    straight-shoota closed #12814
  • Dec 08 17:12
    straight-shoota assigned #12814
  • Dec 08 17:12
    straight-shoota assigned #12813
  • Dec 08 17:12
    straight-shoota assigned #12809
  • Dec 08 17:12
    straight-shoota assigned #12802
  • Dec 08 17:12
    straight-shoota assigned #12797
  • Dec 08 17:12
    straight-shoota assigned #12664
George Dietrich
@Blacksmoke16
prob not going to be that easy when you add more, as the compiler wont be able to guarantee that the value returned from the hash has that method with those arguments
From IRC (bridge bot)
@FromIRC
<Guest64> hmm yes, i will have to ponder about that. thanks for the assistance
George Dietrich
@Blacksmoke16
are the string keys anything significant?
Kirk Haines
@wyhaines
Yeah, it won't work once you add a second struct.
From IRC (bridge bot)
@FromIRC
<Guest64> the string keys are just a way to fetch the correct proc pointer from the hash to return to the dynamic linker. the dynamic linker actually gives me a char*, but i convert it to a string for use.
Kirk Haines
@wyhaines
I've been down this road when I built my #send implementation. :)
From IRC (bridge bot)
@FromIRC
<Guest64> if it matters im attempting to implement rtld-audit for fun and experience: https://man7.org/linux/man-pages/man7/rtld-audit.7.html
George Dietrich
@Blacksmoke16
From IRC (bridge bot)
@FromIRC
<Guest64> i have everything working, im just testing new theories and ways to generate code
George Dietrich
@Blacksmoke16
if the strings are just a way to know what the proc is, you can make the proc's class the key of the hash
could also ofc have a #get method that returns the related Callable instance that you could then directly invoke #call on
but i just combined them into 1 method
Kirk Haines
@wyhaines
Yeah. You can't get away from storing the class/type of Proc or Struct somewhere, in some form.
From IRC (bridge bot)
@FromIRC
<Guest64> random question: is there a way for crystal to expand macros in other files, then move the expanded code into another file for use? if that makes any sense.
From IRC (bridge bot)
@FromIRC
<Guest64> i wish there was better docs for macros somewhere. it seems to have all these cool features but i cant make heads or tails of them
George Dietrich
@Blacksmoke16
you already asked this and we answered it twice :P
From IRC (bridge bot)
@FromIRC
<Guest64> ha, i suppose i did, my bad
George Dietrich
@Blacksmoke16
i will say that mutable constant approach is kinda a smell
im still of the opinion you dont even need a macro
From IRC (bridge bot)
@FromIRC
<Guest64> i guess the problem i am trying to solve is that i have all these function prototypes that vary radically, but the internal body consists mostly of the same method calls plus a bit of dynamic logic based on the function being called, hence the yeild in the macro. i think in the end i was just exploring different options so that i did not have to
<Guest64> write boilerplate 50+ times
Kirk Haines
@wyhaines

A macro generates code only in the location in which it is executed.

However.....you can make what you want to do work with macros.

Macros have access to constants.

So, if you generate all of your procs, assigned to a constant name, under a common namespace, then in your main.cr you can iterate over
that namespace (see Crystal::Maros::TypeNode in the Crystal API docs), find the names of all of your Proc constants, and build your master hash.

George Dietrich
@Blacksmoke16
i.e. in the previous example the logic that was like arg0 + arg1 is the stuff thats unique per proc? but there is also common logic between them all?
From IRC (bridge bot)
@FromIRC
<Guest64> yes corrent, a fair bit of common logic
<Guest64> im reading https://crystal-lang.org/api/1.0.0/Crystal/Macros/TypeNode.html atm like wyhaines suggested
Kirk Haines
@wyhaines
TypeNode just shows you what you have access to within a TypeNode. i.e. #constants, so you can iterate constants.
George Dietrich
@Blacksmoke16
Kirk Haines
@wyhaines
The fact that macros have access to constants means that you can use them to store and gather information from a wide variety of locations, and use it in a central location.
George Dietrich
@Blacksmoke16
auto registers proc types in the collection type, and shows how you can do before/after logic
can remove the #register method then too
From IRC (bridge bot)
@FromIRC
<Guest64> wait i am a bit confised here. you can use {% %} and {{ }} outside of a macro def block?
George Dietrich
@Blacksmoke16
yes, this is also macro code
macro some_name are reusable portions of macro code, but you can also use the macro code outside of them
the end result is the same. Code generated by the macro code is included where it's called as if you manually typed it
From IRC (bridge bot)
@FromIRC
<Guest64> okay, that is pretty cool now, im starting to understand this system a bit more
<Guest64> thanks for the aid
George Dietrich
@Blacksmoke16
Np
From IRC (bridge bot)
@FromIRC
<Guest64> wynhaines: just to circle back on what you said. if i define a proc with a constant such as MY_PROC = -> (){}, if i used {% Proc.constants %} I should be returned an array of all constants that contain a proc?
George Dietrich
@Blacksmoke16
no
From IRC (bridge bot)
@FromIRC
<Guest64> im just trying to understand the macros and typenode system as a whole now, outside of my project
George Dietrich
@Blacksmoke16
sec
George Dietrich
@Blacksmoke16
you're basically mutating the value of a constant at compile time
which you could then later iterate over in other macro code
George Dietrich
@Blacksmoke16
However at this point, it has less use cases with the introduction of annotations
From IRC (bridge bot)
@FromIRC
<Guest64> @Blacksmoke16: yea your example makes sense, but i was referring to when wynhaines said that you can use #constants to iterate constants