goscript 0.0.37 → 0.0.38

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 (196) hide show
  1. package/compiler/analysis.go +129 -8
  2. package/compiler/compiler.go +4 -1
  3. package/compiler/composite-lit.go +2 -4
  4. package/compiler/lit.go +83 -0
  5. package/compiler/protobuf.go +2 -2
  6. package/compiler/spec-value.go +3 -3
  7. package/compiler/spec.go +6 -3
  8. package/compiler/stmt-assign.go +1 -1
  9. package/dist/gs/builtin/slice.js +2 -1
  10. package/dist/gs/builtin/slice.js.map +1 -1
  11. package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
  12. package/dist/gs/github.com/pkg/errors/errors.js +182 -23
  13. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
  14. package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
  15. package/dist/gs/github.com/pkg/errors/go113.js +1 -1
  16. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
  17. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
  18. package/dist/gs/github.com/pkg/errors/index.js +3 -3
  19. package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
  20. package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
  21. package/dist/gs/github.com/pkg/errors/stack.js +8 -5
  22. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
  23. package/dist/gs/internal/abi/index.d.ts +20 -0
  24. package/dist/gs/internal/abi/index.js +20 -0
  25. package/dist/gs/internal/abi/index.js.map +1 -0
  26. package/dist/gs/internal/bytealg/index.d.ts +2 -0
  27. package/dist/gs/internal/bytealg/index.js +33 -0
  28. package/dist/gs/internal/bytealg/index.js.map +1 -0
  29. package/dist/gs/internal/byteorder/index.d.ts +1 -1
  30. package/dist/gs/internal/byteorder/index.js +4 -4
  31. package/dist/gs/internal/byteorder/index.js.map +1 -1
  32. package/dist/gs/math/index.d.ts +44 -44
  33. package/dist/gs/math/index.js +44 -44
  34. package/dist/gs/math/index.js.map +1 -1
  35. package/dist/gs/os/index.d.ts +19 -19
  36. package/dist/gs/os/index.js +19 -19
  37. package/dist/gs/os/index.js.map +1 -1
  38. package/dist/gs/reflect/abi.d.ts +59 -0
  39. package/dist/gs/reflect/abi.gs.d.ts +59 -0
  40. package/dist/gs/reflect/abi.gs.js +79 -0
  41. package/dist/gs/reflect/abi.gs.js.map +1 -0
  42. package/dist/gs/reflect/abi.js +79 -0
  43. package/dist/gs/reflect/abi.js.map +1 -0
  44. package/dist/gs/reflect/badlinkname.d.ts +52 -0
  45. package/dist/gs/reflect/badlinkname.gs.d.ts +52 -0
  46. package/dist/gs/reflect/badlinkname.gs.js +72 -0
  47. package/dist/gs/reflect/badlinkname.gs.js.map +1 -0
  48. package/dist/gs/reflect/badlinkname.js +72 -0
  49. package/dist/gs/reflect/badlinkname.js.map +1 -0
  50. package/dist/gs/reflect/deepequal.d.ts +1 -0
  51. package/dist/gs/reflect/deepequal.gs.d.ts +25 -0
  52. package/dist/gs/reflect/deepequal.gs.js +308 -0
  53. package/dist/gs/reflect/deepequal.gs.js.map +1 -0
  54. package/dist/gs/reflect/deepequal.js +139 -0
  55. package/dist/gs/reflect/deepequal.js.map +1 -0
  56. package/dist/gs/reflect/float32reg_generic.gs.d.ts +2 -0
  57. package/dist/gs/reflect/float32reg_generic.gs.js +10 -0
  58. package/dist/gs/reflect/float32reg_generic.gs.js.map +1 -0
  59. package/dist/gs/reflect/index.d.ts +8 -0
  60. package/dist/gs/reflect/index.gs.d.ts +1 -0
  61. package/dist/gs/reflect/index.gs.js +3 -0
  62. package/dist/gs/reflect/index.gs.js.map +1 -0
  63. package/dist/gs/reflect/index.js +10 -0
  64. package/dist/gs/reflect/index.js.map +1 -0
  65. package/dist/gs/reflect/iter.d.ts +4 -0
  66. package/dist/gs/reflect/iter.gs.d.ts +3 -0
  67. package/dist/gs/reflect/iter.gs.js +24 -0
  68. package/dist/gs/reflect/iter.gs.js.map +1 -0
  69. package/dist/gs/reflect/iter.js +24 -0
  70. package/dist/gs/reflect/iter.js.map +1 -0
  71. package/dist/gs/reflect/makefunc.gs.d.ts +34 -0
  72. package/dist/gs/reflect/makefunc.gs.js +288 -0
  73. package/dist/gs/reflect/makefunc.gs.js.map +1 -0
  74. package/dist/gs/reflect/map.d.ts +14 -0
  75. package/dist/gs/reflect/map.js +70 -0
  76. package/dist/gs/reflect/map.js.map +1 -0
  77. package/dist/gs/reflect/map_swiss.gs.d.ts +14 -0
  78. package/dist/gs/reflect/map_swiss.gs.js +70 -0
  79. package/dist/gs/reflect/map_swiss.gs.js.map +1 -0
  80. package/dist/gs/reflect/reflect.gs.d.ts +132 -0
  81. package/dist/gs/reflect/reflect.gs.js +437 -0
  82. package/dist/gs/reflect/reflect.gs.js.map +1 -0
  83. package/dist/gs/reflect/swapper.d.ts +2 -0
  84. package/dist/gs/reflect/swapper.gs.d.ts +1 -0
  85. package/dist/gs/reflect/swapper.gs.js +32 -0
  86. package/dist/gs/reflect/swapper.gs.js.map +1 -0
  87. package/dist/gs/reflect/swapper.js +46 -0
  88. package/dist/gs/reflect/swapper.js.map +1 -0
  89. package/dist/gs/reflect/type.d.ts +126 -0
  90. package/dist/gs/reflect/type.gs.d.ts +4 -0
  91. package/dist/gs/reflect/type.gs.js +21 -0
  92. package/dist/gs/reflect/type.gs.js.map +1 -0
  93. package/dist/gs/reflect/type.js +825 -0
  94. package/dist/gs/reflect/type.js.map +1 -0
  95. package/dist/gs/reflect/types.d.ts +90 -0
  96. package/dist/gs/reflect/types.js +119 -0
  97. package/dist/gs/reflect/types.js.map +1 -0
  98. package/dist/gs/reflect/value.d.ts +13 -0
  99. package/dist/gs/reflect/value.gs.d.ts +4 -0
  100. package/dist/gs/reflect/value.gs.js +12 -0
  101. package/dist/gs/reflect/value.gs.js.map +1 -0
  102. package/dist/gs/reflect/value.js +201 -0
  103. package/dist/gs/reflect/value.js.map +1 -0
  104. package/dist/gs/reflect/visiblefields.d.ts +4 -0
  105. package/dist/gs/reflect/visiblefields.gs.d.ts +3 -0
  106. package/dist/gs/reflect/visiblefields.gs.js +123 -0
  107. package/dist/gs/reflect/visiblefields.gs.js.map +1 -0
  108. package/dist/gs/reflect/visiblefields.js +143 -0
  109. package/dist/gs/reflect/visiblefields.js.map +1 -0
  110. package/dist/gs/strconv/index.d.ts +6 -6
  111. package/dist/gs/strconv/index.js +6 -6
  112. package/dist/gs/strconv/index.js.map +1 -1
  113. package/dist/gs/strings/index.d.ts +1 -1
  114. package/dist/gs/strings/index.js +1 -1
  115. package/dist/gs/strings/index.js.map +1 -1
  116. package/dist/gs/strings/replace.js.map +1 -1
  117. package/dist/gs/sync/atomic/index.d.ts +4 -4
  118. package/dist/gs/sync/atomic/index.js +4 -4
  119. package/dist/gs/sync/atomic/index.js.map +1 -1
  120. package/dist/gs/syscall/index.d.ts +6 -6
  121. package/dist/gs/syscall/index.js +34 -28
  122. package/dist/gs/syscall/index.js.map +1 -1
  123. package/dist/gs/unsafe/unsafe.js.map +1 -1
  124. package/gs/builtin/slice.ts +2 -1
  125. package/gs/github.com/pkg/errors/errors.ts +408 -238
  126. package/gs/github.com/pkg/errors/go113.ts +5 -6
  127. package/gs/github.com/pkg/errors/index.ts +12 -3
  128. package/gs/github.com/pkg/errors/stack.ts +107 -105
  129. package/gs/internal/abi/index.ts +37 -0
  130. package/gs/internal/bytealg/index.ts +34 -0
  131. package/gs/internal/byteorder/index.ts +5 -5
  132. package/gs/math/abs.gs.test.ts +1 -1
  133. package/gs/math/acosh.gs.test.ts +4 -2
  134. package/gs/math/asin.gs.test.ts +1 -1
  135. package/gs/math/asinh.gs.test.ts +7 -3
  136. package/gs/math/atan.gs.test.ts +1 -1
  137. package/gs/math/atan2.gs.test.ts +17 -9
  138. package/gs/math/atanh.gs.test.ts +1 -1
  139. package/gs/math/bits.gs.test.ts +1 -1
  140. package/gs/math/cbrt.gs.test.ts +1 -1
  141. package/gs/math/const.gs.test.ts +34 -8
  142. package/gs/math/copysign.gs.test.ts +7 -3
  143. package/gs/math/dim.gs.test.ts +19 -7
  144. package/gs/math/erf.gs.test.ts +1 -1
  145. package/gs/math/erfinv.gs.test.ts +4 -2
  146. package/gs/math/exp.gs.test.ts +1 -1
  147. package/gs/math/expm1.gs.test.ts +6 -4
  148. package/gs/math/floor.gs.test.ts +17 -4
  149. package/gs/math/fma.gs.test.ts +53 -53
  150. package/gs/math/frexp.gs.test.ts +112 -117
  151. package/gs/math/gamma.gs.test.ts +1 -1
  152. package/gs/math/hypot.gs.test.ts +53 -53
  153. package/gs/math/index.ts +80 -44
  154. package/gs/math/j0.gs.test.ts +6 -2
  155. package/gs/math/j1.gs.test.ts +6 -2
  156. package/gs/math/jn.gs.test.ts +9 -5
  157. package/gs/math/ldexp.gs.test.ts +103 -86
  158. package/gs/math/lgamma.gs.test.ts +10 -10
  159. package/gs/math/log.gs.test.ts +1 -1
  160. package/gs/math/log10.gs.test.ts +1 -1
  161. package/gs/math/log1p.gs.test.ts +2 -2
  162. package/gs/math/logb.gs.test.ts +1 -1
  163. package/gs/math/mod.gs.test.ts +2 -2
  164. package/gs/math/modf.gs.test.ts +7 -7
  165. package/gs/math/nextafter.gs.test.ts +9 -7
  166. package/gs/math/pow.gs.test.ts +6 -4
  167. package/gs/math/pow10.gs.test.ts +1 -1
  168. package/gs/math/remainder.gs.test.ts +1 -1
  169. package/gs/math/signbit.gs.test.ts +1 -1
  170. package/gs/math/sin.gs.test.ts +1 -1
  171. package/gs/math/sincos.gs.test.ts +33 -14
  172. package/gs/math/sinh.gs.test.ts +1 -1
  173. package/gs/math/sqrt.gs.test.ts +1 -1
  174. package/gs/math/tan.gs.test.ts +3 -3
  175. package/gs/math/tanh.gs.test.ts +1 -1
  176. package/gs/os/index.ts +128 -19
  177. package/gs/reflect/ANALYSIS.md +278 -0
  178. package/gs/reflect/deepequal.ts +154 -0
  179. package/gs/reflect/function-types.test.ts +146 -0
  180. package/gs/reflect/godoc.txt +67 -0
  181. package/gs/reflect/index.ts +83 -0
  182. package/gs/reflect/iter.ts +44 -0
  183. package/gs/reflect/map.ts +81 -0
  184. package/gs/reflect/swapper.ts +52 -0
  185. package/gs/reflect/type.ts +1012 -0
  186. package/gs/reflect/types.ts +214 -0
  187. package/gs/reflect/value.ts +264 -0
  188. package/gs/reflect/visiblefields.ts +173 -0
  189. package/gs/strconv/index.ts +39 -6
  190. package/gs/strings/index.ts +7 -1
  191. package/gs/strings/replace.ts +1 -9
  192. package/gs/sync/atomic/index.ts +53 -4
  193. package/gs/syscall/index.ts +45 -37
  194. package/gs/unsafe/unsafe.ts +1 -1
  195. package/package.json +2 -1
  196. package/gs/internal/testlog/index.ts +0 -7
