@yabgu_gm/tensionscript 0.13.2 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8075,6 +8075,300 @@ declare module "types:tensionscript/src/builtins" {
8075
8075
  /** Compiles runtime type information for use by stdlib. */
8076
8076
  export function compileRTTI(compiler: Compiler): void;
8077
8077
  }
8078
+ declare module "types:tensionscript/src/dwarf/leb" {
8079
+ /**
8080
+ * @fileoverview LEB128 and byte writing, shared by the wasm readers and the
8081
+ * DWARF encoder. Port of `tension-core/src/leb.rs` and the `cstr` helper in
8082
+ * `tension-core/src/dwarf/encode.rs`.
8083
+ * @license Apache-2.0
8084
+ */
8085
+ /** A growable byte sink. Rust's `Vec<u8>` has no direct counterpart here. */
8086
+ export class ByteWriter {
8087
+ buf: Uint8Array;
8088
+ len: number;
8089
+ constructor(capacity?: number);
8090
+ private grow;
8091
+ push(byte: number): void;
8092
+ /** Appends `data[0..data.length]`. */
8093
+ bytes(data: Uint8Array): void;
8094
+ /** Appends `data[start..end]`, the Rust `extend_from_slice(&slice[a..b])`. */
8095
+ slice(data: Uint8Array, start: number, end: number): void;
8096
+ /** Unsigned LEB128. Values here are addresses and lengths, so 32 bits suffice. */
8097
+ uleb(value: number): void;
8098
+ /**
8099
+ * Signed LEB128. Rust writes line deltas as `i64`; every value here is a
8100
+ * source-line difference, which fits `i32`, and SLEB128's terminating
8101
+ * condition makes the two widths encode identically for such values.
8102
+ */
8103
+ sleb(value: number): void;
8104
+ u16le(value: number): void;
8105
+ u32le(value: number): void;
8106
+ /** A NUL-terminated UTF-8 string, the Rust `cstr`. */
8107
+ cstr(text: string): void;
8108
+ /** UTF-8 bytes with no terminator (a wasm name, a DWARF file path). */
8109
+ utf8(text: string): void;
8110
+ /** The written bytes as their own array. */
8111
+ finish(): Uint8Array;
8112
+ }
8113
+ }
8114
+ declare module "types:tensionscript/src/dwarf/source-map" {
8115
+ /**
8116
+ * @fileoverview The source-map v3 side: a purpose-built JSON reader and the
8117
+ * mappings (base64 VLQ) decoder. Port of
8118
+ * `tension-core/src/dwarf/source_map.rs`.
8119
+ * @license Apache-2.0
8120
+ */
8121
+ /** One source-map segment: wasm file offset -> source line/column. */
8122
+ export class Seg {
8123
+ addr: number;
8124
+ file: number;
8125
+ line: number;
8126
+ col: number;
8127
+ constructor(addr: number, file: number, line: number, col: number);
8128
+ }
8129
+ export class SourceMap {
8130
+ sources: string[];
8131
+ segments: Seg[];
8132
+ constructor(sources: string[], segments: Seg[]);
8133
+ }
8134
+ /** Decode one comma-free group of base64 VLQ digits. */
8135
+ export function vlq(text: string): number[];
8136
+ /**
8137
+ * Decode `mappings`. Generated columns are absolute wasm file offsets.
8138
+ *
8139
+ * The source-map spec resets the generated column to 0 at each `;`-separated
8140
+ * line group; source line, source column and file index keep accumulating
8141
+ * across groups.
8142
+ */
8143
+ export function parseMappings(mappings: string, sourceCount: number): Seg[];
8144
+ /** Read `sources` and `mappings` out of a source-map v3 document. */
8145
+ export function parseSourceMap(json: string): SourceMap;
8146
+ }
8147
+ declare module "types:tensionscript/src/dwarf/wasm-layout" {
8148
+ /**
8149
+ * @fileoverview Parsing the guest module: the section walk, code bodies, the
8150
+ * `name` section, and everything synthesis needs from all of it. Port of
8151
+ * `tension-core/src/dwarf/wasm.rs`.
8152
+ *
8153
+ * D8 measured the alternative — taking function and local names from the
8154
+ * compiler's in-memory state — and rejected it: Binaryen owns the emitted
8155
+ * function and local indices (it renames through its own passes), and the
8156
+ * compiler's `FunctionRef`/`Local` keys are not the emitted index space. The
8157
+ * emitted `name` section is the only faithful source, so it is parsed here
8158
+ * exactly as the host parses it.
8159
+ * @license Apache-2.0
8160
+ */
8161
+ /** A cursor over bytes, the Rust `Reader`. */
8162
+ export class Reader {
8163
+ b: Uint8Array;
8164
+ i: number;
8165
+ constructor(b: Uint8Array, i: number);
8166
+ u8(): number;
8167
+ uleb(): number;
8168
+ name(): string;
8169
+ }
8170
+ /**
8171
+ * A wasm value type we can describe to a debugger. `None` is the Rust
8172
+ * `Option<ValType>::None` — everything else (`v128`, reference types) has no
8173
+ * DWARF base type here and is left undescribed.
8174
+ */
8175
+ export enum ValType {
8176
+ None = -1,
8177
+ I32 = 0,
8178
+ I64 = 1,
8179
+ F32 = 2,
8180
+ F64 = 3
8181
+ }
8182
+ export function valTypeFromByte(b: number): ValType;
8183
+ export function valTypeName(ty: ValType): string;
8184
+ /** `DW_AT_encoding`: signed integer or IEEE float. */
8185
+ export function valTypeEncoding(ty: ValType): number;
8186
+ export function valTypeByteSize(ty: ValType): number;
8187
+ /** A body's `[start, end)` file offsets. */
8188
+ export class BodyRange {
8189
+ start: number;
8190
+ end: number;
8191
+ constructor(start: number, end: number);
8192
+ }
8193
+ /** One `(count, valtype)` local-declaration group. */
8194
+ export class LocalDecl {
8195
+ count: number;
8196
+ ty: number;
8197
+ constructor(count: number, ty: number);
8198
+ }
8199
+ /** A local in index order: name, index, value type (null when undescribable). */
8200
+ export class LocalInfo {
8201
+ name: string;
8202
+ index: number;
8203
+ ty: ValType;
8204
+ constructor(name: string, index: number, ty: ValType);
8205
+ }
8206
+ /** A `name` section entry. */
8207
+ export class NamedEntry {
8208
+ index: number;
8209
+ name: string;
8210
+ constructor(index: number, name: string);
8211
+ }
8212
+ /** A local-name entry: function index, local index, name. */
8213
+ export class LocalNameEntry {
8214
+ func: number;
8215
+ index: number;
8216
+ name: string;
8217
+ constructor(func: number, index: number, name: string);
8218
+ }
8219
+ /** A `(params, results)` function type, as valtype bytes. */
8220
+ export class FuncType {
8221
+ params: number[];
8222
+ results: number[];
8223
+ constructor(params: number[], results: number[]);
8224
+ }
8225
+ /** What the synthesizer must learn from the guest module itself. */
8226
+ export class Layout {
8227
+ /** File offset of the code section payload: DWARF address 0. */
8228
+ codePayloadStart: number;
8229
+ /** Payload size; also the exclusive end of the address space. */
8230
+ codePayloadSize: number;
8231
+ /** Body content `[start, end)` in file offsets, one per defined function. */
8232
+ bodies: BodyRange[];
8233
+ /** Body local declarations, parallel to `bodies`. */
8234
+ bodyDecls: LocalDecl[][];
8235
+ /** Functions declared in the import section; the index space starts there. */
8236
+ importedFuncs: number;
8237
+ /** `name` section function names by function index. */
8238
+ names: NamedEntry[];
8239
+ /** `name` section local names: function index, local index, name. */
8240
+ localNames: LocalNameEntry[];
8241
+ /** Function type indices from the function section, one per defined function. */
8242
+ funcTypes: number[];
8243
+ /** Function types from the type section. */
8244
+ types: FuncType[];
8245
+ /** Name of the function defined by body `i`, if the guest kept names. */
8246
+ nameForBody(body: number): string | null;
8247
+ /**
8248
+ * A guest local in index order: the function's parameters first, then the
8249
+ * body's declarations. `name` is what `asc --debug` kept in the `name`
8250
+ * section (subsection 2) when present, else a fallback.
8251
+ */
8252
+ localsForBody(body: number): LocalInfo[];
8253
+ private localName;
8254
+ }
8255
+ /** The two parallel arrays `readCodeBodies` produces. */
8256
+ export class CodeBodies {
8257
+ bodies: BodyRange[];
8258
+ decls: LocalDecl[][];
8259
+ }
8260
+ /** Walk the module and collect everything synthesis needs. */
8261
+ export function parseLayout(wasm: Uint8Array): Layout;
8262
+ }
8263
+ declare module "types:tensionscript/src/dwarf/encode" {
8264
+ /**
8265
+ * @fileoverview The DWARF 4 encoder: abbreviations, the line program,
8266
+ * `.debug_info` DIEs, and the custom-section wrapper. Port of
8267
+ * `tension-core/src/dwarf/encode.rs`.
8268
+ * @license Apache-2.0
8269
+ */
8270
+ import { ByteWriter } from "types:tensionscript/src/dwarf/leb";
8271
+ import { Seg } from "types:tensionscript/src/dwarf/source-map";
8272
+ import { LocalInfo, ValType } from "types:tensionscript/src/dwarf/wasm-layout";
8273
+ /** One subprogram: its name and payload-relative `[lo, hi)` address. */
8274
+ export class FunctionRange {
8275
+ name: string;
8276
+ lo: number;
8277
+ hi: number;
8278
+ constructor(name: string, lo: number, hi: number);
8279
+ }
8280
+ /** A payload-relative `[start, end)` interval. */
8281
+ export class Range {
8282
+ start: number;
8283
+ end: number;
8284
+ constructor(start: number, end: number);
8285
+ }
8286
+ /**
8287
+ * Abbrev 1: compile unit. Abbrev 2: subprogram. Abbrev 3: subprogram with
8288
+ * children. Abbrev 4: base type. Abbrev 5: variable. No `strp`, so no
8289
+ * `.debug_str`; type references are `DW_FORM_ref4` within the unit.
8290
+ */
8291
+ export function encodeDebugAbbrev(): Uint8Array;
8292
+ /**
8293
+ * Turn an AssemblyScript source-map path into one the symbol root resolves.
8294
+ * `asc` writes library sources as `~lib/...`, which no debugger understands.
8295
+ *
8296
+ * The Rust original also probes the filesystem and prefers
8297
+ * `node_modules/assemblyscript/std/assembly/...` when that directory exists.
8298
+ * The compiler has no filesystem access, so the probe collapses to the
8299
+ * fallback branch - which is what the host produced for the baseline fixture
8300
+ * (neither probed path exists in a TensionScript project: the package ships
8301
+ * its stdlib as `@yabgu_gm/tensionscript/std/assembly`).
8302
+ */
8303
+ export function sourcePath(raw: string, compDir: string): string;
8304
+ /**
8305
+ * A DWARF v4 line program. `rows` must be sorted ascending by address.
8306
+ * `ranges` are the payload-relative body ranges, one line sequence each.
8307
+ */
8308
+ export function encodeDebugLine(compDir: string, sources: string[], rows: Seg[], ranges: Range[]): Uint8Array;
8309
+ /**
8310
+ * One `DW_TAG_subprogram` per defined function the name section knows about,
8311
+ * and one `DW_TAG_variable` child per wasm local whose type we can describe.
8312
+ * `locals` is parallel to `functions`.
8313
+ */
8314
+ export function encodeDebugInfo(moduleName: string, compDir: string, functions: FunctionRange[], locals: LocalInfo[][]): Uint8Array;
8315
+ /** Position of a `ValType` in the base-type DIE order, for `typeOffsets`. */
8316
+ export function typeIndex(ty: ValType): number;
8317
+ /**
8318
+ * Append a custom section to `out`: id, size, name length, name, payload -
8319
+ * where `size` counts everything after itself.
8320
+ */
8321
+ export function appendCustom(out: ByteWriter, name: string, payload: Uint8Array): void;
8322
+ }
8323
+ declare module "types:tensionscript/src/dwarf/index" {
8324
+ /**
8325
+ * @fileoverview DWARF synthesis for TensionScript guests, compiler side.
8326
+ *
8327
+ * Port of `tension-core/src/dwarf/mod.rs` (`synthesize`) and the module
8328
+ * comment that explains it. The host rebuilt this from a guest's `name`
8329
+ * section and source map because `asc` emitted no DWARF; the compiler now
8330
+ * carries the same code, so a guest ships its own `.debug_*` sections.
8331
+ *
8332
+ * Address convention (measured, not assumed): a guest DWARF code address is a
8333
+ * byte offset from the start of the code section payload - address 0 is the
8334
+ * first byte of the function-count LEB.
8335
+ *
8336
+ * The encoder is a verbatim port, including the range-splitting rule: the
8337
+ * compile unit's `DW_AT_ranges` entries are intervals between line rows, not
8338
+ * whole bodies, because cranelift emits a function's natives in an order that
8339
+ * is not monotonic in wasm addresses. Its range translation only sees the
8340
+ * ranges active at an entry's start and end addresses, so a whole-body entry
8341
+ * hides any internal range that begins and ends strictly inside it, and lldb
8342
+ * drops line rows that fall in the resulting holes.
8343
+ * @license Apache-2.0
8344
+ */
8345
+ /** What synthesis produced, for the caller's diagnostics. */
8346
+ export class SynthesisResult {
8347
+ bytes: Uint8Array;
8348
+ files: number;
8349
+ rows: number;
8350
+ functions: number;
8351
+ locals: number;
8352
+ dropped: number;
8353
+ constructor(bytes: Uint8Array, files: number, rows: number, functions: number, locals: number, dropped: number);
8354
+ }
8355
+ /**
8356
+ * Copy `wasm` with synthesized `.debug_abbrev`, `.debug_info`, `.debug_line`
8357
+ * and `.debug_ranges` appended: line tables for source breakpoints, function
8358
+ * DIEs for the call stack, and variable DIEs for locals.
8359
+ *
8360
+ * `compDir` becomes the DWARF compile directory and the base for every
8361
+ * file-table entry. `moduleName` becomes the unit's `DW_AT_name`.
8362
+ *
8363
+ * Throws `Error` on malformed input. The Rust original returned
8364
+ * `Result<_, String>`; a throw is the idiomatic equivalent here, and the
8365
+ * caller decides whether a failed synthesis is fatal (the compiler treats it
8366
+ * as a warning and emits the undecorated module).
8367
+ */
8368
+ export function synthesize(wasm: Uint8Array, sourceMapJson: string, compDir: string, moduleName: string): Uint8Array;
8369
+ /** `synthesize` plus the counts the host used to log. */
8370
+ export function synthesizeVerbose(wasm: Uint8Array, sourceMapJson: string, compDir: string, moduleName: string): SynthesisResult;
8371
+ }
8078
8372
  declare module "types:tensionscript/src/module" {
8079
8373
  /**
8080
8374
  * @fileoverview A thin wrapper around Binaryen's C-API.
@@ -9459,7 +9753,16 @@ declare module "types:tensionscript/src/module" {
9459
9753
  optimize(optimizeLevel: number, shrinkLevel: number, debugInfo?: boolean, zeroFilledMemory?: boolean): void;
9460
9754
  validate(): boolean;
9461
9755
  interpret(): void;
9462
- toBinary(sourceMapUrl?: string | null): BinaryModule;
9756
+ /**
9757
+ * Emits the module.
9758
+ *
9759
+ * When `debugInfo` is set *and* a source map is requested, the emitted bytes
9760
+ * gain synthesized DWARF (`.debug_abbrev`, `.debug_info`, `.debug_line`,
9761
+ * `.debug_ranges`) - the same sections `tension-core` used to rebuild from
9762
+ * the guest's source map. A host that already ships DWARF (a C or Rust
9763
+ * guest) is unaffected: this only decorates a module this compiler emits.
9764
+ */
9765
+ toBinary(sourceMapUrl?: string | null, debugInfo?: boolean, compDir?: string, moduleName?: string): BinaryModule;
9463
9766
  toText(watFormat?: boolean): string;
9464
9767
  private cachedStringsToPointers;
9465
9768
  private cachedPointersToStrings;
@@ -12688,6 +12991,14 @@ declare module "types:tensionscript/src/index-wasm" {
12688
12991
  /** Sets the `pedantic` option. */
12689
12992
  export function setPedantic(options: Options, pedantic: boolean): void;
12690
12993
  export function setDebugInfo(options: Options, debug: boolean): void;
12994
+ /**
12995
+ * Appends synthesized DWARF (`.debug_abbrev`, `.debug_info`, `.debug_line`,
12996
+ * `.debug_ranges`) to an emitted module and returns the augmented bytes.
12997
+ *
12998
+ * Exposed for hosts that emit through Binaryen's own writer rather than
12999
+ * `Module#toBinary` - the CLI does exactly that. See `src/dwarf/`.
13000
+ */
13001
+ export function synthesizeDwarf(wasmBytes: Uint8Array, sourceMapJson: string, compDir: string, moduleName: string): Uint8Array;
12691
13002
  /**
12692
13003
  * Runs the compiler's own in-tree `afterParse` transforms (closure lowering,
12693
13004
  * then async lowering) over a program.