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/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md);
- [Async in the TypeScript translator](/quest/m2/ts-async.md) - moq-net's and kio's async code translates with Rust's lazy futures
- [Shared ownership](/quest/m2/ts-shared.md) - `Arc`/`Rc`/`Weak` keep exact counts, and locks and atomics become plain values
- [Copy what a container stores](/quest/m2/ts-store-alias.md) - `push` and other stores of a `Copy` aggregate copy it instead of sharing it
- [str and String methods over char](/quest/m2/ts-str-char.md) - `chars`, `char` patterns, and `String::push` translate, unblocking `ietf/namespace.rs`
- [Share a held-back read across a call](/quest/m2/ts-shared-read.md) - `leading-ones` decode recovers what #83's copy fix cost
- [Output tsc accepts for writes through Result and Poll compares](/quest/m2/ts-tsc-shapes.md) - two shapes whose output fails `tsc` type-check
- [Translate moq-net's model to TypeScript](/quest/m2/ts-model.md) - the driver grows from moq-net's codec to its model, for moq to compare against WASM
Expand Down
18 changes: 0 additions & 18 deletions quest/m2/ts-str-char.md

This file was deleted.

15 changes: 12 additions & 3 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ Each Rust module with translated items becomes a file (`lib.ts`, `coding/varint.
and each type a module of its own beside it, holding the type and its functions
(`coding/decode.Decoder.ts`), each with a `.ts.map` source map into the Rust it came
from. `rt.ts` beside them is the
runtime: what std does that JS does not, with iterators in `rt/iter.ts`, collections in
`rt/collections.ts`, and ownership and async in `rt/task.ts`.
runtime: what std does that JS does not, with iterators in `rt/iter.ts`, `str`'s searches
in `rt/str.ts`, collections in `rt/collections.ts`, and ownership and async in
`rt/task.ts`.

| Rust | TypeScript |
| --- | --- |
Expand Down Expand Up @@ -123,6 +124,13 @@ range's bounds, with no `rt.Iter` made. The crate's own `impl Iterator` returns
std's adaptors through `rt.iterFrom`. A caller calls `next()` for one item, or iterates
an `rt.Iter` with `for ... of`.

A `str` is a JS string, which is UTF-16: `chars` steps by code point, and a search by a
`char` or a predicate, as in `rt.strSplit(s, "/")`, takes the char's text or the closure,
which it calls on each char it reads, in the order std reads them. An offset it returns,
from `rfind` or `match_indices`, counts UTF-8 bytes, as Rust's does. A JS string can't
change in place, so `String::push` assigns a longer one to the local or field the `&mut`
borrows.

Functions and members are camelCase. Functions are monomorphized: each instance is its
own function, suffixed after a `$` by its trait, then by its type's type arguments and
its own, as in `roundtripLite$Group`, `Wrap.get$Wrap_Pair`, `Pair.fmt$Debug`, and
Expand Down Expand Up @@ -303,7 +311,8 @@ holds that JS copies kept other than to read and write it, `Hasher::write` of by
without a mapping in `src/lower/iter.rs` (such as `cycle`, `unzip`, and `partition`), an
own `impl Iterator` with `next_back`, `len`, or another provided method of its own, other
format specs (a precision, `+`, `{:b}`, `{:x?}`, and widths from arguments), writing to a
`String` with `write!`, a copy of a closure that changes what it captured, `mem::swap`,
`String` with `write!` or pushing to one through a parameter, a `str` pattern other than a
`char` or a predicate, a copy of a closure that changes what it captured, `mem::swap`,
`replace`, or `take` of a reference's whole pointee, assigning an `Arc`, a waker, a
`MutexGuard`, a pinned reference, or a future through a reference, a switch on or a
field of another crate's type without a mapping, and std functions without a mapping in
Expand Down
5 changes: 4 additions & 1 deletion ts/fixtures/lang/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op,
import { adaptors, consumers, ranges, options, own, values } from "./iters.ts";
import { keys } from "./keys.ts";
import { copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts";
import { strs } from "./strs.ts";

/** Run one case. */
export function run(input: Uint8Array): rt.ByteVec {
Expand All @@ -19,7 +20,7 @@ export function run(input: Uint8Array): rt.ByteVec {
const _10: [rt.u8, rt.u8] = [input[0], input[1]];
const op: rt.u8 = _10[0];
const kind: rt.u8 = _10[1];
const _14: rt.u8 = rt.u8Rem(op, 42);
const _14: rt.u8 = rt.u8Rem(op, 43);
if (_14 === 0) {
u8Op(kind, input.subarray(2, input.length - 0), out);
} else if (_14 === 1) {
Expand Down Expand Up @@ -120,6 +121,8 @@ export function run(input: Uint8Array): rt.ByteVec {
keys(kind, input.subarray(2, input.length - 0), out);
} else if (_14 === 40) {
chars(kind, input.subarray(2, input.length - 0), out);
} else if (_14 === 41) {
strs(kind, input.subarray(2, input.length - 0), out);
} else {
vecs(input.subarray(2, input.length - 0), out);
}
Expand Down
13 changes: 13 additions & 0 deletions ts/fixtures/lang/expected/strs.Named.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Generated by rust2-ts. Do not edit.

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

export interface Named {
name: string;
}

export function add(self: Named, c: rt.char): void {
self.name = self.name + String.fromCodePoint(c);
}

//# sourceMappingURL=strs.Named.ts.map
Loading