gofront 1.8.0 → 1.9.1

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 (178) hide show
  1. package/README.md +3 -3
  2. package/package.json +6 -5
  3. package/src/backend/js/expressions.js +1157 -408
  4. package/src/backend/js/index.js +327 -153
  5. package/src/backend/js/natives.js +383 -0
  6. package/src/backend/js/runtime.js +559 -2552
  7. package/src/backend/js/statements.js +670 -158
  8. package/src/backend/js/stdlib/index.js +45 -93
  9. package/src/backend/js/templ.js +32 -45
  10. package/src/backend/js/type-info.js +298 -19
  11. package/src/backend/shared/fixed-float.js +20 -0
  12. package/src/backend/shared/fmt-types.js +91 -170
  13. package/src/backend/shared/host-unicode.js +36 -0
  14. package/src/backend/wasm/boundary.js +490 -965
  15. package/src/backend/wasm/emit-builtins.js +884 -256
  16. package/src/backend/wasm/emit-exprs.js +185 -77
  17. package/src/backend/wasm/emit-maps.js +17 -367
  18. package/src/backend/wasm/emit-shared.js +4 -1
  19. package/src/backend/wasm/emit-stmts.js +524 -240
  20. package/src/backend/wasm/emit.js +176 -38
  21. package/src/backend/wasm/globals.js +48 -8
  22. package/src/backend/wasm/glue.js +2 -4
  23. package/src/backend/wasm/index.js +44 -530
  24. package/src/backend/wasm/method-expr.js +12 -1
  25. package/src/backend/wasm/module-emitter.js +299 -770
  26. package/src/backend/wasm/monomorph.js +139 -8
  27. package/src/backend/wasm/natives.js +600 -0
  28. package/src/backend/wasm/prescan.js +5 -153
  29. package/src/backend/wasm/prune-funcs.js +89 -0
  30. package/src/backend/wasm/stdlib/index.js +2 -32
  31. package/src/backend/wasm/types.js +97 -20
  32. package/src/backend/wasm/variadic.js +9 -4
  33. package/src/cli/cli-core.js +5 -1
  34. package/src/cli/test-runner.js +115 -342
  35. package/src/compiler.js +113 -130
  36. package/src/lexer/lexer.js +106 -11
  37. package/src/lexer/templ-lexer.js +61 -18
  38. package/src/lexer/tokens.js +1 -0
  39. package/src/link/stdlib.js +355 -132
  40. package/src/link/type-names.js +204 -0
  41. package/src/link/wasm.js +30 -6
  42. package/src/lower/bounds.js +153 -0
  43. package/src/lower/captures.js +92 -33
  44. package/src/lower/embedding.js +62 -5
  45. package/src/lower/errors-as.js +196 -0
  46. package/src/lower/fmt-formatters.js +929 -0
  47. package/src/lower/functions.js +225 -7
  48. package/src/lower/gen-types.js +293 -0
  49. package/src/lower/index.js +14 -2
  50. package/src/lower/json-codecs.js +334 -245
  51. package/src/lower/ownership.js +25 -7
  52. package/src/lower/reachability.js +69 -51
  53. package/src/lower/walk.js +12 -0
  54. package/src/parser/declarations.js +30 -5
  55. package/src/parser/expressions.js +111 -57
  56. package/src/parser/statements.js +108 -0
  57. package/src/parser/templ.js +44 -5
  58. package/src/parser/types.js +12 -0
  59. package/src/resolver.js +1 -2
  60. package/src/typechecker/assignability.js +214 -19
  61. package/src/typechecker/const-fold.js +70 -27
  62. package/src/typechecker/constants.js +156 -8
  63. package/src/typechecker/expressions.js +490 -108
  64. package/src/typechecker/index.js +346 -42
  65. package/src/typechecker/init-order.js +136 -40
  66. package/src/typechecker/operand-text.js +41 -0
  67. package/src/typechecker/resolve.js +490 -65
  68. package/src/typechecker/statements.js +288 -27
  69. package/src/typechecker/stdlib/excluded.js +9 -5
  70. package/src/typechecker/stdlib/index.js +25 -9
  71. package/src/typechecker/termination.js +10 -1
  72. package/src/typechecker/types.js +287 -575
  73. package/stdlib/bytes/buffer.go +479 -0
  74. package/stdlib/bytes/bytes.go +1010 -0
  75. package/stdlib/bytes/reader.go +161 -0
  76. package/stdlib/context/context.go +115 -0
  77. package/stdlib/crypto/rand/rand.go +34 -0
  78. package/stdlib/crypto/sha256/sha256.go +249 -0
  79. package/stdlib/encoding/base64/base64.go +331 -0
  80. package/stdlib/encoding/binary/binary.go +332 -0
  81. package/stdlib/encoding/hex/hex.go +140 -0
  82. package/stdlib/encoding/json/json.go +62 -0
  83. package/stdlib/errors/errors.go +174 -0
  84. package/stdlib/fmt/errors.go +110 -0
  85. package/stdlib/fmt/format.go +732 -0
  86. package/stdlib/fmt/print.go +1232 -0
  87. package/stdlib/gom/gom.go +293 -0
  88. package/stdlib/html/html.go +251 -0
  89. package/stdlib/internal/fmtrt/fmtrt.go +163 -0
  90. package/stdlib/internal/jsonrt/dec.go +171 -38
  91. package/stdlib/internal/jsonrt/enc.go +186 -36
  92. package/stdlib/internal/jsonrt/scanner.go +17 -8
  93. package/stdlib/io/io.go +157 -1
  94. package/stdlib/maps/maps.go +131 -0
  95. package/stdlib/math/bits/bits.go +507 -0
  96. package/stdlib/math/extra.go +16 -14
  97. package/stdlib/math/math.go +439 -0
  98. package/stdlib/math/rand/rand.go +297 -0
  99. package/stdlib/os/os.go +93 -0
  100. package/stdlib/path/filepath/filepath.go +47 -0
  101. package/stdlib/path/path.go +394 -0
  102. package/stdlib/regexp/regexp.go +231 -0
  103. package/stdlib/slices/slices.go +526 -0
  104. package/stdlib/slices/sort.go +209 -0
  105. package/stdlib/slices/zsort_cmp.go +480 -0
  106. package/stdlib/slices/zsort_ordered.go +482 -0
  107. package/stdlib/sort/sort.go +391 -452
  108. package/stdlib/sort/zsort_func.go +480 -0
  109. package/stdlib/sort/zsort_iface.go +480 -0
  110. package/stdlib/strconv/float.go +1699 -0
  111. package/stdlib/strconv/isprint.go +752 -0
  112. package/stdlib/strconv/quote.go +235 -50
  113. package/stdlib/strconv/strconv.go +616 -0
  114. package/stdlib/strings/builder.go +95 -0
  115. package/stdlib/strings/reader.go +163 -0
  116. package/stdlib/strings/replacer.go +102 -0
  117. package/stdlib/strings/strings.go +807 -0
  118. package/stdlib/sync/sync.go +268 -0
  119. package/stdlib/testing/async_js.go +61 -0
  120. package/stdlib/testing/benchmark.go +297 -0
  121. package/stdlib/testing/testing.go +523 -0
  122. package/stdlib/time/duration.go +233 -0
  123. package/stdlib/time/format.go +745 -0
  124. package/stdlib/time/parse.go +790 -0
  125. package/stdlib/time/sleep_js.go +63 -0
  126. package/stdlib/time/time.go +834 -0
  127. package/stdlib/unicode/unicode.go +141 -3
  128. package/stdlib/unicode/utf8/utf8.go +464 -0
  129. package/src/backend/js/fmt-runtime.js +0 -573
  130. package/src/backend/js/stdlib/base64.js +0 -12
  131. package/src/backend/js/stdlib/binary.js +0 -102
  132. package/src/backend/js/stdlib/bits.js +0 -119
  133. package/src/backend/js/stdlib/builder.js +0 -98
  134. package/src/backend/js/stdlib/bytes.js +0 -368
  135. package/src/backend/js/stdlib/errors.js +0 -45
  136. package/src/backend/js/stdlib/fmt.js +0 -517
  137. package/src/backend/js/stdlib/gom.js +0 -155
  138. package/src/backend/js/stdlib/hex.js +0 -17
  139. package/src/backend/js/stdlib/html.js +0 -20
  140. package/src/backend/js/stdlib/io.js +0 -137
  141. package/src/backend/js/stdlib/json.js +0 -1167
  142. package/src/backend/js/stdlib/maps.js +0 -37
  143. package/src/backend/js/stdlib/math.js +0 -85
  144. package/src/backend/js/stdlib/os.js +0 -13
  145. package/src/backend/js/stdlib/path.js +0 -48
  146. package/src/backend/js/stdlib/rand.js +0 -32
  147. package/src/backend/js/stdlib/regexp.js +0 -54
  148. package/src/backend/js/stdlib/sha256.js +0 -12
  149. package/src/backend/js/stdlib/shared.js +0 -17
  150. package/src/backend/js/stdlib/simd.js +0 -34
  151. package/src/backend/js/stdlib/slices.js +0 -107
  152. package/src/backend/js/stdlib/sort.js +0 -30
  153. package/src/backend/js/stdlib/strconv.js +0 -79
  154. package/src/backend/js/stdlib/strings.js +0 -301
  155. package/src/backend/js/stdlib/sync.js +0 -13
  156. package/src/backend/js/stdlib/testing.js +0 -41
  157. package/src/backend/js/stdlib/time.js +0 -152
  158. package/src/backend/js/stdlib/unicode.js +0 -25
  159. package/src/backend/js/stdlib/utf8.js +0 -26
  160. package/src/backend/wasm/stdlib/bytes.js +0 -6716
  161. package/src/backend/wasm/stdlib/core.js +0 -10278
  162. package/src/backend/wasm/stdlib/io.js +0 -3578
  163. package/src/backend/wasm/stdlib/packages.js +0 -2402
  164. package/src/backend/wasm/stdlib/pure.js +0 -720
  165. package/src/backend/wasm/stdlib/time.js +0 -2229
  166. package/src/typechecker/stdlib/core.js +0 -1079
  167. package/src/typechecker/stdlib/extended.js +0 -1210
  168. package/stdlib/bytes/iter.go +0 -192
  169. package/stdlib/bytes/search.go +0 -240
  170. package/stdlib/bytes/split.go +0 -218
  171. package/stdlib/errors/overlay.go +0 -12
  172. package/stdlib/maps/iter.go +0 -65
  173. package/stdlib/slices/extra.go +0 -73
  174. package/stdlib/slices/iter.go +0 -113
  175. package/stdlib/strings/extra.go +0 -35
  176. package/stdlib/strings/iter.go +0 -122
  177. package/stdlib/sync/extra.go +0 -105
  178. package/stdlib/unicode/utf8/bytes.go +0 -239
