goscript 0.1.1 → 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/cmd/goscript/cmd-test.go +104 -11
- package/cmd/goscript/cmd-test_test.go +1 -1
- package/cmd/goscript/cmd_compile.go +9 -0
- package/compiler/compile-request.go +31 -0
- package/compiler/compiler.go +1 -1
- package/compiler/compliance_test.go +0 -2
- package/compiler/config.go +2 -0
- package/compiler/gotest/package-result.go +2 -0
- package/compiler/gotest/request.go +85 -20
- package/compiler/gotest/runner.go +733 -96
- package/compiler/gotest/runner_test.go +647 -3
- package/compiler/lowered-program.go +9 -2
- package/compiler/lowering.go +2001 -345
- package/compiler/override-facts.go +77 -27
- package/compiler/override-registry.go +5 -4
- package/compiler/override-registry_test.go +135 -0
- package/compiler/package-graph_test.go +62 -7
- package/compiler/package-test-graph-variant.go +40 -16
- package/compiler/package-test-graph.go +0 -5
- package/compiler/package-test-graph_test.go +61 -3
- package/compiler/runtime-contract.go +40 -0
- package/compiler/semantic-model-types.go +16 -0
- package/compiler/semantic-model.go +336 -91
- package/compiler/semantic-model_test.go +50 -1
- package/compiler/service.go +9 -3
- package/compiler/skeleton_test.go +1921 -298
- package/compiler/tsworkspace/owner-process-unix_test.go +72 -0
- package/compiler/tsworkspace/owner.go +8 -0
- package/compiler/tsworkspace/tool-process-other.go +14 -0
- package/compiler/tsworkspace/tool-process-unix.go +19 -0
- package/compiler/typescript-emitter.go +122 -9
- package/dist/gs/builtin/builtin.d.ts +20 -1
- package/dist/gs/builtin/builtin.js +246 -26
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/channel.d.ts +24 -10
- package/dist/gs/builtin/channel.js +107 -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 +43 -9
- package/dist/gs/builtin/slice.js +437 -234
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +2 -0
- package/dist/gs/builtin/type.js +47 -7
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +2 -0
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.js +28 -28
- package/dist/gs/bytes/buffer.gs.js.map +1 -1
- package/dist/gs/bytes/iter.gs.js +13 -13
- package/dist/gs/bytes/iter.gs.js.map +1 -1
- package/dist/gs/compress/zlib/index.d.ts +26 -0
- package/dist/gs/compress/zlib/index.js +168 -0
- package/dist/gs/compress/zlib/index.js.map +1 -0
- package/dist/gs/context/context.d.ts +1 -1
- package/dist/gs/context/context.js +8 -3
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/crypto/ecdh/index.d.ts +52 -0
- package/dist/gs/crypto/ecdh/index.js +226 -0
- package/dist/gs/crypto/ecdh/index.js.map +1 -0
- package/dist/gs/crypto/ed25519/index.d.ts +34 -0
- package/dist/gs/crypto/ed25519/index.js +160 -0
- package/dist/gs/crypto/ed25519/index.js.map +1 -0
- package/dist/gs/crypto/internal/constanttime/index.d.ts +4 -0
- package/dist/gs/crypto/internal/constanttime/index.js +18 -0
- package/dist/gs/crypto/internal/constanttime/index.js.map +1 -0
- package/dist/gs/crypto/rand/index.d.ts +2 -0
- package/dist/gs/crypto/rand/index.js +85 -0
- package/dist/gs/crypto/rand/index.js.map +1 -1
- package/dist/gs/crypto/sha256/index.d.ts +8 -0
- package/dist/gs/crypto/sha256/index.js +118 -0
- package/dist/gs/crypto/sha256/index.js.map +1 -0
- package/dist/gs/crypto/sha512/index.d.ts +14 -0
- package/dist/gs/crypto/sha512/index.js +129 -0
- package/dist/gs/crypto/sha512/index.js.map +1 -0
- package/dist/gs/encoding/json/index.d.ts +3 -0
- package/dist/gs/encoding/json/index.js +15 -0
- package/dist/gs/encoding/json/index.js.map +1 -1
- package/dist/gs/errors/errors.js +29 -6
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +7 -7
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +52 -18
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +56 -20
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +57 -3
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +366 -1
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/util/conc/index.d.ts +20 -0
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js +134 -0
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js.map +1 -0
- package/dist/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.js.map +1 -1
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.d.ts +3 -0
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.js +50 -0
- package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.js.map +1 -0
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js +3 -2
- package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -1
- package/dist/gs/github.com/mr-tron/base58/base58/index.d.ts +27 -0
- package/dist/gs/github.com/mr-tron/base58/base58/index.js +172 -0
- package/dist/gs/github.com/mr-tron/base58/base58/index.js.map +1 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.d.ts +21 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.js +22 -0
- package/dist/gs/github.com/zeebo/blake3/internal/consts/index.js.map +1 -0
- package/dist/gs/go/token/index.js +11 -4
- package/dist/gs/go/token/index.js.map +1 -1
- package/dist/gs/hash/fnv/index.d.ts +57 -0
- package/dist/gs/hash/fnv/index.js +299 -0
- package/dist/gs/hash/fnv/index.js.map +1 -0
- package/dist/gs/hash/index.d.ts +17 -0
- package/dist/gs/hash/index.js +94 -0
- package/dist/gs/hash/index.js.map +1 -0
- package/dist/gs/io/fs/readlink.js +2 -6
- package/dist/gs/io/fs/readlink.js.map +1 -1
- package/dist/gs/io/fs/walk.js.map +1 -1
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/iter/iter.d.ts +3 -2
- package/dist/gs/iter/iter.js.map +1 -1
- package/dist/gs/maps/iter.d.ts +5 -5
- package/dist/gs/maps/iter.js +48 -21
- package/dist/gs/maps/iter.js.map +1 -1
- package/dist/gs/maps/maps.d.ts +6 -6
- package/dist/gs/math/bits/index.js +14 -24
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/mime/index.js +3 -1
- package/dist/gs/mime/index.js.map +1 -1
- package/dist/gs/net/http/httptest/index.d.ts +20 -1
- package/dist/gs/net/http/httptest/index.js +83 -3
- package/dist/gs/net/http/httptest/index.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +110 -6
- package/dist/gs/net/http/index.js +262 -16
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/net/http/pprof/index.d.ts +8 -0
- package/dist/gs/net/http/pprof/index.js +59 -0
- package/dist/gs/net/http/pprof/index.js.map +1 -0
- package/dist/gs/os/error.gs.js +9 -7
- package/dist/gs/os/error.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.js +95 -15
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.d.ts +5 -3
- package/dist/gs/path/filepath/path.js +65 -10
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +3 -2
- package/dist/gs/reflect/index.js +2 -1
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/iter.js +2 -2
- package/dist/gs/reflect/iter.js.map +1 -1
- package/dist/gs/reflect/map.js +26 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +24 -5
- package/dist/gs/reflect/type.js +390 -38
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.d.ts +1 -0
- package/dist/gs/reflect/types.js +3 -1
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/value.d.ts +4 -1
- package/dist/gs/reflect/value.js +39 -1
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/reflect/visiblefields.js +1 -1
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/runtime/debug/index.d.ts +39 -0
- package/dist/gs/runtime/debug/index.js +58 -0
- package/dist/gs/runtime/debug/index.js.map +1 -1
- package/dist/gs/runtime/pprof/index.d.ts +20 -0
- package/dist/gs/runtime/pprof/index.js +85 -0
- package/dist/gs/runtime/pprof/index.js.map +1 -0
- package/dist/gs/runtime/trace/index.d.ts +19 -0
- package/dist/gs/runtime/trace/index.js +64 -0
- package/dist/gs/runtime/trace/index.js.map +1 -0
- package/dist/gs/slices/slices.d.ts +24 -9
- package/dist/gs/slices/slices.js +229 -24
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/sort/slice.gs.d.ts +5 -3
- package/dist/gs/sort/slice.gs.js +55 -17
- package/dist/gs/sort/slice.gs.js.map +1 -1
- package/dist/gs/strings/builder.js +26 -17
- package/dist/gs/strings/builder.js.map +1 -1
- package/dist/gs/strings/iter.js +140 -75
- package/dist/gs/strings/iter.js.map +1 -1
- package/dist/gs/strings/replace.js +2 -2
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/strings.js +52 -6
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/sync.d.ts +6 -3
- package/dist/gs/sync/sync.js +39 -11
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/errors.d.ts +116 -112
- package/dist/gs/syscall/errors.js +38 -1
- package/dist/gs/syscall/errors.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +2 -8
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/syscall/js/index.js +20 -12
- package/dist/gs/syscall/js/index.js.map +1 -1
- package/dist/gs/syscall/types.d.ts +4 -1
- package/dist/gs/syscall/types.js.map +1 -1
- package/dist/gs/testing/testing.d.ts +4 -3
- package/dist/gs/testing/testing.js +21 -4
- package/dist/gs/testing/testing.js.map +1 -1
- package/dist/gs/time/time.js +22 -0
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/dist/gs/unique/index.js +7 -2
- package/dist/gs/unique/index.js.map +1 -1
- package/go.mod +8 -8
- package/go.sum +14 -23
- package/gs/builtin/builtin.ts +364 -37
- package/gs/builtin/channel.ts +161 -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 +257 -10
- package/gs/builtin/slice.test.ts +70 -0
- package/gs/builtin/slice.ts +566 -255
- package/gs/builtin/type.ts +53 -9
- package/gs/builtin/varRef.ts +2 -0
- package/gs/bytes/buffer.gs.ts +28 -28
- package/gs/bytes/iter.gs.ts +13 -14
- package/gs/compress/zlib/index.test.ts +28 -0
- package/gs/compress/zlib/index.ts +200 -0
- package/gs/compress/zlib/meta.json +3 -0
- package/gs/context/context.test.ts +31 -1
- package/gs/context/context.ts +9 -4
- package/gs/crypto/ecdh/index.test.ts +43 -0
- package/gs/crypto/ecdh/index.ts +274 -0
- package/gs/crypto/ed25519/index.test.ts +41 -0
- package/gs/crypto/ed25519/index.ts +238 -0
- package/gs/crypto/ed25519/meta.json +13 -0
- package/gs/crypto/internal/constanttime/index.test.ts +25 -0
- package/gs/crypto/internal/constanttime/index.ts +22 -0
- package/gs/crypto/rand/index.test.ts +89 -1
- package/gs/crypto/rand/index.ts +103 -1
- package/gs/crypto/rand/meta.json +4 -1
- package/gs/crypto/sha256/index.test.ts +78 -0
- package/gs/crypto/sha256/index.ts +150 -0
- package/gs/crypto/sha256/meta.json +9 -0
- package/gs/crypto/sha512/index.test.ts +31 -0
- package/gs/crypto/sha512/index.ts +161 -0
- package/gs/crypto/sha512/meta.json +11 -0
- package/gs/encoding/json/index.test.ts +25 -3
- package/gs/encoding/json/index.ts +21 -3
- package/gs/errors/errors.test.ts +4 -1
- package/gs/errors/errors.ts +32 -8
- package/gs/fmt/fmt.test.ts +3 -1
- package/gs/fmt/fmt.ts +1 -5
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +62 -7
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +78 -36
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +32 -11
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +122 -43
- package/gs/github.com/aperturerobotics/starpc/srpc/index.test.ts +31 -0
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +518 -4
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +6 -0
- package/gs/github.com/aperturerobotics/util/conc/index.test.ts +30 -0
- package/gs/github.com/aperturerobotics/util/conc/index.ts +172 -0
- package/gs/github.com/aperturerobotics/util/conc/meta.json +9 -0
- package/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.ts +1 -4
- package/gs/github.com/hack-pad/safejs/internal/catch/index.test.ts +35 -0
- package/gs/github.com/hack-pad/safejs/internal/catch/index.ts +65 -0
- package/gs/github.com/hack-pad/safejs/internal/catch/meta.json +9 -0
- package/gs/github.com/klauspost/compress/internal/le/index.test.ts +2 -1
- package/gs/github.com/klauspost/compress/internal/le/index.ts +6 -5
- package/gs/github.com/mr-tron/base58/base58/index.test.ts +70 -0
- package/gs/github.com/mr-tron/base58/base58/index.ts +231 -0
- package/gs/github.com/mr-tron/base58/base58/meta.json +3 -0
- package/gs/github.com/zeebo/blake3/internal/consts/index.test.ts +46 -0
- package/gs/github.com/zeebo/blake3/internal/consts/index.ts +26 -0
- package/gs/go/token/index.ts +17 -4
- package/gs/hash/fnv/index.test.ts +67 -0
- package/gs/hash/fnv/index.ts +351 -0
- package/gs/hash/fnv/meta.json +3 -0
- package/gs/hash/index.test.ts +37 -0
- package/gs/hash/index.ts +118 -0
- package/gs/hash/meta.json +5 -0
- package/gs/internal/byteorder/index.test.ts +6 -6
- package/gs/io/fs/readlink.ts +40 -48
- package/gs/io/fs/walk.ts +10 -2
- package/gs/io/io.ts +4 -1
- package/gs/iter/iter.ts +8 -2
- package/gs/maps/iter.ts +69 -26
- package/gs/maps/maps.test.ts +23 -0
- package/gs/maps/maps.ts +6 -6
- package/gs/math/bits/index.test.ts +20 -0
- package/gs/math/bits/index.ts +15 -28
- package/gs/mime/index.ts +8 -2
- package/gs/net/http/httptest/index.test.ts +53 -0
- package/gs/net/http/httptest/index.ts +98 -3
- package/gs/net/http/index.test.ts +129 -1
- package/gs/net/http/index.ts +370 -19
- package/gs/net/http/meta.json +6 -0
- package/gs/net/http/pprof/index.test.ts +47 -0
- package/gs/net/http/pprof/index.ts +65 -0
- package/gs/os/error.gs.ts +9 -10
- package/gs/os/error.test.ts +41 -0
- package/gs/os/file_unix_js.test.ts +55 -0
- package/gs/os/tempfile.gs.test.ts +37 -10
- package/gs/os/types_js.gs.ts +94 -15
- package/gs/path/filepath/match.ts +4 -1
- package/gs/path/filepath/meta.json +6 -0
- package/gs/path/filepath/path.test.ts +57 -2
- package/gs/path/filepath/path.ts +91 -12
- package/gs/reflect/field.test.ts +63 -0
- package/gs/reflect/index.ts +4 -1
- package/gs/reflect/iter.ts +2 -2
- package/gs/reflect/map.test.ts +24 -2
- package/gs/reflect/map.ts +35 -0
- package/gs/reflect/type.ts +543 -60
- package/gs/reflect/typefor.test.ts +100 -0
- package/gs/reflect/types.ts +3 -1
- package/gs/reflect/value.ts +50 -1
- package/gs/reflect/visiblefields.ts +1 -1
- package/gs/runtime/debug/index.test.ts +22 -1
- package/gs/runtime/debug/index.ts +88 -0
- package/gs/runtime/pprof/index.test.ts +36 -0
- package/gs/runtime/pprof/index.ts +104 -0
- package/gs/runtime/pprof/meta.json +6 -0
- package/gs/runtime/trace/index.test.ts +45 -0
- package/gs/runtime/trace/index.ts +97 -0
- package/gs/runtime/trace/meta.json +7 -0
- package/gs/slices/meta.json +2 -1
- package/gs/slices/slices.test.ts +86 -0
- package/gs/slices/slices.ts +284 -37
- package/gs/sort/slice.gs.ts +73 -23
- package/gs/sort/slice.test.ts +40 -0
- package/gs/strings/builder.test.ts +8 -0
- package/gs/strings/builder.ts +29 -17
- package/gs/strings/iter.test.ts +5 -7
- package/gs/strings/iter.ts +146 -71
- package/gs/strings/replace.test.ts +1 -4
- package/gs/strings/replace.ts +6 -6
- package/gs/strings/strings.test.ts +4 -0
- package/gs/strings/strings.ts +54 -6
- package/gs/sync/sync.test.ts +57 -1
- package/gs/sync/sync.ts +45 -13
- package/gs/syscall/errors.ts +158 -115
- package/gs/syscall/fs.ts +8 -8
- package/gs/syscall/js/index.ts +49 -22
- package/gs/syscall/net.test.ts +26 -0
- package/gs/syscall/types.ts +7 -2
- package/gs/testing/testing.test.ts +56 -0
- package/gs/testing/testing.ts +27 -10
- package/gs/time/meta.json +2 -2
- package/gs/time/time.test.ts +4 -0
- package/gs/time/time.ts +33 -2
- package/gs/unicode/unicode.test.ts +14 -3
- package/gs/unicode/unicode.ts +1 -5
- package/gs/unique/index.ts +9 -2
- package/package.json +3 -3
package/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';
|
|
@@ -153,6 +154,7 @@ export const UnsafePointer = 26;
|
|
|
153
154
|
const pointerAddressStride = 0x100000000;
|
|
154
155
|
const pointerAddresses = new WeakMap();
|
|
155
156
|
let nextPointerAddress = 1;
|
|
157
|
+
const canonicalTypes = new globalThis.Map();
|
|
156
158
|
function pointerAddress(value) {
|
|
157
159
|
let address = pointerAddresses.get(value);
|
|
158
160
|
if (address === undefined) {
|
|
@@ -162,17 +164,32 @@ function pointerAddress(value) {
|
|
|
162
164
|
}
|
|
163
165
|
return address;
|
|
164
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
|
+
}
|
|
165
176
|
// InvalidTypeInstance is a singleton type for invalid/zero reflect.Value
|
|
166
177
|
class InvalidTypeClass {
|
|
167
178
|
Kind() {
|
|
168
179
|
return Invalid;
|
|
169
180
|
}
|
|
181
|
+
Comparable() {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
170
184
|
String() {
|
|
171
185
|
return '<invalid reflect.Value>';
|
|
172
186
|
}
|
|
173
187
|
Name() {
|
|
174
188
|
return '';
|
|
175
189
|
}
|
|
190
|
+
PkgPath() {
|
|
191
|
+
return '';
|
|
192
|
+
}
|
|
176
193
|
Size() {
|
|
177
194
|
return 0;
|
|
178
195
|
}
|
|
@@ -188,9 +205,18 @@ class InvalidTypeClass {
|
|
|
188
205
|
Field(_i) {
|
|
189
206
|
throw new Error('reflect: Field of invalid type');
|
|
190
207
|
}
|
|
208
|
+
FieldByName(_name) {
|
|
209
|
+
return [new StructField(), false];
|
|
210
|
+
}
|
|
211
|
+
FieldByNameFunc(_match) {
|
|
212
|
+
return [new StructField(), false];
|
|
213
|
+
}
|
|
191
214
|
Implements(_u) {
|
|
192
215
|
return false;
|
|
193
216
|
}
|
|
217
|
+
AssignableTo(_u) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
194
220
|
OverflowInt(_x) {
|
|
195
221
|
throw new Error('reflect: OverflowInt of invalid type');
|
|
196
222
|
}
|
|
@@ -203,6 +229,9 @@ class InvalidTypeClass {
|
|
|
203
229
|
NumMethod() {
|
|
204
230
|
return 0;
|
|
205
231
|
}
|
|
232
|
+
MethodByName(_name) {
|
|
233
|
+
return [zeroMethod(), false];
|
|
234
|
+
}
|
|
206
235
|
Len() {
|
|
207
236
|
throw new Error('reflect: Len of invalid type');
|
|
208
237
|
}
|
|
@@ -344,6 +373,27 @@ export class Value {
|
|
|
344
373
|
Kind_String(this._type.Kind()) +
|
|
345
374
|
' Value');
|
|
346
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
|
+
}
|
|
347
397
|
Bytes() {
|
|
348
398
|
if (this._value instanceof Uint8Array) {
|
|
349
399
|
return this._value;
|
|
@@ -381,6 +431,20 @@ export class Value {
|
|
|
381
431
|
// Pass parent struct and field name so Set() can update the struct
|
|
382
432
|
return new Value(fieldVal, field.Type, undefined, parentObj, field.Name);
|
|
383
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
|
+
}
|
|
384
448
|
// Additional methods needed by various parts of the codebase
|
|
385
449
|
UnsafePointer() {
|
|
386
450
|
return this._value;
|
|
@@ -422,6 +486,15 @@ export class Value {
|
|
|
422
486
|
}
|
|
423
487
|
return 0;
|
|
424
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
|
+
}
|
|
425
498
|
pointer() {
|
|
426
499
|
return this._value;
|
|
427
500
|
}
|
|
@@ -445,7 +518,10 @@ export class Value {
|
|
|
445
518
|
throw new Error('reflect: call of reflect.Value.Addr on invalid Value');
|
|
446
519
|
}
|
|
447
520
|
const ptrType = PointerTo(this.Type());
|
|
448
|
-
|
|
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);
|
|
449
525
|
}
|
|
450
526
|
CanSet() {
|
|
451
527
|
// Simplified: all valid values are settable in GoScript since we handle
|
|
@@ -489,6 +565,36 @@ export class Value {
|
|
|
489
565
|
Interface() {
|
|
490
566
|
return this._value;
|
|
491
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
|
+
}
|
|
492
598
|
IsZero() {
|
|
493
599
|
const zeroVal = Zero(this.Type()).value;
|
|
494
600
|
return DeepEqual(this._value, zeroVal);
|
|
@@ -500,12 +606,29 @@ export class Value {
|
|
|
500
606
|
return 0;
|
|
501
607
|
}
|
|
502
608
|
MapRange() {
|
|
503
|
-
|
|
504
|
-
|
|
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);
|
|
505
619
|
}
|
|
506
|
-
MapIndex(
|
|
507
|
-
|
|
508
|
-
|
|
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());
|
|
509
632
|
}
|
|
510
633
|
MapKeys() {
|
|
511
634
|
if (this.Kind() !== Map) {
|
|
@@ -812,17 +935,22 @@ export class BasicType {
|
|
|
812
935
|
_kind;
|
|
813
936
|
_name;
|
|
814
937
|
_size;
|
|
815
|
-
|
|
938
|
+
_typeName;
|
|
939
|
+
constructor(_kind, _name, _size = 8, _typeName = '') {
|
|
816
940
|
this._kind = _kind;
|
|
817
941
|
this._name = _name;
|
|
818
942
|
this._size = _size;
|
|
943
|
+
this._typeName = _typeName;
|
|
819
944
|
}
|
|
820
945
|
String() {
|
|
821
|
-
return this._name;
|
|
946
|
+
return this._typeName || this._name;
|
|
822
947
|
}
|
|
823
948
|
Kind() {
|
|
824
949
|
return this._kind;
|
|
825
950
|
}
|
|
951
|
+
Comparable() {
|
|
952
|
+
return this._kind !== Func && this._kind !== Map && this._kind !== Slice;
|
|
953
|
+
}
|
|
826
954
|
Size() {
|
|
827
955
|
return this._size;
|
|
828
956
|
}
|
|
@@ -833,15 +961,34 @@ export class BasicType {
|
|
|
833
961
|
return 0;
|
|
834
962
|
}
|
|
835
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
|
+
}
|
|
836
970
|
return '';
|
|
837
971
|
}
|
|
838
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
|
+
}
|
|
839
980
|
// Basic types have names like 'int', 'string', etc.
|
|
840
981
|
return this._name;
|
|
841
982
|
}
|
|
842
983
|
Field(_i) {
|
|
843
984
|
throw new Error(`reflect: Field of non-struct type ${this._name}`);
|
|
844
985
|
}
|
|
986
|
+
FieldByName(name) {
|
|
987
|
+
return typeFieldByName(this, name);
|
|
988
|
+
}
|
|
989
|
+
FieldByNameFunc(match) {
|
|
990
|
+
return typeFieldByNameFunc(this, match);
|
|
991
|
+
}
|
|
845
992
|
Key() {
|
|
846
993
|
throw new Error(`reflect: Key of non-map type ${this._name}`);
|
|
847
994
|
}
|
|
@@ -854,6 +1001,9 @@ export class BasicType {
|
|
|
854
1001
|
}
|
|
855
1002
|
return false;
|
|
856
1003
|
}
|
|
1004
|
+
AssignableTo(u) {
|
|
1005
|
+
return typeAssignableTo(this, u);
|
|
1006
|
+
}
|
|
857
1007
|
common() {
|
|
858
1008
|
return new rtype(this._kind);
|
|
859
1009
|
}
|
|
@@ -910,6 +1060,9 @@ export class BasicType {
|
|
|
910
1060
|
NumMethod() {
|
|
911
1061
|
return 0;
|
|
912
1062
|
}
|
|
1063
|
+
MethodByName(_name) {
|
|
1064
|
+
return [zeroMethod(), false];
|
|
1065
|
+
}
|
|
913
1066
|
Len() {
|
|
914
1067
|
throw new Error('reflect: call of reflect.Type.Len on ' +
|
|
915
1068
|
Kind_String(this._kind) +
|
|
@@ -959,6 +1112,9 @@ class SliceType {
|
|
|
959
1112
|
Kind() {
|
|
960
1113
|
return Slice;
|
|
961
1114
|
}
|
|
1115
|
+
Comparable() {
|
|
1116
|
+
return false;
|
|
1117
|
+
}
|
|
962
1118
|
Size() {
|
|
963
1119
|
return 24; // slice header size
|
|
964
1120
|
}
|
|
@@ -978,6 +1134,12 @@ class SliceType {
|
|
|
978
1134
|
Field(_i) {
|
|
979
1135
|
throw new Error('reflect: Field of non-struct type');
|
|
980
1136
|
}
|
|
1137
|
+
FieldByName(name) {
|
|
1138
|
+
return typeFieldByName(this, name);
|
|
1139
|
+
}
|
|
1140
|
+
FieldByNameFunc(match) {
|
|
1141
|
+
return typeFieldByNameFunc(this, match);
|
|
1142
|
+
}
|
|
981
1143
|
Key() {
|
|
982
1144
|
throw new Error('reflect: Key of non-map type');
|
|
983
1145
|
}
|
|
@@ -990,6 +1152,9 @@ class SliceType {
|
|
|
990
1152
|
}
|
|
991
1153
|
return false;
|
|
992
1154
|
}
|
|
1155
|
+
AssignableTo(u) {
|
|
1156
|
+
return typeAssignableTo(this, u);
|
|
1157
|
+
}
|
|
993
1158
|
OverflowInt(_x) {
|
|
994
1159
|
throw new Error('reflect: call of reflect.Type.OverflowInt on slice Type');
|
|
995
1160
|
}
|
|
@@ -1002,6 +1167,9 @@ class SliceType {
|
|
|
1002
1167
|
NumMethod() {
|
|
1003
1168
|
return 0;
|
|
1004
1169
|
}
|
|
1170
|
+
MethodByName(_name) {
|
|
1171
|
+
return [zeroMethod(), false];
|
|
1172
|
+
}
|
|
1005
1173
|
Len() {
|
|
1006
1174
|
throw new Error('reflect: call of reflect.Type.Len on slice Type');
|
|
1007
1175
|
}
|
|
@@ -1023,6 +1191,9 @@ class ArrayType {
|
|
|
1023
1191
|
Kind() {
|
|
1024
1192
|
return Array;
|
|
1025
1193
|
}
|
|
1194
|
+
Comparable() {
|
|
1195
|
+
return this._elemType.Comparable();
|
|
1196
|
+
}
|
|
1026
1197
|
Size() {
|
|
1027
1198
|
return this._elemType.Size() * this._len;
|
|
1028
1199
|
}
|
|
@@ -1045,6 +1216,12 @@ class ArrayType {
|
|
|
1045
1216
|
Field(_i) {
|
|
1046
1217
|
throw new Error('reflect: Field of non-struct type');
|
|
1047
1218
|
}
|
|
1219
|
+
FieldByName(name) {
|
|
1220
|
+
return typeFieldByName(this, name);
|
|
1221
|
+
}
|
|
1222
|
+
FieldByNameFunc(match) {
|
|
1223
|
+
return typeFieldByNameFunc(this, match);
|
|
1224
|
+
}
|
|
1048
1225
|
Key() {
|
|
1049
1226
|
throw new Error('reflect: Key of non-map type');
|
|
1050
1227
|
}
|
|
@@ -1057,6 +1234,9 @@ class ArrayType {
|
|
|
1057
1234
|
}
|
|
1058
1235
|
return false;
|
|
1059
1236
|
}
|
|
1237
|
+
AssignableTo(u) {
|
|
1238
|
+
return typeAssignableTo(this, u);
|
|
1239
|
+
}
|
|
1060
1240
|
common() {
|
|
1061
1241
|
return new rtype(this.Kind());
|
|
1062
1242
|
}
|
|
@@ -1072,6 +1252,9 @@ class ArrayType {
|
|
|
1072
1252
|
NumMethod() {
|
|
1073
1253
|
return 0;
|
|
1074
1254
|
}
|
|
1255
|
+
MethodByName(_name) {
|
|
1256
|
+
return [zeroMethod(), false];
|
|
1257
|
+
}
|
|
1075
1258
|
Bits() {
|
|
1076
1259
|
throw new Error('reflect: call of reflect.Type.Bits on array Type');
|
|
1077
1260
|
}
|
|
@@ -1088,6 +1271,9 @@ class PointerType {
|
|
|
1088
1271
|
Kind() {
|
|
1089
1272
|
return Ptr;
|
|
1090
1273
|
}
|
|
1274
|
+
Comparable() {
|
|
1275
|
+
return true;
|
|
1276
|
+
}
|
|
1091
1277
|
Size() {
|
|
1092
1278
|
return 8; // pointer size
|
|
1093
1279
|
}
|
|
@@ -1107,6 +1293,12 @@ class PointerType {
|
|
|
1107
1293
|
Field(_i) {
|
|
1108
1294
|
throw new Error('reflect: Field of non-struct type');
|
|
1109
1295
|
}
|
|
1296
|
+
FieldByName(name) {
|
|
1297
|
+
return typeFieldByName(this, name);
|
|
1298
|
+
}
|
|
1299
|
+
FieldByNameFunc(match) {
|
|
1300
|
+
return typeFieldByNameFunc(this, match);
|
|
1301
|
+
}
|
|
1110
1302
|
Key() {
|
|
1111
1303
|
throw new Error('reflect: Key of non-map type');
|
|
1112
1304
|
}
|
|
@@ -1121,6 +1313,9 @@ class PointerType {
|
|
|
1121
1313
|
const elemTypeName = this._elemType.String();
|
|
1122
1314
|
return typeImplementsInterface(elemTypeName, u);
|
|
1123
1315
|
}
|
|
1316
|
+
AssignableTo(u) {
|
|
1317
|
+
return typeAssignableTo(this, u);
|
|
1318
|
+
}
|
|
1124
1319
|
common() {
|
|
1125
1320
|
return new rtype(this.Kind());
|
|
1126
1321
|
}
|
|
@@ -1136,6 +1331,9 @@ class PointerType {
|
|
|
1136
1331
|
NumMethod() {
|
|
1137
1332
|
return 0;
|
|
1138
1333
|
}
|
|
1334
|
+
MethodByName(name) {
|
|
1335
|
+
return typeMethodByName(this._elemType, name);
|
|
1336
|
+
}
|
|
1139
1337
|
Len() {
|
|
1140
1338
|
throw new Error('reflect: call of reflect.Type.Len on pointer Type');
|
|
1141
1339
|
}
|
|
@@ -1155,6 +1353,9 @@ class FunctionType {
|
|
|
1155
1353
|
Kind() {
|
|
1156
1354
|
return Func;
|
|
1157
1355
|
}
|
|
1356
|
+
Comparable() {
|
|
1357
|
+
return false;
|
|
1358
|
+
}
|
|
1158
1359
|
Size() {
|
|
1159
1360
|
return 8; // function pointer size
|
|
1160
1361
|
}
|
|
@@ -1174,6 +1375,12 @@ class FunctionType {
|
|
|
1174
1375
|
Field(_i) {
|
|
1175
1376
|
throw new Error('reflect: Field of non-struct type');
|
|
1176
1377
|
}
|
|
1378
|
+
FieldByName(name) {
|
|
1379
|
+
return typeFieldByName(this, name);
|
|
1380
|
+
}
|
|
1381
|
+
FieldByNameFunc(match) {
|
|
1382
|
+
return typeFieldByNameFunc(this, match);
|
|
1383
|
+
}
|
|
1177
1384
|
Key() {
|
|
1178
1385
|
throw new Error('reflect: Key of non-map type');
|
|
1179
1386
|
}
|
|
@@ -1186,6 +1393,9 @@ class FunctionType {
|
|
|
1186
1393
|
}
|
|
1187
1394
|
return false;
|
|
1188
1395
|
}
|
|
1396
|
+
AssignableTo(u) {
|
|
1397
|
+
return typeAssignableTo(this, u);
|
|
1398
|
+
}
|
|
1189
1399
|
common() {
|
|
1190
1400
|
return new rtype(this.Kind());
|
|
1191
1401
|
}
|
|
@@ -1201,6 +1411,9 @@ class FunctionType {
|
|
|
1201
1411
|
NumMethod() {
|
|
1202
1412
|
return 0;
|
|
1203
1413
|
}
|
|
1414
|
+
MethodByName(_name) {
|
|
1415
|
+
return [zeroMethod(), false];
|
|
1416
|
+
}
|
|
1204
1417
|
Len() {
|
|
1205
1418
|
throw new Error('reflect: call of reflect.Type.Len on func Type');
|
|
1206
1419
|
}
|
|
@@ -1222,6 +1435,9 @@ class MapType {
|
|
|
1222
1435
|
Kind() {
|
|
1223
1436
|
return Map;
|
|
1224
1437
|
}
|
|
1438
|
+
Comparable() {
|
|
1439
|
+
return false;
|
|
1440
|
+
}
|
|
1225
1441
|
Size() {
|
|
1226
1442
|
return 8; // map header size
|
|
1227
1443
|
}
|
|
@@ -1244,6 +1460,12 @@ class MapType {
|
|
|
1244
1460
|
Field(_i) {
|
|
1245
1461
|
throw new Error('reflect: Field of non-struct type');
|
|
1246
1462
|
}
|
|
1463
|
+
FieldByName(name) {
|
|
1464
|
+
return typeFieldByName(this, name);
|
|
1465
|
+
}
|
|
1466
|
+
FieldByNameFunc(match) {
|
|
1467
|
+
return typeFieldByNameFunc(this, match);
|
|
1468
|
+
}
|
|
1247
1469
|
Implements(u) {
|
|
1248
1470
|
if (!u) {
|
|
1249
1471
|
return false;
|
|
@@ -1253,6 +1475,9 @@ class MapType {
|
|
|
1253
1475
|
}
|
|
1254
1476
|
return false;
|
|
1255
1477
|
}
|
|
1478
|
+
AssignableTo(u) {
|
|
1479
|
+
return typeAssignableTo(this, u);
|
|
1480
|
+
}
|
|
1256
1481
|
common() {
|
|
1257
1482
|
return new rtype(this.Kind());
|
|
1258
1483
|
}
|
|
@@ -1268,6 +1493,9 @@ class MapType {
|
|
|
1268
1493
|
NumMethod() {
|
|
1269
1494
|
return 0;
|
|
1270
1495
|
}
|
|
1496
|
+
MethodByName(_name) {
|
|
1497
|
+
return [zeroMethod(), false];
|
|
1498
|
+
}
|
|
1271
1499
|
Len() {
|
|
1272
1500
|
throw new Error('reflect: call of reflect.Type.Len on map Type');
|
|
1273
1501
|
}
|
|
@@ -1318,6 +1546,61 @@ function typeImplementsInterface(typeName, interfaceType) {
|
|
|
1318
1546
|
}
|
|
1319
1547
|
return true;
|
|
1320
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
|
+
}
|
|
1321
1604
|
class StructType {
|
|
1322
1605
|
_name;
|
|
1323
1606
|
_fields;
|
|
@@ -1331,6 +1614,9 @@ class StructType {
|
|
|
1331
1614
|
Kind() {
|
|
1332
1615
|
return Struct;
|
|
1333
1616
|
}
|
|
1617
|
+
Comparable() {
|
|
1618
|
+
return this._fields.every((field) => field.type.Comparable());
|
|
1619
|
+
}
|
|
1334
1620
|
Size() {
|
|
1335
1621
|
// Struct size is implementation-defined, we'll use a reasonable default
|
|
1336
1622
|
return this._fields.reduce((sum, field) => sum + field.type.Size(), 0);
|
|
@@ -1364,10 +1650,18 @@ class StructType {
|
|
|
1364
1650
|
const f = this._fields[i];
|
|
1365
1651
|
return new StructField({
|
|
1366
1652
|
Name: f.name,
|
|
1653
|
+
PkgPath: '',
|
|
1367
1654
|
Type: f.type,
|
|
1368
1655
|
Tag: f.tag ? new StructTag(f.tag) : undefined,
|
|
1656
|
+
Index: [i],
|
|
1369
1657
|
});
|
|
1370
1658
|
}
|
|
1659
|
+
FieldByName(name) {
|
|
1660
|
+
return typeFieldByName(this, name);
|
|
1661
|
+
}
|
|
1662
|
+
FieldByNameFunc(match) {
|
|
1663
|
+
return typeFieldByNameFunc(this, match);
|
|
1664
|
+
}
|
|
1371
1665
|
Key() {
|
|
1372
1666
|
throw new Error('reflect: Key of non-map type');
|
|
1373
1667
|
}
|
|
@@ -1380,6 +1674,9 @@ class StructType {
|
|
|
1380
1674
|
}
|
|
1381
1675
|
return typeImplementsInterface(this._name, u);
|
|
1382
1676
|
}
|
|
1677
|
+
AssignableTo(u) {
|
|
1678
|
+
return typeAssignableTo(this, u);
|
|
1679
|
+
}
|
|
1383
1680
|
common() {
|
|
1384
1681
|
return new rtype(this.Kind());
|
|
1385
1682
|
}
|
|
@@ -1393,7 +1690,10 @@ class StructType {
|
|
|
1393
1690
|
throw new Error('reflect: call of reflect.Type.OverflowFloat on struct Type');
|
|
1394
1691
|
}
|
|
1395
1692
|
NumMethod() {
|
|
1396
|
-
return
|
|
1693
|
+
return typeMethods(this).length;
|
|
1694
|
+
}
|
|
1695
|
+
MethodByName(name) {
|
|
1696
|
+
return typeMethodByName(this, name);
|
|
1397
1697
|
}
|
|
1398
1698
|
Len() {
|
|
1399
1699
|
throw new Error('reflect: call of reflect.Type.Len on struct Type');
|
|
@@ -1431,28 +1731,29 @@ class StructType {
|
|
|
1431
1731
|
else if (ti && ti.kind) {
|
|
1432
1732
|
// Handle TypeInfo objects from the builtin type system
|
|
1433
1733
|
const name = ti.name || 'unknown';
|
|
1734
|
+
const typeName = ti.typeName || '';
|
|
1434
1735
|
switch (ti.kind) {
|
|
1435
1736
|
case 'basic':
|
|
1436
1737
|
// Map TypeScript type names to Go type names
|
|
1437
1738
|
switch (name) {
|
|
1438
1739
|
case 'string':
|
|
1439
|
-
return new BasicType(String, 'string', 16);
|
|
1740
|
+
return new BasicType(String, 'string', 16, typeName);
|
|
1440
1741
|
case 'number':
|
|
1441
1742
|
case 'int':
|
|
1442
1743
|
case 'int32':
|
|
1443
1744
|
case 'int64':
|
|
1444
|
-
return new BasicType(Int, name === 'number' ? 'int' : name, 8);
|
|
1745
|
+
return new BasicType(Int, name === 'number' ? 'int' : name, 8, typeName);
|
|
1445
1746
|
case 'boolean':
|
|
1446
1747
|
case 'bool':
|
|
1447
|
-
return new BasicType(Bool, 'bool', 1);
|
|
1748
|
+
return new BasicType(Bool, 'bool', 1, typeName);
|
|
1448
1749
|
case 'float64':
|
|
1449
|
-
return new BasicType(Float64, 'float64', 8);
|
|
1750
|
+
return new BasicType(Float64, 'float64', 8, typeName);
|
|
1450
1751
|
case 'complex64':
|
|
1451
|
-
return new BasicType(Complex64, 'complex64', 8);
|
|
1752
|
+
return new BasicType(Complex64, 'complex64', 8, typeName);
|
|
1452
1753
|
case 'complex128':
|
|
1453
|
-
return new BasicType(Complex128, 'complex128', 16);
|
|
1754
|
+
return new BasicType(Complex128, 'complex128', 16, typeName);
|
|
1454
1755
|
default:
|
|
1455
|
-
return new BasicType(Invalid, name, 8);
|
|
1756
|
+
return new BasicType(Invalid, name, 8, typeName);
|
|
1456
1757
|
}
|
|
1457
1758
|
case 'slice':
|
|
1458
1759
|
if (ti.elemType) {
|
|
@@ -1467,7 +1768,7 @@ class StructType {
|
|
|
1467
1768
|
case 'interface':
|
|
1468
1769
|
return new InterfaceType(name);
|
|
1469
1770
|
case 'struct':
|
|
1470
|
-
return new StructType(name,
|
|
1771
|
+
return new StructType(name, structFieldsFromTypeInfo(ti));
|
|
1471
1772
|
default:
|
|
1472
1773
|
return new BasicType(Invalid, name, 8);
|
|
1473
1774
|
}
|
|
@@ -1475,6 +1776,21 @@ class StructType {
|
|
|
1475
1776
|
return new BasicType(Invalid, 'unknown', 8);
|
|
1476
1777
|
}
|
|
1477
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
|
+
}
|
|
1478
1794
|
class ChannelType {
|
|
1479
1795
|
_elemType;
|
|
1480
1796
|
_dir;
|
|
@@ -1498,6 +1814,9 @@ class ChannelType {
|
|
|
1498
1814
|
Kind() {
|
|
1499
1815
|
return Chan;
|
|
1500
1816
|
}
|
|
1817
|
+
Comparable() {
|
|
1818
|
+
return true;
|
|
1819
|
+
}
|
|
1501
1820
|
Size() {
|
|
1502
1821
|
// Channels are represented as pointers, so pointer size
|
|
1503
1822
|
return 8;
|
|
@@ -1518,6 +1837,12 @@ class ChannelType {
|
|
|
1518
1837
|
Field(_i) {
|
|
1519
1838
|
throw new Error('reflect: Field of non-struct type');
|
|
1520
1839
|
}
|
|
1840
|
+
FieldByName(name) {
|
|
1841
|
+
return typeFieldByName(this, name);
|
|
1842
|
+
}
|
|
1843
|
+
FieldByNameFunc(match) {
|
|
1844
|
+
return typeFieldByNameFunc(this, match);
|
|
1845
|
+
}
|
|
1521
1846
|
Key() {
|
|
1522
1847
|
throw new Error('reflect: Key of non-map type');
|
|
1523
1848
|
}
|
|
@@ -1530,6 +1855,9 @@ class ChannelType {
|
|
|
1530
1855
|
}
|
|
1531
1856
|
return false;
|
|
1532
1857
|
}
|
|
1858
|
+
AssignableTo(u) {
|
|
1859
|
+
return typeAssignableTo(this, u);
|
|
1860
|
+
}
|
|
1533
1861
|
common() {
|
|
1534
1862
|
return new rtype(this.Kind());
|
|
1535
1863
|
}
|
|
@@ -1548,6 +1876,9 @@ class ChannelType {
|
|
|
1548
1876
|
NumMethod() {
|
|
1549
1877
|
return 0;
|
|
1550
1878
|
}
|
|
1879
|
+
MethodByName(_name) {
|
|
1880
|
+
return [zeroMethod(), false];
|
|
1881
|
+
}
|
|
1551
1882
|
Len() {
|
|
1552
1883
|
throw new Error('reflect: call of reflect.Type.Len on chan Type');
|
|
1553
1884
|
}
|
|
@@ -1569,6 +1900,9 @@ class InterfaceType {
|
|
|
1569
1900
|
Kind() {
|
|
1570
1901
|
return Interface;
|
|
1571
1902
|
}
|
|
1903
|
+
Comparable() {
|
|
1904
|
+
return true;
|
|
1905
|
+
}
|
|
1572
1906
|
Size() {
|
|
1573
1907
|
return 16;
|
|
1574
1908
|
}
|
|
@@ -1601,12 +1935,21 @@ class InterfaceType {
|
|
|
1601
1935
|
Field(_i) {
|
|
1602
1936
|
throw new Error('reflect: Field of non-struct type');
|
|
1603
1937
|
}
|
|
1938
|
+
FieldByName(name) {
|
|
1939
|
+
return typeFieldByName(this, name);
|
|
1940
|
+
}
|
|
1941
|
+
FieldByNameFunc(match) {
|
|
1942
|
+
return typeFieldByNameFunc(this, match);
|
|
1943
|
+
}
|
|
1604
1944
|
Key() {
|
|
1605
1945
|
throw new Error('reflect: Key of non-map type');
|
|
1606
1946
|
}
|
|
1607
1947
|
Implements(_u) {
|
|
1608
1948
|
return false;
|
|
1609
1949
|
}
|
|
1950
|
+
AssignableTo(u) {
|
|
1951
|
+
return typeAssignableTo(this, u);
|
|
1952
|
+
}
|
|
1610
1953
|
common() {
|
|
1611
1954
|
return new rtype(this.Kind());
|
|
1612
1955
|
}
|
|
@@ -1620,7 +1963,10 @@ class InterfaceType {
|
|
|
1620
1963
|
throw new Error('reflect: call of reflect.Type.OverflowFloat on interface Type');
|
|
1621
1964
|
}
|
|
1622
1965
|
NumMethod() {
|
|
1623
|
-
return
|
|
1966
|
+
return typeMethods(this).length;
|
|
1967
|
+
}
|
|
1968
|
+
MethodByName(name) {
|
|
1969
|
+
return typeMethodByName(this, name);
|
|
1624
1970
|
}
|
|
1625
1971
|
Len() {
|
|
1626
1972
|
throw new Error('reflect: call of reflect.Type.Len on interface Type');
|
|
@@ -1835,7 +2181,7 @@ function getTypeOf(value) {
|
|
|
1835
2181
|
}
|
|
1836
2182
|
// Exported functions as required by godoc.txt
|
|
1837
2183
|
export function TypeOf(i) {
|
|
1838
|
-
return getTypeOf(i);
|
|
2184
|
+
return internType(getTypeOf(i));
|
|
1839
2185
|
}
|
|
1840
2186
|
export function ValueOf(i) {
|
|
1841
2187
|
return new Value(i, getTypeOf(i));
|
|
@@ -1848,64 +2194,70 @@ export function TypeAssert(typeArgs, v) {
|
|
|
1848
2194
|
return $.typeAssertTuple(v.Interface(), descriptor.type);
|
|
1849
2195
|
}
|
|
1850
2196
|
export function ArrayOf(length, elem) {
|
|
1851
|
-
return new ArrayType(elem, length);
|
|
2197
|
+
return internType(new ArrayType(elem, length));
|
|
1852
2198
|
}
|
|
1853
2199
|
export function SliceOf(t) {
|
|
1854
|
-
return new SliceType(t);
|
|
2200
|
+
return internType(new SliceType(t));
|
|
1855
2201
|
}
|
|
1856
2202
|
export function PointerTo(t) {
|
|
1857
2203
|
if (t === null)
|
|
1858
2204
|
return null;
|
|
1859
|
-
return new PointerType(t);
|
|
2205
|
+
return internType(new PointerType(t));
|
|
1860
2206
|
}
|
|
1861
2207
|
export function PtrTo(t) {
|
|
1862
2208
|
return PointerTo(t); // PtrTo is an alias for PointerTo
|
|
1863
2209
|
}
|
|
1864
2210
|
export function MapOf(key, elem) {
|
|
1865
|
-
return new MapType(key, elem);
|
|
2211
|
+
return internType(new MapType(key, elem));
|
|
1866
2212
|
}
|
|
1867
2213
|
export function ChanOf(dir, t) {
|
|
1868
|
-
return new ChannelType(t, dir);
|
|
2214
|
+
return internType(new ChannelType(t, dir));
|
|
1869
2215
|
}
|
|
1870
2216
|
export function TypeFor(typeArgs) {
|
|
1871
2217
|
const descriptor = typeArgs?.T;
|
|
1872
2218
|
if (descriptor?.type) {
|
|
1873
|
-
return typeFromTypeInfo(descriptor.type);
|
|
2219
|
+
return internType(typeFromTypeInfo(descriptor.type));
|
|
1874
2220
|
}
|
|
1875
2221
|
if (descriptor?.methods) {
|
|
1876
2222
|
const methods = Object.keys(descriptor.methods);
|
|
1877
2223
|
if (methods.length !== 0) {
|
|
1878
|
-
return new InterfaceType(`interface { ${methods.map((method) => method + '()').join('; ')} }`);
|
|
2224
|
+
return internType(new InterfaceType(`interface { ${methods.map((method) => method + '()').join('; ')} }`));
|
|
1879
2225
|
}
|
|
1880
2226
|
}
|
|
1881
2227
|
if (descriptor?.zero) {
|
|
1882
|
-
return getTypeOf(descriptor.zero());
|
|
2228
|
+
return internType(getTypeOf(descriptor.zero()));
|
|
1883
2229
|
}
|
|
1884
|
-
return new InterfaceType('interface{}');
|
|
2230
|
+
return internType(new InterfaceType('interface{}'));
|
|
1885
2231
|
}
|
|
1886
2232
|
function typeFromTypeInfo(info) {
|
|
1887
2233
|
if (typeof info === 'string') {
|
|
1888
2234
|
const registered = builtinGetTypeByName(info);
|
|
1889
2235
|
if (registered) {
|
|
1890
|
-
return typeFromTypeInfo(registered);
|
|
2236
|
+
return internType(typeFromTypeInfo(registered));
|
|
1891
2237
|
}
|
|
1892
|
-
return StructType.createTypeFromFieldInfo(info);
|
|
2238
|
+
return internType(StructType.createTypeFromFieldInfo(info));
|
|
1893
2239
|
}
|
|
1894
2240
|
switch (info.kind) {
|
|
1895
2241
|
case $.TypeKind.Array:
|
|
1896
|
-
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));
|
|
1897
2245
|
case $.TypeKind.Channel:
|
|
1898
|
-
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)));
|
|
1899
2247
|
case $.TypeKind.Function:
|
|
1900
|
-
return functionTypeFromInfo(info);
|
|
2248
|
+
return internType(functionTypeFromInfo(info));
|
|
1901
2249
|
case $.TypeKind.Interface:
|
|
1902
|
-
return interfaceTypeFromInfo(info);
|
|
2250
|
+
return internType(interfaceTypeFromInfo(info));
|
|
1903
2251
|
case $.TypeKind.Map:
|
|
1904
|
-
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));
|
|
1905
2257
|
case $.TypeKind.Pointer:
|
|
1906
|
-
return new PointerType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' }));
|
|
2258
|
+
return internType(new PointerType(typeFromTypeInfo(info.elemType ?? { kind: $.TypeKind.Basic, name: 'unknown' })));
|
|
1907
2259
|
default:
|
|
1908
|
-
return StructType.createTypeFromFieldInfo(info);
|
|
2260
|
+
return internType(StructType.createTypeFromFieldInfo(info));
|
|
1909
2261
|
}
|
|
1910
2262
|
}
|
|
1911
2263
|
function functionTypeFromInfo(info) {
|