fixed confused shift tokens (I still dont know which side is left)

This commit is contained in:
mlokr 2024-07-21 10:29:58 +02:00
parent 5a6474f066
commit 9af7bf559f
No known key found for this signature in database
GPG key ID: DEA147DDEE644993
4 changed files with 37 additions and 6 deletions

View file

@ -517,3 +517,29 @@ foo := fn(): Foo {
Foo := struct {x: int, y: u32, z: u32} Foo := struct {x: int, y: u32, z: u32}
``` ```
#### sort_something_viredly
```hb
main := fn(): int {
foo := sqrt
return 0
}
sqrt := fn(x: int): int {
temp := 0
g := 0
b := 32768
bshift := 15
loop if b == 0 break else {
bshift -= 1
temp = b + (g << 1)
temp <<= bshift
if x >= temp {
g += b
x -= temp
}
b >>= 1
}
return g
}
```

View file

@ -3247,7 +3247,8 @@ mod tests {
last_module_name = module_name; last_module_name = module_name;
last_start = i + m.len() + module_name.len() + 1; last_start = i + m.len() + module_name.len() + 1;
} }
module_map.push((last_module_name, &input[last_start..])); parser::test::format(ident, input[last_start..].trim());
module_map.push((last_module_name, input[last_start..].trim()));
let loader = |path: &str, _: &str| { let loader = |path: &str, _: &str| {
module_map module_map
@ -3338,5 +3339,6 @@ mod tests {
arrays => README; arrays => README;
struct_return_from_module_function => README; struct_return_from_module_function => README;
comptime_pointers => README; comptime_pointers => README;
sort_something_viredly => README;
} }
} }

View file

@ -98,9 +98,9 @@ pub enum TokenKind {
Dot = b'.', Dot = b'.',
Div = b'/', Div = b'/',
// Unused = 2-6 // Unused = 2-6
Shr = b'<' - 5, Shl = b'<' - 5,
// Unused = 8 // Unused = 8
Shl = b'>' - 5, Shr = b'>' - 5,
Colon = b':', Colon = b':',
Semi = b';', Semi = b';',
Lt = b'<', Lt = b'<',
@ -159,14 +159,14 @@ pub enum TokenKind {
ModAss = b'%' + 128, ModAss = b'%' + 128,
XorAss = b'^' + 128, XorAss = b'^' + 128,
BandAss = b'&' + 128, BandAss = b'&' + 128,
ShlAss = b'0' + 128, ShrAss = b'>' - 5 + 128,
ShrAss = b'1' + 128, ShlAss = b'<' - 5 + 128,
} }
impl TokenKind { impl TokenKind {
pub fn ass_op(self) -> Option<Self> { pub fn ass_op(self) -> Option<Self> {
let id = (self as u8).saturating_sub(128); let id = (self as u8).saturating_sub(128);
if ascii_mask(b"|+-*/%^&01") & (1u128 << id) == 0 { if ascii_mask(b"|+-*/%^&79") & (1u128 << id) == 0 {
return None; return None;
} }
Some(unsafe { std::mem::transmute::<u8, Self>(id) }) Some(unsafe { std::mem::transmute::<u8, Self>(id) })

View file

@ -0,0 +1,3 @@
code size: 357
ret: 0
status: Ok(())