goscript 0.0.25 → 0.0.28

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 (190) hide show
  1. package/README.md +4 -4
  2. package/cmd/goscript/cmd_compile.go +0 -3
  3. package/cmd/goscript/deps.go +11 -0
  4. package/compiler/analysis.go +259 -55
  5. package/compiler/assignment.go +2 -2
  6. package/compiler/builtin_test.go +1 -1
  7. package/compiler/compiler.go +201 -49
  8. package/compiler/compiler_test.go +53 -0
  9. package/compiler/composite-lit.go +32 -8
  10. package/compiler/decl.go +6 -6
  11. package/compiler/expr-call.go +83 -0
  12. package/compiler/expr.go +1 -1
  13. package/compiler/protobuf.go +557 -0
  14. package/compiler/spec-struct.go +4 -0
  15. package/compiler/spec-value.go +11 -3
  16. package/compiler/spec.go +18 -1
  17. package/compiler/stmt-assign.go +35 -0
  18. package/compiler/type-assert.go +87 -0
  19. package/compiler/type.go +5 -2
  20. package/dist/gs/builtin/builtin.d.ts +19 -1
  21. package/dist/gs/builtin/builtin.js +85 -5
  22. package/dist/gs/builtin/builtin.js.map +1 -1
  23. package/dist/gs/builtin/channel.js.map +1 -1
  24. package/dist/gs/builtin/slice.d.ts +1 -1
  25. package/dist/gs/builtin/slice.js +59 -26
  26. package/dist/gs/builtin/slice.js.map +1 -1
  27. package/dist/gs/cmp/index.js.map +1 -1
  28. package/dist/gs/context/context.d.ts +1 -1
  29. package/dist/gs/context/context.js +20 -11
  30. package/dist/gs/context/context.js.map +1 -1
  31. package/dist/gs/errors/errors.d.ts +7 -0
  32. package/dist/gs/errors/errors.js +190 -0
  33. package/dist/gs/errors/errors.js.map +1 -0
  34. package/dist/gs/errors/index.d.ts +1 -0
  35. package/dist/gs/errors/index.js +2 -0
  36. package/dist/gs/errors/index.js.map +1 -0
  37. package/dist/gs/internal/goarch/index.js +1 -1
  38. package/dist/gs/internal/goarch/index.js.map +1 -1
  39. package/dist/gs/io/index.d.ts +1 -0
  40. package/dist/gs/io/index.js +2 -0
  41. package/dist/gs/io/index.js.map +1 -0
  42. package/dist/gs/io/io.d.ts +107 -0
  43. package/dist/gs/io/io.js +385 -0
  44. package/dist/gs/io/io.js.map +1 -0
  45. package/dist/gs/iter/iter.js.map +1 -1
  46. package/dist/gs/math/bits/index.js +34 -32
  47. package/dist/gs/math/bits/index.js.map +1 -1
  48. package/dist/gs/runtime/runtime.d.ts +1 -0
  49. package/dist/gs/runtime/runtime.js +15 -18
  50. package/dist/gs/runtime/runtime.js.map +1 -1
  51. package/dist/gs/slices/slices.d.ts +1 -1
  52. package/dist/gs/slices/slices.js +1 -1
  53. package/dist/gs/slices/slices.js.map +1 -1
  54. package/dist/gs/strings/builder.d.ts +18 -0
  55. package/dist/gs/strings/builder.js +205 -0
  56. package/dist/gs/strings/builder.js.map +1 -0
  57. package/dist/gs/strings/clone.d.ts +1 -0
  58. package/dist/gs/strings/clone.js +16 -0
  59. package/dist/gs/strings/clone.js.map +1 -0
  60. package/dist/gs/strings/compare.d.ts +1 -0
  61. package/dist/gs/strings/compare.js +14 -0
  62. package/dist/gs/strings/compare.js.map +1 -0
  63. package/dist/gs/strings/index.d.ts +2 -0
  64. package/dist/gs/strings/index.js +3 -0
  65. package/dist/gs/strings/index.js.map +1 -0
  66. package/dist/gs/strings/iter.d.ts +8 -0
  67. package/dist/gs/strings/iter.js +160 -0
  68. package/dist/gs/strings/iter.js.map +1 -0
  69. package/dist/gs/strings/reader.d.ts +34 -0
  70. package/dist/gs/strings/reader.js +418 -0
  71. package/dist/gs/strings/reader.js.map +1 -0
  72. package/dist/gs/strings/replace.d.ts +106 -0
  73. package/dist/gs/strings/replace.js +1136 -0
  74. package/dist/gs/strings/replace.js.map +1 -0
  75. package/dist/gs/strings/search.d.ts +24 -0
  76. package/dist/gs/strings/search.js +169 -0
  77. package/dist/gs/strings/search.js.map +1 -0
  78. package/dist/gs/strings/strings.d.ts +47 -0
  79. package/dist/gs/strings/strings.js +418 -0
  80. package/dist/gs/strings/strings.js.map +1 -0
  81. package/dist/gs/stringslite/index.d.ts +1 -0
  82. package/dist/gs/stringslite/index.js +2 -0
  83. package/dist/gs/stringslite/index.js.map +1 -0
  84. package/dist/gs/stringslite/strings.d.ts +11 -0
  85. package/dist/gs/stringslite/strings.js +67 -0
  86. package/dist/gs/stringslite/strings.js.map +1 -0
  87. package/dist/gs/sync/index.d.ts +1 -0
  88. package/dist/gs/sync/index.js +2 -0
  89. package/dist/gs/sync/index.js.map +1 -0
  90. package/dist/gs/sync/sync.d.ts +79 -0
  91. package/dist/gs/sync/sync.js +392 -0
  92. package/dist/gs/sync/sync.js.map +1 -0
  93. package/dist/gs/time/time.js +7 -7
  94. package/dist/gs/time/time.js.map +1 -1
  95. package/dist/gs/unicode/index.d.ts +1 -0
  96. package/dist/gs/unicode/index.js +2 -0
  97. package/dist/gs/unicode/index.js.map +1 -0
  98. package/dist/gs/unicode/unicode.d.ts +105 -0
  99. package/dist/gs/unicode/unicode.js +332 -0
  100. package/dist/gs/unicode/unicode.js.map +1 -0
  101. package/dist/gs/unicode/utf8/index.d.ts +1 -0
  102. package/dist/gs/unicode/utf8/index.js +3 -0
  103. package/dist/gs/unicode/utf8/index.js.map +1 -0
  104. package/dist/gs/unicode/utf8/utf8.d.ts +20 -0
  105. package/dist/gs/unicode/utf8/utf8.js +196 -0
  106. package/dist/gs/unicode/utf8/utf8.js.map +1 -0
  107. package/dist/gs/unsafe/index.d.ts +1 -0
  108. package/dist/gs/unsafe/index.js +2 -0
  109. package/dist/gs/unsafe/index.js.map +1 -0
  110. package/dist/gs/unsafe/unsafe.d.ts +11 -0
  111. package/dist/gs/unsafe/unsafe.js +44 -0
  112. package/dist/gs/unsafe/unsafe.js.map +1 -0
  113. package/go.mod +2 -1
  114. package/go.sum +6 -2
  115. package/gs/README.md +6 -0
  116. package/gs/builtin/builtin.ts +158 -0
  117. package/gs/builtin/channel.ts +683 -0
  118. package/gs/builtin/defer.ts +58 -0
  119. package/gs/builtin/index.ts +1 -0
  120. package/gs/builtin/io.ts +22 -0
  121. package/gs/builtin/map.ts +50 -0
  122. package/gs/builtin/slice.ts +1030 -0
  123. package/gs/builtin/type.ts +1106 -0
  124. package/gs/builtin/varRef.ts +25 -0
  125. package/gs/cmp/godoc.txt +8 -0
  126. package/gs/cmp/index.ts +29 -0
  127. package/gs/context/context.ts +401 -0
  128. package/gs/context/godoc.txt +69 -0
  129. package/gs/context/index.ts +1 -0
  130. package/gs/errors/errors.ts +223 -0
  131. package/gs/errors/godoc.txt +63 -0
  132. package/gs/errors/index.ts +1 -0
  133. package/gs/internal/goarch/godoc.txt +39 -0
  134. package/gs/internal/goarch/index.ts +18 -0
  135. package/gs/io/godoc.txt +61 -0
  136. package/gs/io/index.ts +1 -0
  137. package/gs/io/io.go +75 -0
  138. package/gs/io/io.ts +546 -0
  139. package/gs/iter/godoc.txt +203 -0
  140. package/gs/iter/index.ts +1 -0
  141. package/gs/iter/iter.ts +117 -0
  142. package/gs/math/bits/index.ts +356 -0
  143. package/gs/math/godoc.txt +76 -0
  144. package/gs/runtime/godoc.txt +331 -0
  145. package/gs/runtime/index.ts +1 -0
  146. package/gs/runtime/runtime.ts +178 -0
  147. package/gs/slices/godoc.txt +44 -0
  148. package/gs/slices/index.ts +1 -0
  149. package/gs/slices/slices.ts +22 -0
  150. package/gs/strings/builder.test.ts +121 -0
  151. package/gs/strings/builder.ts +223 -0
  152. package/gs/strings/clone.test.ts +43 -0
  153. package/gs/strings/clone.ts +17 -0
  154. package/gs/strings/compare.test.ts +84 -0
  155. package/gs/strings/compare.ts +13 -0
  156. package/gs/strings/godoc.txt +66 -0
  157. package/gs/strings/index.ts +2 -0
  158. package/gs/strings/iter.test.ts +343 -0
  159. package/gs/strings/iter.ts +171 -0
  160. package/gs/strings/reader.test.ts +243 -0
  161. package/gs/strings/reader.ts +451 -0
  162. package/gs/strings/replace.test.ts +181 -0
  163. package/gs/strings/replace.ts +1310 -0
  164. package/gs/strings/search.test.ts +214 -0
  165. package/gs/strings/search.ts +213 -0
  166. package/gs/strings/strings.test.ts +477 -0
  167. package/gs/strings/strings.ts +510 -0
  168. package/gs/stringslite/godoc.txt +17 -0
  169. package/gs/stringslite/index.ts +1 -0
  170. package/gs/stringslite/strings.ts +82 -0
  171. package/gs/sync/godoc.txt +21 -0
  172. package/gs/sync/index.ts +1 -0
  173. package/gs/sync/sync.go +64 -0
  174. package/gs/sync/sync.ts +449 -0
  175. package/gs/time/godoc.md +116 -0
  176. package/gs/time/godoc.txt +116 -0
  177. package/gs/time/index.ts +1 -0
  178. package/gs/time/time.ts +272 -0
  179. package/gs/unicode/godoc.txt +52 -0
  180. package/gs/unicode/index.ts +1 -0
  181. package/gs/unicode/unicode.go +38 -0
  182. package/gs/unicode/unicode.ts +418 -0
  183. package/gs/unicode/utf8/godoc.txt +22 -0
  184. package/gs/unicode/utf8/index.ts +2 -0
  185. package/gs/unicode/utf8/utf8.ts +227 -0
  186. package/gs/unsafe/godoc.txt +19 -0
  187. package/gs/unsafe/index.ts +1 -0
  188. package/gs/unsafe/unsafe.test.ts +68 -0
  189. package/gs/unsafe/unsafe.ts +77 -0
  190. package/package.json +6 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsafe.js","sourceRoot":"","sources":["../../../gs/unsafe/unsafe.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,2FAA2F;AAC3F,mCAAmC;AAYnC,uEAAuE;AACvE,4DAA4D;AAC5D,MAAM,UAAU,OAAO,CAAC,QAAuB;IAC7C,MAAM,IAAI,KAAK,CACb,sHAAsH,CACvH,CAAA;AACH,CAAC;AAED,8EAA8E;AAC9E,4DAA4D;AAC5D,MAAM,UAAU,QAAQ,CAAC,QAAuB;IAC9C,MAAM,IAAI,KAAK,CACb,sIAAsI,CACvI,CAAA;AACH,CAAC;AAED,iEAAiE;AACjE,4DAA4D;AAC5D,MAAM,UAAU,MAAM,CAAC,QAAuB;IAC5C,MAAM,IAAI,KAAK,CACb,gHAAgH,CACjH,CAAA;AACH,CAAC;AAED,sDAAsD;AACtD,+DAA+D;AAC/D,MAAM,UAAU,GAAG,CAAC,GAAY,EAAE,GAAgB;IAChD,MAAM,IAAI,KAAK,CACb,yGAAyG,CAC1G,CAAA;AACH,CAAC;AAED,6DAA6D;AAC7D,4DAA4D;AAC5D,MAAM,UAAU,KAAK,CAAC,GAAY,EAAE,GAAgB;IAClD,MAAM,IAAI,KAAK,CACb,6GAA6G,CAC9G,CAAA;AACH,CAAC;AAED,mEAAmE;AACnE,4DAA4D;AAC5D,MAAM,UAAU,SAAS,CAAC,KAAY;IACpC,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAA;AACH,CAAC;AAED,oEAAoE;AACpE,4DAA4D;AAC5D,MAAM,UAAU,MAAM,CAAC,GAAY,EAAE,GAAgB;IACnD,MAAM,IAAI,KAAK,CACb,8GAA8G,CAC/G,CAAA;AACH,CAAC;AAED,kEAAkE;AAClE,4DAA4D;AAC5D,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,MAAM,IAAI,KAAK,CACb,kHAAkH,CACnH,CAAA;AACH,CAAC"}
