From 4f95dce6e2e765d2f13cb4e3c7774e87119c437d Mon Sep 17 00:00:00 2001 From: dcodeIO Date: Fri, 9 Nov 2018 12:28:10 +0100 Subject: [PATCH] Do not emit debug info by default This basically flips the --noDebug flag to become a --debug flag, so some optimizations, like inlining, aren't skipped by default, which might be unexpected. --- bin/asinit | 4 +- cli/asc.js | 2 +- cli/asc.json | 8 +- dist/asc.js | 2 +- dist/asc.js.map | 2 +- examples/game-of-life/package.json | 4 +- examples/i64-polyfill/package.json | 2 +- examples/mandelbrot/package.json | 4 +- examples/n-body/package.json | 6 +- examples/pson/package.json | 2 +- lib/parse/package.json | 2 +- package-lock.json | 6 +- package.json | 2 +- tests/compiler.js | 5 +- tests/compiler/abi.optimized.wat | 23 +- tests/compiler/binary.optimized.wat | 103 +- tests/compiler/call-inferred.optimized.wat | 65 +- tests/compiler/call-optional.optimized.wat | 82 +- .../compiler/class-overloading.optimized.wat | 15 +- tests/compiler/class.optimized.wat | 31 +- tests/compiler/enum.optimized.wat | 10 +- tests/compiler/exports.optimized.wat | 49 +- tests/compiler/function-types.optimized.wat | 100 +- tests/compiler/function.optimized.wat | 82 +- tests/compiler/getter-call.optimized.wat | 24 +- tests/compiler/getter-setter.optimized.wat | 21 +- tests/compiler/if.optimized.wat | 71 +- tests/compiler/import.optimized.wat | 30 +- tests/compiler/infer-type.optimized.wat | 35 +- .../compiler/inlining-recursive.optimized.wat | 7 +- tests/compiler/inlining.optimized.wat | 11 - tests/compiler/instanceof.optimized.wat | 39 +- tests/compiler/main.optimized.wat | 9 +- tests/compiler/mandelbrot.optimized.wat | 69 +- tests/compiler/many-locals.optimized.wat | 37 +- .../named-import-default.optimized.wat | 7 +- tests/compiler/namespace.optimized.wat | 19 +- .../new-without-allocator.optimized.wat | 10 +- tests/compiler/object-literal.optimized.wat | 72 +- tests/compiler/recursive.optimized.wat | 5 - tests/compiler/reexport.optimized.wat | 11 - tests/compiler/rereexport.optimized.wat | 18 +- tests/compiler/retain-i32.optimized.wat | 43 +- tests/compiler/scoped.optimized.wat | 9 +- tests/compiler/static-this.optimized.wat | 8 +- .../std/allocator_arena.optimized.wat | 17 +- tests/compiler/std/array-access.optimized.wat | 142 +- .../compiler/std/array-literal.optimized.wat | 391 ++- tests/compiler/std/array.optimized.wat | 2718 ++++++++++------- tests/compiler/std/arraybuffer.optimized.wat | 110 +- tests/compiler/std/constructor.optimized.wat | 120 +- tests/compiler/std/gc-array.optimized.wat | 305 +- tests/compiler/std/gc-basics.optimized.wat | 200 +- .../compiler/std/gc-integration.optimized.wat | 28 +- tests/compiler/std/gc-object.optimized.wat | 197 +- tests/compiler/std/hash.optimized.wat | 28 +- tests/compiler/std/libm.optimized.wat | 181 +- tests/compiler/std/map.optimized.wat | 1304 ++++---- tests/compiler/std/math.optimized.wat | 802 +++-- tests/compiler/std/mod.optimized.wat | 39 +- tests/compiler/std/new.optimized.wat | 11 +- .../std/operator-overloading.optimized.wat | 708 ++--- tests/compiler/std/pointer.optimized.wat | 90 +- tests/compiler/std/polyfills.optimized.wat | 117 +- tests/compiler/std/set.optimized.wat | 1070 +++---- tests/compiler/std/static-array.optimized.wat | 329 +- tests/compiler/std/string-utf8.optimized.wat | 83 +- tests/compiler/std/string.optimized.wat | 1320 +++++--- tests/compiler/std/symbol.optimized.wat | 322 +- tests/compiler/std/typedarray.optimized.wat | 399 ++- tests/compiler/switch.optimized.wat | 231 +- tests/compiler/void.optimized.wat | 13 +- 72 files changed, 6244 insertions(+), 6197 deletions(-) diff --git a/bin/asinit b/bin/asinit index c4e322c8..c0d77e49 100644 --- a/bin/asinit +++ b/bin/asinit @@ -206,8 +206,8 @@ function ensureGitignore() { function ensurePackageJson() { console.log("- Making sure that 'package.json' contains the build commands...") const entryPath = path.relative(projectDir, entryFile).replace(/\\/g, "/"); - const buildUntouched = "asc " + entryPath + " -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate"; - const buildOptimized = "asc " + entryPath + " -b build/optimized.wasm -t build/optimized.wat --sourceMap --validate --optimize --noDebug"; + const buildUntouched = "asc " + entryPath + " -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug"; + const buildOptimized = "asc " + entryPath + " -b build/optimized.wasm -t build/optimized.wat --sourceMap --validate --optimize"; const buildAll = "npm run asbuild:untouched && npm run asbuild:optimized"; if (!fs.existsSync(packageFile)) { fs.writeFileSync(packageFile, JSON.stringify({ diff --git a/cli/asc.js b/cli/asc.js index cb32a736..851ec2e9 100644 --- a/cli/asc.js +++ b/cli/asc.js @@ -505,7 +505,7 @@ exports.main = function main(argv, options, callback) { module.setOptimizeLevel(optimizeLevel); module.setShrinkLevel(shrinkLevel); - module.setDebugInfo(!args.noDebug); + module.setDebugInfo(args.debug); var runPasses = []; if (args.runPasses) { diff --git a/cli/asc.json b/cli/asc.json index e92b2543..7ee80c77 100644 --- a/cli/asc.json +++ b/cli/asc.json @@ -81,13 +81,13 @@ ], "type": "s" }, - "noTreeShaking": { - "description": "Disables compiler-level tree-shaking, compiling everything.", + "debug": { + "description": "Enables debug information in emitted binaries.", "type": "b", "default": false }, - "noDebug": { - "description": "Disables maintaining of debug information in binaries.", + "noTreeShaking": { + "description": "Disables compiler-level tree-shaking, compiling everything.", "type": "b", "default": false }, diff --git a/dist/asc.js b/dist/asc.js index ca44e6ec..27653761 100644 --- a/dist/asc.js +++ b/dist/asc.js @@ -1,2 +1,2 @@ -!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(function(){try{return require("assemblyscript")}catch(e){}}()):"function"==typeof define&&define.amd?define(["assemblyscript"],n):"object"==typeof exports?exports.asc=n(function(){try{return require("assemblyscript")}catch(e){}}()):e.asc=n(e.assemblyscript)}("undefined"!=typeof self?self:this,function(__WEBPACK_EXTERNAL_MODULE__10__){return function(e){var n={};function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)t.d(r,i,function(n){return e[n]}.bind(null,i));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=4)}([function(e,n,t){n.nextTick=function(e){setTimeout(e,0)},n.platform=n.arch=n.execPath=n.title="browser",n.pid=1,n.browser=!0,n.env={},n.argv=[],n.binding=function(e){throw new Error("No such module. (Possibly not yet loaded)")},function(){var e,r="/";n.cwd=function(){return r},n.chdir=function(n){e||(e=t(1)),r=e.resolve(n,r)}}(),n.exit=n.kill=n.umask=n.dlopen=n.uptime=n.memoryUsage=n.uvCounters=function(){},n.features={}},function(e,n,t){(function(e){function t(e,n){for(var t=0,r=e.length-1;r>=0;r--){var i=e[r];"."===i?e.splice(r,1):".."===i?(e.splice(r,1),t++):t&&(e.splice(r,1),t--)}if(n)for(;t--;t)e.unshift("..");return e}var r=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,i=function(e){return r.exec(e).slice(1)};function s(e,n){if(e.filter)return e.filter(n);for(var t=[],r=0;r=-1&&!r;i--){var a=i>=0?arguments[i]:e.cwd();if("string"!=typeof a)throw new TypeError("Arguments to path.resolve must be strings");a&&(n=a+"/"+n,r="/"===a.charAt(0))}return n=t(s(n.split("/"),function(e){return!!e}),!r).join("/"),(r?"/":"")+n||"."},n.normalize=function(e){var r=n.isAbsolute(e),i="/"===a(e,-1);return(e=t(s(e.split("/"),function(e){return!!e}),!r).join("/"))||r||(e="."),e&&i&&(e+="/"),(r?"/":"")+e},n.isAbsolute=function(e){return"/"===e.charAt(0)},n.join=function(){var e=Array.prototype.slice.call(arguments,0);return n.normalize(s(e,function(e,n){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},n.relative=function(e,t){function r(e){for(var n=0;n=0&&""===e[t];t--);return n>t?[]:e.slice(n,t-n+1)}e=n.resolve(e).substr(1),t=n.resolve(t).substr(1);for(var i=r(e.split("/")),s=r(t.split("/")),a=Math.min(i.length,s.length),o=a,l=0;l{try{assemblyscript=__webpack_require__(10)}catch(e){try{__webpack_require__(!function(){var e=new Error("Cannot find module 'ts-node'");throw e.code="MODULE_NOT_FOUND",e}()).register({project:path.join(".","..","src","tsconfig.json")}),__webpack_require__(!function(){var e=new Error("Cannot find module '../src/glue/js'");throw e.code="MODULE_NOT_FOUND",e}()),assemblyscript=__webpack_require__(!function(){var e=new Error("Cannot find module '../src'");throw e.code="MODULE_NOT_FOUND",e}()),isDev=!0}catch(e_ts){try{assemblyscript=eval("require('./assemblyscript')")}catch(e){throw e.stack=e_ts.stack+"\n---\n"+e.stack,e}}}})(),exports.isBundle=!0,exports.isDev=isDev,exports.version=exports.isBundle?"0.5.0":__webpack_require__(!function(){var e=new Error("Cannot find module '../package.json'");throw e.code="MODULE_NOT_FOUND",e}()).version,exports.options=__webpack_require__(11),exports.sourceMapRoot="assemblyscript:///",exports.libraryPrefix=assemblyscript.LIBRARY_PREFIX,exports.defaultOptimizeLevel=2,exports.defaultShrinkLevel=1,exports.libraryFiles=exports.isBundle?Object({"allocator/arena":'/**\n * Arena Memory Allocator\n *\n * Provides a `memory.reset` function to reset the heap to its initial state. A user has to make\n * sure that there are no more references to cleared memory afterwards. Always aligns to 8 bytes.\n *\n * @module std/assembly/allocator/arena\n *//***/\n\nimport { AL_MASK, MAX_SIZE_32 } from "../internal/allocator";\n\nvar startOffset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;\nvar offset: usize = startOffset;\n\n// Memory allocator interface\n\n@global export function __memory_allocate(size: usize): usize {\n if (size > MAX_SIZE_32) unreachable();\n var ptr = offset;\n var newPtr = (ptr + max(size, 1) + AL_MASK) & ~AL_MASK;\n var pagesBefore = memory.size();\n if (newPtr > pagesBefore << 16) {\n let pagesNeeded = ((newPtr - ptr + 0xffff) & ~0xffff) >>> 16;\n let pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) {\n unreachable(); // out of memory\n }\n }\n }\n offset = newPtr;\n return ptr;\n}\n\n@global export function __memory_free(ptr: usize): void { /* nop */ }\n\n@global export function __memory_reset(): void {\n offset = startOffset;\n}\n',"allocator/buddy":'/**\n * Buddy Memory Allocator.\n * @module std/assembly/allocator/buddy\n *//***/\n\n/*\n Copyright 2018 Evan Wallace\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the "Software"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n*/// see: https://github.com/evanw/buddy-malloc\n\n/*\n * This file implements a buddy memory allocator, which is an allocator that\n * allocates memory within a fixed linear address range. It spans the address\n * range with a binary tree that tracks free space. Both "malloc" and "free"\n * are O(log N) time where N is the maximum possible number of allocations.\n *\n * The "buddy" term comes from how the tree is used. When memory is allocated,\n * nodes in the tree are split recursively until a node of the appropriate size\n * is reached. Every split results in two child nodes, each of which is the\n * buddy of the other. When a node is freed, the node and its buddy can be\n * merged again if the buddy is also free. This makes the memory available\n * for larger allocations again.\n */\n\n/*\n * Every allocation needs an 8-byte header to store the allocation size while\n * staying 8-byte aligned. The address returned by "malloc" is the address\n * right after this header (i.e. the size occupies the 8 bytes before the\n * returned address).\n */\nconst HEADER_SIZE: usize = 8;\n\n/*\n * The minimum allocation size is 16 bytes because we have an 8-byte header and\n * we need to stay 8-byte aligned.\n */\nconst MIN_ALLOC_LOG2: usize = 4;\nconst MIN_ALLOC: usize = 1 << MIN_ALLOC_LOG2;\n\n/*\n * The maximum allocation size is currently set to 2gb. This is the total size\n * of the heap. It\'s technically also the maximum allocation size because the\n * heap could consist of a single allocation of this size. But of course real\n * heaps will have multiple allocations, so the real maximum allocation limit\n * is at most 1gb.\n */\nconst MAX_ALLOC_LOG2: usize = 30; // 31;\nconst MAX_ALLOC: usize = 1 << MAX_ALLOC_LOG2;\n\n/*\n * Allocations are done in powers of two starting from MIN_ALLOC and ending at\n * MAX_ALLOC inclusive. Each allocation size has a bucket that stores the free\n * list for that allocation size.\n *\n * Given a bucket index, the size of the allocations in that bucket can be\n * found with "(size_t)1 << (MAX_ALLOC_LOG2 - bucket)".\n */\nconst BUCKET_COUNT: usize = MAX_ALLOC_LOG2 - MIN_ALLOC_LOG2 + 1;\n\n/*\n * Free lists are stored as circular doubly-linked lists. Every possible\n * allocation size has an associated free list that is threaded through all\n * currently free blocks of that size. That means MIN_ALLOC must be at least\n * "sizeof(list_t)". MIN_ALLOC is currently 16 bytes, so this will be true for\n * both 32-bit and 64-bit.\n */\n@unmanaged\nclass List {\n prev: List;\n next: List;\n static readonly SIZE: usize = 2 * sizeof();\n}\n\n/*\n * Each bucket corresponds to a certain allocation size and stores a free list\n * for that size. The bucket at index 0 corresponds to an allocation size of\n * MAX_ALLOC (i.e. the whole address space).\n */\nvar BUCKETS_START: usize = HEAP_BASE;\nvar BUCKETS_END: usize = BUCKETS_START + BUCKET_COUNT * List.SIZE;\n\nfunction buckets$get(index: usize): List {\n assert(index < BUCKET_COUNT);\n return changetype(BUCKETS_START + index * List.SIZE);\n}\n\n/*\n * We could initialize the allocator by giving it one free block the size of\n * the entire address space. However, this would cause us to instantly reserve\n * half of the entire address space on the first allocation, since the first\n * split would store a free list entry at the start of the right child of the\n * root. Instead, we have the tree start out small and grow the size of the\n * tree as we use more memory. The size of the tree is tracked by this value.\n */\nvar bucket_limit: usize;\n\n/*\n * This array represents a linearized binary tree of bits. Every possible\n * allocation larger than MIN_ALLOC has a node in this tree (and therefore a\n * bit in this array).\n *\n * Given the index for a node, lineraized binary trees allow you to traverse to\n * the parent node or the child nodes just by doing simple arithmetic on the\n * index:\n *\n * - Move to parent: index = (index - 1) / 2;\n * - Move to left child: index = index * 2 + 1;\n * - Move to right child: index = index * 2 + 2;\n * - Move to sibling: index = ((index - 1) ^ 1) + 1;\n *\n * Each node in this tree can be in one of several states:\n *\n * - UNUSED (both children are UNUSED)\n * - SPLIT (one child is UNUSED and the other child isn\'t)\n * - USED (neither children are UNUSED)\n *\n * These states take two bits to store. However, it turns out we have enough\n * information to distinguish between UNUSED and USED from context, so we only\n * need to store SPLIT or not, which only takes a single bit.\n *\n * Note that we don\'t need to store any nodes for allocations of size MIN_ALLOC\n * since we only ever care about parent nodes.\n */\nconst SPLIT_COUNT: usize = (1 << (BUCKET_COUNT - 1)) / 8;\nvar NODE_IS_SPLIT_START: usize = BUCKETS_END;\nvar NODE_IS_SPLIT_END: usize = NODE_IS_SPLIT_START + SPLIT_COUNT * sizeof();\n\nfunction node_is_split$get(index: usize): i32 {\n assert(index < SPLIT_COUNT);\n return load(NODE_IS_SPLIT_START + index);\n}\n\nfunction node_is_split$set(index: usize, state: i32): void {\n assert(index < SPLIT_COUNT);\n store(NODE_IS_SPLIT_START + index, state);\n}\n\n/*\n * This is the starting address of the address range for this allocator. Every\n * returned allocation will be an offset of this pointer from 0 to MAX_ALLOC.\n */\nvar base_ptr: usize;\n\n/*\n * This is the maximum address that has ever been used by the allocator. It\'s\n * used to know when to call "brk" to request more memory from the kernel.\n */\nvar max_ptr: usize;\n\n/*\n * Make sure all addresses before "new_value" are valid and can be used. Memory\n * is allocated in a 2gb address range but that memory is not reserved up\n * front. It\'s only reserved when it\'s needed by calling this function. This\n * will return false if the memory could not be reserved.\n */\nfunction update_max_ptr(new_value: usize): i32 {\n if (new_value > max_ptr) {\n // if (brk(new_value)) {\n // return 0;\n // }\n let oldPages = memory.size();\n let newPages = (((new_value + 0xffff) & ~0xffff) >>> 16);\n assert(newPages > oldPages);\n if (memory.grow(newPages - oldPages) < 0) {\n return 0;\n }\n // max_ptr = new_value;\n max_ptr = newPages << 16;\n }\n return 1;\n}\n\n/*\n * Initialize a list to empty. Because these are circular lists, an "empty"\n * list is an entry where both links point to itself. This makes insertion\n * and removal simpler because they don\'t need any branches.\n */\nfunction list_init(list: List): void {\n list.prev = list;\n list.next = list;\n}\n\n/*\n * Append the provided entry to the end of the list. This assumes the entry\n * isn\'t in a list already because it overwrites the linked list pointers.\n */\nfunction list_push(list: List, entry: List): void {\n var prev = list.prev;\n entry.prev = prev;\n entry.next = list;\n prev.next = entry;\n list.prev = entry;\n}\n\n/*\n * Remove the provided entry from whichever list it\'s currently in. This\n * assumes that the entry is in a list. You don\'t need to provide the list\n * because the lists are circular, so the list\'s pointers will automatically\n * be updated if the first or last entries are removed.\n */\nfunction list_remove(entry: List): void {\n var prev = entry.prev;\n var next = entry.next;\n prev.next = next;\n next.prev = prev;\n}\n\n/*\n * Remove and return the first entry in the list or NULL if the list is empty.\n */\nfunction list_pop(list: List): List | null {\n var back = list.prev;\n if (back == list) return null;\n list_remove(back);\n return back;\n}\n\n/*\n * This maps from the index of a node to the address of memory that node\n * represents. The bucket can be derived from the index using a loop but is\n * required to be provided here since having them means we can avoid the loop\n * and have this function return in constant time.\n */\nfunction ptr_for_node(index: usize, bucket: usize): usize {\n return base_ptr + ((index - (1 << bucket) + 1) << (MAX_ALLOC_LOG2 - bucket));\n}\n\n/*\n * This maps from an address of memory to the node that represents that\n * address. There are often many nodes that all map to the same address, so\n * the bucket is needed to uniquely identify a node.\n */\nfunction node_for_ptr(ptr: usize, bucket: usize): usize {\n return ((ptr - base_ptr) >> (MAX_ALLOC_LOG2 - bucket)) + (1 << bucket) - 1;\n}\n\n/*\n * Given the index of a node, this returns the "is split" flag of the parent.\n */\nfunction parent_is_split(index: usize): bool {\n index = (index - 1) / 2;\n return ((node_is_split$get(index / 8) >>> (index % 8)) & 1) == 1;\n}\n\n/*\n * Given the index of a node, this flips the "is split" flag of the parent.\n */\nfunction flip_parent_is_split(index: usize): void {\n index = (index - 1) / 2;\n var indexDiv8 = index / 8;\n node_is_split$set(indexDiv8,\n node_is_split$get(indexDiv8) ^ (1 << (index % 8))\n );\n}\n\n/*\n * Given the requested size passed to "malloc", this function returns the index\n * of the smallest bucket that can fit that size.\n */\nfunction bucket_for_request(request: usize): usize {\n var bucket = BUCKET_COUNT - 1;\n var size = MIN_ALLOC;\n\n while (size < request) {\n bucket--;\n size *= 2;\n }\n\n return bucket;\n}\n\n/*\n * The tree is always rooted at the current bucket limit. This call grows the\n * tree by repeatedly doubling it in size until the root lies at the provided\n * bucket index. Each doubling lowers the bucket limit by 1.\n */\nfunction lower_bucket_limit(bucket: usize): u32 {\n while (bucket < bucket_limit) {\n let root = node_for_ptr(base_ptr, bucket_limit);\n let right_child: usize;\n\n /*\n * If the parent isn\'t SPLIT, that means the node at the current bucket\n * limit is UNUSED and our address space is entirely free. In that case,\n * clear the root free list, increase the bucket limit, and add a single\n * block with the newly-expanded address space to the new root free list.\n */\n if (!parent_is_split(root)) {\n list_remove(changetype(base_ptr));\n list_init(buckets$get(--bucket_limit));\n list_push(buckets$get(bucket_limit), changetype(base_ptr));\n continue;\n }\n\n /*\n * Otherwise, the tree is currently in use. Create a parent node for the\n * current root node in the SPLIT state with a right child on the free\n * list. Make sure to reserve the memory for the free list entry before\n * writing to it. Note that we do not need to flip the "is split" flag for\n * our current parent because it\'s already on (we know because we just\n * checked it above).\n */\n right_child = ptr_for_node(root + 1, bucket_limit);\n if (!update_max_ptr(right_child + List.SIZE)) {\n return 0;\n }\n list_push(buckets$get(bucket_limit), changetype(right_child));\n list_init(buckets$get(--bucket_limit));\n\n /*\n * Set the grandparent\'s SPLIT flag so if we need to lower the bucket limit\n * again, we\'ll know that the new root node we just added is in use.\n */\n root = (root - 1) / 2;\n if (root != 0) {\n flip_parent_is_split(root);\n }\n }\n\n return 1;\n}\n\n// Memory allocator interface\n\n@global export function __memory_allocate(request: usize): usize {\n var original_bucket: usize, bucket: usize;\n\n /*\n * Make sure it\'s possible for an allocation of this size to succeed. There\'s\n * a hard-coded limit on the maximum allocation size because of the way this\n * allocator works.\n */\n if (request > MAX_ALLOC - HEADER_SIZE) unreachable();\n\n /*\n * Initialize our global state if this is the first call to "malloc". At the\n * beginning, the tree has a single node that represents the smallest\n * possible allocation size. More memory will be reserved later as needed.\n */\n if (base_ptr == 0) {\n // base_ptr = max_ptr = (uint8_t *)sbrk(0);\n base_ptr = (NODE_IS_SPLIT_END + 7) & ~7; // must be aligned\n max_ptr = memory.size() << 16; // must grow first\n bucket_limit = BUCKET_COUNT - 1;\n if (!update_max_ptr(base_ptr + List.SIZE)) {\n return 0;\n }\n list_init(buckets$get(BUCKET_COUNT - 1));\n list_push(buckets$get(BUCKET_COUNT - 1), changetype(base_ptr));\n }\n\n /*\n * Find the smallest bucket that will fit this request. This doesn\'t check\n * that there\'s space for the request yet.\n */\n bucket = bucket_for_request(request + HEADER_SIZE);\n original_bucket = bucket;\n\n /*\n * Search for a bucket with a non-empty free list that\'s as large or larger\n * than what we need. If there isn\'t an exact match, we\'ll need to split a\n * larger one to get a match.\n */\n while (bucket + 1 != 0) {\n let size: usize, bytes_needed: usize, i: usize;\n let ptr: usize;\n\n /*\n * We may need to grow the tree to be able to fit an allocation of this\n * size. Try to grow the tree and stop here if we can\'t.\n */\n if (!lower_bucket_limit(bucket)) {\n return 0;\n }\n\n /*\n * Try to pop a block off the free list for this bucket. If the free list\n * is empty, we\'re going to have to split a larger block instead.\n */\n ptr = changetype(list_pop(buckets$get(bucket)));\n if (!ptr) {\n /*\n * If we\'re not at the root of the tree or it\'s impossible to grow the\n * tree any more, continue on to the next bucket.\n */\n if (bucket != bucket_limit || bucket == 0) {\n bucket--;\n continue;\n }\n\n /*\n * Otherwise, grow the tree one more level and then pop a block off the\n * free list again. Since we know the root of the tree is used (because\n * the free list was empty), this will add a parent above this node in\n * the SPLIT state and then add the new right child node to the free list\n * for this bucket. Popping the free list will give us this right child.\n */\n if (!lower_bucket_limit(bucket - 1)) {\n return 0;\n }\n ptr = changetype(list_pop(buckets$get(bucket)));\n }\n\n /*\n * Try to expand the address space first before going any further. If we\n * have run out of space, put this block back on the free list and fail.\n */\n size = 1 << (MAX_ALLOC_LOG2 - bucket);\n bytes_needed = bucket < original_bucket ? size / 2 + List.SIZE : size;\n if (!update_max_ptr(ptr + bytes_needed)) {\n list_push(buckets$get(bucket), changetype(ptr));\n return 0;\n }\n\n /*\n * If we got a node off the free list, change the node from UNUSED to USED.\n * This involves flipping our parent\'s "is split" bit because that bit is\n * the exclusive-or of the UNUSED flags of both children, and our UNUSED\n * flag (which isn\'t ever stored explicitly) has just changed.\n *\n * Note that we shouldn\'t ever need to flip the "is split" bit of our\n * grandparent because we know our buddy is USED so it\'s impossible for our\n * grandparent to be UNUSED (if our buddy chunk was UNUSED, our parent\n * wouldn\'t ever have been split in the first place).\n */\n i = node_for_ptr(ptr, bucket);\n if (i != 0) {\n flip_parent_is_split(i);\n }\n\n /*\n * If the node we got is larger than we need, split it down to the correct\n * size and put the new unused child nodes on the free list in the\n * corresponding bucket. This is done by repeatedly moving to the left\n * child, splitting the parent, and then adding the right child to the free\n * list.\n */\n while (bucket < original_bucket) {\n i = i * 2 + 1;\n bucket++;\n flip_parent_is_split(i);\n list_push(\n buckets$get(bucket),\n changetype(ptr_for_node(i + 1, bucket))\n );\n }\n\n /*\n * Now that we have a memory address, write the block header (just the size\n * of the allocation) and return the address immediately after the header.\n */\n store(ptr, request);\n return ptr + HEADER_SIZE;\n }\n\n return 0;\n}\n\n@global export function __memory_free(ptr: usize): void {\n var bucket: usize, i: usize;\n\n /*\n * Ignore any attempts to free a NULL pointer.\n */\n if (!ptr) {\n return;\n }\n\n /*\n * We were given the address returned by "malloc" so get back to the actual\n * address of the node by subtracting off the size of the block header. Then\n * look up the index of the node corresponding to this address.\n */\n ptr = ptr - HEADER_SIZE;\n bucket = bucket_for_request(load(ptr) + HEADER_SIZE);\n i = node_for_ptr(ptr, bucket);\n\n /*\n * Traverse up to the root node, flipping USED blocks to UNUSED and merging\n * UNUSED buddies together into a single UNUSED parent.\n */\n while (i != 0) {\n /*\n * Change this node from UNUSED to USED. This involves flipping our\n * parent\'s "is split" bit because that bit is the exclusive-or of the\n * UNUSED flags of both children, and our UNUSED flag (which isn\'t ever\n * stored explicitly) has just changed.\n */\n flip_parent_is_split(i);\n\n /*\n * If the parent is now SPLIT, that means our buddy is USED, so don\'t merge\n * with it. Instead, stop the iteration here and add ourselves to the free\n * list for our bucket.\n *\n * Also stop here if we\'re at the current root node, even if that root node\n * is now UNUSED. Root nodes don\'t have a buddy so we can\'t merge with one.\n */\n if (parent_is_split(i) || bucket == bucket_limit) {\n break;\n }\n\n /*\n * If we get here, we know our buddy is UNUSED. In this case we should\n * merge with that buddy and continue traversing up to the root node. We\n * need to remove the buddy from its free list here but we don\'t need to\n * add the merged parent to its free list yet. That will be done once after\n * this loop is finished.\n */\n list_remove(changetype(ptr_for_node(((i - 1) ^ 1) + 1, bucket)));\n i = (i - 1) / 2;\n bucket--;\n }\n\n /*\n * Add ourselves to the free list for our bucket. We add to the back of the\n * list because "malloc" takes from the back of the list and we want a "free"\n * followed by a "malloc" of the same size to ideally use the same address\n * for better memory locality.\n */\n list_push(buckets$get(bucket), changetype(ptr_for_node(i, bucket)));\n}\n',"allocator/emscripten":"/**\n * Emscripten Memory Allocator.\n *\n * Uses Emscripten's exported _malloc and _free implementations, i.e., when linking with\n * Emscripten-compiled programs that already provide these. Differs from 'system' in that their\n * names are prefixed with an underscore.\n *\n * @module std/assembly/allocator/emscripten\n *//***/\n\ndeclare function _malloc(size: usize): usize;\ndeclare function _free(ptr: usize): void;\n\n// Memory allocator interface\n\n@global export function __memory_allocate(size: usize): usize {\n return _malloc(size);\n}\n\n@global export function __memory_free(ptr: usize): void {\n _free(ptr);\n}\n","allocator/system":"/**\n * System Memory Allocator.\n *\n * Uses the environment's malloc and free implementations, i.e., when linking with other C-like\n * programs that already provide these.\n *\n * @module std/assembly/allocator/system\n *//***/\n\ndeclare function malloc(size: usize): usize;\ndeclare function free(ptr: usize): void;\n\n// Memory allocator interface\n\n@global export function __memory_allocate(size: usize): usize {\n return malloc(size);\n}\n\n@global export function __memory_free(ptr: usize): void {\n free(ptr);\n}\n","allocator/tlsf":"/**\n * Two-Level Segregate Fit Memory Allocator.\n *\n * A general purpose dynamic memory allocator specifically designed to meet real-time requirements.\n * Always aligns to 8 bytes.\n *\n * @module std/assembly/allocator/tlsf\n *//***/\n\n// ╒══════════════ Block size interpretation (32-bit) ═════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┴─┴─┴─┴─╫─┴─┴─┤\n// │ | FL │ SB = SL + AL │ ◄─ usize\n// └───────────────────────────────────────────────┴─────────╨─────┘\n// FL: first level, SL: second level, AL: alignment, SB: small block\n\nimport {\n AL_BITS,\n AL_SIZE,\n AL_MASK\n} from \"../internal/allocator\";\n\nconst SL_BITS: u32 = 5;\nconst SL_SIZE: usize = 1 << SL_BITS;\n\nconst SB_BITS: usize = (SL_BITS + AL_BITS);\nconst SB_SIZE: usize = 1 << SB_BITS;\n\nconst FL_BITS: u32 = (sizeof() == sizeof()\n ? 30 // ^= up to 1GB per block\n : 32 // ^= up to 4GB per block\n) - SB_BITS;\n\n// ╒════════════════ Block structure layout (32-bit) ══════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┼─┤\n// │ size │L│F│ ◄─┐ info\n// ╞═══════════════════════════════════════════════════════════╧═╧═╡ │ ┐\n// │ if free: ◄ prev │ ◄─┤ usize\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ if free: next ► │ ◄─┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... unused free space >= 0 ... │ │ = 0\n// ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤ │\n// │ if free: jump ▲ │ ◄─┘\n// └───────────────────────────────────────────────────────────────┘ MIN SIZE ┘\n// F: FREE, L: LEFT_FREE\n\n/** Tag indicating that this block is free. */\nconst FREE: usize = 1 << 0;\n/** Tag indicating that this block's left block is free. */\nconst LEFT_FREE: usize = 1 << 1;\n/** Mask to obtain all tags. */\nconst TAGS: usize = FREE | LEFT_FREE;\n\n/** Block structure. */\n@unmanaged\nclass Block {\n\n /** Info field holding this block's size and tags. */\n info: usize;\n\n /** End offset of the {@link Block#info} field. User data starts here. */\n static readonly INFO: usize = (sizeof() + AL_MASK) & ~AL_MASK;\n\n /** Previous free block, if any. Only valid if free. */\n prev: Block | null;\n /** Next free block, if any. Only valid if free. */\n next: Block | null;\n\n /** Minimum size of a block, excluding {@link Block#info}. */\n static readonly MIN_SIZE: usize = (3 * sizeof() + AL_MASK) & ~AL_MASK;// prev + next + jump\n\n /** Maximum size of a used block, excluding {@link Block#info}. */\n static readonly MAX_SIZE: usize = 1 << (FL_BITS + SB_BITS);\n\n /** Gets this block's left (free) block in memory. */\n get left(): Block {\n assert(this.info & LEFT_FREE); // must be free to contain a jump\n return assert(\n load(changetype(this) - sizeof())\n ); // can't be null\n }\n\n /** Gets this block's right block in memory. */\n get right(): Block {\n assert(this.info & ~TAGS); // can't skip beyond the tail block\n return assert(\n changetype(\n changetype(this) + Block.INFO + (this.info & ~TAGS)\n )\n ); // can't be null\n }\n}\n\n// ╒════════════════ Root structure layout (32-bit) ═══════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ ┐\n// │ 0 | flMap S│ ◄────┐\n// ╞═══════════════════════════════════════════════════════════════╡ │\n// │ slMap[0] S │ ◄─┐ │\n// ├───────────────────────────────────────────────────────────────┤ │ │\n// │ slMap[1] │ ◄─┤ │\n// ├───────────────────────────────────────────────────────────────┤ u32 │\n// │ ... │ ◄─┤ │\n// ├───────────────────────────────────────────────────────────────┤ │ │\n// │ slMap[22] P │ ◄─┘ │\n// ╞═══════════════════════════════════════════════════════════════╡ usize\n// │ head[0] │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ head[736] │ ◄────┤\n// ╞═══════════════════════════════════════════════════════════════╡ │\n// │ tailRef │ ◄────┘\n// └───────────────────────────────────────────────────────────────┘ SIZE ┘\n// S: Small blocks map, P: Possibly padded if 64-bit\n\nassert((1 << SL_BITS) <= 32); // second level must fit into 32 bits\n\n/** Root structure. */\n@unmanaged\nclass Root {\n\n /** First level bitmap. */\n flMap: usize = 0;\n\n /** Start offset of second level maps. */\n private static readonly SL_START: usize = sizeof();\n\n // Using *one* SL map per *FL bit*\n\n /** Gets the second level map for the specified first level. */\n getSLMap(fl: usize): u32 {\n assert(fl < FL_BITS); // fl out of range\n return load(changetype(this) + fl * 4, Root.SL_START);\n }\n\n /** Sets the second level map for the specified first level. */\n setSLMap(fl: usize, value: u32): void {\n assert(fl < FL_BITS); // fl out of range\n store(changetype(this) + fl * 4, value, Root.SL_START);\n }\n\n /** End offset of second level maps. */\n private static readonly SL_END: usize = Root.SL_START + FL_BITS * 4;\n\n // Using *number bits per SL* heads per *FL bit*\n\n /** Start offset of FL/SL heads. */\n private static readonly HL_START: usize = (Root.SL_END + AL_MASK) & ~AL_MASK;\n\n /** Gets the head of the specified first and second level index. */\n getHead(fl: usize, sl: u32): Block | null {\n assert(fl < FL_BITS); // fl out of range\n assert(sl < SL_SIZE); // sl out of range\n return changetype(load(\n changetype(this) + (fl * SL_SIZE + sl) * sizeof()\n , Root.HL_START));\n }\n\n /** Sets the head of the specified first and second level index. */\n setHead(fl: usize, sl: u32, value: Block | null): void {\n assert(fl < FL_BITS); // fl out of range\n assert(sl < SL_SIZE); // sl out of range\n store(\n changetype(this) + (fl * SL_SIZE + sl) * sizeof()\n , changetype(value)\n , Root.HL_START);\n }\n\n /** End offset of FL/SL heads. */\n private static readonly HL_END: usize = (\n Root.HL_START + FL_BITS * SL_SIZE * sizeof()\n );\n\n get tailRef(): usize { return load(0, Root.HL_END); }\n set tailRef(value: usize) { store(0, value, Root.HL_END); }\n\n /** Total size of the {@link Root} structure. */\n static readonly SIZE: usize = Root.HL_END + sizeof();\n\n /** Inserts a previously used block back into the free list. */\n insert(block: Block): void {\n // check as much as possible here to prevent invalid free blocks\n assert(block); // cannot be null\n var blockInfo = block.info;\n assert(blockInfo & FREE); // must be free\n var size: usize;\n assert(\n (size = block.info & ~TAGS) >= Block.MIN_SIZE && size < Block.MAX_SIZE\n ); // must be valid, not necessary to compute yet if noAssert=true\n\n var right: Block = assert(block.right); // can't be null\n var rightInfo = right.info;\n\n // merge with right block if also free\n if (rightInfo & FREE) {\n this.remove(right);\n block.info = (blockInfo += Block.INFO + (rightInfo & ~TAGS));\n right = block.right;\n rightInfo = right.info;\n // jump is set below\n }\n\n // merge with left block if also free\n if (blockInfo & LEFT_FREE) {\n let left: Block = assert(block.left); // can't be null\n let leftInfo = left.info;\n assert(leftInfo & FREE); // must be free according to tags\n this.remove(left);\n left.info = (leftInfo += Block.INFO + (blockInfo & ~TAGS));\n block = left;\n blockInfo = leftInfo;\n // jump is set below\n }\n\n right.info = rightInfo | LEFT_FREE;\n this.setJump(block, right);\n // right is no longer used now, hence rightInfo is not synced\n\n size = blockInfo & ~TAGS;\n assert(size >= Block.MIN_SIZE && size < Block.MAX_SIZE); // must be valid\n\n // mapping_insert\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size / AL_SIZE);\n } else {\n fl = fls(size);\n sl = ((size >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n\n // perform insertion\n var head = this.getHead(fl, sl);\n block.prev = null;\n block.next = head;\n if (head) head.prev = block;\n this.setHead(fl, sl, block);\n\n // update first and second level maps\n this.flMap |= (1 << fl);\n this.setSLMap(fl, this.getSLMap(fl) | (1 << sl));\n }\n\n /**\n * Removes a free block from FL/SL maps. Does not alter left/jump because it\n * is likely that splitting is performed afterwards, invalidating any changes\n * again.\n */\n private remove(block: Block): void {\n var blockInfo = block.info;\n assert(blockInfo & FREE); // must be free\n var size = blockInfo & ~TAGS;\n assert(size >= Block.MIN_SIZE && size < Block.MAX_SIZE); // must be valid\n\n // mapping_insert\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size / AL_SIZE);\n } else {\n fl = fls(size);\n sl = ((size >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n\n // link previous and next free block\n var prev = block.prev;\n var next = block.next;\n if (prev) prev.next = next;\n if (next) next.prev = prev;\n\n // update head if we are removing it\n if (block == this.getHead(fl, sl)) {\n this.setHead(fl, sl, next);\n\n // clear second level map if head is empty now\n if (!next) {\n let slMap = this.getSLMap(fl);\n this.setSLMap(fl, slMap &= ~(1 << sl));\n\n // clear first level map if second level is empty now\n if (!slMap) this.flMap &= ~(1 << fl);\n }\n }\n }\n\n /** Searches for a free block of at least the specified size. */\n search(size: usize): Block | null {\n assert(size >= Block.MIN_SIZE && size < Block.MAX_SIZE);\n\n // mapping_search\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size / AL_SIZE);\n } else {\n // (*) size += (1 << (fls(size) - SL_BITS)) - 1;\n fl = fls(size);\n sl = ((size >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n // (*) instead of rounding up, use next second level list for better fit\n if (sl < SL_SIZE - 1) ++sl;\n else ++fl, sl = 0;\n }\n\n // search second level\n var slMap = this.getSLMap(fl) & (~0 << sl);\n var head: Block | null;\n if (!slMap) {\n // search next larger first level\n let flMap = this.flMap & (~0 << (fl + 1));\n if (!flMap) {\n head = null;\n } else {\n fl = ffs(flMap);\n slMap = assert(this.getSLMap(fl)); // can't be zero if fl points here\n head = this.getHead(fl, ffs(slMap));\n }\n } else {\n head = this.getHead(fl, ffs(slMap));\n }\n return head;\n }\n\n /** Links a free left with its right block in memory. */\n private setJump(left: Block, right: Block): void {\n assert(left.info & FREE); // must be free\n assert(left.right == right); // right block must match\n assert(right.info & LEFT_FREE); // right block must be tagged as LEFT_FREE\n store(\n changetype(right) - sizeof()\n , left); // last word in left block's (free) data region\n }\n\n /**\n * Uses the specified free block, removing it from internal maps and\n * splitting it if possible, and returns its data pointer.\n */\n use(block: Block, size: usize): usize {\n var blockInfo = block.info;\n assert(blockInfo & FREE); // must be free so we can use it\n assert(size >= Block.MIN_SIZE && size < Block.MAX_SIZE); // must be valid\n assert(!(size & AL_MASK)); // size must be aligned so the new block is\n\n this.remove(block);\n\n // split if the block can hold another MIN_SIZE block\n var remaining = (blockInfo & ~TAGS) - size;\n if (remaining >= Block.INFO + Block.MIN_SIZE) {\n block.info = size | (blockInfo & LEFT_FREE); // also discards FREE\n\n let spare = changetype(\n changetype(block) + Block.INFO + size\n );\n spare.info = (remaining - Block.INFO) | FREE; // not LEFT_FREE\n this.insert(spare); // also sets jump\n\n // otherwise tag block as no longer FREE and right as no longer LEFT_FREE\n } else {\n block.info = blockInfo & ~FREE;\n let right: Block = assert(block.right); // can't be null (tail)\n right.info &= ~LEFT_FREE;\n }\n\n return changetype(block) + Block.INFO;\n }\n\n /** Adds more memory to the pool. */\n addMemory(start: usize, end: usize): bool {\n assert(start <= end);\n assert(!(start & AL_MASK)); // must be aligned\n assert(!(end & AL_MASK)); // must be aligned\n\n var tailRef = this.tailRef;\n var tailInfo: usize = 0;\n if (tailRef) {\n assert(start >= tailRef + sizeof()); // starts after tail\n\n // merge with current tail if adjacent\n if (start - Block.INFO == tailRef) {\n start -= Block.INFO;\n tailInfo = changetype(tailRef).info;\n }\n\n } else {\n assert(start >= changetype(this) + Root.SIZE); // starts after root\n }\n\n // check if size is large enough for a free block and the tail block\n var size = end - start;\n if (size < Block.INFO + Block.MIN_SIZE + Block.INFO) {\n return false;\n }\n\n // left size is total minus its own and the zero-length tail's header\n var leftSize = size - 2 * Block.INFO;\n var left = changetype(start);\n left.info = leftSize | FREE | (tailInfo & LEFT_FREE);\n left.prev = null;\n left.next = null;\n\n // tail is a zero-length used block\n var tail = changetype(start + size - Block.INFO);\n tail.info = 0 | LEFT_FREE;\n this.tailRef = changetype(tail);\n\n this.insert(left); // also merges with free left before tail / sets jump\n\n return true;\n }\n}\n\n/** Determines the first (LSB to MSB) set bit's index of a word. */\nfunction ffs(word: T): T {\n assert(word != 0); // word cannot be 0\n return ctz(word); // differs from ffs only for 0\n}\n\n/** Determines the last (LSB to MSB) set bit's index of a word. */\nfunction fls(word: T): T {\n assert(word != 0); // word cannot be 0\n const inv: T = (sizeof() << 3) - 1;\n return inv - clz(word);\n}\n\n/** Reference to the initialized {@link Root} structure, once initialized. */\nvar ROOT: Root = changetype(0);\n\n// Memory allocator interface\n\n/** Allocates a chunk of memory. */\n@global export function __memory_allocate(size: usize): usize {\n\n // initialize if necessary\n var root = ROOT;\n if (!root) {\n let rootOffset = (HEAP_BASE + AL_MASK) & ~AL_MASK;\n let pagesBefore = memory.size();\n let pagesNeeded = ((((rootOffset + Root.SIZE) + 0xffff) & ~0xffff) >>> 16);\n if (pagesNeeded > pagesBefore && memory.grow(pagesNeeded - pagesBefore) < 0) unreachable();\n ROOT = root = changetype(rootOffset);\n root.tailRef = 0;\n root.flMap = 0;\n for (let fl: usize = 0; fl < FL_BITS; ++fl) {\n root.setSLMap(fl, 0);\n for (let sl: u32 = 0; sl < SL_SIZE; ++sl) {\n root.setHead(fl, sl, null);\n }\n }\n root.addMemory((rootOffset + Root.SIZE + AL_MASK) & ~AL_MASK, memory.size() << 16);\n }\n\n // search for a suitable block\n if (size > Block.MAX_SIZE) unreachable();\n\n // 32-bit MAX_SIZE is 1 << 30 and itself aligned, hence the following can't overflow MAX_SIZE\n size = max((size + AL_MASK) & ~AL_MASK, Block.MIN_SIZE);\n\n var block = root.search(size);\n if (!block) {\n\n // request more memory\n let pagesBefore = memory.size();\n let pagesNeeded = (((size + 0xffff) & ~0xffff) >>> 16);\n let pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) {\n unreachable(); // out of memory\n }\n }\n let pagesAfter = memory.size();\n root.addMemory(pagesBefore << 16, pagesAfter << 16);\n block = assert(root.search(size)); // must be found now\n }\n\n assert((block.info & ~TAGS) >= size);\n return root.use(block, size);\n}\n\n/** Frees the chunk of memory at the specified address. */\n@global export function __memory_free(data: usize): void {\n if (data) {\n let root = ROOT;\n if (root) {\n let block = changetype(data - Block.INFO);\n let blockInfo = block.info;\n assert(!(blockInfo & FREE)); // must be used\n block.info = blockInfo | FREE;\n root.insert(changetype(data - Block.INFO));\n }\n }\n}\n\n@global export function __memory_reset(): void {\n unreachable();\n}\n",array:'import {\n MAX_BLENGTH,\n HEADER_SIZE,\n allocateUnsafe,\n reallocateUnsafe,\n loadUnsafe,\n storeUnsafe\n} from "./internal/arraybuffer";\n\nimport {\n allocateUnsafe as allocateUnsafeString,\n freeUnsafe as freeUnsafeString,\n copyUnsafe as copyUnsafeString\n} from "./internal/string";\n\nimport {\n defaultComparator,\n insertionSort,\n weakHeapSort\n} from "./internal/array";\n\nimport {\n itoa,\n dtoa,\n itoa_stream,\n dtoa_stream,\n MAX_DOUBLE_LENGTH\n} from "./internal/number";\n\nexport class Array {\n\n /* @internal */ buffer_: ArrayBuffer;\n /* @internal */ length_: i32;\n\n constructor(length: i32 = 0) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (length > MAX_LENGTH) throw new RangeError("Invalid array length");\n var byteLength = length << alignof();\n var buffer = allocateUnsafe(byteLength);\n this.buffer_ = buffer;\n this.length_ = length;\n memory.fill(\n changetype(buffer) + HEADER_SIZE,\n 0,\n byteLength\n );\n }\n\n @inline\n get length(): i32 {\n return this.length_;\n }\n\n set length(length: i32) {\n var buffer = this.buffer_;\n var capacity = buffer.byteLength >>> alignof();\n if (length > capacity) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (length > MAX_LENGTH) throw new RangeError("Invalid array length");\n buffer = reallocateUnsafe(buffer, length << alignof());\n this.buffer_ = buffer;\n }\n this.length_ = length;\n }\n\n every(callbackfn: (element: T, index: i32, array: Array) => bool): bool {\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n if (!callbackfn(loadUnsafe(buffer, index), index, this)) return false;\n }\n return true;\n }\n\n findIndex(predicate: (element: T, index: i32, array: Array) => bool): i32 {\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n if (predicate(loadUnsafe(buffer, index), index, this)) return index;\n }\n return -1;\n }\n\n @operator("[]")\n private __get(index: i32): T {\n var buffer = this.buffer_;\n return index < (buffer.byteLength >>> alignof())\n ? loadUnsafe(buffer, index)\n : unreachable();\n }\n\n @operator("{}")\n private __unchecked_get(index: i32): T {\n return loadUnsafe(this.buffer_, index);\n }\n\n @operator("[]=")\n private __set(index: i32, value: T): void {\n var buffer = this.buffer_;\n var capacity = buffer.byteLength >>> alignof();\n if (index >= capacity) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (index >= MAX_LENGTH) throw new Error("Invalid array length");\n buffer = reallocateUnsafe(buffer, (index + 1) << alignof());\n this.buffer_ = buffer;\n this.length_ = index + 1;\n }\n storeUnsafe(buffer, index, value);\n if (isManaged()) __gc_link(changetype(this), changetype(value)); // tslint:disable-line\n }\n\n @operator("{}=")\n private __unchecked_set(index: i32, value: T): void {\n storeUnsafe(this.buffer_, index, value);\n if (isManaged()) __gc_link(changetype(this), changetype(value)); // tslint:disable-line\n }\n\n fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): this {\n var buffer = this.buffer_;\n var len = this.length_;\n start = start < 0 ? max(len + start, 0) : min(start, len);\n end = end < 0 ? max(len + end, 0) : min(end, len);\n if (sizeof() == 1) {\n if (start < end) {\n memory.fill(\n changetype(buffer) + start + HEADER_SIZE,\n value,\n (end - start)\n );\n }\n } else {\n for (; start < end; ++start) {\n storeUnsafe(buffer, start, value);\n }\n }\n return this;\n }\n\n @inline\n includes(searchElement: T, fromIndex: i32 = 0): bool {\n return this.indexOf(searchElement, fromIndex) >= 0;\n }\n\n indexOf(searchElement: 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 buffer = this.buffer_;\n while (fromIndex < length) {\n if (loadUnsafe(buffer, fromIndex) == searchElement) return fromIndex;\n ++fromIndex;\n }\n return -1;\n }\n\n lastIndexOf(searchElement: T, fromIndex: i32 = this.length_): i32 {\n var length = this.length_;\n if (length == 0) return -1;\n if (fromIndex < 0) fromIndex = length + fromIndex; // no need to clamp\n else if (fromIndex >= length) fromIndex = length - 1;\n var buffer = this.buffer_;\n while (fromIndex >= 0) { // ^\n if (loadUnsafe(buffer, fromIndex) == searchElement) return fromIndex;\n --fromIndex;\n }\n return -1;\n }\n\n push(element: T): i32 {\n var length = this.length_;\n var buffer = this.buffer_;\n var capacity = buffer.byteLength >>> alignof();\n var newLength = length + 1; // safe only if length is checked\n if (length >= capacity) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (length >= MAX_LENGTH) throw new Error("Invalid array length");\n buffer = reallocateUnsafe(buffer, newLength << alignof());\n this.buffer_ = buffer;\n }\n this.length_ = newLength;\n storeUnsafe(buffer, length, element);\n if (isManaged()) __gc_link(changetype(this), changetype(element)); // tslint:disable-line\n return newLength;\n }\n\n concat(items: Array): Array {\n var thisLen: isize = this.length_;\n var otherLen = (items == null) ? 0 : items.length_;\n var outLen = thisLen + otherLen;\n var out: Array = new Array(outLen);\n\n if (thisLen) {\n memory.copy(changetype(out.buffer_) + HEADER_SIZE,\n changetype(this.buffer_) + HEADER_SIZE,\n (thisLen << alignof()));\n }\n if (otherLen) {\n memory.copy(changetype(out.buffer_) + HEADER_SIZE + (thisLen << alignof()),\n changetype(items.buffer_) + HEADER_SIZE,\n (otherLen << alignof()));\n }\n return out;\n }\n\n pop(): T {\n var length = this.length_;\n if (length < 1) throw new RangeError("Array is empty");\n var element = loadUnsafe(this.buffer_, --length);\n this.length_ = length;\n return element;\n }\n\n forEach(callbackfn: (value: T, index: i32, array: Array) => void): void {\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n callbackfn(loadUnsafe(buffer, index), index, this);\n }\n }\n\n map(callbackfn: (value: T, index: i32, array: Array) => U): Array {\n var buffer = this.buffer_;\n var length = this.length_;\n var result = new Array(length);\n var resultBuffer = result.buffer_;\n for (let index = 0; index < length && index < this.length_; ++index) {\n storeUnsafe(resultBuffer, index, callbackfn(loadUnsafe(buffer, index), index, this));\n }\n return result;\n }\n\n filter(callbackfn: (value: T, index: i32, array: Array) => bool): Array {\n var buffer = this.buffer_;\n var length = this.length_;\n var result = new Array();\n for (let index = 0; index < length && index < this.length_; ++index) {\n let value = loadUnsafe(buffer, index);\n if (callbackfn(value, index, this)) result.push(value);\n }\n return result;\n }\n\n reduce(\n callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var accum = initialValue;\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n accum = callbackfn(accum, loadUnsafe(buffer, index), index, this);\n }\n return accum;\n }\n\n reduceRight(\n callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var accum = initialValue;\n var buffer = this.buffer_;\n for (let index: i32 = this.length_ - 1; index >= 0; --index) {\n accum = callbackfn(accum, loadUnsafe(buffer, index), index, this);\n }\n return accum;\n }\n\n shift(): T {\n var length = this.length_;\n if (length < 1) throw new RangeError("Array is empty");\n var buffer = this.buffer_;\n var element = loadUnsafe(buffer, 0);\n var lastIndex = length - 1;\n memory.copy(\n changetype(buffer) + HEADER_SIZE,\n changetype(buffer) + HEADER_SIZE + sizeof(),\n lastIndex << alignof()\n );\n storeUnsafe(buffer, lastIndex, null);\n this.length_ = lastIndex;\n return element;\n }\n\n some(callbackfn: (element: T, index: i32, array: Array) => bool): bool {\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n if (callbackfn(loadUnsafe(buffer, index), index, this)) return true;\n }\n return false;\n }\n\n unshift(element: T): i32 {\n var buffer = this.buffer_;\n var capacity = buffer.byteLength >>> alignof();\n var length = this.length_;\n var newLength = length + 1; // safe only if length is checked\n if (length >= capacity) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (length >= MAX_LENGTH) throw new Error("Invalid array length");\n buffer = reallocateUnsafe(buffer, newLength << alignof());\n capacity = buffer.byteLength >>> alignof();\n this.buffer_ = buffer;\n }\n memory.copy(\n changetype(buffer) + HEADER_SIZE + sizeof(),\n changetype(buffer) + HEADER_SIZE,\n (capacity - 1) << alignof()\n );\n storeUnsafe(buffer, 0, element);\n this.length_ = newLength;\n if (isManaged()) __gc_link(changetype(this), changetype(element)); // tslint:disable-line\n return newLength;\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Array {\n var length = this.length_;\n if (begin < 0) begin = max(length + begin, 0);\n else if (begin > length) begin = length;\n if (end < 0) end = length + end; // no need to clamp\n else if (end > length) end = length;\n if (end < begin) end = begin; // ^\n var newLength = end - begin;\n assert(newLength >= 0);\n var sliced = new Array(newLength);\n if (newLength) {\n memory.copy(\n changetype(sliced.buffer_) + HEADER_SIZE,\n changetype(this.buffer_) + HEADER_SIZE + (begin << alignof()),\n newLength << alignof()\n );\n }\n return sliced;\n }\n\n splice(start: i32, deleteCount: i32 = i32.MAX_VALUE): void {\n if (deleteCount < 1) return;\n var length = this.length_;\n if (start < 0) start = max(length + start, 0);\n if (start >= length) return;\n deleteCount = min(deleteCount, length - start);\n var buffer = this.buffer_;\n memory.copy(\n changetype(buffer) + HEADER_SIZE + (start << alignof()),\n changetype(buffer) + HEADER_SIZE + ((start + deleteCount) << alignof()),\n deleteCount << alignof()\n );\n this.length_ = length - deleteCount;\n }\n\n reverse(): Array {\n var buffer = this.buffer_;\n for (let front = 0, back = this.length_ - 1; front < back; ++front, --back) {\n let temp = loadUnsafe(buffer, front);\n storeUnsafe(buffer, front, loadUnsafe(buffer, back));\n storeUnsafe(buffer, back, temp);\n }\n return this;\n }\n\n sort(comparator: (a: T, b: T) => i32 = defaultComparator()): this {\n // TODO remove this when flow will allow trackcing null\n assert(comparator); // The comparison function must be a function\n\n var length = this.length_;\n if (length <= 1) return this;\n var buffer = this.buffer_;\n if (length == 2) {\n let a = loadUnsafe(buffer, 1); // a = arr[1]\n let b = loadUnsafe(buffer, 0); // b = arr[0]\n if (comparator(a, b) < 0) {\n storeUnsafe(buffer, 1, b); // arr[1] = b;\n storeUnsafe(buffer, 0, a); // arr[0] = a;\n }\n return this;\n }\n\n if (isReference()) {\n // TODO replace this to faster stable sort (TimSort) when it implemented\n insertionSort(buffer, 0, length, comparator);\n return this;\n } else {\n if (length < 256) {\n insertionSort(buffer, 0, length, comparator);\n } else {\n weakHeapSort(buffer, 0, length, comparator);\n }\n return this;\n }\n }\n\n join(separator: string = ","): string {\n var lastIndex = this.length_ - 1;\n if (lastIndex < 0) return "";\n var result = "";\n var value: T;\n var buffer = this.buffer_;\n var sepLen = separator.length;\n var hasSeparator = sepLen != 0;\n if (value instanceof bool) {\n if (!lastIndex) {\n return select("true", "false", loadUnsafe(buffer, 0));\n }\n let valueLen = 5; // max possible length of element len("false")\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = allocateUnsafeString(estLen);\n let offset = 0;\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n valueLen = 4 + (!value);\n copyUnsafeString(result, offset, select("true", "false", value), 0, valueLen);\n offset += valueLen;\n if (hasSeparator) {\n copyUnsafeString(result, offset, changetype(separator), 0, sepLen);\n offset += sepLen;\n }\n }\n value = loadUnsafe(buffer, lastIndex);\n valueLen = 4 + (!value);\n copyUnsafeString(result, offset, select("true", "false", value), 0, valueLen);\n offset += valueLen;\n\n let out = result;\n if (estLen > offset) {\n out = result.substring(0, offset);\n freeUnsafeString(result);\n }\n return out;\n } else if (isInteger()) {\n if (!lastIndex) {\n return changetype(itoa(loadUnsafe(buffer, 0)));\n }\n const valueLen = (sizeof() <= 4 ? 10 : 20) + isSigned();\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = allocateUnsafeString(estLen);\n let offset = 0;\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n offset += itoa_stream(changetype(result), offset, value);\n if (hasSeparator) {\n copyUnsafeString(result, offset, separator, 0, sepLen);\n offset += sepLen;\n }\n }\n value = loadUnsafe(buffer, lastIndex);\n offset += itoa_stream(changetype(result), offset, value);\n let out = result;\n if (estLen > offset) {\n out = result.substring(0, offset);\n freeUnsafeString(result);\n }\n return out;\n } else if (isFloat()) {\n if (!lastIndex) {\n return changetype(dtoa(loadUnsafe(buffer, 0)));\n }\n const valueLen = MAX_DOUBLE_LENGTH;\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = allocateUnsafeString(estLen);\n let offset = 0;\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n offset += dtoa_stream(changetype(result), offset, value);\n if (hasSeparator) {\n copyUnsafeString(result, offset, separator, 0, sepLen);\n offset += sepLen;\n }\n }\n value = loadUnsafe(buffer, lastIndex);\n offset += dtoa_stream(changetype(result), offset, value);\n let out = result;\n if (estLen > offset) {\n out = result.substring(0, offset);\n freeUnsafeString(result);\n }\n return out;\n } else if (isString()) {\n if (!lastIndex) {\n return loadUnsafe(buffer, 0);\n }\n let estLen = 0;\n for (let i = 0, len = lastIndex + 1; i < len; ++i) {\n estLen += loadUnsafe(buffer, i).length;\n }\n let offset = 0;\n let result = allocateUnsafeString(estLen + sepLen * lastIndex);\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n if (value) {\n let valueLen = value.length; // tslint:disable-line:no-unsafe-any\n copyUnsafeString(result, offset, value, 0, valueLen); // tslint:disable-line:no-unsafe-any\n offset += valueLen; // tslint:disable-line:no-unsafe-any\n }\n if (hasSeparator) {\n copyUnsafeString(result, offset, separator, 0, sepLen);\n offset += sepLen;\n }\n }\n value = loadUnsafe(buffer, lastIndex);\n if (value) {\n let valueLen = value.length; // tslint:disable-line:no-unsafe-any\n copyUnsafeString(result, offset, value, 0, valueLen); // tslint:disable-line:no-unsafe-any\n }\n return result;\n } else if (isArray()) {\n if (!lastIndex) {\n value = loadUnsafe(buffer, 0);\n return value ? value.join(separator) : ""; // tslint:disable-line:no-unsafe-any\n }\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n if (value) result += value.join(separator); // tslint:disable-line:no-unsafe-any\n if (hasSeparator) result += separator;\n }\n value = loadUnsafe(buffer, lastIndex);\n if (value) result += value.join(separator); // tslint:disable-line:no-unsafe-any\n return result;\n } else if (isReference()) { // References\n if (!lastIndex) return "[object Object]";\n const valueLen = 15; // max possible length of element len("[object Object]")\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = allocateUnsafeString(estLen);\n let offset = 0;\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n if (value) {\n copyUnsafeString(result, offset, changetype("[object Object]"), 0, valueLen);\n offset += valueLen;\n }\n if (hasSeparator) {\n copyUnsafeString(result, offset, changetype(separator), 0, sepLen);\n offset += sepLen;\n }\n }\n if (loadUnsafe(buffer, lastIndex)) {\n copyUnsafeString(result, offset, changetype("[object Object]"), 0, valueLen);\n offset += valueLen;\n }\n let out = result;\n if (estLen > offset) {\n out = result.substring(0, offset);\n freeUnsafeString(result);\n }\n return out;\n } else {\n assert(false); // Unsupported generic typename\n }\n }\n\n @inline\n toString(): string {\n return this.join();\n }\n\n private __gc(): void {\n var buffer = this.buffer_;\n __gc_mark(changetype(buffer)); // tslint:disable-line\n if (isManaged()) {\n let offset: usize = 0;\n let end = this.length_ << alignof();\n while (offset < end) {\n __gc_mark(load(changetype(buffer) + offset, HEADER_SIZE)); // tslint:disable-line\n offset += sizeof();\n }\n }\n }\n}\n',arraybuffer:'import {\n HEADER_SIZE,\n MAX_BLENGTH,\n allocateUnsafe\n} from "./internal/arraybuffer";\n\n@sealed\nexport class ArrayBuffer {\n\n readonly byteLength: i32; // capped to [0, MAX_LENGTH]\n\n // @unsafe\n get data(): usize { return changetype(this) + HEADER_SIZE; }\n\n constructor(length: i32, unsafe: bool = false) {\n if (length > MAX_BLENGTH) throw new RangeError("Invalid array buffer length");\n var buffer = allocateUnsafe(length);\n if (!unsafe) memory.fill(changetype(buffer) + HEADER_SIZE, 0, length);\n return buffer;\n }\n\n slice(begin: i32 = 0, end: i32 = MAX_BLENGTH): ArrayBuffer {\n var len = this.byteLength;\n if (begin < 0) begin = max(len + begin, 0);\n else begin = min(begin, len);\n if (end < 0) end = max(len + end, 0);\n else end = min(end, len);\n var newLen = max(end - begin, 0);\n var buffer = allocateUnsafe(newLen);\n memory.copy(changetype(buffer) + HEADER_SIZE, changetype(this) + HEADER_SIZE + begin, newLen);\n return buffer;\n }\n}\n',"bindings/Math":"export declare const E: f64;\nexport declare const LN2: f64;\nexport declare const LN10: f64;\nexport declare const LOG2E: f64;\nexport declare const LOG10E: f64;\nexport declare const PI: f64;\nexport declare const SQRT1_2: f64;\nexport declare const SQRT2: f64;\n\nexport declare function abs(x: f64): f64;\nexport declare function acos(x: f64): f64;\nexport declare function acosh(x: f64): f64;\nexport declare function asin(x: f64): f64;\nexport declare function asinh(x: f64): f64;\nexport declare function atan(x: f64): f64;\nexport declare function atan2(y: f64, x: f64): f64;\nexport declare function atanh(x: f64): f64;\nexport declare function cbrt(x: f64): f64;\nexport declare function ceil(x: f64): f64;\nexport declare function clz32(x: f64): f64;\nexport declare function cos(x: f64): f64;\nexport declare function cosh(x: f64): f64;\nexport declare function exp(x: f64): f64;\nexport declare function expm1(x: f64): f64;\nexport declare function floor(x: f64): f64;\nexport declare function fround(x: f64): f32;\nexport declare function hypot(value1: f64, value2: f64): f64; // TODO: rest\nexport declare function imul(a: f64, b: f64): f64;\nexport declare function log(x: f64): f64;\nexport declare function log10(x: f64): f64;\nexport declare function log1p(x: f64): f64;\nexport declare function log2(x: f64): f64;\nexport declare function max(value1: f64, value2: f64): f64; // TODO: rest\nexport declare function min(value1: f64, value2: f64): f64; // TODO: rest\nexport declare function pow(base: f64, exponent: f64): f64;\nexport declare function random(): f64;\nexport declare function round(x: f64): f64;\nexport declare function sign(x: f64): f64;\nexport declare function sin(x: f64): f64;\nexport declare function sinh(x: f64): f64;\nexport declare function sqrt(x: f64): f64;\nexport declare function tan(x: f64): f64;\nexport declare function tanh(x: f64): f64;\nexport declare function trunc(x: f64): f64;\n",builtins:"/* tslint:disable */\n\n@builtin @inline export const NaN: f64 = 0 / 0;\n@builtin @inline export const Infinity: f64 = 1 / 0;\n\n@builtin export declare function isInteger(value?: T): bool;\n@builtin export declare function isFloat(value?: T): bool;\n@builtin export declare function isSigned(value?: T): bool;\n@builtin export declare function isReference(value?: T): bool;\n@builtin export declare function isString(value?: T): bool;\n@builtin export declare function isArray(value?: T): bool;\n@builtin export declare function isDefined(expression: void): bool;\n@builtin export declare function isConstant(expression: void): bool;\n@builtin export declare function isManaged(value?: T): bool;\n@inline export function isNaN(value: T): bool { return value != value; }\n@inline export function isFinite(value: T): bool { return value - value == 0; }\n\n@builtin export declare function clz(value: T): T;\n@builtin export declare function ctz(value: T): T;\n@builtin export declare function popcnt(value: T): T;\n@builtin export declare function rotl(value: T, shift: T): T;\n@builtin export declare function rotr(value: T, shift: T): T;\n@builtin export declare function abs(value: T): T;\n@builtin export declare function max(left: T, right: T): T;\n@builtin export declare function min(left: T, right: T): T;\n@builtin export declare function ceil(value: T): T;\n@builtin export declare function floor(value: T): T;\n@builtin export declare function copysign(left: T, right: T): T;\n@builtin export declare function nearest(value: T): T;\n@builtin export declare function reinterpret(value: void): T;\n@builtin export declare function sqrt(value: T): T;\n@builtin export declare function trunc(value: T): T;\n@builtin export declare function load(offset: usize, constantOffset?: usize): T;\n@builtin export declare function store(offset: usize, value: void, constantOffset?: usize): void;\n@builtin export declare function sizeof(): usize; // | u32 / u64\n@builtin export declare function alignof(): usize; // | u32 / u64\n@builtin export declare function offsetof(fieldName?: string): usize; // | u32 / u64\n@builtin export declare function select(ifTrue: T, ifFalse: T, condition: bool): T;\n@builtin export declare function unreachable(): void;\n@builtin export declare function changetype(value: void): T;\n@builtin export declare function assert(isTrueish: T, message?: string): T;\n@builtin export declare function unchecked(expr: T): T;\n@builtin export declare function call_indirect(target: void, ...args: void[]): T;\n\n@builtin export declare function i8(value: void): i8;\nexport namespace i8 {\n export const MIN_VALUE: i8 = -128;\n export const MAX_VALUE: i8 = 127;\n}\n\n@builtin export declare function i16(value: void): i16;\nexport namespace i16 {\n export const MIN_VALUE: i16 = -32768;\n export const MAX_VALUE: i16 = 32767;\n}\n\n@builtin export declare function i32(value: void): i32;\nexport namespace i32 {\n export const MIN_VALUE: i32 = -2147483648;\n export const MAX_VALUE: i32 = 2147483647;\n @builtin export declare function clz(value: i32): i32;\n @builtin export declare function ctz(value: i32): i32;\n @builtin export declare function popcnt(value: i32): i32;\n @builtin export declare function rotl(value: i32, shift: i32): i32;\n @builtin export declare function rotr(value: i32, shift: i32): i32;\n @builtin export declare function reinterpret_f32(value: f32): i32;\n @builtin export declare function load8_s(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function load8_u(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function load16_s(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function load16_u(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function load(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function store8(offset: usize, value: i32, constantOffset?: usize): void;\n @builtin export declare function store16(offset: usize, value: i32, constantOffset?: usize): void;\n @builtin export declare function store(offset: usize, value: i32, constantOffset?: usize): void;\n}\n\n@builtin export declare function i64(value: void): i64;\nexport namespace i64 {\n export const MIN_VALUE: i64 = -9223372036854775808;\n export const MAX_VALUE: i64 = 9223372036854775807;\n @builtin export declare function clz(value: i64): i64;\n @builtin export declare function ctz(value: i64): i64;\n @builtin export declare function load8_s(offset: usize, constantOffset?: usize): i64;\n @builtin export declare function load8_u(offset: usize, constantOffset?: usize): u64;\n @builtin export declare function load16_s(offset: usize, constantOffset?: usize): i64;\n @builtin export declare function load16_u(offset: usize, constantOffset?: usize): u64;\n @builtin export declare function load32_s(offset: usize, constantOffset?: usize): i64;\n @builtin export declare function load32_u(offset: usize, constantOffset?: usize): u64;\n @builtin export declare function load(offset: usize, constantOffset?: usize): i64;\n @builtin export declare function popcnt(value: i64): i64;\n @builtin export declare function rotl(value: i64, shift: i64): i64;\n @builtin export declare function rotr(value: i64, shift: i64): i64;\n @builtin export declare function reinterpret_f64(value: f64): i64;\n @builtin export declare function store8(offset: usize, value: i64, constantOffset?: usize): void;\n @builtin export declare function store16(offset: usize, value: i64, constantOffset?: usize): void;\n @builtin export declare function store32(offset: usize, value: i64, constantOffset?: usize): void;\n @builtin export declare function store(offset: usize, value: i64, constantOffset?: usize): void;\n}\n\n@builtin export declare function isize(value: void): isize;\nexport namespace isize {\n export const MIN_VALUE: isize = sizeof() == sizeof()\n ? -2147483648\n : -9223372036854775808;\n export const MAX_VALUE: isize = sizeof() == sizeof()\n ? 2147483647\n : 9223372036854775807;\n}\n\n@builtin export declare function u8(value: void): u8;\nexport namespace u8 {\n export const MIN_VALUE: u8 = 0;\n export const MAX_VALUE: u8 = 255;\n}\n\n@builtin export declare function u16(value: void): u16;\nexport namespace u16 {\n export const MIN_VALUE: u16 = 0;\n export const MAX_VALUE: u16 = 65535;\n}\n\n@builtin export declare function u32(value: void): u32;\nexport namespace u32 {\n export const MIN_VALUE: u32 = 0;\n export const MAX_VALUE: u32 = 4294967295;\n}\n\n@builtin export declare function u64(value: void): u64;\nexport namespace u64 {\n export const MIN_VALUE: u64 = 0;\n export const MAX_VALUE: u64 = 18446744073709551615;\n}\n\n@builtin export declare function usize(value: void): usize;\nexport namespace usize {\n export const MIN_VALUE: usize = 0;\n export const MAX_VALUE: usize = sizeof() == sizeof()\n ? 4294967295\n : 18446744073709551615;\n}\n\n@builtin export declare function bool(value: void): bool;\nexport namespace bool {\n export const MIN_VALUE: bool = false;\n export const MAX_VALUE: bool = true;\n}\n\n@builtin export declare function f32(value: void): f32;\nexport namespace f32 {\n export const EPSILON = reinterpret(0x34000000); // 0x1p-23f\n export const MIN_VALUE = reinterpret(0x00000001); // 0x0.000001p+0f\n export const MAX_VALUE = reinterpret(0x7F7FFFFF); // 0x1.fffffep+127f\n export const MIN_NORMAL_VALUE = reinterpret(0x00800000); // 0x1p-126f\n export const MIN_SAFE_INTEGER: f32 = -16777215;\n export const MAX_SAFE_INTEGER: f32 = 16777215;\n export const POSITIVE_INFINITY: f32 = Infinity;\n export const NEGATIVE_INFINITY: f32 = -Infinity;\n export const NaN: f32 = NaN;\n @builtin export declare function abs(value: f32): f32;\n @builtin export declare function ceil(value: f32): f32;\n @builtin export declare function copysign(x: f32, y: f32): f32;\n @builtin export declare function floor(value: f32): f32;\n @builtin export declare function load(offset: usize, constantOffset?: usize): f32;\n @builtin export declare function max(left: f32, right: f32): f32;\n @builtin export declare function min(left: f32, right: f32): f32;\n @builtin export declare function nearest(value: f32): f32;\n @builtin export declare function reinterpret_i32(value: i32): f32;\n @builtin export declare function sqrt(value: f32): f32;\n @builtin export declare function store(offset: usize, value: f32, constantOffset?: usize): void;\n @builtin export declare function trunc(value: f32): f32;\n}\n\n@builtin export declare function f64(value: void): f64;\nexport namespace f64 {\n export const EPSILON = reinterpret(0x3CB0000000000000); // 0x1p-52\n export const MIN_VALUE = reinterpret(0x0000000000000001); // 0x0.0000000000001p+0\n export const MAX_VALUE = reinterpret(0x7FEFFFFFFFFFFFFF); // 0x1.fffffffffffffp+1023\n export const MIN_NORMAL_VALUE = reinterpret(0x0010000000000000); // 0x1p-1022\n export const MIN_SAFE_INTEGER: f64 = -9007199254740991;\n export const MAX_SAFE_INTEGER: f64 = 9007199254740991;\n export const POSITIVE_INFINITY: f64 = Infinity;\n export const NEGATIVE_INFINITY: f64 = -Infinity;\n export const NaN: f64 = NaN;\n @builtin export declare function abs(value: f64): f64;\n @builtin export declare function ceil(value: f64): f64;\n @builtin export declare function copysign(x: f64, y: f64): f64;\n @builtin export declare function floor(value: f64): f64;\n @builtin export declare function load(offset: usize, constantOffset?: usize): f64;\n @builtin export declare function max(left: f64, right: f64): f64;\n @builtin export declare function min(left: f64, right: f64): f64;\n @builtin export declare function nearest(value: f64): f64;\n @builtin export declare function reinterpret_i64(value: i64): f64;\n @builtin export declare function sqrt(value: f64): f64;\n @builtin export declare function store(offset: usize, value: f64, constantOffset?: usize): void;\n @builtin export declare function trunc(value: f64): f64;\n}\n\n@builtin export declare function start(): void;\n","collector/itcm":'/**\n * Incremental Tri-Color-Marking Garbage Collector.\n *\n * @module std/assembly/collector/itcm\n *//***/\n\n// Largely based on Bach Le\'s μgc, see: https://github.com/bullno1/ugc\n\nconst TRACE = false;\n\n/** Size of a managed object header. */\nexport const HEADER_SIZE: usize = (offsetof() + AL_MASK) & ~AL_MASK;\n\nimport { AL_MASK, MAX_SIZE_32 } from "../internal/allocator";\nimport { iterateRoots } from "../gc";\n\n/** Collector states. */\nconst enum State {\n /** Not yet initialized. */\n INIT = 0,\n /** Currently transitioning from SWEEP to MARK state. */\n IDLE = 1,\n /** Currently marking reachable objects. */\n MARK = 2,\n /** Currently sweeping unreachable objects. */\n SWEEP = 3\n}\n\n/** Current collector state. */\nvar state = State.INIT;\n/** Current white color value. */\nvar white = 0;\n\n// From and to spaces\nvar fromSpace: ManagedObjectList;\nvar toSpace: ManagedObjectList;\nvar iter: ManagedObject;\n\n// ╒═══════════════ Managed object layout (32-bit) ════════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┼─┴─┤ ┐\n// │ next │0│ C │ ◄─┐ = nextWithColor\n// ├─────────────────────────────────────────────────────────┴─┴───┤ │ usize\n// │ prev │ ◄─┘\n// ├───────────────────────────────────────────────────────────────┤\n// │ hookFn │\n// ╞═══════════════════════════════════════════════════════════════╡ SIZE ┘ ◄─ user-space reference\n// │ ... data ... │\n// └───────────────────────────────────────────────────────────────┘\n// C: color\n\n/** Represents a managed object in memory, consisting of a header followed by the object\'s data. */\n@unmanaged class ManagedObject {\n\n /** Pointer to the next object with color flags stored in the alignment bits. */\n nextWithColor: usize;\n\n /** Pointer to the previous object. */\n prev: ManagedObject;\n\n /** Class-specific hook function called with the user-space reference. */\n hookFn: (ref: usize) => void;\n\n /** Gets the pointer to the next object. */\n get next(): ManagedObject {\n return changetype(this.nextWithColor & ~3);\n }\n\n /** Sets the pointer to the next object. */\n set next(obj: ManagedObject) {\n this.nextWithColor = changetype(obj) | (this.nextWithColor & 3);\n }\n\n /** Gets this object\'s color. */\n get color(): i32 {\n return this.nextWithColor & 3;\n }\n\n /** Sets this object\'s color. */\n set color(color: i32) {\n this.nextWithColor = (this.nextWithColor & ~3) | color;\n }\n\n /** Unlinks this object from its list. */\n unlink(): void {\n var next = this.next;\n var prev = this.prev;\n if (TRACE) trace(" unlink", 3, objToRef(prev), objToRef(this), objToRef(next));\n next.prev = prev;\n prev.next = next;\n }\n\n /** Marks this object as gray, that is reachable with unscanned children. */\n makeGray(): void {\n if (TRACE) trace(" makeGray", 1, objToRef(this));\n const gray = 2;\n if (this == iter) iter = this.prev;\n this.unlink();\n toSpace.push(this);\n this.nextWithColor = (this.nextWithColor & ~3) | gray;\n }\n}\n\n/** A list of managed objects. Used for the from and to spaces. */\n@unmanaged class ManagedObjectList extends ManagedObject {\n\n /** Inserts an object. */\n push(obj: ManagedObject): void {\n var prev = this.prev;\n if (TRACE) trace(" push", 3, objToRef(prev), objToRef(obj), objToRef(this));\n obj.next = this;\n obj.prev = prev;\n prev.next = obj;\n this.prev = obj;\n }\n\n /** Clears this list. */\n clear(): void {\n if (TRACE) trace(" clear", 1, objToRef(this));\n this.nextWithColor = changetype(this);\n this.prev = this;\n }\n}\n\n/** Performs a single step according to the current state. */\nfunction step(): void {\n var obj: ManagedObject;\n switch (state) {\n case State.INIT: {\n if (TRACE) trace("gc~step/INIT");\n fromSpace = changetype(memory.allocate(HEADER_SIZE));\n fromSpace.hookFn = changetype<(ref: usize) => void>(-1); // would error\n fromSpace.clear();\n toSpace = changetype(memory.allocate(HEADER_SIZE));\n toSpace.hookFn = changetype<(ref: usize) => void>(-1); // would error\n toSpace.clear();\n iter = toSpace;\n state = State.IDLE;\n if (TRACE) trace("gc~state = IDLE");\n // fall-through\n }\n case State.IDLE: {\n if (TRACE) trace("gc~step/IDLE");\n iterateRoots(__gc_mark);\n state = State.MARK;\n if (TRACE) trace("gc~state = MARK");\n break;\n }\n case State.MARK: {\n obj = iter.next;\n if (obj !== toSpace) {\n if (TRACE) trace("gc~step/MARK iterate", 1, objToRef(obj));\n iter = obj;\n obj.color = !white;\n // if (TRACE) {\n // trace(" next/prev/hook", 3,\n // changetype(obj.next),\n // changetype(obj.prev),\n // changetype(obj.hookFn)\n // );\n // }\n obj.hookFn(objToRef(obj));\n } else {\n if (TRACE) trace("gc~step/MARK finish");\n iterateRoots(__gc_mark);\n obj = iter.next;\n if (obj === toSpace) {\n let from = fromSpace;\n fromSpace = toSpace;\n toSpace = from;\n white = !white;\n iter = from.next;\n state = State.SWEEP;\n if (TRACE) trace("gc~state = SWEEP");\n }\n }\n break;\n }\n case State.SWEEP: {\n obj = iter;\n if (obj !== toSpace) {\n if (TRACE) trace("gc~step/SWEEP free", 1, objToRef(obj));\n iter = obj.next;\n if (changetype(obj) >= HEAP_BASE) memory.free(changetype(obj));\n } else {\n if (TRACE) trace("gc~step/SWEEP finish");\n toSpace.clear();\n state = State.IDLE;\n if (TRACE) trace("gc~state = IDLE");\n }\n break;\n }\n }\n}\n\n@inline function refToObj(ref: usize): ManagedObject {\n return changetype(ref - HEADER_SIZE);\n}\n\n@inline function objToRef(obj: ManagedObject): usize {\n return changetype(obj) + HEADER_SIZE;\n}\n\n// Garbage collector interface\n\n@global export function __gc_allocate(\n size: usize,\n markFn: (ref: usize) => void\n): usize {\n if (TRACE) trace("gc.allocate", 1, size);\n if (size > MAX_SIZE_32 - HEADER_SIZE) unreachable();\n step(); // also makes sure it\'s initialized\n var obj = changetype(memory.allocate(HEADER_SIZE + size));\n obj.hookFn = markFn;\n obj.color = white;\n fromSpace.push(obj);\n return objToRef(obj);\n}\n\n@global export function __gc_link(parentRef: usize, childRef: usize): void {\n if (TRACE) trace("gc.link", 2, parentRef, childRef);\n var parent = refToObj(parentRef);\n if (parent.color == !white && refToObj(childRef).color == white) parent.makeGray();\n}\n\n@global export function __gc_mark(ref: usize): void {\n if (TRACE) trace("gc.mark", 1, ref);\n if (ref) {\n let obj = refToObj(ref);\n if (obj.color == white) obj.makeGray();\n }\n}\n\n@global export function __gc_collect(): void {\n if (TRACE) trace("gc.collect");\n // begin collecting if not yet collecting\n switch (state) {\n case State.INIT:\n case State.IDLE: step();\n }\n // finish the cycle\n while (state != State.IDLE) step();\n}\n',diagnostics:"/* tslint:disable */\n\n@builtin export declare function ERROR(message?: void): void;\n@builtin export declare function WARNING(message?: void): void;\n@builtin export declare function INFO(message?: void): void;\n",env:"declare function abort(\n message?: string | null,\n fileName?: string | null,\n lineNumber?: u32,\n columnNumber?: u32\n): void;\n\ndeclare function trace(\n message: string,\n n?: i32,\n a0?: f64,\n a1?: f64,\n a2?: f64,\n a3?: f64,\n a4?: f64\n): void;\n",error:'export class Error {\n\n message: string;\n stack: string = ""; // TODO\n\n constructor(message: string = "") {\n this.message = message;\n }\n}\n\nexport class RangeError extends Error {}\nexport class TypeError extends Error {}\n',gc:"/* tslint:disable */\n\n@builtin export declare function iterateRoots(fn: (ref: usize) => void): void;\n\nexport namespace gc {\n\n export function collect(): void {\n if (isDefined(__gc_collect)) { __gc_collect(); return; }\n WARNING(\"Calling 'gc.collect' requires a garbage collector to be present.\");\n unreachable();\n }\n}\n","internal/allocator":"/** Number of alignment bits. */\nexport const AL_BITS: u32 = 3;\n/** Number of possible alignment values. */\nexport const AL_SIZE: usize = 1 << AL_BITS;\n/** Mask to obtain just the alignment bits. */\nexport const AL_MASK: usize = AL_SIZE - 1;\n/** Maximum 32-bit allocation size. */\nexport const MAX_SIZE_32: usize = 1 << 30; // 1GB\n","internal/array":"import {\n loadUnsafeWithOffset,\n storeUnsafeWithOffset\n} from \"./arraybuffer\";\n\nimport {\n compareUnsafe,\n} from \"./string\";\n\n/** Obtains the default comparator for the specified type. */\n@inline\nexport function defaultComparator(): (a: T, b: T) => i32 {\n if (isInteger()) {\n if (isSigned() && sizeof() <= 4) {\n return (a: T, b: T): i32 => ((a - b));\n } else {\n return (a: T, b: T): i32 => ((a > b) - (a < b));\n }\n } else if (isFloat()) {\n if (sizeof() == 4) {\n return (a: T, b: T): i32 => {\n var ia = reinterpret(a);\n var ib = reinterpret(b);\n ia ^= (ia >> 31) >>> 1;\n ib ^= (ib >> 31) >>> 1;\n return (ia > ib) - (ia < ib);\n };\n } else {\n return (a: T, b: T): i32 => {\n var ia = reinterpret(a);\n var ib = reinterpret(b);\n ia ^= (ia >> 63) >>> 1;\n ib ^= (ib >> 63) >>> 1;\n return (ia > ib) - (ia < ib);\n };\n }\n } else if (isString()) {\n return (a: T, b: T): i32 => {\n var sa = a, sb = b;\n return compareUnsafe(sa, 0, sb, 0, min(sa.length, sb.length));\n };\n } else {\n return (a: T, b: T): i32 => ((a > b) - (a < b));\n }\n}\n\n/** Sorts an Array with the 'Insertion Sort' algorithm. */\nexport function insertionSort(\n buffer: ArrayBuffer,\n byteOffset: i32,\n length: i32,\n comparator: (a: T, b: T) => i32\n): void {\n for (let i = 0; i < length; i++) {\n let a = loadUnsafeWithOffset(buffer, i, byteOffset); // a = arr[i]\n let j = i - 1;\n while (j >= 0) {\n let b = loadUnsafeWithOffset(buffer, j, byteOffset); // b = arr[j]\n if (comparator(a, b) < 0) {\n storeUnsafeWithOffset(buffer, j-- + 1, b, byteOffset); // arr[j + 1] = b\n } else break;\n }\n storeUnsafeWithOffset(buffer, j + 1, a, byteOffset); // arr[j + 1] = a\n }\n}\n\n/** Sorts an Array with the 'Weak Heap Sort' algorithm. */\nexport function weakHeapSort(\n buffer: ArrayBuffer,\n byteOffset: i32,\n length: i32,\n comparator: (a: T, b: T) => i32\n): void {\n const shift32 = alignof();\n\n var bitsetSize = (length + 31) >> 5 << shift32;\n var bitset = memory.allocate(bitsetSize); // indexed in 32-bit chunks below\n memory.fill(bitset, 0, bitsetSize);\n\n // see: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.21.1863&rep=rep1&type=pdf\n\n for (let i = length - 1; i > 0; i--) {\n let j = i;\n while ((j & 1) == (load(bitset + (j >> 6 << shift32)) >> (j >> 1 & 31) & 1)) j >>= 1;\n\n let p = j >> 1;\n let a = loadUnsafeWithOffset(buffer, p, byteOffset); // a = arr[p]\n let b = loadUnsafeWithOffset(buffer, i, byteOffset); // b = arr[i]\n if (comparator(a, b) < 0) {\n store(\n bitset + (i >> 5 << shift32),\n load(bitset + (i >> 5 << shift32)) ^ (1 << (i & 31))\n );\n storeUnsafeWithOffset(buffer, i, a, byteOffset); // arr[i] = a\n storeUnsafeWithOffset(buffer, p, b, byteOffset); // arr[p] = b\n }\n }\n\n for (let i = length - 1; i >= 2; i--) {\n let a = loadUnsafeWithOffset(buffer, 0, byteOffset);\n storeUnsafeWithOffset(buffer, 0, loadUnsafeWithOffset(buffer, i, byteOffset), byteOffset);\n storeUnsafeWithOffset(buffer, i, a, byteOffset);\n\n let x = 1, y: i32;\n while ((y = (x << 1) + ((load(bitset + (x >> 5 << shift32)) >> (x & 31)) & 1)) < i) x = y;\n\n while (x > 0) {\n a = loadUnsafeWithOffset(buffer, 0, byteOffset); // a = arr[0]\n let b = loadUnsafeWithOffset(buffer, x, byteOffset); // b = arr[x]\n\n if (comparator(a, b) < 0) {\n store(\n bitset + (x >> 5 << shift32),\n load(bitset + (x >> 5 << shift32)) ^ (1 << (x & 31))\n );\n storeUnsafeWithOffset(buffer, x, a, byteOffset); // arr[x] = a\n storeUnsafeWithOffset(buffer, 0, b, byteOffset); // arr[0] = b\n }\n x >>= 1;\n }\n }\n\n memory.free(bitset);\n\n var t = loadUnsafeWithOffset(buffer, 1, byteOffset); // t = arr[1]\n storeUnsafeWithOffset(buffer, 1, loadUnsafeWithOffset(buffer, 0, byteOffset), byteOffset);\n storeUnsafeWithOffset(buffer, 0, t, byteOffset); // arr[0] = t\n}\n","internal/arraybuffer":'import { AL_MASK, MAX_SIZE_32 } from "./allocator";\n\n/** Size of an ArrayBuffer header. */\nexport const HEADER_SIZE: usize = (offsetof() + AL_MASK) & ~AL_MASK;\n/** Maximum byte length of an ArrayBuffer. */\nexport const MAX_BLENGTH: i32 = MAX_SIZE_32 - HEADER_SIZE;\n\nfunction computeSize(byteLength: i32): usize {\n // round up to power of 2, with HEADER_SIZE=8:\n // 0 -> 2^3 = 8\n // 1..8 -> 2^4 = 16\n // 9..24 -> 2^5 = 32\n // ...\n // MAX_LENGTH -> 2^30 = 0x40000000 (MAX_SIZE_32)\n return 1 << (32 - clz(byteLength + HEADER_SIZE - 1));\n}\n\n// Low-level utility\n\nfunction __gc(ref: usize): void {}\n\nexport function allocateUnsafe(byteLength: i32): ArrayBuffer {\n assert(byteLength <= MAX_BLENGTH);\n var buffer: usize;\n if (isManaged()) {\n buffer = __gc_allocate(computeSize(byteLength), __gc); // tslint:disable-line\n } else {\n buffer = memory.allocate(computeSize(byteLength));\n }\n store(buffer, byteLength, offsetof("byteLength"));\n return changetype(buffer);\n}\n\nexport function reallocateUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuffer {\n var oldByteLength = buffer.byteLength;\n if (newByteLength > oldByteLength) {\n assert(newByteLength <= MAX_BLENGTH);\n if (newByteLength <= (computeSize(oldByteLength) - HEADER_SIZE)) { // fast path: zero out additional space\n store(changetype(buffer), newByteLength, offsetof("byteLength"));\n memory.fill(\n changetype(buffer) + HEADER_SIZE + oldByteLength,\n 0,\n (newByteLength - oldByteLength)\n );\n } else { // slow path: copy to new buffer\n let newBuffer = allocateUnsafe(newByteLength);\n memory.copy(\n changetype(newBuffer) + HEADER_SIZE,\n changetype(buffer) + HEADER_SIZE,\n oldByteLength\n );\n memory.fill(\n changetype(newBuffer) + HEADER_SIZE + oldByteLength,\n 0,\n (newByteLength - oldByteLength)\n );\n return newBuffer;\n }\n } else if (newByteLength < oldByteLength) { // fast path: override size\n // TBD: worth to copy and release if size is significantly less than before?\n assert(newByteLength >= 0);\n store(changetype(buffer), newByteLength, offsetof("byteLength"));\n }\n return buffer;\n}\n\n@inline export function loadUnsafe(buffer: ArrayBuffer, index: i32): V {\n return load(changetype(buffer) + (index << alignof()), HEADER_SIZE);\n}\n\n@inline export function storeUnsafe(buffer: ArrayBuffer, index: i32, value: V): void {\n store(changetype(buffer) + (index << alignof()), value, HEADER_SIZE);\n}\n\n@inline export function loadUnsafeWithOffset(buffer: ArrayBuffer, index: i32, byteOffset: i32): V {\n return load(changetype(buffer) + byteOffset + (index << alignof()), HEADER_SIZE);\n}\n\n@inline export function storeUnsafeWithOffset(buffer: ArrayBuffer, index: i32, value: V, byteOffset: i32): void {\n store(changetype(buffer) + byteOffset + (index << alignof()), value, HEADER_SIZE);\n}\n',"internal/hash":'import {\n HEADER_SIZE as STRING_HEADER_SIZE\n} from "./string";\n\n/** Computes the 32-bit hash of a value of any type. */\n@inline\nexport function hash(key: T): u32 {\n // branch-level tree-shaking makes this a `(return (call ...))`\n if (isString(key)) {\n return hashStr(key);\n } else if (isReference()) {\n if (sizeof() == 4) return hash32(changetype(key));\n if (sizeof() == 8) return hash64(changetype(key));\n } else if (isFloat()) {\n if (sizeof() == 4) return hash32(reinterpret(key));\n if (sizeof() == 8) return hash64(reinterpret(key));\n } else {\n if (sizeof() == 1) return hash8 (key);\n if (sizeof() == 2) return hash16(key);\n if (sizeof() == 4) return hash32(key);\n if (sizeof() == 8) return hash64(key);\n }\n unreachable();\n}\n\n// FNV-1a 32-bit as a starting point, see: http://isthe.com/chongo/tech/comp/fnv/\n\nconst FNV_OFFSET: u32 = 2166136261;\nconst FNV_PRIME: u32 = 16777619;\n\nfunction hash8(key: u32): u32 {\n return (FNV_OFFSET ^ key) * FNV_PRIME;\n}\n\nfunction hash16(key: u32): u32 {\n var v = FNV_OFFSET;\n v = (v ^ ( key & 0xff)) * FNV_PRIME;\n v = (v ^ ( key >> 8 )) * FNV_PRIME;\n return v;\n}\n\nfunction hash32(key: u32): u32 {\n var v = FNV_OFFSET;\n v = (v ^ ( key & 0xff)) * FNV_PRIME;\n v = (v ^ ((key >> 8) & 0xff)) * FNV_PRIME;\n v = (v ^ ((key >> 16) & 0xff)) * FNV_PRIME;\n v = (v ^ ( key >> 24 )) * FNV_PRIME;\n return v;\n}\n\nfunction hash64(key: u64): u32 {\n var l = key;\n var h = (key >>> 32);\n var v = FNV_OFFSET;\n v = (v ^ ( l & 0xff)) * FNV_PRIME;\n v = (v ^ ((l >> 8) & 0xff)) * FNV_PRIME;\n v = (v ^ ((l >> 16) & 0xff)) * FNV_PRIME;\n v = (v ^ ( l >> 24 )) * FNV_PRIME;\n v = (v ^ ( h & 0xff)) * FNV_PRIME;\n v = (v ^ ((h >> 8) & 0xff)) * FNV_PRIME;\n v = (v ^ ((h >> 16) & 0xff)) * FNV_PRIME;\n v = (v ^ ( h >> 24 )) * FNV_PRIME;\n return v;\n}\n\nfunction hashStr(key: string): u32 {\n var v = FNV_OFFSET;\n for (let i: usize = 0, k: usize = key.length << 1; i < k; ++i) {\n v = (v ^ load(changetype(key) + i, STRING_HEADER_SIZE)) * FNV_PRIME;\n }\n return v;\n}\n',"internal/memory":"// this function will go away once `memory.copy` becomes an intrinsic\nexport function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memcpy.c\n var w: u32, x: u32;\n\n // copy 1 byte each until src is aligned to 4 bytes\n while (n && (src & 3)) {\n store(dest++, load(src++));\n n--;\n }\n\n // if dst is aligned to 4 bytes as well, copy 4 bytes each\n if ((dest & 3) == 0) {\n while (n >= 16) {\n store(dest , load(src ));\n store(dest + 4, load(src + 4));\n store(dest + 8, load(src + 8));\n store(dest + 12, load(src + 12));\n src += 16; dest += 16; n -= 16;\n }\n if (n & 8) {\n store(dest , load(src ));\n store(dest + 4, load(src + 4));\n dest += 8; src += 8;\n }\n if (n & 4) {\n store(dest, load(src));\n dest += 4; src += 4;\n }\n if (n & 2) { // drop to 2 bytes each\n store(dest, load(src));\n dest += 2; src += 2;\n }\n if (n & 1) { // drop to 1 byte\n store(dest++, load(src++));\n }\n return;\n }\n\n // if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each\n // doing shifts if faster when copying enough bytes (here: 32 or more)\n if (n >= 32) {\n switch (dest & 3) {\n // known to be != 0\n case 1: {\n w = load(src);\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n n -= 3;\n while (n >= 17) {\n x = load(src + 1);\n store(dest, w >> 24 | x << 8);\n w = load(src + 5);\n store(dest + 4, x >> 24 | w << 8);\n x = load(src + 9);\n store(dest + 8, w >> 24 | x << 8);\n w = load(src + 13);\n store(dest + 12, x >> 24 | w << 8);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 2: {\n w = load(src);\n store(dest++, load(src++));\n store(dest++, load(src++));\n n -= 2;\n while (n >= 18) {\n x = load(src + 2);\n store(dest, w >> 16 | x << 16);\n w = load(src + 6);\n store(dest + 4, x >> 16 | w << 16);\n x = load(src + 10);\n store(dest + 8, w >> 16 | x << 16);\n w = load(src + 14);\n store(dest + 12, x >> 16 | w << 16);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 3: {\n w = load(src);\n store(dest++, load(src++));\n n -= 1;\n while (n >= 19) {\n x = load(src + 3);\n store(dest, w >> 8 | x << 24);\n w = load(src + 7);\n store(dest + 4, x >> 8 | w << 24);\n x = load(src + 11);\n store(dest + 8, w >> 8 | x << 24);\n w = load(src + 15);\n store(dest + 12, x >> 8 | w << 24);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n }\n }\n\n // copy remaining bytes one by one\n if (n & 16) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 8) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 4) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 2) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 1) {\n store(dest++, load(src++));\n }\n}\n\n// this function will go away once `memory.copy` becomes an intrinsic\nexport function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c\n if (dest == src) return;\n if (src + n <= dest || dest + n <= src) {\n memcpy(dest, src, n);\n return;\n }\n if (dest < src) {\n if ((src & 7) == (dest & 7)) {\n while (dest & 7) {\n if (!n) return;\n --n;\n store(dest++, load(src++));\n }\n while (n >= 8) {\n store(dest, load(src));\n n -= 8;\n dest += 8;\n src += 8;\n }\n }\n while (n) {\n store(dest++, load(src++));\n --n;\n }\n } else {\n if ((src & 7) == (dest & 7)) {\n while ((dest + n) & 7) {\n if (!n) return;\n store(dest + --n, load(src + n));\n }\n while (n >= 8) {\n n -= 8;\n store(dest + n, load(src + n));\n }\n }\n while (n) {\n store(dest + --n, load(src + n));\n }\n }\n}\n\n// this function will go away once `memory.fill` becomes an intrinsic\nexport function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset\n\n // fill head and tail with minimal branching\n if (!n) return;\n store(dest, c);\n store(dest + n - 1, c);\n if (n <= 2) return;\n\n store(dest + 1, c);\n store(dest + 2, c);\n store(dest + n - 2, c);\n store(dest + n - 3, c);\n if (n <= 6) return;\n store(dest + 3, c);\n store(dest + n - 4, c);\n if (n <= 8) return;\n\n // advance pointer to align it at 4-byte boundary\n var k: usize = -dest & 3;\n dest += k;\n n -= k;\n n &= -4;\n\n var c32: u32 = -1 / 255 * c;\n\n // fill head/tail up to 28 bytes each in preparation\n store(dest, c32);\n store(dest + n - 4, c32);\n if (n <= 8) return;\n store(dest + 4, c32);\n store(dest + 8, c32);\n store(dest + n - 12, c32);\n store(dest + n - 8, c32);\n if (n <= 24) return;\n store(dest + 12, c32);\n store(dest + 16, c32);\n store(dest + 20, c32);\n store(dest + 24, c32);\n store(dest + n - 28, c32);\n store(dest + n - 24, c32);\n store(dest + n - 20, c32);\n store(dest + n - 16, c32);\n\n // align to a multiple of 8\n k = 24 + (dest & 4);\n dest += k;\n n -= k;\n\n // copy 32 bytes each\n var c64: u64 = c32 | (c32 << 32);\n while (n >= 32) {\n store(dest, c64);\n store(dest + 8, c64);\n store(dest + 16, c64);\n store(dest + 24, c64);\n n -= 32;\n dest += 32;\n }\n}\n\nexport function memcmp(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c\n if (vl == vr) return 0;\n while (n != 0 && load(vl) == load(vr)) {\n n--; vl++; vr++;\n }\n return n ? load(vl) - load(vr) : 0;\n}\n","internal/number":'\nimport {\n CharCode,\n allocateUnsafe as allocateUnsafeString,\n freeUnsafe as freeUnsafeString,\n HEADER_SIZE as STRING_HEADER_SIZE\n} from "./string";\n\nimport {\n loadUnsafe\n} from "./arraybuffer";\n\nexport const MAX_DOUBLE_LENGTH = 28;\n\n@inline\nexport function POWERS10(): u32[] {\n const table: u32[] = [\n 1,\n 10,\n 100,\n 1000,\n 10000,\n 100000,\n 1000000,\n 10000000,\n 100000000,\n 1000000000\n ];\n return table; // inlines to a constant memory offset\n}\n\n/*\n Lookup table for pairwise char codes in range [0-99]\n\n "00", "01", "02", "03", "04", "05", "06", "07", "08", "09",\n "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",\n "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",\n "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",\n "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",\n "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",\n "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",\n "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",\n "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",\n "90", "91", "92", "93", "94", "95", "96", "97", "98", "99"\n*/\n@inline\nexport function DIGITS(): u32[] {\n const table: u32[] = [\n 0x00300030, 0x00310030, 0x00320030, 0x00330030, 0x00340030,\n 0x00350030, 0x00360030, 0x00370030, 0x00380030, 0x00390030,\n 0x00300031, 0x00310031, 0x00320031, 0x00330031, 0x00340031,\n 0x00350031, 0x00360031, 0x00370031, 0x00380031, 0x00390031,\n 0x00300032, 0x00310032, 0x00320032, 0x00330032, 0x00340032,\n 0x00350032, 0x00360032, 0x00370032, 0x00380032, 0x00390032,\n 0x00300033, 0x00310033, 0x00320033, 0x00330033, 0x00340033,\n 0x00350033, 0x00360033, 0x00370033, 0x00380033, 0x00390033,\n 0x00300034, 0x00310034, 0x00320034, 0x00330034, 0x00340034,\n 0x00350034, 0x00360034, 0x00370034, 0x00380034, 0x00390034,\n 0x00300035, 0x00310035, 0x00320035, 0x00330035, 0x00340035,\n 0x00350035, 0x00360035, 0x00370035, 0x00380035, 0x00390035,\n 0x00300036, 0x00310036, 0x00320036, 0x00330036, 0x00340036,\n 0x00350036, 0x00360036, 0x00370036, 0x00380036, 0x00390036,\n 0x00300037, 0x00310037, 0x00320037, 0x00330037, 0x00340037,\n 0x00350037, 0x00360037, 0x00370037, 0x00380037, 0x00390037,\n 0x00300038, 0x00310038, 0x00320038, 0x00330038, 0x00340038,\n 0x00350038, 0x00360038, 0x00370038, 0x00380038, 0x00390038,\n 0x00300039, 0x00310039, 0x00320039, 0x00330039, 0x00340039,\n 0x00350039, 0x00360039, 0x00370039, 0x00380039, 0x00390039\n ];\n return table; // inlines to a constant memory offset\n}\n\n@inline\nfunction EXP_POWERS(): i16[] {\n const table: i16[] = [\n -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,\n -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,\n -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,\n -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,\n -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,\n 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,\n 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,\n 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,\n 907, 933, 960, 986, 1013, 1039, 1066\n ];\n return table;\n}\n\n// 1e-348, 1e-340, ..., 1e340\n@inline\nfunction FRC_POWERS(): u64[] {\n const table: u64[] = [\n 0xFA8FD5A0081C0288, 0xBAAEE17FA23EBF76, 0x8B16FB203055AC76, 0xCF42894A5DCE35EA,\n 0x9A6BB0AA55653B2D, 0xE61ACF033D1A45DF, 0xAB70FE17C79AC6CA, 0xFF77B1FCBEBCDC4F,\n 0xBE5691EF416BD60C, 0x8DD01FAD907FFC3C, 0xD3515C2831559A83, 0x9D71AC8FADA6C9B5,\n 0xEA9C227723EE8BCB, 0xAECC49914078536D, 0x823C12795DB6CE57, 0xC21094364DFB5637,\n 0x9096EA6F3848984F, 0xD77485CB25823AC7, 0xA086CFCD97BF97F4, 0xEF340A98172AACE5,\n 0xB23867FB2A35B28E, 0x84C8D4DFD2C63F3B, 0xC5DD44271AD3CDBA, 0x936B9FCEBB25C996,\n 0xDBAC6C247D62A584, 0xA3AB66580D5FDAF6, 0xF3E2F893DEC3F126, 0xB5B5ADA8AAFF80B8,\n 0x87625F056C7C4A8B, 0xC9BCFF6034C13053, 0x964E858C91BA2655, 0xDFF9772470297EBD,\n 0xA6DFBD9FB8E5B88F, 0xF8A95FCF88747D94, 0xB94470938FA89BCF, 0x8A08F0F8BF0F156B,\n 0xCDB02555653131B6, 0x993FE2C6D07B7FAC, 0xE45C10C42A2B3B06, 0xAA242499697392D3,\n 0xFD87B5F28300CA0E, 0xBCE5086492111AEB, 0x8CBCCC096F5088CC, 0xD1B71758E219652C,\n 0x9C40000000000000, 0xE8D4A51000000000, 0xAD78EBC5AC620000, 0x813F3978F8940984,\n 0xC097CE7BC90715B3, 0x8F7E32CE7BEA5C70, 0xD5D238A4ABE98068, 0x9F4F2726179A2245,\n 0xED63A231D4C4FB27, 0xB0DE65388CC8ADA8, 0x83C7088E1AAB65DB, 0xC45D1DF942711D9A,\n 0x924D692CA61BE758, 0xDA01EE641A708DEA, 0xA26DA3999AEF774A, 0xF209787BB47D6B85,\n 0xB454E4A179DD1877, 0x865B86925B9BC5C2, 0xC83553C5C8965D3D, 0x952AB45CFA97A0B3,\n 0xDE469FBD99A05FE3, 0xA59BC234DB398C25, 0xF6C69A72A3989F5C, 0xB7DCBF5354E9BECE,\n 0x88FCF317F22241E2, 0xCC20CE9BD35C78A5, 0x98165AF37B2153DF, 0xE2A0B5DC971F303A,\n 0xA8D9D1535CE3B396, 0xFB9B7CD9A4A7443C, 0xBB764C4CA7A44410, 0x8BAB8EEFB6409C1A,\n 0xD01FEF10A657842C, 0x9B10A4E5E9913129, 0xE7109BFBA19C0C9D, 0xAC2820D9623BF429,\n 0x80444B5E7AA7CF85, 0xBF21E44003ACDD2D, 0x8E679C2F5E44FF8F, 0xD433179D9C8CB841,\n 0x9E19DB92B4E31BA9, 0xEB96BF6EBADF77D9, 0xAF87023B9BF0EE6B\n ];\n return table;\n}\n\n// Count number of decimals for u32 values\n// In our case input value always non-zero so we can simplify some parts\nexport function decimalCount32(value: u32): u32 {\n if (ASC_SHRINK_LEVEL >= 1) {\n let l: u32 = 32 - clz(value); // log2\n let t = l * 1233 >>> 12; // log10\n\n let lutbuf = POWERS10().buffer_;\n let power = loadUnsafe(lutbuf, t);\n t -= (value < power);\n return t + 1;\n } else {\n if (value < 100000) {\n if (value < 100) {\n return select(1, 2, value < 10);\n } else {\n let m = select(4, 5, value < 10000);\n return select(3, m, value < 1000);\n }\n } else {\n if (value < 10000000) {\n return select(6, 7, value < 1000000);\n } else {\n let m = select(9, 10, value < 1000000000);\n return select(8, m, value < 100000000);\n }\n }\n }\n}\n\n// Count number of decimals for u64 values\n// In our case input value always greater than 2^32-1 so we can skip some parts\nexport function decimalCount64(value: u64): u32 {\n if (ASC_SHRINK_LEVEL >= 1) {\n let l: u32 = 64 - clz(value); // log2\n let t = l * 1233 >>> 12; // log10\n\n let lutbuf = POWERS10().buffer_;\n let power = loadUnsafe(lutbuf, t - 10);\n t -= (value < 10000000000 * power);\n return t + 1;\n } else {\n if (value < 1000000000000000) {\n if (value < 1000000000000) {\n return select(11, 12, value < 100000000000);\n } else {\n let m = select(14, 15, value < 100000000000000);\n return select(13, m, value < 10000000000000);\n }\n } else {\n if (value < 100000000000000000) {\n return select(16, 17, value < 10000000000000000);\n } else {\n let m = select(19, 20, value < 10000000000000000000);\n return select(18, m, value < 1000000000000000000);\n }\n }\n }\n}\n\nfunction utoa32_lut(buffer: usize, num: u32, offset: usize): void {\n var lutbuf = DIGITS().buffer_;\n\n while (num >= 10000) {\n // in most VMs i32/u32 div and modulo by constant can be shared and simplificate\n let t = num / 10000;\n let r = num % 10000;\n num = t;\n\n let d1 = r / 100;\n let d2 = r % 100;\n\n let digits1 = loadUnsafe(lutbuf, d1);\n let digits2 = loadUnsafe(lutbuf, d2);\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32), STRING_HEADER_SIZE);\n }\n\n if (num >= 100) {\n let t = num / 100;\n let d1 = num % 100;\n num = t;\n offset -= 2;\n let digits = loadUnsafe(lutbuf, d1);\n store(buffer + (offset << 1), digits, STRING_HEADER_SIZE);\n }\n\n if (num >= 10) {\n offset -= 2;\n let digits = loadUnsafe(lutbuf, num);\n store(buffer + (offset << 1), digits, STRING_HEADER_SIZE);\n } else {\n offset -= 1;\n let digit = CharCode._0 + num;\n store(buffer + (offset << 1), digit, STRING_HEADER_SIZE);\n }\n}\n\nfunction utoa64_lut(buffer: usize, num: u64, offset: usize): void {\n var lutbuf = DIGITS().buffer_;\n\n while (num >= 100000000) {\n let t = num / 100000000;\n let r = (num - t * 100000000);\n num = t;\n\n let b = r / 10000;\n let c = r % 10000;\n\n let b1 = b / 100;\n let b2 = b % 100;\n let c1 = c / 100;\n let c2 = c % 100;\n\n let digits1 = loadUnsafe(lutbuf, c1);\n let digits2 = loadUnsafe(lutbuf, c2);\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32), STRING_HEADER_SIZE);\n\n digits1 = loadUnsafe(lutbuf, b1);\n digits2 = loadUnsafe(lutbuf, b2);\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32), STRING_HEADER_SIZE);\n }\n\n utoa32_lut(buffer, num, offset);\n}\n\nfunction utoa_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let t = num / 10;\n let r = (num % 10);\n num = t;\n offset -= 1;\n store(buffer + (offset << 1), CharCode._0 + r, STRING_HEADER_SIZE);\n } while (num);\n}\n\n@inline\nexport function utoa32_core(buffer: usize, num: u32, offset: u32): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_simple(buffer, num, offset);\n } else {\n utoa32_lut(buffer, num, offset);\n }\n}\n\n@inline\nexport function utoa64_core(buffer: usize, num: u64, offset: u32): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_simple(buffer, num, offset);\n } else {\n utoa64_lut(buffer, num, offset);\n }\n}\n\nexport function utoa32(value: u32): String {\n if (!value) return "0";\n\n var decimals = decimalCount32(value);\n var buffer = allocateUnsafeString(decimals);\n\n utoa32_core(changetype(buffer), value, decimals);\n return buffer;\n}\n\nexport function itoa32(value: i32): String {\n if (!value) return "0";\n\n var sign = value < 0;\n if (sign) value = -value;\n\n var decimals = decimalCount32(value) + sign;\n var buffer = allocateUnsafeString(decimals);\n\n utoa32_core(changetype(buffer), value, decimals);\n if (sign) store(changetype(buffer), CharCode.MINUS, STRING_HEADER_SIZE);\n\n return buffer;\n}\n\nexport function utoa64(value: u64): String {\n if (!value) return "0";\n\n var buffer: String;\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n buffer = allocateUnsafeString(decimals);\n utoa32_core(changetype(buffer), val32, decimals);\n } else {\n let decimals = decimalCount64(value);\n buffer = allocateUnsafeString(decimals);\n utoa64_core(changetype(buffer), value, decimals);\n }\n return buffer;\n}\n\nexport function itoa64(value: i64): String {\n if (!value) return "0";\n\n var sign = value < 0;\n if (sign) value = -value;\n\n var buffer: String;\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32) + sign;\n buffer = allocateUnsafeString(decimals);\n utoa32_core(changetype(buffer), val32, decimals);\n } else {\n let decimals = decimalCount64(value) + sign;\n buffer = allocateUnsafeString(decimals);\n utoa64_core(changetype(buffer), value, decimals);\n }\n if (sign) store(changetype(buffer), CharCode.MINUS, STRING_HEADER_SIZE);\n\n return buffer;\n}\n\nexport function itoa(value: T): String {\n if (!isInteger()) {\n assert(false); // unexpecteble non-integer generic type\n } else {\n if (isSigned()) {\n if (sizeof() <= 4) {\n return itoa32(value);\n } else {\n return itoa64(value);\n }\n } else {\n if (sizeof() <= 4) {\n return utoa32(value);\n } else {\n return utoa64(value);\n }\n }\n }\n}\n\nvar _K: i32 = 0;\n\nvar _frc: u64 = 0;\nvar _exp: i32 = 0;\n\nvar _frc_minus: u64 = 0;\nvar _frc_plus: u64 = 0;\n\nvar _frc_pow: u64 = 0;\nvar _exp_pow: i32 = 0;\n\n@inline\nfunction umul64f(u: u64, v: u64): u64 {\n var u0 = u & 0xFFFFFFFF;\n var v0 = v & 0xFFFFFFFF;\n\n var u1 = u >> 32;\n var v1 = v >> 32;\n\n var l = u0 * v0;\n var t = u1 * v0 + (l >> 32);\n var w = u0 * v1 + (t & 0xFFFFFFFF);\n\n w += 0x7FFFFFFF; // rounding\n\n t >>= 32;\n w >>= 32;\n\n return u1 * v1 + t + w;\n}\n\n@inline\nfunction umul64e(e1: i32, e2: i32): i32 {\n return e1 + e2 + 64; // where 64 is significand size\n}\n\n@inline\nfunction normalizedBoundaries(f: u64, e: i32): void {\n var frc = (f << 1) + 1;\n var exp = e - 1;\n var off = clz(frc);\n frc <<= off;\n exp -= off;\n\n var m = 1 + (f == 0x0010000000000000);\n\n _frc_plus = frc;\n _frc_minus = ((f << m) - 1) << e - m - exp;\n _exp = exp;\n}\n\n@inline\nfunction grisuRound(buffer: usize, len: i32, delta: u64, rest: u64, ten_kappa: u64, wp_w: u64): void {\n var lastp = buffer + ((len - 1) << 1);\n var digit = load(lastp, STRING_HEADER_SIZE);\n while (\n rest < wp_w &&\n delta - rest >= ten_kappa && (\n rest + ten_kappa < wp_w ||\n wp_w - rest > rest + ten_kappa - wp_w\n )\n ) {\n --digit;\n rest += ten_kappa;\n }\n store(lastp, digit, STRING_HEADER_SIZE);\n}\n\n@inline\nfunction getCachedPower(minExp: i32): void {\n const c = reinterpret(0x3FD34413509F79FE); // 1 / lg(10) = 0.30102999566398114\n var dk = (-61 - minExp) * c + 347;\t // dk must be positive, so can do ceiling in positive\n var k = dk;\n k += (k != dk); // conversion with ceil\n\n var index = (k >> 3) + 1;\n _K = 348 - (index << 3);\t// decimal exponent no need lookup table\n var frcPowers = FRC_POWERS().buffer_;\n var expPowers = EXP_POWERS().buffer_;\n _frc_pow = loadUnsafe(frcPowers, index);\n _exp_pow = loadUnsafe(expPowers, index);\n}\n\n@inline\nfunction grisu2(value: f64, buffer: usize, sign: i32): i32 {\n\n // frexp routine\n var uv = reinterpret(value);\n var exp = ((uv & 0x7FF0000000000000) >>> 52);\n var sid = uv & 0x000FFFFFFFFFFFFF;\n var frc = ((exp != 0) << 52) + sid;\n exp = select(exp, 1, exp != 0) - (0x3FF + 52);\n\n normalizedBoundaries(frc, exp);\n getCachedPower(_exp);\n\n // normalize\n var off = clz(frc);\n frc <<= off;\n exp -= off;\n\n var frc_pow = _frc_pow;\n var exp_pow = _exp_pow;\n\n var w_frc = umul64f(frc, frc_pow);\n var w_exp = umul64e(exp, exp_pow);\n\n var wp_frc = umul64f(_frc_plus, frc_pow) - 1;\n var wp_exp = umul64e(_exp, exp_pow);\n\n var wm_frc = umul64f(_frc_minus, frc_pow) + 1;\n var delta = wp_frc - wm_frc;\n\n return genDigits(buffer, w_frc, w_exp, wp_frc, wp_exp, delta, sign);\n}\n\nfunction genDigits(buffer: usize, w_frc: u64, w_exp: i32, mp_frc: u64, mp_exp: i32, delta: u64, sign: i32): i32 {\n var one_exp = -mp_exp;\n var one_frc = (1) << one_exp;\n var mask = one_frc - 1;\n\n var wp_w_frc = mp_frc - w_frc;\n var wp_w_exp = mp_exp;\n\n var p1 = (mp_frc >> one_exp);\n var p2 = mp_frc & mask;\n\n var kappa = decimalCount32(p1);\n var len = sign;\n\n var powers10 = POWERS10().buffer_;\n\n while (kappa > 0) {\n let d: u32;\n switch (kappa) {\n case 10: { d = p1 / 1000000000; p1 %= 1000000000; break; }\n case 9: { d = p1 / 100000000; p1 %= 100000000; break; }\n case 8: { d = p1 / 10000000; p1 %= 10000000; break; }\n case 7: { d = p1 / 1000000; p1 %= 1000000; break; }\n case 6: { d = p1 / 100000; p1 %= 100000; break; }\n case 5: { d = p1 / 10000; p1 %= 10000; break; }\n case 4: { d = p1 / 1000; p1 %= 1000; break; }\n case 3: { d = p1 / 100; p1 %= 100; break; }\n case 2: { d = p1 / 10; p1 %= 10; break; }\n case 1: { d = p1; p1 = 0; break; }\n default: { d = 0; break; }\n }\n\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d, STRING_HEADER_SIZE);\n\n --kappa;\n let tmp = ((p1) << one_exp) + p2;\n if (tmp <= delta) {\n _K += kappa;\n grisuRound(buffer, len, delta, tmp, loadUnsafe(powers10, kappa) << one_exp, wp_w_frc);\n return len;\n }\n }\n\n while (1) {\n p2 *= 10;\n delta *= 10;\n\n let d = p2 >> one_exp;\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d, STRING_HEADER_SIZE);\n\n p2 &= mask;\n --kappa;\n if (p2 < delta) {\n _K += kappa;\n wp_w_frc *= loadUnsafe(powers10, -kappa);\n grisuRound(buffer, len, delta, p2, one_frc, wp_w_frc);\n return len;\n }\n }\n\n return len;\n}\n\n@inline\nfunction genExponent(buffer: usize, k: i32): i32 {\n var sign = k < 0;\n if (sign) k = -k;\n var decimals = decimalCount32(k) + 1;\n utoa32_core(buffer, k, decimals);\n store(buffer, select(CharCode.MINUS, CharCode.PLUS, sign), STRING_HEADER_SIZE);\n return decimals;\n}\n\nfunction prettify(buffer: usize, length: i32, k: i32): i32 {\n if (!k) {\n store(buffer + (length << 1), CharCode.DOT | (CharCode._0 << 16), STRING_HEADER_SIZE);\n return length + 2;\n }\n\n var kk = length + k;\n if (length <= kk && kk <= 21) {\n // 1234e7 -> 12340000000\n for (let i = length; i < kk; ++i) {\n store(buffer + (i << 1), CharCode._0, STRING_HEADER_SIZE);\n }\n store(buffer + (kk << 1), CharCode.DOT | (CharCode._0 << 16), STRING_HEADER_SIZE);\n return kk + 2;\n } else if (kk > 0 && kk <= 21) {\n // 1234e-2 -> 12.34\n let ptr = buffer + (kk << 1);\n memory.copy(\n ptr + STRING_HEADER_SIZE + 2,\n ptr + STRING_HEADER_SIZE,\n -k << 1\n );\n store(buffer + (kk << 1), CharCode.DOT, STRING_HEADER_SIZE);\n return length + 1;\n } else if (-6 < kk && kk <= 0) {\n // 1234e-6 -> 0.001234\n let offset = 2 - kk;\n memory.copy(\n buffer + STRING_HEADER_SIZE + (offset << 1),\n buffer + STRING_HEADER_SIZE,\n length << 1\n );\n store(buffer, CharCode._0 | (CharCode.DOT << 16), STRING_HEADER_SIZE);\n for (let i = 2; i < offset; ++i) {\n store(buffer + (i << 1), CharCode._0, STRING_HEADER_SIZE);\n }\n return length + offset;\n } else if (length == 1) {\n // 1e30\n store(buffer, CharCode.e, STRING_HEADER_SIZE + 2);\n length = genExponent(buffer + 4, kk - 1);\n return length + 2;\n } else {\n let len = length << 1;\n memory.copy(\n buffer + STRING_HEADER_SIZE + 4,\n buffer + STRING_HEADER_SIZE + 2,\n len - 2\n );\n store(buffer, CharCode.DOT, STRING_HEADER_SIZE + 2);\n store(buffer + len, CharCode.e, STRING_HEADER_SIZE + 2);\n length += genExponent(buffer + len + 4, kk - 1);\n return length + 2;\n }\n}\n\nexport function dtoa_core(buffer: usize, value: f64): i32 {\n var sign = (value < 0);\n if (sign) {\n value = -value;\n store(buffer, CharCode.MINUS, STRING_HEADER_SIZE);\n }\n // assert(value > 0 && value <= 1.7976931348623157e308);\n var len = grisu2(value, buffer, sign);\n len = prettify(buffer + (sign << 1), len - sign, _K);\n return len + sign;\n}\n\nexport function dtoa(value: f64): String {\n if (value == 0) return "0.0";\n if (!isFinite(value)) {\n if (isNaN(value)) return "NaN";\n return select("-Infinity", "Infinity", value < 0);\n }\n var buffer = allocateUnsafeString(MAX_DOUBLE_LENGTH);\n var length = dtoa_core(changetype(buffer), value);\n var result = buffer.substring(0, length);\n freeUnsafeString(buffer);\n return result;\n}\n\nexport function itoa_stream(buffer: usize, offset: usize, value: T): u32 {\n buffer += (offset << 1);\n if (!value) {\n store(buffer, CharCode._0, STRING_HEADER_SIZE);\n return 1;\n }\n var decimals: u32 = 0;\n if (isSigned()) {\n let sign = value < 0;\n if (sign) value = -value;\n if (sizeof() <= 4) {\n decimals = decimalCount32(value) + sign;\n utoa32_core(buffer, value, decimals);\n } else {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n decimals = decimalCount32(val32) + sign;\n utoa32_core(buffer, val32, decimals);\n } else {\n decimals = decimalCount64(value) + sign;\n utoa64_core(buffer, value, decimals);\n }\n }\n if (sign) store(buffer, CharCode.MINUS, STRING_HEADER_SIZE);\n } else {\n if (sizeof() <= 4) {\n decimals = decimalCount32(value);\n utoa32_core(buffer, value, decimals);\n } else {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_core(buffer, val32, decimals);\n } else {\n decimals = decimalCount64(value);\n utoa64_core(buffer, value, decimals);\n }\n }\n }\n return decimals;\n}\n\nexport function dtoa_stream(buffer: usize, offset: usize, value: f64): u32 {\n buffer += (offset << 1);\n if (value == 0.0) {\n store(buffer, CharCode._0, STRING_HEADER_SIZE + 0);\n store(buffer, CharCode.DOT, STRING_HEADER_SIZE + 2);\n store(buffer, CharCode._0, STRING_HEADER_SIZE + 4);\n return 3;\n }\n if (!isFinite(value)) {\n if (isNaN(value)) {\n store(buffer, CharCode.N, STRING_HEADER_SIZE + 0);\n store(buffer, CharCode.a, STRING_HEADER_SIZE + 2);\n store(buffer, CharCode.N, STRING_HEADER_SIZE + 4);\n return 3;\n } else {\n let sign = (value < 0);\n let len = 8 + sign;\n let source = changetype(select("-Infinity", "Infinity", sign));\n memory.copy(buffer + STRING_HEADER_SIZE, source, len << 1);\n return len;\n }\n }\n return dtoa_core(buffer, value);\n}\n',"internal/string":'import { MAX_SIZE_32 } from "./allocator";\nimport { String } from "../string";\n\n/** Size of a String header. */\nexport const HEADER_SIZE = (offsetof() + 1) & ~1; // 2 byte aligned\n/** Maximum length of a String. */\nexport const MAX_LENGTH = (MAX_SIZE_32 - HEADER_SIZE) >>> 1;\n\n// Low-level utility\n\nfunction __gc(ref: usize): void {}\n\nexport function allocateUnsafe(length: i32): String {\n assert(length > 0 && length <= MAX_LENGTH);\n var buffer: usize;\n if (isManaged()) {\n buffer = __gc_allocate(HEADER_SIZE + (length << 1), __gc); // tslint:disable-line\n } else {\n buffer = memory.allocate(HEADER_SIZE + (length << 1));\n }\n store(buffer, length);\n return changetype(buffer);\n}\n\n@inline\nexport function freeUnsafe(buffer: String): void {\n if (!isManaged()) {\n assert(buffer);\n memory.free(changetype(buffer));\n }\n}\n\nexport function copyUnsafe(dest: String, destOffset: usize, src: String, srcOffset: usize, len: usize): void {\n memory.copy(\n changetype(dest) + (destOffset << 1) + HEADER_SIZE,\n changetype(src) + (srcOffset << 1) + HEADER_SIZE,\n len << 1\n );\n}\n\nexport function compareUnsafe(str1: String, offset1: usize, str2: String, offset2: usize, len: usize): i32 {\n var cmp: i32 = 0;\n var ptr1 = changetype(str1) + (offset1 << 1);\n var ptr2 = changetype(str2) + (offset2 << 1);\n while (len && !(cmp = load(ptr1, HEADER_SIZE) - load(ptr2, HEADER_SIZE))) {\n --len, ++ptr1, ++ptr2;\n }\n return cmp;\n}\n\nexport function repeatUnsafe(dest: String, destOffset: usize, src: String, count: i32): void {\n var length = src.length;\n if (ASC_SHRINK_LEVEL > 1) {\n let strLen = length << 1;\n let to = changetype(dest) + HEADER_SIZE + (destOffset << 1);\n let from = changetype(src) + HEADER_SIZE;\n for (let i = 0, len = strLen * count; i < len; i += strLen) {\n memory.copy(to + i, from, strLen);\n }\n } else {\n switch (length) {\n case 0: break;\n case 1: {\n let cc = load(changetype(src), HEADER_SIZE);\n let out = changetype(dest) + (destOffset << 1);\n for (let i = 0; i < count; ++i) {\n store(out + (i << 1), cc, HEADER_SIZE);\n }\n break;\n }\n case 2: {\n let cc = load(changetype(src), HEADER_SIZE);\n let out = changetype(dest) + (destOffset << 1);\n for (let i = 0; i < count; ++i) {\n store(out + (i << 2), cc, HEADER_SIZE);\n }\n break;\n }\n case 3: {\n let cc1 = load(changetype(src), HEADER_SIZE + 0);\n let cc2 = load(changetype(src), HEADER_SIZE + 4);\n let out = changetype(dest) + (destOffset << 1);\n for (let i = 0; i < count; ++i) {\n store(out + (i << 2), cc1, HEADER_SIZE + 0);\n store(out + (i << 1), cc2, HEADER_SIZE + 4);\n }\n break;\n }\n case 4: {\n let cc = load(changetype(src), HEADER_SIZE);\n let out = changetype(dest) + (destOffset << 1);\n for (let i = 0; i < count; ++i) {\n store(out + (i << 3), cc, HEADER_SIZE);\n }\n break;\n }\n default: {\n let strLen = length << 1;\n let to = changetype(dest) + HEADER_SIZE + (destOffset << 1);\n let from = changetype(src) + HEADER_SIZE;\n for (let i = 0, len = strLen * count; i < len; i += strLen) {\n memory.copy(to + i, from, strLen);\n }\n break;\n }\n }\n }\n}\n\n// Helpers\n\nexport const enum CharCode {\n PLUS = 0x2B,\n MINUS = 0x2D,\n DOT = 0x2E,\n _0 = 0x30,\n _1 = 0x31,\n _2 = 0x32,\n _3 = 0x33,\n _4 = 0x34,\n _5 = 0x35,\n _6 = 0x36,\n _7 = 0x37,\n _8 = 0x38,\n _9 = 0x39,\n A = 0x41,\n B = 0x42,\n E = 0x45,\n N = 0x4E,\n O = 0x4F,\n X = 0x58,\n Z = 0x5a,\n a = 0x61,\n b = 0x62,\n e = 0x65,\n n = 0x6E,\n o = 0x6F,\n x = 0x78,\n z = 0x7A\n}\n\nexport function isWhiteSpaceOrLineTerminator(c: u16): bool {\n switch (c) {\n case 9: // \n case 10: // \n case 13: // \n case 11: // \n case 12: // \n case 32: // \n case 160: // \n case 8232: // \n case 8233: // \n case 65279: return true; // \n default: return false;\n }\n}\n\n/** Parses a string to an integer (usually), using the specified radix. */\nexport function parse(str: String, radix: i32 = 0): T {\n var len: i32 = str.length;\n if (!len) return NaN;\n\n var ptr = changetype(str) /* + HEAD -> offset */;\n var code = load(ptr, HEADER_SIZE);\n\n // determine sign\n var sign: T;\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = load(ptr += 2, HEADER_SIZE);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = load(ptr += 2, HEADER_SIZE);\n sign = 1;\n } else {\n sign = 1;\n }\n\n // determine radix\n if (!radix) {\n if (code == CharCode._0 && len > 2) {\n switch (load(ptr + 2, HEADER_SIZE)) {\n case CharCode.B:\n case CharCode.b: {\n ptr += 4; len -= 2;\n radix = 2;\n break;\n }\n case CharCode.O:\n case CharCode.o: {\n ptr += 4; len -= 2;\n radix = 8;\n break;\n }\n case CharCode.X:\n case CharCode.x: {\n ptr += 4; len -= 2;\n radix = 16;\n break;\n }\n default: radix = 10;\n }\n } else radix = 10;\n } else if (radix < 2 || radix > 36) {\n return NaN;\n }\n\n // calculate value\n var num: T = 0;\n while (len--) {\n code = load(ptr, HEADER_SIZE);\n if (code >= CharCode._0 && code <= CharCode._9) {\n code -= CharCode._0;\n } else if (code >= CharCode.A && code <= CharCode.Z) {\n code -= CharCode.A - 10;\n } else if (code >= CharCode.a && code <= CharCode.z) {\n code -= CharCode.a - 10;\n } else break;\n if (code >= radix) break;\n num = (num * radix) + code;\n ptr += 2;\n }\n return sign * num;\n}\n',"internal/typedarray":'import {\n HEADER_SIZE as AB_HEADER_SIZE,\n MAX_BLENGTH as AB_MAX_BLENGTH,\n allocateUnsafe,\n loadUnsafeWithOffset,\n storeUnsafeWithOffset\n} from "./arraybuffer";\n\nimport {\n insertionSort,\n weakHeapSort,\n defaultComparator\n} from "./array";\n\n/** Typed array base class. Not a global object. */\nexport abstract class TypedArray {\n\n readonly buffer: ArrayBuffer;\n readonly byteOffset: i32;\n readonly byteLength: i32;\n\n constructor(length: i32) {\n const MAX_LENGTH = AB_MAX_BLENGTH / sizeof();\n if (length > MAX_LENGTH) throw new RangeError("Invalid typed array length");\n var byteLength = length << alignof();\n var buffer = allocateUnsafe(byteLength);\n memory.fill(changetype(buffer) + AB_HEADER_SIZE, 0, byteLength);\n this.buffer = buffer;\n this.byteOffset = 0;\n this.byteLength = byteLength;\n }\n\n @inline\n get length(): i32 {\n return (this.byteLength - this.byteOffset) >> alignof();\n }\n\n @operator("[]")\n protected __get(index: i32): T {\n var byteOffset = this.byteOffset;\n var elementLength = (this.byteLength - byteOffset) >>> alignof();\n if (index >= elementLength) throw new Error("Index out of bounds");\n return loadUnsafeWithOffset(this.buffer, index, byteOffset);\n }\n\n @inline @operator("{}")\n protected __unchecked_get(index: i32): T {\n return loadUnsafeWithOffset(this.buffer, index, this.byteOffset);\n }\n\n @operator("[]=")\n protected __set(index: i32, value: V): void {\n var byteOffset = this.byteOffset;\n var elementLength = (this.byteLength - byteOffset) >>> alignof();\n if (index >= elementLength) throw new Error("Index out of bounds");\n storeUnsafeWithOffset(this.buffer, index, value, byteOffset);\n }\n\n @inline @operator("{}=")\n protected __unchecked_set(index: i32, value: V): void {\n storeUnsafeWithOffset(this.buffer, index, value, this.byteOffset);\n }\n\n // copyWithin(target: i32, start: i32, end: i32 = this.length): this\n\n fill(value: V, start: i32 = 0, end: i32 = i32.MAX_VALUE): this {\n var buffer = this.buffer;\n var byteOffset = this.byteOffset;\n var len = this.length;\n start = start < 0 ? max(len + start, 0) : min(start, len);\n end = end < 0 ? max(len + end, 0) : min(end, len);\n if (sizeof() == 1) {\n if (start < end) {\n memory.fill(\n changetype(buffer) + start + byteOffset + AB_HEADER_SIZE,\n value,\n (end - start)\n );\n }\n } else {\n for (; start < end; ++start) {\n storeUnsafeWithOffset(buffer, start, value, byteOffset);\n }\n }\n return this;\n }\n\n @inline\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): TypedArray {\n var length = this.length;\n if (begin < 0) begin = max(length + begin, 0);\n else begin = min(begin, length);\n if (end < 0) end = max(length + end, begin);\n else end = max(min(end, length), begin);\n var slice = memory.allocate(offsetof());\n store(slice, this.buffer, offsetof("buffer"));\n store(slice, begin << alignof(), offsetof("byteOffset"));\n store(slice, end << alignof(), offsetof("byteLength"));\n return changetype(slice);\n }\n\n sort(comparator: (a: T, b: T) => i32 = defaultComparator()): this {\n var byteOffset = this.byteOffset;\n var length = this.length;\n if (length <= 1) return this;\n var buffer = this.buffer;\n if (length == 2) {\n let a = loadUnsafeWithOffset(buffer, 1, byteOffset);\n let b = loadUnsafeWithOffset(buffer, 0, byteOffset);\n if (comparator(a, b) < 0) {\n storeUnsafeWithOffset(buffer, 1, b, byteOffset);\n storeUnsafeWithOffset(buffer, 0, a, byteOffset);\n }\n return this;\n }\n\n if (isReference()) {\n // TODO replace this to faster stable sort (TimSort) when it implemented\n insertionSort(buffer, byteOffset, length, comparator);\n return this;\n } else {\n if (length < 256) {\n insertionSort(buffer, byteOffset, length, comparator);\n } else {\n weakHeapSort(buffer, byteOffset, length, comparator);\n }\n return this;\n }\n }\n}\n',iterator:"// export abstract class Iterator {\n// abstract get done(): bool;\n// abstract next(): T;\n// }\n",map:'import {\n HEADER_SIZE as HEADER_SIZE_AB\n} from "./internal/arraybuffer";\n\nimport {\n hash\n} from "./internal/hash";\n\n// A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht\n\nconst INITIAL_CAPACITY = 4;\nconst FILL_FACTOR: f64 = 8 / 3;\nconst FREE_FACTOR: f64 = 3 / 4;\n\n/** Structure of a map entry. */\n@unmanaged class MapEntry {\n key: K;\n value: V;\n taggedNext: usize; // LSB=1 indicates EMPTY\n}\n\n/** Empty bit. */\nconst EMPTY: usize = 1 << 0;\n\n/** Size of a bucket. */\nconst BUCKET_SIZE = sizeof();\n\n/** Computes the alignment of an entry. */\n@inline function ENTRY_ALIGN(): usize {\n // can align to 4 instead of 8 if 32-bit and K/V is <= 32-bits\n const maxkv = sizeof() > sizeof() ? sizeof() : sizeof();\n const align = (maxkv > sizeof() ? maxkv : sizeof()) - 1;\n return align;\n}\n\n/** Computes the aligned size of an entry. */\n@inline function ENTRY_SIZE(): usize {\n const align = ENTRY_ALIGN();\n const size = (offsetof>() + align) & ~align;\n return size;\n}\n\nexport class Map {\n\n // buckets holding references to the respective first entry within\n private buckets: ArrayBuffer; // usize[bucketsMask + 1]\n private bucketsMask: u32;\n\n // entries in insertion order\n private entries: ArrayBuffer; // MapEntry[entriesCapacity]\n private entriesCapacity: i32;\n private entriesOffset: i32;\n private entriesCount: i32;\n\n get size(): i32 { return this.entriesCount; }\n\n constructor() { this.clear(); }\n\n clear(): void {\n const bucketsSize = INITIAL_CAPACITY * BUCKET_SIZE;\n this.buckets = new ArrayBuffer(bucketsSize);\n this.bucketsMask = INITIAL_CAPACITY - 1;\n const entriesSize = INITIAL_CAPACITY * ENTRY_SIZE();\n this.entries = new ArrayBuffer(entriesSize, true);\n this.entriesCapacity = INITIAL_CAPACITY;\n this.entriesOffset = 0;\n this.entriesCount = 0;\n }\n\n private find(key: K, hashCode: u32): MapEntry | null {\n var entry = load>(\n changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE,\n HEADER_SIZE_AB\n );\n while (entry) {\n if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry;\n entry = changetype>(entry.taggedNext & ~EMPTY);\n }\n return null;\n }\n\n has(key: K): bool {\n return this.find(key, hash(key)) !== null;\n }\n\n get(key: K): V {\n var entry = this.find(key, hash(key));\n return entry ? entry.value : unreachable();\n }\n\n set(key: K, value: V): void {\n var hashCode = hash(key);\n var entry = this.find(key, hashCode);\n if (entry) {\n entry.value = value;\n } else {\n // check if rehashing is necessary\n if (this.entriesOffset == this.entriesCapacity) {\n this.rehash(\n this.entriesCount < (this.entriesCapacity * FREE_FACTOR)\n ? this.bucketsMask // just rehash if 1/4+ entries are empty\n : (this.bucketsMask << 1) | 1 // grow capacity to next 2^N\n );\n }\n // append new entry\n let entries = this.entries;\n entry = changetype>(\n changetype(entries) + HEADER_SIZE_AB + this.entriesOffset++ * ENTRY_SIZE()\n );\n entry.key = key;\n entry.value = value;\n ++this.entriesCount;\n // link with previous entry in bucket\n let bucketPtrBase = changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE;\n entry.taggedNext = load(bucketPtrBase, HEADER_SIZE_AB);\n store(bucketPtrBase, changetype(entry), HEADER_SIZE_AB);\n if (isManaged()) __gc_link(changetype(this), changetype(key)); // tslint:disable-line\n if (isManaged()) __gc_link(changetype(this), changetype(value)); // tslint:disable-line\n }\n }\n\n delete(key: K): bool {\n var entry = this.find(key, hash(key));\n if (!entry) return false;\n entry.taggedNext |= EMPTY;\n --this.entriesCount;\n // check if rehashing is appropriate\n var halfBucketsMask = this.bucketsMask >> 1;\n if (\n halfBucketsMask + 1 >= max(INITIAL_CAPACITY, this.entriesCount) &&\n this.entriesCount < (this.entriesCapacity * FREE_FACTOR)\n ) this.rehash(halfBucketsMask);\n return true;\n }\n\n private rehash(newBucketsMask: u32): void {\n var newBucketsCapacity = (newBucketsMask + 1);\n var newBuckets = new ArrayBuffer(newBucketsCapacity * BUCKET_SIZE);\n var newEntriesCapacity = (newBucketsCapacity * FILL_FACTOR);\n var newEntries = new ArrayBuffer(newEntriesCapacity * ENTRY_SIZE(), true);\n\n // copy old entries to new entries\n var oldPtr = changetype(this.entries) + HEADER_SIZE_AB;\n var oldEnd = oldPtr + this.entriesOffset * ENTRY_SIZE();\n var newPtr = changetype(newEntries) + HEADER_SIZE_AB;\n while (oldPtr != oldEnd) {\n let oldEntry = changetype>(oldPtr);\n if (!(oldEntry.taggedNext & EMPTY)) {\n let newEntry = changetype>(newPtr);\n newEntry.key = oldEntry.key;\n newEntry.value = oldEntry.value;\n let newBucketIndex = hash(oldEntry.key) & newBucketsMask;\n let newBucketPtrBase = changetype(newBuckets) + newBucketIndex * BUCKET_SIZE;\n newEntry.taggedNext = load(newBucketPtrBase, HEADER_SIZE_AB);\n store(newBucketPtrBase, newPtr, HEADER_SIZE_AB);\n newPtr += ENTRY_SIZE();\n }\n oldPtr += ENTRY_SIZE();\n }\n\n this.buckets = newBuckets;\n this.bucketsMask = newBucketsMask;\n this.entries = newEntries;\n this.entriesCapacity = newEntriesCapacity;\n this.entriesOffset = this.entriesCount;\n }\n\n private __gc(): void {\n __gc_mark(changetype(this.buckets)); // tslint:disable-line\n var entries = this.entries;\n __gc_mark(changetype(entries)); // tslint:disable-line\n if (isManaged() || isManaged()) {\n let offset: usize = 0;\n let end: usize = this.entriesOffset * ENTRY_SIZE();\n while (offset < end) {\n let entry = changetype>(\n changetype(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE()\n );\n if (!(entry.taggedNext & EMPTY)) {\n if (isManaged()) __gc_mark(changetype(entry.key)); // tslint:disable-line\n if (isManaged()) __gc_mark(changetype(entry.value)); // tslint:disable-line\n }\n offset += ENTRY_SIZE();\n }\n }\n }\n}\n',math:'import * as JSMath from "./bindings/Math";\nexport { JSMath };\n\nimport {\n abs as builtin_abs,\n ceil as builtin_ceil,\n clz as builtin_clz,\n copysign as builtin_copysign,\n floor as builtin_floor,\n max as builtin_max,\n min as builtin_min,\n sqrt as builtin_sqrt,\n trunc as builtin_trunc\n} from "./builtins";\n\n// SUN COPYRIGHT NOTICE\n//\n// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\n// Developed at SunPro, a Sun Microsystems, Inc. business.\n// Permission to use, copy, modify, and distribute this software\n// is freely granted, provided that this notice is preserved.\n//\n// Applies to all functions marked with a comment referring here.\n\n// TODO: sin, cos, tan\n\n/** @internal */\nfunction R(z: f64): f64 { // Rational approximation of (asin(x)-x)/x^3\n const // see: musl/src/math/asin.c and SUN COPYRIGHT NOTICE above\n pS0 = reinterpret(0x3FC5555555555555), // 1.66666666666666657415e-01\n pS1 = reinterpret(0xBFD4D61203EB6F7D), // -3.25565818622400915405e-01\n pS2 = reinterpret(0x3FC9C1550E884455), // 2.01212532134862925881e-01\n pS3 = reinterpret(0xBFA48228B5688F3B), // -4.00555345006794114027e-02\n pS4 = reinterpret(0x3F49EFE07501B288), // 7.91534994289814532176e-04\n pS5 = reinterpret(0x3F023DE10DFDF709), // 3.47933107596021167570e-05\n qS1 = reinterpret(0xC0033A271C8A2D4B), // -2.40339491173441421878e+00\n qS2 = reinterpret(0x40002AE59C598AC8), // 2.02094576023350569471e+00\n qS3 = reinterpret(0xBFE6066C1B8D0159), // -6.88283971605453293030e-01\n qS4 = reinterpret(0x3FB3B8C5B12E9282); // 7.70381505559019352791e-02\n var p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));\n var q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));\n return p / q;\n}\n\n@inline /** @internal */\nfunction expo2(x: f64): f64 { // exp(x)/2 for x >= log(DBL_MAX)\n const // see: musl/src/math/__expo2.c\n k = 2043,\n kln2 = reinterpret(0x40962066151ADD8B); // 0x1.62066151add8bp+10\n var scale = reinterpret(((0x3FF + k / 2) << 20) << 32);\n return NativeMath.exp(x - kln2) * scale * scale;\n}\n\nvar random_seeded = false;\nvar random_state0_64: u64;\nvar random_state1_64: u64;\nvar random_state0_32: u32;\nvar random_state1_32: u32;\n\n/** @internal */\nfunction murmurHash3(h: u64): u64 { // Force all bits of a hash block to avalanche\n h ^= h >> 33; // see: https://github.com/aappleby/smhasher\n h *= 0xFF51AFD7ED558CCD;\n h ^= h >> 33;\n h *= 0xC4CEB9FE1A85EC53;\n h ^= h >> 33;\n return h;\n}\n\n/** @internal */\nfunction splitMix32(h: u32): u32 {\n h += 0x6D2B79F5;\n h = (h ^ (h >> 15)) * (h | 1);\n h ^= h + (h ^ (h >> 7)) * (h | 61);\n return h ^ (h >> 14);\n}\n\nexport namespace NativeMath {\n\n export const E = reinterpret(0x4005BF0A8B145769); // 2.7182818284590452354\n export const LN2 = reinterpret(0x3FE62E42FEFA39EF); // 0.69314718055994530942\n export const LN10 = reinterpret(0x40026BB1BBB55516); // 2.30258509299404568402\n export const LOG2E = reinterpret(0x3FF71547652B82FE); // 1.4426950408889634074\n export const LOG10E = reinterpret(0x3FDBCB7B1526E50E); // 0.43429448190325182765\n export const PI = reinterpret(0x400921FB54442D18); // 3.14159265358979323846\n export const SQRT1_2 = reinterpret(0x3FE6A09E667F3BCD); // 0.70710678118654752440\n export const SQRT2 = reinterpret(0x3FF6A09E667F3BCD); // 1.41421356237309504880\n\n @inline\n export function abs(x: f64): f64 {\n return builtin_abs(x);\n }\n\n export function acos(x: f64): f64 { // see: musl/src/math/acos.c and SUN COPYRIGHT NOTICE above\n const\n pio2_hi = reinterpret(0x3FF921FB54442D18), // 1.57079632679489655800e+00\n pio2_lo = reinterpret(0x3C91A62633145C07), // 6.12323399573676603587e-17\n Ox1p_120f = reinterpret(0x03800000);\n var hx = (reinterpret(x) >> 32);\n var ix = hx & 0x7FFFFFFF;\n if (ix >= 0x3FF00000) {\n let lx = reinterpret(x);\n if ((ix - 0x3FF00000 | lx) == 0) {\n if (hx >> 31) return 2 * pio2_hi + Ox1p_120f;\n return 0;\n }\n return 0 / (x - x);\n }\n if (ix < 0x3FE00000) {\n if (ix <= 0x3C600000) return pio2_hi + Ox1p_120f;\n return pio2_hi - (x - (pio2_lo - x * R(x * x)));\n }\n var s: f64, w: f64, z: f64;\n if (hx >> 31) {\n // z = (1.0 + x) * 0.5;\n z = 0.5 + x * 0.5;\n s = builtin_sqrt(z);\n w = R(z) * s - pio2_lo;\n return 2 * (pio2_hi - (s + w));\n }\n // z = (1.0 - x) * 0.5;\n z = 0.5 - x * 0.5;\n s = builtin_sqrt(z);\n var df = reinterpret(reinterpret(s) & 0xFFFFFFFF00000000);\n var c = (z - df * df) / (s + df);\n w = R(z) * s + c;\n return 2 * (df + w);\n }\n\n export function acosh(x: f64): f64 { // see: musl/src/math/acosh.c\n const s = reinterpret(0x3FE62E42FEFA39EF);\n var e = reinterpret(x) >> 52 & 0x7FF;\n if (e < 0x3FF + 1) return log1p(x - 1 + builtin_sqrt((x - 1) * (x - 1) + 2 * (x - 1)));\n if (e < 0x3FF + 26) return log(2 * x - 1 / (x + builtin_sqrt(x * x - 1)));\n return log(x) + s;\n }\n\n export function asin(x: f64): f64 { // see: musl/src/math/asin.c and SUN COPYRIGHT NOTICE above\n const\n pio2_hi = reinterpret(0x3FF921FB54442D18), // 1.57079632679489655800e+00\n pio2_lo = reinterpret(0x3C91A62633145C07), // 6.12323399573676603587e-17\n Ox1p_120f = reinterpret(0x03800000);\n var hx = (reinterpret(x) >> 32);\n var ix = hx & 0x7FFFFFFF;\n if (ix >= 0x3FF00000) {\n let lx = reinterpret(x);\n if ((ix - 0x3FF00000 | lx) == 0) return x * pio2_hi + Ox1p_120f;\n return 0 / (x - x);\n }\n if (ix < 0x3FE00000) {\n if (ix < 0x3E500000 && ix >= 0x00100000) return x;\n return x + x * R(x * x);\n }\n // var z = (1.0 - builtin_abs(x)) * 0.5;\n var z = 0.5 - builtin_abs(x) * 0.5;\n var s = builtin_sqrt(z);\n var r = R(z);\n if (ix >= 0x3FEF3333) x = pio2_hi - (2 * (s + s * r) - pio2_lo);\n else {\n let f = reinterpret(reinterpret(s) & 0xFFFFFFFF00000000);\n let c = (z - f * f) / (s + f);\n x = 0.5 * pio2_hi - (2 * s * r - (pio2_lo - 2 * c) - (0.5 * pio2_hi - 2 * f));\n }\n if (hx >> 31) return -x;\n return x;\n }\n\n export function asinh(x: f64): f64 { // see: musl/src/math/asinh.c\n const c = reinterpret(0x3FE62E42FEFA39EF); // 0.693147180559945309417232121458176568\n var u = reinterpret(x);\n var e = u >> 52 & 0x7FF;\n var y = reinterpret(u & 0x7FFFFFFFFFFFFFFF);\n if (e >= 0x3FF + 26) y = log(y) + c;\n else if (e >= 0x3FF + 1) y = log(2 * y + 1 / (builtin_sqrt(y * y + 1) + y));\n else if (e >= 0x3FF - 26) y = log1p(y + y * y / (builtin_sqrt(y * y + 1) + 1));\n return builtin_copysign(y, x);\n }\n\n export function atan(x: f64): f64 { // see musl/src/math/atan.c and SUN COPYRIGHT NOTICE above\n const\n atanhi0 = reinterpret(0x3FDDAC670561BB4F), // 4.63647609000806093515e-01\n atanhi1 = reinterpret(0x3FE921FB54442D18), // 7.85398163397448278999e-01\n atanhi2 = reinterpret(0x3FEF730BD281F69B), // 9.82793723247329054082e-01\n atanhi3 = reinterpret(0x3FF921FB54442D18), // 1.57079632679489655800e+00\n atanlo0 = reinterpret(0x3C7A2B7F222F65E2), // 2.26987774529616870924e-17\n atanlo1 = reinterpret(0x3C81A62633145C07), // 3.06161699786838301793e-17\n atanlo2 = reinterpret(0x3C7007887AF0CBBD), // 1.39033110312309984516e-17\n atanlo3 = reinterpret(0x3C91A62633145C07), // 6.12323399573676603587e-17\n aT0 = reinterpret(0x3FD555555555550D), // 3.33333333333329318027e-01\n aT1 = reinterpret(0xBFC999999998EBC4), // -1.99999999998764832476e-01\n aT2 = reinterpret(0x3FC24924920083FF), // 1.42857142725034663711e-01\n aT3 = reinterpret(0xBFBC71C6FE231671), // -1.11111104054623557880e-01,\n aT4 = reinterpret(0x3FB745CDC54C206E), // 9.09088713343650656196e-02\n aT5 = reinterpret(0xBFB3B0F2AF749A6D), // -7.69187620504482999495e-02\n aT6 = reinterpret(0x3FB10D66A0D03D51), // 6.66107313738753120669e-02\n aT7 = reinterpret(0xBFADDE2D52DEFD9A), // -5.83357013379057348645e-02\n aT8 = reinterpret(0x3FA97B4B24760DEB), // 4.97687799461593236017e-02\n aT9 = reinterpret(0xBFA2B4442C6A6C2F), // -3.65315727442169155270e-02\n aT10 = reinterpret(0x3F90AD3AE322DA11), // 1.62858201153657823623e-02\n Ox1p_120f = reinterpret(0x03800000);\n var ix = (reinterpret(x) >> 32);\n var sx = x;\n ix &= 0x7FFFFFFF;\n var z: f64;\n if (ix >= 0x44100000) {\n if (isNaN(x)) return x;\n z = atanhi3 + Ox1p_120f;\n return builtin_copysign(z, sx);\n }\n var id: i32;\n if (ix < 0x3FDC0000) {\n if (ix < 0x3E400000) return x;\n id = -1;\n } else {\n x = builtin_abs(x);\n if (ix < 0x3FF30000) {\n if (ix < 0x3FE60000) {\n id = 0;\n x = (2.0 * x - 1.0) / (2.0 + x);\n } else {\n id = 1;\n x = (x - 1.0) / (x + 1.0);\n }\n } else {\n if (ix < 0x40038000) {\n id = 2;\n x = (x - 1.5) / (1.0 + 1.5 * x);\n } else {\n id = 3;\n x = -1.0 / x;\n }\n }\n }\n z = x * x;\n var w = z * z;\n var s1 = z * (aT0 + w * (aT2 + w * (aT4 + w * (aT6 + w * (aT8 + w * aT10)))));\n var s2 = w * (aT1 + w * (aT3 + w * (aT5 + w * (aT7 + w * aT9))));\n var s3 = x * (s1 + s2);\n if (id < 0) return x - s3;\n switch (id) {\n case 0: { z = atanhi0 - ((s3 - atanlo0) - x); break; }\n case 1: { z = atanhi1 - ((s3 - atanlo1) - x); break; }\n case 2: { z = atanhi2 - ((s3 - atanlo2) - x); break; }\n case 3: { z = atanhi3 - ((s3 - atanlo3) - x); break; }\n default: unreachable();\n }\n return builtin_copysign(z, sx);\n }\n\n export function atanh(x: f64): f64 { // see: musl/src/math/atanh.c\n var u = reinterpret(x);\n var e = u >> 52 & 0x7FF;\n var s = u >> 63;\n u &= 0x7FFFFFFFFFFFFFFF;\n var y = reinterpret(u);\n if (e < 0x3FF - 1) {\n if (e >= 0x3FF - 32) y = 0.5 * log1p(2 * y + 2 * y * y / (1 - y));\n } else {\n y = 0.5 * log1p(2 * (y / (1 - y)));\n }\n return builtin_copysign(y, x);\n }\n\n export function atan2(y: f64, x: f64): f64 { // see: musl/src/math/atan2.c and SUN COPYRIGHT NOTICE above\n const pi_lo = reinterpret(0x3CA1A62633145C07); // 1.2246467991473531772E-16\n if (isNaN(x) || isNaN(y)) return x + y;\n var u = reinterpret(x);\n var ix = (u >> 32);\n var lx = u;\n u = reinterpret(y);\n var iy = (u >> 32);\n var ly = u;\n if ((ix - 0x3FF00000 | lx) == 0) return atan(y);\n var m = ((iy >> 31) & 1) | ((ix >> 30) & 2);\n ix = ix & 0x7FFFFFFF;\n iy = iy & 0x7FFFFFFF;\n if ((iy | ly) == 0) {\n switch (m) {\n case 0:\n case 1: return y;\n case 2: return PI;\n case 3: return -PI;\n }\n }\n if ((ix | lx) == 0) return m & 1 ? -PI / 2 : PI / 2;\n if (ix == 0x7FF00000) {\n if (iy == 0x7FF00000) {\n switch (m) {\n case 0: return PI / 4;\n case 1: return -PI / 4;\n case 2: return 3 * PI / 4;\n case 3: return -3 * PI / 4;\n }\n } else {\n switch (m) {\n case 0: return 0.0;\n case 1: return -0.0;\n case 2: return PI;\n case 3: return -PI;\n }\n }\n }\n var z: f64;\n if (ix + (64 << 20) < iy || iy == 0x7FF00000) return m & 1 ? -PI / 2 : PI / 2;\n if ((m & 2) && iy + (64 << 20) < ix) z = 0;\n else z = atan(builtin_abs(y / x));\n switch (m) {\n case 0: return z;\n case 1: return -z;\n case 2: return PI - (z - pi_lo);\n case 3: return (z - pi_lo) - PI;\n }\n unreachable();\n return 0;\n }\n\n export function cbrt(x: f64): f64 { // see: musl/src/math/cbrt.c and SUN COPYRIGHT NOTICE above\n const\n B1 = 715094163,\n B2 = 696219795,\n P0 = reinterpret(0x3FFE03E60F61E692), // 1.87595182427177009643\n P1 = reinterpret(0xBFFE28E092F02420), // -1.88497979543377169875\n P2 = reinterpret(0x3FF9F1604A49D6C2), // 1.621429720105354466140\n P3 = reinterpret(0xBFE844CBBEE751D9), // -0.758397934778766047437\n P4 = reinterpret(0x3FC2B000D4E4EDD7), // 0.145996192886612446982\n Ox1p54 = reinterpret(0x4350000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32) & 0x7FFFFFFF;\n if (hx >= 0x7FF00000) return x + x;\n if (hx < 0x00100000) {\n u = reinterpret(x * Ox1p54);\n hx = (u >> 32) & 0x7FFFFFFF;\n if (hx == 0) return x;\n hx = hx / 3 + B2;\n } else {\n hx = hx / 3 + B1;\n }\n u &= 1 << 63;\n u |= hx << 32;\n var t = reinterpret(u);\n var r = (t * t) * (t / x);\n t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));\n t = reinterpret((reinterpret(t) + 0x80000000) & 0xFFFFFFFFC0000000);\n var s = t * t;\n r = x / s;\n var w = t + t;\n r = (r - t) / (w + r);\n t = t + t * r;\n return t;\n }\n\n @inline\n export function ceil(x: f64): f64 {\n return builtin_ceil(x);\n }\n\n @inline\n export function clz32(x: f64): f64 {\n return builtin_clz(x);\n }\n\n export function cos(x: f64): f64 { // TODO\n unreachable();\n return 0;\n }\n\n export function cosh(x: f64): f64 { // see: musl/src/math/cosh.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFFFFFFFFFF;\n x = reinterpret(u);\n var w = (u >> 32);\n var t: f64;\n if (w < 0x3FE62E42) {\n if (w < 0x3FF00000 - (26 << 20)) return 1;\n t = expm1(x);\n // return 1 + t * t / (2 * (1 + t));\n return 1 + t * t / (2 + 2 * t);\n }\n if (w < 0x40862E42) {\n t = exp(x);\n return 0.5 * (t + 1 / t);\n }\n t = expo2(x);\n return t;\n }\n\n export function exp(x: f64): f64 { // see: musl/src/math/exp.c and SUN COPYRIGHT NOTICE above\n const\n ln2hi = reinterpret(0x3FE62E42FEE00000), // 6.93147180369123816490e-01\n ln2lo = reinterpret(0x3DEA39EF35793C76), // 1.90821492927058770002e-10\n invln2 = reinterpret(0x3FF71547652B82FE), // 1.44269504088896338700e+00\n P1 = reinterpret(0x3FC555555555553E), // 1.66666666666666019037e-01\n P2 = reinterpret(0xBF66C16C16BEBD93), // -2.77777777770155933842e-03\n P3 = reinterpret(0x3F11566AAF25DE2C), // 6.61375632143793436117e-05\n P4 = reinterpret(0xBEBBBD41C5D26BF1), // -1.65339022054652515390e-06\n P5 = reinterpret(0x3E66376972BEA4D0), // 4.13813679705723846039e-08\n overflow = reinterpret(0x40862E42FEFA39EF), // 709.782712893383973096\n underflow = reinterpret(0xC0874910D52D3051), // -745.13321910194110842\n Ox1p1023 = reinterpret(0x7FE0000000000000);\n var hx = (reinterpret(x) >> 32);\n var sign_ = (hx >> 31);\n hx &= 0x7FFFFFFF;\n if (hx >= 0x4086232B) {\n if (isNaN(x)) return x;\n if (x > overflow) {\n x *= Ox1p1023;\n return x;\n }\n if (x < underflow) return 0;\n }\n var hi: f64, lo: f64 = 0;\n var k = 0;\n if (hx > 0x3FD62E42) {\n if (hx >= 0x3FF0A2B2) {\n k = (invln2 * x + builtin_copysign(0.5, x));\n } else {\n k = 1 - (sign_ << 1);\n }\n hi = x - k * ln2hi;\n lo = k * ln2lo;\n x = hi - lo;\n } else if (hx > 0x3E300000) {\n hi = x;\n } else return 1.0 + x;\n var xx = x * x;\n var c = x - xx * (P1 + xx * (P2 + xx * (P3 + xx * (P4 + xx * P5))));\n var y = 1.0 + (x * c / (2 - c) - lo + hi);\n if (k == 0) return y;\n return scalbn(y, k);\n }\n\n export function expm1(x: f64): f64 { // see: musl/src/math/expm1.c and SUN COPYRIGHT NOTICE above\n const\n o_threshold = reinterpret(0x40862E42FEFA39EF), // 7.09782712893383973096e+02\n ln2_hi = reinterpret(0x3FE62E42FEE00000), // 6.93147180369123816490e-01\n ln2_lo = reinterpret(0x3DEA39EF35793C76), // 1.90821492927058770002e-10\n invln2 = reinterpret(0x3FF71547652B82FE), // 1.44269504088896338700e+00\n Q1 = reinterpret(0xBFA11111111110F4), // -3.33333333333331316428e-02\n Q2 = reinterpret(0x3F5A01A019FE5585), // 1.58730158725481460165e-03\n Q3 = reinterpret(0xBF14CE199EAADBB7), // -7.93650757867487942473e-05\n Q4 = reinterpret(0x3ED0CFCA86E65239), // 4.00821782732936239552e-06\n Q5 = reinterpret(0xBE8AFDB76E09C32D), // -2.01099218183624371326e-07\n Ox1p1023 = reinterpret(0x7FE0000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32 & 0x7FFFFFFF);\n var k = 0, sign_ = (u >> 63);\n if (hx >= 0x4043687A) {\n if (isNaN(x)) return x;\n if (sign_) return -1;\n if (x > o_threshold) return x * Ox1p1023;\n }\n var c = 0.0, t: f64;\n if (hx > 0x3FD62E42) {\n k = select(\n 1 - (sign_ << 1),\n (invln2 * x + builtin_copysign(0.5, x)),\n hx < 0x3FF0A2B2\n );\n t = k;\n let hi = x - t * ln2_hi;\n let lo = t * ln2_lo;\n x = hi - lo;\n c = (hi - x) - lo;\n } else if (hx < 0x3C900000) return x;\n var hfx = 0.5 * x;\n var hxs = x * hfx;\n var r1 = 1.0 + hxs * (Q1 + hxs * (Q2 + hxs * (Q3 + hxs * (Q4 + hxs * Q5))));\n t = 3.0 - r1 * hfx;\n var e = hxs * ((r1 - t) / (6.0 - x * t));\n if (k == 0) return x - (x * e - hxs);\n e = x * (e - c) - c;\n e -= hxs;\n if (k == -1) return 0.5 * (x - e) - 0.5;\n if (k == 1) {\n if (x < -0.25) return -2.0 * (e - (x + 0.5));\n return 1.0 + 2.0 * (x - e);\n }\n u = (0x3FF + k) << 52;\n var twopk = reinterpret(u);\n var y: f64;\n if (k < 0 || k > 56) {\n y = x - e + 1.0;\n if (k == 1024) y = y * 2.0 * Ox1p1023;\n else y = y * twopk;\n return y - 1.0;\n }\n u = (0x3FF - k) << 52;\n y = reinterpret(u);\n if (k < 20) y = (1 - y) - e;\n else y = 1 - (e + y);\n return (x + y) * twopk;\n }\n\n @inline\n export function floor(x: f64): f64 {\n return builtin_floor(x);\n }\n\n @inline\n export function fround(x: f64): f32 {\n return x;\n }\n\n export function hypot(x: f64, y: f64): f64 { // see: musl/src/math/hypot.c\n const\n SPLIT = reinterpret(0x41A0000000000000) + 1, // 0x1p27 + 1\n Ox1p700 = reinterpret(0x6BB0000000000000),\n Ox1p_700 = reinterpret(0x1430000000000000);\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n ux &= 0x7FFFFFFFFFFFFFFF;\n uy &= 0x7FFFFFFFFFFFFFFF;\n if (ux < uy) {\n let ut = ux;\n ux = uy;\n uy = ut;\n }\n var ex = (ux >> 52);\n var ey = (uy >> 52);\n y = reinterpret(uy);\n if (ey == 0x7FF) return y;\n x = reinterpret(ux);\n if (ex == 0x7FF || uy == 0) return x;\n if (ex - ey > 64) return x + y;\n var z = 1.0;\n if (ex > 0x3FF + 510) {\n z = Ox1p700;\n x *= Ox1p_700;\n y *= Ox1p_700;\n } else if (ey < 0x3FF - 450) {\n z = Ox1p_700;\n x *= Ox1p700;\n y *= Ox1p700;\n }\n var c = x * SPLIT;\n var h = x - c + c;\n var l = x - h;\n var hx = x * x;\n var lx = h * h - hx + (2 * h + l) * l;\n c = y * SPLIT;\n h = y - c + c;\n l = y - h;\n var hy = y * y;\n var ly = h * h - hy + (2 * h + l) * l;\n return z * builtin_sqrt(ly + lx + hy + hx);\n }\n\n export function imul(x: f64, y: f64): f64 {\n return (x * y);\n }\n\n export function log(x: f64): f64 { // see: musl/src/math/log.c and SUN COPYRIGHT NOTICE above\n const\n ln2_hi = reinterpret(0x3FE62E42FEE00000), // 6.93147180369123816490e-01\n ln2_lo = reinterpret(0x3DEA39EF35793C76), // 1.90821492927058770002e-10\n Lg1 = reinterpret(0x3FE5555555555593), // 6.666666666666735130e-01\n Lg2 = reinterpret(0x3FD999999997FA04), // 3.999999999940941908e-01\n Lg3 = reinterpret(0x3FD2492494229359), // 2.857142874366239149e-01\n Lg4 = reinterpret(0x3FCC71C51D8E78AF), // 2.222219843214978396e-01\n Lg5 = reinterpret(0x3FC7466496CB03DE), // 1.818357216161805012e-01\n Lg6 = reinterpret(0x3FC39A09D078C69F), // 1.531383769920937332e-01\n Lg7 = reinterpret(0x3FC2F112DF3E5244), // 1.479819860511658591e-01\n Ox1p54 = reinterpret(0x4350000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32);\n var k = 0;\n if (hx < 0x00100000 || (hx >> 31)) {\n if (u << 1 == 0) return -1 / (x * x);\n if (hx >> 31) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = (u >> 32);\n } else if (hx >= 0x7FF00000) return x;\n else if (hx == 0x3FF00000 && u << 32 == 0) return 0;\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += (hx >> 20) - 0x3FF;\n hx = (hx & 0x000FFFFF) + 0x3FE6A09E;\n u = hx << 32 | (u & 0xFFFFFFFF);\n x = reinterpret(u);\n var f = x - 1.0;\n var hfsq = 0.5 * f * f;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n var r = t2 + t1;\n var dk = k;\n return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;\n }\n\n export function log10(x: f64): f64 { // see: musl/src/math/log10.c and SUN COPYRIGHT NOTICE above\n const\n ivln10hi = reinterpret(0x3FDBCB7B15200000), // 4.34294481878168880939e-01\n ivln10lo = reinterpret(0x3DBB9438CA9AADD5), // 2.50829467116452752298e-11\n log10_2hi = reinterpret(0x3FD34413509F6000), // 3.01029995663611771306e-01\n log10_2lo = reinterpret(0x3D59FEF311F12B36), // 3.69423907715893078616e-13\n Lg1 = reinterpret(0x3FE5555555555593), // 6.666666666666735130e-01\n Lg2 = reinterpret(0x3FD999999997FA04), // 3.999999999940941908e-01\n Lg3 = reinterpret(0x3FD2492494229359), // 2.857142874366239149e-01\n Lg4 = reinterpret(0x3FCC71C51D8E78AF), // 2.222219843214978396e-01\n Lg5 = reinterpret(0x3FC7466496CB03DE), // 1.818357216161805012e-01\n Lg6 = reinterpret(0x3FC39A09D078C69F), // 1.531383769920937332e-01\n Lg7 = reinterpret(0x3FC2F112DF3E5244), // 1.479819860511658591e-01\n Ox1p54 = reinterpret(0x4350000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32);\n var k = 0;\n if (hx < 0x00100000 || (hx >> 31)) {\n if (u << 1 == 0) return -1 / (x * x);\n if (hx >> 31) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = (u >> 32);\n } else if (hx >= 0x7FF00000) return x;\n else if (hx == 0x3FF00000 && u << 32 == 0) return 0;\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += (hx >> 20) - 0x3FF;\n hx = (hx & 0x000FFFFF) + 0x3FE6A09E;\n u = hx << 32 | (u & 0xFFFFFFFF);\n x = reinterpret(u);\n var f = x - 1.0;\n var hfsq = 0.5 * f * f;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n var r = t2 + t1;\n var hi = f - hfsq;\n u = reinterpret(hi);\n u &= 0xFFFFFFFF00000000;\n hi = reinterpret(u);\n var lo = f - hi - hfsq + s * (hfsq + r);\n var val_hi = hi * ivln10hi;\n var dk = k;\n var y = dk * log10_2hi;\n var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;\n w = y + val_hi;\n val_lo += (y - w) + val_hi;\n return val_lo + w;\n }\n\n export function log1p(x: f64): f64 { // see: musl/src/math/log1p.c and SUN COPYRIGHT NOTICE above\n const\n ln2_hi = reinterpret(0x3FE62E42FEE00000), // 6.93147180369123816490e-01\n ln2_lo = reinterpret(0x3DEA39EF35793C76), // 1.90821492927058770002e-10\n Lg1 = reinterpret(0x3FE5555555555593), // 6.666666666666735130e-01\n Lg2 = reinterpret(0x3FD999999997FA04), // 3.999999999940941908e-01\n Lg3 = reinterpret(0x3FD2492494229359), // 2.857142874366239149e-01\n Lg4 = reinterpret(0x3FCC71C51D8E78AF), // 2.222219843214978396e-01\n Lg5 = reinterpret(0x3FC7466496CB03DE), // 1.818357216161805012e-01\n Lg6 = reinterpret(0x3FC39A09D078C69F), // 1.531383769920937332e-01\n Lg7 = reinterpret(0x3FC2F112DF3E5244); // 1.479819860511658591e-01\n var u = reinterpret(x);\n var hx = (u >> 32);\n var k = 1;\n var c = 0.0, f = 0.0;\n if (hx < 0x3FDA827A || (hx >> 31)) {\n if (hx >= 0xBFF00000) {\n if (x == -1) return x / 0.0;\n return (x - x) / 0.0;\n }\n if (hx << 1 < 0x3CA00000 << 1) return x;\n if (hx <= 0xBFD2BEC4) {\n k = 0;\n c = 0;\n f = x;\n }\n } else if (hx >= 0x7FF00000) return x;\n if (k) {\n u = reinterpret(1 + x);\n let hu = (u >> 32);\n hu += 0x3FF00000 - 0x3FE6A09E;\n k = (hu >> 20) - 0x3FF;\n if (k < 54) {\n let uf = reinterpret(u);\n c = k >= 2 ? 1 - (uf - x) : x - (uf - 1);\n c /= uf;\n } else c = 0;\n hu = (hu & 0x000FFFFF) + 0x3FE6A09E;\n u = hu << 32 | (u & 0xFFFFFFFF);\n f = reinterpret(u) - 1;\n }\n var hfsq = 0.5 * f * f;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n var r = t2 + t1;\n var dk = k;\n return s * (hfsq + r) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;\n }\n\n export function log2(x: f64): f64 { // see: musl/src/math/log2.c and SUN COPYRIGHT NOTICE above\n const\n ivln2hi = reinterpret(0x3FF7154765200000), // 1.44269504072144627571e+00\n ivln2lo = reinterpret(0x3DE705FC2EEFA200), // 1.67517131648865118353e-10\n Lg1 = reinterpret(0x3FE5555555555593), // 6.666666666666735130e-01\n Lg2 = reinterpret(0x3FD999999997FA04), // 3.999999999940941908e-01\n Lg3 = reinterpret(0x3FD2492494229359), // 2.857142874366239149e-01\n Lg4 = reinterpret(0x3FCC71C51D8E78AF), // 2.222219843214978396e-01\n Lg5 = reinterpret(0x3FC7466496CB03DE), // 1.818357216161805012e-01\n Lg6 = reinterpret(0x3FC39A09D078C69F), // 1.531383769920937332e-01\n Lg7 = reinterpret(0x3FC2F112DF3E5244), // 1.479819860511658591e-01\n Ox1p54 = reinterpret(0x4350000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32);\n var k = 0;\n if (hx < 0x00100000 || (hx >> 31)) {\n if (u << 1 == 0) return -1 / (x * x);\n if (hx >> 31) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = (u >> 32);\n } else if (hx >= 0x7FF00000) return x;\n else if (hx == 0x3FF00000 && u << 32 == 0) return 0;\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += (hx >> 20) - 0x3FF;\n hx = (hx & 0x000FFFFF) + 0x3FE6A09E;\n u = hx << 32 | (u & 0xFFFFFFFF);\n x = reinterpret(u);\n var f = x - 1.0;\n var hfsq = 0.5 * f * f;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n var r = t2 + t1;\n var hi = f - hfsq;\n u = reinterpret(hi);\n u &= 0xFFFFFFFF00000000;\n hi = reinterpret(u);\n var lo = f - hi - hfsq + s * (hfsq + r);\n var val_hi = hi * ivln2hi;\n var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;\n var y = k;\n w = y + val_hi;\n val_lo += (y - w) + val_hi;\n val_hi = w;\n return val_lo + val_hi;\n }\n\n @inline\n export function max(value1: f64, value2: f64): f64 {\n return builtin_max(value1, value2);\n }\n\n @inline\n export function min(value1: f64, value2: f64): f64 {\n return builtin_min(value1, value2);\n }\n\n export function pow(x: f64, y: f64): f64 { // see: musl/src/math/pow.c and SUN COPYRIGHT NOTICE above\n const\n dp_h1 = reinterpret(0x3FE2B80340000000), // 5.84962487220764160156e-01\n dp_l1 = reinterpret(0x3E4CFDEB43CFD006), // 1.35003920212974897128e-08\n two53 = reinterpret(0x4340000000000000), // 9007199254740992.0\n huge = reinterpret(0x7E37E43C8800759C), // 1e+300\n tiny = reinterpret(0x01A56E1FC2F8F359), // 1e-300\n L1 = reinterpret(0x3FE3333333333303), // 5.99999999999994648725e-01\n L2 = reinterpret(0x3FDB6DB6DB6FABFF), // 4.28571428578550184252e-01\n L3 = reinterpret(0x3FD55555518F264D), // 3.33333329818377432918e-01\n L4 = reinterpret(0x3FD17460A91D4101), // 2.72728123808534006489e-01\n L5 = reinterpret(0x3FCD864A93C9DB65), // 2.30660745775561754067e-01\n L6 = reinterpret(0x3FCA7E284A454EEF), // 2.06975017800338417784e-01\n P1 = reinterpret(0x3FC555555555553E), // 1.66666666666666019037e-01\n P2 = reinterpret(0xBF66C16C16BEBD93), // -2.77777777770155933842e-03\n P3 = reinterpret(0x3F11566AAF25DE2C), // 6.61375632143793436117e-05\n P4 = reinterpret(0xBEBBBD41C5D26BF1), // -1.65339022054652515390e-06\n P5 = reinterpret(0x3E66376972BEA4D0), // 4.13813679705723846039e-08\n lg2 = reinterpret(0x3FE62E42FEFA39EF), // 6.93147180559945286227e-01\n lg2_h = reinterpret(0x3FE62E4300000000), // 6.93147182464599609375e-01\n lg2_l = reinterpret(0xBE205C610CA86C39), // -1.90465429995776804525e-09\n ovt = reinterpret(0x3C971547652B82FE), // 8.0085662595372944372e-017\n cp = reinterpret(0x3FEEC709DC3A03FD), // 9.61796693925975554329e-01\n cp_h = reinterpret(0x3FEEC709E0000000), // 9.61796700954437255859e-01\n cp_l = reinterpret(0xBE3E2FE0145B01F5), // -7.02846165095275826516e-09\n ivln2 = reinterpret(0x3FF71547652B82FE), // 1.44269504088896338700e+00\n ivln2_h = reinterpret(0x3FF7154760000000), // 1.44269502162933349609e+00\n ivln2_l = reinterpret(0x3E54AE0BF85DDF44), // 1.92596299112661746887e-08\n inv3 = reinterpret(0x3FD5555555555555); // 0.3333333333333333333333\n var u_ = reinterpret(x);\n var hx = (u_ >> 32);\n var lx = u_;\n u_ = reinterpret(y);\n var hy = (u_ >> 32);\n var ly = u_;\n var ix = hx & 0x7FFFFFFF;\n var iy = hy & 0x7FFFFFFF;\n if ((iy | ly) == 0) return 1.0; // x**0 = 1, even if x is NaN\n // if (hx == 0x3FF00000 && lx == 0) return 1.0; // C: 1**y = 1, even if y is NaN, JS: NaN\n if ( // NaN if either arg is NaN\n ix > 0x7FF00000 || (ix == 0x7FF00000 && lx != 0) ||\n iy > 0x7FF00000 || (iy == 0x7FF00000 && ly != 0)\n ) return x + y;\n var yisint = 0, k: i32;\n if (hx < 0) {\n if (iy >= 0x43400000) yisint = 2;\n else if (iy >= 0x3FF00000) {\n k = (iy >> 20) - 0x3FF;\n let offset = select(52, 20, k > 20) - k;\n let Ly = select(ly, iy, k > 20);\n let jj = Ly >> offset;\n if ((jj << offset) == Ly) yisint = 2 - (jj & 1);\n }\n }\n if (ly == 0) {\n if (iy == 0x7FF00000) { // y is +-inf\n if (((ix - 0x3FF00000) | lx) == 0) return NaN; // C: (-1)**+-inf is 1, JS: NaN\n else if (ix >= 0x3FF00000) return hy >= 0 ? y : 0.0; // (|x|>1)**+-inf = inf,0\n else return hy >= 0 ? 0.0 : -y; // (|x|<1)**+-inf = 0,inf\n }\n if (iy == 0x3FF00000) {\n if (hy >= 0) return x;\n return 1 / x;\n }\n if (hy == 0x40000000) return x * x;\n if (hy == 0x3FE00000) {\n if (hx >= 0) return builtin_sqrt(x);\n }\n }\n var ax = builtin_abs(x), z: f64;\n if (lx == 0) {\n if (ix == 0x7FF00000 || ix == 0 || ix == 0x3FF00000) {\n z = ax;\n if (hy < 0) z = 1.0 / z;\n if (hx < 0) {\n if (((ix - 0x3FF00000) | yisint) == 0) z = (z - z) / (z - z);\n else if (yisint == 1) z = -z;\n }\n return z;\n }\n }\n var s = 1.0;\n if (hx < 0) {\n if (yisint == 0) return (x - x) / (x - x);\n if (yisint == 1) s = -1.0;\n }\n var t1: f64, t2: f64, p_h: f64, p_l: f64, r: f64, t: f64, u: f64, v: f64, w: f64;\n var j: i32, n: i32;\n if (iy > 0x41E00000) {\n if (iy > 0x43F00000) {\n if (ix <= 0x3FEFFFFF) return hy < 0 ? huge * huge : tiny * tiny;\n if (ix >= 0x3FF00000) return hy > 0 ? huge * huge : tiny * tiny;\n }\n if (ix < 0x3FEFFFFF) return hy < 0 ? s * huge * huge : s * tiny * tiny;\n if (ix > 0x3FF00000) return hy > 0 ? s * huge * huge : s * tiny * tiny;\n t = ax - 1.0;\n w = (t * t) * (0.5 - t * (inv3 - t * 0.25));\n u = ivln2_h * t;\n v = t * ivln2_l - w * ivln2;\n t1 = u + v;\n t1 = reinterpret(reinterpret(t1) & 0xFFFFFFFF00000000);\n t2 = v - (t1 - u);\n } else {\n let ss: f64, s2: f64, s_h: f64, s_l: f64, t_h: f64, t_l: f64;\n n = 0;\n if (ix < 0x00100000) {\n ax *= two53;\n n -= 53;\n ix = (reinterpret(ax) >> 32);\n }\n n += (ix >> 20) - 0x3FF;\n j = ix & 0x000FFFFF;\n ix = j | 0x3FF00000;\n if (j <= 0x3988E) k = 0;\n else if (j < 0xBB67A) k = 1;\n else {\n k = 0;\n n += 1;\n ix -= 0x00100000;\n }\n ax = reinterpret(reinterpret(ax) & 0xFFFFFFFF | (ix << 32));\n let bp = select(1.5, 1.0, k); // k ? 1.5 : 1.0\n u = ax - bp;\n v = 1.0 / (ax + bp);\n ss = u * v;\n s_h = ss;\n s_h = reinterpret(reinterpret(s_h) & 0xFFFFFFFF00000000);\n t_h = reinterpret((((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18)) << 32);\n t_l = ax - (t_h - bp);\n s_l = v * ((u - s_h * t_h) - s_h * t_l);\n s2 = ss * ss;\n r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));\n r += s_l * (s_h + ss);\n s2 = s_h * s_h;\n t_h = 3.0 + s2 + r;\n t_h = reinterpret(reinterpret(t_h) & 0xFFFFFFFF00000000);\n t_l = r - ((t_h - 3.0) - s2);\n u = s_h * t_h;\n v = s_l * t_h + t_l * ss;\n p_h = u + v;\n p_h = reinterpret(reinterpret(p_h) & 0xFFFFFFFF00000000);\n p_l = v - (p_h - u);\n let z_h = cp_h * p_h;\n let dp_l = select(dp_l1, 0.0, k);\n let z_l = cp_l * p_h + p_l * cp + dp_l;\n t = n;\n let dp_h = select(dp_h1, 0.0, k);\n t1 = ((z_h + z_l) + dp_h) + t;\n t1 = reinterpret(reinterpret(t1) & 0xFFFFFFFF00000000);\n t2 = z_l - (((t1 - t) - dp_h) - z_h);\n }\n var y1 = y;\n y1 = reinterpret(reinterpret(y1) & 0xFFFFFFFF00000000);\n p_l = (y - y1) * t1 + y * t2;\n p_h = y1 * t1;\n z = p_l + p_h;\n u_ = reinterpret(z);\n j = (u_ >> 32);\n var i = u_;\n if (j >= 0x40900000) {\n if (((j - 0x40900000) | i) != 0) return s * huge * huge;\n if (p_l + ovt > z - p_h) return s * huge * huge;\n } else if ((j & 0x7FFFFFFF) >= 0x4090CC00) {\n if (((j - 0xC090CC00) | i) != 0) return s * tiny * tiny;\n if (p_l <= z - p_h) return s * tiny * tiny;\n }\n i = j & 0x7FFFFFFF;\n k = (i >> 20) - 0x3FF;\n n = 0;\n if (i > 0x3FE00000) {\n n = j + (0x00100000 >> (k + 1));\n k = ((n & 0x7FFFFFFF) >> 20) - 0x3FF;\n t = 0.0;\n t = reinterpret((n & ~(0x000FFFFF >> k)) << 32);\n n = ((n & 0x000FFFFF) | 0x00100000) >> (20 - k);\n if (j < 0) n = -n;\n p_h -= t;\n }\n t = p_l + p_h;\n t = reinterpret(reinterpret(t) & 0xFFFFFFFF00000000);\n u = t * lg2_h;\n v = (p_l - (t - p_h)) * lg2 + t * lg2_l;\n z = u + v;\n w = v - (z - u);\n t = z * z;\n t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));\n r = (z * t1) / (t1 - 2.0) - (w + z * w);\n z = 1.0 - (r - z);\n j = (reinterpret(z) >> 32);\n j += n << 20;\n if ((j >> 20) <= 0) z = scalbn(z, n);\n else z = reinterpret(reinterpret(z) & 0xFFFFFFFF | (j << 32));\n return s * z;\n }\n\n export function seedRandom(value: i64): void {\n assert(value);\n random_seeded = true;\n random_state0_64 = murmurHash3(value);\n random_state1_64 = murmurHash3(~random_state0_64);\n random_state0_32 = splitMix32(value);\n random_state1_32 = splitMix32(random_state0_32);\n }\n\n export function random(): f64 { // see: v8/src/base/random-number-generator.cc\n if (!random_seeded) throw new Error("PRNG must be seeded.");\n var s1 = random_state0_64;\n var s0 = random_state1_64;\n random_state0_64 = s0;\n s1 ^= s1 << 23;\n s1 ^= s1 >> 17;\n s1 ^= s0;\n s1 ^= s0 >> 26;\n random_state1_64 = s1;\n var r = ((s0 + s1) & 0x000FFFFFFFFFFFFF) | 0x3FF0000000000000;\n return reinterpret(r) - 1;\n }\n\n @inline\n export function round(x: f64): f64 {\n return builtin_copysign(builtin_floor(x + 0.5), x);\n }\n\n @inline\n export function sign(x: f64): f64 {\n if (ASC_SHRINK_LEVEL > 0) {\n return builtin_abs(x) > 0 ? builtin_copysign(1, x) : x;\n } else {\n return x > 0 ? 1 : x < 0 ? -1 : x;\n }\n }\n\n export function sin(x: f64): f64 { // TODO\n unreachable();\n return 0;\n }\n\n export function sinh(x: f64): f64 { // see: musl/src/math/sinh.c\n var u = reinterpret(x) & 0x7FFFFFFFFFFFFFFF;\n var absx = reinterpret(u);\n var w = (u >> 32);\n var t: f64;\n var h = builtin_copysign(0.5, x);\n if (w < 0x40862E42) {\n t = expm1(absx);\n if (w < 0x3FF00000) {\n if (w < 0x3FF00000 - (26 << 20)) return x;\n return h * (2 * t - t * t / (t + 1));\n }\n return h * (t + t / (t + 1));\n }\n t = 2 * h * expo2(absx);\n return t;\n }\n\n @inline\n export function sqrt(x: f64): f64 {\n return builtin_sqrt(x);\n }\n\n export function tan(x: f64): f64 { // TODO\n unreachable();\n return 0;\n }\n\n export function tanh(x: f64): f64 { // see: musl/src/math/tanh.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFFFFFFFFFF;\n var y = reinterpret(u);\n var w = (u >> 32);\n var t: f64;\n if (w > 0x3FE193EA) {\n if (w > 0x40340000) {\n t = 1 - 0 / y;\n } else {\n t = expm1(2 * y);\n t = 1 - 2 / (t + 2);\n }\n } else if (w > 0x3FD058AE) {\n t = expm1(2 * y);\n t = t / (t + 2);\n } else if (w >= 0x00100000) {\n t = expm1(-2 * y);\n t = -t / (t + 2);\n } else t = y;\n return builtin_copysign(t, x);\n }\n\n @inline\n export function trunc(x: f64): f64 {\n return builtin_trunc(x);\n }\n\n /** @internal */\n export function scalbn(x: f64, n: i32): f64 { // see: https://git.musl-libc.org/cgit/musl/tree/src/math/scalbn.c\n const\n Ox1p53 = reinterpret(0x4340000000000000),\n Ox1p1023 = reinterpret(0x7FE0000000000000),\n Ox1p_1022 = reinterpret(0x0010000000000000);\n var y = x;\n if (n > 1023) {\n y *= Ox1p1023;\n n -= 1023;\n if (n > 1023) {\n y *= Ox1p1023;\n n = builtin_min(n - 1023, 1023);\n }\n } else if (n < -1022) {\n /* make sure final n < -53 to avoid double\n\t\t rounding in the subnormal range */\n y *= Ox1p_1022 * Ox1p53;\n n += 1022 - 53;\n if (n < -1022) {\n y *= Ox1p_1022 * Ox1p53;\n n = builtin_max(n + 1022 - 53, -1022);\n }\n }\n return y * reinterpret((0x3FF + n) << 52);\n }\n\n export function mod(x: f64, y: f64): f64 { // see: musl/src/math/fmod.c\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = (ux >> 52 & 0x7FF);\n var ey = (uy >> 52 & 0x7FF);\n var sx = ux >> 63;\n var uy1 = uy << 1;\n if (uy1 == 0 || ex == 0x7FF || isNaN(y)) return (x * y) / (x * y);\n var ux1 = ux << 1;\n if (ux1 <= uy1) {\n if (ux1 == uy1) return 0 * x;\n return x;\n }\n if (!ex) {\n ex -= builtin_clz(ux << 12);\n ux <<= -ex + 1;\n } else {\n ux &= -1 >> 12;\n ux |= 1 << 52;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 12);\n uy <<= -ey + 1;\n } else {\n uy &= -1 >> 12;\n uy |= 1 << 52;\n }\n while (ex > ey) {\n if (ux >= uy) {\n if (ux == uy) return 0 * x;\n ux -= uy;\n }\n ux <<= 1;\n --ex;\n }\n if (ux >= uy) {\n if (ux == uy) return 0 * x;\n ux -= uy;\n }\n // for (; !(ux >> 52); ux <<= 1) --ex;\n var shift = builtin_clz(ux << 11);\n ex -= shift;\n ux <<= shift;\n if (ex > 0) {\n ux -= 1 << 52;\n ux |= ex << 52;\n } else {\n ux >>= -ex + 1;\n }\n ux |= sx << 63;\n return reinterpret(ux);\n }\n\n export function rem(x: f64, y: f64): f64 { // see: musl/src/math/remquo.c\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = (ux >> 52 & 0x7FF);\n var ey = (uy >> 52 & 0x7FF);\n var sx = (ux >> 63);\n if (uy << 1 == 0 || ex == 0x7FF || isNaN(y)) return (x * y) / (x * y);\n if (ux << 1 == 0) return x;\n var uxi = ux;\n if (!ex) {\n ex -= builtin_clz(uxi << 12);\n uxi <<= -ex + 1;\n } else {\n uxi &= -1 >> 12;\n uxi |= 1 << 52;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 12);\n uy <<= -ey + 1;\n } else {\n uy &= -1 >> 12;\n uy |= 1 << 52;\n }\n var q: u32 = 0;\n do {\n if (ex < ey) {\n if (ex + 1 == ey) break; // goto end\n return x;\n }\n while (ex > ey) {\n if (uxi >= uy) {\n uxi -= uy;\n ++q;\n }\n uxi <<= 1;\n q <<= 1;\n --ex;\n }\n if (uxi >= uy) {\n uxi -= uy;\n ++q;\n }\n if (uxi == 0) ex = -60;\n else {\n let shift = builtin_clz(uxi << 11);\n ex -= shift;\n uxi <<= shift;\n }\n break;\n } while (false);\n // end:\n if (ex > 0) {\n uxi -= 1 << 52;\n uxi |= ex << 52;\n } else {\n uxi >>= -ex + 1;\n }\n x = reinterpret(uxi);\n y = builtin_abs(y);\n var x2 = x + x;\n if (ex == ey || (ex + 1 == ey && (x2 > y || (x2 == y && (q & 1))))) {\n x -= y;\n // ++q;\n }\n return sx ? -x : x;\n }\n}\n\n/** @internal */\nfunction Rf(z: f32): f32 { // Rational approximation of (asin(x)-x)/x^3\n const // see: musl/src/math/asinf.c and SUN COPYRIGHT NOTICE above\n pS0 = reinterpret(0x3E2AAA75), // 1.6666586697e-01f\n pS1 = reinterpret(0xBD2F13BA), // -4.2743422091e-02f\n pS2 = reinterpret(0xBC0DD36B), // -8.6563630030e-03f\n qS1 = reinterpret(0xBF34E5AE); // -7.0662963390e-01f\n var p = z * (pS0 + z * (pS1 + z * pS2));\n var q: f32 = 1 + z * qS1;\n return p / q;\n}\n\n@inline /** @internal */\nfunction expo2f(x: f32): f32 { // exp(x)/2 for x >= log(DBL_MAX)\n const // see: musl/src/math/__expo2f.c\n k = 235,\n kln2 = reinterpret(0x4322E3BC); // 0x1.45c778p+7f\n var scale = reinterpret((0x7F + k / 2) << 23);\n return NativeMathf.exp(x - kln2) * scale * scale;\n}\n\nexport namespace NativeMathf {\n\n export const E = NativeMath.E;\n export const LN2 = NativeMath.LN2;\n export const LN10 = NativeMath.LN10;\n export const LOG2E = NativeMath.LOG2E;\n export const LOG10E = NativeMath.LOG10E;\n export const PI = NativeMath.PI;\n export const SQRT1_2 = NativeMath.SQRT1_2;\n export const SQRT2 = NativeMath.SQRT2;\n\n @inline\n export function abs(x: f32): f32 {\n return builtin_abs(x);\n }\n\n export function acos(x: f32): f32 { // see: musl/src/math/acosf.c and SUN COPYRIGHT NOTICE above\n const\n pio2_hi = reinterpret(0x3FC90FDA), // 1.5707962513e+00f\n pio2_lo = reinterpret(0x33A22168), // 7.5497894159e-08f\n Ox1p_120f = reinterpret(0x03800000);\n var hx = reinterpret(x);\n var ix = hx & 0x7FFFFFFF;\n if (ix >= 0x3F800000) {\n if (ix == 0x3F800000) {\n if (hx >> 31) return 2 * pio2_hi + Ox1p_120f;\n return 0;\n }\n return 0 / (x - x);\n }\n if (ix < 0x3F000000) {\n if (ix <= 0x32800000) return pio2_hi + Ox1p_120f;\n return pio2_hi - (x - (pio2_lo - x * Rf(x * x)));\n }\n var z: f32, w: f32, s: f32;\n if (hx >> 31) {\n // z = (1 + x) * 0.5;\n z = 0.5 + x * 0.5;\n s = builtin_sqrt(z);\n w = Rf(z) * s - pio2_lo;\n return 2 * (pio2_hi - (s + w));\n }\n // z = (1 - x) * 0.5;\n z = 0.5 - x * 0.5;\n s = builtin_sqrt(z);\n hx = reinterpret(s);\n var df = reinterpret(hx & 0xFFFFF000);\n var c = (z - df * df) / (s + df);\n w = Rf(z) * s + c;\n return 2 * (df + w);\n }\n\n export function acosh(x: f32): f32 { // see: musl/src/math/acoshf.c\n const s = reinterpret(0x3F317218); // 0.693147180559945309417232121458176568f\n var u = reinterpret(x);\n var a = u & 0x7FFFFFFF;\n if (a < 0x3F800000 + (1 << 23)) {\n let xm1 = x - 1;\n return log1p(xm1 + builtin_sqrt(xm1 * (xm1 + 2)));\n }\n if (a < 0x3F800000 + (12 << 23)) return log(2 * x - 1 / (x + builtin_sqrt(x * x - 1)));\n return log(x) + s;\n }\n\n export function asin(x: f32): f32 { // see: musl/src/math/asinf.c and SUN COPYRIGHT NOTICE above\n const\n pio2 = reinterpret(0x3FC90FDB), // 1.570796326794896558e+00f\n Ox1p_120f = reinterpret(0x03800000);\n var sx = x;\n var hx = reinterpret(x) & 0x7FFFFFFF;\n if (hx >= 0x3F800000) {\n if (hx == 0x3F800000) return x * pio2 + Ox1p_120f;\n return 0 / (x - x);\n }\n if (hx < 0x3F000000) {\n if (hx < 0x39800000 && hx >= 0x00800000) return x;\n return x + x * Rf(x * x);\n }\n // var z: f32 = (1 - builtin_abs(x)) * 0.5;\n var z: f32 = 0.5 - builtin_abs(x) * 0.5;\n var s = builtin_sqrt(z); // sic\n x = (pio2 - 2 * (s + s * Rf(z)));\n return builtin_copysign(x, sx);\n }\n\n export function asinh(x: f32): f32 { // see: musl/src/math/asinhf.c\n const c = reinterpret(0x3F317218); // 0.693147180559945309417232121458176568f\n var u = reinterpret(x) & 0x7FFFFFFF;\n var y = reinterpret(u);\n if (u >= 0x3F800000 + (12 << 23)) y = log(y) + c;\n else if (u >= 0x3F800000 + (1 << 23)) y = log(2 * y + 1 / (builtin_sqrt(y * y + 1) + y));\n else if (u >= 0x3F800000 - (12 << 23)) y = log1p(y + y * y / (builtin_sqrt(y * y + 1) + 1));\n return builtin_copysign(y, x);\n }\n\n export function atan(x: f32): f32 { // see: musl/src/math/atanf.c and SUN COPYRIGHT NOTICE above\n const\n atanhi0 = reinterpret(0x3EED6338), // 4.6364760399e-01f\n atanhi1 = reinterpret(0x3F490FDA), // 7.8539812565e-01f\n atanhi2 = reinterpret(0x3F7B985E), // 9.8279368877e-01f\n atanhi3 = reinterpret(0x3FC90FDA), // 1.5707962513e+00f\n atanlo0 = reinterpret(0x31AC3769), // 5.0121582440e-09f\n atanlo1 = reinterpret(0x33222168), // 3.7748947079e-08f\n atanlo2 = reinterpret(0x33140FB4), // 3.4473217170e-08f\n atanlo3 = reinterpret(0x33A22168), // 7.5497894159e-08f\n aT0 = reinterpret(0x3EAAAAA9), // 3.3333328366e-01f\n aT1 = reinterpret(0xBE4CCA98), // -1.9999158382e-01f\n aT2 = reinterpret(0x3E11F50D), // 1.4253635705e-01f\n aT3 = reinterpret(0xBDDA1247), // -1.0648017377e-01f\n aT4 = reinterpret(0x3D7CAC25), // 6.1687607318e-02f\n Ox1p_120f = reinterpret(0x03800000);\n var ix = reinterpret(x);\n var sx = x;\n ix &= 0x7FFFFFFF;\n var z: f32;\n if (ix >= 0x4C800000) {\n if (isNaN(x)) return x;\n z = atanhi3 + Ox1p_120f;\n return builtin_copysign(z, sx);\n }\n var id: i32;\n if (ix < 0x3EE00000) {\n if (ix < 0x39800000) return x;\n id = -1;\n } else {\n x = builtin_abs(x);\n if (ix < 0x3F980000) {\n if (ix < 0x3F300000) {\n id = 0;\n x = (2.0 * x - 1.0) / (2.0 + x);\n } else {\n id = 1;\n x = (x - 1.0) / (x + 1.0);\n }\n } else {\n if (ix < 0x401C0000) {\n id = 2;\n x = (x - 1.5) / (1.0 + 1.5 * x);\n } else {\n id = 3;\n x = -1.0 / x;\n }\n }\n }\n z = x * x;\n var w = z * z;\n var s1 = z * (aT0 + w * (aT2 + w * aT4));\n var s2 = w * (aT1 + w * aT3);\n var s3 = x * (s1 + s2);\n if (id < 0) return x - s3;\n switch (id) {\n case 0: { z = atanhi0 - ((s3 - atanlo0) - x); break; }\n case 1: { z = atanhi1 - ((s3 - atanlo1) - x); break; }\n case 2: { z = atanhi2 - ((s3 - atanlo2) - x); break; }\n case 3: { z = atanhi3 - ((s3 - atanlo3) - x); break; }\n default: unreachable();\n }\n return builtin_copysign(z, sx);\n }\n\n export function atanh(x: f32): f32 { // see: musl/src/math/atanhf.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFF;\n var y = reinterpret(u);\n if (u < 0x3F800000 - (1 << 23)) {\n if (u >= 0x3F800000 - (32 << 23)) y = 0.5 * log1p(2 * y * (1.0 + y / (1 - y)));\n } else y = 0.5 * log1p(2 * (y / (1 - y)));\n return builtin_copysign(y, x);\n }\n\n export function atan2(y: f32, x: f32): f32 { // see: musl/src/math/atan2f.c and SUN COPYRIGHT NOTICE above\n const\n pi = reinterpret(0x40490FDB), // 3.1415927410e+00f\n pi_lo = reinterpret(0xB3BBBD2E); // -8.7422776573e-08f\n if (isNaN(x) || isNaN(y)) return x + y;\n var ix = reinterpret(x);\n var iy = reinterpret(y);\n if (ix == 0x3F800000) return atan(y);\n var m = (((iy >> 31) & 1) | ((ix >> 30) & 2));\n ix &= 0x7FFFFFFF;\n iy &= 0x7FFFFFFF;\n if (iy == 0) {\n switch (m) {\n case 0:\n case 1: return y;\n case 2: return pi;\n case 3: return -pi;\n }\n }\n if (ix == 0) return m & 1 ? -pi / 2 : pi / 2;\n if (ix == 0x7F800000) {\n if (iy == 0x7F800000) {\n switch (m) {\n case 0: return pi / 4;\n case 1: return -pi / 4;\n case 2: return 3 * pi / 4;\n case 3: return -3 * pi / 4;\n }\n } else {\n switch (m) {\n case 0: return 0;\n case 1: return -0;\n case 2: return pi;\n case 3: return -pi;\n }\n }\n }\n if (ix + (26 << 23) < iy || iy == 0x7F800000) return m & 1 ? -pi / 2 : pi / 2;\n var z: f32;\n if ((m & 2) && iy + (26 << 23) < ix) z = 0.0;\n else z = atan(builtin_abs(y / x));\n switch (m) {\n case 0: return z;\n case 1: return -z;\n case 2: return pi - (z - pi_lo);\n case 3: return (z - pi_lo) - pi;\n }\n unreachable();\n return 0;\n }\n\n export function cbrt(x: f32): f32 { // see: musl/src/math/cbrtf.c and SUN COPYRIGHT NOTICE above\n const\n B1 = 709958130,\n B2 = 642849266,\n Ox1p24f = reinterpret(0x4B800000);\n var u = reinterpret(x);\n var hx = u & 0x7FFFFFFF;\n if (hx >= 0x7F800000) return x + x;\n if (hx < 0x00800000) {\n if (hx == 0) return x;\n u = reinterpret(x * Ox1p24f);\n hx = u & 0x7FFFFFFF;\n hx = hx / 3 + B2;\n } else {\n hx = hx / 3 + B1;\n }\n u &= 0x80000000;\n u |= hx;\n var t = reinterpret(u);\n var r = t * t * t;\n t = t * (x + x + r) / (x + r + r);\n r = t * t * t;\n t = t * (x + x + r) / (x + r + r);\n return t;\n }\n\n @inline\n export function ceil(x: f32): f32 {\n return builtin_ceil(x);\n }\n\n @inline\n export function clz32(x: f32): f32 {\n return builtin_clz(x);\n }\n\n export function cos(x: f32): f32 { // TODO\n unreachable();\n return 0;\n }\n\n export function cosh(x: f32): f32 { // see: musl/src/math/coshf.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFF;\n x = reinterpret(u);\n if (u < 0x3F317217) {\n if (u < 0x3F800000 - (12 << 23)) return 1;\n let t = expm1(x);\n // return 1 + t * t / (2 * (1 + t));\n return 1 + t * t / (2 + 2 * t);\n }\n if (u < 0x42B17217) {\n let t = exp(x);\n // return 0.5 * (t + 1 / t);\n return 0.5 * t + 0.5 / t;\n }\n return expo2f(x);\n }\n\n @inline\n export function floor(x: f32): f32 {\n return builtin_floor(x);\n }\n\n export function exp(x: f32): f32 { // see: musl/src/math/expf.c and SUN COPYRIGHT NOTICE above\n const\n ln2hi = reinterpret(0x3F317200), // 6.9314575195e-1f\n ln2lo = reinterpret(0x35BFBE8E), // 1.4286067653e-6f\n invln2 = reinterpret(0x3FB8AA3B), // 1.4426950216e+0f\n P1 = reinterpret(0x3E2AAA8F), // 1.6666625440e-1f\n P2 = reinterpret(0xBB355215), // -2.7667332906e-3f\n Ox1p127f = reinterpret(0x7F000000);\n var hx = reinterpret(x);\n var sign_ = (hx >> 31);\n hx &= 0x7FFFFFFF;\n if (hx >= 0x42AEAC50) {\n if (hx >= 0x42B17218) {\n if (!sign_) {\n x *= Ox1p127f;\n return x;\n } else {\n if (hx >= 0x42CFF1B5) return 0;\n }\n }\n }\n var hi: f32, lo: f32;\n var k: i32;\n if (hx > 0x3EB17218) {\n if (hx > 0x3F851592) {\n k = (invln2 * x + builtin_copysign(0.5, x));\n } else {\n k = 1 - (sign_ << 1);\n }\n hi = x - k * ln2hi;\n lo = k * ln2lo;\n x = hi - lo;\n } else if (hx > 0x39000000) {\n k = 0;\n hi = x;\n lo = 0;\n } else {\n return 1 + x;\n }\n var xx = x * x;\n var c = x - xx * (P1 + xx * P2);\n var y: f32 = 1 + (x * c / (2 - c) - lo + hi);\n if (k == 0) return y;\n return scalbn(y, k);\n }\n\n export function expm1(x: f32): f32 { // see: musl/src/math/expm1f.c and SUN COPYRIGHT NOTICE above\n const\n o_threshold = reinterpret(0x42B17180), // 8.8721679688e+01f\n ln2_hi = reinterpret(0x3F317180), // 6.9313812256e-01f\n ln2_lo = reinterpret(0x3717F7D1), // 9.0580006145e-06f\n invln2 = reinterpret(0x3FB8AA3B), // 1.4426950216e+00f\n Q1 = reinterpret(0xBD088868), // -3.3333212137e-02f\n Q2 = reinterpret(0x3ACF3010), // 1.5807170421e-03f\n Ox1p127f = reinterpret(0x7F000000);\n var u = reinterpret(x);\n var hx = u & 0x7FFFFFFF;\n var sign_ = (u >> 31);\n if (hx >= 0x4195B844) {\n if (hx > 0x7F800000) return x;\n if (sign_) return -1;\n if (x > o_threshold) {\n x *= Ox1p127f;\n return x;\n }\n }\n var c: f32 = 0.0, t: f32, k: i32;\n if (hx > 0x3EB17218) {\n k = select(\n 1 - (sign_ << 1),\n (invln2 * x + builtin_copysign(0.5, x)),\n hx < 0x3F851592\n );\n t = k;\n let hi = x - t * ln2_hi;\n let lo = t * ln2_lo;\n x = hi - lo;\n c = (hi - x) - lo;\n } else if (hx < 0x33000000) {\n return x;\n } else k = 0;\n var hfx: f32 = 0.5 * x;\n var hxs: f32 = x * hfx;\n var r1: f32 = 1.0 + hxs * (Q1 + hxs * Q2);\n t = 3.0 - r1 * hfx;\n var e = hxs * ((r1 - t) / (6.0 - x * t));\n if (k == 0) return x - (x * e - hxs);\n e = x * (e - c) - c;\n e -= hxs;\n if (k == -1) return 0.5 * (x - e) - 0.5;\n if (k == 1) {\n if (x < -0.25) return -2.0 * (e - (x + 0.5));\n return 1.0 + 2.0 * (x - e);\n }\n u = (0x7F + k) << 23;\n var twopk = reinterpret(u);\n var y: f32;\n if (k < 0 || k > 56) {\n y = x - e + 1.0;\n if (k == 128) y = y * 2.0 * Ox1p127f;\n else y = y * twopk;\n return y - 1.0;\n }\n u = (0x7F - k) << 23;\n y = reinterpret(u);\n if (k < 20) y = (1 - y) - e;\n else y = 1 - (e + y);\n return (x + y) * twopk;\n }\n\n @inline\n export function fround(x: f32): f32 {\n return x;\n }\n\n export function hypot(x: f32, y: f32): f32 { // see: musl/src/math/hypotf.c\n const\n Ox1p90f = reinterpret(0x6C800000),\n Ox1p_90f = reinterpret(0x12800000);\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n ux &= 0x7FFFFFFF;\n uy &= 0x7FFFFFFF;\n if (ux < uy) {\n let ut = ux;\n ux = uy;\n uy = ut;\n }\n x = reinterpret(ux);\n y = reinterpret(uy);\n if (uy == 0xFF << 23) return y;\n if (ux >= 0xFF << 23 || uy == 0 || ux - uy >= 25 << 23) return x + y;\n var z: f32 = 1;\n if (ux >= (0x7F + 60) << 23) {\n z = Ox1p90f;\n x *= Ox1p_90f;\n y *= Ox1p_90f;\n } else if (uy < (0x7F - 60) << 23) {\n z = Ox1p_90f;\n x *= Ox1p90f;\n y *= Ox1p90f;\n }\n return z * builtin_sqrt((x * x + y * y));\n }\n\n @inline\n export function imul(x: f32, y: f32): f32 {\n return (x * y);\n }\n\n export function log(x: f32): f32 { // see: musl/src/math/logf.c and SUN COPYRIGHT NOTICE above\n const\n ln2_hi = reinterpret(0x3F317180), // 6.9313812256e-01f\n ln2_lo = reinterpret(0x3717F7D1), // 9.0580006145e-06f\n Lg1 = reinterpret(0x3F2AAAAA), // 0xaaaaaa.0p-24f\n Lg2 = reinterpret(0x3ECCCE13), // 0xccce13.0p-25f\n Lg3 = reinterpret(0x3E91E9EE), // 0x91e9ee.0p-25f\n Lg4 = reinterpret(0x3E789E26), // 0xf89e26.0p-26f\n Ox1p25f = reinterpret(0x4C000000);\n var u = reinterpret(x);\n var k = 0;\n if (u < 0x00800000 || (u >> 31)) {\n if (u << 1 == 0) return -1 / (x * x);\n if (u >> 31) return (x - x) / 0;\n k -= 25;\n x *= Ox1p25f;\n u = reinterpret(x);\n } else if (u >= 0x7F800000) return x;\n else if (u == 0x3F800000) return 0;\n u += 0x3F800000 - 0x3F3504F3;\n k += (u >> 23) - 0x7F;\n u = (u & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(u);\n var f = x - 1.0;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * Lg4);\n var t2 = z * (Lg1 + w * Lg3);\n var r = t2 + t1;\n var hfsq = 0.5 * f * f;\n var dk = k;\n return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;\n }\n\n export function log10(x: f32): f32 { // see: musl/src/math/log10f.c and SUN COPYRIGHT NOTICE above\n const\n ivln10hi = reinterpret(0x3EDE6000), // 4.3432617188e-01f\n ivln10lo = reinterpret(0xB804EAD9), // -3.1689971365e-05f\n log10_2hi = reinterpret(0x3E9A2080), // 3.0102920532e-01f\n log10_2lo = reinterpret(0x355427DB), // 7.9034151668e-07f\n Lg1 = reinterpret(0x3F2AAAAA), // 0xaaaaaa.0p-24f, 0.66666662693f\n Lg2 = reinterpret(0x3ECCCE13), // 0xccce13.0p-25f, 0.40000972152f\n Lg3 = reinterpret(0x3E91E9EE), // 0x91e9ee.0p-25f, 0.28498786688f\n Lg4 = reinterpret(0x3E789E26), // 0xf89e26.0p-26f, 0.24279078841f\n Ox1p25f = reinterpret(0x4C000000);\n var ix = reinterpret(x);\n var k = 0;\n if (ix < 0x00800000 || (ix >> 31)) {\n if (ix << 1 == 0) return -1 / (x * x);\n if (ix >> 31) return (x - x) / 0.0;\n k -= 25;\n x *= Ox1p25f;\n ix = reinterpret(x);\n } else if (ix >= 0x7F800000) return x;\n else if (ix == 0x3F800000) return 0;\n ix += 0x3F800000 - 0x3F3504F3;\n k += (ix >> 23) - 0x7F;\n ix = (ix & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(ix);\n var f = x - 1.0;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * Lg4);\n var t2 = z * (Lg1 + w * Lg3);\n var r = t2 + t1;\n var hfsq: f32 = 0.5 * f * f;\n var hi = f - hfsq;\n ix = reinterpret(hi);\n ix &= 0xFFFFF000;\n hi = reinterpret(ix);\n var lo = f - hi - hfsq + s * (hfsq + r);\n var dk = k;\n return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;\n }\n\n export function log1p(x: f32): f32 { // see: musl/src/math/log1pf.c and SUN COPYRIGHT NOTICE above\n const\n ln2_hi = reinterpret(0x3F317180), // 6.9313812256e-01\n ln2_lo = reinterpret(0x3717F7D1), // 9.0580006145e-06\n Lg1 = reinterpret(0x3F2AAAAA), // 0xaaaaaa.0p-24f, 0.66666662693f\n Lg2 = reinterpret(0x3ECCCE13), // 0xccce13.0p-25f, 0.40000972152f\n Lg3 = reinterpret(0x3E91E9EE), // 0x91e9ee.0p-25f, 0.28498786688f\n Lg4 = reinterpret(0x3E789E26); // 0xf89e26.0p-26f, 0.24279078841f\n var ix = reinterpret(x);\n var c: f32 = 0, f: f32 = 0;\n var k: i32 = 1;\n if (ix < 0x3ED413D0 || (ix >> 31)) {\n if (ix >= 0xBF800000) {\n if (x == -1) return x / 0.0;\n return (x - x) / 0.0;\n }\n if (ix << 1 < 0x33800000 << 1) return x;\n if (ix <= 0xBE95F619) {\n k = 0;\n c = 0;\n f = x;\n }\n } else if (ix >= 0x7F800000) return x;\n if (k) {\n let uf: f32 = 1 + x;\n let iu = reinterpret(uf);\n iu += 0x3F800000 - 0x3F3504F3;\n k = (iu >> 23) - 0x7F;\n if (k < 25) {\n c = k >= 2 ? 1 - (uf - x) : x - (uf - 1);\n c /= uf;\n } else c = 0;\n iu = (iu & 0x007FFFFF) + 0x3F3504F3;\n f = reinterpret(iu) - 1;\n }\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * Lg4);\n var t2 = z * (Lg1 + w * Lg3);\n var r = t2 + t1;\n var hfsq: f32 = 0.5 * f * f;\n var dk = k;\n return s * (hfsq + r) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;\n }\n\n export function log2(x: f32): f32 { // see: musl/src/math/log2f.c and SUN COPYRIGHT NOTICE above\n const\n ivln2hi = reinterpret(0x3FB8B000), // 1.4428710938e+00f\n ivln2lo = reinterpret(0xB9389AD4), // -1.7605285393e-04\n Lg1 = reinterpret(0x3F2AAAAA), // 0xaaaaaa.0p-24f, 0.66666662693f\n Lg2 = reinterpret(0x3ECCCE13), // 0xccce13.0p-25f, 0.40000972152f\n Lg3 = reinterpret(0x3E91E9EE), // 0x91e9ee.0p-25f, 0.28498786688f\n Lg4 = reinterpret(0x3E789E26), // 0xf89e26.0p-26f, 0.24279078841f\n Ox1p25f = reinterpret(0x4C000000);\n var ix = reinterpret(x);\n var k: i32 = 0;\n if (ix < 0x00800000 || (ix >> 31)) {\n if (ix << 1 == 0) return -1 / (x * x);\n if (ix >> 31) return (x - x) / 0.0;\n k -= 25;\n x *= Ox1p25f;\n ix = reinterpret(x);\n } else if (ix >= 0x7F800000) return x;\n else if (ix == 0x3F800000) return 0;\n ix += 0x3F800000 - 0x3F3504F3;\n k += (ix >> 23) - 0x7F;\n ix = (ix & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(ix);\n var f = x - 1.0;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * Lg4);\n var t2 = z * (Lg1 + w * Lg3);\n var r = t2 + t1;\n var hfsq: f32 = 0.5 * f * f;\n var hi = f - hfsq;\n var u = reinterpret(hi);\n u &= 0xFFFFF000;\n hi = reinterpret(u);\n var lo: f32 = f - hi - hfsq + s * (hfsq + r);\n var dk = k;\n return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + dk;\n }\n\n @inline\n export function max(value1: f32, value2: f32): f32 {\n return builtin_max(value1, value2);\n }\n\n @inline\n export function min(value1: f32, value2: f32): f32 {\n return builtin_min(value1, value2);\n }\n\n export function pow(x: f32, y: f32): f32 { // see: musl/src/math/powf.c and SUN COPYRIGHT NOTICE above\n const\n dp_h1 = reinterpret(0x3F15C000), // 5.84960938e-01f\n dp_l1 = reinterpret(0x35D1CFDC), // 1.56322085e-06f\n two24 = reinterpret(0x4B800000), // 16777216f\n huge = reinterpret(0x7149F2CA), // 1.0e+30f\n tiny = reinterpret(0x0DA24260), // 1.0e-30f\n L1 = reinterpret(0x3F19999A), // 6.0000002384e-01f\n L2 = reinterpret(0x3EDB6DB7), // 4.2857143283e-01f\n L3 = reinterpret(0x3EAAAAAB), // 3.3333334327e-01f\n L4 = reinterpret(0x3E8BA305), // 2.7272811532e-01f\n L5 = reinterpret(0x3E6C3255), // 2.3066075146e-01f\n L6 = reinterpret(0x3E53F142), // 2.0697501302e-01f\n P1 = reinterpret(0x3E2AAAAB), // 1.6666667163e-01f\n P2 = reinterpret(0xBB360B61), // -2.7777778450e-03f\n P3 = reinterpret(0x388AB355), // 6.6137559770e-05f\n P4 = reinterpret(0xB5DDEA0E), // -1.6533901999e-06f\n P5 = reinterpret(0x3331BB4C), // 4.1381369442e-08f\n lg2 = reinterpret(0x3F317218), // 6.9314718246e-01f\n lg2_h = reinterpret(0x3F317200), // 6.93145752e-01f\n lg2_l = reinterpret(0x35BFBE8C), // 1.42860654e-06f\n ovt = reinterpret(0x3338AA3C), // 4.2995665694e-08f\n cp = reinterpret(0x3F76384F), // 9.6179670095e-01\n cp_h = reinterpret(0x3F764000), // 9.6191406250e-01\n cp_l = reinterpret(0xB8F623C6), // -1.1736857402e-04\n ivln2 = reinterpret(0x3FB8AA3B), // 1.4426950216e+00\n ivln2_h = reinterpret(0x3FB8AA00), // 1.4426879883e+00\n ivln2_l = reinterpret(0x36ECA570), // 7.0526075433e-06\n inv3 = reinterpret(0x3EAAAAAB); // 0.333333333333\n var hx = reinterpret(x);\n var hy = reinterpret(y);\n var ix = hx & 0x7FFFFFFF;\n var iy = hy & 0x7FFFFFFF;\n if (iy == 0) return 1.0; // x**0 = 1, even if x is NaN\n // if (hx == 0x3F800000) return 1.0; // C: 1**y = 1, even if y is NaN, JS: NaN\n if (ix > 0x7F800000 || iy > 0x7F800000) return x + y; // NaN if either arg is NaN\n var yisint = 0, j: i32, k: i32;\n if (hx < 0) {\n if (iy >= 0x4B800000) yisint = 2;\n else if (iy >= 0x3F800000) {\n k = (iy >> 23) - 0x7F;\n j = iy >> (23 - k);\n if ((j << (23 - k)) == iy) yisint = 2 - (j & 1);\n }\n }\n if (iy == 0x7F800000) { // y is +-inf\n if (ix == 0x3F800000) return NaN; // C: (-1)**+-inf is 1, JS: NaN\n else if (ix > 0x3F800000) return hy >= 0 ? y : 0.0; // (|x|>1)**+-inf = inf,0\n else return hy >= 0 ? 0.0 : -y; // (|x|<1)**+-inf = 0,inf\n }\n if (iy == 0x3F800000) return hy >= 0 ? x : 1.0 / x;\n if (hy == 0x40000000) return x * x;\n if (hy == 0x3F000000) {\n if (hx >= 0) return builtin_sqrt(x);\n }\n var ax = builtin_abs(x);\n var z: f32;\n if (ix == 0x7F800000 || ix == 0 || ix == 0x3F800000) {\n z = ax;\n if (hy < 0) z = 1.0 / z;\n if (hx < 0) {\n if (((ix - 0x3F800000) | yisint) == 0) z = (z - z) / (z - z);\n else if (yisint == 1) z = -z;\n }\n return z;\n }\n var sn = 1.0;\n if (hx < 0) {\n if (yisint == 0) return (x - x) / (x - x);\n if (yisint == 1) sn = -1.0;\n }\n var t1: f32, t2: f32, r: f32, s: f32, t: f32, u: f32, v: f32, w: f32, p_h: f32, p_l: f32;\n var n: i32, is: i32;\n if (iy > 0x4D000000) {\n if (ix < 0x3F7FFFF8) return hy < 0 ? sn * huge * huge : sn * tiny * tiny;\n if (ix > 0x3F800007) return hy > 0 ? sn * huge * huge : sn * tiny * tiny;\n t = ax - 1;\n w = (t * t) * (0.5 - t * (inv3 - t * 0.25));\n u = ivln2_h * t;\n v = t * ivln2_l - w * ivln2;\n t1 = u + v;\n is = reinterpret(t1);\n t1 = reinterpret(is & 0xFFFFF000);\n t2 = v - (t1 - u);\n } else {\n let s2: f32, s_h: f32, s_l: f32, t_h: f32, t_l: f32;\n n = 0;\n if (ix < 0x00800000) {\n ax *= two24;\n n -= 24;\n ix = reinterpret(ax);\n }\n n += (ix >> 23) - 0x7F;\n j = ix & 0x007FFFFF;\n ix = j | 0x3F800000;\n if (j <= 0x1CC471) k = 0;\n else if (j < 0x5DB3D7) k = 1;\n else {\n k = 0;\n n += 1;\n ix -= 0x00800000;\n }\n ax = reinterpret(ix);\n let bp = select(1.5, 1.0, k); // k ? 1.5 : 1.0\n u = ax - bp;\n v = 1.0 / (ax + bp);\n s = u * v;\n s_h = s;\n is = reinterpret(s_h);\n s_h = reinterpret(is & 0xFFFFF000);\n is = ((ix >> 1) & 0xFFFFF000) | 0x20000000;\n t_h = reinterpret(is + 0x00400000 + (k << 21));\n t_l = ax - (t_h - bp);\n s_l = v * ((u - s_h * t_h) - s_h * t_l);\n s2 = s * s;\n r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));\n r += s_l * (s_h + s);\n s2 = s_h * s_h;\n t_h = 3.0 + s2 + r;\n is = reinterpret(t_h);\n t_h = reinterpret(is & 0xFFFFF000);\n t_l = r - ((t_h - 3.0) - s2);\n u = s_h * t_h;\n v = s_l * t_h + t_l * s;\n p_h = u + v;\n is = reinterpret(p_h);\n p_h = reinterpret(is & 0xFFFFF000);\n p_l = v - (p_h - u);\n let z_h = cp_h * p_h;\n let dp_l = select(dp_l1, 0.0, k);\n let z_l = cp_l * p_h + p_l * cp + dp_l;\n t = n;\n let dp_h = select(dp_h1, 0.0, k);\n t1 = (((z_h + z_l) + dp_h) + t);\n is = reinterpret(t1);\n t1 = reinterpret(is & 0xFFFFF000);\n t2 = z_l - (((t1 - t) - dp_h) - z_h);\n }\n is = reinterpret(y);\n var y1 = reinterpret(is & 0xFFFFF000);\n p_l = (y - y1) * t1 + y * t2;\n p_h = y1 * t1;\n z = p_l + p_h;\n j = reinterpret(z);\n if (j > 0x43000000) {\n return sn * huge * huge;\n } else if (j == 0x43000000) {\n if (p_l + ovt > z - p_h) return sn * huge * huge;\n } else if ((j & 0x7FFFFFFF) > 0x43160000) {\n return sn * tiny * tiny;\n } else if (j == 0xC3160000) {\n if (p_l <= z - p_h) return sn * tiny * tiny;\n }\n var i = j & 0x7FFFFFFF;\n k = (i >> 23) - 0x7F;\n n = 0;\n if (i > 0x3F000000) {\n n = j + (0x00800000 >> (k + 1));\n k = ((n & 0x7FFFFFFF) >> 23) - 0x7F;\n t = reinterpret(n & ~(0x007FFFFF >> k));\n n = ((n & 0x007FFFFF) | 0x00800000) >> (23 - k);\n if (j < 0) n = -n;\n p_h -= t;\n }\n t = p_l + p_h;\n is = reinterpret(t);\n t = reinterpret(is & 0xFFFF8000);\n u = t * lg2_h;\n v = (p_l - (t - p_h)) * lg2 + t * lg2_l;\n z = u + v;\n w = v - (z - u);\n t = z * z;\n t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));\n r = (z * t1) / (t1 - 2.0) - (w + z * w);\n z = 1.0 - (r - z);\n j = reinterpret(z);\n j += n << 23;\n if ((j >> 23) <= 0) z = scalbn(z, n);\n else z = reinterpret(j);\n return sn * z;\n }\n\n @inline\n export function seedRandom(value: i64): void {\n NativeMath.seedRandom(value);\n }\n\n // Using xoroshiro64starstar from http://xoshiro.di.unimi.it/xoroshiro64starstar.c\n export function random(): f32 {\n if (!random_seeded) throw new Error("PRNG must be seeded.");\n\n var s0 = random_state0_32;\n var s1 = random_state1_32;\n var r = rotl(s0 * 0x9E3779BB, 5) * 5;\n\n s1 ^= s0;\n random_state0_32 = rotl(s0, 26) ^ s1 ^ (s1 << 9);\n random_state1_32 = rotl(s1, 13);\n\n return reinterpret((r >> 9) | (127 << 23)) - 1.0;\n }\n\n @inline\n export function round(x: f32): f32 {\n return builtin_copysign(builtin_floor(x + 0.5), x);\n }\n\n @inline\n export function sign(x: f32): f32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return builtin_abs(x) > 0 ? builtin_copysign(1, x) : x;\n } else {\n return x > 0 ? 1 : x < 0 ? -1 : x;\n }\n }\n\n export function sin(x: f32): f32 { // TODO\n unreachable();\n return 0;\n }\n\n export function sinh(x: f32): f32 { // see: musl/src/math/sinhf.c\n var u = reinterpret(x) & 0x7FFFFFFF;\n var absx = reinterpret(u);\n var t: f32;\n var h = builtin_copysign(0.5, x);\n if (u < 0x42B17217) {\n t = expm1(absx);\n if (u < 0x3F800000) {\n if (u < 0x3F800000 - (12 << 23)) return x;\n return h * (2 * t - t * t / (t + 1));\n }\n return h * (t + t / (t + 1));\n }\n t = 2 * h * expo2f(absx);\n return t;\n }\n\n @inline\n export function sqrt(x: f32): f32 {\n return builtin_sqrt(x);\n }\n\n export function tan(x: f32): f32 { // TODO\n unreachable();\n return 0;\n }\n\n export function tanh(x: f32): f32 { // see: musl/src/math/tanhf.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFF;\n var y = reinterpret(u);\n var t: f32;\n if (u > 0x3F0C9F54) {\n if (u > 0x41200000) t = 1 + 0 / y;\n else {\n t = expm1(2 * y);\n t = 1 - 2 / (t + 2);\n }\n } else if (u > 0x3E82C578) {\n t = expm1(2 * y);\n t = t / (t + 2);\n } else if (u >= 0x00800000) {\n t = expm1(-2 * y);\n t = -t / (t + 2);\n } else t = y;\n return builtin_copysign(t, x);\n }\n\n @inline\n export function trunc(x: f32): f32 {\n return builtin_trunc(x);\n }\n\n /** @internal */\n export function scalbn(x: f32, n: i32): f32 { // see: https://git.musl-libc.org/cgit/musl/tree/src/math/scalbnf.c\n const\n Ox1p24f = reinterpret(0x4B800000),\n Ox1p127f = reinterpret(0x7F000000),\n Ox1p_126f = reinterpret(0x00800000);\n var y = x;\n if (n > 127) {\n y *= Ox1p127f;\n n -= 127;\n if (n > 127) {\n y *= Ox1p127f;\n n = builtin_min(n - 127, 127);\n }\n } else if (n < -126) {\n y *= Ox1p_126f * Ox1p24f;\n n += 126 - 24;\n if (n < -126) {\n y *= Ox1p_126f * Ox1p24f;\n n = builtin_max(n + 126 - 24, -126);\n }\n }\n return y * reinterpret((0x7F + n) << 23);\n }\n\n export function mod(x: f32, y: f32): f32 { // see: musl/src/math/fmodf.c\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = (ux >> 23 & 0xFF);\n var ey = (uy >> 23 & 0xFF);\n var sx = ux & 0x80000000;\n var uy1 = uy << 1;\n if (uy1 == 0 || ex == 0xFF || isNaN(y)) return (x * y) / (x * y);\n var ux1 = ux << 1;\n if (ux1 <= uy1) {\n if (ux1 == uy1) return 0 * x;\n return x;\n }\n if (!ex) {\n ex -= builtin_clz(ux << 9);\n ux <<= -ex + 1;\n } else {\n ux &= -1 >> 9;\n ux |= 1 << 23;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 9);\n uy <<= -ey + 1;\n } else {\n uy &= -1 >> 9;\n uy |= 1 << 23;\n }\n while (ex > ey) {\n if (ux >= uy) {\n if (ux == uy) return 0 * x;\n ux -= uy;\n }\n ux <<= 1;\n --ex;\n }\n if (ux >= uy) {\n if (ux == uy) return 0 * x;\n ux -= uy;\n }\n // for (; !(ux >> 23); ux <<= 1) --ex;\n var shift = builtin_clz(ux << 8);\n ex -= shift;\n ux <<= shift;\n if (ex > 0) {\n ux -= 1 << 23;\n ux |= ex << 23;\n } else {\n ux >>= -ex + 1;\n }\n ux |= sx;\n return reinterpret(ux);\n }\n\n export function rem(x: f32, y: f32): f32 { // see: musl/src/math/remquof.c\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = (ux >> 23 & 0xFF);\n var ey = (uy >> 23 & 0xFF);\n var sx = (ux >> 31);\n var uxi = ux;\n if (uy << 1 == 0 || ex == 0xFF || isNaN(y)) return (x * y) / (x * y);\n if (ux << 1 == 0) return x;\n if (!ex) {\n ex -= builtin_clz(uxi << 9);\n uxi <<= -ex + 1;\n } else {\n uxi &= -1 >> 9;\n uxi |= 1 << 23;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 9);\n uy <<= -ey + 1;\n } else {\n uy &= -1 >> 9;\n uy |= 1 << 23;\n }\n var q = 0;\n do {\n if (ex < ey) {\n if (ex + 1 == ey) break; // goto end\n return x;\n }\n while (ex > ey) {\n if (uxi >= uy) {\n uxi -= uy;\n ++q;\n }\n uxi <<= 1;\n q <<= 1;\n --ex;\n }\n if (uxi >= uy) {\n uxi -= uy;\n ++q;\n }\n if (uxi == 0) ex = -30;\n else {\n let shift = builtin_clz(uxi << 8);\n ex -= shift;\n uxi <<= shift;\n }\n break;\n } while (false);\n // end\n if (ex > 0) {\n uxi -= 1 << 23;\n uxi |= ex << 23;\n } else {\n uxi >>= -ex + 1;\n }\n x = reinterpret(uxi);\n y = builtin_abs(y);\n var x2 = x + x;\n if (ex == ey || (ex + 1 == ey && (x2 > y || (x2 == y && (q & 1))))) {\n x -= y;\n // q++;\n }\n return sx ? -x : x;\n }\n}\n\nexport function ipow32(x: i32, e: i32): i32 {\n var out = 1;\n if (ASC_SHRINK_LEVEL < 1) {\n if (e < 0) return 0;\n\n switch (e) {\n case 0: return 1;\n case 1: return x;\n case 2: return x * x;\n }\n\n let log = 32 - clz(e);\n if (log <= 5) {\n // 32 = 2 ^ 5, so need only five cases.\n // But some extra cases needs for properly overflowing\n switch (log) {\n case 5: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 4: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 3: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 2: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 1: {\n if (e & 1) out *= x;\n }\n }\n return out;\n }\n }\n\n while (e > 0) {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n return out;\n}\n\nexport function ipow64(x: i64, e: i32): i64 {\n var out: i64 = 1;\n if (ASC_SHRINK_LEVEL < 1) {\n if (e < 0) return 0;\n switch (e) {\n case 0: return 1;\n case 1: return x;\n case 2: return x * x;\n }\n\n let log = 32 - clz(e);\n if (log <= 6) {\n // 64 = 2 ^ 6, so need only six cases.\n // But some extra cases needs for properly overflowing\n switch (log) {\n case 6: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 5: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 4: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 3: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 2: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 1: {\n if (e & 1) out *= x;\n }\n }\n return out;\n }\n }\n\n while (e > 0) {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n return out;\n}\n',memory:'import { memcmp, memmove, memset } from "./internal/memory";\n\n@builtin export declare const HEAP_BASE: usize; // tslint:disable-line\n\n/* tslint:disable */\n\nexport namespace memory {\n\n @builtin export declare function size(): i32;\n\n @builtin export declare function grow(pages: i32): i32;\n\n @inline export function fill(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset\n if (isDefined(__memory_fill)) { __memory_fill(dest, c, n); return; }\n memset(dest, c, n);\n }\n\n @inline export function copy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c\n if (isDefined(__memory_copy)) { __memory_copy(dest, src, n); return; }\n memmove(dest, src, n);\n }\n\n @inline export function compare(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c\n if (isDefined(__memory_compare)) return __memory_compare(vl, vr, n);\n return memcmp(vl, vr, n);\n }\n\n // Passive segments\n\n // export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void {\n // __memory_init(segmentIndex, srcOffset, dstOffset);\n // }\n\n // export function drop(segmentIndex: u32): void {\n // __memory_drop(segmentIndex);\n // }\n\n // Allocator\n\n @inline export function allocate(size: usize): usize {\n if (isDefined(__memory_allocate)) return __memory_allocate(size);\n WARNING("Calling \'memory.allocate\' requires a memory manager to be present.");\n return unreachable();\n }\n\n @inline export function free(ptr: usize): void {\n if (isDefined(__memory_free)) { __memory_free(ptr); return; }\n WARNING("Calling \'memory.free\' requires a memory manager to be present.");\n unreachable();\n }\n\n @inline export function reset(): void {\n if (isDefined(__memory_reset)) { __memory_reset(); return; }\n unreachable();\n }\n}\n',polyfills:"export function bswap(value: T): T {\n assert(sizeof() == 1 || sizeof() == 2 || sizeof() == 4 || sizeof() == 8);\n\n if (sizeof() == 2) {\n return bswap16(value);\n }\n if (sizeof() == 4) {\n return (\n rotl(value & 0xFF00FF00, 8) |\n rotr(value & 0x00FF00FF, 8)\n );\n }\n if (sizeof() == 8) {\n let a: u64 = (value >> 8) & 0x00FF00FF00FF00FF;\n let b: u64 = (value & 0x00FF00FF00FF00FF) << 8;\n let v: u64 = a | b;\n\n a = (v >> 16) & 0x0000FFFF0000FFFF;\n b = (v & 0x0000FFFF0000FFFF) << 16;\n\n return rotr(a | b, 32);\n }\n return value;\n}\n\nexport function bswap16(value: T): T {\n assert(sizeof() == 1 || sizeof() == 2 || sizeof() == 4);\n\n if (sizeof() == 2 || sizeof() == 4) {\n return (((value << 8) & 0xFF00) | ((value >> 8) & 0x00FF) | (value & 0xFFFF0000));\n }\n return value;\n}\n",regexp:'export class RegExp {\n\n // @binding(CALL_NEW, [ STRING, STRING], OBJECT_HANDLE)\n constructor(pattern: string, flags: string = "") { throw new Error("unreachable"); }\n\n // @binding(CALL_THIS, [ STRING ], PASS_THRU)\n test(search: string): bool { throw new Error("unreachable"); }\n\n // @binding(CALL_THIS, [], STRING)\n toString(): string { throw new Error("unreachable"); }\n\n}\n',set:'import {\n HEADER_SIZE as HEADER_SIZE_AB\n} from "./internal/arraybuffer";\n\nimport {\n hash\n} from "./internal/hash";\n\n// A deterministic hash set based on CloseTable from https://github.com/jorendorff/dht\n\nconst INITIAL_CAPACITY = 4;\nconst FILL_FACTOR: f64 = 8 / 3;\nconst FREE_FACTOR: f64 = 3 / 4;\n\n/** Structure of a set entry. */\n@unmanaged class SetEntry {\n key: K;\n taggedNext: usize; // LSB=1 indicates EMPTY\n}\n\n/** Empty bit. */\nconst EMPTY: usize = 1 << 0;\n\n/** Size of a bucket. */\nconst BUCKET_SIZE = sizeof();\n\n/** Computes the alignment of an entry. */\n@inline function ENTRY_ALIGN(): usize {\n // can align to 4 instead of 8 if 32-bit and K is <= 32-bits\n const align = (sizeof() > sizeof() ? sizeof() : sizeof()) - 1;\n return align;\n}\n\n/** Computes the aligned size of an entry. */\n@inline function ENTRY_SIZE(): usize {\n const align = ENTRY_ALIGN();\n const size = (offsetof>() + align) & ~align;\n return size;\n}\n\nexport class Set {\n\n // buckets holding references to the respective first entry within\n private buckets: ArrayBuffer; // usize[bucketsMask + 1]\n private bucketsMask: u32;\n\n // entries in insertion order\n private entries: ArrayBuffer; // SetEntry[entriesCapacity]\n private entriesCapacity: i32;\n private entriesOffset: i32;\n private entriesCount: i32;\n\n get size(): i32 { return this.entriesCount; }\n\n constructor() { this.clear(); }\n\n clear(): void {\n const bucketsSize = INITIAL_CAPACITY * BUCKET_SIZE;\n this.buckets = new ArrayBuffer(bucketsSize);\n this.bucketsMask = INITIAL_CAPACITY - 1;\n const entriesSize = INITIAL_CAPACITY * ENTRY_SIZE();\n this.entries = new ArrayBuffer(entriesSize, true);\n this.entriesCapacity = INITIAL_CAPACITY;\n this.entriesOffset = 0;\n this.entriesCount = 0;\n }\n\n private find(key: K, hashCode: u32): SetEntry | null {\n var entry = load>(\n changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE,\n HEADER_SIZE_AB\n );\n while (entry) {\n if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry;\n entry = changetype>(entry.taggedNext & ~EMPTY);\n }\n return null;\n }\n\n has(key: K): bool {\n return this.find(key, hash(key)) !== null;\n }\n\n add(key: K): void {\n var hashCode = hash(key);\n var entry = this.find(key, hashCode);\n if (!entry) {\n // check if rehashing is necessary\n if (this.entriesOffset == this.entriesCapacity) {\n this.rehash(\n this.entriesCount < (this.entriesCapacity * FREE_FACTOR)\n ? this.bucketsMask // just rehash if 1/4+ entries are empty\n : (this.bucketsMask << 1) | 1 // grow capacity to next 2^N\n );\n }\n // append new entry\n let entries = this.entries;\n entry = changetype>(\n changetype(entries) + HEADER_SIZE_AB + this.entriesOffset++ * ENTRY_SIZE()\n );\n entry.key = key;\n ++this.entriesCount;\n // link with previous entry in bucket\n let bucketPtrBase = changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE;\n entry.taggedNext = load(bucketPtrBase, HEADER_SIZE_AB);\n store(bucketPtrBase, changetype(entry), HEADER_SIZE_AB);\n if (isManaged()) __gc_link(changetype(this), changetype(key)); // tslint:disable-line\n }\n }\n\n delete(key: K): bool {\n var entry = this.find(key, hash(key));\n if (!entry) return false;\n entry.taggedNext |= EMPTY;\n --this.entriesCount;\n // check if rehashing is appropriate\n var halfBucketsMask = this.bucketsMask >> 1;\n if (\n halfBucketsMask + 1 >= max(INITIAL_CAPACITY, this.entriesCount) &&\n this.entriesCount < (this.entriesCapacity * FREE_FACTOR)\n ) this.rehash(halfBucketsMask);\n return true;\n }\n\n private rehash(newBucketsMask: u32): void {\n var newBucketsCapacity = (newBucketsMask + 1);\n var newBuckets = new ArrayBuffer(newBucketsCapacity * BUCKET_SIZE);\n var newEntriesCapacity = (newBucketsCapacity * FILL_FACTOR);\n var newEntries = new ArrayBuffer(newEntriesCapacity * ENTRY_SIZE(), true);\n\n // copy old entries to new entries\n var oldPtr = changetype(this.entries) + HEADER_SIZE_AB;\n var oldEnd = oldPtr + this.entriesOffset * ENTRY_SIZE();\n var newPtr = changetype(newEntries) + HEADER_SIZE_AB;\n while (oldPtr != oldEnd) {\n let oldEntry = changetype>(oldPtr);\n if (!(oldEntry.taggedNext & EMPTY)) {\n let newEntry = changetype>(newPtr);\n newEntry.key = oldEntry.key;\n let newBucketIndex = hash(oldEntry.key) & newBucketsMask;\n let newBucketPtrBase = changetype(newBuckets) + newBucketIndex * BUCKET_SIZE;\n newEntry.taggedNext = load(newBucketPtrBase, HEADER_SIZE_AB);\n store(newBucketPtrBase, newPtr, HEADER_SIZE_AB);\n newPtr += ENTRY_SIZE();\n }\n oldPtr += ENTRY_SIZE();\n }\n\n this.buckets = newBuckets;\n this.bucketsMask = newBucketsMask;\n this.entries = newEntries;\n this.entriesCapacity = newEntriesCapacity;\n this.entriesOffset = this.entriesCount;\n }\n\n private __gc(): void {\n __gc_mark(changetype(this.buckets)); // tslint:disable-line\n var entries = this.entries;\n __gc_mark(changetype(entries)); // tslint:disable-line\n if (isManaged()) {\n let offset: usize = 0;\n let end: usize = this.entriesOffset * ENTRY_SIZE();\n while (offset < end) {\n let entry = changetype>(\n changetype(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE()\n );\n if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype(entry.key)); // tslint:disable-line\n offset += ENTRY_SIZE();\n }\n }\n }\n}\n',string:'import {\n HEADER_SIZE,\n MAX_LENGTH,\n allocateUnsafe,\n compareUnsafe,\n repeatUnsafe,\n copyUnsafe,\n isWhiteSpaceOrLineTerminator,\n CharCode,\n parse\n} from "./internal/string";\n\nimport {\n storeUnsafe as storeUnsafeArray\n} from "./internal/arraybuffer";\n\n@sealed\nexport class String {\n\n readonly length: i32; // capped to [0, MAX_LENGTH]\n\n // TODO Add and handle second argument\n static fromCharCode(code: i32): String {\n var out = allocateUnsafe(1);\n store(\n changetype(out),\n code,\n HEADER_SIZE\n );\n return out;\n }\n\n static fromCodePoint(code: i32): String {\n assert(code <= 0x10FFFF);\n var sur = code > 0xFFFF;\n var out = allocateUnsafe(sur + 1);\n if (!sur) {\n store(\n changetype(out),\n code,\n HEADER_SIZE\n );\n } else {\n code -= 0x10000;\n let hi: u32 = (code >>> 10) + 0xD800;\n let lo: u32 = (code & 0x3FF) + 0xDC00;\n store(\n changetype(out),\n (hi << 16) | lo,\n HEADER_SIZE\n );\n }\n return out;\n }\n\n @operator("[]")\n charAt(pos: i32): String {\n assert(this !== null);\n\n if (pos >= this.length) return changetype("");\n\n var out = allocateUnsafe(1);\n store(\n changetype(out),\n load(\n changetype(this) + (pos << 1),\n HEADER_SIZE\n ),\n HEADER_SIZE\n );\n return out;\n }\n\n charCodeAt(pos: i32): i32 {\n assert(this !== null);\n if (pos >= this.length) return -1; // (NaN)\n\n return load(\n changetype(this) + (pos << 1),\n HEADER_SIZE\n );\n }\n\n codePointAt(pos: i32): i32 {\n assert(this !== null);\n if (pos >= this.length) return -1; // (undefined)\n\n var first = load(\n changetype(this) + (pos << 1),\n HEADER_SIZE\n );\n if (first < 0xD800 || first > 0xDBFF || pos + 1 == this.length) {\n return first;\n }\n var second = load(\n changetype(this) + ((pos + 1) << 1),\n HEADER_SIZE\n );\n if (second < 0xDC00 || second > 0xDFFF) return first;\n return ((first - 0xD800) << 10) + (second - 0xDC00) + 0x10000;\n }\n\n @operator("+")\n private static __concat(left: String, right: String): String {\n if (!changetype(left)) left = changetype("null");\n return left.concat(right);\n }\n\n concat(other: String): String {\n assert(this !== null);\n if (other === null) other = changetype("null");\n\n var thisLen: isize = this.length;\n var otherLen: isize = other.length;\n var outLen: usize = thisLen + otherLen;\n if (outLen == 0) return changetype("");\n var out = allocateUnsafe(outLen);\n copyUnsafe(out, 0, this, 0, thisLen);\n copyUnsafe(out, thisLen, other, 0, otherLen);\n return out;\n }\n\n endsWith(searchString: String, endPosition: i32 = MAX_LENGTH): bool {\n assert(this !== null);\n if (searchString === null) return false;\n var end = min(max(endPosition, 0), this.length);\n var searchLength: isize = searchString.length;\n var start: isize = end - searchLength;\n if (start < 0) return false;\n return !compareUnsafe(this, start, searchString, 0, searchLength);\n }\n\n @operator("==")\n private static __eq(left: String, right: String): bool {\n if (left === right) return true;\n if (left === null || right === null) return false;\n\n var leftLength = left.length;\n if (leftLength != right.length) return false;\n\n return !compareUnsafe(left, 0, right, 0, leftLength);\n }\n\n @operator("!=")\n private static __ne(left: String, right: String): bool {\n return !this.__eq(left, right);\n }\n\n @operator(">")\n private static __gt(left: String, right: String): bool {\n if (left === right || left === null || right === null) return false;\n\n var leftLength = left.length;\n var rightLength = right.length;\n\n if (!leftLength) return false;\n if (!rightLength) return true;\n\n var length = min(leftLength, rightLength);\n return compareUnsafe(left, 0, right, 0, length) > 0;\n }\n\n @operator(">=")\n private static __gte(left: String, right: String): bool {\n if (left === right) return true;\n if (left === null || right === null) return false;\n\n var leftLength = left.length;\n var rightLength = right.length;\n\n if (!leftLength) return !rightLength;\n if (!rightLength) return true;\n\n var length = min(leftLength, rightLength);\n return compareUnsafe(left, 0, right, 0, length) >= 0;\n }\n\n @operator("<")\n private static __lt(left: String, right: String): bool {\n if (left === right || left === null || right === null) return false;\n\n var leftLength = left.length;\n var rightLength = right.length;\n\n if (!rightLength) return false;\n if (!leftLength) return true;\n\n var length = min(leftLength, rightLength);\n return compareUnsafe(left, 0, right, 0, length) < 0;\n }\n\n @operator("<=")\n private static __lte(left: String, right: String): bool {\n if (left === right) return true;\n if (left === null || right === null) return false;\n\n var leftLength = left.length;\n var rightLength = right.length;\n\n if (!rightLength) return !leftLength;\n if (!leftLength) return true;\n\n var length = min(leftLength, rightLength);\n return compareUnsafe(left, 0, right, 0, length) <= 0;\n }\n\n @inline\n includes(searchString: String, position: i32 = 0): bool {\n return this.indexOf(searchString, position) != -1;\n }\n\n indexOf(searchString: String, fromIndex: i32 = 0): i32 {\n assert(this !== null);\n if (searchString === null) searchString = changetype("null");\n\n var searchLen: isize = searchString.length;\n if (!searchLen) return 0;\n var len: isize = this.length;\n if (!len) return -1;\n var start = min(max(fromIndex, 0), len);\n len -= searchLen;\n for (let k: isize = start; k <= len; ++k) {\n if (!compareUnsafe(this, k, searchString, 0, searchLen)) return k;\n }\n return -1;\n }\n\n lastIndexOf(searchString: String, fromIndex: i32 = i32.MAX_VALUE): i32 {\n assert(this !== null);\n if (searchString === null) searchString = changetype("null");\n\n var len: isize = this.length;\n var searchLen: isize = searchString.length;\n if (!searchLen) return len;\n if (!len) return -1;\n var start = min(max(fromIndex, 0), len - searchLen);\n for (let k = start; k >= 0; --k) {\n if (!compareUnsafe(this, k, searchString, 0, searchLen)) return k;\n }\n return -1;\n }\n\n startsWith(searchString: String, position: i32 = 0): bool {\n assert(this !== null);\n if (searchString === null) searchString = changetype("null");\n\n var pos: isize = position;\n var len: isize = this.length;\n var start = min(max(pos, 0), len);\n var searchLength: isize = searchString.length;\n if (searchLength + start > len) return false;\n return !compareUnsafe(this, start, searchString, 0, searchLength);\n }\n\n substr(start: i32, length: i32 = i32.MAX_VALUE): String {\n assert(this !== null);\n var intStart: isize = start;\n var end: isize = length;\n var size: isize = this.length;\n if (intStart < 0) intStart = max(size + intStart, 0);\n var resultLength = min(max(end, 0), size - intStart);\n if (resultLength <= 0) return changetype("");\n var out = allocateUnsafe(resultLength);\n copyUnsafe(out, 0, this, intStart, resultLength);\n return out;\n }\n\n substring(start: i32, end: i32 = i32.MAX_VALUE): String {\n assert(this !== null);\n var len = this.length;\n var finalStart = min(max(start, 0), len);\n var finalEnd = min(max(end, 0), len);\n var from = min(finalStart, finalEnd);\n var to = max(finalStart, finalEnd);\n len = to - from;\n if (!len) return changetype("");\n if (!from && to == this.length) return this;\n var out = allocateUnsafe(len);\n copyUnsafe(out, 0, this, from, len);\n return out;\n }\n\n trim(): String {\n assert(this !== null);\n var length: usize = this.length;\n\n while (\n length &&\n isWhiteSpaceOrLineTerminator(\n load(changetype(this) + (length << 1), HEADER_SIZE)\n )\n ) {\n --length;\n }\n var start: usize = 0;\n while (\n start < length &&\n isWhiteSpaceOrLineTerminator(\n load(changetype(this) + (start << 1), HEADER_SIZE)\n )\n ) {\n ++start, --length;\n }\n if (!length) return changetype("");\n if (!start && length == this.length) return this;\n var out = allocateUnsafe(length);\n copyUnsafe(out, 0, this, start, length);\n return out;\n }\n\n @inline\n trimLeft(): String {\n return this.trimStart();\n }\n\n @inline\n trimRight(): String {\n return this.trimEnd();\n }\n\n trimStart(): String {\n assert(this !== null);\n var start: isize = 0;\n var len: isize = this.length;\n while (\n start < len &&\n isWhiteSpaceOrLineTerminator(\n load(changetype(this) + (start << 1), HEADER_SIZE)\n )\n ) {\n ++start;\n }\n if (!start) return this;\n var outLen = len - start;\n if (!outLen) return changetype("");\n var out = allocateUnsafe(outLen);\n copyUnsafe(out, 0, this, start, outLen);\n return out;\n }\n\n trimEnd(): String {\n assert(this !== null);\n var len: isize = this.length;\n while (\n len > 0 &&\n isWhiteSpaceOrLineTerminator(\n load(changetype(this) + (len << 1), HEADER_SIZE)\n )\n ) {\n --len;\n }\n if (len <= 0) return changetype("");\n if (len == this.length) return this;\n var out = allocateUnsafe(len);\n copyUnsafe(out, 0, this, 0, len);\n return out;\n }\n\n padStart(targetLength: i32, padString: String = changetype(" ")): String {\n assert(this !== null);\n var length = this.length;\n var padLen = padString.length;\n if (targetLength < length || !padLen) return this;\n var len = targetLength - length;\n var out = allocateUnsafe(targetLength);\n if (len > padLen) {\n let count = (len - 1) / padLen;\n let base = count * padLen;\n let rest = len - base;\n repeatUnsafe(out, 0, padString, count);\n if (rest) copyUnsafe(out, base, padString, 0, rest);\n } else {\n copyUnsafe(out, 0, padString, 0, len);\n }\n if (length) copyUnsafe(out, len, this, 0, length);\n return out;\n }\n\n padEnd(targetLength: i32, padString: String = changetype(" ")): String {\n assert(this !== null);\n var length = this.length;\n var padLen = padString.length;\n if (targetLength < length || !padLen) return this;\n var len = targetLength - length;\n var out = allocateUnsafe(targetLength);\n if (length) copyUnsafe(out, 0, this, 0, length);\n if (len > padLen) {\n let count = (len - 1) / padLen;\n let base = count * padLen;\n let rest = len - base;\n repeatUnsafe(out, length, padString, count);\n if (rest) copyUnsafe(out, base + length, padString, 0, rest);\n } else {\n copyUnsafe(out, length, padString, 0, len);\n }\n return out;\n }\n\n repeat(count: i32 = 0): String {\n assert(this !== null);\n var length = this.length;\n\n // Most browsers can\'t handle strings 1 << 28 chars or longer\n if (count < 0 || length * count > (1 << 28)) {\n throw new RangeError("Invalid count value");\n }\n\n if (count == 0 || !length) return changetype("");\n if (count == 1) return this;\n\n var result = allocateUnsafe(length * count);\n repeatUnsafe(result, 0, this, count);\n return result;\n }\n\n split(separator: String = null, limit: i32 = i32.MAX_VALUE): String[] {\n assert(this !== null);\n if (!limit) return new Array();\n if (separator === null) return [this];\n var length: isize = this.length;\n var sepLen: isize = separator.length;\n if (limit < 0) limit = i32.MAX_VALUE;\n if (!sepLen) {\n if (!length) return new Array();\n // split by chars\n length = min(length, limit);\n let result = new Array(length);\n let buffer = result.buffer_;\n for (let i: isize = 0; i < length; ++i) {\n let char = allocateUnsafe(1);\n store(\n changetype(char),\n load(\n changetype(this) + (i << 1),\n HEADER_SIZE\n ),\n HEADER_SIZE\n );\n storeUnsafeArray(buffer, i, char);\n }\n return result;\n } else if (!length) {\n return [changetype("")];\n }\n var result = new Array();\n var end = 0, start = 0, i = 0;\n while ((end = this.indexOf(separator, start)) != -1) {\n let len = end - start;\n if (len > 0) {\n let out = allocateUnsafe(len);\n copyUnsafe(out, 0, this, start, len);\n result.push(out);\n } else {\n result.push(changetype(""));\n }\n if (++i == limit) return result;\n start = end + sepLen;\n }\n if (!start) return [this];\n var len = length - start;\n if (len > 0) {\n let out = allocateUnsafe(len);\n copyUnsafe(out, 0, this, start, len);\n result.push(out);\n } else {\n result.push(changetype(""));\n }\n return result;\n }\n\n toString(): String {\n return this;\n }\n\n get lengthUTF8(): i32 {\n var len = 1; // null terminated\n var pos: usize = 0;\n var end = this.length;\n while (pos < end) {\n let c = load(changetype(this) + (pos << 1), HEADER_SIZE);\n if (c < 128) {\n len += 1; ++pos;\n } else if (c < 2048) {\n len += 2; ++pos;\n } else {\n if (\n (c & 0xFC00) == 0xD800 && pos + 1 < end &&\n (load(changetype(this) + ((pos + 1) << 1), HEADER_SIZE) & 0xFC00) == 0xDC00\n ) {\n len += 4; pos += 2;\n } else {\n len += 3; ++pos;\n }\n }\n }\n return len;\n }\n\n static fromUTF8(ptr: usize, len: usize): String {\n if (len < 1) return changetype("");\n var ptrPos = 0;\n var buf = memory.allocate(len << 1);\n var bufPos = 0;\n while (ptrPos < len) {\n let cp = load(ptr + ptrPos++);\n if (cp < 128) {\n store(buf + bufPos, cp);\n bufPos += 2;\n } else if (cp > 191 && cp < 224) {\n assert(ptrPos + 1 <= len);\n store(buf + bufPos, (cp & 31) << 6 | load(ptr + ptrPos++) & 63);\n bufPos += 2;\n } else if (cp > 239 && cp < 365) {\n assert(ptrPos + 3 <= len);\n cp = (\n (cp & 7) << 18 |\n (load(ptr + ptrPos++) & 63) << 12 |\n (load(ptr + ptrPos++) & 63) << 6 |\n load(ptr + ptrPos++) & 63\n ) - 0x10000;\n store(buf + bufPos, 0xD800 + (cp >> 10));\n bufPos += 2;\n store(buf + bufPos, 0xDC00 + (cp & 1023));\n bufPos += 2;\n } else {\n assert(ptrPos + 2 <= len);\n store(buf + bufPos,\n (cp & 15) << 12 |\n (load(ptr + ptrPos++) & 63) << 6 |\n load(ptr + ptrPos++) & 63\n );\n bufPos += 2;\n }\n }\n assert(ptrPos == len);\n var str = allocateUnsafe((bufPos >> 1));\n memory.copy(changetype(str) + HEADER_SIZE, buf, bufPos);\n memory.free(buf);\n return str;\n }\n\n toUTF8(): usize {\n var buf = memory.allocate(this.lengthUTF8);\n var pos: usize = 0;\n var end = this.length;\n var off: usize = 0;\n while (pos < end) {\n let c1 = load(changetype(this) + (pos << 1), HEADER_SIZE);\n if (c1 < 128) {\n store(buf + off, c1);\n ++off; ++pos;\n } else if (c1 < 2048) {\n let ptr = buf + off;\n store(ptr, c1 >> 6 | 192);\n store(ptr, c1 & 63 | 128, 1);\n off += 2; ++pos;\n } else {\n let ptr = buf + off;\n if ((c1 & 0xFC00) == 0xD800 && pos + 1 < end) {\n let c2 = load(changetype(this) + ((pos + 1) << 1), HEADER_SIZE);\n if ((c2 & 0xFC00) == 0xDC00) {\n c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);\n store(ptr, c1 >> 18 | 240);\n store(ptr, c1 >> 12 & 63 | 128, 1);\n store(ptr, c1 >> 6 & 63 | 128, 2);\n store(ptr, c1 & 63 | 128, 3);\n off += 4; pos += 2;\n continue;\n }\n }\n store(ptr, c1 >> 12 | 224);\n store(ptr, c1 >> 6 & 63 | 128, 1);\n store(ptr, c1 & 63 | 128, 2);\n off += 3; ++pos;\n }\n }\n store(buf + off, 0);\n return buf;\n }\n}\n\nexport function parseInt(str: String, radix: i32 = 0): f64 {\n return parse(str, radix);\n}\n\nexport function parseI32(str: String, radix: i32 = 0): i32 {\n return parse(str, radix);\n}\n\nexport function parseI64(str: String, radix: i32 = 0): i64 {\n return parse(str, radix);\n}\n\n// FIXME: naive implementation\nexport function parseFloat(str: String): f64 {\n var len: i32 = str.length;\n if (!len) return NaN;\n\n var ptr = changetype(str) /* + HEAD -> offset */;\n var code = load(ptr, HEADER_SIZE);\n\n // determine sign\n var sign: f64;\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = load(ptr += 2, HEADER_SIZE);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = load(ptr += 2, HEADER_SIZE);\n sign = 1;\n } else {\n sign = 1;\n }\n\n // calculate value\n var num: f64 = 0;\n while (len--) {\n code = load(ptr, HEADER_SIZE);\n if (code == CharCode.DOT) {\n ptr += 2;\n let fac: f64 = 0.1; // precision :(\n while (len--) {\n code = load(ptr, HEADER_SIZE);\n if (code == CharCode.E || code == CharCode.e) {\n assert(false); // TODO\n }\n code -= CharCode._0;\n if (code > 9) break;\n num += code * fac;\n fac *= 0.1;\n ptr += 2;\n }\n break;\n }\n code -= CharCode._0;\n if (code >= 10) break;\n num = (num * 10) + code;\n ptr += 2;\n }\n return sign * num;\n}\n',symbol:'import { Map } from "./map";\n\nvar stringToId: Map;\nvar idToString: Map;\nvar nextId: usize = 12; // Symbol.unscopables + 1\n\n@unmanaged export class symbol {}\n\ntype Symbol = symbol;\n\nexport function Symbol(description: string | null = null): symbol {\n var id = nextId++;\n if (!id) unreachable(); // out of ids\n return changetype(id);\n}\n\nexport namespace Symbol {\n\n // well-known symbols\n export const hasInstance = changetype(1);\n export const concatSpreadable = changetype(2);\n export const isRegExp = changetype(3);\n export const iterator = changetype(3);\n export const match = changetype(4);\n export const replace = changetype(5);\n export const search = changetype(6);\n export const species = changetype(7);\n export const split = changetype(8);\n export const toPrimitive = changetype(9);\n export const toStringTag = changetype(10);\n export const unscopables = changetype(11);\n\n /* tslint:disable */// not valid TS\n export function for(key: string): symbol {\n if (!stringToId) { stringToId = new Map(); idToString = new Map(); }\n else if (stringToId.has(key)) return changetype(stringToId.get(key));\n var id = nextId++;\n if (!id) unreachable(); // out of ids\n stringToId.set(key, id);\n idToString.set(id, key);\n return changetype(id);\n }\n /* tslint:enable */\n\n export function keyFor(sym: symbol): string | null {\n return idToString !== null && idToString.has(changetype(sym))\n ? idToString.get(changetype(sym))\n : null;\n }\n}\n',table:"export namespace table {\n\n // export function copy(dst: u32, src: u32, n: u32): void {\n // __table_copy(dst, src, n);\n // }\n\n // Passive elements\n\n // export function init(elementIndex: u32, srcOffset: u32, dstOffset: u32, n: u32): void {\n // __table_init(elementIndex, srcOffset, dstOffset, n);\n // }\n\n // export function drop(elementIndex: u32): void {\n // __table_drop(elementIndex);\n // }\n}\n",typedarray:'import {\n TypedArray\n} from "./internal/typedarray";\n\nexport class Int8Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int8Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint8Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint8Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint8ClampedArray extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n @operator("[]=")\n protected __set(index: i32, value: i32): void {\n super.__set(index, max(min(value, 255), 0));\n }\n\n @inline @operator("{}=")\n protected __unchecked_set(index: i32, value: i32): void {\n super.__unchecked_set(index, max(min(value, 255), 0));\n }\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint8ClampedArray {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Int16Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int16Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint16Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint16Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Int32Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int32Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint32Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint32Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Int64Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int64Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint64Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint64Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Float32Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Float32Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Float64Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Float64Array {\n return changetype(super.subarray(begin, end));\n }\n}\n'}):(()=>{const e=path.join(".","..","std","assembly"),n={};return __webpack_require__(!function(){var e=new Error("Cannot find module 'glob'");throw e.code="MODULE_NOT_FOUND",e}()).sync("**/!(*.d).ts",{cwd:e}).forEach(t=>n[t.replace(/\.ts$/,"")]=fs.readFileSync(path.join(e,t),"utf8")),n})(),exports.definitionFiles=exports.isBundle?Object({assembly:"/**\n * Environment definitions for compiling AssemblyScript to WebAssembly using asc.\n * @module std/assembly\n *//***/\n\n/// \n\n// Types\n\n/** An 8-bit signed integer. */\ndeclare type i8 = number;\n/** A 16-bit signed integer. */\ndeclare type i16 = number;\n/** A 32-bit signed integer. */\ndeclare type i32 = number;\n/** A 64-bit signed integer. */\ndeclare type i64 = number;\n/** A 32-bit signed integer when targeting 32-bit WebAssembly or a 64-bit signed integer when targeting 64-bit WebAssembly. */\ndeclare type isize = number;\n/** An 8-bit unsigned integer. */\ndeclare type u8 = number;\n/** A 16-bit unsigned integer. */\ndeclare type u16 = number;\n/** A 32-bit unsigned integer. */\ndeclare type u32 = number;\n/** A 64-bit unsigned integer. */\ndeclare type u64 = number;\n/** A 32-bit unsigned integer when targeting 32-bit WebAssembly or a 64-bit unsigned integer when targeting 64-bit WebAssembly. */\ndeclare type usize = number;\n/** A 1-bit unsigned integer. */\ndeclare type bool = boolean | number;\n/** A 32-bit float. */\ndeclare type f32 = number;\n/** A 64-bit float. */\ndeclare type f64 = number;\n\n// Compiler hints\n\n/** Compiler target. 0 = JS, 1 = WASM32, 2 = WASM64. */\ndeclare const ASC_TARGET: i32;\n/** Provided noTreeshaking option. */\ndeclare const ASC_NO_TREESHAKING: bool;\n/** Provided noAssert option. */\ndeclare const ASC_NO_ASSERT: bool;\n/** Provided memoryBase option. */\ndeclare const ASC_MEMORY_BASE: i32;\n/** Provided optimizeLevel option. */\ndeclare const ASC_OPTIMIZE_LEVEL: i32;\n/** Provided shrinkLevel option. */\ndeclare const ASC_SHRINK_LEVEL: i32;\n/** Whether the mutable global feature is enabled. */\ndeclare const ASC_FEATURE_MUTABLE_GLOBAL: bool;\n/** Whether the sign extension feature is enabled. */\ndeclare const ASC_FEATURE_SIGN_EXTENSION: bool;\n\n// Builtins\n\n/** Performs the sign-agnostic count leading zero bits operation on a 32-bit or 64-bit integer. All zero bits are considered leading if the value is zero. */\ndeclare function clz(value: T): T;\n/** Performs the sign-agnostic count tailing zero bits operation on a 32-bit or 64-bit integer. All zero bits are considered trailing if the value is zero. */\ndeclare function ctz(value: T): T;\n/** Performs the sign-agnostic count number of one bits operation on a 32-bit or 64-bit integer. */\ndeclare function popcnt(value: T): T;\n/** Performs the sign-agnostic rotate left operation on a 32-bit or 64-bit integer. */\ndeclare function rotl(value: T, shift: T): T;\n/** Performs the sign-agnostic rotate right operation on a 32-bit or 64-bit integer. */\ndeclare function rotr(value: T, shift: T): T;\n/** Computes the absolute value of an integer or float. */\ndeclare function abs(value: T): T;\n/** Determines the maximum of two integers or floats. If either operand is `NaN`, returns `NaN`. */\ndeclare function max(left: T, right: T): T;\n/** Determines the minimum of two integers or floats. If either operand is `NaN`, returns `NaN`. */\ndeclare function min(left: T, right: T): T;\n/** Performs the ceiling operation on a 32-bit or 64-bit float. */\ndeclare function ceil(value: T): T;\n/** Composes a 32-bit or 64-bit float from the magnitude of `x` and the sign of `y`. */\ndeclare function copysign(x: T, y: T): T;\n/** Performs the floor operation on a 32-bit or 64-bit float. */\ndeclare function floor(value: T): T;\n/** Rounds to the nearest integer tied to even of a 32-bit or 64-bit float. */\ndeclare function nearest(value: T): T;\n/** Reinterprets the bits of the specified value as type `T`. Valid reinterpretations are u32/i32 to/from f32 and u64/i64 to/from f64. */\ndeclare function reinterpret(value: number): T;\n/** Selects one of two pre-evaluated values depending on the condition. */\ndeclare function select(ifTrue: T, ifFalse: T, condition: bool): T;\n/** Calculates the square root of a 32-bit or 64-bit float. */\ndeclare function sqrt(value: T): T;\n/** Rounds to the nearest integer towards zero of a 32-bit or 64-bit float. */\ndeclare function trunc(value: T): T;\n/** Loads a value of the specified type from memory. Equivalent to dereferncing a pointer in other languages. */\ndeclare function load(ptr: usize, constantOffset?: usize): T;\n/** Stores a value of the specified type to memory. Equivalent to dereferencing a pointer in other languages when assigning a value. */\ndeclare function store(ptr: usize, value: any, constantOffset?: usize): void;\n/** Emits an unreachable operation that results in a runtime error when executed. Both a statement and an expression of any type. */\ndeclare function unreachable(): any; // sic\n\n/** NaN (not a number) as a 32-bit or 64-bit float depending on context. */\ndeclare const NaN: f32 | f64;\n/** Positive infinity as a 32-bit or 64-bit float depending on context. */\ndeclare const Infinity: f32 | f64;\n/** Heap base offset. */\ndeclare const HEAP_BASE: usize;\n/** Determines the byte size of the specified underlying core type. Compiles to a constant. */\ndeclare function sizeof(): usize;\n/** Determines the alignment (log2) of the specified underlying core type. Compiles to a constant. */\ndeclare function alignof(): usize;\n/** Determines the offset of the specified field within the given class type. Returns the class type's end offset if field name has been omitted. Compiles to a constant. */\ndeclare function offsetof(fieldName?: string): usize;\n/** Changes the type of any value of `usize` kind to another one of `usize` kind. Useful for casting class instances to their pointer values and vice-versa. Beware that this is unsafe.*/\ndeclare function changetype(value: any): T;\n/** Explicitly requests no bounds checks on the provided expression. Useful for array accesses. */\ndeclare function unchecked(value: T): T;\n/** Emits a `call_indirect` instruction, calling the specified function in the function table by index with the specified arguments. Does result in a runtime error if the arguments do not match the called function. */\ndeclare function call_indirect(target: Function | u32, ...args: any[]): T;\n/** Tests if a 32-bit or 64-bit float is `NaN`. */\ndeclare function isNaN(value: T): bool;\n/** Tests if a 32-bit or 64-bit float is finite, that is not `NaN` or +/-`Infinity`. */\ndeclare function isFinite(value: T): bool;\n/** Tests if the specified type *or* expression is of an integer type and not a reference. Compiles to a constant. */\ndeclare function isInteger(value?: any): value is number;\n/** Tests if the specified type *or* expression is of a float type. Compiles to a constant. */\ndeclare function isFloat(value?: any): value is number;\n/** Tests if the specified type *or* expression can represent negative numbers. Compiles to a constant. */\ndeclare function isSigned(value?: any): value is number;\n/** Tests if the specified type *or* expression is of a reference type. Compiles to a constant. */\ndeclare function isReference(value?: any): value is object | string;\n/** Tests if the specified type *or* expression can be used as a string. Compiles to a constant. */\ndeclare function isString(value?: any): value is string | String;\n/** Tests if the specified type *or* expression can be used as an array. Compiles to a constant. */\ndeclare function isArray(value?: any): value is Array;\n/** Tests if the specified expression resolves to a defined element. Compiles to a constant. */\ndeclare function isDefined(expression: any): bool;\n/** Tests if the specified expression evaluates to a constant value. Compiles to a constant. */\ndeclare function isConstant(expression: any): bool;\n/** Tests if the specified type *or* expression is of a managed type. Compiles to a constant. */\ndeclare function isManaged(value?: any): bool;\n/** Traps if the specified value is not true-ish, otherwise returns the (non-nullable) value. */\ndeclare function assert(isTrueish: T, message?: string): T & object; // any better way to model `: T != null`?\n/** Parses an integer string to a 64-bit float. */\ndeclare function parseInt(str: string, radix?: i32): f64;\n/** Parses an integer string to a 32-bit integer. */\ndeclare function parseI32(str: string, radix?: i32): i32;\n/** Parses an integer string to a 64-bit integer. */\ndeclare function parseI64(str: string, radix?: i32): i64;\n/** Parses a string to a 64-bit float. */\ndeclare function parseFloat(str: string): f64;\n/** Returns the 64-bit floating-point remainder of `x/y`. */\ndeclare function fmod(x: f64, y: f64): f64;\n/** Returns the 32-bit floating-point remainder of `x/y`. */\ndeclare function fmodf(x: f32, y: f32): f32;\n\n/** Converts any other numeric value to an 8-bit signed integer. */\ndeclare function i8(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;\ndeclare namespace i8 {\n /** Smallest representable value. */\n export const MIN_VALUE: i8;\n /** Largest representable value. */\n export const MAX_VALUE: i8;\n}\n/** Converts any other numeric value to a 16-bit signed integer. */\ndeclare function i16(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;\ndeclare namespace i16 {\n /** Smallest representable value. */\n export const MIN_VALUE: i16;\n /** Largest representable value. */\n export const MAX_VALUE: i16;\n}\n/** Converts any other numeric value to a 32-bit signed integer. */\ndeclare function i32(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i32;\ndeclare namespace i32 {\n /** Smallest representable value. */\n export const MIN_VALUE: i32;\n /** Largest representable value. */\n export const MAX_VALUE: i32;\n /** Loads an 8-bit signed integer from memory and returns it as a 32-bit integer. */\n export function load8_s(offset: usize, constantOffset?: usize): i32;\n /** Loads an 8-bit unsigned integer from memory and returns it as a 32-bit integer. */\n export function load8_u(offset: usize, constantOffset?: usize): i32;\n /** Loads a 16-bit signed integer from memory and returns it as a 32-bit integer. */\n export function load16_s(offset: usize, constantOffset?: usize): i32;\n /** Loads a 16-bit unsigned integer from memory and returns it as a 32-bit integer. */\n export function load16_u(offset: usize, constantOffset?: usize): i32;\n /** Loads a 32-bit integer from memory. */\n export function load(offset: usize, constantOffset?: usize): i32;\n /** Stores a 32-bit integer to memory as an 8-bit integer. */\n export function store8(offset: usize, value: i32, constantOffset?: usize): void;\n /** Stores a 32-bit integer to memory as a 16-bit integer. */\n export function store16(offset: usize, value: i32, constantOffset?: usize): void;\n /** Stores a 32-bit integer to memory. */\n export function store(offset: usize, value: i32, constantOffset?: usize): void;\n}\n/** Converts any other numeric value to a 64-bit signed integer. */\ndeclare function i64(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i64;\ndeclare namespace i64 {\n /** Smallest representable value. */\n export const MIN_VALUE: i64;\n /** Largest representable value. */\n export const MAX_VALUE: i64;\n /** Loads an 8-bit signed integer from memory and returns it as a 64-bit signed integer. */\n export function load8_s(offset: usize, constantOffset?: usize): i64;\n /** Loads an 8-bit unsigned integer from memory and returns it as a 64-bit unsigned integer. */\n export function load8_u(offset: usize, constantOffset?: usize): u64;\n /** Loads a 16-bit signed integer from memory and returns it as a 64-bit signed integer. */\n export function load16_s(offset: usize, constantOffset?: usize): i64;\n /** Loads a 16-bit unsigned integer from memory and returns it as a 64-bit unsigned integer. */\n export function load16_u(offset: usize, constantOffset?: usize): u64;\n /** Loads a 32-bit signed integer from memory and returns it as a 64-bit signed integer. */\n export function load32_s(offset: usize, constantOffset?: usize): i64;\n /** Loads a 32-bit unsigned integer from memory and returns it as a 64-bit unsigned integer. */\n export function load32_u(offset: usize, constantOffset?: usize): u64;\n /** Loads a 64-bit unsigned integer from memory. */\n export function load(offset: usize, constantOffset?: usize): i64;\n /** Stores a 64-bit integer to memory as an 8-bit integer. */\n export function store8(offset: usize, value: i64, constantOffset?: usize): void;\n /** Stores a 64-bit integer to memory as a 16-bit integer. */\n export function store16(offset: usize, value: i64, constantOffset?: usize): void;\n /** Stores a 64-bit integer to memory as a 32-bit integer. */\n export function store32(offset: usize, value: i64, constantOffset?: usize): void;\n /** Stores a 64-bit integer to memory. */\n export function store(offset: usize, value: i64, constantOffset?: usize): void;\n}\n/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */\ndeclare var isize: i32 | i64;\n/** Converts any other numeric value to an 8-bit unsigned integer. */\ndeclare function u8(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;\ndeclare namespace u8 {\n /** Smallest representable value. */\n export const MIN_VALUE: u8;\n /** Largest representable value. */\n export const MAX_VALUE: u8;\n}\n/** Converts any other numeric value to a 16-bit unsigned integer. */\ndeclare function u16(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;\ndeclare namespace u16 {\n /** Smallest representable value. */\n export const MIN_VALUE: u16;\n /** Largest representable value. */\n export const MAX_VALUE: u16;\n}\n/** Converts any other numeric value to a 32-bit unsigned integer. */\ndeclare function u32(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i32;\ndeclare namespace u32 {\n /** Smallest representable value. */\n export const MIN_VALUE: u32;\n /** Largest representable value. */\n export const MAX_VALUE: u32;\n}\n/** Converts any other numeric value to a 64-bit unsigned integer. */\ndeclare function u64(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i64;\ndeclare namespace u64 {\n /** Smallest representable value. */\n export const MIN_VALUE: u64;\n /** Largest representable value. */\n export const MAX_VALUE: u64;\n}\n/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */\ndeclare var usize: u32 | u64;\n/** Converts any other numeric value to a 1-bit unsigned integer. */\ndeclare function bool(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): bool;\ndeclare namespace bool {\n /** Smallest representable value. */\n export const MIN_VALUE: bool;\n /** Largest representable value. */\n export const MAX_VALUE: bool;\n}\n/** Converts any other numeric value to a 32-bit float. */\ndeclare function f32(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): f32;\ndeclare namespace f32 {\n /** Smallest representable value. */\n export const MIN_VALUE: f32;\n /** Largest representable value. */\n export const MAX_VALUE: f32;\n /** Smallest normalized positive value. */\n export const MIN_POSITIVE_VALUE: f32;\n /** Smallest safely representable integer value. */\n export const MIN_SAFE_INTEGER: f32;\n /** Largest safely representable integer value. */\n export const MAX_SAFE_INTEGER: f32;\n /** Difference between 1 and the smallest representable value greater than 1. */\n export const EPSILON: f32;\n /** Returns the floating-point remainder of `x / y` (rounded towards zero). */\n export function mod(x: f32, y: f32): f32;\n /** Returns the floating-point remainder of `x / y` (rounded to nearest). */\n export function rem(x: f32, y: f32): f32;\n /** Loads a 32-bit float from memory. */\n export function load(offset: usize, constantOffset?: usize): f32;\n /** Stores a 32-bit float to memory. */\n export function store(offset: usize, value: f32, constantOffset?: usize): void;\n}\n/** Converts any other numeric value to a 64-bit float. */\ndeclare function f64(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): f64;\ndeclare namespace f64 {\n /** Smallest representable value. */\n export const MIN_VALUE: f64;\n /** Largest representable value. */\n export const MAX_VALUE: f64;\n /** Smallest normalized positive value. */\n export const MIN_POSITIVE_VALUE: f64;\n /** Smallest safely representable integer value. */\n export const MIN_SAFE_INTEGER: f64;\n /** Largest safely representable integer value. */\n export const MAX_SAFE_INTEGER: f64;\n /** Difference between 1 and the smallest representable value greater than 1. */\n export const EPSILON: f64;\n /** Loads a 64-bit float from memory. */\n export function load(offset: usize, constantOffset?: usize): f64;\n /** Stores a 64-bit float to memory. */\n export function store(offset: usize, value: f64, constantOffset?: usize): void;\n}\n\n// User-defined diagnostic macros\n\n/** Emits a user-defined diagnostic error when encountered. */\ndeclare function ERROR(message?: any): void;\n/** Emits a user-defined diagnostic warning when encountered. */\ndeclare function WARNING(message?: any): void;\n/** Emits a user-defined diagnostic info when encountered. */\ndeclare function INFO(message?: any): void;\n\n// Polyfills\n\n/** Performs the sign-agnostic reverse bytes **/\ndeclare function bswap(value: T): T;\n/** Performs the sign-agnostic reverse bytes only for last 16-bit **/\ndeclare function bswap16(value: T): T;\n\n// Standard library\n\n/** Memory operations. */\ndeclare namespace memory {\n /** Returns the current memory size in units of pages. One page is 64kb. */\n export function size(): i32;\n /** Grows linear memory by a given unsigned delta of pages. One page is 64kb. Returns the previous memory size in units of pages or `-1` on failure. */\n export function grow(value: i32): i32;\n /** Sets n bytes beginning at the specified destination in memory to the specified byte value. */\n export function fill(dst: usize, value: u8, count: usize): void;\n /** Copies n bytes from the specified source to the specified destination in memory. These regions may overlap. */\n export function copy(dst: usize, src: usize, n: usize): void;\n /** Copies elements from a passive element segment to a table. */\n // export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void;\n /** Prevents further use of a passive element segment. */\n // export function drop(segmentIndex: u32): void;\n /** Copies elements from one region of a table to another region. */\n export function allocate(size: usize): usize;\n /** Disposes a chunk of memory by its pointer. */\n export function free(ptr: usize): void;\n /** Compares two chunks of memory. Returns `0` if equal, otherwise the difference of the first differing bytes. */\n export function compare(vl: usize, vr: usize, n: usize): i32;\n /** Resets the allocator to its initial state, if supported. */\n export function reset(): void;\n}\n\n/** Garbage collector operations. */\ndeclare namespace gc {\n /** Allocates a managed object identified by its visitor function. */\n export function allocate(size: usize, visitFn: (ref: usize) => void): usize;\n /** Performs a full garbage collection cycle. */\n export function collect(): void;\n}\n\n/** Table operations. */\ndeclare namespace table {\n /** Copies elements from a passive element segment to a table. */\n // export function init(elementIndex: u32, srcOffset: u32, dstOffset: u32, n: u32): void;\n /** Prevents further use of a passive element segment. */\n // export function drop(elementIndex: u32): void;\n /** Copies elements from one region of a table to another region. */\n // export function copy(dest: u32, src: u32, n: u32): void;\n}\n\n/** Class representing a generic, fixed-length raw binary data buffer. */\ndeclare class ArrayBuffer {\n /** The size, in bytes, of the array. */\n readonly byteLength: i32;\n /** Unsafe pointer to the start of the data in memory. */\n readonly data: usize;\n /** Constructs a new array buffer of the given length in bytes. */\n constructor(length: i32, unsafe?: bool);\n /** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */\n slice(begin?: i32, end?: i32): ArrayBuffer;\n}\n\n/** Interface for a typed view on an array buffer. */\ninterface ArrayBufferView {\n [key: number]: T;\n /** The {@link ArrayBuffer} referenced by this view. */\n readonly buffer: ArrayBuffer;\n /** The offset in bytes from the start of the referenced {@link ArrayBuffer}. */\n readonly byteOffset: i32;\n /** The length in bytes from the start of the referenced {@link ArrayBuffer}. */\n readonly byteLength: i32;\n}\n\n/* @internal */\ndeclare abstract class TypedArray implements ArrayBufferView {\n [key: number]: T;\n /** Number of bytes per element. */\n static readonly BYTES_PER_ELEMENT: usize;\n /** Constructs a new typed array. */\n constructor(length: i32);\n /** The {@link ArrayBuffer} referenced by this view. */\n readonly buffer: ArrayBuffer;\n /** The offset in bytes from the start of the referenced {@link ArrayBuffer}. */\n readonly byteOffset: i32;\n /** The length in bytes from the start of the referenced {@link ArrayBuffer}. */\n readonly byteLength: i32;\n /** The length (in elements). */\n readonly length: i32;\n /** Returns a new TypedArray of this type on the same ArrayBuffer from begin inclusive to end exclusive. */\n subarray(begin?: i32, end?: i32): this;\n}\n\n/** An array of twos-complement 8-bit signed integers. */\ndeclare class Int8Array extends TypedArray {}\n/** An array of 8-bit unsigned integers. */\ndeclare class Uint8Array extends TypedArray {}\n/** An array of twos-complement 16-bit signed integers. */\ndeclare class Int16Array extends TypedArray {}\n/** An array of 16-bit unsigned integers. */\ndeclare class Uint16Array extends TypedArray {}\n/** An array of twos-complement 32-bit signed integers. */\ndeclare class Int32Array extends TypedArray {}\n/** An array of 32-bit unsigned integers. */\ndeclare class Uint32Array extends TypedArray {}\n/** An array of twos-complement 64-bit signed integers. */\ndeclare class Int64Array extends TypedArray {}\n/** An array of 64-bit unsigned integers. */\ndeclare class Uint64Array extends TypedArray {}\n/** An array of 32-bit floating point numbers. */\ndeclare class Float32Array extends TypedArray {}\n/** An array of 64-bit floating point numbers. */\ndeclare class Float64Array extends TypedArray {}\n\n/** Class representing a sequence of values of type `T`. */\ndeclare class Array {\n [key: number]: T;\n /** Current length of the array. */\n length: i32;\n /** Constructs a new array. */\n constructor(capacity?: i32);\n fill(value: T, start?: i32, end?: i32): this;\n every(callbackfn: (element: T, index: i32, array?: Array) => bool): bool;\n findIndex(predicate: (element: T, index: i32, array?: Array) => bool): i32;\n includes(searchElement: T, fromIndex?: i32): bool;\n indexOf(searchElement: T, fromIndex?: i32): i32;\n lastIndexOf(searchElement: T, fromIndex?: i32): i32;\n push(element: T): i32;\n concat(items: T[]): T[];\n pop(): T;\n forEach(callbackfn: (value: T, index: i32, array: Array) => void): void;\n map(callbackfn: (value: T, index: i32, array: Array) => U): Array;\n filter(callbackfn: (value: T, index: i32, array: Array) => bool): Array;\n reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U): U;\n reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U): U;\n shift(): T;\n some(callbackfn: (element: T, index: i32, array?: Array) => bool): bool;\n unshift(element: T): i32;\n slice(from: i32, to?: i32): T[];\n splice(start: i32, deleteCount?: i32): void;\n sort(comparator?: (a: T, b: T) => i32): this;\n join(separator?: string): string;\n reverse(): T[];\n toString(): string;\n}\n\n/** Class representing a sequence of characters. */\ndeclare class String {\n\n static fromCharCode(ls: i32, hs?: i32): string;\n static fromCharCodes(arr: u16[]): string;\n static fromCodePoint(code: i32): string;\n static fromCodePoints(arr: i32[]): string;\n\n readonly length: i32;\n readonly lengthUTF8: i32;\n\n charAt(index: u32): string;\n charCodeAt(index: u32): u16;\n concat(other: string): string;\n endsWith(other: string): bool;\n indexOf(other: string, fromIndex?: i32): u32;\n lastIndexOf(other: string, fromIndex?: i32): i32;\n includes(other: string): bool;\n startsWith(other: string): bool;\n substr(start: u32, length?: u32): string;\n substring(start: u32, end?: u32): string;\n trim(): string;\n trimLeft(): string;\n trimRight(): string;\n trimStart(): string;\n trimEnd(): string;\n padStart(targetLength: i32, padString?: string): string;\n padEnd(targetLength: i32, padString?: string): string;\n repeat(count?: i32): string;\n split(separator?: string, limit?: i32): string[];\n toString(): string;\n static fromUTF8(ptr: usize, len: usize): string;\n toUTF8(): usize;\n}\n\n/** Class for representing a runtime error. Base class of all errors. */\ndeclare class Error {\n\n /** Error name. */\n name: string;\n\n /** Message provided on construction. */\n message: string;\n\n /** Stack trace. */\n stack: string;\n\n /** Constructs a new error, optionally with a message. */\n constructor(message?: string);\n}\n\n/** Class for indicating an error when a value is not in the set or range of allowed values. */\ndeclare class RangeError extends Error { }\n\ninterface Boolean {}\ninterface Function {}\ninterface IArguments {}\ninterface Number {}\ninterface Object {}\ninterface RegExp {}\n\ndeclare class Map {\n readonly size: i32;\n has(key: K): bool;\n set(key: K, value: V): void;\n get(key: K): V;\n delete(key: K): bool;\n clear(): void;\n}\n\ndeclare class Set {\n readonly size: i32;\n has(value: T): bool;\n add(value: T): void;\n delete(value: T): bool;\n clear(): void;\n}\n\ninterface SymbolConstructor {\n (description?: string | null): symbol;\n for(key: string): symbol;\n keyFor(sym: symbol): string | null;\n}\ndeclare const Symbol: SymbolConstructor;\n\ninterface IMath {\n /** The base of natural logarithms, e, approximately 2.718. */\n readonly E: T;\n /** The natural logarithm of 2, approximately 0.693. */\n readonly LN2: T;\n /** The natural logarithm of 10, approximately 2.302. */\n readonly LN10: T;\n /** The base 2 logarithm of e, approximately 1.442. */\n readonly LOG2E: T;\n /** The base 10 logarithm of e, approximately 0.434. */\n readonly LOG10E: T;\n /** The ratio of the circumference of a circle to its diameter, approximately 3.14159. */\n readonly PI: T;\n /** The square root of 1/2, approximately 0.707. */\n readonly SQRT1_2: T;\n /** The square root of 2, approximately 1.414. */\n readonly SQRT2: T;\n /** Returns the absolute value of `x`. */\n abs(x: T): T;\n /** Returns the arccosine (in radians) of `x`. */\n acos(x: T): T;\n /** Returns the hyperbolic arc-cosine of `x`. */\n acosh(x: T): T;\n /** Returns the arcsine (in radians) of `x` */\n asin(x: T): T;\n /** Returns the hyperbolic arcsine of `x`. */\n asinh(x: T): T;\n /** Returns the arctangent (in radians) of `x`. */\n atan(x: T): T;\n /** Returns the arctangent of the quotient of its arguments. */\n atan2(y: T, x: T): T;\n /** Returns the hyperbolic arctangent of `x`. */\n atanh(x: T): T;\n /** Returns the cube root of `x`. */\n cbrt(x: T): T;\n /** Returns the smallest integer greater than or equal to `x`. */\n ceil(x: T): T;\n /** Returns the number of leading zero bits in the 32-bit binary representation of `x`. */\n clz32(x: T): T;\n /** Returns the cosine (in radians) of `x`. */\n cos(x: T): T;\n /** Returns the hyperbolic cosine of `x`. */\n cosh(x: T): T;\n /** Returns e to the power of `x`. */\n exp(x: T): T;\n /** Returns e to the power of `x`, minus 1. */\n expm1(x: T): T;\n /** Returns the largest integer less than or equal to `x`. */\n floor(x: T): T;\n /** Returns the nearest 32-bit single precision float representation of `x`. */\n fround(x: T): f32;\n /** Returns the square root of the sum of squares of its arguments. */\n hypot(value1: T, value2: T): T; // TODO: rest\n /** Returns the result of the C-like 32-bit multiplication of `a` and `b`. */\n imul(a: T, b: T): T;\n /** Returns the natural logarithm (base e) of `x`. */\n log(x: T): T;\n /** Returns the base 10 logarithm of `x`. */\n log10(x: T): T;\n /** Returns the natural logarithm (base e) of 1 + `x`. */\n log1p(x: T): T;\n /** Returns the base 2 logarithm of `x`. */\n log2(x: T): T;\n /** Returns the largest-valued number of its arguments. */\n max(value1: T, value2: T): T; // TODO: rest\n /** Returns the lowest-valued number of its arguments. */\n min(value1: T, value2: T): T; // TODO: rest\n /** Returns `base` to the power of `exponent`. */\n pow(base: T, exponent: T): T;\n /** Returns a pseudo-random number in the range from 0.0 inclusive up to but not including 1.0. */\n random(): T;\n /** Returns the value of `x` rounded to the nearest integer. */\n round(x: T): T;\n /** Returns the sign of `x`, indicating whether the number is positive, negative or zero. */\n sign(x: T): T;\n /** Returns the sine of `x`. */\n sin(x: T): T;\n /** Returns the hyperbolic sine of `x`. */\n sinh(x: T): T;\n /** Returns the square root of `x`. */\n sqrt(x: T): T;\n /** Returns the tangent of `x`. */\n tan(x: T): T;\n /** Returns the hyperbolic tangent of `x`. */\n tanh(x: T): T;\n /** Returns the integer part of `x` by removing any fractional digits. */\n trunc(x: T): T;\n}\n\ninterface INativeMath extends IMath {\n /** Seeds the random number generator. */\n seedRandom(value: i64): void;\n /** Returns the floating-point remainder of `x / y` (rounded towards zero). */\n mod(x: T, y: T): T;\n /** Returns the floating-point remainder of `x / y` (rounded to nearest). */\n rem(x: T, y: T): T;\n}\n\n/** Double precision math imported from JavaScript. */\ndeclare const JSMath: IMath;\n/** Double precision math implemented natively. */\ndeclare const NativeMath: INativeMath;\n/** Single precision math implemented natively. */\ndeclare const NativeMathf: INativeMath;\n/** Alias of {@link NativeMath} or {@link JSMath} respectively. Defaults to `NativeMath`. */\ndeclare const Math: IMath;\n/** Alias of {@link NativeMathf} or {@link JSMath} respectively. Defaults to `NativeMathf`. */\ndeclare const Mathf: IMath;\n\n/** Environmental tracing function for debugging purposes. */\ndeclare function trace(msg: string, n?: i32, a0?: f64, a1?: f64, a2?: f64, a3?: f64, a4?: f64): void;\n\n// Decorators\n\n/** Annotates an element as a program global. */\ndeclare function global(target: Function, propertyKey: string, descriptor: any): void;\n\n/** Annotates a method as a binary operator overload for the specified `token`. */\ndeclare function operator(token: string): (target: any, propertyKey: string, descriptor: any) => void;\ndeclare namespace operator {\n /** Annotates a method as a binary operator overload for the specified `token`. */\n export function binary(token: string): (target: any, propertyKey: string, descriptor: any) => void;\n /** Annotates a method as an unary prefix operator overload for the specified `token`. */\n export function prefix(token: string): (target: any, propertyKey: string, descriptor: any) => void;\n /** Annotates a method as an unary postfix operator overload for the specified `token`. */\n export function postfix(token: string): (target: any, propertyKey: string, descriptor: any) => void;\n}\n\n/** Annotates a class as being unmanaged with limited capabilities. */\ndeclare function unmanaged(target: Function): any;\n\n/** Annotates a class as being sealed / non-derivable. */\ndeclare function sealed(target: Function): any;\n\n/** Annotates a method or function as always inlined. */\ndeclare function inline(target: any, propertyKey: any, descriptor: any): any;\n\n/** Annotates an explicit external name of a function or global. */\ndeclare function external(target: any, propertyKey: any, descriptor: any): any;\n",portable:"/**\n * Environment definitions for compiling AssemblyScript to JavaScript using tsc.\n *\n * Note that semantic differences require additional explicit conversions for full compatibility.\n * For example, when casting an i32 to an u8, doing `(someI32 & 0xff)` will yield the same\n * result when compiling to WebAssembly or JS while `someI32` alone does nothing in JS.\n *\n * Note that i64's are not portable (JS numbers are IEEE754 doubles with a maximum safe integer\n * value of 2^53-1) and instead require a compatibility layer to work in JS as well, as for example\n * {@link glue/js/i64} respectively {@link glue/wasm/i64}.\n *\n * @module std/portable\n *//***/\n\n/// \n\n// Types\n\ndeclare type i8 = number;\ndeclare type i16 = number;\ndeclare type i32 = number;\ndeclare type isize = number;\ndeclare type u8 = number;\ndeclare type u16 = number;\ndeclare type u32 = number;\ndeclare type bool = boolean;\ndeclare type usize = number;\ndeclare type f32 = number;\ndeclare type f64 = number;\n\n// Compiler hints\n\n/** Compiler target. 0 = JS, 1 = WASM32, 2 = WASM64. */\ndeclare const ASC_TARGET: i32;\n\n// Builtins\n\n/** Performs the sign-agnostic count leading zero bits operation on a 32-bit integer. All zero bits are considered leading if the value is zero. */\ndeclare function clz(value: T): T;\n/** Performs the sign-agnostic count tailing zero bits operation on a 32-bit integer. All zero bits are considered trailing if the value is zero. */\ndeclare function ctz(value: T): T;\n/** Performs the sign-agnostic count number of one bits operation on a 32-bit integer. */\ndeclare function popcnt(value: T): T;\n/** Performs the sign-agnostic rotate left operation on a 32-bit integer. */\ndeclare function rotl(value: T, shift: T): T;\n/** Performs the sign-agnostic rotate right operation on a 32-bit integer. */\ndeclare function rotr(value: T, shift: T): T;\n/** Computes the absolute value of an integer or float. */\ndeclare function abs(value: T): T;\n/** Determines the maximum of two integers or floats. If either operand is `NaN`, returns `NaN`. */\ndeclare function max(left: T, right: T): T;\n/** Determines the minimum of two integers or floats. If either operand is `NaN`, returns `NaN`. */\ndeclare function min(left: T, right: T): T;\n/** Composes a 32-bit or 64-bit float from the magnitude of `x` and the sign of `y`. */\ndeclare function copysign(x: T, y: T): T;\n/** Performs the ceiling operation on a 32-bit or 64-bit float. */\ndeclare function ceil(value: T): T;\n/** Performs the floor operation on a 32-bit or 64-bit float. */\ndeclare function floor(value: T): T;\n/** Rounds to the nearest integer tied to even of a 32-bit or 64-bit float. */\ndeclare function nearest(value: T): T;\n/** Selects one of two pre-evaluated values depending on the condition. */\ndeclare function select(ifTrue: T, ifFalse: T, condition: bool): T;\n/** Calculates the square root of a 32-bit or 64-bit float. */\ndeclare function sqrt(value: T): T;\n/** Rounds to the nearest integer towards zero of a 32-bit or 64-bit float. */\ndeclare function trunc(value: T): T;\n/** Loads a value of the specified type from memory. Type must be `u8`. */\ndeclare function load(ptr: usize, constantOffset?: usize): T;\n/** Stores a value of the specified type to memory. Type must be `u8`. */\ndeclare function store(ptr: usize, value: T, constantOffset?: usize): void;\n/** Emits an unreachable operation that results in a runtime error when executed. */\ndeclare function unreachable(): any; // sic\n\n/** NaN (not a number) as a 32-bit or 64-bit float depending on context. */\ndeclare const NaN: f32 | f64;\n/** Positive infinity as a 32-bit or 64-bit float depending on context. */\ndeclare const Infinity: f32 | f64;\n/** Changes the type of any value of `usize` kind to another one of `usize` kind. Useful for casting class instances to their pointer values and vice-versa. Beware that this is unsafe.*/\ndeclare function changetype(value: any): T;\n/** Explicitly requests no bounds checks on the provided expression. Useful for array accesses. */\ndeclare function unchecked(value: T): T;\n/** Tests if a 32-bit or 64-bit float is `NaN`. */\ndeclare function isNaN(value: T): bool;\n/** Tests if a 32-bit or 64-bit float is finite, that is not `NaN` or +/-`Infinity`. */\ndeclare function isFinite(value: T): bool;\n/** Tests if the specified value is a valid integer. Can't distinguish an integer from an integral float. */\ndeclare function isInteger(value: any): value is number;\n/** Tests if the specified value is a valid float. Can't distinguish a float from an integer. */\ndeclare function isFloat(value: any): value is number;\n/** Tests if the specified value is of a reference type. */\ndeclare function isReference(value: any): value is object | string;\n/** Tests if the specified value can be used as a string. */\ndeclare function isString(value: any): value is string | String;\n/** Tests if the specified value can be used as an array. */\ndeclare function isArray(value: any): value is Array;\n/** Traps if the specified value is not true-ish, otherwise returns the value. */\ndeclare function assert(isTrueish: T | null, message?: string): T;\n/** Parses an integer string to a 64-bit float. */\ndeclare function parseInt(str: string, radix?: i32): f64;\n/** Parses an integer string to a 32-bit integer. */\ndeclare function parseI32(str: string, radix?: i32): i32;\n/** Parses a floating point string to a 64-bit float. */\ndeclare function parseFloat(str: string): f64;\n/** Returns the 64-bit floating-point remainder of `x/y`. */\ndeclare function fmod(x: f64, y: f64): f64;\n/** Returns the 32-bit floating-point remainder of `x/y`. */\ndeclare function fmodf(x: f32, y: f32): f32;\n\n/** Converts any other numeric value to an 8-bit signed integer. */\ndeclare function i8(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;\ndeclare namespace i8 {\n /** Smallest representable value. */\n export const MIN_VALUE: i8;\n /** Largest representable value. */\n export const MAX_VALUE: i8;\n}\n/** Converts any other numeric value to a 16-bit signed integer. */\ndeclare function i16(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;\ndeclare namespace i16 {\n /** Smallest representable value. */\n export const MIN_VALUE: i16;\n /** Largest representable value. */\n export const MAX_VALUE: i16;\n}\n/** Converts any other numeric value to a 32-bit signed integer. */\ndeclare function i32(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i32;\ndeclare namespace i32 {\n /** Smallest representable value. */\n export const MIN_VALUE: i32;\n /** Largest representable value. */\n export const MAX_VALUE: i32;\n}\n/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */\ndeclare function isize(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): isize;\ndeclare namespace isize {\n /** Smallest representable value. */\n export const MIN_VALUE: isize;\n /** Largest representable value. */\n export const MAX_VALUE: isize;\n}\n/** Converts any other numeric value to an 8-bit unsigned integer. */\ndeclare function u8(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;\ndeclare namespace u8 {\n /** Smallest representable value. */\n export const MIN_VALUE: u8;\n /** Largest representable value. */\n export const MAX_VALUE: u8;\n}\n/** Converts any other numeric value to a 16-bit unsigned integer. */\ndeclare function u16(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;\ndeclare namespace u16 {\n /** Smallest representable value. */\n export const MIN_VALUE: u16;\n /** Largest representable value. */\n export const MAX_VALUE: u16;\n}\n/** Converts any other numeric value to a 32-bit unsigned integer. */\ndeclare function u32(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i32;\ndeclare namespace u32 {\n /** Smallest representable value. */\n export const MIN_VALUE: u32;\n /** Largest representable value. */\n export const MAX_VALUE: u32;\n}\n/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */\ndeclare function usize(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): isize;\ndeclare namespace usize {\n /** Smallest representable value. */\n export const MIN_VALUE: usize;\n /** Largest representable value. */\n export const MAX_VALUE: usize;\n}\n/** Converts any other numeric value to a 1-bit unsigned integer. */\ndeclare function bool(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): bool;\ndeclare namespace bool {\n /** Smallest representable value. */\n export const MIN_VALUE: bool;\n /** Largest representable value. */\n export const MAX_VALUE: bool;\n}\n/** Converts any other numeric value to a 32-bit float. */\ndeclare function f32(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): f32;\ndeclare namespace f32 {\n /** Smallest representable value. */\n export const MIN_VALUE: f32;\n /** Largest representable value. */\n export const MAX_VALUE: f32;\n /** Smallest normalized positive value. */\n export const MIN_POSITIVE_VALUE: f32;\n /** Smallest safely representable integer value. */\n export const MIN_SAFE_INTEGER: f32;\n /** Largest safely representable integer value. */\n export const MAX_SAFE_INTEGER: f32;\n /** Difference between 1 and the smallest representable value greater than 1. */\n export const EPSILON: f32;\n}\n/** Converts any other numeric value to a 64-bit float. */\ndeclare function f64(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): f64;\ndeclare namespace f64 {\n /** Smallest representable value. */\n export const MIN_VALUE: f64;\n /** Largest representable value. */\n export const MAX_VALUE: f64;\n /** Smallest normalized positive value. */\n export const MIN_POSITIVE_VALUE: f64;\n /** Smallest safely representable integer value. */\n export const MIN_SAFE_INTEGER: f64;\n /** Largest safely representable integer value. */\n export const MAX_SAFE_INTEGER: f64;\n /** Difference between 1 and the smallest representable value greater than 1. */\n export const EPSILON: f64;\n}\n\n// Polyfills\n\n/** [Polyfill] Performs the sign-agnostic reverse bytes **/\ndeclare function bswap(value: T): T;\n/** [Polyfill] Performs the sign-agnostic reverse bytes only for last 16-bit **/\ndeclare function bswap16(value: T): T;\n\n// Standard library\n\n/** Memory operations. */\ndeclare namespace memory {\n /** Allocates a chunk of memory of the specified size and returns a pointer to it. */\n function allocate(size: usize): usize;\n /** Disposes a chunk of memory by its pointer. */\n function free(ptr: usize): void;\n /** Copies n bytes from the specified source to the specified destination in memory. These regions may overlap. */\n function copy(dst: usize, src: usize, n: usize): void;\n /** Resets the allocator to its initial state, if supported. */\n function reset(): void;\n}\n\n/** Class representing a generic, fixed-length raw binary data buffer. */\ndeclare class ArrayBuffer {\n /** The size, in bytes, of the array. */\n readonly byteLength: i32;\n /** Constructs a new array buffer of the given length in bytes. */\n constructor(length: i32);\n /** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */\n slice(begin?: i32, end?: i32): ArrayBuffer;\n}\n\ndeclare class Array {\n [key: number]: T;\n length: i32;\n constructor(capacity?: i32);\n fill(value: T, start?: i32, end?: i32): this;\n every(callbackfn: (element: T, index: i32, array?: Array) => bool): bool;\n findIndex(predicate: (element: T, index: i32, array?: Array) => bool): i32;\n includes(searchElement: T, fromIndex?: i32): bool;\n indexOf(searchElement: T, fromIndex?: i32): i32;\n lastIndexOf(searchElement: T, fromIndex?: i32): i32;\n push(element: T): i32;\n concat(items: T[]): T[];\n pop(): T;\n forEach(callbackfn: (value: T, index: i32, array: Array) => void): void;\n map(callbackfn: (value: T, index: i32, array: Array) => U): Array;\n filter(callbackfn: (value: T, index: i32, array: Array) => bool): Array;\n reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U): U;\n reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U): U;\n shift(): T;\n some(callbackfn: (element: T, index: i32, array?: Array) => bool): bool;\n unshift(element: T): i32;\n slice(from?: i32, to?: i32): T[];\n splice(start: i32, deleteCount?: i32): void;\n sort(comparator?: (a: T, b: T) => i32): this;\n join(separator?: string): string;\n reverse(): T[];\n toString(): string;\n}\n\ndeclare class Uint8Array extends Array {}\ndeclare class Uint16Array extends Array {}\ndeclare class Uint32Array extends Array {}\ndeclare class Int8Array extends Array {}\ndeclare class Int16Array extends Array {}\ndeclare class Int32Array extends Array {}\ndeclare class Float32Array extends Array {}\ndeclare class Float64Array extends Array {}\n\ndeclare class String {\n\n static fromCharCode(ls: i32, hs?: i32): string;\n static fromCharCodes(arr: u16[]): string;\n static fromCodePoint(code: i32): string;\n static fromCodePoints(arr: i32[]): string;\n\n readonly length: i32;\n\n private constructor();\n\n charAt(index: i32): string;\n charCodeAt(index: i32): i32;\n concat(other: string): string;\n indexOf(other: string, fromIndex?: i32): i32;\n lastIndexOf(other: string, fromIndex?: i32): i32;\n includes(other: string): bool;\n startsWith(other: string): bool;\n endsWith(other: string): bool;\n substr(start: u32, length?: u32): string;\n substring(from: i32, to?: i32): string;\n trim(): string;\n trimLeft(): string;\n trimRight(): string;\n trimStart(): string;\n trimEnd(): string;\n padStart(targetLength: i32, padString?: string): string;\n padEnd(targetLength: i32, padString?: string): string;\n replace(search: string, replacement: string): string;\n repeat(count?: i32): string;\n split(separator?: string, limit?: i32): string[];\n toString(): string;\n}\n\ninterface Boolean {}\n\ndeclare class Number {\n private constructor();\n toString(radix?: i32): string;\n}\n\ninterface Object {}\n\ninterface Function {}\n\ninterface RegExp {}\n\ninterface IArguments {}\n\ndeclare class Error {\n constructor(message: string);\n message: string;\n stack: string | null;\n}\n\ndeclare class Set {\n constructor(entries?: T[]);\n readonly size: i32;\n has(value: T): bool;\n add(value: T): void;\n delete(value: T): bool;\n clear(): void;\n [Symbol.iterator](): Iterator;\n}\n\ndeclare class Map {\n constructor(entries?: [K, V][]);\n readonly size: i32;\n set(key: K, value: V): void;\n has(key: K): bool;\n get(key: K): V | null;\n clear(): void;\n entries(): Iterable<[K, V]>;\n keys(): Iterable;\n values(): Iterable;\n delete(key: K): bool;\n [Symbol.iterator](): Iterator<[K,V]>;\n}\n\ninterface SymbolConstructor {\n (description?: string | null): symbol;\n for(key: string): symbol;\n keyFor(sym: symbol): string | null;\n readonly iterator: symbol;\n}\ndeclare const Symbol: SymbolConstructor;\n\ninterface Iterable {\n [Symbol.iterator](): Iterator;\n}\n\ninterface Iterator {}\n\ninterface IMath {\n readonly E: f64;\n readonly LN2: f64;\n readonly LN10: f64;\n readonly LOG2E: f64;\n readonly LOG10E: f64;\n readonly PI: f64;\n readonly SQRT1_2: f64;\n readonly SQRT2: f64;\n abs(x: f64): f64;\n acos(x: f64): f64;\n acosh(x: f64): f64;\n asin(x: f64): f64;\n asinh(x: f64): f64;\n atan(x: f64): f64;\n atan2(y: f64, x: f64): f64;\n atanh(x: f64): f64;\n cbrt(x: f64): f64;\n ceil(x: f64): f64;\n clz32(x: f64): i32;\n cos(x: f64): f64;\n cosh(x: f64): f64;\n exp(x: f64): f64;\n expm1(x: f64): f64;\n floor(x: f64): f64;\n fround(x: f64): f32;\n hypot(value1: f64, value2: f64): f64; // TODO: see std/math\n imul(a: f64, b: f64): i32;\n log(x: f64): f64;\n log10(x: f64): f64;\n log1p(x: f64): f64;\n log2(x: f64): f64;\n max(value1: f64, value2: f64): f64; // TODO: see std/math\n min(value1: f64, value2: f64): f64; // TODO: see std/math\n pow(base: f64, exponent: f64): f64;\n random(): f64;\n round(x: f64): f64;\n sign(x: f64): f64;\n sin(x: f64): f64;\n sinh(x: f64): f64;\n sqrt(x: f64): f64;\n tan(x: f64): f64;\n tanh(x: f64): f64;\n trunc(x: f64): f64;\n}\n\ndeclare const Math: IMath;\ndeclare const Mathf: IMath;\ndeclare const JSMath: IMath;\n\ndeclare namespace console {\n /** @deprecated */\n function log(message: string): void;\n}\n"}):(()=>{const e=path.join(".","..","std");return{assembly:fs.readFileSync(path.join(e,"assembly","index.d.ts"),"utf8"),portable:fs.readFileSync(path.join(e,"portable","index.d.ts"),"utf8")}})(),exports.compileString=((e,n)=>{"string"==typeof e&&(e={"input.ts":e});const t=Object.create({stdout:createMemoryStream(),stderr:createMemoryStream(),binary:null,text:null});var r=["--binaryFile","binary","--textFile","text"];return Object.keys(n||{}).forEach(e=>{var t=n[e];Array.isArray(t)?t.forEach(n=>r.push("--"+e,String(n))):r.push("--"+e,String(t))}),exports.main(r.concat(Object.keys(e)),{stdout:t.stdout,stderr:t.stderr,readFile:n=>e.hasOwnProperty(n)?e[n]:null,writeFile:(e,n)=>t[e]=n,listFiles:()=>[]}),t}),exports.main=function(e,n,t){"function"==typeof n?(t=n,n={}):n||(n={});const r=n.stdout||process.stdout,i=n.stderr||process.stderr,s=n.readFile||T,a=n.writeFile||A,o=n.listFiles||z,l=n.stats||createStats();if(!r)throw Error("'options.stdout' must be specified");if(!i)throw Error("'options.stderr' must be specified");const f=optionsUtil.parse(e,exports.options),u=f.options;if(e=f.arguments,u.noColors?colorsUtil.stdout.supported=colorsUtil.stderr.supported=!1:(colorsUtil.stdout=colorsUtil.from(r),colorsUtil.stderr=colorsUtil.from(i)),f.unknown.length&&f.unknown.forEach(e=>{i.write(colorsUtil.stderr.yellow("WARN: ")+"Unknown option '"+e+"'"+EOL)}),f.trailing.length&&i.write(colorsUtil.stderr.yellow("WARN: ")+"Unsupported trailing arguments: "+f.trailing.join(" ")+EOL),t||(t=function(e){var n=0;return e&&(i.write(colorsUtil.stderr.red("ERROR: ")+e.stack.replace(/^ERROR: /i,"")+EOL),n=1),n}),u.version)return r.write("Version "+exports.version+(isDev?"-dev":"")+EOL),t(null);if(u.help||!e.length){var c=u.help?r:i,p=u.help?colorsUtil.stdout:colorsUtil.stderr;return c.write([p.white("SYNTAX")," "+p.cyan("asc")+" [entryFile ...] [options]","",p.white("EXAMPLES")," "+p.cyan("asc")+" hello.ts"," "+p.cyan("asc")+" hello.ts -b hello.wasm -t hello.wat"," "+p.cyan("asc")+" hello1.ts hello2.ts -b -O > hello.wasm","",p.white("OPTIONS")].concat(optionsUtil.help(exports.options,24,EOL)).join(EOL)+EOL),t(null)}if(!fs.readFileSync){if(s===T)throw Error("'options.readFile' must be specified");if(a===A)throw Error("'options.writeFile' must be specified");if(o===z)throw Error("'options.listFiles' must be specified")}const h=u.baseDir?path.resolve(u.baseDir):".",d=[];u.transform&&u.transform.forEach(e=>d.push(__webpack_require__(12)(path.isAbsolute(e=e.trim())?e:path.join(process.cwd(),e))));var x=null;u.noLib?(l.parseCount++,l.parseTime+=measure(()=>{x=assemblyscript.parseFile(exports.libraryFiles.builtins,exports.libraryPrefix+"builtins.ts",!1,x)})):Object.keys(exports.libraryFiles).forEach(e=>{e.indexOf("/")>=0||(l.parseCount++,l.parseTime+=measure(()=>{x=assemblyscript.parseFile(exports.libraryFiles[e],exports.libraryPrefix+e+".ts",!1,x)}))});const g=[];if(u.lib){let e=u.lib;"string"==typeof e&&(e=e.split(",")),Array.prototype.push.apply(g,e.map(e=>e.trim()));for(let e=0,n=g.length;e{x=assemblyscript.parseFile(a,exports.libraryPrefix+i,!1,x)})}}}for(let n=0,r=e.length;n{x=assemblyscript.parseFile(o,a,!0,x)});null!=(a=x.nextFile());){if(a.startsWith(exports.libraryPrefix)){const e=a.substring(exports.libraryPrefix.length),n=a.substring(exports.libraryPrefix.length)+"/index";if(exports.libraryFiles.hasOwnProperty(e))o=exports.libraryFiles[e],a=exports.libraryPrefix+e+".ts";else if(exports.libraryFiles.hasOwnProperty(n))o=exports.libraryFiles[n],a=exports.libraryPrefix+n+".ts";else for(let t=0,r=g.length;t{assemblyscript.parseFile(o,a,!1,x)})}if(checkDiagnostics(x,i))return t(Error("Parse error"))}!function(e,...n){d.forEach(t=>{"function"==typeof t[e]&&t[e](...n)})}("afterParse",x);const b=assemblyscript.finishParsing(x);var y=0,m=0;u.optimize&&(y=exports.defaultOptimizeLevel,m=exports.defaultShrinkLevel),"number"==typeof u.optimizeLevel&&(y=u.optimizeLevel),"number"==typeof u.shrinkLevel&&(m=u.shrinkLevel),y=Math.min(Math.max(y,0),3),m=Math.min(Math.max(m,0),2);const v=assemblyscript.createOptions();if(assemblyscript.setTarget(v,0),assemblyscript.setNoTreeShaking(v,u.noTreeShaking),assemblyscript.setNoAssert(v,u.noAssert),assemblyscript.setImportMemory(v,u.importMemory),assemblyscript.setImportTable(v,u.importTable),assemblyscript.setMemoryBase(v,u.memoryBase>>>0),assemblyscript.setSourceMap(v,null!=u.sourceMap),assemblyscript.setOptimizeLevelHints(v,y,m),u.noLib||(assemblyscript.setGlobalAlias(v,"Math","NativeMath"),assemblyscript.setGlobalAlias(v,"Mathf","NativeMathf"),assemblyscript.setGlobalAlias(v,"abort","~lib/env/abort"),assemblyscript.setGlobalAlias(v,"trace","~lib/env/trace")),u.use){let e=u.use;for(let n=0,r=e.length;n{try{l.compileTime+=measure(()=>{_=assemblyscript.compileProgram(b,v)})}catch(e){return t(e)}})(),checkDiagnostics(x,i))return _&&_.dispose(),t(Error("Compile error"));if(u.validate&&(l.validateCount++,l.validateTime+=measure(()=>{if(!_.validate())return _.dispose(),t(Error("Validate error"))})),"clamp"===u.trapMode)l.optimizeCount++,l.optimizeTime+=measure(()=>{_.runPasses(["trap-mode-clamp"])});else if("js"===u.trapMode)l.optimizeCount++,l.optimizeTime+=measure(()=>{_.runPasses(["trap-mode-js"])});else if("allow"!==u.trapMode)return _.dispose(),t(Error("Unsupported trap mode"));(y>=3||m>=2)&&(y=4),_.setOptimizeLevel(y),_.setShrinkLevel(m),_.setDebugInfo(!u.noDebug);var F=[];if(u.runPasses&&("string"==typeof u.runPasses&&(u.runPasses=u.runPasses.split(",")),u.runPasses.length&&u.runPasses.forEach(e=>{F.indexOf(e)<0&&F.push(e)})),(y>0||m>0)&&(l.optimizeCount++,l.optimizeTime+=measure(()=>{_.optimize()})),F.length&&(l.optimizeCount++,l.optimizeTime+=measure(()=>{_.runPasses(F.map(e=>e.trim()))})),!u.noEmit){let e=!1,n=!1;if(null!=u.outFile&&(/\.was?t$/.test(u.outFile)&&null==u.textFile?u.textFile=u.outFile:/\.js$/.test(u.outFile)&&null==u.asmjsFile?u.asmjsFile=u.outFile:null==u.binaryFile&&(u.binaryFile=u.outFile)),null!=u.binaryFile){let r,o=null!=u.sourceMap?u.sourceMap.length?u.sourceMap:path.basename(u.binaryFile)+".map":null;if(l.emitCount++,l.emitTime+=measure(()=>{r=_.toBinary(o)}),u.binaryFile.length?a(path.join(h,u.binaryFile),r.output):(S(r.output),e=!0),n=!0,null!=r.sourceMap)if(u.binaryFile.length){let e=JSON.parse(r.sourceMap);e.sourceRoot=exports.sourceMapRoot,e.sources.forEach((n,r)=>{let i=null;if(n.startsWith(exports.libraryPrefix)){let e=n.substring(exports.libraryPrefix.length).replace(/\.ts$/,"");if(exports.libraryFiles.hasOwnProperty(e))i=exports.libraryFiles[e];else for(let e=0,t=g.length;e{t=_.toAsmjs()}),a(path.join(h,u.asmjsFile),t)):e||(l.emitCount++,l.emitTime+=measure(()=>{t=_.toAsmjs()}),S(t),e=!0),n=!0}if(null!=u.idlFile){let t;u.idlFile.length?(l.emitCount++,l.emitTime+=measure(()=>{t=assemblyscript.buildIDL(b)}),a(path.join(h,u.idlFile),t)):e||(l.emitCount++,l.emitTime+=measure(()=>{t=assemblyscript.buildIDL(b)}),S(t),e=!0),n=!0}if(null!=u.tsdFile){let t;u.tsdFile.length?(l.emitCount++,l.emitTime+=measure(()=>{t=assemblyscript.buildTSD(b)}),a(path.join(h,u.tsdFile),t)):e||(l.emitCount++,l.emitTime+=measure(()=>{t=assemblyscript.buildTSD(b)}),S(t),e=!0),n=!0}if(null!=u.textFile||!n){let n;u.textFile&&u.textFile.length?(l.emitCount++,l.emitTime+=measure(()=>{n=_.toText()}),a(path.join(h,u.textFile),n)):e||(l.emitCount++,l.emitTime+=measure(()=>{n=_.toText()}),S(n))}}return _.dispose(),u.measure&&printStats(l,i),t(null);function T(e){try{let n;return l.readCount++,l.readTime+=measure(()=>{n=fs.readFileSync(e,{encoding:"utf8"})}),n}catch(e){return null}}function A(e,n){try{return l.writeCount++,l.writeTime+=measure(()=>{mkdirp(path.dirname(e)),"string"==typeof n?fs.writeFileSync(e,n,{encoding:"utf8"}):fs.writeFileSync(e,n)}),!0}catch(e){return!1}}function z(e){var n;try{return l.readTime+=measure(()=>{n=fs.readdirSync(e).filter(e=>/^(?!.*\.d\.ts$).*\.ts$/.test(e))}),n}catch(e){return[]}}function S(e){S.used||(l.writeCount++,S.used=!0),l.writeTime+=measure(()=>{"string"==typeof e?r.write(e,{encoding:"utf8"}):r.write(e)})}};var argumentSubstitutions={"-O":["--optimize"],"-Os":["--optimize","--shrinkLevel","1"],"-Oz":["--optimize","--shrinkLevel","2"],"-O0":["--optimizeLevel","0","--shrinkLevel","0"],"-O0s":["--optimizeLevel","0","--shrinkLevel","1"],"-O0z":["--optimizeLevel","0","--shrinkLevel","2"],"-O1":["--optimizeLevel","1","--shrinkLevel","0"],"-O1s":["--optimizeLevel","1","--shrinkLevel","1"],"-O1z":["--optimizeLevel","1","--shrinkLevel","2"],"-O2":["--optimizeLevel","2","--shrinkLevel","0"],"-O2s":["--optimizeLevel","2","--shrinkLevel","1"],"-O2z":["--optimizeLevel","2","--shrinkLevel","2"],"-O3":["--optimizeLevel","3","--shrinkLevel","0"],"-O3s":["--optimizeLevel","3","--shrinkLevel","1"],"-O3z":["--optimizeLevel","3","--shrinkLevel","2"]};function checkDiagnostics(e,n){for(var t,r=!1;null!=(t=assemblyscript.nextDiagnostic(e));)n&&n.write(assemblyscript.formatDiagnostic(t,n.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(e){const n=process.hrtime();e();const t=process.hrtime(n);return 1e9*t[0]+t[1]}function formatTime(e){return e?(e/1e6).toFixed(3)+" ms":"N/A"}function printStats(e,n){function t(e,n){return formatTime(e)}(n||process.stdout).write(["I/O Read : "+t(e.readTime,e.readCount),"I/O Write : "+t(e.writeTime,e.writeCount),"Parse : "+t(e.parseTime,e.parseCount),"Compile : "+t(e.compileTime,e.compileCount),"Emit : "+t(e.emitTime,e.emitCount),"Validate : "+t(e.validateTime,e.validateCount),"Optimize : "+t(e.optimizeTime,e.optimizeCount)].join(EOL)+EOL)}exports.checkDiagnostics=checkDiagnostics,exports.createStats=createStats,process.hrtime||(process.hrtime=__webpack_require__(13)),exports.measure=measure,exports.formatTime=formatTime,exports.printStats=printStats;var allocBuffer=void 0!==global&&global.Buffer?global.Buffer.allocUnsafe||function(e){return new global.Buffer(e)}:function(e){return new Uint8Array(e)};function createMemoryStream(e){var n=[];return n.write=function(n){if(e&&e(n),"string"==typeof n){let e=allocBuffer(utf8.length(n));utf8.write(n,e,0),n=e}this.push(n)},n.reset=function(){n.length=0},n.toBuffer=function(){for(var e=0,n=0,t=this.length;n191&&r<224?s[a++]=(31&r)<<6|63&e[n++]:r>239&&r<365?(r=((7&r)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++])-65536,s[a++]=55296+(r>>10),s[a++]=56320+(1023&r)):s[a++]=(15&r)<<12|(63&e[n++])<<6|63&e[n++],a>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,s)),a=0);return i?(a&&i.push(String.fromCharCode.apply(String,s.slice(0,a))),i.join("")):String.fromCharCode.apply(String,s.slice(0,a))},r.write=function(e,n,t){for(var r,i,s=t,a=0;a>6|192,n[t++]=63&r|128):55296==(64512&r)&&56320==(64512&(i=e.charCodeAt(a+1)))?(r=65536+((1023&r)<<10)+(1023&i),++a,n[t++]=r>>18|240,n[t++]=r>>12&63|128,n[t++]=r>>6&63|128,n[t++]=63&r|128):(n[t++]=r>>12|224,n[t++]=r>>6&63|128,n[t++]=63&r|128);return t-s}},function(e,n,t){(function(e){var t=void 0!==e&&e||{},r=t.env&&"CI"in t.env;function i(e,t){var i=t||{};return i.supported=e&&!!e.isTTY||r,i.gray=(e=>i.supported?n.GRAY+e+n.RESET:e),i.red=(e=>i.supported?n.RED+e+n.RESET:e),i.green=(e=>i.supported?n.GREEN+e+n.RESET:e),i.yellow=(e=>i.supported?n.YELLOW+e+n.RESET:e),i.blue=(e=>i.supported?n.BLUE+e+n.RESET:e),i.magenta=(e=>i.supported?n.MAGENTA+e+n.RESET:e),i.cyan=(e=>i.supported?n.CYAN+e+n.RESET:e),i.white=(e=>i.supported?n.WHITE+e+n.RESET:e),i}n.stdout=i(t.stdout,n),n.stderr=i(t.stderr),n.from=i,n.GRAY="",n.RED="",n.GREEN="",n.YELLOW="",n.BLUE="",n.MAGENTA="",n.CYAN="",n.WHITE="",n.RESET=""}).call(this,t(0))},function(e,n){n.parse=function(e,n){var t={},r=[],arguments=[],i=[],s={};Object.keys(n).forEach(e=>{var r=n[e];null!=r.alias&&("string"==typeof r.alias?s[r.alias]=e:Array.isArray(r.alias)&&r.alias.forEach(n=>s[n]=e)),null!=r.default&&(t[e]=r.default)});for(var a=0,o=(e=e.slice()).length;at[e]=o.value[e])}else r.push(i)}for(;a{var a=e[n];if(null!=a.description){for(var o="";o.length{for(let n=0;n=0;r--){var i=e[r];"."===i?e.splice(r,1):".."===i?(e.splice(r,1),t++):t&&(e.splice(r,1),t--)}if(n)for(;t--;t)e.unshift("..");return e}var r=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,i=function(e){return r.exec(e).slice(1)};function s(e,n){if(e.filter)return e.filter(n);for(var t=[],r=0;r=-1&&!r;i--){var a=i>=0?arguments[i]:e.cwd();if("string"!=typeof a)throw new TypeError("Arguments to path.resolve must be strings");a&&(n=a+"/"+n,r="/"===a.charAt(0))}return n=t(s(n.split("/"),function(e){return!!e}),!r).join("/"),(r?"/":"")+n||"."},n.normalize=function(e){var r=n.isAbsolute(e),i="/"===a(e,-1);return(e=t(s(e.split("/"),function(e){return!!e}),!r).join("/"))||r||(e="."),e&&i&&(e+="/"),(r?"/":"")+e},n.isAbsolute=function(e){return"/"===e.charAt(0)},n.join=function(){var e=Array.prototype.slice.call(arguments,0);return n.normalize(s(e,function(e,n){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},n.relative=function(e,t){function r(e){for(var n=0;n=0&&""===e[t];t--);return n>t?[]:e.slice(n,t-n+1)}e=n.resolve(e).substr(1),t=n.resolve(t).substr(1);for(var i=r(e.split("/")),s=r(t.split("/")),a=Math.min(i.length,s.length),o=a,l=0;l{try{assemblyscript=__webpack_require__(10)}catch(e){try{__webpack_require__(!function(){var e=new Error("Cannot find module 'ts-node'");throw e.code="MODULE_NOT_FOUND",e}()).register({project:path.join(".","..","src","tsconfig.json")}),__webpack_require__(!function(){var e=new Error("Cannot find module '../src/glue/js'");throw e.code="MODULE_NOT_FOUND",e}()),assemblyscript=__webpack_require__(!function(){var e=new Error("Cannot find module '../src'");throw e.code="MODULE_NOT_FOUND",e}()),isDev=!0}catch(e_ts){try{assemblyscript=eval("require('./assemblyscript')")}catch(e){throw e.stack=e_ts.stack+"\n---\n"+e.stack,e}}}})(),exports.isBundle=!0,exports.isDev=isDev,exports.version=exports.isBundle?"0.5.0":__webpack_require__(!function(){var e=new Error("Cannot find module '../package.json'");throw e.code="MODULE_NOT_FOUND",e}()).version,exports.options=__webpack_require__(11),exports.sourceMapRoot="assemblyscript:///",exports.libraryPrefix=assemblyscript.LIBRARY_PREFIX,exports.defaultOptimizeLevel=2,exports.defaultShrinkLevel=1,exports.libraryFiles=exports.isBundle?Object({"allocator/arena":'/**\n * Arena Memory Allocator\n *\n * Provides a `memory.reset` function to reset the heap to its initial state. A user has to make\n * sure that there are no more references to cleared memory afterwards. Always aligns to 8 bytes.\n *\n * @module std/assembly/allocator/arena\n *//***/\n\nimport { AL_MASK, MAX_SIZE_32 } from "../internal/allocator";\n\nvar startOffset: usize = (HEAP_BASE + AL_MASK) & ~AL_MASK;\nvar offset: usize = startOffset;\n\n// Memory allocator interface\n\n@global export function __memory_allocate(size: usize): usize {\n if (size > MAX_SIZE_32) unreachable();\n var ptr = offset;\n var newPtr = (ptr + max(size, 1) + AL_MASK) & ~AL_MASK;\n var pagesBefore = memory.size();\n if (newPtr > pagesBefore << 16) {\n let pagesNeeded = ((newPtr - ptr + 0xffff) & ~0xffff) >>> 16;\n let pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) {\n unreachable(); // out of memory\n }\n }\n }\n offset = newPtr;\n return ptr;\n}\n\n@global export function __memory_free(ptr: usize): void { /* nop */ }\n\n@global export function __memory_reset(): void {\n offset = startOffset;\n}\n',"allocator/buddy":'/**\n * Buddy Memory Allocator.\n * @module std/assembly/allocator/buddy\n *//***/\n\n/*\n Copyright 2018 Evan Wallace\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the "Software"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n\n*/// see: https://github.com/evanw/buddy-malloc\n\n/*\n * This file implements a buddy memory allocator, which is an allocator that\n * allocates memory within a fixed linear address range. It spans the address\n * range with a binary tree that tracks free space. Both "malloc" and "free"\n * are O(log N) time where N is the maximum possible number of allocations.\n *\n * The "buddy" term comes from how the tree is used. When memory is allocated,\n * nodes in the tree are split recursively until a node of the appropriate size\n * is reached. Every split results in two child nodes, each of which is the\n * buddy of the other. When a node is freed, the node and its buddy can be\n * merged again if the buddy is also free. This makes the memory available\n * for larger allocations again.\n */\n\n/*\n * Every allocation needs an 8-byte header to store the allocation size while\n * staying 8-byte aligned. The address returned by "malloc" is the address\n * right after this header (i.e. the size occupies the 8 bytes before the\n * returned address).\n */\nconst HEADER_SIZE: usize = 8;\n\n/*\n * The minimum allocation size is 16 bytes because we have an 8-byte header and\n * we need to stay 8-byte aligned.\n */\nconst MIN_ALLOC_LOG2: usize = 4;\nconst MIN_ALLOC: usize = 1 << MIN_ALLOC_LOG2;\n\n/*\n * The maximum allocation size is currently set to 2gb. This is the total size\n * of the heap. It\'s technically also the maximum allocation size because the\n * heap could consist of a single allocation of this size. But of course real\n * heaps will have multiple allocations, so the real maximum allocation limit\n * is at most 1gb.\n */\nconst MAX_ALLOC_LOG2: usize = 30; // 31;\nconst MAX_ALLOC: usize = 1 << MAX_ALLOC_LOG2;\n\n/*\n * Allocations are done in powers of two starting from MIN_ALLOC and ending at\n * MAX_ALLOC inclusive. Each allocation size has a bucket that stores the free\n * list for that allocation size.\n *\n * Given a bucket index, the size of the allocations in that bucket can be\n * found with "(size_t)1 << (MAX_ALLOC_LOG2 - bucket)".\n */\nconst BUCKET_COUNT: usize = MAX_ALLOC_LOG2 - MIN_ALLOC_LOG2 + 1;\n\n/*\n * Free lists are stored as circular doubly-linked lists. Every possible\n * allocation size has an associated free list that is threaded through all\n * currently free blocks of that size. That means MIN_ALLOC must be at least\n * "sizeof(list_t)". MIN_ALLOC is currently 16 bytes, so this will be true for\n * both 32-bit and 64-bit.\n */\n@unmanaged\nclass List {\n prev: List;\n next: List;\n static readonly SIZE: usize = 2 * sizeof();\n}\n\n/*\n * Each bucket corresponds to a certain allocation size and stores a free list\n * for that size. The bucket at index 0 corresponds to an allocation size of\n * MAX_ALLOC (i.e. the whole address space).\n */\nvar BUCKETS_START: usize = HEAP_BASE;\nvar BUCKETS_END: usize = BUCKETS_START + BUCKET_COUNT * List.SIZE;\n\nfunction buckets$get(index: usize): List {\n assert(index < BUCKET_COUNT);\n return changetype(BUCKETS_START + index * List.SIZE);\n}\n\n/*\n * We could initialize the allocator by giving it one free block the size of\n * the entire address space. However, this would cause us to instantly reserve\n * half of the entire address space on the first allocation, since the first\n * split would store a free list entry at the start of the right child of the\n * root. Instead, we have the tree start out small and grow the size of the\n * tree as we use more memory. The size of the tree is tracked by this value.\n */\nvar bucket_limit: usize;\n\n/*\n * This array represents a linearized binary tree of bits. Every possible\n * allocation larger than MIN_ALLOC has a node in this tree (and therefore a\n * bit in this array).\n *\n * Given the index for a node, lineraized binary trees allow you to traverse to\n * the parent node or the child nodes just by doing simple arithmetic on the\n * index:\n *\n * - Move to parent: index = (index - 1) / 2;\n * - Move to left child: index = index * 2 + 1;\n * - Move to right child: index = index * 2 + 2;\n * - Move to sibling: index = ((index - 1) ^ 1) + 1;\n *\n * Each node in this tree can be in one of several states:\n *\n * - UNUSED (both children are UNUSED)\n * - SPLIT (one child is UNUSED and the other child isn\'t)\n * - USED (neither children are UNUSED)\n *\n * These states take two bits to store. However, it turns out we have enough\n * information to distinguish between UNUSED and USED from context, so we only\n * need to store SPLIT or not, which only takes a single bit.\n *\n * Note that we don\'t need to store any nodes for allocations of size MIN_ALLOC\n * since we only ever care about parent nodes.\n */\nconst SPLIT_COUNT: usize = (1 << (BUCKET_COUNT - 1)) / 8;\nvar NODE_IS_SPLIT_START: usize = BUCKETS_END;\nvar NODE_IS_SPLIT_END: usize = NODE_IS_SPLIT_START + SPLIT_COUNT * sizeof();\n\nfunction node_is_split$get(index: usize): i32 {\n assert(index < SPLIT_COUNT);\n return load(NODE_IS_SPLIT_START + index);\n}\n\nfunction node_is_split$set(index: usize, state: i32): void {\n assert(index < SPLIT_COUNT);\n store(NODE_IS_SPLIT_START + index, state);\n}\n\n/*\n * This is the starting address of the address range for this allocator. Every\n * returned allocation will be an offset of this pointer from 0 to MAX_ALLOC.\n */\nvar base_ptr: usize;\n\n/*\n * This is the maximum address that has ever been used by the allocator. It\'s\n * used to know when to call "brk" to request more memory from the kernel.\n */\nvar max_ptr: usize;\n\n/*\n * Make sure all addresses before "new_value" are valid and can be used. Memory\n * is allocated in a 2gb address range but that memory is not reserved up\n * front. It\'s only reserved when it\'s needed by calling this function. This\n * will return false if the memory could not be reserved.\n */\nfunction update_max_ptr(new_value: usize): i32 {\n if (new_value > max_ptr) {\n // if (brk(new_value)) {\n // return 0;\n // }\n let oldPages = memory.size();\n let newPages = (((new_value + 0xffff) & ~0xffff) >>> 16);\n assert(newPages > oldPages);\n if (memory.grow(newPages - oldPages) < 0) {\n return 0;\n }\n // max_ptr = new_value;\n max_ptr = newPages << 16;\n }\n return 1;\n}\n\n/*\n * Initialize a list to empty. Because these are circular lists, an "empty"\n * list is an entry where both links point to itself. This makes insertion\n * and removal simpler because they don\'t need any branches.\n */\nfunction list_init(list: List): void {\n list.prev = list;\n list.next = list;\n}\n\n/*\n * Append the provided entry to the end of the list. This assumes the entry\n * isn\'t in a list already because it overwrites the linked list pointers.\n */\nfunction list_push(list: List, entry: List): void {\n var prev = list.prev;\n entry.prev = prev;\n entry.next = list;\n prev.next = entry;\n list.prev = entry;\n}\n\n/*\n * Remove the provided entry from whichever list it\'s currently in. This\n * assumes that the entry is in a list. You don\'t need to provide the list\n * because the lists are circular, so the list\'s pointers will automatically\n * be updated if the first or last entries are removed.\n */\nfunction list_remove(entry: List): void {\n var prev = entry.prev;\n var next = entry.next;\n prev.next = next;\n next.prev = prev;\n}\n\n/*\n * Remove and return the first entry in the list or NULL if the list is empty.\n */\nfunction list_pop(list: List): List | null {\n var back = list.prev;\n if (back == list) return null;\n list_remove(back);\n return back;\n}\n\n/*\n * This maps from the index of a node to the address of memory that node\n * represents. The bucket can be derived from the index using a loop but is\n * required to be provided here since having them means we can avoid the loop\n * and have this function return in constant time.\n */\nfunction ptr_for_node(index: usize, bucket: usize): usize {\n return base_ptr + ((index - (1 << bucket) + 1) << (MAX_ALLOC_LOG2 - bucket));\n}\n\n/*\n * This maps from an address of memory to the node that represents that\n * address. There are often many nodes that all map to the same address, so\n * the bucket is needed to uniquely identify a node.\n */\nfunction node_for_ptr(ptr: usize, bucket: usize): usize {\n return ((ptr - base_ptr) >> (MAX_ALLOC_LOG2 - bucket)) + (1 << bucket) - 1;\n}\n\n/*\n * Given the index of a node, this returns the "is split" flag of the parent.\n */\nfunction parent_is_split(index: usize): bool {\n index = (index - 1) / 2;\n return ((node_is_split$get(index / 8) >>> (index % 8)) & 1) == 1;\n}\n\n/*\n * Given the index of a node, this flips the "is split" flag of the parent.\n */\nfunction flip_parent_is_split(index: usize): void {\n index = (index - 1) / 2;\n var indexDiv8 = index / 8;\n node_is_split$set(indexDiv8,\n node_is_split$get(indexDiv8) ^ (1 << (index % 8))\n );\n}\n\n/*\n * Given the requested size passed to "malloc", this function returns the index\n * of the smallest bucket that can fit that size.\n */\nfunction bucket_for_request(request: usize): usize {\n var bucket = BUCKET_COUNT - 1;\n var size = MIN_ALLOC;\n\n while (size < request) {\n bucket--;\n size *= 2;\n }\n\n return bucket;\n}\n\n/*\n * The tree is always rooted at the current bucket limit. This call grows the\n * tree by repeatedly doubling it in size until the root lies at the provided\n * bucket index. Each doubling lowers the bucket limit by 1.\n */\nfunction lower_bucket_limit(bucket: usize): u32 {\n while (bucket < bucket_limit) {\n let root = node_for_ptr(base_ptr, bucket_limit);\n let right_child: usize;\n\n /*\n * If the parent isn\'t SPLIT, that means the node at the current bucket\n * limit is UNUSED and our address space is entirely free. In that case,\n * clear the root free list, increase the bucket limit, and add a single\n * block with the newly-expanded address space to the new root free list.\n */\n if (!parent_is_split(root)) {\n list_remove(changetype(base_ptr));\n list_init(buckets$get(--bucket_limit));\n list_push(buckets$get(bucket_limit), changetype(base_ptr));\n continue;\n }\n\n /*\n * Otherwise, the tree is currently in use. Create a parent node for the\n * current root node in the SPLIT state with a right child on the free\n * list. Make sure to reserve the memory for the free list entry before\n * writing to it. Note that we do not need to flip the "is split" flag for\n * our current parent because it\'s already on (we know because we just\n * checked it above).\n */\n right_child = ptr_for_node(root + 1, bucket_limit);\n if (!update_max_ptr(right_child + List.SIZE)) {\n return 0;\n }\n list_push(buckets$get(bucket_limit), changetype(right_child));\n list_init(buckets$get(--bucket_limit));\n\n /*\n * Set the grandparent\'s SPLIT flag so if we need to lower the bucket limit\n * again, we\'ll know that the new root node we just added is in use.\n */\n root = (root - 1) / 2;\n if (root != 0) {\n flip_parent_is_split(root);\n }\n }\n\n return 1;\n}\n\n// Memory allocator interface\n\n@global export function __memory_allocate(request: usize): usize {\n var original_bucket: usize, bucket: usize;\n\n /*\n * Make sure it\'s possible for an allocation of this size to succeed. There\'s\n * a hard-coded limit on the maximum allocation size because of the way this\n * allocator works.\n */\n if (request > MAX_ALLOC - HEADER_SIZE) unreachable();\n\n /*\n * Initialize our global state if this is the first call to "malloc". At the\n * beginning, the tree has a single node that represents the smallest\n * possible allocation size. More memory will be reserved later as needed.\n */\n if (base_ptr == 0) {\n // base_ptr = max_ptr = (uint8_t *)sbrk(0);\n base_ptr = (NODE_IS_SPLIT_END + 7) & ~7; // must be aligned\n max_ptr = memory.size() << 16; // must grow first\n bucket_limit = BUCKET_COUNT - 1;\n if (!update_max_ptr(base_ptr + List.SIZE)) {\n return 0;\n }\n list_init(buckets$get(BUCKET_COUNT - 1));\n list_push(buckets$get(BUCKET_COUNT - 1), changetype(base_ptr));\n }\n\n /*\n * Find the smallest bucket that will fit this request. This doesn\'t check\n * that there\'s space for the request yet.\n */\n bucket = bucket_for_request(request + HEADER_SIZE);\n original_bucket = bucket;\n\n /*\n * Search for a bucket with a non-empty free list that\'s as large or larger\n * than what we need. If there isn\'t an exact match, we\'ll need to split a\n * larger one to get a match.\n */\n while (bucket + 1 != 0) {\n let size: usize, bytes_needed: usize, i: usize;\n let ptr: usize;\n\n /*\n * We may need to grow the tree to be able to fit an allocation of this\n * size. Try to grow the tree and stop here if we can\'t.\n */\n if (!lower_bucket_limit(bucket)) {\n return 0;\n }\n\n /*\n * Try to pop a block off the free list for this bucket. If the free list\n * is empty, we\'re going to have to split a larger block instead.\n */\n ptr = changetype(list_pop(buckets$get(bucket)));\n if (!ptr) {\n /*\n * If we\'re not at the root of the tree or it\'s impossible to grow the\n * tree any more, continue on to the next bucket.\n */\n if (bucket != bucket_limit || bucket == 0) {\n bucket--;\n continue;\n }\n\n /*\n * Otherwise, grow the tree one more level and then pop a block off the\n * free list again. Since we know the root of the tree is used (because\n * the free list was empty), this will add a parent above this node in\n * the SPLIT state and then add the new right child node to the free list\n * for this bucket. Popping the free list will give us this right child.\n */\n if (!lower_bucket_limit(bucket - 1)) {\n return 0;\n }\n ptr = changetype(list_pop(buckets$get(bucket)));\n }\n\n /*\n * Try to expand the address space first before going any further. If we\n * have run out of space, put this block back on the free list and fail.\n */\n size = 1 << (MAX_ALLOC_LOG2 - bucket);\n bytes_needed = bucket < original_bucket ? size / 2 + List.SIZE : size;\n if (!update_max_ptr(ptr + bytes_needed)) {\n list_push(buckets$get(bucket), changetype(ptr));\n return 0;\n }\n\n /*\n * If we got a node off the free list, change the node from UNUSED to USED.\n * This involves flipping our parent\'s "is split" bit because that bit is\n * the exclusive-or of the UNUSED flags of both children, and our UNUSED\n * flag (which isn\'t ever stored explicitly) has just changed.\n *\n * Note that we shouldn\'t ever need to flip the "is split" bit of our\n * grandparent because we know our buddy is USED so it\'s impossible for our\n * grandparent to be UNUSED (if our buddy chunk was UNUSED, our parent\n * wouldn\'t ever have been split in the first place).\n */\n i = node_for_ptr(ptr, bucket);\n if (i != 0) {\n flip_parent_is_split(i);\n }\n\n /*\n * If the node we got is larger than we need, split it down to the correct\n * size and put the new unused child nodes on the free list in the\n * corresponding bucket. This is done by repeatedly moving to the left\n * child, splitting the parent, and then adding the right child to the free\n * list.\n */\n while (bucket < original_bucket) {\n i = i * 2 + 1;\n bucket++;\n flip_parent_is_split(i);\n list_push(\n buckets$get(bucket),\n changetype(ptr_for_node(i + 1, bucket))\n );\n }\n\n /*\n * Now that we have a memory address, write the block header (just the size\n * of the allocation) and return the address immediately after the header.\n */\n store(ptr, request);\n return ptr + HEADER_SIZE;\n }\n\n return 0;\n}\n\n@global export function __memory_free(ptr: usize): void {\n var bucket: usize, i: usize;\n\n /*\n * Ignore any attempts to free a NULL pointer.\n */\n if (!ptr) {\n return;\n }\n\n /*\n * We were given the address returned by "malloc" so get back to the actual\n * address of the node by subtracting off the size of the block header. Then\n * look up the index of the node corresponding to this address.\n */\n ptr = ptr - HEADER_SIZE;\n bucket = bucket_for_request(load(ptr) + HEADER_SIZE);\n i = node_for_ptr(ptr, bucket);\n\n /*\n * Traverse up to the root node, flipping USED blocks to UNUSED and merging\n * UNUSED buddies together into a single UNUSED parent.\n */\n while (i != 0) {\n /*\n * Change this node from UNUSED to USED. This involves flipping our\n * parent\'s "is split" bit because that bit is the exclusive-or of the\n * UNUSED flags of both children, and our UNUSED flag (which isn\'t ever\n * stored explicitly) has just changed.\n */\n flip_parent_is_split(i);\n\n /*\n * If the parent is now SPLIT, that means our buddy is USED, so don\'t merge\n * with it. Instead, stop the iteration here and add ourselves to the free\n * list for our bucket.\n *\n * Also stop here if we\'re at the current root node, even if that root node\n * is now UNUSED. Root nodes don\'t have a buddy so we can\'t merge with one.\n */\n if (parent_is_split(i) || bucket == bucket_limit) {\n break;\n }\n\n /*\n * If we get here, we know our buddy is UNUSED. In this case we should\n * merge with that buddy and continue traversing up to the root node. We\n * need to remove the buddy from its free list here but we don\'t need to\n * add the merged parent to its free list yet. That will be done once after\n * this loop is finished.\n */\n list_remove(changetype(ptr_for_node(((i - 1) ^ 1) + 1, bucket)));\n i = (i - 1) / 2;\n bucket--;\n }\n\n /*\n * Add ourselves to the free list for our bucket. We add to the back of the\n * list because "malloc" takes from the back of the list and we want a "free"\n * followed by a "malloc" of the same size to ideally use the same address\n * for better memory locality.\n */\n list_push(buckets$get(bucket), changetype(ptr_for_node(i, bucket)));\n}\n',"allocator/emscripten":"/**\n * Emscripten Memory Allocator.\n *\n * Uses Emscripten's exported _malloc and _free implementations, i.e., when linking with\n * Emscripten-compiled programs that already provide these. Differs from 'system' in that their\n * names are prefixed with an underscore.\n *\n * @module std/assembly/allocator/emscripten\n *//***/\n\ndeclare function _malloc(size: usize): usize;\ndeclare function _free(ptr: usize): void;\n\n// Memory allocator interface\n\n@global export function __memory_allocate(size: usize): usize {\n return _malloc(size);\n}\n\n@global export function __memory_free(ptr: usize): void {\n _free(ptr);\n}\n","allocator/system":"/**\n * System Memory Allocator.\n *\n * Uses the environment's malloc and free implementations, i.e., when linking with other C-like\n * programs that already provide these.\n *\n * @module std/assembly/allocator/system\n *//***/\n\ndeclare function malloc(size: usize): usize;\ndeclare function free(ptr: usize): void;\n\n// Memory allocator interface\n\n@global export function __memory_allocate(size: usize): usize {\n return malloc(size);\n}\n\n@global export function __memory_free(ptr: usize): void {\n free(ptr);\n}\n","allocator/tlsf":"/**\n * Two-Level Segregate Fit Memory Allocator.\n *\n * A general purpose dynamic memory allocator specifically designed to meet real-time requirements.\n * Always aligns to 8 bytes.\n *\n * @module std/assembly/allocator/tlsf\n *//***/\n\n// ╒══════════════ Block size interpretation (32-bit) ═════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┴─┴─┴─┴─╫─┴─┴─┤\n// │ | FL │ SB = SL + AL │ ◄─ usize\n// └───────────────────────────────────────────────┴─────────╨─────┘\n// FL: first level, SL: second level, AL: alignment, SB: small block\n\nimport {\n AL_BITS,\n AL_SIZE,\n AL_MASK\n} from \"../internal/allocator\";\n\nconst SL_BITS: u32 = 5;\nconst SL_SIZE: usize = 1 << SL_BITS;\n\nconst SB_BITS: usize = (SL_BITS + AL_BITS);\nconst SB_SIZE: usize = 1 << SB_BITS;\n\nconst FL_BITS: u32 = (sizeof() == sizeof()\n ? 30 // ^= up to 1GB per block\n : 32 // ^= up to 4GB per block\n) - SB_BITS;\n\n// ╒════════════════ Block structure layout (32-bit) ══════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┼─┤\n// │ size │L│F│ ◄─┐ info\n// ╞═══════════════════════════════════════════════════════════╧═╧═╡ │ ┐\n// │ if free: ◄ prev │ ◄─┤ usize\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ if free: next ► │ ◄─┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... unused free space >= 0 ... │ │ = 0\n// ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤ │\n// │ if free: jump ▲ │ ◄─┘\n// └───────────────────────────────────────────────────────────────┘ MIN SIZE ┘\n// F: FREE, L: LEFT_FREE\n\n/** Tag indicating that this block is free. */\nconst FREE: usize = 1 << 0;\n/** Tag indicating that this block's left block is free. */\nconst LEFT_FREE: usize = 1 << 1;\n/** Mask to obtain all tags. */\nconst TAGS: usize = FREE | LEFT_FREE;\n\n/** Block structure. */\n@unmanaged\nclass Block {\n\n /** Info field holding this block's size and tags. */\n info: usize;\n\n /** End offset of the {@link Block#info} field. User data starts here. */\n static readonly INFO: usize = (sizeof() + AL_MASK) & ~AL_MASK;\n\n /** Previous free block, if any. Only valid if free. */\n prev: Block | null;\n /** Next free block, if any. Only valid if free. */\n next: Block | null;\n\n /** Minimum size of a block, excluding {@link Block#info}. */\n static readonly MIN_SIZE: usize = (3 * sizeof() + AL_MASK) & ~AL_MASK;// prev + next + jump\n\n /** Maximum size of a used block, excluding {@link Block#info}. */\n static readonly MAX_SIZE: usize = 1 << (FL_BITS + SB_BITS);\n\n /** Gets this block's left (free) block in memory. */\n get left(): Block {\n assert(this.info & LEFT_FREE); // must be free to contain a jump\n return assert(\n load(changetype(this) - sizeof())\n ); // can't be null\n }\n\n /** Gets this block's right block in memory. */\n get right(): Block {\n assert(this.info & ~TAGS); // can't skip beyond the tail block\n return assert(\n changetype(\n changetype(this) + Block.INFO + (this.info & ~TAGS)\n )\n ); // can't be null\n }\n}\n\n// ╒════════════════ Root structure layout (32-bit) ═══════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ ┐\n// │ 0 | flMap S│ ◄────┐\n// ╞═══════════════════════════════════════════════════════════════╡ │\n// │ slMap[0] S │ ◄─┐ │\n// ├───────────────────────────────────────────────────────────────┤ │ │\n// │ slMap[1] │ ◄─┤ │\n// ├───────────────────────────────────────────────────────────────┤ u32 │\n// │ ... │ ◄─┤ │\n// ├───────────────────────────────────────────────────────────────┤ │ │\n// │ slMap[22] P │ ◄─┘ │\n// ╞═══════════════════════════════════════════════════════════════╡ usize\n// │ head[0] │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ head[736] │ ◄────┤\n// ╞═══════════════════════════════════════════════════════════════╡ │\n// │ tailRef │ ◄────┘\n// └───────────────────────────────────────────────────────────────┘ SIZE ┘\n// S: Small blocks map, P: Possibly padded if 64-bit\n\nassert((1 << SL_BITS) <= 32); // second level must fit into 32 bits\n\n/** Root structure. */\n@unmanaged\nclass Root {\n\n /** First level bitmap. */\n flMap: usize = 0;\n\n /** Start offset of second level maps. */\n private static readonly SL_START: usize = sizeof();\n\n // Using *one* SL map per *FL bit*\n\n /** Gets the second level map for the specified first level. */\n getSLMap(fl: usize): u32 {\n assert(fl < FL_BITS); // fl out of range\n return load(changetype(this) + fl * 4, Root.SL_START);\n }\n\n /** Sets the second level map for the specified first level. */\n setSLMap(fl: usize, value: u32): void {\n assert(fl < FL_BITS); // fl out of range\n store(changetype(this) + fl * 4, value, Root.SL_START);\n }\n\n /** End offset of second level maps. */\n private static readonly SL_END: usize = Root.SL_START + FL_BITS * 4;\n\n // Using *number bits per SL* heads per *FL bit*\n\n /** Start offset of FL/SL heads. */\n private static readonly HL_START: usize = (Root.SL_END + AL_MASK) & ~AL_MASK;\n\n /** Gets the head of the specified first and second level index. */\n getHead(fl: usize, sl: u32): Block | null {\n assert(fl < FL_BITS); // fl out of range\n assert(sl < SL_SIZE); // sl out of range\n return changetype(load(\n changetype(this) + (fl * SL_SIZE + sl) * sizeof()\n , Root.HL_START));\n }\n\n /** Sets the head of the specified first and second level index. */\n setHead(fl: usize, sl: u32, value: Block | null): void {\n assert(fl < FL_BITS); // fl out of range\n assert(sl < SL_SIZE); // sl out of range\n store(\n changetype(this) + (fl * SL_SIZE + sl) * sizeof()\n , changetype(value)\n , Root.HL_START);\n }\n\n /** End offset of FL/SL heads. */\n private static readonly HL_END: usize = (\n Root.HL_START + FL_BITS * SL_SIZE * sizeof()\n );\n\n get tailRef(): usize { return load(0, Root.HL_END); }\n set tailRef(value: usize) { store(0, value, Root.HL_END); }\n\n /** Total size of the {@link Root} structure. */\n static readonly SIZE: usize = Root.HL_END + sizeof();\n\n /** Inserts a previously used block back into the free list. */\n insert(block: Block): void {\n // check as much as possible here to prevent invalid free blocks\n assert(block); // cannot be null\n var blockInfo = block.info;\n assert(blockInfo & FREE); // must be free\n var size: usize;\n assert(\n (size = block.info & ~TAGS) >= Block.MIN_SIZE && size < Block.MAX_SIZE\n ); // must be valid, not necessary to compute yet if noAssert=true\n\n var right: Block = assert(block.right); // can't be null\n var rightInfo = right.info;\n\n // merge with right block if also free\n if (rightInfo & FREE) {\n this.remove(right);\n block.info = (blockInfo += Block.INFO + (rightInfo & ~TAGS));\n right = block.right;\n rightInfo = right.info;\n // jump is set below\n }\n\n // merge with left block if also free\n if (blockInfo & LEFT_FREE) {\n let left: Block = assert(block.left); // can't be null\n let leftInfo = left.info;\n assert(leftInfo & FREE); // must be free according to tags\n this.remove(left);\n left.info = (leftInfo += Block.INFO + (blockInfo & ~TAGS));\n block = left;\n blockInfo = leftInfo;\n // jump is set below\n }\n\n right.info = rightInfo | LEFT_FREE;\n this.setJump(block, right);\n // right is no longer used now, hence rightInfo is not synced\n\n size = blockInfo & ~TAGS;\n assert(size >= Block.MIN_SIZE && size < Block.MAX_SIZE); // must be valid\n\n // mapping_insert\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size / AL_SIZE);\n } else {\n fl = fls(size);\n sl = ((size >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n\n // perform insertion\n var head = this.getHead(fl, sl);\n block.prev = null;\n block.next = head;\n if (head) head.prev = block;\n this.setHead(fl, sl, block);\n\n // update first and second level maps\n this.flMap |= (1 << fl);\n this.setSLMap(fl, this.getSLMap(fl) | (1 << sl));\n }\n\n /**\n * Removes a free block from FL/SL maps. Does not alter left/jump because it\n * is likely that splitting is performed afterwards, invalidating any changes\n * again.\n */\n private remove(block: Block): void {\n var blockInfo = block.info;\n assert(blockInfo & FREE); // must be free\n var size = blockInfo & ~TAGS;\n assert(size >= Block.MIN_SIZE && size < Block.MAX_SIZE); // must be valid\n\n // mapping_insert\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size / AL_SIZE);\n } else {\n fl = fls(size);\n sl = ((size >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n\n // link previous and next free block\n var prev = block.prev;\n var next = block.next;\n if (prev) prev.next = next;\n if (next) next.prev = prev;\n\n // update head if we are removing it\n if (block == this.getHead(fl, sl)) {\n this.setHead(fl, sl, next);\n\n // clear second level map if head is empty now\n if (!next) {\n let slMap = this.getSLMap(fl);\n this.setSLMap(fl, slMap &= ~(1 << sl));\n\n // clear first level map if second level is empty now\n if (!slMap) this.flMap &= ~(1 << fl);\n }\n }\n }\n\n /** Searches for a free block of at least the specified size. */\n search(size: usize): Block | null {\n assert(size >= Block.MIN_SIZE && size < Block.MAX_SIZE);\n\n // mapping_search\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size / AL_SIZE);\n } else {\n // (*) size += (1 << (fls(size) - SL_BITS)) - 1;\n fl = fls(size);\n sl = ((size >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n // (*) instead of rounding up, use next second level list for better fit\n if (sl < SL_SIZE - 1) ++sl;\n else ++fl, sl = 0;\n }\n\n // search second level\n var slMap = this.getSLMap(fl) & (~0 << sl);\n var head: Block | null;\n if (!slMap) {\n // search next larger first level\n let flMap = this.flMap & (~0 << (fl + 1));\n if (!flMap) {\n head = null;\n } else {\n fl = ffs(flMap);\n slMap = assert(this.getSLMap(fl)); // can't be zero if fl points here\n head = this.getHead(fl, ffs(slMap));\n }\n } else {\n head = this.getHead(fl, ffs(slMap));\n }\n return head;\n }\n\n /** Links a free left with its right block in memory. */\n private setJump(left: Block, right: Block): void {\n assert(left.info & FREE); // must be free\n assert(left.right == right); // right block must match\n assert(right.info & LEFT_FREE); // right block must be tagged as LEFT_FREE\n store(\n changetype(right) - sizeof()\n , left); // last word in left block's (free) data region\n }\n\n /**\n * Uses the specified free block, removing it from internal maps and\n * splitting it if possible, and returns its data pointer.\n */\n use(block: Block, size: usize): usize {\n var blockInfo = block.info;\n assert(blockInfo & FREE); // must be free so we can use it\n assert(size >= Block.MIN_SIZE && size < Block.MAX_SIZE); // must be valid\n assert(!(size & AL_MASK)); // size must be aligned so the new block is\n\n this.remove(block);\n\n // split if the block can hold another MIN_SIZE block\n var remaining = (blockInfo & ~TAGS) - size;\n if (remaining >= Block.INFO + Block.MIN_SIZE) {\n block.info = size | (blockInfo & LEFT_FREE); // also discards FREE\n\n let spare = changetype(\n changetype(block) + Block.INFO + size\n );\n spare.info = (remaining - Block.INFO) | FREE; // not LEFT_FREE\n this.insert(spare); // also sets jump\n\n // otherwise tag block as no longer FREE and right as no longer LEFT_FREE\n } else {\n block.info = blockInfo & ~FREE;\n let right: Block = assert(block.right); // can't be null (tail)\n right.info &= ~LEFT_FREE;\n }\n\n return changetype(block) + Block.INFO;\n }\n\n /** Adds more memory to the pool. */\n addMemory(start: usize, end: usize): bool {\n assert(start <= end);\n assert(!(start & AL_MASK)); // must be aligned\n assert(!(end & AL_MASK)); // must be aligned\n\n var tailRef = this.tailRef;\n var tailInfo: usize = 0;\n if (tailRef) {\n assert(start >= tailRef + sizeof()); // starts after tail\n\n // merge with current tail if adjacent\n if (start - Block.INFO == tailRef) {\n start -= Block.INFO;\n tailInfo = changetype(tailRef).info;\n }\n\n } else {\n assert(start >= changetype(this) + Root.SIZE); // starts after root\n }\n\n // check if size is large enough for a free block and the tail block\n var size = end - start;\n if (size < Block.INFO + Block.MIN_SIZE + Block.INFO) {\n return false;\n }\n\n // left size is total minus its own and the zero-length tail's header\n var leftSize = size - 2 * Block.INFO;\n var left = changetype(start);\n left.info = leftSize | FREE | (tailInfo & LEFT_FREE);\n left.prev = null;\n left.next = null;\n\n // tail is a zero-length used block\n var tail = changetype(start + size - Block.INFO);\n tail.info = 0 | LEFT_FREE;\n this.tailRef = changetype(tail);\n\n this.insert(left); // also merges with free left before tail / sets jump\n\n return true;\n }\n}\n\n/** Determines the first (LSB to MSB) set bit's index of a word. */\nfunction ffs(word: T): T {\n assert(word != 0); // word cannot be 0\n return ctz(word); // differs from ffs only for 0\n}\n\n/** Determines the last (LSB to MSB) set bit's index of a word. */\nfunction fls(word: T): T {\n assert(word != 0); // word cannot be 0\n const inv: T = (sizeof() << 3) - 1;\n return inv - clz(word);\n}\n\n/** Reference to the initialized {@link Root} structure, once initialized. */\nvar ROOT: Root = changetype(0);\n\n// Memory allocator interface\n\n/** Allocates a chunk of memory. */\n@global export function __memory_allocate(size: usize): usize {\n\n // initialize if necessary\n var root = ROOT;\n if (!root) {\n let rootOffset = (HEAP_BASE + AL_MASK) & ~AL_MASK;\n let pagesBefore = memory.size();\n let pagesNeeded = ((((rootOffset + Root.SIZE) + 0xffff) & ~0xffff) >>> 16);\n if (pagesNeeded > pagesBefore && memory.grow(pagesNeeded - pagesBefore) < 0) unreachable();\n ROOT = root = changetype(rootOffset);\n root.tailRef = 0;\n root.flMap = 0;\n for (let fl: usize = 0; fl < FL_BITS; ++fl) {\n root.setSLMap(fl, 0);\n for (let sl: u32 = 0; sl < SL_SIZE; ++sl) {\n root.setHead(fl, sl, null);\n }\n }\n root.addMemory((rootOffset + Root.SIZE + AL_MASK) & ~AL_MASK, memory.size() << 16);\n }\n\n // search for a suitable block\n if (size > Block.MAX_SIZE) unreachable();\n\n // 32-bit MAX_SIZE is 1 << 30 and itself aligned, hence the following can't overflow MAX_SIZE\n size = max((size + AL_MASK) & ~AL_MASK, Block.MIN_SIZE);\n\n var block = root.search(size);\n if (!block) {\n\n // request more memory\n let pagesBefore = memory.size();\n let pagesNeeded = (((size + 0xffff) & ~0xffff) >>> 16);\n let pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) {\n unreachable(); // out of memory\n }\n }\n let pagesAfter = memory.size();\n root.addMemory(pagesBefore << 16, pagesAfter << 16);\n block = assert(root.search(size)); // must be found now\n }\n\n assert((block.info & ~TAGS) >= size);\n return root.use(block, size);\n}\n\n/** Frees the chunk of memory at the specified address. */\n@global export function __memory_free(data: usize): void {\n if (data) {\n let root = ROOT;\n if (root) {\n let block = changetype(data - Block.INFO);\n let blockInfo = block.info;\n assert(!(blockInfo & FREE)); // must be used\n block.info = blockInfo | FREE;\n root.insert(changetype(data - Block.INFO));\n }\n }\n}\n\n@global export function __memory_reset(): void {\n unreachable();\n}\n",array:'import {\n MAX_BLENGTH,\n HEADER_SIZE,\n allocateUnsafe,\n reallocateUnsafe,\n loadUnsafe,\n storeUnsafe\n} from "./internal/arraybuffer";\n\nimport {\n allocateUnsafe as allocateUnsafeString,\n freeUnsafe as freeUnsafeString,\n copyUnsafe as copyUnsafeString\n} from "./internal/string";\n\nimport {\n defaultComparator,\n insertionSort,\n weakHeapSort\n} from "./internal/array";\n\nimport {\n itoa,\n dtoa,\n itoa_stream,\n dtoa_stream,\n MAX_DOUBLE_LENGTH\n} from "./internal/number";\n\nexport class Array {\n\n /* @internal */ buffer_: ArrayBuffer;\n /* @internal */ length_: i32;\n\n constructor(length: i32 = 0) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (length > MAX_LENGTH) throw new RangeError("Invalid array length");\n var byteLength = length << alignof();\n var buffer = allocateUnsafe(byteLength);\n this.buffer_ = buffer;\n this.length_ = length;\n memory.fill(\n changetype(buffer) + HEADER_SIZE,\n 0,\n byteLength\n );\n }\n\n @inline\n get length(): i32 {\n return this.length_;\n }\n\n set length(length: i32) {\n var buffer = this.buffer_;\n var capacity = buffer.byteLength >>> alignof();\n if (length > capacity) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (length > MAX_LENGTH) throw new RangeError("Invalid array length");\n buffer = reallocateUnsafe(buffer, length << alignof());\n this.buffer_ = buffer;\n }\n this.length_ = length;\n }\n\n every(callbackfn: (element: T, index: i32, array: Array) => bool): bool {\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n if (!callbackfn(loadUnsafe(buffer, index), index, this)) return false;\n }\n return true;\n }\n\n findIndex(predicate: (element: T, index: i32, array: Array) => bool): i32 {\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n if (predicate(loadUnsafe(buffer, index), index, this)) return index;\n }\n return -1;\n }\n\n @operator("[]")\n private __get(index: i32): T {\n var buffer = this.buffer_;\n return index < (buffer.byteLength >>> alignof())\n ? loadUnsafe(buffer, index)\n : unreachable();\n }\n\n @operator("{}")\n private __unchecked_get(index: i32): T {\n return loadUnsafe(this.buffer_, index);\n }\n\n @operator("[]=")\n private __set(index: i32, value: T): void {\n var buffer = this.buffer_;\n var capacity = buffer.byteLength >>> alignof();\n if (index >= capacity) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (index >= MAX_LENGTH) throw new Error("Invalid array length");\n buffer = reallocateUnsafe(buffer, (index + 1) << alignof());\n this.buffer_ = buffer;\n this.length_ = index + 1;\n }\n storeUnsafe(buffer, index, value);\n if (isManaged()) __gc_link(changetype(this), changetype(value)); // tslint:disable-line\n }\n\n @operator("{}=")\n private __unchecked_set(index: i32, value: T): void {\n storeUnsafe(this.buffer_, index, value);\n if (isManaged()) __gc_link(changetype(this), changetype(value)); // tslint:disable-line\n }\n\n fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): this {\n var buffer = this.buffer_;\n var len = this.length_;\n start = start < 0 ? max(len + start, 0) : min(start, len);\n end = end < 0 ? max(len + end, 0) : min(end, len);\n if (sizeof() == 1) {\n if (start < end) {\n memory.fill(\n changetype(buffer) + start + HEADER_SIZE,\n value,\n (end - start)\n );\n }\n } else {\n for (; start < end; ++start) {\n storeUnsafe(buffer, start, value);\n }\n }\n return this;\n }\n\n @inline\n includes(searchElement: T, fromIndex: i32 = 0): bool {\n return this.indexOf(searchElement, fromIndex) >= 0;\n }\n\n indexOf(searchElement: 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 buffer = this.buffer_;\n while (fromIndex < length) {\n if (loadUnsafe(buffer, fromIndex) == searchElement) return fromIndex;\n ++fromIndex;\n }\n return -1;\n }\n\n lastIndexOf(searchElement: T, fromIndex: i32 = this.length_): i32 {\n var length = this.length_;\n if (length == 0) return -1;\n if (fromIndex < 0) fromIndex = length + fromIndex; // no need to clamp\n else if (fromIndex >= length) fromIndex = length - 1;\n var buffer = this.buffer_;\n while (fromIndex >= 0) { // ^\n if (loadUnsafe(buffer, fromIndex) == searchElement) return fromIndex;\n --fromIndex;\n }\n return -1;\n }\n\n push(element: T): i32 {\n var length = this.length_;\n var buffer = this.buffer_;\n var capacity = buffer.byteLength >>> alignof();\n var newLength = length + 1; // safe only if length is checked\n if (length >= capacity) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (length >= MAX_LENGTH) throw new Error("Invalid array length");\n buffer = reallocateUnsafe(buffer, newLength << alignof());\n this.buffer_ = buffer;\n }\n this.length_ = newLength;\n storeUnsafe(buffer, length, element);\n if (isManaged()) __gc_link(changetype(this), changetype(element)); // tslint:disable-line\n return newLength;\n }\n\n concat(items: Array): Array {\n var thisLen: isize = this.length_;\n var otherLen = (items == null) ? 0 : items.length_;\n var outLen = thisLen + otherLen;\n var out: Array = new Array(outLen);\n\n if (thisLen) {\n memory.copy(changetype(out.buffer_) + HEADER_SIZE,\n changetype(this.buffer_) + HEADER_SIZE,\n (thisLen << alignof()));\n }\n if (otherLen) {\n memory.copy(changetype(out.buffer_) + HEADER_SIZE + (thisLen << alignof()),\n changetype(items.buffer_) + HEADER_SIZE,\n (otherLen << alignof()));\n }\n return out;\n }\n\n pop(): T {\n var length = this.length_;\n if (length < 1) throw new RangeError("Array is empty");\n var element = loadUnsafe(this.buffer_, --length);\n this.length_ = length;\n return element;\n }\n\n forEach(callbackfn: (value: T, index: i32, array: Array) => void): void {\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n callbackfn(loadUnsafe(buffer, index), index, this);\n }\n }\n\n map(callbackfn: (value: T, index: i32, array: Array) => U): Array {\n var buffer = this.buffer_;\n var length = this.length_;\n var result = new Array(length);\n var resultBuffer = result.buffer_;\n for (let index = 0; index < length && index < this.length_; ++index) {\n storeUnsafe(resultBuffer, index, callbackfn(loadUnsafe(buffer, index), index, this));\n }\n return result;\n }\n\n filter(callbackfn: (value: T, index: i32, array: Array) => bool): Array {\n var buffer = this.buffer_;\n var length = this.length_;\n var result = new Array();\n for (let index = 0; index < length && index < this.length_; ++index) {\n let value = loadUnsafe(buffer, index);\n if (callbackfn(value, index, this)) result.push(value);\n }\n return result;\n }\n\n reduce(\n callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var accum = initialValue;\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n accum = callbackfn(accum, loadUnsafe(buffer, index), index, this);\n }\n return accum;\n }\n\n reduceRight(\n callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var accum = initialValue;\n var buffer = this.buffer_;\n for (let index: i32 = this.length_ - 1; index >= 0; --index) {\n accum = callbackfn(accum, loadUnsafe(buffer, index), index, this);\n }\n return accum;\n }\n\n shift(): T {\n var length = this.length_;\n if (length < 1) throw new RangeError("Array is empty");\n var buffer = this.buffer_;\n var element = loadUnsafe(buffer, 0);\n var lastIndex = length - 1;\n memory.copy(\n changetype(buffer) + HEADER_SIZE,\n changetype(buffer) + HEADER_SIZE + sizeof(),\n lastIndex << alignof()\n );\n storeUnsafe(buffer, lastIndex, null);\n this.length_ = lastIndex;\n return element;\n }\n\n some(callbackfn: (element: T, index: i32, array: Array) => bool): bool {\n var buffer = this.buffer_;\n for (let index = 0, toIndex = this.length_; index < toIndex && index < this.length_; ++index) {\n if (callbackfn(loadUnsafe(buffer, index), index, this)) return true;\n }\n return false;\n }\n\n unshift(element: T): i32 {\n var buffer = this.buffer_;\n var capacity = buffer.byteLength >>> alignof();\n var length = this.length_;\n var newLength = length + 1; // safe only if length is checked\n if (length >= capacity) {\n const MAX_LENGTH = MAX_BLENGTH >>> alignof();\n if (length >= MAX_LENGTH) throw new Error("Invalid array length");\n buffer = reallocateUnsafe(buffer, newLength << alignof());\n capacity = buffer.byteLength >>> alignof();\n this.buffer_ = buffer;\n }\n memory.copy(\n changetype(buffer) + HEADER_SIZE + sizeof(),\n changetype(buffer) + HEADER_SIZE,\n (capacity - 1) << alignof()\n );\n storeUnsafe(buffer, 0, element);\n this.length_ = newLength;\n if (isManaged()) __gc_link(changetype(this), changetype(element)); // tslint:disable-line\n return newLength;\n }\n\n slice(begin: i32 = 0, end: i32 = i32.MAX_VALUE): Array {\n var length = this.length_;\n if (begin < 0) begin = max(length + begin, 0);\n else if (begin > length) begin = length;\n if (end < 0) end = length + end; // no need to clamp\n else if (end > length) end = length;\n if (end < begin) end = begin; // ^\n var newLength = end - begin;\n assert(newLength >= 0);\n var sliced = new Array(newLength);\n if (newLength) {\n memory.copy(\n changetype(sliced.buffer_) + HEADER_SIZE,\n changetype(this.buffer_) + HEADER_SIZE + (begin << alignof()),\n newLength << alignof()\n );\n }\n return sliced;\n }\n\n splice(start: i32, deleteCount: i32 = i32.MAX_VALUE): void {\n if (deleteCount < 1) return;\n var length = this.length_;\n if (start < 0) start = max(length + start, 0);\n if (start >= length) return;\n deleteCount = min(deleteCount, length - start);\n var buffer = this.buffer_;\n memory.copy(\n changetype(buffer) + HEADER_SIZE + (start << alignof()),\n changetype(buffer) + HEADER_SIZE + ((start + deleteCount) << alignof()),\n deleteCount << alignof()\n );\n this.length_ = length - deleteCount;\n }\n\n reverse(): Array {\n var buffer = this.buffer_;\n for (let front = 0, back = this.length_ - 1; front < back; ++front, --back) {\n let temp = loadUnsafe(buffer, front);\n storeUnsafe(buffer, front, loadUnsafe(buffer, back));\n storeUnsafe(buffer, back, temp);\n }\n return this;\n }\n\n sort(comparator: (a: T, b: T) => i32 = defaultComparator()): this {\n // TODO remove this when flow will allow trackcing null\n assert(comparator); // The comparison function must be a function\n\n var length = this.length_;\n if (length <= 1) return this;\n var buffer = this.buffer_;\n if (length == 2) {\n let a = loadUnsafe(buffer, 1); // a = arr[1]\n let b = loadUnsafe(buffer, 0); // b = arr[0]\n if (comparator(a, b) < 0) {\n storeUnsafe(buffer, 1, b); // arr[1] = b;\n storeUnsafe(buffer, 0, a); // arr[0] = a;\n }\n return this;\n }\n\n if (isReference()) {\n // TODO replace this to faster stable sort (TimSort) when it implemented\n insertionSort(buffer, 0, length, comparator);\n return this;\n } else {\n if (length < 256) {\n insertionSort(buffer, 0, length, comparator);\n } else {\n weakHeapSort(buffer, 0, length, comparator);\n }\n return this;\n }\n }\n\n join(separator: string = ","): string {\n var lastIndex = this.length_ - 1;\n if (lastIndex < 0) return "";\n var result = "";\n var value: T;\n var buffer = this.buffer_;\n var sepLen = separator.length;\n var hasSeparator = sepLen != 0;\n if (value instanceof bool) {\n if (!lastIndex) {\n return select("true", "false", loadUnsafe(buffer, 0));\n }\n let valueLen = 5; // max possible length of element len("false")\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = allocateUnsafeString(estLen);\n let offset = 0;\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n valueLen = 4 + (!value);\n copyUnsafeString(result, offset, select("true", "false", value), 0, valueLen);\n offset += valueLen;\n if (hasSeparator) {\n copyUnsafeString(result, offset, changetype(separator), 0, sepLen);\n offset += sepLen;\n }\n }\n value = loadUnsafe(buffer, lastIndex);\n valueLen = 4 + (!value);\n copyUnsafeString(result, offset, select("true", "false", value), 0, valueLen);\n offset += valueLen;\n\n let out = result;\n if (estLen > offset) {\n out = result.substring(0, offset);\n freeUnsafeString(result);\n }\n return out;\n } else if (isInteger()) {\n if (!lastIndex) {\n return changetype(itoa(loadUnsafe(buffer, 0)));\n }\n const valueLen = (sizeof() <= 4 ? 10 : 20) + isSigned();\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = allocateUnsafeString(estLen);\n let offset = 0;\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n offset += itoa_stream(changetype(result), offset, value);\n if (hasSeparator) {\n copyUnsafeString(result, offset, separator, 0, sepLen);\n offset += sepLen;\n }\n }\n value = loadUnsafe(buffer, lastIndex);\n offset += itoa_stream(changetype(result), offset, value);\n let out = result;\n if (estLen > offset) {\n out = result.substring(0, offset);\n freeUnsafeString(result);\n }\n return out;\n } else if (isFloat()) {\n if (!lastIndex) {\n return changetype(dtoa(loadUnsafe(buffer, 0)));\n }\n const valueLen = MAX_DOUBLE_LENGTH;\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = allocateUnsafeString(estLen);\n let offset = 0;\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n offset += dtoa_stream(changetype(result), offset, value);\n if (hasSeparator) {\n copyUnsafeString(result, offset, separator, 0, sepLen);\n offset += sepLen;\n }\n }\n value = loadUnsafe(buffer, lastIndex);\n offset += dtoa_stream(changetype(result), offset, value);\n let out = result;\n if (estLen > offset) {\n out = result.substring(0, offset);\n freeUnsafeString(result);\n }\n return out;\n } else if (isString()) {\n if (!lastIndex) {\n return loadUnsafe(buffer, 0);\n }\n let estLen = 0;\n for (let i = 0, len = lastIndex + 1; i < len; ++i) {\n estLen += loadUnsafe(buffer, i).length;\n }\n let offset = 0;\n let result = allocateUnsafeString(estLen + sepLen * lastIndex);\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n if (value) {\n let valueLen = value.length; // tslint:disable-line:no-unsafe-any\n copyUnsafeString(result, offset, value, 0, valueLen); // tslint:disable-line:no-unsafe-any\n offset += valueLen; // tslint:disable-line:no-unsafe-any\n }\n if (hasSeparator) {\n copyUnsafeString(result, offset, separator, 0, sepLen);\n offset += sepLen;\n }\n }\n value = loadUnsafe(buffer, lastIndex);\n if (value) {\n let valueLen = value.length; // tslint:disable-line:no-unsafe-any\n copyUnsafeString(result, offset, value, 0, valueLen); // tslint:disable-line:no-unsafe-any\n }\n return result;\n } else if (isArray()) {\n if (!lastIndex) {\n value = loadUnsafe(buffer, 0);\n return value ? value.join(separator) : ""; // tslint:disable-line:no-unsafe-any\n }\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n if (value) result += value.join(separator); // tslint:disable-line:no-unsafe-any\n if (hasSeparator) result += separator;\n }\n value = loadUnsafe(buffer, lastIndex);\n if (value) result += value.join(separator); // tslint:disable-line:no-unsafe-any\n return result;\n } else if (isReference()) { // References\n if (!lastIndex) return "[object Object]";\n const valueLen = 15; // max possible length of element len("[object Object]")\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = allocateUnsafeString(estLen);\n let offset = 0;\n for (let i = 0; i < lastIndex; ++i) {\n value = loadUnsafe(buffer, i);\n if (value) {\n copyUnsafeString(result, offset, changetype("[object Object]"), 0, valueLen);\n offset += valueLen;\n }\n if (hasSeparator) {\n copyUnsafeString(result, offset, changetype(separator), 0, sepLen);\n offset += sepLen;\n }\n }\n if (loadUnsafe(buffer, lastIndex)) {\n copyUnsafeString(result, offset, changetype("[object Object]"), 0, valueLen);\n offset += valueLen;\n }\n let out = result;\n if (estLen > offset) {\n out = result.substring(0, offset);\n freeUnsafeString(result);\n }\n return out;\n } else {\n assert(false); // Unsupported generic typename\n }\n }\n\n @inline\n toString(): string {\n return this.join();\n }\n\n private __gc(): void {\n var buffer = this.buffer_;\n __gc_mark(changetype(buffer)); // tslint:disable-line\n if (isManaged()) {\n let offset: usize = 0;\n let end = this.length_ << alignof();\n while (offset < end) {\n __gc_mark(load(changetype(buffer) + offset, HEADER_SIZE)); // tslint:disable-line\n offset += sizeof();\n }\n }\n }\n}\n',arraybuffer:'import {\n HEADER_SIZE,\n MAX_BLENGTH,\n allocateUnsafe\n} from "./internal/arraybuffer";\n\n@sealed\nexport class ArrayBuffer {\n\n readonly byteLength: i32; // capped to [0, MAX_LENGTH]\n\n // @unsafe\n get data(): usize { return changetype(this) + HEADER_SIZE; }\n\n constructor(length: i32, unsafe: bool = false) {\n if (length > MAX_BLENGTH) throw new RangeError("Invalid array buffer length");\n var buffer = allocateUnsafe(length);\n if (!unsafe) memory.fill(changetype(buffer) + HEADER_SIZE, 0, length);\n return buffer;\n }\n\n slice(begin: i32 = 0, end: i32 = MAX_BLENGTH): ArrayBuffer {\n var len = this.byteLength;\n if (begin < 0) begin = max(len + begin, 0);\n else begin = min(begin, len);\n if (end < 0) end = max(len + end, 0);\n else end = min(end, len);\n var newLen = max(end - begin, 0);\n var buffer = allocateUnsafe(newLen);\n memory.copy(changetype(buffer) + HEADER_SIZE, changetype(this) + HEADER_SIZE + begin, newLen);\n return buffer;\n }\n}\n',"bindings/Math":"export declare const E: f64;\nexport declare const LN2: f64;\nexport declare const LN10: f64;\nexport declare const LOG2E: f64;\nexport declare const LOG10E: f64;\nexport declare const PI: f64;\nexport declare const SQRT1_2: f64;\nexport declare const SQRT2: f64;\n\nexport declare function abs(x: f64): f64;\nexport declare function acos(x: f64): f64;\nexport declare function acosh(x: f64): f64;\nexport declare function asin(x: f64): f64;\nexport declare function asinh(x: f64): f64;\nexport declare function atan(x: f64): f64;\nexport declare function atan2(y: f64, x: f64): f64;\nexport declare function atanh(x: f64): f64;\nexport declare function cbrt(x: f64): f64;\nexport declare function ceil(x: f64): f64;\nexport declare function clz32(x: f64): f64;\nexport declare function cos(x: f64): f64;\nexport declare function cosh(x: f64): f64;\nexport declare function exp(x: f64): f64;\nexport declare function expm1(x: f64): f64;\nexport declare function floor(x: f64): f64;\nexport declare function fround(x: f64): f32;\nexport declare function hypot(value1: f64, value2: f64): f64; // TODO: rest\nexport declare function imul(a: f64, b: f64): f64;\nexport declare function log(x: f64): f64;\nexport declare function log10(x: f64): f64;\nexport declare function log1p(x: f64): f64;\nexport declare function log2(x: f64): f64;\nexport declare function max(value1: f64, value2: f64): f64; // TODO: rest\nexport declare function min(value1: f64, value2: f64): f64; // TODO: rest\nexport declare function pow(base: f64, exponent: f64): f64;\nexport declare function random(): f64;\nexport declare function round(x: f64): f64;\nexport declare function sign(x: f64): f64;\nexport declare function sin(x: f64): f64;\nexport declare function sinh(x: f64): f64;\nexport declare function sqrt(x: f64): f64;\nexport declare function tan(x: f64): f64;\nexport declare function tanh(x: f64): f64;\nexport declare function trunc(x: f64): f64;\n",builtins:"/* tslint:disable */\n\n@builtin @inline export const NaN: f64 = 0 / 0;\n@builtin @inline export const Infinity: f64 = 1 / 0;\n\n@builtin export declare function isInteger(value?: T): bool;\n@builtin export declare function isFloat(value?: T): bool;\n@builtin export declare function isSigned(value?: T): bool;\n@builtin export declare function isReference(value?: T): bool;\n@builtin export declare function isString(value?: T): bool;\n@builtin export declare function isArray(value?: T): bool;\n@builtin export declare function isDefined(expression: void): bool;\n@builtin export declare function isConstant(expression: void): bool;\n@builtin export declare function isManaged(value?: T): bool;\n@inline export function isNaN(value: T): bool { return value != value; }\n@inline export function isFinite(value: T): bool { return value - value == 0; }\n\n@builtin export declare function clz(value: T): T;\n@builtin export declare function ctz(value: T): T;\n@builtin export declare function popcnt(value: T): T;\n@builtin export declare function rotl(value: T, shift: T): T;\n@builtin export declare function rotr(value: T, shift: T): T;\n@builtin export declare function abs(value: T): T;\n@builtin export declare function max(left: T, right: T): T;\n@builtin export declare function min(left: T, right: T): T;\n@builtin export declare function ceil(value: T): T;\n@builtin export declare function floor(value: T): T;\n@builtin export declare function copysign(left: T, right: T): T;\n@builtin export declare function nearest(value: T): T;\n@builtin export declare function reinterpret(value: void): T;\n@builtin export declare function sqrt(value: T): T;\n@builtin export declare function trunc(value: T): T;\n@builtin export declare function load(offset: usize, constantOffset?: usize): T;\n@builtin export declare function store(offset: usize, value: void, constantOffset?: usize): void;\n@builtin export declare function sizeof(): usize; // | u32 / u64\n@builtin export declare function alignof(): usize; // | u32 / u64\n@builtin export declare function offsetof(fieldName?: string): usize; // | u32 / u64\n@builtin export declare function select(ifTrue: T, ifFalse: T, condition: bool): T;\n@builtin export declare function unreachable(): void;\n@builtin export declare function changetype(value: void): T;\n@builtin export declare function assert(isTrueish: T, message?: string): T;\n@builtin export declare function unchecked(expr: T): T;\n@builtin export declare function call_indirect(target: void, ...args: void[]): T;\n\n@builtin export declare function i8(value: void): i8;\nexport namespace i8 {\n export const MIN_VALUE: i8 = -128;\n export const MAX_VALUE: i8 = 127;\n}\n\n@builtin export declare function i16(value: void): i16;\nexport namespace i16 {\n export const MIN_VALUE: i16 = -32768;\n export const MAX_VALUE: i16 = 32767;\n}\n\n@builtin export declare function i32(value: void): i32;\nexport namespace i32 {\n export const MIN_VALUE: i32 = -2147483648;\n export const MAX_VALUE: i32 = 2147483647;\n @builtin export declare function clz(value: i32): i32;\n @builtin export declare function ctz(value: i32): i32;\n @builtin export declare function popcnt(value: i32): i32;\n @builtin export declare function rotl(value: i32, shift: i32): i32;\n @builtin export declare function rotr(value: i32, shift: i32): i32;\n @builtin export declare function reinterpret_f32(value: f32): i32;\n @builtin export declare function load8_s(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function load8_u(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function load16_s(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function load16_u(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function load(offset: usize, constantOffset?: usize): i32;\n @builtin export declare function store8(offset: usize, value: i32, constantOffset?: usize): void;\n @builtin export declare function store16(offset: usize, value: i32, constantOffset?: usize): void;\n @builtin export declare function store(offset: usize, value: i32, constantOffset?: usize): void;\n}\n\n@builtin export declare function i64(value: void): i64;\nexport namespace i64 {\n export const MIN_VALUE: i64 = -9223372036854775808;\n export const MAX_VALUE: i64 = 9223372036854775807;\n @builtin export declare function clz(value: i64): i64;\n @builtin export declare function ctz(value: i64): i64;\n @builtin export declare function load8_s(offset: usize, constantOffset?: usize): i64;\n @builtin export declare function load8_u(offset: usize, constantOffset?: usize): u64;\n @builtin export declare function load16_s(offset: usize, constantOffset?: usize): i64;\n @builtin export declare function load16_u(offset: usize, constantOffset?: usize): u64;\n @builtin export declare function load32_s(offset: usize, constantOffset?: usize): i64;\n @builtin export declare function load32_u(offset: usize, constantOffset?: usize): u64;\n @builtin export declare function load(offset: usize, constantOffset?: usize): i64;\n @builtin export declare function popcnt(value: i64): i64;\n @builtin export declare function rotl(value: i64, shift: i64): i64;\n @builtin export declare function rotr(value: i64, shift: i64): i64;\n @builtin export declare function reinterpret_f64(value: f64): i64;\n @builtin export declare function store8(offset: usize, value: i64, constantOffset?: usize): void;\n @builtin export declare function store16(offset: usize, value: i64, constantOffset?: usize): void;\n @builtin export declare function store32(offset: usize, value: i64, constantOffset?: usize): void;\n @builtin export declare function store(offset: usize, value: i64, constantOffset?: usize): void;\n}\n\n@builtin export declare function isize(value: void): isize;\nexport namespace isize {\n export const MIN_VALUE: isize = sizeof() == sizeof()\n ? -2147483648\n : -9223372036854775808;\n export const MAX_VALUE: isize = sizeof() == sizeof()\n ? 2147483647\n : 9223372036854775807;\n}\n\n@builtin export declare function u8(value: void): u8;\nexport namespace u8 {\n export const MIN_VALUE: u8 = 0;\n export const MAX_VALUE: u8 = 255;\n}\n\n@builtin export declare function u16(value: void): u16;\nexport namespace u16 {\n export const MIN_VALUE: u16 = 0;\n export const MAX_VALUE: u16 = 65535;\n}\n\n@builtin export declare function u32(value: void): u32;\nexport namespace u32 {\n export const MIN_VALUE: u32 = 0;\n export const MAX_VALUE: u32 = 4294967295;\n}\n\n@builtin export declare function u64(value: void): u64;\nexport namespace u64 {\n export const MIN_VALUE: u64 = 0;\n export const MAX_VALUE: u64 = 18446744073709551615;\n}\n\n@builtin export declare function usize(value: void): usize;\nexport namespace usize {\n export const MIN_VALUE: usize = 0;\n export const MAX_VALUE: usize = sizeof() == sizeof()\n ? 4294967295\n : 18446744073709551615;\n}\n\n@builtin export declare function bool(value: void): bool;\nexport namespace bool {\n export const MIN_VALUE: bool = false;\n export const MAX_VALUE: bool = true;\n}\n\n@builtin export declare function f32(value: void): f32;\nexport namespace f32 {\n export const EPSILON = reinterpret(0x34000000); // 0x1p-23f\n export const MIN_VALUE = reinterpret(0x00000001); // 0x0.000001p+0f\n export const MAX_VALUE = reinterpret(0x7F7FFFFF); // 0x1.fffffep+127f\n export const MIN_NORMAL_VALUE = reinterpret(0x00800000); // 0x1p-126f\n export const MIN_SAFE_INTEGER: f32 = -16777215;\n export const MAX_SAFE_INTEGER: f32 = 16777215;\n export const POSITIVE_INFINITY: f32 = Infinity;\n export const NEGATIVE_INFINITY: f32 = -Infinity;\n export const NaN: f32 = NaN;\n @builtin export declare function abs(value: f32): f32;\n @builtin export declare function ceil(value: f32): f32;\n @builtin export declare function copysign(x: f32, y: f32): f32;\n @builtin export declare function floor(value: f32): f32;\n @builtin export declare function load(offset: usize, constantOffset?: usize): f32;\n @builtin export declare function max(left: f32, right: f32): f32;\n @builtin export declare function min(left: f32, right: f32): f32;\n @builtin export declare function nearest(value: f32): f32;\n @builtin export declare function reinterpret_i32(value: i32): f32;\n @builtin export declare function sqrt(value: f32): f32;\n @builtin export declare function store(offset: usize, value: f32, constantOffset?: usize): void;\n @builtin export declare function trunc(value: f32): f32;\n}\n\n@builtin export declare function f64(value: void): f64;\nexport namespace f64 {\n export const EPSILON = reinterpret(0x3CB0000000000000); // 0x1p-52\n export const MIN_VALUE = reinterpret(0x0000000000000001); // 0x0.0000000000001p+0\n export const MAX_VALUE = reinterpret(0x7FEFFFFFFFFFFFFF); // 0x1.fffffffffffffp+1023\n export const MIN_NORMAL_VALUE = reinterpret(0x0010000000000000); // 0x1p-1022\n export const MIN_SAFE_INTEGER: f64 = -9007199254740991;\n export const MAX_SAFE_INTEGER: f64 = 9007199254740991;\n export const POSITIVE_INFINITY: f64 = Infinity;\n export const NEGATIVE_INFINITY: f64 = -Infinity;\n export const NaN: f64 = NaN;\n @builtin export declare function abs(value: f64): f64;\n @builtin export declare function ceil(value: f64): f64;\n @builtin export declare function copysign(x: f64, y: f64): f64;\n @builtin export declare function floor(value: f64): f64;\n @builtin export declare function load(offset: usize, constantOffset?: usize): f64;\n @builtin export declare function max(left: f64, right: f64): f64;\n @builtin export declare function min(left: f64, right: f64): f64;\n @builtin export declare function nearest(value: f64): f64;\n @builtin export declare function reinterpret_i64(value: i64): f64;\n @builtin export declare function sqrt(value: f64): f64;\n @builtin export declare function store(offset: usize, value: f64, constantOffset?: usize): void;\n @builtin export declare function trunc(value: f64): f64;\n}\n\n@builtin export declare function start(): void;\n","collector/itcm":'/**\n * Incremental Tri-Color-Marking Garbage Collector.\n *\n * @module std/assembly/collector/itcm\n *//***/\n\n// Largely based on Bach Le\'s μgc, see: https://github.com/bullno1/ugc\n\nconst TRACE = false;\n\n/** Size of a managed object header. */\nexport const HEADER_SIZE: usize = (offsetof() + AL_MASK) & ~AL_MASK;\n\nimport { AL_MASK, MAX_SIZE_32 } from "../internal/allocator";\nimport { iterateRoots } from "../gc";\n\n/** Collector states. */\nconst enum State {\n /** Not yet initialized. */\n INIT = 0,\n /** Currently transitioning from SWEEP to MARK state. */\n IDLE = 1,\n /** Currently marking reachable objects. */\n MARK = 2,\n /** Currently sweeping unreachable objects. */\n SWEEP = 3\n}\n\n/** Current collector state. */\nvar state = State.INIT;\n/** Current white color value. */\nvar white = 0;\n\n// From and to spaces\nvar fromSpace: ManagedObjectList;\nvar toSpace: ManagedObjectList;\nvar iter: ManagedObject;\n\n// ╒═══════════════ Managed object layout (32-bit) ════════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┼─┼─┴─┤ ┐\n// │ next │0│ C │ ◄─┐ = nextWithColor\n// ├─────────────────────────────────────────────────────────┴─┴───┤ │ usize\n// │ prev │ ◄─┘\n// ├───────────────────────────────────────────────────────────────┤\n// │ hookFn │\n// ╞═══════════════════════════════════════════════════════════════╡ SIZE ┘ ◄─ user-space reference\n// │ ... data ... │\n// └───────────────────────────────────────────────────────────────┘\n// C: color\n\n/** Represents a managed object in memory, consisting of a header followed by the object\'s data. */\n@unmanaged class ManagedObject {\n\n /** Pointer to the next object with color flags stored in the alignment bits. */\n nextWithColor: usize;\n\n /** Pointer to the previous object. */\n prev: ManagedObject;\n\n /** Class-specific hook function called with the user-space reference. */\n hookFn: (ref: usize) => void;\n\n /** Gets the pointer to the next object. */\n get next(): ManagedObject {\n return changetype(this.nextWithColor & ~3);\n }\n\n /** Sets the pointer to the next object. */\n set next(obj: ManagedObject) {\n this.nextWithColor = changetype(obj) | (this.nextWithColor & 3);\n }\n\n /** Gets this object\'s color. */\n get color(): i32 {\n return this.nextWithColor & 3;\n }\n\n /** Sets this object\'s color. */\n set color(color: i32) {\n this.nextWithColor = (this.nextWithColor & ~3) | color;\n }\n\n /** Unlinks this object from its list. */\n unlink(): void {\n var next = this.next;\n var prev = this.prev;\n if (TRACE) trace(" unlink", 3, objToRef(prev), objToRef(this), objToRef(next));\n next.prev = prev;\n prev.next = next;\n }\n\n /** Marks this object as gray, that is reachable with unscanned children. */\n makeGray(): void {\n if (TRACE) trace(" makeGray", 1, objToRef(this));\n const gray = 2;\n if (this == iter) iter = this.prev;\n this.unlink();\n toSpace.push(this);\n this.nextWithColor = (this.nextWithColor & ~3) | gray;\n }\n}\n\n/** A list of managed objects. Used for the from and to spaces. */\n@unmanaged class ManagedObjectList extends ManagedObject {\n\n /** Inserts an object. */\n push(obj: ManagedObject): void {\n var prev = this.prev;\n if (TRACE) trace(" push", 3, objToRef(prev), objToRef(obj), objToRef(this));\n obj.next = this;\n obj.prev = prev;\n prev.next = obj;\n this.prev = obj;\n }\n\n /** Clears this list. */\n clear(): void {\n if (TRACE) trace(" clear", 1, objToRef(this));\n this.nextWithColor = changetype(this);\n this.prev = this;\n }\n}\n\n/** Performs a single step according to the current state. */\nfunction step(): void {\n var obj: ManagedObject;\n switch (state) {\n case State.INIT: {\n if (TRACE) trace("gc~step/INIT");\n fromSpace = changetype(memory.allocate(HEADER_SIZE));\n fromSpace.hookFn = changetype<(ref: usize) => void>(-1); // would error\n fromSpace.clear();\n toSpace = changetype(memory.allocate(HEADER_SIZE));\n toSpace.hookFn = changetype<(ref: usize) => void>(-1); // would error\n toSpace.clear();\n iter = toSpace;\n state = State.IDLE;\n if (TRACE) trace("gc~state = IDLE");\n // fall-through\n }\n case State.IDLE: {\n if (TRACE) trace("gc~step/IDLE");\n iterateRoots(__gc_mark);\n state = State.MARK;\n if (TRACE) trace("gc~state = MARK");\n break;\n }\n case State.MARK: {\n obj = iter.next;\n if (obj !== toSpace) {\n if (TRACE) trace("gc~step/MARK iterate", 1, objToRef(obj));\n iter = obj;\n obj.color = !white;\n // if (TRACE) {\n // trace(" next/prev/hook", 3,\n // changetype(obj.next),\n // changetype(obj.prev),\n // changetype(obj.hookFn)\n // );\n // }\n obj.hookFn(objToRef(obj));\n } else {\n if (TRACE) trace("gc~step/MARK finish");\n iterateRoots(__gc_mark);\n obj = iter.next;\n if (obj === toSpace) {\n let from = fromSpace;\n fromSpace = toSpace;\n toSpace = from;\n white = !white;\n iter = from.next;\n state = State.SWEEP;\n if (TRACE) trace("gc~state = SWEEP");\n }\n }\n break;\n }\n case State.SWEEP: {\n obj = iter;\n if (obj !== toSpace) {\n if (TRACE) trace("gc~step/SWEEP free", 1, objToRef(obj));\n iter = obj.next;\n if (changetype(obj) >= HEAP_BASE) memory.free(changetype(obj));\n } else {\n if (TRACE) trace("gc~step/SWEEP finish");\n toSpace.clear();\n state = State.IDLE;\n if (TRACE) trace("gc~state = IDLE");\n }\n break;\n }\n }\n}\n\n@inline function refToObj(ref: usize): ManagedObject {\n return changetype(ref - HEADER_SIZE);\n}\n\n@inline function objToRef(obj: ManagedObject): usize {\n return changetype(obj) + HEADER_SIZE;\n}\n\n// Garbage collector interface\n\n@global export function __gc_allocate(\n size: usize,\n markFn: (ref: usize) => void\n): usize {\n if (TRACE) trace("gc.allocate", 1, size);\n if (size > MAX_SIZE_32 - HEADER_SIZE) unreachable();\n step(); // also makes sure it\'s initialized\n var obj = changetype(memory.allocate(HEADER_SIZE + size));\n obj.hookFn = markFn;\n obj.color = white;\n fromSpace.push(obj);\n return objToRef(obj);\n}\n\n@global export function __gc_link(parentRef: usize, childRef: usize): void {\n if (TRACE) trace("gc.link", 2, parentRef, childRef);\n var parent = refToObj(parentRef);\n if (parent.color == !white && refToObj(childRef).color == white) parent.makeGray();\n}\n\n@global export function __gc_mark(ref: usize): void {\n if (TRACE) trace("gc.mark", 1, ref);\n if (ref) {\n let obj = refToObj(ref);\n if (obj.color == white) obj.makeGray();\n }\n}\n\n@global export function __gc_collect(): void {\n if (TRACE) trace("gc.collect");\n // begin collecting if not yet collecting\n switch (state) {\n case State.INIT:\n case State.IDLE: step();\n }\n // finish the cycle\n while (state != State.IDLE) step();\n}\n',diagnostics:"/* tslint:disable */\n\n@builtin export declare function ERROR(message?: void): void;\n@builtin export declare function WARNING(message?: void): void;\n@builtin export declare function INFO(message?: void): void;\n",env:"declare function abort(\n message?: string | null,\n fileName?: string | null,\n lineNumber?: u32,\n columnNumber?: u32\n): void;\n\ndeclare function trace(\n message: string,\n n?: i32,\n a0?: f64,\n a1?: f64,\n a2?: f64,\n a3?: f64,\n a4?: f64\n): void;\n",error:'export class Error {\n\n message: string;\n stack: string = ""; // TODO\n\n constructor(message: string = "") {\n this.message = message;\n }\n}\n\nexport class RangeError extends Error {}\nexport class TypeError extends Error {}\n',gc:"/* tslint:disable */\n\n@builtin export declare function iterateRoots(fn: (ref: usize) => void): void;\n\nexport namespace gc {\n\n export function collect(): void {\n if (isDefined(__gc_collect)) { __gc_collect(); return; }\n WARNING(\"Calling 'gc.collect' requires a garbage collector to be present.\");\n unreachable();\n }\n}\n","internal/allocator":"/** Number of alignment bits. */\nexport const AL_BITS: u32 = 3;\n/** Number of possible alignment values. */\nexport const AL_SIZE: usize = 1 << AL_BITS;\n/** Mask to obtain just the alignment bits. */\nexport const AL_MASK: usize = AL_SIZE - 1;\n/** Maximum 32-bit allocation size. */\nexport const MAX_SIZE_32: usize = 1 << 30; // 1GB\n","internal/array":"import {\n loadUnsafeWithOffset,\n storeUnsafeWithOffset\n} from \"./arraybuffer\";\n\nimport {\n compareUnsafe,\n} from \"./string\";\n\n/** Obtains the default comparator for the specified type. */\n@inline\nexport function defaultComparator(): (a: T, b: T) => i32 {\n if (isInteger()) {\n if (isSigned() && sizeof() <= 4) {\n return (a: T, b: T): i32 => ((a - b));\n } else {\n return (a: T, b: T): i32 => ((a > b) - (a < b));\n }\n } else if (isFloat()) {\n if (sizeof() == 4) {\n return (a: T, b: T): i32 => {\n var ia = reinterpret(a);\n var ib = reinterpret(b);\n ia ^= (ia >> 31) >>> 1;\n ib ^= (ib >> 31) >>> 1;\n return (ia > ib) - (ia < ib);\n };\n } else {\n return (a: T, b: T): i32 => {\n var ia = reinterpret(a);\n var ib = reinterpret(b);\n ia ^= (ia >> 63) >>> 1;\n ib ^= (ib >> 63) >>> 1;\n return (ia > ib) - (ia < ib);\n };\n }\n } else if (isString()) {\n return (a: T, b: T): i32 => {\n var sa = a, sb = b;\n return compareUnsafe(sa, 0, sb, 0, min(sa.length, sb.length));\n };\n } else {\n return (a: T, b: T): i32 => ((a > b) - (a < b));\n }\n}\n\n/** Sorts an Array with the 'Insertion Sort' algorithm. */\nexport function insertionSort(\n buffer: ArrayBuffer,\n byteOffset: i32,\n length: i32,\n comparator: (a: T, b: T) => i32\n): void {\n for (let i = 0; i < length; i++) {\n let a = loadUnsafeWithOffset(buffer, i, byteOffset); // a = arr[i]\n let j = i - 1;\n while (j >= 0) {\n let b = loadUnsafeWithOffset(buffer, j, byteOffset); // b = arr[j]\n if (comparator(a, b) < 0) {\n storeUnsafeWithOffset(buffer, j-- + 1, b, byteOffset); // arr[j + 1] = b\n } else break;\n }\n storeUnsafeWithOffset(buffer, j + 1, a, byteOffset); // arr[j + 1] = a\n }\n}\n\n/** Sorts an Array with the 'Weak Heap Sort' algorithm. */\nexport function weakHeapSort(\n buffer: ArrayBuffer,\n byteOffset: i32,\n length: i32,\n comparator: (a: T, b: T) => i32\n): void {\n const shift32 = alignof();\n\n var bitsetSize = (length + 31) >> 5 << shift32;\n var bitset = memory.allocate(bitsetSize); // indexed in 32-bit chunks below\n memory.fill(bitset, 0, bitsetSize);\n\n // see: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.21.1863&rep=rep1&type=pdf\n\n for (let i = length - 1; i > 0; i--) {\n let j = i;\n while ((j & 1) == (load(bitset + (j >> 6 << shift32)) >> (j >> 1 & 31) & 1)) j >>= 1;\n\n let p = j >> 1;\n let a = loadUnsafeWithOffset(buffer, p, byteOffset); // a = arr[p]\n let b = loadUnsafeWithOffset(buffer, i, byteOffset); // b = arr[i]\n if (comparator(a, b) < 0) {\n store(\n bitset + (i >> 5 << shift32),\n load(bitset + (i >> 5 << shift32)) ^ (1 << (i & 31))\n );\n storeUnsafeWithOffset(buffer, i, a, byteOffset); // arr[i] = a\n storeUnsafeWithOffset(buffer, p, b, byteOffset); // arr[p] = b\n }\n }\n\n for (let i = length - 1; i >= 2; i--) {\n let a = loadUnsafeWithOffset(buffer, 0, byteOffset);\n storeUnsafeWithOffset(buffer, 0, loadUnsafeWithOffset(buffer, i, byteOffset), byteOffset);\n storeUnsafeWithOffset(buffer, i, a, byteOffset);\n\n let x = 1, y: i32;\n while ((y = (x << 1) + ((load(bitset + (x >> 5 << shift32)) >> (x & 31)) & 1)) < i) x = y;\n\n while (x > 0) {\n a = loadUnsafeWithOffset(buffer, 0, byteOffset); // a = arr[0]\n let b = loadUnsafeWithOffset(buffer, x, byteOffset); // b = arr[x]\n\n if (comparator(a, b) < 0) {\n store(\n bitset + (x >> 5 << shift32),\n load(bitset + (x >> 5 << shift32)) ^ (1 << (x & 31))\n );\n storeUnsafeWithOffset(buffer, x, a, byteOffset); // arr[x] = a\n storeUnsafeWithOffset(buffer, 0, b, byteOffset); // arr[0] = b\n }\n x >>= 1;\n }\n }\n\n memory.free(bitset);\n\n var t = loadUnsafeWithOffset(buffer, 1, byteOffset); // t = arr[1]\n storeUnsafeWithOffset(buffer, 1, loadUnsafeWithOffset(buffer, 0, byteOffset), byteOffset);\n storeUnsafeWithOffset(buffer, 0, t, byteOffset); // arr[0] = t\n}\n","internal/arraybuffer":'import { AL_MASK, MAX_SIZE_32 } from "./allocator";\n\n/** Size of an ArrayBuffer header. */\nexport const HEADER_SIZE: usize = (offsetof() + AL_MASK) & ~AL_MASK;\n/** Maximum byte length of an ArrayBuffer. */\nexport const MAX_BLENGTH: i32 = MAX_SIZE_32 - HEADER_SIZE;\n\nfunction computeSize(byteLength: i32): usize {\n // round up to power of 2, with HEADER_SIZE=8:\n // 0 -> 2^3 = 8\n // 1..8 -> 2^4 = 16\n // 9..24 -> 2^5 = 32\n // ...\n // MAX_LENGTH -> 2^30 = 0x40000000 (MAX_SIZE_32)\n return 1 << (32 - clz(byteLength + HEADER_SIZE - 1));\n}\n\n// Low-level utility\n\nfunction __gc(ref: usize): void {}\n\nexport function allocateUnsafe(byteLength: i32): ArrayBuffer {\n assert(byteLength <= MAX_BLENGTH);\n var buffer: usize;\n if (isManaged()) {\n buffer = __gc_allocate(computeSize(byteLength), __gc); // tslint:disable-line\n } else {\n buffer = memory.allocate(computeSize(byteLength));\n }\n store(buffer, byteLength, offsetof("byteLength"));\n return changetype(buffer);\n}\n\nexport function reallocateUnsafe(buffer: ArrayBuffer, newByteLength: i32): ArrayBuffer {\n var oldByteLength = buffer.byteLength;\n if (newByteLength > oldByteLength) {\n assert(newByteLength <= MAX_BLENGTH);\n if (newByteLength <= (computeSize(oldByteLength) - HEADER_SIZE)) { // fast path: zero out additional space\n store(changetype(buffer), newByteLength, offsetof("byteLength"));\n memory.fill(\n changetype(buffer) + HEADER_SIZE + oldByteLength,\n 0,\n (newByteLength - oldByteLength)\n );\n } else { // slow path: copy to new buffer\n let newBuffer = allocateUnsafe(newByteLength);\n memory.copy(\n changetype(newBuffer) + HEADER_SIZE,\n changetype(buffer) + HEADER_SIZE,\n oldByteLength\n );\n memory.fill(\n changetype(newBuffer) + HEADER_SIZE + oldByteLength,\n 0,\n (newByteLength - oldByteLength)\n );\n return newBuffer;\n }\n } else if (newByteLength < oldByteLength) { // fast path: override size\n // TBD: worth to copy and release if size is significantly less than before?\n assert(newByteLength >= 0);\n store(changetype(buffer), newByteLength, offsetof("byteLength"));\n }\n return buffer;\n}\n\n@inline export function loadUnsafe(buffer: ArrayBuffer, index: i32): V {\n return load(changetype(buffer) + (index << alignof()), HEADER_SIZE);\n}\n\n@inline export function storeUnsafe(buffer: ArrayBuffer, index: i32, value: V): void {\n store(changetype(buffer) + (index << alignof()), value, HEADER_SIZE);\n}\n\n@inline export function loadUnsafeWithOffset(buffer: ArrayBuffer, index: i32, byteOffset: i32): V {\n return load(changetype(buffer) + byteOffset + (index << alignof()), HEADER_SIZE);\n}\n\n@inline export function storeUnsafeWithOffset(buffer: ArrayBuffer, index: i32, value: V, byteOffset: i32): void {\n store(changetype(buffer) + byteOffset + (index << alignof()), value, HEADER_SIZE);\n}\n',"internal/hash":'import {\n HEADER_SIZE as STRING_HEADER_SIZE\n} from "./string";\n\n/** Computes the 32-bit hash of a value of any type. */\n@inline\nexport function hash(key: T): u32 {\n // branch-level tree-shaking makes this a `(return (call ...))`\n if (isString(key)) {\n return hashStr(key);\n } else if (isReference()) {\n if (sizeof() == 4) return hash32(changetype(key));\n if (sizeof() == 8) return hash64(changetype(key));\n } else if (isFloat()) {\n if (sizeof() == 4) return hash32(reinterpret(key));\n if (sizeof() == 8) return hash64(reinterpret(key));\n } else {\n if (sizeof() == 1) return hash8 (key);\n if (sizeof() == 2) return hash16(key);\n if (sizeof() == 4) return hash32(key);\n if (sizeof() == 8) return hash64(key);\n }\n unreachable();\n}\n\n// FNV-1a 32-bit as a starting point, see: http://isthe.com/chongo/tech/comp/fnv/\n\nconst FNV_OFFSET: u32 = 2166136261;\nconst FNV_PRIME: u32 = 16777619;\n\nfunction hash8(key: u32): u32 {\n return (FNV_OFFSET ^ key) * FNV_PRIME;\n}\n\nfunction hash16(key: u32): u32 {\n var v = FNV_OFFSET;\n v = (v ^ ( key & 0xff)) * FNV_PRIME;\n v = (v ^ ( key >> 8 )) * FNV_PRIME;\n return v;\n}\n\nfunction hash32(key: u32): u32 {\n var v = FNV_OFFSET;\n v = (v ^ ( key & 0xff)) * FNV_PRIME;\n v = (v ^ ((key >> 8) & 0xff)) * FNV_PRIME;\n v = (v ^ ((key >> 16) & 0xff)) * FNV_PRIME;\n v = (v ^ ( key >> 24 )) * FNV_PRIME;\n return v;\n}\n\nfunction hash64(key: u64): u32 {\n var l = key;\n var h = (key >>> 32);\n var v = FNV_OFFSET;\n v = (v ^ ( l & 0xff)) * FNV_PRIME;\n v = (v ^ ((l >> 8) & 0xff)) * FNV_PRIME;\n v = (v ^ ((l >> 16) & 0xff)) * FNV_PRIME;\n v = (v ^ ( l >> 24 )) * FNV_PRIME;\n v = (v ^ ( h & 0xff)) * FNV_PRIME;\n v = (v ^ ((h >> 8) & 0xff)) * FNV_PRIME;\n v = (v ^ ((h >> 16) & 0xff)) * FNV_PRIME;\n v = (v ^ ( h >> 24 )) * FNV_PRIME;\n return v;\n}\n\nfunction hashStr(key: string): u32 {\n var v = FNV_OFFSET;\n for (let i: usize = 0, k: usize = key.length << 1; i < k; ++i) {\n v = (v ^ load(changetype(key) + i, STRING_HEADER_SIZE)) * FNV_PRIME;\n }\n return v;\n}\n',"internal/memory":"// this function will go away once `memory.copy` becomes an intrinsic\nexport function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memcpy.c\n var w: u32, x: u32;\n\n // copy 1 byte each until src is aligned to 4 bytes\n while (n && (src & 3)) {\n store(dest++, load(src++));\n n--;\n }\n\n // if dst is aligned to 4 bytes as well, copy 4 bytes each\n if ((dest & 3) == 0) {\n while (n >= 16) {\n store(dest , load(src ));\n store(dest + 4, load(src + 4));\n store(dest + 8, load(src + 8));\n store(dest + 12, load(src + 12));\n src += 16; dest += 16; n -= 16;\n }\n if (n & 8) {\n store(dest , load(src ));\n store(dest + 4, load(src + 4));\n dest += 8; src += 8;\n }\n if (n & 4) {\n store(dest, load(src));\n dest += 4; src += 4;\n }\n if (n & 2) { // drop to 2 bytes each\n store(dest, load(src));\n dest += 2; src += 2;\n }\n if (n & 1) { // drop to 1 byte\n store(dest++, load(src++));\n }\n return;\n }\n\n // if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each\n // doing shifts if faster when copying enough bytes (here: 32 or more)\n if (n >= 32) {\n switch (dest & 3) {\n // known to be != 0\n case 1: {\n w = load(src);\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n n -= 3;\n while (n >= 17) {\n x = load(src + 1);\n store(dest, w >> 24 | x << 8);\n w = load(src + 5);\n store(dest + 4, x >> 24 | w << 8);\n x = load(src + 9);\n store(dest + 8, w >> 24 | x << 8);\n w = load(src + 13);\n store(dest + 12, x >> 24 | w << 8);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 2: {\n w = load(src);\n store(dest++, load(src++));\n store(dest++, load(src++));\n n -= 2;\n while (n >= 18) {\n x = load(src + 2);\n store(dest, w >> 16 | x << 16);\n w = load(src + 6);\n store(dest + 4, x >> 16 | w << 16);\n x = load(src + 10);\n store(dest + 8, w >> 16 | x << 16);\n w = load(src + 14);\n store(dest + 12, x >> 16 | w << 16);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 3: {\n w = load(src);\n store(dest++, load(src++));\n n -= 1;\n while (n >= 19) {\n x = load(src + 3);\n store(dest, w >> 8 | x << 24);\n w = load(src + 7);\n store(dest + 4, x >> 8 | w << 24);\n x = load(src + 11);\n store(dest + 8, w >> 8 | x << 24);\n w = load(src + 15);\n store(dest + 12, x >> 8 | w << 24);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n }\n }\n\n // copy remaining bytes one by one\n if (n & 16) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 8) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 4) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 2) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 1) {\n store(dest++, load(src++));\n }\n}\n\n// this function will go away once `memory.copy` becomes an intrinsic\nexport function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c\n if (dest == src) return;\n if (src + n <= dest || dest + n <= src) {\n memcpy(dest, src, n);\n return;\n }\n if (dest < src) {\n if ((src & 7) == (dest & 7)) {\n while (dest & 7) {\n if (!n) return;\n --n;\n store(dest++, load(src++));\n }\n while (n >= 8) {\n store(dest, load(src));\n n -= 8;\n dest += 8;\n src += 8;\n }\n }\n while (n) {\n store(dest++, load(src++));\n --n;\n }\n } else {\n if ((src & 7) == (dest & 7)) {\n while ((dest + n) & 7) {\n if (!n) return;\n store(dest + --n, load(src + n));\n }\n while (n >= 8) {\n n -= 8;\n store(dest + n, load(src + n));\n }\n }\n while (n) {\n store(dest + --n, load(src + n));\n }\n }\n}\n\n// this function will go away once `memory.fill` becomes an intrinsic\nexport function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset\n\n // fill head and tail with minimal branching\n if (!n) return;\n store(dest, c);\n store(dest + n - 1, c);\n if (n <= 2) return;\n\n store(dest + 1, c);\n store(dest + 2, c);\n store(dest + n - 2, c);\n store(dest + n - 3, c);\n if (n <= 6) return;\n store(dest + 3, c);\n store(dest + n - 4, c);\n if (n <= 8) return;\n\n // advance pointer to align it at 4-byte boundary\n var k: usize = -dest & 3;\n dest += k;\n n -= k;\n n &= -4;\n\n var c32: u32 = -1 / 255 * c;\n\n // fill head/tail up to 28 bytes each in preparation\n store(dest, c32);\n store(dest + n - 4, c32);\n if (n <= 8) return;\n store(dest + 4, c32);\n store(dest + 8, c32);\n store(dest + n - 12, c32);\n store(dest + n - 8, c32);\n if (n <= 24) return;\n store(dest + 12, c32);\n store(dest + 16, c32);\n store(dest + 20, c32);\n store(dest + 24, c32);\n store(dest + n - 28, c32);\n store(dest + n - 24, c32);\n store(dest + n - 20, c32);\n store(dest + n - 16, c32);\n\n // align to a multiple of 8\n k = 24 + (dest & 4);\n dest += k;\n n -= k;\n\n // copy 32 bytes each\n var c64: u64 = c32 | (c32 << 32);\n while (n >= 32) {\n store(dest, c64);\n store(dest + 8, c64);\n store(dest + 16, c64);\n store(dest + 24, c64);\n n -= 32;\n dest += 32;\n }\n}\n\nexport function memcmp(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c\n if (vl == vr) return 0;\n while (n != 0 && load(vl) == load(vr)) {\n n--; vl++; vr++;\n }\n return n ? load(vl) - load(vr) : 0;\n}\n","internal/number":'\nimport {\n CharCode,\n allocateUnsafe as allocateUnsafeString,\n freeUnsafe as freeUnsafeString,\n HEADER_SIZE as STRING_HEADER_SIZE\n} from "./string";\n\nimport {\n loadUnsafe\n} from "./arraybuffer";\n\nexport const MAX_DOUBLE_LENGTH = 28;\n\n@inline\nexport function POWERS10(): u32[] {\n const table: u32[] = [\n 1,\n 10,\n 100,\n 1000,\n 10000,\n 100000,\n 1000000,\n 10000000,\n 100000000,\n 1000000000\n ];\n return table; // inlines to a constant memory offset\n}\n\n/*\n Lookup table for pairwise char codes in range [0-99]\n\n "00", "01", "02", "03", "04", "05", "06", "07", "08", "09",\n "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",\n "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",\n "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",\n "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",\n "50", "51", "52", "53", "54", "55", "56", "57", "58", "59",\n "60", "61", "62", "63", "64", "65", "66", "67", "68", "69",\n "70", "71", "72", "73", "74", "75", "76", "77", "78", "79",\n "80", "81", "82", "83", "84", "85", "86", "87", "88", "89",\n "90", "91", "92", "93", "94", "95", "96", "97", "98", "99"\n*/\n@inline\nexport function DIGITS(): u32[] {\n const table: u32[] = [\n 0x00300030, 0x00310030, 0x00320030, 0x00330030, 0x00340030,\n 0x00350030, 0x00360030, 0x00370030, 0x00380030, 0x00390030,\n 0x00300031, 0x00310031, 0x00320031, 0x00330031, 0x00340031,\n 0x00350031, 0x00360031, 0x00370031, 0x00380031, 0x00390031,\n 0x00300032, 0x00310032, 0x00320032, 0x00330032, 0x00340032,\n 0x00350032, 0x00360032, 0x00370032, 0x00380032, 0x00390032,\n 0x00300033, 0x00310033, 0x00320033, 0x00330033, 0x00340033,\n 0x00350033, 0x00360033, 0x00370033, 0x00380033, 0x00390033,\n 0x00300034, 0x00310034, 0x00320034, 0x00330034, 0x00340034,\n 0x00350034, 0x00360034, 0x00370034, 0x00380034, 0x00390034,\n 0x00300035, 0x00310035, 0x00320035, 0x00330035, 0x00340035,\n 0x00350035, 0x00360035, 0x00370035, 0x00380035, 0x00390035,\n 0x00300036, 0x00310036, 0x00320036, 0x00330036, 0x00340036,\n 0x00350036, 0x00360036, 0x00370036, 0x00380036, 0x00390036,\n 0x00300037, 0x00310037, 0x00320037, 0x00330037, 0x00340037,\n 0x00350037, 0x00360037, 0x00370037, 0x00380037, 0x00390037,\n 0x00300038, 0x00310038, 0x00320038, 0x00330038, 0x00340038,\n 0x00350038, 0x00360038, 0x00370038, 0x00380038, 0x00390038,\n 0x00300039, 0x00310039, 0x00320039, 0x00330039, 0x00340039,\n 0x00350039, 0x00360039, 0x00370039, 0x00380039, 0x00390039\n ];\n return table; // inlines to a constant memory offset\n}\n\n@inline\nfunction EXP_POWERS(): i16[] {\n const table: i16[] = [\n -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,\n -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,\n -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,\n -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,\n -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,\n 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,\n 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,\n 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,\n 907, 933, 960, 986, 1013, 1039, 1066\n ];\n return table;\n}\n\n// 1e-348, 1e-340, ..., 1e340\n@inline\nfunction FRC_POWERS(): u64[] {\n const table: u64[] = [\n 0xFA8FD5A0081C0288, 0xBAAEE17FA23EBF76, 0x8B16FB203055AC76, 0xCF42894A5DCE35EA,\n 0x9A6BB0AA55653B2D, 0xE61ACF033D1A45DF, 0xAB70FE17C79AC6CA, 0xFF77B1FCBEBCDC4F,\n 0xBE5691EF416BD60C, 0x8DD01FAD907FFC3C, 0xD3515C2831559A83, 0x9D71AC8FADA6C9B5,\n 0xEA9C227723EE8BCB, 0xAECC49914078536D, 0x823C12795DB6CE57, 0xC21094364DFB5637,\n 0x9096EA6F3848984F, 0xD77485CB25823AC7, 0xA086CFCD97BF97F4, 0xEF340A98172AACE5,\n 0xB23867FB2A35B28E, 0x84C8D4DFD2C63F3B, 0xC5DD44271AD3CDBA, 0x936B9FCEBB25C996,\n 0xDBAC6C247D62A584, 0xA3AB66580D5FDAF6, 0xF3E2F893DEC3F126, 0xB5B5ADA8AAFF80B8,\n 0x87625F056C7C4A8B, 0xC9BCFF6034C13053, 0x964E858C91BA2655, 0xDFF9772470297EBD,\n 0xA6DFBD9FB8E5B88F, 0xF8A95FCF88747D94, 0xB94470938FA89BCF, 0x8A08F0F8BF0F156B,\n 0xCDB02555653131B6, 0x993FE2C6D07B7FAC, 0xE45C10C42A2B3B06, 0xAA242499697392D3,\n 0xFD87B5F28300CA0E, 0xBCE5086492111AEB, 0x8CBCCC096F5088CC, 0xD1B71758E219652C,\n 0x9C40000000000000, 0xE8D4A51000000000, 0xAD78EBC5AC620000, 0x813F3978F8940984,\n 0xC097CE7BC90715B3, 0x8F7E32CE7BEA5C70, 0xD5D238A4ABE98068, 0x9F4F2726179A2245,\n 0xED63A231D4C4FB27, 0xB0DE65388CC8ADA8, 0x83C7088E1AAB65DB, 0xC45D1DF942711D9A,\n 0x924D692CA61BE758, 0xDA01EE641A708DEA, 0xA26DA3999AEF774A, 0xF209787BB47D6B85,\n 0xB454E4A179DD1877, 0x865B86925B9BC5C2, 0xC83553C5C8965D3D, 0x952AB45CFA97A0B3,\n 0xDE469FBD99A05FE3, 0xA59BC234DB398C25, 0xF6C69A72A3989F5C, 0xB7DCBF5354E9BECE,\n 0x88FCF317F22241E2, 0xCC20CE9BD35C78A5, 0x98165AF37B2153DF, 0xE2A0B5DC971F303A,\n 0xA8D9D1535CE3B396, 0xFB9B7CD9A4A7443C, 0xBB764C4CA7A44410, 0x8BAB8EEFB6409C1A,\n 0xD01FEF10A657842C, 0x9B10A4E5E9913129, 0xE7109BFBA19C0C9D, 0xAC2820D9623BF429,\n 0x80444B5E7AA7CF85, 0xBF21E44003ACDD2D, 0x8E679C2F5E44FF8F, 0xD433179D9C8CB841,\n 0x9E19DB92B4E31BA9, 0xEB96BF6EBADF77D9, 0xAF87023B9BF0EE6B\n ];\n return table;\n}\n\n// Count number of decimals for u32 values\n// In our case input value always non-zero so we can simplify some parts\nexport function decimalCount32(value: u32): u32 {\n if (ASC_SHRINK_LEVEL >= 1) {\n let l: u32 = 32 - clz(value); // log2\n let t = l * 1233 >>> 12; // log10\n\n let lutbuf = POWERS10().buffer_;\n let power = loadUnsafe(lutbuf, t);\n t -= (value < power);\n return t + 1;\n } else {\n if (value < 100000) {\n if (value < 100) {\n return select(1, 2, value < 10);\n } else {\n let m = select(4, 5, value < 10000);\n return select(3, m, value < 1000);\n }\n } else {\n if (value < 10000000) {\n return select(6, 7, value < 1000000);\n } else {\n let m = select(9, 10, value < 1000000000);\n return select(8, m, value < 100000000);\n }\n }\n }\n}\n\n// Count number of decimals for u64 values\n// In our case input value always greater than 2^32-1 so we can skip some parts\nexport function decimalCount64(value: u64): u32 {\n if (ASC_SHRINK_LEVEL >= 1) {\n let l: u32 = 64 - clz(value); // log2\n let t = l * 1233 >>> 12; // log10\n\n let lutbuf = POWERS10().buffer_;\n let power = loadUnsafe(lutbuf, t - 10);\n t -= (value < 10000000000 * power);\n return t + 1;\n } else {\n if (value < 1000000000000000) {\n if (value < 1000000000000) {\n return select(11, 12, value < 100000000000);\n } else {\n let m = select(14, 15, value < 100000000000000);\n return select(13, m, value < 10000000000000);\n }\n } else {\n if (value < 100000000000000000) {\n return select(16, 17, value < 10000000000000000);\n } else {\n let m = select(19, 20, value < 10000000000000000000);\n return select(18, m, value < 1000000000000000000);\n }\n }\n }\n}\n\nfunction utoa32_lut(buffer: usize, num: u32, offset: usize): void {\n var lutbuf = DIGITS().buffer_;\n\n while (num >= 10000) {\n // in most VMs i32/u32 div and modulo by constant can be shared and simplificate\n let t = num / 10000;\n let r = num % 10000;\n num = t;\n\n let d1 = r / 100;\n let d2 = r % 100;\n\n let digits1 = loadUnsafe(lutbuf, d1);\n let digits2 = loadUnsafe(lutbuf, d2);\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32), STRING_HEADER_SIZE);\n }\n\n if (num >= 100) {\n let t = num / 100;\n let d1 = num % 100;\n num = t;\n offset -= 2;\n let digits = loadUnsafe(lutbuf, d1);\n store(buffer + (offset << 1), digits, STRING_HEADER_SIZE);\n }\n\n if (num >= 10) {\n offset -= 2;\n let digits = loadUnsafe(lutbuf, num);\n store(buffer + (offset << 1), digits, STRING_HEADER_SIZE);\n } else {\n offset -= 1;\n let digit = CharCode._0 + num;\n store(buffer + (offset << 1), digit, STRING_HEADER_SIZE);\n }\n}\n\nfunction utoa64_lut(buffer: usize, num: u64, offset: usize): void {\n var lutbuf = DIGITS().buffer_;\n\n while (num >= 100000000) {\n let t = num / 100000000;\n let r = (num - t * 100000000);\n num = t;\n\n let b = r / 10000;\n let c = r % 10000;\n\n let b1 = b / 100;\n let b2 = b % 100;\n let c1 = c / 100;\n let c2 = c % 100;\n\n let digits1 = loadUnsafe(lutbuf, c1);\n let digits2 = loadUnsafe(lutbuf, c2);\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32), STRING_HEADER_SIZE);\n\n digits1 = loadUnsafe(lutbuf, b1);\n digits2 = loadUnsafe(lutbuf, b2);\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32), STRING_HEADER_SIZE);\n }\n\n utoa32_lut(buffer, num, offset);\n}\n\nfunction utoa_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let t = num / 10;\n let r = (num % 10);\n num = t;\n offset -= 1;\n store(buffer + (offset << 1), CharCode._0 + r, STRING_HEADER_SIZE);\n } while (num);\n}\n\n@inline\nexport function utoa32_core(buffer: usize, num: u32, offset: u32): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_simple(buffer, num, offset);\n } else {\n utoa32_lut(buffer, num, offset);\n }\n}\n\n@inline\nexport function utoa64_core(buffer: usize, num: u64, offset: u32): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_simple(buffer, num, offset);\n } else {\n utoa64_lut(buffer, num, offset);\n }\n}\n\nexport function utoa32(value: u32): String {\n if (!value) return "0";\n\n var decimals = decimalCount32(value);\n var buffer = allocateUnsafeString(decimals);\n\n utoa32_core(changetype(buffer), value, decimals);\n return buffer;\n}\n\nexport function itoa32(value: i32): String {\n if (!value) return "0";\n\n var sign = value < 0;\n if (sign) value = -value;\n\n var decimals = decimalCount32(value) + sign;\n var buffer = allocateUnsafeString(decimals);\n\n utoa32_core(changetype(buffer), value, decimals);\n if (sign) store(changetype(buffer), CharCode.MINUS, STRING_HEADER_SIZE);\n\n return buffer;\n}\n\nexport function utoa64(value: u64): String {\n if (!value) return "0";\n\n var buffer: String;\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n buffer = allocateUnsafeString(decimals);\n utoa32_core(changetype(buffer), val32, decimals);\n } else {\n let decimals = decimalCount64(value);\n buffer = allocateUnsafeString(decimals);\n utoa64_core(changetype(buffer), value, decimals);\n }\n return buffer;\n}\n\nexport function itoa64(value: i64): String {\n if (!value) return "0";\n\n var sign = value < 0;\n if (sign) value = -value;\n\n var buffer: String;\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32) + sign;\n buffer = allocateUnsafeString(decimals);\n utoa32_core(changetype(buffer), val32, decimals);\n } else {\n let decimals = decimalCount64(value) + sign;\n buffer = allocateUnsafeString(decimals);\n utoa64_core(changetype(buffer), value, decimals);\n }\n if (sign) store(changetype(buffer), CharCode.MINUS, STRING_HEADER_SIZE);\n\n return buffer;\n}\n\nexport function itoa(value: T): String {\n if (!isInteger()) {\n assert(false); // unexpecteble non-integer generic type\n } else {\n if (isSigned()) {\n if (sizeof() <= 4) {\n return itoa32(value);\n } else {\n return itoa64(value);\n }\n } else {\n if (sizeof() <= 4) {\n return utoa32(value);\n } else {\n return utoa64(value);\n }\n }\n }\n}\n\nvar _K: i32 = 0;\n\nvar _frc: u64 = 0;\nvar _exp: i32 = 0;\n\nvar _frc_minus: u64 = 0;\nvar _frc_plus: u64 = 0;\n\nvar _frc_pow: u64 = 0;\nvar _exp_pow: i32 = 0;\n\n@inline\nfunction umul64f(u: u64, v: u64): u64 {\n var u0 = u & 0xFFFFFFFF;\n var v0 = v & 0xFFFFFFFF;\n\n var u1 = u >> 32;\n var v1 = v >> 32;\n\n var l = u0 * v0;\n var t = u1 * v0 + (l >> 32);\n var w = u0 * v1 + (t & 0xFFFFFFFF);\n\n w += 0x7FFFFFFF; // rounding\n\n t >>= 32;\n w >>= 32;\n\n return u1 * v1 + t + w;\n}\n\n@inline\nfunction umul64e(e1: i32, e2: i32): i32 {\n return e1 + e2 + 64; // where 64 is significand size\n}\n\n@inline\nfunction normalizedBoundaries(f: u64, e: i32): void {\n var frc = (f << 1) + 1;\n var exp = e - 1;\n var off = clz(frc);\n frc <<= off;\n exp -= off;\n\n var m = 1 + (f == 0x0010000000000000);\n\n _frc_plus = frc;\n _frc_minus = ((f << m) - 1) << e - m - exp;\n _exp = exp;\n}\n\n@inline\nfunction grisuRound(buffer: usize, len: i32, delta: u64, rest: u64, ten_kappa: u64, wp_w: u64): void {\n var lastp = buffer + ((len - 1) << 1);\n var digit = load(lastp, STRING_HEADER_SIZE);\n while (\n rest < wp_w &&\n delta - rest >= ten_kappa && (\n rest + ten_kappa < wp_w ||\n wp_w - rest > rest + ten_kappa - wp_w\n )\n ) {\n --digit;\n rest += ten_kappa;\n }\n store(lastp, digit, STRING_HEADER_SIZE);\n}\n\n@inline\nfunction getCachedPower(minExp: i32): void {\n const c = reinterpret(0x3FD34413509F79FE); // 1 / lg(10) = 0.30102999566398114\n var dk = (-61 - minExp) * c + 347;\t // dk must be positive, so can do ceiling in positive\n var k = dk;\n k += (k != dk); // conversion with ceil\n\n var index = (k >> 3) + 1;\n _K = 348 - (index << 3);\t// decimal exponent no need lookup table\n var frcPowers = FRC_POWERS().buffer_;\n var expPowers = EXP_POWERS().buffer_;\n _frc_pow = loadUnsafe(frcPowers, index);\n _exp_pow = loadUnsafe(expPowers, index);\n}\n\n@inline\nfunction grisu2(value: f64, buffer: usize, sign: i32): i32 {\n\n // frexp routine\n var uv = reinterpret(value);\n var exp = ((uv & 0x7FF0000000000000) >>> 52);\n var sid = uv & 0x000FFFFFFFFFFFFF;\n var frc = ((exp != 0) << 52) + sid;\n exp = select(exp, 1, exp != 0) - (0x3FF + 52);\n\n normalizedBoundaries(frc, exp);\n getCachedPower(_exp);\n\n // normalize\n var off = clz(frc);\n frc <<= off;\n exp -= off;\n\n var frc_pow = _frc_pow;\n var exp_pow = _exp_pow;\n\n var w_frc = umul64f(frc, frc_pow);\n var w_exp = umul64e(exp, exp_pow);\n\n var wp_frc = umul64f(_frc_plus, frc_pow) - 1;\n var wp_exp = umul64e(_exp, exp_pow);\n\n var wm_frc = umul64f(_frc_minus, frc_pow) + 1;\n var delta = wp_frc - wm_frc;\n\n return genDigits(buffer, w_frc, w_exp, wp_frc, wp_exp, delta, sign);\n}\n\nfunction genDigits(buffer: usize, w_frc: u64, w_exp: i32, mp_frc: u64, mp_exp: i32, delta: u64, sign: i32): i32 {\n var one_exp = -mp_exp;\n var one_frc = (1) << one_exp;\n var mask = one_frc - 1;\n\n var wp_w_frc = mp_frc - w_frc;\n var wp_w_exp = mp_exp;\n\n var p1 = (mp_frc >> one_exp);\n var p2 = mp_frc & mask;\n\n var kappa = decimalCount32(p1);\n var len = sign;\n\n var powers10 = POWERS10().buffer_;\n\n while (kappa > 0) {\n let d: u32;\n switch (kappa) {\n case 10: { d = p1 / 1000000000; p1 %= 1000000000; break; }\n case 9: { d = p1 / 100000000; p1 %= 100000000; break; }\n case 8: { d = p1 / 10000000; p1 %= 10000000; break; }\n case 7: { d = p1 / 1000000; p1 %= 1000000; break; }\n case 6: { d = p1 / 100000; p1 %= 100000; break; }\n case 5: { d = p1 / 10000; p1 %= 10000; break; }\n case 4: { d = p1 / 1000; p1 %= 1000; break; }\n case 3: { d = p1 / 100; p1 %= 100; break; }\n case 2: { d = p1 / 10; p1 %= 10; break; }\n case 1: { d = p1; p1 = 0; break; }\n default: { d = 0; break; }\n }\n\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d, STRING_HEADER_SIZE);\n\n --kappa;\n let tmp = ((p1) << one_exp) + p2;\n if (tmp <= delta) {\n _K += kappa;\n grisuRound(buffer, len, delta, tmp, loadUnsafe(powers10, kappa) << one_exp, wp_w_frc);\n return len;\n }\n }\n\n while (1) {\n p2 *= 10;\n delta *= 10;\n\n let d = p2 >> one_exp;\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d, STRING_HEADER_SIZE);\n\n p2 &= mask;\n --kappa;\n if (p2 < delta) {\n _K += kappa;\n wp_w_frc *= loadUnsafe(powers10, -kappa);\n grisuRound(buffer, len, delta, p2, one_frc, wp_w_frc);\n return len;\n }\n }\n\n return len;\n}\n\n@inline\nfunction genExponent(buffer: usize, k: i32): i32 {\n var sign = k < 0;\n if (sign) k = -k;\n var decimals = decimalCount32(k) + 1;\n utoa32_core(buffer, k, decimals);\n store(buffer, select(CharCode.MINUS, CharCode.PLUS, sign), STRING_HEADER_SIZE);\n return decimals;\n}\n\nfunction prettify(buffer: usize, length: i32, k: i32): i32 {\n if (!k) {\n store(buffer + (length << 1), CharCode.DOT | (CharCode._0 << 16), STRING_HEADER_SIZE);\n return length + 2;\n }\n\n var kk = length + k;\n if (length <= kk && kk <= 21) {\n // 1234e7 -> 12340000000\n for (let i = length; i < kk; ++i) {\n store(buffer + (i << 1), CharCode._0, STRING_HEADER_SIZE);\n }\n store(buffer + (kk << 1), CharCode.DOT | (CharCode._0 << 16), STRING_HEADER_SIZE);\n return kk + 2;\n } else if (kk > 0 && kk <= 21) {\n // 1234e-2 -> 12.34\n let ptr = buffer + (kk << 1);\n memory.copy(\n ptr + STRING_HEADER_SIZE + 2,\n ptr + STRING_HEADER_SIZE,\n -k << 1\n );\n store(buffer + (kk << 1), CharCode.DOT, STRING_HEADER_SIZE);\n return length + 1;\n } else if (-6 < kk && kk <= 0) {\n // 1234e-6 -> 0.001234\n let offset = 2 - kk;\n memory.copy(\n buffer + STRING_HEADER_SIZE + (offset << 1),\n buffer + STRING_HEADER_SIZE,\n length << 1\n );\n store(buffer, CharCode._0 | (CharCode.DOT << 16), STRING_HEADER_SIZE);\n for (let i = 2; i < offset; ++i) {\n store(buffer + (i << 1), CharCode._0, STRING_HEADER_SIZE);\n }\n return length + offset;\n } else if (length == 1) {\n // 1e30\n store(buffer, CharCode.e, STRING_HEADER_SIZE + 2);\n length = genExponent(buffer + 4, kk - 1);\n return length + 2;\n } else {\n let len = length << 1;\n memory.copy(\n buffer + STRING_HEADER_SIZE + 4,\n buffer + STRING_HEADER_SIZE + 2,\n len - 2\n );\n store(buffer, CharCode.DOT, STRING_HEADER_SIZE + 2);\n store(buffer + len, CharCode.e, STRING_HEADER_SIZE + 2);\n length += genExponent(buffer + len + 4, kk - 1);\n return length + 2;\n }\n}\n\nexport function dtoa_core(buffer: usize, value: f64): i32 {\n var sign = (value < 0);\n if (sign) {\n value = -value;\n store(buffer, CharCode.MINUS, STRING_HEADER_SIZE);\n }\n // assert(value > 0 && value <= 1.7976931348623157e308);\n var len = grisu2(value, buffer, sign);\n len = prettify(buffer + (sign << 1), len - sign, _K);\n return len + sign;\n}\n\nexport function dtoa(value: f64): String {\n if (value == 0) return "0.0";\n if (!isFinite(value)) {\n if (isNaN(value)) return "NaN";\n return select("-Infinity", "Infinity", value < 0);\n }\n var buffer = allocateUnsafeString(MAX_DOUBLE_LENGTH);\n var length = dtoa_core(changetype(buffer), value);\n var result = buffer.substring(0, length);\n freeUnsafeString(buffer);\n return result;\n}\n\nexport function itoa_stream(buffer: usize, offset: usize, value: T): u32 {\n buffer += (offset << 1);\n if (!value) {\n store(buffer, CharCode._0, STRING_HEADER_SIZE);\n return 1;\n }\n var decimals: u32 = 0;\n if (isSigned()) {\n let sign = value < 0;\n if (sign) value = -value;\n if (sizeof() <= 4) {\n decimals = decimalCount32(value) + sign;\n utoa32_core(buffer, value, decimals);\n } else {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n decimals = decimalCount32(val32) + sign;\n utoa32_core(buffer, val32, decimals);\n } else {\n decimals = decimalCount64(value) + sign;\n utoa64_core(buffer, value, decimals);\n }\n }\n if (sign) store(buffer, CharCode.MINUS, STRING_HEADER_SIZE);\n } else {\n if (sizeof() <= 4) {\n decimals = decimalCount32(value);\n utoa32_core(buffer, value, decimals);\n } else {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_core(buffer, val32, decimals);\n } else {\n decimals = decimalCount64(value);\n utoa64_core(buffer, value, decimals);\n }\n }\n }\n return decimals;\n}\n\nexport function dtoa_stream(buffer: usize, offset: usize, value: f64): u32 {\n buffer += (offset << 1);\n if (value == 0.0) {\n store(buffer, CharCode._0, STRING_HEADER_SIZE + 0);\n store(buffer, CharCode.DOT, STRING_HEADER_SIZE + 2);\n store(buffer, CharCode._0, STRING_HEADER_SIZE + 4);\n return 3;\n }\n if (!isFinite(value)) {\n if (isNaN(value)) {\n store(buffer, CharCode.N, STRING_HEADER_SIZE + 0);\n store(buffer, CharCode.a, STRING_HEADER_SIZE + 2);\n store(buffer, CharCode.N, STRING_HEADER_SIZE + 4);\n return 3;\n } else {\n let sign = (value < 0);\n let len = 8 + sign;\n let source = changetype(select("-Infinity", "Infinity", sign));\n memory.copy(buffer + STRING_HEADER_SIZE, source, len << 1);\n return len;\n }\n }\n return dtoa_core(buffer, value);\n}\n',"internal/string":'import { MAX_SIZE_32 } from "./allocator";\nimport { String } from "../string";\n\n/** Size of a String header. */\nexport const HEADER_SIZE = (offsetof() + 1) & ~1; // 2 byte aligned\n/** Maximum length of a String. */\nexport const MAX_LENGTH = (MAX_SIZE_32 - HEADER_SIZE) >>> 1;\n\n// Low-level utility\n\nfunction __gc(ref: usize): void {}\n\nexport function allocateUnsafe(length: i32): String {\n assert(length > 0 && length <= MAX_LENGTH);\n var buffer: usize;\n if (isManaged()) {\n buffer = __gc_allocate(HEADER_SIZE + (length << 1), __gc); // tslint:disable-line\n } else {\n buffer = memory.allocate(HEADER_SIZE + (length << 1));\n }\n store(buffer, length);\n return changetype(buffer);\n}\n\n@inline\nexport function freeUnsafe(buffer: String): void {\n if (!isManaged()) {\n assert(buffer);\n memory.free(changetype(buffer));\n }\n}\n\nexport function copyUnsafe(dest: String, destOffset: usize, src: String, srcOffset: usize, len: usize): void {\n memory.copy(\n changetype(dest) + (destOffset << 1) + HEADER_SIZE,\n changetype(src) + (srcOffset << 1) + HEADER_SIZE,\n len << 1\n );\n}\n\nexport function compareUnsafe(str1: String, offset1: usize, str2: String, offset2: usize, len: usize): i32 {\n var cmp: i32 = 0;\n var ptr1 = changetype(str1) + (offset1 << 1);\n var ptr2 = changetype(str2) + (offset2 << 1);\n while (len && !(cmp = load(ptr1, HEADER_SIZE) - load(ptr2, HEADER_SIZE))) {\n --len, ++ptr1, ++ptr2;\n }\n return cmp;\n}\n\nexport function repeatUnsafe(dest: String, destOffset: usize, src: String, count: i32): void {\n var length = src.length;\n if (ASC_SHRINK_LEVEL > 1) {\n let strLen = length << 1;\n let to = changetype(dest) + HEADER_SIZE + (destOffset << 1);\n let from = changetype(src) + HEADER_SIZE;\n for (let i = 0, len = strLen * count; i < len; i += strLen) {\n memory.copy(to + i, from, strLen);\n }\n } else {\n switch (length) {\n case 0: break;\n case 1: {\n let cc = load(changetype(src), HEADER_SIZE);\n let out = changetype(dest) + (destOffset << 1);\n for (let i = 0; i < count; ++i) {\n store(out + (i << 1), cc, HEADER_SIZE);\n }\n break;\n }\n case 2: {\n let cc = load(changetype(src), HEADER_SIZE);\n let out = changetype(dest) + (destOffset << 1);\n for (let i = 0; i < count; ++i) {\n store(out + (i << 2), cc, HEADER_SIZE);\n }\n break;\n }\n case 3: {\n let cc1 = load(changetype(src), HEADER_SIZE + 0);\n let cc2 = load(changetype(src), HEADER_SIZE + 4);\n let out = changetype(dest) + (destOffset << 1);\n for (let i = 0; i < count; ++i) {\n store(out + (i << 2), cc1, HEADER_SIZE + 0);\n store(out + (i << 1), cc2, HEADER_SIZE + 4);\n }\n break;\n }\n case 4: {\n let cc = load(changetype(src), HEADER_SIZE);\n let out = changetype(dest) + (destOffset << 1);\n for (let i = 0; i < count; ++i) {\n store(out + (i << 3), cc, HEADER_SIZE);\n }\n break;\n }\n default: {\n let strLen = length << 1;\n let to = changetype(dest) + HEADER_SIZE + (destOffset << 1);\n let from = changetype(src) + HEADER_SIZE;\n for (let i = 0, len = strLen * count; i < len; i += strLen) {\n memory.copy(to + i, from, strLen);\n }\n break;\n }\n }\n }\n}\n\n// Helpers\n\nexport const enum CharCode {\n PLUS = 0x2B,\n MINUS = 0x2D,\n DOT = 0x2E,\n _0 = 0x30,\n _1 = 0x31,\n _2 = 0x32,\n _3 = 0x33,\n _4 = 0x34,\n _5 = 0x35,\n _6 = 0x36,\n _7 = 0x37,\n _8 = 0x38,\n _9 = 0x39,\n A = 0x41,\n B = 0x42,\n E = 0x45,\n N = 0x4E,\n O = 0x4F,\n X = 0x58,\n Z = 0x5a,\n a = 0x61,\n b = 0x62,\n e = 0x65,\n n = 0x6E,\n o = 0x6F,\n x = 0x78,\n z = 0x7A\n}\n\nexport function isWhiteSpaceOrLineTerminator(c: u16): bool {\n switch (c) {\n case 9: // \n case 10: // \n case 13: // \n case 11: // \n case 12: // \n case 32: // \n case 160: // \n case 8232: // \n case 8233: // \n case 65279: return true; // \n default: return false;\n }\n}\n\n/** Parses a string to an integer (usually), using the specified radix. */\nexport function parse(str: String, radix: i32 = 0): T {\n var len: i32 = str.length;\n if (!len) return NaN;\n\n var ptr = changetype(str) /* + HEAD -> offset */;\n var code = load(ptr, HEADER_SIZE);\n\n // determine sign\n var sign: T;\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = load(ptr += 2, HEADER_SIZE);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = load(ptr += 2, HEADER_SIZE);\n sign = 1;\n } else {\n sign = 1;\n }\n\n // determine radix\n if (!radix) {\n if (code == CharCode._0 && len > 2) {\n switch (load(ptr + 2, HEADER_SIZE)) {\n case CharCode.B:\n case CharCode.b: {\n ptr += 4; len -= 2;\n radix = 2;\n break;\n }\n case CharCode.O:\n case CharCode.o: {\n ptr += 4; len -= 2;\n radix = 8;\n break;\n }\n case CharCode.X:\n case CharCode.x: {\n ptr += 4; len -= 2;\n radix = 16;\n break;\n }\n default: radix = 10;\n }\n } else radix = 10;\n } else if (radix < 2 || radix > 36) {\n return NaN;\n }\n\n // calculate value\n var num: T = 0;\n while (len--) {\n code = load(ptr, HEADER_SIZE);\n if (code >= CharCode._0 && code <= CharCode._9) {\n code -= CharCode._0;\n } else if (code >= CharCode.A && code <= CharCode.Z) {\n code -= CharCode.A - 10;\n } else if (code >= CharCode.a && code <= CharCode.z) {\n code -= CharCode.a - 10;\n } else break;\n if (code >= radix) break;\n num = (num * radix) + code;\n ptr += 2;\n }\n return sign * num;\n}\n',"internal/typedarray":'import {\n HEADER_SIZE as AB_HEADER_SIZE,\n MAX_BLENGTH as AB_MAX_BLENGTH,\n allocateUnsafe,\n loadUnsafeWithOffset,\n storeUnsafeWithOffset\n} from "./arraybuffer";\n\nimport {\n insertionSort,\n weakHeapSort,\n defaultComparator\n} from "./array";\n\n/** Typed array base class. Not a global object. */\nexport abstract class TypedArray {\n\n readonly buffer: ArrayBuffer;\n readonly byteOffset: i32;\n readonly byteLength: i32;\n\n constructor(length: i32) {\n const MAX_LENGTH = AB_MAX_BLENGTH / sizeof();\n if (length > MAX_LENGTH) throw new RangeError("Invalid typed array length");\n var byteLength = length << alignof();\n var buffer = allocateUnsafe(byteLength);\n memory.fill(changetype(buffer) + AB_HEADER_SIZE, 0, byteLength);\n this.buffer = buffer;\n this.byteOffset = 0;\n this.byteLength = byteLength;\n }\n\n @inline\n get length(): i32 {\n return this.byteLength >>> alignof();\n }\n\n @operator("[]")\n protected __get(index: i32): T {\n if (index >= (this.byteLength >>> alignof())) throw new Error("Index out of bounds");\n return loadUnsafeWithOffset(this.buffer, index, this.byteOffset);\n }\n\n @inline @operator("{}")\n protected __unchecked_get(index: i32): T {\n return loadUnsafeWithOffset(this.buffer, index, this.byteOffset);\n }\n\n @operator("[]=")\n protected __set(index: i32, value: V): void {\n if (index >= (this.byteLength >>> alignof())) throw new Error("Index out of bounds");\n storeUnsafeWithOffset(this.buffer, index, value, this.byteOffset);\n }\n\n @inline @operator("{}=")\n protected __unchecked_set(index: i32, value: V): void {\n storeUnsafeWithOffset(this.buffer, index, value, this.byteOffset);\n }\n\n // copyWithin(target: i32, start: i32, end: i32 = this.length): this\n\n fill(value: V, start: i32 = 0, end: i32 = i32.MAX_VALUE): this {\n var buffer = this.buffer;\n var byteOffset = this.byteOffset;\n var len = this.length;\n start = start < 0 ? max(len + start, 0) : min(start, len);\n end = end < 0 ? max(len + end, 0) : min(end, len);\n if (sizeof() == 1) {\n if (start < end) {\n memory.fill(\n changetype(buffer) + start + byteOffset + AB_HEADER_SIZE,\n value,\n (end - start)\n );\n }\n } else {\n for (; start < end; ++start) {\n storeUnsafeWithOffset(buffer, start, value, byteOffset);\n }\n }\n return this;\n }\n\n @inline\n subarray(begin: i32 = 0, end: i32 = i32.MAX_VALUE): TypedArray {\n var length = this.length;\n if (begin < 0) begin = max(length + begin, 0);\n else begin = min(begin, length);\n if (end < 0) end = max(length + end, begin);\n else end = max(min(end, length), begin);\n var slice = memory.allocate(offsetof());\n store(slice, this.buffer, offsetof("buffer"));\n store(slice, begin << alignof(), offsetof("byteOffset"));\n store(slice, (end - begin) << alignof(), offsetof("byteLength"));\n return changetype(slice);\n }\n\n sort(comparator: (a: T, b: T) => i32 = defaultComparator()): this {\n var byteOffset = this.byteOffset;\n var length = this.length;\n if (length <= 1) return this;\n var buffer = this.buffer;\n if (length == 2) {\n let a = loadUnsafeWithOffset(buffer, 1, byteOffset);\n let b = loadUnsafeWithOffset(buffer, 0, byteOffset);\n if (comparator(a, b) < 0) {\n storeUnsafeWithOffset(buffer, 1, b, byteOffset);\n storeUnsafeWithOffset(buffer, 0, a, byteOffset);\n }\n return this;\n }\n\n if (isReference()) {\n // TODO replace this to faster stable sort (TimSort) when it implemented\n insertionSort(buffer, byteOffset, length, comparator);\n return this;\n } else {\n if (length < 256) {\n insertionSort(buffer, byteOffset, length, comparator);\n } else {\n weakHeapSort(buffer, byteOffset, length, comparator);\n }\n return this;\n }\n }\n}\n',iterator:"// export abstract class Iterator {\n// abstract get done(): bool;\n// abstract next(): T;\n// }\n",map:'import {\n HEADER_SIZE as HEADER_SIZE_AB\n} from "./internal/arraybuffer";\n\nimport {\n hash\n} from "./internal/hash";\n\n// A deterministic hash map based on CloseTable from https://github.com/jorendorff/dht\n\nconst INITIAL_CAPACITY = 4;\nconst FILL_FACTOR: f64 = 8 / 3;\nconst FREE_FACTOR: f64 = 3 / 4;\n\n/** Structure of a map entry. */\n@unmanaged class MapEntry {\n key: K;\n value: V;\n taggedNext: usize; // LSB=1 indicates EMPTY\n}\n\n/** Empty bit. */\nconst EMPTY: usize = 1 << 0;\n\n/** Size of a bucket. */\nconst BUCKET_SIZE = sizeof();\n\n/** Computes the alignment of an entry. */\n@inline function ENTRY_ALIGN(): usize {\n // can align to 4 instead of 8 if 32-bit and K/V is <= 32-bits\n const maxkv = sizeof() > sizeof() ? sizeof() : sizeof();\n const align = (maxkv > sizeof() ? maxkv : sizeof()) - 1;\n return align;\n}\n\n/** Computes the aligned size of an entry. */\n@inline function ENTRY_SIZE(): usize {\n const align = ENTRY_ALIGN();\n const size = (offsetof>() + align) & ~align;\n return size;\n}\n\nexport class Map {\n\n // buckets holding references to the respective first entry within\n private buckets: ArrayBuffer; // usize[bucketsMask + 1]\n private bucketsMask: u32;\n\n // entries in insertion order\n private entries: ArrayBuffer; // MapEntry[entriesCapacity]\n private entriesCapacity: i32;\n private entriesOffset: i32;\n private entriesCount: i32;\n\n get size(): i32 { return this.entriesCount; }\n\n constructor() { this.clear(); }\n\n clear(): void {\n const bucketsSize = INITIAL_CAPACITY * BUCKET_SIZE;\n this.buckets = new ArrayBuffer(bucketsSize);\n this.bucketsMask = INITIAL_CAPACITY - 1;\n const entriesSize = INITIAL_CAPACITY * ENTRY_SIZE();\n this.entries = new ArrayBuffer(entriesSize, true);\n this.entriesCapacity = INITIAL_CAPACITY;\n this.entriesOffset = 0;\n this.entriesCount = 0;\n }\n\n private find(key: K, hashCode: u32): MapEntry | null {\n var entry = load>(\n changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE,\n HEADER_SIZE_AB\n );\n while (entry) {\n if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry;\n entry = changetype>(entry.taggedNext & ~EMPTY);\n }\n return null;\n }\n\n has(key: K): bool {\n return this.find(key, hash(key)) !== null;\n }\n\n get(key: K): V {\n var entry = this.find(key, hash(key));\n return entry ? entry.value : unreachable();\n }\n\n set(key: K, value: V): void {\n var hashCode = hash(key);\n var entry = this.find(key, hashCode);\n if (entry) {\n entry.value = value;\n } else {\n // check if rehashing is necessary\n if (this.entriesOffset == this.entriesCapacity) {\n this.rehash(\n this.entriesCount < (this.entriesCapacity * FREE_FACTOR)\n ? this.bucketsMask // just rehash if 1/4+ entries are empty\n : (this.bucketsMask << 1) | 1 // grow capacity to next 2^N\n );\n }\n // append new entry\n let entries = this.entries;\n entry = changetype>(\n changetype(entries) + HEADER_SIZE_AB + this.entriesOffset++ * ENTRY_SIZE()\n );\n entry.key = key;\n entry.value = value;\n ++this.entriesCount;\n // link with previous entry in bucket\n let bucketPtrBase = changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE;\n entry.taggedNext = load(bucketPtrBase, HEADER_SIZE_AB);\n store(bucketPtrBase, changetype(entry), HEADER_SIZE_AB);\n if (isManaged()) __gc_link(changetype(this), changetype(key)); // tslint:disable-line\n if (isManaged()) __gc_link(changetype(this), changetype(value)); // tslint:disable-line\n }\n }\n\n delete(key: K): bool {\n var entry = this.find(key, hash(key));\n if (!entry) return false;\n entry.taggedNext |= EMPTY;\n --this.entriesCount;\n // check if rehashing is appropriate\n var halfBucketsMask = this.bucketsMask >> 1;\n if (\n halfBucketsMask + 1 >= max(INITIAL_CAPACITY, this.entriesCount) &&\n this.entriesCount < (this.entriesCapacity * FREE_FACTOR)\n ) this.rehash(halfBucketsMask);\n return true;\n }\n\n private rehash(newBucketsMask: u32): void {\n var newBucketsCapacity = (newBucketsMask + 1);\n var newBuckets = new ArrayBuffer(newBucketsCapacity * BUCKET_SIZE);\n var newEntriesCapacity = (newBucketsCapacity * FILL_FACTOR);\n var newEntries = new ArrayBuffer(newEntriesCapacity * ENTRY_SIZE(), true);\n\n // copy old entries to new entries\n var oldPtr = changetype(this.entries) + HEADER_SIZE_AB;\n var oldEnd = oldPtr + this.entriesOffset * ENTRY_SIZE();\n var newPtr = changetype(newEntries) + HEADER_SIZE_AB;\n while (oldPtr != oldEnd) {\n let oldEntry = changetype>(oldPtr);\n if (!(oldEntry.taggedNext & EMPTY)) {\n let newEntry = changetype>(newPtr);\n newEntry.key = oldEntry.key;\n newEntry.value = oldEntry.value;\n let newBucketIndex = hash(oldEntry.key) & newBucketsMask;\n let newBucketPtrBase = changetype(newBuckets) + newBucketIndex * BUCKET_SIZE;\n newEntry.taggedNext = load(newBucketPtrBase, HEADER_SIZE_AB);\n store(newBucketPtrBase, newPtr, HEADER_SIZE_AB);\n newPtr += ENTRY_SIZE();\n }\n oldPtr += ENTRY_SIZE();\n }\n\n this.buckets = newBuckets;\n this.bucketsMask = newBucketsMask;\n this.entries = newEntries;\n this.entriesCapacity = newEntriesCapacity;\n this.entriesOffset = this.entriesCount;\n }\n\n private __gc(): void {\n __gc_mark(changetype(this.buckets)); // tslint:disable-line\n var entries = this.entries;\n __gc_mark(changetype(entries)); // tslint:disable-line\n if (isManaged() || isManaged()) {\n let offset: usize = 0;\n let end: usize = this.entriesOffset * ENTRY_SIZE();\n while (offset < end) {\n let entry = changetype>(\n changetype(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE()\n );\n if (!(entry.taggedNext & EMPTY)) {\n if (isManaged()) __gc_mark(changetype(entry.key)); // tslint:disable-line\n if (isManaged()) __gc_mark(changetype(entry.value)); // tslint:disable-line\n }\n offset += ENTRY_SIZE();\n }\n }\n }\n}\n',math:'import * as JSMath from "./bindings/Math";\nexport { JSMath };\n\nimport {\n abs as builtin_abs,\n ceil as builtin_ceil,\n clz as builtin_clz,\n copysign as builtin_copysign,\n floor as builtin_floor,\n max as builtin_max,\n min as builtin_min,\n sqrt as builtin_sqrt,\n trunc as builtin_trunc\n} from "./builtins";\n\n// SUN COPYRIGHT NOTICE\n//\n// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.\n// Developed at SunPro, a Sun Microsystems, Inc. business.\n// Permission to use, copy, modify, and distribute this software\n// is freely granted, provided that this notice is preserved.\n//\n// Applies to all functions marked with a comment referring here.\n\n// TODO: sin, cos, tan\n\n/** @internal */\nfunction R(z: f64): f64 { // Rational approximation of (asin(x)-x)/x^3\n const // see: musl/src/math/asin.c and SUN COPYRIGHT NOTICE above\n pS0 = reinterpret(0x3FC5555555555555), // 1.66666666666666657415e-01\n pS1 = reinterpret(0xBFD4D61203EB6F7D), // -3.25565818622400915405e-01\n pS2 = reinterpret(0x3FC9C1550E884455), // 2.01212532134862925881e-01\n pS3 = reinterpret(0xBFA48228B5688F3B), // -4.00555345006794114027e-02\n pS4 = reinterpret(0x3F49EFE07501B288), // 7.91534994289814532176e-04\n pS5 = reinterpret(0x3F023DE10DFDF709), // 3.47933107596021167570e-05\n qS1 = reinterpret(0xC0033A271C8A2D4B), // -2.40339491173441421878e+00\n qS2 = reinterpret(0x40002AE59C598AC8), // 2.02094576023350569471e+00\n qS3 = reinterpret(0xBFE6066C1B8D0159), // -6.88283971605453293030e-01\n qS4 = reinterpret(0x3FB3B8C5B12E9282); // 7.70381505559019352791e-02\n var p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));\n var q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));\n return p / q;\n}\n\n@inline /** @internal */\nfunction expo2(x: f64): f64 { // exp(x)/2 for x >= log(DBL_MAX)\n const // see: musl/src/math/__expo2.c\n k = 2043,\n kln2 = reinterpret(0x40962066151ADD8B); // 0x1.62066151add8bp+10\n var scale = reinterpret(((0x3FF + k / 2) << 20) << 32);\n return NativeMath.exp(x - kln2) * scale * scale;\n}\n\nvar random_seeded = false;\nvar random_state0_64: u64;\nvar random_state1_64: u64;\nvar random_state0_32: u32;\nvar random_state1_32: u32;\n\n/** @internal */\nfunction murmurHash3(h: u64): u64 { // Force all bits of a hash block to avalanche\n h ^= h >> 33; // see: https://github.com/aappleby/smhasher\n h *= 0xFF51AFD7ED558CCD;\n h ^= h >> 33;\n h *= 0xC4CEB9FE1A85EC53;\n h ^= h >> 33;\n return h;\n}\n\n/** @internal */\nfunction splitMix32(h: u32): u32 {\n h += 0x6D2B79F5;\n h = (h ^ (h >> 15)) * (h | 1);\n h ^= h + (h ^ (h >> 7)) * (h | 61);\n return h ^ (h >> 14);\n}\n\nexport namespace NativeMath {\n\n export const E = reinterpret(0x4005BF0A8B145769); // 2.7182818284590452354\n export const LN2 = reinterpret(0x3FE62E42FEFA39EF); // 0.69314718055994530942\n export const LN10 = reinterpret(0x40026BB1BBB55516); // 2.30258509299404568402\n export const LOG2E = reinterpret(0x3FF71547652B82FE); // 1.4426950408889634074\n export const LOG10E = reinterpret(0x3FDBCB7B1526E50E); // 0.43429448190325182765\n export const PI = reinterpret(0x400921FB54442D18); // 3.14159265358979323846\n export const SQRT1_2 = reinterpret(0x3FE6A09E667F3BCD); // 0.70710678118654752440\n export const SQRT2 = reinterpret(0x3FF6A09E667F3BCD); // 1.41421356237309504880\n\n @inline\n export function abs(x: f64): f64 {\n return builtin_abs(x);\n }\n\n export function acos(x: f64): f64 { // see: musl/src/math/acos.c and SUN COPYRIGHT NOTICE above\n const\n pio2_hi = reinterpret(0x3FF921FB54442D18), // 1.57079632679489655800e+00\n pio2_lo = reinterpret(0x3C91A62633145C07), // 6.12323399573676603587e-17\n Ox1p_120f = reinterpret(0x03800000);\n var hx = (reinterpret(x) >> 32);\n var ix = hx & 0x7FFFFFFF;\n if (ix >= 0x3FF00000) {\n let lx = reinterpret(x);\n if ((ix - 0x3FF00000 | lx) == 0) {\n if (hx >> 31) return 2 * pio2_hi + Ox1p_120f;\n return 0;\n }\n return 0 / (x - x);\n }\n if (ix < 0x3FE00000) {\n if (ix <= 0x3C600000) return pio2_hi + Ox1p_120f;\n return pio2_hi - (x - (pio2_lo - x * R(x * x)));\n }\n var s: f64, w: f64, z: f64;\n if (hx >> 31) {\n // z = (1.0 + x) * 0.5;\n z = 0.5 + x * 0.5;\n s = builtin_sqrt(z);\n w = R(z) * s - pio2_lo;\n return 2 * (pio2_hi - (s + w));\n }\n // z = (1.0 - x) * 0.5;\n z = 0.5 - x * 0.5;\n s = builtin_sqrt(z);\n var df = reinterpret(reinterpret(s) & 0xFFFFFFFF00000000);\n var c = (z - df * df) / (s + df);\n w = R(z) * s + c;\n return 2 * (df + w);\n }\n\n export function acosh(x: f64): f64 { // see: musl/src/math/acosh.c\n const s = reinterpret(0x3FE62E42FEFA39EF);\n var e = reinterpret(x) >> 52 & 0x7FF;\n if (e < 0x3FF + 1) return log1p(x - 1 + builtin_sqrt((x - 1) * (x - 1) + 2 * (x - 1)));\n if (e < 0x3FF + 26) return log(2 * x - 1 / (x + builtin_sqrt(x * x - 1)));\n return log(x) + s;\n }\n\n export function asin(x: f64): f64 { // see: musl/src/math/asin.c and SUN COPYRIGHT NOTICE above\n const\n pio2_hi = reinterpret(0x3FF921FB54442D18), // 1.57079632679489655800e+00\n pio2_lo = reinterpret(0x3C91A62633145C07), // 6.12323399573676603587e-17\n Ox1p_120f = reinterpret(0x03800000);\n var hx = (reinterpret(x) >> 32);\n var ix = hx & 0x7FFFFFFF;\n if (ix >= 0x3FF00000) {\n let lx = reinterpret(x);\n if ((ix - 0x3FF00000 | lx) == 0) return x * pio2_hi + Ox1p_120f;\n return 0 / (x - x);\n }\n if (ix < 0x3FE00000) {\n if (ix < 0x3E500000 && ix >= 0x00100000) return x;\n return x + x * R(x * x);\n }\n // var z = (1.0 - builtin_abs(x)) * 0.5;\n var z = 0.5 - builtin_abs(x) * 0.5;\n var s = builtin_sqrt(z);\n var r = R(z);\n if (ix >= 0x3FEF3333) x = pio2_hi - (2 * (s + s * r) - pio2_lo);\n else {\n let f = reinterpret(reinterpret(s) & 0xFFFFFFFF00000000);\n let c = (z - f * f) / (s + f);\n x = 0.5 * pio2_hi - (2 * s * r - (pio2_lo - 2 * c) - (0.5 * pio2_hi - 2 * f));\n }\n if (hx >> 31) return -x;\n return x;\n }\n\n export function asinh(x: f64): f64 { // see: musl/src/math/asinh.c\n const c = reinterpret(0x3FE62E42FEFA39EF); // 0.693147180559945309417232121458176568\n var u = reinterpret(x);\n var e = u >> 52 & 0x7FF;\n var y = reinterpret(u & 0x7FFFFFFFFFFFFFFF);\n if (e >= 0x3FF + 26) y = log(y) + c;\n else if (e >= 0x3FF + 1) y = log(2 * y + 1 / (builtin_sqrt(y * y + 1) + y));\n else if (e >= 0x3FF - 26) y = log1p(y + y * y / (builtin_sqrt(y * y + 1) + 1));\n return builtin_copysign(y, x);\n }\n\n export function atan(x: f64): f64 { // see musl/src/math/atan.c and SUN COPYRIGHT NOTICE above\n const\n atanhi0 = reinterpret(0x3FDDAC670561BB4F), // 4.63647609000806093515e-01\n atanhi1 = reinterpret(0x3FE921FB54442D18), // 7.85398163397448278999e-01\n atanhi2 = reinterpret(0x3FEF730BD281F69B), // 9.82793723247329054082e-01\n atanhi3 = reinterpret(0x3FF921FB54442D18), // 1.57079632679489655800e+00\n atanlo0 = reinterpret(0x3C7A2B7F222F65E2), // 2.26987774529616870924e-17\n atanlo1 = reinterpret(0x3C81A62633145C07), // 3.06161699786838301793e-17\n atanlo2 = reinterpret(0x3C7007887AF0CBBD), // 1.39033110312309984516e-17\n atanlo3 = reinterpret(0x3C91A62633145C07), // 6.12323399573676603587e-17\n aT0 = reinterpret(0x3FD555555555550D), // 3.33333333333329318027e-01\n aT1 = reinterpret(0xBFC999999998EBC4), // -1.99999999998764832476e-01\n aT2 = reinterpret(0x3FC24924920083FF), // 1.42857142725034663711e-01\n aT3 = reinterpret(0xBFBC71C6FE231671), // -1.11111104054623557880e-01,\n aT4 = reinterpret(0x3FB745CDC54C206E), // 9.09088713343650656196e-02\n aT5 = reinterpret(0xBFB3B0F2AF749A6D), // -7.69187620504482999495e-02\n aT6 = reinterpret(0x3FB10D66A0D03D51), // 6.66107313738753120669e-02\n aT7 = reinterpret(0xBFADDE2D52DEFD9A), // -5.83357013379057348645e-02\n aT8 = reinterpret(0x3FA97B4B24760DEB), // 4.97687799461593236017e-02\n aT9 = reinterpret(0xBFA2B4442C6A6C2F), // -3.65315727442169155270e-02\n aT10 = reinterpret(0x3F90AD3AE322DA11), // 1.62858201153657823623e-02\n Ox1p_120f = reinterpret(0x03800000);\n var ix = (reinterpret(x) >> 32);\n var sx = x;\n ix &= 0x7FFFFFFF;\n var z: f64;\n if (ix >= 0x44100000) {\n if (isNaN(x)) return x;\n z = atanhi3 + Ox1p_120f;\n return builtin_copysign(z, sx);\n }\n var id: i32;\n if (ix < 0x3FDC0000) {\n if (ix < 0x3E400000) return x;\n id = -1;\n } else {\n x = builtin_abs(x);\n if (ix < 0x3FF30000) {\n if (ix < 0x3FE60000) {\n id = 0;\n x = (2.0 * x - 1.0) / (2.0 + x);\n } else {\n id = 1;\n x = (x - 1.0) / (x + 1.0);\n }\n } else {\n if (ix < 0x40038000) {\n id = 2;\n x = (x - 1.5) / (1.0 + 1.5 * x);\n } else {\n id = 3;\n x = -1.0 / x;\n }\n }\n }\n z = x * x;\n var w = z * z;\n var s1 = z * (aT0 + w * (aT2 + w * (aT4 + w * (aT6 + w * (aT8 + w * aT10)))));\n var s2 = w * (aT1 + w * (aT3 + w * (aT5 + w * (aT7 + w * aT9))));\n var s3 = x * (s1 + s2);\n if (id < 0) return x - s3;\n switch (id) {\n case 0: { z = atanhi0 - ((s3 - atanlo0) - x); break; }\n case 1: { z = atanhi1 - ((s3 - atanlo1) - x); break; }\n case 2: { z = atanhi2 - ((s3 - atanlo2) - x); break; }\n case 3: { z = atanhi3 - ((s3 - atanlo3) - x); break; }\n default: unreachable();\n }\n return builtin_copysign(z, sx);\n }\n\n export function atanh(x: f64): f64 { // see: musl/src/math/atanh.c\n var u = reinterpret(x);\n var e = u >> 52 & 0x7FF;\n var s = u >> 63;\n u &= 0x7FFFFFFFFFFFFFFF;\n var y = reinterpret(u);\n if (e < 0x3FF - 1) {\n if (e >= 0x3FF - 32) y = 0.5 * log1p(2 * y + 2 * y * y / (1 - y));\n } else {\n y = 0.5 * log1p(2 * (y / (1 - y)));\n }\n return builtin_copysign(y, x);\n }\n\n export function atan2(y: f64, x: f64): f64 { // see: musl/src/math/atan2.c and SUN COPYRIGHT NOTICE above\n const pi_lo = reinterpret(0x3CA1A62633145C07); // 1.2246467991473531772E-16\n if (isNaN(x) || isNaN(y)) return x + y;\n var u = reinterpret(x);\n var ix = (u >> 32);\n var lx = u;\n u = reinterpret(y);\n var iy = (u >> 32);\n var ly = u;\n if ((ix - 0x3FF00000 | lx) == 0) return atan(y);\n var m = ((iy >> 31) & 1) | ((ix >> 30) & 2);\n ix = ix & 0x7FFFFFFF;\n iy = iy & 0x7FFFFFFF;\n if ((iy | ly) == 0) {\n switch (m) {\n case 0:\n case 1: return y;\n case 2: return PI;\n case 3: return -PI;\n }\n }\n if ((ix | lx) == 0) return m & 1 ? -PI / 2 : PI / 2;\n if (ix == 0x7FF00000) {\n if (iy == 0x7FF00000) {\n switch (m) {\n case 0: return PI / 4;\n case 1: return -PI / 4;\n case 2: return 3 * PI / 4;\n case 3: return -3 * PI / 4;\n }\n } else {\n switch (m) {\n case 0: return 0.0;\n case 1: return -0.0;\n case 2: return PI;\n case 3: return -PI;\n }\n }\n }\n var z: f64;\n if (ix + (64 << 20) < iy || iy == 0x7FF00000) return m & 1 ? -PI / 2 : PI / 2;\n if ((m & 2) && iy + (64 << 20) < ix) z = 0;\n else z = atan(builtin_abs(y / x));\n switch (m) {\n case 0: return z;\n case 1: return -z;\n case 2: return PI - (z - pi_lo);\n case 3: return (z - pi_lo) - PI;\n }\n unreachable();\n return 0;\n }\n\n export function cbrt(x: f64): f64 { // see: musl/src/math/cbrt.c and SUN COPYRIGHT NOTICE above\n const\n B1 = 715094163,\n B2 = 696219795,\n P0 = reinterpret(0x3FFE03E60F61E692), // 1.87595182427177009643\n P1 = reinterpret(0xBFFE28E092F02420), // -1.88497979543377169875\n P2 = reinterpret(0x3FF9F1604A49D6C2), // 1.621429720105354466140\n P3 = reinterpret(0xBFE844CBBEE751D9), // -0.758397934778766047437\n P4 = reinterpret(0x3FC2B000D4E4EDD7), // 0.145996192886612446982\n Ox1p54 = reinterpret(0x4350000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32) & 0x7FFFFFFF;\n if (hx >= 0x7FF00000) return x + x;\n if (hx < 0x00100000) {\n u = reinterpret(x * Ox1p54);\n hx = (u >> 32) & 0x7FFFFFFF;\n if (hx == 0) return x;\n hx = hx / 3 + B2;\n } else {\n hx = hx / 3 + B1;\n }\n u &= 1 << 63;\n u |= hx << 32;\n var t = reinterpret(u);\n var r = (t * t) * (t / x);\n t = t * ((P0 + r * (P1 + r * P2)) + ((r * r) * r) * (P3 + r * P4));\n t = reinterpret((reinterpret(t) + 0x80000000) & 0xFFFFFFFFC0000000);\n var s = t * t;\n r = x / s;\n var w = t + t;\n r = (r - t) / (w + r);\n t = t + t * r;\n return t;\n }\n\n @inline\n export function ceil(x: f64): f64 {\n return builtin_ceil(x);\n }\n\n @inline\n export function clz32(x: f64): f64 {\n return builtin_clz(x);\n }\n\n export function cos(x: f64): f64 { // TODO\n unreachable();\n return 0;\n }\n\n export function cosh(x: f64): f64 { // see: musl/src/math/cosh.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFFFFFFFFFF;\n x = reinterpret(u);\n var w = (u >> 32);\n var t: f64;\n if (w < 0x3FE62E42) {\n if (w < 0x3FF00000 - (26 << 20)) return 1;\n t = expm1(x);\n // return 1 + t * t / (2 * (1 + t));\n return 1 + t * t / (2 + 2 * t);\n }\n if (w < 0x40862E42) {\n t = exp(x);\n return 0.5 * (t + 1 / t);\n }\n t = expo2(x);\n return t;\n }\n\n export function exp(x: f64): f64 { // see: musl/src/math/exp.c and SUN COPYRIGHT NOTICE above\n const\n ln2hi = reinterpret(0x3FE62E42FEE00000), // 6.93147180369123816490e-01\n ln2lo = reinterpret(0x3DEA39EF35793C76), // 1.90821492927058770002e-10\n invln2 = reinterpret(0x3FF71547652B82FE), // 1.44269504088896338700e+00\n P1 = reinterpret(0x3FC555555555553E), // 1.66666666666666019037e-01\n P2 = reinterpret(0xBF66C16C16BEBD93), // -2.77777777770155933842e-03\n P3 = reinterpret(0x3F11566AAF25DE2C), // 6.61375632143793436117e-05\n P4 = reinterpret(0xBEBBBD41C5D26BF1), // -1.65339022054652515390e-06\n P5 = reinterpret(0x3E66376972BEA4D0), // 4.13813679705723846039e-08\n overflow = reinterpret(0x40862E42FEFA39EF), // 709.782712893383973096\n underflow = reinterpret(0xC0874910D52D3051), // -745.13321910194110842\n Ox1p1023 = reinterpret(0x7FE0000000000000);\n var hx = (reinterpret(x) >> 32);\n var sign_ = (hx >> 31);\n hx &= 0x7FFFFFFF;\n if (hx >= 0x4086232B) {\n if (isNaN(x)) return x;\n if (x > overflow) {\n x *= Ox1p1023;\n return x;\n }\n if (x < underflow) return 0;\n }\n var hi: f64, lo: f64 = 0;\n var k = 0;\n if (hx > 0x3FD62E42) {\n if (hx >= 0x3FF0A2B2) {\n k = (invln2 * x + builtin_copysign(0.5, x));\n } else {\n k = 1 - (sign_ << 1);\n }\n hi = x - k * ln2hi;\n lo = k * ln2lo;\n x = hi - lo;\n } else if (hx > 0x3E300000) {\n hi = x;\n } else return 1.0 + x;\n var xx = x * x;\n var c = x - xx * (P1 + xx * (P2 + xx * (P3 + xx * (P4 + xx * P5))));\n var y = 1.0 + (x * c / (2 - c) - lo + hi);\n if (k == 0) return y;\n return scalbn(y, k);\n }\n\n export function expm1(x: f64): f64 { // see: musl/src/math/expm1.c and SUN COPYRIGHT NOTICE above\n const\n o_threshold = reinterpret(0x40862E42FEFA39EF), // 7.09782712893383973096e+02\n ln2_hi = reinterpret(0x3FE62E42FEE00000), // 6.93147180369123816490e-01\n ln2_lo = reinterpret(0x3DEA39EF35793C76), // 1.90821492927058770002e-10\n invln2 = reinterpret(0x3FF71547652B82FE), // 1.44269504088896338700e+00\n Q1 = reinterpret(0xBFA11111111110F4), // -3.33333333333331316428e-02\n Q2 = reinterpret(0x3F5A01A019FE5585), // 1.58730158725481460165e-03\n Q3 = reinterpret(0xBF14CE199EAADBB7), // -7.93650757867487942473e-05\n Q4 = reinterpret(0x3ED0CFCA86E65239), // 4.00821782732936239552e-06\n Q5 = reinterpret(0xBE8AFDB76E09C32D), // -2.01099218183624371326e-07\n Ox1p1023 = reinterpret(0x7FE0000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32 & 0x7FFFFFFF);\n var k = 0, sign_ = (u >> 63);\n if (hx >= 0x4043687A) {\n if (isNaN(x)) return x;\n if (sign_) return -1;\n if (x > o_threshold) return x * Ox1p1023;\n }\n var c = 0.0, t: f64;\n if (hx > 0x3FD62E42) {\n k = select(\n 1 - (sign_ << 1),\n (invln2 * x + builtin_copysign(0.5, x)),\n hx < 0x3FF0A2B2\n );\n t = k;\n let hi = x - t * ln2_hi;\n let lo = t * ln2_lo;\n x = hi - lo;\n c = (hi - x) - lo;\n } else if (hx < 0x3C900000) return x;\n var hfx = 0.5 * x;\n var hxs = x * hfx;\n var r1 = 1.0 + hxs * (Q1 + hxs * (Q2 + hxs * (Q3 + hxs * (Q4 + hxs * Q5))));\n t = 3.0 - r1 * hfx;\n var e = hxs * ((r1 - t) / (6.0 - x * t));\n if (k == 0) return x - (x * e - hxs);\n e = x * (e - c) - c;\n e -= hxs;\n if (k == -1) return 0.5 * (x - e) - 0.5;\n if (k == 1) {\n if (x < -0.25) return -2.0 * (e - (x + 0.5));\n return 1.0 + 2.0 * (x - e);\n }\n u = (0x3FF + k) << 52;\n var twopk = reinterpret(u);\n var y: f64;\n if (k < 0 || k > 56) {\n y = x - e + 1.0;\n if (k == 1024) y = y * 2.0 * Ox1p1023;\n else y = y * twopk;\n return y - 1.0;\n }\n u = (0x3FF - k) << 52;\n y = reinterpret(u);\n if (k < 20) y = (1 - y) - e;\n else y = 1 - (e + y);\n return (x + y) * twopk;\n }\n\n @inline\n export function floor(x: f64): f64 {\n return builtin_floor(x);\n }\n\n @inline\n export function fround(x: f64): f32 {\n return x;\n }\n\n export function hypot(x: f64, y: f64): f64 { // see: musl/src/math/hypot.c\n const\n SPLIT = reinterpret(0x41A0000000000000) + 1, // 0x1p27 + 1\n Ox1p700 = reinterpret(0x6BB0000000000000),\n Ox1p_700 = reinterpret(0x1430000000000000);\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n ux &= 0x7FFFFFFFFFFFFFFF;\n uy &= 0x7FFFFFFFFFFFFFFF;\n if (ux < uy) {\n let ut = ux;\n ux = uy;\n uy = ut;\n }\n var ex = (ux >> 52);\n var ey = (uy >> 52);\n y = reinterpret(uy);\n if (ey == 0x7FF) return y;\n x = reinterpret(ux);\n if (ex == 0x7FF || uy == 0) return x;\n if (ex - ey > 64) return x + y;\n var z = 1.0;\n if (ex > 0x3FF + 510) {\n z = Ox1p700;\n x *= Ox1p_700;\n y *= Ox1p_700;\n } else if (ey < 0x3FF - 450) {\n z = Ox1p_700;\n x *= Ox1p700;\n y *= Ox1p700;\n }\n var c = x * SPLIT;\n var h = x - c + c;\n var l = x - h;\n var hx = x * x;\n var lx = h * h - hx + (2 * h + l) * l;\n c = y * SPLIT;\n h = y - c + c;\n l = y - h;\n var hy = y * y;\n var ly = h * h - hy + (2 * h + l) * l;\n return z * builtin_sqrt(ly + lx + hy + hx);\n }\n\n export function imul(x: f64, y: f64): f64 {\n return (x * y);\n }\n\n export function log(x: f64): f64 { // see: musl/src/math/log.c and SUN COPYRIGHT NOTICE above\n const\n ln2_hi = reinterpret(0x3FE62E42FEE00000), // 6.93147180369123816490e-01\n ln2_lo = reinterpret(0x3DEA39EF35793C76), // 1.90821492927058770002e-10\n Lg1 = reinterpret(0x3FE5555555555593), // 6.666666666666735130e-01\n Lg2 = reinterpret(0x3FD999999997FA04), // 3.999999999940941908e-01\n Lg3 = reinterpret(0x3FD2492494229359), // 2.857142874366239149e-01\n Lg4 = reinterpret(0x3FCC71C51D8E78AF), // 2.222219843214978396e-01\n Lg5 = reinterpret(0x3FC7466496CB03DE), // 1.818357216161805012e-01\n Lg6 = reinterpret(0x3FC39A09D078C69F), // 1.531383769920937332e-01\n Lg7 = reinterpret(0x3FC2F112DF3E5244), // 1.479819860511658591e-01\n Ox1p54 = reinterpret(0x4350000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32);\n var k = 0;\n if (hx < 0x00100000 || (hx >> 31)) {\n if (u << 1 == 0) return -1 / (x * x);\n if (hx >> 31) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = (u >> 32);\n } else if (hx >= 0x7FF00000) return x;\n else if (hx == 0x3FF00000 && u << 32 == 0) return 0;\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += (hx >> 20) - 0x3FF;\n hx = (hx & 0x000FFFFF) + 0x3FE6A09E;\n u = hx << 32 | (u & 0xFFFFFFFF);\n x = reinterpret(u);\n var f = x - 1.0;\n var hfsq = 0.5 * f * f;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n var r = t2 + t1;\n var dk = k;\n return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;\n }\n\n export function log10(x: f64): f64 { // see: musl/src/math/log10.c and SUN COPYRIGHT NOTICE above\n const\n ivln10hi = reinterpret(0x3FDBCB7B15200000), // 4.34294481878168880939e-01\n ivln10lo = reinterpret(0x3DBB9438CA9AADD5), // 2.50829467116452752298e-11\n log10_2hi = reinterpret(0x3FD34413509F6000), // 3.01029995663611771306e-01\n log10_2lo = reinterpret(0x3D59FEF311F12B36), // 3.69423907715893078616e-13\n Lg1 = reinterpret(0x3FE5555555555593), // 6.666666666666735130e-01\n Lg2 = reinterpret(0x3FD999999997FA04), // 3.999999999940941908e-01\n Lg3 = reinterpret(0x3FD2492494229359), // 2.857142874366239149e-01\n Lg4 = reinterpret(0x3FCC71C51D8E78AF), // 2.222219843214978396e-01\n Lg5 = reinterpret(0x3FC7466496CB03DE), // 1.818357216161805012e-01\n Lg6 = reinterpret(0x3FC39A09D078C69F), // 1.531383769920937332e-01\n Lg7 = reinterpret(0x3FC2F112DF3E5244), // 1.479819860511658591e-01\n Ox1p54 = reinterpret(0x4350000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32);\n var k = 0;\n if (hx < 0x00100000 || (hx >> 31)) {\n if (u << 1 == 0) return -1 / (x * x);\n if (hx >> 31) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = (u >> 32);\n } else if (hx >= 0x7FF00000) return x;\n else if (hx == 0x3FF00000 && u << 32 == 0) return 0;\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += (hx >> 20) - 0x3FF;\n hx = (hx & 0x000FFFFF) + 0x3FE6A09E;\n u = hx << 32 | (u & 0xFFFFFFFF);\n x = reinterpret(u);\n var f = x - 1.0;\n var hfsq = 0.5 * f * f;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n var r = t2 + t1;\n var hi = f - hfsq;\n u = reinterpret(hi);\n u &= 0xFFFFFFFF00000000;\n hi = reinterpret(u);\n var lo = f - hi - hfsq + s * (hfsq + r);\n var val_hi = hi * ivln10hi;\n var dk = k;\n var y = dk * log10_2hi;\n var val_lo = dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi;\n w = y + val_hi;\n val_lo += (y - w) + val_hi;\n return val_lo + w;\n }\n\n export function log1p(x: f64): f64 { // see: musl/src/math/log1p.c and SUN COPYRIGHT NOTICE above\n const\n ln2_hi = reinterpret(0x3FE62E42FEE00000), // 6.93147180369123816490e-01\n ln2_lo = reinterpret(0x3DEA39EF35793C76), // 1.90821492927058770002e-10\n Lg1 = reinterpret(0x3FE5555555555593), // 6.666666666666735130e-01\n Lg2 = reinterpret(0x3FD999999997FA04), // 3.999999999940941908e-01\n Lg3 = reinterpret(0x3FD2492494229359), // 2.857142874366239149e-01\n Lg4 = reinterpret(0x3FCC71C51D8E78AF), // 2.222219843214978396e-01\n Lg5 = reinterpret(0x3FC7466496CB03DE), // 1.818357216161805012e-01\n Lg6 = reinterpret(0x3FC39A09D078C69F), // 1.531383769920937332e-01\n Lg7 = reinterpret(0x3FC2F112DF3E5244); // 1.479819860511658591e-01\n var u = reinterpret(x);\n var hx = (u >> 32);\n var k = 1;\n var c = 0.0, f = 0.0;\n if (hx < 0x3FDA827A || (hx >> 31)) {\n if (hx >= 0xBFF00000) {\n if (x == -1) return x / 0.0;\n return (x - x) / 0.0;\n }\n if (hx << 1 < 0x3CA00000 << 1) return x;\n if (hx <= 0xBFD2BEC4) {\n k = 0;\n c = 0;\n f = x;\n }\n } else if (hx >= 0x7FF00000) return x;\n if (k) {\n u = reinterpret(1 + x);\n let hu = (u >> 32);\n hu += 0x3FF00000 - 0x3FE6A09E;\n k = (hu >> 20) - 0x3FF;\n if (k < 54) {\n let uf = reinterpret(u);\n c = k >= 2 ? 1 - (uf - x) : x - (uf - 1);\n c /= uf;\n } else c = 0;\n hu = (hu & 0x000FFFFF) + 0x3FE6A09E;\n u = hu << 32 | (u & 0xFFFFFFFF);\n f = reinterpret(u) - 1;\n }\n var hfsq = 0.5 * f * f;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n var r = t2 + t1;\n var dk = k;\n return s * (hfsq + r) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;\n }\n\n export function log2(x: f64): f64 { // see: musl/src/math/log2.c and SUN COPYRIGHT NOTICE above\n const\n ivln2hi = reinterpret(0x3FF7154765200000), // 1.44269504072144627571e+00\n ivln2lo = reinterpret(0x3DE705FC2EEFA200), // 1.67517131648865118353e-10\n Lg1 = reinterpret(0x3FE5555555555593), // 6.666666666666735130e-01\n Lg2 = reinterpret(0x3FD999999997FA04), // 3.999999999940941908e-01\n Lg3 = reinterpret(0x3FD2492494229359), // 2.857142874366239149e-01\n Lg4 = reinterpret(0x3FCC71C51D8E78AF), // 2.222219843214978396e-01\n Lg5 = reinterpret(0x3FC7466496CB03DE), // 1.818357216161805012e-01\n Lg6 = reinterpret(0x3FC39A09D078C69F), // 1.531383769920937332e-01\n Lg7 = reinterpret(0x3FC2F112DF3E5244), // 1.479819860511658591e-01\n Ox1p54 = reinterpret(0x4350000000000000);\n var u = reinterpret(x);\n var hx = (u >> 32);\n var k = 0;\n if (hx < 0x00100000 || (hx >> 31)) {\n if (u << 1 == 0) return -1 / (x * x);\n if (hx >> 31) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = (u >> 32);\n } else if (hx >= 0x7FF00000) return x;\n else if (hx == 0x3FF00000 && u << 32 == 0) return 0;\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += (hx >> 20) - 0x3FF;\n hx = (hx & 0x000FFFFF) + 0x3FE6A09E;\n u = hx << 32 | (u & 0xFFFFFFFF);\n x = reinterpret(u);\n var f = x - 1.0;\n var hfsq = 0.5 * f * f;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n var t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n var r = t2 + t1;\n var hi = f - hfsq;\n u = reinterpret(hi);\n u &= 0xFFFFFFFF00000000;\n hi = reinterpret(u);\n var lo = f - hi - hfsq + s * (hfsq + r);\n var val_hi = hi * ivln2hi;\n var val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;\n var y = k;\n w = y + val_hi;\n val_lo += (y - w) + val_hi;\n val_hi = w;\n return val_lo + val_hi;\n }\n\n @inline\n export function max(value1: f64, value2: f64): f64 {\n return builtin_max(value1, value2);\n }\n\n @inline\n export function min(value1: f64, value2: f64): f64 {\n return builtin_min(value1, value2);\n }\n\n export function pow(x: f64, y: f64): f64 { // see: musl/src/math/pow.c and SUN COPYRIGHT NOTICE above\n const\n dp_h1 = reinterpret(0x3FE2B80340000000), // 5.84962487220764160156e-01\n dp_l1 = reinterpret(0x3E4CFDEB43CFD006), // 1.35003920212974897128e-08\n two53 = reinterpret(0x4340000000000000), // 9007199254740992.0\n huge = reinterpret(0x7E37E43C8800759C), // 1e+300\n tiny = reinterpret(0x01A56E1FC2F8F359), // 1e-300\n L1 = reinterpret(0x3FE3333333333303), // 5.99999999999994648725e-01\n L2 = reinterpret(0x3FDB6DB6DB6FABFF), // 4.28571428578550184252e-01\n L3 = reinterpret(0x3FD55555518F264D), // 3.33333329818377432918e-01\n L4 = reinterpret(0x3FD17460A91D4101), // 2.72728123808534006489e-01\n L5 = reinterpret(0x3FCD864A93C9DB65), // 2.30660745775561754067e-01\n L6 = reinterpret(0x3FCA7E284A454EEF), // 2.06975017800338417784e-01\n P1 = reinterpret(0x3FC555555555553E), // 1.66666666666666019037e-01\n P2 = reinterpret(0xBF66C16C16BEBD93), // -2.77777777770155933842e-03\n P3 = reinterpret(0x3F11566AAF25DE2C), // 6.61375632143793436117e-05\n P4 = reinterpret(0xBEBBBD41C5D26BF1), // -1.65339022054652515390e-06\n P5 = reinterpret(0x3E66376972BEA4D0), // 4.13813679705723846039e-08\n lg2 = reinterpret(0x3FE62E42FEFA39EF), // 6.93147180559945286227e-01\n lg2_h = reinterpret(0x3FE62E4300000000), // 6.93147182464599609375e-01\n lg2_l = reinterpret(0xBE205C610CA86C39), // -1.90465429995776804525e-09\n ovt = reinterpret(0x3C971547652B82FE), // 8.0085662595372944372e-017\n cp = reinterpret(0x3FEEC709DC3A03FD), // 9.61796693925975554329e-01\n cp_h = reinterpret(0x3FEEC709E0000000), // 9.61796700954437255859e-01\n cp_l = reinterpret(0xBE3E2FE0145B01F5), // -7.02846165095275826516e-09\n ivln2 = reinterpret(0x3FF71547652B82FE), // 1.44269504088896338700e+00\n ivln2_h = reinterpret(0x3FF7154760000000), // 1.44269502162933349609e+00\n ivln2_l = reinterpret(0x3E54AE0BF85DDF44), // 1.92596299112661746887e-08\n inv3 = reinterpret(0x3FD5555555555555); // 0.3333333333333333333333\n var u_ = reinterpret(x);\n var hx = (u_ >> 32);\n var lx = u_;\n u_ = reinterpret(y);\n var hy = (u_ >> 32);\n var ly = u_;\n var ix = hx & 0x7FFFFFFF;\n var iy = hy & 0x7FFFFFFF;\n if ((iy | ly) == 0) return 1.0; // x**0 = 1, even if x is NaN\n // if (hx == 0x3FF00000 && lx == 0) return 1.0; // C: 1**y = 1, even if y is NaN, JS: NaN\n if ( // NaN if either arg is NaN\n ix > 0x7FF00000 || (ix == 0x7FF00000 && lx != 0) ||\n iy > 0x7FF00000 || (iy == 0x7FF00000 && ly != 0)\n ) return x + y;\n var yisint = 0, k: i32;\n if (hx < 0) {\n if (iy >= 0x43400000) yisint = 2;\n else if (iy >= 0x3FF00000) {\n k = (iy >> 20) - 0x3FF;\n let offset = select(52, 20, k > 20) - k;\n let Ly = select(ly, iy, k > 20);\n let jj = Ly >> offset;\n if ((jj << offset) == Ly) yisint = 2 - (jj & 1);\n }\n }\n if (ly == 0) {\n if (iy == 0x7FF00000) { // y is +-inf\n if (((ix - 0x3FF00000) | lx) == 0) return NaN; // C: (-1)**+-inf is 1, JS: NaN\n else if (ix >= 0x3FF00000) return hy >= 0 ? y : 0.0; // (|x|>1)**+-inf = inf,0\n else return hy >= 0 ? 0.0 : -y; // (|x|<1)**+-inf = 0,inf\n }\n if (iy == 0x3FF00000) {\n if (hy >= 0) return x;\n return 1 / x;\n }\n if (hy == 0x40000000) return x * x;\n if (hy == 0x3FE00000) {\n if (hx >= 0) return builtin_sqrt(x);\n }\n }\n var ax = builtin_abs(x), z: f64;\n if (lx == 0) {\n if (ix == 0x7FF00000 || ix == 0 || ix == 0x3FF00000) {\n z = ax;\n if (hy < 0) z = 1.0 / z;\n if (hx < 0) {\n if (((ix - 0x3FF00000) | yisint) == 0) z = (z - z) / (z - z);\n else if (yisint == 1) z = -z;\n }\n return z;\n }\n }\n var s = 1.0;\n if (hx < 0) {\n if (yisint == 0) return (x - x) / (x - x);\n if (yisint == 1) s = -1.0;\n }\n var t1: f64, t2: f64, p_h: f64, p_l: f64, r: f64, t: f64, u: f64, v: f64, w: f64;\n var j: i32, n: i32;\n if (iy > 0x41E00000) {\n if (iy > 0x43F00000) {\n if (ix <= 0x3FEFFFFF) return hy < 0 ? huge * huge : tiny * tiny;\n if (ix >= 0x3FF00000) return hy > 0 ? huge * huge : tiny * tiny;\n }\n if (ix < 0x3FEFFFFF) return hy < 0 ? s * huge * huge : s * tiny * tiny;\n if (ix > 0x3FF00000) return hy > 0 ? s * huge * huge : s * tiny * tiny;\n t = ax - 1.0;\n w = (t * t) * (0.5 - t * (inv3 - t * 0.25));\n u = ivln2_h * t;\n v = t * ivln2_l - w * ivln2;\n t1 = u + v;\n t1 = reinterpret(reinterpret(t1) & 0xFFFFFFFF00000000);\n t2 = v - (t1 - u);\n } else {\n let ss: f64, s2: f64, s_h: f64, s_l: f64, t_h: f64, t_l: f64;\n n = 0;\n if (ix < 0x00100000) {\n ax *= two53;\n n -= 53;\n ix = (reinterpret(ax) >> 32);\n }\n n += (ix >> 20) - 0x3FF;\n j = ix & 0x000FFFFF;\n ix = j | 0x3FF00000;\n if (j <= 0x3988E) k = 0;\n else if (j < 0xBB67A) k = 1;\n else {\n k = 0;\n n += 1;\n ix -= 0x00100000;\n }\n ax = reinterpret(reinterpret(ax) & 0xFFFFFFFF | (ix << 32));\n let bp = select(1.5, 1.0, k); // k ? 1.5 : 1.0\n u = ax - bp;\n v = 1.0 / (ax + bp);\n ss = u * v;\n s_h = ss;\n s_h = reinterpret(reinterpret(s_h) & 0xFFFFFFFF00000000);\n t_h = reinterpret((((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18)) << 32);\n t_l = ax - (t_h - bp);\n s_l = v * ((u - s_h * t_h) - s_h * t_l);\n s2 = ss * ss;\n r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));\n r += s_l * (s_h + ss);\n s2 = s_h * s_h;\n t_h = 3.0 + s2 + r;\n t_h = reinterpret(reinterpret(t_h) & 0xFFFFFFFF00000000);\n t_l = r - ((t_h - 3.0) - s2);\n u = s_h * t_h;\n v = s_l * t_h + t_l * ss;\n p_h = u + v;\n p_h = reinterpret(reinterpret(p_h) & 0xFFFFFFFF00000000);\n p_l = v - (p_h - u);\n let z_h = cp_h * p_h;\n let dp_l = select(dp_l1, 0.0, k);\n let z_l = cp_l * p_h + p_l * cp + dp_l;\n t = n;\n let dp_h = select(dp_h1, 0.0, k);\n t1 = ((z_h + z_l) + dp_h) + t;\n t1 = reinterpret(reinterpret(t1) & 0xFFFFFFFF00000000);\n t2 = z_l - (((t1 - t) - dp_h) - z_h);\n }\n var y1 = y;\n y1 = reinterpret(reinterpret(y1) & 0xFFFFFFFF00000000);\n p_l = (y - y1) * t1 + y * t2;\n p_h = y1 * t1;\n z = p_l + p_h;\n u_ = reinterpret(z);\n j = (u_ >> 32);\n var i = u_;\n if (j >= 0x40900000) {\n if (((j - 0x40900000) | i) != 0) return s * huge * huge;\n if (p_l + ovt > z - p_h) return s * huge * huge;\n } else if ((j & 0x7FFFFFFF) >= 0x4090CC00) {\n if (((j - 0xC090CC00) | i) != 0) return s * tiny * tiny;\n if (p_l <= z - p_h) return s * tiny * tiny;\n }\n i = j & 0x7FFFFFFF;\n k = (i >> 20) - 0x3FF;\n n = 0;\n if (i > 0x3FE00000) {\n n = j + (0x00100000 >> (k + 1));\n k = ((n & 0x7FFFFFFF) >> 20) - 0x3FF;\n t = 0.0;\n t = reinterpret((n & ~(0x000FFFFF >> k)) << 32);\n n = ((n & 0x000FFFFF) | 0x00100000) >> (20 - k);\n if (j < 0) n = -n;\n p_h -= t;\n }\n t = p_l + p_h;\n t = reinterpret(reinterpret(t) & 0xFFFFFFFF00000000);\n u = t * lg2_h;\n v = (p_l - (t - p_h)) * lg2 + t * lg2_l;\n z = u + v;\n w = v - (z - u);\n t = z * z;\n t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));\n r = (z * t1) / (t1 - 2.0) - (w + z * w);\n z = 1.0 - (r - z);\n j = (reinterpret(z) >> 32);\n j += n << 20;\n if ((j >> 20) <= 0) z = scalbn(z, n);\n else z = reinterpret(reinterpret(z) & 0xFFFFFFFF | (j << 32));\n return s * z;\n }\n\n export function seedRandom(value: i64): void {\n assert(value);\n random_seeded = true;\n random_state0_64 = murmurHash3(value);\n random_state1_64 = murmurHash3(~random_state0_64);\n random_state0_32 = splitMix32(value);\n random_state1_32 = splitMix32(random_state0_32);\n }\n\n export function random(): f64 { // see: v8/src/base/random-number-generator.cc\n if (!random_seeded) throw new Error("PRNG must be seeded.");\n var s1 = random_state0_64;\n var s0 = random_state1_64;\n random_state0_64 = s0;\n s1 ^= s1 << 23;\n s1 ^= s1 >> 17;\n s1 ^= s0;\n s1 ^= s0 >> 26;\n random_state1_64 = s1;\n var r = ((s0 + s1) & 0x000FFFFFFFFFFFFF) | 0x3FF0000000000000;\n return reinterpret(r) - 1;\n }\n\n @inline\n export function round(x: f64): f64 {\n return builtin_copysign(builtin_floor(x + 0.5), x);\n }\n\n @inline\n export function sign(x: f64): f64 {\n if (ASC_SHRINK_LEVEL > 0) {\n return builtin_abs(x) > 0 ? builtin_copysign(1, x) : x;\n } else {\n return x > 0 ? 1 : x < 0 ? -1 : x;\n }\n }\n\n export function sin(x: f64): f64 { // TODO\n unreachable();\n return 0;\n }\n\n export function sinh(x: f64): f64 { // see: musl/src/math/sinh.c\n var u = reinterpret(x) & 0x7FFFFFFFFFFFFFFF;\n var absx = reinterpret(u);\n var w = (u >> 32);\n var t: f64;\n var h = builtin_copysign(0.5, x);\n if (w < 0x40862E42) {\n t = expm1(absx);\n if (w < 0x3FF00000) {\n if (w < 0x3FF00000 - (26 << 20)) return x;\n return h * (2 * t - t * t / (t + 1));\n }\n return h * (t + t / (t + 1));\n }\n t = 2 * h * expo2(absx);\n return t;\n }\n\n @inline\n export function sqrt(x: f64): f64 {\n return builtin_sqrt(x);\n }\n\n export function tan(x: f64): f64 { // TODO\n unreachable();\n return 0;\n }\n\n export function tanh(x: f64): f64 { // see: musl/src/math/tanh.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFFFFFFFFFF;\n var y = reinterpret(u);\n var w = (u >> 32);\n var t: f64;\n if (w > 0x3FE193EA) {\n if (w > 0x40340000) {\n t = 1 - 0 / y;\n } else {\n t = expm1(2 * y);\n t = 1 - 2 / (t + 2);\n }\n } else if (w > 0x3FD058AE) {\n t = expm1(2 * y);\n t = t / (t + 2);\n } else if (w >= 0x00100000) {\n t = expm1(-2 * y);\n t = -t / (t + 2);\n } else t = y;\n return builtin_copysign(t, x);\n }\n\n @inline\n export function trunc(x: f64): f64 {\n return builtin_trunc(x);\n }\n\n /** @internal */\n export function scalbn(x: f64, n: i32): f64 { // see: https://git.musl-libc.org/cgit/musl/tree/src/math/scalbn.c\n const\n Ox1p53 = reinterpret(0x4340000000000000),\n Ox1p1023 = reinterpret(0x7FE0000000000000),\n Ox1p_1022 = reinterpret(0x0010000000000000);\n var y = x;\n if (n > 1023) {\n y *= Ox1p1023;\n n -= 1023;\n if (n > 1023) {\n y *= Ox1p1023;\n n = builtin_min(n - 1023, 1023);\n }\n } else if (n < -1022) {\n /* make sure final n < -53 to avoid double\n\t\t rounding in the subnormal range */\n y *= Ox1p_1022 * Ox1p53;\n n += 1022 - 53;\n if (n < -1022) {\n y *= Ox1p_1022 * Ox1p53;\n n = builtin_max(n + 1022 - 53, -1022);\n }\n }\n return y * reinterpret((0x3FF + n) << 52);\n }\n\n export function mod(x: f64, y: f64): f64 { // see: musl/src/math/fmod.c\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = (ux >> 52 & 0x7FF);\n var ey = (uy >> 52 & 0x7FF);\n var sx = ux >> 63;\n var uy1 = uy << 1;\n if (uy1 == 0 || ex == 0x7FF || isNaN(y)) return (x * y) / (x * y);\n var ux1 = ux << 1;\n if (ux1 <= uy1) {\n if (ux1 == uy1) return 0 * x;\n return x;\n }\n if (!ex) {\n ex -= builtin_clz(ux << 12);\n ux <<= -ex + 1;\n } else {\n ux &= -1 >> 12;\n ux |= 1 << 52;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 12);\n uy <<= -ey + 1;\n } else {\n uy &= -1 >> 12;\n uy |= 1 << 52;\n }\n while (ex > ey) {\n if (ux >= uy) {\n if (ux == uy) return 0 * x;\n ux -= uy;\n }\n ux <<= 1;\n --ex;\n }\n if (ux >= uy) {\n if (ux == uy) return 0 * x;\n ux -= uy;\n }\n // for (; !(ux >> 52); ux <<= 1) --ex;\n var shift = builtin_clz(ux << 11);\n ex -= shift;\n ux <<= shift;\n if (ex > 0) {\n ux -= 1 << 52;\n ux |= ex << 52;\n } else {\n ux >>= -ex + 1;\n }\n ux |= sx << 63;\n return reinterpret(ux);\n }\n\n export function rem(x: f64, y: f64): f64 { // see: musl/src/math/remquo.c\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = (ux >> 52 & 0x7FF);\n var ey = (uy >> 52 & 0x7FF);\n var sx = (ux >> 63);\n if (uy << 1 == 0 || ex == 0x7FF || isNaN(y)) return (x * y) / (x * y);\n if (ux << 1 == 0) return x;\n var uxi = ux;\n if (!ex) {\n ex -= builtin_clz(uxi << 12);\n uxi <<= -ex + 1;\n } else {\n uxi &= -1 >> 12;\n uxi |= 1 << 52;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 12);\n uy <<= -ey + 1;\n } else {\n uy &= -1 >> 12;\n uy |= 1 << 52;\n }\n var q: u32 = 0;\n do {\n if (ex < ey) {\n if (ex + 1 == ey) break; // goto end\n return x;\n }\n while (ex > ey) {\n if (uxi >= uy) {\n uxi -= uy;\n ++q;\n }\n uxi <<= 1;\n q <<= 1;\n --ex;\n }\n if (uxi >= uy) {\n uxi -= uy;\n ++q;\n }\n if (uxi == 0) ex = -60;\n else {\n let shift = builtin_clz(uxi << 11);\n ex -= shift;\n uxi <<= shift;\n }\n break;\n } while (false);\n // end:\n if (ex > 0) {\n uxi -= 1 << 52;\n uxi |= ex << 52;\n } else {\n uxi >>= -ex + 1;\n }\n x = reinterpret(uxi);\n y = builtin_abs(y);\n var x2 = x + x;\n if (ex == ey || (ex + 1 == ey && (x2 > y || (x2 == y && (q & 1))))) {\n x -= y;\n // ++q;\n }\n return sx ? -x : x;\n }\n}\n\n/** @internal */\nfunction Rf(z: f32): f32 { // Rational approximation of (asin(x)-x)/x^3\n const // see: musl/src/math/asinf.c and SUN COPYRIGHT NOTICE above\n pS0 = reinterpret(0x3E2AAA75), // 1.6666586697e-01f\n pS1 = reinterpret(0xBD2F13BA), // -4.2743422091e-02f\n pS2 = reinterpret(0xBC0DD36B), // -8.6563630030e-03f\n qS1 = reinterpret(0xBF34E5AE); // -7.0662963390e-01f\n var p = z * (pS0 + z * (pS1 + z * pS2));\n var q: f32 = 1 + z * qS1;\n return p / q;\n}\n\n@inline /** @internal */\nfunction expo2f(x: f32): f32 { // exp(x)/2 for x >= log(DBL_MAX)\n const // see: musl/src/math/__expo2f.c\n k = 235,\n kln2 = reinterpret(0x4322E3BC); // 0x1.45c778p+7f\n var scale = reinterpret((0x7F + k / 2) << 23);\n return NativeMathf.exp(x - kln2) * scale * scale;\n}\n\nexport namespace NativeMathf {\n\n export const E = NativeMath.E;\n export const LN2 = NativeMath.LN2;\n export const LN10 = NativeMath.LN10;\n export const LOG2E = NativeMath.LOG2E;\n export const LOG10E = NativeMath.LOG10E;\n export const PI = NativeMath.PI;\n export const SQRT1_2 = NativeMath.SQRT1_2;\n export const SQRT2 = NativeMath.SQRT2;\n\n @inline\n export function abs(x: f32): f32 {\n return builtin_abs(x);\n }\n\n export function acos(x: f32): f32 { // see: musl/src/math/acosf.c and SUN COPYRIGHT NOTICE above\n const\n pio2_hi = reinterpret(0x3FC90FDA), // 1.5707962513e+00f\n pio2_lo = reinterpret(0x33A22168), // 7.5497894159e-08f\n Ox1p_120f = reinterpret(0x03800000);\n var hx = reinterpret(x);\n var ix = hx & 0x7FFFFFFF;\n if (ix >= 0x3F800000) {\n if (ix == 0x3F800000) {\n if (hx >> 31) return 2 * pio2_hi + Ox1p_120f;\n return 0;\n }\n return 0 / (x - x);\n }\n if (ix < 0x3F000000) {\n if (ix <= 0x32800000) return pio2_hi + Ox1p_120f;\n return pio2_hi - (x - (pio2_lo - x * Rf(x * x)));\n }\n var z: f32, w: f32, s: f32;\n if (hx >> 31) {\n // z = (1 + x) * 0.5;\n z = 0.5 + x * 0.5;\n s = builtin_sqrt(z);\n w = Rf(z) * s - pio2_lo;\n return 2 * (pio2_hi - (s + w));\n }\n // z = (1 - x) * 0.5;\n z = 0.5 - x * 0.5;\n s = builtin_sqrt(z);\n hx = reinterpret(s);\n var df = reinterpret(hx & 0xFFFFF000);\n var c = (z - df * df) / (s + df);\n w = Rf(z) * s + c;\n return 2 * (df + w);\n }\n\n export function acosh(x: f32): f32 { // see: musl/src/math/acoshf.c\n const s = reinterpret(0x3F317218); // 0.693147180559945309417232121458176568f\n var u = reinterpret(x);\n var a = u & 0x7FFFFFFF;\n if (a < 0x3F800000 + (1 << 23)) {\n let xm1 = x - 1;\n return log1p(xm1 + builtin_sqrt(xm1 * (xm1 + 2)));\n }\n if (a < 0x3F800000 + (12 << 23)) return log(2 * x - 1 / (x + builtin_sqrt(x * x - 1)));\n return log(x) + s;\n }\n\n export function asin(x: f32): f32 { // see: musl/src/math/asinf.c and SUN COPYRIGHT NOTICE above\n const\n pio2 = reinterpret(0x3FC90FDB), // 1.570796326794896558e+00f\n Ox1p_120f = reinterpret(0x03800000);\n var sx = x;\n var hx = reinterpret(x) & 0x7FFFFFFF;\n if (hx >= 0x3F800000) {\n if (hx == 0x3F800000) return x * pio2 + Ox1p_120f;\n return 0 / (x - x);\n }\n if (hx < 0x3F000000) {\n if (hx < 0x39800000 && hx >= 0x00800000) return x;\n return x + x * Rf(x * x);\n }\n // var z: f32 = (1 - builtin_abs(x)) * 0.5;\n var z: f32 = 0.5 - builtin_abs(x) * 0.5;\n var s = builtin_sqrt(z); // sic\n x = (pio2 - 2 * (s + s * Rf(z)));\n return builtin_copysign(x, sx);\n }\n\n export function asinh(x: f32): f32 { // see: musl/src/math/asinhf.c\n const c = reinterpret(0x3F317218); // 0.693147180559945309417232121458176568f\n var u = reinterpret(x) & 0x7FFFFFFF;\n var y = reinterpret(u);\n if (u >= 0x3F800000 + (12 << 23)) y = log(y) + c;\n else if (u >= 0x3F800000 + (1 << 23)) y = log(2 * y + 1 / (builtin_sqrt(y * y + 1) + y));\n else if (u >= 0x3F800000 - (12 << 23)) y = log1p(y + y * y / (builtin_sqrt(y * y + 1) + 1));\n return builtin_copysign(y, x);\n }\n\n export function atan(x: f32): f32 { // see: musl/src/math/atanf.c and SUN COPYRIGHT NOTICE above\n const\n atanhi0 = reinterpret(0x3EED6338), // 4.6364760399e-01f\n atanhi1 = reinterpret(0x3F490FDA), // 7.8539812565e-01f\n atanhi2 = reinterpret(0x3F7B985E), // 9.8279368877e-01f\n atanhi3 = reinterpret(0x3FC90FDA), // 1.5707962513e+00f\n atanlo0 = reinterpret(0x31AC3769), // 5.0121582440e-09f\n atanlo1 = reinterpret(0x33222168), // 3.7748947079e-08f\n atanlo2 = reinterpret(0x33140FB4), // 3.4473217170e-08f\n atanlo3 = reinterpret(0x33A22168), // 7.5497894159e-08f\n aT0 = reinterpret(0x3EAAAAA9), // 3.3333328366e-01f\n aT1 = reinterpret(0xBE4CCA98), // -1.9999158382e-01f\n aT2 = reinterpret(0x3E11F50D), // 1.4253635705e-01f\n aT3 = reinterpret(0xBDDA1247), // -1.0648017377e-01f\n aT4 = reinterpret(0x3D7CAC25), // 6.1687607318e-02f\n Ox1p_120f = reinterpret(0x03800000);\n var ix = reinterpret(x);\n var sx = x;\n ix &= 0x7FFFFFFF;\n var z: f32;\n if (ix >= 0x4C800000) {\n if (isNaN(x)) return x;\n z = atanhi3 + Ox1p_120f;\n return builtin_copysign(z, sx);\n }\n var id: i32;\n if (ix < 0x3EE00000) {\n if (ix < 0x39800000) return x;\n id = -1;\n } else {\n x = builtin_abs(x);\n if (ix < 0x3F980000) {\n if (ix < 0x3F300000) {\n id = 0;\n x = (2.0 * x - 1.0) / (2.0 + x);\n } else {\n id = 1;\n x = (x - 1.0) / (x + 1.0);\n }\n } else {\n if (ix < 0x401C0000) {\n id = 2;\n x = (x - 1.5) / (1.0 + 1.5 * x);\n } else {\n id = 3;\n x = -1.0 / x;\n }\n }\n }\n z = x * x;\n var w = z * z;\n var s1 = z * (aT0 + w * (aT2 + w * aT4));\n var s2 = w * (aT1 + w * aT3);\n var s3 = x * (s1 + s2);\n if (id < 0) return x - s3;\n switch (id) {\n case 0: { z = atanhi0 - ((s3 - atanlo0) - x); break; }\n case 1: { z = atanhi1 - ((s3 - atanlo1) - x); break; }\n case 2: { z = atanhi2 - ((s3 - atanlo2) - x); break; }\n case 3: { z = atanhi3 - ((s3 - atanlo3) - x); break; }\n default: unreachable();\n }\n return builtin_copysign(z, sx);\n }\n\n export function atanh(x: f32): f32 { // see: musl/src/math/atanhf.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFF;\n var y = reinterpret(u);\n if (u < 0x3F800000 - (1 << 23)) {\n if (u >= 0x3F800000 - (32 << 23)) y = 0.5 * log1p(2 * y * (1.0 + y / (1 - y)));\n } else y = 0.5 * log1p(2 * (y / (1 - y)));\n return builtin_copysign(y, x);\n }\n\n export function atan2(y: f32, x: f32): f32 { // see: musl/src/math/atan2f.c and SUN COPYRIGHT NOTICE above\n const\n pi = reinterpret(0x40490FDB), // 3.1415927410e+00f\n pi_lo = reinterpret(0xB3BBBD2E); // -8.7422776573e-08f\n if (isNaN(x) || isNaN(y)) return x + y;\n var ix = reinterpret(x);\n var iy = reinterpret(y);\n if (ix == 0x3F800000) return atan(y);\n var m = (((iy >> 31) & 1) | ((ix >> 30) & 2));\n ix &= 0x7FFFFFFF;\n iy &= 0x7FFFFFFF;\n if (iy == 0) {\n switch (m) {\n case 0:\n case 1: return y;\n case 2: return pi;\n case 3: return -pi;\n }\n }\n if (ix == 0) return m & 1 ? -pi / 2 : pi / 2;\n if (ix == 0x7F800000) {\n if (iy == 0x7F800000) {\n switch (m) {\n case 0: return pi / 4;\n case 1: return -pi / 4;\n case 2: return 3 * pi / 4;\n case 3: return -3 * pi / 4;\n }\n } else {\n switch (m) {\n case 0: return 0;\n case 1: return -0;\n case 2: return pi;\n case 3: return -pi;\n }\n }\n }\n if (ix + (26 << 23) < iy || iy == 0x7F800000) return m & 1 ? -pi / 2 : pi / 2;\n var z: f32;\n if ((m & 2) && iy + (26 << 23) < ix) z = 0.0;\n else z = atan(builtin_abs(y / x));\n switch (m) {\n case 0: return z;\n case 1: return -z;\n case 2: return pi - (z - pi_lo);\n case 3: return (z - pi_lo) - pi;\n }\n unreachable();\n return 0;\n }\n\n export function cbrt(x: f32): f32 { // see: musl/src/math/cbrtf.c and SUN COPYRIGHT NOTICE above\n const\n B1 = 709958130,\n B2 = 642849266,\n Ox1p24f = reinterpret(0x4B800000);\n var u = reinterpret(x);\n var hx = u & 0x7FFFFFFF;\n if (hx >= 0x7F800000) return x + x;\n if (hx < 0x00800000) {\n if (hx == 0) return x;\n u = reinterpret(x * Ox1p24f);\n hx = u & 0x7FFFFFFF;\n hx = hx / 3 + B2;\n } else {\n hx = hx / 3 + B1;\n }\n u &= 0x80000000;\n u |= hx;\n var t = reinterpret(u);\n var r = t * t * t;\n t = t * (x + x + r) / (x + r + r);\n r = t * t * t;\n t = t * (x + x + r) / (x + r + r);\n return t;\n }\n\n @inline\n export function ceil(x: f32): f32 {\n return builtin_ceil(x);\n }\n\n @inline\n export function clz32(x: f32): f32 {\n return builtin_clz(x);\n }\n\n export function cos(x: f32): f32 { // TODO\n unreachable();\n return 0;\n }\n\n export function cosh(x: f32): f32 { // see: musl/src/math/coshf.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFF;\n x = reinterpret(u);\n if (u < 0x3F317217) {\n if (u < 0x3F800000 - (12 << 23)) return 1;\n let t = expm1(x);\n // return 1 + t * t / (2 * (1 + t));\n return 1 + t * t / (2 + 2 * t);\n }\n if (u < 0x42B17217) {\n let t = exp(x);\n // return 0.5 * (t + 1 / t);\n return 0.5 * t + 0.5 / t;\n }\n return expo2f(x);\n }\n\n @inline\n export function floor(x: f32): f32 {\n return builtin_floor(x);\n }\n\n export function exp(x: f32): f32 { // see: musl/src/math/expf.c and SUN COPYRIGHT NOTICE above\n const\n ln2hi = reinterpret(0x3F317200), // 6.9314575195e-1f\n ln2lo = reinterpret(0x35BFBE8E), // 1.4286067653e-6f\n invln2 = reinterpret(0x3FB8AA3B), // 1.4426950216e+0f\n P1 = reinterpret(0x3E2AAA8F), // 1.6666625440e-1f\n P2 = reinterpret(0xBB355215), // -2.7667332906e-3f\n Ox1p127f = reinterpret(0x7F000000);\n var hx = reinterpret(x);\n var sign_ = (hx >> 31);\n hx &= 0x7FFFFFFF;\n if (hx >= 0x42AEAC50) {\n if (hx >= 0x42B17218) {\n if (!sign_) {\n x *= Ox1p127f;\n return x;\n } else {\n if (hx >= 0x42CFF1B5) return 0;\n }\n }\n }\n var hi: f32, lo: f32;\n var k: i32;\n if (hx > 0x3EB17218) {\n if (hx > 0x3F851592) {\n k = (invln2 * x + builtin_copysign(0.5, x));\n } else {\n k = 1 - (sign_ << 1);\n }\n hi = x - k * ln2hi;\n lo = k * ln2lo;\n x = hi - lo;\n } else if (hx > 0x39000000) {\n k = 0;\n hi = x;\n lo = 0;\n } else {\n return 1 + x;\n }\n var xx = x * x;\n var c = x - xx * (P1 + xx * P2);\n var y: f32 = 1 + (x * c / (2 - c) - lo + hi);\n if (k == 0) return y;\n return scalbn(y, k);\n }\n\n export function expm1(x: f32): f32 { // see: musl/src/math/expm1f.c and SUN COPYRIGHT NOTICE above\n const\n o_threshold = reinterpret(0x42B17180), // 8.8721679688e+01f\n ln2_hi = reinterpret(0x3F317180), // 6.9313812256e-01f\n ln2_lo = reinterpret(0x3717F7D1), // 9.0580006145e-06f\n invln2 = reinterpret(0x3FB8AA3B), // 1.4426950216e+00f\n Q1 = reinterpret(0xBD088868), // -3.3333212137e-02f\n Q2 = reinterpret(0x3ACF3010), // 1.5807170421e-03f\n Ox1p127f = reinterpret(0x7F000000);\n var u = reinterpret(x);\n var hx = u & 0x7FFFFFFF;\n var sign_ = (u >> 31);\n if (hx >= 0x4195B844) {\n if (hx > 0x7F800000) return x;\n if (sign_) return -1;\n if (x > o_threshold) {\n x *= Ox1p127f;\n return x;\n }\n }\n var c: f32 = 0.0, t: f32, k: i32;\n if (hx > 0x3EB17218) {\n k = select(\n 1 - (sign_ << 1),\n (invln2 * x + builtin_copysign(0.5, x)),\n hx < 0x3F851592\n );\n t = k;\n let hi = x - t * ln2_hi;\n let lo = t * ln2_lo;\n x = hi - lo;\n c = (hi - x) - lo;\n } else if (hx < 0x33000000) {\n return x;\n } else k = 0;\n var hfx: f32 = 0.5 * x;\n var hxs: f32 = x * hfx;\n var r1: f32 = 1.0 + hxs * (Q1 + hxs * Q2);\n t = 3.0 - r1 * hfx;\n var e = hxs * ((r1 - t) / (6.0 - x * t));\n if (k == 0) return x - (x * e - hxs);\n e = x * (e - c) - c;\n e -= hxs;\n if (k == -1) return 0.5 * (x - e) - 0.5;\n if (k == 1) {\n if (x < -0.25) return -2.0 * (e - (x + 0.5));\n return 1.0 + 2.0 * (x - e);\n }\n u = (0x7F + k) << 23;\n var twopk = reinterpret(u);\n var y: f32;\n if (k < 0 || k > 56) {\n y = x - e + 1.0;\n if (k == 128) y = y * 2.0 * Ox1p127f;\n else y = y * twopk;\n return y - 1.0;\n }\n u = (0x7F - k) << 23;\n y = reinterpret(u);\n if (k < 20) y = (1 - y) - e;\n else y = 1 - (e + y);\n return (x + y) * twopk;\n }\n\n @inline\n export function fround(x: f32): f32 {\n return x;\n }\n\n export function hypot(x: f32, y: f32): f32 { // see: musl/src/math/hypotf.c\n const\n Ox1p90f = reinterpret(0x6C800000),\n Ox1p_90f = reinterpret(0x12800000);\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n ux &= 0x7FFFFFFF;\n uy &= 0x7FFFFFFF;\n if (ux < uy) {\n let ut = ux;\n ux = uy;\n uy = ut;\n }\n x = reinterpret(ux);\n y = reinterpret(uy);\n if (uy == 0xFF << 23) return y;\n if (ux >= 0xFF << 23 || uy == 0 || ux - uy >= 25 << 23) return x + y;\n var z: f32 = 1;\n if (ux >= (0x7F + 60) << 23) {\n z = Ox1p90f;\n x *= Ox1p_90f;\n y *= Ox1p_90f;\n } else if (uy < (0x7F - 60) << 23) {\n z = Ox1p_90f;\n x *= Ox1p90f;\n y *= Ox1p90f;\n }\n return z * builtin_sqrt((x * x + y * y));\n }\n\n @inline\n export function imul(x: f32, y: f32): f32 {\n return (x * y);\n }\n\n export function log(x: f32): f32 { // see: musl/src/math/logf.c and SUN COPYRIGHT NOTICE above\n const\n ln2_hi = reinterpret(0x3F317180), // 6.9313812256e-01f\n ln2_lo = reinterpret(0x3717F7D1), // 9.0580006145e-06f\n Lg1 = reinterpret(0x3F2AAAAA), // 0xaaaaaa.0p-24f\n Lg2 = reinterpret(0x3ECCCE13), // 0xccce13.0p-25f\n Lg3 = reinterpret(0x3E91E9EE), // 0x91e9ee.0p-25f\n Lg4 = reinterpret(0x3E789E26), // 0xf89e26.0p-26f\n Ox1p25f = reinterpret(0x4C000000);\n var u = reinterpret(x);\n var k = 0;\n if (u < 0x00800000 || (u >> 31)) {\n if (u << 1 == 0) return -1 / (x * x);\n if (u >> 31) return (x - x) / 0;\n k -= 25;\n x *= Ox1p25f;\n u = reinterpret(x);\n } else if (u >= 0x7F800000) return x;\n else if (u == 0x3F800000) return 0;\n u += 0x3F800000 - 0x3F3504F3;\n k += (u >> 23) - 0x7F;\n u = (u & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(u);\n var f = x - 1.0;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * Lg4);\n var t2 = z * (Lg1 + w * Lg3);\n var r = t2 + t1;\n var hfsq = 0.5 * f * f;\n var dk = k;\n return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;\n }\n\n export function log10(x: f32): f32 { // see: musl/src/math/log10f.c and SUN COPYRIGHT NOTICE above\n const\n ivln10hi = reinterpret(0x3EDE6000), // 4.3432617188e-01f\n ivln10lo = reinterpret(0xB804EAD9), // -3.1689971365e-05f\n log10_2hi = reinterpret(0x3E9A2080), // 3.0102920532e-01f\n log10_2lo = reinterpret(0x355427DB), // 7.9034151668e-07f\n Lg1 = reinterpret(0x3F2AAAAA), // 0xaaaaaa.0p-24f, 0.66666662693f\n Lg2 = reinterpret(0x3ECCCE13), // 0xccce13.0p-25f, 0.40000972152f\n Lg3 = reinterpret(0x3E91E9EE), // 0x91e9ee.0p-25f, 0.28498786688f\n Lg4 = reinterpret(0x3E789E26), // 0xf89e26.0p-26f, 0.24279078841f\n Ox1p25f = reinterpret(0x4C000000);\n var ix = reinterpret(x);\n var k = 0;\n if (ix < 0x00800000 || (ix >> 31)) {\n if (ix << 1 == 0) return -1 / (x * x);\n if (ix >> 31) return (x - x) / 0.0;\n k -= 25;\n x *= Ox1p25f;\n ix = reinterpret(x);\n } else if (ix >= 0x7F800000) return x;\n else if (ix == 0x3F800000) return 0;\n ix += 0x3F800000 - 0x3F3504F3;\n k += (ix >> 23) - 0x7F;\n ix = (ix & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(ix);\n var f = x - 1.0;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * Lg4);\n var t2 = z * (Lg1 + w * Lg3);\n var r = t2 + t1;\n var hfsq: f32 = 0.5 * f * f;\n var hi = f - hfsq;\n ix = reinterpret(hi);\n ix &= 0xFFFFF000;\n hi = reinterpret(ix);\n var lo = f - hi - hfsq + s * (hfsq + r);\n var dk = k;\n return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;\n }\n\n export function log1p(x: f32): f32 { // see: musl/src/math/log1pf.c and SUN COPYRIGHT NOTICE above\n const\n ln2_hi = reinterpret(0x3F317180), // 6.9313812256e-01\n ln2_lo = reinterpret(0x3717F7D1), // 9.0580006145e-06\n Lg1 = reinterpret(0x3F2AAAAA), // 0xaaaaaa.0p-24f, 0.66666662693f\n Lg2 = reinterpret(0x3ECCCE13), // 0xccce13.0p-25f, 0.40000972152f\n Lg3 = reinterpret(0x3E91E9EE), // 0x91e9ee.0p-25f, 0.28498786688f\n Lg4 = reinterpret(0x3E789E26); // 0xf89e26.0p-26f, 0.24279078841f\n var ix = reinterpret(x);\n var c: f32 = 0, f: f32 = 0;\n var k: i32 = 1;\n if (ix < 0x3ED413D0 || (ix >> 31)) {\n if (ix >= 0xBF800000) {\n if (x == -1) return x / 0.0;\n return (x - x) / 0.0;\n }\n if (ix << 1 < 0x33800000 << 1) return x;\n if (ix <= 0xBE95F619) {\n k = 0;\n c = 0;\n f = x;\n }\n } else if (ix >= 0x7F800000) return x;\n if (k) {\n let uf: f32 = 1 + x;\n let iu = reinterpret(uf);\n iu += 0x3F800000 - 0x3F3504F3;\n k = (iu >> 23) - 0x7F;\n if (k < 25) {\n c = k >= 2 ? 1 - (uf - x) : x - (uf - 1);\n c /= uf;\n } else c = 0;\n iu = (iu & 0x007FFFFF) + 0x3F3504F3;\n f = reinterpret(iu) - 1;\n }\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * Lg4);\n var t2 = z * (Lg1 + w * Lg3);\n var r = t2 + t1;\n var hfsq: f32 = 0.5 * f * f;\n var dk = k;\n return s * (hfsq + r) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;\n }\n\n export function log2(x: f32): f32 { // see: musl/src/math/log2f.c and SUN COPYRIGHT NOTICE above\n const\n ivln2hi = reinterpret(0x3FB8B000), // 1.4428710938e+00f\n ivln2lo = reinterpret(0xB9389AD4), // -1.7605285393e-04\n Lg1 = reinterpret(0x3F2AAAAA), // 0xaaaaaa.0p-24f, 0.66666662693f\n Lg2 = reinterpret(0x3ECCCE13), // 0xccce13.0p-25f, 0.40000972152f\n Lg3 = reinterpret(0x3E91E9EE), // 0x91e9ee.0p-25f, 0.28498786688f\n Lg4 = reinterpret(0x3E789E26), // 0xf89e26.0p-26f, 0.24279078841f\n Ox1p25f = reinterpret(0x4C000000);\n var ix = reinterpret(x);\n var k: i32 = 0;\n if (ix < 0x00800000 || (ix >> 31)) {\n if (ix << 1 == 0) return -1 / (x * x);\n if (ix >> 31) return (x - x) / 0.0;\n k -= 25;\n x *= Ox1p25f;\n ix = reinterpret(x);\n } else if (ix >= 0x7F800000) return x;\n else if (ix == 0x3F800000) return 0;\n ix += 0x3F800000 - 0x3F3504F3;\n k += (ix >> 23) - 0x7F;\n ix = (ix & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(ix);\n var f = x - 1.0;\n var s = f / (2.0 + f);\n var z = s * s;\n var w = z * z;\n var t1 = w * (Lg2 + w * Lg4);\n var t2 = z * (Lg1 + w * Lg3);\n var r = t2 + t1;\n var hfsq: f32 = 0.5 * f * f;\n var hi = f - hfsq;\n var u = reinterpret(hi);\n u &= 0xFFFFF000;\n hi = reinterpret(u);\n var lo: f32 = f - hi - hfsq + s * (hfsq + r);\n var dk = k;\n return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + dk;\n }\n\n @inline\n export function max(value1: f32, value2: f32): f32 {\n return builtin_max(value1, value2);\n }\n\n @inline\n export function min(value1: f32, value2: f32): f32 {\n return builtin_min(value1, value2);\n }\n\n export function pow(x: f32, y: f32): f32 { // see: musl/src/math/powf.c and SUN COPYRIGHT NOTICE above\n const\n dp_h1 = reinterpret(0x3F15C000), // 5.84960938e-01f\n dp_l1 = reinterpret(0x35D1CFDC), // 1.56322085e-06f\n two24 = reinterpret(0x4B800000), // 16777216f\n huge = reinterpret(0x7149F2CA), // 1.0e+30f\n tiny = reinterpret(0x0DA24260), // 1.0e-30f\n L1 = reinterpret(0x3F19999A), // 6.0000002384e-01f\n L2 = reinterpret(0x3EDB6DB7), // 4.2857143283e-01f\n L3 = reinterpret(0x3EAAAAAB), // 3.3333334327e-01f\n L4 = reinterpret(0x3E8BA305), // 2.7272811532e-01f\n L5 = reinterpret(0x3E6C3255), // 2.3066075146e-01f\n L6 = reinterpret(0x3E53F142), // 2.0697501302e-01f\n P1 = reinterpret(0x3E2AAAAB), // 1.6666667163e-01f\n P2 = reinterpret(0xBB360B61), // -2.7777778450e-03f\n P3 = reinterpret(0x388AB355), // 6.6137559770e-05f\n P4 = reinterpret(0xB5DDEA0E), // -1.6533901999e-06f\n P5 = reinterpret(0x3331BB4C), // 4.1381369442e-08f\n lg2 = reinterpret(0x3F317218), // 6.9314718246e-01f\n lg2_h = reinterpret(0x3F317200), // 6.93145752e-01f\n lg2_l = reinterpret(0x35BFBE8C), // 1.42860654e-06f\n ovt = reinterpret(0x3338AA3C), // 4.2995665694e-08f\n cp = reinterpret(0x3F76384F), // 9.6179670095e-01\n cp_h = reinterpret(0x3F764000), // 9.6191406250e-01\n cp_l = reinterpret(0xB8F623C6), // -1.1736857402e-04\n ivln2 = reinterpret(0x3FB8AA3B), // 1.4426950216e+00\n ivln2_h = reinterpret(0x3FB8AA00), // 1.4426879883e+00\n ivln2_l = reinterpret(0x36ECA570), // 7.0526075433e-06\n inv3 = reinterpret(0x3EAAAAAB); // 0.333333333333\n var hx = reinterpret(x);\n var hy = reinterpret(y);\n var ix = hx & 0x7FFFFFFF;\n var iy = hy & 0x7FFFFFFF;\n if (iy == 0) return 1.0; // x**0 = 1, even if x is NaN\n // if (hx == 0x3F800000) return 1.0; // C: 1**y = 1, even if y is NaN, JS: NaN\n if (ix > 0x7F800000 || iy > 0x7F800000) return x + y; // NaN if either arg is NaN\n var yisint = 0, j: i32, k: i32;\n if (hx < 0) {\n if (iy >= 0x4B800000) yisint = 2;\n else if (iy >= 0x3F800000) {\n k = (iy >> 23) - 0x7F;\n j = iy >> (23 - k);\n if ((j << (23 - k)) == iy) yisint = 2 - (j & 1);\n }\n }\n if (iy == 0x7F800000) { // y is +-inf\n if (ix == 0x3F800000) return NaN; // C: (-1)**+-inf is 1, JS: NaN\n else if (ix > 0x3F800000) return hy >= 0 ? y : 0.0; // (|x|>1)**+-inf = inf,0\n else return hy >= 0 ? 0.0 : -y; // (|x|<1)**+-inf = 0,inf\n }\n if (iy == 0x3F800000) return hy >= 0 ? x : 1.0 / x;\n if (hy == 0x40000000) return x * x;\n if (hy == 0x3F000000) {\n if (hx >= 0) return builtin_sqrt(x);\n }\n var ax = builtin_abs(x);\n var z: f32;\n if (ix == 0x7F800000 || ix == 0 || ix == 0x3F800000) {\n z = ax;\n if (hy < 0) z = 1.0 / z;\n if (hx < 0) {\n if (((ix - 0x3F800000) | yisint) == 0) z = (z - z) / (z - z);\n else if (yisint == 1) z = -z;\n }\n return z;\n }\n var sn = 1.0;\n if (hx < 0) {\n if (yisint == 0) return (x - x) / (x - x);\n if (yisint == 1) sn = -1.0;\n }\n var t1: f32, t2: f32, r: f32, s: f32, t: f32, u: f32, v: f32, w: f32, p_h: f32, p_l: f32;\n var n: i32, is: i32;\n if (iy > 0x4D000000) {\n if (ix < 0x3F7FFFF8) return hy < 0 ? sn * huge * huge : sn * tiny * tiny;\n if (ix > 0x3F800007) return hy > 0 ? sn * huge * huge : sn * tiny * tiny;\n t = ax - 1;\n w = (t * t) * (0.5 - t * (inv3 - t * 0.25));\n u = ivln2_h * t;\n v = t * ivln2_l - w * ivln2;\n t1 = u + v;\n is = reinterpret(t1);\n t1 = reinterpret(is & 0xFFFFF000);\n t2 = v - (t1 - u);\n } else {\n let s2: f32, s_h: f32, s_l: f32, t_h: f32, t_l: f32;\n n = 0;\n if (ix < 0x00800000) {\n ax *= two24;\n n -= 24;\n ix = reinterpret(ax);\n }\n n += (ix >> 23) - 0x7F;\n j = ix & 0x007FFFFF;\n ix = j | 0x3F800000;\n if (j <= 0x1CC471) k = 0;\n else if (j < 0x5DB3D7) k = 1;\n else {\n k = 0;\n n += 1;\n ix -= 0x00800000;\n }\n ax = reinterpret(ix);\n let bp = select(1.5, 1.0, k); // k ? 1.5 : 1.0\n u = ax - bp;\n v = 1.0 / (ax + bp);\n s = u * v;\n s_h = s;\n is = reinterpret(s_h);\n s_h = reinterpret(is & 0xFFFFF000);\n is = ((ix >> 1) & 0xFFFFF000) | 0x20000000;\n t_h = reinterpret(is + 0x00400000 + (k << 21));\n t_l = ax - (t_h - bp);\n s_l = v * ((u - s_h * t_h) - s_h * t_l);\n s2 = s * s;\n r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6)))));\n r += s_l * (s_h + s);\n s2 = s_h * s_h;\n t_h = 3.0 + s2 + r;\n is = reinterpret(t_h);\n t_h = reinterpret(is & 0xFFFFF000);\n t_l = r - ((t_h - 3.0) - s2);\n u = s_h * t_h;\n v = s_l * t_h + t_l * s;\n p_h = u + v;\n is = reinterpret(p_h);\n p_h = reinterpret(is & 0xFFFFF000);\n p_l = v - (p_h - u);\n let z_h = cp_h * p_h;\n let dp_l = select(dp_l1, 0.0, k);\n let z_l = cp_l * p_h + p_l * cp + dp_l;\n t = n;\n let dp_h = select(dp_h1, 0.0, k);\n t1 = (((z_h + z_l) + dp_h) + t);\n is = reinterpret(t1);\n t1 = reinterpret(is & 0xFFFFF000);\n t2 = z_l - (((t1 - t) - dp_h) - z_h);\n }\n is = reinterpret(y);\n var y1 = reinterpret(is & 0xFFFFF000);\n p_l = (y - y1) * t1 + y * t2;\n p_h = y1 * t1;\n z = p_l + p_h;\n j = reinterpret(z);\n if (j > 0x43000000) {\n return sn * huge * huge;\n } else if (j == 0x43000000) {\n if (p_l + ovt > z - p_h) return sn * huge * huge;\n } else if ((j & 0x7FFFFFFF) > 0x43160000) {\n return sn * tiny * tiny;\n } else if (j == 0xC3160000) {\n if (p_l <= z - p_h) return sn * tiny * tiny;\n }\n var i = j & 0x7FFFFFFF;\n k = (i >> 23) - 0x7F;\n n = 0;\n if (i > 0x3F000000) {\n n = j + (0x00800000 >> (k + 1));\n k = ((n & 0x7FFFFFFF) >> 23) - 0x7F;\n t = reinterpret(n & ~(0x007FFFFF >> k));\n n = ((n & 0x007FFFFF) | 0x00800000) >> (23 - k);\n if (j < 0) n = -n;\n p_h -= t;\n }\n t = p_l + p_h;\n is = reinterpret(t);\n t = reinterpret(is & 0xFFFF8000);\n u = t * lg2_h;\n v = (p_l - (t - p_h)) * lg2 + t * lg2_l;\n z = u + v;\n w = v - (z - u);\n t = z * z;\n t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5))));\n r = (z * t1) / (t1 - 2.0) - (w + z * w);\n z = 1.0 - (r - z);\n j = reinterpret(z);\n j += n << 23;\n if ((j >> 23) <= 0) z = scalbn(z, n);\n else z = reinterpret(j);\n return sn * z;\n }\n\n @inline\n export function seedRandom(value: i64): void {\n NativeMath.seedRandom(value);\n }\n\n // Using xoroshiro64starstar from http://xoshiro.di.unimi.it/xoroshiro64starstar.c\n export function random(): f32 {\n if (!random_seeded) throw new Error("PRNG must be seeded.");\n\n var s0 = random_state0_32;\n var s1 = random_state1_32;\n var r = rotl(s0 * 0x9E3779BB, 5) * 5;\n\n s1 ^= s0;\n random_state0_32 = rotl(s0, 26) ^ s1 ^ (s1 << 9);\n random_state1_32 = rotl(s1, 13);\n\n return reinterpret((r >> 9) | (127 << 23)) - 1.0;\n }\n\n @inline\n export function round(x: f32): f32 {\n return builtin_copysign(builtin_floor(x + 0.5), x);\n }\n\n @inline\n export function sign(x: f32): f32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return builtin_abs(x) > 0 ? builtin_copysign(1, x) : x;\n } else {\n return x > 0 ? 1 : x < 0 ? -1 : x;\n }\n }\n\n export function sin(x: f32): f32 { // TODO\n unreachable();\n return 0;\n }\n\n export function sinh(x: f32): f32 { // see: musl/src/math/sinhf.c\n var u = reinterpret(x) & 0x7FFFFFFF;\n var absx = reinterpret(u);\n var t: f32;\n var h = builtin_copysign(0.5, x);\n if (u < 0x42B17217) {\n t = expm1(absx);\n if (u < 0x3F800000) {\n if (u < 0x3F800000 - (12 << 23)) return x;\n return h * (2 * t - t * t / (t + 1));\n }\n return h * (t + t / (t + 1));\n }\n t = 2 * h * expo2f(absx);\n return t;\n }\n\n @inline\n export function sqrt(x: f32): f32 {\n return builtin_sqrt(x);\n }\n\n export function tan(x: f32): f32 { // TODO\n unreachable();\n return 0;\n }\n\n export function tanh(x: f32): f32 { // see: musl/src/math/tanhf.c\n var u = reinterpret(x);\n u &= 0x7FFFFFFF;\n var y = reinterpret(u);\n var t: f32;\n if (u > 0x3F0C9F54) {\n if (u > 0x41200000) t = 1 + 0 / y;\n else {\n t = expm1(2 * y);\n t = 1 - 2 / (t + 2);\n }\n } else if (u > 0x3E82C578) {\n t = expm1(2 * y);\n t = t / (t + 2);\n } else if (u >= 0x00800000) {\n t = expm1(-2 * y);\n t = -t / (t + 2);\n } else t = y;\n return builtin_copysign(t, x);\n }\n\n @inline\n export function trunc(x: f32): f32 {\n return builtin_trunc(x);\n }\n\n /** @internal */\n export function scalbn(x: f32, n: i32): f32 { // see: https://git.musl-libc.org/cgit/musl/tree/src/math/scalbnf.c\n const\n Ox1p24f = reinterpret(0x4B800000),\n Ox1p127f = reinterpret(0x7F000000),\n Ox1p_126f = reinterpret(0x00800000);\n var y = x;\n if (n > 127) {\n y *= Ox1p127f;\n n -= 127;\n if (n > 127) {\n y *= Ox1p127f;\n n = builtin_min(n - 127, 127);\n }\n } else if (n < -126) {\n y *= Ox1p_126f * Ox1p24f;\n n += 126 - 24;\n if (n < -126) {\n y *= Ox1p_126f * Ox1p24f;\n n = builtin_max(n + 126 - 24, -126);\n }\n }\n return y * reinterpret((0x7F + n) << 23);\n }\n\n export function mod(x: f32, y: f32): f32 { // see: musl/src/math/fmodf.c\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = (ux >> 23 & 0xFF);\n var ey = (uy >> 23 & 0xFF);\n var sx = ux & 0x80000000;\n var uy1 = uy << 1;\n if (uy1 == 0 || ex == 0xFF || isNaN(y)) return (x * y) / (x * y);\n var ux1 = ux << 1;\n if (ux1 <= uy1) {\n if (ux1 == uy1) return 0 * x;\n return x;\n }\n if (!ex) {\n ex -= builtin_clz(ux << 9);\n ux <<= -ex + 1;\n } else {\n ux &= -1 >> 9;\n ux |= 1 << 23;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 9);\n uy <<= -ey + 1;\n } else {\n uy &= -1 >> 9;\n uy |= 1 << 23;\n }\n while (ex > ey) {\n if (ux >= uy) {\n if (ux == uy) return 0 * x;\n ux -= uy;\n }\n ux <<= 1;\n --ex;\n }\n if (ux >= uy) {\n if (ux == uy) return 0 * x;\n ux -= uy;\n }\n // for (; !(ux >> 23); ux <<= 1) --ex;\n var shift = builtin_clz(ux << 8);\n ex -= shift;\n ux <<= shift;\n if (ex > 0) {\n ux -= 1 << 23;\n ux |= ex << 23;\n } else {\n ux >>= -ex + 1;\n }\n ux |= sx;\n return reinterpret(ux);\n }\n\n export function rem(x: f32, y: f32): f32 { // see: musl/src/math/remquof.c\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = (ux >> 23 & 0xFF);\n var ey = (uy >> 23 & 0xFF);\n var sx = (ux >> 31);\n var uxi = ux;\n if (uy << 1 == 0 || ex == 0xFF || isNaN(y)) return (x * y) / (x * y);\n if (ux << 1 == 0) return x;\n if (!ex) {\n ex -= builtin_clz(uxi << 9);\n uxi <<= -ex + 1;\n } else {\n uxi &= -1 >> 9;\n uxi |= 1 << 23;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 9);\n uy <<= -ey + 1;\n } else {\n uy &= -1 >> 9;\n uy |= 1 << 23;\n }\n var q = 0;\n do {\n if (ex < ey) {\n if (ex + 1 == ey) break; // goto end\n return x;\n }\n while (ex > ey) {\n if (uxi >= uy) {\n uxi -= uy;\n ++q;\n }\n uxi <<= 1;\n q <<= 1;\n --ex;\n }\n if (uxi >= uy) {\n uxi -= uy;\n ++q;\n }\n if (uxi == 0) ex = -30;\n else {\n let shift = builtin_clz(uxi << 8);\n ex -= shift;\n uxi <<= shift;\n }\n break;\n } while (false);\n // end\n if (ex > 0) {\n uxi -= 1 << 23;\n uxi |= ex << 23;\n } else {\n uxi >>= -ex + 1;\n }\n x = reinterpret(uxi);\n y = builtin_abs(y);\n var x2 = x + x;\n if (ex == ey || (ex + 1 == ey && (x2 > y || (x2 == y && (q & 1))))) {\n x -= y;\n // q++;\n }\n return sx ? -x : x;\n }\n}\n\nexport function ipow32(x: i32, e: i32): i32 {\n var out = 1;\n if (ASC_SHRINK_LEVEL < 1) {\n if (e < 0) return 0;\n\n switch (e) {\n case 0: return 1;\n case 1: return x;\n case 2: return x * x;\n }\n\n let log = 32 - clz(e);\n if (log <= 5) {\n // 32 = 2 ^ 5, so need only five cases.\n // But some extra cases needs for properly overflowing\n switch (log) {\n case 5: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 4: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 3: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 2: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 1: {\n if (e & 1) out *= x;\n }\n }\n return out;\n }\n }\n\n while (e > 0) {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n return out;\n}\n\nexport function ipow64(x: i64, e: i32): i64 {\n var out: i64 = 1;\n if (ASC_SHRINK_LEVEL < 1) {\n if (e < 0) return 0;\n switch (e) {\n case 0: return 1;\n case 1: return x;\n case 2: return x * x;\n }\n\n let log = 32 - clz(e);\n if (log <= 6) {\n // 64 = 2 ^ 6, so need only six cases.\n // But some extra cases needs for properly overflowing\n switch (log) {\n case 6: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 5: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 4: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 3: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 2: {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n case 1: {\n if (e & 1) out *= x;\n }\n }\n return out;\n }\n }\n\n while (e > 0) {\n if (e & 1) out *= x;\n e >>= 1;\n x *= x;\n }\n return out;\n}\n',memory:'import { memcmp, memmove, memset } from "./internal/memory";\n\n@builtin export declare const HEAP_BASE: usize; // tslint:disable-line\n\n/* tslint:disable */\n\nexport namespace memory {\n\n @builtin export declare function size(): i32;\n\n @builtin export declare function grow(pages: i32): i32;\n\n @inline export function fill(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset\n if (isDefined(__memory_fill)) { __memory_fill(dest, c, n); return; }\n memset(dest, c, n);\n }\n\n @inline export function copy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c\n if (isDefined(__memory_copy)) { __memory_copy(dest, src, n); return; }\n memmove(dest, src, n);\n }\n\n @inline export function compare(vl: usize, vr: usize, n: usize): i32 { // see: musl/src/string/memcmp.c\n if (isDefined(__memory_compare)) return __memory_compare(vl, vr, n);\n return memcmp(vl, vr, n);\n }\n\n // Passive segments\n\n // export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void {\n // __memory_init(segmentIndex, srcOffset, dstOffset);\n // }\n\n // export function drop(segmentIndex: u32): void {\n // __memory_drop(segmentIndex);\n // }\n\n // Allocator\n\n @inline export function allocate(size: usize): usize {\n if (isDefined(__memory_allocate)) return __memory_allocate(size);\n WARNING("Calling \'memory.allocate\' requires a memory manager to be present.");\n return unreachable();\n }\n\n @inline export function free(ptr: usize): void {\n if (isDefined(__memory_free)) { __memory_free(ptr); return; }\n WARNING("Calling \'memory.free\' requires a memory manager to be present.");\n unreachable();\n }\n\n @inline export function reset(): void {\n if (isDefined(__memory_reset)) { __memory_reset(); return; }\n unreachable();\n }\n}\n',polyfills:"export function bswap(value: T): T {\n assert(sizeof() == 1 || sizeof() == 2 || sizeof() == 4 || sizeof() == 8);\n\n if (sizeof() == 2) {\n return bswap16(value);\n }\n if (sizeof() == 4) {\n return (\n rotl(value & 0xFF00FF00, 8) |\n rotr(value & 0x00FF00FF, 8)\n );\n }\n if (sizeof() == 8) {\n let a: u64 = (value >> 8) & 0x00FF00FF00FF00FF;\n let b: u64 = (value & 0x00FF00FF00FF00FF) << 8;\n let v: u64 = a | b;\n\n a = (v >> 16) & 0x0000FFFF0000FFFF;\n b = (v & 0x0000FFFF0000FFFF) << 16;\n\n return rotr(a | b, 32);\n }\n return value;\n}\n\nexport function bswap16(value: T): T {\n assert(sizeof() == 1 || sizeof() == 2 || sizeof() == 4);\n\n if (sizeof() == 2 || sizeof() == 4) {\n return (((value << 8) & 0xFF00) | ((value >> 8) & 0x00FF) | (value & 0xFFFF0000));\n }\n return value;\n}\n",regexp:'export class RegExp {\n\n // @binding(CALL_NEW, [ STRING, STRING], OBJECT_HANDLE)\n constructor(pattern: string, flags: string = "") { throw new Error("unreachable"); }\n\n // @binding(CALL_THIS, [ STRING ], PASS_THRU)\n test(search: string): bool { throw new Error("unreachable"); }\n\n // @binding(CALL_THIS, [], STRING)\n toString(): string { throw new Error("unreachable"); }\n\n}\n',set:'import {\n HEADER_SIZE as HEADER_SIZE_AB\n} from "./internal/arraybuffer";\n\nimport {\n hash\n} from "./internal/hash";\n\n// A deterministic hash set based on CloseTable from https://github.com/jorendorff/dht\n\nconst INITIAL_CAPACITY = 4;\nconst FILL_FACTOR: f64 = 8 / 3;\nconst FREE_FACTOR: f64 = 3 / 4;\n\n/** Structure of a set entry. */\n@unmanaged class SetEntry {\n key: K;\n taggedNext: usize; // LSB=1 indicates EMPTY\n}\n\n/** Empty bit. */\nconst EMPTY: usize = 1 << 0;\n\n/** Size of a bucket. */\nconst BUCKET_SIZE = sizeof();\n\n/** Computes the alignment of an entry. */\n@inline function ENTRY_ALIGN(): usize {\n // can align to 4 instead of 8 if 32-bit and K is <= 32-bits\n const align = (sizeof() > sizeof() ? sizeof() : sizeof()) - 1;\n return align;\n}\n\n/** Computes the aligned size of an entry. */\n@inline function ENTRY_SIZE(): usize {\n const align = ENTRY_ALIGN();\n const size = (offsetof>() + align) & ~align;\n return size;\n}\n\nexport class Set {\n\n // buckets holding references to the respective first entry within\n private buckets: ArrayBuffer; // usize[bucketsMask + 1]\n private bucketsMask: u32;\n\n // entries in insertion order\n private entries: ArrayBuffer; // SetEntry[entriesCapacity]\n private entriesCapacity: i32;\n private entriesOffset: i32;\n private entriesCount: i32;\n\n get size(): i32 { return this.entriesCount; }\n\n constructor() { this.clear(); }\n\n clear(): void {\n const bucketsSize = INITIAL_CAPACITY * BUCKET_SIZE;\n this.buckets = new ArrayBuffer(bucketsSize);\n this.bucketsMask = INITIAL_CAPACITY - 1;\n const entriesSize = INITIAL_CAPACITY * ENTRY_SIZE();\n this.entries = new ArrayBuffer(entriesSize, true);\n this.entriesCapacity = INITIAL_CAPACITY;\n this.entriesOffset = 0;\n this.entriesCount = 0;\n }\n\n private find(key: K, hashCode: u32): SetEntry | null {\n var entry = load>(\n changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE,\n HEADER_SIZE_AB\n );\n while (entry) {\n if (!(entry.taggedNext & EMPTY) && entry.key == key) return entry;\n entry = changetype>(entry.taggedNext & ~EMPTY);\n }\n return null;\n }\n\n has(key: K): bool {\n return this.find(key, hash(key)) !== null;\n }\n\n add(key: K): void {\n var hashCode = hash(key);\n var entry = this.find(key, hashCode);\n if (!entry) {\n // check if rehashing is necessary\n if (this.entriesOffset == this.entriesCapacity) {\n this.rehash(\n this.entriesCount < (this.entriesCapacity * FREE_FACTOR)\n ? this.bucketsMask // just rehash if 1/4+ entries are empty\n : (this.bucketsMask << 1) | 1 // grow capacity to next 2^N\n );\n }\n // append new entry\n let entries = this.entries;\n entry = changetype>(\n changetype(entries) + HEADER_SIZE_AB + this.entriesOffset++ * ENTRY_SIZE()\n );\n entry.key = key;\n ++this.entriesCount;\n // link with previous entry in bucket\n let bucketPtrBase = changetype(this.buckets) + (hashCode & this.bucketsMask) * BUCKET_SIZE;\n entry.taggedNext = load(bucketPtrBase, HEADER_SIZE_AB);\n store(bucketPtrBase, changetype(entry), HEADER_SIZE_AB);\n if (isManaged()) __gc_link(changetype(this), changetype(key)); // tslint:disable-line\n }\n }\n\n delete(key: K): bool {\n var entry = this.find(key, hash(key));\n if (!entry) return false;\n entry.taggedNext |= EMPTY;\n --this.entriesCount;\n // check if rehashing is appropriate\n var halfBucketsMask = this.bucketsMask >> 1;\n if (\n halfBucketsMask + 1 >= max(INITIAL_CAPACITY, this.entriesCount) &&\n this.entriesCount < (this.entriesCapacity * FREE_FACTOR)\n ) this.rehash(halfBucketsMask);\n return true;\n }\n\n private rehash(newBucketsMask: u32): void {\n var newBucketsCapacity = (newBucketsMask + 1);\n var newBuckets = new ArrayBuffer(newBucketsCapacity * BUCKET_SIZE);\n var newEntriesCapacity = (newBucketsCapacity * FILL_FACTOR);\n var newEntries = new ArrayBuffer(newEntriesCapacity * ENTRY_SIZE(), true);\n\n // copy old entries to new entries\n var oldPtr = changetype(this.entries) + HEADER_SIZE_AB;\n var oldEnd = oldPtr + this.entriesOffset * ENTRY_SIZE();\n var newPtr = changetype(newEntries) + HEADER_SIZE_AB;\n while (oldPtr != oldEnd) {\n let oldEntry = changetype>(oldPtr);\n if (!(oldEntry.taggedNext & EMPTY)) {\n let newEntry = changetype>(newPtr);\n newEntry.key = oldEntry.key;\n let newBucketIndex = hash(oldEntry.key) & newBucketsMask;\n let newBucketPtrBase = changetype(newBuckets) + newBucketIndex * BUCKET_SIZE;\n newEntry.taggedNext = load(newBucketPtrBase, HEADER_SIZE_AB);\n store(newBucketPtrBase, newPtr, HEADER_SIZE_AB);\n newPtr += ENTRY_SIZE();\n }\n oldPtr += ENTRY_SIZE();\n }\n\n this.buckets = newBuckets;\n this.bucketsMask = newBucketsMask;\n this.entries = newEntries;\n this.entriesCapacity = newEntriesCapacity;\n this.entriesOffset = this.entriesCount;\n }\n\n private __gc(): void {\n __gc_mark(changetype(this.buckets)); // tslint:disable-line\n var entries = this.entries;\n __gc_mark(changetype(entries)); // tslint:disable-line\n if (isManaged()) {\n let offset: usize = 0;\n let end: usize = this.entriesOffset * ENTRY_SIZE();\n while (offset < end) {\n let entry = changetype>(\n changetype(entries) + HEADER_SIZE_AB + offset * ENTRY_SIZE()\n );\n if (!(entry.taggedNext & EMPTY)) __gc_mark(changetype(entry.key)); // tslint:disable-line\n offset += ENTRY_SIZE();\n }\n }\n }\n}\n',string:'import {\n HEADER_SIZE,\n MAX_LENGTH,\n allocateUnsafe,\n compareUnsafe,\n repeatUnsafe,\n copyUnsafe,\n isWhiteSpaceOrLineTerminator,\n CharCode,\n parse\n} from "./internal/string";\n\nimport {\n storeUnsafe as storeUnsafeArray\n} from "./internal/arraybuffer";\n\n@sealed\nexport class String {\n\n readonly length: i32; // capped to [0, MAX_LENGTH]\n\n // TODO Add and handle second argument\n static fromCharCode(code: i32): String {\n var out = allocateUnsafe(1);\n store(\n changetype(out),\n code,\n HEADER_SIZE\n );\n return out;\n }\n\n static fromCodePoint(code: i32): String {\n assert(code <= 0x10FFFF);\n var sur = code > 0xFFFF;\n var out = allocateUnsafe(sur + 1);\n if (!sur) {\n store(\n changetype(out),\n code,\n HEADER_SIZE\n );\n } else {\n code -= 0x10000;\n let hi: u32 = (code >>> 10) + 0xD800;\n let lo: u32 = (code & 0x3FF) + 0xDC00;\n store(\n changetype(out),\n (hi << 16) | lo,\n HEADER_SIZE\n );\n }\n return out;\n }\n\n @operator("[]")\n charAt(pos: i32): String {\n assert(this !== null);\n\n if (pos >= this.length) return changetype("");\n\n var out = allocateUnsafe(1);\n store(\n changetype(out),\n load(\n changetype(this) + (pos << 1),\n HEADER_SIZE\n ),\n HEADER_SIZE\n );\n return out;\n }\n\n charCodeAt(pos: i32): i32 {\n assert(this !== null);\n if (pos >= this.length) return -1; // (NaN)\n\n return load(\n changetype(this) + (pos << 1),\n HEADER_SIZE\n );\n }\n\n codePointAt(pos: i32): i32 {\n assert(this !== null);\n if (pos >= this.length) return -1; // (undefined)\n\n var first = load(\n changetype(this) + (pos << 1),\n HEADER_SIZE\n );\n if (first < 0xD800 || first > 0xDBFF || pos + 1 == this.length) {\n return first;\n }\n var second = load(\n changetype(this) + ((pos + 1) << 1),\n HEADER_SIZE\n );\n if (second < 0xDC00 || second > 0xDFFF) return first;\n return ((first - 0xD800) << 10) + (second - 0xDC00) + 0x10000;\n }\n\n @operator("+")\n private static __concat(left: String, right: String): String {\n if (!changetype(left)) left = changetype("null");\n return left.concat(right);\n }\n\n concat(other: String): String {\n assert(this !== null);\n if (other === null) other = changetype("null");\n\n var thisLen: isize = this.length;\n var otherLen: isize = other.length;\n var outLen: usize = thisLen + otherLen;\n if (outLen == 0) return changetype("");\n var out = allocateUnsafe(outLen);\n copyUnsafe(out, 0, this, 0, thisLen);\n copyUnsafe(out, thisLen, other, 0, otherLen);\n return out;\n }\n\n endsWith(searchString: String, endPosition: i32 = MAX_LENGTH): bool {\n assert(this !== null);\n if (searchString === null) return false;\n var end = min(max(endPosition, 0), this.length);\n var searchLength: isize = searchString.length;\n var start: isize = end - searchLength;\n if (start < 0) return false;\n return !compareUnsafe(this, start, searchString, 0, searchLength);\n }\n\n @operator("==")\n private static __eq(left: String, right: String): bool {\n if (left === right) return true;\n if (left === null || right === null) return false;\n\n var leftLength = left.length;\n if (leftLength != right.length) return false;\n\n return !compareUnsafe(left, 0, right, 0, leftLength);\n }\n\n @operator("!=")\n private static __ne(left: String, right: String): bool {\n return !this.__eq(left, right);\n }\n\n @operator(">")\n private static __gt(left: String, right: String): bool {\n if (left === right || left === null || right === null) return false;\n\n var leftLength = left.length;\n var rightLength = right.length;\n\n if (!leftLength) return false;\n if (!rightLength) return true;\n\n var length = min(leftLength, rightLength);\n return compareUnsafe(left, 0, right, 0, length) > 0;\n }\n\n @operator(">=")\n private static __gte(left: String, right: String): bool {\n if (left === right) return true;\n if (left === null || right === null) return false;\n\n var leftLength = left.length;\n var rightLength = right.length;\n\n if (!leftLength) return !rightLength;\n if (!rightLength) return true;\n\n var length = min(leftLength, rightLength);\n return compareUnsafe(left, 0, right, 0, length) >= 0;\n }\n\n @operator("<")\n private static __lt(left: String, right: String): bool {\n if (left === right || left === null || right === null) return false;\n\n var leftLength = left.length;\n var rightLength = right.length;\n\n if (!rightLength) return false;\n if (!leftLength) return true;\n\n var length = min(leftLength, rightLength);\n return compareUnsafe(left, 0, right, 0, length) < 0;\n }\n\n @operator("<=")\n private static __lte(left: String, right: String): bool {\n if (left === right) return true;\n if (left === null || right === null) return false;\n\n var leftLength = left.length;\n var rightLength = right.length;\n\n if (!rightLength) return !leftLength;\n if (!leftLength) return true;\n\n var length = min(leftLength, rightLength);\n return compareUnsafe(left, 0, right, 0, length) <= 0;\n }\n\n @inline\n includes(searchString: String, position: i32 = 0): bool {\n return this.indexOf(searchString, position) != -1;\n }\n\n indexOf(searchString: String, fromIndex: i32 = 0): i32 {\n assert(this !== null);\n if (searchString === null) searchString = changetype("null");\n\n var searchLen: isize = searchString.length;\n if (!searchLen) return 0;\n var len: isize = this.length;\n if (!len) return -1;\n var start = min(max(fromIndex, 0), len);\n len -= searchLen;\n for (let k: isize = start; k <= len; ++k) {\n if (!compareUnsafe(this, k, searchString, 0, searchLen)) return k;\n }\n return -1;\n }\n\n lastIndexOf(searchString: String, fromIndex: i32 = i32.MAX_VALUE): i32 {\n assert(this !== null);\n if (searchString === null) searchString = changetype("null");\n\n var len: isize = this.length;\n var searchLen: isize = searchString.length;\n if (!searchLen) return len;\n if (!len) return -1;\n var start = min(max(fromIndex, 0), len - searchLen);\n for (let k = start; k >= 0; --k) {\n if (!compareUnsafe(this, k, searchString, 0, searchLen)) return k;\n }\n return -1;\n }\n\n startsWith(searchString: String, position: i32 = 0): bool {\n assert(this !== null);\n if (searchString === null) searchString = changetype("null");\n\n var pos: isize = position;\n var len: isize = this.length;\n var start = min(max(pos, 0), len);\n var searchLength: isize = searchString.length;\n if (searchLength + start > len) return false;\n return !compareUnsafe(this, start, searchString, 0, searchLength);\n }\n\n substr(start: i32, length: i32 = i32.MAX_VALUE): String {\n assert(this !== null);\n var intStart: isize = start;\n var end: isize = length;\n var size: isize = this.length;\n if (intStart < 0) intStart = max(size + intStart, 0);\n var resultLength = min(max(end, 0), size - intStart);\n if (resultLength <= 0) return changetype("");\n var out = allocateUnsafe(resultLength);\n copyUnsafe(out, 0, this, intStart, resultLength);\n return out;\n }\n\n substring(start: i32, end: i32 = i32.MAX_VALUE): String {\n assert(this !== null);\n var len = this.length;\n var finalStart = min(max(start, 0), len);\n var finalEnd = min(max(end, 0), len);\n var from = min(finalStart, finalEnd);\n var to = max(finalStart, finalEnd);\n len = to - from;\n if (!len) return changetype("");\n if (!from && to == this.length) return this;\n var out = allocateUnsafe(len);\n copyUnsafe(out, 0, this, from, len);\n return out;\n }\n\n trim(): String {\n assert(this !== null);\n var length: usize = this.length;\n\n while (\n length &&\n isWhiteSpaceOrLineTerminator(\n load(changetype(this) + (length << 1), HEADER_SIZE)\n )\n ) {\n --length;\n }\n var start: usize = 0;\n while (\n start < length &&\n isWhiteSpaceOrLineTerminator(\n load(changetype(this) + (start << 1), HEADER_SIZE)\n )\n ) {\n ++start, --length;\n }\n if (!length) return changetype("");\n if (!start && length == this.length) return this;\n var out = allocateUnsafe(length);\n copyUnsafe(out, 0, this, start, length);\n return out;\n }\n\n @inline\n trimLeft(): String {\n return this.trimStart();\n }\n\n @inline\n trimRight(): String {\n return this.trimEnd();\n }\n\n trimStart(): String {\n assert(this !== null);\n var start: isize = 0;\n var len: isize = this.length;\n while (\n start < len &&\n isWhiteSpaceOrLineTerminator(\n load(changetype(this) + (start << 1), HEADER_SIZE)\n )\n ) {\n ++start;\n }\n if (!start) return this;\n var outLen = len - start;\n if (!outLen) return changetype("");\n var out = allocateUnsafe(outLen);\n copyUnsafe(out, 0, this, start, outLen);\n return out;\n }\n\n trimEnd(): String {\n assert(this !== null);\n var len: isize = this.length;\n while (\n len > 0 &&\n isWhiteSpaceOrLineTerminator(\n load(changetype(this) + (len << 1), HEADER_SIZE)\n )\n ) {\n --len;\n }\n if (len <= 0) return changetype("");\n if (len == this.length) return this;\n var out = allocateUnsafe(len);\n copyUnsafe(out, 0, this, 0, len);\n return out;\n }\n\n padStart(targetLength: i32, padString: String = changetype(" ")): String {\n assert(this !== null);\n var length = this.length;\n var padLen = padString.length;\n if (targetLength < length || !padLen) return this;\n var len = targetLength - length;\n var out = allocateUnsafe(targetLength);\n if (len > padLen) {\n let count = (len - 1) / padLen;\n let base = count * padLen;\n let rest = len - base;\n repeatUnsafe(out, 0, padString, count);\n if (rest) copyUnsafe(out, base, padString, 0, rest);\n } else {\n copyUnsafe(out, 0, padString, 0, len);\n }\n if (length) copyUnsafe(out, len, this, 0, length);\n return out;\n }\n\n padEnd(targetLength: i32, padString: String = changetype(" ")): String {\n assert(this !== null);\n var length = this.length;\n var padLen = padString.length;\n if (targetLength < length || !padLen) return this;\n var len = targetLength - length;\n var out = allocateUnsafe(targetLength);\n if (length) copyUnsafe(out, 0, this, 0, length);\n if (len > padLen) {\n let count = (len - 1) / padLen;\n let base = count * padLen;\n let rest = len - base;\n repeatUnsafe(out, length, padString, count);\n if (rest) copyUnsafe(out, base + length, padString, 0, rest);\n } else {\n copyUnsafe(out, length, padString, 0, len);\n }\n return out;\n }\n\n repeat(count: i32 = 0): String {\n assert(this !== null);\n var length = this.length;\n\n // Most browsers can\'t handle strings 1 << 28 chars or longer\n if (count < 0 || length * count > (1 << 28)) {\n throw new RangeError("Invalid count value");\n }\n\n if (count == 0 || !length) return changetype("");\n if (count == 1) return this;\n\n var result = allocateUnsafe(length * count);\n repeatUnsafe(result, 0, this, count);\n return result;\n }\n\n split(separator: String = null, limit: i32 = i32.MAX_VALUE): String[] {\n assert(this !== null);\n if (!limit) return new Array();\n if (separator === null) return [this];\n var length: isize = this.length;\n var sepLen: isize = separator.length;\n if (limit < 0) limit = i32.MAX_VALUE;\n if (!sepLen) {\n if (!length) return new Array();\n // split by chars\n length = min(length, limit);\n let result = new Array(length);\n let buffer = result.buffer_;\n for (let i: isize = 0; i < length; ++i) {\n let char = allocateUnsafe(1);\n store(\n changetype(char),\n load(\n changetype(this) + (i << 1),\n HEADER_SIZE\n ),\n HEADER_SIZE\n );\n storeUnsafeArray(buffer, i, char);\n }\n return result;\n } else if (!length) {\n return [changetype("")];\n }\n var result = new Array();\n var end = 0, start = 0, i = 0;\n while ((end = this.indexOf(separator, start)) != -1) {\n let len = end - start;\n if (len > 0) {\n let out = allocateUnsafe(len);\n copyUnsafe(out, 0, this, start, len);\n result.push(out);\n } else {\n result.push(changetype(""));\n }\n if (++i == limit) return result;\n start = end + sepLen;\n }\n if (!start) return [this];\n var len = length - start;\n if (len > 0) {\n let out = allocateUnsafe(len);\n copyUnsafe(out, 0, this, start, len);\n result.push(out);\n } else {\n result.push(changetype(""));\n }\n return result;\n }\n\n toString(): String {\n return this;\n }\n\n get lengthUTF8(): i32 {\n var len = 1; // null terminated\n var pos: usize = 0;\n var end = this.length;\n while (pos < end) {\n let c = load(changetype(this) + (pos << 1), HEADER_SIZE);\n if (c < 128) {\n len += 1; ++pos;\n } else if (c < 2048) {\n len += 2; ++pos;\n } else {\n if (\n (c & 0xFC00) == 0xD800 && pos + 1 < end &&\n (load(changetype(this) + ((pos + 1) << 1), HEADER_SIZE) & 0xFC00) == 0xDC00\n ) {\n len += 4; pos += 2;\n } else {\n len += 3; ++pos;\n }\n }\n }\n return len;\n }\n\n static fromUTF8(ptr: usize, len: usize): String {\n if (len < 1) return changetype("");\n var ptrPos = 0;\n var buf = memory.allocate(len << 1);\n var bufPos = 0;\n while (ptrPos < len) {\n let cp = load(ptr + ptrPos++);\n if (cp < 128) {\n store(buf + bufPos, cp);\n bufPos += 2;\n } else if (cp > 191 && cp < 224) {\n assert(ptrPos + 1 <= len);\n store(buf + bufPos, (cp & 31) << 6 | load(ptr + ptrPos++) & 63);\n bufPos += 2;\n } else if (cp > 239 && cp < 365) {\n assert(ptrPos + 3 <= len);\n cp = (\n (cp & 7) << 18 |\n (load(ptr + ptrPos++) & 63) << 12 |\n (load(ptr + ptrPos++) & 63) << 6 |\n load(ptr + ptrPos++) & 63\n ) - 0x10000;\n store(buf + bufPos, 0xD800 + (cp >> 10));\n bufPos += 2;\n store(buf + bufPos, 0xDC00 + (cp & 1023));\n bufPos += 2;\n } else {\n assert(ptrPos + 2 <= len);\n store(buf + bufPos,\n (cp & 15) << 12 |\n (load(ptr + ptrPos++) & 63) << 6 |\n load(ptr + ptrPos++) & 63\n );\n bufPos += 2;\n }\n }\n assert(ptrPos == len);\n var str = allocateUnsafe((bufPos >> 1));\n memory.copy(changetype(str) + HEADER_SIZE, buf, bufPos);\n memory.free(buf);\n return str;\n }\n\n toUTF8(): usize {\n var buf = memory.allocate(this.lengthUTF8);\n var pos: usize = 0;\n var end = this.length;\n var off: usize = 0;\n while (pos < end) {\n let c1 = load(changetype(this) + (pos << 1), HEADER_SIZE);\n if (c1 < 128) {\n store(buf + off, c1);\n ++off; ++pos;\n } else if (c1 < 2048) {\n let ptr = buf + off;\n store(ptr, c1 >> 6 | 192);\n store(ptr, c1 & 63 | 128, 1);\n off += 2; ++pos;\n } else {\n let ptr = buf + off;\n if ((c1 & 0xFC00) == 0xD800 && pos + 1 < end) {\n let c2 = load(changetype(this) + ((pos + 1) << 1), HEADER_SIZE);\n if ((c2 & 0xFC00) == 0xDC00) {\n c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);\n store(ptr, c1 >> 18 | 240);\n store(ptr, c1 >> 12 & 63 | 128, 1);\n store(ptr, c1 >> 6 & 63 | 128, 2);\n store(ptr, c1 & 63 | 128, 3);\n off += 4; pos += 2;\n continue;\n }\n }\n store(ptr, c1 >> 12 | 224);\n store(ptr, c1 >> 6 & 63 | 128, 1);\n store(ptr, c1 & 63 | 128, 2);\n off += 3; ++pos;\n }\n }\n store(buf + off, 0);\n return buf;\n }\n}\n\nexport function parseInt(str: String, radix: i32 = 0): f64 {\n return parse(str, radix);\n}\n\nexport function parseI32(str: String, radix: i32 = 0): i32 {\n return parse(str, radix);\n}\n\nexport function parseI64(str: String, radix: i32 = 0): i64 {\n return parse(str, radix);\n}\n\n// FIXME: naive implementation\nexport function parseFloat(str: String): f64 {\n var len: i32 = str.length;\n if (!len) return NaN;\n\n var ptr = changetype(str) /* + HEAD -> offset */;\n var code = load(ptr, HEADER_SIZE);\n\n // determine sign\n var sign: f64;\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = load(ptr += 2, HEADER_SIZE);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = load(ptr += 2, HEADER_SIZE);\n sign = 1;\n } else {\n sign = 1;\n }\n\n // calculate value\n var num: f64 = 0;\n while (len--) {\n code = load(ptr, HEADER_SIZE);\n if (code == CharCode.DOT) {\n ptr += 2;\n let fac: f64 = 0.1; // precision :(\n while (len--) {\n code = load(ptr, HEADER_SIZE);\n if (code == CharCode.E || code == CharCode.e) {\n assert(false); // TODO\n }\n code -= CharCode._0;\n if (code > 9) break;\n num += code * fac;\n fac *= 0.1;\n ptr += 2;\n }\n break;\n }\n code -= CharCode._0;\n if (code >= 10) break;\n num = (num * 10) + code;\n ptr += 2;\n }\n return sign * num;\n}\n',symbol:'import { Map } from "./map";\n\nvar stringToId: Map;\nvar idToString: Map;\nvar nextId: usize = 12; // Symbol.unscopables + 1\n\n@unmanaged export class symbol {}\n\ntype Symbol = symbol;\n\nexport function Symbol(description: string | null = null): symbol {\n var id = nextId++;\n if (!id) unreachable(); // out of ids\n return changetype(id);\n}\n\nexport namespace Symbol {\n\n // well-known symbols\n export const hasInstance = changetype(1);\n export const concatSpreadable = changetype(2);\n export const isRegExp = changetype(3);\n export const iterator = changetype(3);\n export const match = changetype(4);\n export const replace = changetype(5);\n export const search = changetype(6);\n export const species = changetype(7);\n export const split = changetype(8);\n export const toPrimitive = changetype(9);\n export const toStringTag = changetype(10);\n export const unscopables = changetype(11);\n\n /* tslint:disable */// not valid TS\n export function for(key: string): symbol {\n if (!stringToId) { stringToId = new Map(); idToString = new Map(); }\n else if (stringToId.has(key)) return changetype(stringToId.get(key));\n var id = nextId++;\n if (!id) unreachable(); // out of ids\n stringToId.set(key, id);\n idToString.set(id, key);\n return changetype(id);\n }\n /* tslint:enable */\n\n export function keyFor(sym: symbol): string | null {\n return idToString !== null && idToString.has(changetype(sym))\n ? idToString.get(changetype(sym))\n : null;\n }\n}\n',table:"export namespace table {\n\n // export function copy(dst: u32, src: u32, n: u32): void {\n // __table_copy(dst, src, n);\n // }\n\n // Passive elements\n\n // export function init(elementIndex: u32, srcOffset: u32, dstOffset: u32, n: u32): void {\n // __table_init(elementIndex, srcOffset, dstOffset, n);\n // }\n\n // export function drop(elementIndex: u32): void {\n // __table_drop(elementIndex);\n // }\n}\n",typedarray:'import {\n TypedArray\n} from "./internal/typedarray";\n\nexport class Int8Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int8Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint8Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint8Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint8ClampedArray extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n @inline @operator("[]=")\n protected __set(index: i32, value: i32): void {\n super.__set(index, max(min(value, 255), 0));\n }\n\n @inline @operator("{}=")\n protected __unchecked_set(index: i32, value: i32): void {\n super.__unchecked_set(index, max(min(value, 255), 0));\n }\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint8ClampedArray {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Int16Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int16Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint16Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint16Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Int32Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int32Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint32Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint32Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Int64Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Int64Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Uint64Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Uint64Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Float32Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Float32Array {\n return changetype(super.subarray(begin, end));\n }\n}\n\nexport class Float64Array extends TypedArray {\n static readonly BYTES_PER_ELEMENT: usize = sizeof();\n\n subarray(begin: i32 = 0, end: i32 = 0x7fffffff): Float64Array {\n return changetype(super.subarray(begin, end));\n }\n}\n'}):(()=>{const e=path.join(".","..","std","assembly"),n={};return __webpack_require__(!function(){var e=new Error("Cannot find module 'glob'");throw e.code="MODULE_NOT_FOUND",e}()).sync("**/!(*.d).ts",{cwd:e}).forEach(t=>n[t.replace(/\.ts$/,"")]=fs.readFileSync(path.join(e,t),"utf8")),n})(),exports.definitionFiles=exports.isBundle?Object({assembly:"/**\n * Environment definitions for compiling AssemblyScript to WebAssembly using asc.\n * @module std/assembly\n *//***/\n\n/// \n\n// Types\n\n/** An 8-bit signed integer. */\ndeclare type i8 = number;\n/** A 16-bit signed integer. */\ndeclare type i16 = number;\n/** A 32-bit signed integer. */\ndeclare type i32 = number;\n/** A 64-bit signed integer. */\ndeclare type i64 = number;\n/** A 32-bit signed integer when targeting 32-bit WebAssembly or a 64-bit signed integer when targeting 64-bit WebAssembly. */\ndeclare type isize = number;\n/** An 8-bit unsigned integer. */\ndeclare type u8 = number;\n/** A 16-bit unsigned integer. */\ndeclare type u16 = number;\n/** A 32-bit unsigned integer. */\ndeclare type u32 = number;\n/** A 64-bit unsigned integer. */\ndeclare type u64 = number;\n/** A 32-bit unsigned integer when targeting 32-bit WebAssembly or a 64-bit unsigned integer when targeting 64-bit WebAssembly. */\ndeclare type usize = number;\n/** A 1-bit unsigned integer. */\ndeclare type bool = boolean | number;\n/** A 32-bit float. */\ndeclare type f32 = number;\n/** A 64-bit float. */\ndeclare type f64 = number;\n\n// Compiler hints\n\n/** Compiler target. 0 = JS, 1 = WASM32, 2 = WASM64. */\ndeclare const ASC_TARGET: i32;\n/** Provided noTreeshaking option. */\ndeclare const ASC_NO_TREESHAKING: bool;\n/** Provided noAssert option. */\ndeclare const ASC_NO_ASSERT: bool;\n/** Provided memoryBase option. */\ndeclare const ASC_MEMORY_BASE: i32;\n/** Provided optimizeLevel option. */\ndeclare const ASC_OPTIMIZE_LEVEL: i32;\n/** Provided shrinkLevel option. */\ndeclare const ASC_SHRINK_LEVEL: i32;\n/** Whether the mutable global feature is enabled. */\ndeclare const ASC_FEATURE_MUTABLE_GLOBAL: bool;\n/** Whether the sign extension feature is enabled. */\ndeclare const ASC_FEATURE_SIGN_EXTENSION: bool;\n\n// Builtins\n\n/** Performs the sign-agnostic count leading zero bits operation on a 32-bit or 64-bit integer. All zero bits are considered leading if the value is zero. */\ndeclare function clz(value: T): T;\n/** Performs the sign-agnostic count tailing zero bits operation on a 32-bit or 64-bit integer. All zero bits are considered trailing if the value is zero. */\ndeclare function ctz(value: T): T;\n/** Performs the sign-agnostic count number of one bits operation on a 32-bit or 64-bit integer. */\ndeclare function popcnt(value: T): T;\n/** Performs the sign-agnostic rotate left operation on a 32-bit or 64-bit integer. */\ndeclare function rotl(value: T, shift: T): T;\n/** Performs the sign-agnostic rotate right operation on a 32-bit or 64-bit integer. */\ndeclare function rotr(value: T, shift: T): T;\n/** Computes the absolute value of an integer or float. */\ndeclare function abs(value: T): T;\n/** Determines the maximum of two integers or floats. If either operand is `NaN`, returns `NaN`. */\ndeclare function max(left: T, right: T): T;\n/** Determines the minimum of two integers or floats. If either operand is `NaN`, returns `NaN`. */\ndeclare function min(left: T, right: T): T;\n/** Performs the ceiling operation on a 32-bit or 64-bit float. */\ndeclare function ceil(value: T): T;\n/** Composes a 32-bit or 64-bit float from the magnitude of `x` and the sign of `y`. */\ndeclare function copysign(x: T, y: T): T;\n/** Performs the floor operation on a 32-bit or 64-bit float. */\ndeclare function floor(value: T): T;\n/** Rounds to the nearest integer tied to even of a 32-bit or 64-bit float. */\ndeclare function nearest(value: T): T;\n/** Reinterprets the bits of the specified value as type `T`. Valid reinterpretations are u32/i32 to/from f32 and u64/i64 to/from f64. */\ndeclare function reinterpret(value: number): T;\n/** Selects one of two pre-evaluated values depending on the condition. */\ndeclare function select(ifTrue: T, ifFalse: T, condition: bool): T;\n/** Calculates the square root of a 32-bit or 64-bit float. */\ndeclare function sqrt(value: T): T;\n/** Rounds to the nearest integer towards zero of a 32-bit or 64-bit float. */\ndeclare function trunc(value: T): T;\n/** Loads a value of the specified type from memory. Equivalent to dereferncing a pointer in other languages. */\ndeclare function load(ptr: usize, constantOffset?: usize): T;\n/** Stores a value of the specified type to memory. Equivalent to dereferencing a pointer in other languages when assigning a value. */\ndeclare function store(ptr: usize, value: any, constantOffset?: usize): void;\n/** Emits an unreachable operation that results in a runtime error when executed. Both a statement and an expression of any type. */\ndeclare function unreachable(): any; // sic\n\n/** NaN (not a number) as a 32-bit or 64-bit float depending on context. */\ndeclare const NaN: f32 | f64;\n/** Positive infinity as a 32-bit or 64-bit float depending on context. */\ndeclare const Infinity: f32 | f64;\n/** Heap base offset. */\ndeclare const HEAP_BASE: usize;\n/** Determines the byte size of the specified underlying core type. Compiles to a constant. */\ndeclare function sizeof(): usize;\n/** Determines the alignment (log2) of the specified underlying core type. Compiles to a constant. */\ndeclare function alignof(): usize;\n/** Determines the offset of the specified field within the given class type. Returns the class type's end offset if field name has been omitted. Compiles to a constant. */\ndeclare function offsetof(fieldName?: string): usize;\n/** Changes the type of any value of `usize` kind to another one of `usize` kind. Useful for casting class instances to their pointer values and vice-versa. Beware that this is unsafe.*/\ndeclare function changetype(value: any): T;\n/** Explicitly requests no bounds checks on the provided expression. Useful for array accesses. */\ndeclare function unchecked(value: T): T;\n/** Emits a `call_indirect` instruction, calling the specified function in the function table by index with the specified arguments. Does result in a runtime error if the arguments do not match the called function. */\ndeclare function call_indirect(target: Function | u32, ...args: any[]): T;\n/** Tests if a 32-bit or 64-bit float is `NaN`. */\ndeclare function isNaN(value: T): bool;\n/** Tests if a 32-bit or 64-bit float is finite, that is not `NaN` or +/-`Infinity`. */\ndeclare function isFinite(value: T): bool;\n/** Tests if the specified type *or* expression is of an integer type and not a reference. Compiles to a constant. */\ndeclare function isInteger(value?: any): value is number;\n/** Tests if the specified type *or* expression is of a float type. Compiles to a constant. */\ndeclare function isFloat(value?: any): value is number;\n/** Tests if the specified type *or* expression can represent negative numbers. Compiles to a constant. */\ndeclare function isSigned(value?: any): value is number;\n/** Tests if the specified type *or* expression is of a reference type. Compiles to a constant. */\ndeclare function isReference(value?: any): value is object | string;\n/** Tests if the specified type *or* expression can be used as a string. Compiles to a constant. */\ndeclare function isString(value?: any): value is string | String;\n/** Tests if the specified type *or* expression can be used as an array. Compiles to a constant. */\ndeclare function isArray(value?: any): value is Array;\n/** Tests if the specified expression resolves to a defined element. Compiles to a constant. */\ndeclare function isDefined(expression: any): bool;\n/** Tests if the specified expression evaluates to a constant value. Compiles to a constant. */\ndeclare function isConstant(expression: any): bool;\n/** Tests if the specified type *or* expression is of a managed type. Compiles to a constant. */\ndeclare function isManaged(value?: any): bool;\n/** Traps if the specified value is not true-ish, otherwise returns the (non-nullable) value. */\ndeclare function assert(isTrueish: T, message?: string): T & object; // any better way to model `: T != null`?\n/** Parses an integer string to a 64-bit float. */\ndeclare function parseInt(str: string, radix?: i32): f64;\n/** Parses an integer string to a 32-bit integer. */\ndeclare function parseI32(str: string, radix?: i32): i32;\n/** Parses an integer string to a 64-bit integer. */\ndeclare function parseI64(str: string, radix?: i32): i64;\n/** Parses a string to a 64-bit float. */\ndeclare function parseFloat(str: string): f64;\n/** Returns the 64-bit floating-point remainder of `x/y`. */\ndeclare function fmod(x: f64, y: f64): f64;\n/** Returns the 32-bit floating-point remainder of `x/y`. */\ndeclare function fmodf(x: f32, y: f32): f32;\n\n/** Converts any other numeric value to an 8-bit signed integer. */\ndeclare function i8(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;\ndeclare namespace i8 {\n /** Smallest representable value. */\n export const MIN_VALUE: i8;\n /** Largest representable value. */\n export const MAX_VALUE: i8;\n}\n/** Converts any other numeric value to a 16-bit signed integer. */\ndeclare function i16(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;\ndeclare namespace i16 {\n /** Smallest representable value. */\n export const MIN_VALUE: i16;\n /** Largest representable value. */\n export const MAX_VALUE: i16;\n}\n/** Converts any other numeric value to a 32-bit signed integer. */\ndeclare function i32(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i32;\ndeclare namespace i32 {\n /** Smallest representable value. */\n export const MIN_VALUE: i32;\n /** Largest representable value. */\n export const MAX_VALUE: i32;\n /** Loads an 8-bit signed integer from memory and returns it as a 32-bit integer. */\n export function load8_s(offset: usize, constantOffset?: usize): i32;\n /** Loads an 8-bit unsigned integer from memory and returns it as a 32-bit integer. */\n export function load8_u(offset: usize, constantOffset?: usize): i32;\n /** Loads a 16-bit signed integer from memory and returns it as a 32-bit integer. */\n export function load16_s(offset: usize, constantOffset?: usize): i32;\n /** Loads a 16-bit unsigned integer from memory and returns it as a 32-bit integer. */\n export function load16_u(offset: usize, constantOffset?: usize): i32;\n /** Loads a 32-bit integer from memory. */\n export function load(offset: usize, constantOffset?: usize): i32;\n /** Stores a 32-bit integer to memory as an 8-bit integer. */\n export function store8(offset: usize, value: i32, constantOffset?: usize): void;\n /** Stores a 32-bit integer to memory as a 16-bit integer. */\n export function store16(offset: usize, value: i32, constantOffset?: usize): void;\n /** Stores a 32-bit integer to memory. */\n export function store(offset: usize, value: i32, constantOffset?: usize): void;\n}\n/** Converts any other numeric value to a 64-bit signed integer. */\ndeclare function i64(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i64;\ndeclare namespace i64 {\n /** Smallest representable value. */\n export const MIN_VALUE: i64;\n /** Largest representable value. */\n export const MAX_VALUE: i64;\n /** Loads an 8-bit signed integer from memory and returns it as a 64-bit signed integer. */\n export function load8_s(offset: usize, constantOffset?: usize): i64;\n /** Loads an 8-bit unsigned integer from memory and returns it as a 64-bit unsigned integer. */\n export function load8_u(offset: usize, constantOffset?: usize): u64;\n /** Loads a 16-bit signed integer from memory and returns it as a 64-bit signed integer. */\n export function load16_s(offset: usize, constantOffset?: usize): i64;\n /** Loads a 16-bit unsigned integer from memory and returns it as a 64-bit unsigned integer. */\n export function load16_u(offset: usize, constantOffset?: usize): u64;\n /** Loads a 32-bit signed integer from memory and returns it as a 64-bit signed integer. */\n export function load32_s(offset: usize, constantOffset?: usize): i64;\n /** Loads a 32-bit unsigned integer from memory and returns it as a 64-bit unsigned integer. */\n export function load32_u(offset: usize, constantOffset?: usize): u64;\n /** Loads a 64-bit unsigned integer from memory. */\n export function load(offset: usize, constantOffset?: usize): i64;\n /** Stores a 64-bit integer to memory as an 8-bit integer. */\n export function store8(offset: usize, value: i64, constantOffset?: usize): void;\n /** Stores a 64-bit integer to memory as a 16-bit integer. */\n export function store16(offset: usize, value: i64, constantOffset?: usize): void;\n /** Stores a 64-bit integer to memory as a 32-bit integer. */\n export function store32(offset: usize, value: i64, constantOffset?: usize): void;\n /** Stores a 64-bit integer to memory. */\n export function store(offset: usize, value: i64, constantOffset?: usize): void;\n}\n/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */\ndeclare var isize: i32 | i64;\n/** Converts any other numeric value to an 8-bit unsigned integer. */\ndeclare function u8(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;\ndeclare namespace u8 {\n /** Smallest representable value. */\n export const MIN_VALUE: u8;\n /** Largest representable value. */\n export const MAX_VALUE: u8;\n}\n/** Converts any other numeric value to a 16-bit unsigned integer. */\ndeclare function u16(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i8;\ndeclare namespace u16 {\n /** Smallest representable value. */\n export const MIN_VALUE: u16;\n /** Largest representable value. */\n export const MAX_VALUE: u16;\n}\n/** Converts any other numeric value to a 32-bit unsigned integer. */\ndeclare function u32(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i32;\ndeclare namespace u32 {\n /** Smallest representable value. */\n export const MIN_VALUE: u32;\n /** Largest representable value. */\n export const MAX_VALUE: u32;\n}\n/** Converts any other numeric value to a 64-bit unsigned integer. */\ndeclare function u64(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): i64;\ndeclare namespace u64 {\n /** Smallest representable value. */\n export const MIN_VALUE: u64;\n /** Largest representable value. */\n export const MAX_VALUE: u64;\n}\n/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */\ndeclare var usize: u32 | u64;\n/** Converts any other numeric value to a 1-bit unsigned integer. */\ndeclare function bool(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): bool;\ndeclare namespace bool {\n /** Smallest representable value. */\n export const MIN_VALUE: bool;\n /** Largest representable value. */\n export const MAX_VALUE: bool;\n}\n/** Converts any other numeric value to a 32-bit float. */\ndeclare function f32(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): f32;\ndeclare namespace f32 {\n /** Smallest representable value. */\n export const MIN_VALUE: f32;\n /** Largest representable value. */\n export const MAX_VALUE: f32;\n /** Smallest normalized positive value. */\n export const MIN_POSITIVE_VALUE: f32;\n /** Smallest safely representable integer value. */\n export const MIN_SAFE_INTEGER: f32;\n /** Largest safely representable integer value. */\n export const MAX_SAFE_INTEGER: f32;\n /** Difference between 1 and the smallest representable value greater than 1. */\n export const EPSILON: f32;\n /** Returns the floating-point remainder of `x / y` (rounded towards zero). */\n export function mod(x: f32, y: f32): f32;\n /** Returns the floating-point remainder of `x / y` (rounded to nearest). */\n export function rem(x: f32, y: f32): f32;\n /** Loads a 32-bit float from memory. */\n export function load(offset: usize, constantOffset?: usize): f32;\n /** Stores a 32-bit float to memory. */\n export function store(offset: usize, value: f32, constantOffset?: usize): void;\n}\n/** Converts any other numeric value to a 64-bit float. */\ndeclare function f64(value: i8 | i16 | i32 | i64 | isize | u8 | u16 | u32 | u64 | usize | bool | f32 | f64): f64;\ndeclare namespace f64 {\n /** Smallest representable value. */\n export const MIN_VALUE: f64;\n /** Largest representable value. */\n export const MAX_VALUE: f64;\n /** Smallest normalized positive value. */\n export const MIN_POSITIVE_VALUE: f64;\n /** Smallest safely representable integer value. */\n export const MIN_SAFE_INTEGER: f64;\n /** Largest safely representable integer value. */\n export const MAX_SAFE_INTEGER: f64;\n /** Difference between 1 and the smallest representable value greater than 1. */\n export const EPSILON: f64;\n /** Loads a 64-bit float from memory. */\n export function load(offset: usize, constantOffset?: usize): f64;\n /** Stores a 64-bit float to memory. */\n export function store(offset: usize, value: f64, constantOffset?: usize): void;\n}\n\n// User-defined diagnostic macros\n\n/** Emits a user-defined diagnostic error when encountered. */\ndeclare function ERROR(message?: any): void;\n/** Emits a user-defined diagnostic warning when encountered. */\ndeclare function WARNING(message?: any): void;\n/** Emits a user-defined diagnostic info when encountered. */\ndeclare function INFO(message?: any): void;\n\n// Polyfills\n\n/** Performs the sign-agnostic reverse bytes **/\ndeclare function bswap(value: T): T;\n/** Performs the sign-agnostic reverse bytes only for last 16-bit **/\ndeclare function bswap16(value: T): T;\n\n// Standard library\n\n/** Memory operations. */\ndeclare namespace memory {\n /** Returns the current memory size in units of pages. One page is 64kb. */\n export function size(): i32;\n /** Grows linear memory by a given unsigned delta of pages. One page is 64kb. Returns the previous memory size in units of pages or `-1` on failure. */\n export function grow(value: i32): i32;\n /** Sets n bytes beginning at the specified destination in memory to the specified byte value. */\n export function fill(dst: usize, value: u8, count: usize): void;\n /** Copies n bytes from the specified source to the specified destination in memory. These regions may overlap. */\n export function copy(dst: usize, src: usize, n: usize): void;\n /** Copies elements from a passive element segment to a table. */\n // export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void;\n /** Prevents further use of a passive element segment. */\n // export function drop(segmentIndex: u32): void;\n /** Copies elements from one region of a table to another region. */\n export function allocate(size: usize): usize;\n /** Disposes a chunk of memory by its pointer. */\n export function free(ptr: usize): void;\n /** Compares two chunks of memory. Returns `0` if equal, otherwise the difference of the first differing bytes. */\n export function compare(vl: usize, vr: usize, n: usize): i32;\n /** Resets the allocator to its initial state, if supported. */\n export function reset(): void;\n}\n\n/** Garbage collector operations. */\ndeclare namespace gc {\n /** Allocates a managed object identified by its visitor function. */\n export function allocate(size: usize, visitFn: (ref: usize) => void): usize;\n /** Performs a full garbage collection cycle. */\n export function collect(): void;\n}\n\n/** Table operations. */\ndeclare namespace table {\n /** Copies elements from a passive element segment to a table. */\n // export function init(elementIndex: u32, srcOffset: u32, dstOffset: u32, n: u32): void;\n /** Prevents further use of a passive element segment. */\n // export function drop(elementIndex: u32): void;\n /** Copies elements from one region of a table to another region. */\n // export function copy(dest: u32, src: u32, n: u32): void;\n}\n\n/** Class representing a generic, fixed-length raw binary data buffer. */\ndeclare class ArrayBuffer {\n /** The size, in bytes, of the array. */\n readonly byteLength: i32;\n /** Unsafe pointer to the start of the data in memory. */\n readonly data: usize;\n /** Constructs a new array buffer of the given length in bytes. */\n constructor(length: i32, unsafe?: bool);\n /** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */\n slice(begin?: i32, end?: i32): ArrayBuffer;\n}\n\n/** Interface for a typed view on an array buffer. */\ninterface ArrayBufferView {\n [key: number]: T;\n /** The {@link ArrayBuffer} referenced by this view. */\n readonly buffer: ArrayBuffer;\n /** The offset in bytes from the start of the referenced {@link ArrayBuffer}. */\n readonly byteOffset: i32;\n /** The length in bytes from the start of the referenced {@link ArrayBuffer}. */\n readonly byteLength: i32;\n}\n\n/* @internal */\ndeclare abstract class TypedArray implements ArrayBufferView {\n [key: number]: T;\n /** Number of bytes per element. */\n static readonly BYTES_PER_ELEMENT: usize;\n /** Constructs a new typed array. */\n constructor(length: i32);\n /** The {@link ArrayBuffer} referenced by this view. */\n readonly buffer: ArrayBuffer;\n /** The offset in bytes from the start of the referenced {@link ArrayBuffer}. */\n readonly byteOffset: i32;\n /** The length in bytes from the start of the referenced {@link ArrayBuffer}. */\n readonly byteLength: i32;\n /** The length (in elements). */\n readonly length: i32;\n /** Returns a new TypedArray of this type on the same ArrayBuffer from begin inclusive to end exclusive. */\n subarray(begin?: i32, end?: i32): this;\n}\n\n/** An array of twos-complement 8-bit signed integers. */\ndeclare class Int8Array extends TypedArray {}\n/** An array of 8-bit unsigned integers. */\ndeclare class Uint8Array extends TypedArray {}\n/** An array of twos-complement 16-bit signed integers. */\ndeclare class Int16Array extends TypedArray {}\n/** An array of 16-bit unsigned integers. */\ndeclare class Uint16Array extends TypedArray {}\n/** An array of twos-complement 32-bit signed integers. */\ndeclare class Int32Array extends TypedArray {}\n/** An array of 32-bit unsigned integers. */\ndeclare class Uint32Array extends TypedArray {}\n/** An array of twos-complement 64-bit signed integers. */\ndeclare class Int64Array extends TypedArray {}\n/** An array of 64-bit unsigned integers. */\ndeclare class Uint64Array extends TypedArray {}\n/** An array of 32-bit floating point numbers. */\ndeclare class Float32Array extends TypedArray {}\n/** An array of 64-bit floating point numbers. */\ndeclare class Float64Array extends TypedArray {}\n\n/** Class representing a sequence of values of type `T`. */\ndeclare class Array {\n [key: number]: T;\n /** Current length of the array. */\n length: i32;\n /** Constructs a new array. */\n constructor(capacity?: i32);\n fill(value: T, start?: i32, end?: i32): this;\n every(callbackfn: (element: T, index: i32, array?: Array) => bool): bool;\n findIndex(predicate: (element: T, index: i32, array?: Array) => bool): i32;\n includes(searchElement: T, fromIndex?: i32): bool;\n indexOf(searchElement: T, fromIndex?: i32): i32;\n lastIndexOf(searchElement: T, fromIndex?: i32): i32;\n push(element: T): i32;\n concat(items: T[]): T[];\n pop(): T;\n forEach(callbackfn: (value: T, index: i32, array: Array) => void): void;\n map(callbackfn: (value: T, index: i32, array: Array) => U): Array;\n filter(callbackfn: (value: T, index: i32, array: Array) => bool): Array;\n reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U): U;\n reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U): U;\n shift(): T;\n some(callbackfn: (element: T, index: i32, array?: Array) => bool): bool;\n unshift(element: T): i32;\n slice(from: i32, to?: i32): T[];\n splice(start: i32, deleteCount?: i32): void;\n sort(comparator?: (a: T, b: T) => i32): this;\n join(separator?: string): string;\n reverse(): T[];\n toString(): string;\n}\n\n/** Class representing a sequence of characters. */\ndeclare class String {\n\n static fromCharCode(ls: i32, hs?: i32): string;\n static fromCharCodes(arr: u16[]): string;\n static fromCodePoint(code: i32): string;\n static fromCodePoints(arr: i32[]): string;\n\n readonly length: i32;\n readonly lengthUTF8: i32;\n\n charAt(index: u32): string;\n charCodeAt(index: u32): u16;\n concat(other: string): string;\n endsWith(other: string): bool;\n indexOf(other: string, fromIndex?: i32): u32;\n lastIndexOf(other: string, fromIndex?: i32): i32;\n includes(other: string): bool;\n startsWith(other: string): bool;\n substr(start: u32, length?: u32): string;\n substring(start: u32, end?: u32): string;\n trim(): string;\n trimLeft(): string;\n trimRight(): string;\n trimStart(): string;\n trimEnd(): string;\n padStart(targetLength: i32, padString?: string): string;\n padEnd(targetLength: i32, padString?: string): string;\n repeat(count?: i32): string;\n split(separator?: string, limit?: i32): string[];\n toString(): string;\n static fromUTF8(ptr: usize, len: usize): string;\n toUTF8(): usize;\n}\n\n/** Class for representing a runtime error. Base class of all errors. */\ndeclare class Error {\n\n /** Error name. */\n name: string;\n\n /** Message provided on construction. */\n message: string;\n\n /** Stack trace. */\n stack: string;\n\n /** Constructs a new error, optionally with a message. */\n constructor(message?: string);\n}\n\n/** Class for indicating an error when a value is not in the set or range of allowed values. */\ndeclare class RangeError extends Error { }\n\ninterface Boolean {}\ninterface Function {}\ninterface IArguments {}\ninterface Number {}\ninterface Object {}\ninterface RegExp {}\n\ndeclare class Map {\n readonly size: i32;\n has(key: K): bool;\n set(key: K, value: V): void;\n get(key: K): V;\n delete(key: K): bool;\n clear(): void;\n}\n\ndeclare class Set {\n readonly size: i32;\n has(value: T): bool;\n add(value: T): void;\n delete(value: T): bool;\n clear(): void;\n}\n\ninterface SymbolConstructor {\n (description?: string | null): symbol;\n for(key: string): symbol;\n keyFor(sym: symbol): string | null;\n}\ndeclare const Symbol: SymbolConstructor;\n\ninterface IMath {\n /** The base of natural logarithms, e, approximately 2.718. */\n readonly E: T;\n /** The natural logarithm of 2, approximately 0.693. */\n readonly LN2: T;\n /** The natural logarithm of 10, approximately 2.302. */\n readonly LN10: T;\n /** The base 2 logarithm of e, approximately 1.442. */\n readonly LOG2E: T;\n /** The base 10 logarithm of e, approximately 0.434. */\n readonly LOG10E: T;\n /** The ratio of the circumference of a circle to its diameter, approximately 3.14159. */\n readonly PI: T;\n /** The square root of 1/2, approximately 0.707. */\n readonly SQRT1_2: T;\n /** The square root of 2, approximately 1.414. */\n readonly SQRT2: T;\n /** Returns the absolute value of `x`. */\n abs(x: T): T;\n /** Returns the arccosine (in radians) of `x`. */\n acos(x: T): T;\n /** Returns the hyperbolic arc-cosine of `x`. */\n acosh(x: T): T;\n /** Returns the arcsine (in radians) of `x` */\n asin(x: T): T;\n /** Returns the hyperbolic arcsine of `x`. */\n asinh(x: T): T;\n /** Returns the arctangent (in radians) of `x`. */\n atan(x: T): T;\n /** Returns the arctangent of the quotient of its arguments. */\n atan2(y: T, x: T): T;\n /** Returns the hyperbolic arctangent of `x`. */\n atanh(x: T): T;\n /** Returns the cube root of `x`. */\n cbrt(x: T): T;\n /** Returns the smallest integer greater than or equal to `x`. */\n ceil(x: T): T;\n /** Returns the number of leading zero bits in the 32-bit binary representation of `x`. */\n clz32(x: T): T;\n /** Returns the cosine (in radians) of `x`. */\n cos(x: T): T;\n /** Returns the hyperbolic cosine of `x`. */\n cosh(x: T): T;\n /** Returns e to the power of `x`. */\n exp(x: T): T;\n /** Returns e to the power of `x`, minus 1. */\n expm1(x: T): T;\n /** Returns the largest integer less than or equal to `x`. */\n floor(x: T): T;\n /** Returns the nearest 32-bit single precision float representation of `x`. */\n fround(x: T): f32;\n /** Returns the square root of the sum of squares of its arguments. */\n hypot(value1: T, value2: T): T; // TODO: rest\n /** Returns the result of the C-like 32-bit multiplication of `a` and `b`. */\n imul(a: T, b: T): T;\n /** Returns the natural logarithm (base e) of `x`. */\n log(x: T): T;\n /** Returns the base 10 logarithm of `x`. */\n log10(x: T): T;\n /** Returns the natural logarithm (base e) of 1 + `x`. */\n log1p(x: T): T;\n /** Returns the base 2 logarithm of `x`. */\n log2(x: T): T;\n /** Returns the largest-valued number of its arguments. */\n max(value1: T, value2: T): T; // TODO: rest\n /** Returns the lowest-valued number of its arguments. */\n min(value1: T, value2: T): T; // TODO: rest\n /** Returns `base` to the power of `exponent`. */\n pow(base: T, exponent: T): T;\n /** Returns a pseudo-random number in the range from 0.0 inclusive up to but not including 1.0. */\n random(): T;\n /** Returns the value of `x` rounded to the nearest integer. */\n round(x: T): T;\n /** Returns the sign of `x`, indicating whether the number is positive, negative or zero. */\n sign(x: T): T;\n /** Returns the sine of `x`. */\n sin(x: T): T;\n /** Returns the hyperbolic sine of `x`. */\n sinh(x: T): T;\n /** Returns the square root of `x`. */\n sqrt(x: T): T;\n /** Returns the tangent of `x`. */\n tan(x: T): T;\n /** Returns the hyperbolic tangent of `x`. */\n tanh(x: T): T;\n /** Returns the integer part of `x` by removing any fractional digits. */\n trunc(x: T): T;\n}\n\ninterface INativeMath extends IMath {\n /** Seeds the random number generator. */\n seedRandom(value: i64): void;\n /** Returns the floating-point remainder of `x / y` (rounded towards zero). */\n mod(x: T, y: T): T;\n /** Returns the floating-point remainder of `x / y` (rounded to nearest). */\n rem(x: T, y: T): T;\n}\n\n/** Double precision math imported from JavaScript. */\ndeclare const JSMath: IMath;\n/** Double precision math implemented natively. */\ndeclare const NativeMath: INativeMath;\n/** Single precision math implemented natively. */\ndeclare const NativeMathf: INativeMath;\n/** Alias of {@link NativeMath} or {@link JSMath} respectively. Defaults to `NativeMath`. */\ndeclare const Math: IMath;\n/** Alias of {@link NativeMathf} or {@link JSMath} respectively. Defaults to `NativeMathf`. */\ndeclare const Mathf: IMath;\n\n/** Environmental tracing function for debugging purposes. */\ndeclare function trace(msg: string, n?: i32, a0?: f64, a1?: f64, a2?: f64, a3?: f64, a4?: f64): void;\n\n// Decorators\n\n/** Annotates an element as a program global. */\ndeclare function global(target: Function, propertyKey: string, descriptor: any): void;\n\n/** Annotates a method as a binary operator overload for the specified `token`. */\ndeclare function operator(token: string): (target: any, propertyKey: string, descriptor: any) => void;\ndeclare namespace operator {\n /** Annotates a method as a binary operator overload for the specified `token`. */\n export function binary(token: string): (target: any, propertyKey: string, descriptor: any) => void;\n /** Annotates a method as an unary prefix operator overload for the specified `token`. */\n export function prefix(token: string): (target: any, propertyKey: string, descriptor: any) => void;\n /** Annotates a method as an unary postfix operator overload for the specified `token`. */\n export function postfix(token: string): (target: any, propertyKey: string, descriptor: any) => void;\n}\n\n/** Annotates a class as being unmanaged with limited capabilities. */\ndeclare function unmanaged(target: Function): any;\n\n/** Annotates a class as being sealed / non-derivable. */\ndeclare function sealed(target: Function): any;\n\n/** Annotates a method or function as always inlined. */\ndeclare function inline(target: any, propertyKey: any, descriptor: any): any;\n\n/** Annotates an explicit external name of a function or global. */\ndeclare function external(target: any, propertyKey: any, descriptor: any): any;\n",portable:"/**\n * Environment definitions for compiling AssemblyScript to JavaScript using tsc.\n *\n * Note that semantic differences require additional explicit conversions for full compatibility.\n * For example, when casting an i32 to an u8, doing `(someI32 & 0xff)` will yield the same\n * result when compiling to WebAssembly or JS while `someI32` alone does nothing in JS.\n *\n * Note that i64's are not portable (JS numbers are IEEE754 doubles with a maximum safe integer\n * value of 2^53-1) and instead require a compatibility layer to work in JS as well, as for example\n * {@link glue/js/i64} respectively {@link glue/wasm/i64}.\n *\n * @module std/portable\n *//***/\n\n/// \n\n// Types\n\ndeclare type i8 = number;\ndeclare type i16 = number;\ndeclare type i32 = number;\ndeclare type isize = number;\ndeclare type u8 = number;\ndeclare type u16 = number;\ndeclare type u32 = number;\ndeclare type bool = boolean;\ndeclare type usize = number;\ndeclare type f32 = number;\ndeclare type f64 = number;\n\n// Compiler hints\n\n/** Compiler target. 0 = JS, 1 = WASM32, 2 = WASM64. */\ndeclare const ASC_TARGET: i32;\n\n// Builtins\n\n/** Performs the sign-agnostic count leading zero bits operation on a 32-bit integer. All zero bits are considered leading if the value is zero. */\ndeclare function clz(value: T): T;\n/** Performs the sign-agnostic count tailing zero bits operation on a 32-bit integer. All zero bits are considered trailing if the value is zero. */\ndeclare function ctz(value: T): T;\n/** Performs the sign-agnostic count number of one bits operation on a 32-bit integer. */\ndeclare function popcnt(value: T): T;\n/** Performs the sign-agnostic rotate left operation on a 32-bit integer. */\ndeclare function rotl(value: T, shift: T): T;\n/** Performs the sign-agnostic rotate right operation on a 32-bit integer. */\ndeclare function rotr(value: T, shift: T): T;\n/** Computes the absolute value of an integer or float. */\ndeclare function abs(value: T): T;\n/** Determines the maximum of two integers or floats. If either operand is `NaN`, returns `NaN`. */\ndeclare function max(left: T, right: T): T;\n/** Determines the minimum of two integers or floats. If either operand is `NaN`, returns `NaN`. */\ndeclare function min(left: T, right: T): T;\n/** Composes a 32-bit or 64-bit float from the magnitude of `x` and the sign of `y`. */\ndeclare function copysign(x: T, y: T): T;\n/** Performs the ceiling operation on a 32-bit or 64-bit float. */\ndeclare function ceil(value: T): T;\n/** Performs the floor operation on a 32-bit or 64-bit float. */\ndeclare function floor(value: T): T;\n/** Rounds to the nearest integer tied to even of a 32-bit or 64-bit float. */\ndeclare function nearest(value: T): T;\n/** Selects one of two pre-evaluated values depending on the condition. */\ndeclare function select(ifTrue: T, ifFalse: T, condition: bool): T;\n/** Calculates the square root of a 32-bit or 64-bit float. */\ndeclare function sqrt(value: T): T;\n/** Rounds to the nearest integer towards zero of a 32-bit or 64-bit float. */\ndeclare function trunc(value: T): T;\n/** Loads a value of the specified type from memory. Type must be `u8`. */\ndeclare function load(ptr: usize, constantOffset?: usize): T;\n/** Stores a value of the specified type to memory. Type must be `u8`. */\ndeclare function store(ptr: usize, value: T, constantOffset?: usize): void;\n/** Emits an unreachable operation that results in a runtime error when executed. */\ndeclare function unreachable(): any; // sic\n\n/** NaN (not a number) as a 32-bit or 64-bit float depending on context. */\ndeclare const NaN: f32 | f64;\n/** Positive infinity as a 32-bit or 64-bit float depending on context. */\ndeclare const Infinity: f32 | f64;\n/** Changes the type of any value of `usize` kind to another one of `usize` kind. Useful for casting class instances to their pointer values and vice-versa. Beware that this is unsafe.*/\ndeclare function changetype(value: any): T;\n/** Explicitly requests no bounds checks on the provided expression. Useful for array accesses. */\ndeclare function unchecked(value: T): T;\n/** Tests if a 32-bit or 64-bit float is `NaN`. */\ndeclare function isNaN(value: T): bool;\n/** Tests if a 32-bit or 64-bit float is finite, that is not `NaN` or +/-`Infinity`. */\ndeclare function isFinite(value: T): bool;\n/** Tests if the specified value is a valid integer. Can't distinguish an integer from an integral float. */\ndeclare function isInteger(value: any): value is number;\n/** Tests if the specified value is a valid float. Can't distinguish a float from an integer. */\ndeclare function isFloat(value: any): value is number;\n/** Tests if the specified value is of a reference type. */\ndeclare function isReference(value: any): value is object | string;\n/** Tests if the specified value can be used as a string. */\ndeclare function isString(value: any): value is string | String;\n/** Tests if the specified value can be used as an array. */\ndeclare function isArray(value: any): value is Array;\n/** Traps if the specified value is not true-ish, otherwise returns the value. */\ndeclare function assert(isTrueish: T | null, message?: string): T;\n/** Parses an integer string to a 64-bit float. */\ndeclare function parseInt(str: string, radix?: i32): f64;\n/** Parses an integer string to a 32-bit integer. */\ndeclare function parseI32(str: string, radix?: i32): i32;\n/** Parses a floating point string to a 64-bit float. */\ndeclare function parseFloat(str: string): f64;\n/** Returns the 64-bit floating-point remainder of `x/y`. */\ndeclare function fmod(x: f64, y: f64): f64;\n/** Returns the 32-bit floating-point remainder of `x/y`. */\ndeclare function fmodf(x: f32, y: f32): f32;\n\n/** Converts any other numeric value to an 8-bit signed integer. */\ndeclare function i8(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;\ndeclare namespace i8 {\n /** Smallest representable value. */\n export const MIN_VALUE: i8;\n /** Largest representable value. */\n export const MAX_VALUE: i8;\n}\n/** Converts any other numeric value to a 16-bit signed integer. */\ndeclare function i16(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;\ndeclare namespace i16 {\n /** Smallest representable value. */\n export const MIN_VALUE: i16;\n /** Largest representable value. */\n export const MAX_VALUE: i16;\n}\n/** Converts any other numeric value to a 32-bit signed integer. */\ndeclare function i32(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i32;\ndeclare namespace i32 {\n /** Smallest representable value. */\n export const MIN_VALUE: i32;\n /** Largest representable value. */\n export const MAX_VALUE: i32;\n}\n/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) signed integer. */\ndeclare function isize(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): isize;\ndeclare namespace isize {\n /** Smallest representable value. */\n export const MIN_VALUE: isize;\n /** Largest representable value. */\n export const MAX_VALUE: isize;\n}\n/** Converts any other numeric value to an 8-bit unsigned integer. */\ndeclare function u8(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;\ndeclare namespace u8 {\n /** Smallest representable value. */\n export const MIN_VALUE: u8;\n /** Largest representable value. */\n export const MAX_VALUE: u8;\n}\n/** Converts any other numeric value to a 16-bit unsigned integer. */\ndeclare function u16(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i8;\ndeclare namespace u16 {\n /** Smallest representable value. */\n export const MIN_VALUE: u16;\n /** Largest representable value. */\n export const MAX_VALUE: u16;\n}\n/** Converts any other numeric value to a 32-bit unsigned integer. */\ndeclare function u32(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): i32;\ndeclare namespace u32 {\n /** Smallest representable value. */\n export const MIN_VALUE: u32;\n /** Largest representable value. */\n export const MAX_VALUE: u32;\n}\n/** Converts any other numeric value to a 32-bit (in WASM32) respectivel 64-bit (in WASM64) unsigned integer. */\ndeclare function usize(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): isize;\ndeclare namespace usize {\n /** Smallest representable value. */\n export const MIN_VALUE: usize;\n /** Largest representable value. */\n export const MAX_VALUE: usize;\n}\n/** Converts any other numeric value to a 1-bit unsigned integer. */\ndeclare function bool(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): bool;\ndeclare namespace bool {\n /** Smallest representable value. */\n export const MIN_VALUE: bool;\n /** Largest representable value. */\n export const MAX_VALUE: bool;\n}\n/** Converts any other numeric value to a 32-bit float. */\ndeclare function f32(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): f32;\ndeclare namespace f32 {\n /** Smallest representable value. */\n export const MIN_VALUE: f32;\n /** Largest representable value. */\n export const MAX_VALUE: f32;\n /** Smallest normalized positive value. */\n export const MIN_POSITIVE_VALUE: f32;\n /** Smallest safely representable integer value. */\n export const MIN_SAFE_INTEGER: f32;\n /** Largest safely representable integer value. */\n export const MAX_SAFE_INTEGER: f32;\n /** Difference between 1 and the smallest representable value greater than 1. */\n export const EPSILON: f32;\n}\n/** Converts any other numeric value to a 64-bit float. */\ndeclare function f64(value: i8 | i16 | i32 | isize | u8 | u16 | u32 | usize | bool | f32 | f64): f64;\ndeclare namespace f64 {\n /** Smallest representable value. */\n export const MIN_VALUE: f64;\n /** Largest representable value. */\n export const MAX_VALUE: f64;\n /** Smallest normalized positive value. */\n export const MIN_POSITIVE_VALUE: f64;\n /** Smallest safely representable integer value. */\n export const MIN_SAFE_INTEGER: f64;\n /** Largest safely representable integer value. */\n export const MAX_SAFE_INTEGER: f64;\n /** Difference between 1 and the smallest representable value greater than 1. */\n export const EPSILON: f64;\n}\n\n// Polyfills\n\n/** [Polyfill] Performs the sign-agnostic reverse bytes **/\ndeclare function bswap(value: T): T;\n/** [Polyfill] Performs the sign-agnostic reverse bytes only for last 16-bit **/\ndeclare function bswap16(value: T): T;\n\n// Standard library\n\n/** Memory operations. */\ndeclare namespace memory {\n /** Allocates a chunk of memory of the specified size and returns a pointer to it. */\n function allocate(size: usize): usize;\n /** Disposes a chunk of memory by its pointer. */\n function free(ptr: usize): void;\n /** Copies n bytes from the specified source to the specified destination in memory. These regions may overlap. */\n function copy(dst: usize, src: usize, n: usize): void;\n /** Resets the allocator to its initial state, if supported. */\n function reset(): void;\n}\n\n/** Class representing a generic, fixed-length raw binary data buffer. */\ndeclare class ArrayBuffer {\n /** The size, in bytes, of the array. */\n readonly byteLength: i32;\n /** Constructs a new array buffer of the given length in bytes. */\n constructor(length: i32);\n /** Returns a copy of this array buffer's bytes from begin, inclusive, up to end, exclusive. */\n slice(begin?: i32, end?: i32): ArrayBuffer;\n}\n\ndeclare class Array {\n [key: number]: T;\n length: i32;\n constructor(capacity?: i32);\n fill(value: T, start?: i32, end?: i32): this;\n every(callbackfn: (element: T, index: i32, array?: Array) => bool): bool;\n findIndex(predicate: (element: T, index: i32, array?: Array) => bool): i32;\n includes(searchElement: T, fromIndex?: i32): bool;\n indexOf(searchElement: T, fromIndex?: i32): i32;\n lastIndexOf(searchElement: T, fromIndex?: i32): i32;\n push(element: T): i32;\n concat(items: T[]): T[];\n pop(): T;\n forEach(callbackfn: (value: T, index: i32, array: Array) => void): void;\n map(callbackfn: (value: T, index: i32, array: Array) => U): Array;\n filter(callbackfn: (value: T, index: i32, array: Array) => bool): Array;\n reduce(callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U): U;\n reduceRight(callbackfn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U, initialValue: U): U;\n shift(): T;\n some(callbackfn: (element: T, index: i32, array?: Array) => bool): bool;\n unshift(element: T): i32;\n slice(from?: i32, to?: i32): T[];\n splice(start: i32, deleteCount?: i32): void;\n sort(comparator?: (a: T, b: T) => i32): this;\n join(separator?: string): string;\n reverse(): T[];\n toString(): string;\n}\n\ndeclare class Uint8Array extends Array {}\ndeclare class Uint16Array extends Array {}\ndeclare class Uint32Array extends Array {}\ndeclare class Int8Array extends Array {}\ndeclare class Int16Array extends Array {}\ndeclare class Int32Array extends Array {}\ndeclare class Float32Array extends Array {}\ndeclare class Float64Array extends Array {}\n\ndeclare class String {\n\n static fromCharCode(ls: i32, hs?: i32): string;\n static fromCharCodes(arr: u16[]): string;\n static fromCodePoint(code: i32): string;\n static fromCodePoints(arr: i32[]): string;\n\n readonly length: i32;\n\n private constructor();\n\n charAt(index: i32): string;\n charCodeAt(index: i32): i32;\n concat(other: string): string;\n indexOf(other: string, fromIndex?: i32): i32;\n lastIndexOf(other: string, fromIndex?: i32): i32;\n includes(other: string): bool;\n startsWith(other: string): bool;\n endsWith(other: string): bool;\n substr(start: u32, length?: u32): string;\n substring(from: i32, to?: i32): string;\n trim(): string;\n trimLeft(): string;\n trimRight(): string;\n trimStart(): string;\n trimEnd(): string;\n padStart(targetLength: i32, padString?: string): string;\n padEnd(targetLength: i32, padString?: string): string;\n replace(search: string, replacement: string): string;\n repeat(count?: i32): string;\n split(separator?: string, limit?: i32): string[];\n toString(): string;\n}\n\ninterface Boolean {}\n\ndeclare class Number {\n private constructor();\n toString(radix?: i32): string;\n}\n\ninterface Object {}\n\ninterface Function {}\n\ninterface RegExp {}\n\ninterface IArguments {}\n\ndeclare class Error {\n constructor(message: string);\n message: string;\n stack: string | null;\n}\n\ndeclare class Set {\n constructor(entries?: T[]);\n readonly size: i32;\n has(value: T): bool;\n add(value: T): void;\n delete(value: T): bool;\n clear(): void;\n [Symbol.iterator](): Iterator;\n}\n\ndeclare class Map {\n constructor(entries?: [K, V][]);\n readonly size: i32;\n set(key: K, value: V): void;\n has(key: K): bool;\n get(key: K): V | null;\n clear(): void;\n entries(): Iterable<[K, V]>;\n keys(): Iterable;\n values(): Iterable;\n delete(key: K): bool;\n [Symbol.iterator](): Iterator<[K,V]>;\n}\n\ninterface SymbolConstructor {\n (description?: string | null): symbol;\n for(key: string): symbol;\n keyFor(sym: symbol): string | null;\n readonly iterator: symbol;\n}\ndeclare const Symbol: SymbolConstructor;\n\ninterface Iterable {\n [Symbol.iterator](): Iterator;\n}\n\ninterface Iterator {}\n\ninterface IMath {\n readonly E: f64;\n readonly LN2: f64;\n readonly LN10: f64;\n readonly LOG2E: f64;\n readonly LOG10E: f64;\n readonly PI: f64;\n readonly SQRT1_2: f64;\n readonly SQRT2: f64;\n abs(x: f64): f64;\n acos(x: f64): f64;\n acosh(x: f64): f64;\n asin(x: f64): f64;\n asinh(x: f64): f64;\n atan(x: f64): f64;\n atan2(y: f64, x: f64): f64;\n atanh(x: f64): f64;\n cbrt(x: f64): f64;\n ceil(x: f64): f64;\n clz32(x: f64): i32;\n cos(x: f64): f64;\n cosh(x: f64): f64;\n exp(x: f64): f64;\n expm1(x: f64): f64;\n floor(x: f64): f64;\n fround(x: f64): f32;\n hypot(value1: f64, value2: f64): f64; // TODO: see std/math\n imul(a: f64, b: f64): i32;\n log(x: f64): f64;\n log10(x: f64): f64;\n log1p(x: f64): f64;\n log2(x: f64): f64;\n max(value1: f64, value2: f64): f64; // TODO: see std/math\n min(value1: f64, value2: f64): f64; // TODO: see std/math\n pow(base: f64, exponent: f64): f64;\n random(): f64;\n round(x: f64): f64;\n sign(x: f64): f64;\n sin(x: f64): f64;\n sinh(x: f64): f64;\n sqrt(x: f64): f64;\n tan(x: f64): f64;\n tanh(x: f64): f64;\n trunc(x: f64): f64;\n}\n\ndeclare const Math: IMath;\ndeclare const Mathf: IMath;\ndeclare const JSMath: IMath;\n\ndeclare namespace console {\n /** @deprecated */\n function log(message: string): void;\n}\n"}):(()=>{const e=path.join(".","..","std");return{assembly:fs.readFileSync(path.join(e,"assembly","index.d.ts"),"utf8"),portable:fs.readFileSync(path.join(e,"portable","index.d.ts"),"utf8")}})(),exports.compileString=((e,n)=>{"string"==typeof e&&(e={"input.ts":e});const t=Object.create({stdout:createMemoryStream(),stderr:createMemoryStream(),binary:null,text:null});var r=["--binaryFile","binary","--textFile","text"];return Object.keys(n||{}).forEach(e=>{var t=n[e];Array.isArray(t)?t.forEach(n=>r.push("--"+e,String(n))):r.push("--"+e,String(t))}),exports.main(r.concat(Object.keys(e)),{stdout:t.stdout,stderr:t.stderr,readFile:n=>e.hasOwnProperty(n)?e[n]:null,writeFile:(e,n)=>t[e]=n,listFiles:()=>[]}),t}),exports.main=function(e,n,t){"function"==typeof n?(t=n,n={}):n||(n={});const r=n.stdout||process.stdout,i=n.stderr||process.stderr,s=n.readFile||T,a=n.writeFile||A,o=n.listFiles||z,l=n.stats||createStats();if(!r)throw Error("'options.stdout' must be specified");if(!i)throw Error("'options.stderr' must be specified");const f=optionsUtil.parse(e,exports.options),u=f.options;if(e=f.arguments,u.noColors?colorsUtil.stdout.supported=colorsUtil.stderr.supported=!1:(colorsUtil.stdout=colorsUtil.from(r),colorsUtil.stderr=colorsUtil.from(i)),f.unknown.length&&f.unknown.forEach(e=>{i.write(colorsUtil.stderr.yellow("WARN: ")+"Unknown option '"+e+"'"+EOL)}),f.trailing.length&&i.write(colorsUtil.stderr.yellow("WARN: ")+"Unsupported trailing arguments: "+f.trailing.join(" ")+EOL),t||(t=function(e){var n=0;return e&&(i.write(colorsUtil.stderr.red("ERROR: ")+e.stack.replace(/^ERROR: /i,"")+EOL),n=1),n}),u.version)return r.write("Version "+exports.version+(isDev?"-dev":"")+EOL),t(null);if(u.help||!e.length){var c=u.help?r:i,p=u.help?colorsUtil.stdout:colorsUtil.stderr;return c.write([p.white("SYNTAX")," "+p.cyan("asc")+" [entryFile ...] [options]","",p.white("EXAMPLES")," "+p.cyan("asc")+" hello.ts"," "+p.cyan("asc")+" hello.ts -b hello.wasm -t hello.wat"," "+p.cyan("asc")+" hello1.ts hello2.ts -b -O > hello.wasm","",p.white("OPTIONS")].concat(optionsUtil.help(exports.options,24,EOL)).join(EOL)+EOL),t(null)}if(!fs.readFileSync){if(s===T)throw Error("'options.readFile' must be specified");if(a===A)throw Error("'options.writeFile' must be specified");if(o===z)throw Error("'options.listFiles' must be specified")}const h=u.baseDir?path.resolve(u.baseDir):".",d=[];u.transform&&u.transform.forEach(e=>d.push(__webpack_require__(12)(path.isAbsolute(e=e.trim())?e:path.join(process.cwd(),e))));var x=null;u.noLib?(l.parseCount++,l.parseTime+=measure(()=>{x=assemblyscript.parseFile(exports.libraryFiles.builtins,exports.libraryPrefix+"builtins.ts",!1,x)})):Object.keys(exports.libraryFiles).forEach(e=>{e.indexOf("/")>=0||(l.parseCount++,l.parseTime+=measure(()=>{x=assemblyscript.parseFile(exports.libraryFiles[e],exports.libraryPrefix+e+".ts",!1,x)}))});const g=[];if(u.lib){let e=u.lib;"string"==typeof e&&(e=e.split(",")),Array.prototype.push.apply(g,e.map(e=>e.trim()));for(let e=0,n=g.length;e{x=assemblyscript.parseFile(a,exports.libraryPrefix+i,!1,x)})}}}for(let n=0,r=e.length;n{x=assemblyscript.parseFile(o,a,!0,x)});null!=(a=x.nextFile());){if(a.startsWith(exports.libraryPrefix)){const e=a.substring(exports.libraryPrefix.length),n=a.substring(exports.libraryPrefix.length)+"/index";if(exports.libraryFiles.hasOwnProperty(e))o=exports.libraryFiles[e],a=exports.libraryPrefix+e+".ts";else if(exports.libraryFiles.hasOwnProperty(n))o=exports.libraryFiles[n],a=exports.libraryPrefix+n+".ts";else for(let t=0,r=g.length;t{assemblyscript.parseFile(o,a,!1,x)})}if(checkDiagnostics(x,i))return t(Error("Parse error"))}!function(e,...n){d.forEach(t=>{"function"==typeof t[e]&&t[e](...n)})}("afterParse",x);const b=assemblyscript.finishParsing(x);var y=0,m=0;u.optimize&&(y=exports.defaultOptimizeLevel,m=exports.defaultShrinkLevel),"number"==typeof u.optimizeLevel&&(y=u.optimizeLevel),"number"==typeof u.shrinkLevel&&(m=u.shrinkLevel),y=Math.min(Math.max(y,0),3),m=Math.min(Math.max(m,0),2);const v=assemblyscript.createOptions();if(assemblyscript.setTarget(v,0),assemblyscript.setNoTreeShaking(v,u.noTreeShaking),assemblyscript.setNoAssert(v,u.noAssert),assemblyscript.setImportMemory(v,u.importMemory),assemblyscript.setImportTable(v,u.importTable),assemblyscript.setMemoryBase(v,u.memoryBase>>>0),assemblyscript.setSourceMap(v,null!=u.sourceMap),assemblyscript.setOptimizeLevelHints(v,y,m),u.noLib||(assemblyscript.setGlobalAlias(v,"Math","NativeMath"),assemblyscript.setGlobalAlias(v,"Mathf","NativeMathf"),assemblyscript.setGlobalAlias(v,"abort","~lib/env/abort"),assemblyscript.setGlobalAlias(v,"trace","~lib/env/trace")),u.use){let e=u.use;for(let n=0,r=e.length;n{try{l.compileTime+=measure(()=>{_=assemblyscript.compileProgram(b,v)})}catch(e){return t(e)}})(),checkDiagnostics(x,i))return _&&_.dispose(),t(Error("Compile error"));if(u.validate&&(l.validateCount++,l.validateTime+=measure(()=>{if(!_.validate())return _.dispose(),t(Error("Validate error"))})),"clamp"===u.trapMode)l.optimizeCount++,l.optimizeTime+=measure(()=>{_.runPasses(["trap-mode-clamp"])});else if("js"===u.trapMode)l.optimizeCount++,l.optimizeTime+=measure(()=>{_.runPasses(["trap-mode-js"])});else if("allow"!==u.trapMode)return _.dispose(),t(Error("Unsupported trap mode"));(y>=3||m>=2)&&(y=4),_.setOptimizeLevel(y),_.setShrinkLevel(m),_.setDebugInfo(u.debug);var F=[];if(u.runPasses&&("string"==typeof u.runPasses&&(u.runPasses=u.runPasses.split(",")),u.runPasses.length&&u.runPasses.forEach(e=>{F.indexOf(e)<0&&F.push(e)})),(y>0||m>0)&&(l.optimizeCount++,l.optimizeTime+=measure(()=>{_.optimize()})),F.length&&(l.optimizeCount++,l.optimizeTime+=measure(()=>{_.runPasses(F.map(e=>e.trim()))})),!u.noEmit){let e=!1,n=!1;if(null!=u.outFile&&(/\.was?t$/.test(u.outFile)&&null==u.textFile?u.textFile=u.outFile:/\.js$/.test(u.outFile)&&null==u.asmjsFile?u.asmjsFile=u.outFile:null==u.binaryFile&&(u.binaryFile=u.outFile)),null!=u.binaryFile){let r,o=null!=u.sourceMap?u.sourceMap.length?u.sourceMap:path.basename(u.binaryFile)+".map":null;if(l.emitCount++,l.emitTime+=measure(()=>{r=_.toBinary(o)}),u.binaryFile.length?a(path.join(h,u.binaryFile),r.output):(S(r.output),e=!0),n=!0,null!=r.sourceMap)if(u.binaryFile.length){let e=JSON.parse(r.sourceMap);e.sourceRoot=exports.sourceMapRoot,e.sources.forEach((n,r)=>{let i=null;if(n.startsWith(exports.libraryPrefix)){let e=n.substring(exports.libraryPrefix.length).replace(/\.ts$/,"");if(exports.libraryFiles.hasOwnProperty(e))i=exports.libraryFiles[e];else for(let e=0,t=g.length;e{t=_.toAsmjs()}),a(path.join(h,u.asmjsFile),t)):e||(l.emitCount++,l.emitTime+=measure(()=>{t=_.toAsmjs()}),S(t),e=!0),n=!0}if(null!=u.idlFile){let t;u.idlFile.length?(l.emitCount++,l.emitTime+=measure(()=>{t=assemblyscript.buildIDL(b)}),a(path.join(h,u.idlFile),t)):e||(l.emitCount++,l.emitTime+=measure(()=>{t=assemblyscript.buildIDL(b)}),S(t),e=!0),n=!0}if(null!=u.tsdFile){let t;u.tsdFile.length?(l.emitCount++,l.emitTime+=measure(()=>{t=assemblyscript.buildTSD(b)}),a(path.join(h,u.tsdFile),t)):e||(l.emitCount++,l.emitTime+=measure(()=>{t=assemblyscript.buildTSD(b)}),S(t),e=!0),n=!0}if(null!=u.textFile||!n){let n;u.textFile&&u.textFile.length?(l.emitCount++,l.emitTime+=measure(()=>{n=_.toText()}),a(path.join(h,u.textFile),n)):e||(l.emitCount++,l.emitTime+=measure(()=>{n=_.toText()}),S(n))}}return _.dispose(),u.measure&&printStats(l,i),t(null);function T(e){try{let n;return l.readCount++,l.readTime+=measure(()=>{n=fs.readFileSync(e,{encoding:"utf8"})}),n}catch(e){return null}}function A(e,n){try{return l.writeCount++,l.writeTime+=measure(()=>{mkdirp(path.dirname(e)),"string"==typeof n?fs.writeFileSync(e,n,{encoding:"utf8"}):fs.writeFileSync(e,n)}),!0}catch(e){return!1}}function z(e){var n;try{return l.readTime+=measure(()=>{n=fs.readdirSync(e).filter(e=>/^(?!.*\.d\.ts$).*\.ts$/.test(e))}),n}catch(e){return[]}}function S(e){S.used||(l.writeCount++,S.used=!0),l.writeTime+=measure(()=>{"string"==typeof e?r.write(e,{encoding:"utf8"}):r.write(e)})}};var argumentSubstitutions={"-O":["--optimize"],"-Os":["--optimize","--shrinkLevel","1"],"-Oz":["--optimize","--shrinkLevel","2"],"-O0":["--optimizeLevel","0","--shrinkLevel","0"],"-O0s":["--optimizeLevel","0","--shrinkLevel","1"],"-O0z":["--optimizeLevel","0","--shrinkLevel","2"],"-O1":["--optimizeLevel","1","--shrinkLevel","0"],"-O1s":["--optimizeLevel","1","--shrinkLevel","1"],"-O1z":["--optimizeLevel","1","--shrinkLevel","2"],"-O2":["--optimizeLevel","2","--shrinkLevel","0"],"-O2s":["--optimizeLevel","2","--shrinkLevel","1"],"-O2z":["--optimizeLevel","2","--shrinkLevel","2"],"-O3":["--optimizeLevel","3","--shrinkLevel","0"],"-O3s":["--optimizeLevel","3","--shrinkLevel","1"],"-O3z":["--optimizeLevel","3","--shrinkLevel","2"]};function checkDiagnostics(e,n){for(var t,r=!1;null!=(t=assemblyscript.nextDiagnostic(e));)n&&n.write(assemblyscript.formatDiagnostic(t,n.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(e){const n=process.hrtime();e();const t=process.hrtime(n);return 1e9*t[0]+t[1]}function formatTime(e){return e?(e/1e6).toFixed(3)+" ms":"N/A"}function printStats(e,n){function t(e,n){return formatTime(e)}(n||process.stdout).write(["I/O Read : "+t(e.readTime,e.readCount),"I/O Write : "+t(e.writeTime,e.writeCount),"Parse : "+t(e.parseTime,e.parseCount),"Compile : "+t(e.compileTime,e.compileCount),"Emit : "+t(e.emitTime,e.emitCount),"Validate : "+t(e.validateTime,e.validateCount),"Optimize : "+t(e.optimizeTime,e.optimizeCount)].join(EOL)+EOL)}exports.checkDiagnostics=checkDiagnostics,exports.createStats=createStats,process.hrtime||(process.hrtime=__webpack_require__(13)),exports.measure=measure,exports.formatTime=formatTime,exports.printStats=printStats;var allocBuffer=void 0!==global&&global.Buffer?global.Buffer.allocUnsafe||function(e){return new global.Buffer(e)}:function(e){return new Uint8Array(e)};function createMemoryStream(e){var n=[];return n.write=function(n){if(e&&e(n),"string"==typeof n){let e=allocBuffer(utf8.length(n));utf8.write(n,e,0),n=e}this.push(n)},n.reset=function(){n.length=0},n.toBuffer=function(){for(var e=0,n=0,t=this.length;n191&&r<224?s[a++]=(31&r)<<6|63&e[n++]:r>239&&r<365?(r=((7&r)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++])-65536,s[a++]=55296+(r>>10),s[a++]=56320+(1023&r)):s[a++]=(15&r)<<12|(63&e[n++])<<6|63&e[n++],a>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,s)),a=0);return i?(a&&i.push(String.fromCharCode.apply(String,s.slice(0,a))),i.join("")):String.fromCharCode.apply(String,s.slice(0,a))},r.write=function(e,n,t){for(var r,i,s=t,a=0;a>6|192,n[t++]=63&r|128):55296==(64512&r)&&56320==(64512&(i=e.charCodeAt(a+1)))?(r=65536+((1023&r)<<10)+(1023&i),++a,n[t++]=r>>18|240,n[t++]=r>>12&63|128,n[t++]=r>>6&63|128,n[t++]=63&r|128):(n[t++]=r>>12|224,n[t++]=r>>6&63|128,n[t++]=63&r|128);return t-s}},function(e,n,t){(function(e){var t=void 0!==e&&e||{},r=t.env&&"CI"in t.env;function i(e,t){var i=t||{};return i.supported=e&&!!e.isTTY||r,i.gray=(e=>i.supported?n.GRAY+e+n.RESET:e),i.red=(e=>i.supported?n.RED+e+n.RESET:e),i.green=(e=>i.supported?n.GREEN+e+n.RESET:e),i.yellow=(e=>i.supported?n.YELLOW+e+n.RESET:e),i.blue=(e=>i.supported?n.BLUE+e+n.RESET:e),i.magenta=(e=>i.supported?n.MAGENTA+e+n.RESET:e),i.cyan=(e=>i.supported?n.CYAN+e+n.RESET:e),i.white=(e=>i.supported?n.WHITE+e+n.RESET:e),i}n.stdout=i(t.stdout,n),n.stderr=i(t.stderr),n.from=i,n.GRAY="",n.RED="",n.GREEN="",n.YELLOW="",n.BLUE="",n.MAGENTA="",n.CYAN="",n.WHITE="",n.RESET=""}).call(this,t(0))},function(e,n){n.parse=function(e,n){var t={},r=[],arguments=[],i=[],s={};Object.keys(n).forEach(e=>{var r=n[e];null!=r.alias&&("string"==typeof r.alias?s[r.alias]=e:Array.isArray(r.alias)&&r.alias.forEach(n=>s[n]=e)),null!=r.default&&(t[e]=r.default)});for(var a=0,o=(e=e.slice()).length;at[e]=o.value[e])}else r.push(i)}for(;a{var a=e[n];if(null!=a.description){for(var o="";o.length{for(let n=0;n 0\n var up = 0;\n for (var i = parts.length - 1; i >= 0; i--) {\n var last = parts[i];\n if (last === '.') {\n parts.splice(i, 1);\n } else if (last === '..') {\n parts.splice(i, 1);\n up++;\n } else if (up) {\n parts.splice(i, 1);\n up--;\n }\n }\n\n // if the path is allowed to go above the root, restore leading ..s\n if (allowAboveRoot) {\n for (; up--; up) {\n parts.unshift('..');\n }\n }\n\n return parts;\n}\n\n// Split a filename into [root, dir, basename, ext], unix version\n// 'root' is just a slash, or nothing.\nvar splitPathRe =\n /^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^\\/]+?|)(\\.[^.\\/]*|))(?:[\\/]*)$/;\nvar splitPath = function(filename) {\n return splitPathRe.exec(filename).slice(1);\n};\n\n// path.resolve([from ...], to)\n// posix version\nexports.resolve = function() {\n var resolvedPath = '',\n resolvedAbsolute = false;\n\n for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {\n var path = (i >= 0) ? arguments[i] : process.cwd();\n\n // Skip empty and invalid entries\n if (typeof path !== 'string') {\n throw new TypeError('Arguments to path.resolve must be strings');\n } else if (!path) {\n continue;\n }\n\n resolvedPath = path + '/' + resolvedPath;\n resolvedAbsolute = path.charAt(0) === '/';\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {\n return !!p;\n }), !resolvedAbsolute).join('/');\n\n return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';\n};\n\n// path.normalize(path)\n// posix version\nexports.normalize = function(path) {\n var isAbsolute = exports.isAbsolute(path),\n trailingSlash = substr(path, -1) === '/';\n\n // Normalize the path\n path = normalizeArray(filter(path.split('/'), function(p) {\n return !!p;\n }), !isAbsolute).join('/');\n\n if (!path && !isAbsolute) {\n path = '.';\n }\n if (path && trailingSlash) {\n path += '/';\n }\n\n return (isAbsolute ? '/' : '') + path;\n};\n\n// posix version\nexports.isAbsolute = function(path) {\n return path.charAt(0) === '/';\n};\n\n// posix version\nexports.join = function() {\n var paths = Array.prototype.slice.call(arguments, 0);\n return exports.normalize(filter(paths, function(p, index) {\n if (typeof p !== 'string') {\n throw new TypeError('Arguments to path.join must be strings');\n }\n return p;\n }).join('/'));\n};\n\n\n// path.relative(from, to)\n// posix version\nexports.relative = function(from, to) {\n from = exports.resolve(from).substr(1);\n to = exports.resolve(to).substr(1);\n\n function trim(arr) {\n var start = 0;\n for (; start < arr.length; start++) {\n if (arr[start] !== '') break;\n }\n\n var end = arr.length - 1;\n for (; end >= 0; end--) {\n if (arr[end] !== '') break;\n }\n\n if (start > end) return [];\n return arr.slice(start, end - start + 1);\n }\n\n var fromParts = trim(from.split('/'));\n var toParts = trim(to.split('/'));\n\n var length = Math.min(fromParts.length, toParts.length);\n var samePartsLength = length;\n for (var i = 0; i < length; i++) {\n if (fromParts[i] !== toParts[i]) {\n samePartsLength = i;\n break;\n }\n }\n\n var outputParts = [];\n for (var i = samePartsLength; i < fromParts.length; i++) {\n outputParts.push('..');\n }\n\n outputParts = outputParts.concat(toParts.slice(samePartsLength));\n\n return outputParts.join('/');\n};\n\nexports.sep = '/';\nexports.delimiter = ':';\n\nexports.dirname = function(path) {\n var result = splitPath(path),\n root = result[0],\n dir = result[1];\n\n if (!root && !dir) {\n // No dirname whatsoever\n return '.';\n }\n\n if (dir) {\n // It has a dirname, strip trailing slash\n dir = dir.substr(0, dir.length - 1);\n }\n\n return root + dir;\n};\n\n\nexports.basename = function(path, ext) {\n var f = splitPath(path)[2];\n // TODO: make this comparison case-insensitive on windows?\n if (ext && f.substr(-1 * ext.length) === ext) {\n f = f.substr(0, f.length - ext.length);\n }\n return f;\n};\n\n\nexports.extname = function(path) {\n return splitPath(path)[3];\n};\n\nfunction filter (xs, f) {\n if (xs.filter) return xs.filter(f);\n var res = [];\n for (var i = 0; i < xs.length; i++) {\n if (f(xs[i], i, xs)) res.push(xs[i]);\n }\n return res;\n}\n\n// String.prototype.substr - negative index don't work in IE8\nvar substr = 'ab'.substr(-1) === 'b'\n ? function (str, start, len) { return str.substr(start, len) }\n : function (str, start, len) {\n if (start < 0) start = str.length + start;\n return str.substr(start, len);\n }\n;\n","var g;\n\n// This works in non-strict mode\ng = (function() {\n\treturn this;\n})();\n\ntry {\n\t// This works if eval is allowed (see CSP)\n\tg = g || Function(\"return this\")() || (1, eval)(\"this\");\n} catch (e) {\n\t// This works if the window reference is available\n\tif (typeof window === \"object\") g = window;\n}\n\n// g can still be undefined, but nothing to do about it...\n// We return undefined, instead of nothing here, so it's\n// easier to handle this case. if(!global) { ...}\n\nmodule.exports = g;\n","/**\r\n * Compiler frontend for node.js\r\n *\r\n * Uses the low-level API exported from src/index.ts so it works with the compiler compiled to\r\n * JavaScript as well as the compiler compiled to WebAssembly (eventually). Runs the sources\r\n * directly through ts-node if distribution files are not present (indicated by a `-dev` version).\r\n *\r\n * Can also be packaged as a bundle suitable for in-browser use with the standard library injected\r\n * in the build step. See dist/asc.js for the bundle and webpack.config.js for building details.\r\n *\r\n * @module cli/asc\r\n */\r\n\r\n// Use \".\" instead of \"/\" as cwd in browsers\r\nif (process.browser) process.cwd = function() { return \".\"; };\r\n\r\nconst fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst utf8 = require(\"@protobufjs/utf8\");\r\nconst colorsUtil = require(\"./util/colors\");\r\nconst optionsUtil = require(\"./util/options\");\r\nconst mkdirp = require(\"./util/mkdirp\");\r\nconst EOL = process.platform === \"win32\" ? \"\\r\\n\" : \"\\n\";\r\n\r\n// Emscripten adds an `uncaughtException` listener to Binaryen that results in an additional\r\n// useless code fragment on top of an actual error. suppress this:\r\nif (process.removeAllListeners) process.removeAllListeners(\"uncaughtException\");\r\n\r\n// Use distribution files if present, otherwise run the sources directly\r\nvar assemblyscript, isDev = false;\r\n(() => {\r\n try { // `asc` on the command line\r\n assemblyscript = require(\"../dist/assemblyscript.js\");\r\n } catch (e) {\r\n try { // `asc` on the command line without dist files\r\n require(\"ts-node\").register({ project: path.join(__dirname, \"..\", \"src\", \"tsconfig.json\") });\r\n require(\"../src/glue/js\");\r\n assemblyscript = require(\"../src\");\r\n isDev = true;\r\n } catch (e_ts) {\r\n try { // `require(\"dist/asc.js\")` in explicit browser tests\r\n assemblyscript = eval(\"require('./assemblyscript')\");\r\n } catch (e) {\r\n // combine both errors that lead us here\r\n e.stack = e_ts.stack + \"\\n---\\n\" + e.stack;\r\n throw e;\r\n }\r\n }\r\n }\r\n})();\r\n\r\n/** Whether this is a webpack bundle or not. */\r\nexports.isBundle = typeof BUNDLE_VERSION === \"string\";\r\n\r\n/** Whether asc runs the sources directly or not. */\r\nexports.isDev = isDev;\r\n\r\n/** AssemblyScript version. */\r\nexports.version = exports.isBundle ? BUNDLE_VERSION : require(\"../package.json\").version;\r\n\r\n/** Available CLI options. */\r\nexports.options = require(\"./asc.json\");\r\n\r\n/** Common root used in source maps. */\r\nexports.sourceMapRoot = \"assemblyscript:///\";\r\n\r\n/** Prefix used for library files. */\r\nexports.libraryPrefix = assemblyscript.LIBRARY_PREFIX;\r\n\r\n/** Default Binaryen optimization level. */\r\nexports.defaultOptimizeLevel = 2;\r\n\r\n/** Default Binaryen shrink level. */\r\nexports.defaultShrinkLevel = 1;\r\n\r\n/** Bundled library files. */\r\nexports.libraryFiles = exports.isBundle ? BUNDLE_LIBRARY : (() => { // set up if not a bundle\r\n const libDir = path.join(__dirname, \"..\", \"std\", \"assembly\");\r\n const libFiles = require(\"glob\").sync(\"**/!(*.d).ts\", { cwd: libDir });\r\n const bundled = {};\r\n libFiles.forEach(file => bundled[file.replace(/\\.ts$/, \"\")] = fs.readFileSync(path.join(libDir, file), \"utf8\" ));\r\n return bundled;\r\n})();\r\n\r\n/** Bundled definition files. */\r\nexports.definitionFiles = exports.isBundle ? BUNDLE_DEFINITIONS : (() => { // set up if not a bundle\r\n const stdDir = path.join(__dirname, \"..\", \"std\");\r\n return {\r\n \"assembly\": fs.readFileSync(path.join(stdDir, \"assembly\", \"index.d.ts\"), \"utf8\"),\r\n \"portable\": fs.readFileSync(path.join(stdDir, \"portable\", \"index.d.ts\"), \"utf8\")\r\n };\r\n})();\r\n\r\n/** Convenience function that parses and compiles source strings directly. */\r\nexports.compileString = (sources, options) => {\r\n if (typeof sources === \"string\") sources = { \"input.ts\": sources };\r\n const output = Object.create({\r\n stdout: createMemoryStream(),\r\n stderr: createMemoryStream(),\r\n binary: null,\r\n text: null\r\n });\r\n var argv = [\r\n \"--binaryFile\", \"binary\",\r\n \"--textFile\", \"text\",\r\n ];\r\n Object.keys(options || {}).forEach(key => {\r\n var val = options[key];\r\n if (Array.isArray(val)) val.forEach(val => argv.push(\"--\" + key, String(val)));\r\n else argv.push(\"--\" + key, String(val));\r\n });\r\n exports.main(argv.concat(Object.keys(sources)), {\r\n stdout: output.stdout,\r\n stderr: output.stderr,\r\n readFile: name => sources.hasOwnProperty(name) ? sources[name] : null,\r\n writeFile: (name, contents) => output[name] = contents,\r\n listFiles: () => []\r\n });\r\n return output;\r\n}\r\n\r\n/** Runs the command line utility using the specified arguments array. */\r\nexports.main = function main(argv, options, callback) {\r\n if (typeof options === \"function\") {\r\n callback = options;\r\n options = {};\r\n } else if (!options) {\r\n options = {};\r\n }\r\n\r\n const stdout = options.stdout || process.stdout;\r\n const stderr = options.stderr || process.stderr;\r\n const readFile = options.readFile || readFileNode;\r\n const writeFile = options.writeFile || writeFileNode;\r\n const listFiles = options.listFiles || listFilesNode;\r\n const stats = options.stats || createStats();\r\n\r\n // Output must be specified if not present in the environment\r\n if (!stdout) throw Error(\"'options.stdout' must be specified\");\r\n if (!stderr) throw Error(\"'options.stderr' must be specified\");\r\n\r\n const opts = optionsUtil.parse(argv, exports.options);\r\n const args = opts.options;\r\n argv = opts.arguments;\r\n if (args.noColors) {\r\n colorsUtil.stdout.supported =\r\n colorsUtil.stderr.supported = false;\r\n } else {\r\n colorsUtil.stdout = colorsUtil.from(stdout);\r\n colorsUtil.stderr = colorsUtil.from(stderr);\r\n }\r\n\r\n // Check for unknown arguments\r\n if (opts.unknown.length) {\r\n opts.unknown.forEach(arg => {\r\n stderr.write(colorsUtil.stderr.yellow(\"WARN: \") + \"Unknown option '\" + arg + \"'\" + EOL);\r\n });\r\n }\r\n\r\n // Check for trailing arguments\r\n if (opts.trailing.length) {\r\n stderr.write(colorsUtil.stderr.yellow(\"WARN: \") + \"Unsupported trailing arguments: \" + opts.trailing.join(\" \") + EOL);\r\n }\r\n\r\n // Use default callback if none is provided\r\n if (!callback) callback = function defaultCallback(err) {\r\n var code = 0;\r\n if (err) {\r\n stderr.write(colorsUtil.stderr.red(\"ERROR: \") + err.stack.replace(/^ERROR: /i, \"\") + EOL);\r\n code = 1;\r\n }\r\n return code;\r\n };\r\n\r\n // Just print the version if requested\r\n if (args.version) {\r\n stdout.write(\"Version \" + exports.version + (isDev ? \"-dev\" : \"\") + EOL);\r\n return callback(null);\r\n }\r\n // Print the help message if requested or no source files are provided\r\n if (args.help || !argv.length) {\r\n var out = args.help ? stdout : stderr;\r\n var color = args.help ? colorsUtil.stdout : colorsUtil.stderr;\r\n out.write([\r\n color.white(\"SYNTAX\"),\r\n \" \" + color.cyan(\"asc\") + \" [entryFile ...] [options]\",\r\n \"\",\r\n color.white(\"EXAMPLES\"),\r\n \" \" + color.cyan(\"asc\") + \" hello.ts\",\r\n \" \" + color.cyan(\"asc\") + \" hello.ts -b hello.wasm -t hello.wat\",\r\n \" \" + color.cyan(\"asc\") + \" hello1.ts hello2.ts -b -O > hello.wasm\",\r\n \"\",\r\n color.white(\"OPTIONS\"),\r\n ].concat(\r\n optionsUtil.help(exports.options, 24, EOL)\r\n ).join(EOL) + EOL);\r\n return callback(null);\r\n }\r\n\r\n // I/O must be specified if not present in the environment\r\n if (!fs.readFileSync) {\r\n if (readFile === readFileNode) throw Error(\"'options.readFile' must be specified\");\r\n if (writeFile === writeFileNode) throw Error(\"'options.writeFile' must be specified\");\r\n if (listFiles === listFilesNode) throw Error(\"'options.listFiles' must be specified\");\r\n }\r\n\r\n // Set up base directory\r\n const baseDir = args.baseDir ? path.resolve(args.baseDir) : \".\";\r\n\r\n // Set up transforms\r\n const transforms = [];\r\n if (args.transform) {\r\n args.transform.forEach(transform =>\r\n transforms.push(\r\n require(\r\n path.isAbsolute(transform = transform.trim())\r\n ? transform\r\n : path.join(process.cwd(), transform)\r\n )\r\n )\r\n );\r\n }\r\n function applyTransform(name, ...args) {\r\n transforms.forEach(transform => {\r\n if (typeof transform[name] === \"function\") transform[name](...args);\r\n });\r\n }\r\n\r\n // Begin parsing\r\n var parser = null;\r\n\r\n // Include library files\r\n if (!args.noLib) {\r\n Object.keys(exports.libraryFiles).forEach(libPath => {\r\n if (libPath.indexOf(\"/\") >= 0) return; // in sub-directory: imported on demand\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n parser = assemblyscript.parseFile(\r\n exports.libraryFiles[libPath],\r\n exports.libraryPrefix + libPath + \".ts\",\r\n false,\r\n parser\r\n );\r\n });\r\n });\r\n } else { // always include builtins\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n parser = assemblyscript.parseFile(\r\n exports.libraryFiles[\"builtins\"],\r\n exports.libraryPrefix + \"builtins.ts\",\r\n false,\r\n parser\r\n );\r\n });\r\n }\r\n const customLibDirs = [];\r\n if (args.lib) {\r\n let lib = args.lib;\r\n if (typeof lib === \"string\") lib = lib.split(\",\");\r\n Array.prototype.push.apply(customLibDirs, lib.map(lib => lib.trim()));\r\n for (let i = 0, k = customLibDirs.length; i < k; ++i) { // custom\r\n let libDir = customLibDirs[i];\r\n let libFiles;\r\n if (libDir.endsWith(\".ts\")) {\r\n libFiles = [ path.basename(libDir) ];\r\n libDir = path.dirname(libDir);\r\n } else {\r\n libFiles = listFiles(libDir);\r\n }\r\n for (let j = 0, l = libFiles.length; j < l; ++j) {\r\n let libPath = libFiles[j];\r\n let libText = readFile(path.join(libDir, libPath));\r\n if (libText === null) return callback(Error(\"Library file '\" + libPath + \"' not found.\"));\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n parser = assemblyscript.parseFile(\r\n libText,\r\n exports.libraryPrefix + libPath,\r\n false,\r\n parser\r\n );\r\n });\r\n }\r\n }\r\n }\r\n\r\n // Include entry files\r\n for (let i = 0, k = argv.length; i < k; ++i) {\r\n const filename = argv[i];\r\n\r\n let sourcePath = String(filename).replace(/\\\\/g, \"/\").replace(/(\\.ts|\\/)$/, \"\");\r\n\r\n // Try entryPath.ts, then entryPath/index.ts\r\n let sourceText = readFile(path.join(baseDir, sourcePath) + \".ts\");\r\n if (sourceText === null) {\r\n sourceText = readFile(path.join(baseDir, sourcePath, \"index.ts\"));\r\n if (sourceText === null) {\r\n return callback(Error(\"Entry file '\" + sourcePath + \".ts' not found.\"));\r\n } else {\r\n sourcePath += \"/index.ts\";\r\n }\r\n } else {\r\n sourcePath += \".ts\";\r\n }\r\n\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);\r\n });\r\n\r\n // Process backlog\r\n while ((sourcePath = parser.nextFile()) != null) {\r\n let found = false;\r\n\r\n // Load library file if explicitly requested\r\n if (sourcePath.startsWith(exports.libraryPrefix)) {\r\n const plainName = sourcePath.substring(exports.libraryPrefix.length);\r\n const indexName = sourcePath.substring(exports.libraryPrefix.length) + \"/index\";\r\n if (exports.libraryFiles.hasOwnProperty(plainName)) {\r\n sourceText = exports.libraryFiles[plainName];\r\n sourcePath = exports.libraryPrefix + plainName + \".ts\";\r\n } else if (exports.libraryFiles.hasOwnProperty(indexName)) {\r\n sourceText = exports.libraryFiles[indexName];\r\n sourcePath = exports.libraryPrefix + indexName + \".ts\";\r\n } else {\r\n for (let i = 0, k = customLibDirs.length; i < k; ++i) {\r\n const dir = customLibDirs[i];\r\n sourceText = readFile(path.join(dir, plainName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = exports.libraryPrefix + plainName + \".ts\";\r\n break;\r\n } else {\r\n sourceText = readFile(path.join(dir, indexName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = exports.libraryPrefix + indexName + \".ts\";\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Otherwise try nextFile.ts, nextFile/index.ts, ~lib/nextFile.ts, ~lib/nextFile/index.ts\r\n } else {\r\n const plainName = sourcePath;\r\n const indexName = sourcePath + \"/index\";\r\n sourceText = readFile(path.join(baseDir, plainName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = plainName + \".ts\";\r\n } else {\r\n sourceText = readFile(path.join(baseDir, indexName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = indexName + \".ts\";\r\n } else if (!plainName.startsWith(\".\")) {\r\n if (exports.libraryFiles.hasOwnProperty(plainName)) {\r\n sourceText = exports.libraryFiles[plainName];\r\n sourcePath = exports.libraryPrefix + plainName + \".ts\";\r\n } else if (exports.libraryFiles.hasOwnProperty(indexName)) {\r\n sourceText = exports.libraryFiles[indexName];\r\n sourcePath = exports.libraryPrefix + indexName + \".ts\";\r\n } else {\r\n for (let i = 0, k = customLibDirs.length; i < k; ++i) {\r\n const dir = customLibDirs[i];\r\n sourceText = readFile(path.join(dir, plainName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = exports.libraryPrefix + plainName + \".ts\";\r\n break;\r\n } else {\r\n sourceText = readFile(path.join(dir, indexName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = exports.libraryPrefix + indexName + \".ts\";\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n if (sourceText == null) {\r\n return callback(Error(\"Import file '\" + sourcePath + \".ts' not found.\"));\r\n }\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n assemblyscript.parseFile(sourceText, sourcePath, false, parser);\r\n });\r\n }\r\n if (checkDiagnostics(parser, stderr)) {\r\n return callback(Error(\"Parse error\"));\r\n }\r\n }\r\n\r\n applyTransform(\"afterParse\", parser);\r\n\r\n // Finish parsing\r\n const program = assemblyscript.finishParsing(parser);\r\n\r\n // Set up optimization levels\r\n var optimizeLevel = 0;\r\n var shrinkLevel = 0;\r\n if (args.optimize) {\r\n optimizeLevel = exports.defaultOptimizeLevel;\r\n shrinkLevel = exports.defaultShrinkLevel;\r\n }\r\n if (typeof args.optimizeLevel === \"number\") {\r\n optimizeLevel = args.optimizeLevel;\r\n }\r\n if (typeof args.shrinkLevel === \"number\") {\r\n shrinkLevel = args.shrinkLevel;\r\n }\r\n optimizeLevel = Math.min(Math.max(optimizeLevel, 0), 3);\r\n shrinkLevel = Math.min(Math.max(shrinkLevel, 0), 2);\r\n\r\n // Begin compilation\r\n const compilerOptions = assemblyscript.createOptions();\r\n assemblyscript.setTarget(compilerOptions, 0);\r\n assemblyscript.setNoTreeShaking(compilerOptions, args.noTreeShaking);\r\n assemblyscript.setNoAssert(compilerOptions, args.noAssert);\r\n assemblyscript.setImportMemory(compilerOptions, args.importMemory);\r\n assemblyscript.setImportTable(compilerOptions, args.importTable);\r\n assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);\r\n assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);\r\n assemblyscript.setOptimizeLevelHints(compilerOptions, optimizeLevel, shrinkLevel);\r\n\r\n if (!args.noLib) {\r\n // Initialize default aliases\r\n assemblyscript.setGlobalAlias(compilerOptions, \"Math\", \"NativeMath\");\r\n assemblyscript.setGlobalAlias(compilerOptions, \"Mathf\", \"NativeMathf\");\r\n assemblyscript.setGlobalAlias(compilerOptions, \"abort\", \"~lib/env/abort\");\r\n assemblyscript.setGlobalAlias(compilerOptions, \"trace\", \"~lib/env/trace\");\r\n }\r\n\r\n // Add or override aliases if specified\r\n if (args.use) {\r\n let aliases = args.use;\r\n for (let i = 0, k = aliases.length; i < k; ++i) {\r\n let part = aliases[i];\r\n let p = part.indexOf(\"=\");\r\n if (p < 0) return callback(Error(\"Global alias '\" + part + \"' is invalid.\"));\r\n let name = part.substring(0, p).trim();\r\n let alias = part.substring(p + 1).trim();\r\n if (!name.length) return callback(Error(\"Global alias '\" + part + \"' is invalid.\"));\r\n assemblyscript.setGlobalAlias(compilerOptions, name, alias);\r\n }\r\n }\r\n\r\n // Enable additional features if specified\r\n var features = args.enable;\r\n if (features != null) {\r\n if (typeof features === \"string\") features = features.split(\",\");\r\n for (let i = 0, k = features.length; i < k; ++i) {\r\n let name = features[i].trim();\r\n let flag = assemblyscript[\"FEATURE_\" + name.replace(/\\-/g, \"_\").toUpperCase()];\r\n if (!flag) return callback(Error(\"Feature '\" + name + \"' is unknown.\"));\r\n assemblyscript.enableFeature(compilerOptions, flag);\r\n }\r\n }\r\n\r\n var module;\r\n stats.compileCount++;\r\n (() => {\r\n try {\r\n stats.compileTime += measure(() => {\r\n module = assemblyscript.compileProgram(program, compilerOptions);\r\n });\r\n } catch (e) {\r\n return callback(e);\r\n }\r\n })();\r\n if (checkDiagnostics(parser, stderr)) {\r\n if (module) module.dispose();\r\n return callback(Error(\"Compile error\"));\r\n }\r\n\r\n // Validate the module if requested\r\n if (args.validate) {\r\n stats.validateCount++;\r\n stats.validateTime += measure(() => {\r\n if (!module.validate()) {\r\n module.dispose();\r\n return callback(Error(\"Validate error\"));\r\n }\r\n });\r\n }\r\n\r\n // Set Binaryen-specific options\r\n if (args.trapMode === \"clamp\") {\r\n stats.optimizeCount++;\r\n stats.optimizeTime += measure(() => {\r\n module.runPasses([ \"trap-mode-clamp\" ]);\r\n });\r\n } else if (args.trapMode === \"js\") {\r\n stats.optimizeCount++;\r\n stats.optimizeTime += measure(() => {\r\n module.runPasses([ \"trap-mode-js\" ]);\r\n });\r\n } else if (args.trapMode !== \"allow\") {\r\n module.dispose();\r\n return callback(Error(\"Unsupported trap mode\"));\r\n }\r\n\r\n // Implicitly run costly non-LLVM optimizations on -O3 or -Oz\r\n // see: https://github.com/WebAssembly/binaryen/pull/1596\r\n if (optimizeLevel >= 3 || shrinkLevel >= 2) optimizeLevel = 4;\r\n\r\n module.setOptimizeLevel(optimizeLevel);\r\n module.setShrinkLevel(shrinkLevel);\r\n module.setDebugInfo(!args.noDebug);\r\n\r\n var runPasses = [];\r\n if (args.runPasses) {\r\n if (typeof args.runPasses === \"string\") {\r\n args.runPasses = args.runPasses.split(\",\");\r\n }\r\n if (args.runPasses.length) {\r\n args.runPasses.forEach(pass => {\r\n if (runPasses.indexOf(pass) < 0)\r\n runPasses.push(pass);\r\n });\r\n }\r\n }\r\n\r\n // Optimize the module if requested\r\n if (optimizeLevel > 0 || shrinkLevel > 0) {\r\n stats.optimizeCount++;\r\n stats.optimizeTime += measure(() => {\r\n module.optimize();\r\n });\r\n }\r\n\r\n // Run additional passes if requested\r\n if (runPasses.length) {\r\n stats.optimizeCount++;\r\n stats.optimizeTime += measure(() => {\r\n module.runPasses(runPasses.map(pass => pass.trim()));\r\n });\r\n }\r\n\r\n // Prepare output\r\n if (!args.noEmit) {\r\n let hasStdout = false;\r\n let hasOutput = false;\r\n\r\n if (args.outFile != null) {\r\n if (/\\.was?t$/.test(args.outFile) && args.textFile == null) {\r\n args.textFile = args.outFile;\r\n } else if (/\\.js$/.test(args.outFile) && args.asmjsFile == null) {\r\n args.asmjsFile = args.outFile;\r\n } else if (args.binaryFile == null) {\r\n args.binaryFile = args.outFile;\r\n }\r\n }\r\n\r\n // Write binary\r\n if (args.binaryFile != null) {\r\n let sourceMapURL = args.sourceMap != null\r\n ? args.sourceMap.length\r\n ? args.sourceMap\r\n : path.basename(args.binaryFile) + \".map\"\r\n : null;\r\n\r\n let wasm;\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n wasm = module.toBinary(sourceMapURL)\r\n });\r\n\r\n if (args.binaryFile.length) {\r\n writeFile(path.join(baseDir, args.binaryFile), wasm.output);\r\n } else {\r\n writeStdout(wasm.output);\r\n hasStdout = true;\r\n }\r\n hasOutput = true;\r\n\r\n // Post-process source map\r\n if (wasm.sourceMap != null) {\r\n if (args.binaryFile.length) {\r\n let sourceMap = JSON.parse(wasm.sourceMap);\r\n sourceMap.sourceRoot = exports.sourceMapRoot;\r\n sourceMap.sources.forEach((name, index) => {\r\n let text = null;\r\n if (name.startsWith(exports.libraryPrefix)) {\r\n let stdName = name.substring(exports.libraryPrefix.length).replace(/\\.ts$/, \"\");\r\n if (exports.libraryFiles.hasOwnProperty(stdName)) {\r\n text = exports.libraryFiles[stdName];\r\n } else {\r\n for (let i = 0, k = customLibDirs.length; i < k; ++i) {\r\n text = readFile(path.join(\r\n customLibDirs[i],\r\n name.substring(exports.libraryPrefix.length))\r\n );\r\n if (text !== null) break;\r\n }\r\n }\r\n } else {\r\n text = readFile(path.join(baseDir, name));\r\n }\r\n if (text === null) {\r\n return callback(Error(\"Source file '\" + name + \"' not found.\"));\r\n }\r\n if (!sourceMap.sourceContents) sourceMap.sourceContents = [];\r\n sourceMap.sourceContents[index] = text;\r\n });\r\n writeFile(path.join(\r\n baseDir,\r\n path.dirname(args.binaryFile),\r\n path.basename(sourceMapURL)\r\n ), JSON.stringify(sourceMap));\r\n } else {\r\n stderr.write(\"Skipped source map (stdout already occupied)\" + EOL);\r\n }\r\n }\r\n }\r\n\r\n // Write asm.js\r\n if (args.asmjsFile != null) {\r\n let asm;\r\n if (args.asmjsFile.length) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n asm = module.toAsmjs();\r\n });\r\n writeFile(path.join(baseDir, args.asmjsFile), asm);\r\n } else if (!hasStdout) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n asm = module.toAsmjs();\r\n });\r\n writeStdout(asm);\r\n hasStdout = true;\r\n }\r\n hasOutput = true;\r\n }\r\n\r\n // Write WebIDL\r\n if (args.idlFile != null) {\r\n let idl;\r\n if (args.idlFile.length) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n idl = assemblyscript.buildIDL(program);\r\n });\r\n writeFile(path.join(baseDir, args.idlFile), idl);\r\n } else if (!hasStdout) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n idl = assemblyscript.buildIDL(program);\r\n });\r\n writeStdout(idl);\r\n hasStdout = true;\r\n }\r\n hasOutput = true;\r\n }\r\n\r\n // Write TypeScript definition\r\n if (args.tsdFile != null) {\r\n let tsd;\r\n if (args.tsdFile.length) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n tsd = assemblyscript.buildTSD(program);\r\n });\r\n writeFile(path.join(baseDir, args.tsdFile), tsd);\r\n } else if (!hasStdout) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n tsd = assemblyscript.buildTSD(program);\r\n });\r\n writeStdout(tsd);\r\n hasStdout = true;\r\n }\r\n hasOutput = true;\r\n }\r\n\r\n // Write text (must be last)\r\n if (args.textFile != null || !hasOutput) {\r\n let wat;\r\n if (args.textFile && args.textFile.length) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n wat = module.toText();\r\n });\r\n writeFile(path.join(baseDir, args.textFile), wat);\r\n } else if (!hasStdout) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n wat = module.toText()\r\n });\r\n writeStdout(wat);\r\n }\r\n }\r\n }\r\n\r\n module.dispose();\r\n if (args.measure) {\r\n printStats(stats, stderr);\r\n }\r\n return callback(null);\r\n\r\n function readFileNode(filename) {\r\n try {\r\n let text;\r\n stats.readCount++;\r\n stats.readTime += measure(() => {\r\n text = fs.readFileSync(filename, { encoding: \"utf8\" });\r\n });\r\n return text;\r\n } catch (e) {\r\n return null;\r\n }\r\n }\r\n\r\n function writeFileNode(filename, contents) {\r\n try {\r\n stats.writeCount++;\r\n stats.writeTime += measure(() => {\r\n mkdirp(path.dirname(filename));\r\n if (typeof contents === \"string\") {\r\n fs.writeFileSync(filename, contents, { encoding: \"utf8\" } );\r\n } else {\r\n fs.writeFileSync(filename, contents);\r\n }\r\n });\r\n return true;\r\n } catch (e) {\r\n return false;\r\n }\r\n }\r\n\r\n function listFilesNode(dirname) {\r\n var files;\r\n try {\r\n stats.readTime += measure(() => {\r\n files = fs.readdirSync(dirname).filter(file => /^(?!.*\\.d\\.ts$).*\\.ts$/.test(file));\r\n });\r\n return files;\r\n } catch (e) {\r\n return [];\r\n }\r\n }\r\n\r\n function writeStdout(contents) {\r\n if (!writeStdout.used) {\r\n stats.writeCount++;\r\n writeStdout.used = true;\r\n }\r\n stats.writeTime += measure(() => {\r\n if (typeof contents === \"string\") {\r\n stdout.write(contents, { encoding: \"utf8\" });\r\n } else {\r\n stdout.write(contents);\r\n }\r\n });\r\n }\r\n}\r\n\r\nvar argumentSubstitutions = {\r\n \"-O\" : [ \"--optimize\" ],\r\n \"-Os\" : [ \"--optimize\", \"--shrinkLevel\", \"1\" ],\r\n \"-Oz\" : [ \"--optimize\", \"--shrinkLevel\", \"2\" ],\r\n \"-O0\" : [ \"--optimizeLevel\", \"0\", \"--shrinkLevel\", \"0\" ],\r\n \"-O0s\": [ \"--optimizeLevel\", \"0\", \"--shrinkLevel\", \"1\" ],\r\n \"-O0z\": [ \"--optimizeLevel\", \"0\", \"--shrinkLevel\", \"2\" ],\r\n \"-O1\" : [ \"--optimizeLevel\", \"1\", \"--shrinkLevel\", \"0\" ],\r\n \"-O1s\": [ \"--optimizeLevel\", \"1\", \"--shrinkLevel\", \"1\" ],\r\n \"-O1z\": [ \"--optimizeLevel\", \"1\", \"--shrinkLevel\", \"2\" ],\r\n \"-O2\" : [ \"--optimizeLevel\", \"2\", \"--shrinkLevel\", \"0\" ],\r\n \"-O2s\": [ \"--optimizeLevel\", \"2\", \"--shrinkLevel\", \"1\" ],\r\n \"-O2z\": [ \"--optimizeLevel\", \"2\", \"--shrinkLevel\", \"2\" ],\r\n \"-O3\" : [ \"--optimizeLevel\", \"3\", \"--shrinkLevel\", \"0\" ],\r\n \"-O3s\": [ \"--optimizeLevel\", \"3\", \"--shrinkLevel\", \"1\" ],\r\n \"-O3z\": [ \"--optimizeLevel\", \"3\", \"--shrinkLevel\", \"2\" ],\r\n};\r\n\r\n/** Checks diagnostics emitted so far for errors. */\r\nfunction checkDiagnostics(emitter, stderr) {\r\n var diagnostic;\r\n var hasErrors = false;\r\n while ((diagnostic = assemblyscript.nextDiagnostic(emitter)) != null) {\r\n if (stderr) {\r\n stderr.write(\r\n assemblyscript.formatDiagnostic(diagnostic, stderr.isTTY, true) +\r\n EOL + EOL\r\n );\r\n }\r\n if (assemblyscript.isError(diagnostic)) hasErrors = true;\r\n }\r\n return hasErrors;\r\n}\r\n\r\nexports.checkDiagnostics = checkDiagnostics;\r\n\r\n/** Creates an empty set of stats. */\r\nfunction createStats() {\r\n return {\r\n readTime: 0,\r\n readCount: 0,\r\n writeTime: 0,\r\n writeCount: 0,\r\n parseTime: 0,\r\n parseCount: 0,\r\n compileTime: 0,\r\n compileCount: 0,\r\n emitTime: 0,\r\n emitCount: 0,\r\n validateTime: 0,\r\n validateCount: 0,\r\n optimizeTime: 0,\r\n optimizeCount: 0\r\n };\r\n}\r\n\r\nexports.createStats = createStats;\r\n\r\nif (!process.hrtime) process.hrtime = require(\"browser-process-hrtime\");\r\n\r\n/** Measures the execution time of the specified function. */\r\nfunction measure(fn) {\r\n const start = process.hrtime();\r\n fn();\r\n const times = process.hrtime(start);\r\n return times[0] * 1e9 + times[1];\r\n}\r\n\r\nexports.measure = measure;\r\n\r\n/** Formats a high resolution time to a human readable string. */\r\nfunction formatTime(time) {\r\n return time ? (time / 1e6).toFixed(3) + \" ms\" : \"N/A\";\r\n}\r\n\r\nexports.formatTime = formatTime;\r\n\r\n/** Formats and prints out the contents of a set of stats. */\r\nfunction printStats(stats, output) {\r\n function format(time, count) {\r\n return formatTime(time);\r\n }\r\n (output || process.stdout).write([\r\n \"I/O Read : \" + format(stats.readTime, stats.readCount),\r\n \"I/O Write : \" + format(stats.writeTime, stats.writeCount),\r\n \"Parse : \" + format(stats.parseTime, stats.parseCount),\r\n \"Compile : \" + format(stats.compileTime, stats.compileCount),\r\n \"Emit : \" + format(stats.emitTime, stats.emitCount),\r\n \"Validate : \" + format(stats.validateTime, stats.validateCount),\r\n \"Optimize : \" + format(stats.optimizeTime, stats.optimizeCount)\r\n ].join(EOL) + EOL);\r\n}\r\n\r\nexports.printStats = printStats;\r\n\r\nvar allocBuffer = typeof global !== \"undefined\" && global.Buffer\r\n ? global.Buffer.allocUnsafe || function(len) { return new global.Buffer(len); }\r\n : function(len) { return new Uint8Array(len) };\r\n\r\n/** Creates a memory stream that can be used in place of stdout/stderr. */\r\nfunction createMemoryStream(fn) {\r\n var stream = [];\r\n stream.write = function(chunk) {\r\n if (fn) fn(chunk);\r\n if (typeof chunk === \"string\") {\r\n let buffer = allocBuffer(utf8.length(chunk));\r\n utf8.write(chunk, buffer, 0);\r\n chunk = buffer;\r\n }\r\n this.push(chunk);\r\n };\r\n stream.reset = function() {\r\n stream.length = 0;\r\n };\r\n stream.toBuffer = function() {\r\n var offset = 0, i = 0, k = this.length;\r\n while (i < k) offset += this[i++].length;\r\n var buffer = allocBuffer(offset);\r\n offset = i = 0;\r\n while (i < k) {\r\n buffer.set(this[i], offset);\r\n offset += this[i].length;\r\n ++i;\r\n }\r\n return buffer;\r\n };\r\n stream.toString = function() {\r\n var buffer = this.toBuffer();\r\n return utf8.read(buffer, 0, buffer.length);\r\n };\r\n return stream;\r\n}\r\n\r\nexports.createMemoryStream = createMemoryStream;\r\n\r\n/** Compatible TypeScript compiler options for syntax highlighting etc. */\r\nexports.tscOptions = {\r\n alwaysStrict: true,\r\n noImplicitAny: true,\r\n noImplicitReturns: true,\r\n noImplicitThis: true,\r\n noEmitOnError: true,\r\n strictNullChecks: true,\r\n experimentalDecorators: true,\r\n target: \"esnext\",\r\n module: \"commonjs\",\r\n noLib: true,\r\n types: [],\r\n allowJs: false\r\n};\r\n","\"use strict\";\r\n\r\n/**\r\n * A minimal UTF8 implementation for number arrays.\r\n * @memberof util\r\n * @namespace\r\n */\r\nvar utf8 = exports;\r\n\r\n/**\r\n * Calculates the UTF8 byte length of a string.\r\n * @param {string} string String\r\n * @returns {number} Byte length\r\n */\r\nutf8.length = function utf8_length(string) {\r\n var len = 0,\r\n c = 0;\r\n for (var i = 0; i < string.length; ++i) {\r\n c = string.charCodeAt(i);\r\n if (c < 128)\r\n len += 1;\r\n else if (c < 2048)\r\n len += 2;\r\n else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {\r\n ++i;\r\n len += 4;\r\n } else\r\n len += 3;\r\n }\r\n return len;\r\n};\r\n\r\n/**\r\n * Reads UTF8 bytes as a string.\r\n * @param {Uint8Array} buffer Source buffer\r\n * @param {number} start Source start\r\n * @param {number} end Source end\r\n * @returns {string} String read\r\n */\r\nutf8.read = function utf8_read(buffer, start, end) {\r\n var len = end - start;\r\n if (len < 1)\r\n return \"\";\r\n var parts = null,\r\n chunk = [],\r\n i = 0, // char offset\r\n t; // temporary\r\n while (start < end) {\r\n t = buffer[start++];\r\n if (t < 128)\r\n chunk[i++] = t;\r\n else if (t > 191 && t < 224)\r\n chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;\r\n else if (t > 239 && t < 365) {\r\n t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;\r\n chunk[i++] = 0xD800 + (t >> 10);\r\n chunk[i++] = 0xDC00 + (t & 1023);\r\n } else\r\n chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;\r\n if (i > 8191) {\r\n (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));\r\n i = 0;\r\n }\r\n }\r\n if (parts) {\r\n if (i)\r\n parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));\r\n return parts.join(\"\");\r\n }\r\n return String.fromCharCode.apply(String, chunk.slice(0, i));\r\n};\r\n\r\n/**\r\n * Writes a string as UTF8 bytes.\r\n * @param {string} string Source string\r\n * @param {Uint8Array} buffer Destination buffer\r\n * @param {number} offset Destination offset\r\n * @returns {number} Bytes written\r\n */\r\nutf8.write = function utf8_write(string, buffer, offset) {\r\n var start = offset,\r\n c1, // character 1\r\n c2; // character 2\r\n for (var i = 0; i < string.length; ++i) {\r\n c1 = string.charCodeAt(i);\r\n if (c1 < 128) {\r\n buffer[offset++] = c1;\r\n } else if (c1 < 2048) {\r\n buffer[offset++] = c1 >> 6 | 192;\r\n buffer[offset++] = c1 & 63 | 128;\r\n } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {\r\n c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);\r\n ++i;\r\n buffer[offset++] = c1 >> 18 | 240;\r\n buffer[offset++] = c1 >> 12 & 63 | 128;\r\n buffer[offset++] = c1 >> 6 & 63 | 128;\r\n buffer[offset++] = c1 & 63 | 128;\r\n } else {\r\n buffer[offset++] = c1 >> 12 | 224;\r\n buffer[offset++] = c1 >> 6 & 63 | 128;\r\n buffer[offset++] = c1 & 63 | 128;\r\n }\r\n }\r\n return offset - start;\r\n};\r\n","var proc = typeof process !== \"undefined\" && process || {};\r\nvar isCI = proc.env && \"CI\" in proc.env; // doesn't work when bundled because 'process' is a mock\r\n\r\nfunction from(stream, base) {\r\n var colors = base || {};\r\n colors.supported = (stream && !!stream.isTTY) || isCI;\r\n colors.gray = text => colors.supported ? exports.GRAY + text + exports.RESET : text;\r\n colors.red = text => colors.supported ? exports.RED + text + exports.RESET : text;\r\n colors.green = text => colors.supported ? exports.GREEN + text + exports.RESET : text;\r\n colors.yellow = text => colors.supported ? exports.YELLOW + text + exports.RESET : text;\r\n colors.blue = text => colors.supported ? exports.BLUE + text + exports.RESET : text;\r\n colors.magenta = text => colors.supported ? exports.MAGENTA + text + exports.RESET : text;\r\n colors.cyan = text => colors.supported ? exports.CYAN + text + exports.RESET : text;\r\n colors.white = text => colors.supported ? exports.WHITE + text + exports.RESET : text;\r\n return colors;\r\n}\r\n\r\nexports.stdout = from(proc.stdout, exports);\r\nexports.stderr = from(proc.stderr);\r\nexports.from = from;\r\n\r\nexports.GRAY = \"\\u001b[90m\";\r\nexports.RED = \"\\u001b[91m\";\r\nexports.GREEN = \"\\u001b[92m\";\r\nexports.YELLOW = \"\\u001b[93m\";\r\nexports.BLUE = \"\\u001b[94m\";\r\nexports.MAGENTA = \"\\u001b[95m\";\r\nexports.CYAN = \"\\u001b[96m\";\r\nexports.WHITE = \"\\u001b[97m\";\r\nexports.RESET = \"\\u001b[0m\";\r\n","// type | meaning\r\n// -----|---------------\r\n// b | boolean\r\n// i | integer\r\n// f | float\r\n// s | string\r\n// I | integer array\r\n// F | float array\r\n// S | string array\r\n\r\n/** Parses the specified command line arguments according to the given configuration. */\r\nfunction parse(argv, config) {\r\n var options = {};\r\n var unknown = [];\r\n var arguments = [];\r\n var trailing = [];\r\n\r\n // make an alias map and initialize defaults\r\n var aliases = {};\r\n Object.keys(config).forEach(key => {\r\n var option = config[key];\r\n if (option.alias != null) {\r\n if (typeof option.alias === \"string\") aliases[option.alias] = key;\r\n else if (Array.isArray(option.alias)) option.alias.forEach(alias => aliases[alias] = key);\r\n }\r\n if (option.default != null) options[key] = option.default;\r\n });\r\n\r\n // iterate over argv\r\n for (var i = 0, k = (argv = argv.slice()).length; i < k; ++i) {\r\n let arg = argv[i];\r\n if (arg == \"--\") { ++i; break; }\r\n let match = /^(?:(\\-\\w)(?:=(.*))?|(\\-\\-\\w{2,})(?:=(.*))?)$/.exec(arg), option, key;\r\n if (match) {\r\n if (config[arg]) option = config[key = arg]; // exact\r\n else if (match[1] != null) { // alias\r\n option = config[key = aliases[match[1].substring(1)]];\r\n if (option && match[2] != null) argv[i--] = match[2];\r\n } else if (match[3] != null) { // full\r\n option = config[key = match[3].substring(2)];\r\n if (option && match[4] != null) argv[i--] = match[4];\r\n }\r\n } else {\r\n if (arg.charCodeAt(0) == 45) option = config[key = arg]; // exact\r\n else { arguments.push(arg); continue; } // argument\r\n }\r\n if (option) {\r\n if (option.type == null || option.type === \"b\") options[key] = true; // flag\r\n else {\r\n if (i + 1 < argv.length && argv[i + 1].charCodeAt(0) != 45) { // present\r\n switch (option.type) {\r\n case \"i\": options[key] = parseInt(argv[++i], 10); break;\r\n case \"I\": options[key] = (options[key] || []).concat(parseInt(argv[++i], 10)); break;\r\n case \"f\": options[key] = parseFloat(argv[++i]); break;\r\n case \"F\": options[key] = (options[key] || []).concat(parseFloat(argv[++i])); break;\r\n case \"s\": options[key] = String(argv[++i]); break;\r\n case \"S\": options[key] = (options[key] || []).concat(argv[++i].split(\",\")); break;\r\n default: unknown.push(arg); --i;\r\n }\r\n } else { // omitted\r\n switch (option.type) {\r\n case \"i\":\r\n case \"f\": options[key] = option.default || 0; break;\r\n case \"s\": options[key] = option.default || \"\"; break;\r\n case \"I\":\r\n case \"F\":\r\n case \"S\": options[key] = options.default || []; break;\r\n default: unknown.push(arg);\r\n }\r\n }\r\n }\r\n if (option.value) Object.keys(option.value).forEach(k => options[k] = option.value[k]);\r\n } else unknown.push(arg);\r\n }\r\n while (i < k) trailing.push(argv[i++]); // trailing\r\n\r\n return { options, unknown, arguments, trailing };\r\n}\r\n\r\nexports.parse = parse;\r\n\r\n/** Generates the help text for the specified configuration. */\r\nfunction help(config, options) {\r\n if (!options) options = {};\r\n var indent = options.indent || 2;\r\n var padding = options.padding || 24;\r\n var eol = options.eol || \"\\n\";\r\n var sb = [];\r\n Object.keys(config).forEach(key => {\r\n var option = config[key];\r\n if (option.description == null) return;\r\n var text = \"\";\r\n while (text.length < indent) text += \" \";\r\n text += \"--\" + key;\r\n if (option.alias) text += \", -\" + option.alias;\r\n while (text.length < padding) text += \" \";\r\n if (Array.isArray(option.description)) {\r\n sb.push(text + option.description[0] + option.description.slice(1).map(line => {\r\n for (let i = 0; i < padding; ++i) line = \" \" + line;\r\n return eol + line;\r\n }).join(\"\"));\r\n } else sb.push(text + option.description);\r\n });\r\n return sb.join(eol);\r\n}\r\n\r\nexports.help = help;\r\n","/*\r\nCopyright 2010 James Halliday (mail@substack.net)\r\n\r\nThis project is free software released under the MIT/X11 license:\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in\r\nall copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\nTHE SOFTWARE.\r\n*/\r\n\r\nvar path = require(\"path\");\r\nvar fs = require(\"fs\");\r\nvar _0777 = parseInt(\"0777\", 8);\r\n\r\nmodule.exports = function mkdirp(p, opts, made) {\r\n if (!opts || typeof opts !== \"object\") {\r\n opts = { mode: opts };\r\n }\r\n var mode = opts.mode;\r\n if (mode === undefined) {\r\n mode = _0777 & (~process.umask());\r\n }\r\n if (!made) made = null;\r\n p = path.resolve(p);\r\n try {\r\n fs.mkdirSync(p, mode);\r\n made = made || p;\r\n } catch (err0) {\r\n switch (err0.code) {\r\n case \"ENOENT\":\r\n made = mkdirp(path.dirname(p), opts, made);\r\n mkdirp(p, opts, made);\r\n break;\r\n default:\r\n var stat;\r\n try {\r\n stat = fs.statSync(p);\r\n } catch (err1) {\r\n throw err0;\r\n }\r\n if (!stat.isDirectory()) throw err0;\r\n break;\r\n }\r\n }\r\n return made;\r\n};\r\n","if(typeof __WEBPACK_EXTERNAL_MODULE__10__ === 'undefined') {var e = new Error(\"Cannot find module 'assemblyscript'\"); e.code = 'MODULE_NOT_FOUND'; throw e;}\nmodule.exports = __WEBPACK_EXTERNAL_MODULE__10__;","function webpackEmptyContext(req) {\n\tvar e = new Error(\"Cannot find module '\" + req + \"'\");\n\te.code = 'MODULE_NOT_FOUND';\n\tthrow e;\n}\nwebpackEmptyContext.keys = function() { return []; };\nwebpackEmptyContext.resolve = webpackEmptyContext;\nmodule.exports = webpackEmptyContext;\nwebpackEmptyContext.id = 12;","module.exports = process.hrtime || hrtime\n\n// polyfil for window.performance.now\nvar performance = global.performance || {}\nvar performanceNow =\n performance.now ||\n performance.mozNow ||\n performance.msNow ||\n performance.oNow ||\n performance.webkitNow ||\n function(){ return (new Date()).getTime() }\n\n// generate timestamp or delta\n// see http://nodejs.org/api/process.html#process_process_hrtime\nfunction hrtime(previousTimestamp){\n var clocktime = performanceNow.call(performance)*1e-3\n var seconds = Math.floor(clocktime)\n var nanoseconds = Math.floor((clocktime%1)*1e9)\n if (previousTimestamp) {\n seconds = seconds - previousTimestamp[0]\n nanoseconds = nanoseconds - previousTimestamp[1]\n if (nanoseconds<0) {\n seconds--\n nanoseconds += 1e9\n }\n }\n return [seconds,nanoseconds]\n}"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://asc/webpack/universalModuleDefinition","webpack://asc/webpack/bootstrap","webpack://asc/../node_modules/node-libs-browser/mock/process.js","webpack://asc/../node_modules/path-browserify/index.js","webpack://asc/../node_modules/webpack/buildin/global.js","webpack://asc/./asc.js","webpack://asc/../node_modules/@protobufjs/utf8/index.js","webpack://asc/./util/colors.js","webpack://asc/./util/options.js","webpack://asc/./util/mkdirp.js","webpack://asc/external \"assemblyscript\"","webpack://asc/. sync","webpack://asc/../node_modules/browser-process-hrtime/index.js"],"names":["root","factory","exports","module","require","e","define","amd","self","this","__WEBPACK_EXTERNAL_MODULE__10__","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","nextTick","fn","setTimeout","platform","arch","execPath","title","pid","browser","env","argv","binding","Error","path","cwd","chdir","dir","resolve","exit","kill","umask","dlopen","uptime","memoryUsage","uvCounters","features","process","normalizeArray","parts","allowAboveRoot","up","length","last","splice","unshift","splitPathRe","splitPath","filename","exec","slice","filter","xs","f","res","push","resolvedPath","resolvedAbsolute","arguments","TypeError","charAt","split","join","normalize","isAbsolute","trailingSlash","substr","paths","Array","index","relative","from","to","trim","arr","start","end","fromParts","toParts","Math","min","samePartsLength","outputParts","concat","sep","delimiter","dirname","result","basename","ext","extname","str","len","g","Function","eval","window","global","fs","utf8","colorsUtil","optionsUtil","mkdirp","EOL","removeAllListeners","assemblyscript","isDev","code","register","project","e_ts","stack","isBundle","version","options","sourceMapRoot","libraryPrefix","LIBRARY_PREFIX","defaultOptimizeLevel","defaultShrinkLevel","libraryFiles","allocator/arena","allocator/buddy","allocator/emscripten","allocator/system","allocator/tlsf","array","arraybuffer","bindings/Math","builtins","collector/itcm","diagnostics","error","gc","internal/allocator","internal/array","internal/arraybuffer","internal/hash","internal/memory","internal/number","internal/string","internal/typedarray","iterator","map","math","memory","polyfills","regexp","set","string","symbol","table","typedarray","libDir","bundled","sync","forEach","file","replace","readFileSync","definitionFiles","assembly","portable","stdDir","compileString","sources","input.ts","output","stdout","createMemoryStream","stderr","binary","text","keys","val","isArray","String","main","readFile","writeFile","contents","listFiles","callback","readFileNode","writeFileNode","listFilesNode","stats","createStats","opts","parse","args","noColors","supported","unknown","arg","write","yellow","trailing","err","red","help","out","color","white","cyan","baseDir","transforms","transform","parser","noLib","parseCount","parseTime","measure","parseFile","libPath","indexOf","customLibDirs","lib","apply","k","libFiles","endsWith","j","libText","sourcePath","sourceText","nextFile","startsWith","plainName","substring","indexName","checkDiagnostics","applyTransform","program","finishParsing","optimizeLevel","shrinkLevel","optimize","max","compilerOptions","createOptions","setTarget","setNoTreeShaking","noTreeShaking","setNoAssert","noAssert","setImportMemory","importMemory","setImportTable","importTable","setMemoryBase","memoryBase","setSourceMap","sourceMap","setOptimizeLevelHints","setGlobalAlias","use","aliases","part","alias","enable","flag","toUpperCase","enableFeature","compileCount","compileTime","compileProgram","dispose","validate","validateCount","validateTime","trapMode","optimizeCount","optimizeTime","runPasses","setOptimizeLevel","setShrinkLevel","setDebugInfo","debug","pass","noEmit","hasStdout","hasOutput","outFile","test","textFile","asmjsFile","binaryFile","wasm","sourceMapURL","emitCount","emitTime","toBinary","writeStdout","JSON","sourceRoot","stdName","sourceContents","stringify","asm","toAsmjs","idlFile","idl","buildIDL","tsdFile","tsd","buildTSD","wat","toText","printStats","readCount","readTime","encoding","writeCount","writeTime","writeFileSync","files","readdirSync","used","argumentSubstitutions","-O","-Os","-Oz","-O0","-O0s","-O0z","-O1","-O1s","-O1z","-O2","-O2s","-O2z","-O3","-O3s","-O3z","emitter","diagnostic","hasErrors","nextDiagnostic","formatDiagnostic","isTTY","isError","hrtime","times","formatTime","time","toFixed","format","count","allocBuffer","Buffer","allocUnsafe","Uint8Array","stream","chunk","buffer","reset","toBuffer","offset","toString","read","tscOptions","alwaysStrict","noImplicitAny","noImplicitReturns","noImplicitThis","noEmitOnError","strictNullChecks","experimentalDecorators","target","types","allowJs","charCodeAt","fromCharCode","c1","c2","proc","isCI","base","colors","gray","GRAY","RESET","RED","green","GREEN","YELLOW","blue","BLUE","magenta","MAGENTA","CYAN","WHITE","config","option","default","match","type","parseInt","parseFloat","indent","padding","eol","sb","description","line","_0777","made","undefined","mkdirSync","err0","stat","statSync","err1","isDirectory","webpackEmptyContext","req","id","previousTimestamp","clocktime","performanceNow","performance","seconds","floor","nanoseconds","now","mozNow","msNow","oNow","webkitNow","Date","getTime"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,EAAA,WAA0E,IAAM,OAAAG,QAAA,kBAAoC,MAAAC,KAApH,IACA,mBAAAC,eAAAC,IACAD,QAAA,kBAAAL,GACA,iBAAAC,QACAA,QAAA,IAAAD,EAAA,WAA0E,IAAM,OAAAG,QAAA,kBAAoC,MAAAC,KAApH,IAEAL,EAAA,IAAAC,EAAAD,EAAA,gBARA,CASC,oBAAAQ,UAAAC,KAAA,SAAAC,iCACD,mBCTA,IAAAC,KAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAX,QAGA,IAAAC,EAAAQ,EAAAE,IACAC,EAAAD,EACAE,GAAA,EACAb,YAUA,OANAc,EAAAH,GAAAI,KAAAd,EAAAD,QAAAC,IAAAD,QAAAU,GAGAT,EAAAY,GAAA,EAGAZ,EAAAD,QA0DA,OArDAU,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAlB,EAAAmB,EAAAC,GACAV,EAAAW,EAAArB,EAAAmB,IACAG,OAAAC,eAAAvB,EAAAmB,GAA0CK,YAAA,EAAAC,IAAAL,KAK1CV,EAAAgB,EAAA,SAAA1B,GACA,oBAAA2B,eAAAC,aACAN,OAAAC,eAAAvB,EAAA2B,OAAAC,aAAwDC,MAAA,WAExDP,OAAAC,eAAAvB,EAAA,cAAiD6B,OAAA,KAQjDnB,EAAAoB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAAnB,EAAAmB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,EACA,IAAAI,EAAAX,OAAAY,OAAA,MAGA,GAFAxB,EAAAgB,EAAAO,GACAX,OAAAC,eAAAU,EAAA,WAAyCT,YAAA,EAAAK,UACzC,EAAAE,GAAA,iBAAAF,EAAA,QAAAM,KAAAN,EAAAnB,EAAAQ,EAAAe,EAAAE,EAAA,SAAAA,GAAgH,OAAAN,EAAAM,IAAqBC,KAAA,KAAAD,IACrI,OAAAF,GAIAvB,EAAA2B,EAAA,SAAApC,GACA,IAAAmB,EAAAnB,KAAA+B,WACA,WAA2B,OAAA/B,EAAA,SAC3B,WAAiC,OAAAA,GAEjC,OADAS,EAAAQ,EAAAE,EAAA,IAAAA,GACAA,GAIAV,EAAAW,EAAA,SAAAiB,EAAAC,GAAsD,OAAAjB,OAAAkB,UAAAC,eAAA1B,KAAAuB,EAAAC,IAGtD7B,EAAAgC,EAAA,GAIAhC,IAAAiC,EAAA,qBClFA3C,EAAA4C,SAAA,SAAAC,GACAC,WAAAD,EAAA,IAGA7C,EAAA+C,SAAA/C,EAAAgD,KACAhD,EAAAiD,SAAAjD,EAAAkD,MAAA,UACAlD,EAAAmD,IAAA,EACAnD,EAAAoD,SAAA,EACApD,EAAAqD,OACArD,EAAAsD,QAEAtD,EAAAuD,QAAA,SAAApC,GACA,UAAAqC,MAAA,8CAGA,WACA,IACAC,EADAC,EAAA,IAEA1D,EAAA0D,IAAA,WAA+B,OAAAA,GAC/B1D,EAAA2D,MAAA,SAAAC,GACAH,MAA0B/C,EAAQ,IAClCgD,EAAAD,EAAAI,QAAAD,EAAAF,IANA,GAUA1D,EAAA8D,KAAA9D,EAAA+D,KACA/D,EAAAgE,MAAAhE,EAAAiE,OACAjE,EAAAkE,OAAAlE,EAAAmE,YACAnE,EAAAoE,WAAA,aACApE,EAAAqE,8BC7BA,SAAAC,GAyBA,SAAAC,EAAAC,EAAAC,GAGA,IADA,IAAAC,EAAA,EACA9D,EAAA4D,EAAAG,OAAA,EAAgC/D,GAAA,EAAQA,IAAA,CACxC,IAAAgE,EAAAJ,EAAA5D,GACA,MAAAgE,EACAJ,EAAAK,OAAAjE,EAAA,GACK,OAAAgE,GACLJ,EAAAK,OAAAjE,EAAA,GACA8D,KACKA,IACLF,EAAAK,OAAAjE,EAAA,GACA8D,KAKA,GAAAD,EACA,KAAUC,IAAMA,EAChBF,EAAAM,QAAA,MAIA,OAAAN,EAKA,IAAAO,EACA,gEACAC,EAAA,SAAAC,GACA,OAAAF,EAAAG,KAAAD,GAAAE,MAAA,IAuJA,SAAAC,EAAAC,EAAAC,GACA,GAAAD,EAAAD,OAAA,OAAAC,EAAAD,OAAAE,GAEA,IADA,IAAAC,KACA3E,EAAA,EAAmBA,EAAAyE,EAAAV,OAAe/D,IAClC0E,EAAAD,EAAAzE,KAAAyE,IAAAE,EAAAC,KAAAH,EAAAzE,IAEA,OAAA2E,EAxJAvF,EAAA6D,QAAA,WAIA,IAHA,IAAA4B,EAAA,GACAC,GAAA,EAEA9E,EAAA+E,UAAAhB,OAAA,EAAoC/D,IAAA,IAAA8E,EAA8B9E,IAAA,CAClE,IAAA6C,EAAA7C,GAAA,EAAA+E,UAAA/E,GAAA0D,EAAAZ,MAGA,oBAAAD,EACA,UAAAmC,UAAA,6CACKnC,IAILgC,EAAAhC,EAAA,IAAAgC,EACAC,EAAA,MAAAjC,EAAAoC,OAAA,IAWA,OAJAJ,EAAAlB,EAAAa,EAAAK,EAAAK,MAAA,cAAApD,GACA,QAAAA,KACGgD,GAAAK,KAAA,MAEHL,EAAA,QAAAD,GAAA,KAKAzF,EAAAgG,UAAA,SAAAvC,GACA,IAAAwC,EAAAjG,EAAAiG,WAAAxC,GACAyC,EAAA,MAAAC,EAAA1C,GAAA,GAcA,OAXAA,EAAAc,EAAAa,EAAA3B,EAAAqC,MAAA,cAAApD,GACA,QAAAA,KACGuD,GAAAF,KAAA,OAEHE,IACAxC,EAAA,KAEAA,GAAAyC,IACAzC,GAAA,MAGAwC,EAAA,QAAAxC,GAIAzD,EAAAiG,WAAA,SAAAxC,GACA,YAAAA,EAAAoC,OAAA,IAIA7F,EAAA+F,KAAA,WACA,IAAAK,EAAAC,MAAA7D,UAAA2C,MAAApE,KAAA4E,UAAA,GACA,OAAA3F,EAAAgG,UAAAZ,EAAAgB,EAAA,SAAA1D,EAAA4D,GACA,oBAAA5D,EACA,UAAAkD,UAAA,0CAEA,OAAAlD,IACGqD,KAAA,OAMH/F,EAAAuG,SAAA,SAAAC,EAAAC,GAIA,SAAAC,EAAAC,GAEA,IADA,IAAAC,EAAA,EACUA,EAAAD,EAAAhC,QACV,KAAAgC,EAAAC,GAD8BA,KAK9B,IADA,IAAAC,EAAAF,EAAAhC,OAAA,EACUkC,GAAA,GACV,KAAAF,EAAAE,GADoBA,KAIpB,OAAAD,EAAAC,KACAF,EAAAxB,MAAAyB,EAAAC,EAAAD,EAAA,GAfAJ,EAAAxG,EAAA6D,QAAA2C,GAAAL,OAAA,GACAM,EAAAzG,EAAA6D,QAAA4C,GAAAN,OAAA,GAsBA,IALA,IAAAW,EAAAJ,EAAAF,EAAAV,MAAA,MACAiB,EAAAL,EAAAD,EAAAX,MAAA,MAEAnB,EAAAqC,KAAAC,IAAAH,EAAAnC,OAAAoC,EAAApC,QACAuC,EAAAvC,EACA/D,EAAA,EAAiBA,EAAA+D,EAAY/D,IAC7B,GAAAkG,EAAAlG,KAAAmG,EAAAnG,GAAA,CACAsG,EAAAtG,EACA,MAIA,IAAAuG,KACA,IAAAvG,EAAAsG,EAA+BtG,EAAAkG,EAAAnC,OAAsB/D,IACrDuG,EAAA3B,KAAA,MAKA,OAFA2B,IAAAC,OAAAL,EAAA5B,MAAA+B,KAEAnB,KAAA,MAGA/F,EAAAqH,IAAA,IACArH,EAAAsH,UAAA,IAEAtH,EAAAuH,QAAA,SAAA9D,GACA,IAAA+D,EAAAxC,EAAAvB,GACA3D,EAAA0H,EAAA,GACA5D,EAAA4D,EAAA,GAEA,OAAA1H,GAAA8D,GAKAA,IAEAA,IAAAuC,OAAA,EAAAvC,EAAAe,OAAA,IAGA7E,EAAA8D,GARA,KAYA5D,EAAAyH,SAAA,SAAAhE,EAAAiE,GACA,IAAApC,EAAAN,EAAAvB,GAAA,GAKA,OAHAiE,GAAApC,EAAAa,QAAA,EAAAuB,EAAA/C,UAAA+C,IACApC,IAAAa,OAAA,EAAAb,EAAAX,OAAA+C,EAAA/C,SAEAW,GAIAtF,EAAA2H,QAAA,SAAAlE,GACA,OAAAuB,EAAAvB,GAAA,IAaA,IAAA0C,EAAA,WAAAA,QAAA,GACA,SAAAyB,EAAAhB,EAAAiB,GAAkC,OAAAD,EAAAzB,OAAAS,EAAAiB,IAClC,SAAAD,EAAAhB,EAAAiB,GAEA,OADAjB,EAAA,IAAAA,EAAAgB,EAAAjD,OAAAiC,GACAgB,EAAAzB,OAAAS,EAAAiB,qCC7NA,IAAAC,EAGAA,EAAA,WACA,OAAAvH,KADA,GAIA,IAEAuH,KAAAC,SAAA,cAAAA,KAAA,EAAAC,MAAA,QACC,MAAA7H,GAED,iBAAA8H,SAAAH,EAAAG,QAOAhI,EAAAD,QAAA8H,iGCnBA,SAAAxD,QAAA4D,QAcA5D,QAAAlB,UAAAkB,QAAAZ,IAAA,WAA+C,YAE/C,MAAAyE,GAAWzH,oBAAQ,GACnB+C,KAAa/C,oBAAQ,GACrB0H,KAAa1H,oBAAQ,GACrB2H,WAAmB3H,oBAAQ,GAC3B4H,YAAoB5H,oBAAQ,GAC5B6H,OAAe7H,oBAAQ,GACvB8H,IAAA,UAAAlE,QAAAvB,SAAA,YAIAuB,QAAAmE,oBAAAnE,QAAAmE,mBAAA,qBAGA,IAAAC,eAAAC,OAAA,EACA,MACA,IACAD,eAAqBhI,oBAAQ,IAC1B,MAAAP,GACH,IACMO,qBAAQ,eAAAP,EAAA,IAAAqD,MAAA,sCAAArD,EAAAyI,KAAA,mBAAAzI,EAAA,IAAS0I,UAAYC,QAAArF,KAAAsC,KAAoB,IAAS,8BAC1DrF,qBAAQ,eAAAP,EAAA,IAAAqD,MAAA,6CAAArD,EAAAyI,KAAA,mBAAAzI,EAAA,IACduI,eAAuBhI,qBAAQ,eAAAP,EAAA,IAAAqD,MAAA,qCAAArD,EAAAyI,KAAA,mBAAAzI,EAAA,IAC/BwI,OAAA,EACK,MAAAI,MACL,IACAL,eAAAV,KAAA,+BACO,MAAA7H,GAGP,MADAA,EAAA6I,MAAAD,KAAAC,MAAA,UAAA7I,EAAA6I,MACA7I,MAfA,GAsBAH,QAAAiJ,UAAmB,EAGnBjJ,QAAA2I,YAGA3I,QAAAkJ,QAAAlJ,QAAAiJ,SAAqC,QAAiBvI,qBAAQ,eAAAP,EAAA,IAAAqD,MAAA,8CAAArD,EAAAyI,KAAA,mBAAAzI,EAAA,IAAiB+I,QAG/ElJ,QAAAmJ,QAAkBzI,oBAAQ,IAG1BV,QAAAoJ,cAAA,qBAGApJ,QAAAqJ,cAAAX,eAAAY,eAGAtJ,QAAAuJ,qBAAA,EAGAvJ,QAAAwJ,mBAAA,EAGAxJ,QAAAyJ,aAAAzJ,QAAAiJ,SAA0C3H,QAAAoI,kBAAA,otCAAAC,kBAAA,+ymBAAAC,uBAAA,0nBAAAC,mBAAA,khBAAAC,iBAAA,mujBAAAC,MAAA,+7mBAAAC,YAAA,2iCAAAC,gBAAA,q5DAAAC,SAAA,okUAAAC,iBAAA,8hPAAAC,YAAA,yNAAA/G,IAAA,+QAAAgH,MAAA,iPAAAC,GAAA,yVAAAC,qBAAA,6VAAAC,iBAAA,20IAAAC,uBAAA,ixGAAAC,gBAAA,stEAAAC,kBAAA,s3OAAAC,kBAAA,y0rBAAAC,kBAAA,mtMAAAC,sBAAA,4lIAAAC,SAAA,4GAAAC,IAAA,6mNAAAC,KAAA,4n9EAAAC,OAAA,81DAAAC,UAAA,u7BAAAC,OAAA,2YAAAC,IAAA,w+LAAAC,OAAA,wjlBAAAC,OAAA,yvDAAAC,MAAA,8aAAAC,WAAA,8oGAAc,MACxD,MAAAC,EAAAjI,KAAAsC,KAA2B,IAAS,uBAEpC4F,KAEA,OAHmBjL,qBAAQ,eAAAP,EAAA,IAAAqD,MAAA,mCAAArD,EAAAyI,KAAA,mBAAAzI,EAAA,IAAMyL,KAAA,gBAAwBlI,IAAAgI,IAEzDG,QAAAC,GAAAH,EAAAG,EAAAC,QAAA,aAAA5D,GAAA6D,aAAAvI,KAAAsC,KAAA2F,EAAAI,GAAA,SACAH,GALwD,GASxD3L,QAAAiM,gBAAAjM,QAAAiJ,SAA6C3H,QAAA4K,SAAA,o7gCAAAC,SAAA,s5hBAAkB,MAC/D,MAAAC,EAAA3I,KAAAsC,KAA2B,IAAS,YACpC,OACAmG,SAAA/D,GAAA6D,aAAAvI,KAAAsC,KAAAqG,EAAA,iCACAD,SAAAhE,GAAA6D,aAAAvI,KAAAsC,KAAAqG,EAAA,mCAJ+D,GAS/DpM,QAAAqM,cAAA,EAAAC,EAAAnD,KACA,iBAAAmD,OAA8CC,WAAAD,IAC9C,MAAAE,EAAAlL,OAAAY,QACAuK,OAAAC,qBACAC,OAAAD,qBACAE,OAAA,KACAC,KAAA,OAEA,IAAAvJ,GACA,wBACA,qBAcA,OAZAhC,OAAAwL,KAAA3D,OAA2B0C,QAAA1J,IAC3B,IAAA4K,EAAA5D,EAAAhH,GACAkE,MAAA2G,QAAAD,KAAAlB,QAAAkB,GAAAzJ,EAAAkC,KAAA,KAAArD,EAAA8K,OAAAF,KACAzJ,EAAAkC,KAAA,KAAArD,EAAA8K,OAAAF,MAEA/M,QAAAkN,KAAA5J,EAAA8D,OAAA9F,OAAAwL,KAAAR,KACAG,OAAAD,EAAAC,OACAE,OAAAH,EAAAG,OACAQ,SAAAhM,GAAAmL,EAAA7J,eAAAtB,GAAAmL,EAAAnL,GAAA,KACAiM,UAAA,CAAAjM,EAAAkM,IAAAb,EAAArL,GAAAkM,EACAC,UAAA,SAEAd,IAIAxM,QAAAkN,KAAA,SAAA5J,EAAA6F,EAAAoE,GACA,mBAAApE,GACAoE,EAAApE,EACAA,MACGA,IACHA,MAGA,MAAAsD,EAAAtD,EAAAsD,QAAAnI,QAAAmI,OACAE,EAAAxD,EAAAwD,QAAArI,QAAAqI,OACAQ,EAAAhE,EAAAgE,UAAAK,EACAJ,EAAAjE,EAAAiE,WAAAK,EACAH,EAAAnE,EAAAmE,WAAAI,EACAC,EAAAxE,EAAAwE,OAAAC,cAGA,IAAAnB,EAAA,MAAAjJ,MAAA,sCACA,IAAAmJ,EAAA,MAAAnJ,MAAA,sCAEA,MAAAqK,EAAAvF,YAAAwF,MAAAxK,EAAAtD,QAAAmJ,SACA4E,EAAAF,EAAA1E,QAiCA,GAhCA7F,EAAAuK,EAAAlI,UACAoI,EAAAC,SACA3F,WAAAoE,OAAAwB,UACA5F,WAAAsE,OAAAsB,WAAA,GAEA5F,WAAAoE,OAAApE,WAAA7B,KAAAiG,GACApE,WAAAsE,OAAAtE,WAAA7B,KAAAmG,IAIAkB,EAAAK,QAAAvJ,QACAkJ,EAAAK,QAAArC,QAAAsC,IACAxB,EAAAyB,MAAA/F,WAAAsE,OAAA0B,OAAA,6BAAAF,EAAA,IAAA3F,OAKAqF,EAAAS,SAAA3J,QACAgI,EAAAyB,MAAA/F,WAAAsE,OAAA0B,OAAA,6CAAAR,EAAAS,SAAAvI,KAAA,KAAAyC,KAIA+E,MAAA,SAAAgB,GACA,IAAA3F,EAAA,EAKA,OAJA2F,IACA5B,EAAAyB,MAAA/F,WAAAsE,OAAA6B,IAAA,WAAAD,EAAAvF,MAAA+C,QAAA,gBAAAvD,KACAI,EAAA,GAEAA,IAIAmF,EAAA7E,QAEA,OADAuD,EAAA2B,MAAA,WAAApO,QAAAkJ,SAAAP,MAAA,WAAAH,KACA+E,EAAA,MAGA,GAAAQ,EAAAU,OAAAnL,EAAAqB,OAAA,CACA,IAAA+J,EAAAX,EAAAU,KAAAhC,EAAAE,EACAgC,EAAAZ,EAAAU,KAAApG,WAAAoE,OAAApE,WAAAsE,OAcA,OAbA+B,EAAAN,OACAO,EAAAC,MAAA,UACA,KAAAD,EAAAE,KAAA,oCACA,GACAF,EAAAC,MAAA,YACA,KAAAD,EAAAE,KAAA,mBACA,KAAAF,EAAAE,KAAA,8CACA,KAAAF,EAAAE,KAAA,iDACA,GACAF,EAAAC,MAAA,YACAxH,OACAkB,YAAAmG,KAAAzO,QAAAmJ,QAAA,GAAAX,MACAzC,KAAAyC,UACA+E,EAAA,MAIA,IAAApF,GAAA6D,aAAA,CACA,GAAAmB,IAAAK,EAAA,MAAAhK,MAAA,wCACA,GAAA4J,IAAAK,EAAA,MAAAjK,MAAA,yCACA,GAAA8J,IAAAI,EAAA,MAAAlK,MAAA,yCAIA,MAAAsL,EAAAf,EAAAe,QAAArL,KAAAI,QAAAkK,EAAAe,SAAA,IAGAC,KACAhB,EAAAiB,WACAjB,EAAAiB,UAAAnD,QAAAmD,GACAD,EAAAvJ,KACQ9E,oBAAA,GAAAA,CACE+C,KAAAwC,WAAA+I,IAAAtI,QACVsI,EACAvL,KAAAsC,KAAAzB,QAAAZ,MAAAsL,MAYA,IAAAC,EAAA,KAGAlB,EAAAmB,OAcAvB,EAAAwB,aACAxB,EAAAyB,WAAAC,QAAA,KACAJ,EAAAvG,eAAA4G,UACAtP,QAAAyJ,aAAA,SACAzJ,QAAAqJ,cAAA,eACA,EACA4F,MAnBA3N,OAAAwL,KAAA9M,QAAAyJ,cAAAoC,QAAA0D,IACAA,EAAAC,QAAA,UACA7B,EAAAwB,aACAxB,EAAAyB,WAAAC,QAAA,KACAJ,EAAAvG,eAAA4G,UACAtP,QAAAyJ,aAAA8F,GACAvP,QAAAqJ,cAAAkG,EAAA,OACA,EACAN,QAeA,MAAAQ,KACA,GAAA1B,EAAA2B,IAAA,CACA,IAAAA,EAAA3B,EAAA2B,IACA,iBAAAA,QAAA5J,MAAA,MACAO,MAAA7D,UAAAgD,KAAAmK,MAAAF,EAAAC,EAAA1E,IAAA0E,KAAAhJ,SACA,QAAA9F,EAAA,EAAAgP,EAAAH,EAAA9K,OAA6C/D,EAAAgP,IAAOhP,EAAA,CACpD,IACAiP,EADAnE,EAAA+D,EAAA7O,GAEA8K,EAAAoE,SAAA,QACAD,GAAApM,KAAAgE,SAAAiE,IACAA,EAAAjI,KAAA8D,QAAAmE,IAEAmE,EAAAvC,EAAA5B,GAEA,QAAAqE,EAAA,EAAAlP,EAAAgP,EAAAlL,OAA0CoL,EAAAlP,IAAOkP,EAAA,CACjD,IAAAR,EAAAM,EAAAE,GACAC,EAAA7C,EAAA1J,KAAAsC,KAAA2F,EAAA6D,IACA,UAAAS,EAAA,OAAAzC,EAAA/J,MAAA,iBAAA+L,EAAA,iBACA5B,EAAAwB,aACAxB,EAAAyB,WAAAC,QAAA,KACAJ,EAAAvG,eAAA4G,UACAU,EACAhQ,QAAAqJ,cAAAkG,GACA,EACAN,OAQA,QAAArO,EAAA,EAAAgP,EAAAtM,EAAAqB,OAAkC/D,EAAAgP,IAAOhP,EAAA,CACzC,MAAAqE,EAAA3B,EAAA1C,GAEA,IAAAqP,EAAAhD,OAAAhI,GAAA8G,QAAA,WAAAA,QAAA,iBAGAmE,EAAA/C,EAAA1J,KAAAsC,KAAA+I,EAAAmB,GAAA,OACA,UAAAC,EAAA,CAEA,WADAA,EAAA/C,EAAA1J,KAAAsC,KAAA+I,EAAAmB,EAAA,cAEA,OAAA1C,EAAA/J,MAAA,eAAAyM,EAAA,oBAEAA,GAAA,iBAGAA,GAAA,MASA,IANAtC,EAAAwB,aACAxB,EAAAyB,WAAAC,QAAA,KACAJ,EAAAvG,eAAA4G,UAAAY,EAAAD,GAAA,EAAAhB,KAIA,OAAAgB,EAAAhB,EAAAkB,aAAA,CAIA,GAAAF,EAAAG,WAAApQ,QAAAqJ,eAAA,CACA,MAAAgH,EAAAJ,EAAAK,UAAAtQ,QAAAqJ,cAAA1E,QACA4L,EAAAN,EAAAK,UAAAtQ,QAAAqJ,cAAA1E,QAAA,SACA,GAAA3E,QAAAyJ,aAAAhH,eAAA4N,GACAH,EAAAlQ,QAAAyJ,aAAA4G,GACAJ,EAAAjQ,QAAAqJ,cAAAgH,EAAA,WACS,GAAArQ,QAAAyJ,aAAAhH,eAAA8N,GACTL,EAAAlQ,QAAAyJ,aAAA8G,GACAN,EAAAjQ,QAAAqJ,cAAAkH,EAAA,WAEA,QAAA3P,EAAA,EAAAgP,EAAAH,EAAA9K,OAAmD/D,EAAAgP,IAAOhP,EAAA,CAC1D,MAAAgD,EAAA6L,EAAA7O,GAEA,WADAsP,EAAA/C,EAAA1J,KAAAsC,KAAAnC,EAAAyM,EAAA,SACA,CACAJ,EAAAjQ,QAAAqJ,cAAAgH,EAAA,MACA,MAGA,WADAH,EAAA/C,EAAA1J,KAAAsC,KAAAnC,EAAA2M,EAAA,SACA,CACAN,EAAAjQ,QAAAqJ,cAAAkH,EAAA,MACA,YAOO,CACP,MAAAF,EAAAJ,EACAM,EAAAN,EAAA,SAEA,WADAC,EAAA/C,EAAA1J,KAAAsC,KAAA+I,EAAAuB,EAAA,SAEAJ,EAAAI,EAAA,WAGA,WADAH,EAAA/C,EAAA1J,KAAAsC,KAAA+I,EAAAyB,EAAA,SAEAN,EAAAM,EAAA,WACW,IAAAF,EAAAD,WAAA,KACX,GAAApQ,QAAAyJ,aAAAhH,eAAA4N,GACAH,EAAAlQ,QAAAyJ,aAAA4G,GACAJ,EAAAjQ,QAAAqJ,cAAAgH,EAAA,WACa,GAAArQ,QAAAyJ,aAAAhH,eAAA8N,GACbL,EAAAlQ,QAAAyJ,aAAA8G,GACAN,EAAAjQ,QAAAqJ,cAAAkH,EAAA,WAEA,QAAA3P,EAAA,EAAAgP,EAAAH,EAAA9K,OAAuD/D,EAAAgP,IAAOhP,EAAA,CAC9D,MAAAgD,EAAA6L,EAAA7O,GAEA,WADAsP,EAAA/C,EAAA1J,KAAAsC,KAAAnC,EAAAyM,EAAA,SACA,CACAJ,EAAAjQ,QAAAqJ,cAAAgH,EAAA,MACA,MAGA,WADAH,EAAA/C,EAAA1J,KAAAsC,KAAAnC,EAAA2M,EAAA,SACA,CACAN,EAAAjQ,QAAAqJ,cAAAkH,EAAA,MACA,QAQA,SAAAL,EACA,OAAA3C,EAAA/J,MAAA,gBAAAyM,EAAA,oBAEAtC,EAAAwB,aACAxB,EAAAyB,WAAAC,QAAA,KACA3G,eAAA4G,UAAAY,EAAAD,GAAA,EAAAhB,KAGA,GAAAuB,iBAAAvB,EAAAtC,GACA,OAAAY,EAAA/J,MAAA,iBAtKA,SAAArC,KAAA4M,GACAgB,EAAAlD,QAAAmD,IACA,mBAAAA,EAAA7N,IAAA6N,EAAA7N,MAAA4M,KAwKA0C,CAAA,aAAAxB,GAGA,MAAAyB,EAAAhI,eAAAiI,cAAA1B,GAGA,IAAA2B,EAAA,EACAC,EAAA,EACA9C,EAAA+C,WACAF,EAAA5Q,QAAAuJ,qBACAsH,EAAA7Q,QAAAwJ,oBAEA,iBAAAuE,EAAA6C,gBACAA,EAAA7C,EAAA6C,eAEA,iBAAA7C,EAAA8C,cACAA,EAAA9C,EAAA8C,aAEAD,EAAA5J,KAAAC,IAAAD,KAAA+J,IAAAH,EAAA,MACAC,EAAA7J,KAAAC,IAAAD,KAAA+J,IAAAF,EAAA,MAGA,MAAAG,EAAAtI,eAAAuI,gBAmBA,GAlBAvI,eAAAwI,UAAAF,EAAA,GACAtI,eAAAyI,iBAAAH,EAAAjD,EAAAqD,eACA1I,eAAA2I,YAAAL,EAAAjD,EAAAuD,UACA5I,eAAA6I,gBAAAP,EAAAjD,EAAAyD,cACA9I,eAAA+I,eAAAT,EAAAjD,EAAA2D,aACAhJ,eAAAiJ,cAAAX,EAAAjD,EAAA6D,aAAA,GACAlJ,eAAAmJ,aAAAb,EAAA,MAAAjD,EAAA+D,WACApJ,eAAAqJ,sBAAAf,EAAAJ,EAAAC,GAEA9C,EAAAmB,QAEAxG,eAAAsJ,eAAAhB,EAAA,qBACAtI,eAAAsJ,eAAAhB,EAAA,uBACAtI,eAAAsJ,eAAAhB,EAAA,0BACAtI,eAAAsJ,eAAAhB,EAAA,2BAIAjD,EAAAkE,IAAA,CACA,IAAAC,EAAAnE,EAAAkE,IACA,QAAArR,EAAA,EAAAgP,EAAAsC,EAAAvN,OAAuC/D,EAAAgP,IAAOhP,EAAA,CAC9C,IAAAuR,EAAAD,EAAAtR,GACA8B,EAAAyP,EAAA3C,QAAA,KACA,GAAA9M,EAAA,SAAA6K,EAAA/J,MAAA,iBAAA2O,EAAA,kBACA,IAAAhR,EAAAgR,EAAA7B,UAAA,EAAA5N,GAAAgE,OACA0L,EAAAD,EAAA7B,UAAA5N,EAAA,GAAAgE,OACA,IAAAvF,EAAAwD,OAAA,OAAA4I,EAAA/J,MAAA,iBAAA2O,EAAA,kBACAzJ,eAAAsJ,eAAAhB,EAAA7P,EAAAiR,IAKA,IAWAnS,EAXAoE,EAAA0J,EAAAsE,OACA,SAAAhO,EAAA,CACA,iBAAAA,QAAAyB,MAAA,MACA,QAAAlF,EAAA,EAAAgP,EAAAvL,EAAAM,OAAwC/D,EAAAgP,IAAOhP,EAAA,CAC/C,IAAAO,EAAAkD,EAAAzD,GAAA8F,OACA4L,EAAA5J,eAAA,WAAAvH,EAAA4K,QAAA,WAAAwG,eACA,IAAAD,EAAA,OAAA/E,EAAA/J,MAAA,YAAArC,EAAA,kBACAuH,eAAA8J,cAAAxB,EAAAsB,IAeA,GAVA3E,EAAA8E,eACA,MACA,IACA9E,EAAA+E,aAAArD,QAAA,KACApP,EAAAyI,eAAAiK,eAAAjC,EAAAM,KAEK,MAAA7Q,GACL,OAAAoN,EAAApN,KANA,GASAqQ,iBAAAvB,EAAAtC,GAEA,OADA1M,KAAA2S,UACArF,EAAA/J,MAAA,kBAeA,GAXAuK,EAAA8E,WACAlF,EAAAmF,gBACAnF,EAAAoF,cAAA1D,QAAA,KACA,IAAApP,EAAA4S,WAEA,OADA5S,EAAA2S,UACArF,EAAA/J,MAAA,sBAMA,UAAAuK,EAAAiF,SACArF,EAAAsF,gBACAtF,EAAAuF,cAAA7D,QAAA,KACApP,EAAAkT,WAAA,2BAEG,UAAApF,EAAAiF,SACHrF,EAAAsF,gBACAtF,EAAAuF,cAAA7D,QAAA,KACApP,EAAAkT,WAAA,wBAEG,aAAApF,EAAAiF,SAEH,OADA/S,EAAA2S,UACArF,EAAA/J,MAAA,2BAKAoN,GAAA,GAAAC,GAAA,KAAAD,EAAA,GAEA3Q,EAAAmT,iBAAAxC,GACA3Q,EAAAoT,eAAAxC,GACA5Q,EAAAqT,aAAAvF,EAAAwF,OAEA,IAAAJ,KA8BA,GA7BApF,EAAAoF,YACA,iBAAApF,EAAAoF,YACApF,EAAAoF,UAAApF,EAAAoF,UAAArN,MAAA,MAEAiI,EAAAoF,UAAAxO,QACAoJ,EAAAoF,UAAAtH,QAAA2H,IACAL,EAAA3D,QAAAgE,GAAA,GACAL,EAAA3N,KAAAgO,OAMA5C,EAAA,GAAAC,EAAA,KACAlD,EAAAsF,gBACAtF,EAAAuF,cAAA7D,QAAA,KACApP,EAAA6Q,cAKAqC,EAAAxO,SACAgJ,EAAAsF,gBACAtF,EAAAuF,cAAA7D,QAAA,KACApP,EAAAkT,YAAAnI,IAAAwI,KAAA9M,aAKAqH,EAAA0F,OAAA,CACA,IAAAC,GAAA,EACAC,GAAA,EAaA,GAXA,MAAA5F,EAAA6F,UACA,WAAAC,KAAA9F,EAAA6F,UAAA,MAAA7F,EAAA+F,SACA/F,EAAA+F,SAAA/F,EAAA6F,QACO,QAAAC,KAAA9F,EAAA6F,UAAA,MAAA7F,EAAAgG,UACPhG,EAAAgG,UAAAhG,EAAA6F,QACO,MAAA7F,EAAAiG,aACPjG,EAAAiG,WAAAjG,EAAA6F,UAKA,MAAA7F,EAAAiG,WAAA,CACA,IAMAC,EANAC,EAAA,MAAAnG,EAAA+D,UACA/D,EAAA+D,UAAAnN,OACAoJ,EAAA+D,UACArO,KAAAgE,SAAAsG,EAAAiG,YAAA,OACA,KAiBA,GAdArG,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACA4E,EAAAhU,EAAAoU,SAAAH,KAGAnG,EAAAiG,WAAArP,OACAyI,EAAA3J,KAAAsC,KAAA+I,EAAAf,EAAAiG,YAAAC,EAAAzH,SAEA8H,EAAAL,EAAAzH,QACAkH,GAAA,GAEAC,GAAA,EAGA,MAAAM,EAAAnC,UACA,GAAA/D,EAAAiG,WAAArP,OAAA,CACA,IAAAmN,EAAAyC,KAAAzG,MAAAmG,EAAAnC,WACAA,EAAA0C,WAAAxU,QAAAoJ,cACA0I,EAAAxF,QAAAT,QAAA,CAAA1K,EAAAmF,KACA,IAAAuG,EAAA,KACA,GAAA1L,EAAAiP,WAAApQ,QAAAqJ,eAAA,CACA,IAAAoL,EAAAtT,EAAAmP,UAAAtQ,QAAAqJ,cAAA1E,QAAAoH,QAAA,YACA,GAAA/L,QAAAyJ,aAAAhH,eAAAgS,GACA5H,EAAA7M,QAAAyJ,aAAAgL,QAEA,QAAA7T,EAAA,EAAAgP,EAAAH,EAAA9K,OAAyD/D,EAAAgP,GAKzD,QAJA/C,EAAAM,EAAA1J,KAAAsC,KACA0J,EAAA7O,GACAO,EAAAmP,UAAAtQ,QAAAqJ,cAAA1E,aAHgE/D,SAShEiM,EAAAM,EAAA1J,KAAAsC,KAAA+I,EAAA3N,IAEA,UAAA0L,EACA,OAAAU,EAAA/J,MAAA,gBAAArC,EAAA,iBAEA2Q,EAAA4C,iBAAA5C,EAAA4C,mBACA5C,EAAA4C,eAAApO,GAAAuG,IAEAO,EAAA3J,KAAAsC,KACA+I,EACArL,KAAA8D,QAAAwG,EAAAiG,YACAvQ,KAAAgE,SAAAyM,IACAK,KAAAI,UAAA7C,SAEAnF,EAAAyB,MAAA,+CAAA5F,KAMA,SAAAuF,EAAAgG,UAAA,CACA,IAAAa,EACA7G,EAAAgG,UAAApP,QACAgJ,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACAuF,EAAA3U,EAAA4U,YAEAzH,EAAA3J,KAAAsC,KAAA+I,EAAAf,EAAAgG,WAAAa,IACOlB,IACP/F,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACAuF,EAAA3U,EAAA4U,YAEAP,EAAAM,GACAlB,GAAA,GAEAC,GAAA,EAIA,SAAA5F,EAAA+G,QAAA,CACA,IAAAC,EACAhH,EAAA+G,QAAAnQ,QACAgJ,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACA0F,EAAArM,eAAAsM,SAAAtE,KAEAtD,EAAA3J,KAAAsC,KAAA+I,EAAAf,EAAA+G,SAAAC,IACOrB,IACP/F,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACA0F,EAAArM,eAAAsM,SAAAtE,KAEA4D,EAAAS,GACArB,GAAA,GAEAC,GAAA,EAIA,SAAA5F,EAAAkH,QAAA,CACA,IAAAC,EACAnH,EAAAkH,QAAAtQ,QACAgJ,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACA6F,EAAAxM,eAAAyM,SAAAzE,KAEAtD,EAAA3J,KAAAsC,KAAA+I,EAAAf,EAAAkH,SAAAC,IACOxB,IACP/F,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACA6F,EAAAxM,eAAAyM,SAAAzE,KAEA4D,EAAAY,GACAxB,GAAA,GAEAC,GAAA,EAIA,SAAA5F,EAAA+F,WAAAH,EAAA,CACA,IAAAyB,EACArH,EAAA+F,UAAA/F,EAAA+F,SAAAnP,QACAgJ,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACA+F,EAAAnV,EAAAoV,WAEAjI,EAAA3J,KAAAsC,KAAA+I,EAAAf,EAAA+F,UAAAsB,IACO1B,IACP/F,EAAAwG,YACAxG,EAAAyG,UAAA/E,QAAA,KACA+F,EAAAnV,EAAAoV,WAEAf,EAAAc,KASA,OAJAnV,EAAA2S,UACA7E,EAAAsB,SACAiG,WAAA3H,EAAAhB,GAEAY,EAAA,MAEA,SAAAC,EAAAvI,GACA,IACA,IAAA4H,EAKA,OAJAc,EAAA4H,YACA5H,EAAA6H,UAAAnG,QAAA,KACAxC,EAAA1E,GAAA6D,aAAA/G,GAA0CwQ,SAAA,WAE1C5I,EACK,MAAA1M,GACL,aAIA,SAAAsN,EAAAxI,EAAAoI,GACA,IAUA,OATAM,EAAA+H,aACA/H,EAAAgI,WAAAtG,QAAA,KACA9G,OAAA9E,KAAA8D,QAAAtC,IACA,iBAAAoI,EACAlF,GAAAyN,cAAA3Q,EAAAoI,GAAgDoI,SAAA,SAEhDtN,GAAAyN,cAAA3Q,EAAAoI,MAGA,EACK,MAAAlN,GACL,UAIA,SAAAuN,EAAAnG,GACA,IAAAsO,EACA,IAIA,OAHAlI,EAAA6H,UAAAnG,QAAA,KACAwG,EAAA1N,GAAA2N,YAAAvO,GAAAnC,OAAA0G,GAAA,yBAAA+H,KAAA/H,MAEA+J,EACK,MAAA1V,GACL,UAIA,SAAAmU,EAAAjH,GACAiH,EAAAyB,OACApI,EAAA+H,aACApB,EAAAyB,MAAA,GAEApI,EAAAgI,WAAAtG,QAAA,KACA,iBAAAhC,EACAZ,EAAA2B,MAAAf,GAAgCoI,SAAA,SAEhChJ,EAAA2B,MAAAf,OAMA,IAAA2I,uBACAC,MAAA,cACAC,OAAA,kCACAC,OAAA,kCACAC,OAAA,2CACAC,QAAA,2CACAC,QAAA,2CACAC,OAAA,2CACAC,QAAA,2CACAC,QAAA,2CACAC,OAAA,2CACAC,QAAA,2CACAC,QAAA,2CACAC,OAAA,2CACAC,QAAA,2CACAC,QAAA,4CAIA,SAAAvG,iBAAAwG,EAAArK,GAGA,IAFA,IAAAsK,EACAC,GAAA,EACA,OAAAD,EAAAvO,eAAAyO,eAAAH,KACArK,GACAA,EAAAyB,MACA1F,eAAA0O,iBAAAH,EAAAtK,EAAA0K,OAAA,GACA7O,SAGAE,eAAA4O,QAAAL,KAAAC,GAAA,GAEA,OAAAA,EAMA,SAAAtJ,cACA,OACA4H,SAAA,EACAD,UAAA,EACAI,UAAA,EACAD,WAAA,EACAtG,UAAA,EACAD,WAAA,EACAuD,YAAA,EACAD,aAAA,EACA2B,SAAA,EACAD,UAAA,EACApB,aAAA,EACAD,cAAA,EACAI,aAAA,EACAD,cAAA,GASA,SAAA5D,QAAAxM,GACA,MAAA+D,EAAAtC,QAAAiT,SACA1U,IACA,MAAA2U,EAAAlT,QAAAiT,OAAA3Q,GACA,WAAA4Q,EAAA,GAAAA,EAAA,GAMA,SAAAC,WAAAC,GACA,OAAAA,KAAA,KAAAC,QAAA,eAMA,SAAArC,WAAA3H,EAAAnB,GACA,SAAAoL,EAAAF,EAAAG,GACA,OAAAJ,WAAAC,IAEAlL,GAAAlI,QAAAmI,QAAA2B,OACA,eAAAwJ,EAAAjK,EAAA6H,SAAA7H,EAAA4H,WACA,eAAAqC,EAAAjK,EAAAgI,UAAAhI,EAAA+H,YACA,eAAAkC,EAAAjK,EAAAyB,UAAAzB,EAAAwB,YACA,eAAAyI,EAAAjK,EAAA+E,YAAA/E,EAAA8E,cACA,eAAAmF,EAAAjK,EAAAyG,SAAAzG,EAAAwG,WACA,eAAAyD,EAAAjK,EAAAoF,aAAApF,EAAAmF,eACA,eAAA8E,EAAAjK,EAAAuF,aAAAvF,EAAAsF,gBACAlN,KAAAyC,UAxDAxI,QAAAwQ,kCAsBAxQ,QAAA4N,wBAEAtJ,QAAAiT,SAAAjT,QAAAiT,OAAsC7W,oBAAQ,KAU9CV,QAAAqP,gBAOArP,QAAAyX,sBAkBAzX,QAAAsV,sBAEA,IAAAwC,iBAAA,IAAA5P,eAAA6P,OACA7P,OAAA6P,OAAAC,aAAA,SAAAnQ,GAAgD,WAAAK,OAAA6P,OAAAlQ,IAChD,SAAAA,GAAmB,WAAAoQ,WAAApQ,IAGnB,SAAA6E,mBAAA7J,GACA,IAAAqV,KA6BA,OA5BAA,EAAA9J,MAAA,SAAA+J,GAEA,GADAtV,KAAAsV,GACA,iBAAAA,EAAA,CACA,IAAAC,EAAAN,YAAA1P,KAAAzD,OAAAwT,IACA/P,KAAAgG,MAAA+J,EAAAC,EAAA,GACAD,EAAAC,EAEA7X,KAAAiF,KAAA2S,IAEAD,EAAAG,MAAA,WACAH,EAAAvT,OAAA,GAEAuT,EAAAI,SAAA,WAEA,IADA,IAAAC,EAAA,EAAA3X,EAAA,EAAAgP,EAAArP,KAAAoE,OACA/D,EAAAgP,GAAA2I,GAAAhY,KAAAK,KAAA+D,OACA,IAAAyT,EAAAN,YAAAS,GAEA,IADAA,EAAA3X,EAAA,EACAA,EAAAgP,GACAwI,EAAA/M,IAAA9K,KAAAK,GAAA2X,GACAA,GAAAhY,KAAAK,GAAA+D,SACA/D,EAEA,OAAAwX,GAEAF,EAAAM,SAAA,WACA,IAAAJ,EAAA7X,KAAA+X,WACA,OAAAlQ,KAAAqQ,KAAAL,EAAA,EAAAA,EAAAzT,SAEAuT,EAGAlY,QAAA0M,sCAGA1M,QAAA0Y,YACAC,cAAA,EACAC,eAAA,EACAC,mBAAA,EACAC,gBAAA,EACAC,eAAA,EACAC,kBAAA,EACAC,wBAAA,EACAC,OAAA,SACAjZ,OAAA,WACAiP,OAAA,EACAiK,SACAC,SAAA,4FCl4BA,IAAAhR,EAAApI,EAOAoI,EAAAzD,OAAA,SAAA2G,GAGA,IAFA,IAAAzD,EAAA,EACA5G,EAAA,EACAL,EAAA,EAAmBA,EAAA0K,EAAA3G,SAAmB/D,GACtCK,EAAAqK,EAAA+N,WAAAzY,IACA,IACAiH,GAAA,EACA5G,EAAA,KACA4G,GAAA,EACA,cAAA5G,IAAA,cAAAqK,EAAA+N,WAAAzY,EAAA,OACAA,EACAiH,GAAA,GAEAA,GAAA,EAEA,OAAAA,GAUAO,EAAAqQ,KAAA,SAAAL,EAAAxR,EAAAC,GAEA,GADAA,EAAAD,EACA,EACA,SAKA,IAJA,IAGA9E,EAHA0C,EAAA,KACA2T,KACAvX,EAAA,EAEAgG,EAAAC,IACA/E,EAAAsW,EAAAxR,MACA,IACAuR,EAAAvX,KAAAkB,EACAA,EAAA,KAAAA,EAAA,IACAqW,EAAAvX,MAAA,GAAAkB,IAAA,KAAAsW,EAAAxR,KACA9E,EAAA,KAAAA,EAAA,KACAA,IAAA,EAAAA,IAAA,OAAAsW,EAAAxR,OAAA,OAAAwR,EAAAxR,OAAA,KAAAwR,EAAAxR,MAAA,MACAuR,EAAAvX,KAAA,OAAAkB,GAAA,IACAqW,EAAAvX,KAAA,YAAAkB,IAEAqW,EAAAvX,MAAA,GAAAkB,IAAA,OAAAsW,EAAAxR,OAAA,KAAAwR,EAAAxR,KACAhG,EAAA,QACA4D,WAAAgB,KAAAyH,OAAAqM,aAAA3J,MAAA1C,OAAAkL,IACAvX,EAAA,GAGA,OAAA4D,GACA5D,GACA4D,EAAAgB,KAAAyH,OAAAqM,aAAA3J,MAAA1C,OAAAkL,EAAAhT,MAAA,EAAAvE,KACA4D,EAAAuB,KAAA,KAEAkH,OAAAqM,aAAA3J,MAAA1C,OAAAkL,EAAAhT,MAAA,EAAAvE,KAUAwH,EAAAgG,MAAA,SAAA9C,EAAA8M,EAAAG,GAIA,IAHA,IACAgB,EACAC,EAFA5S,EAAA2R,EAGA3X,EAAA,EAAmBA,EAAA0K,EAAA3G,SAAmB/D,GACtC2Y,EAAAjO,EAAA+N,WAAAzY,IACA,IACAwX,EAAAG,KAAAgB,EACSA,EAAA,MACTnB,EAAAG,KAAAgB,GAAA,MACAnB,EAAAG,KAAA,GAAAgB,EAAA,KACS,cAAAA,IAAA,eAAAC,EAAAlO,EAAA+N,WAAAzY,EAAA,MACT2Y,EAAA,aAAAA,IAAA,UAAAC,KACA5Y,EACAwX,EAAAG,KAAAgB,GAAA,OACAnB,EAAAG,KAAAgB,GAAA,UACAnB,EAAAG,KAAAgB,GAAA,SACAnB,EAAAG,KAAA,GAAAgB,EAAA,MAEAnB,EAAAG,KAAAgB,GAAA,OACAnB,EAAAG,KAAAgB,GAAA,SACAnB,EAAAG,KAAA,GAAAgB,EAAA,KAGA,OAAAhB,EAAA3R,qBCvGA,SAAAtC,GAAA,IAAAmV,OAAA,IAAAnV,SACAoV,EAAAD,EAAApW,KAAA,OAAAoW,EAAApW,IAEA,SAAAmD,EAAA0R,EAAAyB,GACA,IAAAC,EAAAD,MAUA,OATAC,EAAA3L,UAAAiK,OAAAb,OAAAqC,EACAE,EAAAC,KAAAhN,IAAA+M,EAAA3L,UAAAjO,EAAA8Z,KAAAjN,EAAA7M,EAAA+Z,MAAAlN,GACA+M,EAAApL,IAAA3B,IAAA+M,EAAA3L,UAAAjO,EAAAga,IAAAnN,EAAA7M,EAAA+Z,MAAAlN,GACA+M,EAAAK,MAAApN,IAAA+M,EAAA3L,UAAAjO,EAAAka,MAAArN,EAAA7M,EAAA+Z,MAAAlN,GACA+M,EAAAvL,OAAAxB,IAAA+M,EAAA3L,UAAAjO,EAAAma,OAAAtN,EAAA7M,EAAA+Z,MAAAlN,GACA+M,EAAAQ,KAAAvN,IAAA+M,EAAA3L,UAAAjO,EAAAqa,KAAAxN,EAAA7M,EAAA+Z,MAAAlN,GACA+M,EAAAU,QAAAzN,IAAA+M,EAAA3L,UAAAjO,EAAAua,QAAA1N,EAAA7M,EAAA+Z,MAAAlN,GACA+M,EAAA/K,KAAAhC,IAAA+M,EAAA3L,UAAAjO,EAAAwa,KAAA3N,EAAA7M,EAAA+Z,MAAAlN,GACA+M,EAAAhL,MAAA/B,IAAA+M,EAAA3L,UAAAjO,EAAAya,MAAA5N,EAAA7M,EAAA+Z,MAAAlN,GACA+M,EAGA5Z,EAAAyM,OAAAjG,EAAAiT,EAAAhN,OAAAzM,GACAA,EAAA2M,OAAAnG,EAAAiT,EAAA9M,QACA3M,EAAAwG,OAEAxG,EAAA8Z,KAAA,QACA9Z,EAAAga,IAAA,QACAha,EAAAka,MAAA,QACAla,EAAAma,OAAA,QACAna,EAAAqa,KAAA,QACAra,EAAAua,QAAA,QACAva,EAAAwa,KAAA,QACAxa,EAAAya,MAAA,QACAza,EAAA+Z,MAAA,wCCkDA/Z,EAAA8N,MApEA,SAAAxK,EAAAoX,GACA,IAAAvR,KACA+E,KACAvI,aACA2I,KAGA4D,KACA5Q,OAAAwL,KAAA4N,GAAA7O,QAAA1J,IACA,IAAAwY,EAAAD,EAAAvY,GACA,MAAAwY,EAAAvI,QACA,iBAAAuI,EAAAvI,MAAAF,EAAAyI,EAAAvI,OAAAjQ,EACAkE,MAAA2G,QAAA2N,EAAAvI,QAAAuI,EAAAvI,MAAAvG,QAAAuG,GAAAF,EAAAE,GAAAjQ,IAEA,MAAAwY,EAAAC,UAAAzR,EAAAhH,GAAAwY,EAAAC,WAIA,QAAAha,EAAA,EAAAgP,GAAAtM,IAAA6B,SAAAR,OAAmD/D,EAAAgP,IAAOhP,EAAA,CAC1D,IAAAuN,EAAA7K,EAAA1C,GACA,SAAAuN,EAAA,GAAsBvN,EAAK,MAC3B,IAAiD+Z,EAAAxY,EAAjD0Y,EAAA,gDAAiD3V,KAAAiJ,GACjD,GAAA0M,EACAH,EAAAvM,GAAAwM,EAAAD,EAAAvY,EAAAgM,GACA,MAAA0M,EAAA,IACAF,EAAAD,EAAAvY,EAAA+P,EAAA2I,EAAA,GAAAvK,UAAA,OACA,MAAAuK,EAAA,KAAAvX,EAAA1C,KAAAia,EAAA,IACO,MAAAA,EAAA,KACPF,EAAAD,EAAAvY,EAAA0Y,EAAA,GAAAvK,UAAA,MACA,MAAAuK,EAAA,KAAAvX,EAAA1C,KAAAia,EAAA,QAEK,CACL,OAAA1M,EAAAkL,WAAA,GACA,CAAY1T,UAAAH,KAAA2I,GAAqB,SADjCwM,EAAAD,EAAAvY,EAAAgM,GAGA,GAAAwM,EAAA,CACA,SAAAA,EAAAG,MAAA,MAAAH,EAAAG,KAAA3R,EAAAhH,IAAA,OAEA,GAAAvB,EAAA,EAAA0C,EAAAqB,QAAA,IAAArB,EAAA1C,EAAA,GAAAyY,WAAA,GACA,OAAAsB,EAAAG,MACA,QAAA3R,EAAAhH,GAAA4Y,SAAAzX,IAAA1C,GAAA,IAA6D,MAC7D,QAAAuI,EAAAhH,IAAAgH,EAAAhH,QAAAiF,OAAA2T,SAAAzX,IAAA1C,GAAA,KAA0F,MAC1F,QAAAuI,EAAAhH,GAAA6Y,WAAA1X,IAAA1C,IAA2D,MAC3D,QAAAuI,EAAAhH,IAAAgH,EAAAhH,QAAAiF,OAAA4T,WAAA1X,IAAA1C,KAAwF,MACxF,QAAAuI,EAAAhH,GAAA8K,OAAA3J,IAAA1C,IAAuD,MACvD,QAAAuI,EAAAhH,IAAAgH,EAAAhH,QAAAiF,OAAA9D,IAAA1C,GAAAkF,MAAA,MAAuF,MACvF,QAAAoI,EAAA1I,KAAA2I,KAAuCvN,OAGvC,OAAA+Z,EAAAG,MACA,QACA,QAAA3R,EAAAhH,GAAAwY,EAAAC,SAAA,EAAyD,MACzD,QAAAzR,EAAAhH,GAAAwY,EAAAC,SAAA,GAA0D,MAC1D,QACA,QACA,QAAAzR,EAAAhH,GAAAgH,EAAAyR,YAA2D,MAC3D,QAAA1M,EAAA1I,KAAA2I,GAIAwM,EAAA9Y,OAAAP,OAAAwL,KAAA6N,EAAA9Y,OAAAgK,QAAA+D,GAAAzG,EAAAyG,GAAA+K,EAAA9Y,MAAA+N,SACK1B,EAAA1I,KAAA2I,GAEL,KAAAvN,EAAAgP,GAAAtB,EAAA9I,KAAAlC,EAAA1C,MAEA,OAAUuI,UAAA+E,UAAAvI,oBAAA2I,aA8BVtO,EAAAyO,KAxBA,SAAAiM,EAAAvR,GACAA,UACA,IAAA8R,EAAA9R,EAAA8R,QAAA,EACAC,EAAA/R,EAAA+R,SAAA,GACAC,EAAAhS,EAAAgS,KAAA,KACAC,KAgBA,OAfA9Z,OAAAwL,KAAA4N,GAAA7O,QAAA1J,IACA,IAAAwY,EAAAD,EAAAvY,GACA,SAAAwY,EAAAU,YAAA,CAEA,IADA,IAAAxO,EAAA,GACAA,EAAAlI,OAAAsW,GAAApO,GAAA,IAGA,IAFAA,GAAA,KAAA1K,EACAwY,EAAAvI,QAAAvF,GAAA,MAAA8N,EAAAvI,OACAvF,EAAAlI,OAAAuW,GAAArO,GAAA,IACAxG,MAAA2G,QAAA2N,EAAAU,aACAD,EAAA5V,KAAAqH,EAAA8N,EAAAU,YAAA,GAAAV,EAAAU,YAAAlW,MAAA,GAAA6F,IAAAsQ,IACA,QAAA1a,EAAA,EAAuBA,EAAAsa,IAAata,EAAA0a,EAAA,IAAAA,EACpC,OAAAH,EAAAG,IACOvV,KAAA,KACFqV,EAAA5V,KAAAqH,EAAA8N,EAAAU,gBAELD,EAAArV,KAAAoV,sBCvGA,SAAA7W,GAwBA,IAAAb,EAAW/C,EAAQ,GACnByH,EAASzH,EAAQ,GACjB6a,EAAAR,SAAA,UAEA9a,EAAAD,QAAA,SAAAuI,EAAA7F,EAAAmL,EAAA2N,GACA3N,GAAA,iBAAAA,IACAA,GAAY9L,KAAA8L,IAEZ,IAAA9L,EAAA8L,EAAA9L,UACA0Z,IAAA1Z,IACAA,EAAAwZ,GAAAjX,EAAAN,SAEAwX,MAAA,MACA9Y,EAAAe,EAAAI,QAAAnB,GACA,IACAyF,EAAAuT,UAAAhZ,EAAAX,GACAyZ,KAAA9Y,EACG,MAAAiZ,GACH,OAAAA,EAAA/S,MACA,aAEAL,EAAA7F,EAAAmL,EADA2N,EAAAjT,EAAA9E,EAAA8D,QAAA7E,GAAAmL,EAAA2N,IAEA,MACA,QACA,IAAAI,EACA,IACAA,EAAAzT,EAAA0T,SAAAnZ,GACS,MAAAoZ,GACT,MAAAH,EAEA,IAAAC,EAAAG,cAAA,MAAAJ,GAIA,OAAAH,oCC1DA,YAAAhb,gCAAA,CAA4D,IAAAL,EAAA,IAAAqD,MAAA,uCAAsF,MAA7BrD,EAAAyI,KAAA,mBAA6BzI,EAClJF,EAAAD,QAAAQ,yyICDA,SAAAwb,EAAAC,GACA,IAAA9b,EAAA,IAAAqD,MAAA,uBAAAyY,EAAA,KAEA,MADA9b,EAAAyI,KAAA,mBACAzI,EAEA6b,EAAAlP,KAAA,WAAuC,UACvCkP,EAAAnY,QAAAmY,EACA/b,EAAAD,QAAAgc,EACAA,EAAAE,GAAA,qBCRA,SAAA5X,EAAA4D,GAAAjI,EAAAD,QAAAsE,EAAAiT,QAcA,SAAA4E,GACA,IAAAC,EAAA,KAAAC,EAAAtb,KAAAub,GACAC,EAAAvV,KAAAwV,MAAAJ,GACAK,EAAAzV,KAAAwV,MAAAJ,EAAA,OACAD,IACAI,GAAAJ,EAAA,IACAM,GAAAN,EAAA,IACA,IACAI,IACAE,GAAA,MAGA,OAAAF,EAAAE,IAvBA,IAAAH,EAAApU,EAAAoU,gBACAD,EACAC,EAAAI,KACAJ,EAAAK,QACAL,EAAAM,OACAN,EAAAO,MACAP,EAAAQ,WACA,WAAa,WAAAC,MAAAC","file":"asc.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory((function webpackLoadOptionalExternalModule() { try { return require(\"assemblyscript\"); } catch(e) {} }()));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"assemblyscript\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"asc\"] = factory((function webpackLoadOptionalExternalModule() { try { return require(\"assemblyscript\"); } catch(e) {} }()));\n\telse\n\t\troot[\"asc\"] = factory(root[\"assemblyscript\"]);\n})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE__10__) {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 4);\n","exports.nextTick = function nextTick(fn) {\n\tsetTimeout(fn, 0);\n};\n\nexports.platform = exports.arch = \nexports.execPath = exports.title = 'browser';\nexports.pid = 1;\nexports.browser = true;\nexports.env = {};\nexports.argv = [];\n\nexports.binding = function (name) {\n\tthrow new Error('No such module. (Possibly not yet loaded)')\n};\n\n(function () {\n var cwd = '/';\n var path;\n exports.cwd = function () { return cwd };\n exports.chdir = function (dir) {\n if (!path) path = require('path');\n cwd = path.resolve(dir, cwd);\n };\n})();\n\nexports.exit = exports.kill = \nexports.umask = exports.dlopen = \nexports.uptime = exports.memoryUsage = \nexports.uvCounters = function() {};\nexports.features = {};\n","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n// resolves . and .. elements in a path array with directory names there\n// must be no slashes, empty elements, or device names (c:\\) in the array\n// (so also no leading and trailing slashes - it does not distinguish\n// relative and absolute paths)\nfunction normalizeArray(parts, allowAboveRoot) {\n // if the path tries to go above the root, `up` ends up > 0\n var up = 0;\n for (var i = parts.length - 1; i >= 0; i--) {\n var last = parts[i];\n if (last === '.') {\n parts.splice(i, 1);\n } else if (last === '..') {\n parts.splice(i, 1);\n up++;\n } else if (up) {\n parts.splice(i, 1);\n up--;\n }\n }\n\n // if the path is allowed to go above the root, restore leading ..s\n if (allowAboveRoot) {\n for (; up--; up) {\n parts.unshift('..');\n }\n }\n\n return parts;\n}\n\n// Split a filename into [root, dir, basename, ext], unix version\n// 'root' is just a slash, or nothing.\nvar splitPathRe =\n /^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^\\/]+?|)(\\.[^.\\/]*|))(?:[\\/]*)$/;\nvar splitPath = function(filename) {\n return splitPathRe.exec(filename).slice(1);\n};\n\n// path.resolve([from ...], to)\n// posix version\nexports.resolve = function() {\n var resolvedPath = '',\n resolvedAbsolute = false;\n\n for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {\n var path = (i >= 0) ? arguments[i] : process.cwd();\n\n // Skip empty and invalid entries\n if (typeof path !== 'string') {\n throw new TypeError('Arguments to path.resolve must be strings');\n } else if (!path) {\n continue;\n }\n\n resolvedPath = path + '/' + resolvedPath;\n resolvedAbsolute = path.charAt(0) === '/';\n }\n\n // At this point the path should be resolved to a full absolute path, but\n // handle relative paths to be safe (might happen when process.cwd() fails)\n\n // Normalize the path\n resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {\n return !!p;\n }), !resolvedAbsolute).join('/');\n\n return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';\n};\n\n// path.normalize(path)\n// posix version\nexports.normalize = function(path) {\n var isAbsolute = exports.isAbsolute(path),\n trailingSlash = substr(path, -1) === '/';\n\n // Normalize the path\n path = normalizeArray(filter(path.split('/'), function(p) {\n return !!p;\n }), !isAbsolute).join('/');\n\n if (!path && !isAbsolute) {\n path = '.';\n }\n if (path && trailingSlash) {\n path += '/';\n }\n\n return (isAbsolute ? '/' : '') + path;\n};\n\n// posix version\nexports.isAbsolute = function(path) {\n return path.charAt(0) === '/';\n};\n\n// posix version\nexports.join = function() {\n var paths = Array.prototype.slice.call(arguments, 0);\n return exports.normalize(filter(paths, function(p, index) {\n if (typeof p !== 'string') {\n throw new TypeError('Arguments to path.join must be strings');\n }\n return p;\n }).join('/'));\n};\n\n\n// path.relative(from, to)\n// posix version\nexports.relative = function(from, to) {\n from = exports.resolve(from).substr(1);\n to = exports.resolve(to).substr(1);\n\n function trim(arr) {\n var start = 0;\n for (; start < arr.length; start++) {\n if (arr[start] !== '') break;\n }\n\n var end = arr.length - 1;\n for (; end >= 0; end--) {\n if (arr[end] !== '') break;\n }\n\n if (start > end) return [];\n return arr.slice(start, end - start + 1);\n }\n\n var fromParts = trim(from.split('/'));\n var toParts = trim(to.split('/'));\n\n var length = Math.min(fromParts.length, toParts.length);\n var samePartsLength = length;\n for (var i = 0; i < length; i++) {\n if (fromParts[i] !== toParts[i]) {\n samePartsLength = i;\n break;\n }\n }\n\n var outputParts = [];\n for (var i = samePartsLength; i < fromParts.length; i++) {\n outputParts.push('..');\n }\n\n outputParts = outputParts.concat(toParts.slice(samePartsLength));\n\n return outputParts.join('/');\n};\n\nexports.sep = '/';\nexports.delimiter = ':';\n\nexports.dirname = function(path) {\n var result = splitPath(path),\n root = result[0],\n dir = result[1];\n\n if (!root && !dir) {\n // No dirname whatsoever\n return '.';\n }\n\n if (dir) {\n // It has a dirname, strip trailing slash\n dir = dir.substr(0, dir.length - 1);\n }\n\n return root + dir;\n};\n\n\nexports.basename = function(path, ext) {\n var f = splitPath(path)[2];\n // TODO: make this comparison case-insensitive on windows?\n if (ext && f.substr(-1 * ext.length) === ext) {\n f = f.substr(0, f.length - ext.length);\n }\n return f;\n};\n\n\nexports.extname = function(path) {\n return splitPath(path)[3];\n};\n\nfunction filter (xs, f) {\n if (xs.filter) return xs.filter(f);\n var res = [];\n for (var i = 0; i < xs.length; i++) {\n if (f(xs[i], i, xs)) res.push(xs[i]);\n }\n return res;\n}\n\n// String.prototype.substr - negative index don't work in IE8\nvar substr = 'ab'.substr(-1) === 'b'\n ? function (str, start, len) { return str.substr(start, len) }\n : function (str, start, len) {\n if (start < 0) start = str.length + start;\n return str.substr(start, len);\n }\n;\n","var g;\n\n// This works in non-strict mode\ng = (function() {\n\treturn this;\n})();\n\ntry {\n\t// This works if eval is allowed (see CSP)\n\tg = g || Function(\"return this\")() || (1, eval)(\"this\");\n} catch (e) {\n\t// This works if the window reference is available\n\tif (typeof window === \"object\") g = window;\n}\n\n// g can still be undefined, but nothing to do about it...\n// We return undefined, instead of nothing here, so it's\n// easier to handle this case. if(!global) { ...}\n\nmodule.exports = g;\n","/**\r\n * Compiler frontend for node.js\r\n *\r\n * Uses the low-level API exported from src/index.ts so it works with the compiler compiled to\r\n * JavaScript as well as the compiler compiled to WebAssembly (eventually). Runs the sources\r\n * directly through ts-node if distribution files are not present (indicated by a `-dev` version).\r\n *\r\n * Can also be packaged as a bundle suitable for in-browser use with the standard library injected\r\n * in the build step. See dist/asc.js for the bundle and webpack.config.js for building details.\r\n *\r\n * @module cli/asc\r\n */\r\n\r\n// Use \".\" instead of \"/\" as cwd in browsers\r\nif (process.browser) process.cwd = function() { return \".\"; };\r\n\r\nconst fs = require(\"fs\");\r\nconst path = require(\"path\");\r\nconst utf8 = require(\"@protobufjs/utf8\");\r\nconst colorsUtil = require(\"./util/colors\");\r\nconst optionsUtil = require(\"./util/options\");\r\nconst mkdirp = require(\"./util/mkdirp\");\r\nconst EOL = process.platform === \"win32\" ? \"\\r\\n\" : \"\\n\";\r\n\r\n// Emscripten adds an `uncaughtException` listener to Binaryen that results in an additional\r\n// useless code fragment on top of an actual error. suppress this:\r\nif (process.removeAllListeners) process.removeAllListeners(\"uncaughtException\");\r\n\r\n// Use distribution files if present, otherwise run the sources directly\r\nvar assemblyscript, isDev = false;\r\n(() => {\r\n try { // `asc` on the command line\r\n assemblyscript = require(\"../dist/assemblyscript.js\");\r\n } catch (e) {\r\n try { // `asc` on the command line without dist files\r\n require(\"ts-node\").register({ project: path.join(__dirname, \"..\", \"src\", \"tsconfig.json\") });\r\n require(\"../src/glue/js\");\r\n assemblyscript = require(\"../src\");\r\n isDev = true;\r\n } catch (e_ts) {\r\n try { // `require(\"dist/asc.js\")` in explicit browser tests\r\n assemblyscript = eval(\"require('./assemblyscript')\");\r\n } catch (e) {\r\n // combine both errors that lead us here\r\n e.stack = e_ts.stack + \"\\n---\\n\" + e.stack;\r\n throw e;\r\n }\r\n }\r\n }\r\n})();\r\n\r\n/** Whether this is a webpack bundle or not. */\r\nexports.isBundle = typeof BUNDLE_VERSION === \"string\";\r\n\r\n/** Whether asc runs the sources directly or not. */\r\nexports.isDev = isDev;\r\n\r\n/** AssemblyScript version. */\r\nexports.version = exports.isBundle ? BUNDLE_VERSION : require(\"../package.json\").version;\r\n\r\n/** Available CLI options. */\r\nexports.options = require(\"./asc.json\");\r\n\r\n/** Common root used in source maps. */\r\nexports.sourceMapRoot = \"assemblyscript:///\";\r\n\r\n/** Prefix used for library files. */\r\nexports.libraryPrefix = assemblyscript.LIBRARY_PREFIX;\r\n\r\n/** Default Binaryen optimization level. */\r\nexports.defaultOptimizeLevel = 2;\r\n\r\n/** Default Binaryen shrink level. */\r\nexports.defaultShrinkLevel = 1;\r\n\r\n/** Bundled library files. */\r\nexports.libraryFiles = exports.isBundle ? BUNDLE_LIBRARY : (() => { // set up if not a bundle\r\n const libDir = path.join(__dirname, \"..\", \"std\", \"assembly\");\r\n const libFiles = require(\"glob\").sync(\"**/!(*.d).ts\", { cwd: libDir });\r\n const bundled = {};\r\n libFiles.forEach(file => bundled[file.replace(/\\.ts$/, \"\")] = fs.readFileSync(path.join(libDir, file), \"utf8\" ));\r\n return bundled;\r\n})();\r\n\r\n/** Bundled definition files. */\r\nexports.definitionFiles = exports.isBundle ? BUNDLE_DEFINITIONS : (() => { // set up if not a bundle\r\n const stdDir = path.join(__dirname, \"..\", \"std\");\r\n return {\r\n \"assembly\": fs.readFileSync(path.join(stdDir, \"assembly\", \"index.d.ts\"), \"utf8\"),\r\n \"portable\": fs.readFileSync(path.join(stdDir, \"portable\", \"index.d.ts\"), \"utf8\")\r\n };\r\n})();\r\n\r\n/** Convenience function that parses and compiles source strings directly. */\r\nexports.compileString = (sources, options) => {\r\n if (typeof sources === \"string\") sources = { \"input.ts\": sources };\r\n const output = Object.create({\r\n stdout: createMemoryStream(),\r\n stderr: createMemoryStream(),\r\n binary: null,\r\n text: null\r\n });\r\n var argv = [\r\n \"--binaryFile\", \"binary\",\r\n \"--textFile\", \"text\",\r\n ];\r\n Object.keys(options || {}).forEach(key => {\r\n var val = options[key];\r\n if (Array.isArray(val)) val.forEach(val => argv.push(\"--\" + key, String(val)));\r\n else argv.push(\"--\" + key, String(val));\r\n });\r\n exports.main(argv.concat(Object.keys(sources)), {\r\n stdout: output.stdout,\r\n stderr: output.stderr,\r\n readFile: name => sources.hasOwnProperty(name) ? sources[name] : null,\r\n writeFile: (name, contents) => output[name] = contents,\r\n listFiles: () => []\r\n });\r\n return output;\r\n}\r\n\r\n/** Runs the command line utility using the specified arguments array. */\r\nexports.main = function main(argv, options, callback) {\r\n if (typeof options === \"function\") {\r\n callback = options;\r\n options = {};\r\n } else if (!options) {\r\n options = {};\r\n }\r\n\r\n const stdout = options.stdout || process.stdout;\r\n const stderr = options.stderr || process.stderr;\r\n const readFile = options.readFile || readFileNode;\r\n const writeFile = options.writeFile || writeFileNode;\r\n const listFiles = options.listFiles || listFilesNode;\r\n const stats = options.stats || createStats();\r\n\r\n // Output must be specified if not present in the environment\r\n if (!stdout) throw Error(\"'options.stdout' must be specified\");\r\n if (!stderr) throw Error(\"'options.stderr' must be specified\");\r\n\r\n const opts = optionsUtil.parse(argv, exports.options);\r\n const args = opts.options;\r\n argv = opts.arguments;\r\n if (args.noColors) {\r\n colorsUtil.stdout.supported =\r\n colorsUtil.stderr.supported = false;\r\n } else {\r\n colorsUtil.stdout = colorsUtil.from(stdout);\r\n colorsUtil.stderr = colorsUtil.from(stderr);\r\n }\r\n\r\n // Check for unknown arguments\r\n if (opts.unknown.length) {\r\n opts.unknown.forEach(arg => {\r\n stderr.write(colorsUtil.stderr.yellow(\"WARN: \") + \"Unknown option '\" + arg + \"'\" + EOL);\r\n });\r\n }\r\n\r\n // Check for trailing arguments\r\n if (opts.trailing.length) {\r\n stderr.write(colorsUtil.stderr.yellow(\"WARN: \") + \"Unsupported trailing arguments: \" + opts.trailing.join(\" \") + EOL);\r\n }\r\n\r\n // Use default callback if none is provided\r\n if (!callback) callback = function defaultCallback(err) {\r\n var code = 0;\r\n if (err) {\r\n stderr.write(colorsUtil.stderr.red(\"ERROR: \") + err.stack.replace(/^ERROR: /i, \"\") + EOL);\r\n code = 1;\r\n }\r\n return code;\r\n };\r\n\r\n // Just print the version if requested\r\n if (args.version) {\r\n stdout.write(\"Version \" + exports.version + (isDev ? \"-dev\" : \"\") + EOL);\r\n return callback(null);\r\n }\r\n // Print the help message if requested or no source files are provided\r\n if (args.help || !argv.length) {\r\n var out = args.help ? stdout : stderr;\r\n var color = args.help ? colorsUtil.stdout : colorsUtil.stderr;\r\n out.write([\r\n color.white(\"SYNTAX\"),\r\n \" \" + color.cyan(\"asc\") + \" [entryFile ...] [options]\",\r\n \"\",\r\n color.white(\"EXAMPLES\"),\r\n \" \" + color.cyan(\"asc\") + \" hello.ts\",\r\n \" \" + color.cyan(\"asc\") + \" hello.ts -b hello.wasm -t hello.wat\",\r\n \" \" + color.cyan(\"asc\") + \" hello1.ts hello2.ts -b -O > hello.wasm\",\r\n \"\",\r\n color.white(\"OPTIONS\"),\r\n ].concat(\r\n optionsUtil.help(exports.options, 24, EOL)\r\n ).join(EOL) + EOL);\r\n return callback(null);\r\n }\r\n\r\n // I/O must be specified if not present in the environment\r\n if (!fs.readFileSync) {\r\n if (readFile === readFileNode) throw Error(\"'options.readFile' must be specified\");\r\n if (writeFile === writeFileNode) throw Error(\"'options.writeFile' must be specified\");\r\n if (listFiles === listFilesNode) throw Error(\"'options.listFiles' must be specified\");\r\n }\r\n\r\n // Set up base directory\r\n const baseDir = args.baseDir ? path.resolve(args.baseDir) : \".\";\r\n\r\n // Set up transforms\r\n const transforms = [];\r\n if (args.transform) {\r\n args.transform.forEach(transform =>\r\n transforms.push(\r\n require(\r\n path.isAbsolute(transform = transform.trim())\r\n ? transform\r\n : path.join(process.cwd(), transform)\r\n )\r\n )\r\n );\r\n }\r\n function applyTransform(name, ...args) {\r\n transforms.forEach(transform => {\r\n if (typeof transform[name] === \"function\") transform[name](...args);\r\n });\r\n }\r\n\r\n // Begin parsing\r\n var parser = null;\r\n\r\n // Include library files\r\n if (!args.noLib) {\r\n Object.keys(exports.libraryFiles).forEach(libPath => {\r\n if (libPath.indexOf(\"/\") >= 0) return; // in sub-directory: imported on demand\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n parser = assemblyscript.parseFile(\r\n exports.libraryFiles[libPath],\r\n exports.libraryPrefix + libPath + \".ts\",\r\n false,\r\n parser\r\n );\r\n });\r\n });\r\n } else { // always include builtins\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n parser = assemblyscript.parseFile(\r\n exports.libraryFiles[\"builtins\"],\r\n exports.libraryPrefix + \"builtins.ts\",\r\n false,\r\n parser\r\n );\r\n });\r\n }\r\n const customLibDirs = [];\r\n if (args.lib) {\r\n let lib = args.lib;\r\n if (typeof lib === \"string\") lib = lib.split(\",\");\r\n Array.prototype.push.apply(customLibDirs, lib.map(lib => lib.trim()));\r\n for (let i = 0, k = customLibDirs.length; i < k; ++i) { // custom\r\n let libDir = customLibDirs[i];\r\n let libFiles;\r\n if (libDir.endsWith(\".ts\")) {\r\n libFiles = [ path.basename(libDir) ];\r\n libDir = path.dirname(libDir);\r\n } else {\r\n libFiles = listFiles(libDir);\r\n }\r\n for (let j = 0, l = libFiles.length; j < l; ++j) {\r\n let libPath = libFiles[j];\r\n let libText = readFile(path.join(libDir, libPath));\r\n if (libText === null) return callback(Error(\"Library file '\" + libPath + \"' not found.\"));\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n parser = assemblyscript.parseFile(\r\n libText,\r\n exports.libraryPrefix + libPath,\r\n false,\r\n parser\r\n );\r\n });\r\n }\r\n }\r\n }\r\n\r\n // Include entry files\r\n for (let i = 0, k = argv.length; i < k; ++i) {\r\n const filename = argv[i];\r\n\r\n let sourcePath = String(filename).replace(/\\\\/g, \"/\").replace(/(\\.ts|\\/)$/, \"\");\r\n\r\n // Try entryPath.ts, then entryPath/index.ts\r\n let sourceText = readFile(path.join(baseDir, sourcePath) + \".ts\");\r\n if (sourceText === null) {\r\n sourceText = readFile(path.join(baseDir, sourcePath, \"index.ts\"));\r\n if (sourceText === null) {\r\n return callback(Error(\"Entry file '\" + sourcePath + \".ts' not found.\"));\r\n } else {\r\n sourcePath += \"/index.ts\";\r\n }\r\n } else {\r\n sourcePath += \".ts\";\r\n }\r\n\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n parser = assemblyscript.parseFile(sourceText, sourcePath, true, parser);\r\n });\r\n\r\n // Process backlog\r\n while ((sourcePath = parser.nextFile()) != null) {\r\n let found = false;\r\n\r\n // Load library file if explicitly requested\r\n if (sourcePath.startsWith(exports.libraryPrefix)) {\r\n const plainName = sourcePath.substring(exports.libraryPrefix.length);\r\n const indexName = sourcePath.substring(exports.libraryPrefix.length) + \"/index\";\r\n if (exports.libraryFiles.hasOwnProperty(plainName)) {\r\n sourceText = exports.libraryFiles[plainName];\r\n sourcePath = exports.libraryPrefix + plainName + \".ts\";\r\n } else if (exports.libraryFiles.hasOwnProperty(indexName)) {\r\n sourceText = exports.libraryFiles[indexName];\r\n sourcePath = exports.libraryPrefix + indexName + \".ts\";\r\n } else {\r\n for (let i = 0, k = customLibDirs.length; i < k; ++i) {\r\n const dir = customLibDirs[i];\r\n sourceText = readFile(path.join(dir, plainName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = exports.libraryPrefix + plainName + \".ts\";\r\n break;\r\n } else {\r\n sourceText = readFile(path.join(dir, indexName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = exports.libraryPrefix + indexName + \".ts\";\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Otherwise try nextFile.ts, nextFile/index.ts, ~lib/nextFile.ts, ~lib/nextFile/index.ts\r\n } else {\r\n const plainName = sourcePath;\r\n const indexName = sourcePath + \"/index\";\r\n sourceText = readFile(path.join(baseDir, plainName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = plainName + \".ts\";\r\n } else {\r\n sourceText = readFile(path.join(baseDir, indexName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = indexName + \".ts\";\r\n } else if (!plainName.startsWith(\".\")) {\r\n if (exports.libraryFiles.hasOwnProperty(plainName)) {\r\n sourceText = exports.libraryFiles[plainName];\r\n sourcePath = exports.libraryPrefix + plainName + \".ts\";\r\n } else if (exports.libraryFiles.hasOwnProperty(indexName)) {\r\n sourceText = exports.libraryFiles[indexName];\r\n sourcePath = exports.libraryPrefix + indexName + \".ts\";\r\n } else {\r\n for (let i = 0, k = customLibDirs.length; i < k; ++i) {\r\n const dir = customLibDirs[i];\r\n sourceText = readFile(path.join(dir, plainName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = exports.libraryPrefix + plainName + \".ts\";\r\n break;\r\n } else {\r\n sourceText = readFile(path.join(dir, indexName + \".ts\"));\r\n if (sourceText !== null) {\r\n sourcePath = exports.libraryPrefix + indexName + \".ts\";\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n if (sourceText == null) {\r\n return callback(Error(\"Import file '\" + sourcePath + \".ts' not found.\"));\r\n }\r\n stats.parseCount++;\r\n stats.parseTime += measure(() => {\r\n assemblyscript.parseFile(sourceText, sourcePath, false, parser);\r\n });\r\n }\r\n if (checkDiagnostics(parser, stderr)) {\r\n return callback(Error(\"Parse error\"));\r\n }\r\n }\r\n\r\n applyTransform(\"afterParse\", parser);\r\n\r\n // Finish parsing\r\n const program = assemblyscript.finishParsing(parser);\r\n\r\n // Set up optimization levels\r\n var optimizeLevel = 0;\r\n var shrinkLevel = 0;\r\n if (args.optimize) {\r\n optimizeLevel = exports.defaultOptimizeLevel;\r\n shrinkLevel = exports.defaultShrinkLevel;\r\n }\r\n if (typeof args.optimizeLevel === \"number\") {\r\n optimizeLevel = args.optimizeLevel;\r\n }\r\n if (typeof args.shrinkLevel === \"number\") {\r\n shrinkLevel = args.shrinkLevel;\r\n }\r\n optimizeLevel = Math.min(Math.max(optimizeLevel, 0), 3);\r\n shrinkLevel = Math.min(Math.max(shrinkLevel, 0), 2);\r\n\r\n // Begin compilation\r\n const compilerOptions = assemblyscript.createOptions();\r\n assemblyscript.setTarget(compilerOptions, 0);\r\n assemblyscript.setNoTreeShaking(compilerOptions, args.noTreeShaking);\r\n assemblyscript.setNoAssert(compilerOptions, args.noAssert);\r\n assemblyscript.setImportMemory(compilerOptions, args.importMemory);\r\n assemblyscript.setImportTable(compilerOptions, args.importTable);\r\n assemblyscript.setMemoryBase(compilerOptions, args.memoryBase >>> 0);\r\n assemblyscript.setSourceMap(compilerOptions, args.sourceMap != null);\r\n assemblyscript.setOptimizeLevelHints(compilerOptions, optimizeLevel, shrinkLevel);\r\n\r\n if (!args.noLib) {\r\n // Initialize default aliases\r\n assemblyscript.setGlobalAlias(compilerOptions, \"Math\", \"NativeMath\");\r\n assemblyscript.setGlobalAlias(compilerOptions, \"Mathf\", \"NativeMathf\");\r\n assemblyscript.setGlobalAlias(compilerOptions, \"abort\", \"~lib/env/abort\");\r\n assemblyscript.setGlobalAlias(compilerOptions, \"trace\", \"~lib/env/trace\");\r\n }\r\n\r\n // Add or override aliases if specified\r\n if (args.use) {\r\n let aliases = args.use;\r\n for (let i = 0, k = aliases.length; i < k; ++i) {\r\n let part = aliases[i];\r\n let p = part.indexOf(\"=\");\r\n if (p < 0) return callback(Error(\"Global alias '\" + part + \"' is invalid.\"));\r\n let name = part.substring(0, p).trim();\r\n let alias = part.substring(p + 1).trim();\r\n if (!name.length) return callback(Error(\"Global alias '\" + part + \"' is invalid.\"));\r\n assemblyscript.setGlobalAlias(compilerOptions, name, alias);\r\n }\r\n }\r\n\r\n // Enable additional features if specified\r\n var features = args.enable;\r\n if (features != null) {\r\n if (typeof features === \"string\") features = features.split(\",\");\r\n for (let i = 0, k = features.length; i < k; ++i) {\r\n let name = features[i].trim();\r\n let flag = assemblyscript[\"FEATURE_\" + name.replace(/\\-/g, \"_\").toUpperCase()];\r\n if (!flag) return callback(Error(\"Feature '\" + name + \"' is unknown.\"));\r\n assemblyscript.enableFeature(compilerOptions, flag);\r\n }\r\n }\r\n\r\n var module;\r\n stats.compileCount++;\r\n (() => {\r\n try {\r\n stats.compileTime += measure(() => {\r\n module = assemblyscript.compileProgram(program, compilerOptions);\r\n });\r\n } catch (e) {\r\n return callback(e);\r\n }\r\n })();\r\n if (checkDiagnostics(parser, stderr)) {\r\n if (module) module.dispose();\r\n return callback(Error(\"Compile error\"));\r\n }\r\n\r\n // Validate the module if requested\r\n if (args.validate) {\r\n stats.validateCount++;\r\n stats.validateTime += measure(() => {\r\n if (!module.validate()) {\r\n module.dispose();\r\n return callback(Error(\"Validate error\"));\r\n }\r\n });\r\n }\r\n\r\n // Set Binaryen-specific options\r\n if (args.trapMode === \"clamp\") {\r\n stats.optimizeCount++;\r\n stats.optimizeTime += measure(() => {\r\n module.runPasses([ \"trap-mode-clamp\" ]);\r\n });\r\n } else if (args.trapMode === \"js\") {\r\n stats.optimizeCount++;\r\n stats.optimizeTime += measure(() => {\r\n module.runPasses([ \"trap-mode-js\" ]);\r\n });\r\n } else if (args.trapMode !== \"allow\") {\r\n module.dispose();\r\n return callback(Error(\"Unsupported trap mode\"));\r\n }\r\n\r\n // Implicitly run costly non-LLVM optimizations on -O3 or -Oz\r\n // see: https://github.com/WebAssembly/binaryen/pull/1596\r\n if (optimizeLevel >= 3 || shrinkLevel >= 2) optimizeLevel = 4;\r\n\r\n module.setOptimizeLevel(optimizeLevel);\r\n module.setShrinkLevel(shrinkLevel);\r\n module.setDebugInfo(args.debug);\r\n\r\n var runPasses = [];\r\n if (args.runPasses) {\r\n if (typeof args.runPasses === \"string\") {\r\n args.runPasses = args.runPasses.split(\",\");\r\n }\r\n if (args.runPasses.length) {\r\n args.runPasses.forEach(pass => {\r\n if (runPasses.indexOf(pass) < 0)\r\n runPasses.push(pass);\r\n });\r\n }\r\n }\r\n\r\n // Optimize the module if requested\r\n if (optimizeLevel > 0 || shrinkLevel > 0) {\r\n stats.optimizeCount++;\r\n stats.optimizeTime += measure(() => {\r\n module.optimize();\r\n });\r\n }\r\n\r\n // Run additional passes if requested\r\n if (runPasses.length) {\r\n stats.optimizeCount++;\r\n stats.optimizeTime += measure(() => {\r\n module.runPasses(runPasses.map(pass => pass.trim()));\r\n });\r\n }\r\n\r\n // Prepare output\r\n if (!args.noEmit) {\r\n let hasStdout = false;\r\n let hasOutput = false;\r\n\r\n if (args.outFile != null) {\r\n if (/\\.was?t$/.test(args.outFile) && args.textFile == null) {\r\n args.textFile = args.outFile;\r\n } else if (/\\.js$/.test(args.outFile) && args.asmjsFile == null) {\r\n args.asmjsFile = args.outFile;\r\n } else if (args.binaryFile == null) {\r\n args.binaryFile = args.outFile;\r\n }\r\n }\r\n\r\n // Write binary\r\n if (args.binaryFile != null) {\r\n let sourceMapURL = args.sourceMap != null\r\n ? args.sourceMap.length\r\n ? args.sourceMap\r\n : path.basename(args.binaryFile) + \".map\"\r\n : null;\r\n\r\n let wasm;\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n wasm = module.toBinary(sourceMapURL)\r\n });\r\n\r\n if (args.binaryFile.length) {\r\n writeFile(path.join(baseDir, args.binaryFile), wasm.output);\r\n } else {\r\n writeStdout(wasm.output);\r\n hasStdout = true;\r\n }\r\n hasOutput = true;\r\n\r\n // Post-process source map\r\n if (wasm.sourceMap != null) {\r\n if (args.binaryFile.length) {\r\n let sourceMap = JSON.parse(wasm.sourceMap);\r\n sourceMap.sourceRoot = exports.sourceMapRoot;\r\n sourceMap.sources.forEach((name, index) => {\r\n let text = null;\r\n if (name.startsWith(exports.libraryPrefix)) {\r\n let stdName = name.substring(exports.libraryPrefix.length).replace(/\\.ts$/, \"\");\r\n if (exports.libraryFiles.hasOwnProperty(stdName)) {\r\n text = exports.libraryFiles[stdName];\r\n } else {\r\n for (let i = 0, k = customLibDirs.length; i < k; ++i) {\r\n text = readFile(path.join(\r\n customLibDirs[i],\r\n name.substring(exports.libraryPrefix.length))\r\n );\r\n if (text !== null) break;\r\n }\r\n }\r\n } else {\r\n text = readFile(path.join(baseDir, name));\r\n }\r\n if (text === null) {\r\n return callback(Error(\"Source file '\" + name + \"' not found.\"));\r\n }\r\n if (!sourceMap.sourceContents) sourceMap.sourceContents = [];\r\n sourceMap.sourceContents[index] = text;\r\n });\r\n writeFile(path.join(\r\n baseDir,\r\n path.dirname(args.binaryFile),\r\n path.basename(sourceMapURL)\r\n ), JSON.stringify(sourceMap));\r\n } else {\r\n stderr.write(\"Skipped source map (stdout already occupied)\" + EOL);\r\n }\r\n }\r\n }\r\n\r\n // Write asm.js\r\n if (args.asmjsFile != null) {\r\n let asm;\r\n if (args.asmjsFile.length) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n asm = module.toAsmjs();\r\n });\r\n writeFile(path.join(baseDir, args.asmjsFile), asm);\r\n } else if (!hasStdout) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n asm = module.toAsmjs();\r\n });\r\n writeStdout(asm);\r\n hasStdout = true;\r\n }\r\n hasOutput = true;\r\n }\r\n\r\n // Write WebIDL\r\n if (args.idlFile != null) {\r\n let idl;\r\n if (args.idlFile.length) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n idl = assemblyscript.buildIDL(program);\r\n });\r\n writeFile(path.join(baseDir, args.idlFile), idl);\r\n } else if (!hasStdout) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n idl = assemblyscript.buildIDL(program);\r\n });\r\n writeStdout(idl);\r\n hasStdout = true;\r\n }\r\n hasOutput = true;\r\n }\r\n\r\n // Write TypeScript definition\r\n if (args.tsdFile != null) {\r\n let tsd;\r\n if (args.tsdFile.length) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n tsd = assemblyscript.buildTSD(program);\r\n });\r\n writeFile(path.join(baseDir, args.tsdFile), tsd);\r\n } else if (!hasStdout) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n tsd = assemblyscript.buildTSD(program);\r\n });\r\n writeStdout(tsd);\r\n hasStdout = true;\r\n }\r\n hasOutput = true;\r\n }\r\n\r\n // Write text (must be last)\r\n if (args.textFile != null || !hasOutput) {\r\n let wat;\r\n if (args.textFile && args.textFile.length) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n wat = module.toText();\r\n });\r\n writeFile(path.join(baseDir, args.textFile), wat);\r\n } else if (!hasStdout) {\r\n stats.emitCount++;\r\n stats.emitTime += measure(() => {\r\n wat = module.toText()\r\n });\r\n writeStdout(wat);\r\n }\r\n }\r\n }\r\n\r\n module.dispose();\r\n if (args.measure) {\r\n printStats(stats, stderr);\r\n }\r\n return callback(null);\r\n\r\n function readFileNode(filename) {\r\n try {\r\n let text;\r\n stats.readCount++;\r\n stats.readTime += measure(() => {\r\n text = fs.readFileSync(filename, { encoding: \"utf8\" });\r\n });\r\n return text;\r\n } catch (e) {\r\n return null;\r\n }\r\n }\r\n\r\n function writeFileNode(filename, contents) {\r\n try {\r\n stats.writeCount++;\r\n stats.writeTime += measure(() => {\r\n mkdirp(path.dirname(filename));\r\n if (typeof contents === \"string\") {\r\n fs.writeFileSync(filename, contents, { encoding: \"utf8\" } );\r\n } else {\r\n fs.writeFileSync(filename, contents);\r\n }\r\n });\r\n return true;\r\n } catch (e) {\r\n return false;\r\n }\r\n }\r\n\r\n function listFilesNode(dirname) {\r\n var files;\r\n try {\r\n stats.readTime += measure(() => {\r\n files = fs.readdirSync(dirname).filter(file => /^(?!.*\\.d\\.ts$).*\\.ts$/.test(file));\r\n });\r\n return files;\r\n } catch (e) {\r\n return [];\r\n }\r\n }\r\n\r\n function writeStdout(contents) {\r\n if (!writeStdout.used) {\r\n stats.writeCount++;\r\n writeStdout.used = true;\r\n }\r\n stats.writeTime += measure(() => {\r\n if (typeof contents === \"string\") {\r\n stdout.write(contents, { encoding: \"utf8\" });\r\n } else {\r\n stdout.write(contents);\r\n }\r\n });\r\n }\r\n}\r\n\r\nvar argumentSubstitutions = {\r\n \"-O\" : [ \"--optimize\" ],\r\n \"-Os\" : [ \"--optimize\", \"--shrinkLevel\", \"1\" ],\r\n \"-Oz\" : [ \"--optimize\", \"--shrinkLevel\", \"2\" ],\r\n \"-O0\" : [ \"--optimizeLevel\", \"0\", \"--shrinkLevel\", \"0\" ],\r\n \"-O0s\": [ \"--optimizeLevel\", \"0\", \"--shrinkLevel\", \"1\" ],\r\n \"-O0z\": [ \"--optimizeLevel\", \"0\", \"--shrinkLevel\", \"2\" ],\r\n \"-O1\" : [ \"--optimizeLevel\", \"1\", \"--shrinkLevel\", \"0\" ],\r\n \"-O1s\": [ \"--optimizeLevel\", \"1\", \"--shrinkLevel\", \"1\" ],\r\n \"-O1z\": [ \"--optimizeLevel\", \"1\", \"--shrinkLevel\", \"2\" ],\r\n \"-O2\" : [ \"--optimizeLevel\", \"2\", \"--shrinkLevel\", \"0\" ],\r\n \"-O2s\": [ \"--optimizeLevel\", \"2\", \"--shrinkLevel\", \"1\" ],\r\n \"-O2z\": [ \"--optimizeLevel\", \"2\", \"--shrinkLevel\", \"2\" ],\r\n \"-O3\" : [ \"--optimizeLevel\", \"3\", \"--shrinkLevel\", \"0\" ],\r\n \"-O3s\": [ \"--optimizeLevel\", \"3\", \"--shrinkLevel\", \"1\" ],\r\n \"-O3z\": [ \"--optimizeLevel\", \"3\", \"--shrinkLevel\", \"2\" ],\r\n};\r\n\r\n/** Checks diagnostics emitted so far for errors. */\r\nfunction checkDiagnostics(emitter, stderr) {\r\n var diagnostic;\r\n var hasErrors = false;\r\n while ((diagnostic = assemblyscript.nextDiagnostic(emitter)) != null) {\r\n if (stderr) {\r\n stderr.write(\r\n assemblyscript.formatDiagnostic(diagnostic, stderr.isTTY, true) +\r\n EOL + EOL\r\n );\r\n }\r\n if (assemblyscript.isError(diagnostic)) hasErrors = true;\r\n }\r\n return hasErrors;\r\n}\r\n\r\nexports.checkDiagnostics = checkDiagnostics;\r\n\r\n/** Creates an empty set of stats. */\r\nfunction createStats() {\r\n return {\r\n readTime: 0,\r\n readCount: 0,\r\n writeTime: 0,\r\n writeCount: 0,\r\n parseTime: 0,\r\n parseCount: 0,\r\n compileTime: 0,\r\n compileCount: 0,\r\n emitTime: 0,\r\n emitCount: 0,\r\n validateTime: 0,\r\n validateCount: 0,\r\n optimizeTime: 0,\r\n optimizeCount: 0\r\n };\r\n}\r\n\r\nexports.createStats = createStats;\r\n\r\nif (!process.hrtime) process.hrtime = require(\"browser-process-hrtime\");\r\n\r\n/** Measures the execution time of the specified function. */\r\nfunction measure(fn) {\r\n const start = process.hrtime();\r\n fn();\r\n const times = process.hrtime(start);\r\n return times[0] * 1e9 + times[1];\r\n}\r\n\r\nexports.measure = measure;\r\n\r\n/** Formats a high resolution time to a human readable string. */\r\nfunction formatTime(time) {\r\n return time ? (time / 1e6).toFixed(3) + \" ms\" : \"N/A\";\r\n}\r\n\r\nexports.formatTime = formatTime;\r\n\r\n/** Formats and prints out the contents of a set of stats. */\r\nfunction printStats(stats, output) {\r\n function format(time, count) {\r\n return formatTime(time);\r\n }\r\n (output || process.stdout).write([\r\n \"I/O Read : \" + format(stats.readTime, stats.readCount),\r\n \"I/O Write : \" + format(stats.writeTime, stats.writeCount),\r\n \"Parse : \" + format(stats.parseTime, stats.parseCount),\r\n \"Compile : \" + format(stats.compileTime, stats.compileCount),\r\n \"Emit : \" + format(stats.emitTime, stats.emitCount),\r\n \"Validate : \" + format(stats.validateTime, stats.validateCount),\r\n \"Optimize : \" + format(stats.optimizeTime, stats.optimizeCount)\r\n ].join(EOL) + EOL);\r\n}\r\n\r\nexports.printStats = printStats;\r\n\r\nvar allocBuffer = typeof global !== \"undefined\" && global.Buffer\r\n ? global.Buffer.allocUnsafe || function(len) { return new global.Buffer(len); }\r\n : function(len) { return new Uint8Array(len) };\r\n\r\n/** Creates a memory stream that can be used in place of stdout/stderr. */\r\nfunction createMemoryStream(fn) {\r\n var stream = [];\r\n stream.write = function(chunk) {\r\n if (fn) fn(chunk);\r\n if (typeof chunk === \"string\") {\r\n let buffer = allocBuffer(utf8.length(chunk));\r\n utf8.write(chunk, buffer, 0);\r\n chunk = buffer;\r\n }\r\n this.push(chunk);\r\n };\r\n stream.reset = function() {\r\n stream.length = 0;\r\n };\r\n stream.toBuffer = function() {\r\n var offset = 0, i = 0, k = this.length;\r\n while (i < k) offset += this[i++].length;\r\n var buffer = allocBuffer(offset);\r\n offset = i = 0;\r\n while (i < k) {\r\n buffer.set(this[i], offset);\r\n offset += this[i].length;\r\n ++i;\r\n }\r\n return buffer;\r\n };\r\n stream.toString = function() {\r\n var buffer = this.toBuffer();\r\n return utf8.read(buffer, 0, buffer.length);\r\n };\r\n return stream;\r\n}\r\n\r\nexports.createMemoryStream = createMemoryStream;\r\n\r\n/** Compatible TypeScript compiler options for syntax highlighting etc. */\r\nexports.tscOptions = {\r\n alwaysStrict: true,\r\n noImplicitAny: true,\r\n noImplicitReturns: true,\r\n noImplicitThis: true,\r\n noEmitOnError: true,\r\n strictNullChecks: true,\r\n experimentalDecorators: true,\r\n target: \"esnext\",\r\n module: \"commonjs\",\r\n noLib: true,\r\n types: [],\r\n allowJs: false\r\n};\r\n","\"use strict\";\r\n\r\n/**\r\n * A minimal UTF8 implementation for number arrays.\r\n * @memberof util\r\n * @namespace\r\n */\r\nvar utf8 = exports;\r\n\r\n/**\r\n * Calculates the UTF8 byte length of a string.\r\n * @param {string} string String\r\n * @returns {number} Byte length\r\n */\r\nutf8.length = function utf8_length(string) {\r\n var len = 0,\r\n c = 0;\r\n for (var i = 0; i < string.length; ++i) {\r\n c = string.charCodeAt(i);\r\n if (c < 128)\r\n len += 1;\r\n else if (c < 2048)\r\n len += 2;\r\n else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {\r\n ++i;\r\n len += 4;\r\n } else\r\n len += 3;\r\n }\r\n return len;\r\n};\r\n\r\n/**\r\n * Reads UTF8 bytes as a string.\r\n * @param {Uint8Array} buffer Source buffer\r\n * @param {number} start Source start\r\n * @param {number} end Source end\r\n * @returns {string} String read\r\n */\r\nutf8.read = function utf8_read(buffer, start, end) {\r\n var len = end - start;\r\n if (len < 1)\r\n return \"\";\r\n var parts = null,\r\n chunk = [],\r\n i = 0, // char offset\r\n t; // temporary\r\n while (start < end) {\r\n t = buffer[start++];\r\n if (t < 128)\r\n chunk[i++] = t;\r\n else if (t > 191 && t < 224)\r\n chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;\r\n else if (t > 239 && t < 365) {\r\n t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;\r\n chunk[i++] = 0xD800 + (t >> 10);\r\n chunk[i++] = 0xDC00 + (t & 1023);\r\n } else\r\n chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;\r\n if (i > 8191) {\r\n (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));\r\n i = 0;\r\n }\r\n }\r\n if (parts) {\r\n if (i)\r\n parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));\r\n return parts.join(\"\");\r\n }\r\n return String.fromCharCode.apply(String, chunk.slice(0, i));\r\n};\r\n\r\n/**\r\n * Writes a string as UTF8 bytes.\r\n * @param {string} string Source string\r\n * @param {Uint8Array} buffer Destination buffer\r\n * @param {number} offset Destination offset\r\n * @returns {number} Bytes written\r\n */\r\nutf8.write = function utf8_write(string, buffer, offset) {\r\n var start = offset,\r\n c1, // character 1\r\n c2; // character 2\r\n for (var i = 0; i < string.length; ++i) {\r\n c1 = string.charCodeAt(i);\r\n if (c1 < 128) {\r\n buffer[offset++] = c1;\r\n } else if (c1 < 2048) {\r\n buffer[offset++] = c1 >> 6 | 192;\r\n buffer[offset++] = c1 & 63 | 128;\r\n } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {\r\n c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);\r\n ++i;\r\n buffer[offset++] = c1 >> 18 | 240;\r\n buffer[offset++] = c1 >> 12 & 63 | 128;\r\n buffer[offset++] = c1 >> 6 & 63 | 128;\r\n buffer[offset++] = c1 & 63 | 128;\r\n } else {\r\n buffer[offset++] = c1 >> 12 | 224;\r\n buffer[offset++] = c1 >> 6 & 63 | 128;\r\n buffer[offset++] = c1 & 63 | 128;\r\n }\r\n }\r\n return offset - start;\r\n};\r\n","var proc = typeof process !== \"undefined\" && process || {};\r\nvar isCI = proc.env && \"CI\" in proc.env; // doesn't work when bundled because 'process' is a mock\r\n\r\nfunction from(stream, base) {\r\n var colors = base || {};\r\n colors.supported = (stream && !!stream.isTTY) || isCI;\r\n colors.gray = text => colors.supported ? exports.GRAY + text + exports.RESET : text;\r\n colors.red = text => colors.supported ? exports.RED + text + exports.RESET : text;\r\n colors.green = text => colors.supported ? exports.GREEN + text + exports.RESET : text;\r\n colors.yellow = text => colors.supported ? exports.YELLOW + text + exports.RESET : text;\r\n colors.blue = text => colors.supported ? exports.BLUE + text + exports.RESET : text;\r\n colors.magenta = text => colors.supported ? exports.MAGENTA + text + exports.RESET : text;\r\n colors.cyan = text => colors.supported ? exports.CYAN + text + exports.RESET : text;\r\n colors.white = text => colors.supported ? exports.WHITE + text + exports.RESET : text;\r\n return colors;\r\n}\r\n\r\nexports.stdout = from(proc.stdout, exports);\r\nexports.stderr = from(proc.stderr);\r\nexports.from = from;\r\n\r\nexports.GRAY = \"\\u001b[90m\";\r\nexports.RED = \"\\u001b[91m\";\r\nexports.GREEN = \"\\u001b[92m\";\r\nexports.YELLOW = \"\\u001b[93m\";\r\nexports.BLUE = \"\\u001b[94m\";\r\nexports.MAGENTA = \"\\u001b[95m\";\r\nexports.CYAN = \"\\u001b[96m\";\r\nexports.WHITE = \"\\u001b[97m\";\r\nexports.RESET = \"\\u001b[0m\";\r\n","// type | meaning\r\n// -----|---------------\r\n// b | boolean\r\n// i | integer\r\n// f | float\r\n// s | string\r\n// I | integer array\r\n// F | float array\r\n// S | string array\r\n\r\n/** Parses the specified command line arguments according to the given configuration. */\r\nfunction parse(argv, config) {\r\n var options = {};\r\n var unknown = [];\r\n var arguments = [];\r\n var trailing = [];\r\n\r\n // make an alias map and initialize defaults\r\n var aliases = {};\r\n Object.keys(config).forEach(key => {\r\n var option = config[key];\r\n if (option.alias != null) {\r\n if (typeof option.alias === \"string\") aliases[option.alias] = key;\r\n else if (Array.isArray(option.alias)) option.alias.forEach(alias => aliases[alias] = key);\r\n }\r\n if (option.default != null) options[key] = option.default;\r\n });\r\n\r\n // iterate over argv\r\n for (var i = 0, k = (argv = argv.slice()).length; i < k; ++i) {\r\n let arg = argv[i];\r\n if (arg == \"--\") { ++i; break; }\r\n let match = /^(?:(\\-\\w)(?:=(.*))?|(\\-\\-\\w{2,})(?:=(.*))?)$/.exec(arg), option, key;\r\n if (match) {\r\n if (config[arg]) option = config[key = arg]; // exact\r\n else if (match[1] != null) { // alias\r\n option = config[key = aliases[match[1].substring(1)]];\r\n if (option && match[2] != null) argv[i--] = match[2];\r\n } else if (match[3] != null) { // full\r\n option = config[key = match[3].substring(2)];\r\n if (option && match[4] != null) argv[i--] = match[4];\r\n }\r\n } else {\r\n if (arg.charCodeAt(0) == 45) option = config[key = arg]; // exact\r\n else { arguments.push(arg); continue; } // argument\r\n }\r\n if (option) {\r\n if (option.type == null || option.type === \"b\") options[key] = true; // flag\r\n else {\r\n if (i + 1 < argv.length && argv[i + 1].charCodeAt(0) != 45) { // present\r\n switch (option.type) {\r\n case \"i\": options[key] = parseInt(argv[++i], 10); break;\r\n case \"I\": options[key] = (options[key] || []).concat(parseInt(argv[++i], 10)); break;\r\n case \"f\": options[key] = parseFloat(argv[++i]); break;\r\n case \"F\": options[key] = (options[key] || []).concat(parseFloat(argv[++i])); break;\r\n case \"s\": options[key] = String(argv[++i]); break;\r\n case \"S\": options[key] = (options[key] || []).concat(argv[++i].split(\",\")); break;\r\n default: unknown.push(arg); --i;\r\n }\r\n } else { // omitted\r\n switch (option.type) {\r\n case \"i\":\r\n case \"f\": options[key] = option.default || 0; break;\r\n case \"s\": options[key] = option.default || \"\"; break;\r\n case \"I\":\r\n case \"F\":\r\n case \"S\": options[key] = options.default || []; break;\r\n default: unknown.push(arg);\r\n }\r\n }\r\n }\r\n if (option.value) Object.keys(option.value).forEach(k => options[k] = option.value[k]);\r\n } else unknown.push(arg);\r\n }\r\n while (i < k) trailing.push(argv[i++]); // trailing\r\n\r\n return { options, unknown, arguments, trailing };\r\n}\r\n\r\nexports.parse = parse;\r\n\r\n/** Generates the help text for the specified configuration. */\r\nfunction help(config, options) {\r\n if (!options) options = {};\r\n var indent = options.indent || 2;\r\n var padding = options.padding || 24;\r\n var eol = options.eol || \"\\n\";\r\n var sb = [];\r\n Object.keys(config).forEach(key => {\r\n var option = config[key];\r\n if (option.description == null) return;\r\n var text = \"\";\r\n while (text.length < indent) text += \" \";\r\n text += \"--\" + key;\r\n if (option.alias) text += \", -\" + option.alias;\r\n while (text.length < padding) text += \" \";\r\n if (Array.isArray(option.description)) {\r\n sb.push(text + option.description[0] + option.description.slice(1).map(line => {\r\n for (let i = 0; i < padding; ++i) line = \" \" + line;\r\n return eol + line;\r\n }).join(\"\"));\r\n } else sb.push(text + option.description);\r\n });\r\n return sb.join(eol);\r\n}\r\n\r\nexports.help = help;\r\n","/*\r\nCopyright 2010 James Halliday (mail@substack.net)\r\n\r\nThis project is free software released under the MIT/X11 license:\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in\r\nall copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\nTHE SOFTWARE.\r\n*/\r\n\r\nvar path = require(\"path\");\r\nvar fs = require(\"fs\");\r\nvar _0777 = parseInt(\"0777\", 8);\r\n\r\nmodule.exports = function mkdirp(p, opts, made) {\r\n if (!opts || typeof opts !== \"object\") {\r\n opts = { mode: opts };\r\n }\r\n var mode = opts.mode;\r\n if (mode === undefined) {\r\n mode = _0777 & (~process.umask());\r\n }\r\n if (!made) made = null;\r\n p = path.resolve(p);\r\n try {\r\n fs.mkdirSync(p, mode);\r\n made = made || p;\r\n } catch (err0) {\r\n switch (err0.code) {\r\n case \"ENOENT\":\r\n made = mkdirp(path.dirname(p), opts, made);\r\n mkdirp(p, opts, made);\r\n break;\r\n default:\r\n var stat;\r\n try {\r\n stat = fs.statSync(p);\r\n } catch (err1) {\r\n throw err0;\r\n }\r\n if (!stat.isDirectory()) throw err0;\r\n break;\r\n }\r\n }\r\n return made;\r\n};\r\n","if(typeof __WEBPACK_EXTERNAL_MODULE__10__ === 'undefined') {var e = new Error(\"Cannot find module 'assemblyscript'\"); e.code = 'MODULE_NOT_FOUND'; throw e;}\nmodule.exports = __WEBPACK_EXTERNAL_MODULE__10__;","function webpackEmptyContext(req) {\n\tvar e = new Error(\"Cannot find module '\" + req + \"'\");\n\te.code = 'MODULE_NOT_FOUND';\n\tthrow e;\n}\nwebpackEmptyContext.keys = function() { return []; };\nwebpackEmptyContext.resolve = webpackEmptyContext;\nmodule.exports = webpackEmptyContext;\nwebpackEmptyContext.id = 12;","module.exports = process.hrtime || hrtime\n\n// polyfil for window.performance.now\nvar performance = global.performance || {}\nvar performanceNow =\n performance.now ||\n performance.mozNow ||\n performance.msNow ||\n performance.oNow ||\n performance.webkitNow ||\n function(){ return (new Date()).getTime() }\n\n// generate timestamp or delta\n// see http://nodejs.org/api/process.html#process_process_hrtime\nfunction hrtime(previousTimestamp){\n var clocktime = performanceNow.call(performance)*1e-3\n var seconds = Math.floor(clocktime)\n var nanoseconds = Math.floor((clocktime%1)*1e9)\n if (previousTimestamp) {\n seconds = seconds - previousTimestamp[0]\n nanoseconds = nanoseconds - previousTimestamp[1]\n if (nanoseconds<0) {\n seconds--\n nanoseconds += 1e9\n }\n }\n return [seconds,nanoseconds]\n}"],"sourceRoot":""} \ No newline at end of file diff --git a/examples/game-of-life/package.json b/examples/game-of-life/package.json index bffe8a4d..3089b6af 100644 --- a/examples/game-of-life/package.json +++ b/examples/game-of-life/package.json @@ -3,8 +3,8 @@ "version": "1.0.0", "private": true, "scripts": { - "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --importMemory --sourceMap --validate --measure", - "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --use Math=JSMath -O3 --importMemory --sourceMap --validate --noDebug --measure", + "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --importMemory --sourceMap --debug --validate --measure", + "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --use Math=JSMath -O3 --importMemory --sourceMap --validate --measure", "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", "server": "http-server . -o -c-1" }, diff --git a/examples/i64-polyfill/package.json b/examples/i64-polyfill/package.json index c9f4611e..af03821f 100644 --- a/examples/i64-polyfill/package.json +++ b/examples/i64-polyfill/package.json @@ -17,7 +17,7 @@ }, "scripts": { "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", - "asbuild:untouched": "asc assembly/i64.ts -t build/untouched.wat -b build/untouched.wasm --validate --sourceMap --measure", + "asbuild:untouched": "asc assembly/i64.ts -t build/untouched.wat -b build/untouched.wasm --validate --sourceMap --debug --measure", "asbuild:optimized": "asc -O assembly/i64.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --validate --sourceMap --measure", "test": "node tests" }, diff --git a/examples/mandelbrot/package.json b/examples/mandelbrot/package.json index 73467e98..8d583687 100644 --- a/examples/mandelbrot/package.json +++ b/examples/mandelbrot/package.json @@ -3,8 +3,8 @@ "version": "1.0.0", "private": true, "scripts": { - "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --importMemory --sourceMap --validate --measure", - "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --use Math=JSMath -O3 --importMemory --sourceMap --validate --noDebug --measure", + "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --use Math=JSMath --importMemory --sourceMap --debug --validate --measure", + "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -d build/optimized.d.ts --use Math=JSMath -O3 --importMemory --sourceMap --validate --measure", "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", "server": "http-server . -o -c-1" }, diff --git a/examples/n-body/package.json b/examples/n-body/package.json index b52d65c9..dba6042e 100644 --- a/examples/n-body/package.json +++ b/examples/n-body/package.json @@ -3,9 +3,9 @@ "version": "1.0.0", "private": true, "scripts": { - "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --importMemory", - "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --validate --noDebug --noAssert --importMemory", - "asbuild:asmjs": "asc assembly/index.ts -a build/index.asm.js -O3 --validate --noDebug --noAssert", + "asbuild:untouched": "asc assembly/index.ts -b build/untouched.wasm -t build/untouched.wat --sourceMap --debug --validate --importMemory", + "asbuild:optimized": "asc assembly/index.ts -b build/optimized.wasm -t build/optimized.wat -O3 --validate --noAssert --importMemory", + "asbuild:asmjs": "asc assembly/index.ts -a build/index.asm.js -O3 --validate --noAssert", "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized && npm run asbuild:asmjs", "tsbuild": "tsc -p assembly -t ES2017 -m commonjs --outDir build", "build": "npm run asbuild && npm run tsbuild", diff --git a/examples/pson/package.json b/examples/pson/package.json index 04eff24f..e8ab1ade 100644 --- a/examples/pson/package.json +++ b/examples/pson/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "asbuild": "npm run asbuild:untouched && npm run asbuild:optimized", - "asbuild:untouched": "asc assembly/pson.ts -b build/untouched.wasm -t build/untouched.wat --validate --sourceMap --measure", + "asbuild:untouched": "asc assembly/pson.ts -b build/untouched.wasm -t build/untouched.wat --validate --sourceMap --debug --measure", "asbuild:optimized": "asc -O assembly/pson.ts -b build/optimized.wasm -t build/optimized.wat --validate --sourceMap --measure", "test": "node tests" }, diff --git a/lib/parse/package.json b/lib/parse/package.json index c18baefd..23d02b8e 100644 --- a/lib/parse/package.json +++ b/lib/parse/package.json @@ -5,7 +5,7 @@ "main": "index.js", "types": "index.d.ts", "scripts": { - "asbuild": "asc assembly/index.ts -O3 -b build/index.wasm -t build/index.wat --importMemory --noDebug --sourceMap --validate", + "asbuild": "asc assembly/index.ts -O3 -b build/index.wasm -t build/index.wat --importMemory --sourceMap --validate", "build": "npm run asbuild && webpack --mode production --display-modules", "test": "ts-node tests/" }, diff --git a/package-lock.json b/package-lock.json index 618661ed..e794980f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -549,9 +549,9 @@ "dev": true }, "binaryen": { - "version": "52.0.0-nightly.20181104", - "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-52.0.0-nightly.20181104.tgz", - "integrity": "sha512-vmo9zN26kfulEFRWe0okJ2eKS6tef0sIE8bnzPyRbK/OlDRMaYYnmiYbKYwTtCe8CdO3zxDrpWTMXrI426UaZw==" + "version": "52.0.0-nightly.20181108", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-52.0.0-nightly.20181108.tgz", + "integrity": "sha512-EPCTNikr5NWz63au0pIrt8snmt+Fv/YERiDD/BQIT9I0jLYB11m/oMuUA5k5kMCLsfTc2w7Sma4jKVu7VR/owA==" }, "bluebird": { "version": "3.5.3", diff --git a/package.json b/package.json index c402916b..07136324 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@protobufjs/utf8": "^1.1.0", - "binaryen": "52.0.0-nightly.20181104", + "binaryen": "52.0.0-nightly.20181108", "glob": "^7.1.3", "long": "^4.0.0" }, diff --git a/tests/compiler.js b/tests/compiler.js index d331cebb..8846efd7 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -86,6 +86,7 @@ tests.forEach(filename => { "--baseDir", basedir, "--validate", "--measure", + "--debug", "--textFile" // -> stdout ], { stdout: stdout, @@ -136,9 +137,9 @@ tests.forEach(filename => { filename, "--baseDir", basedir, "--validate", - "-O3", "--measure", - "--binaryFile" // -> stdout + "--binaryFile", // -> stdout + "-O3" ]; if (args.create) cmd.push( "--textFile", basename + ".optimized.wat" diff --git a/tests/compiler/abi.optimized.wat b/tests/compiler/abi.optimized.wat index e86322e2..3b8485c5 100644 --- a/tests/compiler/abi.optimized.wat +++ b/tests/compiler/abi.optimized.wat @@ -12,28 +12,13 @@ (export "memory" (memory $0)) (export "table" (table $0)) (export "exported" (func $abi/exported)) - (export "exportedExported" (func $abi/exportedExported)) - (export "exportedInternal" (func $abi/exportedInternal)) + (export "exportedExported" (func $abi/exported)) + (export "exportedInternal" (func $abi/exported)) (start $start) (func $abi/exported (; 1 ;) (type $i) (result i32) i32.const -128 ) - (func $abi/exportedExported (; 2 ;) (type $i) (result i32) - call $abi/exported - ) - (func $abi/internal (; 3 ;) (type $i) (result i32) - i32.const 128 - ) - (func $abi/exportedInternal (; 4 ;) (type $i) (result i32) - call $abi/internal - i32.const 24 - i32.shl - i32.const 24 - i32.shr_s - ) - (func $start (; 5 ;) (type $v) - call $abi/internal - drop + (func $start (; 2 ;) (type $v) i32.const 1 set_global $abi/condition i32.const 0 @@ -48,7 +33,7 @@ unreachable end ) - (func $null (; 6 ;) (type $v) + (func $null (; 3 ;) (type $v) nop ) ) diff --git a/tests/compiler/binary.optimized.wat b/tests/compiler/binary.optimized.wat index 5c1e0b3d..265b62c8 100644 --- a/tests/compiler/binary.optimized.wat +++ b/tests/compiler/binary.optimized.wat @@ -221,32 +221,7 @@ get_local $0 f32.mul ) - (func $~lib/math/NativeMathf.pow (; 2 ;) (type $FUNCSIG$ff) (param $0 f32) (result f32) - (local $1 i32) - (local $2 i32) - get_local $0 - i32.reinterpret/f32 - tee_local $2 - i32.const 2147483647 - i32.and - i32.const 2139095040 - i32.gt_s - tee_local $1 - i32.eqz - if - i32.const 0 - set_local $1 - end - get_local $1 - if - get_local $0 - f32.const 1 - f32.add - return - end - get_local $0 - ) - (func $~lib/math/NativeMath.mod (; 3 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.mod (; 2 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) (local $1 i64) (local $2 i64) (local $3 i64) @@ -404,7 +379,9 @@ get_local $0 f64.mul ) - (func $start (; 4 ;) (type $v) + (func $start (; 3 ;) (type $v) + (local $0 f32) + (local $1 i32) get_global $binary/i i32.const 1 i32.rem_s @@ -626,9 +603,23 @@ get_global $binary/f call $~lib/math/NativeMathf.mod drop - get_global $binary/f - call $~lib/math/NativeMathf.pow - drop + block $__inlined_func$~lib/math/NativeMathf.pow + get_global $binary/f + tee_local $0 + i32.reinterpret/f32 + i32.const 2147483647 + i32.and + i32.const 2139095040 + i32.gt_s + tee_local $1 + i32.eqz + if + i32.const 0 + set_local $1 + end + get_local $1 + br_if $__inlined_func$~lib/math/NativeMathf.pow + end get_global $binary/f f32.const 1 f32.lt @@ -664,8 +655,29 @@ get_global $binary/f call $~lib/math/NativeMathf.mod set_global $binary/f - get_global $binary/f - call $~lib/math/NativeMathf.pow + block $__inlined_func$~lib/math/NativeMathf.pow0 + get_global $binary/f + tee_local $0 + i32.reinterpret/f32 + i32.const 2147483647 + i32.and + i32.const 2139095040 + i32.gt_s + tee_local $1 + i32.eqz + if + i32.const 0 + set_local $1 + end + get_local $1 + if + get_local $0 + f32.const 1 + f32.add + set_local $0 + end + end + get_local $0 set_global $binary/f get_global $binary/f f32.const 1 @@ -678,8 +690,29 @@ get_global $binary/f call $~lib/math/NativeMathf.mod set_global $binary/f - get_global $binary/f - call $~lib/math/NativeMathf.pow + block $__inlined_func$~lib/math/NativeMathf.pow2 + get_global $binary/f + tee_local $0 + i32.reinterpret/f32 + i32.const 2147483647 + i32.and + i32.const 2139095040 + i32.gt_s + tee_local $1 + i32.eqz + if + i32.const 0 + set_local $1 + end + get_local $1 + if + get_local $0 + f32.const 1 + f32.add + set_local $0 + end + end + get_local $0 set_global $binary/f get_global $binary/F call $~lib/math/NativeMath.mod @@ -740,7 +773,7 @@ call $~lib/math/NativeMath.pow set_global $binary/F ) - (func $null (; 5 ;) (type $v) + (func $null (; 4 ;) (type $v) nop ) ) diff --git a/tests/compiler/call-inferred.optimized.wat b/tests/compiler/call-inferred.optimized.wat index 84687f2b..7ed5514f 100644 --- a/tests/compiler/call-inferred.optimized.wat +++ b/tests/compiler/call-inferred.optimized.wat @@ -1,73 +1,12 @@ (module - (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$d (func (result f64))) - (type $FUNCSIG$f (func (result f32))) - (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\10\00\00\00c\00a\00l\00l\00-\00i\00n\00f\00e\00r\00r\00e\00d\00.\00t\00s") (table $0 1 anyfunc) - (elem (i32.const 0) $null) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) - (start $start) - (func $call-inferred/foo (; 1 ;) (type $FUNCSIG$i) (result i32) - i32.const 42 - ) - (func $call-inferred/foo (; 2 ;) (type $FUNCSIG$d) (result f64) - f64.const 42 - ) - (func $call-inferred/foo (; 3 ;) (type $FUNCSIG$f) (result f32) - f32.const 42 - ) - (func $start (; 4 ;) (type $v) - call $call-inferred/foo - i32.const 42 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 5 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $call-inferred/foo - f64.const 42 - f64.ne - if - i32.const 0 - i32.const 8 - i32.const 6 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $call-inferred/foo - f32.const 42 - f32.ne - if - i32.const 0 - i32.const 8 - i32.const 7 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $call-inferred/foo - f32.const 42 - f32.ne - if - i32.const 0 - i32.const 8 - i32.const 13 - i32.const 0 - call $~lib/env/abort - unreachable - end - ) - (func $null (; 5 ;) (type $v) + (func $start (; 0 ;) (type $v) nop ) ) diff --git a/tests/compiler/call-optional.optimized.wat b/tests/compiler/call-optional.optimized.wat index 63f8996d..ea1c2c37 100644 --- a/tests/compiler/call-optional.optimized.wat +++ b/tests/compiler/call-optional.optimized.wat @@ -12,14 +12,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $call-optional/opt (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - get_local $0 - get_local $1 - i32.add - get_local $2 - i32.add - ) - (func $call-optional/opt|trampoline (; 2 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $call-optional/opt|trampoline (; 1 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) block $2of2 block $1of2 block $0of2 @@ -39,16 +32,37 @@ end get_local $0 get_local $1 + i32.add get_local $2 - call $call-optional/opt + i32.add ) - (func $start (; 3 ;) (type $v) + (func $start (; 2 ;) (type $v) + (local $0 i32) + (local $1 i32) i32.const 1 set_global $~argc + block $2of2 + block $1of2 + block $0of2 + block $outOfRange + get_global $~argc + i32.const 1 + i32.sub + br_table $0of2 $1of2 $2of2 $outOfRange + end + unreachable + end + i32.const -1 + set_local $0 + end + i32.const -2 + set_local $1 + end + get_local $0 i32.const 3 - i32.const 0 - i32.const 0 - call $call-optional/opt|trampoline + i32.add + get_local $1 + i32.add if i32.const 0 i32.const 8 @@ -59,10 +73,32 @@ end i32.const 2 set_global $~argc - i32.const 3 i32.const 4 + set_local $0 i32.const 0 - call $call-optional/opt|trampoline + set_local $1 + block $2of21 + block $1of22 + block $0of23 + block $outOfRange4 + get_global $~argc + i32.const 1 + i32.sub + br_table $0of23 $1of22 $2of21 $outOfRange4 + end + unreachable + end + i32.const -1 + set_local $0 + end + i32.const -2 + set_local $1 + end + get_local $0 + i32.const 3 + i32.add + get_local $1 + i32.add i32.const 5 i32.ne if @@ -73,20 +109,6 @@ call $~lib/env/abort unreachable end - i32.const 3 - i32.const 4 - i32.const 5 - call $call-optional/opt - i32.const 12 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 6 - i32.const 0 - call $~lib/env/abort - unreachable - end i32.const 1 set_global $~argc i32.const 3 @@ -137,7 +159,7 @@ unreachable end ) - (func $null (; 4 ;) (type $v) + (func $null (; 3 ;) (type $v) nop ) ) diff --git a/tests/compiler/class-overloading.optimized.wat b/tests/compiler/class-overloading.optimized.wat index 54cf7958..e547460b 100644 --- a/tests/compiler/class-overloading.optimized.wat +++ b/tests/compiler/class-overloading.optimized.wat @@ -1,25 +1,16 @@ (module (type $iv (func (param i32))) (type $v (func)) - (type $FUNCSIG$v (func)) (memory $0 0) (table $0 1 anyfunc) - (elem (i32.const 0) $null) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) (export "test" (func $class-overloading/test)) - (start $start) - (func $class-overloading/Foo#baz (; 0 ;) (type $FUNCSIG$v) + (func $class-overloading/test (; 0 ;) (type $iv) (param $0 i32) nop ) - (func $class-overloading/test (; 1 ;) (type $iv) (param $0 i32) - call $class-overloading/Foo#baz - ) - (func $start (; 2 ;) (type $v) - i32.const 0 - call $class-overloading/test - ) - (func $null (; 3 ;) (type $v) + (func $start (; 1 ;) (type $v) nop ) ) diff --git a/tests/compiler/class.optimized.wat b/tests/compiler/class.optimized.wat index ff7a9ced..58980ff8 100644 --- a/tests/compiler/class.optimized.wat +++ b/tests/compiler/class.optimized.wat @@ -1,33 +1,14 @@ (module (type $ii (func (param i32) (result i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$f (func (result f32))) (memory $0 1) (data (i32.const 8) "\08\00\00\00c\00l\00a\00s\00s\00.\00t\00s") (table $0 1 anyfunc) - (elem (i32.const 0) $null) - (global $class/Animal.ONE (mut i32) (i32.const 1)) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) (export "test" (func $class/test)) - (start $start) - (func $class/Animal.add (; 0 ;) (type $FUNCSIG$i) (result i32) - get_global $class/Animal.ONE - i32.const 3 - i32.add - ) - (func $class/Animal.sub (; 1 ;) (type $FUNCSIG$f) (result f32) - f32.const -1 - get_global $class/Animal.ONE - f32.convert_s/i32 - f32.add - ) - (func $class/test (; 2 ;) (type $ii) (param $0 i32) (result i32) - call $class/Animal.add - drop - call $class/Animal.sub - drop + (func $class/test (; 0 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.load drop @@ -48,13 +29,7 @@ i32.store8 offset=6 get_local $0 ) - (func $start (; 3 ;) (type $v) - call $class/Animal.add - drop - call $class/Animal.sub - drop - ) - (func $null (; 4 ;) (type $v) + (func $start (; 1 ;) (type $v) nop ) ) diff --git a/tests/compiler/enum.optimized.wat b/tests/compiler/enum.optimized.wat index 8e8679cd..ad861254 100644 --- a/tests/compiler/enum.optimized.wat +++ b/tests/compiler/enum.optimized.wat @@ -1,5 +1,4 @@ (module - (type $i (func (result i32))) (type $v (func)) (memory $0 0) (table $0 1 anyfunc) @@ -37,18 +36,13 @@ (export "SelfReference.ZERO" (global $enum/SelfReference.ZERO)) (export "SelfReference.ONE" (global $enum/SelfReference.ONE)) (start $start) - (func $enum/getZero (; 0 ;) (type $i) (result i32) + (func $start (; 0 ;) (type $v) i32.const 0 - ) - (func $start (; 1 ;) (type $v) - call $enum/getZero set_global $enum/NonConstant.ZERO - call $enum/getZero i32.const 1 - i32.add set_global $enum/NonConstant.ONE ) - (func $null (; 2 ;) (type $v) + (func $null (; 1 ;) (type $v) nop ) ) diff --git a/tests/compiler/exports.optimized.wat b/tests/compiler/exports.optimized.wat index 1180572e..13d3c3e9 100644 --- a/tests/compiler/exports.optimized.wat +++ b/tests/compiler/exports.optimized.wat @@ -5,7 +5,6 @@ (type $iiv (func (param i32 i32))) (type $iv (func (param i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (memory $0 0) (table $0 1 anyfunc) (elem (i32.const 0) $null) @@ -122,46 +121,28 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 4 ;) (type $FUNCSIG$i) (result i32) - i32.const 4 - call $~lib/allocator/arena/__memory_allocate - ) - (func $exports/Car#constructor (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.eqz - if - call $~lib/memory/memory.allocate - tee_local $0 - get_local $1 - i32.store - end - get_local $0 - get_local $1 - i32.store - get_local $0 - ) - (func $exports/Car#get:numDoors (; 6 ;) (type $ii) (param $0 i32) (result i32) + (func $exports/Car#get:numDoors (; 4 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.load ) - (func $exports/Car#set:numDoors (; 7 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $exports/Car#set:numDoors (; 5 ;) (type $iiv) (param $0 i32) (param $1 i32) get_local $0 get_local $1 i32.store ) - (func $exports/Car#openDoors (; 8 ;) (type $iv) (param $0 i32) + (func $exports/Car#openDoors (; 6 ;) (type $iv) (param $0 i32) nop ) - (func $start (; 9 ;) (type $v) + (func $start (; 7 ;) (type $v) i32.const 8 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset set_global $~lib/allocator/arena/offset ) - (func $null (; 10 ;) (type $v) + (func $null (; 8 ;) (type $v) nop ) - (func $exports/subOpt|trampoline (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $exports/subOpt|trampoline (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) block $1of1 block $0of1 block $outOfRange @@ -177,13 +158,13 @@ end get_local $0 get_local $1 - call $exports/subOpt + i32.sub ) - (func $~setargc (; 12 ;) (type $iv) (param $0 i32) + (func $~setargc (; 10 ;) (type $iv) (param $0 i32) get_local $0 set_global $~argc ) - (func $exports/Car#constructor|trampoline (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $exports/Car#constructor|trampoline (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) block $1of1 block $0of1 block $outOfRange @@ -196,7 +177,17 @@ set_local $1 end get_local $0 + i32.eqz + if + i32.const 4 + call $~lib/allocator/arena/__memory_allocate + tee_local $0 + get_local $1 + i32.store + end + get_local $0 get_local $1 - call $exports/Car#constructor + i32.store + get_local $0 ) ) diff --git a/tests/compiler/function-types.optimized.wat b/tests/compiler/function-types.optimized.wat index 50e60832..46dc74b3 100644 --- a/tests/compiler/function-types.optimized.wat +++ b/tests/compiler/function-types.optimized.wat @@ -1,12 +1,9 @@ (module - (type $i (func (result i32))) (type $iii (func (param i32 i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $III (func (param i64 i64) (result i64))) (type $FFF (func (param f64 f64) (result f64))) - (type $iiii (func (param i32 i32 i32) (result i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\11\00\00\00f\00u\00n\00c\00t\00i\00o\00n\00-\00t\00y\00p\00e\00s\00.\00t\00s") @@ -23,63 +20,19 @@ get_local $1 i32.add ) - (func $function-types/makeAdder (; 2 ;) (type $i) (result i32) - i32.const 1 - ) - (func $function-types/makeAdder~anonymous|2 (; 3 ;) (type $III) (param $0 i64) (param $1 i64) (result i64) + (func $function-types/makeAdder~anonymous|2 (; 2 ;) (type $III) (param $0 i64) (param $1 i64) (result i64) get_local $0 get_local $1 i64.add ) - (func $function-types/makeAdder (; 4 ;) (type $i) (result i32) - i32.const 2 - ) - (func $function-types/makeAdder~anonymous|3 (; 5 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $function-types/makeAdder~anonymous|3 (; 3 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) get_local $0 get_local $1 f64.add ) - (func $function-types/makeAdder (; 6 ;) (type $i) (result i32) - i32.const 3 - ) - (func $function-types/doAddWithFn (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - i32.const 2 - set_global $~argc - get_local $0 - get_local $1 - get_local $2 - call_indirect (type $iii) - ) - (func $function-types/doAdd (; 8 ;) (type $FUNCSIG$i) (result i32) - i32.const 2 - set_global $~argc - i32.const 3 - i32.const 4 - call $function-types/makeAdder - call_indirect (type $iii) - ) - (func $function-types/makeAndAdd|trampoline (; 9 ;) (type $FUNCSIG$i) (result i32) + (func $start (; 4 ;) (type $v) (local $0 i32) - block $1of1 - block $0of1 - block $outOfRange - get_global $~argc - i32.const 2 - i32.sub - br_table $0of1 $1of1 $outOfRange - end - unreachable - end - call $function-types/makeAdder - set_local $0 - end i32.const 1 - i32.const 2 - get_local $0 - call $function-types/doAddWithFn - ) - (func $start (; 10 ;) (type $v) - call $function-types/makeAdder set_global $function-types/i32Adder i32.const 2 set_global $~argc @@ -97,7 +50,7 @@ call $~lib/env/abort unreachable end - call $function-types/makeAdder + i32.const 2 set_global $function-types/i64Adder i32.const 2 set_global $~argc @@ -119,7 +72,7 @@ set_global $~argc f64.const 1.5 f64.const 2.5 - call $function-types/makeAdder + i32.const 3 call_indirect (type $FFF) f64.const 4 f64.ne @@ -132,9 +85,11 @@ unreachable end i32.const 2 + set_global $~argc + i32.const 2 i32.const 3 get_global $function-types/i32Adder - call $function-types/doAddWithFn + call_indirect (type $iii) i32.const 5 i32.ne if @@ -145,7 +100,12 @@ call $~lib/env/abort unreachable end - call $function-types/doAdd + i32.const 2 + set_global $~argc + i32.const 3 + i32.const 4 + i32.const 1 + call_indirect (type $iii) i32.const 7 i32.ne if @@ -156,10 +116,12 @@ call $~lib/env/abort unreachable end + i32.const 2 + set_global $~argc i32.const 4 i32.const 5 i32.const 4 - call $function-types/doAddWithFn + call_indirect (type $iii) i32.const 9 i32.ne if @@ -172,7 +134,25 @@ end i32.const 2 set_global $~argc - call $function-types/makeAndAdd|trampoline + block $1of1 + block $0of1 + block $outOfRange + get_global $~argc + i32.const 2 + i32.sub + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 1 + set_local $0 + end + i32.const 2 + set_global $~argc + i32.const 1 + i32.const 2 + get_local $0 + call_indirect (type $iii) i32.const 3 i32.ne if @@ -183,10 +163,12 @@ call $~lib/env/abort unreachable end + i32.const 2 + set_global $~argc i32.const 1 i32.const 2 - call $function-types/makeAdder - call $function-types/doAddWithFn + i32.const 1 + call_indirect (type $iii) i32.const 3 i32.ne if @@ -198,7 +180,7 @@ unreachable end ) - (func $null (; 11 ;) (type $v) + (func $null (; 5 ;) (type $v) nop ) ) diff --git a/tests/compiler/function.optimized.wat b/tests/compiler/function.optimized.wat index e582fc89..be03ea1a 100644 --- a/tests/compiler/function.optimized.wat +++ b/tests/compiler/function.optimized.wat @@ -1,89 +1,11 @@ (module (type $v (func)) - (type $i (func (result i32))) - (type $I (func (result i64))) - (type $f (func (result f32))) - (type $F (func (result f64))) - (type $FUNCSIG$v (func)) - (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$j (func (result i64))) - (type $FUNCSIG$f (func (result f32))) - (type $FUNCSIG$d (func (result f64))) (memory $0 0) (table $0 1 anyfunc) - (elem (i32.const 0) $function/v) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) - (start $start) - (func $function/v (; 0 ;) (type $v) + (func $start (; 0 ;) (type $v) nop ) - (func $function/i (; 1 ;) (type $i) (result i32) - i32.const 0 - ) - (func $function/I (; 2 ;) (type $I) (result i64) - i64.const 0 - ) - (func $function/f (; 3 ;) (type $f) (result f32) - f32.const 0 - ) - (func $function/F (; 4 ;) (type $F) (result f64) - f64.const 0 - ) - (func $function/iv (; 5 ;) (type $FUNCSIG$v) - nop - ) - (func $function/ii (; 6 ;) (type $FUNCSIG$i) (result i32) - i32.const 0 - ) - (func $function/II (; 7 ;) (type $FUNCSIG$j) (result i64) - i64.const 0 - ) - (func $function/ff (; 8 ;) (type $FUNCSIG$f) (result f32) - f32.const 0 - ) - (func $function/FF (; 9 ;) (type $FUNCSIG$d) (result f64) - f64.const 0 - ) - (func $function/iii (; 10 ;) (type $FUNCSIG$i) (result i32) - i32.const 3 - ) - (func $function/III (; 11 ;) (type $FUNCSIG$j) (result i64) - i64.const 3 - ) - (func $function/fff (; 12 ;) (type $FUNCSIG$f) (result f32) - f32.const 3 - ) - (func $function/FFF (; 13 ;) (type $FUNCSIG$d) (result f64) - f64.const 3 - ) - (func $start (; 14 ;) (type $v) - call $function/v - call $function/i - drop - call $function/I - drop - call $function/f - drop - call $function/F - drop - call $function/iv - call $function/ii - drop - call $function/II - drop - call $function/ff - drop - call $function/FF - drop - call $function/iv - call $function/iii - drop - call $function/III - drop - call $function/fff - drop - call $function/FFF - drop - ) ) diff --git a/tests/compiler/getter-call.optimized.wat b/tests/compiler/getter-call.optimized.wat index 680e38fb..aad02b15 100644 --- a/tests/compiler/getter-call.optimized.wat +++ b/tests/compiler/getter-call.optimized.wat @@ -2,7 +2,6 @@ (type $i (func (result i32))) (type $ii (func (param i32) (result i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (memory $0 0) (table $0 2 anyfunc) (elem (i32.const 0) $null $getter-call/C#get:x~anonymous|1) @@ -75,32 +74,25 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 1 ;) (type $FUNCSIG$i) (result i32) - i32.const 0 - call $~lib/allocator/arena/__memory_allocate - ) - (func $getter-call/C#get:x~anonymous|1 (; 2 ;) (type $i) (result i32) + (func $getter-call/C#get:x~anonymous|1 (; 1 ;) (type $i) (result i32) i32.const 42 ) - (func $getter-call/C#get:x (; 3 ;) (type $FUNCSIG$i) (result i32) - i32.const 1 - ) - (func $getter-call/test (; 4 ;) (type $i) (result i32) - (local $0 i32) - call $~lib/memory/memory.allocate - set_local $0 + (func $getter-call/test (; 2 ;) (type $i) (result i32) + i32.const 0 + call $~lib/allocator/arena/__memory_allocate + drop i32.const 0 set_global $~argc - call $getter-call/C#get:x + i32.const 1 call_indirect (type $i) ) - (func $start (; 5 ;) (type $v) + (func $start (; 3 ;) (type $v) i32.const 8 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset set_global $~lib/allocator/arena/offset ) - (func $null (; 6 ;) (type $v) + (func $null (; 4 ;) (type $v) nop ) ) diff --git a/tests/compiler/getter-setter.optimized.wat b/tests/compiler/getter-setter.optimized.wat index 8af94b51..793ad4bc 100644 --- a/tests/compiler/getter-setter.optimized.wat +++ b/tests/compiler/getter-setter.optimized.wat @@ -1,7 +1,5 @@ (module - (type $i (func (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) - (type $iv (func (param i32))) (type $v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) @@ -12,15 +10,8 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $getter-setter/Foo.get:bar (; 1 ;) (type $i) (result i32) + (func $start (; 1 ;) (type $v) get_global $getter-setter/Foo._bar - ) - (func $getter-setter/Foo.set:bar (; 2 ;) (type $iv) (param $0 i32) - get_local $0 - set_global $getter-setter/Foo._bar - ) - (func $start (; 3 ;) (type $v) - call $getter-setter/Foo.get:bar if i32.const 0 i32.const 8 @@ -30,8 +21,8 @@ unreachable end i32.const 1 - call $getter-setter/Foo.set:bar - call $getter-setter/Foo.get:bar + set_global $getter-setter/Foo._bar + get_global $getter-setter/Foo._bar i32.const 1 i32.ne if @@ -43,8 +34,8 @@ unreachable end i32.const 2 - call $getter-setter/Foo.set:bar - call $getter-setter/Foo.get:bar + set_global $getter-setter/Foo._bar + get_global $getter-setter/Foo._bar i32.const 2 i32.ne if @@ -56,7 +47,7 @@ unreachable end ) - (func $null (; 4 ;) (type $v) + (func $null (; 2 ;) (type $v) nop ) ) diff --git a/tests/compiler/if.optimized.wat b/tests/compiler/if.optimized.wat index 400a1ed4..911f60c1 100644 --- a/tests/compiler/if.optimized.wat +++ b/tests/compiler/if.optimized.wat @@ -6,14 +6,13 @@ (memory $0 1) (data (i32.const 8) "\05\00\00\00i\00f\00.\00t\00s") (table $0 1 anyfunc) - (elem (i32.const 0) $null) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) (export "ifThenElse" (func $if/ifThenElse)) (export "ifThen" (func $if/ifThen)) (export "ifThenElseBlock" (func $if/ifThenElse)) (export "ifAlwaysReturns" (func $if/ifAlwaysReturns)) - (start $start) (func $if/ifThenElse (; 1 ;) (type $ii) (param $0 i32) (result i32) get_local $0 if (result i32) @@ -44,74 +43,6 @@ end ) (func $start (; 4 ;) (type $v) - i32.const 0 - call $if/ifThenElse - if - i32.const 0 - i32.const 8 - i32.const 8 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 1 - call $if/ifThenElse - i32.const 1 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 9 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 0 - call $if/ifThen - if - i32.const 0 - i32.const 8 - i32.const 17 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 1 - call $if/ifThen - i32.const 1 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 18 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 0 - call $if/ifThenElse - if - i32.const 0 - i32.const 8 - i32.const 30 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 1 - call $if/ifThenElse - i32.const 1 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 31 - i32.const 0 - call $~lib/env/abort - unreachable - end - ) - (func $null (; 5 ;) (type $v) nop ) ) diff --git a/tests/compiler/import.optimized.wat b/tests/compiler/import.optimized.wat index ce4eb673..be03ea1a 100644 --- a/tests/compiler/import.optimized.wat +++ b/tests/compiler/import.optimized.wat @@ -1,37 +1,11 @@ (module (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (memory $0 0) (table $0 1 anyfunc) - (elem (i32.const 0) $export/ns.two) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) - (start $start) - (func $export/add (; 0 ;) (type $FUNCSIG$i) (result i32) - i32.const 3 - ) - (func $export/sub (; 1 ;) (type $FUNCSIG$i) (result i32) - i32.const -1 - ) - (func $export/ns.two (; 2 ;) (type $v) + (func $start (; 0 ;) (type $v) nop ) - (func $start (; 3 ;) (type $v) - (local $0 i32) - (local $1 i32) - call $export/add - set_local $0 - call $export/sub - set_local $1 - call $export/add - drop - call $export/ns.two - call $export/add - set_local $0 - call $export/sub - set_local $1 - call $export/add - drop - call $export/ns.two - ) ) diff --git a/tests/compiler/infer-type.optimized.wat b/tests/compiler/infer-type.optimized.wat index d752382e..9a453559 100644 --- a/tests/compiler/infer-type.optimized.wat +++ b/tests/compiler/infer-type.optimized.wat @@ -1,13 +1,9 @@ (module (type $v (func)) - (type $i (func (result i32))) - (type $I (func (result i64))) - (type $f (func (result f32))) - (type $F (func (result f64))) (memory $0 1) (data (i32.const 8) "\0d\00\00\00i\00n\00f\00e\00r\00-\00t\00y\00p\00e\00.\00t\00s") (table $0 1 anyfunc) - (elem (i32.const 0) $infer-type/locals) + (elem (i32.const 0) $null) (global $infer-type/ri (mut i32) (i32.const 0)) (global $infer-type/rI (mut i64) (i64.const 0)) (global $infer-type/rf (mut f32) (f32.const 0)) @@ -15,31 +11,15 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $infer-type/locals (; 0 ;) (type $v) - nop - ) - (func $infer-type/reti (; 1 ;) (type $i) (result i32) - i32.const 0 - ) - (func $infer-type/retI (; 2 ;) (type $I) (result i64) - i64.const 0 - ) - (func $infer-type/retf (; 3 ;) (type $f) (result f32) - f32.const 0 - ) - (func $infer-type/refF (; 4 ;) (type $F) (result f64) - f64.const 0 - ) - (func $start (; 5 ;) (type $v) + (func $start (; 0 ;) (type $v) (local $0 i32) - call $infer-type/locals - call $infer-type/reti + i32.const 0 set_global $infer-type/ri - call $infer-type/retI + i64.const 0 set_global $infer-type/rI - call $infer-type/retf + f32.const 0 set_global $infer-type/rf - call $infer-type/refF + f64.const 0 set_global $infer-type/rF block $break|0 loop $repeat|0 @@ -57,4 +37,7 @@ unreachable end ) + (func $null (; 1 ;) (type $v) + nop + ) ) diff --git a/tests/compiler/inlining-recursive.optimized.wat b/tests/compiler/inlining-recursive.optimized.wat index 4a3905e4..8fbb6c1f 100644 --- a/tests/compiler/inlining-recursive.optimized.wat +++ b/tests/compiler/inlining-recursive.optimized.wat @@ -6,18 +6,15 @@ (export "memory" (memory $0)) (export "table" (table $0)) (export "foo" (func $inlining-recursive/foo)) - (export "bar" (func $inlining-recursive/bar)) + (export "bar" (func $inlining-recursive/baz)) (export "baz" (func $inlining-recursive/baz)) (func $inlining-recursive/foo (; 0 ;) (type $v) call $inlining-recursive/foo ) (func $inlining-recursive/baz (; 1 ;) (type $v) - call $inlining-recursive/bar - ) - (func $inlining-recursive/bar (; 2 ;) (type $v) call $inlining-recursive/baz ) - (func $null (; 3 ;) (type $v) + (func $null (; 2 ;) (type $v) nop ) ) diff --git a/tests/compiler/inlining.optimized.wat b/tests/compiler/inlining.optimized.wat index 0a02ffef..d4534c17 100644 --- a/tests/compiler/inlining.optimized.wat +++ b/tests/compiler/inlining.optimized.wat @@ -37,17 +37,6 @@ end ) (func $start (; 4 ;) (type $v) - call $inlining/test - i32.const 3 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 10 - i32.const 0 - call $~lib/env/abort - unreachable - end call $inlining/test_funcs ) (func $null (; 5 ;) (type $v) diff --git a/tests/compiler/instanceof.optimized.wat b/tests/compiler/instanceof.optimized.wat index 7b2beb24..841deca3 100644 --- a/tests/compiler/instanceof.optimized.wat +++ b/tests/compiler/instanceof.optimized.wat @@ -1,7 +1,6 @@ (module (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\0d\00\00\00i\00n\00s\00t\00a\00n\00c\00e\00o\00f\00.\00t\00s") @@ -11,41 +10,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $instanceof/isI32 (; 1 ;) (type $FUNCSIG$i) (result i32) - i32.const 1 - ) - (func $instanceof/isI32 (; 2 ;) (type $FUNCSIG$i) (result i32) - i32.const 0 - ) - (func $start (; 3 ;) (type $v) - call $instanceof/isI32 - i32.eqz - if - i32.const 0 - i32.const 8 - i32.const 38 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $instanceof/isI32 - if - i32.const 0 - i32.const 8 - i32.const 39 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $instanceof/isI32 - if - i32.const 0 - i32.const 8 - i32.const 40 - i32.const 0 - call $~lib/env/abort - unreachable - end + (func $start (; 1 ;) (type $v) get_global $instanceof/an if i32.const 0 @@ -68,7 +33,7 @@ unreachable end ) - (func $null (; 4 ;) (type $v) + (func $null (; 2 ;) (type $v) nop ) ) diff --git a/tests/compiler/main.optimized.wat b/tests/compiler/main.optimized.wat index 9975a99e..259adbe0 100644 --- a/tests/compiler/main.optimized.wat +++ b/tests/compiler/main.optimized.wat @@ -13,17 +13,14 @@ get_global $~started i32.eqz if - call $start + i32.const 1 + set_global $main/code i32.const 1 set_global $~started end get_global $main/code ) - (func $start (; 1 ;) (type $v) - i32.const 1 - set_global $main/code - ) - (func $null (; 2 ;) (type $v) + (func $null (; 1 ;) (type $v) nop ) ) diff --git a/tests/compiler/mandelbrot.optimized.wat b/tests/compiler/mandelbrot.optimized.wat index aeaeef49..9cec1fc0 100644 --- a/tests/compiler/mandelbrot.optimized.wat +++ b/tests/compiler/mandelbrot.optimized.wat @@ -1,9 +1,7 @@ (module (type $iiiiv (func (param i32 i32 i32 i32))) (type $FF (func (param f64) (result f64))) - (type $Fi (func (param f64) (result i32))) (type $v (func)) - (type $FUNCSIG$dd (func (param f64) (result f64))) (memory $0 0) (table $0 1 anyfunc) (elem (i32.const 0) $null) @@ -188,26 +186,12 @@ f64.mul f64.add ) - (func $~lib/builtins/isFinite (; 1 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.sub - f64.const 0 - f64.eq - ) - (func $../../examples/mandelbrot/assembly/index/clamp (; 2 ;) (type $FUNCSIG$dd) (param $0 f64) (result f64) - get_local $0 - f64.const 0 - f64.max - f64.const 1 - f64.min - ) - (func $../../examples/mandelbrot/assembly/index/computeLine (; 3 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) + (func $../../examples/mandelbrot/assembly/index/computeLine (; 1 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (local $4 f64) (local $5 f64) (local $6 f64) - (local $7 i32) - (local $8 f64) + (local $7 f64) + (local $8 i32) (local $9 f64) (local $10 f64) (local $11 f64) @@ -225,7 +209,7 @@ tee_local $4 f64.const 2 f64.div - tee_local $8 + tee_local $7 f64.sub f64.const 10 f64.const 3 @@ -241,11 +225,11 @@ set_local $9 block $break|0 loop $repeat|0 - get_local $7 + get_local $8 get_local $1 i32.ge_u br_if $break|0 - get_local $7 + get_local $8 f64.convert_u/i32 get_local $11 f64.sub @@ -267,7 +251,7 @@ get_local $5 get_local $5 f64.mul - tee_local $8 + tee_local $7 f64.add f64.const 4 f64.le @@ -281,7 +265,7 @@ f64.add set_local $5 get_local $6 - get_local $8 + get_local $7 f64.sub get_local $10 f64.add @@ -320,7 +304,7 @@ f64.sub get_local $10 f64.add - set_local $8 + set_local $7 f64.const 2 get_local $4 f64.mul @@ -329,7 +313,7 @@ get_local $9 f64.add set_local $5 - get_local $8 + get_local $7 set_local $4 get_local $2 i32.const 1 @@ -340,6 +324,13 @@ end unreachable end + get_local $0 + get_local $1 + i32.mul + get_local $8 + i32.add + i32.const 1 + i32.shl get_local $4 get_local $4 f64.mul @@ -353,7 +344,10 @@ f64.const 0.6931471805599453 f64.div tee_local $6 - call $~lib/builtins/isFinite + get_local $6 + f64.sub + f64.const 0 + f64.eq if (result i32) f64.const 2047 get_local $2 @@ -365,33 +359,28 @@ get_local $3 f64.convert_u/i32 f64.div - call $../../examples/mandelbrot/assembly/index/clamp + f64.const 0 + f64.max + f64.const 1 + f64.min f64.mul i32.trunc_u/f64 else i32.const 2047 end - set_local $2 - get_local $0 - get_local $1 - i32.mul - get_local $7 - i32.add - i32.const 1 - i32.shl - get_local $2 + tee_local $2 i32.store16 - get_local $7 + get_local $8 i32.const 1 i32.add - set_local $7 + set_local $8 br $repeat|0 unreachable end unreachable end ) - (func $null (; 4 ;) (type $v) + (func $null (; 2 ;) (type $v) nop ) ) diff --git a/tests/compiler/many-locals.optimized.wat b/tests/compiler/many-locals.optimized.wat index ece48cf1..f35f79e3 100644 --- a/tests/compiler/many-locals.optimized.wat +++ b/tests/compiler/many-locals.optimized.wat @@ -1,54 +1,25 @@ (module (type $ii (func (param i32) (result i32))) - (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) - (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\0e\00\00\00m\00a\00n\00y\00-\00l\00o\00c\00a\00l\00s\00.\00t\00s") (table $0 1 anyfunc) - (elem (i32.const 0) $null) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) (export "testI32" (func $many-locals/testI32)) (export "testI8" (func $many-locals/testI8)) - (start $start) - (func $many-locals/testI32 (; 1 ;) (type $ii) (param $0 i32) (result i32) + (func $many-locals/testI32 (; 0 ;) (type $ii) (param $0 i32) (result i32) get_local $0 ) - (func $many-locals/testI8 (; 2 ;) (type $ii) (param $0 i32) (result i32) + (func $many-locals/testI8 (; 1 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 24 i32.shl i32.const 24 i32.shr_s ) - (func $start (; 3 ;) (type $v) - i32.const 42 - call $many-locals/testI32 - i32.const 42 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 133 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 42 - call $many-locals/testI8 - i32.const 42 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 267 - i32.const 0 - call $~lib/env/abort - unreachable - end - ) - (func $null (; 4 ;) (type $v) + (func $start (; 2 ;) (type $v) nop ) ) diff --git a/tests/compiler/named-import-default.optimized.wat b/tests/compiler/named-import-default.optimized.wat index 708e1939..174f6a47 100644 --- a/tests/compiler/named-import-default.optimized.wat +++ b/tests/compiler/named-import-default.optimized.wat @@ -7,13 +7,10 @@ (export "memory" (memory $0)) (export "table" (table $0)) (export "getValue" (func $named-import-default/getValue)) - (func $named-export-default/get3 (; 0 ;) (type $i) (result i32) + (func $named-import-default/getValue (; 0 ;) (type $i) (result i32) i32.const 3 ) - (func $named-import-default/getValue (; 1 ;) (type $i) (result i32) - call $named-export-default/get3 - ) - (func $null (; 2 ;) (type $v) + (func $null (; 1 ;) (type $v) nop ) ) diff --git a/tests/compiler/namespace.optimized.wat b/tests/compiler/namespace.optimized.wat index eb0e992a..be03ea1a 100644 --- a/tests/compiler/namespace.optimized.wat +++ b/tests/compiler/namespace.optimized.wat @@ -1,26 +1,11 @@ (module - (type $i (func (result i32))) (type $v (func)) (memory $0 0) (table $0 1 anyfunc) - (elem (i32.const 0) $null) - (global $namespace/Outer.Inner.aVar (mut i32) (i32.const 0)) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) - (start $start) - (func $namespace/Outer.Inner.aFunc (; 0 ;) (type $i) (result i32) - get_global $namespace/Outer.Inner.aVar - ) - (func $namespace/Joined.anotherFunc (; 1 ;) (type $i) (result i32) - i32.const 3 - ) - (func $start (; 2 ;) (type $v) - call $namespace/Outer.Inner.aFunc - drop - call $namespace/Joined.anotherFunc - drop - ) - (func $null (; 3 ;) (type $v) + (func $start (; 0 ;) (type $v) nop ) ) diff --git a/tests/compiler/new-without-allocator.optimized.wat b/tests/compiler/new-without-allocator.optimized.wat index eca558f9..e18b8440 100644 --- a/tests/compiler/new-without-allocator.optimized.wat +++ b/tests/compiler/new-without-allocator.optimized.wat @@ -1,22 +1,16 @@ (module (type $i (func (result i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (memory $0 0) (table $0 1 anyfunc) (elem (i32.const 0) $null) (export "memory" (memory $0)) (export "table" (table $0)) (export "test" (func $new-without-allocator/test)) - (func $~lib/memory/memory.allocate (; 0 ;) (type $FUNCSIG$i) (result i32) + (func $new-without-allocator/test (; 0 ;) (type $i) (result i32) unreachable ) - (func $new-without-allocator/test (; 1 ;) (type $i) (result i32) - call $~lib/memory/memory.allocate - drop - i32.const 3 - ) - (func $null (; 2 ;) (type $v) + (func $null (; 1 ;) (type $v) nop ) ) diff --git a/tests/compiler/object-literal.optimized.wat b/tests/compiler/object-literal.optimized.wat index 69529d27..1e670972 100644 --- a/tests/compiler/object-literal.optimized.wat +++ b/tests/compiler/object-literal.optimized.wat @@ -78,11 +78,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 2 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - call $~lib/allocator/arena/__memory_allocate - ) - (func $~lib/internal/string/compareUnsafe (; 3 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/string/compareUnsafe (; 2 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -119,7 +115,7 @@ end get_local $4 ) - (func $~lib/string/String.__eq (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String.__eq (; 3 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 8 @@ -157,7 +153,7 @@ call $~lib/internal/string/compareUnsafe i32.eqz ) - (func $object-literal/bar (; 5 ;) (type $iv) (param $0 i32) + (func $object-literal/bar (; 4 ;) (type $iv) (param $0 i32) get_local $0 i32.load i32.const 1 @@ -183,7 +179,27 @@ unreachable end ) - (func $object-literal/bar2 (; 6 ;) (type $iv) (param $0 i32) + (func $start (; 5 ;) (type $v) + (local $0 i32) + i32.const 80 + set_global $~lib/allocator/arena/startOffset + get_global $~lib/allocator/arena/startOffset + set_global $~lib/allocator/arena/offset + i32.const 8 + call $~lib/allocator/arena/__memory_allocate + tee_local $0 + i32.const 1 + i32.store + get_local $0 + i32.const 8 + i32.store offset=4 + get_local $0 + call $object-literal/bar + i32.const 4 + call $~lib/allocator/arena/__memory_allocate + tee_local $0 + i32.const 2 + i32.store get_local $0 i32.load i32.const 2 @@ -196,8 +212,11 @@ call $~lib/env/abort unreachable end - ) - (func $object-literal/Foo2#test (; 7 ;) (type $iv) (param $0 i32) + i32.const 4 + call $~lib/allocator/arena/__memory_allocate + tee_local $0 + i32.const 3 + i32.store get_local $0 i32.load i32.const 3 @@ -211,38 +230,7 @@ unreachable end ) - (func $start (; 8 ;) (type $v) - (local $0 i32) - i32.const 80 - set_global $~lib/allocator/arena/startOffset - get_global $~lib/allocator/arena/startOffset - set_global $~lib/allocator/arena/offset - i32.const 8 - call $~lib/memory/memory.allocate - tee_local $0 - i32.const 1 - i32.store - get_local $0 - i32.const 8 - i32.store offset=4 - get_local $0 - call $object-literal/bar - i32.const 4 - call $~lib/memory/memory.allocate - tee_local $0 - i32.const 2 - i32.store - get_local $0 - call $object-literal/bar2 - i32.const 4 - call $~lib/memory/memory.allocate - tee_local $0 - i32.const 3 - i32.store - get_local $0 - call $object-literal/Foo2#test - ) - (func $null (; 9 ;) (type $v) + (func $null (; 6 ;) (type $v) nop ) ) diff --git a/tests/compiler/recursive.optimized.wat b/tests/compiler/recursive.optimized.wat index 12543f84..bb5cb972 100644 --- a/tests/compiler/recursive.optimized.wat +++ b/tests/compiler/recursive.optimized.wat @@ -8,7 +8,6 @@ (export "table" (table $0)) (export "fib" (func $recursive/fib)) (func $recursive/fib (; 0 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) get_local $0 i32.const 1 i32.le_s @@ -20,14 +19,10 @@ i32.const 1 i32.sub call $recursive/fib - set_local $1 get_local $0 i32.const 2 i32.sub call $recursive/fib - set_local $0 - get_local $1 - get_local $0 i32.add ) (func $null (; 1 ;) (type $v) diff --git a/tests/compiler/reexport.optimized.wat b/tests/compiler/reexport.optimized.wat index 991f6674..4196ca80 100644 --- a/tests/compiler/reexport.optimized.wat +++ b/tests/compiler/reexport.optimized.wat @@ -20,7 +20,6 @@ (export "renamed_add" (func $export/add)) (export "rerenamed_sub" (func $export/mul)) (export "renamed_ns.two" (func $export/ns.two)) - (start $start) (func $export/add (; 0 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 @@ -39,14 +38,4 @@ (func $export/ns.two (; 3 ;) (type $v) nop ) - (func $start (; 4 ;) (type $v) - i32.const 1 - i32.const 2 - call $export/add - drop - i32.const 3 - i32.const 4 - call $export/mul - drop - ) ) diff --git a/tests/compiler/rereexport.optimized.wat b/tests/compiler/rereexport.optimized.wat index 51ad6a42..7442d4c3 100644 --- a/tests/compiler/rereexport.optimized.wat +++ b/tests/compiler/rereexport.optimized.wat @@ -1,9 +1,8 @@ (module (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (memory $0 0) (table $0 1 anyfunc) - (elem (i32.const 0) $null) + (elem (i32.const 0) $start) (global $export/a i32 (i32.const 1)) (global $export/b i32 (i32.const 2)) (export "memory" (memory $0)) @@ -12,20 +11,7 @@ (export "renamed_a" (global $export/a)) (export "renamed_b" (global $export/b)) (export "renamed_renamed_b" (global $export/b)) - (start $start) - (func $export/add (; 0 ;) (type $FUNCSIG$i) (result i32) - i32.const 3 - ) - (func $export/mul (; 1 ;) (type $FUNCSIG$i) (result i32) - i32.const 12 - ) - (func $start (; 2 ;) (type $v) - call $export/add - drop - call $export/mul - drop - ) - (func $null (; 3 ;) (type $v) + (func $start (; 0 ;) (type $v) nop ) ) diff --git a/tests/compiler/retain-i32.optimized.wat b/tests/compiler/retain-i32.optimized.wat index 43e6992f..e30bb22d 100644 --- a/tests/compiler/retain-i32.optimized.wat +++ b/tests/compiler/retain-i32.optimized.wat @@ -1,7 +1,6 @@ (module (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) - (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\0d\00\00\00r\00e\00t\00a\00i\00n\00-\00i\003\002\00.\00t\00s") @@ -12,34 +11,8 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $retain-i32/test (; 1 ;) (type $FUNCSIG$v) - nop - ) - (func $start (; 2 ;) (type $v) + (func $start (; 1 ;) (type $v) (local $0 i32) - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test block $break|0 i32.const -128 set_local $0 @@ -48,18 +21,6 @@ i32.const 255 i32.gt_s br_if $break|0 - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test - call $retain-i32/test get_local $0 i32.const 1 i32.add @@ -300,7 +261,7 @@ unreachable end ) - (func $null (; 3 ;) (type $v) + (func $null (; 2 ;) (type $v) nop ) ) diff --git a/tests/compiler/scoped.optimized.wat b/tests/compiler/scoped.optimized.wat index beebb6d6..112e5df7 100644 --- a/tests/compiler/scoped.optimized.wat +++ b/tests/compiler/scoped.optimized.wat @@ -1,16 +1,12 @@ (module (type $v (func)) - (type $FUNCSIG$v (func)) (memory $0 0) (table $0 1 anyfunc) (elem (i32.const 0) $null) (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $scoped/fn (; 0 ;) (type $FUNCSIG$v) - nop - ) - (func $start (; 1 ;) (type $v) + (func $start (; 0 ;) (type $v) (local $0 i32) block $break|0 loop $repeat|0 @@ -44,9 +40,8 @@ end unreachable end - call $scoped/fn ) - (func $null (; 2 ;) (type $v) + (func $null (; 1 ;) (type $v) nop ) ) diff --git a/tests/compiler/static-this.optimized.wat b/tests/compiler/static-this.optimized.wat index 55f15a88..c620f6b9 100644 --- a/tests/compiler/static-this.optimized.wat +++ b/tests/compiler/static-this.optimized.wat @@ -1,5 +1,4 @@ (module - (type $i (func (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) @@ -11,11 +10,8 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $static-this/Foo.getBar (; 1 ;) (type $i) (result i32) + (func $start (; 1 ;) (type $v) get_global $static-this/Foo.bar - ) - (func $start (; 2 ;) (type $v) - call $static-this/Foo.getBar i32.const 42 i32.ne if @@ -27,7 +23,7 @@ unreachable end ) - (func $null (; 3 ;) (type $v) + (func $null (; 2 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/allocator_arena.optimized.wat b/tests/compiler/std/allocator_arena.optimized.wat index f48ba883..caa604e3 100644 --- a/tests/compiler/std/allocator_arena.optimized.wat +++ b/tests/compiler/std/allocator_arena.optimized.wat @@ -6,7 +6,6 @@ (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\16\00\00\00s\00t\00d\00/\00a\00l\00l\00o\00c\00a\00t\00o\00r\00_\00a\00r\00e\00n\00a\00.\00t\00s") @@ -1424,14 +1423,7 @@ end tee_local $0 ) - (func $~lib/allocator/arena/__memory_free (; 6 ;) (type $FUNCSIG$v) - nop - ) - (func $~lib/allocator/arena/__memory_reset (; 7 ;) (type $v) - get_global $~lib/allocator/arena/startOffset - set_global $~lib/allocator/arena/offset - ) - (func $start (; 8 ;) (type $v) + (func $start (; 6 ;) (type $v) i32.const 56 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -1533,9 +1525,8 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free - call $~lib/allocator/arena/__memory_free - call $~lib/allocator/arena/__memory_reset + get_global $~lib/allocator/arena/startOffset + set_global $~lib/allocator/arena/offset call $~lib/allocator/arena/__memory_allocate set_global $std/allocator_arena/ptr1 get_global $std/allocator_arena/ptr1 @@ -1550,7 +1541,7 @@ unreachable end ) - (func $null (; 9 ;) (type $v) + (func $null (; 7 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/array-access.optimized.wat b/tests/compiler/std/array-access.optimized.wat index 6b2cbeeb..d2b65301 100644 --- a/tests/compiler/std/array-access.optimized.wat +++ b/tests/compiler/std/array-access.optimized.wat @@ -1,6 +1,5 @@ (module (type $ii (func (param i32) (result i32))) - (type $iii (func (param i32 i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) @@ -18,8 +17,9 @@ (export "stringArrayMethodCall" (func $std/array-access/stringArrayMethodCall)) (export "stringArrayArrayPropertyAccess" (func $std/array-access/stringArrayArrayPropertyAccess)) (export "stringArrayArrayMethodCall" (func $std/array-access/stringArrayArrayMethodCall)) - (func $~lib/array/Array>#__get (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $1 + (func $std/array-access/i32ArrayArrayElementAccess (; 1 ;) (type $ii) (param $0 i32) (result i32) + i32.const 1 + i32.const 0 get_local $0 i32.load tee_local $0 @@ -29,9 +29,20 @@ i32.lt_u if (result i32) get_local $0 - get_local $1 - i32.const 2 - i32.shl + i32.load offset=8 + else + unreachable + end + tee_local $0 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 i32.add i32.load offset=8 else @@ -39,20 +50,25 @@ end tee_local $0 ) - (func $std/array-access/i32ArrayArrayElementAccess (; 2 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 + (func $std/array-access/stringArrayPropertyAccess (; 2 ;) (type $ii) (param $0 i32) (result i32) i32.const 0 - call $~lib/array/Array>#__get - i32.const 1 - call $~lib/array/Array>#__get - ) - (func $std/array-access/stringArrayPropertyAccess (; 3 ;) (type $ii) (param $0 i32) (result i32) get_local $0 - i32.const 0 - call $~lib/array/Array>#__get + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.load ) - (func $~lib/internal/string/compareUnsafe (; 4 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $~lib/internal/string/compareUnsafe (; 3 ;) (type $FUNCSIG$iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (local $4 i32) get_local $0 get_local $1 @@ -92,7 +108,7 @@ end get_local $4 ) - (func $~lib/string/String#startsWith (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#startsWith (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -132,29 +148,93 @@ call $~lib/internal/string/compareUnsafe i32.eqz ) - (func $std/array-access/stringArrayMethodCall (; 6 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 + (func $std/array-access/stringArrayMethodCall (; 5 ;) (type $ii) (param $0 i32) (result i32) i32.const 0 - call $~lib/array/Array>#__get + get_local $0 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 call $~lib/string/String#startsWith ) - (func $std/array-access/stringArrayArrayPropertyAccess (; 7 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 0 - call $~lib/array/Array>#__get + (func $std/array-access/stringArrayArrayPropertyAccess (; 6 ;) (type $ii) (param $0 i32) (result i32) i32.const 1 - call $~lib/array/Array>#__get + i32.const 0 + get_local $0 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.load ) - (func $std/array-access/stringArrayArrayMethodCall (; 8 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 0 - call $~lib/array/Array>#__get + (func $std/array-access/stringArrayArrayMethodCall (; 7 ;) (type $ii) (param $0 i32) (result i32) i32.const 1 - call $~lib/array/Array>#__get + i32.const 0 + get_local $0 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 call $~lib/string/String#startsWith ) - (func $null (; 9 ;) (type $v) + (func $null (; 8 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/array-literal.optimized.wat b/tests/compiler/std/array-literal.optimized.wat index 2fcf3077..090b7d29 100644 --- a/tests/compiler/std/array-literal.optimized.wat +++ b/tests/compiler/std/array-literal.optimized.wat @@ -1,8 +1,6 @@ (module (type $iiiiv (func (param i32 i32 i32 i32))) - (type $iii (func (param i32 i32) (result i32))) (type $ii (func (param i32) (result i32))) - (type $iiiv (func (param i32 i32 i32))) (type $v (func)) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$i (func (result i32))) @@ -31,55 +29,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/array/Array#__get (; 1 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.lt_u - if (result i32) - get_local $0 - get_local $1 - i32.add - i32.load8_s offset=8 - else - unreachable - end - tee_local $0 - ) - (func $~lib/array/Array#__get (; 2 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.const 2 - i32.shr_u - i32.lt_u - if (result i32) - get_local $0 - get_local $1 - i32.const 2 - i32.shl - i32.add - i32.load offset=8 - else - unreachable - end - tee_local $0 - ) - (func $~lib/internal/arraybuffer/computeSize (; 3 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/allocator/arena/__memory_allocate (; 4 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/__memory_allocate (; 1 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -141,7 +91,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 5 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -154,19 +104,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/memory/memory.allocate (; 6 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - call $~lib/allocator/arena/__memory_allocate - ) - (func $~lib/internal/memory/memset (; 7 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) get_local $1 i32.eqz @@ -385,14 +337,14 @@ end end ) - (func $~lib/array/Array#constructor (; 8 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/array/Array#constructor (; 4 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) i32.const 3 call $~lib/internal/arraybuffer/allocateUnsafe set_local $1 i32.const 8 - call $~lib/memory/memory.allocate + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 0 i32.store @@ -412,22 +364,14 @@ call $~lib/internal/memory/memset get_local $0 ) - (func $~lib/array/Array#__unchecked_set (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) - get_local $0 - i32.load - get_local $1 - i32.add - get_local $2 - i32.store8 offset=8 - ) - (func $~lib/array/Array#constructor (; 10 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/array/Array#constructor (; 5 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) i32.const 12 call $~lib/internal/arraybuffer/allocateUnsafe set_local $1 i32.const 8 - call $~lib/memory/memory.allocate + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 0 i32.store @@ -447,21 +391,7 @@ call $~lib/internal/memory/memset get_local $0 ) - (func $~lib/array/Array#__unchecked_set (; 11 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) - get_local $0 - i32.load - get_local $1 - i32.const 2 - i32.shl - i32.add - get_local $2 - i32.store offset=8 - ) - (func $std/array-literal/RefWithCtor#constructor (; 12 ;) (type $FUNCSIG$i) (result i32) - i32.const 0 - call $~lib/memory/memory.allocate - ) - (func $start (; 13 ;) (type $v) + (func $start (; 6 ;) (type $v) (local $0 i32) (local $1 i32) i32.const 232 @@ -480,9 +410,19 @@ call $~lib/env/abort unreachable end - i32.const 24 i32.const 0 - call $~lib/array/Array#__get + i32.const 24 + i32.load + tee_local $0 + i32.load + i32.lt_u + if (result i32) + get_local $0 + i32.load8_s offset=8 + else + unreachable + end + tee_local $0 i32.const 255 i32.and if @@ -493,9 +433,21 @@ call $~lib/env/abort unreachable end - i32.const 24 i32.const 1 - call $~lib/array/Array#__get + i32.const 24 + i32.load + tee_local $0 + i32.load + i32.lt_u + if (result i32) + get_local $0 + i32.const 1 + i32.add + i32.load8_s offset=8 + else + unreachable + end + tee_local $0 i32.const 255 i32.and i32.const 1 @@ -508,9 +460,21 @@ call $~lib/env/abort unreachable end - i32.const 24 i32.const 2 - call $~lib/array/Array#__get + i32.const 24 + i32.load + tee_local $0 + i32.load + i32.lt_u + if (result i32) + get_local $0 + i32.const 2 + i32.add + i32.load8_s offset=8 + else + unreachable + end + tee_local $0 i32.const 255 i32.and i32.const 2 @@ -535,9 +499,21 @@ call $~lib/env/abort unreachable end - i32.const 112 i32.const 0 - call $~lib/array/Array#__get + i32.const 112 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 if i32.const 0 i32.const 32 @@ -546,9 +522,23 @@ call $~lib/env/abort unreachable end - i32.const 112 i32.const 1 - call $~lib/array/Array#__get + i32.const 112 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 1 i32.ne if @@ -559,9 +549,23 @@ call $~lib/env/abort unreachable end - i32.const 112 i32.const 2 - call $~lib/array/Array#__get + i32.const 112 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 2 i32.ne if @@ -584,25 +588,29 @@ end call $~lib/array/Array#constructor tee_local $0 - i32.const 0 + i32.load get_global $std/array-literal/i - call $~lib/array/Array#__unchecked_set + i32.store8 offset=8 get_global $std/array-literal/i i32.const 1 i32.add set_global $std/array-literal/i get_local $0 + i32.load i32.const 1 + i32.add get_global $std/array-literal/i - call $~lib/array/Array#__unchecked_set + i32.store8 offset=8 get_global $std/array-literal/i i32.const 1 i32.add set_global $std/array-literal/i get_local $0 + i32.load i32.const 2 + i32.add get_global $std/array-literal/i - call $~lib/array/Array#__unchecked_set + i32.store8 offset=8 get_local $0 set_global $std/array-literal/dynamicArrayI8 get_global $std/array-literal/dynamicArrayI8 @@ -617,9 +625,19 @@ call $~lib/env/abort unreachable end - get_global $std/array-literal/dynamicArrayI8 i32.const 0 - call $~lib/array/Array#__get + get_global $std/array-literal/dynamicArrayI8 + i32.load + tee_local $0 + i32.load + i32.lt_u + if (result i32) + get_local $0 + i32.load8_s offset=8 + else + unreachable + end + tee_local $0 i32.const 255 i32.and if @@ -630,9 +648,21 @@ call $~lib/env/abort unreachable end - get_global $std/array-literal/dynamicArrayI8 i32.const 1 - call $~lib/array/Array#__get + get_global $std/array-literal/dynamicArrayI8 + i32.load + tee_local $0 + i32.load + i32.lt_u + if (result i32) + get_local $0 + i32.const 1 + i32.add + i32.load8_s offset=8 + else + unreachable + end + tee_local $0 i32.const 255 i32.and i32.const 1 @@ -645,9 +675,21 @@ call $~lib/env/abort unreachable end - get_global $std/array-literal/dynamicArrayI8 i32.const 2 - call $~lib/array/Array#__get + get_global $std/array-literal/dynamicArrayI8 + i32.load + tee_local $0 + i32.load + i32.lt_u + if (result i32) + get_local $0 + i32.const 2 + i32.add + i32.load8_s offset=8 + else + unreachable + end + tee_local $0 i32.const 255 i32.and i32.const 2 @@ -664,25 +706,29 @@ set_global $std/array-literal/i call $~lib/array/Array#constructor tee_local $0 - i32.const 0 + i32.load get_global $std/array-literal/i - call $~lib/array/Array#__unchecked_set + i32.store offset=8 get_global $std/array-literal/i i32.const 1 i32.add set_global $std/array-literal/i get_local $0 - i32.const 1 + i32.load + i32.const 4 + i32.add get_global $std/array-literal/i - call $~lib/array/Array#__unchecked_set + i32.store offset=8 get_global $std/array-literal/i i32.const 1 i32.add set_global $std/array-literal/i get_local $0 - i32.const 2 + i32.load + i32.const 8 + i32.add get_global $std/array-literal/i - call $~lib/array/Array#__unchecked_set + i32.store offset=8 get_local $0 set_global $std/array-literal/dynamicArrayI32 get_global $std/array-literal/dynamicArrayI32 @@ -697,9 +743,21 @@ call $~lib/env/abort unreachable end - get_global $std/array-literal/dynamicArrayI32 i32.const 0 - call $~lib/array/Array#__get + get_global $std/array-literal/dynamicArrayI32 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 if i32.const 0 i32.const 32 @@ -708,9 +766,23 @@ call $~lib/env/abort unreachable end - get_global $std/array-literal/dynamicArrayI32 i32.const 1 - call $~lib/array/Array#__get + get_global $std/array-literal/dynamicArrayI32 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 1 i32.ne if @@ -721,9 +793,23 @@ call $~lib/env/abort unreachable end - get_global $std/array-literal/dynamicArrayI32 i32.const 2 - call $~lib/array/Array#__get + get_global $std/array-literal/dynamicArrayI32 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 2 i32.ne if @@ -735,29 +821,33 @@ unreachable end call $~lib/array/Array#constructor + set_local $0 + i32.const 0 + call $~lib/allocator/arena/__memory_allocate set_local $1 - i32.const 0 - call $~lib/memory/memory.allocate - set_local $0 - get_local $1 - i32.const 0 get_local $0 - call $~lib/array/Array#__unchecked_set + i32.load + get_local $1 + i32.store offset=8 i32.const 0 - call $~lib/memory/memory.allocate - set_local $0 - get_local $1 - i32.const 1 + call $~lib/allocator/arena/__memory_allocate + set_local $1 get_local $0 - call $~lib/array/Array#__unchecked_set + i32.load + i32.const 4 + i32.add + get_local $1 + i32.store offset=8 i32.const 0 - call $~lib/memory/memory.allocate - set_local $0 - get_local $1 - i32.const 2 + call $~lib/allocator/arena/__memory_allocate + set_local $1 get_local $0 - call $~lib/array/Array#__unchecked_set + i32.load + i32.const 8 + i32.add get_local $1 + i32.store offset=8 + get_local $0 set_global $std/array-literal/dynamicArrayRef get_global $std/array-literal/dynamicArrayRef i32.load offset=4 @@ -773,24 +863,31 @@ end call $~lib/array/Array#constructor set_local $0 - call $std/array-literal/RefWithCtor#constructor - set_local $1 - get_local $0 i32.const 0 - get_local $1 - call $~lib/array/Array#__unchecked_set - call $std/array-literal/RefWithCtor#constructor + call $~lib/allocator/arena/__memory_allocate set_local $1 get_local $0 - i32.const 1 + i32.load get_local $1 - call $~lib/array/Array#__unchecked_set - call $std/array-literal/RefWithCtor#constructor + i32.store offset=8 + i32.const 0 + call $~lib/allocator/arena/__memory_allocate set_local $1 get_local $0 - i32.const 2 + i32.load + i32.const 4 + i32.add get_local $1 - call $~lib/array/Array#__unchecked_set + i32.store offset=8 + i32.const 0 + call $~lib/allocator/arena/__memory_allocate + set_local $1 + get_local $0 + i32.load + i32.const 8 + i32.add + get_local $1 + i32.store offset=8 get_local $0 set_global $std/array-literal/dynamicArrayRefWithCtor get_global $std/array-literal/dynamicArrayRefWithCtor @@ -806,7 +903,7 @@ unreachable end ) - (func $null (; 14 ;) (type $v) + (func $null (; 7 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/array.optimized.wat b/tests/compiler/std/array.optimized.wat index f0806a2d..a56f6263 100644 --- a/tests/compiler/std/array.optimized.wat +++ b/tests/compiler/std/array.optimized.wat @@ -7,15 +7,11 @@ (type $iiii (func (param i32 i32 i32) (result i32))) (type $iiv (func (param i32 i32))) (type $iiif (func (param i32 i32 i32) (result f32))) - (type $iif (func (param i32 i32) (result f32))) (type $F (func (result f64))) (type $Iv (func (param i64))) - (type $II (func (param i64) (result i64))) (type $ffi (func (param f32 f32) (result i32))) (type $iv (func (param i32))) - (type $fi (func (param f32) (result i32))) (type $FFi (func (param f64 f64) (result i32))) - (type $iiF (func (param i32 i32) (result f64))) (type $Fi (func (param f64) (result i32))) (type $iiiiiv (func (param i32 i32 i32 i32 i32))) (type $iFi (func (param i32 f64) (result i32))) @@ -30,7 +26,6 @@ (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$viii (func (param i32 i32 i32))) - (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (import "Math" "random" (func $~lib/bindings/Math/random (result f64))) @@ -278,17 +273,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/internal/arraybuffer/computeSize (; 2 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/allocator/arena/__memory_allocate (; 3 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/__memory_allocate (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -350,7 +335,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -363,19 +348,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/memory/memory.allocate (; 5 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - call $~lib/allocator/arena/__memory_allocate - ) - (func $~lib/internal/memory/memset (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i64) get_local $2 @@ -610,7 +597,7 @@ end end ) - (func $~lib/array/Array#constructor (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -632,7 +619,7 @@ call $~lib/internal/arraybuffer/allocateUnsafe set_local $2 i32.const 8 - call $~lib/memory/memory.allocate + call $~lib/allocator/arena/__memory_allocate tee_local $1 i32.const 0 i32.store @@ -653,7 +640,7 @@ call $~lib/internal/memory/memset get_local $1 ) - (func $~lib/array/Array#fill (; 8 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $~lib/array/Array#fill (; 6 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (local $4 i32) (local $5 i32) (local $6 i32) @@ -724,31 +711,14 @@ end get_local $0 ) - (func $~lib/array/Array#__get (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.lt_u - if (result i32) - get_local $0 - get_local $1 - i32.add - i32.load8_u offset=8 - else - unreachable - end - tee_local $0 - ) - (func $std/array/isArraysEqual (; 10 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isArraysEqual (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) get_local $0 i32.load offset=4 - tee_local $3 + tee_local $4 get_local $1 i32.load offset=4 i32.ne @@ -766,29 +736,53 @@ block $break|0 loop $repeat|0 get_local $2 - get_local $3 + get_local $4 i32.ge_s br_if $break|0 + get_local $2 get_local $0 - get_local $2 - call $~lib/array/Array#__get - i32.const 255 - i32.and - set_local $4 - get_local $1 - get_local $2 - call $~lib/array/Array#__get + i32.load + tee_local $3 + i32.load + i32.lt_u + if (result i32) + get_local $3 + get_local $2 + i32.add + i32.load8_u offset=8 + else + unreachable + end + tee_local $3 i32.const 255 i32.and set_local $5 - get_local $4 + get_local $2 + tee_local $3 + get_local $1 + i32.load + tee_local $2 + i32.load + i32.lt_u + if (result i32) + get_local $2 + get_local $3 + i32.add + i32.load8_u offset=8 + else + unreachable + end + set_local $2 get_local $5 + get_local $2 + i32.const 255 + i32.and i32.ne if i32.const 0 return else - get_local $2 + get_local $3 i32.const 1 i32.add set_local $2 @@ -801,7 +795,7 @@ end i32.const 1 ) - (func $~lib/array/Array#fill|trampoline (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#fill|trampoline (; 8 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) block $2of2 block $1of2 @@ -826,7 +820,7 @@ get_local $3 call $~lib/array/Array#fill ) - (func $~lib/array/Array#fill (; 12 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $~lib/array/Array#fill (; 9 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (local $4 i32) (local $5 i32) (local $6 i32) @@ -906,28 +900,7 @@ end get_local $0 ) - (func $~lib/array/Array#__get (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.const 2 - i32.shr_u - i32.lt_u - if (result i32) - get_local $0 - get_local $1 - i32.const 2 - i32.shl - i32.add - i32.load offset=8 - else - unreachable - end - tee_local $0 - ) - (func $std/array/isArraysEqual (; 14 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $std/array/isArraysEqual (; 10 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -958,22 +931,54 @@ get_local $2 i32.ge_s br_if $break|0 + get_local $3 get_local $0 - get_local $3 - call $~lib/array/Array#__get - set_local $4 - get_local $1 - get_local $3 - call $~lib/array/Array#__get + i32.load + tee_local $4 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $4 + get_local $3 + i32.const 2 + i32.shl + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $4 set_local $5 - get_local $4 + get_local $3 + tee_local $4 + get_local $1 + i32.load + tee_local $3 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $3 + get_local $4 + i32.const 2 + i32.shl + i32.add + i32.load offset=8 + else + unreachable + end + set_local $3 get_local $5 + get_local $3 i32.ne if i32.const 0 return else - get_local $3 + get_local $4 i32.const 1 i32.add set_local $3 @@ -986,7 +991,7 @@ end i32.const 1 ) - (func $~lib/array/Array#fill|trampoline (; 15 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#fill|trampoline (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) block $2of2 block $1of2 @@ -1011,14 +1016,7 @@ get_local $3 call $~lib/array/Array#fill ) - (func $std/array/internalCapacity (; 16 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.load - i32.const 2 - i32.shr_s - ) - (func $~lib/internal/memory/memcpy (; 17 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 12 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1922,7 +1920,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 18 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 13 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) get_local $0 @@ -2122,9 +2120,10 @@ end end ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateUnsafe (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) + (local $4 i32) get_local $1 get_local $0 i32.load @@ -2142,11 +2141,15 @@ call $~lib/env/abort unreachable end - get_local $2 - call $~lib/internal/arraybuffer/computeSize - set_local $3 get_local $1 - get_local $3 + i32.const 1 + i32.const 32 + get_local $2 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl i32.const 8 i32.sub i32.le_s @@ -2170,14 +2173,13 @@ tee_local $3 i32.const 8 i32.add + tee_local $4 get_local $0 i32.const 8 i32.add get_local $2 call $~lib/internal/memory/memmove - get_local $3 - i32.const 8 - i32.add + get_local $4 get_local $2 i32.add i32.const 0 @@ -2211,26 +2213,26 @@ end get_local $0 ) - (func $~lib/array/Array#push (; 20 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#push (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) get_local $0 i32.load offset=4 - tee_local $3 + tee_local $2 i32.const 1 i32.add - set_local $4 - get_local $3 + set_local $3 + get_local $2 get_local $0 i32.load - tee_local $2 + tee_local $4 i32.load i32.const 2 i32.shr_u i32.ge_u if - get_local $3 + get_local $2 i32.const 268435454 i32.ge_u if @@ -2241,29 +2243,28 @@ call $~lib/env/abort unreachable end - get_local $2 + get_local $0 get_local $4 + get_local $3 i32.const 2 i32.shl call $~lib/internal/arraybuffer/reallocateUnsafe - set_local $2 - get_local $0 - get_local $2 + tee_local $4 i32.store end get_local $0 - get_local $4 - i32.store offset=4 - get_local $2 get_local $3 + i32.store offset=4 + get_local $4 + get_local $2 i32.const 2 i32.shl i32.add get_local $1 i32.store offset=8 - get_local $4 + get_local $3 ) - (func $~lib/array/Array#pop (; 21 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/array/Array#pop (; 16 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -2295,7 +2296,7 @@ i32.store offset=4 get_local $2 ) - (func $~lib/array/Array#concat (; 22 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#concat (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2349,7 +2350,7 @@ end get_local $3 ) - (func $~lib/array/Array#unshift (; 23 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#unshift (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2415,7 +2416,7 @@ i32.store offset=4 get_local $3 ) - (func $~lib/array/Array#shift (; 24 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/array/Array#shift (; 19 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -2462,7 +2463,7 @@ i32.store offset=4 get_local $3 ) - (func $~lib/array/Array#reverse (; 25 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/array/Array#reverse (; 20 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -2522,7 +2523,7 @@ end get_local $0 ) - (func $~lib/array/Array#indexOf (; 26 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#indexOf (; 21 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -2586,7 +2587,7 @@ end i32.const -1 ) - (func $~lib/array/Array#splice (; 27 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/array/Array#splice (; 22 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) (local $2 i32) i32.const 1 @@ -2630,8 +2631,9 @@ i32.sub i32.store offset=4 ) - (func $~lib/array/Array#__set (; 28 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 23 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) + (local $4 i32) get_local $1 get_local $0 i32.load @@ -2652,21 +2654,19 @@ call $~lib/env/abort unreachable end + get_local $0 get_local $3 get_local $1 i32.const 1 i32.add + tee_local $4 i32.const 2 i32.shl call $~lib/internal/arraybuffer/reallocateUnsafe - set_local $3 - get_local $0 - get_local $3 + tee_local $3 i32.store get_local $0 - get_local $1 - i32.const 1 - i32.add + get_local $4 i32.store offset=4 end get_local $3 @@ -2677,11 +2677,11 @@ get_local $2 i32.store offset=8 ) - (func $start~anonymous|1 (; 29 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|1 (; 24 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.eqz ) - (func $~lib/array/Array#findIndex (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#findIndex (; 25 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2739,17 +2739,17 @@ end i32.const -1 ) - (func $start~anonymous|2 (; 31 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|2 (; 26 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const 1 i32.eq ) - (func $start~anonymous|3 (; 32 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|3 (; 27 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const 100 i32.eq ) - (func $start~anonymous|4 (; 33 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|4 (; 28 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 i32.const 100 call $~lib/array/Array#push @@ -2758,7 +2758,7 @@ i32.const 100 i32.eq ) - (func $start~anonymous|6 (; 34 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|6 (; 29 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 call $~lib/array/Array#pop drop @@ -2766,12 +2766,12 @@ i32.const 100 i32.eq ) - (func $start~anonymous|7 (; 35 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|7 (; 30 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const 0 i32.ge_s ) - (func $~lib/array/Array#every (; 36 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#every (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2829,12 +2829,12 @@ end i32.const 1 ) - (func $start~anonymous|8 (; 37 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|8 (; 32 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const 0 i32.le_s ) - (func $start~anonymous|9 (; 38 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|9 (; 33 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 i32.const 100 call $~lib/array/Array#push @@ -2843,12 +2843,12 @@ i32.const 10 i32.lt_s ) - (func $start~anonymous|10 (; 39 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|10 (; 34 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const 10 i32.lt_s ) - (func $start~anonymous|11 (; 40 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|11 (; 35 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 call $~lib/array/Array#pop drop @@ -2856,12 +2856,12 @@ i32.const 3 i32.lt_s ) - (func $start~anonymous|12 (; 41 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|12 (; 36 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const 3 i32.ge_s ) - (func $~lib/array/Array#some (; 42 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#some (; 37 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2919,12 +2919,12 @@ end i32.const 0 ) - (func $start~anonymous|13 (; 43 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|13 (; 38 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const -1 i32.le_s ) - (func $start~anonymous|14 (; 44 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|14 (; 39 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 i32.const 100 call $~lib/array/Array#push @@ -2933,12 +2933,12 @@ i32.const 10 i32.gt_s ) - (func $start~anonymous|15 (; 45 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|15 (; 40 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const 10 i32.gt_s ) - (func $start~anonymous|16 (; 46 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|16 (; 41 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 call $~lib/array/Array#pop drop @@ -2946,13 +2946,13 @@ i32.const 3 i32.gt_s ) - (func $start~anonymous|17 (; 47 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $start~anonymous|17 (; 42 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) get_global $std/array/i get_local $0 i32.add set_global $std/array/i ) - (func $~lib/array/Array#forEach (; 48 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/array/Array#forEach (; 43 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3001,7 +3001,7 @@ unreachable end ) - (func $start~anonymous|18 (; 49 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $start~anonymous|18 (; 44 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) get_local $2 i32.const 100 call $~lib/array/Array#push @@ -3011,7 +3011,7 @@ i32.add set_global $std/array/i ) - (func $start~anonymous|20 (; 50 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $start~anonymous|20 (; 45 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) get_local $2 call $~lib/array/Array#pop drop @@ -3020,11 +3020,11 @@ i32.add set_global $std/array/i ) - (func $start~anonymous|21 (; 51 ;) (type $iiif) (param $0 i32) (param $1 i32) (param $2 i32) (result f32) + (func $start~anonymous|21 (; 46 ;) (type $iiif) (param $0 i32) (param $1 i32) (param $2 i32) (result f32) get_local $0 f32.convert_s/i32 ) - (func $~lib/array/Array#map (; 52 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#map (; 47 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -3085,27 +3085,7 @@ end get_local $5 ) - (func $~lib/array/Array#__get (; 53 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.const 2 - i32.shr_u - i32.lt_u - if (result f32) - get_local $0 - get_local $1 - i32.const 2 - i32.shl - i32.add - f32.load offset=8 - else - unreachable - end - ) - (func $start~anonymous|22 (; 54 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|22 (; 48 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 i32.const 100 call $~lib/array/Array#push @@ -3116,7 +3096,7 @@ set_global $std/array/i get_local $0 ) - (func $~lib/array/Array#map (; 55 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#map (; 49 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3178,14 +3158,14 @@ end get_local $6 ) - (func $start~anonymous|23 (; 56 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|23 (; 50 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_global $std/array/i get_local $0 i32.add set_global $std/array/i get_local $0 ) - (func $start~anonymous|24 (; 57 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|24 (; 51 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 call $~lib/array/Array#pop drop @@ -3195,12 +3175,12 @@ set_global $std/array/i get_local $0 ) - (func $start~anonymous|25 (; 58 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|25 (; 52 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.const 2 i32.ge_s ) - (func $~lib/array/Array#filter (; 59 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#filter (; 53 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3264,7 +3244,7 @@ end get_local $4 ) - (func $start~anonymous|26 (; 60 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|26 (; 54 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 i32.const 100 call $~lib/array/Array#push @@ -3277,7 +3257,7 @@ i32.const 2 i32.ge_s ) - (func $start~anonymous|27 (; 61 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|27 (; 55 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_global $std/array/i get_local $0 i32.add @@ -3286,7 +3266,7 @@ i32.const 2 i32.ge_s ) - (func $start~anonymous|28 (; 62 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $start~anonymous|28 (; 56 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $2 call $~lib/array/Array#pop drop @@ -3298,12 +3278,12 @@ i32.const 2 i32.ge_s ) - (func $start~anonymous|29 (; 63 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|29 (; 57 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) get_local $0 get_local $1 i32.add ) - (func $~lib/array/Array#reduce (; 64 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#reduce (; 58 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -3355,7 +3335,7 @@ end get_local $2 ) - (func $start~anonymous|31 (; 65 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|31 (; 59 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) get_local $0 i32.const 1 i32.and @@ -3367,7 +3347,7 @@ i32.gt_s end ) - (func $start~anonymous|32 (; 66 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|32 (; 60 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) get_local $0 i32.const 1 i32.and @@ -3379,7 +3359,7 @@ i32.gt_s end ) - (func $start~anonymous|33 (; 67 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|33 (; 61 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) get_local $3 i32.const 1 call $~lib/array/Array#push @@ -3388,7 +3368,7 @@ get_local $1 i32.add ) - (func $start~anonymous|35 (; 68 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $start~anonymous|35 (; 62 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) get_local $3 call $~lib/array/Array#pop drop @@ -3396,7 +3376,7 @@ get_local $1 i32.add ) - (func $~lib/array/Array#reduceRight (; 69 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/array/Array#reduceRight (; 63 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -3438,28 +3418,7 @@ end get_local $2 ) - (func $~lib/math/murmurHash3 (; 70 ;) (type $II) (param $0 i64) (result i64) - get_local $0 - get_local $0 - i64.const 33 - i64.shr_u - i64.xor - i64.const -49064778989728563 - i64.mul - tee_local $0 - get_local $0 - i64.const 33 - i64.shr_u - i64.xor - i64.const -4265267296055464877 - i64.mul - tee_local $0 - get_local $0 - i64.const 33 - i64.shr_u - i64.xor - ) - (func $~lib/math/splitMix32 (; 71 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/math/splitMix32 (; 64 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 1831565813 i32.add @@ -3491,7 +3450,8 @@ i32.shr_u i32.xor ) - (func $~lib/math/NativeMath.seedRandom (; 72 ;) (type $Iv) (param $0 i64) + (func $~lib/math/NativeMath.seedRandom (; 65 ;) (type $Iv) (param $0 i64) + (local $1 i64) get_local $0 i64.eqz if @@ -3505,12 +3465,47 @@ i32.const 1 set_global $~lib/math/random_seeded get_local $0 - call $~lib/math/murmurHash3 + get_local $0 + i64.const 33 + i64.shr_u + i64.xor + i64.const -49064778989728563 + i64.mul + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor + i64.const -4265267296055464877 + i64.mul + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor set_global $~lib/math/random_state0_64 get_global $~lib/math/random_state0_64 i64.const -1 i64.xor - call $~lib/math/murmurHash3 + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor + i64.const -49064778989728563 + i64.mul + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor + i64.const -4265267296055464877 + i64.mul + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor set_global $~lib/math/random_state1_64 get_local $0 i32.wrap/i64 @@ -3520,7 +3515,7 @@ call $~lib/math/splitMix32 set_global $~lib/math/random_state1_32 ) - (func $~lib/internal/array/insertionSort (; 73 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/array/insertionSort (; 66 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 f32) @@ -3602,10 +3597,7 @@ unreachable end ) - (func $~lib/allocator/arena/__memory_free (; 74 ;) (type $FUNCSIG$v) - nop - ) - (func $~lib/internal/array/weakHeapSort (; 75 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/array/weakHeapSort (; 67 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -3856,7 +3848,6 @@ end unreachable end - call $~lib/allocator/arena/__memory_free get_local $0 i32.const 4 i32.add @@ -3871,7 +3862,7 @@ get_local $6 f32.store offset=8 ) - (func $~lib/array/Array#sort (; 76 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#sort (; 68 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 f32) @@ -3947,7 +3938,7 @@ end get_local $0 ) - (func $~lib/array/Array#sort|trampoline~anonymous|43 (; 77 ;) (type $ffi) (param $0 f32) (param $1 f32) (result i32) + (func $~lib/array/Array#sort|trampoline~anonymous|43 (; 69 ;) (type $ffi) (param $0 f32) (param $1 f32) (result i32) (local $2 i32) (local $3 i32) get_local $0 @@ -3976,38 +3967,16 @@ i32.lt_s i32.sub ) - (func $~lib/array/Array#sort|trampoline (; 78 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - block $1of1 - block $0of1 - block $outOfRange - get_global $~argc - br_table $0of1 $1of1 $outOfRange - end - unreachable - end - i32.const 43 - set_local $1 - end - get_local $0 - get_local $1 - call $~lib/array/Array#sort - ) - (func $~lib/builtins/isNaN (; 79 ;) (type $fi) (param $0 f32) (result i32) - get_local $0 - get_local $0 - f32.ne - ) - (func $std/array/isArraysEqual (; 80 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/array/isArraysEqual (; 70 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (local $3 i32) + (local $3 f32) (local $4 i32) - (local $5 f32) + (local $5 i32) (local $6 f32) get_local $0 i32.load offset=4 - tee_local $2 + tee_local $5 i32.const 900 i32.load i32.ne @@ -4026,32 +3995,97 @@ loop $repeat|0 block $continue|0 get_local $1 - get_local $2 + get_local $5 i32.ge_s br_if $break|0 + get_local $1 + tee_local $2 get_local $0 - get_local $1 - call $~lib/array/Array#__get - call $~lib/builtins/isNaN - set_local $3 - i32.const 896 - get_local $1 - call $~lib/array/Array#__get - call $~lib/builtins/isNaN - set_local $4 + i32.load + tee_local $4 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result f32) + get_local $4 + get_local $2 + i32.const 2 + i32.shl + i32.add + f32.load offset=8 + else + unreachable + end + tee_local $3 get_local $3 + f32.ne + set_local $4 + get_local $1 + i32.const 896 + i32.load + tee_local $2 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result f32) + get_local $2 + get_local $1 + i32.const 2 + i32.shl + i32.add + f32.load offset=8 + else + unreachable + end + set_local $3 get_local $4 + get_local $3 + get_local $3 + f32.ne i32.eq br_if $continue|0 + get_local $1 + tee_local $2 get_local $0 + i32.load + tee_local $4 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result f32) + get_local $4 + get_local $2 + i32.const 2 + i32.shl + i32.add + f32.load offset=8 + else + unreachable + end + set_local $3 get_local $1 - call $~lib/array/Array#__get - set_local $5 i32.const 896 - get_local $1 - call $~lib/array/Array#__get + i32.load + tee_local $2 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result f32) + get_local $2 + get_local $1 + i32.const 2 + i32.shl + i32.add + f32.load offset=8 + else + unreachable + end set_local $6 - get_local $5 + get_local $3 get_local $6 f32.ne if @@ -4070,7 +4104,7 @@ end i32.const 1 ) - (func $~lib/internal/array/insertionSort (; 81 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/array/insertionSort (; 71 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 f64) @@ -4152,7 +4186,7 @@ unreachable end ) - (func $~lib/internal/array/weakHeapSort (; 82 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/array/weakHeapSort (; 72 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -4403,7 +4437,6 @@ end unreachable end - call $~lib/allocator/arena/__memory_free get_local $0 i32.const 8 i32.add @@ -4418,7 +4451,7 @@ get_local $6 f64.store offset=8 ) - (func $~lib/array/Array#sort (; 83 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#sort (; 73 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 f64) @@ -4494,7 +4527,7 @@ end get_local $0 ) - (func $~lib/array/Array#sort|trampoline~anonymous|44 (; 84 ;) (type $FFi) (param $0 f64) (param $1 f64) (result i32) + (func $~lib/array/Array#sort|trampoline~anonymous|44 (; 74 ;) (type $FFi) (param $0 f64) (param $1 f64) (result i32) (local $2 i64) (local $3 i64) get_local $0 @@ -4523,58 +4556,16 @@ i64.lt_s i32.sub ) - (func $~lib/array/Array#sort|trampoline (; 85 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - block $1of1 - block $0of1 - block $outOfRange - get_global $~argc - br_table $0of1 $1of1 $outOfRange - end - unreachable - end - i32.const 44 - set_local $1 - end - get_local $0 - get_local $1 - call $~lib/array/Array#sort - ) - (func $~lib/array/Array#__get (; 86 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.const 3 - i32.shr_u - i32.lt_u - if (result f64) - get_local $0 - get_local $1 - i32.const 3 - i32.shl - i32.add - f64.load offset=8 - else - unreachable - end - ) - (func $~lib/builtins/isNaN (; 87 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.ne - ) - (func $std/array/isArraysEqual (; 88 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $std/array/isArraysEqual (; 75 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (local $3 i32) + (local $3 f64) (local $4 i32) - (local $5 f64) + (local $5 i32) (local $6 f64) get_local $0 i32.load offset=4 - tee_local $2 + tee_local $5 i32.const 1172 i32.load i32.ne @@ -4593,32 +4584,97 @@ loop $repeat|0 block $continue|0 get_local $1 - get_local $2 + get_local $5 i32.ge_s br_if $break|0 + get_local $1 + tee_local $2 get_local $0 - get_local $1 - call $~lib/array/Array#__get - call $~lib/builtins/isNaN - set_local $3 - i32.const 1168 - get_local $1 - call $~lib/array/Array#__get - call $~lib/builtins/isNaN - set_local $4 + i32.load + tee_local $4 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result f64) + get_local $4 + get_local $2 + i32.const 3 + i32.shl + i32.add + f64.load offset=8 + else + unreachable + end + tee_local $3 get_local $3 + f64.ne + set_local $4 + get_local $1 + i32.const 1168 + i32.load + tee_local $2 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result f64) + get_local $2 + get_local $1 + i32.const 3 + i32.shl + i32.add + f64.load offset=8 + else + unreachable + end + set_local $3 get_local $4 + get_local $3 + get_local $3 + f64.ne i32.eq br_if $continue|0 + get_local $1 + tee_local $2 get_local $0 + i32.load + tee_local $4 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result f64) + get_local $4 + get_local $2 + i32.const 3 + i32.shl + i32.add + f64.load offset=8 + else + unreachable + end + set_local $3 get_local $1 - call $~lib/array/Array#__get - set_local $5 i32.const 1168 - get_local $1 - call $~lib/array/Array#__get + i32.load + tee_local $2 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result f64) + get_local $2 + get_local $1 + i32.const 3 + i32.shl + i32.add + f64.load offset=8 + else + unreachable + end set_local $6 - get_local $5 + get_local $3 get_local $6 f64.ne if @@ -4637,7 +4693,7 @@ end i32.const 1 ) - (func $~lib/internal/array/insertionSort (; 89 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/array/insertionSort (; 76 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -4721,7 +4777,7 @@ unreachable end ) - (func $~lib/internal/array/weakHeapSort (; 90 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/array/weakHeapSort (; 77 ;) (type $FUNCSIG$viii) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -4972,7 +5028,6 @@ end unreachable end - call $~lib/allocator/arena/__memory_free get_local $0 i32.const 4 i32.add @@ -4987,7 +5042,7 @@ get_local $1 i32.store offset=8 ) - (func $~lib/array/Array#sort (; 91 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#sort (; 78 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5062,29 +5117,12 @@ end get_local $0 ) - (func $~lib/array/Array#sort|trampoline~anonymous|45 (; 92 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#sort|trampoline~anonymous|45 (; 79 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 i32.sub ) - (func $~lib/array/Array#sort|trampoline (; 93 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - block $1of1 - block $0of1 - block $outOfRange - get_global $~argc - br_table $0of1 $1of1 $outOfRange - end - unreachable - end - i32.const 45 - set_local $1 - end - get_local $0 - get_local $1 - call $~lib/array/Array#sort - ) - (func $~lib/array/Array#sort|trampoline~anonymous|46 (; 94 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#sort|trampoline~anonymous|46 (; 80 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 i32.gt_u @@ -5093,24 +5131,7 @@ i32.lt_u i32.sub ) - (func $~lib/array/Array#sort|trampoline (; 95 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - block $1of1 - block $0of1 - block $outOfRange - get_global $~argc - br_table $0of1 $1of1 $outOfRange - end - unreachable - end - i32.const 46 - set_local $1 - end - get_local $0 - get_local $1 - call $~lib/array/Array#sort - ) - (func $std/array/createReverseOrderedArray (; 96 ;) (type $ii) (param $0 i32) (result i32) + (func $std/array/createReverseOrderedArray (; 81 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 call $~lib/array/Array#constructor @@ -5144,7 +5165,7 @@ end get_local $1 ) - (func $~lib/math/NativeMath.random (; 97 ;) (type $F) (result f64) + (func $~lib/math/NativeMath.random (; 82 ;) (type $F) (result f64) (local $0 i64) (local $1 i64) get_global $~lib/math/random_seeded @@ -5191,9 +5212,8 @@ f64.const 1 f64.sub ) - (func $std/array/createRandomOrderedArray (; 98 ;) (type $ii) (param $0 i32) (result i32) + (func $std/array/createRandomOrderedArray (; 83 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) - (local $2 f64) get_local $0 call $~lib/array/Array#constructor set_local $0 @@ -5204,11 +5224,9 @@ i32.load offset=4 i32.ge_s br_if $break|0 - call $~lib/math/NativeMath.random - set_local $2 get_local $0 get_local $1 - get_local $2 + call $~lib/math/NativeMath.random get_local $0 i32.load offset=4 f64.convert_s/i32 @@ -5226,7 +5244,7 @@ end get_local $0 ) - (func $std/array/isSorted (; 99 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isSorted (; 84 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5236,26 +5254,58 @@ set_local $2 get_local $0 i32.load offset=4 - set_local $3 + set_local $5 loop $repeat|0 get_local $2 - get_local $3 + get_local $5 i32.ge_s br_if $break|0 i32.const 2 set_global $~argc - get_local $0 get_local $2 i32.const 1 i32.sub - call $~lib/array/Array#__get - set_local $4 + tee_local $4 get_local $0 + i32.load + tee_local $3 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $3 + get_local $4 + i32.const 2 + i32.shl + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $3 + set_local $4 get_local $2 - call $~lib/array/Array#__get - set_local $5 + get_local $0 + i32.load + tee_local $3 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $3 + get_local $2 + i32.const 2 + i32.shl + i32.add + i32.load offset=8 + else + unreachable + end + set_local $3 get_local $4 - get_local $5 + get_local $3 get_local $1 call_indirect (type $iii) i32.const 0 @@ -5277,7 +5327,7 @@ end i32.const 1 ) - (func $std/array/assertSorted (; 100 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $std/array/assertSorted (; 85 ;) (type $iiv) (param $0 i32) (param $1 i32) get_local $0 get_local $1 call $~lib/array/Array#sort @@ -5293,17 +5343,17 @@ unreachable end ) - (func $std/array/assertSortedDefault (; 101 ;) (type $iv) (param $0 i32) + (func $std/array/assertSortedDefault (; 86 ;) (type $iv) (param $0 i32) get_local $0 i32.const 47 call $std/array/assertSorted ) - (func $start~anonymous|49 (; 102 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $start~anonymous|49 (; 87 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $1 get_local $0 i32.sub ) - (func $std/array/createReverseOrderedNestedArray (; 103 ;) (type $FUNCSIG$i) (result i32) + (func $std/array/createReverseOrderedNestedArray (; 88 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -5317,16 +5367,29 @@ i32.load offset=4 i32.ge_s br_if $break|0 + get_local $1 + get_local $0 i32.const 1 call $~lib/array/Array#constructor - set_local $2 - get_local $1 - get_local $0 - get_local $2 call $~lib/array/Array#__set - get_local $1 get_local $0 - call $~lib/array/Array#__get + get_local $1 + i32.load + tee_local $2 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $2 + get_local $0 + i32.const 2 + i32.shl + i32.add + i32.load offset=8 + else + unreachable + end tee_local $2 i32.const 0 get_local $1 @@ -5347,20 +5410,44 @@ end get_local $1 ) - (func $start~anonymous|52 (; 104 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 + (func $start~anonymous|52 (; 89 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) i32.const 0 - call $~lib/array/Array#__get + get_local $0 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 + set_local $2 + i32.const 0 + get_local $1 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end set_local $0 - get_local $1 - i32.const 0 - call $~lib/array/Array#__get - set_local $1 + get_local $2 get_local $0 - get_local $1 i32.sub ) - (func $~lib/array/Array>#sort (; 105 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array>#sort (; 90 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5425,7 +5512,7 @@ call $~lib/internal/array/insertionSort get_local $0 ) - (func $std/array/assertSorted> (; 106 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $std/array/assertSorted> (; 91 ;) (type $iiv) (param $0 i32) (param $1 i32) get_local $0 get_local $1 call $~lib/array/Array>#sort @@ -5441,60 +5528,56 @@ unreachable end ) - (func $std/array/Proxy#constructor (; 107 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - i32.const 4 - call $~lib/memory/memory.allocate - tee_local $1 - get_local $0 - i32.store - get_local $1 - ) - (func $std/array/createReverseOrderedElementsArray (; 108 ;) (type $FUNCSIG$i) (result i32) + (func $std/array/createReverseOrderedElementsArray (; 92 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) + (local $3 i32) i32.const 512 call $~lib/array/Array#constructor - set_local $1 + set_local $0 block $break|0 loop $repeat|0 - get_local $0 get_local $1 + get_local $0 i32.load offset=4 i32.ge_s br_if $break|0 - get_local $1 + get_local $0 i32.load offset=4 i32.const 1 i32.sub - get_local $0 - i32.sub - call $std/array/Proxy#constructor - set_local $2 get_local $1 - get_local $0 + i32.sub + set_local $2 + i32.const 4 + call $~lib/allocator/arena/__memory_allocate + tee_local $3 get_local $2 - call $~lib/array/Array#__set + i32.store get_local $0 + get_local $1 + get_local $3 + call $~lib/array/Array#__set + get_local $1 i32.const 1 i32.add - set_local $0 + set_local $1 br $repeat|0 unreachable end unreachable end - get_local $1 + get_local $0 ) - (func $start~anonymous|53 (; 109 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $start~anonymous|53 (; 93 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 i32.load get_local $1 i32.load i32.sub ) - (func $~lib/internal/string/compareUnsafe (; 110 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/string/compareUnsafe (; 94 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -5531,7 +5614,7 @@ end get_local $4 ) - (func $~lib/string/String.__gt (; 111 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__gt (; 95 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) get_local $0 @@ -5585,7 +5668,7 @@ i32.const 0 i32.gt_s ) - (func $~lib/string/String.__lt (; 112 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__lt (; 96 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) get_local $0 @@ -5639,21 +5722,16 @@ i32.const 0 i32.lt_s ) - (func $start~anonymous|54 (; 113 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) + (func $start~anonymous|54 (; 97 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 call $~lib/string/String.__gt - set_local $2 get_local $0 get_local $1 call $~lib/string/String.__lt - set_local $0 - get_local $2 - get_local $0 i32.sub ) - (func $~lib/string/String.__eq (; 114 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 98 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 get_local $1 @@ -5692,20 +5770,14 @@ call $~lib/internal/string/compareUnsafe i32.eqz ) - (func $~lib/string/String.__ne (; 115 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - get_local $1 - call $~lib/string/String.__eq - i32.eqz - ) - (func $std/array/isArraysEqual (; 116 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/array/isArraysEqual (; 99 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) get_local $0 i32.load offset=4 - tee_local $3 + tee_local $4 get_local $1 i32.load offset=4 i32.ne @@ -5723,29 +5795,61 @@ block $break|0 loop $repeat|0 get_local $2 - get_local $3 + get_local $4 i32.ge_s br_if $break|0 + get_local $2 get_local $0 - get_local $2 - call $~lib/array/Array#__get - set_local $4 - get_local $1 - get_local $2 - call $~lib/array/Array#__get - set_local $5 - get_local $4 - get_local $5 - call $~lib/string/String.__ne - if - i32.const 0 - return - else + i32.load + tee_local $3 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $3 get_local $2 + i32.const 2 + i32.shl + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $3 + set_local $5 + get_local $2 + tee_local $3 + get_local $1 + i32.load + tee_local $2 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $2 + get_local $3 + i32.const 2 + i32.shl + i32.add + i32.load offset=8 + else + unreachable + end + set_local $2 + get_local $5 + get_local $2 + call $~lib/string/String.__eq + if + get_local $3 i32.const 1 i32.add set_local $2 br $repeat|0 + else + i32.const 0 + return end unreachable unreachable @@ -5754,7 +5858,7 @@ end i32.const 1 ) - (func $~lib/internal/string/allocateUnsafe (; 117 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/string/allocateUnsafe (; 100 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 0 @@ -5787,7 +5891,7 @@ i32.store get_local $1 ) - (func $~lib/string/String#charAt (; 118 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String#charAt (; 101 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 584 @@ -5809,7 +5913,7 @@ i32.store16 offset=4 get_local $1 ) - (func $~lib/internal/string/copyUnsafe (; 119 ;) (type $iiiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) + (func $~lib/internal/string/copyUnsafe (; 102 ;) (type $iiiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) get_local $0 get_local $1 i32.const 1 @@ -5829,7 +5933,7 @@ i32.shl call $~lib/internal/memory/memmove ) - (func $~lib/string/String#concat (; 120 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#concat (; 103 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5878,7 +5982,7 @@ call $~lib/internal/string/copyUnsafe get_local $2 ) - (func $~lib/string/String.__concat (; 121 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__concat (; 104 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 i32.eqz if @@ -5889,10 +5993,9 @@ get_local $1 call $~lib/string/String#concat ) - (func $std/array/createRandomString (; 122 ;) (type $ii) (param $0 i32) (result i32) + (func $std/array/createRandomString (; 105 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) - (local $3 i32) i32.const 1560 set_local $1 block $break|0 @@ -5901,6 +6004,7 @@ get_local $0 i32.ge_s br_if $break|0 + get_local $1 call $~lib/math/NativeMath.random i32.const 584 i32.load @@ -5909,9 +6013,6 @@ f64.floor i32.trunc_s/f64 call $~lib/string/String#charAt - set_local $3 - get_local $1 - get_local $3 call $~lib/string/String.__concat set_local $1 get_local $2 @@ -5925,10 +6026,9 @@ end get_local $1 ) - (func $std/array/createRandomStringArray (; 123 ;) (type $FUNCSIG$i) (result i32) + (func $std/array/createRandomStringArray (; 106 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) - (local $2 i32) i32.const 400 call $~lib/array/Array#constructor set_local $1 @@ -5939,15 +6039,13 @@ i32.load offset=4 i32.ge_s br_if $break|0 + get_local $1 + get_local $0 call $~lib/math/NativeMath.random f64.const 32 f64.mul i32.trunc_s/f64 call $std/array/createRandomString - set_local $2 - get_local $1 - get_local $0 - get_local $2 call $~lib/array/Array#__set get_local $0 i32.const 1 @@ -5960,7 +6058,7 @@ end get_local $1 ) - (func $~lib/string/String#substring (; 124 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#substring (; 107 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -6042,7 +6140,7 @@ call $~lib/internal/string/copyUnsafe get_local $2 ) - (func $~lib/array/Array#join (; 125 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/array/Array#join (; 108 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -6190,11 +6288,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end get_local $1 ) - (func $~lib/internal/number/decimalCount32 (; 126 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/number/decimalCount32 (; 109 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 100000 i32.lt_u @@ -6248,7 +6345,7 @@ end end ) - (func $~lib/internal/number/utoa32_lut (; 127 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/number/utoa32_lut (; 110 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) i32.const 2488 @@ -6358,7 +6455,7 @@ i32.store16 offset=4 end ) - (func $~lib/internal/number/itoa32 (; 128 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/number/itoa32 (; 111 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -6371,7 +6468,7 @@ get_local $0 i32.const 0 i32.lt_s - tee_local $2 + tee_local $1 if i32.const 0 get_local $0 @@ -6380,29 +6477,23 @@ end get_local $0 call $~lib/internal/number/decimalCount32 - tee_local $1 - get_local $2 + get_local $1 i32.add tee_local $3 call $~lib/internal/string/allocateUnsafe - tee_local $1 + tee_local $2 get_local $0 get_local $3 call $~lib/internal/number/utoa32_lut - get_local $2 + get_local $1 if - get_local $1 + get_local $2 i32.const 45 i32.store16 offset=4 end - get_local $1 + get_local $2 ) - (func $~lib/internal/number/itoa (; 129 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - call $~lib/internal/number/itoa32 - ) - (func $~lib/internal/number/itoa_stream (; 130 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) + (func $~lib/internal/number/itoa_stream (; 112 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 get_local $1 i32.const 1 @@ -6421,32 +6512,30 @@ get_local $2 i32.const 0 i32.lt_s - tee_local $3 + tee_local $1 if i32.const 0 get_local $2 i32.sub set_local $2 end - get_local $2 - call $~lib/internal/number/decimalCount32 - set_local $1 get_local $0 get_local $2 + get_local $2 + call $~lib/internal/number/decimalCount32 get_local $1 - get_local $3 i32.add - tee_local $1 + tee_local $2 call $~lib/internal/number/utoa32_lut - get_local $3 + get_local $1 if get_local $0 i32.const 45 i32.store16 offset=4 end - get_local $1 + get_local $2 ) - (func $~lib/array/Array#join (; 131 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#join (; 113 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -6454,7 +6543,6 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) get_local $0 i32.load offset=4 i32.const 1 @@ -6480,7 +6568,7 @@ if get_local $5 i32.load offset=8 - call $~lib/internal/number/itoa + call $~lib/internal/number/itoa32 return end get_local $6 @@ -6499,6 +6587,7 @@ get_local $4 i32.ge_s br_if $break|0 + get_local $2 get_local $0 get_local $2 get_local $5 @@ -6508,9 +6597,6 @@ i32.add i32.load offset=8 call $~lib/internal/number/itoa_stream - set_local $9 - get_local $2 - get_local $9 i32.add set_local $2 get_local $7 @@ -6536,6 +6622,10 @@ unreachable end get_local $0 + set_local $3 + get_local $8 + get_local $2 + get_local $0 get_local $2 get_local $5 get_local $4 @@ -6544,12 +6634,6 @@ i32.add i32.load offset=8 call $~lib/internal/number/itoa_stream - set_local $1 - get_local $0 - set_local $3 - get_local $8 - get_local $2 - get_local $1 i32.add tee_local $2 i32.gt_s @@ -6568,11 +6652,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end get_local $3 ) - (func $~lib/internal/number/utoa32 (; 132 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/number/utoa32 (; 114 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -6591,11 +6674,7 @@ call $~lib/internal/number/utoa32_lut get_local $2 ) - (func $~lib/internal/number/itoa (; 133 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - call $~lib/internal/number/utoa32 - ) - (func $~lib/internal/number/itoa_stream (; 134 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/number/itoa_stream (; 115 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) get_local $0 get_local $1 @@ -6612,16 +6691,15 @@ i32.const 1 return end - get_local $2 - call $~lib/internal/number/decimalCount32 - set_local $3 get_local $0 get_local $2 - get_local $3 + get_local $2 + call $~lib/internal/number/decimalCount32 + tee_local $3 call $~lib/internal/number/utoa32_lut get_local $3 ) - (func $~lib/array/Array#join (; 135 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#join (; 116 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -6629,7 +6707,6 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) get_local $0 i32.load offset=4 i32.const 1 @@ -6655,7 +6732,7 @@ if get_local $5 i32.load offset=8 - call $~lib/internal/number/itoa + call $~lib/internal/number/utoa32 return end get_local $6 @@ -6674,6 +6751,7 @@ get_local $4 i32.ge_s br_if $break|0 + get_local $2 get_local $0 get_local $2 get_local $5 @@ -6683,9 +6761,6 @@ i32.add i32.load offset=8 call $~lib/internal/number/itoa_stream - set_local $9 - get_local $2 - get_local $9 i32.add set_local $2 get_local $7 @@ -6711,6 +6786,10 @@ unreachable end get_local $0 + set_local $3 + get_local $8 + get_local $2 + get_local $0 get_local $2 get_local $5 get_local $4 @@ -6719,12 +6798,6 @@ i32.add i32.load offset=8 call $~lib/internal/number/itoa_stream - set_local $1 - get_local $0 - set_local $3 - get_local $8 - get_local $2 - get_local $1 i32.add tee_local $2 i32.gt_s @@ -6743,18 +6816,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end get_local $3 ) - (func $~lib/builtins/isFinite (; 136 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.sub - f64.const 0 - f64.eq - ) - (func $~lib/internal/number/genDigits (; 137 ;) (type $iIiIiIii) (param $0 i32) (param $1 i64) (param $2 i32) (param $3 i64) (param $4 i32) (param $5 i64) (param $6 i32) (result i32) + (func $~lib/internal/number/genDigits (; 117 ;) (type $iIiIiIii) (param $0 i32) (param $1 i64) (param $2 i32) (param $3 i64) (param $4 i32) (param $5 i64) (param $6 i32) (result i32) (local $7 i32) (local $8 i64) (local $9 i32) @@ -7167,7 +7232,7 @@ end end ) - (func $~lib/internal/number/prettify (; 138 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/number/prettify (; 118 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $2 @@ -7189,73 +7254,73 @@ get_local $1 get_local $2 i32.add - tee_local $3 - i32.le_s tee_local $4 + i32.le_s + tee_local $3 if - get_local $3 + get_local $4 i32.const 21 i32.le_s - set_local $4 + set_local $3 end - get_local $4 + get_local $3 if (result i32) block $break|0 get_local $1 - set_local $4 + set_local $3 loop $repeat|0 - get_local $4 get_local $3 + get_local $4 i32.ge_s br_if $break|0 get_local $0 - get_local $4 + get_local $3 i32.const 1 i32.shl i32.add i32.const 48 i32.store16 offset=4 - get_local $4 + get_local $3 i32.const 1 i32.add - set_local $4 + set_local $3 br $repeat|0 unreachable end unreachable end get_local $0 - get_local $3 + get_local $4 i32.const 1 i32.shl i32.add i32.const 3145774 i32.store offset=4 - get_local $3 + get_local $4 i32.const 2 i32.add else - get_local $3 + get_local $4 i32.const 0 i32.gt_s - tee_local $4 + tee_local $3 if - get_local $3 + get_local $4 i32.const 21 i32.le_s - set_local $4 + set_local $3 end - get_local $4 + get_local $3 if (result i32) get_local $0 - get_local $3 + get_local $4 i32.const 1 i32.shl i32.add - tee_local $4 + tee_local $3 i32.const 6 i32.add - get_local $4 + get_local $3 i32.const 4 i32.add i32.const 0 @@ -7265,7 +7330,7 @@ i32.shl call $~lib/internal/memory/memmove get_local $0 - get_local $3 + get_local $4 i32.const 1 i32.shl i32.add @@ -7276,24 +7341,24 @@ i32.add else i32.const -6 - get_local $3 + get_local $4 i32.lt_s - tee_local $4 + tee_local $3 if - get_local $3 + get_local $4 i32.const 0 i32.le_s - set_local $4 + set_local $3 end - get_local $4 + get_local $3 if (result i32) get_local $0 i32.const 4 i32.add i32.const 2 - get_local $3 + get_local $4 i32.sub - tee_local $4 + tee_local $3 i32.const 1 i32.shl i32.add @@ -7309,30 +7374,30 @@ i32.store offset=4 block $break|1 i32.const 2 - set_local $3 + set_local $2 loop $repeat|1 + get_local $2 get_local $3 - get_local $4 i32.ge_s br_if $break|1 get_local $0 - get_local $3 + get_local $2 i32.const 1 i32.shl i32.add i32.const 48 i32.store16 offset=4 - get_local $3 + get_local $2 i32.const 1 i32.add - set_local $3 + set_local $2 br $repeat|1 unreachable end unreachable end get_local $1 - get_local $4 + get_local $3 i32.add else get_local $1 @@ -7345,30 +7410,29 @@ get_local $0 i32.const 4 i32.add - set_local $4 - get_local $3 + set_local $3 + get_local $4 i32.const 1 i32.sub - tee_local $3 + tee_local $2 i32.const 0 i32.lt_s tee_local $0 if i32.const 0 - get_local $3 + get_local $2 i32.sub - set_local $3 + set_local $2 end get_local $3 + get_local $2 + get_local $2 call $~lib/internal/number/decimalCount32 i32.const 1 i32.add - set_local $2 - get_local $4 - get_local $3 - get_local $2 + tee_local $2 call $~lib/internal/number/utoa32_lut - get_local $4 + get_local $3 i32.const 45 i32.const 43 get_local $0 @@ -7403,30 +7467,29 @@ get_local $0 i32.const 4 i32.add - set_local $4 - get_local $3 + set_local $3 + get_local $4 i32.const 1 i32.sub - tee_local $3 + tee_local $2 i32.const 0 i32.lt_s tee_local $0 if i32.const 0 - get_local $3 + get_local $2 i32.sub - set_local $3 + set_local $2 end get_local $3 + get_local $2 + get_local $2 call $~lib/internal/number/decimalCount32 i32.const 1 i32.add - set_local $2 - get_local $4 - get_local $3 - get_local $2 + tee_local $2 call $~lib/internal/number/utoa32_lut - get_local $4 + get_local $3 i32.const 45 i32.const 43 get_local $0 @@ -7442,10 +7505,10 @@ end end ) - (func $~lib/internal/number/dtoa_core (; 139 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) + (func $~lib/internal/number/dtoa_core (; 119 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) (local $2 i64) - (local $3 i32) - (local $4 i64) + (local $3 i64) + (local $4 i32) (local $5 i32) (local $6 i64) (local $7 i64) @@ -7453,15 +7516,14 @@ (local $9 i64) (local $10 i64) (local $11 i64) - (local $12 i64) - (local $13 i64) + (local $12 i32) + (local $13 i32) (local $14 i32) - (local $15 i32) - (local $16 i32) + (local $15 i64) get_local $1 f64.const 0 f64.lt - tee_local $14 + tee_local $12 if get_local $1 f64.neg @@ -7478,10 +7540,10 @@ i64.const 52 i64.shr_u i32.wrap/i64 - tee_local $15 + tee_local $13 i32.const 0 i32.ne - tee_local $3 + tee_local $5 i64.extend_u/i32 i64.const 52 i64.shl @@ -7490,27 +7552,27 @@ i64.and i64.add set_local $2 - get_local $15 + get_local $13 i32.const 1 - get_local $3 + get_local $5 select i32.const 1075 i32.sub - tee_local $15 + tee_local $13 i32.const 1 i32.sub - set_local $3 + set_local $5 get_local $2 i64.const 1 i64.shl i64.const 1 i64.add - tee_local $4 + tee_local $6 i64.clz i32.wrap/i64 - set_local $16 + set_local $4 + get_local $6 get_local $4 - get_local $16 i64.extend_s/i32 i64.shl set_global $~lib/internal/number/_frc_plus @@ -7520,23 +7582,23 @@ i64.eq i32.const 1 i32.add - tee_local $5 + tee_local $14 i64.extend_s/i32 i64.shl i64.const 1 i64.sub - get_local $15 + get_local $13 + get_local $14 + i32.sub get_local $5 + get_local $4 i32.sub - get_local $3 - get_local $16 - i32.sub - tee_local $3 + tee_local $5 i32.sub i64.extend_s/i32 i64.shl set_global $~lib/internal/number/_frc_minus - get_local $3 + get_local $5 set_global $~lib/internal/number/_exp i32.const 348 i32.const -61 @@ -7549,8 +7611,8 @@ f64.add tee_local $1 i32.trunc_s/f64 - tee_local $16 - get_local $16 + tee_local $4 + get_local $4 f64.convert_s/i32 get_local $1 f64.ne @@ -7559,24 +7621,24 @@ i32.shr_s i32.const 1 i32.add - tee_local $3 + tee_local $5 i32.const 3 i32.shl i32.sub set_global $~lib/internal/number/_K i32.const 4200 i32.load - set_local $5 + set_local $4 i32.const 3936 i32.load - get_local $3 + get_local $5 i32.const 3 i32.shl i32.add i64.load offset=8 set_global $~lib/internal/number/_frc_pow + get_local $4 get_local $5 - get_local $3 i32.const 1 i32.shl i32.add @@ -7586,7 +7648,7 @@ get_local $2 i64.clz i32.wrap/i64 - tee_local $5 + tee_local $4 i64.extend_s/i32 i64.shl tee_local $2 @@ -7594,14 +7656,14 @@ i64.and tee_local $7 get_global $~lib/internal/number/_frc_pow - tee_local $4 + tee_local $6 i64.const 4294967295 i64.and tee_local $8 i64.mul set_local $9 get_local $7 - get_local $4 + get_local $6 i64.const 32 i64.shr_u tee_local $10 @@ -7616,7 +7678,7 @@ i64.const 32 i64.shr_u i64.add - tee_local $6 + tee_local $3 i64.const 4294967295 i64.and i64.add @@ -7624,7 +7686,7 @@ get_local $11 get_local $10 i64.mul - get_local $6 + get_local $3 i64.const 32 i64.shr_u i64.add @@ -7636,23 +7698,23 @@ i64.add set_local $2 get_global $~lib/internal/number/_frc_plus - tee_local $6 + tee_local $3 i64.const 4294967295 i64.and tee_local $9 - get_local $4 + get_local $6 i64.const 4294967295 i64.and tee_local $10 i64.mul set_local $7 get_local $9 - get_local $4 + get_local $6 i64.const 32 i64.shr_u tee_local $8 i64.mul - get_local $6 + get_local $3 i64.const 32 i64.shr_u tee_local $11 @@ -7662,43 +7724,43 @@ i64.const 32 i64.shr_u i64.add - tee_local $12 + tee_local $3 i64.const 4294967295 i64.and i64.add - set_local $13 + set_local $7 get_local $11 get_local $8 i64.mul - get_local $12 + get_local $3 i64.const 32 i64.shr_u i64.add - get_local $13 + get_local $7 i64.const 2147483647 i64.add i64.const 32 i64.shr_u i64.add - set_local $13 + set_local $15 get_global $~lib/internal/number/_frc_minus - tee_local $12 + tee_local $3 i64.const 4294967295 i64.and tee_local $7 - get_local $4 + get_local $6 i64.const 4294967295 i64.and tee_local $8 i64.mul set_local $9 get_local $7 - get_local $4 + get_local $6 i64.const 32 i64.shr_u tee_local $10 i64.mul - get_local $12 + get_local $3 i64.const 32 i64.shr_u tee_local $11 @@ -7708,23 +7770,23 @@ i64.const 32 i64.shr_u i64.add - tee_local $6 + tee_local $3 i64.const 4294967295 i64.and i64.add - set_local $12 - get_local $13 + set_local $6 + get_local $15 i64.const 1 i64.sub - tee_local $13 + tee_local $7 get_local $11 get_local $10 i64.mul - get_local $6 + get_local $3 i64.const 32 i64.shr_u i64.add - get_local $12 + get_local $6 i64.const 2147483647 i64.add i64.const 32 @@ -7733,43 +7795,40 @@ i64.const 1 i64.add i64.sub - set_local $6 - get_local $0 - get_local $2 - get_local $15 - get_local $5 - i32.sub - get_global $~lib/internal/number/_exp_pow - tee_local $5 - i32.add - i32.const -64 - i32.sub - tee_local $3 - get_local $13 - get_global $~lib/internal/number/_exp - get_local $5 - i32.add - i32.const -64 - i32.sub - get_local $6 - get_local $14 - call $~lib/internal/number/genDigits set_local $3 get_local $0 - get_local $14 + get_local $12 i32.const 1 i32.shl i32.add + get_local $0 + get_local $2 + get_local $13 + get_local $4 + i32.sub + get_global $~lib/internal/number/_exp_pow + tee_local $4 + i32.add + i32.const -64 + i32.sub + tee_local $5 + get_local $7 + get_global $~lib/internal/number/_exp + get_local $4 + i32.add + i32.const -64 + i32.sub get_local $3 - get_local $14 + get_local $12 + call $~lib/internal/number/genDigits + get_local $12 i32.sub get_global $~lib/internal/number/_K call $~lib/internal/number/prettify - tee_local $3 - get_local $14 + get_local $12 i32.add ) - (func $~lib/internal/number/dtoa (; 140 ;) (type $Fi) (param $0 f64) (result i32) + (func $~lib/internal/number/dtoa (; 120 ;) (type $Fi) (param $0 f64) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -7780,11 +7839,14 @@ return end get_local $0 - call $~lib/builtins/isFinite - i32.eqz + get_local $0 + f64.sub + f64.const 0 + f64.ne if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne if i32.const 2848 return @@ -7799,15 +7861,15 @@ end i32.const 28 call $~lib/internal/string/allocateUnsafe - tee_local $1 + tee_local $2 get_local $0 call $~lib/internal/number/dtoa_core - set_local $2 - get_local $1 + set_local $1 get_local $2 - call $~lib/string/String#substring - set_local $2 get_local $1 + call $~lib/string/String#substring + set_local $1 + get_local $2 i32.eqz if i32.const 0 @@ -7817,10 +7879,9 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free - get_local $2 + get_local $1 ) - (func $~lib/internal/number/dtoa_stream (; 141 ;) (type $iiFi) (param $0 i32) (param $1 i32) (param $2 f64) (result i32) + (func $~lib/internal/number/dtoa_stream (; 121 ;) (type $iiFi) (param $0 i32) (param $1 i32) (param $2 f64) (result i32) (local $3 i32) get_local $0 get_local $1 @@ -7845,11 +7906,14 @@ return end get_local $2 - call $~lib/builtins/isFinite - i32.eqz + get_local $2 + f64.sub + f64.const 0 + f64.ne if get_local $2 - call $~lib/builtins/isNaN + get_local $2 + f64.ne if get_local $0 i32.const 78 @@ -7890,7 +7954,7 @@ get_local $2 call $~lib/internal/number/dtoa_core ) - (func $~lib/array/Array#join (; 142 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/array/Array#join (; 122 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -7899,12 +7963,11 @@ (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) i32.const 4348 i32.load i32.const 1 i32.sub - tee_local $1 + tee_local $3 i32.const 0 i32.lt_s if @@ -7920,7 +7983,7 @@ i32.const 0 i32.ne set_local $6 - get_local $1 + get_local $3 i32.eqz if get_local $4 @@ -7931,7 +7994,7 @@ get_local $5 i32.const 28 i32.add - get_local $1 + get_local $3 i32.mul i32.const 28 i32.add @@ -7940,22 +8003,20 @@ set_local $2 block $break|0 loop $repeat|0 - get_local $3 get_local $1 + get_local $3 i32.ge_s br_if $break|0 + get_local $0 get_local $2 get_local $0 get_local $4 - get_local $3 + get_local $1 i32.const 3 i32.shl i32.add f64.load offset=8 call $~lib/internal/number/dtoa_stream - set_local $8 - get_local $0 - get_local $8 i32.add set_local $0 get_local $6 @@ -7971,30 +8032,27 @@ i32.add set_local $0 end - get_local $3 + get_local $1 i32.const 1 i32.add - set_local $3 + set_local $1 br $repeat|0 unreachable end unreachable end + get_local $7 + get_local $0 get_local $2 + tee_local $1 get_local $0 get_local $4 - get_local $1 + get_local $3 i32.const 3 i32.shl i32.add f64.load offset=8 call $~lib/internal/number/dtoa_stream - set_local $1 - get_local $2 - set_local $3 - get_local $7 - get_local $0 - get_local $1 i32.add tee_local $0 i32.gt_s @@ -8002,7 +8060,7 @@ get_local $2 get_local $0 call $~lib/string/String#substring - set_local $3 + set_local $1 get_local $2 i32.eqz if @@ -8013,11 +8071,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end - get_local $3 + get_local $1 ) - (func $~lib/array/Array#join (; 143 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#join (; 123 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -8161,21 +8218,7 @@ end get_local $0 ) - (func $std/array/Ref#constructor (; 144 ;) (type $FUNCSIG$i) (result i32) - i32.const 0 - call $~lib/memory/memory.allocate - ) - (func $~lib/array/Array#__unchecked_set (; 145 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) - get_local $0 - i32.load - get_local $1 - i32.const 2 - i32.shl - i32.add - get_local $2 - i32.store offset=8 - ) - (func $~lib/array/Array#join (; 146 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#join (; 124 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -8303,19 +8346,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end get_local $2 ) - (func $~lib/internal/number/itoa (; 147 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 24 - i32.shl - i32.const 24 - i32.shr_s - call $~lib/internal/number/itoa32 - ) - (func $~lib/internal/number/itoa_stream (; 148 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/number/itoa_stream (; 125 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) get_local $0 get_local $1 @@ -8353,18 +8387,14 @@ i32.shl i32.const 24 i32.shr_s + tee_local $2 call $~lib/internal/number/decimalCount32 + get_local $3 + i32.add set_local $1 get_local $0 get_local $2 - i32.const 24 - i32.shl - i32.const 24 - i32.shr_s get_local $1 - get_local $3 - i32.add - tee_local $1 call $~lib/internal/number/utoa32_lut get_local $3 if @@ -8374,7 +8404,7 @@ end get_local $1 ) - (func $~lib/array/Array#join (; 149 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/array/Array#join (; 126 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -8383,12 +8413,11 @@ (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) i32.const 4724 i32.load i32.const 1 i32.sub - tee_local $1 + tee_local $3 i32.const 0 i32.lt_s if @@ -8404,18 +8433,18 @@ i32.const 0 i32.ne set_local $6 - get_local $1 + get_local $3 i32.eqz if get_local $4 i32.load8_s offset=8 - call $~lib/internal/number/itoa + call $~lib/internal/number/itoa32 return end get_local $5 i32.const 11 i32.add - get_local $1 + get_local $3 i32.mul i32.const 11 i32.add @@ -8424,20 +8453,18 @@ set_local $2 block $break|0 loop $repeat|0 - get_local $3 get_local $1 + get_local $3 i32.ge_s br_if $break|0 + get_local $0 get_local $2 get_local $0 get_local $4 - get_local $3 + get_local $1 i32.add i32.load8_s offset=8 call $~lib/internal/number/itoa_stream - set_local $8 - get_local $0 - get_local $8 i32.add set_local $0 get_local $6 @@ -8453,28 +8480,25 @@ i32.add set_local $0 end - get_local $3 + get_local $1 i32.const 1 i32.add - set_local $3 + set_local $1 br $repeat|0 unreachable end unreachable end + get_local $7 + get_local $0 get_local $2 + tee_local $1 get_local $0 get_local $4 - get_local $1 + get_local $3 i32.add i32.load8_s offset=8 call $~lib/internal/number/itoa_stream - set_local $1 - get_local $2 - set_local $3 - get_local $7 - get_local $0 - get_local $1 i32.add tee_local $0 i32.gt_s @@ -8482,7 +8506,7 @@ get_local $2 get_local $0 call $~lib/string/String#substring - set_local $3 + set_local $1 get_local $2 i32.eqz if @@ -8493,18 +8517,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end - get_local $3 + get_local $1 ) - (func $~lib/internal/number/itoa (; 150 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 65535 - i32.and - call $~lib/internal/number/utoa32 - ) - (func $~lib/internal/number/itoa_stream (; 151 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) + (func $~lib/internal/number/itoa_stream (; 127 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 get_local $1 i32.const 1 @@ -8525,17 +8541,16 @@ get_local $2 i32.const 65535 i32.and + tee_local $2 call $~lib/internal/number/decimalCount32 - set_local $3 + set_local $1 get_local $0 get_local $2 - i32.const 65535 - i32.and - get_local $3 + get_local $1 call $~lib/internal/number/utoa32_lut - get_local $3 + get_local $1 ) - (func $~lib/array/Array#join (; 152 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/array/Array#join (; 128 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -8544,12 +8559,11 @@ (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) i32.const 4788 i32.load i32.const 1 i32.sub - tee_local $1 + tee_local $3 i32.const 0 i32.lt_s if @@ -8565,18 +8579,18 @@ i32.const 0 i32.ne set_local $6 - get_local $1 + get_local $3 i32.eqz if get_local $4 i32.load16_u offset=8 - call $~lib/internal/number/itoa + call $~lib/internal/number/utoa32 return end get_local $5 i32.const 10 i32.add - get_local $1 + get_local $3 i32.mul i32.const 10 i32.add @@ -8585,22 +8599,20 @@ set_local $2 block $break|0 loop $repeat|0 - get_local $3 get_local $1 + get_local $3 i32.ge_s br_if $break|0 + get_local $0 get_local $2 get_local $0 get_local $4 - get_local $3 + get_local $1 i32.const 1 i32.shl i32.add i32.load16_u offset=8 call $~lib/internal/number/itoa_stream - set_local $8 - get_local $0 - get_local $8 i32.add set_local $0 get_local $6 @@ -8616,30 +8628,27 @@ i32.add set_local $0 end - get_local $3 + get_local $1 i32.const 1 i32.add - set_local $3 + set_local $1 br $repeat|0 unreachable end unreachable end + get_local $7 + get_local $0 get_local $2 + tee_local $1 get_local $0 get_local $4 - get_local $1 + get_local $3 i32.const 1 i32.shl i32.add i32.load16_u offset=8 call $~lib/internal/number/itoa_stream - set_local $1 - get_local $2 - set_local $3 - get_local $7 - get_local $0 - get_local $1 i32.add tee_local $0 i32.gt_s @@ -8647,7 +8656,7 @@ get_local $2 get_local $0 call $~lib/string/String#substring - set_local $3 + set_local $1 get_local $2 i32.eqz if @@ -8658,11 +8667,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end - get_local $3 + get_local $1 ) - (func $~lib/internal/number/decimalCount64 (; 153 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/number/decimalCount64 (; 129 ;) (type $Ii) (param $0 i64) (result i32) get_local $0 i64.const 1000000000000000 i64.lt_u @@ -8716,7 +8724,7 @@ end end ) - (func $~lib/internal/number/utoa64_lut (; 154 ;) (type $iIiv) (param $0 i32) (param $1 i64) (param $2 i32) + (func $~lib/internal/number/utoa64_lut (; 130 ;) (type $iIiv) (param $0 i32) (param $1 i64) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -8813,7 +8821,7 @@ get_local $2 call $~lib/internal/number/utoa32_lut ) - (func $~lib/internal/number/utoa64 (; 155 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/number/utoa64 (; 131 ;) (type $Ii) (param $0 i64) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -8849,11 +8857,7 @@ end get_local $2 ) - (func $~lib/internal/number/itoa (; 156 ;) (type $Ii) (param $0 i64) (result i32) - get_local $0 - call $~lib/internal/number/utoa64 - ) - (func $~lib/internal/number/itoa_stream (; 157 ;) (type $iiIi) (param $0 i32) (param $1 i32) (param $2 i64) (result i32) + (func $~lib/internal/number/itoa_stream (; 132 ;) (type $iiIi) (param $0 i32) (param $1 i32) (param $2 i64) (result i32) (local $3 i32) get_local $0 get_local $1 @@ -8884,17 +8888,16 @@ get_local $1 call $~lib/internal/number/utoa32_lut else - get_local $2 - call $~lib/internal/number/decimalCount64 - set_local $1 get_local $0 get_local $2 - get_local $1 + get_local $2 + call $~lib/internal/number/decimalCount64 + tee_local $1 call $~lib/internal/number/utoa64_lut end get_local $1 ) - (func $~lib/array/Array#join (; 158 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/array/Array#join (; 133 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -8903,12 +8906,11 @@ (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) i32.const 5412 i32.load i32.const 1 i32.sub - tee_local $1 + tee_local $3 i32.const 0 i32.lt_s if @@ -8924,18 +8926,18 @@ i32.const 0 i32.ne set_local $6 - get_local $1 + get_local $3 i32.eqz if get_local $4 i64.load offset=8 - call $~lib/internal/number/itoa + call $~lib/internal/number/utoa64 return end get_local $5 i32.const 20 i32.add - get_local $1 + get_local $3 i32.mul i32.const 20 i32.add @@ -8944,22 +8946,20 @@ set_local $2 block $break|0 loop $repeat|0 - get_local $3 get_local $1 + get_local $3 i32.ge_s br_if $break|0 + get_local $0 get_local $2 get_local $0 get_local $4 - get_local $3 + get_local $1 i32.const 3 i32.shl i32.add i64.load offset=8 call $~lib/internal/number/itoa_stream - set_local $8 - get_local $0 - get_local $8 i32.add set_local $0 get_local $6 @@ -8975,30 +8975,27 @@ i32.add set_local $0 end - get_local $3 + get_local $1 i32.const 1 i32.add - set_local $3 + set_local $1 br $repeat|0 unreachable end unreachable end + get_local $7 + get_local $0 get_local $2 + tee_local $1 get_local $0 get_local $4 - get_local $1 + get_local $3 i32.const 3 i32.shl i32.add i64.load offset=8 call $~lib/internal/number/itoa_stream - set_local $1 - get_local $2 - set_local $3 - get_local $7 - get_local $0 - get_local $1 i32.add tee_local $0 i32.gt_s @@ -9006,7 +9003,7 @@ get_local $2 get_local $0 call $~lib/string/String#substring - set_local $3 + set_local $1 get_local $2 i32.eqz if @@ -9017,11 +9014,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end - get_local $3 + get_local $1 ) - (func $~lib/internal/number/itoa64 (; 159 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/number/itoa64 (; 134 ;) (type $Ii) (param $0 i64) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -9035,7 +9031,7 @@ get_local $0 i64.const 0 i64.lt_s - tee_local $2 + tee_local $1 if i64.const 0 get_local $0 @@ -9050,41 +9046,35 @@ i32.wrap/i64 tee_local $4 call $~lib/internal/number/decimalCount32 - tee_local $1 - get_local $2 + get_local $1 i32.add - tee_local $3 + tee_local $2 call $~lib/internal/string/allocateUnsafe - tee_local $1 + tee_local $3 get_local $4 - get_local $3 + get_local $2 call $~lib/internal/number/utoa32_lut else get_local $0 call $~lib/internal/number/decimalCount64 - tee_local $1 - get_local $2 + get_local $1 i32.add - tee_local $3 + tee_local $2 call $~lib/internal/string/allocateUnsafe - tee_local $1 + tee_local $3 get_local $0 - get_local $3 + get_local $2 call $~lib/internal/number/utoa64_lut end - get_local $2 + get_local $1 if - get_local $1 + get_local $3 i32.const 45 i32.store16 offset=4 end - get_local $1 + get_local $3 ) - (func $~lib/internal/number/itoa (; 160 ;) (type $Ii) (param $0 i64) (result i32) - get_local $0 - call $~lib/internal/number/itoa64 - ) - (func $~lib/internal/number/itoa_stream (; 161 ;) (type $iiIi) (param $0 i32) (param $1 i32) (param $2 i64) (result i32) + (func $~lib/internal/number/itoa_stream (; 135 ;) (type $iiIi) (param $0 i32) (param $1 i32) (param $2 i64) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -9118,23 +9108,20 @@ if get_local $2 i32.wrap/i64 - tee_local $1 + tee_local $4 call $~lib/internal/number/decimalCount32 - set_local $4 - get_local $0 - get_local $1 - get_local $4 get_local $3 i32.add - tee_local $1 - call $~lib/internal/number/utoa32_lut - else - get_local $2 - call $~lib/internal/number/decimalCount64 set_local $1 get_local $0 - get_local $2 + get_local $4 get_local $1 + call $~lib/internal/number/utoa32_lut + else + get_local $0 + get_local $2 + get_local $2 + call $~lib/internal/number/decimalCount64 get_local $3 i32.add tee_local $1 @@ -9148,7 +9135,7 @@ end get_local $1 ) - (func $~lib/array/Array#join (; 162 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/array/Array#join (; 136 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) (local $1 i32) (local $2 i32) @@ -9157,12 +9144,11 @@ (local $5 i32) (local $6 i32) (local $7 i32) - (local $8 i32) i32.const 5612 i32.load i32.const 1 i32.sub - tee_local $1 + tee_local $3 i32.const 0 i32.lt_s if @@ -9178,18 +9164,18 @@ i32.const 0 i32.ne set_local $6 - get_local $1 + get_local $3 i32.eqz if get_local $4 i64.load offset=8 - call $~lib/internal/number/itoa + call $~lib/internal/number/itoa64 return end get_local $5 i32.const 21 i32.add - get_local $1 + get_local $3 i32.mul i32.const 21 i32.add @@ -9198,22 +9184,20 @@ set_local $2 block $break|0 loop $repeat|0 - get_local $3 get_local $1 + get_local $3 i32.ge_s br_if $break|0 + get_local $0 get_local $2 get_local $0 get_local $4 - get_local $3 + get_local $1 i32.const 3 i32.shl i32.add i64.load offset=8 call $~lib/internal/number/itoa_stream - set_local $8 - get_local $0 - get_local $8 i32.add set_local $0 get_local $6 @@ -9229,30 +9213,27 @@ i32.add set_local $0 end - get_local $3 + get_local $1 i32.const 1 i32.add - set_local $3 + set_local $1 br $repeat|0 unreachable end unreachable end + get_local $7 + get_local $0 get_local $2 + tee_local $1 get_local $0 get_local $4 - get_local $1 + get_local $3 i32.const 3 i32.shl i32.add i64.load offset=8 call $~lib/internal/number/itoa_stream - set_local $1 - get_local $2 - set_local $3 - get_local $7 - get_local $0 - get_local $1 i32.add tee_local $0 i32.gt_s @@ -9260,7 +9241,7 @@ get_local $2 get_local $0 call $~lib/string/String#substring - set_local $3 + set_local $1 get_local $2 i32.eqz if @@ -9271,11 +9252,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end - get_local $3 + get_local $1 ) - (func $~lib/array/Array>#join (; 163 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array>#join (; 137 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -9334,12 +9314,10 @@ i32.load offset=8 tee_local $2 if + get_local $1 get_local $2 i32.const 1872 call $~lib/array/Array#join - set_local $2 - get_local $1 - get_local $2 call $~lib/string/String.__concat set_local $1 end @@ -9367,25 +9345,16 @@ i32.load offset=8 tee_local $2 if + get_local $1 get_local $2 i32.const 1872 call $~lib/array/Array#join - set_local $0 - get_local $1 - get_local $0 call $~lib/string/String.__concat set_local $1 end get_local $1 ) - (func $~lib/internal/number/itoa (; 164 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 255 - i32.and - call $~lib/internal/number/utoa32 - ) - (func $~lib/internal/number/itoa_stream (; 165 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) - (local $3 i32) + (func $~lib/internal/number/itoa_stream (; 138 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 get_local $1 i32.const 1 @@ -9406,17 +9375,16 @@ get_local $2 i32.const 255 i32.and + tee_local $2 call $~lib/internal/number/decimalCount32 - set_local $3 + set_local $1 get_local $0 get_local $2 - i32.const 255 - i32.and - get_local $3 + get_local $1 call $~lib/internal/number/utoa32_lut - get_local $3 + get_local $1 ) - (func $~lib/array/Array#join (; 166 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#join (; 139 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -9424,7 +9392,6 @@ (local $6 i32) (local $7 i32) (local $8 i32) - (local $9 i32) get_local $0 i32.load offset=4 i32.const 1 @@ -9450,7 +9417,7 @@ if get_local $5 i32.load8_u offset=8 - call $~lib/internal/number/itoa + call $~lib/internal/number/utoa32 return end get_local $6 @@ -9469,6 +9436,7 @@ get_local $4 i32.ge_s br_if $break|0 + get_local $2 get_local $0 get_local $2 get_local $5 @@ -9476,9 +9444,6 @@ i32.add i32.load8_u offset=8 call $~lib/internal/number/itoa_stream - set_local $9 - get_local $2 - get_local $9 i32.add set_local $2 get_local $7 @@ -9504,18 +9469,16 @@ unreachable end get_local $0 + set_local $3 + get_local $8 + get_local $2 + get_local $0 get_local $2 get_local $5 get_local $4 i32.add i32.load8_u offset=8 call $~lib/internal/number/itoa_stream - set_local $1 - get_local $0 - set_local $3 - get_local $8 - get_local $2 - get_local $1 i32.add tee_local $2 i32.gt_s @@ -9534,11 +9497,10 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free end get_local $3 ) - (func $~lib/array/Array>#join (; 167 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array>#join (; 140 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -9597,12 +9559,10 @@ i32.load offset=8 tee_local $2 if + get_local $1 get_local $2 i32.const 1872 call $~lib/array/Array#join - set_local $2 - get_local $1 - get_local $2 call $~lib/string/String.__concat set_local $1 end @@ -9630,18 +9590,16 @@ i32.load offset=8 tee_local $2 if + get_local $1 get_local $2 i32.const 1872 call $~lib/array/Array#join - set_local $0 - get_local $1 - get_local $0 call $~lib/string/String.__concat set_local $1 end get_local $1 ) - (func $~lib/array/Array>#join (; 168 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array>#join (; 141 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -9700,12 +9658,10 @@ i32.load offset=8 tee_local $3 if + get_local $2 get_local $3 get_local $1 call $~lib/array/Array#join - set_local $3 - get_local $2 - get_local $3 call $~lib/string/String.__concat set_local $2 end @@ -9733,18 +9689,16 @@ i32.load offset=8 tee_local $3 if + get_local $2 get_local $3 get_local $1 call $~lib/array/Array#join - set_local $0 - get_local $2 - get_local $0 call $~lib/string/String.__concat set_local $2 end get_local $2 ) - (func $~lib/array/Array>>#join (; 169 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array>>#join (; 142 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -9803,12 +9757,10 @@ i32.load offset=8 tee_local $2 if + get_local $1 get_local $2 i32.const 1872 call $~lib/array/Array>#join - set_local $2 - get_local $1 - get_local $2 call $~lib/string/String.__concat set_local $1 end @@ -9836,22 +9788,19 @@ i32.load offset=8 tee_local $2 if + get_local $1 get_local $2 i32.const 1872 call $~lib/array/Array>#join - set_local $0 - get_local $1 - get_local $0 call $~lib/string/String.__concat set_local $1 end get_local $1 ) - (func $start (; 170 ;) (type $v) + (func $start (; 143 ;) (type $v) (local $0 i32) (local $1 i32) (local $2 f32) - (local $3 f32) i32.const 6088 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -10059,7 +10008,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s if i32.const 0 i32.const 152 @@ -10072,9 +10024,21 @@ i32.const 42 call $~lib/array/Array#push drop - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 42 i32.ne if @@ -10098,7 +10062,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 1 i32.ne if @@ -10134,7 +10101,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 1 i32.ne if @@ -10162,7 +10132,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 1 i32.ne if @@ -10173,9 +10146,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10203,7 +10188,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 2 i32.ne if @@ -10214,9 +10202,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10227,9 +10227,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10257,7 +10271,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 3 i32.ne if @@ -10268,9 +10285,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10281,9 +10310,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10294,9 +10337,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 45 i32.ne if @@ -10315,7 +10372,10 @@ call $~lib/array/Array#concat set_global $std/array/out get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 3 i32.ne if @@ -10355,7 +10415,10 @@ call $~lib/array/Array#concat drop get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 3 i32.ne if @@ -10366,9 +10429,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10379,9 +10454,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10392,9 +10481,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 45 i32.ne if @@ -10418,7 +10521,10 @@ call $~lib/array/Array#concat set_global $std/array/out get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 3 i32.ne if @@ -10453,9 +10559,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10466,9 +10584,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10479,9 +10611,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 45 i32.ne if @@ -10492,9 +10638,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 3 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 12 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 46 i32.ne if @@ -10505,9 +10665,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 4 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 16 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 47 i32.ne if @@ -10549,9 +10723,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/out i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/out + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 45 i32.ne if @@ -10615,7 +10803,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 4 i32.ne if @@ -10626,9 +10817,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 42 i32.ne if @@ -10639,9 +10842,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10652,9 +10869,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10665,9 +10896,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 3 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 12 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 45 i32.ne if @@ -10695,7 +10940,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 5 i32.ne if @@ -10706,9 +10954,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 41 i32.ne if @@ -10719,9 +10979,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 42 i32.ne if @@ -10732,9 +11006,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10745,9 +11033,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 3 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 12 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10758,9 +11060,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 4 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 16 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 45 i32.ne if @@ -10798,7 +11114,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 5 i32.ne if @@ -10809,9 +11128,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 42 i32.ne if @@ -10822,9 +11153,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10835,9 +11180,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10848,9 +11207,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 3 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 12 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 45 i32.ne if @@ -10888,7 +11261,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 5 i32.ne if @@ -10899,9 +11275,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 42 i32.ne if @@ -10912,9 +11300,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10925,9 +11327,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10954,7 +11370,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 5 i32.ne if @@ -10965,9 +11384,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -10978,9 +11409,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 43 i32.ne if @@ -10991,9 +11436,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 2 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 42 i32.ne if @@ -11361,7 +11820,10 @@ unreachable end get_global $std/array/arr - call $std/array/internalCapacity + i32.load + i32.load + i32.const 2 + i32.shr_s i32.const 5 i32.ne if @@ -11372,9 +11834,21 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 44 i32.ne if @@ -11385,9 +11859,23 @@ call $~lib/env/abort unreachable end - get_global $std/array/arr i32.const 1 - call $~lib/array/Array#__get + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 42 i32.ne if @@ -11897,17 +12385,39 @@ call $~lib/env/abort unreachable end + i32.const 0 get_global $std/array/newArr - i32.const 0 - call $~lib/array/Array#__get + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result f32) + get_local $0 + f32.load offset=8 + else + unreachable + end set_local $2 - get_global $std/array/arr i32.const 0 - call $~lib/array/Array#__get - f32.convert_s/i32 - set_local $3 + get_global $std/array/arr + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + set_local $0 get_local $2 - get_local $3 + get_local $0 + f32.convert_s/i32 f32.ne if i32.const 0 @@ -12451,7 +12961,23 @@ i32.const 0 set_global $~argc get_global $std/array/f32ArrayTyped - call $~lib/array/Array#sort|trampoline + set_local $1 + i32.const 0 + set_local $0 + block $1of1 + block $0of1 + block $outOfRange + get_global $~argc + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 43 + set_local $0 + end + get_local $1 + get_local $0 + call $~lib/array/Array#sort drop get_global $std/array/f32ArrayTyped call $std/array/isArraysEqual @@ -12467,7 +12993,23 @@ i32.const 0 set_global $~argc get_global $std/array/f64ArrayTyped - call $~lib/array/Array#sort|trampoline + set_local $1 + i32.const 0 + set_local $0 + block $1of151 + block $0of152 + block $outOfRange53 + get_global $~argc + br_table $0of152 $1of151 $outOfRange53 + end + unreachable + end + i32.const 44 + set_local $0 + end + get_local $1 + get_local $0 + call $~lib/array/Array#sort drop get_global $std/array/f64ArrayTyped call $std/array/isArraysEqual @@ -12483,7 +13025,23 @@ i32.const 0 set_global $~argc get_global $std/array/i32ArrayTyped - call $~lib/array/Array#sort|trampoline + set_local $1 + i32.const 0 + set_local $0 + block $1of154 + block $0of155 + block $outOfRange56 + get_global $~argc + br_table $0of155 $1of154 $outOfRange56 + end + unreachable + end + i32.const 45 + set_local $0 + end + get_local $1 + get_local $0 + call $~lib/array/Array#sort drop get_global $std/array/i32ArrayTyped i32.const 1248 @@ -12501,7 +13059,23 @@ i32.const 0 set_global $~argc get_global $std/array/u32ArrayTyped - call $~lib/array/Array#sort|trampoline + set_local $1 + i32.const 0 + set_local $0 + block $1of157 + block $0of158 + block $outOfRange59 + get_global $~argc + br_table $0of158 $1of157 $outOfRange59 + end + unreachable + end + i32.const 46 + set_local $0 + end + get_local $1 + get_local $0 + call $~lib/array/Array#sort drop get_global $std/array/u32ArrayTyped i32.const 1328 @@ -12771,22 +13345,28 @@ i32.const 3 call $~lib/array/Array#constructor set_local $0 - call $std/array/Ref#constructor + i32.const 0 + call $~lib/allocator/arena/__memory_allocate set_local $1 get_local $0 - i32.const 0 + i32.load get_local $1 - call $~lib/array/Array#__unchecked_set + i32.store offset=8 get_local $0 - i32.const 1 + i32.load + i32.const 4 + i32.add i32.const 0 - call $~lib/array/Array#__unchecked_set - call $std/array/Ref#constructor + i32.store offset=8 + i32.const 0 + call $~lib/allocator/arena/__memory_allocate set_local $1 get_local $0 - i32.const 2 + i32.load + i32.const 8 + i32.add get_local $1 - call $~lib/array/Array#__unchecked_set + i32.store offset=8 get_local $0 set_global $std/array/refArr get_global $std/array/refArr @@ -12974,7 +13554,7 @@ unreachable end ) - (func $null (; 171 ;) (type $v) + (func $null (; 144 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/arraybuffer.optimized.wat b/tests/compiler/std/arraybuffer.optimized.wat index 61b8ec0a..1fd09805 100644 --- a/tests/compiler/std/arraybuffer.optimized.wat +++ b/tests/compiler/std/arraybuffer.optimized.wat @@ -5,7 +5,6 @@ (type $iiiv (func (param i32 i32 i32))) (type $v (func)) (type $FUNCSIG$vii (func (param i32 i32))) - (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) @@ -22,17 +21,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/allocator/arena/__memory_allocate (; 2 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/__memory_allocate (; 1 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -94,7 +83,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -107,15 +96,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/internal/memory/memset (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) get_local $1 i32.eqz @@ -334,18 +329,7 @@ end end ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 5 ;) (type $FUNCSIG$i) (result i32) - (local $0 i32) - i32.const 8 - call $~lib/internal/arraybuffer/allocateUnsafe - tee_local $0 - i32.const 8 - i32.add - i32.const 8 - call $~lib/internal/memory/memset - get_local $0 - ) - (func $~lib/internal/memory/memcpy (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1249,7 +1233,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 5 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) get_local $0 @@ -1449,31 +1433,31 @@ end end ) - (func $~lib/arraybuffer/ArrayBuffer#slice (; 8 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#slice (; 6 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 i32.load - set_local $4 + set_local $3 get_local $1 i32.const 0 i32.lt_s if (result i32) - get_local $4 + get_local $3 get_local $1 i32.add - tee_local $3 + tee_local $4 i32.const 0 - get_local $3 + get_local $4 i32.const 0 i32.gt_s select else get_local $1 - tee_local $3 - get_local $4 + tee_local $4 + get_local $3 + get_local $1 get_local $3 - get_local $4 i32.lt_s select end @@ -1482,48 +1466,49 @@ i32.const 0 i32.lt_s if (result i32) - get_local $4 + get_local $3 get_local $2 i32.add - tee_local $3 + tee_local $4 i32.const 0 - get_local $3 + get_local $4 i32.const 0 i32.gt_s select else get_local $2 - tee_local $3 - get_local $4 + tee_local $4 + get_local $3 + get_local $2 get_local $3 - get_local $4 i32.lt_s select end tee_local $2 get_local $1 i32.sub - tee_local $3 + tee_local $4 i32.const 0 - get_local $3 + get_local $4 i32.const 0 i32.gt_s select - tee_local $3 - call $~lib/internal/arraybuffer/allocateUnsafe tee_local $2 + call $~lib/internal/arraybuffer/allocateUnsafe + tee_local $3 i32.const 8 i32.add + tee_local $4 get_local $0 i32.const 8 i32.add get_local $1 i32.add - get_local $3 - call $~lib/internal/memory/memmove get_local $2 + call $~lib/internal/memory/memmove + get_local $3 ) - (func $~lib/arraybuffer/ArrayBuffer#slice|trampoline (; 9 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#slice|trampoline (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) block $2of2 block $1of2 @@ -1545,19 +1530,20 @@ get_local $2 call $~lib/arraybuffer/ArrayBuffer#slice ) - (func $~lib/arraybuffer/ArrayBuffer#get:data (; 10 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 8 - i32.add - ) - (func $start (; 11 ;) (type $v) + (func $start (; 8 ;) (type $v) (local $0 i32) - (local $1 i32) i32.const 160 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset set_global $~lib/allocator/arena/offset - call $~lib/arraybuffer/ArrayBuffer#constructor + i32.const 8 + call $~lib/internal/arraybuffer/allocateUnsafe + tee_local $0 + i32.const 8 + i32.add + i32.const 8 + call $~lib/internal/memory/memset + get_local $0 set_global $std/arraybuffer/buffer get_global $std/arraybuffer/buffer i32.load @@ -1590,13 +1576,9 @@ unreachable end get_global $std/arraybuffer/sliced - call $~lib/arraybuffer/ArrayBuffer#get:data - set_local $0 get_global $std/arraybuffer/buffer - call $~lib/arraybuffer/ArrayBuffer#get:data - set_local $1 - get_local $0 - get_local $1 + i32.const 0 + i32.add i32.eq if i32.const 0 @@ -1748,7 +1730,7 @@ unreachable end ) - (func $null (; 12 ;) (type $v) + (func $null (; 9 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/constructor.optimized.wat b/tests/compiler/std/constructor.optimized.wat index a3a1bb18..68f7d682 100644 --- a/tests/compiler/std/constructor.optimized.wat +++ b/tests/compiler/std/constructor.optimized.wat @@ -1,7 +1,6 @@ (module (type $ii (func (param i32) (result i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (memory $0 0) (table $0 1 anyfunc) (elem (i32.const 0) $null) @@ -83,102 +82,83 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 1 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - call $~lib/allocator/arena/__memory_allocate - ) - (func $std/constructor/EmptyCtor#constructor (; 2 ;) (type $FUNCSIG$i) (result i32) - i32.const 0 - call $~lib/memory/memory.allocate - ) - (func $std/constructor/EmptyCtorWithFieldInit#constructor (; 3 ;) (type $FUNCSIG$i) (result i32) - (local $0 i32) - i32.const 4 - call $~lib/memory/memory.allocate - tee_local $0 - i32.const 1 - i32.store - get_local $0 - ) - (func $std/constructor/EmptyCtorWithFieldNoInit#constructor (; 4 ;) (type $FUNCSIG$i) (result i32) - (local $0 i32) - i32.const 4 - call $~lib/memory/memory.allocate - tee_local $0 - i32.const 0 - i32.store - get_local $0 - ) - (func $std/constructor/CtorReturns#constructor (; 5 ;) (type $FUNCSIG$i) (result i32) - i32.const 0 - call $~lib/allocator/arena/__memory_allocate - ) - (func $std/constructor/CtorConditionallyReturns#constructor (; 6 ;) (type $FUNCSIG$i) (result i32) - get_global $std/constructor/b - if - i32.const 0 - call $~lib/allocator/arena/__memory_allocate - return - end - i32.const 0 - call $~lib/memory/memory.allocate - ) - (func $std/constructor/CtorConditionallyAllocates#constructor (; 7 ;) (type $FUNCSIG$i) (result i32) - (local $0 i32) - get_global $std/constructor/b - if - i32.const 0 - call $~lib/memory/memory.allocate - set_local $0 - end - get_local $0 - i32.eqz - if - i32.const 0 - call $~lib/memory/memory.allocate - set_local $0 - end - get_local $0 - ) - (func $start (; 8 ;) (type $v) + (func $start (; 1 ;) (type $v) (local $0 i32) i32.const 8 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset set_global $~lib/allocator/arena/offset - call $std/constructor/EmptyCtor#constructor + i32.const 0 + call $~lib/allocator/arena/__memory_allocate set_global $std/constructor/emptyCtor - call $std/constructor/EmptyCtorWithFieldInit#constructor + i32.const 4 + call $~lib/allocator/arena/__memory_allocate + tee_local $0 + i32.const 1 + i32.store + get_local $0 set_global $std/constructor/emptyCtorWithFieldInit - call $std/constructor/EmptyCtorWithFieldNoInit#constructor + i32.const 4 + call $~lib/allocator/arena/__memory_allocate + tee_local $0 + i32.const 0 + i32.store + get_local $0 set_global $std/constructor/emptyCtorWithFieldNoInit i32.const 0 - call $~lib/memory/memory.allocate + call $~lib/allocator/arena/__memory_allocate set_global $std/constructor/none i32.const 4 - call $~lib/memory/memory.allocate + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 1 i32.store get_local $0 set_global $std/constructor/justFieldInit i32.const 4 - call $~lib/memory/memory.allocate + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 0 i32.store get_local $0 set_global $std/constructor/justFieldNoInit - call $std/constructor/CtorReturns#constructor + i32.const 0 + call $~lib/allocator/arena/__memory_allocate set_global $std/constructor/ctorReturns - call $std/constructor/CtorConditionallyReturns#constructor + block $__inlined_func$std/constructor/CtorConditionallyReturns#constructor (result i32) + get_global $std/constructor/b + if + i32.const 0 + call $~lib/allocator/arena/__memory_allocate + br $__inlined_func$std/constructor/CtorConditionallyReturns#constructor + end + i32.const 0 + call $~lib/allocator/arena/__memory_allocate + end + tee_local $0 set_global $std/constructor/ctorConditionallyReturns - call $std/constructor/EmptyCtor#constructor + i32.const 0 + call $~lib/allocator/arena/__memory_allocate set_global $std/constructor/ctorAllocates - call $std/constructor/CtorConditionallyAllocates#constructor + i32.const 0 + set_local $0 + get_global $std/constructor/b + if + i32.const 0 + call $~lib/allocator/arena/__memory_allocate + set_local $0 + end + get_local $0 + i32.eqz + if + i32.const 0 + call $~lib/allocator/arena/__memory_allocate + set_local $0 + end + get_local $0 set_global $std/constructor/ctorConditionallyAllocates ) - (func $null (; 9 ;) (type $v) + (func $null (; 2 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/gc-array.optimized.wat b/tests/compiler/std/gc-array.optimized.wat index e20bdd17..912bac22 100644 --- a/tests/compiler/std/gc-array.optimized.wat +++ b/tests/compiler/std/gc-array.optimized.wat @@ -8,7 +8,6 @@ (type $iiiiv (func (param i32 i32 i32 i32))) (type $i (func (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) - (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 16) "\01") @@ -39,60 +38,37 @@ get_local $0 call $~lib/collector/itcm/__gc_mark ) - (func $~lib/collector/itcm/ManagedObject#get:color (; 2 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const 3 - i32.and - ) - (func $~lib/collector/itcm/ManagedObject#get:next (; 3 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const -4 - i32.and - ) - (func $~lib/collector/itcm/ManagedObject#set:next (; 4 ;) (type $iiv) (param $0 i32) (param $1 i32) - get_local $0 - get_local $1 - get_local $0 - i32.load - i32.const 3 - i32.and - i32.or - i32.store - ) - (func $~lib/collector/itcm/ManagedObject#unlink (; 5 ;) (type $iv) (param $0 i32) - (local $1 i32) - get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next - tee_local $1 - get_local $0 - i32.load offset=4 - tee_local $0 - i32.store offset=4 - get_local $0 - get_local $1 - call $~lib/collector/itcm/ManagedObject#set:next - ) - (func $~lib/collector/itcm/ManagedObjectList#push (; 6 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/collector/itcm/ManagedObjectList#push (; 2 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) get_local $0 i32.load offset=4 set_local $2 get_local $1 get_local $0 - call $~lib/collector/itcm/ManagedObject#set:next + get_local $1 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_local $1 get_local $2 i32.store offset=4 get_local $2 get_local $1 - call $~lib/collector/itcm/ManagedObject#set:next + get_local $2 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_local $0 get_local $1 i32.store offset=4 ) - (func $~lib/collector/itcm/ManagedObject#makeGray (; 7 ;) (type $iv) (param $0 i32) + (func $~lib/collector/itcm/ManagedObject#makeGray (; 3 ;) (type $iv) (param $0 i32) + (local $1 i32) + (local $2 i32) get_local $0 get_global $~lib/collector/itcm/iter i32.eq @@ -102,7 +78,22 @@ set_global $~lib/collector/itcm/iter end get_local $0 - call $~lib/collector/itcm/ManagedObject#unlink + i32.load + i32.const -4 + i32.and + tee_local $2 + get_local $0 + i32.load offset=4 + tee_local $1 + i32.store offset=4 + get_local $1 + get_local $2 + get_local $1 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_global $~lib/collector/itcm/toSpace get_local $0 call $~lib/collector/itcm/ManagedObjectList#push @@ -115,7 +106,7 @@ i32.or i32.store ) - (func $~lib/collector/itcm/__gc_mark (; 8 ;) (type $iv) (param $0 i32) + (func $~lib/collector/itcm/__gc_mark (; 4 ;) (type $iv) (param $0 i32) (local $1 i32) get_local $0 if @@ -123,7 +114,9 @@ i32.const 16 i32.sub tee_local $1 - call $~lib/collector/itcm/ManagedObject#get:color + i32.load + i32.const 3 + i32.and get_global $~lib/collector/itcm/white i32.eq if @@ -132,7 +125,7 @@ end end ) - (func $~lib/array/Array~gc (; 9 ;) (type $iv) (param $0 i32) + (func $~lib/array/Array~gc (; 5 ;) (type $iv) (param $0 i32) (local $1 i32) (local $2 i32) get_local $0 @@ -162,7 +155,7 @@ end end ) - (func $~lib/allocator/arena/__memory_allocate (; 10 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/__memory_allocate (; 6 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -224,28 +217,10 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/collector/itcm/ManagedObjectList#clear (; 11 ;) (type $iv) (param $0 i32) - get_local $0 - get_local $0 - i32.store - get_local $0 - get_local $0 - i32.store offset=4 - ) - (func $~lib/collector/itcm/ManagedObject#set:color (; 12 ;) (type $iiv) (param $0 i32) (param $1 i32) - get_local $0 - get_local $0 - i32.load - i32.const -4 - i32.and - get_local $1 - i32.or - i32.store - ) - (func $~lib/allocator/arena/__memory_free (; 13 ;) (type $iv) (param $0 i32) + (func $~lib/allocator/arena/__memory_free (; 7 ;) (type $iv) (param $0 i32) nop ) - (func $~lib/collector/itcm/step (; 14 ;) (type $v) + (func $~lib/collector/itcm/step (; 8 ;) (type $v) (local $0 i32) block $break|0 block $case3|0 @@ -264,34 +239,46 @@ end i32.const 16 call $~lib/allocator/arena/__memory_allocate - tee_local $0 set_global $~lib/collector/itcm/fromSpace get_global $~lib/collector/itcm/fromSpace i32.const -1 i32.store offset=8 get_global $~lib/collector/itcm/fromSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 i32.const 16 call $~lib/allocator/arena/__memory_allocate - tee_local $0 set_global $~lib/collector/itcm/toSpace get_global $~lib/collector/itcm/toSpace i32.const -1 i32.store offset=8 get_global $~lib/collector/itcm/toSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 get_global $~lib/collector/itcm/toSpace set_global $~lib/collector/itcm/iter i32.const 1 set_global $~lib/collector/itcm/state end - call $~iterateRoots + get_global $std/gc-array/arr + i32.const 3 + call_indirect (type $iv) i32.const 2 set_global $~lib/collector/itcm/state br $break|0 end get_global $~lib/collector/itcm/iter - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and tee_local $0 get_global $~lib/collector/itcm/toSpace i32.ne @@ -299,9 +286,14 @@ get_local $0 set_global $~lib/collector/itcm/iter get_local $0 + get_local $0 + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/white i32.eqz - call $~lib/collector/itcm/ManagedObject#set:color + i32.or + i32.store i32.const 1 set_global $~argc get_local $0 @@ -311,9 +303,13 @@ i32.load offset=8 call_indirect (type $iv) else - call $~iterateRoots + get_global $std/gc-array/arr + i32.const 3 + call_indirect (type $iv) get_global $~lib/collector/itcm/iter - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/toSpace i32.eq if @@ -327,7 +323,9 @@ i32.eqz set_global $~lib/collector/itcm/white get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and set_global $~lib/collector/itcm/iter i32.const 3 set_global $~lib/collector/itcm/state @@ -341,24 +339,24 @@ i32.ne if get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and set_global $~lib/collector/itcm/iter - get_local $0 - i32.const 180 - i32.ge_u - if - get_local $0 - call $~lib/allocator/arena/__memory_free - end else get_global $~lib/collector/itcm/toSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 i32.const 1 set_global $~lib/collector/itcm/state end end ) - (func $~lib/collector/itcm/__gc_collect (; 15 ;) (type $v) + (func $~lib/collector/itcm/__gc_collect (; 9 ;) (type $v) (local $0 i32) block $break|0 block $case1|0 @@ -384,10 +382,8 @@ end end ) - (func $~lib/gc/gc.collect (; 16 ;) (type $v) - call $~lib/collector/itcm/__gc_collect - ) - (func $~lib/collector/itcm/__gc_allocate (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/collector/itcm/__gc_allocate (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) get_local $0 i32.const 1073741808 i32.gt_u @@ -399,30 +395,25 @@ i32.const 16 i32.add call $~lib/allocator/arena/__memory_allocate - tee_local $0 + tee_local $2 get_local $1 i32.store offset=8 - get_local $0 + get_local $2 + get_local $2 + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/white - call $~lib/collector/itcm/ManagedObject#set:color + i32.or + i32.store get_global $~lib/collector/itcm/fromSpace - get_local $0 + get_local $2 call $~lib/collector/itcm/ManagedObjectList#push - get_local $0 + get_local $2 i32.const 16 i32.add ) - (func $~lib/internal/arraybuffer/computeSize (; 18 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/internal/memory/memset (; 19 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 11 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) get_local $1 i32.eqz @@ -641,7 +632,7 @@ end end ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 20 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 12 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -654,8 +645,14 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl i32.const 6 call $~lib/collector/itcm/__gc_allocate tee_local $1 @@ -663,7 +660,7 @@ i32.store get_local $1 ) - (func $~lib/internal/memory/memcpy (; 21 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 13 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1567,7 +1564,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 22 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 14 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) get_local $0 @@ -1767,9 +1764,10 @@ end end ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 23 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateUnsafe (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) + (local $4 i32) get_local $1 get_local $0 i32.load @@ -1787,11 +1785,15 @@ call $~lib/env/abort unreachable end - get_local $2 - call $~lib/internal/arraybuffer/computeSize - set_local $3 get_local $1 - get_local $3 + i32.const 1 + i32.const 32 + get_local $2 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl i32.const 8 i32.sub i32.le_s @@ -1814,14 +1816,13 @@ tee_local $3 i32.const 8 i32.add + tee_local $4 get_local $0 i32.const 8 i32.add get_local $2 call $~lib/internal/memory/memmove - get_local $3 - i32.const 8 - i32.add + get_local $4 get_local $2 i32.add get_local $1 @@ -1854,13 +1855,15 @@ end get_local $0 ) - (func $~lib/collector/itcm/__gc_link (; 24 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/collector/itcm/__gc_link (; 16 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) get_local $0 i32.const 16 i32.sub tee_local $2 - call $~lib/collector/itcm/ManagedObject#get:color + i32.load + i32.const 3 + i32.and get_global $~lib/collector/itcm/white i32.eqz i32.eq @@ -1869,7 +1872,9 @@ get_local $1 i32.const 16 i32.sub - call $~lib/collector/itcm/ManagedObject#get:color + i32.load + i32.const 3 + i32.and get_global $~lib/collector/itcm/white i32.eq set_local $0 @@ -1880,8 +1885,9 @@ call $~lib/collector/itcm/ManagedObject#makeGray end ) - (func $~lib/array/Array#__set (; 25 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/array/Array#__set (; 17 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) + (local $4 i32) get_local $1 get_local $0 i32.load @@ -1902,21 +1908,19 @@ call $~lib/env/abort unreachable end + get_local $0 get_local $3 get_local $1 i32.const 1 i32.add + tee_local $4 i32.const 2 i32.shl call $~lib/internal/arraybuffer/reallocateUnsafe - set_local $3 - get_local $0 - get_local $3 + tee_local $3 i32.store get_local $0 - get_local $1 - i32.const 1 - i32.add + get_local $4 i32.store offset=4 end get_local $3 @@ -1930,7 +1934,7 @@ get_local $2 call $~lib/collector/itcm/__gc_link ) - (func $std/gc-array/main (; 26 ;) (type $i) (result i32) + (func $std/gc-array/main (; 18 ;) (type $i) (result i32) get_global $~started i32.eqz if @@ -1940,56 +1944,37 @@ end i32.const 0 ) - (func $start (; 27 ;) (type $v) - (local $0 i32) - (local $1 i32) + (func $start (; 19 ;) (type $v) i32.const 184 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset set_global $~lib/allocator/arena/offset i32.const 0 set_global $~lib/collector/itcm/state - call $~lib/gc/gc.collect + call $~lib/collector/itcm/__gc_collect get_global $std/gc-array/arr - set_local $0 + i32.const 0 i32.const 0 i32.const 4 call $~lib/collector/itcm/__gc_allocate - set_local $1 - get_local $0 - i32.const 0 - get_local $1 call $~lib/array/Array#__set - call $~lib/gc/gc.collect + call $~lib/collector/itcm/__gc_collect get_global $std/gc-array/arr - set_local $0 - i32.const 0 - i32.const 4 - call $~lib/collector/itcm/__gc_allocate - set_local $1 - get_local $0 i32.const 1 - get_local $1 - call $~lib/array/Array#__set - call $~lib/gc/gc.collect - get_global $std/gc-array/arr - set_local $0 i32.const 0 i32.const 4 call $~lib/collector/itcm/__gc_allocate - set_local $1 - get_local $0 - i32.const 0 - get_local $1 call $~lib/array/Array#__set - call $~lib/gc/gc.collect + call $~lib/collector/itcm/__gc_collect + get_global $std/gc-array/arr + i32.const 0 + i32.const 0 + i32.const 4 + call $~lib/collector/itcm/__gc_allocate + call $~lib/array/Array#__set + call $~lib/collector/itcm/__gc_collect ) - (func $null (; 28 ;) (type $v) + (func $null (; 20 ;) (type $v) nop ) - (func $~iterateRoots (; 29 ;) (type $FUNCSIG$v) - get_global $std/gc-array/arr - i32.const 3 - call_indirect (type $iv) - ) ) diff --git a/tests/compiler/std/gc-basics.optimized.wat b/tests/compiler/std/gc-basics.optimized.wat index c083ee0d..b719e9a4 100644 --- a/tests/compiler/std/gc-basics.optimized.wat +++ b/tests/compiler/std/gc-basics.optimized.wat @@ -6,7 +6,6 @@ (type $iiiiv (func (param i32 i32 i32 i32))) (type $i (func (result i32))) (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 16) "\03\00\00\00\00\00\00\00\10\00\00\00s\00t\00d\00/\00g\00c\00-\00b\00a\00s\00i\00c\00s\00.\00t\00s") @@ -91,68 +90,37 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/collector/itcm/ManagedObjectList#clear (; 3 ;) (type $iv) (param $0 i32) - get_local $0 - get_local $0 - i32.store - get_local $0 - get_local $0 - i32.store offset=4 - ) - (func $~lib/collector/itcm/ManagedObject#get:color (; 4 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const 3 - i32.and - ) - (func $~lib/collector/itcm/ManagedObject#get:next (; 5 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const -4 - i32.and - ) - (func $~lib/collector/itcm/ManagedObject#set:next (; 6 ;) (type $iiv) (param $0 i32) (param $1 i32) - get_local $0 - get_local $1 - get_local $0 - i32.load - i32.const 3 - i32.and - i32.or - i32.store - ) - (func $~lib/collector/itcm/ManagedObject#unlink (; 7 ;) (type $iv) (param $0 i32) - (local $1 i32) - get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next - tee_local $1 - get_local $0 - i32.load offset=4 - tee_local $0 - i32.store offset=4 - get_local $0 - get_local $1 - call $~lib/collector/itcm/ManagedObject#set:next - ) - (func $~lib/collector/itcm/ManagedObjectList#push (; 8 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/collector/itcm/ManagedObjectList#push (; 3 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) get_local $0 i32.load offset=4 set_local $2 get_local $1 get_local $0 - call $~lib/collector/itcm/ManagedObject#set:next + get_local $1 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_local $1 get_local $2 i32.store offset=4 get_local $2 get_local $1 - call $~lib/collector/itcm/ManagedObject#set:next + get_local $2 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_local $0 get_local $1 i32.store offset=4 ) - (func $~lib/collector/itcm/ManagedObject#makeGray (; 9 ;) (type $iv) (param $0 i32) + (func $~lib/collector/itcm/ManagedObject#makeGray (; 4 ;) (type $iv) (param $0 i32) + (local $1 i32) + (local $2 i32) get_local $0 get_global $~lib/collector/itcm/iter i32.eq @@ -162,7 +130,22 @@ set_global $~lib/collector/itcm/iter end get_local $0 - call $~lib/collector/itcm/ManagedObject#unlink + i32.load + i32.const -4 + i32.and + tee_local $2 + get_local $0 + i32.load offset=4 + tee_local $1 + i32.store offset=4 + get_local $1 + get_local $2 + get_local $1 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_global $~lib/collector/itcm/toSpace get_local $0 call $~lib/collector/itcm/ManagedObjectList#push @@ -175,7 +158,7 @@ i32.or i32.store ) - (func $~lib/collector/itcm/__gc_mark (; 10 ;) (type $iv) (param $0 i32) + (func $~lib/collector/itcm/__gc_mark (; 5 ;) (type $iv) (param $0 i32) (local $1 i32) get_local $0 if @@ -183,7 +166,9 @@ i32.const 16 i32.sub tee_local $1 - call $~lib/collector/itcm/ManagedObject#get:color + i32.load + i32.const 3 + i32.and get_global $~lib/collector/itcm/white i32.eq if @@ -192,17 +177,7 @@ end end ) - (func $~lib/collector/itcm/ManagedObject#set:color (; 11 ;) (type $iiv) (param $0 i32) (param $1 i32) - get_local $0 - get_local $0 - i32.load - i32.const -4 - i32.and - get_local $1 - i32.or - i32.store - ) - (func $~lib/collector/itcm/step (; 12 ;) (type $v) + (func $~lib/collector/itcm/step (; 6 ;) (type $v) (local $0 i32) block $break|0 block $case3|0 @@ -221,34 +196,49 @@ end i32.const 16 call $~lib/allocator/arena/__memory_allocate - tee_local $0 set_global $~lib/collector/itcm/fromSpace get_global $~lib/collector/itcm/fromSpace i32.const -1 i32.store offset=8 get_global $~lib/collector/itcm/fromSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 i32.const 16 call $~lib/allocator/arena/__memory_allocate - tee_local $0 set_global $~lib/collector/itcm/toSpace get_global $~lib/collector/itcm/toSpace i32.const -1 i32.store offset=8 get_global $~lib/collector/itcm/toSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 get_global $~lib/collector/itcm/toSpace set_global $~lib/collector/itcm/iter i32.const 1 set_global $~lib/collector/itcm/state end - call $~iterateRoots + get_global $std/gc-basics/obj + i32.const 2 + call_indirect (type $iv) + get_global $std/gc-basics/obj2 + i32.const 2 + call_indirect (type $iv) i32.const 2 set_global $~lib/collector/itcm/state br $break|0 end get_global $~lib/collector/itcm/iter - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and tee_local $0 get_global $~lib/collector/itcm/toSpace i32.ne @@ -256,9 +246,14 @@ get_local $0 set_global $~lib/collector/itcm/iter get_local $0 + get_local $0 + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/white i32.eqz - call $~lib/collector/itcm/ManagedObject#set:color + i32.or + i32.store i32.const 1 set_global $~argc get_local $0 @@ -268,9 +263,16 @@ i32.load offset=8 call_indirect (type $iv) else - call $~iterateRoots + get_global $std/gc-basics/obj + i32.const 2 + call_indirect (type $iv) + get_global $std/gc-basics/obj2 + i32.const 2 + call_indirect (type $iv) get_global $~lib/collector/itcm/iter - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/toSpace i32.eq if @@ -284,7 +286,9 @@ i32.eqz set_global $~lib/collector/itcm/white get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and set_global $~lib/collector/itcm/iter i32.const 3 set_global $~lib/collector/itcm/state @@ -298,24 +302,24 @@ i32.ne if get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and set_global $~lib/collector/itcm/iter - get_local $0 - i32.const 60 - i32.ge_u - if - get_local $0 - call $std/gc-basics/MyObject_visit - end else get_global $~lib/collector/itcm/toSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 i32.const 1 set_global $~lib/collector/itcm/state end end ) - (func $~lib/collector/itcm/__gc_allocate (; 13 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/collector/itcm/__gc_allocate (; 7 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) call $~lib/collector/itcm/step i32.const 20 @@ -324,8 +328,13 @@ i32.const 1 i32.store offset=8 get_local $0 + get_local $0 + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/white - call $~lib/collector/itcm/ManagedObject#set:color + i32.or + i32.store get_global $~lib/collector/itcm/fromSpace get_local $0 call $~lib/collector/itcm/ManagedObjectList#push @@ -333,7 +342,7 @@ i32.const 16 i32.add ) - (func $~lib/string/String~gc (; 14 ;) (type $iv) (param $0 i32) + (func $~lib/string/String~gc (; 8 ;) (type $iv) (param $0 i32) get_local $0 i32.eqz if @@ -342,7 +351,7 @@ get_local $0 call $~lib/collector/itcm/__gc_mark ) - (func $~lib/collector/itcm/__gc_collect (; 15 ;) (type $v) + (func $~lib/collector/itcm/__gc_collect (; 9 ;) (type $v) (local $0 i32) block $break|0 block $case1|0 @@ -368,10 +377,7 @@ end end ) - (func $~lib/gc/gc.collect (; 16 ;) (type $v) - call $~lib/collector/itcm/__gc_collect - ) - (func $std/gc-basics/main (; 17 ;) (type $i) (result i32) + (func $std/gc-basics/main (; 10 ;) (type $i) (result i32) get_global $~started i32.eqz if @@ -381,7 +387,7 @@ end i32.const 0 ) - (func $start (; 18 ;) (type $v) + (func $start (; 11 ;) (type $v) (local $0 i32) (local $1 i32) (local $2 i32) @@ -468,20 +474,12 @@ call $~lib/env/abort unreachable end - call $~lib/gc/gc.collect + call $~lib/collector/itcm/__gc_collect i32.const 0 set_global $std/gc-basics/obj - call $~lib/gc/gc.collect + call $~lib/collector/itcm/__gc_collect ) - (func $null (; 19 ;) (type $v) + (func $null (; 12 ;) (type $v) nop ) - (func $~iterateRoots (; 20 ;) (type $FUNCSIG$v) - get_global $std/gc-basics/obj - i32.const 2 - call_indirect (type $iv) - get_global $std/gc-basics/obj2 - i32.const 2 - call_indirect (type $iv) - ) ) diff --git a/tests/compiler/std/gc-integration.optimized.wat b/tests/compiler/std/gc-integration.optimized.wat index 53c2903b..c5faa5a8 100644 --- a/tests/compiler/std/gc-integration.optimized.wat +++ b/tests/compiler/std/gc-integration.optimized.wat @@ -2,7 +2,6 @@ (type $iv (func (param i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) - (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\15\00\00\00s\00t\00d\00/\00g\00c\00-\00i\00n\00t\00e\00g\00r\00a\00t\00i\00o\00n\00.\00t\00s") @@ -35,7 +34,18 @@ end ) (func $start (; 2 ;) (type $v) - call $~iterateRoots + i32.const 8 + i32.const 1 + call_indirect (type $iv) + get_global $std/gc-integration/B.d + i32.const 1 + call_indirect (type $iv) + get_global $std/gc-integration/a_ref + i32.const 1 + call_indirect (type $iv) + get_global $std/gc-integration/b_ref + i32.const 1 + call_indirect (type $iv) get_global $std/gc-integration/i i32.const 4 i32.ne @@ -51,18 +61,4 @@ (func $null (; 3 ;) (type $v) nop ) - (func $~iterateRoots (; 4 ;) (type $FUNCSIG$v) - i32.const 8 - i32.const 1 - call_indirect (type $iv) - get_global $std/gc-integration/B.d - i32.const 1 - call_indirect (type $iv) - get_global $std/gc-integration/a_ref - i32.const 1 - call_indirect (type $iv) - get_global $std/gc-integration/b_ref - i32.const 1 - call_indirect (type $iv) - ) ) diff --git a/tests/compiler/std/gc-object.optimized.wat b/tests/compiler/std/gc-object.optimized.wat index 2709de3b..801fade4 100644 --- a/tests/compiler/std/gc-object.optimized.wat +++ b/tests/compiler/std/gc-object.optimized.wat @@ -3,7 +3,6 @@ (type $ii (func (param i32) (result i32))) (type $iv (func (param i32))) (type $iiv (func (param i32 i32))) - (type $FUNCSIG$v (func)) (type $FUNCSIG$i (func (result i32))) (memory $0 0) (table $0 4 anyfunc) @@ -83,68 +82,37 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/collector/itcm/ManagedObjectList#clear (; 1 ;) (type $iv) (param $0 i32) - get_local $0 - get_local $0 - i32.store - get_local $0 - get_local $0 - i32.store offset=4 - ) - (func $~lib/collector/itcm/ManagedObject#get:color (; 2 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const 3 - i32.and - ) - (func $~lib/collector/itcm/ManagedObject#get:next (; 3 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const -4 - i32.and - ) - (func $~lib/collector/itcm/ManagedObject#set:next (; 4 ;) (type $iiv) (param $0 i32) (param $1 i32) - get_local $0 - get_local $1 - get_local $0 - i32.load - i32.const 3 - i32.and - i32.or - i32.store - ) - (func $~lib/collector/itcm/ManagedObject#unlink (; 5 ;) (type $iv) (param $0 i32) - (local $1 i32) - get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next - tee_local $1 - get_local $0 - i32.load offset=4 - tee_local $0 - i32.store offset=4 - get_local $0 - get_local $1 - call $~lib/collector/itcm/ManagedObject#set:next - ) - (func $~lib/collector/itcm/ManagedObjectList#push (; 6 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/collector/itcm/ManagedObjectList#push (; 1 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) get_local $0 i32.load offset=4 set_local $2 get_local $1 get_local $0 - call $~lib/collector/itcm/ManagedObject#set:next + get_local $1 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_local $1 get_local $2 i32.store offset=4 get_local $2 get_local $1 - call $~lib/collector/itcm/ManagedObject#set:next + get_local $2 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_local $0 get_local $1 i32.store offset=4 ) - (func $~lib/collector/itcm/ManagedObject#makeGray (; 7 ;) (type $iv) (param $0 i32) + (func $~lib/collector/itcm/ManagedObject#makeGray (; 2 ;) (type $iv) (param $0 i32) + (local $1 i32) + (local $2 i32) get_local $0 get_global $~lib/collector/itcm/iter i32.eq @@ -154,7 +122,22 @@ set_global $~lib/collector/itcm/iter end get_local $0 - call $~lib/collector/itcm/ManagedObject#unlink + i32.load + i32.const -4 + i32.and + tee_local $2 + get_local $0 + i32.load offset=4 + tee_local $1 + i32.store offset=4 + get_local $1 + get_local $2 + get_local $1 + i32.load + i32.const 3 + i32.and + i32.or + i32.store get_global $~lib/collector/itcm/toSpace get_local $0 call $~lib/collector/itcm/ManagedObjectList#push @@ -167,7 +150,7 @@ i32.or i32.store ) - (func $~lib/collector/itcm/__gc_mark (; 8 ;) (type $iv) (param $0 i32) + (func $~lib/collector/itcm/__gc_mark (; 3 ;) (type $iv) (param $0 i32) (local $1 i32) get_local $0 if @@ -175,7 +158,9 @@ i32.const 16 i32.sub tee_local $1 - call $~lib/collector/itcm/ManagedObject#get:color + i32.load + i32.const 3 + i32.and get_global $~lib/collector/itcm/white i32.eq if @@ -184,20 +169,7 @@ end end ) - (func $~lib/collector/itcm/ManagedObject#set:color (; 9 ;) (type $iiv) (param $0 i32) (param $1 i32) - get_local $0 - get_local $0 - i32.load - i32.const -4 - i32.and - get_local $1 - i32.or - i32.store - ) - (func $~lib/allocator/arena/__memory_free (; 10 ;) (type $FUNCSIG$v) - nop - ) - (func $~lib/collector/itcm/step (; 11 ;) (type $v) + (func $~lib/collector/itcm/step (; 4 ;) (type $v) (local $0 i32) block $break|0 block $case3|0 @@ -216,34 +188,46 @@ end i32.const 16 call $~lib/allocator/arena/__memory_allocate - tee_local $0 set_global $~lib/collector/itcm/fromSpace get_global $~lib/collector/itcm/fromSpace i32.const -1 i32.store offset=8 get_global $~lib/collector/itcm/fromSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 i32.const 16 call $~lib/allocator/arena/__memory_allocate - tee_local $0 set_global $~lib/collector/itcm/toSpace get_global $~lib/collector/itcm/toSpace i32.const -1 i32.store offset=8 get_global $~lib/collector/itcm/toSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 get_global $~lib/collector/itcm/toSpace set_global $~lib/collector/itcm/iter i32.const 1 set_global $~lib/collector/itcm/state end - call $~iterateRoots + get_global $std/gc-object/obj + i32.const 1 + call_indirect (type $iv) i32.const 2 set_global $~lib/collector/itcm/state br $break|0 end get_global $~lib/collector/itcm/iter - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and tee_local $0 get_global $~lib/collector/itcm/toSpace i32.ne @@ -251,9 +235,14 @@ get_local $0 set_global $~lib/collector/itcm/iter get_local $0 + get_local $0 + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/white i32.eqz - call $~lib/collector/itcm/ManagedObject#set:color + i32.or + i32.store i32.const 1 set_global $~argc get_local $0 @@ -263,9 +252,13 @@ i32.load offset=8 call_indirect (type $iv) else - call $~iterateRoots + get_global $std/gc-object/obj + i32.const 1 + call_indirect (type $iv) get_global $~lib/collector/itcm/iter - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/toSpace i32.eq if @@ -279,7 +272,9 @@ i32.eqz set_global $~lib/collector/itcm/white get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and set_global $~lib/collector/itcm/iter i32.const 3 set_global $~lib/collector/itcm/state @@ -293,23 +288,24 @@ i32.ne if get_local $0 - call $~lib/collector/itcm/ManagedObject#get:next + i32.load + i32.const -4 + i32.and set_global $~lib/collector/itcm/iter - get_local $0 - i32.const 8 - i32.ge_u - if - call $~lib/allocator/arena/__memory_free - end else get_global $~lib/collector/itcm/toSpace - call $~lib/collector/itcm/ManagedObjectList#clear + tee_local $0 + get_local $0 + i32.store + get_local $0 + get_local $0 + i32.store offset=4 i32.const 1 set_global $~lib/collector/itcm/state end end ) - (func $~lib/collector/itcm/__gc_allocate (; 12 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/collector/itcm/__gc_allocate (; 5 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) call $~lib/collector/itcm/step i32.const 24 @@ -318,8 +314,13 @@ i32.const 2 i32.store offset=8 get_local $0 + get_local $0 + i32.load + i32.const -4 + i32.and get_global $~lib/collector/itcm/white - call $~lib/collector/itcm/ManagedObject#set:color + i32.or + i32.store get_global $~lib/collector/itcm/fromSpace get_local $0 call $~lib/collector/itcm/ManagedObjectList#push @@ -327,7 +328,7 @@ i32.const 16 i32.add ) - (func $std/gc-object/Base~gc (; 13 ;) (type $iv) (param $0 i32) + (func $std/gc-object/Base~gc (; 6 ;) (type $iv) (param $0 i32) get_local $0 i32.eqz if @@ -336,7 +337,7 @@ get_local $0 call $~lib/collector/itcm/__gc_mark ) - (func $std/gc-object/Custom~gc (; 14 ;) (type $iv) (param $0 i32) + (func $std/gc-object/Custom~gc (; 7 ;) (type $iv) (param $0 i32) get_local $0 i32.eqz if @@ -352,7 +353,7 @@ i32.load offset=4 call $~lib/collector/itcm/__gc_mark ) - (func $~lib/collector/itcm/__gc_collect (; 15 ;) (type $v) + (func $~lib/collector/itcm/__gc_collect (; 8 ;) (type $v) (local $0 i32) block $break|0 block $case1|0 @@ -378,10 +379,7 @@ end end ) - (func $~lib/gc/gc.collect (; 16 ;) (type $v) - call $~lib/collector/itcm/__gc_collect - ) - (func $std/gc-object/main (; 17 ;) (type $v) + (func $std/gc-object/main (; 9 ;) (type $v) get_global $~started i32.eqz if @@ -390,7 +388,7 @@ set_global $~started end ) - (func $start (; 18 ;) (type $v) + (func $start (; 10 ;) (type $v) (local $0 i32) i32.const 8 set_global $~lib/allocator/arena/startOffset @@ -407,21 +405,16 @@ i32.store offset=4 get_local $0 set_global $std/gc-object/obj - call $~lib/gc/gc.collect + call $~lib/collector/itcm/__gc_collect get_global $std/gc-object/obj get_global $std/gc-object/obj i32.store - call $~lib/gc/gc.collect + call $~lib/collector/itcm/__gc_collect i32.const 0 set_global $std/gc-object/obj - call $~lib/gc/gc.collect + call $~lib/collector/itcm/__gc_collect ) - (func $null (; 19 ;) (type $v) + (func $null (; 11 ;) (type $v) nop ) - (func $~iterateRoots (; 20 ;) (type $FUNCSIG$v) - get_global $std/gc-object/obj - i32.const 1 - call_indirect (type $iv) - ) ) diff --git a/tests/compiler/std/hash.optimized.wat b/tests/compiler/std/hash.optimized.wat index 43fc01e6..985ae420 100644 --- a/tests/compiler/std/hash.optimized.wat +++ b/tests/compiler/std/hash.optimized.wat @@ -48,10 +48,7 @@ end get_local $2 ) - (func $std/hash/check (; 1 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - ) - (func $~lib/internal/hash/hash32 (; 2 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/hash/hash32 (; 1 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 255 i32.and @@ -82,7 +79,7 @@ i32.const 16777619 i32.mul ) - (func $~lib/internal/hash/hash64 (; 3 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/hash/hash64 (; 2 ;) (type $Ii) (param $0 i64) (result i32) (local $1 i32) get_local $0 i32.wrap/i64 @@ -148,77 +145,60 @@ i32.const 16777619 i32.mul ) - (func $start (; 4 ;) (type $v) + (func $start (; 3 ;) (type $v) i32.const 0 call $~lib/internal/hash/hashStr - call $std/hash/check drop i32.const 8 call $~lib/internal/hash/hashStr - call $std/hash/check drop i32.const 16 call $~lib/internal/hash/hashStr - call $std/hash/check drop i32.const 24 call $~lib/internal/hash/hashStr - call $std/hash/check drop i32.const 32 call $~lib/internal/hash/hashStr - call $std/hash/check drop i32.const 0 call $~lib/internal/hash/hash32 - call $std/hash/check drop i32.const 1065353216 call $~lib/internal/hash/hash32 - call $std/hash/check drop i32.const 1066192077 call $~lib/internal/hash/hash32 - call $std/hash/check drop i32.const 0 call $~lib/internal/hash/hash32 - call $std/hash/check drop i32.const 2139095040 call $~lib/internal/hash/hash32 - call $std/hash/check drop i32.const 2143289344 call $~lib/internal/hash/hash32 - call $std/hash/check drop i64.const 0 call $~lib/internal/hash/hash64 - call $std/hash/check drop i64.const 4607182418800017408 call $~lib/internal/hash/hash64 - call $std/hash/check drop i64.const 4607632778762754458 call $~lib/internal/hash/hash64 - call $std/hash/check drop i64.const 0 call $~lib/internal/hash/hash64 - call $std/hash/check drop i64.const 9218868437227405312 call $~lib/internal/hash/hash64 - call $std/hash/check drop i64.const 9221120237041090560 call $~lib/internal/hash/hash64 - call $std/hash/check drop ) - (func $null (; 5 ;) (type $v) + (func $null (; 4 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/libm.optimized.wat b/tests/compiler/std/libm.optimized.wat index eedadf97..30be1303 100644 --- a/tests/compiler/std/libm.optimized.wat +++ b/tests/compiler/std/libm.optimized.wat @@ -1,11 +1,9 @@ (module (type $FF (func (param f64) (result f64))) - (type $Fi (func (param f64) (result i32))) (type $FFF (func (param f64 f64) (result f64))) (type $FiF (func (param f64 i32) (result f64))) (type $Ff (func (param f64) (result f32))) (type $v (func)) - (type $FUNCSIG$d (func (result f64))) (memory $0 0) (table $0 1 anyfunc) (elem (i32.const 0) $null) @@ -163,16 +161,14 @@ f64.const 1.5707963267948966 return end - get_local $0 - get_local $0 - f64.mul - call $~lib/math/R - set_local $1 f64.const 1.5707963267948966 get_local $0 f64.const 6.123233995736766e-17 get_local $0 - get_local $1 + get_local $0 + get_local $0 + f64.mul + call $~lib/math/R f64.mul f64.sub f64.sub @@ -183,6 +179,8 @@ i32.const 31 i32.shr_u if + f64.const 2 + f64.const 1.5707963267948966 f64.const 0.5 get_local $0 f64.const 0.5 @@ -190,14 +188,9 @@ f64.add tee_local $1 f64.sqrt - set_local $0 + tee_local $0 get_local $1 call $~lib/math/R - set_local $1 - f64.const 2 - f64.const 1.5707963267948966 - get_local $0 - get_local $1 get_local $0 f64.mul f64.const 6.123233995736766e-17 @@ -230,12 +223,10 @@ f64.add f64.div set_local $5 - get_local $1 - call $~lib/math/R - set_local $1 f64.const 2 get_local $3 get_local $1 + call $~lib/math/R get_local $0 f64.mul get_local $5 @@ -749,12 +740,10 @@ end get_local $0 get_local $0 + get_local $0 + get_local $0 f64.mul call $~lib/math/R - set_local $1 - get_local $0 - get_local $0 - get_local $1 f64.mul f64.add return @@ -911,12 +900,7 @@ get_local $0 call $~lib/math/NativeMath.asinh ) - (func $~lib/builtins/isNaN (; 12 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.ne - ) - (func $~lib/math/NativeMath.atan (; 13 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.atan (; 12 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 f64) @@ -935,7 +919,8 @@ i32.ge_u if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne if get_local $0 return @@ -1141,11 +1126,11 @@ get_local $4 f64.copysign ) - (func $std/libm/atan (; 14 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/atan (; 13 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.atan ) - (func $~lib/math/NativeMath.atanh (; 15 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.atanh (; 14 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i64) (local $3 i64) @@ -1205,11 +1190,11 @@ get_local $0 f64.copysign ) - (func $std/libm/atanh (; 16 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/atanh (; 15 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.atanh ) - (func $~lib/math/NativeMath.atan2 (; 17 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.atan2 (; 16 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1218,12 +1203,14 @@ (local $7 i32) block $folding-inner0 get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f64.ne tee_local $2 i32.eqz if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne set_local $2 end get_local $2 @@ -1465,12 +1452,12 @@ end tee_local $0 ) - (func $std/libm/atan2 (; 18 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/atan2 (; 17 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) get_local $0 get_local $1 call $~lib/math/NativeMath.atan2 ) - (func $~lib/math/NativeMath.cbrt (; 19 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.cbrt (; 18 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -1592,27 +1579,24 @@ f64.mul f64.add ) - (func $std/libm/cbrt (; 20 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/cbrt (; 19 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.cbrt ) - (func $std/libm/ceil (; 21 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/ceil (; 20 ;) (type $FF) (param $0 f64) (result f64) get_local $0 f64.ceil ) - (func $std/libm/clz32 (; 22 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/clz32 (; 21 ;) (type $FF) (param $0 f64) (result f64) get_local $0 i32.trunc_s/f64 i32.clz f64.convert_s/i32 ) - (func $~lib/math/NativeMath.cos (; 23 ;) (type $FUNCSIG$d) (result f64) + (func $std/libm/cos (; 22 ;) (type $FF) (param $0 f64) (result f64) unreachable ) - (func $std/libm/cos (; 24 ;) (type $FF) (param $0 f64) (result f64) - call $~lib/math/NativeMath.cos - ) - (func $~lib/math/NativeMath.expm1 (; 25 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.expm1 (; 23 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -1621,6 +1605,7 @@ (local $6 i32) (local $7 i64) (local $8 f64) + (local $9 f64) get_local $0 i64.reinterpret/f64 tee_local $7 @@ -1639,7 +1624,8 @@ i32.ge_u if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne if get_local $0 return @@ -1736,9 +1722,10 @@ f64.add f64.mul f64.add + tee_local $9 set_local $1 get_local $2 - get_local $1 + get_local $9 f64.const 3 get_local $1 get_local $8 @@ -1891,7 +1878,7 @@ get_local $5 f64.mul ) - (func $~lib/math/NativeMath.scalbn (; 26 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/NativeMath.scalbn (; 24 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) get_local $1 i32.const 1023 i32.gt_s @@ -1965,12 +1952,12 @@ f64.reinterpret/i64 f64.mul ) - (func $~lib/math/NativeMath.exp (; 27 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.exp (; 25 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 i32) (local $3 f64) - (local $4 f64) - (local $5 i32) + (local $4 i32) + (local $5 f64) get_local $0 i64.reinterpret/f64 i64.const 32 @@ -1979,7 +1966,7 @@ tee_local $1 i32.const 31 i32.shr_u - set_local $5 + set_local $4 get_local $1 i32.const 2147483647 i32.and @@ -1988,7 +1975,8 @@ i32.ge_u if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne if get_local $0 return @@ -2029,7 +2017,7 @@ i32.trunc_s/f64 else i32.const 1 - get_local $5 + get_local $4 i32.const 1 i32.shl i32.sub @@ -2040,26 +2028,25 @@ f64.const 0.6931471803691238 f64.mul f64.sub - tee_local $4 + tee_local $3 get_local $0 f64.const 1.9082149292705877e-10 f64.mul - tee_local $3 + tee_local $5 f64.sub set_local $0 else get_local $1 i32.const 1043333120 - i32.gt_u - if (result f64) - get_local $0 - else + i32.le_u + if f64.const 1 get_local $0 f64.add return end - set_local $4 + get_local $0 + set_local $3 end f64.const 1 get_local $0 @@ -2093,9 +2080,9 @@ get_local $0 f64.sub f64.div - get_local $3 + get_local $5 f64.sub - get_local $4 + get_local $3 f64.add f64.add set_local $0 @@ -2109,7 +2096,7 @@ get_local $2 call $~lib/math/NativeMath.scalbn ) - (func $~lib/math/NativeMath.cosh (; 28 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.cosh (; 26 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 i64) get_local $0 @@ -2173,27 +2160,27 @@ f64.const 2247116418577894884661631e283 f64.mul ) - (func $std/libm/cosh (; 29 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/cosh (; 27 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.cosh ) - (func $std/libm/exp (; 30 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/exp (; 28 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.exp ) - (func $std/libm/expm1 (; 31 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/expm1 (; 29 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.expm1 ) - (func $std/libm/floor (; 32 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/floor (; 30 ;) (type $FF) (param $0 f64) (result f64) get_local $0 f64.floor ) - (func $std/libm/fround (; 33 ;) (type $Ff) (param $0 f64) (result f32) + (func $std/libm/fround (; 31 ;) (type $Ff) (param $0 f64) (result f32) get_local $0 f32.demote/f64 ) - (func $~lib/math/NativeMath.hypot (; 34 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.hypot (; 32 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 i64) (local $4 f64) @@ -2373,12 +2360,12 @@ f64.sqrt f64.mul ) - (func $std/libm/hypot (; 35 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/hypot (; 33 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) get_local $0 get_local $1 call $~lib/math/NativeMath.hypot ) - (func $~lib/math/NativeMath.imul (; 36 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/imul (; 34 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) get_local $0 i32.trunc_s/f64 get_local $1 @@ -2386,16 +2373,11 @@ i32.mul f64.convert_s/i32 ) - (func $std/libm/imul (; 37 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) - get_local $0 - get_local $1 - call $~lib/math/NativeMath.imul - ) - (func $std/libm/log (; 38 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log (; 35 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.log ) - (func $~lib/math/NativeMath.log10 (; 39 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log10 (; 36 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 f64) (local $3 i32) @@ -2610,15 +2592,15 @@ get_local $0 f64.add ) - (func $std/libm/log10 (; 40 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log10 (; 37 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.log10 ) - (func $std/libm/log1p (; 41 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log1p (; 38 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.log1p ) - (func $~lib/math/NativeMath.log2 (; 42 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log2 (; 39 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 f64) (local $3 i32) @@ -2827,21 +2809,21 @@ tee_local $2 f64.add ) - (func $std/libm/log2 (; 43 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/log2 (; 40 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.log2 ) - (func $std/libm/max (; 44 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/max (; 41 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) get_local $0 get_local $1 f64.max ) - (func $std/libm/min (; 45 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/min (; 42 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) get_local $0 get_local $1 f64.min ) - (func $~lib/math/NativeMath.pow (; 46 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 43 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) (local $4 i32) @@ -3710,6 +3692,7 @@ get_local $2 f64.mul set_local $3 + get_local $13 f64.const 1 get_local $2 get_local $2 @@ -3783,9 +3766,7 @@ i64.or f64.reinterpret/i64 end - set_local $2 - get_local $13 - get_local $2 + tee_local $2 f64.mul return end @@ -3802,12 +3783,12 @@ f64.const 1.e+300 f64.mul ) - (func $std/libm/pow (; 47 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $std/libm/pow (; 44 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) get_local $0 get_local $1 call $~lib/math/NativeMath.pow ) - (func $std/libm/round (; 48 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/round (; 45 ;) (type $FF) (param $0 f64) (result f64) get_local $0 f64.const 0.5 f64.add @@ -3815,7 +3796,7 @@ get_local $0 f64.copysign ) - (func $std/libm/sign (; 49 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sign (; 46 ;) (type $FF) (param $0 f64) (result f64) get_local $0 f64.const 0 f64.gt @@ -3833,7 +3814,7 @@ end get_local $0 ) - (func $~lib/math/NativeMath.sinh (; 50 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.sinh (; 47 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -3900,7 +3881,6 @@ f64.const 2 get_local $2 f64.mul - set_local $0 get_local $1 f64.const 1416.0996898839683 f64.sub @@ -3909,20 +3889,17 @@ f64.mul f64.const 2247116418577894884661631e283 f64.mul - set_local $1 - get_local $0 - get_local $1 f64.mul ) - (func $std/libm/sinh (; 51 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sinh (; 48 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.sinh ) - (func $std/libm/sqrt (; 52 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/sqrt (; 49 ;) (type $FF) (param $0 f64) (result f64) get_local $0 f64.sqrt ) - (func $~lib/math/NativeMath.tanh (; 53 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.tanh (; 50 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i64) @@ -4001,15 +3978,15 @@ get_local $0 f64.copysign ) - (func $std/libm/tanh (; 54 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/tanh (; 51 ;) (type $FF) (param $0 f64) (result f64) get_local $0 call $~lib/math/NativeMath.tanh ) - (func $std/libm/trunc (; 55 ;) (type $FF) (param $0 f64) (result f64) + (func $std/libm/trunc (; 52 ;) (type $FF) (param $0 f64) (result f64) get_local $0 f64.trunc ) - (func $null (; 56 ;) (type $v) + (func $null (; 53 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/map.optimized.wat b/tests/compiler/std/map.optimized.wat index 3a64c4c3..7b278c08 100644 --- a/tests/compiler/std/map.optimized.wat +++ b/tests/compiler/std/map.optimized.wat @@ -17,9 +17,9 @@ (type $iFi (func (param i32 f64) (result i32))) (type $iFii (func (param i32 f64 i32) (result i32))) (type $iFiv (func (param i32 f64 i32))) - (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\13\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") @@ -94,21 +94,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 2 ;) (type $FUNCSIG$i) (result i32) - i32.const 24 - call $~lib/allocator/arena/__memory_allocate - ) - (func $~lib/internal/arraybuffer/computeSize (; 3 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -121,15 +107,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/internal/memory/memset (; 5 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) get_local $1 i32.eqz @@ -348,7 +340,7 @@ end end ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 6 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 i32.const 1073741816 @@ -377,24 +369,19 @@ end get_local $2 ) - (func $~lib/map/Map#clear (; 7 ;) (type $iv) (param $0 i32) - (local $1 i32) + (func $~lib/map/Map#clear (; 5 ;) (type $iv) (param $0 i32) + get_local $0 i32.const 16 i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store get_local $0 i32.const 3 i32.store offset=4 + get_local $0 i32.const 48 i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store offset=8 get_local $0 i32.const 4 @@ -406,9 +393,10 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map#constructor (; 8 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 6 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) - call $~lib/memory/memory.allocate + i32.const 24 + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 0 i32.store @@ -431,14 +419,7 @@ call $~lib/map/Map#clear get_local $0 ) - (func $~lib/internal/hash/hash8 (; 9 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const -2128831035 - i32.xor - i32.const 16777619 - i32.mul - ) - (func $~lib/map/Map#find (; 10 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -483,23 +464,23 @@ end i32.const 0 ) - (func $~lib/map/Map#has (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) + (func $~lib/map/Map#has (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + get_local $0 + get_local $1 get_local $1 i32.const 24 i32.shl i32.const 24 i32.shr_s - call $~lib/internal/hash/hash8 - set_local $2 - get_local $0 - get_local $1 - get_local $2 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find i32.const 0 i32.ne ) - (func $~lib/map/Map#rehash (; 12 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 9 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -515,100 +496,101 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 12 i32.mul i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 12 i32.mul i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 - get_local $8 + get_local $2 + get_local $7 i32.ne if - get_local $3 + get_local $2 i32.load offset=8 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 i32.load8_s i32.store8 - get_local $2 get_local $3 + get_local $2 i32.load offset=4 i32.store offset=4 get_local $3 - i32.load8_s - call $~lib/internal/hash/hash8 - set_local $4 - get_local $2 - get_local $5 get_local $4 + get_local $2 + i32.load8_s + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=8 - get_local $4 - get_local $2 + get_local $8 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 12 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 12 i32.add - set_local $3 + set_local $2 br $continue|0 end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 13 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map#set (; 10 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -617,11 +599,15 @@ i32.shl i32.const 24 i32.shr_s - call $~lib/internal/hash/hash8 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul + tee_local $3 set_local $5 get_local $0 get_local $1 - get_local $5 + get_local $3 call $~lib/map/Map#find tee_local $3 if @@ -706,18 +692,18 @@ i32.store offset=8 end ) - (func $~lib/map/Map#get (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) + (func $~lib/map/Map#get (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + get_local $0 + get_local $1 get_local $1 i32.const 24 i32.shl i32.const 24 i32.shr_s - call $~lib/internal/hash/hash8 - set_local $2 - get_local $0 - get_local $1 - get_local $2 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find tee_local $0 if (result i32) @@ -726,83 +712,77 @@ else unreachable end - tee_local $0 ) - (func $~lib/map/Map#get:size (; 15 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load offset=20 - ) - (func $~lib/map/Map#delete (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#delete (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.const 24 i32.shl i32.const 24 i32.shr_s - call $~lib/internal/hash/hash8 - set_local $0 - get_local $2 - get_local $1 - get_local $0 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=8 i32.const 1 i32.or i32.store offset=8 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/map/Map#rehash end i32.const 1 ) - (func $std/map/test (; 17 ;) (type $v) + (func $std/map/test (; 13 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/map/Map#constructor @@ -877,7 +857,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -980,7 +960,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -1057,7 +1037,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -1136,7 +1116,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -1150,7 +1130,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -1160,21 +1140,21 @@ unreachable end ) - (func $~lib/map/Map#has (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) + (func $~lib/map/Map#has (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + get_local $0 + get_local $1 get_local $1 i32.const 255 i32.and - call $~lib/internal/hash/hash8 - set_local $2 - get_local $0 - get_local $1 - get_local $2 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find i32.const 0 i32.ne ) - (func $~lib/map/Map#rehash (; 19 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 15 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1190,111 +1170,116 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 12 i32.mul i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 12 i32.mul i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 - get_local $8 + get_local $2 + get_local $7 i32.ne if - get_local $3 + get_local $2 i32.load offset=8 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 i32.load8_u i32.store8 - get_local $2 get_local $3 + get_local $2 i32.load offset=4 i32.store offset=4 get_local $3 - i32.load8_u - call $~lib/internal/hash/hash8 - set_local $4 - get_local $2 - get_local $5 get_local $4 + get_local $2 + i32.load8_u + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=8 - get_local $4 - get_local $2 + get_local $8 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 12 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 12 i32.add - set_local $3 + set_local $2 br $continue|0 end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 20 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map#set (; 16 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) get_local $1 i32.const 255 i32.and - call $~lib/internal/hash/hash8 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul + tee_local $3 set_local $5 get_local $0 get_local $1 - get_local $5 + get_local $3 call $~lib/map/Map#find tee_local $3 if @@ -1379,16 +1364,16 @@ i32.store offset=8 end ) - (func $~lib/map/Map#get (; 21 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) + (func $~lib/map/Map#get (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + get_local $0 + get_local $1 get_local $1 i32.const 255 i32.and - call $~lib/internal/hash/hash8 - set_local $2 - get_local $0 - get_local $1 - get_local $2 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find tee_local $0 if (result i32) @@ -1397,77 +1382,75 @@ else unreachable end - tee_local $0 ) - (func $~lib/map/Map#delete (; 22 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#delete (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.const 255 i32.and - call $~lib/internal/hash/hash8 - set_local $0 - get_local $2 - get_local $1 - get_local $0 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=8 i32.const 1 i32.or i32.store offset=8 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/map/Map#rehash end i32.const 1 ) - (func $std/map/test (; 23 ;) (type $v) + (func $std/map/test (; 19 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/map/Map#constructor @@ -1538,7 +1521,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -1635,7 +1618,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -1710,7 +1693,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -1787,7 +1770,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -1801,7 +1784,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -1811,22 +1794,7 @@ unreachable end ) - (func $~lib/internal/hash/hash16 (; 24 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 255 - i32.and - i32.const -2128831035 - i32.xor - i32.const 16777619 - i32.mul - get_local $0 - i32.const 8 - i32.shr_u - i32.xor - i32.const 16777619 - i32.mul - ) - (func $~lib/map/Map#find (; 25 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 20 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -1871,23 +1839,33 @@ end i32.const 0 ) - (func $~lib/map/Map#has (; 26 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#has (; 21 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) + get_local $0 + get_local $1 get_local $1 i32.const 16 i32.shl i32.const 16 i32.shr_s - call $~lib/internal/hash/hash16 - set_local $2 - get_local $0 - get_local $1 + tee_local $2 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $2 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find i32.const 0 i32.ne ) - (func $~lib/map/Map#rehash (; 27 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 22 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1919,7 +1897,7 @@ i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 12 @@ -1929,33 +1907,43 @@ get_local $6 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 + get_local $2 get_local $8 i32.ne if - get_local $3 + get_local $2 i32.load offset=8 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 i32.load16_s i32.store16 - get_local $2 get_local $3 + get_local $2 i32.load offset=4 i32.store offset=4 get_local $3 - i32.load16_s - call $~lib/internal/hash/hash16 - set_local $4 - get_local $2 get_local $5 + get_local $2 + i32.load16_s + tee_local $4 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $4 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul get_local $1 i32.and i32.const 2 @@ -1965,17 +1953,17 @@ i32.load offset=8 i32.store offset=8 get_local $4 - get_local $2 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 12 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 12 i32.add - set_local $3 + set_local $2 br $continue|0 end end @@ -1996,7 +1984,7 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 28 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map#set (; 23 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -2005,11 +1993,24 @@ i32.shl i32.const 16 i32.shr_s - call $~lib/internal/hash/hash16 + tee_local $3 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul + get_local $3 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul + tee_local $3 set_local $5 get_local $0 get_local $1 - get_local $5 + get_local $3 call $~lib/map/Map#find tee_local $3 if @@ -2094,18 +2095,27 @@ i32.store offset=8 end ) - (func $~lib/map/Map#get (; 29 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) + (func $~lib/map/Map#get (; 24 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + get_local $0 + get_local $1 get_local $1 i32.const 16 i32.shl i32.const 16 i32.shr_s - call $~lib/internal/hash/hash16 - set_local $2 + tee_local $0 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $0 - get_local $1 - get_local $2 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find tee_local $0 if (result i32) @@ -2116,77 +2126,85 @@ end tee_local $0 ) - (func $~lib/map/Map#delete (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#delete (; 25 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.const 16 i32.shl i32.const 16 i32.shr_s - call $~lib/internal/hash/hash16 - set_local $0 - get_local $2 + tee_local $1 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $1 - get_local $0 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=8 i32.const 1 i32.or i32.store offset=8 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/map/Map#rehash end i32.const 1 ) - (func $std/map/test (; 31 ;) (type $v) + (func $std/map/test (; 26 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/map/Map#constructor @@ -2261,7 +2279,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -2364,7 +2382,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -2441,7 +2459,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -2520,7 +2538,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -2534,7 +2552,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -2544,21 +2562,31 @@ unreachable end ) - (func $~lib/map/Map#has (; 32 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#has (; 27 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) + get_local $0 + get_local $1 get_local $1 i32.const 65535 i32.and - call $~lib/internal/hash/hash16 - set_local $2 - get_local $0 - get_local $1 + tee_local $2 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $2 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find i32.const 0 i32.ne ) - (func $~lib/map/Map#rehash (; 33 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 28 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2590,7 +2618,7 @@ i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 12 @@ -2600,33 +2628,43 @@ get_local $6 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 + get_local $2 get_local $8 i32.ne if - get_local $3 + get_local $2 i32.load offset=8 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 i32.load16_u i32.store16 - get_local $2 get_local $3 + get_local $2 i32.load offset=4 i32.store offset=4 get_local $3 - i32.load16_u - call $~lib/internal/hash/hash16 - set_local $4 - get_local $2 get_local $5 + get_local $2 + i32.load16_u + tee_local $4 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $4 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul get_local $1 i32.and i32.const 2 @@ -2636,17 +2674,17 @@ i32.load offset=8 i32.store offset=8 get_local $4 - get_local $2 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 12 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 12 i32.add - set_local $3 + set_local $2 br $continue|0 end end @@ -2667,18 +2705,31 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 34 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map#set (; 29 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) get_local $1 i32.const 65535 i32.and - call $~lib/internal/hash/hash16 + tee_local $3 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul + get_local $3 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul + tee_local $3 set_local $5 get_local $0 get_local $1 - get_local $5 + get_local $3 call $~lib/map/Map#find tee_local $3 if @@ -2763,16 +2814,25 @@ i32.store offset=8 end ) - (func $~lib/map/Map#get (; 35 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) + (func $~lib/map/Map#get (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + get_local $0 + get_local $1 get_local $1 i32.const 65535 i32.and - call $~lib/internal/hash/hash16 - set_local $2 + tee_local $0 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $0 - get_local $1 - get_local $2 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find tee_local $0 if (result i32) @@ -2783,75 +2843,83 @@ end tee_local $0 ) - (func $~lib/map/Map#delete (; 36 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#delete (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.const 65535 i32.and - call $~lib/internal/hash/hash16 - set_local $0 - get_local $2 + tee_local $1 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $1 - get_local $0 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/map/Map#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=8 i32.const 1 i32.or i32.store offset=8 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/map/Map#rehash end i32.const 1 ) - (func $std/map/test (; 37 ;) (type $v) + (func $std/map/test (; 32 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/map/Map#constructor @@ -2922,7 +2990,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -3019,7 +3087,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -3094,7 +3162,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -3171,7 +3239,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -3185,7 +3253,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -3195,7 +3263,7 @@ unreachable end ) - (func $~lib/internal/hash/hash32 (; 38 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/hash/hash32 (; 33 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 255 i32.and @@ -3226,7 +3294,7 @@ i32.const 16777619 i32.mul ) - (func $~lib/map/Map#find (; 39 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 34 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -3269,19 +3337,16 @@ end i32.const 0 ) - (func $~lib/map/Map#has (; 40 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash32 - set_local $2 + (func $~lib/map/Map#has (; 35 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + call $~lib/internal/hash/hash32 call $~lib/map/Map#find i32.const 0 i32.ne ) - (func $~lib/map/Map#rehash (; 41 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 36 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3297,109 +3362,106 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 12 i32.mul i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 12 i32.mul i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 - get_local $8 + get_local $2 + get_local $7 i32.ne if - get_local $3 + get_local $2 i32.load offset=8 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 i32.load i32.store - get_local $2 get_local $3 + get_local $2 i32.load offset=4 i32.store offset=4 get_local $3 + get_local $4 + get_local $2 i32.load call $~lib/internal/hash/hash32 - set_local $4 - get_local $2 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=8 - get_local $4 - get_local $2 + get_local $8 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 12 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 12 i32.add - set_local $3 + set_local $2 br $continue|0 end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 42 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map#set (; 37 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - get_local $1 - call $~lib/internal/hash/hash32 - set_local $5 get_local $0 get_local $1 - get_local $5 + get_local $1 + call $~lib/internal/hash/hash32 + tee_local $5 call $~lib/map/Map#find tee_local $3 if @@ -3484,14 +3546,11 @@ i32.store offset=8 end ) - (func $~lib/map/Map#get (; 43 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash32 - set_local $2 + (func $~lib/map/Map#get (; 38 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + call $~lib/internal/hash/hash32 call $~lib/map/Map#find tee_local $0 if (result i32) @@ -3502,73 +3561,69 @@ end tee_local $0 ) - (func $~lib/map/Map#delete (; 44 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/map/Map#delete (; 39 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 call $~lib/internal/hash/hash32 - set_local $0 - get_local $2 - get_local $1 - get_local $0 call $~lib/map/Map#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=8 i32.const 1 i32.or i32.store offset=8 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/map/Map#rehash end i32.const 1 ) - (func $std/map/test (; 45 ;) (type $v) + (func $std/map/test (; 40 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/map/Map#constructor @@ -3635,7 +3690,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -3726,7 +3781,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -3799,7 +3854,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -3874,7 +3929,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -3888,7 +3943,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -3898,7 +3953,7 @@ unreachable end ) - (func $std/map/test (; 46 ;) (type $v) + (func $std/map/test (; 41 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/map/Map#constructor @@ -3965,7 +4020,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4056,7 +4111,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4129,7 +4184,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -4204,7 +4259,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -4218,7 +4273,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -4228,24 +4283,19 @@ unreachable end ) - (func $~lib/map/Map#clear (; 47 ;) (type $iv) (param $0 i32) - (local $1 i32) + (func $~lib/map/Map#clear (; 42 ;) (type $iv) (param $0 i32) + get_local $0 i32.const 16 i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store get_local $0 i32.const 3 i32.store offset=4 + get_local $0 i32.const 64 i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store offset=8 get_local $0 i32.const 4 @@ -4257,9 +4307,10 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map#constructor (; 48 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 43 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) - call $~lib/memory/memory.allocate + i32.const 24 + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 0 i32.store @@ -4282,7 +4333,7 @@ call $~lib/map/Map#clear get_local $0 ) - (func $~lib/internal/hash/hash64 (; 49 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/hash/hash64 (; 44 ;) (type $Ii) (param $0 i64) (result i32) (local $1 i32) get_local $0 i32.wrap/i64 @@ -4348,7 +4399,7 @@ i32.const 16777619 i32.mul ) - (func $~lib/map/Map#find (; 50 ;) (type $iIii) (param $0 i32) (param $1 i64) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 45 ;) (type $iIii) (param $0 i32) (param $1 i64) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -4391,19 +4442,16 @@ end i32.const 0 ) - (func $~lib/map/Map#has (; 51 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash64 - set_local $2 + (func $~lib/map/Map#has (; 46 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + call $~lib/internal/hash/hash64 call $~lib/map/Map#find i32.const 0 i32.ne ) - (func $~lib/map/Map#rehash (; 52 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 47 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -4419,109 +4467,106 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 4 i32.shl i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 4 i32.shl i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 - get_local $8 + get_local $2 + get_local $7 i32.ne if - get_local $3 + get_local $2 i32.load offset=12 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 i64.load i64.store - get_local $2 get_local $3 + get_local $2 i32.load offset=8 i32.store offset=8 get_local $3 + get_local $4 + get_local $2 i64.load call $~lib/internal/hash/hash64 - set_local $4 - get_local $2 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=12 - get_local $4 - get_local $2 + get_local $8 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 16 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 16 i32.add - set_local $3 + set_local $2 br $continue|0 end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 53 ;) (type $iIiv) (param $0 i32) (param $1 i64) (param $2 i32) + (func $~lib/map/Map#set (; 48 ;) (type $iIiv) (param $0 i32) (param $1 i64) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - get_local $1 - call $~lib/internal/hash/hash64 - set_local $5 get_local $0 get_local $1 - get_local $5 + get_local $1 + call $~lib/internal/hash/hash64 + tee_local $5 call $~lib/map/Map#find tee_local $3 if @@ -4606,14 +4651,11 @@ i32.store offset=8 end ) - (func $~lib/map/Map#get (; 54 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash64 - set_local $2 + (func $~lib/map/Map#get (; 49 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + call $~lib/internal/hash/hash64 call $~lib/map/Map#find tee_local $0 if (result i32) @@ -4624,37 +4666,33 @@ end tee_local $0 ) - (func $~lib/map/Map#delete (; 55 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) + (func $~lib/map/Map#delete (; 50 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) (local $2 i32) (local $3 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 call $~lib/internal/hash/hash64 - set_local $0 - get_local $2 - get_local $1 - get_local $0 call $~lib/map/Map#find - tee_local $0 + tee_local $2 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $2 + get_local $2 i32.load offset=12 i32.const 1 i32.or i32.store offset=12 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u @@ -4662,36 +4700,36 @@ i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $2 + i32.const 4 + get_local $2 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $2 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $2 end - get_local $0 + get_local $2 if - get_local $2 + get_local $0 get_local $3 call $~lib/map/Map#rehash end i32.const 1 ) - (func $std/map/test (; 56 ;) (type $v) + (func $std/map/test (; 51 ;) (type $v) (local $0 i64) (local $1 i32) call $~lib/map/Map#constructor @@ -4760,7 +4798,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4854,7 +4892,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4928,7 +4966,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -5004,7 +5042,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -5018,7 +5056,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -5028,7 +5066,7 @@ unreachable end ) - (func $std/map/test (; 57 ;) (type $v) + (func $std/map/test (; 52 ;) (type $v) (local $0 i64) (local $1 i32) call $~lib/map/Map#constructor @@ -5097,7 +5135,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -5191,7 +5229,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -5265,7 +5303,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -5341,7 +5379,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -5355,7 +5393,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -5365,7 +5403,7 @@ unreachable end ) - (func $~lib/map/Map#find (; 58 ;) (type $ifii) (param $0 i32) (param $1 f32) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 53 ;) (type $ifii) (param $0 i32) (param $1 f32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -5408,20 +5446,17 @@ end i32.const 0 ) - (func $~lib/map/Map#has (; 59 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) - (local $2 i32) + (func $~lib/map/Map#has (; 54 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) + get_local $0 + get_local $1 get_local $1 i32.reinterpret/f32 call $~lib/internal/hash/hash32 - set_local $2 - get_local $0 - get_local $1 - get_local $2 call $~lib/map/Map#find i32.const 0 i32.ne ) - (func $~lib/map/Map#rehash (; 60 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 55 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5437,111 +5472,108 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 12 i32.mul i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 12 i32.mul i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 - get_local $8 + get_local $2 + get_local $7 i32.ne if - get_local $3 + get_local $2 i32.load offset=8 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 f32.load f32.store - get_local $2 get_local $3 + get_local $2 i32.load offset=4 i32.store offset=4 get_local $3 + get_local $4 + get_local $2 f32.load i32.reinterpret/f32 call $~lib/internal/hash/hash32 - set_local $4 - get_local $2 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=8 - get_local $4 - get_local $2 + get_local $8 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 12 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 12 i32.add - set_local $3 + set_local $2 br $continue|0 end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 61 ;) (type $ifiv) (param $0 i32) (param $1 f32) (param $2 i32) + (func $~lib/map/Map#set (; 56 ;) (type $ifiv) (param $0 i32) (param $1 f32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) + get_local $0 + get_local $1 get_local $1 i32.reinterpret/f32 call $~lib/internal/hash/hash32 - set_local $5 - get_local $0 - get_local $1 - get_local $5 + tee_local $5 call $~lib/map/Map#find tee_local $3 if @@ -5626,15 +5658,12 @@ i32.store offset=8 end ) - (func $~lib/map/Map#get (; 62 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) - (local $2 i32) + (func $~lib/map/Map#get (; 57 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) + get_local $0 + get_local $1 get_local $1 i32.reinterpret/f32 call $~lib/internal/hash/hash32 - set_local $2 - get_local $0 - get_local $1 - get_local $2 call $~lib/map/Map#find tee_local $0 if (result i32) @@ -5645,38 +5674,34 @@ end tee_local $0 ) - (func $~lib/map/Map#delete (; 63 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) + (func $~lib/map/Map#delete (; 58 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) (local $2 i32) (local $3 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.reinterpret/f32 call $~lib/internal/hash/hash32 - set_local $0 - get_local $2 - get_local $1 - get_local $0 call $~lib/map/Map#find - tee_local $0 + tee_local $2 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $2 + get_local $2 i32.load offset=8 i32.const 1 i32.or i32.store offset=8 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u @@ -5684,36 +5709,36 @@ i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $2 + i32.const 4 + get_local $2 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $2 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $2 end - get_local $0 + get_local $2 if - get_local $2 + get_local $0 get_local $3 call $~lib/map/Map#rehash end i32.const 1 ) - (func $std/map/test (; 64 ;) (type $v) + (func $std/map/test (; 59 ;) (type $v) (local $0 f32) (local $1 i32) call $~lib/map/Map#constructor @@ -5783,7 +5808,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -5878,7 +5903,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -5953,7 +5978,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -6030,7 +6055,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -6044,7 +6069,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -6054,7 +6079,7 @@ unreachable end ) - (func $~lib/map/Map#find (; 65 ;) (type $iFii) (param $0 i32) (param $1 f64) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 60 ;) (type $iFii) (param $0 i32) (param $1 f64) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -6097,20 +6122,17 @@ end i32.const 0 ) - (func $~lib/map/Map#has (; 66 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) - (local $2 i32) + (func $~lib/map/Map#has (; 61 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) + get_local $0 + get_local $1 get_local $1 i64.reinterpret/f64 call $~lib/internal/hash/hash64 - set_local $2 - get_local $0 - get_local $1 - get_local $2 call $~lib/map/Map#find i32.const 0 i32.ne ) - (func $~lib/map/Map#rehash (; 67 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 62 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -6126,111 +6148,108 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 4 i32.shl i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 4 i32.shl i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 - get_local $8 + get_local $2 + get_local $7 i32.ne if - get_local $3 + get_local $2 i32.load offset=12 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 f64.load f64.store - get_local $2 get_local $3 + get_local $2 i32.load offset=8 i32.store offset=8 get_local $3 + get_local $4 + get_local $2 f64.load i64.reinterpret/f64 call $~lib/internal/hash/hash64 - set_local $4 - get_local $2 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=12 - get_local $4 - get_local $2 + get_local $8 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 16 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 16 i32.add - set_local $3 + set_local $2 br $continue|0 end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 68 ;) (type $iFiv) (param $0 i32) (param $1 f64) (param $2 i32) + (func $~lib/map/Map#set (; 63 ;) (type $iFiv) (param $0 i32) (param $1 f64) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) + get_local $0 + get_local $1 get_local $1 i64.reinterpret/f64 call $~lib/internal/hash/hash64 - set_local $5 - get_local $0 - get_local $1 - get_local $5 + tee_local $5 call $~lib/map/Map#find tee_local $3 if @@ -6315,15 +6334,12 @@ i32.store offset=8 end ) - (func $~lib/map/Map#get (; 69 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) - (local $2 i32) + (func $~lib/map/Map#get (; 64 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) + get_local $0 + get_local $1 get_local $1 i64.reinterpret/f64 call $~lib/internal/hash/hash64 - set_local $2 - get_local $0 - get_local $1 - get_local $2 call $~lib/map/Map#find tee_local $0 if (result i32) @@ -6334,38 +6350,34 @@ end tee_local $0 ) - (func $~lib/map/Map#delete (; 70 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) + (func $~lib/map/Map#delete (; 65 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) (local $2 i32) (local $3 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i64.reinterpret/f64 call $~lib/internal/hash/hash64 - set_local $0 - get_local $2 - get_local $1 - get_local $0 call $~lib/map/Map#find - tee_local $0 + tee_local $2 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $2 + get_local $2 i32.load offset=12 i32.const 1 i32.or i32.store offset=12 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u @@ -6373,36 +6385,36 @@ i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $2 + i32.const 4 + get_local $2 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $2 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $2 end - get_local $0 + get_local $2 if - get_local $2 + get_local $0 get_local $3 call $~lib/map/Map#rehash end i32.const 1 ) - (func $std/map/test (; 71 ;) (type $v) + (func $std/map/test (; 66 ;) (type $v) (local $0 f64) (local $1 i32) call $~lib/map/Map#constructor @@ -6472,7 +6484,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -6567,7 +6579,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -6642,7 +6654,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -6719,7 +6731,7 @@ unreachable end get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -6733,7 +6745,7 @@ get_local $1 call $~lib/map/Map#clear get_local $1 - call $~lib/map/Map#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -6743,7 +6755,7 @@ unreachable end ) - (func $start (; 72 ;) (type $v) + (func $start (; 67 ;) (type $v) i32.const 144 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -6759,7 +6771,7 @@ call $std/map/test call $std/map/test ) - (func $null (; 73 ;) (type $v) + (func $null (; 68 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/math.optimized.wat b/tests/compiler/std/math.optimized.wat index 7d7fca23..69563b25 100644 --- a/tests/compiler/std/math.optimized.wat +++ b/tests/compiler/std/math.optimized.wat @@ -1,11 +1,9 @@ (module (type $iiiiv (func (param i32 i32 i32 i32))) (type $FFFii (func (param f64 f64 f64 i32) (result i32))) - (type $Fi (func (param f64) (result i32))) (type $FFFF (func (param f64 f64 f64) (result f64))) (type $FiF (func (param f64 i32) (result f64))) (type $fffii (func (param f32 f32 f32 i32) (result i32))) - (type $fi (func (param f32) (result i32))) (type $ffff (func (param f32 f32 f32) (result f32))) (type $fif (func (param f32 i32) (result f32))) (type $FF (func (param f64) (result f64))) @@ -16,7 +14,6 @@ (type $fff (func (param f32 f32) (result f32))) (type $F (func (result f64))) (type $Iv (func (param i64))) - (type $II (func (param i64) (result i64))) (type $ii (func (param i32) (result i32))) (type $f (func (result f32))) (type $IiI (func (param i64 i32) (result i64))) @@ -81,47 +78,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/builtins/isNaN (; 30 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.ne - ) - (func $std/math/signbit (; 31 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - i64.reinterpret/f64 - i64.const 63 - i64.shr_u - i32.wrap/i64 - ) - (func $~lib/builtins/isFinite (; 32 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.sub - f64.const 0 - f64.eq - ) - (func $std/math/eulp (; 33 ;) (type $Fi) (param $0 f64) (result i32) - (local $1 i32) - get_local $0 - i64.reinterpret/f64 - i64.const 52 - i64.shr_u - i64.const 2047 - i64.and - i32.wrap/i64 - tee_local $1 - i32.eqz - if - get_local $1 - i32.const 1 - i32.add - set_local $1 - end - get_local $1 - i32.const -1075 - i32.add - ) - (func $~lib/math/NativeMath.scalbn (; 34 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/NativeMath.scalbn (; 30 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) get_local $1 i32.const 1023 i32.gt_s @@ -195,15 +152,19 @@ f64.reinterpret/i64 f64.mul ) - (func $std/math/ulperr (; 35 ;) (type $FFFF) (param $0 f64) (param $1 f64) (param $2 f64) (result f64) + (func $std/math/ulperr (; 31 ;) (type $FFFF) (param $0 f64) (param $1 f64) (param $2 f64) (result f64) (local $3 i32) (local $4 i32) get_local $0 - call $~lib/builtins/isNaN - tee_local $3 + get_local $0 + f64.ne + tee_local $4 + set_local $3 + get_local $4 if get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f64.ne set_local $3 end get_local $3 @@ -216,13 +177,15 @@ f64.eq if get_local $0 - call $std/math/signbit - set_local $4 + i64.reinterpret/f64 + i64.const 63 + i64.shr_u + i32.wrap/i64 get_local $1 - call $std/math/signbit - set_local $3 - get_local $4 - get_local $3 + i64.reinterpret/f64 + i64.const 63 + i64.shr_u + i32.wrap/i64 i32.eq if get_local $2 @@ -232,8 +195,10 @@ return end get_local $0 - call $~lib/builtins/isFinite - i32.eqz + get_local $0 + f64.sub + f64.const 0 + f64.ne if f64.const 8988465674311579538646525e283 get_local $0 @@ -248,19 +213,32 @@ get_local $1 f64.sub set_local $0 - i32.const 0 get_local $1 - call $std/math/eulp - i32.sub - set_local $3 + i64.reinterpret/f64 + i64.const 52 + i64.shr_u + i64.const 2047 + i64.and + i32.wrap/i64 + tee_local $3 + i32.eqz + if + get_local $3 + i32.const 1 + i32.add + set_local $3 + end get_local $0 + i32.const 0 get_local $3 + i32.const -1075 + i32.add + i32.sub call $~lib/math/NativeMath.scalbn - tee_local $0 get_local $2 f64.add ) - (func $std/math/check (; 36 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/check (; 32 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) get_local $0 get_local $1 f64.eq @@ -269,10 +247,12 @@ return end get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f64.ne if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne return end get_local $0 @@ -288,45 +268,7 @@ end i32.const 1 ) - (func $~lib/builtins/isNaN (; 37 ;) (type $fi) (param $0 f32) (result i32) - get_local $0 - get_local $0 - f32.ne - ) - (func $std/math/signbitf (; 38 ;) (type $fi) (param $0 f32) (result i32) - get_local $0 - i32.reinterpret/f32 - i32.const 31 - i32.shr_u - ) - (func $~lib/builtins/isFinite (; 39 ;) (type $fi) (param $0 f32) (result i32) - get_local $0 - get_local $0 - f32.sub - f32.const 0 - f32.eq - ) - (func $std/math/eulpf (; 40 ;) (type $fi) (param $0 f32) (result i32) - (local $1 i32) - get_local $0 - i32.reinterpret/f32 - i32.const 23 - i32.shr_u - i32.const 255 - i32.and - tee_local $1 - i32.eqz - if - get_local $1 - i32.const 1 - i32.add - set_local $1 - end - get_local $1 - i32.const -150 - i32.add - ) - (func $~lib/math/NativeMathf.scalbn (; 41 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) + (func $~lib/math/NativeMathf.scalbn (; 33 ;) (type $fif) (param $0 f32) (param $1 i32) (result f32) get_local $1 i32.const 127 i32.gt_s @@ -399,15 +341,19 @@ f32.reinterpret/i32 f32.mul ) - (func $std/math/ulperrf (; 42 ;) (type $ffff) (param $0 f32) (param $1 f32) (param $2 f32) (result f32) + (func $std/math/ulperrf (; 34 ;) (type $ffff) (param $0 f32) (param $1 f32) (param $2 f32) (result f32) (local $3 i32) (local $4 i32) get_local $0 - call $~lib/builtins/isNaN - tee_local $3 + get_local $0 + f32.ne + tee_local $4 + set_local $3 + get_local $4 if get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f32.ne set_local $3 end get_local $3 @@ -420,13 +366,13 @@ f32.eq if get_local $0 - call $std/math/signbitf - set_local $4 + i32.reinterpret/f32 + i32.const 31 + i32.shr_u get_local $1 - call $std/math/signbitf - set_local $3 - get_local $4 - get_local $3 + i32.reinterpret/f32 + i32.const 31 + i32.shr_u i32.eq if get_local $2 @@ -436,8 +382,10 @@ return end get_local $0 - call $~lib/builtins/isFinite - i32.eqz + get_local $0 + f32.sub + f32.const 0 + f32.ne if f32.const 1701411834604692317316873e14 get_local $0 @@ -452,19 +400,31 @@ get_local $1 f32.sub set_local $0 - i32.const 0 get_local $1 - call $std/math/eulpf - i32.sub - set_local $3 + i32.reinterpret/f32 + i32.const 23 + i32.shr_u + i32.const 255 + i32.and + tee_local $3 + i32.eqz + if + get_local $3 + i32.const 1 + i32.add + set_local $3 + end get_local $0 + i32.const 0 get_local $3 + i32.const -150 + i32.add + i32.sub call $~lib/math/NativeMathf.scalbn - tee_local $0 get_local $2 f32.add ) - (func $std/math/check (; 43 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/check (; 35 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) get_local $0 get_local $1 f32.eq @@ -473,10 +433,12 @@ return end get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f32.ne if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f32.ne return end get_local $0 @@ -492,7 +454,7 @@ end i32.const 1 ) - (func $std/math/test_scalbn (; 44 ;) (type $FUNCSIG$ididi) (param $0 f64) (param $1 i32) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_scalbn (; 36 ;) (type $FUNCSIG$ididi) (param $0 f64) (param $1 i32) (param $2 f64) (param $3 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMath.scalbn @@ -500,7 +462,7 @@ f64.const 0 call $std/math/check ) - (func $std/math/test_scalbnf (; 45 ;) (type $FUNCSIG$ififi) (param $0 f32) (param $1 i32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_scalbnf (; 37 ;) (type $FUNCSIG$ififi) (param $0 f32) (param $1 i32) (param $2 f32) (param $3 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMathf.scalbn @@ -508,7 +470,7 @@ f32.const 0 call $std/math/check ) - (func $std/math/test_abs (; 46 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) + (func $std/math/test_abs (; 38 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) (local $2 i32) get_local $0 f64.abs @@ -519,7 +481,6 @@ if get_local $0 call $~lib/bindings/Math/abs - tee_local $0 get_local $1 f64.const 0 call $std/math/check @@ -527,14 +488,14 @@ end get_local $2 ) - (func $std/math/test_absf (; 47 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_absf (; 39 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) get_local $0 f32.abs get_local $1 f32.const 0 call $std/math/check ) - (func $~lib/math/R (; 48 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/R (; 40 ;) (type $FF) (param $0 f64) (result f64) get_local $0 f64.const 0.16666666666666666 get_local $0 @@ -577,7 +538,7 @@ f64.add f64.div ) - (func $~lib/math/NativeMath.acos (; 49 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.acos (; 41 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 f64) @@ -632,16 +593,14 @@ f64.const 1.5707963267948966 return end - get_local $0 - get_local $0 - f64.mul - call $~lib/math/R - set_local $1 f64.const 1.5707963267948966 get_local $0 f64.const 6.123233995736766e-17 get_local $0 - get_local $1 + get_local $0 + get_local $0 + f64.mul + call $~lib/math/R f64.mul f64.sub f64.sub @@ -652,6 +611,8 @@ i32.const 31 i32.shr_u if + f64.const 2 + f64.const 1.5707963267948966 f64.const 0.5 get_local $0 f64.const 0.5 @@ -659,14 +620,9 @@ f64.add tee_local $1 f64.sqrt - set_local $0 + tee_local $0 get_local $1 call $~lib/math/R - set_local $1 - f64.const 2 - f64.const 1.5707963267948966 - get_local $0 - get_local $1 get_local $0 f64.mul f64.const 6.123233995736766e-17 @@ -699,12 +655,10 @@ f64.add f64.div set_local $5 - get_local $1 - call $~lib/math/R - set_local $1 f64.const 2 get_local $3 get_local $1 + call $~lib/math/R get_local $0 f64.mul get_local $5 @@ -712,7 +666,7 @@ f64.add f64.mul ) - (func $std/math/test_acos (; 50 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_acos (; 42 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.acos @@ -723,7 +677,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/acos - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -732,34 +685,15 @@ end tee_local $3 ) - (func $~lib/math/Rf (; 51 ;) (type $ff) (param $0 f32) (result f32) - get_local $0 - f32.const 0.16666586697101593 - get_local $0 - f32.const -0.04274342209100723 - get_local $0 - f32.const -0.008656363002955914 - f32.mul - f32.add - f32.mul - f32.add - f32.mul - f32.const 1 - get_local $0 - f32.const -0.7066296339035034 - f32.mul - f32.add - f32.div - ) - (func $~lib/math/NativeMathf.acos (; 52 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.acos (; 43 ;) (type $ff) (param $0 f32) (result f32) (local $1 f32) - (local $2 i32) + (local $2 f32) (local $3 i32) - (local $4 f32) + (local $4 i32) (local $5 f32) get_local $0 i32.reinterpret/f32 - tee_local $2 + tee_local $4 i32.const 2147483647 i32.and tee_local $3 @@ -770,7 +704,7 @@ i32.const 1065353216 i32.eq if - get_local $2 + get_local $4 i32.const 31 i32.shr_u if @@ -798,23 +732,37 @@ f32.const 1.570796251296997 return end - get_local $0 - get_local $0 - f32.mul - call $~lib/math/Rf - set_local $1 f32.const 1.570796251296997 get_local $0 f32.const 7.549789415861596e-08 get_local $0 - get_local $1 + get_local $0 + get_local $0 + f32.mul + tee_local $0 + f32.const 0.16666586697101593 + get_local $0 + f32.const -0.04274342209100723 + get_local $0 + f32.const -0.008656363002955914 + f32.mul + f32.add + f32.mul + f32.add + f32.mul + f32.const 1 + get_local $0 + f32.const -0.7066296339035034 + f32.mul + f32.add + f32.div f32.mul f32.sub f32.sub f32.sub return end - get_local $2 + get_local $4 i32.const 31 i32.shr_u if @@ -823,17 +771,31 @@ f32.const 0.5 f32.mul f32.add - tee_local $1 - f32.sqrt - set_local $0 - get_local $1 - call $~lib/math/Rf + tee_local $0 + f32.const 0.16666586697101593 + get_local $0 + f32.const -0.04274342209100723 + get_local $0 + f32.const -0.008656363002955914 + f32.mul + f32.add + f32.mul + f32.add + f32.mul + f32.const 1 + get_local $0 + f32.const -0.7066296339035034 + f32.mul + f32.add + f32.div set_local $1 f32.const 2 f32.const 1.570796251296997 get_local $0 + f32.sqrt + tee_local $2 get_local $1 - get_local $0 + get_local $2 f32.mul f32.const 7.549789415861596e-08 f32.sub @@ -847,46 +809,58 @@ f32.const 0.5 f32.mul f32.sub - tee_local $1 - f32.sqrt tee_local $0 - i32.reinterpret/f32 + f32.sqrt set_local $2 - get_local $1 + get_local $0 get_local $2 + i32.reinterpret/f32 i32.const -4096 i32.and f32.reinterpret/i32 - tee_local $4 - get_local $4 + tee_local $1 + get_local $1 f32.mul f32.sub - get_local $0 - get_local $4 + get_local $2 + get_local $1 f32.add f32.div set_local $5 - get_local $1 - call $~lib/math/Rf - set_local $1 f32.const 2 - get_local $4 get_local $1 get_local $0 + f32.const 0.16666586697101593 + get_local $0 + f32.const -0.04274342209100723 + get_local $0 + f32.const -0.008656363002955914 + f32.mul + f32.add + f32.mul + f32.add + f32.mul + f32.const 1 + get_local $0 + f32.const -0.7066296339035034 + f32.mul + f32.add + f32.div + get_local $2 f32.mul get_local $5 f32.add f32.add f32.mul ) - (func $std/math/test_acosf (; 53 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_acosf (; 44 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.acos get_local $1 get_local $2 call $std/math/check ) - (func $~lib/math/NativeMath.log1p (; 54 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log1p (; 45 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i32) @@ -1091,7 +1065,7 @@ f64.mul f64.add ) - (func $~lib/math/NativeMath.log (; 55 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log (; 46 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 i32) (local $3 i32) @@ -1269,7 +1243,7 @@ f64.mul f64.add ) - (func $~lib/math/NativeMath.acosh (; 56 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.acosh (; 47 ;) (type $FF) (param $0 f64) (result f64) (local $1 i64) get_local $0 i64.reinterpret/f64 @@ -1323,7 +1297,7 @@ f64.const 0.6931471805599453 f64.add ) - (func $std/math/test_acosh (; 57 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_acosh (; 48 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.acosh @@ -1334,7 +1308,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/acosh - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -1343,7 +1316,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.log1p (; 58 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log1p (; 49 ;) (type $ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) (local $3 i32) @@ -1519,7 +1492,7 @@ f32.mul f32.add ) - (func $~lib/math/NativeMathf.log (; 59 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log (; 50 ;) (type $ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 i32) @@ -1658,7 +1631,7 @@ f32.mul f32.add ) - (func $~lib/math/NativeMathf.acosh (; 60 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.acosh (; 51 ;) (type $ff) (param $0 f32) (result f32) (local $1 i32) get_local $0 i32.reinterpret/f32 @@ -1708,14 +1681,14 @@ f32.const 0.6931471824645996 f32.add ) - (func $std/math/test_acoshf (; 61 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_acoshf (; 52 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.acosh get_local $1 get_local $2 call $std/math/check ) - (func $~lib/math/NativeMath.asin (; 62 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.asin (; 53 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i32) @@ -1776,12 +1749,10 @@ end get_local $0 get_local $0 + get_local $0 + get_local $0 f64.mul call $~lib/math/R - set_local $1 - get_local $0 - get_local $0 - get_local $1 f64.mul f64.add return @@ -1858,7 +1829,7 @@ end get_local $0 ) - (func $std/math/test_asin (; 63 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_asin (; 54 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.asin @@ -1869,7 +1840,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/asin - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -1878,11 +1848,11 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.asin (; 64 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.asin (; 55 ;) (type $ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 i32) - (local $4 f64) + (local $4 f32) (local $5 f64) get_local $0 i32.reinterpret/f32 @@ -1931,12 +1901,26 @@ end get_local $0 get_local $0 + get_local $0 + get_local $0 f32.mul - call $~lib/math/Rf - set_local $2 + tee_local $0 + f32.const 0.16666586697101593 get_local $0 + f32.const -0.04274342209100723 get_local $0 - get_local $2 + f32.const -0.008656363002955914 + f32.mul + f32.add + f32.mul + f32.add + f32.mul + f32.const 1 + get_local $0 + f32.const -0.7066296339035034 + f32.mul + f32.add + f32.div f32.mul f32.add return @@ -1948,18 +1932,32 @@ f32.mul f32.sub tee_local $2 - f64.promote/f32 - f64.sqrt - set_local $4 + f32.const 0.16666586697101593 get_local $2 - call $~lib/math/Rf - f64.promote/f32 - set_local $5 + f32.const -0.04274342209100723 + get_local $2 + f32.const -0.008656363002955914 + f32.mul + f32.add + f32.mul + f32.add + f32.mul + f32.const 1 + get_local $2 + f32.const -0.7066296339035034 + f32.mul + f32.add + f32.div + set_local $4 f64.const 1.5707963705062866 f64.const 2 - get_local $4 - get_local $4 + get_local $2 + f64.promote/f32 + f64.sqrt + tee_local $5 get_local $5 + get_local $4 + f64.promote/f32 f64.mul f64.add f64.mul @@ -1968,14 +1966,14 @@ get_local $0 f32.copysign ) - (func $std/math/test_asinf (; 65 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_asinf (; 56 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.asin get_local $1 get_local $2 call $std/math/check ) - (func $~lib/math/NativeMath.asinh (; 66 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.asinh (; 57 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i64) get_local $0 @@ -2047,7 +2045,7 @@ get_local $0 f64.copysign ) - (func $std/math/test_asinh (; 67 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_asinh (; 58 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.asinh @@ -2058,7 +2056,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/asinh - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -2067,7 +2064,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.asinh (; 68 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.asinh (; 59 ;) (type $ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) get_local $0 @@ -2134,14 +2131,14 @@ get_local $0 f32.copysign ) - (func $std/math/test_asinhf (; 69 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_asinhf (; 60 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.asinh get_local $1 get_local $2 call $std/math/check ) - (func $~lib/math/NativeMath.atan (; 70 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.atan (; 61 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 f64) @@ -2160,7 +2157,8 @@ i32.ge_u if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne if get_local $0 return @@ -2366,7 +2364,7 @@ get_local $4 f64.copysign ) - (func $std/math/test_atan (; 71 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_atan (; 62 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.atan @@ -2377,7 +2375,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/atan - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -2386,7 +2383,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.atan (; 72 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.atan (; 63 ;) (type $ff) (param $0 f32) (result f32) (local $1 i32) (local $2 f32) (local $3 f32) @@ -2402,7 +2399,8 @@ i32.ge_u if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f32.ne if get_local $0 return @@ -2584,14 +2582,14 @@ get_local $4 f32.copysign ) - (func $std/math/test_atanf (; 73 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_atanf (; 64 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.atan get_local $1 get_local $2 call $std/math/check ) - (func $~lib/math/NativeMath.atanh (; 74 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.atanh (; 65 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i64) (local $3 i64) @@ -2651,7 +2649,7 @@ get_local $0 f64.copysign ) - (func $std/math/test_atanh (; 75 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_atanh (; 66 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.atanh @@ -2662,7 +2660,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/atanh - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -2671,7 +2668,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.atanh (; 76 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.atanh (; 67 ;) (type $ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) get_local $0 @@ -2722,14 +2719,14 @@ get_local $0 f32.copysign ) - (func $std/math/test_atanhf (; 77 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_atanhf (; 68 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.atanh get_local $1 get_local $2 call $std/math/check ) - (func $~lib/math/NativeMath.atan2 (; 78 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.atan2 (; 69 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2738,12 +2735,14 @@ (local $7 i32) block $folding-inner0 get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f64.ne tee_local $2 i32.eqz if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne set_local $2 end get_local $2 @@ -2985,7 +2984,7 @@ end tee_local $0 ) - (func $std/math/test_atan2 (; 79 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) + (func $std/math/test_atan2 (; 70 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) get_local $0 get_local $1 @@ -2998,7 +2997,6 @@ get_local $0 get_local $1 call $~lib/bindings/Math/atan2 - tee_local $0 get_local $2 get_local $3 call $std/math/check @@ -3007,19 +3005,21 @@ end tee_local $4 ) - (func $~lib/math/NativeMathf.atan2 (; 80 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.atan2 (; 71 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) block $folding-inner0 get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f32.ne tee_local $2 i32.eqz if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f32.ne set_local $2 end get_local $2 @@ -3239,7 +3239,7 @@ end tee_local $0 ) - (func $std/math/test_atan2f (; 81 ;) (type $ffffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) + (func $std/math/test_atan2f (; 72 ;) (type $ffffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMathf.atan2 @@ -3247,7 +3247,7 @@ get_local $3 call $std/math/check ) - (func $~lib/math/NativeMath.cbrt (; 82 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.cbrt (; 73 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -3369,7 +3369,7 @@ f64.mul f64.add ) - (func $std/math/test_cbrt (; 83 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_cbrt (; 74 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.cbrt @@ -3380,7 +3380,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/cbrt - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -3389,7 +3388,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.cbrt (; 84 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.cbrt (; 75 ;) (type $ff) (param $0 f32) (result f32) (local $1 f64) (local $2 f64) (local $3 i32) @@ -3486,14 +3485,14 @@ f64.div f32.demote/f64 ) - (func $std/math/test_cbrtf (; 85 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_cbrtf (; 76 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.cbrt get_local $1 get_local $2 call $std/math/check ) - (func $std/math/test_ceil (; 86 ;) (type $FUNCSIG$iddi) (param $0 f64) (param $1 f64) (param $2 i32) (result i32) + (func $std/math/test_ceil (; 77 ;) (type $FUNCSIG$iddi) (param $0 f64) (param $1 f64) (param $2 i32) (result i32) get_local $0 f64.ceil get_local $1 @@ -3503,7 +3502,6 @@ if get_local $0 call $~lib/bindings/Math/ceil - tee_local $0 get_local $1 f64.const 0 call $std/math/check @@ -3511,14 +3509,14 @@ end get_local $2 ) - (func $std/math/test_ceilf (; 87 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) + (func $std/math/test_ceilf (; 78 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) get_local $0 f32.ceil get_local $1 f32.const 0 call $std/math/check ) - (func $~lib/math/NativeMath.expm1 (; 88 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.expm1 (; 79 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -3527,6 +3525,7 @@ (local $6 i32) (local $7 i64) (local $8 f64) + (local $9 f64) get_local $0 i64.reinterpret/f64 tee_local $7 @@ -3545,7 +3544,8 @@ i32.ge_u if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne if get_local $0 return @@ -3642,9 +3642,10 @@ f64.add f64.mul f64.add + tee_local $9 set_local $1 get_local $2 - get_local $1 + get_local $9 f64.const 3 get_local $1 get_local $8 @@ -3797,12 +3798,12 @@ get_local $5 f64.mul ) - (func $~lib/math/NativeMath.exp (; 89 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.exp (; 80 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 i32) (local $3 f64) - (local $4 f64) - (local $5 i32) + (local $4 i32) + (local $5 f64) get_local $0 i64.reinterpret/f64 i64.const 32 @@ -3811,7 +3812,7 @@ tee_local $1 i32.const 31 i32.shr_u - set_local $5 + set_local $4 get_local $1 i32.const 2147483647 i32.and @@ -3820,7 +3821,8 @@ i32.ge_u if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne if get_local $0 return @@ -3861,7 +3863,7 @@ i32.trunc_s/f64 else i32.const 1 - get_local $5 + get_local $4 i32.const 1 i32.shl i32.sub @@ -3872,26 +3874,25 @@ f64.const 0.6931471803691238 f64.mul f64.sub - tee_local $4 + tee_local $3 get_local $0 f64.const 1.9082149292705877e-10 f64.mul - tee_local $3 + tee_local $5 f64.sub set_local $0 else get_local $1 i32.const 1043333120 - i32.gt_u - if (result f64) - get_local $0 - else + i32.le_u + if f64.const 1 get_local $0 f64.add return end - set_local $4 + get_local $0 + set_local $3 end f64.const 1 get_local $0 @@ -3925,9 +3926,9 @@ get_local $0 f64.sub f64.div - get_local $3 + get_local $5 f64.sub - get_local $4 + get_local $3 f64.add f64.add set_local $0 @@ -3941,7 +3942,7 @@ get_local $2 call $~lib/math/NativeMath.scalbn ) - (func $~lib/math/NativeMath.cosh (; 90 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.cosh (; 81 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 i64) get_local $0 @@ -4005,7 +4006,7 @@ f64.const 2247116418577894884661631e283 f64.mul ) - (func $std/math/test_cosh (; 91 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_cosh (; 82 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.cosh @@ -4016,7 +4017,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/cosh - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -4025,7 +4025,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.expm1 (; 92 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.expm1 (; 83 ;) (type $ff) (param $0 f32) (result f32) (local $1 f32) (local $2 f32) (local $3 i32) @@ -4288,7 +4288,7 @@ get_local $5 f32.mul ) - (func $~lib/math/NativeMathf.exp (; 93 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.exp (; 84 ;) (type $ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -4416,7 +4416,7 @@ get_local $1 call $~lib/math/NativeMathf.scalbn ) - (func $~lib/math/NativeMathf.cosh (; 94 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.cosh (; 85 ;) (type $ff) (param $0 f32) (result f32) (local $1 i32) get_local $0 i32.reinterpret/f32 @@ -4475,14 +4475,14 @@ f32.const 1661534994731144841129758e11 f32.mul ) - (func $std/math/test_coshf (; 95 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_coshf (; 86 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.cosh get_local $1 get_local $2 call $std/math/check ) - (func $std/math/test_exp (; 96 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_exp (; 87 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.exp @@ -4493,7 +4493,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/exp - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -4502,14 +4501,14 @@ end tee_local $3 ) - (func $std/math/test_expf (; 97 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_expf (; 88 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.exp get_local $1 get_local $2 call $std/math/check ) - (func $std/math/test_expm1 (; 98 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_expm1 (; 89 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.expm1 @@ -4520,7 +4519,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/expm1 - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -4529,14 +4527,14 @@ end tee_local $3 ) - (func $std/math/test_expm1f (; 99 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_expm1f (; 90 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.expm1 get_local $1 get_local $2 call $std/math/check ) - (func $std/math/test_floor (; 100 ;) (type $FUNCSIG$iddi) (param $0 f64) (param $1 f64) (param $2 i32) (result i32) + (func $std/math/test_floor (; 91 ;) (type $FUNCSIG$iddi) (param $0 f64) (param $1 f64) (param $2 i32) (result i32) get_local $0 f64.floor get_local $1 @@ -4546,7 +4544,6 @@ if get_local $0 call $~lib/bindings/Math/floor - tee_local $0 get_local $1 f64.const 0 call $std/math/check @@ -4554,14 +4551,14 @@ end get_local $2 ) - (func $std/math/test_floorf (; 101 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) + (func $std/math/test_floorf (; 92 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) get_local $0 f32.floor get_local $1 f32.const 0 call $std/math/check ) - (func $~lib/math/NativeMath.hypot (; 102 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.hypot (; 93 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 i64) (local $4 f64) @@ -4741,7 +4738,7 @@ f64.sqrt f64.mul ) - (func $std/math/test_hypot (; 103 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) + (func $std/math/test_hypot (; 94 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) get_local $0 get_local $1 @@ -4754,7 +4751,6 @@ get_local $0 get_local $1 call $~lib/bindings/Math/hypot - tee_local $0 get_local $2 get_local $3 call $std/math/check @@ -4763,7 +4759,7 @@ end tee_local $4 ) - (func $~lib/math/NativeMathf.hypot (; 104 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.hypot (; 95 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -4877,7 +4873,7 @@ f32.sqrt f32.mul ) - (func $std/math/test_hypotf (; 105 ;) (type $ffffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) + (func $std/math/test_hypotf (; 96 ;) (type $ffffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMathf.hypot @@ -4885,7 +4881,7 @@ get_local $3 call $std/math/check ) - (func $std/math/test_log (; 106 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_log (; 97 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.log @@ -4896,7 +4892,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/log - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -4905,14 +4900,14 @@ end tee_local $3 ) - (func $std/math/test_logf (; 107 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) + (func $std/math/test_logf (; 98 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.log get_local $1 f32.const 0 call $std/math/check ) - (func $~lib/math/NativeMath.log10 (; 108 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log10 (; 99 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 f64) (local $3 i32) @@ -5127,7 +5122,7 @@ get_local $0 f64.add ) - (func $std/math/test_log10 (; 109 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_log10 (; 100 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.log10 @@ -5138,7 +5133,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/log10 - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -5147,7 +5141,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.log10 (; 110 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log10 (; 101 ;) (type $ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -5311,14 +5305,14 @@ f32.mul f32.add ) - (func $std/math/test_log10f (; 111 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_log10f (; 102 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.log10 get_local $1 get_local $2 call $std/math/check ) - (func $std/math/test_log1p (; 112 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_log1p (; 103 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.log1p @@ -5329,7 +5323,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/log1p - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -5338,14 +5331,14 @@ end tee_local $3 ) - (func $std/math/test_log1pf (; 113 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_log1pf (; 104 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.log1p get_local $1 get_local $2 call $std/math/check ) - (func $~lib/math/NativeMath.log2 (; 114 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.log2 (; 105 ;) (type $FF) (param $0 f64) (result f64) (local $1 i32) (local $2 f64) (local $3 i32) @@ -5554,7 +5547,7 @@ tee_local $2 f64.add ) - (func $std/math/test_log2 (; 115 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_log2 (; 106 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.log2 @@ -5565,7 +5558,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/log2 - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -5574,7 +5566,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.log2 (; 116 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.log2 (; 107 ;) (type $ff) (param $0 f32) (result f32) (local $1 i32) (local $2 i32) (local $3 f32) @@ -5730,14 +5722,14 @@ f32.convert_s/i32 f32.add ) - (func $std/math/test_log2f (; 117 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_log2f (; 108 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.log2 get_local $1 get_local $2 call $std/math/check ) - (func $std/math/test_max (; 118 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_max (; 109 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) (local $3 i32) get_local $0 get_local $1 @@ -5750,7 +5742,6 @@ get_local $0 get_local $1 call $~lib/bindings/Math/max - tee_local $0 get_local $2 f64.const 0 call $std/math/check @@ -5758,7 +5749,7 @@ end get_local $3 ) - (func $std/math/test_maxf (; 119 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_maxf (; 110 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) get_local $0 get_local $1 f32.max @@ -5766,7 +5757,7 @@ f32.const 0 call $std/math/check ) - (func $std/math/test_min (; 120 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/math/test_min (; 111 ;) (type $FUNCSIG$iddd) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) (local $3 i32) get_local $0 get_local $1 @@ -5779,7 +5770,6 @@ get_local $0 get_local $1 call $~lib/bindings/Math/min - tee_local $0 get_local $2 f64.const 0 call $std/math/check @@ -5787,7 +5777,7 @@ end get_local $3 ) - (func $std/math/test_minf (; 121 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/math/test_minf (; 112 ;) (type $FUNCSIG$ifff) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) get_local $0 get_local $1 f32.min @@ -5795,7 +5785,7 @@ f32.const 0 call $std/math/check ) - (func $~lib/math/NativeMath.mod (; 122 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.mod (; 113 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) (local $3 i64) (local $4 i64) @@ -6004,7 +5994,7 @@ get_local $0 f64.mul ) - (func $std/math/test_mod (; 123 ;) (type $FUNCSIG$idddi) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_mod (; 114 ;) (type $FUNCSIG$idddi) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMath.mod @@ -6016,7 +6006,6 @@ get_local $0 get_local $1 call $std/math/mod - tee_local $0 get_local $2 f64.const 0 call $std/math/check @@ -6024,7 +6013,7 @@ end get_local $3 ) - (func $~lib/math/NativeMathf.mod (; 124 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.mod (; 115 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -6223,7 +6212,7 @@ get_local $0 f32.mul ) - (func $std/math/test_modf (; 125 ;) (type $FUNCSIG$ifffi) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_modf (; 116 ;) (type $FUNCSIG$ifffi) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMathf.mod @@ -6231,7 +6220,7 @@ f32.const 0 call $std/math/check ) - (func $~lib/math/NativeMath.pow (; 126 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 117 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) (local $4 i32) @@ -7100,6 +7089,7 @@ get_local $2 f64.mul set_local $3 + get_local $13 f64.const 1 get_local $2 get_local $2 @@ -7173,9 +7163,7 @@ i64.or f64.reinterpret/i64 end - set_local $2 - get_local $13 - get_local $2 + tee_local $2 f64.mul return end @@ -7192,7 +7180,7 @@ f64.const 1.e+300 f64.mul ) - (func $std/math/test_pow (; 127 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) + (func $std/math/test_pow (; 118 ;) (type $FFFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 f64) (param $4 i32) (result i32) (local $5 i32) get_local $0 get_local $1 @@ -7205,7 +7193,6 @@ get_local $0 get_local $1 call $~lib/bindings/Math/pow - tee_local $0 get_local $2 get_local $3 call $std/math/check @@ -7214,7 +7201,7 @@ end tee_local $4 ) - (func $~lib/math/NativeMathf.pow (; 128 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.pow (; 119 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) (local $2 f32) (local $3 f32) (local $4 i32) @@ -7952,6 +7939,7 @@ get_local $2 f32.mul set_local $3 + get_local $10 f32.const 1 get_local $2 get_local $2 @@ -8014,9 +8002,7 @@ get_local $8 f32.reinterpret/i32 end - set_local $2 - get_local $10 - get_local $2 + tee_local $2 f32.mul return end @@ -8033,7 +8019,7 @@ f32.const 1.0000000031710769e-30 f32.mul ) - (func $std/math/test_powf (; 129 ;) (type $ffffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) + (func $std/math/test_powf (; 120 ;) (type $ffffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 f32) (param $4 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMathf.pow @@ -8041,28 +8027,7 @@ get_local $3 call $std/math/check ) - (func $~lib/math/murmurHash3 (; 130 ;) (type $II) (param $0 i64) (result i64) - get_local $0 - get_local $0 - i64.const 33 - i64.shr_u - i64.xor - i64.const -49064778989728563 - i64.mul - tee_local $0 - get_local $0 - i64.const 33 - i64.shr_u - i64.xor - i64.const -4265267296055464877 - i64.mul - tee_local $0 - get_local $0 - i64.const 33 - i64.shr_u - i64.xor - ) - (func $~lib/math/splitMix32 (; 131 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/math/splitMix32 (; 121 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 1831565813 i32.add @@ -8094,7 +8059,8 @@ i32.shr_u i32.xor ) - (func $~lib/math/NativeMath.seedRandom (; 132 ;) (type $Iv) (param $0 i64) + (func $~lib/math/NativeMath.seedRandom (; 122 ;) (type $Iv) (param $0 i64) + (local $1 i64) get_local $0 i64.eqz if @@ -8108,12 +8074,47 @@ i32.const 1 set_global $~lib/math/random_seeded get_local $0 - call $~lib/math/murmurHash3 + get_local $0 + i64.const 33 + i64.shr_u + i64.xor + i64.const -49064778989728563 + i64.mul + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor + i64.const -4265267296055464877 + i64.mul + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor set_global $~lib/math/random_state0_64 get_global $~lib/math/random_state0_64 i64.const -1 i64.xor - call $~lib/math/murmurHash3 + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor + i64.const -49064778989728563 + i64.mul + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor + i64.const -4265267296055464877 + i64.mul + tee_local $1 + get_local $1 + i64.const 33 + i64.shr_u + i64.xor set_global $~lib/math/random_state1_64 get_local $0 i32.wrap/i64 @@ -8123,7 +8124,7 @@ call $~lib/math/splitMix32 set_global $~lib/math/random_state1_32 ) - (func $~lib/math/NativeMath.random (; 133 ;) (type $F) (result f64) + (func $~lib/math/NativeMath.random (; 123 ;) (type $F) (result f64) (local $0 i64) (local $1 i64) get_global $~lib/math/random_seeded @@ -8170,7 +8171,7 @@ f64.const 1 f64.sub ) - (func $~lib/math/NativeMathf.random (; 134 ;) (type $f) (result f32) + (func $~lib/math/NativeMathf.random (; 124 ;) (type $f) (result f32) (local $0 i32) (local $1 i32) get_global $~lib/math/random_seeded @@ -8217,7 +8218,7 @@ f32.const 1 f32.sub ) - (func $std/math/test_round (; 135 ;) (type $FUNCSIG$iddi) (param $0 f64) (param $1 f64) (param $2 i32) (result i32) + (func $std/math/test_round (; 125 ;) (type $FUNCSIG$iddi) (param $0 f64) (param $1 f64) (param $2 i32) (result i32) get_local $0 f64.const 0.5 f64.add @@ -8228,7 +8229,7 @@ f64.const 0 call $std/math/check ) - (func $std/math/test_roundf (; 136 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) + (func $std/math/test_roundf (; 126 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) get_local $0 f32.const 0.5 f32.add @@ -8239,7 +8240,7 @@ f32.const 0 call $std/math/check ) - (func $std/math/test_sign (; 137 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) + (func $std/math/test_sign (; 127 ;) (type $FUNCSIG$idd) (param $0 f64) (param $1 f64) (result i32) (local $2 i32) get_local $0 f64.const 0 @@ -8263,7 +8264,6 @@ if get_local $0 call $~lib/bindings/Math/sign - tee_local $0 get_local $1 f64.const 0 call $std/math/check @@ -8271,7 +8271,7 @@ end get_local $2 ) - (func $std/math/test_signf (; 138 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) + (func $std/math/test_signf (; 128 ;) (type $FUNCSIG$iff) (param $0 f32) (param $1 f32) (result i32) get_local $0 f32.const 0 f32.gt @@ -8292,7 +8292,7 @@ f32.const 0 call $std/math/check ) - (func $~lib/math/NativeMath.rem (; 139 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.rem (; 129 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 i64) (local $3 i64) (local $4 i64) @@ -8339,7 +8339,8 @@ i32.eqz if get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f64.ne set_local $5 end get_local $5 @@ -8566,7 +8567,7 @@ end get_local $0 ) - (func $std/math/test_rem (; 140 ;) (type $FUNCSIG$idddi) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_rem (; 130 ;) (type $FUNCSIG$idddi) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMath.rem @@ -8574,7 +8575,7 @@ f64.const 0 call $std/math/check ) - (func $~lib/math/NativeMathf.rem (; 141 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.rem (; 131 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -8619,7 +8620,8 @@ i32.eqz if get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f32.ne set_local $4 end get_local $4 @@ -8835,7 +8837,7 @@ end get_local $0 ) - (func $std/math/test_remf (; 142 ;) (type $FUNCSIG$ifffi) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_remf (; 132 ;) (type $FUNCSIG$ifffi) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMathf.rem @@ -8843,7 +8845,7 @@ f32.const 0 call $std/math/check ) - (func $~lib/math/NativeMath.sinh (; 143 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.sinh (; 133 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 f64) (local $3 i32) @@ -8910,7 +8912,6 @@ f64.const 2 get_local $2 f64.mul - set_local $0 get_local $1 f64.const 1416.0996898839683 f64.sub @@ -8919,12 +8920,9 @@ f64.mul f64.const 2247116418577894884661631e283 f64.mul - set_local $1 - get_local $0 - get_local $1 f64.mul ) - (func $std/math/test_sinh (; 144 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_sinh (; 134 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.sinh @@ -8935,7 +8933,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/sinh - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -8944,7 +8941,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.sinh (; 145 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.sinh (; 135 ;) (type $ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) (local $3 f32) @@ -9006,7 +9003,6 @@ f32.const 2 get_local $3 f32.mul - set_local $0 get_local $1 f32.const 162.88958740234375 f32.sub @@ -9015,19 +9011,16 @@ f32.mul f32.const 1661534994731144841129758e11 f32.mul - set_local $1 - get_local $0 - get_local $1 f32.mul ) - (func $std/math/test_sinhf (; 146 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_sinhf (; 136 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.sinh get_local $1 get_local $2 call $std/math/check ) - (func $std/math/test_sqrt (; 147 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_sqrt (; 137 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 f64.sqrt @@ -9038,7 +9031,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/sqrt - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -9047,14 +9039,14 @@ end tee_local $3 ) - (func $std/math/test_sqrtf (; 148 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_sqrtf (; 138 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 f32.sqrt get_local $1 get_local $2 call $std/math/check ) - (func $~lib/math/NativeMath.tanh (; 149 ;) (type $FF) (param $0 f64) (result f64) + (func $~lib/math/NativeMath.tanh (; 139 ;) (type $FF) (param $0 f64) (result f64) (local $1 f64) (local $2 i32) (local $3 i64) @@ -9133,7 +9125,7 @@ get_local $0 f64.copysign ) - (func $std/math/test_tanh (; 150 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) + (func $std/math/test_tanh (; 140 ;) (type $FFFii) (param $0 f64) (param $1 f64) (param $2 f64) (param $3 i32) (result i32) (local $4 i32) get_local $0 call $~lib/math/NativeMath.tanh @@ -9144,7 +9136,6 @@ if (result i32) get_local $0 call $~lib/bindings/Math/tanh - tee_local $0 get_local $1 get_local $2 call $std/math/check @@ -9153,7 +9144,7 @@ end tee_local $3 ) - (func $~lib/math/NativeMathf.tanh (; 151 ;) (type $ff) (param $0 f32) (result f32) + (func $~lib/math/NativeMathf.tanh (; 141 ;) (type $ff) (param $0 f32) (result f32) (local $1 f32) (local $2 i32) get_local $0 @@ -9227,14 +9218,14 @@ get_local $0 f32.copysign ) - (func $std/math/test_tanhf (; 152 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) + (func $std/math/test_tanhf (; 142 ;) (type $fffii) (param $0 f32) (param $1 f32) (param $2 f32) (param $3 i32) (result i32) get_local $0 call $~lib/math/NativeMathf.tanh get_local $1 get_local $2 call $std/math/check ) - (func $std/math/test_trunc (; 153 ;) (type $FUNCSIG$iddi) (param $0 f64) (param $1 f64) (param $2 i32) (result i32) + (func $std/math/test_trunc (; 143 ;) (type $FUNCSIG$iddi) (param $0 f64) (param $1 f64) (param $2 i32) (result i32) get_local $0 f64.trunc get_local $1 @@ -9244,7 +9235,6 @@ if get_local $0 call $~lib/bindings/Math/trunc - tee_local $0 get_local $1 f64.const 0 call $std/math/check @@ -9252,14 +9242,14 @@ end get_local $2 ) - (func $std/math/test_truncf (; 154 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) + (func $std/math/test_truncf (; 144 ;) (type $FUNCSIG$iffi) (param $0 f32) (param $1 f32) (param $2 i32) (result i32) get_local $0 f32.trunc get_local $1 f32.const 0 call $std/math/check ) - (func $~lib/math/ipow64 (; 155 ;) (type $IiI) (param $0 i64) (param $1 i32) (result i64) + (func $~lib/math/ipow64 (; 145 ;) (type $IiI) (param $0 i64) (param $1 i32) (result i64) (local $2 i64) (local $3 i32) i64.const 1 @@ -9455,13 +9445,11 @@ end get_local $2 ) - (func $start (; 156 ;) (type $v) + (func $start (; 146 ;) (type $v) (local $0 i32) (local $1 i32) (local $2 f64) (local $3 f32) - (local $4 i64) - (local $5 i64) f64.const 2.718281828459045 get_global $~lib/bindings/Math/E f64.const 0 @@ -37691,13 +37679,9 @@ i64.const 57055 i32.const 3 call $~lib/math/ipow64 - set_local $4 i64.const 339590 i32.const 3 call $~lib/math/ipow64 - set_local $5 - get_local $4 - get_local $5 i64.add i64.const 39347712995520375 i64.ne @@ -37710,7 +37694,7 @@ unreachable end ) - (func $null (; 157 ;) (type $v) + (func $null (; 147 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/mod.optimized.wat b/tests/compiler/std/mod.optimized.wat index 56e3130b..7345721c 100644 --- a/tests/compiler/std/mod.optimized.wat +++ b/tests/compiler/std/mod.optimized.wat @@ -2,12 +2,10 @@ (type $FFF (func (param f64 f64) (result f64))) (type $FFFi (func (param f64 f64 f64) (result i32))) (type $FFi (func (param f64 f64) (result i32))) - (type $Fi (func (param f64) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $fffi (func (param f32 f32 f32) (result i32))) (type $fff (func (param f32 f32) (result f32))) (type $ffi (func (param f32 f32) (result i32))) - (type $fi (func (param f32) (result i32))) (type $v (func)) (import "math" "mod" (func $std/mod/mod (param f64 f64) (result f64))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) @@ -228,17 +226,14 @@ get_local $0 f64.mul ) - (func $~lib/builtins/isNaN (; 3 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.ne - ) - (func $std/mod/check (; 4 ;) (type $FFi) (param $0 f64) (param $1 f64) (result i32) + (func $std/mod/check (; 3 ;) (type $FFi) (param $0 f64) (param $1 f64) (result i32) get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f64.ne if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne return end get_local $1 @@ -258,7 +253,7 @@ get_local $1 f64.eq ) - (func $std/mod/test_fmod (; 5 ;) (type $FFFi) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) + (func $std/mod/test_fmod (; 4 ;) (type $FFFi) (param $0 f64) (param $1 f64) (param $2 f64) (result i32) (local $3 i32) get_local $0 get_local $1 @@ -270,14 +265,13 @@ get_local $0 get_local $1 call $std/mod/mod - tee_local $0 get_local $2 call $std/mod/check set_local $3 end get_local $3 ) - (func $~lib/math/NativeMathf.mod (; 6 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) + (func $~lib/math/NativeMathf.mod (; 5 ;) (type $fff) (param $0 f32) (param $1 f32) (result f32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -476,17 +470,14 @@ get_local $0 f32.mul ) - (func $~lib/builtins/isNaN (; 7 ;) (type $fi) (param $0 f32) (result i32) - get_local $0 - get_local $0 - f32.ne - ) - (func $std/mod/check (; 8 ;) (type $ffi) (param $0 f32) (param $1 f32) (result i32) + (func $std/mod/check (; 6 ;) (type $ffi) (param $0 f32) (param $1 f32) (result i32) get_local $1 - call $~lib/builtins/isNaN + get_local $1 + f32.ne if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f32.ne return end get_local $1 @@ -506,14 +497,14 @@ get_local $1 f32.eq ) - (func $std/mod/test_fmodf (; 9 ;) (type $fffi) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) + (func $std/mod/test_fmodf (; 7 ;) (type $fffi) (param $0 f32) (param $1 f32) (param $2 f32) (result i32) get_local $0 get_local $1 call $~lib/math/NativeMathf.mod get_local $2 call $std/mod/check ) - (func $start (; 10 ;) (type $v) + (func $start (; 8 ;) (type $v) f64.const 3 f64.const 2 f64.const 1 @@ -2270,7 +2261,7 @@ unreachable end ) - (func $null (; 11 ;) (type $v) + (func $null (; 9 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/new.optimized.wat b/tests/compiler/std/new.optimized.wat index d5a46f08..b10a54cc 100644 --- a/tests/compiler/std/new.optimized.wat +++ b/tests/compiler/std/new.optimized.wat @@ -73,13 +73,10 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 1 ;) (type $FUNCSIG$i) (result i32) + (func $std/new/AClass#constructor (; 1 ;) (type $FUNCSIG$i) (result i32) + (local $0 i32) i32.const 8 call $~lib/allocator/arena/__memory_allocate - ) - (func $std/new/AClass#constructor (; 2 ;) (type $FUNCSIG$i) (result i32) - (local $0 i32) - call $~lib/memory/memory.allocate tee_local $0 i32.const 1 i32.store @@ -97,7 +94,7 @@ f32.store offset=4 get_local $0 ) - (func $start (; 3 ;) (type $v) + (func $start (; 2 ;) (type $v) i32.const 8 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -105,7 +102,7 @@ call $std/new/AClass#constructor set_global $std/new/aClass ) - (func $null (; 4 ;) (type $v) + (func $null (; 3 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/operator-overloading.optimized.wat b/tests/compiler/std/operator-overloading.optimized.wat index 555a3dc2..8be7761b 100644 --- a/tests/compiler/std/operator-overloading.optimized.wat +++ b/tests/compiler/std/operator-overloading.optimized.wat @@ -5,9 +5,7 @@ (type $FFF (func (param f64 f64) (result f64))) (type $FiF (func (param f64 i32) (result f64))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$ii (func (param i32) (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\1b\00\00\00s\00t\00d\00/\00o\00p\00e\00r\00a\00t\00o\00r\00-\00o\00v\00e\00r\00l\00o\00a\00d\00i\00n\00g\00.\00t\00s") @@ -146,13 +144,10 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 2 ;) (type $FUNCSIG$i) (result i32) + (func $std/operator-overloading/Tester#constructor (; 2 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) i32.const 8 call $~lib/allocator/arena/__memory_allocate - ) - (func $std/operator-overloading/Tester#constructor (; 3 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - call $~lib/memory/memory.allocate tee_local $2 get_local $0 i32.store @@ -161,72 +156,7 @@ i32.store offset=4 get_local $2 ) - (func $std/operator-overloading/Tester.add (; 4 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.add - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.add - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.sub (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.sub - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.sub - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.mul (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.mul - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.mul - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.div (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.div_s - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.div_s - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.mod (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.rem_s - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.rem_s - call $std/operator-overloading/Tester#constructor - ) - (func $~lib/math/NativeMath.scalbn (; 9 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) + (func $~lib/math/NativeMath.scalbn (; 3 ;) (type $FiF) (param $0 f64) (param $1 i32) (result f64) get_local $1 i32.const 1023 i32.gt_s @@ -300,7 +230,7 @@ f64.reinterpret/i64 f64.mul ) - (func $~lib/math/NativeMath.pow (; 10 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) + (func $~lib/math/NativeMath.pow (; 4 ;) (type $FFF) (param $0 f64) (param $1 f64) (result f64) (local $2 f64) (local $3 f64) (local $4 i32) @@ -1169,6 +1099,7 @@ get_local $2 f64.mul set_local $3 + get_local $13 f64.const 1 get_local $2 get_local $2 @@ -1242,9 +1173,7 @@ i64.or f64.reinterpret/i64 end - set_local $2 - get_local $13 - get_local $2 + tee_local $2 f64.mul return end @@ -1261,8 +1190,7 @@ f64.const 1.e+300 f64.mul ) - (func $std/operator-overloading/Tester.pow (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) + (func $std/operator-overloading/Tester.pow (; 5 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 i32.load f64.convert_s/i32 @@ -1271,7 +1199,6 @@ f64.convert_s/i32 call $~lib/math/NativeMath.pow i32.trunc_s/f64 - set_local $2 get_local $0 i32.load offset=4 f64.convert_s/i32 @@ -1280,289 +1207,12 @@ f64.convert_s/i32 call $~lib/math/NativeMath.pow i32.trunc_s/f64 - set_local $0 - get_local $2 - get_local $0 call $std/operator-overloading/Tester#constructor ) - (func $std/operator-overloading/Tester.and (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.and - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.and - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.or (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.or - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.or - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.xor (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.xor - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.xor - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.equals (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.eq - tee_local $2 - if - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.eq - set_local $2 - end - get_local $2 - ) - (func $std/operator-overloading/Tester.notEquals (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.ne - tee_local $2 - if - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.ne - set_local $2 - end - get_local $2 - ) - (func $std/operator-overloading/Tester.greater (; 17 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.gt_s - tee_local $2 - if - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.gt_s - set_local $2 - end - get_local $2 - ) - (func $std/operator-overloading/Tester.greaterEquals (; 18 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.ge_s - tee_local $2 - if - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.ge_s - set_local $2 - end - get_local $2 - ) - (func $std/operator-overloading/Tester.less (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.lt_s - tee_local $2 - if - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.lt_s - set_local $2 - end - get_local $2 - ) - (func $std/operator-overloading/Tester.lessEquals (; 20 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $0 - i32.load - get_local $1 - i32.load - i32.le_s - tee_local $2 - if - get_local $0 - i32.load offset=4 - get_local $1 - i32.load offset=4 - i32.le_s - set_local $2 - end - get_local $2 - ) - (func $std/operator-overloading/Tester.shr (; 21 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const 3 - i32.shr_s - get_local $0 - i32.load offset=4 - i32.const 3 - i32.shr_s - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.shu (; 22 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const 3 - i32.shr_u - get_local $0 - i32.load offset=4 - i32.const 3 - i32.shr_u - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.shl (; 23 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const 3 - i32.shl - get_local $0 - i32.load offset=4 - i32.const 3 - i32.shl - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.pos (; 24 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - get_local $0 - i32.load offset=4 - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.neg (; 25 ;) (type $ii) (param $0 i32) (result i32) - i32.const 0 - get_local $0 - i32.load - i32.sub - i32.const 0 - get_local $0 - i32.load offset=4 - i32.sub - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.not (; 26 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const -1 - i32.xor - get_local $0 - i32.load offset=4 - i32.const -1 - i32.xor - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester.excl (; 27 ;) (type $ii) (param $0 i32) (result i32) - (local $1 i32) - get_local $0 - i32.load - i32.eqz - tee_local $1 - if - get_local $0 - i32.load offset=4 - i32.eqz - set_local $1 - end - get_local $1 - ) - (func $std/operator-overloading/Tester#inc (; 28 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - get_local $0 - i32.load - i32.const 1 - i32.add - i32.store - get_local $0 - get_local $0 - i32.load offset=4 - i32.const 1 - i32.add - i32.store offset=4 - get_local $0 - ) - (func $std/operator-overloading/Tester#dec (; 29 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - get_local $0 - i32.load - i32.const 1 - i32.sub - i32.store - get_local $0 - get_local $0 - i32.load offset=4 - i32.const 1 - i32.sub - i32.store offset=4 - get_local $0 - ) - (func $std/operator-overloading/Tester#postInc (; 30 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const 1 - i32.add - get_local $0 - i32.load offset=4 - i32.const 1 - i32.add - call $std/operator-overloading/Tester#constructor - ) - (func $std/operator-overloading/Tester#postDec (; 31 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load - i32.const 1 - i32.sub - get_local $0 - i32.load offset=4 - i32.const 1 - i32.sub - call $std/operator-overloading/Tester#constructor - ) - (func $start (; 32 ;) (type $v) + (func $start (; 6 ;) (type $v) (local $0 i32) (local $1 i32) + (local $2 i32) i32.const 72 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -1576,8 +1226,18 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/a2 get_global $std/operator-overloading/a1 + tee_local $0 + i32.load get_global $std/operator-overloading/a2 - call $std/operator-overloading/Tester.add + tee_local $1 + i32.load + i32.add + get_local $0 + i32.load offset=4 + get_local $1 + i32.load offset=4 + i32.add + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/a get_global $std/operator-overloading/a i32.load @@ -1610,8 +1270,18 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/s2 get_global $std/operator-overloading/s1 + tee_local $0 + i32.load get_global $std/operator-overloading/s2 - call $std/operator-overloading/Tester.sub + tee_local $1 + i32.load + i32.sub + get_local $0 + i32.load offset=4 + get_local $1 + i32.load offset=4 + i32.sub + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/s get_global $std/operator-overloading/s i32.load @@ -1643,8 +1313,18 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/m2 get_global $std/operator-overloading/m1 + tee_local $0 + i32.load get_global $std/operator-overloading/m2 - call $std/operator-overloading/Tester.mul + tee_local $1 + i32.load + i32.mul + get_local $0 + i32.load offset=4 + get_local $1 + i32.load offset=4 + i32.mul + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/m get_global $std/operator-overloading/m i32.load @@ -1677,8 +1357,18 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/d2 get_global $std/operator-overloading/d1 + tee_local $0 + i32.load get_global $std/operator-overloading/d2 - call $std/operator-overloading/Tester.div + tee_local $1 + i32.load + i32.div_s + get_local $0 + i32.load offset=4 + get_local $1 + i32.load offset=4 + i32.div_s + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/d get_global $std/operator-overloading/d i32.load @@ -1711,8 +1401,18 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/f2 get_global $std/operator-overloading/f1 + tee_local $0 + i32.load get_global $std/operator-overloading/f2 - call $std/operator-overloading/Tester.mod + tee_local $1 + i32.load + i32.rem_s + get_local $0 + i32.load offset=4 + get_local $1 + i32.load offset=4 + i32.rem_s + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/f get_global $std/operator-overloading/f i32.load @@ -1778,8 +1478,18 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/n2 get_global $std/operator-overloading/n1 + tee_local $0 + i32.load get_global $std/operator-overloading/n2 - call $std/operator-overloading/Tester.and + tee_local $1 + i32.load + i32.and + get_local $0 + i32.load offset=4 + get_local $1 + i32.load offset=4 + i32.and + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/n get_global $std/operator-overloading/n i32.load @@ -1812,8 +1522,18 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/o2 get_global $std/operator-overloading/o1 + tee_local $0 + i32.load get_global $std/operator-overloading/o2 - call $std/operator-overloading/Tester.or + tee_local $1 + i32.load + i32.or + get_local $0 + i32.load offset=4 + get_local $1 + i32.load offset=4 + i32.or + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/o get_global $std/operator-overloading/o i32.load @@ -1846,8 +1566,18 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/x2 get_global $std/operator-overloading/x1 + tee_local $0 + i32.load get_global $std/operator-overloading/x2 - call $std/operator-overloading/Tester.xor + tee_local $1 + i32.load + i32.xor + get_local $0 + i32.load offset=4 + get_local $1 + i32.load offset=4 + i32.xor + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/x get_global $std/operator-overloading/x i32.load @@ -1880,8 +1610,22 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/eq2 get_global $std/operator-overloading/eq1 + tee_local $1 + i32.load get_global $std/operator-overloading/eq2 - call $std/operator-overloading/Tester.equals + tee_local $2 + i32.load + i32.eq + tee_local $0 + if + get_local $1 + i32.load offset=4 + get_local $2 + i32.load offset=4 + i32.eq + set_local $0 + end + get_local $0 set_global $std/operator-overloading/eq get_global $std/operator-overloading/eq i32.const 1 @@ -1903,8 +1647,22 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/eq4 get_global $std/operator-overloading/eq3 + tee_local $1 + i32.load get_global $std/operator-overloading/eq4 - call $std/operator-overloading/Tester.equals + tee_local $2 + i32.load + i32.eq + tee_local $0 + if + get_local $1 + i32.load offset=4 + get_local $2 + i32.load offset=4 + i32.eq + set_local $0 + end + get_local $0 set_global $std/operator-overloading/eqf get_global $std/operator-overloading/eqf if @@ -1916,8 +1674,22 @@ unreachable end get_global $std/operator-overloading/eq1 + tee_local $1 + i32.load get_global $std/operator-overloading/eq2 - call $std/operator-overloading/Tester.notEquals + tee_local $2 + i32.load + i32.ne + tee_local $0 + if + get_local $1 + i32.load offset=4 + get_local $2 + i32.load offset=4 + i32.ne + set_local $0 + end + get_local $0 set_global $std/operator-overloading/eq get_global $std/operator-overloading/eq if @@ -1929,8 +1701,22 @@ unreachable end get_global $std/operator-overloading/eq3 + tee_local $1 + i32.load get_global $std/operator-overloading/eq4 - call $std/operator-overloading/Tester.notEquals + tee_local $2 + i32.load + i32.ne + tee_local $0 + if + get_local $1 + i32.load offset=4 + get_local $2 + i32.load offset=4 + i32.ne + set_local $0 + end + get_local $0 set_global $std/operator-overloading/eqf get_global $std/operator-overloading/eqf i32.const 1 @@ -1952,8 +1738,22 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/gt2 get_global $std/operator-overloading/gt1 + tee_local $1 + i32.load get_global $std/operator-overloading/gt2 - call $std/operator-overloading/Tester.greater + tee_local $2 + i32.load + i32.gt_s + tee_local $0 + if + get_local $1 + i32.load offset=4 + get_local $2 + i32.load offset=4 + i32.gt_s + set_local $0 + end + get_local $0 set_global $std/operator-overloading/gt get_global $std/operator-overloading/gt i32.const 1 @@ -1975,8 +1775,22 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/gte2 get_global $std/operator-overloading/gte1 + tee_local $1 + i32.load get_global $std/operator-overloading/gte2 - call $std/operator-overloading/Tester.greaterEquals + tee_local $2 + i32.load + i32.ge_s + tee_local $0 + if + get_local $1 + i32.load offset=4 + get_local $2 + i32.load offset=4 + i32.ge_s + set_local $0 + end + get_local $0 set_global $std/operator-overloading/gte get_global $std/operator-overloading/gte i32.const 1 @@ -1998,8 +1812,22 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/le2 get_global $std/operator-overloading/le1 + tee_local $1 + i32.load get_global $std/operator-overloading/le2 - call $std/operator-overloading/Tester.less + tee_local $2 + i32.load + i32.lt_s + tee_local $0 + if + get_local $1 + i32.load offset=4 + get_local $2 + i32.load offset=4 + i32.lt_s + set_local $0 + end + get_local $0 set_global $std/operator-overloading/le get_global $std/operator-overloading/le i32.const 1 @@ -2021,8 +1849,22 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/leq2 get_global $std/operator-overloading/leq1 + tee_local $1 + i32.load get_global $std/operator-overloading/leq2 - call $std/operator-overloading/Tester.lessEquals + tee_local $2 + i32.load + i32.le_s + tee_local $0 + if + get_local $1 + i32.load offset=4 + get_local $2 + i32.load offset=4 + i32.le_s + set_local $0 + end + get_local $0 set_global $std/operator-overloading/leq get_global $std/operator-overloading/leq i32.const 1 @@ -2040,7 +1882,15 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/shr get_global $std/operator-overloading/shr - call $std/operator-overloading/Tester.shr + tee_local $0 + i32.load + i32.const 3 + i32.shr_s + get_local $0 + i32.load offset=4 + i32.const 3 + i32.shr_s + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/sres get_global $std/operator-overloading/sres i32.load @@ -2069,7 +1919,15 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/shu get_global $std/operator-overloading/shu - call $std/operator-overloading/Tester.shu + tee_local $0 + i32.load + i32.const 3 + i32.shr_u + get_local $0 + i32.load offset=4 + i32.const 3 + i32.shr_u + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/ures get_global $std/operator-overloading/ures i32.load @@ -2098,7 +1956,15 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/shl get_global $std/operator-overloading/shl - call $std/operator-overloading/Tester.shl + tee_local $0 + i32.load + i32.const 3 + i32.shl + get_local $0 + i32.load offset=4 + i32.const 3 + i32.shl + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/sres get_global $std/operator-overloading/sres i32.load @@ -2127,7 +1993,11 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/pos get_global $std/operator-overloading/pos - call $std/operator-overloading/Tester.pos + tee_local $0 + i32.load + get_local $0 + i32.load offset=4 + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/pres get_global $std/operator-overloading/pres i32.load @@ -2157,8 +2027,16 @@ i32.const -2 call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/neg + i32.const 0 get_global $std/operator-overloading/neg - call $std/operator-overloading/Tester.neg + tee_local $0 + i32.load + i32.sub + i32.const 0 + get_local $0 + i32.load offset=4 + i32.sub + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/nres get_global $std/operator-overloading/nres i32.load @@ -2193,7 +2071,15 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/not get_global $std/operator-overloading/not - call $std/operator-overloading/Tester.not + tee_local $0 + i32.load + i32.const -1 + i32.xor + get_local $0 + i32.load offset=4 + i32.const -1 + i32.xor + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/res get_global $std/operator-overloading/res i32.load @@ -2228,7 +2114,17 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/excl get_global $std/operator-overloading/excl - call $std/operator-overloading/Tester.excl + tee_local $1 + i32.load + i32.eqz + tee_local $0 + if + get_local $1 + i32.load offset=4 + i32.eqz + set_local $0 + end + get_local $0 set_global $std/operator-overloading/bres get_global $std/operator-overloading/bres set_local $1 @@ -2269,7 +2165,19 @@ call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/incdec get_global $std/operator-overloading/incdec - call $std/operator-overloading/Tester#inc + tee_local $0 + get_local $0 + i32.load + i32.const 1 + i32.add + i32.store + get_local $0 + get_local $0 + i32.load offset=4 + i32.const 1 + i32.add + i32.store offset=4 + get_local $0 set_global $std/operator-overloading/incdec get_global $std/operator-overloading/incdec i32.load @@ -2294,7 +2202,19 @@ unreachable end get_global $std/operator-overloading/incdec - call $std/operator-overloading/Tester#dec + tee_local $0 + get_local $0 + i32.load + i32.const 1 + i32.sub + i32.store + get_local $0 + get_local $0 + i32.load offset=4 + i32.const 1 + i32.sub + i32.store offset=4 + get_local $0 set_global $std/operator-overloading/incdec get_global $std/operator-overloading/incdec i32.load @@ -2323,7 +2243,14 @@ set_global $std/operator-overloading/incdec get_global $std/operator-overloading/incdec tee_local $0 - call $std/operator-overloading/Tester#postInc + i32.load + i32.const 1 + i32.add + get_local $0 + i32.load offset=4 + i32.const 1 + i32.add + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/incdec get_local $0 set_global $std/operator-overloading/tmp @@ -2372,7 +2299,14 @@ end get_global $std/operator-overloading/incdec tee_local $0 - call $std/operator-overloading/Tester#postDec + i32.load + i32.const 1 + i32.sub + get_local $0 + i32.load offset=4 + i32.const 1 + i32.sub + call $std/operator-overloading/Tester#constructor set_global $std/operator-overloading/incdec get_local $0 set_global $std/operator-overloading/tmp @@ -2530,7 +2464,7 @@ unreachable end ) - (func $null (; 33 ;) (type $v) + (func $null (; 7 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/pointer.optimized.wat b/tests/compiler/std/pointer.optimized.wat index 0bc70743..91fd189f 100644 --- a/tests/compiler/std/pointer.optimized.wat +++ b/tests/compiler/std/pointer.optimized.wat @@ -1,11 +1,7 @@ (module (type $iiiiv (func (param i32 i32 i32 i32))) - (type $iiv (func (param i32 i32))) (type $iiiv (func (param i32 i32 i32))) - (type $iifv (func (param i32 i32 f32))) - (type $iif (func (param i32 i32) (result f32))) (type $v (func)) - (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vi (func (param i32))) (type $FUNCSIG$vii (func (param i32 i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) @@ -22,10 +18,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $std/pointer/Pointer#constructor (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - get_local $0 - ) - (func $~lib/internal/memory/memset (; 2 ;) (type $FUNCSIG$vi) (param $0 i32) + (func $~lib/internal/memory/memset (; 1 ;) (type $FUNCSIG$vi) (param $0 i32) (local $1 i32) get_local $0 i32.const 0 @@ -69,7 +62,7 @@ i32.const 0 i32.store8 ) - (func $~lib/internal/memory/memcpy (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 2 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -973,7 +966,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 4 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memmove (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1176,45 +1169,12 @@ end end ) - (func $std/pointer/Pointer#set:value (; 5 ;) (type $iiv) (param $0 i32) (param $1 i32) - get_local $1 - if - get_local $0 - get_local $1 - call $~lib/internal/memory/memmove - else - get_local $0 - call $~lib/internal/memory/memset - end - ) - (func $std/pointer/Pointer#set (; 6 ;) (type $iifv) (param $0 i32) (param $1 i32) (param $2 f32) - get_local $0 - get_local $1 - i32.const 2 - i32.shl - i32.add - get_local $2 - f32.store - ) - (func $std/pointer/Pointer#get (; 7 ;) (type $iif) (param $0 i32) (param $1 i32) (result f32) - get_local $0 - get_local $1 - i32.const 2 - i32.shl - i32.add - f32.load - ) - (func $std/pointer/Pointer#set:value (; 8 ;) (type $FUNCSIG$vi) (param $0 i32) - get_local $0 - f32.const 1.399999976158142 - f32.store - ) - (func $start (; 9 ;) (type $v) + (func $start (; 4 ;) (type $v) + (local $0 i32) + (local $1 i32) i32.const 8 - call $std/pointer/Pointer#constructor set_global $std/pointer/one i32.const 24 - call $std/pointer/Pointer#constructor set_global $std/pointer/two get_global $std/pointer/one i32.const 8 @@ -1392,8 +1352,17 @@ unreachable end get_global $std/pointer/one + set_local $0 get_global $std/pointer/two - call $std/pointer/Pointer#set:value + tee_local $1 + if + get_local $0 + get_local $1 + call $~lib/internal/memory/memmove + else + get_local $0 + call $~lib/internal/memory/memset + end get_global $std/pointer/one get_global $std/pointer/two i32.eq @@ -1430,19 +1399,17 @@ unreachable end i32.const 0 - call $std/pointer/Pointer#constructor set_global $std/pointer/buf get_global $std/pointer/buf - i32.const 0 f32.const 1.100000023841858 - call $std/pointer/Pointer#set + f32.store get_global $std/pointer/buf - i32.const 1 + i32.const 4 + i32.add f32.const 1.2000000476837158 - call $std/pointer/Pointer#set + f32.store get_global $std/pointer/buf - i32.const 0 - call $std/pointer/Pointer#get + f32.load f32.const 1.100000023841858 f32.ne if @@ -1454,8 +1421,9 @@ unreachable end get_global $std/pointer/buf - i32.const 1 - call $std/pointer/Pointer#get + i32.const 4 + i32.add + f32.load f32.const 1.2000000476837158 f32.ne if @@ -1522,8 +1490,9 @@ f32.const 1.2999999523162842 f32.store get_global $std/pointer/buf - i32.const 2 - call $std/pointer/Pointer#get + i32.const 8 + i32.add + f32.load f32.const 1.2999999523162842 f32.ne if @@ -1561,7 +1530,8 @@ unreachable end get_global $std/pointer/buf - call $std/pointer/Pointer#set:value + f32.const 1.399999976158142 + f32.store get_global $std/pointer/buf f32.load f32.const 1.399999976158142 @@ -1587,7 +1557,7 @@ unreachable end ) - (func $null (; 10 ;) (type $v) + (func $null (; 5 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/polyfills.optimized.wat b/tests/compiler/std/polyfills.optimized.wat index b8d5d5ef..1f970123 100644 --- a/tests/compiler/std/polyfills.optimized.wat +++ b/tests/compiler/std/polyfills.optimized.wat @@ -2,8 +2,6 @@ (type $ii (func (param i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) - (type $FUNCSIG$j (func (result i64))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\11\00\00\00~\00l\00i\00b\00/\00p\00o\00l\00y\00f\00i\00l\00l\00s\00.\00t\00s") @@ -54,11 +52,7 @@ end get_local $0 ) - (func $~lib/polyfills/bswap (; 2 ;) (type $FUNCSIG$i) (result i32) - i32.const 43707 - call $~lib/polyfills/bswap16 - ) - (func $~lib/polyfills/bswap16 (; 3 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/polyfills/bswap16 (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) i32.const 1 tee_local $1 @@ -101,21 +95,9 @@ end get_local $0 ) - (func $~lib/polyfills/bswap (; 4 ;) (type $FUNCSIG$i) (result i32) + (func $start (; 3 ;) (type $v) i32.const 43707 - call $~lib/polyfills/bswap16 - ) - (func $~lib/polyfills/bswap (; 5 ;) (type $FUNCSIG$i) (result i32) - i32.const -573785174 - ) - (func $~lib/polyfills/bswap (; 6 ;) (type $FUNCSIG$j) (result i64) - i64.const -2464388556401798912 - ) - (func $~lib/polyfills/bswap16 (; 7 ;) (type $FUNCSIG$i) (result i32) - i32.const -7816278 - ) - (func $start (; 8 ;) (type $v) - call $~lib/polyfills/bswap + call $~lib/polyfills/bswap16 i32.const 65535 i32.and i32.const 48042 @@ -128,7 +110,8 @@ call $~lib/env/abort unreachable end - call $~lib/polyfills/bswap + i32.const 43707 + call $~lib/polyfills/bswap16 i32.const 65535 i32.and i32.const 48042 @@ -141,72 +124,6 @@ call $~lib/env/abort unreachable end - call $~lib/polyfills/bswap - i32.const -573785174 - i32.ne - if - i32.const 0 - i32.const 48 - i32.const 8 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $~lib/polyfills/bswap - i32.const -573785174 - i32.ne - if - i32.const 0 - i32.const 48 - i32.const 9 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $~lib/polyfills/bswap - i64.const -2464388556401798912 - i64.ne - if - i32.const 0 - i32.const 48 - i32.const 12 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $~lib/polyfills/bswap - i64.const -2464388556401798912 - i64.ne - if - i32.const 0 - i32.const 48 - i32.const 13 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $~lib/polyfills/bswap - i32.const -573785174 - i32.ne - if - i32.const 0 - i32.const 48 - i32.const 16 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $~lib/polyfills/bswap - i32.const -573785174 - i32.ne - if - i32.const 0 - i32.const 48 - i32.const 17 - i32.const 0 - call $~lib/env/abort - unreachable - end i32.const 43707 call $~lib/polyfills/bswap16 i32.const 65535 @@ -235,30 +152,8 @@ call $~lib/env/abort unreachable end - call $~lib/polyfills/bswap16 - i32.const -7816278 - i32.ne - if - i32.const 0 - i32.const 48 - i32.const 24 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $~lib/polyfills/bswap16 - i32.const -7816278 - i32.ne - if - i32.const 0 - i32.const 48 - i32.const 25 - i32.const 0 - call $~lib/env/abort - unreachable - end ) - (func $null (; 9 ;) (type $v) + (func $null (; 4 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/set.optimized.wat b/tests/compiler/std/set.optimized.wat index fa6b7359..1670373f 100644 --- a/tests/compiler/std/set.optimized.wat +++ b/tests/compiler/std/set.optimized.wat @@ -18,9 +18,9 @@ (type $Fi (func (param f64) (result i32))) (type $iFii (func (param i32 f64 i32) (result i32))) (type $iFv (func (param i32 f64))) - (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\13\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00b\00u\00f\00f\00e\00r\00.\00t\00s") @@ -95,21 +95,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 2 ;) (type $FUNCSIG$i) (result i32) - i32.const 24 - call $~lib/allocator/arena/__memory_allocate - ) - (func $~lib/internal/arraybuffer/computeSize (; 3 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 4 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -122,15 +108,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/internal/memory/memset (; 5 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) get_local $1 i32.eqz @@ -349,7 +341,7 @@ end end ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 6 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 i32.const 1073741816 @@ -378,24 +370,19 @@ end get_local $2 ) - (func $~lib/set/Set#clear (; 7 ;) (type $iv) (param $0 i32) - (local $1 i32) + (func $~lib/set/Set#clear (; 5 ;) (type $iv) (param $0 i32) + get_local $0 i32.const 16 i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store get_local $0 i32.const 3 i32.store offset=4 + get_local $0 i32.const 32 i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store offset=8 get_local $0 i32.const 4 @@ -407,9 +394,10 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/set/Set#constructor (; 8 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 6 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) - call $~lib/memory/memory.allocate + i32.const 24 + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 0 i32.store @@ -432,22 +420,7 @@ call $~lib/set/Set#clear get_local $0 ) - (func $~lib/internal/hash/hash8 (; 9 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const -2128831035 - i32.xor - i32.const 16777619 - i32.mul - ) - (func $~lib/internal/hash/hash (; 10 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 24 - i32.shl - i32.const 24 - i32.shr_s - call $~lib/internal/hash/hash8 - ) - (func $~lib/set/Set#find (; 11 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/set/Set#find (; 7 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -492,19 +465,23 @@ end i32.const 0 ) - (func $~lib/set/Set#has (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $2 + (func $~lib/set/Set#has (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + i32.const 24 + i32.shl + i32.const 24 + i32.shr_s + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/set/Set#find i32.const 0 i32.ne ) - (func $~lib/set/Set#rehash (; 13 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#rehash (; 9 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -520,18 +497,18 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 3 i32.shl i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 @@ -542,14 +519,14 @@ i32.const 3 i32.shl i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add set_local $3 loop $continue|0 get_local $2 - get_local $8 + get_local $7 i32.ne if get_local $2 @@ -562,22 +539,23 @@ get_local $2 i32.load8_s i32.store8 + get_local $3 + get_local $4 get_local $2 i32.load8_s - call $~lib/internal/hash/hash8 - set_local $4 - get_local $3 - get_local $5 - get_local $4 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=4 - get_local $4 + get_local $8 get_local $3 i32.store offset=8 get_local $3 @@ -593,32 +571,40 @@ end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set#add (; 14 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#add (; 10 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) get_local $1 - call $~lib/internal/hash/hash + i32.const 24 + i32.shl + i32.const 24 + i32.shr_s + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul + tee_local $2 set_local $4 get_local $0 get_local $1 - get_local $4 + get_local $2 call $~lib/set/Set#find i32.eqz if @@ -696,81 +682,76 @@ i32.store offset=8 end ) - (func $~lib/set/Set#get:size (; 15 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.load offset=20 - ) - (func $~lib/set/Set#delete (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/set/Set#delete (; 11 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.const 24 i32.shl i32.const 24 i32.shr_s - call $~lib/internal/hash/hash8 - set_local $0 - get_local $2 - get_local $1 - get_local $0 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/set/Set#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=4 i32.const 1 i32.or i32.store offset=4 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/set/Set#rehash end i32.const 1 ) - (func $std/set/test (; 17 ;) (type $v) + (func $std/set/test (; 12 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/set/Set#constructor @@ -818,7 +799,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -875,7 +856,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -933,7 +914,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -1005,7 +986,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -1019,7 +1000,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -1029,25 +1010,21 @@ unreachable end ) - (func $~lib/internal/hash/hash (; 18 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/set/Set#has (; 13 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 + get_local $1 + get_local $1 i32.const 255 i32.and - call $~lib/internal/hash/hash8 - ) - (func $~lib/set/Set#has (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $2 - get_local $0 - get_local $1 - get_local $2 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/set/Set#find i32.const 0 i32.ne ) - (func $~lib/set/Set#rehash (; 20 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#rehash (; 14 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1063,18 +1040,18 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 3 i32.shl i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 @@ -1085,14 +1062,14 @@ i32.const 3 i32.shl i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add set_local $3 loop $continue|0 get_local $2 - get_local $8 + get_local $7 i32.ne if get_local $2 @@ -1105,22 +1082,23 @@ get_local $2 i32.load8_u i32.store8 + get_local $3 + get_local $4 get_local $2 i32.load8_u - call $~lib/internal/hash/hash8 - set_local $4 - get_local $3 - get_local $5 - get_local $4 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=4 - get_local $4 + get_local $8 get_local $3 i32.store offset=8 get_local $3 @@ -1136,32 +1114,38 @@ end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set#add (; 21 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#add (; 15 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) get_local $1 - call $~lib/internal/hash/hash + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul + tee_local $2 set_local $4 get_local $0 get_local $1 - get_local $4 + get_local $2 call $~lib/set/Set#find i32.eqz if @@ -1239,75 +1223,74 @@ i32.store offset=8 end ) - (func $~lib/set/Set#delete (; 22 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/set/Set#delete (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.const 255 i32.and - call $~lib/internal/hash/hash8 - set_local $0 - get_local $2 - get_local $1 - get_local $0 + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul call $~lib/set/Set#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=4 i32.const 1 i32.or i32.store offset=4 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/set/Set#rehash end i32.const 1 ) - (func $std/set/test (; 23 ;) (type $v) + (func $std/set/test (; 17 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/set/Set#constructor @@ -1355,7 +1338,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -1412,7 +1395,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -1470,7 +1453,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -1542,7 +1525,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -1556,7 +1539,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -1566,30 +1549,7 @@ unreachable end ) - (func $~lib/internal/hash/hash16 (; 24 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 255 - i32.and - i32.const -2128831035 - i32.xor - i32.const 16777619 - i32.mul - get_local $0 - i32.const 8 - i32.shr_u - i32.xor - i32.const 16777619 - i32.mul - ) - (func $~lib/internal/hash/hash (; 25 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 16 - i32.shl - i32.const 16 - i32.shr_s - call $~lib/internal/hash/hash16 - ) - (func $~lib/set/Set#find (; 26 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/set/Set#find (; 18 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -1634,19 +1594,33 @@ end i32.const 0 ) - (func $~lib/set/Set#has (; 27 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/set/Set#has (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $2 get_local $0 get_local $1 + get_local $1 + i32.const 16 + i32.shl + i32.const 16 + i32.shr_s + tee_local $2 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $2 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/set/Set#find i32.const 0 i32.ne ) - (func $~lib/set/Set#rehash (; 28 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#rehash (; 20 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1704,13 +1678,23 @@ get_local $2 i32.load16_s i32.store16 - get_local $2 - i32.load16_s - call $~lib/internal/hash/hash16 - set_local $4 get_local $3 get_local $5 + get_local $2 + i32.load16_s + tee_local $4 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $4 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul get_local $1 i32.and i32.const 2 @@ -1751,16 +1735,33 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set#add (; 29 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#add (; 21 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) get_local $1 - call $~lib/internal/hash/hash + i32.const 16 + i32.shl + i32.const 16 + i32.shr_s + tee_local $2 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul + get_local $2 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul + tee_local $2 set_local $4 get_local $0 get_local $1 - get_local $4 + get_local $2 call $~lib/set/Set#find i32.eqz if @@ -1838,77 +1839,85 @@ i32.store offset=8 end ) - (func $~lib/set/Set#delete (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/set/Set#delete (; 22 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.const 16 i32.shl i32.const 16 i32.shr_s - call $~lib/internal/hash/hash16 - set_local $0 - get_local $2 + tee_local $1 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $1 - get_local $0 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/set/Set#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=4 i32.const 1 i32.or i32.store offset=4 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/set/Set#rehash end i32.const 1 ) - (func $std/set/test (; 31 ;) (type $v) + (func $std/set/test (; 23 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/set/Set#constructor @@ -1956,7 +1965,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -2013,7 +2022,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -2071,7 +2080,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -2143,7 +2152,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -2157,7 +2166,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -2167,25 +2176,31 @@ unreachable end ) - (func $~lib/internal/hash/hash (; 32 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/set/Set#has (; 24 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (local $2 i32) get_local $0 + get_local $1 + get_local $1 i32.const 65535 i32.and - call $~lib/internal/hash/hash16 - ) - (func $~lib/set/Set#has (; 33 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $2 - get_local $0 - get_local $1 + tee_local $2 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $2 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/set/Set#find i32.const 0 i32.ne ) - (func $~lib/set/Set#rehash (; 34 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#rehash (; 25 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2243,13 +2258,23 @@ get_local $2 i32.load16_u i32.store16 - get_local $2 - i32.load16_u - call $~lib/internal/hash/hash16 - set_local $4 get_local $3 get_local $5 + get_local $2 + i32.load16_u + tee_local $4 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $4 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul get_local $1 i32.and i32.const 2 @@ -2290,16 +2315,31 @@ i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set#add (; 35 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#add (; 26 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) get_local $1 - call $~lib/internal/hash/hash + i32.const 65535 + i32.and + tee_local $2 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul + get_local $2 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul + tee_local $2 set_local $4 get_local $0 get_local $1 - get_local $4 + get_local $2 call $~lib/set/Set#find i32.eqz if @@ -2377,75 +2417,83 @@ i32.store offset=8 end ) - (func $~lib/set/Set#delete (; 36 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/set/Set#delete (; 27 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.const 65535 i32.and - call $~lib/internal/hash/hash16 - set_local $0 - get_local $2 + tee_local $1 + i32.const 255 + i32.and + i32.const -2128831035 + i32.xor + i32.const 16777619 + i32.mul get_local $1 - get_local $0 + i32.const 8 + i32.shr_u + i32.xor + i32.const 16777619 + i32.mul call $~lib/set/Set#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=4 i32.const 1 i32.or i32.store offset=4 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/set/Set#rehash end i32.const 1 ) - (func $std/set/test (; 37 ;) (type $v) + (func $std/set/test (; 28 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/set/Set#constructor @@ -2493,7 +2541,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -2550,7 +2598,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -2608,7 +2656,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -2680,7 +2728,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -2694,7 +2742,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -2704,7 +2752,7 @@ unreachable end ) - (func $~lib/internal/hash/hash32 (; 38 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/hash/hash32 (; 29 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 255 i32.and @@ -2735,11 +2783,7 @@ i32.const 16777619 i32.mul ) - (func $~lib/internal/hash/hash (; 39 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - call $~lib/internal/hash/hash32 - ) - (func $~lib/set/Set#find (; 40 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/set/Set#find (; 30 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -2782,19 +2826,16 @@ end i32.const 0 ) - (func $~lib/set/Set#has (; 41 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $2 + (func $~lib/set/Set#has (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + call $~lib/internal/hash/hash32 call $~lib/set/Set#find i32.const 0 i32.ne ) - (func $~lib/set/Set#rehash (; 42 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#rehash (; 32 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2810,18 +2851,18 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 3 i32.shl i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 @@ -2832,14 +2873,14 @@ i32.const 3 i32.shl i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add set_local $3 loop $continue|0 get_local $2 - get_local $8 + get_local $7 i32.ne if get_local $2 @@ -2852,22 +2893,20 @@ get_local $2 i32.load i32.store + get_local $3 + get_local $4 get_local $2 i32.load call $~lib/internal/hash/hash32 - set_local $4 - get_local $3 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=4 - get_local $4 + get_local $8 get_local $3 i32.store offset=8 get_local $3 @@ -2883,32 +2922,33 @@ end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set#add (; 43 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#add (; 33 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) get_local $1 - call $~lib/internal/hash/hash + call $~lib/internal/hash/hash32 + tee_local $2 set_local $4 get_local $0 get_local $1 - get_local $4 + get_local $2 call $~lib/set/Set#find i32.eqz if @@ -2986,73 +3026,69 @@ i32.store offset=8 end ) - (func $~lib/set/Set#delete (; 44 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/set/Set#delete (; 34 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 call $~lib/internal/hash/hash32 - set_local $0 - get_local $2 - get_local $1 - get_local $0 call $~lib/set/Set#find - tee_local $0 + tee_local $1 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $1 + get_local $1 i32.load offset=4 i32.const 1 i32.or i32.store offset=4 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u - tee_local $1 + tee_local $2 i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $1 + i32.const 4 + get_local $1 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $1 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $1 end - get_local $0 + get_local $1 if + get_local $0 get_local $2 - get_local $1 call $~lib/set/Set#rehash end i32.const 1 ) - (func $std/set/test (; 45 ;) (type $v) + (func $std/set/test (; 35 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/set/Set#constructor @@ -3100,7 +3136,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -3157,7 +3193,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -3215,7 +3251,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -3287,7 +3323,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -3301,7 +3337,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -3311,7 +3347,7 @@ unreachable end ) - (func $std/set/test (; 46 ;) (type $v) + (func $std/set/test (; 36 ;) (type $v) (local $0 i32) (local $1 i32) call $~lib/set/Set#constructor @@ -3359,7 +3395,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -3416,7 +3452,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -3474,7 +3510,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -3546,7 +3582,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -3560,7 +3596,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -3570,24 +3606,19 @@ unreachable end ) - (func $~lib/set/Set#clear (; 47 ;) (type $iv) (param $0 i32) - (local $1 i32) + (func $~lib/set/Set#clear (; 37 ;) (type $iv) (param $0 i32) + get_local $0 i32.const 16 i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store get_local $0 i32.const 3 i32.store offset=4 + get_local $0 i32.const 64 i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store offset=8 get_local $0 i32.const 4 @@ -3599,9 +3630,10 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/set/Set#constructor (; 48 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/set/Set#constructor (; 38 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) - call $~lib/memory/memory.allocate + i32.const 24 + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 0 i32.store @@ -3624,7 +3656,7 @@ call $~lib/set/Set#clear get_local $0 ) - (func $~lib/internal/hash/hash64 (; 49 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/hash/hash64 (; 39 ;) (type $Ii) (param $0 i64) (result i32) (local $1 i32) get_local $0 i32.wrap/i64 @@ -3690,11 +3722,7 @@ i32.const 16777619 i32.mul ) - (func $~lib/internal/hash/hash (; 50 ;) (type $Ii) (param $0 i64) (result i32) - get_local $0 - call $~lib/internal/hash/hash64 - ) - (func $~lib/set/Set#find (; 51 ;) (type $iIii) (param $0 i32) (param $1 i64) (param $2 i32) (result i32) + (func $~lib/set/Set#find (; 40 ;) (type $iIii) (param $0 i32) (param $1 i64) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -3737,19 +3765,16 @@ end i32.const 0 ) - (func $~lib/set/Set#has (; 52 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $2 + (func $~lib/set/Set#has (; 41 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + call $~lib/internal/hash/hash64 call $~lib/set/Set#find i32.const 0 i32.ne ) - (func $~lib/set/Set#rehash (; 53 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#rehash (; 42 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -3765,18 +3790,18 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 4 i32.shl i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 @@ -3787,14 +3812,14 @@ i32.const 4 i32.shl i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add set_local $3 loop $continue|0 get_local $2 - get_local $8 + get_local $7 i32.ne if get_local $2 @@ -3807,22 +3832,20 @@ get_local $2 i64.load i64.store + get_local $3 + get_local $4 get_local $2 i64.load call $~lib/internal/hash/hash64 - set_local $4 - get_local $3 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=8 - get_local $4 + get_local $8 get_local $3 i32.store offset=8 get_local $3 @@ -3838,32 +3861,33 @@ end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set#add (; 54 ;) (type $iIv) (param $0 i32) (param $1 i64) + (func $~lib/set/Set#add (; 43 ;) (type $iIv) (param $0 i32) (param $1 i64) (local $2 i32) (local $3 i32) (local $4 i32) get_local $1 - call $~lib/internal/hash/hash + call $~lib/internal/hash/hash64 + tee_local $2 set_local $4 get_local $0 get_local $1 - get_local $4 + get_local $2 call $~lib/set/Set#find i32.eqz if @@ -3941,37 +3965,33 @@ i32.store offset=8 end ) - (func $~lib/set/Set#delete (; 55 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) + (func $~lib/set/Set#delete (; 44 ;) (type $iIi) (param $0 i32) (param $1 i64) (result i32) (local $2 i32) (local $3 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 call $~lib/internal/hash/hash64 - set_local $0 - get_local $2 - get_local $1 - get_local $0 call $~lib/set/Set#find - tee_local $0 + tee_local $2 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $2 + get_local $2 i32.load offset=8 i32.const 1 i32.or i32.store offset=8 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u @@ -3979,36 +3999,36 @@ i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $2 + i32.const 4 + get_local $2 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $2 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $2 end - get_local $0 + get_local $2 if - get_local $2 + get_local $0 get_local $3 call $~lib/set/Set#rehash end i32.const 1 ) - (func $std/set/test (; 56 ;) (type $v) + (func $std/set/test (; 45 ;) (type $v) (local $0 i64) (local $1 i32) call $~lib/set/Set#constructor @@ -4056,7 +4076,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4113,7 +4133,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4171,7 +4191,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -4243,7 +4263,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -4257,7 +4277,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -4267,7 +4287,7 @@ unreachable end ) - (func $std/set/test (; 57 ;) (type $v) + (func $std/set/test (; 46 ;) (type $v) (local $0 i64) (local $1 i32) call $~lib/set/Set#constructor @@ -4315,7 +4335,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4372,7 +4392,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4430,7 +4450,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -4502,7 +4522,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -4516,7 +4536,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -4526,12 +4546,12 @@ unreachable end ) - (func $~lib/internal/hash/hash (; 58 ;) (type $fi) (param $0 f32) (result i32) + (func $~lib/internal/hash/hash (; 47 ;) (type $fi) (param $0 f32) (result i32) get_local $0 i32.reinterpret/f32 call $~lib/internal/hash/hash32 ) - (func $~lib/set/Set#find (; 59 ;) (type $ifii) (param $0 i32) (param $1 f32) (param $2 i32) (result i32) + (func $~lib/set/Set#find (; 48 ;) (type $ifii) (param $0 i32) (param $1 f32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -4574,19 +4594,16 @@ end i32.const 0 ) - (func $~lib/set/Set#has (; 60 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $2 + (func $~lib/set/Set#has (; 49 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + call $~lib/internal/hash/hash call $~lib/set/Set#find i32.const 0 i32.ne ) - (func $~lib/set/Set#rehash (; 61 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#rehash (; 50 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -4602,18 +4619,18 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 3 i32.shl i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 @@ -4624,14 +4641,14 @@ i32.const 3 i32.shl i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add set_local $3 loop $continue|0 get_local $2 - get_local $8 + get_local $7 i32.ne if get_local $2 @@ -4644,23 +4661,21 @@ get_local $2 f32.load f32.store + get_local $3 + get_local $4 get_local $2 f32.load i32.reinterpret/f32 call $~lib/internal/hash/hash32 - set_local $4 - get_local $3 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=4 - get_local $4 + get_local $8 get_local $3 i32.store offset=8 get_local $3 @@ -4676,32 +4691,31 @@ end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set#add (; 62 ;) (type $ifv) (param $0 i32) (param $1 f32) + (func $~lib/set/Set#add (; 51 ;) (type $ifv) (param $0 i32) (param $1 f32) (local $2 i32) (local $3 i32) (local $4 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $4 get_local $0 get_local $1 - get_local $4 + get_local $1 + call $~lib/internal/hash/hash + tee_local $4 call $~lib/set/Set#find i32.eqz if @@ -4779,38 +4793,34 @@ i32.store offset=8 end ) - (func $~lib/set/Set#delete (; 63 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) + (func $~lib/set/Set#delete (; 52 ;) (type $ifi) (param $0 i32) (param $1 f32) (result i32) (local $2 i32) (local $3 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i32.reinterpret/f32 call $~lib/internal/hash/hash32 - set_local $0 - get_local $2 - get_local $1 - get_local $0 call $~lib/set/Set#find - tee_local $0 + tee_local $2 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $2 + get_local $2 i32.load offset=4 i32.const 1 i32.or i32.store offset=4 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u @@ -4818,36 +4828,36 @@ i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $2 + i32.const 4 + get_local $2 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $2 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $2 end - get_local $0 + get_local $2 if - get_local $2 + get_local $0 get_local $3 call $~lib/set/Set#rehash end i32.const 1 ) - (func $std/set/test (; 64 ;) (type $v) + (func $std/set/test (; 53 ;) (type $v) (local $0 f32) (local $1 i32) call $~lib/set/Set#constructor @@ -4896,7 +4906,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -4954,7 +4964,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -5013,7 +5023,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -5086,7 +5096,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -5100,7 +5110,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -5110,12 +5120,12 @@ unreachable end ) - (func $~lib/internal/hash/hash (; 65 ;) (type $Fi) (param $0 f64) (result i32) + (func $~lib/internal/hash/hash (; 54 ;) (type $Fi) (param $0 f64) (result i32) get_local $0 i64.reinterpret/f64 call $~lib/internal/hash/hash64 ) - (func $~lib/set/Set#find (; 66 ;) (type $iFii) (param $0 i32) (param $1 f64) (param $2 i32) (result i32) + (func $~lib/set/Set#find (; 55 ;) (type $iFii) (param $0 i32) (param $1 f64) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -5158,19 +5168,16 @@ end i32.const 0 ) - (func $~lib/set/Set#has (; 67 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $2 + (func $~lib/set/Set#has (; 56 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) get_local $0 get_local $1 - get_local $2 + get_local $1 + call $~lib/internal/hash/hash call $~lib/set/Set#find i32.const 0 i32.ne ) - (func $~lib/set/Set#rehash (; 68 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/set/Set#rehash (; 57 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5186,18 +5193,18 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 4 i32.shl i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 @@ -5208,14 +5215,14 @@ i32.const 4 i32.shl i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add set_local $3 loop $continue|0 get_local $2 - get_local $8 + get_local $7 i32.ne if get_local $2 @@ -5228,23 +5235,21 @@ get_local $2 f64.load f64.store + get_local $3 + get_local $4 get_local $2 f64.load i64.reinterpret/f64 call $~lib/internal/hash/hash64 - set_local $4 - get_local $3 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=8 - get_local $4 + get_local $8 get_local $3 i32.store offset=8 get_local $3 @@ -5260,32 +5265,31 @@ end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/set/Set#add (; 69 ;) (type $iFv) (param $0 i32) (param $1 f64) + (func $~lib/set/Set#add (; 58 ;) (type $iFv) (param $0 i32) (param $1 f64) (local $2 i32) (local $3 i32) (local $4 i32) - get_local $1 - call $~lib/internal/hash/hash - set_local $4 get_local $0 get_local $1 - get_local $4 + get_local $1 + call $~lib/internal/hash/hash + tee_local $4 call $~lib/set/Set#find i32.eqz if @@ -5363,38 +5367,34 @@ i32.store offset=8 end ) - (func $~lib/set/Set#delete (; 70 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) + (func $~lib/set/Set#delete (; 59 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) (local $2 i32) (local $3 i32) get_local $0 - set_local $2 + get_local $1 get_local $1 i64.reinterpret/f64 call $~lib/internal/hash/hash64 - set_local $0 - get_local $2 - get_local $1 - get_local $0 call $~lib/set/Set#find - tee_local $0 + tee_local $2 i32.eqz if i32.const 0 return end - get_local $0 - get_local $0 + get_local $2 + get_local $2 i32.load offset=8 i32.const 1 i32.or i32.store offset=8 - get_local $2 - get_local $2 + get_local $0 + get_local $0 i32.load offset=20 i32.const 1 i32.sub i32.store offset=20 - get_local $2 + get_local $0 i32.load offset=4 i32.const 1 i32.shr_u @@ -5402,36 +5402,36 @@ i32.const 1 i32.add i32.const 4 - get_local $2 - i32.load offset=20 - tee_local $0 - i32.const 4 get_local $0 + i32.load offset=20 + tee_local $2 + i32.const 4 + get_local $2 i32.gt_u select i32.ge_u - tee_local $0 + tee_local $2 if - get_local $2 + get_local $0 i32.load offset=20 - get_local $2 + get_local $0 i32.load offset=12 f64.convert_s/i32 f64.const 0.75 f64.mul i32.trunc_s/f64 i32.lt_s - set_local $0 + set_local $2 end - get_local $0 + get_local $2 if - get_local $2 + get_local $0 get_local $3 call $~lib/set/Set#rehash end i32.const 1 ) - (func $std/set/test (; 71 ;) (type $v) + (func $std/set/test (; 60 ;) (type $v) (local $0 f64) (local $1 i32) call $~lib/set/Set#constructor @@ -5480,7 +5480,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -5538,7 +5538,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 100 i32.ne if @@ -5597,7 +5597,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -5670,7 +5670,7 @@ unreachable end get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 i32.const 50 i32.ne if @@ -5684,7 +5684,7 @@ get_local $1 call $~lib/set/Set#clear get_local $1 - call $~lib/set/Set#get:size + i32.load offset=20 if i32.const 0 i32.const 120 @@ -5694,7 +5694,7 @@ unreachable end ) - (func $start (; 72 ;) (type $v) + (func $start (; 61 ;) (type $v) i32.const 144 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -5710,7 +5710,7 @@ call $std/set/test call $std/set/test ) - (func $null (; 73 ;) (type $v) + (func $null (; 62 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/static-array.optimized.wat b/tests/compiler/std/static-array.optimized.wat index 3fcdc5ee..ee11414d 100644 --- a/tests/compiler/std/static-array.optimized.wat +++ b/tests/compiler/std/static-array.optimized.wat @@ -4,12 +4,8 @@ (type $iiiv (func (param i32 i32 i32))) (type $ii (func (param i32) (result i32))) (type $v (func)) - (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$v (func)) - (type $FUNCSIG$ji (func (param i32) (result i64))) - (type $FUNCSIG$fi (func (param i32) (result f32))) - (type $FUNCSIG$di (func (param i32) (result f64))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\08\00\00\00\00\00\00\00\01\00\00\00\02") @@ -32,39 +28,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/array/Array#__get (; 1 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - get_local $0 - i32.const 24 - i32.load - tee_local $1 - i32.load - i32.const 2 - i32.shr_u - i32.lt_u - if (result i32) - get_local $1 - get_local $0 - i32.const 2 - i32.shl - i32.add - i32.load offset=8 - else - unreachable - end - tee_local $1 - ) - (func $~lib/internal/arraybuffer/computeSize (; 2 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 1 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) get_local $1 i32.eqz @@ -283,7 +247,7 @@ end end ) - (func $~lib/allocator/arena/__memory_allocate (; 4 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/__memory_allocate (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -345,7 +309,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 5 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -358,15 +322,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/internal/memory/memcpy (; 6 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1270,7 +1240,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 7 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 5 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) get_local $0 @@ -1470,9 +1440,10 @@ end end ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateUnsafe (; 6 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) + (local $4 i32) get_local $1 get_local $0 i32.load @@ -1490,11 +1461,15 @@ call $~lib/env/abort unreachable end - get_local $2 - call $~lib/internal/arraybuffer/computeSize - set_local $3 get_local $1 - get_local $3 + i32.const 1 + i32.const 32 + get_local $2 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl i32.const 8 i32.sub i32.le_s @@ -1517,14 +1492,13 @@ tee_local $3 i32.const 8 i32.add + tee_local $4 get_local $0 i32.const 8 i32.add get_local $2 call $~lib/internal/memory/memmove - get_local $3 - i32.const 8 - i32.add + get_local $4 get_local $2 i32.add get_local $1 @@ -1557,7 +1531,7 @@ end get_local $0 ) - (func $~lib/array/Array#__set (; 9 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 7 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 0 i32.const 24 @@ -1582,28 +1556,7 @@ i32.const 2 i32.store offset=8 ) - (func $~lib/array/Array#__get (; 10 ;) (type $FUNCSIG$ji) (param $0 i32) (result i64) - (local $1 i32) - get_local $0 - i32.const 64 - i32.load - tee_local $1 - i32.load - i32.const 3 - i32.shr_u - i32.lt_u - if (result i64) - get_local $1 - get_local $0 - i32.const 3 - i32.shl - i32.add - i64.load offset=8 - else - unreachable - end - ) - (func $~lib/array/Array#__set (; 11 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 8 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 0 i32.const 64 @@ -1628,28 +1581,7 @@ i64.const 4 i64.store offset=8 ) - (func $~lib/array/Array#__get (; 12 ;) (type $FUNCSIG$fi) (param $0 i32) (result f32) - (local $1 i32) - get_local $0 - i32.const 88 - i32.load - tee_local $1 - i32.load - i32.const 2 - i32.shr_u - i32.lt_u - if (result f32) - get_local $1 - get_local $0 - i32.const 2 - i32.shl - i32.add - f32.load offset=8 - else - unreachable - end - ) - (func $~lib/array/Array#__set (; 13 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 9 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 0 i32.const 88 @@ -1674,28 +1606,7 @@ f32.const 2.5 f32.store offset=8 ) - (func $~lib/array/Array#__get (; 14 ;) (type $FUNCSIG$di) (param $0 i32) (result f64) - (local $1 i32) - get_local $0 - i32.const 128 - i32.load - tee_local $1 - i32.load - i32.const 3 - i32.shr_u - i32.lt_u - if (result f64) - get_local $1 - get_local $0 - i32.const 3 - i32.shl - i32.add - f64.load offset=8 - else - unreachable - end - ) - (func $~lib/array/Array#__set (; 15 ;) (type $FUNCSIG$v) + (func $~lib/array/Array#__set (; 10 ;) (type $FUNCSIG$v) (local $0 i32) i32.const 0 i32.const 128 @@ -1720,7 +1631,8 @@ f64.const 2.25 f64.store offset=8 ) - (func $start (; 16 ;) (type $v) + (func $start (; 11 ;) (type $v) + (local $0 i32) i32.const 280 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -1738,7 +1650,20 @@ unreachable end i32.const 0 - call $~lib/array/Array#__get + i32.const 24 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 1 i32.ne if @@ -1750,7 +1675,22 @@ unreachable end i32.const 1 - call $~lib/array/Array#__get + i32.const 24 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 2 i32.ne if @@ -1763,7 +1703,20 @@ end call $~lib/array/Array#__set i32.const 0 - call $~lib/array/Array#__get + i32.const 24 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 2 i32.ne if @@ -1787,7 +1740,19 @@ unreachable end i32.const 0 - call $~lib/array/Array#__get + i32.const 64 + i32.load + tee_local $0 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result i64) + get_local $0 + i64.load offset=8 + else + unreachable + end i64.const 3 i64.ne if @@ -1799,7 +1764,21 @@ unreachable end i32.const 1 - call $~lib/array/Array#__get + i32.const 64 + i32.load + tee_local $0 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result i64) + get_local $0 + i32.const 8 + i32.add + i64.load offset=8 + else + unreachable + end i64.const 4 i64.ne if @@ -1812,7 +1791,19 @@ end call $~lib/array/Array#__set i32.const 0 - call $~lib/array/Array#__get + i32.const 64 + i32.load + tee_local $0 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result i64) + get_local $0 + i64.load offset=8 + else + unreachable + end i64.const 4 i64.ne if @@ -1836,7 +1827,19 @@ unreachable end i32.const 0 - call $~lib/array/Array#__get + i32.const 88 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result f32) + get_local $0 + f32.load offset=8 + else + unreachable + end f32.const 1.5 f32.ne if @@ -1848,7 +1851,21 @@ unreachable end i32.const 1 - call $~lib/array/Array#__get + i32.const 88 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result f32) + get_local $0 + i32.const 4 + i32.add + f32.load offset=8 + else + unreachable + end f32.const 2.5 f32.ne if @@ -1861,7 +1878,19 @@ end call $~lib/array/Array#__set i32.const 0 - call $~lib/array/Array#__get + i32.const 88 + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result f32) + get_local $0 + f32.load offset=8 + else + unreachable + end f32.const 2.5 f32.ne if @@ -1885,7 +1914,19 @@ unreachable end i32.const 0 - call $~lib/array/Array#__get + i32.const 128 + i32.load + tee_local $0 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result f64) + get_local $0 + f64.load offset=8 + else + unreachable + end f64.const 1.25 f64.ne if @@ -1897,7 +1938,21 @@ unreachable end i32.const 1 - call $~lib/array/Array#__get + i32.const 128 + i32.load + tee_local $0 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result f64) + get_local $0 + i32.const 8 + i32.add + f64.load offset=8 + else + unreachable + end f64.const 2.25 f64.ne if @@ -1910,7 +1965,19 @@ end call $~lib/array/Array#__set i32.const 0 - call $~lib/array/Array#__get + i32.const 128 + i32.load + tee_local $0 + i32.load + i32.const 3 + i32.shr_u + i32.lt_u + if (result f64) + get_local $0 + f64.load offset=8 + else + unreachable + end f64.const 2.25 f64.ne if @@ -1922,7 +1989,7 @@ unreachable end ) - (func $null (; 17 ;) (type $v) + (func $null (; 12 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/string-utf8.optimized.wat b/tests/compiler/std/string-utf8.optimized.wat index 5a4b3788..052a0fce 100644 --- a/tests/compiler/std/string-utf8.optimized.wat +++ b/tests/compiler/std/string-utf8.optimized.wat @@ -4,7 +4,6 @@ (type $iii (func (param i32 i32) (result i32))) (type $iiiv (func (param i32 i32 i32))) (type $v (func)) - (type $FUNCSIG$v (func)) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) @@ -1523,10 +1522,7 @@ end end ) - (func $~lib/allocator/arena/__memory_free (; 7 ;) (type $FUNCSIG$v) - nop - ) - (func $~lib/string/String.fromUTF8 (; 8 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.fromUTF8 (; 7 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1550,34 +1546,33 @@ i32.lt_u if get_local $2 - tee_local $4 + tee_local $3 i32.const 1 i32.add set_local $2 get_local $0 - get_local $4 + get_local $3 i32.add i32.load8_u - tee_local $4 + tee_local $3 i32.const 128 i32.lt_u - if + if (result i32) get_local $6 - get_local $3 - i32.add get_local $4 - i32.store16 + i32.add get_local $3 + i32.store16 + get_local $4 i32.const 2 i32.add - set_local $3 else - get_local $4 + get_local $3 i32.const 191 i32.gt_u tee_local $5 if - get_local $4 + get_local $3 i32.const 224 i32.lt_u set_local $5 @@ -1603,9 +1598,9 @@ i32.add set_local $2 get_local $6 - get_local $3 - i32.add get_local $4 + i32.add + get_local $3 i32.const 31 i32.and i32.const 6 @@ -1618,17 +1613,13 @@ i32.and i32.or i32.store16 - get_local $3 - i32.const 2 - i32.add - set_local $3 else - get_local $4 + get_local $3 i32.const 239 i32.gt_u tee_local $5 if - get_local $4 + get_local $3 i32.const 365 i32.lt_u set_local $5 @@ -1649,9 +1640,9 @@ unreachable end get_local $6 - get_local $3 - i32.add get_local $4 + i32.add + get_local $3 i32.const 7 i32.and i32.const 18 @@ -1666,7 +1657,6 @@ i32.const 12 i32.shl i32.or - tee_local $4 get_local $0 get_local $2 i32.const 1 @@ -1679,13 +1669,12 @@ i32.const 6 i32.shl i32.or - tee_local $4 + tee_local $3 get_local $0 get_local $2 i32.const 1 i32.add tee_local $2 - tee_local $5 i32.add i32.load8_u i32.const 63 @@ -1693,19 +1682,19 @@ i32.or i32.const 65536 i32.sub - tee_local $4 + tee_local $3 i32.const 10 i32.shr_u i32.const 55296 i32.add i32.store16 get_local $6 - get_local $3 + get_local $4 i32.const 2 i32.add - tee_local $3 + tee_local $4 i32.add - get_local $4 + get_local $3 i32.const 1023 i32.and i32.const 56320 @@ -1726,9 +1715,9 @@ unreachable end get_local $6 - get_local $3 - i32.add get_local $4 + i32.add + get_local $3 i32.const 15 i32.and i32.const 12 @@ -1743,13 +1732,12 @@ i32.const 6 i32.shl i32.or - tee_local $4 + tee_local $3 get_local $0 get_local $2 i32.const 1 i32.add tee_local $2 - tee_local $5 i32.add i32.load8_u i32.const 63 @@ -1757,16 +1745,16 @@ i32.or i32.store16 end - get_local $3 - i32.const 2 - i32.add - set_local $3 get_local $2 i32.const 1 i32.add set_local $2 end + get_local $4 + i32.const 2 + i32.add end + set_local $4 br $continue|0 end end @@ -1781,21 +1769,19 @@ call $~lib/env/abort unreachable end - get_local $3 + get_local $4 i32.const 1 i32.shr_u call $~lib/internal/string/allocateUnsafe tee_local $0 i32.const 4 i32.add - tee_local $4 get_local $6 - get_local $3 + get_local $4 call $~lib/internal/memory/memmove - call $~lib/allocator/arena/__memory_free get_local $0 ) - (func $~lib/internal/string/compareUnsafe (; 9 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/string/compareUnsafe (; 8 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -1832,7 +1818,7 @@ end get_local $4 ) - (func $~lib/string/String.__eq (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 get_local $1 @@ -1871,7 +1857,7 @@ call $~lib/internal/string/compareUnsafe i32.eqz ) - (func $start (; 11 ;) (type $v) + (func $start (; 10 ;) (type $v) i32.const 192 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -2115,9 +2101,8 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free ) - (func $null (; 12 ;) (type $v) + (func $null (; 11 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/string.optimized.wat b/tests/compiler/std/string.optimized.wat index d0589d5d..fe8116e6 100644 --- a/tests/compiler/std/string.optimized.wat +++ b/tests/compiler/std/string.optimized.wat @@ -18,9 +18,7 @@ (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) (type $FUNCSIG$di (func (param i32) (result f64))) - (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) - (type $FUNCSIG$v (func)) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\10\00\00\00h\00i\00,\00 \00I\00\'\00m\00 \00a\00 \00s\00t\00r\00i\00n\00g") @@ -539,27 +537,7 @@ call $~lib/internal/string/compareUnsafe i32.eqz ) - (func $~lib/string/String#endsWith|trampoline (; 10 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - block $1of1 - block $0of1 - block $outOfRange - get_global $~argc - i32.const 1 - i32.sub - br_table $0of1 $1of1 $outOfRange - end - unreachable - end - i32.const 536870910 - set_local $1 - end - get_local $0 - i32.const 216 - get_local $1 - call $~lib/string/String#endsWith - ) - (func $~lib/string/String#indexOf (; 11 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/string/String#indexOf (; 10 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -639,7 +617,7 @@ end i32.const -1 ) - (func $~lib/internal/memory/memcpy (; 12 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memcpy (; 11 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -1543,7 +1521,7 @@ i32.store8 end ) - (func $~lib/internal/memory/memmove (; 13 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memmove (; 12 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) get_local $0 @@ -1743,7 +1721,7 @@ end end ) - (func $~lib/internal/string/repeatUnsafe (; 14 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) + (func $~lib/internal/string/repeatUnsafe (; 13 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) @@ -1965,7 +1943,7 @@ end end ) - (func $~lib/internal/string/copyUnsafe (; 15 ;) (type $iiiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) + (func $~lib/internal/string/copyUnsafe (; 14 ;) (type $iiiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (param $4 i32) get_local $0 get_local $1 i32.const 1 @@ -1985,12 +1963,11 @@ i32.shl call $~lib/internal/memory/memmove ) - (func $~lib/string/String#padStart (; 16 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/string/String#padStart (; 15 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) - (local $7 i32) get_local $0 i32.eqz if @@ -2009,75 +1986,74 @@ i32.load tee_local $6 i32.lt_s - tee_local $5 + tee_local $4 i32.eqz if get_local $3 i32.eqz - set_local $5 + set_local $4 end - get_local $5 + get_local $4 if get_local $0 return end get_local $1 + call $~lib/internal/string/allocateUnsafe + set_local $5 + get_local $1 get_local $6 i32.sub - set_local $4 - get_local $1 - call $~lib/internal/string/allocateUnsafe - set_local $1 - get_local $4 + tee_local $1 get_local $3 i32.gt_s if - get_local $4 - get_local $4 + get_local $1 i32.const 1 i32.sub get_local $3 i32.div_s - tee_local $5 + tee_local $4 get_local $3 i32.mul - tee_local $7 - i32.sub set_local $3 - get_local $1 + get_local $5 i32.const 0 get_local $2 - get_local $5 + get_local $4 call $~lib/internal/string/repeatUnsafe + get_local $1 get_local $3 + i32.sub + tee_local $4 if - get_local $1 - get_local $7 + get_local $5 + get_local $3 get_local $2 i32.const 0 - get_local $3 + get_local $4 call $~lib/internal/string/copyUnsafe end else - get_local $1 + get_local $5 i32.const 0 get_local $2 i32.const 0 - get_local $4 + get_local $1 call $~lib/internal/string/copyUnsafe end get_local $6 if + get_local $5 get_local $1 - get_local $4 get_local $0 i32.const 0 get_local $6 call $~lib/internal/string/copyUnsafe end - get_local $1 + get_local $5 ) - (func $~lib/string/String#padStart|trampoline (; 17 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#padStart|trampoline (; 16 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -2097,10 +2073,11 @@ get_local $2 call $~lib/string/String#padStart ) - (func $~lib/string/String#padEnd (; 18 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/string/String#padEnd (; 17 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) + (local $6 i32) get_local $0 i32.eqz if @@ -2113,83 +2090,83 @@ end get_local $2 i32.load - set_local $4 + set_local $5 get_local $1 get_local $0 i32.load - tee_local $5 - i32.lt_s tee_local $3 + i32.lt_s + tee_local $4 i32.eqz if - get_local $4 + get_local $5 i32.eqz - set_local $3 + set_local $4 end - get_local $3 + get_local $4 if get_local $0 return end get_local $1 - get_local $5 + get_local $3 i32.sub - set_local $3 + set_local $6 get_local $1 call $~lib/internal/string/allocateUnsafe set_local $1 - get_local $5 + get_local $3 if get_local $1 i32.const 0 get_local $0 i32.const 0 - get_local $5 + get_local $3 call $~lib/internal/string/copyUnsafe end - get_local $3 - get_local $4 + get_local $6 + get_local $5 i32.gt_s if - get_local $3 - get_local $3 + get_local $6 i32.const 1 i32.sub - get_local $4 + get_local $5 i32.div_s - tee_local $3 - get_local $4 - i32.mul tee_local $4 - i32.sub + get_local $5 + i32.mul set_local $0 get_local $1 - get_local $5 - get_local $2 get_local $3 + get_local $2 + get_local $4 call $~lib/internal/string/repeatUnsafe + get_local $6 get_local $0 + i32.sub + tee_local $4 if get_local $1 - get_local $4 - get_local $5 + get_local $0 + get_local $3 i32.add get_local $2 i32.const 0 - get_local $0 + get_local $4 call $~lib/internal/string/copyUnsafe end else get_local $1 - get_local $5 + get_local $3 get_local $2 i32.const 0 - get_local $3 + get_local $6 call $~lib/internal/string/copyUnsafe end get_local $1 ) - (func $~lib/string/String#padEnd|trampoline (; 19 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#padEnd|trampoline (; 18 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -2209,7 +2186,7 @@ get_local $2 call $~lib/string/String#padEnd ) - (func $~lib/string/String#lastIndexOf (; 20 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/string/String#lastIndexOf (; 19 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -2289,7 +2266,7 @@ end i32.const -1 ) - (func $~lib/string/String#lastIndexOf|trampoline (; 21 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#lastIndexOf|trampoline (; 20 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) block $1of1 block $0of1 @@ -2309,10 +2286,10 @@ get_local $2 call $~lib/string/String#lastIndexOf ) - (func $std/string/getString (; 22 ;) (type $i) (result i32) + (func $std/string/getString (; 21 ;) (type $i) (result i32) get_global $std/string/str ) - (func $~lib/internal/string/parse (; 23 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) + (func $~lib/internal/string/parse (; 22 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2564,12 +2541,12 @@ get_local $5 f64.mul ) - (func $~lib/string/parseInt (; 24 ;) (type $FUNCSIG$di) (param $0 i32) (result f64) + (func $~lib/string/parseInt (; 23 ;) (type $FUNCSIG$di) (param $0 i32) (result f64) get_local $0 i32.const 0 call $~lib/internal/string/parse ) - (func $~lib/string/parseFloat (; 25 ;) (type $iF) (param $0 i32) (result f64) + (func $~lib/string/parseFloat (; 24 ;) (type $iF) (param $0 i32) (result f64) (local $1 i32) (local $2 i32) (local $3 i32) @@ -2737,7 +2714,7 @@ get_local $4 f64.mul ) - (func $~lib/string/String#concat (; 26 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#concat (; 25 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2786,7 +2763,7 @@ call $~lib/internal/string/copyUnsafe get_local $2 ) - (func $~lib/string/String.__concat (; 27 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__concat (; 26 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 i32.eqz if @@ -2797,13 +2774,13 @@ get_local $1 call $~lib/string/String#concat ) - (func $~lib/string/String.__ne (; 28 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__ne (; 27 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $0 get_local $1 call $~lib/string/String.__eq i32.eqz ) - (func $~lib/string/String.__gt (; 29 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__gt (; 28 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) get_local $0 @@ -2858,7 +2835,7 @@ i32.const 0 i32.gt_s ) - (func $~lib/string/String.__gte (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__gte (; 29 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) get_local $0 @@ -2913,7 +2890,7 @@ i32.const 0 i32.ge_s ) - (func $~lib/string/String.__lt (; 31 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__lt (; 30 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) get_local $0 @@ -2968,7 +2945,7 @@ i32.const 0 i32.lt_s ) - (func $~lib/string/String.__lte (; 32 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/string/String.__lte (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -3016,7 +2993,7 @@ i32.const 0 i32.le_s ) - (func $~lib/string/String#repeat (; 33 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#repeat (; 32 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) get_local $0 @@ -3086,17 +3063,7 @@ call $~lib/internal/string/repeatUnsafe get_local $2 ) - (func $~lib/internal/arraybuffer/computeSize (; 34 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 35 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 33 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -3109,19 +3076,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/memory/memory.allocate (; 36 ;) (type $FUNCSIG$i) (result i32) - i32.const 8 - call $~lib/allocator/arena/__memory_allocate - ) - (func $~lib/internal/memory/memset (; 37 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 34 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) get_local $1 i32.eqz @@ -3340,7 +3309,7 @@ end end ) - (func $~lib/array/Array#constructor (; 38 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/array/Array#constructor (; 35 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -3361,7 +3330,8 @@ tee_local $3 call $~lib/internal/arraybuffer/allocateUnsafe set_local $2 - call $~lib/memory/memory.allocate + i32.const 8 + call $~lib/allocator/arena/__memory_allocate tee_local $1 i32.const 0 i32.store @@ -3381,15 +3351,10 @@ call $~lib/internal/memory/memset get_local $1 ) - (func $~lib/array/Array#__unchecked_set (; 39 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) - get_local $0 - i32.load - get_local $1 - i32.store offset=8 - ) - (func $~lib/internal/arraybuffer/reallocateUnsafe (; 40 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/arraybuffer/reallocateUnsafe (; 36 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) + (local $4 i32) get_local $1 get_local $0 i32.load @@ -3407,11 +3372,15 @@ call $~lib/env/abort unreachable end - get_local $2 - call $~lib/internal/arraybuffer/computeSize - set_local $3 get_local $1 - get_local $3 + i32.const 1 + i32.const 32 + get_local $2 + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl i32.const 8 i32.sub i32.le_s @@ -3434,14 +3403,13 @@ tee_local $3 i32.const 8 i32.add + tee_local $4 get_local $0 i32.const 8 i32.add get_local $2 call $~lib/internal/memory/memmove - get_local $3 - i32.const 8 - i32.add + get_local $4 get_local $2 i32.add get_local $1 @@ -3474,26 +3442,26 @@ end get_local $0 ) - (func $~lib/array/Array#push (; 41 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/array/Array#push (; 37 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) get_local $0 i32.load offset=4 - tee_local $3 + tee_local $2 i32.const 1 i32.add - set_local $4 - get_local $3 + set_local $3 + get_local $2 get_local $0 i32.load - tee_local $2 + tee_local $4 i32.load i32.const 2 i32.shr_u i32.ge_u if - get_local $3 + get_local $2 i32.const 268435454 i32.ge_u if @@ -3504,29 +3472,28 @@ call $~lib/env/abort unreachable end - get_local $2 + get_local $0 get_local $4 + get_local $3 i32.const 2 i32.shl call $~lib/internal/arraybuffer/reallocateUnsafe - set_local $2 - get_local $0 - get_local $2 + tee_local $4 i32.store end get_local $0 - get_local $4 - i32.store offset=4 - get_local $2 get_local $3 + i32.store offset=4 + get_local $4 + get_local $2 i32.const 2 i32.shl i32.add get_local $1 i32.store offset=8 - get_local $4 + get_local $3 ) - (func $~lib/string/String#split (; 42 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/string/String#split (; 38 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -3557,10 +3524,11 @@ if i32.const 1 call $~lib/array/Array#constructor - tee_local $5 + tee_local $4 + i32.load get_local $0 - call $~lib/array/Array#__unchecked_set - get_local $5 + i32.store offset=8 + get_local $4 return end get_local $0 @@ -3593,16 +3561,15 @@ return end get_local $3 - tee_local $5 + tee_local $4 get_local $2 - tee_local $7 get_local $3 get_local $2 i32.lt_s select tee_local $3 call $~lib/array/Array#constructor - tee_local $5 + tee_local $4 i32.load set_local $7 block $break|0 @@ -3639,23 +3606,23 @@ end unreachable end - get_local $5 + get_local $4 return end i32.const 0 call $~lib/array/Array#constructor - set_local $6 + set_local $5 loop $continue|1 get_local $0 get_local $1 - get_local $4 + get_local $6 call $~lib/string/String#indexOf - tee_local $10 + tee_local $9 i32.const -1 i32.ne if - get_local $10 - get_local $4 + get_local $9 + get_local $6 i32.sub tee_local $7 i32.const 0 @@ -3663,52 +3630,53 @@ if get_local $7 call $~lib/internal/string/allocateUnsafe - tee_local $5 + tee_local $4 i32.const 0 get_local $0 - get_local $4 + get_local $6 get_local $7 call $~lib/internal/string/copyUnsafe - get_local $6 get_local $5 + get_local $4 call $~lib/array/Array#push drop else - get_local $6 + get_local $5 i32.const 256 call $~lib/array/Array#push drop end - get_local $9 + get_local $10 i32.const 1 i32.add - tee_local $9 + tee_local $10 get_local $2 i32.eq if - get_local $6 + get_local $5 return end - get_local $10 + get_local $9 get_local $8 i32.add - set_local $4 + set_local $6 br $continue|1 end end - get_local $4 + get_local $6 i32.eqz if i32.const 1 call $~lib/array/Array#constructor tee_local $2 + i32.load get_local $0 - call $~lib/array/Array#__unchecked_set + i32.store offset=8 get_local $2 return end get_local $3 - get_local $4 + get_local $6 i32.sub tee_local $1 i32.const 0 @@ -3719,22 +3687,22 @@ tee_local $2 i32.const 0 get_local $0 - get_local $4 + get_local $6 get_local $1 call $~lib/internal/string/copyUnsafe - get_local $6 + get_local $5 get_local $2 call $~lib/array/Array#push drop else - get_local $6 + get_local $5 i32.const 256 call $~lib/array/Array#push drop end - get_local $6 + get_local $5 ) - (func $~lib/string/String#split|trampoline (; 43 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#split|trampoline (; 39 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) block $2of2 block $1of2 @@ -3756,28 +3724,7 @@ get_local $2 call $~lib/string/String#split ) - (func $~lib/array/Array#__get (; 44 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.const 2 - i32.shr_u - i32.lt_u - if (result i32) - get_local $0 - get_local $1 - i32.const 2 - i32.shl - i32.add - i32.load offset=8 - else - unreachable - end - tee_local $0 - ) - (func $~lib/internal/number/decimalCount32 (; 45 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/number/decimalCount32 (; 40 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 100000 i32.lt_u @@ -3831,7 +3778,7 @@ end end ) - (func $~lib/internal/number/utoa32_lut (; 46 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/number/utoa32_lut (; 41 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) i32.const 1520 @@ -3941,7 +3888,7 @@ i32.store16 offset=4 end ) - (func $~lib/internal/number/itoa32 (; 47 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/number/itoa32 (; 42 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -3954,7 +3901,7 @@ get_local $0 i32.const 0 i32.lt_s - tee_local $2 + tee_local $1 if i32.const 0 get_local $0 @@ -3963,24 +3910,23 @@ end get_local $0 call $~lib/internal/number/decimalCount32 - tee_local $1 - get_local $2 + get_local $1 i32.add tee_local $3 call $~lib/internal/string/allocateUnsafe - tee_local $1 + tee_local $2 get_local $0 get_local $3 call $~lib/internal/number/utoa32_lut - get_local $2 + get_local $1 if - get_local $1 + get_local $2 i32.const 45 i32.store16 offset=4 end - get_local $1 + get_local $2 ) - (func $~lib/internal/number/utoa32 (; 48 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/number/utoa32 (; 43 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -3999,7 +3945,7 @@ call $~lib/internal/number/utoa32_lut get_local $2 ) - (func $~lib/internal/number/decimalCount64 (; 49 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/number/decimalCount64 (; 44 ;) (type $Ii) (param $0 i64) (result i32) get_local $0 i64.const 1000000000000000 i64.lt_u @@ -4053,7 +3999,7 @@ end end ) - (func $~lib/internal/number/utoa64_lut (; 50 ;) (type $iIiv) (param $0 i32) (param $1 i64) (param $2 i32) + (func $~lib/internal/number/utoa64_lut (; 45 ;) (type $iIiv) (param $0 i32) (param $1 i64) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) @@ -4150,7 +4096,7 @@ get_local $2 call $~lib/internal/number/utoa32_lut ) - (func $~lib/internal/number/utoa64 (; 51 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/number/utoa64 (; 46 ;) (type $Ii) (param $0 i64) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -4186,7 +4132,7 @@ end get_local $2 ) - (func $~lib/internal/number/itoa64 (; 52 ;) (type $Ii) (param $0 i64) (result i32) + (func $~lib/internal/number/itoa64 (; 47 ;) (type $Ii) (param $0 i64) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -4200,7 +4146,7 @@ get_local $0 i64.const 0 i64.lt_s - tee_local $2 + tee_local $1 if i64.const 0 get_local $0 @@ -4215,49 +4161,35 @@ i32.wrap/i64 tee_local $4 call $~lib/internal/number/decimalCount32 - tee_local $1 - get_local $2 + get_local $1 i32.add - tee_local $3 + tee_local $2 call $~lib/internal/string/allocateUnsafe - tee_local $1 + tee_local $3 get_local $4 - get_local $3 + get_local $2 call $~lib/internal/number/utoa32_lut else get_local $0 call $~lib/internal/number/decimalCount64 - tee_local $1 - get_local $2 + get_local $1 i32.add - tee_local $3 + tee_local $2 call $~lib/internal/string/allocateUnsafe - tee_local $1 + tee_local $3 get_local $0 - get_local $3 + get_local $2 call $~lib/internal/number/utoa64_lut end - get_local $2 + get_local $1 if - get_local $1 + get_local $3 i32.const 45 i32.store16 offset=4 end - get_local $1 + get_local $3 ) - (func $~lib/builtins/isFinite (; 53 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.sub - f64.const 0 - f64.eq - ) - (func $~lib/builtins/isNaN (; 54 ;) (type $Fi) (param $0 f64) (result i32) - get_local $0 - get_local $0 - f64.ne - ) - (func $~lib/internal/number/genDigits (; 55 ;) (type $iIiIiIii) (param $0 i32) (param $1 i64) (param $2 i32) (param $3 i64) (param $4 i32) (param $5 i64) (param $6 i32) (result i32) + (func $~lib/internal/number/genDigits (; 48 ;) (type $iIiIiIii) (param $0 i32) (param $1 i64) (param $2 i32) (param $3 i64) (param $4 i32) (param $5 i64) (param $6 i32) (result i32) (local $7 i32) (local $8 i64) (local $9 i32) @@ -4670,7 +4602,7 @@ end end ) - (func $~lib/internal/number/prettify (; 56 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/number/prettify (; 49 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $2 @@ -4692,73 +4624,73 @@ get_local $1 get_local $2 i32.add - tee_local $3 - i32.le_s tee_local $4 + i32.le_s + tee_local $3 if - get_local $3 + get_local $4 i32.const 21 i32.le_s - set_local $4 + set_local $3 end - get_local $4 + get_local $3 if (result i32) block $break|0 get_local $1 - set_local $4 + set_local $3 loop $repeat|0 - get_local $4 get_local $3 + get_local $4 i32.ge_s br_if $break|0 get_local $0 - get_local $4 + get_local $3 i32.const 1 i32.shl i32.add i32.const 48 i32.store16 offset=4 - get_local $4 + get_local $3 i32.const 1 i32.add - set_local $4 + set_local $3 br $repeat|0 unreachable end unreachable end get_local $0 - get_local $3 + get_local $4 i32.const 1 i32.shl i32.add i32.const 3145774 i32.store offset=4 - get_local $3 + get_local $4 i32.const 2 i32.add else - get_local $3 + get_local $4 i32.const 0 i32.gt_s - tee_local $4 + tee_local $3 if - get_local $3 + get_local $4 i32.const 21 i32.le_s - set_local $4 + set_local $3 end - get_local $4 + get_local $3 if (result i32) get_local $0 - get_local $3 + get_local $4 i32.const 1 i32.shl i32.add - tee_local $4 + tee_local $3 i32.const 6 i32.add - get_local $4 + get_local $3 i32.const 4 i32.add i32.const 0 @@ -4768,7 +4700,7 @@ i32.shl call $~lib/internal/memory/memmove get_local $0 - get_local $3 + get_local $4 i32.const 1 i32.shl i32.add @@ -4779,24 +4711,24 @@ i32.add else i32.const -6 - get_local $3 + get_local $4 i32.lt_s - tee_local $4 + tee_local $3 if - get_local $3 + get_local $4 i32.const 0 i32.le_s - set_local $4 + set_local $3 end - get_local $4 + get_local $3 if (result i32) get_local $0 i32.const 4 i32.add i32.const 2 - get_local $3 + get_local $4 i32.sub - tee_local $4 + tee_local $3 i32.const 1 i32.shl i32.add @@ -4812,30 +4744,30 @@ i32.store offset=4 block $break|1 i32.const 2 - set_local $3 + set_local $2 loop $repeat|1 + get_local $2 get_local $3 - get_local $4 i32.ge_s br_if $break|1 get_local $0 - get_local $3 + get_local $2 i32.const 1 i32.shl i32.add i32.const 48 i32.store16 offset=4 - get_local $3 + get_local $2 i32.const 1 i32.add - set_local $3 + set_local $2 br $repeat|1 unreachable end unreachable end get_local $1 - get_local $4 + get_local $3 i32.add else get_local $1 @@ -4848,30 +4780,29 @@ get_local $0 i32.const 4 i32.add - set_local $4 - get_local $3 + set_local $3 + get_local $4 i32.const 1 i32.sub - tee_local $3 + tee_local $2 i32.const 0 i32.lt_s tee_local $0 if i32.const 0 - get_local $3 + get_local $2 i32.sub - set_local $3 + set_local $2 end get_local $3 + get_local $2 + get_local $2 call $~lib/internal/number/decimalCount32 i32.const 1 i32.add - set_local $2 - get_local $4 - get_local $3 - get_local $2 + tee_local $2 call $~lib/internal/number/utoa32_lut - get_local $4 + get_local $3 i32.const 45 i32.const 43 get_local $0 @@ -4906,30 +4837,29 @@ get_local $0 i32.const 4 i32.add - set_local $4 - get_local $3 + set_local $3 + get_local $4 i32.const 1 i32.sub - tee_local $3 + tee_local $2 i32.const 0 i32.lt_s tee_local $0 if i32.const 0 - get_local $3 + get_local $2 i32.sub - set_local $3 + set_local $2 end get_local $3 + get_local $2 + get_local $2 call $~lib/internal/number/decimalCount32 i32.const 1 i32.add - set_local $2 - get_local $4 - get_local $3 - get_local $2 + tee_local $2 call $~lib/internal/number/utoa32_lut - get_local $4 + get_local $3 i32.const 45 i32.const 43 get_local $0 @@ -4945,10 +4875,10 @@ end end ) - (func $~lib/internal/number/dtoa_core (; 57 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) + (func $~lib/internal/number/dtoa_core (; 50 ;) (type $iFi) (param $0 i32) (param $1 f64) (result i32) (local $2 i64) - (local $3 i32) - (local $4 i64) + (local $3 i64) + (local $4 i32) (local $5 i32) (local $6 i64) (local $7 i64) @@ -4956,15 +4886,14 @@ (local $9 i64) (local $10 i64) (local $11 i64) - (local $12 i64) - (local $13 i64) + (local $12 i32) + (local $13 i32) (local $14 i32) - (local $15 i32) - (local $16 i32) + (local $15 i64) get_local $1 f64.const 0 f64.lt - tee_local $14 + tee_local $12 if get_local $1 f64.neg @@ -4981,10 +4910,10 @@ i64.const 52 i64.shr_u i32.wrap/i64 - tee_local $15 + tee_local $13 i32.const 0 i32.ne - tee_local $3 + tee_local $5 i64.extend_u/i32 i64.const 52 i64.shl @@ -4993,27 +4922,27 @@ i64.and i64.add set_local $2 - get_local $15 + get_local $13 i32.const 1 - get_local $3 + get_local $5 select i32.const 1075 i32.sub - tee_local $15 + tee_local $13 i32.const 1 i32.sub - set_local $3 + set_local $5 get_local $2 i64.const 1 i64.shl i64.const 1 i64.add - tee_local $4 + tee_local $6 i64.clz i32.wrap/i64 - set_local $16 + set_local $4 + get_local $6 get_local $4 - get_local $16 i64.extend_s/i32 i64.shl set_global $~lib/internal/number/_frc_plus @@ -5023,23 +4952,23 @@ i64.eq i32.const 1 i32.add - tee_local $5 + tee_local $14 i64.extend_s/i32 i64.shl i64.const 1 i64.sub - get_local $15 + get_local $13 + get_local $14 + i32.sub get_local $5 + get_local $4 i32.sub - get_local $3 - get_local $16 - i32.sub - tee_local $3 + tee_local $5 i32.sub i64.extend_s/i32 i64.shl set_global $~lib/internal/number/_frc_minus - get_local $3 + get_local $5 set_global $~lib/internal/number/_exp i32.const 348 i32.const -61 @@ -5052,8 +4981,8 @@ f64.add tee_local $1 i32.trunc_s/f64 - tee_local $16 - get_local $16 + tee_local $4 + get_local $4 f64.convert_s/i32 get_local $1 f64.ne @@ -5062,24 +4991,24 @@ i32.shr_s i32.const 1 i32.add - tee_local $3 + tee_local $5 i32.const 3 i32.shl i32.sub set_global $~lib/internal/number/_K i32.const 4256 i32.load - set_local $5 + set_local $4 i32.const 3992 i32.load - get_local $3 + get_local $5 i32.const 3 i32.shl i32.add i64.load offset=8 set_global $~lib/internal/number/_frc_pow + get_local $4 get_local $5 - get_local $3 i32.const 1 i32.shl i32.add @@ -5089,7 +5018,7 @@ get_local $2 i64.clz i32.wrap/i64 - tee_local $5 + tee_local $4 i64.extend_s/i32 i64.shl tee_local $2 @@ -5097,14 +5026,14 @@ i64.and tee_local $7 get_global $~lib/internal/number/_frc_pow - tee_local $4 + tee_local $6 i64.const 4294967295 i64.and tee_local $8 i64.mul set_local $9 get_local $7 - get_local $4 + get_local $6 i64.const 32 i64.shr_u tee_local $10 @@ -5119,7 +5048,7 @@ i64.const 32 i64.shr_u i64.add - tee_local $6 + tee_local $3 i64.const 4294967295 i64.and i64.add @@ -5127,7 +5056,7 @@ get_local $11 get_local $10 i64.mul - get_local $6 + get_local $3 i64.const 32 i64.shr_u i64.add @@ -5139,23 +5068,23 @@ i64.add set_local $2 get_global $~lib/internal/number/_frc_plus - tee_local $6 + tee_local $3 i64.const 4294967295 i64.and tee_local $9 - get_local $4 + get_local $6 i64.const 4294967295 i64.and tee_local $10 i64.mul set_local $7 get_local $9 - get_local $4 + get_local $6 i64.const 32 i64.shr_u tee_local $8 i64.mul - get_local $6 + get_local $3 i64.const 32 i64.shr_u tee_local $11 @@ -5165,43 +5094,43 @@ i64.const 32 i64.shr_u i64.add - tee_local $12 + tee_local $3 i64.const 4294967295 i64.and i64.add - set_local $13 + set_local $7 get_local $11 get_local $8 i64.mul - get_local $12 + get_local $3 i64.const 32 i64.shr_u i64.add - get_local $13 + get_local $7 i64.const 2147483647 i64.add i64.const 32 i64.shr_u i64.add - set_local $13 + set_local $15 get_global $~lib/internal/number/_frc_minus - tee_local $12 + tee_local $3 i64.const 4294967295 i64.and tee_local $7 - get_local $4 + get_local $6 i64.const 4294967295 i64.and tee_local $8 i64.mul set_local $9 get_local $7 - get_local $4 + get_local $6 i64.const 32 i64.shr_u tee_local $10 i64.mul - get_local $12 + get_local $3 i64.const 32 i64.shr_u tee_local $11 @@ -5211,23 +5140,23 @@ i64.const 32 i64.shr_u i64.add - tee_local $6 + tee_local $3 i64.const 4294967295 i64.and i64.add - set_local $12 - get_local $13 + set_local $6 + get_local $15 i64.const 1 i64.sub - tee_local $13 + tee_local $7 get_local $11 get_local $10 i64.mul - get_local $6 + get_local $3 i64.const 32 i64.shr_u i64.add - get_local $12 + get_local $6 i64.const 2147483647 i64.add i64.const 32 @@ -5236,43 +5165,40 @@ i64.const 1 i64.add i64.sub - set_local $6 - get_local $0 - get_local $2 - get_local $15 - get_local $5 - i32.sub - get_global $~lib/internal/number/_exp_pow - tee_local $5 - i32.add - i32.const -64 - i32.sub - tee_local $3 - get_local $13 - get_global $~lib/internal/number/_exp - get_local $5 - i32.add - i32.const -64 - i32.sub - get_local $6 - get_local $14 - call $~lib/internal/number/genDigits set_local $3 get_local $0 - get_local $14 + get_local $12 i32.const 1 i32.shl i32.add + get_local $0 + get_local $2 + get_local $13 + get_local $4 + i32.sub + get_global $~lib/internal/number/_exp_pow + tee_local $4 + i32.add + i32.const -64 + i32.sub + tee_local $5 + get_local $7 + get_global $~lib/internal/number/_exp + get_local $4 + i32.add + i32.const -64 + i32.sub get_local $3 - get_local $14 + get_local $12 + call $~lib/internal/number/genDigits + get_local $12 i32.sub get_global $~lib/internal/number/_K call $~lib/internal/number/prettify - tee_local $3 - get_local $14 + get_local $12 i32.add ) - (func $~lib/string/String#substring (; 58 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String#substring (; 51 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -5354,10 +5280,7 @@ call $~lib/internal/string/copyUnsafe get_local $2 ) - (func $~lib/allocator/arena/__memory_free (; 59 ;) (type $FUNCSIG$v) - nop - ) - (func $~lib/internal/number/dtoa (; 60 ;) (type $Fi) (param $0 f64) (result i32) + (func $~lib/internal/number/dtoa (; 52 ;) (type $Fi) (param $0 f64) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -5368,11 +5291,14 @@ return end get_local $0 - call $~lib/builtins/isFinite - i32.eqz + get_local $0 + f64.sub + f64.const 0 + f64.ne if get_local $0 - call $~lib/builtins/isNaN + get_local $0 + f64.ne if i32.const 2904 return @@ -5387,15 +5313,15 @@ end i32.const 28 call $~lib/internal/string/allocateUnsafe - tee_local $1 + tee_local $2 get_local $0 call $~lib/internal/number/dtoa_core - set_local $2 - get_local $1 + set_local $1 get_local $2 - call $~lib/string/String#substring - set_local $2 get_local $1 + call $~lib/string/String#substring + set_local $1 + get_local $2 i32.eqz if i32.const 0 @@ -5405,10 +5331,9 @@ call $~lib/env/abort unreachable end - call $~lib/allocator/arena/__memory_free - get_local $2 + get_local $1 ) - (func $start (; 61 ;) (type $v) + (func $start (; 53 ;) (type $v) (local $0 i32) (local $1 i32) i32.const 5880 @@ -5540,7 +5465,24 @@ i32.const 1 set_global $~argc get_global $std/string/str - call $~lib/string/String#endsWith|trampoline + set_local $1 + block $1of1 + block $0of1 + block $outOfRange + get_global $~argc + i32.const 1 + i32.sub + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 536870910 + set_local $0 + end + get_local $1 + i32.const 216 + get_local $0 + call $~lib/string/String#endsWith i32.eqz if i32.const 0 @@ -6509,12 +6451,8 @@ set_global $std/string/a i32.const 55296 call $~lib/string/String.fromCodePoint - set_local $0 i32.const 56322 call $~lib/string/String.fromCodePoint - set_local $1 - get_local $0 - get_local $1 call $~lib/string/String.__concat set_global $std/string/b get_global $std/string/a @@ -6679,9 +6617,21 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 256 call $~lib/string/String.__eq set_local $0 @@ -6724,9 +6674,21 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 256 call $~lib/string/String.__eq set_local $0 @@ -6753,9 +6715,21 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 896 call $~lib/string/String.__eq set_local $0 @@ -6782,27 +6756,67 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 @@ -6829,27 +6843,67 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 @@ -6876,36 +6930,90 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 256 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 3 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 12 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 @@ -6932,36 +7040,90 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 256 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 3 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 12 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 @@ -6988,36 +7150,90 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 3 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 12 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 256 call $~lib/string/String.__eq set_local $0 @@ -7044,27 +7260,67 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 @@ -7105,9 +7361,21 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 @@ -7133,9 +7401,21 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 @@ -7161,27 +7441,67 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 @@ -7207,27 +7527,67 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 @@ -7253,27 +7613,67 @@ i32.eq tee_local $0 if - get_global $std/string/sa i32.const 0 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 280 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 1 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 4 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 648 call $~lib/string/String.__eq set_local $0 end get_local $0 if - get_global $std/string/sa i32.const 2 - call $~lib/array/Array#__get + get_global $std/string/sa + i32.load + tee_local $0 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $0 + i32.const 8 + i32.add + i32.load offset=8 + else + unreachable + end + tee_local $0 i32.const 920 call $~lib/string/String.__eq set_local $0 @@ -8550,7 +8950,7 @@ unreachable end ) - (func $null (; 62 ;) (type $v) + (func $null (; 54 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/symbol.optimized.wat b/tests/compiler/std/symbol.optimized.wat index 0aede3b3..866633bf 100644 --- a/tests/compiler/std/symbol.optimized.wat +++ b/tests/compiler/std/symbol.optimized.wat @@ -7,9 +7,9 @@ (type $iii (func (param i32 i32) (result i32))) (type $iiv (func (param i32 i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$vii (func (param i32 i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) + (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) @@ -35,21 +35,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/symbol/Symbol (; 1 ;) (type $FUNCSIG$i) (result i32) - (local $0 i32) - get_global $~lib/symbol/nextId - tee_local $0 - i32.const 1 - i32.add - set_global $~lib/symbol/nextId - get_local $0 - i32.eqz - if - unreachable - end - get_local $0 - ) - (func $~lib/allocator/arena/__memory_allocate (; 2 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/__memory_allocate (; 1 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -111,21 +97,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/memory/memory.allocate (; 3 ;) (type $FUNCSIG$i) (result i32) - i32.const 24 - call $~lib/allocator/arena/__memory_allocate - ) - (func $~lib/internal/arraybuffer/computeSize (; 4 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 5 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -138,15 +110,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/internal/memory/memset (; 6 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $FUNCSIG$vii) (param $0 i32) (param $1 i32) (local $2 i32) get_local $1 i32.eqz @@ -365,7 +343,7 @@ end end ) - (func $~lib/arraybuffer/ArrayBuffer#constructor (; 7 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/arraybuffer/ArrayBuffer#constructor (; 4 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 i32.const 1073741816 @@ -394,24 +372,19 @@ end get_local $2 ) - (func $~lib/map/Map#clear (; 8 ;) (type $iv) (param $0 i32) - (local $1 i32) + (func $~lib/map/Map#clear (; 5 ;) (type $iv) (param $0 i32) + get_local $0 i32.const 16 i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store get_local $0 i32.const 3 i32.store offset=4 + get_local $0 i32.const 48 i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $1 - get_local $0 - get_local $1 i32.store offset=8 get_local $0 i32.const 4 @@ -423,9 +396,10 @@ i32.const 0 i32.store offset=20 ) - (func $~lib/map/Map#constructor (; 9 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/map/Map#constructor (; 6 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) - call $~lib/memory/memory.allocate + i32.const 24 + call $~lib/allocator/arena/__memory_allocate tee_local $0 i32.const 0 i32.store @@ -448,7 +422,7 @@ call $~lib/map/Map#clear get_local $0 ) - (func $~lib/internal/hash/hashStr (; 10 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/hash/hashStr (; 7 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -485,7 +459,7 @@ end get_local $2 ) - (func $~lib/internal/string/compareUnsafe (; 11 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/string/compareUnsafe (; 8 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) (local $4 i32) get_local $0 @@ -522,7 +496,7 @@ end get_local $4 ) - (func $~lib/string/String.__eq (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/string/String.__eq (; 9 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) get_local $0 get_local $1 @@ -561,7 +535,7 @@ call $~lib/internal/string/compareUnsafe i32.eqz ) - (func $~lib/map/Map#find (; 13 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 10 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -604,37 +578,7 @@ end i32.const 0 ) - (func $~lib/map/Map#has (; 14 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hashStr - set_local $2 - get_local $0 - get_local $1 - get_local $2 - call $~lib/map/Map#find - i32.const 0 - i32.ne - ) - (func $~lib/map/Map#get (; 15 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hashStr - set_local $2 - get_local $0 - get_local $1 - get_local $2 - call $~lib/map/Map#find - tee_local $0 - if (result i32) - get_local $0 - i32.load offset=4 - else - unreachable - end - tee_local $0 - ) - (func $~lib/map/Map#rehash (; 16 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 11 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -650,109 +594,106 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 12 i32.mul i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 12 i32.mul i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 - get_local $8 + get_local $2 + get_local $7 i32.ne if - get_local $3 + get_local $2 i32.load offset=8 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 i32.load i32.store - get_local $2 get_local $3 + get_local $2 i32.load offset=4 i32.store offset=4 get_local $3 + get_local $4 + get_local $2 i32.load call $~lib/internal/hash/hashStr - set_local $4 - get_local $2 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=8 - get_local $4 - get_local $2 + get_local $8 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 12 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 12 i32.add - set_local $3 + set_local $2 br $continue|0 end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 17 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map#set (; 12 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - get_local $1 - call $~lib/internal/hash/hashStr - set_local $5 get_local $0 get_local $1 - get_local $5 + get_local $1 + call $~lib/internal/hash/hashStr + tee_local $5 call $~lib/map/Map#find tee_local $3 if @@ -837,7 +778,7 @@ i32.store offset=8 end ) - (func $~lib/internal/hash/hash32 (; 18 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/hash/hash32 (; 13 ;) (type $ii) (param $0 i32) (result i32) get_local $0 i32.const 255 i32.and @@ -868,7 +809,7 @@ i32.const 16777619 i32.mul ) - (func $~lib/map/Map#find (; 19 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/map/Map#find (; 14 ;) (type $iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) get_local $0 i32.load get_local $2 @@ -911,7 +852,7 @@ end i32.const 0 ) - (func $~lib/map/Map#rehash (; 20 ;) (type $iiv) (param $0 i32) (param $1 i32) + (func $~lib/map/Map#rehash (; 15 ;) (type $iiv) (param $0 i32) (param $1 i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -927,109 +868,106 @@ i32.shl i32.const 0 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $5 + set_local $4 get_local $2 f64.convert_s/i32 f64.const 2.6666666666666665 f64.mul i32.trunc_s/f64 - tee_local $7 + tee_local $6 i32.const 12 i32.mul i32.const 1 call $~lib/arraybuffer/ArrayBuffer#constructor - set_local $6 + set_local $5 get_local $0 i32.load offset=8 i32.const 8 i32.add - tee_local $3 + tee_local $2 get_local $0 i32.load offset=16 i32.const 12 i32.mul i32.add - set_local $8 - get_local $6 + set_local $7 + get_local $5 i32.const 8 i32.add - set_local $2 + set_local $3 loop $continue|0 - get_local $3 - get_local $8 + get_local $2 + get_local $7 i32.ne if - get_local $3 + get_local $2 i32.load offset=8 i32.const 1 i32.and i32.eqz if - get_local $2 get_local $3 + get_local $2 i32.load i32.store - get_local $2 get_local $3 + get_local $2 i32.load offset=4 i32.store offset=4 get_local $3 + get_local $4 + get_local $2 i32.load call $~lib/internal/hash/hash32 - set_local $4 - get_local $2 - get_local $5 - get_local $4 get_local $1 i32.and i32.const 2 i32.shl i32.add - tee_local $4 + tee_local $8 i32.load offset=8 i32.store offset=8 - get_local $4 - get_local $2 + get_local $8 + get_local $3 i32.store offset=8 - get_local $2 + get_local $3 i32.const 12 i32.add - set_local $2 + set_local $3 end - get_local $3 + get_local $2 i32.const 12 i32.add - set_local $3 + set_local $2 br $continue|0 end end get_local $0 - get_local $5 + get_local $4 i32.store get_local $0 get_local $1 i32.store offset=4 get_local $0 - get_local $6 + get_local $5 i32.store offset=8 get_local $0 - get_local $7 + get_local $6 i32.store offset=12 get_local $0 get_local $0 i32.load offset=20 i32.store offset=16 ) - (func $~lib/map/Map#set (; 21 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/map/Map#set (; 16 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i32) (local $5 i32) - get_local $1 - call $~lib/internal/hash/hash32 - set_local $5 get_local $0 get_local $1 - get_local $5 + get_local $1 + call $~lib/internal/hash/hash32 + tee_local $5 call $~lib/map/Map#find tee_local $3 if @@ -1114,17 +1052,29 @@ i32.store offset=8 end ) - (func $~lib/symbol/Symbol.for (; 22 ;) (type $FUNCSIG$i) (result i32) + (func $~lib/symbol/Symbol.for (; 17 ;) (type $FUNCSIG$i) (result i32) (local $0 i32) get_global $~lib/symbol/stringToId if get_global $~lib/symbol/stringToId i32.const 8 - call $~lib/map/Map#has + i32.const 8 + call $~lib/internal/hash/hashStr + call $~lib/map/Map#find if get_global $~lib/symbol/stringToId i32.const 8 - call $~lib/map/Map#get + i32.const 8 + call $~lib/internal/hash/hashStr + call $~lib/map/Map#find + tee_local $0 + if (result i32) + get_local $0 + i32.load offset=4 + else + unreachable + end + tee_local $0 return end else @@ -1153,37 +1103,7 @@ call $~lib/map/Map#set get_local $0 ) - (func $~lib/map/Map#has (; 23 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash32 - set_local $2 - get_local $0 - get_local $1 - get_local $2 - call $~lib/map/Map#find - i32.const 0 - i32.ne - ) - (func $~lib/map/Map#get (; 24 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - (local $2 i32) - get_local $1 - call $~lib/internal/hash/hash32 - set_local $2 - get_local $0 - get_local $1 - get_local $2 - call $~lib/map/Map#find - tee_local $0 - if (result i32) - get_local $0 - i32.load offset=4 - else - unreachable - end - tee_local $0 - ) - (func $~lib/symbol/Symbol.keyFor (; 25 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/symbol/Symbol.keyFor (; 18 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_global $~lib/symbol/idToString i32.const 0 @@ -1192,27 +1112,61 @@ if get_global $~lib/symbol/idToString get_local $0 - call $~lib/map/Map#has + get_local $0 + call $~lib/internal/hash/hash32 + call $~lib/map/Map#find + i32.const 0 + i32.ne set_local $1 end get_local $1 if (result i32) get_global $~lib/symbol/idToString get_local $0 - call $~lib/map/Map#get + get_local $0 + call $~lib/internal/hash/hash32 + call $~lib/map/Map#find + tee_local $0 + if (result i32) + get_local $0 + i32.load offset=4 + else + unreachable + end else i32.const 0 end tee_local $0 ) - (func $start (; 26 ;) (type $v) + (func $start (; 19 ;) (type $v) + (local $0 i32) i32.const 168 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset set_global $~lib/allocator/arena/offset - call $~lib/symbol/Symbol + get_global $~lib/symbol/nextId + tee_local $0 + i32.const 1 + i32.add + set_global $~lib/symbol/nextId + get_local $0 + i32.eqz + if + unreachable + end + get_local $0 set_global $std/symbol/sym1 - call $~lib/symbol/Symbol + get_global $~lib/symbol/nextId + tee_local $0 + i32.const 1 + i32.add + set_global $~lib/symbol/nextId + get_local $0 + i32.eqz + if + unreachable + end + get_local $0 set_global $std/symbol/sym2 get_global $std/symbol/sym1 get_global $std/symbol/sym2 @@ -1295,7 +1249,7 @@ unreachable end ) - (func $null (; 27 ;) (type $v) + (func $null (; 20 ;) (type $v) nop ) ) diff --git a/tests/compiler/std/typedarray.optimized.wat b/tests/compiler/std/typedarray.optimized.wat index 2fae4f8d..3ed11aba 100644 --- a/tests/compiler/std/typedarray.optimized.wat +++ b/tests/compiler/std/typedarray.optimized.wat @@ -9,10 +9,8 @@ (type $iiF (func (param i32 i32) (result f64))) (type $iiiii (func (param i32 i32 i32 i32) (result i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$ii (func (param i32) (result i32))) (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - (type $FUNCSIG$v (func)) (type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) @@ -63,17 +61,7 @@ (export "memory" (memory $0)) (export "table" (table $0)) (start $start) - (func $~lib/internal/arraybuffer/computeSize (; 1 ;) (type $ii) (param $0 i32) (result i32) - i32.const 1 - i32.const 32 - get_local $0 - i32.const 7 - i32.add - i32.clz - i32.sub - i32.shl - ) - (func $~lib/allocator/arena/__memory_allocate (; 2 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/allocator/arena/__memory_allocate (; 1 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -135,7 +123,7 @@ set_global $~lib/allocator/arena/offset get_local $1 ) - (func $~lib/internal/arraybuffer/allocateUnsafe (; 3 ;) (type $ii) (param $0 i32) (result i32) + (func $~lib/internal/arraybuffer/allocateUnsafe (; 2 ;) (type $ii) (param $0 i32) (result i32) (local $1 i32) get_local $0 i32.const 1073741816 @@ -148,15 +136,21 @@ call $~lib/env/abort unreachable end + i32.const 1 + i32.const 32 get_local $0 - call $~lib/internal/arraybuffer/computeSize + i32.const 7 + i32.add + i32.clz + i32.sub + i32.shl call $~lib/allocator/arena/__memory_allocate tee_local $1 get_local $0 i32.store get_local $1 ) - (func $~lib/internal/memory/memset (; 4 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/memory/memset (; 3 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) (local $4 i64) get_local $2 @@ -391,11 +385,7 @@ end end ) - (func $~lib/memory/memory.allocate (; 5 ;) (type $FUNCSIG$i) (result i32) - i32.const 12 - call $~lib/allocator/arena/__memory_allocate - ) - (func $~lib/internal/typedarray/TypedArray#constructor (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#constructor (; 4 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -417,7 +407,8 @@ i32.const 0 get_local $0 call $~lib/internal/memory/memset - call $~lib/memory/memory.allocate + i32.const 12 + call $~lib/allocator/arena/__memory_allocate tee_local $1 i32.const 0 i32.store @@ -438,7 +429,7 @@ i32.store offset=8 get_local $1 ) - (func $~lib/internal/typedarray/TypedArray#constructor (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#constructor (; 5 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -463,7 +454,8 @@ i32.const 0 get_local $0 call $~lib/internal/memory/memset - call $~lib/memory/memory.allocate + i32.const 12 + call $~lib/allocator/arena/__memory_allocate tee_local $1 i32.const 0 i32.store @@ -484,7 +476,7 @@ i32.store offset=8 get_local $1 ) - (func $~lib/internal/typedarray/TypedArray#constructor (; 8 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#constructor (; 6 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -509,7 +501,8 @@ i32.const 0 get_local $0 call $~lib/internal/memory/memset - call $~lib/memory/memory.allocate + i32.const 12 + call $~lib/allocator/arena/__memory_allocate tee_local $1 i32.const 0 i32.store @@ -530,7 +523,7 @@ i32.store offset=8 get_local $1 ) - (func $~lib/internal/typedarray/TypedArray#constructor (; 9 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#constructor (; 7 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) get_local $0 @@ -555,7 +548,8 @@ i32.const 0 get_local $0 call $~lib/internal/memory/memset - call $~lib/memory/memory.allocate + i32.const 12 + call $~lib/allocator/arena/__memory_allocate tee_local $1 i32.const 0 i32.store @@ -576,7 +570,7 @@ i32.store offset=8 get_local $1 ) - (func $std/typedarray/testInstantiate (; 10 ;) (type $iv) (param $0 i32) + (func $std/typedarray/testInstantiate (; 8 ;) (type $iv) (param $0 i32) (local $1 i32) get_local $0 call $~lib/internal/typedarray/TypedArray#constructor @@ -1007,7 +1001,7 @@ unreachable end ) - (func $~lib/internal/typedarray/TypedArray#__set (; 11 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/typedarray/TypedArray#__set (; 9 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) get_local $1 get_local $0 i32.load offset=8 @@ -1034,7 +1028,7 @@ get_local $2 i32.store offset=8 ) - (func $~lib/internal/typedarray/TypedArray#__get (; 12 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#__get (; 10 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $1 get_local $0 i32.load offset=8 @@ -1060,7 +1054,7 @@ i32.add i32.load offset=8 ) - (func $~lib/typedarray/Int32Array#subarray (; 13 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/typedarray/Int32Array#subarray (; 11 ;) (type $FUNCSIG$iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) i32.const 1 @@ -1122,7 +1116,7 @@ i32.store offset=8 get_local $2 ) - (func $~lib/internal/typedarray/TypedArray#__set (; 14 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64) + (func $~lib/internal/typedarray/TypedArray#__set (; 12 ;) (type $iiFv) (param $0 i32) (param $1 i32) (param $2 f64) get_local $1 get_local $0 i32.load offset=8 @@ -1149,7 +1143,7 @@ get_local $2 f64.store offset=8 ) - (func $~lib/typedarray/Float64Array#subarray (; 15 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Float64Array#subarray (; 13 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -1197,7 +1191,7 @@ i32.store offset=8 get_local $1 ) - (func $~lib/internal/array/insertionSort (; 16 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) + (func $~lib/internal/array/insertionSort (; 14 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (local $4 i32) (local $5 i32) (local $6 f64) @@ -1287,16 +1281,14 @@ unreachable end ) - (func $~lib/allocator/arena/__memory_free (; 17 ;) (type $FUNCSIG$v) - nop - ) - (func $~lib/internal/array/weakHeapSort (; 18 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) + (func $~lib/internal/array/weakHeapSort (; 15 ;) (type $iiiiv) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (local $4 i32) (local $5 i32) (local $6 i32) (local $7 f64) - (local $8 i32) - (local $9 f64) + (local $8 f64) + (local $9 i32) + (local $10 i32) get_local $2 i32.const 31 i32.add @@ -1304,37 +1296,37 @@ i32.shr_s i32.const 2 i32.shl - tee_local $6 + tee_local $4 call $~lib/allocator/arena/__memory_allocate - tee_local $8 + tee_local $9 i32.const 0 - get_local $6 + get_local $4 call $~lib/internal/memory/memset block $break|0 get_local $2 i32.const 1 i32.sub - set_local $4 + set_local $5 loop $repeat|0 - get_local $4 + get_local $5 i32.const 0 i32.le_s br_if $break|0 - get_local $4 - set_local $6 + get_local $5 + set_local $4 loop $continue|1 - get_local $6 + get_local $4 i32.const 1 i32.and - get_local $8 - get_local $6 + get_local $9 + get_local $4 i32.const 6 i32.shr_s i32.const 2 i32.shl i32.add i32.load - get_local $6 + get_local $4 i32.const 1 i32.shr_s i32.const 31 @@ -1344,29 +1336,28 @@ i32.and i32.eq if - get_local $6 + get_local $4 i32.const 1 i32.shr_s - set_local $6 + set_local $4 br $continue|1 end end get_local $0 get_local $1 i32.add - get_local $6 + tee_local $10 + get_local $4 i32.const 1 i32.shr_s - tee_local $5 + tee_local $6 i32.const 3 i32.shl i32.add f64.load offset=8 - set_local $9 - get_local $0 - get_local $1 - i32.add - get_local $4 + set_local $8 + get_local $10 + get_local $5 i32.const 3 i32.shl i32.add @@ -1374,25 +1365,25 @@ set_local $7 i32.const 2 set_global $~argc - get_local $9 + get_local $8 get_local $7 get_local $3 call_indirect (type $FFi) i32.const 0 i32.lt_s if - get_local $8 - get_local $4 + get_local $9 + get_local $5 i32.const 5 i32.shr_s i32.const 2 i32.shl i32.add - tee_local $6 - get_local $6 + tee_local $4 + get_local $4 i32.load i32.const 1 - get_local $4 + get_local $5 i32.const 31 i32.and i32.shl @@ -1401,26 +1392,25 @@ get_local $0 get_local $1 i32.add - get_local $4 + tee_local $4 + get_local $5 i32.const 3 i32.shl i32.add - get_local $9 + get_local $8 f64.store offset=8 - get_local $0 - get_local $1 - i32.add - get_local $5 + get_local $4 + get_local $6 i32.const 3 i32.shl i32.add get_local $7 f64.store offset=8 end - get_local $4 + get_local $5 i32.const 1 i32.sub - set_local $4 + set_local $5 br $repeat|0 unreachable end @@ -1430,98 +1420,89 @@ get_local $2 i32.const 1 i32.sub - set_local $4 + set_local $5 loop $repeat|2 - get_local $4 + get_local $5 i32.const 2 i32.lt_s br_if $break|2 get_local $0 get_local $1 i32.add + tee_local $2 f64.load offset=8 set_local $7 - get_local $0 - get_local $1 - i32.add - get_local $0 - get_local $1 - i32.add - get_local $4 + get_local $2 + get_local $2 + get_local $5 i32.const 3 i32.shl i32.add + tee_local $2 f64.load offset=8 f64.store offset=8 - get_local $0 - get_local $1 - i32.add - get_local $4 - i32.const 3 - i32.shl - i32.add + get_local $2 get_local $7 f64.store offset=8 i32.const 1 - set_local $5 + set_local $6 loop $continue|3 - get_local $5 + get_local $6 i32.const 1 i32.shl - get_local $8 - get_local $5 + get_local $9 + get_local $6 i32.const 5 i32.shr_s i32.const 2 i32.shl i32.add i32.load - get_local $5 + get_local $6 i32.const 31 i32.and i32.shr_u i32.const 1 i32.and i32.add - tee_local $6 - get_local $4 + tee_local $4 + get_local $5 i32.lt_s if - get_local $6 - set_local $5 + get_local $4 + set_local $6 br $continue|3 end end loop $continue|4 - get_local $5 + get_local $6 i32.const 0 i32.gt_s if get_local $0 get_local $1 i32.add + tee_local $2 f64.load offset=8 set_local $7 - get_local $0 - get_local $1 - i32.add - get_local $5 + get_local $2 + get_local $6 i32.const 3 i32.shl i32.add f64.load offset=8 - set_local $9 + set_local $8 i32.const 2 set_global $~argc get_local $7 - get_local $9 + get_local $8 get_local $3 call_indirect (type $FFi) i32.const 0 i32.lt_s if - get_local $8 - get_local $5 + get_local $9 + get_local $6 i32.const 5 i32.shr_s i32.const 2 @@ -1531,7 +1512,7 @@ get_local $2 i32.load i32.const 1 - get_local $5 + get_local $6 i32.const 31 i32.and i32.shl @@ -1540,59 +1521,51 @@ get_local $0 get_local $1 i32.add - get_local $5 + tee_local $2 + get_local $6 i32.const 3 i32.shl i32.add get_local $7 f64.store offset=8 - get_local $0 - get_local $1 - i32.add - get_local $9 + get_local $2 + get_local $8 f64.store offset=8 end - get_local $5 + get_local $6 i32.const 1 i32.shr_s - set_local $5 + set_local $6 br $continue|4 end end - get_local $4 + get_local $5 i32.const 1 i32.sub - set_local $4 + set_local $5 br $repeat|2 unreachable end unreachable end - call $~lib/allocator/arena/__memory_free get_local $0 get_local $1 i32.add + tee_local $0 i32.const 8 i32.add + tee_local $1 f64.load offset=8 set_local $7 - get_local $0 get_local $1 - i32.add - i32.const 8 - i32.add get_local $0 - get_local $1 - i32.add f64.load offset=8 f64.store offset=8 get_local $0 - get_local $1 - i32.add get_local $7 f64.store offset=8 ) - (func $~lib/internal/typedarray/TypedArray#sort (; 19 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#sort (; 16 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1674,7 +1647,7 @@ end get_local $0 ) - (func $~lib/internal/typedarray/TypedArray#sort|trampoline~anonymous|1 (; 20 ;) (type $FFi) (param $0 f64) (param $1 f64) (result i32) + (func $~lib/internal/typedarray/TypedArray#sort|trampoline~anonymous|1 (; 17 ;) (type $FFi) (param $0 f64) (param $1 f64) (result i32) (local $2 i64) (local $3 i64) get_local $0 @@ -1703,24 +1676,7 @@ i64.lt_s i32.sub ) - (func $~lib/internal/typedarray/TypedArray#sort|trampoline (; 21 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) - (local $1 i32) - block $1of1 - block $0of1 - block $outOfRange - get_global $~argc - br_table $0of1 $1of1 $outOfRange - end - unreachable - end - i32.const 1 - set_local $1 - end - get_local $0 - get_local $1 - call $~lib/internal/typedarray/TypedArray#sort - ) - (func $~lib/internal/typedarray/TypedArray#__get (; 22 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) + (func $~lib/internal/typedarray/TypedArray#__get (; 18 ;) (type $iiF) (param $0 i32) (param $1 i32) (result f64) get_local $1 get_local $0 i32.load offset=8 @@ -1746,7 +1702,7 @@ i32.add f64.load offset=8 ) - (func $~lib/internal/typedarray/TypedArray#__set (; 23 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/internal/typedarray/TypedArray#__set (; 19 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) get_local $1 get_local $0 i32.load offset=8 @@ -1769,7 +1725,7 @@ get_local $2 i32.store8 offset=8 ) - (func $~lib/typedarray/Uint8ClampedArray#__set (; 24 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) + (func $~lib/typedarray/Uint8ClampedArray#__set (; 20 ;) (type $iiiv) (param $0 i32) (param $1 i32) (param $2 i32) (local $3 i32) get_local $0 get_local $1 @@ -1787,7 +1743,7 @@ select call $~lib/internal/typedarray/TypedArray#__set ) - (func $~lib/internal/typedarray/TypedArray#__get (; 25 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#__get (; 21 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $1 get_local $0 i32.load offset=8 @@ -1809,7 +1765,7 @@ i32.add i32.load8_u offset=8 ) - (func $~lib/internal/typedarray/TypedArray#fill (; 26 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#fill (; 22 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (local $4 i32) (local $5 i32) (local $6 i32) @@ -1886,7 +1842,7 @@ end get_local $0 ) - (func $~lib/internal/typedarray/TypedArray#__get (; 27 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#__get (; 23 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) get_local $1 get_local $0 i32.load offset=8 @@ -1908,24 +1864,7 @@ i32.add i32.load8_s offset=8 ) - (func $~lib/array/Array#__get (; 28 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.lt_u - if (result i32) - get_local $0 - get_local $1 - i32.add - i32.load8_s offset=8 - else - unreachable - end - tee_local $0 - ) - (func $std/typedarray/isInt8ArrayEqual (; 29 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/typedarray/isInt8ArrayEqual (; 24 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -1942,30 +1881,37 @@ block $break|0 get_local $0 i32.load offset=8 - set_local $3 + set_local $4 loop $repeat|0 get_local $2 - get_local $3 + get_local $4 i32.ge_s br_if $break|0 get_local $0 get_local $2 call $~lib/internal/typedarray/TypedArray#__get - i32.const 24 - i32.shl - i32.const 24 - i32.shr_s - set_local $4 - get_local $1 - get_local $2 - call $~lib/array/Array#__get - i32.const 24 - i32.shl - i32.const 24 - i32.shr_s + i32.const 255 + i32.and set_local $5 - get_local $4 + get_local $2 + get_local $1 + i32.load + tee_local $3 + i32.load + i32.lt_u + if (result i32) + get_local $3 + get_local $2 + i32.add + i32.load8_s offset=8 + else + unreachable + end + set_local $3 get_local $5 + get_local $3 + i32.const 255 + i32.and i32.ne if i32.const 0 @@ -1984,7 +1930,7 @@ end i32.const 1 ) - (func $~lib/internal/typedarray/TypedArray#fill|trampoline (; 30 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#fill|trampoline (; 25 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) block $2of2 block $1of2 @@ -2009,7 +1955,7 @@ get_local $3 call $~lib/internal/typedarray/TypedArray#fill ) - (func $~lib/typedarray/Int8Array#subarray (; 31 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) + (func $~lib/typedarray/Int8Array#subarray (; 26 ;) (type $FUNCSIG$ii) (param $0 i32) (result i32) (local $1 i32) (local $2 i32) (local $3 i32) @@ -2051,7 +1997,7 @@ i32.store offset=8 get_local $1 ) - (func $~lib/internal/typedarray/TypedArray#fill (; 32 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#fill (; 27 ;) (type $iiiii) (param $0 i32) (param $1 i32) (param $2 i32) (param $3 i32) (result i32) (local $4 i32) (local $5 i32) (local $6 i32) @@ -2139,28 +2085,7 @@ end get_local $0 ) - (func $~lib/array/Array#__get (; 33 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) - get_local $1 - get_local $0 - i32.load - tee_local $0 - i32.load - i32.const 2 - i32.shr_u - i32.lt_u - if (result i32) - get_local $0 - get_local $1 - i32.const 2 - i32.shl - i32.add - i32.load offset=8 - else - unreachable - end - tee_local $0 - ) - (func $std/typedarray/isInt32ArrayEqual (; 34 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) + (func $std/typedarray/isInt32ArrayEqual (; 28 ;) (type $iii) (param $0 i32) (param $1 i32) (result i32) (local $2 i32) (local $3 i32) (local $4 i32) @@ -2181,22 +2106,37 @@ i32.load offset=8 i32.const 2 i32.shr_u - set_local $3 + set_local $4 loop $repeat|0 get_local $2 - get_local $3 + get_local $4 i32.ge_s br_if $break|0 get_local $0 get_local $2 call $~lib/internal/typedarray/TypedArray#__get - set_local $4 - get_local $1 - get_local $2 - call $~lib/array/Array#__get set_local $5 - get_local $4 + get_local $2 + get_local $1 + i32.load + tee_local $3 + i32.load + i32.const 2 + i32.shr_u + i32.lt_u + if (result i32) + get_local $3 + get_local $2 + i32.const 2 + i32.shl + i32.add + i32.load offset=8 + else + unreachable + end + set_local $3 get_local $5 + get_local $3 i32.ne if i32.const 0 @@ -2215,7 +2155,7 @@ end i32.const 1 ) - (func $~lib/internal/typedarray/TypedArray#fill|trampoline (; 35 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) + (func $~lib/internal/typedarray/TypedArray#fill|trampoline (; 29 ;) (type $FUNCSIG$iiii) (param $0 i32) (param $1 i32) (param $2 i32) (result i32) (local $3 i32) block $2of2 block $1of2 @@ -2240,8 +2180,9 @@ get_local $3 call $~lib/internal/typedarray/TypedArray#fill ) - (func $start (; 36 ;) (type $v) + (func $start (; 30 ;) (type $v) (local $0 i32) + (local $1 i32) i32.const 624 set_global $~lib/allocator/arena/startOffset get_global $~lib/allocator/arena/startOffset @@ -2474,7 +2415,21 @@ i32.const 0 set_global $~argc get_global $std/typedarray/af64 - call $~lib/internal/typedarray/TypedArray#sort|trampoline + set_local $1 + block $1of1 + block $0of1 + block $outOfRange + get_global $~argc + br_table $0of1 $1of1 $outOfRange + end + unreachable + end + i32.const 1 + set_local $0 + end + get_local $1 + get_local $0 + call $~lib/internal/typedarray/TypedArray#sort drop get_global $std/typedarray/af64 i32.const 0 @@ -2953,7 +2908,7 @@ call $~lib/internal/typedarray/TypedArray#constructor drop ) - (func $null (; 37 ;) (type $v) + (func $null (; 31 ;) (type $v) nop ) ) diff --git a/tests/compiler/switch.optimized.wat b/tests/compiler/switch.optimized.wat index fcef43d7..95a78264 100644 --- a/tests/compiler/switch.optimized.wat +++ b/tests/compiler/switch.optimized.wat @@ -2,7 +2,6 @@ (type $ii (func (param i32) (result i32))) (type $iiiiv (func (param i32 i32 i32 i32))) (type $v (func)) - (type $FUNCSIG$i (func (result i32))) (import "env" "abort" (func $~lib/env/abort (param i32 i32 i32 i32))) (memory $0 1) (data (i32.const 8) "\t\00\00\00s\00w\00i\00t\00c\00h\00.\00t\00s") @@ -68,56 +67,7 @@ end i32.const 0 ) - (func $switch/doSwitchBreakCase (; 3 ;) (type $ii) (param $0 i32) (result i32) - block $break|0 - get_local $0 - i32.const 1 - i32.eq - br_if $break|0 - i32.const 2 - return - end - i32.const 1 - ) - (func $switch/doSwitchBreakDefault (; 4 ;) (type $ii) (param $0 i32) (result i32) - block $break|0 - block $case1|0 - get_local $0 - i32.const 1 - i32.ne - br_if $break|0 - i32.const 1 - return - unreachable - end - unreachable - end - i32.const 2 - ) - (func $switch/doSwitchFallThroughCase (; 5 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 1 - i32.ne - if - i32.const 2 - return - end - i32.const 1 - ) - (func $switch/doSwitchFallThroughDefault (; 6 ;) (type $ii) (param $0 i32) (result i32) - get_local $0 - i32.const 1 - i32.eq - if - i32.const 1 - return - end - i32.const 2 - ) - (func $switch/doSwitchEmpty (; 7 ;) (type $FUNCSIG$i) (result i32) - i32.const 2 - ) - (func $start (; 8 ;) (type $v) + (func $start (; 3 ;) (type $v) i32.const 0 call $switch/doSwitch if @@ -286,185 +236,8 @@ call $~lib/env/abort unreachable end - i32.const 0 - call $switch/doSwitchBreakCase - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 51 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 1 - call $switch/doSwitchBreakCase - i32.const 1 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 52 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 2 - call $switch/doSwitchBreakCase - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 53 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 0 - call $switch/doSwitchBreakDefault - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 62 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 1 - call $switch/doSwitchBreakDefault - i32.const 1 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 63 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 2 - call $switch/doSwitchBreakDefault - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 64 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 0 - call $switch/doSwitchFallThroughCase - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 73 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 1 - call $switch/doSwitchFallThroughCase - i32.const 1 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 74 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 2 - call $switch/doSwitchFallThroughCase - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 75 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 0 - call $switch/doSwitchFallThroughDefault - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 84 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 1 - call $switch/doSwitchFallThroughDefault - i32.const 1 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 85 - i32.const 0 - call $~lib/env/abort - unreachable - end - i32.const 2 - call $switch/doSwitchFallThroughDefault - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 86 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $switch/doSwitchEmpty - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 92 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $switch/doSwitchEmpty - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 93 - i32.const 0 - call $~lib/env/abort - unreachable - end - call $switch/doSwitchEmpty - i32.const 2 - i32.ne - if - i32.const 0 - i32.const 8 - i32.const 94 - i32.const 0 - call $~lib/env/abort - unreachable - end ) - (func $null (; 9 ;) (type $v) + (func $null (; 4 ;) (type $v) nop ) ) diff --git a/tests/compiler/void.optimized.wat b/tests/compiler/void.optimized.wat index 4c376c51..be03ea1a 100644 --- a/tests/compiler/void.optimized.wat +++ b/tests/compiler/void.optimized.wat @@ -1,20 +1,11 @@ (module - (type $i (func (result i32))) (type $v (func)) (memory $0 0) (table $0 1 anyfunc) - (elem (i32.const 0) $null) + (elem (i32.const 0) $start) (export "memory" (memory $0)) (export "table" (table $0)) - (start $start) - (func $void/anInt (; 0 ;) (type $i) (result i32) - i32.const 2 - ) - (func $start (; 1 ;) (type $v) - call $void/anInt - drop - ) - (func $null (; 2 ;) (type $v) + (func $start (; 0 ;) (type $v) nop ) )