From e835fc0058f97a25675ad21b68de8677dac907b8 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Sat, 31 Oct 2026 04:13:38 -0700 Subject: [PATCH 1/3] chore(quest): claim quest/m3/ts-saturating.md Quest-Claim: 092385aa9067e2f4 From 9ebe6bb4b77ab74e62bbfd858c32b0781ddb74ad Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Sat, 31 Oct 2026 04:33:38 -0700 Subject: [PATCH 2/3] feat(ts): translate Saturating with its std impls Saturating shares Wrapping's lowering through an Overflow mode. Integer saturating_div and saturating_neg, and NonZero's saturating_add, saturating_mul, and saturating_neg translate too. Co-Authored-By: Claude Opus 5.5 --- quest/m3/README.md | 2 +- quest/m3/ts-int-methods.md | 20 + quest/m3/ts-saturating.md | 17 - ts/README.md | 3 +- ts/fixtures/lang/caller.ts | 30 +- ts/fixtures/lang/expected/harness.ts | 3 +- ts/fixtures/lang/expected/lib.ts | 49 + ts/fixtures/lang/expected/saturates.Gauge.ts | 278 ++ ts/fixtures/lang/expected/saturates.ts | 2576 ++++++++++++++++++ ts/fixtures/lang/src/harness.rs | 16 +- ts/fixtures/lang/src/lib.rs | 1 + ts/fixtures/lang/src/saturates.rs | 218 ++ ts/fixtures/reject/census.md | 11 +- ts/fixtures/reject/expected.txt | 1 + ts/fixtures/reject/src/lib.rs | 5 + ts/fixtures/reject/ts.toml | 1 + ts/runtime/rt/int.ts | 12 + ts/src/lower/body.rs | 2 +- ts/src/lower/collections.rs | 20 +- ts/src/lower/copy.rs | 14 +- ts/src/lower/drop.rs | 15 +- ts/src/lower/fmt.rs | 6 +- ts/src/lower/iter.rs | 20 +- ts/src/lower/library.rs | 69 +- ts/src/lower/mir/call.rs | 7 +- ts/src/lower/mir/place.rs | 1 + ts/src/lower/mir/rvalue.rs | 2 +- ts/src/lower/mod.rs | 2 + ts/src/lower/num.rs | 58 +- 29 files changed, 3361 insertions(+), 98 deletions(-) create mode 100644 quest/m3/ts-int-methods.md delete mode 100644 quest/m3/ts-saturating.md create mode 100644 ts/fixtures/lang/expected/saturates.Gauge.ts create mode 100644 ts/fixtures/lang/expected/saturates.ts create mode 100644 ts/fixtures/lang/src/saturates.rs diff --git a/quest/m3/README.md b/quest/m3/README.md index 3d7046444..37e079467 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -28,10 +28,10 @@ generic std gap is planned here even when moq never calls it. - [A deque's two slices](/quest/m3/ts-deque-slices.md) - `VecDeque::as_slices` and `{:?}` of a deque's `Iter`, `IterMut`, and `Drain` translate, split where std's are - [ptr::replace whose result nothing reads](/quest/m3/ts-ptr-replace-unread.md) - `ptr::replace` with its result discarded type-checks - [LinkedList](/quest/m3/ts-linked-list.md) - `LinkedList` and its methods translate -- [Saturating](/quest/m3/ts-saturating.md) - `Saturating` and its std impls translate - [Zip's next_back in constant time](/quest/m3/ts-zip-back.md) - a reversed zip of random-access iterators skips the longer side's excess at once - [A B-tree's collect by std's sort and dedup](/quest/m3/ts-btree-collect-order.md) - collecting into a B-tree keeps the keys std's does when a key's impls disagree - [A tuple's cmp typed as total](/quest/m3/ts-cmp-tuple-total.md) - `rt.cmpTuple` of total fields types its result as `Ordering` - [Slices split by a predicate](/quest/m3/ts-slice-split.md) - `[T]::split` and its forms by a predicate translate - [Boxed slices](/quest/m3/ts-boxed-slices.md) - `Box<[T]>` translates, made, read, and turned back into a `Vec` - [collect into tuples of collections](/quest/m3/ts-collect-tuples.md) - `collect` into a tuple of collections translates +- [Integers' inherent methods](/quest/m3/ts-int-methods.md) - `pow`, `abs`, and the other inherent methods of integers, `NonZero`, `Wrapping`, and `Saturating` translate diff --git a/quest/m3/ts-int-methods.md b/quest/m3/ts-int-methods.md new file mode 100644 index 000000000..f685d2b51 --- /dev/null +++ b/quest/m3/ts-int-methods.md @@ -0,0 +1,20 @@ +# [M] Integers' inherent methods + +## Goal + +[rust2-ts](/ts/README.md) translates the inherent methods of every integer width and of +`NonZero`, `Wrapping`, and `Saturating` of one with std's semantics, proven by differential +tests against native Rust at both bounds of each width. + +## Plan + +Found auditing `Saturating`: each of these refuses as "unsupported call", with its span: +`pow`, `abs`, `signum`, and the `checked_`, `wrapping_`, `saturating_`, and `overflowing_` +forms the runtime lacks, such as `wrapping_neg`, `saturating_pow`, and `saturating_abs`; +`NonZero`'s `saturating_pow` and `saturating_abs`; and `Wrapping`'s and `Saturating`'s own +`pow`, `abs`, `signum`, `count_ones`, `rotate_left`, `swap_bytes`, and the rest, which are +their integer's. The table of integer methods in `ts/src/lower/library.rs` is where each +goes; a wrapper's method is its integer's on the value it holds. No consumer calls them +yet; they are planned here as part of std. + +Public API: the translator's output. diff --git a/quest/m3/ts-saturating.md b/quest/m3/ts-saturating.md deleted file mode 100644 index d8d10d70c..000000000 --- a/quest/m3/ts-saturating.md +++ /dev/null @@ -1,17 +0,0 @@ -# [S] Saturating - -## Goal - -[rust2-ts](/ts/README.md) translates `std::num::Saturating` with std's impls: its -operators, which saturate at the type's bounds, its `Debug` and `Display`, and its -`PartialEq`, `PartialOrd`, `Ord`, and `Hash`, which are its value's, proven by -differential tests against native Rust. - -## Plan - -Found auditing std types' orderings: `Saturating(a).cmp(&Saturating(b))` refuses as -"constructing `std::num::Saturating` from another crate", before its `cmp` is reached. -`Wrapping` already translates as the value it holds, with std's impls; `Saturating` can -follow it. No consumer calls it yet; it is planned here as part of std. - -Public API: the translator's output. diff --git a/ts/README.md b/ts/README.md index 88c140fcd..57df6bdcd 100644 --- a/ts/README.md +++ b/ts/README.md @@ -82,6 +82,7 @@ crate translation reaches is refused, and so are two versions of one crate it re | `u8`-`u32`, `i8`-`i32`, `usize`, `isize` | `rt.u8` and so on: a `number` branded with its type, checked: overflow panics | | `u64`, `i64`, `u128`, `i128` | `rt.u64` and so on: a branded `number` while a safe integer, 32-bit limbs past 2^53, checked the same way | | `Wrapping` | the integer, whose operators wrap, and mask a shift's amount to the width, as std's do | +| `Saturating` | the integer, whose operators saturate at its bounds, as std's do | | `f64` | `rt.f64`: a `number` branded so, which is the same IEEE 754 double | | `f32` | `rt.f32`: a `number` branded so, which a single holds exactly | | `()`, `PhantomData`, `PhantomPinned`, `..` | `undefined`, every value equal and hashing nothing; a type parameter only a `PhantomData` holds is `_T` in its struct's interface | @@ -755,7 +756,7 @@ built natively for wasm32 and run beside its translation on the same inputs by Bun bundles a caller of `Decoder.u8` and `Decoder.new` through `import * as Decoder`, which must keep only those and what they call. - `lang` covers every integer width's arithmetic and casts, `char`s next to each - encoding's edges and the surrogates, `Cow` and `Cow<[T]>` borrowed and owned, `Wrapping` at every width, `Duration`s whose + encoding's edges and the surrogates, `Cow` and `Cow<[T]>` borrowed and owned, `Wrapping` and `Saturating` at every width, `Duration`s whose seconds pass 2^53 or reach `u64::MAX`, control flow, patterns, `Copy` aggregates, those a container stores included and those written into only in another module, behind a type parameter, or through a box, formatting, methods diff --git a/ts/fixtures/lang/caller.ts b/ts/fixtures/lang/caller.ts index 8d88d2565..1f280e1a6 100644 --- a/ts/fixtures/lang/caller.ts +++ b/ts/fixtures/lang/caller.ts @@ -629,4 +629,32 @@ function wraps(): Uint8Array[] { return cases; } -export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...writes, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods, ...wraps(), ...refOrders]; +/** + * `saturates::*` of every kind at every width, over operands at the edges of its range and + * across them: 0, 1, either end, the sign bit's neighbors, which make `MIN / -1` and + * `MIN % -1`, and at 128 bits values past 2^64. + */ +function saturates(): Uint8Array[] { + const widths: [string, number][] = [["u8s", 8], ["u16s", 16], ["u32s", 32], ["u64s", 64], ["u128s", 128], ["usizes", 32], ["i8s", 8], ["i16s", 16], ["i32s", 32], ["i64s", 64], ["i128s", 128], ["isizes", 32]]; + const cases: Uint8Array[] = []; + for (const [name, bits] of widths) { + const o = op(`saturates::${name}`); + const width = BigInt(bits); + const mask = (1n << width) - 1n; + const sign = 1n << (width - 1n); + const half = sign >> 1n; + const edges = [0n, 1n, 3n, mask, mask - 1n, sign, sign - 1n, sign + 1n, half, half + 1n, mask - half]; + if (bits === 128) edges.push(1n << 64n, (1n << 64n) + 3n, 0x9e3779b97f4a7c150123456789abcdefn); + const be = (v: bigint) => Array.from({ length: bits / 8 }, (_, i) => Number((v >> BigInt(bits - 8 - 8 * i)) & 0xffn)); + let i = 0; + for (const a of edges) { + for (const b of edges) { + const c = edges[(i++ * 5 + 3) % edges.length]; + for (let kind = 0; kind < 24; kind++) cases.push(Uint8Array.of(o, kind, ...be(a), ...be(b), ...be(c))); + } + } + } + return cases; +} + +export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...writes, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods, ...wraps(), ...refOrders, ...saturates()]; diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index eb0e72048..eed2ba86d 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -38,6 +38,7 @@ import { objects } from "./objects.ts"; import { orders, bytes as orders_bytes, held } from "./orders.ts"; import { lists, shared as pointers_shared, places as pointers_places, unchecked, nested as pointers_nested, copies as pointers_copies, sentinels, cells as pointers_cells, rebound as pointers_rebound, lapsed, writers, made as pointers_made, segments, uninitRuns, iteratedRuns } from "./pointers.ts"; import { refs, toRefs } from "./refs.ts"; +import { u8s as saturates_u8s, u16s as saturates_u16s, u32s as saturates_u32s, u64s as saturates_u64s, u128s as saturates_u128s, usizes as saturates_usizes, i8s as saturates_i8s, i16s as saturates_i16s, i32s as saturates_i32s, i64s as saturates_i64s, i128s as saturates_i128s, isizes as saturates_isizes } from "./saturates.ts"; import { copies as shapes_copies, order as shapes_order, discriminants, loops, patterns, uninhabited, closures as shapes_closures, library, flows } from "./shapes.ts"; import { singles, mulAdds as singles_mulAdds, formats as singles_formats, parses as singles_parses } from "./singles.ts"; import { parts as slices_parts, chunked, subslices, drains as slices_drains, ranges as slices_ranges, edits as slices_edits } from "./slices.ts"; @@ -212,7 +213,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) held(data77, out78); }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["joins::joins", joins as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["pointers::iterated_runs", (_2178: rt.u8, data78: rt.ByteSlice, out79: rt.ByteVec): undefined => { iteratedRuns(data78, out79); - }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["zeros::writes", zeros_writes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]]; + }] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["zeros::writes", zeros_writes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u8s", saturates_u8s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u16s", saturates_u16s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u32s", saturates_u32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u64s", saturates_u64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u128s", saturates_u128s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::usizes", saturates_usizes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i8s", saturates_i8s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i16s", saturates_i16s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i32s", saturates_i32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i64s", saturates_i64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i128s", saturates_i128s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::isizes", saturates_isizes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]]; } /** Run one case. */ diff --git a/ts/fixtures/lang/expected/lib.ts b/ts/fixtures/lang/expected/lib.ts index 373ec0408..28aaa3738 100644 --- a/ts/fixtures/lang/expected/lib.ts +++ b/ts/fixtures/lang/expected/lib.ts @@ -30,6 +30,7 @@ import type * as Inner from "./pointers.Inner.ts"; import * as List from "./pointers.List.ts"; import type * as Outer from "./pointers.Outer.ts"; import type * as pointers_Pair from "./pointers.Pair.ts"; +import * as saturates_Gauge from "./saturates.Gauge.ts"; import type * as shapes_Gauge from "./shapes.Gauge.ts"; import type * as shapes_Held from "./shapes.Held.ts"; import type * as Lens from "./shapes.Lens.ts"; @@ -263,6 +264,54 @@ export function copy$pointers_Pair(v: pointers_Pair.Pair): pointers_Pair.Pair { return { a: v.a, b: v.b }; } +export function copy$saturates_Gauge_i128(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_i16(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_i32(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_i64(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_i8(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_isize(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_u128(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_u16(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_u32(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_u64(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_u8(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + +export function copy$saturates_Gauge_usize(v: saturates_Gauge.Gauge): saturates_Gauge.Gauge { + return new saturates_Gauge.Gauge(v._0); +} + export function copy$shapes_Gauge(v: shapes_Gauge.Gauge): shapes_Gauge.Gauge { return { level: v.level }; } diff --git a/ts/fixtures/lang/expected/saturates.Gauge.ts b/ts/fixtures/lang/expected/saturates.Gauge.ts new file mode 100644 index 000000000..0e44d6d4f --- /dev/null +++ b/ts/fixtures/lang/expected/saturates.Gauge.ts @@ -0,0 +1,278 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function fmt$fmt_Debug_i128(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i128Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_i16(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i16Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_i32(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i32Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_i64(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i64Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_i8(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.i8Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_isize(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.isizeDebug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_u128(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u128Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_u16(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u16Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_u32(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u32Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_u64(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u64Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_u8(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.u8Debug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function fmt$fmt_Debug_usize(self: Gauge, f: rt.Formatter): rt.Result { + const _3: string = "Gauge"; + const _4: rt.Fmt = (f: rt.Formatter) => rt.usizeDebug(self._0, f); + return rt.debugTupleFinish(rt.debugTupleField(rt.fmtDebugTuple(f, _3), _4)); +} + +export function default$Default_i128(): Gauge { + return new Gauge(0); +} + +export function default$Default_i16(): Gauge { + return new Gauge(0); +} + +export function default$Default_i32(): Gauge { + return new Gauge(0); +} + +export function default$Default_i64(): Gauge { + return new Gauge(0); +} + +export function default$Default_i8(): Gauge { + return new Gauge(0); +} + +export function default$Default_isize(): Gauge { + return new Gauge(0); +} + +export function default$Default_u128(): Gauge { + return new Gauge(0); +} + +export function default$Default_u16(): Gauge { + return new Gauge(0); +} + +export function default$Default_u32(): Gauge { + return new Gauge(0); +} + +export function default$Default_u64(): Gauge { + return new Gauge(0); +} + +export function default$Default_u8(): Gauge { + return new Gauge(0); +} + +export function default$Default_usize(): Gauge { + return new Gauge(0); +} + +export function eq$cmp_PartialEq_i128(self: Gauge, other: Gauge): boolean { + return rt.i128Eq(self._0, other._0); +} + +export function eq$cmp_PartialEq_i16(self: Gauge, other: Gauge): boolean { + return self._0 === other._0; +} + +export function eq$cmp_PartialEq_i32(self: Gauge, other: Gauge): boolean { + return self._0 === other._0; +} + +export function eq$cmp_PartialEq_i64(self: Gauge, other: Gauge): boolean { + return rt.i64Eq(self._0, other._0); +} + +export function eq$cmp_PartialEq_i8(self: Gauge, other: Gauge): boolean { + return self._0 === other._0; +} + +export function eq$cmp_PartialEq_isize(self: Gauge, other: Gauge): boolean { + return self._0 === other._0; +} + +export function eq$cmp_PartialEq_u128(self: Gauge, other: Gauge): boolean { + return rt.u128Eq(self._0, other._0); +} + +export function eq$cmp_PartialEq_u16(self: Gauge, other: Gauge): boolean { + return self._0 === other._0; +} + +export function eq$cmp_PartialEq_u32(self: Gauge, other: Gauge): boolean { + return self._0 === other._0; +} + +export function eq$cmp_PartialEq_u64(self: Gauge, other: Gauge): boolean { + return rt.u64Eq(self._0, other._0); +} + +export function eq$cmp_PartialEq_u8(self: Gauge, other: Gauge): boolean { + return self._0 === other._0; +} + +export function eq$cmp_PartialEq_usize(self: Gauge, other: Gauge): boolean { + return self._0 === other._0; +} + +export function hash$Hash_i128_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash128(self._0, state); +} + +export function hash$Hash_i16_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash16(self._0, state); +} + +export function hash$Hash_i32_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash32(self._0, state); +} + +export function hash$Hash_i64_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash64(self._0, state); +} + +export function hash$Hash_i8_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash8(self._0, state); +} + +export function hash$Hash_isize_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash32(self._0, state); +} + +export function hash$Hash_u128_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash128(self._0, state); +} + +export function hash$Hash_u16_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash16(self._0, state); +} + +export function hash$Hash_u32_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash32(self._0, state); +} + +export function hash$Hash_u64_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash64(self._0, state); +} + +export function hash$Hash_u8_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash8(self._0, state); +} + +export function hash$Hash_usize_hash_DefaultHasher(self: Gauge, state: rt.Hasher): void { + rt.hash32(self._0, state); +} + +export function cmp$cmp_Ord_i128(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_i16(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_i32(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_i64(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_i8(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_isize(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_u128(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_u16(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_u32(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_u64(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_u8(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +export function cmp$cmp_Ord_usize(self: Gauge, other: Gauge): rt.Ordering { + return rt.cmp(self._0, other._0); +} + +/** A `Saturating` in a field, with each derived impl reading it. */ +export class Gauge { + _0: T; + + constructor(_0: T) { + this._0 = _0; + } +} + +//# sourceMappingURL=saturates.Gauge.ts.map diff --git a/ts/fixtures/lang/expected/saturates.ts b/ts/fixtures/lang/expected/saturates.ts new file mode 100644 index 000000000..26aef8402 --- /dev/null +++ b/ts/fixtures/lang/expected/saturates.ts @@ -0,0 +1,2576 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { copy$saturates_Gauge_i128, copy$saturates_Gauge_i16, copy$saturates_Gauge_i32, copy$saturates_Gauge_i64, copy$saturates_Gauge_i8, copy$saturates_Gauge_isize, copy$saturates_Gauge_u128, copy$saturates_Gauge_u16, copy$saturates_Gauge_u32, copy$saturates_Gauge_u64, copy$saturates_Gauge_u8, copy$saturates_Gauge_usize } from "./lib.ts"; +import { isSomeAnd$08u1px1, unwrapOr$0r2bmpr as option_unwrapOr$0r2bmpr } from "./core/option.ts"; +import * as saturates_Gauge from "./saturates.Gauge.ts"; + +export function hashed$i128(v: rt.i128): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash128(v, h); + return rt.hashFinish(h); +} + +export function hashed$i16(v: rt.i16): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash16(v, h); + return rt.hashFinish(h); +} + +export function hashed$i32(v: rt.i32): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$i64(v: rt.i64): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash64(v, h); + return rt.hashFinish(h); +} + +export function hashed$i8(v: rt.i8): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash8(v, h); + return rt.hashFinish(h); +} + +export function hashed$isize(v: rt.isize): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_i128(v: rt.i128): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash128(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_i16(v: rt.i16): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash16(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_i32(v: rt.i32): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_i64(v: rt.i64): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash64(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_i8(v: rt.i8): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash8(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_isize(v: rt.isize): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_u128(v: rt.u128): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash128(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_u16(v: rt.u16): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash16(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_u32(v: rt.u32): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_u64(v: rt.u64): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash64(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_u8(v: rt.u8): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash8(v, h); + return rt.hashFinish(h); +} + +export function hashed$num_Saturating_usize(v: rt.usize): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_i128(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_i128_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_i16(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_i16_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_i32(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_i32_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_i64(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_i64_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_i8(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_i8_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_isize(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_isize_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_u128(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_u128_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_u16(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_u16_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_u32(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_u32_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_u64(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_u64_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_u8(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_u8_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$saturates_Gauge_usize(v: saturates_Gauge.Gauge): rt.u64 { + const h: rt.Hasher = rt.hasher(); + saturates_Gauge.hash$Hash_usize_hash_DefaultHasher(v, h); + return rt.hashFinish(h); +} + +export function hashed$u128(v: rt.u128): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash128(v, h); + return rt.hashFinish(h); +} + +export function hashed$u16(v: rt.u16): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash16(v, h); + return rt.hashFinish(h); +} + +export function hashed$u32(v: rt.u32): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +export function hashed$u64(v: rt.u64): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash64(v, h); + return rt.hashFinish(h); +} + +export function hashed$u8(v: rt.u8): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash8(v, h); + return rt.hashFinish(h); +} + +export function hashed$usize(v: rt.usize): rt.u64 { + const h: rt.Hasher = rt.hasher(); + rt.hash32(v, h); + return rt.hashFinish(h); +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function u8s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.u8) => undefined = (out2: rt.ByteVec, v: rt.u8): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u8ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u8 = (at: rt.usize): rt.u8 => { + const buf: Uint8Array = Uint8Array.of(0); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u8FromBeBytes(buf); + }; + const _8: [rt.u8, rt.u8, rt.u8] = [take(0), take(1), take(2 * 1)]; + const a: rt.u8 = _8[0]; + const b: rt.u8 = _8[1]; + const c: rt.u8 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part47 = rt.u8SaturatingAdd(a, b); + _20(out, part47); + } else if (_21 === 1) { + const part46 = rt.u8SaturatingSub(a, b); + _20(out, part46); + } else if (_21 === 2) { + const part45 = rt.u8SaturatingMul(a, b); + _20(out, part45); + } else if (_21 === 3) { + _20(out, rt.u8Div(a, b)); + } else if (_21 === 4) { + _20(out, rt.u8Rem(a, b)); + } else if (_21 === 5) { + rt.byteVecPush(out, 0); + } else if (_21 === 6) { + _20(out, ~a & 0xff); + } else if (_21 === 7) { + _20(out, a & b); + } else if (_21 === 8) { + _20(out, a | b); + } else if (_21 === 9) { + _20(out, a ^ b); + } else if (_21 === 10) { + let x: rt.u8 = a; + x = rt.u8SaturatingAdd(x, b); + _20(out, x); + x = rt.u8SaturatingMul(x, c); + _20(out, x); + x = rt.u8SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.u8 = a; + x2 = rt.u8Div(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.u8 = a; + x3 = rt.u8Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.u8 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.u8 = a; + x5 = rt.u8SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.u8SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.u8SaturatingMul(x5, b); + _20(out, x5); + x5 = x5 & c; + x5 = x5 | b; + x5 = x5 ^ c; + _20(out, x5); + x5 = rt.u8Div(x5, b); + _20(out, x5); + x5 = rt.u8Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part17 = rt.u8SaturatingAdd(a, b); + _20(out, part17); + const part18 = rt.u8SaturatingSub(a, b); + _20(out, part18); + const part19 = rt.u8SaturatingMul(a, c); + _20(out, part19); + _20(out, ~b & 0xff); + _20(out, a ^ c); + _20(out, a & b); + _20(out, a | c); + let x6: rt.u8 = a; + x6 = rt.u8SaturatingAdd(x6, b); + x6 = rt.u8SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.u8Rem(a, b)); + _20(out, rt.u8Div(c, b)); + } else if (_21 === 16) { + const _204: boolean = a === b; + const _207: boolean = a !== b; + const _210: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _213: boolean = order !== undefined && order <= 0; + const _216: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_204, _207, _210, _213, _216, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _232: boolean | rt.Done = iter.next(); + if (_232 === rt.DONE) { + break; + } + rt.byteVecPush(out, _232 ? 1 : 0); + } + const part14 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part14); + const part15 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part15); + const _250: rt.u8 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _251: rt.u8 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part16 = rt.ordClamp(a, _250, _251, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part16); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_u8(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_u8(a), hashed$u8(a)) ? 1 : 0); + const _266: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _266, true, undefined, undefined, 1, true)); + while (true) { + const _271: rt.u8 | rt.Done = iter2.next(); + if (_271 === rt.DONE) { + break; + } + _20(out, _271); + } + const _280: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash8, rt.same)) as rt.HashSet, _280, undefined, undefined, 469762048); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u8Display(a, f), (f: rt.Formatter) => rt.u8Debug(b, f), (f: rt.Formatter) => rt.u8LowerHex(a, f), (f: rt.Formatter) => rt.u8UpperHex(b, f), (f: rt.Formatter) => rt.u8Octal(c, f), (f: rt.Formatter) => rt.u8Binary(a, f), (f: rt.Formatter) => rt.u8Display(b, f), (f: rt.Formatter) => rt.u8LowerHex(c, f), (f: rt.Formatter) => rt.u8Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + const all: rt.u8[] = [a, b, c]; + const part8 = rt.iterSum(rt.iterSlice(all), rt.u8SaturatingAdd, 0); + _20(out, part8); + const part9 = rt.iterSum(rt.iterSlice(all), rt.u8SaturatingAdd, 0); + _20(out, part9); + const part10 = rt.iterProduct(rt.iterSlice(all), rt.u8SaturatingMul, 1); + _20(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(all), rt.u8SaturatingMul, 1); + _20(out, part11); + const part12 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u8SaturatingAdd, 0); + _20(out, part12); + const part13 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u8SaturatingMul, 1); + _20(out, part13); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _370: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _370[0]; + const y: saturates_Gauge.Gauge = _370[1]; + const _378: saturates_Gauge.Gauge = saturates_Gauge.default$Default_u8(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u8(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u8(_378, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_u8(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_u8(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_u8(x7), hashed$num_Saturating_u8(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_u8(x7); + z._0 = rt.u8SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _414: [rt.u8 | undefined, rt.u8 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_414[0] !== undefined) { + if (_414[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u8ToBeBytes(rt.u8SaturatingMul(_414[0], _414[1])))); + } + } + const part = rt.u8SaturatingMul(a, b); + _20(out, part); + const part2 = rt.u8SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.u8SaturatingSub(a, b); + _20(out, part3); + _20(out, rt.u8Div(a, b)); + } else { + const _457: rt.u8 | undefined = rt.nonZero(a); + if (_457 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u8ToBeBytes(rt.u8SaturatingAdd(_457, b)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function u16s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.u16) => undefined = (out2: rt.ByteVec, v: rt.u16): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u16ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u16 = (at: rt.usize): rt.u16 => { + const buf: Uint8Array = rt.bytes(2); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u16FromBeBytes(buf); + }; + const _8: [rt.u16, rt.u16, rt.u16] = [take(0), take(2), take(2 * 2)]; + const a: rt.u16 = _8[0]; + const b: rt.u16 = _8[1]; + const c: rt.u16 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part47 = rt.u16SaturatingAdd(a, b); + _20(out, part47); + } else if (_21 === 1) { + const part46 = rt.u16SaturatingSub(a, b); + _20(out, part46); + } else if (_21 === 2) { + const part45 = rt.u16SaturatingMul(a, b); + _20(out, part45); + } else if (_21 === 3) { + _20(out, rt.u16Div(a, b)); + } else if (_21 === 4) { + _20(out, rt.u16Rem(a, b)); + } else if (_21 === 5) { + rt.byteVecPush(out, 0); + } else if (_21 === 6) { + _20(out, ~a & 0xffff); + } else if (_21 === 7) { + _20(out, a & b); + } else if (_21 === 8) { + _20(out, a | b); + } else if (_21 === 9) { + _20(out, a ^ b); + } else if (_21 === 10) { + let x: rt.u16 = a; + x = rt.u16SaturatingAdd(x, b); + _20(out, x); + x = rt.u16SaturatingMul(x, c); + _20(out, x); + x = rt.u16SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.u16 = a; + x2 = rt.u16Div(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.u16 = a; + x3 = rt.u16Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.u16 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.u16 = a; + x5 = rt.u16SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.u16SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.u16SaturatingMul(x5, b); + _20(out, x5); + x5 = x5 & c; + x5 = x5 | b; + x5 = x5 ^ c; + _20(out, x5); + x5 = rt.u16Div(x5, b); + _20(out, x5); + x5 = rt.u16Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part17 = rt.u16SaturatingAdd(a, b); + _20(out, part17); + const part18 = rt.u16SaturatingSub(a, b); + _20(out, part18); + const part19 = rt.u16SaturatingMul(a, c); + _20(out, part19); + _20(out, ~b & 0xffff); + _20(out, a ^ c); + _20(out, a & b); + _20(out, a | c); + let x6: rt.u16 = a; + x6 = rt.u16SaturatingAdd(x6, b); + x6 = rt.u16SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.u16Rem(a, b)); + _20(out, rt.u16Div(c, b)); + } else if (_21 === 16) { + const _204: boolean = a === b; + const _207: boolean = a !== b; + const _210: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _213: boolean = order !== undefined && order <= 0; + const _216: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_204, _207, _210, _213, _216, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _232: boolean | rt.Done = iter.next(); + if (_232 === rt.DONE) { + break; + } + rt.byteVecPush(out, _232 ? 1 : 0); + } + const part14 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part14); + const part15 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part15); + const _250: rt.u16 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _251: rt.u16 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part16 = rt.ordClamp(a, _250, _251, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part16); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_u16(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_u16(a), hashed$u16(a)) ? 1 : 0); + const _266: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _266, true, undefined, undefined, 2, true)); + while (true) { + const _271: rt.u16 | rt.Done = iter2.next(); + if (_271 === rt.DONE) { + break; + } + _20(out, _271); + } + const _280: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash16, rt.same)) as rt.HashSet, _280, undefined, undefined, 469762048); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u16Display(a, f), (f: rt.Formatter) => rt.u16Debug(b, f), (f: rt.Formatter) => rt.u16LowerHex(a, f), (f: rt.Formatter) => rt.u16UpperHex(b, f), (f: rt.Formatter) => rt.u16Octal(c, f), (f: rt.Formatter) => rt.u16Binary(a, f), (f: rt.Formatter) => rt.u16Display(b, f), (f: rt.Formatter) => rt.u16LowerHex(c, f), (f: rt.Formatter) => rt.u16Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + const all: rt.u16[] = [a, b, c]; + const part8 = rt.iterSum(rt.iterSlice(all), rt.u16SaturatingAdd, 0); + _20(out, part8); + const part9 = rt.iterSum(rt.iterSlice(all), rt.u16SaturatingAdd, 0); + _20(out, part9); + const part10 = rt.iterProduct(rt.iterSlice(all), rt.u16SaturatingMul, 1); + _20(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(all), rt.u16SaturatingMul, 1); + _20(out, part11); + const part12 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u16SaturatingAdd, 0); + _20(out, part12); + const part13 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u16SaturatingMul, 1); + _20(out, part13); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _370: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _370[0]; + const y: saturates_Gauge.Gauge = _370[1]; + const _378: saturates_Gauge.Gauge = saturates_Gauge.default$Default_u16(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u16(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u16(_378, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_u16(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_u16(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_u16(x7), hashed$num_Saturating_u16(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_u16(x7); + z._0 = rt.u16SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _414: [rt.u16 | undefined, rt.u16 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_414[0] !== undefined) { + if (_414[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(rt.u16SaturatingMul(_414[0], _414[1])))); + } + } + const part = rt.u16SaturatingMul(a, b); + _20(out, part); + const part2 = rt.u16SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.u16SaturatingSub(a, b); + _20(out, part3); + _20(out, rt.u16Div(a, b)); + } else { + const _457: rt.u16 | undefined = rt.nonZero(a); + if (_457 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u16ToBeBytes(rt.u16SaturatingAdd(_457, b)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function u32s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.u32) => undefined = (out2: rt.ByteVec, v: rt.u32): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u32ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u32 = (at: rt.usize): rt.u32 => { + const buf: Uint8Array = rt.bytes(4); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u32FromBeBytes(buf); + }; + const _8: [rt.u32, rt.u32, rt.u32] = [take(0), take(4), take(2 * 4)]; + const a: rt.u32 = _8[0]; + const b: rt.u32 = _8[1]; + const c: rt.u32 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part47 = rt.u32SaturatingAdd(a, b); + _20(out, part47); + } else if (_21 === 1) { + const part46 = rt.u32SaturatingSub(a, b); + _20(out, part46); + } else if (_21 === 2) { + const part45 = rt.u32SaturatingMul(a, b); + _20(out, part45); + } else if (_21 === 3) { + _20(out, rt.u32Div(a, b)); + } else if (_21 === 4) { + _20(out, rt.u32Rem(a, b)); + } else if (_21 === 5) { + rt.byteVecPush(out, 0); + } else if (_21 === 6) { + _20(out, ~a >>> 0); + } else if (_21 === 7) { + _20(out, (a & b) >>> 0); + } else if (_21 === 8) { + _20(out, (a | b) >>> 0); + } else if (_21 === 9) { + _20(out, (a ^ b) >>> 0); + } else if (_21 === 10) { + let x: rt.u32 = a; + x = rt.u32SaturatingAdd(x, b); + _20(out, x); + x = rt.u32SaturatingMul(x, c); + _20(out, x); + x = rt.u32SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.u32 = a; + x2 = rt.u32Div(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.u32 = a; + x3 = rt.u32Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.u32 = a; + x4 = (x4 & b) >>> 0; + x4 = (x4 | c) >>> 0; + x4 = (x4 ^ b) >>> 0; + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.u32 = a; + x5 = rt.u32SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.u32SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.u32SaturatingMul(x5, b); + _20(out, x5); + x5 = (x5 & c) >>> 0; + x5 = (x5 | b) >>> 0; + x5 = (x5 ^ c) >>> 0; + _20(out, x5); + x5 = rt.u32Div(x5, b); + _20(out, x5); + x5 = rt.u32Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part17 = rt.u32SaturatingAdd(a, b); + _20(out, part17); + const part18 = rt.u32SaturatingSub(a, b); + _20(out, part18); + const part19 = rt.u32SaturatingMul(a, c); + _20(out, part19); + _20(out, ~b >>> 0); + _20(out, (a ^ c) >>> 0); + _20(out, (a & b) >>> 0); + _20(out, (a | c) >>> 0); + let x6: rt.u32 = a; + x6 = rt.u32SaturatingAdd(x6, b); + x6 = rt.u32SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.u32Rem(a, b)); + _20(out, rt.u32Div(c, b)); + } else if (_21 === 16) { + const _204: boolean = a === b; + const _207: boolean = a !== b; + const _210: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _213: boolean = order !== undefined && order <= 0; + const _216: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_204, _207, _210, _213, _216, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _232: boolean | rt.Done = iter.next(); + if (_232 === rt.DONE) { + break; + } + rt.byteVecPush(out, _232 ? 1 : 0); + } + const part14 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part14); + const part15 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part15); + const _250: rt.u32 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _251: rt.u32 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part16 = rt.ordClamp(a, _250, _251, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part16); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_u32(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_u32(a), hashed$u32(a)) ? 1 : 0); + const _266: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _266, true, undefined, undefined, 4, true)); + while (true) { + const _271: rt.u32 | rt.Done = iter2.next(); + if (_271 === rt.DONE) { + break; + } + _20(out, _271); + } + const _280: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash32, rt.same)) as rt.HashSet, _280, undefined, undefined, 234881024); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u32Display(a, f), (f: rt.Formatter) => rt.u32Debug(b, f), (f: rt.Formatter) => rt.u32LowerHex(a, f), (f: rt.Formatter) => rt.u32UpperHex(b, f), (f: rt.Formatter) => rt.u32Octal(c, f), (f: rt.Formatter) => rt.u32Binary(a, f), (f: rt.Formatter) => rt.u32Display(b, f), (f: rt.Formatter) => rt.u32LowerHex(c, f), (f: rt.Formatter) => rt.u32Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + const all: rt.u32[] = [a, b, c]; + const part8 = rt.iterSum(rt.iterSlice(all), rt.u32SaturatingAdd, 0); + _20(out, part8); + const part9 = rt.iterSum(rt.iterSlice(all), rt.u32SaturatingAdd, 0); + _20(out, part9); + const part10 = rt.iterProduct(rt.iterSlice(all), rt.u32SaturatingMul, 1); + _20(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(all), rt.u32SaturatingMul, 1); + _20(out, part11); + const part12 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u32SaturatingAdd, 0); + _20(out, part12); + const part13 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u32SaturatingMul, 1); + _20(out, part13); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _370: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _370[0]; + const y: saturates_Gauge.Gauge = _370[1]; + const _378: saturates_Gauge.Gauge = saturates_Gauge.default$Default_u32(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u32(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u32(_378, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_u32(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_u32(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_u32(x7), hashed$num_Saturating_u32(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_u32(x7); + z._0 = rt.u32SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _414: [rt.u32 | undefined, rt.u32 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_414[0] !== undefined) { + if (_414[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u32SaturatingMul(_414[0], _414[1])))); + } + } + const part = rt.u32SaturatingMul(a, b); + _20(out, part); + const part2 = rt.u32SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.u32SaturatingSub(a, b); + _20(out, part3); + _20(out, rt.u32Div(a, b)); + } else { + const _457: rt.u32 | undefined = rt.nonZero(a); + if (_457 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(rt.u32SaturatingAdd(_457, b)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function u64s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.u64) => undefined = (out2: rt.ByteVec, v: rt.u64): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u64ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u64 = (at: rt.usize): rt.u64 => { + const buf: Uint8Array = rt.bytes(8); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u64FromBeBytes(buf); + }; + const _8: [rt.u64, rt.u64, rt.u64] = [take(0), take(8), take(2 * 8)]; + const a: rt.u64 = _8[0]; + const b: rt.u64 = _8[1]; + const c: rt.u64 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part47 = rt.u64SaturatingAdd(a, b); + _20(out, part47); + } else if (_21 === 1) { + const part46 = rt.u64SaturatingSub(a, b); + _20(out, part46); + } else if (_21 === 2) { + const part45 = rt.u64SaturatingMul(a, b); + _20(out, part45); + } else if (_21 === 3) { + _20(out, rt.u64Div(a, b)); + } else if (_21 === 4) { + _20(out, rt.u64Rem(a, b)); + } else if (_21 === 5) { + rt.byteVecPush(out, 0); + } else if (_21 === 6) { + _20(out, rt.u64Not(a)); + } else if (_21 === 7) { + _20(out, rt.u64And(a, b)); + } else if (_21 === 8) { + _20(out, rt.u64Or(a, b)); + } else if (_21 === 9) { + _20(out, rt.u64Xor(a, b)); + } else if (_21 === 10) { + let x: rt.u64 = a; + x = rt.u64SaturatingAdd(x, b); + _20(out, x); + x = rt.u64SaturatingMul(x, c); + _20(out, x); + x = rt.u64SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.u64 = a; + x2 = rt.u64Div(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.u64 = a; + x3 = rt.u64Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.u64 = a; + x4 = rt.u64And(x4, b); + x4 = rt.u64Or(x4, c); + x4 = rt.u64Xor(x4, b); + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.u64 = a; + x5 = rt.u64SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.u64SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.u64SaturatingMul(x5, b); + _20(out, x5); + x5 = rt.u64And(x5, c); + x5 = rt.u64Or(x5, b); + x5 = rt.u64Xor(x5, c); + _20(out, x5); + x5 = rt.u64Div(x5, b); + _20(out, x5); + x5 = rt.u64Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part17 = rt.u64SaturatingAdd(a, b); + _20(out, part17); + const part18 = rt.u64SaturatingSub(a, b); + _20(out, part18); + const part19 = rt.u64SaturatingMul(a, c); + _20(out, part19); + _20(out, rt.u64Not(b)); + _20(out, rt.u64Xor(a, c)); + _20(out, rt.u64And(a, b)); + _20(out, rt.u64Or(a, c)); + let x6: rt.u64 = a; + x6 = rt.u64SaturatingAdd(x6, b); + x6 = rt.u64SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.u64Rem(a, b)); + _20(out, rt.u64Div(c, b)); + } else if (_21 === 16) { + const _204: boolean = rt.u64Eq(a, b); + const _207: boolean = !rt.u64Eq(a, b); + const _210: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _213: boolean = order !== undefined && order <= 0; + const _216: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_204, _207, _210, _213, _216, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _232: boolean | rt.Done = iter.next(); + if (_232 === rt.DONE) { + break; + } + rt.byteVecPush(out, _232 ? 1 : 0); + } + const part14 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part14); + const part15 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part15); + const _250: rt.u64 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _251: rt.u64 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part16 = rt.ordClamp(a, _250, _251, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part16); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_u64(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_u64(a), hashed$u64(a)) ? 1 : 0); + const _266: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _266, true, undefined, undefined, 8, true)); + while (true) { + const _271: rt.u64 | rt.Done = iter2.next(); + if (_271 === rt.DONE) { + break; + } + _20(out, _271); + } + const _280: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash64, rt.u64Eq)) as rt.HashSet, _280, undefined, undefined, 117440512); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u64Display(a, f), (f: rt.Formatter) => rt.u64Debug(b, f), (f: rt.Formatter) => rt.u64LowerHex(a, f), (f: rt.Formatter) => rt.u64UpperHex(b, f), (f: rt.Formatter) => rt.u64Octal(c, f), (f: rt.Formatter) => rt.u64Binary(a, f), (f: rt.Formatter) => rt.u64Display(b, f), (f: rt.Formatter) => rt.u64LowerHex(c, f), (f: rt.Formatter) => rt.u64Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + const all: rt.u64[] = [a, b, c]; + const part8 = rt.iterSum(rt.iterSlice(all), rt.u64SaturatingAdd, 0); + _20(out, part8); + const part9 = rt.iterSum(rt.iterSlice(all), rt.u64SaturatingAdd, 0); + _20(out, part9); + const part10 = rt.iterProduct(rt.iterSlice(all), rt.u64SaturatingMul, 1); + _20(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(all), rt.u64SaturatingMul, 1); + _20(out, part11); + const part12 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u64SaturatingAdd, 0); + _20(out, part12); + const part13 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u64SaturatingMul, 1); + _20(out, part13); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _370: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _370[0]; + const y: saturates_Gauge.Gauge = _370[1]; + const _378: saturates_Gauge.Gauge = saturates_Gauge.default$Default_u64(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u64(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u64(_378, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_u64(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_u64(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_u64(x7), hashed$num_Saturating_u64(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_u64(x7); + z._0 = rt.u64SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _414: [rt.u64 | undefined, rt.u64 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_414[0] !== undefined) { + if (_414[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(rt.u64SaturatingMul(_414[0], _414[1])))); + } + } + const part = rt.u64SaturatingMul(a, b); + _20(out, part); + const part2 = rt.u64SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.u64SaturatingSub(a, b); + _20(out, part3); + _20(out, rt.u64Div(a, b)); + } else { + const _457: rt.u64 | undefined = rt.nonZero(a); + if (_457 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(rt.u64SaturatingAdd(_457, b)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function u128s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.u128) => undefined = (out2: rt.ByteVec, v: rt.u128): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.u128ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.u128 = (at: rt.usize): rt.u128 => { + const buf: Uint8Array = rt.bytes(16); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.u128FromBeBytes(buf); + }; + const _8: [rt.u128, rt.u128, rt.u128] = [take(0), take(16), take(2 * 16)]; + const a: rt.u128 = _8[0]; + const b: rt.u128 = _8[1]; + const c: rt.u128 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part47 = rt.u128SaturatingAdd(a, b); + _20(out, part47); + } else if (_21 === 1) { + const part46 = rt.u128SaturatingSub(a, b); + _20(out, part46); + } else if (_21 === 2) { + const part45 = rt.u128SaturatingMul(a, b); + _20(out, part45); + } else if (_21 === 3) { + _20(out, rt.u128Div(a, b)); + } else if (_21 === 4) { + _20(out, rt.u128Rem(a, b)); + } else if (_21 === 5) { + rt.byteVecPush(out, 0); + } else if (_21 === 6) { + _20(out, rt.u128Not(a)); + } else if (_21 === 7) { + _20(out, rt.u128And(a, b)); + } else if (_21 === 8) { + _20(out, rt.u128Or(a, b)); + } else if (_21 === 9) { + _20(out, rt.u128Xor(a, b)); + } else if (_21 === 10) { + let x: rt.u128 = a; + x = rt.u128SaturatingAdd(x, b); + _20(out, x); + x = rt.u128SaturatingMul(x, c); + _20(out, x); + x = rt.u128SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.u128 = a; + x2 = rt.u128Div(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.u128 = a; + x3 = rt.u128Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.u128 = a; + x4 = rt.u128And(x4, b); + x4 = rt.u128Or(x4, c); + x4 = rt.u128Xor(x4, b); + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.u128 = a; + x5 = rt.u128SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.u128SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.u128SaturatingMul(x5, b); + _20(out, x5); + x5 = rt.u128And(x5, c); + x5 = rt.u128Or(x5, b); + x5 = rt.u128Xor(x5, c); + _20(out, x5); + x5 = rt.u128Div(x5, b); + _20(out, x5); + x5 = rt.u128Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part17 = rt.u128SaturatingAdd(a, b); + _20(out, part17); + const part18 = rt.u128SaturatingSub(a, b); + _20(out, part18); + const part19 = rt.u128SaturatingMul(a, c); + _20(out, part19); + _20(out, rt.u128Not(b)); + _20(out, rt.u128Xor(a, c)); + _20(out, rt.u128And(a, b)); + _20(out, rt.u128Or(a, c)); + let x6: rt.u128 = a; + x6 = rt.u128SaturatingAdd(x6, b); + x6 = rt.u128SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.u128Rem(a, b)); + _20(out, rt.u128Div(c, b)); + } else if (_21 === 16) { + const _204: boolean = rt.u128Eq(a, b); + const _207: boolean = !rt.u128Eq(a, b); + const _210: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _213: boolean = order !== undefined && order <= 0; + const _216: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_204, _207, _210, _213, _216, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _232: boolean | rt.Done = iter.next(); + if (_232 === rt.DONE) { + break; + } + rt.byteVecPush(out, _232 ? 1 : 0); + } + const part14 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part14); + const part15 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part15); + const _250: rt.u128 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _251: rt.u128 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part16 = rt.ordClamp(a, _250, _251, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part16); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_u128(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_u128(a), hashed$u128(a)) ? 1 : 0); + const _266: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _266, true, undefined, undefined, 16, true)); + while (true) { + const _271: rt.u128 | rt.Done = iter2.next(); + if (_271 === rt.DONE) { + break; + } + _20(out, _271); + } + const _280: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash128, rt.u128Eq)) as rt.HashSet, _280, undefined, undefined, 58720256); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u128Display(a, f), (f: rt.Formatter) => rt.u128Debug(b, f), (f: rt.Formatter) => rt.u128LowerHex(a, f), (f: rt.Formatter) => rt.u128UpperHex(b, f), (f: rt.Formatter) => rt.u128Octal(c, f), (f: rt.Formatter) => rt.u128Binary(a, f), (f: rt.Formatter) => rt.u128Display(b, f), (f: rt.Formatter) => rt.u128LowerHex(c, f), (f: rt.Formatter) => rt.u128Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + const all: rt.u128[] = [a, b, c]; + const part8 = rt.iterSum(rt.iterSlice(all), rt.u128SaturatingAdd, 0); + _20(out, part8); + const part9 = rt.iterSum(rt.iterSlice(all), rt.u128SaturatingAdd, 0); + _20(out, part9); + const part10 = rt.iterProduct(rt.iterSlice(all), rt.u128SaturatingMul, 1); + _20(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(all), rt.u128SaturatingMul, 1); + _20(out, part11); + const part12 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u128SaturatingAdd, 0); + _20(out, part12); + const part13 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.u128SaturatingMul, 1); + _20(out, part13); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _370: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _370[0]; + const y: saturates_Gauge.Gauge = _370[1]; + const _378: saturates_Gauge.Gauge = saturates_Gauge.default$Default_u128(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u128(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_u128(_378, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_u128(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_u128(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_u128(x7), hashed$num_Saturating_u128(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_u128(x7); + z._0 = rt.u128SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _414: [rt.u128 | undefined, rt.u128 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_414[0] !== undefined) { + if (_414[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128SaturatingMul(_414[0], _414[1])))); + } + } + const part = rt.u128SaturatingMul(a, b); + _20(out, part); + const part2 = rt.u128SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.u128SaturatingSub(a, b); + _20(out, part3); + _20(out, rt.u128Div(a, b)); + } else { + const _457: rt.u128 | undefined = rt.nonZero(a); + if (_457 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u128ToBeBytes(rt.u128SaturatingAdd(_457, b)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function usizes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.usize) => undefined = (out2: rt.ByteVec, v: rt.usize): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.usizeToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.usize = (at: rt.usize): rt.usize => { + const buf: Uint8Array = rt.bytes(4); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.usizeFromBeBytes(buf); + }; + const _8: [rt.usize, rt.usize, rt.usize] = [take(0), take(4), take(2 * 4)]; + const a: rt.usize = _8[0]; + const b: rt.usize = _8[1]; + const c: rt.usize = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part47 = rt.usizeSaturatingAdd(a, b); + _20(out, part47); + } else if (_21 === 1) { + const part46 = rt.usizeSaturatingSub(a, b); + _20(out, part46); + } else if (_21 === 2) { + const part45 = rt.usizeSaturatingMul(a, b); + _20(out, part45); + } else if (_21 === 3) { + _20(out, rt.usizeDiv(a, b)); + } else if (_21 === 4) { + _20(out, rt.usizeRem(a, b)); + } else if (_21 === 5) { + rt.byteVecPush(out, 0); + } else if (_21 === 6) { + _20(out, ~a >>> 0); + } else if (_21 === 7) { + _20(out, (a & b) >>> 0); + } else if (_21 === 8) { + _20(out, (a | b) >>> 0); + } else if (_21 === 9) { + _20(out, (a ^ b) >>> 0); + } else if (_21 === 10) { + let x: rt.usize = a; + x = rt.usizeSaturatingAdd(x, b); + _20(out, x); + x = rt.usizeSaturatingMul(x, c); + _20(out, x); + x = rt.usizeSaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.usize = a; + x2 = rt.usizeDiv(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.usize = a; + x3 = rt.usizeRem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.usize = a; + x4 = (x4 & b) >>> 0; + x4 = (x4 | c) >>> 0; + x4 = (x4 ^ b) >>> 0; + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.usize = a; + x5 = rt.usizeSaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.usizeSaturatingSub(x5, c); + _20(out, x5); + x5 = rt.usizeSaturatingMul(x5, b); + _20(out, x5); + x5 = (x5 & c) >>> 0; + x5 = (x5 | b) >>> 0; + x5 = (x5 ^ c) >>> 0; + _20(out, x5); + x5 = rt.usizeDiv(x5, b); + _20(out, x5); + x5 = rt.usizeRem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part17 = rt.usizeSaturatingAdd(a, b); + _20(out, part17); + const part18 = rt.usizeSaturatingSub(a, b); + _20(out, part18); + const part19 = rt.usizeSaturatingMul(a, c); + _20(out, part19); + _20(out, ~b >>> 0); + _20(out, (a ^ c) >>> 0); + _20(out, (a & b) >>> 0); + _20(out, (a | c) >>> 0); + let x6: rt.usize = a; + x6 = rt.usizeSaturatingAdd(x6, b); + x6 = rt.usizeSaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.usizeRem(a, b)); + _20(out, rt.usizeDiv(c, b)); + } else if (_21 === 16) { + const _204: boolean = a === b; + const _207: boolean = a !== b; + const _210: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _213: boolean = order !== undefined && order <= 0; + const _216: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_204, _207, _210, _213, _216, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _232: boolean | rt.Done = iter.next(); + if (_232 === rt.DONE) { + break; + } + rt.byteVecPush(out, _232 ? 1 : 0); + } + const part14 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part14); + const part15 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part15); + const _250: rt.usize = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _251: rt.usize = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part16 = rt.ordClamp(a, _250, _251, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part16); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_usize(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_usize(a), hashed$usize(a)) ? 1 : 0); + const _266: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _266, true, undefined, undefined, 4, true)); + while (true) { + const _271: rt.usize | rt.Done = iter2.next(); + if (_271 === rt.DONE) { + break; + } + _20(out, _271); + } + const _280: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash32, rt.same)) as rt.HashSet, _280, undefined, undefined, 234881024); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.usizeDisplay(a, f), (f: rt.Formatter) => rt.usizeDebug(b, f), (f: rt.Formatter) => rt.usizeLowerHex(a, f), (f: rt.Formatter) => rt.usizeUpperHex(b, f), (f: rt.Formatter) => rt.usizeOctal(c, f), (f: rt.Formatter) => rt.usizeBinary(a, f), (f: rt.Formatter) => rt.usizeDisplay(b, f), (f: rt.Formatter) => rt.usizeLowerHex(c, f), (f: rt.Formatter) => rt.usizeDebug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + const all: rt.usize[] = [a, b, c]; + const part8 = rt.iterSum(rt.iterSlice(all), rt.usizeSaturatingAdd, 0); + _20(out, part8); + const part9 = rt.iterSum(rt.iterSlice(all), rt.usizeSaturatingAdd, 0); + _20(out, part9); + const part10 = rt.iterProduct(rt.iterSlice(all), rt.usizeSaturatingMul, 1); + _20(out, part10); + const part11 = rt.iterProduct(rt.iterSlice(all), rt.usizeSaturatingMul, 1); + _20(out, part11); + const part12 = rt.iterSum(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.usizeSaturatingAdd, 0); + _20(out, part12); + const part13 = rt.iterProduct(rt.iterSlice(rt.sliceRange(all, 0, 0)), rt.usizeSaturatingMul, 1); + _20(out, part13); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _370: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _370[0]; + const y: saturates_Gauge.Gauge = _370[1]; + const _378: saturates_Gauge.Gauge = saturates_Gauge.default$Default_usize(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_usize(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_usize(_378, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_usize(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_usize(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_usize(x7), hashed$num_Saturating_usize(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_usize(x7); + z._0 = rt.usizeSaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _414: [rt.usize | undefined, rt.usize | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_414[0] !== undefined) { + if (_414[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.usizeToBeBytes(rt.usizeSaturatingMul(_414[0], _414[1])))); + } + } + const part = rt.usizeSaturatingMul(a, b); + _20(out, part); + const part2 = rt.usizeSaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.usizeSaturatingSub(a, b); + _20(out, part3); + _20(out, rt.usizeDiv(a, b)); + } else { + const _457: rt.usize | undefined = rt.nonZero(a); + if (_457 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.usizeToBeBytes(rt.usizeSaturatingAdd(_457, b)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function i8s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.i8) => undefined = (out2: rt.ByteVec, v: rt.i8): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i8ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i8 = (at: rt.usize): rt.i8 => { + const buf: Uint8Array = Uint8Array.of(0); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i8FromBeBytes(buf); + }; + const _8: [rt.i8, rt.i8, rt.i8] = [take(0), take(1), take(2 * 1)]; + const a: rt.i8 = _8[0]; + const b: rt.i8 = _8[1]; + const c: rt.i8 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part44 = rt.i8SaturatingAdd(a, b); + _20(out, part44); + } else if (_21 === 1) { + const part43 = rt.i8SaturatingSub(a, b); + _20(out, part43); + } else if (_21 === 2) { + const part42 = rt.i8SaturatingMul(a, b); + _20(out, part42); + } else if (_21 === 3) { + const part41 = rt.i8SaturatingDiv(a, b); + _20(out, part41); + } else if (_21 === 4) { + _20(out, rt.i8Rem(a, b)); + } else if (_21 === 5) { + const part37 = rt.i8SaturatingSub(0, a); + _20(out, part37); + const part38 = rt.i8SaturatingSub(0, b); + _20(out, part38); + const part39 = rt.i8SaturatingSub(0, a); + _20(out, part39); + } else if (_21 === 6) { + _20(out, ~a); + } else if (_21 === 7) { + _20(out, a & b); + } else if (_21 === 8) { + _20(out, a | b); + } else if (_21 === 9) { + _20(out, a ^ b); + } else if (_21 === 10) { + let x: rt.i8 = a; + x = rt.i8SaturatingAdd(x, b); + _20(out, x); + x = rt.i8SaturatingMul(x, c); + _20(out, x); + x = rt.i8SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.i8 = a; + x2 = rt.i8SaturatingDiv(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.i8 = a; + x3 = rt.i8Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.i8 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.i8 = a; + x5 = rt.i8SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.i8SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.i8SaturatingMul(x5, b); + _20(out, x5); + x5 = x5 & c; + x5 = x5 | b; + x5 = x5 ^ c; + _20(out, x5); + x5 = rt.i8SaturatingDiv(x5, b); + _20(out, x5); + x5 = rt.i8Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part11 = rt.i8SaturatingAdd(a, b); + _20(out, part11); + const part12 = rt.i8SaturatingSub(a, b); + _20(out, part12); + const part13 = rt.i8SaturatingMul(a, c); + _20(out, part13); + _20(out, ~b); + _20(out, a ^ c); + _20(out, a & b); + _20(out, a | c); + let x6: rt.i8 = a; + x6 = rt.i8SaturatingAdd(x6, b); + x6 = rt.i8SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.i8Rem(a, b)); + const part20 = rt.i8SaturatingDiv(c, b); + _20(out, part20); + } else if (_21 === 16) { + const _219: boolean = a === b; + const _222: boolean = a !== b; + const _225: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _228: boolean = order !== undefined && order <= 0; + const _231: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_219, _222, _225, _228, _231, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _247: boolean | rt.Done = iter.next(); + if (_247 === rt.DONE) { + break; + } + rt.byteVecPush(out, _247 ? 1 : 0); + } + const part8 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part8); + const part9 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part9); + const _265: rt.i8 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _266: rt.i8 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part10 = rt.ordClamp(a, _265, _266, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part10); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_i8(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_i8(a), hashed$i8(a)) ? 1 : 0); + const _281: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _281, true, undefined, undefined, 1, true)); + while (true) { + const _286: rt.i8 | rt.Done = iter2.next(); + if (_286 === rt.DONE) { + break; + } + _20(out, _286); + } + const _295: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash8, rt.same)) as rt.HashSet, _295, undefined, undefined, 469762048); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i8Display(a, f), (f: rt.Formatter) => rt.i8Debug(b, f), (f: rt.Formatter) => rt.i8LowerHex(a, f), (f: rt.Formatter) => rt.i8UpperHex(b, f), (f: rt.Formatter) => rt.i8Octal(c, f), (f: rt.Formatter) => rt.i8Binary(a, f), (f: rt.Formatter) => rt.i8Display(b, f), (f: rt.Formatter) => rt.i8LowerHex(c, f), (f: rt.Formatter) => rt.i8Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + rt.byteVecPush(out, 0); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _344: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _344[0]; + const y: saturates_Gauge.Gauge = _344[1]; + const _352: saturates_Gauge.Gauge = saturates_Gauge.default$Default_i8(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i8(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i8(_352, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_i8(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_i8(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_i8(x7), hashed$num_Saturating_i8(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_i8(x7); + z._0 = rt.i8SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _388: [rt.i8 | undefined, rt.i8 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_388[0] !== undefined) { + if (_388[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i8ToBeBytes(rt.i8SaturatingMul(_388[0], _388[1])))); + } + } + const part = rt.i8SaturatingMul(a, b); + _20(out, part); + const part2 = rt.i8SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.i8SaturatingSub(a, b); + _20(out, part3); + const part4 = rt.i8SaturatingDiv(a, b); + _20(out, part4); + } else { + const _431: rt.i8 | undefined = rt.nonZero(a); + if (_431 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i8ToBeBytes(rt.i8SaturatingSub(0, _431)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function i16s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.i16) => undefined = (out2: rt.ByteVec, v: rt.i16): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i16ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i16 = (at: rt.usize): rt.i16 => { + const buf: Uint8Array = rt.bytes(2); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i16FromBeBytes(buf); + }; + const _8: [rt.i16, rt.i16, rt.i16] = [take(0), take(2), take(2 * 2)]; + const a: rt.i16 = _8[0]; + const b: rt.i16 = _8[1]; + const c: rt.i16 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part44 = rt.i16SaturatingAdd(a, b); + _20(out, part44); + } else if (_21 === 1) { + const part43 = rt.i16SaturatingSub(a, b); + _20(out, part43); + } else if (_21 === 2) { + const part42 = rt.i16SaturatingMul(a, b); + _20(out, part42); + } else if (_21 === 3) { + const part41 = rt.i16SaturatingDiv(a, b); + _20(out, part41); + } else if (_21 === 4) { + _20(out, rt.i16Rem(a, b)); + } else if (_21 === 5) { + const part37 = rt.i16SaturatingSub(0, a); + _20(out, part37); + const part38 = rt.i16SaturatingSub(0, b); + _20(out, part38); + const part39 = rt.i16SaturatingSub(0, a); + _20(out, part39); + } else if (_21 === 6) { + _20(out, ~a); + } else if (_21 === 7) { + _20(out, a & b); + } else if (_21 === 8) { + _20(out, a | b); + } else if (_21 === 9) { + _20(out, a ^ b); + } else if (_21 === 10) { + let x: rt.i16 = a; + x = rt.i16SaturatingAdd(x, b); + _20(out, x); + x = rt.i16SaturatingMul(x, c); + _20(out, x); + x = rt.i16SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.i16 = a; + x2 = rt.i16SaturatingDiv(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.i16 = a; + x3 = rt.i16Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.i16 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.i16 = a; + x5 = rt.i16SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.i16SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.i16SaturatingMul(x5, b); + _20(out, x5); + x5 = x5 & c; + x5 = x5 | b; + x5 = x5 ^ c; + _20(out, x5); + x5 = rt.i16SaturatingDiv(x5, b); + _20(out, x5); + x5 = rt.i16Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part11 = rt.i16SaturatingAdd(a, b); + _20(out, part11); + const part12 = rt.i16SaturatingSub(a, b); + _20(out, part12); + const part13 = rt.i16SaturatingMul(a, c); + _20(out, part13); + _20(out, ~b); + _20(out, a ^ c); + _20(out, a & b); + _20(out, a | c); + let x6: rt.i16 = a; + x6 = rt.i16SaturatingAdd(x6, b); + x6 = rt.i16SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.i16Rem(a, b)); + const part20 = rt.i16SaturatingDiv(c, b); + _20(out, part20); + } else if (_21 === 16) { + const _219: boolean = a === b; + const _222: boolean = a !== b; + const _225: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _228: boolean = order !== undefined && order <= 0; + const _231: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_219, _222, _225, _228, _231, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _247: boolean | rt.Done = iter.next(); + if (_247 === rt.DONE) { + break; + } + rt.byteVecPush(out, _247 ? 1 : 0); + } + const part8 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part8); + const part9 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part9); + const _265: rt.i16 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _266: rt.i16 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part10 = rt.ordClamp(a, _265, _266, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part10); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_i16(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_i16(a), hashed$i16(a)) ? 1 : 0); + const _281: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _281, true, undefined, undefined, 2, true)); + while (true) { + const _286: rt.i16 | rt.Done = iter2.next(); + if (_286 === rt.DONE) { + break; + } + _20(out, _286); + } + const _295: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash16, rt.same)) as rt.HashSet, _295, undefined, undefined, 469762048); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i16Display(a, f), (f: rt.Formatter) => rt.i16Debug(b, f), (f: rt.Formatter) => rt.i16LowerHex(a, f), (f: rt.Formatter) => rt.i16UpperHex(b, f), (f: rt.Formatter) => rt.i16Octal(c, f), (f: rt.Formatter) => rt.i16Binary(a, f), (f: rt.Formatter) => rt.i16Display(b, f), (f: rt.Formatter) => rt.i16LowerHex(c, f), (f: rt.Formatter) => rt.i16Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + rt.byteVecPush(out, 0); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _344: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _344[0]; + const y: saturates_Gauge.Gauge = _344[1]; + const _352: saturates_Gauge.Gauge = saturates_Gauge.default$Default_i16(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i16(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i16(_352, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_i16(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_i16(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_i16(x7), hashed$num_Saturating_i16(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_i16(x7); + z._0 = rt.i16SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _388: [rt.i16 | undefined, rt.i16 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_388[0] !== undefined) { + if (_388[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i16ToBeBytes(rt.i16SaturatingMul(_388[0], _388[1])))); + } + } + const part = rt.i16SaturatingMul(a, b); + _20(out, part); + const part2 = rt.i16SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.i16SaturatingSub(a, b); + _20(out, part3); + const part4 = rt.i16SaturatingDiv(a, b); + _20(out, part4); + } else { + const _431: rt.i16 | undefined = rt.nonZero(a); + if (_431 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i16ToBeBytes(rt.i16SaturatingSub(0, _431)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function i32s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.i32) => undefined = (out2: rt.ByteVec, v: rt.i32): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i32ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i32 = (at: rt.usize): rt.i32 => { + const buf: Uint8Array = rt.bytes(4); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i32FromBeBytes(buf); + }; + const _8: [rt.i32, rt.i32, rt.i32] = [take(0), take(4), take(2 * 4)]; + const a: rt.i32 = _8[0]; + const b: rt.i32 = _8[1]; + const c: rt.i32 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part44 = rt.i32SaturatingAdd(a, b); + _20(out, part44); + } else if (_21 === 1) { + const part43 = rt.i32SaturatingSub(a, b); + _20(out, part43); + } else if (_21 === 2) { + const part42 = rt.i32SaturatingMul(a, b); + _20(out, part42); + } else if (_21 === 3) { + const part41 = rt.i32SaturatingDiv(a, b); + _20(out, part41); + } else if (_21 === 4) { + _20(out, rt.i32Rem(a, b)); + } else if (_21 === 5) { + const part37 = rt.i32SaturatingSub(0, a); + _20(out, part37); + const part38 = rt.i32SaturatingSub(0, b); + _20(out, part38); + const part39 = rt.i32SaturatingSub(0, a); + _20(out, part39); + } else if (_21 === 6) { + _20(out, ~a); + } else if (_21 === 7) { + _20(out, a & b); + } else if (_21 === 8) { + _20(out, a | b); + } else if (_21 === 9) { + _20(out, a ^ b); + } else if (_21 === 10) { + let x: rt.i32 = a; + x = rt.i32SaturatingAdd(x, b); + _20(out, x); + x = rt.i32SaturatingMul(x, c); + _20(out, x); + x = rt.i32SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.i32 = a; + x2 = rt.i32SaturatingDiv(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.i32 = a; + x3 = rt.i32Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.i32 = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.i32 = a; + x5 = rt.i32SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.i32SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.i32SaturatingMul(x5, b); + _20(out, x5); + x5 = x5 & c; + x5 = x5 | b; + x5 = x5 ^ c; + _20(out, x5); + x5 = rt.i32SaturatingDiv(x5, b); + _20(out, x5); + x5 = rt.i32Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part11 = rt.i32SaturatingAdd(a, b); + _20(out, part11); + const part12 = rt.i32SaturatingSub(a, b); + _20(out, part12); + const part13 = rt.i32SaturatingMul(a, c); + _20(out, part13); + _20(out, ~b); + _20(out, a ^ c); + _20(out, a & b); + _20(out, a | c); + let x6: rt.i32 = a; + x6 = rt.i32SaturatingAdd(x6, b); + x6 = rt.i32SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.i32Rem(a, b)); + const part20 = rt.i32SaturatingDiv(c, b); + _20(out, part20); + } else if (_21 === 16) { + const _219: boolean = a === b; + const _222: boolean = a !== b; + const _225: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _228: boolean = order !== undefined && order <= 0; + const _231: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_219, _222, _225, _228, _231, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _247: boolean | rt.Done = iter.next(); + if (_247 === rt.DONE) { + break; + } + rt.byteVecPush(out, _247 ? 1 : 0); + } + const part8 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part8); + const part9 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part9); + const _265: rt.i32 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _266: rt.i32 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part10 = rt.ordClamp(a, _265, _266, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part10); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_i32(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_i32(a), hashed$i32(a)) ? 1 : 0); + const _281: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _281, true, undefined, undefined, 4, true)); + while (true) { + const _286: rt.i32 | rt.Done = iter2.next(); + if (_286 === rt.DONE) { + break; + } + _20(out, _286); + } + const _295: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash32, rt.same)) as rt.HashSet, _295, undefined, undefined, 234881024); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i32Display(a, f), (f: rt.Formatter) => rt.i32Debug(b, f), (f: rt.Formatter) => rt.i32LowerHex(a, f), (f: rt.Formatter) => rt.i32UpperHex(b, f), (f: rt.Formatter) => rt.i32Octal(c, f), (f: rt.Formatter) => rt.i32Binary(a, f), (f: rt.Formatter) => rt.i32Display(b, f), (f: rt.Formatter) => rt.i32LowerHex(c, f), (f: rt.Formatter) => rt.i32Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + rt.byteVecPush(out, 0); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _344: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _344[0]; + const y: saturates_Gauge.Gauge = _344[1]; + const _352: saturates_Gauge.Gauge = saturates_Gauge.default$Default_i32(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i32(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i32(_352, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_i32(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_i32(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_i32(x7), hashed$num_Saturating_i32(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_i32(x7); + z._0 = rt.i32SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _388: [rt.i32 | undefined, rt.i32 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_388[0] !== undefined) { + if (_388[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i32ToBeBytes(rt.i32SaturatingMul(_388[0], _388[1])))); + } + } + const part = rt.i32SaturatingMul(a, b); + _20(out, part); + const part2 = rt.i32SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.i32SaturatingSub(a, b); + _20(out, part3); + const part4 = rt.i32SaturatingDiv(a, b); + _20(out, part4); + } else { + const _431: rt.i32 | undefined = rt.nonZero(a); + if (_431 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i32ToBeBytes(rt.i32SaturatingSub(0, _431)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function i64s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.i64) => undefined = (out2: rt.ByteVec, v: rt.i64): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i64ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i64 = (at: rt.usize): rt.i64 => { + const buf: Uint8Array = rt.bytes(8); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i64FromBeBytes(buf); + }; + const _8: [rt.i64, rt.i64, rt.i64] = [take(0), take(8), take(2 * 8)]; + const a: rt.i64 = _8[0]; + const b: rt.i64 = _8[1]; + const c: rt.i64 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part44 = rt.i64SaturatingAdd(a, b); + _20(out, part44); + } else if (_21 === 1) { + const part43 = rt.i64SaturatingSub(a, b); + _20(out, part43); + } else if (_21 === 2) { + const part42 = rt.i64SaturatingMul(a, b); + _20(out, part42); + } else if (_21 === 3) { + const part41 = rt.i64SaturatingDiv(a, b); + _20(out, part41); + } else if (_21 === 4) { + _20(out, rt.i64Rem(a, b)); + } else if (_21 === 5) { + const part37 = rt.i64SaturatingSub(0, a); + _20(out, part37); + const part38 = rt.i64SaturatingSub(0, b); + _20(out, part38); + const part39 = rt.i64SaturatingSub(0, a); + _20(out, part39); + } else if (_21 === 6) { + _20(out, rt.i64Not(a)); + } else if (_21 === 7) { + _20(out, rt.i64And(a, b)); + } else if (_21 === 8) { + _20(out, rt.i64Or(a, b)); + } else if (_21 === 9) { + _20(out, rt.i64Xor(a, b)); + } else if (_21 === 10) { + let x: rt.i64 = a; + x = rt.i64SaturatingAdd(x, b); + _20(out, x); + x = rt.i64SaturatingMul(x, c); + _20(out, x); + x = rt.i64SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.i64 = a; + x2 = rt.i64SaturatingDiv(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.i64 = a; + x3 = rt.i64Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.i64 = a; + x4 = rt.i64And(x4, b); + x4 = rt.i64Or(x4, c); + x4 = rt.i64Xor(x4, b); + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.i64 = a; + x5 = rt.i64SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.i64SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.i64SaturatingMul(x5, b); + _20(out, x5); + x5 = rt.i64And(x5, c); + x5 = rt.i64Or(x5, b); + x5 = rt.i64Xor(x5, c); + _20(out, x5); + x5 = rt.i64SaturatingDiv(x5, b); + _20(out, x5); + x5 = rt.i64Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part11 = rt.i64SaturatingAdd(a, b); + _20(out, part11); + const part12 = rt.i64SaturatingSub(a, b); + _20(out, part12); + const part13 = rt.i64SaturatingMul(a, c); + _20(out, part13); + _20(out, rt.i64Not(b)); + _20(out, rt.i64Xor(a, c)); + _20(out, rt.i64And(a, b)); + _20(out, rt.i64Or(a, c)); + let x6: rt.i64 = a; + x6 = rt.i64SaturatingAdd(x6, b); + x6 = rt.i64SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.i64Rem(a, b)); + const part20 = rt.i64SaturatingDiv(c, b); + _20(out, part20); + } else if (_21 === 16) { + const _219: boolean = rt.i64Eq(a, b); + const _222: boolean = !rt.i64Eq(a, b); + const _225: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _228: boolean = order !== undefined && order <= 0; + const _231: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_219, _222, _225, _228, _231, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _247: boolean | rt.Done = iter.next(); + if (_247 === rt.DONE) { + break; + } + rt.byteVecPush(out, _247 ? 1 : 0); + } + const part8 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part8); + const part9 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part9); + const _265: rt.i64 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _266: rt.i64 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part10 = rt.ordClamp(a, _265, _266, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part10); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_i64(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_i64(a), hashed$i64(a)) ? 1 : 0); + const _281: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _281, true, undefined, undefined, 8, true)); + while (true) { + const _286: rt.i64 | rt.Done = iter2.next(); + if (_286 === rt.DONE) { + break; + } + _20(out, _286); + } + const _295: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash64, rt.i64Eq)) as rt.HashSet, _295, undefined, undefined, 117440512); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i64Display(a, f), (f: rt.Formatter) => rt.i64Debug(b, f), (f: rt.Formatter) => rt.i64LowerHex(a, f), (f: rt.Formatter) => rt.i64UpperHex(b, f), (f: rt.Formatter) => rt.i64Octal(c, f), (f: rt.Formatter) => rt.i64Binary(a, f), (f: rt.Formatter) => rt.i64Display(b, f), (f: rt.Formatter) => rt.i64LowerHex(c, f), (f: rt.Formatter) => rt.i64Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + rt.byteVecPush(out, 0); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _344: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _344[0]; + const y: saturates_Gauge.Gauge = _344[1]; + const _352: saturates_Gauge.Gauge = saturates_Gauge.default$Default_i64(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i64(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i64(_352, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_i64(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_i64(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_i64(x7), hashed$num_Saturating_i64(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_i64(x7); + z._0 = rt.i64SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _388: [rt.i64 | undefined, rt.i64 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_388[0] !== undefined) { + if (_388[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i64ToBeBytes(rt.i64SaturatingMul(_388[0], _388[1])))); + } + } + const part = rt.i64SaturatingMul(a, b); + _20(out, part); + const part2 = rt.i64SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.i64SaturatingSub(a, b); + _20(out, part3); + const part4 = rt.i64SaturatingDiv(a, b); + _20(out, part4); + } else { + const _431: rt.i64 | undefined = rt.nonZero(a); + if (_431 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i64ToBeBytes(rt.i64SaturatingSub(0, _431)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function i128s(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.i128) => undefined = (out2: rt.ByteVec, v: rt.i128): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.i128ToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.i128 = (at: rt.usize): rt.i128 => { + const buf: Uint8Array = rt.bytes(16); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.i128FromBeBytes(buf); + }; + const _8: [rt.i128, rt.i128, rt.i128] = [take(0), take(16), take(2 * 16)]; + const a: rt.i128 = _8[0]; + const b: rt.i128 = _8[1]; + const c: rt.i128 = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part44 = rt.i128SaturatingAdd(a, b); + _20(out, part44); + } else if (_21 === 1) { + const part43 = rt.i128SaturatingSub(a, b); + _20(out, part43); + } else if (_21 === 2) { + const part42 = rt.i128SaturatingMul(a, b); + _20(out, part42); + } else if (_21 === 3) { + const part41 = rt.i128SaturatingDiv(a, b); + _20(out, part41); + } else if (_21 === 4) { + _20(out, rt.i128Rem(a, b)); + } else if (_21 === 5) { + const part37 = rt.i128SaturatingSub(0, a); + _20(out, part37); + const part38 = rt.i128SaturatingSub(0, b); + _20(out, part38); + const part39 = rt.i128SaturatingSub(0, a); + _20(out, part39); + } else if (_21 === 6) { + _20(out, rt.i128Not(a)); + } else if (_21 === 7) { + _20(out, rt.i128And(a, b)); + } else if (_21 === 8) { + _20(out, rt.i128Or(a, b)); + } else if (_21 === 9) { + _20(out, rt.i128Xor(a, b)); + } else if (_21 === 10) { + let x: rt.i128 = a; + x = rt.i128SaturatingAdd(x, b); + _20(out, x); + x = rt.i128SaturatingMul(x, c); + _20(out, x); + x = rt.i128SaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.i128 = a; + x2 = rt.i128SaturatingDiv(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.i128 = a; + x3 = rt.i128Rem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.i128 = a; + x4 = rt.i128And(x4, b); + x4 = rt.i128Or(x4, c); + x4 = rt.i128Xor(x4, b); + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.i128 = a; + x5 = rt.i128SaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.i128SaturatingSub(x5, c); + _20(out, x5); + x5 = rt.i128SaturatingMul(x5, b); + _20(out, x5); + x5 = rt.i128And(x5, c); + x5 = rt.i128Or(x5, b); + x5 = rt.i128Xor(x5, c); + _20(out, x5); + x5 = rt.i128SaturatingDiv(x5, b); + _20(out, x5); + x5 = rt.i128Rem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part11 = rt.i128SaturatingAdd(a, b); + _20(out, part11); + const part12 = rt.i128SaturatingSub(a, b); + _20(out, part12); + const part13 = rt.i128SaturatingMul(a, c); + _20(out, part13); + _20(out, rt.i128Not(b)); + _20(out, rt.i128Xor(a, c)); + _20(out, rt.i128And(a, b)); + _20(out, rt.i128Or(a, c)); + let x6: rt.i128 = a; + x6 = rt.i128SaturatingAdd(x6, b); + x6 = rt.i128SaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.i128Rem(a, b)); + const part20 = rt.i128SaturatingDiv(c, b); + _20(out, part20); + } else if (_21 === 16) { + const _219: boolean = rt.i128Eq(a, b); + const _222: boolean = !rt.i128Eq(a, b); + const _225: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _228: boolean = order !== undefined && order <= 0; + const _231: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_219, _222, _225, _228, _231, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _247: boolean | rt.Done = iter.next(); + if (_247 === rt.DONE) { + break; + } + rt.byteVecPush(out, _247 ? 1 : 0); + } + const part8 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part8); + const part9 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part9); + const _265: rt.i128 = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _266: rt.i128 = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part10 = rt.ordClamp(a, _265, _266, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part10); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_i128(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_i128(a), hashed$i128(a)) ? 1 : 0); + const _281: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _281, true, undefined, undefined, 16, true)); + while (true) { + const _286: rt.i128 | rt.Done = iter2.next(); + if (_286 === rt.DONE) { + break; + } + _20(out, _286); + } + const _295: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash128, rt.i128Eq)) as rt.HashSet, _295, undefined, undefined, 58720256); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.i128Display(a, f), (f: rt.Formatter) => rt.i128Debug(b, f), (f: rt.Formatter) => rt.i128LowerHex(a, f), (f: rt.Formatter) => rt.i128UpperHex(b, f), (f: rt.Formatter) => rt.i128Octal(c, f), (f: rt.Formatter) => rt.i128Binary(a, f), (f: rt.Formatter) => rt.i128Display(b, f), (f: rt.Formatter) => rt.i128LowerHex(c, f), (f: rt.Formatter) => rt.i128Debug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + rt.byteVecPush(out, 0); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _344: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _344[0]; + const y: saturates_Gauge.Gauge = _344[1]; + const _352: saturates_Gauge.Gauge = saturates_Gauge.default$Default_i128(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i128(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_i128(_352, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_i128(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_i128(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_i128(x7), hashed$num_Saturating_i128(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_i128(x7); + z._0 = rt.i128SaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _388: [rt.i128 | undefined, rt.i128 | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_388[0] !== undefined) { + if (_388[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128SaturatingMul(_388[0], _388[1])))); + } + } + const part = rt.i128SaturatingMul(a, b); + _20(out, part); + const part2 = rt.i128SaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.i128SaturatingSub(a, b); + _20(out, part3); + const part4 = rt.i128SaturatingDiv(a, b); + _20(out, part4); + } else { + const _431: rt.i128 | undefined = rt.nonZero(a); + if (_431 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.i128ToBeBytes(rt.i128SaturatingSub(0, _431)))); + } + } +} + +/** Apply operation `kind` to `Saturating`s taken from `data`: three operands. */ +export function isizes(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + const _20: (a0: rt.ByteVec, a1: rt.isize) => undefined = (out2: rt.ByteVec, v: rt.isize): undefined => { + rt.byteVecExtendFromSlice(out2, rt.byteSliceFrom(rt.isizeToBeBytes(v))); + }; + const take: (a0: rt.usize) => rt.isize = (at: rt.usize): rt.isize => { + const buf: Uint8Array = rt.bytes(4); + const iter3: rt.Iter<[rt.usize, rt.Place]> = rt.iterEnumerate(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(buf)))); + while (true) { + const _10: [rt.usize, rt.Place] | rt.Done = iter3.next(); + if (_10 === rt.DONE) { + break; + } + _10[1].v = option_unwrapOr$0r2bmpr(rt.byteSliceGet(data, rt.usizeAdd(at, _10[0])), 0); + } + return rt.isizeFromBeBytes(buf); + }; + const _8: [rt.isize, rt.isize, rt.isize] = [take(0), take(4), take(2 * 4)]; + const a: rt.isize = _8[0]; + const b: rt.isize = _8[1]; + const c: rt.isize = _8[2]; + const _21: rt.u8 = rt.u8Rem(kind, 24); + if (_21 === 0) { + const part44 = rt.isizeSaturatingAdd(a, b); + _20(out, part44); + } else if (_21 === 1) { + const part43 = rt.isizeSaturatingSub(a, b); + _20(out, part43); + } else if (_21 === 2) { + const part42 = rt.isizeSaturatingMul(a, b); + _20(out, part42); + } else if (_21 === 3) { + const part41 = rt.isizeSaturatingDiv(a, b); + _20(out, part41); + } else if (_21 === 4) { + _20(out, rt.isizeRem(a, b)); + } else if (_21 === 5) { + const part37 = rt.isizeSaturatingSub(0, a); + _20(out, part37); + const part38 = rt.isizeSaturatingSub(0, b); + _20(out, part38); + const part39 = rt.isizeSaturatingSub(0, a); + _20(out, part39); + } else if (_21 === 6) { + _20(out, ~a); + } else if (_21 === 7) { + _20(out, a & b); + } else if (_21 === 8) { + _20(out, a | b); + } else if (_21 === 9) { + _20(out, a ^ b); + } else if (_21 === 10) { + let x: rt.isize = a; + x = rt.isizeSaturatingAdd(x, b); + _20(out, x); + x = rt.isizeSaturatingMul(x, c); + _20(out, x); + x = rt.isizeSaturatingSub(x, b); + _20(out, x); + } else if (_21 === 11) { + let x2: rt.isize = a; + x2 = rt.isizeSaturatingDiv(x2, b); + _20(out, x2); + } else if (_21 === 12) { + let x3: rt.isize = a; + x3 = rt.isizeRem(x3, b); + _20(out, x3); + } else if (_21 === 13) { + let x4: rt.isize = a; + x4 = x4 & b; + x4 = x4 | c; + x4 = x4 ^ b; + _20(out, x4); + } else if (_21 === 14) { + let x5: rt.isize = a; + x5 = rt.isizeSaturatingAdd(x5, b); + _20(out, x5); + x5 = rt.isizeSaturatingSub(x5, c); + _20(out, x5); + x5 = rt.isizeSaturatingMul(x5, b); + _20(out, x5); + x5 = x5 & c; + x5 = x5 | b; + x5 = x5 ^ c; + _20(out, x5); + x5 = rt.isizeSaturatingDiv(x5, b); + _20(out, x5); + x5 = rt.isizeRem(x5, c); + _20(out, x5); + } else if (_21 === 15) { + const part11 = rt.isizeSaturatingAdd(a, b); + _20(out, part11); + const part12 = rt.isizeSaturatingSub(a, b); + _20(out, part12); + const part13 = rt.isizeSaturatingMul(a, c); + _20(out, part13); + _20(out, ~b); + _20(out, a ^ c); + _20(out, a & b); + _20(out, a | c); + let x6: rt.isize = a; + x6 = rt.isizeSaturatingAdd(x6, b); + x6 = rt.isizeSaturatingMul(x6, c); + _20(out, x6); + _20(out, rt.isizeRem(a, b)); + const part20 = rt.isizeSaturatingDiv(c, b); + _20(out, part20); + } else if (_21 === 16) { + const _219: boolean = a === b; + const _222: boolean = a !== b; + const _225: boolean = rt.cmp(a, b) === -1; + const order = rt.cmp(a, b); + const _228: boolean = order !== undefined && order <= 0; + const _231: boolean = rt.cmp(a, b) === 1; + const order2 = rt.cmp(a, b); + const iter: rt.Iter = rt.iterSlice([_219, _222, _225, _228, _231, order2 !== undefined && order2 >= 0, rt.cmp(a, b) < 0, isSomeAnd$08u1px1(rt.cmp(a, c), (o: rt.Ordering): boolean => { + return o > 0; + })]); + while (true) { + const _247: boolean | rt.Done = iter.next(); + if (_247 === rt.DONE) { + break; + } + rt.byteVecPush(out, _247 ? 1 : 0); + } + const part8 = rt.ordMax(a, b, rt.cmpLt(rt.cmp)); + _20(out, part8); + const part9 = rt.ordMin(a, c, rt.cmpLt(rt.cmp)); + _20(out, part9); + const _265: rt.isize = rt.ordMin(b, c, rt.cmpLt(rt.cmp)); + const _266: rt.isize = rt.ordMax(b, c, rt.cmpLt(rt.cmp)); + const part10 = rt.ordClamp(a, _265, _266, rt.cmpLe(rt.cmp), rt.cmpLt(rt.cmp), rt.cmpGt(rt.cmp)); + _20(out, part10); + } else if (_21 === 17) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(hashed$num_Saturating_isize(a)))); + rt.byteVecPush(out, rt.u64Eq(hashed$num_Saturating_isize(a), hashed$isize(a)) ? 1 : 0); + const _281: rt.Iter = rt.iterSlice([a, b, c, a]); + const iter2: rt.Iter = rt.btreeKeys(rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet, _281, true, undefined, undefined, 4, true)); + while (true) { + const _286: rt.isize | rt.Done = iter2.next(); + if (_286 === rt.DONE) { + break; + } + _20(out, _286); + } + const _295: rt.Iter = rt.iterSlice([a, b]); + const seen: rt.HashSet = rt.hashExtendKeys(rt.hashNew(rt.hashing(rt.hash32, rt.same)) as rt.HashSet, _295, undefined, undefined, 234881024); + rt.byteVecPush(out, rt.hashContains(seen, c) ? 1 : 0); + rt.byteVecPush(out, rt.hashLen(seen) & 0xff); + } else if (_21 === 18) { + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.isizeDisplay(a, f), (f: rt.Formatter) => rt.isizeDebug(b, f), (f: rt.Formatter) => rt.isizeLowerHex(a, f), (f: rt.Formatter) => rt.isizeUpperHex(b, f), (f: rt.Formatter) => rt.isizeOctal(c, f), (f: rt.Formatter) => rt.isizeBinary(a, f), (f: rt.Formatter) => rt.isizeDisplay(b, f), (f: rt.Formatter) => rt.isizeLowerHex(c, f), (f: rt.Formatter) => rt.isizeDebug(a, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5], " ", rt.fmtSpec({ align: ">", width: 6 }, args2[6]), " ", rt.fmtSpec({ alternate: true }, args2[7]), " ", rt.fmtSpec({ zero: true, width: 8 }, args2[8]), " ", rt.fmtSpec({ plus: true }, args2[6])]))); + } else if (_21 === 19) { + rt.byteVecPush(out, 0); + } else if (_21 === 20) { + _20(out, 0); + _20(out, a); + _20(out, a); + } else if (_21 === 21) { + const _344: [saturates_Gauge.Gauge, saturates_Gauge.Gauge] = [new saturates_Gauge.Gauge(a), new saturates_Gauge.Gauge(b)]; + const x7: saturates_Gauge.Gauge = _344[0]; + const y: saturates_Gauge.Gauge = _344[1]; + const _352: saturates_Gauge.Gauge = saturates_Gauge.default$Default_isize(); + const args4: rt.Fmt[] = [(f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_isize(x7, f), (f: rt.Formatter) => saturates_Gauge.fmt$fmt_Debug_isize(_352, f)]; + rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1]]))); + rt.byteVecPush(out, saturates_Gauge.eq$cmp_PartialEq_isize(x7, y) ? 1 : 0); + rt.byteVecPush(out, saturates_Gauge.cmp$cmp_Ord_isize(x7, y) & 0xff); + rt.byteVecPush(out, rt.u64Eq(hashed$saturates_Gauge_isize(x7), hashed$num_Saturating_isize(a)) ? 1 : 0); + const z: saturates_Gauge.Gauge = copy$saturates_Gauge_isize(x7); + z._0 = rt.isizeSaturatingSub(z._0, y._0); + _20(out, z._0); + } else if (_21 === 22) { + const _388: [rt.isize | undefined, rt.isize | undefined] = [rt.nonZero(a), rt.nonZero(b)]; + if (_388[0] !== undefined) { + if (_388[1] !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.isizeToBeBytes(rt.isizeSaturatingMul(_388[0], _388[1])))); + } + } + const part = rt.isizeSaturatingMul(a, b); + _20(out, part); + const part2 = rt.isizeSaturatingAdd(a, b); + _20(out, part2); + const part3 = rt.isizeSaturatingSub(a, b); + _20(out, part3); + const part4 = rt.isizeSaturatingDiv(a, b); + _20(out, part4); + } else { + const _431: rt.isize | undefined = rt.nonZero(a); + if (_431 !== undefined) { + rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.isizeToBeBytes(rt.isizeSaturatingSub(0, _431)))); + } + } +} + +//# sourceMappingURL=saturates.ts.map diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 8187c576e..9cd769bb0 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -4,8 +4,8 @@ use crate::{ arrays, atomics, borrows, bounds, captures, cells, chars, chunks, clones, collections, combinators, counts, cows, cycles, defaults, durations, dyns, edits, errors, floats, fmt, folds, generics, hashes, hints, holds, ints, iters, - joins, keys, locals, locks, nested, objects, orders, pointers, refs, shapes, singles, slices, splits, statics, - strs, utf8, wrappers, wraps, zeros, + joins, keys, locals, locks, nested, objects, orders, pointers, refs, saturates, shapes, singles, slices, splits, + statics, strs, utf8, wrappers, wraps, zeros, }; /// The native side's entry: [`run`], except that a case starting with 0xff prints a @@ -214,6 +214,18 @@ fn cases() -> Vec<(&'static str, Case)> { pointers::iterated_runs(data, out) }), ("zeros::writes", zeros::writes), + ("saturates::u8s", saturates::u8s), + ("saturates::u16s", saturates::u16s), + ("saturates::u32s", saturates::u32s), + ("saturates::u64s", saturates::u64s), + ("saturates::u128s", saturates::u128s), + ("saturates::usizes", saturates::usizes), + ("saturates::i8s", saturates::i8s), + ("saturates::i16s", saturates::i16s), + ("saturates::i32s", saturates::i32s), + ("saturates::i64s", saturates::i64s), + ("saturates::i128s", saturates::i128s), + ("saturates::isizes", saturates::isizes), ] } diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index 781a2ec37..06b30f5ca 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -61,6 +61,7 @@ mod objects; mod orders; mod pointers; mod refs; +mod saturates; mod shapes; mod singles; mod slices; diff --git a/ts/fixtures/lang/src/saturates.rs b/ts/fixtures/lang/src/saturates.rs new file mode 100644 index 000000000..7690fcd5c --- /dev/null +++ b/ts/fixtures/lang/src/saturates.rs @@ -0,0 +1,218 @@ +//! `Saturating` of every integer width: its operators and their assign forms, which +//! saturate where the integer's would overflow, its comparisons, hash, and formatting, an +//! unsigned one's `Sum` and `Product`, and a field of one; and the saturating methods of its +//! integer and of a `NonZero` of it. + +use std::collections::{BTreeSet, HashSet}; +use std::hash::{DefaultHasher, Hash, Hasher}; +use std::num::{NonZero, Saturating}; + +/// A `Saturating` in a field, with each derived impl reading it. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] +struct Gauge(Saturating); + +fn hashed(v: &T) -> u64 { + let mut h = DefaultHasher::new(); + v.hash(&mut h); + h.finish() +} + +macro_rules! saturates { + ($name:ident, $t:ty, $sign:ident) => { + /// Apply operation `kind` to `Saturating`s taken from `data`: three operands. + pub fn $name(kind: u8, data: &[u8], out: &mut Vec) { + const N: usize = core::mem::size_of::<$t>(); + let take = |at: usize| { + let mut buf = [0u8; N]; + for (i, b) in buf.iter_mut().enumerate() { + *b = data.get(at + i).copied().unwrap_or(0); + } + Saturating(<$t>::from_be_bytes(buf)) + }; + let (a, b, c) = (take(0), take(N), take(2 * N)); + let put = |out: &mut Vec, v: Saturating<$t>| out.extend_from_slice(&v.0.to_be_bytes()); + match kind % 24 { + 0 => put(out, a + b), + 1 => put(out, a - b), + 2 => put(out, a * b), + 3 => put(out, a / b), + 4 => put(out, a % b), + 5 => saturates!(@$sign, $t, a, b, c, put, out), + 6 => put(out, !a), + 7 => put(out, a & b), + 8 => put(out, a | b), + 9 => put(out, a ^ b), + 10 => { + let mut x = a; + x += b; + put(out, x); + x *= c; + put(out, x); + x -= b; + put(out, x); + } + 11 => { + let mut x = a; + x /= b; + put(out, x); + } + 12 => { + let mut x = a; + x %= b; + put(out, x); + } + 13 => { + let mut x = a; + x &= b; + x |= c; + x ^= b; + put(out, x); + } + 14 => { + // By the integer, and a reference to one. + let mut x = a; + x += b.0; + put(out, x); + x -= &c.0; + put(out, x); + x *= b.0; + put(out, x); + x &= &c.0; + x |= b.0; + x ^= c.0; + put(out, x); + x /= &b.0; + put(out, x); + x %= c.0; + put(out, x); + } + 15 => { + // Through references, which std's impls forward. + put(out, &a + b); + put(out, a - &b); + put(out, &a * &c); + put(out, !&b); + put(out, &a ^ &c); + put(out, &a & b); + put(out, a | &c); + let mut x = a; + x += &b; + x *= &c; + put(out, x); + put(out, &a % &b); + put(out, &c / &b); + } + 16 => { + let bits = [ + a == b, + a != b, + a < b, + a <= b, + a > b, + a >= b, + a.cmp(&b).is_lt(), + a.partial_cmp(&c).is_some_and(|o| o.is_gt()), + ]; + for bit in bits { + out.push(bit as u8); + } + put(out, a.max(b)); + put(out, a.min(c)); + put(out, a.clamp(b.min(c), b.max(c))); + } + 17 => { + out.extend_from_slice(&hashed(&a).to_be_bytes()); + out.push((hashed(&a) == hashed(&a.0)) as u8); + let set: BTreeSet> = [a, b, c, a].into_iter().collect(); + for v in &set { + put(out, *v); + } + let seen: HashSet> = [a, b].into_iter().collect(); + out.push(seen.contains(&c) as u8); + out.push(seen.len() as u8); + } + 18 => { + let text = format!("{a} {b:?} {a:x} {b:X} {c:o} {a:b} {b:>6} {c:#x} {a:08?} {b:+}"); + out.extend_from_slice(text.as_bytes()); + } + 19 => saturates!(@$sign sums, $t, a, b, c, put, out), + 20 => { + let zero = Saturating::<$t>::default(); + put(out, zero); + #[allow(clippy::clone_on_copy, reason = "the clone `Clone` makes")] + let copy = a.clone(); + put(out, copy); + put(out, Saturating(a.0)); + } + 21 => { + let (x, y) = (Gauge(a), Gauge(b)); + let text = format!("{x:?} {:?}", Gauge::<$t>::default()); + out.extend_from_slice(text.as_bytes()); + out.push((x == y) as u8); + out.push(x.cmp(&y) as i8 as u8); + out.push((hashed(&x) == hashed(&a)) as u8); + let mut z = x; + z.0 -= y.0; + put(out, z.0); + } + 22 => { + // The `NonZero`'s, before the integer's, which panics on a zero divisor. + if let (Some(x), Some(y)) = (NonZero::new(a.0), NonZero::new(b.0)) { + out.extend_from_slice(&x.saturating_mul(y).get().to_be_bytes()); + } + put(out, Saturating(a.0.saturating_mul(b.0))); + put(out, Saturating(a.0.saturating_add(b.0))); + put(out, Saturating(a.0.saturating_sub(b.0))); + put(out, Saturating(a.0.saturating_div(b.0))); + } + _ => saturates!(@$sign nonzero, $t, a, b, c, put, out), + } + } + }; + // `Neg`, which only a signed `Saturating` has. + (@signed, $t:ty, $a:ident, $b:ident, $c:ident, $put:ident, $out:ident) => {{ + $put($out, -$a); + $put($out, -&$b); + $put($out, Saturating($a.0.saturating_neg())); + }}; + (@unsigned, $t:ty, $a:ident, $b:ident, $c:ident, $put:ident, $out:ident) => { + $out.push(0) + }; + // `Sum` and `Product`, which std implements only for an unsigned `Saturating`. + (@signed sums, $t:ty, $a:ident, $b:ident, $c:ident, $put:ident, $out:ident) => { + $out.push(0) + }; + (@unsigned sums, $t:ty, $a:ident, $b:ident, $c:ident, $put:ident, $out:ident) => {{ + let all = [$a, $b, $c]; + $put($out, all.iter().sum::>()); + $put($out, all.into_iter().sum::>()); + $put($out, all.iter().product::>()); + $put($out, all.into_iter().product::>()); + $put($out, all[..0].iter().sum::>()); + $put($out, all[..0].iter().product::>()); + }}; + // A signed `NonZero`'s `saturating_neg`, or an unsigned one's `saturating_add`. + (@signed nonzero, $t:ty, $a:ident, $b:ident, $c:ident, $put:ident, $out:ident) => { + if let Some(x) = NonZero::new($a.0) { + $out.extend_from_slice(&x.saturating_neg().get().to_be_bytes()); + } + }; + (@unsigned nonzero, $t:ty, $a:ident, $b:ident, $c:ident, $put:ident, $out:ident) => { + if let Some(x) = NonZero::new($a.0) { + $out.extend_from_slice(&x.saturating_add($b.0).get().to_be_bytes()); + } + }; +} + +saturates!(u8s, u8, unsigned); +saturates!(u16s, u16, unsigned); +saturates!(u32s, u32, unsigned); +saturates!(u64s, u64, unsigned); +saturates!(u128s, u128, unsigned); +saturates!(usizes, usize, unsigned); +saturates!(i8s, i8, signed); +saturates!(i16s, i16, signed); +saturates!(i32s, i32, signed); +saturates!(i64s, i64, signed); +saturates!(i128s, i128, signed); +saturates!(isizes, isize, signed); diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index b384191a4..0170e3f27 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,7 +1,7 @@ # Census of `reject-fixture` -- Refusals: 136 -- Function instances: 167 +- Refusals: 137 +- Function instances: 168 - Generic functions no instance reached, lowered over their type parameters: 10 ## By construct @@ -9,7 +9,7 @@ | Count | Construct | First | | ---: | --- | --- | | 23 | a raw pointer to `_` in `_`, which the crate may put another object in place of | fixtures/reject/src/lib.rs:623:10 | -| 17 | unsupported call to `_` | fixtures/reject/src/lib.rs:167:8 | +| 18 | unsupported call to `_` | fixtures/reject/src/lib.rs:167:8 | | 14 | a raw pointer to `_` in a variable assigned again while it may point there | fixtures/reject/src/lib.rs:631:10 | | 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:344:2 | | 3 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:237:14 | @@ -154,6 +154,7 @@ The type or module each refused type or path belongs to. | 1 | `std::iter` | fixtures/reject/src/lib.rs:1250:22 | | 1 | `std::net::AddrParseError` | fixtures/reject/src/lib.rs:446:32 | | 1 | `std::net::Ipv4Addr` | fixtures/reject/src/lib.rs:446:32 | +| 1 | `std::num::Saturating` | fixtures/reject/src/lib.rs:1270:26 | | 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:999:32 | | 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:999:11 | | 1 | `std::slice::IterMut` | fixtures/reject/src/lib.rs:781:15 | @@ -261,6 +262,7 @@ The type or module each refused type or path belongs to. | 1 | unsupported call to `_` | `::hash` | fixtures/reject/src/lib.rs:314:10 | | 1 | unsupported call to `_` | `std::any::TypeId::of` | fixtures/reject/src/lib.rs:553:17 | | 1 | unsupported call to `_` | `std::borrow::Cow::is_borrowed` | fixtures/reject/src/lib.rs:356:2 | +| 1 | unsupported call to `_` | `std::num::Saturating::pow` | fixtures/reject/src/lib.rs:1270:26 | | 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:167:8 | | 1 | unsupported call to `_` | `std::ops::Range::is_empty` | fixtures/reject/src/lib.rs:1004:9 | | 1 | unsupported call to `_` | `std::ops::RangeTo::contains` | fixtures/reject/src/lib.rs:999:11 | @@ -301,7 +303,7 @@ The type or module each refused type or path belongs to. -
unsupported call to `_` (17) +
unsupported call to `_` (18) - fixtures/reject/src/lib.rs:167:8: unsupported call to `std::ops::Range::::contains::` - fixtures/reject/src/lib.rs:314:10: unsupported call to `::hash::` @@ -320,6 +322,7 @@ The type or module each refused type or path belongs to. - fixtures/reject/src/lib.rs:999:11: unsupported call to `std::ops::RangeTo::::contains::` - fixtures/reject/src/lib.rs:999:32: unsupported call to ` as std::ops::RangeBounds>::contains::` - fixtures/reject/src/lib.rs:1004:9: unsupported call to `std::ops::Range::<&mut u8>::is_empty` +- fixtures/reject/src/lib.rs:1270:26: unsupported call to `std::num::Saturating::::pow`
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index e71192eb9..c54f1c188 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -126,6 +126,7 @@ a raw pointer to `std::cell::UnsafeCell<(u16, u16)>` in `Repeated`, which the cr a raw pointer to `std::cell::UnsafeCell<(u16, u16)>` in `Onced`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1248:46 `std::iter::once` with a mutable reference to a value JS copies, which its mapping would copy at fixtures/reject/src/lib.rs:1250:22 a raw pointer to `(u16, u16)` in `Pushed`, which the crate may put another object in place of at fixtures/reject/src/lib.rs:1263:22 +unsupported call to `std::num::Saturating::::pow` at fixtures/reject/src/lib.rs:1270:26 overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:132:2 an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:152:1 overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:180:2 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index f16a5564e..2150f5ca2 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -1264,3 +1264,8 @@ pub fn pushed_part_kept(n: u16) -> u16 { unsafe { p.write(Pushed { part: (0, 0) }) }; unsafe { (*part).0 } } + +/// A `Saturating`'s own methods, which are its integer's, are not translated yet. +pub fn saturating_pow(a: u8) -> u8 { + std::num::Saturating(a).pow(2).0 +} diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index bbedff986..feec113f4 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -111,5 +111,6 @@ roots = [ "kept_across_iterations", "lent_kept", "pushed_part_kept", + "saturating_pow", ] printable = ["Meters"] diff --git a/ts/runtime/rt/int.ts b/ts/runtime/rt/int.ts index ad1f221b6..4d3b396d5 100644 --- a/ts/runtime/rt/int.ts +++ b/ts/runtime/rt/int.ts @@ -546,6 +546,8 @@ export const i8WrappingMul = (a: i8, b: i8): i8 => (Math.imul(a, b) << 24) >> 24 export const i8WrappingDiv = (a: i8, b: i8): i8 => (b === -1 ? i8WrappingSub(0, a) : i8Div(a, b)); /** `i8`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ export const i8WrappingRem = (a: i8, b: i8): i8 => (b === -1 ? 0 : i8Rem(a, b)); +/** `i8`'s `saturating_div`: `a / b`, truncated and clamped to the type's range, panicking on a zero divisor. */ +export const i8SaturatingDiv = (a: i8, b: i8): i8 => (b === -1 ? i8SaturatingSub(0, a) : i8Div(a, b)); /** `i8`'s `leading_ones`: the count of leading one bits. */ export const i8LeadingOnes = (a: i8): number => Math.clz32(~(a << 24)); /** `i8`'s `leading_zeros`: the count of leading zero bits. */ @@ -613,6 +615,8 @@ export const i16WrappingMul = (a: i16, b: i16): i16 => (Math.imul(a, b) << 16) > export const i16WrappingDiv = (a: i16, b: i16): i16 => (b === -1 ? i16WrappingSub(0, a) : i16Div(a, b)); /** `i16`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ export const i16WrappingRem = (a: i16, b: i16): i16 => (b === -1 ? 0 : i16Rem(a, b)); +/** `i16`'s `saturating_div`: `a / b`, truncated and clamped to the type's range, panicking on a zero divisor. */ +export const i16SaturatingDiv = (a: i16, b: i16): i16 => (b === -1 ? i16SaturatingSub(0, a) : i16Div(a, b)); /** `i16`'s `leading_ones`: the count of leading one bits. */ export const i16LeadingOnes = (a: i16): number => Math.clz32(~(a << 16)); /** `i16`'s `leading_zeros`: the count of leading zero bits. */ @@ -680,6 +684,8 @@ export const i32WrappingMul = (a: i32, b: i32): i32 => Math.imul(a, b); export const i32WrappingDiv = (a: i32, b: i32): i32 => (b === -1 ? i32WrappingSub(0, a) : i32Div(a, b)); /** `i32`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ export const i32WrappingRem = (a: i32, b: i32): i32 => (b === -1 ? 0 : i32Rem(a, b)); +/** `i32`'s `saturating_div`: `a / b`, truncated and clamped to the type's range, panicking on a zero divisor. */ +export const i32SaturatingDiv = (a: i32, b: i32): i32 => (b === -1 ? i32SaturatingSub(0, a) : i32Div(a, b)); /** `i32`'s `leading_ones`: the count of leading one bits. */ export const i32LeadingOnes = (a: i32): number => Math.clz32(~a); /** `i32`'s `leading_zeros`: the count of leading zero bits. */ @@ -822,6 +828,8 @@ export const isizeWrappingMul: (a: isize, b: isize) => isize = i32WrappingMul as export const isizeWrappingDiv: (a: isize, b: isize) => isize = i32WrappingDiv as never; /** `isize`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ export const isizeWrappingRem: (a: isize, b: isize) => isize = i32WrappingRem as never; +/** `isize`'s `saturating_div`: `a / b`, truncated and clamped to the type's range, panicking on a zero divisor. */ +export const isizeSaturatingDiv: (a: isize, b: isize) => isize = i32SaturatingDiv as never; /** `isize`'s `leading_ones`: the count of leading one bits. */ export const isizeLeadingOnes: (a: isize) => number = i32LeadingOnes as never; /** `isize`'s `leading_zeros`: the count of leading zero bits. */ @@ -1613,6 +1621,8 @@ export const i64WrappingMul = (a: i64, b: i64): i64 => (typeof a === "number" && export const i64WrappingDiv = (a: i64, b: i64): i64 => (b === -1 ? i64WrappingSub(0, a) : i64Div(a, b)); /** `i64`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ export const i64WrappingRem = (a: i64, b: i64): i64 => (b === -1 ? 0 : i64Rem(a, b)); +/** `i64`'s `saturating_div`: `a / b`, truncated and clamped to the type's range, panicking on a zero divisor. */ +export const i64SaturatingDiv = (a: i64, b: i64): i64 => (b === -1 ? i64SaturatingSub(0, a) : i64Div(a, b)); /** `i64`'s `leading_ones`: the count of leading one bits. */ export const i64LeadingOnes = (a: i64): number => leadingOnes64(a, true); /** `i64`'s `leading_zeros`: the count of leading zero bits. */ @@ -1831,6 +1841,8 @@ export const i128WrappingMul = (a: i128, b: i128): i128 => (typeof a === "number export const i128WrappingDiv = (a: i128, b: i128): i128 => (b === -1 ? i128WrappingSub(0, a) : i128Div(a, b)); /** `i128`'s `wrapping_rem`: `a % b`, 0 where it would overflow, panicking on a zero divisor. */ export const i128WrappingRem = (a: i128, b: i128): i128 => (b === -1 ? 0 : i128Rem(a, b)); +/** `i128`'s `saturating_div`: `a / b`, truncated and clamped to the type's range, panicking on a zero divisor. */ +export const i128SaturatingDiv = (a: i128, b: i128): i128 => (b === -1 ? i128SaturatingSub(0, a) : i128Div(a, b)); /** `i128`'s `leading_ones`: the count of leading one bits. */ export const i128LeadingOnes = (a: i128): number => leadingOnes128(a, true); /** `i128`'s `leading_zeros`: the count of leading zero bits. */ diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index 342fb9f00..97344d87b 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -183,7 +183,7 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { library::cow_made(elem, variant, values.pop().unwrap()) } (library::Std::Result, i) => Expr::result(i == 0, values.pop().unwrap()), - (library::Std::Reverse | library::Std::Wrapping, _) => values.pop().unwrap(), + (library::Std::Reverse | library::Std::Wrapping | library::Std::Saturating, _) => values.pop().unwrap(), (library::Std::Bound | library::Std::TryLockError, _) => { let ts_ty = self.t.ty(Ty::new_adt(tcx, adt, gargs), span); library::tagged(adt.variant(variant).name.as_str(), values.pop(), ts_ty) diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 63413379b..a0fc6e8ef 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -733,11 +733,11 @@ fn hashing<'tcx>(b: &mut Body<'_, '_, 'tcx>, coll: Ty<'tcx>, key: Ty<'tcx>, span let mut values = vec![hash_fn(b, key, hasher, span), eq_fn(b, key, span)]; // A fieldless enum is a JS string, and a bound value may be any primitive, which its // own `Eq` may tell apart where JS can't, as is the `Some` of an `Option` of one, and a - // `Reverse` or a `Wrapping` of one. + // `Reverse`, a `Wrapping`, or a `Saturating` of one. let mut held = peeled; while let Some(inner) = option_of(b, held) .or_else(|| reverse_of(b, held)) - .or_else(|| wrapping_of(b, held)) + .or_else(|| overflowing_of(b, held)) { held = peel(b, inner); } @@ -1508,7 +1508,7 @@ fn std_key<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { if let Some(inner) = option_of(b, ty) .or_else(|| arc_of(b, ty)) .or_else(|| reverse_of(b, ty)) - .or_else(|| wrapping_of(b, ty)) + .or_else(|| overflowing_of(b, ty)) .or_else(|| cow_of(b, ty)) .or_else(|| deque_of(b, ty)) => { @@ -1553,10 +1553,10 @@ fn reverse_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { (b.t.std_of(ty) == Some(Std::Reverse)).then(|| arg(ty, 0)) } -/// What `ty` holds if it is a `Wrapping`, which compares, orders, and hashes as it, but for -/// its `ne`, which is `!eq`. -fn wrapping_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { - (b.t.std_of(ty) == Some(Std::Wrapping)).then(|| arg(ty, 0)) +/// What `ty` holds if it is a `Wrapping` or a `Saturating`, which compares, orders, and +/// hashes as it, but for its `ne`, which is `!eq`. +fn overflowing_of<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option> { + b.t.std_of(ty).and_then(Std::overflow).map(|_| arg(ty, 0)) } /// What `ty` holds if it is a `Cow<[T]>` other than of bytes, `T`, which compares, orders, @@ -1752,7 +1752,7 @@ pub fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, spa ty::Adt(..) if let Some(inner) = reverse_of(b, ty) => { Expr::rt("cmpReverse", vec![cmp_fn(b, inner, partial, span)]) } - ty::Adt(..) if let Some(inner) = wrapping_of(b, ty) => cmp_fn(b, inner, partial, span), + ty::Adt(..) if let Some(inner) = overflowing_of(b, ty) => cmp_fn(b, inner, partial, span), ty::Adt(..) if let Some(elem) = cow_of(b, ty) => { Expr::rt("cowBy", vec![cmp_fn(b, Ty::new_slice(tcx, elem), partial, span)]) } @@ -1812,7 +1812,7 @@ pub fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr Expr::Rt(same) if same == "same" => Expr::Rt(same), eq => Expr::rt("eqOption", [eq].into_iter().chain(b.t.none_arg(inner)).collect()), }, - ty::Adt(..) if let Some(inner) = reverse_of(b, ty).or_else(|| wrapping_of(b, ty)) => eq_fn(b, inner, span), + ty::Adt(..) if let Some(inner) = reverse_of(b, ty).or_else(|| overflowing_of(b, ty)) => eq_fn(b, inner, span), ty::Adt(..) if let Some(elem) = cow_of(b, ty) => { Expr::rt("cowBy", vec![eq_fn(b, Ty::new_slice(tcx, elem), span)]) } @@ -2029,7 +2029,7 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa Expr::rt("hashOption", [hash].into_iter().chain(b.t.none_arg(inner)).collect()) } ty::Adt(..) if let Some(inner) = arc_of(b, ty) => Expr::rt("hashArc", vec![hash_fn(b, inner, hasher, span)]), - ty::Adt(..) if let Some(inner) = reverse_of(b, ty).or_else(|| wrapping_of(b, ty)) => { + ty::Adt(..) if let Some(inner) = reverse_of(b, ty).or_else(|| overflowing_of(b, ty)) => { hash_fn(b, inner, hasher, span) } ty::Adt(..) if let Some(elem) = cow_of(b, ty) => { diff --git a/ts/src/lower/copy.rs b/ts/src/lower/copy.rs index a1d09a963..e95e06e33 100644 --- a/ts/src/lower/copy.rs +++ b/ts/src/lower/copy.rs @@ -41,9 +41,15 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Adt(adt, args) => match Std::of(self.tcx, adt.did()) { // Their payload, or no object at all; a write into an `rt.Result`'s payload // replaces the result. - Some(Std::Option | Std::Poll | Std::Result | Std::ControlFlow | Std::Reverse | Std::Wrapping) => { - (false, args.types().collect()) - } + Some( + Std::Option + | Std::Poll + | Std::Result + | Std::ControlFlow + | Std::Reverse + | Std::Wrapping + | Std::Saturating, + ) => (false, args.types().collect()), Some(Std::Bound) => (true, args.types().collect()), Some(Std::MaybeUninit) => return self.changes(args.type_at(0)), Some(_) => return false, @@ -189,7 +195,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { Some(Std::Option) => ret(self.copy_unless(self.none(args.type_at(0)), args.type_at(0), span)), Some(Std::Poll) => ret(self.copy_unless(self.pending(args.type_at(0)), args.type_at(0), span)), Some(Std::Result) => ret(self.copy_result(args.type_at(0), args.type_at(1), span)), - Some(Std::Reverse | Std::Wrapping) => ret(self.snapshot(v(), args.type_at(0), span)), + Some(Std::Reverse | Std::Wrapping | Std::Saturating) => ret(self.snapshot(v(), args.type_at(0), span)), Some(Std::Bound) => { let ts_ty = self.ty(ty, span); let held = self.snapshot(v().member("_0"), args.type_at(0), span); diff --git a/ts/src/lower/drop.rs b/ts/src/lower/drop.rs index 1092cd432..5d94d217c 100644 --- a/ts/src/lower/drop.rs +++ b/ts/src/lower/drop.rs @@ -63,6 +63,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | Std::TryLockError | Std::Reverse | Std::Wrapping + | Std::Saturating | Std::Range | Std::RangeInclusive | Std::RangeFrom @@ -162,7 +163,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | Std::Box | Std::Pin | Std::Reverse - | Std::Wrapping, + | Std::Wrapping + | Std::Saturating, ) => self.disposable(args.type_at(0), span), // An `rt.Iter` drops what it was given to. None | Some(Std::Peekable) if self.std_iter(ty) => self.closures_held(ty), @@ -195,7 +197,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { }; match Std::of(self.tcx, adt.did()) { _ if self.bound_drops(adt.did()).is_some() => true, - Some(Std::Box | Std::Pin | Std::Reverse | Std::Wrapping | Std::PoisonError) => { + Some(Std::Box | Std::Pin | Std::Reverse | Std::Wrapping | Std::Saturating | Std::PoisonError) => { self.always_disposes(args.type_at(0)) } Some( @@ -260,7 +262,8 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | Std::Poll | Std::Pin | Std::Reverse - | Std::Wrapping, + | Std::Wrapping + | Std::Saturating, ) => args.types().all(|t| self.inert(t)), // Its waker. Some(Std::Context) => false, @@ -317,7 +320,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { let option = Ty::new_option(self.tcx, args.type_at(0)); return self.drop_value(value.member("v"), option, span); } - Std::Box | Std::Pin | Std::Reverse | Std::Wrapping | Std::PoisonError => { + Std::Box | Std::Pin | Std::Reverse | Std::Wrapping | Std::Saturating | Std::PoisonError => { return self.drop_value(value, args.type_at(0), span); } // Its value, or the function that never made one. @@ -473,7 +476,9 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { ty::Adt(adt, args) => match Std::of(self.tcx, adt.did())? { Std::Vec => Some(args.type_at(0)), Std::Option if self.erases_to(args.type_at(0)).undefined => None, - Std::Option | Std::Box | Std::Pin | Std::Reverse | Std::Wrapping => self.elements(args.type_at(0)), + Std::Option | Std::Box | Std::Pin | Std::Reverse | Std::Wrapping | Std::Saturating => { + self.elements(args.type_at(0)) + } _ => None, }, _ => None, diff --git a/ts/src/lower/fmt.rs b/ts/src/lower/fmt.rs index ca3b4dde8..4ecf10026 100644 --- a/ts/src/lower/fmt.rs +++ b/ts/src/lower/fmt.rs @@ -297,8 +297,10 @@ pub fn std_impl<'tcx>( ty::Adt(adt, args) => match (Std::of(tcx, adt.did())?, tr) { (Std::String | Std::Cow, Trait::Display) if library::string(tcx, ty) => Expr::rt("fmtPad", vec![f, value]), (Std::String | Std::Cow, Trait::Debug) if library::string(tcx, ty) => rt("str", vec![value, f]), - // A `NonZero` and a `Wrapping` write their integer, by each trait. - (Std::Box | Std::NonZero | Std::Wrapping, _) => b.fmt_call(tr, args.type_at(0), value, f, span), + // A `NonZero`, a `Wrapping`, and a `Saturating` write their integer, by each trait. + (Std::Box | Std::NonZero | Std::Wrapping | Std::Saturating, _) => { + b.fmt_call(tr, args.type_at(0), value, f, span) + } // A `Cow<[T]>` writes its slice. (Std::Cow, Trait::Debug) if let Some(elem) = library::cow_slice(tcx, ty) => { b.fmt_call(tr, Ty::new_slice(tcx, elem), library::cow_deref(value, elem), f, span) diff --git a/ts/src/lower/iter.rs b/ts/src/lower/iter.rs index f6c68ca01..984ebcf01 100644 --- a/ts/src/lower/iter.rs +++ b/ts/src/lower/iter.rs @@ -524,18 +524,20 @@ pub fn call<'tcx>( tail(vec![Expr::rt_of(float.name(), op), float.lit(unit)], vec![drops]), ) } - // A `Wrapping`'s wraps, as its `+` and `*` do. + // A `Wrapping`'s wraps and a `Saturating`'s saturates, as its `+` and `*` do. "sum" | "product" => { - let wrapping = super::library::wrapping_of(b.t.tcx, targ(1)?); - let int = Int::of(wrapping.unwrap_or(targ(1)?))?; - let (op, unit) = match (name, wrapping.is_some()) { - ("sum", false) => ("add", 0), - ("sum", true) => ("wrappingAdd", 0), - (_, false) => ("mul", 1), - (_, true) => ("wrappingMul", 1), + let overflowing = super::library::overflowing(b.t.tcx, targ(1)?); + let int = Int::of(overflowing.map_or(targ(1)?, |(_, int)| int))?; + let (op, unit) = match name { + "sum" => ("Add", 0), + _ => ("Mul", 1), + }; + let op = match overflowing { + Some((overflow, _)) => overflow.method(op), + None => op.to_lowercase(), }; let drops = iter_drops(b, self_ty, span); - method(name, tail(vec![int.func(op), int.lit(unit)], vec![drops])) + method(name, tail(vec![int.func(&op), int.lit(unit)], vec![drops])) } // `ExactSizeIterator::len` and `size_hint` are each iterator's own. "len" => Some(recv.member("len").call(rest)), diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 7f3ff103f..0f4c7e9e1 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -13,7 +13,7 @@ use rustc_span::Span; use super::Translator; use super::body::Body; use super::fmt; -use super::num::{self, Int, Operand}; +use super::num::{self, Int, Operand, Overflow}; use crate::ts::{Expr, Stmt, StmtKind}; /// A type with a representation of its own: std's, or a well-known crate's that @@ -128,6 +128,8 @@ pub enum Std { NonZero, /// What it holds, whose arithmetic wraps. Wrapping, + /// What it holds, whose arithmetic saturates at its bounds. + Saturating, /// A `format_args!` argument: a function writing its value, `rt.Fmt`. Argument, /// A raw pointer to its pointee, as `pointer` has it. @@ -182,6 +184,15 @@ impl Std { ) } + /// How its operators overflow, if it is a `Wrapping` or a `Saturating`. + pub fn overflow(self) -> Option { + match self { + Self::Wrapping => Some(Overflow::Wrap), + Self::Saturating => Some(Overflow::Saturate), + _ => None, + } + } + pub fn of(tcx: TyCtxt<'_>, did: DefId) -> Option { if !is_std(tcx, did) { return super::stock::of(tcx, did); @@ -306,6 +317,7 @@ impl Std { ["ops", "range", "Bound"] => Some(Self::Bound), ["num", "nonzero", "NonZero"] => Some(Self::NonZero), ["num", "wrapping", "Wrapping"] => Some(Self::Wrapping), + ["num", "saturating", "Saturating"] => Some(Self::Saturating), ["hash", "random", "DefaultHasher"] => Some(Self::Hasher), ["hash", "random", "RandomState"] => Some(Self::RandomState), ["collections", "hash", "map", "Entry" | "OccupiedEntry" | "VacantEntry"] @@ -396,14 +408,14 @@ pub fn string<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { } /// What a value of `ty` is in JS if `ty` wraps one value it is represented as: `Reverse`'s, -/// `NonZero`'s, and `Wrapping`'s `T`, which differ only in their order, range, and -/// arithmetic, a pattern type's base, and the field of each of core's `niche_types` +/// `NonZero`'s, `Wrapping`'s, and `Saturating`'s `T`, which differ only in their +/// order, range, and arithmetic, a pattern type's base, and the field of each of core's `niche_types` /// structs that hold one. pub fn wrapped<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { match ty.kind() { ty::Pat(base, _) => Some(*base), ty::Adt(adt, args) => match Std::of(tcx, adt.did()) { - Some(Std::Reverse | Std::NonZero | Std::Wrapping) => Some(args.type_at(0)), + Some(Std::Reverse | Std::NonZero | Std::Wrapping | Std::Saturating) => Some(args.type_at(0)), Some(_) => None, None => { let path = std_path(tcx, adt.did()); @@ -1252,6 +1264,10 @@ fn mapping<'tcx>( "saturating_add" => "saturatingAdd", "saturating_sub" => "saturatingSub", "saturating_mul" => "saturatingMul", + // Only a signed one can overflow, at `MIN / -1`. + "saturating_div" if int.signed => "saturatingDiv", + "saturating_div" => "div", + "saturating_neg" => return Some(int.method("saturatingSub", [vec![int.lit(0)], args].concat())), "wrapping_add" => "wrappingAdd", "wrapping_sub" => "wrappingSub", "wrapping_mul" => "wrappingMul", @@ -1363,10 +1379,11 @@ fn mapping<'tcx>( int.method("tryFrom", values) } - // A `Wrapping`'s operators, which wrap as its integer's `wrapping_*` do. + // A `Wrapping`'s or a `Saturating`'s operators, which wrap or saturate as its integer's + // `wrapping_*` or `saturating_*` do. (_, _) if let Some(op) = operator(&owner) - && let Some(int) = wrapping_of(tcx, targ(gargs, 0).peel_refs()) => + && let Some((overflow, int)) = overflowing(tcx, targ(gargs, 0).peel_refs()) => { let [l, r] = <[Expr; 2]>::try_from(args).ok()?; // A constant shift amount, which masks to a constant. @@ -1374,8 +1391,9 @@ fn mapping<'tcx>( Expr::Lit(l) => l.parse().ok(), _ => None, }; - num::wrapping( + num::overflowing( b, + overflow, op, Operand { expr: l, value: None }, Operand { expr: r, value }, @@ -1383,11 +1401,11 @@ fn mapping<'tcx>( span, ) } - ("Neg", "neg") if let Some(int) = wrapping_of(tcx, targ(gargs, 0).peel_refs()) => { - let zero = Int::of(int)?.lit(0); - Int::of(int)?.method("wrappingSub", vec![zero, args.pop()?]) + ("Neg", "neg") if let Some((overflow, int)) = overflowing(tcx, targ(gargs, 0).peel_refs()) => { + let int = Int::of(int)?; + int.method(&overflow.method("Sub"), vec![int.lit(0), args.pop()?]) } - ("Not", "not") if let Some(int) = wrapping_of(tcx, targ(gargs, 0).peel_refs()) => { + ("Not", "not") if let Some((_, int)) = overflowing(tcx, targ(gargs, 0).peel_refs()) => { num::unary(b, rustc_middle::mir::UnOp::Not, args.pop()?, int, span) } // Operators on references to primitives. @@ -1585,11 +1603,16 @@ fn mapping<'tcx>( // A `NonZero` is its integer. ("NonZero", "get") => args.pop()?, ("NonZero", "new") => Expr::rt("nonZero", args), - // Of each width's own impl, which has no type argument to read the integer from. - ("NonZero", "leading_zeros" | "trailing_zeros") => { + // Of each width's own impl, which has no type argument to read the integer from. Its + // saturating arithmetic is its integer's, which never saturates to 0. + ("NonZero", "leading_zeros" | "trailing_zeros" | "saturating_add" | "saturating_mul" | "saturating_neg") => { let imp = tcx.inherent_impl_of_assoc(call.def_id)?; let self_ty = tcx.type_of(imp).instantiate_identity().skip_norm_wip(); - Int::of(unwrapped(tcx, self_ty))?.method(&super::camel(&name), args) + let int = Int::of(unwrapped(tcx, self_ty))?; + match name.as_str() { + "saturating_neg" => int.method("saturatingSub", vec![int.lit(0), args.pop()?]), + _ => int.method(&super::camel(&name), args), + } } // `Bound<&T>::cloned::`: what it holds, cloned. ("Bound", "cloned") => { @@ -2447,14 +2470,14 @@ pub fn operator(owner: &str) -> Option { }) } -/// The integer a `Wrapping` of type `ty` holds, if it is one of an integer. -pub fn wrapping_of<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { - match ty.kind() { - ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::Wrapping) => { - Some(args.type_at(0)).filter(|&t| Int::of(t).is_some()) - } - _ => None, - } +/// How the operators of `ty` overflow and the integer it holds, if it is a `Wrapping` or a +/// `Saturating` of an integer. +pub fn overflowing<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<(Overflow, Ty<'tcx>)> { + let ty::Adt(adt, args) = ty.kind() else { + return None; + }; + let overflow = Std::of(tcx, adt.did())?.overflow()?; + Int::of(args.type_at(0)).map(|_| (overflow, args.type_at(0))) } /// A `str` method's pattern as the runtime takes it, an `rt.Pattern`: a `char`'s text, a @@ -2664,7 +2687,7 @@ pub fn default_value<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span, vec![default_value(b, args.type_at(0), span, out)?], ), Std::OnceCell | Std::OnceLock => super::task::once_new(b, ty), - Std::Box | Std::Wrapping => part(b, args.type_at(0), out), + Std::Box | Std::Wrapping | Std::Saturating => part(b, args.type_at(0), out), Std::Arc => Expr::New(Box::new(Expr::Rt("Arc".into())), vec![part(b, args.type_at(0), out)]), Std::Mutex => Expr::New(Box::new(Expr::Rt("Mutex".into())), vec![part(b, args.type_at(0), out)]), Std::RefCell => Expr::New( diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index d6cd550e7..a0ae67f68 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -641,10 +641,11 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { None => done(place, true), } } - // A `Wrapping` is its integer, so what the `&mut` borrows gets the wrapped result. + // A `Wrapping` or a `Saturating` is its integer, so what the `&mut` borrows gets the + // wrapped or saturated result. (_, _) if let Some(op) = owner.strip_suffix("Assign").and_then(library::operator) - && let Some(int) = targ(0).and_then(|t| library::wrapping_of(tcx, t)) => + && let Some((overflow, int)) = targ(0).and_then(|t| library::overflowing(tcx, t)) => { let place = self.borrowed_place(&args[0].node, span, out)?; let by = self.operand(&args[1].node, span, out); @@ -656,7 +657,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { expr: by, value: self.const_int(&args[1].node), }; - let value = crate::lower::num::wrapping(self.b, op, l, r, int, span); + let value = crate::lower::num::overflowing(self.b, overflow, op, l, r, int, span); self.set_borrowed(&place, value, span, out); done(Expr::undefined(), false) } diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index 3dda2ceba..70b12adb9 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -551,6 +551,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { | Std::Reverse | Std::NonZero | Std::Wrapping + | Std::Saturating | Std::PoisonError, ) => base, // Cast to its variant, which a test narrows only where it reads the field. diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index 8bc9f5613..7faeba1dc 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -607,7 +607,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { (Std::RangeTo | Std::RangeToInclusive, _) => { crate::lower::library::range_to(values.pop().unwrap(), std == Std::RangeToInclusive) } - (Std::Reverse | Std::Wrapping, _) => values.pop().unwrap(), + (Std::Reverse | Std::Wrapping | Std::Saturating, _) => values.pop().unwrap(), (Std::Bound | Std::TryLockError, _) => { let ts_ty = self.b.t.ty(ty, span); crate::lower::library::tagged(def.name.as_str(), values.pop(), ts_ty) diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 4c80e91fe..3034bbe85 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -1431,6 +1431,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | library::Std::Reverse | library::Std::NonZero | library::Std::Wrapping + | library::Std::Saturating | library::Std::PoisonError => self.ty(args.type_at(0), span), library::Std::Bound => Type::Rt("RangeBound", vec![self.ty(args.type_at(0), span)]), library::Std::TryLockError => Type::Rt("TryLockError", vec![self.ty(args.type_at(0), span)]), @@ -1730,6 +1731,7 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { | library::Std::Reverse | library::Std::NonZero | library::Std::Wrapping + | library::Std::Saturating | library::Std::PoisonError, ) => self.erases_to(args.type_at(0)), // `undefined` while it holds nothing. diff --git a/ts/src/lower/num.rs b/ts/src/lower/num.rs index 8c4729030..b3789758f 100644 --- a/ts/src/lower/num.rs +++ b/ts/src/lower/num.rs @@ -342,19 +342,46 @@ pub fn binary<'tcx>( } } -/// `l op r` of `Wrapping`s, as the integer's `wrapping_*` computes it: arithmetic -/// wraps, a shift masks its amount to the width, and only a zero divisor panics. -pub fn wrapping<'tcx>(b: &mut Body<'_, '_, 'tcx>, op: BinOp, l: Operand, r: Operand, ty: Ty<'tcx>, span: Span) -> Expr { +/// How a `Wrapping`'s or a `Saturating`'s operators overflow. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Overflow { + Wrap, + Saturate, +} + +impl Overflow { + /// The runtime's name for the integer method that overflows so: `wrappingAdd` for `Add`. + pub fn method(self, op: &str) -> String { + match self { + Self::Wrap => format!("wrapping{op}"), + Self::Saturate => format!("saturating{op}"), + } + } +} + +/// `l op r` of `Wrapping`s or `Saturating`s, as the integer's `wrapping_*` or +/// `saturating_*` computes it. Arithmetic wraps or saturates, and a `Wrapping`'s shift masks +/// its amount to the width. A zero divisor panics, as does a `Saturating`'s `MIN % -1`, whose +/// `Rem` is the integer's. +pub fn overflowing<'tcx>( + b: &mut Body<'_, '_, 'tcx>, + overflow: Overflow, + op: BinOp, + l: Operand, + r: Operand, + ty: Ty<'tcx>, + span: Span, +) -> Expr { let Some(int) = Int::of(ty) else { - return b.err(span, format!("arithmetic on `Wrapping<{ty}>`")); + return b.err(span, format!("wrapping or saturating arithmetic on `{ty}`")); }; - let name = match op { - BinOp::Add => "wrappingAdd", - BinOp::Sub => "wrappingSub", - BinOp::Mul => "wrappingMul", - BinOp::Div if int.signed => "wrappingDiv", - BinOp::Rem if int.signed => "wrappingRem", - BinOp::Shl | BinOp::Shr => { + let name = match (overflow, op) { + (_, BinOp::Add) => "Add", + (_, BinOp::Sub) => "Sub", + (_, BinOp::Mul) => "Mul", + (_, BinOp::Div) if int.signed => "Div", + (Overflow::Wrap, BinOp::Rem) if int.signed => "Rem", + (Overflow::Wrap, BinOp::Shl | BinOp::Shr) => { let mask = i128::from(int.bits - 1); let r = match r.value { Some(c) => Operand { @@ -368,10 +395,15 @@ pub fn wrapping<'tcx>(b: &mut Body<'_, '_, 'tcx>, op: BinOp, l: Operand, r: Oper }; return binary(b, op, l, r, ty, b.t.tcx.types.usize, span); } - // Neither overflows. + // std implements no shift for a `Saturating`. + (Overflow::Saturate, BinOp::Shl | BinOp::Shr) => { + return b.err(span, format!("`{op:?}` of `Saturating<{ty}>`")); + } + // The integer's own: a bitwise operator never overflows, and an unsigned division or a + // `Saturating`'s remainder panics where the integer's does. _ => return binary(b, op, l, r, ty, ty, span), }; - int.method(name, vec![l.expr, r.expr]) + int.method(&overflow.method(name), vec![l.expr, r.expr]) } pub fn unary<'tcx>(b: &mut Body<'_, '_, 'tcx>, op: UnOp, value: Expr, ty: Ty<'tcx>, span: Span) -> Expr { From 87772b7959af3d5507fa7cc19f16b2cbcd3a6c6b Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Sat, 31 Oct 2026 04:51:04 -0700 Subject: [PATCH 3/3] docs(ts): reflow wrapped's comment Co-Authored-By: Claude Opus 5.5 --- ts/src/lower/library.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 0f4c7e9e1..5b98c013b 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -409,8 +409,8 @@ pub fn string<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { /// What a value of `ty` is in JS if `ty` wraps one value it is represented as: `Reverse`'s, /// `NonZero`'s, `Wrapping`'s, and `Saturating`'s `T`, which differ only in their -/// order, range, and arithmetic, a pattern type's base, and the field of each of core's `niche_types` -/// structs that hold one. +/// order, range, and arithmetic, a pattern type's base, and the field of each of core's +/// `niche_types` structs that hold one. pub fn wrapped<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { match ty.kind() { ty::Pat(base, _) => Some(*base),