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,158 @@
1
+ import * as $ from "@goscript/builtin/builtin.js";
2
+ import { CompareAndSwapPointer, LoadPointer, StorePointer, SwapPointer } from "./doc.gs.js";
3
+
4
+ import * as unsafe from "@goscript/unsafe/index.js"
5
+
6
+ // Pointer type for use in efaceWords
7
+ type Pointer = any;
8
+
9
+ // firstStoreInProgress is a placeholder value used during the first store operation
10
+ const firstStoreInProgress = Symbol('firstStoreInProgress');
11
+
12
+ export class Value {
13
+ public get v(): null | any {
14
+ return this._fields.v.value
15
+ }
16
+ public set v(value: null | any) {
17
+ this._fields.v.value = value
18
+ }
19
+
20
+ public _fields: {
21
+ v: $.VarRef<null | any>;
22
+ }
23
+
24
+ constructor(init?: Partial<{v?: null | any}>) {
25
+ this._fields = {
26
+ v: $.varRef(init?.v ?? null)
27
+ }
28
+ }
29
+
30
+ public clone(): Value {
31
+ const cloned = new Value()
32
+ cloned._fields = {
33
+ v: $.varRef(this._fields.v.value)
34
+ }
35
+ return cloned
36
+ }
37
+
38
+ // Load returns the value set by the most recent Store.
39
+ // It returns nil if there has been no call to Store for this Value.
40
+ public Load(): null | any {
41
+ const v = this
42
+ // For JavaScript, we can simplify this since we're single-threaded
43
+ // Just return the stored value directly
44
+ return v._fields.v.value
45
+ }
46
+
47
+ // Store sets the value of the [Value] v to val.
48
+ // All calls to Store for a given Value must use values of the same concrete type.
49
+ // Store of an inconsistent type panics, as does Store(nil).
50
+ public Store(val: null | any): void {
51
+ const v = this
52
+ if (val == null) {
53
+ $.panic("sync/atomic: store of nil value into Value")
54
+ }
55
+ // For JavaScript, store the value directly
56
+ v._fields.v.value = val
57
+ }
58
+
59
+ // Swap stores new into Value and returns the previous value. It returns nil if
60
+ // the Value is empty.
61
+ //
62
+ // All calls to Swap for a given Value must use values of the same concrete
63
+ // type. Swap of an inconsistent type panics, as does Swap(nil).
64
+ public Swap(_new: null | any): null | any {
65
+ const v = this
66
+ if (_new == null) {
67
+ $.panic("sync/atomic: swap of nil value into Value")
68
+ }
69
+ // For JavaScript, swap the values directly
70
+ const old = v._fields.v.value
71
+ v._fields.v.value = _new
72
+ return old
73
+ }
74
+
75
+ // CompareAndSwap executes the compare-and-swap operation for the [Value].
76
+ //
77
+ // All calls to CompareAndSwap for a given Value must use values of the same
78
+ // concrete type. CompareAndSwap of an inconsistent type panics, as does
79
+ // CompareAndSwap(old, nil).
80
+ public CompareAndSwap(old: null | any, _new: null | any): boolean {
81
+ const v = this
82
+ if (_new == null) {
83
+ $.panic("sync/atomic: compare and swap of nil value into Value")
84
+ }
85
+ // For JavaScript, compare and swap directly
86
+ if (v._fields.v.value === old) {
87
+ v._fields.v.value = _new
88
+ return true
89
+ }
90
+ return false
91
+ }
92
+
93
+ // Register this type with the runtime type system
94
+ static __typeInfo = $.registerStructType(
95
+ 'Value',
96
+ new Value(),
97
+ [{ name: "Load", args: [], returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }] }, { name: "Store", args: [{ name: "val", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [] }, { name: "Swap", args: [{ name: "new", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [{ type: { kind: $.TypeKind.Interface, methods: [] } }] }, { name: "CompareAndSwap", args: [{ name: "old", type: { kind: $.TypeKind.Interface, methods: [] } }, { name: "new", type: { kind: $.TypeKind.Interface, methods: [] } }], returns: [{ type: { kind: $.TypeKind.Basic, name: "boolean" } }] }],
98
+ Value,
99
+ {"v": { kind: $.TypeKind.Interface, methods: [] }}
100
+ );
101
+ }
102
+
103
+
104
+ class efaceWords {
105
+ public get typ(): Pointer {
106
+ return this._fields.typ.value
107
+ }
108
+ public set typ(value: Pointer) {
109
+ this._fields.typ.value = value
110
+ }
111
+
112
+ public get data(): Pointer {
113
+ return this._fields.data.value
114
+ }
115
+ public set data(value: Pointer) {
116
+ this._fields.data.value = value
117
+ }
118
+
119
+ public _fields: {
120
+ typ: $.VarRef<Pointer>;
121
+ data: $.VarRef<Pointer>;
122
+ }
123
+
124
+ constructor(init?: Partial<{data?: Pointer, typ?: Pointer}>) {
125
+ this._fields = {
126
+ typ: $.varRef(init?.typ ?? null),
127
+ data: $.varRef(init?.data ?? null)
128
+ }
129
+ }
130
+
131
+ public clone(): efaceWords {
132
+ const cloned = new efaceWords()
133
+ cloned._fields = {
134
+ typ: $.varRef(this._fields.typ.value),
135
+ data: $.varRef(this._fields.data.value)
136
+ }
137
+ return cloned
138
+ }
139
+
140
+ // Register this type with the runtime type system
141
+ static __typeInfo = $.registerStructType(
142
+ 'efaceWords',
143
+ new efaceWords(),
144
+ [],
145
+ efaceWords,
146
+ {"data": { kind: $.TypeKind.Basic, name: "Pointer" }, "typ": { kind: $.TypeKind.Basic, name: "Pointer" }}
147
+ );
148
+ }
149
+
150
+ // Runtime functions for pinning/unpinning (no-ops in JavaScript)
151
+ export function runtime_procPin(): number {
152
+ return 0; // No-op in JavaScript
153
+ }
154
+
155
+ export function runtime_procUnpin(): void {
156
+ // No-op in JavaScript
157
+ }
158
+
@@ -75,3 +75,9 @@ export function StringData(_str: string): Pointer {
75
75
  'unsafe.StringData is not supported in JavaScript/TypeScript: direct memory access is not available in JavaScript',
76
76
  )
77
77
  }
78
+
79
+ // Pointer converts a value to an unsafe.Pointer for atomic operations
80
+ // In JavaScript/TypeScript, this is just a pass-through function
81
+ export function Pointer(value: any): Pointer {
82
+ return value;
83
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "goscript",
3
3
  "description": "Go to TypeScript transpiler",
4
- "version": "0.0.34",
4
+ "version": "0.0.36",
5
5
  "author": {
6
6
  "name": "Aperture Robotics LLC.",
7
7
  "email": "support@aperture.us",
@@ -1,71 +0,0 @@
1
- import * as $ from "@goscript/builtin/builtin.js";
2
-
3
- import * as iter from "@goscript/iter/index.js"
4
-
5
- // All returns an iterator over key-value pairs from m.
6
- // The iteration order is not specified and is not guaranteed
7
- // to be the same from one call to the next.
8
- export function All<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq2<K, V> {
9
- return (_yield: ((p0: K, p1: V) => boolean) | null): void => {
10
- for (const [k, v] of m.entries()) {
11
- {
12
- if (!_yield!(k, v)) {
13
- return
14
- }
15
- }
16
- }
17
- }
18
- }
19
-
20
- // Keys returns an iterator over keys in m.
21
- // The iteration order is not specified and is not guaranteed
22
- // to be the same from one call to the next.
23
- export function Keys<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq<K> {
24
- return (_yield: ((p0: K) => boolean) | null): void => {
25
- for (const [k, _v] of m.entries()) {
26
- {
27
- if (!_yield!(k)) {
28
- return
29
- }
30
- }
31
- }
32
- }
33
- }
34
-
35
- // Values returns an iterator over values in m.
36
- // The iteration order is not specified and is not guaranteed
37
- // to be the same from one call to the next.
38
- export function Values<K extends $.Comparable, V>(m: Map<K, V>): iter.Seq<V> {
39
- return (_yield: ((p0: V) => boolean) | null): void => {
40
- for (const [_k, v] of m.entries()) {
41
- {
42
- if (!_yield!(v)) {
43
- return
44
- }
45
- }
46
- }
47
- }
48
- }
49
-
50
- // Insert adds the key-value pairs from seq to m.
51
- // If a key in seq already exists in m, its value will be overwritten.
52
- export function Insert<K extends $.Comparable, V>(m: Map<K, V>, seq: iter.Seq2<K, V>): void {
53
- ;(() => {
54
- let shouldContinue = true
55
- seq!((k, v) => {
56
- {
57
- $.mapSet(m, k, v)
58
- }
59
- return shouldContinue
60
- })
61
- })()
62
- }
63
-
64
- // Collect collects key-value pairs from seq into a new map
65
- // and returns it.
66
- export function Collect<K extends $.Comparable, V extends any>(seq: iter.Seq2<K, V>): Map<K, V> {
67
- let m = $.makeMap<K, V>()
68
- Insert(m, seq)
69
- return m
70
- }
71
-
@@ -1,87 +0,0 @@
1
- import * as $ from "@goscript/builtin/builtin.js";
2
-
3
- import * as _ from "@goscript/unsafe/index.js"
4
-
5
- // Equal reports whether two maps contain the same key/value pairs.
6
- // Values are compared using ==.
7
- export function Equal<K extends $.Comparable, V extends $.Comparable>(m1: Map<K, V>, m2: Map<K, V>): boolean {
8
- if ($.len(m1) != $.len(m2)) {
9
- return false
10
- }
11
- for (const [k, v1] of m1.entries()) {
12
- {
13
- {
14
- let [v2, ok] = $.mapGet(m2, k, null as any)
15
- if (!ok || v1 != v2) {
16
- return false
17
- }
18
- }
19
- }
20
- }
21
- return true
22
- }
23
-
24
- // EqualFunc is like Equal, but compares values using eq.
25
- // Keys are still compared with ==.
26
- export function EqualFunc<K extends $.Comparable, V1, V2>(m1: Map<K, V1>, m2: Map<K, V2>, eq: ((p0: V1, p1: V2) => boolean) | null): boolean {
27
- if ($.len(m1) != $.len(m2)) {
28
- return false
29
- }
30
- for (const [k, v1] of m1.entries()) {
31
- {
32
- {
33
- let [v2, ok] = $.mapGet(m2, k, null as any)
34
- if (!ok || !eq!(v1, v2)) {
35
- return false
36
- }
37
- }
38
- }
39
- }
40
- return true
41
- }
42
-
43
- // clone returns a shallow copy of the map.
44
- export function clone<K extends $.Comparable, V>(m: Map<K, V> | null): Map<K, V> | null {
45
- if (m == null) {
46
- return null
47
- }
48
- const result = $.makeMap<K, V>()
49
- for (const [k, v] of m.entries()) {
50
- $.mapSet(result, k, v)
51
- }
52
- return result
53
- }
54
-
55
- // Clone returns a copy of m. This is a shallow clone:
56
- // the new keys and values are set using ordinary assignment.
57
- export function Clone<K extends $.Comparable, V>(m: Map<K, V>): Map<K, V> {
58
- // Preserve nil in case it matters.
59
- if (m == null) {
60
- return null as unknown as Map<K, V>
61
- }
62
- return clone(m)!
63
- }
64
-
65
- // Copy copies all key/value pairs in src adding them to dst.
66
- // When a key in src is already present in dst,
67
- // the value in dst will be overwritten by the value associated
68
- // with the key in src.
69
- export function Copy<K extends $.Comparable, V>(dst: Map<K, V>, src: Map<K, V>): void {
70
- for (const [k, v] of src.entries()) {
71
- {
72
- $.mapSet(dst, k, v)
73
- }
74
- }
75
- }
76
-
77
- // DeleteFunc deletes any key/value pairs from m for which del returns true.
78
- export function DeleteFunc<K extends $.Comparable, V>(m: Map<K, V>, del: ((p0: K, p1: V) => boolean) | null): void {
79
- for (const [k, v] of m.entries()) {
80
- {
81
- if (del!(k, v)) {
82
- $.deleteMapEntry(m, k)
83
- }
84
- }
85
- }
86
- }
87
-
@@ -1,17 +0,0 @@
1
- package stringslite // import "internal/stringslite"
2
-
3
- Package stringslite implements a subset of strings, only using packages that may
4
- be imported by "os".
5
-
6
- Tests for these functions are in the strings package.
7
-
8
- func Clone(s string) string
9
- func Cut(s, sep string) (before, after string, found bool)
10
- func CutPrefix(s, prefix string) (after string, found bool)
11
- func CutSuffix(s, suffix string) (before string, found bool)
12
- func HasPrefix(s, prefix string) bool
13
- func HasSuffix(s, suffix string) bool
14
- func Index(s, substr string) int
15
- func IndexByte(s string, c byte) int
16
- func TrimPrefix(s, prefix string) string
17
- func TrimSuffix(s, suffix string) string
@@ -1 +0,0 @@
1
- export * from './strings'
@@ -1,82 +0,0 @@
1
- import * as $ from '@goscript/builtin/builtin.js'
2
-
3
- import * as unsafe from '@goscript/unsafe/index.js'
4
-
5
- export function HasPrefix(s: string, prefix: string): boolean {
6
- return (
7
- $.len(s) >= $.len(prefix) &&
8
- $.sliceString(s, undefined, $.len(prefix)) == prefix
9
- )
10
- }
11
-
12
- export function HasSuffix(s: string, suffix: string): boolean {
13
- return (
14
- $.len(s) >= $.len(suffix) &&
15
- $.sliceString(s, $.len(s) - $.len(suffix), undefined) == suffix
16
- )
17
- }
18
-
19
- export function IndexByte(s: string, c: number): number {
20
- const char = String.fromCharCode(c)
21
- return s.indexOf(char)
22
- }
23
-
24
- export function Index(s: string, substr: string): number {
25
- if (substr === '') {
26
- return 0
27
- }
28
- return s.indexOf(substr)
29
- }
30
-
31
- export function Cut(s: string, sep: string): [string, string, boolean] {
32
- let i = Index(s, sep)
33
- if (i >= 0) {
34
- return [
35
- $.sliceString(s, undefined, i),
36
- $.sliceString(s, i + $.len(sep), undefined),
37
- true,
38
- ]
39
- }
40
- return [s, '', false]
41
- }
42
-
43
- export function CutPrefix(s: string, prefix: string): [string, boolean] {
44
- if (!HasPrefix(s, prefix)) {
45
- return [s, false]
46
- }
47
- return [$.sliceString(s, $.len(prefix), undefined), true]
48
- }
49
-
50
- export function CutSuffix(s: string, suffix: string): [string, boolean] {
51
- if (!HasSuffix(s, suffix)) {
52
- return [s, false]
53
- }
54
- return [$.sliceString(s, undefined, $.len(s) - $.len(suffix)), true]
55
- }
56
-
57
- export function TrimPrefix(s: string, prefix: string): string {
58
- if (HasPrefix(s, prefix)) {
59
- return $.sliceString(s, $.len(prefix), undefined)
60
- }
61
- return s
62
- }
63
-
64
- export function TrimSuffix(s: string, suffix: string): string {
65
- if (HasSuffix(s, suffix)) {
66
- return $.sliceString(s, undefined, $.len(s) - $.len(suffix))
67
- }
68
- return s
69
- }
70
-
71
- export function Clone(s: string): string {
72
- if ($.len(s) == 0) {
73
- return ''
74
- }
75
- let b = new Uint8Array($.len(s))
76
- $.copy(b, s)
77
- return unsafe.String(b![0], $.len(b))
78
- }
79
-
80
- export function CopyBytes(b: Uint8Array, s: string): number {
81
- return $.copy(b, s)
82
- }