goscript 0.0.34 → 0.0.36

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 (358) hide show
  1. package/compiler/analysis.go +28 -20
  2. package/compiler/analysis_test.go +14 -0
  3. package/compiler/assignment.go +19 -7
  4. package/compiler/compiler.go +15 -99
  5. package/compiler/composite-lit.go +60 -17
  6. package/compiler/decl.go +1 -1
  7. package/compiler/expr-call.go +233 -35
  8. package/compiler/expr-selector.go +28 -2
  9. package/compiler/expr.go +13 -37
  10. package/compiler/lit.go +111 -2
  11. package/compiler/primitive.go +6 -6
  12. package/compiler/protobuf.go +0 -5
  13. package/compiler/sanitize.go +101 -0
  14. package/compiler/spec-struct.go +41 -8
  15. package/compiler/spec-value.go +29 -18
  16. package/compiler/stmt-assign.go +22 -1
  17. package/compiler/stmt.go +26 -9
  18. package/compiler/type.go +3 -3
  19. package/dist/gs/builtin/builtin.d.ts +3 -2
  20. package/dist/gs/builtin/builtin.js +2 -1
  21. package/dist/gs/builtin/builtin.js.map +1 -1
  22. package/dist/gs/builtin/map.js.map +1 -1
  23. package/dist/gs/builtin/slice.d.ts +7 -1
  24. package/dist/gs/builtin/slice.js +112 -22
  25. package/dist/gs/builtin/slice.js.map +1 -1
  26. package/dist/gs/github.com/pkg/errors/errors.d.ts +13 -0
  27. package/dist/gs/github.com/pkg/errors/errors.js +232 -0
  28. package/dist/gs/github.com/pkg/errors/errors.js.map +1 -0
  29. package/dist/gs/github.com/pkg/errors/go113.d.ts +4 -0
  30. package/dist/gs/github.com/pkg/errors/go113.js +34 -0
  31. package/dist/gs/github.com/pkg/errors/go113.js.map +1 -0
  32. package/dist/gs/github.com/pkg/errors/index.d.ts +3 -0
  33. package/dist/gs/github.com/pkg/errors/index.js +4 -0
  34. package/dist/gs/github.com/pkg/errors/index.js.map +1 -0
  35. package/dist/gs/github.com/pkg/errors/stack.d.ts +32 -0
  36. package/dist/gs/github.com/pkg/errors/stack.js +111 -0
  37. package/dist/gs/github.com/pkg/errors/stack.js.map +1 -0
  38. package/dist/gs/maps/index.d.ts +2 -2
  39. package/dist/gs/maps/index.js +2 -2
  40. package/dist/gs/maps/index.js.map +1 -1
  41. package/dist/gs/maps/iter.d.ts +7 -0
  42. package/dist/gs/maps/iter.js +57 -0
  43. package/dist/gs/maps/iter.js.map +1 -0
  44. package/dist/gs/maps/maps.d.ts +7 -0
  45. package/dist/gs/maps/maps.js +67 -0
  46. package/dist/gs/maps/maps.js.map +1 -0
  47. package/dist/gs/math/abs.gs.d.ts +1 -0
  48. package/dist/gs/math/abs.gs.js +10 -0
  49. package/dist/gs/math/abs.gs.js.map +1 -0
  50. package/dist/gs/math/acosh.gs.d.ts +2 -0
  51. package/dist/gs/math/acosh.gs.js +14 -0
  52. package/dist/gs/math/acosh.gs.js.map +1 -0
  53. package/dist/gs/math/asin.gs.d.ts +4 -0
  54. package/dist/gs/math/asin.gs.js +24 -0
  55. package/dist/gs/math/asin.gs.js.map +1 -0
  56. package/dist/gs/math/asinh.gs.d.ts +2 -0
  57. package/dist/gs/math/asinh.gs.js +14 -0
  58. package/dist/gs/math/asinh.gs.js.map +1 -0
  59. package/dist/gs/math/atan.gs.d.ts +4 -0
  60. package/dist/gs/math/atan.gs.js +22 -0
  61. package/dist/gs/math/atan.gs.js.map +1 -0
  62. package/dist/gs/math/atan2.gs.d.ts +2 -0
  63. package/dist/gs/math/atan2.gs.js +30 -0
  64. package/dist/gs/math/atan2.gs.js.map +1 -0
  65. package/dist/gs/math/atanh.gs.d.ts +2 -0
  66. package/dist/gs/math/atanh.gs.js +16 -0
  67. package/dist/gs/math/atanh.gs.js.map +1 -0
  68. package/dist/gs/math/bits.gs.d.ts +5 -0
  69. package/dist/gs/math/bits.gs.js +46 -0
  70. package/dist/gs/math/bits.gs.js.map +1 -0
  71. package/dist/gs/math/cbrt.gs.d.ts +2 -0
  72. package/dist/gs/math/cbrt.gs.js +14 -0
  73. package/dist/gs/math/cbrt.gs.js.map +1 -0
  74. package/dist/gs/math/const.gs.d.ts +30 -0
  75. package/dist/gs/math/const.gs.js +61 -0
  76. package/dist/gs/math/const.gs.js.map +1 -0
  77. package/dist/gs/math/copysign.gs.d.ts +1 -0
  78. package/dist/gs/math/copysign.gs.js +20 -0
  79. package/dist/gs/math/copysign.gs.js.map +1 -0
  80. package/dist/gs/math/dim.gs.d.ts +5 -0
  81. package/dist/gs/math/dim.gs.js +69 -0
  82. package/dist/gs/math/dim.gs.js.map +1 -0
  83. package/dist/gs/math/erf.gs.d.ts +4 -0
  84. package/dist/gs/math/erf.gs.js +336 -0
  85. package/dist/gs/math/erf.gs.js.map +1 -0
  86. package/dist/gs/math/erfinv.gs.d.ts +2 -0
  87. package/dist/gs/math/erfinv.gs.js +118 -0
  88. package/dist/gs/math/erfinv.gs.js.map +1 -0
  89. package/dist/gs/math/exp.gs.d.ts +5 -0
  90. package/dist/gs/math/exp.gs.js +30 -0
  91. package/dist/gs/math/exp.gs.js.map +1 -0
  92. package/dist/gs/math/expm1.gs.d.ts +2 -0
  93. package/dist/gs/math/expm1.gs.js +17 -0
  94. package/dist/gs/math/expm1.gs.js.map +1 -0
  95. package/dist/gs/math/floor.gs.d.ts +8 -0
  96. package/dist/gs/math/floor.gs.js +75 -0
  97. package/dist/gs/math/floor.gs.js.map +1 -0
  98. package/dist/gs/math/fma.gs.d.ts +1 -0
  99. package/dist/gs/math/fma.gs.js +8 -0
  100. package/dist/gs/math/fma.gs.js.map +1 -0
  101. package/dist/gs/math/frexp.gs.d.ts +2 -0
  102. package/dist/gs/math/frexp.gs.js +28 -0
  103. package/dist/gs/math/frexp.gs.js.map +1 -0
  104. package/dist/gs/math/gamma.gs.d.ts +3 -0
  105. package/dist/gs/math/gamma.gs.js +149 -0
  106. package/dist/gs/math/gamma.gs.js.map +1 -0
  107. package/dist/gs/math/hypot.gs.d.ts +2 -0
  108. package/dist/gs/math/hypot.gs.js +16 -0
  109. package/dist/gs/math/hypot.gs.js.map +1 -0
  110. package/dist/gs/math/index.d.ts +44 -0
  111. package/dist/gs/math/index.js +45 -0
  112. package/dist/gs/math/index.js.map +1 -0
  113. package/dist/gs/math/j0.gs.d.ts +4 -0
  114. package/dist/gs/math/j0.gs.js +228 -0
  115. package/dist/gs/math/j0.gs.js.map +1 -0
  116. package/dist/gs/math/j1.gs.d.ts +4 -0
  117. package/dist/gs/math/j1.gs.js +211 -0
  118. package/dist/gs/math/j1.gs.js.map +1 -0
  119. package/dist/gs/math/jn.gs.d.ts +2 -0
  120. package/dist/gs/math/jn.gs.js +412 -0
  121. package/dist/gs/math/jn.gs.js.map +1 -0
  122. package/dist/gs/math/ldexp.gs.d.ts +2 -0
  123. package/dist/gs/math/ldexp.gs.js +20 -0
  124. package/dist/gs/math/ldexp.gs.js.map +1 -0
  125. package/dist/gs/math/lgamma.gs.d.ts +2 -0
  126. package/dist/gs/math/lgamma.gs.js +243 -0
  127. package/dist/gs/math/lgamma.gs.js.map +1 -0
  128. package/dist/gs/math/log.gs.d.ts +2 -0
  129. package/dist/gs/math/log.gs.js +16 -0
  130. package/dist/gs/math/log.gs.js.map +1 -0
  131. package/dist/gs/math/log10.gs.d.ts +4 -0
  132. package/dist/gs/math/log10.gs.js +17 -0
  133. package/dist/gs/math/log10.gs.js.map +1 -0
  134. package/dist/gs/math/log1p.gs.d.ts +2 -0
  135. package/dist/gs/math/log1p.gs.js +17 -0
  136. package/dist/gs/math/log1p.gs.js.map +1 -0
  137. package/dist/gs/math/logb.gs.d.ts +3 -0
  138. package/dist/gs/math/logb.gs.js +43 -0
  139. package/dist/gs/math/logb.gs.js.map +1 -0
  140. package/dist/gs/math/mod.gs.d.ts +2 -0
  141. package/dist/gs/math/mod.gs.js +26 -0
  142. package/dist/gs/math/mod.gs.js.map +1 -0
  143. package/dist/gs/math/modf.gs.d.ts +2 -0
  144. package/dist/gs/math/modf.gs.js +24 -0
  145. package/dist/gs/math/modf.gs.js.map +1 -0
  146. package/dist/gs/math/nextafter.gs.d.ts +2 -0
  147. package/dist/gs/math/nextafter.gs.js +66 -0
  148. package/dist/gs/math/nextafter.gs.js.map +1 -0
  149. package/dist/gs/math/pow.gs.d.ts +3 -0
  150. package/dist/gs/math/pow.gs.js +40 -0
  151. package/dist/gs/math/pow.gs.js.map +1 -0
  152. package/dist/gs/math/pow10.gs.d.ts +1 -0
  153. package/dist/gs/math/pow10.gs.js +14 -0
  154. package/dist/gs/math/pow10.gs.js.map +1 -0
  155. package/dist/gs/math/remainder.gs.d.ts +2 -0
  156. package/dist/gs/math/remainder.gs.js +25 -0
  157. package/dist/gs/math/remainder.gs.js.map +1 -0
  158. package/dist/gs/math/signbit.gs.d.ts +1 -0
  159. package/dist/gs/math/signbit.gs.js +5 -0
  160. package/dist/gs/math/signbit.gs.js.map +1 -0
  161. package/dist/gs/math/sin.gs.d.ts +4 -0
  162. package/dist/gs/math/sin.gs.js +29 -0
  163. package/dist/gs/math/sin.gs.js.map +1 -0
  164. package/dist/gs/math/sincos.gs.d.ts +1 -0
  165. package/dist/gs/math/sincos.gs.js +11 -0
  166. package/dist/gs/math/sincos.gs.js.map +1 -0
  167. package/dist/gs/math/sinh.gs.d.ts +4 -0
  168. package/dist/gs/math/sinh.gs.js +27 -0
  169. package/dist/gs/math/sinh.gs.js.map +1 -0
  170. package/dist/gs/math/sqrt.gs.d.ts +2 -0
  171. package/dist/gs/math/sqrt.gs.js +15 -0
  172. package/dist/gs/math/sqrt.gs.js.map +1 -0
  173. package/dist/gs/math/tan.gs.d.ts +2 -0
  174. package/dist/gs/math/tan.gs.js +17 -0
  175. package/dist/gs/math/tan.gs.js.map +1 -0
  176. package/dist/gs/math/tanh.gs.d.ts +2 -0
  177. package/dist/gs/math/tanh.gs.js +17 -0
  178. package/dist/gs/math/tanh.gs.js.map +1 -0
  179. package/dist/gs/math/trig_reduce.gs.d.ts +1 -0
  180. package/dist/gs/math/trig_reduce.gs.js +62 -0
  181. package/dist/gs/math/trig_reduce.gs.js.map +1 -0
  182. package/dist/gs/math/unsafe.gs.d.ts +4 -0
  183. package/dist/gs/math/unsafe.gs.js +47 -0
  184. package/dist/gs/math/unsafe.gs.js.map +1 -0
  185. package/dist/gs/strconv/atob.gs.d.ts +4 -0
  186. package/dist/gs/strconv/atob.gs.js +42 -0
  187. package/dist/gs/strconv/atob.gs.js.map +1 -0
  188. package/dist/gs/strconv/atof.gs.d.ts +2 -0
  189. package/dist/gs/strconv/atof.gs.js +51 -0
  190. package/dist/gs/strconv/atof.gs.js.map +1 -0
  191. package/dist/gs/strconv/atoi.gs.d.ts +33 -0
  192. package/dist/gs/strconv/atoi.gs.js +200 -0
  193. package/dist/gs/strconv/atoi.gs.js.map +1 -0
  194. package/dist/gs/strconv/doc.gs.d.ts +1 -0
  195. package/dist/gs/strconv/doc.gs.js +2 -0
  196. package/dist/gs/strconv/doc.gs.js.map +1 -0
  197. package/dist/gs/strconv/ftoa.gs.d.ts +3 -0
  198. package/dist/gs/strconv/ftoa.gs.js +58 -0
  199. package/dist/gs/strconv/ftoa.gs.js.map +1 -0
  200. package/dist/gs/strconv/index.d.ts +6 -0
  201. package/dist/gs/strconv/index.js +7 -0
  202. package/dist/gs/strconv/index.js.map +1 -0
  203. package/dist/gs/strconv/itoa.gs.d.ts +6 -0
  204. package/dist/gs/strconv/itoa.gs.js +37 -0
  205. package/dist/gs/strconv/itoa.gs.js.map +1 -0
  206. package/dist/gs/strconv/quote.gs.d.ts +19 -0
  207. package/dist/gs/strconv/quote.gs.js +217 -0
  208. package/dist/gs/strconv/quote.gs.js.map +1 -0
  209. package/dist/gs/strings/index.d.ts +3 -0
  210. package/dist/gs/strings/index.js +4 -0
  211. package/dist/gs/strings/index.js.map +1 -1
  212. package/dist/gs/strings/replace.d.ts +0 -74
  213. package/dist/gs/strings/replace.js +6 -204
  214. package/dist/gs/strings/replace.js.map +1 -1
  215. package/dist/gs/strings/search.d.ts +0 -1
  216. package/dist/gs/strings/search.js +0 -21
  217. package/dist/gs/strings/search.js.map +1 -1
  218. package/dist/gs/sync/atomic/doc.gs.d.ts +28 -0
  219. package/dist/gs/sync/atomic/doc.gs.js +265 -0
  220. package/dist/gs/sync/atomic/doc.gs.js.map +1 -0
  221. package/dist/gs/sync/atomic/doc_64.gs.d.ts +15 -0
  222. package/dist/gs/sync/atomic/doc_64.gs.js +165 -0
  223. package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -0
  224. package/dist/gs/sync/atomic/index.d.ts +4 -0
  225. package/dist/gs/sync/atomic/index.js +5 -0
  226. package/dist/gs/sync/atomic/index.js.map +1 -0
  227. package/dist/gs/sync/atomic/type.gs.d.ts +130 -0
  228. package/dist/gs/sync/atomic/type.gs.js +433 -0
  229. package/dist/gs/sync/atomic/type.gs.js.map +1 -0
  230. package/dist/gs/sync/atomic/value.gs.d.ts +19 -0
  231. package/dist/gs/sync/atomic/value.gs.js +116 -0
  232. package/dist/gs/sync/atomic/value.gs.js.map +1 -0
  233. package/dist/gs/unsafe/unsafe.d.ts +1 -0
  234. package/dist/gs/unsafe/unsafe.js +5 -0
  235. package/dist/gs/unsafe/unsafe.js.map +1 -1
  236. package/gs/builtin/builtin.ts +9 -7
  237. package/gs/builtin/map.ts +5 -1
  238. package/gs/builtin/slice.ts +152 -24
  239. package/gs/github.com/pkg/errors/errors.ts +307 -0
  240. package/gs/github.com/pkg/errors/go113.ts +39 -0
  241. package/gs/github.com/pkg/errors/index.ts +3 -0
  242. package/gs/github.com/pkg/errors/stack.ts +127 -0
  243. package/gs/maps/index.ts +2 -2
  244. package/gs/maps/iter.ts +67 -0
  245. package/gs/maps/maps.ts +89 -0
  246. package/gs/math/TODO.md +156 -0
  247. package/gs/math/abs.gs.test.ts +29 -0
  248. package/gs/math/abs.gs.ts +13 -0
  249. package/gs/math/acosh.gs.test.ts +39 -0
  250. package/gs/math/acosh.gs.ts +21 -0
  251. package/gs/math/asin.gs.test.ts +66 -0
  252. package/gs/math/asin.gs.ts +27 -0
  253. package/gs/math/asinh.gs.test.ts +37 -0
  254. package/gs/math/asinh.gs.ts +21 -0
  255. package/gs/math/atan.gs.test.ts +49 -0
  256. package/gs/math/atan.gs.ts +27 -0
  257. package/gs/math/atan2.gs.test.ts +55 -0
  258. package/gs/math/atan2.gs.ts +37 -0
  259. package/gs/math/atanh.gs.test.ts +47 -0
  260. package/gs/math/atanh.gs.ts +21 -0
  261. package/gs/math/bits.gs.test.ts +88 -0
  262. package/gs/math/bits.gs.ts +61 -0
  263. package/gs/math/cbrt.gs.test.ts +57 -0
  264. package/gs/math/cbrt.gs.ts +20 -0
  265. package/gs/math/const.gs.test.ts +54 -0
  266. package/gs/math/const.gs.ts +93 -0
  267. package/gs/math/copysign.gs.test.ts +44 -0
  268. package/gs/math/copysign.gs.ts +27 -0
  269. package/gs/math/dim.gs.test.ts +102 -0
  270. package/gs/math/dim.gs.ts +84 -0
  271. package/gs/math/erf.gs.test.ts +92 -0
  272. package/gs/math/erf.gs.ts +409 -0
  273. package/gs/math/erfinv.gs.test.ts +104 -0
  274. package/gs/math/erfinv.gs.ts +169 -0
  275. package/gs/math/exp.gs.test.ts +82 -0
  276. package/gs/math/exp.gs.ts +39 -0
  277. package/gs/math/expm1.gs.test.ts +48 -0
  278. package/gs/math/expm1.gs.ts +23 -0
  279. package/gs/math/floor.gs.test.ts +146 -0
  280. package/gs/math/floor.gs.ts +88 -0
  281. package/gs/math/fma.gs.test.ts +83 -0
  282. package/gs/math/fma.gs.ts +7 -0
  283. package/gs/math/frexp.gs.test.ts +146 -0
  284. package/gs/math/frexp.gs.ts +37 -0
  285. package/gs/math/gamma.gs.test.ts +66 -0
  286. package/gs/math/gamma.gs.ts +158 -0
  287. package/gs/math/hypot.gs.test.ts +73 -0
  288. package/gs/math/hypot.gs.ts +23 -0
  289. package/gs/math/index.ts +44 -0
  290. package/gs/math/j0.gs.test.ts +74 -0
  291. package/gs/math/j0.gs.ts +257 -0
  292. package/gs/math/j1.gs.test.ts +81 -0
  293. package/gs/math/j1.gs.ts +231 -0
  294. package/gs/math/jn.gs.test.ts +133 -0
  295. package/gs/math/jn.gs.ts +447 -0
  296. package/gs/math/ldexp.gs.test.ts +128 -0
  297. package/gs/math/ldexp.gs.ts +28 -0
  298. package/gs/math/lgamma.gs.test.ts +102 -0
  299. package/gs/math/lgamma.gs.ts +251 -0
  300. package/gs/math/log.gs.test.ts +40 -0
  301. package/gs/math/log.gs.ts +21 -0
  302. package/gs/math/log10.gs.test.ts +80 -0
  303. package/gs/math/log10.gs.ts +25 -0
  304. package/gs/math/log1p.gs.test.ts +55 -0
  305. package/gs/math/log1p.gs.ts +24 -0
  306. package/gs/math/logb.gs.test.ts +87 -0
  307. package/gs/math/logb.gs.ts +54 -0
  308. package/gs/math/mod.gs.test.ts +64 -0
  309. package/gs/math/mod.gs.ts +36 -0
  310. package/gs/math/modf.gs.test.ts +80 -0
  311. package/gs/math/modf.gs.ts +32 -0
  312. package/gs/math/nextafter.gs.test.ts +107 -0
  313. package/gs/math/nextafter.gs.ts +71 -0
  314. package/gs/math/pow.gs.test.ts +103 -0
  315. package/gs/math/pow.gs.ts +55 -0
  316. package/gs/math/pow10.gs.test.ts +58 -0
  317. package/gs/math/pow10.gs.ts +19 -0
  318. package/gs/math/remainder.gs.test.ts +70 -0
  319. package/gs/math/remainder.gs.ts +33 -0
  320. package/gs/math/signbit.gs.test.ts +33 -0
  321. package/gs/math/signbit.gs.ts +8 -0
  322. package/gs/math/sin.gs.test.ts +83 -0
  323. package/gs/math/sin.gs.ts +38 -0
  324. package/gs/math/sincos.gs.test.ts +91 -0
  325. package/gs/math/sincos.gs.ts +15 -0
  326. package/gs/math/sinh.gs.test.ts +66 -0
  327. package/gs/math/sinh.gs.ts +34 -0
  328. package/gs/math/sqrt.gs.test.ts +49 -0
  329. package/gs/math/sqrt.gs.ts +20 -0
  330. package/gs/math/tan.gs.test.ts +50 -0
  331. package/gs/math/tan.gs.ts +23 -0
  332. package/gs/math/tanh.gs.test.ts +52 -0
  333. package/gs/math/tanh.gs.ts +23 -0
  334. package/gs/math/trig_reduce.gs.ts +66 -0
  335. package/gs/math/unsafe.gs.ts +52 -0
  336. package/gs/strconv/atob.gs.ts +45 -0
  337. package/gs/strconv/atof.gs.ts +60 -0
  338. package/gs/strconv/atoi.gs.ts +243 -0
  339. package/gs/strconv/doc.gs.ts +2 -0
  340. package/gs/strconv/ftoa.gs.ts +66 -0
  341. package/gs/strconv/index.ts +6 -0
  342. package/gs/strconv/itoa.gs.ts +41 -0
  343. package/gs/strconv/quote.gs.ts +245 -0
  344. package/gs/strings/index.ts +4 -0
  345. package/gs/strings/replace.ts +9 -237
  346. package/gs/strings/search.ts +0 -28
  347. package/gs/sync/atomic/doc.gs.ts +276 -0
  348. package/gs/sync/atomic/doc_64.gs.ts +168 -0
  349. package/gs/sync/atomic/index.ts +4 -0
  350. package/gs/sync/atomic/type.gs.ts +596 -0
  351. package/gs/sync/atomic/value.gs.ts +158 -0
  352. package/gs/unsafe/unsafe.ts +6 -0
  353. package/package.json +1 -1
  354. package/gs/maps/iter.gs.ts +0 -71
  355. package/gs/maps/maps.gs.ts +0 -87
  356. package/gs/stringslite/godoc.txt +0 -17
  357. package/gs/stringslite/index.ts +0 -1
  358. package/gs/stringslite/strings.ts +0 -82
