diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 451817ef12..cd6bf414ff 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -1,7 +1,7 @@
name: Publish
on:
schedule:
- - cron: '40 3 * * *'
+ - cron: '0 0 * * *'
jobs:
publish:
name: "Publish packages"
@@ -30,6 +30,8 @@ jobs:
npm run build
- name: Test distribution files
run: npm test
+ - name: Reconfigure for release
+ run: npm run release
- name: Set up version
run: |
VERSION=$(node -e "console.log(require('./package.json').version)")
@@ -50,7 +52,7 @@ jobs:
git commit --allow-empty -m "Release v$VERSION"
fi
echo ::set-env name=VERSION::$VERSION
- cd ./lib/loader
+ cd lib/loader
npm version $VERSION --no-git-tag-version --force
cd ../..
- name: Create tag and push distribution files
@@ -59,17 +61,24 @@ jobs:
git push origin release
git push origin v$VERSION
- name: Publish to npm
+ env:
+ NPM_REGISTRY: "registry.npmjs.org"
+ NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
- echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
+ npm config set "//${NPM_REGISTRY}/:_authToken=${NPM_AUTH_TOKEN}"
npm publish --tag $CHANNEL
- cd ./lib/loader
+ cd lib/loader
npm publish --tag $CHANNEL --access public
cd ../..
- name: Publish to gpr
+ env:
+ NPM_REGISTRY: "npm.pkg.github.com"
+ NPM_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
- echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
+ npm config set "//${NPM_REGISTRY}/:_authToken=${NPM_AUTH_TOKEN}""
sed -i 's/"assemblyscript"/"@assemblyscript\/assemblyscript"/' package.json
- npm publish --tag $CHANNEL --access public
- cd ./lib/loader
- npm publish --tag $CHANNEL --access public
+ sed -i 's/"assemblyscript"/"@assemblyscript\/assemblyscript"/' package-lock.json
+ npm publish --registry=https://${NPM_REGISTRY}
+ cd lib/loader
+ npm publish --registry=https://${NPM_REGISTRY}
cd ../..
diff --git a/README.md b/README.md
index 1a434d0ffd..68cf777f6a 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 AssemblyScript
=================
-[](https://github.com/AssemblyScript/assemblyscript/actions)
+[](https://github.com/AssemblyScript/assemblyscript/actions) [](https://www.npmjs.com/package/assemblyscript) [](https://www.npmjs.com/package/assemblyscript)
**AssemblyScript** compiles a strict subset of [TypeScript](http://www.typescriptlang.org) (basically JavaScript with types) to [WebAssembly](http://webassembly.org) using [Binaryen](https://github.com/WebAssembly/binaryen). It generates lean and mean WebAssembly modules while being just an `npm install` away.
@@ -45,50 +45,17 @@ Motivation
> I do think [compiling TypeScript into WASM] is tremendously useful. It allows JavaScript developers to create WASM modules without having to learn C. – Colin Eberhardt, [Exploring different approaches to building WebAssembly modules](http://blog.scottlogic.com/2017/10/17/wasm-mandelbrot.html) (Oct 17, 2017)
-Instructions
-------------
+Further resources
+-----------------
-For general usage instructions, please refer to the [documentation](https://docs.assemblyscript.org) instead. The following sets up a *development environment* of the compiler, for example if you plan to make a pull request:
+* [Documentation](https://docs.assemblyscript.org)
+ Introduction, quick start, examples and general usage instructions.
-```
-$> git clone https://github.com/AssemblyScript/assemblyscript.git
-$> cd assemblyscript
-$> npm install
-$> npm link
-$> npm run clean
-```
+* [Development instructions](https://docs.assemblyscript.org/details/development)
+ How to set up a development environment (to submit a pull request).
-Note that a fresh clone of the compiler will use the distribution files in `dist/`, but after an `npm run clean` it will run [the sources](./src) directly through ts-node, which is useful in development. This condition can also be checked by running `asc -v` (it is running the sources if it states `-dev`). Also please see our [contribution guidelines](./CONTRIBUTING.md) before making your first pull request.
+* [Project governance](https://github.com/AssemblyScript/meta)
+ Meta information related to the AssemblyScript project.
-Building
---------
-
-To build an UMD bundle to `dist/assemblyscript.js` (depends on [binaryen.js](https://github.com/AssemblyScript/binaryen.js)), including a browser version of asc to `dist/asc.js` (depends on assemblyscript.js):
-
-```
-$> npm run build
-```
-
-Cleaning the distribution files (again):
-
-```
-$> npm run clean
-```
-
-Linting potential changes:
-
-```
-$> npm run check
-```
-
-Running the [tests](./tests):
-
-```
-$> npm test
-```
-
-Running everything in order (lint, clean, test, build, test):
-
-```
-$> npm run all
-```
+* [Media files](./media)
+ Various media files, like logos etc.
diff --git a/dist/asc.js b/dist/asc.js
deleted file mode 100644
index dbafc8e15c..0000000000
--- a/dist/asc.js
+++ /dev/null
@@ -1,2 +0,0 @@
-!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(function(){try{return require("assemblyscript")}catch(n){}}()):"function"==typeof define&&define.amd?define(["assemblyscript"],e):"object"==typeof exports?exports.asc=e(function(){try{return require("assemblyscript")}catch(n){}}()):n.asc=e(n.assemblyscript)}("undefined"!=typeof self?self:this,(function(__WEBPACK_EXTERNAL_MODULE__10__){return function(n){var e={};function t(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return n[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:r})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var i in n)t.d(r,i,function(e){return n[e]}.bind(null,i));return r},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=4)}([function(n,e,t){var r,i;e.nextTick=function(n){var e=Array.prototype.slice.call(arguments);e.shift(),setTimeout((function(){n.apply(null,e)}),0)},e.platform=e.arch=e.execPath=e.title="browser",e.pid=1,e.browser=!0,e.env={},e.argv=[],e.binding=function(n){throw new Error("No such module. (Possibly not yet loaded)")},i="/",e.cwd=function(){return i},e.chdir=function(n){r||(r=t(1)),i=r.resolve(n,i)},e.exit=e.kill=e.umask=e.dlopen=e.uptime=e.memoryUsage=e.uvCounters=function(){},e.features={}},function(n,e,t){(function(n){function t(n,e){for(var t=0,r=n.length-1;r>=0;r--){var i=n[r];"."===i?n.splice(r,1):".."===i?(n.splice(r,1),t++):t&&(n.splice(r,1),t--)}if(e)for(;t--;t)n.unshift("..");return n}function r(n,e){if(n.filter)return n.filter(e);for(var t=[],r=0;r=-1&&!i;o--){var a=o>=0?arguments[o]:n.cwd();if("string"!=typeof a)throw new TypeError("Arguments to path.resolve must be strings");a&&(e=a+"/"+e,i="/"===a.charAt(0))}return(i?"/":"")+(e=t(r(e.split("/"),(function(n){return!!n})),!i).join("/"))||"."},e.normalize=function(n){var o=e.isAbsolute(n),a="/"===i(n,-1);return(n=t(r(n.split("/"),(function(n){return!!n})),!o).join("/"))||o||(n="."),n&&a&&(n+="/"),(o?"/":"")+n},e.isAbsolute=function(n){return"/"===n.charAt(0)},e.join=function(){var n=Array.prototype.slice.call(arguments,0);return e.normalize(r(n,(function(n,e){if("string"!=typeof n)throw new TypeError("Arguments to path.join must be strings");return n})).join("/"))},e.relative=function(n,t){function r(n){for(var e=0;e=0&&""===n[t];t--);return e>t?[]:n.slice(e,t-e+1)}n=e.resolve(n).substr(1),t=e.resolve(t).substr(1);for(var i=r(n.split("/")),o=r(t.split("/")),a=Math.min(i.length,o.length),s=a,l=0;l=1;--o)if(47===(e=n.charCodeAt(o))){if(!i){r=o;break}}else i=!1;return-1===r?t?"/":".":t&&1===r?"/":n.slice(0,r)},e.basename=function(n,e){var t=function(n){"string"!=typeof n&&(n+="");var e,t=0,r=-1,i=!0;for(e=n.length-1;e>=0;--e)if(47===n.charCodeAt(e)){if(!i){t=e+1;break}}else-1===r&&(i=!1,r=e+1);return-1===r?"":n.slice(t,r)}(n);return e&&t.substr(-1*e.length)===e&&(t=t.substr(0,t.length-e.length)),t},e.extname=function(n){"string"!=typeof n&&(n+="");for(var e=-1,t=0,r=-1,i=!0,o=0,a=n.length-1;a>=0;--a){var s=n.charCodeAt(a);if(47!==s)-1===r&&(i=!1,r=a+1),46===s?-1===e?e=a:1!==o&&(o=1):-1!==e&&(o=-1);else if(!i){t=a+1;break}}return-1===e||-1===r||0===o||1===o&&e===r-1&&e===t+1?"":n.slice(e,r)};var i="b"==="ab".substr(-1)?function(n,e,t){return n.substr(e,t)}:function(n,e,t){return e<0&&(e=n.length+e),n.substr(e,t)}}).call(this,t(0))},function(n,e){var t;t=function(){return this}();try{t=t||new Function("return this")()}catch(n){"object"==typeof window&&(t=window)}n.exports=t},function(n,e){},function(n,e,t){n.exports=t(5)},function(module,exports,__webpack_require__){"use strict";(function(process,global){process.browser&&(process.cwd=function(){return"."});const fs=__webpack_require__(3),path=__webpack_require__(1),utf8=__webpack_require__(6),colorsUtil=__webpack_require__(7),optionsUtil=__webpack_require__(8),mkdirp=__webpack_require__(9),EOL="win32"===process.platform?"\r\n":"\n",SEP="win32"===process.platform?"\\":"/";process.removeAllListeners&&process.removeAllListeners("uncaughtException");var assemblyscript,isDev=!1;function checkDiagnostics(n,e){for(var t,r=!1;null!=(t=assemblyscript.nextDiagnostic(n));)e&&e.write(assemblyscript.formatDiagnostic(t,e.isTTY,!0)+EOL+EOL),assemblyscript.isError(t)&&(r=!0);return r}function createStats(){return{readTime:0,readCount:0,writeTime:0,writeCount:0,parseTime:0,parseCount:0,compileTime:0,compileCount:0,emitTime:0,emitCount:0,validateTime:0,validateCount:0,optimizeTime:0,optimizeCount:0}}function measure(n){const e=process.hrtime();n();const t=process.hrtime(e);return 1e9*t[0]+t[1]}function formatTime(n){return n?(n/1e6).toFixed(3)+" ms":"N/A"}function printStats(n,e){function t(n,e){return formatTime(n)}(e||process.stdout).write(["I/O Read : "+t(n.readTime,n.readCount),"I/O Write : "+t(n.writeTime,n.writeCount),"Parse : "+t(n.parseTime,n.parseCount),"Compile : "+t(n.compileTime,n.compileCount),"Emit : "+t(n.emitTime,n.emitCount),"Validate : "+t(n.validateTime,n.validateCount),"Optimize : "+t(n.optimizeTime,n.optimizeCount)].join(EOL)+EOL)}function printRTTI(n,e){e||(e=process.stderr),e.write("# Runtime type information (RTTI)\n"),e.write(assemblyscript.buildRTTI(n))}(()=>{try{assemblyscript=__webpack_require__(10)}catch(e){try{__webpack_require__(!function(){var n=new Error("Cannot find module 'ts-node'");throw n.code="MODULE_NOT_FOUND",n}()).register({project:path.join(".","..","src","tsconfig.json")}),__webpack_require__(!function(){var n=new Error("Cannot find module '../src/glue/js'");throw n.code="MODULE_NOT_FOUND",n}()),assemblyscript=__webpack_require__(!function(){var n=new Error("Cannot find module '../src'");throw n.code="MODULE_NOT_FOUND",n}()),isDev=!0}catch(e_ts){try{assemblyscript=eval("require('./assemblyscript')")}catch(n){throw n.message=e_ts.stack+"\n---\n"+n.stack,n}}}})(),exports.isBundle=!0,exports.isDev=isDev,exports.version=exports.isBundle?"0.7.0":__webpack_require__(!function(){var n=new Error("Cannot find module '../package.json'");throw n.code="MODULE_NOT_FOUND",n}()).version,exports.options=__webpack_require__(11),exports.sourceMapRoot="assemblyscript:///",exports.libraryPrefix=assemblyscript.LIBRARY_PREFIX,exports.defaultOptimizeLevel=3,exports.defaultShrinkLevel=1,exports.libraryFiles=exports.isBundle?Object({array:'/// \n\nimport { BLOCK_MAXSIZE } from "./rt/common";\nimport { COMPARATOR, SORT } from "./util/sort";\nimport { ArrayBufferView } from "./arraybuffer";\nimport { joinBooleanArray, joinIntegerArray, joinFloatArray, joinStringArray, joinReferenceArray } from "./util/string";\nimport { idof, isArray as builtin_isArray } from "./builtins";\nimport { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_EMPTYARRAY, E_HOLEYARRAY } from "./util/error";\n\n/** Ensures that the given array has _at least_ the specified backing size. */\nfunction ensureSize(array: usize, minSize: usize, alignLog2: u32): void {\n var oldCapacity = changetype(array).byteLength;\n if (minSize > oldCapacity >>> alignLog2) {\n if (minSize > BLOCK_MAXSIZE >>> alignLog2) throw new RangeError(E_INVALIDLENGTH);\n let oldData = changetype(changetype(array).buffer);\n let newCapacity = minSize << alignLog2;\n let newData = __realloc(oldData, newCapacity);\n memory.fill(newData + oldCapacity, 0, newCapacity - oldCapacity);\n if (newData !== oldData) { // oldData has been free\'d\n store(array, __retain(newData), offsetof("buffer"));\n store(array, newData, offsetof("dataStart"));\n }\n store(array, newCapacity, offsetof("byteLength"));\n }\n}\n\nexport class Array extends ArrayBufferView {\n [key: number]: T;\n\n // Implementing ArrayBufferView isn\'t strictly necessary here but is done to allow glue code\n // to work with typed and normal arrays interchangeably. Technically, normal arrays do not need\n // `dataStart` (equals `data`) and `dataLength` (equals computed `data.byteLength`).\n\n // Also note that Array with non-nullable T must guard against uninitialized null values\n // whenever an element is accessed. Otherwise, the compiler wouldn\'t be able to guarantee\n // type-safety anymore. For lack of a better word, such an array is "holey".\n\n private length_: i32;\n\n static isArray(value: U): bool {\n return builtin_isArray(value) && value !== null;\n }\n\n static create(capacity: i32 = 0): Array {\n WARNING("\'Array.create\' is deprecated. Use \'new Array\' instead, making sure initial elements are initialized.");\n var array = new Array(capacity);\n array.length = 0;\n return array;\n }\n\n constructor(length: i32 = 0) {\n super(length, alignof());\n this.length_ = length;\n }\n\n get length(): i32 {\n return this.length_;\n }\n\n set length(newLength: i32) {\n var oldLength = this.length_;\n if (isManaged()) {\n if (oldLength > newLength) { // release no longer used refs\n let dataStart = this.dataStart;\n let cur = dataStart + (newLength << alignof());\n let end = dataStart + (oldLength << alignof());\n do __release(load(cur));\n while ((cur += sizeof()) < end);\n } else {\n ensureSize(changetype(this), newLength, alignof());\n }\n } else {\n ensureSize(changetype(this), newLength, alignof());\n }\n this.length_ = newLength;\n }\n\n every(fn: (value: T, index: i32, array: Array) => bool): bool {\n for (let index = 0, length = this.length_; index < min(length, this.length_); ++index) {\n if (!fn(load(this.dataStart + (index << alignof())), index, this)) return false;\n }\n return true;\n }\n\n findIndex(predicate: (value: T, index: i32, array: Array) => bool): i32 {\n for (let index = 0, length = this.length_; index < min(length, this.length_); ++index) {\n if (predicate(load(this.dataStart + (index << alignof())), index, this)) return index;\n }\n return -1;\n }\n\n @operator("[]") private __get(index: i32): T {\n if (index >= this.length_) throw new RangeError(E_INDEXOUTOFRANGE);\n var value = this.__unchecked_get(index);\n if (isReference()) {\n if (!isNullable()) {\n if (!changetype(value)) throw new Error(E_HOLEYARRAY);\n }\n }\n return value;\n }\n\n @unsafe @operator("{}") private __unchecked_get(index: i32): T {\n return load(this.dataStart + (index << alignof()));\n }\n\n @operator("[]=") private __set(index: i32, value: T): void {\n ensureSize(changetype(this), index + 1, alignof());\n this.__unchecked_set(index, value);\n if (index >= this.length_) this.length_ = index + 1;\n }\n\n @unsafe @operator("{}=") private __unchecked_set(index: i32, value: T): void {\n if (isManaged()) {\n let offset = this.dataStart + (index << alignof());\n let oldRef = load(offset);\n if (changetype(value) != oldRef) {\n store(offset, __retain(changetype(value)));\n __release(oldRef);\n }\n } else {\n store(this.dataStart + (index << alignof()), value);\n }\n }\n\n fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): this {\n var dataStart = this.dataStart;\n var length = this.length_;\n start = start < 0 ? max(length + start, 0) : min(start, length);\n end = end < 0 ? max(length + end, 0) : min(end, length);\n if (isManaged()) {\n for (; start < end; ++start) {\n let oldRef: usize = load(dataStart + (start << alignof()));\n if (changetype(value) != oldRef) {\n store(dataStart + (start << alignof()), __retain(changetype(value)));\n __release(oldRef);\n }\n }\n } else if (sizeof() == 1) {\n if (start < end) {\n memory.fill(\n dataStart + start,\n u8(value),\n (end - start)\n );\n }\n } else {\n for (; start < end; ++start) {\n store(dataStart + (start << alignof()), value);\n }\n }\n return this;\n }\n\n includes(value: T, fromIndex: i32 = 0): bool {\n if (isFloat()) {\n let length = this.length_;\n if (length == 0 || fromIndex >= length) return false;\n if (fromIndex < 0) fromIndex = max(length + fromIndex, 0);\n let dataStart = this.dataStart;\n while (fromIndex < length) {\n let elem = load(dataStart + (fromIndex << alignof()));\n // @ts-ignore\n if (elem == value || isNaN(elem) & isNaN(value)) return true;\n ++fromIndex;\n }\n return false;\n } else {\n return this.indexOf(value, fromIndex) >= 0;\n }\n }\n\n indexOf(value: T, fromIndex: i32 = 0): i32 {\n var length = this.length_;\n if (length == 0 || fromIndex >= length) return -1;\n if (fromIndex < 0) fromIndex = max(length + fromIndex, 0);\n var dataStart = this.dataStart;\n while (fromIndex < length) {\n if (load(dataStart + (fromIndex << alignof())) == value) return fromIndex;\n ++fromIndex;\n }\n return -1;\n }\n\n lastIndexOf(value: T, fromIndex: i32 = this.length_): i32 {\n var length = this.length_;\n if (length == 0) return -1;\n if (fromIndex < 0) fromIndex = length + fromIndex;\n else if (fromIndex >= length) fromIndex = length - 1;\n var dataStart = this.dataStart;\n while (fromIndex >= 0) {\n if (load(dataStart + (fromIndex << alignof())) == value) return fromIndex;\n --fromIndex;\n }\n return -1;\n }\n\n push(value: T): i32 {\n var length = this.length_;\n var newLength = length + 1;\n ensureSize(changetype(this), newLength, alignof());\n if (isManaged()) {\n store(this.dataStart + (length << alignof()), __retain(changetype(value)));\n } else {\n store(this.dataStart + (length << alignof()), value);\n }\n this.length_ = newLength;\n return newLength;\n }\n\n concat(other: Array): Array {\n var thisLen = this.length_;\n var otherLen = select(0, other.length_, other === null);\n var outLen = thisLen + otherLen;\n if (outLen > BLOCK_MAXSIZE >>> alignof()) throw new Error(E_INVALIDLENGTH);\n var out = changetype>(__allocArray(outLen, alignof(), idof>())); // retains\n var outStart = out.dataStart;\n var thisSize = thisLen << alignof();\n if (isManaged()) {\n let thisStart = this.dataStart;\n for (let offset: usize = 0; offset < thisSize; offset += sizeof()) {\n let ref = load(thisStart + offset);\n store(outStart + offset, __retain(ref));\n }\n outStart += thisSize;\n let otherStart = other.dataStart;\n let otherSize = otherLen << alignof();\n for (let offset: usize = 0; offset < otherSize; offset += sizeof()) {\n let ref = load(otherStart + offset);\n store(outStart + offset, __retain(ref));\n }\n } else {\n memory.copy(outStart, this.dataStart, thisSize);\n memory.copy(outStart + thisSize, other.dataStart, otherLen << alignof());\n }\n return out;\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): this {\n var dataStart = this.dataStart;\n var len = this.length_;\n\n end = min(end, len);\n var to = target < 0 ? max(len + target, 0) : min(target, len);\n var from = start < 0 ? max(len + start, 0) : min(start, len);\n var last = end < 0 ? max(len + end, 0) : min(end, len);\n var count = min(last - from, len - to);\n\n if (isManaged()) {\n if (from < to && to < (from + count)) { // right to left\n from += count - 1;\n to += count - 1;\n while (count) {\n let oldRef: usize = load(dataStart + (to << alignof()));\n let newRef: usize = load(dataStart + (from << alignof()));\n if (newRef != oldRef) {\n store(dataStart + (to << alignof()), __retain(newRef));\n __release(oldRef);\n }\n --from, --to, --count;\n }\n } else { // left to right\n while (count) {\n let oldRef: usize = load(dataStart + (to << alignof()));\n let newRef: usize = load(dataStart + (from << alignof()));\n if (newRef != oldRef) {\n store(dataStart + (to << alignof()), __retain(newRef));\n __release(oldRef);\n }\n ++from, ++to, --count;\n }\n }\n } else {\n memory.copy( // is memmove\n dataStart + (to << alignof()),\n dataStart + (from << alignof()),\n count << alignof()\n );\n }\n return this;\n }\n\n pop(): T {\n var length = this.length_;\n if (length < 1) throw new RangeError(E_EMPTYARRAY);\n var element = load(this.dataStart + ((--length) << alignof()));\n this.length_ = length;\n return element; // no need to retain -> is moved\n }\n\n forEach(fn: (value: T, index: i32, array: Array) => void): void {\n for (let index = 0, length = this.length_; index < min(length, this.length_); ++index) {\n fn(load(this.dataStart + (index << alignof())), index, this);\n }\n }\n\n map(fn: (value: T, index: i32, array: Array) => U): Array {\n var length = this.length_;\n var out = changetype>(__allocArray(length, alignof(), idof>())); // retains\n var outStart = out.dataStart;\n for (let index = 0; index < min(length, this.length_); ++index) {\n let result = fn(load(this.dataStart + (index << alignof())), index, this); // retains\n if (isManaged()) {\n store(outStart + (index << alignof()), __retain(changetype(result)));\n } else {\n store(outStart + (index << alignof()), result);\n }\n // releases result\n }\n return out;\n }\n\n filter(fn: (value: T, index: i32, array: Array) => bool): Array {\n var result = changetype>(__allocArray(0, alignof(), idof>())); // retains\n for (let index = 0, length = this.length_; index < min(length, this.length_); ++index) {\n let value = load(this.dataStart + (index << alignof()));\n if (fn(value, index, this)) result.push(value);\n }\n return result;\n }\n\n reduce(\n fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var accum = initialValue;\n for (let index = 0, length = this.length_; index < min(length, this.length_); ++index) {\n accum = fn(accum, load(this.dataStart + (index << alignof())), index, this);\n }\n return accum;\n }\n\n reduceRight(\n fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var accum = initialValue;\n for (let index = this.length_ - 1; index >= 0; --index) {\n accum = fn(accum, load(this.dataStart + (index << alignof())), index, this);\n }\n return accum;\n }\n\n shift(): T {\n var length = this.length_;\n if (length < 1) throw new RangeError(E_EMPTYARRAY);\n var base = this.dataStart;\n var element = load(base);\n var lastIndex = length - 1;\n memory.copy(\n base,\n base + sizeof(),\n lastIndex << alignof()\n );\n store(base + (lastIndex << alignof()),\n // @ts-ignore: cast\n null\n );\n this.length_ = lastIndex;\n return element; // no need to retain -> is moved\n }\n\n some(fn: (value: T, index: i32, array: Array) => bool): bool {\n for (let index = 0, length = this.length_; index < min(length, this.length_); ++index) {\n if (fn(load(this.dataStart + (index << alignof())), index, this)) return true;\n }\n return false;\n }\n\n unshift(value: T): i32 {\n var newLength = this.length_ + 1;\n ensureSize(changetype(this), newLength, alignof());\n var dataStart = this.dataStart;\n memory.copy(\n dataStart + sizeof(),\n dataStart,\n (newLength - 1) << alignof()\n );\n if (isManaged()) {\n store(dataStart, __retain(changetype(value)));\n } else {\n store(dataStart, value);\n }\n this.length_ = newLength;\n return newLength;\n }\n\n slice(start: i32 = 0, end: i32 = i32.MAX_VALUE): Array {\n var length = this.length_;\n start = start < 0 ? max(start + length, 0) : min(start, length);\n end = end < 0 ? max(end + length, 0) : min(end , length);\n length = max(end - start, 0);\n var slice = changetype>(__allocArray(length, alignof(), idof>())); // retains\n var sliceBase = slice.dataStart;\n var thisBase = this.dataStart + (start << alignof());\n if (isManaged()) {\n let off = 0;\n let end = length << alignof();\n while (off < end) {\n let ref = load(thisBase + off);\n store(sliceBase + off, __retain(ref));\n off += sizeof();\n }\n } else {\n memory.copy(sliceBase, thisBase, length << alignof());\n }\n return slice;\n }\n\n splice(start: i32, deleteCount: i32 = i32.MAX_VALUE): Array {\n var length = this.length_;\n start = start < 0 ? max(length + start, 0) : min(start, length);\n deleteCount = max(min(deleteCount, length - start), 0);\n var result = changetype>(__allocArray(deleteCount, alignof(), idof>())); // retains\n var resultStart = result.dataStart;\n var thisStart = this.dataStart;\n var thisBase = thisStart + (start << alignof());\n // no need to retain -> is moved\n memory.copy(\n resultStart,\n thisBase,\n deleteCount << alignof()\n );\n var offset = start + deleteCount;\n if (length != offset) {\n memory.copy(\n thisBase,\n thisStart + (offset << alignof()),\n (length - offset) << alignof()\n );\n }\n this.length_ = length - deleteCount;\n return result;\n }\n\n reverse(): Array {\n var length = this.length_;\n if (length) {\n let front = this.dataStart;\n let back = this.dataStart + ((length - 1) << alignof());\n while (front < back) {\n let temp = load(front);\n store(front, load(back));\n store(back, temp);\n front += sizeof();\n back -= sizeof();\n }\n }\n return this;\n }\n\n sort(comparator: (a: T, b: T) => i32 = COMPARATOR()): this {\n var length = this.length_;\n if (length <= 1) return this;\n var base = this.dataStart;\n if (length == 2) {\n let a: T = load(base, sizeof()); // a = arr[1]\n let b: T = load(base); // b = arr[0]\n if (comparator(a, b) < 0) {\n store(base, b, sizeof()); // arr[1] = b;\n store(base, a); // arr[0] = a;\n }\n return this;\n }\n SORT(base, length, comparator);\n return this;\n }\n\n join(separator: string = ","): string {\n var dataStart = this.dataStart;\n var length = this.length_;\n if (isBoolean()) return joinBooleanArray(dataStart, length, separator);\n if (isInteger()) return joinIntegerArray(dataStart, length, separator);\n if (isFloat