Skip to content

Commit ef7e4c7

Browse files
committed
Unaligned bit arrays on the JavaScript target
1 parent 7914051 commit ef7e4c7

8 files changed

+498
-303
lines changed

.github/workflows/ci.yml

+24-3
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,23 @@ jobs:
3838
strategy:
3939
fail-fast: false
4040
matrix:
41+
gleam_version: ["1.6.0", "nightly"]
4142
node_version: ["18.20", "20.16", "22.5"]
4243
steps:
4344
- uses: actions/checkout@v4
4445
- uses: erlef/setup-beam@v1
4546
with:
4647
otp-version: "27.0"
47-
gleam-version: "1.6.0"
48+
gleam-version: ${{ matrix.gleam_version }}
49+
version-type: strict
4850
- uses: actions/setup-node@v4
4951
with:
5052
node-version: ${{ matrix.node_version }}
53+
54+
# Disable tests involving unaligned bit arrays when not on nightly
55+
- if: matrix.gleam_version != 'nightly'
56+
run: rm test/gleam/*_unaligned_test.gleam
57+
5158
- run: gleam test --target javascript --runtime node
5259

5360
test_javascript_bun:
@@ -56,16 +63,23 @@ jobs:
5663
strategy:
5764
fail-fast: false
5865
matrix:
66+
gleam_version: ["1.6.0", "nightly"]
5967
bun_version: ["1.1"]
6068
steps:
6169
- uses: actions/checkout@v4
6270
- uses: erlef/setup-beam@v1
6371
with:
6472
otp-version: "27.0"
65-
gleam-version: "1.6.0"
73+
gleam-version: ${{ matrix.gleam_version }}
74+
version-type: strict
6675
- uses: oven-sh/setup-bun@v2
6776
with:
6877
bun-version: ${{ matrix.bun_version }}
78+
79+
# Disable tests involving unaligned bit arrays when not on nightly
80+
- if: matrix.gleam_version != 'nightly'
81+
run: rm test/gleam/*_unaligned_test.gleam
82+
6983
- run: gleam test --target javascript --runtime bun
7084

7185
test_javascript_deno:
@@ -74,14 +88,21 @@ jobs:
7488
strategy:
7589
fail-fast: false
7690
matrix:
91+
gleam_version: ["1.6.0", "nightly"]
7792
deno_version: ["1.45"]
7893
steps:
7994
- uses: actions/checkout@v4
8095
- uses: erlef/setup-beam@v1
8196
with:
8297
otp-version: "27.0"
83-
gleam-version: "1.6.0"
98+
gleam-version: ${{ matrix.gleam_version }}
99+
version-type: strict
84100
- uses: denoland/setup-deno@v1
85101
with:
86102
deno-version: ${{ matrix.deno_version }}
103+
104+
# Disable tests involving unaligned bit arrays when not on nightly
105+
- if: matrix.gleam_version != 'nightly'
106+
run: rm test/gleam/*_unaligned_test.gleam
107+
87108
- run: gleam test --target javascript --runtime deno

CHANGELOG.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
## Unreleased
44

5-
- The performance of `dict.is_empty` has been improved.
6-
7-
## v0.54.0 - 2025-02-04
8-
95
- The `uri` module gains the `empty` value, representing an empty URI which
106
equivalent to `""`.
7+
- The performance of `dict.is_empty` has been improved.
8+
- Unaligned bit arrays on the JavaScript target are now supported by the
9+
functions in the `bit_array` module. Note: Gleam >= v1.9 is required to use
10+
unaligned bit arrays on the JavaScript target.
1111

1212
## v0.54.0 - 2025-02-04
1313

src/gleam/bit_array.gleam

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,20 @@ pub fn from_string(x: String) -> BitArray
1313
/// Returns an integer which is the number of bits in the bit array.
1414
///
1515
@external(erlang, "erlang", "bit_size")
16-
pub fn bit_size(x: BitArray) -> Int {
17-
byte_size(x) * 8
18-
}
16+
@external(javascript, "../gleam_stdlib.mjs", "bit_array_bit_size")
17+
pub fn bit_size(x: BitArray) -> Int
1918

2019
/// Returns an integer which is the number of bytes in the bit array.
2120
///
2221
@external(erlang, "erlang", "byte_size")
23-
@external(javascript, "../gleam_stdlib.mjs", "length")
22+
@external(javascript, "../gleam_stdlib.mjs", "bit_array_byte_size")
2423
pub fn byte_size(x: BitArray) -> Int
2524

2625
/// Pads a bit array with zeros so that it is a whole number of bytes.
2726
///
2827
@external(erlang, "gleam_stdlib", "bit_array_pad_to_bytes")
29-
pub fn pad_to_bytes(x: BitArray) -> BitArray {
30-
x
31-
}
28+
@external(javascript, "../gleam_stdlib.mjs", "bit_array_pad_to_bytes")
29+
pub fn pad_to_bytes(x: BitArray) -> BitArray
3230

3331
/// Creates a new bit array by joining two bit arrays.
3432
///

0 commit comments

Comments
 (0)