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
From IRC (bridge bot)
@FromIRC
<Guest64> as a side question: is there a cleaner way to create default args
<Guest64> from a splat of types for a macro? for example if *types contains
<Guest64> {Int32, Int32}, when the macro defines a definition i use: def my_def({%
<Guest64> for type, index in args %}arg{{index}} : {{type}},{% end %}) which
<Guest64> expands to def my_def(arg0 : Int32, arg1 : Int32)
George Dietrich
@Blacksmoke16
You can append them to a constant, then iterate over it in a finished hook
But im not really sure you need a macro here, versus just a method and hash of procs
Lance Dillon
@riffraff169
yeah, just create a dispatch table....hash key being name, value being proc, then call the proc when a key matches
could even have it be a list of procs, that can be called in order... and can change them dynamically if needed... basically like hooks
From IRC (bridge bot)
@FromIRC
<Guest64> i was thinking something similar as well. i may be able to make a hash of string, proc() work to my liking
<Guest64> thanks for the ideas
Kirk Haines
@wyhaines
@guest64 Macros create code in the place where the macro is called. Also, macros can not call other macros -- they look like methods, but they aren't really methods. However, macros do have access to constants. So you could have your first macro, the one that defines a proc, inject data into a constant that a later macro, involved with the case statement creation, accesses to build said case statement.
From IRC (bridge bot)
@FromIRC
<Guest64> thanks for the advice, im trying to use a hash to contain my map of String, Proc, but while trying to add my procs to the hash I get this error:
<Guest64> ProcMap = Hash(String, Proc).new
<Guest64> Error: can't use Proc(T, R) as generic type argument yet, use a more specific type
George Dietrich
@Blacksmoke16
you need to type your proc
Proc(String, Int32) e.g. if it accepts a string an returns an int32
From IRC (bridge bot)
@FromIRC
<Guest64> each proc has diufferent types, how can i make that work with the hash
<Guest64> IE each proc added to the hash do not share the same definition
George Dietrich
@Blacksmoke16
that's going to be painful
what are these procs used for?
From IRC (bridge bot)
@FromIRC
<Guest64> thats hard to explain without going into depth of the project. the procs are basically synonyms of existing libc functions which their pointer address is returned back to the dynamic linker during the binding stage to determine which function symbol points to which function
George Dietrich
@Blacksmoke16
might be able to wrap these procs in structs
somethign like
abstract struct Callable
end

struct Proc1 < Callable
  def call # define args/return type
  end
end

struct Proc2 < Callable
  def call # define args/return type
  end
end

hash = Hash(String, Callable).new
the gist of it is that you cant have a hash with type of Proc, would need to specify the types of procs that can be in the hash
i suppose technically the macro approach you wanted to take would work around this by defining a hash literal, which would essentially type itself
From IRC (bridge bot)
@FromIRC
<Guest64> hmm, wrapping the procs inside a struct might work. i never thought of that
<Guest64> could you expand more on this hash literal you speak of?
George Dietrich
@Blacksmoke16
the type of literal hashes are inferred based on the values in the literal
but hashes with a lot of unioned types is kinda meh
From IRC (bridge bot)
@FromIRC
<Guest64> yea thats probably going to be messy since these procs vary in arguments from 0 to 6 with various types ranging from simply ints up to pointers to structs
<Guest64> although thats neat that works like that. ill keep that in mind
From IRC (bridge bot)
@FromIRC
<Guest64> @Blacksmoke16: I am having a bit of trouble implementing a simple test for your callable suggest: https://play.crystal-lang.org/#/r/biyo im probably not doing this right at all heh
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.