Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpreter: support Tuple#[] with range literals #11783

Conversation

HertzDevil
Copy link
Contributor

This is necessary to compile (not run) most of the specs because Spec depends on the methods in src/humanize.cr where this feature is used. I am not very satisfied with the way the indexer on non-metaclass tuples works, but the offset calculations are necessary because of alignment issues. Given:

a = {1_i8, 2_i8, 4_i8, 8_i8, 16_i32}
b = a[3..] # => {8_i8, 16_i32}

here we cannot simply move a's last 5 bytes to the beginning, because there must be padding between b's two elements.

Comment on lines +1426 to +1429
tuple_copy_element: {
operands: [tuple_size : Int32, old_offset : Int32, new_offset : Int32, element_size : Int32],
code: (stack - tuple_size + new_offset).copy_from(stack - tuple_size + old_offset, element_size),
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it wouldn't make sense to define a copy_from instruction that doesn't advance the stack, or maybe as an argument to the existing copy_from. That way we don't keep adding instructions, and maybe we end up with a more general-purpose instruction. Totally optional, though!

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you! ❤️

@straight-shoota straight-shoota added this to the 1.4.0 milestone Jan 31, 2022
@straight-shoota straight-shoota merged commit b5c4d4e into crystal-lang:master Feb 1, 2022
@HertzDevil HertzDevil deleted the feature/i-tuple-range-indexer branch February 2, 2022 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants