gofront 1.8.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 (177) hide show
  1. package/README.md +3 -3
  2. package/package.json +5 -4
  3. package/src/backend/js/expressions.js +849 -371
  4. package/src/backend/js/index.js +241 -147
  5. package/src/backend/js/natives.js +383 -0
  6. package/src/backend/js/runtime.js +512 -2547
  7. package/src/backend/js/statements.js +506 -103
  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 +177 -13
  11. package/src/backend/shared/fixed-float.js +20 -0
  12. package/src/backend/shared/fmt-types.js +63 -171
  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 +643 -256
  16. package/src/backend/wasm/emit-exprs.js +124 -57
  17. package/src/backend/wasm/emit-maps.js +17 -367
  18. package/src/backend/wasm/emit-stmts.js +325 -75
  19. package/src/backend/wasm/emit.js +104 -13
  20. package/src/backend/wasm/globals.js +47 -8
  21. package/src/backend/wasm/glue.js +2 -4
  22. package/src/backend/wasm/index.js +36 -530
  23. package/src/backend/wasm/method-expr.js +12 -1
  24. package/src/backend/wasm/module-emitter.js +92 -717
  25. package/src/backend/wasm/monomorph.js +103 -6
  26. package/src/backend/wasm/natives.js +596 -0
  27. package/src/backend/wasm/prescan.js +5 -153
  28. package/src/backend/wasm/prune-funcs.js +89 -0
  29. package/src/backend/wasm/stdlib/index.js +2 -32
  30. package/src/backend/wasm/types.js +68 -20
  31. package/src/backend/wasm/variadic.js +3 -3
  32. package/src/cli/cli-core.js +5 -1
  33. package/src/cli/test-runner.js +115 -342
  34. package/src/compiler.js +108 -130
  35. package/src/lexer/lexer.js +105 -11
  36. package/src/lexer/templ-lexer.js +61 -18
  37. package/src/lexer/tokens.js +1 -0
  38. package/src/link/stdlib.js +354 -132
  39. package/src/link/type-names.js +148 -0
  40. package/src/link/wasm.js +30 -6
  41. package/src/lower/bounds.js +153 -0
  42. package/src/lower/captures.js +92 -33
  43. package/src/lower/embedding.js +32 -3
  44. package/src/lower/errors-as.js +196 -0
  45. package/src/lower/fmt-formatters.js +905 -0
  46. package/src/lower/functions.js +2 -0
  47. package/src/lower/gen-types.js +274 -0
  48. package/src/lower/index.js +7 -1
  49. package/src/lower/json-codecs.js +228 -247
  50. package/src/lower/ownership.js +25 -7
  51. package/src/lower/reachability.js +69 -51
  52. package/src/lower/walk.js +12 -0
  53. package/src/parser/declarations.js +28 -5
  54. package/src/parser/expressions.js +86 -16
  55. package/src/parser/statements.js +1 -0
  56. package/src/parser/templ.js +44 -5
  57. package/src/parser/types.js +1 -0
  58. package/src/resolver.js +1 -2
  59. package/src/typechecker/assignability.js +124 -11
  60. package/src/typechecker/const-fold.js +70 -27
  61. package/src/typechecker/constants.js +32 -6
  62. package/src/typechecker/expressions.js +326 -98
  63. package/src/typechecker/index.js +208 -33
  64. package/src/typechecker/init-order.js +136 -40
  65. package/src/typechecker/operand-text.js +40 -0
  66. package/src/typechecker/resolve.js +192 -36
  67. package/src/typechecker/statements.js +122 -11
  68. package/src/typechecker/stdlib/excluded.js +9 -5
  69. package/src/typechecker/stdlib/index.js +25 -9
  70. package/src/typechecker/termination.js +10 -1
  71. package/src/typechecker/types.js +203 -573
  72. package/stdlib/bytes/buffer.go +479 -0
  73. package/stdlib/bytes/bytes.go +1010 -0
  74. package/stdlib/bytes/reader.go +161 -0
  75. package/stdlib/context/context.go +115 -0
  76. package/stdlib/crypto/rand/rand.go +34 -0
  77. package/stdlib/crypto/sha256/sha256.go +249 -0
  78. package/stdlib/encoding/base64/base64.go +331 -0
  79. package/stdlib/encoding/binary/binary.go +332 -0
  80. package/stdlib/encoding/hex/hex.go +140 -0
  81. package/stdlib/encoding/json/json.go +62 -0
  82. package/stdlib/errors/errors.go +174 -0
  83. package/stdlib/fmt/errors.go +110 -0
  84. package/stdlib/fmt/format.go +732 -0
  85. package/stdlib/fmt/print.go +1232 -0
  86. package/stdlib/gom/gom.go +293 -0
  87. package/stdlib/html/html.go +251 -0
  88. package/stdlib/internal/fmtrt/fmtrt.go +163 -0
  89. package/stdlib/internal/jsonrt/dec.go +171 -38
  90. package/stdlib/internal/jsonrt/enc.go +186 -36
  91. package/stdlib/internal/jsonrt/scanner.go +17 -8
  92. package/stdlib/io/io.go +157 -1
  93. package/stdlib/maps/maps.go +131 -0
  94. package/stdlib/math/bits/bits.go +507 -0
  95. package/stdlib/math/extra.go +16 -14
  96. package/stdlib/math/math.go +439 -0
  97. package/stdlib/math/rand/rand.go +297 -0
  98. package/stdlib/os/os.go +93 -0
  99. package/stdlib/path/filepath/filepath.go +47 -0
  100. package/stdlib/path/path.go +394 -0
  101. package/stdlib/regexp/regexp.go +231 -0
  102. package/stdlib/slices/slices.go +526 -0
  103. package/stdlib/slices/sort.go +209 -0
  104. package/stdlib/slices/zsort_cmp.go +480 -0
  105. package/stdlib/slices/zsort_ordered.go +482 -0
  106. package/stdlib/sort/sort.go +391 -452
  107. package/stdlib/sort/zsort_func.go +480 -0
  108. package/stdlib/sort/zsort_iface.go +480 -0
  109. package/stdlib/strconv/float.go +1699 -0
  110. package/stdlib/strconv/isprint.go +752 -0
  111. package/stdlib/strconv/quote.go +235 -50
  112. package/stdlib/strconv/strconv.go +616 -0
  113. package/stdlib/strings/builder.go +95 -0
  114. package/stdlib/strings/reader.go +163 -0
  115. package/stdlib/strings/replacer.go +102 -0
  116. package/stdlib/strings/strings.go +807 -0
  117. package/stdlib/sync/sync.go +268 -0
  118. package/stdlib/testing/async_js.go +61 -0
  119. package/stdlib/testing/benchmark.go +297 -0
  120. package/stdlib/testing/testing.go +523 -0
  121. package/stdlib/time/duration.go +233 -0
  122. package/stdlib/time/format.go +745 -0
  123. package/stdlib/time/parse.go +790 -0
  124. package/stdlib/time/sleep_js.go +63 -0
  125. package/stdlib/time/time.go +834 -0
  126. package/stdlib/unicode/unicode.go +141 -3
  127. package/stdlib/unicode/utf8/utf8.go +464 -0
  128. package/src/backend/js/fmt-runtime.js +0 -573
  129. package/src/backend/js/stdlib/base64.js +0 -12
  130. package/src/backend/js/stdlib/binary.js +0 -102
  131. package/src/backend/js/stdlib/bits.js +0 -119
  132. package/src/backend/js/stdlib/builder.js +0 -98
  133. package/src/backend/js/stdlib/bytes.js +0 -368
  134. package/src/backend/js/stdlib/errors.js +0 -45
  135. package/src/backend/js/stdlib/fmt.js +0 -517
  136. package/src/backend/js/stdlib/gom.js +0 -155
  137. package/src/backend/js/stdlib/hex.js +0 -17
  138. package/src/backend/js/stdlib/html.js +0 -20
  139. package/src/backend/js/stdlib/io.js +0 -137
  140. package/src/backend/js/stdlib/json.js +0 -1167
  141. package/src/backend/js/stdlib/maps.js +0 -37
  142. package/src/backend/js/stdlib/math.js +0 -85
  143. package/src/backend/js/stdlib/os.js +0 -13
  144. package/src/backend/js/stdlib/path.js +0 -48
  145. package/src/backend/js/stdlib/rand.js +0 -32
  146. package/src/backend/js/stdlib/regexp.js +0 -54
  147. package/src/backend/js/stdlib/sha256.js +0 -12
  148. package/src/backend/js/stdlib/shared.js +0 -17
  149. package/src/backend/js/stdlib/simd.js +0 -34
  150. package/src/backend/js/stdlib/slices.js +0 -107
  151. package/src/backend/js/stdlib/sort.js +0 -30
  152. package/src/backend/js/stdlib/strconv.js +0 -79
  153. package/src/backend/js/stdlib/strings.js +0 -301
  154. package/src/backend/js/stdlib/sync.js +0 -13
  155. package/src/backend/js/stdlib/testing.js +0 -41
  156. package/src/backend/js/stdlib/time.js +0 -152
  157. package/src/backend/js/stdlib/unicode.js +0 -25
  158. package/src/backend/js/stdlib/utf8.js +0 -26
  159. package/src/backend/wasm/stdlib/bytes.js +0 -6716
  160. package/src/backend/wasm/stdlib/core.js +0 -10278
  161. package/src/backend/wasm/stdlib/io.js +0 -3578
  162. package/src/backend/wasm/stdlib/packages.js +0 -2402
  163. package/src/backend/wasm/stdlib/pure.js +0 -720
  164. package/src/backend/wasm/stdlib/time.js +0 -2229
  165. package/src/typechecker/stdlib/core.js +0 -1079
  166. package/src/typechecker/stdlib/extended.js +0 -1210
  167. package/stdlib/bytes/iter.go +0 -192
  168. package/stdlib/bytes/search.go +0 -240
  169. package/stdlib/bytes/split.go +0 -218
  170. package/stdlib/errors/overlay.go +0 -12
  171. package/stdlib/maps/iter.go +0 -65
  172. package/stdlib/slices/extra.go +0 -73
  173. package/stdlib/slices/iter.go +0 -113
  174. package/stdlib/strings/extra.go +0 -35
  175. package/stdlib/strings/iter.go +0 -122
  176. package/stdlib/sync/extra.go +0 -105
  177. package/stdlib/unicode/utf8/bytes.go +0 -239
