TypeScript Backend
First target, used to validate the IR and semantics. Status: v2 — verified;
tsc --strict is clean and the full conformance suite passes in vitest.
Representation
| LT | TypeScript |
|---|---|
Int (i64) | bigint + BigInt.asIntN(64, …) via lt.iadd/isub/imul/idiv/irem/ineg |
Float | number |
Str | string; index/len are counted per code point ([...s]) |
Bool | boolean |
List<T> | lt.LList<T> (immutable, copy-on-write) |
Map<K,V> | lt.LMap<K,V> (entries ordered by Ord, lookup via binary search O(log n)) |
Dict<V> | lt.LDict<V> (string keys, insertion order, Map index) |
fn(A) -> R | (a: A) => R; a lambda becomes an arrow function |
Value | prelude enum value, rendered like a regular enum; json.parse/stringify in lt |
Set<T> | lt.LSet<T> |
Option<T> | lt.Opt<T> = union {tag:"some"|"none", values, __lt_meta} |
Result<T,E> | lt.Res<T,E> = union {tag:"ok"|"err", …} |
enum | a single identifier: export type Enum + export const Enum, variants called as Enum.Variant(...); variant order & display live in the shared Enum_variant |
struct | class with readonly fields, object constructor { field: … }, __lt_eq, __lt_cmp, __lt_to_string; embed fields remain regular fields and widens to users.tableInfo |
| package-level functions | export function name(...) |
| private functions | export function _name(...) — still exported so test files can call them, but marked _ as internal |
| package bindings | export const name: T = … (private: _name) |
package | one module file: src/<package>.ts |
| receiver functions | remain module functions; p.len() is lowered to len(p) |
Display | lt.disp(value); the owning package’s to_string is called by __lt_to_string |
Eq / Ord | lt.eq(a, b) / lt.cmp(a, b) |
? on Result/Option | const t = …; if (t.tag === "err"/"none") return t; |
| template | concatenation + lt.disp(...) |
| tagged template | call to a package-level function with LList<string> + LList<T>; values are not disped |
match | switch (value.tag) |
| JSX | new Struct({ field: …, children: new LList([...]) }) |
expect.eq etc. | lt.expectEqual / expectNotEqual / expectTrue / expectFalse |
test "title" | it("title", …) in tests/<package>.test.ts |
Package structure
out/ts/
_lingua_rt.ts inline runtime (embedded from runtimes/ts/runtime.ts)
package.json
tsconfig.json strict, ES2022, noEmit
src/<package>.ts one file per LT package
tests/<package>.test.ts only from `lt test`
Cross-package imports use the namespace m<id> (import * as m1 from "./user"), so
names never collide. The runtime alias is always lt, and a user declaration named lt is
mangled to lt_.
Naming
- fields, functions, parameters, local variables:
snake_case→camelCase - private functions/bindings:
_prefix (_doubleTwice) - structs, enums, variants: keep
PascalCase - TypeScript keywords get a
_suffix - test titles are used verbatim in
it("…")
Test
lt test -t ts tests/conformance/*.lt --out out/conformance --run
--run runs vitest. tsconfig.json includes tests/**/*.ts, so tsc --strict
also checks the test files.
Limitations
Orderingis not exposed on the language surface yet.- Builtins are only available as receivers (
xs.map(…)), notlist.map(xs, …).