@@ -6,7 +6,9 @@ describe('Nextafter', () => {
6
6
  expect(Nextafter(1.0, 1.0)).toBe(1.0)
7
7
  expect(Nextafter(0.0, 0.0)).toBe(0.0)
8
8
  expect(Nextafter(-1.0, -1.0)).toBe(-1.0)
9
- expect(Nextafter(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
9
+ expect(Nextafter(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)).toBe(
10
+ Number.POSITIVE_INFINITY,
11
+ )
10
12
  })
11
13
 
12
14
  it('should return NaN when either input is NaN', () => {
@@ -18,7 +20,7 @@ describe('Nextafter', () => {
18
20
  it('should handle zero correctly', () => {
19
21
  const nextPos = Nextafter(0, 1)
20
22
  const nextNeg = Nextafter(0, -1)
21
-
23
+
22
24
  expect(nextPos).toBeGreaterThan(0)
23
25
  expect(nextNeg).toBeLessThan(0)
24
26
  expect(Math.abs(nextPos)).toBe(Number.MIN_VALUE)
@@ -70,7 +72,7 @@ describe('Nextafter32', () => {
70
72
  it('should handle zero correctly', () => {
71
73
  const nextPos = Nextafter32(0, 1)
72
74
  const nextNeg = Nextafter32(0, -1)
73
-
75
+
74
76
  expect(nextPos).toBeGreaterThan(0)
75
77
  expect(nextNeg).toBeLessThan(0)
76
78
  // For float32, the smallest positive value is different
@@ -82,7 +84,7 @@ describe('Nextafter32', () => {
82
84
  const x = 1.0
83
85
  const nextUp = Nextafter32(x, 2.0)
84
86
  const nextDown = Nextafter32(x, 0.0)
85
-
87
+
86
88
  expect(nextUp).toBeGreaterThan(x)
87
89
  expect(nextDown).toBeLessThan(x)
88
90
  })
@@ -91,7 +93,7 @@ describe('Nextafter32', () => {
91
93
  const x = 1.0
92
94
  const nextUp = Nextafter32(x, Number.POSITIVE_INFINITY)
93
95
  const nextDown = Nextafter32(x, 0.0)
94
-
96
+
95
97
  expect(nextUp).toBeGreaterThan(x)
96
98
  expect(nextDown).toBeLessThan(x)
97
99
  })
@@ -100,8 +102,8 @@ describe('Nextafter32', () => {
100
102
  const x = -1.0
101
103
  const nextUp = Nextafter32(x, 0.0)
102
104
  const nextDown = Nextafter32(x, -2.0)
103
-
105
+
104
106
  expect(nextUp).toBeGreaterThan(x)
105
107
  expect(nextDown).toBeLessThan(x)
106
108
  })
107
- })
109
+ })
@@ -37,7 +37,7 @@ describe('Pow', () => {
37
37
  expect(Pow(2, Number.NEGATIVE_INFINITY)).toBe(0)
38
38
  expect(Pow(0.5, Number.POSITIVE_INFINITY)).toBe(0)
39
39
  expect(Pow(0.5, Number.NEGATIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY)
40
-
40
+
41
41
  expect(Pow(Number.POSITIVE_INFINITY, 1)).toBe(Number.POSITIVE_INFINITY)
42
42
  expect(Pow(Number.POSITIVE_INFINITY, -1)).toBe(0)
43
43
  expect(Pow(Number.NEGATIVE_INFINITY, 2)).toBe(Number.POSITIVE_INFINITY)
@@ -59,7 +59,7 @@ describe('Pow', () => {
59
59
 
60
60
  it('should handle fractional exponents', () => {
61
61
  expect(Pow(4, 0.5)).toBe(2)
62
- expect(Pow(8, 1/3)).toBeCloseTo(2, 15)
62
+ expect(Pow(8, 1 / 3)).toBeCloseTo(2, 15)
63
63
  expect(Pow(16, 0.25)).toBe(2)
64
64
  })
65
65
  })
@@ -69,7 +69,9 @@ describe('pow', () => {
69
69
  expect(pow(2, 3)).toBe(Pow(2, 3))
70
70
  expect(pow(0, 1)).toBe(Pow(0, 1))
71
71
  expect(pow(-2, 2)).toBe(Pow(-2, 2))
72
- expect(pow(Number.POSITIVE_INFINITY, 1)).toBe(Pow(Number.POSITIVE_INFINITY, 1))
72
+ expect(pow(Number.POSITIVE_INFINITY, 1)).toBe(
73
+ Pow(Number.POSITIVE_INFINITY, 1),
74
+ )
73
75
  })
74
76
  })
75
77
 
@@ -100,4 +102,4 @@ describe('isOddInt', () => {
100
102
  expect(isOddInt(1 << 53)).toBe(false) // too large
101
103
  expect(isOddInt((1 << 53) - 1)).toBe(true) // largest odd integer
102
104
  })
103
- })
105
+ })
@@ -55,4 +55,4 @@ describe('Pow10', () => {
55
55
  expect(Pow10(n)).toBeCloseTo(Math.pow(10, n), 15)
56
56
  }
57
57
  })
58
- })
58
+ })
@@ -67,4 +67,4 @@ describe('remainder', () => {
67
67
  expect(Number.isNaN(remainder(Number.NaN, 3))).toBe(true)
68
68
  expect(Number.isNaN(remainder(5, 0))).toBe(true)
69
69
  })
