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
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
//go:build gofront
|
|
2
|
+
|
|
3
|
+
//gofront:target both
|
|
4
|
+
|
|
5
|
+
// Package fmtrt is the contract between package fmt and the code the
|
|
6
|
+
// compiler generates for each package that formats values.
|
|
7
|
+
//
|
|
8
|
+
// Go's fmt learns the type of every operand by reflection. Here the compiler
|
|
9
|
+
// knows it statically: it describes an operand as an Arg (a kind, the value
|
|
10
|
+
// in a field of that kind, and closures that reach the parts of a composite)
|
|
11
|
+
// and fmt only reads the description. An operand that arrives through an
|
|
12
|
+
// interface is described by the lookups packages register with Register.
|
|
13
|
+
package fmtrt
|
|
14
|
+
|
|
15
|
+
// The kinds of an Arg.
|
|
16
|
+
const (
|
|
17
|
+
KNone = iota // not described: format the value in V
|
|
18
|
+
KBool // B
|
|
19
|
+
KInt // I, any signed integer type
|
|
20
|
+
KUint // U, any unsigned integer type
|
|
21
|
+
KFloat // R, any float type
|
|
22
|
+
KComplex // R and Im, any complex type
|
|
23
|
+
KString // S
|
|
24
|
+
KStruct // N fields, Field
|
|
25
|
+
KPtr // Nil, Ptr, Inner
|
|
26
|
+
KSlice // Nil, N elements, Elem
|
|
27
|
+
KArray // N elements, Elem
|
|
28
|
+
KMap // Nil, N entries, Entries
|
|
29
|
+
KFunc // Nil, Ptr
|
|
30
|
+
KInterface // V holds the operand, formatted by its dynamic type
|
|
31
|
+
KChan // Nil, Ptr
|
|
32
|
+
KUnsafePtr // Nil, Ptr
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
// Stringer, GoStringer and Error-only views of a value, kept apart from
|
|
36
|
+
// package fmt so that the generated code needs only this package.
|
|
37
|
+
type Stringer interface {
|
|
38
|
+
String() string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type GoStringer interface {
|
|
42
|
+
GoString() string
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Arg describes one operand.
|
|
46
|
+
type Arg struct {
|
|
47
|
+
K int // the kind, one of the K constants
|
|
48
|
+
Size int // the bit size of a number (8, 16, 32, 64 or 0 for int, uint and uintptr)
|
|
49
|
+
T string // the Go type, as %T prints it
|
|
50
|
+
B bool
|
|
51
|
+
I int64
|
|
52
|
+
U uint64
|
|
53
|
+
R float64
|
|
54
|
+
Im float64
|
|
55
|
+
S string
|
|
56
|
+
V any // the operand itself, when K is KNone or KInterface
|
|
57
|
+
|
|
58
|
+
// The methods of the static type that fmt calls. They are set only
|
|
59
|
+
// where Go would call them: the type's method set holds the method and,
|
|
60
|
+
// for a struct field, the field is exported.
|
|
61
|
+
Err error
|
|
62
|
+
Str Stringer
|
|
63
|
+
GoStr GoStringer
|
|
64
|
+
|
|
65
|
+
Nil bool
|
|
66
|
+
N int
|
|
67
|
+
Ptr any
|
|
68
|
+
Boxed bool // Ptr is a pointer to a scalar, boxed anew each time it is put in an Arg
|
|
69
|
+
IsBytes bool // a []byte or [N]byte, whose elements are in Bytes
|
|
70
|
+
Bytes []byte
|
|
71
|
+
Field func(i int) (string, Arg) // the name and value of field i
|
|
72
|
+
Elem func(i int) Arg // element i
|
|
73
|
+
Entries func() []Entry // the entries of a map
|
|
74
|
+
Inner func() Arg // what a non-nil pointer points to
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Entry is one key and value of a map.
|
|
78
|
+
type Entry struct {
|
|
79
|
+
Key Arg
|
|
80
|
+
Val Arg
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type registry struct {
|
|
84
|
+
keys []string
|
|
85
|
+
lookups []func(v any) (Arg, bool)
|
|
86
|
+
scalars []numbered
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// numbered is a pointer to a scalar that has been given an id; same reports
|
|
90
|
+
// whether a value is that pointer.
|
|
91
|
+
type numbered struct {
|
|
92
|
+
same func(v any) bool
|
|
93
|
+
id uint64
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var reg = ®istry{}
|
|
97
|
+
|
|
98
|
+
func (r *registry) add(key string, f func(v any) (Arg, bool)) {
|
|
99
|
+
for _, k := range r.keys {
|
|
100
|
+
if k == key {
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
r.keys = append(r.keys, key)
|
|
105
|
+
r.lookups = append(r.lookups, f)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Register adds a package's lookup, which describes the values of that
|
|
109
|
+
// package's types held in an interface. A key registers once, so a call may
|
|
110
|
+
// be repeated: it identifies the lookup, and it returns true so that it can
|
|
111
|
+
// initialise a package-level variable.
|
|
112
|
+
func Register(key string, f func(v any) (Arg, bool)) bool {
|
|
113
|
+
reg.add(key, f)
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Lookup describes a value held in an interface by asking each registered
|
|
118
|
+
// lookup in turn.
|
|
119
|
+
func Lookup(v any) (Arg, bool) {
|
|
120
|
+
for _, f := range reg.lookups {
|
|
121
|
+
if a, ok := f(v); ok {
|
|
122
|
+
return a, true
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return Arg{}, false
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// PtrID returns a number that identifies the pointer, function or other
|
|
129
|
+
// reference v; 0 for nil.
|
|
130
|
+
func PtrID(v any) uint64 {
|
|
131
|
+
if v == nil {
|
|
132
|
+
return 0
|
|
133
|
+
}
|
|
134
|
+
return ptrID(v)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ArgPtrID returns the identity number of the pointer, function or channel
|
|
138
|
+
// that a holds. A pointer to a scalar is boxed anew each time it is put in an
|
|
139
|
+
// Arg and the host would see a different object, so those are matched by
|
|
140
|
+
// equality against the ones already numbered.
|
|
141
|
+
func ArgPtrID(a Arg) uint64 {
|
|
142
|
+
if !a.Boxed {
|
|
143
|
+
return PtrID(a.Ptr)
|
|
144
|
+
}
|
|
145
|
+
p := a.Ptr
|
|
146
|
+
for _, n := range reg.scalars {
|
|
147
|
+
if n.same(p) {
|
|
148
|
+
return n.id
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
id := PtrID(p)
|
|
152
|
+
reg.remember(p, id)
|
|
153
|
+
return id
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
func (r *registry) remember(p any, id uint64) {
|
|
157
|
+
r.scalars = append(r.scalars, numbered{func(v any) bool { return v == p }, id})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// ptrID is the host's stable identity number for an object.
|
|
161
|
+
//
|
|
162
|
+
//gofront:intrinsic fmt_ptr_id
|
|
163
|
+
func ptrID(v any) uint64
|