goscript 0.0.36 → 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 (376) 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/expr-call.go +26 -0
  5. package/compiler/lit.go +83 -0
  6. package/compiler/protobuf.go +2 -2
  7. package/compiler/spec-value.go +3 -3
  8. package/compiler/spec.go +7 -4
  9. package/compiler/stmt-assign.go +1 -1
  10. package/compiler/stmt.go +26 -8
  11. package/dist/gs/builtin/slice.js +2 -1
  12. package/dist/gs/builtin/slice.js.map +1 -1
  13. package/dist/gs/github.com/pkg/errors/errors.d.ts +1 -1
  14. package/dist/gs/github.com/pkg/errors/errors.js +182 -23
  15. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -1
  16. package/dist/gs/github.com/pkg/errors/go113.d.ts +1 -1
  17. package/dist/gs/github.com/pkg/errors/go113.js +1 -1
  18. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -1
  19. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -3
  20. package/dist/gs/github.com/pkg/errors/index.js +3 -3
  21. package/dist/gs/github.com/pkg/errors/index.js.map +1 -1
  22. package/dist/gs/github.com/pkg/errors/stack.d.ts +1 -1
  23. package/dist/gs/github.com/pkg/errors/stack.js +8 -5
  24. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -1
  25. package/dist/gs/internal/abi/index.d.ts +20 -0
  26. package/dist/gs/internal/abi/index.js +20 -0
  27. package/dist/gs/internal/abi/index.js.map +1 -0
  28. package/dist/gs/internal/bytealg/index.d.ts +2 -0
  29. package/dist/gs/internal/bytealg/index.js +33 -0
  30. package/dist/gs/internal/bytealg/index.js.map +1 -0
  31. package/dist/gs/internal/byteorder/index.d.ts +8 -0
  32. package/dist/gs/internal/byteorder/index.js +34 -0
  33. package/dist/gs/internal/byteorder/index.js.map +1 -0
  34. package/dist/gs/internal/testlog/index.d.ts +1 -0
  35. package/dist/gs/internal/testlog/index.js +5 -0
  36. package/dist/gs/internal/testlog/index.js.map +1 -0
  37. package/dist/gs/math/index.d.ts +44 -44
  38. package/dist/gs/math/index.js +44 -44
  39. package/dist/gs/math/index.js.map +1 -1
  40. package/dist/gs/os/dir.gs.d.ts +6 -0
  41. package/dist/gs/os/dir.gs.js +35 -0
  42. package/dist/gs/os/dir.gs.js.map +1 -0
  43. package/dist/gs/os/dir_unix.gs.d.ts +7 -0
  44. package/dist/gs/os/dir_unix.gs.js +113 -0
  45. package/dist/gs/os/dir_unix.gs.js.map +1 -0
  46. package/dist/gs/os/dirent_js.gs.d.ts +5 -0
  47. package/dist/gs/os/dirent_js.gs.js +20 -0
  48. package/dist/gs/os/dirent_js.gs.js.map +1 -0
  49. package/dist/gs/os/env.gs.d.ts +12 -0
  50. package/dist/gs/os/env.gs.js +157 -0
  51. package/dist/gs/os/env.gs.js.map +1 -0
  52. package/dist/gs/os/error.gs.d.ts +40 -0
  53. package/dist/gs/os/error.gs.js +158 -0
  54. package/dist/gs/os/error.gs.js.map +1 -0
  55. package/dist/gs/os/error_errno.gs.d.ts +1 -0
  56. package/dist/gs/os/error_errno.gs.js +5 -0
  57. package/dist/gs/os/error_errno.gs.js.map +1 -0
  58. package/dist/gs/os/exec.gs.d.ts +60 -0
  59. package/dist/gs/os/exec.gs.js +136 -0
  60. package/dist/gs/os/exec.gs.js.map +1 -0
  61. package/dist/gs/os/exec_nohandle.gs.d.ts +1 -0
  62. package/dist/gs/os/exec_nohandle.gs.js +2 -0
  63. package/dist/gs/os/exec_nohandle.gs.js.map +1 -0
  64. package/dist/gs/os/exec_posix.gs.d.ts +25 -0
  65. package/dist/gs/os/exec_posix.gs.js +67 -0
  66. package/dist/gs/os/exec_posix.gs.js.map +1 -0
  67. package/dist/gs/os/exec_unix.gs.d.ts +4 -0
  68. package/dist/gs/os/exec_unix.gs.js +46 -0
  69. package/dist/gs/os/exec_unix.gs.js.map +1 -0
  70. package/dist/gs/os/executable.gs.d.ts +2 -0
  71. package/dist/gs/os/executable.gs.js +16 -0
  72. package/dist/gs/os/executable.gs.js.map +1 -0
  73. package/dist/gs/os/executable_js.gs.d.ts +2 -0
  74. package/dist/gs/os/executable_js.gs.js +5 -0
  75. package/dist/gs/os/executable_js.gs.js.map +1 -0
  76. package/dist/gs/os/executable_wasm.gs.d.ts +2 -0
  77. package/dist/gs/os/executable_wasm.gs.js +6 -0
  78. package/dist/gs/os/executable_wasm.gs.js.map +1 -0
  79. package/dist/gs/os/file_constants_js.gs.d.ts +41 -0
  80. package/dist/gs/os/file_constants_js.gs.js +78 -0
  81. package/dist/gs/os/file_constants_js.gs.js.map +1 -0
  82. package/dist/gs/os/file_js.gs.d.ts +22 -0
  83. package/dist/gs/os/file_js.gs.js +73 -0
  84. package/dist/gs/os/file_js.gs.js.map +1 -0
  85. package/dist/gs/os/file_open_unix.gs.d.ts +6 -0
  86. package/dist/gs/os/file_open_unix.gs.js +10 -0
  87. package/dist/gs/os/file_open_unix.gs.js.map +1 -0
  88. package/dist/gs/os/file_posix_js.gs.d.ts +8 -0
  89. package/dist/gs/os/file_posix_js.gs.js +32 -0
  90. package/dist/gs/os/file_posix_js.gs.js.map +1 -0
  91. package/dist/gs/os/file_unix_js.gs.d.ts +27 -0
  92. package/dist/gs/os/file_unix_js.gs.js +64 -0
  93. package/dist/gs/os/file_unix_js.gs.js.map +1 -0
  94. package/dist/gs/os/getwd_js.gs.d.ts +6 -0
  95. package/dist/gs/os/getwd_js.gs.js +21 -0
  96. package/dist/gs/os/getwd_js.gs.js.map +1 -0
  97. package/dist/gs/os/index.d.ts +19 -0
  98. package/dist/gs/os/index.js +20 -0
  99. package/dist/gs/os/index.js.map +1 -0
  100. package/dist/gs/os/path.gs.d.ts +4 -0
  101. package/dist/gs/os/path.gs.js +32 -0
  102. package/dist/gs/os/path.gs.js.map +1 -0
  103. package/dist/gs/os/path_unix.gs.d.ts +4 -0
  104. package/dist/gs/os/path_unix.gs.js +40 -0
  105. package/dist/gs/os/path_unix.gs.js.map +1 -0
  106. package/dist/gs/os/pidfd_js.gs.d.ts +6 -0
  107. package/dist/gs/os/pidfd_js.gs.js +14 -0
  108. package/dist/gs/os/pidfd_js.gs.js.map +1 -0
  109. package/dist/gs/os/pipe_wasm.gs.d.ts +2 -0
  110. package/dist/gs/os/pipe_wasm.gs.js +14 -0
  111. package/dist/gs/os/pipe_wasm.gs.js.map +1 -0
  112. package/dist/gs/os/proc.gs.d.ts +11 -0
  113. package/dist/gs/os/proc.gs.js +68 -0
  114. package/dist/gs/os/proc.gs.js.map +1 -0
  115. package/dist/gs/os/proc_js.gs.d.ts +3 -0
  116. package/dist/gs/os/proc_js.gs.js +12 -0
  117. package/dist/gs/os/proc_js.gs.js.map +1 -0
  118. package/dist/gs/os/rawconn_js.gs.d.ts +10 -0
  119. package/dist/gs/os/rawconn_js.gs.js +26 -0
  120. package/dist/gs/os/rawconn_js.gs.js.map +1 -0
  121. package/dist/gs/os/removeall_js.gs.d.ts +2 -0
  122. package/dist/gs/os/removeall_js.gs.js +7 -0
  123. package/dist/gs/os/removeall_js.gs.js.map +1 -0
  124. package/dist/gs/os/root_js.gs.d.ts +23 -0
  125. package/dist/gs/os/root_js.gs.js +80 -0
  126. package/dist/gs/os/root_js.gs.js.map +1 -0
  127. package/dist/gs/os/root_nonwindows.gs.d.ts +2 -0
  128. package/dist/gs/os/root_nonwindows.gs.js +4 -0
  129. package/dist/gs/os/root_nonwindows.gs.js.map +1 -0
  130. package/dist/gs/os/root_noopenat.gs.d.ts +11 -0
  131. package/dist/gs/os/root_noopenat.gs.js +31 -0
  132. package/dist/gs/os/root_noopenat.gs.js.map +1 -0
  133. package/dist/gs/os/stat.gs.d.ts +24 -0
  134. package/dist/gs/os/stat.gs.js +20 -0
  135. package/dist/gs/os/stat.gs.js.map +1 -0
  136. package/dist/gs/os/stat_js.gs.d.ts +6 -0
  137. package/dist/gs/os/stat_js.gs.js +23 -0
  138. package/dist/gs/os/stat_js.gs.js.map +1 -0
  139. package/dist/gs/os/stat_unix_js.gs.d.ts +8 -0
  140. package/dist/gs/os/stat_unix_js.gs.js +16 -0
  141. package/dist/gs/os/stat_unix_js.gs.js.map +1 -0
  142. package/dist/gs/os/sticky_bsd.gs.d.ts +1 -0
  143. package/dist/gs/os/sticky_bsd.gs.js +3 -0
  144. package/dist/gs/os/sticky_bsd.gs.js.map +1 -0
  145. package/dist/gs/os/sys.gs.d.ts +2 -0
  146. package/dist/gs/os/sys.gs.js +10 -0
  147. package/dist/gs/os/sys.gs.js.map +1 -0
  148. package/dist/gs/os/sys_bsd.gs.d.ts +2 -0
  149. package/dist/gs/os/sys_bsd.gs.js +15 -0
  150. package/dist/gs/os/sys_bsd.gs.js.map +1 -0
  151. package/dist/gs/os/sys_js.gs.d.ts +2 -0
  152. package/dist/gs/os/sys_js.gs.js +6 -0
  153. package/dist/gs/os/sys_js.gs.js.map +1 -0
  154. package/dist/gs/os/tempfile.gs.d.ts +5 -0
  155. package/dist/gs/os/tempfile.gs.js +30 -0
  156. package/dist/gs/os/tempfile.gs.js.map +1 -0
  157. package/dist/gs/os/types.gs.d.ts +59 -0
  158. package/dist/gs/os/types.gs.js +123 -0
  159. package/dist/gs/os/types.gs.js.map +1 -0
  160. package/dist/gs/os/types_js.gs.d.ts +74 -0
  161. package/dist/gs/os/types_js.gs.js +147 -0
  162. package/dist/gs/os/types_js.gs.js.map +1 -0
  163. package/dist/gs/os/types_unix.gs.d.ts +40 -0
  164. package/dist/gs/os/types_unix.gs.js +87 -0
  165. package/dist/gs/os/types_unix.gs.js.map +1 -0
  166. package/dist/gs/os/wait_unimp.gs.d.ts +1 -0
  167. package/dist/gs/os/wait_unimp.gs.js +2 -0
  168. package/dist/gs/os/wait_unimp.gs.js.map +1 -0
  169. package/dist/gs/os/zero_copy_posix.gs.d.ts +4 -0
  170. package/dist/gs/os/zero_copy_posix.gs.js +27 -0
  171. package/dist/gs/os/zero_copy_posix.gs.js.map +1 -0
  172. package/dist/gs/os/zero_copy_stub.gs.d.ts +1 -0
  173. package/dist/gs/os/zero_copy_stub.gs.js +2 -0
  174. package/dist/gs/os/zero_copy_stub.gs.js.map +1 -0
  175. package/dist/gs/reflect/abi.d.ts +59 -0
  176. package/dist/gs/reflect/abi.gs.d.ts +59 -0
  177. package/dist/gs/reflect/abi.gs.js +79 -0
  178. package/dist/gs/reflect/abi.gs.js.map +1 -0
  179. package/dist/gs/reflect/abi.js +79 -0
  180. package/dist/gs/reflect/abi.js.map +1 -0
  181. package/dist/gs/reflect/badlinkname.d.ts +52 -0
  182. package/dist/gs/reflect/badlinkname.gs.d.ts +52 -0
  183. package/dist/gs/reflect/badlinkname.gs.js +72 -0
  184. package/dist/gs/reflect/badlinkname.gs.js.map +1 -0
  185. package/dist/gs/reflect/badlinkname.js +72 -0
  186. package/dist/gs/reflect/badlinkname.js.map +1 -0
  187. package/dist/gs/reflect/deepequal.d.ts +1 -0
  188. package/dist/gs/reflect/deepequal.gs.d.ts +25 -0
  189. package/dist/gs/reflect/deepequal.gs.js +308 -0
  190. package/dist/gs/reflect/deepequal.gs.js.map +1 -0
  191. package/dist/gs/reflect/deepequal.js +139 -0
  192. package/dist/gs/reflect/deepequal.js.map +1 -0
  193. package/dist/gs/reflect/float32reg_generic.gs.d.ts +2 -0
  194. package/dist/gs/reflect/float32reg_generic.gs.js +10 -0
  195. package/dist/gs/reflect/float32reg_generic.gs.js.map +1 -0
  196. package/dist/gs/reflect/index.d.ts +8 -0
  197. package/dist/gs/reflect/index.gs.d.ts +1 -0
  198. package/dist/gs/reflect/index.gs.js +3 -0
  199. package/dist/gs/reflect/index.gs.js.map +1 -0
  200. package/dist/gs/reflect/index.js +10 -0
  201. package/dist/gs/reflect/index.js.map +1 -0
  202. package/dist/gs/reflect/iter.d.ts +4 -0
  203. package/dist/gs/reflect/iter.gs.d.ts +3 -0
  204. package/dist/gs/reflect/iter.gs.js +24 -0
  205. package/dist/gs/reflect/iter.gs.js.map +1 -0
  206. package/dist/gs/reflect/iter.js +24 -0
  207. package/dist/gs/reflect/iter.js.map +1 -0
  208. package/dist/gs/reflect/makefunc.gs.d.ts +34 -0
  209. package/dist/gs/reflect/makefunc.gs.js +288 -0
  210. package/dist/gs/reflect/makefunc.gs.js.map +1 -0
  211. package/dist/gs/reflect/map.d.ts +14 -0
  212. package/dist/gs/reflect/map.js +70 -0
  213. package/dist/gs/reflect/map.js.map +1 -0
  214. package/dist/gs/reflect/map_swiss.gs.d.ts +14 -0
  215. package/dist/gs/reflect/map_swiss.gs.js +70 -0
  216. package/dist/gs/reflect/map_swiss.gs.js.map +1 -0
  217. package/dist/gs/reflect/reflect.gs.d.ts +132 -0
  218. package/dist/gs/reflect/reflect.gs.js +437 -0
  219. package/dist/gs/reflect/reflect.gs.js.map +1 -0
  220. package/dist/gs/reflect/swapper.d.ts +2 -0
  221. package/dist/gs/reflect/swapper.gs.d.ts +1 -0
  222. package/dist/gs/reflect/swapper.gs.js +32 -0
  223. package/dist/gs/reflect/swapper.gs.js.map +1 -0
  224. package/dist/gs/reflect/swapper.js +46 -0
  225. package/dist/gs/reflect/swapper.js.map +1 -0
  226. package/dist/gs/reflect/type.d.ts +126 -0
  227. package/dist/gs/reflect/type.gs.d.ts +4 -0
  228. package/dist/gs/reflect/type.gs.js +21 -0
  229. package/dist/gs/reflect/type.gs.js.map +1 -0
  230. package/dist/gs/reflect/type.js +825 -0
  231. package/dist/gs/reflect/type.js.map +1 -0
  232. package/dist/gs/reflect/types.d.ts +90 -0
  233. package/dist/gs/reflect/types.js +119 -0
  234. package/dist/gs/reflect/types.js.map +1 -0
  235. package/dist/gs/reflect/value.d.ts +13 -0
  236. package/dist/gs/reflect/value.gs.d.ts +4 -0
  237. package/dist/gs/reflect/value.gs.js +12 -0
  238. package/dist/gs/reflect/value.gs.js.map +1 -0
  239. package/dist/gs/reflect/value.js +201 -0
  240. package/dist/gs/reflect/value.js.map +1 -0
  241. package/dist/gs/reflect/visiblefields.d.ts +4 -0
  242. package/dist/gs/reflect/visiblefields.gs.d.ts +3 -0
  243. package/dist/gs/reflect/visiblefields.gs.js +123 -0
  244. package/dist/gs/reflect/visiblefields.gs.js.map +1 -0
  245. package/dist/gs/reflect/visiblefields.js +143 -0
  246. package/dist/gs/reflect/visiblefields.js.map +1 -0
  247. package/dist/gs/strconv/index.d.ts +6 -6
  248. package/dist/gs/strconv/index.js +6 -6
  249. package/dist/gs/strconv/index.js.map +1 -1
  250. package/dist/gs/strings/index.d.ts +1 -1
  251. package/dist/gs/strings/index.js +1 -1
  252. package/dist/gs/strings/index.js.map +1 -1
  253. package/dist/gs/strings/replace.js.map +1 -1
  254. package/dist/gs/sync/atomic/index.d.ts +4 -4
  255. package/dist/gs/sync/atomic/index.js +4 -4
  256. package/dist/gs/sync/atomic/index.js.map +1 -1
  257. package/dist/gs/syscall/index.d.ts +80 -0
  258. package/dist/gs/syscall/index.js +169 -0
  259. package/dist/gs/syscall/index.js.map +1 -0
  260. package/dist/gs/unsafe/unsafe.js.map +1 -1
  261. package/gs/builtin/slice.ts +2 -1
  262. package/gs/github.com/pkg/errors/errors.ts +408 -238
  263. package/gs/github.com/pkg/errors/go113.ts +5 -6
  264. package/gs/github.com/pkg/errors/index.ts +12 -3
  265. package/gs/github.com/pkg/errors/stack.ts +107 -105
  266. package/gs/internal/abi/index.ts +37 -0
  267. package/gs/internal/bytealg/index.ts +34 -0
  268. package/gs/internal/byteorder/index.ts +40 -0
  269. package/gs/math/abs.gs.test.ts +1 -1
  270. package/gs/math/acosh.gs.test.ts +4 -2
  271. package/gs/math/asin.gs.test.ts +1 -1
  272. package/gs/math/asinh.gs.test.ts +7 -3
  273. package/gs/math/atan.gs.test.ts +1 -1
  274. package/gs/math/atan2.gs.test.ts +17 -9
  275. package/gs/math/atanh.gs.test.ts +1 -1
  276. package/gs/math/bits.gs.test.ts +1 -1
  277. package/gs/math/cbrt.gs.test.ts +1 -1
  278. package/gs/math/const.gs.test.ts +34 -8
  279. package/gs/math/copysign.gs.test.ts +7 -3
  280. package/gs/math/dim.gs.test.ts +19 -7
  281. package/gs/math/erf.gs.test.ts +1 -1
  282. package/gs/math/erfinv.gs.test.ts +4 -2
  283. package/gs/math/exp.gs.test.ts +1 -1
  284. package/gs/math/expm1.gs.test.ts +6 -4
  285. package/gs/math/floor.gs.test.ts +17 -4
  286. package/gs/math/fma.gs.test.ts +53 -53
  287. package/gs/math/frexp.gs.test.ts +112 -117
  288. package/gs/math/gamma.gs.test.ts +1 -1
  289. package/gs/math/hypot.gs.test.ts +53 -53
  290. package/gs/math/index.ts +80 -44
  291. package/gs/math/j0.gs.test.ts +6 -2
  292. package/gs/math/j1.gs.test.ts +6 -2
  293. package/gs/math/jn.gs.test.ts +9 -5
  294. package/gs/math/ldexp.gs.test.ts +103 -86
  295. package/gs/math/lgamma.gs.test.ts +10 -10
  296. package/gs/math/log.gs.test.ts +1 -1
  297. package/gs/math/log10.gs.test.ts +1 -1
  298. package/gs/math/log1p.gs.test.ts +2 -2
  299. package/gs/math/logb.gs.test.ts +1 -1
  300. package/gs/math/mod.gs.test.ts +2 -2
  301. package/gs/math/modf.gs.test.ts +7 -7
  302. package/gs/math/nextafter.gs.test.ts +9 -7
  303. package/gs/math/pow.gs.test.ts +6 -4
  304. package/gs/math/pow10.gs.test.ts +1 -1
  305. package/gs/math/remainder.gs.test.ts +1 -1
  306. package/gs/math/signbit.gs.test.ts +1 -1
  307. package/gs/math/sin.gs.test.ts +1 -1
  308. package/gs/math/sincos.gs.test.ts +33 -14
  309. package/gs/math/sinh.gs.test.ts +1 -1
  310. package/gs/math/sqrt.gs.test.ts +1 -1
  311. package/gs/math/tan.gs.test.ts +3 -3
  312. package/gs/math/tanh.gs.test.ts +1 -1
  313. package/gs/os/dir.gs.ts +42 -0
  314. package/gs/os/dir_unix.gs.ts +155 -0
  315. package/gs/os/dirent_js.gs.ts +27 -0
  316. package/gs/os/env.gs.ts +179 -0
  317. package/gs/os/error.gs.ts +205 -0
  318. package/gs/os/error_errno.gs.ts +12 -0
  319. package/gs/os/exec.gs.ts +198 -0
  320. package/gs/os/exec_nohandle.gs.ts +2 -0
  321. package/gs/os/exec_posix.gs.ts +95 -0
  322. package/gs/os/exec_unix.gs.ts +64 -0
  323. package/gs/os/executable.gs.ts +18 -0
  324. package/gs/os/executable_js.gs.ts +6 -0
  325. package/gs/os/executable_wasm.gs.ts +10 -0
  326. package/gs/os/file_constants_js.gs.ts +98 -0
  327. package/gs/os/file_js.gs.ts +99 -0
  328. package/gs/os/file_open_unix.gs.ts +15 -0
  329. package/gs/os/file_posix_js.gs.ts +40 -0
  330. package/gs/os/file_unix_js.gs.ts +94 -0
  331. package/gs/os/getwd_js.gs.ts +28 -0
  332. package/gs/os/index.ts +128 -0
  333. package/gs/os/path.gs.ts +35 -0
  334. package/gs/os/path_unix.gs.ts +49 -0
  335. package/gs/os/pidfd_js.gs.ts +25 -0
  336. package/gs/os/pipe_wasm.gs.ts +17 -0
  337. package/gs/os/proc.gs.ts +84 -0
  338. package/gs/os/proc_js.gs.ts +15 -0
  339. package/gs/os/rawconn_js.gs.ts +30 -0
  340. package/gs/os/removeall_js.gs.ts +9 -0
  341. package/gs/os/root_js.gs.ts +111 -0
  342. package/gs/os/root_nonwindows.gs.ts +6 -0
  343. package/gs/os/root_noopenat.gs.ts +45 -0
  344. package/gs/os/stat.gs.ts +38 -0
  345. package/gs/os/stat_js.gs.ts +30 -0
  346. package/gs/os/stat_unix_js.gs.ts +27 -0
  347. package/gs/os/sticky_bsd.gs.ts +4 -0
  348. package/gs/os/sys.gs.ts +12 -0
  349. package/gs/os/sys_bsd.gs.ts +17 -0
  350. package/gs/os/sys_js.gs.ts +9 -0
  351. package/gs/os/tempfile.gs.ts +34 -0
  352. package/gs/os/types.gs.ts +170 -0
  353. package/gs/os/types_js.gs.ts +205 -0
  354. package/gs/os/types_unix.gs.ts +118 -0
  355. package/gs/os/wait_unimp.gs.ts +2 -0
  356. package/gs/os/zero_copy_posix.gs.ts +35 -0
  357. package/gs/os/zero_copy_stub.gs.ts +4 -0
  358. package/gs/reflect/ANALYSIS.md +278 -0
  359. package/gs/reflect/deepequal.ts +154 -0
  360. package/gs/reflect/function-types.test.ts +146 -0
  361. package/gs/reflect/godoc.txt +67 -0
  362. package/gs/reflect/index.ts +83 -0
  363. package/gs/reflect/iter.ts +44 -0
  364. package/gs/reflect/map.ts +81 -0
  365. package/gs/reflect/swapper.ts +52 -0
  366. package/gs/reflect/type.ts +1012 -0
  367. package/gs/reflect/types.ts +214 -0
  368. package/gs/reflect/value.ts +264 -0
  369. package/gs/reflect/visiblefields.ts +173 -0
  370. package/gs/strconv/index.ts +39 -6
  371. package/gs/strings/index.ts +7 -1
  372. package/gs/strings/replace.ts +1 -9
  373. package/gs/sync/atomic/index.ts +53 -4
  374. package/gs/syscall/index.ts +212 -0
  375. package/gs/unsafe/unsafe.ts +1 -1
  376. package/package.json +2 -1
