goscript 0.0.47 → 0.0.49
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/deps.go +1 -4
- package/compiler/analysis.go +224 -63
- package/compiler/analysis_test.go +112 -0
- package/compiler/compiler.go +19 -87
- package/compiler/expr-call-type-conversion.go +148 -59
- package/compiler/expr-call.go +202 -10
- package/compiler/expr.go +5 -82
- package/compiler/gs_dependencies_test.go +60 -1
- package/compiler/spec-value.go +73 -51
- package/compiler/spec.go +293 -151
- package/compiler/stmt.go +192 -81
- package/dist/gs/builtin/builtin.d.ts +1 -5
- package/dist/gs/builtin/builtin.js +1 -34
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/fmt/fmt.js +20 -4
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/io/fs/fs.d.ts +6 -12
- package/dist/gs/io/fs/fs.js +52 -67
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/os/index.d.ts +2 -1
- package/dist/gs/os/index.js +1 -1
- package/dist/gs/os/index.js.map +1 -1
- package/dist/gs/os/types_js.gs.d.ts +7 -1
- package/dist/gs/os/types_js.gs.js +16 -1
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.js +2 -2
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/dist/gs/reflect/index.d.ts +3 -3
- package/dist/gs/reflect/index.js +2 -2
- package/dist/gs/reflect/index.js.map +1 -1
- package/dist/gs/reflect/map.js +2 -2
- package/dist/gs/reflect/map.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +8 -9
- package/dist/gs/reflect/type.js +101 -103
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/reflect/types.d.ts +1 -10
- package/dist/gs/reflect/types.js +3 -26
- package/dist/gs/reflect/types.js.map +1 -1
- package/dist/gs/reflect/value.js +23 -23
- package/dist/gs/reflect/value.js.map +1 -1
- package/dist/gs/reflect/visiblefields.js +3 -3
- package/dist/gs/reflect/visiblefields.js.map +1 -1
- package/dist/gs/time/time.d.ts +11 -22
- package/dist/gs/time/time.js +29 -57
- package/dist/gs/time/time.js.map +1 -1
- package/gs/TODO.md +129 -0
- package/gs/builtin/builtin.ts +3 -41
- package/gs/builtin/slice.ts +1 -1
- package/gs/bytes/meta.json +10 -0
- package/gs/fmt/fmt.ts +18 -4
- package/gs/fmt/meta.json +5 -0
- package/gs/internal/meta.json +5 -0
- package/gs/io/fs/fs.ts +58 -73
- package/gs/io/meta.json +9 -0
- package/gs/maps/meta.json +6 -0
- package/gs/math/meta.json +5 -0
- package/gs/os/index.ts +8 -1
- package/gs/os/meta.json +15 -0
- package/gs/os/types_js.gs.ts +22 -1
- package/gs/os/types_unix.gs.ts +2 -2
- package/gs/path/meta.json +6 -0
- package/gs/reflect/function-types.test.ts +10 -10
- package/gs/reflect/index.ts +6 -6
- package/gs/reflect/map.ts +2 -2
- package/gs/reflect/meta.json +5 -0
- package/gs/reflect/type.ts +108 -103
- package/gs/reflect/types.ts +2 -28
- package/gs/reflect/value.ts +23 -23
- package/gs/reflect/visiblefields.ts +3 -3
- package/gs/strconv/meta.json +5 -0
- package/gs/strings/meta.json +9 -0
- package/gs/sync/meta.json +19 -0
- package/gs/time/time.ts +32 -65
- package/package.json +1 -1
- package/dist/gs/builtin/io.d.ts +0 -16
- package/dist/gs/builtin/io.js +0 -15
- package/dist/gs/builtin/io.js.map +0 -1
- package/dist/gs/internal/testlog/index.d.ts +0 -1
- package/dist/gs/internal/testlog/index.js +0 -5
- package/dist/gs/internal/testlog/index.js.map +0 -1
- package/dist/gs/maps/iter.gs.d.ts +0 -7
- package/dist/gs/maps/iter.gs.js +0 -65
- package/dist/gs/maps/iter.gs.js.map +0 -1
- package/dist/gs/maps/maps.gs.d.ts +0 -7
- package/dist/gs/maps/maps.gs.js +0 -79
- package/dist/gs/maps/maps.gs.js.map +0 -1
- package/dist/gs/reflect/abi.d.ts +0 -59
- package/dist/gs/reflect/abi.gs.d.ts +0 -59
- package/dist/gs/reflect/abi.gs.js +0 -79
- package/dist/gs/reflect/abi.gs.js.map +0 -1
- package/dist/gs/reflect/abi.js +0 -79
- package/dist/gs/reflect/abi.js.map +0 -1
- package/dist/gs/reflect/badlinkname.d.ts +0 -52
- package/dist/gs/reflect/badlinkname.gs.d.ts +0 -52
- package/dist/gs/reflect/badlinkname.gs.js +0 -72
- package/dist/gs/reflect/badlinkname.gs.js.map +0 -1
- package/dist/gs/reflect/badlinkname.js +0 -72
- package/dist/gs/reflect/badlinkname.js.map +0 -1
- package/dist/gs/reflect/deepequal.gs.d.ts +0 -25
- package/dist/gs/reflect/deepequal.gs.js +0 -308
- package/dist/gs/reflect/deepequal.gs.js.map +0 -1
- package/dist/gs/reflect/float32reg_generic.gs.d.ts +0 -2
- package/dist/gs/reflect/float32reg_generic.gs.js +0 -10
- package/dist/gs/reflect/float32reg_generic.gs.js.map +0 -1
- package/dist/gs/reflect/index.gs.d.ts +0 -1
- package/dist/gs/reflect/index.gs.js +0 -3
- package/dist/gs/reflect/index.gs.js.map +0 -1
- package/dist/gs/reflect/iter.gs.d.ts +0 -3
- package/dist/gs/reflect/iter.gs.js +0 -24
- package/dist/gs/reflect/iter.gs.js.map +0 -1
- package/dist/gs/reflect/makefunc.gs.d.ts +0 -34
- package/dist/gs/reflect/makefunc.gs.js +0 -288
- package/dist/gs/reflect/makefunc.gs.js.map +0 -1
- package/dist/gs/reflect/map_swiss.gs.d.ts +0 -14
- package/dist/gs/reflect/map_swiss.gs.js +0 -70
- package/dist/gs/reflect/map_swiss.gs.js.map +0 -1
- package/dist/gs/reflect/reflect.gs.d.ts +0 -132
- package/dist/gs/reflect/reflect.gs.js +0 -437
- package/dist/gs/reflect/reflect.gs.js.map +0 -1
- package/dist/gs/reflect/swapper.gs.d.ts +0 -1
- package/dist/gs/reflect/swapper.gs.js +0 -32
- package/dist/gs/reflect/swapper.gs.js.map +0 -1
- package/dist/gs/reflect/type.gs.d.ts +0 -4
- package/dist/gs/reflect/type.gs.js +0 -21
- package/dist/gs/reflect/type.gs.js.map +0 -1
- package/dist/gs/reflect/value.gs.d.ts +0 -4
- package/dist/gs/reflect/value.gs.js +0 -12
- package/dist/gs/reflect/value.gs.js.map +0 -1
- package/dist/gs/reflect/visiblefields.gs.d.ts +0 -3
- package/dist/gs/reflect/visiblefields.gs.js +0 -123
- package/dist/gs/reflect/visiblefields.gs.js.map +0 -1
- package/dist/gs/stringslite/index.d.ts +0 -1
- package/dist/gs/stringslite/index.js +0 -2
- package/dist/gs/stringslite/index.js.map +0 -1
- package/dist/gs/stringslite/strings.d.ts +0 -11
- package/dist/gs/stringslite/strings.js +0 -67
- package/dist/gs/stringslite/strings.js.map +0 -1
- package/gs/bytes/metadata.go +0 -12
- package/gs/fmt/metadata.go +0 -7
- package/gs/internal/metadata.go +0 -7
- package/gs/io/io.go +0 -75
- package/gs/io/metadata.go +0 -11
- package/gs/maps/metadata.go +0 -8
- package/gs/math/metadata.go +0 -7
- package/gs/os/metadata.go +0 -17
- package/gs/path/metadata.go +0 -8
- package/gs/reflect/metadata.go +0 -7
- package/gs/strconv/metadata.go +0 -7
- package/gs/strings/metadata.go +0 -11
- package/gs/sync/metadata.go +0 -7
- package/gs/sync/sync.go +0 -64
package/gs/reflect/type.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReflectValue,
|
|
1
|
+
import { ReflectValue, StructField } from './types.js'
|
|
2
2
|
import { MapIter } from './map.js'
|
|
3
3
|
|
|
4
4
|
// rtype is the common implementation of most values
|
|
@@ -10,17 +10,16 @@ export class rtype {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
String(): string {
|
|
13
|
-
return this.kind
|
|
13
|
+
return Kind_String(this.kind)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
Pointers(): boolean {
|
|
17
|
-
|
|
18
|
-
const k = this.kind.valueOf()
|
|
17
|
+
const k = this.kind
|
|
19
18
|
return (
|
|
20
|
-
k === Ptr
|
|
21
|
-
k === Map
|
|
22
|
-
k === Slice
|
|
23
|
-
k === Interface
|
|
19
|
+
k === Ptr ||
|
|
20
|
+
k === Map ||
|
|
21
|
+
k === Slice ||
|
|
22
|
+
k === Interface
|
|
24
23
|
)
|
|
25
24
|
}
|
|
26
25
|
}
|
|
@@ -42,15 +41,14 @@ export class flag {
|
|
|
42
41
|
if (typeof _value === 'number') {
|
|
43
42
|
this._value = _value
|
|
44
43
|
} else {
|
|
45
|
-
this._value = _value
|
|
44
|
+
this._value = _value
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
valueOf(): number {
|
|
50
|
-
return typeof this._value === 'number' ? this._value : this._value
|
|
49
|
+
return typeof this._value === 'number' ? this._value : this._value
|
|
51
50
|
}
|
|
52
51
|
|
|
53
|
-
// Support arithmetic operations
|
|
54
52
|
static from(value: number | Kind): flag {
|
|
55
53
|
return new flag(value)
|
|
56
54
|
}
|
|
@@ -80,86 +78,93 @@ export class bitVector {
|
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
// Kind represents the specific kind of type that a Type represents.
|
|
83
|
-
export
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
81
|
+
export type Kind = number
|
|
82
|
+
|
|
83
|
+
// Kind_String returns the string representation of a Kind (wrapper function naming)
|
|
84
|
+
export function Kind_String(k: Kind): string {
|
|
85
|
+
const kindNames = [
|
|
86
|
+
'invalid',
|
|
87
|
+
'bool',
|
|
88
|
+
'int',
|
|
89
|
+
'int8',
|
|
90
|
+
'int16',
|
|
91
|
+
'int32',
|
|
92
|
+
'int64',
|
|
93
|
+
'uint',
|
|
94
|
+
'uint8',
|
|
95
|
+
'uint16',
|
|
96
|
+
'uint32',
|
|
97
|
+
'uint64',
|
|
98
|
+
'uintptr',
|
|
99
|
+
'float32',
|
|
100
|
+
'float64',
|
|
101
|
+
'complex64',
|
|
102
|
+
'complex128',
|
|
103
|
+
'array',
|
|
104
|
+
'chan',
|
|
105
|
+
'func',
|
|
106
|
+
'interface',
|
|
107
|
+
'map',
|
|
108
|
+
'ptr',
|
|
109
|
+
'slice',
|
|
110
|
+
'string',
|
|
111
|
+
'struct',
|
|
112
|
+
'unsafe.Pointer',
|
|
113
|
+
]
|
|
114
|
+
if (k >= 0 && k < kindNames.length) {
|
|
115
|
+
return kindNames[k]
|
|
116
|
+
}
|
|
117
|
+
return 'invalid'
|
|
118
|
+
}
|
|
97
119
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
'complex64',
|
|
116
|
-
'complex128',
|
|
117
|
-
'array',
|
|
118
|
-
'chan',
|
|
119
|
-
'func',
|
|
120
|
-
'interface',
|
|
121
|
-
'map',
|
|
122
|
-
'ptr',
|
|
123
|
-
'slice',
|
|
124
|
-
'string',
|
|
125
|
-
'struct',
|
|
126
|
-
'unsafe.Pointer',
|
|
127
|
-
]
|
|
128
|
-
if (this._value >= 0 && this._value < kindNames.length) {
|
|
129
|
-
return kindNames[this._value]
|
|
130
|
-
}
|
|
131
|
-
return 'invalid'
|
|
120
|
+
// Channel direction constants and type
|
|
121
|
+
export type ChanDir = number
|
|
122
|
+
|
|
123
|
+
export const RecvDir: ChanDir = 1
|
|
124
|
+
export const SendDir: ChanDir = 2
|
|
125
|
+
export const BothDir: ChanDir = 3
|
|
126
|
+
|
|
127
|
+
export function ChanDir_String(d: ChanDir): string {
|
|
128
|
+
switch (d) {
|
|
129
|
+
case RecvDir:
|
|
130
|
+
return "RecvDir"
|
|
131
|
+
case SendDir:
|
|
132
|
+
return "SendDir"
|
|
133
|
+
case BothDir:
|
|
134
|
+
return "BothDir"
|
|
135
|
+
default:
|
|
136
|
+
return "ChanDir(" + d + ")"
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
|
|
135
140
|
// Kind constants
|
|
136
|
-
export const Invalid =
|
|
137
|
-
export const Bool =
|
|
138
|
-
export const Int =
|
|
139
|
-
export const Int8 =
|
|
140
|
-
export const Int16 =
|
|
141
|
-
export const Int32 =
|
|
142
|
-
export const Int64 =
|
|
143
|
-
export const Uint =
|
|
144
|
-
export const Uint8 =
|
|
145
|
-
export const Uint16 =
|
|
146
|
-
export const Uint32 =
|
|
147
|
-
export const Uint64 =
|
|
148
|
-
export const Uintptr =
|
|
149
|
-
export const Float32 =
|
|
150
|
-
export const Float64 =
|
|
151
|
-
export const Complex64 =
|
|
152
|
-
export const Complex128 =
|
|
153
|
-
export const Array =
|
|
154
|
-
export const Chan =
|
|
155
|
-
export const Func =
|
|
156
|
-
export const Interface =
|
|
157
|
-
export const Map =
|
|
158
|
-
export const Ptr =
|
|
159
|
-
export const Slice =
|
|
160
|
-
export const String =
|
|
161
|
-
export const Struct =
|
|
162
|
-
export const UnsafePointer =
|
|
141
|
+
export const Invalid: Kind = 0
|
|
142
|
+
export const Bool: Kind = 1
|
|
143
|
+
export const Int: Kind = 2
|
|
144
|
+
export const Int8: Kind = 3
|
|
145
|
+
export const Int16: Kind = 4
|
|
146
|
+
export const Int32: Kind = 5
|
|
147
|
+
export const Int64: Kind = 6
|
|
148
|
+
export const Uint: Kind = 7
|
|
149
|
+
export const Uint8: Kind = 8
|
|
150
|
+
export const Uint16: Kind = 9
|
|
151
|
+
export const Uint32: Kind = 10
|
|
152
|
+
export const Uint64: Kind = 11
|
|
153
|
+
export const Uintptr: Kind = 12
|
|
154
|
+
export const Float32: Kind = 13
|
|
155
|
+
export const Float64: Kind = 14
|
|
156
|
+
export const Complex64: Kind = 15
|
|
157
|
+
export const Complex128: Kind = 16
|
|
158
|
+
export const Array: Kind = 17
|
|
159
|
+
export const Chan: Kind = 18
|
|
160
|
+
export const Func: Kind = 19
|
|
161
|
+
export const Interface: Kind = 20
|
|
162
|
+
export const Map: Kind = 21
|
|
163
|
+
export const Ptr: Kind = 22
|
|
164
|
+
export const Slice: Kind = 23
|
|
165
|
+
export const String: Kind = 24
|
|
166
|
+
export const Struct: Kind = 25
|
|
167
|
+
export const UnsafePointer: Kind = 26
|
|
163
168
|
|
|
164
169
|
// Type is the representation of a Go type.
|
|
165
170
|
export interface Type {
|
|
@@ -206,7 +211,7 @@ export class Value {
|
|
|
206
211
|
}
|
|
207
212
|
throw new Error(
|
|
208
213
|
'reflect: call of reflect.Value.Int on ' +
|
|
209
|
-
this._type.Kind()
|
|
214
|
+
Kind_String(this._type.Kind()) +
|
|
210
215
|
' Value',
|
|
211
216
|
)
|
|
212
217
|
}
|
|
@@ -217,7 +222,7 @@ export class Value {
|
|
|
217
222
|
}
|
|
218
223
|
throw new Error(
|
|
219
224
|
'reflect: call of reflect.Value.Uint on ' +
|
|
220
|
-
this._type.Kind()
|
|
225
|
+
Kind_String(this._type.Kind()) +
|
|
221
226
|
' Value',
|
|
222
227
|
)
|
|
223
228
|
}
|
|
@@ -228,7 +233,7 @@ export class Value {
|
|
|
228
233
|
}
|
|
229
234
|
throw new Error(
|
|
230
235
|
'reflect: call of reflect.Value.Float on ' +
|
|
231
|
-
this._type.Kind()
|
|
236
|
+
Kind_String(this._type.Kind()) +
|
|
232
237
|
' Value',
|
|
233
238
|
)
|
|
234
239
|
}
|
|
@@ -239,7 +244,7 @@ export class Value {
|
|
|
239
244
|
}
|
|
240
245
|
throw new Error(
|
|
241
246
|
'reflect: call of reflect.Value.Bool on ' +
|
|
242
|
-
this._type.Kind()
|
|
247
|
+
Kind_String(this._type.Kind()) +
|
|
243
248
|
' Value',
|
|
244
249
|
)
|
|
245
250
|
}
|
|
@@ -249,7 +254,7 @@ export class Value {
|
|
|
249
254
|
return this._value
|
|
250
255
|
}
|
|
251
256
|
// Special case for bool values - display as <bool Value>
|
|
252
|
-
if (this._type.Kind()
|
|
257
|
+
if (this._type.Kind() === Bool) {
|
|
253
258
|
return '<bool Value>'
|
|
254
259
|
}
|
|
255
260
|
return this._type.String()
|
|
@@ -294,7 +299,7 @@ export class Value {
|
|
|
294
299
|
|
|
295
300
|
throw new Error(
|
|
296
301
|
'reflect: call of reflect.Value.Len on ' +
|
|
297
|
-
this._type.Kind()
|
|
302
|
+
Kind_String(this._type.Kind()) +
|
|
298
303
|
' Value',
|
|
299
304
|
)
|
|
300
305
|
}
|
|
@@ -321,7 +326,7 @@ export class Value {
|
|
|
321
326
|
}
|
|
322
327
|
throw new Error(
|
|
323
328
|
'reflect: call of reflect.Value.Index on ' +
|
|
324
|
-
this._type.Kind()
|
|
329
|
+
Kind_String(this._type.Kind()) +
|
|
325
330
|
' Value',
|
|
326
331
|
)
|
|
327
332
|
}
|
|
@@ -332,7 +337,7 @@ export class Value {
|
|
|
332
337
|
}
|
|
333
338
|
throw new Error(
|
|
334
339
|
'reflect: call of reflect.Value.Bytes on ' +
|
|
335
|
-
this._type.Kind()
|
|
340
|
+
Kind_String(this._type.Kind()) +
|
|
336
341
|
' Value',
|
|
337
342
|
)
|
|
338
343
|
}
|
|
@@ -401,7 +406,7 @@ export class Value {
|
|
|
401
406
|
|
|
402
407
|
// Send sends a value to a channel
|
|
403
408
|
public Send(x: Value): void {
|
|
404
|
-
if (this._type.Kind()
|
|
409
|
+
if (this._type.Kind() !== Chan) {
|
|
405
410
|
throw new Error('reflect: send on non-chan type')
|
|
406
411
|
}
|
|
407
412
|
|
|
@@ -711,12 +716,12 @@ class ChannelType implements Type {
|
|
|
711
716
|
public String(): string {
|
|
712
717
|
// Format: chan T, <-chan T, or chan<- T
|
|
713
718
|
const elem = this._elemType.String()
|
|
714
|
-
switch (this._dir
|
|
715
|
-
case
|
|
719
|
+
switch (this._dir) {
|
|
720
|
+
case RecvDir:
|
|
716
721
|
return `<-chan ${elem}`
|
|
717
|
-
case
|
|
722
|
+
case SendDir:
|
|
718
723
|
return `chan<- ${elem}`
|
|
719
|
-
case
|
|
724
|
+
case BothDir:
|
|
720
725
|
default:
|
|
721
726
|
return `chan ${elem}`
|
|
722
727
|
}
|
|
@@ -995,13 +1000,13 @@ export function ChanOf(dir: ChanDir, t: Type): Type {
|
|
|
995
1000
|
|
|
996
1001
|
// Additional functions from merged files
|
|
997
1002
|
export function canRangeFunc(t: Type): boolean {
|
|
998
|
-
const kind = t.Kind()
|
|
999
|
-
return kind ===
|
|
1003
|
+
const kind = t.Kind()
|
|
1004
|
+
return kind === Slice || kind === Array || kind === String
|
|
1000
1005
|
}
|
|
1001
1006
|
|
|
1002
1007
|
export function canRangeFunc2(t: Type): boolean {
|
|
1003
|
-
const kind = t.Kind()
|
|
1004
|
-
return kind ===
|
|
1008
|
+
const kind = t.Kind()
|
|
1009
|
+
return kind === Map
|
|
1005
1010
|
}
|
|
1006
1011
|
|
|
1007
1012
|
export function funcLayout(
|
package/gs/reflect/types.ts
CHANGED
|
@@ -34,34 +34,8 @@ export type ReflectValue =
|
|
|
34
34
|
| Float32Array
|
|
35
35
|
| Float64Array
|
|
36
36
|
|
|
37
|
-
// Channel direction constants and type
|
|
38
|
-
export class ChanDir {
|
|
39
|
-
constructor(private _value: number) {}
|
|
40
|
-
|
|
41
|
-
valueOf(): number {
|
|
42
|
-
return this._value
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
toString(): string {
|
|
46
|
-
switch (this._value) {
|
|
47
|
-
case 1:
|
|
48
|
-
return 'RecvDir'
|
|
49
|
-
case 2:
|
|
50
|
-
return 'SendDir'
|
|
51
|
-
case 3:
|
|
52
|
-
return 'BothDir'
|
|
53
|
-
default:
|
|
54
|
-
return 'InvalidDir'
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const RecvDir = new ChanDir(1)
|
|
60
|
-
export const SendDir = new ChanDir(2)
|
|
61
|
-
export const BothDir = new ChanDir(3)
|
|
62
|
-
|
|
63
37
|
// Import Type and Kind from the main type module
|
|
64
|
-
import { Type, Kind, Value } from './type.js'
|
|
38
|
+
import { Type, Kind, Value, Kind_String, ChanDir } from './type.js'
|
|
65
39
|
|
|
66
40
|
// Struct field representation
|
|
67
41
|
export class StructField {
|
|
@@ -205,7 +179,7 @@ export class ValueError extends Error {
|
|
|
205
179
|
|
|
206
180
|
constructor(init: { Kind: Kind; Method: string }) {
|
|
207
181
|
super(
|
|
208
|
-
`reflect: call of reflect.Value.${init.Method} on ${init.Kind
|
|
182
|
+
`reflect: call of reflect.Value.${init.Method} on ${Kind_String(init.Kind)} Value`,
|
|
209
183
|
)
|
|
210
184
|
this.Kind = init.Kind
|
|
211
185
|
this.Method = init.Method
|
package/gs/reflect/value.ts
CHANGED
|
@@ -40,30 +40,30 @@ export { ValueOf } from './type'
|
|
|
40
40
|
export function Zero(typ: Type): Value {
|
|
41
41
|
let zeroValue: ReflectValue
|
|
42
42
|
|
|
43
|
-
switch (typ.Kind()
|
|
44
|
-
case Bool
|
|
43
|
+
switch (typ.Kind()) {
|
|
44
|
+
case Bool:
|
|
45
45
|
zeroValue = false
|
|
46
46
|
break
|
|
47
|
-
case Int
|
|
48
|
-
case Int8
|
|
49
|
-
case Int16
|
|
50
|
-
case Int32
|
|
51
|
-
case Int64
|
|
52
|
-
case Uint
|
|
53
|
-
case Uint8
|
|
54
|
-
case Uint16
|
|
55
|
-
case Uint32
|
|
56
|
-
case Uint64
|
|
57
|
-
case Uintptr
|
|
58
|
-
case Float32
|
|
59
|
-
case Float64
|
|
47
|
+
case Int:
|
|
48
|
+
case Int8:
|
|
49
|
+
case Int16:
|
|
50
|
+
case Int32:
|
|
51
|
+
case Int64:
|
|
52
|
+
case Uint:
|
|
53
|
+
case Uint8:
|
|
54
|
+
case Uint16:
|
|
55
|
+
case Uint32:
|
|
56
|
+
case Uint64:
|
|
57
|
+
case Uintptr:
|
|
58
|
+
case Float32:
|
|
59
|
+
case Float64:
|
|
60
60
|
zeroValue = 0
|
|
61
61
|
break
|
|
62
|
-
case String
|
|
62
|
+
case String:
|
|
63
63
|
zeroValue = ''
|
|
64
64
|
break
|
|
65
|
-
case Slice
|
|
66
|
-
case Array
|
|
65
|
+
case Slice:
|
|
66
|
+
case Array:
|
|
67
67
|
zeroValue = []
|
|
68
68
|
break
|
|
69
69
|
default:
|
|
@@ -116,7 +116,7 @@ function getArrayFromValue(value: Value): unknown[] | null {
|
|
|
116
116
|
export function Indirect(v: Value): Value {
|
|
117
117
|
// Check if this is a pointer type
|
|
118
118
|
const type = v.Type()
|
|
119
|
-
if (type.Kind()
|
|
119
|
+
if (type.Kind() === Ptr) {
|
|
120
120
|
// Ptr kind
|
|
121
121
|
const elemType = type.Elem()
|
|
122
122
|
if (elemType) {
|
|
@@ -141,7 +141,7 @@ export function New(typ: Type): Value {
|
|
|
141
141
|
|
|
142
142
|
// MakeSlice returns a Value representing a new slice with the specified type, length, and capacity.
|
|
143
143
|
export function MakeSlice(typ: Type, len: number, _cap: number): Value {
|
|
144
|
-
if (typ.Kind()
|
|
144
|
+
if (typ.Kind() !== Slice) {
|
|
145
145
|
throw new Error('reflect.MakeSlice of non-slice type')
|
|
146
146
|
}
|
|
147
147
|
|
|
@@ -160,7 +160,7 @@ export function MakeSlice(typ: Type, len: number, _cap: number): Value {
|
|
|
160
160
|
|
|
161
161
|
// MakeMap returns a Value representing a new map with the specified type.
|
|
162
162
|
export function MakeMap(typ: Type): Value {
|
|
163
|
-
if (typ.Kind()
|
|
163
|
+
if (typ.Kind() !== Map) {
|
|
164
164
|
throw new Error('reflect.MakeMap of non-map type')
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -170,7 +170,7 @@ export function MakeMap(typ: Type): Value {
|
|
|
170
170
|
|
|
171
171
|
// Append appends the values x to a slice and returns the resulting slice.
|
|
172
172
|
export function Append(s: Value, x: Value): Value {
|
|
173
|
-
if (s.Kind()
|
|
173
|
+
if (s.Kind() !== Slice) {
|
|
174
174
|
throw new Error('reflect.Append of non-slice')
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -187,7 +187,7 @@ export function Append(s: Value, x: Value): Value {
|
|
|
187
187
|
|
|
188
188
|
// MakeChan returns a Value representing a new channel with the specified type.
|
|
189
189
|
export function MakeChan(typ: Type, buffer: number): Value {
|
|
190
|
-
if (typ.Kind()
|
|
190
|
+
if (typ.Kind() !== Chan) {
|
|
191
191
|
throw new Error('reflect.MakeChan of non-chan type')
|
|
192
192
|
}
|
|
193
193
|
|
|
@@ -15,7 +15,7 @@ export function VisibleFields(t: Type): $.Slice<StructField> {
|
|
|
15
15
|
if (t == null) {
|
|
16
16
|
$.panic('reflect: VisibleFields(nil)')
|
|
17
17
|
}
|
|
18
|
-
if (t!.Kind()
|
|
18
|
+
if (t!.Kind() != 25) {
|
|
19
19
|
$.panic('reflect.VisibleFields of non-struct type ' + t!.String())
|
|
20
20
|
}
|
|
21
21
|
let w = new visibleFieldsWalker({
|
|
@@ -133,13 +133,13 @@ class visibleFieldsWalker {
|
|
|
133
133
|
const f = field.clone()
|
|
134
134
|
f.Index = $.append(null, w.index) as number[]
|
|
135
135
|
if (f.Anonymous) {
|
|
136
|
-
if (f.Type && f.Type.Kind()
|
|
136
|
+
if (f.Type && f.Type.Kind() === Ptr) {
|
|
137
137
|
const elemType = f.Type.Elem!()
|
|
138
138
|
if (elemType) {
|
|
139
139
|
f.Type = elemType
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
if (f.Type && f.Type.Kind()
|
|
142
|
+
if (f.Type && f.Type.Kind() === Struct) {
|
|
143
143
|
w.walk(f.Type)
|
|
144
144
|
}
|
|
145
145
|
} else {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": [
|
|
3
|
+
"unsafe"
|
|
4
|
+
],
|
|
5
|
+
"asyncMethods": {
|
|
6
|
+
"Mutex.Lock": true,
|
|
7
|
+
"RWMutex.Lock": true,
|
|
8
|
+
"RWMutex.RLock": true,
|
|
9
|
+
"WaitGroup.Wait": true,
|
|
10
|
+
"Once.Do": true,
|
|
11
|
+
"Cond.Wait": true,
|
|
12
|
+
"Map.Delete": true,
|
|
13
|
+
"Map.Load": true,
|
|
14
|
+
"Map.LoadAndDelete": true,
|
|
15
|
+
"Map.LoadOrStore": true,
|
|
16
|
+
"Map.Range": true,
|
|
17
|
+
"Map.Store": true
|
|
18
|
+
}
|
|
19
|
+
}
|