Skip to content

Commit

Permalink
Support more bit array options for ints and floats on JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-viney committed Jul 1, 2024
1 parent 9bc0d79 commit 55d0cd5
Show file tree
Hide file tree
Showing 44 changed files with 1,246 additions and 204 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
Unsupported feature for Javascript since they would already cause
a runtime error on Javascript.

This means if you compile specifically for Javascript you will now recieve
This means if you compile specifically for Javascript you will now receive
this error:

```
Expand Down Expand Up @@ -132,6 +132,11 @@
- When compiling to JavaScript constants will now be annotated as `@__PURE__`.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- The `little` and `big` endianness options, the `signed` and `unsigned` integer
options, and sized floats (32-bit and 64-bit), can now be used in bit array
expressions and patterns on the JavaScript target.
([Richard Viney](https://github.com/richard-viney))

### Formatter

### Language Server
Expand Down
2 changes: 1 addition & 1 deletion compiler-core/src/bit_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where
}
}

// Endianness is only valid for int, utf6, utf32 and float
// Endianness is only valid for int, utf16, utf32 and float
match categories {
SegmentOptionCategories {
typ: None | Some(Int { .. } | Utf16 { .. } | Utf32 { .. } | Float { .. }),
Expand Down
3 changes: 2 additions & 1 deletion compiler-core/src/javascript.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod endianness;
mod expression;
mod import;
mod pattern;
Expand Down Expand Up @@ -167,7 +168,7 @@ impl<'a> Generator<'a> {
};

if self.tracker.float_bit_array_segment_used {
self.register_prelude_usage(&mut imports, "float64Bits", None);
self.register_prelude_usage(&mut imports, "sizedFloat", None);
};

// Put it all together
Expand Down
11 changes: 11 additions & 0 deletions compiler-core/src/javascript/endianness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[derive(Debug, PartialEq)]
pub enum Endianness {
Big,
Little,
}

impl Endianness {
pub fn is_big(&self) -> bool {
*self == Endianness::Big
}
}
Loading

0 comments on commit 55d0cd5

Please sign in to comment.