Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ generic std gap is planned here even when moq never calls it.
- [A vector's exact capacity as it shrinks](/quest/m3/ts-vec-exact-capacity.md) - a deque made from a `Vec` splits its slices where std's does
- [A B-tree's searches call Ord as std's do](/quest/m3/ts-btree-search-order.md) - a B-tree's lookups and inserts call a key's own `Ord` in std's order and number
- [Rc and Arc of a slice](/quest/m3/ts-shared-slices.md) - `Rc<[T]>` and `Arc<[T]>` from a `Vec`, a slice, or an iterator translate
- [Operator trait methods called by path](/quest/m3/ts-operator-paths.md) - `<u8 as AddAssign>::add_assign` and every other `std::ops` operator method translate called by path or as a value
- [The rest of a vector's methods](/quest/m3/ts-vec-rest.md) - `append`, `resize`, `split_off`, `try_reserve`, and `Vec::from(VecDeque)` translate
- [A reversed zip's per-pair cost](/quest/m3/ts-zip-rev-overhead.md) - a reversed by-index zip costs per pair what a forward one does, or the gap is explained
- [Whole writes into a lazy cell or thread-local key](/quest/m3/ts-lazy-writes.md) - a whole write through a `&mut` to a `LazyCell`, `LazyLock`, or `LocalKey` keeps its state
Expand Down
23 changes: 0 additions & 23 deletions quest/m3/ts-operator-paths.md

This file was deleted.

4 changes: 4 additions & 0 deletions ts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions ts/fixtures/lang/operators/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "lang-operators-fixture"
description = "A part of the language rust2-ts translates, exercised against native Rust"
version = "0.0.0"
edition.workspace = true
license.workspace = true
publish = false

[lib]
# The cdylib is the native side of the differential test, built for wasm32.
crate-type = ["lib", "cdylib"]

[lints]
workspace = true
62 changes: 62 additions & 0 deletions ts/fixtures/lang/operators/caller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// The inputs `operators`' cases name, which run with the generated ones.

import { double, op } from "./lang.ts";

export { ops, run } from "./lang.ts";

/**
* `operators::*` of every integer kind at every width, over operands at the edges of its
* range: 0, 1, either end, the sign bit's neighbors, which make `MIN / -1`, and at 128 bits
* values past 2^64. Shift amounts are at, past, and many times past the width, and negative
* as an `i16`. Each form takes its turn at each pair.
*/
function ints(): 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(`operators::${name}`);
const width = BigInt(bits);
const mask = (1n << width) - 1n;
const sign = 1n << (width - 1n);
const edges = [0n, 1n, 3n, mask, mask - 1n, sign, sign - 1n, sign + 1n];
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));
// The amount's low byte and its high byte, which reads as `high << 24`; `0xff`
// reads as a negative `i16`.
const shifts = [[0, 0], [1, 0], [bits - 1, 0], [bits, 0], [bits + 1, 0], [2 * bits + 3, 0], [5, 1], [0xff, 0x80]];
let i = 0;
for (const a of edges) {
for (const b of edges) {
const [low, high] = shifts[i % shifts.length];
for (let kind = 0; kind < 32; kind++) cases.push(Uint8Array.of(...o, kind, (i + kind) % 6, ...be(a), ...be(b), low, high));
i++;
}
}
}
return cases;
}

/** Signed zeros, rounding, each type's extremes and subnormals, infinities, and NaN. */
const doubles = [0, -0, 1, -1, 0.1, 1 / 3, 1.5, -2.5, 2 ** 53, 3.4028235677973366e38, 1e-40, 5e-324, Number.MAX_VALUE, Infinity, -Infinity, NaN];

/** `operators::f64s` and `f32s` of every kind, over each pair of doubles. */
function floats(): Uint8Array[] {
const cases: Uint8Array[] = [];
for (const name of ["f64s", "f32s"]) {
const o = op(`operators::${name}`);
let i = 0;
for (const a of doubles) {
for (const b of doubles) {
for (let kind = 0; kind < 16; kind++) cases.push(Uint8Array.of(...o, kind, (i + kind) % 6, ...double(a), ...double(b)));
i++;
}
}
}
return cases;
}

/** `operators::bools` of every kind, pair, and form. */
const boolsOp = op("operators::bools");
const bools = Array.from({ length: 10 * 6 * 4 }, (_, i) => Uint8Array.of(...boolsOp, i % 10, Math.floor(i / 10) % 6, Math.floor(i / 60)));

export const cases: Uint8Array[] = [...ints(), ...floats(), ...bools];
12 changes: 12 additions & 0 deletions ts/fixtures/lang/operators/expected/core/option.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "../rt.ts";

export function unwrapOr$0r2bmpr(self: rt.u8 | undefined, default_: rt.u8): rt.u8 {
if (self === undefined) {
return default_;
}
return self;
}

//# sourceMappingURL=option.ts.map
40 changes: 40 additions & 0 deletions ts/fixtures/lang/operators/expected/harness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { cases } from "./lib.ts";

/** Run one case. */
export function run(input: rt.ByteSlice): rt.ByteVec {
const out: rt.ByteVec = new rt.ByteVec();
if (!(input.length >= 3)) {
return out;
}
const cases_: [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined][] = cases();
cases_[rt.idx(cases_, rt.usizeRem(((input.data[input.start] << 8) | input.data[input.start + 1]) as rt.usize, cases_.length))][1](input.data[input.start + 2], new rt.ByteSlice(input.data, input.start + 3, input.length - 3), out);
return out;
}

/**
* The first two bytes, as one big-endian number, that pick the case named `name`, which
* `lang.ts` targets by.
*/
export function op(name: string): rt.u16 {
const _11: rt.usize | undefined = rt.iterPosition(rt.iterSlice(cases()), (_2: [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]): boolean => {
return _2[0] === name;
});
if (_11 !== undefined) {
const _20: rt.Result<rt.u16, rt.TryFromIntError> = rt.u16TryFrom(_11);
if (_20.ok) {
if ((_20.value >> 8) !== 255) {
return _20.value;
}
}
const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, name)];
rt.panicFmt(["case ", args4[0], " is past what two bytes pick"]);
} else {
const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, name)];
rt.panicFmt(["no case ", args2[0]]);
}
}

//# sourceMappingURL=harness.ts.map
14 changes: 14 additions & 0 deletions ts/fixtures/lang/operators/expected/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { u8s, u16s, u32s, u64s, u128s, usizes, i8s, i16s, i32s, i64s, i128s, isizes, f64s, f32s, bools } from "./operators.ts";

/**
* Each case's name and what it runs. The first two bytes, big-endian, pick one modulo
* their count, so a case added at the end moves no other.
*/
export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined][] {
return [["operators::u8s", u8s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::u16s", u16s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::u32s", u32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::u64s", u64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::u128s", u128s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::usizes", usizes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::i8s", i8s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::i16s", i16s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::i32s", i32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::i64s", i64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::i128s", i128s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::isizes", isizes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::f64s", f64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::f32s", f32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["operators::bools", bools as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]];
}

//# sourceMappingURL=lib.ts.map
Loading