package/go.mod CHANGED
@@ -4,6 +4,7 @@ go 1.24.3
4
4
 
5
5
  require (
6
6
  github.com/aperturerobotics/cli v1.0.0
7
+ github.com/aperturerobotics/protobuf-go-lite v0.9.1
7
8
  github.com/aperturerobotics/util v1.30.0
8
9
  github.com/pkg/errors v0.9.1
9
10
  github.com/sirupsen/logrus v1.9.3
@@ -12,7 +13,7 @@ require (
12
13
 
13
14
  require (
14
15
  github.com/aperturerobotics/common v0.22.1 // indirect
15
- github.com/stretchr/testify v1.10.0 // indirect
16
+ github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20240713111131-be6bf89c3008 // indirect
16
17
  github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
17
18
  golang.org/x/mod v0.24.0 // indirect
18
19
  golang.org/x/sync v0.14.0 // indirect
package/go.sum CHANGED
@@ -2,13 +2,17 @@ github.com/aperturerobotics/cli v1.0.0 h1:s3xT2h7eBih4/4yZKTn/HQ6P+qpk6ygWZl2416
2
2
  github.com/aperturerobotics/cli v1.0.0/go.mod h1:wtlINjMcKuwyV1x4ftReuA6hHZcPB8kPMXHyQqGFCSc=
3
3
  github.com/aperturerobotics/common v0.22.1 h1:wxTV9wSgfAM9jYUuSzNFzUeC28DQMBgDO3iGahlHeaY=
4
4
  github.com/aperturerobotics/common v0.22.1/go.mod h1:wsPfDVCTNpGHddg/MSfm84rKoO4GAvb+TQtATXz+pKY=
5
+ github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20240713111131-be6bf89c3008 h1:So9JeziaWKx2Fw8sK4AUN/szqKtJ0jEMhS6bU4sHbxs=
6
+ github.com/aperturerobotics/json-iterator-lite v1.0.1-0.20240713111131-be6bf89c3008/go.mod h1:snaApCEDtrHHP6UWSLKiYNOZU9A5NyzccKenx9oZEzg=
7
+ github.com/aperturerobotics/protobuf-go-lite v0.9.1 h1:P1knXKnwLJpVE8fmeXYGckKu79IhqUvKRdCfJNR0MwQ=
8
+ github.com/aperturerobotics/protobuf-go-lite v0.9.1/go.mod h1:fULrxQxEBWKQm7vvju9AfjTp9yfHoLgwMQWTiZQ2tg0=
5
9
  github.com/aperturerobotics/util v1.30.0 h1:OKhFVPnAfR8/dfVNV27EtMr27C0kzwPiStoCwKiint0=
6
10
  github.com/aperturerobotics/util v1.30.0/go.mod h1:T97YTP+FVLegYo5rylOVaPuTLyZyiDqYxD5zVLI9YAc=
7
11
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8
12
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9
13
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10
- github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
11
- github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
14
+ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
15
+ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
12
16
  github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
13
17
  github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
14
18
  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
package/gs/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Hand-written Go Packages
2
+
3
+ This directory contains hand-written .gs.ts files corresponding to select
4
+ packages from the standard library. These packages are hard or impossible to
5
+ transpile correctly, so we hand-write the TypeScript equivalents here.
6
+
@@ -0,0 +1,158 @@
1
+ export * from './varRef.js'
2
+ export * from './channel.js'
3
+ export * from './defer.js'
4
+ export * from './io.js'
5
+ export * from './map.js'
6
+ export * from './slice.js'
7
+ export * from './type.js'
8
+
9
+ // Copy is the Go builtin function that copies the contents of one slice to another.
10
+ // It returns the number of elements copied.
11
+ export function copy<T>(
12
+ dst: T[] | Uint8Array,
13
+ src: T[] | Uint8Array | string,
14
+ ): number {
15
+ // Handle string to Uint8Array copy (common in Go)
16
+ if (typeof src === 'string' && dst instanceof Uint8Array) {
17
+ const encoder = new TextEncoder()
18
+ const srcBytes = encoder.encode(src)
19
+ const n = Math.min(dst.length, srcBytes.length)
20
+ for (let i = 0; i < n; i++) {
21
+ dst[i] = srcBytes[i]
22
+ }
23
+ return n
24
+ }
25
+
26
+ // Handle Uint8Array to Uint8Array copy
27
+ if (dst instanceof Uint8Array && src instanceof Uint8Array) {
28
+ const n = Math.min(dst.length, src.length)
29
+ for (let i = 0; i < n; i++) {
30
+ dst[i] = src[i]
31
+ }
32
+ return n
33
+ }
34
+
35
+ // Handle array to array copy (original implementation)
36
+ if (Array.isArray(dst) && Array.isArray(src)) {
37
+ const n = Math.min(dst.length, src.length)
38
+ for (let i = 0; i < n; i++) {
39
+ dst[i] = src[i]
40
+ }
41
+ return n
42
+ }
43
+
44
+ // Handle mixed types - convert to compatible format
45
+ if (dst instanceof Uint8Array && Array.isArray(src)) {
46
+ const n = Math.min(dst.length, src.length)
47
+ for (let i = 0; i < n; i++) {
48
+ dst[i] = src[i] as number
49
+ }
50
+ return n
51
+ }
52
+
53
+ if (Array.isArray(dst) && src instanceof Uint8Array) {
54
+ const n = Math.min(dst.length, src.length)
55
+ for (let i = 0; i < n; i++) {
56
+ dst[i] = src[i] as T
57
+ }
58
+ return n
59
+ }
60
+
61
+ throw new Error(
62
+ `Unsupported copy operation between ${typeof dst} and ${typeof src}`,
63
+ )
64
+ }
65
+
66
+ // Duration multiplication helper for time package operations
67
+ // Handles expressions like time.Hour * 24
68
+ export function multiplyDuration(duration: any, multiplier: number): any {
69
+ // Check if duration has a multiply method (like our Duration class)
70
+ if (duration && typeof duration.multiply === 'function') {
71
+ return duration.multiply(multiplier)
72
+ }
73
+
74
+ // Check if duration has a valueOf method for numeric operations
75
+ if (duration && typeof duration.valueOf === 'function') {
76
+ const numValue = duration.valueOf()
77
+ // Return an object with the same structure but multiplied value
78
+ if (typeof numValue === 'number') {
79
+ // Try to create a new instance of the same type
80
+ if (duration.constructor) {
81
+ return new duration.constructor(numValue * multiplier)
82
+ }
83
+ // Fallback: return a simple object with valueOf
84
+ return {
85
+ valueOf: () => numValue * multiplier,
86
+ toString: () => (numValue * multiplier).toString() + 'ns',
87
+ }
88
+ }
89
+ }
90
+
91
+ // Fallback for simple numeric values
92
+ if (typeof duration === 'number') {
93
+ return duration * multiplier
94
+ }
95
+
96
+ throw new Error(`Cannot multiply duration of type ${typeof duration}`)
97
+ }
98
+
99
+ /**
100
+ * Normalizes various byte representations into a `Uint8Array` for protobuf compatibility.
101
+ *
102
+ * @param {Uint8Array | number[] | null | undefined | { data: number[] } | { valueOf(): number[] }} bytes
103
+ * The input to normalize. Accepted types:
104
+ * - `Uint8Array`: Returned as-is.
105
+ * - `number[]`: Converted to a `Uint8Array`.
106
+ * - `null` or `undefined`: Returns an empty `Uint8Array`.
107
+ * - `{ data: number[] }`: An object with a `data` property (e.g., `$.Slice<number>`), where `data` is a `number[]`.
108
+ * - `{ valueOf(): number[] }`: An object with a `valueOf` method that returns a `number[]`.
109
+ * @returns {Uint8Array} A normalized `Uint8Array` representation of the input.
110
+ * @throws {Error} If the input type is unsupported or cannot be normalized.
111
+ */
112
+ export function normalizeBytes(
113
+ bytes:
114
+ | Uint8Array
115
+ | number[]
116
+ | null
117
+ | undefined
118
+ | { data: number[] }
119
+ | { valueOf(): number[] },
120
+ ): Uint8Array {
121
+ if (bytes === null || bytes === undefined) {
122
+ return new Uint8Array(0)
123
+ }
124
+
125
+ if (bytes instanceof Uint8Array) {
126
+ return bytes
127
+ }
128
+
129
+ // Handle $.Slice<number> (which has a .data property that's a number[])
130
+ if (
131
+ bytes &&
132
+ typeof bytes === 'object' &&
133
+ 'data' in bytes &&
134
+ Array.isArray(bytes.data)
135
+ ) {
136
+ return new Uint8Array(bytes.data)
137
+ }
138
+
139
+ // Handle plain number arrays
140
+ if (Array.isArray(bytes)) {
141
+ return new Uint8Array(bytes)
142
+ }
143
+
144
+ // Handle objects with valueOf() method that returns a number array
145
+ if (
146
+ bytes &&
147
+ typeof bytes === 'object' &&
148
+ 'valueOf' in bytes &&
149
+ typeof bytes.valueOf === 'function'
150
+ ) {
151
+ const value = bytes.valueOf()
152
+ if (Array.isArray(value)) {
153
+ return new Uint8Array(value)
154
+ }
155
+ }
156
+
157
+ throw new Error(`Cannot normalize bytes of type ${typeof bytes}: ${bytes}`)
158
+ }