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.
Files changed (194) hide show
  1. package/README.md +14 -14
  2. package/package.json +10 -38
  3. package/src/backend/js/expressions.js +2060 -389
  4. package/src/backend/js/index.js +586 -174
  5. package/src/backend/js/natives.js +383 -0
  6. package/src/backend/js/runtime.js +936 -1644
  7. package/src/backend/js/statements.js +1349 -132
  8. package/src/backend/js/stdlib/index.js +51 -94
  9. package/src/backend/js/templ.js +67 -118
  10. package/src/backend/js/type-info.js +436 -0
  11. package/src/backend/shared/fixed-float.js +20 -0
  12. package/src/backend/shared/fmt-types.js +80 -0
  13. package/src/backend/shared/host-unicode.js +36 -0
  14. package/src/backend/wasm/boundary.js +753 -872
  15. package/src/backend/wasm/emit-builtins.js +914 -237
  16. package/src/backend/wasm/emit-exprs.js +1456 -195
  17. package/src/backend/wasm/emit-maps.js +78 -380
  18. package/src/backend/wasm/emit-stmts.js +1659 -214
  19. package/src/backend/wasm/emit.js +614 -88
  20. package/src/backend/wasm/encode.js +43 -13
  21. package/src/backend/wasm/globals.js +491 -0
  22. package/src/backend/wasm/glue.js +2 -4
  23. package/src/backend/wasm/index.js +406 -3195
  24. package/src/backend/wasm/method-expr.js +392 -0
  25. package/src/backend/wasm/module-emitter.js +1615 -0
  26. package/src/backend/wasm/monomorph.js +164 -9
  27. package/src/backend/wasm/natives.js +596 -0
  28. package/src/backend/wasm/prescan.js +249 -0
  29. package/src/backend/wasm/prune-funcs.js +89 -0
  30. package/src/backend/wasm/stdlib/index.js +2 -37
  31. package/src/backend/wasm/stdlib/simd.js +293 -28
  32. package/src/backend/wasm/types.js +260 -27
  33. package/src/backend/wasm/variadic.js +93 -0
  34. package/src/backend/wasm/wat.js +47 -20
  35. package/src/{cli-core.js → cli/cli-core.js} +241 -11
  36. package/src/{test-runner.js → cli/test-runner.js} +188 -122
  37. package/src/{vendor.js → cli/vendor.js} +3 -4
  38. package/src/compiler.js +202 -386
  39. package/src/index.js +15 -169
  40. package/src/{lexer.js → lexer/lexer.js} +203 -62
  41. package/src/{templ-lexer.js → lexer/templ-lexer.js} +61 -18
  42. package/src/{tokens.js → lexer/tokens.js} +2 -0
  43. package/src/link/sourcemap.js +97 -0
  44. package/src/link/stdlib.js +737 -0
  45. package/src/link/type-names.js +148 -0
  46. package/src/link/wasm.js +318 -0
  47. package/src/lower/bounds.js +547 -0
  48. package/src/lower/boxing.js +1 -1
  49. package/src/lower/captures.js +267 -64
  50. package/src/lower/embedding.js +32 -3
  51. package/src/lower/errors-as.js +196 -0
  52. package/src/lower/fmt-formatters.js +905 -0
  53. package/src/lower/functions.js +2 -0
  54. package/src/lower/gen-types.js +274 -0
  55. package/src/lower/index.js +33 -19
  56. package/src/lower/json-codecs.js +1379 -0
  57. package/src/lower/ownership.js +47 -8
  58. package/src/lower/range.js +86 -1
  59. package/src/lower/reachability.js +150 -0
  60. package/src/lower/walk.js +12 -0
  61. package/src/parser/declarations.js +83 -15
  62. package/src/parser/expressions.js +110 -18
  63. package/src/parser/index.js +2 -1
  64. package/src/parser/statements.js +38 -22
  65. package/src/{templ-parser.js → parser/templ.js} +179 -17
  66. package/src/parser/types.js +70 -9
  67. package/src/resolver.js +21 -1
  68. package/src/typechecker/assignability.js +291 -19
  69. package/src/typechecker/const-fold.js +399 -0
  70. package/src/typechecker/constants.js +282 -0
  71. package/src/typechecker/expressions.js +1220 -183
  72. package/src/typechecker/index.js +659 -92
  73. package/src/typechecker/init-order.js +426 -0
  74. package/src/typechecker/operand-text.js +40 -0
  75. package/src/typechecker/resolve.js +613 -62
  76. package/src/typechecker/statements.js +212 -20
  77. package/src/typechecker/stdlib/excluded.js +902 -0
  78. package/src/typechecker/stdlib/index.js +38 -0
  79. package/src/typechecker/stdlib/simd.js +65 -15
  80. package/src/typechecker/termination.js +11 -2
  81. package/src/typechecker/types.js +268 -514
  82. package/stdlib/bytes/buffer.go +479 -0
  83. package/stdlib/bytes/bytes.go +1010 -0
  84. package/stdlib/bytes/reader.go +161 -0
  85. package/stdlib/cmp/cmp.go +65 -0
  86. package/stdlib/context/context.go +115 -0
  87. package/stdlib/crypto/rand/rand.go +34 -0
  88. package/stdlib/crypto/sha256/sha256.go +249 -0
  89. package/stdlib/encoding/base64/base64.go +331 -0
  90. package/stdlib/encoding/binary/binary.go +332 -0
  91. package/stdlib/encoding/hex/hex.go +140 -0
  92. package/stdlib/encoding/json/errors.go +31 -0
  93. package/stdlib/encoding/json/indent.go +71 -0
  94. package/stdlib/encoding/json/json.go +62 -0
  95. package/stdlib/encoding/json/number.go +12 -0
  96. package/stdlib/encoding/json/stream.go +173 -0
  97. package/stdlib/errors/errors.go +174 -0
  98. package/stdlib/fmt/errors.go +110 -0
  99. package/stdlib/fmt/format.go +732 -0
  100. package/stdlib/fmt/print.go +1232 -0
  101. package/stdlib/gom/gom.go +293 -0
  102. package/stdlib/hash/hash.go +53 -0
  103. package/stdlib/html/html.go +251 -0
  104. package/stdlib/internal/fmtrt/fmtrt.go +163 -0
  105. package/stdlib/internal/jsonrt/dec.go +871 -0
  106. package/stdlib/internal/jsonrt/enc.go +516 -0
  107. package/stdlib/internal/jsonrt/indent.go +135 -0
  108. package/stdlib/internal/jsonrt/number.go +27 -0
  109. package/stdlib/internal/jsonrt/reader.go +73 -0
  110. package/stdlib/internal/jsonrt/scanner.go +658 -0
  111. package/stdlib/io/io.go +502 -0
  112. package/stdlib/iter/iter.go +18 -0
  113. package/stdlib/maps/maps.go +131 -0
  114. package/stdlib/math/bits/bits.go +507 -0
  115. package/stdlib/math/extra.go +272 -0
  116. package/stdlib/math/math.go +439 -0
  117. package/stdlib/math/rand/rand.go +297 -0
  118. package/stdlib/os/os.go +93 -0
  119. package/stdlib/path/filepath/filepath.go +47 -0
  120. package/stdlib/path/path.go +394 -0
  121. package/stdlib/regexp/regexp.go +231 -0
  122. package/stdlib/slices/slices.go +526 -0
  123. package/stdlib/slices/sort.go +209 -0
  124. package/stdlib/slices/zsort_cmp.go +480 -0
  125. package/stdlib/slices/zsort_ordered.go +482 -0
  126. package/stdlib/sort/sort.go +500 -0
  127. package/stdlib/sort/zsort_func.go +480 -0
  128. package/stdlib/sort/zsort_iface.go +480 -0
  129. package/stdlib/strconv/float.go +1699 -0
  130. package/stdlib/strconv/isprint.go +752 -0
  131. package/stdlib/strconv/quote.go +526 -0
  132. package/stdlib/strconv/strconv.go +616 -0
  133. package/stdlib/strings/builder.go +95 -0
  134. package/stdlib/strings/reader.go +163 -0
  135. package/stdlib/strings/replacer.go +102 -0
  136. package/stdlib/strings/strings.go +807 -0
  137. package/stdlib/sync/sync.go +268 -0
  138. package/stdlib/testing/async_js.go +61 -0
  139. package/stdlib/testing/benchmark.go +297 -0
  140. package/stdlib/testing/testing.go +523 -0
  141. package/stdlib/time/duration.go +233 -0
  142. package/stdlib/time/format.go +745 -0
  143. package/stdlib/time/parse.go +790 -0
  144. package/stdlib/time/sleep_js.go +63 -0
  145. package/stdlib/time/time.go +834 -0
  146. package/stdlib/unicode/unicode.go +250 -0
  147. package/stdlib/unicode/utf8/utf8.go +464 -0
  148. package/src/backend/js/stdlib/base64.js +0 -12
  149. package/src/backend/js/stdlib/binary.js +0 -102
  150. package/src/backend/js/stdlib/bits.js +0 -46
  151. package/src/backend/js/stdlib/builder.js +0 -63
  152. package/src/backend/js/stdlib/bytes.js +0 -122
  153. package/src/backend/js/stdlib/errors.js +0 -44
  154. package/src/backend/js/stdlib/fmt.js +0 -178
  155. package/src/backend/js/stdlib/gom.js +0 -155
  156. package/src/backend/js/stdlib/hex.js +0 -17
  157. package/src/backend/js/stdlib/html.js +0 -20
  158. package/src/backend/js/stdlib/io.js +0 -137
  159. package/src/backend/js/stdlib/json.js +0 -972
  160. package/src/backend/js/stdlib/maps.js +0 -45
  161. package/src/backend/js/stdlib/math.js +0 -69
  162. package/src/backend/js/stdlib/os.js +0 -13
  163. package/src/backend/js/stdlib/path.js +0 -48
  164. package/src/backend/js/stdlib/rand.js +0 -32
  165. package/src/backend/js/stdlib/regexp.js +0 -54
  166. package/src/backend/js/stdlib/sha256.js +0 -12
  167. package/src/backend/js/stdlib/shared.js +0 -17
  168. package/src/backend/js/stdlib/simd.js +0 -24
  169. package/src/backend/js/stdlib/slices.js +0 -77
  170. package/src/backend/js/stdlib/sort.js +0 -30
  171. package/src/backend/js/stdlib/strconv.js +0 -74
  172. package/src/backend/js/stdlib/strings.js +0 -222
  173. package/src/backend/js/stdlib/sync.js +0 -13
  174. package/src/backend/js/stdlib/testing.js +0 -34
  175. package/src/backend/js/stdlib/time.js +0 -128
  176. package/src/backend/js/stdlib/unicode.js +0 -25
  177. package/src/backend/js/stdlib/utf8.js +0 -26
  178. package/src/backend/wasm/const-fold.js +0 -205
  179. package/src/backend/wasm/emit-stdlib.js +0 -13
  180. package/src/backend/wasm/stdlib/bytes.js +0 -5039
  181. package/src/backend/wasm/stdlib/core.js +0 -8903
  182. package/src/backend/wasm/stdlib/io.js +0 -2161
  183. package/src/backend/wasm/stdlib/packages.js +0 -2400
  184. package/src/backend/wasm/stdlib/pure.js +0 -720
  185. package/src/backend/wasm/stdlib/time.js +0 -1200
  186. package/src/typechecker/stdlib/core.js +0 -801
  187. package/src/typechecker/stdlib/extended.js +0 -914
  188. package/src/typechecker/stdlib.js +0 -22
  189. /package/src/{asset-manager.js → cli/asset-manager.js} +0 -0
  190. /package/src/{colors.js → cli/colors.js} +0 -0
  191. /package/src/{dev-server.js → cli/dev-server.js} +0 -0
  192. /package/src/{minifier.js → cli/minifier.js} +0 -0
  193. /package/src/{project-config.js → cli/project-config.js} +0 -0
  194. /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 = &registry{}
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