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 @@ -31,7 +31,6 @@ generic std gap is planned here even when moq never calls it.
- [std's sorts call their tests in std's order](/quest/m3/ts-sort-order.md) - `slice::sort` and a B-tree's `collect` call `lt` or `cmp` as std's driftsort does past 16 elements
- [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
- [The rest of a boxed slice's impls](/quest/m3/ts-boxed-slice-rest.md) - `clone_from`, `AsRef`, `AsMut`, `TryFrom` into a boxed array, and `Box<str>` into bytes translate for boxed slices
- [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
18 changes: 0 additions & 18 deletions quest/m3/ts-boxed-slice-rest.md

This file was deleted.

2 changes: 1 addition & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ built natively for wasm32 and run beside its translation on the same inputs by
- `lang` covers every integer width's arithmetic, casts, and inherent methods, with
`NonZero`'s, `Wrapping`'s, and `Saturating`'s, at each width's edges, the ASCII methods of
every byte, of chars either side of ASCII, Latin-1, and the surrogates, and of slices and strings, `char`s next to each
encoding's edges and the surrogates, `Cow<str>` and `Cow<[T]>` borrowed and owned, `Box<[T]>` and `Box<str>` made each way and turned back, `Wrapping` and `Saturating` at every width, `Duration`s whose
encoding's edges and the surrogates, `Cow<str>` and `Cow<[T]>` borrowed and owned, `Box<[T]>` and `Box<str>` made each way, cloned into, lent, and turned back, into a boxed array or bytes included, `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
Expand Down
325 changes: 324 additions & 1 deletion ts/fixtures/lang/expected/boxes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$array_tuple2_u8_u16, copy$array_u16, copy$array_u8, copy$tuple2_u8_u16 } from "./lib.ts";
import { copy$array_tuple2_u8_u16, copy$array_u16, copy$array_u8, copy$tuple2_u8_u16, drop$Result_boxed_Box_array1_boxes_Logged_boxed_Box_slice_boxes_Logged } from "./lib.ts";
import * as boxes_Held from "./boxes.Held.ts";
import * as boxes_Logged from "./boxes.Logged.ts";
import type * as Owner from "./boxes.Owner.ts";
Expand Down Expand Up @@ -714,4 +714,327 @@ export function places(_1: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
}
}

/** Clones `from` into `slot` by its `clone_from`. */
export function refill$boxed_Box_slice_boxes_Logged(slot: rt.Place<boxes_Logged.Logged[]>, from: boxes_Logged.Logged[]): void {
slot.v = rt.boxSliceCloneFrom(slot.v, from, boxes_Logged.clone$Clone, rt.drop);
}

/** Clones `from` into `slot` by its `clone_from`. */
export function refill$boxed_Box_slice_u8(slot: rt.Place<rt.ByteSlice>, from: rt.ByteSlice): void {
slot.v = rt.byteBoxSliceCloneFrom(slot.v, from);
}

/** The sum of the bytes `x` lends by its `AsRef`. */
export function sum$boxed_Box_slice_u8(x: rt.ByteSlice): rt.u8 {
return rt.iterFold(rt.iterSlice(rt.byteSliceView(x)), 0, (a: rt.u8, _32: rt.u8): rt.u8 => {
return rt.u8WrappingAdd(a, _32);
});
}

/** Writes through what `x` lends by its `AsMut`. */
export function flip$boxed_Box_slice_u8(x: rt.Place<rt.ByteSlice>): void {
const iter: rt.Iter<rt.Place<rt.u8>> = rt.iterSliceMut(rt.byteSliceView(x.v));
while (true) {
const _5: rt.Place<rt.u8> | rt.Done = iter.next();
if (_5 === rt.DONE) {
break;
}
_5.v = _5.v ^ 15;
}
}

/** Puts what boxing `r` into an array gave: its bytes, or a marker and what it gave back. */
export function boxed$0_boxed_Box_slice_u8(r: rt.Result<Uint8Array, rt.ByteSlice>, out: rt.ByteVec): void {
if (r.ok) {
const a: Uint8Array = r.value;
const _5: rt.Place<rt.u8> | undefined = rt.sliceFirstMut(rt.byteSliceView(rt.byteSliceFrom(a)));
if (_5 !== undefined) {
_5.v = _5.v ^ 255;
}
bytes(rt.byteSliceFrom(a), out);
} else {
const e: rt.ByteSlice = r.error;
rt.byteVecPush(out, 238);
bytes(e, out);
}
}

/** Puts what boxing `r` into an array gave: its bytes, or a marker and what it gave back. */
export function boxed$3_boxed_Box_slice_u8(r: rt.Result<Uint8Array, rt.ByteSlice>, out: rt.ByteVec): void {
if (r.ok) {
const a: Uint8Array = r.value;
const _5: rt.Place<rt.u8> | undefined = rt.sliceFirstMut(rt.byteSliceView(rt.byteSliceFrom(a)));
if (_5 !== undefined) {
_5.v = _5.v ^ 255;
}
bytes(rt.byteSliceFrom(a), out);
} else {
const e: rt.ByteSlice = r.error;
rt.byteVecPush(out, 238);
bytes(e, out);
}
}

/** Puts what boxing `r` into an array gave: its bytes, or a marker and what it gave back. */
export function boxed$4_Vec_u8(r: rt.Result<Uint8Array, rt.ByteVec>, out: rt.ByteVec): void {
if (r.ok) {
const a: Uint8Array = r.value;
const _5: rt.Place<rt.u8> | undefined = rt.sliceFirstMut(rt.byteSliceView(rt.byteSliceFrom(a)));
if (_5 !== undefined) {
_5.v = _5.v ^ 255;
}
bytes(rt.byteSliceFrom(a), out);
} else {
const e: rt.ByteVec = r.error;
rt.byteVecPush(out, 238);
bytes(rt.byteVecSlice(e), out);
}
}

/**
* The rest of a box's impls: `clone_from` of a boxed slice, into one of its length by
* each item's `clone_from` and into one of another replaced whole; `AsRef` and `AsMut` of
* a box of any value; `TryFrom` of a boxed slice and a `Vec` into a boxed array, of its
* length or not; and a boxed text's bytes. Each of bytes and of other values, empty or
* not, with what drops dropped in std's order.
*/
export function impls(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
const data2: rt.ByteSlice = rt.byteSliceRange(data, 0, rt.usizeRem(kind >> 3 as rt.usize, rt.usizeAdd(data.length, 1)));
const half: rt.usize = rt.usizeDiv(data2.length, 2);
const log: rt.Arc<rt.RefCell<rt.ByteVec>> = new rt.Arc(new rt.RefCell(new rt.ByteVec()));
const logged: (a0: rt.u8) => boxes_Logged.Logged = (id: rt.u8): boxes_Logged.Logged => {
return new boxes_Logged.Logged(id, rt.arcClone(log));
};
const _23: rt.u8 = rt.u8Rem(kind, 4);
if (_23 === 0) {
let a: rt.ByteSlice = rt.byteSliceFrom(rt.byteSliceToArray(rt.byteSliceRange(data2, 0, half)));
const b: rt.ByteSlice = rt.byteSliceFrom(rt.byteSliceToArray(rt.byteSliceRange(data2, half, rt.usizeMul(half, 2))));
a = rt.byteBoxSliceCloneFrom(a, b);
const _36: rt.Place<rt.u8> | undefined = rt.sliceFirstMut(rt.byteSliceView(a));
if (_36 !== undefined) {
_36.v = _36.v ^ 255;
}
bytes(a, out);
bytes(b, out);
const _49: rt.ByteSlice = rt.byteSliceFrom(rt.byteSliceToArray(data2));
refill$boxed_Box_slice_u8(rt.place(() => a, (value2) => a = value2), _49);
rt.byteSliceView(a).reverse();
bytes(a, out);
let w: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, half))), (_216: rt.u8): rt.u16 => {
return rt.u16Mul(_216 as rt.u16, 257);
}), undefined, 2, true);
const v: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, 0, rt.usizeSub(data2.length, half)))), (_218: rt.u8): rt.u16 => {
return (((_218 as rt.u16)) << 3) & 0xffff;
}), undefined, 2, true);
w = rt.boxSliceCloneFrom(w, v);
w.reverse();
wides(w, out);
wides(v, out);
const _82: rt.u16[] = [1, 2, 3];
w = rt.boxSliceCloneFrom(w, _82);
wides(w, out);
let p: [rt.u8, rt.u16][] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, 0, half))), (_220: rt.u8): [rt.u8, rt.u16] => {
return [_220, 7] as [rt.u8, rt.u16];
}), undefined, 4, true);
const q: [rt.u8, rt.u16][] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, half, rt.usizeMul(half, 2)))), (_221: rt.u8): [rt.u8, rt.u16] => {
return [_221 ^ 1, 9] as [rt.u8, rt.u16];
}), undefined, 4, true);
p = rt.boxSliceCloneFrom(p, q, copy$tuple2_u8_u16);
const _102: [rt.u8, rt.u16] | undefined = rt.sliceFirst(p);
if (_102 !== undefined) {
_102[0] = 51;
_102[1] = 68;
}
const iter: rt.Iter<[rt.u8, rt.u16]> = rt.iterChain(rt.iterSlice(p), rt.iterSlice(q));
while (true) {
const _113: [rt.u8, rt.u16] | rt.Done = iter.next();
if (_113 === rt.DONE) {
break;
}
rt.byteVecPush(out, _113[0]);
rt.iterExtendBytes(out, rt.iterSlice(rt.u16ToBeBytes(_113[1]).reverse()), undefined, true);
}
let s: string[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, 0, half))), (_222: rt.u8): string => {
return text(rt.byteSliceFrom(Uint8Array.of(_222)));
}), undefined, 12, true);
const t: string[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, half, rt.usizeMul(half, 2)))), (_223: rt.u8): string => {
const x11: rt.u8 = _223;
return text(rt.byteSliceFrom(Uint8Array.of(x11, x11)));
}), undefined, 12, true);
s = rt.boxSliceCloneFrom(s, t);
const _138: rt.Place<string> | undefined = rt.sliceFirstMut(s);
if (_138 !== undefined) {
_138.v = _138.v + "!";
}
const iter2: rt.Iter<string> = rt.iterChain(rt.iterSlice(s), rt.iterSlice(t));
while (true) {
const _150: string | rt.Done = iter2.next();
if (_150 === rt.DONE) {
break;
}
fmt_put(out, _150);
}
let l: boxes_Logged.Logged[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, 0, half))), (_224: rt.u8): boxes_Logged.Logged => {
return logged(_224 & 126);
}), undefined, 8, true);
const m: boxes_Logged.Logged[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, half, rt.usizeMul(half, 2)))), (_226: rt.u8): boxes_Logged.Logged => {
return logged(_226 | 1);
}), undefined, 8, true);
flush(log.value, out);
l = rt.boxSliceCloneFrom(l, m, boxes_Logged.clone$Clone, rt.drop);
flush(log.value, out);
ids(l, out);
const _187: boxes_Logged.Logged[] = [logged(16), logged(18), logged(20)];
refill$boxed_Box_slice_boxes_Logged(rt.place(() => l, (value3) => l = value3), _187);
rt.dropAll(_187);
flush(log.value, out);
ids(l, out);
const held: boxes_Held.Held = new boxes_Held.Held(rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data2, 0, rt.usizeSub(data2.length, half)))), (_227: rt.u8): boxes_Logged.Logged => {
return logged(_227 & 126);
}), undefined, 8, true), logged(80));
flush(log.value, out);
held.items = rt.boxSliceCloneFrom(held.items, m, boxes_Logged.clone$Clone, rt.drop);
flush(log.value, out);
ids(held.items, out);
held[Symbol.dispose]();
flush(log.value, out);
const v2: rt.ByteSlice[] = [rt.byteSliceFrom(rt.byteSliceToArray(rt.byteSliceRange(data2, 0, half))), rt.byteSliceFrom(rt.byteSliceToArray(data2))];
const at = rt.idx(v2, 1);
v2[at] = rt.byteBoxSliceCloneFrom(v2[at], b);
const at2 = rt.idx(v2, 0);
v2[at2] = rt.byteBoxSliceCloneFrom(v2[at2], a);
for (const _252 of v2) {
bytes(_252, out);
}
rt.dropAll(l);
rt.dropAll(m);
flush(log.value, out);
let t2: string = "ab";
t2 = text(data2);
fmt_put(out, t2);
} else if (_23 === 1) {
let a2: rt.ByteSlice = rt.byteSliceFrom(rt.byteSliceToArray(data2));
bytes(a2, out);
rt.byteSliceView(a2).reverse();
flip$boxed_Box_slice_u8(rt.place(() => a2, (value) => a2 = value));
rt.byteVecPush(out, sum$boxed_Box_slice_u8(a2));
bytes(a2, out);
let n: rt.u32 = data2.length as rt.u32;
n = rt.u32Add(n, 7);
rt.iterExtendBytes(out, rt.iterSlice(rt.u32ToBeBytes(n).reverse()), undefined, true);
const pair: [rt.u8, rt.u16] = [option_unwrapOr$0r2bmpr(rt.byteSliceFirst(data2), 1), 2];
const _306: [rt.u8, rt.u16] = pair;
_306[1] = _306[1] ^ 257;
const copy: [rt.u8, rt.u16] = copy$tuple2_u8_u16(pair);
pair[0] = 9;
rt.byteVecPush(out, copy[0]);
rt.iterExtendBytes(out, rt.iterSlice(rt.u16ToBeBytes(copy[1]).reverse()), undefined, true);
rt.byteVecPush(out, pair[0]);
const array: Uint8Array = Uint8Array.of(1, 2, 3, 4);
const _322: rt.ByteSlice = rt.byteSliceFrom(array);
const _324: rt.usize = rt.usizeRem(kind as rt.usize, 4);
if (!(_324 < 4)) {
rt.panic("index out of bounds: the len is " + 4 + " but the index is " + _324);
}
_322.data[_322.start + _324] = 85;
rt.byteSliceView(rt.byteSliceFrom(array)).reverse();
bytes(rt.byteSliceFrom(array), out);
const v3: rt.ByteVec = rt.byteSliceToByteVec(data2);
rt.byteVecPush(v3, 102);
bytes(rt.byteVecSlice(v3), out);
let s2: string = text(data2);
s2 = s2 + "#";
fmt_put(out, s2);
const w2: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data2)), (_28: rt.u8): rt.u16 => {
return rt.u16Add(_28 as rt.u16, 1);
}), undefined, 2, true);
rt.sliceSort(w2, rt.lt);
wides(w2, out);
const l2: boxes_Logged.Logged[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data2)), (_214: rt.u8): boxes_Logged.Logged => {
return logged(_214);
}), undefined, 8, true);
const _368: boxes_Logged.Logged[] = l2;
if (_368.length >= 2) {
const swapped = _368[0];
_368[0] = _368[_368.length - 1];
_368[_368.length - 1] = swapped;
}
ids(l2, out);
let o: rt.u8 | undefined = rt.byteSliceFirst(data2);
if (o !== undefined) {
o = rt.u8WrappingAdd(o, 1);
}
rt.byteVecPush(out, option_unwrapOr$0r2bmpr(o, 238));
rt.dropAll(l2);
} else if (_23 === 2) {
const _395: rt.ByteSlice = rt.byteSliceFrom(rt.byteSliceToArray(data2));
boxed$3_boxed_Box_slice_u8(_395.length === 3 ? rt.Ok(rt.byteSliceView(_395)) : rt.Err(_395), out);
const _398: rt.ByteSlice = rt.byteSliceFrom(rt.byteSliceToArray(data2));
boxed$0_boxed_Box_slice_u8(_398.length === 0 ? rt.Ok(rt.byteSliceView(_398)) : rt.Err(_398), out);
const _400: rt.ByteVec = rt.byteSliceToByteVec(data2);
const r: rt.Result<Uint8Array, rt.ByteVec> = _400.length === 2 ? rt.Ok(rt.byteSliceView(rt.byteVecSlice(_400))) : rt.Err(_400);
if (r.ok) {
bytes(rt.byteSliceFrom(r.value), out);
} else {
const v4: rt.ByteVec = r.error;
rt.byteVecPush(v4, 119);
bytes(rt.byteVecSlice(v4), out);
}
const spare: rt.ByteVec = rt.byteVecWithCapacity(32);
rt.byteVecExtendFromSlice(spare, data2);
const _417: rt.ByteVec = spare;
boxed$4_Vec_u8(_417.length === 4 ? rt.Ok(rt.byteSliceView(rt.byteVecSlice(_417))) : rt.Err(_417), out);
const w3: rt.u16[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data2)), (_2: rt.u8): rt.u16 => {
return rt.u16Mul(_2 as rt.u16, 3);
}), undefined, 2, true);
const _422: rt.Result<rt.u16[], rt.u16[]> = w3.length === 2 ? rt.Ok(w3) : rt.Err(w3);
if (_422.ok) {
const a4: rt.u16[] = _422.value;
a4[1] = 4660;
wides(a4, out);
} else {
wides(_422.error, out);
}
const l3: boxes_Logged.Logged[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data2)), (_22: rt.u8): boxes_Logged.Logged => {
return logged(_22 & 126);
}), undefined, 8, true);
const _438: rt.Result<boxes_Logged.Logged[], boxes_Logged.Logged[]> = l3.length === 2 ? rt.Ok(l3) : rt.Err(l3);
if (_438.ok) {
const a5: boxes_Logged.Logged[] = _438.value;
ids(a5, out);
flush(log.value, out);
rt.dropAll(a5);
} else {
const l4: boxes_Logged.Logged[] = _438.error;
ids(l4, out);
flush(log.value, out);
rt.dropAll(l4);
}
flush(log.value, out);
const l5: boxes_Logged.Logged[] = rt.iterToArray(rt.iterMap(rt.iterSlice(rt.byteSliceView(data2)), (_25: rt.u8): boxes_Logged.Logged => {
return logged(_25 | 1);
}), undefined, 8, true);
const r2: rt.Result<boxes_Logged.Logged[], boxes_Logged.Logged[]> = l5.length === 1 ? rt.Ok(l5) : rt.Err(l5);
flush(log.value, out);
drop$Result_boxed_Box_array1_boxes_Logged_boxed_Box_slice_boxes_Logged(r2);
flush(log.value, out);
} else {
const s3: string = text(data2);
const a6: rt.ByteSlice = rt.stringAsBytes(s3);
rt.byteSliceView(a6).reverse();
bytes(a6, out);
const b2: rt.ByteSlice = rt.stringAsBytes(s3);
const _485: rt.Place<rt.u8> | undefined = rt.sliceLastMut(rt.byteSliceView(b2));
if (_485 !== undefined) {
_485.v = 33;
}
bytes(b2, out);
const v5: rt.ByteVec = rt.byteSliceToByteVec(rt.stringAsBytes(s3));
rt.byteVecPush(v5, 46);
bytes(rt.byteVecSlice(v5), out);
bytes(rt.stringAsBytes(""), out);
}
log[Symbol.dispose]();
}

//# sourceMappingURL=boxes.ts.map
Loading