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.
Files changed (159) hide show
  1. package/cmd/goscript/deps.go +1 -4
  2. package/compiler/analysis.go +1120 -513
  3. package/compiler/analysis_test.go +113 -4
  4. package/compiler/compiler.go +88 -124
  5. package/compiler/decl.go +22 -0
  6. package/compiler/expr-call-async.go +46 -52
  7. package/compiler/expr-call-type-conversion.go +144 -59
  8. package/compiler/expr-call.go +235 -12
  9. package/compiler/expr.go +5 -82
  10. package/compiler/gs_dependencies_test.go +60 -1
  11. package/compiler/spec-value.go +73 -51
  12. package/compiler/spec.go +337 -151
  13. package/compiler/stmt-assign.go +7 -4
  14. package/compiler/stmt.go +250 -81
  15. package/compiler/type.go +13 -0
  16. package/dist/gs/builtin/builtin.d.ts +1 -5
  17. package/dist/gs/builtin/builtin.js +1 -34
  18. package/dist/gs/builtin/builtin.js.map +1 -1
  19. package/dist/gs/builtin/slice.js.map +1 -1
  20. package/dist/gs/context/context.d.ts +16 -18
  21. package/dist/gs/context/context.js +23 -13
  22. package/dist/gs/context/context.js.map +1 -1
  23. package/dist/gs/fmt/fmt.js +22 -4
  24. package/dist/gs/fmt/fmt.js.map +1 -1
  25. package/dist/gs/io/fs/fs.d.ts +6 -12
  26. package/dist/gs/io/fs/fs.js +52 -67
  27. package/dist/gs/io/fs/fs.js.map +1 -1
  28. package/dist/gs/os/index.d.ts +2 -1
  29. package/dist/gs/os/index.js +1 -1
  30. package/dist/gs/os/index.js.map +1 -1
  31. package/dist/gs/os/types_js.gs.d.ts +7 -1
  32. package/dist/gs/os/types_js.gs.js +16 -1
  33. package/dist/gs/os/types_js.gs.js.map +1 -1
  34. package/dist/gs/os/types_unix.gs.js +2 -2
  35. package/dist/gs/os/types_unix.gs.js.map +1 -1
  36. package/dist/gs/reflect/index.d.ts +3 -3
  37. package/dist/gs/reflect/index.js +2 -2
  38. package/dist/gs/reflect/index.js.map +1 -1
  39. package/dist/gs/reflect/map.js +2 -2
  40. package/dist/gs/reflect/map.js.map +1 -1
  41. package/dist/gs/reflect/type.d.ts +8 -9
  42. package/dist/gs/reflect/type.js +98 -103
  43. package/dist/gs/reflect/type.js.map +1 -1
  44. package/dist/gs/reflect/types.d.ts +1 -10
  45. package/dist/gs/reflect/types.js +3 -26
  46. package/dist/gs/reflect/types.js.map +1 -1
  47. package/dist/gs/reflect/value.js +23 -23
  48. package/dist/gs/reflect/value.js.map +1 -1
  49. package/dist/gs/reflect/visiblefields.js +3 -3
  50. package/dist/gs/reflect/visiblefields.js.map +1 -1
  51. package/dist/gs/time/time.d.ts +13 -23
  52. package/dist/gs/time/time.js +57 -75
  53. package/dist/gs/time/time.js.map +1 -1
  54. package/gs/builtin/builtin.ts +3 -47
  55. package/gs/builtin/slice.ts +1 -1
  56. package/gs/bytes/meta.json +10 -0
  57. package/gs/context/context.ts +63 -45
  58. package/gs/fmt/fmt.ts +22 -4
  59. package/gs/fmt/meta.json +5 -0
  60. package/gs/internal/meta.json +5 -0
  61. package/gs/io/fs/fs.ts +58 -73
  62. package/gs/io/meta.json +9 -0
  63. package/gs/maps/meta.json +6 -0
  64. package/gs/math/meta.json +5 -0
  65. package/gs/os/index.ts +8 -1
  66. package/gs/os/meta.json +15 -0
  67. package/gs/os/types_js.gs.ts +22 -1
  68. package/gs/os/types_unix.gs.ts +2 -2
  69. package/gs/path/meta.json +6 -0
  70. package/gs/reflect/function-types.test.ts +10 -10
  71. package/gs/reflect/index.ts +6 -6
  72. package/gs/reflect/map.ts +2 -2
  73. package/gs/reflect/meta.json +5 -0
  74. package/gs/reflect/type.ts +105 -105
  75. package/gs/reflect/types.ts +2 -28
  76. package/gs/reflect/value.ts +23 -23
  77. package/gs/reflect/visiblefields.ts +3 -3
  78. package/gs/strconv/meta.json +5 -0
  79. package/gs/strings/meta.json +9 -0
  80. package/gs/sync/meta.json +19 -0
  81. package/gs/time/time.ts +65 -84
  82. package/package.json +2 -2
  83. package/dist/gs/builtin/io.d.ts +0 -16
  84. package/dist/gs/builtin/io.js +0 -15
  85. package/dist/gs/builtin/io.js.map +0 -1
  86. package/dist/gs/internal/testlog/index.d.ts +0 -1
  87. package/dist/gs/internal/testlog/index.js +0 -5
  88. package/dist/gs/internal/testlog/index.js.map +0 -1
  89. package/dist/gs/maps/iter.gs.d.ts +0 -7
  90. package/dist/gs/maps/iter.gs.js +0 -65
  91. package/dist/gs/maps/iter.gs.js.map +0 -1
  92. package/dist/gs/maps/maps.gs.d.ts +0 -7
  93. package/dist/gs/maps/maps.gs.js +0 -79
  94. package/dist/gs/maps/maps.gs.js.map +0 -1
  95. package/dist/gs/reflect/abi.d.ts +0 -59
  96. package/dist/gs/reflect/abi.gs.d.ts +0 -59
  97. package/dist/gs/reflect/abi.gs.js +0 -79
  98. package/dist/gs/reflect/abi.gs.js.map +0 -1
  99. package/dist/gs/reflect/abi.js +0 -79
  100. package/dist/gs/reflect/abi.js.map +0 -1
  101. package/dist/gs/reflect/badlinkname.d.ts +0 -52
  102. package/dist/gs/reflect/badlinkname.gs.d.ts +0 -52
  103. package/dist/gs/reflect/badlinkname.gs.js +0 -72
  104. package/dist/gs/reflect/badlinkname.gs.js.map +0 -1
  105. package/dist/gs/reflect/badlinkname.js +0 -72
  106. package/dist/gs/reflect/badlinkname.js.map +0 -1
  107. package/dist/gs/reflect/deepequal.gs.d.ts +0 -25
  108. package/dist/gs/reflect/deepequal.gs.js +0 -308
  109. package/dist/gs/reflect/deepequal.gs.js.map +0 -1
  110. package/dist/gs/reflect/float32reg_generic.gs.d.ts +0 -2
  111. package/dist/gs/reflect/float32reg_generic.gs.js +0 -10
  112. package/dist/gs/reflect/float32reg_generic.gs.js.map +0 -1
  113. package/dist/gs/reflect/index.gs.d.ts +0 -1
  114. package/dist/gs/reflect/index.gs.js +0 -3
  115. package/dist/gs/reflect/index.gs.js.map +0 -1
  116. package/dist/gs/reflect/iter.gs.d.ts +0 -3
  117. package/dist/gs/reflect/iter.gs.js +0 -24
  118. package/dist/gs/reflect/iter.gs.js.map +0 -1
  119. package/dist/gs/reflect/makefunc.gs.d.ts +0 -34
  120. package/dist/gs/reflect/makefunc.gs.js +0 -288
  121. package/dist/gs/reflect/makefunc.gs.js.map +0 -1
  122. package/dist/gs/reflect/map_swiss.gs.d.ts +0 -14
  123. package/dist/gs/reflect/map_swiss.gs.js +0 -70
  124. package/dist/gs/reflect/map_swiss.gs.js.map +0 -1
  125. package/dist/gs/reflect/reflect.gs.d.ts +0 -132
  126. package/dist/gs/reflect/reflect.gs.js +0 -437
  127. package/dist/gs/reflect/reflect.gs.js.map +0 -1
  128. package/dist/gs/reflect/swapper.gs.d.ts +0 -1
  129. package/dist/gs/reflect/swapper.gs.js +0 -32
  130. package/dist/gs/reflect/swapper.gs.js.map +0 -1
  131. package/dist/gs/reflect/type.gs.d.ts +0 -4
  132. package/dist/gs/reflect/type.gs.js +0 -21
  133. package/dist/gs/reflect/type.gs.js.map +0 -1
  134. package/dist/gs/reflect/value.gs.d.ts +0 -4
  135. package/dist/gs/reflect/value.gs.js +0 -12
  136. package/dist/gs/reflect/value.gs.js.map +0 -1
  137. package/dist/gs/reflect/visiblefields.gs.d.ts +0 -3
  138. package/dist/gs/reflect/visiblefields.gs.js +0 -123
  139. package/dist/gs/reflect/visiblefields.gs.js.map +0 -1
  140. package/dist/gs/stringslite/index.d.ts +0 -1
  141. package/dist/gs/stringslite/index.js +0 -2
  142. package/dist/gs/stringslite/index.js.map +0 -1
  143. package/dist/gs/stringslite/strings.d.ts +0 -11
  144. package/dist/gs/stringslite/strings.js +0 -67
  145. package/dist/gs/stringslite/strings.js.map +0 -1
  146. package/gs/bytes/metadata.go +0 -12
  147. package/gs/fmt/metadata.go +0 -7
  148. package/gs/internal/metadata.go +0 -7
  149. package/gs/io/io.go +0 -75
  150. package/gs/io/metadata.go +0 -11
  151. package/gs/maps/metadata.go +0 -8
  152. package/gs/math/metadata.go +0 -7
  153. package/gs/os/metadata.go +0 -17
  154. package/gs/path/metadata.go +0 -8
  155. package/gs/reflect/metadata.go +0 -7
  156. package/gs/strconv/metadata.go +0 -7
  157. package/gs/strings/metadata.go +0 -11
  158. package/gs/sync/metadata.go +0 -7
  159. 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().String()).toBe('func')
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().String()).toBe('func')
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().String()).toBe('func')
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().String()).toBe('func')
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().String()).toBe('func')
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().String()).toBe('func')
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().String()).toBe('func')
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().String()).toBe('func')
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().String()).toBe('func')
127
+ expect(Kind_String(type.Kind())).toBe('func')
128
128
  })
129
129
 
130
130
  it('should detect functions that return values vs void functions', () => {
@@ -3,15 +3,19 @@ export {
3
3
  TypeOf,
4
4
  ValueOf,
5
5
  Value,
6
- Kind,
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 new Kind(21) // Map kind
20
+ return MapKind // Map kind
21
21
  }
22
22
 
23
23
  public Size(): number {
@@ -0,0 +1,5 @@
1
+ {
2
+ "dependencies": [
3
+ "iter"
4
+ ]
5
+ }
@@ -1,4 +1,4 @@
1
- import { ReflectValue, ChanDir, StructField } from './types.js'
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.String()
13
+ return Kind_String(this.kind)
14
14
  }
15
15
 
16
16
  Pointers(): boolean {
17
- // Return true for pointer-like types
18
- const k = this.kind.valueOf()
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.valueOf()
39
+ this._value = _value
46
40
  }
47
41
  }
48
42
 
49
43
  valueOf(): number {
50
- return typeof this._value === 'number' ? this._value : this._value.valueOf()
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 class Kind {
84
- constructor(private _value: number) {}
85
-
86
- valueOf(): number {
87
- return this._value
88
- }
89
-
90
- toString(): string {
91
- return this.String()
92
- }
93
-
94
- static from(value: number): Kind {
95
- return new Kind(value)
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
- public String(): string {
99
- const kindNames = [
100
- 'invalid',
101
- 'bool',
102
- 'int',
103
- 'int8',
104
- 'int16',
105
- 'int32',
106
- 'int64',
107
- 'uint',
108
- 'uint8',
109
- 'uint16',
110
- 'uint32',
111
- 'uint64',
112
- 'uintptr',
113
- 'float32',
114
- 'float64',
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 = new Kind(0)
137
- export const Bool = new Kind(1)
138
- export const Int = new Kind(2)
139
- export const Int8 = new Kind(3)
140
- export const Int16 = new Kind(4)
141
- export const Int32 = new Kind(5)
142
- export const Int64 = new Kind(6)
143
- export const Uint = new Kind(7)
144
- export const Uint8 = new Kind(8)
145
- export const Uint16 = new Kind(9)
146
- export const Uint32 = new Kind(10)
147
- export const Uint64 = new Kind(11)
148
- export const Uintptr = new Kind(12)
149
- export const Float32 = new Kind(13)
150
- export const Float64 = new Kind(14)
151
- export const Complex64 = new Kind(15)
152
- export const Complex128 = new Kind(16)
153
- export const Array = new Kind(17)
154
- export const Chan = new Kind(18)
155
- export const Func = new Kind(19)
156
- export const Interface = new Kind(20)
157
- export const Map = new Kind(21)
158
- export const Ptr = new Kind(22)
159
- export const Slice = new Kind(23)
160
- export const String = new Kind(24)
161
- export const Struct = new Kind(25)
162
- export const UnsafePointer = new Kind(26)
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().String() +
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().String() +
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().String() +
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().String() +
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().valueOf() === Bool.valueOf()) {
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().String() +
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().String() +
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().String() +
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().valueOf() !== Chan.valueOf()) {
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.valueOf()) {
715
- case 1: // RecvDir
714
+ switch (this._dir) {
715
+ case RecvDir:
716
716
  return `<-chan ${elem}`
717
- case 2: // SendDir
717
+ case SendDir:
718
718
  return `chan<- ${elem}`
719
- case 3: // BothDir
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().valueOf()
999
- return kind === 23 || kind === 17 || kind === 24 // slice, array, string
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().valueOf()
1004
- return kind === 21 // map
1003
+ const kind = t.Kind()
1004
+ return kind === Map
1005
1005
  }
1006
1006
 
1007
1007
  export function funcLayout(
@@ -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.String()} Value`,
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
@@ -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().valueOf()) {
44
- case Bool.valueOf():
43
+ switch (typ.Kind()) {
44
+ case Bool:
45
45
  zeroValue = false
46
46
  break
47
- case Int.valueOf():
48
- case Int8.valueOf():
49
- case Int16.valueOf():
50
- case Int32.valueOf():
51
- case Int64.valueOf():
52
- case Uint.valueOf():
53
- case Uint8.valueOf():
54
- case Uint16.valueOf():
55
- case Uint32.valueOf():
56
- case Uint64.valueOf():
57
- case Uintptr.valueOf():
58
- case Float32.valueOf():
59
- case Float64.valueOf():
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.valueOf():
62
+ case String:
63
63
  zeroValue = ''
64
64
  break
65
- case Slice.valueOf():
66
- case Array.valueOf():
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().valueOf() === Ptr.valueOf()) {
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().valueOf() !== Slice.valueOf()) {
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().valueOf() !== Map.valueOf()) {
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().valueOf() !== Slice.valueOf()) {
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().valueOf() !== Chan.valueOf()) {
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().valueOf() != 25) {
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().valueOf() === Ptr.valueOf()) {
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().valueOf() === Struct.valueOf()) {
142
+ if (f.Type && f.Type.Kind() === Struct) {
143
143
  w.walk(f.Type)
144
144
  }
145
145
  } else {
@@ -0,0 +1,5 @@
1
+ {
2
+ "dependencies": [
3
+ "errors"
4
+ ]
5
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "dependencies": [
3
+ "errors",
4
+ "io",
5
+ "iter",
6
+ "unicode",
7
+ "unicode/utf8"
8
+ ]
9
+ }
@@ -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
+ }