gofront 1.7.0 → 1.9.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/README.md +14 -14
- package/package.json +10 -38
- package/src/backend/js/expressions.js +2060 -389
- package/src/backend/js/index.js +586 -174
- package/src/backend/js/natives.js +383 -0
- package/src/backend/js/runtime.js +936 -1644
- package/src/backend/js/statements.js +1349 -132
- package/src/backend/js/stdlib/index.js +51 -94
- package/src/backend/js/templ.js +67 -118
- package/src/backend/js/type-info.js +436 -0
- package/src/backend/shared/fixed-float.js +20 -0
- package/src/backend/shared/fmt-types.js +80 -0
- package/src/backend/shared/host-unicode.js +36 -0
- package/src/backend/wasm/boundary.js +753 -872
- package/src/backend/wasm/emit-builtins.js +914 -237
- package/src/backend/wasm/emit-exprs.js +1456 -195
- package/src/backend/wasm/emit-maps.js +78 -380
- package/src/backend/wasm/emit-stmts.js +1659 -214
- package/src/backend/wasm/emit.js +614 -88
- package/src/backend/wasm/encode.js +43 -13
- package/src/backend/wasm/globals.js +491 -0
- package/src/backend/wasm/glue.js +2 -4
- package/src/backend/wasm/index.js +406 -3195
- package/src/backend/wasm/method-expr.js +392 -0
- package/src/backend/wasm/module-emitter.js +1615 -0
- package/src/backend/wasm/monomorph.js +164 -9
- package/src/backend/wasm/natives.js +596 -0
- package/src/backend/wasm/prescan.js +249 -0
- package/src/backend/wasm/prune-funcs.js +89 -0
- package/src/backend/wasm/stdlib/index.js +2 -37
- package/src/backend/wasm/stdlib/simd.js +293 -28
- package/src/backend/wasm/types.js +260 -27
- package/src/backend/wasm/variadic.js +93 -0
- package/src/backend/wasm/wat.js +47 -20
- package/src/{cli-core.js → cli/cli-core.js} +241 -11
- package/src/{test-runner.js → cli/test-runner.js} +188 -122
- package/src/{vendor.js → cli/vendor.js} +3 -4
- package/src/compiler.js +202 -386
- package/src/index.js +15 -169
- package/src/{lexer.js → lexer/lexer.js} +203 -62
- package/src/{templ-lexer.js → lexer/templ-lexer.js} +61 -18
- package/src/{tokens.js → lexer/tokens.js} +2 -0
- package/src/link/sourcemap.js +97 -0
- package/src/link/stdlib.js +737 -0
- package/src/link/type-names.js +148 -0
- package/src/link/wasm.js +318 -0
- package/src/lower/bounds.js +547 -0
- package/src/lower/boxing.js +1 -1
- package/src/lower/captures.js +267 -64
- package/src/lower/embedding.js +32 -3
- package/src/lower/errors-as.js +196 -0
- package/src/lower/fmt-formatters.js +905 -0
- package/src/lower/functions.js +2 -0
- package/src/lower/gen-types.js +274 -0
- package/src/lower/index.js +33 -19
- package/src/lower/json-codecs.js +1379 -0
- package/src/lower/ownership.js +47 -8
- package/src/lower/range.js +86 -1
- package/src/lower/reachability.js +150 -0
- package/src/lower/walk.js +12 -0
- package/src/parser/declarations.js +83 -15
- package/src/parser/expressions.js +110 -18
- package/src/parser/index.js +2 -1
- package/src/parser/statements.js +38 -22
- package/src/{templ-parser.js → parser/templ.js} +179 -17
- package/src/parser/types.js +70 -9
- package/src/resolver.js +21 -1
- package/src/typechecker/assignability.js +291 -19
- package/src/typechecker/const-fold.js +399 -0
- package/src/typechecker/constants.js +282 -0
- package/src/typechecker/expressions.js +1220 -183
- package/src/typechecker/index.js +659 -92
- package/src/typechecker/init-order.js +426 -0
- package/src/typechecker/operand-text.js +40 -0
- package/src/typechecker/resolve.js +613 -62
- package/src/typechecker/statements.js +212 -20
- package/src/typechecker/stdlib/excluded.js +902 -0
- package/src/typechecker/stdlib/index.js +38 -0
- package/src/typechecker/stdlib/simd.js +65 -15
- package/src/typechecker/termination.js +11 -2
- package/src/typechecker/types.js +268 -514
- package/stdlib/bytes/buffer.go +479 -0
- package/stdlib/bytes/bytes.go +1010 -0
- package/stdlib/bytes/reader.go +161 -0
- package/stdlib/cmp/cmp.go +65 -0
- package/stdlib/context/context.go +115 -0
- package/stdlib/crypto/rand/rand.go +34 -0
- package/stdlib/crypto/sha256/sha256.go +249 -0
- package/stdlib/encoding/base64/base64.go +331 -0
- package/stdlib/encoding/binary/binary.go +332 -0
- package/stdlib/encoding/hex/hex.go +140 -0
- package/stdlib/encoding/json/errors.go +31 -0
- package/stdlib/encoding/json/indent.go +71 -0
- package/stdlib/encoding/json/json.go +62 -0
- package/stdlib/encoding/json/number.go +12 -0
- package/stdlib/encoding/json/stream.go +173 -0
- package/stdlib/errors/errors.go +174 -0
- package/stdlib/fmt/errors.go +110 -0
- package/stdlib/fmt/format.go +732 -0
- package/stdlib/fmt/print.go +1232 -0
- package/stdlib/gom/gom.go +293 -0
- package/stdlib/hash/hash.go +53 -0
- package/stdlib/html/html.go +251 -0
- package/stdlib/internal/fmtrt/fmtrt.go +163 -0
- package/stdlib/internal/jsonrt/dec.go +871 -0
- package/stdlib/internal/jsonrt/enc.go +516 -0
- package/stdlib/internal/jsonrt/indent.go +135 -0
- package/stdlib/internal/jsonrt/number.go +27 -0
- package/stdlib/internal/jsonrt/reader.go +73 -0
- package/stdlib/internal/jsonrt/scanner.go +658 -0
- package/stdlib/io/io.go +502 -0
- package/stdlib/iter/iter.go +18 -0
- package/stdlib/maps/maps.go +131 -0
- package/stdlib/math/bits/bits.go +507 -0
- package/stdlib/math/extra.go +272 -0
- package/stdlib/math/math.go +439 -0
- package/stdlib/math/rand/rand.go +297 -0
- package/stdlib/os/os.go +93 -0
- package/stdlib/path/filepath/filepath.go +47 -0
- package/stdlib/path/path.go +394 -0
- package/stdlib/regexp/regexp.go +231 -0
- package/stdlib/slices/slices.go +526 -0
- package/stdlib/slices/sort.go +209 -0
- package/stdlib/slices/zsort_cmp.go +480 -0
- package/stdlib/slices/zsort_ordered.go +482 -0
- package/stdlib/sort/sort.go +500 -0
- package/stdlib/sort/zsort_func.go +480 -0
- package/stdlib/sort/zsort_iface.go +480 -0
- package/stdlib/strconv/float.go +1699 -0
- package/stdlib/strconv/isprint.go +752 -0
- package/stdlib/strconv/quote.go +526 -0
- package/stdlib/strconv/strconv.go +616 -0
- package/stdlib/strings/builder.go +95 -0
- package/stdlib/strings/reader.go +163 -0
- package/stdlib/strings/replacer.go +102 -0
- package/stdlib/strings/strings.go +807 -0
- package/stdlib/sync/sync.go +268 -0
- package/stdlib/testing/async_js.go +61 -0
- package/stdlib/testing/benchmark.go +297 -0
- package/stdlib/testing/testing.go +523 -0
- package/stdlib/time/duration.go +233 -0
- package/stdlib/time/format.go +745 -0
- package/stdlib/time/parse.go +790 -0
- package/stdlib/time/sleep_js.go +63 -0
- package/stdlib/time/time.go +834 -0
- package/stdlib/unicode/unicode.go +250 -0
- package/stdlib/unicode/utf8/utf8.go +464 -0
- package/src/backend/js/stdlib/base64.js +0 -12
- package/src/backend/js/stdlib/binary.js +0 -102
- package/src/backend/js/stdlib/bits.js +0 -46
- package/src/backend/js/stdlib/builder.js +0 -63
- package/src/backend/js/stdlib/bytes.js +0 -122
- package/src/backend/js/stdlib/errors.js +0 -44
- package/src/backend/js/stdlib/fmt.js +0 -178
- package/src/backend/js/stdlib/gom.js +0 -155
- package/src/backend/js/stdlib/hex.js +0 -17
- package/src/backend/js/stdlib/html.js +0 -20
- package/src/backend/js/stdlib/io.js +0 -137
- package/src/backend/js/stdlib/json.js +0 -972
- package/src/backend/js/stdlib/maps.js +0 -45
- package/src/backend/js/stdlib/math.js +0 -69
- package/src/backend/js/stdlib/os.js +0 -13
- package/src/backend/js/stdlib/path.js +0 -48
- package/src/backend/js/stdlib/rand.js +0 -32
- package/src/backend/js/stdlib/regexp.js +0 -54
- package/src/backend/js/stdlib/sha256.js +0 -12
- package/src/backend/js/stdlib/shared.js +0 -17
- package/src/backend/js/stdlib/simd.js +0 -24
- package/src/backend/js/stdlib/slices.js +0 -77
- package/src/backend/js/stdlib/sort.js +0 -30
- package/src/backend/js/stdlib/strconv.js +0 -74
- package/src/backend/js/stdlib/strings.js +0 -222
- package/src/backend/js/stdlib/sync.js +0 -13
- package/src/backend/js/stdlib/testing.js +0 -34
- package/src/backend/js/stdlib/time.js +0 -128
- package/src/backend/js/stdlib/unicode.js +0 -25
- package/src/backend/js/stdlib/utf8.js +0 -26
- package/src/backend/wasm/const-fold.js +0 -205
- package/src/backend/wasm/emit-stdlib.js +0 -13
- package/src/backend/wasm/stdlib/bytes.js +0 -5039
- package/src/backend/wasm/stdlib/core.js +0 -8903
- package/src/backend/wasm/stdlib/io.js +0 -2161
- package/src/backend/wasm/stdlib/packages.js +0 -2400
- package/src/backend/wasm/stdlib/pure.js +0 -720
- package/src/backend/wasm/stdlib/time.js +0 -1200
- package/src/typechecker/stdlib/core.js +0 -801
- package/src/typechecker/stdlib/extended.js +0 -914
- package/src/typechecker/stdlib.js +0 -22
- /package/src/{asset-manager.js → cli/asset-manager.js} +0 -0
- /package/src/{colors.js → cli/colors.js} +0 -0
- /package/src/{dev-server.js → cli/dev-server.js} +0 -0
- /package/src/{minifier.js → cli/minifier.js} +0 -0
- /package/src/{project-config.js → cli/project-config.js} +0 -0
- /package/src/{pwa.js → cli/pwa.js} +0 -0
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `maps` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
/** @type {ThisType<CodeGen>} */
|
|
6
|
-
export const mapsMethods = {
|
|
7
|
-
_genMaps(fn, a) {
|
|
8
|
-
if (fn === "Equal") {
|
|
9
|
-
this.useHelper("equal");
|
|
10
|
-
const [a1, b1] = a();
|
|
11
|
-
return `__equal(${a1}, ${b1})`;
|
|
12
|
-
}
|
|
13
|
-
switch (fn) {
|
|
14
|
-
case "Keys": {
|
|
15
|
-
const [m] = a();
|
|
16
|
-
return `Object.keys(${m})`;
|
|
17
|
-
}
|
|
18
|
-
case "Values": {
|
|
19
|
-
const [m] = a();
|
|
20
|
-
return `Object.values(${m})`;
|
|
21
|
-
}
|
|
22
|
-
case "Clone": {
|
|
23
|
-
const [m] = a();
|
|
24
|
-
return `({...${m}})`;
|
|
25
|
-
}
|
|
26
|
-
case "Copy": {
|
|
27
|
-
const [dst, src] = a();
|
|
28
|
-
return `Object.assign(${dst}, ${src})`;
|
|
29
|
-
}
|
|
30
|
-
case "EqualFunc": {
|
|
31
|
-
const [m1, m2, eq] = a();
|
|
32
|
-
return `((a, b, f) => { const ka = Object.keys(a); if (ka.length !== Object.keys(b).length) return false; return ka.every(k => k in b && f(a[k], b[k])); })(${m1}, ${m2}, ${eq})`;
|
|
33
|
-
}
|
|
34
|
-
case "Delete": {
|
|
35
|
-
const [m, k] = a();
|
|
36
|
-
return `(delete ${m}[${k}], undefined)`;
|
|
37
|
-
}
|
|
38
|
-
case "DeleteFunc": {
|
|
39
|
-
const [m, fn2] = a();
|
|
40
|
-
return `Object.keys(${m}).forEach(k => { if (${fn2}(k, ${m}[k])) delete ${m}[k]; })`;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
},
|
|
45
|
-
};
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `math` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const MATH1 = {
|
|
6
|
-
Abs: "abs",
|
|
7
|
-
Floor: "floor",
|
|
8
|
-
Ceil: "ceil",
|
|
9
|
-
Sqrt: "sqrt",
|
|
10
|
-
Cbrt: "cbrt",
|
|
11
|
-
Log: "log",
|
|
12
|
-
Log2: "log2",
|
|
13
|
-
Log10: "log10",
|
|
14
|
-
Sin: "sin",
|
|
15
|
-
Cos: "cos",
|
|
16
|
-
Tan: "tan",
|
|
17
|
-
Atan: "atan",
|
|
18
|
-
Asin: "asin",
|
|
19
|
-
Acos: "acos",
|
|
20
|
-
Exp: "exp",
|
|
21
|
-
Trunc: "trunc",
|
|
22
|
-
Sinh: "sinh",
|
|
23
|
-
Cosh: "cosh",
|
|
24
|
-
Tanh: "tanh",
|
|
25
|
-
};
|
|
26
|
-
const MATH2 = {
|
|
27
|
-
Pow: "pow",
|
|
28
|
-
Min: "min",
|
|
29
|
-
Max: "max",
|
|
30
|
-
Atan2: "atan2",
|
|
31
|
-
Hypot: "hypot",
|
|
32
|
-
};
|
|
33
|
-
const MATH_EXTRA = {
|
|
34
|
-
// Go rounds half away from zero; Math.round rounds half toward +Infinity.
|
|
35
|
-
Round: ([x]) => `(Math.sign(${x}) * Math.round(Math.abs(${x})))`,
|
|
36
|
-
Mod: ([x, y]) => `${x} % ${y}`,
|
|
37
|
-
Inf: ([x]) => `(${x} >= 0 ? Infinity : -Infinity)`,
|
|
38
|
-
IsNaN: ([x]) => `Number.isNaN(${x})`,
|
|
39
|
-
IsInf: ([x, y]) =>
|
|
40
|
-
`(${y} > 0 ? ${x} === Infinity : ${y} < 0 ? ${x} === -Infinity : !Number.isFinite(${x}))`,
|
|
41
|
-
NaN: () => "NaN",
|
|
42
|
-
Exp2: ([x]) => `Math.pow(2, ${x})`,
|
|
43
|
-
Signbit: ([x]) => `(${x} < 0 || Object.is(${x}, -0))`,
|
|
44
|
-
Copysign: ([x, y]) =>
|
|
45
|
-
`(Math.abs(${x}) * (${y} < 0 || Object.is(${y}, -0) ? -1 : 1))`,
|
|
46
|
-
Dim: ([x, y]) => `Math.max(${x} - ${y}, 0)`,
|
|
47
|
-
Remainder: ([x, y]) =>
|
|
48
|
-
`((x, y) => { if (isNaN(x) || isNaN(y) || y === 0 || !isFinite(x)) return NaN; if (!isFinite(y)) return x; const q = x / y; const r = Math.round(q); const diff = Math.abs(q - r); const n = (diff === 0.5 && (r % 2 !== 0)) ? (r < q ? r + 1 : r - 1) : r; return x - n * y; })(${x}, ${y})`,
|
|
49
|
-
Float64bits: ([x]) =>
|
|
50
|
-
`((f) => { const b = new ArrayBuffer(8); new Float64Array(b)[0] = f; return Number(new BigUint64Array(b)[0]); })(${x})`,
|
|
51
|
-
Float64frombits: ([b]) =>
|
|
52
|
-
`((u) => { const buf = new ArrayBuffer(8); new BigUint64Array(buf)[0] = BigInt(u); return new Float64Array(buf)[0]; })(${b})`,
|
|
53
|
-
Float32bits: ([x]) =>
|
|
54
|
-
`((f) => { const b = new ArrayBuffer(4); new Float32Array(b)[0] = f; return new Uint32Array(b)[0]; })(${x})`,
|
|
55
|
-
Float32frombits: ([b]) =>
|
|
56
|
-
`((u) => { const buf = new ArrayBuffer(4); new Uint32Array(buf)[0] = Number(u) >>> 0; return new Float32Array(buf)[0]; })(${b})`,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/** @type {ThisType<CodeGen>} */
|
|
60
|
-
export const mathMethods = {
|
|
61
|
-
_genMath(fn, a) {
|
|
62
|
-
const args = a();
|
|
63
|
-
const [x, y] = args;
|
|
64
|
-
if (MATH1[fn]) return `Math.${MATH1[fn]}(${x})`;
|
|
65
|
-
if (MATH2[fn]) return `Math.${MATH2[fn]}(${x}, ${y})`;
|
|
66
|
-
const gen = MATH_EXTRA[fn];
|
|
67
|
-
return gen ? gen(args) : undefined;
|
|
68
|
-
},
|
|
69
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `os` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
/** @type {ThisType<CodeGen>} */
|
|
6
|
-
export const osMethods = {
|
|
7
|
-
_genOs(fn, a) {
|
|
8
|
-
const args = a();
|
|
9
|
-
if (fn === "Exit") return `process.exit(${args[0]})`;
|
|
10
|
-
if (fn === "Getenv") return `(process.env[${args[0]}] ?? "")`;
|
|
11
|
-
return undefined;
|
|
12
|
-
},
|
|
13
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `path` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const PATH_DISPATCH = {
|
|
6
|
-
Base: (a) =>
|
|
7
|
-
`((p) => { if (!p) return "."; const stripped = p.replace(/\\/+$/, ""); if (!stripped) return "/"; const i = stripped.lastIndexOf("/"); return i < 0 ? stripped : stripped.slice(i + 1) || "/"; })(${a[0]})`,
|
|
8
|
-
Dir: (a) =>
|
|
9
|
-
`((p) => { const i = p.lastIndexOf("/"); if (i < 0) return "."; const res = p.slice(0, i); return res === "" ? "/" : __pathClean(res); })(${a[0]})`,
|
|
10
|
-
Ext: (a) =>
|
|
11
|
-
`((p) => { const b = p.slice(p.lastIndexOf("/") + 1); const i = b.lastIndexOf("."); return i <= 0 ? "" : b.slice(i); })(${a[0]})`,
|
|
12
|
-
IsAbs: (a) => `(${a[0]}).startsWith("/")`,
|
|
13
|
-
Split: (a) =>
|
|
14
|
-
`((p) => { const i = p.lastIndexOf("/"); return i < 0 ? ["", p] : [p.slice(0, i + 1), p.slice(i + 1)]; })(${a[0]})`,
|
|
15
|
-
Match: (a) =>
|
|
16
|
-
`((pat, name) => { const [m, err] = __pathMatch(pat, name); return [m, err ? __path_err_bad_pattern : null]; })(${a[0]}, ${a[1]})`,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** @type {ThisType<CodeGen>} */
|
|
20
|
-
export const pathMethods = {
|
|
21
|
-
_genPath(fn, a, expr) {
|
|
22
|
-
if (fn === "Match") {
|
|
23
|
-
this.useHelper("error");
|
|
24
|
-
this.useHelper("pathError");
|
|
25
|
-
this.useHelper("pathClean");
|
|
26
|
-
}
|
|
27
|
-
if (fn === "Dir") {
|
|
28
|
-
this.useHelper("pathClean");
|
|
29
|
-
}
|
|
30
|
-
if (fn === "Join") {
|
|
31
|
-
this.useHelper("pathClean");
|
|
32
|
-
const allArgs = expr.args
|
|
33
|
-
.map((e) =>
|
|
34
|
-
e._spread || expr.ellipsis
|
|
35
|
-
? `...(${this.genExpr(e)})`
|
|
36
|
-
: this.genExpr(e),
|
|
37
|
-
)
|
|
38
|
-
.join(", ");
|
|
39
|
-
return `((arr) => arr.length === 0 ? "" : __pathClean(arr.join("/")))([${allArgs}].filter(x => x !== ""))`;
|
|
40
|
-
}
|
|
41
|
-
if (fn === "Clean") {
|
|
42
|
-
this.useHelper("pathClean");
|
|
43
|
-
return `__pathClean(${a()[0]})`;
|
|
44
|
-
}
|
|
45
|
-
const gen = PATH_DISPATCH[fn];
|
|
46
|
-
return gen ? gen(a()) : undefined;
|
|
47
|
-
},
|
|
48
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `math/rand` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const RAND_DISPATCH = {
|
|
6
|
-
Intn: (a) =>
|
|
7
|
-
`((n) => { if (n <= 0) throw new Error("invalid argument to Intn"); return Math.floor(Math.random() * n); })(${a[0]})`,
|
|
8
|
-
Int63n: (a) =>
|
|
9
|
-
`((n) => { if (n <= 0) throw new Error("invalid argument to Int63n"); return Math.floor(Math.random() * n); })(${a[0]})`,
|
|
10
|
-
Int31n: (a) =>
|
|
11
|
-
`((n) => { if (n <= 0) throw new Error("invalid argument to Int31n"); return Math.floor(Math.random() * n); })(${a[0]})`,
|
|
12
|
-
Float64: () => "Math.random()",
|
|
13
|
-
Float32: () => "Math.random()",
|
|
14
|
-
Int: () => "Math.floor(Math.random() * 2147483647)",
|
|
15
|
-
Int31: () => "Math.floor(Math.random() * 2147483647)",
|
|
16
|
-
Int63: () => "Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)",
|
|
17
|
-
Seed: () => "(void 0)",
|
|
18
|
-
Shuffle: (a) =>
|
|
19
|
-
`((n, f) => { if (n < 0) throw new Error("invalid argument to Shuffle"); for (let i = n - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); f(i, j); } })(${a[0]}, ${a[1]})`,
|
|
20
|
-
Perm: (a) =>
|
|
21
|
-
`((n) => { if (n < 0) throw new Error("invalid argument to Perm"); const a = Array.from({length: n}, (_, i) => i); for (let i = n - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [a[i], a[j]] = [a[j], a[i]]; } return a; })(${a[0]})`,
|
|
22
|
-
Read: (a) => `__crypto_rand_read(${a[0]})`,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/** @type {ThisType<CodeGen>} */
|
|
26
|
-
export const randMethods = {
|
|
27
|
-
_genRand(fn, a) {
|
|
28
|
-
if (fn === "Read") this.useHelper("cryptoRand");
|
|
29
|
-
const gen = RAND_DISPATCH[fn];
|
|
30
|
-
return gen ? gen(a()) : undefined;
|
|
31
|
-
},
|
|
32
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `regexp` package and `*Regexp` methods.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const REGEXP_METHOD = {
|
|
6
|
-
MatchString: (re, a) => `${re}.test(${a[0]})`,
|
|
7
|
-
FindString: (re, a) => `(${re}.exec(${a[0]})?.[0] ?? "")`,
|
|
8
|
-
FindStringIndex: (re, a) =>
|
|
9
|
-
`((m => m ? [m.index, m.index + m[0].length] : null)(${re}.exec(${a[0]})))`,
|
|
10
|
-
FindAllString: (re, a) =>
|
|
11
|
-
`[...${a[0]}.matchAll(new RegExp(${re}.source, ${re}.flags.includes("g") ? ${re}.flags : ${re}.flags + "g"))].slice(0, ${a[1]} < 0 ? undefined : ${a[1]}).map(m => m[0])`,
|
|
12
|
-
FindStringSubmatch: (re, a) => `[...(${re}.exec(${a[0]}) ?? [])]`,
|
|
13
|
-
FindAllStringSubmatch: (re, a) =>
|
|
14
|
-
`[...${a[0]}.matchAll(new RegExp(${re}.source, ${re}.flags.includes("g") ? ${re}.flags : ${re}.flags + "g"))].slice(0, ${a[1]} < 0 ? undefined : ${a[1]}).map(m => [...m])`,
|
|
15
|
-
ReplaceAllString: (re, a) =>
|
|
16
|
-
`${a[0]}.replaceAll(new RegExp(${re}.source, ${re}.flags.includes("g") ? ${re}.flags : ${re}.flags + "g"), ${a[1]})`,
|
|
17
|
-
ReplaceAllLiteralString: (re, a) =>
|
|
18
|
-
`${a[0]}.replaceAll(new RegExp(${re}.source, ${re}.flags.includes("g") ? ${re}.flags : ${re}.flags + "g"), ${a[1]}.replace(/\\$/g, '$$$$'))`,
|
|
19
|
-
Split: (re, a) =>
|
|
20
|
-
`${a[0]}.split(${re}).slice(0, ${a[1]} < 0 ? undefined : ${a[1]})`,
|
|
21
|
-
String: (re) => `${re}.source`,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/** @type {ThisType<CodeGen>} */
|
|
25
|
-
export const regexpMethods = {
|
|
26
|
-
_genRegexp(fn, a) {
|
|
27
|
-
// Converts a Go regexp pattern string (which may contain inline flags like (?i))
|
|
28
|
-
// into a JS RegExp, extracting the flags into the second constructor argument.
|
|
29
|
-
const makeRegExp = (pat) =>
|
|
30
|
-
`((p) => { const m = /^\\(\\?([gimsuy]+)\\)/.exec(p); return m ? new RegExp(p.slice(m[0].length), m[1]) : new RegExp(p); })(${pat})`;
|
|
31
|
-
switch (fn) {
|
|
32
|
-
case "MustCompile":
|
|
33
|
-
return makeRegExp(a()[0]);
|
|
34
|
-
case "Compile":
|
|
35
|
-
return `[${makeRegExp(a()[0])}, null]`;
|
|
36
|
-
case "MatchString": {
|
|
37
|
-
const [pat, s] = a();
|
|
38
|
-
return `[new RegExp(${pat}).test(${s}), null]`;
|
|
39
|
-
}
|
|
40
|
-
case "QuoteMeta":
|
|
41
|
-
return `${a()[0]}.replace(/[.*+?^\${}()|[\\]\\\\]/g, '\\\\$&')`;
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
_genRegexpMethodCall(method, expr) {
|
|
47
|
-
const recv = expr.func.expr;
|
|
48
|
-
// *Regexp is a plain JS RegExp — no .value boxing needed
|
|
49
|
-
const re = this.genExpr(recv);
|
|
50
|
-
const args = expr.args.map((a) => this.genExpr(a));
|
|
51
|
-
const gen = REGEXP_METHOD[method];
|
|
52
|
-
return gen ? gen(re, args) : undefined;
|
|
53
|
-
},
|
|
54
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/backend/js/stdlib/sha256.js
|
|
2
|
-
// CodeGen for Go crypto/sha256 package.
|
|
3
|
-
|
|
4
|
-
export const sha256Methods = {
|
|
5
|
-
_genSha256(fn, a) {
|
|
6
|
-
this.useHelper("sha256");
|
|
7
|
-
const args = a();
|
|
8
|
-
if (fn === "Sum256") return `__sha256.Sum256(${args[0]})`;
|
|
9
|
-
if (fn === "New") return "__sha256.New()";
|
|
10
|
-
return undefined;
|
|
11
|
-
},
|
|
12
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// CodeGen for the `gofront/shared` package: in js packages a shared buffer is
|
|
2
|
-
// just a TypedArray (no linear memory is involved); in wasm packages the facade
|
|
3
|
-
// hands out zero-copy views onto the module memory.
|
|
4
|
-
|
|
5
|
-
import { SHARED_KINDS } from "../../../typechecker/stdlib/shared.js";
|
|
6
|
-
|
|
7
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
8
|
-
|
|
9
|
-
/** @type {ThisType<CodeGen>} */
|
|
10
|
-
export const sharedMethods = {
|
|
11
|
-
_genShared(fn, a) {
|
|
12
|
-
if (!fn.startsWith("New")) return undefined;
|
|
13
|
-
const info = SHARED_KINDS[fn.slice(3)];
|
|
14
|
-
if (!info) return undefined;
|
|
15
|
-
return `new ${info.ctor}(${a()[0]})`;
|
|
16
|
-
},
|
|
17
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// src/backend/js/stdlib/simd.js
|
|
2
|
-
// CodeGen for the `gofront/simd` package in JS packages.
|
|
3
|
-
|
|
4
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
5
|
-
|
|
6
|
-
/** @type {ThisType<CodeGen>} */
|
|
7
|
-
export const simdMethods = {
|
|
8
|
-
_genSimd(fn, a) {
|
|
9
|
-
this.useHelper("simd");
|
|
10
|
-
const args = a();
|
|
11
|
-
switch (fn) {
|
|
12
|
-
case "Splat":
|
|
13
|
-
return `__simd_splat(${args[0]})`;
|
|
14
|
-
case "NewF32x4":
|
|
15
|
-
return `__simd_f32x4(${args[0]}, ${args[1]}, ${args[2]}, ${args[3]})`;
|
|
16
|
-
case "LoadF32x4":
|
|
17
|
-
return `__simd_load(${args[0]}, ${args[1]})`;
|
|
18
|
-
case "StoreF32x4":
|
|
19
|
-
return `__simd_store(${args[0]}, ${args[1]}, ${args[2]})`;
|
|
20
|
-
default:
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { isTypedArraySlice } from "../../../typechecker/types.js";
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const SLICES_DISPATCH = {
|
|
6
|
-
Contains: (a) => `${a[0]}.includes(${a[1]})`,
|
|
7
|
-
ContainsFunc: (a) =>
|
|
8
|
-
`((s, f) => { s = s || []; for (let i = 0; i < s.length; i++) { if (f(s[i])) return true; } return false; })(${a[0]}, ${a[1]})`,
|
|
9
|
-
Index: (a) => `${a[0]}.indexOf(${a[1]})`,
|
|
10
|
-
IndexFunc: (a) =>
|
|
11
|
-
`((s, f) => { s = s || []; for (let i = 0; i < s.length; i++) { if (f(s[i])) return i; } return -1; })(${a[0]}, ${a[1]})`,
|
|
12
|
-
BinarySearch: (a) =>
|
|
13
|
-
`((s, target) => { s = s || []; let i = 0, j = s.length; while (i < j) { const h = (i + j) >>> 1; if (s[h] < target) i = h + 1; else j = h; } return [i, i < s.length && s[i] === target]; })(${a[0]}, ${a[1]})`,
|
|
14
|
-
BinarySearchFunc: (a) =>
|
|
15
|
-
`((s, target, cmp) => { s = s || []; let i = 0, j = s.length; while (i < j) { const h = (i + j) >>> 1; if (cmp(s[h], target) < 0) i = h + 1; else j = h; } return [i, i < s.length && cmp(s[i], target) === 0]; })(${a[0]}, ${a[1]}, ${a[2]})`,
|
|
16
|
-
Compare: (a) =>
|
|
17
|
-
`((a, b) => { a = a || []; b = b || []; for (let i = 0; i < a.length && i < b.length; i++) { const x = a[i], y = b[i]; const xN = typeof x === "number" && isNaN(x), yN = typeof y === "number" && isNaN(y); if (xN && yN) continue; if (xN) return -1; if (yN) return 1; if (x < y) return -1; if (x > y) return 1; } return a.length < b.length ? -1 : a.length > b.length ? 1 : 0; })(${a[0]}, ${a[1]})`,
|
|
18
|
-
Sort: (a) =>
|
|
19
|
-
`((s) => s ? s.sort((a, b) => a < b ? -1 : a > b ? 1 : 0) : null)(${a[0]})`,
|
|
20
|
-
SortFunc: (a) => `((s, f) => s ? s.sort(f) : null)(${a[0]}, ${a[1]})`,
|
|
21
|
-
SortStableFunc: (a) => `((s, f) => s ? s.sort(f) : null)(${a[0]}, ${a[1]})`,
|
|
22
|
-
IsSorted: (a) =>
|
|
23
|
-
`((s) => { s = s || []; for (let i = 0; i < s.length; i++) { if (typeof s[i] === "number" && isNaN(s[i])) return false; if (i > 0 && s[i] < s[i-1]) return false; } return true; })(${a[0]})`,
|
|
24
|
-
IsSortedFunc: (a) =>
|
|
25
|
-
`((s, f) => { s = s || []; for (let i = 1; i < s.length; i++) { if (f(s[i], s[i-1]) < 0) return false; } return true; })(${a[0]}, ${a[1]})`,
|
|
26
|
-
Reverse: (a) => `((s) => s ? s.reverse() : null)(${a[0]})`,
|
|
27
|
-
Max: (a) =>
|
|
28
|
-
`((s) => { if (!s || s.length === 0) throw new Error("slices.Max: empty list"); let m = s[0]; for (let i = 1; i < s.length; i++) { const x = s[i]; if ((typeof x === "number" && isNaN(x)) || x > m || (x === 0 && m === 0 && Object.is(m, -0) && !Object.is(x, -0))) m = x; } return m; })(${a[0]})`,
|
|
29
|
-
Min: (a) =>
|
|
30
|
-
`((s) => { if (!s || s.length === 0) throw new Error("slices.Min: empty list"); let m = s[0]; for (let i = 1; i < s.length; i++) { const x = s[i]; if ((typeof x === "number" && isNaN(x)) || x < m || (x === 0 && m === 0 && Object.is(x, -0))) m = x; } return m; })(${a[0]})`,
|
|
31
|
-
MaxFunc: (a) =>
|
|
32
|
-
`((s, f) => { if (!s || s.length === 0) throw new Error("slices.MaxFunc: empty list"); return s.reduce((m, x) => f(x, m) > 0 ? x : m); })(${a[0]}, ${a[1]})`,
|
|
33
|
-
MinFunc: (a) =>
|
|
34
|
-
`((s, f) => { if (!s || s.length === 0) throw new Error("slices.MinFunc: empty list"); return s.reduce((m, x) => f(x, m) < 0 ? x : m); })(${a[0]}, ${a[1]})`,
|
|
35
|
-
Clone: (a) => `((s) => s ? s.slice() : null)(${a[0]})`,
|
|
36
|
-
Compact: (a) =>
|
|
37
|
-
`((s) => { if (!s || s.length === 0) return s; let k = 1; for (let i = 1; i < s.length; i++) { if (s[i] !== s[k - 1]) s[k++] = s[i]; } return ArrayBuffer.isView(s) ? s.subarray(0, k) : (s.length = k, s); })(${a[0]})`,
|
|
38
|
-
CompactFunc: (a) =>
|
|
39
|
-
`((s, f) => { if (!s || s.length === 0) return s; let k = 1; for (let i = 1; i < s.length; i++) { if (!f(s[i], s[k - 1])) s[k++] = s[i]; } return ArrayBuffer.isView(s) ? s.subarray(0, k) : (s.length = k, s); })(${a[0]}, ${a[1]})`,
|
|
40
|
-
Concat: (a) =>
|
|
41
|
-
a.length === 0
|
|
42
|
-
? "null"
|
|
43
|
-
: `((...slices) => { const nonNull = slices.filter(Boolean); if (nonNull.length === 0) return slices[0] === null ? null : []; if (ArrayBuffer.isView(nonNull[0])) { const totalLen = nonNull.reduce((sum, s) => sum + s.length, 0); const out = new nonNull[0].constructor(totalLen); let off = 0; for (const s of nonNull) { out.set(s, off); off += s.length; } return out; } return [].concat(...slices.map(s => s ? (ArrayBuffer.isView(s) ? Array.from(s) : s) : [])); })(${a.map((x) => `(${x})`).join(", ")})`,
|
|
44
|
-
Delete: (a) =>
|
|
45
|
-
`((s, i, j) => { if (!s && i === 0 && j === 0) return s; s = s || []; if (i < 0 || j < i || j > s.length) throw new Error("runtime error: slice bounds out of range"); if (ArrayBuffer.isView(s)) { s.copyWithin(i, j); return s.subarray(0, s.length - (j - i)); } s.splice(i, j - i); return s; })(${a[0]}, ${a[1]}, ${a[2]})`,
|
|
46
|
-
DeleteFunc: (a) =>
|
|
47
|
-
`((s, f) => { if (!s || s.length === 0) return s; let k = 0; for (let i = 0; i < s.length; i++) { if (!f(s[i])) s[k++] = s[i]; } return ArrayBuffer.isView(s) ? s.subarray(0, k) : (s.length = k, s); })(${a[0]}, ${a[1]})`,
|
|
48
|
-
Insert: (a, isTyped) => {
|
|
49
|
-
const items = a.slice(2);
|
|
50
|
-
const nilInit = isTyped ? "new Uint8Array(0)" : "[]";
|
|
51
|
-
return `((s, i, ...v) => { if (!s && i === 0) s = ${nilInit}; if (!s || i < 0 || i > s.length) throw new Error("runtime error: slice bounds out of range"); if (ArrayBuffer.isView(s)) { const res = new s.constructor(s.length + v.length); res.set(s.subarray(0, i), 0); res.set(v, i); res.set(s.subarray(i), i + v.length); return res; } s.splice(i, 0, ...v); return s; })(${a[0]}, ${a[1]}${items.length ? `, ${items.join(", ")}` : ""})`;
|
|
52
|
-
},
|
|
53
|
-
Replace: (a, isTyped) => {
|
|
54
|
-
const items = a.slice(3);
|
|
55
|
-
const nilInit = isTyped ? "new Uint8Array(0)" : "[]";
|
|
56
|
-
return `((s, i, j, ...v) => { if (!s && i === 0 && j === 0) s = ${nilInit}; if (!s || i < 0 || j < i || j > s.length) throw new Error("runtime error: slice bounds out of range"); if (ArrayBuffer.isView(s)) { const res = new s.constructor(s.length - (j - i) + v.length); res.set(s.subarray(0, i), 0); res.set(v, i); res.set(s.subarray(j), i + v.length); return res; } s.splice(i, j - i, ...v); return s; })(${a[0]}, ${a[1]}, ${a[2]}${items.length ? `, ${items.join(", ")}` : ""})`;
|
|
57
|
-
},
|
|
58
|
-
Grow: (a, isTyped) => {
|
|
59
|
-
const nilInit = isTyped ? "new Uint8Array(0)" : "[]";
|
|
60
|
-
return `((s, n) => { if (n < 0) throw new Error("runtime error: makeslice: len out of range"); if (!s) return ${nilInit}; return s.slice(); })(${a[0]}, ${a[1]})`;
|
|
61
|
-
},
|
|
62
|
-
Clip: (a) => `((s) => s ? s.slice() : null)(${a[0]})`,
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/** @type {ThisType<CodeGen>} */
|
|
66
|
-
export const slicesMethods = {
|
|
67
|
-
_genSlices(fn, a, expr) {
|
|
68
|
-
if (fn === "Equal") {
|
|
69
|
-
this.useHelper("equal");
|
|
70
|
-
const [a1, b1] = a();
|
|
71
|
-
return `__equal(${a1}, ${b1})`;
|
|
72
|
-
}
|
|
73
|
-
const isTyped = isTypedArraySlice(expr?.args?.[0]?._type);
|
|
74
|
-
const gen = SLICES_DISPATCH[fn];
|
|
75
|
-
return gen ? gen(a(), isTyped) : undefined;
|
|
76
|
-
},
|
|
77
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `sort` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
const SORT_DISPATCH = {
|
|
6
|
-
Ints: (a) => `${a[0]}.sort((a, b) => a - b)`,
|
|
7
|
-
Float64s: (a) => `${a[0]}.sort((a, b) => a - b)`,
|
|
8
|
-
Strings: (a) => `${a[0]}.sort()`,
|
|
9
|
-
Slice: (a) => `__sortSlice(${a[0]}, ${a[1]})`,
|
|
10
|
-
SliceStable: (a) => `__sortSlice(${a[0]}, ${a[1]})`,
|
|
11
|
-
SliceIsSorted: (a) =>
|
|
12
|
-
`((s, less) => { for (let i = (s?.length ?? 0) - 1; i > 0; i--) if (less(i, i - 1)) return false; return true; })(${a[0]}, ${a[1]})`,
|
|
13
|
-
Search: (a) =>
|
|
14
|
-
`((n, f) => { let lo = 0, hi = n; while (lo < hi) { const mid = (lo + hi) >>> 1; if (f(mid)) hi = mid; else lo = mid + 1; } return lo; })(${a[0]}, ${a[1]})`,
|
|
15
|
-
IntsAreSorted: (a) =>
|
|
16
|
-
`(${a[0]}).every((v, i, a) => i === 0 || a[i - 1] <= v)`,
|
|
17
|
-
Float64sAreSorted: (a) =>
|
|
18
|
-
`(${a[0]}).every((v, i, a) => i === 0 || a[i - 1] <= v)`,
|
|
19
|
-
StringsAreSorted: (a) =>
|
|
20
|
-
`(${a[0]}).every((v, i, a) => i === 0 || a[i - 1] <= v)`,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/** @type {ThisType<CodeGen>} */
|
|
24
|
-
export const sortMethods = {
|
|
25
|
-
_genSort(fn, a) {
|
|
26
|
-
if (fn === "Slice" || fn === "SliceStable") this.useHelper("sortSlice");
|
|
27
|
-
const gen = SORT_DISPATCH[fn];
|
|
28
|
-
return gen ? gen(a()) : undefined;
|
|
29
|
-
},
|
|
30
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// CodeGen for Go `strconv` package.
|
|
2
|
-
|
|
3
|
-
/** @typedef {import('../index.js').CodeGen} CodeGen */
|
|
4
|
-
|
|
5
|
-
// Parsers return [value, msg|null] from the shared __strconv_* helpers
|
|
6
|
-
// (runtime.js); the message becomes a Go error value.
|
|
7
|
-
const parsed = (call, toValue = "r[0]") =>
|
|
8
|
-
`((r) => [${toValue}, r[1] === null ? null : __error(r[1], r[1].includes("invalid syntax") ? __strconv_err_syntax : r[1].includes("value out of range") ? __strconv_err_range : null)])(${call})`;
|
|
9
|
-
|
|
10
|
-
const STRCONV_DISPATCH = {
|
|
11
|
-
Itoa: (a) => `String(${a[0]})`,
|
|
12
|
-
Atoi: (a) => parsed(`__strconv_atoi(${a[0]})`, "Number(r[0])"),
|
|
13
|
-
FormatBool: (a) => `String(${a[0]})`,
|
|
14
|
-
FormatInt: (a) => `(${a[0]}).toString(${a[1]})`,
|
|
15
|
-
FormatFloat: (a) =>
|
|
16
|
-
a.length < 3
|
|
17
|
-
? `String(${a[0]})`
|
|
18
|
-
: `__strconv_format_float(${a[0]}, ${a[1]}, ${a[2]})`,
|
|
19
|
-
ParseFloat: (a) => parsed(`__strconv_parse_float(${a[0]})`),
|
|
20
|
-
ParseInt: (a) =>
|
|
21
|
-
parsed(
|
|
22
|
-
`__strconv_parse_int(${a[0]}, ${a[1]}, ${a[2] ?? 64})`,
|
|
23
|
-
"Number(r[0])",
|
|
24
|
-
),
|
|
25
|
-
ParseBool: (a) => parsed(`__strconv_parse_bool(${a[0]})`),
|
|
26
|
-
Quote: (a) => `JSON.stringify(${a[0]})`,
|
|
27
|
-
Unquote: (a) =>
|
|
28
|
-
`((s) => { if (typeof s === "string" && s.startsWith("\`") && s.endsWith("\`") && s.length >= 2) { if (s.slice(1, -1).includes("\`")) return ["", __strconv_err_syntax]; return [s.slice(1, -1), null]; } try { const v = JSON.parse(s); if (typeof v !== "string") throw 0; return [v, null]; } catch(e) { return ["", __strconv_err_syntax]; } })(${a[0]})`,
|
|
29
|
-
AppendInt: (a) =>
|
|
30
|
-
`((d, s) => { const e = new TextEncoder().encode(s); const dl = d ? d.length : 0; const r = new Uint8Array(dl + e.length); if (dl > 0) r.set(d, 0); r.set(e, dl); return r; })(${a[0]}, (${a[1]}).toString(${a[2]}))`,
|
|
31
|
-
AppendUint: (a) =>
|
|
32
|
-
`((d, s) => { const e = new TextEncoder().encode(s); const dl = d ? d.length : 0; const r = new Uint8Array(dl + e.length); if (dl > 0) r.set(d, 0); r.set(e, dl); return r; })(${a[0]}, (BigInt.asUintN(64, BigInt(${a[1]}))).toString(${a[2]}))`,
|
|
33
|
-
AppendBool: (a) =>
|
|
34
|
-
`((d, s) => { const e = new TextEncoder().encode(s); const dl = d ? d.length : 0; const r = new Uint8Array(dl + e.length); if (dl > 0) r.set(d, 0); r.set(e, dl); return r; })(${a[0]}, String(${a[1]}))`,
|
|
35
|
-
AppendFloat: (a) =>
|
|
36
|
-
`((d, s) => { const e = new TextEncoder().encode(s); const dl = d ? d.length : 0; const r = new Uint8Array(dl + e.length); if (dl > 0) r.set(d, 0); r.set(e, dl); return r; })(${a[0]}, __strconv_format_float(${a[1]}, typeof (${a[2]}) === "string" ? (${a[2]}).charCodeAt(0) : (${a[2]}), ${a[3]}))`,
|
|
37
|
-
FormatUint: (a) => `(BigInt.asUintN(64, BigInt(${a[0]}))).toString(${a[1]})`,
|
|
38
|
-
ParseUint: (a) =>
|
|
39
|
-
parsed(
|
|
40
|
-
`__strconv_parse_uint(${a[0]}, ${a[1]}, ${a[2] ?? 64})`,
|
|
41
|
-
"Number(r[0])",
|
|
42
|
-
),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const USES_ERROR = new Set([
|
|
46
|
-
"Atoi",
|
|
47
|
-
"ParseFloat",
|
|
48
|
-
"ParseInt",
|
|
49
|
-
"ParseUint",
|
|
50
|
-
"ParseBool",
|
|
51
|
-
"Unquote",
|
|
52
|
-
]);
|
|
53
|
-
const USES_STRCONV = new Set([
|
|
54
|
-
"Atoi",
|
|
55
|
-
"ParseFloat",
|
|
56
|
-
"ParseInt",
|
|
57
|
-
"ParseUint",
|
|
58
|
-
"ParseBool",
|
|
59
|
-
"FormatFloat",
|
|
60
|
-
"AppendFloat",
|
|
61
|
-
]);
|
|
62
|
-
|
|
63
|
-
/** @type {ThisType<CodeGen>} */
|
|
64
|
-
export const strconvMethods = {
|
|
65
|
-
_genStrconv(fn, a) {
|
|
66
|
-
const gen = STRCONV_DISPATCH[fn];
|
|
67
|
-
if (gen && USES_ERROR.has(fn)) {
|
|
68
|
-
this.useHelper("error");
|
|
69
|
-
this.useHelper("strconvError");
|
|
70
|
-
}
|
|
71
|
-
if (gen && USES_STRCONV.has(fn)) this.useHelper("strconv");
|
|
72
|
-
return gen ? gen(a()) : undefined;
|
|
73
|
-
},
|
|
74
|
-
};
|