70
- })
70
+ })
@@ -30,4 +30,4 @@ describe('Signbit', () => {
30
30
  expect(Signbit(Number.NaN)).toBe(false)
31
31
  expect(Signbit(-Number.NaN)).toBe(false) // NaN doesn't have a sign
32
32
  })
33
- })
33
+ })
@@ -80,4 +80,4 @@ describe('cos', () => {
80
80
  expect(cos(-Math.PI / 2)).toBe(Cos(-Math.PI / 2))
81
81
  expect(cos(Math.PI)).toBe(Cos(Math.PI))
82
82
  })
83
- })
83
+ })
@@ -6,7 +6,7 @@ describe('Sincos', () => {
6
6
  const [sin, cos] = Sincos(0)
7
7
  expect(sin).toBe(0)
8
8
  expect(cos).toBe(1)
9
-
9
+
10
10
  const [sinNeg, cosNeg] = Sincos(-0)
11
11
  expect(sinNeg).toBe(-0)
12
12
  expect(cosNeg).toBe(1)
@@ -16,15 +16,15 @@ describe('Sincos', () => {
16
16
  const [sin1, cos1] = Sincos(Math.PI / 2)
17
17
  expect(sin1).toBeCloseTo(1, 15)
18
18
  expect(cos1).toBeCloseTo(0, 15)
19
-
19
+
20
20
  const [sin2, cos2] = Sincos(-Math.PI / 2)
21
21
  expect(sin2).toBeCloseTo(-1, 15)
22
22
  expect(cos2).toBeCloseTo(0, 15)
23
-
23
+
24
24
  const [sin3, cos3] = Sincos(Math.PI)
25
25
  expect(sin3).toBeCloseTo(0, 15)
26
26
  expect(cos3).toBeCloseTo(-1, 15)
27
-
27
+
28
28
  const [sin4, cos4] = Sincos(-Math.PI)
29
29
  expect(sin4).toBeCloseTo(0, 15)
30
30
  expect(cos4).toBeCloseTo(-1, 15)
@@ -34,11 +34,11 @@ describe('Sincos', () => {
34
34
  const [sin1, cos1] = Sincos(Math.PI / 6)
35
35
  expect(sin1).toBeCloseTo(0.5, 15)
36
36
  expect(cos1).toBeCloseTo(Math.sqrt(3) / 2, 15)
37
-
37
+
38
38
  const [sin2, cos2] = Sincos(Math.PI / 4)
39
39
  expect(sin2).toBeCloseTo(Math.sqrt(2) / 2, 15)
40
40
  expect(cos2).toBeCloseTo(Math.sqrt(2) / 2, 15)
41
-
41
+
42
42
  const [sin3, cos3] = Sincos(Math.PI / 3)
43
43
  expect(sin3).toBeCloseTo(Math.sqrt(3) / 2, 15)
44
44
  expect(cos3).toBeCloseTo(0.5, 15)
@@ -48,19 +48,29 @@ describe('Sincos', () => {
48
48
  const [sin1, cos1] = Sincos(Number.POSITIVE_INFINITY)
49
49
  expect(Number.isNaN(sin1)).toBe(true)
50
50
  expect(Number.isNaN(cos1)).toBe(true)
51
-
51
+
52
52
  const [sin2, cos2] = Sincos(Number.NEGATIVE_INFINITY)
53
53
  expect(Number.isNaN(sin2)).toBe(true)
54
54
  expect(Number.isNaN(cos2)).toBe(true)
55
-
55
+
56
56
  const [sin3, cos3] = Sincos(Number.NaN)
57
57
  expect(Number.isNaN(sin3)).toBe(true)
58
58
  expect(Number.isNaN(cos3)).toBe(true)
59
59
  })
60
60
 
61
61
  it('should satisfy the Pythagorean identity', () => {
62
- const testValues = [0, Math.PI / 6, Math.PI / 4, Math.PI / 3, Math.PI / 2, Math.PI, 1.5, 2.7, -1.2]
63
-
62
+ const testValues = [
63
+ 0,
64
+ Math.PI / 6,
65
+ Math.PI / 4,
66
+ Math.PI / 3,
67
+ Math.PI / 2,
68
+ Math.PI,
69
+ 1.5,
70
+ 2.7,
71
+ -1.2,
72
+ ]
73
+
64
74
  for (const x of testValues) {
65
75
  const [sin, cos] = Sincos(x)
66
76
  expect(sin * sin + cos * cos).toBeCloseTo(1, 14)
@@ -72,7 +82,7 @@ describe('Sincos', () => {
72
82
  const [sin1, cos1] = Sincos(x)
73
83
  const [sin2, cos2] = Sincos(x + 2 * Math.PI)
74
84
  const [sin3, cos3] = Sincos(x + 4 * Math.PI)
75
-
85
+
76
86
  expect(sin1).toBeCloseTo(sin2, 14)
77
87
  expect(cos1).toBeCloseTo(cos2, 14)
78
88
  expect(sin1).toBeCloseTo(sin3, 14)
@@ -80,12 +90,21 @@ describe('Sincos', () => {
80
90
  })
81
91
 
82
92
  it('should match individual Math.sin and Math.cos calls', () => {
83
- const testValues = [0, Math.PI / 6, Math.PI / 4, Math.PI / 3, Math.PI / 2, Math.PI, 1.5, -1.2]
84
-
93
+ const testValues = [
94
+ 0,
95
+ Math.PI / 6,
96
+ Math.PI / 4,
97
+ Math.PI / 3,
98
+ Math.PI / 2,
99
+ Math.PI,
100
+ 1.5,
101
+ -1.2,
102
+ ]
103
+
85
104
  for (const x of testValues) {
86
105
  const [sin, cos] = Sincos(x)
87
106
  expect(sin).toBeCloseTo(Math.sin(x), 15)
88
107
  expect(cos).toBeCloseTo(Math.cos(x), 15)
89
108
  }
90
109
  })
91
- })
110
+ })
@@ -63,4 +63,4 @@ describe('cosh', () => {
63
63
  expect(cosh(-1)).toBe(Cosh(-1))
64
64
  expect(cosh(Number.POSITIVE_INFINITY)).toBe(Cosh(Number.POSITIVE_INFINITY))
65
65
  })
66
- })
66
+ })
@@ -46,4 +46,4 @@ describe('sqrt', () => {
46
46
  expect(sqrt(9)).toBe(Sqrt(9))
47
47
  expect(Number.isNaN(sqrt(-1))).toBe(Number.isNaN(Sqrt(-1)))
48
48
  })
49
- })
49
+ })
@@ -22,8 +22,8 @@ describe('Tan', () => {
22
22
  it('should approach infinity near asymptotes', () => {
23
23
  const nearPiOver2 = Math.PI / 2 - 1e-10
24
24
  expect(Math.abs(Tan(nearPiOver2))).toBeGreaterThan(1e9)
25
-
26
- const near3PiOver2 = 3 * Math.PI / 2 - 1e-10
25
+
26
+ const near3PiOver2 = (3 * Math.PI) / 2 - 1e-10
27
27
  expect(Math.abs(Tan(near3PiOver2))).toBeGreaterThan(1e9)
28
28
  })
29
29
 
@@ -47,4 +47,4 @@ describe('tan', () => {
47
47
  expect(tan(Math.PI)).toBe(Tan(Math.PI))
48
48
  expect(Number.isNaN(tan(Number.NaN))).toBe(Number.isNaN(Tan(Number.NaN)))
49
49
  })
50
- })
50
+ })
@@ -49,4 +49,4 @@ describe('tanh', () => {
49
49
  expect(tanh(-1)).toBe(Tanh(-1))
50
50
  expect(tanh(Number.POSITIVE_INFINITY)).toBe(Tanh(Number.POSITIVE_INFINITY))
51
51
  })
