Skip to content

Trying to use a const array instead of char #160

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tmke8
Copy link
Owner

@tmke8 tmke8 commented Jul 6, 2024

No description provided.

@tmke8
Copy link
Owner Author

tmke8 commented Jul 6, 2024

This doesn't really work because the iterator over the input str returns chars, so I'd have to convert them anyway.

@tmke8
Copy link
Owner Author

tmke8 commented Jul 7, 2024

When the lexer is iterating over the input string, I can't assume that all the unicode characters are at most 3-byte. So, I need to accomodate 4-byte characters and might as well use this crate for everything: https://docs.rs/encode_unicode/latest/encode_unicode/

Though, I'm still not completely convinced by the str borrowing in that crate... The tricky operation is re-deriving how many bytes the character needs: https://docs.rs/encode_unicode/1.0.0/src/encode_unicode/utf8_char.rs.html#545-567 (There is actually some interesting discussion in the comments of that function. It seems webassembly does have the mentioned instruction.)

Though, I suppose this must all be much more efficient that converting a char to utf8.

@tmke8
Copy link
Owner Author

tmke8 commented Jul 7, 2024

Assuming the problem with the lexer iterator is solved, there remains the problem of the transform.

Maybe I can add two [u8; 4] together (and abuse overflow to mimick subtraction)? This would be the perfect job for std:simd but that hasn't been stabilized yet :(

    fn add(a: [u8; N], b: [u8; N]) {
        array::from_fn(|i| a[i] + b[i])
    }

likely with std::num::Wrapping to enable intentional wrapping

EDIT: see #161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant