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,6 +34,5 @@ generic std gap is planned here even when moq never calls it.
- [A VecDeque's Debug](/quest/m3/ts-deque-debug.md) - `{:?}` of a `VecDeque` translates, writing std's list
- [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - an instance whose lowering drops every read of a parameter marks it unused, so `tsc` accepts it
- [std's impls of its zero-sized types](/quest/m3/ts-zero-sized-impls.md) - `PhantomData`'s derived impls translate, and `()` is a hash or B-tree key
- [An array's map](/quest/m3/ts-array-map.md) - `<[T; N]>::map` translates, calling its closure on each element in order
- [Array keys a collection holds](/quest/m3/ts-array-keys.md) - collections of `[T; N]` keys type-check
- [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
16 changes: 0 additions & 16 deletions quest/m3/ts-array-map.md

This file was deleted.

231 changes: 230 additions & 1 deletion ts/fixtures/lang/expected/arrays.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { copy$u32s, copy$u8s } from "./lib.ts";
import { copy$u32s, copy$u8s, copy$u8ss } from "./lib.ts";
import { map$1j8xzu6, map$0rbsrz6 } from "./core/option.ts";

/** Each byte an operation, its value the operand; each puts what it read. */
export function fromFns(data: rt.ByteSlice, out: rt.ByteVec): void {
Expand Down Expand Up @@ -95,6 +96,234 @@ export function counted$5(op: rt.u8): rt.usize[] {
});
}

/**
* Arrays `map` makes, calling its closure on each element in order; each byte an
* operation, its value the operand. From bytes and to them, of none at all, through what
* the closure captured by reference and by move, of `Option`s whose `None` is `rt.None`,
* and of arrays, each element the closure's own to change.
*/
export function maps(data: rt.ByteSlice, out: rt.ByteVec): void {
let s!: string;
for (const op of rt.byteSliceView(data)) {
const _10: rt.u8 = rt.u8Rem(op, 5);
if (_10 === 0) {
const seen: rt.ByteVec = new rt.ByteVec();
const bytes: Uint8Array = Uint8Array.of(op, op ^ 1, op ^ 2, op ^ 3);
const wide: rt.u16[] = rt.arrayMap(bytes, (b2: rt.u8): rt.u16 => {
rt.byteVecPush(seen, b2);
return ((((b2 as rt.u16)) << 8) & 0xffff) | op as rt.u16;
});
const narrow: Uint8Array = rt.bytesMap(wide, (w3: rt.u16): rt.u8 => {
return (w3 >> 4) & 0xff;
});
const same: Uint8Array = rt.bytesMap(narrow, (b3: rt.u8): rt.u8 => {
return rt.u8WrappingMul(b3, op);
});
const words: rt.u32[] = rt.arrayMap([op as rt.u32, 7, 9], (w4: rt.u32): rt.u32 => {
return rt.u32WrappingMul(w4, 16777619);
});
const _31: rt.ByteSlice = rt.byteSliceFrom(bytes);
const _33: rt.ByteSlice = rt.byteSliceFrom(narrow);
const _34: rt.ByteSlice = rt.byteSliceFrom(same);
const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_31), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(wide, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_33), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_34), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(words, f, rt.u32Debug), (f: rt.Formatter) => rt.fmtList(rt.byteVecView(seen), f, rt.u8Debug)];
s = rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", args2[3], " ", args2[4], " ", args2[5]]);
} else if (_10 === 1) {
const _46: rt.u16[] = rt.arrayMap(Uint8Array.of(), (a0: rt.u8): rt.u16 => {
return a0 as rt.u16;
});
const _47: Uint8Array = rt.bytesMap([], (w2: rt.u16): rt.u8 => {
return w2 & 0xff;
});
const _48: string[] = rt.arrayMap([], (n: rt.u32): string => {
return rt.fmtToString((f: rt.Formatter) => rt.u32Display(n, f));
});
const _53: rt.ByteSlice = rt.byteSliceFrom(_47);
const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(_46, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_53), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(_48, f, rt.fmtStr)];
s = rt.fmtFormat([args4[0], " ", args4[1], " ", args4[2]]);
} else if (_10 === 2) {
const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.u8Display(op, f)];
const captured = rt.fmtFormat(["w", args6[0]]);
const words2: string[] = rt.arrayMap(Uint8Array.of(1, 2, 3), (i: rt.u8): string => {
const args16: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, captured), (f: rt.Formatter) => rt.u8Display(i, f)];
return rt.fmtFormat([args16[0], args16[1]]);
});
const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(words2, f, rt.fmtStr)];
const shown: string = rt.fmtFormat([args8[0]]);
const _89: rt.ByteSlice = rt.byteSliceFrom(rt.bytesMap(words2, (w: string): rt.u8 => {
return rt.u8Add(rt.stringLen(w) & 0xff, rt.u8Rem(op, 3));
}));
const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, shown), (f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_89), f, rt.u8Debug)];
s = rt.fmtFormat([args10[0], " ", args10[1]]);
} else if (_10 === 3) {
const options: Array<rt.u8 | undefined> = [op, undefined, rt.u8WrappingAdd(op, 60)];
const nested: Array<rt.u8 | undefined | rt.None> = rt.arrayMap(options, (o: rt.u8 | undefined): rt.u8 | undefined | rt.None => {
return map$0rbsrz6(o, (b: rt.u8): rt.u8 | undefined => {
return rt.u8CheckedAdd(b, 200);
});
});
const flat: Array<rt.u8 | undefined> = rt.arrayMap(nested, (o2: rt.u8 | undefined | rt.None): rt.u8 | undefined => {
if (o2 === rt.None) {
return 0;
}
return o2;
});
const units: Array<undefined | rt.None> = rt.arrayMap(nested, (o3: rt.u8 | undefined | rt.None): undefined | rt.None => {
return map$1j8xzu6(o3, (_2: rt.u8 | undefined): undefined => {});
});
const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(options, f, (value: rt.u8 | undefined, f: rt.Formatter) => rt.fmtOption(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(nested, f, (value: rt.u8 | undefined | rt.None, f: rt.Formatter) => rt.fmtOption(value, f, (value: rt.u8 | undefined, f: rt.Formatter) => rt.fmtOption(value, f, rt.u8Debug), rt.None)), (f: rt.Formatter) => rt.fmtList(flat, f, (value: rt.u8 | undefined, f: rt.Formatter) => rt.fmtOption(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(units, f, (value: undefined | rt.None, f: rt.Formatter) => rt.fmtOption(value, f, rt.fmtUnit, rt.None))];
s = rt.fmtFormat([args12[0], " ", args12[1], " ", args12[2], " ", args12[3]]);
} else {
const grid: Uint8Array[] = [Uint8Array.of(op, 1), Uint8Array.of(2, 3), Uint8Array.of(4, op)];
const flipped: Uint8Array[] = rt.arrayMap(grid, (row: Uint8Array): Uint8Array => {
row = copy$u8s(row);
row[0] = row[0] ^ 255;
rt.byteSliceView(rt.byteSliceFrom(row)).reverse();
return copy$u8s(row);
});
const sums: rt.u16[] = rt.arrayMap(flipped, (row2: Uint8Array): rt.u16 => {
return rt.u16Add(row2[0] as rt.u16, row2[1] as rt.u16);
});
const same2: Uint8Array[] = copy$u8ss(rt.arrayMap(grid, (row3: Uint8Array): Uint8Array => {
return row3;
}));
const _124: rt.usize = rt.usizeRem(op as rt.usize, 3);
if (!(_124 < 3)) {
rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _124);
}
same2[_124][0] = same2[_124][0] ^ 128;
const _134: rt.u64[] = shifted$3(op);
const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(grid, f, (value: Uint8Array, f: rt.Formatter) => rt.fmtList(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(flipped, f, (value: Uint8Array, f: rt.Formatter) => rt.fmtList(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(sums, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(same2, f, (value: Uint8Array, f: rt.Formatter) => rt.fmtList(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(_134, f, rt.u64Debug)];
s = rt.fmtFormat([args14[0], " ", args14[1], " ", args14[2], " ", args14[3], " ", args14[4]]);
}
rt.byteVecExtendFromSlice(out, rt.stringAsBytes(s));
rt.byteVecPush(out, 10);
}
}

/** An array as long as `N` says, mapped by a function. */
export function shifted$3(op: rt.u8): rt.u64[] {
return rt.arrayMap(rt.bytes(3).fill(op), (a0: rt.u8): rt.u64 => {
return a0 as rt.u64;
});
}

/**
* Arrays' elements lent by `each_ref` and `each_mut`, each byte an operation, its value
* the operand: bytes, wide integers, and strings, each lent as its place, arrays of bytes
* as their views, and other arrays as themselves. Writes through each land in the array.
*/
export function lent(data: rt.ByteSlice, out: rt.ByteVec): void {
const bytes: Uint8Array = rt.bytes(3);
const wide: rt.u16[] = Array.from({ length: 2 }, (): rt.u16 => {
return 0;
});
const words: string[] = ["", ""];
const item = copy$u8s(rt.bytes(2));
const grid: Uint8Array[] = Array.from({ length: 2 }, (): Uint8Array => {
return copy$u8s(item);
});
const item2 = copy$u32s(Array.from({ length: 2 }, (): rt.u32 => {
return 0;
}));
const pairs: rt.u32[][] = Array.from({ length: 2 }, (): rt.u32[] => {
return copy$u32s(item2);
});
for (const op of rt.byteSliceView(data)) {
const i: rt.usize = op as rt.usize;
const _21: rt.u8 = rt.u8Rem(op, 6);
if (_21 === 0) {
const _23: rt.Place<rt.u8>[] = rt.arrayPlaces(rt.byteSliceView(rt.byteSliceFrom(bytes)));
const _25: rt.usize = rt.usizeRem(i, 3);
if (!(_25 < 3)) {
rt.panic("index out of bounds: the len is " + 3 + " but the index is " + _25);
}
_23[_25].v = _23[_25].v ^ op;
const iter2: rt.Iter<rt.Place<rt.u8>> = rt.iterSlice(rt.arrayPlaces(rt.byteSliceView(rt.byteSliceFrom(bytes))));
while (true) {
const _32: rt.Place<rt.u8> | rt.Done = iter2.next();
if (_32 === rt.DONE) {
break;
}
_32.v = rt.u8WrappingAdd(_32.v, 1);
}
} else if (_21 === 1) {
const _40: rt.Place<rt.u16>[] = rt.arrayPlaces(wide);
_40[0].v = rt.u16WrappingAdd(_40[0].v, (((op as rt.u16)) << 7) & 0xffff);
const swapped = _40[0].v;
_40[0].v = _40[1].v;
_40[1].v = swapped;
} else if (_21 === 2) {
const _49: rt.Place<string>[] = rt.arrayPlaces(words);
const _51: rt.usize = rt.usizeRem(i, 2);
if (!(_51 < 2)) {
rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _51);
}
_49[_51].v = _49[_51].v + String.fromCodePoint(rt.u8Add(97, rt.u8Rem(op, 26)) as rt.char);
} else if (_21 === 3) {
const rows: rt.ByteSlice[] = rt.arrayMap(grid, rt.byteSliceFrom);
const _61: rt.usize = rt.usizeRem(i, 2);
if (!(_61 < 2)) {
rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _61);
}
const _64: rt.usize = rt.usizeRem(rt.usizeRem(i, 3), 2);
if (!(_64 < 2)) {
rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _64);
}
const slice = rows[_61];
slice.data[slice.start + _64] = op;
const _71: rt.usize = rt.usizeRem(rt.usizeAdd(i, 1), 2);
if (!(_71 < 2)) {
rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _71);
}
rt.byteSliceView(rows[_71]).reverse();
const _78: rt.u32[][] = rt.arrayFrom(pairs);
const _80: rt.u32 = op as rt.u32;
const _83: rt.usize = rt.usizeRem(i, 2);
if (!(_83 < 2)) {
rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _83);
}
_78[0][_83] = (_80 << 20) >>> 0;
rt.sliceCopyFromSlice(_78[1], [_78[0][1], op as rt.u32]);
} else if (_21 === 4) {
rt.arrayPlaces(rt.byteSliceView(rt.byteSliceFrom(Uint8Array.of())));
const iter3: rt.Iter<rt.Place<rt.u8>> = rt.iterSlice([]);
while (true) {
const _99: rt.Place<rt.u8> | rt.Done = iter3.next();
if (_99 === rt.DONE) {
break;
}
_99.v = op;
}
const lens: Uint8Array = rt.bytesMap(rt.arrayFrom(words), (w: string): rt.u8 => {
return rt.stringLen(w) & 0xff;
});
const rows2: Uint8Array = rt.bytesMap(rt.arrayMap(grid, rt.byteSliceFrom), (row: rt.ByteSlice): rt.u8 => {
return row.data[row.start] ^ row.data[row.start + 1];
});
const sums: rt.u32[] = rt.arrayMap(rt.arrayFrom(pairs), (pair: rt.u32[]): rt.u32 => {
return rt.u32WrappingAdd(pair[0], pair[1]);
});
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(lens));
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rows2));
const _123: rt.usize = rt.usizeRem(i, 2);
if (!(_123 < 2)) {
rt.panic("index out of bounds: the len is " + 2 + " but the index is " + _123);
}
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u32ToBeBytes(sums[_123]).reverse()));
} else {
const read: rt.u8[] = rt.arrayFrom(rt.byteSliceView(rt.byteSliceFrom(bytes)));
const wides: rt.u16[] = rt.arrayFrom(wide);
const _135: rt.u8[] = rt.arrayFrom(rt.byteSliceView(rt.byteSliceFrom(Uint8Array.of())));
const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(read, f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(wides, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(_135, f, rt.u8Debug)];
rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2]])));
}
}
[rt.byteSliceFrom(bytes), wide, words, grid, pairs] as [rt.ByteSlice, rt.u16[], string[], Uint8Array[], rt.u32[][]];
const arg = rt.byteSliceFrom(bytes);
const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(arg), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(wide, f, rt.u16Debug), (f: rt.Formatter) => rt.fmtList(words, f, rt.fmtStr), (f: rt.Formatter) => rt.fmtList(grid, f, (value: Uint8Array, f: rt.Formatter) => rt.fmtList(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(pairs, f, (value: rt.u32[], f: rt.Formatter) => rt.fmtList(value, f, rt.u32Debug))];
rt.byteVecExtendFromSlice(out, rt.stringAsBytes(rt.fmtFormat([args4[0], " ", args4[1], " ", args4[2], " ", args4[3], " ", args4[4]])));
}

