Skip to content

Commit 0ca55ac

Browse files
authored
V4 Pre-release (#43)
* Start on v4 with extension types. * ++ * ++ * ++ * Better tests. * Fix fromHiLo. * ++ * More, fixed a lot of bugs. * Fix JS runtime bugs. * Tweak instructions. * Support running in WASM and AOT. * Tweak CI. * Speed up coverage. * ++ * Cleanup tests a bit. * Fix some tests. * More tests. * ++ * More progress found some bugs. * ++ * ++ * ++ * ++ * Full test coverage. * ++ * ++ * ++
1 parent d302bc5 commit 0ca55ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+13060
-3684
lines changed

.github/workflows/check.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Check
2+
3+
on:
4+
# Post-submit.
5+
push:
6+
branches: [ main ]
7+
8+
# Pre-submit.
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/[email protected]
17+
- uses: dart-lang/[email protected]
18+
- uses: actions/setup-node@v4
19+
- uses: browser-actions/setup-chrome@v1
20+
- run: dart pub get
21+
- run: dart format --output none --set-exit-if-changed .
22+
- run: dart analyze
23+
- run: dart test -P all
24+
- run: ./chore coverage -- -P coverage
25+
- name: Upload coverage
26+
uses: coverallsapp/[email protected]
27+
with:
28+
github-token: ${{ secrets.GITHUB_TOKEN }}
29+
path-to-lcov: coverage/lcov.info

.github/workflows/dart.yml

-25
This file was deleted.

.github/workflows/deploy.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Deploy
2+
3+
on:
4+
# Post-submit.
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/[email protected]
13+
- uses: dart-lang/[email protected]
14+
- run: dart pub get
15+
- name: Build API Docs
16+
run: ./chore dartdoc
17+
- name: Deploy to GitHub Pages
18+
uses: peaceiris/actions-gh-pages@v4
19+
with:
20+
github_token: ${{ secrets.GITHUB_TOKEN }}
21+
publish_dir: ./doc/api

.gitignore

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
.dart_tool/
2-
.packages
3-
.vscode/
2+
doc/api/
43
coverage/
5-
# https://github.com/pulyaevskiy/test-coverage/issues/15
6-
coverage_badge.svg
7-
test/.test_coverage.dart
84
pubspec.lock
5+
out.js*

CHANGELOG.md

+81-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,83 @@
11
# CHANGELOG
22

3+
## 4.0.0-alpha
4+
5+
> [!IMPORTANT]
6+
> Version 4.0.0 has a _large_ set of breaking changes, including removing the
7+
> vast majority of extension methods and boxed classes, in favor of using the
8+
> newer _extension types_ feature in Dart. I would be opening to adding back
9+
> some deprecated methods, or a `lib/compat.dart` file if there is demand;
10+
> please [file an issue][] if you need this.
11+
12+
[file an issue]: https://github.com/matanlurey/binary.dart/issues
13+
14+
**New features**:
15+
16+
Lots and lots. It will be easier to just read the API documentation.
17+
18+
**Breaking changes:**
19+
20+
_Basically everything_. The entire API has been restructured to use extension
21+
types, and some APIs removed entirely that were either not well-thought out
22+
(_oops_) or were unnecessary:
23+
24+
- `Integral`, which was a base type for defining integers, has been removed in
25+
favor of a helper class, `IntDescriptor`, which is used to define new integer
26+
types, and acts sort of a meta type or poor man's macro for defining features:
27+
28+
```diff
29+
- class Int4 extends Integral<Int4> {
30+
- Int4(int value) : super.checked(value, signed: true, size: 4);
31+
-
32+
- @override
33+
- Int4 wrapSafeValue(int value) => Int4(value);
34+
- }
35+
36+
+ extension type const Int4._(int _) implements FixedInt {
37+
+ static const _descriptor = _IntDescriptor<Int8>.signed(
38+
+ Int4.fromUnchecked,
39+
+ width: 4,
40+
+ max: 7,
41+
+ );
42+
+
43+
+ factory Int4(int v) => _descriptor.fit(v);
44+
+
45+
+ // ...
46+
+ }
47+
```
48+
49+
In practice, it is much more difficult to implement a custom type, as many
50+
methods have to be hand-written, but it is also a much better future-proof
51+
approach. In the near-term, it's possible we could expose the code generator
52+
used by this package internally as a tool for others to use, and longer-term
53+
[Dart macros](https://dart.dev/language/macros) can be used to simplify this
54+
process for users.
55+
56+
- Fixed-size integers still exist, but with an updated API. Replacements are a
57+
follows:
58+
59+
- `.bitChunk(l, r)` -> `.chunk(l, [s?])`
60+
- `.bitRange(l, r)` -> `.slice(l, [r?])`
61+
- `.bitsSet` -> `.countOnes()`
62+
- `.clearBit(n)` -> `.setNthBit(n, false)`
63+
- `.getBit(n)` -> `.nthBit(n)` or `operator [n]`
64+
- `.replaceBitRange(l, r, b)` -> `.replace(l, r?, b)`
65+
- `.rotateLeftShift(n)` -> `.rotateLeft(n)`
66+
- `.rotateRightShift(n)` -> `.rotateRight(n)`
67+
- `.setBit(n)` -> `.setNthBit(n)`
68+
- `.signExtend(n)` -> _removed_.
69+
- `.size` has been removed in favor of a static `.width`; as extension types
70+
are non-virtual.
71+
- `.toggleBit(n)` -> `.toggleNthBit(n)`
72+
- `.value` -> `.toInt()`
73+
74+
- The extension methods `BinaryInt` were removed. Instead, use the extension
75+
types directly. A small subset of helper methods are available on
76+
`IntExtension` but have little in common with the previous API (mostly
77+
convenience methods).
78+
79+
- Every other extension method set was removed.
80+
381
## 3.0.1
482

583
- Downgrade [meta](https://pub.dev/packages/meta) version to [v1.7.0](https://pub.dev/packages/meta/versions/1.7.0) for Flutter compatibility.
@@ -16,7 +94,7 @@ _Special thanks to <https://github.com/leynier> for driving this update!_
1694

1795
## 2.0.0
1896

19-
### Highlights
97+
**Highlights**:
2098

2199
Added limited support for operations on integer values that exceed 32-bits.
22100
Before `2.0.0` most of the methods provided by this package had undefined
@@ -40,7 +118,7 @@ assumed to have _undefined behavior_ when compiled to JavaScript.
40118

41119
> Tip: Don't want to consider all of that? You can always just use `Uint32`!
42120
43-
### Operating on Larger Ints
121+
**Operating on Larger Ints**:
44122

45123
Added `<int>.hiLo()`, which returns a fixed 2-length `Uint32List` where
46124
element 0 is the "hi" (upper bits) and element 1 is the "lo" (lower bits).
@@ -61,7 +139,7 @@ future release, but you may also try using these other implemntations:
61139
- [BigInt](https://api.dart.dev/stable/2.8.4/dart-core/BigInt-class.html)
62140
- [Int64](https://pub.dev/documentation/fixnum/latest/fixnum/Int64-class.html)
63141

64-
### Additional changes
142+
**Additional Changes:**
65143

66144
- Added `<int>.pow(n)`, which is like `<dart:math>.pow` with a return of `int`.
67145
- Added `<Integral>.signExtend(startSize)`.

Makefile

-13
This file was deleted.

0 commit comments

Comments
 (0)