@@ -0,0 +1,276 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+
3
+ import * as unsafe from "@goscript/unsafe/index.js"
4
+
5
+ // Type alias for uintptr (pointer-sized unsigned integer)
6
+ export type uintptr = number;
7
+ export type Pointer = any;
8
+
9
+ // SwapInt32 atomically stores new into *addr and returns the previous *addr value.
10
+ // Consider using the more ergonomic and less error-prone [Int32.Swap] instead.
11
+ //
12
+ //go:noescape
13
+ export function SwapInt32(addr: $.VarRef<number> | null, _new: number): number {
14
+ if (!addr) return 0;
15
+ let old = addr.value;
16
+ addr.value = _new;
17
+ return old;
18
+ }
19
+
20
+ // SwapUint32 atomically stores new into *addr and returns the previous *addr value.
21
+ // Consider using the more ergonomic and less error-prone [Uint32.Swap] instead.
22
+ //
23
+ //go:noescape
24
+ export function SwapUint32(addr: $.VarRef<number> | null, _new: number): number {
25
+ if (!addr) return 0;
26
+ let old = addr.value;
27
+ addr.value = _new;
28
+ return old;
29
+ }
30
+
31
+ // SwapUintptr atomically stores new into *addr and returns the previous *addr value.
32
+ // Consider using the more ergonomic and less error-prone [Uintptr.Swap] instead.
33
+ //
34
+ //go:noescape
35
+ export function SwapUintptr(addr: $.VarRef<uintptr> | null, _new: uintptr): uintptr {
36
+ if (!addr) return 0;
37
+ let old = addr.value;
38
+ addr.value = _new;
39
+ return old;
40
+ }
41
+
42
+ // SwapPointer atomically stores new into *addr and returns the previous *addr value.
43
+ // Consider using the more ergonomic and less error-prone [Pointer.Swap] instead.
44
+ export function SwapPointer(addr: $.VarRef<Pointer> | null, _new: Pointer): Pointer {
45
+ if (!addr) return null;
46
+ let old = addr.value;
47
+ addr.value = _new;
48
+ return old;
49
+ }
50
+
51
+ // CompareAndSwapInt32 executes the compare-and-swap operation for an int32 value.
52
+ // Consider using the more ergonomic and less error-prone [Int32.CompareAndSwap] instead.
53
+ //
54
+ //go:noescape
55
+ export function CompareAndSwapInt32(addr: $.VarRef<number> | null, old: number, _new: number): boolean {
56
+ if (!addr) return false;
57
+ if (addr.value === old) {
58
+ addr.value = _new;
59
+ return true;
60
+ }
61
+ return false;
62
+ }
63
+
64
+ // CompareAndSwapUint32 executes the compare-and-swap operation for a uint32 value.
65
+ // Consider using the more ergonomic and less error-prone [Uint32.CompareAndSwap] instead.
66
+ //
67
+ //go:noescape
68
+ export function CompareAndSwapUint32(addr: $.VarRef<number> | null, old: number, _new: number): boolean {
69
+ if (!addr) return false;
70
+ if (addr.value === old) {
71
+ addr.value = _new;
72
+ return true;
73
+ }
74
+ return false;
75
+ }
76
+
77
+ // CompareAndSwapUintptr executes the compare-and-swap operation for a uintptr value.
78
+ // Consider using the more ergonomic and less error-prone [Uintptr.CompareAndSwap] instead.
79
+ //
80
+ //go:noescape
81
+ export function CompareAndSwapUintptr(addr: $.VarRef<uintptr> | null, old: uintptr, _new: uintptr): boolean {
82
+ if (!addr) return false;
83
+ if (addr.value === old) {
84
+ addr.value = _new;
85
+ return true;
86
+ }
87
+ return false;
88
+ }
89
+
90
+ // CompareAndSwapPointer executes the compare-and-swap operation for a unsafe.Pointer value.
91
+ // Consider using the more ergonomic and less error-prone [Pointer.CompareAndSwap] instead.
92
+ export function CompareAndSwapPointer(addr: $.VarRef<Pointer> | null, old: Pointer, _new: Pointer): boolean {
93
+ if (!addr) return false;
94
+ if (addr.value === old) {
95
+ addr.value = _new;
96
+ return true;
97
+ }
98
+ return false;
99
+ }
100
+
101
+ // AddInt32 atomically adds delta to *addr and returns the new value.
102
+ // Consider using the more ergonomic and less error-prone [Int32.Add] instead.
103
+ //
104
+ //go:noescape
105
+ export function AddInt32(addr: $.VarRef<number> | null, delta: number): number {
106
+ if (!addr) return 0;
107
+ addr.value = (addr.value + delta) | 0; // Use bitwise OR to ensure 32-bit signed integer
108
+ return addr.value;
109
+ }
110
+
111
+ // AddUint32 atomically adds delta to *addr and returns the new value.
112
+ // To subtract a signed positive constant value c from x, do AddUint32(&x, ^uint32(c-1)).
113
+ // In particular, to decrement x, do AddUint32(&x, ^uint32(0)).
114
+ // Consider using the more ergonomic and less error-prone [Uint32.Add] instead.
115
+ //
116
+ //go:noescape
117
+ export function AddUint32(addr: $.VarRef<number> | null, delta: number): number {
118
+ if (!addr) return 0;
119
+ addr.value = (addr.value + delta) >>> 0; // Use unsigned right shift to ensure 32-bit unsigned integer
120
+ return addr.value;
121
+ }
122
+
123
+ // AddUintptr atomically adds delta to *addr and returns the new value.
124
+ // Consider using the more ergonomic and less error-prone [Uintptr.Add] instead.
125
+ //
126
+ //go:noescape
127
+ export function AddUintptr(addr: $.VarRef<uintptr> | null, delta: uintptr): uintptr {
128
+ if (!addr) return 0;
129
+ addr.value = (addr.value + delta) >>> 0; // Use unsigned right shift for uintptr
130
+ return addr.value;
131
+ }
132
+
133
+ // AndInt32 atomically performs a bitwise AND operation on *addr using the bitmask provided as mask
134
+ // and returns the old value.
135
+ // Consider using the more ergonomic and less error-prone [Int32.And] instead.
136
+ //
137
+ //go:noescape
138
+ export function AndInt32(addr: $.VarRef<number> | null, mask: number): number {
139
+ if (!addr) return 0;
140
+ let old = addr.value;
141
+ addr.value = (addr.value & mask) | 0; // Use bitwise OR to ensure 32-bit signed integer
142
+ return old;
143
+ }
144
+
145
+ // AndUint32 atomically performs a bitwise AND operation on *addr using the bitmask provided as mask
146
+ // and returns the old value.
147
+ // Consider using the more ergonomic and less error-prone [Uint32.And] instead.
148
+ //
149
+ //go:noescape
150
+ export function AndUint32(addr: $.VarRef<number> | null, mask: number): number {
151
+ if (!addr) return 0;
152
+ let old = addr.value;
153
+ addr.value = (addr.value & mask) >>> 0; // Use unsigned right shift to ensure 32-bit unsigned integer
154
+ return old;
155
+ }
156
+
157
+ // AndUintptr atomically performs a bitwise AND operation on *addr using the bitmask provided as mask
158
+ // and returns the old value.
159
+ // Consider using the more ergonomic and less error-prone [Uintptr.And] instead.
160
+ //
161
+ //go:noescape
162
+ export function AndUintptr(addr: $.VarRef<uintptr> | null, mask: uintptr): uintptr {
163
+ if (!addr) return 0;
164
+ let old = addr.value;
165
+ addr.value = (addr.value & mask) >>> 0; // Use unsigned right shift for uintptr
166
+ return old;
167
+ }
168
+
169
+ // OrInt32 atomically performs a bitwise OR operation on *addr using the bitmask provided as mask
170
+ // and returns the old value.
171
+ // Consider using the more ergonomic and less error-prone [Int32.Or] instead.
172
+ //
173
+ //go:noescape
174
+ export function OrInt32(addr: $.VarRef<number> | null, mask: number): number {
175
+ if (!addr) return 0;
176
+ let old = addr.value;
177
+ addr.value = (addr.value | mask) | 0; // Use bitwise OR to ensure 32-bit signed integer
178
+ return old;
179
+ }
180
+
181
+ // OrUint32 atomically performs a bitwise OR operation on *addr using the bitmask provided as mask
182
+ // and returns the old value.
183
+ // Consider using the more ergonomic and less error-prone [Uint32.Or] instead.
184
+ //
185
+ //go:noescape
186
+ export function OrUint32(addr: $.VarRef<number> | null, mask: number): number {
187
+ if (!addr) return 0;
188
+ let old = addr.value;
189
+ addr.value = (addr.value | mask) >>> 0; // Use unsigned right shift to ensure 32-bit unsigned integer
190
+ return old;
191
+ }
192
+
193
+ // OrUintptr atomically performs a bitwise OR operation on *addr using the bitmask provided as mask
194
+ // and returns the old value.
195
+ // Consider using the more ergonomic and less error-prone [Uintptr.Or] instead.
196
+ //
197
+ //go:noescape
198
+ export function OrUintptr(addr: $.VarRef<uintptr> | null, mask: uintptr): uintptr {
199
+ if (!addr) return 0;
200
+ let old = addr.value;
201
+ addr.value = (addr.value | mask) >>> 0; // Use unsigned right shift for uintptr
202
+ return old;
203
+ }
204
+
205
+ // LoadInt32 atomically loads *addr.
206
+ // Consider using the more ergonomic and less error-prone [Int32.Load] instead.
207
+ //
208
+ //go:noescape
209
+ export function LoadInt32(addr: $.VarRef<number> | null): number {
210
+ if (!addr) return 0;
211
+ return addr.value;
212
+ }
213
+
214
+ // LoadUint32 atomically loads *addr.
215
+ // Consider using the more ergonomic and less error-prone [Uint32.Load] instead.
216
+ //
217
+ //go:noescape
218
+ export function LoadUint32(addr: $.VarRef<number> | null): number {
219
+ if (!addr) return 0;
220
+ return addr.value;
221
+ }
222
+
223
+ // LoadUintptr atomically loads *addr.
224
+ // Consider using the more ergonomic and less error-prone [Uintptr.Load] instead.
225
+ //
226
+ //go:noescape
227
+ export function LoadUintptr(addr: $.VarRef<uintptr> | null): uintptr {
228
+ if (!addr) return 0;
229
+ return addr.value;
230
+ }
231
+
232
+ // LoadPointer atomically loads *addr.
233
+ // Consider using the more ergonomic and less error-prone [Pointer.Load] instead.
234
+ export function LoadPointer(addr: $.VarRef<Pointer> | null): Pointer {
235
+ if (!addr) return null;
236
+ return addr.value;
237
+ }
238
+
239
+ // StoreInt32 atomically stores val into *addr.
240
+ // Consider using the more ergonomic and less error-prone [Int32.Store] instead.
241
+ //
242
+ //go:noescape
243
+ export function StoreInt32(addr: $.VarRef<number> | null, val: number): void {
244
+ if (addr) {
245
+ addr.value = val | 0; // Use bitwise OR to ensure 32-bit signed integer
246
+ }
247
+ }
248
+
249
+ // StoreUint32 atomically stores val into *addr.
250
+ // Consider using the more ergonomic and less error-prone [Uint32.Store] instead.
251
+ //
252
+ //go:noescape
253
+ export function StoreUint32(addr: $.VarRef<number> | null, val: number): void {
254
+ if (addr) {
255
+ addr.value = val >>> 0; // Use unsigned right shift to ensure 32-bit unsigned integer
256
+ }
257
+ }
258
+
259
+ // StoreUintptr atomically stores val into *addr.
260
+ // Consider using the more ergonomic and less error-prone [Uintptr.Store] instead.
261
+ //
262
+ //go:noescape
263
+ export function StoreUintptr(addr: $.VarRef<uintptr> | null, val: uintptr): void {
264
+ if (addr) {
265
+ addr.value = val >>> 0; // Use unsigned right shift for uintptr
266
+ }
267
+ }
268
+
269
+ // StorePointer atomically stores val into *addr.
270
+ // Consider using the more ergonomic and less error-prone [Pointer.Store] instead.
271
+ export function StorePointer(addr: $.VarRef<Pointer> | null, val: Pointer): void {
272
+ if (addr) {
273
+ addr.value = val;
274
+ }
275
+ }
276
+
@@ -0,0 +1,168 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+
3
+ // SwapInt64 atomically stores new into *addr and returns the previous *addr value.
4
+ // Consider using the more ergonomic and less error-prone [Int64.Swap] instead
5
+ // (particularly if you target 32-bit platforms; see the bugs section).
6
+ //
7
+ //go:noescape
8
+ export function SwapInt64(addr: $.VarRef<number> | null, _new: number): number {
9
+ if (!addr) return 0;
10
+ let old = addr.value;
11
+ addr.value = _new;
12
+ return old;
13
+ }
14
+
15
+ // SwapUint64 atomically stores new into *addr and returns the previous *addr value.
16
+ // Consider using the more ergonomic and less error-prone [Uint64.Swap] instead
17
+ // (particularly if you target 32-bit platforms; see the bugs section).
18
+ //
19
+ //go:noescape
20
+ export function SwapUint64(addr: $.VarRef<number> | null, _new: number): number {
21
+ if (!addr) return 0;
22
+ let old = addr.value;
23
+ addr.value = _new;
24
+ return old;
25
+ }
26
+
27
+ // CompareAndSwapInt64 executes the compare-and-swap operation for an int64 value.
28
+ // Consider using the more ergonomic and less error-prone [Int64.CompareAndSwap] instead
29
+ // (particularly if you target 32-bit platforms; see the bugs section).
30
+ //
31
+ //go:noescape
32
+ export function CompareAndSwapInt64(addr: $.VarRef<number> | null, old: number, _new: number): boolean {
33
+ if (!addr) return false;
34
+ if (addr.value === old) {
35
+ addr.value = _new;
36
+ return true;
37
+ }
38
+ return false;
39
+ }
40
+
41
+ // CompareAndSwapUint64 executes the compare-and-swap operation for a uint64 value.
42
+ // Consider using the more ergonomic and less error-prone [Uint64.CompareAndSwap] instead
43
+ // (particularly if you target 32-bit platforms; see the bugs section).
44
+ //
45
+ //go:noescape
46
+ export function CompareAndSwapUint64(addr: $.VarRef<number> | null, old: number, _new: number): boolean {
47
+ if (!addr) return false;
48
+ if (addr.value === old) {
49
+ addr.value = _new;
50
+ return true;
51
+ }
52
+ return false;
53
+ }
54
+
55
+ // AddInt64 atomically adds delta to *addr and returns the new value.
56
+ // Consider using the more ergonomic and less error-prone [Int64.Add] instead
57
+ // (particularly if you target 32-bit platforms; see the bugs section).
58
+ //
59
+ //go:noescape
60
+ export function AddInt64(addr: $.VarRef<number> | null, delta: number): number {
61
+ if (!addr) return 0;
62
+ addr.value = addr.value + delta;
63
+ return addr.value;
64
+ }
65
+
66
+ // AddUint64 atomically adds delta to *addr and returns the new value.
67
+ // To subtract a signed positive constant value c from x, do AddUint64(&x, ^uint64(c-1)).
68
+ // In particular, to decrement x, do AddUint64(&x, ^uint64(0)).
69
+ // Consider using the more ergonomic and less error-prone [Uint64.Add] instead
70
+ // (particularly if you target 32-bit platforms; see the bugs section).
71
+ //
72
+ //go:noescape
73
+ export function AddUint64(addr: $.VarRef<number> | null, delta: number): number {
74
+ if (!addr) return 0;
75
+ addr.value = addr.value + delta;
76
+ return addr.value;
77
+ }
78
+
79
+ // AndInt64 atomically performs a bitwise AND operation on *addr using the bitmask provided as mask
80
+ // and returns the old value.
81
+ // Consider using the more ergonomic and less error-prone [Int64.And] instead.
82
+ //
83
+ //go:noescape
84
+ export function AndInt64(addr: $.VarRef<number> | null, mask: number): number {
85
+ if (!addr) return 0;
86
+ let old = addr.value;
87
+ addr.value = addr.value & mask;
88
+ return old;
89
+ }
90
+
91
+ // AndUint64 atomically performs a bitwise AND operation on *addr using the bitmask provided as mask
92
+ // and returns the old.
93
+ // Consider using the more ergonomic and less error-prone [Uint64.And] instead.
94
+ //
95
+ //go:noescape
96
+ export function AndUint64(addr: $.VarRef<number> | null, mask: number): number {
97
+ if (!addr) return 0;
98
+ let old = addr.value;
99
+ addr.value = addr.value & mask;
100
+ return old;
101
+ }
102
+
103
+ // OrInt64 atomically performs a bitwise OR operation on *addr using the bitmask provided as mask
104
+ // and returns the old value.
105
+ // Consider using the more ergonomic and less error-prone [Int64.Or] instead.
106
+ //
107
+ //go:noescape
108
+ export function OrInt64(addr: $.VarRef<number> | null, mask: number): number {
109
+ if (!addr) return 0;
110
+ let old = addr.value;
111
+ addr.value = addr.value | mask;
112
+ return old;
113
+ }
114
+
115
+ // OrUint64 atomically performs a bitwise OR operation on *addr using the bitmask provided as mask
116
+ // and returns the old value.
117
+ // Consider using the more ergonomic and less error-prone [Uint64.Or] instead.
118
+ //
119
+ //go:noescape
120
+ export function OrUint64(addr: $.VarRef<number> | null, mask: number): number {
121
+ if (!addr) return 0;
122
+ let old = addr.value;
123
+ addr.value = addr.value | mask;
124
+ return old;
125
+ }
126
+
127
+ // LoadInt64 atomically loads *addr.
128
+ // Consider using the more ergonomic and less error-prone [Int64.Load] instead
129
+ // (particularly if you target 32-bit platforms; see the bugs section).
130
+ //
131
+ //go:noescape
132
+ export function LoadInt64(addr: $.VarRef<number> | null): number {
133
+ if (!addr) return 0;
134
+ return addr.value;
135
+ }
136
+
137
+ // LoadUint64 atomically loads *addr.
138
+ // Consider using the more ergonomic and less error-prone [Uint64.Load] instead
139
+ // (particularly if you target 32-bit platforms; see the bugs section).
140
+ //
141
+ //go:noescape
142
+ export function LoadUint64(addr: $.VarRef<number> | null): number {
143
+ if (!addr) return 0;
144
+ return addr.value;
145
+ }
146
+
147
+ // StoreInt64 atomically stores val into *addr.
148
+ // Consider using the more ergonomic and less error-prone [Int64.Store] instead
149
+ // (particularly if you target 32-bit platforms; see the bugs section).
150
+ //
151
+ //go:noescape
152
+ export function StoreInt64(addr: $.VarRef<number> | null, val: number): void {
153
+ if (addr) {
154
+ addr.value = val;
155
+ }
156
+ }
157
+
158
+ // StoreUint64 atomically stores val into *addr.
159
+ // Consider using the more ergonomic and less error-prone [Uint64.Store] instead
160
+ // (particularly if you target 32-bit platforms; see the bugs section).
161
+ //
162
+ //go:noescape
163
+ export function StoreUint64(addr: $.VarRef<number> | null, val: number): void {
164
+ if (addr) {
165
+ addr.value = val;
166
+ }
167
+ }
168
+
@@ -0,0 +1,4 @@
1
+ export { AddInt32, AddUint32, AddUintptr, AndInt32, AndUint32, AndUintptr, CompareAndSwapInt32, CompareAndSwapPointer, CompareAndSwapUint32, CompareAndSwapUintptr, LoadInt32, LoadPointer, LoadUint32, LoadUintptr, OrInt32, OrUint32, OrUintptr, StoreInt32, StorePointer, StoreUint32, StoreUintptr, SwapInt32, SwapPointer, SwapUint32, SwapUintptr } from "./doc.gs.js"
2
+ export { AddInt64, AddUint64, AndInt64, AndUint64, CompareAndSwapInt64, CompareAndSwapUint64, LoadInt64, LoadUint64, OrInt64, OrUint64, StoreInt64, StoreUint64, SwapInt64, SwapUint64 } from "./doc_64.gs.js"
3
+ export { Bool, Int32, Int64, Pointer, Uint32, Uint64, Uintptr } from "./type.gs.js"
4
+ export { Value } from "./value.gs.js"