@amxts/core 0.1.0

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 (247) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/README.ru.md +162 -0
  4. package/amxmodx/base/include/amxconst.inc +594 -0
  5. package/amxmodx/base/include/amxmisc.inc +902 -0
  6. package/amxmodx/base/include/amxmodx.inc +3447 -0
  7. package/amxmodx/base/include/amxmodx_version.inc +20 -0
  8. package/amxmodx/base/include/cellarray.inc +525 -0
  9. package/amxmodx/base/include/cellstack.inc +166 -0
  10. package/amxmodx/base/include/celltrie.inc +412 -0
  11. package/amxmodx/base/include/core.inc +202 -0
  12. package/amxmodx/base/include/csstats.inc +298 -0
  13. package/amxmodx/base/include/csstats_const.inc +29 -0
  14. package/amxmodx/base/include/cstrike.inc +1287 -0
  15. package/amxmodx/base/include/cstrike_const.inc +521 -0
  16. package/amxmodx/base/include/csx.inc +259 -0
  17. package/amxmodx/base/include/cvars.inc +547 -0
  18. package/amxmodx/base/include/datapack.inc +161 -0
  19. package/amxmodx/base/include/dbi.inc +154 -0
  20. package/amxmodx/base/include/dodconst.inc +152 -0
  21. package/amxmodx/base/include/dodfun.inc +152 -0
  22. package/amxmodx/base/include/dodstats.inc +69 -0
  23. package/amxmodx/base/include/dodx.inc +161 -0
  24. package/amxmodx/base/include/engine.inc +1343 -0
  25. package/amxmodx/base/include/engine_const.inc +310 -0
  26. package/amxmodx/base/include/engine_stocks.inc +248 -0
  27. package/amxmodx/base/include/esf.inc +70 -0
  28. package/amxmodx/base/include/esf_const.inc +74 -0
  29. package/amxmodx/base/include/fakemeta.inc +1127 -0
  30. package/amxmodx/base/include/fakemeta_const.inc +793 -0
  31. package/amxmodx/base/include/fakemeta_stocks.inc +395 -0
  32. package/amxmodx/base/include/fakemeta_util.inc +882 -0
  33. package/amxmodx/base/include/file.inc +666 -0
  34. package/amxmodx/base/include/float.inc +422 -0
  35. package/amxmodx/base/include/fun.inc +333 -0
  36. package/amxmodx/base/include/gameconfig.inc +93 -0
  37. package/amxmodx/base/include/geoip.inc +264 -0
  38. package/amxmodx/base/include/ham_const.inc +4352 -0
  39. package/amxmodx/base/include/hamsandwich.inc +439 -0
  40. package/amxmodx/base/include/hlsdk_const.inc +808 -0
  41. package/amxmodx/base/include/json.inc +777 -0
  42. package/amxmodx/base/include/lang.inc +119 -0
  43. package/amxmodx/base/include/message_const.inc +1130 -0
  44. package/amxmodx/base/include/message_stocks.inc +161 -0
  45. package/amxmodx/base/include/messages.inc +604 -0
  46. package/amxmodx/base/include/newmenus.inc +387 -0
  47. package/amxmodx/base/include/ns.inc +754 -0
  48. package/amxmodx/base/include/ns_const.inc +196 -0
  49. package/amxmodx/base/include/nvault.inc +154 -0
  50. package/amxmodx/base/include/regex.inc +348 -0
  51. package/amxmodx/base/include/sockets.inc +183 -0
  52. package/amxmodx/base/include/sorting.inc +107 -0
  53. package/amxmodx/base/include/sqlx.inc +582 -0
  54. package/amxmodx/base/include/string.inc +786 -0
  55. package/amxmodx/base/include/string_const.inc +156 -0
  56. package/amxmodx/base/include/string_stocks.inc +325 -0
  57. package/amxmodx/base/include/textparse_ini.inc +214 -0
  58. package/amxmodx/base/include/textparse_smc.inc +261 -0
  59. package/amxmodx/base/include/tfcconst.inc +84 -0
  60. package/amxmodx/base/include/tfcstats.inc +62 -0
  61. package/amxmodx/base/include/tfcx.inc +148 -0
  62. package/amxmodx/base/include/time.inc +118 -0
  63. package/amxmodx/base/include/tsconst.inc +154 -0
  64. package/amxmodx/base/include/tsfun.inc +198 -0
  65. package/amxmodx/base/include/tsstats.inc +65 -0
  66. package/amxmodx/base/include/tsx.inc +88 -0
  67. package/amxmodx/base/include/vault.inc +60 -0
  68. package/amxmodx/base/include/vector.inc +131 -0
  69. package/amxmodx/base/include/xs.inc +1570 -0
  70. package/as/amxts.d.ts +153 -0
  71. package/as/constants.ts +4730 -0
  72. package/as/effects.ts +1449 -0
  73. package/as/entities.ts +5482 -0
  74. package/as/events.ts +3054 -0
  75. package/as/facade.ts +4639 -0
  76. package/as/flags.ts +299 -0
  77. package/as/fs.ts +287 -0
  78. package/as/hooks.ts +18536 -0
  79. package/as/kit.ts +25 -0
  80. package/as/lib/check.ts +86 -0
  81. package/as/modules/http.ts +184 -0
  82. package/as/natives.ts +11845 -0
  83. package/as/os.ts +30 -0
  84. package/as/promise.ts +1392 -0
  85. package/as/promise.types.d.ts +82 -0
  86. package/as/remote.ts +288 -0
  87. package/as/tsconfig.json +22 -0
  88. package/as/vector.ts +65 -0
  89. package/bin/amxts.mjs +10 -0
  90. package/includes/menu_core.inc +355 -0
  91. package/includes/order.txt +54 -0
  92. package/includes/sources.json +27 -0
  93. package/includes/universal_config.inc +355 -0
  94. package/lint/oxlint-plugin.mjs +77 -0
  95. package/node_modules/assemblyscript/LICENSE +201 -0
  96. package/node_modules/assemblyscript/NOTICE +93 -0
  97. package/node_modules/assemblyscript/package.json +63 -0
  98. package/node_modules/assemblyscript/std/README.md +6 -0
  99. package/node_modules/assemblyscript/std/assembly/array.ts +526 -0
  100. package/node_modules/assemblyscript/std/assembly/arraybuffer.ts +77 -0
  101. package/node_modules/assemblyscript/std/assembly/atomics.ts +127 -0
  102. package/node_modules/assemblyscript/std/assembly/bindings/asyncify.ts +16 -0
  103. package/node_modules/assemblyscript/std/assembly/bindings/dom.ts +291 -0
  104. package/node_modules/assemblyscript/std/assembly/bindings/node.ts +6 -0
  105. package/node_modules/assemblyscript/std/assembly/builtins.ts +2631 -0
  106. package/node_modules/assemblyscript/std/assembly/compat.ts +2 -0
  107. package/node_modules/assemblyscript/std/assembly/console.ts +42 -0
  108. package/node_modules/assemblyscript/std/assembly/crypto.ts +9 -0
  109. package/node_modules/assemblyscript/std/assembly/dataview.ts +181 -0
  110. package/node_modules/assemblyscript/std/assembly/date.ts +373 -0
  111. package/node_modules/assemblyscript/std/assembly/diagnostics.ts +11 -0
  112. package/node_modules/assemblyscript/std/assembly/error.ts +44 -0
  113. package/node_modules/assemblyscript/std/assembly/function.ts +38 -0
  114. package/node_modules/assemblyscript/std/assembly/index.d.ts +2822 -0
  115. package/node_modules/assemblyscript/std/assembly/iterator.ts +35 -0
  116. package/node_modules/assemblyscript/std/assembly/map.ts +260 -0
  117. package/node_modules/assemblyscript/std/assembly/math.ts +3289 -0
  118. package/node_modules/assemblyscript/std/assembly/memory.ts +123 -0
  119. package/node_modules/assemblyscript/std/assembly/number.ts +388 -0
  120. package/node_modules/assemblyscript/std/assembly/object.ts +36 -0
  121. package/node_modules/assemblyscript/std/assembly/performance.ts +9 -0
  122. package/node_modules/assemblyscript/std/assembly/polyfills.ts +27 -0
  123. package/node_modules/assemblyscript/std/assembly/process.ts +50 -0
  124. package/node_modules/assemblyscript/std/assembly/reference.ts +48 -0
  125. package/node_modules/assemblyscript/std/assembly/regexp.ts +12 -0
  126. package/node_modules/assemblyscript/std/assembly/rt/README.md +83 -0
  127. package/node_modules/assemblyscript/std/assembly/rt/common.ts +81 -0
  128. package/node_modules/assemblyscript/std/assembly/rt/index-incremental.ts +2 -0
  129. package/node_modules/assemblyscript/std/assembly/rt/index-minimal.ts +2 -0
  130. package/node_modules/assemblyscript/std/assembly/rt/index-stub.ts +1 -0
  131. package/node_modules/assemblyscript/std/assembly/rt/index.d.ts +37 -0
  132. package/node_modules/assemblyscript/std/assembly/rt/itcms.ts +419 -0
  133. package/node_modules/assemblyscript/std/assembly/rt/rtrace.ts +15 -0
  134. package/node_modules/assemblyscript/std/assembly/rt/stub.ts +133 -0
  135. package/node_modules/assemblyscript/std/assembly/rt/tcms.ts +254 -0
  136. package/node_modules/assemblyscript/std/assembly/rt/tlsf.ts +592 -0
  137. package/node_modules/assemblyscript/std/assembly/rt.ts +87 -0
  138. package/node_modules/assemblyscript/std/assembly/set.ts +220 -0
  139. package/node_modules/assemblyscript/std/assembly/shared/feature.ts +65 -0
  140. package/node_modules/assemblyscript/std/assembly/shared/runtime.ts +11 -0
  141. package/node_modules/assemblyscript/std/assembly/shared/target.ts +11 -0
  142. package/node_modules/assemblyscript/std/assembly/shared/tsconfig.json +11 -0
  143. package/node_modules/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
  144. package/node_modules/assemblyscript/std/assembly/staticarray.ts +401 -0
  145. package/node_modules/assemblyscript/std/assembly/string.ts +847 -0
  146. package/node_modules/assemblyscript/std/assembly/symbol.ts +114 -0
  147. package/node_modules/assemblyscript/std/assembly/table.ts +16 -0
  148. package/node_modules/assemblyscript/std/assembly/tsconfig.json +6 -0
  149. package/node_modules/assemblyscript/std/assembly/typedarray.ts +1945 -0
  150. package/node_modules/assemblyscript/std/assembly/uri.ts +17 -0
  151. package/node_modules/assemblyscript/std/assembly/util/bytes.ts +107 -0
  152. package/node_modules/assemblyscript/std/assembly/util/casemap.ts +497 -0
  153. package/node_modules/assemblyscript/std/assembly/util/error.ts +54 -0
  154. package/node_modules/assemblyscript/std/assembly/util/hash.ts +117 -0
  155. package/node_modules/assemblyscript/std/assembly/util/math.ts +1922 -0
  156. package/node_modules/assemblyscript/std/assembly/util/memory.ts +290 -0
  157. package/node_modules/assemblyscript/std/assembly/util/number.ts +873 -0
  158. package/node_modules/assemblyscript/std/assembly/util/sort.ts +313 -0
  159. package/node_modules/assemblyscript/std/assembly/util/string.ts +1202 -0
  160. package/node_modules/assemblyscript/std/assembly/util/uri.ts +275 -0
  161. package/node_modules/assemblyscript/std/assembly/vector.ts +4 -0
  162. package/node_modules/assemblyscript/std/assembly.json +16 -0
  163. package/node_modules/assemblyscript/std/portable/index.d.ts +462 -0
  164. package/node_modules/assemblyscript/std/portable/index.js +416 -0
  165. package/node_modules/assemblyscript/std/portable.json +11 -0
  166. package/node_modules/assemblyscript/std/types/assembly/index.d.ts +1 -0
  167. package/node_modules/assemblyscript/std/types/assembly/package.json +3 -0
  168. package/node_modules/assemblyscript/std/types/portable/index.d.ts +1 -0
  169. package/node_modules/assemblyscript/std/types/portable/package.json +3 -0
  170. package/node_modules/assemblyscript/tsconfig-base.json +13 -0
  171. package/package.json +112 -0
  172. package/runtime/deps/assemblyscript/LICENSE +201 -0
  173. package/runtime/deps/assemblyscript/NOTICE +93 -0
  174. package/runtime/deps/assemblyscript/bin/asc.js +35 -0
  175. package/runtime/deps/assemblyscript/dist/asc.js +25035 -0
  176. package/runtime/deps/assemblyscript/dist/assemblyscript.js +337 -0
  177. package/runtime/deps/assemblyscript/node_modules/binaryen/LICENSE +201 -0
  178. package/runtime/deps/assemblyscript/node_modules/binaryen/index.js +28905 -0
  179. package/runtime/deps/assemblyscript/node_modules/binaryen/package.json +50 -0
  180. package/runtime/deps/assemblyscript/node_modules/long/LICENSE +202 -0
  181. package/runtime/deps/assemblyscript/node_modules/long/index.js +1581 -0
  182. package/runtime/deps/assemblyscript/node_modules/long/package.json +58 -0
  183. package/runtime/deps/assemblyscript/package.json +114 -0
  184. package/runtime/host/amxts.inc +85 -0
  185. package/runtime/licenses/AMXX-LICENSE.txt +34 -0
  186. package/runtime/licenses/AssemblyScript-LICENSE +201 -0
  187. package/runtime/licenses/AssemblyScript-NOTICE +93 -0
  188. package/runtime/licenses/Binaryen-LICENSE +201 -0
  189. package/runtime/licenses/Bun-LICENSE.md +84 -0
  190. package/runtime/licenses/GPL-3.0.txt +674 -0
  191. package/runtime/licenses/LLVM-LICENSE.TXT +279 -0
  192. package/runtime/licenses/README.md +25 -0
  193. package/runtime/licenses/WAMR-LICENSE +219 -0
  194. package/runtime/natives.txt +1095 -0
  195. package/runtime/patches/README.md +59 -0
  196. package/runtime/patches/assemblyscript-0.28.20-amxts.patch +14174 -0
  197. package/runtime/patches/wamr-2.4.5-amxts.patch +364 -0
  198. package/scripts/apply-docs.ts +508 -0
  199. package/scripts/asc.ts +27 -0
  200. package/scripts/auto-imports.ts +258 -0
  201. package/scripts/build-wasm.ts +595 -0
  202. package/scripts/check.ts +93 -0
  203. package/scripts/compile-cache.ts +179 -0
  204. package/scripts/compile.ts +401 -0
  205. package/scripts/docker-server.ts +73 -0
  206. package/scripts/docs/as/amxts.ts +210 -0
  207. package/scripts/docs/as/effects.ts +1684 -0
  208. package/scripts/docs/as/facade.ts +3302 -0
  209. package/scripts/docs/as/fs.ts +173 -0
  210. package/scripts/docs/as/lib/check.ts +68 -0
  211. package/scripts/docs/as/modules/http.ts +66 -0
  212. package/scripts/docs/as/os.ts +16 -0
  213. package/scripts/docs/as/promise.ts +132 -0
  214. package/scripts/docs/as/promise.types.ts +63 -0
  215. package/scripts/docs/as/vector.ts +48 -0
  216. package/scripts/docs/entities.ts +2338 -0
  217. package/scripts/docs/events.ts +245 -0
  218. package/scripts/docs/game.ts +497 -0
  219. package/scripts/docs/messages.ts +148 -0
  220. package/scripts/file-contents.ts +74 -0
  221. package/scripts/includes.ts +134 -0
  222. package/scripts/player-fields.ts +866 -0
  223. package/scripts/plugin-cache.ts +92 -0
  224. package/scripts/plugin-natives.ts +1157 -0
  225. package/scripts/prebuilt.ts +268 -0
  226. package/scripts/prepare.ts +134 -0
  227. package/scripts/project.ts +973 -0
  228. package/scripts/run.ts +28 -0
  229. package/scripts/shared-modules.ts +906 -0
  230. package/scripts/system.ts +33 -0
  231. package/scripts/tracked-fs.ts +115 -0
  232. package/scripts/typed-configs.ts +788 -0
  233. package/scripts/ui.ts +77 -0
  234. package/src/cli-api.mjs +175 -0
  235. package/src/parser/include-parser.ts +506 -0
  236. package/src/system.mjs +155 -0
  237. package/src/testing/compile-cache.ts +31 -0
  238. package/src/testing/compile.ts +222 -0
  239. package/src/testing/coroutines.ts +191 -0
  240. package/src/testing/index.ts +39 -0
  241. package/src/testing/kits.ts +55 -0
  242. package/src/testing/memory.ts +125 -0
  243. package/src/testing/natives.ts +925 -0
  244. package/src/testing/server.ts +1874 -0
  245. package/src/testing/setup.ts +63 -0
  246. package/src/testing/tables.ts +139 -0
  247. package/src/types.ts +51 -0