@@ -0,0 +1,233 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Copyright 2010 The Go Authors. All rights reserved.
6
+ // Use of this source code is governed by a BSD-style
7
+ // license that can be found in the LICENSE file.
8
+
9
+ package time
10
+
11
+ // A Duration represents the elapsed time between two instants as an int64
12
+ // nanosecond count. The representation limits the largest representable
13
+ // duration to approximately 290 years.
14
+ type Duration int64
15
+
16
+ const (
17
+ minDuration Duration = -1 << 63
18
+ maxDuration Duration = 1<<63 - 1
19
+ )
20
+
21
+ // Common durations. There is no definition for units of Day or larger to
22
+ // avoid confusion across daylight savings time zone transitions.
23
+ const (
24
+ Nanosecond Duration = 1
25
+ Microsecond = 1000 * Nanosecond
26
+ Millisecond = 1000 * Microsecond
27
+ Second = 1000 * Millisecond
28
+ Minute = 60 * Second
29
+ Hour = 60 * Minute
30
+ )
31
+
32
+ // String returns a string representing the duration in the form "72h3m0.5s".
33
+ // Leading zero units are omitted. As a special case, durations less than one
34
+ // second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure
35
+ // that the leading digit is non-zero. The zero duration formats as 0s.
36
+ func (d Duration) String() string {
37
+ buf := make([]byte, 32)
38
+ w := len(buf)
39
+
40
+ u := uint64(d)
41
+ neg := d < 0
42
+ if neg {
43
+ u = -u
44
+ }
45
+
46
+ if u < uint64(Second) {
47
+ // Special case: if duration is smaller than a second,
48
+ // use smaller units, like 1.2ms
49
+ var prec int
50
+ w--
51
+ buf[w] = 's'
52
+ w--
53
+ switch {
54
+ case u == 0:
55
+ return "0s"
56
+ case u < uint64(Microsecond):
57
+ // print nanoseconds
58
+ prec = 0
59
+ buf[w] = 'n'
60
+ case u < uint64(Millisecond):
61
+ // print microseconds: U+00B5 'µ' micro sign == 0xC2 0xB5
62
+ prec = 3
63
+ w--
64
+ buf[w] = 0xC2
65
+ buf[w+1] = 0xB5
66
+ default:
67
+ // print milliseconds
68
+ prec = 6
69
+ buf[w] = 'm'
70
+ }
71
+ w, u = fmtFrac(buf, w, u, prec)
72
+ w = fmtInt(buf, w, u)
73
+ } else {
74
+ w--
75
+ buf[w] = 's'
76
+
77
+ w, u = fmtFrac(buf, w, u, 9)
78
+
79
+ // u is now integer seconds
80
+ w = fmtInt(buf, w, u%60)
81
+ u /= 60
82
+
83
+ // u is now integer minutes
84
+ if u > 0 {
85
+ w--
86
+ buf[w] = 'm'
87
+ w = fmtInt(buf, w, u%60)
88
+ u /= 60
89
+
90
+ // u is now integer hours
91
+ // Stop at hours because days can be different lengths.
92
+ if u > 0 {
93
+ w--
94
+ buf[w] = 'h'
95
+ w = fmtInt(buf, w, u)
96
+ }
97
+ }
98
+ }
99
+
100
+ if neg {
101
+ w--
102
+ buf[w] = '-'
103
+ }
104
+
105
+ return string(buf[w:])
106
+ }
107
+
108
+ // fmtFrac formats the fraction of v/10**prec (e.g., ".12345") into the tail
109
+ // of buf at w, omitting trailing zeros. It omits the decimal point too when
110
+ // the fraction is 0. It returns the index where the output bytes begin and
111
+ // the value v/10**prec.
112
+ func fmtFrac(buf []byte, w int, v uint64, prec int) (nw int, nv uint64) {
113
+ // Omit trailing zeros up to and including decimal point.
114
+ print := false
115
+ for i := 0; i < prec; i++ {
116
+ digit := v % 10
117
+ print = print || digit != 0
118
+ if print {
119
+ w--
120
+ buf[w] = byte(digit) + '0'
121
+ }
122
+ v /= 10
123
+ }
124
+ if print {
125
+ w--
126
+ buf[w] = '.'
127
+ }
128
+ return w, v
129
+ }
130
+
131
+ // fmtInt formats v into the tail of buf at w. It returns the index where the
132
+ // output begins.
133
+ func fmtInt(buf []byte, w int, v uint64) int {
134
+ if v == 0 {
135
+ w--
136
+ buf[w] = '0'
137
+ } else {
138
+ for v > 0 {
139
+ w--
140
+ buf[w] = byte(v%10) + '0'
141
+ v /= 10
142
+ }
143
+ }
144
+ return w
145
+ }
146
+
147
+ // Nanoseconds returns the duration as an integer nanosecond count.
148
+ func (d Duration) Nanoseconds() int64 { return int64(d) }
149
+
150
+ // Microseconds returns the duration as an integer microsecond count.
151
+ func (d Duration) Microseconds() int64 { return int64(d) / 1000 }
152
+
153
+ // Milliseconds returns the duration as an integer millisecond count.
154
+ func (d Duration) Milliseconds() int64 { return int64(d) / 1000000 }
155
+
156
+ // Seconds returns the duration as a floating point number of seconds.
157
+ func (d Duration) Seconds() float64 {
158
+ sec := d / Second
159
+ nsec := d % Second
160
+ return float64(sec) + float64(nsec)/1e9
161
+ }
162
+
163
+ // Minutes returns the duration as a floating point number of minutes.
164
+ func (d Duration) Minutes() float64 {
165
+ min := d / Minute
166
+ nsec := d % Minute
167
+ return float64(min) + float64(nsec)/(60*1e9)
168
+ }
169
+
170
+ // Hours returns the duration as a floating point number of hours.
171
+ func (d Duration) Hours() float64 {
172
+ h := d / Hour
173
+ nsec := d % Hour
174
+ return float64(h) + float64(nsec)/(60*60*1e9)
175
+ }
176
+
177
+ // Truncate returns the result of rounding d toward zero to a multiple of m.
178
+ // If m <= 0, Truncate returns d unchanged.
179
+ func (d Duration) Truncate(m Duration) Duration {
180
+ if m <= 0 {
181
+ return d
182
+ }
183
+ return d - d%m
184
+ }
185
+
186
+ // lessThanHalf reports whether x+x < y but avoids overflow, assuming x and y
187
+ // are both positive.
188
+ func lessThanHalf(x, y Duration) bool {
189
+ return uint64(x)+uint64(x) < uint64(y)
190
+ }
191
+
192
+ // Round returns the result of rounding d to the nearest multiple of m. The
193
+ // rounding behavior for halfway values is to round away from zero. If the
194
+ // result exceeds the maximum (or minimum) value that can be stored in a
195
+ // Duration, Round returns the maximum (or minimum) duration. If m <= 0, Round
196
+ // returns d unchanged.
197
+ func (d Duration) Round(m Duration) Duration {
198
+ if m <= 0 {
199
+ return d
200
+ }
201
+ r := d % m
202
+ if d < 0 {
203
+ r = -r
204
+ if lessThanHalf(r, m) {
205
+ return d + r
206
+ }
207
+ if d1 := d - m + r; d1 < d {
208
+ return d1
209
+ }
210
+ return minDuration // overflow
211
+ }
212
+ if lessThanHalf(r, m) {
213
+ return d - r
214
+ }
215
+ if d1 := d + m - r; d1 > d {
216
+ return d1
217
+ }
218
+ return maxDuration // overflow
219
+ }
220
+
221
+ // Abs returns the absolute value of d. As a special case, Duration(math.MinInt64)
222
+ // is converted to Duration(math.MaxInt64), reducing its magnitude by 1
223
+ // nanosecond.
224
+ func (d Duration) Abs() Duration {
225
+ switch {
226
+ case d >= 0:
227
+ return d
228
+ case d == minDuration:
229
+ return maxDuration
230
+ default:
231
+ return -d
232
+ }
233
+ }