@yabgu_gm/tensionscript 0.13.1 → 0.14.0
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.
- package/dist/asc.generated.d.ts +403 -26
- package/dist/asc.js +5 -5
- package/dist/asc.js.map +3 -3
- package/dist/assemblyscript.generated.d.ts +403 -26
- package/dist/assemblyscript.js +64 -63
- package/dist/assemblyscript.js.map +4 -4
- package/dist/importmap.json +2 -2
- package/dist/web.js +3 -3
- package/package.json +13 -2
package/dist/asc.generated.d.ts
CHANGED
|
@@ -6516,6 +6516,300 @@ declare module "types:tensionscript/src/builtins" {
|
|
|
6516
6516
|
/** Compiles runtime type information for use by stdlib. */
|
|
6517
6517
|
export function compileRTTI(compiler: Compiler): void;
|
|
6518
6518
|
}
|
|
6519
|
+
declare module "types:tensionscript/src/dwarf/leb" {
|
|
6520
|
+
/**
|
|
6521
|
+
* @fileoverview LEB128 and byte writing, shared by the wasm readers and the
|
|
6522
|
+
* DWARF encoder. Port of `tension-core/src/leb.rs` and the `cstr` helper in
|
|
6523
|
+
* `tension-core/src/dwarf/encode.rs`.
|
|
6524
|
+
* @license Apache-2.0
|
|
6525
|
+
*/
|
|
6526
|
+
/** A growable byte sink. Rust's `Vec<u8>` has no direct counterpart here. */
|
|
6527
|
+
export class ByteWriter {
|
|
6528
|
+
buf: Uint8Array;
|
|
6529
|
+
len: number;
|
|
6530
|
+
constructor(capacity?: number);
|
|
6531
|
+
private grow;
|
|
6532
|
+
push(byte: number): void;
|
|
6533
|
+
/** Appends `data[0..data.length]`. */
|
|
6534
|
+
bytes(data: Uint8Array): void;
|
|
6535
|
+
/** Appends `data[start..end]`, the Rust `extend_from_slice(&slice[a..b])`. */
|
|
6536
|
+
slice(data: Uint8Array, start: number, end: number): void;
|
|
6537
|
+
/** Unsigned LEB128. Values here are addresses and lengths, so 32 bits suffice. */
|
|
6538
|
+
uleb(value: number): void;
|
|
6539
|
+
/**
|
|
6540
|
+
* Signed LEB128. Rust writes line deltas as `i64`; every value here is a
|
|
6541
|
+
* source-line difference, which fits `i32`, and SLEB128's terminating
|
|
6542
|
+
* condition makes the two widths encode identically for such values.
|
|
6543
|
+
*/
|
|
6544
|
+
sleb(value: number): void;
|
|
6545
|
+
u16le(value: number): void;
|
|
6546
|
+
u32le(value: number): void;
|
|
6547
|
+
/** A NUL-terminated UTF-8 string, the Rust `cstr`. */
|
|
6548
|
+
cstr(text: string): void;
|
|
6549
|
+
/** UTF-8 bytes with no terminator (a wasm name, a DWARF file path). */
|
|
6550
|
+
utf8(text: string): void;
|
|
6551
|
+
/** The written bytes as their own array. */
|
|
6552
|
+
finish(): Uint8Array;
|
|
6553
|
+
}
|
|
6554
|
+
}
|
|
6555
|
+
declare module "types:tensionscript/src/dwarf/source-map" {
|
|
6556
|
+
/**
|
|
6557
|
+
* @fileoverview The source-map v3 side: a purpose-built JSON reader and the
|
|
6558
|
+
* mappings (base64 VLQ) decoder. Port of
|
|
6559
|
+
* `tension-core/src/dwarf/source_map.rs`.
|
|
6560
|
+
* @license Apache-2.0
|
|
6561
|
+
*/
|
|
6562
|
+
/** One source-map segment: wasm file offset -> source line/column. */
|
|
6563
|
+
export class Seg {
|
|
6564
|
+
addr: number;
|
|
6565
|
+
file: number;
|
|
6566
|
+
line: number;
|
|
6567
|
+
col: number;
|
|
6568
|
+
constructor(addr: number, file: number, line: number, col: number);
|
|
6569
|
+
}
|
|
6570
|
+
export class SourceMap {
|
|
6571
|
+
sources: string[];
|
|
6572
|
+
segments: Seg[];
|
|
6573
|
+
constructor(sources: string[], segments: Seg[]);
|
|
6574
|
+
}
|
|
6575
|
+
/** Decode one comma-free group of base64 VLQ digits. */
|
|
6576
|
+
export function vlq(text: string): number[];
|
|
6577
|
+
/**
|
|
6578
|
+
* Decode `mappings`. Generated columns are absolute wasm file offsets.
|
|
6579
|
+
*
|
|
6580
|
+
* The source-map spec resets the generated column to 0 at each `;`-separated
|
|
6581
|
+
* line group; source line, source column and file index keep accumulating
|
|
6582
|
+
* across groups.
|
|
6583
|
+
*/
|
|
6584
|
+
export function parseMappings(mappings: string, sourceCount: number): Seg[];
|
|
6585
|
+
/** Read `sources` and `mappings` out of a source-map v3 document. */
|
|
6586
|
+
export function parseSourceMap(json: string): SourceMap;
|
|
6587
|
+
}
|
|
6588
|
+
declare module "types:tensionscript/src/dwarf/wasm-layout" {
|
|
6589
|
+
/**
|
|
6590
|
+
* @fileoverview Parsing the guest module: the section walk, code bodies, the
|
|
6591
|
+
* `name` section, and everything synthesis needs from all of it. Port of
|
|
6592
|
+
* `tension-core/src/dwarf/wasm.rs`.
|
|
6593
|
+
*
|
|
6594
|
+
* D8 measured the alternative — taking function and local names from the
|
|
6595
|
+
* compiler's in-memory state — and rejected it: Binaryen owns the emitted
|
|
6596
|
+
* function and local indices (it renames through its own passes), and the
|
|
6597
|
+
* compiler's `FunctionRef`/`Local` keys are not the emitted index space. The
|
|
6598
|
+
* emitted `name` section is the only faithful source, so it is parsed here
|
|
6599
|
+
* exactly as the host parses it.
|
|
6600
|
+
* @license Apache-2.0
|
|
6601
|
+
*/
|
|
6602
|
+
/** A cursor over bytes, the Rust `Reader`. */
|
|
6603
|
+
export class Reader {
|
|
6604
|
+
b: Uint8Array;
|
|
6605
|
+
i: number;
|
|
6606
|
+
constructor(b: Uint8Array, i: number);
|
|
6607
|
+
u8(): number;
|
|
6608
|
+
uleb(): number;
|
|
6609
|
+
name(): string;
|
|
6610
|
+
}
|
|
6611
|
+
/**
|
|
6612
|
+
* A wasm value type we can describe to a debugger. `None` is the Rust
|
|
6613
|
+
* `Option<ValType>::None` — everything else (`v128`, reference types) has no
|
|
6614
|
+
* DWARF base type here and is left undescribed.
|
|
6615
|
+
*/
|
|
6616
|
+
export enum ValType {
|
|
6617
|
+
None = -1,
|
|
6618
|
+
I32 = 0,
|
|
6619
|
+
I64 = 1,
|
|
6620
|
+
F32 = 2,
|
|
6621
|
+
F64 = 3
|
|
6622
|
+
}
|
|
6623
|
+
export function valTypeFromByte(b: number): ValType;
|
|
6624
|
+
export function valTypeName(ty: ValType): string;
|
|
6625
|
+
/** `DW_AT_encoding`: signed integer or IEEE float. */
|
|
6626
|
+
export function valTypeEncoding(ty: ValType): number;
|
|
6627
|
+
export function valTypeByteSize(ty: ValType): number;
|
|
6628
|
+
/** A body's `[start, end)` file offsets. */
|
|
6629
|
+
export class BodyRange {
|
|
6630
|
+
start: number;
|
|
6631
|
+
end: number;
|
|
6632
|
+
constructor(start: number, end: number);
|
|
6633
|
+
}
|
|
6634
|
+
/** One `(count, valtype)` local-declaration group. */
|
|
6635
|
+
export class LocalDecl {
|
|
6636
|
+
count: number;
|
|
6637
|
+
ty: number;
|
|
6638
|
+
constructor(count: number, ty: number);
|
|
6639
|
+
}
|
|
6640
|
+
/** A local in index order: name, index, value type (null when undescribable). */
|
|
6641
|
+
export class LocalInfo {
|
|
6642
|
+
name: string;
|
|
6643
|
+
index: number;
|
|
6644
|
+
ty: ValType;
|
|
6645
|
+
constructor(name: string, index: number, ty: ValType);
|
|
6646
|
+
}
|
|
6647
|
+
/** A `name` section entry. */
|
|
6648
|
+
export class NamedEntry {
|
|
6649
|
+
index: number;
|
|
6650
|
+
name: string;
|
|
6651
|
+
constructor(index: number, name: string);
|
|
6652
|
+
}
|
|
6653
|
+
/** A local-name entry: function index, local index, name. */
|
|
6654
|
+
export class LocalNameEntry {
|
|
6655
|
+
func: number;
|
|
6656
|
+
index: number;
|
|
6657
|
+
name: string;
|
|
6658
|
+
constructor(func: number, index: number, name: string);
|
|
6659
|
+
}
|
|
6660
|
+
/** A `(params, results)` function type, as valtype bytes. */
|
|
6661
|
+
export class FuncType {
|
|
6662
|
+
params: number[];
|
|
6663
|
+
results: number[];
|
|
6664
|
+
constructor(params: number[], results: number[]);
|
|
6665
|
+
}
|
|
6666
|
+
/** What the synthesizer must learn from the guest module itself. */
|
|
6667
|
+
export class Layout {
|
|
6668
|
+
/** File offset of the code section payload: DWARF address 0. */
|
|
6669
|
+
codePayloadStart: number;
|
|
6670
|
+
/** Payload size; also the exclusive end of the address space. */
|
|
6671
|
+
codePayloadSize: number;
|
|
6672
|
+
/** Body content `[start, end)` in file offsets, one per defined function. */
|
|
6673
|
+
bodies: BodyRange[];
|
|
6674
|
+
/** Body local declarations, parallel to `bodies`. */
|
|
6675
|
+
bodyDecls: LocalDecl[][];
|
|
6676
|
+
/** Functions declared in the import section; the index space starts there. */
|
|
6677
|
+
importedFuncs: number;
|
|
6678
|
+
/** `name` section function names by function index. */
|
|
6679
|
+
names: NamedEntry[];
|
|
6680
|
+
/** `name` section local names: function index, local index, name. */
|
|
6681
|
+
localNames: LocalNameEntry[];
|
|
6682
|
+
/** Function type indices from the function section, one per defined function. */
|
|
6683
|
+
funcTypes: number[];
|
|
6684
|
+
/** Function types from the type section. */
|
|
6685
|
+
types: FuncType[];
|
|
6686
|
+
/** Name of the function defined by body `i`, if the guest kept names. */
|
|
6687
|
+
nameForBody(body: number): string | null;
|
|
6688
|
+
/**
|
|
6689
|
+
* A guest local in index order: the function's parameters first, then the
|
|
6690
|
+
* body's declarations. `name` is what `asc --debug` kept in the `name`
|
|
6691
|
+
* section (subsection 2) when present, else a fallback.
|
|
6692
|
+
*/
|
|
6693
|
+
localsForBody(body: number): LocalInfo[];
|
|
6694
|
+
private localName;
|
|
6695
|
+
}
|
|
6696
|
+
/** The two parallel arrays `readCodeBodies` produces. */
|
|
6697
|
+
export class CodeBodies {
|
|
6698
|
+
bodies: BodyRange[];
|
|
6699
|
+
decls: LocalDecl[][];
|
|
6700
|
+
}
|
|
6701
|
+
/** Walk the module and collect everything synthesis needs. */
|
|
6702
|
+
export function parseLayout(wasm: Uint8Array): Layout;
|
|
6703
|
+
}
|
|
6704
|
+
declare module "types:tensionscript/src/dwarf/encode" {
|
|
6705
|
+
/**
|
|
6706
|
+
* @fileoverview The DWARF 4 encoder: abbreviations, the line program,
|
|
6707
|
+
* `.debug_info` DIEs, and the custom-section wrapper. Port of
|
|
6708
|
+
* `tension-core/src/dwarf/encode.rs`.
|
|
6709
|
+
* @license Apache-2.0
|
|
6710
|
+
*/
|
|
6711
|
+
import { ByteWriter } from "types:tensionscript/src/dwarf/leb";
|
|
6712
|
+
import { Seg } from "types:tensionscript/src/dwarf/source-map";
|
|
6713
|
+
import { LocalInfo, ValType } from "types:tensionscript/src/dwarf/wasm-layout";
|
|
6714
|
+
/** One subprogram: its name and payload-relative `[lo, hi)` address. */
|
|
6715
|
+
export class FunctionRange {
|
|
6716
|
+
name: string;
|
|
6717
|
+
lo: number;
|
|
6718
|
+
hi: number;
|
|
6719
|
+
constructor(name: string, lo: number, hi: number);
|
|
6720
|
+
}
|
|
6721
|
+
/** A payload-relative `[start, end)` interval. */
|
|
6722
|
+
export class Range {
|
|
6723
|
+
start: number;
|
|
6724
|
+
end: number;
|
|
6725
|
+
constructor(start: number, end: number);
|
|
6726
|
+
}
|
|
6727
|
+
/**
|
|
6728
|
+
* Abbrev 1: compile unit. Abbrev 2: subprogram. Abbrev 3: subprogram with
|
|
6729
|
+
* children. Abbrev 4: base type. Abbrev 5: variable. No `strp`, so no
|
|
6730
|
+
* `.debug_str`; type references are `DW_FORM_ref4` within the unit.
|
|
6731
|
+
*/
|
|
6732
|
+
export function encodeDebugAbbrev(): Uint8Array;
|
|
6733
|
+
/**
|
|
6734
|
+
* Turn an AssemblyScript source-map path into one the symbol root resolves.
|
|
6735
|
+
* `asc` writes library sources as `~lib/...`, which no debugger understands.
|
|
6736
|
+
*
|
|
6737
|
+
* The Rust original also probes the filesystem and prefers
|
|
6738
|
+
* `node_modules/assemblyscript/std/assembly/...` when that directory exists.
|
|
6739
|
+
* The compiler has no filesystem access, so the probe collapses to the
|
|
6740
|
+
* fallback branch - which is what the host produced for the baseline fixture
|
|
6741
|
+
* (neither probed path exists in a TensionScript project: the package ships
|
|
6742
|
+
* its stdlib as `@yabgu_gm/tensionscript/std/assembly`).
|
|
6743
|
+
*/
|
|
6744
|
+
export function sourcePath(raw: string, compDir: string): string;
|
|
6745
|
+
/**
|
|
6746
|
+
* A DWARF v4 line program. `rows` must be sorted ascending by address.
|
|
6747
|
+
* `ranges` are the payload-relative body ranges, one line sequence each.
|
|
6748
|
+
*/
|
|
6749
|
+
export function encodeDebugLine(compDir: string, sources: string[], rows: Seg[], ranges: Range[]): Uint8Array;
|
|
6750
|
+
/**
|
|
6751
|
+
* One `DW_TAG_subprogram` per defined function the name section knows about,
|
|
6752
|
+
* and one `DW_TAG_variable` child per wasm local whose type we can describe.
|
|
6753
|
+
* `locals` is parallel to `functions`.
|
|
6754
|
+
*/
|
|
6755
|
+
export function encodeDebugInfo(moduleName: string, compDir: string, functions: FunctionRange[], locals: LocalInfo[][]): Uint8Array;
|
|
6756
|
+
/** Position of a `ValType` in the base-type DIE order, for `typeOffsets`. */
|
|
6757
|
+
export function typeIndex(ty: ValType): number;
|
|
6758
|
+
/**
|
|
6759
|
+
* Append a custom section to `out`: id, size, name length, name, payload -
|
|
6760
|
+
* where `size` counts everything after itself.
|
|
6761
|
+
*/
|
|
6762
|
+
export function appendCustom(out: ByteWriter, name: string, payload: Uint8Array): void;
|
|
6763
|
+
}
|
|
6764
|
+
declare module "types:tensionscript/src/dwarf/index" {
|
|
6765
|
+
/**
|
|
6766
|
+
* @fileoverview DWARF synthesis for TensionScript guests, compiler side.
|
|
6767
|
+
*
|
|
6768
|
+
* Port of `tension-core/src/dwarf/mod.rs` (`synthesize`) and the module
|
|
6769
|
+
* comment that explains it. The host rebuilt this from a guest's `name`
|
|
6770
|
+
* section and source map because `asc` emitted no DWARF; the compiler now
|
|
6771
|
+
* carries the same code, so a guest ships its own `.debug_*` sections.
|
|
6772
|
+
*
|
|
6773
|
+
* Address convention (measured, not assumed): a guest DWARF code address is a
|
|
6774
|
+
* byte offset from the start of the code section payload - address 0 is the
|
|
6775
|
+
* first byte of the function-count LEB.
|
|
6776
|
+
*
|
|
6777
|
+
* The encoder is a verbatim port, including the range-splitting rule: the
|
|
6778
|
+
* compile unit's `DW_AT_ranges` entries are intervals between line rows, not
|
|
6779
|
+
* whole bodies, because cranelift emits a function's natives in an order that
|
|
6780
|
+
* is not monotonic in wasm addresses. Its range translation only sees the
|
|
6781
|
+
* ranges active at an entry's start and end addresses, so a whole-body entry
|
|
6782
|
+
* hides any internal range that begins and ends strictly inside it, and lldb
|
|
6783
|
+
* drops line rows that fall in the resulting holes.
|
|
6784
|
+
* @license Apache-2.0
|
|
6785
|
+
*/
|
|
6786
|
+
/** What synthesis produced, for the caller's diagnostics. */
|
|
6787
|
+
export class SynthesisResult {
|
|
6788
|
+
bytes: Uint8Array;
|
|
6789
|
+
files: number;
|
|
6790
|
+
rows: number;
|
|
6791
|
+
functions: number;
|
|
6792
|
+
locals: number;
|
|
6793
|
+
dropped: number;
|
|
6794
|
+
constructor(bytes: Uint8Array, files: number, rows: number, functions: number, locals: number, dropped: number);
|
|
6795
|
+
}
|
|
6796
|
+
/**
|
|
6797
|
+
* Copy `wasm` with synthesized `.debug_abbrev`, `.debug_info`, `.debug_line`
|
|
6798
|
+
* and `.debug_ranges` appended: line tables for source breakpoints, function
|
|
6799
|
+
* DIEs for the call stack, and variable DIEs for locals.
|
|
6800
|
+
*
|
|
6801
|
+
* `compDir` becomes the DWARF compile directory and the base for every
|
|
6802
|
+
* file-table entry. `moduleName` becomes the unit's `DW_AT_name`.
|
|
6803
|
+
*
|
|
6804
|
+
* Throws `Error` on malformed input. The Rust original returned
|
|
6805
|
+
* `Result<_, String>`; a throw is the idiomatic equivalent here, and the
|
|
6806
|
+
* caller decides whether a failed synthesis is fatal (the compiler treats it
|
|
6807
|
+
* as a warning and emits the undecorated module).
|
|
6808
|
+
*/
|
|
6809
|
+
export function synthesize(wasm: Uint8Array, sourceMapJson: string, compDir: string, moduleName: string): Uint8Array;
|
|
6810
|
+
/** `synthesize` plus the counts the host used to log. */
|
|
6811
|
+
export function synthesizeVerbose(wasm: Uint8Array, sourceMapJson: string, compDir: string, moduleName: string): SynthesisResult;
|
|
6812
|
+
}
|
|
6519
6813
|
declare module "types:tensionscript/src/module" {
|
|
6520
6814
|
/**
|
|
6521
6815
|
* @fileoverview A thin wrapper around Binaryen's C-API.
|
|
@@ -7900,7 +8194,16 @@ declare module "types:tensionscript/src/module" {
|
|
|
7900
8194
|
optimize(optimizeLevel: number, shrinkLevel: number, debugInfo?: boolean, zeroFilledMemory?: boolean): void;
|
|
7901
8195
|
validate(): boolean;
|
|
7902
8196
|
interpret(): void;
|
|
7903
|
-
|
|
8197
|
+
/**
|
|
8198
|
+
* Emits the module.
|
|
8199
|
+
*
|
|
8200
|
+
* When `debugInfo` is set *and* a source map is requested, the emitted bytes
|
|
8201
|
+
* gain synthesized DWARF (`.debug_abbrev`, `.debug_info`, `.debug_line`,
|
|
8202
|
+
* `.debug_ranges`) - the same sections `tension-core` used to rebuild from
|
|
8203
|
+
* the guest's source map. A host that already ships DWARF (a C or Rust
|
|
8204
|
+
* guest) is unaffected: this only decorates a module this compiler emits.
|
|
8205
|
+
*/
|
|
8206
|
+
toBinary(sourceMapUrl?: string | null, debugInfo?: boolean, compDir?: string, moduleName?: string): BinaryModule;
|
|
7904
8207
|
toText(watFormat?: boolean): string;
|
|
7905
8208
|
private cachedStringsToPointers;
|
|
7906
8209
|
private cachedPointersToStrings;
|
|
@@ -11333,25 +11636,75 @@ declare module "types:tensionscript/src/compiler" {
|
|
|
11333
11636
|
* Compiles an array literal into one operand per element leaf, starting at
|
|
11334
11637
|
* `at`, and returns how many were written.
|
|
11335
11638
|
*
|
|
11336
|
-
*
|
|
11337
|
-
*
|
|
11338
|
-
*
|
|
11339
|
-
*
|
|
11340
|
-
* refusals disagree on.
|
|
11341
|
-
*
|
|
11342
|
-
* Three rules:
|
|
11343
|
-
*
|
|
11344
|
-
* - A **record element** is several leaves and no literal names them, so it is
|
|
11345
|
-
* refused by name; building the array field-by-field in a local is the
|
|
11346
|
-
* working route in both positions.
|
|
11347
|
-
* - A **short** literal zero-fills. The slot exists either way, and a WASM
|
|
11348
|
-
* operand cannot be left out.
|
|
11349
|
-
* - A **long** literal is an arity error rather than a write past the operand
|
|
11350
|
-
* block — `sum([1, 2, 3, 4, 5])` into a `[u32 * 4]` parameter reached
|
|
11351
|
-
* Binaryen with five operands for four slots and crashed the compiler, so
|
|
11352
|
-
* this bound is a guard, not a formality.
|
|
11639
|
+
* The operand sink of `emitSroaArrayLiteralLeaves`: the walk yields the leaves
|
|
11640
|
+
* and this places them, then fills any element the literal omitted — a WASM
|
|
11641
|
+
* operand cannot be left out, even when a local could (`fillSroaArrayFromLiteral`,
|
|
11642
|
+
* where zero is free).
|
|
11353
11643
|
*/
|
|
11354
11644
|
private pushSroaArrayLiteralOperands;
|
|
11645
|
+
/**
|
|
11646
|
+
* Compiles an array literal into one **leaf expression per leaf**, appended to
|
|
11647
|
+
* `leaves` in element-major order.
|
|
11648
|
+
*
|
|
11649
|
+
* **The one array-literal element walk.** Three positions use it: the call site
|
|
11650
|
+
* (`pushSroaArrayLiteralOperands`), the return
|
|
11651
|
+
* (`compileMultivalueReturnStatement`), and the local declaration
|
|
11652
|
+
* (`fillSroaArrayFromLiteral`). A value-form array's elements are leaves, and
|
|
11653
|
+
* the positions differ only in what they do with them — push operands, make a
|
|
11654
|
+
* tuple, or `local.set` — so the rules for *reading* a literal live here once.
|
|
11655
|
+
*
|
|
11656
|
+
* `verb` is `"passing"`, `"returning"` or `"initializing"`; it only chooses
|
|
11657
|
+
* the wording of the refusals.
|
|
11658
|
+
*
|
|
11659
|
+
* The elements a literal omits are **not** produced here: a WASM local starts
|
|
11660
|
+
* at zero, so a local declaration needs no stores for them, while an argument
|
|
11661
|
+
* or a return needs an operand and the caller fills it (`makeZero` per leaf
|
|
11662
|
+
* type). Two different destinations, one walk.
|
|
11663
|
+
*
|
|
11664
|
+
* A **long** literal is an arity error rather than a write past the leaf
|
|
11665
|
+
* block — `sum([1, 2, 3, 4, 5])` into a `[u32 * 4]` parameter reached Binaryen
|
|
11666
|
+
* with five operands for four slots and crashed the compiler, so this bound is
|
|
11667
|
+
* a guard, not a formality.
|
|
11668
|
+
*
|
|
11669
|
+
* A **record** element is several leaves, so it is read one leaf per field: an
|
|
11670
|
+
* object literal (`{ x: 1.5, y: 2.5 }`) compiles straight to them
|
|
11671
|
+
* (`emitSroaObjectElementLeaves`), and anything else — a record local, a call —
|
|
11672
|
+
* is refused by name, because a local there is a pointer, not the leaves.
|
|
11673
|
+
*/
|
|
11674
|
+
private emitSroaArrayLiteralLeaves;
|
|
11675
|
+
/**
|
|
11676
|
+
* Compiles one **object literal** element of a `[T * N]` array literal into
|
|
11677
|
+
* that element's field leaves, in declaration order.
|
|
11678
|
+
*
|
|
11679
|
+
* `{ x: 10.5, y: 20.5 }` is the natural way to write a record element, and for
|
|
11680
|
+
* an `@unmanaged struct` it can be compiled straight to leaves — no heap
|
|
11681
|
+
* record, no constructor, no pointer. The class path (`compileObjectLiteral`)
|
|
11682
|
+
* cannot be reused for it: that one requires a class, takes a temp local of
|
|
11683
|
+
* that class, and returns one reference, because it has to produce an
|
|
11684
|
+
* *address*. Measured on the same spelling: `const p: P = { x: 10.5 }` emits
|
|
11685
|
+
* `P#constructor` plus `__alloc(16)` and setters — a heap record, not a value.
|
|
11686
|
+
*
|
|
11687
|
+
* Policies, each measured against the class path so the two spellings agree:
|
|
11688
|
+
*
|
|
11689
|
+
* - **Declaration order.** Fields are emitted in the record's declaration
|
|
11690
|
+
* order, not the literal's, because the leaves are positional.
|
|
11691
|
+
* - **Last duplicate wins** — `{ x: 1.0, x: 2.0 }` is `2.0`, as measured for
|
|
11692
|
+
* `const p: P = { x: 1.0, x: 2.0 }`.
|
|
11693
|
+
* - **An unknown name is an error** at the name, matching
|
|
11694
|
+
* `compileObjectLiteral`'s `TS2339`.
|
|
11695
|
+
* - **An omitted field takes its declared default**, matching the constructor
|
|
11696
|
+
* the class path runs: measured, `{ x: 10.0 }` on `{ x = 5.0; y = 7.0 }`
|
|
11697
|
+
* yielded `y = 7.0`, not `0`. Only a **constant** default is reproduced
|
|
11698
|
+
* here; one that needs the record instance (`y = this.x * 2.0`) is refused
|
|
11699
|
+
* by name, because a leaf emission has no instance to evaluate it against.
|
|
11700
|
+
* - **A field left with no default is zero**, matching `{ x: 3.0 }` on a record
|
|
11701
|
+
* with no initialisers (measured: `y` came back `0`).
|
|
11702
|
+
*
|
|
11703
|
+
* A **nested** field (an `@inline struct` inside the record) is refused: its
|
|
11704
|
+
* value is a second set of leaves behind a second object literal, which is the
|
|
11705
|
+
* recursion this landing does not carry.
|
|
11706
|
+
*/
|
|
11707
|
+
private emitSroaObjectElementLeaves;
|
|
11355
11708
|
private expandSroaArgument;
|
|
11356
11709
|
/**
|
|
11357
11710
|
* The SROA local an expression names, or `null`.
|
|
@@ -11377,6 +11730,18 @@ declare module "types:tensionscript/src/compiler" {
|
|
|
11377
11730
|
* carrying its own map, so the walk descends through it.
|
|
11378
11731
|
*/
|
|
11379
11732
|
private pushSroaLeafOperands;
|
|
11733
|
+
/**
|
|
11734
|
+
* Collects a `fieldLocals` tree's leaves into `out`, depth first.
|
|
11735
|
+
*
|
|
11736
|
+
* **The one definition of leaf order.** A nested value is a placeholder
|
|
11737
|
+
* (index `-1`) carrying its own map, so the walk descends through it rather
|
|
11738
|
+
* than yielding it. Every emitter that needs "the leaves of this value, in
|
|
11739
|
+
* order" goes through here — `pushSroaLeafOperands` for call operands, the
|
|
11740
|
+
* array-literal walk for literal elements, the local binder for stores — so
|
|
11741
|
+
* order is stated once instead of re-derived per site. It must agree with
|
|
11742
|
+
* `Signature.leafTypesOf`, which is the type-level twin.
|
|
11743
|
+
*/
|
|
11744
|
+
private collectSroaLeafLocals;
|
|
11380
11745
|
private resolveSroaReceiver;
|
|
11381
11746
|
/** Size of the static call-temp region, in bytes. 4 KB is 256 slots at the
|
|
11382
11747
|
* 16-byte fixture record size. Overflow aborts (see `makeSretCallBlock`);
|
|
@@ -11688,14 +12053,18 @@ declare module "types:tensionscript/src/compiler" {
|
|
|
11688
12053
|
/**
|
|
11689
12054
|
* Stores an array literal's elements into a value-form array's leaves.
|
|
11690
12055
|
*
|
|
11691
|
-
*
|
|
11692
|
-
*
|
|
11693
|
-
*
|
|
11694
|
-
*
|
|
11695
|
-
*
|
|
11696
|
-
*
|
|
11697
|
-
*
|
|
11698
|
-
*
|
|
12056
|
+
* The **local-declaration sink** of `emitSroaArrayLiteralLeaves`: the walk
|
|
12057
|
+
* yields one expression per leaf in element-major order, and this local's
|
|
12058
|
+
* leaves were created in the same order (`fillSroaArrayLocals` keys them
|
|
12059
|
+
* `"0"`, `"1"`, ...), so the two line up positionally and a `local.set` per
|
|
12060
|
+
* pair is the whole job. No zero-fill: a WASM local starts at zero, so an
|
|
12061
|
+
* omitted element needs no store — which is why the walk does not produce one.
|
|
12062
|
+
*
|
|
12063
|
+
* A scalar element is one leaf. A **record** element is several, and the walk
|
|
12064
|
+
* refuses it by name: the object-literal spelling (`{ x: 1.5, y: 2.5 }`) goes
|
|
12065
|
+
* through the class path and *allocates* — measured, `const p: P = { x: 1.5 }`
|
|
12066
|
+
* emitted `P#constructor` plus setters and needed `env.abort`, i.e. a heap
|
|
12067
|
+
* record behind a pointer, which is not a value.
|
|
11699
12068
|
*/
|
|
11700
12069
|
private fillSroaArrayFromLiteral;
|
|
11701
12070
|
/**
|
|
@@ -12688,6 +13057,14 @@ declare module "types:tensionscript/src/index-wasm" {
|
|
|
12688
13057
|
/** Sets the `pedantic` option. */
|
|
12689
13058
|
export function setPedantic(options: Options, pedantic: boolean): void;
|
|
12690
13059
|
export function setDebugInfo(options: Options, debug: boolean): void;
|
|
13060
|
+
/**
|
|
13061
|
+
* Appends synthesized DWARF (`.debug_abbrev`, `.debug_info`, `.debug_line`,
|
|
13062
|
+
* `.debug_ranges`) to an emitted module and returns the augmented bytes.
|
|
13063
|
+
*
|
|
13064
|
+
* Exposed for hosts that emit through Binaryen's own writer rather than
|
|
13065
|
+
* `Module#toBinary` - the CLI does exactly that. See `src/dwarf/`.
|
|
13066
|
+
*/
|
|
13067
|
+
export function synthesizeDwarf(wasmBytes: Uint8Array, sourceMapJson: string, compDir: string, moduleName: string): Uint8Array;
|
|
12691
13068
|
/**
|
|
12692
13069
|
* Runs the compiler's own in-tree `afterParse` transforms (closure lowering,
|
|
12693
13070
|
* then async lowering) over a program.
|