goscript 0.1.1 → 0.1.3
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-test.go +104 -11
- package/cmd/goscript/cmd-test_test.go +1 -1
- package/cmd/goscript/cmd_compile.go +9 -0
- package/compiler/compile-request.go +31 -0
- package/compiler/compiler.go +1 -1
- package/compiler/compliance_test.go +0 -2
- package/compiler/config.go +2 -0
- package/compiler/gotest/package-result.go +2 -0
- package/compiler/gotest/request.go +85 -20
- package/compiler/gotest/runner.go +733 -96
- package/compiler/gotest/runner_test.go +647 -3
- package/compiler/lowered-program.go +10 -2
- package/compiler/lowering.go +2676 -349
- package/compiler/override-facts.go +77 -27
- package/compiler/override-registry.go +5 -4
- package/compiler/override-registry_test.go +178 -0
- package/compiler/package-graph_test.go +62 -7
- package/compiler/package-test-graph-variant.go +40 -16
- package/compiler/package-test-graph.go +0 -5
- package/compiler/package-test-graph_test.go +61 -3
- package/compiler/runtime-contract.go +40 -0
- package/compiler/semantic-model-types.go +16 -0
- package/compiler/semantic-model.go +336 -91
- package/compiler/semantic-model_test.go +50 -1
- package/compiler/service.go +9 -3
- package/compiler/skeleton_test.go +2371 -296
- package/compiler/tsworkspace/owner-process-unix_test.go +72 -0
- package/compiler/tsworkspace/owner.go +8 -0
- package/compiler/tsworkspace/tool-process-other.go +14 -0
- package/compiler/tsworkspace/tool-process-unix.go +19 -0
- package/compiler/typescript-emitter.go +149 -10
- package/dist/gs/builtin/builtin.d.ts +20 -1
- package/dist/gs/builtin/builtin.js +246 -26
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +24 -10
- package/dist/gs/builtin/channel.js +143 -34
- package/dist/gs/builtin/channel.js.map +1 -1
- package/dist/gs/builtin/defer.d.ts +1 -0
- package/dist/gs/builtin/defer.js +12 -2
- package/dist/gs/builtin/defer.js.map +1 -1
- package/dist/gs/builtin/hostio.d.ts +9 -0
- package/dist/gs/builtin/hostio.js +25 -0
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/map.js +40 -6
- package/dist/gs/builtin/map.js.map +1 -1
- package/dist/gs/builtin/print.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +43 -9
- package/dist/gs/builtin/slice.js +437 -234
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +2 -0
- package/dist/gs/builtin/type.js +55 -10
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +2 -0
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.js +28 -28
- package/dist/gs/bytes/buffer.gs.js.map +1 -1
- package/dist/gs/bytes/bytes.gs.d.ts +7 -5
- package/dist/gs/bytes/bytes.gs.js +10 -4
- package/dist/gs/bytes/bytes.gs.js.map +1 -1
- package/dist/gs/bytes/iter.gs.js +13 -13
- package/dist/gs/bytes/iter.gs.js.map +1 -1
- package/dist/gs/compress/zlib/index.d.ts +26 -0
- package/dist/gs/compress/zlib/index.js +168 -0
- package/dist/gs/compress/zlib/index.js.map +1 -0
- package/dist/gs/context/context.d.ts +1 -1
- package/dist/gs/context/context.js +8 -3
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/crypto/ecdh/index.d.ts +52 -0
- package/dist/gs/crypto/ecdh/index.js +226 -0
- package/dist/gs/crypto/ecdh/index.js.map +1 -0
- package/dist/gs/crypto/ed25519/index.d.ts +34 -0
- package/dist/gs/crypto/ed25519/index.js +160 -0
- package/dist/gs/crypto/ed25519/index.js.map +1 -0
- package/dist/gs/crypto/internal/constanttime/index.d.ts +4 -0
- package/dist/gs/crypto/internal/constanttime/index.js +18 -0
- package/dist/gs/crypto/internal/constanttime/index.js.map +1 -0
- package/dist/gs/crypto/rand/index.d.ts +2 -0
- package/dist/gs/crypto/rand/index.js +85 -0
- package/dist/gs/crypto/rand/index.js.map +1 -1
- package/dist/gs/crypto/sha1/index.d.ts +5 -0
- package/dist/gs/crypto/sha1/index.js +106 -0
- package/dist/gs/crypto/sha1/index.js.map +1 -0
- package/dist/gs/crypto/sha256/index.d.ts +8 -0
- package/dist/gs/crypto/sha256/index.js +118 -0
- package/dist/gs/crypto/sha256/index.js.map +1 -0
- package/dist/gs/crypto/sha512/index.d.ts +14 -0
- package/dist/gs/crypto/sha512/index.js +129 -0
- package/dist/gs/crypto/sha512/index.js.map +1 -0
- package/dist/gs/encoding/json/index.d.ts +3 -0
- package/dist/gs/encoding/json/index.js +15 -0
- package/dist/gs/encoding/json/index.js.map +1 -1
- package/dist/gs/errors/errors.js +29 -6
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +1 -1
- package/dist/gs/fmt/fmt.js +64 -3
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +7 -7
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +52 -18
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +56 -20
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +57 -3
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +366 -1
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/util/conc/index.d.ts +20 -0
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js +134 -0
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.js.map +1 -1
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.d.ts +3 -0
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.js +50 -0
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.js.map +1 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js +3 -2
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -1
- package/dist/gs/github.com/mr-tron/base58/base58/index.d.ts +27 -0
- package/dist/gs/github.com/mr-tron/base58/base58/index.js +172 -0
- package/dist/gs/github.com/mr-tron/base58/base58/index.js.map +1 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.d.ts +21 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.js +22 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.js.map +1 -0
- package/dist/gs/go/token/index.js +11 -4
- package/dist/gs/go/token/index.js.map +1 -1
- package/dist/gs/hash/fnv/index.d.ts +57 -0
- package/dist/gs/hash/fnv/index.js +299 -0
- package/dist/gs/hash/fnv/index.js.map +1 -0
- package/dist/gs/hash/index.d.ts +17 -0
- package/dist/gs/hash/index.js +94 -0
- package/dist/gs/hash/index.js.map +1 -0
- package/dist/gs/io/fs/readlink.js +2 -6
- package/dist/gs/io/fs/readlink.js.map +1 -1
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/io/io.d.ts +8 -5
- package/dist/gs/io/io.js +20 -2
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/iter/iter.d.ts +3 -2
- package/dist/gs/iter/iter.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +5 -5
- package/dist/gs/maps/iter.js +48 -21
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.d.ts +6 -6
- package/dist/gs/math/bits/index.js +14 -24
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/mime/index.js +3 -1
- package/dist/gs/mime/index.js.map +1 -1
- package/dist/gs/net/http/httptest/index.d.ts +20 -1
- package/dist/gs/net/http/httptest/index.js +85 -3
- package/dist/gs/net/http/httptest/index.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +118 -6
- package/dist/gs/net/http/index.js +389 -14
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/net/http/pprof/index.d.ts +8 -0
- package/dist/gs/net/http/pprof/index.js +59 -0
- package/dist/gs/net/http/pprof/index.js.map +1 -0
- package/dist/gs/os/error.gs.js +9 -7
- package/dist/gs/os/error.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.js +95 -15
- package/dist/gs/os/types_js.gs.js.map +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.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +5 -3
- package/dist/gs/path/filepath/path.js +65 -10
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +3 -2
- package/dist/gs/reflect/index.js +2 -1
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/iter.js +2 -2
- package/dist/gs/reflect/iter.js.map +1 -1
- package/dist/gs/reflect/map.js +26 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +24 -5
- package/dist/gs/reflect/type.js +390 -38
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.d.ts +1 -0
- package/dist/gs/reflect/types.js +3 -1
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/value.d.ts +4 -1
- package/dist/gs/reflect/value.js +39 -1
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/reflect/visiblefields.js +1 -1
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/runtime/debug/index.d.ts +39 -0
- package/dist/gs/runtime/debug/index.js +58 -0
- package/dist/gs/runtime/debug/index.js.map +1 -1
- package/dist/gs/runtime/pprof/index.d.ts +20 -0
- package/dist/gs/runtime/pprof/index.js +85 -0
- package/dist/gs/runtime/pprof/index.js.map +1 -0
- package/dist/gs/runtime/trace/index.d.ts +19 -0
- package/dist/gs/runtime/trace/index.js +64 -0
- package/dist/gs/runtime/trace/index.js.map +1 -0
- package/dist/gs/slices/slices.d.ts +24 -9
- package/dist/gs/slices/slices.js +229 -24
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/slice.gs.d.ts +5 -3
- package/dist/gs/sort/slice.gs.js +55 -17
- package/dist/gs/sort/slice.gs.js.map +1 -1
- package/dist/gs/strings/builder.js +26 -17
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/strings/iter.js +140 -75
- package/dist/gs/strings/iter.js.map +1 -1
- package/dist/gs/strings/replace.js +2 -2
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/strings.js +52 -6
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +6 -3
- package/dist/gs/sync/sync.js +39 -11
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/errors.d.ts +116 -112
- package/dist/gs/syscall/errors.js +38 -1
- package/dist/gs/syscall/errors.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +2 -8
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/syscall/js/index.js +20 -12
- package/dist/gs/syscall/js/index.js.map +1 -1
- package/dist/gs/syscall/types.d.ts +4 -1
- package/dist/gs/syscall/types.js.map +1 -1
- package/dist/gs/testing/testing.d.ts +4 -3
- package/dist/gs/testing/testing.js +21 -4
- package/dist/gs/testing/testing.js.map +1 -1
- package/dist/gs/time/time.js +22 -0
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/dist/gs/unique/index.js +7 -2
- package/dist/gs/unique/index.js.map +1 -1
- package/go.mod +8 -8
- package/go.sum +14 -23
- package/gs/builtin/builtin.ts +364 -37
- package/gs/builtin/channel.ts +208 -38
- package/gs/builtin/defer.ts +13 -2
- package/gs/builtin/hostio.test.ts +1 -0
- package/gs/builtin/hostio.ts +38 -0
- package/gs/builtin/map.ts +46 -6
- package/gs/builtin/print.ts +12 -3
- package/gs/builtin/runtime-contract.test.ts +290 -10
- package/gs/builtin/slice.test.ts +70 -0
- package/gs/builtin/slice.ts +566 -255
- package/gs/builtin/type.ts +63 -10
- package/gs/builtin/varRef.ts +2 -0
- package/gs/bytes/buffer.gs.ts +28 -28
- package/gs/bytes/bytes.gs.ts +19 -10
- package/gs/bytes/bytes.test.ts +17 -0
- package/gs/bytes/iter.gs.ts +13 -14
- package/gs/compress/zlib/index.test.ts +28 -0
- package/gs/compress/zlib/index.ts +200 -0
- package/gs/compress/zlib/meta.json +3 -0
- package/gs/context/context.test.ts +36 -2
- package/gs/context/context.ts +9 -4
- package/gs/crypto/ecdh/index.test.ts +43 -0
- package/gs/crypto/ecdh/index.ts +274 -0
- package/gs/crypto/ed25519/index.test.ts +41 -0
- package/gs/crypto/ed25519/index.ts +238 -0
- package/gs/crypto/ed25519/meta.json +13 -0
- package/gs/crypto/internal/constanttime/index.test.ts +25 -0
- package/gs/crypto/internal/constanttime/index.ts +22 -0
- package/gs/crypto/rand/index.test.ts +89 -1
- package/gs/crypto/rand/index.ts +103 -1
- package/gs/crypto/rand/meta.json +4 -1
- package/gs/crypto/sha1/index.test.ts +28 -0
- package/gs/crypto/sha1/index.ts +130 -0
- package/gs/crypto/sha1/meta.json +8 -0
- package/gs/crypto/sha256/index.test.ts +78 -0
- package/gs/crypto/sha256/index.ts +150 -0
- package/gs/crypto/sha256/meta.json +9 -0
- package/gs/crypto/sha512/index.test.ts +31 -0
- package/gs/crypto/sha512/index.ts +161 -0
- package/gs/crypto/sha512/meta.json +11 -0
- package/gs/encoding/json/index.test.ts +25 -3
- package/gs/encoding/json/index.ts +21 -3
- package/gs/errors/errors.test.ts +4 -1
- package/gs/errors/errors.ts +32 -8
- package/gs/fmt/fmt.test.ts +23 -1
- package/gs/fmt/fmt.ts +76 -10
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +62 -7
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +78 -36
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +32 -11
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +122 -43
- package/gs/github.com/aperturerobotics/starpc/srpc/index.test.ts +31 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +518 -4
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +6 -0
- package/gs/github.com/aperturerobotics/util/conc/index.test.ts +30 -0
- package/gs/github.com/aperturerobotics/util/conc/index.ts +172 -0
- package/gs/github.com/aperturerobotics/util/conc/meta.json +9 -0
- package/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.ts +1 -4
- package/gs/github.com/hack-pad/safejs/internal/catch/index.test.ts +35 -0
- package/gs/github.com/hack-pad/safejs/internal/catch/index.ts +65 -0
- package/gs/github.com/hack-pad/safejs/internal/catch/meta.json +9 -0
- package/gs/github.com/klauspost/compress/internal/le/index.test.ts +2 -1
- package/gs/github.com/klauspost/compress/internal/le/index.ts +6 -5
- package/gs/github.com/mr-tron/base58/base58/index.test.ts +70 -0
- package/gs/github.com/mr-tron/base58/base58/index.ts +231 -0
- package/gs/github.com/mr-tron/base58/base58/meta.json +3 -0
- package/gs/github.com/zeebo/blake3/internal/consts/index.test.ts +46 -0
- package/gs/github.com/zeebo/blake3/internal/consts/index.ts +26 -0
- package/gs/go/token/index.ts +17 -4
- package/gs/hash/fnv/index.test.ts +67 -0
- package/gs/hash/fnv/index.ts +351 -0
- package/gs/hash/fnv/meta.json +3 -0
- package/gs/hash/index.test.ts +37 -0
- package/gs/hash/index.ts +118 -0
- package/gs/hash/meta.json +5 -0
- package/gs/internal/byteorder/index.test.ts +6 -6
- package/gs/io/fs/readlink.ts +40 -48
- package/gs/io/fs/walk.ts +10 -2
- package/gs/io/io.test.ts +64 -0
- package/gs/io/io.ts +34 -13
- package/gs/iter/iter.ts +8 -2
- package/gs/maps/iter.ts +69 -26
- package/gs/maps/maps.test.ts +23 -0
- package/gs/maps/maps.ts +6 -6
- package/gs/math/bits/index.test.ts +20 -0
- package/gs/math/bits/index.ts +15 -28
- package/gs/mime/index.ts +8 -2
- package/gs/net/http/httptest/index.test.ts +85 -0
- package/gs/net/http/httptest/index.ts +113 -3
- package/gs/net/http/index.test.ts +159 -1
- package/gs/net/http/index.ts +515 -15
- package/gs/net/http/meta.json +6 -0
- package/gs/net/http/pprof/index.test.ts +47 -0
- package/gs/net/http/pprof/index.ts +65 -0
- package/gs/os/error.gs.ts +9 -10
- package/gs/os/error.test.ts +41 -0
- package/gs/os/file_unix_js.test.ts +55 -0
- package/gs/os/tempfile.gs.test.ts +37 -10
- package/gs/os/types_js.gs.ts +94 -15
- package/gs/os/zero_copy_posix.gs.ts +1 -2
- package/gs/path/filepath/match.ts +4 -1
- package/gs/path/filepath/meta.json +6 -0
- package/gs/path/filepath/path.test.ts +57 -2
- package/gs/path/filepath/path.ts +91 -12
- package/gs/reflect/field.test.ts +63 -0
- package/gs/reflect/index.ts +4 -1
- package/gs/reflect/iter.ts +2 -2
- package/gs/reflect/map.test.ts +24 -2
- package/gs/reflect/map.ts +35 -0
- package/gs/reflect/type.ts +543 -60
- package/gs/reflect/typefor.test.ts +100 -0
- package/gs/reflect/types.ts +3 -1
- package/gs/reflect/value.ts +50 -1
- package/gs/reflect/visiblefields.ts +1 -1
- package/gs/runtime/debug/index.test.ts +22 -1
- package/gs/runtime/debug/index.ts +88 -0
- package/gs/runtime/pprof/index.test.ts +36 -0
- package/gs/runtime/pprof/index.ts +104 -0
- package/gs/runtime/pprof/meta.json +6 -0
- package/gs/runtime/trace/index.test.ts +45 -0
- package/gs/runtime/trace/index.ts +97 -0
- package/gs/runtime/trace/meta.json +7 -0
- package/gs/slices/meta.json +2 -1
- package/gs/slices/slices.test.ts +86 -0
- package/gs/slices/slices.ts +284 -37
- package/gs/sort/slice.gs.ts +73 -23
- package/gs/sort/slice.test.ts +40 -0
- package/gs/strings/builder.test.ts +8 -0
- package/gs/strings/builder.ts +29 -17
- package/gs/strings/iter.test.ts +5 -7
- package/gs/strings/iter.ts +146 -71
- package/gs/strings/replace.test.ts +1 -4
- package/gs/strings/replace.ts +6 -6
- package/gs/strings/strings.test.ts +4 -0
- package/gs/strings/strings.ts +54 -6
- package/gs/sync/meta.json +1 -0
- package/gs/sync/sync.test.ts +57 -1
- package/gs/sync/sync.ts +45 -13
- package/gs/syscall/errors.ts +158 -115
- package/gs/syscall/fs.ts +8 -8
- package/gs/syscall/js/index.ts +49 -22
- package/gs/syscall/net.test.ts +26 -0
- package/gs/syscall/types.ts +7 -2
- package/gs/testing/testing.test.ts +56 -0
- package/gs/testing/testing.ts +27 -10
- package/gs/time/meta.json +2 -2
- package/gs/time/time.test.ts +4 -0
- package/gs/time/time.ts +33 -2
- package/gs/unicode/unicode.test.ts +14 -3
- package/gs/unicode/unicode.ts +1 -5
- package/gs/unique/index.ts +9 -2
- package/package.json +3 -3
package/gs/io/fs/readlink.ts
CHANGED
|
@@ -9,56 +9,48 @@ export type ReadLinkFS =
|
|
|
9
9
|
Lstat(name: string): [FileInfo, $.GoError]
|
|
10
10
|
} & FS)
|
|
11
11
|
|
|
12
|
-
$.registerInterfaceType(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
name: '
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
name: 'Error',
|
|
30
|
-
args: [],
|
|
31
|
-
returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
},
|
|
12
|
+
$.registerInterfaceType('ReadLinkFS', null, [
|
|
13
|
+
{
|
|
14
|
+
name: 'ReadLink',
|
|
15
|
+
args: [{ name: 'name', type: { kind: $.TypeKind.Basic, name: 'string' } }],
|
|
16
|
+
returns: [
|
|
17
|
+
{ type: { kind: $.TypeKind.Basic, name: 'string' } },
|
|
18
|
+
{
|
|
19
|
+
type: {
|
|
20
|
+
kind: $.TypeKind.Interface,
|
|
21
|
+
name: 'GoError',
|
|
22
|
+
methods: [
|
|
23
|
+
{
|
|
24
|
+
name: 'Error',
|
|
25
|
+
args: [],
|
|
26
|
+
returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
35
29
|
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
],
|
|
56
|
-
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'Lstat',
|
|
35
|
+
args: [{ name: 'name', type: { kind: $.TypeKind.Basic, name: 'string' } }],
|
|
36
|
+
returns: [
|
|
37
|
+
{ type: 'FileInfo' },
|
|
38
|
+
{
|
|
39
|
+
type: {
|
|
40
|
+
kind: $.TypeKind.Interface,
|
|
41
|
+
name: 'GoError',
|
|
42
|
+
methods: [
|
|
43
|
+
{
|
|
44
|
+
name: 'Error',
|
|
45
|
+
args: [],
|
|
46
|
+
returns: [{ type: { kind: $.TypeKind.Basic, name: 'string' } }],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
57
49
|
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
)
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
])
|
|
62
54
|
|
|
63
55
|
export function ReadLink(fsys: FS, name: string): [string, $.GoError] {
|
|
64
56
|
const { value: sym, ok } = $.typeAssert<ReadLinkFS>(fsys, 'ReadLinkFS')
|
package/gs/io/fs/walk.ts
CHANGED
|
@@ -12,7 +12,11 @@ export let SkipDir: $.GoError = errors.New('skip this directory')
|
|
|
12
12
|
export let SkipAll: $.GoError = errors.New('skip everything and stop the walk')
|
|
13
13
|
|
|
14
14
|
export type WalkDirFunc =
|
|
15
|
-
| ((
|
|
15
|
+
| ((
|
|
16
|
+
path: string,
|
|
17
|
+
d: DirEntry,
|
|
18
|
+
err: $.GoError,
|
|
19
|
+
) => $.GoError | Promise<$.GoError>)
|
|
16
20
|
| null
|
|
17
21
|
|
|
18
22
|
// walkDir recursively descends path, calling walkDirFn.
|
|
@@ -79,7 +83,11 @@ export async function walkDir(
|
|
|
79
83
|
//
|
|
80
84
|
// WalkDir does not follow symbolic links found in directories,
|
|
81
85
|
// but if root itself is a symbolic link, its target will be walked.
|
|
82
|
-
export async function WalkDir(
|
|
86
|
+
export async function WalkDir(
|
|
87
|
+
fsys: FS,
|
|
88
|
+
root: string,
|
|
89
|
+
fn: WalkDirFunc,
|
|
90
|
+
): Promise<$.GoError> {
|
|
83
91
|
let [info, err] = Stat(fsys, root)
|
|
84
92
|
if (err != null) {
|
|
85
93
|
err = await fn!(root, null, err)
|
package/gs/io/io.test.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as $ from '@goscript/builtin/index.js'
|
|
2
|
+
import { LimitedReader, MultiWriter, TeeReader } from './index.js'
|
|
3
|
+
import { describe, expect, test } from 'vitest'
|
|
4
|
+
|
|
5
|
+
class sliceReader {
|
|
6
|
+
constructor(private data: Uint8Array) {}
|
|
7
|
+
|
|
8
|
+
Read(p: $.Bytes): [number, $.GoError] {
|
|
9
|
+
const n = Math.min($.len(p), this.data.length)
|
|
10
|
+
p!.set(this.data.subarray(0, n), 0)
|
|
11
|
+
this.data = this.data.subarray(n)
|
|
12
|
+
return [n, n === 0 ? new Error('EOF') as $.GoError : null]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class captureWriter {
|
|
17
|
+
public chunks: number[] = []
|
|
18
|
+
|
|
19
|
+
Write(p: $.Bytes): [number, $.GoError] {
|
|
20
|
+
this.chunks.push(...Array.from(p ?? []))
|
|
21
|
+
return [$.len(p), null]
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('io override', () => {
|
|
26
|
+
test('LimitedReader accepts generated struct-literal construction', async () => {
|
|
27
|
+
const reader = new LimitedReader({
|
|
28
|
+
R: new sliceReader($.stringToBytes('abcdef')),
|
|
29
|
+
N: 3,
|
|
30
|
+
})
|
|
31
|
+
const buf = new Uint8Array(8)
|
|
32
|
+
|
|
33
|
+
const [n, err] = await reader.Read(buf)
|
|
34
|
+
|
|
35
|
+
expect(err).toBeNull()
|
|
36
|
+
expect(n).toBe(3)
|
|
37
|
+
expect(Buffer.from(buf.subarray(0, n)).toString('utf8')).toBe('abc')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('TeeReader accepts nullable generated interface values', () => {
|
|
41
|
+
const writer = new captureWriter()
|
|
42
|
+
const reader = TeeReader(new sliceReader($.stringToBytes('abc')), writer)
|
|
43
|
+
const buf = new Uint8Array(4)
|
|
44
|
+
|
|
45
|
+
const [n, err] = reader.Read(buf)
|
|
46
|
+
|
|
47
|
+
expect(err).toBeNull()
|
|
48
|
+
expect(n).toBe(3)
|
|
49
|
+
expect(Buffer.from(writer.chunks).toString('utf8')).toBe('abc')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('MultiWriter accepts nullable generated interface values', () => {
|
|
53
|
+
const first = new captureWriter()
|
|
54
|
+
const second = new captureWriter()
|
|
55
|
+
const writer = MultiWriter(first, second)
|
|
56
|
+
|
|
57
|
+
const [n, err] = writer.Write($.stringToBytes('abc'))
|
|
58
|
+
|
|
59
|
+
expect(err).toBeNull()
|
|
60
|
+
expect(n).toBe(3)
|
|
61
|
+
expect(Buffer.from(first.chunks).toString('utf8')).toBe('abc')
|
|
62
|
+
expect(Buffer.from(second.chunks).toString('utf8')).toBe('abc')
|
|
63
|
+
})
|
|
64
|
+
})
|
package/gs/io/io.ts
CHANGED
|
@@ -232,7 +232,7 @@ class DiscardWriter implements Writer {
|
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
export const Discard: Writer = new DiscardWriter()
|
|
235
|
+
export const Discard: Writer | null = new DiscardWriter()
|
|
236
236
|
|
|
237
237
|
// WriteString writes the contents of the string s to w, which accepts a slice of bytes
|
|
238
238
|
export function WriteString(w: Writer, s: string): [number, $.GoError] {
|
|
@@ -248,12 +248,18 @@ export function WriteString(w: Writer, s: string): [number, $.GoError] {
|
|
|
248
248
|
|
|
249
249
|
// LimitedReader reads from R but limits the amount of data returned to just N bytes
|
|
250
250
|
export class LimitedReader implements Reader {
|
|
251
|
-
public R: Reader
|
|
251
|
+
public R: Reader | null
|
|
252
252
|
public N: number
|
|
253
253
|
|
|
254
|
-
constructor(r
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
constructor(r?: Reader | { R?: Reader | null; N?: number } | null, n?: number) {
|
|
255
|
+
if (r != null && typeof (r as { Read?: unknown }).Read !== 'function') {
|
|
256
|
+
const init = r as { R?: Reader | null; N?: number }
|
|
257
|
+
this.R = init.R ?? null
|
|
258
|
+
this.N = init.N ?? 0
|
|
259
|
+
return
|
|
260
|
+
}
|
|
261
|
+
this.R = (r as Reader | null | undefined) ?? null
|
|
262
|
+
this.N = n ?? 0
|
|
257
263
|
}
|
|
258
264
|
|
|
259
265
|
Read(p: $.Bytes): [number, $.GoError] {
|
|
@@ -261,6 +267,9 @@ export class LimitedReader implements Reader {
|
|
|
261
267
|
if (this.N <= 0) {
|
|
262
268
|
return [0, EOF]
|
|
263
269
|
}
|
|
270
|
+
if (this.R == null) {
|
|
271
|
+
throw new Error('io.LimitedReader: nil reader')
|
|
272
|
+
}
|
|
264
273
|
|
|
265
274
|
let readBuf = p
|
|
266
275
|
if ($.len(p) > this.N) {
|
|
@@ -547,7 +556,10 @@ export async function ReadAtLeast(
|
|
|
547
556
|
}
|
|
548
557
|
|
|
549
558
|
// ReadFull reads exactly len(buf) bytes from r into buf
|
|
550
|
-
export async function ReadFull(
|
|
559
|
+
export async function ReadFull(
|
|
560
|
+
r: Reader,
|
|
561
|
+
buf: $.Bytes,
|
|
562
|
+
): Promise<[number, $.GoError]> {
|
|
551
563
|
return await ReadAtLeast(r, buf, $.len(buf))
|
|
552
564
|
}
|
|
553
565
|
|
|
@@ -642,19 +654,22 @@ class multiReader implements Reader {
|
|
|
642
654
|
}
|
|
643
655
|
|
|
644
656
|
// MultiWriter creates a writer that duplicates its writes to all the provided writers
|
|
645
|
-
export function MultiWriter(...writers: Writer[]): Writer {
|
|
657
|
+
export function MultiWriter(...writers: (Writer | null)[]): Writer {
|
|
646
658
|
return new multiWriter(writers.slice())
|
|
647
659
|
}
|
|
648
660
|
|
|
649
661
|
class multiWriter implements Writer {
|
|
650
|
-
private writers: Writer[]
|
|
662
|
+
private writers: (Writer | null)[]
|
|
651
663
|
|
|
652
|
-
constructor(writers: Writer[]) {
|
|
664
|
+
constructor(writers: (Writer | null)[]) {
|
|
653
665
|
this.writers = writers
|
|
654
666
|
}
|
|
655
667
|
|
|
656
668
|
Write(p: $.Bytes): [number, $.GoError] {
|
|
657
669
|
for (const w of this.writers) {
|
|
670
|
+
if (w == null) {
|
|
671
|
+
throw new Error('io.MultiWriter: nil writer')
|
|
672
|
+
}
|
|
658
673
|
const [n, err] = w.Write(p)
|
|
659
674
|
if (err !== null) {
|
|
660
675
|
return [n, err]
|
|
@@ -668,22 +683,28 @@ class multiWriter implements Writer {
|
|
|
668
683
|
}
|
|
669
684
|
|
|
670
685
|
// TeeReader returns a Reader that writes to w what it reads from r
|
|
671
|
-
export function TeeReader(r: Reader, w: Writer): Reader {
|
|
686
|
+
export function TeeReader(r: Reader | null, w: Writer | null): Reader {
|
|
672
687
|
return new teeReader(r, w)
|
|
673
688
|
}
|
|
674
689
|
|
|
675
690
|
class teeReader implements Reader {
|
|
676
|
-
private r: Reader
|
|
677
|
-
private w: Writer
|
|
691
|
+
private r: Reader | null
|
|
692
|
+
private w: Writer | null
|
|
678
693
|
|
|
679
|
-
constructor(r: Reader, w: Writer) {
|
|
694
|
+
constructor(r: Reader | null, w: Writer | null) {
|
|
680
695
|
this.r = r
|
|
681
696
|
this.w = w
|
|
682
697
|
}
|
|
683
698
|
|
|
684
699
|
Read(p: $.Bytes): [number, $.GoError] {
|
|
700
|
+
if (this.r == null) {
|
|
701
|
+
throw new Error('io.TeeReader: nil reader')
|
|
702
|
+
}
|
|
685
703
|
const [n, err] = this.r.Read(p)
|
|
686
704
|
if (n > 0) {
|
|
705
|
+
if (this.w == null) {
|
|
706
|
+
throw new Error('io.TeeReader: nil writer')
|
|
707
|
+
}
|
|
687
708
|
const [nw, ew] = this.w.Write($.goSlice(p, 0, n))
|
|
688
709
|
if (ew !== null) {
|
|
689
710
|
return [n, ew]
|
package/gs/iter/iter.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
// TypeScript implementation of Go's iter package
|
|
2
2
|
// This provides iterator types and functions
|
|
3
3
|
|
|
4
|
+
export type YieldResult = boolean | globalThis.Promise<boolean>
|
|
5
|
+
|
|
4
6
|
// Seq is an iterator over sequences of individual values
|
|
5
|
-
export type Seq<V> = (
|
|
7
|
+
export type Seq<V> = (
|
|
8
|
+
_yield: ((value: V) => YieldResult) | null,
|
|
9
|
+
) => void | globalThis.Promise<void>
|
|
6
10
|
|
|
7
11
|
// Seq2 is an iterator over sequences of pairs of values
|
|
8
|
-
export type Seq2<K, V> = (
|
|
12
|
+
export type Seq2<K, V> = (
|
|
13
|
+
_yield: ((key: K, value: V) => YieldResult) | null,
|
|
14
|
+
) => void | globalThis.Promise<void>
|
|
9
15
|
|
|
10
16
|
// Pull converts the "push-style" iterator sequence seq into a "pull-style" iterator
|
|
11
17
|
// Returns a function that returns the next value and a boolean indicating if iteration should continue
|
package/gs/maps/iter.ts
CHANGED
|
@@ -5,51 +5,39 @@ import * as iter from '@goscript/iter/index.js'
|
|
|
5
5
|
// All returns an iterator over key-value pairs from m.
|
|
6
6
|
// The iteration order is not specified and is not guaranteed
|
|
7
7
|
// to be the same from one call to the next.
|
|
8
|
-
export function All<K extends $.Comparable, V>(
|
|
8
|
+
export function All<K extends $.Comparable | null, V>(
|
|
9
9
|
m: Map<K, V> | null,
|
|
10
10
|
): iter.Seq2<K, V> {
|
|
11
|
-
return (_yield: ((p0: K, p1: V) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
11
|
+
return (_yield: ((p0: K, p1: V) => iter.YieldResult) | null):
|
|
12
|
+
| void
|
|
13
|
+
| globalThis.Promise<void> => iteratePairs(m?.entries() ?? [], _yield)
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
// Keys returns an iterator over keys in m.
|
|
21
17
|
// The iteration order is not specified and is not guaranteed
|
|
22
18
|
// to be the same from one call to the next.
|
|
23
|
-
export function Keys<K extends $.Comparable, V>(
|
|
19
|
+
export function Keys<K extends $.Comparable | null, V>(
|
|
24
20
|
m: Map<K, V> | null,
|
|
25
21
|
): iter.Seq<K> {
|
|
26
|
-
return (_yield: ((p0: K) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
22
|
+
return (_yield: ((p0: K) => iter.YieldResult) | null):
|
|
23
|
+
| void
|
|
24
|
+
| globalThis.Promise<void> => iterateValues(mapKeys(m), _yield)
|
|
33
25
|
}
|
|
34
26
|
|
|
35
27
|
// Values returns an iterator over values in m.
|
|
36
28
|
// The iteration order is not specified and is not guaranteed
|
|
37
29
|
// to be the same from one call to the next.
|
|
38
|
-
export function Values<K extends $.Comparable, V>(
|
|
30
|
+
export function Values<K extends $.Comparable | null, V>(
|
|
39
31
|
m: Map<K, V> | null,
|
|
40
32
|
): iter.Seq<V> {
|
|
41
|
-
return (_yield: ((p0: V) =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
33
|
+
return (_yield: ((p0: V) => iter.YieldResult) | null):
|
|
34
|
+
| void
|
|
35
|
+
| globalThis.Promise<void> => iterateValues(mapValues(m), _yield)
|
|
48
36
|
}
|
|
49
37
|
|
|
50
38
|
// Insert adds the key-value pairs from seq to m.
|
|
51
39
|
// If a key in seq already exists in m, its value will be overwritten.
|
|
52
|
-
export function Insert<K extends $.Comparable, V>(
|
|
40
|
+
export function Insert<K extends $.Comparable | null, V>(
|
|
53
41
|
m: Map<K, V>,
|
|
54
42
|
seq: iter.Seq2<K, V>,
|
|
55
43
|
): void {
|
|
@@ -64,10 +52,65 @@ export function Insert<K extends $.Comparable, V>(
|
|
|
64
52
|
|
|
65
53
|
// Collect collects key-value pairs from seq into a new map
|
|
66
54
|
// and returns it.
|
|
67
|
-
export function Collect<K extends $.Comparable, V>(
|
|
55
|
+
export function Collect<K extends $.Comparable | null, V>(
|
|
68
56
|
seq: iter.Seq2<K, V>,
|
|
69
57
|
): Map<K, V> {
|
|
70
58
|
let m = $.makeMap<K, V>()
|
|
71
59
|
Insert(m, seq)
|
|
72
60
|
return m
|
|
73
61
|
}
|
|
62
|
+
|
|
63
|
+
function mapKeys<K extends $.Comparable | null, V>(m: Map<K, V> | null): K[] {
|
|
64
|
+
return Array.from(m?.keys() ?? [])
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function mapValues<K extends $.Comparable | null, V>(m: Map<K, V> | null): V[] {
|
|
68
|
+
return Array.from(m?.values() ?? [])
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function iterateValues<T>(
|
|
72
|
+
values: Iterable<T>,
|
|
73
|
+
yieldValue: ((value: T) => iter.YieldResult) | null,
|
|
74
|
+
): void | globalThis.Promise<void> {
|
|
75
|
+
const items = Array.from(values)
|
|
76
|
+
const walk = (idx: number): void | globalThis.Promise<void> => {
|
|
77
|
+
for (; idx < items.length; idx++) {
|
|
78
|
+
const keepGoing = yieldValue!(items[idx])
|
|
79
|
+
if (keepGoing instanceof Promise) {
|
|
80
|
+
return keepGoing.then((next) => {
|
|
81
|
+
if (next) {
|
|
82
|
+
return walk(idx + 1)
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
if (!keepGoing) {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return walk(0)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function iteratePairs<K, V>(
|
|
95
|
+
entries: Iterable<[K, V]>,
|
|
96
|
+
yieldValue: ((key: K, value: V) => iter.YieldResult) | null,
|
|
97
|
+
): void | globalThis.Promise<void> {
|
|
98
|
+
const items = Array.from(entries)
|
|
99
|
+
const walk = (idx: number): void | globalThis.Promise<void> => {
|
|
100
|
+
for (; idx < items.length; idx++) {
|
|
101
|
+
const [key, value] = items[idx]
|
|
102
|
+
const keepGoing = yieldValue!(key, value)
|
|
103
|
+
if (keepGoing instanceof Promise) {
|
|
104
|
+
return keepGoing.then((next) => {
|
|
105
|
+
if (next) {
|
|
106
|
+
return walk(idx + 1)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
if (!keepGoing) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return walk(0)
|
|
116
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { Clone, Values } from './index.js'
|
|
4
|
+
|
|
5
|
+
describe('maps overrides', () => {
|
|
6
|
+
it('accept nilable comparable keys', () => {
|
|
7
|
+
const source = new Map<object | null, number>()
|
|
8
|
+
const key = { name: 'type' }
|
|
9
|
+
source.set(null, 1)
|
|
10
|
+
source.set(key, 2)
|
|
11
|
+
|
|
12
|
+
const cloned = Clone(source)
|
|
13
|
+
expect(cloned?.get(null)).toBe(1)
|
|
14
|
+
expect(cloned?.get(key)).toBe(2)
|
|
15
|
+
|
|
16
|
+
const values: number[] = []
|
|
17
|
+
Values(cloned)((value) => {
|
|
18
|
+
values.push(value)
|
|
19
|
+
return true
|
|
20
|
+
})
|
|
21
|
+
expect(values.sort()).toEqual([1, 2])
|
|
22
|
+
})
|
|
23
|
+
})
|
package/gs/maps/maps.ts
CHANGED
|
@@ -4,7 +4,7 @@ import * as _ from '@goscript/unsafe/index.js'
|
|
|
4
4
|
|
|
5
5
|
// Equal reports whether two maps contain the same key/value pairs.
|
|
6
6
|
// Values are compared using ==.
|
|
7
|
-
export function Equal<K extends $.Comparable, V extends $.Comparable>(
|
|
7
|
+
export function Equal<K extends $.Comparable | null, V extends $.Comparable | null>(
|
|
8
8
|
m1: Map<K, V>,
|
|
9
9
|
m2: Map<K, V>,
|
|
10
10
|
): boolean {
|
|
@@ -22,7 +22,7 @@ export function Equal<K extends $.Comparable, V extends $.Comparable>(
|
|
|
22
22
|
|
|
23
23
|
// EqualFunc is like Equal, but compares values using eq.
|
|
24
24
|
// Keys are still compared with ==.
|
|
25
|
-
export function EqualFunc<K extends $.Comparable, V1, V2>(
|
|
25
|
+
export function EqualFunc<K extends $.Comparable | null, V1, V2>(
|
|
26
26
|
m1: Map<K, V1>,
|
|
27
27
|
m2: Map<K, V2>,
|
|
28
28
|
eq: ((p0: V1, p1: V2) => boolean) | null,
|
|
@@ -40,7 +40,7 @@ export function EqualFunc<K extends $.Comparable, V1, V2>(
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// clone returns a shallow copy of the map.
|
|
43
|
-
export function clone<K extends $.Comparable, V>(
|
|
43
|
+
export function clone<K extends $.Comparable | null, V>(
|
|
44
44
|
m: Map<K, V> | null,
|
|
45
45
|
): Map<K, V> | null {
|
|
46
46
|
if (m == null) {
|
|
@@ -55,7 +55,7 @@ export function clone<K extends $.Comparable, V>(
|
|
|
55
55
|
|
|
56
56
|
// Clone returns a copy of m. This is a shallow clone:
|
|
57
57
|
// the new keys and values are set using ordinary assignment.
|
|
58
|
-
export function Clone<K extends $.Comparable, V>(
|
|
58
|
+
export function Clone<K extends $.Comparable | null, V>(
|
|
59
59
|
m: Map<K, V> | null,
|
|
60
60
|
): Map<K, V> | null {
|
|
61
61
|
// Preserve nil in case it matters.
|
|
@@ -69,7 +69,7 @@ export function Clone<K extends $.Comparable, V>(
|
|
|
69
69
|
// When a key in src is already present in dst,
|
|
70
70
|
// the value in dst will be overwritten by the value associated
|
|
71
71
|
// with the key in src.
|
|
72
|
-
export function Copy<K extends $.Comparable, V>(
|
|
72
|
+
export function Copy<K extends $.Comparable | null, V>(
|
|
73
73
|
dst: Map<K, V> | null,
|
|
74
74
|
src: Map<K, V> | null,
|
|
75
75
|
): void {
|
|
@@ -79,7 +79,7 @@ export function Copy<K extends $.Comparable, V>(
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// DeleteFunc deletes any key/value pairs from m for which del returns true.
|
|
82
|
-
export function DeleteFunc<K extends $.Comparable, V>(
|
|
82
|
+
export function DeleteFunc<K extends $.Comparable | null, V>(
|
|
83
83
|
m: Map<K, V>,
|
|
84
84
|
del: ((p0: K, p1: V) => boolean) | null,
|
|
85
85
|
): void {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import { Mul64 } from './index.js'
|
|
4
|
+
|
|
5
|
+
describe('math/bits override', () => {
|
|
6
|
+
it('returns the full 128-bit product from Mul64', () => {
|
|
7
|
+
expect(Mul64(0xffffffffffffffffn, 0xffffffffffffffffn)).toEqual([
|
|
8
|
+
0xfffffffffffffffen,
|
|
9
|
+
1n,
|
|
10
|
+
])
|
|
11
|
+
expect(Mul64(0x1fffffffffffffn, 0x1fffffffffffffn)).toEqual([
|
|
12
|
+
0x3ffffffffffn,
|
|
13
|
+
0xffc0000000000001n,
|
|
14
|
+
])
|
|
15
|
+
expect(Mul64(0x1fffffffffffff, 0x1fffffffffffff)).toEqual([
|
|
16
|
+
0x3ffffffffff,
|
|
17
|
+
0xffc0000000000001n,
|
|
18
|
+
])
|
|
19
|
+
})
|
|
20
|
+
})
|
package/gs/math/bits/index.ts
CHANGED
|
@@ -17,7 +17,9 @@ function useBigIntResult(...values: Word64[]): boolean {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function word64Result(value: bigint, useBigInt: boolean): Word64 {
|
|
20
|
-
return useBigInt
|
|
20
|
+
return useBigInt || value > BigInt(Number.MAX_SAFE_INTEGER) ?
|
|
21
|
+
value
|
|
22
|
+
: Number(value)
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
// --- Leading zeros ---
|
|
@@ -209,20 +211,16 @@ export function Reverse64(x: Word64): Word64 {
|
|
|
209
211
|
((word & 0x0000ffff0000ffffn) << 16n)
|
|
210
212
|
// Swap 8-bit chunks
|
|
211
213
|
word =
|
|
212
|
-
((word & 0xff00ff00ff00ff00n) >> 8n) |
|
|
213
|
-
((word & 0x00ff00ff00ff00ffn) << 8n)
|
|
214
|
+
((word & 0xff00ff00ff00ff00n) >> 8n) | ((word & 0x00ff00ff00ff00ffn) << 8n)
|
|
214
215
|
// Swap 4-bit chunks
|
|
215
216
|
word =
|
|
216
|
-
((word & 0xf0f0f0f0f0f0f0f0n) >> 4n) |
|
|
217
|
-
((word & 0x0f0f0f0f0f0f0f0fn) << 4n)
|
|
217
|
+
((word & 0xf0f0f0f0f0f0f0f0n) >> 4n) | ((word & 0x0f0f0f0f0f0f0f0fn) << 4n)
|
|
218
218
|
// Swap 2-bit chunks
|
|
219
219
|
word =
|
|
220
|
-
((word & 0xccccccccccccccccn) >> 2n) |
|
|
221
|
-
((word & 0x3333333333333333n) << 2n)
|
|
220
|
+
((word & 0xccccccccccccccccn) >> 2n) | ((word & 0x3333333333333333n) << 2n)
|
|
222
221
|
// Swap 1-bit chunks
|
|
223
222
|
word =
|
|
224
|
-
((word & 0xaaaaaaaaaaaaaaaan) >> 1n) |
|
|
225
|
-
((word & 0x5555555555555555n) << 1n)
|
|
223
|
+
((word & 0xaaaaaaaaaaaaaaaan) >> 1n) | ((word & 0x5555555555555555n) << 1n)
|
|
226
224
|
|
|
227
225
|
return word64Result(word & uint64Mask, useBigInt)
|
|
228
226
|
}
|
|
@@ -307,25 +305,14 @@ export function Mul64(x: Word64, y: Word64): [Word64, Word64] {
|
|
|
307
305
|
const useBigInt = useBigIntResult(x, y)
|
|
308
306
|
x = toUint64(x)
|
|
309
307
|
y = toUint64(y)
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
// Multiply parts
|
|
319
|
-
const p00 = x0 * y0
|
|
320
|
-
const p01 = x0 * y1
|
|
321
|
-
const p10 = x1 * y0
|
|
322
|
-
const p11 = x1 * y1
|
|
323
|
-
|
|
324
|
-
// Combine results
|
|
325
|
-
const lo = p00 + ((p01 + p10) << 32n)
|
|
326
|
-
const hi = p11 + ((p01 + p10) >> 32n) + (lo < p00 ? 1n : 0n)
|
|
327
|
-
|
|
328
|
-
return [word64Result(hi & uint64Mask, useBigInt), word64Result(lo & uint64Mask, useBigInt)]
|
|
308
|
+
const product = x * y
|
|
309
|
+
const lo = product & uint64Mask
|
|
310
|
+
const hi = product >> 64n
|
|
311
|
+
|
|
312
|
+
return [
|
|
313
|
+
word64Result(hi & uint64Mask, useBigInt),
|
|
314
|
+
word64Result(lo, useBigInt),
|
|
315
|
+
]
|
|
329
316
|
}
|
|
330
317
|
|
|
331
318
|
// --- Division functions ---
|
package/gs/mime/index.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
export function FormatMediaType(
|
|
1
|
+
export function FormatMediaType(
|
|
2
|
+
t: string,
|
|
3
|
+
param: Map<string, string> | Record<string, string> | null,
|
|
4
|
+
): string {
|
|
2
5
|
if (!isToken(t)) {
|
|
3
6
|
return ''
|
|
4
7
|
}
|
|
5
8
|
let out = t
|
|
6
|
-
const entries =
|
|
9
|
+
const entries =
|
|
10
|
+
param instanceof Map ?
|
|
11
|
+
Array.from(param.entries())
|
|
12
|
+
: Object.entries(param ?? {})
|
|
7
13
|
entries.sort(([a], [b]) => a.localeCompare(b))
|
|
8
14
|
for (const [key, value] of entries) {
|
|
9
15
|
if (!isToken(key)) {
|