goscript 0.1.4 → 0.2.1
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 +5 -2
- package/cmd/go_js_wasm_exec/main.go +201 -0
- package/cmd/go_js_wasm_exec/main_test.go +83 -0
- package/cmd/goscript/{cmd_compile.go → cmd-compile.go} +7 -0
- package/cmd/goscript/cmd-test.go +14 -0
- package/cmd/goscript/cmd-test_test.go +1 -1
- package/cmd/goscript-wasm/main.go +38 -6
- package/compiler/compile-request.go +12 -9
- package/compiler/compliance_test.go +0 -1
- package/compiler/config.go +2 -0
- package/compiler/diagnostic.go +104 -12
- package/compiler/diagnostic_test.go +106 -0
- package/compiler/gotest/request.go +28 -0
- package/compiler/gotest/runner.go +354 -44
- package/compiler/gotest/runner_test.go +293 -1
- package/compiler/gotest/testdata/browserapi/browserapi_test.go +20 -0
- package/compiler/gotest/testdata/browserapi/go.mod +3 -0
- package/compiler/index.test.ts +23 -0
- package/compiler/lowered-program.go +33 -24
- package/compiler/lowering.go +746 -194
- package/compiler/lowering_bench_test.go +42 -27
- package/compiler/lowering_internal_test.go +18 -0
- package/compiler/override-facts.go +15 -0
- package/compiler/override-parity-verifier.go +450 -0
- package/compiler/override-parity.go +122 -0
- package/compiler/override-registry_test.go +559 -0
- package/compiler/protobuf-ts-binding.go +567 -0
- package/compiler/protobuf-ts-binding_test.go +402 -0
- package/compiler/runtime-contract.go +4 -0
- package/compiler/runtime-contract_test.go +2 -0
- package/compiler/semantic-model-types.go +9 -4
- package/compiler/semantic-model.go +282 -70
- package/compiler/semantic-model_test.go +82 -1
- package/compiler/service.go +21 -1
- package/compiler/skeleton_test.go +118 -10
- package/compiler/typescript-emitter.go +128 -13
- package/compiler/wasm/compile_test.go +37 -4
- package/compiler/{wasm_api.go → wasm-api.go} +57 -7
- package/dist/gs/builtin/hostio.js +5 -0
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/slice.d.ts +13 -2
- package/dist/gs/builtin/slice.js +187 -6
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.d.ts +13 -5
- package/dist/gs/builtin/type.js +153 -60
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +11 -0
- package/dist/gs/builtin/varRef.js +57 -2
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/buffer.gs.js +1 -1
- package/dist/gs/bytes/buffer.gs.js.map +1 -1
- package/dist/gs/bytes/reader.gs.js +1 -1
- package/dist/gs/bytes/reader.gs.js.map +1 -1
- package/dist/gs/compress/zlib/index.d.ts +10 -3
- package/dist/gs/compress/zlib/index.js +50 -16
- package/dist/gs/compress/zlib/index.js.map +1 -1
- package/dist/gs/encoding/json/index.d.ts +114 -0
- package/dist/gs/encoding/json/index.js +544 -36
- package/dist/gs/encoding/json/index.js.map +1 -1
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +101 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +589 -0
- 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 +1 -0
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +17 -11
- package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -1
- package/dist/gs/github.com/pkg/errors/errors.js +54 -30
- package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
- package/dist/gs/go/scanner/index.d.ts +2 -0
- package/dist/gs/go/scanner/index.js +29 -5
- package/dist/gs/go/scanner/index.js.map +1 -1
- package/dist/gs/go/token/index.js +22 -6
- package/dist/gs/go/token/index.js.map +1 -1
- package/dist/gs/hash/index.d.ts +6 -0
- package/dist/gs/hash/index.js +20 -0
- package/dist/gs/hash/index.js.map +1 -1
- package/dist/gs/internal/byteorder/index.js +2 -2
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/internal/goarch/index.d.ts +43 -3
- package/dist/gs/internal/goarch/index.js +42 -10
- package/dist/gs/internal/goarch/index.js.map +1 -1
- package/dist/gs/io/fs/fs.js +26 -14
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/io/fs/readdir.js +4 -2
- package/dist/gs/io/fs/readdir.js.map +1 -1
- package/dist/gs/io/fs/sub.js +8 -1
- package/dist/gs/io/fs/sub.js.map +1 -1
- package/dist/gs/io/io.d.ts +2 -0
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/math/bits/index.d.ts +5 -0
- package/dist/gs/math/bits/index.js +16 -4
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/mime/index.d.ts +16 -0
- package/dist/gs/mime/index.js +315 -6
- package/dist/gs/mime/index.js.map +1 -1
- package/dist/gs/net/http/httptest/index.d.ts +12 -0
- package/dist/gs/net/http/httptest/index.js +85 -6
- package/dist/gs/net/http/httptest/index.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +300 -5
- package/dist/gs/net/http/index.js +1598 -58
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/os/dir_unix.gs.js +1 -1
- package/dist/gs/os/dir_unix.gs.js.map +1 -1
- package/dist/gs/os/error.gs.js +1 -1
- package/dist/gs/os/error.gs.js.map +1 -1
- package/dist/gs/os/exec.gs.d.ts +1 -0
- package/dist/gs/os/exec.gs.js +4 -8
- package/dist/gs/os/exec.gs.js.map +1 -1
- package/dist/gs/os/exec_posix.gs.js +1 -1
- package/dist/gs/os/exec_posix.gs.js.map +1 -1
- package/dist/gs/os/index.d.ts +1 -1
- package/dist/gs/os/index.js +1 -1
- package/dist/gs/os/index.js.map +1 -1
- package/dist/gs/os/proc.gs.d.ts +4 -0
- package/dist/gs/os/proc.gs.js +12 -6
- package/dist/gs/os/proc.gs.js.map +1 -1
- package/dist/gs/os/root_js.gs.js +1 -1
- package/dist/gs/os/root_js.gs.js.map +1 -1
- package/dist/gs/os/types.gs.js +1 -1
- package/dist/gs/os/types.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.js +1 -1
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.js +1 -1
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/dist/gs/path/path.js +11 -7
- package/dist/gs/path/path.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +5 -4
- package/dist/gs/reflect/index.js +4 -3
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/map.js +15 -0
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +25 -6
- package/dist/gs/reflect/type.js +1475 -228
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.d.ts +14 -6
- package/dist/gs/reflect/types.js +35 -1
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/value.d.ts +1 -0
- package/dist/gs/reflect/value.js +83 -41
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/reflect/visiblefields.js +4 -140
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/runtime/pprof/index.d.ts +8 -2
- package/dist/gs/runtime/pprof/index.js +50 -30
- package/dist/gs/runtime/pprof/index.js.map +1 -1
- package/dist/gs/runtime/runtime.js +5 -4
- package/dist/gs/runtime/runtime.js.map +1 -1
- package/dist/gs/runtime/trace/index.js +5 -19
- package/dist/gs/runtime/trace/index.js.map +1 -1
- package/dist/gs/strconv/atoi.gs.js +1 -1
- package/dist/gs/strconv/atoi.gs.js.map +1 -1
- package/dist/gs/strconv/complex.gs.d.ts +3 -0
- package/dist/gs/strconv/complex.gs.js +148 -0
- package/dist/gs/strconv/complex.gs.js.map +1 -0
- package/dist/gs/strconv/index.d.ts +1 -0
- package/dist/gs/strconv/index.js +1 -0
- package/dist/gs/strconv/index.js.map +1 -1
- package/dist/gs/strings/builder.js +1 -1
- package/dist/gs/strings/reader.js +9 -5
- package/dist/gs/strings/reader.js.map +1 -1
- package/dist/gs/strings/replace.js +15 -7
- package/dist/gs/strings/replace.js.map +1 -1
- package/dist/gs/strings/strings.d.ts +5 -0
- package/dist/gs/strings/strings.js +57 -5
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/atomic/doc_64.gs.js +7 -6
- package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -1
- package/dist/gs/sync/atomic/type.gs.js +9 -9
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/atomic/value.gs.js +2 -2
- package/dist/gs/sync/atomic/value.gs.js.map +1 -1
- package/dist/gs/syscall/env.js +22 -14
- package/dist/gs/syscall/env.js.map +1 -1
- package/dist/gs/testing/testing.js +55 -13
- package/dist/gs/testing/testing.js.map +1 -1
- package/dist/gs/time/time.d.ts +24 -1
- package/dist/gs/time/time.js +43 -3
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unique/index.js +7 -1
- package/dist/gs/unique/index.js.map +1 -1
- package/go.mod +3 -3
- package/go.sum +16 -0
- package/gs/builtin/hostio.test.ts +16 -0
- package/gs/builtin/hostio.ts +7 -0
- package/gs/builtin/runtime-contract.test.ts +246 -21
- package/gs/builtin/slice.ts +269 -24
- package/gs/builtin/type.ts +226 -59
- package/gs/builtin/varRef.ts +85 -2
- package/gs/bytes/buffer.gs.ts +1 -1
- package/gs/bytes/reader.gs.ts +1 -1
- package/gs/compress/zlib/index.test.ts +62 -1
- package/gs/compress/zlib/index.ts +53 -16
- package/gs/compress/zlib/parity.json +51 -0
- package/gs/encoding/json/index.test.ts +360 -6
- package/gs/encoding/json/index.ts +679 -38
- package/gs/encoding/json/parity.json +81 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +373 -3
- package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +893 -1
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +18 -0
- package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +17 -11
- package/gs/github.com/pkg/errors/errors.ts +54 -30
- package/gs/go/scanner/index.test.ts +39 -56
- package/gs/go/scanner/index.ts +33 -5
- package/gs/go/scanner/parity.json +27 -0
- package/gs/go/token/index.ts +22 -6
- package/gs/hash/index.test.ts +20 -33
- package/gs/hash/index.ts +28 -0
- package/gs/hash/parity.json +21 -0
- package/gs/internal/byteorder/index.test.ts +2 -2
- package/gs/internal/byteorder/index.ts +2 -2
- package/gs/internal/goarch/index.test.ts +32 -0
- package/gs/internal/goarch/index.ts +45 -13
- package/gs/internal/goarch/parity.json +144 -0
- package/gs/io/fs/fs.ts +26 -14
- package/gs/io/fs/readdir.ts +4 -4
- package/gs/io/fs/sub.ts +8 -1
- package/gs/io/io.ts +1 -0
- package/gs/io/parity.json +162 -0
- package/gs/math/bits/index.test.ts +14 -1
- package/gs/math/bits/index.ts +23 -4
- package/gs/math/bits/parity.json +156 -0
- package/gs/mime/index.test.ts +90 -0
- package/gs/mime/index.ts +369 -6
- package/gs/mime/parity.json +36 -0
- package/gs/net/http/httptest/index.test.ts +98 -2
- package/gs/net/http/httptest/index.ts +101 -6
- package/gs/net/http/httptest/parity.json +15 -0
- package/gs/net/http/index.test.ts +781 -12
- package/gs/net/http/index.ts +1860 -139
- package/gs/net/http/meta.json +16 -1
- package/gs/net/http/parity.json +193 -0
- package/gs/os/dir_unix.gs.ts +1 -1
- package/gs/os/error.gs.ts +1 -1
- package/gs/os/exec.gs.ts +4 -8
- package/gs/os/exec_posix.gs.ts +1 -1
- package/gs/os/index.test.ts +9 -0
- package/gs/os/index.ts +1 -0
- package/gs/os/parity.json +9 -0
- package/gs/os/proc.gs.ts +18 -5
- package/gs/os/proc.test.ts +26 -0
- package/gs/os/root_js.gs.ts +1 -1
- package/gs/os/types.gs.ts +1 -1
- package/gs/os/types_js.gs.ts +1 -1
- package/gs/os/types_unix.gs.ts +1 -1
- package/gs/path/path.ts +11 -7
- package/gs/reflect/field.test.ts +37 -15
- package/gs/reflect/function-types.test.ts +518 -22
- package/gs/reflect/index.ts +8 -6
- package/gs/reflect/map.ts +20 -0
- package/gs/reflect/meta.json +6 -4
- package/gs/reflect/parity.json +234 -0
- package/gs/reflect/sliceat.test.ts +156 -0
- package/gs/reflect/structof.test.ts +401 -0
- package/gs/reflect/type.ts +1961 -317
- package/gs/reflect/typefor.test.ts +530 -10
- package/gs/reflect/types.ts +43 -18
- package/gs/reflect/value.ts +105 -45
- package/gs/reflect/visiblefields.ts +5 -168
- package/gs/runtime/parity.json +24 -0
- package/gs/runtime/pprof/index.test.ts +29 -7
- package/gs/runtime/pprof/index.ts +56 -30
- package/gs/runtime/pprof/parity.json +27 -0
- package/gs/runtime/runtime.test.ts +3 -1
- package/gs/runtime/runtime.ts +4 -3
- package/gs/runtime/trace/index.test.ts +5 -3
- package/gs/runtime/trace/index.ts +8 -20
- package/gs/runtime/trace/parity.json +36 -0
- package/gs/strconv/atoi.gs.ts +1 -1
- package/gs/strconv/complex.gs.ts +174 -0
- package/gs/strconv/complex.test.ts +65 -0
- package/gs/strconv/index.ts +1 -0
- package/gs/strconv/parity.json +120 -0
- package/gs/strings/builder.ts +1 -1
- package/gs/strings/parity.json +186 -0
- package/gs/strings/reader.ts +9 -5
- package/gs/strings/replace.ts +15 -7
- package/gs/strings/strings.test.ts +22 -2
- package/gs/strings/strings.ts +64 -6
- package/gs/sync/atomic/doc_64.gs.ts +6 -7
- package/gs/sync/atomic/doc_64.test.ts +43 -0
- package/gs/sync/atomic/type.gs.ts +9 -9
- package/gs/sync/atomic/value.gs.ts +2 -2
- package/gs/syscall/env.ts +29 -14
- package/gs/testing/testing.test.ts +67 -0
- package/gs/testing/testing.ts +87 -19
- package/gs/time/parity.json +225 -0
- package/gs/time/time.test.ts +20 -2
- package/gs/time/time.ts +49 -7
- package/gs/unique/index.ts +7 -1
- package/package.json +4 -2
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +0 -217
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +0 -926
- package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +0 -1
- package/gs/github.com/aperturerobotics/starpc/srpc/index.test.ts +0 -38
- package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +0 -1361
- package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +0 -46
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
2
|
import {
|
|
3
|
+
interfaceValue,
|
|
4
|
+
makeChannel,
|
|
3
5
|
makeMap,
|
|
4
6
|
mapGet,
|
|
5
7
|
mapSet,
|
|
8
|
+
markAsStructValue,
|
|
6
9
|
namedValueInterfaceValue,
|
|
7
10
|
TypeKind,
|
|
8
11
|
registerInterfaceType,
|
|
@@ -10,7 +13,19 @@ import {
|
|
|
10
13
|
varRef,
|
|
11
14
|
} from '../builtin/index.js'
|
|
12
15
|
import { StructField } from './types.js'
|
|
13
|
-
import {
|
|
16
|
+
import { SelectCase, SelectRecv } from './types.js'
|
|
17
|
+
import {
|
|
18
|
+
Chan,
|
|
19
|
+
Int,
|
|
20
|
+
Ptr,
|
|
21
|
+
Struct,
|
|
22
|
+
StructOf,
|
|
23
|
+
TypeFor,
|
|
24
|
+
TypeOf,
|
|
25
|
+
Uint64,
|
|
26
|
+
ValueOf,
|
|
27
|
+
} from './type.js'
|
|
28
|
+
import { Indirect, New, Select, Zero } from './value.js'
|
|
14
29
|
|
|
15
30
|
describe('TypeFor', () => {
|
|
16
31
|
it('exposes StructField PkgPath and exported semantics', () => {
|
|
@@ -50,6 +65,101 @@ describe('TypeFor', () => {
|
|
|
50
65
|
expect(namedIntType.Kind()).toBe(Int)
|
|
51
66
|
})
|
|
52
67
|
|
|
68
|
+
it('preserves generic method signatures for named basic types', () => {
|
|
69
|
+
const stringResult = { kind: TypeKind.Basic, name: 'string' } as const
|
|
70
|
+
const namedIntDescriptor = {
|
|
71
|
+
kind: TypeKind.Basic,
|
|
72
|
+
name: 'int',
|
|
73
|
+
typeName: 'main.MyInt',
|
|
74
|
+
} as const
|
|
75
|
+
const methodSignatures = [
|
|
76
|
+
{
|
|
77
|
+
name: 'String',
|
|
78
|
+
args: [],
|
|
79
|
+
returns: [{ type: stringResult }],
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
const preexisting = TypeFor({
|
|
83
|
+
T: {
|
|
84
|
+
type: namedIntDescriptor,
|
|
85
|
+
zero: () => 0,
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const namedIntType = TypeFor({
|
|
90
|
+
T: {
|
|
91
|
+
type: namedIntDescriptor,
|
|
92
|
+
zero: () => 0,
|
|
93
|
+
methods: { String: (receiver: number) => String(receiver) },
|
|
94
|
+
methodSignatures,
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
const stringerType = TypeFor({
|
|
98
|
+
T: {
|
|
99
|
+
type: {
|
|
100
|
+
kind: TypeKind.Interface,
|
|
101
|
+
methods: methodSignatures,
|
|
102
|
+
},
|
|
103
|
+
zero: () => null,
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
expect(namedIntType).toBe(preexisting)
|
|
108
|
+
expect(namedIntType.NumMethod()).toBe(1)
|
|
109
|
+
const [method, ok] = namedIntType.MethodByName('String')
|
|
110
|
+
expect(ok).toBe(true)
|
|
111
|
+
expect(method.Type.NumIn()).toBe(1)
|
|
112
|
+
expect(method.Type.NumOut()).toBe(1)
|
|
113
|
+
expect(method.Type.Out(0).String()).toBe('string')
|
|
114
|
+
expect(namedIntType.Implements(stringerType)).toBe(true)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('preserves generic method signatures for pointers to named basic types', () => {
|
|
118
|
+
const stringResult = { kind: TypeKind.Basic, name: 'string' } as const
|
|
119
|
+
const methodSignatures = [
|
|
120
|
+
{
|
|
121
|
+
name: 'String',
|
|
122
|
+
args: [],
|
|
123
|
+
returns: [{ type: stringResult }],
|
|
124
|
+
},
|
|
125
|
+
]
|
|
126
|
+
const pointerType = TypeFor({
|
|
127
|
+
T: {
|
|
128
|
+
type: {
|
|
129
|
+
kind: TypeKind.Pointer,
|
|
130
|
+
elemType: {
|
|
131
|
+
kind: TypeKind.Basic,
|
|
132
|
+
name: 'bool',
|
|
133
|
+
typeName: 'main.MyBool',
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
zero: () => null,
|
|
137
|
+
methods: { String: () => 'true' },
|
|
138
|
+
methodSignatures,
|
|
139
|
+
},
|
|
140
|
+
})
|
|
141
|
+
const stringerType = TypeFor({
|
|
142
|
+
T: {
|
|
143
|
+
type: {
|
|
144
|
+
kind: TypeKind.Interface,
|
|
145
|
+
methods: methodSignatures,
|
|
146
|
+
},
|
|
147
|
+
zero: () => null,
|
|
148
|
+
},
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
expect(pointerType.Kind()).toBe(Ptr)
|
|
152
|
+
expect(pointerType.String()).toBe('*main.MyBool')
|
|
153
|
+
expect(pointerType.NumMethod()).toBe(1)
|
|
154
|
+
const [method, ok] = pointerType.MethodByName('String')
|
|
155
|
+
expect(ok).toBe(true)
|
|
156
|
+
expect(method.Type.NumIn()).toBe(1)
|
|
157
|
+
expect(method.Type.In(0)).toBe(pointerType)
|
|
158
|
+
expect(method.Type.NumOut()).toBe(1)
|
|
159
|
+
expect(method.Type.Out(0).String()).toBe('string')
|
|
160
|
+
expect(pointerType.Implements(stringerType)).toBe(true)
|
|
161
|
+
})
|
|
162
|
+
|
|
53
163
|
it('preserves named pointer type metadata on interface boxes', () => {
|
|
54
164
|
const target = varRef(0)
|
|
55
165
|
const boxed = namedValueInterfaceValue(
|
|
@@ -78,6 +188,22 @@ describe('TypeFor', () => {
|
|
|
78
188
|
expect(target.value).toBe(15)
|
|
79
189
|
})
|
|
80
190
|
|
|
191
|
+
it('preserves channel type metadata on interface boxes', () => {
|
|
192
|
+
const ch = makeChannel<{}>(0, {}, 'both')
|
|
193
|
+
const chanValue = ValueOf(interfaceValue(ch, '<-chan struct{}'))
|
|
194
|
+
|
|
195
|
+
expect(chanValue.Type().Kind()).toBe(Chan)
|
|
196
|
+
expect(chanValue.Type().String()).toBe('<-chan struct {}')
|
|
197
|
+
expect(chanValue.Type().Elem().Kind()).toBe(Struct)
|
|
198
|
+
|
|
199
|
+
const [chosen, recv, ok] = Select([
|
|
200
|
+
new SelectCase({ Dir: SelectRecv, Chan: chanValue }),
|
|
201
|
+
])
|
|
202
|
+
expect(chosen).toBe(0)
|
|
203
|
+
expect(ok).toBe(true)
|
|
204
|
+
expect(recv.Type().String()).toBe('struct {}')
|
|
205
|
+
})
|
|
206
|
+
|
|
81
207
|
it('formats literal interface methods from type metadata', () => {
|
|
82
208
|
const ifaceType = TypeFor({
|
|
83
209
|
T: {
|
|
@@ -92,6 +218,130 @@ describe('TypeFor', () => {
|
|
|
92
218
|
expect(ifaceType.String()).toBe('interface { SomeMethod() }')
|
|
93
219
|
})
|
|
94
220
|
|
|
221
|
+
it('handles recursive interface method metadata', () => {
|
|
222
|
+
const recursiveMethod = {
|
|
223
|
+
name: 'Visit',
|
|
224
|
+
args: [{ name: 'next', type: 'main.RecursiveInterface' }],
|
|
225
|
+
returns: [{ name: '_r0', type: 'main.RecursiveInterface' }],
|
|
226
|
+
}
|
|
227
|
+
registerInterfaceType('main.RecursiveInterface', null, [recursiveMethod])
|
|
228
|
+
|
|
229
|
+
class RecursiveImpl {
|
|
230
|
+
public Visit(next: unknown): unknown {
|
|
231
|
+
return next
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const typeInfo = registerStructType(
|
|
236
|
+
'main.RecursiveImpl',
|
|
237
|
+
new RecursiveImpl(),
|
|
238
|
+
[recursiveMethod],
|
|
239
|
+
RecursiveImpl,
|
|
240
|
+
[],
|
|
241
|
+
)
|
|
242
|
+
;(RecursiveImpl as any).__typeInfo = typeInfo
|
|
243
|
+
|
|
244
|
+
const ifaceType = TypeFor({
|
|
245
|
+
T: { type: 'main.RecursiveInterface', zero: () => null },
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
expect(ifaceType.String()).toBe(
|
|
249
|
+
'interface { Visit(main.RecursiveInterface) main.RecursiveInterface }',
|
|
250
|
+
)
|
|
251
|
+
expect(ifaceType.AssignableTo(ifaceType)).toBe(true)
|
|
252
|
+
expect(TypeOf(new RecursiveImpl()).AssignableTo(ifaceType)).toBe(true)
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('handles recursive struct field metadata', () => {
|
|
256
|
+
class RecursiveNode {
|
|
257
|
+
public Next: RecursiveNode | null = null
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const typeInfo = registerStructType(
|
|
261
|
+
'main.RecursiveNode',
|
|
262
|
+
new RecursiveNode(),
|
|
263
|
+
[],
|
|
264
|
+
RecursiveNode,
|
|
265
|
+
[
|
|
266
|
+
{
|
|
267
|
+
name: 'Next',
|
|
268
|
+
key: 'Next',
|
|
269
|
+
type: {
|
|
270
|
+
kind: TypeKind.Pointer,
|
|
271
|
+
elemType: 'main.RecursiveNode',
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
)
|
|
276
|
+
Object.assign(RecursiveNode, { __typeInfo: typeInfo })
|
|
277
|
+
|
|
278
|
+
const nodeType = TypeFor({
|
|
279
|
+
T: { type: 'main.RecursiveNode', zero: () => new RecursiveNode() },
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
expect(nodeType.Kind()).toBe(Struct)
|
|
283
|
+
expect(nodeType.Field(0).Name).toBe('Next')
|
|
284
|
+
expect(nodeType.Field(0).Type.String()).toBe('*main.RecursiveNode')
|
|
285
|
+
expect(nodeType.Field(0).Type.Elem().NumField()).toBe(1)
|
|
286
|
+
expect(nodeType.Field(0).Type.Elem().Field(0).Type.String()).toBe(
|
|
287
|
+
'*main.RecursiveNode',
|
|
288
|
+
)
|
|
289
|
+
expect(TypeOf(new RecursiveNode()).Field(0).Type.String()).toBe(
|
|
290
|
+
'*main.RecursiveNode',
|
|
291
|
+
)
|
|
292
|
+
expect(TypeOf(new RecursiveNode()).Field(0).Type.Elem().NumField()).toBe(1)
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
it('keeps mutually recursive registered struct identity canonical', () => {
|
|
296
|
+
class RecursiveA {
|
|
297
|
+
public B: RecursiveB | null = null
|
|
298
|
+
}
|
|
299
|
+
class RecursiveB {
|
|
300
|
+
public A: RecursiveA | null = null
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const aInfo = registerStructType(
|
|
304
|
+
'main.RecursiveA',
|
|
305
|
+
new RecursiveA(),
|
|
306
|
+
[],
|
|
307
|
+
RecursiveA,
|
|
308
|
+
[
|
|
309
|
+
{
|
|
310
|
+
name: 'B',
|
|
311
|
+
key: 'B',
|
|
312
|
+
type: { kind: TypeKind.Pointer, elemType: 'main.RecursiveB' },
|
|
313
|
+
},
|
|
314
|
+
],
|
|
315
|
+
)
|
|
316
|
+
const bInfo = registerStructType(
|
|
317
|
+
'main.RecursiveB',
|
|
318
|
+
new RecursiveB(),
|
|
319
|
+
[],
|
|
320
|
+
RecursiveB,
|
|
321
|
+
[
|
|
322
|
+
{
|
|
323
|
+
name: 'A',
|
|
324
|
+
key: 'A',
|
|
325
|
+
type: { kind: TypeKind.Pointer, elemType: 'main.RecursiveA' },
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
)
|
|
329
|
+
Object.assign(RecursiveA, { __typeInfo: aInfo })
|
|
330
|
+
Object.assign(RecursiveB, { __typeInfo: bInfo })
|
|
331
|
+
|
|
332
|
+
const aType = TypeFor({
|
|
333
|
+
T: { type: 'main.RecursiveA', zero: () => new RecursiveA() },
|
|
334
|
+
})
|
|
335
|
+
const bType = TypeFor({
|
|
336
|
+
T: { type: 'main.RecursiveB', zero: () => new RecursiveB() },
|
|
337
|
+
})
|
|
338
|
+
const bFromA = aType.Field(0).Type.Elem()
|
|
339
|
+
|
|
340
|
+
expect(bFromA.NumField()).toBe(1)
|
|
341
|
+
expect(bFromA).toBe(bType)
|
|
342
|
+
expect(bType.Field(0).Type.Elem()).toBe(aType)
|
|
343
|
+
})
|
|
344
|
+
|
|
95
345
|
it('formats unnamed function signatures from type metadata', () => {
|
|
96
346
|
const fnType = TypeFor({
|
|
97
347
|
T: {
|
|
@@ -105,6 +355,194 @@ describe('TypeFor', () => {
|
|
|
105
355
|
})
|
|
106
356
|
|
|
107
357
|
expect(fnType.String()).toBe('func(int) string')
|
|
358
|
+
expect(fnType.NumIn()).toBe(1)
|
|
359
|
+
expect(fnType.In(0).String()).toBe('int')
|
|
360
|
+
expect(fnType.NumOut()).toBe(1)
|
|
361
|
+
expect(fnType.Out(0).String()).toBe('string')
|
|
362
|
+
expect(fnType.IsVariadic()).toBe(false)
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
it('preserves named and variadic function descriptors', () => {
|
|
366
|
+
const namedFnType = TypeFor({
|
|
367
|
+
T: {
|
|
368
|
+
type: {
|
|
369
|
+
kind: TypeKind.Function,
|
|
370
|
+
name: 'example.test.Callback',
|
|
371
|
+
params: [{ kind: TypeKind.Basic, name: 'int' }],
|
|
372
|
+
results: [{ kind: TypeKind.Basic, name: 'string' }],
|
|
373
|
+
},
|
|
374
|
+
zero: () => null,
|
|
375
|
+
},
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
expect(namedFnType.String()).toBe('example.test.Callback')
|
|
379
|
+
expect(namedFnType.PkgPath()).toBe('example.test')
|
|
380
|
+
expect(namedFnType.Name()).toBe('Callback')
|
|
381
|
+
expect(namedFnType.NumIn()).toBe(1)
|
|
382
|
+
expect(namedFnType.In(0).String()).toBe('int')
|
|
383
|
+
expect(namedFnType.NumOut()).toBe(1)
|
|
384
|
+
expect(namedFnType.Out(0).String()).toBe('string')
|
|
385
|
+
|
|
386
|
+
const variadicFnType = TypeFor({
|
|
387
|
+
T: {
|
|
388
|
+
type: {
|
|
389
|
+
kind: TypeKind.Function,
|
|
390
|
+
params: [
|
|
391
|
+
{
|
|
392
|
+
kind: TypeKind.Slice,
|
|
393
|
+
elemType: { kind: TypeKind.Basic, name: 'string' },
|
|
394
|
+
},
|
|
395
|
+
],
|
|
396
|
+
results: [{ kind: TypeKind.Basic, name: 'int' }],
|
|
397
|
+
isVariadic: true,
|
|
398
|
+
},
|
|
399
|
+
zero: () => null,
|
|
400
|
+
},
|
|
401
|
+
})
|
|
402
|
+
|
|
403
|
+
expect(variadicFnType.String()).toBe('func(...string) int')
|
|
404
|
+
expect(variadicFnType.NumIn()).toBe(1)
|
|
405
|
+
expect(variadicFnType.In(0).String()).toBe('[]string')
|
|
406
|
+
expect(variadicFnType.NumOut()).toBe(1)
|
|
407
|
+
expect(variadicFnType.Out(0).String()).toBe('int')
|
|
408
|
+
expect(variadicFnType.IsVariadic()).toBe(true)
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
it('rehydrates anonymous struct descriptors as unnamed struct types', () => {
|
|
412
|
+
const intType = TypeOf(0)
|
|
413
|
+
const descriptor = {
|
|
414
|
+
kind: TypeKind.Struct,
|
|
415
|
+
methods: [],
|
|
416
|
+
fields: [
|
|
417
|
+
{
|
|
418
|
+
name: 'X',
|
|
419
|
+
key: 'X',
|
|
420
|
+
type: { kind: TypeKind.Basic, name: 'int' },
|
|
421
|
+
tag: 'json:"x"',
|
|
422
|
+
index: [0],
|
|
423
|
+
offset: 0,
|
|
424
|
+
exported: true,
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
} as const
|
|
428
|
+
|
|
429
|
+
const typ = TypeFor({
|
|
430
|
+
T: {
|
|
431
|
+
type: descriptor,
|
|
432
|
+
zero: () => ({ X: 0 }),
|
|
433
|
+
},
|
|
434
|
+
})
|
|
435
|
+
const dynamic = StructOf([
|
|
436
|
+
new StructField({
|
|
437
|
+
Name: 'X',
|
|
438
|
+
Type: intType,
|
|
439
|
+
Tag: 'json:"x"',
|
|
440
|
+
}),
|
|
441
|
+
])
|
|
442
|
+
|
|
443
|
+
expect(typ.String()).toBe('struct { X int "json:\\"x\\"" }')
|
|
444
|
+
expect(typ.Name()).toBe('')
|
|
445
|
+
expect(typ.PkgPath()).toBe('')
|
|
446
|
+
expect(typ.NumField()).toBe(1)
|
|
447
|
+
expect(typ.Field(0).Name).toBe('X')
|
|
448
|
+
expect(typ.Field(0).Tag.Get('json')).toBe('x')
|
|
449
|
+
expect(typ.AssignableTo(dynamic)).toBe(true)
|
|
450
|
+
expect(dynamic.AssignableTo(typ)).toBe(true)
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
it('uses full anonymous struct identity in method signatures', () => {
|
|
454
|
+
const baseField = {
|
|
455
|
+
name: 'X',
|
|
456
|
+
key: 'X',
|
|
457
|
+
type: { kind: TypeKind.Basic, name: 'int' },
|
|
458
|
+
index: [0],
|
|
459
|
+
offset: 0,
|
|
460
|
+
exported: true,
|
|
461
|
+
} as const
|
|
462
|
+
const taggedParam = {
|
|
463
|
+
kind: TypeKind.Struct,
|
|
464
|
+
methods: [],
|
|
465
|
+
fields: [{ ...baseField, tag: 'json:"a"' }],
|
|
466
|
+
} as const
|
|
467
|
+
const methodSignatures = [
|
|
468
|
+
{
|
|
469
|
+
name: 'Accept',
|
|
470
|
+
args: [{ type: taggedParam }],
|
|
471
|
+
returns: [],
|
|
472
|
+
},
|
|
473
|
+
]
|
|
474
|
+
const receiverType = TypeFor({
|
|
475
|
+
T: {
|
|
476
|
+
type: { kind: TypeKind.Basic, name: 'int', typeName: 'main.Receiver' },
|
|
477
|
+
zero: () => 0,
|
|
478
|
+
methodSignatures,
|
|
479
|
+
},
|
|
480
|
+
})
|
|
481
|
+
const sameInterface = TypeFor({
|
|
482
|
+
T: {
|
|
483
|
+
type: {
|
|
484
|
+
kind: TypeKind.Interface,
|
|
485
|
+
methods: methodSignatures,
|
|
486
|
+
},
|
|
487
|
+
zero: () => null,
|
|
488
|
+
},
|
|
489
|
+
})
|
|
490
|
+
const differentTagInterface = TypeFor({
|
|
491
|
+
T: {
|
|
492
|
+
type: {
|
|
493
|
+
kind: TypeKind.Interface,
|
|
494
|
+
methods: [
|
|
495
|
+
{
|
|
496
|
+
name: 'Accept',
|
|
497
|
+
args: [
|
|
498
|
+
{
|
|
499
|
+
type: {
|
|
500
|
+
kind: TypeKind.Struct,
|
|
501
|
+
methods: [],
|
|
502
|
+
fields: [{ ...baseField, tag: 'json:"b"' }],
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
],
|
|
506
|
+
returns: [],
|
|
507
|
+
},
|
|
508
|
+
],
|
|
509
|
+
},
|
|
510
|
+
zero: () => null,
|
|
511
|
+
},
|
|
512
|
+
})
|
|
513
|
+
const differentEmbeddingInterface = TypeFor({
|
|
514
|
+
T: {
|
|
515
|
+
type: {
|
|
516
|
+
kind: TypeKind.Interface,
|
|
517
|
+
methods: [
|
|
518
|
+
{
|
|
519
|
+
name: 'Accept',
|
|
520
|
+
args: [
|
|
521
|
+
{
|
|
522
|
+
type: {
|
|
523
|
+
kind: TypeKind.Struct,
|
|
524
|
+
methods: [],
|
|
525
|
+
fields: [
|
|
526
|
+
{
|
|
527
|
+
...baseField,
|
|
528
|
+
tag: 'json:"a"',
|
|
529
|
+
anonymous: true,
|
|
530
|
+
},
|
|
531
|
+
],
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
],
|
|
535
|
+
returns: [],
|
|
536
|
+
},
|
|
537
|
+
],
|
|
538
|
+
},
|
|
539
|
+
zero: () => null,
|
|
540
|
+
},
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
expect(receiverType.Implements(sameInterface)).toBe(true)
|
|
544
|
+
expect(receiverType.Implements(differentTagInterface)).toBe(false)
|
|
545
|
+
expect(receiverType.Implements(differentEmbeddingInterface)).toBe(false)
|
|
108
546
|
})
|
|
109
547
|
|
|
110
548
|
it('resolves registered type names from descriptors', () => {
|
|
@@ -115,25 +553,39 @@ describe('TypeFor', () => {
|
|
|
115
553
|
new RegisteredStruct(),
|
|
116
554
|
[],
|
|
117
555
|
RegisteredStruct,
|
|
118
|
-
|
|
556
|
+
[],
|
|
119
557
|
)
|
|
120
558
|
registerStructType(
|
|
121
559
|
'main.RegisteredWithFields',
|
|
122
560
|
new RegisteredWithFields(),
|
|
123
561
|
[],
|
|
124
562
|
RegisteredWithFields,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
563
|
+
[
|
|
564
|
+
{
|
|
565
|
+
name: 'Name',
|
|
566
|
+
key: 'Name',
|
|
567
|
+
type: { kind: TypeKind.Basic, name: 'string' },
|
|
568
|
+
},
|
|
569
|
+
{
|
|
570
|
+
key: 'Count',
|
|
128
571
|
name: 'Total',
|
|
129
572
|
type: { kind: TypeKind.Basic, name: 'int' },
|
|
130
573
|
tag: 'json:"total"',
|
|
574
|
+
pkgPath: 'main',
|
|
575
|
+
anonymous: true,
|
|
576
|
+
index: [3],
|
|
577
|
+
offset: 24,
|
|
578
|
+
exported: false,
|
|
131
579
|
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
580
|
+
{
|
|
581
|
+
name: 'Items',
|
|
582
|
+
key: 'Items',
|
|
583
|
+
type: {
|
|
584
|
+
kind: TypeKind.Slice,
|
|
585
|
+
elemType: 'main.RegisteredStruct',
|
|
586
|
+
},
|
|
135
587
|
},
|
|
136
|
-
|
|
588
|
+
],
|
|
137
589
|
)
|
|
138
590
|
registerInterfaceType('main.RegisteredInterface', null, [
|
|
139
591
|
{ name: 'SomeMethod', args: [], returns: [] },
|
|
@@ -160,9 +612,77 @@ describe('TypeFor', () => {
|
|
|
160
612
|
expect(fieldsType.Field(0).Name).toBe('Name')
|
|
161
613
|
expect(fieldsType.Field(0).Type.String()).toBe('string')
|
|
162
614
|
expect(fieldsType.Field(1).Name).toBe('Total')
|
|
615
|
+
expect(fieldsType.Field(1).PkgPath).toBe('main')
|
|
616
|
+
expect(fieldsType.Field(1).IsExported()).toBe(false)
|
|
617
|
+
expect(fieldsType.Field(1).Anonymous).toBe(true)
|
|
618
|
+
expect(fieldsType.Field(1).Index).toEqual([3])
|
|
619
|
+
expect(fieldsType.Field(1).Offset).toBe(24)
|
|
163
620
|
expect(fieldsType.Field(1).Tag.Get('json')).toBe('total')
|
|
164
621
|
expect(fieldsType.Field(2).Type.String()).toBe('[]main.RegisteredStruct')
|
|
165
|
-
expect(fieldsType.Field(2).Type.Elem().String()).toBe(
|
|
622
|
+
expect(fieldsType.Field(2).Type.Elem().String()).toBe(
|
|
623
|
+
'main.RegisteredStruct',
|
|
624
|
+
)
|
|
625
|
+
})
|
|
626
|
+
|
|
627
|
+
it('allocates registered struct zero values through the named constructor', () => {
|
|
628
|
+
class RegisteredZero {
|
|
629
|
+
public get Name(): string {
|
|
630
|
+
return this._fields.Name.value
|
|
631
|
+
}
|
|
632
|
+
public set Name(value: string) {
|
|
633
|
+
this._fields.Name.value = value
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
public _fields: {
|
|
637
|
+
Name: ReturnType<typeof varRef<string>>
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
constructor(init?: Partial<{ Name?: string }>) {
|
|
641
|
+
this._fields = {
|
|
642
|
+
Name: varRef(init?.Name ?? ''),
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
public clone(): RegisteredZero {
|
|
647
|
+
return markAsStructValue(new RegisteredZero({ Name: this.Name }))
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const typeInfo = registerStructType(
|
|
652
|
+
'main.RegisteredZero',
|
|
653
|
+
() => new RegisteredZero(),
|
|
654
|
+
[],
|
|
655
|
+
RegisteredZero,
|
|
656
|
+
[
|
|
657
|
+
{
|
|
658
|
+
name: 'Name',
|
|
659
|
+
key: 'Name',
|
|
660
|
+
type: { kind: TypeKind.Basic, name: 'string' },
|
|
661
|
+
index: [0],
|
|
662
|
+
offset: 0,
|
|
663
|
+
exported: true,
|
|
664
|
+
},
|
|
665
|
+
],
|
|
666
|
+
)
|
|
667
|
+
;(RegisteredZero as any).__typeInfo = typeInfo
|
|
668
|
+
|
|
669
|
+
const typ = TypeOf(new RegisteredZero())
|
|
670
|
+
expect(Zero(typ).Interface()).toBeInstanceOf(RegisteredZero)
|
|
671
|
+
expect(TypeOf(Zero(typ).Interface()).String()).toBe('main.RegisteredZero')
|
|
672
|
+
|
|
673
|
+
const ptr = New(typ)
|
|
674
|
+
expect(ptr.Elem().Interface()).toBeInstanceOf(RegisteredZero)
|
|
675
|
+
ptr.Elem().FieldByName('Name').SetString('Ada')
|
|
676
|
+
expect((ptr.Elem().Interface() as RegisteredZero).Name).toBe('Ada')
|
|
677
|
+
})
|
|
678
|
+
|
|
679
|
+
it('unwraps New pointers through Indirect', () => {
|
|
680
|
+
const pointer = New(TypeOf(0))
|
|
681
|
+
const value = Indirect(pointer)
|
|
682
|
+
|
|
683
|
+
expect(value.Int()).toBe(0)
|
|
684
|
+
value.SetInt(7)
|
|
685
|
+
expect(pointer.Elem().Int()).toBe(7)
|
|
166
686
|
})
|
|
167
687
|
|
|
168
688
|
it('interns runtime type descriptors for reflect.Type map keys', () => {
|
package/gs/reflect/types.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface UnsafePointer {
|
|
|
11
11
|
|
|
12
12
|
export type Pointer = UnsafePointer | null
|
|
13
13
|
|
|
14
|
+
export type ReflectFunc = (...args: unknown[]) => unknown
|
|
15
|
+
|
|
14
16
|
// Define the possible JavaScript values that can be reflected
|
|
15
17
|
export type ReflectValue =
|
|
16
18
|
| null
|
|
@@ -20,7 +22,7 @@ export type ReflectValue =
|
|
|
20
22
|
| bigint
|
|
21
23
|
| string
|
|
22
24
|
| symbol
|
|
23
|
-
|
|
|
25
|
+
| ReflectFunc
|
|
24
26
|
| object
|
|
25
27
|
| unknown[]
|
|
26
28
|
| Map<unknown, unknown>
|
|
@@ -37,6 +39,10 @@ export type ReflectValue =
|
|
|
37
39
|
// Import Type and Kind from the main type module
|
|
38
40
|
import { Type, Kind, Value, Kind_String, ChanDir } from './type.js'
|
|
39
41
|
|
|
42
|
+
type StructFieldInit = Omit<Partial<StructField>, 'Tag'> & {
|
|
43
|
+
Tag?: StructTag | string
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
// Struct field representation
|
|
41
47
|
export class StructField {
|
|
42
48
|
public Name: string = ''
|
|
@@ -47,9 +53,13 @@ export class StructField {
|
|
|
47
53
|
public Index: number[] = []
|
|
48
54
|
public Anonymous: boolean = false
|
|
49
55
|
|
|
50
|
-
constructor(init?:
|
|
56
|
+
constructor(init?: StructFieldInit) {
|
|
51
57
|
if (init) {
|
|
52
|
-
|
|
58
|
+
const { Tag, ...rest } = init
|
|
59
|
+
Object.assign(this, rest)
|
|
60
|
+
if (Tag !== undefined) {
|
|
61
|
+
this.Tag = typeof Tag === 'string' ? new StructTag(Tag) : Tag
|
|
62
|
+
}
|
|
53
63
|
}
|
|
54
64
|
}
|
|
55
65
|
|
|
@@ -102,12 +112,17 @@ export function StructTag_Get(tag: StructTag | undefined, key: string): string {
|
|
|
102
112
|
return tag.Get(key)
|
|
103
113
|
}
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
export class Method {
|
|
116
|
+
public Name = ''
|
|
117
|
+
public Type!: Type
|
|
118
|
+
public Func!: ReflectFunc
|
|
119
|
+
public Index = 0
|
|
120
|
+
|
|
121
|
+
constructor(init?: Partial<Method>) {
|
|
122
|
+
if (init) {
|
|
123
|
+
Object.assign(this, init)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
111
126
|
}
|
|
112
127
|
|
|
113
128
|
// Channel type for reflection
|
|
@@ -139,17 +154,27 @@ export const SelectSend: SelectDir = 1
|
|
|
139
154
|
export const SelectRecv: SelectDir = 2
|
|
140
155
|
export const SelectDefault: SelectDir = 3
|
|
141
156
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
157
|
+
export class SliceHeader {
|
|
158
|
+
public Data: uintptr = 0
|
|
159
|
+
public Len = 0
|
|
160
|
+
public Cap = 0
|
|
161
|
+
|
|
162
|
+
constructor(init?: Partial<SliceHeader>) {
|
|
163
|
+
if (init) {
|
|
164
|
+
Object.assign(this, init)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
147
167
|
}
|
|
148
168
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
169
|
+
export class StringHeader {
|
|
170
|
+
public Data: uintptr = 0
|
|
171
|
+
public Len = 0
|
|
172
|
+
|
|
173
|
+
constructor(init?: Partial<StringHeader>) {
|
|
174
|
+
if (init) {
|
|
175
|
+
Object.assign(this, init)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
153
178
|
}
|
|
154
179
|
|
|
155
180
|
// Map iterator with proper typing
|