goscript 0.2.6 → 0.2.7
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/cmd/goscript/cmd-compile.go +7 -0
- package/cmd/goscript/cmd_compile_test.go +83 -0
- package/compiler/compile-request.go +3 -0
- package/compiler/compiler-cache.go +828 -0
- package/compiler/compiler-cache_test.go +705 -0
- package/compiler/config.go +2 -0
- package/compiler/index.test.ts +26 -1
- package/compiler/index.ts +5 -0
- package/compiler/lowered-program.go +31 -20
- package/compiler/lowering.go +349 -93
- package/compiler/lowering_bench_test.go +1 -0
- package/compiler/override-facts.go +309 -8
- package/compiler/override-parity-verifier.go +45 -1
- package/compiler/override-parity-verifier_test.go +100 -0
- package/compiler/override-registry_test.go +1 -0
- package/compiler/package-graph.go +40 -12
- package/compiler/package-graph_test.go +29 -0
- package/compiler/runtime-contract.go +8 -0
- package/compiler/service.go +98 -11
- package/compiler/skeleton_test.go +110 -14
- package/compiler/typescript-emitter.go +120 -23
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/index.js +3 -0
- package/dist/compiler/index.js.map +1 -1
- package/dist/gs/builtin/builtin.d.ts +24 -33
- package/dist/gs/builtin/builtin.js +54 -61
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/hostio.d.ts +1 -0
- package/dist/gs/builtin/hostio.js +1 -1
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/index.d.ts +1 -0
- package/dist/gs/builtin/index.js +1 -0
- package/dist/gs/builtin/index.js.map +1 -1
- package/dist/gs/builtin/panic.d.ts +18 -0
- package/dist/gs/builtin/panic.js +98 -0
- package/dist/gs/builtin/panic.js.map +1 -0
- package/dist/gs/builtin/slice.d.ts +10 -0
- package/dist/gs/builtin/slice.js +110 -53
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.js +15 -3
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +1 -1
- package/dist/gs/builtin/varRef.js +3 -2
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/bytes.gs.js +51 -38
- package/dist/gs/bytes/bytes.gs.js.map +1 -1
- package/dist/gs/bytes/reader.gs.d.ts +1 -1
- package/dist/gs/bytes/reader.gs.js +6 -7
- package/dist/gs/bytes/reader.gs.js.map +1 -1
- package/dist/gs/cmp/index.d.ts +1 -1
- package/dist/gs/cmp/index.js +43 -10
- package/dist/gs/cmp/index.js.map +1 -1
- package/dist/gs/context/context.d.ts +2 -2
- package/dist/gs/context/context.js +1 -1
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/embed/index.js +1 -1
- package/dist/gs/embed/index.js.map +1 -1
- package/dist/gs/encoding/binary/index.js +201 -8
- package/dist/gs/encoding/binary/index.js.map +1 -1
- package/dist/gs/encoding/json/index.d.ts +5 -0
- package/dist/gs/encoding/json/index.js +388 -25
- package/dist/gs/encoding/json/index.js.map +1 -1
- package/dist/gs/errors/errors.js +17 -24
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.js +129 -35
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.js +1 -1
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.js.map +1 -1
- package/dist/gs/internal/bytealg/index.js +43 -8
- package/dist/gs/internal/bytealg/index.js.map +1 -1
- package/dist/gs/internal/byteorder/index.d.ts +2 -2
- package/dist/gs/internal/byteorder/index.js +2 -2
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/io/fs/format.js +2 -2
- package/dist/gs/io/fs/format.js.map +1 -1
- package/dist/gs/io/fs/fs.d.ts +1 -1
- package/dist/gs/io/fs/fs.js +1 -1
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/io/io.d.ts +21 -21
- package/dist/gs/io/io.js +49 -50
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/math/bits/index.js +26 -8
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/math/copysign.gs.js +10 -17
- package/dist/gs/math/copysign.gs.js.map +1 -1
- package/dist/gs/math/pow.gs.js +5 -0
- package/dist/gs/math/pow.gs.js.map +1 -1
- package/dist/gs/math/signbit.gs.js +6 -2
- package/dist/gs/math/signbit.gs.js.map +1 -1
- package/dist/gs/mime/index.js +1 -0
- package/dist/gs/mime/index.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +6 -6
- package/dist/gs/net/http/index.js +507 -43
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/os/stat.gs.d.ts +2 -2
- package/dist/gs/os/types.gs.d.ts +1 -1
- package/dist/gs/os/types.gs.js +1 -1
- package/dist/gs/os/types.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.d.ts +1 -1
- package/dist/gs/os/types_js.gs.js +7 -7
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.d.ts +1 -1
- package/dist/gs/os/types_unix.gs.js +1 -1
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/dist/gs/os/zero_copy_posix.gs.d.ts +1 -1
- package/dist/gs/os/zero_copy_posix.gs.js +1 -1
- package/dist/gs/os/zero_copy_posix.gs.js.map +1 -1
- package/dist/gs/path/filepath/match.js +8 -4
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.js +216 -42
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/path/match.js +6 -3
- package/dist/gs/path/match.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +5 -4
- package/dist/gs/reflect/type.js +29 -11
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/slices/slices.js +11 -11
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/strconv/atof.gs.js +156 -43
- package/dist/gs/strconv/atof.gs.js.map +1 -1
- package/dist/gs/strconv/atoi.gs.d.ts +3 -2
- package/dist/gs/strconv/atoi.gs.js +86 -67
- package/dist/gs/strconv/atoi.gs.js.map +1 -1
- package/dist/gs/strconv/ftoa.gs.js +73 -3
- package/dist/gs/strconv/ftoa.gs.js.map +1 -1
- package/dist/gs/strconv/itoa.gs.d.ts +4 -4
- package/dist/gs/strconv/itoa.gs.js +5 -4
- package/dist/gs/strconv/itoa.gs.js.map +1 -1
- package/dist/gs/strconv/quote.gs.d.ts +1 -1
- package/dist/gs/strconv/quote.gs.js +311 -103
- package/dist/gs/strconv/quote.gs.js.map +1 -1
- package/dist/gs/strings/reader.d.ts +1 -1
- package/dist/gs/strings/reader.js +8 -8
- package/dist/gs/strings/reader.js.map +1 -1
- package/dist/gs/strings/strings.js +87 -61
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/atomic/doc_64.gs.d.ts +14 -14
- package/dist/gs/sync/atomic/doc_64.gs.js +10 -10
- package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -1
- package/dist/gs/sync/atomic/type.gs.d.ts +22 -22
- package/dist/gs/sync/atomic/type.gs.js +4 -4
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/sync.js +50 -12
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +6 -6
- package/dist/gs/syscall/fs.js +1 -1
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/time/time.d.ts +18 -18
- package/dist/gs/time/time.js +58 -55
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/tables.d.ts +11 -0
- package/dist/gs/unicode/tables.js +635 -0
- package/dist/gs/unicode/tables.js.map +1 -0
- package/dist/gs/unicode/unicode.d.ts +58 -38
- package/dist/gs/unicode/unicode.js +362 -278
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/go.sum +13 -0
- package/gs/builtin/builtin.ts +83 -93
- package/gs/builtin/hostio.ts +1 -1
- package/gs/builtin/index.ts +1 -0
- package/gs/builtin/panic.test.ts +189 -0
- package/gs/builtin/panic.ts +107 -0
- package/gs/builtin/runtime-contract.test.ts +5 -5
- package/gs/builtin/slice.test.ts +23 -0
- package/gs/builtin/slice.ts +133 -95
- package/gs/builtin/type.ts +16 -3
- package/gs/builtin/varRef.ts +4 -2
- package/gs/builtin/wide-int.test.ts +41 -0
- package/gs/bytes/bytes.gs.ts +54 -41
- package/gs/bytes/bytes.test.ts +18 -1
- package/gs/bytes/reader.gs.ts +7 -8
- package/gs/cmp/index.test.ts +55 -0
- package/gs/cmp/index.ts +45 -9
- package/gs/context/context.ts +3 -3
- package/gs/embed/index.ts +2 -2
- package/gs/encoding/binary/index.test.ts +104 -0
- package/gs/encoding/binary/index.ts +259 -11
- package/gs/encoding/json/index.test.ts +107 -0
- package/gs/encoding/json/index.ts +400 -29
- package/gs/errors/errors.test.ts +44 -1
- package/gs/errors/errors.ts +15 -31
- package/gs/fmt/fmt.test.ts +70 -2
- package/gs/fmt/fmt.ts +128 -34
- package/gs/golang.org/x/crypto/cryptobyte/index.ts +1 -1
- package/gs/internal/bytealg/index.test.ts +26 -1
- package/gs/internal/bytealg/index.ts +44 -8
- package/gs/internal/byteorder/index.ts +6 -4
- package/gs/io/fs/format.ts +2 -2
- package/gs/io/fs/fs.ts +2 -2
- package/gs/io/fs/stat.test.ts +2 -2
- package/gs/io/fs/sub.test.ts +2 -2
- package/gs/io/fs/walk.test.ts +2 -2
- package/gs/io/io.test.ts +47 -5
- package/gs/io/io.ts +73 -73
- package/gs/io/limit.test.ts +103 -0
- package/gs/math/bits/index.test.ts +128 -0
- package/gs/math/bits/index.ts +26 -8
- package/gs/math/copysign.gs.test.ts +3 -1
- package/gs/math/copysign.gs.ts +10 -22
- package/gs/math/pow.gs.test.ts +4 -5
- package/gs/math/pow.gs.ts +5 -0
- package/gs/math/signbit.gs.test.ts +2 -1
- package/gs/math/signbit.gs.ts +6 -3
- package/gs/mime/index.ts +1 -0
- package/gs/net/http/index.test.ts +683 -2
- package/gs/net/http/index.ts +598 -57
- package/gs/net/http/meta.json +3 -0
- package/gs/os/stat.gs.ts +2 -2
- package/gs/os/types.gs.ts +2 -2
- package/gs/os/types_js.gs.ts +9 -9
- package/gs/os/types_unix.gs.ts +2 -2
- package/gs/os/zero_copy_posix.gs.ts +2 -2
- package/gs/path/filepath/match.test.ts +16 -0
- package/gs/path/filepath/match.ts +8 -4
- package/gs/path/filepath/path.test.ts +91 -9
- package/gs/path/filepath/path.ts +223 -49
- package/gs/path/match.test.ts +32 -0
- package/gs/path/match.ts +6 -3
- package/gs/reflect/deepequal.test.ts +1 -1
- package/gs/reflect/field.test.ts +1 -1
- package/gs/reflect/function-types.test.ts +6 -6
- package/gs/reflect/sliceat.test.ts +13 -13
- package/gs/reflect/structof.test.ts +4 -4
- package/gs/reflect/type.ts +34 -14
- package/gs/reflect/typefor.test.ts +5 -5
- package/gs/runtime/pprof/index.test.ts +20 -0
- package/gs/runtime/trace/index.test.ts +3 -0
- package/gs/slices/slices.test.ts +31 -0
- package/gs/slices/slices.ts +11 -11
- package/gs/strconv/append.test.ts +99 -0
- package/gs/strconv/atof.gs.ts +156 -42
- package/gs/strconv/atof.test.ts +45 -0
- package/gs/strconv/atoi.gs.ts +87 -69
- package/gs/strconv/atoi.test.ts +49 -0
- package/gs/strconv/ftoa.gs.ts +85 -10
- package/gs/strconv/ftoa.test.ts +43 -0
- package/gs/strconv/itoa.gs.ts +10 -9
- package/gs/strconv/quote.gs.ts +335 -108
- package/gs/strconv/quote.test.ts +111 -0
- package/gs/strings/reader.test.ts +10 -10
- package/gs/strings/reader.ts +9 -9
- package/gs/strings/strings.test.ts +18 -5
- package/gs/strings/strings.ts +81 -68
- package/gs/sync/atomic/doc_64.gs.ts +24 -24
- package/gs/sync/atomic/doc_64.test.ts +5 -5
- package/gs/sync/atomic/type.gs.ts +28 -28
- package/gs/sync/sync.test.ts +109 -1
- package/gs/sync/sync.ts +46 -12
- package/gs/syscall/fs.ts +8 -8
- package/gs/syscall/net.test.ts +1 -1
- package/gs/time/parse.test.ts +45 -0
- package/gs/time/time.test.ts +46 -23
- package/gs/time/time.ts +69 -66
- package/gs/unicode/gen.go +198 -0
- package/gs/unicode/tables.ts +646 -0
- package/gs/unicode/unicode.test.ts +69 -0
- package/gs/unicode/unicode.ts +396 -312
- package/package.json +1 -1
- package/dist/gs/github.com/aperturerobotics/util/conc/index.d.ts +0 -20
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js +0 -134
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js.map +0 -1
- package/gs/github.com/aperturerobotics/util/conc/index.test.ts +0 -30
- package/gs/github.com/aperturerobotics/util/conc/index.ts +0 -172
- package/gs/github.com/aperturerobotics/util/conc/meta.json +0 -9
package/gs/strings/reader.ts
CHANGED
|
@@ -161,30 +161,30 @@ export class Reader {
|
|
|
161
161
|
return null
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
// Seek implements the [io.Seeker] interface.
|
|
165
|
-
|
|
164
|
+
// Seek implements the [io.Seeker] interface. offset is a Go int64 (bigint);
|
|
165
|
+
// the internal read index stays a number for string slicing.
|
|
166
|
+
public Seek(offset: bigint, whence: number): [bigint, $.GoError] {
|
|
166
167
|
const r = this
|
|
167
168
|
r!.prevRune = -1
|
|
168
169
|
let abs: number
|
|
169
170
|
switch (whence) {
|
|
170
171
|
case io.SeekStart:
|
|
171
|
-
abs = offset
|
|
172
|
+
abs = Number(offset)
|
|
172
173
|
break
|
|
173
174
|
case io.SeekCurrent:
|
|
174
|
-
abs = r!.i + offset
|
|
175
|
+
abs = r!.i + Number(offset)
|
|
175
176
|
break
|
|
176
177
|
case io.SeekEnd:
|
|
177
|
-
abs = ($.len(r!.s) as number) + offset
|
|
178
|
+
abs = ($.len(r!.s) as number) + Number(offset)
|
|
178
179
|
break
|
|
179
180
|
default:
|
|
180
|
-
return [
|
|
181
|
-
break
|
|
181
|
+
return [0n, $.newError('strings.Reader.Seek: invalid whence')]
|
|
182
182
|
}
|
|
183
183
|
if (abs < 0) {
|
|
184
|
-
return [
|
|
184
|
+
return [0n, $.newError('strings.Reader.Seek: negative position')]
|
|
185
185
|
}
|
|
186
186
|
r!.i = abs
|
|
187
|
-
return [abs, null]
|
|
187
|
+
return [BigInt(abs), null]
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
// WriteTo implements the [io.WriterTo] interface.
|
|
@@ -319,7 +319,17 @@ describe('strings', () => {
|
|
|
319
319
|
)
|
|
320
320
|
expect(Replace('hello world hello', 'hello', 'hi', 2)).toBe('hi world hi')
|
|
321
321
|
expect(Replace('hello world', 'xyz', 'abc', 1)).toBe('hello world')
|
|
322
|
-
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
it('matches Go for empty old, negative n, and remainder', () => {
|
|
325
|
+
// Empty old inserts at the start and after each rune, then appends the
|
|
326
|
+
// untouched remainder once the insertion limit is reached.
|
|
327
|
+
expect(Replace('abc', '', '-', 2)).toBe('-a-bc')
|
|
328
|
+
expect(Replace('abc', '', '-', -1)).toBe('-a-b-c-')
|
|
329
|
+
expect(Replace('hello', '', 'x', 1)).toBe('xhello')
|
|
330
|
+
// n < 0 replaces every occurrence, not none.
|
|
331
|
+
expect(Replace('aaa', 'a', 'b', -1)).toBe('bbb')
|
|
332
|
+
expect(Replace('a,b,c', ',', ';', -1)).toBe('a;b;c')
|
|
323
333
|
})
|
|
324
334
|
})
|
|
325
335
|
|
|
@@ -380,7 +390,8 @@ describe('strings', () => {
|
|
|
380
390
|
describe('Title', () => {
|
|
381
391
|
it('should convert to title case', () => {
|
|
382
392
|
expect(Title('hello world')).toBe('Hello World')
|
|
383
|
-
|
|
393
|
+
// Go's Title only title-cases word-initial letters; the rest is unchanged.
|
|
394
|
+
expect(Title('HELLO WORLD')).toBe('HELLO WORLD')
|
|
384
395
|
expect(Title('')).toBe('')
|
|
385
396
|
})
|
|
386
397
|
})
|
|
@@ -411,9 +422,11 @@ describe('strings', () => {
|
|
|
411
422
|
|
|
412
423
|
describe('special casing and UTF-8 cleanup', () => {
|
|
413
424
|
it('should expose special-case string helpers', () => {
|
|
414
|
-
expect(ToUpperSpecial(
|
|
415
|
-
expect(ToLowerSpecial(
|
|
416
|
-
expect(ToTitleSpecial(
|
|
425
|
+
expect(ToUpperSpecial(new unicode.SpecialCase(), 'hello')).toBe('HELLO')
|
|
426
|
+
expect(ToLowerSpecial(new unicode.SpecialCase(), 'HELLO')).toBe('hello')
|
|
427
|
+
expect(ToTitleSpecial(new unicode.SpecialCase(), 'hello world')).toBe(
|
|
428
|
+
'HELLO WORLD',
|
|
429
|
+
)
|
|
417
430
|
expect(ToUpperSpecial(unicode.TurkishCase, 'iki')).toBe('İKİ')
|
|
418
431
|
expect(ToLowerSpecial(unicode.TurkishCase, 'Iİ')).toBe('ıi')
|
|
419
432
|
expect(ToTitleSpecial(unicode.TurkishCase, 'iki')).toBe('İKİ')
|
package/gs/strings/strings.ts
CHANGED
|
@@ -353,70 +353,32 @@ export function Repeat(s: string, count: number): string {
|
|
|
353
353
|
|
|
354
354
|
// ToUpper returns s with all Unicode letters mapped to their upper case.
|
|
355
355
|
export function ToUpper(s: string): string {
|
|
356
|
-
return s
|
|
356
|
+
return Map(unicode.ToUpper, s)
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
// ToUpperSpecial returns s with all Unicode letters mapped to their upper case using the case mapping specified by c.
|
|
359
360
|
export function ToUpperSpecial(c: unicode.SpecialCase, s: string): string {
|
|
360
|
-
|
|
361
|
-
return mapTurkishCase(s, 'upper')
|
|
362
|
-
}
|
|
363
|
-
return ToUpper(s)
|
|
361
|
+
return Map((r) => c.ToUpper(r), s)
|
|
364
362
|
}
|
|
365
363
|
|
|
366
364
|
// ToLower returns s with all Unicode letters mapped to their lower case.
|
|
367
365
|
export function ToLower(s: string): string {
|
|
368
|
-
return s
|
|
366
|
+
return Map(unicode.ToLower, s)
|
|
369
367
|
}
|
|
370
368
|
|
|
369
|
+
// ToLowerSpecial returns s with all Unicode letters mapped to their lower case using the case mapping specified by c.
|
|
371
370
|
export function ToLowerSpecial(c: unicode.SpecialCase, s: string): string {
|
|
372
|
-
|
|
373
|
-
return mapTurkishCase(s, 'lower')
|
|
374
|
-
}
|
|
375
|
-
return ToLower(s)
|
|
371
|
+
return Map((r) => c.ToLower(r), s)
|
|
376
372
|
}
|
|
377
373
|
|
|
378
374
|
// ToTitle returns a copy of the string s with all Unicode letters mapped to their Unicode title case.
|
|
379
375
|
export function ToTitle(s: string): string {
|
|
380
|
-
return s
|
|
376
|
+
return Map(unicode.ToTitle, s)
|
|
381
377
|
}
|
|
382
378
|
|
|
379
|
+
// ToTitleSpecial returns a copy of s with all Unicode letters mapped to their Unicode title case using the case mapping specified by c.
|
|
383
380
|
export function ToTitleSpecial(c: unicode.SpecialCase, s: string): string {
|
|
384
|
-
|
|
385
|
-
return mapTurkishCase(s, 'upper')
|
|
386
|
-
}
|
|
387
|
-
return ToTitle(s)
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function isTurkishCase(c: unicode.SpecialCase): boolean {
|
|
391
|
-
return c === unicode.TurkishCase || c === unicode.AzeriCase
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
function mapTurkishCase(s: string, mode: 'upper' | 'lower'): string {
|
|
395
|
-
let out = ''
|
|
396
|
-
for (const char of s) {
|
|
397
|
-
if (mode === 'upper') {
|
|
398
|
-
if (char === 'i') {
|
|
399
|
-
out += 'İ'
|
|
400
|
-
continue
|
|
401
|
-
}
|
|
402
|
-
if (char === 'ı') {
|
|
403
|
-
out += 'I'
|
|
404
|
-
continue
|
|
405
|
-
}
|
|
406
|
-
out += char.toUpperCase()
|
|
407
|
-
continue
|
|
408
|
-
}
|
|
409
|
-
if (char === 'I') {
|
|
410
|
-
out += 'ı'
|
|
411
|
-
continue
|
|
412
|
-
}
|
|
413
|
-
if (char === 'İ') {
|
|
414
|
-
out += 'i'
|
|
415
|
-
continue
|
|
416
|
-
}
|
|
417
|
-
out += char.toLowerCase()
|
|
418
|
-
}
|
|
419
|
-
return out
|
|
381
|
+
return Map((r) => c.ToTitle(r), s)
|
|
420
382
|
}
|
|
421
383
|
|
|
422
384
|
export function ToValidUTF8(s: string, replacement: string): string {
|
|
@@ -424,16 +386,30 @@ export function ToValidUTF8(s: string, replacement: string): string {
|
|
|
424
386
|
return s
|
|
425
387
|
}
|
|
426
388
|
|
|
389
|
+
// isSeparator reports whether the rune could mark a word boundary.
|
|
390
|
+
function isSeparator(r: number): boolean {
|
|
391
|
+
if (r <= 0x7f) {
|
|
392
|
+
if (r >= 0x30 && r <= 0x39) return false
|
|
393
|
+
if (r >= 0x61 && r <= 0x7a) return false
|
|
394
|
+
if (r >= 0x41 && r <= 0x5a) return false
|
|
395
|
+
if (r === 0x5f) return false
|
|
396
|
+
return true
|
|
397
|
+
}
|
|
398
|
+
if (unicode.IsLetter(r) || unicode.IsDigit(r)) return false
|
|
399
|
+
return unicode.IsSpace(r)
|
|
400
|
+
}
|
|
401
|
+
|
|
427
402
|
// Title returns a copy of the string s with all Unicode letters that begin words mapped to their Unicode title case.
|
|
428
403
|
export function Title(s: string): string {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
404
|
+
let prev = 0x20
|
|
405
|
+
return Map((r) => {
|
|
406
|
+
if (isSeparator(prev)) {
|
|
407
|
+
prev = r
|
|
408
|
+
return unicode.ToTitle(r)
|
|
409
|
+
}
|
|
410
|
+
prev = r
|
|
411
|
+
return r
|
|
412
|
+
}, s)
|
|
437
413
|
}
|
|
438
414
|
|
|
439
415
|
// TrimSpace returns a slice of the string s, with all leading and trailing white space removed.
|
|
@@ -529,24 +505,35 @@ export function Replace(
|
|
|
529
505
|
newStr: string,
|
|
530
506
|
n: number,
|
|
531
507
|
): string {
|
|
532
|
-
if (n
|
|
508
|
+
if (n === 0 || old === newStr) {
|
|
533
509
|
return s
|
|
534
510
|
}
|
|
535
511
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
512
|
+
if (old === '') {
|
|
513
|
+
// Empty old matches at the start and after each rune (code point),
|
|
514
|
+
// yielding up to runeCount+1 insertions; n < 0 means no limit.
|
|
515
|
+
const runes = globalThis.Array.from(s)
|
|
516
|
+
const limit = n < 0 ? runes.length + 1 : Math.min(n, runes.length + 1)
|
|
517
|
+
let result = newStr
|
|
518
|
+
let i = 0
|
|
519
|
+
for (; i < limit - 1; i++) {
|
|
520
|
+
result += runes[i] + newStr
|
|
521
|
+
}
|
|
522
|
+
return result + runes.slice(i).join('')
|
|
523
|
+
}
|
|
539
524
|
|
|
540
|
-
|
|
541
|
-
|
|
525
|
+
// Non-empty old: replace up to n occurrences; n < 0 means all.
|
|
526
|
+
let result = ''
|
|
527
|
+
let start = 0
|
|
528
|
+
let count = 0
|
|
529
|
+
while (n < 0 || count < n) {
|
|
530
|
+
const index = s.indexOf(old, start)
|
|
542
531
|
if (index === -1) break
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
pos = index + newStr.length
|
|
532
|
+
result += s.slice(start, index) + newStr
|
|
533
|
+
start = index + old.length
|
|
546
534
|
count++
|
|
547
535
|
}
|
|
548
|
-
|
|
549
|
-
return result
|
|
536
|
+
return result + s.slice(start)
|
|
550
537
|
}
|
|
551
538
|
|
|
552
539
|
// ReplaceAll returns a copy of the string s with all non-overlapping instances of old replaced by new.
|
|
@@ -557,9 +544,35 @@ export function ReplaceAll(s: string, old: string, newStr: string): string {
|
|
|
557
544
|
return s.split(old).join(newStr)
|
|
558
545
|
}
|
|
559
546
|
|
|
560
|
-
// EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under Unicode case-folding.
|
|
547
|
+
// EqualFold reports whether s and t, interpreted as UTF-8 strings, are equal under simple Unicode case-folding.
|
|
561
548
|
export function EqualFold(s: string, t: string): boolean {
|
|
562
|
-
|
|
549
|
+
const sr = Array.from(s, (ch) => ch.codePointAt(0)!)
|
|
550
|
+
const tr = Array.from(t, (ch) => ch.codePointAt(0)!)
|
|
551
|
+
let i = 0
|
|
552
|
+
let j = 0
|
|
553
|
+
while (i < sr.length && j < tr.length) {
|
|
554
|
+
let a = sr[i++]
|
|
555
|
+
let b = tr[j++]
|
|
556
|
+
if (a === b) continue
|
|
557
|
+
if (b < a) {
|
|
558
|
+
const tmp = a
|
|
559
|
+
a = b
|
|
560
|
+
b = tmp
|
|
561
|
+
}
|
|
562
|
+
if (b < 0x80) {
|
|
563
|
+
// ASCII: a and b match only as the same letter in opposite case.
|
|
564
|
+
if (a >= 0x41 && a <= 0x5a && b === a + 0x20) continue
|
|
565
|
+
return false
|
|
566
|
+
}
|
|
567
|
+
// Walk the simple-fold orbit of the smaller rune toward the larger.
|
|
568
|
+
let r = unicode.SimpleFold(a)
|
|
569
|
+
while (r !== a && r < b) {
|
|
570
|
+
r = unicode.SimpleFold(r)
|
|
571
|
+
}
|
|
572
|
+
if (r === b) continue
|
|
573
|
+
return false
|
|
574
|
+
}
|
|
575
|
+
return i === sr.length && j === tr.length
|
|
563
576
|
}
|
|
564
577
|
|
|
565
578
|
// Compare returns an integer comparing two strings lexicographically.
|
|
@@ -5,8 +5,8 @@ import * as $ from "@goscript/builtin/index.js";
|
|
|
5
5
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
6
6
|
//
|
|
7
7
|
//go:noescape
|
|
8
|
-
export function SwapInt64(addr: $.VarRef<
|
|
9
|
-
if (!addr) return
|
|
8
|
+
export function SwapInt64(addr: $.VarRef<bigint> | null, _new: bigint): bigint {
|
|
9
|
+
if (!addr) return 0n;
|
|
10
10
|
let old = addr.value;
|
|
11
11
|
addr.value = _new;
|
|
12
12
|
return old;
|
|
@@ -17,8 +17,8 @@ export function SwapInt64(addr: $.VarRef<number> | null, _new: number): number {
|
|
|
17
17
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
18
18
|
//
|
|
19
19
|
//go:noescape
|
|
20
|
-
export function SwapUint64(addr: $.VarRef<
|
|
21
|
-
if (!addr) return
|
|
20
|
+
export function SwapUint64(addr: $.VarRef<bigint> | null, _new: bigint): bigint {
|
|
21
|
+
if (!addr) return 0n;
|
|
22
22
|
let old = addr.value;
|
|
23
23
|
addr.value = _new;
|
|
24
24
|
return old;
|
|
@@ -29,7 +29,7 @@ export function SwapUint64(addr: $.VarRef<number> | null, _new: number): number
|
|
|
29
29
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
30
30
|
//
|
|
31
31
|
//go:noescape
|
|
32
|
-
export function CompareAndSwapInt64(addr: $.VarRef<
|
|
32
|
+
export function CompareAndSwapInt64(addr: $.VarRef<bigint> | null, old: bigint, _new: bigint): boolean {
|
|
33
33
|
if (!addr) return false;
|
|
34
34
|
if (addr.value === old) {
|
|
35
35
|
addr.value = _new;
|
|
@@ -43,7 +43,7 @@ export function CompareAndSwapInt64(addr: $.VarRef<number> | null, old: number,
|
|
|
43
43
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
44
44
|
//
|
|
45
45
|
//go:noescape
|
|
46
|
-
export function CompareAndSwapUint64(addr: $.VarRef<
|
|
46
|
+
export function CompareAndSwapUint64(addr: $.VarRef<bigint> | null, old: bigint, _new: bigint): boolean {
|
|
47
47
|
if (!addr) return false;
|
|
48
48
|
if (addr.value === old) {
|
|
49
49
|
addr.value = _new;
|
|
@@ -57,8 +57,8 @@ export function CompareAndSwapUint64(addr: $.VarRef<number> | null, old: number,
|
|
|
57
57
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
58
58
|
//
|
|
59
59
|
//go:noescape
|
|
60
|
-
export function AddInt64(addr: $.VarRef<
|
|
61
|
-
if (!addr) return
|
|
60
|
+
export function AddInt64(addr: $.VarRef<bigint> | null, delta: bigint): bigint {
|
|
61
|
+
if (!addr) return 0n;
|
|
62
62
|
addr.value = $.int64Add(addr.value, delta);
|
|
63
63
|
return addr.value;
|
|
64
64
|
}
|
|
@@ -70,8 +70,8 @@ export function AddInt64(addr: $.VarRef<number> | null, delta: number): number {
|
|
|
70
70
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
71
71
|
//
|
|
72
72
|
//go:noescape
|
|
73
|
-
export function AddUint64(addr: $.VarRef<
|
|
74
|
-
if (!addr) return
|
|
73
|
+
export function AddUint64(addr: $.VarRef<bigint> | null, delta: bigint): bigint {
|
|
74
|
+
if (!addr) return 0n;
|
|
75
75
|
addr.value = $.uint64Add(addr.value, delta);
|
|
76
76
|
return addr.value;
|
|
77
77
|
}
|
|
@@ -81,8 +81,8 @@ export function AddUint64(addr: $.VarRef<number> | null, delta: number): number
|
|
|
81
81
|
// Consider using the more ergonomic and less error-prone [Int64.And] instead.
|
|
82
82
|
//
|
|
83
83
|
//go:noescape
|
|
84
|
-
export function AndInt64(addr: $.VarRef<
|
|
85
|
-
if (!addr) return
|
|
84
|
+
export function AndInt64(addr: $.VarRef<bigint> | null, mask: bigint): bigint {
|
|
85
|
+
if (!addr) return 0n;
|
|
86
86
|
let old = addr.value;
|
|
87
87
|
addr.value = $.int64And(addr.value, mask);
|
|
88
88
|
return old;
|
|
@@ -93,8 +93,8 @@ export function AndInt64(addr: $.VarRef<number> | null, mask: number): number {
|
|
|
93
93
|
// Consider using the more ergonomic and less error-prone [Uint64.And] instead.
|
|
94
94
|
//
|
|
95
95
|
//go:noescape
|
|
96
|
-
export function AndUint64(addr: $.VarRef<
|
|
97
|
-
if (!addr) return
|
|
96
|
+
export function AndUint64(addr: $.VarRef<bigint> | null, mask: bigint): bigint {
|
|
97
|
+
if (!addr) return 0n;
|
|
98
98
|
let old = addr.value;
|
|
99
99
|
addr.value = $.uint64And(addr.value, mask);
|
|
100
100
|
return old;
|
|
@@ -105,8 +105,8 @@ export function AndUint64(addr: $.VarRef<number> | null, mask: number): number {
|
|
|
105
105
|
// Consider using the more ergonomic and less error-prone [Int64.Or] instead.
|
|
106
106
|
//
|
|
107
107
|
//go:noescape
|
|
108
|
-
export function OrInt64(addr: $.VarRef<
|
|
109
|
-
if (!addr) return
|
|
108
|
+
export function OrInt64(addr: $.VarRef<bigint> | null, mask: bigint): bigint {
|
|
109
|
+
if (!addr) return 0n;
|
|
110
110
|
let old = addr.value;
|
|
111
111
|
addr.value = $.int64Or(addr.value, mask);
|
|
112
112
|
return old;
|
|
@@ -117,8 +117,8 @@ export function OrInt64(addr: $.VarRef<number> | null, mask: number): number {
|
|
|
117
117
|
// Consider using the more ergonomic and less error-prone [Uint64.Or] instead.
|
|
118
118
|
//
|
|
119
119
|
//go:noescape
|
|
120
|
-
export function OrUint64(addr: $.VarRef<
|
|
121
|
-
if (!addr) return
|
|
120
|
+
export function OrUint64(addr: $.VarRef<bigint> | null, mask: bigint): bigint {
|
|
121
|
+
if (!addr) return 0n;
|
|
122
122
|
let old = addr.value;
|
|
123
123
|
addr.value = $.uint64Or(addr.value, mask);
|
|
124
124
|
return old;
|
|
@@ -129,8 +129,8 @@ export function OrUint64(addr: $.VarRef<number> | null, mask: number): number {
|
|
|
129
129
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
130
130
|
//
|
|
131
131
|
//go:noescape
|
|
132
|
-
export function LoadInt64(addr: $.VarRef<
|
|
133
|
-
if (!addr) return
|
|
132
|
+
export function LoadInt64(addr: $.VarRef<bigint> | null): bigint {
|
|
133
|
+
if (!addr) return 0n;
|
|
134
134
|
return addr.value;
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -139,8 +139,8 @@ export function LoadInt64(addr: $.VarRef<number> | null): number {
|
|
|
139
139
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
140
140
|
//
|
|
141
141
|
//go:noescape
|
|
142
|
-
export function LoadUint64(addr: $.VarRef<
|
|
143
|
-
if (!addr) return
|
|
142
|
+
export function LoadUint64(addr: $.VarRef<bigint> | null): bigint {
|
|
143
|
+
if (!addr) return 0n;
|
|
144
144
|
return addr.value;
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -149,7 +149,7 @@ export function LoadUint64(addr: $.VarRef<number> | null): number {
|
|
|
149
149
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
150
150
|
//
|
|
151
151
|
//go:noescape
|
|
152
|
-
export function StoreInt64(addr: $.VarRef<
|
|
152
|
+
export function StoreInt64(addr: $.VarRef<bigint> | null, val: bigint): void {
|
|
153
153
|
if (addr) {
|
|
154
154
|
addr.value = val;
|
|
155
155
|
}
|
|
@@ -160,7 +160,7 @@ export function StoreInt64(addr: $.VarRef<number> | null, val: number): void {
|
|
|
160
160
|
// (particularly if you target 32-bit platforms; see the bugs section).
|
|
161
161
|
//
|
|
162
162
|
//go:noescape
|
|
163
|
-
export function StoreUint64(addr: $.VarRef<
|
|
163
|
+
export function StoreUint64(addr: $.VarRef<bigint> | null, val: bigint): void {
|
|
164
164
|
if (addr) {
|
|
165
165
|
addr.value = val;
|
|
166
166
|
}
|
|
@@ -11,8 +11,8 @@ describe('sync/atomic 64-bit operations', () => {
|
|
|
11
11
|
test('adds uint64 values without mixing number and bigint arithmetic', () => {
|
|
12
12
|
const value = $.varRef($.uint('18446744073709551614', 64))
|
|
13
13
|
|
|
14
|
-
expect(AddUint64(value, $.uint(2, 64))).toBe(
|
|
15
|
-
expect(value.value).toBe(
|
|
14
|
+
expect(AddUint64(value, $.uint(2, 64))).toBe(0n)
|
|
15
|
+
expect(value.value).toBe(0n)
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
test('preserves high uint64 bits for bitwise operations', () => {
|
|
@@ -28,9 +28,9 @@ describe('sync/atomic 64-bit operations', () => {
|
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
test('adds int64 values without number coercion', () => {
|
|
31
|
-
const value = $.varRef($.
|
|
31
|
+
const value = $.varRef($.int64('9223372036854775807'))
|
|
32
32
|
|
|
33
|
-
expect(AddInt64(value,
|
|
34
|
-
expect(value.value).toBe(-
|
|
33
|
+
expect(AddInt64(value, 1n)).toBe(-9223372036854775808n)
|
|
34
|
+
expect(value.value).toBe(-9223372036854775808n)
|
|
35
35
|
})
|
|
36
36
|
})
|
|
@@ -223,20 +223,20 @@ export class Int32 {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
export class Int64 {
|
|
226
|
-
public get v():
|
|
226
|
+
public get v(): bigint {
|
|
227
227
|
return this._fields.v.value
|
|
228
228
|
}
|
|
229
|
-
public set v(value:
|
|
229
|
+
public set v(value: bigint) {
|
|
230
230
|
this._fields.v.value = value
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
public _fields: {
|
|
234
|
-
v: $.VarRef<
|
|
234
|
+
v: $.VarRef<bigint>;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
constructor(init?: Partial<{v?:
|
|
237
|
+
constructor(init?: Partial<{v?: bigint}>) {
|
|
238
238
|
this._fields = {
|
|
239
|
-
v: $.varRef(init?.v ??
|
|
239
|
+
v: $.varRef(init?.v ?? 0n)
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
|
|
@@ -249,45 +249,45 @@ export class Int64 {
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
// Load atomically loads and returns the value stored in x.
|
|
252
|
-
public Load():
|
|
252
|
+
public Load(): bigint {
|
|
253
253
|
const x = this
|
|
254
254
|
return LoadInt64(x._fields.v)
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
// Store atomically stores val into x.
|
|
258
|
-
public Store(val:
|
|
258
|
+
public Store(val: bigint): void {
|
|
259
259
|
const x = this
|
|
260
260
|
StoreInt64(x._fields.v, val)
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
// Swap atomically stores new into x and returns the previous value.
|
|
264
|
-
public Swap(_new:
|
|
264
|
+
public Swap(_new: bigint): bigint {
|
|
265
265
|
const x = this
|
|
266
266
|
return SwapInt64(x._fields.v, _new)
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
// CompareAndSwap executes the compare-and-swap operation for x.
|
|
270
|
-
public CompareAndSwap(old:
|
|
270
|
+
public CompareAndSwap(old: bigint, _new: bigint): boolean {
|
|
271
271
|
const x = this
|
|
272
272
|
return CompareAndSwapInt64(x._fields.v, old, _new)
|
|
273
273
|
}
|
|
274
274
|
|
|
275
275
|
// Add atomically adds delta to x and returns the new value.
|
|
276
|
-
public Add(delta:
|
|
276
|
+
public Add(delta: bigint): bigint {
|
|
277
277
|
const x = this
|
|
278
278
|
return AddInt64(x._fields.v, delta)
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
// And atomically performs a bitwise AND operation on x using the bitmask
|
|
282
282
|
// provided as mask and returns the old value.
|
|
283
|
-
public And(mask:
|
|
283
|
+
public And(mask: bigint): bigint {
|
|
284
284
|
const x = this
|
|
285
285
|
return AndInt64(x._fields.v, mask)
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
// Or atomically performs a bitwise OR operation on x using the bitmask
|
|
289
289
|
// provided as mask and returns the old value.
|
|
290
|
-
public Or(mask:
|
|
290
|
+
public Or(mask: bigint): bigint {
|
|
291
291
|
const x = this
|
|
292
292
|
return OrInt64(x._fields.v, mask)
|
|
293
293
|
}
|
|
@@ -296,9 +296,9 @@ export class Int64 {
|
|
|
296
296
|
static __typeInfo = $.registerStructType(
|
|
297
297
|
'Int64',
|
|
298
298
|
new Int64(),
|
|
299
|
-
[{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "
|
|
299
|
+
[{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }] }, { name: "Store", args: [{ name: "val", type: { kind: $.TypeKind.Basic, name: "int64" } }], returns: [] }, { name: "Swap", args: [{ name: "new", type: { kind: $.TypeKind.Basic, name: "int64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }] }, { name: "CompareAndSwap", args: [{ name: "old", type: { kind: $.TypeKind.Basic, name: "int64" } }, { name: "new", type: { kind: $.TypeKind.Basic, name: "int64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "Add", args: [{ name: "delta", type: { kind: $.TypeKind.Basic, name: "int64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }] }, { name: "And", args: [{ name: "mask", type: { kind: $.TypeKind.Basic, name: "int64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }] }, { name: "Or", args: [{ name: "mask", type: { kind: $.TypeKind.Basic, name: "int64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "int64" } }] }],
|
|
300
300
|
Int64,
|
|
301
|
-
[{ name: "v", key: "v", type: { kind: $.TypeKind.Basic, name: "
|
|
301
|
+
[{ name: "v", key: "v", type: { kind: $.TypeKind.Basic, name: "int64" } }]
|
|
302
302
|
);
|
|
303
303
|
}
|
|
304
304
|
|
|
@@ -383,20 +383,20 @@ export class Uint32 {
|
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
export class Uint64 {
|
|
386
|
-
public get v():
|
|
386
|
+
public get v(): bigint {
|
|
387
387
|
return this._fields.v.value
|
|
388
388
|
}
|
|
389
|
-
public set v(value:
|
|
389
|
+
public set v(value: bigint) {
|
|
390
390
|
this._fields.v.value = value
|
|
391
391
|
}
|
|
392
392
|
|
|
393
393
|
public _fields: {
|
|
394
|
-
v: $.VarRef<
|
|
394
|
+
v: $.VarRef<bigint>;
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
constructor(init?: Partial<{v?:
|
|
397
|
+
constructor(init?: Partial<{v?: bigint}>) {
|
|
398
398
|
this._fields = {
|
|
399
|
-
v: $.varRef(init?.v ??
|
|
399
|
+
v: $.varRef(init?.v ?? 0n)
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
|
|
@@ -409,45 +409,45 @@ export class Uint64 {
|
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
// Load atomically loads and returns the value stored in x.
|
|
412
|
-
public Load():
|
|
412
|
+
public Load(): bigint {
|
|
413
413
|
const x = this
|
|
414
414
|
return LoadUint64(x._fields.v)
|
|
415
415
|
}
|
|
416
416
|
|
|
417
417
|
// Store atomically stores val into x.
|
|
418
|
-
public Store(val:
|
|
418
|
+
public Store(val: bigint): void {
|
|
419
419
|
const x = this
|
|
420
420
|
StoreUint64(x._fields.v, val)
|
|
421
421
|
}
|
|
422
422
|
|
|
423
423
|
// Swap atomically stores new into x and returns the previous value.
|
|
424
|
-
public Swap(_new:
|
|
424
|
+
public Swap(_new: bigint): bigint {
|
|
425
425
|
const x = this
|
|
426
426
|
return SwapUint64(x._fields.v, _new)
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
// CompareAndSwap executes the compare-and-swap operation for x.
|
|
430
|
-
public CompareAndSwap(old:
|
|
430
|
+
public CompareAndSwap(old: bigint, _new: bigint): boolean {
|
|
431
431
|
const x = this
|
|
432
432
|
return CompareAndSwapUint64(x._fields.v, old, _new)
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
// Add atomically adds delta to x and returns the new value.
|
|
436
|
-
public Add(delta:
|
|
436
|
+
public Add(delta: bigint): bigint {
|
|
437
437
|
const x = this
|
|
438
438
|
return AddUint64(x._fields.v, delta)
|
|
439
439
|
}
|
|
440
440
|
|
|
441
441
|
// And atomically performs a bitwise AND operation on x using the bitmask
|
|
442
442
|
// provided as mask and returns the old value.
|
|
443
|
-
public And(mask:
|
|
443
|
+
public And(mask: bigint): bigint {
|
|
444
444
|
const x = this
|
|
445
445
|
return AndUint64(x._fields.v, mask)
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
// Or atomically performs a bitwise OR operation on x using the bitmask
|
|
449
449
|
// provided as mask and returns the old value.
|
|
450
|
-
public Or(mask:
|
|
450
|
+
public Or(mask: bigint): bigint {
|
|
451
451
|
const x = this
|
|
452
452
|
return OrUint64(x._fields.v, mask)
|
|
453
453
|
}
|
|
@@ -456,9 +456,9 @@ export class Uint64 {
|
|
|
456
456
|
static __typeInfo = $.registerStructType(
|
|
457
457
|
'Uint64',
|
|
458
458
|
new Uint64(),
|
|
459
|
-
[{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "
|
|
459
|
+
[{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Basic, name: "uint64" } }] }, { name: "Store", args: [{ name: "val", type: { kind: $.TypeKind.Basic, name: "uint64" } }], returns: [] }, { name: "Swap", args: [{ name: "new", type: { kind: $.TypeKind.Basic, name: "uint64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "uint64" } }] }, { name: "CompareAndSwap", args: [{ name: "old", type: { kind: $.TypeKind.Basic, name: "uint64" } }, { name: "new", type: { kind: $.TypeKind.Basic, name: "uint64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }, { name: "Add", args: [{ name: "delta", type: { kind: $.TypeKind.Basic, name: "uint64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "uint64" } }] }, { name: "And", args: [{ name: "mask", type: { kind: $.TypeKind.Basic, name: "uint64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "uint64" } }] }, { name: "Or", args: [{ name: "mask", type: { kind: $.TypeKind.Basic, name: "uint64" } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "uint64" } }] }],
|
|
460
460
|
Uint64,
|
|
461
|
-
[{ name: "v", key: "v", type: { kind: $.TypeKind.Basic, name: "
|
|
461
|
+
[{ name: "v", key: "v", type: { kind: $.TypeKind.Basic, name: "uint64" } }]
|
|
462
462
|
);
|
|
463
463
|
}
|
|
464
464
|
|