goscript 0.0.48 → 0.0.50
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 +1120 -513
- package/compiler/analysis_test.go +113 -4
- package/compiler/compiler.go +88 -124
- package/compiler/decl.go +22 -0
- package/compiler/expr-call-async.go +46 -52
- package/compiler/expr-call-type-conversion.go +144 -59
- package/compiler/expr-call.go +235 -12
- 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 +337 -151
- package/compiler/stmt-assign.go +7 -4
- package/compiler/stmt.go +250 -81
- package/compiler/type.go +13 -0
- 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/context/context.d.ts +16 -18
- package/dist/gs/context/context.js +23 -13
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/fmt/fmt.js +22 -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 +98 -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 +13 -23
- package/dist/gs/time/time.js +57 -75
- package/dist/gs/time/time.js.map +1 -1
- package/gs/builtin/builtin.ts +3 -47
- package/gs/builtin/slice.ts +1 -1
- package/gs/bytes/meta.json +10 -0
- package/gs/context/context.ts +63 -45
- package/gs/fmt/fmt.ts +22 -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 +105 -105
- 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 +65 -84
- package/package.json +2 -2
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
|
-
import { TypeOf } from './type.js'
|
|
2
|
+
import { TypeOf, Kind_String } from './type.js'
|
|
3
3
|
|
|
4
4
|
describe('Function Type Detection', () => {
|
|
5
5
|
it('should detect regular function types', () => {
|
|
@@ -8,7 +8,7 @@ describe('Function Type Detection', () => {
|
|
|
8
8
|
}
|
|
9
9
|
const type = TypeOf(regularFunc)
|
|
10
10
|
expect(type.String()).toMatch(/^func/)
|
|
11
|
-
expect(type.Kind()
|
|
11
|
+
expect(Kind_String(type.Kind())).toBe('func')
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
it('should detect GoScript typed functions with __goTypeName', () => {
|
|
@@ -19,7 +19,7 @@ describe('Function Type Detection', () => {
|
|
|
19
19
|
Object.assign(greetFunc, { __goTypeName: 'Greeter' })
|
|
20
20
|
const greetType = TypeOf(greetFunc)
|
|
21
21
|
expect(greetType.String()).toBe('func(string) string')
|
|
22
|
-
expect(greetType.Kind()
|
|
22
|
+
expect(Kind_String(greetType.Kind())).toBe('func')
|
|
23
23
|
|
|
24
24
|
// Test Adder function type
|
|
25
25
|
const addFunc = function (a: number, b: number) {
|
|
@@ -28,7 +28,7 @@ describe('Function Type Detection', () => {
|
|
|
28
28
|
Object.assign(addFunc, { __goTypeName: 'Adder' })
|
|
29
29
|
const addType = TypeOf(addFunc)
|
|
30
30
|
expect(addType.String()).toBe('func(int, int) int')
|
|
31
|
-
expect(addType.Kind()
|
|
31
|
+
expect(Kind_String(addType.Kind())).toBe('func')
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
it('should detect functions with full __typeInfo metadata', () => {
|
|
@@ -49,7 +49,7 @@ describe('Function Type Detection', () => {
|
|
|
49
49
|
|
|
50
50
|
const type = TypeOf(complexFunc)
|
|
51
51
|
expect(type.String()).toBe('func(int, int) int')
|
|
52
|
-
expect(type.Kind()
|
|
52
|
+
expect(Kind_String(type.Kind())).toBe('func')
|
|
53
53
|
})
|
|
54
54
|
|
|
55
55
|
it('should handle functions with multiple return types', () => {
|
|
@@ -70,7 +70,7 @@ describe('Function Type Detection', () => {
|
|
|
70
70
|
|
|
71
71
|
const type = TypeOf(multiReturnFunc)
|
|
72
72
|
expect(type.String()).toBe('func() (int, string)')
|
|
73
|
-
expect(type.Kind()
|
|
73
|
+
expect(Kind_String(type.Kind())).toBe('func')
|
|
74
74
|
})
|
|
75
75
|
|
|
76
76
|
it('should handle functions with no parameters', () => {
|
|
@@ -88,7 +88,7 @@ describe('Function Type Detection', () => {
|
|
|
88
88
|
|
|
89
89
|
const type = TypeOf(noParamFunc)
|
|
90
90
|
expect(type.String()).toBe('func() int')
|
|
91
|
-
expect(type.Kind()
|
|
91
|
+
expect(Kind_String(type.Kind())).toBe('func')
|
|
92
92
|
})
|
|
93
93
|
|
|
94
94
|
it('should handle functions with no return type', () => {
|
|
@@ -106,7 +106,7 @@ describe('Function Type Detection', () => {
|
|
|
106
106
|
|
|
107
107
|
const type = TypeOf(voidFunc)
|
|
108
108
|
expect(type.String()).toBe('func(int)')
|
|
109
|
-
expect(type.Kind()
|
|
109
|
+
expect(Kind_String(type.Kind())).toBe('func')
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
it('should fallback to generic func for unknown typed functions', () => {
|
|
@@ -117,14 +117,14 @@ describe('Function Type Detection', () => {
|
|
|
117
117
|
|
|
118
118
|
const type = TypeOf(unknownFunc)
|
|
119
119
|
expect(type.String()).toBe('func')
|
|
120
|
-
expect(type.Kind()
|
|
120
|
+
expect(Kind_String(type.Kind())).toBe('func')
|
|
121
121
|
})
|
|
122
122
|
|
|
123
123
|
it('should handle arrow functions', () => {
|
|
124
124
|
const arrowFunc = (x: number) => x * 2
|
|
125
125
|
const type = TypeOf(arrowFunc)
|
|
126
126
|
expect(type.String()).toMatch(/^func/)
|
|
127
|
-
expect(type.Kind()
|
|
127
|
+
expect(Kind_String(type.Kind())).toBe('func')
|
|
128
128
|
})
|
|
129
129
|
|
|
130
130
|
it('should detect functions that return values vs void functions', () => {
|
package/gs/reflect/index.ts
CHANGED
|
@@ -3,15 +3,19 @@ export {
|
|
|
3
3
|
TypeOf,
|
|
4
4
|
ValueOf,
|
|
5
5
|
Value,
|
|
6
|
-
|
|
6
|
+
Kind_String,
|
|
7
7
|
ArrayOf,
|
|
8
8
|
SliceOf,
|
|
9
9
|
PointerTo,
|
|
10
10
|
PtrTo,
|
|
11
11
|
MapOf,
|
|
12
12
|
ChanOf,
|
|
13
|
+
ChanDir_String,
|
|
14
|
+
RecvDir,
|
|
15
|
+
SendDir,
|
|
16
|
+
BothDir,
|
|
13
17
|
} from './type'
|
|
14
|
-
export type { Type } from './type'
|
|
18
|
+
export type { Type, ChanDir, Kind } from './type'
|
|
15
19
|
export { DeepEqual } from './deepequal'
|
|
16
20
|
export {
|
|
17
21
|
Zero,
|
|
@@ -28,10 +32,6 @@ export { Swapper } from './swapper'
|
|
|
28
32
|
|
|
29
33
|
// Export new types and constants
|
|
30
34
|
export {
|
|
31
|
-
ChanDir,
|
|
32
|
-
RecvDir,
|
|
33
|
-
SendDir,
|
|
34
|
-
BothDir,
|
|
35
35
|
StructTag,
|
|
36
36
|
ValueError,
|
|
37
37
|
SelectDir,
|
package/gs/reflect/map.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Type, Kind, Value } from './type.js'
|
|
1
|
+
import { Type, Kind, Value, Map as MapKind } from './type.js'
|
|
2
2
|
|
|
3
3
|
// Simple MapOf implementation using JavaScript Map
|
|
4
4
|
export function MapOf(key: Type, elem: Type): Type {
|
|
@@ -17,7 +17,7 @@ class MapType implements Type {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
public Kind(): Kind {
|
|
20
|
-
return
|
|
20
|
+
return MapKind // Map kind
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
public Size(): number {
|
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,18 +10,12 @@ 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
|
-
|
|
19
|
-
return (
|
|
20
|
-
k === Ptr.valueOf() ||
|
|
21
|
-
k === Map.valueOf() ||
|
|
22
|
-
k === Slice.valueOf() ||
|
|
23
|
-
k === Interface.valueOf()
|
|
24
|
-
)
|
|
17
|
+
const k = this.kind
|
|
18
|
+
return k === Ptr || k === Map || k === Slice || k === Interface
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
21
|
|
|
@@ -42,15 +36,14 @@ export class flag {
|
|
|
42
36
|
if (typeof _value === 'number') {
|
|
43
37
|
this._value = _value
|
|
44
38
|
} else {
|
|
45
|
-
this._value = _value
|
|
39
|
+
this._value = _value
|
|
46
40
|
}
|
|
47
41
|
}
|
|
48
42
|
|
|
49
43
|
valueOf(): number {
|
|
50
|
-
return typeof this._value === 'number' ? this._value : this._value
|
|
44
|
+
return typeof this._value === 'number' ? this._value : this._value
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
// Support arithmetic operations
|
|
54
47
|
static from(value: number | Kind): flag {
|
|
55
48
|
return new flag(value)
|
|
56
49
|
}
|
|
@@ -80,86 +73,93 @@ export class bitVector {
|
|
|
80
73
|
}
|
|
81
74
|
|
|
82
75
|
// 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
|
-
|
|
76
|
+
export type Kind = number
|
|
77
|
+
|
|
78
|
+
// Kind_String returns the string representation of a Kind (wrapper function naming)
|
|
79
|
+
export function Kind_String(k: Kind): string {
|
|
80
|
+
const kindNames = [
|
|
81
|
+
'invalid',
|
|
82
|
+
'bool',
|
|
83
|
+
'int',
|
|
84
|
+
'int8',
|
|
85
|
+
'int16',
|
|
86
|
+
'int32',
|
|
87
|
+
'int64',
|
|
88
|
+
'uint',
|
|
89
|
+
'uint8',
|
|
90
|
+
'uint16',
|
|
91
|
+
'uint32',
|
|
92
|
+
'uint64',
|
|
93
|
+
'uintptr',
|
|
94
|
+
'float32',
|
|
95
|
+
'float64',
|
|
96
|
+
'complex64',
|
|
97
|
+
'complex128',
|
|
98
|
+
'array',
|
|
99
|
+
'chan',
|
|
100
|
+
'func',
|
|
101
|
+
'interface',
|
|
102
|
+
'map',
|
|
103
|
+
'ptr',
|
|
104
|
+
'slice',
|
|
105
|
+
'string',
|
|
106
|
+
'struct',
|
|
107
|
+
'unsafe.Pointer',
|
|
108
|
+
]
|
|
109
|
+
if (k >= 0 && k < kindNames.length) {
|
|
110
|
+
return kindNames[k]
|
|
111
|
+
}
|
|
112
|
+
return 'invalid'
|
|
113
|
+
}
|
|
97
114
|
|
|
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'
|
|
115
|
+
// Channel direction constants and type
|
|
116
|
+
export type ChanDir = number
|
|
117
|
+
|
|
118
|
+
export const RecvDir: ChanDir = 1
|
|
119
|
+
export const SendDir: ChanDir = 2
|
|
120
|
+
export const BothDir: ChanDir = 3
|
|
121
|
+
|
|
122
|
+
export function ChanDir_String(d: ChanDir): string {
|
|
123
|
+
switch (d) {
|
|
124
|
+
case RecvDir:
|
|
125
|
+
return 'RecvDir'
|
|
126
|
+
case SendDir:
|
|
127
|
+
return 'SendDir'
|
|
128
|
+
case BothDir:
|
|
129
|
+
return 'BothDir'
|
|
130
|
+
default:
|
|
131
|
+
return 'ChanDir(' + d + ')'
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
// 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 =
|
|
136
|
+
export const Invalid: Kind = 0
|
|
137
|
+
export const Bool: Kind = 1
|
|
138
|
+
export const Int: Kind = 2
|
|
139
|
+
export const Int8: Kind = 3
|
|
140
|
+
export const Int16: Kind = 4
|
|
141
|
+
export const Int32: Kind = 5
|
|
142
|
+
export const Int64: Kind = 6
|
|
143
|
+
export const Uint: Kind = 7
|
|
144
|
+
export const Uint8: Kind = 8
|
|
145
|
+
export const Uint16: Kind = 9
|
|
146
|
+
export const Uint32: Kind = 10
|
|
147
|
+
export const Uint64: Kind = 11
|
|
148
|
+
export const Uintptr: Kind = 12
|
|
149
|
+
export const Float32: Kind = 13
|
|
150
|
+
export const Float64: Kind = 14
|
|
151
|
+
export const Complex64: Kind = 15
|
|
152
|
+
export const Complex128: Kind = 16
|
|
153
|
+
export const Array: Kind = 17
|
|
154
|
+
export const Chan: Kind = 18
|
|
155
|
+
export const Func: Kind = 19
|
|
156
|
+
export const Interface: Kind = 20
|
|
157
|
+
export const Map: Kind = 21
|
|
158
|
+
export const Ptr: Kind = 22
|
|
159
|
+
export const Slice: Kind = 23
|
|
160
|
+
export const String: Kind = 24
|
|
161
|
+
export const Struct: Kind = 25
|
|
162
|
+
export const UnsafePointer: Kind = 26
|
|
163
163
|
|
|
164
164
|
// Type is the representation of a Go type.
|
|
165
165
|
export interface Type {
|
|
@@ -206,7 +206,7 @@ export class Value {
|
|
|
206
206
|
}
|
|
207
207
|
throw new Error(
|
|
208
208
|
'reflect: call of reflect.Value.Int on ' +
|
|
209
|
-
this._type.Kind()
|
|
209
|
+
Kind_String(this._type.Kind()) +
|
|
210
210
|
' Value',
|
|
211
211
|
)
|
|
212
212
|
}
|
|
@@ -217,7 +217,7 @@ export class Value {
|
|
|
217
217
|
}
|
|
218
218
|
throw new Error(
|
|
219
219
|
'reflect: call of reflect.Value.Uint on ' +
|
|
220
|
-
this._type.Kind()
|
|
220
|
+
Kind_String(this._type.Kind()) +
|
|
221
221
|
' Value',
|
|
222
222
|
)
|
|
223
223
|
}
|
|
@@ -228,7 +228,7 @@ export class Value {
|
|
|
228
228
|
}
|
|
229
229
|
throw new Error(
|
|
230
230
|
'reflect: call of reflect.Value.Float on ' +
|
|
231
|
-
this._type.Kind()
|
|
231
|
+
Kind_String(this._type.Kind()) +
|
|
232
232
|
' Value',
|
|
233
233
|
)
|
|
234
234
|
}
|
|
@@ -239,7 +239,7 @@ export class Value {
|
|
|
239
239
|
}
|
|
240
240
|
throw new Error(
|
|
241
241
|
'reflect: call of reflect.Value.Bool on ' +
|
|
242
|
-
this._type.Kind()
|
|
242
|
+
Kind_String(this._type.Kind()) +
|
|
243
243
|
' Value',
|
|
244
244
|
)
|
|
245
245
|
}
|
|
@@ -249,7 +249,7 @@ export class Value {
|
|
|
249
249
|
return this._value
|
|
250
250
|
}
|
|
251
251
|
// Special case for bool values - display as <bool Value>
|
|
252
|
-
if (this._type.Kind()
|
|
252
|
+
if (this._type.Kind() === Bool) {
|
|
253
253
|
return '<bool Value>'
|
|
254
254
|
}
|
|
255
255
|
return this._type.String()
|
|
@@ -294,7 +294,7 @@ export class Value {
|
|
|
294
294
|
|
|
295
295
|
throw new Error(
|
|
296
296
|
'reflect: call of reflect.Value.Len on ' +
|
|
297
|
-
this._type.Kind()
|
|
297
|
+
Kind_String(this._type.Kind()) +
|
|
298
298
|
' Value',
|
|
299
299
|
)
|
|
300
300
|
}
|
|
@@ -321,7 +321,7 @@ export class Value {
|
|
|
321
321
|
}
|
|
322
322
|
throw new Error(
|
|
323
323
|
'reflect: call of reflect.Value.Index on ' +
|
|
324
|
-
this._type.Kind()
|
|
324
|
+
Kind_String(this._type.Kind()) +
|
|
325
325
|
' Value',
|
|
326
326
|
)
|
|
327
327
|
}
|
|
@@ -332,7 +332,7 @@ export class Value {
|
|
|
332
332
|
}
|
|
333
333
|
throw new Error(
|
|
334
334
|
'reflect: call of reflect.Value.Bytes on ' +
|
|
335
|
-
this._type.Kind()
|
|
335
|
+
Kind_String(this._type.Kind()) +
|
|
336
336
|
' Value',
|
|
337
337
|
)
|
|
338
338
|
}
|
|
@@ -401,7 +401,7 @@ export class Value {
|
|
|
401
401
|
|
|
402
402
|
// Send sends a value to a channel
|
|
403
403
|
public Send(x: Value): void {
|
|
404
|
-
if (this._type.Kind()
|
|
404
|
+
if (this._type.Kind() !== Chan) {
|
|
405
405
|
throw new Error('reflect: send on non-chan type')
|
|
406
406
|
}
|
|
407
407
|
|
|
@@ -711,12 +711,12 @@ class ChannelType implements Type {
|
|
|
711
711
|
public String(): string {
|
|
712
712
|
// Format: chan T, <-chan T, or chan<- T
|
|
713
713
|
const elem = this._elemType.String()
|
|
714
|
-
switch (this._dir
|
|
715
|
-
case
|
|
714
|
+
switch (this._dir) {
|
|
715
|
+
case RecvDir:
|
|
716
716
|
return `<-chan ${elem}`
|
|
717
|
-
case
|
|
717
|
+
case SendDir:
|
|
718
718
|
return `chan<- ${elem}`
|
|
719
|
-
case
|
|
719
|
+
case BothDir:
|
|
720
720
|
default:
|
|
721
721
|
return `chan ${elem}`
|
|
722
722
|
}
|
|
@@ -995,13 +995,13 @@ export function ChanOf(dir: ChanDir, t: Type): Type {
|
|
|
995
995
|
|
|
996
996
|
// Additional functions from merged files
|
|
997
997
|
export function canRangeFunc(t: Type): boolean {
|
|
998
|
-
const kind = t.Kind()
|
|
999
|
-
return kind ===
|
|
998
|
+
const kind = t.Kind()
|
|
999
|
+
return kind === Slice || kind === Array || kind === String
|
|
1000
1000
|
}
|
|
1001
1001
|
|
|
1002
1002
|
export function canRangeFunc2(t: Type): boolean {
|
|
1003
|
-
const kind = t.Kind()
|
|
1004
|
-
return kind ===
|
|
1003
|
+
const kind = t.Kind()
|
|
1004
|
+
return kind === Map
|
|
1005
1005
|
}
|
|
1006
1006
|
|
|
1007
1007
|
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
|
+
}
|