goscript 0.1.1 → 0.1.2

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 (356) hide show
  1. package/cmd/goscript/cmd-test.go +104 -11
  2. package/cmd/goscript/cmd-test_test.go +1 -1
  3. package/cmd/goscript/cmd_compile.go +9 -0
  4. package/compiler/compile-request.go +31 -0
  5. package/compiler/compiler.go +1 -1
  6. package/compiler/compliance_test.go +0 -2
  7. package/compiler/config.go +2 -0
  8. package/compiler/gotest/package-result.go +2 -0
  9. package/compiler/gotest/request.go +85 -20
  10. package/compiler/gotest/runner.go +733 -96
  11. package/compiler/gotest/runner_test.go +647 -3
  12. package/compiler/lowered-program.go +9 -2
  13. package/compiler/lowering.go +2001 -345
  14. package/compiler/override-facts.go +77 -27
  15. package/compiler/override-registry.go +5 -4
  16. package/compiler/override-registry_test.go +135 -0
  17. package/compiler/package-graph_test.go +62 -7
  18. package/compiler/package-test-graph-variant.go +40 -16
  19. package/compiler/package-test-graph.go +0 -5
  20. package/compiler/package-test-graph_test.go +61 -3
  21. package/compiler/runtime-contract.go +40 -0
  22. package/compiler/semantic-model-types.go +16 -0
  23. package/compiler/semantic-model.go +336 -91
  24. package/compiler/semantic-model_test.go +50 -1
  25. package/compiler/service.go +9 -3
  26. package/compiler/skeleton_test.go +1921 -298
  27. package/compiler/tsworkspace/owner-process-unix_test.go +72 -0
  28. package/compiler/tsworkspace/owner.go +8 -0
  29. package/compiler/tsworkspace/tool-process-other.go +14 -0
  30. package/compiler/tsworkspace/tool-process-unix.go +19 -0
  31. package/compiler/typescript-emitter.go +122 -9
  32. package/dist/gs/builtin/builtin.d.ts +20 -1
  33. package/dist/gs/builtin/builtin.js +246 -26
  34. package/dist/gs/builtin/builtin.js.map +1 -1
  35. package/dist/gs/builtin/channel.d.ts +24 -10
  36. package/dist/gs/builtin/channel.js +107 -25
  37. package/dist/gs/builtin/channel.js.map +1 -1
  38. package/dist/gs/builtin/defer.d.ts +1 -0
  39. package/dist/gs/builtin/defer.js +12 -2
  40. package/dist/gs/builtin/defer.js.map +1 -1
  41. package/dist/gs/builtin/hostio.d.ts +9 -0
  42. package/dist/gs/builtin/hostio.js +25 -0
  43. package/dist/gs/builtin/hostio.js.map +1 -1
  44. package/dist/gs/builtin/map.js +40 -6
  45. package/dist/gs/builtin/map.js.map +1 -1
  46. package/dist/gs/builtin/print.js.map +1 -1
  47. package/dist/gs/builtin/slice.d.ts +43 -9
  48. package/dist/gs/builtin/slice.js +437 -234
  49. package/dist/gs/builtin/slice.js.map +1 -1
  50. package/dist/gs/builtin/type.d.ts +2 -0
  51. package/dist/gs/builtin/type.js +47 -7
  52. package/dist/gs/builtin/type.js.map +1 -1
  53. package/dist/gs/builtin/varRef.d.ts +2 -0
  54. package/dist/gs/builtin/varRef.js.map +1 -1
  55. package/dist/gs/bytes/buffer.gs.js +28 -28
  56. package/dist/gs/bytes/buffer.gs.js.map +1 -1
  57. package/dist/gs/bytes/iter.gs.js +13 -13
  58. package/dist/gs/bytes/iter.gs.js.map +1 -1
  59. package/dist/gs/compress/zlib/index.d.ts +26 -0
  60. package/dist/gs/compress/zlib/index.js +168 -0
  61. package/dist/gs/compress/zlib/index.js.map +1 -0
  62. package/dist/gs/context/context.d.ts +1 -1
  63. package/dist/gs/context/context.js +8 -3
  64. package/dist/gs/context/context.js.map +1 -1
  65. package/dist/gs/crypto/ecdh/index.d.ts +52 -0
  66. package/dist/gs/crypto/ecdh/index.js +226 -0
  67. package/dist/gs/crypto/ecdh/index.js.map +1 -0
  68. package/dist/gs/crypto/ed25519/index.d.ts +34 -0
  69. package/dist/gs/crypto/ed25519/index.js +160 -0
  70. package/dist/gs/crypto/ed25519/index.js.map +1 -0
  71. package/dist/gs/crypto/internal/constanttime/index.d.ts +4 -0
  72. package/dist/gs/crypto/internal/constanttime/index.js +18 -0
  73. package/dist/gs/crypto/internal/constanttime/index.js.map +1 -0
  74. package/dist/gs/crypto/rand/index.d.ts +2 -0
  75. package/dist/gs/crypto/rand/index.js +85 -0
  76. package/dist/gs/crypto/rand/index.js.map +1 -1
  77. package/dist/gs/crypto/sha256/index.d.ts +8 -0
  78. package/dist/gs/crypto/sha256/index.js +118 -0
  79. package/dist/gs/crypto/sha256/index.js.map +1 -0
  80. package/dist/gs/crypto/sha512/index.d.ts +14 -0
  81. package/dist/gs/crypto/sha512/index.js +129 -0
  82. package/dist/gs/crypto/sha512/index.js.map +1 -0
  83. package/dist/gs/encoding/json/index.d.ts +3 -0
  84. package/dist/gs/encoding/json/index.js +15 -0
  85. package/dist/gs/encoding/json/index.js.map +1 -1
  86. package/dist/gs/errors/errors.js +29 -6
  87. package/dist/gs/errors/errors.js.map +1 -1
  88. package/dist/gs/fmt/fmt.js.map +1 -1
  89. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.d.ts +7 -7
  90. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js +52 -18
  91. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/index.js.map +1 -1
  92. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js +56 -20
  93. package/dist/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.js.map +1 -1
  94. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.d.ts +57 -3
  95. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js +366 -1
  96. package/dist/gs/github.com/aperturerobotics/starpc/srpc/index.js.map +1 -1
  97. package/dist/gs/github.com/aperturerobotics/util/conc/index.d.ts +20 -0
  98. package/dist/gs/github.com/aperturerobotics/util/conc/index.js +134 -0
  99. package/dist/gs/github.com/aperturerobotics/util/conc/index.js.map +1 -0
  100. package/dist/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.js.map +1 -1
  101. package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.d.ts +3 -0
  102. package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.js +50 -0
  103. package/dist/gs/github.com/hack-pad/safejs/internal/catch/index.js.map +1 -0
  104. package/dist/gs/github.com/klauspost/compress/internal/le/index.js +3 -2
  105. package/dist/gs/github.com/klauspost/compress/internal/le/index.js.map +1 -1
  106. package/dist/gs/github.com/mr-tron/base58/base58/index.d.ts +27 -0
  107. package/dist/gs/github.com/mr-tron/base58/base58/index.js +172 -0
  108. package/dist/gs/github.com/mr-tron/base58/base58/index.js.map +1 -0
  109. package/dist/gs/github.com/zeebo/blake3/internal/consts/index.d.ts +21 -0
  110. package/dist/gs/github.com/zeebo/blake3/internal/consts/index.js +22 -0
  111. package/dist/gs/github.com/zeebo/blake3/internal/consts/index.js.map +1 -0
  112. package/dist/gs/go/token/index.js +11 -4
  113. package/dist/gs/go/token/index.js.map +1 -1
  114. package/dist/gs/hash/fnv/index.d.ts +57 -0
  115. package/dist/gs/hash/fnv/index.js +299 -0
  116. package/dist/gs/hash/fnv/index.js.map +1 -0
  117. package/dist/gs/hash/index.d.ts +17 -0
  118. package/dist/gs/hash/index.js +94 -0
  119. package/dist/gs/hash/index.js.map +1 -0
  120. package/dist/gs/io/fs/readlink.js +2 -6
  121. package/dist/gs/io/fs/readlink.js.map +1 -1
  122. package/dist/gs/io/fs/walk.js.map +1 -1
  123. package/dist/gs/io/io.js.map +1 -1
  124. package/dist/gs/iter/iter.d.ts +3 -2
  125. package/dist/gs/iter/iter.js.map +1 -1
  126. package/dist/gs/maps/iter.d.ts +5 -5
  127. package/dist/gs/maps/iter.js +48 -21
  128. package/dist/gs/maps/iter.js.map +1 -1
  129. package/dist/gs/maps/maps.d.ts +6 -6
  130. package/dist/gs/math/bits/index.js +14 -24
  131. package/dist/gs/math/bits/index.js.map +1 -1
  132. package/dist/gs/mime/index.js +3 -1
  133. package/dist/gs/mime/index.js.map +1 -1
  134. package/dist/gs/net/http/httptest/index.d.ts +20 -1
  135. package/dist/gs/net/http/httptest/index.js +83 -3
  136. package/dist/gs/net/http/httptest/index.js.map +1 -1
  137. package/dist/gs/net/http/index.d.ts +110 -6
  138. package/dist/gs/net/http/index.js +262 -16
  139. package/dist/gs/net/http/index.js.map +1 -1
  140. package/dist/gs/net/http/pprof/index.d.ts +8 -0
  141. package/dist/gs/net/http/pprof/index.js +59 -0
  142. package/dist/gs/net/http/pprof/index.js.map +1 -0
  143. package/dist/gs/os/error.gs.js +9 -7
  144. package/dist/gs/os/error.gs.js.map +1 -1
  145. package/dist/gs/os/types_js.gs.js +95 -15
  146. package/dist/gs/os/types_js.gs.js.map +1 -1
  147. package/dist/gs/path/filepath/match.js.map +1 -1
  148. package/dist/gs/path/filepath/path.d.ts +5 -3
  149. package/dist/gs/path/filepath/path.js +65 -10
  150. package/dist/gs/path/filepath/path.js.map +1 -1
  151. package/dist/gs/reflect/index.d.ts +3 -2
  152. package/dist/gs/reflect/index.js +2 -1
  153. package/dist/gs/reflect/index.js.map +1 -1
  154. package/dist/gs/reflect/iter.js +2 -2
  155. package/dist/gs/reflect/iter.js.map +1 -1
  156. package/dist/gs/reflect/map.js +26 -0
  157. package/dist/gs/reflect/map.js.map +1 -1
  158. package/dist/gs/reflect/type.d.ts +24 -5
  159. package/dist/gs/reflect/type.js +390 -38
  160. package/dist/gs/reflect/type.js.map +1 -1
  161. package/dist/gs/reflect/types.d.ts +1 -0
  162. package/dist/gs/reflect/types.js +3 -1
  163. package/dist/gs/reflect/types.js.map +1 -1
  164. package/dist/gs/reflect/value.d.ts +4 -1
  165. package/dist/gs/reflect/value.js +39 -1
  166. package/dist/gs/reflect/value.js.map +1 -1
  167. package/dist/gs/reflect/visiblefields.js +1 -1
  168. package/dist/gs/reflect/visiblefields.js.map +1 -1
  169. package/dist/gs/runtime/debug/index.d.ts +39 -0
  170. package/dist/gs/runtime/debug/index.js +58 -0
  171. package/dist/gs/runtime/debug/index.js.map +1 -1
  172. package/dist/gs/runtime/pprof/index.d.ts +20 -0
  173. package/dist/gs/runtime/pprof/index.js +85 -0
  174. package/dist/gs/runtime/pprof/index.js.map +1 -0
  175. package/dist/gs/runtime/trace/index.d.ts +19 -0
  176. package/dist/gs/runtime/trace/index.js +64 -0
  177. package/dist/gs/runtime/trace/index.js.map +1 -0
  178. package/dist/gs/slices/slices.d.ts +24 -9
  179. package/dist/gs/slices/slices.js +229 -24
  180. package/dist/gs/slices/slices.js.map +1 -1
  181. package/dist/gs/sort/slice.gs.d.ts +5 -3
  182. package/dist/gs/sort/slice.gs.js +55 -17
  183. package/dist/gs/sort/slice.gs.js.map +1 -1
  184. package/dist/gs/strings/builder.js +26 -17
  185. package/dist/gs/strings/builder.js.map +1 -1
  186. package/dist/gs/strings/iter.js +140 -75
  187. package/dist/gs/strings/iter.js.map +1 -1
  188. package/dist/gs/strings/replace.js +2 -2
  189. package/dist/gs/strings/replace.js.map +1 -1
  190. package/dist/gs/strings/strings.js +52 -6
  191. package/dist/gs/strings/strings.js.map +1 -1
  192. package/dist/gs/sync/sync.d.ts +6 -3
  193. package/dist/gs/sync/sync.js +39 -11
  194. package/dist/gs/sync/sync.js.map +1 -1
  195. package/dist/gs/syscall/errors.d.ts +116 -112
  196. package/dist/gs/syscall/errors.js +38 -1
  197. package/dist/gs/syscall/errors.js.map +1 -1
  198. package/dist/gs/syscall/fs.d.ts +2 -8
  199. package/dist/gs/syscall/fs.js.map +1 -1
  200. package/dist/gs/syscall/js/index.js +20 -12
  201. package/dist/gs/syscall/js/index.js.map +1 -1
  202. package/dist/gs/syscall/types.d.ts +4 -1
  203. package/dist/gs/syscall/types.js.map +1 -1
  204. package/dist/gs/testing/testing.d.ts +4 -3
  205. package/dist/gs/testing/testing.js +21 -4
  206. package/dist/gs/testing/testing.js.map +1 -1
  207. package/dist/gs/time/time.js +22 -0
  208. package/dist/gs/time/time.js.map +1 -1
  209. package/dist/gs/unicode/unicode.js.map +1 -1
  210. package/dist/gs/unique/index.js +7 -2
  211. package/dist/gs/unique/index.js.map +1 -1
  212. package/go.mod +8 -8
  213. package/go.sum +14 -23
  214. package/gs/builtin/builtin.ts +364 -37
  215. package/gs/builtin/channel.ts +161 -29
  216. package/gs/builtin/defer.ts +13 -2
  217. package/gs/builtin/hostio.test.ts +1 -0
  218. package/gs/builtin/hostio.ts +38 -0
  219. package/gs/builtin/map.ts +46 -6
  220. package/gs/builtin/print.ts +12 -3
  221. package/gs/builtin/runtime-contract.test.ts +257 -10
  222. package/gs/builtin/slice.test.ts +70 -0
  223. package/gs/builtin/slice.ts +566 -255
  224. package/gs/builtin/type.ts +53 -9
  225. package/gs/builtin/varRef.ts +2 -0
  226. package/gs/bytes/buffer.gs.ts +28 -28
  227. package/gs/bytes/iter.gs.ts +13 -14
  228. package/gs/compress/zlib/index.test.ts +28 -0
  229. package/gs/compress/zlib/index.ts +200 -0
  230. package/gs/compress/zlib/meta.json +3 -0
  231. package/gs/context/context.test.ts +31 -1
  232. package/gs/context/context.ts +9 -4
  233. package/gs/crypto/ecdh/index.test.ts +43 -0
  234. package/gs/crypto/ecdh/index.ts +274 -0
  235. package/gs/crypto/ed25519/index.test.ts +41 -0
  236. package/gs/crypto/ed25519/index.ts +238 -0
  237. package/gs/crypto/ed25519/meta.json +13 -0
  238. package/gs/crypto/internal/constanttime/index.test.ts +25 -0
  239. package/gs/crypto/internal/constanttime/index.ts +22 -0
  240. package/gs/crypto/rand/index.test.ts +89 -1
  241. package/gs/crypto/rand/index.ts +103 -1
  242. package/gs/crypto/rand/meta.json +4 -1
  243. package/gs/crypto/sha256/index.test.ts +78 -0
  244. package/gs/crypto/sha256/index.ts +150 -0
  245. package/gs/crypto/sha256/meta.json +9 -0
  246. package/gs/crypto/sha512/index.test.ts +31 -0
  247. package/gs/crypto/sha512/index.ts +161 -0
  248. package/gs/crypto/sha512/meta.json +11 -0
  249. package/gs/encoding/json/index.test.ts +25 -3
  250. package/gs/encoding/json/index.ts +21 -3
  251. package/gs/errors/errors.test.ts +4 -1
  252. package/gs/errors/errors.ts +32 -8
  253. package/gs/fmt/fmt.test.ts +3 -1
  254. package/gs/fmt/fmt.ts +1 -5
  255. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.test.ts +62 -7
  256. package/gs/github.com/aperturerobotics/protobuf-go-lite/index.ts +78 -36
  257. package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.test.ts +32 -11
  258. package/gs/github.com/aperturerobotics/protobuf-go-lite/json/index.ts +122 -43
  259. package/gs/github.com/aperturerobotics/starpc/srpc/index.test.ts +31 -0
  260. package/gs/github.com/aperturerobotics/starpc/srpc/index.ts +518 -4
  261. package/gs/github.com/aperturerobotics/starpc/srpc/meta.json +6 -0
  262. package/gs/github.com/aperturerobotics/util/conc/index.test.ts +30 -0
  263. package/gs/github.com/aperturerobotics/util/conc/index.ts +172 -0
  264. package/gs/github.com/aperturerobotics/util/conc/meta.json +9 -0
  265. package/gs/github.com/aperturerobotics/wasivm/wazero/kernel/runtime/browser/browser.ts +1 -4
  266. package/gs/github.com/hack-pad/safejs/internal/catch/index.test.ts +35 -0
  267. package/gs/github.com/hack-pad/safejs/internal/catch/index.ts +65 -0
  268. package/gs/github.com/hack-pad/safejs/internal/catch/meta.json +9 -0
  269. package/gs/github.com/klauspost/compress/internal/le/index.test.ts +2 -1
  270. package/gs/github.com/klauspost/compress/internal/le/index.ts +6 -5
  271. package/gs/github.com/mr-tron/base58/base58/index.test.ts +70 -0
  272. package/gs/github.com/mr-tron/base58/base58/index.ts +231 -0
  273. package/gs/github.com/mr-tron/base58/base58/meta.json +3 -0
  274. package/gs/github.com/zeebo/blake3/internal/consts/index.test.ts +46 -0
  275. package/gs/github.com/zeebo/blake3/internal/consts/index.ts +26 -0
  276. package/gs/go/token/index.ts +17 -4
  277. package/gs/hash/fnv/index.test.ts +67 -0
  278. package/gs/hash/fnv/index.ts +351 -0
  279. package/gs/hash/fnv/meta.json +3 -0
  280. package/gs/hash/index.test.ts +37 -0
  281. package/gs/hash/index.ts +118 -0
  282. package/gs/hash/meta.json +5 -0
  283. package/gs/internal/byteorder/index.test.ts +6 -6
  284. package/gs/io/fs/readlink.ts +40 -48
  285. package/gs/io/fs/walk.ts +10 -2
  286. package/gs/io/io.ts +4 -1
  287. package/gs/iter/iter.ts +8 -2
  288. package/gs/maps/iter.ts +69 -26
  289. package/gs/maps/maps.test.ts +23 -0
  290. package/gs/maps/maps.ts +6 -6
  291. package/gs/math/bits/index.test.ts +20 -0
  292. package/gs/math/bits/index.ts +15 -28
  293. package/gs/mime/index.ts +8 -2
  294. package/gs/net/http/httptest/index.test.ts +53 -0
  295. package/gs/net/http/httptest/index.ts +98 -3
  296. package/gs/net/http/index.test.ts +129 -1
  297. package/gs/net/http/index.ts +370 -19
  298. package/gs/net/http/meta.json +6 -0
  299. package/gs/net/http/pprof/index.test.ts +47 -0
  300. package/gs/net/http/pprof/index.ts +65 -0
  301. package/gs/os/error.gs.ts +9 -10
  302. package/gs/os/error.test.ts +41 -0
  303. package/gs/os/file_unix_js.test.ts +55 -0
  304. package/gs/os/tempfile.gs.test.ts +37 -10
  305. package/gs/os/types_js.gs.ts +94 -15
  306. package/gs/path/filepath/match.ts +4 -1
  307. package/gs/path/filepath/meta.json +6 -0
  308. package/gs/path/filepath/path.test.ts +57 -2
  309. package/gs/path/filepath/path.ts +91 -12
  310. package/gs/reflect/field.test.ts +63 -0
  311. package/gs/reflect/index.ts +4 -1
  312. package/gs/reflect/iter.ts +2 -2
  313. package/gs/reflect/map.test.ts +24 -2
  314. package/gs/reflect/map.ts +35 -0
  315. package/gs/reflect/type.ts +543 -60
  316. package/gs/reflect/typefor.test.ts +100 -0
  317. package/gs/reflect/types.ts +3 -1
  318. package/gs/reflect/value.ts +50 -1
  319. package/gs/reflect/visiblefields.ts +1 -1
  320. package/gs/runtime/debug/index.test.ts +22 -1
  321. package/gs/runtime/debug/index.ts +88 -0
  322. package/gs/runtime/pprof/index.test.ts +36 -0
  323. package/gs/runtime/pprof/index.ts +104 -0
  324. package/gs/runtime/pprof/meta.json +6 -0
  325. package/gs/runtime/trace/index.test.ts +45 -0
  326. package/gs/runtime/trace/index.ts +97 -0
  327. package/gs/runtime/trace/meta.json +7 -0
  328. package/gs/slices/meta.json +2 -1
  329. package/gs/slices/slices.test.ts +86 -0
  330. package/gs/slices/slices.ts +284 -37
  331. package/gs/sort/slice.gs.ts +73 -23
  332. package/gs/sort/slice.test.ts +40 -0
  333. package/gs/strings/builder.test.ts +8 -0
  334. package/gs/strings/builder.ts +29 -17
  335. package/gs/strings/iter.test.ts +5 -7
  336. package/gs/strings/iter.ts +146 -71
  337. package/gs/strings/replace.test.ts +1 -4
  338. package/gs/strings/replace.ts +6 -6
  339. package/gs/strings/strings.test.ts +4 -0
  340. package/gs/strings/strings.ts +54 -6
  341. package/gs/sync/sync.test.ts +57 -1
  342. package/gs/sync/sync.ts +45 -13
  343. package/gs/syscall/errors.ts +158 -115
  344. package/gs/syscall/fs.ts +8 -8
  345. package/gs/syscall/js/index.ts +49 -22
  346. package/gs/syscall/net.test.ts +26 -0
  347. package/gs/syscall/types.ts +7 -2
  348. package/gs/testing/testing.test.ts +56 -0
  349. package/gs/testing/testing.ts +27 -10
  350. package/gs/time/meta.json +2 -2
  351. package/gs/time/time.test.ts +4 -0
  352. package/gs/time/time.ts +33 -2
  353. package/gs/unicode/unicode.test.ts +14 -3
  354. package/gs/unicode/unicode.ts +1 -5
  355. package/gs/unique/index.ts +9 -2
  356. package/package.json +3 -3
