wat4wasm 1.0.7 → 1.1.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/examples/01-text/module-output.wat +3 -35
- package/examples/02-include/module-output.wat +2 -2
- package/examples/03-ref.extern/module-output.wat +31 -549
- package/examples/04-ref.func/module-output.wat +3 -4
- package/examples/05-global.get/module-output.wat +19 -269
- package/examples/06-async/module-output.wat +5 -215
- package/examples/07-data/module-output.wasm +0 -0
- package/examples/08-reflectors/module-output.wat +50 -264
- package/examples/09-replaceAll/module-output.wat +3 -1
- package/examples/99-complex/apply_1.js +5 -0
- package/examples/99-complex/output.html +1 -1
- package/examples/shell-usages.sh +10 -23
- package/lib/cli.js +29 -2
- package/lib/processors/replace_all.js +1 -0
- package/package.json +1 -1
- package/wat4wasm +26 -1
|
@@ -16,6 +16,7 @@ export default function (wat) {
|
|
|
16
16
|
.replaceAll("(console $", "(call $self.console.")
|
|
17
17
|
.replaceAll("(reflect $", "(call $self.Reflect.")
|
|
18
18
|
.replaceAll("(bigint $", "(call $self.BigInt.")
|
|
19
|
+
.replaceAll("(promise $", "(call $self.Promise.")
|
|
19
20
|
.replaceAll("(number $", "(call $self.Number.")
|
|
20
21
|
.replaceAll("(math $", "(call $self.Math.")
|
|
21
22
|
.replaceAll("(string $", "(call $self.String.")
|
package/package.json
CHANGED
package/wat4wasm
CHANGED
|
@@ -1235,6 +1235,7 @@ function REPLACE_ALL (wat) {
|
|
|
1235
1235
|
.replaceAll("(console $", "(call $self.console.")
|
|
1236
1236
|
.replaceAll("(reflect $", "(call $self.Reflect.")
|
|
1237
1237
|
.replaceAll("(bigint $", "(call $self.BigInt.")
|
|
1238
|
+
.replaceAll("(promise $", "(call $self.Promise.")
|
|
1238
1239
|
.replaceAll("(number $", "(call $self.Number.")
|
|
1239
1240
|
.replaceAll("(math $", "(call $self.Math.")
|
|
1240
1241
|
.replaceAll("(string $", "(call $self.String.")
|
|
@@ -1784,6 +1785,7 @@ async function processCLI(compileCallback, PROCESS = process) {
|
|
|
1784
1785
|
faviconLinkHref: "data:null",
|
|
1785
1786
|
printOnly: false,
|
|
1786
1787
|
passthroughArgs: [],
|
|
1788
|
+
applyScripts: [],
|
|
1787
1789
|
};
|
|
1788
1790
|
for (let i = 0; i < args.length; i++) {
|
|
1789
1791
|
const arg = args[i];
|
|
@@ -1791,6 +1793,8 @@ async function processCLI(compileCallback, PROCESS = process) {
|
|
|
1791
1793
|
config.outputFile = arg.split("=")[1];
|
|
1792
1794
|
} else if (arg.startsWith("--input=")) {
|
|
1793
1795
|
config.inputFile = arg.split("=")[1];
|
|
1796
|
+
} else if (arg.startsWith("--apply=")) {
|
|
1797
|
+
config.applyScripts.push(arg.split("=")[1]);
|
|
1794
1798
|
} else if (arg.startsWith("--wat2wasm=")) {
|
|
1795
1799
|
config.wat2wasmPath = arg.split("=")[1];
|
|
1796
1800
|
} else if (arg.startsWith("--tag=")) {
|
|
@@ -1836,6 +1840,18 @@ async function processCLI(compileCallback, PROCESS = process) {
|
|
|
1836
1840
|
console.error("Error: Input file required! Usage: wat4wasm <input.wat> [options]");
|
|
1837
1841
|
PROCESS.exit(1);
|
|
1838
1842
|
}
|
|
1843
|
+
config.inputDirectory = process
|
|
1844
|
+
.cwd()
|
|
1845
|
+
.replaceAll("file://", "")
|
|
1846
|
+
.concat(config
|
|
1847
|
+
.inputFile
|
|
1848
|
+
.split("/")
|
|
1849
|
+
.reverse().slice(1)
|
|
1850
|
+
.reverse()
|
|
1851
|
+
.join("/")
|
|
1852
|
+
)
|
|
1853
|
+
.concat("/")
|
|
1854
|
+
.replaceAll("//", "/");
|
|
1839
1855
|
const isJSTarget = config.outputFile?.endsWith(".js");
|
|
1840
1856
|
const isHTMLTarget = config.outputFile?.endsWith(".html");
|
|
1841
1857
|
if (isHTMLTarget || isJSTarget) {
|
|
@@ -1854,7 +1870,16 @@ async function processCLI(compileCallback, PROCESS = process) {
|
|
|
1854
1870
|
}
|
|
1855
1871
|
const rawCode = fs.readFileSync(config.inputFile, "utf8");
|
|
1856
1872
|
// 2. Call the provided compile function
|
|
1857
|
-
|
|
1873
|
+
let compiled = await compileCallback(rawCode);
|
|
1874
|
+
let applyScript, applyCount = config.applyScripts.length;
|
|
1875
|
+
while (applyScript = config.applyScripts[--applyCount]) {
|
|
1876
|
+
const baseName = applyScript.split("/").pop().split(".").reverse().slice(1).reverse().join(".");
|
|
1877
|
+
console.log(`\x1b[0m\x1b[34m🎸 apply call[\x1b[35m${applyCount}\x1b[0m] \x1b[32m-->\x1b[0m \x1b[35m${baseName}\x1b[0m(wat)\x1b[0m`);
|
|
1878
|
+
const { default: applyFunction } = await import(
|
|
1879
|
+
config.inputDirectory.concat(applyScript)
|
|
1880
|
+
);
|
|
1881
|
+
compiled = await applyFunction(compiled);
|
|
1882
|
+
}
|
|
1858
1883
|
console.log("\x1b[0m")
|
|
1859
1884
|
// 3. Handle Output
|
|
1860
1885
|
if (config.printOnly) {
|