/**
* Arrays as slices, of bytes and of other values, empty ones included; each byte an
* operation, its value the operand. Writes through `as_mut_slice` land in the array.
Expand Down
8 changes: 8 additions & 0 deletions ts/fixtures/lang/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ export function map$1diqi3e(self: rt.Place<rt.u8 | undefined> | undefined, f: (a
return undefined;
}

export function map$1j8xzu6(self: rt.u8 | undefined | rt.None, f: (a0: rt.u8 | undefined) => undefined): undefined | rt.None {
if (self === rt.None) {
return rt.None;
}
f(self);
return undefined;
}

export function map$11y9s7r(self: slices_Pair.Pair[] | undefined, f: (a0: slices_Pair.Pair[]) => rt.u8): rt.u8 | undefined {
if (self === undefined) {
return undefined;
Expand Down
8 changes: 6 additions & 2 deletions ts/fixtures/lang/expected/harness.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 { fromFns, asSlices } from "./arrays.ts";
import { fromFns, maps, lent, asSlices } from "./arrays.ts";
import { atomics } from "./atomics.ts";
import { borrows } from "./borrows.ts";
import { bounds } from "./bounds.ts";
Expand Down Expand Up @@ -188,7 +188,11 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec)
uninhabited(data67, out68);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["keys::lent_keys", lentKeys as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["keys::lent_values", lentValues as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["singles::singles", singles as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["singles::formats", singles_formats as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["singles::parses", singles_parses as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["iters::peeked_others", (_2168: rt.u8, data68: rt.ByteSlice, out69: rt.ByteVec): undefined => {
peekedOthers(data68, out69);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["hints::hints", hints as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["hints::reserves", reserves as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::set_ops", setOps as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["folds::folds", folds as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["zeros::zeros", zeros 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], ["hints::hints", hints as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["hints::reserves", reserves as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::set_ops", setOps as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["folds::folds", folds as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["zeros::zeros", zeros as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["arrays::maps", (_2169: rt.u8, data69: rt.ByteSlice, out70: rt.ByteVec): undefined => {
maps(data69, out70);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["arrays::lent", (_2170: rt.u8, data70: rt.ByteSlice, out71: rt.ByteVec): undefined => {
lent(data70, out71);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]];
}

/** Run one case. */
Expand Down
4 changes: 4 additions & 0 deletions ts/fixtures/lang/expected/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ export function copy$u8s(v: Uint8Array): Uint8Array {
return v.slice();
}

export function copy$u8ss(v: Uint8Array[]): Uint8Array[] {
return v.map(copy$u8s);
}

export function copy$units(v: undefined[]): undefined[] {
return v.slice();
}
Expand Down
Loading