@@ -0,0 +1,163 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Overlay on the emitter-backed strings package: Reader written in Go over the
6
+ // real package's algorithm. GoFront strings are host strings whose indexes
7
+ // are not UTF-8 byte offsets, so the Reader holds the UTF-8 bytes of the
8
+ // string it was created from.
9
+ package strings
10
+
11
+ import (
12
+ "errors"
13
+ "io"
14
+ "unicode/utf8"
15
+ )
16
+
17
+ // A Reader implements the [io.Reader], [io.ReaderAt], [io.WriterTo], [io.Seeker],
18
+ // [io.ByteScanner], and [io.RuneScanner] interfaces by reading from
19
+ // a string.
20
+ // Unlike a [Buffer], a Reader is read-only and supports seeking.
21
+ // The zero value for Reader operates like a Reader of an empty string.
22
+ type Reader struct {
23
+ s []byte
24
+ i int64 // current reading index
25
+ prevRune int // index of previous rune; or < 0
26
+ }
27
+
28
+ // Len returns the number of bytes of the unread portion of the
29
+ // string.
30
+ func (r *Reader) Len() int {
31
+ if r.i >= int64(len(r.s)) {
32
+ return 0
33
+ }
34
+ return int(int64(len(r.s)) - r.i)
35
+ }
36
+
37
+ // Size returns the original length of the underlying string.
38
+ // Size is the number of bytes available for reading via [Reader.ReadAt].
39
+ // The result is unaffected by any method calls except [Reader.Reset].
40
+ func (r *Reader) Size() int64 { return int64(len(r.s)) }
41
+
42
+ // Read implements the [io.Reader] interface.
43
+ func (r *Reader) Read(b []byte) (n int, err error) {
44
+ if r.i >= int64(len(r.s)) {
45
+ return 0, io.EOF
46
+ }
47
+ r.prevRune = -1
48
+ n = copy(b, r.s[r.i:])
49
+ r.i += int64(n)
50
+ return
51
+ }
52
+
53
+ // ReadAt implements the [io.ReaderAt] interface.
54
+ func (r *Reader) ReadAt(b []byte, off int64) (n int, err error) {
55
+ // cannot modify state - see io.ReaderAt
56
+ if off < 0 {
57
+ return 0, errors.New("strings.Reader.ReadAt: negative offset")
58
+ }
59
+ if off >= int64(len(r.s)) {
60
+ return 0, io.EOF
61
+ }
62
+ n = copy(b, r.s[off:])
63
+ if n < len(b) {
64
+ err = io.EOF
65
+ }
66
+ return
67
+ }
68
+
69
+ // ReadByte implements the [io.ByteReader] interface.
70
+ func (r *Reader) ReadByte() (byte, error) {
71
+ r.prevRune = -1
72
+ if r.i >= int64(len(r.s)) {
73
+ return 0, io.EOF
74
+ }
75
+ b := r.s[r.i]
76
+ r.i++
77
+ return b, nil
78
+ }
79
+
80
+ // UnreadByte complements [Reader.ReadByte] in implementing the [io.ByteScanner] interface.
81
+ func (r *Reader) UnreadByte() error {
82
+ if r.i <= 0 {
83
+ return errors.New("strings.Reader.UnreadByte: at beginning of string")
84
+ }
85
+ r.prevRune = -1
86
+ r.i--
87
+ return nil
88
+ }
89
+
90
+ // ReadRune implements the [io.RuneReader] interface.
91
+ func (r *Reader) ReadRune() (ch rune, size int, err error) {
92
+ if r.i >= int64(len(r.s)) {
93
+ r.prevRune = -1
94
+ return 0, 0, io.EOF
95
+ }
96
+ r.prevRune = int(r.i)
97
+ if c := r.s[r.i]; c < utf8.RuneSelf {
98
+ r.i++
99
+ return rune(c), 1, nil
100
+ }
101
+ ch, size = utf8.DecodeRune(r.s[r.i:])
102
+ r.i += int64(size)
103
+ return
104
+ }
105
+
106
+ // UnreadRune complements [Reader.ReadRune] in implementing the [io.RuneScanner] interface.
107
+ func (r *Reader) UnreadRune() error {
108
+ if r.i <= 0 {
109
+ return errors.New("strings.Reader.UnreadRune: at beginning of string")
110
+ }
111
+ if r.prevRune < 0 {
112
+ return errors.New("strings.Reader.UnreadRune: previous operation was not ReadRune")
113
+ }
114
+ r.i = int64(r.prevRune)
115
+ r.prevRune = -1
116
+ return nil
117
+ }
118
+
119
+ // Seek implements the [io.Seeker] interface.
120
+ func (r *Reader) Seek(offset int64, whence int) (int64, error) {
121
+ r.prevRune = -1
122
+ var abs int64
123
+ switch whence {
124
+ case io.SeekStart:
125
+ abs = offset
126
+ case io.SeekCurrent:
127
+ abs = r.i + offset
128
+ case io.SeekEnd:
129
+ abs = int64(len(r.s)) + offset
130
+ default:
131
+ return 0, errors.New("strings.Reader.Seek: invalid whence")
132
+ }
133
+ if abs < 0 {
134
+ return 0, errors.New("strings.Reader.Seek: negative position")
135
+ }
136
+ r.i = abs
137
+ return abs, nil
138
+ }
139
+
140
+ // WriteTo implements the [io.WriterTo] interface.
141
+ func (r *Reader) WriteTo(w io.Writer) (n int64, err error) {
142
+ r.prevRune = -1
143
+ if r.i >= int64(len(r.s)) {
144
+ return 0, nil
145
+ }
146
+ b := r.s[r.i:]
147
+ m, err := w.Write(b)
148
+ if m > len(b) {
149
+ panic("strings.Reader.WriteTo: invalid Write count")
150
+ }
151
+ r.i += int64(m)
152
+ n = int64(m)
153
+ if m != len(b) && err == nil {
154
+ err = io.ErrShortWrite
155
+ }
156
+ return
157
+ }
158
+
159
+ // Reset resets the [Reader] to be reading from s.
160
+ func (r *Reader) Reset(s string) { *r = Reader{[]byte(s), 0, -1} }
161
+
162
+ // NewReader returns a new [Reader] reading from s.
163
+ func NewReader(s string) *Reader { return &Reader{[]byte(s), 0, -1} }
@@ -0,0 +1,102 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Overlay on the emitter-backed strings package: Replacer written in Go.
6
+ // Replacements run in the order they appear in the target string without
7
+ // overlapping, and the old strings are tried in argument order, with an
8
+ // empty old string never matching twice at the same position, as in Go's
9
+ // generic replacer.
10
+ package strings
11
+
12
+ import "io"
13
+
14
+ // Replacer replaces a list of strings with replacements.
15
+ // It is safe for concurrent use by multiple goroutines.
16
+ type Replacer struct {
17
+ oldnew []string
18
+ }
19
+
20
+ // NewReplacer returns a new Replacer from a list of old, new string
21
+ // pairs. It panics if given an odd number of arguments.
22
+ func NewReplacer(oldnew ...string) *Replacer {
23
+ if len(oldnew)%2 == 1 {
24
+ panic("strings.NewReplacer: odd argument count")
25
+ }
26
+ return &Replacer{oldnew: append([]string(nil), oldnew...)}
27
+ }
28
+
29
+ // match returns the replacement chosen at the start of s and the length of
30
+ // the old string it replaces; the first old string in argument order that is
31
+ // a prefix of s wins, and an empty one is skipped when skipEmpty is set.
32
+ func (r *Replacer) match(s string, skipEmpty bool) (val string, keylen int, ok bool) {
33
+ for i := 0; i < len(r.oldnew); i += 2 {
34
+ old := r.oldnew[i]
35
+ if skipEmpty && len(old) == 0 {
36
+ continue
37
+ }
38
+ if len(old) <= len(s) && s[:len(old)] == old {
39
+ return r.oldnew[i+1], len(old), true
40
+ }
41
+ }
42
+ return "", 0, false
43
+ }
44
+
45
+ // Replace returns a copy of s with all replacements performed.
46
+ func (r *Replacer) Replace(s string) string {
47
+ var out []byte
48
+ changed := false
49
+ last := 0
50
+ prevMatchEmpty := false
51
+ for i := 0; i <= len(s); {
52
+ val, keylen, ok := r.match(s[i:], prevMatchEmpty)
53
+ prevMatchEmpty = ok && keylen == 0
54
+ if ok {
55
+ changed = true
56
+ out = append(out, s[last:i]...)
57
+ out = append(out, val...)
58
+ i += keylen
59
+ last = i
60
+ continue
61
+ }
62
+ i++
63
+ }
64
+ if !changed {
65
+ return s
66
+ }
67
+ out = append(out, s[last:]...)
68
+ return string(out)
69
+ }
70
+
71
+ // WriteString writes s to w with all replacements performed.
72
+ func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error) {
73
+ last := 0
74
+ prevMatchEmpty := false
75
+ for i := 0; i <= len(s); {
76
+ val, keylen, ok := r.match(s[i:], prevMatchEmpty)
77
+ prevMatchEmpty = ok && keylen == 0
78
+ if ok {
79
+ var wn int
80
+ wn, err = io.WriteString(w, s[last:i])
81
+ n += wn
82
+ if err != nil {
83
+ return
84
+ }
85
+ wn, err = io.WriteString(w, val)
86
+ n += wn
87
+ if err != nil {
88
+ return
89
+ }
90
+ i += keylen
91
+ last = i
92
+ continue
93
+ }
94
+ i++
95
+ }
96
+ if last != len(s) {
97
+ var wn int
98
+ wn, err = io.WriteString(w, s[last:])
99
+ n += wn
100
+ }
101
+ return
102
+ }