@@ -0,0 +1,26 @@
1
+ export const IV0 = 0x6a09e667
2
+ export const IV1 = 0xbb67ae85
3
+ export const IV2 = 0x3c6ef372
4
+ export const IV3 = 0xa54ff53a
5
+ export const IV4 = 0x510e527f
6
+ export const IV5 = 0x9b05688c
7
+ export const IV6 = 0x1f83d9ab
8
+ export const IV7 = 0x5be0cd19
9
+
10
+ export const IV: number[] = [IV0, IV1, IV2, IV3, IV4, IV5, IV6, IV7]
11
+
12
+ export const Flag_ChunkStart = 1 << 0
13
+ export const Flag_ChunkEnd = 1 << 1
14
+ export const Flag_Parent = 1 << 2
15
+ export const Flag_Root = 1 << 3
16
+ export const Flag_Keyed = 1 << 4
17
+ export const Flag_DeriveKeyContext = 1 << 5
18
+ export const Flag_DeriveKeyMaterial = 1 << 6
19
+
20
+ export const BlockLen = 64
21
+ export const ChunkLen = 1024
22
+
23
+ export const HasAVX2 = false
24
+ export const HasSSE41 = false
25
+
26
+ export const OptimizeLittleEndian = false
@@ -368,7 +368,10 @@ export class File {
368
368
 
369
369
  public AddLine(offset: number): void {
370
370
  const last = this.linesValue[this.linesValue.length - 1]
371
- if ((this.linesValue.length === 0 || last < offset) && offset < this.sizeValue) {
371
+ if (
372
+ (this.linesValue.length === 0 || last < offset) &&
373
+ offset < this.sizeValue
374
+ ) {
372
375
  this.linesValue.push(offset)
373
376
  }
374
377
  }
@@ -428,8 +431,16 @@ export class File {
428
431
  column: number,
429
432
  ): void {
430
433
  const last = this.infosValue[this.infosValue.length - 1]
431
- if ((this.infosValue.length === 0 || last.Offset < offset) && offset < this.sizeValue) {
432
- this.infosValue.push({ Offset: offset, Filename: filename, Line: line, Column: column })
434
+ if (
435
+ (this.infosValue.length === 0 || last.Offset < offset) &&
436
+ offset < this.sizeValue
437
+ ) {
438
+ this.infosValue.push({
439
+ Offset: offset,
440
+ Filename: filename,
441
+ Line: line,
442
+ Column: column,
443
+ })
433
444
  }
434
445
  }
435
446
 
@@ -567,7 +578,9 @@ export class FileSet {
567
578
  if (pos === NoPos) {
568
579
  return null
569
580
  }
570
- return this.files.find((file) => file.Base() <= pos && pos <= file.End()) ?? null
581
+ return (
582
+ this.files.find((file) => file.Base() <= pos && pos <= file.End()) ?? null
583
+ )
571
584
  }
572
585
 
573
586
  public PositionFor(pos: Pos, adjusted: boolean): Position {
@@ -0,0 +1,67 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import * as $ from '../../builtin/index.js'
4
+ import {
5
+ New128,
6
+ New128a,
7
+ New32,
8
+ New32a,
9
+ New64,
10
+ New64a,
11
+ } from './index.js'
12
+
13
+ describe('hash/fnv override', () => {
14
+ it('matches Go FNV sums for hello', async () => {
15
+ const h32 = New32()
16
+ h32.Write($.stringToBytes('hello'))
17
+ expect(h32.Sum32()).toBe(0xb6fa7167)
18
+ expect(hex(await h32.Sum($.stringToBytes('prefix')))).toBe(
19
+ '707265666978b6fa7167',
20
+ )
21
+ expect(h32.Size()).toBe(4)
22
+
23
+ const h32a = New32a()
24
+ h32a.Write($.stringToBytes('hello'))
25
+ expect(h32a.Sum32()).toBe(0x4f9f2cab)
26
+ expect(hex(await h32a.Sum(null))).toBe('4f9f2cab')
27
+
28
+ const h64 = New64()
29
+ h64.Write($.stringToBytes('hello'))
30
+ expect(h64.Sum64()).toBe(0x7b495389bdbdd4c7n)
31
+ expect(hex(await h64.Sum(null))).toBe('7b495389bdbdd4c7')
32
+
33
+ const h64a = New64a()
34
+ h64a.Write($.stringToBytes('hello'))
35
+ expect(h64a.Sum64()).toBe(0xa430d84680aabd0bn)
36
+ expect(hex(await h64a.Sum(null))).toBe('a430d84680aabd0b')
37
+
38
+ const h128 = New128()
39
+ h128.Write($.stringToBytes('hello'))
40
+ expect(hex(await h128.Sum(null))).toBe('f14b58486483d94f708038798c29697f')
41
+
42
+ const h128a = New128a()
43
+ h128a.Write($.stringToBytes('hello'))
44
+ expect(hex(await h128a.Sum(null))).toBe('e3e1efd54283d94f7081314b599d31b3')
45
+ })
46
+
47
+ it('marshals and restores state', async () => {
48
+ const hash = New128a()
49
+ hash.Write($.stringToBytes('hello'))
50
+ const [state, marshalErr] = hash.MarshalBinary()
51
+ expect(marshalErr).toBeNull()
52
+
53
+ const restored = New128a()
54
+ expect(restored.UnmarshalBinary(state)).toBeNull()
55
+ restored.Write($.stringToBytes(' world'))
56
+
57
+ const expected = New128a()
58
+ expected.Write($.stringToBytes('hello world'))
59
+ expect(hex(await restored.Sum(null))).toBe(hex(await expected.Sum(null)))
60
+ })
61
+ })
62
+
63
+ function hex(bytes: $.Bytes): string {
64
+ return Array.from($.bytesToUint8Array(bytes), (b) =>
65
+ b.toString(16).padStart(2, '0'),
66
+ ).join('')
67
+ }
@@ -0,0 +1,351 @@
1
+ import * as $ from '@goscript/builtin/index.js'
2
+
3
+ const offset32 = 0x811c9dc5
4
+ const offset64 = 0xcbf29ce484222325n
5
+ const offset128Lower = 0x62b821756295c58dn
6
+ const offset128Higher = 0x6c62272e07bb0142n
7
+ const offset128 = (offset128Higher << 64n) | offset128Lower
8
+ const prime32 = 0x01000193
9
+ const prime64 = 0x00000100000001b3n
10
+ const prime128 = (1n << 88n) | 0x13bn
11
+ const uint64Mask = 0xffffffffffffffffn
12
+ const uint128Mask = 0xffffffffffffffffffffffffffffffffn
13
+
14
+ const magic32 = bytes('fnv\x01')
15
+ const magic32a = bytes('fnv\x02')
16
+ const magic64 = bytes('fnv\x03')
17
+ const magic64a = bytes('fnv\x04')
18
+ const magic128 = bytes('fnv\x05')
19
+ const magic128a = bytes('fnv\x06')
20
+
21
+ class FNV32 {
22
+ private hash = offset32
23
+
24
+ constructor(
25
+ private readonly alternate: boolean,
26
+ private readonly magic: Uint8Array,
27
+ ) {}
28
+
29
+ Write(data: $.Bytes): [number, $.GoError] {
30
+ const bytes = $.bytesToUint8Array(data)
31
+ let hash = this.hash >>> 0
32
+ if (this.alternate) {
33
+ for (const c of bytes) {
34
+ hash ^= c
35
+ hash = Math.imul(hash, prime32) >>> 0
36
+ }
37
+ } else {
38
+ for (const c of bytes) {
39
+ hash = Math.imul(hash, prime32) >>> 0
40
+ hash ^= c
41
+ }
42
+ }
43
+ this.hash = hash >>> 0
44
+ return [bytes.length, null]
45
+ }
46
+
47
+ async Sum(prefix: $.Bytes | null): Promise<$.Bytes> {
48
+ return appendBytes($.bytesToUint8Array(prefix), be32(this.hash))
49
+ }
50
+
51
+ Sum32(): number {
52
+ return this.hash >>> 0
53
+ }
54
+
55
+ Reset(): void {
56
+ this.hash = offset32
57
+ }
58
+
59
+ Size(): number {
60
+ return 4
61
+ }
62
+
63
+ BlockSize(): number {
64
+ return 1
65
+ }
66
+
67
+ AppendBinary(prefix: $.Bytes | null): [$.Bytes, $.GoError] {
68
+ return [appendBytes($.bytesToUint8Array(prefix), this.magic, be32(this.hash)), null]
69
+ }
70
+
71
+ MarshalBinary(): [$.Bytes, $.GoError] {
72
+ return this.AppendBinary(null)
73
+ }
74
+
75
+ UnmarshalBinary(data: $.Bytes): $.GoError {
76
+ const state = $.bytesToUint8Array(data)
77
+ const err = validateState(state, this.magic, 8)
78
+ if (err != null) {
79
+ return err
80
+ }
81
+ this.hash = readBE32(state, 4)
82
+ return null
83
+ }
84
+
85
+ Clone(): [FNV32, $.GoError] {
86
+ const clone = new FNV32(this.alternate, this.magic)
87
+ clone.hash = this.hash
88
+ return [clone, null]
89
+ }
90
+ }
91
+
92
+ class FNV64 {
93
+ private hash = offset64
94
+
95
+ constructor(
96
+ private readonly alternate: boolean,
97
+ private readonly magic: Uint8Array,
98
+ ) {}
99
+
100
+ Write(data: $.Bytes): [number, $.GoError] {
101
+ const bytes = $.bytesToUint8Array(data)
102
+ let hash = this.hash
103
+ if (this.alternate) {
104
+ for (const c of bytes) {
105
+ hash ^= BigInt(c)
106
+ hash = (hash * prime64) & uint64Mask
107
+ }
108
+ } else {
109
+ for (const c of bytes) {
110
+ hash = (hash * prime64) & uint64Mask
111
+ hash ^= BigInt(c)
112
+ }
113
+ }
114
+ this.hash = hash
115
+ return [bytes.length, null]
116
+ }
117
+
118
+ async Sum(prefix: $.Bytes | null): Promise<$.Bytes> {
119
+ return appendBytes($.bytesToUint8Array(prefix), be64(this.hash))
120
+ }
121
+
122
+ Sum64(): bigint {
123
+ return this.hash
124
+ }
125
+
126
+ Reset(): void {
127
+ this.hash = offset64
128
+ }
129
+
130
+ Size(): number {
131
+ return 8
132
+ }
133
+
134
+ BlockSize(): number {
135
+ return 1
136
+ }
137
+
138
+ AppendBinary(prefix: $.Bytes | null): [$.Bytes, $.GoError] {
139
+ return [appendBytes($.bytesToUint8Array(prefix), this.magic, be64(this.hash)), null]
140
+ }
141
+
142
+ MarshalBinary(): [$.Bytes, $.GoError] {
143
+ return this.AppendBinary(null)
144
+ }
145
+
146
+ UnmarshalBinary(data: $.Bytes): $.GoError {
147
+ const state = $.bytesToUint8Array(data)
148
+ const err = validateState(state, this.magic, 12)
149
+ if (err != null) {
150
+ return err
151
+ }
152
+ this.hash = readBE64(state, 4)
153
+ return null
154
+ }
155
+
156
+ Clone(): [FNV64, $.GoError] {
157
+ const clone = new FNV64(this.alternate, this.magic)
158
+ clone.hash = this.hash
159
+ return [clone, null]
160
+ }
161
+ }
162
+
163
+ class FNV128 {
164
+ private hash = offset128
165
+
166
+ constructor(
167
+ private readonly alternate: boolean,
168
+ private readonly magic: Uint8Array,
169
+ ) {}
170
+
171
+ Write(data: $.Bytes): [number, $.GoError] {
172
+ const bytes = $.bytesToUint8Array(data)
173
+ let hash = this.hash
174
+ for (const c of bytes) {
175
+ if (this.alternate) {
176
+ hash ^= BigInt(c)
177
+ }
178
+ hash = (hash * prime128) & uint128Mask
179
+ if (!this.alternate) {
180
+ hash ^= BigInt(c)
181
+ }
182
+ }
183
+ this.hash = hash
184
+ return [bytes.length, null]
185
+ }
186
+
187
+ async Sum(prefix: $.Bytes | null): Promise<$.Bytes> {
188
+ return appendBytes($.bytesToUint8Array(prefix), be64(this.high()), be64(this.low()))
189
+ }
190
+
191
+ Reset(): void {
192
+ this.hash = offset128
193
+ }
194
+
195
+ Size(): number {
196
+ return 16
197
+ }
198
+
199
+ BlockSize(): number {
200
+ return 1
201
+ }
202
+
203
+ AppendBinary(prefix: $.Bytes | null): [$.Bytes, $.GoError] {
204
+ return [
205
+ appendBytes($.bytesToUint8Array(prefix), this.magic, be64(this.high()), be64(this.low())),
206
+ null,
207
+ ]
208
+ }
209
+
210
+ MarshalBinary(): [$.Bytes, $.GoError] {
211
+ return this.AppendBinary(null)
212
+ }
213
+
214
+ UnmarshalBinary(data: $.Bytes): $.GoError {
215
+ const state = $.bytesToUint8Array(data)
216
+ const err = validateState(state, this.magic, 20)
217
+ if (err != null) {
218
+ return err
219
+ }
220
+ this.hash = ((readBE64(state, 4) << 64n) | readBE64(state, 12)) & uint128Mask
221
+ return null
222
+ }
223
+
224
+ Clone(): [FNV128, $.GoError] {
225
+ const clone = new FNV128(this.alternate, this.magic)
226
+ clone.hash = this.hash
227
+ return [clone, null]
228
+ }
229
+
230
+ private high(): bigint {
231
+ return (this.hash >> 64n) & uint64Mask
232
+ }
233
+
234
+ private low(): bigint {
235
+ return this.hash & uint64Mask
236
+ }
237
+ }
238
+
239
+ export function New32(): FNV32 {
240
+ return $.interfaceValue<FNV32>(new FNV32(false, magic32), '*fnv.sum32')
241
+ }
242
+
243
+ export function New32a(): FNV32 {
244
+ return $.interfaceValue<FNV32>(new FNV32(true, magic32a), '*fnv.sum32a')
245
+ }
246
+
247
+ export function New64(): FNV64 {
248
+ return $.interfaceValue<FNV64>(new FNV64(false, magic64), '*fnv.sum64')
249
+ }
250
+
251
+ export function New64a(): FNV64 {
252
+ return $.interfaceValue<FNV64>(new FNV64(true, magic64a), '*fnv.sum64a')
253
+ }
254
+
255
+ export function New128(): FNV128 {
256
+ return $.interfaceValue<FNV128>(new FNV128(false, magic128), '*fnv.sum128')
257
+ }
258
+
259
+ export function New128a(): FNV128 {
260
+ return $.interfaceValue<FNV128>(new FNV128(true, magic128a), '*fnv.sum128a')
261
+ }
262
+
263
+ function bytes(value: string): Uint8Array {
264
+ return $.stringToBytes(value)
265
+ }
266
+
267
+ function appendBytes(prefix: Uint8Array, ...chunks: Uint8Array[]): Uint8Array {
268
+ let size = prefix.length
269
+ for (const chunk of chunks) {
270
+ size += chunk.length
271
+ }
272
+ const out = new Uint8Array(size)
273
+ out.set(prefix)
274
+ let offset = prefix.length
275
+ for (const chunk of chunks) {
276
+ out.set(chunk, offset)
277
+ offset += chunk.length
278
+ }
279
+ return out
280
+ }
281
+
282
+ function be32(value: number): Uint8Array {
283
+ return new Uint8Array([
284
+ (value >>> 24) & 0xff,
285
+ (value >>> 16) & 0xff,
286
+ (value >>> 8) & 0xff,
287
+ value & 0xff,
288
+ ])
289
+ }
290
+
291
+ function be64(value: bigint): Uint8Array {
292
+ const word = value & uint64Mask
293
+ return new Uint8Array([
294
+ Number((word >> 56n) & 0xffn),
295
+ Number((word >> 48n) & 0xffn),
296
+ Number((word >> 40n) & 0xffn),
297
+ Number((word >> 32n) & 0xffn),
298
+ Number((word >> 24n) & 0xffn),
299
+ Number((word >> 16n) & 0xffn),
300
+ Number((word >> 8n) & 0xffn),
301
+ Number(word & 0xffn),
302
+ ])
303
+ }
304
+
305
+ function readBE32(bytes: Uint8Array, offset: number): number {
306
+ return (
307
+ ((bytes[offset] << 24) >>> 0) |
308
+ (bytes[offset + 1] << 16) |
309
+ (bytes[offset + 2] << 8) |
310
+ bytes[offset + 3]
311
+ ) >>> 0
312
+ }
313
+
314
+ function readBE64(bytes: Uint8Array, offset: number): bigint {
315
+ return (
316
+ (BigInt(bytes[offset]) << 56n) |
317
+ (BigInt(bytes[offset + 1]) << 48n) |
318
+ (BigInt(bytes[offset + 2]) << 40n) |
319
+ (BigInt(bytes[offset + 3]) << 32n) |
320
+ (BigInt(bytes[offset + 4]) << 24n) |
321
+ (BigInt(bytes[offset + 5]) << 16n) |
322
+ (BigInt(bytes[offset + 6]) << 8n) |
323
+ BigInt(bytes[offset + 7])
324
+ )
325
+ }
326
+
327
+ function validateState(
328
+ state: Uint8Array,
329
+ magic: Uint8Array,
330
+ size: number,
331
+ ): $.GoError {
332
+ if (!startsWith(state, magic)) {
333
+ return $.newError('hash/fnv: invalid hash state identifier')
334
+ }
335
+ if (state.length !== size) {
336
+ return $.newError('hash/fnv: invalid hash state size')
337
+ }
338
+ return null
339
+ }
340
+
341
+ function startsWith(value: Uint8Array, prefix: Uint8Array): boolean {
342
+ if (value.length < prefix.length) {
343
+ return false
344
+ }
345
+ for (let i = 0; i < prefix.length; i++) {
346
+ if (value[i] !== prefix[i]) {
347
+ return false
348
+ }
349
+ }
350
+ return true
351
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "dependencies": []
3
+ }
@@ -0,0 +1,37 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import * as $ from '../builtin/index.js'
4
+
5
+ import './index.js'
6
+
7
+ class FakeHash {
8
+ Write(p: $.Bytes): [number, $.GoError] {
9
+ return [$.len(p), null]
10
+ }
11
+
12
+ Sum(b: $.Bytes): $.Bytes {
13
+ return b
14
+ }
15
+
16
+ Reset(): void {}
17
+
18
+ Size(): number {
19
+ return 20
20
+ }
21
+
22
+ BlockSize(): number {
23
+ return 64
24
+ }
25
+ }
26
+
27
+ describe('hash runtime contracts', () => {
28
+ it('registers Hash for runtime type assertions', () => {
29
+ const [value, ok] = $.typeAssertTuple<FakeHash>(
30
+ new FakeHash(),
31
+ 'hash.Hash',
32
+ )
33
+
34
+ expect(ok).toBe(true)
35
+ expect(value).toBeInstanceOf(FakeHash)
36
+ })
37
+ })
@@ -0,0 +1,118 @@
1
+ import * as $ from '@goscript/builtin/index.js'
2
+
3
+ export interface Hash {
4
+ Write(p: $.Bytes): [number, $.GoError]
5
+ Sum(b: $.Bytes): Promise<$.Bytes>
6
+ Reset(): void
7
+ Size(): number
8
+ BlockSize(): number
9
+ }
10
+
11
+ export interface Hash32 extends Hash {
12
+ Sum32(): number
13
+ }
14
+
15
+ export interface Hash64 extends Hash {
16
+ Sum64(): bigint
17
+ }
18
+
19
+ export interface Cloner {
20
+ Clone(): [Hash, $.GoError]
21
+ }
22
+
23
+ const bytesType: $.SliceTypeInfo = {
24
+ kind: $.TypeKind.Slice,
25
+ elemType: { kind: $.TypeKind.Basic, name: 'uint8' },
26
+ }
27
+ const intType: $.BasicTypeInfo = { kind: $.TypeKind.Basic, name: 'int' }
28
+ const uint32Type: $.BasicTypeInfo = {
29
+ kind: $.TypeKind.Basic,
30
+ name: 'uint32',
31
+ }
32
+ const uint64Type: $.BasicTypeInfo = {
33
+ kind: $.TypeKind.Basic,
34
+ name: 'uint64',
35
+ }
36
+ const errorType: $.InterfaceTypeInfo = {
37
+ kind: $.TypeKind.Interface,
38
+ name: 'error',
39
+ methods: [],
40
+ }
41
+
42
+ $.registerInterfaceType('hash.Hash', null, [
43
+ {
44
+ name: 'Write',
45
+ args: [{ name: 'p', type: bytesType }],
46
+ returns: [
47
+ { name: 'n', type: intType },
48
+ { name: 'err', type: errorType },
49
+ ],
50
+ },
51
+ {
52
+ name: 'Sum',
53
+ args: [{ name: 'b', type: bytesType }],
54
+ returns: [{ name: '_r0', type: bytesType }],
55
+ },
56
+ { name: 'Reset', args: [], returns: [] },
57
+ { name: 'Size', args: [], returns: [{ name: '_r0', type: intType }] },
58
+ { name: 'BlockSize', args: [], returns: [{ name: '_r0', type: intType }] },
59
+ ])
60
+
61
+ $.registerInterfaceType('hash.Hash32', null, [
62
+ {
63
+ name: 'Write',
64
+ args: [{ name: 'p', type: bytesType }],
65
+ returns: [
66
+ { name: 'n', type: intType },
67
+ { name: 'err', type: errorType },
68
+ ],
69
+ },
70
+ {
71
+ name: 'Sum',
72
+ args: [{ name: 'b', type: bytesType }],
73
+ returns: [{ name: '_r0', type: bytesType }],
74
+ },
75
+ { name: 'Reset', args: [], returns: [] },
76
+ { name: 'Size', args: [], returns: [{ name: '_r0', type: intType }] },
77
+ { name: 'BlockSize', args: [], returns: [{ name: '_r0', type: intType }] },
78
+ {
79
+ name: 'Sum32',
80
+ args: [],
81
+ returns: [{ name: '_r0', type: uint32Type }],
82
+ },
83
+ ])
84
+
85
+ $.registerInterfaceType('hash.Hash64', null, [
86
+ {
87
+ name: 'Write',
88
+ args: [{ name: 'p', type: bytesType }],
89
+ returns: [
90
+ { name: 'n', type: intType },
91
+ { name: 'err', type: errorType },
92
+ ],
93
+ },
94
+ {
95
+ name: 'Sum',
96
+ args: [{ name: 'b', type: bytesType }],
97
+ returns: [{ name: '_r0', type: bytesType }],
98
+ },
99
+ { name: 'Reset', args: [], returns: [] },
100
+ { name: 'Size', args: [], returns: [{ name: '_r0', type: intType }] },
101
+ { name: 'BlockSize', args: [], returns: [{ name: '_r0', type: intType }] },
102
+ {
103
+ name: 'Sum64',
104
+ args: [],
105
+ returns: [{ name: '_r0', type: uint64Type }],
106
+ },
107
+ ])
108
+
109
+ $.registerInterfaceType('hash.Cloner', null, [
110
+ {
111
+ name: 'Clone',
112
+ args: [],
113
+ returns: [
114
+ { name: '_r0', type: 'hash.Hash' },
115
+ { name: 'err', type: errorType },
116
+ ],
117
+ },
118
+ ])
@@ -0,0 +1,5 @@
1
+ {
2
+ "asyncMethods": {
3
+ "Hash.Sum": true
4
+ }
5
+ }
@@ -29,11 +29,11 @@ describe('internal/byteorder uint64', () => {
29
29
  })
30
30
 
31
31
  test('appends uint64 values', () => {
32
- expect(Array.from(BEAppendUint64(new Uint8Array([0xaa]), 0x0102n))).toEqual([
33
- 0xaa, 0, 0, 0, 0, 0, 0, 1, 2,
34
- ])
35
- expect(Array.from(LEAppendUint64(new Uint8Array([0xaa]), 0x0102n))).toEqual([
36
- 0xaa, 2, 1, 0, 0, 0, 0, 0, 0,
37
- ])
32
+ expect(Array.from(BEAppendUint64(new Uint8Array([0xaa]), 0x0102n))).toEqual(
33
+ [0xaa, 0, 0, 0, 0, 0, 0, 1, 2],
34
+ )
35
+ expect(Array.from(LEAppendUint64(new Uint8Array([0xaa]), 0x0102n))).toEqual(
36
+ [0xaa, 2, 1, 0, 0, 0, 0, 0, 0],
37
+ )
38
38
  })
39
39
  })