@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.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/README.ru.md +162 -0
- package/amxmodx/base/include/amxconst.inc +594 -0
- package/amxmodx/base/include/amxmisc.inc +902 -0
- package/amxmodx/base/include/amxmodx.inc +3447 -0
- package/amxmodx/base/include/amxmodx_version.inc +20 -0
- package/amxmodx/base/include/cellarray.inc +525 -0
- package/amxmodx/base/include/cellstack.inc +166 -0
- package/amxmodx/base/include/celltrie.inc +412 -0
- package/amxmodx/base/include/core.inc +202 -0
- package/amxmodx/base/include/csstats.inc +298 -0
- package/amxmodx/base/include/csstats_const.inc +29 -0
- package/amxmodx/base/include/cstrike.inc +1287 -0
- package/amxmodx/base/include/cstrike_const.inc +521 -0
- package/amxmodx/base/include/csx.inc +259 -0
- package/amxmodx/base/include/cvars.inc +547 -0
- package/amxmodx/base/include/datapack.inc +161 -0
- package/amxmodx/base/include/dbi.inc +154 -0
- package/amxmodx/base/include/dodconst.inc +152 -0
- package/amxmodx/base/include/dodfun.inc +152 -0
- package/amxmodx/base/include/dodstats.inc +69 -0
- package/amxmodx/base/include/dodx.inc +161 -0
- package/amxmodx/base/include/engine.inc +1343 -0
- package/amxmodx/base/include/engine_const.inc +310 -0
- package/amxmodx/base/include/engine_stocks.inc +248 -0
- package/amxmodx/base/include/esf.inc +70 -0
- package/amxmodx/base/include/esf_const.inc +74 -0
- package/amxmodx/base/include/fakemeta.inc +1127 -0
- package/amxmodx/base/include/fakemeta_const.inc +793 -0
- package/amxmodx/base/include/fakemeta_stocks.inc +395 -0
- package/amxmodx/base/include/fakemeta_util.inc +882 -0
- package/amxmodx/base/include/file.inc +666 -0
- package/amxmodx/base/include/float.inc +422 -0
- package/amxmodx/base/include/fun.inc +333 -0
- package/amxmodx/base/include/gameconfig.inc +93 -0
- package/amxmodx/base/include/geoip.inc +264 -0
- package/amxmodx/base/include/ham_const.inc +4352 -0
- package/amxmodx/base/include/hamsandwich.inc +439 -0
- package/amxmodx/base/include/hlsdk_const.inc +808 -0
- package/amxmodx/base/include/json.inc +777 -0
- package/amxmodx/base/include/lang.inc +119 -0
- package/amxmodx/base/include/message_const.inc +1130 -0
- package/amxmodx/base/include/message_stocks.inc +161 -0
- package/amxmodx/base/include/messages.inc +604 -0
- package/amxmodx/base/include/newmenus.inc +387 -0
- package/amxmodx/base/include/ns.inc +754 -0
- package/amxmodx/base/include/ns_const.inc +196 -0
- package/amxmodx/base/include/nvault.inc +154 -0
- package/amxmodx/base/include/regex.inc +348 -0
- package/amxmodx/base/include/sockets.inc +183 -0
- package/amxmodx/base/include/sorting.inc +107 -0
- package/amxmodx/base/include/sqlx.inc +582 -0
- package/amxmodx/base/include/string.inc +786 -0
- package/amxmodx/base/include/string_const.inc +156 -0
- package/amxmodx/base/include/string_stocks.inc +325 -0
- package/amxmodx/base/include/textparse_ini.inc +214 -0
- package/amxmodx/base/include/textparse_smc.inc +261 -0
- package/amxmodx/base/include/tfcconst.inc +84 -0
- package/amxmodx/base/include/tfcstats.inc +62 -0
- package/amxmodx/base/include/tfcx.inc +148 -0
- package/amxmodx/base/include/time.inc +118 -0
- package/amxmodx/base/include/tsconst.inc +154 -0
- package/amxmodx/base/include/tsfun.inc +198 -0
- package/amxmodx/base/include/tsstats.inc +65 -0
- package/amxmodx/base/include/tsx.inc +88 -0
- package/amxmodx/base/include/vault.inc +60 -0
- package/amxmodx/base/include/vector.inc +131 -0
- package/amxmodx/base/include/xs.inc +1570 -0
- package/as/amxts.d.ts +153 -0
- package/as/constants.ts +4730 -0
- package/as/effects.ts +1449 -0
- package/as/entities.ts +5482 -0
- package/as/events.ts +3054 -0
- package/as/facade.ts +4639 -0
- package/as/flags.ts +299 -0
- package/as/fs.ts +287 -0
- package/as/hooks.ts +18536 -0
- package/as/kit.ts +25 -0
- package/as/lib/check.ts +86 -0
- package/as/modules/http.ts +184 -0
- package/as/natives.ts +11845 -0
- package/as/os.ts +30 -0
- package/as/promise.ts +1392 -0
- package/as/promise.types.d.ts +82 -0
- package/as/remote.ts +288 -0
- package/as/tsconfig.json +22 -0
- package/as/vector.ts +65 -0
- package/bin/amxts.mjs +10 -0
- package/includes/menu_core.inc +355 -0
- package/includes/order.txt +54 -0
- package/includes/sources.json +27 -0
- package/includes/universal_config.inc +355 -0
- package/lint/oxlint-plugin.mjs +77 -0
- package/node_modules/assemblyscript/LICENSE +201 -0
- package/node_modules/assemblyscript/NOTICE +93 -0
- package/node_modules/assemblyscript/package.json +63 -0
- package/node_modules/assemblyscript/std/README.md +6 -0
- package/node_modules/assemblyscript/std/assembly/array.ts +526 -0
- package/node_modules/assemblyscript/std/assembly/arraybuffer.ts +77 -0
- package/node_modules/assemblyscript/std/assembly/atomics.ts +127 -0
- package/node_modules/assemblyscript/std/assembly/bindings/asyncify.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/bindings/dom.ts +291 -0
- package/node_modules/assemblyscript/std/assembly/bindings/node.ts +6 -0
- package/node_modules/assemblyscript/std/assembly/builtins.ts +2631 -0
- package/node_modules/assemblyscript/std/assembly/compat.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/console.ts +42 -0
- package/node_modules/assemblyscript/std/assembly/crypto.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/dataview.ts +181 -0
- package/node_modules/assemblyscript/std/assembly/date.ts +373 -0
- package/node_modules/assemblyscript/std/assembly/diagnostics.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/error.ts +44 -0
- package/node_modules/assemblyscript/std/assembly/function.ts +38 -0
- package/node_modules/assemblyscript/std/assembly/index.d.ts +2822 -0
- package/node_modules/assemblyscript/std/assembly/iterator.ts +35 -0
- package/node_modules/assemblyscript/std/assembly/map.ts +260 -0
- package/node_modules/assemblyscript/std/assembly/math.ts +3289 -0
- package/node_modules/assemblyscript/std/assembly/memory.ts +123 -0
- package/node_modules/assemblyscript/std/assembly/number.ts +388 -0
- package/node_modules/assemblyscript/std/assembly/object.ts +36 -0
- package/node_modules/assemblyscript/std/assembly/performance.ts +9 -0
- package/node_modules/assemblyscript/std/assembly/polyfills.ts +27 -0
- package/node_modules/assemblyscript/std/assembly/process.ts +50 -0
- package/node_modules/assemblyscript/std/assembly/reference.ts +48 -0
- package/node_modules/assemblyscript/std/assembly/regexp.ts +12 -0
- package/node_modules/assemblyscript/std/assembly/rt/README.md +83 -0
- package/node_modules/assemblyscript/std/assembly/rt/common.ts +81 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-incremental.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-minimal.ts +2 -0
- package/node_modules/assemblyscript/std/assembly/rt/index-stub.ts +1 -0
- package/node_modules/assemblyscript/std/assembly/rt/index.d.ts +37 -0
- package/node_modules/assemblyscript/std/assembly/rt/itcms.ts +419 -0
- package/node_modules/assemblyscript/std/assembly/rt/rtrace.ts +15 -0
- package/node_modules/assemblyscript/std/assembly/rt/stub.ts +133 -0
- package/node_modules/assemblyscript/std/assembly/rt/tcms.ts +254 -0
- package/node_modules/assemblyscript/std/assembly/rt/tlsf.ts +592 -0
- package/node_modules/assemblyscript/std/assembly/rt.ts +87 -0
- package/node_modules/assemblyscript/std/assembly/set.ts +220 -0
- package/node_modules/assemblyscript/std/assembly/shared/feature.ts +65 -0
- package/node_modules/assemblyscript/std/assembly/shared/runtime.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/target.ts +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/tsconfig.json +11 -0
- package/node_modules/assemblyscript/std/assembly/shared/typeinfo.ts +72 -0
- package/node_modules/assemblyscript/std/assembly/staticarray.ts +401 -0
- package/node_modules/assemblyscript/std/assembly/string.ts +847 -0
- package/node_modules/assemblyscript/std/assembly/symbol.ts +114 -0
- package/node_modules/assemblyscript/std/assembly/table.ts +16 -0
- package/node_modules/assemblyscript/std/assembly/tsconfig.json +6 -0
- package/node_modules/assemblyscript/std/assembly/typedarray.ts +1945 -0
- package/node_modules/assemblyscript/std/assembly/uri.ts +17 -0
- package/node_modules/assemblyscript/std/assembly/util/bytes.ts +107 -0
- package/node_modules/assemblyscript/std/assembly/util/casemap.ts +497 -0
- package/node_modules/assemblyscript/std/assembly/util/error.ts +54 -0
- package/node_modules/assemblyscript/std/assembly/util/hash.ts +117 -0
- package/node_modules/assemblyscript/std/assembly/util/math.ts +1922 -0
- package/node_modules/assemblyscript/std/assembly/util/memory.ts +290 -0
- package/node_modules/assemblyscript/std/assembly/util/number.ts +873 -0
- package/node_modules/assemblyscript/std/assembly/util/sort.ts +313 -0
- package/node_modules/assemblyscript/std/assembly/util/string.ts +1202 -0
- package/node_modules/assemblyscript/std/assembly/util/uri.ts +275 -0
- package/node_modules/assemblyscript/std/assembly/vector.ts +4 -0
- package/node_modules/assemblyscript/std/assembly.json +16 -0
- package/node_modules/assemblyscript/std/portable/index.d.ts +462 -0
- package/node_modules/assemblyscript/std/portable/index.js +416 -0
- package/node_modules/assemblyscript/std/portable.json +11 -0
- package/node_modules/assemblyscript/std/types/assembly/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/assembly/package.json +3 -0
- package/node_modules/assemblyscript/std/types/portable/index.d.ts +1 -0
- package/node_modules/assemblyscript/std/types/portable/package.json +3 -0
- package/node_modules/assemblyscript/tsconfig-base.json +13 -0
- package/package.json +112 -0
- package/runtime/deps/assemblyscript/LICENSE +201 -0
- package/runtime/deps/assemblyscript/NOTICE +93 -0
- package/runtime/deps/assemblyscript/bin/asc.js +35 -0
- package/runtime/deps/assemblyscript/dist/asc.js +25035 -0
- package/runtime/deps/assemblyscript/dist/assemblyscript.js +337 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/LICENSE +201 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/index.js +28905 -0
- package/runtime/deps/assemblyscript/node_modules/binaryen/package.json +50 -0
- package/runtime/deps/assemblyscript/node_modules/long/LICENSE +202 -0
- package/runtime/deps/assemblyscript/node_modules/long/index.js +1581 -0
- package/runtime/deps/assemblyscript/node_modules/long/package.json +58 -0
- package/runtime/deps/assemblyscript/package.json +114 -0
- package/runtime/host/amxts.inc +85 -0
- package/runtime/licenses/AMXX-LICENSE.txt +34 -0
- package/runtime/licenses/AssemblyScript-LICENSE +201 -0
- package/runtime/licenses/AssemblyScript-NOTICE +93 -0
- package/runtime/licenses/Binaryen-LICENSE +201 -0
- package/runtime/licenses/Bun-LICENSE.md +84 -0
- package/runtime/licenses/GPL-3.0.txt +674 -0
- package/runtime/licenses/LLVM-LICENSE.TXT +279 -0
- package/runtime/licenses/README.md +25 -0
- package/runtime/licenses/WAMR-LICENSE +219 -0
- package/runtime/natives.txt +1095 -0
- package/runtime/patches/README.md +59 -0
- package/runtime/patches/assemblyscript-0.28.20-amxts.patch +14174 -0
- package/runtime/patches/wamr-2.4.5-amxts.patch +364 -0
- package/scripts/apply-docs.ts +508 -0
- package/scripts/asc.ts +27 -0
- package/scripts/auto-imports.ts +258 -0
- package/scripts/build-wasm.ts +595 -0
- package/scripts/check.ts +93 -0
- package/scripts/compile-cache.ts +179 -0
- package/scripts/compile.ts +401 -0
- package/scripts/docker-server.ts +73 -0
- package/scripts/docs/as/amxts.ts +210 -0
- package/scripts/docs/as/effects.ts +1684 -0
- package/scripts/docs/as/facade.ts +3302 -0
- package/scripts/docs/as/fs.ts +173 -0
- package/scripts/docs/as/lib/check.ts +68 -0
- package/scripts/docs/as/modules/http.ts +66 -0
- package/scripts/docs/as/os.ts +16 -0
- package/scripts/docs/as/promise.ts +132 -0
- package/scripts/docs/as/promise.types.ts +63 -0
- package/scripts/docs/as/vector.ts +48 -0
- package/scripts/docs/entities.ts +2338 -0
- package/scripts/docs/events.ts +245 -0
- package/scripts/docs/game.ts +497 -0
- package/scripts/docs/messages.ts +148 -0
- package/scripts/file-contents.ts +74 -0
- package/scripts/includes.ts +134 -0
- package/scripts/player-fields.ts +866 -0
- package/scripts/plugin-cache.ts +92 -0
- package/scripts/plugin-natives.ts +1157 -0
- package/scripts/prebuilt.ts +268 -0
- package/scripts/prepare.ts +134 -0
- package/scripts/project.ts +973 -0
- package/scripts/run.ts +28 -0
- package/scripts/shared-modules.ts +906 -0
- package/scripts/system.ts +33 -0
- package/scripts/tracked-fs.ts +115 -0
- package/scripts/typed-configs.ts +788 -0
- package/scripts/ui.ts +77 -0
- package/src/cli-api.mjs +175 -0
- package/src/parser/include-parser.ts +506 -0
- package/src/system.mjs +155 -0
- package/src/testing/compile-cache.ts +31 -0
- package/src/testing/compile.ts +222 -0
- package/src/testing/coroutines.ts +191 -0
- package/src/testing/index.ts +39 -0
- package/src/testing/kits.ts +55 -0
- package/src/testing/memory.ts +125 -0
- package/src/testing/natives.ts +925 -0
- package/src/testing/server.ts +1874 -0
- package/src/testing/setup.ts +63 -0
- package/src/testing/tables.ts +139 -0
- package/src/types.ts +51 -0
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
/// <reference path="./rt/index.d.ts" />
|
|
2
|
+
|
|
3
|
+
import { OBJECT, BLOCK_MAXSIZE, TOTAL_OVERHEAD } 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 { idof } from "./builtins";
|
|
8
|
+
import { Array } from "./array";
|
|
9
|
+
import { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_HOLEYARRAY } from "./util/error";
|
|
10
|
+
import { joinBooleanArray, joinIntegerArray, joinFloatArray, joinStringArray, joinReferenceArray } from "./util/string";
|
|
11
|
+
|
|
12
|
+
@final
|
|
13
|
+
export class StaticArray<T> {
|
|
14
|
+
[key: number]: T;
|
|
15
|
+
|
|
16
|
+
// Note that the interface of StaticArray instances must be a semantically
|
|
17
|
+
// compatible subset of Array<T> in order for syntax highlighting to work
|
|
18
|
+
// properly, for instance when creating static arrays from array literals.
|
|
19
|
+
// The additionally provided static methods take care of dealing with static
|
|
20
|
+
// arrays exclusively, without having to convert to Array<T> first.
|
|
21
|
+
|
|
22
|
+
static fromArray<T>(source: Array<T>): StaticArray<T> {
|
|
23
|
+
let length = source.length;
|
|
24
|
+
let outSize = <usize>length << alignof<T>();
|
|
25
|
+
let out = changetype<StaticArray<T>>(__new(outSize, idof<StaticArray<T>>()));
|
|
26
|
+
if (isManaged<T>()) {
|
|
27
|
+
let sourcePtr = source.dataStart;
|
|
28
|
+
for (let i = 0; i < length; ++i) {
|
|
29
|
+
let off = <usize>i << alignof<T>();
|
|
30
|
+
let ref = load<usize>(sourcePtr + off);
|
|
31
|
+
store<usize>(changetype<usize>(out) + off, ref);
|
|
32
|
+
__link(changetype<usize>(out), ref, true);
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
memory.copy(changetype<usize>(out), source.dataStart, outSize);
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** @deprecated Please use source.concat<StaticArray<T>> instead. */
|
|
41
|
+
static concat<T>(source: StaticArray<T>, other: StaticArray<T>): StaticArray<T> {
|
|
42
|
+
return source.concat<StaticArray<T>>(other);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** @deprecated Please use source.slice<StaticArray<T>> instead. */
|
|
46
|
+
static slice<T>(source: StaticArray<T>, start: i32 = 0, end: i32 = i32.MAX_VALUE): StaticArray<T> {
|
|
47
|
+
return source.slice<StaticArray<T>>(start, end);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
constructor(length: i32) {
|
|
51
|
+
if (<u32>length > <u32>BLOCK_MAXSIZE >>> alignof<T>()) throw new RangeError(E_INVALIDLENGTH);
|
|
52
|
+
let outSize = <usize>length << alignof<T>();
|
|
53
|
+
let out = changetype<StaticArray<T>>(__new(outSize, idof<StaticArray<T>>()));
|
|
54
|
+
if (ASC_RUNTIME != Runtime.Incremental) {
|
|
55
|
+
memory.fill(changetype<usize>(out), 0, outSize);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get length(): i32 {
|
|
61
|
+
return changetype<OBJECT>(changetype<usize>(this) - TOTAL_OVERHEAD).rtSize >>> alignof<T>();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
at(index: i32): T {
|
|
65
|
+
let len = this.length;
|
|
66
|
+
index += select(0, len, index >= 0);
|
|
67
|
+
if (<u32>index >= <u32>len) throw new RangeError(E_INDEXOUTOFRANGE);
|
|
68
|
+
let value = load<T>(changetype<usize>(this) + (<usize>index << alignof<T>()));
|
|
69
|
+
if (isReference<T>()) {
|
|
70
|
+
if (!isNullable<T>()) {
|
|
71
|
+
if (!changetype<usize>(value)) throw new Error(E_HOLEYARRAY);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@operator("[]") private __get(index: i32): T {
|
|
78
|
+
if (<u32>index >= <u32>this.length) throw new RangeError(E_INDEXOUTOFRANGE);
|
|
79
|
+
let value = load<T>(changetype<usize>(this) + (<usize>index << alignof<T>()));
|
|
80
|
+
if (isReference<T>()) {
|
|
81
|
+
if (!isNullable<T>()) {
|
|
82
|
+
if (!changetype<usize>(value)) throw new Error(E_HOLEYARRAY);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@unsafe @operator("{}") private __uget(index: i32): T {
|
|
89
|
+
return load<T>(changetype<usize>(this) + (<usize>index << alignof<T>()));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@operator("[]=") private __set(index: i32, value: T): void {
|
|
93
|
+
if (<u32>index >= <u32>this.length) throw new RangeError(E_INDEXOUTOFRANGE);
|
|
94
|
+
this.__uset(index, value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@unsafe @operator("{}=") private __uset(index: i32, value: T): void {
|
|
98
|
+
store<T>(changetype<usize>(this) + (<usize>index << alignof<T>()), value);
|
|
99
|
+
if (isManaged<T>()) {
|
|
100
|
+
__link(changetype<usize>(this), changetype<usize>(value), true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): StaticArray<T> {
|
|
105
|
+
if (isManaged<T>()) {
|
|
106
|
+
FILL<usize>(changetype<usize>(this), this.length, changetype<usize>(value), start, end);
|
|
107
|
+
__link(changetype<usize>(this), changetype<usize>(value), false);
|
|
108
|
+
} else {
|
|
109
|
+
FILL<T>(changetype<usize>(this), this.length, value, start, end);
|
|
110
|
+
}
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): StaticArray<T> {
|
|
115
|
+
let ptr = changetype<usize>(this);
|
|
116
|
+
let len = this.length;
|
|
117
|
+
|
|
118
|
+
end = min<i32>(end, len);
|
|
119
|
+
|
|
120
|
+
let to = target < 0 ? max(len + target, 0) : min(target, len);
|
|
121
|
+
let from = start < 0 ? max(len + start, 0) : min(start, len);
|
|
122
|
+
let last = end < 0 ? max(len + end, 0) : min(end, len);
|
|
123
|
+
let count = min(last - from, len - to);
|
|
124
|
+
|
|
125
|
+
memory.copy( // is memmove
|
|
126
|
+
ptr + (<usize>to << alignof<T>()),
|
|
127
|
+
ptr + (<usize>from << alignof<T>()),
|
|
128
|
+
<usize>count << alignof<T>()
|
|
129
|
+
);
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
includes(value: T, fromIndex: i32 = 0): bool {
|
|
134
|
+
if (isFloat<T>()) {
|
|
135
|
+
let length = this.length;
|
|
136
|
+
if (length == 0 || fromIndex >= length) return false;
|
|
137
|
+
if (fromIndex < 0) fromIndex = max(length + fromIndex, 0);
|
|
138
|
+
while (fromIndex < length) {
|
|
139
|
+
let elem = load<T>(changetype<usize>(this) + (<usize>fromIndex << alignof<T>()));
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
if (elem == value || isNaN(elem) & isNaN(value)) return true;
|
|
142
|
+
++fromIndex;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
} else {
|
|
146
|
+
return this.indexOf(value, fromIndex) >= 0;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
indexOf(value: T, fromIndex: i32 = 0): i32 {
|
|
151
|
+
let length = this.length;
|
|
152
|
+
if (length == 0 || fromIndex >= length) return -1;
|
|
153
|
+
if (fromIndex < 0) fromIndex = max(length + fromIndex, 0);
|
|
154
|
+
while (fromIndex < length) {
|
|
155
|
+
if (load<T>(changetype<usize>(this) + (<usize>fromIndex << alignof<T>())) == value) return fromIndex;
|
|
156
|
+
++fromIndex;
|
|
157
|
+
}
|
|
158
|
+
return -1;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
lastIndexOf(value: T, fromIndex: i32 = this.length): i32 {
|
|
162
|
+
let length = this.length;
|
|
163
|
+
if (length == 0) return -1;
|
|
164
|
+
if (fromIndex < 0) fromIndex = length + fromIndex;
|
|
165
|
+
else if (fromIndex >= length) fromIndex = length - 1;
|
|
166
|
+
while (fromIndex >= 0) {
|
|
167
|
+
if (load<T>(changetype<usize>(this) + (<usize>fromIndex << alignof<T>())) == value) return fromIndex;
|
|
168
|
+
--fromIndex;
|
|
169
|
+
}
|
|
170
|
+
return -1;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
concat<U extends ArrayLike<T> = Array<T>>(other: U): U {
|
|
174
|
+
let sourceLen = this.length;
|
|
175
|
+
let otherLen = other.length;
|
|
176
|
+
let outLen = sourceLen + otherLen;
|
|
177
|
+
if (<u32>outLen > <u32>BLOCK_MAXSIZE >>> alignof<T>()) {
|
|
178
|
+
throw new Error(E_INVALIDLENGTH);
|
|
179
|
+
}
|
|
180
|
+
let sourceSize = <usize>sourceLen << alignof<T>();
|
|
181
|
+
let out = changetype<U>(this); // FIXME: instanceof needs *some* value
|
|
182
|
+
|
|
183
|
+
if (out instanceof Array<T>) {
|
|
184
|
+
out = changetype<U>(__newArray(outLen, alignof<T>(), idof<Array<T>>()));
|
|
185
|
+
// ^ FIXME: Function returns type U, but can't __newArray(U extends Array<T>)
|
|
186
|
+
let outStart = changetype<Array<T>>(out).dataStart;
|
|
187
|
+
let otherStart = changetype<Array<T>>(other).dataStart;
|
|
188
|
+
let thisStart = changetype<usize>(this);
|
|
189
|
+
|
|
190
|
+
if (isManaged<T>()) {
|
|
191
|
+
for (let offset: usize = 0; offset < sourceSize; offset += sizeof<T>()) {
|
|
192
|
+
let ref = load<usize>(thisStart + offset);
|
|
193
|
+
store<usize>(outStart + offset, ref);
|
|
194
|
+
__link(changetype<usize>(out), ref, true);
|
|
195
|
+
}
|
|
196
|
+
outStart += sourceSize;
|
|
197
|
+
let otherSize = <usize>otherLen << alignof<T>();
|
|
198
|
+
for (let offset: usize = 0; offset < otherSize; offset += sizeof<T>()) {
|
|
199
|
+
let ref = load<usize>(otherStart + offset);
|
|
200
|
+
store<usize>(outStart + offset, ref);
|
|
201
|
+
__link(changetype<usize>(out), ref, true);
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
memory.copy(outStart, thisStart, sourceSize);
|
|
205
|
+
memory.copy(outStart + sourceSize, otherStart, <usize>otherLen << alignof<T>());
|
|
206
|
+
}
|
|
207
|
+
} else if (out instanceof StaticArray<T>) {
|
|
208
|
+
out = changetype<U>(__new(<usize>outLen << alignof<T>(), idof<StaticArray<T>>()));
|
|
209
|
+
let outStart = changetype<usize>(out);
|
|
210
|
+
let otherStart = changetype<usize>(other);
|
|
211
|
+
let thisStart = changetype<usize>(this);
|
|
212
|
+
|
|
213
|
+
if (isManaged<T>()) {
|
|
214
|
+
for (let offset: usize = 0; offset < sourceSize; offset += sizeof<T>()) {
|
|
215
|
+
let ref = load<usize>(thisStart + offset);
|
|
216
|
+
store<usize>(outStart + offset, ref);
|
|
217
|
+
__link(changetype<usize>(out), ref, true);
|
|
218
|
+
}
|
|
219
|
+
outStart += sourceSize;
|
|
220
|
+
let otherSize = <usize>otherLen << alignof<T>();
|
|
221
|
+
for (let offset: usize = 0; offset < otherSize; offset += sizeof<T>()) {
|
|
222
|
+
let ref = load<usize>(otherStart + offset);
|
|
223
|
+
store<usize>(outStart + offset, ref);
|
|
224
|
+
__link(changetype<usize>(out), ref, true);
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
memory.copy(outStart, thisStart, sourceSize);
|
|
228
|
+
memory.copy(outStart + sourceSize, otherStart, <usize>otherLen << alignof<T>());
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
ERROR("Only Array<T> and StaticArray<T> accept for 'U' parameter");
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
slice<U extends ArrayLike<T> = Array<T>>(start: i32 = 0, end: i32 = i32.MAX_VALUE): U {
|
|
237
|
+
let length = this.length;
|
|
238
|
+
start = start < 0 ? max(start + length, 0) : min(start, length);
|
|
239
|
+
end = end < 0 ? max(end + length, 0) : min(end, length);
|
|
240
|
+
length = max(end - start, 0);
|
|
241
|
+
|
|
242
|
+
let sourceStart = changetype<usize>(this) + (<usize>start << alignof<T>());
|
|
243
|
+
let size = <usize>length << alignof<T>();
|
|
244
|
+
let out = changetype<U>(this); // FIXME: instanceof needs *some* value
|
|
245
|
+
|
|
246
|
+
if (out instanceof Array<T>) {
|
|
247
|
+
// return Array
|
|
248
|
+
out = changetype<U>(__newArray(length, alignof<T>(), idof<Array<T>>()));
|
|
249
|
+
// ^ FIXME: Function returns type U, but can't __newArray(U extends Array<T>)
|
|
250
|
+
let outStart = changetype<Array<T>>(out).dataStart;
|
|
251
|
+
if (isManaged<T>()) {
|
|
252
|
+
let off: usize = 0;
|
|
253
|
+
while (off < size) {
|
|
254
|
+
let ref = load<usize>(sourceStart + off);
|
|
255
|
+
store<usize>(outStart + off, ref);
|
|
256
|
+
__link(changetype<usize>(out), ref, true);
|
|
257
|
+
off += sizeof<usize>();
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
memory.copy(outStart, sourceStart, size);
|
|
261
|
+
}
|
|
262
|
+
} else if (out instanceof StaticArray<T>) {
|
|
263
|
+
// return StaticArray
|
|
264
|
+
out = changetype<U>(__new(size, idof<StaticArray<T>>()));
|
|
265
|
+
let outStart = changetype<usize>(out);
|
|
266
|
+
if (isManaged<T>()) {
|
|
267
|
+
let off: usize = 0;
|
|
268
|
+
while (off < size) {
|
|
269
|
+
let ref = load<usize>(sourceStart + off);
|
|
270
|
+
store<usize>(outStart + off, ref);
|
|
271
|
+
__link(outStart, ref, true);
|
|
272
|
+
off += sizeof<usize>();
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
memory.copy(outStart, sourceStart, size);
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
ERROR("Only Array<T> and StaticArray<T> accept for 'U' parameter");
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
findIndex(fn: (value: T, index: i32, array: StaticArray<T>) => bool): i32 {
|
|
284
|
+
for (let i = 0, len = this.length; i < len; ++i) {
|
|
285
|
+
if (fn(load<T>(changetype<usize>(this) + (<usize>i << alignof<T>())), i, this)) return i;
|
|
286
|
+
}
|
|
287
|
+
return -1;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
findLastIndex(fn: (value: T, index: i32, array: StaticArray<T>) => bool): i32 {
|
|
291
|
+
for (let i = this.length - 1; i >= 0; --i) {
|
|
292
|
+
if (fn(load<T>(changetype<usize>(this) + (<usize>i << alignof<T>())), i, this)) return i;
|
|
293
|
+
}
|
|
294
|
+
return -1;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
forEach(fn: (value: T, index: i32, array: StaticArray<T>) => void): void {
|
|
298
|
+
for (let i = 0, len = this.length; i < len; ++i) {
|
|
299
|
+
fn(load<T>(changetype<usize>(this) + (<usize>i << alignof<T>())), i, this);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
map<U>(fn: (value: T, index: i32, array: StaticArray<T>) => U): Array<U> {
|
|
304
|
+
let len = this.length;
|
|
305
|
+
let out = changetype<Array<U>>(__newArray(len, alignof<U>(), idof<Array<U>>()));
|
|
306
|
+
let outStart = out.dataStart;
|
|
307
|
+
for (let i = 0; i < len; ++i) {
|
|
308
|
+
let result = fn(load<T>(changetype<usize>(this) + (<usize>i << alignof<T>())), i, this);
|
|
309
|
+
store<U>(outStart + (<usize>i << alignof<U>()), result);
|
|
310
|
+
if (isManaged<U>()) {
|
|
311
|
+
__link(changetype<usize>(out), changetype<usize>(result), true);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
filter(fn: (value: T, index: i32, array: StaticArray<T>) => bool): Array<T> {
|
|
318
|
+
let result = changetype<Array<T>>(__newArray(0, alignof<T>(), idof<Array<T>>()));
|
|
319
|
+
for (let i = 0, len = this.length; i < len; ++i) {
|
|
320
|
+
let value = load<T>(changetype<usize>(this) + (<usize>i << alignof<T>()));
|
|
321
|
+
if (fn(value, i, this)) result.push(value);
|
|
322
|
+
}
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
reduce<U>(
|
|
327
|
+
fn: (previousValue: U, currentValue: T, currentIndex: i32, array: StaticArray<T>) => U,
|
|
328
|
+
initialValue: U
|
|
329
|
+
): U {
|
|
330
|
+
let acc = initialValue;
|
|
331
|
+
for (let i = 0, len = this.length; i < len; ++i) {
|
|
332
|
+
acc = fn(acc, load<T>(changetype<usize>(this) + (<usize>i << alignof<T>())), i, this);
|
|
333
|
+
}
|
|
334
|
+
return acc;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
reduceRight<U>(
|
|
338
|
+
fn: (previousValue: U, currentValue: T, currentIndex: i32, array: StaticArray<T>) => U,
|
|
339
|
+
initialValue: U
|
|
340
|
+
): U {
|
|
341
|
+
let acc = initialValue;
|
|
342
|
+
for (let i = this.length - 1; i >= 0; --i) {
|
|
343
|
+
acc = fn(acc, load<T>(changetype<usize>(this) + (<usize>i << alignof<T>())), i, this);
|
|
344
|
+
}
|
|
345
|
+
return acc;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
every(fn: (value: T, index: i32, array: StaticArray<T>) => bool): bool {
|
|
349
|
+
for (let i = 0, len = this.length; i < len; ++i) {
|
|
350
|
+
if (!fn(load<T>(changetype<usize>(this) + (<usize>i << alignof<T>())), i, this)) return false;
|
|
351
|
+
}
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
some(fn: (value: T, index: i32, array: StaticArray<T>) => bool): bool {
|
|
356
|
+
for (let i = 0, len = this.length; i < len; ++i) {
|
|
357
|
+
if (fn(load<T>(changetype<usize>(this) + (<usize>i << alignof<T>())), i, this)) return true;
|
|
358
|
+
}
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
sort(comparator: (a: T, b: T) => i32 = COMPARATOR<T>()): StaticArray<T> {
|
|
363
|
+
SORT<T>(changetype<usize>(this), this.length, comparator);
|
|
364
|
+
return this;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
join(separator: string = ","): string {
|
|
368
|
+
if (isBoolean<T>()) return joinBooleanArray(changetype<usize>(this), this.length, separator);
|
|
369
|
+
if (isInteger<T>()) return joinIntegerArray<T>(changetype<usize>(this), this.length, separator);
|
|
370
|
+
if (isFloat<T>()) return joinFloatArray<T>(changetype<usize>(this), this.length, separator);
|
|
371
|
+
if (ASC_SHRINK_LEVEL < 1) {
|
|
372
|
+
if (isString<T>()) return joinStringArray(changetype<usize>(this), this.length, separator);
|
|
373
|
+
}
|
|
374
|
+
if (isReference<T>()) return joinReferenceArray<T>(changetype<usize>(this), this.length, separator);
|
|
375
|
+
ERROR("unspported element type");
|
|
376
|
+
return <string>unreachable();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
reverse(): StaticArray<T> {
|
|
380
|
+
REVERSE<T>(changetype<usize>(this), this.length);
|
|
381
|
+
return this;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
toString(): string {
|
|
385
|
+
return this.join();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// RT integration
|
|
389
|
+
|
|
390
|
+
@unsafe private __visit(cookie: u32): void {
|
|
391
|
+
if (isManaged<T>()) {
|
|
392
|
+
let cur = changetype<usize>(this);
|
|
393
|
+
let end = cur + changetype<OBJECT>(changetype<usize>(this) - TOTAL_OVERHEAD).rtSize;
|
|
394
|
+
while (cur < end) {
|
|
395
|
+
let val = load<usize>(cur);
|
|
396
|
+
if (val) __visit(val, cookie);
|
|
397
|
+
cur += sizeof<usize>();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|