watr 4.3.3 → 4.4.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.
@@ -56,12 +56,11 @@ export function strength(ast: any[]): any[];
56
56
  */
57
57
  export function branch(ast: any[]): any[];
58
58
  /**
59
- * Propagate constant values through local variables.
60
- * When a local is set to a constant and not modified before use, replace the get with the constant.
61
- * @param {Array} ast
62
- * @returns {Array}
59
+ * Propagate values through locals and eliminate single-use/dead locals.
60
+ * Constants propagate to all uses; pure single-use exprs inline into get site.
61
+ * Multi-pass with batch counting for convergence.
63
62
  */
64
- export function propagate(ast: any[]): any[];
63
+ export function propagate(ast: any): any;
65
64
  /**
66
65
  * Inline tiny functions (single expression, no locals, no params or simple params).
67
66
  * @param {Array} ast
@@ -84,5 +83,95 @@ export namespace OPTS {
84
83
  let branch: boolean;
85
84
  let propagate: boolean;
86
85
  let inline: boolean;
86
+ let vacuum: boolean;
87
+ let peephole: boolean;
88
+ let globals: boolean;
89
+ let offset: boolean;
90
+ let unbranch: boolean;
91
+ let stripmut: boolean;
92
+ let brif: boolean;
93
+ let foldarms: boolean;
94
+ let dedupe: boolean;
95
+ let reorder: boolean;
96
+ let dedupTypes: boolean;
97
+ let packData: boolean;
98
+ let minifyImports: boolean;
87
99
  }
100
+ /**
101
+ * Remove no-op code: nops, drop of pure expressions, empty branches,
102
+ * and select with identical arms.
103
+ * @param {Array} ast
104
+ * @returns {Array}
105
+ */
106
+ export function vacuum(ast: any[]): any[];
107
+ /**
108
+ * Apply peephole optimizations.
109
+ * @param {Array} ast
110
+ * @returns {Array}
111
+ */
112
+ export function peephole(ast: any[]): any[];
113
+ /**
114
+ * Replace global.get of immutable globals with their constant init values.
115
+ * @param {Array} ast
116
+ * @returns {Array}
117
+ */
118
+ export function globals(ast: any[]): any[];
119
+ /** Match (type.load/store (i32.add ptr (type.const N))) and fold offset */
120
+ export function offset(ast: any): any;
121
+ /**
122
+ * Remove br to a block's own label when it is the last instruction.
123
+ * @param {Array} ast
124
+ * @returns {Array}
125
+ */
126
+ export function unbranch(ast: any[]): any[];
127
+ /**
128
+ * Strip mutability from globals that are never written.
129
+ * Enables globals constant-propagation for more globals.
130
+ * @param {Array} ast
131
+ * @returns {Array}
132
+ */
133
+ export function stripmut(ast: any[]): any[];
134
+ /**
135
+ * Simplify (if cond (then (br $label))) → (br_if $label cond)
136
+ * and (if cond (then) (else (br $label))) → (br_if $label (i32.eqz cond))
137
+ * Only when the br is the sole instruction in the arm.
138
+ * @param {Array} ast
139
+ * @returns {Array}
140
+ */
141
+ export function brif(ast: any[]): any[];
142
+ /**
143
+ * Fold identical trailing code out of if/else arms.
144
+ * (if cond (then A X) (else B X)) → (if cond (then A) (else B)) X
145
+ * @param {Array} ast
146
+ * @returns {Array}
147
+ */
148
+ export function foldarms(ast: any[]): any[];
149
+ /**
150
+ * Eliminate duplicate functions by hashing bodies.
151
+ * Keeps the first occurrence and redirects all references to it.
152
+ * @param {Array} ast
153
+ * @returns {Array}
154
+ */
155
+ export function dedupe(ast: any[]): any[];
156
+ export function reorder(ast: any): any;
157
+ /**
158
+ * Merge structurally identical (type ...) definitions.
159
+ * Keeps the first occurrence and redirects all references.
160
+ * @param {Array} ast
161
+ * @returns {Array}
162
+ */
163
+ export function dedupTypes(ast: any[]): any[];
164
+ /**
165
+ * Pack data segments: trim trailing zeros and merge adjacent constant-offset segments.
166
+ * @param {Array} ast
167
+ * @returns {Array}
168
+ */
169
+ export function packData(ast: any[]): any[];
170
+ /**
171
+ * Minify import module and field names for smaller binaries.
172
+ * Only safe when you control the host environment.
173
+ * @param {Array} ast
174
+ * @returns {Array}
175
+ */
176
+ export function minifyImports(ast: any[]): any[];
88
177
  //# sourceMappingURL=optimize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AAioCA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SAwB/B;AAtkCD;;;;;GAKG;AACH,6CA8LC;AAyHD;;;;GAIG;AACH,wCAmCC;AAwQD;;;;GAIG;AACH,4CAuBC;AA+CD;;;;;GAKG;AACH,8CAqDC;AApTD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CA0EC;AAiJD;;;;;GAKG;AACH,6CAuEC;AAID;;;;GAIG;AACH,0CAwFC;AAn+BD;;;;GAIG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAe/B"}
1
+ {"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AA2+DA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SA6C/B;AA34DD;;;;;GAKG;AACH,6CAsIC;AA6ID;;;;GAIG;AACH,wCAwBC;AAoMD;;;;GAIG;AACH,4CAuBC;AA+CD;;;;;GAKG;AACH,8CAqDC;AAjRD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CAuCC;AAwVD;;;;GAIG;AACH,yCAwBC;AAID;;;;GAIG;AACH,0CAwFC;AApiCD;;;;GAIG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAgB/B;;;;;;;;;;;;;;;;;;;;;;;;;AAshCD;;;;;GAKG;AACH,0CAgDC;AAyED;;;;GAIG;AACH,4CAQC;AAID;;;;GAIG;AACH,2CA0CC;AAID,2EAA2E;AAC3E,sCAgEC;AAID;;;;GAIG;AACH,4CAuCC;AAID;;;;;GAKG;AACH,4CAsBC;AAID;;;;;;GAMG;AACH,wCAmBC;AAID;;;;;GAKG;AACH,4CAsCC;AAoCD;;;;;GAKG;AACH,0CA+DC;AAoWD,uCA0BC;AA1XD;;;;;GAKG;AACH,8CA0EC;AAoID;;;;GAIG;AACH,4CA0DC;AAqBD;;;;;GAKG;AACH,iDAiBC"}
package/watr.js CHANGED
@@ -152,7 +152,7 @@ function genImports(imports) {
152
152
  function compile(source, ...values) {
153
153
  // Options object as last argument (non-template call)
154
154
  let opts = {}
155
- if (!Array.isArray(source) && values.length && typeof values[values.length - 1] === 'object' && values[values.length - 1] !== null && !(values[values.length - 1] instanceof Uint8Array)) {
155
+ if (!Array.isArray(source) && values.length && typeof values[values.length - 1] === 'object' && values[values.length - 1] !== null && !values[values.length - 1].byteLength) {
156
156
  opts = values.pop()
157
157
  }
158
158
 
@@ -189,7 +189,7 @@ function compile(source, ...values) {
189
189
  return parsed
190
190
  }
191
191
  // Uint8Array → convert to plain array for flat() compatibility
192
- if (value instanceof Uint8Array) return [...value]
192
+ if (value.byteLength !== undefined) return [...value]
193
193
  return value
194
194
  }
195
195
  return node