@@ -0,0 +1,154 @@
1
+ // DeepEqual reports whether x and y are "deeply equal," defined as follows.
2
+ // Two values of identical type are deeply equal if one of the following cases applies.
3
+ // Values of distinct types are never deeply equal.
4
+ //
5
+ // Array values are deeply equal when their corresponding elements are deeply equal.
6
+ //
7
+ // Struct values are deeply equal if their corresponding fields,
8
+ // both exported and unexported, are deeply equal.
9
+ //
10
+ // Func values are deeply equal if both are nil; otherwise they are not deeply equal.
11
+ //
12
+ // Interface values are deeply equal if they hold deeply equal concrete values.
13
+ //
14
+ // Map values are deeply equal when all of the following are true:
15
+ // they are both nil or both non-nil, they have the same length,
16
+ // and either they are the same map object or their corresponding keys
17
+ // (matched using Go equality) map to deeply equal values.
18
+ //
19
+ // Pointer values are deeply equal if they are equal using Go's == operator
20
+ // or if they point to deeply equal values.
21
+ //
22
+ // Slice values are deeply equal when all of the following are true:
23
+ // they are both nil or both non-nil, they have the same length,
24
+ // and either they point to the same initial entry of the same underlying array
25
+ // (that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal.
26
+ // Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil))
27
+ // are not deeply equal.
28
+ //
29
+ // Other values - numbers, bools, strings, and channels - are deeply equal
30
+ // if they are equal using Go's == operator.
31
+ //
32
+ // In general DeepEqual is a recursive relaxation of Go's == operator.
33
+ // However, this idea is impossible to implement without some inconsistency.
34
+ // Specifically, it is possible for a value to be unequal to itself,
35
+ // either because it is of func type (uncomparable in general)
36
+ // or because it is a floating-point NaN value (not equal to itself in floating-point comparison),
37
+ // or because it is an array, struct, or interface containing
38
+ // such a value.
39
+ // On the other hand, pointer values are always equal to themselves,
40
+ // even if they point at or contain such problematic values,
41
+ // because they compare equal using Go's == operator, and that
42
+ // is a sufficient condition to be deeply equal, regardless of content.
43
+ // DeepEqual has been defined so that the same short-cut applies
44
+ // to slices and maps: if x and y are the same slice or the same map,
45
+ // they are deeply equal regardless of content.
46
+ //
47
+ // As DeepEqual traverses the data values it may find a cycle. The
48
+ // second and subsequent times that DeepEqual compares two pointer
49
+ // values that have been compared before, it treats the values as
50
+ // equal rather than examining the values to which they point.
51
+ // This ensures that DeepEqual terminates.
52
+ export function DeepEqual(x: null | any, y: null | any): boolean {
53
+ // Handle null/undefined cases
54
+ if (x === y) {
55
+ return true
56
+ }
57
+
58
+ if (x === null || y === null || x === undefined || y === undefined) {
59
+ return x === y
60
+ }
61
+
62
+ // Check for identical references first
63
+ if (x === y) {
64
+ return true
65
+ }
66
+
67
+ // Different types are never equal
68
+ if (typeof x !== typeof y) {
69
+ return false
70
+ }
71
+
72
+ // Handle arrays (including GoScript slices)
73
+ if (globalThis.Array.isArray(x) && globalThis.Array.isArray(y)) {
74
+ if (x.length !== y.length) {
75
+ return false
76
+ }
77
+ for (let i = 0; i < x.length; i++) {
78
+ if (!DeepEqual(x[i], y[i])) {
79
+ return false
80
+ }
81
+ }
82
+ return true
83
+ }
84
+
85
+ // Handle GoScript slice objects with __meta__ structure
86
+ if (x && y && typeof x === 'object' && typeof y === 'object') {
87
+ // Check if both are GoScript slices
88
+ if ('__meta__' in x && '__meta__' in y) {
89
+ const xMeta = (
90
+ x as { __meta__?: { backing?: unknown[]; length?: number } }
91
+ ).__meta__
92
+ const yMeta = (
93
+ y as { __meta__?: { backing?: unknown[]; length?: number } }
94
+ ).__meta__
95
+
96
+ if (
97
+ xMeta &&
98
+ yMeta &&
99
+ 'backing' in xMeta &&
100
+ 'backing' in yMeta &&
101
+ 'length' in xMeta &&
102
+ 'length' in yMeta &&
103
+ globalThis.Array.isArray(xMeta.backing) &&
104
+ globalThis.Array.isArray(yMeta.backing) &&
105
+ typeof xMeta.length === 'number' &&
106
+ typeof yMeta.length === 'number'
107
+ ) {
108
+ // Compare lengths
109
+ if (xMeta.length !== yMeta.length) {
110
+ return false
111
+ }
112
+
113
+ // Compare elements
114
+ for (let i = 0; i < xMeta.length; i++) {
115
+ if (!DeepEqual(xMeta.backing[i], yMeta.backing[i])) {
116
+ return false
117
+ }
118
+ }
119
+ return true
120
+ }
121
+ }
122
+ }
123
+
124
+ // Handle Maps
125
+ if (x instanceof globalThis.Map && y instanceof globalThis.Map) {
126
+ if (x.size !== y.size) {
127
+ return false
128
+ }
129
+ for (const [key, value] of x) {
130
+ if (!y.has(key) || !DeepEqual(value, y.get(key))) {
131
+ return false
132
+ }
133
+ }
134
+ return true
135
+ }
136
+
137
+ // Handle objects (structs)
138
+ if (typeof x === 'object' && typeof y === 'object') {
139
+ const keysX = Object.keys(x)
140
+ const keysY = Object.keys(y)
141
+ if (keysX.length !== keysY.length) {
142
+ return false
143
+ }
144
+ for (const key of keysX) {
145
+ if (!keysY.includes(key) || !DeepEqual(x[key], y[key])) {
146
+ return false
147
+ }
148
+ }
149
+ return true
150
+ }
151
+
152
+ // For primitive values, use direct comparison
153
+ return x === y
154
+ }
@@ -0,0 +1,146 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { TypeOf } from './type.js'
3
+
4
+ describe('Function Type Detection', () => {
5
+ it('should detect regular function types', () => {
6
+ const regularFunc = function (x: number, y: number) {
7
+ return x + y
8
+ }
9
+ const type = TypeOf(regularFunc)
10
+ expect(type.String()).toMatch(/^func/)
11
+ expect(type.Kind().String()).toBe('func')
12
+ })
13
+
14
+ it('should detect GoScript typed functions with __goTypeName', () => {
15
+ // Test Greeter function type
16
+ const greetFunc = function (name: string) {
17
+ return 'Hello, ' + name
18
+ }
19
+ Object.assign(greetFunc, { __goTypeName: 'Greeter' })
20
+ const greetType = TypeOf(greetFunc)
21
+ expect(greetType.String()).toBe('func(string) string')
22
+ expect(greetType.Kind().String()).toBe('func')
23
+
24
+ // Test Adder function type
25
+ const addFunc = function (a: number, b: number) {
26
+ return a + b
27
+ }
28
+ Object.assign(addFunc, { __goTypeName: 'Adder' })
29
+ const addType = TypeOf(addFunc)
30
+ expect(addType.String()).toBe('func(int, int) int')
31
+ expect(addType.Kind().String()).toBe('func')
32
+ })
33
+
34
+ it('should detect functions with full __typeInfo metadata', () => {
35
+ const complexFunc = function (x: number, y: number) {
36
+ return x + y
37
+ }
38
+ Object.assign(complexFunc, {
39
+ __goTypeName: 'MyFunc',
40
+ __typeInfo: {
41
+ kind: 'Function',
42
+ params: [
43
+ { kind: 'Basic', name: 'int' },
44
+ { kind: 'Basic', name: 'int' },
45
+ ],
46
+ results: [{ kind: 'Basic', name: 'int' }],
47
+ },
48
+ })
49
+
50
+ const type = TypeOf(complexFunc)
51
+ expect(type.String()).toBe('func(int, int) int')
52
+ expect(type.Kind().String()).toBe('func')
53
+ })
54
+
55
+ it('should handle functions with multiple return types', () => {
56
+ const multiReturnFunc = function () {
57
+ return [1, 'test']
58
+ }
59
+ Object.assign(multiReturnFunc, {
60
+ __goTypeName: 'MultiReturn',
61
+ __typeInfo: {
62
+ kind: 'Function',
63
+ params: [],
64
+ results: [
65
+ { kind: 'Basic', name: 'int' },
66
+ { kind: 'Basic', name: 'string' },
67
+ ],
68
+ },
69
+ })
70
+
71
+ const type = TypeOf(multiReturnFunc)
72
+ expect(type.String()).toBe('func() (int, string)')
73
+ expect(type.Kind().String()).toBe('func')
74
+ })
75
+
76
+ it('should handle functions with no parameters', () => {
77
+ const noParamFunc = function () {
78
+ return 42
79
+ }
80
+ Object.assign(noParamFunc, {
81
+ __goTypeName: 'NoParam',
82
+ __typeInfo: {
83
+ kind: 'Function',
84
+ params: [],
85
+ results: [{ kind: 'Basic', name: 'int' }],
86
+ },
87
+ })
88
+
89
+ const type = TypeOf(noParamFunc)
90
+ expect(type.String()).toBe('func() int')
91
+ expect(type.Kind().String()).toBe('func')
92
+ })
93
+
94
+ it('should handle functions with no return type', () => {
95
+ const voidFunc = function (x: number) {
96
+ console.log(x)
97
+ }
98
+ Object.assign(voidFunc, {
99
+ __goTypeName: 'VoidFunc',
100
+ __typeInfo: {
101
+ kind: 'Function',
102
+ params: [{ kind: 'Basic', name: 'int' }],
103
+ results: [],
104
+ },
105
+ })
106
+
107
+ const type = TypeOf(voidFunc)
108
+ expect(type.String()).toBe('func(int)')
109
+ expect(type.Kind().String()).toBe('func')
110
+ })
111
+
112
+ it('should fallback to generic func for unknown typed functions', () => {
113
+ const unknownFunc = function (x: any) {
114
+ return x
115
+ }
116
+ Object.assign(unknownFunc, { __goTypeName: 'UnknownType' })
117
+
118
+ const type = TypeOf(unknownFunc)
119
+ expect(type.String()).toBe('func')
120
+ expect(type.Kind().String()).toBe('func')
121
+ })
122
+
123
+ it('should handle arrow functions', () => {
124
+ const arrowFunc = (x: number) => x * 2
125
+ const type = TypeOf(arrowFunc)
126
+ expect(type.String()).toMatch(/^func/)
127
+ expect(type.Kind().String()).toBe('func')
128
+ })
129
+
130
+ it('should detect functions that return values vs void functions', () => {
131
+ // Function with return
132
+ const returningFunc = function (x: number) {
133
+ return x * 2
134
+ }
135
+ const returnType = TypeOf(returningFunc)
136
+ expect(returnType.String()).toMatch(/func.*any$/)
137
+
138
+ // Function without return (void)
139
+ const voidFunc = function (x: number) {
140
+ console.log(x)
141
+ }
142
+ const voidType = TypeOf(voidFunc)
143
+ // Should not have return type suffix
144
+ expect(voidType.String()).not.toMatch(/func.*any$/)
145
+ })
146
+ })
@@ -0,0 +1,67 @@
1
+ package reflect // import "reflect"
2
+
3
+ Package reflect implements run-time reflection, allowing a program to manipulate
4
+ objects with arbitrary types. The typical use is to take a value with static
5
+ type interface{} and extract its dynamic type information by calling TypeOf,
6
+ which returns a Type.
7
+
8
+ A call to ValueOf returns a Value representing the run-time data. Zero takes a
9
+ Type and returns a Value representing a zero value for that type.
10
+
11
+ See "The Laws of Reflection" for an introduction to reflection in Go:
12
+ https://golang.org/doc/articles/laws_of_reflection.html
13
+
14
+ const Ptr = Pointer
15
+ func Copy(dst, src Value) int
16
+ func DeepEqual(x, y any) bool
17
+ func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)
18
+ func Swapper(slice any) func(i, j int)
19
+ type ChanDir int
20
+ const RecvDir ChanDir = 1 << iota ...
21
+ type Kind uint
22
+ const Invalid Kind = iota ...
23
+ type MapIter struct{ ... }
24
+ type Method struct{ ... }
25
+ type SelectCase struct{ ... }
26
+ type SelectDir int
27
+ const SelectSend SelectDir ...
28
+ type SliceHeader struct{ ... }
29
+ type StringHeader struct{ ... }
30
+ type StructField struct{ ... }
31
+ func VisibleFields(t Type) []StructField
32
+ type StructTag string
33
+ type Type interface{ ... }
34
+ func ArrayOf(length int, elem Type) Type
35
+ func ChanOf(dir ChanDir, t Type) Type
36
+ func FuncOf(in, out []Type, variadic bool) Type
37
+ func MapOf(key, elem Type) Type
38
+ func PointerTo(t Type) Type
39
+ func PtrTo(t Type) Type
40
+ func SliceOf(t Type) Type
41
+ func StructOf(fields []StructField) Type
42
+ func TypeFor[T any]() Type
43
+ func TypeOf(i any) Type
44
+ type Value struct{ ... }
45
+ func Append(s Value, x ...Value) Value
46
+ func AppendSlice(s, t Value) Value
47
+ func Indirect(v Value) Value
48
+ func MakeChan(typ Type, buffer int) Value
49
+ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value
50
+ func MakeMap(typ Type) Value
51
+ func MakeMapWithSize(typ Type, n int) Value
52
+ func MakeSlice(typ Type, len, cap int) Value
53
+ func New(typ Type) Value
54
+ func NewAt(typ Type, p unsafe.Pointer) Value
55
+ func SliceAt(typ Type, p unsafe.Pointer, n int) Value
56
+ func ValueOf(i any) Value
57
+ func Zero(typ Type) Value
58
+ type ValueError struct{ ... }
59
+
60
+ BUG: FieldByName and related functions consider struct field names to be equal
61
+ if the names are equal, even if they are unexported names originating
62
+ in different packages. The practical effect of this is that the result of
63
+ t.FieldByName("x") is not well defined if the struct type t contains
64
+ multiple fields named x (embedded from different packages).
65
+ FieldByName may return one of the fields named x or may report that there are none.
66
+ See https://golang.org/issue/4876 for more details.
67
+
@@ -0,0 +1,83 @@
1
+ // Export the main reflect functions organized like Go stdlib
2
+ export {
3
+ TypeOf,
4
+ ValueOf,
5
+ Value,
6
+ Kind,
7
+ ArrayOf,
8
+ SliceOf,
9
+ PointerTo,
10
+ PtrTo,
11
+ MapOf,
12
+ ChanOf,
13
+ } from './type'
14
+ export type { Type } from './type'
15
+ export { DeepEqual } from './deepequal'
16
+ export {
17
+ Zero,
18
+ Copy,
19
+ Indirect,
20
+ New,
21
+ MakeSlice,
22
+ MakeMap,
23
+ Append,
24
+ MakeChan,
25
+ Select,
26
+ } from './value'
27
+ export { Swapper } from './swapper'
28
+
29
+ // Export new types and constants
30
+ export {
31
+ ChanDir,
32
+ RecvDir,
33
+ SendDir,
34
+ BothDir,
35
+ StructTag,
36
+ ValueError,
37
+ SelectDir,
38
+ SelectSend,
39
+ SelectRecv,
40
+ SelectDefault,
41
+ bitVector,
42
+ } from './types'
43
+ export type {
44
+ uintptr,
45
+ Pointer,
46
+ StructField,
47
+ Method,
48
+ SelectCase,
49
+ SliceHeader,
50
+ StringHeader,
51
+ MapIter,
52
+ } from './types'
53
+
54
+ // Export kind constants
55
+ export {
56
+ Invalid,
57
+ Bool,
58
+ Int,
59
+ Int8,
60
+ Int16,
61
+ Int32,
62
+ Int64,
63
+ Uint,
64
+ Uint8,
65
+ Uint16,
66
+ Uint32,
67
+ Uint64,
68
+ Uintptr,
69
+ Float32,
70
+ Float64,
71
+ Complex64,
72
+ Complex128,
73
+ Array,
74
+ Chan,
75
+ Func,
76
+ Interface,
77
+ Map,
78
+ Ptr,
79
+ Slice,
80
+ String,
81
+ Struct,
82
+ UnsafePointer,
83
+ } from './type'
@@ -0,0 +1,44 @@
1
+ import { Type, Value } from './type.js'
2
+ import { uintptr } from './types.js'
3
+ import { ValueOf } from './value.js'
4
+
5
+ import * as iter from '@goscript/iter/index.js'
6
+
7
+ export function rangeNum<
8
+ T extends
9
+ | number
10
+ | number
11
+ | number
12
+ | number
13
+ | number
14
+ | number
15
+ | number
16
+ | number
17
+ | number
18
+ | number
19
+ | uintptr,
20
+ N extends number | number,
21
+ >(num: N, t: Type): iter.Seq<Value> {
22
+ // cannot use range T(v) because no core type.
23
+
24
+ // if the iteration value type is define by
25
+ // type T built-in type.
26
+ return (_yield: ((v: Value) => boolean) | null): void => {
27
+ let convert = t!.PkgPath!() != ''
28
+ // cannot use range T(v) because no core type.
29
+
30
+ // if the iteration value type is define by
31
+ // type T built-in type.
32
+ for (let i = 0 as unknown as T; i < (num as unknown as T); i++) {
33
+ let tmp = ValueOf(i).clone()
34
+ // if the iteration value type is define by
35
+ // type T built-in type.
36
+ if (convert) {
37
+ tmp = tmp.Convert(t).clone()
38
+ }
39
+ if (!_yield!(tmp)) {
40
+ return
41
+ }
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,81 @@
1
+ import { Type, Kind, Value } from './type.js'
2
+
3
+ // Simple MapOf implementation using JavaScript Map
4
+ export function MapOf(key: Type, elem: Type): Type {
5
+ return new MapType(key, elem)
6
+ }
7
+
8
+ // Simple map type implementation
9
+ class MapType implements Type {
10
+ constructor(
11
+ private _keyType: Type,
12
+ private _elemType: Type,
13
+ ) {}
14
+
15
+ public String(): string {
16
+ return `map[${this._keyType.String()}]${this._elemType.String()}`
17
+ }
18
+
19
+ public Kind(): Kind {
20
+ return new Kind(21) // Map kind
21
+ }
22
+
23
+ public Size(): number {
24
+ return 8 // pointer size
25
+ }
26
+
27
+ public Elem(): Type | null {
28
+ return this._elemType
29
+ }
30
+
31
+ public Key(): Type | null {
32
+ return this._keyType
33
+ }
34
+
35
+ public NumField(): number {
36
+ return 0
37
+ }
38
+ }
39
+
40
+ // Simple map iterator using JavaScript Map
41
+ export class MapIter {
42
+ private iterator: Iterator<[any, any]>
43
+ private currentEntry: IteratorResult<[any, any]> | null = null
44
+
45
+ constructor(private map: Map<any, any>) {
46
+ this.iterator = map.entries()
47
+ this.Next()
48
+ }
49
+
50
+ public Next(): boolean {
51
+ this.currentEntry = this.iterator.next()
52
+ return !this.currentEntry.done
53
+ }
54
+
55
+ public Key(): any {
56
+ return this.currentEntry?.value?.[0]
57
+ }
58
+
59
+ public Value(): any {
60
+ return this.currentEntry?.value?.[1]
61
+ }
62
+
63
+ public Reset(m: any): void {
64
+ if (m instanceof Map) {
65
+ this.map = m
66
+ this.iterator = m.entries()
67
+ this.Next()
68
+ }
69
+ }
70
+ }
71
+
72
+ // Helper functions for map operations
73
+ export function MakeMap(typ: Type): Value {
74
+ const map = new Map()
75
+ return new Value(map, typ)
76
+ }
77
+
78
+ export function MakeMapWithSize(typ: Type, _n: number): Value {
79
+ // JavaScript Map doesn't have initial size, so we ignore n
80
+ return MakeMap(typ)
81
+ }
@@ -0,0 +1,52 @@
1
+ import { ReflectValue } from './types'
2
+
3
+ // Swapper returns a function that swaps the elements in the provided slice.
4
+ // Swapper panics if the provided interface is not a slice.
5
+ export function Swapper(slice: ReflectValue): (i: number, j: number) => void {
6
+ let actualArray: unknown[] | null = null
7
+
8
+ // Try to extract the underlying array
9
+ if (Array.isArray(slice)) {
10
+ actualArray = slice
11
+ } else if (slice && typeof slice === 'object' && '__meta__' in slice) {
12
+ // GoScript slice object
13
+ const meta = (slice as { __meta__?: { backing?: unknown[] } }).__meta__
14
+ if (meta && meta.backing && Array.isArray(meta.backing)) {
15
+ actualArray = meta.backing
16
+ }
17
+ }
18
+
19
+ if (!actualArray) {
20
+ // Return a no-op function if we can't extract an array
21
+ return () => {}
22
+ }
23
+
24
+ // Fast path for slices of size 0 and 1. Nothing to swap.
25
+ switch (actualArray.length) {
26
+ case 0:
27
+ return (_i: number, _j: number): void => {
28
+ throw new Error('reflect: slice index out of range')
29
+ }
30
+ case 1:
31
+ return (i: number, j: number): void => {
32
+ if (i !== 0 || j !== 0) {
33
+ throw new Error('reflect: slice index out of range')
34
+ }
35
+ }
36
+ }
37
+
38
+ // Return the swapper function
39
+ return (i: number, j: number) => {
40
+ if (
41
+ actualArray &&
42
+ i >= 0 &&
43
+ j >= 0 &&
44
+ i < actualArray.length &&
45
+ j < actualArray.length
46
+ ) {
47
+ const temp = actualArray[i]
48
+ actualArray[i] = actualArray[j]
49
+ actualArray[j] = temp
50
+ }
51
+ }
52
+ }