You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Count leading zeros can't be used at compile time. This is actually part of #933. This blocks a lot of other work to fully support unicode due to it needing this function.
part of the error: note: LLVM intrinsic operand has unknown value: #pop<simd 15> : !pop.scalar<ui8>
from bit import count_leading_zeros
fn_utf8_first_byte_sequence_length(b: Byte) -> Int:
"""Get the length of the sequence starting with given byte. Do note that this does not work correctly if given a continuation byte."""
debug_assert(
(b &0b1100_0000) !=0b1000_0000,
"Function does not work correctly if given a continuation byte.",
)
returnint(count_leading_zeros(~b)) +int(b <0b1000_0000)
fnmain():
print(_utf8_first_byte_sequence_length(ord("a")) ==1)
print(_utf8_first_byte_sequence_length("🔥".as_bytes()[0]) ==4)
alias `🔥`="🔥".as_bytes()[0]
aliaslength= _utf8_first_byte_sequence_length(`🔥`)
print(length ==4)
System information
- Provide version information for Mojo by pasting the output of `mojo -v``mojo 24.6.0.dev2024120805`
The text was updated successfully, but these errors were encountered:
Why would this not be planned? we need Unicode support in StringLiteral. And the StringSlice iterator uses this function, and many other things that users will want to run at compile time.
Unless we get a way to branch when the code is running at compile time, this is needed
PS: I'm not saying I want this tomorrow, but it should be on the roadmap to at least provide alternatives (like a boolean when running code at compile time) for these cases.
Bug description
Count leading zeros can't be used at compile time. This is actually part of #933. This blocks a lot of other work to fully support unicode due to it needing this function.
part of the error:
note: LLVM intrinsic operand has unknown value: #pop<simd 15> : !pop.scalar<ui8>
CC: @lattner
Steps to reproduce
System information
The text was updated successfully, but these errors were encountered: