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
package/src/typechecker/types.js
CHANGED
|
@@ -102,529 +102,183 @@ export const BROWSER_GLOBALS = new Set([
|
|
|
102
102
|
"TextDecoder",
|
|
103
103
|
]);
|
|
104
104
|
|
|
105
|
-
// Stdlib packages the WASM backend can emit. Extend as src/backend/wasm/
|
|
105
|
+
// Stdlib packages the WASM backend can emit. Extend as src/backend/wasm/stdlib/
|
|
106
106
|
// gains support; anything not listed is rejected at import with "not yet available in
|
|
107
107
|
// wasm packages".
|
|
108
108
|
export const WASM_SUPPORTED_STDLIB = new Set([
|
|
109
|
-
"math",
|
|
110
|
-
"math/bits",
|
|
111
|
-
"math/rand",
|
|
112
|
-
"errors",
|
|
113
|
-
"fmt",
|
|
114
|
-
"strings",
|
|
115
|
-
"bytes",
|
|
116
|
-
"strconv",
|
|
117
|
-
"unicode",
|
|
118
|
-
"unicode/utf8",
|
|
119
|
-
"slices",
|
|
120
|
-
"maps",
|
|
121
|
-
"sort",
|
|
122
|
-
"path",
|
|
123
|
-
"path/filepath",
|
|
124
|
-
"html",
|
|
125
|
-
"io",
|
|
126
|
-
"time",
|
|
127
|
-
"testing",
|
|
128
109
|
"gofront/shared",
|
|
129
110
|
"gofront/simd",
|
|
130
|
-
"sync",
|
|
131
|
-
"crypto/rand",
|
|
132
|
-
"crypto/sha256",
|
|
133
|
-
"encoding/binary",
|
|
134
|
-
"encoding/hex",
|
|
135
|
-
"encoding/base64",
|
|
136
111
|
]);
|
|
137
112
|
|
|
138
|
-
export const STDLIB_PACKAGES =
|
|
139
|
-
...WASM_SUPPORTED_STDLIB,
|
|
140
|
-
"os",
|
|
141
|
-
"gom",
|
|
142
|
-
"regexp",
|
|
143
|
-
"encoding/json",
|
|
144
|
-
]);
|
|
113
|
+
export const STDLIB_PACKAGES = WASM_SUPPORTED_STDLIB;
|
|
145
114
|
|
|
146
115
|
// Per-namespace member subset the WASM backend implements. `null` means every
|
|
147
116
|
// member the checker knows about. Members outside the set are rejected in
|
|
148
117
|
// wasm/both packages with "'strings.Split' is not yet available in wasm packages".
|
|
149
|
-
export const WASM_STDLIB_MEMBERS = new Map(
|
|
150
|
-
["json", new Set()],
|
|
151
|
-
[
|
|
152
|
-
"math",
|
|
153
|
-
new Set([
|
|
154
|
-
"Sqrt",
|
|
155
|
-
"Floor",
|
|
156
|
-
"Ceil",
|
|
157
|
-
"Trunc",
|
|
158
|
-
"Abs",
|
|
159
|
-
"Min",
|
|
160
|
-
"Max",
|
|
161
|
-
"Copysign",
|
|
162
|
-
"Dim",
|
|
163
|
-
"Inf",
|
|
164
|
-
"NaN",
|
|
165
|
-
"IsNaN",
|
|
166
|
-
"IsInf",
|
|
167
|
-
"Signbit",
|
|
168
|
-
"Sin",
|
|
169
|
-
"Cos",
|
|
170
|
-
"Tan",
|
|
171
|
-
"Asin",
|
|
172
|
-
"Acos",
|
|
173
|
-
"Atan",
|
|
174
|
-
"Atan2",
|
|
175
|
-
"Pow",
|
|
176
|
-
"Mod",
|
|
177
|
-
"Hypot",
|
|
178
|
-
"Cbrt",
|
|
179
|
-
"Exp",
|
|
180
|
-
"Exp2",
|
|
181
|
-
"Log",
|
|
182
|
-
"Log2",
|
|
183
|
-
"Log10",
|
|
184
|
-
"Round",
|
|
185
|
-
"Remainder",
|
|
186
|
-
"Float64bits",
|
|
187
|
-
"Float64frombits",
|
|
188
|
-
"Float32bits",
|
|
189
|
-
"Float32frombits",
|
|
190
|
-
"Sinh",
|
|
191
|
-
"Cosh",
|
|
192
|
-
"Tanh",
|
|
193
|
-
// constants
|
|
194
|
-
"E",
|
|
195
|
-
"Pi",
|
|
196
|
-
"Phi",
|
|
197
|
-
"Sqrt2",
|
|
198
|
-
"SqrtE",
|
|
199
|
-
"SqrtPi",
|
|
200
|
-
"SqrtPhi",
|
|
201
|
-
"Ln2",
|
|
202
|
-
"Log2E",
|
|
203
|
-
"Ln10",
|
|
204
|
-
"Log10E",
|
|
205
|
-
"MaxFloat32",
|
|
206
|
-
"SmallestNonzeroFloat32",
|
|
207
|
-
"MaxFloat64",
|
|
208
|
-
"SmallestNonzeroFloat64",
|
|
209
|
-
"MaxInt",
|
|
210
|
-
"MinInt",
|
|
211
|
-
"MaxInt8",
|
|
212
|
-
"MinInt8",
|
|
213
|
-
"MaxInt16",
|
|
214
|
-
"MinInt16",
|
|
215
|
-
"MaxInt32",
|
|
216
|
-
"MinInt32",
|
|
217
|
-
"MaxInt64",
|
|
218
|
-
"MinInt64",
|
|
219
|
-
"MaxUint8",
|
|
220
|
-
"MaxUint16",
|
|
221
|
-
"MaxUint32",
|
|
222
|
-
"MaxUint",
|
|
223
|
-
"MaxUint64",
|
|
224
|
-
]),
|
|
225
|
-
],
|
|
226
|
-
[
|
|
227
|
-
"bits",
|
|
228
|
-
new Set([
|
|
229
|
-
"LeadingZeros32",
|
|
230
|
-
"LeadingZeros64",
|
|
231
|
-
"TrailingZeros32",
|
|
232
|
-
"TrailingZeros64",
|
|
233
|
-
"OnesCount32",
|
|
234
|
-
"OnesCount64",
|
|
235
|
-
"RotateLeft32",
|
|
236
|
-
"RotateLeft64",
|
|
237
|
-
"ReverseBytes16",
|
|
238
|
-
"ReverseBytes32",
|
|
239
|
-
"ReverseBytes64",
|
|
240
|
-
"Len32",
|
|
241
|
-
"Len64",
|
|
242
|
-
"Reverse32",
|
|
243
|
-
"Reverse64",
|
|
244
|
-
]),
|
|
245
|
-
],
|
|
246
|
-
["errors", new Set(["New", "Is", "Unwrap", "As", "Join"])],
|
|
247
|
-
[
|
|
248
|
-
"utf8",
|
|
249
|
-
new Set([
|
|
250
|
-
"RuneCountInString",
|
|
251
|
-
"RuneLen",
|
|
252
|
-
"ValidString",
|
|
253
|
-
"ValidRune",
|
|
254
|
-
"DecodeRuneInString",
|
|
255
|
-
"DecodeLastRuneInString",
|
|
256
|
-
"FullRuneInString",
|
|
257
|
-
"RuneError",
|
|
258
|
-
"MaxRune",
|
|
259
|
-
"UTFMax",
|
|
260
|
-
]),
|
|
261
|
-
],
|
|
262
|
-
[
|
|
263
|
-
"sort",
|
|
264
|
-
new Set([
|
|
265
|
-
"Ints",
|
|
266
|
-
"Float64s",
|
|
267
|
-
"Strings",
|
|
268
|
-
"Slice",
|
|
269
|
-
"SliceStable",
|
|
270
|
-
"SliceIsSorted",
|
|
271
|
-
"Search",
|
|
272
|
-
"IntsAreSorted",
|
|
273
|
-
"Float64sAreSorted",
|
|
274
|
-
"StringsAreSorted",
|
|
275
|
-
]),
|
|
276
|
-
],
|
|
277
|
-
[
|
|
278
|
-
"fmt",
|
|
279
|
-
new Set([
|
|
280
|
-
"Sprintf",
|
|
281
|
-
"Errorf",
|
|
282
|
-
"Printf",
|
|
283
|
-
"Println",
|
|
284
|
-
"Print",
|
|
285
|
-
"Fprintf",
|
|
286
|
-
"Fprintln",
|
|
287
|
-
"Fprint",
|
|
288
|
-
"Sscan",
|
|
289
|
-
"Sscanln",
|
|
290
|
-
"Sscanf",
|
|
291
|
-
]),
|
|
292
|
-
],
|
|
293
|
-
[
|
|
294
|
-
"strings",
|
|
295
|
-
new Set([
|
|
296
|
-
"Contains",
|
|
297
|
-
"ContainsAny",
|
|
298
|
-
"ContainsRune",
|
|
299
|
-
"HasPrefix",
|
|
300
|
-
"HasSuffix",
|
|
301
|
-
"Index",
|
|
302
|
-
"IndexAny",
|
|
303
|
-
"IndexByte",
|
|
304
|
-
"IndexRune",
|
|
305
|
-
"LastIndex",
|
|
306
|
-
"LastIndexByte",
|
|
307
|
-
"Count",
|
|
308
|
-
"Repeat",
|
|
309
|
-
"Replace",
|
|
310
|
-
"ReplaceAll",
|
|
311
|
-
"ToUpper",
|
|
312
|
-
"ToLower",
|
|
313
|
-
"Title",
|
|
314
|
-
"ToTitle",
|
|
315
|
-
"TrimSpace",
|
|
316
|
-
"Trim",
|
|
317
|
-
"TrimLeft",
|
|
318
|
-
"TrimRight",
|
|
319
|
-
"TrimPrefix",
|
|
320
|
-
"TrimSuffix",
|
|
321
|
-
"EqualFold",
|
|
322
|
-
"Split",
|
|
323
|
-
"Fields",
|
|
324
|
-
"Join",
|
|
325
|
-
"Cut",
|
|
326
|
-
"CutPrefix",
|
|
327
|
-
"CutSuffix",
|
|
328
|
-
"SplitN",
|
|
329
|
-
"SplitAfter",
|
|
330
|
-
"SplitAfterN",
|
|
331
|
-
"LastIndexAny",
|
|
332
|
-
"Map",
|
|
333
|
-
"IndexFunc",
|
|
334
|
-
"LastIndexFunc",
|
|
335
|
-
"TrimFunc",
|
|
336
|
-
"TrimLeftFunc",
|
|
337
|
-
"TrimRightFunc",
|
|
338
|
-
"FieldsFunc",
|
|
339
|
-
"NewReplacer",
|
|
340
|
-
"Builder",
|
|
341
|
-
"NewReader",
|
|
342
|
-
"Reader",
|
|
343
|
-
]),
|
|
344
|
-
],
|
|
345
|
-
[
|
|
346
|
-
"strconv",
|
|
347
|
-
new Set([
|
|
348
|
-
"Itoa",
|
|
349
|
-
"Atoi",
|
|
350
|
-
"FormatInt",
|
|
351
|
-
"FormatUint",
|
|
352
|
-
"FormatFloat",
|
|
353
|
-
"FormatBool",
|
|
354
|
-
"ParseInt",
|
|
355
|
-
"ParseUint",
|
|
356
|
-
"ParseFloat",
|
|
357
|
-
"ParseBool",
|
|
358
|
-
"Quote",
|
|
359
|
-
"Unquote",
|
|
360
|
-
"AppendInt",
|
|
361
|
-
"AppendUint",
|
|
362
|
-
"AppendFloat",
|
|
363
|
-
"AppendBool",
|
|
364
|
-
"ErrSyntax",
|
|
365
|
-
"ErrRange",
|
|
366
|
-
]),
|
|
367
|
-
],
|
|
368
|
-
[
|
|
369
|
-
"slices",
|
|
370
|
-
new Set([
|
|
371
|
-
"Sort",
|
|
372
|
-
"Reverse",
|
|
373
|
-
"Contains",
|
|
374
|
-
"Index",
|
|
375
|
-
"IndexFunc",
|
|
376
|
-
"ContainsFunc",
|
|
377
|
-
"BinarySearch",
|
|
378
|
-
"BinarySearchFunc",
|
|
379
|
-
"Equal",
|
|
380
|
-
"Clone",
|
|
381
|
-
"Compare",
|
|
382
|
-
"SortFunc",
|
|
383
|
-
"SortStableFunc",
|
|
384
|
-
"IsSorted",
|
|
385
|
-
"IsSortedFunc",
|
|
386
|
-
"Min",
|
|
387
|
-
"Max",
|
|
388
|
-
"MinFunc",
|
|
389
|
-
"MaxFunc",
|
|
390
|
-
"Compact",
|
|
391
|
-
"CompactFunc",
|
|
392
|
-
"Concat",
|
|
393
|
-
"Delete",
|
|
394
|
-
"DeleteFunc",
|
|
395
|
-
"Insert",
|
|
396
|
-
"Replace",
|
|
397
|
-
"Grow",
|
|
398
|
-
"Clip",
|
|
399
|
-
]),
|
|
400
|
-
],
|
|
401
|
-
[
|
|
402
|
-
"maps",
|
|
403
|
-
new Set([
|
|
404
|
-
"Keys",
|
|
405
|
-
"Values",
|
|
406
|
-
"Clone",
|
|
407
|
-
"Copy",
|
|
408
|
-
"Equal",
|
|
409
|
-
"EqualFunc",
|
|
410
|
-
"Delete",
|
|
411
|
-
"DeleteFunc",
|
|
412
|
-
]),
|
|
413
|
-
],
|
|
414
|
-
[
|
|
415
|
-
"unicode",
|
|
416
|
-
new Set([
|
|
417
|
-
"IsLetter",
|
|
418
|
-
"IsDigit",
|
|
419
|
-
"IsSpace",
|
|
420
|
-
"IsUpper",
|
|
421
|
-
"IsLower",
|
|
422
|
-
"IsPunct",
|
|
423
|
-
"IsControl",
|
|
424
|
-
"IsPrint",
|
|
425
|
-
"IsGraphic",
|
|
426
|
-
"ToUpper",
|
|
427
|
-
"ToLower",
|
|
428
|
-
]),
|
|
429
|
-
],
|
|
430
|
-
[
|
|
431
|
-
"rand",
|
|
432
|
-
new Set([
|
|
433
|
-
"Intn",
|
|
434
|
-
"Float64",
|
|
435
|
-
"Float32",
|
|
436
|
-
"Int",
|
|
437
|
-
"Int63",
|
|
438
|
-
"Int63n",
|
|
439
|
-
"Int31",
|
|
440
|
-
"Int31n",
|
|
441
|
-
"Seed",
|
|
442
|
-
"Shuffle",
|
|
443
|
-
"Perm",
|
|
444
|
-
"Read",
|
|
445
|
-
"Reader",
|
|
446
|
-
]),
|
|
447
|
-
],
|
|
448
|
-
[
|
|
449
|
-
"bytes",
|
|
450
|
-
new Set([
|
|
451
|
-
"Contains",
|
|
452
|
-
"HasPrefix",
|
|
453
|
-
"HasSuffix",
|
|
454
|
-
"Index",
|
|
455
|
-
"Count",
|
|
456
|
-
"Repeat",
|
|
457
|
-
"Replace",
|
|
458
|
-
"ReplaceAll",
|
|
459
|
-
"ToUpper",
|
|
460
|
-
"ToLower",
|
|
461
|
-
"TrimSpace",
|
|
462
|
-
"Trim",
|
|
463
|
-
"Equal",
|
|
464
|
-
"Split",
|
|
465
|
-
"Join",
|
|
466
|
-
"TrimPrefix",
|
|
467
|
-
"TrimSuffix",
|
|
468
|
-
"TrimLeft",
|
|
469
|
-
"TrimRight",
|
|
470
|
-
"TrimFunc",
|
|
471
|
-
"IndexByte",
|
|
472
|
-
"LastIndex",
|
|
473
|
-
"LastIndexByte",
|
|
474
|
-
"Fields",
|
|
475
|
-
"FieldsFunc",
|
|
476
|
-
"Clone",
|
|
477
|
-
"Cut",
|
|
478
|
-
"ToTitle",
|
|
479
|
-
"ContainsAny",
|
|
480
|
-
"ContainsRune",
|
|
481
|
-
"Map",
|
|
482
|
-
"SplitN",
|
|
483
|
-
"Buffer",
|
|
484
|
-
"NewReader",
|
|
485
|
-
"Reader",
|
|
486
|
-
]),
|
|
487
|
-
],
|
|
488
|
-
[
|
|
489
|
-
"path",
|
|
490
|
-
new Set([
|
|
491
|
-
"Base",
|
|
492
|
-
"Dir",
|
|
493
|
-
"Ext",
|
|
494
|
-
"Join",
|
|
495
|
-
"Clean",
|
|
496
|
-
"IsAbs",
|
|
497
|
-
"Split",
|
|
498
|
-
"Match",
|
|
499
|
-
"ErrBadPattern",
|
|
500
|
-
]),
|
|
501
|
-
],
|
|
502
|
-
[
|
|
503
|
-
"filepath",
|
|
504
|
-
new Set([
|
|
505
|
-
"Base",
|
|
506
|
-
"Dir",
|
|
507
|
-
"Ext",
|
|
508
|
-
"Join",
|
|
509
|
-
"Clean",
|
|
510
|
-
"IsAbs",
|
|
511
|
-
"Split",
|
|
512
|
-
"Match",
|
|
513
|
-
"ErrBadPattern",
|
|
514
|
-
]),
|
|
515
|
-
],
|
|
516
|
-
["html", new Set(["EscapeString", "UnescapeString"])],
|
|
517
|
-
[
|
|
518
|
-
"io",
|
|
519
|
-
new Set([
|
|
520
|
-
"Writer",
|
|
521
|
-
"Reader",
|
|
522
|
-
"ReadWriter",
|
|
523
|
-
"Closer",
|
|
524
|
-
"EOF",
|
|
525
|
-
"ErrUnexpectedEOF",
|
|
526
|
-
"ErrShortWrite",
|
|
527
|
-
"ReadFull",
|
|
528
|
-
"ReadAll",
|
|
529
|
-
"Discard",
|
|
530
|
-
"WriteString",
|
|
531
|
-
"LimitReader",
|
|
532
|
-
"Copy",
|
|
533
|
-
"CopyN",
|
|
534
|
-
]),
|
|
535
|
-
],
|
|
536
|
-
[
|
|
537
|
-
"time",
|
|
538
|
-
new Set([
|
|
539
|
-
"Now",
|
|
540
|
-
"Since",
|
|
541
|
-
"Parse",
|
|
542
|
-
"Unix",
|
|
543
|
-
"UnixMicro",
|
|
544
|
-
"UnixMilli",
|
|
545
|
-
"Date",
|
|
546
|
-
"Duration",
|
|
547
|
-
"Nanosecond",
|
|
548
|
-
"Microsecond",
|
|
549
|
-
"Millisecond",
|
|
550
|
-
"Second",
|
|
551
|
-
"Minute",
|
|
552
|
-
"Hour",
|
|
553
|
-
"RFC3339",
|
|
554
|
-
"RFC3339Nano",
|
|
555
|
-
"DateOnly",
|
|
556
|
-
"TimeOnly",
|
|
557
|
-
"DateTime",
|
|
558
|
-
"UTC",
|
|
559
|
-
"Local",
|
|
560
|
-
"January",
|
|
561
|
-
"February",
|
|
562
|
-
"March",
|
|
563
|
-
"April",
|
|
564
|
-
"May",
|
|
565
|
-
"June",
|
|
566
|
-
"July",
|
|
567
|
-
"August",
|
|
568
|
-
"September",
|
|
569
|
-
"October",
|
|
570
|
-
"November",
|
|
571
|
-
"December",
|
|
572
|
-
"Sunday",
|
|
573
|
-
"Monday",
|
|
574
|
-
"Tuesday",
|
|
575
|
-
"Wednesday",
|
|
576
|
-
"Thursday",
|
|
577
|
-
"Friday",
|
|
578
|
-
"Saturday",
|
|
579
|
-
"Time",
|
|
580
|
-
]),
|
|
581
|
-
],
|
|
582
|
-
["testing", new Set(["T"])],
|
|
583
|
-
["sync", new Set(["Mutex", "RWMutex", "Once", "WaitGroup", "Locker"])],
|
|
584
|
-
["sha256", new Set(["Sum256", "New", "Size", "BlockSize"])],
|
|
585
|
-
[
|
|
586
|
-
"binary",
|
|
587
|
-
new Set([
|
|
588
|
-
"LittleEndian",
|
|
589
|
-
"BigEndian",
|
|
590
|
-
"ByteOrder",
|
|
591
|
-
"Read",
|
|
592
|
-
"Write",
|
|
593
|
-
"Size",
|
|
594
|
-
"AppendUint16",
|
|
595
|
-
"AppendUint32",
|
|
596
|
-
"AppendUint64",
|
|
597
|
-
]),
|
|
598
|
-
],
|
|
599
|
-
[
|
|
600
|
-
"hex",
|
|
601
|
-
new Set([
|
|
602
|
-
"EncodeToString",
|
|
603
|
-
"DecodeString",
|
|
604
|
-
"Encode",
|
|
605
|
-
"Decode",
|
|
606
|
-
"EncodedLen",
|
|
607
|
-
"DecodedLen",
|
|
608
|
-
"ErrLength",
|
|
609
|
-
]),
|
|
610
|
-
],
|
|
611
|
-
[
|
|
612
|
-
"base64",
|
|
613
|
-
new Set([
|
|
614
|
-
"StdEncoding",
|
|
615
|
-
"URLEncoding",
|
|
616
|
-
"RawStdEncoding",
|
|
617
|
-
"RawURLEncoding",
|
|
618
|
-
"Encoding",
|
|
619
|
-
"NewEncoding",
|
|
620
|
-
"StdPadding",
|
|
621
|
-
"NoPadding",
|
|
622
|
-
]),
|
|
623
|
-
],
|
|
624
|
-
]);
|
|
118
|
+
export const WASM_STDLIB_MEMBERS = new Map();
|
|
625
119
|
|
|
626
120
|
export const VALID_TARGETS = new Set(["js", "wasm", "both"]);
|
|
627
121
|
|
|
122
|
+
// Backend-provided implementations for body-less Go-source stdlib functions
|
|
123
|
+
// marked `//gofront:intrinsic <name>`: name -> required signature. New
|
|
124
|
+
// intrinsics need a plan change.
|
|
125
|
+
export const INTRINSICS = new Map([
|
|
126
|
+
// A uniformly distributed float64 in [0, 1) from the host source
|
|
127
|
+
// (`Math.random`); the only entropy math/rand draws.
|
|
128
|
+
["rand_source", "func() float64"],
|
|
129
|
+
// The host clock in nanoseconds since the Unix epoch, and the offset in
|
|
130
|
+
// seconds east of UTC of the host's time zone at a Unix time (time).
|
|
131
|
+
["time_now", "func() int64"],
|
|
132
|
+
["time_zone_offset", "func(int64) int"],
|
|
133
|
+
// time (js only): suspend for a number of nanoseconds; the declaration is
|
|
134
|
+
// `async`.
|
|
135
|
+
["time_sleep", "func(int64) void"],
|
|
136
|
+
// os: write a string to a file descriptor (0 stdin, 1 stdout, 2 stderr),
|
|
137
|
+
// exit the process, and read and set environment variables.
|
|
138
|
+
["os_write", "func(int, string) void"],
|
|
139
|
+
["os_exit", "func(int) void"],
|
|
140
|
+
["os_getenv", "func(string) string"],
|
|
141
|
+
["os_setenv", "func(string, string) void"],
|
|
142
|
+
// unicode: the host's answer for runes above ASCII, by class (the
|
|
143
|
+
// constants of stdlib/unicode), and its case mappings.
|
|
144
|
+
["unicode_is", "func(int32, int) bool"],
|
|
145
|
+
["unicode_to_upper", "func(int32) int32"],
|
|
146
|
+
["unicode_to_lower", "func(int32) int32"],
|
|
147
|
+
// crypto/rand: four random bytes from the host's secure source.
|
|
148
|
+
["crypto_rand_u32", "func() uint32"],
|
|
149
|
+
// testing: a monotonic clock in nanoseconds, and an unanchored regular
|
|
150
|
+
// expression match for -run and -bench patterns.
|
|
151
|
+
["testing_nanotime", "func() int64"],
|
|
152
|
+
["testing_match", "func(string, string) bool"],
|
|
153
|
+
// testing (js only): call a test body and return what it returned (a
|
|
154
|
+
// promise for an async body, otherwise nil).
|
|
155
|
+
["testing_call", "func(any, any) any"],
|
|
156
|
+
// fmt: a stable number for a pointer, function or other reference.
|
|
157
|
+
["fmt_ptr_id", "func(any) uint64"],
|
|
158
|
+
// math: IEEE-754 bit casts, and the host's `Math.*` (`%` for Mod).
|
|
159
|
+
["math_float64bits", "func(float64) uint64"],
|
|
160
|
+
["math_float64frombits", "func(uint64) float64"],
|
|
161
|
+
["math_float32bits", "func(float32) uint32"],
|
|
162
|
+
["math_float32frombits", "func(uint32) float32"],
|
|
163
|
+
...[
|
|
164
|
+
"sin",
|
|
165
|
+
"cos",
|
|
166
|
+
"tan",
|
|
167
|
+
"asin",
|
|
168
|
+
"acos",
|
|
169
|
+
"atan",
|
|
170
|
+
"sinh",
|
|
171
|
+
"cosh",
|
|
172
|
+
"tanh",
|
|
173
|
+
"exp",
|
|
174
|
+
"expm1",
|
|
175
|
+
"log",
|
|
176
|
+
"log1p",
|
|
177
|
+
"log2",
|
|
178
|
+
"log10",
|
|
179
|
+
"cbrt",
|
|
180
|
+
].map((f) => [`math_${f}`, "func(float64) float64"]),
|
|
181
|
+
...["atan2", "pow", "hypot", "mod"].map((f) => [
|
|
182
|
+
`math_${f}`,
|
|
183
|
+
"func(float64, float64) float64",
|
|
184
|
+
]),
|
|
185
|
+
]);
|
|
186
|
+
|
|
187
|
+
// The fmt functions whose calls the compiler wraps with a generated function
|
|
188
|
+
// (src/lower/fmt-formatters.js); a wrapped call may forward `f()`'s results.
|
|
189
|
+
export const FMT_PRINT_FUNCS = new Set([
|
|
190
|
+
"Sprint",
|
|
191
|
+
"Sprintln",
|
|
192
|
+
"Print",
|
|
193
|
+
"Println",
|
|
194
|
+
"Fprint",
|
|
195
|
+
"Fprintln",
|
|
196
|
+
"Append",
|
|
197
|
+
"Appendln",
|
|
198
|
+
"Sprintf",
|
|
199
|
+
"Printf",
|
|
200
|
+
"Errorf",
|
|
201
|
+
"Fprintf",
|
|
202
|
+
"Appendf",
|
|
203
|
+
]);
|
|
204
|
+
|
|
205
|
+
// Names a standard-library function may carry in `//gofront:native <name>`:
|
|
206
|
+
// the function keeps its Go body, and a backend registry may replace calls to
|
|
207
|
+
// it with host code (or decline). A closed set; new names need a plan change.
|
|
208
|
+
export const NATIVES = new Set([
|
|
209
|
+
"slices.Contains",
|
|
210
|
+
"slices.Index",
|
|
211
|
+
"slices.Reverse",
|
|
212
|
+
"slices.Clone",
|
|
213
|
+
"bytes.Compare",
|
|
214
|
+
"bytes.Equal",
|
|
215
|
+
"bytes.IndexByte",
|
|
216
|
+
"slices.Sort",
|
|
217
|
+
"sort.Ints",
|
|
218
|
+
"sort.Strings",
|
|
219
|
+
"utf8.RuneCountInString",
|
|
220
|
+
"strings.Index",
|
|
221
|
+
"strings.LastIndex",
|
|
222
|
+
"strings.IndexByte",
|
|
223
|
+
"strings.LastIndexByte",
|
|
224
|
+
"strings.IndexRune",
|
|
225
|
+
"strings.IndexAny",
|
|
226
|
+
"strings.LastIndexAny",
|
|
227
|
+
"strings.Contains",
|
|
228
|
+
"strings.ContainsAny",
|
|
229
|
+
"strings.ContainsRune",
|
|
230
|
+
"strings.HasPrefix",
|
|
231
|
+
"strings.HasSuffix",
|
|
232
|
+
"strings.Count",
|
|
233
|
+
"strings.Repeat",
|
|
234
|
+
"strings.Join",
|
|
235
|
+
"strings.Replace",
|
|
236
|
+
"strings.ReplaceAll",
|
|
237
|
+
"strings.Split",
|
|
238
|
+
"strings.Fields",
|
|
239
|
+
"strings.ToUpper",
|
|
240
|
+
"strings.ToLower",
|
|
241
|
+
"strings.TrimSpace",
|
|
242
|
+
"strings.Trim",
|
|
243
|
+
"strings.TrimLeft",
|
|
244
|
+
"strings.TrimRight",
|
|
245
|
+
"strings.TrimPrefix",
|
|
246
|
+
"strings.TrimSuffix",
|
|
247
|
+
"strconv.shortest",
|
|
248
|
+
"strconv.fixed",
|
|
249
|
+
"strconv.parseDecimal",
|
|
250
|
+
// internal/jsonrt: the encoder's writes into its output buffer.
|
|
251
|
+
"jsonrt.putString",
|
|
252
|
+
"jsonrt.putInt",
|
|
253
|
+
"jsonrt.putUint",
|
|
254
|
+
"jsonrt.putFloat",
|
|
255
|
+
"jsonrt.putQuoted",
|
|
256
|
+
"jsonrt.readStr",
|
|
257
|
+
"jsonrt.readNum",
|
|
258
|
+
"jsonrt.CheckValid",
|
|
259
|
+
"jsonrt.LooksFloat32",
|
|
260
|
+
// math: the functions with a single host expression or instruction.
|
|
261
|
+
"math.IsNaN",
|
|
262
|
+
"math.IsInf",
|
|
263
|
+
"math.Inf",
|
|
264
|
+
"math.NaN",
|
|
265
|
+
"math.Signbit",
|
|
266
|
+
"math.Copysign",
|
|
267
|
+
"math.Abs",
|
|
268
|
+
"math.Max",
|
|
269
|
+
"math.Min",
|
|
270
|
+
"math.Trunc",
|
|
271
|
+
"math.Floor",
|
|
272
|
+
"math.Ceil",
|
|
273
|
+
"math.Round",
|
|
274
|
+
"math.Sqrt",
|
|
275
|
+
// math/bits: one host instruction per width (`Math.clz32`, WASM `clz`,
|
|
276
|
+
// `ctz` and `popcnt`).
|
|
277
|
+
...["Len", "LeadingZeros", "TrailingZeros", "OnesCount"].flatMap((f) =>
|
|
278
|
+
["", "8", "16", "32", "64"].map((w) => `bits.${f}${w}`),
|
|
279
|
+
),
|
|
280
|
+
]);
|
|
281
|
+
|
|
628
282
|
// ── Static operator sets (module-level for reuse) ────────────
|
|
629
283
|
export const CMP_OPS = new Set(["==", "!=", "<", ">", "<=", ">="]);
|
|
630
284
|
export const LOG_OPS = new Set(["&&", "||"]);
|
|
@@ -649,6 +303,9 @@ export const FLOAT64 = { kind: "basic", name: "float64" };
|
|
|
649
303
|
export const STRING = { kind: "basic", name: "string" };
|
|
650
304
|
export const BOOL = { kind: "basic", name: "bool" };
|
|
651
305
|
export const ANY = { kind: "basic", name: "any" };
|
|
306
|
+
// `any` written in source. Untyped JS interop also yields plain ANY, which stays
|
|
307
|
+
// freely assignable; only a declared `any` needs a type assertion.
|
|
308
|
+
export const DECLARED_ANY = { kind: "basic", name: "any", _declared: true };
|
|
652
309
|
export const TAINTED_ANY = { kind: "basic", name: "any", _tainted: true };
|
|
653
310
|
export const VOID = { kind: "basic", name: "void" };
|
|
654
311
|
export const NIL = { kind: "basic", name: "nil" };
|
|
@@ -669,7 +326,7 @@ export const UNTYPED_BOOL = { kind: "untyped", base: "bool" };
|
|
|
669
326
|
|
|
670
327
|
// ── Complex types ────────────────────────────────────────────
|
|
671
328
|
export const COMPLEX128 = { kind: "basic", name: "complex128" };
|
|
672
|
-
const COMPLEX64 = { kind: "basic", name: "complex64" };
|
|
329
|
+
export const COMPLEX64 = { kind: "basic", name: "complex64" };
|
|
673
330
|
export const UNTYPED_COMPLEX = { kind: "untyped", base: "complex128" };
|
|
674
331
|
|
|
675
332
|
export const BASIC_TYPES = {
|
|
@@ -736,6 +393,33 @@ export const isFloat = makeBasicPredicate(...SIZED_FLOAT_NAMES);
|
|
|
736
393
|
export const isString = makeBasicPredicate("string");
|
|
737
394
|
export const isBool = makeBasicPredicate("bool");
|
|
738
395
|
|
|
396
|
+
// True when type t represents an int64 or uint64 (including named types like time.Duration).
|
|
397
|
+
export function is64BitInt(t) {
|
|
398
|
+
if (!t) return false;
|
|
399
|
+
if (t.kind === "untyped") return t.base === "int64" || t.base === "uint64";
|
|
400
|
+
let cur = t;
|
|
401
|
+
while (cur?.kind === "named") cur = cur.underlying;
|
|
402
|
+
return (
|
|
403
|
+
cur?.kind === "basic" && (cur.name === "int64" || cur.name === "uint64")
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export function is64BitSigned(t) {
|
|
408
|
+
if (!t) return false;
|
|
409
|
+
if (t.kind === "untyped") return t.base === "int64";
|
|
410
|
+
let cur = t;
|
|
411
|
+
while (cur?.kind === "named") cur = cur.underlying;
|
|
412
|
+
return cur?.kind === "basic" && cur.name === "int64";
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export function is64BitUnsigned(t) {
|
|
416
|
+
if (!t) return false;
|
|
417
|
+
if (t.kind === "untyped") return t.base === "uint64";
|
|
418
|
+
let cur = t;
|
|
419
|
+
while (cur?.kind === "named") cur = cur.underlying;
|
|
420
|
+
return cur?.kind === "basic" && cur.name === "uint64";
|
|
421
|
+
}
|
|
422
|
+
|
|
739
423
|
// ── TypedArray mappings ──────────────────────────────────────
|
|
740
424
|
// []float64 deliberately stays a plain Array for JSON / JS-library interop.
|
|
741
425
|
const TYPED_ARRAY_CONSTRUCTORS = {
|
|
@@ -750,6 +434,32 @@ const TYPED_ARRAY_CONSTRUCTORS = {
|
|
|
750
434
|
rune: "Int32Array",
|
|
751
435
|
};
|
|
752
436
|
|
|
437
|
+
// Element indices of an array or slice literal (Go spec): `i: v` puts v at
|
|
438
|
+
// index i, any other element goes right after the previous one, so
|
|
439
|
+
// `[5]int{1, 3: 4, 5}` fills indices 0, 3 and 4. Array literal keys are
|
|
440
|
+
// resolved by the type checker (`_index`, which handles named constants and
|
|
441
|
+
// constant expressions); otherwise only integer-literal keys are known and
|
|
442
|
+
// another key is treated as a positional element.
|
|
443
|
+
export function compositeLitIndices(elems) {
|
|
444
|
+
const out = [];
|
|
445
|
+
let next = 0;
|
|
446
|
+
for (const e of elems) {
|
|
447
|
+
if (e.kind === "KeyValueExpr" && e._index !== undefined) next = e._index;
|
|
448
|
+
else if (e.kind === "KeyValueExpr" && e.key?.value !== undefined)
|
|
449
|
+
next = Number(e.key.value);
|
|
450
|
+
out.push(next++);
|
|
451
|
+
}
|
|
452
|
+
return out;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Highest element index of an array or slice literal (-1 when empty). A
|
|
456
|
+
// loop, not `Math.max(...)`: spreading a huge literal overflows the stack.
|
|
457
|
+
export function compositeLitMaxIndex(elems) {
|
|
458
|
+
let max = -1;
|
|
459
|
+
for (const i of compositeLitIndices(elems)) if (i > max) max = i;
|
|
460
|
+
return max;
|
|
461
|
+
}
|
|
462
|
+
|
|
753
463
|
export function typedArrayConstructorForElem(elemType) {
|
|
754
464
|
if (!elemType) return null;
|
|
755
465
|
const name = elemType.kind === "basic" ? elemType.name : null;
|
|
@@ -765,12 +475,28 @@ export function isTypedArraySlice(type) {
|
|
|
765
475
|
|
|
766
476
|
export function isComplex(t) {
|
|
767
477
|
if (!t) return false;
|
|
768
|
-
if (
|
|
478
|
+
if (
|
|
479
|
+
(t.kind === "basic" || t.kind === "TypeName" || t.kind === "Ident") &&
|
|
480
|
+
(t.name === "complex128" || t.name === "complex64")
|
|
481
|
+
)
|
|
769
482
|
return true;
|
|
770
483
|
if (t.kind === "untyped" && t.base === "complex128") return true;
|
|
771
484
|
if (t.kind === "named") return isComplex(t.underlying);
|
|
772
485
|
return false;
|
|
773
486
|
}
|
|
487
|
+
export function isComplex64(t) {
|
|
488
|
+
if (!t) return false;
|
|
489
|
+
if (
|
|
490
|
+
(t.kind === "basic" || t.kind === "TypeName" || t.kind === "Ident") &&
|
|
491
|
+
t.name === "complex64"
|
|
492
|
+
)
|
|
493
|
+
return true;
|
|
494
|
+
if (t.kind === "untyped" && t.base === "complex64") return true;
|
|
495
|
+
if (t.kind === "named") return isComplex64(t.underlying);
|
|
496
|
+
if (t.name === "complex64") return true;
|
|
497
|
+
if (t.underlying) return isComplex64(t.underlying);
|
|
498
|
+
return false;
|
|
499
|
+
}
|
|
774
500
|
export function isComplexOrNumeric(t) {
|
|
775
501
|
return isNumeric(t) || isComplex(t);
|
|
776
502
|
}
|
|
@@ -851,10 +577,12 @@ export function typeStr(t) {
|
|
|
851
577
|
}
|
|
852
578
|
case "tuple":
|
|
853
579
|
return `(${t.types.map(typeStr).join(", ")})`;
|
|
854
|
-
case "named":
|
|
580
|
+
case "named": {
|
|
581
|
+
const name = displayTypeName(t.name);
|
|
855
582
|
return t.typeArgs && t.typeArgs.length > 0
|
|
856
|
-
? `${
|
|
857
|
-
:
|
|
583
|
+
? `${name}[${t.typeArgs.map(typeStr).join(", ")}]`
|
|
584
|
+
: name;
|
|
585
|
+
}
|
|
858
586
|
case "pointer":
|
|
859
587
|
return `*${typeStr(t.base)}`;
|
|
860
588
|
case "typeParam":
|
|
@@ -866,6 +594,32 @@ export function typeStr(t) {
|
|
|
866
594
|
}
|
|
867
595
|
}
|
|
868
596
|
|
|
597
|
+
// The field an embedded type declares is named after the type as written, so
|
|
598
|
+
// an alias (`type A = Base; struct{ A }`) gives the field `A`.
|
|
599
|
+
export function embeddedFieldName(f) {
|
|
600
|
+
const ast = f.astType?.kind === "PointerType" ? f.astType.base : f.astType;
|
|
601
|
+
const t = f.type?.kind === "pointer" ? f.type.base : f.type;
|
|
602
|
+
return (ast?.name ?? t?.name ?? "")
|
|
603
|
+
.split(".")
|
|
604
|
+
.pop()
|
|
605
|
+
.replace(/\$\$.*$/, "");
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// A function-local type shadowed by another type is renamed `Name__L<n>`.
|
|
609
|
+
export const LOCAL_TYPE_SUFFIX = /__L\d+/;
|
|
610
|
+
|
|
611
|
+
// Go-source stdlib names are mangled to `Name$$path` (`List$$container$list`);
|
|
612
|
+
// diagnostics show them qualified, as Go does (`list.List`).
|
|
613
|
+
export function displayTypeName(name) {
|
|
614
|
+
if (typeof name === "string") name = name.replace(LOCAL_TYPE_SUFFIX, "");
|
|
615
|
+
const i = typeof name === "string" ? name.indexOf("$$") : -1;
|
|
616
|
+
if (i < 0) return name;
|
|
617
|
+
return `${name
|
|
618
|
+
.slice(i + 2)
|
|
619
|
+
.split("$")
|
|
620
|
+
.at(-1)}.${name.slice(0, i)}`;
|
|
621
|
+
}
|
|
622
|
+
|
|
869
623
|
// ── Iterator function detection (Go 1.23 range-over-func) ───
|
|
870
624
|
|
|
871
625
|
/**
|