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/gs/reflect/type.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Method,
|
|
3
|
+
ReflectValue,
|
|
4
|
+
StructField,
|
|
5
|
+
StructTag,
|
|
6
|
+
ValueError,
|
|
7
|
+
} from './types.js'
|
|
2
8
|
export { StructField }
|
|
3
9
|
import { MapIter } from './map.js'
|
|
4
10
|
import {
|
|
@@ -173,6 +179,31 @@ export const String: Kind = 24
|
|
|
173
179
|
export const Struct: Kind = 25
|
|
174
180
|
export const UnsafePointer: Kind = 26
|
|
175
181
|
|
|
182
|
+
const pointerAddressStride = 0x100000000
|
|
183
|
+
const pointerAddresses = new WeakMap<object, number>()
|
|
184
|
+
let nextPointerAddress = 1
|
|
185
|
+
const canonicalTypes = new globalThis.Map<string, Type>()
|
|
186
|
+
|
|
187
|
+
function pointerAddress(value: object): number {
|
|
188
|
+
let address = pointerAddresses.get(value)
|
|
189
|
+
if (address === undefined) {
|
|
190
|
+
address = nextPointerAddress * pointerAddressStride
|
|
191
|
+
nextPointerAddress++
|
|
192
|
+
pointerAddresses.set(value, address)
|
|
193
|
+
}
|
|
194
|
+
return address
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function internType(t: Type): Type {
|
|
198
|
+
const key = `${t.Kind()}:${t.PkgPath()}:${t.Name()}:${t.String()}`
|
|
199
|
+
const existing = canonicalTypes.get(key)
|
|
200
|
+
if (existing) {
|
|
201
|
+
return existing
|
|
202
|
+
}
|
|
203
|
+
canonicalTypes.set(key, t)
|
|
204
|
+
return t
|
|
205
|
+
}
|
|
206
|
+
|
|
176
207
|
// Type is the representation of a Go type.
|
|
177
208
|
export interface Type {
|
|
178
209
|
// String returns a string representation of the type.
|
|
@@ -192,12 +223,18 @@ export interface Type {
|
|
|
192
223
|
NumField(): number
|
|
193
224
|
|
|
194
225
|
// PkgPath returns the package path for named types, empty for unnamed types.
|
|
195
|
-
PkgPath
|
|
226
|
+
PkgPath(): string
|
|
196
227
|
|
|
197
228
|
// Field returns a struct type's i'th field.
|
|
198
229
|
// Panics if the type's Kind is not Struct or i is out of range.
|
|
199
230
|
Field(i: number): StructField
|
|
200
231
|
|
|
232
|
+
// FieldByName returns the struct field with the given name.
|
|
233
|
+
FieldByName(name: string): [StructField, boolean]
|
|
234
|
+
|
|
235
|
+
// FieldByNameFunc returns the first struct field whose name satisfies match.
|
|
236
|
+
FieldByNameFunc(match: (name: string) => boolean): [StructField, boolean]
|
|
237
|
+
|
|
201
238
|
// Key returns a map type's key type.
|
|
202
239
|
// Panics if the type's Kind is not Map.
|
|
203
240
|
Key(): Type
|
|
@@ -208,6 +245,9 @@ export interface Type {
|
|
|
208
245
|
// Implements reports whether the type implements the interface type u.
|
|
209
246
|
Implements(u: Type | null): boolean
|
|
210
247
|
|
|
248
|
+
// AssignableTo reports whether a value of this type is assignable to u.
|
|
249
|
+
AssignableTo(u: Type | null): boolean
|
|
250
|
+
|
|
211
251
|
// common returns the common type implementation.
|
|
212
252
|
common?(): rtype
|
|
213
253
|
|
|
@@ -226,9 +266,19 @@ export interface Type {
|
|
|
226
266
|
// NumMethod returns the number of methods in the type's method set
|
|
227
267
|
NumMethod(): number
|
|
228
268
|
|
|
269
|
+
// MethodByName returns the method with that name in the type's method set.
|
|
270
|
+
MethodByName(name: string): [Method, boolean]
|
|
271
|
+
|
|
272
|
+
// Len returns an array type's length.
|
|
273
|
+
// Panics if the type's Kind is not Array.
|
|
274
|
+
Len(): number
|
|
275
|
+
|
|
229
276
|
// Bits returns the size of the type in bits
|
|
230
277
|
// Panics if the type's Kind is not a sized type.
|
|
231
278
|
Bits(): number
|
|
279
|
+
|
|
280
|
+
// Comparable reports whether values of this type are comparable.
|
|
281
|
+
Comparable(): boolean
|
|
232
282
|
}
|
|
233
283
|
|
|
234
284
|
// InvalidTypeInstance is a singleton type for invalid/zero reflect.Value
|
|
@@ -236,12 +286,18 @@ class InvalidTypeClass implements Type {
|
|
|
236
286
|
Kind(): Kind {
|
|
237
287
|
return Invalid
|
|
238
288
|
}
|
|
289
|
+
Comparable(): boolean {
|
|
290
|
+
return false
|
|
291
|
+
}
|
|
239
292
|
String(): string {
|
|
240
293
|
return '<invalid reflect.Value>'
|
|
241
294
|
}
|
|
242
295
|
Name(): string {
|
|
243
296
|
return ''
|
|
244
297
|
}
|
|
298
|
+
PkgPath(): string {
|
|
299
|
+
return ''
|
|
300
|
+
}
|
|
245
301
|
Size(): number {
|
|
246
302
|
return 0
|
|
247
303
|
}
|
|
@@ -257,9 +313,18 @@ class InvalidTypeClass implements Type {
|
|
|
257
313
|
Field(_i: number): StructField {
|
|
258
314
|
throw new Error('reflect: Field of invalid type')
|
|
259
315
|
}
|
|
316
|
+
FieldByName(_name: string): [StructField, boolean] {
|
|
317
|
+
return [new StructField(), false]
|
|
318
|
+
}
|
|
319
|
+
FieldByNameFunc(_match: (name: string) => boolean): [StructField, boolean] {
|
|
320
|
+
return [new StructField(), false]
|
|
321
|
+
}
|
|
260
322
|
Implements(_u: Type | null): boolean {
|
|
261
323
|
return false
|
|
262
324
|
}
|
|
325
|
+
AssignableTo(_u: Type | null): boolean {
|
|
326
|
+
return false
|
|
327
|
+
}
|
|
263
328
|
OverflowInt(_x: number): boolean {
|
|
264
329
|
throw new Error('reflect: OverflowInt of invalid type')
|
|
265
330
|
}
|
|
@@ -272,6 +337,12 @@ class InvalidTypeClass implements Type {
|
|
|
272
337
|
NumMethod(): number {
|
|
273
338
|
return 0
|
|
274
339
|
}
|
|
340
|
+
MethodByName(_name: string): [Method, boolean] {
|
|
341
|
+
return [zeroMethod(), false]
|
|
342
|
+
}
|
|
343
|
+
Len(): number {
|
|
344
|
+
throw new Error('reflect: Len of invalid type')
|
|
345
|
+
}
|
|
275
346
|
Bits(): number {
|
|
276
347
|
throw new Error('reflect: Bits of invalid type')
|
|
277
348
|
}
|
|
@@ -458,6 +529,35 @@ export class Value {
|
|
|
458
529
|
)
|
|
459
530
|
}
|
|
460
531
|
|
|
532
|
+
public Slice(i: number, j: number): Value {
|
|
533
|
+
const length = this.Len()
|
|
534
|
+
if (i < 0 || j < i || j > length) {
|
|
535
|
+
throw new Error(
|
|
536
|
+
`reflect.Value.Slice: slice index out of bounds [${i}:${j}] with length ${length}`,
|
|
537
|
+
)
|
|
538
|
+
}
|
|
539
|
+
if (
|
|
540
|
+
this._value &&
|
|
541
|
+
typeof this._value === 'object' &&
|
|
542
|
+
'__meta__' in this._value
|
|
543
|
+
) {
|
|
544
|
+
return new Value(
|
|
545
|
+
$.goSlice(this._value as $.Slice<unknown>, i, j),
|
|
546
|
+
this._type,
|
|
547
|
+
)
|
|
548
|
+
}
|
|
549
|
+
if (globalThis.Array.isArray(this._value)) {
|
|
550
|
+
return new Value(this._value.slice(i, j), this._type)
|
|
551
|
+
}
|
|
552
|
+
if (this._value instanceof Uint8Array) {
|
|
553
|
+
return new Value(this._value.slice(i, j), this._type)
|
|
554
|
+
}
|
|
555
|
+
if (typeof this._value === 'string') {
|
|
556
|
+
return new Value(this._value.slice(i, j), this._type)
|
|
557
|
+
}
|
|
558
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'Slice' })
|
|
559
|
+
}
|
|
560
|
+
|
|
461
561
|
public Bytes(): Uint8Array {
|
|
462
562
|
if (this._value instanceof Uint8Array) {
|
|
463
563
|
return this._value
|
|
@@ -503,11 +603,76 @@ export class Value {
|
|
|
503
603
|
return new Value(fieldVal, field.Type, undefined, parentObj, field.Name)
|
|
504
604
|
}
|
|
505
605
|
|
|
606
|
+
public FieldByIndex(index: $.Slice<number>): Value {
|
|
607
|
+
let current: Value = this
|
|
608
|
+
for (const fieldIndex of $.asArray(index)) {
|
|
609
|
+
current = current.Field(fieldIndex)
|
|
610
|
+
}
|
|
611
|
+
return current
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
public FieldByName(name: string): Value {
|
|
615
|
+
const [field, ok] = this.Type().FieldByName(name)
|
|
616
|
+
if (!ok) {
|
|
617
|
+
return new Value(null, invalidTypeInstance)
|
|
618
|
+
}
|
|
619
|
+
return this.FieldByIndex(field.Index)
|
|
620
|
+
}
|
|
621
|
+
|
|
506
622
|
// Additional methods needed by various parts of the codebase
|
|
507
623
|
public UnsafePointer(): unknown {
|
|
508
624
|
return this._value
|
|
509
625
|
}
|
|
510
626
|
|
|
627
|
+
public Pointer(): number {
|
|
628
|
+
const kind = this.Kind()
|
|
629
|
+
if (
|
|
630
|
+
kind !== Chan &&
|
|
631
|
+
kind !== Func &&
|
|
632
|
+
kind !== Map &&
|
|
633
|
+
kind !== Ptr &&
|
|
634
|
+
kind !== Slice &&
|
|
635
|
+
kind !== UnsafePointer
|
|
636
|
+
) {
|
|
637
|
+
throw new ValueError({ Kind: kind, Method: 'Pointer' })
|
|
638
|
+
}
|
|
639
|
+
if (this._value === null || this._value === undefined) {
|
|
640
|
+
return 0
|
|
641
|
+
}
|
|
642
|
+
if ($.isVarRef(this._value)) {
|
|
643
|
+
const address = this._value.__goAddress?.()
|
|
644
|
+
if (address !== undefined) {
|
|
645
|
+
return address
|
|
646
|
+
}
|
|
647
|
+
return pointerAddress(this._value)
|
|
648
|
+
}
|
|
649
|
+
if (kind === Slice) {
|
|
650
|
+
const slice = this._value as $.Slice<unknown> | Uint8Array
|
|
651
|
+
try {
|
|
652
|
+
if ($.len(slice) === 0) {
|
|
653
|
+
return 0
|
|
654
|
+
}
|
|
655
|
+
return $.indexAddress(slice, 0)
|
|
656
|
+
} catch {
|
|
657
|
+
return 0
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
if (typeof this._value === 'object' || typeof this._value === 'function') {
|
|
661
|
+
return pointerAddress(this._value)
|
|
662
|
+
}
|
|
663
|
+
return 0
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
public UnsafeAddr(): number | { value: Value } {
|
|
667
|
+
if (!this.CanAddr()) {
|
|
668
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'UnsafeAddr' })
|
|
669
|
+
}
|
|
670
|
+
if (this._parentStruct && this._fieldName) {
|
|
671
|
+
return { value: this }
|
|
672
|
+
}
|
|
673
|
+
return this.Pointer()
|
|
674
|
+
}
|
|
675
|
+
|
|
511
676
|
public pointer(): unknown {
|
|
512
677
|
return this._value
|
|
513
678
|
}
|
|
@@ -536,7 +701,10 @@ export class Value {
|
|
|
536
701
|
throw new Error('reflect: call of reflect.Value.Addr on invalid Value')
|
|
537
702
|
}
|
|
538
703
|
const ptrType = PointerTo(this.Type())
|
|
539
|
-
|
|
704
|
+
if (this._parentStruct && this._fieldName) {
|
|
705
|
+
return new Value($.fieldRef(this._parentStruct, this._fieldName), ptrType)
|
|
706
|
+
}
|
|
707
|
+
return new Value($.varRef(this._value), ptrType)
|
|
540
708
|
}
|
|
541
709
|
|
|
542
710
|
public CanSet(): boolean {
|
|
@@ -584,6 +752,40 @@ export class Value {
|
|
|
584
752
|
return this._value
|
|
585
753
|
}
|
|
586
754
|
|
|
755
|
+
public MethodByName(name: string): Value {
|
|
756
|
+
if (!this.IsValid()) {
|
|
757
|
+
return new Value()
|
|
758
|
+
}
|
|
759
|
+
const receiver = $.isVarRef(this._value) ? this._value.value : this._value
|
|
760
|
+
if (
|
|
761
|
+
receiver === null ||
|
|
762
|
+
receiver === undefined ||
|
|
763
|
+
(typeof receiver !== 'object' && typeof receiver !== 'function')
|
|
764
|
+
) {
|
|
765
|
+
return new Value()
|
|
766
|
+
}
|
|
767
|
+
const method = (receiver as Record<string, unknown>)[name]
|
|
768
|
+
if (typeof method !== 'function') {
|
|
769
|
+
return new Value()
|
|
770
|
+
}
|
|
771
|
+
return new Value(method.bind(receiver), new FunctionType('func'))
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
public Call(inArgs: $.Slice<Value>): $.Slice<Value> {
|
|
775
|
+
if (this.Kind() !== Func || typeof this._value !== 'function') {
|
|
776
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'Call' })
|
|
777
|
+
}
|
|
778
|
+
const args = $.asArray(inArgs).map((arg) => arg.Interface())
|
|
779
|
+
const result = this._value(...args) as ReflectValue | ReflectValue[]
|
|
780
|
+
if (globalThis.Array.isArray(result)) {
|
|
781
|
+
return $.arrayToSlice(result.map((value) => ValueOf(value)))
|
|
782
|
+
}
|
|
783
|
+
if (result === undefined) {
|
|
784
|
+
return $.makeSlice<Value>(0)
|
|
785
|
+
}
|
|
786
|
+
return $.arrayToSlice([ValueOf(result)])
|
|
787
|
+
}
|
|
788
|
+
|
|
587
789
|
public IsZero(): boolean {
|
|
588
790
|
const zeroVal = Zero(this.Type()).value
|
|
589
791
|
return DeepEqual(this._value, zeroVal)
|
|
@@ -598,18 +800,64 @@ export class Value {
|
|
|
598
800
|
}
|
|
599
801
|
|
|
600
802
|
public MapRange(): MapIter<unknown, unknown> | null {
|
|
601
|
-
|
|
602
|
-
|
|
803
|
+
if (this.Kind() !== Map) {
|
|
804
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapRange' })
|
|
805
|
+
}
|
|
806
|
+
if (this._value === null || this._value === undefined) {
|
|
807
|
+
return new MapIter(new globalThis.Map())
|
|
808
|
+
}
|
|
809
|
+
if (!(this._value instanceof globalThis.Map)) {
|
|
810
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapRange' })
|
|
811
|
+
}
|
|
812
|
+
return new MapIter(this._value)
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
public MapIndex(key: Value): Value {
|
|
816
|
+
if (this.Kind() !== Map) {
|
|
817
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapIndex' })
|
|
818
|
+
}
|
|
819
|
+
if (!(this._value instanceof globalThis.Map)) {
|
|
820
|
+
return new Value(null, new BasicType(Invalid, 'invalid'))
|
|
821
|
+
}
|
|
822
|
+
const rawKey = key.Interface()
|
|
823
|
+
if (!this._value.has(rawKey)) {
|
|
824
|
+
return new Value(null, new BasicType(Invalid, 'invalid'))
|
|
825
|
+
}
|
|
826
|
+
return new Value(
|
|
827
|
+
this._value.get(rawKey) as ReflectValue,
|
|
828
|
+
this.Type().Elem(),
|
|
829
|
+
)
|
|
603
830
|
}
|
|
604
831
|
|
|
605
|
-
public
|
|
606
|
-
|
|
607
|
-
|
|
832
|
+
public MapKeys(): $.Slice<Value> {
|
|
833
|
+
if (this.Kind() !== Map) {
|
|
834
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapKeys' })
|
|
835
|
+
}
|
|
836
|
+
if (this._value === null || this._value === undefined) {
|
|
837
|
+
return $.makeSlice<Value>(0)
|
|
838
|
+
}
|
|
839
|
+
if (!(this._value instanceof globalThis.Map)) {
|
|
840
|
+
throw new ValueError({ Kind: this.Kind(), Method: 'MapKeys' })
|
|
841
|
+
}
|
|
842
|
+
const keyType = this.Type().Key()
|
|
843
|
+
const keys: Value[] = []
|
|
844
|
+
for (const key of this._value.keys()) {
|
|
845
|
+
keys.push(new Value(key as ReflectValue, keyType))
|
|
846
|
+
}
|
|
847
|
+
return $.arrayToSlice(keys)
|
|
608
848
|
}
|
|
609
849
|
|
|
610
|
-
public Complex(): number |
|
|
611
|
-
|
|
612
|
-
|
|
850
|
+
public Complex(): number | $.Complex | null {
|
|
851
|
+
const k = this.Kind()
|
|
852
|
+
if (k !== Complex64 && k !== Complex128) {
|
|
853
|
+
throw new Error(
|
|
854
|
+
'reflect: call of reflect.Value.Complex on ' +
|
|
855
|
+
Kind_String(k) +
|
|
856
|
+
' Value',
|
|
857
|
+
)
|
|
858
|
+
}
|
|
859
|
+
const value = this._parentVarRef ? this._parentVarRef.value : this._value
|
|
860
|
+
return value as number | $.Complex | null
|
|
613
861
|
}
|
|
614
862
|
|
|
615
863
|
// Send sends a value to a channel
|
|
@@ -755,6 +1003,28 @@ export class Value {
|
|
|
755
1003
|
}
|
|
756
1004
|
}
|
|
757
1005
|
|
|
1006
|
+
// SetComplex sets v's underlying value to x
|
|
1007
|
+
public SetComplex(x: number | $.Complex): void {
|
|
1008
|
+
if (!this.CanSet()) {
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
'reflect: call of reflect.Value.SetComplex on unaddressable value',
|
|
1011
|
+
)
|
|
1012
|
+
}
|
|
1013
|
+
const k = this.Kind()
|
|
1014
|
+
if (k !== Complex64 && k !== Complex128) {
|
|
1015
|
+
throw new Error(
|
|
1016
|
+
'reflect: call of reflect.Value.SetComplex on ' + k + ' Value',
|
|
1017
|
+
)
|
|
1018
|
+
}
|
|
1019
|
+
this._value = x
|
|
1020
|
+
if (this._parentVarRef) {
|
|
1021
|
+
this._parentVarRef.value = x
|
|
1022
|
+
}
|
|
1023
|
+
if (this._parentStruct && this._fieldName) {
|
|
1024
|
+
this._parentStruct[this._fieldName] = x
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
758
1028
|
// SetBytes sets v's underlying value to x
|
|
759
1029
|
public SetBytes(x: $.Slice<number>): void {
|
|
760
1030
|
if (!this.CanSet()) {
|
|
@@ -940,16 +1210,21 @@ export class BasicType implements Type {
|
|
|
940
1210
|
private _kind: Kind,
|
|
941
1211
|
private _name: string,
|
|
942
1212
|
private _size: number = 8,
|
|
1213
|
+
private _typeName: string = '',
|
|
943
1214
|
) {}
|
|
944
1215
|
|
|
945
1216
|
public String(): string {
|
|
946
|
-
return this._name
|
|
1217
|
+
return this._typeName || this._name
|
|
947
1218
|
}
|
|
948
1219
|
|
|
949
1220
|
public Kind(): Kind {
|
|
950
1221
|
return this._kind
|
|
951
1222
|
}
|
|
952
1223
|
|
|
1224
|
+
public Comparable(): boolean {
|
|
1225
|
+
return this._kind !== Func && this._kind !== Map && this._kind !== Slice
|
|
1226
|
+
}
|
|
1227
|
+
|
|
953
1228
|
public Size(): number {
|
|
954
1229
|
return this._size
|
|
955
1230
|
}
|
|
@@ -962,11 +1237,24 @@ export class BasicType implements Type {
|
|
|
962
1237
|
return 0
|
|
963
1238
|
}
|
|
964
1239
|
|
|
965
|
-
public PkgPath
|
|
1240
|
+
public PkgPath(): string {
|
|
1241
|
+
if (this._typeName) {
|
|
1242
|
+
const dotIndex = this._typeName.lastIndexOf('.')
|
|
1243
|
+
if (dotIndex > 0) {
|
|
1244
|
+
return this._typeName.substring(0, dotIndex)
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
966
1247
|
return ''
|
|
967
1248
|
}
|
|
968
1249
|
|
|
969
1250
|
public Name(): string {
|
|
1251
|
+
if (this._typeName) {
|
|
1252
|
+
const dotIndex = this._typeName.lastIndexOf('.')
|
|
1253
|
+
if (dotIndex >= 0) {
|
|
1254
|
+
return this._typeName.substring(dotIndex + 1)
|
|
1255
|
+
}
|
|
1256
|
+
return this._typeName
|
|
1257
|
+
}
|
|
970
1258
|
// Basic types have names like 'int', 'string', etc.
|
|
971
1259
|
return this._name
|
|
972
1260
|
}
|
|
@@ -975,6 +1263,16 @@ export class BasicType implements Type {
|
|
|
975
1263
|
throw new Error(`reflect: Field of non-struct type ${this._name}`)
|
|
976
1264
|
}
|
|
977
1265
|
|
|
1266
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
1267
|
+
return typeFieldByName(this, name)
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
public FieldByNameFunc(
|
|
1271
|
+
match: (name: string) => boolean,
|
|
1272
|
+
): [StructField, boolean] {
|
|
1273
|
+
return typeFieldByNameFunc(this, match)
|
|
1274
|
+
}
|
|
1275
|
+
|
|
978
1276
|
public Key(): Type {
|
|
979
1277
|
throw new Error(`reflect: Key of non-map type ${this._name}`)
|
|
980
1278
|
}
|
|
@@ -989,6 +1287,10 @@ export class BasicType implements Type {
|
|
|
989
1287
|
return false
|
|
990
1288
|
}
|
|
991
1289
|
|
|
1290
|
+
public AssignableTo(u: Type | null): boolean {
|
|
1291
|
+
return typeAssignableTo(this, u)
|
|
1292
|
+
}
|
|
1293
|
+
|
|
992
1294
|
public common?(): rtype {
|
|
993
1295
|
return new rtype(this._kind)
|
|
994
1296
|
}
|
|
@@ -1055,6 +1357,17 @@ export class BasicType implements Type {
|
|
|
1055
1357
|
public NumMethod(): number {
|
|
1056
1358
|
return 0
|
|
1057
1359
|
}
|
|
1360
|
+
public MethodByName(_name: string): [Method, boolean] {
|
|
1361
|
+
return [zeroMethod(), false]
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
public Len(): number {
|
|
1365
|
+
throw new Error(
|
|
1366
|
+
'reflect: call of reflect.Type.Len on ' +
|
|
1367
|
+
Kind_String(this._kind) +
|
|
1368
|
+
' Type',
|
|
1369
|
+
)
|
|
1370
|
+
}
|
|
1058
1371
|
|
|
1059
1372
|
public Bits(): number {
|
|
1060
1373
|
const k = this._kind
|
|
@@ -1075,6 +1388,10 @@ export class BasicType implements Type {
|
|
|
1075
1388
|
case Uint64:
|
|
1076
1389
|
case Float64:
|
|
1077
1390
|
return 64
|
|
1391
|
+
case Complex64:
|
|
1392
|
+
return 64
|
|
1393
|
+
case Complex128:
|
|
1394
|
+
return 128
|
|
1078
1395
|
case Int:
|
|
1079
1396
|
case Uint:
|
|
1080
1397
|
case Uintptr:
|
|
@@ -1099,6 +1416,10 @@ class SliceType implements Type {
|
|
|
1099
1416
|
return Slice
|
|
1100
1417
|
}
|
|
1101
1418
|
|
|
1419
|
+
public Comparable(): boolean {
|
|
1420
|
+
return false
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1102
1423
|
public Size(): number {
|
|
1103
1424
|
return 24 // slice header size
|
|
1104
1425
|
}
|
|
@@ -1111,7 +1432,7 @@ class SliceType implements Type {
|
|
|
1111
1432
|
return 0
|
|
1112
1433
|
}
|
|
1113
1434
|
|
|
1114
|
-
public PkgPath
|
|
1435
|
+
public PkgPath(): string {
|
|
1115
1436
|
return ''
|
|
1116
1437
|
}
|
|
1117
1438
|
|
|
@@ -1124,6 +1445,16 @@ class SliceType implements Type {
|
|
|
1124
1445
|
throw new Error('reflect: Field of non-struct type')
|
|
1125
1446
|
}
|
|
1126
1447
|
|
|
1448
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
1449
|
+
return typeFieldByName(this, name)
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
public FieldByNameFunc(
|
|
1453
|
+
match: (name: string) => boolean,
|
|
1454
|
+
): [StructField, boolean] {
|
|
1455
|
+
return typeFieldByNameFunc(this, match)
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1127
1458
|
public Key(): Type {
|
|
1128
1459
|
throw new Error('reflect: Key of non-map type')
|
|
1129
1460
|
}
|
|
@@ -1138,6 +1469,10 @@ class SliceType implements Type {
|
|
|
1138
1469
|
return false
|
|
1139
1470
|
}
|
|
1140
1471
|
|
|
1472
|
+
public AssignableTo(u: Type | null): boolean {
|
|
1473
|
+
return typeAssignableTo(this, u)
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1141
1476
|
public OverflowInt(_x: number): boolean {
|
|
1142
1477
|
throw new Error('reflect: call of reflect.Type.OverflowInt on slice Type')
|
|
1143
1478
|
}
|
|
@@ -1153,6 +1488,13 @@ class SliceType implements Type {
|
|
|
1153
1488
|
public NumMethod(): number {
|
|
1154
1489
|
return 0
|
|
1155
1490
|
}
|
|
1491
|
+
public MethodByName(_name: string): [Method, boolean] {
|
|
1492
|
+
return [zeroMethod(), false]
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
public Len(): number {
|
|
1496
|
+
throw new Error('reflect: call of reflect.Type.Len on slice Type')
|
|
1497
|
+
}
|
|
1156
1498
|
|
|
1157
1499
|
public Bits(): number {
|
|
1158
1500
|
throw new Error('reflect: call of reflect.Type.Bits on slice Type')
|
|
@@ -1174,6 +1516,10 @@ class ArrayType implements Type {
|
|
|
1174
1516
|
return Array
|
|
1175
1517
|
}
|
|
1176
1518
|
|
|
1519
|
+
public Comparable(): boolean {
|
|
1520
|
+
return this._elemType.Comparable()
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1177
1523
|
public Size(): number {
|
|
1178
1524
|
return this._elemType.Size() * this._len
|
|
1179
1525
|
}
|
|
@@ -1190,7 +1536,7 @@ class ArrayType implements Type {
|
|
|
1190
1536
|
return this._len
|
|
1191
1537
|
}
|
|
1192
1538
|
|
|
1193
|
-
public PkgPath
|
|
1539
|
+
public PkgPath(): string {
|
|
1194
1540
|
return ''
|
|
1195
1541
|
}
|
|
1196
1542
|
|
|
@@ -1203,6 +1549,16 @@ class ArrayType implements Type {
|
|
|
1203
1549
|
throw new Error('reflect: Field of non-struct type')
|
|
1204
1550
|
}
|
|
1205
1551
|
|
|
1552
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
1553
|
+
return typeFieldByName(this, name)
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
public FieldByNameFunc(
|
|
1557
|
+
match: (name: string) => boolean,
|
|
1558
|
+
): [StructField, boolean] {
|
|
1559
|
+
return typeFieldByNameFunc(this, match)
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1206
1562
|
public Key(): Type {
|
|
1207
1563
|
throw new Error('reflect: Key of non-map type')
|
|
1208
1564
|
}
|
|
@@ -1217,6 +1573,10 @@ class ArrayType implements Type {
|
|
|
1217
1573
|
return false
|
|
1218
1574
|
}
|
|
1219
1575
|
|
|
1576
|
+
public AssignableTo(u: Type | null): boolean {
|
|
1577
|
+
return typeAssignableTo(this, u)
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1220
1580
|
public common?(): rtype {
|
|
1221
1581
|
return new rtype(this.Kind())
|
|
1222
1582
|
}
|
|
@@ -1236,6 +1596,9 @@ class ArrayType implements Type {
|
|
|
1236
1596
|
public NumMethod(): number {
|
|
1237
1597
|
return 0
|
|
1238
1598
|
}
|
|
1599
|
+
public MethodByName(_name: string): [Method, boolean] {
|
|
1600
|
+
return [zeroMethod(), false]
|
|
1601
|
+
}
|
|
1239
1602
|
|
|
1240
1603
|
public Bits(): number {
|
|
1241
1604
|
throw new Error('reflect: call of reflect.Type.Bits on array Type')
|
|
@@ -1254,6 +1617,10 @@ class PointerType implements Type {
|
|
|
1254
1617
|
return Ptr
|
|
1255
1618
|
}
|
|
1256
1619
|
|
|
1620
|
+
public Comparable(): boolean {
|
|
1621
|
+
return true
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1257
1624
|
public Size(): number {
|
|
1258
1625
|
return 8 // pointer size
|
|
1259
1626
|
}
|
|
@@ -1266,7 +1633,7 @@ class PointerType implements Type {
|
|
|
1266
1633
|
return 0
|
|
1267
1634
|
}
|
|
1268
1635
|
|
|
1269
|
-
public PkgPath
|
|
1636
|
+
public PkgPath(): string {
|
|
1270
1637
|
return ''
|
|
1271
1638
|
}
|
|
1272
1639
|
|
|
@@ -1279,6 +1646,16 @@ class PointerType implements Type {
|
|
|
1279
1646
|
throw new Error('reflect: Field of non-struct type')
|
|
1280
1647
|
}
|
|
1281
1648
|
|
|
1649
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
1650
|
+
return typeFieldByName(this, name)
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
public FieldByNameFunc(
|
|
1654
|
+
match: (name: string) => boolean,
|
|
1655
|
+
): [StructField, boolean] {
|
|
1656
|
+
return typeFieldByNameFunc(this, match)
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1282
1659
|
public Key(): Type {
|
|
1283
1660
|
throw new Error('reflect: Key of non-map type')
|
|
1284
1661
|
}
|
|
@@ -1295,6 +1672,10 @@ class PointerType implements Type {
|
|
|
1295
1672
|
return typeImplementsInterface(elemTypeName, u)
|
|
1296
1673
|
}
|
|
1297
1674
|
|
|
1675
|
+
public AssignableTo(u: Type | null): boolean {
|
|
1676
|
+
return typeAssignableTo(this, u)
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1298
1679
|
public common?(): rtype {
|
|
1299
1680
|
return new rtype(this.Kind())
|
|
1300
1681
|
}
|
|
@@ -1318,6 +1699,13 @@ class PointerType implements Type {
|
|
|
1318
1699
|
public NumMethod(): number {
|
|
1319
1700
|
return 0
|
|
1320
1701
|
}
|
|
1702
|
+
public MethodByName(name: string): [Method, boolean] {
|
|
1703
|
+
return typeMethodByName(this._elemType, name)
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
public Len(): number {
|
|
1707
|
+
throw new Error('reflect: call of reflect.Type.Len on pointer Type')
|
|
1708
|
+
}
|
|
1321
1709
|
|
|
1322
1710
|
public Bits(): number {
|
|
1323
1711
|
throw new Error('reflect: call of reflect.Type.Bits on pointer Type')
|
|
@@ -1336,6 +1724,10 @@ class FunctionType implements Type {
|
|
|
1336
1724
|
return Func
|
|
1337
1725
|
}
|
|
1338
1726
|
|
|
1727
|
+
public Comparable(): boolean {
|
|
1728
|
+
return false
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1339
1731
|
public Size(): number {
|
|
1340
1732
|
return 8 // function pointer size
|
|
1341
1733
|
}
|
|
@@ -1348,7 +1740,7 @@ class FunctionType implements Type {
|
|
|
1348
1740
|
return 0
|
|
1349
1741
|
}
|
|
1350
1742
|
|
|
1351
|
-
public PkgPath
|
|
1743
|
+
public PkgPath(): string {
|
|
1352
1744
|
return ''
|
|
1353
1745
|
}
|
|
1354
1746
|
|
|
@@ -1361,6 +1753,16 @@ class FunctionType implements Type {
|
|
|
1361
1753
|
throw new Error('reflect: Field of non-struct type')
|
|
1362
1754
|
}
|
|
1363
1755
|
|
|
1756
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
1757
|
+
return typeFieldByName(this, name)
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
public FieldByNameFunc(
|
|
1761
|
+
match: (name: string) => boolean,
|
|
1762
|
+
): [StructField, boolean] {
|
|
1763
|
+
return typeFieldByNameFunc(this, match)
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1364
1766
|
public Key(): Type {
|
|
1365
1767
|
throw new Error('reflect: Key of non-map type')
|
|
1366
1768
|
}
|
|
@@ -1375,6 +1777,10 @@ class FunctionType implements Type {
|
|
|
1375
1777
|
return false
|
|
1376
1778
|
}
|
|
1377
1779
|
|
|
1780
|
+
public AssignableTo(u: Type | null): boolean {
|
|
1781
|
+
return typeAssignableTo(this, u)
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1378
1784
|
public common?(): rtype {
|
|
1379
1785
|
return new rtype(this.Kind())
|
|
1380
1786
|
}
|
|
@@ -1394,6 +1800,13 @@ class FunctionType implements Type {
|
|
|
1394
1800
|
public NumMethod(): number {
|
|
1395
1801
|
return 0
|
|
1396
1802
|
}
|
|
1803
|
+
public MethodByName(_name: string): [Method, boolean] {
|
|
1804
|
+
return [zeroMethod(), false]
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
public Len(): number {
|
|
1808
|
+
throw new Error('reflect: call of reflect.Type.Len on func Type')
|
|
1809
|
+
}
|
|
1397
1810
|
|
|
1398
1811
|
public Bits(): number {
|
|
1399
1812
|
throw new Error('reflect: call of reflect.Type.Bits on func Type')
|
|
@@ -1415,6 +1828,10 @@ class MapType implements Type {
|
|
|
1415
1828
|
return Map
|
|
1416
1829
|
}
|
|
1417
1830
|
|
|
1831
|
+
public Comparable(): boolean {
|
|
1832
|
+
return false
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1418
1835
|
public Size(): number {
|
|
1419
1836
|
return 8 // map header size
|
|
1420
1837
|
}
|
|
@@ -1431,7 +1848,7 @@ class MapType implements Type {
|
|
|
1431
1848
|
return this._keyType
|
|
1432
1849
|
}
|
|
1433
1850
|
|
|
1434
|
-
public PkgPath
|
|
1851
|
+
public PkgPath(): string {
|
|
1435
1852
|
return ''
|
|
1436
1853
|
}
|
|
1437
1854
|
|
|
@@ -1444,6 +1861,16 @@ class MapType implements Type {
|
|
|
1444
1861
|
throw new Error('reflect: Field of non-struct type')
|
|
1445
1862
|
}
|
|
1446
1863
|
|
|
1864
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
1865
|
+
return typeFieldByName(this, name)
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
public FieldByNameFunc(
|
|
1869
|
+
match: (name: string) => boolean,
|
|
1870
|
+
): [StructField, boolean] {
|
|
1871
|
+
return typeFieldByNameFunc(this, match)
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1447
1874
|
public Implements(u: Type | null): boolean {
|
|
1448
1875
|
if (!u) {
|
|
1449
1876
|
return false
|
|
@@ -1454,6 +1881,10 @@ class MapType implements Type {
|
|
|
1454
1881
|
return false
|
|
1455
1882
|
}
|
|
1456
1883
|
|
|
1884
|
+
public AssignableTo(u: Type | null): boolean {
|
|
1885
|
+
return typeAssignableTo(this, u)
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1457
1888
|
public common?(): rtype {
|
|
1458
1889
|
return new rtype(this.Kind())
|
|
1459
1890
|
}
|
|
@@ -1473,6 +1904,13 @@ class MapType implements Type {
|
|
|
1473
1904
|
public NumMethod(): number {
|
|
1474
1905
|
return 0
|
|
1475
1906
|
}
|
|
1907
|
+
public MethodByName(_name: string): [Method, boolean] {
|
|
1908
|
+
return [zeroMethod(), false]
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
public Len(): number {
|
|
1912
|
+
throw new Error('reflect: call of reflect.Type.Len on map Type')
|
|
1913
|
+
}
|
|
1476
1914
|
|
|
1477
1915
|
public Bits(): number {
|
|
1478
1916
|
throw new Error('reflect: call of reflect.Type.Bits on map Type')
|
|
@@ -1537,6 +1975,74 @@ function typeImplementsInterface(
|
|
|
1537
1975
|
return true
|
|
1538
1976
|
}
|
|
1539
1977
|
|
|
1978
|
+
function typeFieldByName(t: Type, name: string): [StructField, boolean] {
|
|
1979
|
+
return typeFieldByNameFunc(t, (fieldName) => fieldName === name)
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
function typeFieldByNameFunc(
|
|
1983
|
+
t: Type,
|
|
1984
|
+
match: (name: string) => boolean,
|
|
1985
|
+
): [StructField, boolean] {
|
|
1986
|
+
if (t.Kind() !== Struct) {
|
|
1987
|
+
throw new Error('reflect: FieldByName of non-struct type')
|
|
1988
|
+
}
|
|
1989
|
+
for (let i = 0; i < t.NumField(); i++) {
|
|
1990
|
+
const field = t.Field(i)
|
|
1991
|
+
if (match(field.Name)) {
|
|
1992
|
+
return [field, true]
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
return [new StructField(), false]
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
function zeroMethod(): Method {
|
|
1999
|
+
return {
|
|
2000
|
+
Name: '',
|
|
2001
|
+
Type: new BasicType(Invalid, '<invalid>'),
|
|
2002
|
+
Func: () => undefined,
|
|
2003
|
+
Index: 0,
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
function methodFromSignature(
|
|
2008
|
+
signature: $.MethodSignature,
|
|
2009
|
+
index: number,
|
|
2010
|
+
): Method {
|
|
2011
|
+
return {
|
|
2012
|
+
Name: signature.name,
|
|
2013
|
+
Type: new FunctionType('func'),
|
|
2014
|
+
Func: () => undefined,
|
|
2015
|
+
Index: index,
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
function typeMethods(t: Type): $.MethodSignature[] {
|
|
2020
|
+
const typeInfo = builtinGetTypeByName(t.String())
|
|
2021
|
+
if (!typeInfo) {
|
|
2022
|
+
return []
|
|
2023
|
+
}
|
|
2024
|
+
if (isStructTypeInfo(typeInfo) || isInterfaceTypeInfo(typeInfo)) {
|
|
2025
|
+
return typeInfo.methods || []
|
|
2026
|
+
}
|
|
2027
|
+
return []
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
function typeMethodByName(t: Type, name: string): [Method, boolean] {
|
|
2031
|
+
const methods = typeMethods(t)
|
|
2032
|
+
const index = methods.findIndex((method) => method.name === name)
|
|
2033
|
+
if (index === -1) {
|
|
2034
|
+
return [zeroMethod(), false]
|
|
2035
|
+
}
|
|
2036
|
+
return [methodFromSignature(methods[index], index), true]
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
function typeAssignableTo(t: Type, u: Type | null): boolean {
|
|
2040
|
+
if (u === null) {
|
|
2041
|
+
return false
|
|
2042
|
+
}
|
|
2043
|
+
return t.String() === u.String() || t.Implements(u)
|
|
2044
|
+
}
|
|
2045
|
+
|
|
1540
2046
|
class StructType implements Type {
|
|
1541
2047
|
constructor(
|
|
1542
2048
|
private _name: string,
|
|
@@ -1551,6 +2057,10 @@ class StructType implements Type {
|
|
|
1551
2057
|
return Struct
|
|
1552
2058
|
}
|
|
1553
2059
|
|
|
2060
|
+
public Comparable(): boolean {
|
|
2061
|
+
return this._fields.every((field) => field.type.Comparable())
|
|
2062
|
+
}
|
|
2063
|
+
|
|
1554
2064
|
public Size(): number {
|
|
1555
2065
|
// Struct size is implementation-defined, we'll use a reasonable default
|
|
1556
2066
|
return this._fields.reduce((sum, field) => sum + field.type.Size(), 0)
|
|
@@ -1564,7 +2074,7 @@ class StructType implements Type {
|
|
|
1564
2074
|
return this._fields.length
|
|
1565
2075
|
}
|
|
1566
2076
|
|
|
1567
|
-
public PkgPath
|
|
2077
|
+
public PkgPath(): string {
|
|
1568
2078
|
// Extract package path from full type name (e.g., "main.Person" -> "main")
|
|
1569
2079
|
const dotIndex = this._name.lastIndexOf('.')
|
|
1570
2080
|
if (dotIndex > 0) {
|
|
@@ -1591,11 +2101,23 @@ class StructType implements Type {
|
|
|
1591
2101
|
const f = this._fields[i]
|
|
1592
2102
|
return new StructField({
|
|
1593
2103
|
Name: f.name,
|
|
2104
|
+
PkgPath: '',
|
|
1594
2105
|
Type: f.type,
|
|
1595
2106
|
Tag: f.tag ? new StructTag(f.tag) : undefined,
|
|
2107
|
+
Index: [i],
|
|
1596
2108
|
})
|
|
1597
2109
|
}
|
|
1598
2110
|
|
|
2111
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
2112
|
+
return typeFieldByName(this, name)
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
public FieldByNameFunc(
|
|
2116
|
+
match: (name: string) => boolean,
|
|
2117
|
+
): [StructField, boolean] {
|
|
2118
|
+
return typeFieldByNameFunc(this, match)
|
|
2119
|
+
}
|
|
2120
|
+
|
|
1599
2121
|
public Key(): Type {
|
|
1600
2122
|
throw new Error('reflect: Key of non-map type')
|
|
1601
2123
|
}
|
|
@@ -1610,6 +2132,10 @@ class StructType implements Type {
|
|
|
1610
2132
|
return typeImplementsInterface(this._name, u)
|
|
1611
2133
|
}
|
|
1612
2134
|
|
|
2135
|
+
public AssignableTo(u: Type | null): boolean {
|
|
2136
|
+
return typeAssignableTo(this, u)
|
|
2137
|
+
}
|
|
2138
|
+
|
|
1613
2139
|
public common?(): rtype {
|
|
1614
2140
|
return new rtype(this.Kind())
|
|
1615
2141
|
}
|
|
@@ -1629,7 +2155,15 @@ class StructType implements Type {
|
|
|
1629
2155
|
}
|
|
1630
2156
|
|
|
1631
2157
|
public NumMethod(): number {
|
|
1632
|
-
return
|
|
2158
|
+
return typeMethods(this).length
|
|
2159
|
+
}
|
|
2160
|
+
|
|
2161
|
+
public MethodByName(name: string): [Method, boolean] {
|
|
2162
|
+
return typeMethodByName(this, name)
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
public Len(): number {
|
|
2166
|
+
throw new Error('reflect: call of reflect.Type.Len on struct Type')
|
|
1633
2167
|
}
|
|
1634
2168
|
|
|
1635
2169
|
public Bits(): number {
|
|
@@ -1651,6 +2185,10 @@ class StructType implements Type {
|
|
|
1651
2185
|
return new BasicType(Bool, 'bool', 1)
|
|
1652
2186
|
case 'float64':
|
|
1653
2187
|
return new BasicType(Float64, ti, 8)
|
|
2188
|
+
case 'complex64':
|
|
2189
|
+
return new BasicType(Complex64, ti, 8)
|
|
2190
|
+
case 'complex128':
|
|
2191
|
+
return new BasicType(Complex128, ti, 16)
|
|
1654
2192
|
case 'uint':
|
|
1655
2193
|
case 'uint32':
|
|
1656
2194
|
case 'uint64':
|
|
@@ -1661,24 +2199,34 @@ class StructType implements Type {
|
|
|
1661
2199
|
} else if (ti && ti.kind) {
|
|
1662
2200
|
// Handle TypeInfo objects from the builtin type system
|
|
1663
2201
|
const name = ti.name || 'unknown'
|
|
2202
|
+
const typeName = ti.typeName || ''
|
|
1664
2203
|
switch (ti.kind) {
|
|
1665
2204
|
case 'basic':
|
|
1666
2205
|
// Map TypeScript type names to Go type names
|
|
1667
2206
|
switch (name) {
|
|
1668
2207
|
case 'string':
|
|
1669
|
-
return new BasicType(String, 'string', 16)
|
|
2208
|
+
return new BasicType(String, 'string', 16, typeName)
|
|
1670
2209
|
case 'number':
|
|
1671
2210
|
case 'int':
|
|
1672
2211
|
case 'int32':
|
|
1673
2212
|
case 'int64':
|
|
1674
|
-
return new BasicType(
|
|
2213
|
+
return new BasicType(
|
|
2214
|
+
Int,
|
|
2215
|
+
name === 'number' ? 'int' : name,
|
|
2216
|
+
8,
|
|
2217
|
+
typeName,
|
|
2218
|
+
)
|
|
1675
2219
|
case 'boolean':
|
|
1676
2220
|
case 'bool':
|
|
1677
|
-
return new BasicType(Bool, 'bool', 1)
|
|
2221
|
+
return new BasicType(Bool, 'bool', 1, typeName)
|
|
1678
2222
|
case 'float64':
|
|
1679
|
-
return new BasicType(Float64, 'float64', 8)
|
|
2223
|
+
return new BasicType(Float64, 'float64', 8, typeName)
|
|
2224
|
+
case 'complex64':
|
|
2225
|
+
return new BasicType(Complex64, 'complex64', 8, typeName)
|
|
2226
|
+
case 'complex128':
|
|
2227
|
+
return new BasicType(Complex128, 'complex128', 16, typeName)
|
|
1680
2228
|
default:
|
|
1681
|
-
return new BasicType(Invalid, name, 8)
|
|
2229
|
+
return new BasicType(Invalid, name, 8, typeName)
|
|
1682
2230
|
}
|
|
1683
2231
|
case 'slice':
|
|
1684
2232
|
if (ti.elemType) {
|
|
@@ -1697,7 +2245,7 @@ class StructType implements Type {
|
|
|
1697
2245
|
case 'interface':
|
|
1698
2246
|
return new InterfaceType(name)
|
|
1699
2247
|
case 'struct':
|
|
1700
|
-
return new StructType(name,
|
|
2248
|
+
return new StructType(name, structFieldsFromTypeInfo(ti))
|
|
1701
2249
|
default:
|
|
1702
2250
|
return new BasicType(Invalid, name, 8)
|
|
1703
2251
|
}
|
|
@@ -1706,6 +2254,24 @@ class StructType implements Type {
|
|
|
1706
2254
|
}
|
|
1707
2255
|
}
|
|
1708
2256
|
|
|
2257
|
+
function structFieldsFromTypeInfo(
|
|
2258
|
+
ti: $.StructTypeInfo,
|
|
2259
|
+
): Array<{ name: string; type: Type; tag?: string }> {
|
|
2260
|
+
return Object.entries(ti.fields || {}).map(([name, fieldInfo]) => {
|
|
2261
|
+
if (isStructFieldInfo(fieldInfo)) {
|
|
2262
|
+
return {
|
|
2263
|
+
name: fieldInfo.name ?? name,
|
|
2264
|
+
type: typeFromTypeInfo(fieldInfo.type),
|
|
2265
|
+
tag: fieldInfo.tag,
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
return {
|
|
2269
|
+
name,
|
|
2270
|
+
type: typeFromTypeInfo(fieldInfo),
|
|
2271
|
+
}
|
|
2272
|
+
})
|
|
2273
|
+
}
|
|
2274
|
+
|
|
1709
2275
|
class ChannelType implements Type {
|
|
1710
2276
|
constructor(
|
|
1711
2277
|
private _elemType: Type,
|
|
@@ -1730,6 +2296,10 @@ class ChannelType implements Type {
|
|
|
1730
2296
|
return Chan
|
|
1731
2297
|
}
|
|
1732
2298
|
|
|
2299
|
+
public Comparable(): boolean {
|
|
2300
|
+
return true
|
|
2301
|
+
}
|
|
2302
|
+
|
|
1733
2303
|
public Size(): number {
|
|
1734
2304
|
// Channels are represented as pointers, so pointer size
|
|
1735
2305
|
return 8
|
|
@@ -1743,7 +2313,7 @@ class ChannelType implements Type {
|
|
|
1743
2313
|
return 0
|
|
1744
2314
|
}
|
|
1745
2315
|
|
|
1746
|
-
public PkgPath
|
|
2316
|
+
public PkgPath(): string {
|
|
1747
2317
|
return ''
|
|
1748
2318
|
}
|
|
1749
2319
|
|
|
@@ -1756,6 +2326,16 @@ class ChannelType implements Type {
|
|
|
1756
2326
|
throw new Error('reflect: Field of non-struct type')
|
|
1757
2327
|
}
|
|
1758
2328
|
|
|
2329
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
2330
|
+
return typeFieldByName(this, name)
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
public FieldByNameFunc(
|
|
2334
|
+
match: (name: string) => boolean,
|
|
2335
|
+
): [StructField, boolean] {
|
|
2336
|
+
return typeFieldByNameFunc(this, match)
|
|
2337
|
+
}
|
|
2338
|
+
|
|
1759
2339
|
public Key(): Type {
|
|
1760
2340
|
throw new Error('reflect: Key of non-map type')
|
|
1761
2341
|
}
|
|
@@ -1770,6 +2350,10 @@ class ChannelType implements Type {
|
|
|
1770
2350
|
return false
|
|
1771
2351
|
}
|
|
1772
2352
|
|
|
2353
|
+
public AssignableTo(u: Type | null): boolean {
|
|
2354
|
+
return typeAssignableTo(this, u)
|
|
2355
|
+
}
|
|
2356
|
+
|
|
1773
2357
|
public common?(): rtype {
|
|
1774
2358
|
return new rtype(this.Kind())
|
|
1775
2359
|
}
|
|
@@ -1793,6 +2377,13 @@ class ChannelType implements Type {
|
|
|
1793
2377
|
public NumMethod(): number {
|
|
1794
2378
|
return 0
|
|
1795
2379
|
}
|
|
2380
|
+
public MethodByName(_name: string): [Method, boolean] {
|
|
2381
|
+
return [zeroMethod(), false]
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
public Len(): number {
|
|
2385
|
+
throw new Error('reflect: call of reflect.Type.Len on chan Type')
|
|
2386
|
+
}
|
|
1796
2387
|
|
|
1797
2388
|
public Bits(): number {
|
|
1798
2389
|
throw new Error('reflect: call of reflect.Type.Bits on chan Type')
|
|
@@ -1814,6 +2405,10 @@ class InterfaceType implements Type {
|
|
|
1814
2405
|
return Interface
|
|
1815
2406
|
}
|
|
1816
2407
|
|
|
2408
|
+
public Comparable(): boolean {
|
|
2409
|
+
return true
|
|
2410
|
+
}
|
|
2411
|
+
|
|
1817
2412
|
public Size(): number {
|
|
1818
2413
|
return 16
|
|
1819
2414
|
}
|
|
@@ -1826,11 +2421,8 @@ class InterfaceType implements Type {
|
|
|
1826
2421
|
return 0
|
|
1827
2422
|
}
|
|
1828
2423
|
|
|
1829
|
-
public PkgPath
|
|
1830
|
-
if (
|
|
1831
|
-
this._name === 'interface{}' ||
|
|
1832
|
-
this._name.startsWith('interface {')
|
|
1833
|
-
) {
|
|
2424
|
+
public PkgPath(): string {
|
|
2425
|
+
if (this._name === 'interface{}' || this._name.startsWith('interface {')) {
|
|
1834
2426
|
return ''
|
|
1835
2427
|
}
|
|
1836
2428
|
const dotIndex = this._name.lastIndexOf('.')
|
|
@@ -1841,10 +2433,7 @@ class InterfaceType implements Type {
|
|
|
1841
2433
|
}
|
|
1842
2434
|
|
|
1843
2435
|
public Name(): string {
|
|
1844
|
-
if (
|
|
1845
|
-
this._name === 'interface{}' ||
|
|
1846
|
-
this._name.startsWith('interface {')
|
|
1847
|
-
) {
|
|
2436
|
+
if (this._name === 'interface{}' || this._name.startsWith('interface {')) {
|
|
1848
2437
|
return this._name
|
|
1849
2438
|
}
|
|
1850
2439
|
const dotIndex = this._name.lastIndexOf('.')
|
|
@@ -1858,6 +2447,16 @@ class InterfaceType implements Type {
|
|
|
1858
2447
|
throw new Error('reflect: Field of non-struct type')
|
|
1859
2448
|
}
|
|
1860
2449
|
|
|
2450
|
+
public FieldByName(name: string): [StructField, boolean] {
|
|
2451
|
+
return typeFieldByName(this, name)
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
public FieldByNameFunc(
|
|
2455
|
+
match: (name: string) => boolean,
|
|
2456
|
+
): [StructField, boolean] {
|
|
2457
|
+
return typeFieldByNameFunc(this, match)
|
|
2458
|
+
}
|
|
2459
|
+
|
|
1861
2460
|
public Key(): Type {
|
|
1862
2461
|
throw new Error('reflect: Key of non-map type')
|
|
1863
2462
|
}
|
|
@@ -1866,6 +2465,10 @@ class InterfaceType implements Type {
|
|
|
1866
2465
|
return false
|
|
1867
2466
|
}
|
|
1868
2467
|
|
|
2468
|
+
public AssignableTo(u: Type | null): boolean {
|
|
2469
|
+
return typeAssignableTo(this, u)
|
|
2470
|
+
}
|
|
2471
|
+
|
|
1869
2472
|
public common?(): rtype {
|
|
1870
2473
|
return new rtype(this.Kind())
|
|
1871
2474
|
}
|
|
@@ -1889,7 +2492,15 @@ class InterfaceType implements Type {
|
|
|
1889
2492
|
}
|
|
1890
2493
|
|
|
1891
2494
|
public NumMethod(): number {
|
|
1892
|
-
return
|
|
2495
|
+
return typeMethods(this).length
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
public MethodByName(name: string): [Method, boolean] {
|
|
2499
|
+
return typeMethodByName(this, name)
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
public Len(): number {
|
|
2503
|
+
throw new Error('reflect: call of reflect.Type.Len on interface Type')
|
|
1893
2504
|
}
|
|
1894
2505
|
|
|
1895
2506
|
public Bits(): number {
|
|
@@ -2003,6 +2614,15 @@ function getTypeOf(value: ReflectValue): Type {
|
|
|
2003
2614
|
return new PointerType(elemType)
|
|
2004
2615
|
}
|
|
2005
2616
|
|
|
2617
|
+
if (
|
|
2618
|
+
'real' in value &&
|
|
2619
|
+
'imag' in value &&
|
|
2620
|
+
typeof (value as $.Complex).real === 'number' &&
|
|
2621
|
+
typeof (value as $.Complex).imag === 'number'
|
|
2622
|
+
) {
|
|
2623
|
+
return new BasicType(Complex128, 'complex128', 16)
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2006
2626
|
// Check for arrays
|
|
2007
2627
|
if (globalThis.Array.isArray(value)) {
|
|
2008
2628
|
if (value.length === 0) {
|
|
@@ -2101,7 +2721,7 @@ function getTypeOf(value: ReflectValue): Type {
|
|
|
2101
2721
|
// Check if fieldInfo is a StructFieldInfo with type and tag
|
|
2102
2722
|
if (isStructFieldInfo(fieldInfo)) {
|
|
2103
2723
|
return {
|
|
2104
|
-
name,
|
|
2724
|
+
name: fieldInfo.name ?? name,
|
|
2105
2725
|
type: StructType.createTypeFromFieldInfo(fieldInfo.type),
|
|
2106
2726
|
tag: fieldInfo.tag,
|
|
2107
2727
|
}
|
|
@@ -2134,24 +2754,35 @@ function getTypeOf(value: ReflectValue): Type {
|
|
|
2134
2754
|
|
|
2135
2755
|
// Exported functions as required by godoc.txt
|
|
2136
2756
|
export function TypeOf(i: ReflectValue): Type {
|
|
2137
|
-
return getTypeOf(i)
|
|
2757
|
+
return internType(getTypeOf(i))
|
|
2138
2758
|
}
|
|
2139
2759
|
|
|
2140
2760
|
export function ValueOf(i: ReflectValue): Value {
|
|
2141
2761
|
return new Value(i, getTypeOf(i))
|
|
2142
2762
|
}
|
|
2143
2763
|
|
|
2764
|
+
export function TypeAssert(
|
|
2765
|
+
typeArgs: $.GenericTypeArgs | undefined,
|
|
2766
|
+
v: Value,
|
|
2767
|
+
): [any, boolean] {
|
|
2768
|
+
const descriptor = typeArgs?.T
|
|
2769
|
+
if (!descriptor?.type) {
|
|
2770
|
+
return [v.Interface(), true]
|
|
2771
|
+
}
|
|
2772
|
+
return $.typeAssertTuple<any>(v.Interface(), descriptor.type)
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2144
2775
|
export function ArrayOf(length: number, elem: Type): Type {
|
|
2145
|
-
return new ArrayType(elem, length)
|
|
2776
|
+
return internType(new ArrayType(elem, length))
|
|
2146
2777
|
}
|
|
2147
2778
|
|
|
2148
2779
|
export function SliceOf(t: Type): Type {
|
|
2149
|
-
return new SliceType(t)
|
|
2780
|
+
return internType(new SliceType(t))
|
|
2150
2781
|
}
|
|
2151
2782
|
|
|
2152
2783
|
export function PointerTo(t: Type | null): Type | null {
|
|
2153
2784
|
if (t === null) return null
|
|
2154
|
-
return new PointerType(t)
|
|
2785
|
+
return internType(new PointerType(t))
|
|
2155
2786
|
}
|
|
2156
2787
|
|
|
2157
2788
|
export function PtrTo(t: Type | null): Type | null {
|
|
@@ -2159,66 +2790,98 @@ export function PtrTo(t: Type | null): Type | null {
|
|
|
2159
2790
|
}
|
|
2160
2791
|
|
|
2161
2792
|
export function MapOf(key: Type, elem: Type): Type {
|
|
2162
|
-
return new MapType(key, elem)
|
|
2793
|
+
return internType(new MapType(key, elem))
|
|
2163
2794
|
}
|
|
2164
2795
|
|
|
2165
2796
|
export function ChanOf(dir: ChanDir, t: Type): Type {
|
|
2166
|
-
return new ChannelType(t, dir)
|
|
2797
|
+
return internType(new ChannelType(t, dir))
|
|
2167
2798
|
}
|
|
2168
2799
|
|
|
2169
2800
|
export function TypeFor(typeArgs?: $.GenericTypeArgs): Type {
|
|
2170
2801
|
const descriptor = typeArgs?.T
|
|
2171
2802
|
if (descriptor?.type) {
|
|
2172
|
-
return typeFromTypeInfo(descriptor.type)
|
|
2803
|
+
return internType(typeFromTypeInfo(descriptor.type))
|
|
2173
2804
|
}
|
|
2174
2805
|
if (descriptor?.methods) {
|
|
2175
2806
|
const methods = Object.keys(descriptor.methods)
|
|
2176
2807
|
if (methods.length !== 0) {
|
|
2177
|
-
return
|
|
2178
|
-
|
|
2808
|
+
return internType(
|
|
2809
|
+
new InterfaceType(
|
|
2810
|
+
`interface { ${methods.map((method) => method + '()').join('; ')} }`,
|
|
2811
|
+
),
|
|
2179
2812
|
)
|
|
2180
2813
|
}
|
|
2181
2814
|
}
|
|
2182
2815
|
if (descriptor?.zero) {
|
|
2183
|
-
return getTypeOf(descriptor.zero())
|
|
2816
|
+
return internType(getTypeOf(descriptor.zero()))
|
|
2184
2817
|
}
|
|
2185
|
-
return new InterfaceType('interface{}')
|
|
2818
|
+
return internType(new InterfaceType('interface{}'))
|
|
2186
2819
|
}
|
|
2187
2820
|
|
|
2188
2821
|
function typeFromTypeInfo(info: $.TypeInfo | string): Type {
|
|
2189
2822
|
if (typeof info === 'string') {
|
|
2190
2823
|
const registered = builtinGetTypeByName(info)
|
|
2191
2824
|
if (registered) {
|
|
2192
|
-
return typeFromTypeInfo(registered)
|
|
2825
|
+
return internType(typeFromTypeInfo(registered))
|
|
2193
2826
|
}
|
|
2194
|
-
return StructType.createTypeFromFieldInfo(info)
|
|
2827
|
+
return internType(StructType.createTypeFromFieldInfo(info))
|
|
2195
2828
|
}
|
|
2196
2829
|
switch (info.kind) {
|
|
2197
2830
|
case $.TypeKind.Array:
|
|
2198
|
-
return
|
|
2199
|
-
|
|
2200
|
-
|
|
2831
|
+
return internType(
|
|
2832
|
+
new ArrayType(
|
|
2833
|
+
typeFromTypeInfo(
|
|
2834
|
+
info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' },
|
|
2835
|
+
),
|
|
2836
|
+
info.length,
|
|
2837
|
+
),
|
|
2201
2838
|
)
|
|
2839
|
+
case $.TypeKind.Basic:
|
|
2840
|
+
return internType(StructType.createTypeFromFieldInfo(info))
|
|
2202
2841
|
case $.TypeKind.Channel:
|
|
2203
|
-
return
|
|
2204
|
-
|
|
2205
|
-
|
|
2842
|
+
return internType(
|
|
2843
|
+
new ChannelType(
|
|
2844
|
+
typeFromTypeInfo(
|
|
2845
|
+
info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' },
|
|
2846
|
+
),
|
|
2847
|
+
chanDirFromTypeInfo(info.direction),
|
|
2848
|
+
),
|
|
2206
2849
|
)
|
|
2207
2850
|
case $.TypeKind.Function:
|
|
2208
|
-
return functionTypeFromInfo(info)
|
|
2851
|
+
return internType(functionTypeFromInfo(info))
|
|
2209
2852
|
case $.TypeKind.Interface:
|
|
2210
|
-
return interfaceTypeFromInfo(info)
|
|
2853
|
+
return internType(interfaceTypeFromInfo(info))
|
|
2211
2854
|
case $.TypeKind.Map:
|
|
2212
|
-
return
|
|
2213
|
-
|
|
2214
|
-
|
|
2855
|
+
return internType(
|
|
2856
|
+
new MapType(
|
|
2857
|
+
typeFromTypeInfo(
|
|
2858
|
+
info.keyType ?? { kind: $.TypeKind.Basic, name: 'unknown' },
|
|
2859
|
+
),
|
|
2860
|
+
typeFromTypeInfo(
|
|
2861
|
+
info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' },
|
|
2862
|
+
),
|
|
2863
|
+
),
|
|
2864
|
+
)
|
|
2865
|
+
case $.TypeKind.Slice:
|
|
2866
|
+
return internType(
|
|
2867
|
+
new SliceType(
|
|
2868
|
+
typeFromTypeInfo(
|
|
2869
|
+
info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' },
|
|
2870
|
+
),
|
|
2871
|
+
),
|
|
2215
2872
|
)
|
|
2873
|
+
case $.TypeKind.Struct:
|
|
2874
|
+
return internType(StructType.createTypeFromFieldInfo(info))
|
|
2216
2875
|
case $.TypeKind.Pointer:
|
|
2217
|
-
return
|
|
2218
|
-
|
|
2876
|
+
return internType(
|
|
2877
|
+
new PointerType(
|
|
2878
|
+
typeFromTypeInfo(
|
|
2879
|
+
info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' },
|
|
2880
|
+
),
|
|
2881
|
+
),
|
|
2219
2882
|
)
|
|
2220
2883
|
default:
|
|
2221
|
-
return StructType.createTypeFromFieldInfo(info)
|
|
2884
|
+
return internType(StructType.createTypeFromFieldInfo(info))
|
|
2222
2885
|
}
|
|
2223
2886
|
}
|
|
2224
2887
|
|