52
- })
52
+ })
package/gs/os/index.ts CHANGED
@@ -1,19 +1,128 @@
1
- export { CopyFS, ReadDir } from "./dir.gs.js"
2
- export { Clearenv, Environ, Expand, ExpandEnv, Getenv, LookupEnv, Setenv, Unsetenv } from "./env.gs.js"
3
- export { ErrClosed, ErrDeadlineExceeded, ErrExist, ErrInvalid, ErrNoDeadline, ErrNotExist, ErrPermission, ErrUnimplemented, IsExist, IsNotExist, IsPermission, IsTimeout, NewSyscallError, PathError, SyscallError } from "./error.gs.js"
4
- export { ErrProcessDone, FindProcess, Getpid, Getppid, ProcAttr, Process, Signal, StartProcess } from "./exec.gs.js"
5
- export { Interrupt, Kill, ProcessState } from "./exec_posix.gs.js"
6
- export { Executable } from "./executable.gs.js"
7
- export { Chdir, Chmod, Create, DirFS, Mkdir, Open, OpenFile, ReadFile, Rename, WriteFile, MkdirAll, RemoveAll } from "./file_js.gs.js"
8
- export { LinkError, O_APPEND, O_CREATE, O_EXCL, O_RDONLY, O_RDWR, O_SYNC, O_TRUNC, O_WRONLY, Readlink, SEEK_CUR, SEEK_END, SEEK_SET, TempDir, UserCacheDir, UserConfigDir, UserHomeDir } from "./file_constants_js.gs.js"
9
- export { DevNull, Link, NewFile, Remove, Stderr, Stdin, Stdout, Symlink, Truncate } from "./file_unix_js.gs.js"
10
- export { Chown, Chtimes, Lchown } from "./file_posix_js.gs.js"
11
- export { Getwd } from "./getwd_js.gs.js"
12
- export { IsPathSeparator, PathListSeparator, PathSeparator } from "./path_unix.gs.js"
13
- export { Pipe } from "./pipe_wasm.gs.js"
14
- export { Args, Exit, Getegid, Geteuid, Getgid, Getgroups, Getuid } from "./proc.gs.js"
15
- export { OpenInRoot, OpenRoot, Root } from "./root_js.gs.js"
16
- export { Lstat, Stat } from "./stat_js.gs.js"
17
- export { Hostname } from "./sys.gs.js"
18
- export { CreateTemp, MkdirTemp } from "./tempfile.gs.js"
19
- export { DirEntry, File, FileInfo, FileMode, Getpagesize, ModeAppend, ModeCharDevice, ModeDevice, ModeDir, ModeExclusive, ModeIrregular, ModeNamedPipe, ModePerm, ModeSetgid, ModeSetuid, ModeSocket, ModeSticky, ModeSymlink, ModeTemporary, ModeType, SameFile } from "./types_js.gs.js"
1
+ export { CopyFS, ReadDir } from './dir.gs.js'
2
+ export {
3
+ Clearenv,
4
+ Environ,
5
+ Expand,
6
+ ExpandEnv,
7
+ Getenv,
8
+ LookupEnv,
9
+ Setenv,
10
+ Unsetenv,
11
+ } from './env.gs.js'
12
+ export {
13
+ ErrClosed,
14
+ ErrDeadlineExceeded,
15
+ ErrExist,
16
+ ErrInvalid,
17
+ ErrNoDeadline,
18
+ ErrNotExist,
19
+ ErrPermission,
20
+ ErrUnimplemented,
21
+ IsExist,
22
+ IsNotExist,
23
+ IsPermission,
24
+ IsTimeout,
25
+ NewSyscallError,
26
+ PathError,
27
+ SyscallError,
28
+ } from './error.gs.js'
29
+ export {
30
+ ErrProcessDone,
31
+ FindProcess,
32
+ Getpid,
33
+ Getppid,
34
+ ProcAttr,
35
+ Process,
36
+ Signal,
37
+ StartProcess,
38
+ } from './exec.gs.js'
39
+ export { Interrupt, Kill, ProcessState } from './exec_posix.gs.js'
40
+ export { Executable } from './executable.gs.js'
41
+ export {
42
+ Chdir,
43
+ Chmod,
44
+ Create,
45
+ DirFS,
46
+ Mkdir,
47
+ Open,
48
+ OpenFile,
49
+ ReadFile,
50
+ Rename,
51
+ WriteFile,
52
+ MkdirAll,
53
+ RemoveAll,
54
+ } from './file_js.gs.js'
55
+ export {
56
+ LinkError,
57
+ O_APPEND,
58
+ O_CREATE,
59
+ O_EXCL,
60
+ O_RDONLY,
61
+ O_RDWR,
62
+ O_SYNC,
63
+ O_TRUNC,
64
+ O_WRONLY,
65
+ Readlink,
66
+ SEEK_CUR,
67
+ SEEK_END,
68
+ SEEK_SET,
69
+ TempDir,
70
+ UserCacheDir,
71
+ UserConfigDir,
72
+ UserHomeDir,
73
+ } from './file_constants_js.gs.js'
74
+ export {
75
+ DevNull,
76
+ Link,
77
+ NewFile,
78
+ Remove,
79
+ Stderr,
80
+ Stdin,
81
+ Stdout,
82
+ Symlink,
83
+ Truncate,
84
+ } from './file_unix_js.gs.js'
85
+ export { Chown, Chtimes, Lchown } from './file_posix_js.gs.js'
86
+ export { Getwd } from './getwd_js.gs.js'
87
+ export {
88
+ IsPathSeparator,
89
+ PathListSeparator,
90
+ PathSeparator,
91
+ } from './path_unix.gs.js'
92
+ export { Pipe } from './pipe_wasm.gs.js'
93
+ export {
94
+ Args,
95
+ Exit,
96
+ Getegid,
97
+ Geteuid,
98
+ Getgid,
99
+ Getgroups,
100
+ Getuid,
101
+ } from './proc.gs.js'
102
+ export { OpenInRoot, OpenRoot, Root } from './root_js.gs.js'
103
+ export { Lstat, Stat } from './stat_js.gs.js'
104
+ export { Hostname } from './sys.gs.js'
105
+ export { CreateTemp, MkdirTemp } from './tempfile.gs.js'
106
+ export {
107
+ DirEntry,
108
+ File,
109
+ FileInfo,
110
+ FileMode,
111
+ Getpagesize,
112
+ ModeAppend,
113
+ ModeCharDevice,
114
+ ModeDevice,
115
+ ModeDir,
116
+ ModeExclusive,
117
+ ModeIrregular,
118
+ ModeNamedPipe,
119
+ ModePerm,
120
+ ModeSetgid,
121
+ ModeSetuid,
122
+ ModeSocket,
123
+ ModeSticky,
124
+ ModeSymlink,
125
+ ModeTemporary,
126
+ ModeType,
127
+ SameFile,
128
+ } from './types_js.gs.js'
@@ -0,0 +1,278 @@
1
+ # GoScript Reflect Package Implementation Analysis
2
+
3
+ This document analyzes the implementation status of the `gs/reflect/` package compared to the Go standard library `reflect` package as specified in `godoc.txt`.
4
+
5
+ ## Constants
6
+
7
+ ### `const Ptr = Pointer`
8
+ - **Status**: ✅ **IMPLEMENTED**
9
+ - **Location**: `type.ts`
10
+ - **Notes**: Exported in `index.ts` as alias
11
+
12
+ ## Functions
13
+
14
+ ### `func Copy(dst, src Value) int`
15
+ - **Status**: ✅ **IMPLEMENTED**
16
+ - **Location**: `value.ts:63-78`
17
+ - **Notes**: Correctly implemented with proper array extraction and copying logic
18
+
19
+ ### `func DeepEqual(x, y any) bool`
20
+ - **Status**: ✅ **IMPLEMENTED**
21
+ - **Location**: `deepequal.ts:333-345`
22
+ - **Notes**: Full implementation with cycle detection, supports all Go types. Helper function `deepValueEqual` handles the recursive comparison logic.
23
+
24
+ ### `func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)`
25
+ - **Status**: ✅ **IMPLEMENTED**
26
+ - **Location**: `value.ts:184-227`
27
+ - **Notes**: Full implementation with support for channel receive operations, default cases, and proper value extraction from channels with queued values
28
+
29
+ ### `func Swapper(slice any) func(i, j int)`
30
+ - **Status**: ✅ **IMPLEMENTED**
31
+ - **Location**: `swapper.ts:5-46`
32
+ - **Notes**: Correctly implemented with support for regular arrays and GoScript slice objects
33
+
34
+ ## Types
35
+
36
+ ### `type ChanDir int`
37
+ - **Status**: ✅ **IMPLEMENTED**
38
+ - **Location**: `types.ts:35-50`
39
+ - **Notes**: Class implementation with proper constants
40
+
41
+ #### Constants: `const RecvDir ChanDir = 1 << iota ...`
42
+ - **RecvDir, SendDir, BothDir**: ✅ **IMPLEMENTED** in `types.ts:51-53`
43
+
44
+ ### `type Kind uint`
45
+ - **Status**: ✅ **IMPLEMENTED**
46
+ - **Location**: `type.ts:69-100`
47
+ - **Notes**: Class implementation with `String()` method
48
+
49
+ #### Kind Constants: `const Invalid Kind = iota ...`
50
+ - **Status**: ✅ **IMPLEMENTED**
51
+ - **Location**: `type.ts:103-127`
52
+ - **Notes**: All 27 kind constants properly defined (Invalid through UnsafePointer)
53
+
54
+ ### `type MapIter struct{ ... }`
55
+ - **Status**: ✅ **IMPLEMENTED**
56
+ - **Location**: `types.ts:139-148` and `map.ts:35-64`
57
+ - **Notes**: Interface defined in types.ts, concrete implementation in map.ts
58
+
59
+ ### `type Method struct{ ... }`
60
+ - **Status**: ✅ **IMPLEMENTED**
61
+ - **Location**: `types.ts:95-100`
62
+ - **Notes**: Interface definition only, methods not implemented
63
+
64
+ ### `type SelectCase struct{ ... }`
65
+ - **Status**: ✅ **IMPLEMENTED**
66
+ - **Location**: `types.ts:116-120`
67
+ - **Notes**: Type defined and used by Select function implementation
68
+
69
+ ### `type SelectDir int`
70
+ - **Status**: ✅ **IMPLEMENTED**
71
+ - **Location**: `types.ts:122-131`
72
+ - **Notes**: Class with constants SelectSend, SelectRecv, SelectDefault
73
+
74
+ ### `type SliceHeader struct{ ... }`
75
+ - **Status**: ✅ **IMPLEMENTED**
76
+ - **Location**: `types.ts:133-137`
77
+ - **Notes**: Interface definition
78
+
79
+ ### `type StringHeader struct{ ... }`
80
+ - **Status**: ✅ **IMPLEMENTED**
81
+ - **Location**: `types.ts:139-142`
82
+ - **Notes**: Interface definition
83
+
84
+ ### `type StructField struct{ ... }`
85
+ - **Status**: ✅ **IMPLEMENTED**
86
+ - **Location**: `types.ts:57-84`
87
+ - **Notes**: Full class implementation with clone method
88
+
89
+ #### `func VisibleFields(t Type) []StructField`
90
+ - **Status**: ✅ **IMPLEMENTED**
91
+ - **Location**: `visiblefields.ts:14-42`
92
+ - **Notes**: Complete implementation with proper field walking logic
93
+
94
+ ### `type StructTag string`
95
+ - **Status**: ✅ **IMPLEMENTED**
96
+ - **Location**: `types.ts:86-104`
97
+ - **Notes**: Class with `Get(key string) string` method for tag parsing
98
+
99
+ ### `type Type interface{ ... }`
100
+ - **Status**: ✅ **IMPLEMENTED**
101
+ - **Location**: `type.ts:128-151`
102
+ - **Notes**: Interface definition with all required methods
103
+
104
+ #### Type Constructor Functions:
105
+
106
+ ##### `func ArrayOf(length int, elem Type) Type`
107
+ - **Status**: ✅ **IMPLEMENTED**
108
+ - **Location**: `type.ts:764`
109
+ - **Notes**: Uses internal `ArrayType` class
110
+
111
+ ##### `func ChanOf(dir ChanDir, t Type) Type`
112
+ - **Status**: ✅ **IMPLEMENTED**
113
+ - **Location**: `type.ts:838-842` and `type.ts:593-644`
114
+ - **Notes**: Uses internal `ChannelType` class with proper direction formatting (chan T, <-chan T, chan<- T)
115
+
116
+ ##### `func FuncOf(in, out []Type, variadic bool) Type`
117
+ - **Status**: ❌ **NOT IMPLEMENTED**
118
+ - **Notes**: No function type constructor found
119
+
120
+ ##### `func MapOf(key, elem Type) Type`
121
+ - **Status**: ✅ **IMPLEMENTED**
122
+ - **Location**: `type.ts:774` and `map.ts:7-32`
123
+ - **Notes**: Multiple implementations, uses internal `MapType` class
124
+
125
+ ##### `func PointerTo(t Type) Type`
126
+ - **Status**: ✅ **IMPLEMENTED**
127
+ - **Location**: `type.ts:768`
128
+ - **Notes**: Uses internal `PointerType` class
129
+
130
+ ##### `func PtrTo(t Type) Type`
131
+ - **Status**: ✅ **IMPLEMENTED**
132
+ - **Location**: `type.ts:772`
133
+ - **Notes**: Alias for PointerTo
134
+
135
+ ##### `func SliceOf(t Type) Type`
136
+ - **Status**: ✅ **IMPLEMENTED**
137
+ - **Location**: `type.ts:766`
138
+ - **Notes**: Uses internal `SliceType` class
139
+
140
+ ##### `func StructOf(fields []StructField) Type`
141
+ - **Status**: ❌ **NOT IMPLEMENTED**
142
+ - **Notes**: No struct type constructor found
143
+
144
+ ##### `func TypeFor[T any]() Type`
145
+ - **Status**: ❌ **NOT IMPLEMENTED**
146
+ - **Notes**: Generic type function not implemented (TypeScript limitation)
147
+
148
+ ##### `func TypeOf(i any) Type`
149
+ - **Status**: ✅ **IMPLEMENTED**
150
+ - **Location**: `type.ts:758`
151
+ - **Notes**: Comprehensive implementation with support for all JavaScript and GoScript types
152
+
153
+ ### `type Value struct{ ... }`
154
+ - **Status**: ✅ **IMPLEMENTED**
155
+ - **Location**: `type.ts:153-351`
156
+ - **Notes**: Comprehensive class implementation with most methods including Send for channel operations
157
+
158
+ #### Value Constructor Functions:
159
+
160
+ ##### `func Append(s Value, x ...Value) Value`
161
+ - **Status**: ⚠️ **PARTIALLY IMPLEMENTED**
162
+ - **Location**: `value.ts:145-162`
163
+ - **Notes**: Only handles single value append, not variadic
164
+
165
+ ##### `func AppendSlice(s, t Value) Value`
166
+ - **Status**: ❌ **NOT IMPLEMENTED**
167
+ - **Notes**: No implementation found
168
+
169
+ ##### `func Indirect(v Value) Value`
170
+ - **Status**: ✅ **IMPLEMENTED**
171
+ - **Location**: `value.ts:96-108`
172
+ - **Notes**: Correctly handles pointer dereferencing
173
+
174
+ ##### `func MakeChan(typ Type, buffer int) Value`
175
+ - **Status**: ✅ **IMPLEMENTED**
176
+ - **Location**: `value.ts:164-182`
177
+ - **Notes**: Creates channels using builtin.makeChannel with proper element type zero values
178
+
179
+ ##### `func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value`
180
+ - **Status**: ⚠️ **STUBBED**
181
+ - **Location**: `makefunc.ts:83-107`
182
+ - **Notes**: Function exists but returns empty Value, complex stub implementation
183
+
184
+ ##### `func MakeMap(typ Type) Value`
185
+ - **Status**: ✅ **IMPLEMENTED**
186
+ - **Location**: `value.ts:125-133` and `map.ts:67-71`
187
+ - **Notes**: Multiple implementations, creates JavaScript Map
188
+
189
+ ##### `func MakeMapWithSize(typ Type, n int) Value`
190
+ - **Status**: ✅ **IMPLEMENTED**
191
+ - **Location**: `map.ts:73-76`
192
+ - **Notes**: Ignores size parameter (JavaScript Map limitation)
193
+
194
+ ##### `func MakeSlice(typ Type, len, cap int) Value`
195
+ - **Status**: ✅ **IMPLEMENTED**
196
+ - **Location**: `value.ts:111-124`
197
+ - **Notes**: Creates array with proper length and zero values
198
+
199
+ ##### `func New(typ Type) Value`
200
+ - **Status**: ✅ **IMPLEMENTED**
201
+ - **Location**: `value.ts:110-118`
202
+ - **Notes**: Returns pointer to zero value
203
+
204
+ ##### `func NewAt(typ Type, p unsafe.Pointer) Value`
205
+ - **Status**: ❌ **NOT IMPLEMENTED**
206
+ - **Notes**: No unsafe pointer implementation
207
+
208
+ ##### `func SliceAt(typ Type, p unsafe.Pointer, n int) Value`
209
+ - **Status**: ❌ **NOT IMPLEMENTED**
210
+ - **Notes**: No unsafe pointer implementation
211
+
212
+ ##### `func ValueOf(i any) Value`
213
+ - **Status**: ✅ **IMPLEMENTED**
214
+ - **Location**: `type.ts:760`
215
+ - **Notes**: Creates Value from any JavaScript/GoScript value
216
+
217
+ ##### `func Zero(typ Type) Value`
218
+ - **Status**: ✅ **IMPLEMENTED**
219
+ - **Location**: `value.ts:20-50`
220
+ - **Notes**: Returns appropriate zero values for all basic types
221
+
222
+ ### `type ValueError struct{ ... }`
223
+ - **Status**: ✅ **IMPLEMENTED**
224
+ - **Location**: `types.ts:178-208`
225
+ - **Notes**: Extends Error class with Kind and Method fields
226
+
227
+ ## Channel Operations
228
+
229
+ ### Channel Type System
230
+ - **Status**: ✅ **IMPLEMENTED**
231
+ - **Location**: `type.ts:593-644`
232
+ - **Notes**: `ChannelType` class supports all channel directions (BothDir, SendDir, RecvDir) with proper string formatting
233
+
234
+ ### Channel Creation and Operations
235
+ - **`MakeChan`**: ✅ **IMPLEMENTED** - Creates channels with proper buffering support
236
+ - **`ChanOf`**: ✅ **IMPLEMENTED** - Creates channel types with direction support
237
+ - **`Value.Send`**: ✅ **IMPLEMENTED** - Sends values to channels using internal queue mechanism
238
+ - **`Select`**: ✅ **IMPLEMENTED** - Handles channel selection with receive operations and default cases
239
+
240
+ ### Channel Integration
241
+ - **Status**: ✅ **FULLY INTEGRATED**
242
+ - **Location**: `index.ts` exports all channel-related functions
243
+ - **Notes**: Channel operations are fully integrated into the reflect package and pass compliance tests
244
+
245
+ ## Missing/Stubbed Implementations
246
+
247
+ ### Major Missing Features:
248
+ 1. **Unsafe pointer operations**: `NewAt`, `SliceAt`
249
+ 2. **Function type construction**: `FuncOf`
250
+ 3. **Struct type construction**: `StructOf`
251
+ 4. **Generic type support**: `TypeFor[T any]()`
252
+ 5. **Variadic append**: `AppendSlice`, variadic `Append`
253
+
254
+ ### Stubbed Files:
255
+ 1. **`badlinkname.ts`**: Contains stub implementations for Go runtime linkname functions
256
+ 2. **`abi.ts`**: Contains stub implementations for ABI-related functionality
257
+ 3. **`makefunc.ts`**: Partially implemented but returns empty values
258
+
259
+ ### Internal Implementation Files:
260
+ 1. **`iter.ts`**: Contains range iteration support for numeric types
261
+ 2. **Test file**: `function-types.test.ts` shows good test coverage for function type detection
262
+
263
+ ## Known Issues
264
+
265
+ ### Go Reflect Package Bug (from godoc.txt)
266
+ The official Go reflect package has a known bug where `FieldByName` and related functions consider struct field names equal if the names are equal, even if they are unexported names from different packages. This affects the behavior when a struct contains multiple fields with the same name from different embedded packages. This issue is documented in https://golang.org/issue/4876.
267
+
268
+ **GoScript Implementation**: Since the current implementation has limited struct field operations, this bug may not be present, but should be considered if implementing more comprehensive struct field access methods.
269
+
270
+ ## Overall Assessment
271
+
272
+ The GoScript reflect package has a **comprehensive foundation** with most core functionality implemented:
273
+
274
+ - ✅ **Strong**: Type system, Value operations, basic constructors, deep equality, **channel operations**
275
+ - ⚠️ **Partial**: Function reflection, method operations
276
+ - ❌ **Missing**: Unsafe operations, some type constructors
277
+
278
+ The implementation appears designed for JavaScript/TypeScript interoperability rather than full Go runtime compatibility, which explains the absence of unsafe operations and some low-level features. **Channel operations are now fully implemented and tested**, making this a robust reflect package for GoScript's use cases.