goscript 0.1.0 → 0.1.2
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/README.md +267 -255
- package/cmd/goscript/cmd-test.go +286 -0
- package/cmd/goscript/cmd-test_test.go +76 -0
- package/cmd/goscript/cmd_compile.go +9 -0
- package/cmd/goscript/main.go +1 -0
- package/compiler/build-flags.go +38 -0
- package/compiler/compile-request.go +33 -0
- package/compiler/compiler.go +1 -1
- package/compiler/compliance_test.go +0 -10
- package/compiler/config.go +2 -0
- package/compiler/gotest/owner.go +24 -0
- package/compiler/gotest/package-result.go +69 -0
- package/compiler/gotest/request.go +210 -0
- package/compiler/gotest/result.go +28 -0
- package/compiler/gotest/runner.go +1225 -0
- package/compiler/gotest/runner_test.go +1271 -0
- package/compiler/gotest/test.go +9 -0
- package/compiler/index.test.ts +1 -1
- package/compiler/lowered-program.go +80 -21
- package/compiler/lowering.go +6754 -602
- package/compiler/override-facts.go +357 -0
- package/compiler/override-registry.go +52 -190
- package/compiler/override-registry_test.go +182 -0
- package/compiler/package-graph.go +50 -27
- package/compiler/package-graph_test.go +99 -9
- package/compiler/package-test-function.go +9 -0
- package/compiler/package-test-graph-package.go +40 -0
- package/compiler/package-test-graph-variant.go +129 -0
- package/compiler/package-test-graph.go +112 -0
- package/compiler/package-test-graph_test.go +202 -0
- package/compiler/runtime-contract.go +229 -29
- package/compiler/runtime-contract_test.go +44 -30
- package/compiler/semantic-model-types.go +25 -6
- package/compiler/semantic-model.go +819 -74
- package/compiler/semantic-model_test.go +104 -0
- package/compiler/service.go +10 -4
- package/compiler/skeleton_test.go +2777 -524
- package/compiler/tsworkspace/owner-process-unix_test.go +72 -0
- package/compiler/tsworkspace/owner.go +342 -0
- package/compiler/tsworkspace/owner_test.go +93 -0
- package/compiler/tsworkspace/result.go +17 -0
- package/compiler/tsworkspace/tool-process-other.go +14 -0
- package/compiler/tsworkspace/tool-process-unix.go +19 -0
- package/compiler/typescript-emitter.go +576 -86
- package/compiler/wasm/compile.go +1 -1
- package/compiler/wasm/compile_test.go +61 -11
- package/compiler/wasm_api.go +172 -7
- package/dist/gs/builtin/builtin.d.ts +40 -3
- package/dist/gs/builtin/builtin.js +430 -22
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +32 -10
- package/dist/gs/builtin/channel.js +119 -25
- 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 +64 -10
- package/dist/gs/builtin/slice.js +619 -244
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +7 -2
- package/dist/gs/builtin/type.js +128 -29
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +7 -0
- package/dist/gs/builtin/varRef.js +23 -0
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.js +74 -70
- package/dist/gs/bytes/buffer.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/bytes/reader.gs.js +20 -18
- package/dist/gs/bytes/reader.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 +6 -5
- package/dist/gs/context/context.js +17 -12
- 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/internal/fips140deps/byteorder/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/byteorder/index.js.map +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.d.ts +1 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/index.js +2 -0
- package/dist/gs/crypto/internal/fips140deps/godebug/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/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/embed/index.d.ts +7 -0
- package/dist/gs/embed/index.js +16 -0
- package/dist/gs/embed/index.js.map +1 -0
- package/dist/gs/encoding/json/index.d.ts +4 -0
- package/dist/gs/encoding/json/index.js +33 -0
- package/dist/gs/encoding/json/index.js.map +1 -1
- package/dist/gs/errors/errors.d.ts +4 -0
- package/dist/gs/errors/errors.js +108 -4
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.d.ts +4 -4
- package/dist/gs/fmt/fmt.js +42 -11
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +37 -2
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +245 -1
- 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.d.ts +189 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +861 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +217 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +814 -0
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -0
- 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.d.ts +9 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js +72 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -0
- 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/internal/scannerhooks/index.d.ts +3 -0
- package/dist/gs/go/internal/scannerhooks/index.js +5 -0
- package/dist/gs/go/internal/scannerhooks/index.js.map +1 -0
- package/dist/gs/go/scanner/index.d.ts +13 -0
- package/dist/gs/go/scanner/index.js +35 -0
- package/dist/gs/go/scanner/index.js.map +1 -1
- package/dist/gs/go/token/index.d.ts +156 -0
- package/dist/gs/go/token/index.js +507 -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/internal/abi/index.d.ts +4 -0
- package/dist/gs/internal/abi/index.js +10 -0
- package/dist/gs/internal/abi/index.js.map +1 -1
- package/dist/gs/internal/bytealg/index.d.ts +2 -0
- package/dist/gs/internal/bytealg/index.js +14 -0
- package/dist/gs/internal/bytealg/index.js.map +1 -1
- package/dist/gs/internal/byteorder/index.d.ts +8 -2
- package/dist/gs/internal/byteorder/index.js +56 -25
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/internal/godebug/index.d.ts +12 -0
- package/dist/gs/internal/godebug/index.js +30 -0
- package/dist/gs/internal/godebug/index.js.map +1 -0
- package/dist/gs/io/fs/index.d.ts +1 -0
- package/dist/gs/io/fs/index.js +1 -0
- package/dist/gs/io/fs/index.js.map +1 -1
- package/dist/gs/io/fs/readlink.d.ts +8 -0
- package/dist/gs/io/fs/readlink.js +60 -0
- package/dist/gs/io/fs/readlink.js.map +1 -0
- package/dist/gs/io/fs/walk.d.ts +3 -3
- package/dist/gs/io/fs/walk.js +7 -7
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/io/io.d.ts +40 -6
- package/dist/gs/io/io.js +151 -26
- 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/maps/maps.js +1 -1
- package/dist/gs/maps/maps.js.map +1 -1
- package/dist/gs/math/bits/index.d.ts +13 -4
- package/dist/gs/math/bits/index.js +70 -48
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/math/const.gs.d.ts +5 -5
- package/dist/gs/math/const.gs.js +4 -4
- package/dist/gs/math/const.gs.js.map +1 -1
- package/dist/gs/mime/index.d.ts +1 -0
- package/dist/gs/mime/index.js +52 -0
- package/dist/gs/mime/index.js.map +1 -0
- package/dist/gs/net/http/httptest/index.d.ts +30 -0
- package/dist/gs/net/http/httptest/index.js +101 -0
- package/dist/gs/net/http/httptest/index.js.map +1 -0
- package/dist/gs/net/http/index.d.ts +131 -0
- package/dist/gs/net/http/index.js +307 -0
- package/dist/gs/net/http/index.js.map +1 -0
- 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/dir_unix.gs.js +2 -2
- package/dist/gs/os/dir_unix.gs.js.map +1 -1
- 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/path/filepath/match.js +165 -3
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +8 -4
- package/dist/gs/path/filepath/path.js +192 -8
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/path/path.d.ts +4 -1
- package/dist/gs/path/path.js +16 -4
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +4 -3
- package/dist/gs/reflect/index.js +3 -2
- 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 +29 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +31 -9
- package/dist/gs/reflect/type.js +536 -43
- 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 +41 -0
- package/dist/gs/runtime/debug/index.js +66 -0
- package/dist/gs/runtime/debug/index.js.map +1 -0
- 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/runtime.d.ts +35 -3
- package/dist/gs/runtime/runtime.js +72 -0
- package/dist/gs/runtime/runtime.js.map +1 -1
- 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 +42 -8
- package/dist/gs/slices/slices.js +425 -11
- 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 +60 -22
- package/dist/gs/sort/slice.gs.js.map +1 -1
- package/dist/gs/sort/sort.gs.d.ts +4 -4
- package/dist/gs/sort/sort.gs.js +11 -8
- package/dist/gs/sort/sort.gs.js.map +1 -1
- package/dist/gs/strings/builder.d.ts +1 -1
- package/dist/gs/strings/builder.js +29 -19
- 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/atomic/type.gs.d.ts +9 -8
- package/dist/gs/sync/atomic/type.gs.js +0 -2
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +8 -3
- package/dist/gs/sync/sync.js +66 -11
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/constants.d.ts +36 -24
- package/dist/gs/syscall/constants.js +12 -0
- package/dist/gs/syscall/constants.js.map +1 -1
- package/dist/gs/syscall/errors.d.ts +117 -111
- package/dist/gs/syscall/errors.js +45 -0
- package/dist/gs/syscall/errors.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +37 -0
- package/dist/gs/syscall/fs.js +102 -0
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/syscall/js/index.d.ts +90 -0
- package/dist/gs/syscall/js/index.js +383 -0
- package/dist/gs/syscall/js/index.js.map +1 -0
- package/dist/gs/syscall/types.d.ts +26 -1
- package/dist/gs/syscall/types.js +45 -1
- package/dist/gs/syscall/types.js.map +1 -1
- package/dist/gs/testing/index.d.ts +1 -0
- package/dist/gs/testing/index.js +2 -0
- package/dist/gs/testing/index.js.map +1 -0
- package/dist/gs/testing/testing.d.ts +78 -0
- package/dist/gs/testing/testing.js +318 -0
- package/dist/gs/testing/testing.js.map +1 -0
- package/dist/gs/time/time.d.ts +41 -4
- package/dist/gs/time/time.js +227 -36
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/unicode.d.ts +23 -1
- package/dist/gs/unicode/unicode.js +79 -10
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/dist/gs/unicode/utf8/utf8.d.ts +4 -4
- package/dist/gs/unicode/utf8/utf8.js +24 -11
- package/dist/gs/unicode/utf8/utf8.js.map +1 -1
- package/dist/gs/unique/index.d.ts +11 -0
- package/dist/gs/unique/index.js +76 -0
- package/dist/gs/unique/index.js.map +1 -0
- package/go.mod +8 -8
- package/go.sum +14 -14
- package/gs/builtin/builtin.ts +585 -27
- package/gs/builtin/channel.ts +183 -29
- 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 +383 -10
- package/gs/builtin/slice.test.ts +70 -0
- package/gs/builtin/slice.ts +785 -265
- package/gs/builtin/type.ts +160 -41
- package/gs/builtin/varRef.ts +40 -1
- package/gs/bytes/buffer.gs.ts +74 -70
- package/gs/bytes/iter.gs.ts +13 -14
- package/gs/bytes/meta.json +8 -3
- package/gs/bytes/reader.gs.ts +20 -19
- 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 +71 -0
- package/gs/context/context.ts +30 -29
- 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/internal/fips140deps/byteorder/index.ts +1 -0
- package/gs/crypto/internal/fips140deps/godebug/index.ts +1 -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/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/embed/index.ts +20 -0
- package/gs/embed/meta.json +5 -0
- package/gs/encoding/json/index.test.ts +39 -3
- package/gs/encoding/json/index.ts +45 -3
- package/gs/errors/errors.test.ts +85 -0
- package/gs/errors/errors.ts +132 -4
- package/gs/fmt/fmt.test.ts +3 -1
- package/gs/fmt/fmt.ts +55 -19
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +128 -1
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +342 -4
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +180 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +1084 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.test.ts +31 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +1233 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +46 -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 +37 -0
- package/gs/github.com/klauspost/compress/internal/le/index.ts +115 -0
- 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/internal/scannerhooks/index.test.ts +14 -0
- package/gs/go/internal/scannerhooks/index.ts +9 -0
- package/gs/go/scanner/index.test.ts +22 -0
- package/gs/go/scanner/index.ts +47 -0
- package/gs/go/token/index.test.ts +47 -1
- package/gs/go/token/index.ts +583 -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/abi/index.test.ts +18 -0
- package/gs/internal/abi/index.ts +14 -0
- package/gs/internal/bytealg/index.test.ts +18 -0
- package/gs/internal/bytealg/index.ts +16 -0
- package/gs/internal/byteorder/index.test.ts +39 -0
- package/gs/internal/byteorder/index.ts +100 -27
- package/gs/internal/godebug/index.test.ts +16 -0
- package/gs/internal/godebug/index.ts +35 -0
- package/gs/io/fs/index.ts +1 -0
- package/gs/io/fs/meta.json +5 -0
- package/gs/io/fs/readlink.test.ts +43 -0
- package/gs/io/fs/readlink.ts +69 -0
- package/gs/io/fs/walk.test.ts +61 -0
- package/gs/io/fs/walk.ts +17 -9
- package/gs/io/io.ts +177 -31
- package/gs/io/meta.json +10 -2
- package/gs/iter/iter.ts +8 -2
- package/gs/maps/iter.ts +75 -26
- package/gs/maps/maps.test.ts +23 -0
- package/gs/maps/maps.ts +13 -11
- package/gs/math/bits/index.test.ts +20 -0
- package/gs/math/bits/index.ts +107 -64
- package/gs/math/const.gs.test.ts +11 -5
- package/gs/math/const.gs.ts +5 -6
- package/gs/mime/index.ts +60 -0
- package/gs/net/http/httptest/index.test.ts +53 -0
- package/gs/net/http/httptest/index.ts +120 -0
- package/gs/net/http/index.test.ts +148 -0
- package/gs/net/http/index.ts +432 -0
- 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/dir_unix.gs.ts +2 -3
- 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 +96 -17
- package/gs/path/filepath/match.test.ts +31 -12
- package/gs/path/filepath/match.ts +181 -3
- package/gs/path/filepath/meta.json +6 -0
- package/gs/path/filepath/path.test.ts +80 -0
- package/gs/path/filepath/path.ts +244 -11
- package/gs/path/path.ts +20 -5
- package/gs/reflect/field.test.ts +63 -0
- package/gs/reflect/index.ts +5 -1
- package/gs/reflect/iter.ts +2 -2
- package/gs/reflect/map.test.ts +42 -1
- package/gs/reflect/map.ts +39 -0
- package/gs/reflect/type.ts +728 -65
- 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 +45 -0
- package/gs/runtime/debug/index.ts +96 -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/runtime.test.ts +19 -0
- package/gs/runtime/runtime.ts +98 -3
- 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 +180 -0
- package/gs/slices/slices.ts +502 -15
- package/gs/sort/meta.json +7 -0
- package/gs/sort/slice.gs.ts +85 -26
- package/gs/sort/slice.test.ts +40 -0
- package/gs/sort/sort.gs.ts +16 -13
- package/gs/strings/builder.test.ts +8 -0
- package/gs/strings/builder.ts +33 -20
- 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/atomic/type.gs.ts +13 -14
- package/gs/sync/meta.json +3 -1
- package/gs/sync/sync.test.ts +69 -1
- package/gs/sync/sync.ts +72 -13
- package/gs/syscall/constants.ts +39 -24
- package/gs/syscall/errors.ts +165 -112
- package/gs/syscall/fs.ts +195 -0
- package/gs/syscall/js/index.ts +485 -0
- package/gs/syscall/js/meta.json +4 -0
- package/gs/syscall/net.test.ts +111 -0
- package/gs/syscall/types.ts +63 -2
- package/gs/testing/index.ts +1 -0
- package/gs/testing/meta.json +5 -0
- package/gs/testing/testing.test.ts +146 -0
- package/gs/testing/testing.ts +399 -0
- package/gs/time/meta.json +2 -2
- package/gs/time/time.test.ts +110 -0
- package/gs/time/time.ts +309 -57
- package/gs/unicode/unicode.test.ts +36 -0
- package/gs/unicode/unicode.ts +115 -9
- package/gs/unicode/utf8/utf8.test.ts +13 -0
- package/gs/unicode/utf8/utf8.ts +28 -16
- package/gs/unique/index.ts +98 -0
- package/package.json +3 -2
package/dist/gs/reflect/type.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { StructField, StructTag, ValueError } from './types.js';
|
|
1
|
+
import { StructField, StructTag, ValueError, } from './types.js';
|
|
2
2
|
export { StructField };
|
|
3
|
+
import { MapIter } from './map.js';
|
|
3
4
|
import { getTypeByName as builtinGetTypeByName, TypeKind, isStructTypeInfo, isInterfaceTypeInfo, isStructFieldInfo, } from '../builtin/type.js';
|
|
4
5
|
import { Zero } from './value.js';
|
|
5
6
|
import { DeepEqual } from './deepequal.js';
|
|
@@ -150,17 +151,45 @@ export const Slice = 23;
|
|
|
150
151
|
export const String = 24;
|
|
151
152
|
export const Struct = 25;
|
|
152
153
|
export const UnsafePointer = 26;
|
|
154
|
+
const pointerAddressStride = 0x100000000;
|
|
155
|
+
const pointerAddresses = new WeakMap();
|
|
156
|
+
let nextPointerAddress = 1;
|
|
157
|
+
const canonicalTypes = new globalThis.Map();
|
|
158
|
+
function pointerAddress(value) {
|
|
159
|
+
let address = pointerAddresses.get(value);
|
|
160
|
+
if (address === undefined) {
|
|
161
|
+
address = nextPointerAddress * pointerAddressStride;
|
|
162
|
+
nextPointerAddress++;
|
|
163
|
+
pointerAddresses.set(value, address);
|
|
164
|
+
}
|
|
165
|
+
return address;
|
|
166
|
+
}
|
|
167
|
+
function internType(t) {
|
|
168
|
+
const key = `${t.Kind()}:${t.PkgPath()}:${t.Name()}:${t.String()}`;
|
|
169
|
+
const existing = canonicalTypes.get(key);
|
|
170
|
+
if (existing) {
|
|
171
|
+
return existing;
|
|
172
|
+
}
|
|
173
|
+
canonicalTypes.set(key, t);
|
|
174
|
+
return t;
|
|
175
|
+
}
|
|
153
176
|
// InvalidTypeInstance is a singleton type for invalid/zero reflect.Value
|
|
154
177
|
class InvalidTypeClass {
|
|
155
178
|
Kind() {
|
|
156
179
|
return Invalid;
|
|
157
180
|
}
|
|
181
|
+
Comparable() {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
158
184
|
String() {
|
|
159
185
|
return '<invalid reflect.Value>';
|
|
160
186
|
}
|
|
161
187
|
Name() {
|
|
162
188
|
return '';
|
|
163
189
|
}
|
|
190
|
+
PkgPath() {
|
|
191
|
+
return '';
|
|
192
|
+
}
|
|
164
193
|
Size() {
|
|
165
194
|
return 0;
|
|
166
195
|
}
|
|
@@ -176,9 +205,18 @@ class InvalidTypeClass {
|
|
|
176
205
|
Field(_i) {
|
|
177
206
|
throw new Error('reflect: Field of invalid type');
|
|
178
207
|
}
|
|
208
|
+
FieldByName(_name) {
|
|
209
|
+
return [new StructField(), false];
|
|
210
|
+
}
|
|
211
|
+
FieldByNameFunc(_match) {
|
|
212
|
+
return [new StructField(), false];
|
|
213
|
+
}
|
|
179
214
|
Implements(_u) {
|
|
180
215
|
return false;
|
|
181
216
|
}
|
|
217
|
+
AssignableTo(_u) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
182
220
|
OverflowInt(_x) {
|
|
183
221
|
throw new Error('reflect: OverflowInt of invalid type');
|
|
184
222
|
}
|
|
@@ -191,6 +229,12 @@ class InvalidTypeClass {
|
|
|
191
229
|
NumMethod() {
|
|
192
230
|
return 0;
|
|
193
231
|
}
|
|
232
|
+
MethodByName(_name) {
|
|
233
|
+
return [zeroMethod(), false];
|
|
234
|
+
}
|
|
235
|
+
Len() {
|
|
236
|
+
throw new Error('reflect: Len of invalid type');
|
|
237
|
+
}
|
|
194
238
|
Bits() {
|
|
195
239
|
throw new Error('reflect: Bits of invalid type');
|
|
196
240
|
}
|
|
@@ -329,6 +373,27 @@ export class Value {
|
|
|
329
373
|
Kind_String(this._type.Kind()) +
|
|
330
374
|
' Value');
|
|
331
375
|
}
|
|
376
|
+
Slice(i, j) {
|
|
377
|
+
const length = this.Len();
|
|
378
|
+
if (i < 0 || j < i || j > length) {
|
|
379
|
+
throw new Error(`reflect.Value.Slice: slice index out of bounds [${i}:${j}] with length ${length}`);
|
|
380
|
+
}
|
|
381
|
+
if (this._value &&
|
|
382
|
+
typeof this._value === 'object' &&
|
|
383
|
+
'__meta__' in this._value) {
|
|
384
|
+
return new Value($.goSlice(this._value, i, j), this._type);
|
|
385
|
+
}
|
|
386
|
+
if (globalThis.Array.isArray(this._value)) {
|
|
387
|
+
return new Value(this._value.slice(i, j), this._type);
|
|
388
|
+
}
|
|
389
|
+
if (this._value instanceof Uint8Array) {
|
|
390
|
+
return new Value(this._value.slice(i, j), this._type);
|
|
391
|
+
}
|
|
392
|
+
if (typeof this._value === 'string') {
|
|
393
|
+
return new Value(this._value.slice(i, j), this._type);
|
|
394
|
+
}
|
|
395
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'Slice' });
|
|
396
|
+
}
|
|
332
397
|
Bytes() {
|
|
333
398
|
if (this._value instanceof Uint8Array) {
|
|
334
399
|
return this._value;
|
|
@@ -366,10 +431,70 @@ export class Value {
|
|
|
366
431
|
// Pass parent struct and field name so Set() can update the struct
|
|
367
432
|
return new Value(fieldVal, field.Type, undefined, parentObj, field.Name);
|
|
368
433
|
}
|
|
434
|
+
FieldByIndex(index) {
|
|
435
|
+
let current = this;
|
|
436
|
+
for (const fieldIndex of $.asArray(index)) {
|
|
437
|
+
current = current.Field(fieldIndex);
|
|
438
|
+
}
|
|
439
|
+
return current;
|
|
440
|
+
}
|
|
441
|
+
FieldByName(name) {
|
|
442
|
+
const [field, ok] = this.Type().FieldByName(name);
|
|
443
|
+
if (!ok) {
|
|
444
|
+
return new Value(null, invalidTypeInstance);
|
|
445
|
+
}
|
|
446
|
+
return this.FieldByIndex(field.Index);
|
|
447
|
+
}
|
|
369
448
|
// Additional methods needed by various parts of the codebase
|
|
370
449
|
UnsafePointer() {
|
|
371
450
|
return this._value;
|
|
372
451
|
}
|
|
452
|
+
Pointer() {
|
|
453
|
+
const kind = this.Kind();
|
|
454
|
+
if (kind !== Chan &&
|
|
455
|
+
kind !== Func &&
|
|
456
|
+
kind !== Map &&
|
|
457
|
+
kind !== Ptr &&
|
|
458
|
+
kind !== Slice &&
|
|
459
|
+
kind !== UnsafePointer) {
|
|
460
|
+
throw new ValueError({ Kind: kind, Method: 'Pointer' });
|
|
461
|
+
}
|
|
462
|
+
if (this._value === null || this._value === undefined) {
|
|
463
|
+
return 0;
|
|
464
|
+
}
|
|
465
|
+
if ($.isVarRef(this._value)) {
|
|
466
|
+
const address = this._value.__goAddress?.();
|
|
467
|
+
if (address !== undefined) {
|
|
468
|
+
return address;
|
|
469
|
+
}
|
|
470
|
+
return pointerAddress(this._value);
|
|
471
|
+
}
|
|
472
|
+
if (kind === Slice) {
|
|
473
|
+
const slice = this._value;
|
|
474
|
+
try {
|
|
475
|
+
if ($.len(slice) === 0) {
|
|
476
|
+
return 0;
|
|
477
|
+
}
|
|
478
|
+
return $.indexAddress(slice, 0);
|
|
479
|
+
}
|
|
480
|
+
catch {
|
|
481
|
+
return 0;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (typeof this._value === 'object' || typeof this._value === 'function') {
|
|
485
|
+
return pointerAddress(this._value);
|
|
486
|
+
}
|
|
487
|
+
return 0;
|
|
488
|
+
}
|
|
489
|
+
UnsafeAddr() {
|
|
490
|
+
if (!this.CanAddr()) {
|
|
491
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'UnsafeAddr' });
|
|
492
|
+
}
|
|
493
|
+
if (this._parentStruct && this._fieldName) {
|
|
494
|
+
return { value: this };
|
|
495
|
+
}
|
|
496
|
+
return this.Pointer();
|
|
497
|
+
}
|
|
373
498
|
pointer() {
|
|
374
499
|
return this._value;
|
|
375
500
|
}
|
|
@@ -393,7 +518,10 @@ export class Value {
|
|
|
393
518
|
throw new Error('reflect: call of reflect.Value.Addr on invalid Value');
|
|
394
519
|
}
|
|
395
520
|
const ptrType = PointerTo(this.Type());
|
|
396
|
-
|
|
521
|
+
if (this._parentStruct && this._fieldName) {
|
|
522
|
+
return new Value($.fieldRef(this._parentStruct, this._fieldName), ptrType);
|
|
523
|
+
}
|
|
524
|
+
return new Value($.varRef(this._value), ptrType);
|
|
397
525
|
}
|
|
398
526
|
CanSet() {
|
|
399
527
|
// Simplified: all valid values are settable in GoScript since we handle
|
|
@@ -437,6 +565,36 @@ export class Value {
|
|
|
437
565
|
Interface() {
|
|
438
566
|
return this._value;
|
|
439
567
|
}
|
|
568
|
+
MethodByName(name) {
|
|
569
|
+
if (!this.IsValid()) {
|
|
570
|
+
return new Value();
|
|
571
|
+
}
|
|
572
|
+
const receiver = $.isVarRef(this._value) ? this._value.value : this._value;
|
|
573
|
+
if (receiver === null ||
|
|
574
|
+
receiver === undefined ||
|
|
575
|
+
(typeof receiver !== 'object' && typeof receiver !== 'function')) {
|
|
576
|
+
return new Value();
|
|
577
|
+
}
|
|
578
|
+
const method = receiver[name];
|
|
579
|
+
if (typeof method !== 'function') {
|
|
580
|
+
return new Value();
|
|
581
|
+
}
|
|
582
|
+
return new Value(method.bind(receiver), new FunctionType('func'));
|
|
583
|
+
}
|
|
584
|
+
Call(inArgs) {
|
|
585
|
+
if (this.Kind() !== Func || typeof this._value !== 'function') {
|
|
586
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'Call' });
|
|
587
|
+
}
|
|
588
|
+
const args = $.asArray(inArgs).map((arg) => arg.Interface());
|
|
589
|
+
const result = this._value(...args);
|
|
590
|
+
if (globalThis.Array.isArray(result)) {
|
|
591
|
+
return $.arrayToSlice(result.map((value) => ValueOf(value)));
|
|
592
|
+
}
|
|
593
|
+
if (result === undefined) {
|
|
594
|
+
return $.makeSlice(0);
|
|
595
|
+
}
|
|
596
|
+
return $.arrayToSlice([ValueOf(result)]);
|
|
597
|
+
}
|
|
440
598
|
IsZero() {
|
|
441
599
|
const zeroVal = Zero(this.Type()).value;
|
|
442
600
|
return DeepEqual(this._value, zeroVal);
|
|
@@ -448,16 +606,56 @@ export class Value {
|
|
|
448
606
|
return 0;
|
|
449
607
|
}
|
|
450
608
|
MapRange() {
|
|
451
|
-
|
|
452
|
-
|
|
609
|
+
if (this.Kind() !== Map) {
|
|
610
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapRange' });
|
|
611
|
+
}
|
|
612
|
+
if (this._value === null || this._value === undefined) {
|
|
613
|
+
return new MapIter(new globalThis.Map());
|
|
614
|
+
}
|
|
615
|
+
if (!(this._value instanceof globalThis.Map)) {
|
|
616
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapRange' });
|
|
617
|
+
}
|
|
618
|
+
return new MapIter(this._value);
|
|
453
619
|
}
|
|
454
|
-
MapIndex(
|
|
455
|
-
|
|
456
|
-
|
|
620
|
+
MapIndex(key) {
|
|
621
|
+
if (this.Kind() !== Map) {
|
|
622
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapIndex' });
|
|
623
|
+
}
|
|
624
|
+
if (!(this._value instanceof globalThis.Map)) {
|
|
625
|
+
return new Value(null, new BasicType(Invalid, 'invalid'));
|
|
626
|
+
}
|
|
627
|
+
const rawKey = key.Interface();
|
|
628
|
+
if (!this._value.has(rawKey)) {
|
|
629
|
+
return new Value(null, new BasicType(Invalid, 'invalid'));
|
|
630
|
+
}
|
|
631
|
+
return new Value(this._value.get(rawKey), this.Type().Elem());
|
|
632
|
+
}
|
|
633
|
+
MapKeys() {
|
|
634
|
+
if (this.Kind() !== Map) {
|
|
635
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapKeys' });
|
|
636
|
+
}
|
|
637
|
+
if (this._value === null || this._value === undefined) {
|
|
638
|
+
return $.makeSlice(0);
|
|
639
|
+
}
|
|
640
|
+
if (!(this._value instanceof globalThis.Map)) {
|
|
641
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapKeys' });
|
|
642
|
+
}
|
|
643
|
+
const keyType = this.Type().Key();
|
|
644
|
+
const keys = [];
|
|
645
|
+
for (const key of this._value.keys()) {
|
|
646
|
+
keys.push(new Value(key, keyType));
|
|
647
|
+
}
|
|
648
|
+
return $.arrayToSlice(keys);
|
|
457
649
|
}
|
|
458
650
|
Complex() {
|
|
459
|
-
|
|
460
|
-
|
|
651
|
+
const k = this.Kind();
|
|
652
|
+
if (k !== Complex64 && k !== Complex128) {
|
|
653
|
+
throw new Error('reflect: call of reflect.Value.Complex on ' +
|
|
654
|
+
Kind_String(k) +
|
|
655
|
+
' Value');
|
|
656
|
+
}
|
|
657
|
+
const value = this._parentVarRef ? this._parentVarRef.value : this._value;
|
|
658
|
+
return value;
|
|
461
659
|
}
|
|
462
660
|
// Send sends a value to a channel
|
|
463
661
|
Send(x) {
|
|
@@ -571,6 +769,23 @@ export class Value {
|
|
|
571
769
|
this._parentStruct[this._fieldName] = x;
|
|
572
770
|
}
|
|
573
771
|
}
|
|
772
|
+
// SetComplex sets v's underlying value to x
|
|
773
|
+
SetComplex(x) {
|
|
774
|
+
if (!this.CanSet()) {
|
|
775
|
+
throw new Error('reflect: call of reflect.Value.SetComplex on unaddressable value');
|
|
776
|
+
}
|
|
777
|
+
const k = this.Kind();
|
|
778
|
+
if (k !== Complex64 && k !== Complex128) {
|
|
779
|
+
throw new Error('reflect: call of reflect.Value.SetComplex on ' + k + ' Value');
|
|
780
|
+
}
|
|
781
|
+
this._value = x;
|
|
782
|
+
if (this._parentVarRef) {
|
|
783
|
+
this._parentVarRef.value = x;
|
|
784
|
+
}
|
|
785
|
+
if (this._parentStruct && this._fieldName) {
|
|
786
|
+
this._parentStruct[this._fieldName] = x;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
574
789
|
// SetBytes sets v's underlying value to x
|
|
575
790
|
SetBytes(x) {
|
|
576
791
|
if (!this.CanSet()) {
|
|
@@ -720,17 +935,22 @@ export class BasicType {
|
|
|
720
935
|
_kind;
|
|
721
936
|
_name;
|
|
722
937
|
_size;
|
|
723
|
-
|
|
938
|
+
_typeName;
|
|
939
|
+
constructor(_kind, _name, _size = 8, _typeName = '') {
|
|
724
940
|
this._kind = _kind;
|
|
725
941
|
this._name = _name;
|
|
726
942
|
this._size = _size;
|
|
943
|
+
this._typeName = _typeName;
|
|
727
944
|
}
|
|
728
945
|
String() {
|
|
729
|
-
return this._name;
|
|
946
|
+
return this._typeName || this._name;
|
|
730
947
|
}
|
|
731
948
|
Kind() {
|
|
732
949
|
return this._kind;
|
|
733
950
|
}
|
|
951
|
+
Comparable() {
|
|
952
|
+
return this._kind !== Func && this._kind !== Map && this._kind !== Slice;
|
|
953
|
+
}
|
|
734
954
|
Size() {
|
|
735
955
|
return this._size;
|
|
736
956
|
}
|
|
@@ -741,15 +961,34 @@ export class BasicType {
|
|
|
741
961
|
return 0;
|
|
742
962
|
}
|
|
743
963
|
PkgPath() {
|
|
964
|
+
if (this._typeName) {
|
|
965
|
+
const dotIndex = this._typeName.lastIndexOf('.');
|
|
966
|
+
if (dotIndex > 0) {
|
|
967
|
+
return this._typeName.substring(0, dotIndex);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
744
970
|
return '';
|
|
745
971
|
}
|
|
746
972
|
Name() {
|
|
973
|
+
if (this._typeName) {
|
|
974
|
+
const dotIndex = this._typeName.lastIndexOf('.');
|
|
975
|
+
if (dotIndex >= 0) {
|
|
976
|
+
return this._typeName.substring(dotIndex + 1);
|
|
977
|
+
}
|
|
978
|
+
return this._typeName;
|
|
979
|
+
}
|
|
747
980
|
// Basic types have names like 'int', 'string', etc.
|
|
748
981
|
return this._name;
|
|
749
982
|
}
|
|
750
983
|
Field(_i) {
|
|
751
984
|
throw new Error(`reflect: Field of non-struct type ${this._name}`);
|
|
752
985
|
}
|
|
986
|
+
FieldByName(name) {
|
|
987
|
+
return typeFieldByName(this, name);
|
|
988
|
+
}
|
|
989
|
+
FieldByNameFunc(match) {
|
|
990
|
+
return typeFieldByNameFunc(this, match);
|
|
991
|
+
}
|
|
753
992
|
Key() {
|
|
754
993
|
throw new Error(`reflect: Key of non-map type ${this._name}`);
|
|
755
994
|
}
|
|
@@ -762,6 +1001,9 @@ export class BasicType {
|
|
|
762
1001
|
}
|
|
763
1002
|
return false;
|
|
764
1003
|
}
|
|
1004
|
+
AssignableTo(u) {
|
|
1005
|
+
return typeAssignableTo(this, u);
|
|
1006
|
+
}
|
|
765
1007
|
common() {
|
|
766
1008
|
return new rtype(this._kind);
|
|
767
1009
|
}
|
|
@@ -818,6 +1060,14 @@ export class BasicType {
|
|
|
818
1060
|
NumMethod() {
|
|
819
1061
|
return 0;
|
|
820
1062
|
}
|
|
1063
|
+
MethodByName(_name) {
|
|
1064
|
+
return [zeroMethod(), false];
|
|
1065
|
+
}
|
|
1066
|
+
Len() {
|
|
1067
|
+
throw new Error('reflect: call of reflect.Type.Len on ' +
|
|
1068
|
+
Kind_String(this._kind) +
|
|
1069
|
+
' Type');
|
|
1070
|
+
}
|
|
821
1071
|
Bits() {
|
|
822
1072
|
const k = this._kind;
|
|
823
1073
|
switch (k) {
|
|
@@ -837,6 +1087,10 @@ export class BasicType {
|
|
|
837
1087
|
case Uint64:
|
|
838
1088
|
case Float64:
|
|
839
1089
|
return 64;
|
|
1090
|
+
case Complex64:
|
|
1091
|
+
return 64;
|
|
1092
|
+
case Complex128:
|
|
1093
|
+
return 128;
|
|
840
1094
|
case Int:
|
|
841
1095
|
case Uint:
|
|
842
1096
|
case Uintptr:
|
|
@@ -858,6 +1112,9 @@ class SliceType {
|
|
|
858
1112
|
Kind() {
|
|
859
1113
|
return Slice;
|
|
860
1114
|
}
|
|
1115
|
+
Comparable() {
|
|
1116
|
+
return false;
|
|
1117
|
+
}
|
|
861
1118
|
Size() {
|
|
862
1119
|
return 24; // slice header size
|
|
863
1120
|
}
|
|
@@ -877,6 +1134,12 @@ class SliceType {
|
|
|
877
1134
|
Field(_i) {
|
|
878
1135
|
throw new Error('reflect: Field of non-struct type');
|
|
879
1136
|
}
|
|
1137
|
+
FieldByName(name) {
|
|
1138
|
+
return typeFieldByName(this, name);
|
|
1139
|
+
}
|
|
1140
|
+
FieldByNameFunc(match) {
|
|
1141
|
+
return typeFieldByNameFunc(this, match);
|
|
1142
|
+
}
|
|
880
1143
|
Key() {
|
|
881
1144
|
throw new Error('reflect: Key of non-map type');
|
|
882
1145
|
}
|
|
@@ -889,6 +1152,9 @@ class SliceType {
|
|
|
889
1152
|
}
|
|
890
1153
|
return false;
|
|
891
1154
|
}
|
|
1155
|
+
AssignableTo(u) {
|
|
1156
|
+
return typeAssignableTo(this, u);
|
|
1157
|
+
}
|
|
892
1158
|
OverflowInt(_x) {
|
|
893
1159
|
throw new Error('reflect: call of reflect.Type.OverflowInt on slice Type');
|
|
894
1160
|
}
|
|
@@ -901,6 +1167,12 @@ class SliceType {
|
|
|
901
1167
|
NumMethod() {
|
|
902
1168
|
return 0;
|
|
903
1169
|
}
|
|
1170
|
+
MethodByName(_name) {
|
|
1171
|
+
return [zeroMethod(), false];
|
|
1172
|
+
}
|
|
1173
|
+
Len() {
|
|
1174
|
+
throw new Error('reflect: call of reflect.Type.Len on slice Type');
|
|
1175
|
+
}
|
|
904
1176
|
Bits() {
|
|
905
1177
|
throw new Error('reflect: call of reflect.Type.Bits on slice Type');
|
|
906
1178
|
}
|
|
@@ -919,6 +1191,9 @@ class ArrayType {
|
|
|
919
1191
|
Kind() {
|
|
920
1192
|
return Array;
|
|
921
1193
|
}
|
|
1194
|
+
Comparable() {
|
|
1195
|
+
return this._elemType.Comparable();
|
|
1196
|
+
}
|
|
922
1197
|
Size() {
|
|
923
1198
|
return this._elemType.Size() * this._len;
|
|
924
1199
|
}
|
|
@@ -941,6 +1216,12 @@ class ArrayType {
|
|
|
941
1216
|
Field(_i) {
|
|
942
1217
|
throw new Error('reflect: Field of non-struct type');
|
|
943
1218
|
}
|
|
1219
|
+
FieldByName(name) {
|
|
1220
|
+
return typeFieldByName(this, name);
|
|
1221
|
+
}
|
|
1222
|
+
FieldByNameFunc(match) {
|
|
1223
|
+
return typeFieldByNameFunc(this, match);
|
|
1224
|
+
}
|
|
944
1225
|
Key() {
|
|
945
1226
|
throw new Error('reflect: Key of non-map type');
|
|
946
1227
|
}
|
|
@@ -953,6 +1234,9 @@ class ArrayType {
|
|
|
953
1234
|
}
|
|
954
1235
|
return false;
|
|
955
1236
|
}
|
|
1237
|
+
AssignableTo(u) {
|
|
1238
|
+
return typeAssignableTo(this, u);
|
|
1239
|
+
}
|
|
956
1240
|
common() {
|
|
957
1241
|
return new rtype(this.Kind());
|
|
958
1242
|
}
|
|
@@ -968,6 +1252,9 @@ class ArrayType {
|
|
|
968
1252
|
NumMethod() {
|
|
969
1253
|
return 0;
|
|
970
1254
|
}
|
|
1255
|
+
MethodByName(_name) {
|
|
1256
|
+
return [zeroMethod(), false];
|
|
1257
|
+
}
|
|
971
1258
|
Bits() {
|
|
972
1259
|
throw new Error('reflect: call of reflect.Type.Bits on array Type');
|
|
973
1260
|
}
|
|
@@ -984,6 +1271,9 @@ class PointerType {
|
|
|
984
1271
|
Kind() {
|
|
985
1272
|
return Ptr;
|
|
986
1273
|
}
|
|
1274
|
+
Comparable() {
|
|
1275
|
+
return true;
|
|
1276
|
+
}
|
|
987
1277
|
Size() {
|
|
988
1278
|
return 8; // pointer size
|
|
989
1279
|
}
|
|
@@ -1003,6 +1293,12 @@ class PointerType {
|
|
|
1003
1293
|
Field(_i) {
|
|
1004
1294
|
throw new Error('reflect: Field of non-struct type');
|
|
1005
1295
|
}
|
|
1296
|
+
FieldByName(name) {
|
|
1297
|
+
return typeFieldByName(this, name);
|
|
1298
|
+
}
|
|
1299
|
+
FieldByNameFunc(match) {
|
|
1300
|
+
return typeFieldByNameFunc(this, match);
|
|
1301
|
+
}
|
|
1006
1302
|
Key() {
|
|
1007
1303
|
throw new Error('reflect: Key of non-map type');
|
|
1008
1304
|
}
|
|
@@ -1017,6 +1313,9 @@ class PointerType {
|
|
|
1017
1313
|
const elemTypeName = this._elemType.String();
|
|
1018
1314
|
return typeImplementsInterface(elemTypeName, u);
|
|
1019
1315
|
}
|
|
1316
|
+
AssignableTo(u) {
|
|
1317
|
+
return typeAssignableTo(this, u);
|
|
1318
|
+
}
|
|
1020
1319
|
common() {
|
|
1021
1320
|
return new rtype(this.Kind());
|
|
1022
1321
|
}
|
|
@@ -1032,6 +1331,12 @@ class PointerType {
|
|
|
1032
1331
|
NumMethod() {
|
|
1033
1332
|
return 0;
|
|
1034
1333
|
}
|
|
1334
|
+
MethodByName(name) {
|
|
1335
|
+
return typeMethodByName(this._elemType, name);
|
|
1336
|
+
}
|
|
1337
|
+
Len() {
|
|
1338
|
+
throw new Error('reflect: call of reflect.Type.Len on pointer Type');
|
|
1339
|
+
}
|
|
1035
1340
|
Bits() {
|
|
1036
1341
|
throw new Error('reflect: call of reflect.Type.Bits on pointer Type');
|
|
1037
1342
|
}
|
|
@@ -1048,6 +1353,9 @@ class FunctionType {
|
|
|
1048
1353
|
Kind() {
|
|
1049
1354
|
return Func;
|
|
1050
1355
|
}
|
|
1356
|
+
Comparable() {
|
|
1357
|
+
return false;
|
|
1358
|
+
}
|
|
1051
1359
|
Size() {
|
|
1052
1360
|
return 8; // function pointer size
|
|
1053
1361
|
}
|
|
@@ -1067,6 +1375,12 @@ class FunctionType {
|
|
|
1067
1375
|
Field(_i) {
|
|
1068
1376
|
throw new Error('reflect: Field of non-struct type');
|
|
1069
1377
|
}
|
|
1378
|
+
FieldByName(name) {
|
|
1379
|
+
return typeFieldByName(this, name);
|
|
1380
|
+
}
|
|
1381
|
+
FieldByNameFunc(match) {
|
|
1382
|
+
return typeFieldByNameFunc(this, match);
|
|
1383
|
+
}
|
|
1070
1384
|
Key() {
|
|
1071
1385
|
throw new Error('reflect: Key of non-map type');
|
|
1072
1386
|
}
|
|
@@ -1079,6 +1393,9 @@ class FunctionType {
|
|
|
1079
1393
|
}
|
|
1080
1394
|
return false;
|
|
1081
1395
|
}
|
|
1396
|
+
AssignableTo(u) {
|
|
1397
|
+
return typeAssignableTo(this, u);
|
|
1398
|
+
}
|
|
1082
1399
|
common() {
|
|
1083
1400
|
return new rtype(this.Kind());
|
|
1084
1401
|
}
|
|
@@ -1094,6 +1411,12 @@ class FunctionType {
|
|
|
1094
1411
|
NumMethod() {
|
|
1095
1412
|
return 0;
|
|
1096
1413
|
}
|
|
1414
|
+
MethodByName(_name) {
|
|
1415
|
+
return [zeroMethod(), false];
|
|
1416
|
+
}
|
|
1417
|
+
Len() {
|
|
1418
|
+
throw new Error('reflect: call of reflect.Type.Len on func Type');
|
|
1419
|
+
}
|
|
1097
1420
|
Bits() {
|
|
1098
1421
|
throw new Error('reflect: call of reflect.Type.Bits on func Type');
|
|
1099
1422
|
}
|
|
@@ -1112,6 +1435,9 @@ class MapType {
|
|
|
1112
1435
|
Kind() {
|
|
1113
1436
|
return Map;
|
|
1114
1437
|
}
|
|
1438
|
+
Comparable() {
|
|
1439
|
+
return false;
|
|
1440
|
+
}
|
|
1115
1441
|
Size() {
|
|
1116
1442
|
return 8; // map header size
|
|
1117
1443
|
}
|
|
@@ -1134,6 +1460,12 @@ class MapType {
|
|
|
1134
1460
|
Field(_i) {
|
|
1135
1461
|
throw new Error('reflect: Field of non-struct type');
|
|
1136
1462
|
}
|
|
1463
|
+
FieldByName(name) {
|
|
1464
|
+
return typeFieldByName(this, name);
|
|
1465
|
+
}
|
|
1466
|
+
FieldByNameFunc(match) {
|
|
1467
|
+
return typeFieldByNameFunc(this, match);
|
|
1468
|
+
}
|
|
1137
1469
|
Implements(u) {
|
|
1138
1470
|
if (!u) {
|
|
1139
1471
|
return false;
|
|
@@ -1143,6 +1475,9 @@ class MapType {
|
|
|
1143
1475
|
}
|
|
1144
1476
|
return false;
|
|
1145
1477
|
}
|
|
1478
|
+
AssignableTo(u) {
|
|
1479
|
+
return typeAssignableTo(this, u);
|
|
1480
|
+
}
|
|
1146
1481
|
common() {
|
|
1147
1482
|
return new rtype(this.Kind());
|
|
1148
1483
|
}
|
|
@@ -1158,6 +1493,12 @@ class MapType {
|
|
|
1158
1493
|
NumMethod() {
|
|
1159
1494
|
return 0;
|
|
1160
1495
|
}
|
|
1496
|
+
MethodByName(_name) {
|
|
1497
|
+
return [zeroMethod(), false];
|
|
1498
|
+
}
|
|
1499
|
+
Len() {
|
|
1500
|
+
throw new Error('reflect: call of reflect.Type.Len on map Type');
|
|
1501
|
+
}
|
|
1161
1502
|
Bits() {
|
|
1162
1503
|
throw new Error('reflect: call of reflect.Type.Bits on map Type');
|
|
1163
1504
|
}
|
|
@@ -1205,6 +1546,61 @@ function typeImplementsInterface(typeName, interfaceType) {
|
|
|
1205
1546
|
}
|
|
1206
1547
|
return true;
|
|
1207
1548
|
}
|
|
1549
|
+
function typeFieldByName(t, name) {
|
|
1550
|
+
return typeFieldByNameFunc(t, (fieldName) => fieldName === name);
|
|
1551
|
+
}
|
|
1552
|
+
function typeFieldByNameFunc(t, match) {
|
|
1553
|
+
if (t.Kind() !== Struct) {
|
|
1554
|
+
throw new Error('reflect: FieldByName of non-struct type');
|
|
1555
|
+
}
|
|
1556
|
+
for (let i = 0; i < t.NumField(); i++) {
|
|
1557
|
+
const field = t.Field(i);
|
|
1558
|
+
if (match(field.Name)) {
|
|
1559
|
+
return [field, true];
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
return [new StructField(), false];
|
|
1563
|
+
}
|
|
1564
|
+
function zeroMethod() {
|
|
1565
|
+
return {
|
|
1566
|
+
Name: '',
|
|
1567
|
+
Type: new BasicType(Invalid, '<invalid>'),
|
|
1568
|
+
Func: () => undefined,
|
|
1569
|
+
Index: 0,
|
|
1570
|
+
};
|
|
1571
|
+
}
|
|
1572
|
+
function methodFromSignature(signature, index) {
|
|
1573
|
+
return {
|
|
1574
|
+
Name: signature.name,
|
|
1575
|
+
Type: new FunctionType('func'),
|
|
1576
|
+
Func: () => undefined,
|
|
1577
|
+
Index: index,
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
function typeMethods(t) {
|
|
1581
|
+
const typeInfo = builtinGetTypeByName(t.String());
|
|
1582
|
+
if (!typeInfo) {
|
|
1583
|
+
return [];
|
|
1584
|
+
}
|
|
1585
|
+
if (isStructTypeInfo(typeInfo) || isInterfaceTypeInfo(typeInfo)) {
|
|
1586
|
+
return typeInfo.methods || [];
|
|
1587
|
+
}
|
|
1588
|
+
return [];
|
|
1589
|
+
}
|
|
1590
|
+
function typeMethodByName(t, name) {
|
|
1591
|
+
const methods = typeMethods(t);
|
|
1592
|
+
const index = methods.findIndex((method) => method.name === name);
|
|
1593
|
+
if (index === -1) {
|
|
1594
|
+
return [zeroMethod(), false];
|
|
1595
|
+
}
|
|
1596
|
+
return [methodFromSignature(methods[index], index), true];
|
|
1597
|
+
}
|
|
1598
|
+
function typeAssignableTo(t, u) {
|
|
1599
|
+
if (u === null) {
|
|
1600
|
+
return false;
|
|
1601
|
+
}
|
|
1602
|
+
return t.String() === u.String() || t.Implements(u);
|
|
1603
|
+
}
|
|
1208
1604
|
class StructType {
|
|
1209
1605
|
_name;
|
|
1210
1606
|
_fields;
|
|
@@ -1218,6 +1614,9 @@ class StructType {
|
|
|
1218
1614
|
Kind() {
|
|
1219
1615
|
return Struct;
|
|
1220
1616
|
}
|
|
1617
|
+
Comparable() {
|
|
1618
|
+
return this._fields.every((field) => field.type.Comparable());
|
|
1619
|
+
}
|
|
1221
1620
|
Size() {
|
|
1222
1621
|
// Struct size is implementation-defined, we'll use a reasonable default
|
|
1223
1622
|
return this._fields.reduce((sum, field) => sum + field.type.Size(), 0);
|
|
@@ -1251,10 +1650,18 @@ class StructType {
|
|
|
1251
1650
|
const f = this._fields[i];
|
|
1252
1651
|
return new StructField({
|
|
1253
1652
|
Name: f.name,
|
|
1653
|
+
PkgPath: '',
|
|
1254
1654
|
Type: f.type,
|
|
1255
1655
|
Tag: f.tag ? new StructTag(f.tag) : undefined,
|
|
1656
|
+
Index: [i],
|
|
1256
1657
|
});
|
|
1257
1658
|
}
|
|
1659
|
+
FieldByName(name) {
|
|
1660
|
+
return typeFieldByName(this, name);
|
|
1661
|
+
}
|
|
1662
|
+
FieldByNameFunc(match) {
|
|
1663
|
+
return typeFieldByNameFunc(this, match);
|
|
1664
|
+
}
|
|
1258
1665
|
Key() {
|
|
1259
1666
|
throw new Error('reflect: Key of non-map type');
|
|
1260
1667
|
}
|
|
@@ -1267,6 +1674,9 @@ class StructType {
|
|
|
1267
1674
|
}
|
|
1268
1675
|
return typeImplementsInterface(this._name, u);
|
|
1269
1676
|
}
|
|
1677
|
+
AssignableTo(u) {
|
|
1678
|
+
return typeAssignableTo(this, u);
|
|
1679
|
+
}
|
|
1270
1680
|
common() {
|
|
1271
1681
|
return new rtype(this.Kind());
|
|
1272
1682
|
}
|
|
@@ -1280,7 +1690,13 @@ class StructType {
|
|
|
1280
1690
|
throw new Error('reflect: call of reflect.Type.OverflowFloat on struct Type');
|
|
1281
1691
|
}
|
|
1282
1692
|
NumMethod() {
|
|
1283
|
-
return
|
|
1693
|
+
return typeMethods(this).length;
|
|
1694
|
+
}
|
|
1695
|
+
MethodByName(name) {
|
|
1696
|
+
return typeMethodByName(this, name);
|
|
1697
|
+
}
|
|
1698
|
+
Len() {
|
|
1699
|
+
throw new Error('reflect: call of reflect.Type.Len on struct Type');
|
|
1284
1700
|
}
|
|
1285
1701
|
Bits() {
|
|
1286
1702
|
throw new Error('reflect: call of reflect.Type.Bits on struct Type');
|
|
@@ -1300,6 +1716,10 @@ class StructType {
|
|
|
1300
1716
|
return new BasicType(Bool, 'bool', 1);
|
|
1301
1717
|
case 'float64':
|
|
1302
1718
|
return new BasicType(Float64, ti, 8);
|
|
1719
|
+
case 'complex64':
|
|
1720
|
+
return new BasicType(Complex64, ti, 8);
|
|
1721
|
+
case 'complex128':
|
|
1722
|
+
return new BasicType(Complex128, ti, 16);
|
|
1303
1723
|
case 'uint':
|
|
1304
1724
|
case 'uint32':
|
|
1305
1725
|
case 'uint64':
|
|
@@ -1311,24 +1731,29 @@ class StructType {
|
|
|
1311
1731
|
else if (ti && ti.kind) {
|
|
1312
1732
|
// Handle TypeInfo objects from the builtin type system
|
|
1313
1733
|
const name = ti.name || 'unknown';
|
|
1734
|
+
const typeName = ti.typeName || '';
|
|
1314
1735
|
switch (ti.kind) {
|
|
1315
1736
|
case 'basic':
|
|
1316
1737
|
// Map TypeScript type names to Go type names
|
|
1317
1738
|
switch (name) {
|
|
1318
1739
|
case 'string':
|
|
1319
|
-
return new BasicType(String, 'string', 16);
|
|
1740
|
+
return new BasicType(String, 'string', 16, typeName);
|
|
1320
1741
|
case 'number':
|
|
1321
1742
|
case 'int':
|
|
1322
1743
|
case 'int32':
|
|
1323
1744
|
case 'int64':
|
|
1324
|
-
return new BasicType(Int, name === 'number' ? 'int' : name, 8);
|
|
1745
|
+
return new BasicType(Int, name === 'number' ? 'int' : name, 8, typeName);
|
|
1325
1746
|
case 'boolean':
|
|
1326
1747
|
case 'bool':
|
|
1327
|
-
return new BasicType(Bool, 'bool', 1);
|
|
1748
|
+
return new BasicType(Bool, 'bool', 1, typeName);
|
|
1328
1749
|
case 'float64':
|
|
1329
|
-
return new BasicType(Float64, 'float64', 8);
|
|
1750
|
+
return new BasicType(Float64, 'float64', 8, typeName);
|
|
1751
|
+
case 'complex64':
|
|
1752
|
+
return new BasicType(Complex64, 'complex64', 8, typeName);
|
|
1753
|
+
case 'complex128':
|
|
1754
|
+
return new BasicType(Complex128, 'complex128', 16, typeName);
|
|
1330
1755
|
default:
|
|
1331
|
-
return new BasicType(Invalid, name, 8);
|
|
1756
|
+
return new BasicType(Invalid, name, 8, typeName);
|
|
1332
1757
|
}
|
|
1333
1758
|
case 'slice':
|
|
1334
1759
|
if (ti.elemType) {
|
|
@@ -1343,7 +1768,7 @@ class StructType {
|
|
|
1343
1768
|
case 'interface':
|
|
1344
1769
|
return new InterfaceType(name);
|
|
1345
1770
|
case 'struct':
|
|
1346
|
-
return new StructType(name,
|
|
1771
|
+
return new StructType(name, structFieldsFromTypeInfo(ti));
|
|
1347
1772
|
default:
|
|
1348
1773
|
return new BasicType(Invalid, name, 8);
|
|
1349
1774
|
}
|
|
@@ -1351,6 +1776,21 @@ class StructType {
|
|
|
1351
1776
|
return new BasicType(Invalid, 'unknown', 8);
|
|
1352
1777
|
}
|
|
1353
1778
|
}
|
|
1779
|
+
function structFieldsFromTypeInfo(ti) {
|
|
1780
|
+
return Object.entries(ti.fields || {}).map(([name, fieldInfo]) => {
|
|
1781
|
+
if (isStructFieldInfo(fieldInfo)) {
|
|
1782
|
+
return {
|
|
1783
|
+
name: fieldInfo.name ?? name,
|
|
1784
|
+
type: typeFromTypeInfo(fieldInfo.type),
|
|
1785
|
+
tag: fieldInfo.tag,
|
|
1786
|
+
};
|
|
1787
|
+
}
|
|
1788
|
+
return {
|
|
1789
|
+
name,
|
|
1790
|
+
type: typeFromTypeInfo(fieldInfo),
|
|
1791
|
+
};
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1354
1794
|
class ChannelType {
|
|
1355
1795
|
_elemType;
|
|
1356
1796
|
_dir;
|
|
@@ -1374,6 +1814,9 @@ class ChannelType {
|
|
|
1374
1814
|
Kind() {
|
|
1375
1815
|
return Chan;
|
|
1376
1816
|
}
|
|
1817
|
+
Comparable() {
|
|
1818
|
+
return true;
|
|
1819
|
+
}
|
|
1377
1820
|
Size() {
|
|
1378
1821
|
// Channels are represented as pointers, so pointer size
|
|
1379
1822
|
return 8;
|
|
@@ -1394,6 +1837,12 @@ class ChannelType {
|
|
|
1394
1837
|
Field(_i) {
|
|
1395
1838
|
throw new Error('reflect: Field of non-struct type');
|
|
1396
1839
|
}
|
|
1840
|
+
FieldByName(name) {
|
|
1841
|
+
return typeFieldByName(this, name);
|
|
1842
|
+
}
|
|
1843
|
+
FieldByNameFunc(match) {
|
|
1844
|
+
return typeFieldByNameFunc(this, match);
|
|
1845
|
+
}
|
|
1397
1846
|
Key() {
|
|
1398
1847
|
throw new Error('reflect: Key of non-map type');
|
|
1399
1848
|
}
|
|
@@ -1406,6 +1855,9 @@ class ChannelType {
|
|
|
1406
1855
|
}
|
|
1407
1856
|
return false;
|
|
1408
1857
|
}
|
|
1858
|
+
AssignableTo(u) {
|
|
1859
|
+
return typeAssignableTo(this, u);
|
|
1860
|
+
}
|
|
1409
1861
|
common() {
|
|
1410
1862
|
return new rtype(this.Kind());
|
|
1411
1863
|
}
|
|
@@ -1424,6 +1876,12 @@ class ChannelType {
|
|
|
1424
1876
|
NumMethod() {
|
|
1425
1877
|
return 0;
|
|
1426
1878
|
}
|
|
1879
|
+
MethodByName(_name) {
|
|
1880
|
+
return [zeroMethod(), false];
|
|
1881
|
+
}
|
|
1882
|
+
Len() {
|
|
1883
|
+
throw new Error('reflect: call of reflect.Type.Len on chan Type');
|
|
1884
|
+
}
|
|
1427
1885
|
Bits() {
|
|
1428
1886
|
throw new Error('reflect: call of reflect.Type.Bits on chan Type');
|
|
1429
1887
|
}
|
|
@@ -1442,6 +1900,9 @@ class InterfaceType {
|
|
|
1442
1900
|
Kind() {
|
|
1443
1901
|
return Interface;
|
|
1444
1902
|
}
|
|
1903
|
+
Comparable() {
|
|
1904
|
+
return true;
|
|
1905
|
+
}
|
|
1445
1906
|
Size() {
|
|
1446
1907
|
return 16;
|
|
1447
1908
|
}
|
|
@@ -1452,8 +1913,7 @@ class InterfaceType {
|
|
|
1452
1913
|
return 0;
|
|
1453
1914
|
}
|
|
1454
1915
|
PkgPath() {
|
|
1455
|
-
if (this._name === 'interface{}' ||
|
|
1456
|
-
this._name.startsWith('interface {')) {
|
|
1916
|
+
if (this._name === 'interface{}' || this._name.startsWith('interface {')) {
|
|
1457
1917
|
return '';
|
|
1458
1918
|
}
|
|
1459
1919
|
const dotIndex = this._name.lastIndexOf('.');
|
|
@@ -1463,8 +1923,7 @@ class InterfaceType {
|
|
|
1463
1923
|
return '';
|
|
1464
1924
|
}
|
|
1465
1925
|
Name() {
|
|
1466
|
-
if (this._name === 'interface{}' ||
|
|
1467
|
-
this._name.startsWith('interface {')) {
|
|
1926
|
+
if (this._name === 'interface{}' || this._name.startsWith('interface {')) {
|
|
1468
1927
|
return this._name;
|
|
1469
1928
|
}
|
|
1470
1929
|
const dotIndex = this._name.lastIndexOf('.');
|
|
@@ -1476,12 +1935,21 @@ class InterfaceType {
|
|
|
1476
1935
|
Field(_i) {
|
|
1477
1936
|
throw new Error('reflect: Field of non-struct type');
|
|
1478
1937
|
}
|
|
1938
|
+
FieldByName(name) {
|
|
1939
|
+
return typeFieldByName(this, name);
|
|
1940
|
+
}
|
|
1941
|
+
FieldByNameFunc(match) {
|
|
1942
|
+
return typeFieldByNameFunc(this, match);
|
|
1943
|
+
}
|
|
1479
1944
|
Key() {
|
|
1480
1945
|
throw new Error('reflect: Key of non-map type');
|
|
1481
1946
|
}
|
|
1482
1947
|
Implements(_u) {
|
|
1483
1948
|
return false;
|
|
1484
1949
|
}
|
|
1950
|
+
AssignableTo(u) {
|
|
1951
|
+
return typeAssignableTo(this, u);
|
|
1952
|
+
}
|
|
1485
1953
|
common() {
|
|
1486
1954
|
return new rtype(this.Kind());
|
|
1487
1955
|
}
|
|
@@ -1495,7 +1963,13 @@ class InterfaceType {
|
|
|
1495
1963
|
throw new Error('reflect: call of reflect.Type.OverflowFloat on interface Type');
|
|
1496
1964
|
}
|
|
1497
1965
|
NumMethod() {
|
|
1498
|
-
return
|
|
1966
|
+
return typeMethods(this).length;
|
|
1967
|
+
}
|
|
1968
|
+
MethodByName(name) {
|
|
1969
|
+
return typeMethodByName(this, name);
|
|
1970
|
+
}
|
|
1971
|
+
Len() {
|
|
1972
|
+
throw new Error('reflect: call of reflect.Type.Len on interface Type');
|
|
1499
1973
|
}
|
|
1500
1974
|
Bits() {
|
|
1501
1975
|
throw new Error('reflect: call of reflect.Type.Bits on interface Type');
|
|
@@ -1595,6 +2069,12 @@ function getTypeOf(value) {
|
|
|
1595
2069
|
const elemType = getTypeOf(value.value);
|
|
1596
2070
|
return new PointerType(elemType);
|
|
1597
2071
|
}
|
|
2072
|
+
if ('real' in value &&
|
|
2073
|
+
'imag' in value &&
|
|
2074
|
+
typeof value.real === 'number' &&
|
|
2075
|
+
typeof value.imag === 'number') {
|
|
2076
|
+
return new BasicType(Complex128, 'complex128', 16);
|
|
2077
|
+
}
|
|
1598
2078
|
// Check for arrays
|
|
1599
2079
|
if (globalThis.Array.isArray(value)) {
|
|
1600
2080
|
if (value.length === 0) {
|
|
@@ -1672,7 +2152,7 @@ function getTypeOf(value) {
|
|
|
1672
2152
|
// Check if fieldInfo is a StructFieldInfo with type and tag
|
|
1673
2153
|
if (isStructFieldInfo(fieldInfo)) {
|
|
1674
2154
|
return {
|
|
1675
|
-
name,
|
|
2155
|
+
name: fieldInfo.name ?? name,
|
|
1676
2156
|
type: StructType.createTypeFromFieldInfo(fieldInfo.type),
|
|
1677
2157
|
tag: fieldInfo.tag,
|
|
1678
2158
|
};
|
|
@@ -1701,70 +2181,83 @@ function getTypeOf(value) {
|
|
|
1701
2181
|
}
|
|
1702
2182
|
// Exported functions as required by godoc.txt
|
|
1703
2183
|
export function TypeOf(i) {
|
|
1704
|
-
return getTypeOf(i);
|
|
2184
|
+
return internType(getTypeOf(i));
|
|
1705
2185
|
}
|
|
1706
2186
|
export function ValueOf(i) {
|
|
1707
2187
|
return new Value(i, getTypeOf(i));
|
|
1708
2188
|
}
|
|
2189
|
+
export function TypeAssert(typeArgs, v) {
|
|
2190
|
+
const descriptor = typeArgs?.T;
|
|
2191
|
+
if (!descriptor?.type) {
|
|
2192
|
+
return [v.Interface(), true];
|
|
2193
|
+
}
|
|
2194
|
+
return $.typeAssertTuple(v.Interface(), descriptor.type);
|
|
2195
|
+
}
|
|
1709
2196
|
export function ArrayOf(length, elem) {
|
|
1710
|
-
return new ArrayType(elem, length);
|
|
2197
|
+
return internType(new ArrayType(elem, length));
|
|
1711
2198
|
}
|
|
1712
2199
|
export function SliceOf(t) {
|
|
1713
|
-
return new SliceType(t);
|
|
2200
|
+
return internType(new SliceType(t));
|
|
1714
2201
|
}
|
|
1715
2202
|
export function PointerTo(t) {
|
|
1716
2203
|
if (t === null)
|
|
1717
2204
|
return null;
|
|
1718
|
-
return new PointerType(t);
|
|
2205
|
+
return internType(new PointerType(t));
|
|
1719
2206
|
}
|
|
1720
2207
|
export function PtrTo(t) {
|
|
1721
2208
|
return PointerTo(t); // PtrTo is an alias for PointerTo
|
|
1722
2209
|
}
|
|
1723
2210
|
export function MapOf(key, elem) {
|
|
1724
|
-
return new MapType(key, elem);
|
|
2211
|
+
return internType(new MapType(key, elem));
|
|
1725
2212
|
}
|
|
1726
2213
|
export function ChanOf(dir, t) {
|
|
1727
|
-
return new ChannelType(t, dir);
|
|
2214
|
+
return internType(new ChannelType(t, dir));
|
|
1728
2215
|
}
|
|
1729
2216
|
export function TypeFor(typeArgs) {
|
|
1730
2217
|
const descriptor = typeArgs?.T;
|
|
1731
2218
|
if (descriptor?.type) {
|
|
1732
|
-
return typeFromTypeInfo(descriptor.type);
|
|
2219
|
+
return internType(typeFromTypeInfo(descriptor.type));
|
|
1733
2220
|
}
|
|
1734
2221
|
if (descriptor?.methods) {
|
|
1735
2222
|
const methods = Object.keys(descriptor.methods);
|
|
1736
2223
|
if (methods.length !== 0) {
|
|
1737
|
-
return new InterfaceType(`interface { ${methods.map((method) => method + '()').join('; ')} }`);
|
|
2224
|
+
return internType(new InterfaceType(`interface { ${methods.map((method) => method + '()').join('; ')} }`));
|
|
1738
2225
|
}
|
|
1739
2226
|
}
|
|
1740
2227
|
if (descriptor?.zero) {
|
|
1741
|
-
return getTypeOf(descriptor.zero());
|
|
2228
|
+
return internType(getTypeOf(descriptor.zero()));
|
|
1742
2229
|
}
|
|
1743
|
-
return new InterfaceType('interface{}');
|
|
2230
|
+
return internType(new InterfaceType('interface{}'));
|
|
1744
2231
|
}
|
|
1745
2232
|
function typeFromTypeInfo(info) {
|
|
1746
2233
|
if (typeof info === 'string') {
|
|
1747
2234
|
const registered = builtinGetTypeByName(info);
|
|
1748
2235
|
if (registered) {
|
|
1749
|
-
return typeFromTypeInfo(registered);
|
|
2236
|
+
return internType(typeFromTypeInfo(registered));
|
|
1750
2237
|
}
|
|
1751
|
-
return StructType.createTypeFromFieldInfo(info);
|
|
2238
|
+
return internType(StructType.createTypeFromFieldInfo(info));
|
|
1752
2239
|
}
|
|
1753
2240
|
switch (info.kind) {
|
|
1754
2241
|
case $.TypeKind.Array:
|
|
1755
|
-
return new ArrayType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }), info.length);
|
|
2242
|
+
return internType(new ArrayType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }), info.length));
|
|
2243
|
+
case $.TypeKind.Basic:
|
|
2244
|
+
return internType(StructType.createTypeFromFieldInfo(info));
|
|
1756
2245
|
case $.TypeKind.Channel:
|
|
1757
|
-
return new ChannelType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }), chanDirFromTypeInfo(info.direction));
|
|
2246
|
+
return internType(new ChannelType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }), chanDirFromTypeInfo(info.direction)));
|
|
1758
2247
|
case $.TypeKind.Function:
|
|
1759
|
-
return functionTypeFromInfo(info);
|
|
2248
|
+
return internType(functionTypeFromInfo(info));
|
|
1760
2249
|
case $.TypeKind.Interface:
|
|
1761
|
-
return interfaceTypeFromInfo(info);
|
|
2250
|
+
return internType(interfaceTypeFromInfo(info));
|
|
1762
2251
|
case $.TypeKind.Map:
|
|
1763
|
-
return new MapType(typeFromTypeInfo(info.keyType ?? { kind: $.TypeKind.Basic, name: 'unknown' }), typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }));
|
|
2252
|
+
return internType(new MapType(typeFromTypeInfo(info.keyType ?? { kind: $.TypeKind.Basic, name: 'unknown' }), typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' })));
|
|
2253
|
+
case $.TypeKind.Slice:
|
|
2254
|
+
return internType(new SliceType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' })));
|
|
2255
|
+
case $.TypeKind.Struct:
|
|
2256
|
+
return internType(StructType.createTypeFromFieldInfo(info));
|
|
1764
2257
|
case $.TypeKind.Pointer:
|
|
1765
|
-
return new PointerType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }));
|
|
2258
|
+
return internType(new PointerType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' })));
|
|
1766
2259
|
default:
|
|
1767
|
-
return StructType.createTypeFromFieldInfo(info);
|
|
2260
|
+
return internType(StructType.createTypeFromFieldInfo(info));
|
|
1768
2261
|
}
|
|
1769
2262
|
}
|
|
1770
2263
|
function functionTypeFromInfo(info) {
|