@@ -0,0 +1,93 @@
1
+ The following authors have all licensed their contributions to AssemblyScript
2
+ under the licensing terms detailed in LICENSE:
3
+
4
+ * Daniel Wirtz <dcode@dcode.io>
5
+ * Max Graey <maxgraey@gmail.com>
6
+ * Igor Sbitnev <PinkaminaDianePie@gmail.com>
7
+ * Norton Wang <me@nortonwang.com>
8
+ * Alan Pierce <alangpierce@gmail.com>
9
+ * Palmer <pengliao@live.cn>
10
+ * Linus Unnebäck <linus@folkdatorn.se>
11
+ * Joshua Tenner <tenner.joshua@gmail.com>
12
+ * Nidin Vinayakan <01@01alchemist.com>
13
+ * Aaron Turner <aaron@aaronthedev.com>
14
+ * Willem Wyndham <willem@cs.umd.edu>
15
+ * Bowen Wang <bowen@nearprotocol.com>
16
+ * Emil Laine <laine.emil@gmail.com>
17
+ * Stephen Paul Weber <stephen.weber@shopify.com>
18
+ * Jay Phelps <hello@jayphelps.com>
19
+ * jhwgh1968 <jhwgh1968@protonmail.com>
20
+ * Jeffrey Charles <jeffreycharles@gmail.com>
21
+ * Vladimir Tikhonov <reg@tikhonov.by>
22
+ * Duncan Uszkay <duncan.uszkay@shopify.com>
23
+ * Surma <surma@surma.dev>
24
+ * Julien Letellier <letellier.julien@gmail.com>
25
+ * Guido Zuidhof <me@guido.io>
26
+ * ncave <777696+ncave@users.noreply.github.com>
27
+ * Andrew Davis <pulpdrew@gmail.com>
28
+ * Maël Nison <nison.mael@gmail.com>
29
+ * Valeria Viana Gusmao <valeria.viana.gusmao@gmail.com>
30
+ * Gabor Greif <ggreif@gmail.com>
31
+ * Martin Fredriksson <martin.fredriksson@vikinganalytics.se>
32
+ * forcepusher <bionitsoup@gmail.com>
33
+ * Piotr Oleś <piotrek.oles@gmail.com>
34
+ * Saúl Cabrera <saulecabrera@gmail.com>
35
+ * Chance Snow <git@chancesnow.me>
36
+ * Peter Salomonsen <petersalomonsen@runbox.com>
37
+ * ookangzheng <git-ed@runbox.no>
38
+ * yjhmelody <yjh465402634@gmail.com>
39
+ * bnbarak <bn.barak@gmail.com>
40
+ * Colin Eberhardt <colin.eberhardt@gmail.com>
41
+ * Ryan Pivovar <ryanpivovar@gmail.com>
42
+ * Roman F. <70765447+romdotdog@users.noreply.github.com>
43
+ * Joe Pea <trusktr@gmail.com>
44
+ * Felipe Gasper <FGasper@users.noreply.github.com>
45
+ * Congcong Cai <congcongcai0907@163.com>
46
+ * mooooooi <emwings@outlook.com>
47
+ * Yasushi Ando <andyjpn@gmail.com>
48
+ * Syed Jafri <syed@metalpay.co>
49
+ * Peter Hayman <peteyhayman@gmail.com>
50
+ * ApsarasX <apsarax@outlook.com>
51
+ * Adrien Zinger <zinger.ad@gmail.com>
52
+ * Ruixiang Chen <xiang19890319@gmail.com>
53
+ * Daniel Salvadori <danaugrs@gmail.com>
54
+ * Jairus Tanaka <me@jairus.dev>
55
+ * CountBleck <Mr.YouKnowWhoIAm@protonmail.com>
56
+ * Abdul Rauf <abdulraufmujahid@gmail.com>
57
+ * Bach Le <bach@bullno1.com>
58
+ * Xinquan Xu <xinquan0203@163.com>
59
+ * Matt Johnson-Pint <mattjohnsonpint@gmail.com>
60
+ * Fabián Heredia Montiel <fabianhjr@users.noreply.github.com>
61
+ * Jonas Minnberg <sasq64@gmail.com>
62
+ * Kam Chehresa <kaz.che@gmail.com>
63
+ * Mopsgamer <79159094+Mopsgamer@users.noreply.github.com>
64
+ * EDM115 <github@edm115.dev>
65
+ * Weixie Cui <cuiweixie@gmail.com>
66
+
67
+ Portions of this software are derived from third-party works licensed under
68
+ the following terms:
69
+
70
+ * TypeScript: https://github.com/Microsoft/TypeScript
71
+
72
+ Copyright (c) Microsoft Corporation
73
+ Apache License, Version 2.0 (https://opensource.org/licenses/Apache-2.0)
74
+
75
+ * Binaryen: https://github.com/WebAssembly/binaryen
76
+
77
+ Copyright (c) WebAssembly Community Group participants
78
+ Apache License, Version 2.0 (https://opensource.org/licenses/Apache-2.0)
79
+
80
+ * musl libc: http://www.musl-libc.org
81
+
82
+ Copyright (c) Rich Felker, et al.
83
+ The MIT License (https://opensource.org/licenses/MIT)
84
+
85
+ * V8: https://developers.google.com/v8/
86
+
87
+ Copyright (c) the V8 project authors
88
+ The 3-Clause BSD License (https://opensource.org/licenses/BSD-3-Clause)
89
+
90
+ * Arm Optimized Routines: https://github.com/ARM-software/optimized-routines
91
+
92
+ Copyright (c) Arm Limited
93
+ The MIT License (https://opensource.org/licenses/MIT)
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "assemblyscript",
3
+ "description": "A TypeScript-like language for WebAssembly.",
4
+ "keywords": [
5
+ "typescript",
6
+ "webassembly",
7
+ "compiler",
8
+ "assemblyscript",
9
+ "wasm"
10
+ ],
11
+ "version": "0.28.20",
12
+ "author": "Daniel Wirtz <dcode+assemblyscript@dcode.io>",
13
+ "license": "Apache-2.0",
14
+ "homepage": "https://assemblyscript.org",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/AssemblyScript/assemblyscript.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/AssemblyScript/assemblyscript/issues"
21
+ },
22
+ "engines": {
23
+ "node": ">=20",
24
+ "npm": ">=10"
25
+ },
26
+ "engineStrict": true,
27
+ "type": "module",
28
+ "exports": {
29
+ ".": {
30
+ "import": "./dist/assemblyscript.js",
31
+ "types": "./dist/assemblyscript.d.ts"
32
+ },
33
+ "./asc": {
34
+ "import": "./dist/asc.js",
35
+ "types": "./dist/asc.d.ts"
36
+ },
37
+ "./transform": {
38
+ "import": "./dist/transform.js",
39
+ "types": "./dist/transform.d.ts",
40
+ "require": "./dist/transform.cjs"
41
+ },
42
+ "./binaryen": {
43
+ "import": "./lib/binaryen.js",
44
+ "types": "./lib/binaryen.d.ts"
45
+ },
46
+ "./*": "./*"
47
+ },
48
+ "imports": {
49
+ "#rtrace": {
50
+ "import": "./lib/rtrace/index.js",
51
+ "types": "./lib/rtrace/index.d.ts"
52
+ }
53
+ },
54
+ "files": [
55
+ "std/",
56
+ "tsconfig-base.json",
57
+ "NOTICE"
58
+ ],
59
+ "funding": {
60
+ "type": "opencollective",
61
+ "url": "https://opencollective.com/assemblyscript"
62
+ }
63
+ }
@@ -0,0 +1,6 @@
1
+ Standard library
2
+ ================
3
+
4
+ Standard library components for use with `tsc` (portable) and `asc` (assembly).
5
+
6
+ Base configurations (.json) and definition files (.d.ts) are relevant to `tsc` only and not used by `asc`.
@@ -0,0 +1,526 @@
1
+ /// <reference path="./rt/index.d.ts" />
2
+
3
+ import { BLOCK_MAXSIZE } from "./rt/common";
4
+ import { Runtime } from "shared/runtime";
5
+ import { COMPARATOR, SORT } from "./util/sort";
6
+ import { REVERSE, FILL } from "./util/bytes";
7
+ import { joinBooleanArray, joinIntegerArray, joinFloatArray, joinStringArray, joinReferenceArray } from "./util/string";
8
+ import { idof, isArray as builtin_isArray } from "./builtins";
9
+ import { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_EMPTYARRAY, E_HOLEYARRAY } from "./util/error";
10
+
11
+ // @ts-ignore: decorator
12
+ @inline @lazy const MIN_SIZE: usize = 8;
13
+
14
+ /** Ensures that the given array has _at least_ the specified backing size. */
15
+ function ensureCapacity(array: usize, newSize: usize, alignLog2: u32, canGrow: bool = true): void {
16
+ // Depends on the fact that Arrays mimic ArrayBufferView
17
+ let oldCapacity = <usize>changetype<ArrayBufferView>(array).byteLength;
18
+ if (newSize > oldCapacity >>> alignLog2) {
19
+ if (newSize > BLOCK_MAXSIZE >>> alignLog2) throw new RangeError(E_INVALIDLENGTH);
20
+ let oldData = changetype<usize>(changetype<ArrayBufferView>(array).buffer);
21
+ // Grows old capacity by factor of two.
22
+ // Make sure we don't reach BLOCK_MAXSIZE for new growed capacity.
23
+ let newCapacity = max(newSize, MIN_SIZE) << alignLog2;
24
+ if (canGrow) newCapacity = max(min(oldCapacity << 1, BLOCK_MAXSIZE), newCapacity);
25
+ let newData = __renew(oldData, newCapacity);
26
+ // __new / __renew already init memory range as zeros in Incremental runtime.
27
+ // So try to avoid this.
28
+ if (ASC_RUNTIME != Runtime.Incremental) {
29
+ memory.fill(newData + oldCapacity, 0, newCapacity - oldCapacity);
30
+ }
31
+ if (newData != oldData) { // oldData has been free'd
32
+ store<usize>(array, newData, offsetof<ArrayBufferView>("buffer"));
33
+ store<usize>(array, newData, offsetof<ArrayBufferView>("dataStart"));
34
+ __link(array, changetype<usize>(newData), false);
35
+ }
36
+ store<u32>(array, <u32>newCapacity, offsetof<ArrayBufferView>("byteLength"));
37
+ }
38
+ }
39
+
40
+ export class Array<T> {
41
+ [key: number]: T;
42
+
43
+ // Mimicking ArrayBufferView isn't strictly necessary here but is done to allow glue code
44
+ // to work with typed and normal arrays interchangeably. Technically, normal arrays do not need
45
+ // `dataStart` (equals `buffer`) and `byteLength` (equals computed `buffer.byteLength`), but the
46
+ // block is 16 bytes anyway so it's fine to have a couple extra fields in there.
47
+
48
+ private buffer: ArrayBuffer;
49
+ @unsafe readonly dataStart: usize;
50
+ private byteLength: i32; // Uses here as capacity
51
+
52
+ // Also note that Array<T> with non-nullable T must guard against uninitialized null values
53
+ // whenever an element is accessed. Otherwise, the compiler wouldn't be able to guarantee
54
+ // type-safety anymore. For lack of a better word, such an array is "holey".
55
+
56
+ private length_: i32;
57
+
58
+ static isArray<U>(value: U): bool {
59
+ return isReference<U>() ? changetype<usize>(value) != 0 && builtin_isArray(value) : false;
60
+ }
61
+
62
+ static create<T>(capacity: i32 = 0): Array<T> {
63
+ WARNING("'Array.create' is deprecated. Use 'new Array' instead, making sure initial elements are initialized.");
64
+ let array = new Array<T>(capacity);
65
+ array.length = 0;
66
+ return array;
67
+ }
68
+
69
+ constructor(length: i32 = 0) {
70
+ if (<u32>length > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new RangeError(E_INVALIDLENGTH);
71
+ // reserve capacity for at least MIN_SIZE elements
72
+ let bufferSize = max(<usize>length, MIN_SIZE) << alignof<T>();
73
+ let buffer = changetype<ArrayBuffer>(__new(bufferSize, idof<ArrayBuffer>()));
74
+ if (ASC_RUNTIME != Runtime.Incremental) {
75
+ memory.fill(changetype<usize>(buffer), 0, bufferSize);
76
+ }
77
+ this.buffer = buffer; // links
78
+ this.dataStart = changetype<usize>(buffer);
79
+ this.byteLength = <i32>bufferSize;
80
+ this.length_ = length;
81
+ }
82
+
83
+ get length(): i32 {
84
+ return this.length_;
85
+ }
86
+
87
+ set length(newLength: i32) {
88
+ ensureCapacity(changetype<usize>(this), newLength, alignof<T>(), false);
89
+ this.length_ = newLength;
90
+ }
91
+
92
+ every(fn: (value: T, index: i32, array: Array<T>) => bool): bool {
93
+ for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
94
+ if (!fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this)) return false;
95
+ }
96
+ return true;
97
+ }
98
+
99
+ findIndex(fn: (value: T, index: i32, array: Array<T>) => bool): i32 {
100
+ for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
101
+ if (fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this)) return i;
102
+ }
103
+ return -1;
104
+ }
105
+
106
+ findLastIndex(fn: (value: T, index: i32, array: Array<T>) => bool): i32 {
107
+ for (let i = this.length_ - 1; i >= 0; --i) {
108
+ if (fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this)) return i;
109
+ }
110
+ return -1;
111
+ }
112
+
113
+ @operator("[]") private __get(index: i32): T {
114
+ if (<u32>index >= <u32>this.length_) throw new RangeError(E_INDEXOUTOFRANGE);
115
+ let value = load<T>(this.dataStart + (<usize>index << alignof<T>()));
116
+ if (isReference<T>()) {
117
+ if (!isNullable<T>()) {
118
+ if (!changetype<usize>(value)) throw new Error(E_HOLEYARRAY);
119
+ }
120
+ }
121
+ return value;
122
+ }
123
+
124
+ @unsafe @operator("{}") private __uget(index: i32): T {
125
+ return load<T>(this.dataStart + (<usize>index << alignof<T>()));
126
+ }
127
+
128
+ @operator("[]=") private __set(index: i32, value: T): void {
129
+ if (<u32>index >= <u32>this.length_) {
130
+ if (index < 0) throw new RangeError(E_INDEXOUTOFRANGE);
131
+ ensureCapacity(changetype<usize>(this), index + 1, alignof<T>());
132
+ this.length_ = index + 1;
133
+ }
134
+ store<T>(this.dataStart + (<usize>index << alignof<T>()), value);
135
+ if (isManaged<T>()) {
136
+ __link(changetype<usize>(this), changetype<usize>(value), true);
137
+ }
138
+ }
139
+
140
+ at(index: i32): T {
141
+ let len = this.length_;
142
+ index += select(0, len, index >= 0);
143
+ if (<u32>index >= <u32>len) throw new RangeError(E_INDEXOUTOFRANGE);
144
+ let value = load<T>(this.dataStart + (<usize>index << alignof<T>()));
145
+ if (isReference<T>()) {
146
+ if (!isNullable<T>()) {
147
+ if (!changetype<usize>(value)) throw new Error(E_HOLEYARRAY);
148
+ }
149
+ }
150
+ return value;
151
+ }
152
+
153
+ fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): Array<T> {
154
+ if (isManaged<T>()) {
155
+ FILL<usize>(this.dataStart, this.length_, changetype<usize>(value), start, end);
156
+ __link(changetype<usize>(this), changetype<usize>(value), false);
157
+ } else {
158
+ FILL<T>(this.dataStart, this.length_, value, start, end);
159
+ }
160
+ return this;
161
+ }
162
+
163
+ includes(value: T, fromIndex: i32 = 0): bool {
164
+ if (isFloat<T>()) {
165
+ let len = this.length_;
166
+ if (len == 0 || fromIndex >= len) return false;
167
+ if (fromIndex < 0) fromIndex = max(len + fromIndex, 0);
168
+ let ptr = this.dataStart;
169
+ while (fromIndex < len) {
170
+ let elem = load<T>(ptr + (<usize>fromIndex << alignof<T>()));
171
+ // @ts-ignore
172
+ if (elem == value || isNaN(elem) & isNaN(value)) return true;
173
+ ++fromIndex;
174
+ }
175
+ return false;
176
+ } else {
177
+ return this.indexOf(value, fromIndex) >= 0;
178
+ }
179
+ }
180
+
181
+ indexOf(value: T, fromIndex: i32 = 0): i32 {
182
+ let len = this.length_;
183
+ if (len == 0 || fromIndex >= len) return -1;
184
+ if (fromIndex < 0) fromIndex = max(len + fromIndex, 0);
185
+ let ptr = this.dataStart;
186
+ while (fromIndex < len) {
187
+ if (load<T>(ptr + (<usize>fromIndex << alignof<T>())) == value) return fromIndex;
188
+ ++fromIndex;
189
+ }
190
+ return -1;
191
+ }
192
+
193
+ lastIndexOf(value: T, fromIndex: i32 = this.length_): i32 {
194
+ let len = this.length_;
195
+ if (len == 0) return -1;
196
+ if (fromIndex < 0) fromIndex = len + fromIndex;
197
+ else if (fromIndex >= len) fromIndex = len - 1;
198
+ let ptr = this.dataStart;
199
+ while (fromIndex >= 0) {
200
+ if (load<T>(ptr + (<usize>fromIndex << alignof<T>())) == value) return fromIndex;
201
+ --fromIndex;
202
+ }
203
+ return -1;
204
+ }
205
+
206
+ push(value: T): i32 {
207
+ let oldLen = this.length_;
208
+ let len = oldLen + 1;
209
+ ensureCapacity(changetype<usize>(this), len, alignof<T>());
210
+ if (isManaged<T>()) {
211
+ store<usize>(this.dataStart + (<usize>oldLen << alignof<T>()), changetype<usize>(value));
212
+ __link(changetype<usize>(this), changetype<usize>(value), true);
213
+ } else {
214
+ store<T>(this.dataStart + (<usize>oldLen << alignof<T>()), value);
215
+ }
216
+ this.length_ = len;
217
+ return len;
218
+ }
219
+
220
+ concat(other: Array<T>): Array<T> {
221
+ let thisLen = this.length_;
222
+ let otherLen = other.length_;
223
+ let outLen = thisLen + otherLen;
224
+ if (<u32>outLen > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new Error(E_INVALIDLENGTH);
225
+ let out = changetype<Array<T>>(__newArray(outLen, alignof<T>(), idof<Array<T>>()));
226
+ let outStart = out.dataStart;
227
+ let thisSize = <usize>thisLen << alignof<T>();
228
+ if (isManaged<T>()) {
229
+ let thisStart = this.dataStart;
230
+ for (let offset: usize = 0; offset < thisSize; offset += sizeof<T>()) {
231
+ let ref = load<usize>(thisStart + offset);
232
+ store<usize>(outStart + offset, ref);
233
+ __link(changetype<usize>(out), ref, true);
234
+ }
235
+ outStart += thisSize;
236
+ let otherStart = other.dataStart;
237
+ let otherSize = <usize>otherLen << alignof<T>();
238
+ for (let offset: usize = 0; offset < otherSize; offset += sizeof<T>()) {
239
+ let ref = load<usize>(otherStart + offset);
240
+ store<usize>(outStart + offset, ref);
241
+ __link(changetype<usize>(out), ref, true);
242
+ }
243
+ } else {
244
+ memory.copy(outStart, this.dataStart, thisSize);
245
+ memory.copy(outStart + thisSize, other.dataStart, <usize>otherLen << alignof<T>());
246
+ }
247
+ return out;
248
+ }
249
+
250
+ copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Array<T> {
251
+ let ptr = this.dataStart;
252
+ let len = this.length_;
253
+
254
+ end = min<i32>(end, len);
255
+
256
+ let to = target < 0 ? max(len + target, 0) : min(target, len);
257
+ let from = start < 0 ? max(len + start, 0) : min(start, len);
258
+ let last = end < 0 ? max(len + end, 0) : min(end, len);
259
+ let count = min(last - from, len - to);
260
+
261
+ memory.copy( // is memmove
262
+ ptr + (<usize>to << alignof<T>()),
263
+ ptr + (<usize>from << alignof<T>()),
264
+ <usize>count << alignof<T>()
265
+ );
266
+ return this;
267
+ }
268
+
269
+ pop(): T {
270
+ let len = this.length_;
271
+ if (len < 1) throw new RangeError(E_EMPTYARRAY);
272
+ let val = load<T>(this.dataStart + (<usize>(--len) << alignof<T>()));
273
+ this.length_ = len;
274
+ return val;
275
+ }
276
+
277
+ forEach(fn: (value: T, index: i32, array: Array<T>) => void): void {
278
+ for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
279
+ fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
280
+ }
281
+ }
282
+
283
+ map<U>(fn: (value: T, index: i32, array: Array<T>) => U): Array<U> {
284
+ let len = this.length_;
285
+ let out = changetype<Array<U>>(__newArray(len, alignof<U>(), idof<Array<U>>()));
286
+ let outStart = out.dataStart;
287
+ for (let i = 0; i < min(len, this.length_); ++i) {
288
+ let result = fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
289
+ store<U>(outStart + (<usize>i << alignof<U>()), result);
290
+ if (isManaged<U>()) {
291
+ __link(changetype<usize>(out), changetype<usize>(result), true);
292
+ }
293
+ }
294
+ return out;
295
+ }
296
+
297
+ filter(fn: (value: T, index: i32, array: Array<T>) => bool): Array<T> {
298
+ let result = changetype<Array<T>>(__newArray(0, alignof<T>(), idof<Array<T>>()));
299
+ for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
300
+ let value = load<T>(this.dataStart + (<usize>i << alignof<T>()));
301
+ if (fn(value, i, this)) result.push(value);
302
+ }
303
+ return result;
304
+ }
305
+
306
+ reduce<U>(
307
+ fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array<T>) => U,
308
+ initialValue: U
309
+ ): U {
310
+ let acc = initialValue;
311
+ for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
312
+ acc = fn(acc, load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
313
+ }
314
+ return acc;
315
+ }
316
+
317
+ reduceRight<U>(
318
+ fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array<T>) => U,
319
+ initialValue: U
320
+ ): U {
321
+ let acc = initialValue;
322
+ for (let i = this.length_ - 1; i >= 0; --i) {
323
+ acc = fn(acc, load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this);
324
+ }
325
+ return acc;
326
+ }
327
+
328
+ shift(): T {
329
+ let len = this.length_;
330
+ if (len < 1) throw new RangeError(E_EMPTYARRAY);
331
+ let base = this.dataStart;
332
+ let element = load<T>(base);
333
+ let lastIndex = len - 1;
334
+ memory.copy(
335
+ base,
336
+ base + sizeof<T>(),
337
+ <usize>lastIndex << alignof<T>()
338
+ );
339
+ if (isReference<T>()) {
340
+ store<usize>(base + (<usize>lastIndex << alignof<T>()), 0);
341
+ } else {
342
+ // @ts-ignore
343
+ store<T>(base + (<usize>lastIndex << alignof<T>()), <T>0);
344
+ }
345
+ this.length_ = lastIndex;
346
+ return element;
347
+ }
348
+
349
+ some(fn: (value: T, index: i32, array: Array<T>) => bool): bool {
350
+ for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {
351
+ if (fn(load<T>(this.dataStart + (<usize>i << alignof<T>())), i, this)) return true;
352
+ }
353
+ return false;
354
+ }
355
+
356
+ unshift(value: T): i32 {
357
+ let len = this.length_ + 1;
358
+ ensureCapacity(changetype<usize>(this), len, alignof<T>());
359
+ let ptr = this.dataStart;
360
+ memory.copy(
361
+ ptr + sizeof<T>(),
362
+ ptr,
363
+ <usize>(len - 1) << alignof<T>()
364
+ );
365
+ store<T>(ptr, value);
366
+ if (isManaged<T>()) {
367
+ __link(changetype<usize>(this), changetype<usize>(value), true);
368
+ }
369
+ this.length_ = len;
370
+ return len;
371
+ }
372
+
373
+ slice(start: i32 = 0, end: i32 = i32.MAX_VALUE): Array<T> {
374
+ let len = this.length_;
375
+ start = start < 0 ? max(start + len, 0) : min(start, len);
376
+ end = end < 0 ? max(end + len, 0) : min(end , len);
377
+ len = max(end - start, 0);
378
+ let slice = changetype<Array<T>>(__newArray(len, alignof<T>(), idof<Array<T>>()));
379
+ let sliceBase = slice.dataStart;
380
+ let thisBase = this.dataStart + (<usize>start << alignof<T>());
381
+ if (isManaged<T>()) {
382
+ let off = <usize>0;
383
+ let end = <usize>len << alignof<usize>();
384
+ while (off < end) {
385
+ let ref = load<usize>(thisBase + off);
386
+ store<usize>(sliceBase + off, ref);
387
+ __link(changetype<usize>(slice), ref, true);
388
+ off += sizeof<usize>();
389
+ }
390
+ } else {
391
+ memory.copy(sliceBase, thisBase, len << alignof<T>());
392
+ }
393
+ return slice;
394
+ }
395
+
396
+ splice(start: i32, deleteCount: i32 = i32.MAX_VALUE): Array<T> {
397
+ let len = this.length_;
398
+ start = start < 0 ? max<i32>(len + start, 0) : min<i32>(start, len);
399
+ deleteCount = max<i32>(min<i32>(deleteCount, len - start), 0);
400
+ let result = changetype<Array<T>>(__newArray(deleteCount, alignof<T>(), idof<Array<T>>()));
401
+ let resultStart = result.dataStart;
402
+ let thisStart = this.dataStart;
403
+ let thisBase = thisStart + (<usize>start << alignof<T>());
404
+ memory.copy(
405
+ resultStart,
406
+ thisBase,
407
+ <usize>deleteCount << alignof<T>()
408
+ );
409
+ let offset = start + deleteCount;
410
+ if (len != offset) {
411
+ memory.copy(
412
+ thisBase,
413
+ thisStart + (<usize>offset << alignof<T>()),
414
+ <usize>(len - offset) << alignof<T>()
415
+ );
416
+ }
417
+ this.length_ = len - deleteCount;
418
+ return result;
419
+ }
420
+
421
+ reverse(): Array<T> {
422
+ REVERSE<T>(this.dataStart, this.length_);
423
+ return this;
424
+ }
425
+
426
+ sort(comparator: (a: T, b: T) => i32 = COMPARATOR<T>()): Array<T> {
427
+ SORT<T>(this.dataStart, this.length_, comparator);
428
+ return this;
429
+ }
430
+
431
+ join(separator: string = ","): string {
432
+ let ptr = this.dataStart;
433
+ let len = this.length_;
434
+ if (isBoolean<T>()) return joinBooleanArray(ptr, len, separator);
435
+ if (isInteger<T>()) return joinIntegerArray<T>(ptr, len, separator);
436
+ if (isFloat<T>()) return joinFloatArray<T>(ptr, len, separator);
437
+
438
+ if (ASC_SHRINK_LEVEL < 1) {
439
+ if (isString<T>()) return joinStringArray(ptr, len, separator);
440
+ }
441
+ // For rest objects and arrays use general join routine
442
+ if (isReference<T>()) return joinReferenceArray<T>(ptr, len, separator);
443
+ ERROR("unspported element type");
444
+ return <string>unreachable();
445
+ }
446
+
447
+ flat(): T {
448
+ if (!isArray<T>()) {
449
+ ERROR("Cannot call flat() on Array<T> where T is not an Array.");
450
+ }
451
+ // Get the length and data start values
452
+ let ptr = this.dataStart;
453
+ let len = this.length_;
454
+
455
+ // calculate the end size with an initial pass
456
+ let size = 0;
457
+ for (let i = 0; i < len; ++i) {
458
+ let child = load<usize>(ptr + (i << alignof<T>()));
459
+ size += child == 0 ? 0 : load<i32>(child, offsetof<T>("length_"));
460
+ }
461
+
462
+ // calculate the byteLength of the resulting backing ArrayBuffer
463
+ const align = alignof<valueof<T>>();
464
+ let byteLength = <usize>size << align;
465
+ let outBuffer = changetype<ArrayBuffer>(__new(byteLength, idof<ArrayBuffer>()));
466
+
467
+ // create the return value and initialize it
468
+ let outArray = changetype<T>(__new(offsetof<T>(), idof<T>()));
469
+ store<i32>(changetype<usize>(outArray), size, offsetof<T>("length_"));
470
+
471
+ // byteLength, dataStart, and buffer are all readonly
472
+ store<i32>(changetype<usize>(outArray), byteLength, offsetof<T>("byteLength"));
473
+ store<usize>(changetype<usize>(outArray), changetype<usize>(outBuffer), offsetof<T>("dataStart"));
474
+ store<usize>(changetype<usize>(outArray), changetype<usize>(outBuffer), offsetof<T>("buffer"));
475
+ __link(changetype<usize>(outArray), changetype<usize>(outBuffer), false);
476
+
477
+ // set the elements
478
+ let resultOffset: usize = 0;
479
+ for (let i = 0; i < len; ++i) { // for each child
480
+ let child = load<usize>(ptr + (<usize>i << alignof<T>()));
481
+
482
+ // ignore null arrays
483
+ if (!child) continue;
484
+
485
+ // copy the underlying buffer data to the result buffer
486
+ let childDataLength = <usize>load<i32>(child, offsetof<T>("length_")) << align;
487
+ memory.copy(
488
+ changetype<usize>(outBuffer) + resultOffset,
489
+ load<usize>(child, offsetof<T>("dataStart")),
490
+ childDataLength
491
+ );
492
+
493
+ // advance the result length
494
+ resultOffset += childDataLength;
495
+ }
496
+
497
+ // if the `valueof<T>` type is managed, we must link each reference
498
+ if (isManaged<valueof<T>>()) {
499
+ for (let i = 0; i < size; ++i) {
500
+ let ref = load<usize>(changetype<usize>(outBuffer) + (<usize>i << usize(alignof<valueof<T>>())));
501
+ __link(changetype<usize>(outBuffer), ref, true);
502
+ }
503
+ }
504
+
505
+ return outArray;
506
+ }
507
+
508
+ toString(): string {
509
+ return this.join();
510
+ }
511
+
512
+ // RT integration
513
+
514
+ @unsafe private __visit(cookie: u32): void {
515
+ if (isManaged<T>()) {
516
+ let cur = this.dataStart;
517
+ let end = cur + (<usize>this.length_ << alignof<T>());
518
+ while (cur < end) {
519
+ let val = load<usize>(cur);
520
+ if (val) __visit(val, cookie);
521
+ cur += sizeof<usize>();
522
+ }
523
+ }
524
+ __visit(changetype<usize>(this.buffer), cookie);
525
+ }
526
+ }