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,297 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Copyright 2009 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 rand implements pseudo-random number generators.
10
+ //
11
+ // The top-level functions draw from the host's random source and are not
12
+ // reproducible; Seed is a no-op. A generator made with New(NewSource(seed))
13
+ // is deterministic for a seed, but its sequence is not the one Go's
14
+ // generator produces.
15
+ package rand
16
+
17
+ // A Source represents a source of pseudo-random int64 values in [0, 1<<63).
18
+ type Source interface {
19
+ Int63() int64
20
+ Seed(seed int64)
21
+ }
22
+
23
+ // A Source64 is a Source that can also generate uniformly-distributed
24
+ // pseudo-random uint64 values in [0, 1<<64) directly.
25
+ type Source64 interface {
26
+ Source
27
+ Uint64() uint64
28
+ }
29
+
30
+ // hostFloat returns a uniformly distributed float64 in [0, 1) from the host.
31
+ //
32
+ //gofront:intrinsic rand_source
33
+ func hostFloat() float64
34
+
35
+ // hostSource is the Source behind the top-level functions.
36
+ type hostSource struct{}
37
+
38
+ func (hostSource) Uint64() uint64 {
39
+ hi := uint64(hostFloat() * (1 << 32))
40
+ lo := uint64(hostFloat() * (1 << 32))
41
+ return hi<<32 | lo
42
+ }
43
+
44
+ func (s hostSource) Int63() int64 { return int64(s.Uint64() >> 1) }
45
+
46
+ func (hostSource) Seed(seed int64) {}
47
+
48
+ var host Source = hostSource{}
49
+
50
+ // splitMix is a SplitMix64 generator, the Source behind NewSource.
51
+ type splitMix struct {
52
+ state uint64
53
+ }
54
+
55
+ func (s *splitMix) Uint64() uint64 {
56
+ // Variables, not constants: JS output of a typed 64-bit constant above
57
+ // 2^53 is a Number.
58
+ var gamma, mul1, mul2 uint64 = 0x9e3779b97f4a7c15, 0xbf58476d1ce4e5b9, 0x94d049bb133111eb
59
+ s.state += gamma
60
+ z := s.state
61
+ z = (z ^ (z >> 30)) * mul1
62
+ z = (z ^ (z >> 27)) * mul2
63
+ return z ^ (z >> 31)
64
+ }
65
+
66
+ func (s *splitMix) Int63() int64 { return int64(s.Uint64() >> 1) }
67
+
68
+ func (s *splitMix) Seed(seed int64) { s.state = uint64(seed) }
69
+
70
+ // NewSource returns a new pseudo-random Source seeded with the given value.
71
+ func NewSource(seed int64) Source {
72
+ return &splitMix{state: uint64(seed)}
73
+ }
74
+
75
+ // A Rand is a source of random numbers.
76
+ type Rand struct {
77
+ src Source
78
+ s64 Source64 // non-nil if src is source64
79
+
80
+ // readVal contains remainder of 63-bit integer used for bytes
81
+ // generation during Read; readPos is the number of bytes left in it.
82
+ readVal int64
83
+ readPos int8
84
+ }
85
+
86
+ // New returns a new Rand that uses random values from src to generate other
87
+ // random values.
88
+ func New(src Source) *Rand {
89
+ s64, _ := src.(Source64)
90
+ return &Rand{src: src, s64: s64}
91
+ }
92
+
93
+ // Seed uses the provided seed value to initialize the generator to a
94
+ // deterministic state.
95
+ func (r *Rand) Seed(seed int64) {
96
+ r.src.Seed(seed)
97
+ r.readPos = 0
98
+ }
99
+
100
+ // Int63 returns a non-negative pseudo-random 63-bit integer as an int64.
101
+ func (r *Rand) Int63() int64 { return r.src.Int63() }
102
+
103
+ // Uint32 returns a pseudo-random 32-bit value as a uint32.
104
+ func (r *Rand) Uint32() uint32 { return uint32(r.Int63() >> 31) }
105
+
106
+ // Uint64 returns a pseudo-random 64-bit value as a uint64.
107
+ func (r *Rand) Uint64() uint64 {
108
+ if r.s64 != nil {
109
+ return r.s64.Uint64()
110
+ }
111
+ return uint64(r.Int63())>>31 | uint64(r.Int63())<<32
112
+ }
113
+
114
+ // Int31 returns a non-negative pseudo-random 31-bit integer as an int32.
115
+ func (r *Rand) Int31() int32 { return int32(r.Int63() >> 32) }
116
+
117
+ // Int returns a non-negative pseudo-random int.
118
+ func (r *Rand) Int() int {
119
+ u := uint(r.Int63())
120
+ return int(u << 1 >> 1)
121
+ }
122
+
123
+ // Int63n returns, as an int64, a non-negative pseudo-random number in the
124
+ // half-open interval [0,n). It panics if n <= 0.
125
+ func (r *Rand) Int63n(n int64) int64 {
126
+ if n <= 0 {
127
+ panic("invalid argument to Int63n")
128
+ }
129
+ if n&(n-1) == 0 { // n is power of two, can mask
130
+ return r.Int63() & (n - 1)
131
+ }
132
+ // A typed variable: an untyped left operand of % is signed in WASM, and
133
+ // JS output of a typed constant above 2^53 is a Number.
134
+ var half uint64 = 1 << 63
135
+ max := int64(half - 1 - half%uint64(n))
136
+ v := r.Int63()
137
+ for v > max {
138
+ v = r.Int63()
139
+ }
140
+ return v % n
141
+ }
142
+
143
+ // Int31n returns, as an int32, a non-negative pseudo-random number in the
144
+ // half-open interval [0,n). It panics if n <= 0.
145
+ func (r *Rand) Int31n(n int32) int32 {
146
+ if n <= 0 {
147
+ panic("invalid argument to Int31n")
148
+ }
149
+ if n&(n-1) == 0 { // n is power of two, can mask
150
+ return r.Int31() & (n - 1)
151
+ }
152
+ const half uint32 = 1 << 31 // typed: an untyped left operand of % is signed in WASM
153
+ max := int32(half - 1 - half%uint32(n))
154
+ v := r.Int31()
155
+ for v > max {
156
+ v = r.Int31()
157
+ }
158
+ return v % n
159
+ }
160
+
161
+ // Intn returns, as an int, a non-negative pseudo-random number in the
162
+ // half-open interval [0,n). It panics if n <= 0.
163
+ func (r *Rand) Intn(n int) int {
164
+ if n <= 0 {
165
+ panic("invalid argument to Intn")
166
+ }
167
+ if n <= 1<<31-1 {
168
+ return int(r.Int31n(int32(n)))
169
+ }
170
+ return int(r.Int63n(int64(n)))
171
+ }
172
+
173
+ // Float64 returns, as a float64, a pseudo-random number in the half-open
174
+ // interval [0.0,1.0).
175
+ func (r *Rand) Float64() float64 {
176
+ for {
177
+ f := float64(r.Int63n(1<<53)) / (1 << 53)
178
+ if f != 1 {
179
+ return f
180
+ }
181
+ }
182
+ }
183
+
184
+ // Float32 returns, as a float32, a pseudo-random number in the half-open
185
+ // interval [0.0,1.0).
186
+ func (r *Rand) Float32() float32 {
187
+ for {
188
+ f := float32(r.Float64())
189
+ if f != 1 {
190
+ return f
191
+ }
192
+ }
193
+ }
194
+
195
+ // Perm returns, as a slice of n ints, a pseudo-random permutation of the
196
+ // integers in the half-open interval [0,n).
197
+ func (r *Rand) Perm(n int) []int {
198
+ if n < 0 {
199
+ // make([]int, n) panics like this; JS output of make does not check.
200
+ panic("runtime error: makeslice: len out of range")
201
+ }
202
+ m := make([]int, n)
203
+ for i := 0; i < n; i++ {
204
+ j := r.Intn(i + 1)
205
+ m[i] = m[j]
206
+ m[j] = i
207
+ }
208
+ return m
209
+ }
210
+
211
+ // Shuffle pseudo-randomizes the order of elements. n is the number of
212
+ // elements. Shuffle panics if n < 0. swap swaps the elements with indexes i
213
+ // and j.
214
+ func (r *Rand) Shuffle(n int, swap func(i, j int)) {
215
+ if n < 0 {
216
+ panic("invalid argument to Shuffle")
217
+ }
218
+ for i := n - 1; i > 0; i-- {
219
+ j := int(r.Int63n(int64(i + 1)))
220
+ swap(i, j)
221
+ }
222
+ }
223
+
224
+ // Read generates len(p) random bytes and writes them into p. It always
225
+ // returns len(p) and a nil error.
226
+ func (r *Rand) Read(p []byte) (n int, err error) {
227
+ pos := r.readPos
228
+ val := r.readVal
229
+ for n = 0; n < len(p); n++ {
230
+ if pos == 0 {
231
+ val = r.Int63()
232
+ pos = 7
233
+ }
234
+ p[n] = byte(val)
235
+ val >>= 8
236
+ pos--
237
+ }
238
+ r.readPos = pos
239
+ r.readVal = val
240
+ return
241
+ }
242
+
243
+ // The top-level functions draw from the host source through a Rand that
244
+ // holds no state of its own.
245
+
246
+ func hostRand() *Rand { return &Rand{src: host} }
247
+
248
+ // Seed does nothing: the top-level functions always draw from the host.
249
+ func Seed(seed int64) {}
250
+
251
+ // Int63 returns a non-negative pseudo-random 63-bit integer as an int64.
252
+ func Int63() int64 { return host.Int63() }
253
+
254
+ // Uint32 returns a pseudo-random 32-bit value as a uint32.
255
+ func Uint32() uint32 { return hostRand().Uint32() }
256
+
257
+ // Uint64 returns a pseudo-random 64-bit value as a uint64.
258
+ func Uint64() uint64 { return hostSource{}.Uint64() }
259
+
260
+ // Int31 returns a non-negative pseudo-random 31-bit integer as an int32.
261
+ func Int31() int32 { return hostRand().Int31() }
262
+
263
+ // Int returns a non-negative pseudo-random int.
264
+ func Int() int { return hostRand().Int() }
265
+
266
+ // Int63n returns, as an int64, a non-negative pseudo-random number in the
267
+ // half-open interval [0,n). It panics if n <= 0.
268
+ func Int63n(n int64) int64 { return hostRand().Int63n(n) }
269
+
270
+ // Int31n returns, as an int32, a non-negative pseudo-random number in the
271
+ // half-open interval [0,n). It panics if n <= 0.
272
+ func Int31n(n int32) int32 { return hostRand().Int31n(n) }
273
+
274
+ // Intn returns, as an int, a non-negative pseudo-random number in the
275
+ // half-open interval [0,n). It panics if n <= 0.
276
+ func Intn(n int) int { return hostRand().Intn(n) }
277
+
278
+ // Float64 returns, as a float64, a pseudo-random number in the half-open
279
+ // interval [0.0,1.0).
280
+ func Float64() float64 { return hostRand().Float64() }
281
+
282
+ // Float32 returns, as a float32, a pseudo-random number in the half-open
283
+ // interval [0.0,1.0).
284
+ func Float32() float32 { return hostRand().Float32() }
285
+
286
+ // Perm returns, as a slice of n ints, a pseudo-random permutation of the
287
+ // integers in the half-open interval [0,n).
288
+ func Perm(n int) []int { return hostRand().Perm(n) }
289
+
290
+ // Shuffle pseudo-randomizes the order of elements. n is the number of
291
+ // elements. Shuffle panics if n < 0. swap swaps the elements with indexes i
292
+ // and j.
293
+ func Shuffle(n int, swap func(i, j int)) { hostRand().Shuffle(n, swap) }
294
+
295
+ // Read generates len(p) random bytes and writes them into p. It always
296
+ // returns len(p) and a nil error.
297
+ func Read(p []byte) (n int, err error) { return hostRand().Read(p) }
@@ -0,0 +1,93 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Package os provides the process-level part of the real package: the
6
+ // standard streams, Exit and the environment. Files, directories and
7
+ // processes are not supported.
8
+ //
9
+ // Writes to Stdout and Stderr go through the host's output; Stdin is always
10
+ // at end of input.
11
+ package os
12
+
13
+ import "io"
14
+
15
+ // File represents an open file descriptor.
16
+ type File struct {
17
+ fd int
18
+ }
19
+
20
+ // Stdin, Stdout and Stderr are open Files pointing to the standard input,
21
+ // standard output, and standard error file descriptors.
22
+ var (
23
+ Stdin = &File{0}
24
+ Stdout = &File{1}
25
+ Stderr = &File{2}
26
+ )
27
+
28
+ // Args hold the command-line arguments. It is always empty.
29
+ var Args []string
30
+
31
+ // hostWrite writes s to the host's output for the file descriptor fd.
32
+ //
33
+ //gofront:intrinsic os_write
34
+ func hostWrite(fd int, s string)
35
+
36
+ // hostExit terminates the process with the given status code.
37
+ //
38
+ //gofront:intrinsic os_exit
39
+ func hostExit(code int)
40
+
41
+ // hostGetenv returns the value of the host environment variable key, or
42
+ // the empty string.
43
+ //
44
+ //gofront:intrinsic os_getenv
45
+ func hostGetenv(key string) string
46
+
47
+ // hostSetenv sets the host environment variable key to value.
48
+ //
49
+ //gofront:intrinsic os_setenv
50
+ func hostSetenv(key, value string)
51
+
52
+ // Write writes len(b) bytes from b to the File.
53
+ func (f *File) Write(b []byte) (n int, err error) {
54
+ hostWrite(f.fd, string(b))
55
+ return len(b), nil
56
+ }
57
+
58
+ // WriteString is like Write, but writes the contents of string s rather
59
+ // than a slice of bytes. It reports the bytes written, not the characters.
60
+ func (f *File) WriteString(s string) (n int, err error) {
61
+ hostWrite(f.fd, s)
62
+ // The JavaScript backend counts a string in UTF-16 units; the bytes are
63
+ // what Go reports.
64
+ return len([]byte(s)), nil
65
+ }
66
+
67
+ // Read reads up to len(b) bytes from the File. Standard input is always at
68
+ // end of input, so it returns 0, io.EOF.
69
+ func (f *File) Read(b []byte) (n int, err error) {
70
+ return 0, io.EOF
71
+ }
72
+
73
+ // Close closes the File. It has no effect on the standard streams.
74
+ func (f *File) Close() error {
75
+ return nil
76
+ }
77
+
78
+ // Exit causes the current program to exit with the given status code.
79
+ func Exit(code int) {
80
+ hostExit(code)
81
+ }
82
+
83
+ // Getenv retrieves the value of the environment variable named by the key.
84
+ // It returns the value, which will be empty if the variable is not present.
85
+ func Getenv(key string) string {
86
+ return hostGetenv(key)
87
+ }
88
+
89
+ // Setenv sets the value of the environment variable named by the key.
90
+ func Setenv(key, value string) error {
91
+ hostSetenv(key, value)
92
+ return nil
93
+ }
@@ -0,0 +1,47 @@
1
+ //go:build gofront
2
+
3
+ //gofront:target both
4
+
5
+ // Package filepath implements utility routines for manipulating filename
6
+ // paths. GoFront targets the browser and the JavaScript runtime, where paths
7
+ // are slash-separated, so every function is the one in package path.
8
+ package filepath
9
+
10
+ import "path"
11
+
12
+ // ErrBadPattern indicates a pattern was malformed.
13
+ var ErrBadPattern = path.ErrBadPattern
14
+
15
+ // Separator is the OS-specific path separator.
16
+ const Separator = '/'
17
+
18
+ // ListSeparator is the OS-specific path list separator.
19
+ const ListSeparator = ':'
20
+
21
+ // Join joins any number of path elements into a single path, separating them
22
+ // with a slash and cleaning the result.
23
+ func Join(elem ...string) string { return path.Join(elem...) }
24
+
25
+ // Clean returns the shortest path name equivalent to path by purely lexical
26
+ // processing.
27
+ func Clean(p string) string { return path.Clean(p) }
28
+
29
+ // Base returns the last element of path.
30
+ func Base(p string) string { return path.Base(p) }
31
+
32
+ // Dir returns all but the last element of path, typically the path's
33
+ // directory.
34
+ func Dir(p string) string { return path.Dir(p) }
35
+
36
+ // Ext returns the file name extension used by path.
37
+ func Ext(p string) string { return path.Ext(p) }
38
+
39
+ // Split splits path immediately following the final slash, separating it into
40
+ // a directory and file name component.
41
+ func Split(p string) (dir, file string) { return path.Split(p) }
42
+
43
+ // IsAbs reports whether the path is absolute.
44
+ func IsAbs(p string) bool { return path.IsAbs(p) }
45
+
46
+ // Match reports whether name matches the shell file name pattern.
47
+ func Match(pattern, name string) (matched bool, err error) { return path.Match(pattern, name) }