goscript 0.0.37 → 0.0.39
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.
- package/compiler/analysis.go +129 -8
- package/compiler/compiler.go +4 -1
- package/compiler/composite-lit.go +2 -4
- package/compiler/expr-call.go +12 -0
- package/compiler/lit.go +100 -6
- package/compiler/protobuf.go +2 -2
- package/compiler/spec-value.go +3 -3
- package/compiler/spec.go +6 -3
- package/compiler/stmt-assign.go +1 -1
- package/dist/gs/builtin/builtin.d.ts +45 -0
- package/dist/gs/builtin/builtin.js +197 -0
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/slice.js +2 -1
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.d.ts +56 -0
- package/dist/gs/bytes/buffer.gs.js +611 -0
- package/dist/gs/bytes/buffer.gs.js.map +1 -0
- package/dist/gs/bytes/bytes.gs.d.ts +78 -0
- package/dist/gs/bytes/bytes.gs.js +1011 -0
- package/dist/gs/bytes/bytes.gs.js.map +1 -0
- package/dist/gs/bytes/index.d.ts +4 -0
- package/dist/gs/bytes/index.js +5 -0
- package/dist/gs/bytes/index.js.map +1 -0
- package/dist/gs/bytes/iter.gs.d.ts +9 -0
- package/dist/gs/bytes/iter.gs.js +143 -0
- package/dist/gs/bytes/iter.gs.js.map +1 -0
- package/dist/gs/bytes/reader.gs.d.ts +34 -0
- package/dist/gs/bytes/reader.gs.js +198 -0
- package/dist/gs/bytes/reader.gs.js.map +1 -0
- package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/errors.js +182 -23
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/go113.js +1 -1
- package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
- package/dist/gs/github.com/pkg/errors/index.js +3 -3
- package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
- package/dist/gs/github.com/pkg/errors/stack.js +8 -5
- package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
- package/dist/gs/internal/abi/index.d.ts +20 -0
- package/dist/gs/internal/abi/index.js +20 -0
- package/dist/gs/internal/abi/index.js.map +1 -0
- package/dist/gs/internal/bytealg/index.d.ts +14 -0
- package/dist/gs/internal/bytealg/index.js +139 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -0
- package/dist/gs/internal/byteorder/index.d.ts +1 -1
- package/dist/gs/internal/byteorder/index.js +4 -4
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/math/index.d.ts +44 -44
- package/dist/gs/math/index.js +44 -44
- package/dist/gs/math/index.js.map +1 -1
- package/dist/gs/os/index.d.ts +19 -19
- package/dist/gs/os/index.js +19 -19
- package/dist/gs/os/index.js.map +1 -1
- package/dist/gs/reflect/deepequal.d.ts +2 -0
- package/dist/gs/reflect/deepequal.js +91 -0
- package/dist/gs/reflect/deepequal.js.map +1 -0
- package/dist/gs/reflect/index.d.ts +8 -0
- package/dist/gs/reflect/index.js +10 -0
- package/dist/gs/reflect/index.js.map +1 -0
- package/dist/gs/reflect/iter.d.ts +4 -0
- package/dist/gs/reflect/iter.js +24 -0
- package/dist/gs/reflect/iter.js.map +1 -0
- package/dist/gs/reflect/map.d.ts +20 -0
- package/dist/gs/reflect/map.js +74 -0
- package/dist/gs/reflect/map.js.map +1 -0
- package/dist/gs/reflect/swapper.d.ts +2 -0
- package/dist/gs/reflect/swapper.js +46 -0
- package/dist/gs/reflect/swapper.js.map +1 -0
- package/dist/gs/reflect/type.d.ts +134 -0
- package/dist/gs/reflect/type.js +825 -0
- package/dist/gs/reflect/type.js.map +1 -0
- package/dist/gs/reflect/types.d.ts +90 -0
- package/dist/gs/reflect/types.js +119 -0
- package/dist/gs/reflect/types.js.map +1 -0
- package/dist/gs/reflect/value.d.ts +13 -0
- package/dist/gs/reflect/value.js +202 -0
- package/dist/gs/reflect/value.js.map +1 -0
- package/dist/gs/reflect/visiblefields.d.ts +4 -0
- package/dist/gs/reflect/visiblefields.js +149 -0
- package/dist/gs/reflect/visiblefields.js.map +1 -0
- package/dist/gs/strconv/index.d.ts +6 -6
- package/dist/gs/strconv/index.js +6 -6
- package/dist/gs/strconv/index.js.map +1 -1
- package/dist/gs/strings/index.d.ts +1 -1
- package/dist/gs/strings/index.js +1 -1
- package/dist/gs/strings/index.js.map +1 -1
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/sync/atomic/index.d.ts +4 -4
- package/dist/gs/sync/atomic/index.js +4 -4
- package/dist/gs/sync/atomic/index.js.map +1 -1
- package/dist/gs/syscall/index.d.ts +6 -6
- package/dist/gs/syscall/index.js +34 -28
- package/dist/gs/syscall/index.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +1 -1
- package/dist/gs/unicode/utf8/utf8.js +4 -2
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/dist/gs/unsafe/unsafe.js.map +1 -1
- package/gs/builtin/builtin.ts +219 -0
- package/gs/builtin/slice.ts +2 -1
- package/gs/bytes/buffer.gs.ts +614 -0
- package/gs/bytes/bytes.gs.ts +1180 -0
- package/gs/bytes/godoc.txt +69 -0
- package/gs/bytes/index.ts +69 -0
- package/gs/bytes/iter.gs.ts +149 -0
- package/gs/bytes/reader.gs.ts +230 -0
- package/gs/github.com/pkg/errors/errors.ts +408 -238
- package/gs/github.com/pkg/errors/go113.ts +5 -6
- package/gs/github.com/pkg/errors/index.ts +12 -3
- package/gs/github.com/pkg/errors/stack.ts +107 -105
- package/gs/internal/abi/index.ts +37 -0
- package/gs/internal/bytealg/index.ts +149 -0
- package/gs/internal/byteorder/index.ts +5 -5
- package/gs/math/abs.gs.test.ts +1 -1
- package/gs/math/acosh.gs.test.ts +4 -2
- package/gs/math/asin.gs.test.ts +1 -1
- package/gs/math/asinh.gs.test.ts +7 -3
- package/gs/math/atan.gs.test.ts +1 -1
- package/gs/math/atan2.gs.test.ts +17 -9
- package/gs/math/atanh.gs.test.ts +1 -1
- package/gs/math/bits.gs.test.ts +1 -1
- package/gs/math/cbrt.gs.test.ts +1 -1
- package/gs/math/const.gs.test.ts +34 -8
- package/gs/math/copysign.gs.test.ts +7 -3
- package/gs/math/dim.gs.test.ts +19 -7
- package/gs/math/erf.gs.test.ts +1 -1
- package/gs/math/erfinv.gs.test.ts +4 -2
- package/gs/math/exp.gs.test.ts +1 -1
- package/gs/math/expm1.gs.test.ts +6 -4
- package/gs/math/floor.gs.test.ts +17 -4
- package/gs/math/fma.gs.test.ts +53 -53
- package/gs/math/frexp.gs.test.ts +112 -117
- package/gs/math/gamma.gs.test.ts +1 -1
- package/gs/math/hypot.gs.test.ts +53 -53
- package/gs/math/index.ts +80 -44
- package/gs/math/j0.gs.test.ts +6 -2
- package/gs/math/j1.gs.test.ts +6 -2
- package/gs/math/jn.gs.test.ts +9 -5
- package/gs/math/ldexp.gs.test.ts +103 -86
- package/gs/math/lgamma.gs.test.ts +10 -10
- package/gs/math/log.gs.test.ts +1 -1
- package/gs/math/log10.gs.test.ts +1 -1
- package/gs/math/log1p.gs.test.ts +2 -2
- package/gs/math/logb.gs.test.ts +1 -1
- package/gs/math/mod.gs.test.ts +2 -2
- package/gs/math/modf.gs.test.ts +7 -7
- package/gs/math/nextafter.gs.test.ts +9 -7
- package/gs/math/pow.gs.test.ts +6 -4
- package/gs/math/pow10.gs.test.ts +1 -1
- package/gs/math/remainder.gs.test.ts +1 -1
- package/gs/math/signbit.gs.test.ts +1 -1
- package/gs/math/sin.gs.test.ts +1 -1
- package/gs/math/sincos.gs.test.ts +33 -14
- package/gs/math/sinh.gs.test.ts +1 -1
- package/gs/math/sqrt.gs.test.ts +1 -1
- package/gs/math/tan.gs.test.ts +3 -3
- package/gs/math/tanh.gs.test.ts +1 -1
- package/gs/os/index.ts +128 -19
- package/gs/reflect/ANALYSIS.md +278 -0
- package/gs/reflect/deepequal.test.ts +41 -0
- package/gs/reflect/deepequal.ts +169 -0
- package/gs/reflect/function-types.test.ts +146 -0
- package/gs/reflect/godoc.txt +67 -0
- package/gs/reflect/index.ts +83 -0
- package/gs/reflect/iter.ts +44 -0
- package/gs/reflect/map.test.ts +30 -0
- package/gs/reflect/map.ts +85 -0
- package/gs/reflect/swapper.ts +52 -0
- package/gs/reflect/type.ts +1016 -0
- package/gs/reflect/types.ts +214 -0
- package/gs/reflect/value.ts +270 -0
- package/gs/reflect/visiblefields.ts +177 -0
- package/gs/strconv/index.ts +39 -6
- package/gs/strings/index.ts +7 -1
- package/gs/strings/replace.ts +1 -9
- package/gs/sync/atomic/index.ts +53 -4
- package/gs/syscall/index.ts +45 -37
- package/gs/unicode/utf8/utf8.ts +8 -5
- package/gs/unsafe/unsafe.ts +1 -1
- package/package.json +2 -1
- package/dist/gs/internal/testlog/index.d.ts +0 -1
- package/dist/gs/internal/testlog/index.js +0 -5
- package/dist/gs/internal/testlog/index.js.map +0 -1
- package/dist/gs/maps/iter.gs.d.ts +0 -7
- package/dist/gs/maps/iter.gs.js +0 -65
- package/dist/gs/maps/iter.gs.js.map +0 -1
- package/dist/gs/maps/maps.gs.d.ts +0 -7
- package/dist/gs/maps/maps.gs.js +0 -79
- package/dist/gs/maps/maps.gs.js.map +0 -1
- package/dist/gs/stringslite/index.d.ts +0 -1
- package/dist/gs/stringslite/index.js +0 -2
- package/dist/gs/stringslite/index.js.map +0 -1
- package/dist/gs/stringslite/strings.d.ts +0 -11
- package/dist/gs/stringslite/strings.js +0 -67
- package/dist/gs/stringslite/strings.js.map +0 -1
- package/gs/internal/testlog/index.ts +0 -7
package/gs/builtin/builtin.ts
CHANGED
|
@@ -209,3 +209,222 @@ export function sortSlice<T extends string | number>(s: Slice<T>): void {
|
|
|
209
209
|
return
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* bytesEqual efficiently compares two byte slices for equality.
|
|
215
|
+
* Optimized for different byte representations.
|
|
216
|
+
*/
|
|
217
|
+
export function bytesEqual(a: Bytes | null, b: Bytes | null): boolean {
|
|
218
|
+
// Handle null cases
|
|
219
|
+
if (a === null && b === null) return true
|
|
220
|
+
if (a === null || b === null) return false
|
|
221
|
+
|
|
222
|
+
// Convert to arrays for comparison
|
|
223
|
+
const aArr = bytesToArray(a)
|
|
224
|
+
const bArr = bytesToArray(b)
|
|
225
|
+
|
|
226
|
+
if (aArr.length !== bArr.length) return false
|
|
227
|
+
|
|
228
|
+
for (let i = 0; i < aArr.length; i++) {
|
|
229
|
+
if (aArr[i] !== bArr[i]) return false
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return true
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* bytesCompare compares two byte slices lexicographically.
|
|
237
|
+
* Returns -1 if a < b, 0 if a == b, +1 if a > b.
|
|
238
|
+
*/
|
|
239
|
+
export function bytesCompare(a: Bytes | null, b: Bytes | null): number {
|
|
240
|
+
// Handle null cases
|
|
241
|
+
if (a === null && b === null) return 0
|
|
242
|
+
if (a === null) return -1
|
|
243
|
+
if (b === null) return 1
|
|
244
|
+
|
|
245
|
+
const aArr = bytesToArray(a)
|
|
246
|
+
const bArr = bytesToArray(b)
|
|
247
|
+
|
|
248
|
+
const minLen = Math.min(aArr.length, bArr.length)
|
|
249
|
+
|
|
250
|
+
for (let i = 0; i < minLen; i++) {
|
|
251
|
+
if (aArr[i] < bArr[i]) return -1
|
|
252
|
+
if (aArr[i] > bArr[i]) return 1
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (aArr.length < bArr.length) return -1
|
|
256
|
+
if (aArr.length > bArr.length) return 1
|
|
257
|
+
return 0
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* bytesToArray converts any Bytes representation to a number array.
|
|
262
|
+
*/
|
|
263
|
+
export function bytesToArray(bytes: Bytes | null): number[] {
|
|
264
|
+
if (bytes === null) return []
|
|
265
|
+
|
|
266
|
+
if (bytes instanceof Uint8Array) {
|
|
267
|
+
return Array.from(bytes)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (Array.isArray(bytes)) {
|
|
271
|
+
return bytes
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Handle SliceProxy
|
|
275
|
+
if (isSliceProxy(bytes)) {
|
|
276
|
+
const proxy = bytes as SliceProxy<number>
|
|
277
|
+
const meta = proxy.__meta__
|
|
278
|
+
return meta.backing.slice(meta.offset, meta.offset + meta.length)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
throw new Error(`Cannot convert bytes of type ${typeof bytes} to array`)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* bytesToUint8Array converts any Bytes representation to a Uint8Array.
|
|
286
|
+
*/
|
|
287
|
+
export function bytesToUint8Array(bytes: Bytes | null): Uint8Array {
|
|
288
|
+
if (bytes === null) return new Uint8Array(0)
|
|
289
|
+
|
|
290
|
+
if (bytes instanceof Uint8Array) {
|
|
291
|
+
return bytes
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return new Uint8Array(bytesToArray(bytes))
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* bytesIndexOf finds the first occurrence of subslice in bytes.
|
|
299
|
+
* Returns -1 if not found.
|
|
300
|
+
*/
|
|
301
|
+
export function bytesIndexOf(
|
|
302
|
+
bytes: Bytes | null,
|
|
303
|
+
subslice: Bytes | null,
|
|
304
|
+
): number {
|
|
305
|
+
if (bytes === null || subslice === null) return -1
|
|
306
|
+
|
|
307
|
+
const haystack = bytesToArray(bytes)
|
|
308
|
+
const needle = bytesToArray(subslice)
|
|
309
|
+
|
|
310
|
+
if (needle.length === 0) return 0
|
|
311
|
+
if (needle.length > haystack.length) return -1
|
|
312
|
+
|
|
313
|
+
for (let i = 0; i <= haystack.length - needle.length; i++) {
|
|
314
|
+
let found = true
|
|
315
|
+
for (let j = 0; j < needle.length; j++) {
|
|
316
|
+
if (haystack[i + j] !== needle[j]) {
|
|
317
|
+
found = false
|
|
318
|
+
break
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (found) return i
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return -1
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* bytesLastIndexOf finds the last occurrence of subslice in bytes.
|
|
329
|
+
* Returns -1 if not found.
|
|
330
|
+
*/
|
|
331
|
+
export function bytesLastIndexOf(
|
|
332
|
+
bytes: Bytes | null,
|
|
333
|
+
subslice: Bytes | null,
|
|
334
|
+
): number {
|
|
335
|
+
if (bytes === null || subslice === null) return -1
|
|
336
|
+
|
|
337
|
+
const haystack = bytesToArray(bytes)
|
|
338
|
+
const needle = bytesToArray(subslice)
|
|
339
|
+
|
|
340
|
+
if (needle.length === 0) return haystack.length
|
|
341
|
+
if (needle.length > haystack.length) return -1
|
|
342
|
+
|
|
343
|
+
for (let i = haystack.length - needle.length; i >= 0; i--) {
|
|
344
|
+
let found = true
|
|
345
|
+
for (let j = 0; j < needle.length; j++) {
|
|
346
|
+
if (haystack[i + j] !== needle[j]) {
|
|
347
|
+
found = false
|
|
348
|
+
break
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (found) return i
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return -1
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* bytesIndexByte finds the first occurrence of byte c in bytes.
|
|
359
|
+
* Returns -1 if not found.
|
|
360
|
+
*/
|
|
361
|
+
export function bytesIndexByte(bytes: Bytes | null, c: number): number {
|
|
362
|
+
if (bytes === null) return -1
|
|
363
|
+
|
|
364
|
+
const arr = bytesToArray(bytes)
|
|
365
|
+
return arr.indexOf(c)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* bytesLastIndexByte finds the last occurrence of byte c in bytes.
|
|
370
|
+
* Returns -1 if not found.
|
|
371
|
+
*/
|
|
372
|
+
export function bytesLastIndexByte(bytes: Bytes | null, c: number): number {
|
|
373
|
+
if (bytes === null) return -1
|
|
374
|
+
|
|
375
|
+
const arr = bytesToArray(bytes)
|
|
376
|
+
return arr.lastIndexOf(c)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* bytesCount counts non-overlapping instances of sep in bytes.
|
|
381
|
+
*/
|
|
382
|
+
export function bytesCount(bytes: Bytes | null, sep: Bytes | null): number {
|
|
383
|
+
if (bytes === null || sep === null) return 0
|
|
384
|
+
|
|
385
|
+
const haystack = bytesToArray(bytes)
|
|
386
|
+
const needle = bytesToArray(sep)
|
|
387
|
+
|
|
388
|
+
if (needle.length === 0) {
|
|
389
|
+
// Special case: empty separator counts code points + 1
|
|
390
|
+
// For now, just return length + 1 (ASCII assumption)
|
|
391
|
+
return haystack.length + 1
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
let count = 0
|
|
395
|
+
let pos = 0
|
|
396
|
+
|
|
397
|
+
while (pos <= haystack.length - needle.length) {
|
|
398
|
+
let found = true
|
|
399
|
+
for (let i = 0; i < needle.length; i++) {
|
|
400
|
+
if (haystack[pos + i] !== needle[i]) {
|
|
401
|
+
found = false
|
|
402
|
+
break
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (found) {
|
|
406
|
+
count++
|
|
407
|
+
pos += needle.length
|
|
408
|
+
} else {
|
|
409
|
+
pos++
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return count
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Math functions needed by various packages
|
|
417
|
+
export function min(a: number, b: number): number {
|
|
418
|
+
return Math.min(a, b)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export function max(a: number, b: number): number {
|
|
422
|
+
return Math.max(a, b)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Panic recovery function (simplified implementation)
|
|
426
|
+
export function recover(): any {
|
|
427
|
+
// In a real implementation, this would interact with Go's panic/recover mechanism
|
|
428
|
+
// For now, return null to indicate no panic was recovered
|
|
429
|
+
return null
|
|
430
|
+
}
|
package/gs/builtin/slice.ts
CHANGED
|
@@ -1041,7 +1041,8 @@ export const sliceString = (
|
|
|
1041
1041
|
// Attempt to decode with strict UTF-8 validation
|
|
1042
1042
|
const result = new TextDecoder('utf-8', { fatal: true }).decode(slicedBytes)
|
|
1043
1043
|
return result
|
|
1044
|
-
|
|
1044
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1045
|
+
} catch (_e) {
|
|
1045
1046
|
// If we get here, the slice would create invalid UTF-8
|
|
1046
1047
|
// This is a fundamental limitation of JavaScript string handling
|
|
1047
1048
|
throw new Error(
|