Hi, I have an use case where I need to get the offset of a tuple item, that may be different depending on memory alignment, I can detail the use case if necessary.
offsetof
pseudo-method nowadays accept just instance variables as second argument, so, my suggestion is to extend this and in case of Tuples, accept a Int
, to get the offset of the nth item in the tuple.
Similar thing can be done for NamedTuple as well, accepting a symbol or a stringliteral.
Is this feasible? Is there already a way to get the offset of a tuple item and I don’t know?
By what I understood the magic happens only at def visit(node : OffsetOf)
(crystal/main_visitor.cr at master · crystal-lang/crystal · GitHub) and parse_offsetof
(crystal/parser.cr at master · crystal-lang/crystal · GitHub), am I right?
If you guys feel comfortable with the idea I can try to write a patch.