gofront 1.7.0 → 1.8.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 +13 -13
- package/package.json +8 -37
- package/src/backend/js/expressions.js +1341 -148
- package/src/backend/js/fmt-runtime.js +573 -0
- package/src/backend/js/index.js +375 -57
- package/src/backend/js/runtime.js +1460 -133
- package/src/backend/js/statements.js +900 -86
- package/src/backend/js/stdlib/bits.js +87 -14
- package/src/backend/js/stdlib/builder.js +41 -6
- package/src/backend/js/stdlib/bytes.js +253 -7
- package/src/backend/js/stdlib/errors.js +2 -1
- package/src/backend/js/stdlib/fmt.js +349 -10
- package/src/backend/js/stdlib/index.js +8 -3
- package/src/backend/js/stdlib/json.js +247 -52
- package/src/backend/js/stdlib/maps.js +0 -8
- package/src/backend/js/stdlib/math.js +17 -1
- package/src/backend/js/stdlib/simd.js +10 -0
- package/src/backend/js/stdlib/slices.js +36 -6
- package/src/backend/js/stdlib/strconv.js +10 -5
- package/src/backend/js/stdlib/strings.js +83 -4
- package/src/backend/js/stdlib/testing.js +7 -0
- package/src/backend/js/stdlib/time.js +79 -55
- package/src/backend/js/stdlib/unicode.js +1 -1
- package/src/backend/js/stdlib/utf8.js +1 -1
- package/src/backend/js/templ.js +38 -76
- package/src/backend/js/type-info.js +272 -0
- package/src/backend/shared/fmt-types.js +188 -0
- package/src/backend/wasm/boundary.js +436 -80
- package/src/backend/wasm/emit-builtins.js +303 -13
- package/src/backend/wasm/emit-exprs.js +1397 -203
- package/src/backend/wasm/emit-maps.js +61 -13
- package/src/backend/wasm/emit-stmts.js +1359 -164
- package/src/backend/wasm/emit.js +512 -77
- package/src/backend/wasm/encode.js +43 -13
- package/src/backend/wasm/globals.js +452 -0
- package/src/backend/wasm/index.js +194 -2489
- package/src/backend/wasm/method-expr.js +381 -0
- package/src/backend/wasm/module-emitter.js +2240 -0
- package/src/backend/wasm/monomorph.js +62 -4
- package/src/backend/wasm/prescan.js +397 -0
- package/src/backend/wasm/stdlib/bytes.js +1804 -127
- package/src/backend/wasm/stdlib/core.js +1574 -199
- package/src/backend/wasm/stdlib/index.js +0 -5
- package/src/backend/wasm/stdlib/io.js +1567 -150
- package/src/backend/wasm/stdlib/packages.js +2 -0
- package/src/backend/wasm/stdlib/simd.js +293 -28
- package/src/backend/wasm/stdlib/time.js +1041 -12
- package/src/backend/wasm/types.js +200 -15
- 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} +236 -10
- package/src/{test-runner.js → cli/test-runner.js} +332 -39
- package/src/{vendor.js → cli/vendor.js} +3 -4
- package/src/compiler.js +107 -269
- package/src/index.js +15 -169
- package/src/{lexer.js → lexer/lexer.js} +102 -55
- package/src/{tokens.js → lexer/tokens.js} +1 -0
- package/src/link/sourcemap.js +97 -0
- package/src/link/stdlib.js +515 -0
- package/src/link/wasm.js +294 -0
- package/src/lower/bounds.js +394 -0
- package/src/lower/boxing.js +1 -1
- package/src/lower/captures.js +176 -32
- package/src/lower/index.js +26 -18
- package/src/lower/json-codecs.js +1398 -0
- package/src/lower/ownership.js +22 -1
- package/src/lower/range.js +86 -1
- package/src/lower/reachability.js +132 -0
- package/src/parser/declarations.js +58 -13
- package/src/parser/expressions.js +29 -7
- package/src/parser/index.js +2 -1
- package/src/parser/statements.js +37 -22
- package/src/{templ-parser.js → parser/templ.js} +138 -15
- package/src/parser/types.js +69 -9
- package/src/resolver.js +22 -1
- package/src/typechecker/assignability.js +176 -17
- package/src/typechecker/const-fold.js +356 -0
- package/src/typechecker/constants.js +256 -0
- package/src/typechecker/expressions.js +931 -122
- package/src/typechecker/index.js +459 -67
- package/src/typechecker/init-order.js +330 -0
- package/src/typechecker/resolve.js +451 -56
- package/src/typechecker/statements.js +90 -9
- package/src/typechecker/stdlib/core.js +333 -55
- package/src/typechecker/stdlib/excluded.js +898 -0
- package/src/typechecker/stdlib/extended.js +322 -26
- package/src/typechecker/{stdlib.js → stdlib/index.js} +5 -5
- package/src/typechecker/stdlib/simd.js +65 -15
- package/src/typechecker/termination.js +1 -1
- package/src/typechecker/types.js +149 -25
- package/stdlib/bytes/iter.go +192 -0
- package/stdlib/bytes/search.go +240 -0
- package/stdlib/bytes/split.go +218 -0
- package/stdlib/cmp/cmp.go +65 -0
- package/stdlib/encoding/json/errors.go +31 -0
- package/stdlib/encoding/json/indent.go +71 -0
- package/stdlib/encoding/json/number.go +12 -0
- package/stdlib/encoding/json/stream.go +173 -0
- package/stdlib/errors/overlay.go +12 -0
- package/stdlib/hash/hash.go +53 -0
- package/stdlib/internal/jsonrt/dec.go +738 -0
- package/stdlib/internal/jsonrt/enc.go +366 -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 +649 -0
- package/stdlib/io/io.go +346 -0
- package/stdlib/iter/iter.go +18 -0
- package/stdlib/maps/iter.go +65 -0
- package/stdlib/math/extra.go +270 -0
- package/stdlib/slices/extra.go +73 -0
- package/stdlib/slices/iter.go +113 -0
- package/stdlib/sort/sort.go +561 -0
- package/stdlib/strconv/quote.go +341 -0
- package/stdlib/strings/extra.go +35 -0
- package/stdlib/strings/iter.go +122 -0
- package/stdlib/sync/extra.go +105 -0
- package/stdlib/unicode/unicode.go +112 -0
- package/stdlib/unicode/utf8/bytes.go +239 -0
- package/src/backend/wasm/const-fold.js +0 -205
- package/src/backend/wasm/emit-stdlib.js +0 -13
- /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/{templ-lexer.js → lexer/templ-lexer.js} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//go:build gofront
|
|
2
|
+
|
|
3
|
+
//gofront:target both
|
|
4
|
+
|
|
5
|
+
// Overlay on the emitter-backed slices package: comparison and repetition
|
|
6
|
+
// members written in Go and merged into the slices namespace. The
|
|
7
|
+
// checker has no core types for type parameters, so these take []E rather
|
|
8
|
+
// than Go's S ~[]E and Repeat returns []E.
|
|
9
|
+
package slices
|
|
10
|
+
|
|
11
|
+
// EqualFunc reports whether two slices are equal using an equality
|
|
12
|
+
// function on each pair of elements. If the lengths are different,
|
|
13
|
+
// EqualFunc returns false. Otherwise, the elements are compared in
|
|
14
|
+
// increasing index order, and the comparison stops at the first index
|
|
15
|
+
// for which eq returns false.
|
|
16
|
+
func EqualFunc[E1, E2 any](s1 []E1, s2 []E2, eq func(E1, E2) bool) bool {
|
|
17
|
+
if len(s1) != len(s2) {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
for i, v1 := range s1 {
|
|
21
|
+
v2 := s2[i]
|
|
22
|
+
if !eq(v1, v2) {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// CompareFunc is like Compare but uses a custom comparison function on each
|
|
30
|
+
// pair of elements.
|
|
31
|
+
// The result is the first non-zero result of cmp; if cmp always
|
|
32
|
+
// returns 0 the result is 0 if len(s1) == len(s2), -1 if len(s1) < len(s2),
|
|
33
|
+
// and +1 if len(s1) > len(s2).
|
|
34
|
+
func CompareFunc[E1, E2 any](s1 []E1, s2 []E2, cmp func(E1, E2) int) int {
|
|
35
|
+
for i, v1 := range s1 {
|
|
36
|
+
if i >= len(s2) {
|
|
37
|
+
return +1
|
|
38
|
+
}
|
|
39
|
+
v2 := s2[i]
|
|
40
|
+
if c := cmp(v1, v2); c != 0 {
|
|
41
|
+
return c
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if len(s1) < len(s2) {
|
|
45
|
+
return -1
|
|
46
|
+
}
|
|
47
|
+
return 0
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// repeatMaxInt is the largest int, as the overflow bound of Repeat.
|
|
51
|
+
const repeatMaxInt = 1<<63 - 1
|
|
52
|
+
|
|
53
|
+
// Repeat returns a new slice that repeats the provided slice the given number of times.
|
|
54
|
+
// The result has length and capacity (len(x) * count).
|
|
55
|
+
// The result is never nil.
|
|
56
|
+
// Repeat panics if count is negative or if the result of (len(x) * count)
|
|
57
|
+
// overflows.
|
|
58
|
+
func Repeat[E any](x []E, count int) []E {
|
|
59
|
+
if count < 0 {
|
|
60
|
+
panic("cannot be negative")
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if len(x) > 0 && count > repeatMaxInt/len(x) {
|
|
64
|
+
panic("the result of (len(x) * count) overflows")
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
newslice := make([]E, len(x)*count)
|
|
68
|
+
n := copy(newslice, x)
|
|
69
|
+
for n < len(newslice) {
|
|
70
|
+
n += copy(newslice[n:], newslice[:n])
|
|
71
|
+
}
|
|
72
|
+
return newslice
|
|
73
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//go:build gofront
|
|
2
|
+
|
|
3
|
+
//gofront:target both
|
|
4
|
+
|
|
5
|
+
// Overlay on the emitter-backed slices package: the iterator members are
|
|
6
|
+
// written in Go over iter.Seq and iter.Seq2 and merged into the slices
|
|
7
|
+
// namespace. Unqualified references to emitter members (Sort, SortFunc,
|
|
8
|
+
// SortStableFunc) resolve to the emitter implementation.
|
|
9
|
+
package slices
|
|
10
|
+
|
|
11
|
+
import (
|
|
12
|
+
"cmp"
|
|
13
|
+
"iter"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// All returns an iterator over index-value pairs in the slice
|
|
17
|
+
// in the usual order.
|
|
18
|
+
func All[E any](s []E) iter.Seq2[int, E] {
|
|
19
|
+
return func(yield func(int, E) bool) {
|
|
20
|
+
for i, v := range s {
|
|
21
|
+
if !yield(i, v) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Backward returns an iterator over index-value pairs in the slice,
|
|
29
|
+
// traversing it backward with descending indices.
|
|
30
|
+
func Backward[E any](s []E) iter.Seq2[int, E] {
|
|
31
|
+
return func(yield func(int, E) bool) {
|
|
32
|
+
for i := len(s) - 1; i >= 0; i-- {
|
|
33
|
+
if !yield(i, s[i]) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Values returns an iterator that yields the slice elements in order.
|
|
41
|
+
func Values[E any](s []E) iter.Seq[E] {
|
|
42
|
+
return func(yield func(E) bool) {
|
|
43
|
+
for _, v := range s {
|
|
44
|
+
if !yield(v) {
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// AppendSeq appends the values from seq to the slice and
|
|
52
|
+
// returns the extended slice.
|
|
53
|
+
func AppendSeq[E any](s []E, seq iter.Seq[E]) []E {
|
|
54
|
+
for v := range seq {
|
|
55
|
+
s = append(s, v)
|
|
56
|
+
}
|
|
57
|
+
return s
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Collect collects values from seq into a new slice and returns it.
|
|
61
|
+
func Collect[E any](seq iter.Seq[E]) []E {
|
|
62
|
+
var s []E
|
|
63
|
+
return AppendSeq(s, seq)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Sorted collects values from seq into a new slice, sorts the slice,
|
|
67
|
+
// and returns it.
|
|
68
|
+
func Sorted[E cmp.Ordered](seq iter.Seq[E]) []E {
|
|
69
|
+
s := Collect(seq)
|
|
70
|
+
Sort(s)
|
|
71
|
+
return s
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// SortedFunc collects values from seq into a new slice, sorts the slice
|
|
75
|
+
// using the comparison function, and returns it.
|
|
76
|
+
func SortedFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E {
|
|
77
|
+
s := Collect(seq)
|
|
78
|
+
SortFunc(s, cmp)
|
|
79
|
+
return s
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// SortedStableFunc collects values from seq into a new slice.
|
|
83
|
+
// It then sorts the slice while keeping the original order of equal elements,
|
|
84
|
+
// using the comparison function to compare elements.
|
|
85
|
+
// It returns the new slice.
|
|
86
|
+
func SortedStableFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E {
|
|
87
|
+
s := Collect(seq)
|
|
88
|
+
SortStableFunc(s, cmp)
|
|
89
|
+
return s
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Chunk returns an iterator over consecutive sub-slices of up to n elements
|
|
93
|
+
// of s. All but the last sub-slice will have size n. All sub-slices are
|
|
94
|
+
// clipped to have no capacity beyond the length. If s is empty, the sequence
|
|
95
|
+
// is empty: there is no empty slice in the sequence. Chunk panics if n is
|
|
96
|
+
// less than 1.
|
|
97
|
+
func Chunk[E any](s []E, n int) iter.Seq[[]E] {
|
|
98
|
+
if n < 1 {
|
|
99
|
+
panic("cannot be less than 1")
|
|
100
|
+
}
|
|
101
|
+
return func(yield func([]E) bool) {
|
|
102
|
+
for i := 0; i < len(s); i += n {
|
|
103
|
+
// Clamp the last chunk to the slice bound as necessary.
|
|
104
|
+
end := min(n, len(s[i:]))
|
|
105
|
+
|
|
106
|
+
// Set the capacity of each chunk so that appending to a chunk does
|
|
107
|
+
// not modify the original slice.
|
|
108
|
+
if !yield(s[i : i+end : i+end]) {
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|