goscript 0.0.41 → 0.0.43
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 +260 -2
- package/compiler/assignment.go +6 -0
- package/compiler/compiler.go +98 -8
- package/compiler/decl.go +42 -20
- package/compiler/expr-call.go +37 -1
- package/compiler/expr-type.go +20 -0
- package/compiler/lit.go +4 -20
- package/compiler/spec-struct.go +3 -4
- package/compiler/spec-value.go +18 -1
- package/compiler/spec.go +15 -8
- package/compiler/stmt-range.go +1 -1
- package/compiler/stmt.go +118 -17
- package/compiler/type-assert.go +4 -4
- package/compiler/type.go +63 -5
- package/dist/gs/builtin/map.d.ts +4 -4
- package/dist/gs/builtin/map.js +6 -3
- package/dist/gs/builtin/map.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +7 -0
- package/dist/gs/builtin/slice.js +12 -0
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.js +8 -70
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +22 -21
- package/dist/gs/fmt/fmt.js +12 -12
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/internal/testlog/index.d.ts +1 -0
- package/dist/gs/internal/testlog/index.js +5 -0
- package/dist/gs/internal/testlog/index.js.map +1 -0
- package/dist/gs/io/io.d.ts +13 -13
- package/dist/gs/io/io.js +31 -21
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/maps/iter.gs.d.ts +7 -0
- package/dist/gs/maps/iter.gs.js +65 -0
- package/dist/gs/maps/iter.gs.js.map +1 -0
- package/dist/gs/maps/maps.gs.d.ts +7 -0
- package/dist/gs/maps/maps.gs.js +79 -0
- package/dist/gs/maps/maps.gs.js.map +1 -0
- package/dist/gs/path/filepath/match.d.ts +4 -3
- package/dist/gs/path/filepath/match.js +2 -2
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +2 -2
- package/dist/gs/path/filepath/path.js +3 -3
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/reflect/abi.d.ts +59 -0
- package/dist/gs/reflect/abi.gs.d.ts +59 -0
- package/dist/gs/reflect/abi.gs.js +79 -0
- package/dist/gs/reflect/abi.gs.js.map +1 -0
- package/dist/gs/reflect/abi.js +79 -0
- package/dist/gs/reflect/abi.js.map +1 -0
- package/dist/gs/reflect/badlinkname.d.ts +52 -0
- package/dist/gs/reflect/badlinkname.gs.d.ts +52 -0
- package/dist/gs/reflect/badlinkname.gs.js +72 -0
- package/dist/gs/reflect/badlinkname.gs.js.map +1 -0
- package/dist/gs/reflect/badlinkname.js +72 -0
- package/dist/gs/reflect/badlinkname.js.map +1 -0
- package/dist/gs/reflect/deepequal.gs.d.ts +25 -0
- package/dist/gs/reflect/deepequal.gs.js +308 -0
- package/dist/gs/reflect/deepequal.gs.js.map +1 -0
- package/dist/gs/reflect/float32reg_generic.gs.d.ts +2 -0
- package/dist/gs/reflect/float32reg_generic.gs.js +10 -0
- package/dist/gs/reflect/float32reg_generic.gs.js.map +1 -0
- package/dist/gs/reflect/index.gs.d.ts +1 -0
- package/dist/gs/reflect/index.gs.js +3 -0
- package/dist/gs/reflect/index.gs.js.map +1 -0
- package/dist/gs/reflect/iter.gs.d.ts +3 -0
- package/dist/gs/reflect/iter.gs.js +24 -0
- package/dist/gs/reflect/iter.gs.js.map +1 -0
- package/dist/gs/reflect/makefunc.gs.d.ts +34 -0
- package/dist/gs/reflect/makefunc.gs.js +288 -0
- package/dist/gs/reflect/makefunc.gs.js.map +1 -0
- package/dist/gs/reflect/map_swiss.gs.d.ts +14 -0
- package/dist/gs/reflect/map_swiss.gs.js +70 -0
- package/dist/gs/reflect/map_swiss.gs.js.map +1 -0
- package/dist/gs/reflect/reflect.gs.d.ts +132 -0
- package/dist/gs/reflect/reflect.gs.js +437 -0
- package/dist/gs/reflect/reflect.gs.js.map +1 -0
- package/dist/gs/reflect/swapper.gs.d.ts +1 -0
- package/dist/gs/reflect/swapper.gs.js +32 -0
- package/dist/gs/reflect/swapper.gs.js.map +1 -0
- package/dist/gs/reflect/type.gs.d.ts +4 -0
- package/dist/gs/reflect/type.gs.js +21 -0
- package/dist/gs/reflect/type.gs.js.map +1 -0
- package/dist/gs/reflect/value.gs.d.ts +4 -0
- package/dist/gs/reflect/value.gs.js +12 -0
- package/dist/gs/reflect/value.gs.js.map +1 -0
- package/dist/gs/reflect/visiblefields.gs.d.ts +3 -0
- package/dist/gs/reflect/visiblefields.gs.js +123 -0
- package/dist/gs/reflect/visiblefields.gs.js.map +1 -0
- package/dist/gs/strings/reader.d.ts +1 -1
- package/dist/gs/strings/reader.js.map +1 -1
- package/dist/gs/stringslite/index.d.ts +1 -0
- package/dist/gs/stringslite/index.js +2 -0
- package/dist/gs/stringslite/index.js.map +1 -0
- package/dist/gs/stringslite/strings.d.ts +11 -0
- package/dist/gs/stringslite/strings.js +67 -0
- package/dist/gs/stringslite/strings.js.map +1 -0
- package/dist/gs/time/time.d.ts +69 -0
- package/dist/gs/time/time.js +350 -0
- package/dist/gs/time/time.js.map +1 -1
- package/gs/builtin/map.ts +12 -8
- package/gs/builtin/slice.ts +13 -0
- package/gs/builtin/type.ts +8 -100
- package/gs/fmt/fmt.ts +33 -33
- package/gs/io/io.ts +47 -39
- package/gs/path/filepath/match.ts +4 -4
- package/gs/path/filepath/path.ts +3 -3
- package/gs/strings/reader.ts +1 -1
- package/gs/time/time.ts +403 -0
- package/package.json +1 -1
package/gs/io/io.ts
CHANGED
|
@@ -41,12 +41,12 @@ export const SeekEnd = 2 // seek relative to the end
|
|
|
41
41
|
|
|
42
42
|
// Reader is the interface that wraps the basic Read method
|
|
43
43
|
export interface Reader {
|
|
44
|
-
Read(p:
|
|
44
|
+
Read(p: $.Bytes): [number, $.GoError]
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// Writer is the interface that wraps the basic Write method
|
|
48
48
|
export interface Writer {
|
|
49
|
-
Write(p:
|
|
49
|
+
Write(p: $.Bytes): [number, $.GoError]
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Closer is the interface that wraps the basic Close method
|
|
@@ -70,12 +70,12 @@ export interface ReadWriteSeeker extends Reader, Writer, Seeker {}
|
|
|
70
70
|
|
|
71
71
|
// ReaderAt is the interface that wraps the basic ReadAt method
|
|
72
72
|
export interface ReaderAt {
|
|
73
|
-
ReadAt(p:
|
|
73
|
+
ReadAt(p: $.Bytes, off: number): [number, $.GoError]
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// WriterAt is the interface that wraps the basic WriteAt method
|
|
77
77
|
export interface WriterAt {
|
|
78
|
-
WriteAt(p:
|
|
78
|
+
WriteAt(p: $.Bytes, off: number): [number, $.GoError]
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// ByteReader is the interface that wraps the ReadByte method
|
|
@@ -120,8 +120,8 @@ export interface ReaderFrom {
|
|
|
120
120
|
|
|
121
121
|
// Discard is a Writer on which all Write calls succeed without doing anything
|
|
122
122
|
class DiscardWriter implements Writer {
|
|
123
|
-
Write(p:
|
|
124
|
-
return [p
|
|
123
|
+
Write(p: $.Bytes): [number, $.GoError] {
|
|
124
|
+
return [$.len(p), null]
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -149,14 +149,14 @@ export class LimitedReader implements Reader {
|
|
|
149
149
|
this.N = n
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
Read(p:
|
|
152
|
+
Read(p: $.Bytes): [number, $.GoError] {
|
|
153
153
|
if (this.N <= 0) {
|
|
154
154
|
return [0, EOF]
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
let readBuf = p
|
|
158
|
-
if (p
|
|
159
|
-
readBuf = p
|
|
158
|
+
if ($.len(p) > this.N) {
|
|
159
|
+
readBuf = $.goSlice(p, 0, this.N)
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
const [n, err] = this.R.Read(readBuf)
|
|
@@ -184,14 +184,14 @@ export class SectionReader implements Reader, Seeker, ReaderAt {
|
|
|
184
184
|
this.limit = off + n
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
Read(p:
|
|
187
|
+
Read(p: $.Bytes): [number, $.GoError] {
|
|
188
188
|
if (this.off >= this.limit) {
|
|
189
189
|
return [0, EOF]
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
let max = this.limit - this.off
|
|
193
|
-
if (p
|
|
194
|
-
p = p
|
|
193
|
+
if ($.len(p) > max) {
|
|
194
|
+
p = $.goSlice(p, 0, max)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
const [n, err] = this.r.ReadAt(p, this.off)
|
|
@@ -223,14 +223,14 @@ export class SectionReader implements Reader, Seeker, ReaderAt {
|
|
|
223
223
|
return [abs - this.base, null]
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
ReadAt(p:
|
|
226
|
+
ReadAt(p: $.Bytes, off: number): [number, $.GoError] {
|
|
227
227
|
if (off < 0 || off >= this.limit - this.base) {
|
|
228
228
|
return [0, EOF]
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
off += this.base
|
|
232
|
-
if (off + p
|
|
233
|
-
p = p
|
|
232
|
+
if (off + $.len(p) > this.limit) {
|
|
233
|
+
p = $.goSlice(p, 0, this.limit - off)
|
|
234
234
|
const [n, err] = this.r.ReadAt(p, off)
|
|
235
235
|
if (err === null) {
|
|
236
236
|
return [n, EOF]
|
|
@@ -267,13 +267,13 @@ export class OffsetWriter implements Writer, WriterAt {
|
|
|
267
267
|
this.off = 0
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
Write(p:
|
|
270
|
+
Write(p: $.Bytes): [number, $.GoError] {
|
|
271
271
|
const [n, err] = this.w.WriteAt(p, this.base + this.off)
|
|
272
272
|
this.off += n
|
|
273
273
|
return [n, err]
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
WriteAt(p:
|
|
276
|
+
WriteAt(p: $.Bytes, off: number): [number, $.GoError] {
|
|
277
277
|
if (off < 0) {
|
|
278
278
|
return [0, newError('io.OffsetWriter.WriteAt: negative offset')]
|
|
279
279
|
}
|
|
@@ -316,7 +316,7 @@ export function Copy(dst: Writer, src: Reader): [number, $.GoError] {
|
|
|
316
316
|
export function CopyBuffer(
|
|
317
317
|
dst: Writer,
|
|
318
318
|
src: Reader,
|
|
319
|
-
buf:
|
|
319
|
+
buf: $.Bytes | null,
|
|
320
320
|
): [number, $.GoError] {
|
|
321
321
|
// If src implements WriterTo, use it
|
|
322
322
|
if ('WriteTo' in src && typeof (src as any).WriteTo === 'function') {
|
|
@@ -329,14 +329,14 @@ export function CopyBuffer(
|
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
if (buf === null) {
|
|
332
|
-
buf =
|
|
332
|
+
buf = $.makeSlice<number>(32 * 1024, undefined, 'byte') // 32KB default buffer
|
|
333
333
|
}
|
|
334
334
|
|
|
335
335
|
let written = 0
|
|
336
336
|
while (true) {
|
|
337
337
|
const [nr, er] = src.Read(buf)
|
|
338
338
|
if (nr > 0) {
|
|
339
|
-
const [nw, ew] = dst.Write(buf
|
|
339
|
+
const [nw, ew] = dst.Write($.goSlice(buf, 0, nr))
|
|
340
340
|
if (nw < 0 || nr < nw) {
|
|
341
341
|
if (ew === null) {
|
|
342
342
|
return [written, ErrShortWrite]
|
|
@@ -381,16 +381,16 @@ export function CopyN(
|
|
|
381
381
|
// ReadAtLeast reads from r into buf until it has read at least min bytes
|
|
382
382
|
export function ReadAtLeast(
|
|
383
383
|
r: Reader,
|
|
384
|
-
buf:
|
|
384
|
+
buf: $.Bytes,
|
|
385
385
|
min: number,
|
|
386
386
|
): [number, $.GoError] {
|
|
387
|
-
if (buf
|
|
387
|
+
if ($.len(buf) < min) {
|
|
388
388
|
return [0, ErrShortBuffer]
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
let n = 0
|
|
392
392
|
while (n < min) {
|
|
393
|
-
const [nn, err] = r.Read(buf
|
|
393
|
+
const [nn, err] = r.Read($.goSlice(buf, n))
|
|
394
394
|
n += nn
|
|
395
395
|
if (err !== null) {
|
|
396
396
|
if (err === EOF && n >= min) {
|
|
@@ -406,36 +406,44 @@ export function ReadAtLeast(
|
|
|
406
406
|
}
|
|
407
407
|
|
|
408
408
|
// ReadFull reads exactly len(buf) bytes from r into buf
|
|
409
|
-
export function ReadFull(r: Reader, buf:
|
|
410
|
-
return ReadAtLeast(r, buf, buf
|
|
409
|
+
export function ReadFull(r: Reader, buf: $.Bytes): [number, $.GoError] {
|
|
410
|
+
return ReadAtLeast(r, buf, $.len(buf))
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
// ReadAll reads from r until an error or EOF and returns the data it read
|
|
414
|
-
export function ReadAll(r: Reader): [
|
|
415
|
-
const chunks:
|
|
414
|
+
export function ReadAll(r: Reader): [$.Bytes, $.GoError] {
|
|
415
|
+
const chunks: $.Bytes[] = []
|
|
416
416
|
let totalLength = 0
|
|
417
|
-
const buf =
|
|
417
|
+
const buf = $.makeSlice<number>(512, undefined, 'byte')
|
|
418
418
|
|
|
419
419
|
while (true) {
|
|
420
420
|
const [n, err] = r.Read(buf)
|
|
421
421
|
if (n > 0) {
|
|
422
|
-
chunks.push(buf
|
|
422
|
+
chunks.push($.goSlice(buf, 0, n))
|
|
423
423
|
totalLength += n
|
|
424
424
|
}
|
|
425
425
|
if (err !== null) {
|
|
426
426
|
if (err === EOF) {
|
|
427
427
|
break
|
|
428
428
|
}
|
|
429
|
-
return [
|
|
429
|
+
return [$.makeSlice<number>(0, undefined, 'byte'), err]
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
// Combine all chunks
|
|
434
|
-
const result =
|
|
434
|
+
const result = $.makeSlice<number>(totalLength, undefined, 'byte')
|
|
435
435
|
let offset = 0
|
|
436
436
|
for (const chunk of chunks) {
|
|
437
|
-
|
|
438
|
-
|
|
437
|
+
if (chunk instanceof Uint8Array) {
|
|
438
|
+
// Handle Uint8Array chunks
|
|
439
|
+
const resultSlice = $.goSlice(result, offset, offset + chunk.length)
|
|
440
|
+
$.copy(resultSlice, chunk)
|
|
441
|
+
} else {
|
|
442
|
+
// Handle Slice<number> chunks
|
|
443
|
+
const resultSlice = $.goSlice(result, offset, offset + $.len(chunk))
|
|
444
|
+
$.copy(resultSlice, chunk)
|
|
445
|
+
}
|
|
446
|
+
offset += $.len(chunk)
|
|
439
447
|
}
|
|
440
448
|
|
|
441
449
|
return [result, null]
|
|
@@ -461,7 +469,7 @@ class multiReader implements Reader {
|
|
|
461
469
|
this.readers = readers
|
|
462
470
|
}
|
|
463
471
|
|
|
464
|
-
Read(p:
|
|
472
|
+
Read(p: $.Bytes): [number, $.GoError] {
|
|
465
473
|
while (this.readers.length > 0) {
|
|
466
474
|
if (this.readers.length === 1) {
|
|
467
475
|
// Optimization for single reader
|
|
@@ -502,17 +510,17 @@ class multiWriter implements Writer {
|
|
|
502
510
|
this.writers = writers
|
|
503
511
|
}
|
|
504
512
|
|
|
505
|
-
Write(p:
|
|
513
|
+
Write(p: $.Bytes): [number, $.GoError] {
|
|
506
514
|
for (const w of this.writers) {
|
|
507
515
|
const [n, err] = w.Write(p)
|
|
508
516
|
if (err !== null) {
|
|
509
517
|
return [n, err]
|
|
510
518
|
}
|
|
511
|
-
if (n !== p
|
|
519
|
+
if (n !== $.len(p)) {
|
|
512
520
|
return [n, ErrShortWrite]
|
|
513
521
|
}
|
|
514
522
|
}
|
|
515
|
-
return [p
|
|
523
|
+
return [$.len(p), null]
|
|
516
524
|
}
|
|
517
525
|
}
|
|
518
526
|
|
|
@@ -530,10 +538,10 @@ class teeReader implements Reader {
|
|
|
530
538
|
this.w = w
|
|
531
539
|
}
|
|
532
540
|
|
|
533
|
-
Read(p:
|
|
541
|
+
Read(p: $.Bytes): [number, $.GoError] {
|
|
534
542
|
const [n, err] = this.r.Read(p)
|
|
535
543
|
if (n > 0) {
|
|
536
|
-
const [nw, ew] = this.w.Write(p
|
|
544
|
+
const [nw, ew] = this.w.Write($.goSlice(p, 0, n))
|
|
537
545
|
if (ew !== null) {
|
|
538
546
|
return [n, ew]
|
|
539
547
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
2
|
|
|
3
|
-
export const ErrBadPattern =
|
|
3
|
+
export const ErrBadPattern = $.newError('syntax error in pattern')
|
|
4
4
|
|
|
5
5
|
// Match reports whether name matches the shell file name pattern.
|
|
6
6
|
// The pattern syntax is:
|
|
@@ -23,7 +23,7 @@ export const ErrBadPattern = new Error('syntax error in pattern')
|
|
|
23
23
|
// Match requires pattern to match all of name, not just a substring.
|
|
24
24
|
// The only possible returned error is ErrBadPattern, when pattern
|
|
25
25
|
// is malformed.
|
|
26
|
-
export function Match(pattern: string, name: string): [boolean,
|
|
26
|
+
export function Match(pattern: string, name: string): [boolean, $.GoError] {
|
|
27
27
|
try {
|
|
28
28
|
// Validate pattern first
|
|
29
29
|
validatePattern(pattern)
|
|
@@ -236,7 +236,7 @@ function matchCharClass(
|
|
|
236
236
|
//
|
|
237
237
|
// Glob ignores file system errors such as I/O errors reading directories.
|
|
238
238
|
// The only possible returned error is ErrBadPattern, when pattern is malformed.
|
|
239
|
-
export function Glob(pattern: string): [string[],
|
|
239
|
+
export function Glob(pattern: string): [string[], $.GoError] {
|
|
240
240
|
try {
|
|
241
241
|
// Validate the pattern using the same logic as Match
|
|
242
242
|
validatePattern(pattern)
|
package/gs/path/filepath/path.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import * as $ from "@goscript/builtin/index.js"
|
|
4
4
|
|
|
5
5
|
// Path separator constants
|
|
6
|
-
export const Separator = '/'
|
|
7
|
-
export const ListSeparator = ':'
|
|
6
|
+
export const Separator = $.stringToRune('/')
|
|
7
|
+
export const ListSeparator = $.stringToRune(':')
|
|
8
8
|
|
|
9
9
|
// Error constants
|
|
10
10
|
export const SkipDir = $.newError('skip this directory')
|
|
@@ -234,7 +234,7 @@ export function SplitList(path: string): string[] {
|
|
|
234
234
|
if (path === '') {
|
|
235
235
|
return []
|
|
236
236
|
}
|
|
237
|
-
return path.split(ListSeparator)
|
|
237
|
+
return path.split(String.fromCharCode(ListSeparator))
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
// HasPrefix tests whether the path p begins with prefix.
|
package/gs/strings/reader.ts
CHANGED
|
@@ -72,7 +72,7 @@ export class Reader {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Read implements the [io.Reader] interface.
|
|
75
|
-
public Read(b:
|
|
75
|
+
public Read(b: $.Bytes): [number, $.GoError] {
|
|
76
76
|
const r = this
|
|
77
77
|
if (r!.i >= ($.len(r!.s) as number)) {
|
|
78
78
|
return [0, io.EOF]
|