From 9305fd0c9cee24a2c7555f1e226d330360fe9089 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 23 Feb 2024 16:53:21 +0000 Subject: [PATCH 1/8] chore: upgrade prettier-plugin-solidity to 1.3.1 --- .changeset/loud-rockets-switch.md | 5 + docs/pages/store/reference/misc.mdx | 28 +- docs/pages/store/reference/store-core.mdx | 500 +++++++++--------- docs/pages/store/reference/store-hook.mdx | 68 ++- docs/pages/store/reference/store.mdx | 174 +++--- .../world/reference/internal/delegation.mdx | 19 +- .../internal/init-module-implementation.mdx | 90 ++-- .../world/reference/internal/init-module.mdx | 38 +- .../world/reference/internal/systemcall.mdx | 27 +- docs/pages/world/reference/misc.mdx | 20 +- docs/pages/world/reference/module.mdx | 9 +- docs/pages/world/reference/world-context.mdx | 41 +- docs/pages/world/reference/world-external.mdx | 90 ++-- docs/pages/world/reference/world.mdx | 109 ++-- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../minimal/packages/contracts/package.json | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../packages/contracts/package.json | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- package.json | 2 +- packages/common/package.json | 2 +- .../src/interfaces/IBaseWorld.sol | 4 +- .../src/codegen/interfaces/IBaseWorld.sol | 4 +- .../interfaces/IRegistrationSystem.sol | 4 +- pnpm-lock.yaml | 37 +- .../phaser/packages/contracts/package.json | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../react-ecs/packages/contracts/package.json | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../react/packages/contracts/package.json | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../threejs/packages/contracts/package.json | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../vanilla/packages/contracts/package.json | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- 35 files changed, 608 insertions(+), 709 deletions(-) create mode 100644 .changeset/loud-rockets-switch.md diff --git a/.changeset/loud-rockets-switch.md b/.changeset/loud-rockets-switch.md new file mode 100644 index 0000000000..f48556604b --- /dev/null +++ b/.changeset/loud-rockets-switch.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/common": patch +--- + +Pinned prettier-plugin-solidity version to 1.3.1 diff --git a/docs/pages/store/reference/misc.mdx b/docs/pages/store/reference/misc.mdx index ae365f79b0..7e883d5212 100644 --- a/docs/pages/store/reference/misc.mdx +++ b/docs/pages/store/reference/misc.mdx @@ -642,11 +642,8 @@ Filter a hook from the hook list by its address. _This function writes the updated hook list to the table in place._ ```solidity -function filterListByAddress( - ResourceId hookTableId, - ResourceId resourceWithHooks, - address hookAddressToRemove -) internal; +function filterListByAddress(ResourceId hookTableId, ResourceId resourceWithHooks, address hookAddressToRemove) + internal; ``` **Parameters** @@ -1554,14 +1551,8 @@ uint8 constant AFTER_DELETE_RECORD = 1 << 7; _Bitmap to enable all hooks._ ```solidity -uint8 constant ALL = BEFORE_SET_RECORD | - AFTER_SET_RECORD | - BEFORE_SPLICE_STATIC_DATA | - AFTER_SPLICE_STATIC_DATA | - BEFORE_SPLICE_DYNAMIC_DATA | - AFTER_SPLICE_DYNAMIC_DATA | - BEFORE_DELETE_RECORD | - AFTER_DELETE_RECORD; +uint8 constant ALL = BEFORE_SET_RECORD | AFTER_SET_RECORD | BEFORE_SPLICE_STATIC_DATA | AFTER_SPLICE_STATIC_DATA + | BEFORE_SPLICE_DYNAMIC_DATA | AFTER_SPLICE_DYNAMIC_DATA | BEFORE_DELETE_RECORD | AFTER_DELETE_RECORD; ``` #### BEFORE_ALL @@ -1569,10 +1560,8 @@ uint8 constant ALL = BEFORE_SET_RECORD | _Bitmap to enable all "before" hooks._ ```solidity -uint8 constant BEFORE_ALL = BEFORE_SET_RECORD | - BEFORE_SPLICE_STATIC_DATA | - BEFORE_SPLICE_DYNAMIC_DATA | - BEFORE_DELETE_RECORD; +uint8 constant BEFORE_ALL = + BEFORE_SET_RECORD | BEFORE_SPLICE_STATIC_DATA | BEFORE_SPLICE_DYNAMIC_DATA | BEFORE_DELETE_RECORD; ``` #### AFTER_ALL @@ -1580,10 +1569,7 @@ uint8 constant BEFORE_ALL = BEFORE_SET_RECORD | _Bitmap to enable all "after" hooks._ ```solidity -uint8 constant AFTER_ALL = AFTER_SET_RECORD | - AFTER_SPLICE_STATIC_DATA | - AFTER_SPLICE_DYNAMIC_DATA | - AFTER_DELETE_RECORD; +uint8 constant AFTER_ALL = AFTER_SET_RECORD | AFTER_SPLICE_STATIC_DATA | AFTER_SPLICE_DYNAMIC_DATA | AFTER_DELETE_RECORD; ``` ## storeResourceTypes.sol constants diff --git a/docs/pages/store/reference/store-core.mdx b/docs/pages/store/reference/store-core.mdx index 0afc6d0ed0..db49b80c31 100644 --- a/docs/pages/store/reference/store-core.mdx +++ b/docs/pages/store/reference/store-core.mdx @@ -113,12 +113,12 @@ Register a new table with the given configuration. ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] memory keyNames, - string[] memory fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] memory keyNames, + string[] memory fieldNames ) internal; ``` @@ -179,11 +179,11 @@ If the field layout is available to the caller, it is recommended to use the oth ```solidity function setRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData ) internal; ``` @@ -208,12 +208,12 @@ event without calling hooks or modifying the state._ ```solidity function setRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData, + FieldLayout fieldLayout ) internal; ``` @@ -259,12 +259,12 @@ For offchain tables, it returns early after emitting the event._ ```solidity function spliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes memory data + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes memory data ) internal; ``` @@ -313,11 +313,11 @@ For offchain tables, it returns early after emitting the event._ ```solidity function setField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - bytes memory data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + bytes memory data, + FieldLayout fieldLayout ) internal; ``` @@ -341,11 +341,11 @@ For offchain tables, it returns early after emitting the event._ ```solidity function setStaticField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - bytes memory data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + bytes memory data, + FieldLayout fieldLayout ) internal; ``` @@ -368,12 +368,8 @@ _This method emits a `Store_SpliceDynamicData` event, updates the data in storag For offchain tables, it returns early after emitting the event._ ```solidity -function setDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - bytes memory data -) internal; +function setDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex, bytes memory data) + internal; ``` **Parameters** @@ -437,10 +433,10 @@ For offchain tables, it returns early after emitting the event._ ```solidity function pushToDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - bytes memory dataToPush + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + bytes memory dataToPush ) internal; ``` @@ -463,10 +459,10 @@ For offchain tables, it returns early after emitting the event._ ```solidity function popFromDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 byteLengthToPop + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 byteLengthToPop ) internal; ``` @@ -487,10 +483,10 @@ _This function internally calls another overload of `getRecord`, loading the fie If the field layout is available to the caller, it is recommended to use the other overload to avoid an additional storage read._ ```solidity -function getRecord( - ResourceId tableId, - bytes32[] memory keyTuple -) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord(ResourceId tableId, bytes32[] memory keyTuple) + internal + view + returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -513,11 +509,10 @@ function getRecord( Get the full record (all fields, static and dynamic data) for the given table ID and key tuple, with the given field layout. ```solidity -function getRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - FieldLayout fieldLayout -) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord(ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout) + internal + view + returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -543,7 +538,10 @@ Get a single field from the given table ID and key tuple. _This function internally calls another overload of `getField`, loading the field layout from storage._ ```solidity -function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) internal view returns (bytes memory); +function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) + internal + view + returns (bytes memory); ``` **Parameters** @@ -565,12 +563,10 @@ function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldInde Get a single field from the given table ID and key tuple, with the given field layout. ```solidity -function getField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) internal view returns (bytes memory); +function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + internal + view + returns (bytes memory); ``` **Parameters** @@ -596,12 +592,10 @@ _The field value is left-aligned in the returned bytes32, the rest of the word i Consumers are expected to truncate the returned value as needed._ ```solidity -function getStaticField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) internal view returns (bytes32); +function getStaticField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + internal + view + returns (bytes32); ``` **Parameters** @@ -624,11 +618,10 @@ function getStaticField( Get a single dynamic field from the given table ID and key tuple. ```solidity -function getDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex -) internal view returns (bytes memory); +function getDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) + internal + view + returns (bytes memory); ``` **Parameters** @@ -653,11 +646,10 @@ _This function internally calls another overload of `getFieldLength`, loading th If the field layout is available to the caller, it is recommended to use the other overload to avoid an additional storage read._ ```solidity -function getFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex -) internal view returns (uint256); +function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) + internal + view + returns (uint256); ``` **Parameters** @@ -679,12 +671,10 @@ function getFieldLength( Get the byte length of a single field from the given table ID and key tuple. ```solidity -function getFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) internal view returns (uint256); +function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + internal + view + returns (uint256); ``` **Parameters** @@ -707,11 +697,10 @@ function getFieldLength( Get the byte length of a single dynamic field from the given table ID and key tuple. ```solidity -function getDynamicFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex -) internal view returns (uint256); +function getDynamicFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) + internal + view + returns (uint256); ``` **Parameters** @@ -734,11 +723,11 @@ Get a byte slice (including start, excluding end) of a single dynamic field from ```solidity function getDynamicFieldSlice( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 start, - uint256 end + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 start, + uint256 end ) internal view returns (bytes memory); ``` @@ -886,13 +875,13 @@ It reverts with `Store_IndexOutOfBounds` if the start index is larger than the p ```solidity function _spliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes memory data, - PackedCounter previousEncodedLengths + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes memory data, + PackedCounter previousEncodedLengths ) internal; ``` @@ -913,11 +902,10 @@ function _spliceDynamicData( Get full static data for the given table ID and key tuple, with the given length in bytes. ```solidity -function _getStaticData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint256 length -) internal view returns (bytes memory); +function _getStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint256 length) + internal + view + returns (bytes memory); ``` **Parameters** @@ -939,12 +927,10 @@ function _getStaticData( Get a single static field from the given table ID and key tuple, with the given value field layout. ```solidity -function _getStaticFieldBytes( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) internal view returns (bytes memory); +function _getStaticFieldBytes(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + internal + view + returns (bytes memory); ``` **Parameters** @@ -1030,11 +1016,10 @@ function _getStaticDataOffset(FieldLayout fieldLayout, uint8 fieldIndex) interna Compute the storage location based on table ID, key tuple, and dynamic field index. ```solidity -function _getDynamicDataLocation( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex -) internal pure returns (uint256); +function _getDynamicDataLocation(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) + internal + pure + returns (uint256); ``` **Parameters** @@ -1077,10 +1062,10 @@ function _getDynamicDataLengthLocation(ResourceId tableId, bytes32[] memory keyT Load the encoded dynamic data length from storage for the given table ID and key tuple. ```solidity -function _loadEncodedDynamicDataLength( - ResourceId tableId, - bytes32[] memory keyTuple -) internal view returns (PackedCounter); +function _loadEncodedDynamicDataLength(ResourceId tableId, bytes32[] memory keyTuple) + internal + view + returns (PackedCounter); ``` **Parameters** @@ -1210,10 +1195,11 @@ function getKeySchema(ResourceId tableId) public view virtual returns (Schema ke Fetches a record from a specified table using a provided key tuple. ```solidity -function getRecord( - ResourceId tableId, - bytes32[] calldata keyTuple -) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord(ResourceId tableId, bytes32[] calldata keyTuple) + public + view + virtual + returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -1236,11 +1222,11 @@ function getRecord( Fetches a record from a specified table using a provided key tuple and field layout. ```solidity -function getRecord( - ResourceId tableId, - bytes32[] calldata keyTuple, - FieldLayout fieldLayout -) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord(ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout) + public + view + virtual + returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -1267,11 +1253,11 @@ _This overload loads the FieldLayout from storage. If the table's FieldLayout is to the caller, it should be passed in to the other overload to avoid the storage read._ ```solidity -function getField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex -) public view virtual returns (bytes memory data); +function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex) + public + view + virtual + returns (bytes memory data); ``` **Parameters** @@ -1293,12 +1279,11 @@ function getField( Retrieves data for a specified field in a record. ```solidity -function getField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) public view virtual returns (bytes memory data); +function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + public + view + virtual + returns (bytes memory data); ``` **Parameters** @@ -1321,12 +1306,11 @@ function getField( Retrieves data for a specific static (fixed length) field in a record. ```solidity -function getStaticField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) public view virtual returns (bytes32 data); +function getStaticField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + public + view + virtual + returns (bytes32 data); ``` **Parameters** @@ -1349,11 +1333,11 @@ function getStaticField( Retrieves data for a specific dynamic (variable length) field in a record. ```solidity -function getDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex -) public view virtual returns (bytes memory data); +function getDynamicField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 dynamicFieldIndex) + public + view + virtual + returns (bytes memory data); ``` **Parameters** @@ -1378,11 +1362,11 @@ _This overload loads the FieldLayout from storage. If the table's FieldLayout is to the caller, it should be passed in to the other overload to avoid the storage read._ ```solidity -function getFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex -) public view virtual returns (uint256); +function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) + public + view + virtual + returns (uint256); ``` **Parameters** @@ -1404,12 +1388,11 @@ function getFieldLength( Calculates the length of a specified field in a record. ```solidity -function getFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) public view virtual returns (uint256); +function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + public + view + virtual + returns (uint256); ``` **Parameters** @@ -1432,11 +1415,11 @@ function getFieldLength( Calculates the length of a specified dynamic (variable length) field in a record. ```solidity -function getDynamicFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex -) public view virtual returns (uint256); +function getDynamicFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) + public + view + virtual + returns (uint256); ``` **Parameters** @@ -1459,11 +1442,11 @@ Retrieves a slice of a dynamic (variable length) field. ```solidity function getDynamicFieldSlice( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 start, - uint256 end + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 start, + uint256 end ) public view virtual returns (bytes memory); ``` @@ -1649,12 +1632,12 @@ _Registers a table with specified configurations._ ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] memory keyNames, - string[] memory fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] memory keyNames, + string[] memory fieldNames ) internal; ``` @@ -1675,11 +1658,11 @@ _Sets a record in the store._ ```solidity function setRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData ) internal; ``` @@ -1716,12 +1699,12 @@ _Splices the dynamic data for a given table ID, key tuple, and dynamic field ind ```solidity function spliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes memory data + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes memory data ) internal; ``` @@ -1759,11 +1742,11 @@ _Sets the data for a specific field in a record, considering a specific field la ```solidity function setField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - bytes memory data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + bytes memory data, + FieldLayout fieldLayout ) internal; ``` @@ -1783,11 +1766,11 @@ _Sets the data for a specific static (fixed length) field in a record, consideri ```solidity function setStaticField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - bytes memory data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + bytes memory data, + FieldLayout fieldLayout ) internal; ``` @@ -1806,12 +1789,8 @@ function setStaticField( _Sets the value of a specific dynamic (variable-length) field in a record._ ```solidity -function setDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - bytes memory data -) internal; +function setDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex, bytes memory data) + internal; ``` **Parameters** @@ -1829,10 +1808,10 @@ _Appends data to a specific dynamic (variable length) field of a record._ ```solidity function pushToDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - bytes memory dataToPush + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + bytes memory dataToPush ) internal; ``` @@ -1851,10 +1830,10 @@ _Removes data from the end of a specific dynamic (variable length) field of a re ```solidity function popFromDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 byteLengthToPop + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 byteLengthToPop ) internal; ``` @@ -1887,10 +1866,10 @@ function deleteRecord(ResourceId tableId, bytes32[] memory keyTuple) internal; _Retrieves a record from a table._ ```solidity -function getRecord( - ResourceId tableId, - bytes32[] memory keyTuple -) internal view returns (bytes memory, PackedCounter, bytes memory); +function getRecord(ResourceId tableId, bytes32[] memory keyTuple) + internal + view + returns (bytes memory, PackedCounter, bytes memory); ``` **Parameters** @@ -1913,11 +1892,10 @@ function getRecord( _Retrieves a record from a table with a specific layout._ ```solidity -function getRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - FieldLayout fieldLayout -) internal view returns (bytes memory, PackedCounter, bytes memory); +function getRecord(ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout) + internal + view + returns (bytes memory, PackedCounter, bytes memory); ``` **Parameters** @@ -1941,7 +1919,10 @@ function getRecord( _Retrieves a specific field from a record._ ```solidity -function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) internal view returns (bytes memory); +function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) + internal + view + returns (bytes memory); ``` **Parameters** @@ -1963,12 +1944,10 @@ function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldInde _Retrieves a specific field from a record with a given layout._ ```solidity -function getField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) internal view returns (bytes memory); +function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + internal + view + returns (bytes memory); ``` **Parameters** @@ -1991,12 +1970,10 @@ function getField( _Retrieves a specific static (fixed length) field from a record with a given layout._ ```solidity -function getStaticField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) internal view returns (bytes32); +function getStaticField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + internal + view + returns (bytes32); ``` **Parameters** @@ -2019,11 +1996,10 @@ function getStaticField( _Retrieves a specific dynamic (variable length) field from a record._ ```solidity -function getDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex -) internal view returns (bytes memory); +function getDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) + internal + view + returns (bytes memory); ``` **Parameters** @@ -2045,11 +2021,10 @@ function getDynamicField( _Retrieves the length of a specific field in a record._ ```solidity -function getFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex -) internal view returns (uint256); +function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) + internal + view + returns (uint256); ``` **Parameters** @@ -2071,12 +2046,10 @@ function getFieldLength( _Retrieves the length of a specific field in a record with a given layout._ ```solidity -function getFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) internal view returns (uint256); +function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + internal + view + returns (uint256); ``` **Parameters** @@ -2099,11 +2072,10 @@ function getFieldLength( _Retrieves the length of a specific dynamic (variable length) field in a record._ ```solidity -function getDynamicFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex -) internal view returns (uint256); +function getDynamicFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) + internal + view + returns (uint256); ``` **Parameters** @@ -2126,11 +2098,11 @@ _Retrieves a slice of a dynamic (variable length) field from a record._ ```solidity function getDynamicFieldSlice( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 start, - uint256 end + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 start, + uint256 end ) internal view returns (bytes memory); ``` @@ -2158,6 +2130,6 @@ _Represents the layout of the storage slot (currently just the address)_ ```solidity struct StorageSlotLayout { - address storeAddress; + address storeAddress; } ``` diff --git a/docs/pages/store/reference/store-hook.mdx b/docs/pages/store/reference/store-hook.mdx index bce6a9c9ca..50c1a8e048 100644 --- a/docs/pages/store/reference/store-hook.mdx +++ b/docs/pages/store/reference/store-hook.mdx @@ -15,12 +15,12 @@ Called before setting a record in the store. ```solidity function onBeforeSetRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData, + FieldLayout fieldLayout ) external; ``` @@ -41,12 +41,12 @@ Called after setting a record in the store. ```solidity function onAfterSetRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData, + FieldLayout fieldLayout ) external; ``` @@ -69,12 +69,8 @@ _Splice operations in static data always overwrite data starting at the start po so the total length of the data remains the same and no data is shifted._ ```solidity -function onBeforeSpliceStaticData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint48 start, - bytes memory data -) external; +function onBeforeSpliceStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint48 start, bytes memory data) + external; ``` **Parameters** @@ -94,12 +90,8 @@ _Splice operations in static data always overwrite data starting at the start po so the total length of the data remains the same and no data is shifted._ ```solidity -function onAfterSpliceStaticData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint48 start, - bytes memory data -) external; +function onAfterSpliceStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint48 start, bytes memory data) + external; ``` **Parameters** @@ -120,13 +112,13 @@ to avoid shifting data after the inserted or deleted data._ ```solidity function onBeforeSpliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - PackedCounter encodedLengths, - bytes memory data + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + PackedCounter encodedLengths, + bytes memory data ) external; ``` @@ -151,13 +143,13 @@ to avoid shifting data after the inserted or deleted data._ ```solidity function onAfterSpliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - PackedCounter encodedLengths, - bytes memory data + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + PackedCounter encodedLengths, + bytes memory data ) external; ``` diff --git a/docs/pages/store/reference/store.mdx b/docs/pages/store/reference/store.mdx index 20bcc354bf..3fa899f267 100644 --- a/docs/pages/store/reference/store.mdx +++ b/docs/pages/store/reference/store.mdx @@ -246,10 +246,10 @@ function getKeySchema(ResourceId tableId) external view returns (Schema keySchem Get full record (all fields, static and dynamic data) for the given tableId and key tuple, loading the field layout from storage ```solidity -function getRecord( - ResourceId tableId, - bytes32[] calldata keyTuple -) external view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord(ResourceId tableId, bytes32[] calldata keyTuple) + external + view + returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` #### getRecord @@ -257,11 +257,10 @@ function getRecord( Get full record (all fields, static and dynamic data) for the given tableId and key tuple, with the given field layout ```solidity -function getRecord( - ResourceId tableId, - bytes32[] calldata keyTuple, - FieldLayout fieldLayout -) external view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord(ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout) + external + view + returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` #### getField @@ -269,11 +268,10 @@ function getRecord( Get a single field from the given tableId and key tuple, loading the field layout from storage ```solidity -function getField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex -) external view returns (bytes memory data); +function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex) + external + view + returns (bytes memory data); ``` #### getField @@ -281,12 +279,10 @@ function getField( Get a single field from the given tableId and key tuple, with the given field layout ```solidity -function getField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) external view returns (bytes memory data); +function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + external + view + returns (bytes memory data); ``` #### getStaticField @@ -296,12 +292,10 @@ Note: the field value is left-aligned in the returned bytes32, the rest of the w Consumers are expected to truncate the returned value as needed. ```solidity -function getStaticField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) external view returns (bytes32); +function getStaticField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + external + view + returns (bytes32); ``` #### getDynamicField @@ -310,11 +304,10 @@ Get a single dynamic field from the given tableId and key tuple at the given dyn (Dynamic field index = field index - number of static fields) ```solidity -function getDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex -) external view returns (bytes memory); +function getDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) + external + view + returns (bytes memory); ``` #### getFieldLength @@ -322,11 +315,10 @@ function getDynamicField( Get the byte length of a single field from the given tableId and key tuple, loading the field layout from storage ```solidity -function getFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex -) external view returns (uint256); +function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) + external + view + returns (uint256); ``` #### getFieldLength @@ -334,12 +326,10 @@ function getFieldLength( Get the byte length of a single field from the given tableId and key tuple, with the given value field layout ```solidity -function getFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - FieldLayout fieldLayout -) external view returns (uint256); +function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) + external + view + returns (uint256); ``` #### getDynamicFieldLength @@ -347,11 +337,10 @@ function getFieldLength( Get the byte length of a single dynamic field from the given tableId and key tuple ```solidity -function getDynamicFieldLength( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex -) external view returns (uint256); +function getDynamicFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) + external + view + returns (uint256); ``` #### getDynamicFieldSlice @@ -361,11 +350,11 @@ The slice is unchecked and will return invalid data if `start`:`end` overflow. ```solidity function getDynamicFieldSlice( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 start, - uint256 end + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 start, + uint256 end ) external view returns (bytes memory data); ``` @@ -382,30 +371,31 @@ function getDynamicFieldSlice( ```solidity function setRecord( - ResourceId tableId, - bytes32[] calldata keyTuple, - bytes calldata staticData, - PackedCounter encodedLengths, - bytes calldata dynamicData + ResourceId tableId, + bytes32[] calldata keyTuple, + bytes calldata staticData, + PackedCounter encodedLengths, + bytes calldata dynamicData ) external; ``` #### spliceStaticData ```solidity -function spliceStaticData(ResourceId tableId, bytes32[] calldata keyTuple, uint48 start, bytes calldata data) external; +function spliceStaticData(ResourceId tableId, bytes32[] calldata keyTuple, uint48 start, bytes calldata data) + external; ``` #### spliceDynamicData ```solidity function spliceDynamicData( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes calldata data + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes calldata data ) external; ``` @@ -419,11 +409,11 @@ function setField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIn ```solidity function setField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data, + FieldLayout fieldLayout ) external; ``` @@ -431,33 +421,29 @@ function setField( ```solidity function setStaticField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data, + FieldLayout fieldLayout ) external; ``` #### setDynamicField ```solidity -function setDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - bytes calldata data -) external; +function setDynamicField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 dynamicFieldIndex, bytes calldata data) + external; ``` #### pushToDynamicField ```solidity function pushToDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - bytes calldata dataToPush + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + bytes calldata dataToPush ) external; ``` @@ -465,10 +451,10 @@ function pushToDynamicField( ```solidity function popFromDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - uint256 byteLengthToPop + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + uint256 byteLengthToPop ) external; ``` @@ -492,12 +478,12 @@ making them less performance critical than the methods. ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] calldata keyNames, - string[] calldata fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] calldata keyNames, + string[] calldata fieldNames ) external; ``` diff --git a/docs/pages/world/reference/internal/delegation.mdx b/docs/pages/world/reference/internal/delegation.mdx index 12831b861d..0600ace8fd 100644 --- a/docs/pages/world/reference/internal/delegation.mdx +++ b/docs/pages/world/reference/internal/delegation.mdx @@ -76,11 +76,11 @@ _Verifying the delegation might have side effects in the delegation control cont ```solidity function verify( - ResourceId delegationControlId, - address delegator, - address delegatee, - ResourceId systemId, - bytes memory callData + ResourceId delegationControlId, + address delegator, + address delegatee, + ResourceId systemId, + bytes memory callData ) internal returns (bool); ``` @@ -119,9 +119,12 @@ Check if the given interfaceId is supported by this contract. _Overrides the functionality from IERC165 and WorldContextConsumer to check for supported interfaces._ ```solidity -function supportsInterface( - bytes4 interfaceId -) public pure virtual override(IERC165, WorldContextConsumer) returns (bool); +function supportsInterface(bytes4 interfaceId) + public + pure + virtual + override(IERC165, WorldContextConsumer) + returns (bool); ``` **Parameters** diff --git a/docs/pages/world/reference/internal/init-module-implementation.mdx b/docs/pages/world/reference/internal/init-module-implementation.mdx index 6acb16654e..1cc11c4410 100644 --- a/docs/pages/world/reference/internal/init-module-implementation.mdx +++ b/docs/pages/world/reference/internal/init-module-implementation.mdx @@ -125,11 +125,10 @@ Transfer balance to another namespace in the World. _Requires the caller to have access to the source namespace and ensures the destination namespace type is valid._ ```solidity -function transferBalanceToNamespace( - ResourceId fromNamespaceId, - ResourceId toNamespaceId, - uint256 amount -) public virtual onlyDelegatecall; +function transferBalanceToNamespace(ResourceId fromNamespaceId, ResourceId toNamespaceId, uint256 amount) + public + virtual + onlyDelegatecall; ``` **Parameters** @@ -147,11 +146,10 @@ Transfer balance out of the World to a specific address. _Requires the caller to have access to the source namespace and ensures sufficient balance before transfer._ ```solidity -function transferBalanceToAddress( - ResourceId fromNamespaceId, - address toAddress, - uint256 amount -) public virtual onlyDelegatecall; +function transferBalanceToAddress(ResourceId fromNamespaceId, address toAddress, uint256 amount) + public + virtual + onlyDelegatecall; ``` **Parameters** @@ -182,12 +180,12 @@ Existing namespaces require the caller to be the owner for table registration._ ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] calldata keyNames, - string[] calldata fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] calldata keyNames, + string[] calldata fieldNames ) public virtual onlyDelegatecall; ``` @@ -210,11 +208,10 @@ _The caller must be the owner of the namespace to which the table belongs. The hook must conform to the IStoreHook interface._ ```solidity -function registerStoreHook( - ResourceId tableId, - IStoreHook hookAddress, - uint8 enabledHooksBitmap -) public virtual onlyDelegatecall; +function registerStoreHook(ResourceId tableId, IStoreHook hookAddress, uint8 enabledHooksBitmap) + public + virtual + onlyDelegatecall; ``` **Parameters** @@ -260,7 +257,10 @@ Make batch calls to multiple systems into a single transaction. _Iterates through an array of system calls, executes them, and returns an array of return data._ ```solidity -function batchCall(SystemCallData[] calldata systemCalls) public onlyDelegatecall returns (bytes[] memory returnDatas); +function batchCall(SystemCallData[] calldata systemCalls) + public + onlyDelegatecall + returns (bytes[] memory returnDatas); ``` **Parameters** @@ -282,9 +282,10 @@ Make batch calls from specific addresses to multiple systems in a single transac _Iterates through an array of system calls with specified 'from' addresses, executes them, and returns an array of return data._ ```solidity -function batchCallFrom( - SystemCallFromData[] calldata systemCalls -) public onlyDelegatecall returns (bytes[] memory returnDatas); +function batchCallFrom(SystemCallFromData[] calldata systemCalls) + public + onlyDelegatecall + returns (bytes[] memory returnDatas); ``` **Parameters** @@ -333,11 +334,10 @@ Registers a new system hook _Adds a new hook for the system at the provided system ID_ ```solidity -function registerSystemHook( - ResourceId systemId, - ISystemHook hookAddress, - uint8 enabledHooksBitmap -) public virtual onlyDelegatecall; +function registerSystemHook(ResourceId systemId, ISystemHook hookAddress, uint8 enabledHooksBitmap) + public + virtual + onlyDelegatecall; ``` **Parameters** @@ -396,10 +396,10 @@ Registers a new World function selector _Creates a mapping between a World function and its associated system function_ ```solidity -function registerFunctionSelector( - ResourceId systemId, - string memory systemFunctionSignature -) public onlyDelegatecall returns (bytes4 worldFunctionSelector); +function registerFunctionSelector(ResourceId systemId, string memory systemFunctionSignature) + public + onlyDelegatecall + returns (bytes4 worldFunctionSelector); ``` **Parameters** @@ -423,9 +423,9 @@ _Creates a mapping for a root World function without namespace or name prefix_ ```solidity function registerRootFunctionSelector( - ResourceId systemId, - string memory worldFunctionSignature, - bytes4 systemFunctionSelector + ResourceId systemId, + string memory worldFunctionSignature, + bytes4 systemFunctionSelector ) public onlyDelegatecall returns (bytes4 worldFunctionSelector); ``` @@ -450,11 +450,9 @@ Registers a delegation for the caller _Creates a new delegation from the caller to the specified delegatee_ ```solidity -function registerDelegation( - address delegatee, - ResourceId delegationControlId, - bytes memory initCallData -) public onlyDelegatecall; +function registerDelegation(address delegatee, ResourceId delegationControlId, bytes memory initCallData) + public + onlyDelegatecall; ``` **Parameters** @@ -488,11 +486,9 @@ Registers a delegation for a namespace _Sets up a new delegation control for a specific namespace_ ```solidity -function registerNamespaceDelegation( - ResourceId namespaceId, - ResourceId delegationControlId, - bytes memory initCallData -) public onlyDelegatecall; +function registerNamespaceDelegation(ResourceId namespaceId, ResourceId delegationControlId, bytes memory initCallData) + public + onlyDelegatecall; ``` **Parameters** diff --git a/docs/pages/world/reference/internal/init-module.mdx b/docs/pages/world/reference/internal/init-module.mdx index c25be28ee8..f17174eac7 100644 --- a/docs/pages/world/reference/internal/init-module.mdx +++ b/docs/pages/world/reference/internal/init-module.mdx @@ -43,10 +43,10 @@ address internal immutable registrationSystem; ```solidity constructor( - AccessManagementSystem _accessManagementSystem, - BalanceTransferSystem _balanceTransferSystem, - BatchCallSystem _batchCallSystem, - RegistrationSystem _registrationSystem + AccessManagementSystem _accessManagementSystem, + BalanceTransferSystem _balanceTransferSystem, + BatchCallSystem _batchCallSystem, + RegistrationSystem _registrationSystem ); ``` @@ -129,9 +129,8 @@ _Resource ID for access management system._ _This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name._ ```solidity -ResourceId constant ACCESS_MANAGEMENT_SYSTEM_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("AccessManagement"))) -); +ResourceId constant ACCESS_MANAGEMENT_SYSTEM_ID = + ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("AccessManagement")))); ``` #### BALANCE_TRANSFER_SYSTEM_ID @@ -141,9 +140,8 @@ _Resource ID for balance transfer system._ _This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name._ ```solidity -ResourceId constant BALANCE_TRANSFER_SYSTEM_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BalanceTransfer"))) -); +ResourceId constant BALANCE_TRANSFER_SYSTEM_ID = + ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BalanceTransfer")))); ``` #### BATCH_CALL_SYSTEM_ID @@ -153,9 +151,8 @@ _Resource ID for batch call system._ _This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name._ ```solidity -ResourceId constant BATCH_CALL_SYSTEM_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BatchCall"))) -); +ResourceId constant BATCH_CALL_SYSTEM_ID = + ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BatchCall")))); ``` #### REGISTRATION_SYSTEM_ID @@ -165,9 +162,8 @@ _Resource ID for core registration system._ _This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name._ ```solidity -ResourceId constant REGISTRATION_SYSTEM_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("Registration"))) -); +ResourceId constant REGISTRATION_SYSTEM_ID = + ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("Registration")))); ``` ## RegistrationSystem @@ -237,8 +233,8 @@ _Used to represent a call to a specific system identified by a ResourceId._ ```solidity struct SystemCallData { - ResourceId systemId; - bytes callData; + ResourceId systemId; + bytes callData; } ``` @@ -252,8 +248,8 @@ _Used to represent a call from a specific address to a specific system._ ```solidity struct SystemCallFromData { - address from; - ResourceId systemId; - bytes callData; + address from; + ResourceId systemId; + bytes callData; } ``` diff --git a/docs/pages/world/reference/internal/systemcall.mdx b/docs/pages/world/reference/internal/systemcall.mdx index 94b9579e7c..619082d31e 100644 --- a/docs/pages/world/reference/internal/systemcall.mdx +++ b/docs/pages/world/reference/internal/systemcall.mdx @@ -16,12 +16,9 @@ Calls a system identified by its Resource ID while ensuring necessary access con _This function does not revert if the system call fails. Instead, it returns a success flag._ ```solidity -function call( - address caller, - uint256 value, - ResourceId systemId, - bytes memory callData -) internal returns (bool success, bytes memory data); +function call(address caller, uint256 value, ResourceId systemId, bytes memory callData) + internal + returns (bool success, bytes memory data); ``` **Parameters** @@ -47,12 +44,9 @@ Calls a system identified by its Resource ID, ensuring access controls, and trig _This function does not revert if the system call fails. Instead, it returns a success flag._ ```solidity -function callWithHooks( - address caller, - ResourceId systemId, - bytes memory callData, - uint256 value -) internal returns (bool success, bytes memory data); +function callWithHooks(address caller, ResourceId systemId, bytes memory callData, uint256 value) + internal + returns (bool success, bytes memory data); ``` **Parameters** @@ -76,12 +70,9 @@ function callWithHooks( Calls a system identified by its Resource ID, ensures access controls, triggers associated system hooks, and reverts on failure. ```solidity -function callWithHooksOrRevert( - address caller, - ResourceId systemId, - bytes memory callData, - uint256 value -) internal returns (bytes memory data); +function callWithHooksOrRevert(address caller, ResourceId systemId, bytes memory callData, uint256 value) + internal + returns (bytes memory data); ``` **Parameters** diff --git a/docs/pages/world/reference/misc.mdx b/docs/pages/world/reference/misc.mdx index b2ebefd27c..f4642f30a1 100644 --- a/docs/pages/world/reference/misc.mdx +++ b/docs/pages/world/reference/misc.mdx @@ -46,33 +46,29 @@ bytes16 constant ROOT_NAME = ""; #### STORE_NAMESPACE_ID ```solidity -ResourceId constant STORE_NAMESPACE_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_NAMESPACE, bytes14("store"), ROOT_NAME)) -); +ResourceId constant STORE_NAMESPACE_ID = + ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_NAMESPACE, bytes14("store"), ROOT_NAME))); ``` #### WORLD_NAMESPACE_ID ```solidity -ResourceId constant WORLD_NAMESPACE_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_NAMESPACE, bytes14("world"), ROOT_NAME)) -); +ResourceId constant WORLD_NAMESPACE_ID = + ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_NAMESPACE, bytes14("world"), ROOT_NAME))); ``` #### ROOT_NAMESPACE_ID ```solidity -ResourceId constant ROOT_NAMESPACE_ID = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_NAMESPACE, ROOT_NAMESPACE, ROOT_NAME)) -); +ResourceId constant ROOT_NAMESPACE_ID = + ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_NAMESPACE, ROOT_NAMESPACE, ROOT_NAME))); ``` #### UNLIMITED_DELEGATION ```solidity -ResourceId constant UNLIMITED_DELEGATION = ResourceId.wrap( - bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("unlimited"))) -); +ResourceId constant UNLIMITED_DELEGATION = + ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("unlimited")))); ``` ## revertWithBytes diff --git a/docs/pages/world/reference/module.mdx b/docs/pages/world/reference/module.mdx index 6ebade08b3..190369a71e 100644 --- a/docs/pages/world/reference/module.mdx +++ b/docs/pages/world/reference/module.mdx @@ -26,9 +26,12 @@ Checks if the given interfaceId is supported by this contract. _Overrides the functionality from IERC165 and WorldContextConsumer to check for supported interfaces._ ```solidity -function supportsInterface( - bytes4 interfaceId -) public pure virtual override(IERC165, WorldContextConsumer) returns (bool); +function supportsInterface(bytes4 interfaceId) + public + pure + virtual + override(IERC165, WorldContextConsumer) + returns (bool); ``` **Parameters** diff --git a/docs/pages/world/reference/world-context.mdx b/docs/pages/world/reference/world-context.mdx index 514178c281..4db4a9653f 100644 --- a/docs/pages/world/reference/world-context.mdx +++ b/docs/pages/world/reference/world-context.mdx @@ -150,7 +150,10 @@ appending the context values (like msg.sender and msg.value) to the calldata for Appends context values to the given calldata. ```solidity -function appendContext(bytes memory callData, address msgSender, uint256 msgValue) internal pure returns (bytes memory); +function appendContext(bytes memory callData, address msgSender, uint256 msgValue) + internal + pure + returns (bytes memory); ``` **Parameters** @@ -172,12 +175,9 @@ function appendContext(bytes memory callData, address msgSender, uint256 msgValu Makes a call to the target contract with context values appended to the calldata. ```solidity -function callWithContext( - address msgSender, - uint256 msgValue, - address target, - bytes memory callData -) internal returns (bool success, bytes memory data); +function callWithContext(address msgSender, uint256 msgValue, address target, bytes memory callData) + internal + returns (bool success, bytes memory data); ``` **Parameters** @@ -201,12 +201,9 @@ function callWithContext( Makes a delegatecall to the target contract with context values appended to the calldata. ```solidity -function delegatecallWithContext( - address msgSender, - uint256 msgValue, - address target, - bytes memory callData -) internal returns (bool success, bytes memory data); +function delegatecallWithContext(address msgSender, uint256 msgValue, address target, bytes memory callData) + internal + returns (bool success, bytes memory data); ``` **Parameters** @@ -232,12 +229,9 @@ Makes a call to the target contract with context values appended to the calldata _Revert in the case of failure._ ```solidity -function callWithContextOrRevert( - address msgSender, - uint256 msgValue, - address target, - bytes memory callData -) internal returns (bytes memory data); +function callWithContextOrRevert(address msgSender, uint256 msgValue, address target, bytes memory callData) + internal + returns (bytes memory data); ``` **Parameters** @@ -262,12 +256,9 @@ Makes a delegatecall to the target contract with context values appended to the _Revert in the case of failure._ ```solidity -function delegatecallWithContextOrRevert( - address msgSender, - uint256 msgValue, - address target, - bytes memory callData -) internal returns (bytes memory data); +function delegatecallWithContextOrRevert(address msgSender, uint256 msgValue, address target, bytes memory callData) + internal + returns (bytes memory data); ``` **Parameters** diff --git a/docs/pages/world/reference/world-external.mdx b/docs/pages/world/reference/world-external.mdx index 3a587a5f10..0a6b952da9 100644 --- a/docs/pages/world/reference/world-external.mdx +++ b/docs/pages/world/reference/world-external.mdx @@ -32,12 +32,12 @@ function storeVersion() public pure returns (bytes32); ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] calldata keyNames, - string[] calldata fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] calldata keyNames, + string[] calldata fieldNames ) external; ``` @@ -127,11 +127,10 @@ Transfer balance to another namespace in the World. _Requires the caller to have access to the source namespace and ensures the destination namespace type is valid._ ```solidity -function transferBalanceToNamespace( - ResourceId fromNamespaceId, - ResourceId toNamespaceId, - uint256 amount -) public virtual onlyDelegatecall; +function transferBalanceToNamespace(ResourceId fromNamespaceId, ResourceId toNamespaceId, uint256 amount) + public + virtual + onlyDelegatecall; ``` **Parameters** @@ -149,11 +148,10 @@ Transfer balance out of the World to a specific address. _Requires the caller to have access to the source namespace and ensures sufficient balance before transfer._ ```solidity -function transferBalanceToAddress( - ResourceId fromNamespaceId, - address toAddress, - uint256 amount -) public virtual onlyDelegatecall; +function transferBalanceToAddress(ResourceId fromNamespaceId, address toAddress, uint256 amount) + public + virtual + onlyDelegatecall; ``` **Parameters** @@ -171,7 +169,10 @@ Make batch calls to multiple systems into a single transaction. _Iterates through an array of system calls, executes them, and returns an array of return data._ ```solidity -function batchCall(SystemCallData[] calldata systemCalls) public onlyDelegatecall returns (bytes[] memory returnDatas); +function batchCall(SystemCallData[] calldata systemCalls) + public + onlyDelegatecall + returns (bytes[] memory returnDatas); ``` **Parameters** @@ -193,9 +194,10 @@ Make batch calls from specific addresses to multiple systems in a single transac _Iterates through an array of system calls with specified 'from' addresses, executes them, and returns an array of return data._ ```solidity -function batchCallFrom( - SystemCallFromData[] calldata systemCalls -) public onlyDelegatecall returns (bytes[] memory returnDatas); +function batchCallFrom(SystemCallFromData[] calldata systemCalls) + public + onlyDelegatecall + returns (bytes[] memory returnDatas); ``` **Parameters** @@ -251,11 +253,10 @@ Registers a new system hook _Adds a new hook for the system at the provided system ID_ ```solidity -function registerSystemHook( - ResourceId systemId, - ISystemHook hookAddress, - uint8 enabledHooksBitmap -) public virtual onlyDelegatecall; +function registerSystemHook(ResourceId systemId, ISystemHook hookAddress, uint8 enabledHooksBitmap) + public + virtual + onlyDelegatecall; ``` **Parameters** @@ -314,10 +315,10 @@ Registers a new World function selector _Creates a mapping between a World function and its associated system function_ ```solidity -function registerFunctionSelector( - ResourceId systemId, - string memory systemFunctionSignature -) public onlyDelegatecall returns (bytes4 worldFunctionSelector); +function registerFunctionSelector(ResourceId systemId, string memory systemFunctionSignature) + public + onlyDelegatecall + returns (bytes4 worldFunctionSelector); ``` **Parameters** @@ -341,9 +342,9 @@ _Creates a mapping for a root World function without namespace or name prefix_ ```solidity function registerRootFunctionSelector( - ResourceId systemId, - string memory worldFunctionSignature, - bytes4 systemFunctionSelector + ResourceId systemId, + string memory worldFunctionSignature, + bytes4 systemFunctionSelector ) public onlyDelegatecall returns (bytes4 worldFunctionSelector); ``` @@ -368,11 +369,9 @@ Registers a delegation for the caller _Creates a new delegation from the caller to the specified delegatee_ ```solidity -function registerDelegation( - address delegatee, - ResourceId delegationControlId, - bytes memory initCallData -) public onlyDelegatecall; +function registerDelegation(address delegatee, ResourceId delegationControlId, bytes memory initCallData) + public + onlyDelegatecall; ``` **Parameters** @@ -406,11 +405,9 @@ Registers a delegation for a namespace _Sets up a new delegation control for a specific namespace_ ```solidity -function registerNamespaceDelegation( - ResourceId namespaceId, - ResourceId delegationControlId, - bytes memory initCallData -) public onlyDelegatecall; +function registerNamespaceDelegation(ResourceId namespaceId, ResourceId delegationControlId, bytes memory initCallData) + public + onlyDelegatecall; ``` **Parameters** @@ -549,11 +546,10 @@ Call the system at the given system ID on behalf of the given delegator. _If the system is not public, the delegator must have access to the namespace or name (encoded in the system ID)._ ```solidity -function callFrom( - address delegator, - ResourceId systemId, - bytes memory callData -) external payable returns (bytes memory); +function callFrom(address delegator, ResourceId systemId, bytes memory callData) + external + payable + returns (bytes memory); ``` **Parameters** diff --git a/docs/pages/world/reference/world.mdx b/docs/pages/world/reference/world.mdx index 6ac0c4f3fd..eabb61b7c6 100644 --- a/docs/pages/world/reference/world.mdx +++ b/docs/pages/world/reference/world.mdx @@ -93,11 +93,11 @@ _Requires the caller to have access to the table's namespace or name (encoded in ```solidity function setRecord( - ResourceId tableId, - bytes32[] calldata keyTuple, - bytes calldata staticData, - PackedCounter encodedLengths, - bytes calldata dynamicData + ResourceId tableId, + bytes32[] calldata keyTuple, + bytes calldata staticData, + PackedCounter encodedLengths, + bytes calldata dynamicData ) public virtual prohibitDirectCallback; ``` @@ -116,12 +116,10 @@ function setRecord( Modifies static (fixed length) data in a record at the specified position. ```solidity -function spliceStaticData( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint48 start, - bytes calldata data -) public virtual prohibitDirectCallback; +function spliceStaticData(ResourceId tableId, bytes32[] calldata keyTuple, uint48 start, bytes calldata data) + public + virtual + prohibitDirectCallback; ``` **Parameters** @@ -139,12 +137,12 @@ Modifies dynamic (variable length) data in a record for a specified field. ```solidity function spliceDynamicData( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes calldata data + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes calldata data ) public virtual prohibitDirectCallback; ``` @@ -164,12 +162,10 @@ function spliceDynamicData( Writes data into a specified field in the table identified by `tableId`. ```solidity -function setField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data -) public virtual prohibitDirectCallback; +function setField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, bytes calldata data) + public + virtual + prohibitDirectCallback; ``` **Parameters** @@ -187,11 +183,11 @@ Writes data into a specified field in the table, adhering to a specific layout. ```solidity function setField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data, + FieldLayout fieldLayout ) public virtual prohibitDirectCallback; ``` @@ -213,11 +209,11 @@ _Requires the caller to have access to the table's namespace or name (encoded in ```solidity function setStaticField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data, + FieldLayout fieldLayout ) public virtual prohibitDirectCallback; ``` @@ -236,12 +232,10 @@ function setStaticField( Writes data into a dynamic (varible length) field in the table identified by `tableId`. ```solidity -function setDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - bytes calldata data -) public virtual prohibitDirectCallback; +function setDynamicField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 dynamicFieldIndex, bytes calldata data) + public + virtual + prohibitDirectCallback; ``` **Parameters** @@ -259,10 +253,10 @@ Appends data to the end of a dynamic (variable length) field in the table identi ```solidity function pushToDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - bytes calldata dataToPush + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + bytes calldata dataToPush ) public virtual prohibitDirectCallback; ``` @@ -281,10 +275,10 @@ Removes a specified amount of data from the end of a dynamic (variable length) f ```solidity function popFromDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - uint256 byteLengthToPop + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + uint256 byteLengthToPop ) public virtual prohibitDirectCallback; ``` @@ -323,10 +317,12 @@ Calls a system with a given system ID. _If system is private, caller must have appropriate access._ ```solidity -function call( - ResourceId systemId, - bytes memory callData -) external payable virtual prohibitDirectCallback returns (bytes memory); +function call(ResourceId systemId, bytes memory callData) + external + payable + virtual + prohibitDirectCallback + returns (bytes memory); ``` **Parameters** @@ -349,11 +345,12 @@ Calls a system with a given system ID on behalf of the given delegator. _If system is private, caller must have appropriate access._ ```solidity -function callFrom( - address delegator, - ResourceId systemId, - bytes memory callData -) external payable virtual prohibitDirectCallback returns (bytes memory); +function callFrom(address delegator, ResourceId systemId, bytes memory callData) + external + payable + virtual + prohibitDirectCallback + returns (bytes memory); ``` **Parameters** diff --git a/e2e/packages/contracts/src/codegen/world/IWorld.sol b/e2e/packages/contracts/src/codegen/world/IWorld.sol index 6865aa9033..ccc2a5f90e 100644 --- a/e2e/packages/contracts/src/codegen/world/IWorld.sol +++ b/e2e/packages/contracts/src/codegen/world/IWorld.sol @@ -16,6 +16,4 @@ import { IVectorSystem } from "./IVectorSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, ICustomErrorsSystem, INumberListSystem, INumberSystem, IVectorSystem { - -} +interface IWorld is IBaseWorld, ICustomErrorsSystem, INumberListSystem, INumberSystem, IVectorSystem {} diff --git a/examples/minimal/packages/contracts/package.json b/examples/minimal/packages/contracts/package.json index 1bd8b4276b..72f4f46204 100644 --- a/examples/minimal/packages/contracts/package.json +++ b/examples/minimal/packages/contracts/package.json @@ -28,7 +28,7 @@ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", "prettier": "^2.6.2", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "rimraf": "^3.0.2", "solhint": "^3.4.1", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", diff --git a/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol b/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol index 31f6c0439b..f5ec737542 100644 --- a/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol +++ b/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol @@ -16,6 +16,4 @@ import { IStructSystem } from "./IStructSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IChatSystem, IIncrementSystem, IInventorySystem, IStructSystem { - -} +interface IWorld is IBaseWorld, IChatSystem, IIncrementSystem, IInventorySystem, IStructSystem {} diff --git a/examples/multiple-accounts/packages/contracts/package.json b/examples/multiple-accounts/packages/contracts/package.json index 6b71970f9e..13c972596e 100644 --- a/examples/multiple-accounts/packages/contracts/package.json +++ b/examples/multiple-accounts/packages/contracts/package.json @@ -26,7 +26,7 @@ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", "prettier": "^2.6.2", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "2.0.0-next.15", "solhint-plugin-mud": "2.0.0-next.15" diff --git a/examples/multiple-accounts/packages/contracts/src/codegen/world/IWorld.sol b/examples/multiple-accounts/packages/contracts/src/codegen/world/IWorld.sol index a6f78a1166..5f3dd0f4e3 100644 --- a/examples/multiple-accounts/packages/contracts/src/codegen/world/IWorld.sol +++ b/examples/multiple-accounts/packages/contracts/src/codegen/world/IWorld.sol @@ -13,6 +13,4 @@ import { ILastCallSystem } from "./ILastCallSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, ILastCallSystem { - -} +interface IWorld is IBaseWorld, ILastCallSystem {} diff --git a/package.json b/package.json index 17c7bc3c33..2b29cd3c80 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "husky": ">=6", "lint-staged": ">=10", "prettier": "^2.8.4", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "rimraf": "^3.0.2", "turbo": "^1.9.3", "typescript": "5.1.6" diff --git a/packages/common/package.json b/packages/common/package.json index 216270c946..c0a19f8a27 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -60,7 +60,7 @@ "p-queue": "^7.4.1", "p-retry": "^5.1.2", "prettier": "^2.8.4", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "viem": "2.7.12" }, "devDependencies": { diff --git a/packages/world-modules/src/interfaces/IBaseWorld.sol b/packages/world-modules/src/interfaces/IBaseWorld.sol index 554767a8a4..47ac0bd2ee 100644 --- a/packages/world-modules/src/interfaces/IBaseWorld.sol +++ b/packages/world-modules/src/interfaces/IBaseWorld.sol @@ -12,6 +12,4 @@ import { IWorldKernel } from "@latticexyz/world/src/IWorldKernel.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IBaseWorld is IStore, IWorldKernel { - -} +interface IBaseWorld is IStore, IWorldKernel {} diff --git a/packages/world/src/codegen/interfaces/IBaseWorld.sol b/packages/world/src/codegen/interfaces/IBaseWorld.sol index 6026287465..02a41582b3 100644 --- a/packages/world/src/codegen/interfaces/IBaseWorld.sol +++ b/packages/world/src/codegen/interfaces/IBaseWorld.sol @@ -28,6 +28,4 @@ interface IBaseWorld is IModuleInstallationSystem, IWorldRegistrationSystem, IRegistrationSystem -{ - -} +{} diff --git a/packages/world/src/codegen/interfaces/IRegistrationSystem.sol b/packages/world/src/codegen/interfaces/IRegistrationSystem.sol index f14496a41b..e3b787d819 100644 --- a/packages/world/src/codegen/interfaces/IRegistrationSystem.sol +++ b/packages/world/src/codegen/interfaces/IRegistrationSystem.sol @@ -7,6 +7,4 @@ pragma solidity >=0.8.24; * @title IRegistrationSystem * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. */ -interface IRegistrationSystem { - -} +interface IRegistrationSystem {} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ccb001cd7d..f1498d25a2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,8 +42,8 @@ importers: specifier: ^2.8.4 version: 2.8.4 prettier-plugin-solidity: - specifier: 1.1.3 - version: 1.1.3(prettier@2.8.4) + specifier: 1.3.1 + version: 1.3.1(prettier@2.8.4) rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -285,8 +285,8 @@ importers: specifier: ^2.8.4 version: 2.8.4 prettier-plugin-solidity: - specifier: 1.1.3 - version: 1.1.3(prettier@2.8.4) + specifier: 1.3.1 + version: 1.3.1(prettier@2.8.4) viem: specifier: 2.7.12 version: 2.7.12(typescript@5.1.6)(zod@3.21.4) @@ -3306,6 +3306,10 @@ packages: resolution: {integrity: sha512-ESipEcHyRHg4Np4SqBCfcXwyxxna1DgFVz69bgpLV8vzl/NP1DtcKsJ4dJZXWQhY/Z4J2LeKBiOkOVZn9ct33Q==} dependencies: antlr4ts: 0.5.0-alpha.4 + dev: false + + /@solidity-parser/parser@0.17.0: + resolution: {integrity: sha512-Nko8R0/kUo391jsEHHxrGM07QFdnPGvlmox4rmH0kNiNAashItAilhy4Mv4pK5gQmW5f4sXAF58fwJbmlkGcVw==} /@testing-library/react-hooks@8.0.1(@types/react@18.2.22)(react-test-renderer@18.2.0)(react@18.2.0): resolution: {integrity: sha512-Aqhl2IVmLt8IovEVarNDFuJDVWVvhnr9/GCU6UUnrYXwgDFF9h2L2o2P9KBni1AST5sT6riAyoukFLyjQUgD/g==} @@ -9951,16 +9955,16 @@ packages: engines: {node: '>= 0.8.0'} dev: true - /prettier-plugin-solidity@1.1.3(prettier@2.8.4): - resolution: {integrity: sha512-fQ9yucPi2sBbA2U2Xjh6m4isUTJ7S7QLc/XDDsktqqxYfTwdYKJ0EnnywXHwCGAaYbQNK+HIYPL1OemxuMsgeg==} - engines: {node: '>=12'} + /prettier-plugin-solidity@1.3.1(prettier@2.8.4): + resolution: {integrity: sha512-MN4OP5I2gHAzHZG1wcuJl0FsLS3c4Cc5494bbg+6oQWBPuEamjwDvmGfFMZ6NFzsh3Efd9UUxeT7ImgjNH4ozA==} + engines: {node: '>=16'} peerDependencies: - prettier: '>=2.3.0 || >=3.0.0-alpha.0' + prettier: '>=2.3.0' dependencies: - '@solidity-parser/parser': 0.16.0 + '@solidity-parser/parser': 0.17.0 prettier: 2.8.4 - semver: 7.5.0 - solidity-comments-extractor: 0.0.7 + semver: 7.6.0 + solidity-comments-extractor: 0.0.8 /prettier@1.19.1: resolution: {integrity: sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==} @@ -10647,6 +10651,13 @@ packages: dependencies: lru-cache: 6.0.0 + /semver@7.6.0: + resolution: {integrity: sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==} + engines: {node: '>=10'} + hasBin: true + dependencies: + lru-cache: 6.0.0 + /serialize-javascript@6.0.0: resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==} dependencies: @@ -10838,8 +10849,8 @@ packages: - supports-color dev: true - /solidity-comments-extractor@0.0.7: - resolution: {integrity: sha512-wciNMLg/Irp8OKGrh3S2tfvZiZ0NEyILfcRCXCD4mp7SgK/i9gzLfhY2hY7VMCQJ3kH9UB9BzNdibIVMchzyYw==} + /solidity-comments-extractor@0.0.8: + resolution: {integrity: sha512-htM7Vn6LhHreR+EglVMd2s+sZhcXAirB1Zlyrv5zBuTxieCvjfnRpd7iZk75m/u6NOlEyQ94C6TWbBn2cY7w8g==} /sonic-boom@3.3.0: resolution: {integrity: sha512-LYxp34KlZ1a2Jb8ZQgFCK3niIHzibdwtwNUWKg0qQRzsDoJ3Gfgkf8KdBTFU3SkejDEIlWwnSnpVdOZIhFMl/g==} diff --git a/templates/phaser/packages/contracts/package.json b/templates/phaser/packages/contracts/package.json index aa7c055744..a79cc0adbd 100644 --- a/templates/phaser/packages/contracts/package.json +++ b/templates/phaser/packages/contracts/package.json @@ -26,7 +26,7 @@ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", "prettier": "^2.6.2", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", "solhint-plugin-mud": "file:../../../../packages/solhint-plugin-mud" diff --git a/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol b/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol index 938ff3572a..5d3a316e04 100644 --- a/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol @@ -13,6 +13,4 @@ import { IIncrementSystem } from "./IIncrementSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IIncrementSystem { - -} +interface IWorld is IBaseWorld, IIncrementSystem {} diff --git a/templates/react-ecs/packages/contracts/package.json b/templates/react-ecs/packages/contracts/package.json index aa7c055744..a79cc0adbd 100644 --- a/templates/react-ecs/packages/contracts/package.json +++ b/templates/react-ecs/packages/contracts/package.json @@ -26,7 +26,7 @@ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", "prettier": "^2.6.2", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", "solhint-plugin-mud": "file:../../../../packages/solhint-plugin-mud" diff --git a/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol b/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol index 938ff3572a..5d3a316e04 100644 --- a/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol @@ -13,6 +13,4 @@ import { IIncrementSystem } from "./IIncrementSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IIncrementSystem { - -} +interface IWorld is IBaseWorld, IIncrementSystem {} diff --git a/templates/react/packages/contracts/package.json b/templates/react/packages/contracts/package.json index aa7c055744..a79cc0adbd 100644 --- a/templates/react/packages/contracts/package.json +++ b/templates/react/packages/contracts/package.json @@ -26,7 +26,7 @@ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", "prettier": "^2.6.2", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", "solhint-plugin-mud": "file:../../../../packages/solhint-plugin-mud" diff --git a/templates/react/packages/contracts/src/codegen/world/IWorld.sol b/templates/react/packages/contracts/src/codegen/world/IWorld.sol index d3a48bdf1e..063b2733b4 100644 --- a/templates/react/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/react/packages/contracts/src/codegen/world/IWorld.sol @@ -13,6 +13,4 @@ import { ITasksSystem } from "./ITasksSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, ITasksSystem { - -} +interface IWorld is IBaseWorld, ITasksSystem {} diff --git a/templates/threejs/packages/contracts/package.json b/templates/threejs/packages/contracts/package.json index eaf3a8b0b8..551f5c90b5 100644 --- a/templates/threejs/packages/contracts/package.json +++ b/templates/threejs/packages/contracts/package.json @@ -25,7 +25,7 @@ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", "prettier": "^2.6.2", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", "solhint-plugin-mud": "file:../../../../packages/solhint-plugin-mud" diff --git a/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol b/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol index b9395b8273..ea308b6ac1 100644 --- a/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol @@ -13,6 +13,4 @@ import { IMoveSystem } from "./IMoveSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IMoveSystem { - -} +interface IWorld is IBaseWorld, IMoveSystem {} diff --git a/templates/vanilla/packages/contracts/package.json b/templates/vanilla/packages/contracts/package.json index aa7c055744..a79cc0adbd 100644 --- a/templates/vanilla/packages/contracts/package.json +++ b/templates/vanilla/packages/contracts/package.json @@ -26,7 +26,7 @@ "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", "prettier": "^2.6.2", - "prettier-plugin-solidity": "1.1.3", + "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", "solhint-plugin-mud": "file:../../../../packages/solhint-plugin-mud" diff --git a/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol b/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol index 938ff3572a..5d3a316e04 100644 --- a/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol @@ -13,6 +13,4 @@ import { IIncrementSystem } from "./IIncrementSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IIncrementSystem { - -} +interface IWorld is IBaseWorld, IIncrementSystem {} From f02657bc14a199c05af0bbd708965c24bd30e86b Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 23 Feb 2024 17:06:07 +0000 Subject: [PATCH 2/8] chore: upgrade prettier to 3.2.5 --- .changeset/nasty-waves-divide.md | 4 +- .changeset/tame-lemons-play.md | 2 +- CHANGELOG.md | 6 +- docs/app/page.tsx | 2 +- docs/components/MUDTable.module.css | 10 +- docs/pages/changelog.mdx | 6 +- .../emojimon/3-players-and-movement.mdx | 2 +- .../guides/emojimon/4-map-and-terrain.mdx | 2 +- .../emojimon/5-a-wild-emojimon-appears.mdx | 4 +- docs/pages/guides/hello-world/add-table.mdx | 2 +- docs/pages/store/reference/misc.mdx | 28 +- docs/pages/store/reference/store-core.mdx | 520 ++++++++++-------- docs/pages/store/reference/store-hook.mdx | 68 ++- docs/pages/store/reference/store.mdx | 194 ++++--- .../world/reference/internal/delegation.mdx | 19 +- .../internal/init-module-implementation.mdx | 90 +-- .../world/reference/internal/init-module.mdx | 38 +- .../world/reference/internal/systemcall.mdx | 27 +- docs/pages/world/reference/misc.mdx | 20 +- docs/pages/world/reference/module.mdx | 9 +- docs/pages/world/reference/world-context.mdx | 41 +- docs/pages/world/reference/world-external.mdx | 90 +-- docs/pages/world/reference/world.mdx | 109 ++-- docs/src/tailwindcss-plugins/animate.ts | 14 +- e2e/packages/client-vanilla/src/index.ts | 2 +- e2e/packages/contracts/package.json | 2 +- .../sync-test/compare/compare.test.ts | 4 +- .../sync-test/data/callPageFunction.ts | 2 +- e2e/packages/sync-test/data/callWorld.ts | 2 +- e2e/packages/sync-test/data/types.ts | 7 +- e2e/packages/sync-test/indexerSync.test.ts | 2 +- .../setup/openClientWithRootAccount.ts | 2 +- .../sync-test/setup/startBrowserAndPage.ts | 2 +- .../test-data/generate-bench-data-bulk.ts | 2 +- .../test-data/generate-bench-data-query.ts | 2 +- e2e/packages/test-data/generateLogs.ts | 4 +- .../src/mud/createSystemCalls.ts | 2 +- .../packages/client-phaser/src/ui/App.tsx | 2 +- .../src/ui/hooks/usePhaserLayer.tsx | 2 +- .../packages/client-react/src/index.tsx | 2 +- .../client-react/src/mud/createSystemCalls.ts | 2 +- .../minimal/packages/contracts/package.json | 2 +- .../packages/client/src/index.tsx | 2 +- .../packages/contracts/package.json | 2 +- package.json | 2 +- packages/abi-ts/src/abi-ts.ts | 2 +- packages/block-logs-stream/CHANGELOG.md | 4 +- packages/block-logs-stream/README.md | 2 +- .../src/blockRangeToLogs.test.ts | 2 +- .../block-logs-stream/src/blockRangeToLogs.ts | 6 +- .../block-logs-stream/src/fetchLogs.test.ts | 4 +- .../src/groupLogsByBlockNumber.ts | 2 +- packages/cli/CHANGELOG.md | 2 +- packages/cli/src/commands/dev-contracts.ts | 2 +- packages/cli/src/commands/set-version.ts | 2 +- packages/cli/src/commands/trace.ts | 2 +- packages/cli/src/deploy/configToTables.ts | 6 +- packages/cli/src/deploy/deployWorld.ts | 2 +- packages/cli/src/deploy/ensureContract.ts | 6 +- packages/cli/src/deploy/ensureFunctions.ts | 8 +- packages/cli/src/deploy/ensureModules.ts | 6 +- .../cli/src/deploy/ensureNamespaceOwner.ts | 8 +- packages/cli/src/deploy/ensureSystems.ts | 32 +- packages/cli/src/deploy/ensureTables.ts | 6 +- packages/cli/src/deploy/ensureWorldFactory.ts | 6 +- packages/cli/src/deploy/getFunctions.ts | 2 +- packages/cli/src/deploy/getResourceAccess.ts | 4 +- packages/cli/src/deploy/getSystems.ts | 2 +- packages/cli/src/deploy/getTables.ts | 2 +- packages/cli/src/deploy/logsToWorldDeploy.ts | 2 +- packages/cli/src/deploy/resolveConfig.ts | 12 +- packages/cli/src/mud.ts | 2 +- packages/cli/src/runDeploy.ts | 8 +- packages/cli/src/utils/printMUD.ts | 2 +- .../cli/src/utils/utils/getContractData.ts | 2 +- packages/cli/src/utils/utils/postDeploy.ts | 4 +- packages/cli/tsup.config.ts | 2 +- packages/common/CHANGELOG.md | 2 +- packages/common/package.json | 2 +- .../codegen/render-solidity/common.test.ts | 20 +- .../src/codegen/render-solidity/common.ts | 14 +- .../codegen/render-solidity/renderEnums.ts | 2 +- .../render-solidity/renderTypeHelpers.ts | 4 +- .../src/codegen/utils/contractToInterface.ts | 2 +- .../src/codegen/utils/extractUserTypes.ts | 2 +- .../src/codegen/utils/formatAndWrite.ts | 2 +- .../src/codegen/utils/loadUserTypesFile.ts | 6 +- packages/common/src/foundry/index.ts | 2 +- packages/common/src/getContract.ts | 8 +- packages/common/src/hexToResource.ts | 2 +- packages/common/src/sendTransaction.ts | 8 +- packages/common/src/utils/groupBy.ts | 2 +- packages/common/src/utils/mapObject.ts | 4 +- packages/common/src/writeContract.ts | 8 +- .../config/src/library/dynamicResolution.ts | 2 +- packages/create-mud/CHANGELOG.md | 2 +- packages/dev-tools/src/App.tsx | 4 +- .../dev-tools/src/actions/WriteSummary.tsx | 6 +- .../dev-tools/src/actions/getTransaction.ts | 2 +- .../src/actions/getTransactionReceipt.ts | 2 +- .../src/actions/getTransactionResult.ts | 2 +- packages/dev-tools/src/mount.tsx | 4 +- .../dev-tools/src/recs/ComponentDataTable.tsx | 4 +- .../dev-tools/src/recs/ComponentsPage.tsx | 2 +- packages/dev-tools/src/router.tsx | 4 +- .../dev-tools/src/summary/SummaryPage.tsx | 2 +- packages/dev-tools/src/zustand/TablesPage.tsx | 2 +- packages/dev-tools/src/zustand/useRecords.ts | 2 +- packages/faucet/bin/parseEnv.ts | 2 +- packages/faucet/src/createAppRouter.ts | 2 +- packages/gas-report/ts/gas-report.ts | 2 +- packages/noise/assembly/perlin.ts | 6 +- packages/noise/test/hardhat/keccak.spec.ts | 2 +- packages/phaserx/src/createCamera.ts | 6 +- packages/phaserx/src/createChunks.ts | 6 +- packages/phaserx/src/createCulling.ts | 4 +- packages/phaserx/src/createDebugger.ts | 8 +- packages/phaserx/src/createEmbodiedEntity.ts | 8 +- packages/phaserx/src/createInput.ts | 26 +- packages/phaserx/src/createObjectPool.ts | 2 +- packages/phaserx/src/guards.ts | 8 +- .../src/tilemap/createAnimatedTilemap.ts | 2 +- .../src/tilemap/createChunkedTilemap.ts | 8 +- .../src/tilemap/createVirtualTilemap.ts | 2 +- packages/phaserx/src/types.ts | 4 +- packages/phaserx/src/utils/chunks.ts | 2 +- packages/phaserx/src/utils/coords.ts | 4 +- packages/phaserx/src/utils/generateFrames.ts | 2 +- .../src/decodeDynamicField.test.ts | 52 +- .../protocol-parser/src/decodeDynamicField.ts | 2 +- packages/protocol-parser/src/decodeField.ts | 2 +- packages/protocol-parser/src/decodeKey.ts | 4 +- .../src/decodeKeyTuple.test.ts | 6 +- .../protocol-parser/src/decodeKeyTuple.ts | 4 +- .../protocol-parser/src/decodeRecord.test.ts | 2 +- packages/protocol-parser/src/decodeRecord.ts | 4 +- .../src/decodeStaticField.test.ts | 32 +- .../protocol-parser/src/decodeStaticField.ts | 2 +- packages/protocol-parser/src/decodeValue.ts | 2 +- .../protocol-parser/src/decodeValueArgs.ts | 4 +- packages/protocol-parser/src/encodeField.ts | 4 +- .../src/encodeKeyTuple.test.ts | 6 +- .../protocol-parser/src/encodeLengths.test.ts | 4 +- packages/protocol-parser/src/encodeLengths.ts | 2 +- .../protocol-parser/src/encodeRecord.test.ts | 2 +- packages/protocol-parser/src/encodeRecord.ts | 4 +- packages/protocol-parser/src/encodeValue.ts | 2 +- .../protocol-parser/src/encodeValueArgs.ts | 4 +- packages/protocol-parser/src/errors.ts | 8 +- .../src/hexToPackedCounter.test.ts | 6 +- .../protocol-parser/src/hexToSchema.test.ts | 4 +- packages/protocol-parser/src/hexToSchema.ts | 2 +- .../protocol-parser/src/schemaToHex.test.ts | 6 +- packages/react/src/useComponentValue.ts | 6 +- packages/react/src/useEntityQuery.test.ts | 4 +- packages/react/src/usePromise.ts | 2 +- packages/recs/CHANGELOG.md | 2 +- packages/recs/src/Component.ts | 34 +- packages/recs/src/Entity.ts | 2 +- packages/recs/src/Indexer.ts | 2 +- packages/recs/src/Query.spec.ts | 58 +- packages/recs/src/Query.ts | 22 +- packages/recs/src/System.spec.ts | 8 +- packages/recs/src/System.ts | 14 +- .../src/deprecated/createActionSystem.spec.ts | 2 +- .../recs/src/deprecated/createActionSystem.ts | 6 +- .../src/deprecated/defineActionComponent.ts | 2 +- .../src/deprecated/waitForActionCompletion.ts | 2 +- .../src/deprecated/waitForComponentValueIn.ts | 6 +- packages/recs/src/utils.ts | 4 +- .../src/typescript/arrayAbiTypes.ts | 2 +- .../mappings/AbiTypeToPrimitiveType.ts | 4 +- .../mappings/AbiTypeToSchemaType.ts | 2 +- .../deprecated/types/StaticAbiTypes.ts | 2 +- .../src/typescript/schemaAbiTypes.test.ts | 2 +- packages/schema-type/src/typescript/utils.ts | 35 +- .../services/protobuf/ts/faucet/faucet.ts | 38 +- .../services/ts/faucet/createFaucetService.ts | 2 +- .../src/rules/NoMsgSender.ts | 2 +- .../src/rules/SystemFileName.ts | 2 +- packages/store-indexer/CHANGELOG.md | 2 +- packages/store-indexer/bin/parseEnv.ts | 2 +- .../bin/postgres-decoded-indexer.ts | 13 +- .../store-indexer/bin/postgres-frontend.ts | 6 +- .../store-indexer/bin/postgres-indexer.ts | 13 +- packages/store-indexer/bin/sqlite-indexer.ts | 15 +- .../src/koa-middleware/sentry.ts | 4 +- .../store-indexer/src/postgres/apiRoutes.ts | 4 +- .../src/postgres/deprecated/getLogs.ts | 12 +- .../store-indexer/src/postgres/queryLogs.ts | 10 +- .../store-indexer/src/postgres/recordToLog.ts | 2 +- .../src/sqlite/getTablesWithRecords.ts | 6 +- packages/store-sync/src/common.ts | 2 +- packages/store-sync/src/createStoreSync.ts | 18 +- packages/store-sync/src/flattenSchema.ts | 2 +- packages/store-sync/src/getSnapshot.ts | 2 +- .../store-sync/src/indexer-client/input.ts | 2 +- .../store-sync/src/isTableRegistrationLog.ts | 2 +- packages/store-sync/src/logToTable.test.ts | 2 +- packages/store-sync/src/logToTable.ts | 2 +- .../src/postgres-decoded/buildTable.test.ts | 4 +- .../src/postgres-decoded/buildTable.ts | 4 +- .../createStorageAdapter.test.ts | 8 +- .../postgres-decoded/createStorageAdapter.ts | 8 +- .../src/postgres-decoded/getTables.ts | 8 +- .../src/postgres/createStorageAdapter.test.ts | 8 +- .../src/postgres/createStorageAdapter.ts | 12 +- .../store-sync/src/postgres/setupTables.ts | 4 +- packages/store-sync/src/postgres/tables.ts | 2 +- packages/store-sync/src/recs/decodeEntity.ts | 6 +- .../src/recs/defineInternalComponents.ts | 4 +- packages/store-sync/src/recs/encodeEntity.ts | 6 +- .../store-sync/src/recs/getTableEntity.ts | 2 +- .../store-sync/src/recs/isStoreComponent.ts | 2 +- .../store-sync/src/recs/recsStorage.test.ts | 8 +- packages/store-sync/src/recs/recsStorage.ts | 12 +- .../store-sync/src/recs/tableToComponent.ts | 4 +- .../store-sync/src/recs/tablesToComponents.ts | 2 +- packages/store-sync/src/schemaToDefaults.ts | 2 +- packages/store-sync/src/sqlite/buildTable.ts | 4 +- packages/store-sync/src/sqlite/getTables.ts | 6 +- .../src/sqlite/sqliteStorage.test.ts | 6 +- .../store-sync/src/sqlite/sqliteStorage.ts | 14 +- .../src/sqlite/sqliteTableToSql.test.ts | 6 +- packages/store-sync/src/tableToLog.test.ts | 2 +- .../store-sync/src/tablesWithRecordsToLogs.ts | 4 +- .../src/zustand/createStorageAdapter.test.ts | 2 +- .../src/zustand/createStorageAdapter.ts | 2 +- .../store-sync/src/zustand/createStore.ts | 10 +- packages/store-sync/src/zustand/getId.test.ts | 4 +- .../store-sync/src/zustand/logToTable.test.ts | 2 +- packages/store-sync/src/zustand/logToTable.ts | 2 +- .../store-sync/src/zustand/syncToZustand.ts | 2 +- packages/store-sync/test/logsToBlocks.ts | 4 +- packages/store/ts/codegen/field.ts | 80 +-- packages/store/ts/codegen/record.ts | 26 +- .../ts/codegen/renderFieldLayout.test.ts | 10 +- packages/store/ts/codegen/renderTable.ts | 12 +- packages/store/ts/codegen/tableOptions.ts | 2 +- packages/store/ts/codegen/tablegen.ts | 4 +- .../codegen/tightcoder/renderDecodeSlice.ts | 2 +- .../codegen/tightcoder/renderEncodeArray.ts | 2 +- packages/store/ts/codegen/userType.ts | 6 +- packages/store/ts/common.ts | 12 +- .../experimental/resolveConfig.test-d.ts | 2 +- .../config/experimental/resolveConfig.test.ts | 4 +- .../ts/config/experimental/resolveConfig.ts | 46 +- packages/store/ts/config/storeConfig.ts | 100 ++-- packages/store/ts/register/mudConfig.ts | 2 +- .../store/ts/scripts/generate-tightcoder.ts | 2 +- packages/store/ts/storeEvents.test.ts | 2 +- packages/utils/src/bytes.ts | 2 +- packages/utils/src/cubic.ts | 10 +- packages/utils/src/mobx.ts | 2 +- packages/utils/src/objects.ts | 2 +- packages/utils/src/promise.ts | 2 +- packages/utils/src/proxy.ts | 6 +- packages/utils/src/rx.ts | 10 +- packages/utils/src/types.ts | 12 +- .../world/ts/config/resolveWorldConfig.ts | 2 +- packages/world/ts/config/types.ts | 45 +- packages/world/ts/config/worldConfig.ts | 2 +- packages/world/ts/encodeSystemCalls.ts | 2 +- packages/world/ts/encodeSystemCallsFrom.ts | 4 +- .../render-solidity/renderSystemInterface.ts | 2 +- .../world/ts/node/render-solidity/worldgen.ts | 4 +- packages/world/ts/worldEvents.test.ts | 2 +- pnpm-lock.yaml | 22 +- scripts/changelog.ts | 2 +- scripts/render-api-docs.ts | 8 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../phaser/packages/client/src/ui/App.tsx | 2 +- .../client/src/ui/hooks/usePhaserLayer.tsx | 2 +- .../phaser/packages/contracts/package.json | 2 +- .../react-ecs/packages/client/src/index.tsx | 2 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../react-ecs/packages/contracts/package.json | 2 +- templates/react/packages/client/src/index.tsx | 2 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../react/packages/contracts/package.json | 2 +- .../threejs/packages/client/src/index.tsx | 2 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../threejs/packages/contracts/package.json | 2 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../vanilla/packages/contracts/package.json | 2 +- 285 files changed, 1545 insertions(+), 1422 deletions(-) diff --git a/.changeset/nasty-waves-divide.md b/.changeset/nasty-waves-divide.md index f85dd96047..61ac31054c 100644 --- a/.changeset/nasty-waves-divide.md +++ b/.changeset/nasty-waves-divide.md @@ -22,7 +22,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest" const latestBlockNumber$ = latestBlock$.pipe( filter(isNonPendingBlock), - map((block) => block.number) + map((block) => block.number), ); latestBlockNumber$ @@ -38,7 +38,7 @@ latestBlockNumber$ "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/.changeset/tame-lemons-play.md b/.changeset/tame-lemons-play.md index e20f0bcd55..17de0f9339 100644 --- a/.changeset/tame-lemons-play.md +++ b/.changeset/tame-lemons-play.md @@ -172,7 +172,7 @@ As you migrate, you may find some features replaced, removed, or not included by .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3efbf55d..12d6a624bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3395,7 +3395,7 @@ As you migrate, you may find some features replaced, removed, or not included by .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` @@ -3633,7 +3633,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest" const latestBlockNumber$ = latestBlock$.pipe( filter(isNonPendingBlock), - map((block) => block.number) + map((block) => block.number), ); latestBlockNumber$ @@ -3649,7 +3649,7 @@ latestBlockNumber$ "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/docs/app/page.tsx b/docs/app/page.tsx index 7a954b39d5..bbb7c29d8c 100644 --- a/docs/app/page.tsx +++ b/docs/app/page.tsx @@ -24,7 +24,7 @@ export default async function HomePage() { "min-h-screen flex flex-col animate-in animate-duration-500 fade-in", "gap-12 p-8", "sm:justify-between", - "md:gap-16 md:p-16" + "md:gap-16 md:p-16", )} >
diff --git a/docs/components/MUDTable.module.css b/docs/components/MUDTable.module.css index becc677b84..97b6223686 100644 --- a/docs/components/MUDTable.module.css +++ b/docs/components/MUDTable.module.css @@ -1,5 +1,13 @@ .table { - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace; + font-family: + ui-monospace, + SFMono-Regular, + Menlo, + Monaco, + Consolas, + Liberation Mono, + Courier New, + monospace; background-color: hsl(var(--nextra-primary-hue) 100% 66%/0.1); margin-top: 1em; text-align: center; diff --git a/docs/pages/changelog.mdx b/docs/pages/changelog.mdx index 9e3efbf55d..12d6a624bf 100644 --- a/docs/pages/changelog.mdx +++ b/docs/pages/changelog.mdx @@ -3395,7 +3395,7 @@ As you migrate, you may find some features replaced, removed, or not included by .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` @@ -3633,7 +3633,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest" const latestBlockNumber$ = latestBlock$.pipe( filter(isNonPendingBlock), - map((block) => block.number) + map((block) => block.number), ); latestBlockNumber$ @@ -3649,7 +3649,7 @@ latestBlockNumber$ "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/docs/pages/guides/emojimon/3-players-and-movement.mdx b/docs/pages/guides/emojimon/3-players-and-movement.mdx index d5eac88e95..cefe114200 100644 --- a/docs/pages/guides/emojimon/3-players-and-movement.mdx +++ b/docs/pages/guides/emojimon/3-players-and-movement.mdx @@ -255,7 +255,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { playerEntity, worldContract, waitForTransaction }: SetupNetworkResult, - { Player, Position }: ClientComponents + { Player, Position }: ClientComponents, ) { const moveBy = async (deltaX: number, deltaY: number) => { if (!playerEntity) { diff --git a/docs/pages/guides/emojimon/4-map-and-terrain.mdx b/docs/pages/guides/emojimon/4-map-and-terrain.mdx index 4e81e1584d..bbbc842494 100644 --- a/docs/pages/guides/emojimon/4-map-and-terrain.mdx +++ b/docs/pages/guides/emojimon/4-map-and-terrain.mdx @@ -445,7 +445,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { playerEntity, worldContract, waitForTransaction }: SetupNetworkResult, - { MapConfig, Obstruction, Player, Position }: ClientComponents + { MapConfig, Obstruction, Player, Position }: ClientComponents, ) { const isObstructed = (x: number, y: number) => { return runQuery([Has(Obstruction), HasValue(Position, { x, y })]).size > 0; diff --git a/docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx b/docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx index 7392e1f57e..b7522d7304 100644 --- a/docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx +++ b/docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx @@ -718,7 +718,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { playerEntity, worldContract, waitForTransaction }: SetupNetworkResult, - { Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents + { Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents, ) { const wrapPosition = (x: number, y: number) => { const mapConfig = getComponentValue(MapConfig, singletonEntity); @@ -890,7 +890,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { playerEntity, worldContract, waitForTransaction }: SetupNetworkResult, - { Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents + { Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents, ) { const wrapPosition = (x: number, y: number) => { const mapConfig = getComponentValue(MapConfig, singletonEntity); diff --git a/docs/pages/guides/hello-world/add-table.mdx b/docs/pages/guides/hello-world/add-table.mdx index 0673138767..b1fa6dc4d6 100644 --- a/docs/pages/guides/hello-world/add-table.mdx +++ b/docs/pages/guides/hello-world/add-table.mdx @@ -261,7 +261,7 @@ This exclamation point tells the compiler that it's OK, there will be a real val ```html filename="index.html" copy showLineNumbers {12-17} - + diff --git a/docs/pages/store/reference/misc.mdx b/docs/pages/store/reference/misc.mdx index 7e883d5212..ae365f79b0 100644 --- a/docs/pages/store/reference/misc.mdx +++ b/docs/pages/store/reference/misc.mdx @@ -642,8 +642,11 @@ Filter a hook from the hook list by its address. _This function writes the updated hook list to the table in place._ ```solidity -function filterListByAddress(ResourceId hookTableId, ResourceId resourceWithHooks, address hookAddressToRemove) - internal; +function filterListByAddress( + ResourceId hookTableId, + ResourceId resourceWithHooks, + address hookAddressToRemove +) internal; ``` **Parameters** @@ -1551,8 +1554,14 @@ uint8 constant AFTER_DELETE_RECORD = 1 << 7; _Bitmap to enable all hooks._ ```solidity -uint8 constant ALL = BEFORE_SET_RECORD | AFTER_SET_RECORD | BEFORE_SPLICE_STATIC_DATA | AFTER_SPLICE_STATIC_DATA - | BEFORE_SPLICE_DYNAMIC_DATA | AFTER_SPLICE_DYNAMIC_DATA | BEFORE_DELETE_RECORD | AFTER_DELETE_RECORD; +uint8 constant ALL = BEFORE_SET_RECORD | + AFTER_SET_RECORD | + BEFORE_SPLICE_STATIC_DATA | + AFTER_SPLICE_STATIC_DATA | + BEFORE_SPLICE_DYNAMIC_DATA | + AFTER_SPLICE_DYNAMIC_DATA | + BEFORE_DELETE_RECORD | + AFTER_DELETE_RECORD; ``` #### BEFORE_ALL @@ -1560,8 +1569,10 @@ uint8 constant ALL = BEFORE_SET_RECORD | AFTER_SET_RECORD | BEFORE_SPLICE_STATIC _Bitmap to enable all "before" hooks._ ```solidity -uint8 constant BEFORE_ALL = - BEFORE_SET_RECORD | BEFORE_SPLICE_STATIC_DATA | BEFORE_SPLICE_DYNAMIC_DATA | BEFORE_DELETE_RECORD; +uint8 constant BEFORE_ALL = BEFORE_SET_RECORD | + BEFORE_SPLICE_STATIC_DATA | + BEFORE_SPLICE_DYNAMIC_DATA | + BEFORE_DELETE_RECORD; ``` #### AFTER_ALL @@ -1569,7 +1580,10 @@ uint8 constant BEFORE_ALL = _Bitmap to enable all "after" hooks._ ```solidity -uint8 constant AFTER_ALL = AFTER_SET_RECORD | AFTER_SPLICE_STATIC_DATA | AFTER_SPLICE_DYNAMIC_DATA | AFTER_DELETE_RECORD; +uint8 constant AFTER_ALL = AFTER_SET_RECORD | + AFTER_SPLICE_STATIC_DATA | + AFTER_SPLICE_DYNAMIC_DATA | + AFTER_DELETE_RECORD; ``` ## storeResourceTypes.sol constants diff --git a/docs/pages/store/reference/store-core.mdx b/docs/pages/store/reference/store-core.mdx index db49b80c31..354dac53b3 100644 --- a/docs/pages/store/reference/store-core.mdx +++ b/docs/pages/store/reference/store-core.mdx @@ -113,12 +113,12 @@ Register a new table with the given configuration. ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] memory keyNames, - string[] memory fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] memory keyNames, + string[] memory fieldNames ) internal; ``` @@ -179,11 +179,11 @@ If the field layout is available to the caller, it is recommended to use the oth ```solidity function setRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData ) internal; ``` @@ -208,12 +208,12 @@ event without calling hooks or modifying the state._ ```solidity function setRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData, + FieldLayout fieldLayout ) internal; ``` @@ -259,12 +259,12 @@ For offchain tables, it returns early after emitting the event._ ```solidity function spliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes memory data + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes memory data ) internal; ``` @@ -313,11 +313,11 @@ For offchain tables, it returns early after emitting the event._ ```solidity function setField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - bytes memory data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + bytes memory data, + FieldLayout fieldLayout ) internal; ``` @@ -341,11 +341,11 @@ For offchain tables, it returns early after emitting the event._ ```solidity function setStaticField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - bytes memory data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + bytes memory data, + FieldLayout fieldLayout ) internal; ``` @@ -368,8 +368,12 @@ _This method emits a `Store_SpliceDynamicData` event, updates the data in storag For offchain tables, it returns early after emitting the event._ ```solidity -function setDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex, bytes memory data) - internal; +function setDynamicField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + bytes memory data +) internal; ``` **Parameters** @@ -433,10 +437,10 @@ For offchain tables, it returns early after emitting the event._ ```solidity function pushToDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - bytes memory dataToPush + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + bytes memory dataToPush ) internal; ``` @@ -459,10 +463,10 @@ For offchain tables, it returns early after emitting the event._ ```solidity function popFromDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 byteLengthToPop + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 byteLengthToPop ) internal; ``` @@ -483,10 +487,10 @@ _This function internally calls another overload of `getRecord`, loading the fie If the field layout is available to the caller, it is recommended to use the other overload to avoid an additional storage read._ ```solidity -function getRecord(ResourceId tableId, bytes32[] memory keyTuple) - internal - view - returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord( + ResourceId tableId, + bytes32[] memory keyTuple +) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -509,10 +513,11 @@ function getRecord(ResourceId tableId, bytes32[] memory keyTuple) Get the full record (all fields, static and dynamic data) for the given table ID and key tuple, with the given field layout. ```solidity -function getRecord(ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout) - internal - view - returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord( + ResourceId tableId, + bytes32[] memory keyTuple, + FieldLayout fieldLayout +) internal view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -538,10 +543,7 @@ Get a single field from the given table ID and key tuple. _This function internally calls another overload of `getField`, loading the field layout from storage._ ```solidity -function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) - internal - view - returns (bytes memory); +function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) internal view returns (bytes memory); ``` **Parameters** @@ -563,10 +565,12 @@ function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldInde Get a single field from the given table ID and key tuple, with the given field layout. ```solidity -function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - internal - view - returns (bytes memory); +function getField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) internal view returns (bytes memory); ``` **Parameters** @@ -592,10 +596,12 @@ _The field value is left-aligned in the returned bytes32, the rest of the word i Consumers are expected to truncate the returned value as needed._ ```solidity -function getStaticField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - internal - view - returns (bytes32); +function getStaticField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) internal view returns (bytes32); ``` **Parameters** @@ -618,10 +624,11 @@ function getStaticField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie Get a single dynamic field from the given table ID and key tuple. ```solidity -function getDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) - internal - view - returns (bytes memory); +function getDynamicField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex +) internal view returns (bytes memory); ``` **Parameters** @@ -646,10 +653,11 @@ _This function internally calls another overload of `getFieldLength`, loading th If the field layout is available to the caller, it is recommended to use the other overload to avoid an additional storage read._ ```solidity -function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) - internal - view - returns (uint256); +function getFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex +) internal view returns (uint256); ``` **Parameters** @@ -671,10 +679,12 @@ function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie Get the byte length of a single field from the given table ID and key tuple. ```solidity -function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - internal - view - returns (uint256); +function getFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) internal view returns (uint256); ``` **Parameters** @@ -697,10 +707,11 @@ function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie Get the byte length of a single dynamic field from the given table ID and key tuple. ```solidity -function getDynamicFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) - internal - view - returns (uint256); +function getDynamicFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex +) internal view returns (uint256); ``` **Parameters** @@ -723,11 +734,11 @@ Get a byte slice (including start, excluding end) of a single dynamic field from ```solidity function getDynamicFieldSlice( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 start, - uint256 end + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 start, + uint256 end ) internal view returns (bytes memory); ``` @@ -755,7 +766,11 @@ Emitted when a new record is set in the store. ```solidity event Store_SetRecord( - ResourceId indexed tableId, bytes32[] keyTuple, bytes staticData, PackedCounter encodedLengths, bytes dynamicData + ResourceId indexed tableId, + bytes32[] keyTuple, + bytes staticData, + PackedCounter encodedLengths, + bytes dynamicData ); ``` @@ -795,13 +810,13 @@ Emitted when dynamic data in the store is spliced. ```solidity event Store_SpliceDynamicData( - ResourceId indexed tableId, - bytes32[] keyTuple, - uint8 dynamicFieldIndex, - uint48 start, - uint40 deleteCount, - PackedCounter encodedLengths, - bytes data + ResourceId indexed tableId, + bytes32[] keyTuple, + uint8 dynamicFieldIndex, + uint48 start, + uint40 deleteCount, + PackedCounter encodedLengths, + bytes data ); ``` @@ -875,13 +890,13 @@ It reverts with `Store_IndexOutOfBounds` if the start index is larger than the p ```solidity function _spliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes memory data, - PackedCounter previousEncodedLengths + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes memory data, + PackedCounter previousEncodedLengths ) internal; ``` @@ -902,10 +917,11 @@ function _spliceDynamicData( Get full static data for the given table ID and key tuple, with the given length in bytes. ```solidity -function _getStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint256 length) - internal - view - returns (bytes memory); +function _getStaticData( + ResourceId tableId, + bytes32[] memory keyTuple, + uint256 length +) internal view returns (bytes memory); ``` **Parameters** @@ -927,10 +943,12 @@ function _getStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint256 l Get a single static field from the given table ID and key tuple, with the given value field layout. ```solidity -function _getStaticFieldBytes(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - internal - view - returns (bytes memory); +function _getStaticFieldBytes( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) internal view returns (bytes memory); ``` **Parameters** @@ -1016,10 +1034,11 @@ function _getStaticDataOffset(FieldLayout fieldLayout, uint8 fieldIndex) interna Compute the storage location based on table ID, key tuple, and dynamic field index. ```solidity -function _getDynamicDataLocation(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) - internal - pure - returns (uint256); +function _getDynamicDataLocation( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex +) internal pure returns (uint256); ``` **Parameters** @@ -1062,10 +1081,10 @@ function _getDynamicDataLengthLocation(ResourceId tableId, bytes32[] memory keyT Load the encoded dynamic data length from storage for the given table ID and key tuple. ```solidity -function _loadEncodedDynamicDataLength(ResourceId tableId, bytes32[] memory keyTuple) - internal - view - returns (PackedCounter); +function _loadEncodedDynamicDataLength( + ResourceId tableId, + bytes32[] memory keyTuple +) internal view returns (PackedCounter); ``` **Parameters** @@ -1195,11 +1214,10 @@ function getKeySchema(ResourceId tableId) public view virtual returns (Schema ke Fetches a record from a specified table using a provided key tuple. ```solidity -function getRecord(ResourceId tableId, bytes32[] calldata keyTuple) - public - view - virtual - returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord( + ResourceId tableId, + bytes32[] calldata keyTuple +) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -1222,11 +1240,11 @@ function getRecord(ResourceId tableId, bytes32[] calldata keyTuple) Fetches a record from a specified table using a provided key tuple and field layout. ```solidity -function getRecord(ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout) - public - view - virtual - returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord( + ResourceId tableId, + bytes32[] calldata keyTuple, + FieldLayout fieldLayout +) public view virtual returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` **Parameters** @@ -1253,11 +1271,11 @@ _This overload loads the FieldLayout from storage. If the table's FieldLayout is to the caller, it should be passed in to the other overload to avoid the storage read._ ```solidity -function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex) - public - view - virtual - returns (bytes memory data); +function getField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex +) public view virtual returns (bytes memory data); ``` **Parameters** @@ -1279,11 +1297,12 @@ function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIn Retrieves data for a specified field in a record. ```solidity -function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - public - view - virtual - returns (bytes memory data); +function getField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) public view virtual returns (bytes memory data); ``` **Parameters** @@ -1306,11 +1325,12 @@ function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIn Retrieves data for a specific static (fixed length) field in a record. ```solidity -function getStaticField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - public - view - virtual - returns (bytes32 data); +function getStaticField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) public view virtual returns (bytes32 data); ``` **Parameters** @@ -1333,11 +1353,11 @@ function getStaticField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 f Retrieves data for a specific dynamic (variable length) field in a record. ```solidity -function getDynamicField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 dynamicFieldIndex) - public - view - virtual - returns (bytes memory data); +function getDynamicField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex +) public view virtual returns (bytes memory data); ``` **Parameters** @@ -1362,11 +1382,11 @@ _This overload loads the FieldLayout from storage. If the table's FieldLayout is to the caller, it should be passed in to the other overload to avoid the storage read._ ```solidity -function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) - public - view - virtual - returns (uint256); +function getFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex +) public view virtual returns (uint256); ``` **Parameters** @@ -1388,11 +1408,12 @@ function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie Calculates the length of a specified field in a record. ```solidity -function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - public - view - virtual - returns (uint256); +function getFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) public view virtual returns (uint256); ``` **Parameters** @@ -1415,11 +1436,11 @@ function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie Calculates the length of a specified dynamic (variable length) field in a record. ```solidity -function getDynamicFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) - public - view - virtual - returns (uint256); +function getDynamicFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex +) public view virtual returns (uint256); ``` **Parameters** @@ -1442,11 +1463,11 @@ Retrieves a slice of a dynamic (variable length) field. ```solidity function getDynamicFieldSlice( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 start, - uint256 end + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 start, + uint256 end ) public view virtual returns (bytes memory); ``` @@ -1632,12 +1653,12 @@ _Registers a table with specified configurations._ ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] memory keyNames, - string[] memory fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] memory keyNames, + string[] memory fieldNames ) internal; ``` @@ -1658,11 +1679,11 @@ _Sets a record in the store._ ```solidity function setRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData ) internal; ``` @@ -1699,12 +1720,12 @@ _Splices the dynamic data for a given table ID, key tuple, and dynamic field ind ```solidity function spliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes memory data + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes memory data ) internal; ``` @@ -1742,11 +1763,11 @@ _Sets the data for a specific field in a record, considering a specific field la ```solidity function setField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - bytes memory data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + bytes memory data, + FieldLayout fieldLayout ) internal; ``` @@ -1766,11 +1787,11 @@ _Sets the data for a specific static (fixed length) field in a record, consideri ```solidity function setStaticField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 fieldIndex, - bytes memory data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + bytes memory data, + FieldLayout fieldLayout ) internal; ``` @@ -1789,8 +1810,12 @@ function setStaticField( _Sets the value of a specific dynamic (variable-length) field in a record._ ```solidity -function setDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex, bytes memory data) - internal; +function setDynamicField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + bytes memory data +) internal; ``` **Parameters** @@ -1808,10 +1833,10 @@ _Appends data to a specific dynamic (variable length) field of a record._ ```solidity function pushToDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - bytes memory dataToPush + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + bytes memory dataToPush ) internal; ``` @@ -1830,10 +1855,10 @@ _Removes data from the end of a specific dynamic (variable length) field of a re ```solidity function popFromDynamicField( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 byteLengthToPop + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 byteLengthToPop ) internal; ``` @@ -1866,10 +1891,10 @@ function deleteRecord(ResourceId tableId, bytes32[] memory keyTuple) internal; _Retrieves a record from a table._ ```solidity -function getRecord(ResourceId tableId, bytes32[] memory keyTuple) - internal - view - returns (bytes memory, PackedCounter, bytes memory); +function getRecord( + ResourceId tableId, + bytes32[] memory keyTuple +) internal view returns (bytes memory, PackedCounter, bytes memory); ``` **Parameters** @@ -1892,10 +1917,11 @@ function getRecord(ResourceId tableId, bytes32[] memory keyTuple) _Retrieves a record from a table with a specific layout._ ```solidity -function getRecord(ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fieldLayout) - internal - view - returns (bytes memory, PackedCounter, bytes memory); +function getRecord( + ResourceId tableId, + bytes32[] memory keyTuple, + FieldLayout fieldLayout +) internal view returns (bytes memory, PackedCounter, bytes memory); ``` **Parameters** @@ -1919,10 +1945,7 @@ function getRecord(ResourceId tableId, bytes32[] memory keyTuple, FieldLayout fi _Retrieves a specific field from a record._ ```solidity -function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) - internal - view - returns (bytes memory); +function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) internal view returns (bytes memory); ``` **Parameters** @@ -1944,10 +1967,12 @@ function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldInde _Retrieves a specific field from a record with a given layout._ ```solidity -function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - internal - view - returns (bytes memory); +function getField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) internal view returns (bytes memory); ``` **Parameters** @@ -1970,10 +1995,12 @@ function getField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldInde _Retrieves a specific static (fixed length) field from a record with a given layout._ ```solidity -function getStaticField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - internal - view - returns (bytes32); +function getStaticField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) internal view returns (bytes32); ``` **Parameters** @@ -1996,10 +2023,11 @@ function getStaticField(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie _Retrieves a specific dynamic (variable length) field from a record._ ```solidity -function getDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) - internal - view - returns (bytes memory); +function getDynamicField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex +) internal view returns (bytes memory); ``` **Parameters** @@ -2021,10 +2049,11 @@ function getDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dy _Retrieves the length of a specific field in a record._ ```solidity -function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) - internal - view - returns (uint256); +function getFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex +) internal view returns (uint256); ``` **Parameters** @@ -2046,10 +2075,12 @@ function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie _Retrieves the length of a specific field in a record with a given layout._ ```solidity -function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - internal - view - returns (uint256); +function getFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) internal view returns (uint256); ``` **Parameters** @@ -2072,10 +2103,11 @@ function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie _Retrieves the length of a specific dynamic (variable length) field in a record._ ```solidity -function getDynamicFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) - internal - view - returns (uint256); +function getDynamicFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex +) internal view returns (uint256); ``` **Parameters** @@ -2098,11 +2130,11 @@ _Retrieves a slice of a dynamic (variable length) field from a record._ ```solidity function getDynamicFieldSlice( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 start, - uint256 end + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 start, + uint256 end ) internal view returns (bytes memory); ``` @@ -2130,6 +2162,6 @@ _Represents the layout of the storage slot (currently just the address)_ ```solidity struct StorageSlotLayout { - address storeAddress; + address storeAddress; } ``` diff --git a/docs/pages/store/reference/store-hook.mdx b/docs/pages/store/reference/store-hook.mdx index 50c1a8e048..bce6a9c9ca 100644 --- a/docs/pages/store/reference/store-hook.mdx +++ b/docs/pages/store/reference/store-hook.mdx @@ -15,12 +15,12 @@ Called before setting a record in the store. ```solidity function onBeforeSetRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData, + FieldLayout fieldLayout ) external; ``` @@ -41,12 +41,12 @@ Called after setting a record in the store. ```solidity function onAfterSetRecord( - ResourceId tableId, - bytes32[] memory keyTuple, - bytes memory staticData, - PackedCounter encodedLengths, - bytes memory dynamicData, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] memory keyTuple, + bytes memory staticData, + PackedCounter encodedLengths, + bytes memory dynamicData, + FieldLayout fieldLayout ) external; ``` @@ -69,8 +69,12 @@ _Splice operations in static data always overwrite data starting at the start po so the total length of the data remains the same and no data is shifted._ ```solidity -function onBeforeSpliceStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint48 start, bytes memory data) - external; +function onBeforeSpliceStaticData( + ResourceId tableId, + bytes32[] memory keyTuple, + uint48 start, + bytes memory data +) external; ``` **Parameters** @@ -90,8 +94,12 @@ _Splice operations in static data always overwrite data starting at the start po so the total length of the data remains the same and no data is shifted._ ```solidity -function onAfterSpliceStaticData(ResourceId tableId, bytes32[] memory keyTuple, uint48 start, bytes memory data) - external; +function onAfterSpliceStaticData( + ResourceId tableId, + bytes32[] memory keyTuple, + uint48 start, + bytes memory data +) external; ``` **Parameters** @@ -112,13 +120,13 @@ to avoid shifting data after the inserted or deleted data._ ```solidity function onBeforeSpliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - PackedCounter encodedLengths, - bytes memory data + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + PackedCounter encodedLengths, + bytes memory data ) external; ``` @@ -143,13 +151,13 @@ to avoid shifting data after the inserted or deleted data._ ```solidity function onAfterSpliceDynamicData( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - PackedCounter encodedLengths, - bytes memory data + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + PackedCounter encodedLengths, + bytes memory data ) external; ``` diff --git a/docs/pages/store/reference/store.mdx b/docs/pages/store/reference/store.mdx index 3fa899f267..eec99dc792 100644 --- a/docs/pages/store/reference/store.mdx +++ b/docs/pages/store/reference/store.mdx @@ -19,7 +19,11 @@ Emitted when a new record is set in the store. ```solidity event Store_SetRecord( - ResourceId indexed tableId, bytes32[] keyTuple, bytes staticData, PackedCounter encodedLengths, bytes dynamicData + ResourceId indexed tableId, + bytes32[] keyTuple, + bytes staticData, + PackedCounter encodedLengths, + bytes dynamicData ); ``` @@ -59,13 +63,13 @@ Emitted when dynamic data in the store is spliced. ```solidity event Store_SpliceDynamicData( - ResourceId indexed tableId, - bytes32[] keyTuple, - uint8 dynamicFieldIndex, - uint48 start, - uint40 deleteCount, - PackedCounter encodedLengths, - bytes data + ResourceId indexed tableId, + bytes32[] keyTuple, + uint8 dynamicFieldIndex, + uint48 start, + uint40 deleteCount, + PackedCounter encodedLengths, + bytes data ); ``` @@ -246,10 +250,10 @@ function getKeySchema(ResourceId tableId) external view returns (Schema keySchem Get full record (all fields, static and dynamic data) for the given tableId and key tuple, loading the field layout from storage ```solidity -function getRecord(ResourceId tableId, bytes32[] calldata keyTuple) - external - view - returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord( + ResourceId tableId, + bytes32[] calldata keyTuple +) external view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` #### getRecord @@ -257,10 +261,11 @@ function getRecord(ResourceId tableId, bytes32[] calldata keyTuple) Get full record (all fields, static and dynamic data) for the given tableId and key tuple, with the given field layout ```solidity -function getRecord(ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout fieldLayout) - external - view - returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); +function getRecord( + ResourceId tableId, + bytes32[] calldata keyTuple, + FieldLayout fieldLayout +) external view returns (bytes memory staticData, PackedCounter encodedLengths, bytes memory dynamicData); ``` #### getField @@ -268,10 +273,11 @@ function getRecord(ResourceId tableId, bytes32[] calldata keyTuple, FieldLayout Get a single field from the given tableId and key tuple, loading the field layout from storage ```solidity -function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex) - external - view - returns (bytes memory data); +function getField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex +) external view returns (bytes memory data); ``` #### getField @@ -279,10 +285,12 @@ function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIn Get a single field from the given tableId and key tuple, with the given field layout ```solidity -function getField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - external - view - returns (bytes memory data); +function getField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) external view returns (bytes memory data); ``` #### getStaticField @@ -292,10 +300,12 @@ Note: the field value is left-aligned in the returned bytes32, the rest of the w Consumers are expected to truncate the returned value as needed. ```solidity -function getStaticField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - external - view - returns (bytes32); +function getStaticField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) external view returns (bytes32); ``` #### getDynamicField @@ -304,10 +314,11 @@ Get a single dynamic field from the given tableId and key tuple at the given dyn (Dynamic field index = field index - number of static fields) ```solidity -function getDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) - external - view - returns (bytes memory); +function getDynamicField( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex +) external view returns (bytes memory); ``` #### getFieldLength @@ -315,10 +326,11 @@ function getDynamicField(ResourceId tableId, bytes32[] memory keyTuple, uint8 dy Get the byte length of a single field from the given tableId and key tuple, loading the field layout from storage ```solidity -function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex) - external - view - returns (uint256); +function getFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex +) external view returns (uint256); ``` #### getFieldLength @@ -326,10 +338,12 @@ function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie Get the byte length of a single field from the given tableId and key tuple, with the given value field layout ```solidity -function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fieldIndex, FieldLayout fieldLayout) - external - view - returns (uint256); +function getFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 fieldIndex, + FieldLayout fieldLayout +) external view returns (uint256); ``` #### getDynamicFieldLength @@ -337,10 +351,11 @@ function getFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 fie Get the byte length of a single dynamic field from the given tableId and key tuple ```solidity -function getDynamicFieldLength(ResourceId tableId, bytes32[] memory keyTuple, uint8 dynamicFieldIndex) - external - view - returns (uint256); +function getDynamicFieldLength( + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex +) external view returns (uint256); ``` #### getDynamicFieldSlice @@ -350,11 +365,11 @@ The slice is unchecked and will return invalid data if `start`:`end` overflow. ```solidity function getDynamicFieldSlice( - ResourceId tableId, - bytes32[] memory keyTuple, - uint8 dynamicFieldIndex, - uint256 start, - uint256 end + ResourceId tableId, + bytes32[] memory keyTuple, + uint8 dynamicFieldIndex, + uint256 start, + uint256 end ) external view returns (bytes memory data); ``` @@ -371,31 +386,30 @@ function getDynamicFieldSlice( ```solidity function setRecord( - ResourceId tableId, - bytes32[] calldata keyTuple, - bytes calldata staticData, - PackedCounter encodedLengths, - bytes calldata dynamicData + ResourceId tableId, + bytes32[] calldata keyTuple, + bytes calldata staticData, + PackedCounter encodedLengths, + bytes calldata dynamicData ) external; ``` #### spliceStaticData ```solidity -function spliceStaticData(ResourceId tableId, bytes32[] calldata keyTuple, uint48 start, bytes calldata data) - external; +function spliceStaticData(ResourceId tableId, bytes32[] calldata keyTuple, uint48 start, bytes calldata data) external; ``` #### spliceDynamicData ```solidity function spliceDynamicData( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes calldata data + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes calldata data ) external; ``` @@ -409,11 +423,11 @@ function setField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIn ```solidity function setField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data, + FieldLayout fieldLayout ) external; ``` @@ -421,29 +435,33 @@ function setField( ```solidity function setStaticField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data, + FieldLayout fieldLayout ) external; ``` #### setDynamicField ```solidity -function setDynamicField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 dynamicFieldIndex, bytes calldata data) - external; +function setDynamicField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + bytes calldata data +) external; ``` #### pushToDynamicField ```solidity function pushToDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - bytes calldata dataToPush + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + bytes calldata dataToPush ) external; ``` @@ -451,10 +469,10 @@ function pushToDynamicField( ```solidity function popFromDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - uint256 byteLengthToPop + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + uint256 byteLengthToPop ) external; ``` @@ -478,12 +496,12 @@ making them less performance critical than the methods. ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] calldata keyNames, - string[] calldata fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] calldata keyNames, + string[] calldata fieldNames ) external; ``` diff --git a/docs/pages/world/reference/internal/delegation.mdx b/docs/pages/world/reference/internal/delegation.mdx index 0600ace8fd..12831b861d 100644 --- a/docs/pages/world/reference/internal/delegation.mdx +++ b/docs/pages/world/reference/internal/delegation.mdx @@ -76,11 +76,11 @@ _Verifying the delegation might have side effects in the delegation control cont ```solidity function verify( - ResourceId delegationControlId, - address delegator, - address delegatee, - ResourceId systemId, - bytes memory callData + ResourceId delegationControlId, + address delegator, + address delegatee, + ResourceId systemId, + bytes memory callData ) internal returns (bool); ``` @@ -119,12 +119,9 @@ Check if the given interfaceId is supported by this contract. _Overrides the functionality from IERC165 and WorldContextConsumer to check for supported interfaces._ ```solidity -function supportsInterface(bytes4 interfaceId) - public - pure - virtual - override(IERC165, WorldContextConsumer) - returns (bool); +function supportsInterface( + bytes4 interfaceId +) public pure virtual override(IERC165, WorldContextConsumer) returns (bool); ``` **Parameters** diff --git a/docs/pages/world/reference/internal/init-module-implementation.mdx b/docs/pages/world/reference/internal/init-module-implementation.mdx index 1cc11c4410..6acb16654e 100644 --- a/docs/pages/world/reference/internal/init-module-implementation.mdx +++ b/docs/pages/world/reference/internal/init-module-implementation.mdx @@ -125,10 +125,11 @@ Transfer balance to another namespace in the World. _Requires the caller to have access to the source namespace and ensures the destination namespace type is valid._ ```solidity -function transferBalanceToNamespace(ResourceId fromNamespaceId, ResourceId toNamespaceId, uint256 amount) - public - virtual - onlyDelegatecall; +function transferBalanceToNamespace( + ResourceId fromNamespaceId, + ResourceId toNamespaceId, + uint256 amount +) public virtual onlyDelegatecall; ``` **Parameters** @@ -146,10 +147,11 @@ Transfer balance out of the World to a specific address. _Requires the caller to have access to the source namespace and ensures sufficient balance before transfer._ ```solidity -function transferBalanceToAddress(ResourceId fromNamespaceId, address toAddress, uint256 amount) - public - virtual - onlyDelegatecall; +function transferBalanceToAddress( + ResourceId fromNamespaceId, + address toAddress, + uint256 amount +) public virtual onlyDelegatecall; ``` **Parameters** @@ -180,12 +182,12 @@ Existing namespaces require the caller to be the owner for table registration._ ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] calldata keyNames, - string[] calldata fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] calldata keyNames, + string[] calldata fieldNames ) public virtual onlyDelegatecall; ``` @@ -208,10 +210,11 @@ _The caller must be the owner of the namespace to which the table belongs. The hook must conform to the IStoreHook interface._ ```solidity -function registerStoreHook(ResourceId tableId, IStoreHook hookAddress, uint8 enabledHooksBitmap) - public - virtual - onlyDelegatecall; +function registerStoreHook( + ResourceId tableId, + IStoreHook hookAddress, + uint8 enabledHooksBitmap +) public virtual onlyDelegatecall; ``` **Parameters** @@ -257,10 +260,7 @@ Make batch calls to multiple systems into a single transaction. _Iterates through an array of system calls, executes them, and returns an array of return data._ ```solidity -function batchCall(SystemCallData[] calldata systemCalls) - public - onlyDelegatecall - returns (bytes[] memory returnDatas); +function batchCall(SystemCallData[] calldata systemCalls) public onlyDelegatecall returns (bytes[] memory returnDatas); ``` **Parameters** @@ -282,10 +282,9 @@ Make batch calls from specific addresses to multiple systems in a single transac _Iterates through an array of system calls with specified 'from' addresses, executes them, and returns an array of return data._ ```solidity -function batchCallFrom(SystemCallFromData[] calldata systemCalls) - public - onlyDelegatecall - returns (bytes[] memory returnDatas); +function batchCallFrom( + SystemCallFromData[] calldata systemCalls +) public onlyDelegatecall returns (bytes[] memory returnDatas); ``` **Parameters** @@ -334,10 +333,11 @@ Registers a new system hook _Adds a new hook for the system at the provided system ID_ ```solidity -function registerSystemHook(ResourceId systemId, ISystemHook hookAddress, uint8 enabledHooksBitmap) - public - virtual - onlyDelegatecall; +function registerSystemHook( + ResourceId systemId, + ISystemHook hookAddress, + uint8 enabledHooksBitmap +) public virtual onlyDelegatecall; ``` **Parameters** @@ -396,10 +396,10 @@ Registers a new World function selector _Creates a mapping between a World function and its associated system function_ ```solidity -function registerFunctionSelector(ResourceId systemId, string memory systemFunctionSignature) - public - onlyDelegatecall - returns (bytes4 worldFunctionSelector); +function registerFunctionSelector( + ResourceId systemId, + string memory systemFunctionSignature +) public onlyDelegatecall returns (bytes4 worldFunctionSelector); ``` **Parameters** @@ -423,9 +423,9 @@ _Creates a mapping for a root World function without namespace or name prefix_ ```solidity function registerRootFunctionSelector( - ResourceId systemId, - string memory worldFunctionSignature, - bytes4 systemFunctionSelector + ResourceId systemId, + string memory worldFunctionSignature, + bytes4 systemFunctionSelector ) public onlyDelegatecall returns (bytes4 worldFunctionSelector); ``` @@ -450,9 +450,11 @@ Registers a delegation for the caller _Creates a new delegation from the caller to the specified delegatee_ ```solidity -function registerDelegation(address delegatee, ResourceId delegationControlId, bytes memory initCallData) - public - onlyDelegatecall; +function registerDelegation( + address delegatee, + ResourceId delegationControlId, + bytes memory initCallData +) public onlyDelegatecall; ``` **Parameters** @@ -486,9 +488,11 @@ Registers a delegation for a namespace _Sets up a new delegation control for a specific namespace_ ```solidity -function registerNamespaceDelegation(ResourceId namespaceId, ResourceId delegationControlId, bytes memory initCallData) - public - onlyDelegatecall; +function registerNamespaceDelegation( + ResourceId namespaceId, + ResourceId delegationControlId, + bytes memory initCallData +) public onlyDelegatecall; ``` **Parameters** diff --git a/docs/pages/world/reference/internal/init-module.mdx b/docs/pages/world/reference/internal/init-module.mdx index f17174eac7..c25be28ee8 100644 --- a/docs/pages/world/reference/internal/init-module.mdx +++ b/docs/pages/world/reference/internal/init-module.mdx @@ -43,10 +43,10 @@ address internal immutable registrationSystem; ```solidity constructor( - AccessManagementSystem _accessManagementSystem, - BalanceTransferSystem _balanceTransferSystem, - BatchCallSystem _batchCallSystem, - RegistrationSystem _registrationSystem + AccessManagementSystem _accessManagementSystem, + BalanceTransferSystem _balanceTransferSystem, + BatchCallSystem _batchCallSystem, + RegistrationSystem _registrationSystem ); ``` @@ -129,8 +129,9 @@ _Resource ID for access management system._ _This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name._ ```solidity -ResourceId constant ACCESS_MANAGEMENT_SYSTEM_ID = - ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("AccessManagement")))); +ResourceId constant ACCESS_MANAGEMENT_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("AccessManagement"))) +); ``` #### BALANCE_TRANSFER_SYSTEM_ID @@ -140,8 +141,9 @@ _Resource ID for balance transfer system._ _This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name._ ```solidity -ResourceId constant BALANCE_TRANSFER_SYSTEM_ID = - ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BalanceTransfer")))); +ResourceId constant BALANCE_TRANSFER_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BalanceTransfer"))) +); ``` #### BATCH_CALL_SYSTEM_ID @@ -151,8 +153,9 @@ _Resource ID for batch call system._ _This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name._ ```solidity -ResourceId constant BATCH_CALL_SYSTEM_ID = - ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BatchCall")))); +ResourceId constant BATCH_CALL_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("BatchCall"))) +); ``` #### REGISTRATION_SYSTEM_ID @@ -162,8 +165,9 @@ _Resource ID for core registration system._ _This ID is derived from the RESOURCE_SYSTEM type, the ROOT_NAMESPACE, and the system name._ ```solidity -ResourceId constant REGISTRATION_SYSTEM_ID = - ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("Registration")))); +ResourceId constant REGISTRATION_SYSTEM_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("Registration"))) +); ``` ## RegistrationSystem @@ -233,8 +237,8 @@ _Used to represent a call to a specific system identified by a ResourceId._ ```solidity struct SystemCallData { - ResourceId systemId; - bytes callData; + ResourceId systemId; + bytes callData; } ``` @@ -248,8 +252,8 @@ _Used to represent a call from a specific address to a specific system._ ```solidity struct SystemCallFromData { - address from; - ResourceId systemId; - bytes callData; + address from; + ResourceId systemId; + bytes callData; } ``` diff --git a/docs/pages/world/reference/internal/systemcall.mdx b/docs/pages/world/reference/internal/systemcall.mdx index 619082d31e..94b9579e7c 100644 --- a/docs/pages/world/reference/internal/systemcall.mdx +++ b/docs/pages/world/reference/internal/systemcall.mdx @@ -16,9 +16,12 @@ Calls a system identified by its Resource ID while ensuring necessary access con _This function does not revert if the system call fails. Instead, it returns a success flag._ ```solidity -function call(address caller, uint256 value, ResourceId systemId, bytes memory callData) - internal - returns (bool success, bytes memory data); +function call( + address caller, + uint256 value, + ResourceId systemId, + bytes memory callData +) internal returns (bool success, bytes memory data); ``` **Parameters** @@ -44,9 +47,12 @@ Calls a system identified by its Resource ID, ensuring access controls, and trig _This function does not revert if the system call fails. Instead, it returns a success flag._ ```solidity -function callWithHooks(address caller, ResourceId systemId, bytes memory callData, uint256 value) - internal - returns (bool success, bytes memory data); +function callWithHooks( + address caller, + ResourceId systemId, + bytes memory callData, + uint256 value +) internal returns (bool success, bytes memory data); ``` **Parameters** @@ -70,9 +76,12 @@ function callWithHooks(address caller, ResourceId systemId, bytes memory callDat Calls a system identified by its Resource ID, ensures access controls, triggers associated system hooks, and reverts on failure. ```solidity -function callWithHooksOrRevert(address caller, ResourceId systemId, bytes memory callData, uint256 value) - internal - returns (bytes memory data); +function callWithHooksOrRevert( + address caller, + ResourceId systemId, + bytes memory callData, + uint256 value +) internal returns (bytes memory data); ``` **Parameters** diff --git a/docs/pages/world/reference/misc.mdx b/docs/pages/world/reference/misc.mdx index f4642f30a1..b2ebefd27c 100644 --- a/docs/pages/world/reference/misc.mdx +++ b/docs/pages/world/reference/misc.mdx @@ -46,29 +46,33 @@ bytes16 constant ROOT_NAME = ""; #### STORE_NAMESPACE_ID ```solidity -ResourceId constant STORE_NAMESPACE_ID = - ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_NAMESPACE, bytes14("store"), ROOT_NAME))); +ResourceId constant STORE_NAMESPACE_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_NAMESPACE, bytes14("store"), ROOT_NAME)) +); ``` #### WORLD_NAMESPACE_ID ```solidity -ResourceId constant WORLD_NAMESPACE_ID = - ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_NAMESPACE, bytes14("world"), ROOT_NAME))); +ResourceId constant WORLD_NAMESPACE_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_NAMESPACE, bytes14("world"), ROOT_NAME)) +); ``` #### ROOT_NAMESPACE_ID ```solidity -ResourceId constant ROOT_NAMESPACE_ID = - ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_NAMESPACE, ROOT_NAMESPACE, ROOT_NAME))); +ResourceId constant ROOT_NAMESPACE_ID = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_NAMESPACE, ROOT_NAMESPACE, ROOT_NAME)) +); ``` #### UNLIMITED_DELEGATION ```solidity -ResourceId constant UNLIMITED_DELEGATION = - ResourceId.wrap(bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("unlimited")))); +ResourceId constant UNLIMITED_DELEGATION = ResourceId.wrap( + bytes32(abi.encodePacked(RESOURCE_SYSTEM, ROOT_NAMESPACE, bytes16("unlimited"))) +); ``` ## revertWithBytes diff --git a/docs/pages/world/reference/module.mdx b/docs/pages/world/reference/module.mdx index 190369a71e..6ebade08b3 100644 --- a/docs/pages/world/reference/module.mdx +++ b/docs/pages/world/reference/module.mdx @@ -26,12 +26,9 @@ Checks if the given interfaceId is supported by this contract. _Overrides the functionality from IERC165 and WorldContextConsumer to check for supported interfaces._ ```solidity -function supportsInterface(bytes4 interfaceId) - public - pure - virtual - override(IERC165, WorldContextConsumer) - returns (bool); +function supportsInterface( + bytes4 interfaceId +) public pure virtual override(IERC165, WorldContextConsumer) returns (bool); ``` **Parameters** diff --git a/docs/pages/world/reference/world-context.mdx b/docs/pages/world/reference/world-context.mdx index 4db4a9653f..514178c281 100644 --- a/docs/pages/world/reference/world-context.mdx +++ b/docs/pages/world/reference/world-context.mdx @@ -150,10 +150,7 @@ appending the context values (like msg.sender and msg.value) to the calldata for Appends context values to the given calldata. ```solidity -function appendContext(bytes memory callData, address msgSender, uint256 msgValue) - internal - pure - returns (bytes memory); +function appendContext(bytes memory callData, address msgSender, uint256 msgValue) internal pure returns (bytes memory); ``` **Parameters** @@ -175,9 +172,12 @@ function appendContext(bytes memory callData, address msgSender, uint256 msgValu Makes a call to the target contract with context values appended to the calldata. ```solidity -function callWithContext(address msgSender, uint256 msgValue, address target, bytes memory callData) - internal - returns (bool success, bytes memory data); +function callWithContext( + address msgSender, + uint256 msgValue, + address target, + bytes memory callData +) internal returns (bool success, bytes memory data); ``` **Parameters** @@ -201,9 +201,12 @@ function callWithContext(address msgSender, uint256 msgValue, address target, by Makes a delegatecall to the target contract with context values appended to the calldata. ```solidity -function delegatecallWithContext(address msgSender, uint256 msgValue, address target, bytes memory callData) - internal - returns (bool success, bytes memory data); +function delegatecallWithContext( + address msgSender, + uint256 msgValue, + address target, + bytes memory callData +) internal returns (bool success, bytes memory data); ``` **Parameters** @@ -229,9 +232,12 @@ Makes a call to the target contract with context values appended to the calldata _Revert in the case of failure._ ```solidity -function callWithContextOrRevert(address msgSender, uint256 msgValue, address target, bytes memory callData) - internal - returns (bytes memory data); +function callWithContextOrRevert( + address msgSender, + uint256 msgValue, + address target, + bytes memory callData +) internal returns (bytes memory data); ``` **Parameters** @@ -256,9 +262,12 @@ Makes a delegatecall to the target contract with context values appended to the _Revert in the case of failure._ ```solidity -function delegatecallWithContextOrRevert(address msgSender, uint256 msgValue, address target, bytes memory callData) - internal - returns (bytes memory data); +function delegatecallWithContextOrRevert( + address msgSender, + uint256 msgValue, + address target, + bytes memory callData +) internal returns (bytes memory data); ``` **Parameters** diff --git a/docs/pages/world/reference/world-external.mdx b/docs/pages/world/reference/world-external.mdx index 0a6b952da9..3a587a5f10 100644 --- a/docs/pages/world/reference/world-external.mdx +++ b/docs/pages/world/reference/world-external.mdx @@ -32,12 +32,12 @@ function storeVersion() public pure returns (bytes32); ```solidity function registerTable( - ResourceId tableId, - FieldLayout fieldLayout, - Schema keySchema, - Schema valueSchema, - string[] calldata keyNames, - string[] calldata fieldNames + ResourceId tableId, + FieldLayout fieldLayout, + Schema keySchema, + Schema valueSchema, + string[] calldata keyNames, + string[] calldata fieldNames ) external; ``` @@ -127,10 +127,11 @@ Transfer balance to another namespace in the World. _Requires the caller to have access to the source namespace and ensures the destination namespace type is valid._ ```solidity -function transferBalanceToNamespace(ResourceId fromNamespaceId, ResourceId toNamespaceId, uint256 amount) - public - virtual - onlyDelegatecall; +function transferBalanceToNamespace( + ResourceId fromNamespaceId, + ResourceId toNamespaceId, + uint256 amount +) public virtual onlyDelegatecall; ``` **Parameters** @@ -148,10 +149,11 @@ Transfer balance out of the World to a specific address. _Requires the caller to have access to the source namespace and ensures sufficient balance before transfer._ ```solidity -function transferBalanceToAddress(ResourceId fromNamespaceId, address toAddress, uint256 amount) - public - virtual - onlyDelegatecall; +function transferBalanceToAddress( + ResourceId fromNamespaceId, + address toAddress, + uint256 amount +) public virtual onlyDelegatecall; ``` **Parameters** @@ -169,10 +171,7 @@ Make batch calls to multiple systems into a single transaction. _Iterates through an array of system calls, executes them, and returns an array of return data._ ```solidity -function batchCall(SystemCallData[] calldata systemCalls) - public - onlyDelegatecall - returns (bytes[] memory returnDatas); +function batchCall(SystemCallData[] calldata systemCalls) public onlyDelegatecall returns (bytes[] memory returnDatas); ``` **Parameters** @@ -194,10 +193,9 @@ Make batch calls from specific addresses to multiple systems in a single transac _Iterates through an array of system calls with specified 'from' addresses, executes them, and returns an array of return data._ ```solidity -function batchCallFrom(SystemCallFromData[] calldata systemCalls) - public - onlyDelegatecall - returns (bytes[] memory returnDatas); +function batchCallFrom( + SystemCallFromData[] calldata systemCalls +) public onlyDelegatecall returns (bytes[] memory returnDatas); ``` **Parameters** @@ -253,10 +251,11 @@ Registers a new system hook _Adds a new hook for the system at the provided system ID_ ```solidity -function registerSystemHook(ResourceId systemId, ISystemHook hookAddress, uint8 enabledHooksBitmap) - public - virtual - onlyDelegatecall; +function registerSystemHook( + ResourceId systemId, + ISystemHook hookAddress, + uint8 enabledHooksBitmap +) public virtual onlyDelegatecall; ``` **Parameters** @@ -315,10 +314,10 @@ Registers a new World function selector _Creates a mapping between a World function and its associated system function_ ```solidity -function registerFunctionSelector(ResourceId systemId, string memory systemFunctionSignature) - public - onlyDelegatecall - returns (bytes4 worldFunctionSelector); +function registerFunctionSelector( + ResourceId systemId, + string memory systemFunctionSignature +) public onlyDelegatecall returns (bytes4 worldFunctionSelector); ``` **Parameters** @@ -342,9 +341,9 @@ _Creates a mapping for a root World function without namespace or name prefix_ ```solidity function registerRootFunctionSelector( - ResourceId systemId, - string memory worldFunctionSignature, - bytes4 systemFunctionSelector + ResourceId systemId, + string memory worldFunctionSignature, + bytes4 systemFunctionSelector ) public onlyDelegatecall returns (bytes4 worldFunctionSelector); ``` @@ -369,9 +368,11 @@ Registers a delegation for the caller _Creates a new delegation from the caller to the specified delegatee_ ```solidity -function registerDelegation(address delegatee, ResourceId delegationControlId, bytes memory initCallData) - public - onlyDelegatecall; +function registerDelegation( + address delegatee, + ResourceId delegationControlId, + bytes memory initCallData +) public onlyDelegatecall; ``` **Parameters** @@ -405,9 +406,11 @@ Registers a delegation for a namespace _Sets up a new delegation control for a specific namespace_ ```solidity -function registerNamespaceDelegation(ResourceId namespaceId, ResourceId delegationControlId, bytes memory initCallData) - public - onlyDelegatecall; +function registerNamespaceDelegation( + ResourceId namespaceId, + ResourceId delegationControlId, + bytes memory initCallData +) public onlyDelegatecall; ``` **Parameters** @@ -546,10 +549,11 @@ Call the system at the given system ID on behalf of the given delegator. _If the system is not public, the delegator must have access to the namespace or name (encoded in the system ID)._ ```solidity -function callFrom(address delegator, ResourceId systemId, bytes memory callData) - external - payable - returns (bytes memory); +function callFrom( + address delegator, + ResourceId systemId, + bytes memory callData +) external payable returns (bytes memory); ``` **Parameters** diff --git a/docs/pages/world/reference/world.mdx b/docs/pages/world/reference/world.mdx index eabb61b7c6..6ac0c4f3fd 100644 --- a/docs/pages/world/reference/world.mdx +++ b/docs/pages/world/reference/world.mdx @@ -93,11 +93,11 @@ _Requires the caller to have access to the table's namespace or name (encoded in ```solidity function setRecord( - ResourceId tableId, - bytes32[] calldata keyTuple, - bytes calldata staticData, - PackedCounter encodedLengths, - bytes calldata dynamicData + ResourceId tableId, + bytes32[] calldata keyTuple, + bytes calldata staticData, + PackedCounter encodedLengths, + bytes calldata dynamicData ) public virtual prohibitDirectCallback; ``` @@ -116,10 +116,12 @@ function setRecord( Modifies static (fixed length) data in a record at the specified position. ```solidity -function spliceStaticData(ResourceId tableId, bytes32[] calldata keyTuple, uint48 start, bytes calldata data) - public - virtual - prohibitDirectCallback; +function spliceStaticData( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint48 start, + bytes calldata data +) public virtual prohibitDirectCallback; ``` **Parameters** @@ -137,12 +139,12 @@ Modifies dynamic (variable length) data in a record for a specified field. ```solidity function spliceDynamicData( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - uint40 startWithinField, - uint40 deleteCount, - bytes calldata data + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + uint40 startWithinField, + uint40 deleteCount, + bytes calldata data ) public virtual prohibitDirectCallback; ``` @@ -162,10 +164,12 @@ function spliceDynamicData( Writes data into a specified field in the table identified by `tableId`. ```solidity -function setField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 fieldIndex, bytes calldata data) - public - virtual - prohibitDirectCallback; +function setField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data +) public virtual prohibitDirectCallback; ``` **Parameters** @@ -183,11 +187,11 @@ Writes data into a specified field in the table, adhering to a specific layout. ```solidity function setField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data, + FieldLayout fieldLayout ) public virtual prohibitDirectCallback; ``` @@ -209,11 +213,11 @@ _Requires the caller to have access to the table's namespace or name (encoded in ```solidity function setStaticField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 fieldIndex, - bytes calldata data, - FieldLayout fieldLayout + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 fieldIndex, + bytes calldata data, + FieldLayout fieldLayout ) public virtual prohibitDirectCallback; ``` @@ -232,10 +236,12 @@ function setStaticField( Writes data into a dynamic (varible length) field in the table identified by `tableId`. ```solidity -function setDynamicField(ResourceId tableId, bytes32[] calldata keyTuple, uint8 dynamicFieldIndex, bytes calldata data) - public - virtual - prohibitDirectCallback; +function setDynamicField( + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + bytes calldata data +) public virtual prohibitDirectCallback; ``` **Parameters** @@ -253,10 +259,10 @@ Appends data to the end of a dynamic (variable length) field in the table identi ```solidity function pushToDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - bytes calldata dataToPush + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + bytes calldata dataToPush ) public virtual prohibitDirectCallback; ``` @@ -275,10 +281,10 @@ Removes a specified amount of data from the end of a dynamic (variable length) f ```solidity function popFromDynamicField( - ResourceId tableId, - bytes32[] calldata keyTuple, - uint8 dynamicFieldIndex, - uint256 byteLengthToPop + ResourceId tableId, + bytes32[] calldata keyTuple, + uint8 dynamicFieldIndex, + uint256 byteLengthToPop ) public virtual prohibitDirectCallback; ``` @@ -317,12 +323,10 @@ Calls a system with a given system ID. _If system is private, caller must have appropriate access._ ```solidity -function call(ResourceId systemId, bytes memory callData) - external - payable - virtual - prohibitDirectCallback - returns (bytes memory); +function call( + ResourceId systemId, + bytes memory callData +) external payable virtual prohibitDirectCallback returns (bytes memory); ``` **Parameters** @@ -345,12 +349,11 @@ Calls a system with a given system ID on behalf of the given delegator. _If system is private, caller must have appropriate access._ ```solidity -function callFrom(address delegator, ResourceId systemId, bytes memory callData) - external - payable - virtual - prohibitDirectCallback - returns (bytes memory); +function callFrom( + address delegator, + ResourceId systemId, + bytes memory callData +) external payable virtual prohibitDirectCallback returns (bytes memory); ``` **Parameters** diff --git a/docs/src/tailwindcss-plugins/animate.ts b/docs/src/tailwindcss-plugins/animate.ts index f64ba44b27..1c6e3c1369 100644 --- a/docs/src/tailwindcss-plugins/animate.ts +++ b/docs/src/tailwindcss-plugins/animate.ts @@ -37,7 +37,7 @@ module.exports = plugin( "fade-in": (value) => ({ "--tw-enter-opacity": value }), "fade-out": (value) => ({ "--tw-exit-opacity": value }), }, - { values: theme("animationOpacity") } + { values: theme("animationOpacity") }, ); matchUtilities( @@ -45,7 +45,7 @@ module.exports = plugin( "zoom-in": (value) => ({ "--tw-enter-scale": value }), "zoom-out": (value) => ({ "--tw-exit-scale": value }), }, - { values: theme("animationScale") } + { values: theme("animationScale") }, ); matchUtilities( @@ -53,7 +53,7 @@ module.exports = plugin( "spin-in": (value) => ({ "--tw-enter-rotate": value }), "spin-out": (value) => ({ "--tw-exit-rotate": value }), }, - { values: theme("animationRotate") } + { values: theme("animationRotate") }, ); matchUtilities( @@ -83,19 +83,19 @@ module.exports = plugin( "--tw-exit-translate-x": value, }), }, - { values: theme("animationTranslate") } + { values: theme("animationTranslate") }, ); matchUtilities( { "animate-duration": (value: string) => ({ animationDuration: value }) }, - { values: filterDefault(theme("animationDuration")) } + { values: filterDefault(theme("animationDuration")) }, ); matchUtilities({ delay: (value) => ({ animationDelay: value }) }, { values: theme("animationDelay") }); matchUtilities( { ease: (value: string) => ({ animationTimingFunction: value }) }, - { values: filterDefault(theme("animationTimingFunction")) } + { values: filterDefault(theme("animationTimingFunction")) }, ); addUtilities({ @@ -175,5 +175,5 @@ module.exports = plugin( }, }, }, - } + }, ); diff --git a/e2e/packages/client-vanilla/src/index.ts b/e2e/packages/client-vanilla/src/index.ts index 464d986f78..7899f3c949 100644 --- a/e2e/packages/client-vanilla/src/index.ts +++ b/e2e/packages/client-vanilla/src/index.ts @@ -17,7 +17,7 @@ _window.getEntities = (componentName: keyof typeof components) => Array.from(com _window.getKeys = (componentName: keyof typeof components) => Array.from(components[componentName].entities()).map((entity) => - decodeEntity(components[componentName].metadata.keySchema, entity) + decodeEntity(components[componentName].metadata.keySchema, entity), ); // Update block number in the UI diff --git a/e2e/packages/contracts/package.json b/e2e/packages/contracts/package.json index 27a8b462a5..3f1b229fb3 100644 --- a/e2e/packages/contracts/package.json +++ b/e2e/packages/contracts/package.json @@ -19,7 +19,7 @@ "dotenv": "^16.0.3", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "^2.6.2", + "prettier": "3.2.5", "rimraf": "^3.0.2", "typescript": "5.1.6", "vite": "^4.2.1", diff --git a/e2e/packages/sync-test/compare/compare.test.ts b/e2e/packages/sync-test/compare/compare.test.ts index f3bb9b5351..c6d7f0f8f7 100644 --- a/e2e/packages/sync-test/compare/compare.test.ts +++ b/e2e/packages/sync-test/compare/compare.test.ts @@ -35,7 +35,7 @@ function setRecord( address: Address, tableId: TableId, key: Key, - data: Data + data: Data, ): void { state[address.toLowerCase()] ??= {}; state[address.toLowerCase()][tableId] ??= {}; @@ -46,7 +46,7 @@ function getRecord( state: Record>>, address: Address, tableId: TableId, - key: Key + key: Key, ): Data | undefined { return state[address]?.[tableId]?.[key]; } diff --git a/e2e/packages/sync-test/data/callPageFunction.ts b/e2e/packages/sync-test/data/callPageFunction.ts index ece5b02e01..89a9c395a4 100644 --- a/e2e/packages/sync-test/data/callPageFunction.ts +++ b/e2e/packages/sync-test/data/callPageFunction.ts @@ -9,7 +9,7 @@ import { deserialize, serialize } from "./utils"; export async function callPageFunction( page: Page, functionName: string, - args: unknown[] + args: unknown[], ): Promise | undefined> { const context = [functionName, args, serialize.toString(), deserialize.toString()] as const; const serializedValue = await page.evaluate(async ([functionName, args, serializeString, deserializeString]) => { diff --git a/e2e/packages/sync-test/data/callWorld.ts b/e2e/packages/sync-test/data/callWorld.ts index c19e1d9029..c6b58c04c6 100644 --- a/e2e/packages/sync-test/data/callWorld.ts +++ b/e2e/packages/sync-test/data/callWorld.ts @@ -23,6 +23,6 @@ export function callWorld(page: Page, method: T throw new Error([`Error executing ${_method} with args:`, JSON.stringify(_args), error].join("\n\n")); }); }, - [method, args] + [method, args], ); } diff --git a/e2e/packages/sync-test/data/types.ts b/e2e/packages/sync-test/data/types.ts index b79ac3f3b6..98369a7426 100644 --- a/e2e/packages/sync-test/data/types.ts +++ b/e2e/packages/sync-test/data/types.ts @@ -2,9 +2,10 @@ import { SchemaAbiType, SchemaAbiTypeToPrimitiveType } from "@latticexyz/schema-type"; import config from "../../contracts/mud.config"; import { Hex } from "viem"; -type SchemaToPrimitive = Schema extends Record - ? { [key in keyof Schema]: SchemaAbiTypeToPrimitiveType } - : never; +type SchemaToPrimitive = + Schema extends Record + ? { [key in keyof Schema]: SchemaAbiTypeToPrimitiveType } + : never; type Key = SchemaToPrimitive< (typeof config)["tables"][Table]["keySchema"] diff --git a/e2e/packages/sync-test/indexerSync.test.ts b/e2e/packages/sync-test/indexerSync.test.ts index f23edf5f16..3585c6e4a2 100644 --- a/e2e/packages/sync-test/indexerSync.test.ts +++ b/e2e/packages/sync-test/indexerSync.test.ts @@ -143,7 +143,7 @@ describe("Sync from indexer", async () => { y: -2, zone: "0x6d61703100000000000000000000000000000000000000000000000000000000", }, - ]) + ]), ); // Should not have thrown errors diff --git a/e2e/packages/sync-test/setup/openClientWithRootAccount.ts b/e2e/packages/sync-test/setup/openClientWithRootAccount.ts index 85b88658d6..98158ca286 100644 --- a/e2e/packages/sync-test/setup/openClientWithRootAccount.ts +++ b/e2e/packages/sync-test/setup/openClientWithRootAccount.ts @@ -12,6 +12,6 @@ export async function openClientWithRootAccount(page: Page, options?: { indexerU // I wish I could pass undefined values into URLSearchParams and have them be ignored during stringify ...(process.env.PRIVATE_KEY ? { privateKey: process.env.PRIVATE_KEY } : null), ...(options?.indexerUrl ? { indexerUrl: options?.indexerUrl } : null), - }).toString()}` + }).toString()}`, ); } diff --git a/e2e/packages/sync-test/setup/startBrowserAndPage.ts b/e2e/packages/sync-test/setup/startBrowserAndPage.ts index 0f18151879..9cbced06a0 100644 --- a/e2e/packages/sync-test/setup/startBrowserAndPage.ts +++ b/e2e/packages/sync-test/setup/startBrowserAndPage.ts @@ -2,7 +2,7 @@ import { Browser, Page, chromium } from "@playwright/test"; import chalk from "chalk"; export async function startBrowserAndPage( - reportError: (error: string) => void + reportError: (error: string) => void, ): Promise<{ browser: Browser; page: Page }> { // open browser page const browser = await chromium.launch(); diff --git a/e2e/packages/test-data/generate-bench-data-bulk.ts b/e2e/packages/test-data/generate-bench-data-bulk.ts index 313ad45a7d..c69fad503f 100644 --- a/e2e/packages/test-data/generate-bench-data-bulk.ts +++ b/e2e/packages/test-data/generate-bench-data-bulk.ts @@ -34,7 +34,7 @@ for (let i = 0; i < NUM_RECORDS.length; i++) { const logsFilename = path.join( path.dirname(fileURLToPath(import.meta.url)), - `../../../test-data/world-logs-bulk-${numRecords}.json` + `../../../test-data/world-logs-bulk-${numRecords}.json`, ); console.log("writing", logs.length, "logs to", logsFilename); diff --git a/e2e/packages/test-data/generate-bench-data-query.ts b/e2e/packages/test-data/generate-bench-data-query.ts index d97a976fd4..4e34afe75c 100644 --- a/e2e/packages/test-data/generate-bench-data-query.ts +++ b/e2e/packages/test-data/generate-bench-data-query.ts @@ -30,7 +30,7 @@ const logs = await generateLogs(rpc, async (worldContract) => { const logsFilename = path.join( path.dirname(fileURLToPath(import.meta.url)), - `../../../test-data/world-logs-query.json` + `../../../test-data/world-logs-query.json`, ); console.log("writing", logs.length, "logs to", logsFilename); diff --git a/e2e/packages/test-data/generateLogs.ts b/e2e/packages/test-data/generateLogs.ts index fff5449b2f..ba855efe61 100644 --- a/e2e/packages/test-data/generateLogs.ts +++ b/e2e/packages/test-data/generateLogs.ts @@ -31,7 +31,7 @@ type WorldContract = GetContractReturnType< export async function generateLogs( rpc: string, - transactionHook: (worldContract: WorldContract) => Promise + transactionHook: (worldContract: WorldContract) => Promise, ): Promise { console.log("deploying world"); const { stdout, stderr } = await execa("pnpm", ["mud", "deploy", "--rpc", rpc, "--saveDeployment", "false"], { @@ -88,7 +88,7 @@ export async function generateLogs( encodeEventTopics({ abi: [event], eventName: event.name, - }) + }), ), ], fromBlock: numberToHex(0n), diff --git a/examples/minimal/packages/client-phaser/src/mud/createSystemCalls.ts b/examples/minimal/packages/client-phaser/src/mud/createSystemCalls.ts index 1e0c674320..37203654b1 100644 --- a/examples/minimal/packages/client-phaser/src/mud/createSystemCalls.ts +++ b/examples/minimal/packages/client-phaser/src/mud/createSystemCalls.ts @@ -7,7 +7,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { worldContract, waitForTransaction }: SetupNetworkResult, - { CounterTable }: ClientComponents + { CounterTable }: ClientComponents, ) { const increment = async () => { const tx = await worldContract.write.increment(); diff --git a/examples/minimal/packages/client-phaser/src/ui/App.tsx b/examples/minimal/packages/client-phaser/src/ui/App.tsx index 69529815b5..0ddd731ec7 100644 --- a/examples/minimal/packages/client-phaser/src/ui/App.tsx +++ b/examples/minimal/packages/client-phaser/src/ui/App.tsx @@ -26,7 +26,7 @@ export const App = () => { worldAbi: networkLayer.network.worldContract.abi, write$: networkLayer.network.write$, recsWorld: networkLayer.world, - }) + }), ); } }, [networkLayer]); diff --git a/examples/minimal/packages/client-phaser/src/ui/hooks/usePhaserLayer.tsx b/examples/minimal/packages/client-phaser/src/ui/hooks/usePhaserLayer.tsx index f0a4c36da7..c6292e57ff 100644 --- a/examples/minimal/packages/client-phaser/src/ui/hooks/usePhaserLayer.tsx +++ b/examples/minimal/packages/client-phaser/src/ui/hooks/usePhaserLayer.tsx @@ -79,7 +79,7 @@ export const usePhaserLayer = ({ networkLayer }: Props) => { } } }, - [container] + [container], ); return useMemo(() => ({ ref, phaserLayer }), [ref, phaserLayer]); diff --git a/examples/minimal/packages/client-react/src/index.tsx b/examples/minimal/packages/client-react/src/index.tsx index da8d70f020..1b005dc561 100644 --- a/examples/minimal/packages/client-react/src/index.tsx +++ b/examples/minimal/packages/client-react/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/examples/minimal/packages/client-react/src/mud/createSystemCalls.ts b/examples/minimal/packages/client-react/src/mud/createSystemCalls.ts index 1e0c674320..37203654b1 100644 --- a/examples/minimal/packages/client-react/src/mud/createSystemCalls.ts +++ b/examples/minimal/packages/client-react/src/mud/createSystemCalls.ts @@ -7,7 +7,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { worldContract, waitForTransaction }: SetupNetworkResult, - { CounterTable }: ClientComponents + { CounterTable }: ClientComponents, ) { const increment = async () => { const tx = await worldContract.write.increment(); diff --git a/examples/minimal/packages/contracts/package.json b/examples/minimal/packages/contracts/package.json index 72f4f46204..7d49c273a0 100644 --- a/examples/minimal/packages/contracts/package.json +++ b/examples/minimal/packages/contracts/package.json @@ -27,7 +27,7 @@ "@types/node": "^18.15.11", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "^2.6.2", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "rimraf": "^3.0.2", "solhint": "^3.4.1", diff --git a/examples/multiple-accounts/packages/client/src/index.tsx b/examples/multiple-accounts/packages/client/src/index.tsx index 3ba2a44052..c9b662c9f0 100644 --- a/examples/multiple-accounts/packages/client/src/index.tsx +++ b/examples/multiple-accounts/packages/client/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/examples/multiple-accounts/packages/contracts/package.json b/examples/multiple-accounts/packages/contracts/package.json index 13c972596e..461ceb6001 100644 --- a/examples/multiple-accounts/packages/contracts/package.json +++ b/examples/multiple-accounts/packages/contracts/package.json @@ -25,7 +25,7 @@ "@types/node": "^18.15.11", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "^2.6.2", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "2.0.0-next.15", diff --git a/package.json b/package.json index 2b29cd3c80..b9abb3e9e1 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "execa": "^7.0.0", "husky": ">=6", "lint-staged": ">=10", - "prettier": "^2.8.4", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "rimraf": "^3.0.2", "turbo": "^1.9.3", diff --git a/packages/abi-ts/src/abi-ts.ts b/packages/abi-ts/src/abi-ts.ts index 8d12d0ee0a..a6093d52ec 100755 --- a/packages/abi-ts/src/abi-ts.ts +++ b/packages/abi-ts/src/abi-ts.ts @@ -21,7 +21,7 @@ yargs(hideBin(process.argv)) console.error(chalk.red(msg)); if (msg.includes("Missing required argument")) { console.log( - chalk.yellow(`Run 'pnpm abi-ts ${process.argv[2]} --help' for a list of available and required arguments.`) + chalk.yellow(`Run 'pnpm abi-ts ${process.argv[2]} --help' for a list of available and required arguments.`), ); } diff --git a/packages/block-logs-stream/CHANGELOG.md b/packages/block-logs-stream/CHANGELOG.md index 545ea08a88..7e9de47863 100644 --- a/packages/block-logs-stream/CHANGELOG.md +++ b/packages/block-logs-stream/CHANGELOG.md @@ -418,7 +418,7 @@ const latestBlockNumber$ = latestBlock$.pipe( filter(isNonPendingBlock), - map((block) => block.number) + map((block) => block.number), ); latestBlockNumber$ @@ -434,7 +434,7 @@ "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/packages/block-logs-stream/README.md b/packages/block-logs-stream/README.md index a76e15825f..0d7ccc924f 100644 --- a/packages/block-logs-stream/README.md +++ b/packages/block-logs-stream/README.md @@ -32,7 +32,7 @@ latestBlockNumber$ "event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/packages/block-logs-stream/src/blockRangeToLogs.test.ts b/packages/block-logs-stream/src/blockRangeToLogs.test.ts index a0474841b8..607a8dea77 100644 --- a/packages/block-logs-stream/src/blockRangeToLogs.test.ts +++ b/packages/block-logs-stream/src/blockRangeToLogs.test.ts @@ -41,7 +41,7 @@ describe("blockRangeToLogs", () => { publicClient, address: "0x", events: [], - }) + }), ); (async (): Promise => { diff --git a/packages/block-logs-stream/src/blockRangeToLogs.ts b/packages/block-logs-stream/src/blockRangeToLogs.ts index 825320f14d..9a87da6242 100644 --- a/packages/block-logs-stream/src/blockRangeToLogs.ts +++ b/packages/block-logs-stream/src/blockRangeToLogs.ts @@ -65,12 +65,12 @@ export function blockRangeToLogs({ fromBlock, toBlock, maxBlockRange, - }) + }), ).pipe( tap(({ toBlock }) => { fromBlock = toBlock + 1n; - }) + }), ); - }) + }), ); } diff --git a/packages/block-logs-stream/src/fetchLogs.test.ts b/packages/block-logs-stream/src/fetchLogs.test.ts index 7f95f507b9..4bd28cb1c2 100644 --- a/packages/block-logs-stream/src/fetchLogs.test.ts +++ b/packages/block-logs-stream/src/fetchLogs.test.ts @@ -150,7 +150,7 @@ describe("fetchLogs", () => { code: -32005, message: "block range exceeded", }, - }) + }), ); } @@ -374,7 +374,7 @@ describe("fetchLogs", () => { code: -32005, message: "rate limit exceeded", }, - }) + }), ); } diff --git a/packages/block-logs-stream/src/groupLogsByBlockNumber.ts b/packages/block-logs-stream/src/groupLogsByBlockNumber.ts index b0656acfbc..37fd614d35 100644 --- a/packages/block-logs-stream/src/groupLogsByBlockNumber.ts +++ b/packages/block-logs-stream/src/groupLogsByBlockNumber.ts @@ -24,7 +24,7 @@ export type GroupLogsByBlockNumberResult = { */ export function groupLogsByBlockNumber( logs: readonly TLog[], - toBlock?: BlockNumber + toBlock?: BlockNumber, ): GroupLogsByBlockNumberResult { const blockNumbers = Array.from(new Set(logs.map((log) => log.blockNumber))); blockNumbers.sort(bigIntSort); diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 0bec448c15..705083a33e 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1135,7 +1135,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/cli/src/commands/dev-contracts.ts b/packages/cli/src/commands/dev-contracts.ts index 9cd69fb3cd..cff93f08d9 100644 --- a/packages/cli/src/commands/dev-contracts.ts +++ b/packages/cli/src/commands/dev-contracts.ts @@ -105,7 +105,7 @@ const commandModule: CommandModule = { const mutuallyExclusiveOptions = ["mudVersion", "link", "tag", "commit", "restore"]; const numMutuallyExclusiveOptions = mutuallyExclusiveOptions.reduce( (acc, opt) => (options[opt] ? acc + 1 : acc), - 0 + 0, ); if (numMutuallyExclusiveOptions === 0) { diff --git a/packages/cli/src/commands/trace.ts b/packages/cli/src/commands/trace.ts index e6d55a9ece..e8659eb089 100644 --- a/packages/cli/src/commands/trace.ts +++ b/packages/cli/src/commands/trace.ts @@ -63,7 +63,7 @@ const commandModule: CommandModule = { const resolvedConfig = resolveWorldConfig( mudConfig, - existingContracts.map(({ basename }) => basename) + existingContracts.map(({ basename }) => basename), ); // Get worldAddress either from args or from worldsFile diff --git a/packages/cli/src/deploy/configToTables.ts b/packages/cli/src/deploy/configToTables.ts index 4c07a81bb3..3e9b0e5729 100644 --- a/packages/cli/src/deploy/configToTables.ts +++ b/packages/cli/src/deploy/configToTables.ts @@ -14,12 +14,12 @@ type UserTypes = config["userTypes"]; export type TableKey< config extends StoreConfig = StoreConfig, - table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]] + table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]], > = `${config["namespace"]}_${table["name"]}`; export type Table< config extends StoreConfig = StoreConfig, - table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]] + table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]], > = { readonly namespace: config["namespace"]; readonly name: table["name"]; @@ -63,6 +63,6 @@ export function configToTables(config: config): Tabl keySchema: resolveUserTypes(table.keySchema, userTypes) as any, valueSchema: resolveUserTypes(table.valueSchema, userTypes) as any, } satisfies Table, - ]) + ]), ) as Tables; } diff --git a/packages/cli/src/deploy/deployWorld.ts b/packages/cli/src/deploy/deployWorld.ts index c038327c84..2b2911ce57 100644 --- a/packages/cli/src/deploy/deployWorld.ts +++ b/packages/cli/src/deploy/deployWorld.ts @@ -9,7 +9,7 @@ import { WorldDeploy } from "./common"; export async function deployWorld( client: Client, - salt: Hex + salt: Hex, ): Promise { await ensureWorldFactory(client); diff --git a/packages/cli/src/deploy/ensureContract.ts b/packages/cli/src/deploy/ensureContract.ts index 92553952f9..a4244ed56c 100644 --- a/packages/cli/src/deploy/ensureContract.ts +++ b/packages/cli/src/deploy/ensureContract.ts @@ -31,11 +31,11 @@ export async function ensureContract({ if (deployedBytecodeSize > contractSizeLimit) { console.warn( - `\nBytecode for ${label} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n` + `\nBytecode for ${label} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n`, ); } else if (deployedBytecodeSize > contractSizeLimit * 0.95) { console.warn( - `\nBytecode for ${label} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n` + `\nBytecode for ${label} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n`, ); } @@ -55,7 +55,7 @@ export async function ensureContract({ debug(`failed to deploy ${label}, retrying in ${delay}ms...`); await wait(delay); }, - } + }, ), ]; } diff --git a/packages/cli/src/deploy/ensureFunctions.ts b/packages/cli/src/deploy/ensureFunctions.ts index 7432697354..337d9a4008 100644 --- a/packages/cli/src/deploy/ensureFunctions.ts +++ b/packages/cli/src/deploy/ensureFunctions.ts @@ -29,7 +29,7 @@ export async function ensureFunctions({ "found", wrongSystem.length, "functions already registered but pointing at a different system ID:", - wrongSystem.map((func) => func.signature).join(", ") + wrongSystem.map((func) => func.signature).join(", "), ); } } @@ -59,7 +59,7 @@ export async function ensureFunctions({ debug(`failed to register function ${func.signature}, retrying in ${delay}ms...`); await wait(delay); }, - } + }, ); } return pRetry( @@ -79,8 +79,8 @@ export async function ensureFunctions({ debug(`failed to register function ${func.signature}, retrying in ${delay}ms...`); await wait(delay); }, - } + }, ); - }) + }), ); } diff --git a/packages/cli/src/deploy/ensureModules.ts b/packages/cli/src/deploy/ensureModules.ts index 276485dfc5..0477f10efa 100644 --- a/packages/cli/src/deploy/ensureModules.ts +++ b/packages/cli/src/deploy/ensureModules.ts @@ -65,9 +65,9 @@ export async function ensureModules({ debug(`failed to install module ${mod.name}, retrying in ${delay}ms...`); await wait(delay); }, - } - ) - ) + }, + ), + ), ) ).filter(isDefined); } diff --git a/packages/cli/src/deploy/ensureNamespaceOwner.ts b/packages/cli/src/deploy/ensureNamespaceOwner.ts index 65384d2de3..0771951e90 100644 --- a/packages/cli/src/deploy/ensureNamespaceOwner.ts +++ b/packages/cli/src/deploy/ensureNamespaceOwner.ts @@ -24,7 +24,7 @@ export async function ensureNamespaceOwner({ "existing namespaces:", Array.from(existingNamespaces) .map((namespace) => (namespace === "" ? "" : namespace)) - .join(", ") + .join(", "), ); } @@ -39,7 +39,7 @@ export async function ensureNamespaceOwner({ key: { namespaceId: resourceToHex({ type: "namespace", namespace, name: "" }) }, }); return [namespace, owner]; - }) + }), ); const unauthorizedNamespaces = namespaceOwners @@ -63,8 +63,8 @@ export async function ensureNamespaceOwner({ abi: worldAbi, functionName: "registerNamespace", args: [resourceToHex({ namespace, type: "namespace", name: "" })], - }) - ) + }), + ), ); return registrationTxs; diff --git a/packages/cli/src/deploy/ensureSystems.ts b/packages/cli/src/deploy/ensureSystems.ts index 4ebaf24e3b..0bffe7c7da 100644 --- a/packages/cli/src/deploy/ensureSystems.ts +++ b/packages/cli/src/deploy/ensureSystems.ts @@ -25,23 +25,23 @@ export async function ensureSystems({ const systemIds = systems.map((system) => system.systemId); const currentAccess = worldAccess.filter(({ resourceId }) => systemIds.includes(resourceId)); const desiredAccess = systems.flatMap((system) => - system.allowedAddresses.map((address) => ({ resourceId: system.systemId, address })) + system.allowedAddresses.map((address) => ({ resourceId: system.systemId, address })), ); const accessToAdd = desiredAccess.filter( (access) => !currentAccess.some( ({ resourceId, address }) => - resourceId === access.resourceId && getAddress(address) === getAddress(access.address) - ) + resourceId === access.resourceId && getAddress(address) === getAddress(access.address), + ), ); const accessToRemove = currentAccess.filter( (access) => !desiredAccess.some( ({ resourceId, address }) => - resourceId === access.resourceId && getAddress(address) === getAddress(access.address) - ) + resourceId === access.resourceId && getAddress(address) === getAddress(access.address), + ), ); // TODO: move each system access+registration to batch call to be atomic @@ -71,8 +71,8 @@ export async function ensureSystems({ debug(`failed to revoke access, retrying in ${delay}ms...`); await wait(delay); }, - } - ) + }, + ), ), ...accessToAdd.map((access) => pRetry( @@ -91,16 +91,16 @@ export async function ensureSystems({ debug(`failed to grant access, retrying in ${delay}ms...`); await wait(delay); }, - } - ) + }, + ), ), ]; const existingSystems = systems.filter((system) => worldSystems.some( (worldSystem) => - worldSystem.systemId === system.systemId && getAddress(worldSystem.address) === getAddress(system.address) - ) + worldSystem.systemId === system.systemId && getAddress(worldSystem.address) === getAddress(system.address), + ), ); if (existingSystems.length) { debug("existing systems", existingSystems.map(resourceLabel).join(", ")); @@ -113,15 +113,15 @@ export async function ensureSystems({ const systemsToUpgrade = missingSystems.filter((system) => worldSystems.some( (worldSystem) => - worldSystem.systemId === system.systemId && getAddress(worldSystem.address) !== getAddress(system.address) - ) + worldSystem.systemId === system.systemId && getAddress(worldSystem.address) !== getAddress(system.address), + ), ); if (systemsToUpgrade.length) { debug("upgrading systems", systemsToUpgrade.map(resourceLabel).join(", ")); } const systemsToAdd = missingSystems.filter( - (system) => !worldSystems.some((worldSystem) => worldSystem.systemId === system.systemId) + (system) => !worldSystems.some((worldSystem) => worldSystem.systemId === system.systemId), ); if (systemsToAdd.length) { debug("registering new systems", systemsToAdd.map(resourceLabel).join(", ")); @@ -154,8 +154,8 @@ export async function ensureSystems({ debug(`failed to register system ${resourceLabel(system)}, retrying in ${delay}ms...`); await wait(delay); }, - } - ) + }, + ), ); return await Promise.all([...accessTxs, ...registerTxs]); diff --git a/packages/cli/src/deploy/ensureTables.ts b/packages/cli/src/deploy/ensureTables.ts index cd31975bda..3f8d134890 100644 --- a/packages/cli/src/deploy/ensureTables.ts +++ b/packages/cli/src/deploy/ensureTables.ts @@ -55,9 +55,9 @@ export async function ensureTables({ debug(`failed to register table ${resourceLabel(table)}, retrying in ${delay}ms...`); await wait(delay); }, - } - ) - ) + }, + ), + ), ); } diff --git a/packages/cli/src/deploy/ensureWorldFactory.ts b/packages/cli/src/deploy/ensureWorldFactory.ts index 1f2913a801..c30635fbff 100644 --- a/packages/cli/src/deploy/ensureWorldFactory.ts +++ b/packages/cli/src/deploy/ensureWorldFactory.ts @@ -13,7 +13,7 @@ import { ensureContractsDeployed } from "./ensureContractsDeployed"; import { Contract } from "./ensureContract"; export const accessManagementSystemDeployedBytecodeSize = size( - accessManagementSystemBuild.deployedBytecode.object as Hex + accessManagementSystemBuild.deployedBytecode.object as Hex, ); export const accessManagementSystemBytecode = encodeDeployData({ bytecode: accessManagementSystemBuild.bytecode.object as Hex, @@ -26,7 +26,7 @@ export const accessManagementSystem = getCreate2Address({ }); export const balanceTransferSystemDeployedBytecodeSize = size( - balanceTransferSystemBuild.deployedBytecode.object as Hex + balanceTransferSystemBuild.deployedBytecode.object as Hex, ); export const balanceTransferSystemBytecode = encodeDeployData({ bytecode: balanceTransferSystemBuild.bytecode.object as Hex, @@ -108,7 +108,7 @@ export const worldFactoryContracts: readonly Contract[] = [ ]; export async function ensureWorldFactory( - client: Client + client: Client, ): Promise { // WorldFactory constructor doesn't call InitModule, only sets its address, so we can do these in parallel since the address is deterministic return await ensureContractsDeployed({ diff --git a/packages/cli/src/deploy/getFunctions.ts b/packages/cli/src/deploy/getFunctions.ts index d3ba822e48..6ed040e9bb 100644 --- a/packages/cli/src/deploy/getFunctions.ts +++ b/packages/cli/src/deploy/getFunctions.ts @@ -51,7 +51,7 @@ export async function getFunctions({ systemFunctionSignature, systemFunctionSelector, }; - }) + }), ); return functions; diff --git a/packages/cli/src/deploy/getResourceAccess.ts b/packages/cli/src/deploy/getResourceAccess.ts index e38a2b2cfd..a9642085be 100644 --- a/packages/cli/src/deploy/getResourceAccess.ts +++ b/packages/cli/src/deploy/getResourceAccess.ts @@ -35,8 +35,8 @@ export async function getResourceAccess({ await Promise.all( keys.map( async (key) => - [key, await getTableValue({ client, worldDeploy, table: worldTables.world_ResourceAccess, key })] as const - ) + [key, await getTableValue({ client, worldDeploy, table: worldTables.world_ResourceAccess, key })] as const, + ), ) ) .filter(([, value]) => value.access) diff --git a/packages/cli/src/deploy/getSystems.ts b/packages/cli/src/deploy/getSystems.ts index f3619fed63..373c451a29 100644 --- a/packages/cli/src/deploy/getSystems.ts +++ b/packages/cli/src/deploy/getSystems.ts @@ -43,6 +43,6 @@ export async function getSystems({ .map(({ address }) => address), functions: systemFunctions, }; - }) + }), ); } diff --git a/packages/cli/src/deploy/getTables.ts b/packages/cli/src/deploy/getTables.ts index 4154f38199..3342c7b9db 100644 --- a/packages/cli/src/deploy/getTables.ts +++ b/packages/cli/src/deploy/getTables.ts @@ -45,7 +45,7 @@ export async function getTables({ const valueAbiTypes = [...valueSchemaFields.staticFields, ...valueSchemaFields.dynamicFields]; const keySchema = Object.fromEntries( - keySchemaFields.staticFields.map((abiType, i) => [keyNames[i], abiType]) + keySchemaFields.staticFields.map((abiType, i) => [keyNames[i], abiType]), ) as KeySchema; const valueSchema = Object.fromEntries(valueAbiTypes.map((abiType, i) => [fieldNames[i], abiType])) as ValueSchema; diff --git a/packages/cli/src/deploy/logsToWorldDeploy.ts b/packages/cli/src/deploy/logsToWorldDeploy.ts index 81091270fd..a6f078766f 100644 --- a/packages/cli/src/deploy/logsToWorldDeploy.ts +++ b/packages/cli/src/deploy/logsToWorldDeploy.ts @@ -37,7 +37,7 @@ export function logsToWorldDeploy(logs: readonly Log[]): ? { storeVersion: hexToString(trim(log.args.storeVersion, { dir: "right" })) } : null), }), - {} + {}, ); if (address == null) throw new Error("could not find world address"); diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index ec18c69ef2..0eb514c916 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -71,7 +71,7 @@ export function resolveConfig({ allowAll: system.openAccess, allowedAddresses: system.accessListAddresses as Hex[], allowedSystemIds: system.accessListSystems.map((name) => - resourceToHex({ type: "system", namespace, name: resolvedConfig.systems[name].name }) + resourceToHex({ type: "system", namespace, name: resolvedConfig.systems[name].name }), ), address: getCreate2Address({ from: deployer, bytecode: contractData.bytecode, salt }), bytecode: contractData.bytecode, @@ -89,8 +89,8 @@ export function resolveConfig({ if (!targetSystem) { throw new Error( `System ${resourceLabel(system)} wanted access to ${resourceLabel( - hexToResource(systemId) - )}, but it wasn't found in the config.` + hexToResource(systemId), + )}, but it wasn't found in the config.`, ); } return targetSystem.address; @@ -98,7 +98,7 @@ export function resolveConfig({ return { ...system, allowedAddresses: Array.from( - new Set([...allowedAddresses, ...allowedSystemAddresses].map((addr) => getAddress(addr))) + new Set([...allowedAddresses, ...allowedSystemAddresses].map((addr) => getAddress(addr))), ), }; }); @@ -113,9 +113,9 @@ export function resolveConfig({ type: table.offchainOnly ? "offchainTable" : "table", namespace: config.namespace, name: table.name, - }) + }), ), - ]) + ]), ), }; diff --git a/packages/cli/src/mud.ts b/packages/cli/src/mud.ts index b1f85a25fb..b01f04031b 100755 --- a/packages/cli/src/mud.ts +++ b/packages/cli/src/mud.ts @@ -26,7 +26,7 @@ async function run() { console.error(chalk.red(msg)); if (msg.includes("Missing required argument")) { console.log( - chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`) + chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`), ); } console.log(""); diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index 90e4ff556e..1d74a58ca9 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -60,8 +60,8 @@ export async function runDeploy(opts: DeployOptions): Promise { const rpc = opts.rpc ?? (await getRpcUrl(profile)); console.log( chalk.bgBlue( - chalk.whiteBright(`\n Deploying MUD contracts${profile ? " with profile " + profile : ""} to RPC ${rpc} \n`) - ) + chalk.whiteBright(`\n Deploying MUD contracts${profile ? " with profile " + profile : ""} to RPC ${rpc} \n`), + ), ); // Run build @@ -74,7 +74,7 @@ export async function runDeploy(opts: DeployOptions): Promise { throw new MUDError( `Missing PRIVATE_KEY environment variable. Run 'echo "PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" > .env' -in your contracts directory to use the default anvil private key.` +in your contracts directory to use the default anvil private key.`, ); } @@ -121,7 +121,7 @@ in your contracts directory to use the default anvil private key.` writeFileSync(config.worldsFile, JSON.stringify(deploys, null, 2)); console.log( - chalk.bgGreen(chalk.whiteBright(`\n Deployment result (written to ${config.worldsFile} and ${deploysDir}): \n`)) + chalk.bgGreen(chalk.whiteBright(`\n Deployment result (written to ${config.worldsFile} and ${deploysDir}): \n`)), ); } diff --git a/packages/cli/src/utils/printMUD.ts b/packages/cli/src/utils/printMUD.ts index b3114e5916..5933c97d6f 100644 --- a/packages/cli/src/utils/printMUD.ts +++ b/packages/cli/src/utils/printMUD.ts @@ -9,6 +9,6 @@ export function printMUD() { | :\\/: || :\\/: || (__) | | '--'M|| '--'U|| '--'D| '------''------''------' -`) +`), ); } diff --git a/packages/cli/src/utils/utils/getContractData.ts b/packages/cli/src/utils/utils/getContractData.ts index a289b0443d..c527d2b873 100644 --- a/packages/cli/src/utils/utils/getContractData.ts +++ b/packages/cli/src/utils/utils/getContractData.ts @@ -9,7 +9,7 @@ import { Abi, Hex, size } from "viem"; */ export function getContractData( contractName: string, - forgeOutDirectory: string + forgeOutDirectory: string, ): { bytecode: Hex; abi: Abi; deployedBytecodeSize: number } { let data: any; const contractDataPath = path.join(forgeOutDirectory, contractName + ".sol", contractName + ".json"); diff --git a/packages/cli/src/utils/utils/postDeploy.ts b/packages/cli/src/utils/utils/postDeploy.ts index e30d63eaa1..a03eb1e2fa 100644 --- a/packages/cli/src/utils/utils/postDeploy.ts +++ b/packages/cli/src/utils/utils/postDeploy.ts @@ -7,7 +7,7 @@ export async function postDeploy( postDeployScript: string, worldAddress: string, rpc: string, - profile: string | undefined + profile: string | undefined, ): Promise { // Execute postDeploy forge script const postDeployPath = path.join(await getScriptDirectory(), postDeployScript + ".s.sol"); @@ -17,7 +17,7 @@ export async function postDeploy( ["script", postDeployScript, "--sig", "run(address)", worldAddress, "--broadcast", "--rpc-url", rpc, "-vvv"], { profile: profile, - } + }, ); } else { console.log(`No script at ${postDeployPath}, skipping post deploy hook`); diff --git a/packages/cli/tsup.config.ts b/packages/cli/tsup.config.ts index 8e74fd917d..cc3e3ca7de 100644 --- a/packages/cli/tsup.config.ts +++ b/packages/cli/tsup.config.ts @@ -14,7 +14,7 @@ const mudPackages: MudPackages = Object.fromEntries( JSON.parse(readFileSync(filename, "utf8")), ]) .filter(([, packageJson]) => !packageJson.private) - .map(([localPath, packageJson]) => [packageJson.name, { localPath }]) + .map(([localPath, packageJson]) => [packageJson.name, { localPath }]), ); export default defineConfig({ diff --git a/packages/common/CHANGELOG.md b/packages/common/CHANGELOG.md index 042dabaa3c..3d53ad41dd 100644 --- a/packages/common/CHANGELOG.md +++ b/packages/common/CHANGELOG.md @@ -669,7 +669,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/common/package.json b/packages/common/package.json index c0a19f8a27..851a3659ef 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -59,7 +59,7 @@ "execa": "^7.0.0", "p-queue": "^7.4.1", "p-retry": "^5.1.2", - "prettier": "^2.8.4", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "viem": "2.7.12" }, diff --git a/packages/common/src/codegen/render-solidity/common.test.ts b/packages/common/src/codegen/render-solidity/common.test.ts index e51e849b4f..436ad77102 100644 --- a/packages/common/src/codegen/render-solidity/common.test.ts +++ b/packages/common/src/codegen/render-solidity/common.test.ts @@ -22,38 +22,38 @@ describe("getLeftPaddingBits", () => { describe("renderValueTypeToBytes32", () => { it("returns Solidity code to cast native type to bytes32", () => { expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "bytes32" })).toMatchInlineSnapshot( - '"someField"' + '"someField"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bytes32" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bytes32" }), ).toMatchInlineSnapshot('"SomeStruct.unwrap(someField)"'); expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "bytes16" })).toMatchInlineSnapshot( - '"bytes32(someField)"' + '"bytes32(someField)"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bytes16" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bytes16" }), ).toMatchInlineSnapshot('"bytes32(SomeStruct.unwrap(someField))"'); expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "uint8" })).toMatchInlineSnapshot( - '"bytes32(uint256(someField))"' + '"bytes32(uint256(someField))"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "uint8" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "uint8" }), ).toMatchInlineSnapshot('"bytes32(uint256(SomeStruct.unwrap(someField)))"'); expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "bool" })).toMatchInlineSnapshot( - '"_boolToBytes32(someField)"' + '"_boolToBytes32(someField)"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bool" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bool" }), ).toMatchInlineSnapshot('"_boolToBytes32(SomeStruct.unwrap(someField))"'); expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "address" })).toMatchInlineSnapshot( - '"bytes32(uint256(uint160(someField)))"' + '"bytes32(uint256(uint160(someField)))"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "address" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "address" }), ).toMatchInlineSnapshot('"bytes32(uint256(uint160(SomeStruct.unwrap(someField))))"'); }); }); diff --git a/packages/common/src/codegen/render-solidity/common.ts b/packages/common/src/codegen/render-solidity/common.ts index ea985a0146..ad20d4cbcc 100644 --- a/packages/common/src/codegen/render-solidity/common.ts +++ b/packages/common/src/codegen/render-solidity/common.ts @@ -94,7 +94,7 @@ export function renderImports(imports: ImportDatum[]): string { path: solidityRelativeImportPath(importDatum.fromPath, importDatum.usedInPath), }; } - }) + }), ); } @@ -107,7 +107,7 @@ export function renderRelativeImports(imports: RelativeImportDatum[]): string { imports.map(({ symbol, fromPath, usedInPath }) => ({ symbol, path: solidityRelativeImportPath(fromPath, usedInPath), - })) + })), ); } @@ -154,7 +154,7 @@ interface RenderWithStoreCallbackData { */ export function renderWithStore( storeArgument: boolean, - callback: (data: RenderWithStoreCallbackData) => string + callback: (data: RenderWithStoreCallbackData) => string, ): string { let result = ""; result += callback({ _typedStore: undefined, _store: "StoreSwitch", _commentSuffix: "", _methodNamePrefix: "" }); @@ -190,7 +190,7 @@ export function renderWithStore( export function renderWithFieldSuffix( withSuffixlessFieldMethods: boolean, fieldName: string, - callback: (_methodNameSuffix: string) => string + callback: (_methodNameSuffix: string) => string, ): string { const methodNameSuffix = `${fieldName[0].toUpperCase()}${fieldName.slice(1)}`; let result = ""; @@ -215,7 +215,7 @@ export function renderTableId({ }: Pick): string { return ` // Hex below is the result of \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify( - namespace + namespace, )}, name: ${JSON.stringify(name)}, typeId: ${offchainOnly ? "RESOURCE_OFFCHAIN_TABLE" : "RESOURCE_TABLE"} });\` ResourceId constant _tableId = ResourceId.wrap(${resourceToHex({ type: offchainOnly ? "offchainTable" : "table", @@ -233,7 +233,7 @@ export function renderTableId({ */ export function renderValueTypeToBytes32( name: string, - { typeUnwrap, internalTypeId }: Pick + { typeUnwrap, internalTypeId }: Pick, ): string { const innerText = typeUnwrap.length ? `${typeUnwrap}(${name})` : name; @@ -278,7 +278,7 @@ export function getLeftPaddingBits(field: Pick( lineTerminator: string, list: T[], - renderItem: (item: T, index: number) => string + renderItem: (item: T, index: number) => string, ): string { return list .map((item, index) => renderItem(item, index) + (index === list.length - 1 ? "" : lineTerminator)) diff --git a/packages/common/src/codegen/render-solidity/renderEnums.ts b/packages/common/src/codegen/render-solidity/renderEnums.ts index 00df0b1094..74d456d81a 100644 --- a/packages/common/src/codegen/render-solidity/renderEnums.ts +++ b/packages/common/src/codegen/render-solidity/renderEnums.ts @@ -13,7 +13,7 @@ export function renderEnums(enums: RenderEnum[]): string { enum ${name} { ${renderArguments(memberNames)} } - ` + `, ); return result; diff --git a/packages/common/src/codegen/render-solidity/renderTypeHelpers.ts b/packages/common/src/codegen/render-solidity/renderTypeHelpers.ts index 81b39c4baa..f6182d60e0 100644 --- a/packages/common/src/codegen/render-solidity/renderTypeHelpers.ts +++ b/packages/common/src/codegen/render-solidity/renderTypeHelpers.ts @@ -74,7 +74,7 @@ function renderWrapperStaticArray( functionName: string, elementType: string, staticLength: number, - internalTypeId: string + internalTypeId: string, ): string { // WARNING: ensure this still works if changing major solidity versions! // (the memory layout for static arrays may change) @@ -119,7 +119,7 @@ function renderUnwrapperStaticArray( functionName: string, elementType: string, staticLength: number, - internalTypeId: string + internalTypeId: string, ): string { // byte length for memory copying (more efficient than a loop) const byteLength = staticLength * 32; diff --git a/packages/common/src/codegen/utils/contractToInterface.ts b/packages/common/src/codegen/utils/contractToInterface.ts index 13c347290a..2e1e83e907 100644 --- a/packages/common/src/codegen/utils/contractToInterface.ts +++ b/packages/common/src/codegen/utils/contractToInterface.ts @@ -33,7 +33,7 @@ interface SymbolImport { */ export function contractToInterface( data: string, - contractName: string + contractName: string, ): { functions: ContractInterfaceFunction[]; errors: ContractInterfaceError[]; diff --git a/packages/common/src/codegen/utils/extractUserTypes.ts b/packages/common/src/codegen/utils/extractUserTypes.ts index 21f48c0ed2..8bdc960699 100644 --- a/packages/common/src/codegen/utils/extractUserTypes.ts +++ b/packages/common/src/codegen/utils/extractUserTypes.ts @@ -24,7 +24,7 @@ export interface SolidityUserDefinedType { export function extractUserTypes( data: string, userTypeNames: string[], - fromPath: string + fromPath: string, ): Record { const ast = parse(data); diff --git a/packages/common/src/codegen/utils/formatAndWrite.ts b/packages/common/src/codegen/utils/formatAndWrite.ts index f8cca27b1f..1121d58262 100644 --- a/packages/common/src/codegen/utils/formatAndWrite.ts +++ b/packages/common/src/codegen/utils/formatAndWrite.ts @@ -27,7 +27,7 @@ export async function formatAndWriteSolidity(output: string, fullOutputPath: str export async function formatAndWriteTypescript( output: string, fullOutputPath: string, - logPrefix: string + logPrefix: string, ): Promise { const formattedOutput = await formatTypescript(output); diff --git a/packages/common/src/codegen/utils/loadUserTypesFile.ts b/packages/common/src/codegen/utils/loadUserTypesFile.ts index cacbd59472..127299d92f 100644 --- a/packages/common/src/codegen/utils/loadUserTypesFile.ts +++ b/packages/common/src/codegen/utils/loadUserTypesFile.ts @@ -19,7 +19,7 @@ export type UserType = { export function loadAndExtractUserTypes( userTypes: Record, outputBaseDirectory: string, - remappings: [string, string][] + remappings: [string, string][], ): Record { const userTypesPerFile: Record = {}; for (const [userTypeName, { filePath: unresolvedFilePath }] of Object.entries(userTypes)) { @@ -37,7 +37,7 @@ export function loadAndExtractUserTypes( for (const [userTypeName, userType] of Object.entries(userTypesInFile)) { if (userType.internalTypeId !== userTypes[userTypeName].internalType) { throw new MUDError( - `User type "${userTypeName}" has internal type "${userType.internalTypeId}" but config specifies "${userTypes[userTypeName].internalType}"` + `User type "${userTypeName}" has internal type "${userType.internalTypeId}" but config specifies "${userTypes[userTypeName].internalType}"`, ); } } @@ -50,7 +50,7 @@ export function loadAndExtractUserTypes( function loadUserTypesFile( outputBaseDirectory: string, unresolvedFilePath: string, - remappings: [string, string][] + remappings: [string, string][], ): { filePath: string; data: string; diff --git a/packages/common/src/foundry/index.ts b/packages/common/src/foundry/index.ts index b7f29ee61a..83f20bff42 100644 --- a/packages/common/src/foundry/index.ts +++ b/packages/common/src/foundry/index.ts @@ -87,7 +87,7 @@ export async function getRemappings(profile?: string): Promise<[string, string][ */ export async function forge( args: string[], - options?: { profile?: string; silent?: boolean; env?: NodeJS.ProcessEnv } + options?: { profile?: string; silent?: boolean; env?: NodeJS.ProcessEnv }, ): Promise { const execOptions: Options = { env: { FOUNDRY_PROFILE: options?.profile, ...options?.env }, diff --git a/packages/common/src/getContract.ts b/packages/common/src/getContract.ts index a845359dd8..863eec55a2 100644 --- a/packages/common/src/getContract.ts +++ b/packages/common/src/getContract.ts @@ -42,7 +42,7 @@ export type GetContractOptions< TChain extends Chain, TAccount extends Account, TPublicClient extends PublicClient, - TWalletClient extends WalletClient + TWalletClient extends WalletClient, > = GetContractParameters< TTransport, TChain, @@ -63,7 +63,7 @@ export function getContract< TChain extends Chain, TAccount extends Account, TPublicClient extends PublicClient, - TWalletClient extends WalletClient + TWalletClient extends WalletClient, >({ abi, address, @@ -99,7 +99,7 @@ export function getContract< return ( ...parameters: [ args?: readonly unknown[], - options?: UnionOmit + options?: UnionOmit, ] ) => { const { args, options } = getFunctionParameters(parameters); @@ -125,7 +125,7 @@ export function getContract< return result; }; }, - } + }, ); } diff --git a/packages/common/src/hexToResource.ts b/packages/common/src/hexToResource.ts index 5ac3f8a2de..9997413fb3 100644 --- a/packages/common/src/hexToResource.ts +++ b/packages/common/src/hexToResource.ts @@ -5,7 +5,7 @@ import { resourceTypeIds } from "./resourceToHex"; import { ReverseMap } from "./type-utils/common"; const resourceTypeIdToType = Object.fromEntries( - Object.entries(resourceTypeIds).map(([key, value]) => [value, key]) + Object.entries(resourceTypeIds).map(([key, value]) => [value, key]), ) as ReverseMap; function getResourceType(resourceTypeId: string): ResourceType | undefined { diff --git a/packages/common/src/sendTransaction.ts b/packages/common/src/sendTransaction.ts index 9e64497825..7d08930f57 100644 --- a/packages/common/src/sendTransaction.ts +++ b/packages/common/src/sendTransaction.ts @@ -20,10 +20,10 @@ const debug = parentDebug.extend("sendTransaction"); export async function sendTransaction< TChain extends Chain | undefined, TAccount extends Account | undefined, - TChainOverride extends Chain | undefined + TChainOverride extends Chain | undefined, >( client: Client, - request: SendTransactionParameters + request: SendTransactionParameters, ): Promise { const rawAccount = request.account ?? client.account; if (!rawAccount) { @@ -83,8 +83,8 @@ export async function sendTransaction< // TODO: prepare again if there are gas errors? throw error; }, - } + }, ), - { throwOnTimeout: true } + { throwOnTimeout: true }, ); } diff --git a/packages/common/src/utils/groupBy.ts b/packages/common/src/utils/groupBy.ts index 5a81d49e3f..556f7a89b7 100644 --- a/packages/common/src/utils/groupBy.ts +++ b/packages/common/src/utils/groupBy.ts @@ -1,6 +1,6 @@ export function groupBy( values: readonly value[], - getKey: (value: value) => key + getKey: (value: value) => key, ): Map { const map = new Map(); for (const value of values) { diff --git a/packages/common/src/utils/mapObject.ts b/packages/common/src/utils/mapObject.ts index 189f568657..89434b19b9 100644 --- a/packages/common/src/utils/mapObject.ts +++ b/packages/common/src/utils/mapObject.ts @@ -3,9 +3,9 @@ */ export function mapObject< Source extends Record, - Target extends { [key in keyof Source]: unknown } + Target extends { [key in keyof Source]: unknown }, >(source: Source, valueMap: (value: Source[typeof key], key: keyof Source) => Target[typeof key]): Target { return Object.fromEntries( - Object.entries(source).map(([key, value]) => [key, valueMap(value as Source[keyof Source], key)]) + Object.entries(source).map(([key, value]) => [key, valueMap(value as Source[keyof Source], key)]), ) as Target; } diff --git a/packages/common/src/writeContract.ts b/packages/common/src/writeContract.ts index 973ecfb8bb..5818f18db4 100644 --- a/packages/common/src/writeContract.ts +++ b/packages/common/src/writeContract.ts @@ -26,10 +26,10 @@ export async function writeContract< abi extends Abi | readonly unknown[], functionName extends ContractFunctionName, args extends ContractFunctionArgs, - chainOverride extends Chain | undefined + chainOverride extends Chain | undefined, >( client: Client, - request: WriteContractParameters + request: WriteContractParameters, ): Promise { const rawAccount = request.account ?? client.account; if (!rawAccount) { @@ -88,8 +88,8 @@ export async function writeContract< // TODO: prepareWrite again if there are gas errors? throw error; }, - } + }, ), - { throwOnTimeout: true } + { throwOnTimeout: true }, ); } diff --git a/packages/config/src/library/dynamicResolution.ts b/packages/config/src/library/dynamicResolution.ts index 4fc1dbdbcc..cf6e4083eb 100644 --- a/packages/config/src/library/dynamicResolution.ts +++ b/packages/config/src/library/dynamicResolution.ts @@ -35,7 +35,7 @@ export function isDynamicResolution(value: unknown): value is DynamicResolution */ export function resolveWithContext( unresolved: any, - context: { systemAddresses?: Record>; tableIds?: Record } + context: { systemAddresses?: Record>; tableIds?: Record }, ): ValueWithType { if (!isDynamicResolution(unresolved)) return unresolved; let resolved: ValueWithType | undefined = undefined; diff --git a/packages/create-mud/CHANGELOG.md b/packages/create-mud/CHANGELOG.md index 71ccd47861..ddb24ed63f 100644 --- a/packages/create-mud/CHANGELOG.md +++ b/packages/create-mud/CHANGELOG.md @@ -636,7 +636,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/dev-tools/src/App.tsx b/packages/dev-tools/src/App.tsx index 08f1fd7ccb..0d74c3fcae 100644 --- a/packages/dev-tools/src/App.tsx +++ b/packages/dev-tools/src/App.tsx @@ -29,7 +29,7 @@ export function App() { className={twMerge( "pointer-events-auto w-full max-w-screen-sm h-full absolute right-0", "transition duration-500", - shown ? "translate-x-0" : "translate-x-full" + shown ? "translate-x-0" : "translate-x-full", )} >
@@ -49,7 +49,7 @@ export function App() { className={twMerge( "w-full h-full bg-slate-800 text-white/80 text-sm flex flex-col", "transition duration-500", - shown ? "opacity-100" : "opacity-0" + shown ? "opacity-100" : "opacity-0", )} > diff --git a/packages/dev-tools/src/actions/WriteSummary.tsx b/packages/dev-tools/src/actions/WriteSummary.tsx index fc4b011d3c..44bd73ab00 100644 --- a/packages/dev-tools/src/actions/WriteSummary.tsx +++ b/packages/dev-tools/src/actions/WriteSummary.tsx @@ -80,7 +80,7 @@ export function WriteSummary({ write }: Props) {
@@ -97,7 +97,7 @@ export function WriteSummary({ write }: Props) { target="_blank" className={twMerge( "flex-none font-mono text-xs text-white/40", - blockExplorer ? "hover:text-white/60 hover:underline" : null + blockExplorer ? "hover:text-white/60 hover:underline" : null, )} title={transactionReceipt.value.blockNumber.toString()} > @@ -110,7 +110,7 @@ export function WriteSummary({ write }: Props) { target="_blank" className={twMerge( "flex-none font-mono text-xs text-white/40", - blockExplorer ? "hover:text-white/60 hover:underline" : null + blockExplorer ? "hover:text-white/60 hover:underline" : null, )} title={hash.value} > diff --git a/packages/dev-tools/src/actions/getTransaction.ts b/packages/dev-tools/src/actions/getTransaction.ts index eba0191ee4..50763582b1 100644 --- a/packages/dev-tools/src/actions/getTransaction.ts +++ b/packages/dev-tools/src/actions/getTransaction.ts @@ -10,7 +10,7 @@ const cache: Record> = {}; export function getTransaction( publicClient: PublicClient, - write: ContractWrite + write: ContractWrite, ): Promise { if (!cache[write.id]) { cache[write.id] = write.result.then((hash) => publicClient.getTransaction({ hash })); diff --git a/packages/dev-tools/src/actions/getTransactionReceipt.ts b/packages/dev-tools/src/actions/getTransactionReceipt.ts index 531dcb06d3..425f840e74 100644 --- a/packages/dev-tools/src/actions/getTransactionReceipt.ts +++ b/packages/dev-tools/src/actions/getTransactionReceipt.ts @@ -7,7 +7,7 @@ const cache: Record> = {}; export function getTransactionReceipt( publicClient: PublicClient, - write: ContractWrite + write: ContractWrite, ): Promise { if (!cache[write.id]) { cache[write.id] = write.result.then((hash) => publicClient.waitForTransactionReceipt({ hash })); diff --git a/packages/dev-tools/src/actions/getTransactionResult.ts b/packages/dev-tools/src/actions/getTransactionResult.ts index e2c3f70d65..380f027b36 100644 --- a/packages/dev-tools/src/actions/getTransactionResult.ts +++ b/packages/dev-tools/src/actions/getTransactionResult.ts @@ -13,7 +13,7 @@ const cache: Record> = {}; export function getTransactionResult( publicClient: PublicClient, worldAbi: Abi, - write: ContractWrite + write: ContractWrite, ): Promise { if (!cache[write.id]) { const transaction = getTransaction(publicClient, write); diff --git a/packages/dev-tools/src/mount.tsx b/packages/dev-tools/src/mount.tsx index bfaff6c910..c54976211d 100644 --- a/packages/dev-tools/src/mount.tsx +++ b/packages/dev-tools/src/mount.tsx @@ -5,7 +5,7 @@ const containerId = "mud-dev-tools"; // TODO: rework to always return a unmount function (not a promise or possibly undefined) export async function mount( - opts: DevToolsOptions + opts: DevToolsOptions, ): Promise<(() => void) | undefined> { if (typeof window === "undefined") { console.warn("MUD dev-tools should only be used in browser bundles"); @@ -39,7 +39,7 @@ export async function mount( - + , ); document.body.appendChild(rootElement); diff --git a/packages/dev-tools/src/recs/ComponentDataTable.tsx b/packages/dev-tools/src/recs/ComponentDataTable.tsx index 5323d9af3f..6dce6eb87f 100644 --- a/packages/dev-tools/src/recs/ComponentDataTable.tsx +++ b/packages/dev-tools/src/recs/ComponentDataTable.tsx @@ -38,8 +38,8 @@ export function ComponentDataTable({ component }: Props) { {component.schema[name] === Type.T ? serialize(fieldValue) : Array.isArray(fieldValue) - ? fieldValue.map(String).join(", ") - : String(fieldValue)} + ? fieldValue.map(String).join(", ") + : String(fieldValue)} ); })} diff --git a/packages/dev-tools/src/recs/ComponentsPage.tsx b/packages/dev-tools/src/recs/ComponentsPage.tsx index ef95a1bb5b..9abc66bb9e 100644 --- a/packages/dev-tools/src/recs/ComponentsPage.tsx +++ b/packages/dev-tools/src/recs/ComponentsPage.tsx @@ -63,7 +63,7 @@ export function ComponentsPage() { }> } /> - - ) + , + ), ); diff --git a/packages/dev-tools/src/summary/SummaryPage.tsx b/packages/dev-tools/src/summary/SummaryPage.tsx index 230e18fa40..516aac5b16 100644 --- a/packages/dev-tools/src/summary/SummaryPage.tsx +++ b/packages/dev-tools/src/summary/SummaryPage.tsx @@ -8,7 +8,7 @@ import packageJson from "../../package.json"; import { useDevToolsContext } from "../DevToolsContext"; const isLinked = Object.entries(packageJson.dependencies).some( - ([name, version]) => name.startsWith("@latticexyz/") && version.startsWith("link:") + ([name, version]) => name.startsWith("@latticexyz/") && version.startsWith("link:"), ); export function SummaryPage() { diff --git a/packages/dev-tools/src/zustand/TablesPage.tsx b/packages/dev-tools/src/zustand/TablesPage.tsx index c1907d8c82..f80155e2f6 100644 --- a/packages/dev-tools/src/zustand/TablesPage.tsx +++ b/packages/dev-tools/src/zustand/TablesPage.tsx @@ -58,7 +58,7 @@ export function TablesPage() { (table: table): TableRecord
}>( - useStore.getState().getRecords(table) + useStore.getState().getRecords(table), ); useEffect(() => { return useStore.subscribe((state) => { diff --git a/packages/faucet/bin/parseEnv.ts b/packages/faucet/bin/parseEnv.ts index dd739618c9..7d17e6da78 100644 --- a/packages/faucet/bin/parseEnv.ts +++ b/packages/faucet/bin/parseEnv.ts @@ -13,7 +13,7 @@ const commonSchema = z.object({ }); export function parseEnv( - schema?: TSchema + schema?: TSchema, ): z.infer : typeof commonSchema> { const envSchema = schema !== undefined ? z.intersection(commonSchema, schema) : commonSchema; try { diff --git a/packages/faucet/src/createAppRouter.ts b/packages/faucet/src/createAppRouter.ts index c30c417911..ab8285c286 100644 --- a/packages/faucet/src/createAppRouter.ts +++ b/packages/faucet/src/createAppRouter.ts @@ -19,7 +19,7 @@ export function createAppRouter() { .input( z.object({ address: z.string().refine(isHex), - }) + }), ) .mutation(async (opts): Promise => { const { client, faucetAccount, dripAmount } = opts.ctx; diff --git a/packages/gas-report/ts/gas-report.ts b/packages/gas-report/ts/gas-report.ts index aac2397f12..2391c2f101 100755 --- a/packages/gas-report/ts/gas-report.ts +++ b/packages/gas-report/ts/gas-report.ts @@ -25,7 +25,7 @@ yargs(hideBin(process.argv)) console.error(chalk.red(msg)); if (msg.includes("Missing required argument")) { console.log( - chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`) + chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`), ); } diff --git a/packages/noise/assembly/perlin.ts b/packages/noise/assembly/perlin.ts index 57e2078d59..102d433b0b 100644 --- a/packages/noise/assembly/perlin.ts +++ b/packages/noise/assembly/perlin.ts @@ -35,13 +35,13 @@ export function perlin(_x: i32, _y: i32, _z: i32, denom: i32): f64 { lerp( v, lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z)), - lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z)) + lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z)), ), lerp( v, lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1)), - lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1)) - ) + lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1)), + ), ); // Shift to range from 0 to 1 diff --git a/packages/noise/test/hardhat/keccak.spec.ts b/packages/noise/test/hardhat/keccak.spec.ts index 1cb030f698..bd68a733ff 100644 --- a/packages/noise/test/hardhat/keccak.spec.ts +++ b/packages/noise/test/hardhat/keccak.spec.ts @@ -26,7 +26,7 @@ describe("keccak256", () => { { t: "uint32", v: x }, { t: "uint32", v: y }, { t: "uint32", v: scale }, - { t: "uint32", v: seed } + { t: "uint32", v: seed }, )!; const encodedString = encodePackedU32([x, y, scale, seed]); const testHash = "0x" + keccak256(encodedString, true); diff --git a/packages/phaserx/src/createCamera.ts b/packages/phaserx/src/createCamera.ts index d7df7d9c91..4c131a15f5 100644 --- a/packages/phaserx/src/createCamera.ts +++ b/packages/phaserx/src/createCamera.ts @@ -20,7 +20,7 @@ export function createCamera(phaserCamera: Phaser.Cameras.Scene2D.Camera, option onPinch: (state) => pinchStream$.next(state), onWheel: (state) => wheelStream$.next(state), }, - {} + {}, ); // function getNearestLevel(currentZoom: number): number { @@ -51,7 +51,7 @@ export function createCamera(phaserCamera: Phaser.Cameras.Scene2D.Camera, option return zoom + scaledDelta; }), // Compute pinch speed map((zoom) => Math.min(Math.max(zoom, options.minZoom), options.maxZoom)), // Limit zoom values - scan((acc, curr) => [acc[1], curr], [1, 1]) // keep track of the last value to offset the map position (not implemented yet) + scan((acc, curr) => [acc[1], curr], [1, 1]), // keep track of the last value to offset the map position (not implemented yet) ) .subscribe(([, zoom]) => { // Set the gesture zoom state to the current zoom value to avoid zooming beyond the max values @@ -67,7 +67,7 @@ export function createCamera(phaserCamera: Phaser.Cameras.Scene2D.Camera, option // @ts-ignore map((state) => state.delta.map((x) => x * options.wheelSpeed)), // Compute wheel speed map((movement) => movement.map((m: number) => m / phaserCamera.zoom)), // Adjust for current zoom value - map((movement) => [phaserCamera.scrollX + movement[0], phaserCamera.scrollY + movement[1]]) // Compute new pinch + map((movement) => [phaserCamera.scrollX + movement[0], phaserCamera.scrollY + movement[1]]), // Compute new pinch ) .subscribe(([x, y]) => { phaserCamera.setScroll(x, y); diff --git a/packages/phaserx/src/createChunks.ts b/packages/phaserx/src/createChunks.ts index a300c50f9d..f940574344 100644 --- a/packages/phaserx/src/createChunks.ts +++ b/packages/phaserx/src/createChunks.ts @@ -19,9 +19,9 @@ export function createChunks(worldView$: Observable, chunkSize: number, pa width: width + 2 * padding, height: height + 2 * padding, }, - chunkSize - ) - ) + chunkSize, + ), + ), ); visibleChunkStream.subscribe((newVisibleChunks) => { diff --git a/packages/phaserx/src/createCulling.ts b/packages/phaserx/src/createCulling.ts index 7df01f83e9..e17419422f 100644 --- a/packages/phaserx/src/createCulling.ts +++ b/packages/phaserx/src/createCulling.ts @@ -50,7 +50,7 @@ export function createCulling(objectPool: ObjectPool, camera: Camera, chunks: Ch map((chunk: ChunkCoord) => from(chunkRegistry.get(chunk))), // Map to streams of entityIds mergeMap((entities) => entities), // Flatten the stream of entities map((entityId) => objectPool.get(entityId, "Existing")), // Map entityId to embodiedEntity - filterNullish() + filterNullish(), ); // Spawn entities when their chunk appears in the viewport @@ -77,7 +77,7 @@ export function createCulling(objectPool: ObjectPool, camera: Camera, chunks: Ch entity.despawn(); } }, - { fireImmediately: true } + { fireImmediately: true }, ); disposer.set(entity.id, dispose); } diff --git a/packages/phaserx/src/createDebugger.ts b/packages/phaserx/src/createDebugger.ts index e33bba3cf0..7cbddf3ea8 100644 --- a/packages/phaserx/src/createDebugger.ts +++ b/packages/phaserx/src/createDebugger.ts @@ -15,7 +15,7 @@ export function createDebugger( chunks: Chunks, scene: Phaser.Scene, objectPool: ObjectPool, - map: AnimatedTilemap + map: AnimatedTilemap, ) { const options = { logViewport: false, @@ -47,8 +47,8 @@ export function createDebugger( console.log( `Entities: ${objectPool.objects.size} / Pool size: ${Object.values(objectPool.groups).reduce( (acc, curr) => acc + curr.getChildren().length, - 0 - )} / Pool active: ${Object.values(objectPool.groups).reduce((acc, curr) => acc + curr.countActive(), 0)}` + 0, + )} / Pool active: ${Object.values(objectPool.groups).reduce((acc, curr) => acc + curr.countActive(), 0)}`, ); } @@ -66,7 +66,7 @@ export function createDebugger( chunks.chunkSize, chunks.chunkSize, getRandomColor(), - 0.5 + 0.5, ); visualChunk.setInteractive(); visualChunk.on("pointerup", () => { diff --git a/packages/phaserx/src/createEmbodiedEntity.ts b/packages/phaserx/src/createEmbodiedEntity.ts index faf53312cb..765243607b 100644 --- a/packages/phaserx/src/createEmbodiedEntity.ts +++ b/packages/phaserx/src/createEmbodiedEntity.ts @@ -14,7 +14,7 @@ export function createEmbodiedEntity( id: string, group: Phaser.GameObjects.Group, type: Type, - currentCameraFilter = 0 + currentCameraFilter = 0, ): EmbodiedEntity { const position: PixelCoord = observable({ x: 0, y: 0 }); const onOnce = new Map>(); @@ -136,7 +136,7 @@ export function createEmbodiedEntity( function executeGameObjectFunctions( gameObject: GameObject, - functions: Iterable> + functions: Iterable>, ) { if (!gameObject) return; for (const func of functions) { @@ -145,7 +145,7 @@ function executeGameObjectFunctions( } function modifiesPosition( - func: GameObjectFunction + func: GameObjectFunction, ): Partial | undefined { let newPosition: Partial | undefined = undefined; const gameObjectProxy = new Proxy( @@ -162,7 +162,7 @@ function modifiesPosition( if (prop === "y") newPosition = newPosition ? { ...newPosition, y: value } : { y: value }; return true; }, - } + }, ); func(gameObjectProxy as GameObject); return newPosition; diff --git a/packages/phaserx/src/createInput.ts b/packages/phaserx/src/createInput.ts index f1569d9147..7f38908b6a 100644 --- a/packages/phaserx/src/createInput.ts +++ b/packages/phaserx/src/createInput.ts @@ -42,25 +42,25 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { map(() => { return { pointer: inputPlugin.manager?.activePointer }; }), - filterNullish() + filterNullish(), ); const pointerdown$: Observable<{ pointer: Phaser.Input.Pointer; event: MouseEvent }> = fromEvent( document, - "mousedown" + "mousedown", ).pipe( filter(() => enabled.current), map((event) => ({ pointer: inputPlugin.manager?.activePointer, event: event as MouseEvent })), - filterNullish() + filterNullish(), ); const pointerup$: Observable<{ pointer: Phaser.Input.Pointer; event: MouseEvent }> = fromEvent( document, - "mouseup" + "mouseup", ).pipe( filter(() => enabled.current), map((event) => ({ pointer: inputPlugin.manager?.activePointer, event: event as MouseEvent })), - filterNullish() + filterNullish(), ); // Click stream @@ -73,7 +73,7 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { bufferCount(2, 1), // Store the last two timestamps filter(([prev, now]) => prev[0] && !now[0] && now[1] - prev[1] < 250), // Only care if button was pressed before and is not anymore and it happened within 500ms map(() => inputPlugin.manager?.activePointer), // Return the current pointer - filterNullish() + filterNullish(), ); // Double click stream @@ -84,14 +84,14 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { filter(([prev, now]) => now - prev < 500), // Filter clicks with more than 500ms distance throttleTime(500), // A third click within 500ms is not counted as another double click map(() => inputPlugin.manager?.activePointer), // Return the current pointer - filterNullish() + filterNullish(), ); // Right click stream const rightClick$ = merge(pointerdown$, pointerup$).pipe( filter(({ pointer }) => enabled.current && pointer.rightButtonDown()), map(() => inputPlugin.manager?.activePointer), // Return the current pointer - filterNullish() + filterNullish(), ); // Drag stream @@ -106,14 +106,14 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { ? { ...acc, width: curr.worldX - acc.x, height: curr.worldY - acc.y } // Update the width/height : { x: curr.worldX, y: curr.worldY, width: 0, height: 0 } // Else start the drag : undefined, - undefined + undefined, ), filterNullish(), - filter((area) => Math.abs(area.width) > 10 && Math.abs(area.height) > 10) // Prevent clicking to be mistaken as a drag - ) + filter((area) => Math.abs(area.width) > 10 && Math.abs(area.height) > 10), // Prevent clicking to be mistaken as a drag + ), ).pipe( filter(() => enabled.current), - distinctUntilChanged() // Prevent same value to be emitted in a row + distinctUntilChanged(), // Prevent same value to be emitted in a row ); const pressedKeys = observable(new Set()); @@ -170,7 +170,7 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { (passes) => { if (passes) callback(); }, - { fireImmediately: true } + { fireImmediately: true }, ); disposers.add(disposer); } diff --git a/packages/phaserx/src/createObjectPool.ts b/packages/phaserx/src/createObjectPool.ts index 654be498e8..e3535487cc 100644 --- a/packages/phaserx/src/createObjectPool.ts +++ b/packages/phaserx/src/createObjectPool.ts @@ -22,7 +22,7 @@ export function createObjectPool(scene: Phaser.Scene) { function get( entity: number | string, - type: Type + type: Type, ): ObjectPoolReturnType { if (typeof entity === "number") entity = String(entity); let embodiedEntity = objects.get(entity); diff --git a/packages/phaserx/src/guards.ts b/packages/phaserx/src/guards.ts index 96681af748..e6e83b8510 100644 --- a/packages/phaserx/src/guards.ts +++ b/packages/phaserx/src/guards.ts @@ -19,7 +19,7 @@ export function defineAssetsConfig(assets: A) { } export function defineMapConfig, L extends LayerConfig>( - config: MapConfig + config: MapConfig, ) { return config; } @@ -29,7 +29,7 @@ export function defineSceneConfig< S extends { [key: string]: Sprite }, T extends TilesetConfig, M extends MapsConfig, - Ans extends Animation[] + Ans extends Animation[], >(config: SceneConfig) { return config; } @@ -44,14 +44,14 @@ export function defineCameraConfig(config: CameraConfig) { export function isSprite( gameObject: Phaser.GameObjects.GameObject, - type: keyof GameObjectTypes + type: keyof GameObjectTypes, ): gameObject is GameObject<"Sprite"> { return type === "Sprite"; } export function isRectangle( gameObject: Phaser.GameObjects.GameObject, - type: keyof GameObjectTypes + type: keyof GameObjectTypes, ): gameObject is GameObject<"Rectangle"> { return type === "Rectangle"; } diff --git a/packages/phaserx/src/tilemap/createAnimatedTilemap.ts b/packages/phaserx/src/tilemap/createAnimatedTilemap.ts index cf01db3e70..449f30ecff 100644 --- a/packages/phaserx/src/tilemap/createAnimatedTilemap.ts +++ b/packages/phaserx/src/tilemap/createAnimatedTilemap.ts @@ -7,7 +7,7 @@ import { createVirtualTilemap } from "./createVirtualTilemap"; import { TileAnimation } from "./types"; export function createAnimatedTilemap( - config: Omit, "tiles"> & { animationInterval: number } + config: Omit, "tiles"> & { animationInterval: number }, ): AnimatedTilemap { const { layerConfig: { layers, defaultLayer }, diff --git a/packages/phaserx/src/tilemap/createChunkedTilemap.ts b/packages/phaserx/src/tilemap/createChunkedTilemap.ts index 2f4b92187b..360a27248e 100644 --- a/packages/phaserx/src/tilemap/createChunkedTilemap.ts +++ b/packages/phaserx/src/tilemap/createChunkedTilemap.ts @@ -20,7 +20,7 @@ export type ChunkedTilemapConfig( - params: ChunkedTilemapConfig + params: ChunkedTilemapConfig, ): ChunkedTilemap { const { scene, tilesets, layerConfig, chunks, backgroundTile, tiles, tileWidth, tileHeight } = params; const relevantTilesets = Object.keys(layerConfig.layers) @@ -68,7 +68,7 @@ export function createChunkedTilemap( - config: Omit, "tiles"> + config: Omit, "tiles">, ): VirtualTilemap { const { chunks, diff --git a/packages/phaserx/src/types.ts b/packages/phaserx/src/types.ts index c059ebbf49..031de7a11e 100644 --- a/packages/phaserx/src/types.ts +++ b/packages/phaserx/src/types.ts @@ -26,7 +26,7 @@ export type GameObjectTypes = typeof GameObjectClasses; export type GameObject = InstanceType; export type GameObjectFunction = ( - gameObject: GameObject + gameObject: GameObject, ) => Promise | void; export type GameScene = ReturnType; @@ -135,7 +135,7 @@ export type SceneConfig< S extends { [key: string]: Sprite }, T extends TilesetConfig, M extends MapsConfig, - Ans extends Animation[] + Ans extends Animation[], > = { preload?: (scene: Phaser.Scene) => void; create?: (scene: Phaser.Scene) => void; diff --git a/packages/phaserx/src/utils/chunks.ts b/packages/phaserx/src/utils/chunks.ts index 587d4f50d8..b6e47c2a44 100644 --- a/packages/phaserx/src/utils/chunks.ts +++ b/packages/phaserx/src/utils/chunks.ts @@ -21,7 +21,7 @@ export function getChunksInArea(area: Area, chunkSize: number) { x: topLeftChunk.x + x, y: topLeftChunk.y + y, }, - true + true, ); } } diff --git a/packages/phaserx/src/utils/coords.ts b/packages/phaserx/src/utils/coords.ts index fcd197f74c..4d20821360 100644 --- a/packages/phaserx/src/utils/coords.ts +++ b/packages/phaserx/src/utils/coords.ts @@ -64,7 +64,7 @@ export function tileCoordToChunkCoord( tileCoord: WorldCoord, tileWidth: number, tileHeight: number, - chunkSize: number + chunkSize: number, ): ChunkCoord { const pixelCoord = tileCoordToPixelCoord(tileCoord, tileWidth, tileHeight); return pixelToChunkCoord(pixelCoord, chunkSize); @@ -74,7 +74,7 @@ export function chunkCoordToTileCoord( chunkCoord: ChunkCoord, tileWidth: number, tileHeight: number, - chunkSize: number + chunkSize: number, ): WorldCoord { const pixelCoord = chunkToPixelCoord(chunkCoord, chunkSize); return pixelCoordToTileCoord(pixelCoord, tileWidth, tileHeight); diff --git a/packages/phaserx/src/utils/generateFrames.ts b/packages/phaserx/src/utils/generateFrames.ts index ef9ad74aec..99fa4a8ab6 100644 --- a/packages/phaserx/src/utils/generateFrames.ts +++ b/packages/phaserx/src/utils/generateFrames.ts @@ -2,7 +2,7 @@ import { Animation, Assets } from "../types"; export function generateFrames( anims: Phaser.Animations.AnimationManager, - animation: Animation + animation: Animation, ): Phaser.Types.Animations.AnimationFrame[] { if (animation.prefix && animation.suffix) { return anims.generateFrameNames(animation.assetKey, { diff --git a/packages/protocol-parser/src/decodeDynamicField.test.ts b/packages/protocol-parser/src/decodeDynamicField.test.ts index 4ad3b8236f..1120adac5f 100644 --- a/packages/protocol-parser/src/decodeDynamicField.test.ts +++ b/packages/protocol-parser/src/decodeDynamicField.test.ts @@ -22,28 +22,28 @@ describe("decodeDynamicField", () => { it("can decode uint256[]", () => { expect( - decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000000") + decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000000"), ).toStrictEqual([0n]); expect( - decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000001") + decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000001"), ).toStrictEqual([1n]); expect( - decodeDynamicField("uint256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + decodeDynamicField("uint256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), ).toStrictEqual([115792089237316195423570985008687907853269984665640564039457584007913129639935n]); expect( - decodeDynamicField("uint256[]", "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe") + decodeDynamicField("uint256[]", "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"), ).toStrictEqual([115792089237316195423570985008687907853269984665640564039457584007913129639934n]); expect( decodeDynamicField( "uint256[]", - "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001" - ) + "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001", + ), ).toStrictEqual([1n, 1n]); expect( decodeDynamicField( "uint256[]", - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ) + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + ), ).toStrictEqual([ 115792089237316195423570985008687907853269984665640564039457584007913129639935n, 115792089237316195423570985008687907853269984665640564039457584007913129639935n, @@ -68,41 +68,41 @@ describe("decodeDynamicField", () => { it("can decode int256[]", () => { expect( - decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000000") + decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000000"), ).toStrictEqual([0n]); expect( - decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000001") + decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000001"), ).toStrictEqual([1n]); expect( - decodeDynamicField("int256[]", "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + decodeDynamicField("int256[]", "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), ).toStrictEqual([57896044618658097711785492504343953926634992332820282019728792003956564819967n]); expect( - decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000000") + decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000000"), ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819968n]); expect( - decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000001") + decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000001"), ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819967n]); expect( - decodeDynamicField("int256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + decodeDynamicField("int256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), ).toStrictEqual([-1n]); expect( decodeDynamicField( "int256[]", - "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ) + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + ), ).toStrictEqual([57896044618658097711785492504343953926634992332820282019728792003956564819967n, -1n]); expect( decodeDynamicField( "int256[]", - "0x80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - ) + "0x80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + ), ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819968n, 0n]); expect( decodeDynamicField( "int256[]", - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000000000000000000000000000000000000000001" - ) + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000000000000000000000000000000000000000001", + ), ).toStrictEqual([-1n, -57896044618658097711785492504343953926634992332820282019728792003956564819967n]); }); @@ -129,13 +129,13 @@ describe("decodeDynamicField", () => { ]); expect(decodeDynamicField("bytes4[]", "0xff00ff00ff00ff00")).toStrictEqual(["0xff00ff00", "0xff00ff00"]); expect( - decodeDynamicField("bytes32[]", "0x0000000000000000000000000000000000000000000000000000000000000001") + decodeDynamicField("bytes32[]", "0x0000000000000000000000000000000000000000000000000000000000000001"), ).toStrictEqual(["0x0000000000000000000000000000000000000000000000000000000000000001"]); expect( decodeDynamicField( "bytes32[]", - "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" - ) + "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", + ), ).toStrictEqual([ "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", @@ -151,10 +151,10 @@ describe("decodeDynamicField", () => { ]); expect(() => decodeDynamicField("address[]", "0x00")).toThrow( - 'Hex value "0x00" has length of 2, but expected a multiple of 40 for address[] type.' + 'Hex value "0x00" has length of 2, but expected a multiple of 40 for address[] type.', ); expect(() => decodeDynamicField("address[]", "0xffffffffffffffffffffffffffffffffffffffffff")).toThrow( - 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected a multiple of 40 for address[] type.' + 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected a multiple of 40 for address[] type.', ); }); @@ -164,7 +164,7 @@ describe("decodeDynamicField", () => { expect(decodeDynamicField("bytes", "0x0001")).toBe("0x0001"); expect(decodeDynamicField("bytes", "0xff00ff00ff00ff00")).toBe("0xff00ff00ff00ff00"); expect(decodeDynamicField("bytes", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe( - "0x0000000000000000000000000000000000000000000000000000000000000001" + "0x0000000000000000000000000000000000000000000000000000000000000001", ); }); diff --git a/packages/protocol-parser/src/decodeDynamicField.ts b/packages/protocol-parser/src/decodeDynamicField.ts index 3fcb63876c..d9eaf52b64 100644 --- a/packages/protocol-parser/src/decodeDynamicField.ts +++ b/packages/protocol-parser/src/decodeDynamicField.ts @@ -14,7 +14,7 @@ import { InvalidHexLengthError, InvalidHexLengthForArrayFieldError } from "./err export function decodeDynamicField< TAbiType extends DynamicAbiType, - TPrimitiveType extends DynamicAbiTypeToPrimitiveType + TPrimitiveType extends DynamicAbiTypeToPrimitiveType, >(abiType: TAbiType, data: Hex): TPrimitiveType { if (abiType === "bytes") { return data as TPrimitiveType; diff --git a/packages/protocol-parser/src/decodeField.ts b/packages/protocol-parser/src/decodeField.ts index b3a63059d5..e6b6d881c7 100644 --- a/packages/protocol-parser/src/decodeField.ts +++ b/packages/protocol-parser/src/decodeField.ts @@ -5,7 +5,7 @@ import { decodeStaticField } from "./decodeStaticField"; export function decodeField< TAbiType extends SchemaAbiType, - TPrimitiveType extends SchemaAbiTypeToPrimitiveType + TPrimitiveType extends SchemaAbiTypeToPrimitiveType, >(abiType: TAbiType, data: Hex): TPrimitiveType { return ( isDynamicAbiType(abiType) ? decodeDynamicField(abiType, data) : decodeStaticField(abiType, data) diff --git a/packages/protocol-parser/src/decodeKey.ts b/packages/protocol-parser/src/decodeKey.ts index 2b11552ad8..bec0695e6a 100644 --- a/packages/protocol-parser/src/decodeKey.ts +++ b/packages/protocol-parser/src/decodeKey.ts @@ -4,12 +4,12 @@ import { decodeKeyTuple } from "./decodeKeyTuple"; export function decodeKey( keySchema: TSchema, - data: readonly Hex[] + data: readonly Hex[], ): SchemaToPrimitives { // TODO: refactor and move all decodeKeyTuple logic into this method so we can delete decodeKeyTuple const keyValues = decodeKeyTuple({ staticFields: Object.values(keySchema), dynamicFields: [] }, data); return Object.fromEntries( - Object.keys(keySchema).map((name, i) => [name, keyValues[i]]) + Object.keys(keySchema).map((name, i) => [name, keyValues[i]]), ) as SchemaToPrimitives; } diff --git a/packages/protocol-parser/src/decodeKeyTuple.test.ts b/packages/protocol-parser/src/decodeKeyTuple.test.ts index 362118332d..cd1c2c14c1 100644 --- a/packages/protocol-parser/src/decodeKeyTuple.test.ts +++ b/packages/protocol-parser/src/decodeKeyTuple.test.ts @@ -6,12 +6,12 @@ describe("decodeKeyTuple", () => { expect( decodeKeyTuple({ staticFields: ["bool"], dynamicFields: [] }, [ "0x0000000000000000000000000000000000000000000000000000000000000000", - ]) + ]), ).toStrictEqual([false]); expect( decodeKeyTuple({ staticFields: ["bool"], dynamicFields: [] }, [ "0x0000000000000000000000000000000000000000000000000000000000000001", - ]) + ]), ).toStrictEqual([true]); }); @@ -24,7 +24,7 @@ describe("decodeKeyTuple", () => { "0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000003", - ]) + ]), ).toStrictEqual([ 42n, -42, diff --git a/packages/protocol-parser/src/decodeKeyTuple.ts b/packages/protocol-parser/src/decodeKeyTuple.ts index 623df1fac1..426806dd68 100644 --- a/packages/protocol-parser/src/decodeKeyTuple.ts +++ b/packages/protocol-parser/src/decodeKeyTuple.ts @@ -8,10 +8,10 @@ import { Schema } from "./common"; export function decodeKeyTuple(keySchema: Schema, keyTuple: readonly Hex[]): StaticPrimitiveType[] { if (keySchema.staticFields.length !== keyTuple.length) { throw new Error( - `key tuple length ${keyTuple.length} does not match key schema length ${keySchema.staticFields.length}` + `key tuple length ${keyTuple.length} does not match key schema length ${keySchema.staticFields.length}`, ); } return keyTuple.map( - (key, index) => decodeAbiParameters([{ type: keySchema.staticFields[index] }], key)[0] as StaticPrimitiveType + (key, index) => decodeAbiParameters([{ type: keySchema.staticFields[index] }], key)[0] as StaticPrimitiveType, ); } diff --git a/packages/protocol-parser/src/decodeRecord.test.ts b/packages/protocol-parser/src/decodeRecord.test.ts index 87e357f599..f09283c4ab 100644 --- a/packages/protocol-parser/src/decodeRecord.test.ts +++ b/packages/protocol-parser/src/decodeRecord.test.ts @@ -6,7 +6,7 @@ describe("decodeRecord", () => { const valueSchema = { staticFields: ["uint32", "uint128"], dynamicFields: ["uint32[]", "string"] } as const; const values = decodeRecord( valueSchema, - "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67" + "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67", ); expect(values).toStrictEqual([1, 2n, [3, 4], "some string"]); }); diff --git a/packages/protocol-parser/src/decodeRecord.ts b/packages/protocol-parser/src/decodeRecord.ts index 411d93327c..1ae389fbcf 100644 --- a/packages/protocol-parser/src/decodeRecord.ts +++ b/packages/protocol-parser/src/decodeRecord.ts @@ -34,7 +34,7 @@ export function decodeRecord(valueSchema: Schema, data: Hex): readonly (StaticPr expectedLength: schemaStaticDataLength, actualLength: actualStaticDataLength, bytesOffset, - } + }, ); } @@ -63,7 +63,7 @@ export function decodeRecord(valueSchema: Schema, data: Hex): readonly (StaticPr expectedLength: dataLayout.totalByteLength, actualLength: actualDynamicDataLength, bytesOffset, - } + }, ); } } diff --git a/packages/protocol-parser/src/decodeStaticField.test.ts b/packages/protocol-parser/src/decodeStaticField.test.ts index 8ad29713aa..307b324a97 100644 --- a/packages/protocol-parser/src/decodeStaticField.test.ts +++ b/packages/protocol-parser/src/decodeStaticField.test.ts @@ -7,22 +7,22 @@ describe("decodeStaticField", () => { expect(decodeStaticField("bool", "0x01")).toBe(true); expect(() => decodeStaticField("bool", "0x0")).toThrow( - 'Hex value "0x0" has length of 1, but expected length of 2 for bool type.' + 'Hex value "0x0" has length of 1, but expected length of 2 for bool type.', ); expect(() => decodeStaticField("bool", "0x1")).toThrow( - 'Hex value "0x1" has length of 1, but expected length of 2 for bool type.' + 'Hex value "0x1" has length of 1, but expected length of 2 for bool type.', ); expect(() => decodeStaticField("bool", "0x000")).toThrow( - 'Hex value "0x000" is an odd length (3). It must be an even length.' + 'Hex value "0x000" is an odd length (3). It must be an even length.', ); expect(() => decodeStaticField("bool", "0x001")).toThrow( - 'Hex value "0x001" is an odd length (3). It must be an even length.' + 'Hex value "0x001" is an odd length (3). It must be an even length.', ); expect(() => decodeStaticField("bool", "0x0000")).toThrow( - 'Hex value "0x0000" has length of 4, but expected length of 2 for bool type.' + 'Hex value "0x0000" has length of 4, but expected length of 2 for bool type.', ); expect(() => decodeStaticField("bool", "0x0001")).toThrow( - 'Hex value "0x0001" has length of 4, but expected length of 2 for bool type.' + 'Hex value "0x0001" has length of 4, but expected length of 2 for bool type.', ); }); @@ -36,10 +36,10 @@ describe("decodeStaticField", () => { expect(decodeStaticField("uint256", "0x0000000000000000000000000000000000000000000000000000000000000000")).toBe(0n); expect(decodeStaticField("uint256", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe(1n); expect(decodeStaticField("uint256", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).toBe( - 115792089237316195423570985008687907853269984665640564039457584007913129639935n + 115792089237316195423570985008687907853269984665640564039457584007913129639935n, ); expect(decodeStaticField("uint256", "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")).toBe( - 115792089237316195423570985008687907853269984665640564039457584007913129639934n + 115792089237316195423570985008687907853269984665640564039457584007913129639934n, ); }); @@ -56,13 +56,13 @@ describe("decodeStaticField", () => { expect(decodeStaticField("int256", "0x0000000000000000000000000000000000000000000000000000000000000000")).toBe(0n); expect(decodeStaticField("int256", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe(1n); expect(decodeStaticField("int256", "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).toBe( - 57896044618658097711785492504343953926634992332820282019728792003956564819967n + 57896044618658097711785492504343953926634992332820282019728792003956564819967n, ); expect(decodeStaticField("int256", "0x8000000000000000000000000000000000000000000000000000000000000000")).toBe( - -57896044618658097711785492504343953926634992332820282019728792003956564819968n + -57896044618658097711785492504343953926634992332820282019728792003956564819968n, ); expect(decodeStaticField("int256", "0x8000000000000000000000000000000000000000000000000000000000000001")).toBe( - -57896044618658097711785492504343953926634992332820282019728792003956564819967n + -57896044618658097711785492504343953926634992332820282019728792003956564819967n, ); expect(decodeStaticField("int256", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).toBe(-1n); }); @@ -72,23 +72,23 @@ describe("decodeStaticField", () => { expect(decodeStaticField("bytes2", "0x0001")).toBe("0x0001"); expect(decodeStaticField("bytes8", "0xff00ff00ff00ff00")).toBe("0xff00ff00ff00ff00"); expect(decodeStaticField("bytes32", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe( - "0x0000000000000000000000000000000000000000000000000000000000000001" + "0x0000000000000000000000000000000000000000000000000000000000000001", ); }); it("can decode address", () => { expect(decodeStaticField("address", "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266")).toBe( - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", ); expect(decodeStaticField("address", "0xffffffffffffffffffffffffffffffffffffffff")).toBe( - "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF" + "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF", ); expect(() => decodeStaticField("address", "0x00")).toThrow( - 'Hex value "0x00" has length of 2, but expected length of 40 for address type.' + 'Hex value "0x00" has length of 2, but expected length of 40 for address type.', ); expect(() => decodeStaticField("address", "0xffffffffffffffffffffffffffffffffffffffffff")).toThrow( - 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected length of 40 for address type.' + 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected length of 40 for address type.', ); }); }); diff --git a/packages/protocol-parser/src/decodeStaticField.ts b/packages/protocol-parser/src/decodeStaticField.ts index e8595d8832..9d2819d307 100644 --- a/packages/protocol-parser/src/decodeStaticField.ts +++ b/packages/protocol-parser/src/decodeStaticField.ts @@ -10,7 +10,7 @@ import { InvalidHexLengthError, InvalidHexLengthForStaticFieldError } from "./er export function decodeStaticField< TAbiType extends StaticAbiType, - TPrimitiveType extends StaticAbiTypeToPrimitiveType + TPrimitiveType extends StaticAbiTypeToPrimitiveType, >(abiType: TAbiType, data: Hex): TPrimitiveType { if (data.length > 3 && data.length % 2 !== 0) { throw new InvalidHexLengthError(data); diff --git a/packages/protocol-parser/src/decodeValue.ts b/packages/protocol-parser/src/decodeValue.ts index bd96093fed..06bb1a4b4a 100644 --- a/packages/protocol-parser/src/decodeValue.ts +++ b/packages/protocol-parser/src/decodeValue.ts @@ -11,6 +11,6 @@ export function decodeValue(valueSchema: TSchema, d const valueTuple = decodeRecord({ staticFields, dynamicFields }, data); return Object.fromEntries( - Object.keys(valueSchema).map((name, i) => [name, valueTuple[i]]) + Object.keys(valueSchema).map((name, i) => [name, valueTuple[i]]), ) as SchemaToPrimitives; } diff --git a/packages/protocol-parser/src/decodeValueArgs.ts b/packages/protocol-parser/src/decodeValueArgs.ts index d9f5e5161f..62966ba93d 100644 --- a/packages/protocol-parser/src/decodeValueArgs.ts +++ b/packages/protocol-parser/src/decodeValueArgs.ts @@ -7,7 +7,7 @@ import { readHex } from "@latticexyz/common"; export function decodeValueArgs( valueSchema: TSchema, - { staticData, encodedLengths, dynamicData }: ValueArgs + { staticData, encodedLengths, dynamicData }: ValueArgs, ): SchemaToPrimitives { return decodeValue( valueSchema, @@ -15,6 +15,6 @@ export function decodeValueArgs( readHex(staticData, 0, staticDataLength(Object.values(valueSchema).filter(isStaticAbiType))), encodedLengths, dynamicData, - ]) + ]), ); } diff --git a/packages/protocol-parser/src/encodeField.ts b/packages/protocol-parser/src/encodeField.ts index 99e977a850..cacfda1caf 100644 --- a/packages/protocol-parser/src/encodeField.ts +++ b/packages/protocol-parser/src/encodeField.ts @@ -4,7 +4,7 @@ import { Hex, encodePacked } from "viem"; export function encodeField( fieldType: TSchemaAbiType, - value: AbiParameterToPrimitiveType<{ type: TSchemaAbiType }> + value: AbiParameterToPrimitiveType<{ type: TSchemaAbiType }>, ): Hex { if (isArrayAbiType(fieldType) && Array.isArray(value)) { const staticFieldType = arrayAbiTypeToStaticAbiType(fieldType); @@ -13,7 +13,7 @@ export function encodeField( ? "0x" : encodePacked( value.map(() => staticFieldType), - value + value, ); } return encodePacked([fieldType], [value]); diff --git a/packages/protocol-parser/src/encodeKeyTuple.test.ts b/packages/protocol-parser/src/encodeKeyTuple.test.ts index 048e0d2921..2d712fdfe3 100644 --- a/packages/protocol-parser/src/encodeKeyTuple.test.ts +++ b/packages/protocol-parser/src/encodeKeyTuple.test.ts @@ -12,8 +12,8 @@ describe("encodeKeyTuple", () => { staticFields: ["bool"], dynamicFields: [], }, - [true] - ) + [true], + ), ).toStrictEqual(["0x0000000000000000000000000000000000000000000000000000000000000001"]); }); @@ -26,7 +26,7 @@ describe("encodeKeyTuple", () => { "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF", true, 3, - ]) + ]), ).toStrictEqual([ "0x000000000000000000000000000000000000000000000000000000000000002a", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd6", diff --git a/packages/protocol-parser/src/encodeLengths.test.ts b/packages/protocol-parser/src/encodeLengths.test.ts index 70d6b53187..8bd77ba7de 100644 --- a/packages/protocol-parser/src/encodeLengths.test.ts +++ b/packages/protocol-parser/src/encodeLengths.test.ts @@ -4,13 +4,13 @@ import { encodeLengths } from "./encodeLengths"; describe("encodeLengths", () => { it("can encode empty tuple", () => { expect(encodeLengths([])).toMatchInlineSnapshot( - '"0x0000000000000000000000000000000000000000000000000000000000000000"' + '"0x0000000000000000000000000000000000000000000000000000000000000000"', ); }); it("can encode bool key tuple", () => { expect(encodeLengths(["0x1234", "0x12345678"])).toMatchInlineSnapshot( - '"0x0000000000000000000000000000000000000004000000000200000000000006"' + '"0x0000000000000000000000000000000000000004000000000200000000000006"', ); }); }); diff --git a/packages/protocol-parser/src/encodeLengths.ts b/packages/protocol-parser/src/encodeLengths.ts index 5a3bbf0827..156e275f84 100644 --- a/packages/protocol-parser/src/encodeLengths.ts +++ b/packages/protocol-parser/src/encodeLengths.ts @@ -7,6 +7,6 @@ export function encodeLengths(values: Hex[]): Hex { return padHex( concatHex([...byteLengths.map((length) => encodeField("uint40", length)), encodeField("uint56", totalByteLength)]), - { size: 32, dir: "left" } + { size: 32, dir: "left" }, ); } diff --git a/packages/protocol-parser/src/encodeRecord.test.ts b/packages/protocol-parser/src/encodeRecord.test.ts index 29222756fa..33be538fd3 100644 --- a/packages/protocol-parser/src/encodeRecord.test.ts +++ b/packages/protocol-parser/src/encodeRecord.test.ts @@ -6,7 +6,7 @@ describe("encodeRecord", () => { const valueSchema = { staticFields: ["uint32", "uint128"], dynamicFields: ["uint32[]", "string"] } as const; const hex = encodeRecord(valueSchema, [1, 2n, [3, 4], "some string"]); expect(hex).toBe( - "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67" + "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67", ); }); diff --git a/packages/protocol-parser/src/encodeRecord.ts b/packages/protocol-parser/src/encodeRecord.ts index b92287830c..6c0e0f4daf 100644 --- a/packages/protocol-parser/src/encodeRecord.ts +++ b/packages/protocol-parser/src/encodeRecord.ts @@ -6,7 +6,7 @@ import { Schema } from "./common"; /** @deprecated use `encodeValue` instead */ export function encodeRecord( valueSchema: Schema, - values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[] + values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[], ): Hex { const staticValues = values.slice(0, valueSchema.staticFields.length) as readonly StaticPrimitiveType[]; const dynamicValues = values.slice(valueSchema.staticFields.length) as readonly DynamicPrimitiveType[]; @@ -18,7 +18,7 @@ export function encodeRecord( if (valueSchema.dynamicFields.length === 0) return `0x${staticData}`; const dynamicDataItems = dynamicValues.map((value, i) => - encodeField(valueSchema.dynamicFields[i], value).replace(/^0x/, "") + encodeField(valueSchema.dynamicFields[i], value).replace(/^0x/, ""), ); const dynamicFieldByteLengths = dynamicDataItems.map((value) => value.length / 2).reverse(); diff --git a/packages/protocol-parser/src/encodeValue.ts b/packages/protocol-parser/src/encodeValue.ts index df85964b65..accb91e0a1 100644 --- a/packages/protocol-parser/src/encodeValue.ts +++ b/packages/protocol-parser/src/encodeValue.ts @@ -4,7 +4,7 @@ import { encodeValueArgs } from "./encodeValueArgs"; export function encodeValue( valueSchema: TSchema, - value: SchemaToPrimitives + value: SchemaToPrimitives, ): Hex { const { staticData, encodedLengths, dynamicData } = encodeValueArgs(valueSchema, value); return concatHex([staticData, encodedLengths, dynamicData]); diff --git a/packages/protocol-parser/src/encodeValueArgs.ts b/packages/protocol-parser/src/encodeValueArgs.ts index 5100f4f753..bc0723f93f 100644 --- a/packages/protocol-parser/src/encodeValueArgs.ts +++ b/packages/protocol-parser/src/encodeValueArgs.ts @@ -13,7 +13,7 @@ import { encodeLengths } from "./encodeLengths"; export function encodeValueArgs( valueSchema: TSchema, - value: SchemaToPrimitives + value: SchemaToPrimitives, ): ValueArgs { const valueSchemaEntries = Object.entries(valueSchema); const staticFields = valueSchemaEntries.filter(([, type]) => isStaticAbiType(type)) as [string, StaticAbiType][]; @@ -23,7 +23,7 @@ export function encodeValueArgs( const encodedStaticValues = staticFields.map(([name, type]) => encodeField(type, value[name] as StaticPrimitiveType)); const encodedDynamicValues = dynamicFields.map(([name, type]) => - encodeField(type, value[name] as DynamicPrimitiveType) + encodeField(type, value[name] as DynamicPrimitiveType), ); const encodedLengths = encodeLengths(encodedDynamicValues); diff --git a/packages/protocol-parser/src/errors.ts b/packages/protocol-parser/src/errors.ts index 1071b89564..168d0eb93d 100644 --- a/packages/protocol-parser/src/errors.ts +++ b/packages/protocol-parser/src/errors.ts @@ -29,7 +29,7 @@ export class InvalidHexLengthForStaticFieldError extends MUDError { super( `Hex value "${value}" has length of ${value.length - 2}, but expected length of ${ staticAbiTypeToByteLength[abiType] * 2 - } for ${abiType} type.` + } for ${abiType} type.`, ); } } @@ -40,7 +40,7 @@ export class InvalidHexLengthForArrayFieldError extends MUDError { super( `Hex value "${value}" has length of ${value.length - 2}, but expected a multiple of ${ staticAbiTypeToByteLength[abiType] * 2 - } for ${abiType}[] type.` + } for ${abiType}[] type.`, ); } } @@ -50,7 +50,7 @@ export class SchemaStaticLengthMismatchError extends MUDError { constructor(schemaData: Hex, definedLength: number, summedLength: number) { super( `Schema "${schemaData}" static data length (${definedLength}) did not match the summed length of all static fields (${summedLength}). ` + - `Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?` + `Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`, ); } } @@ -59,7 +59,7 @@ export class PackedCounterLengthMismatchError extends MUDError { override name = "PackedCounterLengthMismatchError"; constructor(packedCounterData: Hex, definedLength: bigint, summedLength: bigint) { super( - `PackedCounter "${packedCounterData}" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).` + `PackedCounter "${packedCounterData}" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).`, ); } } diff --git a/packages/protocol-parser/src/hexToPackedCounter.test.ts b/packages/protocol-parser/src/hexToPackedCounter.test.ts index 82537cc018..91e6a090e0 100644 --- a/packages/protocol-parser/src/hexToPackedCounter.test.ts +++ b/packages/protocol-parser/src/hexToPackedCounter.test.ts @@ -20,16 +20,16 @@ describe("hexToPackedCounter", () => { it("throws if schema hex data is not bytes32", () => { expect(() => hexToPackedCounter("0x01234")).toThrowErrorMatchingInlineSnapshot( - '"Hex value \\"0x01234\\" has length of 5, but expected length of 64 for a packed counter."' + '"Hex value \\"0x01234\\" has length of 5, but expected length of 64 for a packed counter."', ); }); it("throws if packed counter total byte length doesn't match summed byte length of fields", () => { expect(() => - hexToPackedCounter("0x0000000000000000000000000000400000000020000000002000000000000040") + hexToPackedCounter("0x0000000000000000000000000000400000000020000000002000000000000040"), ).toThrowErrorMatchingInlineSnapshot( // eslint-disable-next-line max-len - '"PackedCounter \\"0x0000000000000000000000000000400000000020000000002000000000000040\\" total bytes length (64) did not match the summed length of all field byte lengths (128)."' + '"PackedCounter \\"0x0000000000000000000000000000400000000020000000002000000000000040\\" total bytes length (64) did not match the summed length of all field byte lengths (128)."', ); }); }); diff --git a/packages/protocol-parser/src/hexToSchema.test.ts b/packages/protocol-parser/src/hexToSchema.test.ts index a73b132bbf..cbff4ee435 100644 --- a/packages/protocol-parser/src/hexToSchema.test.ts +++ b/packages/protocol-parser/src/hexToSchema.test.ts @@ -55,14 +55,14 @@ describe("hexToSchema", () => { it("throws if schema hex data is not bytes32", () => { expect(() => hexToSchema("0x002502045f2381c3c4c5")).toThrow( - 'Hex value "0x002502045f2381c3c4c5" has length of 20, but expected length of 64 for a schema.' + 'Hex value "0x002502045f2381c3c4c5" has length of 20, but expected length of 64 for a schema.', ); }); it("throws if schema static field lengths do not match", () => { expect(() => hexToSchema("0x002502045f2381c3c4c500000000000000000000000000000000000000000000")).toThrow( // eslint-disable-next-line max-len - 'Schema "0x002502045f2381c3c4c500000000000000000000000000000000000000000000" static data length (37) did not match the summed length of all static fields (36). Is `staticAbiTypeToByteLength` up to date with Solidity schema types?' + 'Schema "0x002502045f2381c3c4c500000000000000000000000000000000000000000000" static data length (37) did not match the summed length of all static fields (36). Is `staticAbiTypeToByteLength` up to date with Solidity schema types?', ); }); }); diff --git a/packages/protocol-parser/src/hexToSchema.ts b/packages/protocol-parser/src/hexToSchema.ts index ff16f1e5cc..b0b74211bb 100644 --- a/packages/protocol-parser/src/hexToSchema.ts +++ b/packages/protocol-parser/src/hexToSchema.ts @@ -28,7 +28,7 @@ export function hexToSchema(data: Hex): Schema { if (actualStaticDataLength !== staticDataLength) { console.warn( `Schema "${data}" static data length (${staticDataLength}) did not match the summed length of all static fields (${actualStaticDataLength}). ` + - `Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?` + `Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`, ); throw new SchemaStaticLengthMismatchError(data, staticDataLength, actualStaticDataLength); } diff --git a/packages/protocol-parser/src/schemaToHex.test.ts b/packages/protocol-parser/src/schemaToHex.test.ts index 57e051e5fe..82860e7331 100644 --- a/packages/protocol-parser/src/schemaToHex.test.ts +++ b/packages/protocol-parser/src/schemaToHex.test.ts @@ -4,13 +4,13 @@ import { schemaToHex } from "./schemaToHex"; describe("schemaToHex", () => { it("converts schema to hex", () => { expect(schemaToHex({ staticFields: ["bool"], dynamicFields: [] })).toBe( - "0x0001010060000000000000000000000000000000000000000000000000000000" + "0x0001010060000000000000000000000000000000000000000000000000000000", ); expect(schemaToHex({ staticFields: ["bool"], dynamicFields: ["bool[]"] })).toBe( - "0x0001010160c20000000000000000000000000000000000000000000000000000" + "0x0001010160c20000000000000000000000000000000000000000000000000000", ); expect( - schemaToHex({ staticFields: ["bytes32", "int32"], dynamicFields: ["uint256[]", "address[]", "bytes", "string"] }) + schemaToHex({ staticFields: ["bytes32", "int32"], dynamicFields: ["uint256[]", "address[]", "bytes", "string"] }), ).toBe("0x002402045f2381c3c4c500000000000000000000000000000000000000000000"); }); }); diff --git a/packages/react/src/useComponentValue.ts b/packages/react/src/useComponentValue.ts index fecb60ede4..aa7a7bbd10 100644 --- a/packages/react/src/useComponentValue.ts +++ b/packages/react/src/useComponentValue.ts @@ -13,18 +13,18 @@ import { useEffect, useState } from "react"; export function useComponentValue( component: Component, entity: Entity | undefined, - defaultValue: ComponentValue + defaultValue: ComponentValue, ): ComponentValue; export function useComponentValue( component: Component, - entity: Entity | undefined + entity: Entity | undefined, ): ComponentValue | undefined; export function useComponentValue( component: Component, entity: Entity | undefined, - defaultValue?: ComponentValue + defaultValue?: ComponentValue, ) { const [value, setValue] = useState(entity != null ? getComponentValue(component, entity) : undefined); diff --git a/packages/react/src/useEntityQuery.test.ts b/packages/react/src/useEntityQuery.test.ts index 484a8e80a5..12811c388c 100644 --- a/packages/react/src/useEntityQuery.test.ts +++ b/packages/react/src/useEntityQuery.test.ts @@ -36,7 +36,7 @@ describe("useEntityQuery", () => { const { result } = renderHook(() => useEntityQuery([Has(Position)], { updateOnValueChange: false })); const { result: resultOnValueChange } = renderHook(() => - useEntityQuery([Has(Position)], { updateOnValueChange: true }) + useEntityQuery([Has(Position)], { updateOnValueChange: true }), ); expect(result.current.length).toBe(2); @@ -80,7 +80,7 @@ describe("useEntityQuery", () => { const { result } = renderHook(() => useEntityQuery([Has(Position)], { updateOnValueChange: false })); const { result: resultOnValueChange } = renderHook(() => - useEntityQuery([Has(Position)], { updateOnValueChange: true }) + useEntityQuery([Has(Position)], { updateOnValueChange: true }), ); expect(result.all).toHaveLength(2); diff --git a/packages/react/src/usePromise.ts b/packages/react/src/usePromise.ts index a53806d37d..2c3fbfa111 100644 --- a/packages/react/src/usePromise.ts +++ b/packages/react/src/usePromise.ts @@ -7,7 +7,7 @@ export type UsePromiseResult = PromiseSettledResult> | { status: " export function usePromise(promise: PromiseLike | null | undefined) { const promiseRef = useRef(promise); const [result, setResult] = useState>( - promise == null ? { status: "idle" } : { status: "pending" } + promise == null ? { status: "idle" } : { status: "pending" }, ); useEffect(() => { diff --git a/packages/recs/CHANGELOG.md b/packages/recs/CHANGELOG.md index 4de2c01b38..472da33f59 100644 --- a/packages/recs/CHANGELOG.md +++ b/packages/recs/CHANGELOG.md @@ -339,7 +339,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/recs/src/Component.ts b/packages/recs/src/Component.ts index 58a56e8047..ccc5d038a5 100644 --- a/packages/recs/src/Component.ts +++ b/packages/recs/src/Component.ts @@ -55,7 +55,7 @@ function getComponentName(component: Component) { export function defineComponent( world: World, schema: S, - options?: { id?: string; metadata?: M; indexed?: boolean } + options?: { id?: string; metadata?: M; indexed?: boolean }, ) { if (Object.keys(schema).length === 0) throw new Error("Component schema must have at least one key"); const id = options?.id ?? uuid(); @@ -86,7 +86,7 @@ export function setComponent( component: Component, entity: Entity, value: ComponentValue, - options: ComponentMutationOptions = {} + options: ComponentMutationOptions = {}, ) { const entitySymbol = getEntitySymbol(entity); const prevValue = getComponentValue(component, entity); @@ -110,7 +110,7 @@ export function setComponent( "for entity", entity, ". Existing keys: ", - Object.keys(component.values) + Object.keys(component.values), ); } } @@ -141,7 +141,7 @@ export function updateComponent( entity: Entity, value: Partial>, initialValue?: ComponentValue, - options: ComponentMutationOptions = {} + options: ComponentMutationOptions = {}, ) { const currentValue = getComponentValue(component, entity); if (currentValue === undefined) { @@ -163,7 +163,7 @@ export function updateComponent( export function removeComponent( component: Component, entity: Entity, - options: ComponentMutationOptions = {} + options: ComponentMutationOptions = {}, ) { const entitySymbol = getEntitySymbol(entity); const prevValue = getComponentValue(component, entity); @@ -184,7 +184,7 @@ export function removeComponent( component: Component, - entity: Entity + entity: Entity, ): boolean { const entitySymbol = getEntitySymbol(entity); const map = Object.values(component.values)[0]; @@ -201,7 +201,7 @@ export function hasComponent( */ export function getComponentValue( component: Component, - entity: Entity + entity: Entity, ): ComponentValue | undefined { const value: Record = {}; const entitySymbol = getEntitySymbol(entity); @@ -230,7 +230,7 @@ export function getComponentValue( */ export function getComponentValueStrict( component: Component, - entity: Entity + entity: Entity, ): ComponentValue { const value = getComponentValue(component, entity); if (!value) throw new Error(`No value for component ${getComponentName(component)} on entity ${entity}`); @@ -253,7 +253,7 @@ export function getComponentValueStrict( */ export function componentValueEquals( a?: Partial>, - b?: ComponentValue + b?: ComponentValue, ): boolean { if (!a && !b) return true; if (!a || !b) return false; @@ -276,7 +276,7 @@ export function componentValueEquals( */ export function withValue( component: Component, - value: ComponentValue + value: ComponentValue, ): [Component, ComponentValue] { return [component, value]; } @@ -290,7 +290,7 @@ export function withValue( */ export function getEntitiesWithValue( component: Component | Indexer, - value: Partial> + value: Partial>, ): Set { // Shortcut for indexers if (isIndexer(component) && isFullComponentValue(component, value)) { @@ -315,7 +315,7 @@ export function getEntitiesWithValue( * @returns Set of all entities in the given component. */ export function getComponentEntities( - component: Component + component: Component, ): IterableIterator { return component.entities(); } @@ -335,7 +335,7 @@ export function getComponentEntities( * @returns overridable component */ export function overridableComponent( - component: Component + component: Component, ): OverridableComponent { let nonce = 0; @@ -457,7 +457,7 @@ export function overridableComponent !overriddenEntityValues.get(getEntitySymbol(e.entity))), - map((update) => ({ ...update, component: overriddenComponent })) + map((update) => ({ ...update, component: overriddenComponent })), ) .subscribe(update$); @@ -475,7 +475,7 @@ export function clearLocalCache(component: Component, uniqueWorldIdentifier?: st // Note: Only proof of concept for now - use this only for component that do not update frequently export function createLocalCache( component: Component, - uniqueWorldIdentifier?: string + uniqueWorldIdentifier?: string, ): Component { const { world, update$, values } = component; const cacheId = getLocalCacheId(component as Component, uniqueWorldIdentifier); @@ -509,7 +509,7 @@ export function createLocalCache { numUpdates++; const encoded = JSON.stringify( - Object.entries(mapObject(values, (m) => [...m.entries()].map((e) => [getEntityString(e[0]), e[1]]))) + Object.entries(mapObject(values, (m) => [...m.entries()].map((e) => [getEntityString(e[0]), e[1]]))), ); localStorage.setItem(cacheId, encoded); if (numUpdates > 200) { @@ -520,7 +520,7 @@ export function createLocalCache( - component: Component + component: Component, ): Indexer { const valueToEntities = new Map>(); diff --git a/packages/recs/src/Query.spec.ts b/packages/recs/src/Query.spec.ts index b75f91b474..1c200a5d34 100644 --- a/packages/recs/src/Query.spec.ts +++ b/packages/recs/src/Query.spec.ts @@ -98,27 +98,27 @@ describe("Query", () => { expect(runQuery([HasValue(OwnedByEntity, { value: Player })])).toEqual(new Set([Depth1])); expect(runQuery([ProxyExpand(OwnedByEntity, 0), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1]) + new Set([Depth1]), ); expect(runQuery([ProxyExpand(OwnedByEntity, 1), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1, Depth2]) + new Set([Depth1, Depth2]), ); expect(runQuery([ProxyExpand(OwnedByEntity, 2), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1, Depth2, Depth3]) + new Set([Depth1, Depth2, Depth3]), ); expect(runQuery([ProxyExpand(OwnedByEntity, 3), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1, Depth2, Depth3, Depth4]) + new Set([Depth1, Depth2, Depth3, Depth4]), ); expect(runQuery([ProxyExpand(OwnedByEntity, 4), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1, Depth2, Depth3, Depth4, Depth5]) + new Set([Depth1, Depth2, Depth3, Depth4, Depth5]), ); expect( - runQuery([ProxyExpand(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(OwnedByEntity, { value: Player })]) + runQuery([ProxyExpand(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(OwnedByEntity, { value: Player })]), ).toEqual(new Set([Depth1, Depth2, Depth3, Depth4, Depth5])); }); @@ -132,8 +132,8 @@ describe("Query", () => { expect( runQuery( [ProxyRead(OwnedByEntity, 1), HasValue(Name, { name: "Alice" })], - new Set([Depth1, Depth2, Depth3]) // Provide an initial set of entities - ) + new Set([Depth1, Depth2, Depth3]), // Provide an initial set of entities + ), ).toEqual(new Set([Depth1])); expect( @@ -142,7 +142,7 @@ describe("Query", () => { HasValue(Name, { name: "Alice" }), // Get all entities with name Alice or owned by Alice ProxyExpand(OwnedByEntity, 0), // Turn off proxy expand NotValue(Name, { name: "Alice" }), // Filter Alice, only keep entities owned by Alice - ]) + ]), ).toEqual(new Set([Depth1])); expect( @@ -151,15 +151,15 @@ describe("Query", () => { HasValue(Name, { name: "Alice" }), // Get all child entities of Alice (including alice) ProxyExpand(OwnedByEntity, 0), // Turn off proxy expand NotValue(Name, { name: "Alice" }), // Filter Alice, only keep entities owned by Alice - ]) + ]), ).toEqual(new Set([Depth1, Depth2, Depth3, Depth4])); // Get all entities from the initial set [Depth3] that have an indirect owner called Alice expect( runQuery( [ProxyRead(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(Name, { name: "Alice" })], - new Set([Depth3]) // Provide an initial set of entities - ) + new Set([Depth3]), // Provide an initial set of entities + ), ).toEqual(new Set([Depth3])); // Get all entities that have an indirect owner called Alice @@ -171,8 +171,8 @@ describe("Query", () => { ProxyRead(OwnedByEntity, 0), NotValue(Name, { name: "Alice" }), ], - new Set([Player, Depth1, Depth2, Depth3, Depth4]) // Provide an initial set of entities - ) + new Set([Player, Depth1, Depth2, Depth3, Depth4]), // Provide an initial set of entities + ), ).toEqual(new Set([Depth1, Depth2, Depth3, Depth4])); // Get all entities from the initial set [Depth3] that have an indirect owner called Alice and their direct child @@ -183,8 +183,8 @@ describe("Query", () => { ProxyExpand(OwnedByEntity, 1), HasValue(Name, { name: "Alice" }), ], - new Set([Depth2]) // Provide an initial set of entities - ) + new Set([Depth2]), // Provide an initial set of entities + ), ).toEqual(new Set([Depth2, Depth3])); }); @@ -204,15 +204,15 @@ describe("Query", () => { createEntity(world, [withValue(Position, { x: 1, y: 1 })]); expect(runQuery([ProxyExpand(FromPrototype, 1), Has(CanMove), Not(Prototype)])).toEqual( - new Set([instance1, instance2]) + new Set([instance1, instance2]), ); expect(runQuery([Has(Position), ProxyRead(FromPrototype, 1), Has(CanMove)])).toEqual( - new Set([instance1, instance2]) + new Set([instance1, instance2]), ); expect(runQuery([ProxyRead(FromPrototype, 1), Has(Position), Has(CanMove)])).toEqual( - new Set([instance1, instance2]) + new Set([instance1, instance2]), ); }); @@ -287,7 +287,7 @@ describe("Query", () => { Has(CanMove), // ...have the CanMove component... ProxyRead(OwnedByEntity, Number.MAX_SAFE_INTEGER), // ...and for whose owner holds... NotValue(Name, { name: "Alice" }), // ...their name is not Alice - ]) + ]), ).toEqual(new Set([Instance3, Entity8])); }); @@ -343,14 +343,14 @@ describe("Query", () => { entity: entities[0], component: CanMove, value: [{ value: true }, undefined], - }) + }), ); expect(mock).toHaveBeenCalledWith( expect.objectContaining({ entity: entities[1], component: CanMove, value: [{ value: true }, undefined], - }) + }), ); expect(mock).toBeCalledTimes(2); @@ -360,7 +360,7 @@ describe("Query", () => { entity: entities[2], component: CanMove, value: [{ value: true }, undefined], - }) + }), ); expect(mock).toHaveBeenCalledTimes(3); }); @@ -388,7 +388,7 @@ describe("Query", () => { entity: entity1, component: CanMove, value: [undefined, { value: true }], - }) + }), ); removeComponent(CanMove, entity2); @@ -398,7 +398,7 @@ describe("Query", () => { entity: entity2, component: CanMove, value: [undefined, { value: true }], - }) + }), ); }); }); @@ -617,7 +617,7 @@ describe("Query", () => { const query1 = defineQuery( [ProxyRead(OwnedByEntity, 1), HasValue(Name, { name: "Alice" })], - { initialSet: new Set([Depth1, Depth2, Depth3]) } // Provide an initial set of entities + { initialSet: new Set([Depth1, Depth2, Depth3]) }, // Provide an initial set of entities ); query1.update$.subscribe(); @@ -639,7 +639,7 @@ describe("Query", () => { const query4 = defineQuery( [ProxyRead(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(Name, { name: "Alice" })], - { initialSet: new Set([Depth3]) } // Provide an initial set of entities + { initialSet: new Set([Depth3]) }, // Provide an initial set of entities ); query4.update$.subscribe(); @@ -650,7 +650,7 @@ describe("Query", () => { ProxyRead(OwnedByEntity, 0), NotValue(Name, { name: "Alice" }), ], - { initialSet: new Set([Player, Depth1, Depth2, Depth3, Depth4]) } // Provide an initial set of entities + { initialSet: new Set([Player, Depth1, Depth2, Depth3, Depth4]) }, // Provide an initial set of entities ); query5.update$.subscribe(); @@ -660,7 +660,7 @@ describe("Query", () => { ProxyExpand(OwnedByEntity, 1), HasValue(Name, { name: "Alice" }), ], - { initialSet: new Set([Depth2]) } // Provide an initial set of entities + { initialSet: new Set([Depth2]) }, // Provide an initial set of entities ); query6.update$.subscribe(); diff --git a/packages/recs/src/Query.ts b/packages/recs/src/Query.ts index b32c2e2563..2ebce7fa81 100644 --- a/packages/recs/src/Query.ts +++ b/packages/recs/src/Query.ts @@ -88,7 +88,7 @@ export function Not(component: Component): NotQueryFragment */ export function HasValue( component: Component, - value: Partial> + value: Partial>, ): HasValueQueryFragment { return { type: QueryFragmentType.HasValue, component, value }; } @@ -112,7 +112,7 @@ export function HasValue( */ export function NotValue( component: Component, - value: Partial> + value: Partial>, ): NotValueQueryFragment { return { type: QueryFragmentType.NotValue, component, value }; } @@ -199,7 +199,7 @@ function passesQueryFragment(entity: Entity, fragment: EntityQ * @returns True if the query fragment is positive, else false. */ function isPositiveFragment( - fragment: QueryFragment + fragment: QueryFragment, ): fragment is HasQueryFragment | HasValueQueryFragment { return fragment.type === QueryFragmentType.Has || fragment.type == QueryFragmentType.HasValue; } @@ -211,7 +211,7 @@ function isPositiveFragment( * @returns True if the query fragment is negative, else false. */ function isNegativeFragment( - fragment: QueryFragment + fragment: QueryFragment, ): fragment is NotQueryFragment | NotValueQueryFragment { return fragment.type === QueryFragmentType.Not || fragment.type == QueryFragmentType.NotValue; } @@ -253,7 +253,7 @@ function isBreakingPassState(passes: boolean, fragment: EntityQueryFragment( entity: Entity, fragment: EntityQueryFragment, - proxyRead: ProxyReadQueryFragment + proxyRead: ProxyReadQueryFragment, ): boolean | null { let proxyEntity = entity; let passes = false; @@ -288,7 +288,7 @@ function passesQueryFragmentProxy( export function getChildEntities( entity: Entity, component: Component<{ value: Type.Entity }>, - depth: number + depth: number, ): Set { if (depth === 0) return new Set(); @@ -416,7 +416,7 @@ export function runQuery(fragments: QueryFragment[], initialSet?: Set): */ export function defineQuery( fragments: QueryFragment[], - options?: { runOnInit?: boolean; initialSet?: Set } + options?: { runOnInit?: boolean; initialSet?: Set }, ): { update$: Observable; matching: ObservableSet; @@ -503,7 +503,7 @@ export function defineQuery( return { ...update, type: UpdateType.Enter }; } }), - filterNullish() + filterNullish(), ); return { @@ -521,7 +521,7 @@ export function defineQuery( */ export function defineUpdateQuery( fragments: QueryFragment[], - options?: { runOnInit?: boolean } + options?: { runOnInit?: boolean }, ): Observable { return defineQuery(fragments, options).update$.pipe(filter((e) => e.type === UpdateType.Update)); } @@ -535,7 +535,7 @@ export function defineUpdateQuery( */ export function defineEnterQuery( fragments: QueryFragment[], - options?: { runOnInit?: boolean } + options?: { runOnInit?: boolean }, ): Observable { return defineQuery(fragments, options).update$.pipe(filter((e) => e.type === UpdateType.Enter)); } @@ -549,7 +549,7 @@ export function defineEnterQuery( */ export function defineExitQuery( fragments: QueryFragment[], - options?: { runOnInit?: boolean } + options?: { runOnInit?: boolean }, ): Observable { return defineQuery(fragments, options).update$.pipe(filter((e) => e.type === UpdateType.Exit)); } diff --git a/packages/recs/src/System.spec.ts b/packages/recs/src/System.spec.ts index 2f872323f6..4c0a6680a3 100644 --- a/packages/recs/src/System.spec.ts +++ b/packages/recs/src/System.spec.ts @@ -100,13 +100,13 @@ describe("System", () => { expect(mock).toHaveBeenCalledTimes(1); expect(mock).toHaveBeenCalledWith( - expect.objectContaining({ entity: entity1, component: CanMove, value: [{ value: true }, undefined] }) + expect.objectContaining({ entity: entity1, component: CanMove, value: [{ value: true }, undefined] }), ); const entity2 = createEntity(world, [withValue(CanMove, { value: true })]); expect(mock).toHaveBeenCalledTimes(2); expect(mock).toHaveBeenCalledWith( - expect.objectContaining({ entity: entity2, component: CanMove, value: [{ value: true }, undefined] }) + expect.objectContaining({ entity: entity2, component: CanMove, value: [{ value: true }, undefined] }), ); }); @@ -126,13 +126,13 @@ describe("System", () => { expect(mock).toHaveBeenCalledTimes(1); expect(mock).toHaveBeenCalledWith( - expect.objectContaining({ entity: entity1, component: CanMove, value: [undefined, { value: true }] }) + expect.objectContaining({ entity: entity1, component: CanMove, value: [undefined, { value: true }] }), ); removeComponent(CanMove, entity2); expect(mock).toHaveBeenCalledTimes(2); expect(mock).toHaveBeenCalledWith( - expect.objectContaining({ entity: entity2, component: CanMove, value: [undefined, { value: true }] }) + expect.objectContaining({ entity: entity2, component: CanMove, value: [undefined, { value: true }] }), ); }); }); diff --git a/packages/recs/src/System.ts b/packages/recs/src/System.ts index eaf8d2b2a0..6f91498bd3 100644 --- a/packages/recs/src/System.ts +++ b/packages/recs/src/System.ts @@ -36,7 +36,7 @@ export function defineUpdateSystem( world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { defineRxSystem(world, defineUpdateQuery(query, options), system); } @@ -56,7 +56,7 @@ export function defineEnterSystem( world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { defineRxSystem(world, defineEnterQuery(query, options), system); } @@ -76,7 +76,7 @@ export function defineExitSystem( world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { defineRxSystem(world, defineExitQuery(query, options), system); } @@ -96,7 +96,7 @@ export function defineSystem( world: World, query: QueryFragment[], system: (update: ComponentUpdate & { type: UpdateType }) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { defineRxSystem(world, defineQuery(query, options).update$, system); } @@ -116,7 +116,7 @@ export function defineComponentSystem( world: World, component: Component, system: (update: ComponentUpdate) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { const initial$ = options?.runOnInit ? from(getComponentEntities(component)).pipe(toUpdateStream(component)) : EMPTY; defineRxSystem(world, concat(initial$, component.update$), system); @@ -135,7 +135,7 @@ export function defineSyncSystem( query: QueryFragment[], component: (entity: Entity) => Component, value: (entity: Entity) => ComponentValue, - options: { update?: boolean; runOnInit?: boolean } = { update: false, runOnInit: true } + options: { update?: boolean; runOnInit?: boolean } = { update: false, runOnInit: true }, ) { defineSystem( world, @@ -145,6 +145,6 @@ export function defineSyncSystem( if (type === UpdateType.Exit) removeComponent(component(entity), entity); if (options?.update && type === UpdateType.Update) setComponent(component(entity), entity, value(entity)); }, - options + options, ); } diff --git a/packages/recs/src/deprecated/createActionSystem.spec.ts b/packages/recs/src/deprecated/createActionSystem.spec.ts index b1d0c0653f..ac224b2261 100644 --- a/packages/recs/src/deprecated/createActionSystem.spec.ts +++ b/packages/recs/src/deprecated/createActionSystem.spec.ts @@ -177,7 +177,7 @@ describe("ActionSystem", () => { expect(runQuery([HasValue(Action, { on: settlement1 })])).toEqual(new Set([entity1])); expect(runQuery([HasValue(Action, { on: settlement2 })])).toEqual(new Set([entity2])); expect(runQuery([HasValue(Action, { state: ActionState.Requested })])).toEqual( - new Set([entity1, entity2, entity3]) + new Set([entity1, entity2, entity3]), ); }); diff --git a/packages/recs/src/deprecated/createActionSystem.ts b/packages/recs/src/deprecated/createActionSystem.ts index 1cbe367ac1..94b245fce7 100644 --- a/packages/recs/src/deprecated/createActionSystem.ts +++ b/packages/recs/src/deprecated/createActionSystem.ts @@ -15,7 +15,7 @@ export type ActionSystem = ReturnType; export function createActionSystem( world: World, txReduced$: Observable, - waitForTransaction?: (tx: string) => Promise + waitForTransaction?: (tx: string) => Promise, ) { // Action component const Action = defineActionComponent(world); @@ -40,7 +40,7 @@ export function createActionSystem( * @returns Components including pending updates */ function withOptimisticUpdates( - component: Component + component: Component, ): OverridableComponent { const optimisticComponent = componentsWithOptimisticUpdates[component.id] || overridableComponent(component); @@ -99,7 +99,7 @@ export function createActionSystem( // This subscriotion makes sure the action requirement is checked again every time // one of the referenced components changes or the pending updates map changes const subscription = merge( - ...Object.values(action.componentsWithOptimisticUpdates).map((c) => c.update$) + ...Object.values(action.componentsWithOptimisticUpdates).map((c) => c.update$), ).subscribe(() => checkRequirement(action)); checkRequirement(action); disposer.set(action.id, { dispose: () => subscription?.unsubscribe() }); diff --git a/packages/recs/src/deprecated/defineActionComponent.ts b/packages/recs/src/deprecated/defineActionComponent.ts index 6d73b4882e..3da5829a50 100644 --- a/packages/recs/src/deprecated/defineActionComponent.ts +++ b/packages/recs/src/deprecated/defineActionComponent.ts @@ -12,7 +12,7 @@ export function defineActionComponent(world: World) { overrides: Type.OptionalStringArray, txHash: Type.OptionalString, }, - { id: "Action" } + { id: "Action" }, ); return Action as Component, Metadata, T>; } diff --git a/packages/recs/src/deprecated/waitForActionCompletion.ts b/packages/recs/src/deprecated/waitForActionCompletion.ts index c271c29ce5..e7378bab57 100644 --- a/packages/recs/src/deprecated/waitForActionCompletion.ts +++ b/packages/recs/src/deprecated/waitForActionCompletion.ts @@ -5,7 +5,7 @@ import { waitForComponentValueIn } from "./waitForComponentValueIn"; export async function waitForActionCompletion( Action: ReturnType, - entity: Entity + entity: Entity, ): Promise { return waitForComponentValueIn(Action, entity, [ { state: ActionState.Cancelled }, diff --git a/packages/recs/src/deprecated/waitForComponentValueIn.ts b/packages/recs/src/deprecated/waitForComponentValueIn.ts index 97fba687aa..318649b381 100644 --- a/packages/recs/src/deprecated/waitForComponentValueIn.ts +++ b/packages/recs/src/deprecated/waitForComponentValueIn.ts @@ -6,7 +6,7 @@ import { Component, Metadata, Entity, ComponentValue, Schema } from "../types"; export function waitForComponentValueIn( component: Component, entity: Entity, - values: Partial>[] + values: Partial>[], ): Promise { const [resolve, , promise] = deferred(); @@ -19,13 +19,13 @@ export function waitForComponentValueIn( const value$ = component.update$.pipe( filter((update) => update.entity === entity), // Ignore updates of other entities - map((update) => update.value[0]) // Map the update to the current value + map((update) => update.value[0]), // Map the update to the current value ); const subscription = value$ .pipe( startWith(getComponentValue(component, entity)), - filter((currentValue) => Boolean(values.find((searchValue) => componentValueEquals(searchValue, currentValue)))) + filter((currentValue) => Boolean(values.find((searchValue) => componentValueEquals(searchValue, currentValue)))), ) .subscribe(() => { resolve(); diff --git a/packages/recs/src/utils.ts b/packages/recs/src/utils.ts index 4407acc17a..33989a7ec5 100644 --- a/packages/recs/src/utils.ts +++ b/packages/recs/src/utils.ts @@ -12,7 +12,7 @@ import { Component, ComponentUpdate, ComponentValue, Entity, Indexer, Schema } f */ export function isComponentUpdate( update: ComponentUpdate, - component: Component + component: Component, ): update is ComponentUpdate { return update.component === component; } @@ -62,7 +62,7 @@ export function isIndexer(c: Component | Indexer): c is */ export function isFullComponentValue( component: Component, - value: Partial> + value: Partial>, ): value is ComponentValue { return Object.keys(component.schema).every((key) => key in value); } diff --git a/packages/schema-type/src/typescript/arrayAbiTypes.ts b/packages/schema-type/src/typescript/arrayAbiTypes.ts index 76c7d69673..00dc9a733c 100644 --- a/packages/schema-type/src/typescript/arrayAbiTypes.ts +++ b/packages/schema-type/src/typescript/arrayAbiTypes.ts @@ -11,7 +11,7 @@ export function isArrayAbiType(abiType: string): } export function arrayAbiTypeToStaticAbiType( - abiType: T + abiType: T, ): ArrayAbiTypeToStaticAbiType { return abiType.replace(arrayAbiTypePattern, "") as ArrayAbiTypeToStaticAbiType; } diff --git a/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts b/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts index 02982cc2a1..13c9b7c977 100644 --- a/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts +++ b/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts @@ -8,5 +8,5 @@ export type AbiTypeToPrimitiveType = T extends `${infer Static ? StaticAbiTypeToPrimitiveType[] : never : T extends AbiType - ? StaticAbiTypeToPrimitiveType - : never; + ? StaticAbiTypeToPrimitiveType + : never; diff --git a/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts b/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts index fb7f484ad9..9e0d93640a 100644 --- a/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts +++ b/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts @@ -2,5 +2,5 @@ import { SchemaTypeToAbiType } from "./SchemaTypeToAbiType"; import { SchemaType } from "../SchemaType"; export const AbiTypeToSchemaType = Object.fromEntries( - Object.entries(SchemaTypeToAbiType).map(([schemaType, abiType]) => [abiType, parseInt(schemaType) as SchemaType]) + Object.entries(SchemaTypeToAbiType).map(([schemaType, abiType]) => [abiType, parseInt(schemaType) as SchemaType]), ) satisfies Record; diff --git a/packages/schema-type/src/typescript/deprecated/types/StaticAbiTypes.ts b/packages/schema-type/src/typescript/deprecated/types/StaticAbiTypes.ts index d4b3506c13..db658108b5 100644 --- a/packages/schema-type/src/typescript/deprecated/types/StaticAbiTypes.ts +++ b/packages/schema-type/src/typescript/deprecated/types/StaticAbiTypes.ts @@ -6,5 +6,5 @@ import { StaticSchemaType } from "./StaticSchemaType"; export type StaticAbiType = (typeof SchemaTypeToAbiType)[StaticSchemaType]; export const StaticAbiTypes = AbiTypes.filter( - (abiType) => getStaticByteLength(AbiTypeToSchemaType[abiType]) > 0 + (abiType) => getStaticByteLength(AbiTypeToSchemaType[abiType]) > 0, ) as StaticAbiType[]; diff --git a/packages/schema-type/src/typescript/schemaAbiTypes.test.ts b/packages/schema-type/src/typescript/schemaAbiTypes.test.ts index 6d23754108..df77fed6f8 100644 --- a/packages/schema-type/src/typescript/schemaAbiTypes.test.ts +++ b/packages/schema-type/src/typescript/schemaAbiTypes.test.ts @@ -9,7 +9,7 @@ describe("schemaAbiTypes", () => { const soliditySchemaTypes = matches?.[1].replace(/\s/g, "").split(",") ?? []; const soliditySchemaTypesAsAbiTypes = soliditySchemaTypes.map((soliditySchemaType) => - soliditySchemaType.replace(/_ARRAY$/, "[]").toLowerCase() + soliditySchemaType.replace(/_ARRAY$/, "[]").toLowerCase(), ); expect(soliditySchemaTypesAsAbiTypes).toStrictEqual(schemaAbiTypes); diff --git a/packages/schema-type/src/typescript/utils.ts b/packages/schema-type/src/typescript/utils.ts index 65d1a05c65..543d6fd6d9 100644 --- a/packages/schema-type/src/typescript/utils.ts +++ b/packages/schema-type/src/typescript/utils.ts @@ -3,21 +3,22 @@ import { Hex } from "viem"; export type TupleSplit = O["length"] extends N ? [O, T] : T extends readonly [infer F, ...infer R] - ? TupleSplit - : [O, T]; + ? TupleSplit + : [O, T]; -export type LiteralToBroad = T extends Readonly> - ? readonly LiteralToBroad[] - : T extends Array - ? LiteralToBroad[] - : T extends number - ? number - : T extends bigint - ? bigint - : T extends Hex - ? Hex - : T extends boolean - ? boolean - : T extends string - ? string - : never; +export type LiteralToBroad = + T extends Readonly> + ? readonly LiteralToBroad[] + : T extends Array + ? LiteralToBroad[] + : T extends number + ? number + : T extends bigint + ? bigint + : T extends Hex + ? Hex + : T extends boolean + ? boolean + : T extends string + ? string + : never; diff --git a/packages/services/protobuf/ts/faucet/faucet.ts b/packages/services/protobuf/ts/faucet/faucet.ts index 0bdb04e62f..c60dc04035 100644 --- a/packages/services/protobuf/ts/faucet/faucet.ts +++ b/packages/services/protobuf/ts/faucet/faucet.ts @@ -231,7 +231,7 @@ export const FaucetStore = { } return acc; }, - {} + {}, ); message.usernameToAddress = Object.entries(object.usernameToAddress ?? {}).reduce<{ [key: string]: string }>( (acc, [key, value]) => { @@ -240,7 +240,7 @@ export const FaucetStore = { } return acc; }, - {} + {}, ); message.latestDrip = Object.entries(object.latestDrip ?? {}).reduce<{ [key: string]: number }>( (acc, [key, value]) => { @@ -249,7 +249,7 @@ export const FaucetStore = { } return acc; }, - {} + {}, ); message.totalDripCount = object.totalDripCount ?? 0; return message; @@ -1092,24 +1092,24 @@ export interface FaucetServiceImplementation { dripVerifyTweet(request: DripRequest, context: CallContext & CallContextExt): Promise>; timeUntilDrip( request: DripRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; getLinkedTwitters( request: GetLinkedTwittersRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; getLinkedTwitterForAddress( request: LinkedTwitterForAddressRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; getLinkedAddressForTwitter( request: LinkedAddressForTwitterRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; /** Admin utility endpoints for modifying state. Requires a signature with faucet private key. */ setLinkedTwitter( request: SetLinkedTwitterRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; } @@ -1119,24 +1119,24 @@ export interface FaucetServiceClient { dripVerifyTweet(request: DeepPartial, options?: CallOptions & CallOptionsExt): Promise; timeUntilDrip( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; getLinkedTwitters( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; getLinkedTwitterForAddress( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; getLinkedAddressForTwitter( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; /** Admin utility endpoints for modifying state. Requires a signature with faucet private key. */ setLinkedTwitter( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; } @@ -1164,12 +1164,12 @@ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefi export type DeepPartial = T extends Builtin ? T : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial; + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; function longToNumber(long: Long): number { if (long.gt(Number.MAX_SAFE_INTEGER)) { diff --git a/packages/services/ts/faucet/createFaucetService.ts b/packages/services/ts/faucet/createFaucetService.ts index f82eb82c22..ea0b1c565b 100644 --- a/packages/services/ts/faucet/createFaucetService.ts +++ b/packages/services/ts/faucet/createFaucetService.ts @@ -8,7 +8,7 @@ import { FromTsProtoServiceDefinition } from "nice-grpc-web/lib/service-definiti * @returns FaucetServiceClient */ export function createFaucetService( - url: string + url: string, ): RawClient> { return createClient(FaucetServiceDefinition, createChannel(url)); } diff --git a/packages/solhint-plugin-mud/src/rules/NoMsgSender.ts b/packages/solhint-plugin-mud/src/rules/NoMsgSender.ts index 1c81e6ef51..fb3751c4dd 100644 --- a/packages/solhint-plugin-mud/src/rules/NoMsgSender.ts +++ b/packages/solhint-plugin-mud/src/rules/NoMsgSender.ts @@ -29,7 +29,7 @@ export class NoMsgSender implements SolhintRule { this.reporter.error( node, this.ruleId, - `Systems and their libraries should use "_msgSender()" or "_world()" instead of "msg.sender".` + `Systems and their libraries should use "_msgSender()" or "_world()" instead of "msg.sender".`, ); } } diff --git a/packages/solhint-plugin-mud/src/rules/SystemFileName.ts b/packages/solhint-plugin-mud/src/rules/SystemFileName.ts index 2e8706fbba..337cebb1d5 100644 --- a/packages/solhint-plugin-mud/src/rules/SystemFileName.ts +++ b/packages/solhint-plugin-mud/src/rules/SystemFileName.ts @@ -46,7 +46,7 @@ export class SystemFileName implements SolhintRule { this.reporter.error( node, this.ruleId, - `System file must contain a contract with a matching name "${expectedContractName}"` + `System file must contain a contract with a matching name "${expectedContractName}"`, ); } } diff --git a/packages/store-indexer/CHANGELOG.md b/packages/store-indexer/CHANGELOG.md index 10ee41a923..f5b485fae7 100644 --- a/packages/store-indexer/CHANGELOG.md +++ b/packages/store-indexer/CHANGELOG.md @@ -594,7 +594,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/store-indexer/bin/parseEnv.ts b/packages/store-indexer/bin/parseEnv.ts index 876e4109c4..3278469f25 100644 --- a/packages/store-indexer/bin/parseEnv.ts +++ b/packages/store-indexer/bin/parseEnv.ts @@ -22,7 +22,7 @@ export const indexerEnvSchema = z.intersection( RPC_HTTP_URL: z.string().optional(), RPC_WS_URL: z.string(), }), - ]) + ]), ); export function parseEnv(envSchema: TSchema): z.infer { diff --git a/packages/store-indexer/bin/postgres-decoded-indexer.ts b/packages/store-indexer/bin/postgres-decoded-indexer.ts index 6bad5ec347..d21eb6bf85 100644 --- a/packages/store-indexer/bin/postgres-decoded-indexer.ts +++ b/packages/store-indexer/bin/postgres-decoded-indexer.ts @@ -22,8 +22,8 @@ const env = parseEnv( HEALTHCHECK_HOST: z.string().optional(), HEALTHCHECK_PORT: z.coerce.number().optional(), SENTRY_DSN: z.string().optional(), - }) - ) + }), + ), ); const transports: Transport[] = [ @@ -80,9 +80,10 @@ let isCaughtUp = false; combineLatest([latestBlockNumber$, storedBlockLogs$]) .pipe( filter( - ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => latestBlockNumber === lastBlockNumberProcessed + ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => + latestBlockNumber === lastBlockNumberProcessed, ), - first() + first(), ) .subscribe(() => { isCaughtUp = true; @@ -103,12 +104,12 @@ if (env.HEALTHCHECK_HOST != null || env.HEALTHCHECK_PORT != null) { server.use( healthcheck({ isReady: () => isCaughtUp, - }) + }), ); server.use(helloWorld()); server.listen({ host: env.HEALTHCHECK_HOST, port: env.HEALTHCHECK_PORT }); console.log( - `postgres indexer healthcheck server listening on http://${env.HEALTHCHECK_HOST}:${env.HEALTHCHECK_PORT}` + `postgres indexer healthcheck server listening on http://${env.HEALTHCHECK_HOST}:${env.HEALTHCHECK_PORT}`, ); } diff --git a/packages/store-indexer/bin/postgres-frontend.ts b/packages/store-indexer/bin/postgres-frontend.ts index 037a53cddf..f95d80919c 100644 --- a/packages/store-indexer/bin/postgres-frontend.ts +++ b/packages/store-indexer/bin/postgres-frontend.ts @@ -20,8 +20,8 @@ const env = parseEnv( z.object({ DATABASE_URL: z.string(), SENTRY_DSN: z.string().optional(), - }) - ) + }), + ), ); const database = postgres(env.DATABASE_URL, { prepare: false }); @@ -44,7 +44,7 @@ server.use( createContext: async () => ({ queryAdapter: await createQueryAdapter(drizzle(database)), }), - }) + }), ); server.listen({ host: env.HOST, port: env.PORT }); diff --git a/packages/store-indexer/bin/postgres-indexer.ts b/packages/store-indexer/bin/postgres-indexer.ts index 15cce32a1a..2f1baa7ffe 100644 --- a/packages/store-indexer/bin/postgres-indexer.ts +++ b/packages/store-indexer/bin/postgres-indexer.ts @@ -18,8 +18,8 @@ const env = parseEnv( DATABASE_URL: z.string(), HEALTHCHECK_HOST: z.string().optional(), HEALTHCHECK_PORT: z.coerce.number().optional(), - }) - ) + }), + ), ); const transports: Transport[] = [ @@ -81,9 +81,10 @@ let isCaughtUp = false; combineLatest([latestBlockNumber$, storedBlockLogs$]) .pipe( filter( - ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => latestBlockNumber === lastBlockNumberProcessed + ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => + latestBlockNumber === lastBlockNumberProcessed, ), - first() + first(), ) .subscribe(() => { isCaughtUp = true; @@ -102,12 +103,12 @@ if (env.HEALTHCHECK_HOST != null || env.HEALTHCHECK_PORT != null) { server.use( healthcheck({ isReady: () => isCaughtUp, - }) + }), ); server.use(helloWorld()); server.listen({ host: env.HEALTHCHECK_HOST, port: env.HEALTHCHECK_PORT }); console.log( - `postgres indexer healthcheck server listening on http://${env.HEALTHCHECK_HOST}:${env.HEALTHCHECK_PORT}` + `postgres indexer healthcheck server listening on http://${env.HEALTHCHECK_HOST}:${env.HEALTHCHECK_PORT}`, ); } diff --git a/packages/store-indexer/bin/sqlite-indexer.ts b/packages/store-indexer/bin/sqlite-indexer.ts index bfea5260bb..c1ebebf326 100644 --- a/packages/store-indexer/bin/sqlite-indexer.ts +++ b/packages/store-indexer/bin/sqlite-indexer.ts @@ -26,8 +26,8 @@ const env = parseEnv( z.object({ SQLITE_FILENAME: z.string().default("indexer.db"), SENTRY_DSN: z.string().optional(), - }) - ) + }), + ), ); const transports: Transport[] = [ @@ -60,7 +60,7 @@ try { currentChainState.schemaVersion, "to", schemaVersion, - "recreating database" + "recreating database", ); fs.truncateSync(env.SQLITE_FILENAME); } else if (currentChainState.lastUpdatedBlockNumber != null) { @@ -84,9 +84,10 @@ let isCaughtUp = false; combineLatest([latestBlockNumber$, storedBlockLogs$]) .pipe( filter( - ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => latestBlockNumber === lastBlockNumberProcessed + ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => + latestBlockNumber === lastBlockNumberProcessed, ), - first() + first(), ) .subscribe(() => { isCaughtUp = true; @@ -103,7 +104,7 @@ server.use(cors()); server.use( healthcheck({ isReady: () => isCaughtUp, - }) + }), ); server.use(helloWorld()); server.use(apiRoutes(database)); @@ -115,7 +116,7 @@ server.use( createContext: async () => ({ queryAdapter: await createQueryAdapter(database), }), - }) + }), ); server.listen({ host: env.HOST, port: env.PORT }); diff --git a/packages/store-indexer/src/koa-middleware/sentry.ts b/packages/store-indexer/src/koa-middleware/sentry.ts index ea59ea7492..e8999dffcd 100644 --- a/packages/store-indexer/src/koa-middleware/sentry.ts +++ b/packages/store-indexer/src/koa-middleware/sentry.ts @@ -31,8 +31,8 @@ export function requestHandler(): Koa.Middleware { include: { user: false, }, - }) - ) + }), + ), ); await next(); }); diff --git a/packages/store-indexer/src/postgres/apiRoutes.ts b/packages/store-indexer/src/postgres/apiRoutes.ts index 383700fc5f..66f5d63397 100644 --- a/packages/store-indexer/src/postgres/apiRoutes.ts +++ b/packages/store-indexer/src/postgres/apiRoutes.ts @@ -38,8 +38,8 @@ export function apiRoutes(database: Sql): Middleware { ctx.body = "no logs found"; error( `no logs found for chainId ${options.chainId}, address ${options.address}, filters ${JSON.stringify( - options.filters - )}` + options.filters, + )}`, ); return; } diff --git a/packages/store-indexer/src/postgres/deprecated/getLogs.ts b/packages/store-indexer/src/postgres/deprecated/getLogs.ts index e6138fef2e..a883e9b011 100644 --- a/packages/store-indexer/src/postgres/deprecated/getLogs.ts +++ b/packages/store-indexer/src/postgres/deprecated/getLogs.ts @@ -20,7 +20,7 @@ export async function getLogs( readonly chainId: number; readonly address?: Hex; readonly filters?: readonly SyncFilter[]; - } + }, ): Promise<{ blockNumber: bigint; logs: (StorageAdapterLog & { eventName: "Store_SetRecord" })[] }> { const benchmark = createBenchmark("drizzleGetLogs"); @@ -30,12 +30,12 @@ export async function getLogs( address != null ? eq(tables.recordsTable.address, address) : undefined, eq(tables.recordsTable.tableId, filter.tableId), filter.key0 != null ? eq(tables.recordsTable.key0, filter.key0) : undefined, - filter.key1 != null ? eq(tables.recordsTable.key1, filter.key1) : undefined - ) + filter.key1 != null ? eq(tables.recordsTable.key1, filter.key1) : undefined, + ), ) : address != null - ? [eq(tables.recordsTable.address, address)] - : []; + ? [eq(tables.recordsTable.address, address)] + : []; benchmark("parse config"); // Query for the block number that the indexer (i.e. chain) is at, in case the @@ -63,7 +63,7 @@ export async function getLogs( .from(tables.recordsTable) .where(or(...conditions)) .orderBy( - asc(tables.recordsTable.blockNumber) + asc(tables.recordsTable.blockNumber), // TODO: add logIndex (https://github.com/latticexyz/mud/issues/1979) ); benchmark("query records"); diff --git a/packages/store-indexer/src/postgres/queryLogs.ts b/packages/store-indexer/src/postgres/queryLogs.ts index b887a7a026..037f3bdc7b 100644 --- a/packages/store-indexer/src/postgres/queryLogs.ts +++ b/packages/store-indexer/src/postgres/queryLogs.ts @@ -26,16 +26,16 @@ export function queryLogs(sql: Sql, opts: z.infer): PendingQuery hex columns via custom types: https://github.com/porsager/postgres#custom-types diff --git a/packages/store-indexer/src/postgres/recordToLog.ts b/packages/store-indexer/src/postgres/recordToLog.ts index 097a7657f7..b74ec281d3 100644 --- a/packages/store-indexer/src/postgres/recordToLog.ts +++ b/packages/store-indexer/src/postgres/recordToLog.ts @@ -3,7 +3,7 @@ import { decodeDynamicField } from "@latticexyz/protocol-parser"; import { RecordData } from "./common"; export function recordToLog( - record: Omit + record: Omit, ): StorageAdapterLog & { eventName: "Store_SetRecord" } { return { address: record.address, diff --git a/packages/store-indexer/src/sqlite/getTablesWithRecords.ts b/packages/store-indexer/src/sqlite/getTablesWithRecords.ts index 987de4e641..10093c99ef 100644 --- a/packages/store-indexer/src/sqlite/getTablesWithRecords.ts +++ b/packages/store-indexer/src/sqlite/getTablesWithRecords.ts @@ -20,7 +20,7 @@ export function getTablesWithRecords( readonly chainId: number; readonly address?: Hex; readonly filters?: readonly SyncFilter[]; - } + }, ): { blockNumber: bigint | null; tables: readonly TableWithRecords[] } { const metadata = database .select() @@ -44,7 +44,7 @@ export function getTablesWithRecords( .from(sqliteTable) .where(eq(sqliteTable.__isDeleted, false)) .orderBy( - asc(sqliteTable.__lastUpdatedBlockNumber) + asc(sqliteTable.__lastUpdatedBlockNumber), // TODO: add logIndex (https://github.com/latticexyz/mud/issues/1979) ) .all(); @@ -56,7 +56,7 @@ export function getTablesWithRecords( (filter) => filter.tableId === table.tableId && (filter.key0 == null || filter.key0 === keyTuple[0]) && - (filter.key1 == null || filter.key1 === keyTuple[1]) + (filter.key1 == null || filter.key1 === keyTuple[1]), ); }); return { diff --git a/packages/store-sync/src/common.ts b/packages/store-sync/src/common.ts index bd5a20aee9..4b32bacfd9 100644 --- a/packages/store-sync/src/common.ts +++ b/packages/store-sync/src/common.ts @@ -13,7 +13,7 @@ export const storeTables = resolveConfig(storeConfig).tables; export const worldTables = resolveConfig(worldConfig).tables; export const internalTableIds = [...Object.values(storeTables), ...Object.values(worldTables)].map( - (table) => table.tableId + (table) => table.tableId, ); export type ChainId = number; diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index ad3e2ada04..ce0d32198d 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -72,7 +72,7 @@ export async function createStoreSync (filter) => filter.tableId === log.args.tableId && (filter.key0 == null || filter.key0 === log.args.keyTuple[0]) && - (filter.key1 == null || filter.key1 === log.args.keyTuple[1]) + (filter.key1 == null || filter.key1 === log.args.keyTuple[1]), ) : undefined; @@ -119,7 +119,7 @@ export async function createStoreSync return of(undefined); }), - shareReplay(1) + shareReplay(1), ); const storedInitialBlockLogs$ = initialBlockLogs$.pipe( @@ -167,13 +167,13 @@ export async function createStoreSync return { blockNumber, logs }; }), - shareReplay(1) + shareReplay(1), ); const startBlock$ = initialBlockLogs$.pipe( map((block) => bigIntMax(block?.blockNumber ?? 0n, initialStartBlock)), // TODO: if start block is still 0, find via deploy event - tap((startBlock) => debug("starting sync from block", startBlock)) + tap((startBlock) => debug("starting sync from block", startBlock)), ); const latestBlock$ = createBlockStream({ publicClient, blockTag: "latest" }).pipe(shareReplay(1)); @@ -182,7 +182,7 @@ export async function createStoreSync tap((blockNumber) => { debug("latest block number", blockNumber); }), - shareReplay(1) + shareReplay(1), ); let startBlock: bigint | null = null; @@ -237,7 +237,7 @@ export async function createStoreSync } } }), - share() + share(), ); const storedBlockLogs$ = concat(storedInitialBlockLogs$, storedBlock$).pipe(share()); @@ -248,10 +248,10 @@ export async function createStoreSync const recentBlocks$ = storedBlockLogs$.pipe( scan( (recentBlocks, block) => [block, ...recentBlocks].slice(0, recentBlocksWindow), - [] + [], ), filter((recentBlocks) => recentBlocks.length > 0), - shareReplay(1) + shareReplay(1), ); // TODO: move to its own file so we can test it, have its own debug instance, etc. @@ -277,7 +277,7 @@ export async function createStoreSync throw error; } }), - tap((result) => debug("has tx?", tx, result)) + tap((result) => debug("has tx?", tx, result)), ); await firstValueFrom(hasTransaction$.pipe(filter(identity))); diff --git a/packages/store-sync/src/flattenSchema.ts b/packages/store-sync/src/flattenSchema.ts index 7cc9a92d90..dd2a61d019 100644 --- a/packages/store-sync/src/flattenSchema.ts +++ b/packages/store-sync/src/flattenSchema.ts @@ -2,7 +2,7 @@ import { mapObject } from "@latticexyz/common/utils"; import { ValueSchema } from "@latticexyz/store"; export function flattenSchema( - schema: schema + schema: schema, ): { readonly [k in keyof schema]: schema[k]["type"] } { return mapObject(schema, (value) => value.type); } diff --git a/packages/store-sync/src/getSnapshot.ts b/packages/store-sync/src/getSnapshot.ts index c79f2df255..f78d6e8cf0 100644 --- a/packages/store-sync/src/getSnapshot.ts +++ b/packages/store-sync/src/getSnapshot.ts @@ -63,7 +63,7 @@ export async function getSnapshot({ const result = await trpcIndexer.findAll.query({ chainId, address, filters }); // warn after we fetch from old endpoint so we know that the indexer is accessible console.warn( - `The indexer at ${indexerUrl} appears to be outdated. Consider upgrading to a recent version for better performance.` + `The indexer at ${indexerUrl} appears to be outdated. Consider upgrading to a recent version for better performance.`, ); // if the indexer returns no block number, it hasn't indexed this chain diff --git a/packages/store-sync/src/indexer-client/input.ts b/packages/store-sync/src/indexer-client/input.ts index 14107f1faa..643c88bf11 100644 --- a/packages/store-sync/src/indexer-client/input.ts +++ b/packages/store-sync/src/indexer-client/input.ts @@ -10,7 +10,7 @@ export const input = z.object({ tableId: z.string().refine(isHex), key0: z.string().refine(isHex).optional(), key1: z.string().refine(isHex).optional(), - }) + }), ) .default([]), }); diff --git a/packages/store-sync/src/isTableRegistrationLog.ts b/packages/store-sync/src/isTableRegistrationLog.ts index 8f6b6148d6..e7f9ac6acf 100644 --- a/packages/store-sync/src/isTableRegistrationLog.ts +++ b/packages/store-sync/src/isTableRegistrationLog.ts @@ -4,7 +4,7 @@ import { StorageAdapterLog, storeTables } from "./common"; * @internal */ export function isTableRegistrationLog( - log: StorageAdapterLog + log: StorageAdapterLog, ): log is StorageAdapterLog & { eventName: "Store_SetRecord" } { return log.eventName === "Store_SetRecord" && log.args.tableId === storeTables.Tables.tableId; } diff --git a/packages/store-sync/src/logToTable.test.ts b/packages/store-sync/src/logToTable.test.ts index f50e813bb5..0feb33c786 100644 --- a/packages/store-sync/src/logToTable.test.ts +++ b/packages/store-sync/src/logToTable.test.ts @@ -18,7 +18,7 @@ describe("logToTable", () => { // eslint-disable-next-line max-len "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000077461626c654964000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000b6669656c644c61796f757400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000096b6579536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b76616c7565536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012616269456e636f6465644b65794e616d657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014616269456e636f6465644669656c644e616d6573000000000000000000000000", }, - }) + }), ).toMatchInlineSnapshot(` { "address": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c", diff --git a/packages/store-sync/src/logToTable.ts b/packages/store-sync/src/logToTable.ts index 0d50dce3aa..c69e616186 100644 --- a/packages/store-sync/src/logToTable.ts +++ b/packages/store-sync/src/logToTable.ts @@ -17,7 +17,7 @@ export function logToTable(log: StorageAdapterLog & { eventName: "Store_SetRecor const value = decodeValue( // TODO: remove cast when we have strong types for user types schemasTable.valueSchema as ValueSchema, - concatHex([log.args.staticData, log.args.encodedLengths, log.args.dynamicData]) + concatHex([log.args.staticData, log.args.encodedLengths, log.args.dynamicData]), ); // TODO: remove cast when we have strong types for user types diff --git a/packages/store-sync/src/postgres-decoded/buildTable.test.ts b/packages/store-sync/src/postgres-decoded/buildTable.test.ts index f20f846392..b6369772f5 100644 --- a/packages/store-sync/src/postgres-decoded/buildTable.test.ts +++ b/packages/store-sync/src/postgres-decoded/buildTable.test.ts @@ -22,7 +22,7 @@ describe("buildTable", () => { dataType: column.dataType, sqlName: column.sqlName, notNull: column.notNull, - })) + })), ).toMatchInlineSnapshot(` { "__keyBytes": { @@ -81,7 +81,7 @@ describe("buildTable", () => { name: column.name, dataType: column.dataType, sqlName: column.sqlName, - })) + })), ).toMatchInlineSnapshot(` { "__keyBytes": { diff --git a/packages/store-sync/src/postgres-decoded/buildTable.ts b/packages/store-sync/src/postgres-decoded/buildTable.ts index 2f0a6f336c..56797a8438 100644 --- a/packages/store-sync/src/postgres-decoded/buildTable.ts +++ b/packages/store-sync/src/postgres-decoded/buildTable.ts @@ -56,10 +56,10 @@ export function buildTable [name, buildColumn(snakeCase(name), type).notNull()]) + Object.entries(keySchema).map(([name, type]) => [name, buildColumn(snakeCase(name), type).notNull()]), ); const valueColumns = Object.fromEntries( - Object.entries(valueSchema).map(([name, type]) => [name, buildColumn(snakeCase(name), type).notNull()]) + Object.entries(valueSchema).map(([name, type]) => [name, buildColumn(snakeCase(name), type).notNull()]), ); // TODO: make sure there are no meta columns that overlap with key/value columns diff --git a/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts b/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts index cf692f02a8..cb213fb258 100644 --- a/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts +++ b/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts @@ -22,7 +22,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("createStorageAdapter", async () => { @@ -64,9 +64,9 @@ describe("createStorageAdapter", async () => { .where( eq( storageAdapter.tables.recordsTable.tableId, - resourceToHex({ type: "table", namespace: "", name: "NumberList" }) - ) - ) + resourceToHex({ type: "table", namespace: "", name: "NumberList" }), + ), + ), ).toMatchInlineSnapshot(` [ { diff --git a/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts b/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts index e8c3c5dd3d..437c8af9b6 100644 --- a/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts +++ b/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts @@ -44,7 +44,7 @@ export async function createStorageAdapter ({ address: log.address, tableId: log.args.tableId })) + logs.map((log) => ({ address: log.address, tableId: log.args.tableId })), ); // TODO: check if DB schema/table was created? @@ -56,7 +56,7 @@ export async function createStorageAdapter { for (const log of logs) { const table = tables.find( - (table) => getAddress(table.address) === getAddress(log.address) && table.tableId === log.args.tableId + (table) => getAddress(table.address) === getAddress(log.address) && table.tableId === log.args.tableId, ); if (!table) { const { namespace, name } = hexToResource(log.args.tableId); @@ -80,8 +80,8 @@ export async function createStorageAdapter, - filters: { address: Hex | null; tableId: Hex | null }[] = [] + filters: { address: Hex | null; tableId: Hex | null }[] = [], ): Promise { const conditions = filters.map((filter) => and( filter.address != null ? eq(internalTables.recordsTable.address, filter.address) : undefined, - filter.tableId != null ? eq(internalTables.recordsTable.key0, filter.tableId) : undefined - ) + filter.tableId != null ? eq(internalTables.recordsTable.key0, filter.tableId) : undefined, + ), ); const records = await db @@ -34,7 +34,7 @@ export async function getTables( encodedLengths: record.encodedLengths ?? "0x", dynamicData: record.dynamicData ?? "0x", }, - } as const) + }) as const, ); const tables = logs.map(logToTable); diff --git a/packages/store-sync/src/postgres/createStorageAdapter.test.ts b/packages/store-sync/src/postgres/createStorageAdapter.test.ts index c05928640f..bd368633b0 100644 --- a/packages/store-sync/src/postgres/createStorageAdapter.test.ts +++ b/packages/store-sync/src/postgres/createStorageAdapter.test.ts @@ -20,7 +20,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("createStorageAdapter", async () => { @@ -62,9 +62,9 @@ describe("createStorageAdapter", async () => { .where( eq( storageAdapter.tables.recordsTable.tableId, - resourceToHex({ type: "table", namespace: "", name: "NumberList" }) - ) - ) + resourceToHex({ type: "table", namespace: "", name: "NumberList" }), + ), + ), ).toMatchInlineSnapshot(` [ { diff --git a/packages/store-sync/src/postgres/createStorageAdapter.ts b/packages/store-sync/src/postgres/createStorageAdapter.ts index 43578e9ad9..91cfe6f225 100644 --- a/packages/store-sync/src/postgres/createStorageAdapter.ts +++ b/packages/store-sync/src/postgres/createStorageAdapter.ts @@ -80,8 +80,8 @@ export async function createStorageAdapter, - tables: PgTableWithColumns[] + tables: PgTableWithColumns[], ): Promise<() => Promise> { const schemaNames = unique(tables.map((table) => getTableConfig(table).schema).filter(isDefined)); @@ -49,7 +49,7 @@ export async function setupTables( if (primaryKeyColumns.length) { query = query.addPrimaryKeyConstraint( `${tableConfig.name}_${primaryKeyColumns.join("_")}_pk`, - primaryKeyColumns as any + primaryKeyColumns as any, ); } diff --git a/packages/store-sync/src/postgres/tables.ts b/packages/store-sync/src/postgres/tables.ts index b8871327d3..2f00011976 100644 --- a/packages/store-sync/src/postgres/tables.ts +++ b/packages/store-sync/src/postgres/tables.ts @@ -37,7 +37,7 @@ const recordsTable = pgSchema(schemaName).table( key1Index: index("key1_index").on(table.address, table.tableId, table.key1), // TODO: add indices for querying without table ID // TODO: add indices for querying multiple keys - }) + }), ); export const tables = { diff --git a/packages/store-sync/src/recs/decodeEntity.ts b/packages/store-sync/src/recs/decodeEntity.ts index ba2c084a7f..d4210de20b 100644 --- a/packages/store-sync/src/recs/decodeEntity.ts +++ b/packages/store-sync/src/recs/decodeEntity.ts @@ -5,18 +5,18 @@ import { KeySchema, SchemaToPrimitives } from "@latticexyz/protocol-parser"; export function decodeEntity( keySchema: TKeySchema, - entity: Entity + entity: Entity, ): SchemaToPrimitives { const hexKeyTuple = entityToHexKeyTuple(entity); if (hexKeyTuple.length !== Object.keys(keySchema).length) { throw new Error( - `entity key tuple length ${hexKeyTuple.length} does not match key schema length ${Object.keys(keySchema).length}` + `entity key tuple length ${hexKeyTuple.length} does not match key schema length ${Object.keys(keySchema).length}`, ); } return Object.fromEntries( Object.entries(keySchema).map(([key, type], index) => [ key, decodeAbiParameters([{ type }], hexKeyTuple[index] as Hex)[0], - ]) + ]), ) as SchemaToPrimitives; } diff --git a/packages/store-sync/src/recs/defineInternalComponents.ts b/packages/store-sync/src/recs/defineInternalComponents.ts index 992b878ce4..5b974cbd65 100644 --- a/packages/store-sync/src/recs/defineInternalComponents.ts +++ b/packages/store-sync/src/recs/defineInternalComponents.ts @@ -7,7 +7,7 @@ export function defineInternalComponents(world: World) { RegisteredTables: defineComponent<{ table: Type.T }, Metadata, Table>( world, { table: Type.T }, - { metadata: { componentName: "RegisteredTables" } } + { metadata: { componentName: "RegisteredTables" } }, ), SyncProgress: defineComponent( world, @@ -18,7 +18,7 @@ export function defineInternalComponents(world: World) { latestBlockNumber: Type.BigInt, lastBlockNumberProcessed: Type.BigInt, }, - { metadata: { componentName: "SyncProgress" } } + { metadata: { componentName: "SyncProgress" } }, ), } as const satisfies Record>; } diff --git a/packages/store-sync/src/recs/encodeEntity.ts b/packages/store-sync/src/recs/encodeEntity.ts index bef8a33c1b..061a630dee 100644 --- a/packages/store-sync/src/recs/encodeEntity.ts +++ b/packages/store-sync/src/recs/encodeEntity.ts @@ -5,14 +5,14 @@ import { KeySchema, SchemaToPrimitives } from "@latticexyz/protocol-parser"; export function encodeEntity( keySchema: TKeySchema, - key: SchemaToPrimitives + key: SchemaToPrimitives, ): Entity { if (Object.keys(keySchema).length !== Object.keys(key).length) { throw new Error( - `key length ${Object.keys(key).length} does not match key schema length ${Object.keys(keySchema).length}` + `key length ${Object.keys(key).length} does not match key schema length ${Object.keys(keySchema).length}`, ); } return hexKeyTupleToEntity( - Object.entries(keySchema).map(([keyName, type]) => encodeAbiParameters([{ type }], [key[keyName]])) + Object.entries(keySchema).map(([keyName, type]) => encodeAbiParameters([{ type }], [key[keyName]])), ); } diff --git a/packages/store-sync/src/recs/getTableEntity.ts b/packages/store-sync/src/recs/getTableEntity.ts index 5b92368da3..52ae66b6e3 100644 --- a/packages/store-sync/src/recs/getTableEntity.ts +++ b/packages/store-sync/src/recs/getTableEntity.ts @@ -10,6 +10,6 @@ export function getTableEntity(table: Pick( - component: Component + component: Component, ): component is Component { return ( component.metadata?.componentName != null && diff --git a/packages/store-sync/src/recs/recsStorage.test.ts b/packages/store-sync/src/recs/recsStorage.test.ts index afead84f6b..a1e5217cbe 100644 --- a/packages/store-sync/src/recs/recsStorage.test.ts +++ b/packages/store-sync/src/recs/recsStorage.test.ts @@ -21,7 +21,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("recsStorage", () => { @@ -29,7 +29,7 @@ describe("recsStorage", () => { const world = createWorld(); const { components } = recsStorage({ world, tables }); expect(components.NumberList.id).toMatchInlineSnapshot( - '"0x746200000000000000000000000000004e756d6265724c697374000000000000"' + '"0x746200000000000000000000000000004e756d6265724c697374000000000000"', ); }); @@ -60,7 +60,9 @@ describe("recsStorage", () => { `); expect( - [...getComponentEntities(components.NumberList)].map((entity) => getComponentValue(components.NumberList, entity)) + [...getComponentEntities(components.NumberList)].map((entity) => + getComponentValue(components.NumberList, entity), + ), ).toMatchInlineSnapshot(` [ { diff --git a/packages/store-sync/src/recs/recsStorage.ts b/packages/store-sync/src/recs/recsStorage.ts index e610787ab3..c1f547a9f6 100644 --- a/packages/store-sync/src/recs/recsStorage.ts +++ b/packages/store-sync/src/recs/recsStorage.ts @@ -60,7 +60,7 @@ export function recsStorage>({ components.RegisteredTables, tableEntity, { table: newTable }, - { skipUpdateStream: shouldSkipUpdateStream?.() } + { skipUpdateStream: shouldSkipUpdateStream?.() }, ); } } @@ -69,7 +69,7 @@ export function recsStorage>({ const { namespace, name } = hexToResource(log.args.tableId); const table = getComponentValue( components.RegisteredTables, - getTableEntity({ address: log.address, namespace, name }) + getTableEntity({ address: log.address, namespace, name }), )?.table; if (!table) { debug(`skipping update for unknown table: ${namespace}:${name} at ${log.address}`); @@ -81,7 +81,7 @@ export function recsStorage>({ debug( `skipping update for unknown component: ${table.tableId} (${table.namespace}:${ table.name - }). Available components: ${Object.keys(components)}` + }). Available components: ${Object.keys(components)}`, ); continue; } @@ -105,7 +105,7 @@ export function recsStorage>({ __encodedLengths: log.args.encodedLengths, __dynamicData: log.args.dynamicData, }, - { skipUpdateStream: shouldSkipUpdateStream?.() } + { skipUpdateStream: shouldSkipUpdateStream?.() }, ); } else if (log.eventName === "Store_SpliceStaticData") { // TODO: add tests that this works when no record had been set before @@ -133,7 +133,7 @@ export function recsStorage>({ ...newValue, __staticData: newStaticData, }, - { skipUpdateStream: shouldSkipUpdateStream?.() } + { skipUpdateStream: shouldSkipUpdateStream?.() }, ); } else if (log.eventName === "Store_SpliceDynamicData") { // TODO: add tests that this works when no record had been set before @@ -163,7 +163,7 @@ export function recsStorage>({ __encodedLengths: log.args.encodedLengths, __dynamicData: newDynamicData, }, - { skipUpdateStream: shouldSkipUpdateStream?.() } + { skipUpdateStream: shouldSkipUpdateStream?.() }, ); } else if (log.eventName === "Store_DeleteRecord") { debug("deleting component", { diff --git a/packages/store-sync/src/recs/tableToComponent.ts b/packages/store-sync/src/recs/tableToComponent.ts index 8a3e89cc7c..a00b0f97c3 100644 --- a/packages/store-sync/src/recs/tableToComponent.ts +++ b/packages/store-sync/src/recs/tableToComponent.ts @@ -30,7 +30,7 @@ export function tableToComponent
(world: World, table: table Object.entries(table.valueSchema).map(([fieldName, { type: schemaAbiType }]) => [ fieldName, schemaAbiTypeToRecsType[schemaAbiType as SchemaAbiType], - ]) + ]), ), __staticData: Type.OptionalString, __encodedLengths: Type.OptionalString, @@ -44,6 +44,6 @@ export function tableToComponent
(world: World, table: table keySchema: mapObject(table.keySchema, ({ type }) => type), valueSchema: mapObject(table.valueSchema, ({ type }) => type), }, - } + }, ) as TableToComponent
; } diff --git a/packages/store-sync/src/recs/tablesToComponents.ts b/packages/store-sync/src/recs/tablesToComponents.ts index be1a2cde4e..5952f6aa7a 100644 --- a/packages/store-sync/src/recs/tablesToComponents.ts +++ b/packages/store-sync/src/recs/tablesToComponents.ts @@ -9,7 +9,7 @@ export type TablesToComponents> = { export function tablesToComponents>( world: World, - tables: tables + tables: tables, ): TablesToComponents { return mapObject(tables, (table) => tableToComponent(world, table)); } diff --git a/packages/store-sync/src/schemaToDefaults.ts b/packages/store-sync/src/schemaToDefaults.ts index 278b4c77c7..f7658c15e0 100644 --- a/packages/store-sync/src/schemaToDefaults.ts +++ b/packages/store-sync/src/schemaToDefaults.ts @@ -3,6 +3,6 @@ import { schemaAbiTypeToDefaultValue } from "@latticexyz/schema-type"; export function schemaToDefaults(valueSchema: TSchema): SchemaToPrimitives { return Object.fromEntries( - Object.entries(valueSchema).map(([key, abiType]) => [key, schemaAbiTypeToDefaultValue[abiType]]) + Object.entries(valueSchema).map(([key, abiType]) => [key, schemaAbiTypeToDefaultValue[abiType]]), ) as SchemaToPrimitives; } diff --git a/packages/store-sync/src/sqlite/buildTable.ts b/packages/store-sync/src/sqlite/buildTable.ts index 2b9b0efd5c..d37d77d8e7 100644 --- a/packages/store-sync/src/sqlite/buildTable.ts +++ b/packages/store-sync/src/sqlite/buildTable.ts @@ -53,11 +53,11 @@ export function buildTable [name, buildColumn(name, type).notNull()]) + Object.entries(keySchema).map(([name, type]) => [name, buildColumn(name, type).notNull()]), ); const valueColumns = Object.fromEntries( - Object.entries(valueSchema).map(([name, type]) => [name, buildColumn(name, type).notNull()]) + Object.entries(valueSchema).map(([name, type]) => [name, buildColumn(name, type).notNull()]), ); // TODO: unique constraint on key columns? diff --git a/packages/store-sync/src/sqlite/getTables.ts b/packages/store-sync/src/sqlite/getTables.ts index 008a772167..01f9e90aa9 100644 --- a/packages/store-sync/src/sqlite/getTables.ts +++ b/packages/store-sync/src/sqlite/getTables.ts @@ -6,17 +6,17 @@ import { mudStoreTables } from "./internalTables"; export function getTables( db: BaseSQLiteDatabase<"sync", void>, - conditions: Pick[] = [] + conditions: Pick[] = [], ): Table[] { const ids = Array.from( - new Set(conditions.map((condition) => getTableName(condition.address, condition.namespace, condition.name))) + new Set(conditions.map((condition) => getTableName(condition.address, condition.namespace, condition.name))), ); const tables = db .select() .from(mudStoreTables) .where(ids.length ? inArray(mudStoreTables.id, ids) : undefined) .orderBy( - asc(mudStoreTables.lastUpdatedBlockNumber) + asc(mudStoreTables.lastUpdatedBlockNumber), // TODO: add logIndex (https://github.com/latticexyz/mud/issues/1979) ) .all(); diff --git a/packages/store-sync/src/sqlite/sqliteStorage.test.ts b/packages/store-sync/src/sqlite/sqliteStorage.test.ts index c8afe6a3d5..ed21a8dc58 100644 --- a/packages/store-sync/src/sqlite/sqliteStorage.test.ts +++ b/packages/store-sync/src/sqlite/sqliteStorage.test.ts @@ -24,7 +24,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("sqliteStorage", async () => { @@ -44,10 +44,10 @@ describe("sqliteStorage", async () => { it("should create tables and data from block log", async () => { expect(() => db.select().from(chainState).all()).toThrowErrorMatchingInlineSnapshot( - '"no such table: __chainState"' + '"no such table: __chainState"', ); expect(() => db.select().from(mudStoreTables).all()).toThrowErrorMatchingInlineSnapshot( - '"no such table: __mudStoreTables"' + '"no such table: __mudStoreTables"', ); const storageAdapter = await sqliteStorage({ database: db, publicClient }); diff --git a/packages/store-sync/src/sqlite/sqliteStorage.ts b/packages/store-sync/src/sqlite/sqliteStorage.ts index 7ea54ea3ec..4c3b9a3bca 100644 --- a/packages/store-sync/src/sqlite/sqliteStorage.ts +++ b/packages/store-sync/src/sqlite/sqliteStorage.ts @@ -62,10 +62,10 @@ export async function sqliteStorage({ JSON.stringify({ address: getAddress(log.address), ...hexToResource(log.args.tableId), - }) - ) - ) - ).map((json) => JSON.parse(json)) + }), + ), + ), + ).map((json) => JSON.parse(json)), ); await database.transaction(async (tx) => { @@ -76,15 +76,15 @@ export async function sqliteStorage({ and( eq(mudStoreTables.address, address), eq(mudStoreTables.namespace, namespace), - eq(mudStoreTables.name, name) - ) + eq(mudStoreTables.name, name), + ), ) .run(); } for (const log of logs) { const table = tables.find( - (table) => table.address === getAddress(log.address) && table.tableId === log.args.tableId + (table) => table.address === getAddress(log.address) && table.tableId === log.args.tableId, ); if (!table) { const tableId = hexToResource(log.args.tableId); diff --git a/packages/store-sync/src/sqlite/sqliteTableToSql.test.ts b/packages/store-sync/src/sqlite/sqliteTableToSql.test.ts index c07270f84e..cad8a1ca39 100644 --- a/packages/store-sync/src/sqlite/sqliteTableToSql.test.ts +++ b/packages/store-sync/src/sqlite/sqliteTableToSql.test.ts @@ -16,7 +16,7 @@ describe("sqliteTableToSql", () => { expect(sql).toMatchInlineSnapshot( // eslint-disable-next-line max-len - '"create table if not exists \\"some table\\" (\\"x\\" integer not null, \\"y\\" integer not null, \\"name\\" text default \'\' not null, \\"block_number\\" blob default \'1000\' not null, constraint \\"some table__primaryKey\\" primary key (\\"x\\", \\"y\\"))"' + '"create table if not exists \\"some table\\" (\\"x\\" integer not null, \\"y\\" integer not null, \\"name\\" text default \'\' not null, \\"block_number\\" blob default \'1000\' not null, constraint \\"some table__primaryKey\\" primary key (\\"x\\", \\"y\\"))"', ); }); @@ -29,7 +29,7 @@ describe("sqliteTableToSql", () => { const sql = sqliteTableToSql(table); expect(sql).toMatchInlineSnapshot( - '"create table if not exists \\"some table\\" (\\"name\\" text default \'\' not null)"' + '"create table if not exists \\"some table\\" (\\"name\\" text default \'\' not null)"', ); }); @@ -42,7 +42,7 @@ describe("sqliteTableToSql", () => { const sql = sqliteTableToSql(table); expect(sql).toMatchInlineSnapshot( - '"create table if not exists \\"some table\\" (\\"snake_case\\" text default \'\' not null, constraint \\"some table__primaryKey\\" primary key (\\"snake_case\\"))"' + '"create table if not exists \\"some table\\" (\\"snake_case\\" text default \'\' not null, constraint \\"some table__primaryKey\\" primary key (\\"snake_case\\"))"', ); }); }); diff --git a/packages/store-sync/src/tableToLog.test.ts b/packages/store-sync/src/tableToLog.test.ts index 0b58c4c45a..ca1f9de5f5 100644 --- a/packages/store-sync/src/tableToLog.test.ts +++ b/packages/store-sync/src/tableToLog.test.ts @@ -14,7 +14,7 @@ describe("tableToLog", () => { name: storeTables.Tables.name, keySchema: flattenSchema(storeTables.Tables.keySchema), valueSchema: flattenSchema(storeTables.Tables.valueSchema), - }) + }), ).toMatchInlineSnapshot(` { "address": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c", diff --git a/packages/store-sync/src/tablesWithRecordsToLogs.ts b/packages/store-sync/src/tablesWithRecordsToLogs.ts index a7e35d5a89..afd37437e5 100644 --- a/packages/store-sync/src/tablesWithRecordsToLogs.ts +++ b/packages/store-sync/src/tablesWithRecordsToLogs.ts @@ -18,8 +18,8 @@ export function tablesWithRecordsToLogs(tables: readonly TableWithRecords[]): St keyTuple: encodeKey(table.keySchema, record.key), ...encodeValueArgs(table.valueSchema, record.value), }, - }) - ) + }), + ), ), ]; } diff --git a/packages/store-sync/src/zustand/createStorageAdapter.test.ts b/packages/store-sync/src/zustand/createStorageAdapter.test.ts index 76fa8fc707..cdc089d051 100644 --- a/packages/store-sync/src/zustand/createStorageAdapter.test.ts +++ b/packages/store-sync/src/zustand/createStorageAdapter.test.ts @@ -20,7 +20,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as unknown as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("createStorageAdapter", () => { diff --git a/packages/store-sync/src/zustand/createStorageAdapter.ts b/packages/store-sync/src/zustand/createStorageAdapter.ts index 4427ef349f..ae4e84eb31 100644 --- a/packages/store-sync/src/zustand/createStorageAdapter.ts +++ b/packages/store-sync/src/zustand/createStorageAdapter.ts @@ -136,7 +136,7 @@ export function createStorageAdapter({ }, ]; }) - .filter(isDefined) + .filter(isDefined), ), }; diff --git a/packages/store-sync/src/zustand/createStore.ts b/packages/store-sync/src/zustand/createStore.ts index 77642e3eaa..93a2dd3258 100644 --- a/packages/store-sync/src/zustand/createStore.ts +++ b/packages/store-sync/src/zustand/createStore.ts @@ -36,11 +36,11 @@ export type ZustandState = { readonly getRecords:
(table: table) => TableRecords
; readonly getRecord:
( table: table, - key: SchemaToPrimitives + key: SchemaToPrimitives, ) => TableRecord
| undefined; readonly getValue:
( table: table, - key: SchemaToPrimitives + key: SchemaToPrimitives, ) => TableRecord
["value"] | undefined; }; @@ -65,12 +65,12 @@ export function createStore(opts: CreateStoreOptions(table: table): TableRecords
=> { const records = get().records; return Object.fromEntries( - Object.entries(records).filter(([id, record]) => record.table.tableId === table.tableId) + Object.entries(records).filter(([id, record]) => record.table.tableId === table.tableId), ) as unknown as TableRecords
; }, getRecord:
( table: table, - key: SchemaToPrimitives + key: SchemaToPrimitives, ): TableRecord
| undefined => { const keyTuple = encodeKey(flattenSchema(table.keySchema), key); const id = getId({ tableId: table.tableId, keyTuple }); @@ -78,7 +78,7 @@ export function createStore(opts: CreateStoreOptions( table: table, - key: SchemaToPrimitives + key: SchemaToPrimitives, ): TableRecord
["value"] | undefined => { return get().getRecord(table, key)?.value; }, diff --git a/packages/store-sync/src/zustand/getId.test.ts b/packages/store-sync/src/zustand/getId.test.ts index e47b398a4e..2016d318a0 100644 --- a/packages/store-sync/src/zustand/getId.test.ts +++ b/packages/store-sync/src/zustand/getId.test.ts @@ -7,9 +7,9 @@ describe("getId", () => { getId({ tableId: "0x74626d756473746f72650000000000005461626c657300000000000000000000", keyTuple: ["0x74626d756473746f72650000000000005461626c657300000000000000000000"], - }) + }), ).toMatchInlineSnapshot( - '"0x74626d756473746f72650000000000005461626c657300000000000000000000:0x74626d756473746f72650000000000005461626c657300000000000000000000"' + '"0x74626d756473746f72650000000000005461626c657300000000000000000000:0x74626d756473746f72650000000000005461626c657300000000000000000000"', ); }); }); diff --git a/packages/store-sync/src/zustand/logToTable.test.ts b/packages/store-sync/src/zustand/logToTable.test.ts index 010d25b7ed..fbaf89cd0c 100644 --- a/packages/store-sync/src/zustand/logToTable.test.ts +++ b/packages/store-sync/src/zustand/logToTable.test.ts @@ -18,7 +18,7 @@ describe("logToTable", () => { // eslint-disable-next-line max-len "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000077461626c654964000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000b6669656c644c61796f757400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000096b6579536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b76616c7565536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012616269456e636f6465644b65794e616d657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014616269456e636f6465644669656c644e616d6573000000000000000000000000", }, - }) + }), ).toMatchInlineSnapshot(` { "keySchema": { diff --git a/packages/store-sync/src/zustand/logToTable.ts b/packages/store-sync/src/zustand/logToTable.ts index 8d2b32e4e7..703f276704 100644 --- a/packages/store-sync/src/zustand/logToTable.ts +++ b/packages/store-sync/src/zustand/logToTable.ts @@ -14,7 +14,7 @@ export function logToTable(log: StorageAdapterLog & { eventName: "Store_SetRecor const value = decodeValue( schemasTable.valueSchema, - concatHex([log.args.staticData, log.args.encodedLengths, log.args.dynamicData]) + concatHex([log.args.staticData, log.args.encodedLengths, log.args.dynamicData]), ); const keySchema = hexToSchema(value.keySchema); diff --git a/packages/store-sync/src/zustand/syncToZustand.ts b/packages/store-sync/src/zustand/syncToZustand.ts index 850bb1c231..d5df3c0e80 100644 --- a/packages/store-sync/src/zustand/syncToZustand.ts +++ b/packages/store-sync/src/zustand/syncToZustand.ts @@ -9,7 +9,7 @@ import { SyncStep } from "../SyncStep"; type AllTables< config extends StoreConfig, - extraTables extends Tables | undefined + extraTables extends Tables | undefined, > = ResolvedStoreConfig["tables"] & (extraTables extends Tables ? extraTables : Record) & typeof storeTables & diff --git a/packages/store-sync/test/logsToBlocks.ts b/packages/store-sync/test/logsToBlocks.ts index e3ffb8a9ac..2c92392316 100644 --- a/packages/store-sync/test/logsToBlocks.ts +++ b/packages/store-sync/test/logsToBlocks.ts @@ -4,7 +4,7 @@ import { RpcLog, formatLog, decodeEventLog, Hex } from "viem"; import { StoreEventsLog } from "../src/common"; export function logsToBlocks( - rpcLogs: { data: string; topics: string[] }[] + rpcLogs: { data: string; topics: string[] }[], ): GroupLogsByBlockNumberResult { return groupLogsByBlockNumber( rpcLogs.map((log) => { @@ -15,6 +15,6 @@ export function logsToBlocks( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); } diff --git a/packages/store/ts/codegen/field.ts b/packages/store/ts/codegen/field.ts index b9992e8ba7..ce62a59584 100644 --- a/packages/store/ts/codegen/field.ts +++ b/packages/store/ts/codegen/field.ts @@ -35,10 +35,10 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Get ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}get${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal view returns (${_typedFieldName}) { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal view returns (${_typedFieldName}) { ${_keyTupleDefinition} ${ field.isDynamic @@ -56,8 +56,8 @@ export function renderFieldMethods(options: RenderTableOptions): string { } return ${renderDecodeFieldSingle(field)}; } - ` - ) + `, + ), ); } @@ -79,7 +79,7 @@ export function renderFieldMethods(options: RenderTableOptions): string { ${_store}.${setFieldMethod}(${internalArguments}); } `; - }) + }), ); if (field.isDynamic) { @@ -97,14 +97,14 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Get the length of ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}length${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal pure returns (uint256) { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal pure returns (uint256) { return ${typeWrappingData.staticLength}; } - ` - ) + `, + ), ); } else { result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => @@ -115,18 +115,18 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Get the length of ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}length${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal view returns (uint256) { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal view returns (uint256) { ${_keyTupleDefinition} uint256 _byteLength = ${_store}.getDynamicFieldLength(_tableId, _keyTuple, ${dynamicSchemaIndex}); unchecked { return _byteLength / ${portionData.elementLength}; } } - ` - ) + `, + ), ); } @@ -139,11 +139,11 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @dev Reverts with Store_IndexOutOfBounds if \`_index\` is out of bounds for the array. */ function ${_methodNamePrefix}getItem${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - "uint256 _index", - ])}) internal view returns (${portionData.typeWithLocation}) { + _typedStore, + _typedTableId, + _typedKeyArgs, + "uint256 _index", + ])}) internal view returns (${portionData.typeWithLocation}) { ${_keyTupleDefinition} unchecked { bytes memory _blob = ${_store}.getDynamicFieldSlice( @@ -156,8 +156,8 @@ export function renderFieldMethods(options: RenderTableOptions): string { return ${portionData.decoded}; } } - ` - ) + `, + ), ); } @@ -170,16 +170,16 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Push ${portionData.title} to ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}push${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - `${portionData.typeWithLocation} ${portionData.name}`, - ])}) internal { + _typedStore, + _typedTableId, + _typedKeyArgs, + `${portionData.typeWithLocation} ${portionData.name}`, + ])}) internal { ${_keyTupleDefinition} ${_store}.pushToDynamicField(_tableId, _keyTuple, ${dynamicSchemaIndex}, ${portionData.encoded}); } - ` - ) + `, + ), ); result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => @@ -190,15 +190,15 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Pop ${portionData.title} from ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}pop${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal { ${_keyTupleDefinition} ${_store}.popFromDynamicField(_tableId, _keyTuple, ${dynamicSchemaIndex}, ${portionData.elementLength}); } - ` - ) + `, + ), ); } @@ -233,7 +233,7 @@ export function renderFieldMethods(options: RenderTableOptions): string { } } `; - }) + }), ); } } diff --git a/packages/store/ts/codegen/record.ts b/packages/store/ts/codegen/record.ts index 7d190b8185..bd540d7068 100644 --- a/packages/store/ts/codegen/record.ts +++ b/packages/store/ts/codegen/record.ts @@ -27,10 +27,10 @@ export function renderRecordMethods(options: RenderTableOptions) { * @notice Get the full data${_commentSuffix}. */ function ${_methodNamePrefix}get(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal view returns (${renderDecodedRecord(options)}) { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal view returns (${renderDecodedRecord(options)}) { ${_keyTupleDefinition} ( @@ -40,7 +40,7 @@ export function renderRecordMethods(options: RenderTableOptions) { ) = ${_store}.getRecord(_tableId, _keyTuple, _fieldLayout); return decode(_staticData, _encodedLengths, _dynamicData); } - ` + `, ); } @@ -70,7 +70,7 @@ export function renderRecordMethods(options: RenderTableOptions) { ${_store}.setRecord(${internalArguments}); } `; - } + }, ); if (structName !== undefined) { @@ -100,7 +100,7 @@ export function renderRecordMethods(options: RenderTableOptions) { ${_store}.setRecord(${internalArguments}); } `; - } + }, ); } @@ -170,7 +170,7 @@ export function renderDeleteRecordMethods(options: RenderTableOptions) { ${_store}.deleteRecord(${internalArguments}); } `; - } + }, ); } @@ -202,13 +202,13 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields * @notice Decode the tightly packed blob of static data using this table's field layout. */ function decodeStatic(bytes memory _blob) internal pure returns (${renderArguments( - staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) { ${renderList( staticFields, (field, index) => ` ${field.name} = ${renderDecodeValueType(field, staticOffsets[index])}; - ` + `, )} } `; @@ -220,7 +220,7 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic(PackedCounter _encodedLengths, bytes memory _blob) internal pure returns (${renderArguments( - dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) { ${renderList( dynamicFields, @@ -245,7 +245,7 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields ${field.name} = ${renderDecodeDynamicFieldPartial(field)}; `; } - } + }, )} } `; @@ -273,7 +273,7 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields if (dynamicFields.length > 0) { result += ` (${renderArguments( - dynamicFields.map((field) => `${fieldNamePrefix}${field.name}`) + dynamicFields.map((field) => `${fieldNamePrefix}${field.name}`), )}) = decodeDynamic(_encodedLengths, _dynamicData); `; } diff --git a/packages/store/ts/codegen/renderFieldLayout.test.ts b/packages/store/ts/codegen/renderFieldLayout.test.ts index 38b8b4b6df..89c6663f74 100644 --- a/packages/store/ts/codegen/renderFieldLayout.test.ts +++ b/packages/store/ts/codegen/renderFieldLayout.test.ts @@ -35,23 +35,23 @@ describe("renderFieldLayout", () => { ]; expect(renderFieldLayout(fields)).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x013418040102030405060708090a0b0c0d0e0f10111213141516172000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x013418040102030405060708090a0b0c0d0e0f10111213141516172000000000);"', ); expect(renderFieldLayout([{ isDynamic: false, staticByteLength: 2 }])).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0002010002000000000000000000000000000000000000000000000000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0002010002000000000000000000000000000000000000000000000000000000);"', ); expect(renderFieldLayout([{ isDynamic: false, staticByteLength: 8 }])).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0008010008000000000000000000000000000000000000000000000000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0008010008000000000000000000000000000000000000000000000000000000);"', ); expect(renderFieldLayout([{ isDynamic: false, staticByteLength: 16 }])).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0010010010000000000000000000000000000000000000000000000000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0010010010000000000000000000000000000000000000000000000000000000);"', ); expect(renderFieldLayout([{ isDynamic: true, staticByteLength: 0 }])).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000);"', ); }); diff --git a/packages/store/ts/codegen/renderTable.ts b/packages/store/ts/codegen/renderTable.ts index 9bcd9fa05b..d85654c406 100644 --- a/packages/store/ts/codegen/renderTable.ts +++ b/packages/store/ts/codegen/renderTable.ts @@ -137,7 +137,7 @@ export function renderTable(options: RenderTableOptions) { function ${_methodNamePrefix}register(${renderArguments([_typedStore, _typedTableId])}) internal { ${_store}.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames()); } - ` + `, )} ${renderFieldMethods(options)} @@ -159,7 +159,7 @@ export function renderTable(options: RenderTableOptions) { * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ function encode(${renderArguments( - options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) internal pure returns (bytes memory, PackedCounter, bytes memory) { ${renderRecordData(options)} @@ -194,7 +194,7 @@ function renderEncodeStatic(staticFields: RenderStaticField[]) { * @return The static data, encoded into a sequence of bytes. */ function encodeStatic(${renderArguments( - staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) internal pure returns (bytes memory) { return abi.encodePacked(${renderArguments(staticFields.map(({ name }) => name))}); } @@ -216,7 +216,7 @@ function renderEncodeLengths(dynamicFields: RenderDynamicField[]) { * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ function encodeLengths(${renderArguments( - dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) internal pure returns (PackedCounter _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { @@ -228,7 +228,7 @@ function renderEncodeLengths(dynamicFields: RenderDynamicField[]) { } else { return `bytes(${name}).length`; } - }) + }), )} ); } @@ -251,7 +251,7 @@ function renderEncodeDynamic(dynamicFields: RenderDynamicField[]) { * @return The dynamic data, encoded into a sequence of bytes. */ function encodeDynamic(${renderArguments( - dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) internal pure returns (bytes memory) { return abi.encodePacked(${renderArguments(dynamicFields.map((field) => renderEncodeFieldSingle(field)))}); } diff --git a/packages/store/ts/codegen/tableOptions.ts b/packages/store/ts/codegen/tableOptions.ts index ce8425b349..e3763fdd59 100644 --- a/packages/store/ts/codegen/tableOptions.ts +++ b/packages/store/ts/codegen/tableOptions.ts @@ -26,7 +26,7 @@ export interface TableOptions { */ export function getTableOptions( config: StoreConfig, - solidityUserTypes: Record + solidityUserTypes: Record, ): TableOptions[] { const storeImportPath = config.storeImportPath; diff --git a/packages/store/ts/codegen/tablegen.ts b/packages/store/ts/codegen/tablegen.ts index 18d0bcfb56..02cd7a62c2 100644 --- a/packages/store/ts/codegen/tablegen.ts +++ b/packages/store/ts/codegen/tablegen.ts @@ -15,7 +15,7 @@ export async function tablegen(config: StoreConfig, outputBaseDirectory: string, await Promise.all( uniqueTableDirectories.map(async (tableDir) => { await rm(path.join(outputBaseDirectory, tableDir), { recursive: true, force: true }); - }) + }), ); // write tables to files @@ -24,7 +24,7 @@ export async function tablegen(config: StoreConfig, outputBaseDirectory: string, const fullOutputPath = path.join(outputBaseDirectory, outputPath); const output = renderTable(renderOptions); await formatAndWriteSolidity(output, fullOutputPath, "Generated table"); - }) + }), ); // write table index diff --git a/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts b/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts index 3506405ac6..83dba0422a 100644 --- a/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts +++ b/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts @@ -24,7 +24,7 @@ export function renderDecodeSlice() { renderTightCoderDecode({ internalTypeId: staticAbiType, staticByteLength: staticAbiTypeToByteLength[staticAbiType], - }) + }), ) .join("\n")} } diff --git a/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts b/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts index 7e80df8537..a601534dc9 100644 --- a/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts +++ b/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts @@ -22,7 +22,7 @@ export function renderEncodeArray() { renderTightCoderEncode({ internalTypeId: staticAbiType, staticByteLength: staticAbiTypeToByteLength[staticAbiType], - }) + }), ) .join("\n")} } diff --git a/packages/store/ts/codegen/userType.ts b/packages/store/ts/codegen/userType.ts index 72e613df37..62b371c8d9 100644 --- a/packages/store/ts/codegen/userType.ts +++ b/packages/store/ts/codegen/userType.ts @@ -14,7 +14,7 @@ import { StoreConfig } from "../config"; export function resolveAbiOrUserType( abiOrUserType: string, config: StoreConfig, - solidityUserTypes: Record + solidityUserTypes: Record, ): { schemaType: SchemaType; renderType: RenderType; @@ -47,7 +47,7 @@ export function importForAbiOrUserType( abiOrUserType: string, usedInDirectory: string, config: StoreConfig, - solidityUserTypes: Record + solidityUserTypes: Record, ): ImportDatum | undefined { // abi types which directly mirror a SchemaType if (abiOrUserType in AbiTypeToSchemaType) { @@ -103,7 +103,7 @@ export function getSchemaTypeInfo(schemaType: SchemaType): RenderType { export function getUserTypeInfo( userType: string, config: StoreConfig, - solidityUserTypes: Record + solidityUserTypes: Record, ): { schemaType: SchemaType; renderType: RenderType; diff --git a/packages/store/ts/common.ts b/packages/store/ts/common.ts index a4d57e182c..5a9d1ebeb9 100644 --- a/packages/store/ts/common.ts +++ b/packages/store/ts/common.ts @@ -33,14 +33,14 @@ export type SchemaToPrimitives = { export type ConfigFieldTypeToSchemaAbiType> = T extends SchemaAbiType ? T : T extends `${string}[${string}]` - ? "uint8[]" - : "uint8"; + ? "uint8[]" + : "uint8"; export type ConfigFieldTypeToPrimitiveType> = T extends SchemaAbiType ? SchemaAbiTypeToPrimitiveType : T extends `${string}[${string}]` // field type might include enums and enum arrays, which are mapped to uint8/uint8[] - ? number[] // map enum arrays to `number[]` - : number; // map enums to `number` + ? number[] // map enum arrays to `number[]` + : number; // map enums to `number` /** Map a table schema config like `{ value: "uint256", type: "SomeEnum" }` to its primitive types like `{ value: bigint, type: number }` */ export type SchemaConfigToPrimitives = { @@ -56,12 +56,12 @@ export type ConfigToTablesPrimitives = { export type ConfigToKeyPrimitives< C extends StoreConfig, - Table extends keyof ConfigToTablesPrimitives + Table extends keyof ConfigToTablesPrimitives, > = ConfigToTablesPrimitives[Table]["key"]; export type ConfigToValuePrimitives< C extends StoreConfig, - Table extends keyof ConfigToTablesPrimitives + Table extends keyof ConfigToTablesPrimitives, > = ConfigToTablesPrimitives[Table]["value"]; export type ConfigToRecordPrimitives> = { diff --git a/packages/store/ts/config/experimental/resolveConfig.test-d.ts b/packages/store/ts/config/experimental/resolveConfig.test-d.ts index 0c5f5e52a3..80d8c8a960 100644 --- a/packages/store/ts/config/experimental/resolveConfig.test-d.ts +++ b/packages/store/ts/config/experimental/resolveConfig.test-d.ts @@ -29,7 +29,7 @@ describe("resolveConfig", () => { valueSchema: "ResourceType", }, }, - }) + }), ); expectTypeOf().toEqualTypeOf<"the-namespace">(); diff --git a/packages/store/ts/config/experimental/resolveConfig.test.ts b/packages/store/ts/config/experimental/resolveConfig.test.ts index d6187ca73c..c011aa1d01 100644 --- a/packages/store/ts/config/experimental/resolveConfig.test.ts +++ b/packages/store/ts/config/experimental/resolveConfig.test.ts @@ -25,7 +25,7 @@ const config = resolveConfig( valueSchema: "ResourceType", }, }, - }) + }), ); describe("resolveConfig", () => { @@ -35,7 +35,7 @@ describe("resolveConfig", () => { expect(config.tables.Shorthand.name).toEqual("Shorthand"); expect(config.tables.Shorthand.tableId).toEqual( - resourceToHex({ type: "table", namespace: "the-namespace", name: "Shorthand" }) + resourceToHex({ type: "table", namespace: "the-namespace", name: "Shorthand" }), ); expect(config.tables.Shorthand.keySchema).toEqual({ diff --git a/packages/store/ts/config/experimental/resolveConfig.ts b/packages/store/ts/config/experimental/resolveConfig.ts index 83354fa8f5..0d03e36884 100644 --- a/packages/store/ts/config/experimental/resolveConfig.ts +++ b/packages/store/ts/config/experimental/resolveConfig.ts @@ -26,7 +26,7 @@ type ResolvedTableConfig< TUserTypes extends UserTypesConfig["userTypes"], TEnumNames extends StringForUnion, TNamespace extends string = string, - TName extends string = string + TName extends string = string, > = { keySchema: ResolvedKeySchema; valueSchema: ResolvedValueSchema; @@ -38,34 +38,34 @@ type ResolvedTableConfig< type ResolvedKeySchema< TKeySchema extends TableConfig["keySchema"], TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion + TEnumNames extends StringForUnion, > = ResolvedSchema; type ResolvedValueSchema< TValueSchema extends TableConfig["valueSchema"], TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion + TEnumNames extends StringForUnion, > = ResolvedSchema, TUserTypes, TEnumNames>; type ResolvedSchema< TSchema extends Exclude, TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion + TEnumNames extends StringForUnion, > = { [key in keyof TSchema]: { type: TSchema[key] extends SchemaAbiType ? TSchema[key] : TSchema[key] extends keyof TUserTypes - ? TUserTypes[TSchema[key]] extends UserType - ? // Note: we mistakenly named the plain ABI type "internalType", - // while in Solidity ABIs the plain ABI type is called "type" and - // and the custom type "internalType". We're planning to - // change our version and align with Solidity ABIs going forward. - TUserTypes[TSchema[key]]["internalType"] - : never - : TSchema[key] extends TEnumNames - ? "uint8" - : never; + ? TUserTypes[TSchema[key]] extends UserType + ? // Note: we mistakenly named the plain ABI type "internalType", + // while in Solidity ABIs the plain ABI type is called "type" and + // and the custom type "internalType". We're planning to + // change our version and align with Solidity ABIs going forward. + TUserTypes[TSchema[key]]["internalType"] + : never + : TSchema[key] extends TEnumNames + ? "uint8" + : never; internalType: TSchema[key]; }; }; @@ -75,7 +75,7 @@ type ResolvedSchema< * @deprecated Internal only */ export function resolveConfig( - config: TStoreConfig + config: TStoreConfig, ): ResolvedStoreConfig { const resolvedTables: Record> = {}; @@ -85,7 +85,7 @@ export function resolveConfig( config.userTypes, Object.keys(config.enums), config.namespace, - key + key, ) as ReturnType; } @@ -99,13 +99,13 @@ function resolveTable< TUserTypes extends UserTypesConfig["userTypes"], TEnums extends StringForUnion[], TNamespace extends string, - TName extends string + TName extends string, >( tableConfig: TTableConfig, userTypes: TUserTypes, enums: TEnums, namespace: TNamespace, - name: TName + name: TName, ): ResolvedTableConfig { const { keySchema, valueSchema } = tableConfig; @@ -125,11 +125,11 @@ function resolveTable< function resolveKeySchema< TKeySchema extends TableConfig["keySchema"], TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[] + TEnums extends StringForUnion[], >( keySchema: TKeySchema, userTypes: TUserTypes, - enums: TEnums + enums: TEnums, ): ResolvedKeySchema { const schema = ( keySchema == null ? { key: "bytes32" } : typeof keySchema === "string" ? { key: keySchema } : keySchema @@ -140,11 +140,11 @@ function resolveKeySchema< function resolveValueSchema< TValueSchema extends TableConfig["valueSchema"], TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[] + TEnums extends StringForUnion[], >( valueSchema: TValueSchema, userTypes: TUserTypes, - enums: TEnums + enums: TEnums, ): ResolvedValueSchema { const schema = ( typeof valueSchema === "string" ? ({ value: valueSchema } as unknown as TValueSchema) : valueSchema @@ -155,7 +155,7 @@ function resolveValueSchema< function resolveSchema< TSchema extends Exclude | TableConfig["valueSchema"], string>, TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[] + TEnums extends StringForUnion[], >(schema: TSchema, userTypes: TUserTypes, enums: TEnums): ResolvedSchema { return mapObject>(schema, (value, key) => { const isUserType = userTypes && value in userTypes; diff --git a/packages/store/ts/config/storeConfig.ts b/packages/store/ts/config/storeConfig.ts index 01c2b5e002..dc474f4f49 100644 --- a/packages/store/ts/config/storeConfig.ts +++ b/packages/store/ts/config/storeConfig.ts @@ -73,7 +73,7 @@ export const zSchemaConfig = zFullSchemaConfig.or(zShorthandSchemaConfig); type ResolvedSchema< TSchema extends Record, - TUserTypes extends Record> + TUserTypes extends Record>, > = { [key in keyof TSchema]: TSchema[key] extends keyof TUserTypes ? TUserTypes[TSchema[key]]["internalType"] @@ -84,7 +84,7 @@ type ResolvedSchema< // (see https://github.com/latticexyz/mud/pull/1588) export function resolveUserTypes< TSchema extends Record, - TUserTypes extends Record> + TUserTypes extends Record>, >(schema: TSchema, userTypes: TUserTypes): ResolvedSchema { const resolvedSchema: Record = {}; for (const [key, value] of Object.entries(schema)) { @@ -109,7 +109,7 @@ export function resolveUserTypes< export interface TableConfig< UserTypes extends StringForUnion = StringForUnion, - StaticUserTypes extends StringForUnion = StringForUnion + StaticUserTypes extends StringForUnion = StringForUnion, > { /** Output directory path for the file. Default is "tables" */ directory?: string; @@ -136,7 +136,7 @@ export interface TableConfig< export type FullTableConfig< UserTypes extends StringForUnion = StringForUnion, - StaticUserTypes extends StringForUnion = StringForUnion + StaticUserTypes extends StringForUnion = StringForUnion, > = Required> & { valueSchema: FullSchemaConfig; }; @@ -197,7 +197,7 @@ export const zTableConfig = zFullTableConfig.or(zShorthandTableConfig); export type TablesConfig< UserTypes extends StringForUnion = StringForUnion, - StaticUserTypes extends StringForUnion = StringForUnion + StaticUserTypes extends StringForUnion = StringForUnion, > = Record | FieldData>; export const zTablesConfig = z.record(zTableName, zTableConfig).transform((tables) => { @@ -213,17 +213,17 @@ export const zTablesConfig = z.record(zTableName, zTableConfig).transform((table export type FullTablesConfig< UserTypes extends StringForUnion = StringForUnion, - StaticUserTypes extends StringForUnion = StringForUnion + StaticUserTypes extends StringForUnion = StringForUnion, > = Record>; export type ExpandTablesConfig> = { [TableName in keyof T]: T[TableName] extends FieldData ? ExpandTableConfig<{ valueSchema: { value: T[TableName] } }, TableName extends string ? TableName : never> : T[TableName] extends TableConfig - ? ExpandTableConfig - : // Weakly typed values get a weakly typed expansion. - // This shouldn't normally happen within `mudConfig`, but can be manually triggered via `ExpandMUDUserConfig` - ExpandTableConfig, TableName extends string ? TableName : string>; + ? ExpandTableConfig + : // Weakly typed values get a weakly typed expansion. + // This shouldn't normally happen within `mudConfig`, but can be manually triggered via `ExpandMUDUserConfig` + ExpandTableConfig, TableName extends string ? TableName : string>; }; /************************************************************************ @@ -242,22 +242,22 @@ export type EnumsConfig = never extends EnumNa enums?: Record; } : StringForUnion extends EnumNames - ? { - /** - * Enum names mapped to lists of their member names - * - * (enums aren't inferred - use `mudConfig` or `storeConfig` helper, and `as const` for variables) - */ - enums?: Record; - } - : { - /** - * Enum names mapped to lists of their member names - * - * Enums defined here can be used as types in table schemas/keys - */ - enums: Record; - }; + ? { + /** + * Enum names mapped to lists of their member names + * + * (enums aren't inferred - use `mudConfig` or `storeConfig` helper, and `as const` for variables) + */ + enums?: Record; + } + : { + /** + * Enum names mapped to lists of their member names + * + * Enums defined here can be used as types in table schemas/keys + */ + enums: Record; + }; export type FullEnumsConfig = { enums: Record; @@ -285,26 +285,26 @@ export type UserTypesConfig; } : StringForUnion extends UserTypeNames - ? { - /** - * User types mapped to file paths from which to import them. - * Paths are treated as relative to root. - * Paths that don't start with a "." have foundry remappings applied to them first. - * - * (user types aren't inferred - use `mudConfig` or `storeConfig` helper, and `as const` for variables) - */ - userTypes?: Record; - } - : { - /** - * User types mapped to file paths from which to import them. - * Paths are treated as relative to root. - * Paths that don't start with a "." have foundry remappings applied to them first. - * - * User types defined here can be used as types in table schemas/keys - */ - userTypes: Record; - }; + ? { + /** + * User types mapped to file paths from which to import them. + * Paths are treated as relative to root. + * Paths that don't start with a "." have foundry remappings applied to them first. + * + * (user types aren't inferred - use `mudConfig` or `storeConfig` helper, and `as const` for variables) + */ + userTypes?: Record; + } + : { + /** + * User types mapped to file paths from which to import them. + * Paths are treated as relative to root. + * Paths that don't start with a "." have foundry remappings applied to them first. + * + * User types defined here can be used as types in table schemas/keys + */ + userTypes: Record; + }; const zUserTypeConfig = z.object({ filePath: z.string(), @@ -327,7 +327,7 @@ export type MUDUserConfig< T extends MUDCoreUserConfig = MUDCoreUserConfig, EnumNames extends StringForUnion = StringForUnion, UserTypeNames extends StringForUnion = StringForUnion, - StaticUserTypes extends ExtractUserTypes = ExtractUserTypes + StaticUserTypes extends ExtractUserTypes = ExtractUserTypes, > = T & EnumsConfig & UserTypesConfig & { @@ -404,7 +404,7 @@ function validateStoreConfig(config: z.output, ctx: ctx.addIssue({ code: ZodIssueCode.custom, message: `Table library names, enum names, user type names must be globally unique: ${duplicateGlobalNames.join( - ", " + ", ", )}`, }); } @@ -432,7 +432,7 @@ function validateAbiOrUserType( userTypeNames: string[], staticUserTypeNames: string[], type: string, - ctx: RefinementCtx + ctx: RefinementCtx, ) { if (!(AbiTypes as string[]).includes(type) && !userTypeNames.includes(type)) { const staticArray = parseStaticArray(type); @@ -460,7 +460,7 @@ function validateStaticArray( staticUserTypeNames: string[], elementType: string, staticLength: number, - ctx: RefinementCtx + ctx: RefinementCtx, ) { validateStaticAbiOrUserType(staticUserTypeNames, elementType, ctx); diff --git a/packages/store/ts/register/mudConfig.ts b/packages/store/ts/register/mudConfig.ts index 907ef5fb1c..4ac0be54d4 100644 --- a/packages/store/ts/register/mudConfig.ts +++ b/packages/store/ts/register/mudConfig.ts @@ -9,7 +9,7 @@ export function mudConfig< // (`never` is overridden by inference, so only the defined enums can be used by default) EnumNames extends StringForUnion = never, UserTypeNames extends StringForUnion = never, - StaticUserTypes extends ExtractUserTypes = ExtractUserTypes + StaticUserTypes extends ExtractUserTypes = ExtractUserTypes, >(config: MUDUserConfig): ExpandMUDUserConfig { // eslint-disable-next-line @typescript-eslint/no-explicit-any return mudCoreConfig(config) as any; diff --git a/packages/store/ts/scripts/generate-tightcoder.ts b/packages/store/ts/scripts/generate-tightcoder.ts index dd95ddb9bb..d4f0a56579 100644 --- a/packages/store/ts/scripts/generate-tightcoder.ts +++ b/packages/store/ts/scripts/generate-tightcoder.ts @@ -6,5 +6,5 @@ await formatAndWriteSolidity(renderEncodeArray(), "src/tightcoder/EncodeArray.so await formatAndWriteSolidity( renderTightCoderAutoTest(), "test/tightcoder/TightCoderAuto.t.sol", - "Generated TightCoderAutoTest" + "Generated TightCoderAutoTest", ); diff --git a/packages/store/ts/storeEvents.test.ts b/packages/store/ts/storeEvents.test.ts index b7361f5664..e4e7c06daf 100644 --- a/packages/store/ts/storeEvents.test.ts +++ b/packages/store/ts/storeEvents.test.ts @@ -20,7 +20,7 @@ describe("Store events", () => { for (const storeEvent of storeEvents) { const parsedStoreEvent = parseAbiItem(storeEvent); const abiItem = IStoreAbi.find( - (item) => item.type === parsedStoreEvent.type && item.name === parsedStoreEvent.name + (item) => item.type === parsedStoreEvent.type && item.name === parsedStoreEvent.name, ); expect(abiItem).not.toBeUndefined(); expect(normalizeAbiEvent(parsedStoreEvent)).toMatchObject(normalizeAbiEvent(abiItem as AbiEvent)); diff --git a/packages/utils/src/bytes.ts b/packages/utils/src/bytes.ts index c90728e7b9..659cda462f 100644 --- a/packages/utils/src/bytes.ts +++ b/packages/utils/src/bytes.ts @@ -20,7 +20,7 @@ export function concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array { return Uint8Array.from( arrays.reduce((acc, curr) => { return [...acc, ...curr]; - }, []) + }, []), ); } diff --git a/packages/utils/src/cubic.ts b/packages/utils/src/cubic.ts index 611da1a9b5..bddb47e232 100644 --- a/packages/utils/src/cubic.ts +++ b/packages/utils/src/cubic.ts @@ -30,7 +30,7 @@ export function cubicNoiseConfig( octave: number, scale: number, periodX = Number.MAX_SAFE_INTEGER, - periodY = Number.MAX_SAFE_INTEGER + periodY = Number.MAX_SAFE_INTEGER, ) { return { seed: Math.floor(seed * Number.MAX_SAFE_INTEGER), @@ -59,7 +59,7 @@ export function cubicNoiseSample1(config: ReturnType, x randomize(config.seed, tile(xi + 2, config.periodX), 0), lerp, 1, - 1 + 1, ) * 0.666666 + 0.166666 @@ -76,7 +76,7 @@ export function cubicNoiseSample1(config: ReturnType, x export function cubicNoiseSample2( { octave, periodX, periodY, seed, scale }: ReturnType, x: number, - y: number + y: number, ) { const xi = Math.floor(x / octave); const lerpX = Math.floor((x * ACCURACY) / octave) - xi * ACCURACY; @@ -99,11 +99,11 @@ export function cubicNoiseSample2( randomize(seed, x3, y), lerpX, ACCURACY, - 1 + 1, ); } return Math.floor( - interpolate(xSamples[0], xSamples[1], xSamples[2], xSamples[3], lerpY, ACCURACY, scale) / Math.pow(ACCURACY, 6) + interpolate(xSamples[0], xSamples[1], xSamples[2], xSamples[3], lerpY, ACCURACY, scale) / Math.pow(ACCURACY, 6), ); } diff --git a/packages/utils/src/mobx.ts b/packages/utils/src/mobx.ts index 659c28fa54..40583c831c 100644 --- a/packages/utils/src/mobx.ts +++ b/packages/utils/src/mobx.ts @@ -15,7 +15,7 @@ export async function awaitValue(comp: IComputedValue | IObser resolve(value); } }, - { fireImmediately: true } + { fireImmediately: true }, ); const value = await promise; diff --git a/packages/utils/src/objects.ts b/packages/utils/src/objects.ts index fc491bb3c5..8b75d21d22 100644 --- a/packages/utils/src/objects.ts +++ b/packages/utils/src/objects.ts @@ -6,7 +6,7 @@ */ export function mapObject( source: S, - valueMap: (value: S[keyof S], key: keyof S) => T[keyof S] + valueMap: (value: S[keyof S], key: keyof S) => T[keyof S], ): T { const target: Partial<{ [key in keyof typeof source]: T[keyof S] }> = {}; for (const key in source) { diff --git a/packages/utils/src/promise.ts b/packages/utils/src/promise.ts index fcd11bd2a6..0af015a14b 100644 --- a/packages/utils/src/promise.ts +++ b/packages/utils/src/promise.ts @@ -20,7 +20,7 @@ export const callWithRetry = ( fn: (...args: any[]) => Promise, args: any[] = [], maxRetries = 10, - retryInterval = 1000 + retryInterval = 1000, ): Promise => { const [resolve, reject, promise] = deferred(); const process = async () => { diff --git a/packages/utils/src/proxy.ts b/packages/utils/src/proxy.ts index dc41151af6..85c599c21c 100644 --- a/packages/utils/src/proxy.ts +++ b/packages/utils/src/proxy.ts @@ -20,7 +20,7 @@ function deepAccess(target: Record, path: string[]): any { * @returns Cached */ export function cacheUntilReady>( - target: IObservableValue | IComputedValue + target: IObservableValue | IComputedValue, ): Cached { // The call queue contains the path and arguments of calls to the // proxiedTarget while the target was not available yet. @@ -71,7 +71,7 @@ export function cacheUntilReady>( return promise; } }, - } + }, ); reaction( @@ -94,7 +94,7 @@ export function cacheUntilReady>( resolve(target); } } - } + }, ); return proxiedTarget as Cached; diff --git a/packages/utils/src/rx.ts b/packages/utils/src/rx.ts index b18835a6b4..7a37b1f24a 100644 --- a/packages/utils/src/rx.ts +++ b/packages/utils/src/rx.ts @@ -19,7 +19,7 @@ import { awaitValue } from "./mobx"; export function filterNullish(): OperatorFunction> { return pipe, Observable>>( - filter((x: T) => x != null) as OperatorFunction> + filter((x: T) => x != null) as OperatorFunction>, ); } @@ -50,7 +50,7 @@ export function stretch(spacingDelayMs: number) { }; }, null), filterNullish(), - mergeMap((i) => of(i.value).pipe(delay(i.delay)), 1) + mergeMap((i) => of(i.value).pipe(delay(i.delay)), 1), ); } @@ -65,7 +65,7 @@ export function computedToStream(comp: IComputedValue | IObservableValue { if (value != null) stream.next(value); }, - { fireImmediately: true } + { fireImmediately: true }, ); return stream; } @@ -77,7 +77,7 @@ export function observableToStream(obs: T): Observable { (value) => { if (value != null) stream.next(value); }, - { fireImmediately: true } + { fireImmediately: true }, ); return stream; } @@ -104,7 +104,7 @@ export async function streamToDefinedComputed(stream$: Observable): Promis */ export async function awaitStreamValue( stream$: Observable, - predicate: (value: T) => boolean = (value) => value != null + predicate: (value: T) => boolean = (value) => value != null, ): Promise { const [resolve, , promise] = deferred(); stream$.pipe(first(predicate)).subscribe(resolve); diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index 1649769316..b9c1f99a4a 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -8,13 +8,13 @@ export type CachedValue = Proxied extends true ? V extends Func ? AsyncFunc : V extends Record - ? Cached & { proxied: true } - : { proxied: true } + ? Cached & { proxied: true } + : { proxied: true } : V extends Func - ? Func - : V extends Record - ? V - : V & { proxied: false }; + ? Func + : V extends Record + ? V + : V & { proxied: false }; export type Cached = | ({ proxied: false } & { [key in keyof C]: CachedValue }) diff --git a/packages/world/ts/config/resolveWorldConfig.ts b/packages/world/ts/config/resolveWorldConfig.ts index 656cc8fd5e..aedae246e6 100644 --- a/packages/world/ts/config/resolveWorldConfig.ts +++ b/packages/world/ts/config/resolveWorldConfig.ts @@ -28,7 +28,7 @@ export function resolveWorldConfig(config: StoreConfig & WorldConfig, existingCo // Combine the default and overridden system names and filter out excluded systems const systemNames = [...new Set([...defaultSystemNames, ...overriddenSystemNames])].filter( - (name) => !config.excludeSystems.includes(name) + (name) => !config.excludeSystems.includes(name), ); // Resolve the config diff --git a/packages/world/ts/config/types.ts b/packages/world/ts/config/types.ts index 5cb70b6910..3a590229f0 100644 --- a/packages/world/ts/config/types.ts +++ b/packages/world/ts/config/types.ts @@ -5,30 +5,29 @@ import { zWorldConfig } from "./worldConfig"; import { SYSTEM_DEFAULTS } from "./defaults"; // zod doesn't preserve doc comments -export type SystemUserConfig = +export type SystemUserConfig = { + /** The full resource selector consists of namespace and name */ + name?: string; + /** + * Register function selectors for the system in the World. + * Defaults to true. + * Note: + * - For root systems all World function selectors will correspond to the system's function selectors. + * - For non-root systems, the World function selectors will be __. + */ + registerFunctionSelectors?: boolean; +} & ( | { - /** The full resource selector consists of namespace and name */ - name?: string; - /** - * Register function selectors for the system in the World. - * Defaults to true. - * Note: - * - For root systems all World function selectors will correspond to the system's function selectors. - * - For non-root systems, the World function selectors will be __. - */ - registerFunctionSelectors?: boolean; - } & ( - | { - /** If openAccess is true, any address can call the system */ - openAccess?: true; - } - | { - /** If openAccess is false, only the addresses or systems in `access` can call the system */ - openAccess: false; - /** An array of addresses or system names that can access the system */ - accessList: string[]; - } - ); + /** If openAccess is true, any address can call the system */ + openAccess?: true; + } + | { + /** If openAccess is false, only the addresses or systems in `access` can call the system */ + openAccess: false; + /** An array of addresses or system names that can access the system */ + accessList: string[]; + } +); export interface ExpandSystemConfig extends OrDefaults< diff --git a/packages/world/ts/config/worldConfig.ts b/packages/world/ts/config/worldConfig.ts index ecd579ac7f..71d56c8de7 100644 --- a/packages/world/ts/config/worldConfig.ts +++ b/packages/world/ts/config/worldConfig.ts @@ -20,7 +20,7 @@ const zSystemConfig = z.intersection( openAccess: z.literal(false), accessList: zSystemAccessList, }), - ]) + ]), ); const zValueWithType = z.object({ diff --git a/packages/world/ts/encodeSystemCalls.ts b/packages/world/ts/encodeSystemCalls.ts index fe027924da..f93301da43 100644 --- a/packages/world/ts/encodeSystemCalls.ts +++ b/packages/world/ts/encodeSystemCalls.ts @@ -6,7 +6,7 @@ import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype" /** Encode system calls to be passed as arguments into `World.batchCall` */ export function encodeSystemCalls>( abi: abi, - systemCalls: readonly Omit, "abi">[] + systemCalls: readonly Omit, "abi">[], ): AbiParametersToPrimitiveTypes["inputs"]>[] { return systemCalls.map((systemCall) => encodeSystemCall({ ...systemCall, abi } as SystemCall)); } diff --git a/packages/world/ts/encodeSystemCallsFrom.ts b/packages/world/ts/encodeSystemCallsFrom.ts index f5c9bf548e..0e0b40d0da 100644 --- a/packages/world/ts/encodeSystemCallsFrom.ts +++ b/packages/world/ts/encodeSystemCallsFrom.ts @@ -7,9 +7,9 @@ import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype" export function encodeSystemCallsFrom>( abi: abi, from: Address, - systemCalls: readonly Omit, "abi" | "from">[] + systemCalls: readonly Omit, "abi" | "from">[], ): AbiParametersToPrimitiveTypes["inputs"]>[] { return systemCalls.map((systemCall) => - encodeSystemCallFrom({ ...systemCall, abi, from } as SystemCallFrom) + encodeSystemCallFrom({ ...systemCall, abi, from } as SystemCallFrom), ); } diff --git a/packages/world/ts/node/render-solidity/renderSystemInterface.ts b/packages/world/ts/node/render-solidity/renderSystemInterface.ts index b3a6ce7a92..05dc7ed43d 100644 --- a/packages/world/ts/node/render-solidity/renderSystemInterface.ts +++ b/packages/world/ts/node/render-solidity/renderSystemInterface.ts @@ -22,7 +22,7 @@ export function renderSystemInterface(options: RenderSystemInterfaceOptions) { function ${functionPrefix}${name}( ${renderArguments(parameters)} ) external ${stateMutability} ${renderReturnParameters(returnParameters)}; - ` + `, )} } `; diff --git a/packages/world/ts/node/render-solidity/worldgen.ts b/packages/world/ts/node/render-solidity/worldgen.ts index f9dbf77d37..af5313ead3 100644 --- a/packages/world/ts/node/render-solidity/worldgen.ts +++ b/packages/world/ts/node/render-solidity/worldgen.ts @@ -10,11 +10,11 @@ import { WorldConfig } from "../../config/types"; export async function worldgen( config: StoreConfig & WorldConfig, existingContracts: { path: string; basename: string }[], - outputBaseDirectory: string + outputBaseDirectory: string, ) { const resolvedConfig = resolveWorldConfig( config, - existingContracts.map(({ basename }) => basename) + existingContracts.map(({ basename }) => basename), ); const worldgenBaseDirectory = path.join(outputBaseDirectory, config.worldgenDirectory); diff --git a/packages/world/ts/worldEvents.test.ts b/packages/world/ts/worldEvents.test.ts index 080a1740fa..477e61127e 100644 --- a/packages/world/ts/worldEvents.test.ts +++ b/packages/world/ts/worldEvents.test.ts @@ -19,7 +19,7 @@ function normalizeAbiEvent(event: AbiEvent) { describe("WorldFactory events", () => { it("should match the ABI", () => { const forgeAbiItem = IWorldFactoryAbi.find( - (item) => item.type === "event" && item.name === "WorldDeployed" + (item) => item.type === "event" && item.name === "WorldDeployed", ) as AbiEvent; expect(normalizeAbiEvent(parseAbiItem(worldDeployedEvent))).toMatchObject(normalizeAbiEvent(forgeAbiItem)); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f1498d25a2..ce0f90e916 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,11 +39,11 @@ importers: specifier: '>=10' version: 10.0.0 prettier: - specifier: ^2.8.4 - version: 2.8.4 + specifier: 3.2.5 + version: 3.2.5 prettier-plugin-solidity: specifier: 1.3.1 - version: 1.3.1(prettier@2.8.4) + version: 1.3.1(prettier@3.2.5) rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -282,11 +282,11 @@ importers: specifier: ^5.1.2 version: 5.1.2 prettier: - specifier: ^2.8.4 - version: 2.8.4 + specifier: 3.2.5 + version: 3.2.5 prettier-plugin-solidity: specifier: 1.3.1 - version: 1.3.1(prettier@2.8.4) + version: 1.3.1(prettier@3.2.5) viem: specifier: 2.7.12 version: 2.7.12(typescript@5.1.6)(zod@3.21.4) @@ -9955,14 +9955,14 @@ packages: engines: {node: '>= 0.8.0'} dev: true - /prettier-plugin-solidity@1.3.1(prettier@2.8.4): + /prettier-plugin-solidity@1.3.1(prettier@3.2.5): resolution: {integrity: sha512-MN4OP5I2gHAzHZG1wcuJl0FsLS3c4Cc5494bbg+6oQWBPuEamjwDvmGfFMZ6NFzsh3Efd9UUxeT7ImgjNH4ozA==} engines: {node: '>=16'} peerDependencies: prettier: '>=2.3.0' dependencies: '@solidity-parser/parser': 0.17.0 - prettier: 2.8.4 + prettier: 3.2.5 semver: 7.6.0 solidity-comments-extractor: 0.0.8 @@ -9978,6 +9978,12 @@ packages: resolution: {integrity: sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==} engines: {node: '>=10.13.0'} hasBin: true + dev: true + + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} + hasBin: true /pretty-format@27.5.1: resolution: {integrity: sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==} diff --git a/scripts/changelog.ts b/scripts/changelog.ts index 9daee85ea1..42e4c61049 100644 --- a/scripts/changelog.ts +++ b/scripts/changelog.ts @@ -116,7 +116,7 @@ async function getChanges(include: "diff" | "all") { const changeset = readFileSync(changesetPath).toString(); const gitLog = (await execa("git", ["log", changesetPath])).stdout; return { ...parseChangeset(changeset), ...parseGitLog(gitLog) }; - }) + }), ); // Sort the changesets into patch, minor and major updates diff --git a/scripts/render-api-docs.ts b/scripts/render-api-docs.ts index 8e3e70fe98..f29db51ad2 100644 --- a/scripts/render-api-docs.ts +++ b/scripts/render-api-docs.ts @@ -236,7 +236,7 @@ const PUBLIC_APIS: PublicApis = { .replaceAll("This is an autogenerated file; do not edit manually", "") .replaceAll( "*This interface is automatically generated from the corresponding system contract. Do not edit manually.*", - "" + "", ) .replace(/## StoreData((.|\n)*?)### Functions/m, "### Functions") .replace(/#### constructor((.|\n)*?)#### storeVersion/m, "#### storeVersion") @@ -420,7 +420,7 @@ function getPackages() { Object.values(PUBLIC_APIS) .map(({ inputFiles }) => inputFiles) .flat() - .map((input) => input.source.split("/")[0]) + .map((input) => input.source.split("/")[0]), ), ]; } @@ -470,11 +470,11 @@ async function renderDocs() { .map((fileName) => readFileSync(path.join(docsPath, fileName), { encoding: "utf8" })); }) .flat() - .join("\n") + .join("\n"), ); // Write the output file - writeFileSync(path.join(DOCS_ROOT, outputFile), formatMarkdown(content)); + writeFileSync(path.join(DOCS_ROOT, outputFile), await formatMarkdown(content)); } } diff --git a/templates/phaser/packages/client/src/mud/createSystemCalls.ts b/templates/phaser/packages/client/src/mud/createSystemCalls.ts index f3c72c4e9f..fef3e78936 100644 --- a/templates/phaser/packages/client/src/mud/createSystemCalls.ts +++ b/templates/phaser/packages/client/src/mud/createSystemCalls.ts @@ -37,7 +37,7 @@ export function createSystemCalls( * (https://github.com/latticexyz/mud/blob/main/templates/phaser/packages/client/src/mud/setupNetwork.ts#L75-L81). */ { worldContract, waitForTransaction }: SetupNetworkResult, - { Counter }: ClientComponents + { Counter }: ClientComponents, ) { const increment = async () => { /* diff --git a/templates/phaser/packages/client/src/ui/App.tsx b/templates/phaser/packages/client/src/ui/App.tsx index a61f2ba87e..7dd4d29641 100644 --- a/templates/phaser/packages/client/src/ui/App.tsx +++ b/templates/phaser/packages/client/src/ui/App.tsx @@ -26,7 +26,7 @@ export const App = () => { worldAbi: networkLayer.network.worldContract.abi, write$: networkLayer.network.write$, recsWorld: networkLayer.world, - }) + }), ); } }, [networkLayer]); diff --git a/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx b/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx index ff47610f2c..2d428b0c24 100644 --- a/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx +++ b/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx @@ -80,7 +80,7 @@ export const usePhaserLayer = ({ networkLayer }: Props) => { } } }, - [container] + [container], ); return useMemo(() => ({ ref, phaserLayer }), [ref, phaserLayer]); diff --git a/templates/phaser/packages/contracts/package.json b/templates/phaser/packages/contracts/package.json index a79cc0adbd..b2640d68cd 100644 --- a/templates/phaser/packages/contracts/package.json +++ b/templates/phaser/packages/contracts/package.json @@ -25,7 +25,7 @@ "@types/node": "^18.15.11", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "^2.6.2", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", diff --git a/templates/react-ecs/packages/client/src/index.tsx b/templates/react-ecs/packages/client/src/index.tsx index da8d70f020..1b005dc561 100644 --- a/templates/react-ecs/packages/client/src/index.tsx +++ b/templates/react-ecs/packages/client/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts b/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts index 09e7807c6f..30b4f7f6b7 100644 --- a/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +++ b/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts @@ -31,7 +31,7 @@ export function createSystemCalls( * (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83). */ { worldContract, waitForTransaction }: SetupNetworkResult, - { Counter }: ClientComponents + { Counter }: ClientComponents, ) { const increment = async () => { /* diff --git a/templates/react-ecs/packages/contracts/package.json b/templates/react-ecs/packages/contracts/package.json index a79cc0adbd..b2640d68cd 100644 --- a/templates/react-ecs/packages/contracts/package.json +++ b/templates/react-ecs/packages/contracts/package.json @@ -25,7 +25,7 @@ "@types/node": "^18.15.11", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "^2.6.2", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", diff --git a/templates/react/packages/client/src/index.tsx b/templates/react/packages/client/src/index.tsx index 3ba2a44052..c9b662c9f0 100644 --- a/templates/react/packages/client/src/index.tsx +++ b/templates/react/packages/client/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/templates/react/packages/client/src/mud/createSystemCalls.ts b/templates/react/packages/client/src/mud/createSystemCalls.ts index 7f9cb42e04..d7714ec453 100644 --- a/templates/react/packages/client/src/mud/createSystemCalls.ts +++ b/templates/react/packages/client/src/mud/createSystemCalls.ts @@ -28,7 +28,7 @@ export function createSystemCalls( * syncToRecs * (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83). */ - { tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult + { tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult, ) { const addTask = async (label: string) => { const tx = await worldContract.write.addTask([label]); diff --git a/templates/react/packages/contracts/package.json b/templates/react/packages/contracts/package.json index a79cc0adbd..b2640d68cd 100644 --- a/templates/react/packages/contracts/package.json +++ b/templates/react/packages/contracts/package.json @@ -25,7 +25,7 @@ "@types/node": "^18.15.11", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "^2.6.2", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", diff --git a/templates/threejs/packages/client/src/index.tsx b/templates/threejs/packages/client/src/index.tsx index da8d70f020..1b005dc561 100644 --- a/templates/threejs/packages/client/src/index.tsx +++ b/templates/threejs/packages/client/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/templates/threejs/packages/client/src/mud/createSystemCalls.ts b/templates/threejs/packages/client/src/mud/createSystemCalls.ts index 145e2ef1e5..d537c578fb 100644 --- a/templates/threejs/packages/client/src/mud/createSystemCalls.ts +++ b/templates/threejs/packages/client/src/mud/createSystemCalls.ts @@ -30,7 +30,7 @@ export function createSystemCalls( * (https://github.com/latticexyz/mud/blob/main/templates/threejs/packages/client/src/mud/setupNetwork.ts#L75-L81). */ { worldContract, waitForTransaction, playerEntity }: SetupNetworkResult, - { Position }: ClientComponents + { Position }: ClientComponents, ) { const moveTo = async (x: number, y: number, z: number) => { /* diff --git a/templates/threejs/packages/contracts/package.json b/templates/threejs/packages/contracts/package.json index 551f5c90b5..f5c5dc1be2 100644 --- a/templates/threejs/packages/contracts/package.json +++ b/templates/threejs/packages/contracts/package.json @@ -24,7 +24,7 @@ "@types/node": "^18.15.11", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "^2.6.2", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", diff --git a/templates/vanilla/packages/client/src/mud/createSystemCalls.ts b/templates/vanilla/packages/client/src/mud/createSystemCalls.ts index ebff84233d..f153b51e86 100644 --- a/templates/vanilla/packages/client/src/mud/createSystemCalls.ts +++ b/templates/vanilla/packages/client/src/mud/createSystemCalls.ts @@ -31,7 +31,7 @@ export function createSystemCalls( * (https://github.com/latticexyz/mud/blob/main/templates/vanilla/packages/client/src/mud/setupNetwork.ts#L77-L83). */ { worldContract, waitForTransaction }: SetupNetworkResult, - { Counter }: ClientComponents + { Counter }: ClientComponents, ) { const increment = async () => { /* diff --git a/templates/vanilla/packages/contracts/package.json b/templates/vanilla/packages/contracts/package.json index a79cc0adbd..b2640d68cd 100644 --- a/templates/vanilla/packages/contracts/package.json +++ b/templates/vanilla/packages/contracts/package.json @@ -25,7 +25,7 @@ "@types/node": "^18.15.11", "ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", "forge-std": "https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1", - "prettier": "^2.6.2", + "prettier": "3.2.5", "prettier-plugin-solidity": "1.3.1", "solhint": "^3.3.7", "solhint-config-mud": "file:../../../../packages/solhint-config-mud", From 40307adf5b2cd70320ae15ceb579d918d66b83b1 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 23 Feb 2024 17:16:05 +0000 Subject: [PATCH 3/8] chore: add release.wasm.map --- packages/noise/build/release.wasm.map | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/noise/build/release.wasm.map b/packages/noise/build/release.wasm.map index 3b2c0ebb37..b6c8a7775e 100644 --- a/packages/noise/build/release.wasm.map +++ b/packages/noise/build/release.wasm.map @@ -1 +1 @@ -{"version":3,"sources":["~lib/rt/common.ts","~lib/rt/tlsf.ts","~lib/shared/typeinfo.ts","~lib/rt/itcms.ts","assembly/perlin.ts","~lib/util/math.ts","~lib/util/number.ts","~lib/util/string.ts","~lib/math.ts","~lib/shared/runtime.ts","~lib/util/sort.ts","~lib/array.ts","~lib/util/error.ts"],"names":[],"mappings":"yGWiHI,AAAI,EAAc,AAAK,SAAmC,eAO1D,AANoB,MAAkB,EAAgB,6CPvDhD,EAAO,uBAEJ,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAhChB,6QAJW,AAJX,AAAO,EAAI,GAAI,GAAK,EAAK,EAAI,UAAI,WAAM,qCAInB,mDAAT,AAJX,AAAO,EAAI,GAAI,GAAK,EAAK,EAAI,UAAI,WAAM,eAI5B,cAAS,2DAAT,iBAAS,0CAAT,AAJJ,EAAI,GAAI,GAAK,EAAK,EAAI,UAAI,WAAM,aAI5B,qBAAS","sourceRoot":"./release","sourcesContent":["// Alignment guarantees\n\n// @ts-ignore: decorator\n@inline export const AL_BITS: u32 = 4; // 16 bytes to fit up to v128\n// @ts-ignore: decorator\n@inline export const AL_SIZE: usize = 1 << AL_BITS;\n// @ts-ignore: decorator\n@inline export const AL_MASK: usize = AL_SIZE - 1;\n\n// Extra debugging\n\n// @ts-ignore: decorator\n@inline export const DEBUG = true;\n// @ts-ignore: decorator\n@inline export const TRACE = false;\n// @ts-ignore: decorator\n@inline export const RTRACE = isDefined(ASC_RTRACE);\n// @ts-ignore: decorator\n@inline export const PROFILE = isDefined(ASC_PROFILE);\n\n// Memory manager\n\n// ╒════════════ Memory manager block 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// │ MM info │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class BLOCK {\n /** Memory manager info. */\n mmInfo: usize;\n}\n\n/** Overhead of a memory manager block. */\n// @ts-ignore: decorator\n@inline export const BLOCK_OVERHEAD: usize = offsetof();\n\n/** Maximum size of a memory manager block's payload. */\n// @ts-ignore: decorator\n@inline export const BLOCK_MAXSIZE: usize = (1 << 30) - BLOCK_OVERHEAD;\n\n// Garbage collector\n\n// ╒══════════ Garbage collector 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// │ Memory manager block │ -20\n// ╞═══════════════════════════════════════════════════════════════╡\n// │ GC info │ -16\n// ├───────────────────────────────────────────────────────────────┤\n// │ GC info │ -12\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT id │ -8\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT size │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class OBJECT extends BLOCK {\n /** Garbage collector info. */\n gcInfo: u32;\n /** Garbage collector info. */\n gcInfo2: u32;\n /** Runtime class id. */\n rtId: u32;\n /** Runtime object size. */\n rtSize: u32;\n}\n\n/** Overhead of a garbage collector object. Excludes memory manager block overhead. */\n// @ts-ignore: decorator\n@inline export const OBJECT_OVERHEAD: usize = (offsetof() - BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK;\n\n/** Maximum size of a garbage collector object's payload. */\n// @ts-ignore: decorator\n@inline export const OBJECT_MAXSIZE: usize = BLOCK_MAXSIZE - OBJECT_OVERHEAD;\n\n/** Total of memory manager and garbage collector overhead. */\n// @ts-ignore: decorator\n@inline export const TOTAL_OVERHEAD: usize = BLOCK_OVERHEAD + OBJECT_OVERHEAD;\n","import { AL_BITS, AL_SIZE, AL_MASK, DEBUG, BLOCK, BLOCK_OVERHEAD, BLOCK_MAXSIZE } from \"./common\";\nimport { oninit, onalloc, onresize, onmove, onfree } from \"./rtrace\";\nimport { E_ALLOCATION_TOO_LARGE } from \"../util/error\";\n\n// === The TLSF (Two-Level Segregate Fit) memory allocator ===\n// see: http://www.gii.upv.es/tlsf/\n\n// - `ffs(x)` is equivalent to `ctz(x)` with x != 0\n// - `fls(x)` is equivalent to `sizeof(x) * 8 - clz(x) - 1`\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\n// @ts-ignore: decorator\n@inline const SL_BITS: u32 = 4;\n// @ts-ignore: decorator\n@inline const SL_SIZE: u32 = 1 << SL_BITS;\n\n// @ts-ignore: decorator\n@inline const SB_BITS: u32 = SL_BITS + AL_BITS;\n// @ts-ignore: decorator\n@inline const SB_SIZE: u32 = 1 << SB_BITS;\n\n// @ts-ignore: decorator\n@inline const FL_BITS: u32 = 31 - SB_BITS;\n\n// [00]: < 256B (SB) [12]: < 1M\n// [01]: < 512B [13]: < 2M\n// [02]: < 1K [14]: < 4M\n// [03]: < 2K [15]: < 8M\n// [04]: < 4K [16]: < 16M\n// [05]: < 8K [17]: < 32M\n// [06]: < 16K [18]: < 64M\n// [07]: < 32K [19]: < 128M\n// [08]: < 64K [20]: < 256M\n// [09]: < 128K [21]: < 512M\n// [10]: < 256K [22]: <= 1G - OVERHEAD\n// [11]: < 512K\n// VMs limit to 2GB total (currently), making one 1G block max (or three 512M etc.) due to block overhead\n\n// Tags stored in otherwise unused alignment bits\n\n// @ts-ignore: decorator\n@inline const FREE: usize = 1 << 0;\n// @ts-ignore: decorator\n@inline const LEFTFREE: usize = 1 << 1;\n// @ts-ignore: decorator\n@inline const TAGS_MASK: usize = FREE | LEFTFREE; // <= AL_MASK\n\n// ╒════════════════════ Block 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 overhead\n// ╞>ptr═══════════════════════════════════════════════════════╧═╧═╡ │ ┘\n// │ if free: ◄ prev │ ◄─┤ usize\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ if free: next ► │ ◄─┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... │ │ >= 0\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ if free: back ▲ │ ◄─┘\n// └───────────────────────────────────────────────────────────────┘ >= MIN SIZE\n// F: FREE, L: LEFTFREE\n@unmanaged export class Block extends BLOCK {\n\n /** Previous free block, if any. Only valid if free, otherwise part of payload. */\n prev: Block | null;\n /** Next free block, if any. Only valid if free, otherwise part of payload. */\n next: Block | null;\n\n // If the block is free, there is a 'back'reference at its end pointing at its start.\n}\n\n// Block constants. A block must have a minimum size of three pointers so it can hold `prev`,\n// `next` and `back` if free.\n\n// @ts-ignore: decorator\n@inline const BLOCK_MINSIZE: usize = ((3 * sizeof() + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD; // prev + next + back\n// @ts-ignore: decorator\n// @inline const BLOCK_MAXSIZE: usize = 1 << (FL_BITS + SB_BITS - 1); // exclusive, lives in common.ts\n\n/** Gets the left block of a block. Only valid if the left block is free. */\n// @ts-ignore: decorator\n@inline function GETFREELEFT(block: Block): Block {\n return load(changetype(block) - sizeof());\n}\n\n/** Gets the right block of a block by advancing to the right by its size. */\n// @ts-ignore: decorator\n@inline function GETRIGHT(block: Block): Block {\n return changetype(changetype(block) + BLOCK_OVERHEAD + (block.mmInfo & ~TAGS_MASK));\n}\n\n// ╒═════════════════════ Root 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// │ slMap[22] │ ◄─┘ │\n// ╞═══════════════════════════════════════════════════════════════╡ usize\n// │ head[0] │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ head[367] │ ◄────┤\n// ╞═══════════════════════════════════════════════════════════════╡ │\n// │ tail │ ◄────┘\n// └───────────────────────────────────────────────────────────────┘ SIZE ┘\n// S: Small blocks map\n@unmanaged class Root {\n /** First level bitmap. */\n flMap: usize;\n}\n\n// Root constants. Where stuff is stored inside of the root structure.\n\n// @ts-ignore: decorator\n@inline const SL_START: usize = sizeof();\n// @ts-ignore: decorator\n@inline const SL_END: usize = SL_START + (FL_BITS << alignof());\n// @ts-ignore: decorator\n@inline const HL_START: usize = (SL_END + AL_MASK) & ~AL_MASK;\n// @ts-ignore: decorator\n@inline const HL_END: usize = HL_START + FL_BITS * SL_SIZE * sizeof();\n// @ts-ignore: decorator\n@inline const ROOT_SIZE: usize = HL_END + sizeof();\n\n// @ts-ignore: decorator\n@lazy export var ROOT: Root;\n\n/** Gets the second level map of the specified first level. */\n// @ts-ignore: decorator\n@inline function GETSL(root: Root, fl: usize): u32 {\n return load(\n changetype(root) + (fl << alignof()),\n SL_START\n );\n}\n\n/** Sets the second level map of the specified first level. */\n// @ts-ignore: decorator\n@inline function SETSL(root: Root, fl: usize, slMap: u32): void {\n store(\n changetype(root) + (fl << alignof()),\n slMap,\n SL_START\n );\n}\n\n/** Gets the head of the free list for the specified combination of first and second level. */\n// @ts-ignore: decorator\n@inline function GETHEAD(root: Root, fl: usize, sl: u32): Block | null {\n return load(\n changetype(root) + (((fl << SL_BITS) + sl) << alignof()),\n HL_START\n );\n}\n\n/** Sets the head of the free list for the specified combination of first and second level. */\n// @ts-ignore: decorator\n@inline function SETHEAD(root: Root, fl: usize, sl: u32, head: Block | null): void {\n store(\n changetype(root) + (((fl << SL_BITS) + sl) << alignof()),\n head,\n HL_START\n );\n}\n\n/** Gets the tail block.. */\n// @ts-ignore: decorator\n@inline function GETTAIL(root: Root): Block {\n return load(\n changetype(root),\n HL_END\n );\n}\n\n/** Sets the tail block. */\n// @ts-ignore: decorator\n@inline function SETTAIL(root: Root, tail: Block): void {\n store(\n changetype(root),\n tail,\n HL_END\n );\n}\n\n/** Inserts a previously used block back into the free list. */\nfunction insertBlock(root: Root, block: Block): void {\n if (DEBUG) assert(block); // cannot be null\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(blockInfo & FREE); // must be free\n\n var right = GETRIGHT(block);\n var rightInfo = right.mmInfo;\n\n // merge with right block if also free\n if (rightInfo & FREE) {\n removeBlock(root, right);\n block.mmInfo = blockInfo = blockInfo + BLOCK_OVERHEAD + (rightInfo & ~TAGS_MASK); // keep block tags\n right = GETRIGHT(block);\n rightInfo = right.mmInfo;\n // 'back' is set below\n }\n\n // merge with left block if also free\n if (blockInfo & LEFTFREE) {\n let left = GETFREELEFT(block);\n let leftInfo = left.mmInfo;\n if (DEBUG) assert(leftInfo & FREE); // must be free according to right tags\n removeBlock(root, left);\n block = left;\n block.mmInfo = blockInfo = leftInfo + BLOCK_OVERHEAD + (blockInfo & ~TAGS_MASK); // keep left tags\n // 'back' is set below\n }\n\n right.mmInfo = rightInfo | LEFTFREE;\n // reference to right is no longer used now, hence rightInfo is not synced\n\n // we now know the size of the block\n var size = blockInfo & ~TAGS_MASK;\n if (DEBUG) assert(size >= BLOCK_MINSIZE); // must be a valid size\n if (DEBUG) assert(changetype(block) + BLOCK_OVERHEAD + size == changetype(right)); // must match\n\n // set 'back' to itself at the end of block\n store(changetype(right) - sizeof(), block);\n\n // mapping_insert\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size >> AL_BITS);\n } else {\n const inv: usize = sizeof() * 8 - 1;\n let boundedSize = min(size, BLOCK_MAXSIZE);\n fl = inv - clz(boundedSize);\n sl = ((boundedSize >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\n\n // perform insertion\n var head = GETHEAD(root, fl, sl);\n block.prev = null;\n block.next = head;\n if (head) head.prev = block;\n SETHEAD(root, fl, sl, block);\n\n // update first and second level maps\n root.flMap |= (1 << fl);\n SETSL(root, fl, GETSL(root, fl) | (1 << sl));\n}\n\n/** Removes a free block from internal lists. */\nfunction removeBlock(root: Root, block: Block): void {\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(blockInfo & FREE); // must be free\n var size = blockInfo & ~TAGS_MASK;\n if (DEBUG) assert(size >= BLOCK_MINSIZE); // 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_BITS);\n } else {\n const inv: usize = sizeof() * 8 - 1;\n let boundedSize = min(size, BLOCK_MAXSIZE);\n fl = inv - clz(boundedSize);\n sl = ((boundedSize >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\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 == GETHEAD(root, fl, sl)) {\n SETHEAD(root, fl, sl, next);\n\n // clear second level map if head is empty now\n if (!next) {\n let slMap = GETSL(root, fl);\n SETSL(root, fl, slMap &= ~(1 << sl));\n\n // clear first level map if second level is empty now\n if (!slMap) root.flMap &= ~(1 << fl);\n }\n }\n // note: does not alter left/back because it is likely that splitting\n // is performed afterwards, invalidating those changes. so, the caller\n // must perform those updates.\n}\n\n/** Searches for a free block of at least the specified size. */\nfunction searchBlock(root: Root, size: usize): Block | null {\n // size was already asserted by caller\n\n // mapping_search\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size >> AL_BITS);\n } else {\n const halfMaxSize = BLOCK_MAXSIZE >> 1; // don't round last fl\n const inv: usize = sizeof() * 8 - 1;\n const invRound = inv - SL_BITS;\n let requestSize = size < halfMaxSize\n ? size + (1 << (invRound - clz(size))) - 1\n : size;\n fl = inv - clz(requestSize);\n sl = ((requestSize >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\n\n // search second level\n var slMap = GETSL(root, fl) & (~0 << sl);\n var head: Block | null = null;\n if (!slMap) {\n // search next larger first level\n let flMap = root.flMap & (~0 << (fl + 1));\n if (!flMap) {\n head = null;\n } else {\n fl = ctz(flMap);\n slMap = GETSL(root, fl);\n if (DEBUG) assert(slMap); // can't be zero if fl points here\n head = GETHEAD(root, fl, ctz(slMap));\n }\n } else {\n head = GETHEAD(root, fl, ctz(slMap));\n }\n return head;\n}\n\n/** Prepares the specified block before (re-)use, possibly splitting it. */\nfunction prepareBlock(root: Root, block: Block, size: usize): void {\n // size was already asserted by caller\n\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(!((size + BLOCK_OVERHEAD) & AL_MASK)); // size must be aligned so the new block is\n\n // split if the block can hold another MINSIZE block incl. overhead\n var remaining = (blockInfo & ~TAGS_MASK) - size;\n if (remaining >= BLOCK_OVERHEAD + BLOCK_MINSIZE) {\n block.mmInfo = size | (blockInfo & LEFTFREE); // also discards FREE\n\n let spare = changetype(changetype(block) + BLOCK_OVERHEAD + size);\n spare.mmInfo = (remaining - BLOCK_OVERHEAD) | FREE; // not LEFTFREE\n insertBlock(root, spare); // also sets 'back'\n\n // otherwise tag block as no longer FREE and right as no longer LEFTFREE\n } else {\n block.mmInfo = blockInfo & ~FREE;\n GETRIGHT(block).mmInfo &= ~LEFTFREE;\n }\n}\n\n/** Adds more memory to the pool. */\nfunction addMemory(root: Root, start: usize, end: usize): bool {\n if (DEBUG) assert(start <= end); // must be valid\n start = ((start + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;\n end &= ~AL_MASK;\n\n var tail = GETTAIL(root);\n var tailInfo: usize = 0;\n if (tail) { // more memory\n if (DEBUG) assert(start >= changetype(tail) + BLOCK_OVERHEAD);\n\n // merge with current tail if adjacent\n const offsetToTail = AL_SIZE;\n if (start - offsetToTail == changetype(tail)) {\n start -= offsetToTail;\n tailInfo = tail.mmInfo;\n } else {\n // We don't do this, but a user might `memory.grow` manually\n // leading to non-adjacent pages managed by TLSF.\n }\n\n } else if (DEBUG) { // first memory\n assert(start >= changetype(root) + 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_OVERHEAD + BLOCK_MINSIZE + BLOCK_OVERHEAD) {\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_OVERHEAD;\n var left = changetype(start);\n left.mmInfo = leftSize | FREE | (tailInfo & LEFTFREE);\n left.prev = null;\n left.next = null;\n\n // tail is a zero-length used block\n tail = changetype(start + BLOCK_OVERHEAD + leftSize);\n tail.mmInfo = 0 | LEFTFREE;\n SETTAIL(root, tail);\n\n insertBlock(root, left); // also merges with free left before tail / sets 'back'\n\n return true;\n}\n\n/** Grows memory to fit at least another block of the specified size. */\nfunction growMemory(root: Root, size: usize): void {\n if (ASC_LOW_MEMORY_LIMIT) {\n unreachable();\n return;\n }\n // Here, both rounding performed in searchBlock ...\n const halfMaxSize = BLOCK_MAXSIZE >> 1;\n if (size < halfMaxSize) { // don't round last fl\n const invRound = (sizeof() * 8 - 1) - SL_BITS;\n size += (1 << (invRound - clz(size))) - 1;\n }\n // and additional BLOCK_OVERHEAD must be taken into account. If we are going\n // to merge with the tail block, that's one time, otherwise it's two times.\n var pagesBefore = memory.size();\n size += BLOCK_OVERHEAD << usize((pagesBefore << 16) - BLOCK_OVERHEAD != changetype(GETTAIL(root)));\n var pagesNeeded = (((size + 0xffff) & ~0xffff) >>> 16);\n var pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) unreachable();\n }\n var pagesAfter = memory.size();\n addMemory(root, pagesBefore << 16, pagesAfter << 16);\n}\n\n/** Computes the size (excl. header) of a block. */\nfunction computeSize(size: usize): usize {\n // Size must be large enough and aligned minus preceeding overhead\n return size <= BLOCK_MINSIZE\n ? BLOCK_MINSIZE\n : ((size + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;\n}\n\n/** Prepares and checks an allocation size. */\nfunction prepareSize(size: usize): usize {\n if (size > BLOCK_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n return computeSize(size);\n}\n\n/** Initializes the root structure. */\nfunction initialize(): void {\n if (isDefined(ASC_RTRACE)) oninit(__heap_base);\n var rootOffset = (__heap_base + AL_MASK) & ~AL_MASK;\n var pagesBefore = memory.size();\n var pagesNeeded = ((((rootOffset + ROOT_SIZE) + 0xffff) & ~0xffff) >>> 16);\n if (pagesNeeded > pagesBefore && memory.grow(pagesNeeded - pagesBefore) < 0) unreachable();\n var root = changetype(rootOffset);\n root.flMap = 0;\n SETTAIL(root, changetype(0));\n for (let fl: usize = 0; fl < FL_BITS; ++fl) {\n SETSL(root, fl, 0);\n for (let sl: u32 = 0; sl < SL_SIZE; ++sl) {\n SETHEAD(root, fl, sl, null);\n }\n }\n var memStart = rootOffset + ROOT_SIZE;\n if (ASC_LOW_MEMORY_LIMIT) {\n const memEnd = ASC_LOW_MEMORY_LIMIT & ~AL_MASK;\n if (memStart <= memEnd) addMemory(root, memStart, memEnd);\n else unreachable(); // low memory limit already exceeded\n } else {\n addMemory(root, memStart, memory.size() << 16);\n }\n ROOT = root;\n}\n\n/** Allocates a block of the specified size. */\nexport function allocateBlock(root: Root, size: usize): Block {\n var payloadSize = prepareSize(size);\n var block = searchBlock(root, payloadSize);\n if (!block) {\n growMemory(root, payloadSize);\n block = changetype(searchBlock(root, payloadSize));\n if (DEBUG) assert(block); // must be found now\n }\n if (DEBUG) assert((block.mmInfo & ~TAGS_MASK) >= payloadSize); // must fit\n removeBlock(root, block);\n prepareBlock(root, block, payloadSize);\n if (isDefined(ASC_RTRACE)) onalloc(block);\n return block;\n}\n\n/** Reallocates a block to the specified size. */\nexport function reallocateBlock(root: Root, block: Block, size: usize): Block {\n var payloadSize = prepareSize(size);\n var blockInfo = block.mmInfo;\n var blockSize = blockInfo & ~TAGS_MASK;\n\n // possibly split and update runtime size if it still fits\n if (payloadSize <= blockSize) {\n prepareBlock(root, block, payloadSize);\n if (isDefined(ASC_RTRACE)) {\n if (payloadSize != blockSize) onresize(block, BLOCK_OVERHEAD + blockSize);\n }\n return block;\n }\n\n // merge with right free block if merger is large enough\n var right = GETRIGHT(block);\n var rightInfo = right.mmInfo;\n if (rightInfo & FREE) {\n let mergeSize = blockSize + BLOCK_OVERHEAD + (rightInfo & ~TAGS_MASK);\n if (mergeSize >= payloadSize) {\n removeBlock(root, right);\n block.mmInfo = (blockInfo & TAGS_MASK) | mergeSize;\n prepareBlock(root, block, payloadSize);\n if (isDefined(ASC_RTRACE)) onresize(block, BLOCK_OVERHEAD + blockSize);\n return block;\n }\n }\n\n // otherwise move the block\n return moveBlock(root, block, size);\n}\n\n/** Moves a block to a new one of the specified size. */\nfunction moveBlock(root: Root, block: Block, newSize: usize): Block {\n var newBlock = allocateBlock(root, newSize);\n memory.copy(changetype(newBlock) + BLOCK_OVERHEAD, changetype(block) + BLOCK_OVERHEAD, block.mmInfo & ~TAGS_MASK);\n if (changetype(block) >= __heap_base) {\n if (isDefined(ASC_RTRACE)) onmove(block, newBlock);\n freeBlock(root, block);\n }\n return newBlock;\n}\n\n/** Frees a block. */\nexport function freeBlock(root: Root, block: Block): void {\n if (isDefined(ASC_RTRACE)) onfree(block);\n block.mmInfo = block.mmInfo | FREE;\n insertBlock(root, block);\n}\n\n/** Checks that a used block is valid to be freed or reallocated. */\nfunction checkUsedBlock(ptr: usize): Block {\n var block = changetype(ptr - BLOCK_OVERHEAD);\n assert(\n ptr != 0 && !(ptr & AL_MASK) && // must exist and be aligned\n !(block.mmInfo & FREE) // must be used\n );\n return block;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __alloc(size: usize): usize {\n if (!ROOT) initialize();\n return changetype(allocateBlock(ROOT, size)) + BLOCK_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __realloc(ptr: usize, size: usize): usize {\n if (!ROOT) initialize();\n return (ptr < __heap_base\n ? changetype(moveBlock(ROOT, checkUsedBlock(ptr), size))\n : changetype(reallocateBlock(ROOT, checkUsedBlock(ptr), size))\n ) + BLOCK_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __free(ptr: usize): void {\n if (ptr < __heap_base) return;\n if (!ROOT) initialize();\n freeBlock(ROOT, checkUsedBlock(ptr));\n}\n","// This file is shared with the compiler and must remain portable\n\n// ╒═══════════════════ Typeinfo interpretation ═══════════════════╕\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// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ ◄─ __rtti_base\n// │ count │\n// ╞═══════════════════════════════════════════════════════════════╡ ┐\n// │ Typeinfo#flags [id=0] │ id < count\n// ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤\n// │ Typeinfo#base [id=0] │\n// ├───────────────────────────────────────────────────────────────┤\n// │ ... │\n\n/** Runtime type information data structure. */\n@unmanaged\nexport class Typeinfo {\n /** Flags describing the shape of this class type. */\n flags: TypeinfoFlags = TypeinfoFlags.NONE;\n /** Base class id or `0` if none. */\n base: u32 = 0;\n}\n\n/** Runtime type information flags. */\nexport const enum TypeinfoFlags {\n /** No specific flags. */\n NONE = 0,\n /** Type is an `ArrayBufferView`. */\n ARRAYBUFFERVIEW = 1 << 0,\n /** Type is an `Array`. */\n ARRAY = 1 << 1,\n /** Type is a `StaticArray`. */\n STATICARRAY = 1 << 2,\n /** Type is a `Set`. */\n SET = 1 << 3,\n /** Type is a `Map`. */\n MAP = 1 << 4,\n /** Type has no outgoing pointers. */\n POINTERFREE = 1 << 5,\n /** Value alignment of 1 byte. */\n VALUE_ALIGN_0 = 1 << 6,\n /** Value alignment of 2 bytes. */\n VALUE_ALIGN_1 = 1 << 7,\n /** Value alignment of 4 bytes. */\n VALUE_ALIGN_2 = 1 << 8,\n /** Value alignment of 8 bytes. */\n VALUE_ALIGN_3 = 1 << 9,\n /** Value alignment of 16 bytes. */\n VALUE_ALIGN_4 = 1 << 10,\n /** Value is a signed type. */\n VALUE_SIGNED = 1 << 11,\n /** Value is a float type. */\n VALUE_FLOAT = 1 << 12,\n /** Value type is nullable. */\n VALUE_NULLABLE = 1 << 13,\n /** Value type is managed. */\n VALUE_MANAGED = 1 << 14,\n /** Key alignment of 1 byte. */\n KEY_ALIGN_0 = 1 << 15,\n /** Key alignment of 2 bytes. */\n KEY_ALIGN_1 = 1 << 16,\n /** Key alignment of 4 bytes. */\n KEY_ALIGN_2 = 1 << 17,\n /** Key alignment of 8 bytes. */\n KEY_ALIGN_3 = 1 << 18,\n /** Key alignment of 16 bytes. */\n KEY_ALIGN_4 = 1 << 19,\n /** Key is a signed type. */\n KEY_SIGNED = 1 << 20,\n /** Key is a float type. */\n KEY_FLOAT = 1 << 21,\n /** Key type is nullable. */\n KEY_NULLABLE = 1 << 22,\n /** Key type is managed. */\n KEY_MANAGED = 1 << 23\n}\n","import { BLOCK, BLOCK_OVERHEAD, OBJECT_OVERHEAD, OBJECT_MAXSIZE, TOTAL_OVERHEAD, DEBUG, TRACE, RTRACE, PROFILE } from \"./common\";\nimport { onvisit, oncollect, oninterrupt, onyield } from \"./rtrace\";\nimport { TypeinfoFlags } from \"../shared/typeinfo\";\nimport { E_ALLOCATION_TOO_LARGE, E_ALREADY_PINNED, E_NOT_PINNED } from \"../util/error\";\n\n// === ITCMS: An incremental Tri-Color Mark & Sweep garbage collector ===\n// Adapted from Bach Le's μgc, see: https://github.com/bullno1/ugc\n\n// ╒═════════════╤══════════════ Colors ═══════════════════════════╕\n// │ Color │ Meaning │\n// ├─────────────┼─────────────────────────────────────────────────┤\n// │ WHITE* │ Unprocessed │\n// │ BLACK* │ Processed │\n// │ GRAY │ Processed with unprocessed children │\n// │ TRANSPARENT │ Manually pinned (always reachable) │\n// └─────────────┴─────────────────────────────────────────────────┘\n// * flipped between cycles\n\n// @ts-ignore: decorator\n@lazy var white = 0;\n// @ts-ignore: decorator\n@inline const gray = 2;\n// @ts-ignore: decorator\n@inline const transparent = 3;\n// @ts-ignore: decorator\n@inline const COLOR_MASK = 3;\n\n/** Size in memory of all objects currently managed by the GC. */\n// @ts-ignore: decorator\n@lazy var total: usize = 0;\n\n/** Currently transitioning from SWEEP to MARK state. */\n// @ts-ignore: decorator\n@inline const STATE_IDLE = 0;\n/** Currently marking reachable objects. */\n// @ts-ignore: decorator\n@inline const STATE_MARK = 1;\n/** Currently sweeping unreachable objects. */\n// @ts-ignore: decorator\n@inline const STATE_SWEEP = 2;\n/** Current collector state. */\n// @ts-ignore: decorator\n@lazy var state = STATE_IDLE;\n\n// @ts-ignore: decorator\n@lazy var fromSpace = initLazy(changetype(memory.data(offsetof())));\n// @ts-ignore: decorator\n@lazy var toSpace = initLazy(changetype(memory.data(offsetof())));\n// @ts-ignore: decorator\n@lazy var pinSpace = initLazy(changetype(memory.data(offsetof())));\n// @ts-ignore: decorator\n@lazy var iter: Object; // null\n\nfunction initLazy(space: Object): Object {\n space.nextWithColor = changetype(space);\n space.prev = space;\n return space;\n}\n\n/** Visit cookie indicating scanning of an object. */\n// @ts-ignore: decorator\n@inline const VISIT_SCAN = 0;\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// │ Memory manager block │\n// ╞═══════════════════════════════════════════════════════════╤═══╡\n// │ next │ C │ = nextWithColor\n// ├───────────────────────────────────────────────────────────┴───┤\n// │ prev │\n// ├───────────────────────────────────────────────────────────────┤\n// │ rtId │\n// ├───────────────────────────────────────────────────────────────┤\n// │ rtSize │\n// ╞>ptr═══════════════════════════════════════════════════════════╡\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 Object extends BLOCK {\n /** Pointer to the next object with color flags stored in the alignment bits. */\n nextWithColor: usize; // *u32\n /** Pointer to the previous object. */\n prev: Object; // *u32\n /** Runtime id. */\n rtId: u32;\n /** Runtime size. */\n rtSize: u32;\n\n /** Gets the pointer to the next object. */\n get next(): Object {\n return changetype(this.nextWithColor & ~COLOR_MASK);\n }\n\n /** Sets the pointer to the next object. */\n set next(obj: Object) {\n this.nextWithColor = changetype(obj) | (this.nextWithColor & COLOR_MASK);\n }\n\n /** Gets this object's color. */\n get color(): i32 {\n return i32(this.nextWithColor & COLOR_MASK);\n }\n\n /** Sets this object's color. */\n set color(color: i32) {\n this.nextWithColor = (this.nextWithColor & ~COLOR_MASK) | color;\n }\n\n /** Gets the size of this object in memory. */\n get size(): usize {\n return BLOCK_OVERHEAD + (this.mmInfo & ~3);\n }\n\n /** Tests if this object is pointerfree. */\n get isPointerfree(): bool {\n var rtId = this.rtId;\n return rtId <= idof() || (__typeinfo(rtId) & TypeinfoFlags.POINTERFREE) != 0;\n }\n\n /** Unlinks this object from its list. */\n unlink(): void {\n var next = this.next;\n if (next == null) {\n if (DEBUG) assert(this.prev == null && changetype(this) < __heap_base);\n return; // static data not yet linked\n }\n var prev = this.prev;\n if (DEBUG) assert(prev);\n next.prev = prev;\n prev.next = next;\n }\n\n /** Links this object to the specified list, with the given color. */\n linkTo(list: Object, withColor: i32): void {\n let prev = list.prev;\n this.nextWithColor = changetype(list) | withColor;\n this.prev = prev;\n prev.next = this;\n list.prev = this;\n }\n\n /** Marks this object as gray, that is reachable with unscanned children. */\n makeGray(): void {\n if (this == iter) iter = assert(this.prev);\n this.unlink();\n this.linkTo(toSpace, this.isPointerfree ? i32(!white) : gray);\n }\n}\n\n/** Visits all objects considered to be program roots. */\nfunction visitRoots(cookie: u32): void {\n __visit_globals(cookie);\n var pn = pinSpace;\n var iter = pn.next;\n while (iter != pn) {\n if (DEBUG) assert(iter.color == transparent);\n __visit_members(changetype(iter) + TOTAL_OVERHEAD, cookie);\n iter = iter.next;\n }\n}\n\n/** Visits all objects on the stack. */\nfunction visitStack(cookie: u32): void {\n var ptr = __stack_pointer;\n while (ptr < __heap_base) {\n __visit(load(ptr), cookie);\n ptr += sizeof();\n }\n}\n\n/** Performs a single step according to the current state. */\nfunction step(): usize {\n // Magic constants responsible for pause times. Obtained experimentally\n // using the compiler compiling itself. 2048 budget pro run by default.\n const MARKCOST = isDefined(ASC_GC_MARKCOST) ? ASC_GC_MARKCOST : 1;\n const SWEEPCOST = isDefined(ASC_GC_SWEEPCOST) ? ASC_GC_SWEEPCOST : 10;\n var obj: Object;\n switch (state) {\n case STATE_IDLE: {\n state = STATE_MARK;\n visitCount = 0;\n visitRoots(VISIT_SCAN);\n iter = toSpace;\n return visitCount * MARKCOST;\n }\n case STATE_MARK: {\n let black = i32(!white);\n obj = iter.next;\n while (obj != toSpace) {\n iter = obj;\n if (obj.color != black) { // skip already-blacks (pointerfree)\n obj.color = black;\n visitCount = 0;\n __visit_members(changetype(obj) + TOTAL_OVERHEAD, VISIT_SCAN);\n return visitCount * MARKCOST;\n }\n obj = obj.next;\n }\n visitCount = 0;\n visitRoots(VISIT_SCAN);\n obj = iter.next;\n if (obj == toSpace) {\n visitStack(VISIT_SCAN);\n obj = iter.next;\n while (obj != toSpace) {\n if (obj.color != black) {\n obj.color = black;\n __visit_members(changetype(obj) + TOTAL_OVERHEAD, VISIT_SCAN);\n }\n obj = obj.next;\n }\n let from = fromSpace;\n fromSpace = toSpace;\n toSpace = from;\n white = black;\n iter = from.next;\n state = STATE_SWEEP;\n }\n return visitCount * MARKCOST;\n }\n case STATE_SWEEP: {\n obj = iter;\n if (obj != toSpace) {\n iter = obj.next;\n if (DEBUG) assert(obj.color == i32(!white)); // old white\n free(obj);\n return SWEEPCOST;\n }\n toSpace.nextWithColor = changetype(toSpace);\n toSpace.prev = toSpace;\n state = STATE_IDLE;\n break;\n }\n }\n return 0;\n}\n\n/** Frees an object. */\nfunction free(obj: Object): void {\n if (changetype(obj) < __heap_base) {\n obj.nextWithColor = 0; // may become linked again\n obj.prev = changetype(0);\n } else {\n total -= obj.size;\n if (isDefined(__finalize)) {\n __finalize(changetype(obj) + TOTAL_OVERHEAD);\n }\n __free(changetype(obj) + BLOCK_OVERHEAD);\n }\n}\n\n// Garbage collector interface\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __new(size: usize, id: i32): usize {\n if (size >= OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n if (total >= threshold) interrupt();\n var obj = changetype(__alloc(OBJECT_OVERHEAD + size) - BLOCK_OVERHEAD);\n obj.rtId = id;\n obj.rtSize = size;\n obj.linkTo(fromSpace, white); // inits next/prev\n total += obj.size;\n var ptr = changetype(obj) + TOTAL_OVERHEAD;\n // may be visited before being fully initialized, so must fill\n memory.fill(ptr, 0, size);\n return ptr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __renew(oldPtr: usize, size: usize): usize {\n var oldObj = changetype(oldPtr - TOTAL_OVERHEAD);\n // Update object size if its block is large enough\n if (size <= (oldObj.mmInfo & ~3) - OBJECT_OVERHEAD) {\n oldObj.rtSize = size;\n return oldPtr;\n }\n // If not the same object anymore, we have to move it move it due to the\n // shadow stack potentially still referencing the old object\n var newPtr = __new(size, oldObj.rtId);\n memory.copy(newPtr, oldPtr, min(size, oldObj.rtSize));\n return newPtr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __link(parentPtr: usize, childPtr: usize, expectMultiple: bool): void {\n // Write barrier is unnecessary if non-incremental\n if (!childPtr) return;\n if (DEBUG) assert(parentPtr);\n var child = changetype(childPtr - TOTAL_OVERHEAD);\n if (child.color == white) {\n let parent = changetype(parentPtr - TOTAL_OVERHEAD);\n let parentColor = parent.color;\n if (parentColor == i32(!white)) {\n // Maintain the invariant that no black object may point to a white object.\n if (expectMultiple) {\n // Move the barrier \"backward\". Suitable for containers receiving multiple stores.\n // Avoids a barrier for subsequent objects stored into the same container.\n parent.makeGray();\n } else {\n // Move the barrier \"forward\". Suitable for objects receiving isolated stores.\n child.makeGray();\n }\n } else if (parentColor == transparent && state == STATE_MARK) {\n // Pinned objects are considered 'black' during the mark phase.\n child.makeGray();\n }\n }\n}\n\n// @ts-ignore: decorator\n@lazy var visitCount = 0;\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __visit(ptr: usize, cookie: i32): void {\n if (!ptr) return;\n let obj = changetype(ptr - TOTAL_OVERHEAD);\n if (RTRACE) if (!onvisit(obj)) return;\n if (obj.color == white) {\n obj.makeGray();\n ++visitCount;\n }\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __pin(ptr: usize): usize {\n if (ptr) {\n let obj = changetype(ptr - TOTAL_OVERHEAD);\n if (obj.color == transparent) {\n throw new Error(E_ALREADY_PINNED);\n }\n obj.unlink(); // from fromSpace\n obj.linkTo(pinSpace, transparent);\n }\n return ptr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __unpin(ptr: usize): void {\n if (!ptr) return;\n var obj = changetype(ptr - TOTAL_OVERHEAD);\n if (obj.color != transparent) {\n throw new Error(E_NOT_PINNED);\n }\n if (state == STATE_MARK) {\n // We may be right at the point after marking roots for the second time and\n // entering the sweep phase, in which case the object would be missed if it\n // is not only pinned but also a root. Make sure it isn't missed.\n obj.makeGray();\n } else {\n obj.unlink();\n obj.linkTo(fromSpace, white);\n }\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __collect(): void {\n if (TRACE) trace(\"GC (full) at\", 1, total);\n if (state > STATE_IDLE) {\n // finish current cycle\n while (state != STATE_IDLE) step();\n }\n // perform a full cycle\n step();\n while (state != STATE_IDLE) step();\n threshold = (total * IDLEFACTOR / 100) + GRANULARITY;\n if (TRACE) trace(\"GC (full) done at cur/max\", 2, total, memory.size() << 16);\n if (RTRACE || PROFILE) oncollect(total);\n}\n\n// Garbage collector automation\n\n/** How often to interrupt. The default of 1024 means \"interrupt each 1024 bytes allocated\". */\n// @ts-ignore: decorator\n@inline const GRANULARITY: usize = isDefined(ASC_GC_GRANULARITY) ? ASC_GC_GRANULARITY : 1024;\n/** How long to interrupt. The default of 200% means \"run at double the speed of allocations\". */\n// @ts-ignore: decorator\n@inline const STEPFACTOR: usize = isDefined(ASC_GC_SWEEPFACTOR) ? ASC_GC_SWEEPFACTOR : 200;\n/** How long to idle. The default of 200% means \"wait for memory to double before kicking in again\". */\n// @ts-ignore: decorator\n@inline const IDLEFACTOR: usize = isDefined(ASC_GC_IDLEFACTOR) ? ASC_GC_IDLEFACTOR : 200;\n\n/** Threshold of memory used by objects to exceed before interrupting again. */\n// @ts-ignore: decorator\n@lazy var threshold: usize = ((memory.size() << 16) - __heap_base) >> 1;\n\n/** Performs a reasonable amount of incremental GC steps. */\nfunction interrupt(): void {\n if (PROFILE) oninterrupt(total);\n if (TRACE) trace(\"GC (auto) at\", 1, total);\n var budget: isize = GRANULARITY * STEPFACTOR / 100;\n do {\n budget -= step();\n if (state == STATE_IDLE) {\n if (TRACE) trace(\"└ GC (auto) done at cur/max\", 2, total, memory.size() << 16);\n threshold = (total * IDLEFACTOR / 100) + GRANULARITY;\n if (PROFILE) onyield(total);\n return;\n }\n } while (budget > 0);\n if (TRACE) trace(\"└ GC (auto) ongoing at\", 1, total);\n threshold = total + GRANULARITY * usize(total - threshold < GRANULARITY);\n if (PROFILE) onyield(total);\n}\n","// Ported from perlin reference implementation (https://cs.nyu.edu/~perlin/noise/)\n\nexport function perlin(_x: i32, _y: i32, _z: i32, denom: i32): f64 {\n // Convert fraction into f64\n let x: f64 = f64(_x) / f64(denom);\n let y: f64 = f64(_y) / f64(denom);\n let z: f64 = f64(_z) / f64(denom);\n\n // Find unit cube that contains point\n const X: i32 = i32(Math.floor(x)) & 255;\n const Y: i32 = i32(Math.floor(y)) & 255;\n const Z: i32 = i32(Math.floor(z)) & 255;\n\n // Find relative x,y,z of point in cube\n x -= Math.floor(x);\n y -= Math.floor(y);\n z -= Math.floor(z);\n\n // Compute fade curves for each x,y,z\n const u: f64 = fade(x);\n const v: f64 = fade(y);\n const w: f64 = fade(z);\n\n // Hash coordinates of the 8 cube corners\n const A: i32 = p[X] + Y;\n const AA: i32 = p[A] + Z;\n const AB: i32 = p[A + 1] + Z;\n const B: i32 = p[X + 1] + Y;\n const BA: i32 = p[B] + Z;\n const BB: i32 = p[B + 1] + Z;\n\n // Add blended results from 8 corners of cube\n const r: f64 = lerp(\n w,\n lerp(\n v,\n lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z)),\n lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z))\n ),\n lerp(\n v,\n lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1)),\n lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1))\n )\n );\n\n // Shift to range from 0 to 1\n return (r + 1) / 2;\n}\n\nfunction fade(t: f64): f64 {\n return t * t * t * (t * (t * 6 - 15) + 10);\n}\n\nfunction lerp(t: f64, a: f64, b: f64): f64 {\n return a + t * (b - a);\n}\n\nfunction grad(hash: i32, x: f64, y: f64, z: f64): f64 {\n switch (hash & 0xf) {\n case 0x0:\n return x + y;\n case 0x1:\n return -x + y;\n case 0x2:\n return x - y;\n case 0x3:\n return -x - y;\n case 0x4:\n return x + z;\n case 0x5:\n return -x + z;\n case 0x6:\n return x - z;\n case 0x7:\n return -x - z;\n case 0x8:\n return y + z;\n case 0x9:\n return -y + z;\n case 0xa:\n return y - z;\n case 0xb:\n return -y - z;\n case 0xc:\n return y + x;\n case 0xd:\n return -y + z;\n case 0xe:\n return y - x;\n case 0xf:\n return -y - z;\n default:\n return 0; // never happens\n }\n}\n\nconst p: i32[] = [\n 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21,\n 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149,\n 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229,\n 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209,\n 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217,\n 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,\n 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98,\n 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179,\n 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50,\n 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180, 151,\n 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10,\n 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56,\n 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122,\n 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76,\n 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226,\n 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223,\n 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108,\n 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162,\n 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45,\n 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180,\n];\n","//\n// Lookup data for exp2f\n//\n\n// @ts-ignore: decorator\n@inline const EXP2F_TABLE_BITS = 5;\n\n// @ts-ignore: decorator\n@lazy @inline const EXP2F_DATA_TAB = memory.data([\n // exp2f_data_tab[i] = uint(2^(i/N)) - (i << 52-BITS)\n // used for computing 2^(k/N) for an int |k| < 150 N as\n // double(tab[k%N] + (k << 52-BITS))\n 0x3FF0000000000000, 0x3FEFD9B0D3158574, 0x3FEFB5586CF9890F, 0x3FEF9301D0125B51,\n 0x3FEF72B83C7D517B, 0x3FEF54873168B9AA, 0x3FEF387A6E756238, 0x3FEF1E9DF51FDEE1,\n 0x3FEF06FE0A31B715, 0x3FEEF1A7373AA9CB, 0x3FEEDEA64C123422, 0x3FEECE086061892D,\n 0x3FEEBFDAD5362A27, 0x3FEEB42B569D4F82, 0x3FEEAB07DD485429, 0x3FEEA47EB03A5585,\n 0x3FEEA09E667F3BCD, 0x3FEE9F75E8EC5F74, 0x3FEEA11473EB0187, 0x3FEEA589994CCE13,\n 0x3FEEACE5422AA0DB, 0x3FEEB737B0CDC5E5, 0x3FEEC49182A3F090, 0x3FEED503B23E255D,\n 0x3FEEE89F995AD3AD, 0x3FEEFF76F2FB5E47, 0x3FEF199BDD85529C, 0x3FEF3720DCEF9069,\n 0x3FEF5818DCFBA487, 0x3FEF7C97337B9B5F, 0x3FEFA4AFA2A490DA, 0x3FEFD0765B6E4540\n]);\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)\n// Wrong count: 168353 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function exp2f_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N, // 0x1.8p+52\n Ox127f = reinterpret(0x7F000000);\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n var xd = x;\n var ix = reinterpret(x);\n var ux = ix >> 20 & 0x7FF;\n if (ux >= 0x430) {\n // |x| >= 128 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > 0) return x * Ox127f; // x > 0 -> HugeVal (Owerflow)\n if (x <= -150) return 0; // x <= -150 -> 0 (Underflow)\n }\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)] and int k.\n var kd = xd + shift;\n var ki = reinterpret(kd);\n var r = xd - (kd - shift);\n var t: u64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n y = C2 * r + 1;\n y += (C0 * r + C1) * (r * r);\n y *= s;\n\n return y;\n}\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.)\n// Wrong count: 170635 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function expf_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000), // 0x1.8p+52\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep+0\n Ox1p127f = reinterpret(0x7F000000);\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394) / N / N / N, // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3) / N / N, // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6) / N; // 0x1.62e42ff0c52d6p-1\n\n var xd = x;\n var ix = reinterpret(x);\n var ux = ix >> 20 & 0x7FF;\n if (ux >= 0x42B) {\n // |x| >= 88 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > reinterpret(0x42B17217)) return x * Ox1p127f; // x > log(0x1p128) ~= 88.72 -> HugeVal (Owerflow)\n if (x < reinterpret(0xC2CFF1B4)) return 0; // x < log(0x1p-150) ~= -103.97 -> 0 (Underflow)\n }\n\n // x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k.\n var z = InvLn2N * xd;\n\n // Round and convert z to int, the result is in [-150*N, 128*N] and\n // ideally ties-to-even rule is used, otherwise the magnitude of r\n // can be bigger which gives larger approximation error.\n var kd = (z + shift);\n var ki = reinterpret(kd);\n var r = z - (kd - shift);\n var s: f64, y: f64, t: u64;\n\n // exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n\n return y;\n}\n\n//\n// Lookup data for log2f\n//\n\n// @ts-ignore: decorator\n@inline const LOG2F_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2F_DATA_TAB = memory.data([\n reinterpret(0x3FF661EC79F8F3BE), reinterpret(0xBFDEFEC65B963019), // 0x1.661ec79f8f3bep+0, -0x1.efec65b963019p-2,\n reinterpret(0x3FF571ED4AAF883D), reinterpret(0xBFDB0B6832D4FCA4), // 0x1.571ed4aaf883dp+0, -0x1.b0b6832d4fca4p-2,\n reinterpret(0x3FF49539F0F010B0), reinterpret(0xBFD7418B0A1FB77B), // 0x1.49539f0f010bp+0 , -0x1.7418b0a1fb77bp-2,\n reinterpret(0x3FF3C995B0B80385), reinterpret(0xBFD39DE91A6DCF7B), // 0x1.3c995b0b80385p+0, -0x1.39de91a6dcf7bp-2,\n reinterpret(0x3FF30D190C8864A5), reinterpret(0xBFD01D9BF3F2B631), // 0x1.30d190c8864a5p+0, -0x1.01d9bf3f2b631p-2,\n reinterpret(0x3FF25E227B0B8EA0), reinterpret(0xBFC97C1D1B3B7AF0), // 0x1.25e227b0b8eap+0 , -0x1.97c1d1b3b7afp-3 ,\n reinterpret(0x3FF1BB4A4A1A343F), reinterpret(0xBFC2F9E393AF3C9F), // 0x1.1bb4a4a1a343fp+0, -0x1.2f9e393af3c9fp-3,\n reinterpret(0x3FF12358F08AE5BA), reinterpret(0xBFB960CBBF788D5C), // 0x1.12358f08ae5bap+0, -0x1.960cbbf788d5cp-4,\n reinterpret(0x3FF0953F419900A7), reinterpret(0xBFAA6F9DB6475FCE), // 0x1.0953f419900a7p+0, -0x1.a6f9db6475fcep-5,\n reinterpret(0x3FF0000000000000), 0, // 0x1p+0, 0x0,\n reinterpret(0x3FEE608CFD9A47AC), reinterpret(0x3FB338CA9F24F53D), // 0x1.e608cfd9a47acp-1, 0x1.338ca9f24f53dp-4,\n reinterpret(0x3FECA4B31F026AA0), reinterpret(0x3FC476A9543891BA), // 0x1.ca4b31f026aap-1 , 0x1.476a9543891bap-3,\n reinterpret(0x3FEB2036576AFCE6), reinterpret(0x3FCE840B4AC4E4D2), // 0x1.b2036576afce6p-1, 0x1.e840b4ac4e4d2p-3,\n reinterpret(0x3FE9C2D163A1AA2D), reinterpret(0x3FD40645F0C6651C), // 0x1.9c2d163a1aa2dp-1, 0x1.40645f0c6651cp-2,\n reinterpret(0x3FE886E6037841ED), reinterpret(0x3FD88E9C2C1B9FF8), // 0x1.886e6037841edp-1, 0x1.88e9c2c1b9ff8p-2,\n reinterpret(0x3FE767DCF5534862), reinterpret(0x3FDCE0A44EB17BCC) // 0x1.767dcf5534862p-1, 0x1.ce0a44eb17bccp-2\n]);\n\n// ULP error: 0.752 (nearest rounding.)\n// Relative error: 1.9 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function log2f_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOG2F_TABLE_BITS) - 1,\n Ox1p23f = reinterpret(0x4B000000); // 0x1p23f\n\n const\n A0 = reinterpret(0xBFD712B6F70A7E4D), // -0x1.712b6f70a7e4dp-2\n A1 = reinterpret(0x3FDECABF496832E0), // 0x1.ecabf496832ep-2\n A2 = reinterpret(0xBFE715479FFAE3DE), // -0x1.715479ffae3dep-1\n A3 = reinterpret(0x3FF715475F35C8B8); // 0x1.715475f35c8b8p0\n\n var ux = reinterpret(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && predict_false(ix == 0x3f800000)) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if (ux * 2 == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log2(inf) == inf.\n if ((ux >> 31) || ux * 2 >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = (tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK;\n var top = tmp & 0xFF800000;\n var iz = ux - top;\n var k = tmp >> 23;\n\n var invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n var logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n var z = reinterpret(iz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n var r = z * invc - 1;\n var y0 = logc + k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n var y = A1 * r + A2;\n var p = A3 * r + y0;\n var r2 = r * r;\n y += A0 * r2;\n y = y * r2 + p;\n\n return y;\n}\n\n//\n// Lookup data for logf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/logf.c\n//\n\n// @ts-ignore: decorator\n@inline const LOGF_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline const LOGF_DATA_TAB = memory.data([\n reinterpret(0x3FF661EC79F8F3BE), reinterpret(0xBFD57BF7808CAADE), // 0x1.661ec79f8f3bep+0, -0x1.57bf7808caadep-2,\n reinterpret(0x3FF571ED4AAF883D), reinterpret(0xBFD2BEF0A7C06DDB), // 0x1.571ed4aaf883dp+0, -0x1.2bef0a7c06ddbp-2,\n reinterpret(0x3FF49539F0F010B0), reinterpret(0xBFD01EAE7F513A67), // 0x1.49539f0f010bp+0 , -0x1.01eae7f513a67p-2,\n reinterpret(0x3FF3C995B0B80385), reinterpret(0xBFCB31D8A68224E9), // 0x1.3c995b0b80385p+0, -0x1.b31d8a68224e9p-3,\n reinterpret(0x3FF30D190C8864A5), reinterpret(0xBFC6574F0AC07758), // 0x1.30d190c8864a5p+0, -0x1.6574f0ac07758p-3,\n reinterpret(0x3FF25E227B0B8EA0), reinterpret(0xBFC1AA2BC79C8100), // 0x1.25e227b0b8eap+0 , -0x1.1aa2bc79c81p-3 ,\n reinterpret(0x3FF1BB4A4A1A343F), reinterpret(0xBFBA4E76CE8C0E5E), // 0x1.1bb4a4a1a343fp+0, -0x1.a4e76ce8c0e5ep-4,\n reinterpret(0x3FF12358F08AE5BA), reinterpret(0xBFB1973C5A611CCC), // 0x1.12358f08ae5bap+0, -0x1.1973c5a611cccp-4,\n reinterpret(0x3FF0953F419900A7), reinterpret(0xBFA252F438E10C1E), // 0x1.0953f419900a7p+0, -0x1.252f438e10c1ep-5,\n reinterpret(0x3FF0000000000000), 0, // 0x1p+0, 0,\n reinterpret(0x3FEE608CFD9A47AC), reinterpret(0x3FAAA5AA5DF25984), // 0x1.e608cfd9a47acp-1, 0x1.aa5aa5df25984p-5,\n reinterpret(0x3FECA4B31F026AA0), reinterpret(0x3FBC5E53AA362EB4), // 0x1.ca4b31f026aap-1 , 0x1.c5e53aa362eb4p-4,\n reinterpret(0x3FEB2036576AFCE6), reinterpret(0x3FC526E57720DB08), // 0x1.b2036576afce6p-1, 0x1.526e57720db08p-3,\n reinterpret(0x3FE9C2D163A1AA2D), reinterpret(0x3FCBC2860D224770), // 0x1.9c2d163a1aa2dp-1, 0x1.bc2860d22477p-3 ,\n reinterpret(0x3FE886E6037841ED), reinterpret(0x3FD1058BC8A07EE1), // 0x1.886e6037841edp-1, 0x1.1058bc8a07ee1p-2,\n reinterpret(0x3FE767DCF5534862), reinterpret(0x3FD4043057B6EE09) // 0x1.767dcf5534862p-1, 0x1.4043057b6ee09p-2\n]);\n\n// ULP error: 0.818 (nearest rounding.)\n// Relative error: 1.957 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function logf_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOGF_TABLE_BITS) - 1,\n Ox1p23f = reinterpret(0x4B000000); // 0x1p23f\n\n const\n Ln2 = reinterpret(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1;\n A0 = reinterpret(0xBFD00EA348B88334), // -0x1.00ea348b88334p-2\n A1 = reinterpret(0x3FD5575B0BE00B6A), // 0x1.5575b0be00b6ap-2\n A2 = reinterpret(0xBFDFFFFEF20A4123); // -0x1.ffffef20a4123p-2\n\n var ux = reinterpret(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && ux == 0x3f800000) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if ((ux << 1) == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log(inf) == inf.\n if ((ux >> 31) || (ux << 1) >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = (tmp >> (23 - LOGF_TABLE_BITS)) & N_MASK;\n var k = tmp >> 23;\n var iz = ux - (tmp & 0x1FF << 23);\n\n var invc = load(LOGF_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n var logc = load(LOGF_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n\n var z = reinterpret(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2\n var r = z * invc - 1;\n var y0 = logc + k * Ln2;\n\n // Pipelined polynomial evaluation to approximate log1p(r).\n var r2 = r * r;\n var y = A1 * r + A2;\n y += A0 * r2;\n y = y * r2 + (y0 + r);\n\n return y;\n}\n\n//\n// Lookup data for powf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/powf.c\n//\n\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnanf(ux: u32): bool {\n return (ux << 1) - 1 >= (0x7f800000 << 1) - 1;\n}\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkintf(iy: u32): i32 {\n var e = iy >> 23 & 0xFF;\n if (e < 0x7F ) return 0;\n if (e > 0x7F + 23) return 2;\n e = 1 << (0x7F + 23 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// Subnormal input is normalized so ix has negative biased exponent.\n// Output is multiplied by N (POWF_SCALE) if TOINT_INTRINICS is set.\n// @ts-ignore: decorator\n@inline\nfunction log2f_inline(ux: u32): f64 {\n const N_MASK = (1 << LOG2F_TABLE_BITS) - 1;\n\n const\n A0 = reinterpret(0x3FD27616C9496E0B), // 0x1.27616c9496e0bp-2\n A1 = reinterpret(0xBFD71969A075C67A), // -0x1.71969a075c67ap-2\n A2 = reinterpret(0x3FDEC70A6CA7BADD), // 0x1.ec70a6ca7baddp-2\n A3 = reinterpret(0xBFE7154748BEF6C8), // -0x1.7154748bef6c8p-1\n A4 = reinterpret(0x3FF71547652AB82B); // 0x1.71547652ab82bp+0\n\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = usize((tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK);\n var top = tmp & 0xFF800000;\n var uz = ux - top;\n var k = top >> 23;\n\n var invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n var logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n var z = reinterpret(uz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n var r = z * invc - 1;\n var y0 = logc + k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n var y = A0 * r + A1;\n var p = A2 * r + A3;\n var q = A4 * r + y0;\n\n r *= r;\n q += p * r;\n y = y * (r * r) + q;\n\n return y;\n}\n\n// The output of log2 and thus the input of exp2 is either scaled by N\n// (in case of fast toint intrinsics) or not. The unscaled xd must be\n// in [-1021,1023], sign_bias sets the sign of the result.\n// @ts-ignore: decorator\n@inline\nfunction exp2f_inline(xd: f64, signBias: u32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N; // 0x1.8p+52\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)]\n var kd = (xd + shift);\n var ki = reinterpret(kd);\n var r = xd - (kd - shift);\n var t: u64, z: f64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += (ki + signBias) << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n return y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflowf(sign: u32, y: f32): f32 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret(0x70000000)); // 0x1p97f\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret(0x10000000)); // 0x1p-95f\n}\n\n// @ts-ignore: decorator\n@inline\nexport function powf_lut(x: f32, y: f32): f32 {\n const\n Ox1p23f = reinterpret(0x4B000000), // 0x1p23f\n UPPER_LIMIT = reinterpret(0x405FFFFFFFD1D571), // 0x1.fffffffd1d571p+6\n LOWER_LIMIT = -150.0,\n SIGN_BIAS = 1 << (EXP2F_TABLE_BITS + 11);\n\n var signBias: u32 = 0;\n var ix = reinterpret(x);\n var iy = reinterpret(y);\n var ny = 0;\n\n if (i32(ix - 0x00800000 >= 0x7f800000 - 0x00800000) | (ny = i32(zeroinfnanf(iy)))) {\n // Either (x < 0x1p-126 or inf or nan) or (y is 0 or inf or nan).\n if (ny) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3F800000) return NaN; // original: 1.0\n if ((ix << 1) > (0x7F800000 << 1) || (iy << 1) > (0x7F800000 << 1)) return x + y;\n if ((ix << 1) == (0x3F800000 << 1)) return NaN; // original: 1.0\n if (((ix << 1) < (0x3F800000 << 1)) == !(iy >> 31)) return 0; // |x| < 1 && y==inf or |x| > 1 && y==-inf.\n return y * y;\n }\n if (zeroinfnanf(ix)) {\n let x2 = x * x;\n if ((ix >> 31) && checkintf(iy) == 1) x2 = -x2;\n return iy < 0 ? 1 / x2 : x2;\n }\n // x and y are non-zero finite.\n if (ix < 0) {\n // Finite x < 0.\n let yint = checkintf(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) signBias = SIGN_BIAS;\n ix &= 0x7FFFFFFF;\n }\n if (ix < 0x00800000) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret(x * Ox1p23f);\n ix &= 0x7FFFFFFF;\n ix -= 23 << 23;\n }\n }\n var logx = log2f_inline(ix);\n var ylogx = y * logx; // cannot overflow, y is single prec.\n if ((reinterpret(ylogx) >> 47 & 0xFFFF) >= 0x80BF) { // reinterpret(126.0) >> 47\n // |y * log(x)| >= 126\n if (ylogx > UPPER_LIMIT) return oflowf(signBias); // overflow\n if (ylogx <= LOWER_LIMIT) return uflowf(signBias); // underflow\n }\n return exp2f_inline(ylogx, signBias);\n}\n\n//\n// Lookup data for exp. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp.c\n//\n\n// @ts-ignore: decorator\n@inline const EXP_TABLE_BITS = 7;\n\n// @ts-ignore: decorator\n@lazy @inline const EXP_DATA_TAB = memory.data([\n 0x0000000000000000, 0x3FF0000000000000,\n 0x3C9B3B4F1A88BF6E, 0x3FEFF63DA9FB3335,\n 0xBC7160139CD8DC5D, 0x3FEFEC9A3E778061,\n 0xBC905E7A108766D1, 0x3FEFE315E86E7F85,\n 0x3C8CD2523567F613, 0x3FEFD9B0D3158574,\n 0xBC8BCE8023F98EFA, 0x3FEFD06B29DDF6DE,\n 0x3C60F74E61E6C861, 0x3FEFC74518759BC8,\n 0x3C90A3E45B33D399, 0x3FEFBE3ECAC6F383,\n 0x3C979AA65D837B6D, 0x3FEFB5586CF9890F,\n 0x3C8EB51A92FDEFFC, 0x3FEFAC922B7247F7,\n 0x3C3EBE3D702F9CD1, 0x3FEFA3EC32D3D1A2,\n 0xBC6A033489906E0B, 0x3FEF9B66AFFED31B,\n 0xBC9556522A2FBD0E, 0x3FEF9301D0125B51,\n 0xBC5080EF8C4EEA55, 0x3FEF8ABDC06C31CC,\n 0xBC91C923B9D5F416, 0x3FEF829AAEA92DE0,\n 0x3C80D3E3E95C55AF, 0x3FEF7A98C8A58E51,\n 0xBC801B15EAA59348, 0x3FEF72B83C7D517B,\n 0xBC8F1FF055DE323D, 0x3FEF6AF9388C8DEA,\n 0x3C8B898C3F1353BF, 0x3FEF635BEB6FCB75,\n 0xBC96D99C7611EB26, 0x3FEF5BE084045CD4,\n 0x3C9AECF73E3A2F60, 0x3FEF54873168B9AA,\n 0xBC8FE782CB86389D, 0x3FEF4D5022FCD91D,\n 0x3C8A6F4144A6C38D, 0x3FEF463B88628CD6,\n 0x3C807A05B0E4047D, 0x3FEF3F49917DDC96,\n 0x3C968EFDE3A8A894, 0x3FEF387A6E756238,\n 0x3C875E18F274487D, 0x3FEF31CE4FB2A63F,\n 0x3C80472B981FE7F2, 0x3FEF2B4565E27CDD,\n 0xBC96B87B3F71085E, 0x3FEF24DFE1F56381,\n 0x3C82F7E16D09AB31, 0x3FEF1E9DF51FDEE1,\n 0xBC3D219B1A6FBFFA, 0x3FEF187FD0DAD990,\n 0x3C8B3782720C0AB4, 0x3FEF1285A6E4030B,\n 0x3C6E149289CECB8F, 0x3FEF0CAFA93E2F56,\n 0x3C834D754DB0ABB6, 0x3FEF06FE0A31B715,\n 0x3C864201E2AC744C, 0x3FEF0170FC4CD831,\n 0x3C8FDD395DD3F84A, 0x3FEEFC08B26416FF,\n 0xBC86A3803B8E5B04, 0x3FEEF6C55F929FF1,\n 0xBC924AEDCC4B5068, 0x3FEEF1A7373AA9CB,\n 0xBC9907F81B512D8E, 0x3FEEECAE6D05D866,\n 0xBC71D1E83E9436D2, 0x3FEEE7DB34E59FF7,\n 0xBC991919B3CE1B15, 0x3FEEE32DC313A8E5,\n 0x3C859F48A72A4C6D, 0x3FEEDEA64C123422,\n 0xBC9312607A28698A, 0x3FEEDA4504AC801C,\n 0xBC58A78F4817895B, 0x3FEED60A21F72E2A,\n 0xBC7C2C9B67499A1B, 0x3FEED1F5D950A897,\n 0x3C4363ED60C2AC11, 0x3FEECE086061892D,\n 0x3C9666093B0664EF, 0x3FEECA41ED1D0057,\n 0x3C6ECCE1DAA10379, 0x3FEEC6A2B5C13CD0,\n 0x3C93FF8E3F0F1230, 0x3FEEC32AF0D7D3DE,\n 0x3C7690CEBB7AAFB0, 0x3FEEBFDAD5362A27,\n 0x3C931DBDEB54E077, 0x3FEEBCB299FDDD0D,\n 0xBC8F94340071A38E, 0x3FEEB9B2769D2CA7,\n 0xBC87DECCDC93A349, 0x3FEEB6DAA2CF6642,\n 0xBC78DEC6BD0F385F, 0x3FEEB42B569D4F82,\n 0xBC861246EC7B5CF6, 0x3FEEB1A4CA5D920F,\n 0x3C93350518FDD78E, 0x3FEEAF4736B527DA,\n 0x3C7B98B72F8A9B05, 0x3FEEAD12D497C7FD,\n 0x3C9063E1E21C5409, 0x3FEEAB07DD485429,\n 0x3C34C7855019C6EA, 0x3FEEA9268A5946B7,\n 0x3C9432E62B64C035, 0x3FEEA76F15AD2148,\n 0xBC8CE44A6199769F, 0x3FEEA5E1B976DC09,\n 0xBC8C33C53BEF4DA8, 0x3FEEA47EB03A5585,\n 0xBC845378892BE9AE, 0x3FEEA34634CCC320,\n 0xBC93CEDD78565858, 0x3FEEA23882552225,\n 0x3C5710AA807E1964, 0x3FEEA155D44CA973,\n 0xBC93B3EFBF5E2228, 0x3FEEA09E667F3BCD,\n 0xBC6A12AD8734B982, 0x3FEEA012750BDABF,\n 0xBC6367EFB86DA9EE, 0x3FEE9FB23C651A2F,\n 0xBC80DC3D54E08851, 0x3FEE9F7DF9519484,\n 0xBC781F647E5A3ECF, 0x3FEE9F75E8EC5F74,\n 0xBC86EE4AC08B7DB0, 0x3FEE9F9A48A58174,\n 0xBC8619321E55E68A, 0x3FEE9FEB564267C9,\n 0x3C909CCB5E09D4D3, 0x3FEEA0694FDE5D3F,\n 0xBC7B32DCB94DA51D, 0x3FEEA11473EB0187,\n 0x3C94ECFD5467C06B, 0x3FEEA1ED0130C132,\n 0x3C65EBE1ABD66C55, 0x3FEEA2F336CF4E62,\n 0xBC88A1C52FB3CF42, 0x3FEEA427543E1A12,\n 0xBC9369B6F13B3734, 0x3FEEA589994CCE13,\n 0xBC805E843A19FF1E, 0x3FEEA71A4623C7AD,\n 0xBC94D450D872576E, 0x3FEEA8D99B4492ED,\n 0x3C90AD675B0E8A00, 0x3FEEAAC7D98A6699,\n 0x3C8DB72FC1F0EAB4, 0x3FEEACE5422AA0DB,\n 0xBC65B6609CC5E7FF, 0x3FEEAF3216B5448C,\n 0x3C7BF68359F35F44, 0x3FEEB1AE99157736,\n 0xBC93091FA71E3D83, 0x3FEEB45B0B91FFC6,\n 0xBC5DA9B88B6C1E29, 0x3FEEB737B0CDC5E5,\n 0xBC6C23F97C90B959, 0x3FEEBA44CBC8520F,\n 0xBC92434322F4F9AA, 0x3FEEBD829FDE4E50,\n 0xBC85CA6CD7668E4B, 0x3FEEC0F170CA07BA,\n 0x3C71AFFC2B91CE27, 0x3FEEC49182A3F090,\n 0x3C6DD235E10A73BB, 0x3FEEC86319E32323,\n 0xBC87C50422622263, 0x3FEECC667B5DE565,\n 0x3C8B1C86E3E231D5, 0x3FEED09BEC4A2D33,\n 0xBC91BBD1D3BCBB15, 0x3FEED503B23E255D,\n 0x3C90CC319CEE31D2, 0x3FEED99E1330B358,\n 0x3C8469846E735AB3, 0x3FEEDE6B5579FDBF,\n 0xBC82DFCD978E9DB4, 0x3FEEE36BBFD3F37A,\n 0x3C8C1A7792CB3387, 0x3FEEE89F995AD3AD,\n 0xBC907B8F4AD1D9FA, 0x3FEEEE07298DB666,\n 0xBC55C3D956DCAEBA, 0x3FEEF3A2B84F15FB,\n 0xBC90A40E3DA6F640, 0x3FEEF9728DE5593A,\n 0xBC68D6F438AD9334, 0x3FEEFF76F2FB5E47,\n 0xBC91EEE26B588A35, 0x3FEF05B030A1064A,\n 0x3C74FFD70A5FDDCD, 0x3FEF0C1E904BC1D2,\n 0xBC91BDFBFA9298AC, 0x3FEF12C25BD71E09,\n 0x3C736EAE30AF0CB3, 0x3FEF199BDD85529C,\n 0x3C8EE3325C9FFD94, 0x3FEF20AB5FFFD07A,\n 0x3C84E08FD10959AC, 0x3FEF27F12E57D14B,\n 0x3C63CDAF384E1A67, 0x3FEF2F6D9406E7B5,\n 0x3C676B2C6C921968, 0x3FEF3720DCEF9069,\n 0xBC808A1883CCB5D2, 0x3FEF3F0B555DC3FA,\n 0xBC8FAD5D3FFFFA6F, 0x3FEF472D4A07897C,\n 0xBC900DAE3875A949, 0x3FEF4F87080D89F2,\n 0x3C74A385A63D07A7, 0x3FEF5818DCFBA487,\n 0xBC82919E2040220F, 0x3FEF60E316C98398,\n 0x3C8E5A50D5C192AC, 0x3FEF69E603DB3285,\n 0x3C843A59AC016B4B, 0x3FEF7321F301B460,\n 0xBC82D52107B43E1F, 0x3FEF7C97337B9B5F,\n 0xBC892AB93B470DC9, 0x3FEF864614F5A129,\n 0x3C74B604603A88D3, 0x3FEF902EE78B3FF6,\n 0x3C83C5EC519D7271, 0x3FEF9A51FBC74C83,\n 0xBC8FF7128FD391F0, 0x3FEFA4AFA2A490DA,\n 0xBC8DAE98E223747D, 0x3FEFAF482D8E67F1,\n 0x3C8EC3BC41AA2008, 0x3FEFBA1BEE615A27,\n 0x3C842B94C3A9EB32, 0x3FEFC52B376BBA97,\n 0x3C8A64A931D185EE, 0x3FEFD0765B6E4540,\n 0xBC8E37BAE43BE3ED, 0x3FEFDBFDAD9CBE14,\n 0x3C77893B4D91CD9D, 0x3FEFE7C1819E90D8,\n 0x3C5305C14160CC89, 0x3FEFF3C22B8F71F1\n]);\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase(tmp: f64, sbits: u64, ki: u64): f64 {\n const\n Ox1p_1022 = reinterpret(0x0010000000000000), // 0x1p-1022\n Ox1p1009 = reinterpret(0x7F00000000000000); // 0x1p1009\n\n var scale: f64;\n if (!(ki & 0x80000000)) {\n // k > 0, the exponent of scale might have overflowed by <= 460.\n sbits -= u64(1009) << 52;\n scale = reinterpret(sbits);\n return Ox1p1009 * (scale + scale * tmp); // 0x1p1009\n }\n // k < 0, need special care in the subnormal range.\n sbits += u64(1022) << 52;\n // Note: sbits is signed scale.\n scale = reinterpret(sbits);\n var y = scale + scale * tmp;\n if (abs(y) < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let one = copysign(1.0, y);\n let lo = scale - y + scale * tmp;\n let hi = one + y;\n lo = one - hi + y + lo;\n y = (hi + lo) - one;\n // Fix the sign of 0.\n if (y == 0.0) y = reinterpret(sbits & 0x8000000000000000);\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret(0x4338000000000000); // 0x1.8p52;\n\n const\n C2 = reinterpret(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n var ux = reinterpret(x);\n var abstop = u32(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) {\n return 1.0 + x;\n } else {\n return select(0, Infinity, ux < 0);\n }\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]\n var z = InvLn2N * x;\n // #if TOINT_INTRINSICS\n // \tkd = roundtoint(z);\n // \tki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // \t// z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // var kd = z + shift;\n // var ki = reinterpret(kd) >> 16;\n // var kd = ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes.\n var kd = z + shift;\n var ki = reinterpret(kd);\n kd -= shift;\n // #endif\n var r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // 2^(k/N) ~= scale * (1 + tail).\n var idx = usize((ki & N_MASK) << 1);\n var top = ki << (52 - EXP_TABLE_BITS);\n\n var tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()))); // T[idx]\n // This is only a valid scale when -1023*N < k < 1024*N\n var sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top; // T[idx + 1]\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n var r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp.\n var tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n var scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n//\n// Lookup data for exp2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp2.c\n//\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase2(tmp: f64, sbits: u64, ki: u64): f64 {\n const Ox1p_1022 = reinterpret(0x10000000000000); // 0x1p-1022\n var scale: f64;\n if ((ki & 0x80000000) == 0) {\n // k > 0, the exponent of scale might have overflowed by 1\n sbits -= u64(1) << 52;\n scale = reinterpret(sbits);\n return 2 * (scale * tmp + scale);\n }\n // k < 0, need special care in the subnormal range\n sbits += u64(1022) << 52;\n scale = reinterpret(sbits);\n var y = scale * tmp + scale;\n if (y < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let hi: f64, lo: f64;\n lo = scale - y + scale * tmp;\n hi = 1.0 + y;\n lo = 1.0 - hi + y + lo;\n y = (hi + lo) - 1.0;\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp2_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N; // 0x1.8p52\n\n const\n C1 = reinterpret(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1\n C2 = reinterpret(0x3FCEBFBDFF82C424), // 0x1.ebfbdff82c424p-3\n C3 = reinterpret(0x3FAC6B08D70CF4B5), // 0x1.c6b08d70cf4b5p-5\n C4 = reinterpret(0x3F83B2ABD24650CC), // 0x1.3b2abd24650ccp-7\n C5 = reinterpret(0x3F55D7E09B4E3A84); // 0x1.5d7e09b4e3a84p-10\n\n var ux = reinterpret(x);\n var abstop = u32(ux >> 52) & 0x7ff;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1.0;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) return 1.0 + x;\n if (ux >= 0) return Infinity;\n else if (ux >= 0xC090CC0000000000) return 0;\n }\n if ((ux << 1) > 0x811A000000000000) abstop = 0; // Large x is special cased below.\n }\n\n // exp2(x) = 2^(k/N) * 2^r, with 2^r in [2^(-1/2N),2^(1/2N)].\n // x = k/N + r, with int k and r in [-1/2N, 1/2N]\n var kd = x + shift;\n var ki = reinterpret(kd);\n kd -= shift; // k/N for int k\n var r = x - kd;\n // 2^(k/N) ~= scale * (1 + tail)\n var idx = usize((ki & N_MASK) << 1);\n var top = ki << (52 - EXP_TABLE_BITS);\n\n var tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()), 0 << alignof())); // T[idx])\n // This is only a valid scale when -1023*N < k < 1024*N\n var sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top; // T[idx + 1]\n // exp2(x) = 2^(k/N) * 2^r ~= scale + scale * (tail + 2^r - 1).\n // Evaluation is optimized assuming superscalar pipelined execution\n var r2 = r * r;\n // Without fma the worst case error is 0.5/N ulp larger.\n // Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp.\n var tmp = tail + r * C1 + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase2(tmp, sbits, ki);\n var scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-928, so there\n // is no spurious underflow here even without fma.\n return scale * tmp + scale;\n}\n\n//\n// Lookup data for log2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c\n//\n\n// @ts-ignore: decorator\n@inline const LOG2_TABLE_BITS = 6;\n\n/* Algorithm:\n\n x = 2^k z\n log2(x) = k + log2(c) + log2(z/c)\n log2(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log2(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p10 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-64 and\n 3) the rounding error in (double)log2(c) is minimized (< 0x1p-68).\n\nNote: 1) ensures that k + logc can be computed without rounding error, 2)\nensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to a\nsingle rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log2(x)| < 0x1p-4, this is not enough so that is special cased. */\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2_DATA_TAB1 = memory.data([\n // invc , logc\n reinterpret(0x3FF724286BB1ACF8), reinterpret(0xBFE1095FEECDB000),\n reinterpret(0x3FF6E1F766D2CCA1), reinterpret(0xBFE08494BD76D000),\n reinterpret(0x3FF6A13D0E30D48A), reinterpret(0xBFE00143AEE8F800),\n reinterpret(0x3FF661EC32D06C85), reinterpret(0xBFDEFEC5360B4000),\n reinterpret(0x3FF623FA951198F8), reinterpret(0xBFDDFDD91AB7E000),\n reinterpret(0x3FF5E75BA4CF026C), reinterpret(0xBFDCFFAE0CC79000),\n reinterpret(0x3FF5AC055A214FB8), reinterpret(0xBFDC043811FDA000),\n reinterpret(0x3FF571ED0F166E1E), reinterpret(0xBFDB0B67323AE000),\n reinterpret(0x3FF53909590BF835), reinterpret(0xBFDA152F5A2DB000),\n reinterpret(0x3FF5014FED61ADDD), reinterpret(0xBFD9217F5AF86000),\n reinterpret(0x3FF4CAB88E487BD0), reinterpret(0xBFD8304DB0719000),\n reinterpret(0x3FF49539B4334FEE), reinterpret(0xBFD74189F9A9E000),\n reinterpret(0x3FF460CBDFAFD569), reinterpret(0xBFD6552BB5199000),\n reinterpret(0x3FF42D664EE4B953), reinterpret(0xBFD56B23A29B1000),\n reinterpret(0x3FF3FB01111DD8A6), reinterpret(0xBFD483650F5FA000),\n reinterpret(0x3FF3C995B70C5836), reinterpret(0xBFD39DE937F6A000),\n reinterpret(0x3FF3991C4AB6FD4A), reinterpret(0xBFD2BAA1538D6000),\n reinterpret(0x3FF3698E0CE099B5), reinterpret(0xBFD1D98340CA4000),\n reinterpret(0x3FF33AE48213E7B2), reinterpret(0xBFD0FA853A40E000),\n reinterpret(0x3FF30D191985BDB1), reinterpret(0xBFD01D9C32E73000),\n reinterpret(0x3FF2E025CAB271D7), reinterpret(0xBFCE857DA2FA6000),\n reinterpret(0x3FF2B404CF13CD82), reinterpret(0xBFCCD3C8633D8000),\n reinterpret(0x3FF288B02C7CCB50), reinterpret(0xBFCB26034C14A000),\n reinterpret(0x3FF25E2263944DE5), reinterpret(0xBFC97C1C2F4FE000),\n reinterpret(0x3FF234563D8615B1), reinterpret(0xBFC7D6023F800000),\n reinterpret(0x3FF20B46E33EAF38), reinterpret(0xBFC633A71A05E000),\n reinterpret(0x3FF1E2EEFDCDA3DD), reinterpret(0xBFC494F5E9570000),\n reinterpret(0x3FF1BB4A580B3930), reinterpret(0xBFC2F9E424E0A000),\n reinterpret(0x3FF19453847F2200), reinterpret(0xBFC162595AFDC000),\n reinterpret(0x3FF16E06C0D5D73C), reinterpret(0xBFBF9C9A75BD8000),\n reinterpret(0x3FF1485F47B7E4C2), reinterpret(0xBFBC7B575BF9C000),\n reinterpret(0x3FF12358AD0085D1), reinterpret(0xBFB960C60FF48000),\n reinterpret(0x3FF0FEF00F532227), reinterpret(0xBFB64CE247B60000),\n reinterpret(0x3FF0DB2077D03A8F), reinterpret(0xBFB33F78B2014000),\n reinterpret(0x3FF0B7E6D65980D9), reinterpret(0xBFB0387D1A42C000),\n reinterpret(0x3FF0953EFE7B408D), reinterpret(0xBFAA6F9208B50000),\n reinterpret(0x3FF07325CAC53B83), reinterpret(0xBFA47A954F770000),\n reinterpret(0x3FF05197E40D1B5C), reinterpret(0xBF9D23A8C50C0000),\n reinterpret(0x3FF03091C1208EA2), reinterpret(0xBF916A2629780000),\n reinterpret(0x3FF0101025B37E21), reinterpret(0xBF7720F8D8E80000),\n reinterpret(0x3FEFC07EF9CAA76B), reinterpret(0x3F86FE53B1500000),\n reinterpret(0x3FEF4465D3F6F184), reinterpret(0x3FA11CCCE10F8000),\n reinterpret(0x3FEECC079F84107F), reinterpret(0x3FAC4DFC8C8B8000),\n reinterpret(0x3FEE573A99975AE8), reinterpret(0x3FB3AA321E574000),\n reinterpret(0x3FEDE5D6F0BD3DE6), reinterpret(0x3FB918A0D08B8000),\n reinterpret(0x3FED77B681FF38B3), reinterpret(0x3FBE72E9DA044000),\n reinterpret(0x3FED0CB5724DE943), reinterpret(0x3FC1DCD2507F6000),\n reinterpret(0x3FECA4B2DC0E7563), reinterpret(0x3FC476AB03DEA000),\n reinterpret(0x3FEC3F8EE8D6CB51), reinterpret(0x3FC7074377E22000),\n reinterpret(0x3FEBDD2B4F020C4C), reinterpret(0x3FC98EDE8BA94000),\n reinterpret(0x3FEB7D6C006015CA), reinterpret(0x3FCC0DB86AD2E000),\n reinterpret(0x3FEB20366E2E338F), reinterpret(0x3FCE840AAFCEE000),\n reinterpret(0x3FEAC57026295039), reinterpret(0x3FD0790AB4678000),\n reinterpret(0x3FEA6D01BC2731DD), reinterpret(0x3FD1AC056801C000),\n reinterpret(0x3FEA16D3BC3FF18B), reinterpret(0x3FD2DB11D4FEE000),\n reinterpret(0x3FE9C2D14967FEAD), reinterpret(0x3FD406464EC58000),\n reinterpret(0x3FE970E4F47C9902), reinterpret(0x3FD52DBE093AF000),\n reinterpret(0x3FE920FB3982BCF2), reinterpret(0x3FD651902050D000),\n reinterpret(0x3FE8D30187F759F1), reinterpret(0x3FD771D2CDEAF000),\n reinterpret(0x3FE886E5EBB9F66D), reinterpret(0x3FD88E9C857D9000),\n reinterpret(0x3FE83C97B658B994), reinterpret(0x3FD9A80155E16000),\n reinterpret(0x3FE7F405FFC61022), reinterpret(0x3FDABE186ED3D000),\n reinterpret(0x3FE7AD22181415CA), reinterpret(0x3FDBD0F2AEA0E000),\n reinterpret(0x3FE767DCF99EFF8C), reinterpret(0x3FDCE0A43DBF4000)\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2_DATA_TAB2 = memory.data([\n // chi , clo\n reinterpret(0x3FE6200012B90A8E), reinterpret(0x3C8904AB0644B605),\n reinterpret(0x3FE66000045734A6), reinterpret(0x3C61FF9BEA62F7A9),\n reinterpret(0x3FE69FFFC325F2C5), reinterpret(0x3C827ECFCB3C90BA),\n reinterpret(0x3FE6E00038B95A04), reinterpret(0x3C88FF8856739326),\n reinterpret(0x3FE71FFFE09994E3), reinterpret(0x3C8AFD40275F82B1),\n reinterpret(0x3FE7600015590E10), reinterpret(0xBC72FD75B4238341),\n reinterpret(0x3FE7A00012655BD5), reinterpret(0x3C7808E67C242B76),\n reinterpret(0x3FE7E0003259E9A6), reinterpret(0xBC6208E426F622B7),\n reinterpret(0x3FE81FFFEDB4B2D2), reinterpret(0xBC8402461EA5C92F),\n reinterpret(0x3FE860002DFAFCC3), reinterpret(0x3C6DF7F4A2F29A1F),\n reinterpret(0x3FE89FFFF78C6B50), reinterpret(0xBC8E0453094995FD),\n reinterpret(0x3FE8E00039671566), reinterpret(0xBC8A04F3BEC77B45),\n reinterpret(0x3FE91FFFE2BF1745), reinterpret(0xBC77FA34400E203C),\n reinterpret(0x3FE95FFFCC5C9FD1), reinterpret(0xBC76FF8005A0695D),\n reinterpret(0x3FE9A0003BBA4767), reinterpret(0x3C70F8C4C4EC7E03),\n reinterpret(0x3FE9DFFFE7B92DA5), reinterpret(0x3C8E7FD9478C4602),\n reinterpret(0x3FEA1FFFD72EFDAF), reinterpret(0xBC6A0C554DCDAE7E),\n reinterpret(0x3FEA5FFFDE04FF95), reinterpret(0x3C867DA98CE9B26B),\n reinterpret(0x3FEA9FFFCA5E8D2B), reinterpret(0xBC8284C9B54C13DE),\n reinterpret(0x3FEADFFFDDAD03EA), reinterpret(0x3C5812C8EA602E3C),\n reinterpret(0x3FEB1FFFF10D3D4D), reinterpret(0xBC8EFADDAD27789C),\n reinterpret(0x3FEB5FFFCE21165A), reinterpret(0x3C53CB1719C61237),\n reinterpret(0x3FEB9FFFD950E674), reinterpret(0x3C73F7D94194CE00),\n reinterpret(0x3FEBE000139CA8AF), reinterpret(0x3C750AC4215D9BC0),\n reinterpret(0x3FEC20005B46DF99), reinterpret(0x3C6BEEA653E9C1C9),\n reinterpret(0x3FEC600040B9F7AE), reinterpret(0xBC7C079F274A70D6),\n reinterpret(0x3FECA0006255FD8A), reinterpret(0xBC7A0B4076E84C1F),\n reinterpret(0x3FECDFFFD94C095D), reinterpret(0x3C88F933F99AB5D7),\n reinterpret(0x3FED1FFFF975D6CF), reinterpret(0xBC582C08665FE1BE),\n reinterpret(0x3FED5FFFA2561C93), reinterpret(0xBC7B04289BD295F3),\n reinterpret(0x3FED9FFF9D228B0C), reinterpret(0x3C870251340FA236),\n reinterpret(0x3FEDE00065BC7E16), reinterpret(0xBC75011E16A4D80C),\n reinterpret(0x3FEE200002F64791), reinterpret(0x3C89802F09EF62E0),\n reinterpret(0x3FEE600057D7A6D8), reinterpret(0xBC7E0B75580CF7FA),\n reinterpret(0x3FEEA00027EDC00C), reinterpret(0xBC8C848309459811),\n reinterpret(0x3FEEE0006CF5CB7C), reinterpret(0xBC8F8027951576F4),\n reinterpret(0x3FEF2000782B7DCC), reinterpret(0xBC8F81D97274538F),\n reinterpret(0x3FEF6000260C450A), reinterpret(0xBC4071002727FFDC),\n reinterpret(0x3FEF9FFFE88CD533), reinterpret(0xBC581BDCE1FDA8B0),\n reinterpret(0x3FEFDFFFD50F8689), reinterpret(0x3C87F91ACB918E6E),\n reinterpret(0x3FF0200004292367), reinterpret(0x3C9B7FF365324681),\n reinterpret(0x3FF05FFFE3E3D668), reinterpret(0x3C86FA08DDAE957B),\n reinterpret(0x3FF0A0000A85A757), reinterpret(0xBC57E2DE80D3FB91),\n reinterpret(0x3FF0E0001A5F3FCC), reinterpret(0xBC91823305C5F014),\n reinterpret(0x3FF11FFFF8AFBAF5), reinterpret(0xBC8BFABB6680BAC2),\n reinterpret(0x3FF15FFFE54D91AD), reinterpret(0xBC9D7F121737E7EF),\n reinterpret(0x3FF1A00011AC36E1), reinterpret(0x3C9C000A0516F5FF),\n reinterpret(0x3FF1E00019C84248), reinterpret(0xBC9082FBE4DA5DA0),\n reinterpret(0x3FF220000FFE5E6E), reinterpret(0xBC88FDD04C9CFB43),\n reinterpret(0x3FF26000269FD891), reinterpret(0x3C8CFE2A7994D182),\n reinterpret(0x3FF2A00029A6E6DA), reinterpret(0xBC700273715E8BC5),\n reinterpret(0x3FF2DFFFE0293E39), reinterpret(0x3C9B7C39DAB2A6F9),\n reinterpret(0x3FF31FFFF7DCF082), reinterpret(0x3C7DF1336EDC5254),\n reinterpret(0x3FF35FFFF05A8B60), reinterpret(0xBC9E03564CCD31EB),\n reinterpret(0x3FF3A0002E0EAECC), reinterpret(0x3C75F0E74BD3A477),\n reinterpret(0x3FF3E000043BB236), reinterpret(0x3C9C7DCB149D8833),\n reinterpret(0x3FF4200002D187FF), reinterpret(0x3C7E08AFCF2D3D28),\n reinterpret(0x3FF460000D387CB1), reinterpret(0x3C820837856599A6),\n reinterpret(0x3FF4A00004569F89), reinterpret(0xBC89FA5C904FBCD2),\n reinterpret(0x3FF4E000043543F3), reinterpret(0xBC781125ED175329),\n reinterpret(0x3FF51FFFCC027F0F), reinterpret(0x3C9883D8847754DC),\n reinterpret(0x3FF55FFFFD87B36F), reinterpret(0xBC8709E731D02807),\n reinterpret(0x3FF59FFFF21DF7BA), reinterpret(0x3C87F79F68727B02),\n reinterpret(0x3FF5DFFFEBFC3481), reinterpret(0xBC9180902E30E93E)\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function log2_lut(x: f64): f64 {\n const N_MASK = (1 << LOG2_TABLE_BITS) - 1;\n\n const\n LO: u64 = 0x3FEEA4AF00000000, // reinterpret(1.0 - 0x1.5b51p-5)\n HI: u64 = 0x3FF0B55900000000; // reinterpret(1.0 + 0x1.6ab2p-5)\n\n const\n InvLn2hi = reinterpret(0x3FF7154765200000), // 0x1.7154765200000p+0\n InvLn2lo = reinterpret(0x3DE705FC2EEFA200), // 0x1.705fc2eefa200p-33\n Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n const\n B0 = reinterpret(0xBFE71547652B82FE), // -0x1.71547652b82fep-1\n B1 = reinterpret(0x3FDEC709DC3A03F7), // 0x1.ec709dc3a03f7p-2\n B2 = reinterpret(0xBFD71547652B7C3F), // -0x1.71547652b7c3fp-2\n B3 = reinterpret(0x3FD2776C50F05BE4), // 0x1.2776c50f05be4p-2\n B4 = reinterpret(0xBFCEC709DD768FE5), // -0x1.ec709dd768fe5p-3\n B5 = reinterpret(0x3FCA61761EC4E736), // 0x1.a61761ec4e736p-3\n B6 = reinterpret(0xBFC7153FBC64A79B), // -0x1.7153fbc64a79bp-3\n B7 = reinterpret(0x3FC484D154F01B4A), // 0x1.484d154f01b4ap-3\n B8 = reinterpret(0xBFC289E4A72C383C), // -0x1.289e4a72c383cp-3\n B9 = reinterpret(0x3FC0B32F285AEE66); // 0x1.0b32f285aee66p-3\n\n const\n A0 = reinterpret(0xBFE71547652B8339), // -0x1.71547652b8339p-1\n A1 = reinterpret(0x3FDEC709DC3A04BE), // 0x1.ec709dc3a04bep-2\n A2 = reinterpret(0xBFD7154764702FFB), // -0x1.7154764702ffbp-2\n A3 = reinterpret(0x3FD2776C50034C48), // 0x1.2776c50034c48p-2\n A4 = reinterpret(0xBFCEC7B328EA92BC), // -0x1.ec7b328ea92bcp-3\n A5 = reinterpret(0x3FCA6225E117F92E); // 0x1.a6225e117f92ep-3\n\n var ix = reinterpret(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n // #if __FP_FAST_FMA\n // hi = r * InvLn2hi;\n // lo = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -hi);\n // #else\n let rhi = reinterpret(reinterpret(r) & 0xFFFFFFFF00000000);\n let rlo = r - rhi;\n let hi = rhi * InvLn2hi;\n let lo = rlo * InvLn2hi + r * InvLn2lo;\n // #endif\n let r2 = r * r; // rounding error: 0x1p-62\n let r4 = r2 * r2;\n // Worst-case error is less than 0.54 ULP (0.55 ULP without fma)\n let p = r2 * (B0 + r * B1);\n let y = hi + p;\n lo += hi - y + p;\n lo += r4 * (B2 + r * B3 + r2 * (B4 + r * B5) +\n r4 * (B6 + r * B7 + r2 * (B8 + r * B9)));\n return y + lo;\n }\n var top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7ff0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan.\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == 0x7FF0000000000000) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ix = reinterpret(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3FE6000000000000;\n var i = ((tmp >> (52 - LOG2_TABLE_BITS)) & N_MASK);\n var k = tmp >> 52;\n var iz = ix - (tmp & 0xFFF0000000000000);\n\n var invc = load(LOG2_DATA_TAB1 + (i << (1 + alignof())), 0 << alignof()); // T[i].invc;\n var logc = load(LOG2_DATA_TAB1 + (i << (1 + alignof())), 1 << alignof()); // T[i].logc;\n var z = reinterpret(iz);\n var kd = k;\n\n // log2(x) = log2(z/c) + log2(c) + k.\n // r ~= z/c - 1, |r| < 1/(2*N).\n // #if __FP_FAST_FMA\n // \t// rounding error: 0x1p-55/N.\n // \tr = __builtin_fma(z, invc, -1.0);\n // \tt1 = r * InvLn2hi;\n // \tt2 = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -t1);\n // #else\n // rounding error: 0x1p-55/N + 0x1p-65.\n var chi = load(LOG2_DATA_TAB2 + (i << (1 + alignof())), 0 << alignof()); // T[i].chi;\n var clo = load(LOG2_DATA_TAB2 + (i << (1 + alignof())), 1 << alignof()); // T[i].clo;\n\n var r = (z - chi - clo) * invc;\n var rhi = reinterpret(reinterpret(r) & 0xFFFFFFFF00000000);\n var rlo = r - rhi;\n var t1 = rhi * InvLn2hi;\n var t2 = rlo * InvLn2hi + r * InvLn2lo;\n // #endif\n\n // hi + lo = r/ln2 + log2(c) + k\n var t3 = kd + logc;\n var hi = t3 + t1;\n var lo = t3 - hi + t1 + t2;\n\n // log2(r+1) = r/ln2 + r^2*poly(r)\n // Evaluation is optimized assuming superscalar pipelined execution\n var r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma).\n // ~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma).\n var p = A0 + r * A1 + r2 * (A2 + r * A3) + (r2 * r2) * (A4 + r * A5);\n return lo + r2 * p + hi;\n}\n\n//\n// Lookup data for log. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log.c\n//\n\n// @ts-ignore: decorator\n@inline const LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p9 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-66 and\n 3) the rounding error in (double)log(c) is minimized (< 0x1p-66).\n\nNote: 1) ensures that k*ln2hi + logc can be computed without rounding error,\n2) ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to\na single rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log(x)| < 0x1p-4, this is not enough so that is special cased.*/\n\n// @ts-ignore: decorator\n@lazy @inline const LOG_DATA_TAB1 = memory.data([\n // invc , logc\n reinterpret(0x3FF734F0C3E0DE9F), reinterpret(0xBFD7CC7F79E69000),\n reinterpret(0x3FF713786A2CE91F), reinterpret(0xBFD76FEEC20D0000),\n reinterpret(0x3FF6F26008FAB5A0), reinterpret(0xBFD713E31351E000),\n reinterpret(0x3FF6D1A61F138C7D), reinterpret(0xBFD6B85B38287800),\n reinterpret(0x3FF6B1490BC5B4D1), reinterpret(0xBFD65D5590807800),\n reinterpret(0x3FF69147332F0CBA), reinterpret(0xBFD602D076180000),\n reinterpret(0x3FF6719F18224223), reinterpret(0xBFD5A8CA86909000),\n reinterpret(0x3FF6524F99A51ED9), reinterpret(0xBFD54F4356035000),\n reinterpret(0x3FF63356AA8F24C4), reinterpret(0xBFD4F637C36B4000),\n reinterpret(0x3FF614B36B9DDC14), reinterpret(0xBFD49DA7FDA85000),\n reinterpret(0x3FF5F66452C65C4C), reinterpret(0xBFD445923989A800),\n reinterpret(0x3FF5D867B5912C4F), reinterpret(0xBFD3EDF439B0B800),\n reinterpret(0x3FF5BABCCB5B90DE), reinterpret(0xBFD396CE448F7000),\n reinterpret(0x3FF59D61F2D91A78), reinterpret(0xBFD3401E17BDA000),\n reinterpret(0x3FF5805612465687), reinterpret(0xBFD2E9E2EF468000),\n reinterpret(0x3FF56397CEE76BD3), reinterpret(0xBFD2941B3830E000),\n reinterpret(0x3FF54725E2A77F93), reinterpret(0xBFD23EC58CDA8800),\n reinterpret(0x3FF52AFF42064583), reinterpret(0xBFD1E9E129279000),\n reinterpret(0x3FF50F22DBB2BDDF), reinterpret(0xBFD1956D2B48F800),\n reinterpret(0x3FF4F38F4734DED7), reinterpret(0xBFD141679AB9F800),\n reinterpret(0x3FF4D843CFDE2840), reinterpret(0xBFD0EDD094EF9800),\n reinterpret(0x3FF4BD3EC078A3C8), reinterpret(0xBFD09AA518DB1000),\n reinterpret(0x3FF4A27FC3E0258A), reinterpret(0xBFD047E65263B800),\n reinterpret(0x3FF4880524D48434), reinterpret(0xBFCFEB224586F000),\n reinterpret(0x3FF46DCE1B192D0B), reinterpret(0xBFCF474A7517B000),\n reinterpret(0x3FF453D9D3391854), reinterpret(0xBFCEA4443D103000),\n reinterpret(0x3FF43A2744B4845A), reinterpret(0xBFCE020D44E9B000),\n reinterpret(0x3FF420B54115F8FB), reinterpret(0xBFCD60A22977F000),\n reinterpret(0x3FF40782DA3EF4B1), reinterpret(0xBFCCC00104959000),\n reinterpret(0x3FF3EE8F5D57FE8F), reinterpret(0xBFCC202956891000),\n reinterpret(0x3FF3D5D9A00B4CE9), reinterpret(0xBFCB81178D811000),\n reinterpret(0x3FF3BD60C010C12B), reinterpret(0xBFCAE2C9CCD3D000),\n reinterpret(0x3FF3A5242B75DAB8), reinterpret(0xBFCA45402E129000),\n reinterpret(0x3FF38D22CD9FD002), reinterpret(0xBFC9A877681DF000),\n reinterpret(0x3FF3755BC5847A1C), reinterpret(0xBFC90C6D69483000),\n reinterpret(0x3FF35DCE49AD36E2), reinterpret(0xBFC87120A645C000),\n reinterpret(0x3FF34679984DD440), reinterpret(0xBFC7D68FB4143000),\n reinterpret(0x3FF32F5CCEFFCB24), reinterpret(0xBFC73CB83C627000),\n reinterpret(0x3FF3187775A10D49), reinterpret(0xBFC6A39A9B376000),\n reinterpret(0x3FF301C8373E3990), reinterpret(0xBFC60B3154B7A000),\n reinterpret(0x3FF2EB4EBB95F841), reinterpret(0xBFC5737D76243000),\n reinterpret(0x3FF2D50A0219A9D1), reinterpret(0xBFC4DC7B8FC23000),\n reinterpret(0x3FF2BEF9A8B7FD2A), reinterpret(0xBFC4462C51D20000),\n reinterpret(0x3FF2A91C7A0C1BAB), reinterpret(0xBFC3B08ABC830000),\n reinterpret(0x3FF293726014B530), reinterpret(0xBFC31B996B490000),\n reinterpret(0x3FF27DFA5757A1F5), reinterpret(0xBFC2875490A44000),\n reinterpret(0x3FF268B39B1D3BBF), reinterpret(0xBFC1F3B9F879A000),\n reinterpret(0x3FF2539D838FF5BD), reinterpret(0xBFC160C8252CA000),\n reinterpret(0x3FF23EB7AAC9083B), reinterpret(0xBFC0CE7F57F72000),\n reinterpret(0x3FF22A012BA940B6), reinterpret(0xBFC03CDC49FEA000),\n reinterpret(0x3FF2157996CC4132), reinterpret(0xBFBF57BDBC4B8000),\n reinterpret(0x3FF201201DD2FC9B), reinterpret(0xBFBE370896404000),\n reinterpret(0x3FF1ECF4494D480B), reinterpret(0xBFBD17983EF94000),\n reinterpret(0x3FF1D8F5528F6569), reinterpret(0xBFBBF9674ED8A000),\n reinterpret(0x3FF1C52311577E7C), reinterpret(0xBFBADC79202F6000),\n reinterpret(0x3FF1B17C74CB26E9), reinterpret(0xBFB9C0C3E7288000),\n reinterpret(0x3FF19E010C2C1AB6), reinterpret(0xBFB8A646B372C000),\n reinterpret(0x3FF18AB07BB670BD), reinterpret(0xBFB78D01B3AC0000),\n reinterpret(0x3FF1778A25EFBCB6), reinterpret(0xBFB674F145380000),\n reinterpret(0x3FF1648D354C31DA), reinterpret(0xBFB55E0E6D878000),\n reinterpret(0x3FF151B990275FDD), reinterpret(0xBFB4485CDEA1E000),\n reinterpret(0x3FF13F0EA432D24C), reinterpret(0xBFB333D94D6AA000),\n reinterpret(0x3FF12C8B7210F9DA), reinterpret(0xBFB22079F8C56000),\n reinterpret(0x3FF11A3028ECB531), reinterpret(0xBFB10E4698622000),\n reinterpret(0x3FF107FBDA8434AF), reinterpret(0xBFAFFA6C6AD20000),\n reinterpret(0x3FF0F5EE0F4E6BB3), reinterpret(0xBFADDA8D4A774000),\n reinterpret(0x3FF0E4065D2A9FCE), reinterpret(0xBFABBCECE4850000),\n reinterpret(0x3FF0D244632CA521), reinterpret(0xBFA9A1894012C000),\n reinterpret(0x3FF0C0A77CE2981A), reinterpret(0xBFA788583302C000),\n reinterpret(0x3FF0AF2F83C636D1), reinterpret(0xBFA5715E67D68000),\n reinterpret(0x3FF09DDB98A01339), reinterpret(0xBFA35C8A49658000),\n reinterpret(0x3FF08CABAF52E7DF), reinterpret(0xBFA149E364154000),\n reinterpret(0x3FF07B9F2F4E28FB), reinterpret(0xBF9E72C082EB8000),\n reinterpret(0x3FF06AB58C358F19), reinterpret(0xBF9A55F152528000),\n reinterpret(0x3FF059EEA5ECF92C), reinterpret(0xBF963D62CF818000),\n reinterpret(0x3FF04949CDD12C90), reinterpret(0xBF9228FB8CAA0000),\n reinterpret(0x3FF038C6C6F0ADA9), reinterpret(0xBF8C317B20F90000),\n reinterpret(0x3FF02865137932A9), reinterpret(0xBF8419355DAA0000),\n reinterpret(0x3FF0182427EA7348), reinterpret(0xBF781203C2EC0000),\n reinterpret(0x3FF008040614B195), reinterpret(0xBF60040979240000),\n reinterpret(0x3FEFE01FF726FA1A), reinterpret(0x3F6FEFF384900000),\n reinterpret(0x3FEFA11CC261EA74), reinterpret(0x3F87DC41353D0000),\n reinterpret(0x3FEF6310B081992E), reinterpret(0x3F93CEA3C4C28000),\n reinterpret(0x3FEF25F63CEEADCD), reinterpret(0x3F9B9FC114890000),\n reinterpret(0x3FEEE9C8039113E7), reinterpret(0x3FA1B0D8CE110000),\n reinterpret(0x3FEEAE8078CBB1AB), reinterpret(0x3FA58A5BD001C000),\n reinterpret(0x3FEE741AA29D0C9B), reinterpret(0x3FA95C8340D88000),\n reinterpret(0x3FEE3A91830A99B5), reinterpret(0x3FAD276AEF578000),\n reinterpret(0x3FEE01E009609A56), reinterpret(0x3FB07598E598C000),\n reinterpret(0x3FEDCA01E577BB98), reinterpret(0x3FB253F5E30D2000),\n reinterpret(0x3FED92F20B7C9103), reinterpret(0x3FB42EDD8B380000),\n reinterpret(0x3FED5CAC66FB5CCE), reinterpret(0x3FB606598757C000),\n reinterpret(0x3FED272CAA5EDE9D), reinterpret(0x3FB7DA76356A0000),\n reinterpret(0x3FECF26E3E6B2CCD), reinterpret(0x3FB9AB434E1C6000),\n reinterpret(0x3FECBE6DA2A77902), reinterpret(0x3FBB78C7BB0D6000),\n reinterpret(0x3FEC8B266D37086D), reinterpret(0x3FBD431332E72000),\n reinterpret(0x3FEC5894BD5D5804), reinterpret(0x3FBF0A3171DE6000),\n reinterpret(0x3FEC26B533BB9F8C), reinterpret(0x3FC067152B914000),\n reinterpret(0x3FEBF583EEECE73F), reinterpret(0x3FC147858292B000),\n reinterpret(0x3FEBC4FD75DB96C1), reinterpret(0x3FC2266ECDCA3000),\n reinterpret(0x3FEB951E0C864A28), reinterpret(0x3FC303D7A6C55000),\n reinterpret(0x3FEB65E2C5EF3E2C), reinterpret(0x3FC3DFC33C331000),\n reinterpret(0x3FEB374867C9888B), reinterpret(0x3FC4BA366B7A8000),\n reinterpret(0x3FEB094B211D304A), reinterpret(0x3FC5933928D1F000),\n reinterpret(0x3FEADBE885F2EF7E), reinterpret(0x3FC66ACD2418F000),\n reinterpret(0x3FEAAF1D31603DA2), reinterpret(0x3FC740F8EC669000),\n reinterpret(0x3FEA82E63FD358A7), reinterpret(0x3FC815C0F51AF000),\n reinterpret(0x3FEA5740EF09738B), reinterpret(0x3FC8E92954F68000),\n reinterpret(0x3FEA2C2A90AB4B27), reinterpret(0x3FC9BB3602F84000),\n reinterpret(0x3FEA01A01393F2D1), reinterpret(0x3FCA8BED1C2C0000),\n reinterpret(0x3FE9D79F24DB3C1B), reinterpret(0x3FCB5B515C01D000),\n reinterpret(0x3FE9AE2505C7B190), reinterpret(0x3FCC2967CCBCC000),\n reinterpret(0x3FE9852EF297CE2F), reinterpret(0x3FCCF635D5486000),\n reinterpret(0x3FE95CBAEEA44B75), reinterpret(0x3FCDC1BD3446C000),\n reinterpret(0x3FE934C69DE74838), reinterpret(0x3FCE8C01B8CFE000),\n reinterpret(0x3FE90D4F2F6752E6), reinterpret(0x3FCF5509C0179000),\n reinterpret(0x3FE8E6528EFFD79D), reinterpret(0x3FD00E6C121FB800),\n reinterpret(0x3FE8BFCE9FCC007C), reinterpret(0x3FD071B80E93D000),\n reinterpret(0x3FE899C0DABEC30E), reinterpret(0x3FD0D46B9E867000),\n reinterpret(0x3FE87427AA2317FB), reinterpret(0x3FD13687334BD000),\n reinterpret(0x3FE84F00ACB39A08), reinterpret(0x3FD1980D67234800),\n reinterpret(0x3FE82A49E8653E55), reinterpret(0x3FD1F8FFE0CC8000),\n reinterpret(0x3FE8060195F40260), reinterpret(0x3FD2595FD7636800),\n reinterpret(0x3FE7E22563E0A329), reinterpret(0x3FD2B9300914A800),\n reinterpret(0x3FE7BEB377DCB5AD), reinterpret(0x3FD3187210436000),\n reinterpret(0x3FE79BAA679725C2), reinterpret(0x3FD377266DEC1800),\n reinterpret(0x3FE77907F2170657), reinterpret(0x3FD3D54FFBAF3000),\n reinterpret(0x3FE756CADBD6130C), reinterpret(0x3FD432EEE32FE000)\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOG_DATA_TAB2 = memory.data([\n // chi , clo\n reinterpret(0x3FE61000014FB66B), reinterpret(0x3C7E026C91425B3C),\n reinterpret(0x3FE63000034DB495), reinterpret(0x3C8DBFEA48005D41),\n reinterpret(0x3FE650000D94D478), reinterpret(0x3C8E7FA786D6A5B7),\n reinterpret(0x3FE67000074E6FAD), reinterpret(0x3C61FCEA6B54254C),\n reinterpret(0x3FE68FFFFEDF0FAE), reinterpret(0xBC7C7E274C590EFD),\n reinterpret(0x3FE6B0000763C5BC), reinterpret(0xBC8AC16848DCDA01),\n reinterpret(0x3FE6D0001E5CC1F6), reinterpret(0x3C833F1C9D499311),\n reinterpret(0x3FE6EFFFEB05F63E), reinterpret(0xBC7E80041AE22D53),\n reinterpret(0x3FE710000E869780), reinterpret(0x3C7BFF6671097952),\n reinterpret(0x3FE72FFFFC67E912), reinterpret(0x3C8C00E226BD8724),\n reinterpret(0x3FE74FFFDF81116A), reinterpret(0xBC6E02916EF101D2),\n reinterpret(0x3FE770000F679C90), reinterpret(0xBC67FC71CD549C74),\n reinterpret(0x3FE78FFFFA7EC835), reinterpret(0x3C81BEC19EF50483),\n reinterpret(0x3FE7AFFFFE20C2E6), reinterpret(0xBC707E1729CC6465),\n reinterpret(0x3FE7CFFFED3FC900), reinterpret(0xBC808072087B8B1C),\n reinterpret(0x3FE7EFFFE9261A76), reinterpret(0x3C8DC0286D9DF9AE),\n reinterpret(0x3FE81000049CA3E8), reinterpret(0x3C897FD251E54C33),\n reinterpret(0x3FE8300017932C8F), reinterpret(0xBC8AFEE9B630F381),\n reinterpret(0x3FE850000633739C), reinterpret(0x3C89BFBF6B6535BC),\n reinterpret(0x3FE87000204289C6), reinterpret(0xBC8BBF65F3117B75),\n reinterpret(0x3FE88FFFEBF57904), reinterpret(0xBC89006EA23DCB57),\n reinterpret(0x3FE8B00022BC04DF), reinterpret(0xBC7D00DF38E04B0A),\n reinterpret(0x3FE8CFFFE50C1B8A), reinterpret(0xBC88007146FF9F05),\n reinterpret(0x3FE8EFFFFC918E43), reinterpret(0x3C83817BD07A7038),\n reinterpret(0x3FE910001EFA5FC7), reinterpret(0x3C893E9176DFB403),\n reinterpret(0x3FE9300013467BB9), reinterpret(0x3C7F804E4B980276),\n reinterpret(0x3FE94FFFE6EE076F), reinterpret(0xBC8F7EF0D9FF622E),\n reinterpret(0x3FE96FFFDE3C12D1), reinterpret(0xBC7082AA962638BA),\n reinterpret(0x3FE98FFFF4458A0D), reinterpret(0xBC87801B9164A8EF),\n reinterpret(0x3FE9AFFFDD982E3E), reinterpret(0xBC8740E08A5A9337),\n reinterpret(0x3FE9CFFFED49FB66), reinterpret(0x3C3FCE08C19BE000),\n reinterpret(0x3FE9F00020F19C51), reinterpret(0xBC8A3FAA27885B0A),\n reinterpret(0x3FEA10001145B006), reinterpret(0x3C74FF489958DA56),\n reinterpret(0x3FEA300007BBF6FA), reinterpret(0x3C8CBEAB8A2B6D18),\n reinterpret(0x3FEA500010971D79), reinterpret(0x3C88FECADD787930),\n reinterpret(0x3FEA70001DF52E48), reinterpret(0xBC8F41763DD8ABDB),\n reinterpret(0x3FEA90001C593352), reinterpret(0xBC8EBF0284C27612),\n reinterpret(0x3FEAB0002A4F3E4B), reinterpret(0xBC69FD043CFF3F5F),\n reinterpret(0x3FEACFFFD7AE1ED1), reinterpret(0xBC823EE7129070B4),\n reinterpret(0x3FEAEFFFEE510478), reinterpret(0x3C6A063EE00EDEA3),\n reinterpret(0x3FEB0FFFDB650D5B), reinterpret(0x3C5A06C8381F0AB9),\n reinterpret(0x3FEB2FFFFEAACA57), reinterpret(0xBC79011E74233C1D),\n reinterpret(0x3FEB4FFFD995BADC), reinterpret(0xBC79FF1068862A9F),\n reinterpret(0x3FEB7000249E659C), reinterpret(0x3C8AFF45D0864F3E),\n reinterpret(0x3FEB8FFFF9871640), reinterpret(0x3C7CFE7796C2C3F9),\n reinterpret(0x3FEBAFFFD204CB4F), reinterpret(0xBC63FF27EEF22BC4),\n reinterpret(0x3FEBCFFFD2415C45), reinterpret(0xBC6CFFB7EE3BEA21),\n reinterpret(0x3FEBEFFFF86309DF), reinterpret(0xBC814103972E0B5C),\n reinterpret(0x3FEC0FFFE1B57653), reinterpret(0x3C8BC16494B76A19),\n reinterpret(0x3FEC2FFFF1FA57E3), reinterpret(0xBC64FEEF8D30C6ED),\n reinterpret(0x3FEC4FFFDCBFE424), reinterpret(0xBC843F68BCEC4775),\n reinterpret(0x3FEC6FFFED54B9F7), reinterpret(0x3C847EA3F053E0EC),\n reinterpret(0x3FEC8FFFEB998FD5), reinterpret(0x3C7383068DF992F1),\n reinterpret(0x3FECB0002125219A), reinterpret(0xBC68FD8E64180E04),\n reinterpret(0x3FECCFFFDD94469C), reinterpret(0x3C8E7EBE1CC7EA72),\n reinterpret(0x3FECEFFFEAFDC476), reinterpret(0x3C8EBE39AD9F88FE),\n reinterpret(0x3FED1000169AF82B), reinterpret(0x3C757D91A8B95A71),\n reinterpret(0x3FED30000D0FF71D), reinterpret(0x3C89C1906970C7DA),\n reinterpret(0x3FED4FFFEA790FC4), reinterpret(0xBC580E37C558FE0C),\n reinterpret(0x3FED70002EDC87E5), reinterpret(0xBC7F80D64DC10F44),\n reinterpret(0x3FED900021DC82AA), reinterpret(0xBC747C8F94FD5C5C),\n reinterpret(0x3FEDAFFFD86B0283), reinterpret(0x3C8C7F1DC521617E),\n reinterpret(0x3FEDD000296C4739), reinterpret(0x3C88019EB2FFB153),\n reinterpret(0x3FEDEFFFE54490F5), reinterpret(0x3C6E00D2C652CC89),\n reinterpret(0x3FEE0FFFCDABF694), reinterpret(0xBC7F8340202D69D2),\n reinterpret(0x3FEE2FFFDB52C8DD), reinterpret(0x3C7B00C1CA1B0864),\n reinterpret(0x3FEE4FFFF24216EF), reinterpret(0x3C72FFA8B094AB51),\n reinterpret(0x3FEE6FFFE88A5E11), reinterpret(0xBC57F673B1EFBE59),\n reinterpret(0x3FEE9000119EFF0D), reinterpret(0xBC84808D5E0BC801),\n reinterpret(0x3FEEAFFFDFA51744), reinterpret(0x3C780006D54320B5),\n reinterpret(0x3FEED0001A127FA1), reinterpret(0xBC5002F860565C92),\n reinterpret(0x3FEEF00007BABCC4), reinterpret(0xBC8540445D35E611),\n reinterpret(0x3FEF0FFFF57A8D02), reinterpret(0xBC4FFB3139EF9105),\n reinterpret(0x3FEF30001EE58AC7), reinterpret(0x3C8A81ACF2731155),\n reinterpret(0x3FEF4FFFF5823494), reinterpret(0x3C8A3F41D4D7C743),\n reinterpret(0x3FEF6FFFFCA94C6B), reinterpret(0xBC6202F41C987875),\n reinterpret(0x3FEF8FFFE1F9C441), reinterpret(0x3C777DD1F477E74B),\n reinterpret(0x3FEFAFFFD2E0E37E), reinterpret(0xBC6F01199A7CA331),\n reinterpret(0x3FEFD0001C77E49E), reinterpret(0x3C7181EE4BCEACB1),\n reinterpret(0x3FEFEFFFF7E0C331), reinterpret(0xBC6E05370170875A),\n reinterpret(0x3FF00FFFF465606E), reinterpret(0xBC8A7EAD491C0ADA),\n reinterpret(0x3FF02FFFF3867A58), reinterpret(0xBC977F69C3FCB2E0),\n reinterpret(0x3FF04FFFFDFC0D17), reinterpret(0x3C97BFFE34CB945B),\n reinterpret(0x3FF0700003CD4D82), reinterpret(0x3C820083C0E456CB),\n reinterpret(0x3FF08FFFF9F2CBE8), reinterpret(0xBC6DFFDFBE37751A),\n reinterpret(0x3FF0B000010CDA65), reinterpret(0xBC913F7FAEE626EB),\n reinterpret(0x3FF0D00001A4D338), reinterpret(0x3C807DFA79489FF7),\n reinterpret(0x3FF0EFFFFADAFDFD), reinterpret(0xBC77040570D66BC0),\n reinterpret(0x3FF110000BBAFD96), reinterpret(0x3C8E80D4846D0B62),\n reinterpret(0x3FF12FFFFAE5F45D), reinterpret(0x3C9DBFFA64FD36EF),\n reinterpret(0x3FF150000DD59AD9), reinterpret(0x3C9A0077701250AE),\n reinterpret(0x3FF170000F21559A), reinterpret(0x3C8DFDF9E2E3DEEE),\n reinterpret(0x3FF18FFFFC275426), reinterpret(0x3C910030DC3B7273),\n reinterpret(0x3FF1B000123D3C59), reinterpret(0x3C997F7980030188),\n reinterpret(0x3FF1CFFFF8299EB7), reinterpret(0xBC65F932AB9F8C67),\n reinterpret(0x3FF1EFFFF48AD400), reinterpret(0x3C937FBF9DA75BEB),\n reinterpret(0x3FF210000C8B86A4), reinterpret(0x3C9F806B91FD5B22),\n reinterpret(0x3FF2300003854303), reinterpret(0x3C93FFC2EB9FBF33),\n reinterpret(0x3FF24FFFFFBCF684), reinterpret(0x3C7601E77E2E2E72),\n reinterpret(0x3FF26FFFF52921D9), reinterpret(0x3C7FFCBB767F0C61),\n reinterpret(0x3FF2900014933A3C), reinterpret(0xBC7202CA3C02412B),\n reinterpret(0x3FF2B00014556313), reinterpret(0xBC92808233F21F02),\n reinterpret(0x3FF2CFFFEBFE523B), reinterpret(0xBC88FF7E384FDCF2),\n reinterpret(0x3FF2F0000BB8AD96), reinterpret(0xBC85FF51503041C5),\n reinterpret(0x3FF30FFFFB7AE2AF), reinterpret(0xBC810071885E289D),\n reinterpret(0x3FF32FFFFEAC5F7F), reinterpret(0xBC91FF5D3FB7B715),\n reinterpret(0x3FF350000CA66756), reinterpret(0x3C957F82228B82BD),\n reinterpret(0x3FF3700011FBF721), reinterpret(0x3C8000BAC40DD5CC),\n reinterpret(0x3FF38FFFF9592FB9), reinterpret(0xBC943F9D2DB2A751),\n reinterpret(0x3FF3B00004DDD242), reinterpret(0x3C857F6B707638E1),\n reinterpret(0x3FF3CFFFF5B2C957), reinterpret(0x3C7A023A10BF1231),\n reinterpret(0x3FF3EFFFEAB0B418), reinterpret(0x3C987F6D66B152B0),\n reinterpret(0x3FF410001532AFF4), reinterpret(0x3C67F8375F198524),\n reinterpret(0x3FF4300017478B29), reinterpret(0x3C8301E672DC5143),\n reinterpret(0x3FF44FFFE795B463), reinterpret(0x3C89FF69B8B2895A),\n reinterpret(0x3FF46FFFE80475E0), reinterpret(0xBC95C0B19BC2F254),\n reinterpret(0x3FF48FFFEF6FC1E7), reinterpret(0x3C9B4009F23A2A72),\n reinterpret(0x3FF4AFFFE5BEA704), reinterpret(0xBC94FFB7BF0D7D45),\n reinterpret(0x3FF4D000171027DE), reinterpret(0xBC99C06471DC6A3D),\n reinterpret(0x3FF4F0000FF03EE2), reinterpret(0x3C977F890B85531C),\n reinterpret(0x3FF5100012DC4BD1), reinterpret(0x3C6004657166A436),\n reinterpret(0x3FF530001605277A), reinterpret(0xBC96BFCECE233209),\n reinterpret(0x3FF54FFFECDB704C), reinterpret(0xBC8902720505A1D7),\n reinterpret(0x3FF56FFFEF5F54A9), reinterpret(0x3C9BBFE60EC96412),\n reinterpret(0x3FF5900017E61012), reinterpret(0x3C887EC581AFEF90),\n reinterpret(0x3FF5B00003C93E92), reinterpret(0xBC9F41080ABF0CC0),\n reinterpret(0x3FF5D0001D4919BC), reinterpret(0xBC98812AFB254729),\n reinterpret(0x3FF5EFFFE7B87A89), reinterpret(0xBC947EB780ED6904)\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function log_lut(x: f64): f64 {\n const N_MASK = (1 << LOG_TABLE_BITS) - 1;\n\n const\n B0 = reinterpret(0xBFE0000000000000), // -0x1p-1\n B1 = reinterpret(0x3FD5555555555577), // 0x1.5555555555577p-2\n B2 = reinterpret(0xBFCFFFFFFFFFFDCB), // -0x1.ffffffffffdcbp-3\n B3 = reinterpret(0x3FC999999995DD0C), // 0x1.999999995dd0cp-3\n B4 = reinterpret(0xBFC55555556745A7), // -0x1.55555556745a7p-3\n B5 = reinterpret(0x3FC24924A344DE30), // 0x1.24924a344de3p-3\n B6 = reinterpret(0xBFBFFFFFA4423D65), // -0x1.fffffa4423d65p-4\n B7 = reinterpret(0x3FBC7184282AD6CA), // 0x1.c7184282ad6cap-4\n B8 = reinterpret(0xBFB999EB43B068FF), // -0x1.999eb43b068ffp-4\n B9 = reinterpret(0x3FB78182F7AFD085), // 0x1.78182f7afd085p-4\n B10 = reinterpret(0xBFB5521375D145CD); // -0x1.5521375d145cdp-4\n\n const\n A0 = reinterpret(0xBFE0000000000001), // -0x1.0000000000001p-1\n A1 = reinterpret(0x3FD555555551305B), // 0x1.555555551305bp-2\n A2 = reinterpret(0xBFCFFFFFFFEB4590), // -0x1.fffffffeb459p-3\n A3 = reinterpret(0x3FC999B324F10111), // 0x1.999b324f10111p-3\n A4 = reinterpret(0xBFC55575E506C89F); // -0x1.55575e506c89fp-3\n\n const\n LO: u64 = 0x3FEE000000000000,\n HI: u64 = 0x3FF1090000000000;\n\n const\n Ln2hi = reinterpret(0x3FE62E42FEFA3800), // 0x1.62e42fefa3800p-1\n Ln2lo = reinterpret(0x3D2EF35793C76730), // 0x1.ef35793c76730p-45\n Ox1p27 = reinterpret(0x41A0000000000000), // 0x1p27\n Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n var ix = reinterpret(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n let r2 = r * r;\n let r3 = r2 * r;\n let y =\n r3 * (B1 + r * B2 + r2 * B3 +\n r3 * (B4 + r * B5 + r2 * B6 +\n r3 * (B7 + r * B8 + r2 * B9 + r3 * B10)));\n // Worst-case error is around 0.507 ULP\n let w = r * Ox1p27;\n let rhi = r + w - w;\n let rlo = r - rhi;\n w = rhi * rhi * B0; // B[0] == -0.5\n let hi = r + w;\n let lo = r - hi + w;\n lo += B0 * rlo * (rhi + r);\n return y + lo + hi;\n }\n var top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7FF0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == reinterpret(Infinity)) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it\n ix = reinterpret(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3FE6000000000000;\n var i = ((tmp >> (52 - LOG_TABLE_BITS)) & N_MASK);\n var k = tmp >> 52;\n var iz = ix - (tmp & (u64(0xFFF) << 52));\n\n var invc = load(LOG_DATA_TAB1 + (i << (1 + alignof())), 0 << alignof()); // T[i].invc;\n var logc = load(LOG_DATA_TAB1 + (i << (1 + alignof())), 1 << alignof()); // T[i].logc;\n var z = reinterpret(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2.\n // r ~= z/c - 1, |r| < 1/(2*N)\n // #if __FP_FAST_FMA\n // \t// rounding error: 0x1p-55/N\n // \tr = __builtin_fma(z, invc, -1.0);\n // #else\n // rounding error: 0x1p-55/N + 0x1p-66\n const chi = load(LOG_DATA_TAB2 + (i << (1 + alignof())), 0 << alignof()); // T2[i].chi\n const clo = load(LOG_DATA_TAB2 + (i << (1 + alignof())), 1 << alignof()); // T2[i].clo\n var r = (z - chi - clo) * invc;\n // #endif\n var kd = k;\n\n // hi + lo = r + log(c) + k*Ln2\n var w = kd * Ln2hi + logc;\n var hi = w + r;\n var lo = w - hi + r + kd * Ln2lo;\n\n // log(x) = lo + (log1p(r) - r) + hi\n var r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst case error if |y| > 0x1p-5:\n // 0.5 + 4.13/N + abs-poly-error*2^57 ULP (+ 0.002 ULP without fma)\n // Worst case error if |y| > 0x1p-4:\n // 0.5 + 2.06/N + abs-poly-error*2^56 ULP (+ 0.001 ULP without fma).\n return lo + r2 * A0 + r * r2 * (A1 + r * A2 + r2 * (A3 + r * A4)) + hi;\n}\n\n//\n// Lookup data for pow. See: https://git.musl-libc.org/cgit/musl/tree/src/math/pow.c\n//\n\n// @ts-ignore: decorator\n@inline const POW_LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [0x1.69555p-1; 0x1.69555p0] which is split into N subintervals\nand z falls into the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = round(0x1p43*log(c))/0x1p43\n tab[i].logctail = (double)(log(c) - logc)\n\nwhere c is chosen near the center of the subinterval such that 1/c has only a\nfew precision bits so z/c - 1 is exactly representible as double:\n\n 1/c = center < 1 ? round(N/center)/N : round(2*N/center)/N/2\n\nNote: |z/c - 1| < 1/N for the chosen c, |log(c) - logc - logctail| < 0x1p-97,\nthe last few bits of logc are rounded away so k*ln2hi + logc has no rounding\nerror and the interval for z is selected such that near x == 1, where log(x)\nis tiny, large cancellation error is avoided in logc + poly(z/c - 1). */\n\n// @ts-ignore: decorator\n@lazy @inline const POW_LOG_DATA_TAB = memory.data([\n // invc ,pad, logc , logctail\n reinterpret(0x3FF6A00000000000), 0, reinterpret(0xBFD62C82F2B9C800), reinterpret(0x3CFAB42428375680),\n reinterpret(0x3FF6800000000000), 0, reinterpret(0xBFD5D1BDBF580800), reinterpret(0xBD1CA508D8E0F720),\n reinterpret(0x3FF6600000000000), 0, reinterpret(0xBFD5767717455800), reinterpret(0xBD2362A4D5B6506D),\n reinterpret(0x3FF6400000000000), 0, reinterpret(0xBFD51AAD872DF800), reinterpret(0xBCE684E49EB067D5),\n reinterpret(0x3FF6200000000000), 0, reinterpret(0xBFD4BE5F95777800), reinterpret(0xBD041B6993293EE0),\n reinterpret(0x3FF6000000000000), 0, reinterpret(0xBFD4618BC21C6000), reinterpret(0x3D13D82F484C84CC),\n reinterpret(0x3FF5E00000000000), 0, reinterpret(0xBFD404308686A800), reinterpret(0x3CDC42F3ED820B3A),\n reinterpret(0x3FF5C00000000000), 0, reinterpret(0xBFD3A64C55694800), reinterpret(0x3D20B1C686519460),\n reinterpret(0x3FF5A00000000000), 0, reinterpret(0xBFD347DD9A988000), reinterpret(0x3D25594DD4C58092),\n reinterpret(0x3FF5800000000000), 0, reinterpret(0xBFD2E8E2BAE12000), reinterpret(0x3D267B1E99B72BD8),\n reinterpret(0x3FF5600000000000), 0, reinterpret(0xBFD2895A13DE8800), reinterpret(0x3D15CA14B6CFB03F),\n reinterpret(0x3FF5600000000000), 0, reinterpret(0xBFD2895A13DE8800), reinterpret(0x3D15CA14B6CFB03F),\n reinterpret(0x3FF5400000000000), 0, reinterpret(0xBFD22941FBCF7800), reinterpret(0xBD165A242853DA76),\n reinterpret(0x3FF5200000000000), 0, reinterpret(0xBFD1C898C1699800), reinterpret(0xBD1FAFBC68E75404),\n reinterpret(0x3FF5000000000000), 0, reinterpret(0xBFD1675CABABA800), reinterpret(0x3D1F1FC63382A8F0),\n reinterpret(0x3FF4E00000000000), 0, reinterpret(0xBFD1058BF9AE4800), reinterpret(0xBD26A8C4FD055A66),\n reinterpret(0x3FF4C00000000000), 0, reinterpret(0xBFD0A324E2739000), reinterpret(0xBD0C6BEE7EF4030E),\n reinterpret(0x3FF4A00000000000), 0, reinterpret(0xBFD0402594B4D000), reinterpret(0xBCF036B89EF42D7F),\n reinterpret(0x3FF4A00000000000), 0, reinterpret(0xBFD0402594B4D000), reinterpret(0xBCF036B89EF42D7F),\n reinterpret(0x3FF4800000000000), 0, reinterpret(0xBFCFB9186D5E4000), reinterpret(0x3D0D572AAB993C87),\n reinterpret(0x3FF4600000000000), 0, reinterpret(0xBFCEF0ADCBDC6000), reinterpret(0x3D2B26B79C86AF24),\n reinterpret(0x3FF4400000000000), 0, reinterpret(0xBFCE27076E2AF000), reinterpret(0xBD172F4F543FFF10),\n reinterpret(0x3FF4200000000000), 0, reinterpret(0xBFCD5C216B4FC000), reinterpret(0x3D21BA91BBCA681B),\n reinterpret(0x3FF4000000000000), 0, reinterpret(0xBFCC8FF7C79AA000), reinterpret(0x3D27794F689F8434),\n reinterpret(0x3FF4000000000000), 0, reinterpret(0xBFCC8FF7C79AA000), reinterpret(0x3D27794F689F8434),\n reinterpret(0x3FF3E00000000000), 0, reinterpret(0xBFCBC286742D9000), reinterpret(0x3D194EB0318BB78F),\n reinterpret(0x3FF3C00000000000), 0, reinterpret(0xBFCAF3C94E80C000), reinterpret(0x3CBA4E633FCD9066),\n reinterpret(0x3FF3A00000000000), 0, reinterpret(0xBFCA23BC1FE2B000), reinterpret(0xBD258C64DC46C1EA),\n reinterpret(0x3FF3A00000000000), 0, reinterpret(0xBFCA23BC1FE2B000), reinterpret(0xBD258C64DC46C1EA),\n reinterpret(0x3FF3800000000000), 0, reinterpret(0xBFC9525A9CF45000), reinterpret(0xBD2AD1D904C1D4E3),\n reinterpret(0x3FF3600000000000), 0, reinterpret(0xBFC87FA06520D000), reinterpret(0x3D2BBDBF7FDBFA09),\n reinterpret(0x3FF3400000000000), 0, reinterpret(0xBFC7AB890210E000), reinterpret(0x3D2BDB9072534A58),\n reinterpret(0x3FF3400000000000), 0, reinterpret(0xBFC7AB890210E000), reinterpret(0x3D2BDB9072534A58),\n reinterpret(0x3FF3200000000000), 0, reinterpret(0xBFC6D60FE719D000), reinterpret(0xBD10E46AA3B2E266),\n reinterpret(0x3FF3000000000000), 0, reinterpret(0xBFC5FF3070A79000), reinterpret(0xBD1E9E439F105039),\n reinterpret(0x3FF3000000000000), 0, reinterpret(0xBFC5FF3070A79000), reinterpret(0xBD1E9E439F105039),\n reinterpret(0x3FF2E00000000000), 0, reinterpret(0xBFC526E5E3A1B000), reinterpret(0xBD20DE8B90075B8F),\n reinterpret(0x3FF2C00000000000), 0, reinterpret(0xBFC44D2B6CCB8000), reinterpret(0x3D170CC16135783C),\n reinterpret(0x3FF2C00000000000), 0, reinterpret(0xBFC44D2B6CCB8000), reinterpret(0x3D170CC16135783C),\n reinterpret(0x3FF2A00000000000), 0, reinterpret(0xBFC371FC201E9000), reinterpret(0x3CF178864D27543A),\n reinterpret(0x3FF2800000000000), 0, reinterpret(0xBFC29552F81FF000), reinterpret(0xBD248D301771C408),\n reinterpret(0x3FF2600000000000), 0, reinterpret(0xBFC1B72AD52F6000), reinterpret(0xBD2E80A41811A396),\n reinterpret(0x3FF2600000000000), 0, reinterpret(0xBFC1B72AD52F6000), reinterpret(0xBD2E80A41811A396),\n reinterpret(0x3FF2400000000000), 0, reinterpret(0xBFC0D77E7CD09000), reinterpret(0x3D0A699688E85BF4),\n reinterpret(0x3FF2400000000000), 0, reinterpret(0xBFC0D77E7CD09000), reinterpret(0x3D0A699688E85BF4),\n reinterpret(0x3FF2200000000000), 0, reinterpret(0xBFBFEC9131DBE000), reinterpret(0xBD2575545CA333F2),\n reinterpret(0x3FF2000000000000), 0, reinterpret(0xBFBE27076E2B0000), reinterpret(0x3D2A342C2AF0003C),\n reinterpret(0x3FF2000000000000), 0, reinterpret(0xBFBE27076E2B0000), reinterpret(0x3D2A342C2AF0003C),\n reinterpret(0x3FF1E00000000000), 0, reinterpret(0xBFBC5E548F5BC000), reinterpret(0xBD1D0C57585FBE06),\n reinterpret(0x3FF1C00000000000), 0, reinterpret(0xBFBA926D3A4AE000), reinterpret(0x3D253935E85BAAC8),\n reinterpret(0x3FF1C00000000000), 0, reinterpret(0xBFBA926D3A4AE000), reinterpret(0x3D253935E85BAAC8),\n reinterpret(0x3FF1A00000000000), 0, reinterpret(0xBFB8C345D631A000), reinterpret(0x3D137C294D2F5668),\n reinterpret(0x3FF1A00000000000), 0, reinterpret(0xBFB8C345D631A000), reinterpret(0x3D137C294D2F5668),\n reinterpret(0x3FF1800000000000), 0, reinterpret(0xBFB6F0D28AE56000), reinterpret(0xBD269737C93373DA),\n reinterpret(0x3FF1600000000000), 0, reinterpret(0xBFB51B073F062000), reinterpret(0x3D1F025B61C65E57),\n reinterpret(0x3FF1600000000000), 0, reinterpret(0xBFB51B073F062000), reinterpret(0x3D1F025B61C65E57),\n reinterpret(0x3FF1400000000000), 0, reinterpret(0xBFB341D7961BE000), reinterpret(0x3D2C5EDACCF913DF),\n reinterpret(0x3FF1400000000000), 0, reinterpret(0xBFB341D7961BE000), reinterpret(0x3D2C5EDACCF913DF),\n reinterpret(0x3FF1200000000000), 0, reinterpret(0xBFB16536EEA38000), reinterpret(0x3D147C5E768FA309),\n reinterpret(0x3FF1000000000000), 0, reinterpret(0xBFAF0A30C0118000), reinterpret(0x3D2D599E83368E91),\n reinterpret(0x3FF1000000000000), 0, reinterpret(0xBFAF0A30C0118000), reinterpret(0x3D2D599E83368E91),\n reinterpret(0x3FF0E00000000000), 0, reinterpret(0xBFAB42DD71198000), reinterpret(0x3D1C827AE5D6704C),\n reinterpret(0x3FF0E00000000000), 0, reinterpret(0xBFAB42DD71198000), reinterpret(0x3D1C827AE5D6704C),\n reinterpret(0x3FF0C00000000000), 0, reinterpret(0xBFA77458F632C000), reinterpret(0xBD2CFC4634F2A1EE),\n reinterpret(0x3FF0C00000000000), 0, reinterpret(0xBFA77458F632C000), reinterpret(0xBD2CFC4634F2A1EE),\n reinterpret(0x3FF0A00000000000), 0, reinterpret(0xBFA39E87B9FEC000), reinterpret(0x3CF502B7F526FEAA),\n reinterpret(0x3FF0A00000000000), 0, reinterpret(0xBFA39E87B9FEC000), reinterpret(0x3CF502B7F526FEAA),\n reinterpret(0x3FF0800000000000), 0, reinterpret(0xBF9F829B0E780000), reinterpret(0xBD2980267C7E09E4),\n reinterpret(0x3FF0800000000000), 0, reinterpret(0xBF9F829B0E780000), reinterpret(0xBD2980267C7E09E4),\n reinterpret(0x3FF0600000000000), 0, reinterpret(0xBF97B91B07D58000), reinterpret(0xBD288D5493FAA639),\n reinterpret(0x3FF0400000000000), 0, reinterpret(0xBF8FC0A8B0FC0000), reinterpret(0xBCDF1E7CF6D3A69C),\n reinterpret(0x3FF0400000000000), 0, reinterpret(0xBF8FC0A8B0FC0000), reinterpret(0xBCDF1E7CF6D3A69C),\n reinterpret(0x3FF0200000000000), 0, reinterpret(0xBF7FE02A6B100000), reinterpret(0xBD19E23F0DDA40E4),\n reinterpret(0x3FF0200000000000), 0, reinterpret(0xBF7FE02A6B100000), reinterpret(0xBD19E23F0DDA40E4),\n reinterpret(0x3FF0000000000000), 0, 0, 0,\n reinterpret(0x3FF0000000000000), 0, 0, 0,\n reinterpret(0x3FEFC00000000000), 0, reinterpret(0x3F80101575890000), reinterpret(0xBD10C76B999D2BE8),\n reinterpret(0x3FEF800000000000), 0, reinterpret(0x3F90205658938000), reinterpret(0xBD23DC5B06E2F7D2),\n reinterpret(0x3FEF400000000000), 0, reinterpret(0x3F98492528C90000), reinterpret(0xBD2AA0BA325A0C34),\n reinterpret(0x3FEF000000000000), 0, reinterpret(0x3FA0415D89E74000), reinterpret(0x3D0111C05CF1D753),\n reinterpret(0x3FEEC00000000000), 0, reinterpret(0x3FA466AED42E0000), reinterpret(0xBD2C167375BDFD28),\n reinterpret(0x3FEE800000000000), 0, reinterpret(0x3FA894AA149FC000), reinterpret(0xBD197995D05A267D),\n reinterpret(0x3FEE400000000000), 0, reinterpret(0x3FACCB73CDDDC000), reinterpret(0xBD1A68F247D82807),\n reinterpret(0x3FEE200000000000), 0, reinterpret(0x3FAEEA31C006C000), reinterpret(0xBD0E113E4FC93B7B),\n reinterpret(0x3FEDE00000000000), 0, reinterpret(0x3FB1973BD1466000), reinterpret(0xBD25325D560D9E9B),\n reinterpret(0x3FEDA00000000000), 0, reinterpret(0x3FB3BDF5A7D1E000), reinterpret(0x3D2CC85EA5DB4ED7),\n reinterpret(0x3FED600000000000), 0, reinterpret(0x3FB5E95A4D97A000), reinterpret(0xBD2C69063C5D1D1E),\n reinterpret(0x3FED400000000000), 0, reinterpret(0x3FB700D30AEAC000), reinterpret(0x3CEC1E8DA99DED32),\n reinterpret(0x3FED000000000000), 0, reinterpret(0x3FB9335E5D594000), reinterpret(0x3D23115C3ABD47DA),\n reinterpret(0x3FECC00000000000), 0, reinterpret(0x3FBB6AC88DAD6000), reinterpret(0xBD1390802BF768E5),\n reinterpret(0x3FECA00000000000), 0, reinterpret(0x3FBC885801BC4000), reinterpret(0x3D2646D1C65AACD3),\n reinterpret(0x3FEC600000000000), 0, reinterpret(0x3FBEC739830A2000), reinterpret(0xBD2DC068AFE645E0),\n reinterpret(0x3FEC400000000000), 0, reinterpret(0x3FBFE89139DBE000), reinterpret(0xBD2534D64FA10AFD),\n reinterpret(0x3FEC000000000000), 0, reinterpret(0x3FC1178E8227E000), reinterpret(0x3D21EF78CE2D07F2),\n reinterpret(0x3FEBE00000000000), 0, reinterpret(0x3FC1AA2B7E23F000), reinterpret(0x3D2CA78E44389934),\n reinterpret(0x3FEBA00000000000), 0, reinterpret(0x3FC2D1610C868000), reinterpret(0x3D039D6CCB81B4A1),\n reinterpret(0x3FEB800000000000), 0, reinterpret(0x3FC365FCB0159000), reinterpret(0x3CC62FA8234B7289),\n reinterpret(0x3FEB400000000000), 0, reinterpret(0x3FC4913D8333B000), reinterpret(0x3D25837954FDB678),\n reinterpret(0x3FEB200000000000), 0, reinterpret(0x3FC527E5E4A1B000), reinterpret(0x3D2633E8E5697DC7),\n reinterpret(0x3FEAE00000000000), 0, reinterpret(0x3FC6574EBE8C1000), reinterpret(0x3D19CF8B2C3C2E78),\n reinterpret(0x3FEAC00000000000), 0, reinterpret(0x3FC6F0128B757000), reinterpret(0xBD25118DE59C21E1),\n reinterpret(0x3FEAA00000000000), 0, reinterpret(0x3FC7898D85445000), reinterpret(0xBD1C661070914305),\n reinterpret(0x3FEA600000000000), 0, reinterpret(0x3FC8BEAFEB390000), reinterpret(0xBD073D54AAE92CD1),\n reinterpret(0x3FEA400000000000), 0, reinterpret(0x3FC95A5ADCF70000), reinterpret(0x3D07F22858A0FF6F),\n reinterpret(0x3FEA000000000000), 0, reinterpret(0x3FCA93ED3C8AE000), reinterpret(0xBD28724350562169),\n reinterpret(0x3FE9E00000000000), 0, reinterpret(0x3FCB31D8575BD000), reinterpret(0xBD0C358D4EACE1AA),\n reinterpret(0x3FE9C00000000000), 0, reinterpret(0x3FCBD087383BE000), reinterpret(0xBD2D4BC4595412B6),\n reinterpret(0x3FE9A00000000000), 0, reinterpret(0x3FCC6FFBC6F01000), reinterpret(0xBCF1EC72C5962BD2),\n reinterpret(0x3FE9600000000000), 0, reinterpret(0x3FCDB13DB0D49000), reinterpret(0xBD2AFF2AF715B035),\n reinterpret(0x3FE9400000000000), 0, reinterpret(0x3FCE530EFFE71000), reinterpret(0x3CC212276041F430),\n reinterpret(0x3FE9200000000000), 0, reinterpret(0x3FCEF5ADE4DD0000), reinterpret(0xBCCA211565BB8E11),\n reinterpret(0x3FE9000000000000), 0, reinterpret(0x3FCF991C6CB3B000), reinterpret(0x3D1BCBECCA0CDF30),\n reinterpret(0x3FE8C00000000000), 0, reinterpret(0x3FD07138604D5800), reinterpret(0x3CF89CDB16ED4E91),\n reinterpret(0x3FE8A00000000000), 0, reinterpret(0x3FD0C42D67616000), reinterpret(0x3D27188B163CEAE9),\n reinterpret(0x3FE8800000000000), 0, reinterpret(0x3FD1178E8227E800), reinterpret(0xBD2C210E63A5F01C),\n reinterpret(0x3FE8600000000000), 0, reinterpret(0x3FD16B5CCBACF800), reinterpret(0x3D2B9ACDF7A51681),\n reinterpret(0x3FE8400000000000), 0, reinterpret(0x3FD1BF99635A6800), reinterpret(0x3D2CA6ED5147BDB7),\n reinterpret(0x3FE8200000000000), 0, reinterpret(0x3FD214456D0EB800), reinterpret(0x3D0A87DEBA46BAEA),\n reinterpret(0x3FE7E00000000000), 0, reinterpret(0x3FD2BEF07CDC9000), reinterpret(0x3D2A9CFA4A5004F4),\n reinterpret(0x3FE7C00000000000), 0, reinterpret(0x3FD314F1E1D36000), reinterpret(0xBD28E27AD3213CB8),\n reinterpret(0x3FE7A00000000000), 0, reinterpret(0x3FD36B6776BE1000), reinterpret(0x3D116ECDB0F177C8),\n reinterpret(0x3FE7800000000000), 0, reinterpret(0x3FD3C25277333000), reinterpret(0x3D183B54B606BD5C),\n reinterpret(0x3FE7600000000000), 0, reinterpret(0x3FD419B423D5E800), reinterpret(0x3D08E436EC90E09D),\n reinterpret(0x3FE7400000000000), 0, reinterpret(0x3FD4718DC271C800), reinterpret(0xBD2F27CE0967D675),\n reinterpret(0x3FE7200000000000), 0, reinterpret(0x3FD4C9E09E173000), reinterpret(0xBD2E20891B0AD8A4),\n reinterpret(0x3FE7000000000000), 0, reinterpret(0x3FD522AE0738A000), reinterpret(0x3D2EBE708164C759),\n reinterpret(0x3FE6E00000000000), 0, reinterpret(0x3FD57BF753C8D000), reinterpret(0x3D1FADEDEE5D40EF),\n reinterpret(0x3FE6C00000000000), 0, reinterpret(0x3FD5D5BDDF596000), reinterpret(0xBD0A0B2A08A465DC)\n]);\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkint(iy: u64): i32 {\n var e = iy >> 52 & 0x7FF;\n if (e < 0x3FF ) return 0;\n if (e > 0x3FF + 52) return 2;\n e = u64(1) << (0x3FF + 52 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflow(sign: u32, y: f64): f64 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflow(sign: u32): f64 {\n return xflow(sign, reinterpret(0x1000000000000000)); // 0x1p-767\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflow(sign: u32): f64 {\n return xflow(sign, reinterpret(0x7000000000000000)); // 0x1p769\n}\n\n// Returns 1 if input is the bit representation of 0, infinity or nan.\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnan(u: u64): bool {\n return (u << 1) - 1 >= 0xFFE0000000000000 - 1;\n}\n\n// @ts-ignore: decorator\n@lazy var log_tail: f64 = 0;\n\n// Compute y+TAIL = log(x) where the rounded result is y and TAIL has about\n// additional 15 bits precision. IX is the bit representation of x, but\n// normalized in the subnormal range using the sign bit for the exponent.\n// @ts-ignore: decorator\n@inline\nfunction log_inline(ix: u64): f64 {\n const N = 1 << POW_LOG_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n Ln2hi = reinterpret(0x3FE62E42FEFA3800),\n Ln2lo = reinterpret(0x3D2EF35793C76730);\n\n const\n A0 = reinterpret(0xBFE0000000000000),\n A1 = reinterpret(0xBFE5555555555560),\n A2 = reinterpret(0x3FE0000000000006),\n A3 = reinterpret(0x3FE999999959554E),\n A4 = reinterpret(0xBFE555555529A47A),\n A5 = reinterpret(0xBFF2495B9B4845E9),\n A6 = reinterpret(0x3FF0002B8B263FC3);\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3fE6955500000000;\n var i = usize((tmp >> (52 - POW_LOG_TABLE_BITS)) & N_MASK);\n var k = tmp >> 52;\n var iz = ix - (tmp & u64(0xFFF) << 52);\n var z = reinterpret(iz);\n var kd = k;\n\n // log(x) = k*Ln2 + log(c) + log1p(z/c-1).\n var invc = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 0 << alignof()); // tab[i].invc\n var logc = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 2 << alignof()); // tab[i].logc\n var logctail = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 3 << alignof()); // tab[i].logctail\n\n // Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and\n // |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible.\n // Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|.\n var zhi = reinterpret((iz + u64(0x80000000)) & 0xFFFFFFFF00000000);\n var zlo = z - zhi;\n var rhi = zhi * invc - 1.0;\n var rlo = zlo * invc;\n var r = rhi + rlo;\n\n // k * Ln2 + log(c) + r.\n var t1 = kd * Ln2hi + logc;\n var t2 = t1 + r;\n var lo1 = kd * Ln2lo + logctail;\n var lo2 = t1 - t2 + r;\n\n // Evaluation is optimized assuming superscalar pipelined execution.\n var ar = A0 * r; // A[0] = -0.5\n var ar2 = r * ar;\n var ar3 = r * ar2;\n // k * Ln2 + log(c) + r + A[0] * r * r.\n var arhi = A0 * rhi;\n var arhi2 = rhi * arhi;\n var hi = t2 + arhi2;\n var lo3 = rlo * (ar + arhi);\n var lo4 = t2 - hi + arhi2;\n\n // p = log1p(r) - r - A[0] * r * r.\n var p = ar3 * (A1 + r * A2 + ar2 * (A3 + r * A4 + ar2 * (A5 + r * A6)));\n var lo = lo1 + lo2 + lo3 + lo4 + p;\n var y = hi + lo;\n log_tail = hi - y + lo;\n\n return y;\n}\n\n// @ts-ignore: decorator\n@inline const SIGN_BIAS = 0x800 << EXP_TABLE_BITS;\n\n// Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.\n// The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1.\n// @ts-ignore: decorator\n@inline\nfunction exp_inline(x: f64, xtail: f64, sign_bias: u32): f64 {\n const N = 1 << EXP_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret(0x4338000000000000); // 0x1.8p52\n\n const\n C2 = reinterpret(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n var abstop: u32;\n var ki: u64, top: u64, sbits: u64;\n var idx: usize;\n // double_t for better performance on targets with FLT_EVAL_METHOD==2.\n var kd: f64, z: f64, r: f64, r2: f64, scale: f64, tail: f64, tmp: f64;\n\n var ux = reinterpret(x);\n abstop = u32(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) {\n // Avoid spurious underflow for tiny x.\n // Note: 0 is common input.\n return select(-1.0, 1.0, sign_bias);\n }\n if (abstop >= 0x409) { // top12(1024.0)\n // Note: inf and nan are already handled.\n return ux < 0\n ? uflow(sign_bias)\n : oflow(sign_bias);\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].\n z = InvLn2N * x;\n\n // #if TOINT_INTRINSICS\n // kd = roundtoint(z);\n // ki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // // z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // kd = eval_as_double(z + shift);\n // ki = asuint64(kd) >> 16;\n // kd = (double_t)(int32_t)ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes\n kd = z + shift;\n ki = reinterpret(kd);\n kd -= shift;\n // #endif\n r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // The code assumes 2^-200 < |xtail| < 2^-8/N\n r += xtail;\n // 2^(k/N) ~= scale * (1 + tail)\n idx = usize((ki & N_MASK) << 1);\n top = (ki + sign_bias) << (52 - EXP_TABLE_BITS);\n\n tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof())));\n // This is only a valid scale when -1023*N < k < 1024*N\n sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top;\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp\n tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function pow_lut(x: f64, y: f64): f64 {\n const Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n var sign_bias: u32 = 0;\n var ix = reinterpret(x);\n var iy = reinterpret(y);\n var topx = ix >> 52;\n var topy = iy >> 52;\n\n if (topx - 0x001 >= 0x7FF - 0x001 || (topy & 0x7FF) - 0x3BE >= 0x43e - 0x3BE) {\n // Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0\n // and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1.\n // Special cases: (x < 0x1p-126 or inf or nan) or\n // (|y| < 0x1p-65 or |y| >= 0x1p63 or nan).\n if (zeroinfnan(iy)) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3FF0000000000000) return NaN; // original: 1.0\n if ((ix << 1) > 0xFFE0000000000000 || (iy << 1) > 0xFFE0000000000000) return x + y;\n if ((ix << 1) == 0x7FE0000000000000) return NaN; // original: 1.0\n if (((ix << 1) < 0x7FE0000000000000) == !(iy >> 63)) return 0; // |x|<1 && y==inf or |x|>1 && y==-inf.\n return y * y;\n }\n if (zeroinfnan(ix)) {\n let x2 = x * x;\n if (i32(ix >> 63) && checkint(iy) == 1) x2 = -x2;\n return iy < 0 ? 1 / x2 : x2;\n }\n // Here x and y are non-zero finite\n if (ix < 0) {\n // Finite x < 0\n let yint = checkint(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) sign_bias = SIGN_BIAS;\n ix &= 0x7FFFFFFFFFFFFFFF;\n topx &= 0x7FF;\n }\n if ((topy & 0x7FF) - 0x3BE >= 0x43E - 0x3BE) {\n // Note: sign_bias == 0 here because y is not odd.\n if (ix == 0x3FF0000000000000) return 1;\n if ((topy & 0x7FF) < 0x3BE) return 1; // |y| < 2^-65, x^y ~= 1 + y*log(x).\n return (ix > 0x3FF0000000000000) == (topy < 0x800) ? Infinity : 0;\n }\n if (topx == 0) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret(x * Ox1p52);\n ix &= 0x7FFFFFFFFFFFFFFF;\n ix -= u64(52) << 52;\n }\n }\n\n var hi = log_inline(ix);\n var lo = log_tail;\n var ehi: f64, elo: f64;\n // #if __FP_FAST_FMA\n // ehi = y * hi;\n // elo = y * lo + __builtin_fma(y, hi, -ehi);\n // #else\n var yhi = reinterpret(iy & 0xFFFFFFFFF8000000);\n var ylo = y - yhi;\n var lhi = reinterpret(reinterpret(hi) & 0xFFFFFFFFF8000000);\n var llo = hi - lhi + lo;\n ehi = yhi * lhi;\n elo = ylo * lhi + y * llo; // |elo| < |ehi| * 2^-25.\n // #endif\n return exp_inline(ehi, elo, sign_bias);\n}\n","/// \n\nimport { idof } from \"../builtins\";\nimport { CharCode } from \"./string\";\n\n// @ts-ignore: decorator\n@inline\nexport const MAX_DOUBLE_LENGTH = 28;\n\n// @ts-ignore: decorator\n@lazy @inline const POWERS10 = memory.data([\n 1,\n 10,\n 100,\n 1000,\n 10000,\n 100000,\n 1000000,\n 10000000,\n 100000000,\n 1000000000\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// @ts-ignore: decorator\n@lazy @inline const DIGITS = memory.data([\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\n// Lookup table for pairwise char codes in range [0x00-0xFF]\n// @ts-ignore: decorator\n@lazy @inline const HEX_DIGITS =\n\"000102030405060708090a0b0c0d0e0f\\\n101112131415161718191a1b1c1d1e1f\\\n202122232425262728292a2b2c2d2e2f\\\n303132333435363738393a3b3c3d3e3f\\\n404142434445464748494a4b4c4d4e4f\\\n505152535455565758595a5b5c5d5e5f\\\n606162636465666768696a6b6c6d6e6f\\\n707172737475767778797a7b7c7d7e7f\\\n808182838485868788898a8b8c8d8e8f\\\n909192939495969798999a9b9c9d9e9f\\\na0a1a2a3a4a5a6a7a8a9aaabacadaeaf\\\nb0b1b2b3b4b5b6b7b8b9babbbcbdbebf\\\nc0c1c2c3c4c5c6c7c8c9cacbcccdcecf\\\nd0d1d2d3d4d5d6d7d8d9dadbdcdddedf\\\ne0e1e2e3e4e5e6e7e8e9eaebecedeeef\\\nf0f1f2f3f4f5f6f7f8f9fafbfcfdfeff\";\n\n// @ts-ignore: decorator\n@lazy @inline const ANY_DIGITS = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n\n// @ts-ignore: decorator\n@lazy @inline const EXP_POWERS = memory.data([/* eslint-disable indent */\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/* eslint-enable indent */]);\n\n// 1e-348, 1e-340, ..., 1e340\n// @ts-ignore: decorator\n@lazy @inline const FRC_POWERS = memory.data([\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\n// @ts-ignore: decorator\n@inline\nexport function isPowerOf2(value: T): bool {\n return popcnt(value) == 1;\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 (value < 100000) {\n if (value < 100) {\n return 1 + u32(value >= 10);\n } else {\n return 3 + u32(value >= 10000) + u32(value >= 1000);\n }\n } else {\n if (value < 10000000) {\n return 6 + u32(value >= 1000000);\n } else {\n return 8 + u32(value >= 1000000000) + u32(value >= 100000000);\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 decimalCount64High(value: u64): u32 {\n if (value < 1000000000000000) {\n if (value < 1000000000000) {\n return 10 + u32(value >= 100000000000) + u32(value >= 10000000000);\n } else {\n return 13 + u32(value >= 100000000000000) + u32(value >= 10000000000000);\n }\n } else {\n if (value < 100000000000000000) {\n return 16 + u32(value >= 10000000000000000);\n } else {\n return 18 + u32(value >= 10000000000000000000) + u32(value >= 1000000000000000000);\n }\n }\n}\n\nfunction ulog_base(num: u64, base: i32): u32 {\n if (isPowerOf2(base)) {\n return (63 - clz(num)) / (31 - clz(base)) + 1;\n }\n var b64 = u64(base), b = b64, e: u32 = 1;\n while (num >= b) {\n num /= b;\n b *= b;\n e <<= 1;\n }\n while (num >= 1) {\n num /= b64;\n e++;\n }\n return e - 1;\n}\n\nfunction utoa32_dec_lut(buffer: usize, num: u32, offset: usize): void {\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 = load(DIGITS + (d1 << alignof()));\n let digits2 = load(DIGITS + (d2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\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 = load(DIGITS + (d1 << alignof()));\n store(buffer + (offset << 1), digits);\n }\n\n if (num >= 10) {\n offset -= 2;\n let digits = load(DIGITS + (num << alignof()));\n store(buffer + (offset << 1), digits);\n } else {\n offset -= 1;\n let digit = CharCode._0 + num;\n store(buffer + (offset << 1), digit);\n }\n}\n\nfunction utoa64_dec_lut(buffer: usize, num: u64, offset: usize): void {\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 = load(DIGITS + (c1 << alignof()));\n let digits2 = load(DIGITS + (c2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n\n digits1 = load(DIGITS + (b1 << alignof()));\n digits2 = load(DIGITS + (b2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n }\n\n utoa32_dec_lut(buffer, num, offset);\n}\n\nfunction utoa_hex_lut(buffer: usize, num: u64, offset: usize): void {\n const lut = changetype(HEX_DIGITS);\n while (offset >= 2) {\n offset -= 2;\n store(\n buffer + (offset << 1),\n load(lut + ((num & 0xFF) << alignof()))\n );\n num >>= 8;\n }\n if (offset & 1) {\n store(buffer, load(lut + (num << 6)));\n }\n}\n\nfunction utoa_dec_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let t = num / 10;\n let r = (num % 10);\n num = changetype(t);\n offset--;\n store(buffer + (offset << 1), CharCode._0 + r);\n } while (num);\n}\n\nfunction utoa_hex_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let d = num & 0x0F | CharCode._0;\n d += select(0x27, 0, d > CharCode._9);\n offset--;\n store(buffer + (offset << 1), d);\n // @ts-ignore: type\n num >>= 4;\n } while (num);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function utoa32_dec_core(buffer: usize, num: u32, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_dec_simple(buffer, num, offset);\n } else {\n utoa32_dec_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa32_hex_core(buffer: usize, num: u32, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_hex_simple(buffer, num, offset);\n } else {\n utoa_hex_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa64_dec_core(buffer: usize, num: u64, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_dec_simple(buffer, num, offset);\n } else {\n utoa64_dec_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa64_hex_core(buffer: usize, num: u64, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_hex_simple(buffer, num, offset);\n } else {\n utoa_hex_lut(buffer, num, offset);\n }\n}\n\nfunction utoa64_any_core(buffer: usize, num: u64, offset: usize, radix: i32): void {\n const lut = changetype(ANY_DIGITS);\n var base = u64(radix);\n if ((radix & (radix - 1)) == 0) { // for radix which pow of two\n let shift = u64(ctz(radix) & 7);\n let mask = base - 1;\n do {\n offset--;\n store(buffer + (offset << 1), load(lut + (usize(num & mask) << 1)));\n num >>= shift;\n } while (num);\n } else {\n do {\n offset--;\n let q = num / base;\n store(buffer + (offset << 1), load(lut + (usize(num - q * base) << 1)));\n num = q;\n } while (num);\n }\n}\n\nexport function utoa32(value: u32, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n var out: String;\n\n if (radix == 10) {\n let decimals = decimalCount32(value);\n out = changetype(__new(decimals << 1, idof()));\n utoa32_dec_core(changetype(out), value, decimals);\n } else if (radix == 16) {\n let decimals = (31 - clz(value) >> 2) + 1;\n out = changetype(__new(decimals << 1, idof()));\n utoa32_hex_core(changetype(out), value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_any_core(changetype(out), value, decimals, radix);\n }\n return out;\n}\n\nexport function itoa32(value: i32, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n\n var sign = (value >>> 31) << 1;\n if (sign) value = -value;\n var out: String;\n\n if (radix == 10) {\n let decimals = decimalCount32(value);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_dec_core(changetype(out) + sign, value, decimals);\n } else if (radix == 16) {\n let decimals = (31 - clz(value) >> 2) + 1;\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_hex_core(changetype(out) + sign, value, decimals);\n } else {\n let val32 = u32(value);\n let decimals = ulog_base(val32, radix);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_any_core(changetype(out) + sign, val32, decimals, radix);\n }\n if (sign) store(changetype(out), CharCode.MINUS);\n return out;\n}\n\nexport function utoa64(value: u64, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n var out: String;\n\n if (radix == 10) {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n out = changetype(__new(decimals << 1, idof()));\n utoa32_dec_core(changetype(out), val32, decimals);\n } else {\n let decimals = decimalCount64High(value);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_dec_core(changetype(out), value, decimals);\n }\n } else if (radix == 16) {\n let decimals = (63 - u32(clz(value)) >> 2) + 1;\n out = changetype(__new(decimals << 1, idof()));\n utoa64_hex_core(changetype(out), value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_any_core(changetype(out), value, decimals, radix);\n }\n return out;\n}\n\nexport function itoa64(value: i64, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n\n var sign = u32(value >>> 63) << 1;\n if (sign) value = -value;\n var out: String;\n\n if (radix == 10) {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_dec_core(changetype(out) + sign, val32, decimals);\n } else {\n let decimals = decimalCount64High(value);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_dec_core(changetype(out) + sign, value, decimals);\n }\n } else if (radix == 16) {\n let decimals = (63 - u32(clz(value)) >> 2) + 1;\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_hex_core(changetype(out) + sign, value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_any_core(changetype(out) + sign, value, decimals, radix);\n }\n if (sign) store(changetype(out), CharCode.MINUS);\n return out;\n}\n\n// @ts-ignore: decorator\n@lazy var _K: i32 = 0;\n\n// // @ts-ignore: decorator\n// @lazy\n// var _frc: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy var _exp: i32 = 0;\n\n// @ts-ignore: decorator\n@lazy var _frc_minus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy var _frc_plus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy var _frc_pow: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy var _exp_pow: i32 = 0;\n\n// @ts-ignore: decorator\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// @ts-ignore: decorator\n@inline\nfunction umul64e(e1: i32, e2: i32): i32 {\n return e1 + e2 + 64; // where 64 is significand size\n}\n\n// @ts-ignore: decorator\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 + i32(f == 0x0010000000000000);\n\n _frc_plus = frc;\n _frc_minus = ((f << m) - 1) << e - m - exp;\n _exp = exp;\n}\n\n// @ts-ignore: decorator\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);\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);\n}\n\n// @ts-ignore: decorator\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 += i32(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 _frc_pow = load(FRC_POWERS + (index << alignof()));\n _exp_pow = load(EXP_POWERS + (index << alignof()));\n}\n\n// @ts-ignore: decorator\n@inline\nfunction grisu2(value: f64, buffer: usize, sign: i32): i32 {\n\n // frexp routine\n var uv = reinterpret(value);\n var exp = i32((uv & 0x7FF0000000000000) >>> 52);\n var sid = uv & 0x000FFFFFFFFFFFFF;\n var frc = (u64(exp != 0) << 52) + sid;\n exp = select(exp, 1, exp) - (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\n var p1 = u32(mp_frc >> one_exp);\n var p2 = mp_frc & mask;\n\n var kappa = decimalCount32(p1);\n var len = sign;\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);\n\n --kappa;\n let tmp = ((p1) << one_exp) + p2;\n if (tmp <= delta) {\n _K += kappa;\n grisuRound(buffer, len, delta, tmp, load(POWERS10 + (kappa << alignof())) << one_exp, wp_w_frc);\n return len;\n }\n }\n\n while (true) {\n p2 *= 10;\n delta *= 10;\n\n let d = p2 >> one_exp;\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d);\n\n p2 &= mask;\n --kappa;\n if (p2 < delta) {\n _K += kappa;\n wp_w_frc *= load(POWERS10 + (-kappa << alignof()));\n grisuRound(buffer, len, delta, p2, one_frc, wp_w_frc);\n return len;\n }\n }\n}\n\n// @ts-ignore: decorator\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_dec_core(buffer, k, decimals);\n store(buffer, select(CharCode.MINUS, CharCode.PLUS, sign));\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));\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);\n }\n store(buffer + (kk << 1), CharCode.DOT | (CharCode._0 << 16));\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 + 2,\n ptr,\n -k << 1\n );\n store(buffer + (kk << 1), CharCode.DOT);\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 + (offset << 1),\n buffer,\n length << 1\n );\n store(buffer, CharCode._0 | (CharCode.DOT << 16));\n for (let i = 2; i < offset; ++i) {\n store(buffer + (i << 1), CharCode._0);\n }\n return length + offset;\n } else if (length == 1) {\n // 1e30\n store(buffer, CharCode.e, 2);\n length = genExponent(buffer + 4, kk - 1);\n return length + 2;\n } else {\n let len = length << 1;\n memory.copy(\n buffer + 4,\n buffer + 2,\n len - 2\n );\n store(buffer, CharCode.DOT, 2);\n store(buffer + len, CharCode.e, 2);\n length += genExponent(buffer + len + 4, kk - 1);\n return length + 2;\n }\n}\n\nfunction dtoa_core(buffer: usize, value: f64): i32 {\n var sign = i32(value < 0);\n if (sign) {\n value = -value;\n store(buffer, CharCode.MINUS);\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\n// @ts-ignore: decorator\n@lazy @inline const dtoa_buf = memory.data(MAX_DOUBLE_LENGTH << 1);\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 size = dtoa_core(dtoa_buf, value) << 1;\n var result = changetype(__new(size, idof()));\n memory.copy(changetype(result), dtoa_buf, size);\n return result;\n}\n\nexport function itoa_buffered(buffer: usize, value: T): u32 {\n var sign: u32 = 0;\n if (isSigned()) {\n sign = u32(value < 0);\n if (sign) {\n if (sizeof() == 1) {\n if (value == -0x80) {\n // -0x80 -> -128\n store(buffer,\n CharCode.MINUS |\n (CharCode._0 + 1) << 16 |\n (CharCode._0 + 2) << 32 |\n (CharCode._0 + 8) << 48\n );\n return 4;\n }\n }\n if (sizeof() == 2) {\n if (value == -0x8000) {\n // -0x8000 -> -32768\n store(buffer,\n CharCode.MINUS |\n (CharCode._0 + 3) << 16 |\n (CharCode._0 + 2) << 32 |\n (CharCode._0 + 7) << 48\n ); // -327\n store(buffer + 8,\n (CharCode._0 + 6) << 0 |\n (CharCode._0 + 8) << 16\n ); // 68\n return 6;\n }\n }\n store(buffer, CharCode.MINUS);\n // @ts-ignore\n value = -value;\n }\n }\n var dest = buffer + (sign << 1);\n if (ASC_SHRINK_LEVEL <= 1) {\n if (isSigned()) {\n if (sizeof() <= 4) {\n if (value < 10) {\n store(dest, value | CharCode._0);\n return 1 + sign;\n }\n } else {\n if (value < 10) {\n store(dest, value | CharCode._0);\n return 1 + sign;\n }\n }\n } else {\n if (value < 10) {\n store(buffer, value | CharCode._0);\n return 1;\n }\n }\n }\n var decimals: u32 = 0;\n if (sizeof() <= 4) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_dec_core(dest, val32, decimals);\n } else {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_dec_core(dest, val32, decimals);\n } else {\n let val64 = value;\n decimals = decimalCount64High(val64);\n utoa64_dec_core(dest, val64, decimals);\n }\n }\n return sign + decimals;\n}\n\nexport function dtoa_buffered(buffer: usize, value: f64): u32 {\n if (value == 0) {\n store(buffer, CharCode._0);\n store(buffer, CharCode.DOT, 2);\n store(buffer, CharCode._0, 4);\n return 3;\n }\n if (!isFinite(value)) {\n if (isNaN(value)) {\n store(buffer, CharCode.N);\n store(buffer, CharCode.a, 2);\n store(buffer, CharCode.N, 4);\n return 3;\n } else {\n let sign = value < 0;\n if (sign) {\n store(buffer, CharCode.MINUS); // -\n buffer += 2;\n }\n store(buffer, 0x690066006E0049, 0); // ifnI\n store(buffer, 0x7900740069006E, 8); // ytin\n return 8 + u32(sign);\n }\n }\n return dtoa_core(buffer, value);\n}\n","import {\n itoa32,\n utoa32,\n itoa64,\n utoa64,\n dtoa,\n itoa_buffered,\n dtoa_buffered,\n MAX_DOUBLE_LENGTH\n} from \"./number\";\n\nimport {\n ipow32\n} from \"../math\";\n\n// All tables are stored as two staged lookup tables (static tries)\n// because the full range of Unicode symbols can't be efficiently\n// represented as-is in memory (see Unicode spec ch 5, p.196):\n// https://www.unicode.org/versions/Unicode12.0.0/ch05.pdf\n// Tables have been generated using these forked musl tools:\n// https://github.com/MaxGraey/musl-chartable-tools/tree/case-ignorable\n\n// Lookup table to check if a character is alphanumeric or not\n// See: https://git.musl-libc.org/cgit/musl/tree/src/ctype/alpha.h\n// size: 3904 bytes\n// @ts-ignore\n@inline @lazy const ALPHA_TABLE = memory.data([\n 18,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,17,34,35,36,17,37,38,39,40,\n 41,42,43,44,17,45,46,47,16,16,48,16,16,16,16,16,16,16,49,50,51,16,52,53,16,16,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,54,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,55,17,17,17,17,56,17,57,58,59,60,61,62,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67,\n 68,69,70,71,72,73,74,17,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,\n 93,94,16,95,96,97,98,17,17,17,99,100,101,16,16,16,16,16,16,16,16,16,16,17,17,\n 17,17,102,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,103,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,17,17,104,105,16,16,106,107,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,108,17,17,17,17,109,110,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 17,111,112,16,16,16,16,16,16,16,16,16,113,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,114,115,116,117,16,16,16,16,16,16,16,16,118,\n 119,120,16,16,16,16,16,121,122,16,16,16,16,123,16,16,124,16,16,16,16,16,16,16,\n 16,16,125,16,16,16,\n 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254,\n 255,255,7,0,0,0,0,0,4,32,4,255,255,127,255,255,255,127,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,188,64,215,255,255,\n 251,255,255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,3,252,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,254,255,255,255,127,2,255,255,255,\n 255,255,1,0,0,0,0,255,191,182,0,255,255,255,135,7,0,0,0,255,7,255,255,255,255,\n 255,255,255,254,255,195,255,255,255,255,255,255,255,255,255,255,255,255,239,\n 31,254,225,255,\n 159,0,0,255,255,255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255,\n 255,255,3,0,255,255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255,\n 1,255,7,0,0,0,0,0,0,255,255,223,255,255,0,240,255,248,3,255,255,255,255,255,\n 255,255,255,255,239,255,223,225,255,207,255,254,255,239,159,249,255,255,253,\n 197,227,159,89,128,176,207,255,3,16,238,135,249,255,255,253,109,195,135,25,2,\n 94,192,255,63,0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,30,238,\n 159,249,255,255,253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,\n 255,195,199,29,129,0,192,255,0,0,239,223,253,255,255,253,255,227,223,29,96,7,\n 207,255,0,0,239,223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,255,223,\n 253,255,255,255,255,231,223,93,240,128,207,255,0,252,238,255,127,252,255,255,\n 251,47,127,128,95,255,192,255,12,0,254,255,255,255,255,127,255,7,63,32,255,3,\n 0,0,0,0,214,247,255,255,175,255,255,59,95,32,255,243,0,0,0,\n 0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3,255,255,254,255,255,255,\n 31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249,255,3,255,255,255,255,255,\n 255,255,255,255,63,255,255,255,255,191,32,255,255,255,255,255,247,255,255,255,\n 255,255,255,255,255,255,61,127,61,255,255,255,255,255,61,255,255,255,255,61,\n 127,61,255,127,255,255,255,255,255,255,255,61,255,255,255,255,255,255,255,255,\n 7,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,63,63,254,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,159,255,255,254,255,255,7,255,255,255,255,255,255,255,255,\n 255,199,255,1,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255,\n 255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255,3,255,255,255,255,255,255,\n 255,255,255,255,255,1,255,255,255,255,255,7,255,255,255,255,255,255,255,255,\n 63,\n 0,255,255,255,127,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255,\n 255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255,\n 127,254,255,31,0,255,3,255,3,128,0,0,128,1,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255,\n 255,191,255,3,0,255,255,255,255,255,255,127,0,255,227,255,255,255,255,255,63,\n 255,1,255,255,255,255,255,231,0,0,0,0,0,222,111,4,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,\n 128,255,31,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,255,\n 255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243,\n 224,67,0,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,\n 0,255,255,255,255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255,\n 255,255,255,255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127,\n 255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,224,0,0,0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254,\n 255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,255,254,255,\n 255,255,255,255,255,255,255,255,255,127,0,0,255,255,255,255,0,0,0,0,0,0,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,\n 31,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255,\n 255,127,240,143,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,\n 0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,249,255,255,255,\n 255,255,255,252,7,0,0,0,0,224,255,191,255,255,255,255,0,0,0,255,255,255,255,\n 255,255,15,0,255,255,255,255,255,255,255,255,47,0,255,3,0,0,252,232,255,255,\n 255,255,255,7,255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247,\n 255,0,128,255,3,255,255,255,127,255,255,255,255,255,255,127,0,255,63,255,3,\n 255,255,127,252,255,255,255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126,\n 126,0,127,127,255,255,255,255,255,247,255,3,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255,255,\n 255,\n 15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127,95,219,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255,255,255,\n 252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,223,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,255,3,\n 254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255,255,127,\n 252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0,\n 0,255,255,255,255,0,224,255,255,255,7,255,255,255,255,255,7,255,255,255,63,\n 255,255,255,255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,255,3,255,255,255,255,15,255,255,255,\n 255,15,255,255,255,255,255,0,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,255,255,63,0,255,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191,145,255,255,63,0,255,255,\n 127,0,255,255,255,127,0,0,0,0,0,0,0,0,255,255,55,0,255,255,63,0,255,255,255,3,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240,239,\n 254,255,255,63,0,0,0,0,0,255,255,255,31,255,255,255,31,0,0,0,0,255,254,255,\n 255,31,0,0,0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,255,255,3,\n 0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,255,255,255,255,255,255,7,\n 0,255,255,255,255,255,255,7,0,255,255,255,255,255,0,255,3,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 255,27,3,0,0,0,0,0,0,0,0,0,255,255,255,31,128,0,255,255,63,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,31,0,0,0,255,255,127,0,255,255,255,255,255,255,255,255,63,0,0,\n 0,192,255,0,0,252,255,255,255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,\n 255,255,255,255,199,255,240,0,255,255,255,255,71,0,255,255,255,255,255,255,\n 255,255,30,192,255,23,0,0,0,0,255,255,251,255,255,255,159,64,0,0,0,0,0,0,0,0,\n 127,189,255,191,255,1,255,255,255,255,255,255,255,1,255,3,239,159,249,255,255,\n 253,237,227,159,25,129,224,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,187,7,255,131,3,0,0,0,255,255,255,255,255,\n 255,255,255,179,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 255,255,255,63,127,0,0,0,63,0,0,0,0,255,255,255,255,255,255,255,127,17,0,255,\n 3,0,0,0,0,255,255,255,255,255,255,63,1,255,3,0,0,0,0,0,0,255,255,255,231,255,\n 7,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,3,0,128,\n 127,242,111,255,255,255,191,153,7,0,255,3,0,0,0,0,0,0,0,0,255,252,255,255,255,\n 255,255,252,26,0,0,0,255,255,255,255,255,255,231,127,0,0,255,255,255,255,255,\n 255,255,255,255,32,0,0,0,0,255,255,255,255,255,255,255,1,255,253,255,255,255,\n 255,127,127,1,0,255,3,0,0,252,255,255,255,252,255,255,254,127,0,0,0,0,0,0,0,0,\n 0,127,251,255,255,255,255,127,180,203,0,255,3,191,253,255,255,255,127,123,1,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,127,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,\n 0,255,255,255,255,255,255,255,1,255,255,255,127,255,3,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,63,0,0,255,255,255,255,255,255,0,0,15,0,255,3,248,255,255,224,255,\n 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,\n 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,135,\n 255,255,255,255,255,255,255,128,255,255,0,0,0,0,0,0,0,0,11,0,3,0,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,0,0,\n 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 127,0,0,0,0,0,0,7,0,240,0,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,7,255,31,255,1,255,67,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,255,\n 223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,\n 255,123,95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,63,255,255,255,253,255,255,247,255,255,255,\n 247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,255,253,\n 255,255,255,253,255,255,247,207,255,255,255,255,255,255,127,255,255,249,219,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,31,\n 128,63,255,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,15,255,\n 3,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,31,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,143,8,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,239,255,255,255,150,254,247,10,\n 132,234,150,170,150,247,247,94,255,251,255,15,238,251,255,15,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,3\n]);\n\n// size: 1568 bytes (compressed to ~1380 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline const CASED = memory.data([\n 18,19,20,21,22,23,16,16,16,16,16,16,16,16,16,16,\n 24,16,16,25,16,16,16,16,16,16,16,16,26,27,17,28,\n 29,30,16,16,31,16,16,16,16,16,16,16,32,33,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,34,35,16,16,16,36,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,37,16,16,16,38,\n 16,16,16,16,39,16,16,16,16,16,16,16,40,16,16,16,\n 16,16,16,16,16,16,16,16,41,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,42,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,43,44,45,46,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,47,16,16,16,16,16,16,\n 16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,254,255,255,7,254,255,255,7,0,0,0,0,0,4,32,4,\n 255,255,127,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,247,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,239,255,255,255,255,1,3,0,0,0,31,0,0,0,\n 0,0,0,0,0,0,0,0,32,0,0,0,0,0,207,188,64,215,255,255,251,255,255,255,\n 255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 3,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,255,\n 255,255,127,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 191,32,255,255,255,255,255,231,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,255,255,255,255,255,255,63,63,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,1,255,255,255,255,255,231,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,\n 255,255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,\n 132,252,47,62,80,189,31,242,224,67,0,0,255,255,255,255,24,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,0,255,255,255,255,255,127,255,255,\n 255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,120,12,0,\n 255,255,255,255,191,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,63,0,0,\n 255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,255,255,\n 255,255,255,255,255,255,255,255,255,120,255,255,255,255,255,255,252,7,0,0,0,0,96,7,\n 0,0,0,0,0,0,255,255,255,255,255,247,255,1,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,127,0,248,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,7,\n 254,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,15,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,7,0,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,\n 255,255,255,223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,255,123,\n 95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,\n 253,255,255,247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,\n 255,253,255,255,255,253,255,255,247,15,0,0,0,0,0,0,255,255,255,255,255,255,255,255,\n 15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0\n]);\n\n// size: 2976 bytes (compressed to ~2050 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline const CASE_IGNORABLES = memory.data([\n 18,16,19,20,21,22,23,24,25,26,27,28,29,30,31,32,\n 33,16,16,34,16,16,16,35,36,37,38,39,40,41,16,42,\n 43,16,16,16,16,16,16,16,16,16,16,16,44,45,46,16,\n 47,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 48,16,16,16,49,16,50,51,52,53,54,55,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,56,16,16,57,58,\n 16,59,60,61,16,16,16,16,16,16,62,16,16,63,64,65,\n 66,67,68,69,70,71,72,73,74,75,76,16,77,78,79,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,80,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,81,82,16,16,16,83,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,84,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,85,86,16,16,16,16,16,16,16,87,16,16,16,16,16,\n 88,89,90,16,16,16,16,16,91,92,16,16,16,16,16,16,\n 16,16,16,93,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,128,64,0,4,0,0,0,64,1,0,0,0,0,0,0,0,0,161,144,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,48,4,176,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,130,0,0,0,0,\n 0,0,254,255,255,255,255,191,182,0,0,0,0,0,16,0,63,0,255,23,0,0,0,0,\n 1,248,255,255,0,0,1,0,0,0,0,0,0,0,0,0,0,0,192,191,255,61,0,0,\n 0,128,2,0,0,0,255,255,255,7,0,0,0,0,0,0,0,0,0,0,192,255,1,0,\n 0,0,0,0,0,248,63,36,0,0,192,255,255,63,0,0,0,0,0,14,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,248,255,255,255,255,255,7,0,0,0,0,0,0,20,\n 254,33,254,0,12,0,2,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0,64,\n 6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,\n 190,33,0,0,12,0,0,252,2,0,0,0,0,0,0,144,30,32,96,0,12,0,0,0,\n 4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,17,0,0,0,0,0,0,192,\n 193,61,96,0,12,0,0,0,2,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,\n 3,0,0,0,0,0,0,24,30,32,0,0,12,0,0,0,2,0,0,0,0,0,0,0,\n 0,4,92,0,0,0,0,0,0,0,0,0,0,0,242,7,192,127,0,0,0,0,0,0,\n 0,0,0,0,0,0,242,31,64,63,0,0,0,0,0,0,0,0,0,3,0,0,160,2,\n 0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,\n 0,0,0,0,0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,\n 0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,28,0,\n 0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,143,32,0,0,0,0,\n 0,120,0,0,0,0,0,0,8,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,\n 0,0,64,127,229,31,248,159,0,0,0,0,128,0,255,255,1,0,0,0,0,0,0,0,\n 15,0,0,0,0,0,208,23,4,0,0,0,0,248,15,0,3,0,0,0,60,59,0,0,\n 0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,0,0,0,63,\n 0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,240,255,255,\n 255,255,255,255,255,7,0,1,0,0,0,248,255,255,255,255,255,255,255,255,255,255,255,251,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,\n 3,224,0,224,0,224,0,96,0,248,0,3,144,124,0,0,0,0,0,0,223,255,2,128,\n 0,0,255,31,0,0,0,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,48,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,128,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,60,62,8,\n 0,0,0,0,0,0,0,0,0,0,0,126,0,0,0,0,0,0,0,0,0,0,0,112,\n 0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63,0,16,0,0,0,0,0,0,\n 0,0,0,0,0,128,247,191,0,0,0,240,0,0,0,0,0,0,0,0,0,0,3,0,\n 255,255,255,255,3,0,0,0,0,0,0,0,0,0,1,0,0,7,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,3,68,8,0,0,96,16,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,128,0,0,0,0,192,63,0,0,\n 128,255,3,0,0,0,0,0,7,0,0,0,0,0,200,51,0,128,0,0,96,0,0,0,\n 0,0,0,0,0,126,102,0,8,16,0,0,0,0,1,16,0,0,0,0,0,0,157,193,\n 2,0,0,32,0,48,88,0,0,0,0,0,0,0,0,0,0,0,0,248,0,14,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,\n 255,255,8,0,255,255,0,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,128,128,64,0,4,0,0,0,64,1,0,0,0,0,0,1,0,\n 0,0,0,192,0,0,0,0,0,0,0,0,8,0,0,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,110,240,0,0,0,0,0,135,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,\n 0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 192,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,\n 0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,\n 3,0,0,0,0,0,192,127,0,158,0,0,0,0,0,0,0,0,0,0,0,128,211,64,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,\n 3,0,0,0,0,0,0,24,1,0,0,0,192,31,31,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,\n 0,0,0,0,0,0,248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,\n 0,0,0,0,0,0,0,0,0,0,0,224,188,15,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,6,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,88,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,126,14,0,0,0,0,\n 0,252,127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,\n 0,0,0,0,0,0,0,0,0,0,252,255,255,252,109,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,126,180,191,0,0,0,0,0,0,0,0,0,163,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,255,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,15,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,128,0,0,0,0,0,0,0,128,255,255,0,0,0,0,0,0,0,0,27,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,\n 231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,\n 0,0,0,0,0,0,0,0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,63,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 240,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,248\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOWER127 = memory.data([\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 91,92,93,94,95,96,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 123,124,125,126,127\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const UPPER127 = memory.data([\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 91,92,93,94,95,96,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 123,124,125,126,127\n]);\n\n// 23 * 8 = 184 bytes\n// @ts-ignore: decorator\n@lazy @inline const POWERS10 = memory.data([\n 1e00, 1e01, 1e02, 1e03, 1e04, 1e05, 1e06, 1e07, 1e08, 1e09,\n 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,\n 1e20, 1e21, 1e22\n]);\n\n// @ts-ignore: decorator\n@inline\nexport const enum CharCode {\n PERCENT = 0x25,\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 I = 0x49,\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 u = 0x75,\n x = 0x78,\n z = 0x7A\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isAscii(c: u32): bool {\n return !(c >> 7);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isLower8(c: u32): bool {\n return c - CharCode.a < 26;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isUpper8(c: u32): bool {\n return c - CharCode.A < 26;\n}\n\nexport function isSpace(c: u32): bool {\n if (c < 0x1680) { // < (1)\n // , , , , , and \n // (c == 0x20 || c == 0xA0) was optimized to (c | 0x80) == 0xA0\n return ((c | 0x80) == 0xA0) || (c - 0x09 <= 0x0D - 0x09);\n }\n if (c - 0x2000 <= 0x200A - 0x2000) return true;\n switch (c) {\n case 0x1680: // (1)\n case 0x2028: // (2)\n case 0x2029: // \n case 0x202F: // \n case 0x205F: // \n case 0x3000: // \n case 0xFEFF: return true; // \n }\n return false;\n}\n\nexport function isAlpha(c: u32): bool {\n if (isAscii(c)) return (c | 32) - CharCode.a < 26;\n if (c < 0x20000) {\n // @ts-ignore: cast\n return stagedBinaryLookup(ALPHA_TABLE, c);\n }\n return c < 0x2FFFE;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCased(c: u32): bool {\n // @ts-ignore: cast\n return c < 0x1F18A && stagedBinaryLookup(CASED, c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCaseIgnorable(c: u32): bool {\n // @ts-ignore: cast\n return c < 0xE01F0 && stagedBinaryLookup(CASE_IGNORABLES, c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isFinalSigma(buffer: usize, index: isize, len: isize): bool {\n const lookaheadLimit = 30; // max lookahead limit\n var found = false;\n var pos = index;\n var minPos = max(0, pos - lookaheadLimit);\n while (pos > minPos) {\n let c = codePointBefore(buffer, pos);\n if (!isCaseIgnorable(c)) {\n if (isCased(c)) {\n found = true;\n } else {\n return false;\n }\n }\n pos -= isize(c >= 0x10000) + 1;\n }\n if (!found) return false;\n pos = index + 1;\n var maxPos = min(pos + lookaheadLimit, len);\n while (pos < maxPos) {\n let c = load(buffer + (pos << 1));\n if (u32((c & 0xFC00) == 0xD800) & u32(pos + 1 != len)) {\n let c1 = load(buffer + (pos << 1), 2);\n if ((c1 & 0xFC00) == 0xDC00) {\n c = (c - 0xD800 << 10) + (c1 - 0xDC00) + 0x10000;\n }\n }\n if (!isCaseIgnorable(c)) {\n return !isCased(c);\n }\n pos += isize(c >= 0x10000) + 1;\n }\n return true;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction codePointBefore(buffer: usize, index: isize): i32 {\n if (index <= 0) return -1;\n var c = load(buffer + (index - 1 << 1));\n if (u32((c & 0xFC00) == 0xDC00) & u32(index - 2 >= 0)) {\n let c1 = load(buffer + (index - 2 << 1));\n if ((c1 & 0xFC00) == 0xD800) {\n return ((c1 & 0x3FF) << 10) + (c & 0x3FF) + 0x10000;\n }\n }\n return (c & 0xF800) == 0xD800 ? 0xFFFD : c;\n}\n\n// Search routine for two-staged lookup tables\nfunction stagedBinaryLookup(table: usize, c: u32): bool {\n return ((load(table + (load(table + (c >>> 8)) << 5) + ((c & 255) >> 3)) >>> (c & 7)) & 1);\n}\n\nexport function compareImpl(str1: string, index1: usize, str2: string, index2: usize, len: usize): i32 {\n var ptr1 = changetype(str1) + (index1 << 1);\n var ptr2 = changetype(str2) + (index2 << 1);\n if (ASC_SHRINK_LEVEL < 2) {\n if (len >= 4 && !((ptr1 & 7) | (ptr2 & 7))) {\n do {\n if (load(ptr1) != load(ptr2)) break;\n ptr1 += 8;\n ptr2 += 8;\n len -= 4;\n } while (len >= 4);\n }\n }\n while (len--) {\n let a = load(ptr1);\n let b = load(ptr2);\n if (a != b) return a - b;\n ptr1 += 2;\n ptr2 += 2;\n }\n return 0;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toLower8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c | u32(isUpper8(c)) << 5;\n } else {\n return load(LOWER127 + c);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toUpper8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c & ~(u32(isLower8(c)) << 5);\n } else {\n return load(UPPER127 + c);\n }\n}\n\n/** Parses a string to an integer (usually), using the specified radix. */\nexport function strtol(str: string, radix: i32 = 0): T {\n var len = str.length;\n if (!len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n\n var ptr = changetype(str) /* + HEAD -> offset */;\n var code = load(ptr);\n\n // trim white spaces\n while (isSpace(code)) {\n code = load(ptr += 2);\n --len;\n }\n // determine sign\n // @ts-ignore\n var sign: T = 1;\n if (code == CharCode.MINUS || code == CharCode.PLUS) {\n if (!--len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n if (code == CharCode.MINUS) {\n // @ts-ignore: type\n sign = -1;\n }\n code = load(ptr += 2);\n }\n\n // See https://tc39.es/ecma262/#sec-parseint-string-radix\n if (radix) {\n if (radix < 2 || radix > 36) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n // handle case as parseInt(\"0xFF\", 16) by spec\n if (radix == 16) {\n if (\n len > 2 &&\n code == CharCode._0 &&\n (load(ptr, 2) | 32) == CharCode.x\n ) {\n ptr += 4; len -= 2;\n }\n }\n } else {\n // determine radix by literal prefix\n if (code == CharCode._0 && len > 2) {\n switch (load(ptr, 2) | 32) {\n case CharCode.b: {\n ptr += 4; len -= 2;\n radix = 2;\n break;\n }\n case CharCode.o: {\n ptr += 4; len -= 2;\n radix = 8;\n break;\n }\n case CharCode.x: {\n ptr += 4; len -= 2;\n radix = 16;\n break;\n }\n }\n }\n if (!radix) radix = 10;\n }\n\n // calculate value\n // @ts-ignore: type\n var num: T = 0;\n var initial = len - 1;\n while (len--) {\n code = load(ptr);\n if (code - CharCode._0 < 10) {\n code -= CharCode._0;\n } else if (code - CharCode.A <= (CharCode.Z - CharCode.A)) {\n code -= CharCode.A - 10;\n } else if (code - CharCode.a <= (CharCode.z - CharCode.a)) {\n code -= CharCode.a - 10;\n }\n if (code >= radix) {\n if (initial == len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n break;\n }\n // @ts-ignore: type\n num = num * radix + code;\n ptr += 2;\n }\n // @ts-ignore: type\n return sign * num;\n}\n\nexport function strtod(str: string): f64 {\n var len = str.length;\n if (!len) return NaN;\n\n var ptr = changetype(str);\n var code = load(ptr);\n\n var sign = 1.0;\n // skip white spaces\n while (len && isSpace(code)) {\n code = load(ptr += 2);\n --len;\n }\n if (!len) return NaN;\n\n // try parse '-' or '+'\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = load(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = load(ptr += 2);\n }\n\n // try parse Infinity\n if (len >= 8 && code == CharCode.I) {\n if (\n load(ptr, 0) == 0x690066006E0049 && // ifnI\n load(ptr, 8) == 0x7900740069006E // ytin\n ) {\n return Infinity * sign;\n }\n return NaN;\n }\n // validate next symbol\n if (code != CharCode.DOT && (code - CharCode._0) >= 10) {\n return NaN;\n }\n var savedPtr = ptr;\n // skip zeros\n while (code == CharCode._0) {\n code = load(ptr += 2);\n --len;\n }\n if (len <= 0) return 0;\n const capacity = 19; // int(64 * 0.3010)\n var pointed = false;\n var consumed = 0;\n var position = 0;\n var x: u64 = 0;\n if (code == CharCode.DOT) {\n let noDigits = !(savedPtr - ptr);\n ptr += 2; --len;\n if (!len && noDigits) return NaN;\n for (pointed = true; (code = load(ptr)) == CharCode._0; --position, ptr += 2) --len;\n if (len <= 0) return 0;\n if (!position && noDigits && code - CharCode._0 >= 10) return NaN;\n }\n for (let digit = code - CharCode._0; digit < 10 || (code == CharCode.DOT && !pointed); digit = code - CharCode._0) {\n if (digit < 10) {\n x = consumed < capacity ? 10 * x + digit : x | u64(!!digit);\n ++consumed;\n } else {\n position = consumed;\n pointed = true;\n }\n if (!--len) break;\n code = load(ptr += 2);\n }\n\n if (!pointed) position = consumed;\n return copysign(scientific(x, position - min(capacity, consumed) + parseExp(ptr, len)), sign);\n}\n\nexport function strtob(str: string): bool {\n var size: usize = str.length << 1;\n var offset: usize = 0;\n if (size > 8) {\n // try trim end whitespaces first\n while (size && isSpace(load(changetype(str) + size - 2))) size -= 2;\n if (size > 8) {\n // trim start whitespaces\n while (offset < size && isSpace(load(changetype(str) + offset))) offset += 2;\n size -= offset;\n }\n }\n if (size != 8) return false;\n // \"true\" represents as \\00\\e\\00\\u\\00\\e\\00\\t (00 65 00 75 00 72 00 74)\n return load(changetype(str) + offset) == 0x0065_0075_0072_0074;\n}\n\nexport function joinBooleanArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) return select(\"true\", \"false\", load(dataStart));\n\n var sepLen = separator.length;\n var valueLen = 5; // max possible length of element len(\"false\")\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype(__new(estLen << 1, idof()));\n var offset = 0;\n var value: bool;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + i);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + lastIndex);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinIntegerArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n let value = load(dataStart);\n if (isSigned()) {\n if (sizeof() <= 4) {\n // @ts-ignore: type\n return changetype(itoa32(value, 10));\n } else {\n // @ts-ignore: type\n return changetype(itoa64(value, 10));\n }\n } else {\n if (sizeof() <= 4) {\n // @ts-ignore: type\n return changetype(utoa32(value, 10));\n } else {\n // @ts-ignore: type\n return changetype(utoa64(value, 10));\n }\n }\n }\n\n var sepLen = separator.length;\n const valueLen = (sizeof() <= 4 ? 10 : 20) + i32(isSigned());\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype(__new(estLen << 1, idof()));\n var offset = 0;\n var value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n offset += itoa_buffered(changetype(result) + (offset << 1), value);\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n offset += itoa_buffered(changetype(result) + (offset << 1), value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinFloatArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n return changetype(dtoa(\n // @ts-ignore: type\n load(dataStart))\n );\n }\n\n const valueLen = MAX_DOUBLE_LENGTH;\n var sepLen = separator.length;\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype(__new(estLen << 1, idof()));\n var offset = 0;\n var value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n offset += dtoa_buffered(changetype(result) + (offset << 1), value);\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n offset += dtoa_buffered(changetype(result) + (offset << 1), value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinStringArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n // @ts-ignore: type\n return load(dataStart) || \"\";\n }\n var estLen = 0;\n var value: string;\n for (let i = 0; i < length; ++i) {\n value = load(dataStart + (i << alignof()));\n if (changetype(value) != 0) estLen += value.length;\n }\n var offset = 0;\n var sepLen = separator.length;\n var result = changetype(__new((estLen + sepLen * lastIndex) << 1, idof()));\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n if (changetype(value) != 0) {\n let valueLen = value.length;\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(value),\n valueLen << 1\n );\n offset += valueLen;\n }\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n if (changetype(value) != 0) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(value),\n value.length << 1\n );\n }\n return result;\n}\n\nexport function joinReferenceArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n var value: T;\n if (!lastIndex) {\n value = load(dataStart);\n // @ts-ignore: type\n return value != null ? value.toString() : \"\";\n }\n var result = \"\";\n var sepLen = separator.length;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n if (value != null) result += value.toString();\n if (sepLen) result += separator;\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n if (value != null) result += value.toString();\n return result;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction scientific(significand: u64, exp: i32): f64 {\n if (!significand || exp < -342) return 0;\n if (exp > 308) return Infinity;\n // Try use fast path\n // Use fast path for string-to-double conversion if possible\n // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion\n // Simple integer\n var significandf = significand;\n if (!exp) return significandf;\n if (exp > 22 && exp <= 22 + 15) {\n significandf *= pow10(exp - 22);\n exp = 22;\n }\n if (significand <= 9007199254740991 && abs(exp) <= 22) {\n if (exp > 0) return significandf * pow10(exp);\n return significandf / pow10(-exp);\n } else if (exp < 0) {\n return scaledown(significand, exp);\n } else {\n return scaleup(significand, exp);\n }\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaledown(significand: u64, exp: i32): f64 {\n const denom: u64 = 6103515625; // 1e14 * 0x1p-14\n const scale = reinterpret(0x3F06849B86A12B9B); // 1e-14 * 0x1p32\n\n var shift = clz(significand);\n significand <<= shift;\n shift = exp - shift;\n\n for (; exp <= -14; exp += 14) {\n let q = significand / denom;\n let r = significand % denom;\n let s = clz(q);\n significand = (q << s) + nearest(scale * (r << (s - 18)));\n shift -= s;\n }\n var b = ipow32(5, -exp);\n var q = significand / b;\n var r = significand % b;\n var s = clz(q);\n significand = (q << s) + (reinterpret(reinterpret(r) + (s << 52)) / b);\n shift -= s;\n\n return NativeMath.scalbn(significand, shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaleup(significand: u64, exp: i32): f64 {\n const coeff: u32 = 1220703125; // 1e13 * 0x1p-13;\n var shift = ctz(significand);\n significand >>= shift;\n shift += exp;\n\n __fixmulShift = shift;\n for (; exp >= 13; exp -= 13) {\n significand = fixmul(significand, coeff);\n }\n significand = fixmul(significand, ipow32(5, exp));\n shift = __fixmulShift;\n return NativeMath.scalbn(significand, shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction parseExp(ptr: usize, len: i32): i32 {\n var sign = 1, magnitude = 0;\n var code = load(ptr);\n // check code is 'e' or 'E'\n if ((code | 32) != CharCode.e) return 0;\n\n if (!--len) return 0;\n code = load(ptr += 2);\n if (code == CharCode.MINUS) {\n if (!--len) return 0;\n code = load(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return 0;\n code = load(ptr += 2);\n }\n // skip zeros\n while (code == CharCode._0) {\n if (!--len) return 0;\n code = load(ptr += 2);\n }\n for (let digit: u32 = code - CharCode._0; len && digit < 10; digit = code - CharCode._0) {\n if (magnitude >= 3200) return sign * 3200;\n magnitude = 10 * magnitude + digit;\n code = load(ptr += 2);\n --len;\n }\n return sign * magnitude;\n}\n\n// @ts-ignore: decorator\n@lazy var __fixmulShift: u64 = 0;\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction fixmul(a: u64, b: u32): u64 {\n var low = (a & 0xFFFFFFFF) * b;\n var high = (a >> 32) * b + (low >> 32);\n var overflow = (high >> 32);\n var space = clz(overflow);\n var revspace: u64 = 32 - space;\n __fixmulShift += revspace;\n return (high << space | (low & 0xFFFFFFFF) >> revspace) + (low << space >> 31 & 1);\n}\n\n// @ts-ignore: decorator\n@inline\nfunction pow10(n: i32): f64 {\n // argument `n` should bounds in [0, 22] range\n return load(POWERS10 + (n << alignof()));\n}\n","import { Math as JSMath } from \"./bindings/dom\";\nexport { JSMath };\n\nimport {\n pow_lut, exp_lut, exp2_lut, log_lut, log2_lut,\n powf_lut, expf_lut, exp2f_lut, logf_lut, log2f_lut\n} from \"./util/math\";\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/** @internal */\n// @ts-ignore: decorator\n@lazy var rempio2_y0: f64, rempio2_y1: f64, res128_hi: u64;\n\n/** @internal */\n// @ts-ignore: decorator\n@lazy @inline const PIO2_TABLE = memory.data([\n 0x00000000A2F9836E, 0x4E441529FC2757D1, 0xF534DDC0DB629599, 0x3C439041FE5163AB,\n 0xDEBBC561B7246E3A, 0x424DD2E006492EEA, 0x09D1921CFE1DEB1C, 0xB129A73EE88235F5,\n 0x2EBB4484E99C7026, 0xB45F7E413991D639, 0x835339F49C845F8B, 0xBDF9283B1FF897FF,\n 0xDE05980FEF2F118B, 0x5A0A6D1F6D367ECF, 0x27CB09B74F463F66, 0x9E5FEA2D7527BAC7,\n 0xEBE5F17B3D0739F7, 0x8A5292EA6BFB5FB1, 0x1F8D5D0856033046, 0xFC7B6BABF0CFBC20,\n 0x9AF4361DA9E39161, 0x5EE61B086599855F, 0x14A068408DFFD880, 0x4D73273106061557\n]);\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\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/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction expo2(x: f64, sign: 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 // in directed rounding correct sign before rounding or overflow is important\n return NativeMath.exp(x - kln2) * (sign * scale) * scale;\n}\n\n/** @internal */\n/* Helper function to eventually get bits of π/2 * |x|\n *\n * y = π/4 * (frac << clz(frac) >> 11)\n * return clz(frac)\n *\n * Right shift 11 bits to make upper half fit in `double`\n */\n// @ts-ignore: decorator\n@inline\nfunction pio2_right(q0: u64, q1: u64): u64 { // see: jdh8/metallic/blob/master/src/math/double/rem_pio2.c\n // Bits of π/4\n const p0: u64 = 0xC4C6628B80DC1CD1;\n const p1: u64 = 0xC90FDAA22168C234;\n\n const Ox1p_64 = reinterpret(0x3BF0000000000000); // 0x1p-64\n const Ox1p_75 = reinterpret(0x3B40000000000000); // 0x1p-75\n\n var shift = clz(q1);\n\n q1 = q1 << shift | q0 >> (64 - shift);\n q0 <<= shift;\n\n var lo = umuldi(p1, q1);\n var hi = res128_hi;\n\n var ahi = hi >> 11;\n var alo = lo >> 11 | hi << 53;\n var blo = (Ox1p_75 * p0 * q1 + Ox1p_75 * p1 * q0);\n\n rempio2_y0 = (ahi + u64(lo < blo));\n rempio2_y1 = Ox1p_64 * (alo + blo);\n\n return shift;\n}\n\n/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction umuldi(u: u64, v: u64): u64 {\n var u1: u64 , v1: u64, w0: u64, w1: u64, t: u64;\n\n u1 = u & 0xFFFFFFFF;\n v1 = v & 0xFFFFFFFF;\n\n u >>= 32;\n v >>= 32;\n\n t = u1 * v1;\n w0 = t & 0xFFFFFFFF;\n t = u * v1 + (t >> 32);\n w1 = t >> 32;\n t = u1 * v + (t & 0xFFFFFFFF);\n\n res128_hi = u * v + w1 + (t >> 32);\n return (t << 32) + w0;\n}\n\n/** @internal */\nfunction pio2_large_quot(x: f64, u: i64): i32 { // see: jdh8/metallic/blob/master/src/math/double/rem_pio2.c\n var magnitude = u & 0x7FFFFFFFFFFFFFFF;\n var offset = (magnitude >> 52) - 1045;\n var shift = offset & 63;\n var tblPtr = PIO2_TABLE + ((offset >> 6) << 3);\n var s0: u64, s1: u64, s2: u64;\n\n var b0 = load(tblPtr, 0 << 3);\n var b1 = load(tblPtr, 1 << 3);\n var b2 = load(tblPtr, 2 << 3);\n\n // Get 192 bits of 0x1p-31 / π with `offset` bits skipped\n if (shift) {\n let rshift = 64 - shift;\n let b3 = load(tblPtr, 3 << 3);\n s0 = b1 >> rshift | b0 << shift;\n s1 = b2 >> rshift | b1 << shift;\n s2 = b3 >> rshift | b2 << shift;\n } else {\n s0 = b0;\n s1 = b1;\n s2 = b2;\n }\n\n var significand = (u & 0x000FFFFFFFFFFFFF) | 0x0010000000000000;\n\n // First 128 bits of fractional part of x/(2π)\n var blo = umuldi(s1, significand);\n var bhi = res128_hi;\n\n var ahi = s0 * significand;\n var clo = (s2 >> 32) * (significand >> 32);\n var plo = blo + clo;\n var phi = ahi + bhi + u64(plo < clo);\n\n // r: u128 = p << 2\n var rlo = plo << 2;\n var rhi = phi << 2 | plo >> 62;\n\n // s: i128 = r >> 127\n var slo = rhi >> 63;\n var shi = slo >> 1;\n var q = (phi >> 62) - slo;\n\n var shifter = 0x3CB0000000000000 - (pio2_right(rlo ^ slo, rhi ^ shi) << 52);\n var signbit = (u ^ rhi) & 0x8000000000000000;\n var coeff = reinterpret(shifter | signbit);\n\n rempio2_y0 *= coeff;\n rempio2_y1 *= coeff;\n\n return q;\n}\n\n/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction rempio2(x: f64, u: u64, sign: i32): i32 {\n const\n pio2_1 = reinterpret(0x3FF921FB54400000), // 1.57079632673412561417e+00\n pio2_1t = reinterpret(0x3DD0B4611A626331), // 6.07710050650619224932e-11\n pio2_2 = reinterpret(0x3DD0B4611A600000), // 6.07710050630396597660e-11\n pio2_2t = reinterpret(0x3BA3198A2E037073), // 2.02226624879595063154e-21\n pio2_3 = reinterpret(0x3BA3198A2E000000), // 2.02226624871116645580e-21\n pio2_3t = reinterpret(0x397B839A252049C1), // 8.47842766036889956997e-32\n invpio2 = reinterpret(0x3FE45F306DC9C883); // 0.63661977236758134308\n\n var ix = (u >> 32) & 0x7FFFFFFF;\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (ix < 0x4002D97C) { // |x| < 3pi/4, special case with n=+-1\n let q = 1, z: f64, y0: f64, y1: f64;\n if (!sign) {\n z = x - pio2_1;\n if (ix != 0x3FF921FB) { // 33+53 bit pi is good enough\n y0 = z - pio2_1t;\n y1 = (z - y0) - pio2_1t;\n } else { // near pi/2, use 33+33+53 bit pi\n z -= pio2_2;\n y0 = z - pio2_2t;\n y1 = (z - y0) - pio2_2t;\n }\n } else { // negative x\n z = x + pio2_1;\n if (ix != 0x3FF921FB) { // 33+53 bit pi is good enough\n y0 = z + pio2_1t;\n y1 = (z - y0) + pio2_1t;\n } else { // near pi/2, use 33+33+53 bit pi\n z += pio2_2;\n y0 = z + pio2_2t;\n y1 = (z - y0) + pio2_2t;\n }\n q = -1;\n }\n rempio2_y0 = y0;\n rempio2_y1 = y1;\n return q;\n }\n }\n\n if (ix < 0x413921FB) { // |x| ~< 2^20*pi/2 (1647099)\n // Use precise Cody Waite scheme\n let q = nearest(x * invpio2);\n let r = x - q * pio2_1;\n let w = q * pio2_1t; // 1st round good to 85 bit\n let j = ix >> 20;\n let y0 = r - w;\n let hi = (reinterpret(y0) >> 32);\n let i = j - ((hi >> 20) & 0x7FF);\n\n if (i > 16) { // 2nd iteration needed, good to 118\n let t = r;\n w = q * pio2_2;\n r = t - w;\n w = q * pio2_2t - ((t - r) - w);\n y0 = r - w;\n hi = (reinterpret(y0) >> 32);\n i = j - ((hi >> 20) & 0x7FF);\n if (i > 49) { // 3rd iteration need, 151 bits acc\n let t = r;\n w = q * pio2_3;\n r = t - w;\n w = q * pio2_3t - ((t - r) - w);\n y0 = r - w;\n }\n }\n let y1 = (r - y0) - w;\n rempio2_y0 = y0;\n rempio2_y1 = y1;\n return q;\n }\n var q = pio2_large_quot(x, u);\n return select(-q, q, sign);\n}\n\n/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction sin_kern(x: f64, y: f64, iy: i32): f64 { // see: musl/tree/src/math/__sin.c\n const\n S1 = reinterpret(0xBFC5555555555549), // -1.66666666666666324348e-01\n S2 = reinterpret(0x3F8111111110F8A6), // 8.33333333332248946124e-03\n S3 = reinterpret(0xBF2A01A019C161D5), // -1.98412698298579493134e-04\n S4 = reinterpret(0x3EC71DE357B1FE7D), // 2.75573137070700676789e-06\n S5 = reinterpret(0xBE5AE5E68A2B9CEB), // -2.50507602534068634195e-08\n S6 = reinterpret(0x3DE5D93A5ACFD57C); // 1.58969099521155010221e-10\n\n var z = x * x;\n var w = z * z;\n var r = S2 + z * (S3 + z * S4) + z * w * (S5 + z * S6);\n var v = z * x;\n if (!iy) {\n return x + v * (S1 + z * r);\n } else {\n return x - ((z * (0.5 * y - v * r) - y) - v * S1);\n }\n}\n\n/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction cos_kern(x: f64, y: f64): f64 { // see: musl/tree/src/math/__cos.c\n const\n C1 = reinterpret(0x3FA555555555554C), // 4.16666666666666019037e-02\n C2 = reinterpret(0xBF56C16C16C15177), // -1.38888888888741095749e-03\n C3 = reinterpret(0x3EFA01A019CB1590), // 2.48015872894767294178e-05\n C4 = reinterpret(0xBE927E4F809C52AD), // -2.75573143513906633035e-07\n C5 = reinterpret(0x3E21EE9EBDB4B1C4), // 2.08757232129817482790e-09\n C6 = reinterpret(0xBDA8FAE9BE8838D4); // -1.13596475577881948265e-11\n\n var z = x * x;\n var w = z * z;\n var r = z * (C1 + z * (C2 + z * C3)) + w * w * (C4 + z * (C5 + z * C6));\n var hz = 0.5 * z;\n w = 1.0 - hz;\n return w + (((1.0 - w) - hz) + (z * r - x * y));\n}\n\n/** @internal */\nfunction tan_kern(x: f64, y: f64, iy: i32): f64 { // see: src/lib/msun/src/k_tan.c\n const\n T0 = reinterpret(0x3FD5555555555563), // 3.33333333333334091986e-01\n T1 = reinterpret(0x3FC111111110FE7A), // 1.33333333333201242699e-01\n T2 = reinterpret(0x3FABA1BA1BB341FE), // 5.39682539762260521377e-02\n T3 = reinterpret(0x3F9664F48406D637), // 2.18694882948595424599e-02\n T4 = reinterpret(0x3F8226E3E96E8493), // 8.86323982359930005737e-03\n T5 = reinterpret(0x3F6D6D22C9560328), // 3.59207910759131235356e-03\n T6 = reinterpret(0x3F57DBC8FEE08315), // 1.45620945432529025516e-03\n T7 = reinterpret(0x3F4344D8F2F26501), // 5.88041240820264096874e-04\n T8 = reinterpret(0x3F3026F71A8D1068), // 2.46463134818469906812e-04\n T9 = reinterpret(0x3F147E88A03792A6), // 7.81794442939557092300e-05\n T10 = reinterpret(0x3F12B80F32F0A7E9), // 7.14072491382608190305e-05\n T11 = reinterpret(0xBEF375CBDB605373), // -1.85586374855275456654e-05\n T12 = reinterpret(0x3EFB2A7074BF7AD4); // 2.59073051863633712884e-05\n\n const\n one = reinterpret(0x3FF0000000000000), // 1.00000000000000000000e+00\n pio4 = reinterpret(0x3FE921FB54442D18), // 7.85398163397448278999e-01\n pio4lo = reinterpret(0x3C81A62633145C07); // 3.06161699786838301793e-17\n\n var z: f64, r: f64, v: f64, w: f64, s: f64;\n var hx = (reinterpret(x) >> 32); // high word of x\n var ix = hx & 0x7FFFFFFF; // high word of |x|\n var big = ix >= 0x3FE59428;\n if (big) { // |x| >= 0.6744\n if (hx < 0) { x = -x, y = -y; }\n z = pio4 - x;\n w = pio4lo - y;\n x = z + w;\n y = 0.0;\n }\n z = x * x;\n w = z * z;\n r = T1 + w * (T3 + w * (T5 + w * (T7 + w * (T9 + w * T11))));\n v = z * (T2 + w * (T4 + w * (T6 + w * (T8 + w * (T10 + w * T12)))));\n s = z * x;\n r = y + z * (s * (r + v) + y);\n r += T0 * s;\n w = x + r;\n if (big) {\n v = iy;\n return (1 - ((hx >> 30) & 2)) * (v - 2.0 * (x - (w * w / (w + v) - r)));\n }\n if (iy == 1) return w;\n var a: f64, t: f64;\n z = w;\n z = reinterpret(reinterpret(z) & 0xFFFFFFFF00000000);\n v = r - (z - x); // z + v = r + x\n t = a = -one / w; // a = -1.0 / w\n t = reinterpret(reinterpret(t) & 0xFFFFFFFF00000000);\n s = one + t * z;\n return t + a * (s + t * v);\n}\n\n/** @internal */\nfunction dtoi32(x: f64): i32 {\n if (ASC_SHRINK_LEVEL > 0) {\n const inv32 = 1.0 / 4294967296;\n return (x - 4294967296 * floor(x * inv32));\n } else {\n let result = 0;\n let u = reinterpret(x);\n let e = (u >> 52) & 0x7FF;\n if (e <= 1023 + 30) {\n result = x;\n } else if (e <= 1023 + 30 + 53) {\n let v = (u & ((1 << 52) - 1)) | (1 << 52);\n v = v << e - 1023 - 52 + 32;\n result = (v >> 32);\n result = select(-result, result, u < 0);\n }\n return result;\n }\n}\n\n// @ts-ignore: decorator\n@lazy var random_seeded = false;\n\n// @ts-ignore: decorator\n@lazy var random_state0_64: u64, random_state1_64: u64;\n\n// @ts-ignore: decorator\n@lazy var random_state0_32: u32, random_state1_32: u32;\n\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\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 // @ts-ignore: decorator\n @lazy\n export const E = reinterpret(0x4005BF0A8B145769); // 2.7182818284590452354\n\n // @ts-ignore: decorator\n @lazy\n export const LN2 = reinterpret(0x3FE62E42FEFA39EF); // 0.69314718055994530942\n\n // @ts-ignore: decorator\n @lazy\n export const LN10 = reinterpret(0x40026BB1BBB55516); // 2.30258509299404568402\n\n // @ts-ignore: decorator\n @lazy\n export const LOG2E = reinterpret(0x3FF71547652B82FE); // 1.4426950408889634074\n\n // @ts-ignore: decorator\n @lazy\n export const LOG10E = reinterpret(0x3FDBCB7B1526E50E); // 0.43429448190325182765\n\n // @ts-ignore: decorator\n @lazy\n export const PI = reinterpret(0x400921FB54442D18); // 3.14159265358979323846\n\n // @ts-ignore: decorator\n @lazy\n export const SQRT1_2 = reinterpret(0x3FE6A09E667F3BCD); // 0.70710678118654752440\n\n // @ts-ignore: decorator\n @lazy\n export const SQRT2 = reinterpret(0x3FF6A09E667F3BCD); // 1.41421356237309504880\n\n // @ts-ignore: decorator\n @lazy\n export var sincos_sin: f64 = 0;\n\n // @ts-ignore: decorator\n @lazy\n export var sincos_cos: f64 = 0;\n\n // @ts-ignore: decorator\n @inline 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\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 < 0) 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 < 0) {\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 u = reinterpret(x);\n // Prevent propagation for all input values less than 1.0.\n // Note musl lib didn't fix this yet.\n if (u < 0x3FF0000000000000) return (x - x) / 0.0;\n var e = u >> 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\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 return select(-x, x, hx < 0);\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\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 y = builtin_abs(x);\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 let t = m & 2 ? 3 * PI / 4 : PI / 4;\n return m & 1 ? -t : t;\n } else {\n let t = m & 2 ? PI : 0;\n return m & 1 ? -t : t;\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); // 0x1p54\n\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 r = (r - t) / (2 * t + r);\n t = t + t * r;\n return t;\n }\n\n // @ts-ignore: decorator\n @inline\n export function ceil(x: f64): f64 {\n return builtin_ceil(x);\n }\n\n export function clz32(x: f64): f64 {\n if (!isFinite(x)) return 32;\n /*\n * Wasm (MVP) and JS have different approaches for double->int conversions.\n *\n * For emulate JS conversion behavior and avoid trapping from wasm we should modulate by MAX_INT\n * our float-point arguments before actual convertion to integers.\n */\n return builtin_clz(dtoi32(x));\n }\n\n export function cos(x: f64): f64 { // see: musl/src/math/cos.c\n var u = reinterpret(x);\n var ux = u32(u >> 32);\n var sign = ux >> 31;\n\n ux &= 0x7FFFFFFF;\n\n // |x| ~< pi/4\n if (ux <= 0x3FE921FB) {\n if (ux < 0x3E46A09E) { // |x| < 2**-27 * sqrt(2)\n return 1.0;\n }\n return cos_kern(x, 0);\n }\n\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7FF00000) return x - x;\n\n // argument reduction needed\n var n = rempio2(x, u, sign);\n var y0 = rempio2_y0;\n var y1 = rempio2_y1;\n\n x = n & 1 ? sin_kern(y0, y1, 1) : cos_kern(y0, y1);\n return (n + 1) & 2 ? -x : x;\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, 1);\n return t;\n }\n\n export function exp(x: f64): f64 { // see: musl/src/math/exp.c and SUN COPYRIGHT NOTICE above\n if (ASC_SHRINK_LEVEL < 1) {\n return exp_lut(x);\n } else {\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); // 0x1p1023\n\n let hx = u32(reinterpret(x) >> 32);\n let sign = hx >> 31;\n hx &= 0x7FFFFFFF;\n if (hx >= 0x4086232B) {\n if (isNaN(x)) return x;\n if (x > overflow) return x * Ox1p1023;\n if (x < underflow) return 0;\n }\n let hi: f64, lo: f64 = 0;\n let k = 0;\n if (hx > 0x3FD62E42) {\n if (hx >= 0x3FF0A2B2) {\n k = i32(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 let xs = x * x;\n // var c = x - xp2 * (P1 + xp2 * (P2 + xp2 * (P3 + xp2 * (P4 + xp2 * P5))));\n let xq = xs * xs;\n let c = x - (xs * P1 + xq * ((P2 + xs * P3) + xq * (P4 + xs * P5)));\n let y = 1.0 + (x * c / (2 - c) - lo + hi);\n return k == 0 ? y : scalbn(y, k);\n }\n }\n\n export function exp2(x: f64): f64 {\n return exp2_lut(x);\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); // 0x1p1023\n\n var u = reinterpret(x);\n var hx = u32(u >> 32) & 0x7FFFFFFF;\n var sign = u32(u >> 63);\n var k = 0;\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 i32(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 var hxq = hxs * hxs;\n var r1 = (1.0 + hxs * Q1) + hxq * ((Q2 + hxs * Q3) + hxq * (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 // @ts-ignore: decorator\n @inline\n export function floor(x: f64): f64 {\n return builtin_floor(x);\n }\n\n // @ts-ignore: decorator\n @inline\n export function fround(x: f64): f64 {\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\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 = i32(ux >> 52);\n var ey = i32(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 /*\n * Wasm (MVP) and JS have different approaches for double->int conversions.\n *\n * For emulate JS conversion behavior and avoid trapping from wasm we should modulate by MAX_INT\n * our float-point arguments before actual convertion to integers.\n */\n if (!isFinite(x + y)) return 0;\n return dtoi32(x) * dtoi32(y);\n }\n\n export function log(x: f64): f64 { // see: musl/src/math/log.c and SUN COPYRIGHT NOTICE above\n if (ASC_SHRINK_LEVEL < 1) {\n return log_lut(x);\n } else {\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); // 0x1p54\n\n let u = reinterpret(x);\n let hx = u32(u >> 32);\n let k = 0;\n let sign = hx >> 31;\n if (sign || hx < 0x00100000) {\n if (u << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = u32(u >> 32);\n } else if (hx >= 0x7FF00000) {\n return x;\n } else if (hx == 0x3FF00000 && u << 32 == 0) {\n return 0;\n }\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 let f = x - 1.0;\n let hfsq = 0.5 * f * f;\n let s = f / (2.0 + f);\n let z = s * s;\n let w = z * z;\n let t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n let t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n let r = t2 + t1;\n let dk = k;\n return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;\n }\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); // 0x1p54\n\n var u = reinterpret(x);\n var hx = u32(u >> 32);\n var k = 0;\n var sign = hx >> 31;\n if (sign || hx < 0x00100000) {\n if (u << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = u32(u >> 32);\n } else if (hx >= 0x7FF00000) {\n return x;\n } else if (hx == 0x3FF00000 && u << 32 == 0) {\n return 0;\n }\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += i32(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\n var u = reinterpret(x);\n var hx = u32(u >> 32);\n var k = 1;\n var c = 0.0, f = 0.0;\n if (hx < 0x3FDA827A || bool(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 = u32(u >> 32);\n hu += 0x3FF00000 - 0x3FE6A09E;\n k = i32(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 if (ASC_SHRINK_LEVEL < 1) {\n return log2_lut(x);\n } else {\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); // 1p54\n\n let u = reinterpret(x);\n let hx = u32(u >> 32);\n let k = 0;\n let sign = hx >> 31;\n if (sign || hx < 0x00100000) {\n if (u << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = u32(u >> 32);\n } else if (hx >= 0x7FF00000) {\n return x;\n } else if (hx == 0x3FF00000 && u << 32 == 0) {\n return 0;\n }\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += i32(hx >> 20) - 0x3FF;\n hx = (hx & 0x000FFFFF) + 0x3FE6A09E;\n u = hx << 32 | (u & 0xFFFFFFFF);\n x = reinterpret(u);\n let f = x - 1.0;\n let hfsq = 0.5 * f * f;\n let s = f / (2.0 + f);\n let z = s * s;\n let w = z * z;\n let t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n let t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n let r = t2 + t1;\n let hi = f - hfsq;\n u = reinterpret(hi);\n u &= 0xFFFFFFFF00000000;\n hi = reinterpret(u);\n let lo = f - hi - hfsq + s * (hfsq + r);\n let val_hi = hi * ivln2hi;\n let val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;\n let 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\n // @ts-ignore: decorator\n @inline\n export function max(value1: f64, value2: f64): f64 {\n return builtin_max(value1, value2);\n }\n\n // @ts-ignore: decorator\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 // TODO: remove this fast pathes after introduced own mid-end IR with \"stdlib call simplify\" transforms\n if (builtin_abs(y) <= 2) {\n if (y == 2.0) return x * x;\n if (y == 0.5) {\n return select(\n builtin_abs(builtin_sqrt(x)),\n Infinity,\n x != -Infinity\n );\n }\n if (y == -1.0) return 1 / x;\n if (y == 1.0) return x;\n if (y == 0.0) return 1.0;\n }\n if (ASC_SHRINK_LEVEL < 1) {\n return pow_lut(x, y);\n } else {\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\n let u_ = reinterpret(x);\n let hx = i32(u_ >> 32);\n let lx = u_;\n u_ = reinterpret(y);\n let hy = i32(u_ >> 32);\n let ly = u_;\n let ix = hx & 0x7FFFFFFF;\n let 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 let 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 let ax = builtin_abs(x), z: f64;\n if (lx == 0) {\n if (ix == 0 || ix == 0x7FF00000 || ix == 0x3FF00000) {\n z = ax;\n if (hy < 0) z = 1.0 / z;\n if (hx < 0) {\n if (((ix - 0x3FF00000) | yisint) == 0) {\n let d = z - z;\n z = d / d;\n } else if (yisint == 1) z = -z;\n }\n return z;\n }\n }\n let s = 1.0;\n if (hx < 0) {\n if (yisint == 0) {\n let d = x - x;\n return d / d;\n }\n if (yisint == 1) s = -1.0;\n }\n let t1: f64, t2: f64, p_h: f64, p_l: f64, r: f64, t: f64, u: f64, v: f64, w: f64;\n let 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(u64(((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 let 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 = u32(u_ >> 32);\n let 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(u64(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 = u32(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\n export function seedRandom(value: i64): void {\n // Instead zero seed use golden ratio:\n // phi = (1 + sqrt(5)) / 2\n // trunc(2^64 / phi) = 0x9e3779b97f4a7c15\n if (value == 0) value = 0x9e3779b97f4a7c15;\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 random_seeded = true;\n }\n\n export function random(): f64 { // see: v8/src/base/utils/random-number-generator.cc\n if (!random_seeded) seedRandom(reinterpret(seed()));\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 >> 12) | 0x3FF0000000000000;\n return reinterpret(r) - 1;\n }\n\n // @ts-ignore: decorator\n @inline\n export function round(x: f64): f64 {\n let roundUp = builtin_ceil(x);\n return select(roundUp, roundUp - 1.0, roundUp - 0.5 <= x);\n }\n\n // @ts-ignore: decorator\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 // @ts-ignore: decorator\n @inline\n export function signbit(x: f64): bool {\n return bool(reinterpret(x) >>> 63);\n }\n\n export function sin(x: f64): f64 { // see: musl/src/math/sin.c\n var u = reinterpret(x);\n var ux = u32(u >> 32);\n var sign = ux >> 31;\n\n ux &= 0x7FFFFFFF;\n\n // |x| ~< pi/4\n if (ux <= 0x3FE921FB) {\n if (ux < 0x3E500000) { // |x| < 2**-26\n return x;\n }\n return sin_kern(x, 0.0, 0);\n }\n\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7FF00000) return x - x;\n\n // argument reduction needed\n var n = rempio2(x, u, sign);\n var y0 = rempio2_y0;\n var y1 = rempio2_y1;\n\n x = n & 1 ? cos_kern(y0, y1) : sin_kern(y0, y1, 1);\n return n & 2 ? -x : x;\n }\n\n export function sinh(x: f64): f64 { // see: musl/src/math/sinh.c\n var u = reinterpret(x) & 0x7FFFFFFFFFFFFFFF;\n var a = reinterpret(u);\n var w = u32(u >> 32);\n var h = builtin_copysign(0.5, x);\n if (w < 0x40862E42) {\n let t = expm1(a);\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 return expo2(a, 2 * h);\n }\n\n // @ts-ignore: decorator\n @inline\n export function sqrt(x: f64): f64 {\n return builtin_sqrt(x);\n }\n\n export function tan(x: f64): f64 { // see: musl/src/math/tan.c\n var u = reinterpret(x);\n var ux = u32(u >> 32);\n var sign = ux >>> 31;\n\n ux &= 0x7FFFFFFF;\n\n // |x| ~< pi/4\n if (ux <= 0x3FE921FB) {\n if (ux < 0x3E400000) { // |x| < 2**-27\n return x;\n }\n return tan_kern(x, 0.0, 1);\n }\n\n // tan(Inf or NaN) is NaN\n if (ux >= 0x7FF00000) return x - x;\n\n var n = rempio2(x, u, sign);\n return tan_kern(rempio2_y0, rempio2_y1, 1 - ((n & 1) << 1));\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 = u32(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 // @ts-ignore: decorator\n @inline\n export function trunc(x: f64): f64 {\n return builtin_trunc(x);\n }\n\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\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 // 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 if (builtin_abs(y) == 1.0) {\n // x % 1, x % -1 ==> sign(x) * abs(x - 1.0 * trunc(x / 1.0))\n // TODO: move this rule to compiler's optimization pass.\n // It could be apply for any x % C_pot, where \"C_pot\" is pow of two const.\n return builtin_copysign(x - builtin_trunc(x), x);\n }\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = i64(ux >> 52 & 0x7FF);\n var ey = i64(uy >> 52 & 0x7FF);\n var sx = ux >> 63;\n var uy1 = uy << 1;\n if (uy1 == 0 || ex == 0x7FF || isNaN(y)) {\n let m = x * y;\n return m / m;\n }\n var ux1 = ux << 1;\n if (ux1 <= uy1) {\n return x * f64(ux1 != uy1);\n }\n if (!ex) {\n ex -= builtin_clz(ux << 12);\n ux <<= 1 - ex;\n } else {\n ux &= u64(-1) >> 12;\n ux |= 1 << 52;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 12);\n uy <<= 1 - ey;\n } else {\n uy &= u64(-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 return reinterpret(ux | (sx << 63));\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 = i64(ux >> 52 & 0x7FF);\n var ey = i64(uy >> 52 & 0x7FF);\n if (uy << 1 == 0 || ex == 0x7FF || isNaN(y)) {\n let m = x * y;\n return m / m;\n }\n if (ux << 1 == 0) return x;\n var uxi = ux;\n if (!ex) {\n ex -= builtin_clz(uxi << 12);\n uxi <<= 1 - ex;\n } else {\n uxi &= u64(-1) >> 12;\n uxi |= 1 << 52;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 12);\n uy <<= 1 - ey;\n } else {\n uy &= u64(-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 ux < 0 ? -x : x;\n }\n\n export function sincos(x: f64): void { // see: musl/tree/src/math/sincos.c\n var u = reinterpret(x);\n var ux = u32(u >> 32);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3FE921FB) { // |x| ~<= π/4\n if (ux < 0x3E46A09E) { // if |x| < 2**-27 * sqrt(2)\n sincos_sin = x;\n sincos_cos = 1;\n return;\n }\n sincos_sin = sin_kern(x, 0, 0);\n sincos_cos = cos_kern(x, 0);\n return;\n }\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7F800000) {\n let xx = x - x;\n sincos_sin = xx;\n sincos_cos = xx;\n return;\n }\n // general argument reduction needed\n var n = rempio2(x, u, sign);\n var y0 = rempio2_y0;\n var y1 = rempio2_y1;\n var s = sin_kern(y0, y1, 1);\n var c = cos_kern(y0, y1);\n var sin = s, cos = c;\n if (n & 1) {\n sin = c;\n cos = -s;\n }\n if (n & 2) {\n sin = -sin;\n cos = -cos;\n }\n sincos_sin = sin;\n sincos_cos = cos;\n }\n}\n\n// @ts-ignore: decorator\n@lazy var rempio2f_y: f64;\n\n// @ts-ignore: decorator\n@lazy @inline const PIO2F_TABLE = memory.data([\n 0xA2F9836E4E441529,\n 0xFC2757D1F534DDC0,\n 0xDB6295993C439041,\n 0xFE5163ABDEBBC561\n]);\n\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\n var p = z * (pS0 + z * (pS1 + z * pS2));\n var q: f32 = 1 + z * qS1;\n return p / q;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction expo2f(x: f32, sign: 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(u32(0x7F + (k >> 1)) << 23);\n // in directed rounding correct sign before rounding or overflow is important\n return NativeMathf.exp(x - kln2) * (sign * scale) * scale;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction pio2f_large_quot(x: f32, u: i32): i32 { // see: jdh8/metallic/blob/master/src/math/float/rem_pio2f.c\n const coeff = reinterpret(0x3BF921FB54442D18); // π * 0x1p-65 = 8.51530395021638647334e-20\n\n var offset = (u >> 23) - 152;\n var shift = u64(offset & 63);\n var tblPtr = PIO2F_TABLE + (offset >> 6 << 3);\n\n var b0 = load(tblPtr, 0 << 3);\n var b1 = load(tblPtr, 1 << 3);\n var lo: u64;\n\n if (shift > 32) {\n let b2 = load(tblPtr, 2 << 3);\n lo = b2 >> (96 - shift);\n lo |= b1 << (shift - 32);\n } else {\n lo = b1 >> (32 - shift);\n }\n\n var hi = (b1 >> (64 - shift)) | (b0 << shift);\n var mantissa: u64 = (u & 0x007FFFFF) | 0x00800000;\n var product = mantissa * hi + (mantissa * lo >> 32);\n var r: i64 = product << 2;\n var q = i32((product >> 62) + (r >>> 63));\n rempio2f_y = copysign(coeff, x) * r;\n return q;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction rempio2f(x: f32, u: u32, sign: i32): i32 { // see: jdh8/metallic/blob/master/src/math/float/rem_pio2f.c\n const\n pi2hi = reinterpret(0x3FF921FB50000000), // 1.57079631090164184570\n pi2lo = reinterpret(0x3E5110B4611A6263), // 1.58932547735281966916e-8\n _2_pi = reinterpret(0x3FE45F306DC9C883); // 0.63661977236758134308\n\n if (u < 0x4DC90FDB) { // π * 0x1p28\n let q = nearest(x * _2_pi);\n rempio2f_y = x - q * pi2hi - q * pi2lo;\n return q;\n }\n\n var q = pio2f_large_quot(x, u);\n return select(-q, q, sign);\n}\n\n// |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]).\n// @ts-ignore: decorator\n@inline\nfunction sin_kernf(x: f64): f32 { // see: musl/tree/src/math/__sindf.c\n const\n S1 = reinterpret(0xBFC5555554CBAC77), // -0x15555554cbac77.0p-55\n S2 = reinterpret(0x3F811110896EFBB2), // 0x111110896efbb2.0p-59\n S3 = reinterpret(0xBF2A00F9E2CAE774), // -0x1a00f9e2cae774.0p-65\n S4 = reinterpret(0x3EC6CD878C3B46A7); // 0x16cd878c3b46a7.0p-71\n\n var z = x * x;\n var w = z * z;\n var r = S3 + z * S4;\n var s = z * x;\n return f32((x + s * (S1 + z * S2)) + s * w * r);\n}\n\n// |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]).\n// @ts-ignore: decorator\n@inline\nfunction cos_kernf(x: f64): f32 { // see: musl/tree/src/math/__cosdf.c\n const\n C0 = reinterpret(0xBFDFFFFFFD0C5E81), // -0x1ffffffd0c5e81.0p-54\n C1 = reinterpret(0x3FA55553E1053A42), // 0x155553e1053a42.0p-57\n C2 = reinterpret(0xBF56C087E80F1E27), // -0x16c087e80f1e27.0p-62\n C3 = reinterpret(0x3EF99342E0EE5069); // 0x199342e0ee5069.0p-68\n\n var z = x * x;\n var w = z * z;\n var r = C2 + z * C3;\n return f32(((1 + z * C0) + w * C1) + (w * z) * r);\n}\n\n// |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]).\n// @ts-ignore: decorator\n@inline\nfunction tan_kernf(x: f64, odd: i32): f32 { // see: musl/tree/src/math/__tandf.c\n const\n T0 = reinterpret(0x3FD5554D3418C99F), // 0x15554d3418c99f.0p-54\n T1 = reinterpret(0x3FC112FD38999F72), // 0x1112fd38999f72.0p-55\n T2 = reinterpret(0x3FAB54C91D865AFE), // 0x1b54c91d865afe.0p-57\n T3 = reinterpret(0x3F991DF3908C33CE), // 0x191df3908c33ce.0p-58\n T4 = reinterpret(0x3F685DADFCECF44E), // 0x185dadfcecf44e.0p-61\n T5 = reinterpret(0x3F8362B9BF971BCD); // 0x1362b9bf971bcd.0p-59\n\n var z = x * x;\n var r = T4 + z * T5;\n var t = T2 + z * T3;\n var w = z * z;\n var s = z * x;\n var u = T0 + z * T1;\n\n r = (x + s * u) + (s * w) * (t + w * r);\n return f32(odd ? -1 / r : r);\n}\n\n// See: jdh8/metallic/src/math/float/log2f.c and jdh8/metallic/src/math/float/kernel/atanh.h\n// @ts-ignore: decorator\n@inline\nfunction log2f(x: f64): f64 {\n const\n log2e = reinterpret(0x3FF71547652B82FE), // 1.44269504088896340736\n c0 = reinterpret(0x3FD555554FD9CAEF), // 0.33333332822728226129\n c1 = reinterpret(0x3FC999A7A8AF4132), // 0.20000167595436263505\n c2 = reinterpret(0x3FC2438D79437030), // 0.14268654271188685375\n c3 = reinterpret(0x3FBE2F663B001C97); // 0.11791075649681414150\n\n var i = reinterpret(x);\n var exponent = (i - 0x3FE6A09E667F3BCD) >> 52;\n x = reinterpret(i - (exponent << 52));\n x = (x - 1) / (x + 1);\n var xx = x * x;\n var y = x + x * xx * (c0 + c1 * xx + (c2 + c3 * xx) * (xx * xx));\n return (2 * log2e) * y + exponent;\n}\n\n// See: jdh8/metallic/src/math/float/exp2f.h and jdh8/metallic/blob/master/src/math/float/kernel/exp2f.h\n// @ts-ignore: decorator\n@inline\nfunction exp2f(x: f64): f64 {\n const\n c0 = reinterpret(0x3FE62E4302FCC24A), // 6.931471880289532425e-1\n c1 = reinterpret(0x3FCEBFBE07D97B91), // 2.402265108421173406e-1\n c2 = reinterpret(0x3FAC6AF6CCFC1A65), // 5.550357105498874537e-2\n c3 = reinterpret(0x3F83B29E3CE9AEF6), // 9.618030771171497658e-3\n c4 = reinterpret(0x3F55F0896145A89F), // 1.339086685300950937e-3\n c5 = reinterpret(0x3F2446C81E384864); // 1.546973499989028719e-4\n\n if (x < -1022) return 0;\n if (x >= 1024) return Infinity;\n\n var n = nearest(x);\n x -= n;\n var xx = x * x;\n var y = 1 + x * (c0 + c1 * x + (c2 + c3 * x) * xx + (c4 + c5 * x) * (xx * xx));\n return reinterpret(reinterpret(y) + (n << 52));\n}\n\nexport namespace NativeMathf {\n\n // @ts-ignore: decorator\n @lazy\n export const E = NativeMath.E;\n\n // @ts-ignore: decorator\n @lazy\n export const LN2 = NativeMath.LN2;\n\n // @ts-ignore: decorator\n @lazy\n export const LN10 = NativeMath.LN10;\n\n // @ts-ignore: decorator\n @lazy\n export const LOG2E = NativeMath.LOG2E;\n\n // @ts-ignore: decorator\n @lazy\n export const LOG10E = NativeMath.LOG10E;\n\n // @ts-ignore: decorator\n @lazy\n export const PI = NativeMath.PI;\n\n // @ts-ignore: decorator\n @lazy\n export const SQRT1_2 = NativeMath.SQRT1_2;\n\n // @ts-ignore: decorator\n @lazy\n export const SQRT2 = NativeMath.SQRT2;\n\n // @ts-ignore: decorator\n @lazy\n export var sincos_sin: f32 = 0;\n\n // @ts-ignore: decorator\n @lazy\n export var sincos_cos: f32 = 0;\n\n // @ts-ignore: decorator\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); // 0x1p-120f\n\n var hx = reinterpret(x);\n var ix = hx & 0x7FFFFFFF;\n if (ix >= 0x3F800000) {\n if (ix == 0x3F800000) {\n return select(2 * pio2_hi + Ox1p_120f, 0, hx < 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 < 0) {\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)) { // |x| < 2, invalid if x < 1\n let xm1 = x - 1;\n return log1p(xm1 + builtin_sqrt(xm1 * (xm1 + 2)));\n }\n if (u < 0x3F800000 + (12 << 23)) { // 2 <= x < 0x1p12\n return log(2 * x - 1 / (x + builtin_sqrt(x * x - 1)));\n }\n // x >= 0x1p12 or x <= -2 or NaN\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); // 0x1p-120f\n\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 = f32(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); // 0x1p-120f\n\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 var y = builtin_abs(x);\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\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 = u32(((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 let t: f32 = m & 2 ? 3 * pi / 4 : pi / 4;\n return m & 1 ? -t : t;\n } else {\n let t: f32 = m & 2 ? pi : 0.0;\n return m & 1 ? -t : t;\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\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 // @ts-ignore: decorator\n @inline\n export function ceil(x: f32): f32 {\n return builtin_ceil(x);\n }\n\n export function clz32(x: f32): f32 {\n if (!isFinite(x)) return 32;\n return builtin_clz(dtoi32(x));\n }\n\n export function cos(x: f32): f32 { // see: musl/src/math/cosf.c\n const\n c1pio2 = reinterpret(0x3FF921FB54442D18), // M_PI_2 * 1\n c2pio2 = reinterpret(0x400921FB54442D18), // M_PI_2 * 2\n c3pio2 = reinterpret(0x4012D97C7F3321D2), // M_PI_2 * 3\n c4pio2 = reinterpret(0x401921FB54442D18); // M_PI_2 * 4\n\n var ux = reinterpret(x);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3F490FDA) { // |x| ~<= π/4\n if (ux < 0x39800000) { // |x| < 2**-12\n // raise inexact if x != 0\n return 1;\n }\n return cos_kernf(x);\n }\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (ux <= 0x407B53D1) { // |x| ~<= 5π/4\n if (ux > 0x4016CBE3) { // |x| ~> 3π/4\n return -cos_kernf(sign ? x + c2pio2 : x - c2pio2);\n } else {\n return sign ? sin_kernf(x + c1pio2) : sin_kernf(c1pio2 - x);\n }\n }\n if (ux <= 0x40E231D5) { // |x| ~<= 9π/4\n if (ux > 0x40AFEDDF) { // |x| ~> 7π/4\n return cos_kernf(sign ? x + c4pio2 : x - c4pio2);\n } else {\n return sign ? sin_kernf(-x - c3pio2) : sin_kernf(x - c3pio2);\n }\n }\n }\n\n // cos(Inf or NaN) is NaN\n if (ux >= 0x7F800000) return x - x;\n\n // general argument reduction needed\n var n = rempio2f(x, ux, sign);\n var y = rempio2f_y;\n\n var t = n & 1 ? sin_kernf(y) : cos_kernf(y);\n return (n + 1) & 2 ? -t : t;\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, 1);\n }\n\n // @ts-ignore: decorator\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 if (ASC_SHRINK_LEVEL < 1) {\n return expf_lut(x);\n } else {\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); // 0x1p+127f\n\n let hx = reinterpret(x);\n let sign = hx >> 31;\n hx &= 0x7FFFFFFF;\n if (hx >= 0x42AEAC50) {\n if (hx > 0x7F800000) return x; // NaN\n if (hx >= 0x42B17218) {\n if (!sign) return x * Ox1p127f;\n else if (hx >= 0x42CFF1B5) return 0;\n }\n }\n let hi: f32, lo: f32;\n let k: i32;\n if (hx > 0x3EB17218) {\n if (hx > 0x3F851592) {\n k = i32(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 let xx = x * x;\n let c = x - xx * (P1 + xx * P2);\n let y: f32 = 1 + (x * c / (2 - c) - lo + hi);\n return k == 0 ? y : scalbn(y, k);\n }\n }\n\n export function exp2(x: f32): f32 {\n return exp2f_lut(x);\n }\n\n export function expm1(x: f32): f32 { // see: musl/src/math/expm1f.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 invln2 = reinterpret(0x3FB8AA3B), // 1.4426950216e+00f\n Q1 = reinterpret(0xBD088868), // -3.3333212137e-02f\n Q2 = reinterpret(0x3ACF3010), // 1.5807170421e-03f\n Ox1p127f = reinterpret(0x7F000000); // 0x1p+127f\n\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 (hx > 0x42B17217) { // x > log(FLT_MAX)\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 i32(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 // @ts-ignore: decorator\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\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(f32(x * x + y * y));\n }\n\n // @ts-ignore: decorator\n @inline\n export function imul(x: f32, y: f32): f32 {\n /*\n * Wasm (MVP) and JS have different approaches for double->int conversions.\n *\n * For emulate JS conversion behavior and avoid trapping from wasm we should modulate by MAX_INT\n * our float-point arguments before actual convertion to integers.\n */\n if (!isFinite(x + y)) return 0;\n return (dtoi32(x) * dtoi32(y));\n }\n\n export function log(x: f32): f32 { // see: musl/src/math/logf.c and SUN COPYRIGHT NOTICE above\n if (ASC_SHRINK_LEVEL < 1) {\n return logf_lut(x);\n } else {\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\n let u = reinterpret(x);\n let k = 0;\n let sign = u >> 31;\n if (sign || u < 0x00800000) {\n if (u << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0;\n k -= 25;\n x *= Ox1p25f;\n u = reinterpret(x);\n } else if (u >= 0x7F800000) {\n return x;\n } else if (u == 0x3F800000) {\n return 0;\n }\n u += 0x3F800000 - 0x3F3504F3;\n k += i32(u >> 23) - 0x7F;\n u = (u & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(u);\n let f = x - 1.0;\n let s = f / (2.0 + f);\n let z = s * s;\n let w = z * z;\n let t1 = w * (Lg2 + w * Lg4);\n let t2 = z * (Lg1 + w * Lg3);\n let r = t2 + t1;\n let hfsq = 0.5 * f * f;\n let dk = k;\n return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;\n }\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); // 0x1p25f\n\n var ux = reinterpret(x);\n var k = 0;\n var sign = ux >> 31;\n if (sign || ux < 0x00800000) {\n if (ux << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 25;\n x *= Ox1p25f;\n ux = reinterpret(x);\n } else if (ux >= 0x7F800000) {\n return x;\n } else if (ux == 0x3F800000) {\n return 0;\n }\n ux += 0x3F800000 - 0x3F3504F3;\n k += i32(ux >> 23) - 0x7F;\n ux = (ux & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(ux);\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 ux = reinterpret(hi);\n ux &= 0xFFFFF000;\n hi = reinterpret(ux);\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\n var ix = reinterpret(x);\n var c: f32 = 0;\n var f: f32 = 0;\n var k = 1;\n if (ix < 0x3ED413D0 || bool(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 = i32(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 if (ASC_SHRINK_LEVEL < 1) {\n return log2f_lut(x);\n } else {\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); // 0x1p25f\n\n let ux = reinterpret(x);\n let k = 0;\n let sign = ux >> 31;\n if (sign || ux < 0x00800000) {\n if (ux << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 25;\n x *= Ox1p25f;\n ux = reinterpret(x);\n } else if (ux >= 0x7F800000) {\n return x;\n } else if (ux == 0x3F800000) {\n return 0;\n }\n ux += 0x3F800000 - 0x3F3504F3;\n k += i32(ux >> 23) - 0x7F;\n ux = (ux & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(ux);\n let f = x - 1.0;\n let s = f / (2.0 + f);\n let z = s * s;\n let w = z * z;\n let t1 = w * (Lg2 + w * Lg4);\n let t2 = z * (Lg1 + w * Lg3);\n let r = t2 + t1;\n let hfsq: f32 = 0.5 * f * f;\n let hi = f - hfsq;\n let u = reinterpret(hi);\n u &= 0xFFFFF000;\n hi = reinterpret(u);\n let lo: f32 = f - hi - hfsq + s * (hfsq + r);\n let dk = k;\n return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + dk;\n }\n }\n\n // @ts-ignore: decorator\n @inline\n export function max(value1: f32, value2: f32): f32 {\n return builtin_max(value1, value2);\n }\n\n // @ts-ignore: decorator\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 {\n // TODO: remove this fast pathes after introduced own mid-end IR with \"stdlib call simplify\" transforms\n if (builtin_abs(y) <= 2) {\n if (y == 2.0) return x * x;\n if (y == 0.5) {\n return select(\n builtin_abs(builtin_sqrt(x)),\n Infinity,\n x != -Infinity\n );\n }\n if (y == -1.0) return 1 / x;\n if (y == 1.0) return x;\n if (y == 0.0) return 1.0;\n }\n if (ASC_SHRINK_LEVEL < 1) {\n // see: musl/src/math/powf.c\n return powf_lut(x, y);\n } else {\n // based on: jdh8/metallic/src/math/float/powf.c\n if (y == 0) return 1;\n // @ts-ignore: cast\n if (isNaN(x) | isNaN(y)) {\n return NaN;\n }\n let sign: u32 = 0;\n let uy = reinterpret(y);\n let ux = reinterpret(x);\n let sx = ux >> 31;\n ux &= 0x7FFFFFFF;\n if (sx && nearest(y) == y) {\n x = -x;\n sx = 0;\n sign = u32(nearest(y * 0.5) != y * 0.5) << 31;\n }\n let m: u32;\n if (ux == 0x3F800000) { // x == 1\n m = sx | u32((uy & 0x7FFFFFFF) == 0x7F800000) ? 0x7FC00000 : 0x3F800000;\n } else if (ux == 0) {\n m = uy < 0 ? 0x7F800000 : 0;\n } else if (ux == 0x7F800000) {\n m = uy < 0 ? 0 : 0x7F800000;\n } else if (sx) {\n m = 0x7FC00000;\n } else {\n m = reinterpret(exp2f(y * log2f(x)));\n }\n return reinterpret(m | sign);\n }\n }\n\n // @ts-ignore: decorator\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) seedRandom(reinterpret(seed()));\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 // @ts-ignore: decorator\n @inline\n export function round(x: f32): f32 {\n let roundUp = builtin_ceil(x);\n return select(roundUp, roundUp - 1.0, roundUp - 0.5 <= x);\n }\n\n // @ts-ignore: decorator\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 // @ts-ignore: decorator\n @inline\n export function signbit(x: f32): bool {\n return (reinterpret(x) >>> 31);\n }\n\n export function sin(x: f32): f32 { // see: musl/src/math/sinf.c\n const\n s1pio2 = reinterpret(0x3FF921FB54442D18), // M_PI_2 * 1\n s2pio2 = reinterpret(0x400921FB54442D18), // M_PI_2 * 2\n s3pio2 = reinterpret(0x4012D97C7F3321D2), // M_PI_2 * 3\n s4pio2 = reinterpret(0x401921FB54442D18); // M_PI_2 * 4\n\n var ux = reinterpret(x);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3F490FDA) { // |x| ~<= π/4\n if (ux < 0x39800000) { // |x| < 2**-12\n return x;\n }\n return sin_kernf(x);\n }\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (ux <= 0x407B53D1) { // |x| ~<= 5π/4\n if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4\n return sign ? -cos_kernf(x + s1pio2) : cos_kernf(x - s1pio2);\n }\n return sin_kernf(-(sign ? x + s2pio2 : x - s2pio2));\n }\n\n if (ux <= 0x40E231D5) { // |x| ~<= 9π/4\n if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4\n return sign ? cos_kernf(x + s3pio2) : -cos_kernf(x - s3pio2);\n }\n return sin_kernf(sign ? x + s4pio2 : x - s4pio2);\n }\n }\n\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7F800000) return x - x;\n\n var n = rempio2f(x, ux, sign);\n var y = rempio2f_y;\n\n var t = n & 1 ? cos_kernf(y) : sin_kernf(y);\n return n & 2 ? -t : t;\n }\n\n export function sinh(x: f32): f32 { // see: musl/src/math/sinhf.c\n var u = reinterpret(x) & 0x7FFFFFFF;\n var a = reinterpret(u);\n var h = builtin_copysign(0.5, x);\n if (u < 0x42B17217) {\n let t = expm1(a);\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 return expo2f(a, 2 * h);\n }\n\n // @ts-ignore: decorator\n @inline\n export function sqrt(x: f32): f32 {\n return builtin_sqrt(x);\n }\n\n export function tan(x: f32): f32 { // see: musl/src/math/tanf.c\n const\n t1pio2 = reinterpret(0x3FF921FB54442D18), // 1 * M_PI_2\n t2pio2 = reinterpret(0x400921FB54442D18), // 2 * M_PI_2\n t3pio2 = reinterpret(0x4012D97C7F3321D2), // 3 * M_PI_2\n t4pio2 = reinterpret(0x401921FB54442D18); // 4 * M_PI_2\n\n var ux = reinterpret(x);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3F490FDA) { // |x| ~<= π/4\n if (ux < 0x39800000) { // |x| < 2**-12\n return x;\n }\n return tan_kernf(x, 0);\n }\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (ux <= 0x407B53D1) { // |x| ~<= 5π/4\n if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4\n return tan_kernf((sign ? x + t1pio2 : x - t1pio2), 1);\n } else {\n return tan_kernf((sign ? x + t2pio2 : x - t2pio2), 0);\n }\n }\n if (ux <= 0x40E231D5) { // |x| ~<= 9π/4\n if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4\n return tan_kernf((sign ? x + t3pio2 : x - t3pio2), 1);\n } else {\n return tan_kernf((sign ? x + t4pio2 : x - t4pio2), 0);\n }\n }\n }\n\n // tan(Inf or NaN) is NaN\n if (ux >= 0x7F800000) return x - x;\n\n // argument reduction\n var n = rempio2f(x, ux, sign);\n var y = rempio2f_y;\n return tan_kernf(y, n & 1);\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 // @ts-ignore: decorator\n @inline\n export function trunc(x: f32): f32 {\n return builtin_trunc(x);\n }\n\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\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 if (builtin_abs(y) == 1.0) {\n // x % 1, x % -1 ==> sign(x) * abs(x - 1.0 * trunc(x / 1.0))\n // TODO: move this rule to compiler's optimization pass.\n // It could be apply for any x % C_pot, where \"C_pot\" is pow of two const.\n return builtin_copysign(x - builtin_trunc(x), x);\n }\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = i32(ux >> 23 & 0xFF);\n var ey = i32(uy >> 23 & 0xFF);\n var sm = ux & 0x80000000;\n var uy1 = uy << 1;\n if (uy1 == 0 || ex == 0xFF || isNaN(y)) {\n let m = x * y;\n return m / m;\n }\n var ux1 = ux << 1;\n if (ux1 <= uy1) {\n return x * f32(ux1 != uy1);\n }\n if (!ex) {\n ex -= builtin_clz(ux << 9);\n ux <<= 1 - ex;\n } else {\n ux &= -1 >> 9;\n ux |= 1 << 23;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 9);\n uy <<= 1 - ey;\n } else {\n uy &= u32(-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 return reinterpret(ux | sm);\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 = i32(ux >> 23 & 0xFF);\n var ey = i32(uy >> 23 & 0xFF);\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 <<= 1 - ex;\n } else {\n uxi &= u32(-1) >> 9;\n uxi |= 1 << 23;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 9);\n uy <<= 1 - ey;\n } else {\n uy &= u32(-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 && bool(q & 1))))) {\n x -= y;\n // q++;\n }\n return ux < 0 ? -x : x;\n }\n\n export function sincos(x: f32): void { // see: musl/tree/src/math/sincosf.c\n const\n s1pio2 = reinterpret(0x3FF921FB54442D18), // 1 * M_PI_2\n s2pio2 = reinterpret(0x400921FB54442D18), // 2 * M_PI_2\n s3pio2 = reinterpret(0x4012D97C7F3321D2), // 3 * M_PI_2\n s4pio2 = reinterpret(0x401921FB54442D18); // 4 * M_PI_2\n\n var ux = reinterpret(x);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3F490FDA) { // |x| ~<= π/4\n if (ux < 0x39800000) { // |x| < 2**-12\n sincos_sin = x;\n sincos_cos = 1;\n return;\n }\n sincos_sin = sin_kernf(x);\n sincos_cos = cos_kernf(x);\n return;\n }\n if (ASC_SHRINK_LEVEL < 1) {\n if (ux <= 0x407B53D1) { // |x| ~<= 5π/4\n if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4\n if (sign) {\n sincos_sin = -cos_kernf(x + s1pio2);\n sincos_cos = sin_kernf(x + s1pio2);\n } else {\n sincos_sin = cos_kernf(s1pio2 - x);\n sincos_cos = sin_kernf(s1pio2 - x);\n }\n return;\n }\n // -sin(x + c) is not correct if x+c could be 0: -0 vs +0\n sincos_sin = -sin_kernf(sign ? x + s2pio2 : x - s2pio2);\n sincos_cos = -cos_kernf(sign ? x + s2pio2 : x - s2pio2);\n return;\n }\n if (ux <= 0x40E231D5) { // |x| ~<= 9π/4\n if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4\n if (sign) {\n sincos_sin = cos_kernf(x + s3pio2);\n sincos_cos = -sin_kernf(x + s3pio2);\n } else {\n sincos_sin = -cos_kernf(x - s3pio2);\n sincos_cos = sin_kernf(x - s3pio2);\n }\n return;\n }\n sincos_sin = sin_kernf(sign ? x + s4pio2 : x - s4pio2);\n sincos_cos = cos_kernf(sign ? x + s4pio2 : x - s4pio2);\n return;\n }\n }\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7F800000) {\n let xx = x - x;\n sincos_sin = xx;\n sincos_cos = xx;\n return;\n }\n // general argument reduction needed\n var n = rempio2f(x, ux, sign);\n var y = rempio2f_y;\n var s = sin_kernf(y);\n var c = cos_kernf(y);\n var sin = s, cos = c;\n if (n & 1) {\n sin = c;\n cos = -s;\n }\n if (n & 2) {\n sin = -sin;\n cos = -cos;\n }\n sincos_sin = sin;\n sincos_cos = cos;\n }\n}\n\nexport function ipow32(x: i32, e: i32): i32 {\n var out = 1;\n if (ASC_SHRINK_LEVEL < 1) {\n if (x == 2) {\n return select(1 << e, 0, e < 32);\n }\n if (e <= 0) {\n if (x == -1) return select(-1, 1, e & 1);\n return i32(e == 0) | i32(x == 1);\n }\n else if (e == 1) return x;\n else if (e == 2) return x * x;\n else if (e < 32) {\n let log = 32 - clz(e);\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 while (e) {\n if (e & 1) out *= x;\n e >>>= 1;\n x *= x;\n }\n return out;\n}\n\nexport function ipow64(x: i64, e: i64): i64 {\n var out: i64 = 1;\n if (ASC_SHRINK_LEVEL < 1) {\n if (x == 2) {\n return select(1 << e, 0, e < 64);\n }\n if (e <= 0) {\n if (x == -1) return select(-1, 1, e & 1);\n return i64(e == 0) | i64(x == 1);\n }\n else if (e == 1) return x;\n else if (e == 2) return x * x;\n else if (e < 64) {\n let log = 64 - clz(e);\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 while (e) {\n if (e & 1) out *= x;\n e >>>= 1;\n x *= x;\n }\n return out;\n}\n\n/*\nTODO:\nIn compile time if only exponent is constant we could replace ipow32/ipow64 by shortest addition chains\nwhich usually faster than exponentiation by squaring\n\nfor ipow32 and e < 32:\n\nlet b: i32, c: i32, d: i32, h: i32, k: i32, g: i32;\nswitch (e) {\n case 1: return x;\n case 2: return x * x;\n case 3: return x * x * x;\n case 4: return (b = x * x) * b;\n case 5: return (b = x * x) * b * x;\n case 6: return (b = x * x) * b * b;\n case 7: return (b = x * x) * b * b * x;\n case 8: return (d = (b = x * x) * b) * d;\n case 9: return (c = x * x * x) * c * c;\n case 10: return (d = (b = x * x) * b) * d * b;\n case 11: return (d = (b = x * x) * b) * d * b * x;\n case 12: return (d = (b = x * x) * b) * d * d;\n case 13: return (d = (b = x * x) * b) * d * d * x;\n case 14: return (d = (b = x * x) * b) * d * d * b;\n case 15: return (k = (b = x * x) * b * x) * k * k;\n case 16: return (h = (d = (b = x * x) * b) * d) * h;\n case 17: return (h = (d = (b = x * x) * b) * d) * h * x;\n case 18: return (h = (d = (b = x * x) * b) * d * x) * h;\n case 19: return (h = (d = (b = x * x) * b) * d * x) * h * x;\n case 20: return (h = (k = (b = x * x) * b * x) * k) * h;\n case 21: return (h = (k = (b = x * x) * b * x) * k) * h * x;\n case 22: return (g = (h = (k = (b = x * x) * b * x) * k) * x) * g;\n case 23: return (h = (d = (c = (b = x * x) * x) * b) * d) * h * c;\n case 24: return (h = (d = (c = x * x * x) * c) * d) * h;\n case 25: return (h = (d = (c = x * x * x) * c) * d) * h * x;\n case 26: return (g = (h = (d = (c = x * x * x) * c) * d) * x) * g;\n case 27: return (h = (d = (c = x * x * x) * c) * d) * h * c;\n case 28: return (h = (d = (c = x * x * x) * c * x) * d) * h;\n case 29: return (h = (d = (c = x * x * x) * c * x) * d) * h * x;\n case 30: return (h = (d = (c = x * x * x) * c) * d * c) * h;\n case 31: return (h = (d = (c = x * x * x) * c) * d * c) * h * x;\n}\n\nfor ipow64: TODO\nswitch (e) {\n case 32:\n ...\n case 63:\n}\n*/\n","// This file is shared with the compiler and must remain portable\n\n/** Runtime types. */\nexport enum Runtime {\n /** Simple bump allocator without GC. */\n Stub = 0,\n /** Stop the world semi-automatic GC. */\n Minimal = 1,\n /** incremental GC. */\n Incremental = 2,\n}\n","import { compareImpl } from \"./string\";\n\ntype Comparator = (a: T, b: T) => i32;\n\n// @ts-ignore: decorator\n@lazy @inline const EMPTY = u32.MAX_VALUE;\n// @ts-ignore: decorator\n@inline const INSERTION_SORT_THRESHOLD = 48;\n// @ts-ignore: decorator\n@inline const MIN_RUN_LENGTH = 32;\n\n// @ts-ignore: decorator\n@inline\nfunction log2u(n: u32): u32 {\n return 31 - clz(n);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function COMPARATOR(): Comparator {\n if (isInteger()) {\n if (isSigned() && sizeof() <= 4) {\n return (a, b) => i32(a) - i32(b);\n } else {\n return (a, b) => i32(a > b) - i32(a < b);\n }\n } else if (isFloat()) {\n if (sizeof() == 4) {\n return (a, b) => {\n var ia = reinterpret(f32(a));\n var ib = reinterpret(f32(b));\n ia ^= ia >> 31 >>> 1;\n ib ^= ib >> 31 >>> 1;\n return i32(ia > ib) - i32(ia < ib);\n };\n } else {\n return (a, b) => {\n var ia = reinterpret(f64(a));\n var ib = reinterpret(f64(b));\n ia ^= ia >> 63 >>> 1;\n ib ^= ib >> 63 >>> 1;\n return i32(ia > ib) - i32(ia < ib);\n };\n }\n } else if (isString()) {\n return (a, b) => {\n if (\n changetype(a) == changetype(b) ||\n changetype(a) == 0 ||\n changetype(b) == 0\n ) return 0;\n var alen = changetype(a).length;\n var blen = changetype(b).length;\n if (!(alen | blen)) return 0;\n if (!alen) return -1;\n if (!blen) return 1;\n let res = compareImpl(\n changetype(a), 0,\n changetype(b), 0,\n min(alen, blen)\n );\n return res ? res : alen - blen;\n };\n } else {\n return (a, b) => i32(a > b) - i32(a < b);\n }\n}\n\n// Power Sort implementation (stable) from paper \"Nearly-Optimal Mergesorts\"\n// https://arxiv.org/pdf/1805.04154.pdf\n// This method usually outperform TimSort.\n// TODO: refactor c >>> 31 to c < 0 when binaryen will support this opt\nexport function SORT(\n ptr: usize,\n len: i32,\n comparator: Comparator\n): void {\n if (len <= INSERTION_SORT_THRESHOLD) {\n if (len <= 1) return;\n if (ASC_SHRINK_LEVEL < 1) {\n switch (len) {\n case 3: {\n let a = load(ptr, 0);\n let b = load(ptr, 1 << alignof());\n let c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 0);\n a = select(a, b, c);\n b = load(ptr, 2 << alignof());\n c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 1 << alignof());\n store(ptr, select(a, b, c), 2 << alignof());\n }\n case 2: {\n let a = load(ptr, 0);\n let b = load(ptr, 1 << alignof());\n let c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 0);\n store(ptr, select(a, b, c), 1 << alignof());\n return;\n }\n }\n }\n insertionSort(ptr, 0, len - 1, 0, comparator);\n return;\n }\n\n var lgPlus2 = log2u(len) + 2;\n var lgPlus2Size = lgPlus2 << alignof();\n var leftRunStartBuf = __alloc(lgPlus2Size << 1);\n var leftRunEndBuf = leftRunStartBuf + lgPlus2Size;\n\n for (let i: u32 = 0; i < lgPlus2; ++i) {\n store(leftRunStartBuf + (i << alignof()), EMPTY);\n }\n\n var buffer = __alloc(len << alignof());\n\n var hi = len - 1;\n var endA = extendRunRight(ptr, 0, hi, comparator);\n var lenA = endA + 1;\n\n if (lenA < MIN_RUN_LENGTH) {\n endA = min(hi, MIN_RUN_LENGTH - 1);\n insertionSort(ptr, 0, endA, lenA, comparator);\n }\n\n var top: u32 = 0, startA = 0;\n while (endA < hi) {\n let startB = endA + 1;\n let endB = extendRunRight(ptr, startB, hi, comparator);\n let lenB = endB - startB + 1;\n\n if (lenB < MIN_RUN_LENGTH) {\n endB = min(hi, startB + MIN_RUN_LENGTH - 1);\n insertionSort(ptr, startB, endB, lenB, comparator);\n }\n\n let k = nodePower(0, hi, startA, startB, endB);\n\n for (let i = top; i > k; --i) {\n let start = load(leftRunStartBuf + (i << alignof()));\n if (start != EMPTY) {\n mergeRuns(\n ptr,\n start,\n load(leftRunEndBuf + (i << alignof())) + 1,\n endA,\n buffer,\n comparator\n );\n startA = start;\n store(leftRunStartBuf + (i << alignof()), EMPTY);\n }\n }\n\n store(leftRunStartBuf + (k << alignof()), startA);\n store(leftRunEndBuf + (k << alignof()), endA);\n startA = startB;\n endA = endB;\n top = k;\n }\n\n for (let i = top; i != 0; --i) {\n let start = load(leftRunStartBuf + (i << alignof()));\n if (start != EMPTY) {\n mergeRuns(\n ptr,\n start,\n load(leftRunEndBuf + (i << alignof())) + 1,\n hi,\n buffer,\n comparator\n );\n }\n }\n // dealloc aux buffers\n __free(buffer);\n __free(leftRunStartBuf);\n}\n\nfunction insertionSort(\n ptr: usize,\n left: i32,\n right: i32,\n presorted: i32,\n comparator: Comparator\n): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n // slightly improved original insertion sort\n for (let i = left + presorted; i <= right; ++i) {\n let j = i - 1;\n let a = load(ptr + (i << alignof()));\n while (j >= left) {\n let b = load(ptr + (j << alignof()));\n if (comparator(a, b) < 0) {\n store(ptr + (j << alignof()), b, 1 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), a, 1 << alignof());\n }\n } else {\n // even-odd two-way insertion sort which allow increase minRunLen\n let range = right - left + 1;\n let i = left + select(range & 1, presorted - ((range - presorted) & 1), presorted == 0);\n for (; i <= right; i += 2) {\n let a = load(ptr + (i << alignof()), 0);\n let b = load(ptr + (i << alignof()), 1 << alignof());\n let min = b, max = a;\n if (comparator(a, b) <= 0) {\n min = a, max = b;\n }\n let j = i - 1;\n while (j >= left) {\n a = load(ptr + (j << alignof()));\n if (comparator(a, max) > 0) {\n store(ptr + (j << alignof()), a, 2 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), max, 2 << alignof());\n while (j >= left) {\n a = load(ptr + (j << alignof()));\n if (comparator(a, min) > 0) {\n store(ptr + (j << alignof()), a, 1 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), min, 1 << alignof());\n }\n }\n}\n\nfunction nodePower(left: u32, right: u32, startA: u32, startB: u32, endB: u32): u32 {\n var n: u64 = right - left + 1;\n var s = startB - (left << 1);\n var l = startA + s;\n var r = endB + s + 1;\n var a = (l << 30) / n;\n var b = (r << 30) / n;\n return clz((a ^ b));\n}\n\nfunction extendRunRight(\n ptr: usize,\n i: i32,\n right: i32,\n comparator: Comparator\n): i32 {\n if (i == right) return i;\n var j = i;\n if (comparator(\n load(ptr + ( j << alignof())),\n load(ptr + (++j << alignof()))\n ) > 0) {\n while (\n j < right &&\n (comparator(\n load(ptr + (j << alignof()), 1 << alignof()),\n load(ptr + (j << alignof()))\n ) >>> 31) // < 0\n ) ++j;\n // reverse\n let k = j;\n while (i < k) {\n let tmp = load(ptr + (i << alignof()));\n store(ptr + (i << alignof()), load(ptr + (k << alignof()))); ++i;\n store(ptr + (k << alignof()), tmp); --k;\n }\n } else {\n while (\n j < right &&\n comparator(\n load(ptr + (j << alignof()), 1 << alignof()),\n load(ptr + (j << alignof()))\n ) >= 0\n ) ++j;\n }\n return j;\n}\n\n// Merges arr[l..m - 1] and arr[m..r]\nfunction mergeRuns(\n ptr: usize,\n l: i32,\n m: i32,\n r: i32,\n buffer: usize,\n comparator: Comparator\n): void {\n --m;\n var i: i32, j: i32, t = r + m;\n for (i = m + 1; i > l; --i) {\n store(\n buffer + ((i - 1) << alignof()),\n load(ptr + ((i - 1) << alignof()))\n );\n }\n for (j = m; j < r; ++j) {\n store(\n buffer + ((t - j) << alignof()),\n load(ptr + (j << alignof()), 1 << alignof())\n );\n }\n for (let k = l; k <= r; ++k) {\n let a = load(buffer + (j << alignof()));\n let b = load(buffer + (i << alignof()));\n if (comparator(a, b) < 0) {\n store(ptr + (k << alignof()), a);\n --j;\n } else {\n store(ptr + (k << alignof()), b);\n ++i;\n }\n }\n}\n","/// \n\nimport { BLOCK_MAXSIZE } from \"./rt/common\";\nimport { Runtime } from \"shared/runtime\";\nimport { COMPARATOR, SORT } from \"./util/sort\";\nimport { REVERSE, FILL } from \"./util/bytes\";\nimport { joinBooleanArray, joinIntegerArray, joinFloatArray, joinStringArray, joinReferenceArray } from \"./util/string\";\nimport { idof, isArray as builtin_isArray } from \"./builtins\";\nimport { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_EMPTYARRAY, E_HOLEYARRAY } from \"./util/error\";\n\n// @ts-ignore: decorator\n@inline @lazy const MIN_SIZE: usize = 8;\n\n/** Ensures that the given array has _at least_ the specified backing size. */\nfunction ensureCapacity(array: usize, newSize: usize, alignLog2: u32, canGrow: bool = true): void {\n // Depends on the fact that Arrays mimic ArrayBufferView\n var oldCapacity = changetype(array).byteLength;\n if (newSize > oldCapacity >>> alignLog2) {\n if (newSize > BLOCK_MAXSIZE >>> alignLog2) throw new RangeError(E_INVALIDLENGTH);\n let oldData = changetype(changetype(array).buffer);\n // Grows old capacity by factor of two.\n // Make sure we don't reach BLOCK_MAXSIZE for new growed capacity.\n let newCapacity = max(newSize, MIN_SIZE) << alignLog2;\n if (canGrow) newCapacity = max(min(oldCapacity << 1, BLOCK_MAXSIZE), newCapacity);\n let newData = __renew(oldData, newCapacity);\n // __new / __renew already init memory range as zeros in Incremental runtime.\n // So try to avoid this.\n if (ASC_RUNTIME != Runtime.Incremental) {\n memory.fill(newData + oldCapacity, 0, newCapacity - oldCapacity);\n }\n if (newData != oldData) { // oldData has been free'd\n store(array, newData, offsetof(\"buffer\"));\n store(array, newData, offsetof(\"dataStart\"));\n __link(array, changetype(newData), false);\n }\n store(array, newCapacity, offsetof(\"byteLength\"));\n }\n}\n\nexport class Array {\n [key: number]: T;\n\n // Mimicking ArrayBufferView isn't strictly necessary here but is done to allow glue code\n // to work with typed and normal arrays interchangeably. Technically, normal arrays do not need\n // `dataStart` (equals `buffer`) and `byteLength` (equals computed `buffer.byteLength`), but the\n // block is 16 bytes anyway so it's fine to have a couple extra fields in there.\n\n private buffer: ArrayBuffer;\n @unsafe readonly dataStart: usize;\n private byteLength: i32; // Uses here as capacity\n\n // Also note that Array with non-nullable T must guard against uninitialized null values\n // whenever an element is accessed. Otherwise, the compiler wouldn't be able to guarantee\n // type-safety anymore. For lack of a better word, such an array is \"holey\".\n\n private length_: i32;\n\n static isArray(value: U): bool {\n return isReference() ? changetype(value) != 0 && builtin_isArray(value) : false;\n }\n\n static create(capacity: i32 = 0): Array {\n WARNING(\"'Array.create' is deprecated. Use 'new Array' instead, making sure initial elements are initialized.\");\n var array = new Array(capacity);\n array.length = 0;\n return array;\n }\n\n constructor(length: i32 = 0) {\n if (length > BLOCK_MAXSIZE >>> alignof()) throw new RangeError(E_INVALIDLENGTH);\n // reserve capacity for at least MIN_SIZE elements\n var bufferSize = max(length, MIN_SIZE) << alignof();\n var buffer = changetype(__new(bufferSize, idof()));\n if (ASC_RUNTIME != Runtime.Incremental) {\n memory.fill(changetype(buffer), 0, bufferSize);\n }\n this.buffer = buffer; // links\n this.dataStart = changetype(buffer);\n this.byteLength = bufferSize;\n this.length_ = length;\n }\n\n get length(): i32 {\n return this.length_;\n }\n\n set length(newLength: i32) {\n ensureCapacity(changetype(this), newLength, alignof(), false);\n this.length_ = newLength;\n }\n\n every(fn: (value: T, index: i32, array: Array) => bool): bool {\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n if (!fn(load(this.dataStart + (i << alignof())), i, this)) return false;\n }\n return true;\n }\n\n findIndex(fn: (value: T, index: i32, array: Array) => bool): i32 {\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n if (fn(load(this.dataStart + (i << alignof())), i, this)) return i;\n }\n return -1;\n }\n\n findLastIndex(fn: (value: T, index: i32, array: Array) => bool): i32 {\n for (let i = this.length_ - 1; i >= 0; --i) {\n if (fn(load(this.dataStart + (i << alignof())), i, this)) return i;\n }\n return -1;\n }\n\n @operator(\"[]\") private __get(index: i32): T {\n if (index >= this.length_) throw new RangeError(E_INDEXOUTOFRANGE);\n var value = load(this.dataStart + (index << alignof()));\n if (isReference()) {\n if (!isNullable()) {\n if (!changetype(value)) throw new Error(E_HOLEYARRAY);\n }\n }\n return value;\n }\n\n @unsafe @operator(\"{}\") private __uget(index: i32): T {\n return load(this.dataStart + (index << alignof()));\n }\n\n @operator(\"[]=\") private __set(index: i32, value: T): void {\n if (index >= this.length_) {\n if (index < 0) throw new RangeError(E_INDEXOUTOFRANGE);\n ensureCapacity(changetype(this), index + 1, alignof());\n this.length_ = index + 1;\n }\n this.__uset(index, value);\n }\n\n @unsafe @operator(\"{}=\") private __uset(index: i32, value: T): void {\n store(this.dataStart + (index << alignof()), value);\n if (isManaged()) {\n __link(changetype(this), changetype(value), true);\n }\n }\n\n at(index: i32): T {\n var len = this.length_;\n index += select(0, len, index >= 0);\n if (index >= len) throw new RangeError(E_INDEXOUTOFRANGE);\n var value = load(this.dataStart + (index << alignof()));\n if (isReference()) {\n if (!isNullable()) {\n if (!changetype(value)) throw new Error(E_HOLEYARRAY);\n }\n }\n return value;\n }\n\n fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): Array {\n if (isManaged()) {\n FILL(this.dataStart, this.length_, changetype(value), start, end);\n __link(changetype(this), changetype(value), false);\n } else {\n FILL(this.dataStart, this.length_, value, start, end);\n }\n return this;\n }\n\n includes(value: T, fromIndex: i32 = 0): bool {\n if (isFloat()) {\n let len = this.length_;\n if (len == 0 || fromIndex >= len) return false;\n if (fromIndex < 0) fromIndex = max(len + fromIndex, 0);\n let ptr = this.dataStart;\n while (fromIndex < len) {\n let elem = load(ptr + (fromIndex << alignof()));\n // @ts-ignore\n if (elem == value || isNaN(elem) & isNaN(value)) return true;\n ++fromIndex;\n }\n return false;\n } else {\n return this.indexOf(value, fromIndex) >= 0;\n }\n }\n\n indexOf(value: T, fromIndex: i32 = 0): i32 {\n var len = this.length_;\n if (len == 0 || fromIndex >= len) return -1;\n if (fromIndex < 0) fromIndex = max(len + fromIndex, 0);\n var ptr = this.dataStart;\n while (fromIndex < len) {\n if (load(ptr + (fromIndex << alignof())) == value) return fromIndex;\n ++fromIndex;\n }\n return -1;\n }\n\n lastIndexOf(value: T, fromIndex: i32 = this.length_): i32 {\n var len = this.length_;\n if (len == 0) return -1;\n if (fromIndex < 0) fromIndex = len + fromIndex;\n else if (fromIndex >= len) fromIndex = len - 1;\n var ptr = this.dataStart;\n while (fromIndex >= 0) {\n if (load(ptr + (fromIndex << alignof())) == value) return fromIndex;\n --fromIndex;\n }\n return -1;\n }\n\n push(value: T): i32 {\n var oldLen = this.length_;\n var len = oldLen + 1;\n ensureCapacity(changetype(this), len, alignof());\n if (isManaged()) {\n store(this.dataStart + (oldLen << alignof()), changetype(value));\n __link(changetype(this), changetype(value), true);\n } else {\n store(this.dataStart + (oldLen << alignof()), value);\n }\n this.length_ = len;\n return len;\n }\n\n concat(other: Array): Array {\n var thisLen = this.length_;\n var otherLen = other.length_;\n var outLen = thisLen + otherLen;\n if (outLen > BLOCK_MAXSIZE >>> alignof()) throw new Error(E_INVALIDLENGTH);\n var out = changetype>(__newArray(outLen, alignof(), idof>()));\n var outStart = out.dataStart;\n var thisSize = thisLen << alignof();\n if (isManaged()) {\n let thisStart = this.dataStart;\n for (let offset: usize = 0; offset < thisSize; offset += sizeof()) {\n let ref = load(thisStart + offset);\n store(outStart + offset, ref);\n __link(changetype(out), ref, true);\n }\n outStart += thisSize;\n let otherStart = other.dataStart;\n let otherSize = otherLen << alignof();\n for (let offset: usize = 0; offset < otherSize; offset += sizeof()) {\n let ref = load(otherStart + offset);\n store(outStart + offset, ref);\n __link(changetype(out), ref, true);\n }\n } else {\n memory.copy(outStart, this.dataStart, thisSize);\n memory.copy(outStart + thisSize, other.dataStart, otherLen << alignof());\n }\n return out;\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Array {\n var ptr = this.dataStart;\n var len = this.length_;\n\n end = min(end, len);\n\n var to = target < 0 ? max(len + target, 0) : min(target, len);\n var from = start < 0 ? max(len + start, 0) : min(start, len);\n var last = end < 0 ? max(len + end, 0) : min(end, len);\n var count = min(last - from, len - to);\n\n memory.copy( // is memmove\n ptr + (to << alignof()),\n ptr + (from << alignof()),\n count << alignof()\n );\n return this;\n }\n\n pop(): T {\n var len = this.length_;\n if (len < 1) throw new RangeError(E_EMPTYARRAY);\n var val = load(this.dataStart + ((--len) << alignof()));\n this.length_ = len;\n return val;\n }\n\n forEach(fn: (value: T, index: i32, array: Array) => void): void {\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n fn(load(this.dataStart + (i << alignof())), i, this);\n }\n }\n\n map(fn: (value: T, index: i32, array: Array) => U): Array {\n var len = this.length_;\n var out = changetype>(__newArray(len, alignof(), idof>()));\n var outStart = out.dataStart;\n for (let i = 0; i < min(len, this.length_); ++i) {\n let result = fn(load(this.dataStart + (i << alignof())), i, this);\n store(outStart + (i << alignof()), result);\n if (isManaged()) {\n __link(changetype(out), changetype(result), true);\n }\n }\n return out;\n }\n\n filter(fn: (value: T, index: i32, array: Array) => bool): Array {\n var result = changetype>(__newArray(0, alignof(), idof>()));\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n let value = load(this.dataStart + (i << alignof()));\n if (fn(value, i, this)) result.push(value);\n }\n return result;\n }\n\n reduce(\n fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var acc = initialValue;\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n acc = fn(acc, load(this.dataStart + (i << alignof())), i, this);\n }\n return acc;\n }\n\n reduceRight(\n fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var acc = initialValue;\n for (let i = this.length_ - 1; i >= 0; --i) {\n acc = fn(acc, load(this.dataStart + (i << alignof())), i, this);\n }\n return acc;\n }\n\n shift(): T {\n var len = this.length_;\n if (len < 1) throw new RangeError(E_EMPTYARRAY);\n var base = this.dataStart;\n var element = load(base);\n var lastIndex = len - 1;\n memory.copy(\n base,\n base + sizeof(),\n lastIndex << alignof()\n );\n if (isReference()) {\n store(base + (lastIndex << alignof()), 0);\n } else {\n // @ts-ignore\n store(base + (lastIndex << alignof()), 0);\n }\n this.length_ = lastIndex;\n return element;\n }\n\n some(fn: (value: T, index: i32, array: Array) => bool): bool {\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n if (fn(load(this.dataStart + (i << alignof())), i, this)) return true;\n }\n return false;\n }\n\n unshift(value: T): i32 {\n var len = this.length_ + 1;\n ensureCapacity(changetype(this), len, alignof());\n var ptr = this.dataStart;\n memory.copy(\n ptr + sizeof(),\n ptr,\n (len - 1) << alignof()\n );\n store(ptr, value);\n if (isManaged()) {\n __link(changetype(this), changetype(value), true);\n }\n this.length_ = len;\n return len;\n }\n\n slice(start: i32 = 0, end: i32 = i32.MAX_VALUE): Array {\n var len = this.length_;\n start = start < 0 ? max(start + len, 0) : min(start, len);\n end = end < 0 ? max(end + len, 0) : min(end , len);\n len = max(end - start, 0);\n var slice = changetype>(__newArray(len, alignof(), idof>()));\n var sliceBase = slice.dataStart;\n var thisBase = this.dataStart + (start << alignof());\n if (isManaged()) {\n let off = 0;\n let end = len << alignof();\n while (off < end) {\n let ref = load(thisBase + off);\n store(sliceBase + off, ref);\n __link(changetype(slice), ref, true);\n off += sizeof();\n }\n } else {\n memory.copy(sliceBase, thisBase, len << alignof());\n }\n return slice;\n }\n\n splice(start: i32, deleteCount: i32 = i32.MAX_VALUE): Array {\n var len = this.length_;\n start = start < 0 ? max(len + start, 0) : min(start, len);\n deleteCount = max(min(deleteCount, len - start), 0);\n var result = changetype>(__newArray(deleteCount, alignof(), idof>()));\n var resultStart = result.dataStart;\n var thisStart = this.dataStart;\n var thisBase = thisStart + (start << alignof());\n memory.copy(\n resultStart,\n thisBase,\n deleteCount << alignof()\n );\n var offset = start + deleteCount;\n if (len != offset) {\n memory.copy(\n thisBase,\n thisStart + (offset << alignof()),\n (len - offset) << alignof()\n );\n }\n this.length_ = len - deleteCount;\n return result;\n }\n\n reverse(): Array {\n REVERSE(this.dataStart, this.length_);\n return this;\n }\n\n sort(comparator: (a: T, b: T) => i32 = COMPARATOR()): Array {\n SORT(this.dataStart, this.length_, comparator);\n return this;\n }\n\n join(separator: string = \",\"): string {\n var ptr = this.dataStart;\n var len = this.length_;\n if (isBoolean()) return joinBooleanArray(ptr, len, separator);\n if (isInteger()) return joinIntegerArray(ptr, len, separator);\n if (isFloat()) return joinFloatArray(ptr, len, separator);\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (isString()) return joinStringArray(ptr, len, separator);\n }\n // For rest objects and arrays use general join routine\n if (isReference()) return joinReferenceArray(ptr, len, separator);\n ERROR(\"unspported element type\");\n return unreachable();\n }\n\n flat(): T {\n if (!isArray()) {\n ERROR(\"Cannot call flat() on Array where T is not an Array.\");\n }\n // Get the length and data start values\n var ptr = this.dataStart;\n var len = this.length_;\n\n // calculate the end size with an initial pass\n var size = 0;\n for (let i = 0; i < len; ++i) {\n let child = load(ptr + (i << alignof()));\n size += child == 0 ? 0 : load(child, offsetof(\"length_\"));\n }\n\n // calculate the byteLength of the resulting backing ArrayBuffer\n const align = alignof>();\n var byteLength = size << align;\n var outBuffer = changetype(__new(byteLength, idof()));\n\n // create the return value and initialize it\n var outArray = changetype(__new(offsetof(), idof()));\n store(changetype(outArray), size, offsetof(\"length_\"));\n\n // byteLength, dataStart, and buffer are all readonly\n store(changetype(outArray), byteLength, offsetof(\"byteLength\"));\n store(changetype(outArray), changetype(outBuffer), offsetof(\"dataStart\"));\n store(changetype(outArray), changetype(outBuffer), offsetof(\"buffer\"));\n __link(changetype(outArray), changetype(outBuffer), false);\n\n // set the elements\n var resultOffset: usize = 0;\n for (let i = 0; i < len; ++i) { // for each child\n let child = load(ptr + (i << alignof()));\n\n // ignore null arrays\n if (!child) continue;\n\n // copy the underlying buffer data to the result buffer\n let childDataLength = load(child, offsetof(\"length_\")) << align;\n memory.copy(\n changetype(outBuffer) + resultOffset,\n load(child, offsetof(\"dataStart\")),\n childDataLength\n );\n\n // advance the result length\n resultOffset += childDataLength;\n }\n\n // if the `valueof` type is managed, we must link each reference\n if (isManaged>()) {\n for (let i = 0; i < size; ++i) {\n let ref = load(changetype(outBuffer) + (i << usize(alignof>())));\n __link(changetype(outBuffer), ref, true);\n }\n }\n\n return outArray;\n }\n\n toString(): string {\n return this.join();\n }\n\n // RT integration\n\n @unsafe private __visit(cookie: u32): void {\n if (isManaged()) {\n let cur = this.dataStart;\n let end = cur + (this.length_ << alignof());\n while (cur < end) {\n let val = load(cur);\n if (val) __visit(val, cookie);\n cur += sizeof();\n }\n }\n __visit(changetype(this.buffer), cookie);\n }\n}\n","// Common error messages for use across the standard library. Keeping error messages compact\n// and reusing them where possible ensures minimal static data in binaries.\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INDEXOUTOFRANGE: string = \"Index out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_VALUEOUTOFRANGE: string = \"Value out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDLENGTH: string = \"Invalid length\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_EMPTYARRAY: string = \"Array is empty\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_HOLEYARRAY: string = \"Element type must be nullable if array is holey\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOTIMPLEMENTED: string = \"Not implemented\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_KEYNOTFOUND: string = \"Key does not exist\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_ALLOCATION_TOO_LARGE: string = \"Allocation too large\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_ALREADY_PINNED: string = \"Object already pinned\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOT_PINNED: string = \"Object is not pinned\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_URI_MALFORMED: string = \"URI malformed\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDDATE: string = \"Invalid Date\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_UNPAIRED_SURROGATE: string = \"Unpaired surrogate\";\n"]} \ No newline at end of file +{"version":3,"sources":["~lib/rt/common.ts","~lib/rt/tlsf.ts","~lib/shared/typeinfo.ts","~lib/rt/itcms.ts","assembly/perlin.ts","~lib/util/math.ts","~lib/util/number.ts","~lib/util/string.ts","~lib/math.ts","~lib/shared/runtime.ts","~lib/util/sort.ts","~lib/array.ts","~lib/util/error.ts"],"names":[],"mappings":"yGWiHI,AAAI,EAAc,AAAK,SAAmC,eAO1D,AANoB,MAAkB,EAAgB,6CPvDhD,EAAO,uBAEJ,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAEL,EAAI,KAEJ,AAAC,GAAI,KAhChB,6QAJW,AAJX,AAAO,EAAI,GAAI,GAAK,EAAK,EAAI,UAAI,WAAM,qCAInB,mDAAT,AAJX,AAAO,EAAI,GAAI,GAAK,EAAK,EAAI,UAAI,WAAM,eAI5B,cAAS,2DAAT,iBAAS,0CAAT,AAJJ,EAAI,GAAI,GAAK,EAAK,EAAI,UAAI,WAAM,aAI5B,qBAAS","sourceRoot":"./release","sourcesContent":["// Alignment guarantees\n\n// @ts-ignore: decorator\n@inline export const AL_BITS: u32 = 4; // 16 bytes to fit up to v128\n// @ts-ignore: decorator\n@inline export const AL_SIZE: usize = 1 << AL_BITS;\n// @ts-ignore: decorator\n@inline export const AL_MASK: usize = AL_SIZE - 1;\n\n// Extra debugging\n\n// @ts-ignore: decorator\n@inline export const DEBUG = true;\n// @ts-ignore: decorator\n@inline export const TRACE = false;\n// @ts-ignore: decorator\n@inline export const RTRACE = isDefined(ASC_RTRACE);\n// @ts-ignore: decorator\n@inline export const PROFILE = isDefined(ASC_PROFILE);\n\n// Memory manager\n\n// ╒════════════ Memory manager block 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// │ MM info │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class BLOCK {\n /** Memory manager info. */\n mmInfo: usize;\n}\n\n/** Overhead of a memory manager block. */\n// @ts-ignore: decorator\n@inline export const BLOCK_OVERHEAD: usize = offsetof();\n\n/** Maximum size of a memory manager block's payload. */\n// @ts-ignore: decorator\n@inline export const BLOCK_MAXSIZE: usize = (1 << 30) - BLOCK_OVERHEAD;\n\n// Garbage collector\n\n// ╒══════════ Garbage collector 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// │ Memory manager block │ -20\n// ╞═══════════════════════════════════════════════════════════════╡\n// │ GC info │ -16\n// ├───────────────────────────────────────────────────────────────┤\n// │ GC info │ -12\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT id │ -8\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT size │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class OBJECT extends BLOCK {\n /** Garbage collector info. */\n gcInfo: u32;\n /** Garbage collector info. */\n gcInfo2: u32;\n /** Runtime class id. */\n rtId: u32;\n /** Runtime object size. */\n rtSize: u32;\n}\n\n/** Overhead of a garbage collector object. Excludes memory manager block overhead. */\n// @ts-ignore: decorator\n@inline export const OBJECT_OVERHEAD: usize = (offsetof() - BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK;\n\n/** Maximum size of a garbage collector object's payload. */\n// @ts-ignore: decorator\n@inline export const OBJECT_MAXSIZE: usize = BLOCK_MAXSIZE - OBJECT_OVERHEAD;\n\n/** Total of memory manager and garbage collector overhead. */\n// @ts-ignore: decorator\n@inline export const TOTAL_OVERHEAD: usize = BLOCK_OVERHEAD + OBJECT_OVERHEAD;\n","import { AL_BITS, AL_SIZE, AL_MASK, DEBUG, BLOCK, BLOCK_OVERHEAD, BLOCK_MAXSIZE } from \"./common\";\nimport { oninit, onalloc, onresize, onmove, onfree } from \"./rtrace\";\nimport { E_ALLOCATION_TOO_LARGE } from \"../util/error\";\n\n// === The TLSF (Two-Level Segregate Fit) memory allocator ===\n// see: http://www.gii.upv.es/tlsf/\n\n// - `ffs(x)` is equivalent to `ctz(x)` with x != 0\n// - `fls(x)` is equivalent to `sizeof(x) * 8 - clz(x) - 1`\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\n// @ts-ignore: decorator\n@inline const SL_BITS: u32 = 4;\n// @ts-ignore: decorator\n@inline const SL_SIZE: u32 = 1 << SL_BITS;\n\n// @ts-ignore: decorator\n@inline const SB_BITS: u32 = SL_BITS + AL_BITS;\n// @ts-ignore: decorator\n@inline const SB_SIZE: u32 = 1 << SB_BITS;\n\n// @ts-ignore: decorator\n@inline const FL_BITS: u32 = 31 - SB_BITS;\n\n// [00]: < 256B (SB) [12]: < 1M\n// [01]: < 512B [13]: < 2M\n// [02]: < 1K [14]: < 4M\n// [03]: < 2K [15]: < 8M\n// [04]: < 4K [16]: < 16M\n// [05]: < 8K [17]: < 32M\n// [06]: < 16K [18]: < 64M\n// [07]: < 32K [19]: < 128M\n// [08]: < 64K [20]: < 256M\n// [09]: < 128K [21]: < 512M\n// [10]: < 256K [22]: <= 1G - OVERHEAD\n// [11]: < 512K\n// VMs limit to 2GB total (currently), making one 1G block max (or three 512M etc.) due to block overhead\n\n// Tags stored in otherwise unused alignment bits\n\n// @ts-ignore: decorator\n@inline const FREE: usize = 1 << 0;\n// @ts-ignore: decorator\n@inline const LEFTFREE: usize = 1 << 1;\n// @ts-ignore: decorator\n@inline const TAGS_MASK: usize = FREE | LEFTFREE; // <= AL_MASK\n\n// ╒════════════════════ Block 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 overhead\n// ╞>ptr═══════════════════════════════════════════════════════╧═╧═╡ │ ┘\n// │ if free: ◄ prev │ ◄─┤ usize\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ if free: next ► │ ◄─┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... │ │ >= 0\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ if free: back ▲ │ ◄─┘\n// └───────────────────────────────────────────────────────────────┘ >= MIN SIZE\n// F: FREE, L: LEFTFREE\n@unmanaged export class Block extends BLOCK {\n\n /** Previous free block, if any. Only valid if free, otherwise part of payload. */\n prev: Block | null;\n /** Next free block, if any. Only valid if free, otherwise part of payload. */\n next: Block | null;\n\n // If the block is free, there is a 'back'reference at its end pointing at its start.\n}\n\n// Block constants. A block must have a minimum size of three pointers so it can hold `prev`,\n// `next` and `back` if free.\n\n// @ts-ignore: decorator\n@inline const BLOCK_MINSIZE: usize = ((3 * sizeof() + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD; // prev + next + back\n// @ts-ignore: decorator\n// @inline const BLOCK_MAXSIZE: usize = 1 << (FL_BITS + SB_BITS - 1); // exclusive, lives in common.ts\n\n/** Gets the left block of a block. Only valid if the left block is free. */\n// @ts-ignore: decorator\n@inline function GETFREELEFT(block: Block): Block {\n return load(changetype(block) - sizeof());\n}\n\n/** Gets the right block of a block by advancing to the right by its size. */\n// @ts-ignore: decorator\n@inline function GETRIGHT(block: Block): Block {\n return changetype(changetype(block) + BLOCK_OVERHEAD + (block.mmInfo & ~TAGS_MASK));\n}\n\n// ╒═════════════════════ Root 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// │ slMap[22] │ ◄─┘ │\n// ╞═══════════════════════════════════════════════════════════════╡ usize\n// │ head[0] │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ ... │ ◄────┤\n// ├───────────────────────────────────────────────────────────────┤ │\n// │ head[367] │ ◄────┤\n// ╞═══════════════════════════════════════════════════════════════╡ │\n// │ tail │ ◄────┘\n// └───────────────────────────────────────────────────────────────┘ SIZE ┘\n// S: Small blocks map\n@unmanaged class Root {\n /** First level bitmap. */\n flMap: usize;\n}\n\n// Root constants. Where stuff is stored inside of the root structure.\n\n// @ts-ignore: decorator\n@inline const SL_START: usize = sizeof();\n// @ts-ignore: decorator\n@inline const SL_END: usize = SL_START + (FL_BITS << alignof());\n// @ts-ignore: decorator\n@inline const HL_START: usize = (SL_END + AL_MASK) & ~AL_MASK;\n// @ts-ignore: decorator\n@inline const HL_END: usize = HL_START + FL_BITS * SL_SIZE * sizeof();\n// @ts-ignore: decorator\n@inline const ROOT_SIZE: usize = HL_END + sizeof();\n\n// @ts-ignore: decorator\n@lazy export var ROOT: Root;\n\n/** Gets the second level map of the specified first level. */\n// @ts-ignore: decorator\n@inline function GETSL(root: Root, fl: usize): u32 {\n return load(\n changetype(root) + (fl << alignof()),\n SL_START\n );\n}\n\n/** Sets the second level map of the specified first level. */\n// @ts-ignore: decorator\n@inline function SETSL(root: Root, fl: usize, slMap: u32): void {\n store(\n changetype(root) + (fl << alignof()),\n slMap,\n SL_START\n );\n}\n\n/** Gets the head of the free list for the specified combination of first and second level. */\n// @ts-ignore: decorator\n@inline function GETHEAD(root: Root, fl: usize, sl: u32): Block | null {\n return load(\n changetype(root) + (((fl << SL_BITS) + sl) << alignof()),\n HL_START\n );\n}\n\n/** Sets the head of the free list for the specified combination of first and second level. */\n// @ts-ignore: decorator\n@inline function SETHEAD(root: Root, fl: usize, sl: u32, head: Block | null): void {\n store(\n changetype(root) + (((fl << SL_BITS) + sl) << alignof()),\n head,\n HL_START\n );\n}\n\n/** Gets the tail block.. */\n// @ts-ignore: decorator\n@inline function GETTAIL(root: Root): Block {\n return load(\n changetype(root),\n HL_END\n );\n}\n\n/** Sets the tail block. */\n// @ts-ignore: decorator\n@inline function SETTAIL(root: Root, tail: Block): void {\n store(\n changetype(root),\n tail,\n HL_END\n );\n}\n\n/** Inserts a previously used block back into the free list. */\nfunction insertBlock(root: Root, block: Block): void {\n if (DEBUG) assert(block); // cannot be null\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(blockInfo & FREE); // must be free\n\n var right = GETRIGHT(block);\n var rightInfo = right.mmInfo;\n\n // merge with right block if also free\n if (rightInfo & FREE) {\n removeBlock(root, right);\n block.mmInfo = blockInfo = blockInfo + BLOCK_OVERHEAD + (rightInfo & ~TAGS_MASK); // keep block tags\n right = GETRIGHT(block);\n rightInfo = right.mmInfo;\n // 'back' is set below\n }\n\n // merge with left block if also free\n if (blockInfo & LEFTFREE) {\n let left = GETFREELEFT(block);\n let leftInfo = left.mmInfo;\n if (DEBUG) assert(leftInfo & FREE); // must be free according to right tags\n removeBlock(root, left);\n block = left;\n block.mmInfo = blockInfo = leftInfo + BLOCK_OVERHEAD + (blockInfo & ~TAGS_MASK); // keep left tags\n // 'back' is set below\n }\n\n right.mmInfo = rightInfo | LEFTFREE;\n // reference to right is no longer used now, hence rightInfo is not synced\n\n // we now know the size of the block\n var size = blockInfo & ~TAGS_MASK;\n if (DEBUG) assert(size >= BLOCK_MINSIZE); // must be a valid size\n if (DEBUG) assert(changetype(block) + BLOCK_OVERHEAD + size == changetype(right)); // must match\n\n // set 'back' to itself at the end of block\n store(changetype(right) - sizeof(), block);\n\n // mapping_insert\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size >> AL_BITS);\n } else {\n const inv: usize = sizeof() * 8 - 1;\n let boundedSize = min(size, BLOCK_MAXSIZE);\n fl = inv - clz(boundedSize);\n sl = ((boundedSize >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\n\n // perform insertion\n var head = GETHEAD(root, fl, sl);\n block.prev = null;\n block.next = head;\n if (head) head.prev = block;\n SETHEAD(root, fl, sl, block);\n\n // update first and second level maps\n root.flMap |= (1 << fl);\n SETSL(root, fl, GETSL(root, fl) | (1 << sl));\n}\n\n/** Removes a free block from internal lists. */\nfunction removeBlock(root: Root, block: Block): void {\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(blockInfo & FREE); // must be free\n var size = blockInfo & ~TAGS_MASK;\n if (DEBUG) assert(size >= BLOCK_MINSIZE); // 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_BITS);\n } else {\n const inv: usize = sizeof() * 8 - 1;\n let boundedSize = min(size, BLOCK_MAXSIZE);\n fl = inv - clz(boundedSize);\n sl = ((boundedSize >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\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 == GETHEAD(root, fl, sl)) {\n SETHEAD(root, fl, sl, next);\n\n // clear second level map if head is empty now\n if (!next) {\n let slMap = GETSL(root, fl);\n SETSL(root, fl, slMap &= ~(1 << sl));\n\n // clear first level map if second level is empty now\n if (!slMap) root.flMap &= ~(1 << fl);\n }\n }\n // note: does not alter left/back because it is likely that splitting\n // is performed afterwards, invalidating those changes. so, the caller\n // must perform those updates.\n}\n\n/** Searches for a free block of at least the specified size. */\nfunction searchBlock(root: Root, size: usize): Block | null {\n // size was already asserted by caller\n\n // mapping_search\n var fl: usize, sl: u32;\n if (size < SB_SIZE) {\n fl = 0;\n sl = (size >> AL_BITS);\n } else {\n const halfMaxSize = BLOCK_MAXSIZE >> 1; // don't round last fl\n const inv: usize = sizeof() * 8 - 1;\n const invRound = inv - SL_BITS;\n let requestSize = size < halfMaxSize\n ? size + (1 << (invRound - clz(size))) - 1\n : size;\n fl = inv - clz(requestSize);\n sl = ((requestSize >> (fl - SL_BITS)) ^ (1 << SL_BITS));\n fl -= SB_BITS - 1;\n }\n if (DEBUG) assert(fl < FL_BITS && sl < SL_SIZE); // fl/sl out of range\n\n // search second level\n var slMap = GETSL(root, fl) & (~0 << sl);\n var head: Block | null = null;\n if (!slMap) {\n // search next larger first level\n let flMap = root.flMap & (~0 << (fl + 1));\n if (!flMap) {\n head = null;\n } else {\n fl = ctz(flMap);\n slMap = GETSL(root, fl);\n if (DEBUG) assert(slMap); // can't be zero if fl points here\n head = GETHEAD(root, fl, ctz(slMap));\n }\n } else {\n head = GETHEAD(root, fl, ctz(slMap));\n }\n return head;\n}\n\n/** Prepares the specified block before (re-)use, possibly splitting it. */\nfunction prepareBlock(root: Root, block: Block, size: usize): void {\n // size was already asserted by caller\n\n var blockInfo = block.mmInfo;\n if (DEBUG) assert(!((size + BLOCK_OVERHEAD) & AL_MASK)); // size must be aligned so the new block is\n\n // split if the block can hold another MINSIZE block incl. overhead\n var remaining = (blockInfo & ~TAGS_MASK) - size;\n if (remaining >= BLOCK_OVERHEAD + BLOCK_MINSIZE) {\n block.mmInfo = size | (blockInfo & LEFTFREE); // also discards FREE\n\n let spare = changetype(changetype(block) + BLOCK_OVERHEAD + size);\n spare.mmInfo = (remaining - BLOCK_OVERHEAD) | FREE; // not LEFTFREE\n insertBlock(root, spare); // also sets 'back'\n\n // otherwise tag block as no longer FREE and right as no longer LEFTFREE\n } else {\n block.mmInfo = blockInfo & ~FREE;\n GETRIGHT(block).mmInfo &= ~LEFTFREE;\n }\n}\n\n/** Adds more memory to the pool. */\nfunction addMemory(root: Root, start: usize, end: usize): bool {\n if (DEBUG) assert(start <= end); // must be valid\n start = ((start + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;\n end &= ~AL_MASK;\n\n var tail = GETTAIL(root);\n var tailInfo: usize = 0;\n if (tail) { // more memory\n if (DEBUG) assert(start >= changetype(tail) + BLOCK_OVERHEAD);\n\n // merge with current tail if adjacent\n const offsetToTail = AL_SIZE;\n if (start - offsetToTail == changetype(tail)) {\n start -= offsetToTail;\n tailInfo = tail.mmInfo;\n } else {\n // We don't do this, but a user might `memory.grow` manually\n // leading to non-adjacent pages managed by TLSF.\n }\n\n } else if (DEBUG) { // first memory\n assert(start >= changetype(root) + 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_OVERHEAD + BLOCK_MINSIZE + BLOCK_OVERHEAD) {\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_OVERHEAD;\n var left = changetype(start);\n left.mmInfo = leftSize | FREE | (tailInfo & LEFTFREE);\n left.prev = null;\n left.next = null;\n\n // tail is a zero-length used block\n tail = changetype(start + BLOCK_OVERHEAD + leftSize);\n tail.mmInfo = 0 | LEFTFREE;\n SETTAIL(root, tail);\n\n insertBlock(root, left); // also merges with free left before tail / sets 'back'\n\n return true;\n}\n\n/** Grows memory to fit at least another block of the specified size. */\nfunction growMemory(root: Root, size: usize): void {\n if (ASC_LOW_MEMORY_LIMIT) {\n unreachable();\n return;\n }\n // Here, both rounding performed in searchBlock ...\n const halfMaxSize = BLOCK_MAXSIZE >> 1;\n if (size < halfMaxSize) { // don't round last fl\n const invRound = (sizeof() * 8 - 1) - SL_BITS;\n size += (1 << (invRound - clz(size))) - 1;\n }\n // and additional BLOCK_OVERHEAD must be taken into account. If we are going\n // to merge with the tail block, that's one time, otherwise it's two times.\n var pagesBefore = memory.size();\n size += BLOCK_OVERHEAD << usize((pagesBefore << 16) - BLOCK_OVERHEAD != changetype(GETTAIL(root)));\n var pagesNeeded = (((size + 0xffff) & ~0xffff) >>> 16);\n var pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) unreachable();\n }\n var pagesAfter = memory.size();\n addMemory(root, pagesBefore << 16, pagesAfter << 16);\n}\n\n/** Computes the size (excl. header) of a block. */\nfunction computeSize(size: usize): usize {\n // Size must be large enough and aligned minus preceeding overhead\n return size <= BLOCK_MINSIZE\n ? BLOCK_MINSIZE\n : ((size + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;\n}\n\n/** Prepares and checks an allocation size. */\nfunction prepareSize(size: usize): usize {\n if (size > BLOCK_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n return computeSize(size);\n}\n\n/** Initializes the root structure. */\nfunction initialize(): void {\n if (isDefined(ASC_RTRACE)) oninit(__heap_base);\n var rootOffset = (__heap_base + AL_MASK) & ~AL_MASK;\n var pagesBefore = memory.size();\n var pagesNeeded = ((((rootOffset + ROOT_SIZE) + 0xffff) & ~0xffff) >>> 16);\n if (pagesNeeded > pagesBefore && memory.grow(pagesNeeded - pagesBefore) < 0) unreachable();\n var root = changetype(rootOffset);\n root.flMap = 0;\n SETTAIL(root, changetype(0));\n for (let fl: usize = 0; fl < FL_BITS; ++fl) {\n SETSL(root, fl, 0);\n for (let sl: u32 = 0; sl < SL_SIZE; ++sl) {\n SETHEAD(root, fl, sl, null);\n }\n }\n var memStart = rootOffset + ROOT_SIZE;\n if (ASC_LOW_MEMORY_LIMIT) {\n const memEnd = ASC_LOW_MEMORY_LIMIT & ~AL_MASK;\n if (memStart <= memEnd) addMemory(root, memStart, memEnd);\n else unreachable(); // low memory limit already exceeded\n } else {\n addMemory(root, memStart, memory.size() << 16);\n }\n ROOT = root;\n}\n\n/** Allocates a block of the specified size. */\nexport function allocateBlock(root: Root, size: usize): Block {\n var payloadSize = prepareSize(size);\n var block = searchBlock(root, payloadSize);\n if (!block) {\n growMemory(root, payloadSize);\n block = changetype(searchBlock(root, payloadSize));\n if (DEBUG) assert(block); // must be found now\n }\n if (DEBUG) assert((block.mmInfo & ~TAGS_MASK) >= payloadSize); // must fit\n removeBlock(root, block);\n prepareBlock(root, block, payloadSize);\n if (isDefined(ASC_RTRACE)) onalloc(block);\n return block;\n}\n\n/** Reallocates a block to the specified size. */\nexport function reallocateBlock(root: Root, block: Block, size: usize): Block {\n var payloadSize = prepareSize(size);\n var blockInfo = block.mmInfo;\n var blockSize = blockInfo & ~TAGS_MASK;\n\n // possibly split and update runtime size if it still fits\n if (payloadSize <= blockSize) {\n prepareBlock(root, block, payloadSize);\n if (isDefined(ASC_RTRACE)) {\n if (payloadSize != blockSize) onresize(block, BLOCK_OVERHEAD + blockSize);\n }\n return block;\n }\n\n // merge with right free block if merger is large enough\n var right = GETRIGHT(block);\n var rightInfo = right.mmInfo;\n if (rightInfo & FREE) {\n let mergeSize = blockSize + BLOCK_OVERHEAD + (rightInfo & ~TAGS_MASK);\n if (mergeSize >= payloadSize) {\n removeBlock(root, right);\n block.mmInfo = (blockInfo & TAGS_MASK) | mergeSize;\n prepareBlock(root, block, payloadSize);\n if (isDefined(ASC_RTRACE)) onresize(block, BLOCK_OVERHEAD + blockSize);\n return block;\n }\n }\n\n // otherwise move the block\n return moveBlock(root, block, size);\n}\n\n/** Moves a block to a new one of the specified size. */\nfunction moveBlock(root: Root, block: Block, newSize: usize): Block {\n var newBlock = allocateBlock(root, newSize);\n memory.copy(changetype(newBlock) + BLOCK_OVERHEAD, changetype(block) + BLOCK_OVERHEAD, block.mmInfo & ~TAGS_MASK);\n if (changetype(block) >= __heap_base) {\n if (isDefined(ASC_RTRACE)) onmove(block, newBlock);\n freeBlock(root, block);\n }\n return newBlock;\n}\n\n/** Frees a block. */\nexport function freeBlock(root: Root, block: Block): void {\n if (isDefined(ASC_RTRACE)) onfree(block);\n block.mmInfo = block.mmInfo | FREE;\n insertBlock(root, block);\n}\n\n/** Checks that a used block is valid to be freed or reallocated. */\nfunction checkUsedBlock(ptr: usize): Block {\n var block = changetype(ptr - BLOCK_OVERHEAD);\n assert(\n ptr != 0 && !(ptr & AL_MASK) && // must exist and be aligned\n !(block.mmInfo & FREE) // must be used\n );\n return block;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __alloc(size: usize): usize {\n if (!ROOT) initialize();\n return changetype(allocateBlock(ROOT, size)) + BLOCK_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __realloc(ptr: usize, size: usize): usize {\n if (!ROOT) initialize();\n return (ptr < __heap_base\n ? changetype(moveBlock(ROOT, checkUsedBlock(ptr), size))\n : changetype(reallocateBlock(ROOT, checkUsedBlock(ptr), size))\n ) + BLOCK_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __free(ptr: usize): void {\n if (ptr < __heap_base) return;\n if (!ROOT) initialize();\n freeBlock(ROOT, checkUsedBlock(ptr));\n}\n","// This file is shared with the compiler and must remain portable\n\n// ╒═══════════════════ Typeinfo interpretation ═══════════════════╕\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// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤ ◄─ __rtti_base\n// │ count │\n// ╞═══════════════════════════════════════════════════════════════╡ ┐\n// │ Typeinfo#flags [id=0] │ id < count\n// ├ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┤\n// │ Typeinfo#base [id=0] │\n// ├───────────────────────────────────────────────────────────────┤\n// │ ... │\n\n/** Runtime type information data structure. */\n@unmanaged\nexport class Typeinfo {\n /** Flags describing the shape of this class type. */\n flags: TypeinfoFlags = TypeinfoFlags.NONE;\n /** Base class id or `0` if none. */\n base: u32 = 0;\n}\n\n/** Runtime type information flags. */\nexport const enum TypeinfoFlags {\n /** No specific flags. */\n NONE = 0,\n /** Type is an `ArrayBufferView`. */\n ARRAYBUFFERVIEW = 1 << 0,\n /** Type is an `Array`. */\n ARRAY = 1 << 1,\n /** Type is a `StaticArray`. */\n STATICARRAY = 1 << 2,\n /** Type is a `Set`. */\n SET = 1 << 3,\n /** Type is a `Map`. */\n MAP = 1 << 4,\n /** Type has no outgoing pointers. */\n POINTERFREE = 1 << 5,\n /** Value alignment of 1 byte. */\n VALUE_ALIGN_0 = 1 << 6,\n /** Value alignment of 2 bytes. */\n VALUE_ALIGN_1 = 1 << 7,\n /** Value alignment of 4 bytes. */\n VALUE_ALIGN_2 = 1 << 8,\n /** Value alignment of 8 bytes. */\n VALUE_ALIGN_3 = 1 << 9,\n /** Value alignment of 16 bytes. */\n VALUE_ALIGN_4 = 1 << 10,\n /** Value is a signed type. */\n VALUE_SIGNED = 1 << 11,\n /** Value is a float type. */\n VALUE_FLOAT = 1 << 12,\n /** Value type is nullable. */\n VALUE_NULLABLE = 1 << 13,\n /** Value type is managed. */\n VALUE_MANAGED = 1 << 14,\n /** Key alignment of 1 byte. */\n KEY_ALIGN_0 = 1 << 15,\n /** Key alignment of 2 bytes. */\n KEY_ALIGN_1 = 1 << 16,\n /** Key alignment of 4 bytes. */\n KEY_ALIGN_2 = 1 << 17,\n /** Key alignment of 8 bytes. */\n KEY_ALIGN_3 = 1 << 18,\n /** Key alignment of 16 bytes. */\n KEY_ALIGN_4 = 1 << 19,\n /** Key is a signed type. */\n KEY_SIGNED = 1 << 20,\n /** Key is a float type. */\n KEY_FLOAT = 1 << 21,\n /** Key type is nullable. */\n KEY_NULLABLE = 1 << 22,\n /** Key type is managed. */\n KEY_MANAGED = 1 << 23\n}\n","import { BLOCK, BLOCK_OVERHEAD, OBJECT_OVERHEAD, OBJECT_MAXSIZE, TOTAL_OVERHEAD, DEBUG, TRACE, RTRACE, PROFILE } from \"./common\";\nimport { onvisit, oncollect, oninterrupt, onyield } from \"./rtrace\";\nimport { TypeinfoFlags } from \"../shared/typeinfo\";\nimport { E_ALLOCATION_TOO_LARGE, E_ALREADY_PINNED, E_NOT_PINNED } from \"../util/error\";\n\n// === ITCMS: An incremental Tri-Color Mark & Sweep garbage collector ===\n// Adapted from Bach Le's μgc, see: https://github.com/bullno1/ugc\n\n// ╒═════════════╤══════════════ Colors ═══════════════════════════╕\n// │ Color │ Meaning │\n// ├─────────────┼─────────────────────────────────────────────────┤\n// │ WHITE* │ Unprocessed │\n// │ BLACK* │ Processed │\n// │ GRAY │ Processed with unprocessed children │\n// │ TRANSPARENT │ Manually pinned (always reachable) │\n// └─────────────┴─────────────────────────────────────────────────┘\n// * flipped between cycles\n\n// @ts-ignore: decorator\n@lazy var white = 0;\n// @ts-ignore: decorator\n@inline const gray = 2;\n// @ts-ignore: decorator\n@inline const transparent = 3;\n// @ts-ignore: decorator\n@inline const COLOR_MASK = 3;\n\n/** Size in memory of all objects currently managed by the GC. */\n// @ts-ignore: decorator\n@lazy var total: usize = 0;\n\n/** Currently transitioning from SWEEP to MARK state. */\n// @ts-ignore: decorator\n@inline const STATE_IDLE = 0;\n/** Currently marking reachable objects. */\n// @ts-ignore: decorator\n@inline const STATE_MARK = 1;\n/** Currently sweeping unreachable objects. */\n// @ts-ignore: decorator\n@inline const STATE_SWEEP = 2;\n/** Current collector state. */\n// @ts-ignore: decorator\n@lazy var state = STATE_IDLE;\n\n// @ts-ignore: decorator\n@lazy var fromSpace = initLazy(changetype(memory.data(offsetof())));\n// @ts-ignore: decorator\n@lazy var toSpace = initLazy(changetype(memory.data(offsetof())));\n// @ts-ignore: decorator\n@lazy var pinSpace = initLazy(changetype(memory.data(offsetof())));\n// @ts-ignore: decorator\n@lazy var iter: Object; // null\n\nfunction initLazy(space: Object): Object {\n space.nextWithColor = changetype(space);\n space.prev = space;\n return space;\n}\n\n/** Visit cookie indicating scanning of an object. */\n// @ts-ignore: decorator\n@inline const VISIT_SCAN = 0;\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// │ Memory manager block │\n// ╞═══════════════════════════════════════════════════════════╤═══╡\n// │ next │ C │ = nextWithColor\n// ├───────────────────────────────────────────────────────────┴───┤\n// │ prev │\n// ├───────────────────────────────────────────────────────────────┤\n// │ rtId │\n// ├───────────────────────────────────────────────────────────────┤\n// │ rtSize │\n// ╞>ptr═══════════════════════════════════════════════════════════╡\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 Object extends BLOCK {\n /** Pointer to the next object with color flags stored in the alignment bits. */\n nextWithColor: usize; // *u32\n /** Pointer to the previous object. */\n prev: Object; // *u32\n /** Runtime id. */\n rtId: u32;\n /** Runtime size. */\n rtSize: u32;\n\n /** Gets the pointer to the next object. */\n get next(): Object {\n return changetype(this.nextWithColor & ~COLOR_MASK);\n }\n\n /** Sets the pointer to the next object. */\n set next(obj: Object) {\n this.nextWithColor = changetype(obj) | (this.nextWithColor & COLOR_MASK);\n }\n\n /** Gets this object's color. */\n get color(): i32 {\n return i32(this.nextWithColor & COLOR_MASK);\n }\n\n /** Sets this object's color. */\n set color(color: i32) {\n this.nextWithColor = (this.nextWithColor & ~COLOR_MASK) | color;\n }\n\n /** Gets the size of this object in memory. */\n get size(): usize {\n return BLOCK_OVERHEAD + (this.mmInfo & ~3);\n }\n\n /** Tests if this object is pointerfree. */\n get isPointerfree(): bool {\n var rtId = this.rtId;\n return rtId <= idof() || (__typeinfo(rtId) & TypeinfoFlags.POINTERFREE) != 0;\n }\n\n /** Unlinks this object from its list. */\n unlink(): void {\n var next = this.next;\n if (next == null) {\n if (DEBUG) assert(this.prev == null && changetype(this) < __heap_base);\n return; // static data not yet linked\n }\n var prev = this.prev;\n if (DEBUG) assert(prev);\n next.prev = prev;\n prev.next = next;\n }\n\n /** Links this object to the specified list, with the given color. */\n linkTo(list: Object, withColor: i32): void {\n let prev = list.prev;\n this.nextWithColor = changetype(list) | withColor;\n this.prev = prev;\n prev.next = this;\n list.prev = this;\n }\n\n /** Marks this object as gray, that is reachable with unscanned children. */\n makeGray(): void {\n if (this == iter) iter = assert(this.prev);\n this.unlink();\n this.linkTo(toSpace, this.isPointerfree ? i32(!white) : gray);\n }\n}\n\n/** Visits all objects considered to be program roots. */\nfunction visitRoots(cookie: u32): void {\n __visit_globals(cookie);\n var pn = pinSpace;\n var iter = pn.next;\n while (iter != pn) {\n if (DEBUG) assert(iter.color == transparent);\n __visit_members(changetype(iter) + TOTAL_OVERHEAD, cookie);\n iter = iter.next;\n }\n}\n\n/** Visits all objects on the stack. */\nfunction visitStack(cookie: u32): void {\n var ptr = __stack_pointer;\n while (ptr < __heap_base) {\n __visit(load(ptr), cookie);\n ptr += sizeof();\n }\n}\n\n/** Performs a single step according to the current state. */\nfunction step(): usize {\n // Magic constants responsible for pause times. Obtained experimentally\n // using the compiler compiling itself. 2048 budget pro run by default.\n const MARKCOST = isDefined(ASC_GC_MARKCOST) ? ASC_GC_MARKCOST : 1;\n const SWEEPCOST = isDefined(ASC_GC_SWEEPCOST) ? ASC_GC_SWEEPCOST : 10;\n var obj: Object;\n switch (state) {\n case STATE_IDLE: {\n state = STATE_MARK;\n visitCount = 0;\n visitRoots(VISIT_SCAN);\n iter = toSpace;\n return visitCount * MARKCOST;\n }\n case STATE_MARK: {\n let black = i32(!white);\n obj = iter.next;\n while (obj != toSpace) {\n iter = obj;\n if (obj.color != black) { // skip already-blacks (pointerfree)\n obj.color = black;\n visitCount = 0;\n __visit_members(changetype(obj) + TOTAL_OVERHEAD, VISIT_SCAN);\n return visitCount * MARKCOST;\n }\n obj = obj.next;\n }\n visitCount = 0;\n visitRoots(VISIT_SCAN);\n obj = iter.next;\n if (obj == toSpace) {\n visitStack(VISIT_SCAN);\n obj = iter.next;\n while (obj != toSpace) {\n if (obj.color != black) {\n obj.color = black;\n __visit_members(changetype(obj) + TOTAL_OVERHEAD, VISIT_SCAN);\n }\n obj = obj.next;\n }\n let from = fromSpace;\n fromSpace = toSpace;\n toSpace = from;\n white = black;\n iter = from.next;\n state = STATE_SWEEP;\n }\n return visitCount * MARKCOST;\n }\n case STATE_SWEEP: {\n obj = iter;\n if (obj != toSpace) {\n iter = obj.next;\n if (DEBUG) assert(obj.color == i32(!white)); // old white\n free(obj);\n return SWEEPCOST;\n }\n toSpace.nextWithColor = changetype(toSpace);\n toSpace.prev = toSpace;\n state = STATE_IDLE;\n break;\n }\n }\n return 0;\n}\n\n/** Frees an object. */\nfunction free(obj: Object): void {\n if (changetype(obj) < __heap_base) {\n obj.nextWithColor = 0; // may become linked again\n obj.prev = changetype(0);\n } else {\n total -= obj.size;\n if (isDefined(__finalize)) {\n __finalize(changetype(obj) + TOTAL_OVERHEAD);\n }\n __free(changetype(obj) + BLOCK_OVERHEAD);\n }\n}\n\n// Garbage collector interface\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __new(size: usize, id: i32): usize {\n if (size >= OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n if (total >= threshold) interrupt();\n var obj = changetype(__alloc(OBJECT_OVERHEAD + size) - BLOCK_OVERHEAD);\n obj.rtId = id;\n obj.rtSize = size;\n obj.linkTo(fromSpace, white); // inits next/prev\n total += obj.size;\n var ptr = changetype(obj) + TOTAL_OVERHEAD;\n // may be visited before being fully initialized, so must fill\n memory.fill(ptr, 0, size);\n return ptr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __renew(oldPtr: usize, size: usize): usize {\n var oldObj = changetype(oldPtr - TOTAL_OVERHEAD);\n // Update object size if its block is large enough\n if (size <= (oldObj.mmInfo & ~3) - OBJECT_OVERHEAD) {\n oldObj.rtSize = size;\n return oldPtr;\n }\n // If not the same object anymore, we have to move it move it due to the\n // shadow stack potentially still referencing the old object\n var newPtr = __new(size, oldObj.rtId);\n memory.copy(newPtr, oldPtr, min(size, oldObj.rtSize));\n return newPtr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __link(parentPtr: usize, childPtr: usize, expectMultiple: bool): void {\n // Write barrier is unnecessary if non-incremental\n if (!childPtr) return;\n if (DEBUG) assert(parentPtr);\n var child = changetype(childPtr - TOTAL_OVERHEAD);\n if (child.color == white) {\n let parent = changetype(parentPtr - TOTAL_OVERHEAD);\n let parentColor = parent.color;\n if (parentColor == i32(!white)) {\n // Maintain the invariant that no black object may point to a white object.\n if (expectMultiple) {\n // Move the barrier \"backward\". Suitable for containers receiving multiple stores.\n // Avoids a barrier for subsequent objects stored into the same container.\n parent.makeGray();\n } else {\n // Move the barrier \"forward\". Suitable for objects receiving isolated stores.\n child.makeGray();\n }\n } else if (parentColor == transparent && state == STATE_MARK) {\n // Pinned objects are considered 'black' during the mark phase.\n child.makeGray();\n }\n }\n}\n\n// @ts-ignore: decorator\n@lazy var visitCount = 0;\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __visit(ptr: usize, cookie: i32): void {\n if (!ptr) return;\n let obj = changetype(ptr - TOTAL_OVERHEAD);\n if (RTRACE) if (!onvisit(obj)) return;\n if (obj.color == white) {\n obj.makeGray();\n ++visitCount;\n }\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __pin(ptr: usize): usize {\n if (ptr) {\n let obj = changetype(ptr - TOTAL_OVERHEAD);\n if (obj.color == transparent) {\n throw new Error(E_ALREADY_PINNED);\n }\n obj.unlink(); // from fromSpace\n obj.linkTo(pinSpace, transparent);\n }\n return ptr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __unpin(ptr: usize): void {\n if (!ptr) return;\n var obj = changetype(ptr - TOTAL_OVERHEAD);\n if (obj.color != transparent) {\n throw new Error(E_NOT_PINNED);\n }\n if (state == STATE_MARK) {\n // We may be right at the point after marking roots for the second time and\n // entering the sweep phase, in which case the object would be missed if it\n // is not only pinned but also a root. Make sure it isn't missed.\n obj.makeGray();\n } else {\n obj.unlink();\n obj.linkTo(fromSpace, white);\n }\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __collect(): void {\n if (TRACE) trace(\"GC (full) at\", 1, total);\n if (state > STATE_IDLE) {\n // finish current cycle\n while (state != STATE_IDLE) step();\n }\n // perform a full cycle\n step();\n while (state != STATE_IDLE) step();\n threshold = (total * IDLEFACTOR / 100) + GRANULARITY;\n if (TRACE) trace(\"GC (full) done at cur/max\", 2, total, memory.size() << 16);\n if (RTRACE || PROFILE) oncollect(total);\n}\n\n// Garbage collector automation\n\n/** How often to interrupt. The default of 1024 means \"interrupt each 1024 bytes allocated\". */\n// @ts-ignore: decorator\n@inline const GRANULARITY: usize = isDefined(ASC_GC_GRANULARITY) ? ASC_GC_GRANULARITY : 1024;\n/** How long to interrupt. The default of 200% means \"run at double the speed of allocations\". */\n// @ts-ignore: decorator\n@inline const STEPFACTOR: usize = isDefined(ASC_GC_SWEEPFACTOR) ? ASC_GC_SWEEPFACTOR : 200;\n/** How long to idle. The default of 200% means \"wait for memory to double before kicking in again\". */\n// @ts-ignore: decorator\n@inline const IDLEFACTOR: usize = isDefined(ASC_GC_IDLEFACTOR) ? ASC_GC_IDLEFACTOR : 200;\n\n/** Threshold of memory used by objects to exceed before interrupting again. */\n// @ts-ignore: decorator\n@lazy var threshold: usize = ((memory.size() << 16) - __heap_base) >> 1;\n\n/** Performs a reasonable amount of incremental GC steps. */\nfunction interrupt(): void {\n if (PROFILE) oninterrupt(total);\n if (TRACE) trace(\"GC (auto) at\", 1, total);\n var budget: isize = GRANULARITY * STEPFACTOR / 100;\n do {\n budget -= step();\n if (state == STATE_IDLE) {\n if (TRACE) trace(\"└ GC (auto) done at cur/max\", 2, total, memory.size() << 16);\n threshold = (total * IDLEFACTOR / 100) + GRANULARITY;\n if (PROFILE) onyield(total);\n return;\n }\n } while (budget > 0);\n if (TRACE) trace(\"└ GC (auto) ongoing at\", 1, total);\n threshold = total + GRANULARITY * usize(total - threshold < GRANULARITY);\n if (PROFILE) onyield(total);\n}\n","// Ported from perlin reference implementation (https://cs.nyu.edu/~perlin/noise/)\n\nexport function perlin(_x: i32, _y: i32, _z: i32, denom: i32): f64 {\n // Convert fraction into f64\n let x: f64 = f64(_x) / f64(denom);\n let y: f64 = f64(_y) / f64(denom);\n let z: f64 = f64(_z) / f64(denom);\n\n // Find unit cube that contains point\n const X: i32 = i32(Math.floor(x)) & 255;\n const Y: i32 = i32(Math.floor(y)) & 255;\n const Z: i32 = i32(Math.floor(z)) & 255;\n\n // Find relative x,y,z of point in cube\n x -= Math.floor(x);\n y -= Math.floor(y);\n z -= Math.floor(z);\n\n // Compute fade curves for each x,y,z\n const u: f64 = fade(x);\n const v: f64 = fade(y);\n const w: f64 = fade(z);\n\n // Hash coordinates of the 8 cube corners\n const A: i32 = p[X] + Y;\n const AA: i32 = p[A] + Z;\n const AB: i32 = p[A + 1] + Z;\n const B: i32 = p[X + 1] + Y;\n const BA: i32 = p[B] + Z;\n const BB: i32 = p[B + 1] + Z;\n\n // Add blended results from 8 corners of cube\n const r: f64 = lerp(\n w,\n lerp(\n v,\n lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z)),\n lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z)),\n ),\n lerp(\n v,\n lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1)),\n lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1)),\n ),\n );\n\n // Shift to range from 0 to 1\n return (r + 1) / 2;\n}\n\nfunction fade(t: f64): f64 {\n return t * t * t * (t * (t * 6 - 15) + 10);\n}\n\nfunction lerp(t: f64, a: f64, b: f64): f64 {\n return a + t * (b - a);\n}\n\nfunction grad(hash: i32, x: f64, y: f64, z: f64): f64 {\n switch (hash & 0xf) {\n case 0x0:\n return x + y;\n case 0x1:\n return -x + y;\n case 0x2:\n return x - y;\n case 0x3:\n return -x - y;\n case 0x4:\n return x + z;\n case 0x5:\n return -x + z;\n case 0x6:\n return x - z;\n case 0x7:\n return -x - z;\n case 0x8:\n return y + z;\n case 0x9:\n return -y + z;\n case 0xa:\n return y - z;\n case 0xb:\n return -y - z;\n case 0xc:\n return y + x;\n case 0xd:\n return -y + z;\n case 0xe:\n return y - x;\n case 0xf:\n return -y - z;\n default:\n return 0; // never happens\n }\n}\n\nconst p: i32[] = [\n 151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21,\n 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149,\n 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229,\n 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209,\n 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217,\n 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,\n 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98,\n 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179,\n 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50,\n 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180, 151,\n 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10,\n 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56,\n 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122,\n 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76,\n 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226,\n 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223,\n 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108,\n 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162,\n 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45,\n 127, 4, 150, 254, 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180,\n];\n","//\n// Lookup data for exp2f\n//\n\n// @ts-ignore: decorator\n@inline const EXP2F_TABLE_BITS = 5;\n\n// @ts-ignore: decorator\n@lazy @inline const EXP2F_DATA_TAB = memory.data([\n // exp2f_data_tab[i] = uint(2^(i/N)) - (i << 52-BITS)\n // used for computing 2^(k/N) for an int |k| < 150 N as\n // double(tab[k%N] + (k << 52-BITS))\n 0x3FF0000000000000, 0x3FEFD9B0D3158574, 0x3FEFB5586CF9890F, 0x3FEF9301D0125B51,\n 0x3FEF72B83C7D517B, 0x3FEF54873168B9AA, 0x3FEF387A6E756238, 0x3FEF1E9DF51FDEE1,\n 0x3FEF06FE0A31B715, 0x3FEEF1A7373AA9CB, 0x3FEEDEA64C123422, 0x3FEECE086061892D,\n 0x3FEEBFDAD5362A27, 0x3FEEB42B569D4F82, 0x3FEEAB07DD485429, 0x3FEEA47EB03A5585,\n 0x3FEEA09E667F3BCD, 0x3FEE9F75E8EC5F74, 0x3FEEA11473EB0187, 0x3FEEA589994CCE13,\n 0x3FEEACE5422AA0DB, 0x3FEEB737B0CDC5E5, 0x3FEEC49182A3F090, 0x3FEED503B23E255D,\n 0x3FEEE89F995AD3AD, 0x3FEEFF76F2FB5E47, 0x3FEF199BDD85529C, 0x3FEF3720DCEF9069,\n 0x3FEF5818DCFBA487, 0x3FEF7C97337B9B5F, 0x3FEFA4AFA2A490DA, 0x3FEFD0765B6E4540\n]);\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)\n// Wrong count: 168353 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function exp2f_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N, // 0x1.8p+52\n Ox127f = reinterpret(0x7F000000);\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n var xd = x;\n var ix = reinterpret(x);\n var ux = ix >> 20 & 0x7FF;\n if (ux >= 0x430) {\n // |x| >= 128 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > 0) return x * Ox127f; // x > 0 -> HugeVal (Owerflow)\n if (x <= -150) return 0; // x <= -150 -> 0 (Underflow)\n }\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)] and int k.\n var kd = xd + shift;\n var ki = reinterpret(kd);\n var r = xd - (kd - shift);\n var t: u64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n y = C2 * r + 1;\n y += (C0 * r + C1) * (r * r);\n y *= s;\n\n return y;\n}\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.)\n// Wrong count: 170635 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function expf_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000), // 0x1.8p+52\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep+0\n Ox1p127f = reinterpret(0x7F000000);\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394) / N / N / N, // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3) / N / N, // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6) / N; // 0x1.62e42ff0c52d6p-1\n\n var xd = x;\n var ix = reinterpret(x);\n var ux = ix >> 20 & 0x7FF;\n if (ux >= 0x42B) {\n // |x| >= 88 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > reinterpret(0x42B17217)) return x * Ox1p127f; // x > log(0x1p128) ~= 88.72 -> HugeVal (Owerflow)\n if (x < reinterpret(0xC2CFF1B4)) return 0; // x < log(0x1p-150) ~= -103.97 -> 0 (Underflow)\n }\n\n // x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k.\n var z = InvLn2N * xd;\n\n // Round and convert z to int, the result is in [-150*N, 128*N] and\n // ideally ties-to-even rule is used, otherwise the magnitude of r\n // can be bigger which gives larger approximation error.\n var kd = (z + shift);\n var ki = reinterpret(kd);\n var r = z - (kd - shift);\n var s: f64, y: f64, t: u64;\n\n // exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n\n return y;\n}\n\n//\n// Lookup data for log2f\n//\n\n// @ts-ignore: decorator\n@inline const LOG2F_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2F_DATA_TAB = memory.data([\n reinterpret(0x3FF661EC79F8F3BE), reinterpret(0xBFDEFEC65B963019), // 0x1.661ec79f8f3bep+0, -0x1.efec65b963019p-2,\n reinterpret(0x3FF571ED4AAF883D), reinterpret(0xBFDB0B6832D4FCA4), // 0x1.571ed4aaf883dp+0, -0x1.b0b6832d4fca4p-2,\n reinterpret(0x3FF49539F0F010B0), reinterpret(0xBFD7418B0A1FB77B), // 0x1.49539f0f010bp+0 , -0x1.7418b0a1fb77bp-2,\n reinterpret(0x3FF3C995B0B80385), reinterpret(0xBFD39DE91A6DCF7B), // 0x1.3c995b0b80385p+0, -0x1.39de91a6dcf7bp-2,\n reinterpret(0x3FF30D190C8864A5), reinterpret(0xBFD01D9BF3F2B631), // 0x1.30d190c8864a5p+0, -0x1.01d9bf3f2b631p-2,\n reinterpret(0x3FF25E227B0B8EA0), reinterpret(0xBFC97C1D1B3B7AF0), // 0x1.25e227b0b8eap+0 , -0x1.97c1d1b3b7afp-3 ,\n reinterpret(0x3FF1BB4A4A1A343F), reinterpret(0xBFC2F9E393AF3C9F), // 0x1.1bb4a4a1a343fp+0, -0x1.2f9e393af3c9fp-3,\n reinterpret(0x3FF12358F08AE5BA), reinterpret(0xBFB960CBBF788D5C), // 0x1.12358f08ae5bap+0, -0x1.960cbbf788d5cp-4,\n reinterpret(0x3FF0953F419900A7), reinterpret(0xBFAA6F9DB6475FCE), // 0x1.0953f419900a7p+0, -0x1.a6f9db6475fcep-5,\n reinterpret(0x3FF0000000000000), 0, // 0x1p+0, 0x0,\n reinterpret(0x3FEE608CFD9A47AC), reinterpret(0x3FB338CA9F24F53D), // 0x1.e608cfd9a47acp-1, 0x1.338ca9f24f53dp-4,\n reinterpret(0x3FECA4B31F026AA0), reinterpret(0x3FC476A9543891BA), // 0x1.ca4b31f026aap-1 , 0x1.476a9543891bap-3,\n reinterpret(0x3FEB2036576AFCE6), reinterpret(0x3FCE840B4AC4E4D2), // 0x1.b2036576afce6p-1, 0x1.e840b4ac4e4d2p-3,\n reinterpret(0x3FE9C2D163A1AA2D), reinterpret(0x3FD40645F0C6651C), // 0x1.9c2d163a1aa2dp-1, 0x1.40645f0c6651cp-2,\n reinterpret(0x3FE886E6037841ED), reinterpret(0x3FD88E9C2C1B9FF8), // 0x1.886e6037841edp-1, 0x1.88e9c2c1b9ff8p-2,\n reinterpret(0x3FE767DCF5534862), reinterpret(0x3FDCE0A44EB17BCC) // 0x1.767dcf5534862p-1, 0x1.ce0a44eb17bccp-2\n]);\n\n// ULP error: 0.752 (nearest rounding.)\n// Relative error: 1.9 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function log2f_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOG2F_TABLE_BITS) - 1,\n Ox1p23f = reinterpret(0x4B000000); // 0x1p23f\n\n const\n A0 = reinterpret(0xBFD712B6F70A7E4D), // -0x1.712b6f70a7e4dp-2\n A1 = reinterpret(0x3FDECABF496832E0), // 0x1.ecabf496832ep-2\n A2 = reinterpret(0xBFE715479FFAE3DE), // -0x1.715479ffae3dep-1\n A3 = reinterpret(0x3FF715475F35C8B8); // 0x1.715475f35c8b8p0\n\n var ux = reinterpret(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && predict_false(ix == 0x3f800000)) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if (ux * 2 == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log2(inf) == inf.\n if ((ux >> 31) || ux * 2 >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = (tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK;\n var top = tmp & 0xFF800000;\n var iz = ux - top;\n var k = tmp >> 23;\n\n var invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n var logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n var z = reinterpret(iz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n var r = z * invc - 1;\n var y0 = logc + k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n var y = A1 * r + A2;\n var p = A3 * r + y0;\n var r2 = r * r;\n y += A0 * r2;\n y = y * r2 + p;\n\n return y;\n}\n\n//\n// Lookup data for logf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/logf.c\n//\n\n// @ts-ignore: decorator\n@inline const LOGF_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline const LOGF_DATA_TAB = memory.data([\n reinterpret(0x3FF661EC79F8F3BE), reinterpret(0xBFD57BF7808CAADE), // 0x1.661ec79f8f3bep+0, -0x1.57bf7808caadep-2,\n reinterpret(0x3FF571ED4AAF883D), reinterpret(0xBFD2BEF0A7C06DDB), // 0x1.571ed4aaf883dp+0, -0x1.2bef0a7c06ddbp-2,\n reinterpret(0x3FF49539F0F010B0), reinterpret(0xBFD01EAE7F513A67), // 0x1.49539f0f010bp+0 , -0x1.01eae7f513a67p-2,\n reinterpret(0x3FF3C995B0B80385), reinterpret(0xBFCB31D8A68224E9), // 0x1.3c995b0b80385p+0, -0x1.b31d8a68224e9p-3,\n reinterpret(0x3FF30D190C8864A5), reinterpret(0xBFC6574F0AC07758), // 0x1.30d190c8864a5p+0, -0x1.6574f0ac07758p-3,\n reinterpret(0x3FF25E227B0B8EA0), reinterpret(0xBFC1AA2BC79C8100), // 0x1.25e227b0b8eap+0 , -0x1.1aa2bc79c81p-3 ,\n reinterpret(0x3FF1BB4A4A1A343F), reinterpret(0xBFBA4E76CE8C0E5E), // 0x1.1bb4a4a1a343fp+0, -0x1.a4e76ce8c0e5ep-4,\n reinterpret(0x3FF12358F08AE5BA), reinterpret(0xBFB1973C5A611CCC), // 0x1.12358f08ae5bap+0, -0x1.1973c5a611cccp-4,\n reinterpret(0x3FF0953F419900A7), reinterpret(0xBFA252F438E10C1E), // 0x1.0953f419900a7p+0, -0x1.252f438e10c1ep-5,\n reinterpret(0x3FF0000000000000), 0, // 0x1p+0, 0,\n reinterpret(0x3FEE608CFD9A47AC), reinterpret(0x3FAAA5AA5DF25984), // 0x1.e608cfd9a47acp-1, 0x1.aa5aa5df25984p-5,\n reinterpret(0x3FECA4B31F026AA0), reinterpret(0x3FBC5E53AA362EB4), // 0x1.ca4b31f026aap-1 , 0x1.c5e53aa362eb4p-4,\n reinterpret(0x3FEB2036576AFCE6), reinterpret(0x3FC526E57720DB08), // 0x1.b2036576afce6p-1, 0x1.526e57720db08p-3,\n reinterpret(0x3FE9C2D163A1AA2D), reinterpret(0x3FCBC2860D224770), // 0x1.9c2d163a1aa2dp-1, 0x1.bc2860d22477p-3 ,\n reinterpret(0x3FE886E6037841ED), reinterpret(0x3FD1058BC8A07EE1), // 0x1.886e6037841edp-1, 0x1.1058bc8a07ee1p-2,\n reinterpret(0x3FE767DCF5534862), reinterpret(0x3FD4043057B6EE09) // 0x1.767dcf5534862p-1, 0x1.4043057b6ee09p-2\n]);\n\n// ULP error: 0.818 (nearest rounding.)\n// Relative error: 1.957 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function logf_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOGF_TABLE_BITS) - 1,\n Ox1p23f = reinterpret(0x4B000000); // 0x1p23f\n\n const\n Ln2 = reinterpret(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1;\n A0 = reinterpret(0xBFD00EA348B88334), // -0x1.00ea348b88334p-2\n A1 = reinterpret(0x3FD5575B0BE00B6A), // 0x1.5575b0be00b6ap-2\n A2 = reinterpret(0xBFDFFFFEF20A4123); // -0x1.ffffef20a4123p-2\n\n var ux = reinterpret(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && ux == 0x3f800000) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if ((ux << 1) == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log(inf) == inf.\n if ((ux >> 31) || (ux << 1) >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = (tmp >> (23 - LOGF_TABLE_BITS)) & N_MASK;\n var k = tmp >> 23;\n var iz = ux - (tmp & 0x1FF << 23);\n\n var invc = load(LOGF_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n var logc = load(LOGF_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n\n var z = reinterpret(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2\n var r = z * invc - 1;\n var y0 = logc + k * Ln2;\n\n // Pipelined polynomial evaluation to approximate log1p(r).\n var r2 = r * r;\n var y = A1 * r + A2;\n y += A0 * r2;\n y = y * r2 + (y0 + r);\n\n return y;\n}\n\n//\n// Lookup data for powf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/powf.c\n//\n\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnanf(ux: u32): bool {\n return (ux << 1) - 1 >= (0x7f800000 << 1) - 1;\n}\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkintf(iy: u32): i32 {\n var e = iy >> 23 & 0xFF;\n if (e < 0x7F ) return 0;\n if (e > 0x7F + 23) return 2;\n e = 1 << (0x7F + 23 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// Subnormal input is normalized so ix has negative biased exponent.\n// Output is multiplied by N (POWF_SCALE) if TOINT_INTRINICS is set.\n// @ts-ignore: decorator\n@inline\nfunction log2f_inline(ux: u32): f64 {\n const N_MASK = (1 << LOG2F_TABLE_BITS) - 1;\n\n const\n A0 = reinterpret(0x3FD27616C9496E0B), // 0x1.27616c9496e0bp-2\n A1 = reinterpret(0xBFD71969A075C67A), // -0x1.71969a075c67ap-2\n A2 = reinterpret(0x3FDEC70A6CA7BADD), // 0x1.ec70a6ca7baddp-2\n A3 = reinterpret(0xBFE7154748BEF6C8), // -0x1.7154748bef6c8p-1\n A4 = reinterpret(0x3FF71547652AB82B); // 0x1.71547652ab82bp+0\n\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ux - 0x3F330000;\n var i = usize((tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK);\n var top = tmp & 0xFF800000;\n var uz = ux - top;\n var k = top >> 23;\n\n var invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n var logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n var z = reinterpret(uz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n var r = z * invc - 1;\n var y0 = logc + k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n var y = A0 * r + A1;\n var p = A2 * r + A3;\n var q = A4 * r + y0;\n\n r *= r;\n q += p * r;\n y = y * (r * r) + q;\n\n return y;\n}\n\n// The output of log2 and thus the input of exp2 is either scaled by N\n// (in case of fast toint intrinsics) or not. The unscaled xd must be\n// in [-1021,1023], sign_bias sets the sign of the result.\n// @ts-ignore: decorator\n@inline\nfunction exp2f_inline(xd: f64, signBias: u32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N; // 0x1.8p+52\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)]\n var kd = (xd + shift);\n var ki = reinterpret(kd);\n var r = xd - (kd - shift);\n var t: u64, z: f64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += (ki + signBias) << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n return y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflowf(sign: u32, y: f32): f32 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret(0x70000000)); // 0x1p97f\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret(0x10000000)); // 0x1p-95f\n}\n\n// @ts-ignore: decorator\n@inline\nexport function powf_lut(x: f32, y: f32): f32 {\n const\n Ox1p23f = reinterpret(0x4B000000), // 0x1p23f\n UPPER_LIMIT = reinterpret(0x405FFFFFFFD1D571), // 0x1.fffffffd1d571p+6\n LOWER_LIMIT = -150.0,\n SIGN_BIAS = 1 << (EXP2F_TABLE_BITS + 11);\n\n var signBias: u32 = 0;\n var ix = reinterpret(x);\n var iy = reinterpret(y);\n var ny = 0;\n\n if (i32(ix - 0x00800000 >= 0x7f800000 - 0x00800000) | (ny = i32(zeroinfnanf(iy)))) {\n // Either (x < 0x1p-126 or inf or nan) or (y is 0 or inf or nan).\n if (ny) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3F800000) return NaN; // original: 1.0\n if ((ix << 1) > (0x7F800000 << 1) || (iy << 1) > (0x7F800000 << 1)) return x + y;\n if ((ix << 1) == (0x3F800000 << 1)) return NaN; // original: 1.0\n if (((ix << 1) < (0x3F800000 << 1)) == !(iy >> 31)) return 0; // |x| < 1 && y==inf or |x| > 1 && y==-inf.\n return y * y;\n }\n if (zeroinfnanf(ix)) {\n let x2 = x * x;\n if ((ix >> 31) && checkintf(iy) == 1) x2 = -x2;\n return iy < 0 ? 1 / x2 : x2;\n }\n // x and y are non-zero finite.\n if (ix < 0) {\n // Finite x < 0.\n let yint = checkintf(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) signBias = SIGN_BIAS;\n ix &= 0x7FFFFFFF;\n }\n if (ix < 0x00800000) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret(x * Ox1p23f);\n ix &= 0x7FFFFFFF;\n ix -= 23 << 23;\n }\n }\n var logx = log2f_inline(ix);\n var ylogx = y * logx; // cannot overflow, y is single prec.\n if ((reinterpret(ylogx) >> 47 & 0xFFFF) >= 0x80BF) { // reinterpret(126.0) >> 47\n // |y * log(x)| >= 126\n if (ylogx > UPPER_LIMIT) return oflowf(signBias); // overflow\n if (ylogx <= LOWER_LIMIT) return uflowf(signBias); // underflow\n }\n return exp2f_inline(ylogx, signBias);\n}\n\n//\n// Lookup data for exp. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp.c\n//\n\n// @ts-ignore: decorator\n@inline const EXP_TABLE_BITS = 7;\n\n// @ts-ignore: decorator\n@lazy @inline const EXP_DATA_TAB = memory.data([\n 0x0000000000000000, 0x3FF0000000000000,\n 0x3C9B3B4F1A88BF6E, 0x3FEFF63DA9FB3335,\n 0xBC7160139CD8DC5D, 0x3FEFEC9A3E778061,\n 0xBC905E7A108766D1, 0x3FEFE315E86E7F85,\n 0x3C8CD2523567F613, 0x3FEFD9B0D3158574,\n 0xBC8BCE8023F98EFA, 0x3FEFD06B29DDF6DE,\n 0x3C60F74E61E6C861, 0x3FEFC74518759BC8,\n 0x3C90A3E45B33D399, 0x3FEFBE3ECAC6F383,\n 0x3C979AA65D837B6D, 0x3FEFB5586CF9890F,\n 0x3C8EB51A92FDEFFC, 0x3FEFAC922B7247F7,\n 0x3C3EBE3D702F9CD1, 0x3FEFA3EC32D3D1A2,\n 0xBC6A033489906E0B, 0x3FEF9B66AFFED31B,\n 0xBC9556522A2FBD0E, 0x3FEF9301D0125B51,\n 0xBC5080EF8C4EEA55, 0x3FEF8ABDC06C31CC,\n 0xBC91C923B9D5F416, 0x3FEF829AAEA92DE0,\n 0x3C80D3E3E95C55AF, 0x3FEF7A98C8A58E51,\n 0xBC801B15EAA59348, 0x3FEF72B83C7D517B,\n 0xBC8F1FF055DE323D, 0x3FEF6AF9388C8DEA,\n 0x3C8B898C3F1353BF, 0x3FEF635BEB6FCB75,\n 0xBC96D99C7611EB26, 0x3FEF5BE084045CD4,\n 0x3C9AECF73E3A2F60, 0x3FEF54873168B9AA,\n 0xBC8FE782CB86389D, 0x3FEF4D5022FCD91D,\n 0x3C8A6F4144A6C38D, 0x3FEF463B88628CD6,\n 0x3C807A05B0E4047D, 0x3FEF3F49917DDC96,\n 0x3C968EFDE3A8A894, 0x3FEF387A6E756238,\n 0x3C875E18F274487D, 0x3FEF31CE4FB2A63F,\n 0x3C80472B981FE7F2, 0x3FEF2B4565E27CDD,\n 0xBC96B87B3F71085E, 0x3FEF24DFE1F56381,\n 0x3C82F7E16D09AB31, 0x3FEF1E9DF51FDEE1,\n 0xBC3D219B1A6FBFFA, 0x3FEF187FD0DAD990,\n 0x3C8B3782720C0AB4, 0x3FEF1285A6E4030B,\n 0x3C6E149289CECB8F, 0x3FEF0CAFA93E2F56,\n 0x3C834D754DB0ABB6, 0x3FEF06FE0A31B715,\n 0x3C864201E2AC744C, 0x3FEF0170FC4CD831,\n 0x3C8FDD395DD3F84A, 0x3FEEFC08B26416FF,\n 0xBC86A3803B8E5B04, 0x3FEEF6C55F929FF1,\n 0xBC924AEDCC4B5068, 0x3FEEF1A7373AA9CB,\n 0xBC9907F81B512D8E, 0x3FEEECAE6D05D866,\n 0xBC71D1E83E9436D2, 0x3FEEE7DB34E59FF7,\n 0xBC991919B3CE1B15, 0x3FEEE32DC313A8E5,\n 0x3C859F48A72A4C6D, 0x3FEEDEA64C123422,\n 0xBC9312607A28698A, 0x3FEEDA4504AC801C,\n 0xBC58A78F4817895B, 0x3FEED60A21F72E2A,\n 0xBC7C2C9B67499A1B, 0x3FEED1F5D950A897,\n 0x3C4363ED60C2AC11, 0x3FEECE086061892D,\n 0x3C9666093B0664EF, 0x3FEECA41ED1D0057,\n 0x3C6ECCE1DAA10379, 0x3FEEC6A2B5C13CD0,\n 0x3C93FF8E3F0F1230, 0x3FEEC32AF0D7D3DE,\n 0x3C7690CEBB7AAFB0, 0x3FEEBFDAD5362A27,\n 0x3C931DBDEB54E077, 0x3FEEBCB299FDDD0D,\n 0xBC8F94340071A38E, 0x3FEEB9B2769D2CA7,\n 0xBC87DECCDC93A349, 0x3FEEB6DAA2CF6642,\n 0xBC78DEC6BD0F385F, 0x3FEEB42B569D4F82,\n 0xBC861246EC7B5CF6, 0x3FEEB1A4CA5D920F,\n 0x3C93350518FDD78E, 0x3FEEAF4736B527DA,\n 0x3C7B98B72F8A9B05, 0x3FEEAD12D497C7FD,\n 0x3C9063E1E21C5409, 0x3FEEAB07DD485429,\n 0x3C34C7855019C6EA, 0x3FEEA9268A5946B7,\n 0x3C9432E62B64C035, 0x3FEEA76F15AD2148,\n 0xBC8CE44A6199769F, 0x3FEEA5E1B976DC09,\n 0xBC8C33C53BEF4DA8, 0x3FEEA47EB03A5585,\n 0xBC845378892BE9AE, 0x3FEEA34634CCC320,\n 0xBC93CEDD78565858, 0x3FEEA23882552225,\n 0x3C5710AA807E1964, 0x3FEEA155D44CA973,\n 0xBC93B3EFBF5E2228, 0x3FEEA09E667F3BCD,\n 0xBC6A12AD8734B982, 0x3FEEA012750BDABF,\n 0xBC6367EFB86DA9EE, 0x3FEE9FB23C651A2F,\n 0xBC80DC3D54E08851, 0x3FEE9F7DF9519484,\n 0xBC781F647E5A3ECF, 0x3FEE9F75E8EC5F74,\n 0xBC86EE4AC08B7DB0, 0x3FEE9F9A48A58174,\n 0xBC8619321E55E68A, 0x3FEE9FEB564267C9,\n 0x3C909CCB5E09D4D3, 0x3FEEA0694FDE5D3F,\n 0xBC7B32DCB94DA51D, 0x3FEEA11473EB0187,\n 0x3C94ECFD5467C06B, 0x3FEEA1ED0130C132,\n 0x3C65EBE1ABD66C55, 0x3FEEA2F336CF4E62,\n 0xBC88A1C52FB3CF42, 0x3FEEA427543E1A12,\n 0xBC9369B6F13B3734, 0x3FEEA589994CCE13,\n 0xBC805E843A19FF1E, 0x3FEEA71A4623C7AD,\n 0xBC94D450D872576E, 0x3FEEA8D99B4492ED,\n 0x3C90AD675B0E8A00, 0x3FEEAAC7D98A6699,\n 0x3C8DB72FC1F0EAB4, 0x3FEEACE5422AA0DB,\n 0xBC65B6609CC5E7FF, 0x3FEEAF3216B5448C,\n 0x3C7BF68359F35F44, 0x3FEEB1AE99157736,\n 0xBC93091FA71E3D83, 0x3FEEB45B0B91FFC6,\n 0xBC5DA9B88B6C1E29, 0x3FEEB737B0CDC5E5,\n 0xBC6C23F97C90B959, 0x3FEEBA44CBC8520F,\n 0xBC92434322F4F9AA, 0x3FEEBD829FDE4E50,\n 0xBC85CA6CD7668E4B, 0x3FEEC0F170CA07BA,\n 0x3C71AFFC2B91CE27, 0x3FEEC49182A3F090,\n 0x3C6DD235E10A73BB, 0x3FEEC86319E32323,\n 0xBC87C50422622263, 0x3FEECC667B5DE565,\n 0x3C8B1C86E3E231D5, 0x3FEED09BEC4A2D33,\n 0xBC91BBD1D3BCBB15, 0x3FEED503B23E255D,\n 0x3C90CC319CEE31D2, 0x3FEED99E1330B358,\n 0x3C8469846E735AB3, 0x3FEEDE6B5579FDBF,\n 0xBC82DFCD978E9DB4, 0x3FEEE36BBFD3F37A,\n 0x3C8C1A7792CB3387, 0x3FEEE89F995AD3AD,\n 0xBC907B8F4AD1D9FA, 0x3FEEEE07298DB666,\n 0xBC55C3D956DCAEBA, 0x3FEEF3A2B84F15FB,\n 0xBC90A40E3DA6F640, 0x3FEEF9728DE5593A,\n 0xBC68D6F438AD9334, 0x3FEEFF76F2FB5E47,\n 0xBC91EEE26B588A35, 0x3FEF05B030A1064A,\n 0x3C74FFD70A5FDDCD, 0x3FEF0C1E904BC1D2,\n 0xBC91BDFBFA9298AC, 0x3FEF12C25BD71E09,\n 0x3C736EAE30AF0CB3, 0x3FEF199BDD85529C,\n 0x3C8EE3325C9FFD94, 0x3FEF20AB5FFFD07A,\n 0x3C84E08FD10959AC, 0x3FEF27F12E57D14B,\n 0x3C63CDAF384E1A67, 0x3FEF2F6D9406E7B5,\n 0x3C676B2C6C921968, 0x3FEF3720DCEF9069,\n 0xBC808A1883CCB5D2, 0x3FEF3F0B555DC3FA,\n 0xBC8FAD5D3FFFFA6F, 0x3FEF472D4A07897C,\n 0xBC900DAE3875A949, 0x3FEF4F87080D89F2,\n 0x3C74A385A63D07A7, 0x3FEF5818DCFBA487,\n 0xBC82919E2040220F, 0x3FEF60E316C98398,\n 0x3C8E5A50D5C192AC, 0x3FEF69E603DB3285,\n 0x3C843A59AC016B4B, 0x3FEF7321F301B460,\n 0xBC82D52107B43E1F, 0x3FEF7C97337B9B5F,\n 0xBC892AB93B470DC9, 0x3FEF864614F5A129,\n 0x3C74B604603A88D3, 0x3FEF902EE78B3FF6,\n 0x3C83C5EC519D7271, 0x3FEF9A51FBC74C83,\n 0xBC8FF7128FD391F0, 0x3FEFA4AFA2A490DA,\n 0xBC8DAE98E223747D, 0x3FEFAF482D8E67F1,\n 0x3C8EC3BC41AA2008, 0x3FEFBA1BEE615A27,\n 0x3C842B94C3A9EB32, 0x3FEFC52B376BBA97,\n 0x3C8A64A931D185EE, 0x3FEFD0765B6E4540,\n 0xBC8E37BAE43BE3ED, 0x3FEFDBFDAD9CBE14,\n 0x3C77893B4D91CD9D, 0x3FEFE7C1819E90D8,\n 0x3C5305C14160CC89, 0x3FEFF3C22B8F71F1\n]);\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase(tmp: f64, sbits: u64, ki: u64): f64 {\n const\n Ox1p_1022 = reinterpret(0x0010000000000000), // 0x1p-1022\n Ox1p1009 = reinterpret(0x7F00000000000000); // 0x1p1009\n\n var scale: f64;\n if (!(ki & 0x80000000)) {\n // k > 0, the exponent of scale might have overflowed by <= 460.\n sbits -= u64(1009) << 52;\n scale = reinterpret(sbits);\n return Ox1p1009 * (scale + scale * tmp); // 0x1p1009\n }\n // k < 0, need special care in the subnormal range.\n sbits += u64(1022) << 52;\n // Note: sbits is signed scale.\n scale = reinterpret(sbits);\n var y = scale + scale * tmp;\n if (abs(y) < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let one = copysign(1.0, y);\n let lo = scale - y + scale * tmp;\n let hi = one + y;\n lo = one - hi + y + lo;\n y = (hi + lo) - one;\n // Fix the sign of 0.\n if (y == 0.0) y = reinterpret(sbits & 0x8000000000000000);\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret(0x4338000000000000); // 0x1.8p52;\n\n const\n C2 = reinterpret(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n var ux = reinterpret(x);\n var abstop = u32(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) {\n return 1.0 + x;\n } else {\n return select(0, Infinity, ux < 0);\n }\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]\n var z = InvLn2N * x;\n // #if TOINT_INTRINSICS\n // \tkd = roundtoint(z);\n // \tki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // \t// z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // var kd = z + shift;\n // var ki = reinterpret(kd) >> 16;\n // var kd = ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes.\n var kd = z + shift;\n var ki = reinterpret(kd);\n kd -= shift;\n // #endif\n var r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // 2^(k/N) ~= scale * (1 + tail).\n var idx = usize((ki & N_MASK) << 1);\n var top = ki << (52 - EXP_TABLE_BITS);\n\n var tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()))); // T[idx]\n // This is only a valid scale when -1023*N < k < 1024*N\n var sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top; // T[idx + 1]\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n var r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp.\n var tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n var scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n//\n// Lookup data for exp2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp2.c\n//\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase2(tmp: f64, sbits: u64, ki: u64): f64 {\n const Ox1p_1022 = reinterpret(0x10000000000000); // 0x1p-1022\n var scale: f64;\n if ((ki & 0x80000000) == 0) {\n // k > 0, the exponent of scale might have overflowed by 1\n sbits -= u64(1) << 52;\n scale = reinterpret(sbits);\n return 2 * (scale * tmp + scale);\n }\n // k < 0, need special care in the subnormal range\n sbits += u64(1022) << 52;\n scale = reinterpret(sbits);\n var y = scale * tmp + scale;\n if (y < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let hi: f64, lo: f64;\n lo = scale - y + scale * tmp;\n hi = 1.0 + y;\n lo = 1.0 - hi + y + lo;\n y = (hi + lo) - 1.0;\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp2_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N; // 0x1.8p52\n\n const\n C1 = reinterpret(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1\n C2 = reinterpret(0x3FCEBFBDFF82C424), // 0x1.ebfbdff82c424p-3\n C3 = reinterpret(0x3FAC6B08D70CF4B5), // 0x1.c6b08d70cf4b5p-5\n C4 = reinterpret(0x3F83B2ABD24650CC), // 0x1.3b2abd24650ccp-7\n C5 = reinterpret(0x3F55D7E09B4E3A84); // 0x1.5d7e09b4e3a84p-10\n\n var ux = reinterpret(x);\n var abstop = u32(ux >> 52) & 0x7ff;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1.0;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) return 1.0 + x;\n if (ux >= 0) return Infinity;\n else if (ux >= 0xC090CC0000000000) return 0;\n }\n if ((ux << 1) > 0x811A000000000000) abstop = 0; // Large x is special cased below.\n }\n\n // exp2(x) = 2^(k/N) * 2^r, with 2^r in [2^(-1/2N),2^(1/2N)].\n // x = k/N + r, with int k and r in [-1/2N, 1/2N]\n var kd = x + shift;\n var ki = reinterpret(kd);\n kd -= shift; // k/N for int k\n var r = x - kd;\n // 2^(k/N) ~= scale * (1 + tail)\n var idx = usize((ki & N_MASK) << 1);\n var top = ki << (52 - EXP_TABLE_BITS);\n\n var tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()), 0 << alignof())); // T[idx])\n // This is only a valid scale when -1023*N < k < 1024*N\n var sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top; // T[idx + 1]\n // exp2(x) = 2^(k/N) * 2^r ~= scale + scale * (tail + 2^r - 1).\n // Evaluation is optimized assuming superscalar pipelined execution\n var r2 = r * r;\n // Without fma the worst case error is 0.5/N ulp larger.\n // Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp.\n var tmp = tail + r * C1 + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase2(tmp, sbits, ki);\n var scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-928, so there\n // is no spurious underflow here even without fma.\n return scale * tmp + scale;\n}\n\n//\n// Lookup data for log2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c\n//\n\n// @ts-ignore: decorator\n@inline const LOG2_TABLE_BITS = 6;\n\n/* Algorithm:\n\n x = 2^k z\n log2(x) = k + log2(c) + log2(z/c)\n log2(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log2(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p10 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-64 and\n 3) the rounding error in (double)log2(c) is minimized (< 0x1p-68).\n\nNote: 1) ensures that k + logc can be computed without rounding error, 2)\nensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to a\nsingle rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log2(x)| < 0x1p-4, this is not enough so that is special cased. */\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2_DATA_TAB1 = memory.data([\n // invc , logc\n reinterpret(0x3FF724286BB1ACF8), reinterpret(0xBFE1095FEECDB000),\n reinterpret(0x3FF6E1F766D2CCA1), reinterpret(0xBFE08494BD76D000),\n reinterpret(0x3FF6A13D0E30D48A), reinterpret(0xBFE00143AEE8F800),\n reinterpret(0x3FF661EC32D06C85), reinterpret(0xBFDEFEC5360B4000),\n reinterpret(0x3FF623FA951198F8), reinterpret(0xBFDDFDD91AB7E000),\n reinterpret(0x3FF5E75BA4CF026C), reinterpret(0xBFDCFFAE0CC79000),\n reinterpret(0x3FF5AC055A214FB8), reinterpret(0xBFDC043811FDA000),\n reinterpret(0x3FF571ED0F166E1E), reinterpret(0xBFDB0B67323AE000),\n reinterpret(0x3FF53909590BF835), reinterpret(0xBFDA152F5A2DB000),\n reinterpret(0x3FF5014FED61ADDD), reinterpret(0xBFD9217F5AF86000),\n reinterpret(0x3FF4CAB88E487BD0), reinterpret(0xBFD8304DB0719000),\n reinterpret(0x3FF49539B4334FEE), reinterpret(0xBFD74189F9A9E000),\n reinterpret(0x3FF460CBDFAFD569), reinterpret(0xBFD6552BB5199000),\n reinterpret(0x3FF42D664EE4B953), reinterpret(0xBFD56B23A29B1000),\n reinterpret(0x3FF3FB01111DD8A6), reinterpret(0xBFD483650F5FA000),\n reinterpret(0x3FF3C995B70C5836), reinterpret(0xBFD39DE937F6A000),\n reinterpret(0x3FF3991C4AB6FD4A), reinterpret(0xBFD2BAA1538D6000),\n reinterpret(0x3FF3698E0CE099B5), reinterpret(0xBFD1D98340CA4000),\n reinterpret(0x3FF33AE48213E7B2), reinterpret(0xBFD0FA853A40E000),\n reinterpret(0x3FF30D191985BDB1), reinterpret(0xBFD01D9C32E73000),\n reinterpret(0x3FF2E025CAB271D7), reinterpret(0xBFCE857DA2FA6000),\n reinterpret(0x3FF2B404CF13CD82), reinterpret(0xBFCCD3C8633D8000),\n reinterpret(0x3FF288B02C7CCB50), reinterpret(0xBFCB26034C14A000),\n reinterpret(0x3FF25E2263944DE5), reinterpret(0xBFC97C1C2F4FE000),\n reinterpret(0x3FF234563D8615B1), reinterpret(0xBFC7D6023F800000),\n reinterpret(0x3FF20B46E33EAF38), reinterpret(0xBFC633A71A05E000),\n reinterpret(0x3FF1E2EEFDCDA3DD), reinterpret(0xBFC494F5E9570000),\n reinterpret(0x3FF1BB4A580B3930), reinterpret(0xBFC2F9E424E0A000),\n reinterpret(0x3FF19453847F2200), reinterpret(0xBFC162595AFDC000),\n reinterpret(0x3FF16E06C0D5D73C), reinterpret(0xBFBF9C9A75BD8000),\n reinterpret(0x3FF1485F47B7E4C2), reinterpret(0xBFBC7B575BF9C000),\n reinterpret(0x3FF12358AD0085D1), reinterpret(0xBFB960C60FF48000),\n reinterpret(0x3FF0FEF00F532227), reinterpret(0xBFB64CE247B60000),\n reinterpret(0x3FF0DB2077D03A8F), reinterpret(0xBFB33F78B2014000),\n reinterpret(0x3FF0B7E6D65980D9), reinterpret(0xBFB0387D1A42C000),\n reinterpret(0x3FF0953EFE7B408D), reinterpret(0xBFAA6F9208B50000),\n reinterpret(0x3FF07325CAC53B83), reinterpret(0xBFA47A954F770000),\n reinterpret(0x3FF05197E40D1B5C), reinterpret(0xBF9D23A8C50C0000),\n reinterpret(0x3FF03091C1208EA2), reinterpret(0xBF916A2629780000),\n reinterpret(0x3FF0101025B37E21), reinterpret(0xBF7720F8D8E80000),\n reinterpret(0x3FEFC07EF9CAA76B), reinterpret(0x3F86FE53B1500000),\n reinterpret(0x3FEF4465D3F6F184), reinterpret(0x3FA11CCCE10F8000),\n reinterpret(0x3FEECC079F84107F), reinterpret(0x3FAC4DFC8C8B8000),\n reinterpret(0x3FEE573A99975AE8), reinterpret(0x3FB3AA321E574000),\n reinterpret(0x3FEDE5D6F0BD3DE6), reinterpret(0x3FB918A0D08B8000),\n reinterpret(0x3FED77B681FF38B3), reinterpret(0x3FBE72E9DA044000),\n reinterpret(0x3FED0CB5724DE943), reinterpret(0x3FC1DCD2507F6000),\n reinterpret(0x3FECA4B2DC0E7563), reinterpret(0x3FC476AB03DEA000),\n reinterpret(0x3FEC3F8EE8D6CB51), reinterpret(0x3FC7074377E22000),\n reinterpret(0x3FEBDD2B4F020C4C), reinterpret(0x3FC98EDE8BA94000),\n reinterpret(0x3FEB7D6C006015CA), reinterpret(0x3FCC0DB86AD2E000),\n reinterpret(0x3FEB20366E2E338F), reinterpret(0x3FCE840AAFCEE000),\n reinterpret(0x3FEAC57026295039), reinterpret(0x3FD0790AB4678000),\n reinterpret(0x3FEA6D01BC2731DD), reinterpret(0x3FD1AC056801C000),\n reinterpret(0x3FEA16D3BC3FF18B), reinterpret(0x3FD2DB11D4FEE000),\n reinterpret(0x3FE9C2D14967FEAD), reinterpret(0x3FD406464EC58000),\n reinterpret(0x3FE970E4F47C9902), reinterpret(0x3FD52DBE093AF000),\n reinterpret(0x3FE920FB3982BCF2), reinterpret(0x3FD651902050D000),\n reinterpret(0x3FE8D30187F759F1), reinterpret(0x3FD771D2CDEAF000),\n reinterpret(0x3FE886E5EBB9F66D), reinterpret(0x3FD88E9C857D9000),\n reinterpret(0x3FE83C97B658B994), reinterpret(0x3FD9A80155E16000),\n reinterpret(0x3FE7F405FFC61022), reinterpret(0x3FDABE186ED3D000),\n reinterpret(0x3FE7AD22181415CA), reinterpret(0x3FDBD0F2AEA0E000),\n reinterpret(0x3FE767DCF99EFF8C), reinterpret(0x3FDCE0A43DBF4000)\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2_DATA_TAB2 = memory.data([\n // chi , clo\n reinterpret(0x3FE6200012B90A8E), reinterpret(0x3C8904AB0644B605),\n reinterpret(0x3FE66000045734A6), reinterpret(0x3C61FF9BEA62F7A9),\n reinterpret(0x3FE69FFFC325F2C5), reinterpret(0x3C827ECFCB3C90BA),\n reinterpret(0x3FE6E00038B95A04), reinterpret(0x3C88FF8856739326),\n reinterpret(0x3FE71FFFE09994E3), reinterpret(0x3C8AFD40275F82B1),\n reinterpret(0x3FE7600015590E10), reinterpret(0xBC72FD75B4238341),\n reinterpret(0x3FE7A00012655BD5), reinterpret(0x3C7808E67C242B76),\n reinterpret(0x3FE7E0003259E9A6), reinterpret(0xBC6208E426F622B7),\n reinterpret(0x3FE81FFFEDB4B2D2), reinterpret(0xBC8402461EA5C92F),\n reinterpret(0x3FE860002DFAFCC3), reinterpret(0x3C6DF7F4A2F29A1F),\n reinterpret(0x3FE89FFFF78C6B50), reinterpret(0xBC8E0453094995FD),\n reinterpret(0x3FE8E00039671566), reinterpret(0xBC8A04F3BEC77B45),\n reinterpret(0x3FE91FFFE2BF1745), reinterpret(0xBC77FA34400E203C),\n reinterpret(0x3FE95FFFCC5C9FD1), reinterpret(0xBC76FF8005A0695D),\n reinterpret(0x3FE9A0003BBA4767), reinterpret(0x3C70F8C4C4EC7E03),\n reinterpret(0x3FE9DFFFE7B92DA5), reinterpret(0x3C8E7FD9478C4602),\n reinterpret(0x3FEA1FFFD72EFDAF), reinterpret(0xBC6A0C554DCDAE7E),\n reinterpret(0x3FEA5FFFDE04FF95), reinterpret(0x3C867DA98CE9B26B),\n reinterpret(0x3FEA9FFFCA5E8D2B), reinterpret(0xBC8284C9B54C13DE),\n reinterpret(0x3FEADFFFDDAD03EA), reinterpret(0x3C5812C8EA602E3C),\n reinterpret(0x3FEB1FFFF10D3D4D), reinterpret(0xBC8EFADDAD27789C),\n reinterpret(0x3FEB5FFFCE21165A), reinterpret(0x3C53CB1719C61237),\n reinterpret(0x3FEB9FFFD950E674), reinterpret(0x3C73F7D94194CE00),\n reinterpret(0x3FEBE000139CA8AF), reinterpret(0x3C750AC4215D9BC0),\n reinterpret(0x3FEC20005B46DF99), reinterpret(0x3C6BEEA653E9C1C9),\n reinterpret(0x3FEC600040B9F7AE), reinterpret(0xBC7C079F274A70D6),\n reinterpret(0x3FECA0006255FD8A), reinterpret(0xBC7A0B4076E84C1F),\n reinterpret(0x3FECDFFFD94C095D), reinterpret(0x3C88F933F99AB5D7),\n reinterpret(0x3FED1FFFF975D6CF), reinterpret(0xBC582C08665FE1BE),\n reinterpret(0x3FED5FFFA2561C93), reinterpret(0xBC7B04289BD295F3),\n reinterpret(0x3FED9FFF9D228B0C), reinterpret(0x3C870251340FA236),\n reinterpret(0x3FEDE00065BC7E16), reinterpret(0xBC75011E16A4D80C),\n reinterpret(0x3FEE200002F64791), reinterpret(0x3C89802F09EF62E0),\n reinterpret(0x3FEE600057D7A6D8), reinterpret(0xBC7E0B75580CF7FA),\n reinterpret(0x3FEEA00027EDC00C), reinterpret(0xBC8C848309459811),\n reinterpret(0x3FEEE0006CF5CB7C), reinterpret(0xBC8F8027951576F4),\n reinterpret(0x3FEF2000782B7DCC), reinterpret(0xBC8F81D97274538F),\n reinterpret(0x3FEF6000260C450A), reinterpret(0xBC4071002727FFDC),\n reinterpret(0x3FEF9FFFE88CD533), reinterpret(0xBC581BDCE1FDA8B0),\n reinterpret(0x3FEFDFFFD50F8689), reinterpret(0x3C87F91ACB918E6E),\n reinterpret(0x3FF0200004292367), reinterpret(0x3C9B7FF365324681),\n reinterpret(0x3FF05FFFE3E3D668), reinterpret(0x3C86FA08DDAE957B),\n reinterpret(0x3FF0A0000A85A757), reinterpret(0xBC57E2DE80D3FB91),\n reinterpret(0x3FF0E0001A5F3FCC), reinterpret(0xBC91823305C5F014),\n reinterpret(0x3FF11FFFF8AFBAF5), reinterpret(0xBC8BFABB6680BAC2),\n reinterpret(0x3FF15FFFE54D91AD), reinterpret(0xBC9D7F121737E7EF),\n reinterpret(0x3FF1A00011AC36E1), reinterpret(0x3C9C000A0516F5FF),\n reinterpret(0x3FF1E00019C84248), reinterpret(0xBC9082FBE4DA5DA0),\n reinterpret(0x3FF220000FFE5E6E), reinterpret(0xBC88FDD04C9CFB43),\n reinterpret(0x3FF26000269FD891), reinterpret(0x3C8CFE2A7994D182),\n reinterpret(0x3FF2A00029A6E6DA), reinterpret(0xBC700273715E8BC5),\n reinterpret(0x3FF2DFFFE0293E39), reinterpret(0x3C9B7C39DAB2A6F9),\n reinterpret(0x3FF31FFFF7DCF082), reinterpret(0x3C7DF1336EDC5254),\n reinterpret(0x3FF35FFFF05A8B60), reinterpret(0xBC9E03564CCD31EB),\n reinterpret(0x3FF3A0002E0EAECC), reinterpret(0x3C75F0E74BD3A477),\n reinterpret(0x3FF3E000043BB236), reinterpret(0x3C9C7DCB149D8833),\n reinterpret(0x3FF4200002D187FF), reinterpret(0x3C7E08AFCF2D3D28),\n reinterpret(0x3FF460000D387CB1), reinterpret(0x3C820837856599A6),\n reinterpret(0x3FF4A00004569F89), reinterpret(0xBC89FA5C904FBCD2),\n reinterpret(0x3FF4E000043543F3), reinterpret(0xBC781125ED175329),\n reinterpret(0x3FF51FFFCC027F0F), reinterpret(0x3C9883D8847754DC),\n reinterpret(0x3FF55FFFFD87B36F), reinterpret(0xBC8709E731D02807),\n reinterpret(0x3FF59FFFF21DF7BA), reinterpret(0x3C87F79F68727B02),\n reinterpret(0x3FF5DFFFEBFC3481), reinterpret(0xBC9180902E30E93E)\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function log2_lut(x: f64): f64 {\n const N_MASK = (1 << LOG2_TABLE_BITS) - 1;\n\n const\n LO: u64 = 0x3FEEA4AF00000000, // reinterpret(1.0 - 0x1.5b51p-5)\n HI: u64 = 0x3FF0B55900000000; // reinterpret(1.0 + 0x1.6ab2p-5)\n\n const\n InvLn2hi = reinterpret(0x3FF7154765200000), // 0x1.7154765200000p+0\n InvLn2lo = reinterpret(0x3DE705FC2EEFA200), // 0x1.705fc2eefa200p-33\n Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n const\n B0 = reinterpret(0xBFE71547652B82FE), // -0x1.71547652b82fep-1\n B1 = reinterpret(0x3FDEC709DC3A03F7), // 0x1.ec709dc3a03f7p-2\n B2 = reinterpret(0xBFD71547652B7C3F), // -0x1.71547652b7c3fp-2\n B3 = reinterpret(0x3FD2776C50F05BE4), // 0x1.2776c50f05be4p-2\n B4 = reinterpret(0xBFCEC709DD768FE5), // -0x1.ec709dd768fe5p-3\n B5 = reinterpret(0x3FCA61761EC4E736), // 0x1.a61761ec4e736p-3\n B6 = reinterpret(0xBFC7153FBC64A79B), // -0x1.7153fbc64a79bp-3\n B7 = reinterpret(0x3FC484D154F01B4A), // 0x1.484d154f01b4ap-3\n B8 = reinterpret(0xBFC289E4A72C383C), // -0x1.289e4a72c383cp-3\n B9 = reinterpret(0x3FC0B32F285AEE66); // 0x1.0b32f285aee66p-3\n\n const\n A0 = reinterpret(0xBFE71547652B8339), // -0x1.71547652b8339p-1\n A1 = reinterpret(0x3FDEC709DC3A04BE), // 0x1.ec709dc3a04bep-2\n A2 = reinterpret(0xBFD7154764702FFB), // -0x1.7154764702ffbp-2\n A3 = reinterpret(0x3FD2776C50034C48), // 0x1.2776c50034c48p-2\n A4 = reinterpret(0xBFCEC7B328EA92BC), // -0x1.ec7b328ea92bcp-3\n A5 = reinterpret(0x3FCA6225E117F92E); // 0x1.a6225e117f92ep-3\n\n var ix = reinterpret(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n // #if __FP_FAST_FMA\n // hi = r * InvLn2hi;\n // lo = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -hi);\n // #else\n let rhi = reinterpret(reinterpret(r) & 0xFFFFFFFF00000000);\n let rlo = r - rhi;\n let hi = rhi * InvLn2hi;\n let lo = rlo * InvLn2hi + r * InvLn2lo;\n // #endif\n let r2 = r * r; // rounding error: 0x1p-62\n let r4 = r2 * r2;\n // Worst-case error is less than 0.54 ULP (0.55 ULP without fma)\n let p = r2 * (B0 + r * B1);\n let y = hi + p;\n lo += hi - y + p;\n lo += r4 * (B2 + r * B3 + r2 * (B4 + r * B5) +\n r4 * (B6 + r * B7 + r2 * (B8 + r * B9)));\n return y + lo;\n }\n var top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7ff0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan.\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == 0x7FF0000000000000) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ix = reinterpret(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3FE6000000000000;\n var i = ((tmp >> (52 - LOG2_TABLE_BITS)) & N_MASK);\n var k = tmp >> 52;\n var iz = ix - (tmp & 0xFFF0000000000000);\n\n var invc = load(LOG2_DATA_TAB1 + (i << (1 + alignof())), 0 << alignof()); // T[i].invc;\n var logc = load(LOG2_DATA_TAB1 + (i << (1 + alignof())), 1 << alignof()); // T[i].logc;\n var z = reinterpret(iz);\n var kd = k;\n\n // log2(x) = log2(z/c) + log2(c) + k.\n // r ~= z/c - 1, |r| < 1/(2*N).\n // #if __FP_FAST_FMA\n // \t// rounding error: 0x1p-55/N.\n // \tr = __builtin_fma(z, invc, -1.0);\n // \tt1 = r * InvLn2hi;\n // \tt2 = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -t1);\n // #else\n // rounding error: 0x1p-55/N + 0x1p-65.\n var chi = load(LOG2_DATA_TAB2 + (i << (1 + alignof())), 0 << alignof()); // T[i].chi;\n var clo = load(LOG2_DATA_TAB2 + (i << (1 + alignof())), 1 << alignof()); // T[i].clo;\n\n var r = (z - chi - clo) * invc;\n var rhi = reinterpret(reinterpret(r) & 0xFFFFFFFF00000000);\n var rlo = r - rhi;\n var t1 = rhi * InvLn2hi;\n var t2 = rlo * InvLn2hi + r * InvLn2lo;\n // #endif\n\n // hi + lo = r/ln2 + log2(c) + k\n var t3 = kd + logc;\n var hi = t3 + t1;\n var lo = t3 - hi + t1 + t2;\n\n // log2(r+1) = r/ln2 + r^2*poly(r)\n // Evaluation is optimized assuming superscalar pipelined execution\n var r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma).\n // ~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma).\n var p = A0 + r * A1 + r2 * (A2 + r * A3) + (r2 * r2) * (A4 + r * A5);\n return lo + r2 * p + hi;\n}\n\n//\n// Lookup data for log. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log.c\n//\n\n// @ts-ignore: decorator\n@inline const LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p9 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-66 and\n 3) the rounding error in (double)log(c) is minimized (< 0x1p-66).\n\nNote: 1) ensures that k*ln2hi + logc can be computed without rounding error,\n2) ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to\na single rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log(x)| < 0x1p-4, this is not enough so that is special cased.*/\n\n// @ts-ignore: decorator\n@lazy @inline const LOG_DATA_TAB1 = memory.data([\n // invc , logc\n reinterpret(0x3FF734F0C3E0DE9F), reinterpret(0xBFD7CC7F79E69000),\n reinterpret(0x3FF713786A2CE91F), reinterpret(0xBFD76FEEC20D0000),\n reinterpret(0x3FF6F26008FAB5A0), reinterpret(0xBFD713E31351E000),\n reinterpret(0x3FF6D1A61F138C7D), reinterpret(0xBFD6B85B38287800),\n reinterpret(0x3FF6B1490BC5B4D1), reinterpret(0xBFD65D5590807800),\n reinterpret(0x3FF69147332F0CBA), reinterpret(0xBFD602D076180000),\n reinterpret(0x3FF6719F18224223), reinterpret(0xBFD5A8CA86909000),\n reinterpret(0x3FF6524F99A51ED9), reinterpret(0xBFD54F4356035000),\n reinterpret(0x3FF63356AA8F24C4), reinterpret(0xBFD4F637C36B4000),\n reinterpret(0x3FF614B36B9DDC14), reinterpret(0xBFD49DA7FDA85000),\n reinterpret(0x3FF5F66452C65C4C), reinterpret(0xBFD445923989A800),\n reinterpret(0x3FF5D867B5912C4F), reinterpret(0xBFD3EDF439B0B800),\n reinterpret(0x3FF5BABCCB5B90DE), reinterpret(0xBFD396CE448F7000),\n reinterpret(0x3FF59D61F2D91A78), reinterpret(0xBFD3401E17BDA000),\n reinterpret(0x3FF5805612465687), reinterpret(0xBFD2E9E2EF468000),\n reinterpret(0x3FF56397CEE76BD3), reinterpret(0xBFD2941B3830E000),\n reinterpret(0x3FF54725E2A77F93), reinterpret(0xBFD23EC58CDA8800),\n reinterpret(0x3FF52AFF42064583), reinterpret(0xBFD1E9E129279000),\n reinterpret(0x3FF50F22DBB2BDDF), reinterpret(0xBFD1956D2B48F800),\n reinterpret(0x3FF4F38F4734DED7), reinterpret(0xBFD141679AB9F800),\n reinterpret(0x3FF4D843CFDE2840), reinterpret(0xBFD0EDD094EF9800),\n reinterpret(0x3FF4BD3EC078A3C8), reinterpret(0xBFD09AA518DB1000),\n reinterpret(0x3FF4A27FC3E0258A), reinterpret(0xBFD047E65263B800),\n reinterpret(0x3FF4880524D48434), reinterpret(0xBFCFEB224586F000),\n reinterpret(0x3FF46DCE1B192D0B), reinterpret(0xBFCF474A7517B000),\n reinterpret(0x3FF453D9D3391854), reinterpret(0xBFCEA4443D103000),\n reinterpret(0x3FF43A2744B4845A), reinterpret(0xBFCE020D44E9B000),\n reinterpret(0x3FF420B54115F8FB), reinterpret(0xBFCD60A22977F000),\n reinterpret(0x3FF40782DA3EF4B1), reinterpret(0xBFCCC00104959000),\n reinterpret(0x3FF3EE8F5D57FE8F), reinterpret(0xBFCC202956891000),\n reinterpret(0x3FF3D5D9A00B4CE9), reinterpret(0xBFCB81178D811000),\n reinterpret(0x3FF3BD60C010C12B), reinterpret(0xBFCAE2C9CCD3D000),\n reinterpret(0x3FF3A5242B75DAB8), reinterpret(0xBFCA45402E129000),\n reinterpret(0x3FF38D22CD9FD002), reinterpret(0xBFC9A877681DF000),\n reinterpret(0x3FF3755BC5847A1C), reinterpret(0xBFC90C6D69483000),\n reinterpret(0x3FF35DCE49AD36E2), reinterpret(0xBFC87120A645C000),\n reinterpret(0x3FF34679984DD440), reinterpret(0xBFC7D68FB4143000),\n reinterpret(0x3FF32F5CCEFFCB24), reinterpret(0xBFC73CB83C627000),\n reinterpret(0x3FF3187775A10D49), reinterpret(0xBFC6A39A9B376000),\n reinterpret(0x3FF301C8373E3990), reinterpret(0xBFC60B3154B7A000),\n reinterpret(0x3FF2EB4EBB95F841), reinterpret(0xBFC5737D76243000),\n reinterpret(0x3FF2D50A0219A9D1), reinterpret(0xBFC4DC7B8FC23000),\n reinterpret(0x3FF2BEF9A8B7FD2A), reinterpret(0xBFC4462C51D20000),\n reinterpret(0x3FF2A91C7A0C1BAB), reinterpret(0xBFC3B08ABC830000),\n reinterpret(0x3FF293726014B530), reinterpret(0xBFC31B996B490000),\n reinterpret(0x3FF27DFA5757A1F5), reinterpret(0xBFC2875490A44000),\n reinterpret(0x3FF268B39B1D3BBF), reinterpret(0xBFC1F3B9F879A000),\n reinterpret(0x3FF2539D838FF5BD), reinterpret(0xBFC160C8252CA000),\n reinterpret(0x3FF23EB7AAC9083B), reinterpret(0xBFC0CE7F57F72000),\n reinterpret(0x3FF22A012BA940B6), reinterpret(0xBFC03CDC49FEA000),\n reinterpret(0x3FF2157996CC4132), reinterpret(0xBFBF57BDBC4B8000),\n reinterpret(0x3FF201201DD2FC9B), reinterpret(0xBFBE370896404000),\n reinterpret(0x3FF1ECF4494D480B), reinterpret(0xBFBD17983EF94000),\n reinterpret(0x3FF1D8F5528F6569), reinterpret(0xBFBBF9674ED8A000),\n reinterpret(0x3FF1C52311577E7C), reinterpret(0xBFBADC79202F6000),\n reinterpret(0x3FF1B17C74CB26E9), reinterpret(0xBFB9C0C3E7288000),\n reinterpret(0x3FF19E010C2C1AB6), reinterpret(0xBFB8A646B372C000),\n reinterpret(0x3FF18AB07BB670BD), reinterpret(0xBFB78D01B3AC0000),\n reinterpret(0x3FF1778A25EFBCB6), reinterpret(0xBFB674F145380000),\n reinterpret(0x3FF1648D354C31DA), reinterpret(0xBFB55E0E6D878000),\n reinterpret(0x3FF151B990275FDD), reinterpret(0xBFB4485CDEA1E000),\n reinterpret(0x3FF13F0EA432D24C), reinterpret(0xBFB333D94D6AA000),\n reinterpret(0x3FF12C8B7210F9DA), reinterpret(0xBFB22079F8C56000),\n reinterpret(0x3FF11A3028ECB531), reinterpret(0xBFB10E4698622000),\n reinterpret(0x3FF107FBDA8434AF), reinterpret(0xBFAFFA6C6AD20000),\n reinterpret(0x3FF0F5EE0F4E6BB3), reinterpret(0xBFADDA8D4A774000),\n reinterpret(0x3FF0E4065D2A9FCE), reinterpret(0xBFABBCECE4850000),\n reinterpret(0x3FF0D244632CA521), reinterpret(0xBFA9A1894012C000),\n reinterpret(0x3FF0C0A77CE2981A), reinterpret(0xBFA788583302C000),\n reinterpret(0x3FF0AF2F83C636D1), reinterpret(0xBFA5715E67D68000),\n reinterpret(0x3FF09DDB98A01339), reinterpret(0xBFA35C8A49658000),\n reinterpret(0x3FF08CABAF52E7DF), reinterpret(0xBFA149E364154000),\n reinterpret(0x3FF07B9F2F4E28FB), reinterpret(0xBF9E72C082EB8000),\n reinterpret(0x3FF06AB58C358F19), reinterpret(0xBF9A55F152528000),\n reinterpret(0x3FF059EEA5ECF92C), reinterpret(0xBF963D62CF818000),\n reinterpret(0x3FF04949CDD12C90), reinterpret(0xBF9228FB8CAA0000),\n reinterpret(0x3FF038C6C6F0ADA9), reinterpret(0xBF8C317B20F90000),\n reinterpret(0x3FF02865137932A9), reinterpret(0xBF8419355DAA0000),\n reinterpret(0x3FF0182427EA7348), reinterpret(0xBF781203C2EC0000),\n reinterpret(0x3FF008040614B195), reinterpret(0xBF60040979240000),\n reinterpret(0x3FEFE01FF726FA1A), reinterpret(0x3F6FEFF384900000),\n reinterpret(0x3FEFA11CC261EA74), reinterpret(0x3F87DC41353D0000),\n reinterpret(0x3FEF6310B081992E), reinterpret(0x3F93CEA3C4C28000),\n reinterpret(0x3FEF25F63CEEADCD), reinterpret(0x3F9B9FC114890000),\n reinterpret(0x3FEEE9C8039113E7), reinterpret(0x3FA1B0D8CE110000),\n reinterpret(0x3FEEAE8078CBB1AB), reinterpret(0x3FA58A5BD001C000),\n reinterpret(0x3FEE741AA29D0C9B), reinterpret(0x3FA95C8340D88000),\n reinterpret(0x3FEE3A91830A99B5), reinterpret(0x3FAD276AEF578000),\n reinterpret(0x3FEE01E009609A56), reinterpret(0x3FB07598E598C000),\n reinterpret(0x3FEDCA01E577BB98), reinterpret(0x3FB253F5E30D2000),\n reinterpret(0x3FED92F20B7C9103), reinterpret(0x3FB42EDD8B380000),\n reinterpret(0x3FED5CAC66FB5CCE), reinterpret(0x3FB606598757C000),\n reinterpret(0x3FED272CAA5EDE9D), reinterpret(0x3FB7DA76356A0000),\n reinterpret(0x3FECF26E3E6B2CCD), reinterpret(0x3FB9AB434E1C6000),\n reinterpret(0x3FECBE6DA2A77902), reinterpret(0x3FBB78C7BB0D6000),\n reinterpret(0x3FEC8B266D37086D), reinterpret(0x3FBD431332E72000),\n reinterpret(0x3FEC5894BD5D5804), reinterpret(0x3FBF0A3171DE6000),\n reinterpret(0x3FEC26B533BB9F8C), reinterpret(0x3FC067152B914000),\n reinterpret(0x3FEBF583EEECE73F), reinterpret(0x3FC147858292B000),\n reinterpret(0x3FEBC4FD75DB96C1), reinterpret(0x3FC2266ECDCA3000),\n reinterpret(0x3FEB951E0C864A28), reinterpret(0x3FC303D7A6C55000),\n reinterpret(0x3FEB65E2C5EF3E2C), reinterpret(0x3FC3DFC33C331000),\n reinterpret(0x3FEB374867C9888B), reinterpret(0x3FC4BA366B7A8000),\n reinterpret(0x3FEB094B211D304A), reinterpret(0x3FC5933928D1F000),\n reinterpret(0x3FEADBE885F2EF7E), reinterpret(0x3FC66ACD2418F000),\n reinterpret(0x3FEAAF1D31603DA2), reinterpret(0x3FC740F8EC669000),\n reinterpret(0x3FEA82E63FD358A7), reinterpret(0x3FC815C0F51AF000),\n reinterpret(0x3FEA5740EF09738B), reinterpret(0x3FC8E92954F68000),\n reinterpret(0x3FEA2C2A90AB4B27), reinterpret(0x3FC9BB3602F84000),\n reinterpret(0x3FEA01A01393F2D1), reinterpret(0x3FCA8BED1C2C0000),\n reinterpret(0x3FE9D79F24DB3C1B), reinterpret(0x3FCB5B515C01D000),\n reinterpret(0x3FE9AE2505C7B190), reinterpret(0x3FCC2967CCBCC000),\n reinterpret(0x3FE9852EF297CE2F), reinterpret(0x3FCCF635D5486000),\n reinterpret(0x3FE95CBAEEA44B75), reinterpret(0x3FCDC1BD3446C000),\n reinterpret(0x3FE934C69DE74838), reinterpret(0x3FCE8C01B8CFE000),\n reinterpret(0x3FE90D4F2F6752E6), reinterpret(0x3FCF5509C0179000),\n reinterpret(0x3FE8E6528EFFD79D), reinterpret(0x3FD00E6C121FB800),\n reinterpret(0x3FE8BFCE9FCC007C), reinterpret(0x3FD071B80E93D000),\n reinterpret(0x3FE899C0DABEC30E), reinterpret(0x3FD0D46B9E867000),\n reinterpret(0x3FE87427AA2317FB), reinterpret(0x3FD13687334BD000),\n reinterpret(0x3FE84F00ACB39A08), reinterpret(0x3FD1980D67234800),\n reinterpret(0x3FE82A49E8653E55), reinterpret(0x3FD1F8FFE0CC8000),\n reinterpret(0x3FE8060195F40260), reinterpret(0x3FD2595FD7636800),\n reinterpret(0x3FE7E22563E0A329), reinterpret(0x3FD2B9300914A800),\n reinterpret(0x3FE7BEB377DCB5AD), reinterpret(0x3FD3187210436000),\n reinterpret(0x3FE79BAA679725C2), reinterpret(0x3FD377266DEC1800),\n reinterpret(0x3FE77907F2170657), reinterpret(0x3FD3D54FFBAF3000),\n reinterpret(0x3FE756CADBD6130C), reinterpret(0x3FD432EEE32FE000)\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOG_DATA_TAB2 = memory.data([\n // chi , clo\n reinterpret(0x3FE61000014FB66B), reinterpret(0x3C7E026C91425B3C),\n reinterpret(0x3FE63000034DB495), reinterpret(0x3C8DBFEA48005D41),\n reinterpret(0x3FE650000D94D478), reinterpret(0x3C8E7FA786D6A5B7),\n reinterpret(0x3FE67000074E6FAD), reinterpret(0x3C61FCEA6B54254C),\n reinterpret(0x3FE68FFFFEDF0FAE), reinterpret(0xBC7C7E274C590EFD),\n reinterpret(0x3FE6B0000763C5BC), reinterpret(0xBC8AC16848DCDA01),\n reinterpret(0x3FE6D0001E5CC1F6), reinterpret(0x3C833F1C9D499311),\n reinterpret(0x3FE6EFFFEB05F63E), reinterpret(0xBC7E80041AE22D53),\n reinterpret(0x3FE710000E869780), reinterpret(0x3C7BFF6671097952),\n reinterpret(0x3FE72FFFFC67E912), reinterpret(0x3C8C00E226BD8724),\n reinterpret(0x3FE74FFFDF81116A), reinterpret(0xBC6E02916EF101D2),\n reinterpret(0x3FE770000F679C90), reinterpret(0xBC67FC71CD549C74),\n reinterpret(0x3FE78FFFFA7EC835), reinterpret(0x3C81BEC19EF50483),\n reinterpret(0x3FE7AFFFFE20C2E6), reinterpret(0xBC707E1729CC6465),\n reinterpret(0x3FE7CFFFED3FC900), reinterpret(0xBC808072087B8B1C),\n reinterpret(0x3FE7EFFFE9261A76), reinterpret(0x3C8DC0286D9DF9AE),\n reinterpret(0x3FE81000049CA3E8), reinterpret(0x3C897FD251E54C33),\n reinterpret(0x3FE8300017932C8F), reinterpret(0xBC8AFEE9B630F381),\n reinterpret(0x3FE850000633739C), reinterpret(0x3C89BFBF6B6535BC),\n reinterpret(0x3FE87000204289C6), reinterpret(0xBC8BBF65F3117B75),\n reinterpret(0x3FE88FFFEBF57904), reinterpret(0xBC89006EA23DCB57),\n reinterpret(0x3FE8B00022BC04DF), reinterpret(0xBC7D00DF38E04B0A),\n reinterpret(0x3FE8CFFFE50C1B8A), reinterpret(0xBC88007146FF9F05),\n reinterpret(0x3FE8EFFFFC918E43), reinterpret(0x3C83817BD07A7038),\n reinterpret(0x3FE910001EFA5FC7), reinterpret(0x3C893E9176DFB403),\n reinterpret(0x3FE9300013467BB9), reinterpret(0x3C7F804E4B980276),\n reinterpret(0x3FE94FFFE6EE076F), reinterpret(0xBC8F7EF0D9FF622E),\n reinterpret(0x3FE96FFFDE3C12D1), reinterpret(0xBC7082AA962638BA),\n reinterpret(0x3FE98FFFF4458A0D), reinterpret(0xBC87801B9164A8EF),\n reinterpret(0x3FE9AFFFDD982E3E), reinterpret(0xBC8740E08A5A9337),\n reinterpret(0x3FE9CFFFED49FB66), reinterpret(0x3C3FCE08C19BE000),\n reinterpret(0x3FE9F00020F19C51), reinterpret(0xBC8A3FAA27885B0A),\n reinterpret(0x3FEA10001145B006), reinterpret(0x3C74FF489958DA56),\n reinterpret(0x3FEA300007BBF6FA), reinterpret(0x3C8CBEAB8A2B6D18),\n reinterpret(0x3FEA500010971D79), reinterpret(0x3C88FECADD787930),\n reinterpret(0x3FEA70001DF52E48), reinterpret(0xBC8F41763DD8ABDB),\n reinterpret(0x3FEA90001C593352), reinterpret(0xBC8EBF0284C27612),\n reinterpret(0x3FEAB0002A4F3E4B), reinterpret(0xBC69FD043CFF3F5F),\n reinterpret(0x3FEACFFFD7AE1ED1), reinterpret(0xBC823EE7129070B4),\n reinterpret(0x3FEAEFFFEE510478), reinterpret(0x3C6A063EE00EDEA3),\n reinterpret(0x3FEB0FFFDB650D5B), reinterpret(0x3C5A06C8381F0AB9),\n reinterpret(0x3FEB2FFFFEAACA57), reinterpret(0xBC79011E74233C1D),\n reinterpret(0x3FEB4FFFD995BADC), reinterpret(0xBC79FF1068862A9F),\n reinterpret(0x3FEB7000249E659C), reinterpret(0x3C8AFF45D0864F3E),\n reinterpret(0x3FEB8FFFF9871640), reinterpret(0x3C7CFE7796C2C3F9),\n reinterpret(0x3FEBAFFFD204CB4F), reinterpret(0xBC63FF27EEF22BC4),\n reinterpret(0x3FEBCFFFD2415C45), reinterpret(0xBC6CFFB7EE3BEA21),\n reinterpret(0x3FEBEFFFF86309DF), reinterpret(0xBC814103972E0B5C),\n reinterpret(0x3FEC0FFFE1B57653), reinterpret(0x3C8BC16494B76A19),\n reinterpret(0x3FEC2FFFF1FA57E3), reinterpret(0xBC64FEEF8D30C6ED),\n reinterpret(0x3FEC4FFFDCBFE424), reinterpret(0xBC843F68BCEC4775),\n reinterpret(0x3FEC6FFFED54B9F7), reinterpret(0x3C847EA3F053E0EC),\n reinterpret(0x3FEC8FFFEB998FD5), reinterpret(0x3C7383068DF992F1),\n reinterpret(0x3FECB0002125219A), reinterpret(0xBC68FD8E64180E04),\n reinterpret(0x3FECCFFFDD94469C), reinterpret(0x3C8E7EBE1CC7EA72),\n reinterpret(0x3FECEFFFEAFDC476), reinterpret(0x3C8EBE39AD9F88FE),\n reinterpret(0x3FED1000169AF82B), reinterpret(0x3C757D91A8B95A71),\n reinterpret(0x3FED30000D0FF71D), reinterpret(0x3C89C1906970C7DA),\n reinterpret(0x3FED4FFFEA790FC4), reinterpret(0xBC580E37C558FE0C),\n reinterpret(0x3FED70002EDC87E5), reinterpret(0xBC7F80D64DC10F44),\n reinterpret(0x3FED900021DC82AA), reinterpret(0xBC747C8F94FD5C5C),\n reinterpret(0x3FEDAFFFD86B0283), reinterpret(0x3C8C7F1DC521617E),\n reinterpret(0x3FEDD000296C4739), reinterpret(0x3C88019EB2FFB153),\n reinterpret(0x3FEDEFFFE54490F5), reinterpret(0x3C6E00D2C652CC89),\n reinterpret(0x3FEE0FFFCDABF694), reinterpret(0xBC7F8340202D69D2),\n reinterpret(0x3FEE2FFFDB52C8DD), reinterpret(0x3C7B00C1CA1B0864),\n reinterpret(0x3FEE4FFFF24216EF), reinterpret(0x3C72FFA8B094AB51),\n reinterpret(0x3FEE6FFFE88A5E11), reinterpret(0xBC57F673B1EFBE59),\n reinterpret(0x3FEE9000119EFF0D), reinterpret(0xBC84808D5E0BC801),\n reinterpret(0x3FEEAFFFDFA51744), reinterpret(0x3C780006D54320B5),\n reinterpret(0x3FEED0001A127FA1), reinterpret(0xBC5002F860565C92),\n reinterpret(0x3FEEF00007BABCC4), reinterpret(0xBC8540445D35E611),\n reinterpret(0x3FEF0FFFF57A8D02), reinterpret(0xBC4FFB3139EF9105),\n reinterpret(0x3FEF30001EE58AC7), reinterpret(0x3C8A81ACF2731155),\n reinterpret(0x3FEF4FFFF5823494), reinterpret(0x3C8A3F41D4D7C743),\n reinterpret(0x3FEF6FFFFCA94C6B), reinterpret(0xBC6202F41C987875),\n reinterpret(0x3FEF8FFFE1F9C441), reinterpret(0x3C777DD1F477E74B),\n reinterpret(0x3FEFAFFFD2E0E37E), reinterpret(0xBC6F01199A7CA331),\n reinterpret(0x3FEFD0001C77E49E), reinterpret(0x3C7181EE4BCEACB1),\n reinterpret(0x3FEFEFFFF7E0C331), reinterpret(0xBC6E05370170875A),\n reinterpret(0x3FF00FFFF465606E), reinterpret(0xBC8A7EAD491C0ADA),\n reinterpret(0x3FF02FFFF3867A58), reinterpret(0xBC977F69C3FCB2E0),\n reinterpret(0x3FF04FFFFDFC0D17), reinterpret(0x3C97BFFE34CB945B),\n reinterpret(0x3FF0700003CD4D82), reinterpret(0x3C820083C0E456CB),\n reinterpret(0x3FF08FFFF9F2CBE8), reinterpret(0xBC6DFFDFBE37751A),\n reinterpret(0x3FF0B000010CDA65), reinterpret(0xBC913F7FAEE626EB),\n reinterpret(0x3FF0D00001A4D338), reinterpret(0x3C807DFA79489FF7),\n reinterpret(0x3FF0EFFFFADAFDFD), reinterpret(0xBC77040570D66BC0),\n reinterpret(0x3FF110000BBAFD96), reinterpret(0x3C8E80D4846D0B62),\n reinterpret(0x3FF12FFFFAE5F45D), reinterpret(0x3C9DBFFA64FD36EF),\n reinterpret(0x3FF150000DD59AD9), reinterpret(0x3C9A0077701250AE),\n reinterpret(0x3FF170000F21559A), reinterpret(0x3C8DFDF9E2E3DEEE),\n reinterpret(0x3FF18FFFFC275426), reinterpret(0x3C910030DC3B7273),\n reinterpret(0x3FF1B000123D3C59), reinterpret(0x3C997F7980030188),\n reinterpret(0x3FF1CFFFF8299EB7), reinterpret(0xBC65F932AB9F8C67),\n reinterpret(0x3FF1EFFFF48AD400), reinterpret(0x3C937FBF9DA75BEB),\n reinterpret(0x3FF210000C8B86A4), reinterpret(0x3C9F806B91FD5B22),\n reinterpret(0x3FF2300003854303), reinterpret(0x3C93FFC2EB9FBF33),\n reinterpret(0x3FF24FFFFFBCF684), reinterpret(0x3C7601E77E2E2E72),\n reinterpret(0x3FF26FFFF52921D9), reinterpret(0x3C7FFCBB767F0C61),\n reinterpret(0x3FF2900014933A3C), reinterpret(0xBC7202CA3C02412B),\n reinterpret(0x3FF2B00014556313), reinterpret(0xBC92808233F21F02),\n reinterpret(0x3FF2CFFFEBFE523B), reinterpret(0xBC88FF7E384FDCF2),\n reinterpret(0x3FF2F0000BB8AD96), reinterpret(0xBC85FF51503041C5),\n reinterpret(0x3FF30FFFFB7AE2AF), reinterpret(0xBC810071885E289D),\n reinterpret(0x3FF32FFFFEAC5F7F), reinterpret(0xBC91FF5D3FB7B715),\n reinterpret(0x3FF350000CA66756), reinterpret(0x3C957F82228B82BD),\n reinterpret(0x3FF3700011FBF721), reinterpret(0x3C8000BAC40DD5CC),\n reinterpret(0x3FF38FFFF9592FB9), reinterpret(0xBC943F9D2DB2A751),\n reinterpret(0x3FF3B00004DDD242), reinterpret(0x3C857F6B707638E1),\n reinterpret(0x3FF3CFFFF5B2C957), reinterpret(0x3C7A023A10BF1231),\n reinterpret(0x3FF3EFFFEAB0B418), reinterpret(0x3C987F6D66B152B0),\n reinterpret(0x3FF410001532AFF4), reinterpret(0x3C67F8375F198524),\n reinterpret(0x3FF4300017478B29), reinterpret(0x3C8301E672DC5143),\n reinterpret(0x3FF44FFFE795B463), reinterpret(0x3C89FF69B8B2895A),\n reinterpret(0x3FF46FFFE80475E0), reinterpret(0xBC95C0B19BC2F254),\n reinterpret(0x3FF48FFFEF6FC1E7), reinterpret(0x3C9B4009F23A2A72),\n reinterpret(0x3FF4AFFFE5BEA704), reinterpret(0xBC94FFB7BF0D7D45),\n reinterpret(0x3FF4D000171027DE), reinterpret(0xBC99C06471DC6A3D),\n reinterpret(0x3FF4F0000FF03EE2), reinterpret(0x3C977F890B85531C),\n reinterpret(0x3FF5100012DC4BD1), reinterpret(0x3C6004657166A436),\n reinterpret(0x3FF530001605277A), reinterpret(0xBC96BFCECE233209),\n reinterpret(0x3FF54FFFECDB704C), reinterpret(0xBC8902720505A1D7),\n reinterpret(0x3FF56FFFEF5F54A9), reinterpret(0x3C9BBFE60EC96412),\n reinterpret(0x3FF5900017E61012), reinterpret(0x3C887EC581AFEF90),\n reinterpret(0x3FF5B00003C93E92), reinterpret(0xBC9F41080ABF0CC0),\n reinterpret(0x3FF5D0001D4919BC), reinterpret(0xBC98812AFB254729),\n reinterpret(0x3FF5EFFFE7B87A89), reinterpret(0xBC947EB780ED6904)\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function log_lut(x: f64): f64 {\n const N_MASK = (1 << LOG_TABLE_BITS) - 1;\n\n const\n B0 = reinterpret(0xBFE0000000000000), // -0x1p-1\n B1 = reinterpret(0x3FD5555555555577), // 0x1.5555555555577p-2\n B2 = reinterpret(0xBFCFFFFFFFFFFDCB), // -0x1.ffffffffffdcbp-3\n B3 = reinterpret(0x3FC999999995DD0C), // 0x1.999999995dd0cp-3\n B4 = reinterpret(0xBFC55555556745A7), // -0x1.55555556745a7p-3\n B5 = reinterpret(0x3FC24924A344DE30), // 0x1.24924a344de3p-3\n B6 = reinterpret(0xBFBFFFFFA4423D65), // -0x1.fffffa4423d65p-4\n B7 = reinterpret(0x3FBC7184282AD6CA), // 0x1.c7184282ad6cap-4\n B8 = reinterpret(0xBFB999EB43B068FF), // -0x1.999eb43b068ffp-4\n B9 = reinterpret(0x3FB78182F7AFD085), // 0x1.78182f7afd085p-4\n B10 = reinterpret(0xBFB5521375D145CD); // -0x1.5521375d145cdp-4\n\n const\n A0 = reinterpret(0xBFE0000000000001), // -0x1.0000000000001p-1\n A1 = reinterpret(0x3FD555555551305B), // 0x1.555555551305bp-2\n A2 = reinterpret(0xBFCFFFFFFFEB4590), // -0x1.fffffffeb459p-3\n A3 = reinterpret(0x3FC999B324F10111), // 0x1.999b324f10111p-3\n A4 = reinterpret(0xBFC55575E506C89F); // -0x1.55575e506c89fp-3\n\n const\n LO: u64 = 0x3FEE000000000000,\n HI: u64 = 0x3FF1090000000000;\n\n const\n Ln2hi = reinterpret(0x3FE62E42FEFA3800), // 0x1.62e42fefa3800p-1\n Ln2lo = reinterpret(0x3D2EF35793C76730), // 0x1.ef35793c76730p-45\n Ox1p27 = reinterpret(0x41A0000000000000), // 0x1p27\n Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n var ix = reinterpret(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n let r2 = r * r;\n let r3 = r2 * r;\n let y =\n r3 * (B1 + r * B2 + r2 * B3 +\n r3 * (B4 + r * B5 + r2 * B6 +\n r3 * (B7 + r * B8 + r2 * B9 + r3 * B10)));\n // Worst-case error is around 0.507 ULP\n let w = r * Ox1p27;\n let rhi = r + w - w;\n let rlo = r - rhi;\n w = rhi * rhi * B0; // B[0] == -0.5\n let hi = r + w;\n let lo = r - hi + w;\n lo += B0 * rlo * (rhi + r);\n return y + lo + hi;\n }\n var top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7FF0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == reinterpret(Infinity)) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it\n ix = reinterpret(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3FE6000000000000;\n var i = ((tmp >> (52 - LOG_TABLE_BITS)) & N_MASK);\n var k = tmp >> 52;\n var iz = ix - (tmp & (u64(0xFFF) << 52));\n\n var invc = load(LOG_DATA_TAB1 + (i << (1 + alignof())), 0 << alignof()); // T[i].invc;\n var logc = load(LOG_DATA_TAB1 + (i << (1 + alignof())), 1 << alignof()); // T[i].logc;\n var z = reinterpret(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2.\n // r ~= z/c - 1, |r| < 1/(2*N)\n // #if __FP_FAST_FMA\n // \t// rounding error: 0x1p-55/N\n // \tr = __builtin_fma(z, invc, -1.0);\n // #else\n // rounding error: 0x1p-55/N + 0x1p-66\n const chi = load(LOG_DATA_TAB2 + (i << (1 + alignof())), 0 << alignof()); // T2[i].chi\n const clo = load(LOG_DATA_TAB2 + (i << (1 + alignof())), 1 << alignof()); // T2[i].clo\n var r = (z - chi - clo) * invc;\n // #endif\n var kd = k;\n\n // hi + lo = r + log(c) + k*Ln2\n var w = kd * Ln2hi + logc;\n var hi = w + r;\n var lo = w - hi + r + kd * Ln2lo;\n\n // log(x) = lo + (log1p(r) - r) + hi\n var r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst case error if |y| > 0x1p-5:\n // 0.5 + 4.13/N + abs-poly-error*2^57 ULP (+ 0.002 ULP without fma)\n // Worst case error if |y| > 0x1p-4:\n // 0.5 + 2.06/N + abs-poly-error*2^56 ULP (+ 0.001 ULP without fma).\n return lo + r2 * A0 + r * r2 * (A1 + r * A2 + r2 * (A3 + r * A4)) + hi;\n}\n\n//\n// Lookup data for pow. See: https://git.musl-libc.org/cgit/musl/tree/src/math/pow.c\n//\n\n// @ts-ignore: decorator\n@inline const POW_LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [0x1.69555p-1; 0x1.69555p0] which is split into N subintervals\nand z falls into the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = round(0x1p43*log(c))/0x1p43\n tab[i].logctail = (double)(log(c) - logc)\n\nwhere c is chosen near the center of the subinterval such that 1/c has only a\nfew precision bits so z/c - 1 is exactly representible as double:\n\n 1/c = center < 1 ? round(N/center)/N : round(2*N/center)/N/2\n\nNote: |z/c - 1| < 1/N for the chosen c, |log(c) - logc - logctail| < 0x1p-97,\nthe last few bits of logc are rounded away so k*ln2hi + logc has no rounding\nerror and the interval for z is selected such that near x == 1, where log(x)\nis tiny, large cancellation error is avoided in logc + poly(z/c - 1). */\n\n// @ts-ignore: decorator\n@lazy @inline const POW_LOG_DATA_TAB = memory.data([\n // invc ,pad, logc , logctail\n reinterpret(0x3FF6A00000000000), 0, reinterpret(0xBFD62C82F2B9C800), reinterpret(0x3CFAB42428375680),\n reinterpret(0x3FF6800000000000), 0, reinterpret(0xBFD5D1BDBF580800), reinterpret(0xBD1CA508D8E0F720),\n reinterpret(0x3FF6600000000000), 0, reinterpret(0xBFD5767717455800), reinterpret(0xBD2362A4D5B6506D),\n reinterpret(0x3FF6400000000000), 0, reinterpret(0xBFD51AAD872DF800), reinterpret(0xBCE684E49EB067D5),\n reinterpret(0x3FF6200000000000), 0, reinterpret(0xBFD4BE5F95777800), reinterpret(0xBD041B6993293EE0),\n reinterpret(0x3FF6000000000000), 0, reinterpret(0xBFD4618BC21C6000), reinterpret(0x3D13D82F484C84CC),\n reinterpret(0x3FF5E00000000000), 0, reinterpret(0xBFD404308686A800), reinterpret(0x3CDC42F3ED820B3A),\n reinterpret(0x3FF5C00000000000), 0, reinterpret(0xBFD3A64C55694800), reinterpret(0x3D20B1C686519460),\n reinterpret(0x3FF5A00000000000), 0, reinterpret(0xBFD347DD9A988000), reinterpret(0x3D25594DD4C58092),\n reinterpret(0x3FF5800000000000), 0, reinterpret(0xBFD2E8E2BAE12000), reinterpret(0x3D267B1E99B72BD8),\n reinterpret(0x3FF5600000000000), 0, reinterpret(0xBFD2895A13DE8800), reinterpret(0x3D15CA14B6CFB03F),\n reinterpret(0x3FF5600000000000), 0, reinterpret(0xBFD2895A13DE8800), reinterpret(0x3D15CA14B6CFB03F),\n reinterpret(0x3FF5400000000000), 0, reinterpret(0xBFD22941FBCF7800), reinterpret(0xBD165A242853DA76),\n reinterpret(0x3FF5200000000000), 0, reinterpret(0xBFD1C898C1699800), reinterpret(0xBD1FAFBC68E75404),\n reinterpret(0x3FF5000000000000), 0, reinterpret(0xBFD1675CABABA800), reinterpret(0x3D1F1FC63382A8F0),\n reinterpret(0x3FF4E00000000000), 0, reinterpret(0xBFD1058BF9AE4800), reinterpret(0xBD26A8C4FD055A66),\n reinterpret(0x3FF4C00000000000), 0, reinterpret(0xBFD0A324E2739000), reinterpret(0xBD0C6BEE7EF4030E),\n reinterpret(0x3FF4A00000000000), 0, reinterpret(0xBFD0402594B4D000), reinterpret(0xBCF036B89EF42D7F),\n reinterpret(0x3FF4A00000000000), 0, reinterpret(0xBFD0402594B4D000), reinterpret(0xBCF036B89EF42D7F),\n reinterpret(0x3FF4800000000000), 0, reinterpret(0xBFCFB9186D5E4000), reinterpret(0x3D0D572AAB993C87),\n reinterpret(0x3FF4600000000000), 0, reinterpret(0xBFCEF0ADCBDC6000), reinterpret(0x3D2B26B79C86AF24),\n reinterpret(0x3FF4400000000000), 0, reinterpret(0xBFCE27076E2AF000), reinterpret(0xBD172F4F543FFF10),\n reinterpret(0x3FF4200000000000), 0, reinterpret(0xBFCD5C216B4FC000), reinterpret(0x3D21BA91BBCA681B),\n reinterpret(0x3FF4000000000000), 0, reinterpret(0xBFCC8FF7C79AA000), reinterpret(0x3D27794F689F8434),\n reinterpret(0x3FF4000000000000), 0, reinterpret(0xBFCC8FF7C79AA000), reinterpret(0x3D27794F689F8434),\n reinterpret(0x3FF3E00000000000), 0, reinterpret(0xBFCBC286742D9000), reinterpret(0x3D194EB0318BB78F),\n reinterpret(0x3FF3C00000000000), 0, reinterpret(0xBFCAF3C94E80C000), reinterpret(0x3CBA4E633FCD9066),\n reinterpret(0x3FF3A00000000000), 0, reinterpret(0xBFCA23BC1FE2B000), reinterpret(0xBD258C64DC46C1EA),\n reinterpret(0x3FF3A00000000000), 0, reinterpret(0xBFCA23BC1FE2B000), reinterpret(0xBD258C64DC46C1EA),\n reinterpret(0x3FF3800000000000), 0, reinterpret(0xBFC9525A9CF45000), reinterpret(0xBD2AD1D904C1D4E3),\n reinterpret(0x3FF3600000000000), 0, reinterpret(0xBFC87FA06520D000), reinterpret(0x3D2BBDBF7FDBFA09),\n reinterpret(0x3FF3400000000000), 0, reinterpret(0xBFC7AB890210E000), reinterpret(0x3D2BDB9072534A58),\n reinterpret(0x3FF3400000000000), 0, reinterpret(0xBFC7AB890210E000), reinterpret(0x3D2BDB9072534A58),\n reinterpret(0x3FF3200000000000), 0, reinterpret(0xBFC6D60FE719D000), reinterpret(0xBD10E46AA3B2E266),\n reinterpret(0x3FF3000000000000), 0, reinterpret(0xBFC5FF3070A79000), reinterpret(0xBD1E9E439F105039),\n reinterpret(0x3FF3000000000000), 0, reinterpret(0xBFC5FF3070A79000), reinterpret(0xBD1E9E439F105039),\n reinterpret(0x3FF2E00000000000), 0, reinterpret(0xBFC526E5E3A1B000), reinterpret(0xBD20DE8B90075B8F),\n reinterpret(0x3FF2C00000000000), 0, reinterpret(0xBFC44D2B6CCB8000), reinterpret(0x3D170CC16135783C),\n reinterpret(0x3FF2C00000000000), 0, reinterpret(0xBFC44D2B6CCB8000), reinterpret(0x3D170CC16135783C),\n reinterpret(0x3FF2A00000000000), 0, reinterpret(0xBFC371FC201E9000), reinterpret(0x3CF178864D27543A),\n reinterpret(0x3FF2800000000000), 0, reinterpret(0xBFC29552F81FF000), reinterpret(0xBD248D301771C408),\n reinterpret(0x3FF2600000000000), 0, reinterpret(0xBFC1B72AD52F6000), reinterpret(0xBD2E80A41811A396),\n reinterpret(0x3FF2600000000000), 0, reinterpret(0xBFC1B72AD52F6000), reinterpret(0xBD2E80A41811A396),\n reinterpret(0x3FF2400000000000), 0, reinterpret(0xBFC0D77E7CD09000), reinterpret(0x3D0A699688E85BF4),\n reinterpret(0x3FF2400000000000), 0, reinterpret(0xBFC0D77E7CD09000), reinterpret(0x3D0A699688E85BF4),\n reinterpret(0x3FF2200000000000), 0, reinterpret(0xBFBFEC9131DBE000), reinterpret(0xBD2575545CA333F2),\n reinterpret(0x3FF2000000000000), 0, reinterpret(0xBFBE27076E2B0000), reinterpret(0x3D2A342C2AF0003C),\n reinterpret(0x3FF2000000000000), 0, reinterpret(0xBFBE27076E2B0000), reinterpret(0x3D2A342C2AF0003C),\n reinterpret(0x3FF1E00000000000), 0, reinterpret(0xBFBC5E548F5BC000), reinterpret(0xBD1D0C57585FBE06),\n reinterpret(0x3FF1C00000000000), 0, reinterpret(0xBFBA926D3A4AE000), reinterpret(0x3D253935E85BAAC8),\n reinterpret(0x3FF1C00000000000), 0, reinterpret(0xBFBA926D3A4AE000), reinterpret(0x3D253935E85BAAC8),\n reinterpret(0x3FF1A00000000000), 0, reinterpret(0xBFB8C345D631A000), reinterpret(0x3D137C294D2F5668),\n reinterpret(0x3FF1A00000000000), 0, reinterpret(0xBFB8C345D631A000), reinterpret(0x3D137C294D2F5668),\n reinterpret(0x3FF1800000000000), 0, reinterpret(0xBFB6F0D28AE56000), reinterpret(0xBD269737C93373DA),\n reinterpret(0x3FF1600000000000), 0, reinterpret(0xBFB51B073F062000), reinterpret(0x3D1F025B61C65E57),\n reinterpret(0x3FF1600000000000), 0, reinterpret(0xBFB51B073F062000), reinterpret(0x3D1F025B61C65E57),\n reinterpret(0x3FF1400000000000), 0, reinterpret(0xBFB341D7961BE000), reinterpret(0x3D2C5EDACCF913DF),\n reinterpret(0x3FF1400000000000), 0, reinterpret(0xBFB341D7961BE000), reinterpret(0x3D2C5EDACCF913DF),\n reinterpret(0x3FF1200000000000), 0, reinterpret(0xBFB16536EEA38000), reinterpret(0x3D147C5E768FA309),\n reinterpret(0x3FF1000000000000), 0, reinterpret(0xBFAF0A30C0118000), reinterpret(0x3D2D599E83368E91),\n reinterpret(0x3FF1000000000000), 0, reinterpret(0xBFAF0A30C0118000), reinterpret(0x3D2D599E83368E91),\n reinterpret(0x3FF0E00000000000), 0, reinterpret(0xBFAB42DD71198000), reinterpret(0x3D1C827AE5D6704C),\n reinterpret(0x3FF0E00000000000), 0, reinterpret(0xBFAB42DD71198000), reinterpret(0x3D1C827AE5D6704C),\n reinterpret(0x3FF0C00000000000), 0, reinterpret(0xBFA77458F632C000), reinterpret(0xBD2CFC4634F2A1EE),\n reinterpret(0x3FF0C00000000000), 0, reinterpret(0xBFA77458F632C000), reinterpret(0xBD2CFC4634F2A1EE),\n reinterpret(0x3FF0A00000000000), 0, reinterpret(0xBFA39E87B9FEC000), reinterpret(0x3CF502B7F526FEAA),\n reinterpret(0x3FF0A00000000000), 0, reinterpret(0xBFA39E87B9FEC000), reinterpret(0x3CF502B7F526FEAA),\n reinterpret(0x3FF0800000000000), 0, reinterpret(0xBF9F829B0E780000), reinterpret(0xBD2980267C7E09E4),\n reinterpret(0x3FF0800000000000), 0, reinterpret(0xBF9F829B0E780000), reinterpret(0xBD2980267C7E09E4),\n reinterpret(0x3FF0600000000000), 0, reinterpret(0xBF97B91B07D58000), reinterpret(0xBD288D5493FAA639),\n reinterpret(0x3FF0400000000000), 0, reinterpret(0xBF8FC0A8B0FC0000), reinterpret(0xBCDF1E7CF6D3A69C),\n reinterpret(0x3FF0400000000000), 0, reinterpret(0xBF8FC0A8B0FC0000), reinterpret(0xBCDF1E7CF6D3A69C),\n reinterpret(0x3FF0200000000000), 0, reinterpret(0xBF7FE02A6B100000), reinterpret(0xBD19E23F0DDA40E4),\n reinterpret(0x3FF0200000000000), 0, reinterpret(0xBF7FE02A6B100000), reinterpret(0xBD19E23F0DDA40E4),\n reinterpret(0x3FF0000000000000), 0, 0, 0,\n reinterpret(0x3FF0000000000000), 0, 0, 0,\n reinterpret(0x3FEFC00000000000), 0, reinterpret(0x3F80101575890000), reinterpret(0xBD10C76B999D2BE8),\n reinterpret(0x3FEF800000000000), 0, reinterpret(0x3F90205658938000), reinterpret(0xBD23DC5B06E2F7D2),\n reinterpret(0x3FEF400000000000), 0, reinterpret(0x3F98492528C90000), reinterpret(0xBD2AA0BA325A0C34),\n reinterpret(0x3FEF000000000000), 0, reinterpret(0x3FA0415D89E74000), reinterpret(0x3D0111C05CF1D753),\n reinterpret(0x3FEEC00000000000), 0, reinterpret(0x3FA466AED42E0000), reinterpret(0xBD2C167375BDFD28),\n reinterpret(0x3FEE800000000000), 0, reinterpret(0x3FA894AA149FC000), reinterpret(0xBD197995D05A267D),\n reinterpret(0x3FEE400000000000), 0, reinterpret(0x3FACCB73CDDDC000), reinterpret(0xBD1A68F247D82807),\n reinterpret(0x3FEE200000000000), 0, reinterpret(0x3FAEEA31C006C000), reinterpret(0xBD0E113E4FC93B7B),\n reinterpret(0x3FEDE00000000000), 0, reinterpret(0x3FB1973BD1466000), reinterpret(0xBD25325D560D9E9B),\n reinterpret(0x3FEDA00000000000), 0, reinterpret(0x3FB3BDF5A7D1E000), reinterpret(0x3D2CC85EA5DB4ED7),\n reinterpret(0x3FED600000000000), 0, reinterpret(0x3FB5E95A4D97A000), reinterpret(0xBD2C69063C5D1D1E),\n reinterpret(0x3FED400000000000), 0, reinterpret(0x3FB700D30AEAC000), reinterpret(0x3CEC1E8DA99DED32),\n reinterpret(0x3FED000000000000), 0, reinterpret(0x3FB9335E5D594000), reinterpret(0x3D23115C3ABD47DA),\n reinterpret(0x3FECC00000000000), 0, reinterpret(0x3FBB6AC88DAD6000), reinterpret(0xBD1390802BF768E5),\n reinterpret(0x3FECA00000000000), 0, reinterpret(0x3FBC885801BC4000), reinterpret(0x3D2646D1C65AACD3),\n reinterpret(0x3FEC600000000000), 0, reinterpret(0x3FBEC739830A2000), reinterpret(0xBD2DC068AFE645E0),\n reinterpret(0x3FEC400000000000), 0, reinterpret(0x3FBFE89139DBE000), reinterpret(0xBD2534D64FA10AFD),\n reinterpret(0x3FEC000000000000), 0, reinterpret(0x3FC1178E8227E000), reinterpret(0x3D21EF78CE2D07F2),\n reinterpret(0x3FEBE00000000000), 0, reinterpret(0x3FC1AA2B7E23F000), reinterpret(0x3D2CA78E44389934),\n reinterpret(0x3FEBA00000000000), 0, reinterpret(0x3FC2D1610C868000), reinterpret(0x3D039D6CCB81B4A1),\n reinterpret(0x3FEB800000000000), 0, reinterpret(0x3FC365FCB0159000), reinterpret(0x3CC62FA8234B7289),\n reinterpret(0x3FEB400000000000), 0, reinterpret(0x3FC4913D8333B000), reinterpret(0x3D25837954FDB678),\n reinterpret(0x3FEB200000000000), 0, reinterpret(0x3FC527E5E4A1B000), reinterpret(0x3D2633E8E5697DC7),\n reinterpret(0x3FEAE00000000000), 0, reinterpret(0x3FC6574EBE8C1000), reinterpret(0x3D19CF8B2C3C2E78),\n reinterpret(0x3FEAC00000000000), 0, reinterpret(0x3FC6F0128B757000), reinterpret(0xBD25118DE59C21E1),\n reinterpret(0x3FEAA00000000000), 0, reinterpret(0x3FC7898D85445000), reinterpret(0xBD1C661070914305),\n reinterpret(0x3FEA600000000000), 0, reinterpret(0x3FC8BEAFEB390000), reinterpret(0xBD073D54AAE92CD1),\n reinterpret(0x3FEA400000000000), 0, reinterpret(0x3FC95A5ADCF70000), reinterpret(0x3D07F22858A0FF6F),\n reinterpret(0x3FEA000000000000), 0, reinterpret(0x3FCA93ED3C8AE000), reinterpret(0xBD28724350562169),\n reinterpret(0x3FE9E00000000000), 0, reinterpret(0x3FCB31D8575BD000), reinterpret(0xBD0C358D4EACE1AA),\n reinterpret(0x3FE9C00000000000), 0, reinterpret(0x3FCBD087383BE000), reinterpret(0xBD2D4BC4595412B6),\n reinterpret(0x3FE9A00000000000), 0, reinterpret(0x3FCC6FFBC6F01000), reinterpret(0xBCF1EC72C5962BD2),\n reinterpret(0x3FE9600000000000), 0, reinterpret(0x3FCDB13DB0D49000), reinterpret(0xBD2AFF2AF715B035),\n reinterpret(0x3FE9400000000000), 0, reinterpret(0x3FCE530EFFE71000), reinterpret(0x3CC212276041F430),\n reinterpret(0x3FE9200000000000), 0, reinterpret(0x3FCEF5ADE4DD0000), reinterpret(0xBCCA211565BB8E11),\n reinterpret(0x3FE9000000000000), 0, reinterpret(0x3FCF991C6CB3B000), reinterpret(0x3D1BCBECCA0CDF30),\n reinterpret(0x3FE8C00000000000), 0, reinterpret(0x3FD07138604D5800), reinterpret(0x3CF89CDB16ED4E91),\n reinterpret(0x3FE8A00000000000), 0, reinterpret(0x3FD0C42D67616000), reinterpret(0x3D27188B163CEAE9),\n reinterpret(0x3FE8800000000000), 0, reinterpret(0x3FD1178E8227E800), reinterpret(0xBD2C210E63A5F01C),\n reinterpret(0x3FE8600000000000), 0, reinterpret(0x3FD16B5CCBACF800), reinterpret(0x3D2B9ACDF7A51681),\n reinterpret(0x3FE8400000000000), 0, reinterpret(0x3FD1BF99635A6800), reinterpret(0x3D2CA6ED5147BDB7),\n reinterpret(0x3FE8200000000000), 0, reinterpret(0x3FD214456D0EB800), reinterpret(0x3D0A87DEBA46BAEA),\n reinterpret(0x3FE7E00000000000), 0, reinterpret(0x3FD2BEF07CDC9000), reinterpret(0x3D2A9CFA4A5004F4),\n reinterpret(0x3FE7C00000000000), 0, reinterpret(0x3FD314F1E1D36000), reinterpret(0xBD28E27AD3213CB8),\n reinterpret(0x3FE7A00000000000), 0, reinterpret(0x3FD36B6776BE1000), reinterpret(0x3D116ECDB0F177C8),\n reinterpret(0x3FE7800000000000), 0, reinterpret(0x3FD3C25277333000), reinterpret(0x3D183B54B606BD5C),\n reinterpret(0x3FE7600000000000), 0, reinterpret(0x3FD419B423D5E800), reinterpret(0x3D08E436EC90E09D),\n reinterpret(0x3FE7400000000000), 0, reinterpret(0x3FD4718DC271C800), reinterpret(0xBD2F27CE0967D675),\n reinterpret(0x3FE7200000000000), 0, reinterpret(0x3FD4C9E09E173000), reinterpret(0xBD2E20891B0AD8A4),\n reinterpret(0x3FE7000000000000), 0, reinterpret(0x3FD522AE0738A000), reinterpret(0x3D2EBE708164C759),\n reinterpret(0x3FE6E00000000000), 0, reinterpret(0x3FD57BF753C8D000), reinterpret(0x3D1FADEDEE5D40EF),\n reinterpret(0x3FE6C00000000000), 0, reinterpret(0x3FD5D5BDDF596000), reinterpret(0xBD0A0B2A08A465DC)\n]);\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkint(iy: u64): i32 {\n var e = iy >> 52 & 0x7FF;\n if (e < 0x3FF ) return 0;\n if (e > 0x3FF + 52) return 2;\n e = u64(1) << (0x3FF + 52 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflow(sign: u32, y: f64): f64 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflow(sign: u32): f64 {\n return xflow(sign, reinterpret(0x1000000000000000)); // 0x1p-767\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflow(sign: u32): f64 {\n return xflow(sign, reinterpret(0x7000000000000000)); // 0x1p769\n}\n\n// Returns 1 if input is the bit representation of 0, infinity or nan.\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnan(u: u64): bool {\n return (u << 1) - 1 >= 0xFFE0000000000000 - 1;\n}\n\n// @ts-ignore: decorator\n@lazy var log_tail: f64 = 0;\n\n// Compute y+TAIL = log(x) where the rounded result is y and TAIL has about\n// additional 15 bits precision. IX is the bit representation of x, but\n// normalized in the subnormal range using the sign bit for the exponent.\n// @ts-ignore: decorator\n@inline\nfunction log_inline(ix: u64): f64 {\n const N = 1 << POW_LOG_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n Ln2hi = reinterpret(0x3FE62E42FEFA3800),\n Ln2lo = reinterpret(0x3D2EF35793C76730);\n\n const\n A0 = reinterpret(0xBFE0000000000000),\n A1 = reinterpret(0xBFE5555555555560),\n A2 = reinterpret(0x3FE0000000000006),\n A3 = reinterpret(0x3FE999999959554E),\n A4 = reinterpret(0xBFE555555529A47A),\n A5 = reinterpret(0xBFF2495B9B4845E9),\n A6 = reinterpret(0x3FF0002B8B263FC3);\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n var tmp = ix - 0x3fE6955500000000;\n var i = usize((tmp >> (52 - POW_LOG_TABLE_BITS)) & N_MASK);\n var k = tmp >> 52;\n var iz = ix - (tmp & u64(0xFFF) << 52);\n var z = reinterpret(iz);\n var kd = k;\n\n // log(x) = k*Ln2 + log(c) + log1p(z/c-1).\n var invc = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 0 << alignof()); // tab[i].invc\n var logc = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 2 << alignof()); // tab[i].logc\n var logctail = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 3 << alignof()); // tab[i].logctail\n\n // Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and\n // |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible.\n // Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|.\n var zhi = reinterpret((iz + u64(0x80000000)) & 0xFFFFFFFF00000000);\n var zlo = z - zhi;\n var rhi = zhi * invc - 1.0;\n var rlo = zlo * invc;\n var r = rhi + rlo;\n\n // k * Ln2 + log(c) + r.\n var t1 = kd * Ln2hi + logc;\n var t2 = t1 + r;\n var lo1 = kd * Ln2lo + logctail;\n var lo2 = t1 - t2 + r;\n\n // Evaluation is optimized assuming superscalar pipelined execution.\n var ar = A0 * r; // A[0] = -0.5\n var ar2 = r * ar;\n var ar3 = r * ar2;\n // k * Ln2 + log(c) + r + A[0] * r * r.\n var arhi = A0 * rhi;\n var arhi2 = rhi * arhi;\n var hi = t2 + arhi2;\n var lo3 = rlo * (ar + arhi);\n var lo4 = t2 - hi + arhi2;\n\n // p = log1p(r) - r - A[0] * r * r.\n var p = ar3 * (A1 + r * A2 + ar2 * (A3 + r * A4 + ar2 * (A5 + r * A6)));\n var lo = lo1 + lo2 + lo3 + lo4 + p;\n var y = hi + lo;\n log_tail = hi - y + lo;\n\n return y;\n}\n\n// @ts-ignore: decorator\n@inline const SIGN_BIAS = 0x800 << EXP_TABLE_BITS;\n\n// Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.\n// The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1.\n// @ts-ignore: decorator\n@inline\nfunction exp_inline(x: f64, xtail: f64, sign_bias: u32): f64 {\n const N = 1 << EXP_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret(0x4338000000000000); // 0x1.8p52\n\n const\n C2 = reinterpret(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n var abstop: u32;\n var ki: u64, top: u64, sbits: u64;\n var idx: usize;\n // double_t for better performance on targets with FLT_EVAL_METHOD==2.\n var kd: f64, z: f64, r: f64, r2: f64, scale: f64, tail: f64, tmp: f64;\n\n var ux = reinterpret(x);\n abstop = u32(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) {\n // Avoid spurious underflow for tiny x.\n // Note: 0 is common input.\n return select(-1.0, 1.0, sign_bias);\n }\n if (abstop >= 0x409) { // top12(1024.0)\n // Note: inf and nan are already handled.\n return ux < 0\n ? uflow(sign_bias)\n : oflow(sign_bias);\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].\n z = InvLn2N * x;\n\n // #if TOINT_INTRINSICS\n // kd = roundtoint(z);\n // ki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // // z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // kd = eval_as_double(z + shift);\n // ki = asuint64(kd) >> 16;\n // kd = (double_t)(int32_t)ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes\n kd = z + shift;\n ki = reinterpret(kd);\n kd -= shift;\n // #endif\n r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // The code assumes 2^-200 < |xtail| < 2^-8/N\n r += xtail;\n // 2^(k/N) ~= scale * (1 + tail)\n idx = usize((ki & N_MASK) << 1);\n top = (ki + sign_bias) << (52 - EXP_TABLE_BITS);\n\n tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof())));\n // This is only a valid scale when -1023*N < k < 1024*N\n sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top;\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp\n tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function pow_lut(x: f64, y: f64): f64 {\n const Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n var sign_bias: u32 = 0;\n var ix = reinterpret(x);\n var iy = reinterpret(y);\n var topx = ix >> 52;\n var topy = iy >> 52;\n\n if (topx - 0x001 >= 0x7FF - 0x001 || (topy & 0x7FF) - 0x3BE >= 0x43e - 0x3BE) {\n // Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0\n // and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1.\n // Special cases: (x < 0x1p-126 or inf or nan) or\n // (|y| < 0x1p-65 or |y| >= 0x1p63 or nan).\n if (zeroinfnan(iy)) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3FF0000000000000) return NaN; // original: 1.0\n if ((ix << 1) > 0xFFE0000000000000 || (iy << 1) > 0xFFE0000000000000) return x + y;\n if ((ix << 1) == 0x7FE0000000000000) return NaN; // original: 1.0\n if (((ix << 1) < 0x7FE0000000000000) == !(iy >> 63)) return 0; // |x|<1 && y==inf or |x|>1 && y==-inf.\n return y * y;\n }\n if (zeroinfnan(ix)) {\n let x2 = x * x;\n if (i32(ix >> 63) && checkint(iy) == 1) x2 = -x2;\n return iy < 0 ? 1 / x2 : x2;\n }\n // Here x and y are non-zero finite\n if (ix < 0) {\n // Finite x < 0\n let yint = checkint(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) sign_bias = SIGN_BIAS;\n ix &= 0x7FFFFFFFFFFFFFFF;\n topx &= 0x7FF;\n }\n if ((topy & 0x7FF) - 0x3BE >= 0x43E - 0x3BE) {\n // Note: sign_bias == 0 here because y is not odd.\n if (ix == 0x3FF0000000000000) return 1;\n if ((topy & 0x7FF) < 0x3BE) return 1; // |y| < 2^-65, x^y ~= 1 + y*log(x).\n return (ix > 0x3FF0000000000000) == (topy < 0x800) ? Infinity : 0;\n }\n if (topx == 0) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret(x * Ox1p52);\n ix &= 0x7FFFFFFFFFFFFFFF;\n ix -= u64(52) << 52;\n }\n }\n\n var hi = log_inline(ix);\n var lo = log_tail;\n var ehi: f64, elo: f64;\n // #if __FP_FAST_FMA\n // ehi = y * hi;\n // elo = y * lo + __builtin_fma(y, hi, -ehi);\n // #else\n var yhi = reinterpret(iy & 0xFFFFFFFFF8000000);\n var ylo = y - yhi;\n var lhi = reinterpret(reinterpret(hi) & 0xFFFFFFFFF8000000);\n var llo = hi - lhi + lo;\n ehi = yhi * lhi;\n elo = ylo * lhi + y * llo; // |elo| < |ehi| * 2^-25.\n // #endif\n return exp_inline(ehi, elo, sign_bias);\n}\n","/// \n\nimport { idof } from \"../builtins\";\nimport { CharCode } from \"./string\";\n\n// @ts-ignore: decorator\n@inline\nexport const MAX_DOUBLE_LENGTH = 28;\n\n// @ts-ignore: decorator\n@lazy @inline const POWERS10 = memory.data([\n 1,\n 10,\n 100,\n 1000,\n 10000,\n 100000,\n 1000000,\n 10000000,\n 100000000,\n 1000000000\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// @ts-ignore: decorator\n@lazy @inline const DIGITS = memory.data([\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\n// Lookup table for pairwise char codes in range [0x00-0xFF]\n// @ts-ignore: decorator\n@lazy @inline const HEX_DIGITS =\n\"000102030405060708090a0b0c0d0e0f\\\n101112131415161718191a1b1c1d1e1f\\\n202122232425262728292a2b2c2d2e2f\\\n303132333435363738393a3b3c3d3e3f\\\n404142434445464748494a4b4c4d4e4f\\\n505152535455565758595a5b5c5d5e5f\\\n606162636465666768696a6b6c6d6e6f\\\n707172737475767778797a7b7c7d7e7f\\\n808182838485868788898a8b8c8d8e8f\\\n909192939495969798999a9b9c9d9e9f\\\na0a1a2a3a4a5a6a7a8a9aaabacadaeaf\\\nb0b1b2b3b4b5b6b7b8b9babbbcbdbebf\\\nc0c1c2c3c4c5c6c7c8c9cacbcccdcecf\\\nd0d1d2d3d4d5d6d7d8d9dadbdcdddedf\\\ne0e1e2e3e4e5e6e7e8e9eaebecedeeef\\\nf0f1f2f3f4f5f6f7f8f9fafbfcfdfeff\";\n\n// @ts-ignore: decorator\n@lazy @inline const ANY_DIGITS = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n\n// @ts-ignore: decorator\n@lazy @inline const EXP_POWERS = memory.data([/* eslint-disable indent */\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/* eslint-enable indent */]);\n\n// 1e-348, 1e-340, ..., 1e340\n// @ts-ignore: decorator\n@lazy @inline const FRC_POWERS = memory.data([\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\n// @ts-ignore: decorator\n@inline\nexport function isPowerOf2(value: T): bool {\n return popcnt(value) == 1;\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 (value < 100000) {\n if (value < 100) {\n return 1 + u32(value >= 10);\n } else {\n return 3 + u32(value >= 10000) + u32(value >= 1000);\n }\n } else {\n if (value < 10000000) {\n return 6 + u32(value >= 1000000);\n } else {\n return 8 + u32(value >= 1000000000) + u32(value >= 100000000);\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 decimalCount64High(value: u64): u32 {\n if (value < 1000000000000000) {\n if (value < 1000000000000) {\n return 10 + u32(value >= 100000000000) + u32(value >= 10000000000);\n } else {\n return 13 + u32(value >= 100000000000000) + u32(value >= 10000000000000);\n }\n } else {\n if (value < 100000000000000000) {\n return 16 + u32(value >= 10000000000000000);\n } else {\n return 18 + u32(value >= 10000000000000000000) + u32(value >= 1000000000000000000);\n }\n }\n}\n\nfunction ulog_base(num: u64, base: i32): u32 {\n if (isPowerOf2(base)) {\n return (63 - clz(num)) / (31 - clz(base)) + 1;\n }\n var b64 = u64(base), b = b64, e: u32 = 1;\n while (num >= b) {\n num /= b;\n b *= b;\n e <<= 1;\n }\n while (num >= 1) {\n num /= b64;\n e++;\n }\n return e - 1;\n}\n\nfunction utoa32_dec_lut(buffer: usize, num: u32, offset: usize): void {\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 = load(DIGITS + (d1 << alignof()));\n let digits2 = load(DIGITS + (d2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\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 = load(DIGITS + (d1 << alignof()));\n store(buffer + (offset << 1), digits);\n }\n\n if (num >= 10) {\n offset -= 2;\n let digits = load(DIGITS + (num << alignof()));\n store(buffer + (offset << 1), digits);\n } else {\n offset -= 1;\n let digit = CharCode._0 + num;\n store(buffer + (offset << 1), digit);\n }\n}\n\nfunction utoa64_dec_lut(buffer: usize, num: u64, offset: usize): void {\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 = load(DIGITS + (c1 << alignof()));\n let digits2 = load(DIGITS + (c2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n\n digits1 = load(DIGITS + (b1 << alignof()));\n digits2 = load(DIGITS + (b2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n }\n\n utoa32_dec_lut(buffer, num, offset);\n}\n\nfunction utoa_hex_lut(buffer: usize, num: u64, offset: usize): void {\n const lut = changetype(HEX_DIGITS);\n while (offset >= 2) {\n offset -= 2;\n store(\n buffer + (offset << 1),\n load(lut + ((num & 0xFF) << alignof()))\n );\n num >>= 8;\n }\n if (offset & 1) {\n store(buffer, load(lut + (num << 6)));\n }\n}\n\nfunction utoa_dec_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let t = num / 10;\n let r = (num % 10);\n num = changetype(t);\n offset--;\n store(buffer + (offset << 1), CharCode._0 + r);\n } while (num);\n}\n\nfunction utoa_hex_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let d = num & 0x0F | CharCode._0;\n d += select(0x27, 0, d > CharCode._9);\n offset--;\n store(buffer + (offset << 1), d);\n // @ts-ignore: type\n num >>= 4;\n } while (num);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function utoa32_dec_core(buffer: usize, num: u32, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_dec_simple(buffer, num, offset);\n } else {\n utoa32_dec_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa32_hex_core(buffer: usize, num: u32, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_hex_simple(buffer, num, offset);\n } else {\n utoa_hex_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa64_dec_core(buffer: usize, num: u64, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_dec_simple(buffer, num, offset);\n } else {\n utoa64_dec_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa64_hex_core(buffer: usize, num: u64, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_hex_simple(buffer, num, offset);\n } else {\n utoa_hex_lut(buffer, num, offset);\n }\n}\n\nfunction utoa64_any_core(buffer: usize, num: u64, offset: usize, radix: i32): void {\n const lut = changetype(ANY_DIGITS);\n var base = u64(radix);\n if ((radix & (radix - 1)) == 0) { // for radix which pow of two\n let shift = u64(ctz(radix) & 7);\n let mask = base - 1;\n do {\n offset--;\n store(buffer + (offset << 1), load(lut + (usize(num & mask) << 1)));\n num >>= shift;\n } while (num);\n } else {\n do {\n offset--;\n let q = num / base;\n store(buffer + (offset << 1), load(lut + (usize(num - q * base) << 1)));\n num = q;\n } while (num);\n }\n}\n\nexport function utoa32(value: u32, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n var out: String;\n\n if (radix == 10) {\n let decimals = decimalCount32(value);\n out = changetype(__new(decimals << 1, idof()));\n utoa32_dec_core(changetype(out), value, decimals);\n } else if (radix == 16) {\n let decimals = (31 - clz(value) >> 2) + 1;\n out = changetype(__new(decimals << 1, idof()));\n utoa32_hex_core(changetype(out), value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_any_core(changetype(out), value, decimals, radix);\n }\n return out;\n}\n\nexport function itoa32(value: i32, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n\n var sign = (value >>> 31) << 1;\n if (sign) value = -value;\n var out: String;\n\n if (radix == 10) {\n let decimals = decimalCount32(value);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_dec_core(changetype(out) + sign, value, decimals);\n } else if (radix == 16) {\n let decimals = (31 - clz(value) >> 2) + 1;\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_hex_core(changetype(out) + sign, value, decimals);\n } else {\n let val32 = u32(value);\n let decimals = ulog_base(val32, radix);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_any_core(changetype(out) + sign, val32, decimals, radix);\n }\n if (sign) store(changetype(out), CharCode.MINUS);\n return out;\n}\n\nexport function utoa64(value: u64, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n var out: String;\n\n if (radix == 10) {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n out = changetype(__new(decimals << 1, idof()));\n utoa32_dec_core(changetype(out), val32, decimals);\n } else {\n let decimals = decimalCount64High(value);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_dec_core(changetype(out), value, decimals);\n }\n } else if (radix == 16) {\n let decimals = (63 - u32(clz(value)) >> 2) + 1;\n out = changetype(__new(decimals << 1, idof()));\n utoa64_hex_core(changetype(out), value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_any_core(changetype(out), value, decimals, radix);\n }\n return out;\n}\n\nexport function itoa64(value: i64, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n\n var sign = u32(value >>> 63) << 1;\n if (sign) value = -value;\n var out: String;\n\n if (radix == 10) {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_dec_core(changetype(out) + sign, val32, decimals);\n } else {\n let decimals = decimalCount64High(value);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_dec_core(changetype(out) + sign, value, decimals);\n }\n } else if (radix == 16) {\n let decimals = (63 - u32(clz(value)) >> 2) + 1;\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_hex_core(changetype(out) + sign, value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_any_core(changetype(out) + sign, value, decimals, radix);\n }\n if (sign) store(changetype(out), CharCode.MINUS);\n return out;\n}\n\n// @ts-ignore: decorator\n@lazy var _K: i32 = 0;\n\n// // @ts-ignore: decorator\n// @lazy\n// var _frc: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy var _exp: i32 = 0;\n\n// @ts-ignore: decorator\n@lazy var _frc_minus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy var _frc_plus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy var _frc_pow: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy var _exp_pow: i32 = 0;\n\n// @ts-ignore: decorator\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// @ts-ignore: decorator\n@inline\nfunction umul64e(e1: i32, e2: i32): i32 {\n return e1 + e2 + 64; // where 64 is significand size\n}\n\n// @ts-ignore: decorator\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 + i32(f == 0x0010000000000000);\n\n _frc_plus = frc;\n _frc_minus = ((f << m) - 1) << e - m - exp;\n _exp = exp;\n}\n\n// @ts-ignore: decorator\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);\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);\n}\n\n// @ts-ignore: decorator\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 += i32(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 _frc_pow = load(FRC_POWERS + (index << alignof()));\n _exp_pow = load(EXP_POWERS + (index << alignof()));\n}\n\n// @ts-ignore: decorator\n@inline\nfunction grisu2(value: f64, buffer: usize, sign: i32): i32 {\n\n // frexp routine\n var uv = reinterpret(value);\n var exp = i32((uv & 0x7FF0000000000000) >>> 52);\n var sid = uv & 0x000FFFFFFFFFFFFF;\n var frc = (u64(exp != 0) << 52) + sid;\n exp = select(exp, 1, exp) - (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\n var p1 = u32(mp_frc >> one_exp);\n var p2 = mp_frc & mask;\n\n var kappa = decimalCount32(p1);\n var len = sign;\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);\n\n --kappa;\n let tmp = ((p1) << one_exp) + p2;\n if (tmp <= delta) {\n _K += kappa;\n grisuRound(buffer, len, delta, tmp, load(POWERS10 + (kappa << alignof())) << one_exp, wp_w_frc);\n return len;\n }\n }\n\n while (true) {\n p2 *= 10;\n delta *= 10;\n\n let d = p2 >> one_exp;\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d);\n\n p2 &= mask;\n --kappa;\n if (p2 < delta) {\n _K += kappa;\n wp_w_frc *= load(POWERS10 + (-kappa << alignof()));\n grisuRound(buffer, len, delta, p2, one_frc, wp_w_frc);\n return len;\n }\n }\n}\n\n// @ts-ignore: decorator\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_dec_core(buffer, k, decimals);\n store(buffer, select(CharCode.MINUS, CharCode.PLUS, sign));\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));\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);\n }\n store(buffer + (kk << 1), CharCode.DOT | (CharCode._0 << 16));\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 + 2,\n ptr,\n -k << 1\n );\n store(buffer + (kk << 1), CharCode.DOT);\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 + (offset << 1),\n buffer,\n length << 1\n );\n store(buffer, CharCode._0 | (CharCode.DOT << 16));\n for (let i = 2; i < offset; ++i) {\n store(buffer + (i << 1), CharCode._0);\n }\n return length + offset;\n } else if (length == 1) {\n // 1e30\n store(buffer, CharCode.e, 2);\n length = genExponent(buffer + 4, kk - 1);\n return length + 2;\n } else {\n let len = length << 1;\n memory.copy(\n buffer + 4,\n buffer + 2,\n len - 2\n );\n store(buffer, CharCode.DOT, 2);\n store(buffer + len, CharCode.e, 2);\n length += genExponent(buffer + len + 4, kk - 1);\n return length + 2;\n }\n}\n\nfunction dtoa_core(buffer: usize, value: f64): i32 {\n var sign = i32(value < 0);\n if (sign) {\n value = -value;\n store(buffer, CharCode.MINUS);\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\n// @ts-ignore: decorator\n@lazy @inline const dtoa_buf = memory.data(MAX_DOUBLE_LENGTH << 1);\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 size = dtoa_core(dtoa_buf, value) << 1;\n var result = changetype(__new(size, idof()));\n memory.copy(changetype(result), dtoa_buf, size);\n return result;\n}\n\nexport function itoa_buffered(buffer: usize, value: T): u32 {\n var sign: u32 = 0;\n if (isSigned()) {\n sign = u32(value < 0);\n if (sign) {\n if (sizeof() == 1) {\n if (value == -0x80) {\n // -0x80 -> -128\n store(buffer,\n CharCode.MINUS |\n (CharCode._0 + 1) << 16 |\n (CharCode._0 + 2) << 32 |\n (CharCode._0 + 8) << 48\n );\n return 4;\n }\n }\n if (sizeof() == 2) {\n if (value == -0x8000) {\n // -0x8000 -> -32768\n store(buffer,\n CharCode.MINUS |\n (CharCode._0 + 3) << 16 |\n (CharCode._0 + 2) << 32 |\n (CharCode._0 + 7) << 48\n ); // -327\n store(buffer + 8,\n (CharCode._0 + 6) << 0 |\n (CharCode._0 + 8) << 16\n ); // 68\n return 6;\n }\n }\n store(buffer, CharCode.MINUS);\n // @ts-ignore\n value = -value;\n }\n }\n var dest = buffer + (sign << 1);\n if (ASC_SHRINK_LEVEL <= 1) {\n if (isSigned()) {\n if (sizeof() <= 4) {\n if (value < 10) {\n store(dest, value | CharCode._0);\n return 1 + sign;\n }\n } else {\n if (value < 10) {\n store(dest, value | CharCode._0);\n return 1 + sign;\n }\n }\n } else {\n if (value < 10) {\n store(buffer, value | CharCode._0);\n return 1;\n }\n }\n }\n var decimals: u32 = 0;\n if (sizeof() <= 4) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_dec_core(dest, val32, decimals);\n } else {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_dec_core(dest, val32, decimals);\n } else {\n let val64 = value;\n decimals = decimalCount64High(val64);\n utoa64_dec_core(dest, val64, decimals);\n }\n }\n return sign + decimals;\n}\n\nexport function dtoa_buffered(buffer: usize, value: f64): u32 {\n if (value == 0) {\n store(buffer, CharCode._0);\n store(buffer, CharCode.DOT, 2);\n store(buffer, CharCode._0, 4);\n return 3;\n }\n if (!isFinite(value)) {\n if (isNaN(value)) {\n store(buffer, CharCode.N);\n store(buffer, CharCode.a, 2);\n store(buffer, CharCode.N, 4);\n return 3;\n } else {\n let sign = value < 0;\n if (sign) {\n store(buffer, CharCode.MINUS); // -\n buffer += 2;\n }\n store(buffer, 0x690066006E0049, 0); // ifnI\n store(buffer, 0x7900740069006E, 8); // ytin\n return 8 + u32(sign);\n }\n }\n return dtoa_core(buffer, value);\n}\n","import {\n itoa32,\n utoa32,\n itoa64,\n utoa64,\n dtoa,\n itoa_buffered,\n dtoa_buffered,\n MAX_DOUBLE_LENGTH\n} from \"./number\";\n\nimport {\n ipow32\n} from \"../math\";\n\n// All tables are stored as two staged lookup tables (static tries)\n// because the full range of Unicode symbols can't be efficiently\n// represented as-is in memory (see Unicode spec ch 5, p.196):\n// https://www.unicode.org/versions/Unicode12.0.0/ch05.pdf\n// Tables have been generated using these forked musl tools:\n// https://github.com/MaxGraey/musl-chartable-tools/tree/case-ignorable\n\n// Lookup table to check if a character is alphanumeric or not\n// See: https://git.musl-libc.org/cgit/musl/tree/src/ctype/alpha.h\n// size: 3904 bytes\n// @ts-ignore\n@inline @lazy const ALPHA_TABLE = memory.data([\n 18,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,17,34,35,36,17,37,38,39,40,\n 41,42,43,44,17,45,46,47,16,16,48,16,16,16,16,16,16,16,49,50,51,16,52,53,16,16,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,54,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,55,17,17,17,17,56,17,57,58,59,60,61,62,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67,\n 68,69,70,71,72,73,74,17,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,\n 93,94,16,95,96,97,98,17,17,17,99,100,101,16,16,16,16,16,16,16,16,16,16,17,17,\n 17,17,102,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,103,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,17,17,104,105,16,16,106,107,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,108,17,17,17,17,109,110,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 17,111,112,16,16,16,16,16,16,16,16,16,113,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,114,115,116,117,16,16,16,16,16,16,16,16,118,\n 119,120,16,16,16,16,16,121,122,16,16,16,16,123,16,16,124,16,16,16,16,16,16,16,\n 16,16,125,16,16,16,\n 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254,\n 255,255,7,0,0,0,0,0,4,32,4,255,255,127,255,255,255,127,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,188,64,215,255,255,\n 251,255,255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,3,252,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,254,255,255,255,127,2,255,255,255,\n 255,255,1,0,0,0,0,255,191,182,0,255,255,255,135,7,0,0,0,255,7,255,255,255,255,\n 255,255,255,254,255,195,255,255,255,255,255,255,255,255,255,255,255,255,239,\n 31,254,225,255,\n 159,0,0,255,255,255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255,\n 255,255,3,0,255,255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255,\n 1,255,7,0,0,0,0,0,0,255,255,223,255,255,0,240,255,248,3,255,255,255,255,255,\n 255,255,255,255,239,255,223,225,255,207,255,254,255,239,159,249,255,255,253,\n 197,227,159,89,128,176,207,255,3,16,238,135,249,255,255,253,109,195,135,25,2,\n 94,192,255,63,0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,30,238,\n 159,249,255,255,253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,\n 255,195,199,29,129,0,192,255,0,0,239,223,253,255,255,253,255,227,223,29,96,7,\n 207,255,0,0,239,223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,255,223,\n 253,255,255,255,255,231,223,93,240,128,207,255,0,252,238,255,127,252,255,255,\n 251,47,127,128,95,255,192,255,12,0,254,255,255,255,255,127,255,7,63,32,255,3,\n 0,0,0,0,214,247,255,255,175,255,255,59,95,32,255,243,0,0,0,\n 0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3,255,255,254,255,255,255,\n 31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249,255,3,255,255,255,255,255,\n 255,255,255,255,63,255,255,255,255,191,32,255,255,255,255,255,247,255,255,255,\n 255,255,255,255,255,255,61,127,61,255,255,255,255,255,61,255,255,255,255,61,\n 127,61,255,127,255,255,255,255,255,255,255,61,255,255,255,255,255,255,255,255,\n 7,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,63,63,254,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,159,255,255,254,255,255,7,255,255,255,255,255,255,255,255,\n 255,199,255,1,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255,\n 255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255,3,255,255,255,255,255,255,\n 255,255,255,255,255,1,255,255,255,255,255,7,255,255,255,255,255,255,255,255,\n 63,\n 0,255,255,255,127,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255,\n 255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255,\n 127,254,255,31,0,255,3,255,3,128,0,0,128,1,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255,\n 255,191,255,3,0,255,255,255,255,255,255,127,0,255,227,255,255,255,255,255,63,\n 255,1,255,255,255,255,255,231,0,0,0,0,0,222,111,4,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,\n 128,255,31,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,255,\n 255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243,\n 224,67,0,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,\n 0,255,255,255,255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255,\n 255,255,255,255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127,\n 255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,224,0,0,0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254,\n 255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,255,254,255,\n 255,255,255,255,255,255,255,255,255,127,0,0,255,255,255,255,0,0,0,0,0,0,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,\n 31,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255,\n 255,127,240,143,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,\n 0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,249,255,255,255,\n 255,255,255,252,7,0,0,0,0,224,255,191,255,255,255,255,0,0,0,255,255,255,255,\n 255,255,15,0,255,255,255,255,255,255,255,255,47,0,255,3,0,0,252,232,255,255,\n 255,255,255,7,255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247,\n 255,0,128,255,3,255,255,255,127,255,255,255,255,255,255,127,0,255,63,255,3,\n 255,255,127,252,255,255,255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126,\n 126,0,127,127,255,255,255,255,255,247,255,3,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255,255,\n 255,\n 15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127,95,219,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255,255,255,\n 252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,223,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,255,3,\n 254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255,255,127,\n 252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0,\n 0,255,255,255,255,0,224,255,255,255,7,255,255,255,255,255,7,255,255,255,63,\n 255,255,255,255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,255,3,255,255,255,255,15,255,255,255,\n 255,15,255,255,255,255,255,0,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,255,255,63,0,255,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191,145,255,255,63,0,255,255,\n 127,0,255,255,255,127,0,0,0,0,0,0,0,0,255,255,55,0,255,255,63,0,255,255,255,3,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240,239,\n 254,255,255,63,0,0,0,0,0,255,255,255,31,255,255,255,31,0,0,0,0,255,254,255,\n 255,31,0,0,0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,255,255,3,\n 0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,255,255,255,255,255,255,7,\n 0,255,255,255,255,255,255,7,0,255,255,255,255,255,0,255,3,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 255,27,3,0,0,0,0,0,0,0,0,0,255,255,255,31,128,0,255,255,63,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,31,0,0,0,255,255,127,0,255,255,255,255,255,255,255,255,63,0,0,\n 0,192,255,0,0,252,255,255,255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,\n 255,255,255,255,199,255,240,0,255,255,255,255,71,0,255,255,255,255,255,255,\n 255,255,30,192,255,23,0,0,0,0,255,255,251,255,255,255,159,64,0,0,0,0,0,0,0,0,\n 127,189,255,191,255,1,255,255,255,255,255,255,255,1,255,3,239,159,249,255,255,\n 253,237,227,159,25,129,224,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,187,7,255,131,3,0,0,0,255,255,255,255,255,\n 255,255,255,179,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 255,255,255,63,127,0,0,0,63,0,0,0,0,255,255,255,255,255,255,255,127,17,0,255,\n 3,0,0,0,0,255,255,255,255,255,255,63,1,255,3,0,0,0,0,0,0,255,255,255,231,255,\n 7,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,3,0,128,\n 127,242,111,255,255,255,191,153,7,0,255,3,0,0,0,0,0,0,0,0,255,252,255,255,255,\n 255,255,252,26,0,0,0,255,255,255,255,255,255,231,127,0,0,255,255,255,255,255,\n 255,255,255,255,32,0,0,0,0,255,255,255,255,255,255,255,1,255,253,255,255,255,\n 255,127,127,1,0,255,3,0,0,252,255,255,255,252,255,255,254,127,0,0,0,0,0,0,0,0,\n 0,127,251,255,255,255,255,127,180,203,0,255,3,191,253,255,255,255,127,123,1,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,127,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,\n 0,255,255,255,255,255,255,255,1,255,255,255,127,255,3,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,63,0,0,255,255,255,255,255,255,0,0,15,0,255,3,248,255,255,224,255,\n 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,\n 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,135,\n 255,255,255,255,255,255,255,128,255,255,0,0,0,0,0,0,0,0,11,0,3,0,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,0,0,\n 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 127,0,0,0,0,0,0,7,0,240,0,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,7,255,31,255,1,255,67,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,255,\n 223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,\n 255,123,95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,63,255,255,255,253,255,255,247,255,255,255,\n 247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,255,253,\n 255,255,255,253,255,255,247,207,255,255,255,255,255,255,127,255,255,249,219,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,31,\n 128,63,255,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,15,255,\n 3,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,31,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,143,8,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,239,255,255,255,150,254,247,10,\n 132,234,150,170,150,247,247,94,255,251,255,15,238,251,255,15,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,3\n]);\n\n// size: 1568 bytes (compressed to ~1380 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline const CASED = memory.data([\n 18,19,20,21,22,23,16,16,16,16,16,16,16,16,16,16,\n 24,16,16,25,16,16,16,16,16,16,16,16,26,27,17,28,\n 29,30,16,16,31,16,16,16,16,16,16,16,32,33,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,34,35,16,16,16,36,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,37,16,16,16,38,\n 16,16,16,16,39,16,16,16,16,16,16,16,40,16,16,16,\n 16,16,16,16,16,16,16,16,41,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,42,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,43,44,45,46,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,47,16,16,16,16,16,16,\n 16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,254,255,255,7,254,255,255,7,0,0,0,0,0,4,32,4,\n 255,255,127,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,247,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,239,255,255,255,255,1,3,0,0,0,31,0,0,0,\n 0,0,0,0,0,0,0,0,32,0,0,0,0,0,207,188,64,215,255,255,251,255,255,255,\n 255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 3,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,255,\n 255,255,127,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 191,32,255,255,255,255,255,231,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,255,255,255,255,255,255,63,63,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,1,255,255,255,255,255,231,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,\n 255,255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,\n 132,252,47,62,80,189,31,242,224,67,0,0,255,255,255,255,24,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,0,255,255,255,255,255,127,255,255,\n 255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,120,12,0,\n 255,255,255,255,191,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,63,0,0,\n 255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,255,255,\n 255,255,255,255,255,255,255,255,255,120,255,255,255,255,255,255,252,7,0,0,0,0,96,7,\n 0,0,0,0,0,0,255,255,255,255,255,247,255,1,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,127,0,248,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,7,\n 254,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,15,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,7,0,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,\n 255,255,255,223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,255,123,\n 95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,\n 253,255,255,247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,\n 255,253,255,255,255,253,255,255,247,15,0,0,0,0,0,0,255,255,255,255,255,255,255,255,\n 15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0\n]);\n\n// size: 2976 bytes (compressed to ~2050 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline const CASE_IGNORABLES = memory.data([\n 18,16,19,20,21,22,23,24,25,26,27,28,29,30,31,32,\n 33,16,16,34,16,16,16,35,36,37,38,39,40,41,16,42,\n 43,16,16,16,16,16,16,16,16,16,16,16,44,45,46,16,\n 47,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 48,16,16,16,49,16,50,51,52,53,54,55,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,56,16,16,57,58,\n 16,59,60,61,16,16,16,16,16,16,62,16,16,63,64,65,\n 66,67,68,69,70,71,72,73,74,75,76,16,77,78,79,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,80,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,81,82,16,16,16,83,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,84,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,85,86,16,16,16,16,16,16,16,87,16,16,16,16,16,\n 88,89,90,16,16,16,16,16,91,92,16,16,16,16,16,16,\n 16,16,16,93,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,128,64,0,4,0,0,0,64,1,0,0,0,0,0,0,0,0,161,144,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,48,4,176,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,130,0,0,0,0,\n 0,0,254,255,255,255,255,191,182,0,0,0,0,0,16,0,63,0,255,23,0,0,0,0,\n 1,248,255,255,0,0,1,0,0,0,0,0,0,0,0,0,0,0,192,191,255,61,0,0,\n 0,128,2,0,0,0,255,255,255,7,0,0,0,0,0,0,0,0,0,0,192,255,1,0,\n 0,0,0,0,0,248,63,36,0,0,192,255,255,63,0,0,0,0,0,14,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,248,255,255,255,255,255,7,0,0,0,0,0,0,20,\n 254,33,254,0,12,0,2,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0,64,\n 6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,\n 190,33,0,0,12,0,0,252,2,0,0,0,0,0,0,144,30,32,96,0,12,0,0,0,\n 4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,17,0,0,0,0,0,0,192,\n 193,61,96,0,12,0,0,0,2,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,\n 3,0,0,0,0,0,0,24,30,32,0,0,12,0,0,0,2,0,0,0,0,0,0,0,\n 0,4,92,0,0,0,0,0,0,0,0,0,0,0,242,7,192,127,0,0,0,0,0,0,\n 0,0,0,0,0,0,242,31,64,63,0,0,0,0,0,0,0,0,0,3,0,0,160,2,\n 0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,\n 0,0,0,0,0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,\n 0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,28,0,\n 0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,143,32,0,0,0,0,\n 0,120,0,0,0,0,0,0,8,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,\n 0,0,64,127,229,31,248,159,0,0,0,0,128,0,255,255,1,0,0,0,0,0,0,0,\n 15,0,0,0,0,0,208,23,4,0,0,0,0,248,15,0,3,0,0,0,60,59,0,0,\n 0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,0,0,0,63,\n 0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,240,255,255,\n 255,255,255,255,255,7,0,1,0,0,0,248,255,255,255,255,255,255,255,255,255,255,255,251,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,\n 3,224,0,224,0,224,0,96,0,248,0,3,144,124,0,0,0,0,0,0,223,255,2,128,\n 0,0,255,31,0,0,0,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,48,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,128,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,60,62,8,\n 0,0,0,0,0,0,0,0,0,0,0,126,0,0,0,0,0,0,0,0,0,0,0,112,\n 0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63,0,16,0,0,0,0,0,0,\n 0,0,0,0,0,128,247,191,0,0,0,240,0,0,0,0,0,0,0,0,0,0,3,0,\n 255,255,255,255,3,0,0,0,0,0,0,0,0,0,1,0,0,7,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,3,68,8,0,0,96,16,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,128,0,0,0,0,192,63,0,0,\n 128,255,3,0,0,0,0,0,7,0,0,0,0,0,200,51,0,128,0,0,96,0,0,0,\n 0,0,0,0,0,126,102,0,8,16,0,0,0,0,1,16,0,0,0,0,0,0,157,193,\n 2,0,0,32,0,48,88,0,0,0,0,0,0,0,0,0,0,0,0,248,0,14,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,\n 255,255,8,0,255,255,0,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,128,128,64,0,4,0,0,0,64,1,0,0,0,0,0,1,0,\n 0,0,0,192,0,0,0,0,0,0,0,0,8,0,0,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,110,240,0,0,0,0,0,135,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,\n 0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 192,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,\n 0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,\n 3,0,0,0,0,0,192,127,0,158,0,0,0,0,0,0,0,0,0,0,0,128,211,64,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,\n 3,0,0,0,0,0,0,24,1,0,0,0,192,31,31,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,\n 0,0,0,0,0,0,248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,\n 0,0,0,0,0,0,0,0,0,0,0,224,188,15,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,6,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,88,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,126,14,0,0,0,0,\n 0,252,127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,\n 0,0,0,0,0,0,0,0,0,0,252,255,255,252,109,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,126,180,191,0,0,0,0,0,0,0,0,0,163,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,255,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,15,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,128,0,0,0,0,0,0,0,128,255,255,0,0,0,0,0,0,0,0,27,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,\n 231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,\n 0,0,0,0,0,0,0,0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,63,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 240,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,248\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOWER127 = memory.data([\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 91,92,93,94,95,96,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 123,124,125,126,127\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const UPPER127 = memory.data([\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 91,92,93,94,95,96,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 123,124,125,126,127\n]);\n\n// 23 * 8 = 184 bytes\n// @ts-ignore: decorator\n@lazy @inline const POWERS10 = memory.data([\n 1e00, 1e01, 1e02, 1e03, 1e04, 1e05, 1e06, 1e07, 1e08, 1e09,\n 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,\n 1e20, 1e21, 1e22\n]);\n\n// @ts-ignore: decorator\n@inline\nexport const enum CharCode {\n PERCENT = 0x25,\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 I = 0x49,\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 u = 0x75,\n x = 0x78,\n z = 0x7A\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isAscii(c: u32): bool {\n return !(c >> 7);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isLower8(c: u32): bool {\n return c - CharCode.a < 26;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isUpper8(c: u32): bool {\n return c - CharCode.A < 26;\n}\n\nexport function isSpace(c: u32): bool {\n if (c < 0x1680) { // < (1)\n // , , , , , and \n // (c == 0x20 || c == 0xA0) was optimized to (c | 0x80) == 0xA0\n return ((c | 0x80) == 0xA0) || (c - 0x09 <= 0x0D - 0x09);\n }\n if (c - 0x2000 <= 0x200A - 0x2000) return true;\n switch (c) {\n case 0x1680: // (1)\n case 0x2028: // (2)\n case 0x2029: // \n case 0x202F: // \n case 0x205F: // \n case 0x3000: // \n case 0xFEFF: return true; // \n }\n return false;\n}\n\nexport function isAlpha(c: u32): bool {\n if (isAscii(c)) return (c | 32) - CharCode.a < 26;\n if (c < 0x20000) {\n // @ts-ignore: cast\n return stagedBinaryLookup(ALPHA_TABLE, c);\n }\n return c < 0x2FFFE;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCased(c: u32): bool {\n // @ts-ignore: cast\n return c < 0x1F18A && stagedBinaryLookup(CASED, c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCaseIgnorable(c: u32): bool {\n // @ts-ignore: cast\n return c < 0xE01F0 && stagedBinaryLookup(CASE_IGNORABLES, c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isFinalSigma(buffer: usize, index: isize, len: isize): bool {\n const lookaheadLimit = 30; // max lookahead limit\n var found = false;\n var pos = index;\n var minPos = max(0, pos - lookaheadLimit);\n while (pos > minPos) {\n let c = codePointBefore(buffer, pos);\n if (!isCaseIgnorable(c)) {\n if (isCased(c)) {\n found = true;\n } else {\n return false;\n }\n }\n pos -= isize(c >= 0x10000) + 1;\n }\n if (!found) return false;\n pos = index + 1;\n var maxPos = min(pos + lookaheadLimit, len);\n while (pos < maxPos) {\n let c = load(buffer + (pos << 1));\n if (u32((c & 0xFC00) == 0xD800) & u32(pos + 1 != len)) {\n let c1 = load(buffer + (pos << 1), 2);\n if ((c1 & 0xFC00) == 0xDC00) {\n c = (c - 0xD800 << 10) + (c1 - 0xDC00) + 0x10000;\n }\n }\n if (!isCaseIgnorable(c)) {\n return !isCased(c);\n }\n pos += isize(c >= 0x10000) + 1;\n }\n return true;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction codePointBefore(buffer: usize, index: isize): i32 {\n if (index <= 0) return -1;\n var c = load(buffer + (index - 1 << 1));\n if (u32((c & 0xFC00) == 0xDC00) & u32(index - 2 >= 0)) {\n let c1 = load(buffer + (index - 2 << 1));\n if ((c1 & 0xFC00) == 0xD800) {\n return ((c1 & 0x3FF) << 10) + (c & 0x3FF) + 0x10000;\n }\n }\n return (c & 0xF800) == 0xD800 ? 0xFFFD : c;\n}\n\n// Search routine for two-staged lookup tables\nfunction stagedBinaryLookup(table: usize, c: u32): bool {\n return ((load(table + (load(table + (c >>> 8)) << 5) + ((c & 255) >> 3)) >>> (c & 7)) & 1);\n}\n\nexport function compareImpl(str1: string, index1: usize, str2: string, index2: usize, len: usize): i32 {\n var ptr1 = changetype(str1) + (index1 << 1);\n var ptr2 = changetype(str2) + (index2 << 1);\n if (ASC_SHRINK_LEVEL < 2) {\n if (len >= 4 && !((ptr1 & 7) | (ptr2 & 7))) {\n do {\n if (load(ptr1) != load(ptr2)) break;\n ptr1 += 8;\n ptr2 += 8;\n len -= 4;\n } while (len >= 4);\n }\n }\n while (len--) {\n let a = load(ptr1);\n let b = load(ptr2);\n if (a != b) return a - b;\n ptr1 += 2;\n ptr2 += 2;\n }\n return 0;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toLower8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c | u32(isUpper8(c)) << 5;\n } else {\n return load(LOWER127 + c);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toUpper8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c & ~(u32(isLower8(c)) << 5);\n } else {\n return load(UPPER127 + c);\n }\n}\n\n/** Parses a string to an integer (usually), using the specified radix. */\nexport function strtol(str: string, radix: i32 = 0): T {\n var len = str.length;\n if (!len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n\n var ptr = changetype(str) /* + HEAD -> offset */;\n var code = load(ptr);\n\n // trim white spaces\n while (isSpace(code)) {\n code = load(ptr += 2);\n --len;\n }\n // determine sign\n // @ts-ignore\n var sign: T = 1;\n if (code == CharCode.MINUS || code == CharCode.PLUS) {\n if (!--len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n if (code == CharCode.MINUS) {\n // @ts-ignore: type\n sign = -1;\n }\n code = load(ptr += 2);\n }\n\n // See https://tc39.es/ecma262/#sec-parseint-string-radix\n if (radix) {\n if (radix < 2 || radix > 36) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n // handle case as parseInt(\"0xFF\", 16) by spec\n if (radix == 16) {\n if (\n len > 2 &&\n code == CharCode._0 &&\n (load(ptr, 2) | 32) == CharCode.x\n ) {\n ptr += 4; len -= 2;\n }\n }\n } else {\n // determine radix by literal prefix\n if (code == CharCode._0 && len > 2) {\n switch (load(ptr, 2) | 32) {\n case CharCode.b: {\n ptr += 4; len -= 2;\n radix = 2;\n break;\n }\n case CharCode.o: {\n ptr += 4; len -= 2;\n radix = 8;\n break;\n }\n case CharCode.x: {\n ptr += 4; len -= 2;\n radix = 16;\n break;\n }\n }\n }\n if (!radix) radix = 10;\n }\n\n // calculate value\n // @ts-ignore: type\n var num: T = 0;\n var initial = len - 1;\n while (len--) {\n code = load(ptr);\n if (code - CharCode._0 < 10) {\n code -= CharCode._0;\n } else if (code - CharCode.A <= (CharCode.Z - CharCode.A)) {\n code -= CharCode.A - 10;\n } else if (code - CharCode.a <= (CharCode.z - CharCode.a)) {\n code -= CharCode.a - 10;\n }\n if (code >= radix) {\n if (initial == len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n break;\n }\n // @ts-ignore: type\n num = num * radix + code;\n ptr += 2;\n }\n // @ts-ignore: type\n return sign * num;\n}\n\nexport function strtod(str: string): f64 {\n var len = str.length;\n if (!len) return NaN;\n\n var ptr = changetype(str);\n var code = load(ptr);\n\n var sign = 1.0;\n // skip white spaces\n while (len && isSpace(code)) {\n code = load(ptr += 2);\n --len;\n }\n if (!len) return NaN;\n\n // try parse '-' or '+'\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = load(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = load(ptr += 2);\n }\n\n // try parse Infinity\n if (len >= 8 && code == CharCode.I) {\n if (\n load(ptr, 0) == 0x690066006E0049 && // ifnI\n load(ptr, 8) == 0x7900740069006E // ytin\n ) {\n return Infinity * sign;\n }\n return NaN;\n }\n // validate next symbol\n if (code != CharCode.DOT && (code - CharCode._0) >= 10) {\n return NaN;\n }\n var savedPtr = ptr;\n // skip zeros\n while (code == CharCode._0) {\n code = load(ptr += 2);\n --len;\n }\n if (len <= 0) return 0;\n const capacity = 19; // int(64 * 0.3010)\n var pointed = false;\n var consumed = 0;\n var position = 0;\n var x: u64 = 0;\n if (code == CharCode.DOT) {\n let noDigits = !(savedPtr - ptr);\n ptr += 2; --len;\n if (!len && noDigits) return NaN;\n for (pointed = true; (code = load(ptr)) == CharCode._0; --position, ptr += 2) --len;\n if (len <= 0) return 0;\n if (!position && noDigits && code - CharCode._0 >= 10) return NaN;\n }\n for (let digit = code - CharCode._0; digit < 10 || (code == CharCode.DOT && !pointed); digit = code - CharCode._0) {\n if (digit < 10) {\n x = consumed < capacity ? 10 * x + digit : x | u64(!!digit);\n ++consumed;\n } else {\n position = consumed;\n pointed = true;\n }\n if (!--len) break;\n code = load(ptr += 2);\n }\n\n if (!pointed) position = consumed;\n return copysign(scientific(x, position - min(capacity, consumed) + parseExp(ptr, len)), sign);\n}\n\nexport function strtob(str: string): bool {\n var size: usize = str.length << 1;\n var offset: usize = 0;\n if (size > 8) {\n // try trim end whitespaces first\n while (size && isSpace(load(changetype(str) + size - 2))) size -= 2;\n if (size > 8) {\n // trim start whitespaces\n while (offset < size && isSpace(load(changetype(str) + offset))) offset += 2;\n size -= offset;\n }\n }\n if (size != 8) return false;\n // \"true\" represents as \\00\\e\\00\\u\\00\\e\\00\\t (00 65 00 75 00 72 00 74)\n return load(changetype(str) + offset) == 0x0065_0075_0072_0074;\n}\n\nexport function joinBooleanArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) return select(\"true\", \"false\", load(dataStart));\n\n var sepLen = separator.length;\n var valueLen = 5; // max possible length of element len(\"false\")\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype(__new(estLen << 1, idof()));\n var offset = 0;\n var value: bool;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + i);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + lastIndex);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinIntegerArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n let value = load(dataStart);\n if (isSigned()) {\n if (sizeof() <= 4) {\n // @ts-ignore: type\n return changetype(itoa32(value, 10));\n } else {\n // @ts-ignore: type\n return changetype(itoa64(value, 10));\n }\n } else {\n if (sizeof() <= 4) {\n // @ts-ignore: type\n return changetype(utoa32(value, 10));\n } else {\n // @ts-ignore: type\n return changetype(utoa64(value, 10));\n }\n }\n }\n\n var sepLen = separator.length;\n const valueLen = (sizeof() <= 4 ? 10 : 20) + i32(isSigned());\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype(__new(estLen << 1, idof()));\n var offset = 0;\n var value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n offset += itoa_buffered(changetype(result) + (offset << 1), value);\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n offset += itoa_buffered(changetype(result) + (offset << 1), value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinFloatArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n return changetype(dtoa(\n // @ts-ignore: type\n load(dataStart))\n );\n }\n\n const valueLen = MAX_DOUBLE_LENGTH;\n var sepLen = separator.length;\n var estLen = (valueLen + sepLen) * lastIndex + valueLen;\n var result = changetype(__new(estLen << 1, idof()));\n var offset = 0;\n var value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n offset += dtoa_buffered(changetype(result) + (offset << 1), value);\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n offset += dtoa_buffered(changetype(result) + (offset << 1), value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinStringArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n // @ts-ignore: type\n return load(dataStart) || \"\";\n }\n var estLen = 0;\n var value: string;\n for (let i = 0; i < length; ++i) {\n value = load(dataStart + (i << alignof()));\n if (changetype(value) != 0) estLen += value.length;\n }\n var offset = 0;\n var sepLen = separator.length;\n var result = changetype(__new((estLen + sepLen * lastIndex) << 1, idof()));\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n if (changetype(value) != 0) {\n let valueLen = value.length;\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(value),\n valueLen << 1\n );\n offset += valueLen;\n }\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n if (changetype(value) != 0) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(value),\n value.length << 1\n );\n }\n return result;\n}\n\nexport function joinReferenceArray(dataStart: usize, length: i32, separator: string): string {\n var lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n var value: T;\n if (!lastIndex) {\n value = load(dataStart);\n // @ts-ignore: type\n return value != null ? value.toString() : \"\";\n }\n var result = \"\";\n var sepLen = separator.length;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n if (value != null) result += value.toString();\n if (sepLen) result += separator;\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n if (value != null) result += value.toString();\n return result;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction scientific(significand: u64, exp: i32): f64 {\n if (!significand || exp < -342) return 0;\n if (exp > 308) return Infinity;\n // Try use fast path\n // Use fast path for string-to-double conversion if possible\n // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion\n // Simple integer\n var significandf = significand;\n if (!exp) return significandf;\n if (exp > 22 && exp <= 22 + 15) {\n significandf *= pow10(exp - 22);\n exp = 22;\n }\n if (significand <= 9007199254740991 && abs(exp) <= 22) {\n if (exp > 0) return significandf * pow10(exp);\n return significandf / pow10(-exp);\n } else if (exp < 0) {\n return scaledown(significand, exp);\n } else {\n return scaleup(significand, exp);\n }\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaledown(significand: u64, exp: i32): f64 {\n const denom: u64 = 6103515625; // 1e14 * 0x1p-14\n const scale = reinterpret(0x3F06849B86A12B9B); // 1e-14 * 0x1p32\n\n var shift = clz(significand);\n significand <<= shift;\n shift = exp - shift;\n\n for (; exp <= -14; exp += 14) {\n let q = significand / denom;\n let r = significand % denom;\n let s = clz(q);\n significand = (q << s) + nearest(scale * (r << (s - 18)));\n shift -= s;\n }\n var b = ipow32(5, -exp);\n var q = significand / b;\n var r = significand % b;\n var s = clz(q);\n significand = (q << s) + (reinterpret(reinterpret(r) + (s << 52)) / b);\n shift -= s;\n\n return NativeMath.scalbn(significand, shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaleup(significand: u64, exp: i32): f64 {\n const coeff: u32 = 1220703125; // 1e13 * 0x1p-13;\n var shift = ctz(significand);\n significand >>= shift;\n shift += exp;\n\n __fixmulShift = shift;\n for (; exp >= 13; exp -= 13) {\n significand = fixmul(significand, coeff);\n }\n significand = fixmul(significand, ipow32(5, exp));\n shift = __fixmulShift;\n return NativeMath.scalbn(significand, shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction parseExp(ptr: usize, len: i32): i32 {\n var sign = 1, magnitude = 0;\n var code = load(ptr);\n // check code is 'e' or 'E'\n if ((code | 32) != CharCode.e) return 0;\n\n if (!--len) return 0;\n code = load(ptr += 2);\n if (code == CharCode.MINUS) {\n if (!--len) return 0;\n code = load(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return 0;\n code = load(ptr += 2);\n }\n // skip zeros\n while (code == CharCode._0) {\n if (!--len) return 0;\n code = load(ptr += 2);\n }\n for (let digit: u32 = code - CharCode._0; len && digit < 10; digit = code - CharCode._0) {\n if (magnitude >= 3200) return sign * 3200;\n magnitude = 10 * magnitude + digit;\n code = load(ptr += 2);\n --len;\n }\n return sign * magnitude;\n}\n\n// @ts-ignore: decorator\n@lazy var __fixmulShift: u64 = 0;\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction fixmul(a: u64, b: u32): u64 {\n var low = (a & 0xFFFFFFFF) * b;\n var high = (a >> 32) * b + (low >> 32);\n var overflow = (high >> 32);\n var space = clz(overflow);\n var revspace: u64 = 32 - space;\n __fixmulShift += revspace;\n return (high << space | (low & 0xFFFFFFFF) >> revspace) + (low << space >> 31 & 1);\n}\n\n// @ts-ignore: decorator\n@inline\nfunction pow10(n: i32): f64 {\n // argument `n` should bounds in [0, 22] range\n return load(POWERS10 + (n << alignof()));\n}\n","import { Math as JSMath } from \"./bindings/dom\";\nexport { JSMath };\n\nimport {\n pow_lut, exp_lut, exp2_lut, log_lut, log2_lut,\n powf_lut, expf_lut, exp2f_lut, logf_lut, log2f_lut\n} from \"./util/math\";\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/** @internal */\n// @ts-ignore: decorator\n@lazy var rempio2_y0: f64, rempio2_y1: f64, res128_hi: u64;\n\n/** @internal */\n// @ts-ignore: decorator\n@lazy @inline const PIO2_TABLE = memory.data([\n 0x00000000A2F9836E, 0x4E441529FC2757D1, 0xF534DDC0DB629599, 0x3C439041FE5163AB,\n 0xDEBBC561B7246E3A, 0x424DD2E006492EEA, 0x09D1921CFE1DEB1C, 0xB129A73EE88235F5,\n 0x2EBB4484E99C7026, 0xB45F7E413991D639, 0x835339F49C845F8B, 0xBDF9283B1FF897FF,\n 0xDE05980FEF2F118B, 0x5A0A6D1F6D367ECF, 0x27CB09B74F463F66, 0x9E5FEA2D7527BAC7,\n 0xEBE5F17B3D0739F7, 0x8A5292EA6BFB5FB1, 0x1F8D5D0856033046, 0xFC7B6BABF0CFBC20,\n 0x9AF4361DA9E39161, 0x5EE61B086599855F, 0x14A068408DFFD880, 0x4D73273106061557\n]);\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\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/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction expo2(x: f64, sign: 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 // in directed rounding correct sign before rounding or overflow is important\n return NativeMath.exp(x - kln2) * (sign * scale) * scale;\n}\n\n/** @internal */\n/* Helper function to eventually get bits of π/2 * |x|\n *\n * y = π/4 * (frac << clz(frac) >> 11)\n * return clz(frac)\n *\n * Right shift 11 bits to make upper half fit in `double`\n */\n// @ts-ignore: decorator\n@inline\nfunction pio2_right(q0: u64, q1: u64): u64 { // see: jdh8/metallic/blob/master/src/math/double/rem_pio2.c\n // Bits of π/4\n const p0: u64 = 0xC4C6628B80DC1CD1;\n const p1: u64 = 0xC90FDAA22168C234;\n\n const Ox1p_64 = reinterpret(0x3BF0000000000000); // 0x1p-64\n const Ox1p_75 = reinterpret(0x3B40000000000000); // 0x1p-75\n\n var shift = clz(q1);\n\n q1 = q1 << shift | q0 >> (64 - shift);\n q0 <<= shift;\n\n var lo = umuldi(p1, q1);\n var hi = res128_hi;\n\n var ahi = hi >> 11;\n var alo = lo >> 11 | hi << 53;\n var blo = (Ox1p_75 * p0 * q1 + Ox1p_75 * p1 * q0);\n\n rempio2_y0 = (ahi + u64(lo < blo));\n rempio2_y1 = Ox1p_64 * (alo + blo);\n\n return shift;\n}\n\n/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction umuldi(u: u64, v: u64): u64 {\n var u1: u64 , v1: u64, w0: u64, w1: u64, t: u64;\n\n u1 = u & 0xFFFFFFFF;\n v1 = v & 0xFFFFFFFF;\n\n u >>= 32;\n v >>= 32;\n\n t = u1 * v1;\n w0 = t & 0xFFFFFFFF;\n t = u * v1 + (t >> 32);\n w1 = t >> 32;\n t = u1 * v + (t & 0xFFFFFFFF);\n\n res128_hi = u * v + w1 + (t >> 32);\n return (t << 32) + w0;\n}\n\n/** @internal */\nfunction pio2_large_quot(x: f64, u: i64): i32 { // see: jdh8/metallic/blob/master/src/math/double/rem_pio2.c\n var magnitude = u & 0x7FFFFFFFFFFFFFFF;\n var offset = (magnitude >> 52) - 1045;\n var shift = offset & 63;\n var tblPtr = PIO2_TABLE + ((offset >> 6) << 3);\n var s0: u64, s1: u64, s2: u64;\n\n var b0 = load(tblPtr, 0 << 3);\n var b1 = load(tblPtr, 1 << 3);\n var b2 = load(tblPtr, 2 << 3);\n\n // Get 192 bits of 0x1p-31 / π with `offset` bits skipped\n if (shift) {\n let rshift = 64 - shift;\n let b3 = load(tblPtr, 3 << 3);\n s0 = b1 >> rshift | b0 << shift;\n s1 = b2 >> rshift | b1 << shift;\n s2 = b3 >> rshift | b2 << shift;\n } else {\n s0 = b0;\n s1 = b1;\n s2 = b2;\n }\n\n var significand = (u & 0x000FFFFFFFFFFFFF) | 0x0010000000000000;\n\n // First 128 bits of fractional part of x/(2π)\n var blo = umuldi(s1, significand);\n var bhi = res128_hi;\n\n var ahi = s0 * significand;\n var clo = (s2 >> 32) * (significand >> 32);\n var plo = blo + clo;\n var phi = ahi + bhi + u64(plo < clo);\n\n // r: u128 = p << 2\n var rlo = plo << 2;\n var rhi = phi << 2 | plo >> 62;\n\n // s: i128 = r >> 127\n var slo = rhi >> 63;\n var shi = slo >> 1;\n var q = (phi >> 62) - slo;\n\n var shifter = 0x3CB0000000000000 - (pio2_right(rlo ^ slo, rhi ^ shi) << 52);\n var signbit = (u ^ rhi) & 0x8000000000000000;\n var coeff = reinterpret(shifter | signbit);\n\n rempio2_y0 *= coeff;\n rempio2_y1 *= coeff;\n\n return q;\n}\n\n/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction rempio2(x: f64, u: u64, sign: i32): i32 {\n const\n pio2_1 = reinterpret(0x3FF921FB54400000), // 1.57079632673412561417e+00\n pio2_1t = reinterpret(0x3DD0B4611A626331), // 6.07710050650619224932e-11\n pio2_2 = reinterpret(0x3DD0B4611A600000), // 6.07710050630396597660e-11\n pio2_2t = reinterpret(0x3BA3198A2E037073), // 2.02226624879595063154e-21\n pio2_3 = reinterpret(0x3BA3198A2E000000), // 2.02226624871116645580e-21\n pio2_3t = reinterpret(0x397B839A252049C1), // 8.47842766036889956997e-32\n invpio2 = reinterpret(0x3FE45F306DC9C883); // 0.63661977236758134308\n\n var ix = (u >> 32) & 0x7FFFFFFF;\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (ix < 0x4002D97C) { // |x| < 3pi/4, special case with n=+-1\n let q = 1, z: f64, y0: f64, y1: f64;\n if (!sign) {\n z = x - pio2_1;\n if (ix != 0x3FF921FB) { // 33+53 bit pi is good enough\n y0 = z - pio2_1t;\n y1 = (z - y0) - pio2_1t;\n } else { // near pi/2, use 33+33+53 bit pi\n z -= pio2_2;\n y0 = z - pio2_2t;\n y1 = (z - y0) - pio2_2t;\n }\n } else { // negative x\n z = x + pio2_1;\n if (ix != 0x3FF921FB) { // 33+53 bit pi is good enough\n y0 = z + pio2_1t;\n y1 = (z - y0) + pio2_1t;\n } else { // near pi/2, use 33+33+53 bit pi\n z += pio2_2;\n y0 = z + pio2_2t;\n y1 = (z - y0) + pio2_2t;\n }\n q = -1;\n }\n rempio2_y0 = y0;\n rempio2_y1 = y1;\n return q;\n }\n }\n\n if (ix < 0x413921FB) { // |x| ~< 2^20*pi/2 (1647099)\n // Use precise Cody Waite scheme\n let q = nearest(x * invpio2);\n let r = x - q * pio2_1;\n let w = q * pio2_1t; // 1st round good to 85 bit\n let j = ix >> 20;\n let y0 = r - w;\n let hi = (reinterpret(y0) >> 32);\n let i = j - ((hi >> 20) & 0x7FF);\n\n if (i > 16) { // 2nd iteration needed, good to 118\n let t = r;\n w = q * pio2_2;\n r = t - w;\n w = q * pio2_2t - ((t - r) - w);\n y0 = r - w;\n hi = (reinterpret(y0) >> 32);\n i = j - ((hi >> 20) & 0x7FF);\n if (i > 49) { // 3rd iteration need, 151 bits acc\n let t = r;\n w = q * pio2_3;\n r = t - w;\n w = q * pio2_3t - ((t - r) - w);\n y0 = r - w;\n }\n }\n let y1 = (r - y0) - w;\n rempio2_y0 = y0;\n rempio2_y1 = y1;\n return q;\n }\n var q = pio2_large_quot(x, u);\n return select(-q, q, sign);\n}\n\n/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction sin_kern(x: f64, y: f64, iy: i32): f64 { // see: musl/tree/src/math/__sin.c\n const\n S1 = reinterpret(0xBFC5555555555549), // -1.66666666666666324348e-01\n S2 = reinterpret(0x3F8111111110F8A6), // 8.33333333332248946124e-03\n S3 = reinterpret(0xBF2A01A019C161D5), // -1.98412698298579493134e-04\n S4 = reinterpret(0x3EC71DE357B1FE7D), // 2.75573137070700676789e-06\n S5 = reinterpret(0xBE5AE5E68A2B9CEB), // -2.50507602534068634195e-08\n S6 = reinterpret(0x3DE5D93A5ACFD57C); // 1.58969099521155010221e-10\n\n var z = x * x;\n var w = z * z;\n var r = S2 + z * (S3 + z * S4) + z * w * (S5 + z * S6);\n var v = z * x;\n if (!iy) {\n return x + v * (S1 + z * r);\n } else {\n return x - ((z * (0.5 * y - v * r) - y) - v * S1);\n }\n}\n\n/** @internal */\n// @ts-ignore: decorator\n@inline\nfunction cos_kern(x: f64, y: f64): f64 { // see: musl/tree/src/math/__cos.c\n const\n C1 = reinterpret(0x3FA555555555554C), // 4.16666666666666019037e-02\n C2 = reinterpret(0xBF56C16C16C15177), // -1.38888888888741095749e-03\n C3 = reinterpret(0x3EFA01A019CB1590), // 2.48015872894767294178e-05\n C4 = reinterpret(0xBE927E4F809C52AD), // -2.75573143513906633035e-07\n C5 = reinterpret(0x3E21EE9EBDB4B1C4), // 2.08757232129817482790e-09\n C6 = reinterpret(0xBDA8FAE9BE8838D4); // -1.13596475577881948265e-11\n\n var z = x * x;\n var w = z * z;\n var r = z * (C1 + z * (C2 + z * C3)) + w * w * (C4 + z * (C5 + z * C6));\n var hz = 0.5 * z;\n w = 1.0 - hz;\n return w + (((1.0 - w) - hz) + (z * r - x * y));\n}\n\n/** @internal */\nfunction tan_kern(x: f64, y: f64, iy: i32): f64 { // see: src/lib/msun/src/k_tan.c\n const\n T0 = reinterpret(0x3FD5555555555563), // 3.33333333333334091986e-01\n T1 = reinterpret(0x3FC111111110FE7A), // 1.33333333333201242699e-01\n T2 = reinterpret(0x3FABA1BA1BB341FE), // 5.39682539762260521377e-02\n T3 = reinterpret(0x3F9664F48406D637), // 2.18694882948595424599e-02\n T4 = reinterpret(0x3F8226E3E96E8493), // 8.86323982359930005737e-03\n T5 = reinterpret(0x3F6D6D22C9560328), // 3.59207910759131235356e-03\n T6 = reinterpret(0x3F57DBC8FEE08315), // 1.45620945432529025516e-03\n T7 = reinterpret(0x3F4344D8F2F26501), // 5.88041240820264096874e-04\n T8 = reinterpret(0x3F3026F71A8D1068), // 2.46463134818469906812e-04\n T9 = reinterpret(0x3F147E88A03792A6), // 7.81794442939557092300e-05\n T10 = reinterpret(0x3F12B80F32F0A7E9), // 7.14072491382608190305e-05\n T11 = reinterpret(0xBEF375CBDB605373), // -1.85586374855275456654e-05\n T12 = reinterpret(0x3EFB2A7074BF7AD4); // 2.59073051863633712884e-05\n\n const\n one = reinterpret(0x3FF0000000000000), // 1.00000000000000000000e+00\n pio4 = reinterpret(0x3FE921FB54442D18), // 7.85398163397448278999e-01\n pio4lo = reinterpret(0x3C81A62633145C07); // 3.06161699786838301793e-17\n\n var z: f64, r: f64, v: f64, w: f64, s: f64;\n var hx = (reinterpret(x) >> 32); // high word of x\n var ix = hx & 0x7FFFFFFF; // high word of |x|\n var big = ix >= 0x3FE59428;\n if (big) { // |x| >= 0.6744\n if (hx < 0) { x = -x, y = -y; }\n z = pio4 - x;\n w = pio4lo - y;\n x = z + w;\n y = 0.0;\n }\n z = x * x;\n w = z * z;\n r = T1 + w * (T3 + w * (T5 + w * (T7 + w * (T9 + w * T11))));\n v = z * (T2 + w * (T4 + w * (T6 + w * (T8 + w * (T10 + w * T12)))));\n s = z * x;\n r = y + z * (s * (r + v) + y);\n r += T0 * s;\n w = x + r;\n if (big) {\n v = iy;\n return (1 - ((hx >> 30) & 2)) * (v - 2.0 * (x - (w * w / (w + v) - r)));\n }\n if (iy == 1) return w;\n var a: f64, t: f64;\n z = w;\n z = reinterpret(reinterpret(z) & 0xFFFFFFFF00000000);\n v = r - (z - x); // z + v = r + x\n t = a = -one / w; // a = -1.0 / w\n t = reinterpret(reinterpret(t) & 0xFFFFFFFF00000000);\n s = one + t * z;\n return t + a * (s + t * v);\n}\n\n/** @internal */\nfunction dtoi32(x: f64): i32 {\n if (ASC_SHRINK_LEVEL > 0) {\n const inv32 = 1.0 / 4294967296;\n return (x - 4294967296 * floor(x * inv32));\n } else {\n let result = 0;\n let u = reinterpret(x);\n let e = (u >> 52) & 0x7FF;\n if (e <= 1023 + 30) {\n result = x;\n } else if (e <= 1023 + 30 + 53) {\n let v = (u & ((1 << 52) - 1)) | (1 << 52);\n v = v << e - 1023 - 52 + 32;\n result = (v >> 32);\n result = select(-result, result, u < 0);\n }\n return result;\n }\n}\n\n// @ts-ignore: decorator\n@lazy var random_seeded = false;\n\n// @ts-ignore: decorator\n@lazy var random_state0_64: u64, random_state1_64: u64;\n\n// @ts-ignore: decorator\n@lazy var random_state0_32: u32, random_state1_32: u32;\n\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\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 // @ts-ignore: decorator\n @lazy\n export const E = reinterpret(0x4005BF0A8B145769); // 2.7182818284590452354\n\n // @ts-ignore: decorator\n @lazy\n export const LN2 = reinterpret(0x3FE62E42FEFA39EF); // 0.69314718055994530942\n\n // @ts-ignore: decorator\n @lazy\n export const LN10 = reinterpret(0x40026BB1BBB55516); // 2.30258509299404568402\n\n // @ts-ignore: decorator\n @lazy\n export const LOG2E = reinterpret(0x3FF71547652B82FE); // 1.4426950408889634074\n\n // @ts-ignore: decorator\n @lazy\n export const LOG10E = reinterpret(0x3FDBCB7B1526E50E); // 0.43429448190325182765\n\n // @ts-ignore: decorator\n @lazy\n export const PI = reinterpret(0x400921FB54442D18); // 3.14159265358979323846\n\n // @ts-ignore: decorator\n @lazy\n export const SQRT1_2 = reinterpret(0x3FE6A09E667F3BCD); // 0.70710678118654752440\n\n // @ts-ignore: decorator\n @lazy\n export const SQRT2 = reinterpret(0x3FF6A09E667F3BCD); // 1.41421356237309504880\n\n // @ts-ignore: decorator\n @lazy\n export var sincos_sin: f64 = 0;\n\n // @ts-ignore: decorator\n @lazy\n export var sincos_cos: f64 = 0;\n\n // @ts-ignore: decorator\n @inline 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\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 < 0) 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 < 0) {\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 u = reinterpret(x);\n // Prevent propagation for all input values less than 1.0.\n // Note musl lib didn't fix this yet.\n if (u < 0x3FF0000000000000) return (x - x) / 0.0;\n var e = u >> 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\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 return select(-x, x, hx < 0);\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\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 y = builtin_abs(x);\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 let t = m & 2 ? 3 * PI / 4 : PI / 4;\n return m & 1 ? -t : t;\n } else {\n let t = m & 2 ? PI : 0;\n return m & 1 ? -t : t;\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); // 0x1p54\n\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 r = (r - t) / (2 * t + r);\n t = t + t * r;\n return t;\n }\n\n // @ts-ignore: decorator\n @inline\n export function ceil(x: f64): f64 {\n return builtin_ceil(x);\n }\n\n export function clz32(x: f64): f64 {\n if (!isFinite(x)) return 32;\n /*\n * Wasm (MVP) and JS have different approaches for double->int conversions.\n *\n * For emulate JS conversion behavior and avoid trapping from wasm we should modulate by MAX_INT\n * our float-point arguments before actual convertion to integers.\n */\n return builtin_clz(dtoi32(x));\n }\n\n export function cos(x: f64): f64 { // see: musl/src/math/cos.c\n var u = reinterpret(x);\n var ux = u32(u >> 32);\n var sign = ux >> 31;\n\n ux &= 0x7FFFFFFF;\n\n // |x| ~< pi/4\n if (ux <= 0x3FE921FB) {\n if (ux < 0x3E46A09E) { // |x| < 2**-27 * sqrt(2)\n return 1.0;\n }\n return cos_kern(x, 0);\n }\n\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7FF00000) return x - x;\n\n // argument reduction needed\n var n = rempio2(x, u, sign);\n var y0 = rempio2_y0;\n var y1 = rempio2_y1;\n\n x = n & 1 ? sin_kern(y0, y1, 1) : cos_kern(y0, y1);\n return (n + 1) & 2 ? -x : x;\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, 1);\n return t;\n }\n\n export function exp(x: f64): f64 { // see: musl/src/math/exp.c and SUN COPYRIGHT NOTICE above\n if (ASC_SHRINK_LEVEL < 1) {\n return exp_lut(x);\n } else {\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); // 0x1p1023\n\n let hx = u32(reinterpret(x) >> 32);\n let sign = hx >> 31;\n hx &= 0x7FFFFFFF;\n if (hx >= 0x4086232B) {\n if (isNaN(x)) return x;\n if (x > overflow) return x * Ox1p1023;\n if (x < underflow) return 0;\n }\n let hi: f64, lo: f64 = 0;\n let k = 0;\n if (hx > 0x3FD62E42) {\n if (hx >= 0x3FF0A2B2) {\n k = i32(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 let xs = x * x;\n // var c = x - xp2 * (P1 + xp2 * (P2 + xp2 * (P3 + xp2 * (P4 + xp2 * P5))));\n let xq = xs * xs;\n let c = x - (xs * P1 + xq * ((P2 + xs * P3) + xq * (P4 + xs * P5)));\n let y = 1.0 + (x * c / (2 - c) - lo + hi);\n return k == 0 ? y : scalbn(y, k);\n }\n }\n\n export function exp2(x: f64): f64 {\n return exp2_lut(x);\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); // 0x1p1023\n\n var u = reinterpret(x);\n var hx = u32(u >> 32) & 0x7FFFFFFF;\n var sign = u32(u >> 63);\n var k = 0;\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 i32(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 var hxq = hxs * hxs;\n var r1 = (1.0 + hxs * Q1) + hxq * ((Q2 + hxs * Q3) + hxq * (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 // @ts-ignore: decorator\n @inline\n export function floor(x: f64): f64 {\n return builtin_floor(x);\n }\n\n // @ts-ignore: decorator\n @inline\n export function fround(x: f64): f64 {\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\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 = i32(ux >> 52);\n var ey = i32(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 /*\n * Wasm (MVP) and JS have different approaches for double->int conversions.\n *\n * For emulate JS conversion behavior and avoid trapping from wasm we should modulate by MAX_INT\n * our float-point arguments before actual convertion to integers.\n */\n if (!isFinite(x + y)) return 0;\n return dtoi32(x) * dtoi32(y);\n }\n\n export function log(x: f64): f64 { // see: musl/src/math/log.c and SUN COPYRIGHT NOTICE above\n if (ASC_SHRINK_LEVEL < 1) {\n return log_lut(x);\n } else {\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); // 0x1p54\n\n let u = reinterpret(x);\n let hx = u32(u >> 32);\n let k = 0;\n let sign = hx >> 31;\n if (sign || hx < 0x00100000) {\n if (u << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = u32(u >> 32);\n } else if (hx >= 0x7FF00000) {\n return x;\n } else if (hx == 0x3FF00000 && u << 32 == 0) {\n return 0;\n }\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 let f = x - 1.0;\n let hfsq = 0.5 * f * f;\n let s = f / (2.0 + f);\n let z = s * s;\n let w = z * z;\n let t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n let t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n let r = t2 + t1;\n let dk = k;\n return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;\n }\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); // 0x1p54\n\n var u = reinterpret(x);\n var hx = u32(u >> 32);\n var k = 0;\n var sign = hx >> 31;\n if (sign || hx < 0x00100000) {\n if (u << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = u32(u >> 32);\n } else if (hx >= 0x7FF00000) {\n return x;\n } else if (hx == 0x3FF00000 && u << 32 == 0) {\n return 0;\n }\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += i32(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\n var u = reinterpret(x);\n var hx = u32(u >> 32);\n var k = 1;\n var c = 0.0, f = 0.0;\n if (hx < 0x3FDA827A || bool(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 = u32(u >> 32);\n hu += 0x3FF00000 - 0x3FE6A09E;\n k = i32(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 if (ASC_SHRINK_LEVEL < 1) {\n return log2_lut(x);\n } else {\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); // 1p54\n\n let u = reinterpret(x);\n let hx = u32(u >> 32);\n let k = 0;\n let sign = hx >> 31;\n if (sign || hx < 0x00100000) {\n if (u << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 54;\n x *= Ox1p54;\n u = reinterpret(x);\n hx = u32(u >> 32);\n } else if (hx >= 0x7FF00000) {\n return x;\n } else if (hx == 0x3FF00000 && u << 32 == 0) {\n return 0;\n }\n hx += 0x3FF00000 - 0x3FE6A09E;\n k += i32(hx >> 20) - 0x3FF;\n hx = (hx & 0x000FFFFF) + 0x3FE6A09E;\n u = hx << 32 | (u & 0xFFFFFFFF);\n x = reinterpret(u);\n let f = x - 1.0;\n let hfsq = 0.5 * f * f;\n let s = f / (2.0 + f);\n let z = s * s;\n let w = z * z;\n let t1 = w * (Lg2 + w * (Lg4 + w * Lg6));\n let t2 = z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7)));\n let r = t2 + t1;\n let hi = f - hfsq;\n u = reinterpret(hi);\n u &= 0xFFFFFFFF00000000;\n hi = reinterpret(u);\n let lo = f - hi - hfsq + s * (hfsq + r);\n let val_hi = hi * ivln2hi;\n let val_lo = (lo + hi) * ivln2lo + lo * ivln2hi;\n let 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\n // @ts-ignore: decorator\n @inline\n export function max(value1: f64, value2: f64): f64 {\n return builtin_max(value1, value2);\n }\n\n // @ts-ignore: decorator\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 // TODO: remove this fast pathes after introduced own mid-end IR with \"stdlib call simplify\" transforms\n if (builtin_abs(y) <= 2) {\n if (y == 2.0) return x * x;\n if (y == 0.5) {\n return select(\n builtin_abs(builtin_sqrt(x)),\n Infinity,\n x != -Infinity\n );\n }\n if (y == -1.0) return 1 / x;\n if (y == 1.0) return x;\n if (y == 0.0) return 1.0;\n }\n if (ASC_SHRINK_LEVEL < 1) {\n return pow_lut(x, y);\n } else {\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\n let u_ = reinterpret(x);\n let hx = i32(u_ >> 32);\n let lx = u_;\n u_ = reinterpret(y);\n let hy = i32(u_ >> 32);\n let ly = u_;\n let ix = hx & 0x7FFFFFFF;\n let 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 let 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 let ax = builtin_abs(x), z: f64;\n if (lx == 0) {\n if (ix == 0 || ix == 0x7FF00000 || ix == 0x3FF00000) {\n z = ax;\n if (hy < 0) z = 1.0 / z;\n if (hx < 0) {\n if (((ix - 0x3FF00000) | yisint) == 0) {\n let d = z - z;\n z = d / d;\n } else if (yisint == 1) z = -z;\n }\n return z;\n }\n }\n let s = 1.0;\n if (hx < 0) {\n if (yisint == 0) {\n let d = x - x;\n return d / d;\n }\n if (yisint == 1) s = -1.0;\n }\n let t1: f64, t2: f64, p_h: f64, p_l: f64, r: f64, t: f64, u: f64, v: f64, w: f64;\n let 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(u64(((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 let 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 = u32(u_ >> 32);\n let 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(u64(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 = u32(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\n export function seedRandom(value: i64): void {\n // Instead zero seed use golden ratio:\n // phi = (1 + sqrt(5)) / 2\n // trunc(2^64 / phi) = 0x9e3779b97f4a7c15\n if (value == 0) value = 0x9e3779b97f4a7c15;\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 random_seeded = true;\n }\n\n export function random(): f64 { // see: v8/src/base/utils/random-number-generator.cc\n if (!random_seeded) seedRandom(reinterpret(seed()));\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 >> 12) | 0x3FF0000000000000;\n return reinterpret(r) - 1;\n }\n\n // @ts-ignore: decorator\n @inline\n export function round(x: f64): f64 {\n let roundUp = builtin_ceil(x);\n return select(roundUp, roundUp - 1.0, roundUp - 0.5 <= x);\n }\n\n // @ts-ignore: decorator\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 // @ts-ignore: decorator\n @inline\n export function signbit(x: f64): bool {\n return bool(reinterpret(x) >>> 63);\n }\n\n export function sin(x: f64): f64 { // see: musl/src/math/sin.c\n var u = reinterpret(x);\n var ux = u32(u >> 32);\n var sign = ux >> 31;\n\n ux &= 0x7FFFFFFF;\n\n // |x| ~< pi/4\n if (ux <= 0x3FE921FB) {\n if (ux < 0x3E500000) { // |x| < 2**-26\n return x;\n }\n return sin_kern(x, 0.0, 0);\n }\n\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7FF00000) return x - x;\n\n // argument reduction needed\n var n = rempio2(x, u, sign);\n var y0 = rempio2_y0;\n var y1 = rempio2_y1;\n\n x = n & 1 ? cos_kern(y0, y1) : sin_kern(y0, y1, 1);\n return n & 2 ? -x : x;\n }\n\n export function sinh(x: f64): f64 { // see: musl/src/math/sinh.c\n var u = reinterpret(x) & 0x7FFFFFFFFFFFFFFF;\n var a = reinterpret(u);\n var w = u32(u >> 32);\n var h = builtin_copysign(0.5, x);\n if (w < 0x40862E42) {\n let t = expm1(a);\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 return expo2(a, 2 * h);\n }\n\n // @ts-ignore: decorator\n @inline\n export function sqrt(x: f64): f64 {\n return builtin_sqrt(x);\n }\n\n export function tan(x: f64): f64 { // see: musl/src/math/tan.c\n var u = reinterpret(x);\n var ux = u32(u >> 32);\n var sign = ux >>> 31;\n\n ux &= 0x7FFFFFFF;\n\n // |x| ~< pi/4\n if (ux <= 0x3FE921FB) {\n if (ux < 0x3E400000) { // |x| < 2**-27\n return x;\n }\n return tan_kern(x, 0.0, 1);\n }\n\n // tan(Inf or NaN) is NaN\n if (ux >= 0x7FF00000) return x - x;\n\n var n = rempio2(x, u, sign);\n return tan_kern(rempio2_y0, rempio2_y1, 1 - ((n & 1) << 1));\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 = u32(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 // @ts-ignore: decorator\n @inline\n export function trunc(x: f64): f64 {\n return builtin_trunc(x);\n }\n\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\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 // 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 if (builtin_abs(y) == 1.0) {\n // x % 1, x % -1 ==> sign(x) * abs(x - 1.0 * trunc(x / 1.0))\n // TODO: move this rule to compiler's optimization pass.\n // It could be apply for any x % C_pot, where \"C_pot\" is pow of two const.\n return builtin_copysign(x - builtin_trunc(x), x);\n }\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = i64(ux >> 52 & 0x7FF);\n var ey = i64(uy >> 52 & 0x7FF);\n var sx = ux >> 63;\n var uy1 = uy << 1;\n if (uy1 == 0 || ex == 0x7FF || isNaN(y)) {\n let m = x * y;\n return m / m;\n }\n var ux1 = ux << 1;\n if (ux1 <= uy1) {\n return x * f64(ux1 != uy1);\n }\n if (!ex) {\n ex -= builtin_clz(ux << 12);\n ux <<= 1 - ex;\n } else {\n ux &= u64(-1) >> 12;\n ux |= 1 << 52;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 12);\n uy <<= 1 - ey;\n } else {\n uy &= u64(-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 return reinterpret(ux | (sx << 63));\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 = i64(ux >> 52 & 0x7FF);\n var ey = i64(uy >> 52 & 0x7FF);\n if (uy << 1 == 0 || ex == 0x7FF || isNaN(y)) {\n let m = x * y;\n return m / m;\n }\n if (ux << 1 == 0) return x;\n var uxi = ux;\n if (!ex) {\n ex -= builtin_clz(uxi << 12);\n uxi <<= 1 - ex;\n } else {\n uxi &= u64(-1) >> 12;\n uxi |= 1 << 52;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 12);\n uy <<= 1 - ey;\n } else {\n uy &= u64(-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 ux < 0 ? -x : x;\n }\n\n export function sincos(x: f64): void { // see: musl/tree/src/math/sincos.c\n var u = reinterpret(x);\n var ux = u32(u >> 32);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3FE921FB) { // |x| ~<= π/4\n if (ux < 0x3E46A09E) { // if |x| < 2**-27 * sqrt(2)\n sincos_sin = x;\n sincos_cos = 1;\n return;\n }\n sincos_sin = sin_kern(x, 0, 0);\n sincos_cos = cos_kern(x, 0);\n return;\n }\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7F800000) {\n let xx = x - x;\n sincos_sin = xx;\n sincos_cos = xx;\n return;\n }\n // general argument reduction needed\n var n = rempio2(x, u, sign);\n var y0 = rempio2_y0;\n var y1 = rempio2_y1;\n var s = sin_kern(y0, y1, 1);\n var c = cos_kern(y0, y1);\n var sin = s, cos = c;\n if (n & 1) {\n sin = c;\n cos = -s;\n }\n if (n & 2) {\n sin = -sin;\n cos = -cos;\n }\n sincos_sin = sin;\n sincos_cos = cos;\n }\n}\n\n// @ts-ignore: decorator\n@lazy var rempio2f_y: f64;\n\n// @ts-ignore: decorator\n@lazy @inline const PIO2F_TABLE = memory.data([\n 0xA2F9836E4E441529,\n 0xFC2757D1F534DDC0,\n 0xDB6295993C439041,\n 0xFE5163ABDEBBC561\n]);\n\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\n var p = z * (pS0 + z * (pS1 + z * pS2));\n var q: f32 = 1 + z * qS1;\n return p / q;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction expo2f(x: f32, sign: 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(u32(0x7F + (k >> 1)) << 23);\n // in directed rounding correct sign before rounding or overflow is important\n return NativeMathf.exp(x - kln2) * (sign * scale) * scale;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction pio2f_large_quot(x: f32, u: i32): i32 { // see: jdh8/metallic/blob/master/src/math/float/rem_pio2f.c\n const coeff = reinterpret(0x3BF921FB54442D18); // π * 0x1p-65 = 8.51530395021638647334e-20\n\n var offset = (u >> 23) - 152;\n var shift = u64(offset & 63);\n var tblPtr = PIO2F_TABLE + (offset >> 6 << 3);\n\n var b0 = load(tblPtr, 0 << 3);\n var b1 = load(tblPtr, 1 << 3);\n var lo: u64;\n\n if (shift > 32) {\n let b2 = load(tblPtr, 2 << 3);\n lo = b2 >> (96 - shift);\n lo |= b1 << (shift - 32);\n } else {\n lo = b1 >> (32 - shift);\n }\n\n var hi = (b1 >> (64 - shift)) | (b0 << shift);\n var mantissa: u64 = (u & 0x007FFFFF) | 0x00800000;\n var product = mantissa * hi + (mantissa * lo >> 32);\n var r: i64 = product << 2;\n var q = i32((product >> 62) + (r >>> 63));\n rempio2f_y = copysign(coeff, x) * r;\n return q;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction rempio2f(x: f32, u: u32, sign: i32): i32 { // see: jdh8/metallic/blob/master/src/math/float/rem_pio2f.c\n const\n pi2hi = reinterpret(0x3FF921FB50000000), // 1.57079631090164184570\n pi2lo = reinterpret(0x3E5110B4611A6263), // 1.58932547735281966916e-8\n _2_pi = reinterpret(0x3FE45F306DC9C883); // 0.63661977236758134308\n\n if (u < 0x4DC90FDB) { // π * 0x1p28\n let q = nearest(x * _2_pi);\n rempio2f_y = x - q * pi2hi - q * pi2lo;\n return q;\n }\n\n var q = pio2f_large_quot(x, u);\n return select(-q, q, sign);\n}\n\n// |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]).\n// @ts-ignore: decorator\n@inline\nfunction sin_kernf(x: f64): f32 { // see: musl/tree/src/math/__sindf.c\n const\n S1 = reinterpret(0xBFC5555554CBAC77), // -0x15555554cbac77.0p-55\n S2 = reinterpret(0x3F811110896EFBB2), // 0x111110896efbb2.0p-59\n S3 = reinterpret(0xBF2A00F9E2CAE774), // -0x1a00f9e2cae774.0p-65\n S4 = reinterpret(0x3EC6CD878C3B46A7); // 0x16cd878c3b46a7.0p-71\n\n var z = x * x;\n var w = z * z;\n var r = S3 + z * S4;\n var s = z * x;\n return f32((x + s * (S1 + z * S2)) + s * w * r);\n}\n\n// |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]).\n// @ts-ignore: decorator\n@inline\nfunction cos_kernf(x: f64): f32 { // see: musl/tree/src/math/__cosdf.c\n const\n C0 = reinterpret(0xBFDFFFFFFD0C5E81), // -0x1ffffffd0c5e81.0p-54\n C1 = reinterpret(0x3FA55553E1053A42), // 0x155553e1053a42.0p-57\n C2 = reinterpret(0xBF56C087E80F1E27), // -0x16c087e80f1e27.0p-62\n C3 = reinterpret(0x3EF99342E0EE5069); // 0x199342e0ee5069.0p-68\n\n var z = x * x;\n var w = z * z;\n var r = C2 + z * C3;\n return f32(((1 + z * C0) + w * C1) + (w * z) * r);\n}\n\n// |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]).\n// @ts-ignore: decorator\n@inline\nfunction tan_kernf(x: f64, odd: i32): f32 { // see: musl/tree/src/math/__tandf.c\n const\n T0 = reinterpret(0x3FD5554D3418C99F), // 0x15554d3418c99f.0p-54\n T1 = reinterpret(0x3FC112FD38999F72), // 0x1112fd38999f72.0p-55\n T2 = reinterpret(0x3FAB54C91D865AFE), // 0x1b54c91d865afe.0p-57\n T3 = reinterpret(0x3F991DF3908C33CE), // 0x191df3908c33ce.0p-58\n T4 = reinterpret(0x3F685DADFCECF44E), // 0x185dadfcecf44e.0p-61\n T5 = reinterpret(0x3F8362B9BF971BCD); // 0x1362b9bf971bcd.0p-59\n\n var z = x * x;\n var r = T4 + z * T5;\n var t = T2 + z * T3;\n var w = z * z;\n var s = z * x;\n var u = T0 + z * T1;\n\n r = (x + s * u) + (s * w) * (t + w * r);\n return f32(odd ? -1 / r : r);\n}\n\n// See: jdh8/metallic/src/math/float/log2f.c and jdh8/metallic/src/math/float/kernel/atanh.h\n// @ts-ignore: decorator\n@inline\nfunction log2f(x: f64): f64 {\n const\n log2e = reinterpret(0x3FF71547652B82FE), // 1.44269504088896340736\n c0 = reinterpret(0x3FD555554FD9CAEF), // 0.33333332822728226129\n c1 = reinterpret(0x3FC999A7A8AF4132), // 0.20000167595436263505\n c2 = reinterpret(0x3FC2438D79437030), // 0.14268654271188685375\n c3 = reinterpret(0x3FBE2F663B001C97); // 0.11791075649681414150\n\n var i = reinterpret(x);\n var exponent = (i - 0x3FE6A09E667F3BCD) >> 52;\n x = reinterpret(i - (exponent << 52));\n x = (x - 1) / (x + 1);\n var xx = x * x;\n var y = x + x * xx * (c0 + c1 * xx + (c2 + c3 * xx) * (xx * xx));\n return (2 * log2e) * y + exponent;\n}\n\n// See: jdh8/metallic/src/math/float/exp2f.h and jdh8/metallic/blob/master/src/math/float/kernel/exp2f.h\n// @ts-ignore: decorator\n@inline\nfunction exp2f(x: f64): f64 {\n const\n c0 = reinterpret(0x3FE62E4302FCC24A), // 6.931471880289532425e-1\n c1 = reinterpret(0x3FCEBFBE07D97B91), // 2.402265108421173406e-1\n c2 = reinterpret(0x3FAC6AF6CCFC1A65), // 5.550357105498874537e-2\n c3 = reinterpret(0x3F83B29E3CE9AEF6), // 9.618030771171497658e-3\n c4 = reinterpret(0x3F55F0896145A89F), // 1.339086685300950937e-3\n c5 = reinterpret(0x3F2446C81E384864); // 1.546973499989028719e-4\n\n if (x < -1022) return 0;\n if (x >= 1024) return Infinity;\n\n var n = nearest(x);\n x -= n;\n var xx = x * x;\n var y = 1 + x * (c0 + c1 * x + (c2 + c3 * x) * xx + (c4 + c5 * x) * (xx * xx));\n return reinterpret(reinterpret(y) + (n << 52));\n}\n\nexport namespace NativeMathf {\n\n // @ts-ignore: decorator\n @lazy\n export const E = NativeMath.E;\n\n // @ts-ignore: decorator\n @lazy\n export const LN2 = NativeMath.LN2;\n\n // @ts-ignore: decorator\n @lazy\n export const LN10 = NativeMath.LN10;\n\n // @ts-ignore: decorator\n @lazy\n export const LOG2E = NativeMath.LOG2E;\n\n // @ts-ignore: decorator\n @lazy\n export const LOG10E = NativeMath.LOG10E;\n\n // @ts-ignore: decorator\n @lazy\n export const PI = NativeMath.PI;\n\n // @ts-ignore: decorator\n @lazy\n export const SQRT1_2 = NativeMath.SQRT1_2;\n\n // @ts-ignore: decorator\n @lazy\n export const SQRT2 = NativeMath.SQRT2;\n\n // @ts-ignore: decorator\n @lazy\n export var sincos_sin: f32 = 0;\n\n // @ts-ignore: decorator\n @lazy\n export var sincos_cos: f32 = 0;\n\n // @ts-ignore: decorator\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); // 0x1p-120f\n\n var hx = reinterpret(x);\n var ix = hx & 0x7FFFFFFF;\n if (ix >= 0x3F800000) {\n if (ix == 0x3F800000) {\n return select(2 * pio2_hi + Ox1p_120f, 0, hx < 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 < 0) {\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)) { // |x| < 2, invalid if x < 1\n let xm1 = x - 1;\n return log1p(xm1 + builtin_sqrt(xm1 * (xm1 + 2)));\n }\n if (u < 0x3F800000 + (12 << 23)) { // 2 <= x < 0x1p12\n return log(2 * x - 1 / (x + builtin_sqrt(x * x - 1)));\n }\n // x >= 0x1p12 or x <= -2 or NaN\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); // 0x1p-120f\n\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 = f32(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); // 0x1p-120f\n\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 var y = builtin_abs(x);\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\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 = u32(((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 let t: f32 = m & 2 ? 3 * pi / 4 : pi / 4;\n return m & 1 ? -t : t;\n } else {\n let t: f32 = m & 2 ? pi : 0.0;\n return m & 1 ? -t : t;\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\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 // @ts-ignore: decorator\n @inline\n export function ceil(x: f32): f32 {\n return builtin_ceil(x);\n }\n\n export function clz32(x: f32): f32 {\n if (!isFinite(x)) return 32;\n return builtin_clz(dtoi32(x));\n }\n\n export function cos(x: f32): f32 { // see: musl/src/math/cosf.c\n const\n c1pio2 = reinterpret(0x3FF921FB54442D18), // M_PI_2 * 1\n c2pio2 = reinterpret(0x400921FB54442D18), // M_PI_2 * 2\n c3pio2 = reinterpret(0x4012D97C7F3321D2), // M_PI_2 * 3\n c4pio2 = reinterpret(0x401921FB54442D18); // M_PI_2 * 4\n\n var ux = reinterpret(x);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3F490FDA) { // |x| ~<= π/4\n if (ux < 0x39800000) { // |x| < 2**-12\n // raise inexact if x != 0\n return 1;\n }\n return cos_kernf(x);\n }\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (ux <= 0x407B53D1) { // |x| ~<= 5π/4\n if (ux > 0x4016CBE3) { // |x| ~> 3π/4\n return -cos_kernf(sign ? x + c2pio2 : x - c2pio2);\n } else {\n return sign ? sin_kernf(x + c1pio2) : sin_kernf(c1pio2 - x);\n }\n }\n if (ux <= 0x40E231D5) { // |x| ~<= 9π/4\n if (ux > 0x40AFEDDF) { // |x| ~> 7π/4\n return cos_kernf(sign ? x + c4pio2 : x - c4pio2);\n } else {\n return sign ? sin_kernf(-x - c3pio2) : sin_kernf(x - c3pio2);\n }\n }\n }\n\n // cos(Inf or NaN) is NaN\n if (ux >= 0x7F800000) return x - x;\n\n // general argument reduction needed\n var n = rempio2f(x, ux, sign);\n var y = rempio2f_y;\n\n var t = n & 1 ? sin_kernf(y) : cos_kernf(y);\n return (n + 1) & 2 ? -t : t;\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, 1);\n }\n\n // @ts-ignore: decorator\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 if (ASC_SHRINK_LEVEL < 1) {\n return expf_lut(x);\n } else {\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); // 0x1p+127f\n\n let hx = reinterpret(x);\n let sign = hx >> 31;\n hx &= 0x7FFFFFFF;\n if (hx >= 0x42AEAC50) {\n if (hx > 0x7F800000) return x; // NaN\n if (hx >= 0x42B17218) {\n if (!sign) return x * Ox1p127f;\n else if (hx >= 0x42CFF1B5) return 0;\n }\n }\n let hi: f32, lo: f32;\n let k: i32;\n if (hx > 0x3EB17218) {\n if (hx > 0x3F851592) {\n k = i32(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 let xx = x * x;\n let c = x - xx * (P1 + xx * P2);\n let y: f32 = 1 + (x * c / (2 - c) - lo + hi);\n return k == 0 ? y : scalbn(y, k);\n }\n }\n\n export function exp2(x: f32): f32 {\n return exp2f_lut(x);\n }\n\n export function expm1(x: f32): f32 { // see: musl/src/math/expm1f.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 invln2 = reinterpret(0x3FB8AA3B), // 1.4426950216e+00f\n Q1 = reinterpret(0xBD088868), // -3.3333212137e-02f\n Q2 = reinterpret(0x3ACF3010), // 1.5807170421e-03f\n Ox1p127f = reinterpret(0x7F000000); // 0x1p+127f\n\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 (hx > 0x42B17217) { // x > log(FLT_MAX)\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 i32(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 // @ts-ignore: decorator\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\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(f32(x * x + y * y));\n }\n\n // @ts-ignore: decorator\n @inline\n export function imul(x: f32, y: f32): f32 {\n /*\n * Wasm (MVP) and JS have different approaches for double->int conversions.\n *\n * For emulate JS conversion behavior and avoid trapping from wasm we should modulate by MAX_INT\n * our float-point arguments before actual convertion to integers.\n */\n if (!isFinite(x + y)) return 0;\n return (dtoi32(x) * dtoi32(y));\n }\n\n export function log(x: f32): f32 { // see: musl/src/math/logf.c and SUN COPYRIGHT NOTICE above\n if (ASC_SHRINK_LEVEL < 1) {\n return logf_lut(x);\n } else {\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\n let u = reinterpret(x);\n let k = 0;\n let sign = u >> 31;\n if (sign || u < 0x00800000) {\n if (u << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0;\n k -= 25;\n x *= Ox1p25f;\n u = reinterpret(x);\n } else if (u >= 0x7F800000) {\n return x;\n } else if (u == 0x3F800000) {\n return 0;\n }\n u += 0x3F800000 - 0x3F3504F3;\n k += i32(u >> 23) - 0x7F;\n u = (u & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(u);\n let f = x - 1.0;\n let s = f / (2.0 + f);\n let z = s * s;\n let w = z * z;\n let t1 = w * (Lg2 + w * Lg4);\n let t2 = z * (Lg1 + w * Lg3);\n let r = t2 + t1;\n let hfsq = 0.5 * f * f;\n let dk = k;\n return s * (hfsq + r) + dk * ln2_lo - hfsq + f + dk * ln2_hi;\n }\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); // 0x1p25f\n\n var ux = reinterpret(x);\n var k = 0;\n var sign = ux >> 31;\n if (sign || ux < 0x00800000) {\n if (ux << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 25;\n x *= Ox1p25f;\n ux = reinterpret(x);\n } else if (ux >= 0x7F800000) {\n return x;\n } else if (ux == 0x3F800000) {\n return 0;\n }\n ux += 0x3F800000 - 0x3F3504F3;\n k += i32(ux >> 23) - 0x7F;\n ux = (ux & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(ux);\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 ux = reinterpret(hi);\n ux &= 0xFFFFF000;\n hi = reinterpret(ux);\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\n var ix = reinterpret(x);\n var c: f32 = 0;\n var f: f32 = 0;\n var k = 1;\n if (ix < 0x3ED413D0 || bool(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 = i32(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 if (ASC_SHRINK_LEVEL < 1) {\n return log2f_lut(x);\n } else {\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); // 0x1p25f\n\n let ux = reinterpret(x);\n let k = 0;\n let sign = ux >> 31;\n if (sign || ux < 0x00800000) {\n if (ux << 1 == 0) return -1 / (x * x);\n if (sign) return (x - x) / 0.0;\n k -= 25;\n x *= Ox1p25f;\n ux = reinterpret(x);\n } else if (ux >= 0x7F800000) {\n return x;\n } else if (ux == 0x3F800000) {\n return 0;\n }\n ux += 0x3F800000 - 0x3F3504F3;\n k += i32(ux >> 23) - 0x7F;\n ux = (ux & 0x007FFFFF) + 0x3F3504F3;\n x = reinterpret(ux);\n let f = x - 1.0;\n let s = f / (2.0 + f);\n let z = s * s;\n let w = z * z;\n let t1 = w * (Lg2 + w * Lg4);\n let t2 = z * (Lg1 + w * Lg3);\n let r = t2 + t1;\n let hfsq: f32 = 0.5 * f * f;\n let hi = f - hfsq;\n let u = reinterpret(hi);\n u &= 0xFFFFF000;\n hi = reinterpret(u);\n let lo: f32 = f - hi - hfsq + s * (hfsq + r);\n let dk = k;\n return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + dk;\n }\n }\n\n // @ts-ignore: decorator\n @inline\n export function max(value1: f32, value2: f32): f32 {\n return builtin_max(value1, value2);\n }\n\n // @ts-ignore: decorator\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 {\n // TODO: remove this fast pathes after introduced own mid-end IR with \"stdlib call simplify\" transforms\n if (builtin_abs(y) <= 2) {\n if (y == 2.0) return x * x;\n if (y == 0.5) {\n return select(\n builtin_abs(builtin_sqrt(x)),\n Infinity,\n x != -Infinity\n );\n }\n if (y == -1.0) return 1 / x;\n if (y == 1.0) return x;\n if (y == 0.0) return 1.0;\n }\n if (ASC_SHRINK_LEVEL < 1) {\n // see: musl/src/math/powf.c\n return powf_lut(x, y);\n } else {\n // based on: jdh8/metallic/src/math/float/powf.c\n if (y == 0) return 1;\n // @ts-ignore: cast\n if (isNaN(x) | isNaN(y)) {\n return NaN;\n }\n let sign: u32 = 0;\n let uy = reinterpret(y);\n let ux = reinterpret(x);\n let sx = ux >> 31;\n ux &= 0x7FFFFFFF;\n if (sx && nearest(y) == y) {\n x = -x;\n sx = 0;\n sign = u32(nearest(y * 0.5) != y * 0.5) << 31;\n }\n let m: u32;\n if (ux == 0x3F800000) { // x == 1\n m = sx | u32((uy & 0x7FFFFFFF) == 0x7F800000) ? 0x7FC00000 : 0x3F800000;\n } else if (ux == 0) {\n m = uy < 0 ? 0x7F800000 : 0;\n } else if (ux == 0x7F800000) {\n m = uy < 0 ? 0 : 0x7F800000;\n } else if (sx) {\n m = 0x7FC00000;\n } else {\n m = reinterpret(exp2f(y * log2f(x)));\n }\n return reinterpret(m | sign);\n }\n }\n\n // @ts-ignore: decorator\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) seedRandom(reinterpret(seed()));\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 // @ts-ignore: decorator\n @inline\n export function round(x: f32): f32 {\n let roundUp = builtin_ceil(x);\n return select(roundUp, roundUp - 1.0, roundUp - 0.5 <= x);\n }\n\n // @ts-ignore: decorator\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 // @ts-ignore: decorator\n @inline\n export function signbit(x: f32): bool {\n return (reinterpret(x) >>> 31);\n }\n\n export function sin(x: f32): f32 { // see: musl/src/math/sinf.c\n const\n s1pio2 = reinterpret(0x3FF921FB54442D18), // M_PI_2 * 1\n s2pio2 = reinterpret(0x400921FB54442D18), // M_PI_2 * 2\n s3pio2 = reinterpret(0x4012D97C7F3321D2), // M_PI_2 * 3\n s4pio2 = reinterpret(0x401921FB54442D18); // M_PI_2 * 4\n\n var ux = reinterpret(x);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3F490FDA) { // |x| ~<= π/4\n if (ux < 0x39800000) { // |x| < 2**-12\n return x;\n }\n return sin_kernf(x);\n }\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (ux <= 0x407B53D1) { // |x| ~<= 5π/4\n if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4\n return sign ? -cos_kernf(x + s1pio2) : cos_kernf(x - s1pio2);\n }\n return sin_kernf(-(sign ? x + s2pio2 : x - s2pio2));\n }\n\n if (ux <= 0x40E231D5) { // |x| ~<= 9π/4\n if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4\n return sign ? cos_kernf(x + s3pio2) : -cos_kernf(x - s3pio2);\n }\n return sin_kernf(sign ? x + s4pio2 : x - s4pio2);\n }\n }\n\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7F800000) return x - x;\n\n var n = rempio2f(x, ux, sign);\n var y = rempio2f_y;\n\n var t = n & 1 ? cos_kernf(y) : sin_kernf(y);\n return n & 2 ? -t : t;\n }\n\n export function sinh(x: f32): f32 { // see: musl/src/math/sinhf.c\n var u = reinterpret(x) & 0x7FFFFFFF;\n var a = reinterpret(u);\n var h = builtin_copysign(0.5, x);\n if (u < 0x42B17217) {\n let t = expm1(a);\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 return expo2f(a, 2 * h);\n }\n\n // @ts-ignore: decorator\n @inline\n export function sqrt(x: f32): f32 {\n return builtin_sqrt(x);\n }\n\n export function tan(x: f32): f32 { // see: musl/src/math/tanf.c\n const\n t1pio2 = reinterpret(0x3FF921FB54442D18), // 1 * M_PI_2\n t2pio2 = reinterpret(0x400921FB54442D18), // 2 * M_PI_2\n t3pio2 = reinterpret(0x4012D97C7F3321D2), // 3 * M_PI_2\n t4pio2 = reinterpret(0x401921FB54442D18); // 4 * M_PI_2\n\n var ux = reinterpret(x);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3F490FDA) { // |x| ~<= π/4\n if (ux < 0x39800000) { // |x| < 2**-12\n return x;\n }\n return tan_kernf(x, 0);\n }\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (ux <= 0x407B53D1) { // |x| ~<= 5π/4\n if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4\n return tan_kernf((sign ? x + t1pio2 : x - t1pio2), 1);\n } else {\n return tan_kernf((sign ? x + t2pio2 : x - t2pio2), 0);\n }\n }\n if (ux <= 0x40E231D5) { // |x| ~<= 9π/4\n if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4\n return tan_kernf((sign ? x + t3pio2 : x - t3pio2), 1);\n } else {\n return tan_kernf((sign ? x + t4pio2 : x - t4pio2), 0);\n }\n }\n }\n\n // tan(Inf or NaN) is NaN\n if (ux >= 0x7F800000) return x - x;\n\n // argument reduction\n var n = rempio2f(x, ux, sign);\n var y = rempio2f_y;\n return tan_kernf(y, n & 1);\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 // @ts-ignore: decorator\n @inline\n export function trunc(x: f32): f32 {\n return builtin_trunc(x);\n }\n\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\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 if (builtin_abs(y) == 1.0) {\n // x % 1, x % -1 ==> sign(x) * abs(x - 1.0 * trunc(x / 1.0))\n // TODO: move this rule to compiler's optimization pass.\n // It could be apply for any x % C_pot, where \"C_pot\" is pow of two const.\n return builtin_copysign(x - builtin_trunc(x), x);\n }\n var ux = reinterpret(x);\n var uy = reinterpret(y);\n var ex = i32(ux >> 23 & 0xFF);\n var ey = i32(uy >> 23 & 0xFF);\n var sm = ux & 0x80000000;\n var uy1 = uy << 1;\n if (uy1 == 0 || ex == 0xFF || isNaN(y)) {\n let m = x * y;\n return m / m;\n }\n var ux1 = ux << 1;\n if (ux1 <= uy1) {\n return x * f32(ux1 != uy1);\n }\n if (!ex) {\n ex -= builtin_clz(ux << 9);\n ux <<= 1 - ex;\n } else {\n ux &= -1 >> 9;\n ux |= 1 << 23;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 9);\n uy <<= 1 - ey;\n } else {\n uy &= u32(-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 return reinterpret(ux | sm);\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 = i32(ux >> 23 & 0xFF);\n var ey = i32(uy >> 23 & 0xFF);\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 <<= 1 - ex;\n } else {\n uxi &= u32(-1) >> 9;\n uxi |= 1 << 23;\n }\n if (!ey) {\n ey -= builtin_clz(uy << 9);\n uy <<= 1 - ey;\n } else {\n uy &= u32(-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 && bool(q & 1))))) {\n x -= y;\n // q++;\n }\n return ux < 0 ? -x : x;\n }\n\n export function sincos(x: f32): void { // see: musl/tree/src/math/sincosf.c\n const\n s1pio2 = reinterpret(0x3FF921FB54442D18), // 1 * M_PI_2\n s2pio2 = reinterpret(0x400921FB54442D18), // 2 * M_PI_2\n s3pio2 = reinterpret(0x4012D97C7F3321D2), // 3 * M_PI_2\n s4pio2 = reinterpret(0x401921FB54442D18); // 4 * M_PI_2\n\n var ux = reinterpret(x);\n var sign = ux >> 31;\n ux &= 0x7FFFFFFF;\n\n if (ux <= 0x3F490FDA) { // |x| ~<= π/4\n if (ux < 0x39800000) { // |x| < 2**-12\n sincos_sin = x;\n sincos_cos = 1;\n return;\n }\n sincos_sin = sin_kernf(x);\n sincos_cos = cos_kernf(x);\n return;\n }\n if (ASC_SHRINK_LEVEL < 1) {\n if (ux <= 0x407B53D1) { // |x| ~<= 5π/4\n if (ux <= 0x4016CBE3) { // |x| ~<= 3π/4\n if (sign) {\n sincos_sin = -cos_kernf(x + s1pio2);\n sincos_cos = sin_kernf(x + s1pio2);\n } else {\n sincos_sin = cos_kernf(s1pio2 - x);\n sincos_cos = sin_kernf(s1pio2 - x);\n }\n return;\n }\n // -sin(x + c) is not correct if x+c could be 0: -0 vs +0\n sincos_sin = -sin_kernf(sign ? x + s2pio2 : x - s2pio2);\n sincos_cos = -cos_kernf(sign ? x + s2pio2 : x - s2pio2);\n return;\n }\n if (ux <= 0x40E231D5) { // |x| ~<= 9π/4\n if (ux <= 0x40AFEDDF) { // |x| ~<= 7π/4\n if (sign) {\n sincos_sin = cos_kernf(x + s3pio2);\n sincos_cos = -sin_kernf(x + s3pio2);\n } else {\n sincos_sin = -cos_kernf(x - s3pio2);\n sincos_cos = sin_kernf(x - s3pio2);\n }\n return;\n }\n sincos_sin = sin_kernf(sign ? x + s4pio2 : x - s4pio2);\n sincos_cos = cos_kernf(sign ? x + s4pio2 : x - s4pio2);\n return;\n }\n }\n // sin(Inf or NaN) is NaN\n if (ux >= 0x7F800000) {\n let xx = x - x;\n sincos_sin = xx;\n sincos_cos = xx;\n return;\n }\n // general argument reduction needed\n var n = rempio2f(x, ux, sign);\n var y = rempio2f_y;\n var s = sin_kernf(y);\n var c = cos_kernf(y);\n var sin = s, cos = c;\n if (n & 1) {\n sin = c;\n cos = -s;\n }\n if (n & 2) {\n sin = -sin;\n cos = -cos;\n }\n sincos_sin = sin;\n sincos_cos = cos;\n }\n}\n\nexport function ipow32(x: i32, e: i32): i32 {\n var out = 1;\n if (ASC_SHRINK_LEVEL < 1) {\n if (x == 2) {\n return select(1 << e, 0, e < 32);\n }\n if (e <= 0) {\n if (x == -1) return select(-1, 1, e & 1);\n return i32(e == 0) | i32(x == 1);\n }\n else if (e == 1) return x;\n else if (e == 2) return x * x;\n else if (e < 32) {\n let log = 32 - clz(e);\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 while (e) {\n if (e & 1) out *= x;\n e >>>= 1;\n x *= x;\n }\n return out;\n}\n\nexport function ipow64(x: i64, e: i64): i64 {\n var out: i64 = 1;\n if (ASC_SHRINK_LEVEL < 1) {\n if (x == 2) {\n return select(1 << e, 0, e < 64);\n }\n if (e <= 0) {\n if (x == -1) return select(-1, 1, e & 1);\n return i64(e == 0) | i64(x == 1);\n }\n else if (e == 1) return x;\n else if (e == 2) return x * x;\n else if (e < 64) {\n let log = 64 - clz(e);\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 while (e) {\n if (e & 1) out *= x;\n e >>>= 1;\n x *= x;\n }\n return out;\n}\n\n/*\nTODO:\nIn compile time if only exponent is constant we could replace ipow32/ipow64 by shortest addition chains\nwhich usually faster than exponentiation by squaring\n\nfor ipow32 and e < 32:\n\nlet b: i32, c: i32, d: i32, h: i32, k: i32, g: i32;\nswitch (e) {\n case 1: return x;\n case 2: return x * x;\n case 3: return x * x * x;\n case 4: return (b = x * x) * b;\n case 5: return (b = x * x) * b * x;\n case 6: return (b = x * x) * b * b;\n case 7: return (b = x * x) * b * b * x;\n case 8: return (d = (b = x * x) * b) * d;\n case 9: return (c = x * x * x) * c * c;\n case 10: return (d = (b = x * x) * b) * d * b;\n case 11: return (d = (b = x * x) * b) * d * b * x;\n case 12: return (d = (b = x * x) * b) * d * d;\n case 13: return (d = (b = x * x) * b) * d * d * x;\n case 14: return (d = (b = x * x) * b) * d * d * b;\n case 15: return (k = (b = x * x) * b * x) * k * k;\n case 16: return (h = (d = (b = x * x) * b) * d) * h;\n case 17: return (h = (d = (b = x * x) * b) * d) * h * x;\n case 18: return (h = (d = (b = x * x) * b) * d * x) * h;\n case 19: return (h = (d = (b = x * x) * b) * d * x) * h * x;\n case 20: return (h = (k = (b = x * x) * b * x) * k) * h;\n case 21: return (h = (k = (b = x * x) * b * x) * k) * h * x;\n case 22: return (g = (h = (k = (b = x * x) * b * x) * k) * x) * g;\n case 23: return (h = (d = (c = (b = x * x) * x) * b) * d) * h * c;\n case 24: return (h = (d = (c = x * x * x) * c) * d) * h;\n case 25: return (h = (d = (c = x * x * x) * c) * d) * h * x;\n case 26: return (g = (h = (d = (c = x * x * x) * c) * d) * x) * g;\n case 27: return (h = (d = (c = x * x * x) * c) * d) * h * c;\n case 28: return (h = (d = (c = x * x * x) * c * x) * d) * h;\n case 29: return (h = (d = (c = x * x * x) * c * x) * d) * h * x;\n case 30: return (h = (d = (c = x * x * x) * c) * d * c) * h;\n case 31: return (h = (d = (c = x * x * x) * c) * d * c) * h * x;\n}\n\nfor ipow64: TODO\nswitch (e) {\n case 32:\n ...\n case 63:\n}\n*/\n","// This file is shared with the compiler and must remain portable\n\n/** Runtime types. */\nexport enum Runtime {\n /** Simple bump allocator without GC. */\n Stub = 0,\n /** Stop the world semi-automatic GC. */\n Minimal = 1,\n /** incremental GC. */\n Incremental = 2,\n}\n","import { compareImpl } from \"./string\";\n\ntype Comparator = (a: T, b: T) => i32;\n\n// @ts-ignore: decorator\n@lazy @inline const EMPTY = u32.MAX_VALUE;\n// @ts-ignore: decorator\n@inline const INSERTION_SORT_THRESHOLD = 48;\n// @ts-ignore: decorator\n@inline const MIN_RUN_LENGTH = 32;\n\n// @ts-ignore: decorator\n@inline\nfunction log2u(n: u32): u32 {\n return 31 - clz(n);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function COMPARATOR(): Comparator {\n if (isInteger()) {\n if (isSigned() && sizeof() <= 4) {\n return (a, b) => i32(a) - i32(b);\n } else {\n return (a, b) => i32(a > b) - i32(a < b);\n }\n } else if (isFloat()) {\n if (sizeof() == 4) {\n return (a, b) => {\n var ia = reinterpret(f32(a));\n var ib = reinterpret(f32(b));\n ia ^= ia >> 31 >>> 1;\n ib ^= ib >> 31 >>> 1;\n return i32(ia > ib) - i32(ia < ib);\n };\n } else {\n return (a, b) => {\n var ia = reinterpret(f64(a));\n var ib = reinterpret(f64(b));\n ia ^= ia >> 63 >>> 1;\n ib ^= ib >> 63 >>> 1;\n return i32(ia > ib) - i32(ia < ib);\n };\n }\n } else if (isString()) {\n return (a, b) => {\n if (\n changetype(a) == changetype(b) ||\n changetype(a) == 0 ||\n changetype(b) == 0\n ) return 0;\n var alen = changetype(a).length;\n var blen = changetype(b).length;\n if (!(alen | blen)) return 0;\n if (!alen) return -1;\n if (!blen) return 1;\n let res = compareImpl(\n changetype(a), 0,\n changetype(b), 0,\n min(alen, blen)\n );\n return res ? res : alen - blen;\n };\n } else {\n return (a, b) => i32(a > b) - i32(a < b);\n }\n}\n\n// Power Sort implementation (stable) from paper \"Nearly-Optimal Mergesorts\"\n// https://arxiv.org/pdf/1805.04154.pdf\n// This method usually outperform TimSort.\n// TODO: refactor c >>> 31 to c < 0 when binaryen will support this opt\nexport function SORT(\n ptr: usize,\n len: i32,\n comparator: Comparator\n): void {\n if (len <= INSERTION_SORT_THRESHOLD) {\n if (len <= 1) return;\n if (ASC_SHRINK_LEVEL < 1) {\n switch (len) {\n case 3: {\n let a = load(ptr, 0);\n let b = load(ptr, 1 << alignof());\n let c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 0);\n a = select(a, b, c);\n b = load(ptr, 2 << alignof());\n c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 1 << alignof());\n store(ptr, select(a, b, c), 2 << alignof());\n }\n case 2: {\n let a = load(ptr, 0);\n let b = load(ptr, 1 << alignof());\n let c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 0);\n store(ptr, select(a, b, c), 1 << alignof());\n return;\n }\n }\n }\n insertionSort(ptr, 0, len - 1, 0, comparator);\n return;\n }\n\n var lgPlus2 = log2u(len) + 2;\n var lgPlus2Size = lgPlus2 << alignof();\n var leftRunStartBuf = __alloc(lgPlus2Size << 1);\n var leftRunEndBuf = leftRunStartBuf + lgPlus2Size;\n\n for (let i: u32 = 0; i < lgPlus2; ++i) {\n store(leftRunStartBuf + (i << alignof()), EMPTY);\n }\n\n var buffer = __alloc(len << alignof());\n\n var hi = len - 1;\n var endA = extendRunRight(ptr, 0, hi, comparator);\n var lenA = endA + 1;\n\n if (lenA < MIN_RUN_LENGTH) {\n endA = min(hi, MIN_RUN_LENGTH - 1);\n insertionSort(ptr, 0, endA, lenA, comparator);\n }\n\n var top: u32 = 0, startA = 0;\n while (endA < hi) {\n let startB = endA + 1;\n let endB = extendRunRight(ptr, startB, hi, comparator);\n let lenB = endB - startB + 1;\n\n if (lenB < MIN_RUN_LENGTH) {\n endB = min(hi, startB + MIN_RUN_LENGTH - 1);\n insertionSort(ptr, startB, endB, lenB, comparator);\n }\n\n let k = nodePower(0, hi, startA, startB, endB);\n\n for (let i = top; i > k; --i) {\n let start = load(leftRunStartBuf + (i << alignof()));\n if (start != EMPTY) {\n mergeRuns(\n ptr,\n start,\n load(leftRunEndBuf + (i << alignof())) + 1,\n endA,\n buffer,\n comparator\n );\n startA = start;\n store(leftRunStartBuf + (i << alignof()), EMPTY);\n }\n }\n\n store(leftRunStartBuf + (k << alignof()), startA);\n store(leftRunEndBuf + (k << alignof()), endA);\n startA = startB;\n endA = endB;\n top = k;\n }\n\n for (let i = top; i != 0; --i) {\n let start = load(leftRunStartBuf + (i << alignof()));\n if (start != EMPTY) {\n mergeRuns(\n ptr,\n start,\n load(leftRunEndBuf + (i << alignof())) + 1,\n hi,\n buffer,\n comparator\n );\n }\n }\n // dealloc aux buffers\n __free(buffer);\n __free(leftRunStartBuf);\n}\n\nfunction insertionSort(\n ptr: usize,\n left: i32,\n right: i32,\n presorted: i32,\n comparator: Comparator\n): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n // slightly improved original insertion sort\n for (let i = left + presorted; i <= right; ++i) {\n let j = i - 1;\n let a = load(ptr + (i << alignof()));\n while (j >= left) {\n let b = load(ptr + (j << alignof()));\n if (comparator(a, b) < 0) {\n store(ptr + (j << alignof()), b, 1 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), a, 1 << alignof());\n }\n } else {\n // even-odd two-way insertion sort which allow increase minRunLen\n let range = right - left + 1;\n let i = left + select(range & 1, presorted - ((range - presorted) & 1), presorted == 0);\n for (; i <= right; i += 2) {\n let a = load(ptr + (i << alignof()), 0);\n let b = load(ptr + (i << alignof()), 1 << alignof());\n let min = b, max = a;\n if (comparator(a, b) <= 0) {\n min = a, max = b;\n }\n let j = i - 1;\n while (j >= left) {\n a = load(ptr + (j << alignof()));\n if (comparator(a, max) > 0) {\n store(ptr + (j << alignof()), a, 2 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), max, 2 << alignof());\n while (j >= left) {\n a = load(ptr + (j << alignof()));\n if (comparator(a, min) > 0) {\n store(ptr + (j << alignof()), a, 1 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), min, 1 << alignof());\n }\n }\n}\n\nfunction nodePower(left: u32, right: u32, startA: u32, startB: u32, endB: u32): u32 {\n var n: u64 = right - left + 1;\n var s = startB - (left << 1);\n var l = startA + s;\n var r = endB + s + 1;\n var a = (l << 30) / n;\n var b = (r << 30) / n;\n return clz((a ^ b));\n}\n\nfunction extendRunRight(\n ptr: usize,\n i: i32,\n right: i32,\n comparator: Comparator\n): i32 {\n if (i == right) return i;\n var j = i;\n if (comparator(\n load(ptr + ( j << alignof())),\n load(ptr + (++j << alignof()))\n ) > 0) {\n while (\n j < right &&\n (comparator(\n load(ptr + (j << alignof()), 1 << alignof()),\n load(ptr + (j << alignof()))\n ) >>> 31) // < 0\n ) ++j;\n // reverse\n let k = j;\n while (i < k) {\n let tmp = load(ptr + (i << alignof()));\n store(ptr + (i << alignof()), load(ptr + (k << alignof()))); ++i;\n store(ptr + (k << alignof()), tmp); --k;\n }\n } else {\n while (\n j < right &&\n comparator(\n load(ptr + (j << alignof()), 1 << alignof()),\n load(ptr + (j << alignof()))\n ) >= 0\n ) ++j;\n }\n return j;\n}\n\n// Merges arr[l..m - 1] and arr[m..r]\nfunction mergeRuns(\n ptr: usize,\n l: i32,\n m: i32,\n r: i32,\n buffer: usize,\n comparator: Comparator\n): void {\n --m;\n var i: i32, j: i32, t = r + m;\n for (i = m + 1; i > l; --i) {\n store(\n buffer + ((i - 1) << alignof()),\n load(ptr + ((i - 1) << alignof()))\n );\n }\n for (j = m; j < r; ++j) {\n store(\n buffer + ((t - j) << alignof()),\n load(ptr + (j << alignof()), 1 << alignof())\n );\n }\n for (let k = l; k <= r; ++k) {\n let a = load(buffer + (j << alignof()));\n let b = load(buffer + (i << alignof()));\n if (comparator(a, b) < 0) {\n store(ptr + (k << alignof()), a);\n --j;\n } else {\n store(ptr + (k << alignof()), b);\n ++i;\n }\n }\n}\n","/// \n\nimport { BLOCK_MAXSIZE } from \"./rt/common\";\nimport { Runtime } from \"shared/runtime\";\nimport { COMPARATOR, SORT } from \"./util/sort\";\nimport { REVERSE, FILL } from \"./util/bytes\";\nimport { joinBooleanArray, joinIntegerArray, joinFloatArray, joinStringArray, joinReferenceArray } from \"./util/string\";\nimport { idof, isArray as builtin_isArray } from \"./builtins\";\nimport { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_EMPTYARRAY, E_HOLEYARRAY } from \"./util/error\";\n\n// @ts-ignore: decorator\n@inline @lazy const MIN_SIZE: usize = 8;\n\n/** Ensures that the given array has _at least_ the specified backing size. */\nfunction ensureCapacity(array: usize, newSize: usize, alignLog2: u32, canGrow: bool = true): void {\n // Depends on the fact that Arrays mimic ArrayBufferView\n var oldCapacity = changetype(array).byteLength;\n if (newSize > oldCapacity >>> alignLog2) {\n if (newSize > BLOCK_MAXSIZE >>> alignLog2) throw new RangeError(E_INVALIDLENGTH);\n let oldData = changetype(changetype(array).buffer);\n // Grows old capacity by factor of two.\n // Make sure we don't reach BLOCK_MAXSIZE for new growed capacity.\n let newCapacity = max(newSize, MIN_SIZE) << alignLog2;\n if (canGrow) newCapacity = max(min(oldCapacity << 1, BLOCK_MAXSIZE), newCapacity);\n let newData = __renew(oldData, newCapacity);\n // __new / __renew already init memory range as zeros in Incremental runtime.\n // So try to avoid this.\n if (ASC_RUNTIME != Runtime.Incremental) {\n memory.fill(newData + oldCapacity, 0, newCapacity - oldCapacity);\n }\n if (newData != oldData) { // oldData has been free'd\n store(array, newData, offsetof(\"buffer\"));\n store(array, newData, offsetof(\"dataStart\"));\n __link(array, changetype(newData), false);\n }\n store(array, newCapacity, offsetof(\"byteLength\"));\n }\n}\n\nexport class Array {\n [key: number]: T;\n\n // Mimicking ArrayBufferView isn't strictly necessary here but is done to allow glue code\n // to work with typed and normal arrays interchangeably. Technically, normal arrays do not need\n // `dataStart` (equals `buffer`) and `byteLength` (equals computed `buffer.byteLength`), but the\n // block is 16 bytes anyway so it's fine to have a couple extra fields in there.\n\n private buffer: ArrayBuffer;\n @unsafe readonly dataStart: usize;\n private byteLength: i32; // Uses here as capacity\n\n // Also note that Array with non-nullable T must guard against uninitialized null values\n // whenever an element is accessed. Otherwise, the compiler wouldn't be able to guarantee\n // type-safety anymore. For lack of a better word, such an array is \"holey\".\n\n private length_: i32;\n\n static isArray(value: U): bool {\n return isReference() ? changetype(value) != 0 && builtin_isArray(value) : false;\n }\n\n static create(capacity: i32 = 0): Array {\n WARNING(\"'Array.create' is deprecated. Use 'new Array' instead, making sure initial elements are initialized.\");\n var array = new Array(capacity);\n array.length = 0;\n return array;\n }\n\n constructor(length: i32 = 0) {\n if (length > BLOCK_MAXSIZE >>> alignof()) throw new RangeError(E_INVALIDLENGTH);\n // reserve capacity for at least MIN_SIZE elements\n var bufferSize = max(length, MIN_SIZE) << alignof();\n var buffer = changetype(__new(bufferSize, idof()));\n if (ASC_RUNTIME != Runtime.Incremental) {\n memory.fill(changetype(buffer), 0, bufferSize);\n }\n this.buffer = buffer; // links\n this.dataStart = changetype(buffer);\n this.byteLength = bufferSize;\n this.length_ = length;\n }\n\n get length(): i32 {\n return this.length_;\n }\n\n set length(newLength: i32) {\n ensureCapacity(changetype(this), newLength, alignof(), false);\n this.length_ = newLength;\n }\n\n every(fn: (value: T, index: i32, array: Array) => bool): bool {\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n if (!fn(load(this.dataStart + (i << alignof())), i, this)) return false;\n }\n return true;\n }\n\n findIndex(fn: (value: T, index: i32, array: Array) => bool): i32 {\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n if (fn(load(this.dataStart + (i << alignof())), i, this)) return i;\n }\n return -1;\n }\n\n findLastIndex(fn: (value: T, index: i32, array: Array) => bool): i32 {\n for (let i = this.length_ - 1; i >= 0; --i) {\n if (fn(load(this.dataStart + (i << alignof())), i, this)) return i;\n }\n return -1;\n }\n\n @operator(\"[]\") private __get(index: i32): T {\n if (index >= this.length_) throw new RangeError(E_INDEXOUTOFRANGE);\n var value = load(this.dataStart + (index << alignof()));\n if (isReference()) {\n if (!isNullable()) {\n if (!changetype(value)) throw new Error(E_HOLEYARRAY);\n }\n }\n return value;\n }\n\n @unsafe @operator(\"{}\") private __uget(index: i32): T {\n return load(this.dataStart + (index << alignof()));\n }\n\n @operator(\"[]=\") private __set(index: i32, value: T): void {\n if (index >= this.length_) {\n if (index < 0) throw new RangeError(E_INDEXOUTOFRANGE);\n ensureCapacity(changetype(this), index + 1, alignof());\n this.length_ = index + 1;\n }\n this.__uset(index, value);\n }\n\n @unsafe @operator(\"{}=\") private __uset(index: i32, value: T): void {\n store(this.dataStart + (index << alignof()), value);\n if (isManaged()) {\n __link(changetype(this), changetype(value), true);\n }\n }\n\n at(index: i32): T {\n var len = this.length_;\n index += select(0, len, index >= 0);\n if (index >= len) throw new RangeError(E_INDEXOUTOFRANGE);\n var value = load(this.dataStart + (index << alignof()));\n if (isReference()) {\n if (!isNullable()) {\n if (!changetype(value)) throw new Error(E_HOLEYARRAY);\n }\n }\n return value;\n }\n\n fill(value: T, start: i32 = 0, end: i32 = i32.MAX_VALUE): Array {\n if (isManaged()) {\n FILL(this.dataStart, this.length_, changetype(value), start, end);\n __link(changetype(this), changetype(value), false);\n } else {\n FILL(this.dataStart, this.length_, value, start, end);\n }\n return this;\n }\n\n includes(value: T, fromIndex: i32 = 0): bool {\n if (isFloat()) {\n let len = this.length_;\n if (len == 0 || fromIndex >= len) return false;\n if (fromIndex < 0) fromIndex = max(len + fromIndex, 0);\n let ptr = this.dataStart;\n while (fromIndex < len) {\n let elem = load(ptr + (fromIndex << alignof()));\n // @ts-ignore\n if (elem == value || isNaN(elem) & isNaN(value)) return true;\n ++fromIndex;\n }\n return false;\n } else {\n return this.indexOf(value, fromIndex) >= 0;\n }\n }\n\n indexOf(value: T, fromIndex: i32 = 0): i32 {\n var len = this.length_;\n if (len == 0 || fromIndex >= len) return -1;\n if (fromIndex < 0) fromIndex = max(len + fromIndex, 0);\n var ptr = this.dataStart;\n while (fromIndex < len) {\n if (load(ptr + (fromIndex << alignof())) == value) return fromIndex;\n ++fromIndex;\n }\n return -1;\n }\n\n lastIndexOf(value: T, fromIndex: i32 = this.length_): i32 {\n var len = this.length_;\n if (len == 0) return -1;\n if (fromIndex < 0) fromIndex = len + fromIndex;\n else if (fromIndex >= len) fromIndex = len - 1;\n var ptr = this.dataStart;\n while (fromIndex >= 0) {\n if (load(ptr + (fromIndex << alignof())) == value) return fromIndex;\n --fromIndex;\n }\n return -1;\n }\n\n push(value: T): i32 {\n var oldLen = this.length_;\n var len = oldLen + 1;\n ensureCapacity(changetype(this), len, alignof());\n if (isManaged()) {\n store(this.dataStart + (oldLen << alignof()), changetype(value));\n __link(changetype(this), changetype(value), true);\n } else {\n store(this.dataStart + (oldLen << alignof()), value);\n }\n this.length_ = len;\n return len;\n }\n\n concat(other: Array): Array {\n var thisLen = this.length_;\n var otherLen = other.length_;\n var outLen = thisLen + otherLen;\n if (outLen > BLOCK_MAXSIZE >>> alignof()) throw new Error(E_INVALIDLENGTH);\n var out = changetype>(__newArray(outLen, alignof(), idof>()));\n var outStart = out.dataStart;\n var thisSize = thisLen << alignof();\n if (isManaged()) {\n let thisStart = this.dataStart;\n for (let offset: usize = 0; offset < thisSize; offset += sizeof()) {\n let ref = load(thisStart + offset);\n store(outStart + offset, ref);\n __link(changetype(out), ref, true);\n }\n outStart += thisSize;\n let otherStart = other.dataStart;\n let otherSize = otherLen << alignof();\n for (let offset: usize = 0; offset < otherSize; offset += sizeof()) {\n let ref = load(otherStart + offset);\n store(outStart + offset, ref);\n __link(changetype(out), ref, true);\n }\n } else {\n memory.copy(outStart, this.dataStart, thisSize);\n memory.copy(outStart + thisSize, other.dataStart, otherLen << alignof());\n }\n return out;\n }\n\n copyWithin(target: i32, start: i32, end: i32 = i32.MAX_VALUE): Array {\n var ptr = this.dataStart;\n var len = this.length_;\n\n end = min(end, len);\n\n var to = target < 0 ? max(len + target, 0) : min(target, len);\n var from = start < 0 ? max(len + start, 0) : min(start, len);\n var last = end < 0 ? max(len + end, 0) : min(end, len);\n var count = min(last - from, len - to);\n\n memory.copy( // is memmove\n ptr + (to << alignof()),\n ptr + (from << alignof()),\n count << alignof()\n );\n return this;\n }\n\n pop(): T {\n var len = this.length_;\n if (len < 1) throw new RangeError(E_EMPTYARRAY);\n var val = load(this.dataStart + ((--len) << alignof()));\n this.length_ = len;\n return val;\n }\n\n forEach(fn: (value: T, index: i32, array: Array) => void): void {\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n fn(load(this.dataStart + (i << alignof())), i, this);\n }\n }\n\n map(fn: (value: T, index: i32, array: Array) => U): Array {\n var len = this.length_;\n var out = changetype>(__newArray(len, alignof(), idof>()));\n var outStart = out.dataStart;\n for (let i = 0; i < min(len, this.length_); ++i) {\n let result = fn(load(this.dataStart + (i << alignof())), i, this);\n store(outStart + (i << alignof()), result);\n if (isManaged()) {\n __link(changetype(out), changetype(result), true);\n }\n }\n return out;\n }\n\n filter(fn: (value: T, index: i32, array: Array) => bool): Array {\n var result = changetype>(__newArray(0, alignof(), idof>()));\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n let value = load(this.dataStart + (i << alignof()));\n if (fn(value, i, this)) result.push(value);\n }\n return result;\n }\n\n reduce(\n fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var acc = initialValue;\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n acc = fn(acc, load(this.dataStart + (i << alignof())), i, this);\n }\n return acc;\n }\n\n reduceRight(\n fn: (previousValue: U, currentValue: T, currentIndex: i32, array: Array) => U,\n initialValue: U\n ): U {\n var acc = initialValue;\n for (let i = this.length_ - 1; i >= 0; --i) {\n acc = fn(acc, load(this.dataStart + (i << alignof())), i, this);\n }\n return acc;\n }\n\n shift(): T {\n var len = this.length_;\n if (len < 1) throw new RangeError(E_EMPTYARRAY);\n var base = this.dataStart;\n var element = load(base);\n var lastIndex = len - 1;\n memory.copy(\n base,\n base + sizeof(),\n lastIndex << alignof()\n );\n if (isReference()) {\n store(base + (lastIndex << alignof()), 0);\n } else {\n // @ts-ignore\n store(base + (lastIndex << alignof()), 0);\n }\n this.length_ = lastIndex;\n return element;\n }\n\n some(fn: (value: T, index: i32, array: Array) => bool): bool {\n for (let i = 0, len = this.length_; i < min(len, this.length_); ++i) {\n if (fn(load(this.dataStart + (i << alignof())), i, this)) return true;\n }\n return false;\n }\n\n unshift(value: T): i32 {\n var len = this.length_ + 1;\n ensureCapacity(changetype(this), len, alignof());\n var ptr = this.dataStart;\n memory.copy(\n ptr + sizeof(),\n ptr,\n (len - 1) << alignof()\n );\n store(ptr, value);\n if (isManaged()) {\n __link(changetype(this), changetype(value), true);\n }\n this.length_ = len;\n return len;\n }\n\n slice(start: i32 = 0, end: i32 = i32.MAX_VALUE): Array {\n var len = this.length_;\n start = start < 0 ? max(start + len, 0) : min(start, len);\n end = end < 0 ? max(end + len, 0) : min(end , len);\n len = max(end - start, 0);\n var slice = changetype>(__newArray(len, alignof(), idof>()));\n var sliceBase = slice.dataStart;\n var thisBase = this.dataStart + (start << alignof());\n if (isManaged()) {\n let off = 0;\n let end = len << alignof();\n while (off < end) {\n let ref = load(thisBase + off);\n store(sliceBase + off, ref);\n __link(changetype(slice), ref, true);\n off += sizeof();\n }\n } else {\n memory.copy(sliceBase, thisBase, len << alignof());\n }\n return slice;\n }\n\n splice(start: i32, deleteCount: i32 = i32.MAX_VALUE): Array {\n var len = this.length_;\n start = start < 0 ? max(len + start, 0) : min(start, len);\n deleteCount = max(min(deleteCount, len - start), 0);\n var result = changetype>(__newArray(deleteCount, alignof(), idof>()));\n var resultStart = result.dataStart;\n var thisStart = this.dataStart;\n var thisBase = thisStart + (start << alignof());\n memory.copy(\n resultStart,\n thisBase,\n deleteCount << alignof()\n );\n var offset = start + deleteCount;\n if (len != offset) {\n memory.copy(\n thisBase,\n thisStart + (offset << alignof()),\n (len - offset) << alignof()\n );\n }\n this.length_ = len - deleteCount;\n return result;\n }\n\n reverse(): Array {\n REVERSE(this.dataStart, this.length_);\n return this;\n }\n\n sort(comparator: (a: T, b: T) => i32 = COMPARATOR()): Array {\n SORT(this.dataStart, this.length_, comparator);\n return this;\n }\n\n join(separator: string = \",\"): string {\n var ptr = this.dataStart;\n var len = this.length_;\n if (isBoolean()) return joinBooleanArray(ptr, len, separator);\n if (isInteger()) return joinIntegerArray(ptr, len, separator);\n if (isFloat()) return joinFloatArray(ptr, len, separator);\n\n if (ASC_SHRINK_LEVEL < 1) {\n if (isString()) return joinStringArray(ptr, len, separator);\n }\n // For rest objects and arrays use general join routine\n if (isReference()) return joinReferenceArray(ptr, len, separator);\n ERROR(\"unspported element type\");\n return unreachable();\n }\n\n flat(): T {\n if (!isArray()) {\n ERROR(\"Cannot call flat() on Array where T is not an Array.\");\n }\n // Get the length and data start values\n var ptr = this.dataStart;\n var len = this.length_;\n\n // calculate the end size with an initial pass\n var size = 0;\n for (let i = 0; i < len; ++i) {\n let child = load(ptr + (i << alignof()));\n size += child == 0 ? 0 : load(child, offsetof(\"length_\"));\n }\n\n // calculate the byteLength of the resulting backing ArrayBuffer\n const align = alignof>();\n var byteLength = size << align;\n var outBuffer = changetype(__new(byteLength, idof()));\n\n // create the return value and initialize it\n var outArray = changetype(__new(offsetof(), idof()));\n store(changetype(outArray), size, offsetof(\"length_\"));\n\n // byteLength, dataStart, and buffer are all readonly\n store(changetype(outArray), byteLength, offsetof(\"byteLength\"));\n store(changetype(outArray), changetype(outBuffer), offsetof(\"dataStart\"));\n store(changetype(outArray), changetype(outBuffer), offsetof(\"buffer\"));\n __link(changetype(outArray), changetype(outBuffer), false);\n\n // set the elements\n var resultOffset: usize = 0;\n for (let i = 0; i < len; ++i) { // for each child\n let child = load(ptr + (i << alignof()));\n\n // ignore null arrays\n if (!child) continue;\n\n // copy the underlying buffer data to the result buffer\n let childDataLength = load(child, offsetof(\"length_\")) << align;\n memory.copy(\n changetype(outBuffer) + resultOffset,\n load(child, offsetof(\"dataStart\")),\n childDataLength\n );\n\n // advance the result length\n resultOffset += childDataLength;\n }\n\n // if the `valueof` type is managed, we must link each reference\n if (isManaged>()) {\n for (let i = 0; i < size; ++i) {\n let ref = load(changetype(outBuffer) + (i << usize(alignof>())));\n __link(changetype(outBuffer), ref, true);\n }\n }\n\n return outArray;\n }\n\n toString(): string {\n return this.join();\n }\n\n // RT integration\n\n @unsafe private __visit(cookie: u32): void {\n if (isManaged()) {\n let cur = this.dataStart;\n let end = cur + (this.length_ << alignof());\n while (cur < end) {\n let val = load(cur);\n if (val) __visit(val, cookie);\n cur += sizeof();\n }\n }\n __visit(changetype(this.buffer), cookie);\n }\n}\n","// Common error messages for use across the standard library. Keeping error messages compact\n// and reusing them where possible ensures minimal static data in binaries.\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INDEXOUTOFRANGE: string = \"Index out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_VALUEOUTOFRANGE: string = \"Value out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDLENGTH: string = \"Invalid length\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_EMPTYARRAY: string = \"Array is empty\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_HOLEYARRAY: string = \"Element type must be nullable if array is holey\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOTIMPLEMENTED: string = \"Not implemented\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_KEYNOTFOUND: string = \"Key does not exist\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_ALLOCATION_TOO_LARGE: string = \"Allocation too large\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_ALREADY_PINNED: string = \"Object already pinned\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOT_PINNED: string = \"Object is not pinned\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_URI_MALFORMED: string = \"URI malformed\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDDATE: string = \"Invalid Date\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_UNPAIRED_SURROGATE: string = \"Unpaired surrogate\";\n"]} \ No newline at end of file From d68d635f0d9c69a7a978c01ad11b01e58ea511e9 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 23 Feb 2024 17:26:35 +0000 Subject: [PATCH 4/8] chore: update lockfiles --- e2e/pnpm-lock.yaml | 10 ++--- examples/minimal/pnpm-lock.yaml | 52 ++++++++++++++--------- examples/multiple-accounts/pnpm-lock.yaml | 38 +++++++++++------ 3 files changed, 62 insertions(+), 38 deletions(-) diff --git a/e2e/pnpm-lock.yaml b/e2e/pnpm-lock.yaml index 5f0ff0d145..cce221a655 100644 --- a/e2e/pnpm-lock.yaml +++ b/e2e/pnpm-lock.yaml @@ -112,8 +112,8 @@ importers: specifier: https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1 version: github.com/foundry-rs/forge-std/74cfb77e308dd188d2f58864aaf44963ae6b88b1 prettier: - specifier: ^2.6.2 - version: 2.6.2 + specifier: 3.2.5 + version: 3.2.5 rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -1531,9 +1531,9 @@ packages: resolution: {integrity: sha512-+JD93VELV9gHkqpV5gdL5/70HdGtEw4/XE1S4BC8f1mcPmdib3K5XsKVbnR1XcAyC41zOnifJ+9YRKxdIsXiUw==} dev: true - /prettier@2.6.2: - resolution: {integrity: sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==} - engines: {node: '>=10.13.0'} + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} hasBin: true dev: true diff --git a/examples/minimal/pnpm-lock.yaml b/examples/minimal/pnpm-lock.yaml index 932aaf3a72..f14ec12a18 100644 --- a/examples/minimal/pnpm-lock.yaml +++ b/examples/minimal/pnpm-lock.yaml @@ -339,11 +339,11 @@ importers: specifier: https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1 version: github.com/foundry-rs/forge-std/74cfb77e308dd188d2f58864aaf44963ae6b88b1 prettier: - specifier: ^2.6.2 - version: 2.6.2 + specifier: 3.2.5 + version: 3.2.5 prettier-plugin-solidity: - specifier: 1.1.3 - version: 1.1.3(prettier@2.6.2) + specifier: 1.3.1 + version: 1.3.1(prettier@3.2.5) rimraf: specifier: ^3.0.2 version: 3.0.2 @@ -1032,6 +1032,10 @@ packages: antlr4ts: 0.5.0-alpha.4 dev: true + /@solidity-parser/parser@0.17.0: + resolution: {integrity: sha512-Nko8R0/kUo391jsEHHxrGM07QFdnPGvlmox4rmH0kNiNAashItAilhy4Mv4pK5gQmW5f4sXAF58fwJbmlkGcVw==} + dev: true + /@solidstate/contracts@0.0.52: resolution: {integrity: sha512-xSBn5oLnfYtgNYrsRq/COlWHt0NxK26PFQ3FvI2DDMAFpZKFsffGLzUl8umezj2gVKpN7EZ+EVLdPKjqx6eUOw==} dev: true @@ -2885,22 +2889,16 @@ packages: engines: {node: '>= 0.8.0'} dev: true - /prettier-plugin-solidity@1.1.3(prettier@2.6.2): - resolution: {integrity: sha512-fQ9yucPi2sBbA2U2Xjh6m4isUTJ7S7QLc/XDDsktqqxYfTwdYKJ0EnnywXHwCGAaYbQNK+HIYPL1OemxuMsgeg==} - engines: {node: '>=12'} + /prettier-plugin-solidity@1.3.1(prettier@3.2.5): + resolution: {integrity: sha512-MN4OP5I2gHAzHZG1wcuJl0FsLS3c4Cc5494bbg+6oQWBPuEamjwDvmGfFMZ6NFzsh3Efd9UUxeT7ImgjNH4ozA==} + engines: {node: '>=16'} peerDependencies: - prettier: '>=2.3.0 || >=3.0.0-alpha.0' + prettier: '>=2.3.0' dependencies: - '@solidity-parser/parser': 0.16.0 - prettier: 2.6.2 - semver: 7.5.0 - solidity-comments-extractor: 0.0.7 - dev: true - - /prettier@2.6.2: - resolution: {integrity: sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==} - engines: {node: '>=10.13.0'} - hasBin: true + '@solidity-parser/parser': 0.17.0 + prettier: 3.2.5 + semver: 7.6.0 + solidity-comments-extractor: 0.0.8 dev: true /prettier@2.8.8: @@ -2911,6 +2909,12 @@ packages: dev: true optional: true + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} + hasBin: true + dev: true + /prop-types@15.8.1: resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==} dependencies: @@ -3096,6 +3100,14 @@ packages: lru-cache: 6.0.0 dev: true + /semver@7.6.0: + resolution: {integrity: sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==} + engines: {node: '>=10'} + hasBin: true + dependencies: + lru-cache: 6.0.0 + dev: true + /shallowequal@1.1.0: resolution: {integrity: sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==} dev: false @@ -3167,8 +3179,8 @@ packages: prettier: 2.8.8 dev: true - /solidity-comments-extractor@0.0.7: - resolution: {integrity: sha512-wciNMLg/Irp8OKGrh3S2tfvZiZ0NEyILfcRCXCD4mp7SgK/i9gzLfhY2hY7VMCQJ3kH9UB9BzNdibIVMchzyYw==} + /solidity-comments-extractor@0.0.8: + resolution: {integrity: sha512-htM7Vn6LhHreR+EglVMd2s+sZhcXAirB1Zlyrv5zBuTxieCvjfnRpd7iZk75m/u6NOlEyQ94C6TWbBn2cY7w8g==} dev: true /source-map-js@1.0.2: diff --git a/examples/multiple-accounts/pnpm-lock.yaml b/examples/multiple-accounts/pnpm-lock.yaml index 7015942044..275ffd4f07 100644 --- a/examples/multiple-accounts/pnpm-lock.yaml +++ b/examples/multiple-accounts/pnpm-lock.yaml @@ -128,11 +128,11 @@ importers: specifier: https://github.com/foundry-rs/forge-std.git#74cfb77e308dd188d2f58864aaf44963ae6b88b1 version: github.com/foundry-rs/forge-std/74cfb77e308dd188d2f58864aaf44963ae6b88b1 prettier: - specifier: ^2.6.2 - version: 2.8.8 + specifier: 3.2.5 + version: 3.2.5 prettier-plugin-solidity: - specifier: 1.1.3 - version: 1.1.3(prettier@2.8.8) + specifier: 1.3.1 + version: 1.3.1(prettier@3.2.5) solhint: specifier: ^3.3.7 version: 3.6.2(typescript@5.1.6) @@ -700,6 +700,10 @@ packages: antlr4ts: 0.5.0-alpha.4 dev: true + /@solidity-parser/parser@0.17.0: + resolution: {integrity: sha512-Nko8R0/kUo391jsEHHxrGM07QFdnPGvlmox4rmH0kNiNAashItAilhy4Mv4pK5gQmW5f4sXAF58fwJbmlkGcVw==} + dev: true + /@types/debug@4.1.7: resolution: {integrity: sha512-9AonUzyTjXXhEOa0DnqpzZi6VHlqKMswga9EXjpXnnqxwLtdvPPtlO8evrI5D9S6asFRCQ6v+wpiUKbw+vKqyg==} dependencies: @@ -2285,22 +2289,30 @@ packages: engines: {node: '>= 0.8.0'} dev: true - /prettier-plugin-solidity@1.1.3(prettier@2.8.8): - resolution: {integrity: sha512-fQ9yucPi2sBbA2U2Xjh6m4isUTJ7S7QLc/XDDsktqqxYfTwdYKJ0EnnywXHwCGAaYbQNK+HIYPL1OemxuMsgeg==} - engines: {node: '>=12'} + /prettier-plugin-solidity@1.3.1(prettier@3.2.5): + resolution: {integrity: sha512-MN4OP5I2gHAzHZG1wcuJl0FsLS3c4Cc5494bbg+6oQWBPuEamjwDvmGfFMZ6NFzsh3Efd9UUxeT7ImgjNH4ozA==} + engines: {node: '>=16'} peerDependencies: - prettier: '>=2.3.0 || >=3.0.0-alpha.0' + prettier: '>=2.3.0' dependencies: - '@solidity-parser/parser': 0.16.2 - prettier: 2.8.8 + '@solidity-parser/parser': 0.17.0 + prettier: 3.2.5 semver: 7.5.4 - solidity-comments-extractor: 0.0.7 + solidity-comments-extractor: 0.0.8 dev: true /prettier@2.8.8: resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} engines: {node: '>=10.13.0'} hasBin: true + requiresBuild: true + dev: true + optional: true + + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} + hasBin: true dev: true /prop-types@15.8.1: @@ -2539,8 +2551,8 @@ packages: - typescript dev: true - /solidity-comments-extractor@0.0.7: - resolution: {integrity: sha512-wciNMLg/Irp8OKGrh3S2tfvZiZ0NEyILfcRCXCD4mp7SgK/i9gzLfhY2hY7VMCQJ3kH9UB9BzNdibIVMchzyYw==} + /solidity-comments-extractor@0.0.8: + resolution: {integrity: sha512-htM7Vn6LhHreR+EglVMd2s+sZhcXAirB1Zlyrv5zBuTxieCvjfnRpd7iZk75m/u6NOlEyQ94C6TWbBn2cY7w8g==} dev: true /source-map-js@1.0.2: From 3808ad5df2d79bd563aa5a24ac252e797a99ffe1 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 23 Feb 2024 17:37:59 +0000 Subject: [PATCH 5/8] chore: remove @types/prettier --- examples/multiple-accounts/package.json | 1 - examples/multiple-accounts/pnpm-lock.yaml | 7 ------- pnpm-lock.yaml | 6 +++--- templates/phaser/package.json | 1 - templates/react-ecs/package.json | 1 - templates/react/package.json | 1 - templates/threejs/package.json | 1 - templates/vanilla/package.json | 1 - 8 files changed, 3 insertions(+), 16 deletions(-) diff --git a/examples/multiple-accounts/package.json b/examples/multiple-accounts/package.json index 16893bf7de..9e94423c4d 100644 --- a/examples/multiple-accounts/package.json +++ b/examples/multiple-accounts/package.json @@ -14,7 +14,6 @@ "devDependencies": { "@latticexyz/cli": "link:../../packages/cli", "@types/debug": "4.1.7", - "@types/prettier": "2.7.2", "@typescript-eslint/eslint-plugin": "5.46.1", "@typescript-eslint/parser": "5.46.1", "eslint": "8.29.0", diff --git a/examples/multiple-accounts/pnpm-lock.yaml b/examples/multiple-accounts/pnpm-lock.yaml index 275ffd4f07..878afde32c 100644 --- a/examples/multiple-accounts/pnpm-lock.yaml +++ b/examples/multiple-accounts/pnpm-lock.yaml @@ -14,9 +14,6 @@ importers: '@types/debug': specifier: 4.1.7 version: 4.1.7 - '@types/prettier': - specifier: 2.7.2 - version: 2.7.2 '@typescript-eslint/eslint-plugin': specifier: 5.46.1 version: 5.46.1(@typescript-eslint/parser@5.46.1)(eslint@8.29.0)(typescript@5.1.6) @@ -724,10 +721,6 @@ packages: undici-types: 5.26.5 dev: true - /@types/prettier@2.7.2: - resolution: {integrity: sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==} - dev: true - /@types/prop-types@15.7.11: resolution: {integrity: sha512-ga8y9v9uyeiLdpKddhxYQkxNDrfvuPrlFb0N1qnZZByvcElJaXthF1UhvCh9TLWJBEHeNtdnbysW7Y6Uq8CVng==} dev: true diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ce0f90e916..6779b8a416 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3650,8 +3650,8 @@ packages: '@types/node': 18.15.11 dev: true - /@types/prettier@2.7.2: - resolution: {integrity: sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==} + /@types/prettier@2.7.3: + resolution: {integrity: sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==} dev: true /@types/prop-types@15.7.5: @@ -8086,7 +8086,7 @@ packages: '@jest/transform': 29.5.0 '@jest/types': 29.5.0 '@types/babel__traverse': 7.18.3 - '@types/prettier': 2.7.2 + '@types/prettier': 2.7.3 babel-preset-current-node-syntax: 1.0.1(@babel/core@7.21.4) chalk: 4.1.2 expect: 29.5.0 diff --git a/templates/phaser/package.json b/templates/phaser/package.json index bef09b4664..f50980f9a7 100644 --- a/templates/phaser/package.json +++ b/templates/phaser/package.json @@ -14,7 +14,6 @@ "devDependencies": { "@latticexyz/cli": "link:../../packages/cli", "@types/debug": "4.1.7", - "@types/prettier": "2.7.2", "@typescript-eslint/eslint-plugin": "5.46.1", "@typescript-eslint/parser": "5.46.1", "eslint": "8.29.0", diff --git a/templates/react-ecs/package.json b/templates/react-ecs/package.json index 80edea1359..58440578e0 100644 --- a/templates/react-ecs/package.json +++ b/templates/react-ecs/package.json @@ -14,7 +14,6 @@ "devDependencies": { "@latticexyz/cli": "link:../../packages/cli", "@types/debug": "4.1.7", - "@types/prettier": "2.7.2", "@typescript-eslint/eslint-plugin": "5.46.1", "@typescript-eslint/parser": "5.46.1", "eslint": "8.29.0", diff --git a/templates/react/package.json b/templates/react/package.json index 16893bf7de..9e94423c4d 100644 --- a/templates/react/package.json +++ b/templates/react/package.json @@ -14,7 +14,6 @@ "devDependencies": { "@latticexyz/cli": "link:../../packages/cli", "@types/debug": "4.1.7", - "@types/prettier": "2.7.2", "@typescript-eslint/eslint-plugin": "5.46.1", "@typescript-eslint/parser": "5.46.1", "eslint": "8.29.0", diff --git a/templates/threejs/package.json b/templates/threejs/package.json index 0faad70ae7..010dc5af8a 100644 --- a/templates/threejs/package.json +++ b/templates/threejs/package.json @@ -14,7 +14,6 @@ "devDependencies": { "@latticexyz/cli": "link:../../packages/cli", "@types/debug": "4.1.7", - "@types/prettier": "2.7.2", "@typescript-eslint/eslint-plugin": "5.46.1", "@typescript-eslint/parser": "5.46.1", "eslint": "8.29.0", diff --git a/templates/vanilla/package.json b/templates/vanilla/package.json index d3affb9b3e..6d8b2d9f34 100644 --- a/templates/vanilla/package.json +++ b/templates/vanilla/package.json @@ -14,7 +14,6 @@ "devDependencies": { "@latticexyz/cli": "link:../../packages/cli", "@types/debug": "4.1.7", - "@types/prettier": "2.7.2", "@typescript-eslint/eslint-plugin": "5.46.1", "@typescript-eslint/parser": "5.46.1", "eslint": "8.29.0", From d6635d684d19cd62f418e98c1a1a52d23e55d587 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 23 Feb 2024 17:46:59 +0000 Subject: [PATCH 6/8] chore: expand changeset --- .changeset/loud-rockets-switch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/loud-rockets-switch.md b/.changeset/loud-rockets-switch.md index f48556604b..2e80de7d69 100644 --- a/.changeset/loud-rockets-switch.md +++ b/.changeset/loud-rockets-switch.md @@ -2,4 +2,4 @@ "@latticexyz/common": patch --- -Pinned prettier-plugin-solidity version to 1.3.1 +Upgraded prettier version to 3.2.5 and prettier-plugin-solidity version to 1.3.1. From 9e52a77bd1d163f56821d5e2cf3453b42f7ec07a Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Thu, 29 Feb 2024 11:34:39 +0000 Subject: [PATCH 7/8] chore: prettier --- .changeset/nasty-waves-divide.md | 4 +- .changeset/tame-lemons-play.md | 2 +- CHANGELOG.md | 6 +- docs/app/page.tsx | 2 +- docs/components/MUDTable.module.css | 10 +- docs/pages/changelog.mdx | 6 +- .../emojimon/3-players-and-movement.mdx | 2 +- .../guides/emojimon/4-map-and-terrain.mdx | 2 +- .../emojimon/5-a-wild-emojimon-appears.mdx | 4 +- docs/pages/guides/hello-world/add-table.mdx | 2 +- docs/pages/store/reference/misc.mdx | 84 +++++++++++++++ docs/src/tailwindcss-plugins/animate.ts | 14 +-- e2e/packages/client-vanilla/src/index.ts | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../sync-test/compare/compare.test.ts | 4 +- .../sync-test/data/callPageFunction.ts | 2 +- e2e/packages/sync-test/data/callWorld.ts | 2 +- e2e/packages/sync-test/data/types.ts | 7 +- e2e/packages/sync-test/indexerSync.test.ts | 2 +- .../setup/openClientWithRootAccount.ts | 2 +- .../sync-test/setup/startBrowserAndPage.ts | 2 +- .../test-data/generate-bench-data-bulk.ts | 2 +- .../test-data/generate-bench-data-query.ts | 2 +- e2e/packages/test-data/generateLogs.ts | 4 +- .../src/mud/createSystemCalls.ts | 2 +- .../packages/client-phaser/src/ui/App.tsx | 2 +- .../src/ui/hooks/usePhaserLayer.tsx | 2 +- .../packages/client-react/src/index.tsx | 2 +- .../client-react/src/mud/createSystemCalls.ts | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../packages/client/src/index.tsx | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- packages/abi-ts/src/abi-ts.ts | 2 +- packages/block-logs-stream/CHANGELOG.md | 4 +- packages/block-logs-stream/README.md | 2 +- .../src/blockRangeToLogs.test.ts | 2 +- .../block-logs-stream/src/blockRangeToLogs.ts | 6 +- .../block-logs-stream/src/fetchLogs.test.ts | 4 +- .../src/groupLogsByBlockNumber.ts | 2 +- packages/cli/CHANGELOG.md | 2 +- packages/cli/src/commands/dev-contracts.ts | 2 +- packages/cli/src/commands/set-version.ts | 2 +- packages/cli/src/commands/trace.ts | 2 +- packages/cli/src/deploy/configToTables.ts | 6 +- packages/cli/src/deploy/deployWorld.ts | 2 +- packages/cli/src/deploy/ensureContract.ts | 6 +- packages/cli/src/deploy/ensureDeployer.ts | 8 +- packages/cli/src/deploy/ensureFunctions.ts | 8 +- packages/cli/src/deploy/ensureModules.ts | 6 +- .../cli/src/deploy/ensureNamespaceOwner.ts | 8 +- packages/cli/src/deploy/ensureSystems.ts | 36 +++---- packages/cli/src/deploy/ensureTables.ts | 6 +- packages/cli/src/deploy/ensureWorldFactory.ts | 2 +- packages/cli/src/deploy/getFunctions.ts | 2 +- packages/cli/src/deploy/getResourceAccess.ts | 4 +- packages/cli/src/deploy/getSystems.ts | 2 +- packages/cli/src/deploy/getTables.ts | 2 +- packages/cli/src/deploy/logsToWorldDeploy.ts | 2 +- packages/cli/src/deploy/resolveConfig.ts | 10 +- packages/cli/src/mud.ts | 2 +- packages/cli/src/runDeploy.ts | 8 +- packages/cli/src/utils/printMUD.ts | 2 +- .../cli/src/utils/utils/getContractData.ts | 2 +- packages/cli/src/utils/utils/postDeploy.ts | 4 +- packages/cli/tsup.config.ts | 2 +- packages/common/CHANGELOG.md | 2 +- .../codegen/render-solidity/common.test.ts | 20 ++-- .../src/codegen/render-solidity/common.ts | 14 +-- .../codegen/render-solidity/renderEnums.ts | 2 +- .../render-solidity/renderTypeHelpers.ts | 4 +- .../src/codegen/utils/contractToInterface.ts | 2 +- .../src/codegen/utils/extractUserTypes.ts | 2 +- .../src/codegen/utils/formatAndWrite.ts | 2 +- .../src/codegen/utils/loadUserTypesFile.ts | 6 +- packages/common/src/foundry/index.ts | 2 +- packages/common/src/getContract.ts | 8 +- packages/common/src/hexToResource.ts | 2 +- packages/common/src/sendTransaction.ts | 8 +- packages/common/src/utils/groupBy.ts | 2 +- packages/common/src/utils/mapObject.ts | 4 +- packages/common/src/writeContract.ts | 8 +- .../config/src/library/dynamicResolution.ts | 2 +- packages/create-mud/CHANGELOG.md | 2 +- packages/dev-tools/src/App.tsx | 4 +- .../dev-tools/src/actions/WriteSummary.tsx | 6 +- .../dev-tools/src/actions/getTransaction.ts | 2 +- .../src/actions/getTransactionReceipt.ts | 2 +- .../src/actions/getTransactionResult.ts | 2 +- packages/dev-tools/src/mount.tsx | 4 +- .../dev-tools/src/recs/ComponentDataTable.tsx | 4 +- .../dev-tools/src/recs/ComponentsPage.tsx | 2 +- packages/dev-tools/src/router.tsx | 4 +- .../dev-tools/src/summary/SummaryPage.tsx | 2 +- packages/dev-tools/src/zustand/TablesPage.tsx | 2 +- packages/dev-tools/src/zustand/useRecords.ts | 2 +- packages/faucet/bin/parseEnv.ts | 2 +- packages/faucet/src/createAppRouter.ts | 2 +- packages/gas-report/ts/gas-report.ts | 2 +- packages/phaserx/src/createCamera.ts | 6 +- packages/phaserx/src/createChunks.ts | 6 +- packages/phaserx/src/createCulling.ts | 4 +- packages/phaserx/src/createDebugger.ts | 8 +- packages/phaserx/src/createEmbodiedEntity.ts | 8 +- packages/phaserx/src/createInput.ts | 26 ++--- packages/phaserx/src/createObjectPool.ts | 2 +- packages/phaserx/src/guards.ts | 8 +- .../src/tilemap/createAnimatedTilemap.ts | 2 +- .../src/tilemap/createChunkedTilemap.ts | 8 +- .../src/tilemap/createVirtualTilemap.ts | 2 +- packages/phaserx/src/types.ts | 4 +- packages/phaserx/src/utils/chunks.ts | 2 +- packages/phaserx/src/utils/coords.ts | 4 +- packages/phaserx/src/utils/generateFrames.ts | 2 +- .../src/decodeDynamicField.test.ts | 52 ++++----- .../protocol-parser/src/decodeDynamicField.ts | 2 +- packages/protocol-parser/src/decodeField.ts | 2 +- packages/protocol-parser/src/decodeKey.ts | 4 +- .../src/decodeKeyTuple.test.ts | 6 +- .../protocol-parser/src/decodeKeyTuple.ts | 4 +- .../protocol-parser/src/decodeRecord.test.ts | 2 +- packages/protocol-parser/src/decodeRecord.ts | 4 +- .../src/decodeStaticField.test.ts | 32 +++--- .../protocol-parser/src/decodeStaticField.ts | 2 +- packages/protocol-parser/src/decodeValue.ts | 2 +- .../protocol-parser/src/decodeValueArgs.ts | 4 +- packages/protocol-parser/src/encodeField.ts | 4 +- .../src/encodeKeyTuple.test.ts | 6 +- .../protocol-parser/src/encodeLengths.test.ts | 4 +- packages/protocol-parser/src/encodeLengths.ts | 2 +- .../protocol-parser/src/encodeRecord.test.ts | 2 +- packages/protocol-parser/src/encodeRecord.ts | 4 +- packages/protocol-parser/src/encodeValue.ts | 2 +- .../protocol-parser/src/encodeValueArgs.ts | 4 +- packages/protocol-parser/src/errors.ts | 8 +- .../src/hexToPackedCounter.test.ts | 6 +- .../protocol-parser/src/hexToSchema.test.ts | 4 +- packages/protocol-parser/src/hexToSchema.ts | 2 +- .../protocol-parser/src/schemaToHex.test.ts | 6 +- packages/react/src/useComponentValue.ts | 6 +- packages/react/src/useEntityQuery.test.ts | 4 +- packages/react/src/usePromise.ts | 2 +- packages/recs/CHANGELOG.md | 2 +- packages/recs/src/Component.ts | 34 +++--- packages/recs/src/Entity.ts | 2 +- packages/recs/src/Indexer.ts | 2 +- packages/recs/src/Query.spec.ts | 58 +++++----- packages/recs/src/Query.ts | 22 ++-- packages/recs/src/System.spec.ts | 8 +- packages/recs/src/System.ts | 14 +-- .../src/deprecated/createActionSystem.spec.ts | 2 +- .../recs/src/deprecated/createActionSystem.ts | 6 +- .../src/deprecated/defineActionComponent.ts | 2 +- .../src/deprecated/waitForActionCompletion.ts | 2 +- .../src/deprecated/waitForComponentValueIn.ts | 6 +- packages/recs/src/utils.ts | 4 +- .../src/typescript/arrayAbiTypes.ts | 2 +- .../mappings/AbiTypeToPrimitiveType.ts | 4 +- .../mappings/AbiTypeToSchemaType.ts | 2 +- .../deprecated/types/StaticAbiTypes.ts | 2 +- .../src/typescript/schemaAbiTypes.test.ts | 2 +- packages/schema-type/src/typescript/utils.ts | 35 +++--- .../services/protobuf/ts/faucet/faucet.ts | 38 +++---- .../services/ts/faucet/createFaucetService.ts | 2 +- .../src/rules/NoMsgSender.ts | 2 +- .../src/rules/SystemFileName.ts | 2 +- packages/store-indexer/CHANGELOG.md | 2 +- packages/store-indexer/bin/parseEnv.ts | 2 +- .../bin/postgres-decoded-indexer.ts | 13 +-- .../store-indexer/bin/postgres-frontend.ts | 6 +- .../store-indexer/bin/postgres-indexer.ts | 13 +-- packages/store-indexer/bin/sqlite-indexer.ts | 15 +-- .../src/koa-middleware/sentry.ts | 4 +- .../store-indexer/src/postgres/apiRoutes.ts | 4 +- .../src/postgres/deprecated/getLogs.ts | 12 +-- .../store-indexer/src/postgres/queryLogs.ts | 10 +- .../store-indexer/src/postgres/recordToLog.ts | 2 +- .../src/sqlite/getTablesWithRecords.ts | 6 +- packages/store-sync/src/common.ts | 2 +- packages/store-sync/src/createStoreSync.ts | 18 ++-- packages/store-sync/src/flattenSchema.ts | 2 +- packages/store-sync/src/getSnapshot.ts | 2 +- .../store-sync/src/indexer-client/input.ts | 2 +- .../store-sync/src/isTableRegistrationLog.ts | 2 +- packages/store-sync/src/logToTable.test.ts | 2 +- packages/store-sync/src/logToTable.ts | 2 +- .../src/postgres-decoded/buildTable.test.ts | 4 +- .../src/postgres-decoded/buildTable.ts | 4 +- .../createStorageAdapter.test.ts | 8 +- .../postgres-decoded/createStorageAdapter.ts | 10 +- .../src/postgres-decoded/getTables.ts | 8 +- .../src/postgres/createStorageAdapter.test.ts | 8 +- .../src/postgres/createStorageAdapter.ts | 12 +-- .../store-sync/src/postgres/setupTables.ts | 4 +- packages/store-sync/src/postgres/tables.ts | 2 +- packages/store-sync/src/recs/decodeEntity.ts | 6 +- .../src/recs/defineInternalComponents.ts | 4 +- packages/store-sync/src/recs/encodeEntity.ts | 6 +- .../store-sync/src/recs/getTableEntity.ts | 2 +- .../store-sync/src/recs/isStoreComponent.ts | 2 +- .../store-sync/src/recs/recsStorage.test.ts | 8 +- packages/store-sync/src/recs/recsStorage.ts | 12 +-- .../store-sync/src/recs/tableToComponent.ts | 4 +- .../store-sync/src/recs/tablesToComponents.ts | 2 +- packages/store-sync/src/schemaToDefaults.ts | 2 +- packages/store-sync/src/sqlite/buildTable.ts | 4 +- packages/store-sync/src/sqlite/getTables.ts | 6 +- .../src/sqlite/sqliteStorage.test.ts | 6 +- .../store-sync/src/sqlite/sqliteStorage.ts | 16 +-- .../src/sqlite/sqliteTableToSql.test.ts | 6 +- packages/store-sync/src/tableToLog.test.ts | 2 +- .../store-sync/src/tablesWithRecordsToLogs.ts | 4 +- .../src/zustand/createStorageAdapter.test.ts | 2 +- .../src/zustand/createStorageAdapter.ts | 4 +- .../store-sync/src/zustand/createStore.ts | 10 +- packages/store-sync/src/zustand/getId.test.ts | 4 +- .../store-sync/src/zustand/logToTable.test.ts | 2 +- packages/store-sync/src/zustand/logToTable.ts | 2 +- .../store-sync/src/zustand/syncToZustand.ts | 2 +- packages/store-sync/test/logsToBlocks.ts | 4 +- packages/store/src/IStore.sol | 4 +- packages/store/ts/codegen/field.ts | 80 +++++++------- packages/store/ts/codegen/record.ts | 26 ++--- .../ts/codegen/renderFieldLayout.test.ts | 10 +- packages/store/ts/codegen/renderTable.ts | 16 +-- packages/store/ts/codegen/tableOptions.ts | 2 +- packages/store/ts/codegen/tablegen.ts | 4 +- .../codegen/tightcoder/renderDecodeSlice.ts | 2 +- .../codegen/tightcoder/renderEncodeArray.ts | 2 +- packages/store/ts/codegen/userType.ts | 6 +- packages/store/ts/common.ts | 12 +-- .../experimental/resolveConfig.test-d.ts | 2 +- .../config/experimental/resolveConfig.test.ts | 4 +- .../ts/config/experimental/resolveConfig.ts | 46 ++++---- packages/store/ts/config/storeConfig.ts | 100 +++++++++--------- packages/store/ts/register/mudConfig.ts | 2 +- .../store/ts/scripts/generate-tightcoder.ts | 2 +- packages/store/ts/storeEvents.test.ts | 2 +- packages/utils/src/bytes.ts | 2 +- packages/utils/src/cubic.ts | 10 +- packages/utils/src/mobx.ts | 2 +- packages/utils/src/objects.ts | 2 +- packages/utils/src/promise.ts | 2 +- packages/utils/src/proxy.ts | 6 +- packages/utils/src/rx.ts | 10 +- packages/utils/src/types.ts | 12 +-- .../src/interfaces/IBaseWorld.sol | 4 +- .../src/codegen/interfaces/IBaseWorld.sol | 4 +- .../interfaces/IRegistrationSystem.sol | 4 +- .../world/ts/config/resolveWorldConfig.ts | 2 +- packages/world/ts/config/worldConfig.ts | 2 +- packages/world/ts/encodeSystemCalls.ts | 2 +- packages/world/ts/encodeSystemCallsFrom.ts | 4 +- .../render-solidity/renderSystemInterface.ts | 2 +- .../world/ts/node/render-solidity/worldgen.ts | 4 +- packages/world/ts/worldEvents.test.ts | 2 +- scripts/changelog.ts | 2 +- scripts/render-api-docs.ts | 22 ++-- .../client/src/mud/createSystemCalls.ts | 2 +- .../phaser/packages/client/src/ui/App.tsx | 2 +- .../client/src/ui/hooks/usePhaserLayer.tsx | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../react-ecs/packages/client/src/index.tsx | 2 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- templates/react/packages/client/src/index.tsx | 2 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../threejs/packages/client/src/index.tsx | 2 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- .../client/src/mud/createSystemCalls.ts | 2 +- .../contracts/src/codegen/world/IWorld.sol | 4 +- 272 files changed, 928 insertions(+), 853 deletions(-) diff --git a/.changeset/nasty-waves-divide.md b/.changeset/nasty-waves-divide.md index f85dd96047..61ac31054c 100644 --- a/.changeset/nasty-waves-divide.md +++ b/.changeset/nasty-waves-divide.md @@ -22,7 +22,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest" const latestBlockNumber$ = latestBlock$.pipe( filter(isNonPendingBlock), - map((block) => block.number) + map((block) => block.number), ); latestBlockNumber$ @@ -38,7 +38,7 @@ latestBlockNumber$ "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/.changeset/tame-lemons-play.md b/.changeset/tame-lemons-play.md index e20f0bcd55..17de0f9339 100644 --- a/.changeset/tame-lemons-play.md +++ b/.changeset/tame-lemons-play.md @@ -172,7 +172,7 @@ As you migrate, you may find some features replaced, removed, or not included by .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3efbf55d..12d6a624bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3395,7 +3395,7 @@ As you migrate, you may find some features replaced, removed, or not included by .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` @@ -3633,7 +3633,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest" const latestBlockNumber$ = latestBlock$.pipe( filter(isNonPendingBlock), - map((block) => block.number) + map((block) => block.number), ); latestBlockNumber$ @@ -3649,7 +3649,7 @@ latestBlockNumber$ "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/docs/app/page.tsx b/docs/app/page.tsx index 7a954b39d5..bbb7c29d8c 100644 --- a/docs/app/page.tsx +++ b/docs/app/page.tsx @@ -24,7 +24,7 @@ export default async function HomePage() { "min-h-screen flex flex-col animate-in animate-duration-500 fade-in", "gap-12 p-8", "sm:justify-between", - "md:gap-16 md:p-16" + "md:gap-16 md:p-16", )} >
diff --git a/docs/components/MUDTable.module.css b/docs/components/MUDTable.module.css index becc677b84..97b6223686 100644 --- a/docs/components/MUDTable.module.css +++ b/docs/components/MUDTable.module.css @@ -1,5 +1,13 @@ .table { - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace; + font-family: + ui-monospace, + SFMono-Regular, + Menlo, + Monaco, + Consolas, + Liberation Mono, + Courier New, + monospace; background-color: hsl(var(--nextra-primary-hue) 100% 66%/0.1); margin-top: 1em; text-align: center; diff --git a/docs/pages/changelog.mdx b/docs/pages/changelog.mdx index 9e3efbf55d..12d6a624bf 100644 --- a/docs/pages/changelog.mdx +++ b/docs/pages/changelog.mdx @@ -3395,7 +3395,7 @@ As you migrate, you may find some features replaced, removed, or not included by .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` @@ -3633,7 +3633,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest" const latestBlockNumber$ = latestBlock$.pipe( filter(isNonPendingBlock), - map((block) => block.number) + map((block) => block.number), ); latestBlockNumber$ @@ -3649,7 +3649,7 @@ latestBlockNumber$ "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/docs/pages/guides/emojimon/3-players-and-movement.mdx b/docs/pages/guides/emojimon/3-players-and-movement.mdx index d5eac88e95..cefe114200 100644 --- a/docs/pages/guides/emojimon/3-players-and-movement.mdx +++ b/docs/pages/guides/emojimon/3-players-and-movement.mdx @@ -255,7 +255,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { playerEntity, worldContract, waitForTransaction }: SetupNetworkResult, - { Player, Position }: ClientComponents + { Player, Position }: ClientComponents, ) { const moveBy = async (deltaX: number, deltaY: number) => { if (!playerEntity) { diff --git a/docs/pages/guides/emojimon/4-map-and-terrain.mdx b/docs/pages/guides/emojimon/4-map-and-terrain.mdx index 4e81e1584d..bbbc842494 100644 --- a/docs/pages/guides/emojimon/4-map-and-terrain.mdx +++ b/docs/pages/guides/emojimon/4-map-and-terrain.mdx @@ -445,7 +445,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { playerEntity, worldContract, waitForTransaction }: SetupNetworkResult, - { MapConfig, Obstruction, Player, Position }: ClientComponents + { MapConfig, Obstruction, Player, Position }: ClientComponents, ) { const isObstructed = (x: number, y: number) => { return runQuery([Has(Obstruction), HasValue(Position, { x, y })]).size > 0; diff --git a/docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx b/docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx index 7392e1f57e..b7522d7304 100644 --- a/docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx +++ b/docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx @@ -718,7 +718,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { playerEntity, worldContract, waitForTransaction }: SetupNetworkResult, - { Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents + { Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents, ) { const wrapPosition = (x: number, y: number) => { const mapConfig = getComponentValue(MapConfig, singletonEntity); @@ -890,7 +890,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { playerEntity, worldContract, waitForTransaction }: SetupNetworkResult, - { Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents + { Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents, ) { const wrapPosition = (x: number, y: number) => { const mapConfig = getComponentValue(MapConfig, singletonEntity); diff --git a/docs/pages/guides/hello-world/add-table.mdx b/docs/pages/guides/hello-world/add-table.mdx index 0673138767..b1fa6dc4d6 100644 --- a/docs/pages/guides/hello-world/add-table.mdx +++ b/docs/pages/guides/hello-world/add-table.mdx @@ -261,7 +261,7 @@ This exclamation point tells the compiler that it's OK, there will be a real val ```html filename="index.html" copy showLineNumbers {12-17} - + diff --git a/docs/pages/store/reference/misc.mdx b/docs/pages/store/reference/misc.mdx index 1d26769632..721b093860 100644 --- a/docs/pages/store/reference/misc.mdx +++ b/docs/pages/store/reference/misc.mdx @@ -269,6 +269,62 @@ function slice32(bytes memory data, uint256 start) internal pure returns (bytes3 | -------- | --------- | -------------------------------------------------------------------------- | | `output` | `bytes32` | The extracted bytes32 value from the specified position in the bytes blob. | +## FieldLayout_Empty + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) + +```solidity +error FieldLayout_Empty(); +``` + +## FieldLayout_InvalidStaticDataLength + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) + +```solidity +error FieldLayout_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength); +``` + +## FieldLayout_StaticLengthDoesNotFitInAWord + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) + +```solidity +error FieldLayout_StaticLengthDoesNotFitInAWord(uint256 index); +``` + +## FieldLayout_StaticLengthIsNotZero + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) + +```solidity +error FieldLayout_StaticLengthIsNotZero(uint256 index); +``` + +## FieldLayout_StaticLengthIsZero + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) + +```solidity +error FieldLayout_StaticLengthIsZero(uint256 index); +``` + +## FieldLayout_TooManyDynamicFields + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) + +```solidity +error FieldLayout_TooManyDynamicFields(uint256 numFields, uint256 maxFields); +``` + +## FieldLayout_TooManyFields + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) + +```solidity +error FieldLayout_TooManyFields(uint256 numFields, uint256 maxFields); +``` + ## FieldLayoutInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) @@ -799,6 +855,26 @@ type and a name_ type ResourceId is bytes32; ``` +## Schema_InvalidLength + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) + +_Error raised when the provided schema has an invalid length._ + +```solidity +error Schema_InvalidLength(uint256 length); +``` + +## Schema_StaticTypeAfterDynamicType + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) + +_Error raised when a static type is placed after a dynamic type in a schema._ + +```solidity +error Schema_StaticTypeAfterDynamicType(); +``` + ## SchemaInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) @@ -1023,6 +1099,14 @@ _Defines and handles the encoding/decoding of Schemas which describe the layout type Schema is bytes32; ``` +## Slice_OutOfBounds + +[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol) + +```solidity +error Slice_OutOfBounds(bytes data, uint256 start, uint256 end); +``` + ## SliceInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol) diff --git a/docs/src/tailwindcss-plugins/animate.ts b/docs/src/tailwindcss-plugins/animate.ts index f64ba44b27..1c6e3c1369 100644 --- a/docs/src/tailwindcss-plugins/animate.ts +++ b/docs/src/tailwindcss-plugins/animate.ts @@ -37,7 +37,7 @@ module.exports = plugin( "fade-in": (value) => ({ "--tw-enter-opacity": value }), "fade-out": (value) => ({ "--tw-exit-opacity": value }), }, - { values: theme("animationOpacity") } + { values: theme("animationOpacity") }, ); matchUtilities( @@ -45,7 +45,7 @@ module.exports = plugin( "zoom-in": (value) => ({ "--tw-enter-scale": value }), "zoom-out": (value) => ({ "--tw-exit-scale": value }), }, - { values: theme("animationScale") } + { values: theme("animationScale") }, ); matchUtilities( @@ -53,7 +53,7 @@ module.exports = plugin( "spin-in": (value) => ({ "--tw-enter-rotate": value }), "spin-out": (value) => ({ "--tw-exit-rotate": value }), }, - { values: theme("animationRotate") } + { values: theme("animationRotate") }, ); matchUtilities( @@ -83,19 +83,19 @@ module.exports = plugin( "--tw-exit-translate-x": value, }), }, - { values: theme("animationTranslate") } + { values: theme("animationTranslate") }, ); matchUtilities( { "animate-duration": (value: string) => ({ animationDuration: value }) }, - { values: filterDefault(theme("animationDuration")) } + { values: filterDefault(theme("animationDuration")) }, ); matchUtilities({ delay: (value) => ({ animationDelay: value }) }, { values: theme("animationDelay") }); matchUtilities( { ease: (value: string) => ({ animationTimingFunction: value }) }, - { values: filterDefault(theme("animationTimingFunction")) } + { values: filterDefault(theme("animationTimingFunction")) }, ); addUtilities({ @@ -175,5 +175,5 @@ module.exports = plugin( }, }, }, - } + }, ); diff --git a/e2e/packages/client-vanilla/src/index.ts b/e2e/packages/client-vanilla/src/index.ts index 464d986f78..7899f3c949 100644 --- a/e2e/packages/client-vanilla/src/index.ts +++ b/e2e/packages/client-vanilla/src/index.ts @@ -17,7 +17,7 @@ _window.getEntities = (componentName: keyof typeof components) => Array.from(com _window.getKeys = (componentName: keyof typeof components) => Array.from(components[componentName].entities()).map((entity) => - decodeEntity(components[componentName].metadata.keySchema, entity) + decodeEntity(components[componentName].metadata.keySchema, entity), ); // Update block number in the UI diff --git a/e2e/packages/contracts/src/codegen/world/IWorld.sol b/e2e/packages/contracts/src/codegen/world/IWorld.sol index e0c902f4ad..62448e2b51 100644 --- a/e2e/packages/contracts/src/codegen/world/IWorld.sol +++ b/e2e/packages/contracts/src/codegen/world/IWorld.sol @@ -17,6 +17,4 @@ import { IVectorSystem } from "./IVectorSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, ICustomErrorsSystem, INumberListSystem, INumberSystem, IVectorSystem { - -} +interface IWorld is IBaseWorld, ICustomErrorsSystem, INumberListSystem, INumberSystem, IVectorSystem {} diff --git a/e2e/packages/sync-test/compare/compare.test.ts b/e2e/packages/sync-test/compare/compare.test.ts index f3bb9b5351..c6d7f0f8f7 100644 --- a/e2e/packages/sync-test/compare/compare.test.ts +++ b/e2e/packages/sync-test/compare/compare.test.ts @@ -35,7 +35,7 @@ function setRecord( address: Address, tableId: TableId, key: Key, - data: Data + data: Data, ): void { state[address.toLowerCase()] ??= {}; state[address.toLowerCase()][tableId] ??= {}; @@ -46,7 +46,7 @@ function getRecord( state: Record>>, address: Address, tableId: TableId, - key: Key + key: Key, ): Data | undefined { return state[address]?.[tableId]?.[key]; } diff --git a/e2e/packages/sync-test/data/callPageFunction.ts b/e2e/packages/sync-test/data/callPageFunction.ts index ece5b02e01..89a9c395a4 100644 --- a/e2e/packages/sync-test/data/callPageFunction.ts +++ b/e2e/packages/sync-test/data/callPageFunction.ts @@ -9,7 +9,7 @@ import { deserialize, serialize } from "./utils"; export async function callPageFunction( page: Page, functionName: string, - args: unknown[] + args: unknown[], ): Promise | undefined> { const context = [functionName, args, serialize.toString(), deserialize.toString()] as const; const serializedValue = await page.evaluate(async ([functionName, args, serializeString, deserializeString]) => { diff --git a/e2e/packages/sync-test/data/callWorld.ts b/e2e/packages/sync-test/data/callWorld.ts index c19e1d9029..c6b58c04c6 100644 --- a/e2e/packages/sync-test/data/callWorld.ts +++ b/e2e/packages/sync-test/data/callWorld.ts @@ -23,6 +23,6 @@ export function callWorld(page: Page, method: T throw new Error([`Error executing ${_method} with args:`, JSON.stringify(_args), error].join("\n\n")); }); }, - [method, args] + [method, args], ); } diff --git a/e2e/packages/sync-test/data/types.ts b/e2e/packages/sync-test/data/types.ts index b79ac3f3b6..98369a7426 100644 --- a/e2e/packages/sync-test/data/types.ts +++ b/e2e/packages/sync-test/data/types.ts @@ -2,9 +2,10 @@ import { SchemaAbiType, SchemaAbiTypeToPrimitiveType } from "@latticexyz/schema-type"; import config from "../../contracts/mud.config"; import { Hex } from "viem"; -type SchemaToPrimitive = Schema extends Record - ? { [key in keyof Schema]: SchemaAbiTypeToPrimitiveType } - : never; +type SchemaToPrimitive = + Schema extends Record + ? { [key in keyof Schema]: SchemaAbiTypeToPrimitiveType } + : never; type Key
= SchemaToPrimitive< (typeof config)["tables"][Table]["keySchema"] diff --git a/e2e/packages/sync-test/indexerSync.test.ts b/e2e/packages/sync-test/indexerSync.test.ts index f23edf5f16..3585c6e4a2 100644 --- a/e2e/packages/sync-test/indexerSync.test.ts +++ b/e2e/packages/sync-test/indexerSync.test.ts @@ -143,7 +143,7 @@ describe("Sync from indexer", async () => { y: -2, zone: "0x6d61703100000000000000000000000000000000000000000000000000000000", }, - ]) + ]), ); // Should not have thrown errors diff --git a/e2e/packages/sync-test/setup/openClientWithRootAccount.ts b/e2e/packages/sync-test/setup/openClientWithRootAccount.ts index 85b88658d6..98158ca286 100644 --- a/e2e/packages/sync-test/setup/openClientWithRootAccount.ts +++ b/e2e/packages/sync-test/setup/openClientWithRootAccount.ts @@ -12,6 +12,6 @@ export async function openClientWithRootAccount(page: Page, options?: { indexerU // I wish I could pass undefined values into URLSearchParams and have them be ignored during stringify ...(process.env.PRIVATE_KEY ? { privateKey: process.env.PRIVATE_KEY } : null), ...(options?.indexerUrl ? { indexerUrl: options?.indexerUrl } : null), - }).toString()}` + }).toString()}`, ); } diff --git a/e2e/packages/sync-test/setup/startBrowserAndPage.ts b/e2e/packages/sync-test/setup/startBrowserAndPage.ts index 0f18151879..9cbced06a0 100644 --- a/e2e/packages/sync-test/setup/startBrowserAndPage.ts +++ b/e2e/packages/sync-test/setup/startBrowserAndPage.ts @@ -2,7 +2,7 @@ import { Browser, Page, chromium } from "@playwright/test"; import chalk from "chalk"; export async function startBrowserAndPage( - reportError: (error: string) => void + reportError: (error: string) => void, ): Promise<{ browser: Browser; page: Page }> { // open browser page const browser = await chromium.launch(); diff --git a/e2e/packages/test-data/generate-bench-data-bulk.ts b/e2e/packages/test-data/generate-bench-data-bulk.ts index 313ad45a7d..c69fad503f 100644 --- a/e2e/packages/test-data/generate-bench-data-bulk.ts +++ b/e2e/packages/test-data/generate-bench-data-bulk.ts @@ -34,7 +34,7 @@ for (let i = 0; i < NUM_RECORDS.length; i++) { const logsFilename = path.join( path.dirname(fileURLToPath(import.meta.url)), - `../../../test-data/world-logs-bulk-${numRecords}.json` + `../../../test-data/world-logs-bulk-${numRecords}.json`, ); console.log("writing", logs.length, "logs to", logsFilename); diff --git a/e2e/packages/test-data/generate-bench-data-query.ts b/e2e/packages/test-data/generate-bench-data-query.ts index d97a976fd4..4e34afe75c 100644 --- a/e2e/packages/test-data/generate-bench-data-query.ts +++ b/e2e/packages/test-data/generate-bench-data-query.ts @@ -30,7 +30,7 @@ const logs = await generateLogs(rpc, async (worldContract) => { const logsFilename = path.join( path.dirname(fileURLToPath(import.meta.url)), - `../../../test-data/world-logs-query.json` + `../../../test-data/world-logs-query.json`, ); console.log("writing", logs.length, "logs to", logsFilename); diff --git a/e2e/packages/test-data/generateLogs.ts b/e2e/packages/test-data/generateLogs.ts index fff5449b2f..ba855efe61 100644 --- a/e2e/packages/test-data/generateLogs.ts +++ b/e2e/packages/test-data/generateLogs.ts @@ -31,7 +31,7 @@ type WorldContract = GetContractReturnType< export async function generateLogs( rpc: string, - transactionHook: (worldContract: WorldContract) => Promise + transactionHook: (worldContract: WorldContract) => Promise, ): Promise { console.log("deploying world"); const { stdout, stderr } = await execa("pnpm", ["mud", "deploy", "--rpc", rpc, "--saveDeployment", "false"], { @@ -88,7 +88,7 @@ export async function generateLogs( encodeEventTopics({ abi: [event], eventName: event.name, - }) + }), ), ], fromBlock: numberToHex(0n), diff --git a/examples/minimal/packages/client-phaser/src/mud/createSystemCalls.ts b/examples/minimal/packages/client-phaser/src/mud/createSystemCalls.ts index 1e0c674320..37203654b1 100644 --- a/examples/minimal/packages/client-phaser/src/mud/createSystemCalls.ts +++ b/examples/minimal/packages/client-phaser/src/mud/createSystemCalls.ts @@ -7,7 +7,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { worldContract, waitForTransaction }: SetupNetworkResult, - { CounterTable }: ClientComponents + { CounterTable }: ClientComponents, ) { const increment = async () => { const tx = await worldContract.write.increment(); diff --git a/examples/minimal/packages/client-phaser/src/ui/App.tsx b/examples/minimal/packages/client-phaser/src/ui/App.tsx index 69529815b5..0ddd731ec7 100644 --- a/examples/minimal/packages/client-phaser/src/ui/App.tsx +++ b/examples/minimal/packages/client-phaser/src/ui/App.tsx @@ -26,7 +26,7 @@ export const App = () => { worldAbi: networkLayer.network.worldContract.abi, write$: networkLayer.network.write$, recsWorld: networkLayer.world, - }) + }), ); } }, [networkLayer]); diff --git a/examples/minimal/packages/client-phaser/src/ui/hooks/usePhaserLayer.tsx b/examples/minimal/packages/client-phaser/src/ui/hooks/usePhaserLayer.tsx index f0a4c36da7..c6292e57ff 100644 --- a/examples/minimal/packages/client-phaser/src/ui/hooks/usePhaserLayer.tsx +++ b/examples/minimal/packages/client-phaser/src/ui/hooks/usePhaserLayer.tsx @@ -79,7 +79,7 @@ export const usePhaserLayer = ({ networkLayer }: Props) => { } } }, - [container] + [container], ); return useMemo(() => ({ ref, phaserLayer }), [ref, phaserLayer]); diff --git a/examples/minimal/packages/client-react/src/index.tsx b/examples/minimal/packages/client-react/src/index.tsx index da8d70f020..1b005dc561 100644 --- a/examples/minimal/packages/client-react/src/index.tsx +++ b/examples/minimal/packages/client-react/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/examples/minimal/packages/client-react/src/mud/createSystemCalls.ts b/examples/minimal/packages/client-react/src/mud/createSystemCalls.ts index 1e0c674320..37203654b1 100644 --- a/examples/minimal/packages/client-react/src/mud/createSystemCalls.ts +++ b/examples/minimal/packages/client-react/src/mud/createSystemCalls.ts @@ -7,7 +7,7 @@ export type SystemCalls = ReturnType; export function createSystemCalls( { worldContract, waitForTransaction }: SetupNetworkResult, - { CounterTable }: ClientComponents + { CounterTable }: ClientComponents, ) { const increment = async () => { const tx = await worldContract.write.increment(); diff --git a/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol b/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol index dfa955dbea..6eb7845c59 100644 --- a/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol +++ b/examples/minimal/packages/contracts/src/codegen/world/IWorld.sol @@ -17,6 +17,4 @@ import { IStructSystem } from "./IStructSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IChatSystem, IIncrementSystem, IInventorySystem, IStructSystem { - -} +interface IWorld is IBaseWorld, IChatSystem, IIncrementSystem, IInventorySystem, IStructSystem {} diff --git a/examples/multiple-accounts/packages/client/src/index.tsx b/examples/multiple-accounts/packages/client/src/index.tsx index 3ba2a44052..c9b662c9f0 100644 --- a/examples/multiple-accounts/packages/client/src/index.tsx +++ b/examples/multiple-accounts/packages/client/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/examples/multiple-accounts/packages/contracts/src/codegen/world/IWorld.sol b/examples/multiple-accounts/packages/contracts/src/codegen/world/IWorld.sol index f84aef6a65..2c909e6f4f 100644 --- a/examples/multiple-accounts/packages/contracts/src/codegen/world/IWorld.sol +++ b/examples/multiple-accounts/packages/contracts/src/codegen/world/IWorld.sol @@ -14,6 +14,4 @@ import { ILastCallSystem } from "./ILastCallSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, ILastCallSystem { - -} +interface IWorld is IBaseWorld, ILastCallSystem {} diff --git a/packages/abi-ts/src/abi-ts.ts b/packages/abi-ts/src/abi-ts.ts index 8d12d0ee0a..a6093d52ec 100755 --- a/packages/abi-ts/src/abi-ts.ts +++ b/packages/abi-ts/src/abi-ts.ts @@ -21,7 +21,7 @@ yargs(hideBin(process.argv)) console.error(chalk.red(msg)); if (msg.includes("Missing required argument")) { console.log( - chalk.yellow(`Run 'pnpm abi-ts ${process.argv[2]} --help' for a list of available and required arguments.`) + chalk.yellow(`Run 'pnpm abi-ts ${process.argv[2]} --help' for a list of available and required arguments.`), ); } diff --git a/packages/block-logs-stream/CHANGELOG.md b/packages/block-logs-stream/CHANGELOG.md index 545ea08a88..7e9de47863 100644 --- a/packages/block-logs-stream/CHANGELOG.md +++ b/packages/block-logs-stream/CHANGELOG.md @@ -418,7 +418,7 @@ const latestBlockNumber$ = latestBlock$.pipe( filter(isNonPendingBlock), - map((block) => block.number) + map((block) => block.number), ); latestBlockNumber$ @@ -434,7 +434,7 @@ "event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/packages/block-logs-stream/README.md b/packages/block-logs-stream/README.md index a76e15825f..0d7ccc924f 100644 --- a/packages/block-logs-stream/README.md +++ b/packages/block-logs-stream/README.md @@ -32,7 +32,7 @@ latestBlockNumber$ "event Store_DeleteRecord(bytes32 indexed tableId, bytes32[] keyTuple)", ]), }), - mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))) + mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))), ) .subscribe((block) => { console.log("got events for block", block); diff --git a/packages/block-logs-stream/src/blockRangeToLogs.test.ts b/packages/block-logs-stream/src/blockRangeToLogs.test.ts index a0474841b8..607a8dea77 100644 --- a/packages/block-logs-stream/src/blockRangeToLogs.test.ts +++ b/packages/block-logs-stream/src/blockRangeToLogs.test.ts @@ -41,7 +41,7 @@ describe("blockRangeToLogs", () => { publicClient, address: "0x", events: [], - }) + }), ); (async (): Promise => { diff --git a/packages/block-logs-stream/src/blockRangeToLogs.ts b/packages/block-logs-stream/src/blockRangeToLogs.ts index 825320f14d..9a87da6242 100644 --- a/packages/block-logs-stream/src/blockRangeToLogs.ts +++ b/packages/block-logs-stream/src/blockRangeToLogs.ts @@ -65,12 +65,12 @@ export function blockRangeToLogs({ fromBlock, toBlock, maxBlockRange, - }) + }), ).pipe( tap(({ toBlock }) => { fromBlock = toBlock + 1n; - }) + }), ); - }) + }), ); } diff --git a/packages/block-logs-stream/src/fetchLogs.test.ts b/packages/block-logs-stream/src/fetchLogs.test.ts index 7f95f507b9..4bd28cb1c2 100644 --- a/packages/block-logs-stream/src/fetchLogs.test.ts +++ b/packages/block-logs-stream/src/fetchLogs.test.ts @@ -150,7 +150,7 @@ describe("fetchLogs", () => { code: -32005, message: "block range exceeded", }, - }) + }), ); } @@ -374,7 +374,7 @@ describe("fetchLogs", () => { code: -32005, message: "rate limit exceeded", }, - }) + }), ); } diff --git a/packages/block-logs-stream/src/groupLogsByBlockNumber.ts b/packages/block-logs-stream/src/groupLogsByBlockNumber.ts index b0656acfbc..37fd614d35 100644 --- a/packages/block-logs-stream/src/groupLogsByBlockNumber.ts +++ b/packages/block-logs-stream/src/groupLogsByBlockNumber.ts @@ -24,7 +24,7 @@ export type GroupLogsByBlockNumberResult = { */ export function groupLogsByBlockNumber( logs: readonly TLog[], - toBlock?: BlockNumber + toBlock?: BlockNumber, ): GroupLogsByBlockNumberResult { const blockNumbers = Array.from(new Set(logs.map((log) => log.blockNumber))); blockNumbers.sort(bigIntSort); diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 0bec448c15..705083a33e 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1135,7 +1135,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/cli/src/commands/dev-contracts.ts b/packages/cli/src/commands/dev-contracts.ts index 084c271275..23b7b1d03c 100644 --- a/packages/cli/src/commands/dev-contracts.ts +++ b/packages/cli/src/commands/dev-contracts.ts @@ -106,7 +106,7 @@ const commandModule: CommandModule = { const mutuallyExclusiveOptions = ["mudVersion", "link", "tag", "commit", "restore"]; const numMutuallyExclusiveOptions = mutuallyExclusiveOptions.reduce( (acc, opt) => (options[opt] ? acc + 1 : acc), - 0 + 0, ); if (numMutuallyExclusiveOptions === 0) { diff --git a/packages/cli/src/commands/trace.ts b/packages/cli/src/commands/trace.ts index e6d55a9ece..e8659eb089 100644 --- a/packages/cli/src/commands/trace.ts +++ b/packages/cli/src/commands/trace.ts @@ -63,7 +63,7 @@ const commandModule: CommandModule = { const resolvedConfig = resolveWorldConfig( mudConfig, - existingContracts.map(({ basename }) => basename) + existingContracts.map(({ basename }) => basename), ); // Get worldAddress either from args or from worldsFile diff --git a/packages/cli/src/deploy/configToTables.ts b/packages/cli/src/deploy/configToTables.ts index 4c07a81bb3..3e9b0e5729 100644 --- a/packages/cli/src/deploy/configToTables.ts +++ b/packages/cli/src/deploy/configToTables.ts @@ -14,12 +14,12 @@ type UserTypes = config["userTypes"]; export type TableKey< config extends StoreConfig = StoreConfig, - table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]] + table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]], > = `${config["namespace"]}_${table["name"]}`; export type Table< config extends StoreConfig = StoreConfig, - table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]] + table extends config["tables"][keyof config["tables"]] = config["tables"][keyof config["tables"]], > = { readonly namespace: config["namespace"]; readonly name: table["name"]; @@ -63,6 +63,6 @@ export function configToTables(config: config): Tabl keySchema: resolveUserTypes(table.keySchema, userTypes) as any, valueSchema: resolveUserTypes(table.valueSchema, userTypes) as any, } satisfies Table, - ]) + ]), ) as Tables; } diff --git a/packages/cli/src/deploy/deployWorld.ts b/packages/cli/src/deploy/deployWorld.ts index 16c4c7bc75..7f5bf4ba04 100644 --- a/packages/cli/src/deploy/deployWorld.ts +++ b/packages/cli/src/deploy/deployWorld.ts @@ -10,7 +10,7 @@ import { WorldDeploy } from "./common"; export async function deployWorld( client: Client, deployerAddress: Hex, - salt: Hex + salt: Hex, ): Promise { const worldFactory = await ensureWorldFactory(client, deployerAddress); diff --git a/packages/cli/src/deploy/ensureContract.ts b/packages/cli/src/deploy/ensureContract.ts index b7110bcb1d..d86269ee54 100644 --- a/packages/cli/src/deploy/ensureContract.ts +++ b/packages/cli/src/deploy/ensureContract.ts @@ -32,11 +32,11 @@ export async function ensureContract({ if (deployedBytecodeSize > contractSizeLimit) { console.warn( - `\nBytecode for ${label} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n` + `\nBytecode for ${label} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n`, ); } else if (deployedBytecodeSize > contractSizeLimit * 0.95) { console.warn( - `\nBytecode for ${label} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n` + `\nBytecode for ${label} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.\n`, ); } @@ -56,7 +56,7 @@ export async function ensureContract({ debug(`failed to deploy ${label}, retrying in ${delay}ms...`); await wait(delay); }, - } + }, ), ]; } diff --git a/packages/cli/src/deploy/ensureDeployer.ts b/packages/cli/src/deploy/ensureDeployer.ts index 709f27d6f3..92c7c136b0 100644 --- a/packages/cli/src/deploy/ensureDeployer.ts +++ b/packages/cli/src/deploy/ensureDeployer.ts @@ -12,7 +12,7 @@ export async function ensureDeployer(client: Client func.signature).join(", ") + wrongSystem.map((func) => func.signature).join(", "), ); } } @@ -59,7 +59,7 @@ export async function ensureFunctions({ debug(`failed to register function ${func.signature}, retrying in ${delay}ms...`); await wait(delay); }, - } + }, ); } return pRetry( @@ -79,8 +79,8 @@ export async function ensureFunctions({ debug(`failed to register function ${func.signature}, retrying in ${delay}ms...`); await wait(delay); }, - } + }, ); - }) + }), ); } diff --git a/packages/cli/src/deploy/ensureModules.ts b/packages/cli/src/deploy/ensureModules.ts index dddef29a09..5a658a85c2 100644 --- a/packages/cli/src/deploy/ensureModules.ts +++ b/packages/cli/src/deploy/ensureModules.ts @@ -68,9 +68,9 @@ export async function ensureModules({ debug(`failed to install module ${mod.name}, retrying in ${delay}ms...`); await wait(delay); }, - } - ) - ) + }, + ), + ), ) ).filter(isDefined); } diff --git a/packages/cli/src/deploy/ensureNamespaceOwner.ts b/packages/cli/src/deploy/ensureNamespaceOwner.ts index 65384d2de3..0771951e90 100644 --- a/packages/cli/src/deploy/ensureNamespaceOwner.ts +++ b/packages/cli/src/deploy/ensureNamespaceOwner.ts @@ -24,7 +24,7 @@ export async function ensureNamespaceOwner({ "existing namespaces:", Array.from(existingNamespaces) .map((namespace) => (namespace === "" ? "" : namespace)) - .join(", ") + .join(", "), ); } @@ -39,7 +39,7 @@ export async function ensureNamespaceOwner({ key: { namespaceId: resourceToHex({ type: "namespace", namespace, name: "" }) }, }); return [namespace, owner]; - }) + }), ); const unauthorizedNamespaces = namespaceOwners @@ -63,8 +63,8 @@ export async function ensureNamespaceOwner({ abi: worldAbi, functionName: "registerNamespace", args: [resourceToHex({ namespace, type: "namespace", name: "" })], - }) - ) + }), + ), ); return registrationTxs; diff --git a/packages/cli/src/deploy/ensureSystems.ts b/packages/cli/src/deploy/ensureSystems.ts index 51bac4ae5b..dc1661a8c2 100644 --- a/packages/cli/src/deploy/ensureSystems.ts +++ b/packages/cli/src/deploy/ensureSystems.ts @@ -32,8 +32,8 @@ export async function ensureSystems({ worldSystems.some( (worldSystem) => worldSystem.systemId === system.systemId && - getAddress(worldSystem.address) === getAddress(system.getAddress(deployerAddress)) - ) + getAddress(worldSystem.address) === getAddress(system.getAddress(deployerAddress)), + ), ); if (existingSystems.length) { debug("existing systems", existingSystems.map(resourceToLabel).join(", ")); @@ -47,15 +47,15 @@ export async function ensureSystems({ worldSystems.some( (worldSystem) => worldSystem.systemId === system.systemId && - getAddress(worldSystem.address) !== getAddress(system.getAddress(deployerAddress)) - ) + getAddress(worldSystem.address) !== getAddress(system.getAddress(deployerAddress)), + ), ); if (systemsToUpgrade.length) { debug("upgrading systems", systemsToUpgrade.map(resourceToLabel).join(", ")); } const systemsToAdd = missingSystems.filter( - (system) => !worldSystems.some((worldSystem) => worldSystem.systemId === system.systemId) + (system) => !worldSystems.some((worldSystem) => worldSystem.systemId === system.systemId), ); if (systemsToAdd.length) { debug("registering new systems", systemsToAdd.map(resourceToLabel).join(", ")); @@ -90,9 +90,9 @@ export async function ensureSystems({ debug(`failed to register system ${resourceToLabel(system)}, retrying in ${delay}ms...`); await wait(delay); }, - } - ) - ) + }, + ), + ), ); // Adjust system access @@ -101,7 +101,7 @@ export async function ensureSystems({ const currentAccess = worldAccess.filter(({ resourceId }) => systemIds.includes(resourceId)); const desiredAccess = [ ...systems.flatMap((system) => - system.allowedAddresses.map((address) => ({ resourceId: system.systemId, address })) + system.allowedAddresses.map((address) => ({ resourceId: system.systemId, address })), ), ...systems.flatMap((system) => system.allowedSystemIds @@ -111,7 +111,7 @@ export async function ensureSystems({ worldSystems.find((s) => s.systemId === systemId)?.address ?? systems.find((s) => s.systemId === systemId)?.getAddress(deployerAddress), })) - .filter((access): access is typeof access & { address: Address } => access.address != null) + .filter((access): access is typeof access & { address: Address } => access.address != null), ), ]; @@ -119,16 +119,16 @@ export async function ensureSystems({ (access) => !currentAccess.some( ({ resourceId, address }) => - resourceId === access.resourceId && getAddress(address) === getAddress(access.address) - ) + resourceId === access.resourceId && getAddress(address) === getAddress(access.address), + ), ); const accessToRemove = currentAccess.filter( (access) => !desiredAccess.some( ({ resourceId, address }) => - resourceId === access.resourceId && getAddress(address) === getAddress(access.address) - ) + resourceId === access.resourceId && getAddress(address) === getAddress(access.address), + ), ); if (accessToRemove.length) { @@ -156,8 +156,8 @@ export async function ensureSystems({ debug(`failed to revoke access, retrying in ${delay}ms...`); await wait(delay); }, - } - ) + }, + ), ), ...accessToAdd.map((access) => pRetry( @@ -176,8 +176,8 @@ export async function ensureSystems({ debug(`failed to grant access, retrying in ${delay}ms...`); await wait(delay); }, - } - ) + }, + ), ), ]); diff --git a/packages/cli/src/deploy/ensureTables.ts b/packages/cli/src/deploy/ensureTables.ts index 31beddba46..0ab65681bd 100644 --- a/packages/cli/src/deploy/ensureTables.ts +++ b/packages/cli/src/deploy/ensureTables.ts @@ -54,9 +54,9 @@ export async function ensureTables({ debug(`failed to register table ${resourceToLabel(table)}, retrying in ${delay}ms...`); await wait(delay); }, - } - ) - ) + }, + ), + ), ); } diff --git a/packages/cli/src/deploy/ensureWorldFactory.ts b/packages/cli/src/deploy/ensureWorldFactory.ts index 0df1c21508..0c241f7669 100644 --- a/packages/cli/src/deploy/ensureWorldFactory.ts +++ b/packages/cli/src/deploy/ensureWorldFactory.ts @@ -13,7 +13,7 @@ import { Contract } from "./ensureContract"; export async function ensureWorldFactory( client: Client, - deployerAddress: Hex + deployerAddress: Hex, ): Promise
{ const accessManagementSystemDeployedBytecodeSize = size(accessManagementSystemBuild.deployedBytecode.object as Hex); const accessManagementSystemBytecode = accessManagementSystemBuild.bytecode.object as Hex; diff --git a/packages/cli/src/deploy/getFunctions.ts b/packages/cli/src/deploy/getFunctions.ts index 39b7955486..834dd2cecb 100644 --- a/packages/cli/src/deploy/getFunctions.ts +++ b/packages/cli/src/deploy/getFunctions.ts @@ -51,7 +51,7 @@ export async function getFunctions({ systemFunctionSignature, systemFunctionSelector, }; - }) + }), ); return functions; diff --git a/packages/cli/src/deploy/getResourceAccess.ts b/packages/cli/src/deploy/getResourceAccess.ts index e38a2b2cfd..a9642085be 100644 --- a/packages/cli/src/deploy/getResourceAccess.ts +++ b/packages/cli/src/deploy/getResourceAccess.ts @@ -35,8 +35,8 @@ export async function getResourceAccess({ await Promise.all( keys.map( async (key) => - [key, await getTableValue({ client, worldDeploy, table: worldTables.world_ResourceAccess, key })] as const - ) + [key, await getTableValue({ client, worldDeploy, table: worldTables.world_ResourceAccess, key })] as const, + ), ) ) .filter(([, value]) => value.access) diff --git a/packages/cli/src/deploy/getSystems.ts b/packages/cli/src/deploy/getSystems.ts index c87145efc1..b3cfa98eb6 100644 --- a/packages/cli/src/deploy/getSystems.ts +++ b/packages/cli/src/deploy/getSystems.ts @@ -42,6 +42,6 @@ export async function getSystems({ .map(({ address }) => address), functions: systemFunctions, }; - }) + }), ); } diff --git a/packages/cli/src/deploy/getTables.ts b/packages/cli/src/deploy/getTables.ts index 4154f38199..3342c7b9db 100644 --- a/packages/cli/src/deploy/getTables.ts +++ b/packages/cli/src/deploy/getTables.ts @@ -45,7 +45,7 @@ export async function getTables({ const valueAbiTypes = [...valueSchemaFields.staticFields, ...valueSchemaFields.dynamicFields]; const keySchema = Object.fromEntries( - keySchemaFields.staticFields.map((abiType, i) => [keyNames[i], abiType]) + keySchemaFields.staticFields.map((abiType, i) => [keyNames[i], abiType]), ) as KeySchema; const valueSchema = Object.fromEntries(valueAbiTypes.map((abiType, i) => [fieldNames[i], abiType])) as ValueSchema; diff --git a/packages/cli/src/deploy/logsToWorldDeploy.ts b/packages/cli/src/deploy/logsToWorldDeploy.ts index 81091270fd..a6f078766f 100644 --- a/packages/cli/src/deploy/logsToWorldDeploy.ts +++ b/packages/cli/src/deploy/logsToWorldDeploy.ts @@ -37,7 +37,7 @@ export function logsToWorldDeploy(logs: readonly Log[]): ? { storeVersion: hexToString(trim(log.args.storeVersion, { dir: "right" })) } : null), }), - {} + {}, ); if (address == null) throw new Error("could not find world address"); diff --git a/packages/cli/src/deploy/resolveConfig.ts b/packages/cli/src/deploy/resolveConfig.ts index bc56ad8dc2..2cde8cfc1f 100644 --- a/packages/cli/src/deploy/resolveConfig.ts +++ b/packages/cli/src/deploy/resolveConfig.ts @@ -61,7 +61,7 @@ export function resolveConfig({ allowAll: system.openAccess, allowedAddresses: system.accessListAddresses as Hex[], allowedSystemIds: system.accessListSystems.map((name) => - resourceToHex({ type: "system", namespace, name: resolvedConfig.systems[name].name }) + resourceToHex({ type: "system", namespace, name: resolvedConfig.systems[name].name }), ), getAddress: (deployer: Address) => getCreate2Address({ from: deployer, bytecode: contractData.bytecode, salt }), bytecode: contractData.bytecode, @@ -81,8 +81,8 @@ export function resolveConfig({ const names = overlappingSystems.map((system) => system.name); throw new Error( `Found systems with overlapping system ID: ${names.join( - ", " - )}.\n\nSystem IDs are generated from the first 16 bytes of the name, so you may need to rename them to avoid the overlap.` + ", ", + )}.\n\nSystem IDs are generated from the first 16 bytes of the name, so you may need to rename them to avoid the overlap.`, ); } @@ -96,9 +96,9 @@ export function resolveConfig({ type: table.offchainOnly ? "offchainTable" : "table", namespace: config.namespace, name: table.name, - }) + }), ), - ]) + ]), ), }; diff --git a/packages/cli/src/mud.ts b/packages/cli/src/mud.ts index b1f85a25fb..b01f04031b 100755 --- a/packages/cli/src/mud.ts +++ b/packages/cli/src/mud.ts @@ -26,7 +26,7 @@ async function run() { console.error(chalk.red(msg)); if (msg.includes("Missing required argument")) { console.log( - chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`) + chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`), ); } console.log(""); diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index ba668668b8..0535fe29f0 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -64,8 +64,8 @@ export async function runDeploy(opts: DeployOptions): Promise { const rpc = opts.rpc ?? (await getRpcUrl(profile)); console.log( chalk.bgBlue( - chalk.whiteBright(`\n Deploying MUD contracts${profile ? " with profile " + profile : ""} to RPC ${rpc} \n`) - ) + chalk.whiteBright(`\n Deploying MUD contracts${profile ? " with profile " + profile : ""} to RPC ${rpc} \n`), + ), ); // Run build @@ -78,7 +78,7 @@ export async function runDeploy(opts: DeployOptions): Promise { throw new MUDError( `Missing PRIVATE_KEY environment variable. Run 'echo "PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" > .env' -in your contracts directory to use the default anvil private key.` +in your contracts directory to use the default anvil private key.`, ); } @@ -126,7 +126,7 @@ in your contracts directory to use the default anvil private key.` writeFileSync(config.worldsFile, JSON.stringify(deploys, null, 2)); console.log( - chalk.bgGreen(chalk.whiteBright(`\n Deployment result (written to ${config.worldsFile} and ${deploysDir}): \n`)) + chalk.bgGreen(chalk.whiteBright(`\n Deployment result (written to ${config.worldsFile} and ${deploysDir}): \n`)), ); } diff --git a/packages/cli/src/utils/printMUD.ts b/packages/cli/src/utils/printMUD.ts index b3114e5916..5933c97d6f 100644 --- a/packages/cli/src/utils/printMUD.ts +++ b/packages/cli/src/utils/printMUD.ts @@ -9,6 +9,6 @@ export function printMUD() { | :\\/: || :\\/: || (__) | | '--'M|| '--'U|| '--'D| '------''------''------' -`) +`), ); } diff --git a/packages/cli/src/utils/utils/getContractData.ts b/packages/cli/src/utils/utils/getContractData.ts index a289b0443d..c527d2b873 100644 --- a/packages/cli/src/utils/utils/getContractData.ts +++ b/packages/cli/src/utils/utils/getContractData.ts @@ -9,7 +9,7 @@ import { Abi, Hex, size } from "viem"; */ export function getContractData( contractName: string, - forgeOutDirectory: string + forgeOutDirectory: string, ): { bytecode: Hex; abi: Abi; deployedBytecodeSize: number } { let data: any; const contractDataPath = path.join(forgeOutDirectory, contractName + ".sol", contractName + ".json"); diff --git a/packages/cli/src/utils/utils/postDeploy.ts b/packages/cli/src/utils/utils/postDeploy.ts index e30d63eaa1..a03eb1e2fa 100644 --- a/packages/cli/src/utils/utils/postDeploy.ts +++ b/packages/cli/src/utils/utils/postDeploy.ts @@ -7,7 +7,7 @@ export async function postDeploy( postDeployScript: string, worldAddress: string, rpc: string, - profile: string | undefined + profile: string | undefined, ): Promise { // Execute postDeploy forge script const postDeployPath = path.join(await getScriptDirectory(), postDeployScript + ".s.sol"); @@ -17,7 +17,7 @@ export async function postDeploy( ["script", postDeployScript, "--sig", "run(address)", worldAddress, "--broadcast", "--rpc-url", rpc, "-vvv"], { profile: profile, - } + }, ); } else { console.log(`No script at ${postDeployPath}, skipping post deploy hook`); diff --git a/packages/cli/tsup.config.ts b/packages/cli/tsup.config.ts index 8e74fd917d..cc3e3ca7de 100644 --- a/packages/cli/tsup.config.ts +++ b/packages/cli/tsup.config.ts @@ -14,7 +14,7 @@ const mudPackages: MudPackages = Object.fromEntries( JSON.parse(readFileSync(filename, "utf8")), ]) .filter(([, packageJson]) => !packageJson.private) - .map(([localPath, packageJson]) => [packageJson.name, { localPath }]) + .map(([localPath, packageJson]) => [packageJson.name, { localPath }]), ); export default defineConfig({ diff --git a/packages/common/CHANGELOG.md b/packages/common/CHANGELOG.md index 042dabaa3c..3d53ad41dd 100644 --- a/packages/common/CHANGELOG.md +++ b/packages/common/CHANGELOG.md @@ -669,7 +669,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/common/src/codegen/render-solidity/common.test.ts b/packages/common/src/codegen/render-solidity/common.test.ts index c754c07551..c249c21cec 100644 --- a/packages/common/src/codegen/render-solidity/common.test.ts +++ b/packages/common/src/codegen/render-solidity/common.test.ts @@ -22,38 +22,38 @@ describe("getLeftPaddingBits", () => { describe("renderValueTypeToBytes32", () => { it("returns Solidity code to cast native type to bytes32", () => { expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "bytes32" })).toMatchInlineSnapshot( - '"someField"' + '"someField"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bytes32" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bytes32" }), ).toMatchInlineSnapshot('"SomeStruct.unwrap(someField)"'); expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "bytes16" })).toMatchInlineSnapshot( - '"bytes32(someField)"' + '"bytes32(someField)"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bytes16" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bytes16" }), ).toMatchInlineSnapshot('"bytes32(SomeStruct.unwrap(someField))"'); expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "uint8" })).toMatchInlineSnapshot( - '"bytes32(uint256(someField))"' + '"bytes32(uint256(someField))"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "uint8" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "uint8" }), ).toMatchInlineSnapshot('"bytes32(uint256(SomeStruct.unwrap(someField)))"'); expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "bool" })).toMatchInlineSnapshot( - '"_boolToBytes32(someField)"' + '"_boolToBytes32(someField)"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bool" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "bool" }), ).toMatchInlineSnapshot('"_boolToBytes32(SomeStruct.unwrap(someField))"'); expect(renderValueTypeToBytes32("someField", { typeUnwrap: "", internalTypeId: "address" })).toMatchInlineSnapshot( - '"bytes32(uint256(uint160(someField)))"' + '"bytes32(uint256(uint160(someField)))"', ); expect( - renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "address" }) + renderValueTypeToBytes32("someField", { typeUnwrap: "SomeStruct.unwrap", internalTypeId: "address" }), ).toMatchInlineSnapshot('"bytes32(uint256(uint160(SomeStruct.unwrap(someField))))"'); }); }); diff --git a/packages/common/src/codegen/render-solidity/common.ts b/packages/common/src/codegen/render-solidity/common.ts index 0813f25160..58bbdf4b99 100644 --- a/packages/common/src/codegen/render-solidity/common.ts +++ b/packages/common/src/codegen/render-solidity/common.ts @@ -94,7 +94,7 @@ export function renderImports(imports: ImportDatum[]): string { path: solidityRelativeImportPath(importDatum.fromPath, importDatum.usedInPath), }; } - }) + }), ); } @@ -107,7 +107,7 @@ export function renderRelativeImports(imports: RelativeImportDatum[]): string { imports.map(({ symbol, fromPath, usedInPath }) => ({ symbol, path: solidityRelativeImportPath(fromPath, usedInPath), - })) + })), ); } @@ -154,7 +154,7 @@ interface RenderWithStoreCallbackData { */ export function renderWithStore( storeArgument: boolean, - callback: (data: RenderWithStoreCallbackData) => string + callback: (data: RenderWithStoreCallbackData) => string, ): string { let result = ""; result += callback({ _typedStore: undefined, _store: "StoreSwitch", _commentSuffix: "", _methodNamePrefix: "" }); @@ -190,7 +190,7 @@ export function renderWithStore( export function renderWithFieldSuffix( withSuffixlessFieldMethods: boolean, fieldName: string, - callback: (_methodNameSuffix: string) => string + callback: (_methodNameSuffix: string) => string, ): string { const methodNameSuffix = `${fieldName[0].toUpperCase()}${fieldName.slice(1)}`; let result = ""; @@ -214,7 +214,7 @@ export function renderTableId({ }: Pick): string { return ` // Hex below is the result of \`WorldResourceIdLib.encode({ namespace: ${JSON.stringify( - namespace + namespace, )}, name: ${JSON.stringify(name)}, typeId: ${offchainOnly ? "RESOURCE_OFFCHAIN_TABLE" : "RESOURCE_TABLE"} });\` ResourceId constant _tableId = ResourceId.wrap(${resourceToHex({ type: offchainOnly ? "offchainTable" : "table", @@ -231,7 +231,7 @@ export function renderTableId({ */ export function renderValueTypeToBytes32( name: string, - { typeUnwrap, internalTypeId }: Pick + { typeUnwrap, internalTypeId }: Pick, ): string { const innerText = typeUnwrap.length ? `${typeUnwrap}(${name})` : name; @@ -276,7 +276,7 @@ export function getLeftPaddingBits(field: Pick( lineTerminator: string, list: T[], - renderItem: (item: T, index: number) => string + renderItem: (item: T, index: number) => string, ): string { return list .map((item, index) => renderItem(item, index) + (index === list.length - 1 ? "" : lineTerminator)) diff --git a/packages/common/src/codegen/render-solidity/renderEnums.ts b/packages/common/src/codegen/render-solidity/renderEnums.ts index 00df0b1094..74d456d81a 100644 --- a/packages/common/src/codegen/render-solidity/renderEnums.ts +++ b/packages/common/src/codegen/render-solidity/renderEnums.ts @@ -13,7 +13,7 @@ export function renderEnums(enums: RenderEnum[]): string { enum ${name} { ${renderArguments(memberNames)} } - ` + `, ); return result; diff --git a/packages/common/src/codegen/render-solidity/renderTypeHelpers.ts b/packages/common/src/codegen/render-solidity/renderTypeHelpers.ts index 81b39c4baa..f6182d60e0 100644 --- a/packages/common/src/codegen/render-solidity/renderTypeHelpers.ts +++ b/packages/common/src/codegen/render-solidity/renderTypeHelpers.ts @@ -74,7 +74,7 @@ function renderWrapperStaticArray( functionName: string, elementType: string, staticLength: number, - internalTypeId: string + internalTypeId: string, ): string { // WARNING: ensure this still works if changing major solidity versions! // (the memory layout for static arrays may change) @@ -119,7 +119,7 @@ function renderUnwrapperStaticArray( functionName: string, elementType: string, staticLength: number, - internalTypeId: string + internalTypeId: string, ): string { // byte length for memory copying (more efficient than a loop) const byteLength = staticLength * 32; diff --git a/packages/common/src/codegen/utils/contractToInterface.ts b/packages/common/src/codegen/utils/contractToInterface.ts index 13c347290a..2e1e83e907 100644 --- a/packages/common/src/codegen/utils/contractToInterface.ts +++ b/packages/common/src/codegen/utils/contractToInterface.ts @@ -33,7 +33,7 @@ interface SymbolImport { */ export function contractToInterface( data: string, - contractName: string + contractName: string, ): { functions: ContractInterfaceFunction[]; errors: ContractInterfaceError[]; diff --git a/packages/common/src/codegen/utils/extractUserTypes.ts b/packages/common/src/codegen/utils/extractUserTypes.ts index 21f48c0ed2..8bdc960699 100644 --- a/packages/common/src/codegen/utils/extractUserTypes.ts +++ b/packages/common/src/codegen/utils/extractUserTypes.ts @@ -24,7 +24,7 @@ export interface SolidityUserDefinedType { export function extractUserTypes( data: string, userTypeNames: string[], - fromPath: string + fromPath: string, ): Record { const ast = parse(data); diff --git a/packages/common/src/codegen/utils/formatAndWrite.ts b/packages/common/src/codegen/utils/formatAndWrite.ts index f8cca27b1f..1121d58262 100644 --- a/packages/common/src/codegen/utils/formatAndWrite.ts +++ b/packages/common/src/codegen/utils/formatAndWrite.ts @@ -27,7 +27,7 @@ export async function formatAndWriteSolidity(output: string, fullOutputPath: str export async function formatAndWriteTypescript( output: string, fullOutputPath: string, - logPrefix: string + logPrefix: string, ): Promise { const formattedOutput = await formatTypescript(output); diff --git a/packages/common/src/codegen/utils/loadUserTypesFile.ts b/packages/common/src/codegen/utils/loadUserTypesFile.ts index cacbd59472..127299d92f 100644 --- a/packages/common/src/codegen/utils/loadUserTypesFile.ts +++ b/packages/common/src/codegen/utils/loadUserTypesFile.ts @@ -19,7 +19,7 @@ export type UserType = { export function loadAndExtractUserTypes( userTypes: Record, outputBaseDirectory: string, - remappings: [string, string][] + remappings: [string, string][], ): Record { const userTypesPerFile: Record = {}; for (const [userTypeName, { filePath: unresolvedFilePath }] of Object.entries(userTypes)) { @@ -37,7 +37,7 @@ export function loadAndExtractUserTypes( for (const [userTypeName, userType] of Object.entries(userTypesInFile)) { if (userType.internalTypeId !== userTypes[userTypeName].internalType) { throw new MUDError( - `User type "${userTypeName}" has internal type "${userType.internalTypeId}" but config specifies "${userTypes[userTypeName].internalType}"` + `User type "${userTypeName}" has internal type "${userType.internalTypeId}" but config specifies "${userTypes[userTypeName].internalType}"`, ); } } @@ -50,7 +50,7 @@ export function loadAndExtractUserTypes( function loadUserTypesFile( outputBaseDirectory: string, unresolvedFilePath: string, - remappings: [string, string][] + remappings: [string, string][], ): { filePath: string; data: string; diff --git a/packages/common/src/foundry/index.ts b/packages/common/src/foundry/index.ts index b7f29ee61a..83f20bff42 100644 --- a/packages/common/src/foundry/index.ts +++ b/packages/common/src/foundry/index.ts @@ -87,7 +87,7 @@ export async function getRemappings(profile?: string): Promise<[string, string][ */ export async function forge( args: string[], - options?: { profile?: string; silent?: boolean; env?: NodeJS.ProcessEnv } + options?: { profile?: string; silent?: boolean; env?: NodeJS.ProcessEnv }, ): Promise { const execOptions: Options = { env: { FOUNDRY_PROFILE: options?.profile, ...options?.env }, diff --git a/packages/common/src/getContract.ts b/packages/common/src/getContract.ts index a845359dd8..863eec55a2 100644 --- a/packages/common/src/getContract.ts +++ b/packages/common/src/getContract.ts @@ -42,7 +42,7 @@ export type GetContractOptions< TChain extends Chain, TAccount extends Account, TPublicClient extends PublicClient, - TWalletClient extends WalletClient + TWalletClient extends WalletClient, > = GetContractParameters< TTransport, TChain, @@ -63,7 +63,7 @@ export function getContract< TChain extends Chain, TAccount extends Account, TPublicClient extends PublicClient, - TWalletClient extends WalletClient + TWalletClient extends WalletClient, >({ abi, address, @@ -99,7 +99,7 @@ export function getContract< return ( ...parameters: [ args?: readonly unknown[], - options?: UnionOmit + options?: UnionOmit, ] ) => { const { args, options } = getFunctionParameters(parameters); @@ -125,7 +125,7 @@ export function getContract< return result; }; }, - } + }, ); } diff --git a/packages/common/src/hexToResource.ts b/packages/common/src/hexToResource.ts index 94178a9ed2..f95c93d15b 100644 --- a/packages/common/src/hexToResource.ts +++ b/packages/common/src/hexToResource.ts @@ -6,7 +6,7 @@ import { ReverseMap } from "./type-utils/common"; import { resourceToLabel } from "./resourceLabel"; const resourceTypeIdToType = Object.fromEntries( - Object.entries(resourceTypeIds).map(([key, value]) => [value, key]) + Object.entries(resourceTypeIds).map(([key, value]) => [value, key]), ) as ReverseMap; function getResourceType(resourceTypeId: string): ResourceType | undefined { diff --git a/packages/common/src/sendTransaction.ts b/packages/common/src/sendTransaction.ts index 9e64497825..7d08930f57 100644 --- a/packages/common/src/sendTransaction.ts +++ b/packages/common/src/sendTransaction.ts @@ -20,10 +20,10 @@ const debug = parentDebug.extend("sendTransaction"); export async function sendTransaction< TChain extends Chain | undefined, TAccount extends Account | undefined, - TChainOverride extends Chain | undefined + TChainOverride extends Chain | undefined, >( client: Client, - request: SendTransactionParameters + request: SendTransactionParameters, ): Promise { const rawAccount = request.account ?? client.account; if (!rawAccount) { @@ -83,8 +83,8 @@ export async function sendTransaction< // TODO: prepare again if there are gas errors? throw error; }, - } + }, ), - { throwOnTimeout: true } + { throwOnTimeout: true }, ); } diff --git a/packages/common/src/utils/groupBy.ts b/packages/common/src/utils/groupBy.ts index 5a81d49e3f..556f7a89b7 100644 --- a/packages/common/src/utils/groupBy.ts +++ b/packages/common/src/utils/groupBy.ts @@ -1,6 +1,6 @@ export function groupBy( values: readonly value[], - getKey: (value: value) => key + getKey: (value: value) => key, ): Map { const map = new Map(); for (const value of values) { diff --git a/packages/common/src/utils/mapObject.ts b/packages/common/src/utils/mapObject.ts index 189f568657..89434b19b9 100644 --- a/packages/common/src/utils/mapObject.ts +++ b/packages/common/src/utils/mapObject.ts @@ -3,9 +3,9 @@ */ export function mapObject< Source extends Record, - Target extends { [key in keyof Source]: unknown } + Target extends { [key in keyof Source]: unknown }, >(source: Source, valueMap: (value: Source[typeof key], key: keyof Source) => Target[typeof key]): Target { return Object.fromEntries( - Object.entries(source).map(([key, value]) => [key, valueMap(value as Source[keyof Source], key)]) + Object.entries(source).map(([key, value]) => [key, valueMap(value as Source[keyof Source], key)]), ) as Target; } diff --git a/packages/common/src/writeContract.ts b/packages/common/src/writeContract.ts index 973ecfb8bb..5818f18db4 100644 --- a/packages/common/src/writeContract.ts +++ b/packages/common/src/writeContract.ts @@ -26,10 +26,10 @@ export async function writeContract< abi extends Abi | readonly unknown[], functionName extends ContractFunctionName, args extends ContractFunctionArgs, - chainOverride extends Chain | undefined + chainOverride extends Chain | undefined, >( client: Client, - request: WriteContractParameters + request: WriteContractParameters, ): Promise { const rawAccount = request.account ?? client.account; if (!rawAccount) { @@ -88,8 +88,8 @@ export async function writeContract< // TODO: prepareWrite again if there are gas errors? throw error; }, - } + }, ), - { throwOnTimeout: true } + { throwOnTimeout: true }, ); } diff --git a/packages/config/src/library/dynamicResolution.ts b/packages/config/src/library/dynamicResolution.ts index 4fc1dbdbcc..cf6e4083eb 100644 --- a/packages/config/src/library/dynamicResolution.ts +++ b/packages/config/src/library/dynamicResolution.ts @@ -35,7 +35,7 @@ export function isDynamicResolution(value: unknown): value is DynamicResolution */ export function resolveWithContext( unresolved: any, - context: { systemAddresses?: Record>; tableIds?: Record } + context: { systemAddresses?: Record>; tableIds?: Record }, ): ValueWithType { if (!isDynamicResolution(unresolved)) return unresolved; let resolved: ValueWithType | undefined = undefined; diff --git a/packages/create-mud/CHANGELOG.md b/packages/create-mud/CHANGELOG.md index 71ccd47861..ddb24ed63f 100644 --- a/packages/create-mud/CHANGELOG.md +++ b/packages/create-mud/CHANGELOG.md @@ -636,7 +636,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/dev-tools/src/App.tsx b/packages/dev-tools/src/App.tsx index 08f1fd7ccb..0d74c3fcae 100644 --- a/packages/dev-tools/src/App.tsx +++ b/packages/dev-tools/src/App.tsx @@ -29,7 +29,7 @@ export function App() { className={twMerge( "pointer-events-auto w-full max-w-screen-sm h-full absolute right-0", "transition duration-500", - shown ? "translate-x-0" : "translate-x-full" + shown ? "translate-x-0" : "translate-x-full", )} >
@@ -49,7 +49,7 @@ export function App() { className={twMerge( "w-full h-full bg-slate-800 text-white/80 text-sm flex flex-col", "transition duration-500", - shown ? "opacity-100" : "opacity-0" + shown ? "opacity-100" : "opacity-0", )} > diff --git a/packages/dev-tools/src/actions/WriteSummary.tsx b/packages/dev-tools/src/actions/WriteSummary.tsx index 5ac4232835..8221805752 100644 --- a/packages/dev-tools/src/actions/WriteSummary.tsx +++ b/packages/dev-tools/src/actions/WriteSummary.tsx @@ -80,7 +80,7 @@ export function WriteSummary({ write }: Props) {
@@ -97,7 +97,7 @@ export function WriteSummary({ write }: Props) { target="_blank" className={twMerge( "flex-none font-mono text-xs text-white/40", - blockExplorer ? "hover:text-white/60 hover:underline" : null + blockExplorer ? "hover:text-white/60 hover:underline" : null, )} title={transactionReceipt.value.blockNumber.toString()} > @@ -110,7 +110,7 @@ export function WriteSummary({ write }: Props) { target="_blank" className={twMerge( "flex-none font-mono text-xs text-white/40", - blockExplorer ? "hover:text-white/60 hover:underline" : null + blockExplorer ? "hover:text-white/60 hover:underline" : null, )} title={hash.value} > diff --git a/packages/dev-tools/src/actions/getTransaction.ts b/packages/dev-tools/src/actions/getTransaction.ts index eba0191ee4..50763582b1 100644 --- a/packages/dev-tools/src/actions/getTransaction.ts +++ b/packages/dev-tools/src/actions/getTransaction.ts @@ -10,7 +10,7 @@ const cache: Record> = {}; export function getTransaction( publicClient: PublicClient, - write: ContractWrite + write: ContractWrite, ): Promise { if (!cache[write.id]) { cache[write.id] = write.result.then((hash) => publicClient.getTransaction({ hash })); diff --git a/packages/dev-tools/src/actions/getTransactionReceipt.ts b/packages/dev-tools/src/actions/getTransactionReceipt.ts index 531dcb06d3..425f840e74 100644 --- a/packages/dev-tools/src/actions/getTransactionReceipt.ts +++ b/packages/dev-tools/src/actions/getTransactionReceipt.ts @@ -7,7 +7,7 @@ const cache: Record> = {}; export function getTransactionReceipt( publicClient: PublicClient, - write: ContractWrite + write: ContractWrite, ): Promise { if (!cache[write.id]) { cache[write.id] = write.result.then((hash) => publicClient.waitForTransactionReceipt({ hash })); diff --git a/packages/dev-tools/src/actions/getTransactionResult.ts b/packages/dev-tools/src/actions/getTransactionResult.ts index e2c3f70d65..380f027b36 100644 --- a/packages/dev-tools/src/actions/getTransactionResult.ts +++ b/packages/dev-tools/src/actions/getTransactionResult.ts @@ -13,7 +13,7 @@ const cache: Record> = {}; export function getTransactionResult( publicClient: PublicClient, worldAbi: Abi, - write: ContractWrite + write: ContractWrite, ): Promise { if (!cache[write.id]) { const transaction = getTransaction(publicClient, write); diff --git a/packages/dev-tools/src/mount.tsx b/packages/dev-tools/src/mount.tsx index bfaff6c910..c54976211d 100644 --- a/packages/dev-tools/src/mount.tsx +++ b/packages/dev-tools/src/mount.tsx @@ -5,7 +5,7 @@ const containerId = "mud-dev-tools"; // TODO: rework to always return a unmount function (not a promise or possibly undefined) export async function mount( - opts: DevToolsOptions + opts: DevToolsOptions, ): Promise<(() => void) | undefined> { if (typeof window === "undefined") { console.warn("MUD dev-tools should only be used in browser bundles"); @@ -39,7 +39,7 @@ export async function mount( - + , ); document.body.appendChild(rootElement); diff --git a/packages/dev-tools/src/recs/ComponentDataTable.tsx b/packages/dev-tools/src/recs/ComponentDataTable.tsx index 5323d9af3f..6dce6eb87f 100644 --- a/packages/dev-tools/src/recs/ComponentDataTable.tsx +++ b/packages/dev-tools/src/recs/ComponentDataTable.tsx @@ -38,8 +38,8 @@ export function ComponentDataTable({ component }: Props) { {component.schema[name] === Type.T ? serialize(fieldValue) : Array.isArray(fieldValue) - ? fieldValue.map(String).join(", ") - : String(fieldValue)} + ? fieldValue.map(String).join(", ") + : String(fieldValue)} ); })} diff --git a/packages/dev-tools/src/recs/ComponentsPage.tsx b/packages/dev-tools/src/recs/ComponentsPage.tsx index ef95a1bb5b..9abc66bb9e 100644 --- a/packages/dev-tools/src/recs/ComponentsPage.tsx +++ b/packages/dev-tools/src/recs/ComponentsPage.tsx @@ -63,7 +63,7 @@ export function ComponentsPage() { }> } /> - - ) + , + ), ); diff --git a/packages/dev-tools/src/summary/SummaryPage.tsx b/packages/dev-tools/src/summary/SummaryPage.tsx index 230e18fa40..516aac5b16 100644 --- a/packages/dev-tools/src/summary/SummaryPage.tsx +++ b/packages/dev-tools/src/summary/SummaryPage.tsx @@ -8,7 +8,7 @@ import packageJson from "../../package.json"; import { useDevToolsContext } from "../DevToolsContext"; const isLinked = Object.entries(packageJson.dependencies).some( - ([name, version]) => name.startsWith("@latticexyz/") && version.startsWith("link:") + ([name, version]) => name.startsWith("@latticexyz/") && version.startsWith("link:"), ); export function SummaryPage() { diff --git a/packages/dev-tools/src/zustand/TablesPage.tsx b/packages/dev-tools/src/zustand/TablesPage.tsx index cd27b25dbc..4c28750e89 100644 --- a/packages/dev-tools/src/zustand/TablesPage.tsx +++ b/packages/dev-tools/src/zustand/TablesPage.tsx @@ -57,7 +57,7 @@ export function TablesPage() { (table: table): TableRecord
}>( - useStore.getState().getRecords(table) + useStore.getState().getRecords(table), ); useEffect(() => { return useStore.subscribe((state) => { diff --git a/packages/faucet/bin/parseEnv.ts b/packages/faucet/bin/parseEnv.ts index dd739618c9..7d17e6da78 100644 --- a/packages/faucet/bin/parseEnv.ts +++ b/packages/faucet/bin/parseEnv.ts @@ -13,7 +13,7 @@ const commonSchema = z.object({ }); export function parseEnv( - schema?: TSchema + schema?: TSchema, ): z.infer : typeof commonSchema> { const envSchema = schema !== undefined ? z.intersection(commonSchema, schema) : commonSchema; try { diff --git a/packages/faucet/src/createAppRouter.ts b/packages/faucet/src/createAppRouter.ts index c30c417911..ab8285c286 100644 --- a/packages/faucet/src/createAppRouter.ts +++ b/packages/faucet/src/createAppRouter.ts @@ -19,7 +19,7 @@ export function createAppRouter() { .input( z.object({ address: z.string().refine(isHex), - }) + }), ) .mutation(async (opts): Promise => { const { client, faucetAccount, dripAmount } = opts.ctx; diff --git a/packages/gas-report/ts/gas-report.ts b/packages/gas-report/ts/gas-report.ts index aac2397f12..2391c2f101 100755 --- a/packages/gas-report/ts/gas-report.ts +++ b/packages/gas-report/ts/gas-report.ts @@ -25,7 +25,7 @@ yargs(hideBin(process.argv)) console.error(chalk.red(msg)); if (msg.includes("Missing required argument")) { console.log( - chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`) + chalk.yellow(`Run 'pnpm mud ${process.argv[2]} --help' for a list of available and required arguments.`), ); } diff --git a/packages/phaserx/src/createCamera.ts b/packages/phaserx/src/createCamera.ts index d7df7d9c91..4c131a15f5 100644 --- a/packages/phaserx/src/createCamera.ts +++ b/packages/phaserx/src/createCamera.ts @@ -20,7 +20,7 @@ export function createCamera(phaserCamera: Phaser.Cameras.Scene2D.Camera, option onPinch: (state) => pinchStream$.next(state), onWheel: (state) => wheelStream$.next(state), }, - {} + {}, ); // function getNearestLevel(currentZoom: number): number { @@ -51,7 +51,7 @@ export function createCamera(phaserCamera: Phaser.Cameras.Scene2D.Camera, option return zoom + scaledDelta; }), // Compute pinch speed map((zoom) => Math.min(Math.max(zoom, options.minZoom), options.maxZoom)), // Limit zoom values - scan((acc, curr) => [acc[1], curr], [1, 1]) // keep track of the last value to offset the map position (not implemented yet) + scan((acc, curr) => [acc[1], curr], [1, 1]), // keep track of the last value to offset the map position (not implemented yet) ) .subscribe(([, zoom]) => { // Set the gesture zoom state to the current zoom value to avoid zooming beyond the max values @@ -67,7 +67,7 @@ export function createCamera(phaserCamera: Phaser.Cameras.Scene2D.Camera, option // @ts-ignore map((state) => state.delta.map((x) => x * options.wheelSpeed)), // Compute wheel speed map((movement) => movement.map((m: number) => m / phaserCamera.zoom)), // Adjust for current zoom value - map((movement) => [phaserCamera.scrollX + movement[0], phaserCamera.scrollY + movement[1]]) // Compute new pinch + map((movement) => [phaserCamera.scrollX + movement[0], phaserCamera.scrollY + movement[1]]), // Compute new pinch ) .subscribe(([x, y]) => { phaserCamera.setScroll(x, y); diff --git a/packages/phaserx/src/createChunks.ts b/packages/phaserx/src/createChunks.ts index a300c50f9d..f940574344 100644 --- a/packages/phaserx/src/createChunks.ts +++ b/packages/phaserx/src/createChunks.ts @@ -19,9 +19,9 @@ export function createChunks(worldView$: Observable, chunkSize: number, pa width: width + 2 * padding, height: height + 2 * padding, }, - chunkSize - ) - ) + chunkSize, + ), + ), ); visibleChunkStream.subscribe((newVisibleChunks) => { diff --git a/packages/phaserx/src/createCulling.ts b/packages/phaserx/src/createCulling.ts index 7df01f83e9..e17419422f 100644 --- a/packages/phaserx/src/createCulling.ts +++ b/packages/phaserx/src/createCulling.ts @@ -50,7 +50,7 @@ export function createCulling(objectPool: ObjectPool, camera: Camera, chunks: Ch map((chunk: ChunkCoord) => from(chunkRegistry.get(chunk))), // Map to streams of entityIds mergeMap((entities) => entities), // Flatten the stream of entities map((entityId) => objectPool.get(entityId, "Existing")), // Map entityId to embodiedEntity - filterNullish() + filterNullish(), ); // Spawn entities when their chunk appears in the viewport @@ -77,7 +77,7 @@ export function createCulling(objectPool: ObjectPool, camera: Camera, chunks: Ch entity.despawn(); } }, - { fireImmediately: true } + { fireImmediately: true }, ); disposer.set(entity.id, dispose); } diff --git a/packages/phaserx/src/createDebugger.ts b/packages/phaserx/src/createDebugger.ts index e33bba3cf0..7cbddf3ea8 100644 --- a/packages/phaserx/src/createDebugger.ts +++ b/packages/phaserx/src/createDebugger.ts @@ -15,7 +15,7 @@ export function createDebugger( chunks: Chunks, scene: Phaser.Scene, objectPool: ObjectPool, - map: AnimatedTilemap + map: AnimatedTilemap, ) { const options = { logViewport: false, @@ -47,8 +47,8 @@ export function createDebugger( console.log( `Entities: ${objectPool.objects.size} / Pool size: ${Object.values(objectPool.groups).reduce( (acc, curr) => acc + curr.getChildren().length, - 0 - )} / Pool active: ${Object.values(objectPool.groups).reduce((acc, curr) => acc + curr.countActive(), 0)}` + 0, + )} / Pool active: ${Object.values(objectPool.groups).reduce((acc, curr) => acc + curr.countActive(), 0)}`, ); } @@ -66,7 +66,7 @@ export function createDebugger( chunks.chunkSize, chunks.chunkSize, getRandomColor(), - 0.5 + 0.5, ); visualChunk.setInteractive(); visualChunk.on("pointerup", () => { diff --git a/packages/phaserx/src/createEmbodiedEntity.ts b/packages/phaserx/src/createEmbodiedEntity.ts index faf53312cb..765243607b 100644 --- a/packages/phaserx/src/createEmbodiedEntity.ts +++ b/packages/phaserx/src/createEmbodiedEntity.ts @@ -14,7 +14,7 @@ export function createEmbodiedEntity( id: string, group: Phaser.GameObjects.Group, type: Type, - currentCameraFilter = 0 + currentCameraFilter = 0, ): EmbodiedEntity { const position: PixelCoord = observable({ x: 0, y: 0 }); const onOnce = new Map>(); @@ -136,7 +136,7 @@ export function createEmbodiedEntity( function executeGameObjectFunctions( gameObject: GameObject, - functions: Iterable> + functions: Iterable>, ) { if (!gameObject) return; for (const func of functions) { @@ -145,7 +145,7 @@ function executeGameObjectFunctions( } function modifiesPosition( - func: GameObjectFunction + func: GameObjectFunction, ): Partial | undefined { let newPosition: Partial | undefined = undefined; const gameObjectProxy = new Proxy( @@ -162,7 +162,7 @@ function modifiesPosition( if (prop === "y") newPosition = newPosition ? { ...newPosition, y: value } : { y: value }; return true; }, - } + }, ); func(gameObjectProxy as GameObject); return newPosition; diff --git a/packages/phaserx/src/createInput.ts b/packages/phaserx/src/createInput.ts index f1569d9147..7f38908b6a 100644 --- a/packages/phaserx/src/createInput.ts +++ b/packages/phaserx/src/createInput.ts @@ -42,25 +42,25 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { map(() => { return { pointer: inputPlugin.manager?.activePointer }; }), - filterNullish() + filterNullish(), ); const pointerdown$: Observable<{ pointer: Phaser.Input.Pointer; event: MouseEvent }> = fromEvent( document, - "mousedown" + "mousedown", ).pipe( filter(() => enabled.current), map((event) => ({ pointer: inputPlugin.manager?.activePointer, event: event as MouseEvent })), - filterNullish() + filterNullish(), ); const pointerup$: Observable<{ pointer: Phaser.Input.Pointer; event: MouseEvent }> = fromEvent( document, - "mouseup" + "mouseup", ).pipe( filter(() => enabled.current), map((event) => ({ pointer: inputPlugin.manager?.activePointer, event: event as MouseEvent })), - filterNullish() + filterNullish(), ); // Click stream @@ -73,7 +73,7 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { bufferCount(2, 1), // Store the last two timestamps filter(([prev, now]) => prev[0] && !now[0] && now[1] - prev[1] < 250), // Only care if button was pressed before and is not anymore and it happened within 500ms map(() => inputPlugin.manager?.activePointer), // Return the current pointer - filterNullish() + filterNullish(), ); // Double click stream @@ -84,14 +84,14 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { filter(([prev, now]) => now - prev < 500), // Filter clicks with more than 500ms distance throttleTime(500), // A third click within 500ms is not counted as another double click map(() => inputPlugin.manager?.activePointer), // Return the current pointer - filterNullish() + filterNullish(), ); // Right click stream const rightClick$ = merge(pointerdown$, pointerup$).pipe( filter(({ pointer }) => enabled.current && pointer.rightButtonDown()), map(() => inputPlugin.manager?.activePointer), // Return the current pointer - filterNullish() + filterNullish(), ); // Drag stream @@ -106,14 +106,14 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { ? { ...acc, width: curr.worldX - acc.x, height: curr.worldY - acc.y } // Update the width/height : { x: curr.worldX, y: curr.worldY, width: 0, height: 0 } // Else start the drag : undefined, - undefined + undefined, ), filterNullish(), - filter((area) => Math.abs(area.width) > 10 && Math.abs(area.height) > 10) // Prevent clicking to be mistaken as a drag - ) + filter((area) => Math.abs(area.width) > 10 && Math.abs(area.height) > 10), // Prevent clicking to be mistaken as a drag + ), ).pipe( filter(() => enabled.current), - distinctUntilChanged() // Prevent same value to be emitted in a row + distinctUntilChanged(), // Prevent same value to be emitted in a row ); const pressedKeys = observable(new Set()); @@ -170,7 +170,7 @@ export function createInput(inputPlugin: Phaser.Input.InputPlugin) { (passes) => { if (passes) callback(); }, - { fireImmediately: true } + { fireImmediately: true }, ); disposers.add(disposer); } diff --git a/packages/phaserx/src/createObjectPool.ts b/packages/phaserx/src/createObjectPool.ts index 654be498e8..e3535487cc 100644 --- a/packages/phaserx/src/createObjectPool.ts +++ b/packages/phaserx/src/createObjectPool.ts @@ -22,7 +22,7 @@ export function createObjectPool(scene: Phaser.Scene) { function get( entity: number | string, - type: Type + type: Type, ): ObjectPoolReturnType { if (typeof entity === "number") entity = String(entity); let embodiedEntity = objects.get(entity); diff --git a/packages/phaserx/src/guards.ts b/packages/phaserx/src/guards.ts index 96681af748..e6e83b8510 100644 --- a/packages/phaserx/src/guards.ts +++ b/packages/phaserx/src/guards.ts @@ -19,7 +19,7 @@ export function defineAssetsConfig(assets: A) { } export function defineMapConfig, L extends LayerConfig>( - config: MapConfig + config: MapConfig, ) { return config; } @@ -29,7 +29,7 @@ export function defineSceneConfig< S extends { [key: string]: Sprite }, T extends TilesetConfig, M extends MapsConfig, - Ans extends Animation[] + Ans extends Animation[], >(config: SceneConfig) { return config; } @@ -44,14 +44,14 @@ export function defineCameraConfig(config: CameraConfig) { export function isSprite( gameObject: Phaser.GameObjects.GameObject, - type: keyof GameObjectTypes + type: keyof GameObjectTypes, ): gameObject is GameObject<"Sprite"> { return type === "Sprite"; } export function isRectangle( gameObject: Phaser.GameObjects.GameObject, - type: keyof GameObjectTypes + type: keyof GameObjectTypes, ): gameObject is GameObject<"Rectangle"> { return type === "Rectangle"; } diff --git a/packages/phaserx/src/tilemap/createAnimatedTilemap.ts b/packages/phaserx/src/tilemap/createAnimatedTilemap.ts index cf01db3e70..449f30ecff 100644 --- a/packages/phaserx/src/tilemap/createAnimatedTilemap.ts +++ b/packages/phaserx/src/tilemap/createAnimatedTilemap.ts @@ -7,7 +7,7 @@ import { createVirtualTilemap } from "./createVirtualTilemap"; import { TileAnimation } from "./types"; export function createAnimatedTilemap( - config: Omit, "tiles"> & { animationInterval: number } + config: Omit, "tiles"> & { animationInterval: number }, ): AnimatedTilemap { const { layerConfig: { layers, defaultLayer }, diff --git a/packages/phaserx/src/tilemap/createChunkedTilemap.ts b/packages/phaserx/src/tilemap/createChunkedTilemap.ts index 2f4b92187b..360a27248e 100644 --- a/packages/phaserx/src/tilemap/createChunkedTilemap.ts +++ b/packages/phaserx/src/tilemap/createChunkedTilemap.ts @@ -20,7 +20,7 @@ export type ChunkedTilemapConfig( - params: ChunkedTilemapConfig + params: ChunkedTilemapConfig, ): ChunkedTilemap { const { scene, tilesets, layerConfig, chunks, backgroundTile, tiles, tileWidth, tileHeight } = params; const relevantTilesets = Object.keys(layerConfig.layers) @@ -68,7 +68,7 @@ export function createChunkedTilemap( - config: Omit, "tiles"> + config: Omit, "tiles">, ): VirtualTilemap { const { chunks, diff --git a/packages/phaserx/src/types.ts b/packages/phaserx/src/types.ts index c059ebbf49..031de7a11e 100644 --- a/packages/phaserx/src/types.ts +++ b/packages/phaserx/src/types.ts @@ -26,7 +26,7 @@ export type GameObjectTypes = typeof GameObjectClasses; export type GameObject = InstanceType; export type GameObjectFunction = ( - gameObject: GameObject + gameObject: GameObject, ) => Promise | void; export type GameScene = ReturnType; @@ -135,7 +135,7 @@ export type SceneConfig< S extends { [key: string]: Sprite }, T extends TilesetConfig, M extends MapsConfig, - Ans extends Animation[] + Ans extends Animation[], > = { preload?: (scene: Phaser.Scene) => void; create?: (scene: Phaser.Scene) => void; diff --git a/packages/phaserx/src/utils/chunks.ts b/packages/phaserx/src/utils/chunks.ts index 587d4f50d8..b6e47c2a44 100644 --- a/packages/phaserx/src/utils/chunks.ts +++ b/packages/phaserx/src/utils/chunks.ts @@ -21,7 +21,7 @@ export function getChunksInArea(area: Area, chunkSize: number) { x: topLeftChunk.x + x, y: topLeftChunk.y + y, }, - true + true, ); } } diff --git a/packages/phaserx/src/utils/coords.ts b/packages/phaserx/src/utils/coords.ts index fcd197f74c..4d20821360 100644 --- a/packages/phaserx/src/utils/coords.ts +++ b/packages/phaserx/src/utils/coords.ts @@ -64,7 +64,7 @@ export function tileCoordToChunkCoord( tileCoord: WorldCoord, tileWidth: number, tileHeight: number, - chunkSize: number + chunkSize: number, ): ChunkCoord { const pixelCoord = tileCoordToPixelCoord(tileCoord, tileWidth, tileHeight); return pixelToChunkCoord(pixelCoord, chunkSize); @@ -74,7 +74,7 @@ export function chunkCoordToTileCoord( chunkCoord: ChunkCoord, tileWidth: number, tileHeight: number, - chunkSize: number + chunkSize: number, ): WorldCoord { const pixelCoord = chunkToPixelCoord(chunkCoord, chunkSize); return pixelCoordToTileCoord(pixelCoord, tileWidth, tileHeight); diff --git a/packages/phaserx/src/utils/generateFrames.ts b/packages/phaserx/src/utils/generateFrames.ts index ef9ad74aec..99fa4a8ab6 100644 --- a/packages/phaserx/src/utils/generateFrames.ts +++ b/packages/phaserx/src/utils/generateFrames.ts @@ -2,7 +2,7 @@ import { Animation, Assets } from "../types"; export function generateFrames( anims: Phaser.Animations.AnimationManager, - animation: Animation + animation: Animation, ): Phaser.Types.Animations.AnimationFrame[] { if (animation.prefix && animation.suffix) { return anims.generateFrameNames(animation.assetKey, { diff --git a/packages/protocol-parser/src/decodeDynamicField.test.ts b/packages/protocol-parser/src/decodeDynamicField.test.ts index 4ad3b8236f..1120adac5f 100644 --- a/packages/protocol-parser/src/decodeDynamicField.test.ts +++ b/packages/protocol-parser/src/decodeDynamicField.test.ts @@ -22,28 +22,28 @@ describe("decodeDynamicField", () => { it("can decode uint256[]", () => { expect( - decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000000") + decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000000"), ).toStrictEqual([0n]); expect( - decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000001") + decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000001"), ).toStrictEqual([1n]); expect( - decodeDynamicField("uint256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + decodeDynamicField("uint256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), ).toStrictEqual([115792089237316195423570985008687907853269984665640564039457584007913129639935n]); expect( - decodeDynamicField("uint256[]", "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe") + decodeDynamicField("uint256[]", "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"), ).toStrictEqual([115792089237316195423570985008687907853269984665640564039457584007913129639934n]); expect( decodeDynamicField( "uint256[]", - "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001" - ) + "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001", + ), ).toStrictEqual([1n, 1n]); expect( decodeDynamicField( "uint256[]", - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ) + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + ), ).toStrictEqual([ 115792089237316195423570985008687907853269984665640564039457584007913129639935n, 115792089237316195423570985008687907853269984665640564039457584007913129639935n, @@ -68,41 +68,41 @@ describe("decodeDynamicField", () => { it("can decode int256[]", () => { expect( - decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000000") + decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000000"), ).toStrictEqual([0n]); expect( - decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000001") + decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000001"), ).toStrictEqual([1n]); expect( - decodeDynamicField("int256[]", "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + decodeDynamicField("int256[]", "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), ).toStrictEqual([57896044618658097711785492504343953926634992332820282019728792003956564819967n]); expect( - decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000000") + decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000000"), ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819968n]); expect( - decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000001") + decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000001"), ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819967n]); expect( - decodeDynamicField("int256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + decodeDynamicField("int256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), ).toStrictEqual([-1n]); expect( decodeDynamicField( "int256[]", - "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" - ) + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + ), ).toStrictEqual([57896044618658097711785492504343953926634992332820282019728792003956564819967n, -1n]); expect( decodeDynamicField( "int256[]", - "0x80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" - ) + "0x80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + ), ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819968n, 0n]); expect( decodeDynamicField( "int256[]", - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000000000000000000000000000000000000000001" - ) + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000000000000000000000000000000000000000001", + ), ).toStrictEqual([-1n, -57896044618658097711785492504343953926634992332820282019728792003956564819967n]); }); @@ -129,13 +129,13 @@ describe("decodeDynamicField", () => { ]); expect(decodeDynamicField("bytes4[]", "0xff00ff00ff00ff00")).toStrictEqual(["0xff00ff00", "0xff00ff00"]); expect( - decodeDynamicField("bytes32[]", "0x0000000000000000000000000000000000000000000000000000000000000001") + decodeDynamicField("bytes32[]", "0x0000000000000000000000000000000000000000000000000000000000000001"), ).toStrictEqual(["0x0000000000000000000000000000000000000000000000000000000000000001"]); expect( decodeDynamicField( "bytes32[]", - "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" - ) + "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001", + ), ).toStrictEqual([ "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000001", @@ -151,10 +151,10 @@ describe("decodeDynamicField", () => { ]); expect(() => decodeDynamicField("address[]", "0x00")).toThrow( - 'Hex value "0x00" has length of 2, but expected a multiple of 40 for address[] type.' + 'Hex value "0x00" has length of 2, but expected a multiple of 40 for address[] type.', ); expect(() => decodeDynamicField("address[]", "0xffffffffffffffffffffffffffffffffffffffffff")).toThrow( - 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected a multiple of 40 for address[] type.' + 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected a multiple of 40 for address[] type.', ); }); @@ -164,7 +164,7 @@ describe("decodeDynamicField", () => { expect(decodeDynamicField("bytes", "0x0001")).toBe("0x0001"); expect(decodeDynamicField("bytes", "0xff00ff00ff00ff00")).toBe("0xff00ff00ff00ff00"); expect(decodeDynamicField("bytes", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe( - "0x0000000000000000000000000000000000000000000000000000000000000001" + "0x0000000000000000000000000000000000000000000000000000000000000001", ); }); diff --git a/packages/protocol-parser/src/decodeDynamicField.ts b/packages/protocol-parser/src/decodeDynamicField.ts index 3fcb63876c..d9eaf52b64 100644 --- a/packages/protocol-parser/src/decodeDynamicField.ts +++ b/packages/protocol-parser/src/decodeDynamicField.ts @@ -14,7 +14,7 @@ import { InvalidHexLengthError, InvalidHexLengthForArrayFieldError } from "./err export function decodeDynamicField< TAbiType extends DynamicAbiType, - TPrimitiveType extends DynamicAbiTypeToPrimitiveType + TPrimitiveType extends DynamicAbiTypeToPrimitiveType, >(abiType: TAbiType, data: Hex): TPrimitiveType { if (abiType === "bytes") { return data as TPrimitiveType; diff --git a/packages/protocol-parser/src/decodeField.ts b/packages/protocol-parser/src/decodeField.ts index b3a63059d5..e6b6d881c7 100644 --- a/packages/protocol-parser/src/decodeField.ts +++ b/packages/protocol-parser/src/decodeField.ts @@ -5,7 +5,7 @@ import { decodeStaticField } from "./decodeStaticField"; export function decodeField< TAbiType extends SchemaAbiType, - TPrimitiveType extends SchemaAbiTypeToPrimitiveType + TPrimitiveType extends SchemaAbiTypeToPrimitiveType, >(abiType: TAbiType, data: Hex): TPrimitiveType { return ( isDynamicAbiType(abiType) ? decodeDynamicField(abiType, data) : decodeStaticField(abiType, data) diff --git a/packages/protocol-parser/src/decodeKey.ts b/packages/protocol-parser/src/decodeKey.ts index 2b11552ad8..bec0695e6a 100644 --- a/packages/protocol-parser/src/decodeKey.ts +++ b/packages/protocol-parser/src/decodeKey.ts @@ -4,12 +4,12 @@ import { decodeKeyTuple } from "./decodeKeyTuple"; export function decodeKey( keySchema: TSchema, - data: readonly Hex[] + data: readonly Hex[], ): SchemaToPrimitives { // TODO: refactor and move all decodeKeyTuple logic into this method so we can delete decodeKeyTuple const keyValues = decodeKeyTuple({ staticFields: Object.values(keySchema), dynamicFields: [] }, data); return Object.fromEntries( - Object.keys(keySchema).map((name, i) => [name, keyValues[i]]) + Object.keys(keySchema).map((name, i) => [name, keyValues[i]]), ) as SchemaToPrimitives; } diff --git a/packages/protocol-parser/src/decodeKeyTuple.test.ts b/packages/protocol-parser/src/decodeKeyTuple.test.ts index 362118332d..cd1c2c14c1 100644 --- a/packages/protocol-parser/src/decodeKeyTuple.test.ts +++ b/packages/protocol-parser/src/decodeKeyTuple.test.ts @@ -6,12 +6,12 @@ describe("decodeKeyTuple", () => { expect( decodeKeyTuple({ staticFields: ["bool"], dynamicFields: [] }, [ "0x0000000000000000000000000000000000000000000000000000000000000000", - ]) + ]), ).toStrictEqual([false]); expect( decodeKeyTuple({ staticFields: ["bool"], dynamicFields: [] }, [ "0x0000000000000000000000000000000000000000000000000000000000000001", - ]) + ]), ).toStrictEqual([true]); }); @@ -24,7 +24,7 @@ describe("decodeKeyTuple", () => { "0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000003", - ]) + ]), ).toStrictEqual([ 42n, -42, diff --git a/packages/protocol-parser/src/decodeKeyTuple.ts b/packages/protocol-parser/src/decodeKeyTuple.ts index 623df1fac1..426806dd68 100644 --- a/packages/protocol-parser/src/decodeKeyTuple.ts +++ b/packages/protocol-parser/src/decodeKeyTuple.ts @@ -8,10 +8,10 @@ import { Schema } from "./common"; export function decodeKeyTuple(keySchema: Schema, keyTuple: readonly Hex[]): StaticPrimitiveType[] { if (keySchema.staticFields.length !== keyTuple.length) { throw new Error( - `key tuple length ${keyTuple.length} does not match key schema length ${keySchema.staticFields.length}` + `key tuple length ${keyTuple.length} does not match key schema length ${keySchema.staticFields.length}`, ); } return keyTuple.map( - (key, index) => decodeAbiParameters([{ type: keySchema.staticFields[index] }], key)[0] as StaticPrimitiveType + (key, index) => decodeAbiParameters([{ type: keySchema.staticFields[index] }], key)[0] as StaticPrimitiveType, ); } diff --git a/packages/protocol-parser/src/decodeRecord.test.ts b/packages/protocol-parser/src/decodeRecord.test.ts index 87e357f599..f09283c4ab 100644 --- a/packages/protocol-parser/src/decodeRecord.test.ts +++ b/packages/protocol-parser/src/decodeRecord.test.ts @@ -6,7 +6,7 @@ describe("decodeRecord", () => { const valueSchema = { staticFields: ["uint32", "uint128"], dynamicFields: ["uint32[]", "string"] } as const; const values = decodeRecord( valueSchema, - "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67" + "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67", ); expect(values).toStrictEqual([1, 2n, [3, 4], "some string"]); }); diff --git a/packages/protocol-parser/src/decodeRecord.ts b/packages/protocol-parser/src/decodeRecord.ts index 411d93327c..1ae389fbcf 100644 --- a/packages/protocol-parser/src/decodeRecord.ts +++ b/packages/protocol-parser/src/decodeRecord.ts @@ -34,7 +34,7 @@ export function decodeRecord(valueSchema: Schema, data: Hex): readonly (StaticPr expectedLength: schemaStaticDataLength, actualLength: actualStaticDataLength, bytesOffset, - } + }, ); } @@ -63,7 +63,7 @@ export function decodeRecord(valueSchema: Schema, data: Hex): readonly (StaticPr expectedLength: dataLayout.totalByteLength, actualLength: actualDynamicDataLength, bytesOffset, - } + }, ); } } diff --git a/packages/protocol-parser/src/decodeStaticField.test.ts b/packages/protocol-parser/src/decodeStaticField.test.ts index 8ad29713aa..307b324a97 100644 --- a/packages/protocol-parser/src/decodeStaticField.test.ts +++ b/packages/protocol-parser/src/decodeStaticField.test.ts @@ -7,22 +7,22 @@ describe("decodeStaticField", () => { expect(decodeStaticField("bool", "0x01")).toBe(true); expect(() => decodeStaticField("bool", "0x0")).toThrow( - 'Hex value "0x0" has length of 1, but expected length of 2 for bool type.' + 'Hex value "0x0" has length of 1, but expected length of 2 for bool type.', ); expect(() => decodeStaticField("bool", "0x1")).toThrow( - 'Hex value "0x1" has length of 1, but expected length of 2 for bool type.' + 'Hex value "0x1" has length of 1, but expected length of 2 for bool type.', ); expect(() => decodeStaticField("bool", "0x000")).toThrow( - 'Hex value "0x000" is an odd length (3). It must be an even length.' + 'Hex value "0x000" is an odd length (3). It must be an even length.', ); expect(() => decodeStaticField("bool", "0x001")).toThrow( - 'Hex value "0x001" is an odd length (3). It must be an even length.' + 'Hex value "0x001" is an odd length (3). It must be an even length.', ); expect(() => decodeStaticField("bool", "0x0000")).toThrow( - 'Hex value "0x0000" has length of 4, but expected length of 2 for bool type.' + 'Hex value "0x0000" has length of 4, but expected length of 2 for bool type.', ); expect(() => decodeStaticField("bool", "0x0001")).toThrow( - 'Hex value "0x0001" has length of 4, but expected length of 2 for bool type.' + 'Hex value "0x0001" has length of 4, but expected length of 2 for bool type.', ); }); @@ -36,10 +36,10 @@ describe("decodeStaticField", () => { expect(decodeStaticField("uint256", "0x0000000000000000000000000000000000000000000000000000000000000000")).toBe(0n); expect(decodeStaticField("uint256", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe(1n); expect(decodeStaticField("uint256", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).toBe( - 115792089237316195423570985008687907853269984665640564039457584007913129639935n + 115792089237316195423570985008687907853269984665640564039457584007913129639935n, ); expect(decodeStaticField("uint256", "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")).toBe( - 115792089237316195423570985008687907853269984665640564039457584007913129639934n + 115792089237316195423570985008687907853269984665640564039457584007913129639934n, ); }); @@ -56,13 +56,13 @@ describe("decodeStaticField", () => { expect(decodeStaticField("int256", "0x0000000000000000000000000000000000000000000000000000000000000000")).toBe(0n); expect(decodeStaticField("int256", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe(1n); expect(decodeStaticField("int256", "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).toBe( - 57896044618658097711785492504343953926634992332820282019728792003956564819967n + 57896044618658097711785492504343953926634992332820282019728792003956564819967n, ); expect(decodeStaticField("int256", "0x8000000000000000000000000000000000000000000000000000000000000000")).toBe( - -57896044618658097711785492504343953926634992332820282019728792003956564819968n + -57896044618658097711785492504343953926634992332820282019728792003956564819968n, ); expect(decodeStaticField("int256", "0x8000000000000000000000000000000000000000000000000000000000000001")).toBe( - -57896044618658097711785492504343953926634992332820282019728792003956564819967n + -57896044618658097711785492504343953926634992332820282019728792003956564819967n, ); expect(decodeStaticField("int256", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")).toBe(-1n); }); @@ -72,23 +72,23 @@ describe("decodeStaticField", () => { expect(decodeStaticField("bytes2", "0x0001")).toBe("0x0001"); expect(decodeStaticField("bytes8", "0xff00ff00ff00ff00")).toBe("0xff00ff00ff00ff00"); expect(decodeStaticField("bytes32", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe( - "0x0000000000000000000000000000000000000000000000000000000000000001" + "0x0000000000000000000000000000000000000000000000000000000000000001", ); }); it("can decode address", () => { expect(decodeStaticField("address", "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266")).toBe( - "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" + "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", ); expect(decodeStaticField("address", "0xffffffffffffffffffffffffffffffffffffffff")).toBe( - "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF" + "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF", ); expect(() => decodeStaticField("address", "0x00")).toThrow( - 'Hex value "0x00" has length of 2, but expected length of 40 for address type.' + 'Hex value "0x00" has length of 2, but expected length of 40 for address type.', ); expect(() => decodeStaticField("address", "0xffffffffffffffffffffffffffffffffffffffffff")).toThrow( - 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected length of 40 for address type.' + 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected length of 40 for address type.', ); }); }); diff --git a/packages/protocol-parser/src/decodeStaticField.ts b/packages/protocol-parser/src/decodeStaticField.ts index e8595d8832..9d2819d307 100644 --- a/packages/protocol-parser/src/decodeStaticField.ts +++ b/packages/protocol-parser/src/decodeStaticField.ts @@ -10,7 +10,7 @@ import { InvalidHexLengthError, InvalidHexLengthForStaticFieldError } from "./er export function decodeStaticField< TAbiType extends StaticAbiType, - TPrimitiveType extends StaticAbiTypeToPrimitiveType + TPrimitiveType extends StaticAbiTypeToPrimitiveType, >(abiType: TAbiType, data: Hex): TPrimitiveType { if (data.length > 3 && data.length % 2 !== 0) { throw new InvalidHexLengthError(data); diff --git a/packages/protocol-parser/src/decodeValue.ts b/packages/protocol-parser/src/decodeValue.ts index bd96093fed..06bb1a4b4a 100644 --- a/packages/protocol-parser/src/decodeValue.ts +++ b/packages/protocol-parser/src/decodeValue.ts @@ -11,6 +11,6 @@ export function decodeValue(valueSchema: TSchema, d const valueTuple = decodeRecord({ staticFields, dynamicFields }, data); return Object.fromEntries( - Object.keys(valueSchema).map((name, i) => [name, valueTuple[i]]) + Object.keys(valueSchema).map((name, i) => [name, valueTuple[i]]), ) as SchemaToPrimitives; } diff --git a/packages/protocol-parser/src/decodeValueArgs.ts b/packages/protocol-parser/src/decodeValueArgs.ts index d9f5e5161f..62966ba93d 100644 --- a/packages/protocol-parser/src/decodeValueArgs.ts +++ b/packages/protocol-parser/src/decodeValueArgs.ts @@ -7,7 +7,7 @@ import { readHex } from "@latticexyz/common"; export function decodeValueArgs( valueSchema: TSchema, - { staticData, encodedLengths, dynamicData }: ValueArgs + { staticData, encodedLengths, dynamicData }: ValueArgs, ): SchemaToPrimitives { return decodeValue( valueSchema, @@ -15,6 +15,6 @@ export function decodeValueArgs( readHex(staticData, 0, staticDataLength(Object.values(valueSchema).filter(isStaticAbiType))), encodedLengths, dynamicData, - ]) + ]), ); } diff --git a/packages/protocol-parser/src/encodeField.ts b/packages/protocol-parser/src/encodeField.ts index 99e977a850..cacfda1caf 100644 --- a/packages/protocol-parser/src/encodeField.ts +++ b/packages/protocol-parser/src/encodeField.ts @@ -4,7 +4,7 @@ import { Hex, encodePacked } from "viem"; export function encodeField( fieldType: TSchemaAbiType, - value: AbiParameterToPrimitiveType<{ type: TSchemaAbiType }> + value: AbiParameterToPrimitiveType<{ type: TSchemaAbiType }>, ): Hex { if (isArrayAbiType(fieldType) && Array.isArray(value)) { const staticFieldType = arrayAbiTypeToStaticAbiType(fieldType); @@ -13,7 +13,7 @@ export function encodeField( ? "0x" : encodePacked( value.map(() => staticFieldType), - value + value, ); } return encodePacked([fieldType], [value]); diff --git a/packages/protocol-parser/src/encodeKeyTuple.test.ts b/packages/protocol-parser/src/encodeKeyTuple.test.ts index 048e0d2921..2d712fdfe3 100644 --- a/packages/protocol-parser/src/encodeKeyTuple.test.ts +++ b/packages/protocol-parser/src/encodeKeyTuple.test.ts @@ -12,8 +12,8 @@ describe("encodeKeyTuple", () => { staticFields: ["bool"], dynamicFields: [], }, - [true] - ) + [true], + ), ).toStrictEqual(["0x0000000000000000000000000000000000000000000000000000000000000001"]); }); @@ -26,7 +26,7 @@ describe("encodeKeyTuple", () => { "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF", true, 3, - ]) + ]), ).toStrictEqual([ "0x000000000000000000000000000000000000000000000000000000000000002a", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd6", diff --git a/packages/protocol-parser/src/encodeLengths.test.ts b/packages/protocol-parser/src/encodeLengths.test.ts index 70d6b53187..8bd77ba7de 100644 --- a/packages/protocol-parser/src/encodeLengths.test.ts +++ b/packages/protocol-parser/src/encodeLengths.test.ts @@ -4,13 +4,13 @@ import { encodeLengths } from "./encodeLengths"; describe("encodeLengths", () => { it("can encode empty tuple", () => { expect(encodeLengths([])).toMatchInlineSnapshot( - '"0x0000000000000000000000000000000000000000000000000000000000000000"' + '"0x0000000000000000000000000000000000000000000000000000000000000000"', ); }); it("can encode bool key tuple", () => { expect(encodeLengths(["0x1234", "0x12345678"])).toMatchInlineSnapshot( - '"0x0000000000000000000000000000000000000004000000000200000000000006"' + '"0x0000000000000000000000000000000000000004000000000200000000000006"', ); }); }); diff --git a/packages/protocol-parser/src/encodeLengths.ts b/packages/protocol-parser/src/encodeLengths.ts index 5a3bbf0827..156e275f84 100644 --- a/packages/protocol-parser/src/encodeLengths.ts +++ b/packages/protocol-parser/src/encodeLengths.ts @@ -7,6 +7,6 @@ export function encodeLengths(values: Hex[]): Hex { return padHex( concatHex([...byteLengths.map((length) => encodeField("uint40", length)), encodeField("uint56", totalByteLength)]), - { size: 32, dir: "left" } + { size: 32, dir: "left" }, ); } diff --git a/packages/protocol-parser/src/encodeRecord.test.ts b/packages/protocol-parser/src/encodeRecord.test.ts index 29222756fa..33be538fd3 100644 --- a/packages/protocol-parser/src/encodeRecord.test.ts +++ b/packages/protocol-parser/src/encodeRecord.test.ts @@ -6,7 +6,7 @@ describe("encodeRecord", () => { const valueSchema = { staticFields: ["uint32", "uint128"], dynamicFields: ["uint32[]", "string"] } as const; const hex = encodeRecord(valueSchema, [1, 2n, [3, 4], "some string"]); expect(hex).toBe( - "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67" + "0x0000000100000000000000000000000000000002000000000000000000000000000000000000000b0000000008000000000000130000000300000004736f6d6520737472696e67", ); }); diff --git a/packages/protocol-parser/src/encodeRecord.ts b/packages/protocol-parser/src/encodeRecord.ts index b92287830c..6c0e0f4daf 100644 --- a/packages/protocol-parser/src/encodeRecord.ts +++ b/packages/protocol-parser/src/encodeRecord.ts @@ -6,7 +6,7 @@ import { Schema } from "./common"; /** @deprecated use `encodeValue` instead */ export function encodeRecord( valueSchema: Schema, - values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[] + values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[], ): Hex { const staticValues = values.slice(0, valueSchema.staticFields.length) as readonly StaticPrimitiveType[]; const dynamicValues = values.slice(valueSchema.staticFields.length) as readonly DynamicPrimitiveType[]; @@ -18,7 +18,7 @@ export function encodeRecord( if (valueSchema.dynamicFields.length === 0) return `0x${staticData}`; const dynamicDataItems = dynamicValues.map((value, i) => - encodeField(valueSchema.dynamicFields[i], value).replace(/^0x/, "") + encodeField(valueSchema.dynamicFields[i], value).replace(/^0x/, ""), ); const dynamicFieldByteLengths = dynamicDataItems.map((value) => value.length / 2).reverse(); diff --git a/packages/protocol-parser/src/encodeValue.ts b/packages/protocol-parser/src/encodeValue.ts index df85964b65..accb91e0a1 100644 --- a/packages/protocol-parser/src/encodeValue.ts +++ b/packages/protocol-parser/src/encodeValue.ts @@ -4,7 +4,7 @@ import { encodeValueArgs } from "./encodeValueArgs"; export function encodeValue( valueSchema: TSchema, - value: SchemaToPrimitives + value: SchemaToPrimitives, ): Hex { const { staticData, encodedLengths, dynamicData } = encodeValueArgs(valueSchema, value); return concatHex([staticData, encodedLengths, dynamicData]); diff --git a/packages/protocol-parser/src/encodeValueArgs.ts b/packages/protocol-parser/src/encodeValueArgs.ts index 5100f4f753..bc0723f93f 100644 --- a/packages/protocol-parser/src/encodeValueArgs.ts +++ b/packages/protocol-parser/src/encodeValueArgs.ts @@ -13,7 +13,7 @@ import { encodeLengths } from "./encodeLengths"; export function encodeValueArgs( valueSchema: TSchema, - value: SchemaToPrimitives + value: SchemaToPrimitives, ): ValueArgs { const valueSchemaEntries = Object.entries(valueSchema); const staticFields = valueSchemaEntries.filter(([, type]) => isStaticAbiType(type)) as [string, StaticAbiType][]; @@ -23,7 +23,7 @@ export function encodeValueArgs( const encodedStaticValues = staticFields.map(([name, type]) => encodeField(type, value[name] as StaticPrimitiveType)); const encodedDynamicValues = dynamicFields.map(([name, type]) => - encodeField(type, value[name] as DynamicPrimitiveType) + encodeField(type, value[name] as DynamicPrimitiveType), ); const encodedLengths = encodeLengths(encodedDynamicValues); diff --git a/packages/protocol-parser/src/errors.ts b/packages/protocol-parser/src/errors.ts index 1071b89564..168d0eb93d 100644 --- a/packages/protocol-parser/src/errors.ts +++ b/packages/protocol-parser/src/errors.ts @@ -29,7 +29,7 @@ export class InvalidHexLengthForStaticFieldError extends MUDError { super( `Hex value "${value}" has length of ${value.length - 2}, but expected length of ${ staticAbiTypeToByteLength[abiType] * 2 - } for ${abiType} type.` + } for ${abiType} type.`, ); } } @@ -40,7 +40,7 @@ export class InvalidHexLengthForArrayFieldError extends MUDError { super( `Hex value "${value}" has length of ${value.length - 2}, but expected a multiple of ${ staticAbiTypeToByteLength[abiType] * 2 - } for ${abiType}[] type.` + } for ${abiType}[] type.`, ); } } @@ -50,7 +50,7 @@ export class SchemaStaticLengthMismatchError extends MUDError { constructor(schemaData: Hex, definedLength: number, summedLength: number) { super( `Schema "${schemaData}" static data length (${definedLength}) did not match the summed length of all static fields (${summedLength}). ` + - `Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?` + `Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`, ); } } @@ -59,7 +59,7 @@ export class PackedCounterLengthMismatchError extends MUDError { override name = "PackedCounterLengthMismatchError"; constructor(packedCounterData: Hex, definedLength: bigint, summedLength: bigint) { super( - `PackedCounter "${packedCounterData}" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).` + `PackedCounter "${packedCounterData}" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).`, ); } } diff --git a/packages/protocol-parser/src/hexToPackedCounter.test.ts b/packages/protocol-parser/src/hexToPackedCounter.test.ts index 82537cc018..91e6a090e0 100644 --- a/packages/protocol-parser/src/hexToPackedCounter.test.ts +++ b/packages/protocol-parser/src/hexToPackedCounter.test.ts @@ -20,16 +20,16 @@ describe("hexToPackedCounter", () => { it("throws if schema hex data is not bytes32", () => { expect(() => hexToPackedCounter("0x01234")).toThrowErrorMatchingInlineSnapshot( - '"Hex value \\"0x01234\\" has length of 5, but expected length of 64 for a packed counter."' + '"Hex value \\"0x01234\\" has length of 5, but expected length of 64 for a packed counter."', ); }); it("throws if packed counter total byte length doesn't match summed byte length of fields", () => { expect(() => - hexToPackedCounter("0x0000000000000000000000000000400000000020000000002000000000000040") + hexToPackedCounter("0x0000000000000000000000000000400000000020000000002000000000000040"), ).toThrowErrorMatchingInlineSnapshot( // eslint-disable-next-line max-len - '"PackedCounter \\"0x0000000000000000000000000000400000000020000000002000000000000040\\" total bytes length (64) did not match the summed length of all field byte lengths (128)."' + '"PackedCounter \\"0x0000000000000000000000000000400000000020000000002000000000000040\\" total bytes length (64) did not match the summed length of all field byte lengths (128)."', ); }); }); diff --git a/packages/protocol-parser/src/hexToSchema.test.ts b/packages/protocol-parser/src/hexToSchema.test.ts index a73b132bbf..cbff4ee435 100644 --- a/packages/protocol-parser/src/hexToSchema.test.ts +++ b/packages/protocol-parser/src/hexToSchema.test.ts @@ -55,14 +55,14 @@ describe("hexToSchema", () => { it("throws if schema hex data is not bytes32", () => { expect(() => hexToSchema("0x002502045f2381c3c4c5")).toThrow( - 'Hex value "0x002502045f2381c3c4c5" has length of 20, but expected length of 64 for a schema.' + 'Hex value "0x002502045f2381c3c4c5" has length of 20, but expected length of 64 for a schema.', ); }); it("throws if schema static field lengths do not match", () => { expect(() => hexToSchema("0x002502045f2381c3c4c500000000000000000000000000000000000000000000")).toThrow( // eslint-disable-next-line max-len - 'Schema "0x002502045f2381c3c4c500000000000000000000000000000000000000000000" static data length (37) did not match the summed length of all static fields (36). Is `staticAbiTypeToByteLength` up to date with Solidity schema types?' + 'Schema "0x002502045f2381c3c4c500000000000000000000000000000000000000000000" static data length (37) did not match the summed length of all static fields (36). Is `staticAbiTypeToByteLength` up to date with Solidity schema types?', ); }); }); diff --git a/packages/protocol-parser/src/hexToSchema.ts b/packages/protocol-parser/src/hexToSchema.ts index ff16f1e5cc..b0b74211bb 100644 --- a/packages/protocol-parser/src/hexToSchema.ts +++ b/packages/protocol-parser/src/hexToSchema.ts @@ -28,7 +28,7 @@ export function hexToSchema(data: Hex): Schema { if (actualStaticDataLength !== staticDataLength) { console.warn( `Schema "${data}" static data length (${staticDataLength}) did not match the summed length of all static fields (${actualStaticDataLength}). ` + - `Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?` + `Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`, ); throw new SchemaStaticLengthMismatchError(data, staticDataLength, actualStaticDataLength); } diff --git a/packages/protocol-parser/src/schemaToHex.test.ts b/packages/protocol-parser/src/schemaToHex.test.ts index 57e051e5fe..82860e7331 100644 --- a/packages/protocol-parser/src/schemaToHex.test.ts +++ b/packages/protocol-parser/src/schemaToHex.test.ts @@ -4,13 +4,13 @@ import { schemaToHex } from "./schemaToHex"; describe("schemaToHex", () => { it("converts schema to hex", () => { expect(schemaToHex({ staticFields: ["bool"], dynamicFields: [] })).toBe( - "0x0001010060000000000000000000000000000000000000000000000000000000" + "0x0001010060000000000000000000000000000000000000000000000000000000", ); expect(schemaToHex({ staticFields: ["bool"], dynamicFields: ["bool[]"] })).toBe( - "0x0001010160c20000000000000000000000000000000000000000000000000000" + "0x0001010160c20000000000000000000000000000000000000000000000000000", ); expect( - schemaToHex({ staticFields: ["bytes32", "int32"], dynamicFields: ["uint256[]", "address[]", "bytes", "string"] }) + schemaToHex({ staticFields: ["bytes32", "int32"], dynamicFields: ["uint256[]", "address[]", "bytes", "string"] }), ).toBe("0x002402045f2381c3c4c500000000000000000000000000000000000000000000"); }); }); diff --git a/packages/react/src/useComponentValue.ts b/packages/react/src/useComponentValue.ts index fecb60ede4..aa7a7bbd10 100644 --- a/packages/react/src/useComponentValue.ts +++ b/packages/react/src/useComponentValue.ts @@ -13,18 +13,18 @@ import { useEffect, useState } from "react"; export function useComponentValue( component: Component, entity: Entity | undefined, - defaultValue: ComponentValue + defaultValue: ComponentValue, ): ComponentValue; export function useComponentValue( component: Component, - entity: Entity | undefined + entity: Entity | undefined, ): ComponentValue | undefined; export function useComponentValue( component: Component, entity: Entity | undefined, - defaultValue?: ComponentValue + defaultValue?: ComponentValue, ) { const [value, setValue] = useState(entity != null ? getComponentValue(component, entity) : undefined); diff --git a/packages/react/src/useEntityQuery.test.ts b/packages/react/src/useEntityQuery.test.ts index 484a8e80a5..12811c388c 100644 --- a/packages/react/src/useEntityQuery.test.ts +++ b/packages/react/src/useEntityQuery.test.ts @@ -36,7 +36,7 @@ describe("useEntityQuery", () => { const { result } = renderHook(() => useEntityQuery([Has(Position)], { updateOnValueChange: false })); const { result: resultOnValueChange } = renderHook(() => - useEntityQuery([Has(Position)], { updateOnValueChange: true }) + useEntityQuery([Has(Position)], { updateOnValueChange: true }), ); expect(result.current.length).toBe(2); @@ -80,7 +80,7 @@ describe("useEntityQuery", () => { const { result } = renderHook(() => useEntityQuery([Has(Position)], { updateOnValueChange: false })); const { result: resultOnValueChange } = renderHook(() => - useEntityQuery([Has(Position)], { updateOnValueChange: true }) + useEntityQuery([Has(Position)], { updateOnValueChange: true }), ); expect(result.all).toHaveLength(2); diff --git a/packages/react/src/usePromise.ts b/packages/react/src/usePromise.ts index a53806d37d..2c3fbfa111 100644 --- a/packages/react/src/usePromise.ts +++ b/packages/react/src/usePromise.ts @@ -7,7 +7,7 @@ export type UsePromiseResult = PromiseSettledResult> | { status: " export function usePromise(promise: PromiseLike | null | undefined) { const promiseRef = useRef(promise); const [result, setResult] = useState>( - promise == null ? { status: "idle" } : { status: "pending" } + promise == null ? { status: "idle" } : { status: "pending" }, ); useEffect(() => { diff --git a/packages/recs/CHANGELOG.md b/packages/recs/CHANGELOG.md index 4de2c01b38..472da33f59 100644 --- a/packages/recs/CHANGELOG.md +++ b/packages/recs/CHANGELOG.md @@ -339,7 +339,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/recs/src/Component.ts b/packages/recs/src/Component.ts index 58a56e8047..ccc5d038a5 100644 --- a/packages/recs/src/Component.ts +++ b/packages/recs/src/Component.ts @@ -55,7 +55,7 @@ function getComponentName(component: Component) { export function defineComponent( world: World, schema: S, - options?: { id?: string; metadata?: M; indexed?: boolean } + options?: { id?: string; metadata?: M; indexed?: boolean }, ) { if (Object.keys(schema).length === 0) throw new Error("Component schema must have at least one key"); const id = options?.id ?? uuid(); @@ -86,7 +86,7 @@ export function setComponent( component: Component, entity: Entity, value: ComponentValue, - options: ComponentMutationOptions = {} + options: ComponentMutationOptions = {}, ) { const entitySymbol = getEntitySymbol(entity); const prevValue = getComponentValue(component, entity); @@ -110,7 +110,7 @@ export function setComponent( "for entity", entity, ". Existing keys: ", - Object.keys(component.values) + Object.keys(component.values), ); } } @@ -141,7 +141,7 @@ export function updateComponent( entity: Entity, value: Partial>, initialValue?: ComponentValue, - options: ComponentMutationOptions = {} + options: ComponentMutationOptions = {}, ) { const currentValue = getComponentValue(component, entity); if (currentValue === undefined) { @@ -163,7 +163,7 @@ export function updateComponent( export function removeComponent( component: Component, entity: Entity, - options: ComponentMutationOptions = {} + options: ComponentMutationOptions = {}, ) { const entitySymbol = getEntitySymbol(entity); const prevValue = getComponentValue(component, entity); @@ -184,7 +184,7 @@ export function removeComponent( component: Component, - entity: Entity + entity: Entity, ): boolean { const entitySymbol = getEntitySymbol(entity); const map = Object.values(component.values)[0]; @@ -201,7 +201,7 @@ export function hasComponent( */ export function getComponentValue( component: Component, - entity: Entity + entity: Entity, ): ComponentValue | undefined { const value: Record = {}; const entitySymbol = getEntitySymbol(entity); @@ -230,7 +230,7 @@ export function getComponentValue( */ export function getComponentValueStrict( component: Component, - entity: Entity + entity: Entity, ): ComponentValue { const value = getComponentValue(component, entity); if (!value) throw new Error(`No value for component ${getComponentName(component)} on entity ${entity}`); @@ -253,7 +253,7 @@ export function getComponentValueStrict( */ export function componentValueEquals( a?: Partial>, - b?: ComponentValue + b?: ComponentValue, ): boolean { if (!a && !b) return true; if (!a || !b) return false; @@ -276,7 +276,7 @@ export function componentValueEquals( */ export function withValue( component: Component, - value: ComponentValue + value: ComponentValue, ): [Component, ComponentValue] { return [component, value]; } @@ -290,7 +290,7 @@ export function withValue( */ export function getEntitiesWithValue( component: Component | Indexer, - value: Partial> + value: Partial>, ): Set { // Shortcut for indexers if (isIndexer(component) && isFullComponentValue(component, value)) { @@ -315,7 +315,7 @@ export function getEntitiesWithValue( * @returns Set of all entities in the given component. */ export function getComponentEntities( - component: Component + component: Component, ): IterableIterator { return component.entities(); } @@ -335,7 +335,7 @@ export function getComponentEntities( * @returns overridable component */ export function overridableComponent( - component: Component + component: Component, ): OverridableComponent { let nonce = 0; @@ -457,7 +457,7 @@ export function overridableComponent !overriddenEntityValues.get(getEntitySymbol(e.entity))), - map((update) => ({ ...update, component: overriddenComponent })) + map((update) => ({ ...update, component: overriddenComponent })), ) .subscribe(update$); @@ -475,7 +475,7 @@ export function clearLocalCache(component: Component, uniqueWorldIdentifier?: st // Note: Only proof of concept for now - use this only for component that do not update frequently export function createLocalCache( component: Component, - uniqueWorldIdentifier?: string + uniqueWorldIdentifier?: string, ): Component { const { world, update$, values } = component; const cacheId = getLocalCacheId(component as Component, uniqueWorldIdentifier); @@ -509,7 +509,7 @@ export function createLocalCache { numUpdates++; const encoded = JSON.stringify( - Object.entries(mapObject(values, (m) => [...m.entries()].map((e) => [getEntityString(e[0]), e[1]]))) + Object.entries(mapObject(values, (m) => [...m.entries()].map((e) => [getEntityString(e[0]), e[1]]))), ); localStorage.setItem(cacheId, encoded); if (numUpdates > 200) { @@ -520,7 +520,7 @@ export function createLocalCache( - component: Component + component: Component, ): Indexer { const valueToEntities = new Map>(); diff --git a/packages/recs/src/Query.spec.ts b/packages/recs/src/Query.spec.ts index b75f91b474..1c200a5d34 100644 --- a/packages/recs/src/Query.spec.ts +++ b/packages/recs/src/Query.spec.ts @@ -98,27 +98,27 @@ describe("Query", () => { expect(runQuery([HasValue(OwnedByEntity, { value: Player })])).toEqual(new Set([Depth1])); expect(runQuery([ProxyExpand(OwnedByEntity, 0), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1]) + new Set([Depth1]), ); expect(runQuery([ProxyExpand(OwnedByEntity, 1), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1, Depth2]) + new Set([Depth1, Depth2]), ); expect(runQuery([ProxyExpand(OwnedByEntity, 2), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1, Depth2, Depth3]) + new Set([Depth1, Depth2, Depth3]), ); expect(runQuery([ProxyExpand(OwnedByEntity, 3), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1, Depth2, Depth3, Depth4]) + new Set([Depth1, Depth2, Depth3, Depth4]), ); expect(runQuery([ProxyExpand(OwnedByEntity, 4), HasValue(OwnedByEntity, { value: Player })])).toEqual( - new Set([Depth1, Depth2, Depth3, Depth4, Depth5]) + new Set([Depth1, Depth2, Depth3, Depth4, Depth5]), ); expect( - runQuery([ProxyExpand(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(OwnedByEntity, { value: Player })]) + runQuery([ProxyExpand(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(OwnedByEntity, { value: Player })]), ).toEqual(new Set([Depth1, Depth2, Depth3, Depth4, Depth5])); }); @@ -132,8 +132,8 @@ describe("Query", () => { expect( runQuery( [ProxyRead(OwnedByEntity, 1), HasValue(Name, { name: "Alice" })], - new Set([Depth1, Depth2, Depth3]) // Provide an initial set of entities - ) + new Set([Depth1, Depth2, Depth3]), // Provide an initial set of entities + ), ).toEqual(new Set([Depth1])); expect( @@ -142,7 +142,7 @@ describe("Query", () => { HasValue(Name, { name: "Alice" }), // Get all entities with name Alice or owned by Alice ProxyExpand(OwnedByEntity, 0), // Turn off proxy expand NotValue(Name, { name: "Alice" }), // Filter Alice, only keep entities owned by Alice - ]) + ]), ).toEqual(new Set([Depth1])); expect( @@ -151,15 +151,15 @@ describe("Query", () => { HasValue(Name, { name: "Alice" }), // Get all child entities of Alice (including alice) ProxyExpand(OwnedByEntity, 0), // Turn off proxy expand NotValue(Name, { name: "Alice" }), // Filter Alice, only keep entities owned by Alice - ]) + ]), ).toEqual(new Set([Depth1, Depth2, Depth3, Depth4])); // Get all entities from the initial set [Depth3] that have an indirect owner called Alice expect( runQuery( [ProxyRead(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(Name, { name: "Alice" })], - new Set([Depth3]) // Provide an initial set of entities - ) + new Set([Depth3]), // Provide an initial set of entities + ), ).toEqual(new Set([Depth3])); // Get all entities that have an indirect owner called Alice @@ -171,8 +171,8 @@ describe("Query", () => { ProxyRead(OwnedByEntity, 0), NotValue(Name, { name: "Alice" }), ], - new Set([Player, Depth1, Depth2, Depth3, Depth4]) // Provide an initial set of entities - ) + new Set([Player, Depth1, Depth2, Depth3, Depth4]), // Provide an initial set of entities + ), ).toEqual(new Set([Depth1, Depth2, Depth3, Depth4])); // Get all entities from the initial set [Depth3] that have an indirect owner called Alice and their direct child @@ -183,8 +183,8 @@ describe("Query", () => { ProxyExpand(OwnedByEntity, 1), HasValue(Name, { name: "Alice" }), ], - new Set([Depth2]) // Provide an initial set of entities - ) + new Set([Depth2]), // Provide an initial set of entities + ), ).toEqual(new Set([Depth2, Depth3])); }); @@ -204,15 +204,15 @@ describe("Query", () => { createEntity(world, [withValue(Position, { x: 1, y: 1 })]); expect(runQuery([ProxyExpand(FromPrototype, 1), Has(CanMove), Not(Prototype)])).toEqual( - new Set([instance1, instance2]) + new Set([instance1, instance2]), ); expect(runQuery([Has(Position), ProxyRead(FromPrototype, 1), Has(CanMove)])).toEqual( - new Set([instance1, instance2]) + new Set([instance1, instance2]), ); expect(runQuery([ProxyRead(FromPrototype, 1), Has(Position), Has(CanMove)])).toEqual( - new Set([instance1, instance2]) + new Set([instance1, instance2]), ); }); @@ -287,7 +287,7 @@ describe("Query", () => { Has(CanMove), // ...have the CanMove component... ProxyRead(OwnedByEntity, Number.MAX_SAFE_INTEGER), // ...and for whose owner holds... NotValue(Name, { name: "Alice" }), // ...their name is not Alice - ]) + ]), ).toEqual(new Set([Instance3, Entity8])); }); @@ -343,14 +343,14 @@ describe("Query", () => { entity: entities[0], component: CanMove, value: [{ value: true }, undefined], - }) + }), ); expect(mock).toHaveBeenCalledWith( expect.objectContaining({ entity: entities[1], component: CanMove, value: [{ value: true }, undefined], - }) + }), ); expect(mock).toBeCalledTimes(2); @@ -360,7 +360,7 @@ describe("Query", () => { entity: entities[2], component: CanMove, value: [{ value: true }, undefined], - }) + }), ); expect(mock).toHaveBeenCalledTimes(3); }); @@ -388,7 +388,7 @@ describe("Query", () => { entity: entity1, component: CanMove, value: [undefined, { value: true }], - }) + }), ); removeComponent(CanMove, entity2); @@ -398,7 +398,7 @@ describe("Query", () => { entity: entity2, component: CanMove, value: [undefined, { value: true }], - }) + }), ); }); }); @@ -617,7 +617,7 @@ describe("Query", () => { const query1 = defineQuery( [ProxyRead(OwnedByEntity, 1), HasValue(Name, { name: "Alice" })], - { initialSet: new Set([Depth1, Depth2, Depth3]) } // Provide an initial set of entities + { initialSet: new Set([Depth1, Depth2, Depth3]) }, // Provide an initial set of entities ); query1.update$.subscribe(); @@ -639,7 +639,7 @@ describe("Query", () => { const query4 = defineQuery( [ProxyRead(OwnedByEntity, Number.MAX_SAFE_INTEGER), HasValue(Name, { name: "Alice" })], - { initialSet: new Set([Depth3]) } // Provide an initial set of entities + { initialSet: new Set([Depth3]) }, // Provide an initial set of entities ); query4.update$.subscribe(); @@ -650,7 +650,7 @@ describe("Query", () => { ProxyRead(OwnedByEntity, 0), NotValue(Name, { name: "Alice" }), ], - { initialSet: new Set([Player, Depth1, Depth2, Depth3, Depth4]) } // Provide an initial set of entities + { initialSet: new Set([Player, Depth1, Depth2, Depth3, Depth4]) }, // Provide an initial set of entities ); query5.update$.subscribe(); @@ -660,7 +660,7 @@ describe("Query", () => { ProxyExpand(OwnedByEntity, 1), HasValue(Name, { name: "Alice" }), ], - { initialSet: new Set([Depth2]) } // Provide an initial set of entities + { initialSet: new Set([Depth2]) }, // Provide an initial set of entities ); query6.update$.subscribe(); diff --git a/packages/recs/src/Query.ts b/packages/recs/src/Query.ts index b32c2e2563..2ebce7fa81 100644 --- a/packages/recs/src/Query.ts +++ b/packages/recs/src/Query.ts @@ -88,7 +88,7 @@ export function Not(component: Component): NotQueryFragment */ export function HasValue( component: Component, - value: Partial> + value: Partial>, ): HasValueQueryFragment { return { type: QueryFragmentType.HasValue, component, value }; } @@ -112,7 +112,7 @@ export function HasValue( */ export function NotValue( component: Component, - value: Partial> + value: Partial>, ): NotValueQueryFragment { return { type: QueryFragmentType.NotValue, component, value }; } @@ -199,7 +199,7 @@ function passesQueryFragment(entity: Entity, fragment: EntityQ * @returns True if the query fragment is positive, else false. */ function isPositiveFragment( - fragment: QueryFragment + fragment: QueryFragment, ): fragment is HasQueryFragment | HasValueQueryFragment { return fragment.type === QueryFragmentType.Has || fragment.type == QueryFragmentType.HasValue; } @@ -211,7 +211,7 @@ function isPositiveFragment( * @returns True if the query fragment is negative, else false. */ function isNegativeFragment( - fragment: QueryFragment + fragment: QueryFragment, ): fragment is NotQueryFragment | NotValueQueryFragment { return fragment.type === QueryFragmentType.Not || fragment.type == QueryFragmentType.NotValue; } @@ -253,7 +253,7 @@ function isBreakingPassState(passes: boolean, fragment: EntityQueryFragment( entity: Entity, fragment: EntityQueryFragment, - proxyRead: ProxyReadQueryFragment + proxyRead: ProxyReadQueryFragment, ): boolean | null { let proxyEntity = entity; let passes = false; @@ -288,7 +288,7 @@ function passesQueryFragmentProxy( export function getChildEntities( entity: Entity, component: Component<{ value: Type.Entity }>, - depth: number + depth: number, ): Set { if (depth === 0) return new Set(); @@ -416,7 +416,7 @@ export function runQuery(fragments: QueryFragment[], initialSet?: Set): */ export function defineQuery( fragments: QueryFragment[], - options?: { runOnInit?: boolean; initialSet?: Set } + options?: { runOnInit?: boolean; initialSet?: Set }, ): { update$: Observable; matching: ObservableSet; @@ -503,7 +503,7 @@ export function defineQuery( return { ...update, type: UpdateType.Enter }; } }), - filterNullish() + filterNullish(), ); return { @@ -521,7 +521,7 @@ export function defineQuery( */ export function defineUpdateQuery( fragments: QueryFragment[], - options?: { runOnInit?: boolean } + options?: { runOnInit?: boolean }, ): Observable { return defineQuery(fragments, options).update$.pipe(filter((e) => e.type === UpdateType.Update)); } @@ -535,7 +535,7 @@ export function defineUpdateQuery( */ export function defineEnterQuery( fragments: QueryFragment[], - options?: { runOnInit?: boolean } + options?: { runOnInit?: boolean }, ): Observable { return defineQuery(fragments, options).update$.pipe(filter((e) => e.type === UpdateType.Enter)); } @@ -549,7 +549,7 @@ export function defineEnterQuery( */ export function defineExitQuery( fragments: QueryFragment[], - options?: { runOnInit?: boolean } + options?: { runOnInit?: boolean }, ): Observable { return defineQuery(fragments, options).update$.pipe(filter((e) => e.type === UpdateType.Exit)); } diff --git a/packages/recs/src/System.spec.ts b/packages/recs/src/System.spec.ts index 2f872323f6..4c0a6680a3 100644 --- a/packages/recs/src/System.spec.ts +++ b/packages/recs/src/System.spec.ts @@ -100,13 +100,13 @@ describe("System", () => { expect(mock).toHaveBeenCalledTimes(1); expect(mock).toHaveBeenCalledWith( - expect.objectContaining({ entity: entity1, component: CanMove, value: [{ value: true }, undefined] }) + expect.objectContaining({ entity: entity1, component: CanMove, value: [{ value: true }, undefined] }), ); const entity2 = createEntity(world, [withValue(CanMove, { value: true })]); expect(mock).toHaveBeenCalledTimes(2); expect(mock).toHaveBeenCalledWith( - expect.objectContaining({ entity: entity2, component: CanMove, value: [{ value: true }, undefined] }) + expect.objectContaining({ entity: entity2, component: CanMove, value: [{ value: true }, undefined] }), ); }); @@ -126,13 +126,13 @@ describe("System", () => { expect(mock).toHaveBeenCalledTimes(1); expect(mock).toHaveBeenCalledWith( - expect.objectContaining({ entity: entity1, component: CanMove, value: [undefined, { value: true }] }) + expect.objectContaining({ entity: entity1, component: CanMove, value: [undefined, { value: true }] }), ); removeComponent(CanMove, entity2); expect(mock).toHaveBeenCalledTimes(2); expect(mock).toHaveBeenCalledWith( - expect.objectContaining({ entity: entity2, component: CanMove, value: [undefined, { value: true }] }) + expect.objectContaining({ entity: entity2, component: CanMove, value: [undefined, { value: true }] }), ); }); }); diff --git a/packages/recs/src/System.ts b/packages/recs/src/System.ts index eaf8d2b2a0..6f91498bd3 100644 --- a/packages/recs/src/System.ts +++ b/packages/recs/src/System.ts @@ -36,7 +36,7 @@ export function defineUpdateSystem( world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { defineRxSystem(world, defineUpdateQuery(query, options), system); } @@ -56,7 +56,7 @@ export function defineEnterSystem( world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { defineRxSystem(world, defineEnterQuery(query, options), system); } @@ -76,7 +76,7 @@ export function defineExitSystem( world: World, query: QueryFragment[], system: (update: ComponentUpdate) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { defineRxSystem(world, defineExitQuery(query, options), system); } @@ -96,7 +96,7 @@ export function defineSystem( world: World, query: QueryFragment[], system: (update: ComponentUpdate & { type: UpdateType }) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { defineRxSystem(world, defineQuery(query, options).update$, system); } @@ -116,7 +116,7 @@ export function defineComponentSystem( world: World, component: Component, system: (update: ComponentUpdate) => void, - options: { runOnInit?: boolean } = { runOnInit: true } + options: { runOnInit?: boolean } = { runOnInit: true }, ) { const initial$ = options?.runOnInit ? from(getComponentEntities(component)).pipe(toUpdateStream(component)) : EMPTY; defineRxSystem(world, concat(initial$, component.update$), system); @@ -135,7 +135,7 @@ export function defineSyncSystem( query: QueryFragment[], component: (entity: Entity) => Component, value: (entity: Entity) => ComponentValue, - options: { update?: boolean; runOnInit?: boolean } = { update: false, runOnInit: true } + options: { update?: boolean; runOnInit?: boolean } = { update: false, runOnInit: true }, ) { defineSystem( world, @@ -145,6 +145,6 @@ export function defineSyncSystem( if (type === UpdateType.Exit) removeComponent(component(entity), entity); if (options?.update && type === UpdateType.Update) setComponent(component(entity), entity, value(entity)); }, - options + options, ); } diff --git a/packages/recs/src/deprecated/createActionSystem.spec.ts b/packages/recs/src/deprecated/createActionSystem.spec.ts index b1d0c0653f..ac224b2261 100644 --- a/packages/recs/src/deprecated/createActionSystem.spec.ts +++ b/packages/recs/src/deprecated/createActionSystem.spec.ts @@ -177,7 +177,7 @@ describe("ActionSystem", () => { expect(runQuery([HasValue(Action, { on: settlement1 })])).toEqual(new Set([entity1])); expect(runQuery([HasValue(Action, { on: settlement2 })])).toEqual(new Set([entity2])); expect(runQuery([HasValue(Action, { state: ActionState.Requested })])).toEqual( - new Set([entity1, entity2, entity3]) + new Set([entity1, entity2, entity3]), ); }); diff --git a/packages/recs/src/deprecated/createActionSystem.ts b/packages/recs/src/deprecated/createActionSystem.ts index 1cbe367ac1..94b245fce7 100644 --- a/packages/recs/src/deprecated/createActionSystem.ts +++ b/packages/recs/src/deprecated/createActionSystem.ts @@ -15,7 +15,7 @@ export type ActionSystem = ReturnType; export function createActionSystem( world: World, txReduced$: Observable, - waitForTransaction?: (tx: string) => Promise + waitForTransaction?: (tx: string) => Promise, ) { // Action component const Action = defineActionComponent(world); @@ -40,7 +40,7 @@ export function createActionSystem( * @returns Components including pending updates */ function withOptimisticUpdates( - component: Component + component: Component, ): OverridableComponent { const optimisticComponent = componentsWithOptimisticUpdates[component.id] || overridableComponent(component); @@ -99,7 +99,7 @@ export function createActionSystem( // This subscriotion makes sure the action requirement is checked again every time // one of the referenced components changes or the pending updates map changes const subscription = merge( - ...Object.values(action.componentsWithOptimisticUpdates).map((c) => c.update$) + ...Object.values(action.componentsWithOptimisticUpdates).map((c) => c.update$), ).subscribe(() => checkRequirement(action)); checkRequirement(action); disposer.set(action.id, { dispose: () => subscription?.unsubscribe() }); diff --git a/packages/recs/src/deprecated/defineActionComponent.ts b/packages/recs/src/deprecated/defineActionComponent.ts index 6d73b4882e..3da5829a50 100644 --- a/packages/recs/src/deprecated/defineActionComponent.ts +++ b/packages/recs/src/deprecated/defineActionComponent.ts @@ -12,7 +12,7 @@ export function defineActionComponent(world: World) { overrides: Type.OptionalStringArray, txHash: Type.OptionalString, }, - { id: "Action" } + { id: "Action" }, ); return Action as Component, Metadata, T>; } diff --git a/packages/recs/src/deprecated/waitForActionCompletion.ts b/packages/recs/src/deprecated/waitForActionCompletion.ts index c271c29ce5..e7378bab57 100644 --- a/packages/recs/src/deprecated/waitForActionCompletion.ts +++ b/packages/recs/src/deprecated/waitForActionCompletion.ts @@ -5,7 +5,7 @@ import { waitForComponentValueIn } from "./waitForComponentValueIn"; export async function waitForActionCompletion( Action: ReturnType, - entity: Entity + entity: Entity, ): Promise { return waitForComponentValueIn(Action, entity, [ { state: ActionState.Cancelled }, diff --git a/packages/recs/src/deprecated/waitForComponentValueIn.ts b/packages/recs/src/deprecated/waitForComponentValueIn.ts index 97fba687aa..318649b381 100644 --- a/packages/recs/src/deprecated/waitForComponentValueIn.ts +++ b/packages/recs/src/deprecated/waitForComponentValueIn.ts @@ -6,7 +6,7 @@ import { Component, Metadata, Entity, ComponentValue, Schema } from "../types"; export function waitForComponentValueIn( component: Component, entity: Entity, - values: Partial>[] + values: Partial>[], ): Promise { const [resolve, , promise] = deferred(); @@ -19,13 +19,13 @@ export function waitForComponentValueIn( const value$ = component.update$.pipe( filter((update) => update.entity === entity), // Ignore updates of other entities - map((update) => update.value[0]) // Map the update to the current value + map((update) => update.value[0]), // Map the update to the current value ); const subscription = value$ .pipe( startWith(getComponentValue(component, entity)), - filter((currentValue) => Boolean(values.find((searchValue) => componentValueEquals(searchValue, currentValue)))) + filter((currentValue) => Boolean(values.find((searchValue) => componentValueEquals(searchValue, currentValue)))), ) .subscribe(() => { resolve(); diff --git a/packages/recs/src/utils.ts b/packages/recs/src/utils.ts index 4407acc17a..33989a7ec5 100644 --- a/packages/recs/src/utils.ts +++ b/packages/recs/src/utils.ts @@ -12,7 +12,7 @@ import { Component, ComponentUpdate, ComponentValue, Entity, Indexer, Schema } f */ export function isComponentUpdate( update: ComponentUpdate, - component: Component + component: Component, ): update is ComponentUpdate { return update.component === component; } @@ -62,7 +62,7 @@ export function isIndexer(c: Component | Indexer): c is */ export function isFullComponentValue( component: Component, - value: Partial> + value: Partial>, ): value is ComponentValue { return Object.keys(component.schema).every((key) => key in value); } diff --git a/packages/schema-type/src/typescript/arrayAbiTypes.ts b/packages/schema-type/src/typescript/arrayAbiTypes.ts index 76c7d69673..00dc9a733c 100644 --- a/packages/schema-type/src/typescript/arrayAbiTypes.ts +++ b/packages/schema-type/src/typescript/arrayAbiTypes.ts @@ -11,7 +11,7 @@ export function isArrayAbiType(abiType: string): } export function arrayAbiTypeToStaticAbiType( - abiType: T + abiType: T, ): ArrayAbiTypeToStaticAbiType { return abiType.replace(arrayAbiTypePattern, "") as ArrayAbiTypeToStaticAbiType; } diff --git a/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts b/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts index 02982cc2a1..13c9b7c977 100644 --- a/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts +++ b/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts @@ -8,5 +8,5 @@ export type AbiTypeToPrimitiveType = T extends `${infer Static ? StaticAbiTypeToPrimitiveType[] : never : T extends AbiType - ? StaticAbiTypeToPrimitiveType - : never; + ? StaticAbiTypeToPrimitiveType + : never; diff --git a/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts b/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts index fb7f484ad9..9e0d93640a 100644 --- a/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts +++ b/packages/schema-type/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts @@ -2,5 +2,5 @@ import { SchemaTypeToAbiType } from "./SchemaTypeToAbiType"; import { SchemaType } from "../SchemaType"; export const AbiTypeToSchemaType = Object.fromEntries( - Object.entries(SchemaTypeToAbiType).map(([schemaType, abiType]) => [abiType, parseInt(schemaType) as SchemaType]) + Object.entries(SchemaTypeToAbiType).map(([schemaType, abiType]) => [abiType, parseInt(schemaType) as SchemaType]), ) satisfies Record; diff --git a/packages/schema-type/src/typescript/deprecated/types/StaticAbiTypes.ts b/packages/schema-type/src/typescript/deprecated/types/StaticAbiTypes.ts index d4b3506c13..db658108b5 100644 --- a/packages/schema-type/src/typescript/deprecated/types/StaticAbiTypes.ts +++ b/packages/schema-type/src/typescript/deprecated/types/StaticAbiTypes.ts @@ -6,5 +6,5 @@ import { StaticSchemaType } from "./StaticSchemaType"; export type StaticAbiType = (typeof SchemaTypeToAbiType)[StaticSchemaType]; export const StaticAbiTypes = AbiTypes.filter( - (abiType) => getStaticByteLength(AbiTypeToSchemaType[abiType]) > 0 + (abiType) => getStaticByteLength(AbiTypeToSchemaType[abiType]) > 0, ) as StaticAbiType[]; diff --git a/packages/schema-type/src/typescript/schemaAbiTypes.test.ts b/packages/schema-type/src/typescript/schemaAbiTypes.test.ts index 6d23754108..df77fed6f8 100644 --- a/packages/schema-type/src/typescript/schemaAbiTypes.test.ts +++ b/packages/schema-type/src/typescript/schemaAbiTypes.test.ts @@ -9,7 +9,7 @@ describe("schemaAbiTypes", () => { const soliditySchemaTypes = matches?.[1].replace(/\s/g, "").split(",") ?? []; const soliditySchemaTypesAsAbiTypes = soliditySchemaTypes.map((soliditySchemaType) => - soliditySchemaType.replace(/_ARRAY$/, "[]").toLowerCase() + soliditySchemaType.replace(/_ARRAY$/, "[]").toLowerCase(), ); expect(soliditySchemaTypesAsAbiTypes).toStrictEqual(schemaAbiTypes); diff --git a/packages/schema-type/src/typescript/utils.ts b/packages/schema-type/src/typescript/utils.ts index 65d1a05c65..543d6fd6d9 100644 --- a/packages/schema-type/src/typescript/utils.ts +++ b/packages/schema-type/src/typescript/utils.ts @@ -3,21 +3,22 @@ import { Hex } from "viem"; export type TupleSplit = O["length"] extends N ? [O, T] : T extends readonly [infer F, ...infer R] - ? TupleSplit - : [O, T]; + ? TupleSplit + : [O, T]; -export type LiteralToBroad = T extends Readonly> - ? readonly LiteralToBroad[] - : T extends Array - ? LiteralToBroad[] - : T extends number - ? number - : T extends bigint - ? bigint - : T extends Hex - ? Hex - : T extends boolean - ? boolean - : T extends string - ? string - : never; +export type LiteralToBroad = + T extends Readonly> + ? readonly LiteralToBroad[] + : T extends Array + ? LiteralToBroad[] + : T extends number + ? number + : T extends bigint + ? bigint + : T extends Hex + ? Hex + : T extends boolean + ? boolean + : T extends string + ? string + : never; diff --git a/packages/services/protobuf/ts/faucet/faucet.ts b/packages/services/protobuf/ts/faucet/faucet.ts index 0bdb04e62f..c60dc04035 100644 --- a/packages/services/protobuf/ts/faucet/faucet.ts +++ b/packages/services/protobuf/ts/faucet/faucet.ts @@ -231,7 +231,7 @@ export const FaucetStore = { } return acc; }, - {} + {}, ); message.usernameToAddress = Object.entries(object.usernameToAddress ?? {}).reduce<{ [key: string]: string }>( (acc, [key, value]) => { @@ -240,7 +240,7 @@ export const FaucetStore = { } return acc; }, - {} + {}, ); message.latestDrip = Object.entries(object.latestDrip ?? {}).reduce<{ [key: string]: number }>( (acc, [key, value]) => { @@ -249,7 +249,7 @@ export const FaucetStore = { } return acc; }, - {} + {}, ); message.totalDripCount = object.totalDripCount ?? 0; return message; @@ -1092,24 +1092,24 @@ export interface FaucetServiceImplementation { dripVerifyTweet(request: DripRequest, context: CallContext & CallContextExt): Promise>; timeUntilDrip( request: DripRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; getLinkedTwitters( request: GetLinkedTwittersRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; getLinkedTwitterForAddress( request: LinkedTwitterForAddressRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; getLinkedAddressForTwitter( request: LinkedAddressForTwitterRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; /** Admin utility endpoints for modifying state. Requires a signature with faucet private key. */ setLinkedTwitter( request: SetLinkedTwitterRequest, - context: CallContext & CallContextExt + context: CallContext & CallContextExt, ): Promise>; } @@ -1119,24 +1119,24 @@ export interface FaucetServiceClient { dripVerifyTweet(request: DeepPartial, options?: CallOptions & CallOptionsExt): Promise; timeUntilDrip( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; getLinkedTwitters( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; getLinkedTwitterForAddress( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; getLinkedAddressForTwitter( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; /** Admin utility endpoints for modifying state. Requires a signature with faucet private key. */ setLinkedTwitter( request: DeepPartial, - options?: CallOptions & CallOptionsExt + options?: CallOptions & CallOptionsExt, ): Promise; } @@ -1164,12 +1164,12 @@ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefi export type DeepPartial = T extends Builtin ? T : T extends Array - ? Array> - : T extends ReadonlyArray - ? ReadonlyArray> - : T extends {} - ? { [K in keyof T]?: DeepPartial } - : Partial; + ? Array> + : T extends ReadonlyArray + ? ReadonlyArray> + : T extends {} + ? { [K in keyof T]?: DeepPartial } + : Partial; function longToNumber(long: Long): number { if (long.gt(Number.MAX_SAFE_INTEGER)) { diff --git a/packages/services/ts/faucet/createFaucetService.ts b/packages/services/ts/faucet/createFaucetService.ts index f82eb82c22..ea0b1c565b 100644 --- a/packages/services/ts/faucet/createFaucetService.ts +++ b/packages/services/ts/faucet/createFaucetService.ts @@ -8,7 +8,7 @@ import { FromTsProtoServiceDefinition } from "nice-grpc-web/lib/service-definiti * @returns FaucetServiceClient */ export function createFaucetService( - url: string + url: string, ): RawClient> { return createClient(FaucetServiceDefinition, createChannel(url)); } diff --git a/packages/solhint-plugin-mud/src/rules/NoMsgSender.ts b/packages/solhint-plugin-mud/src/rules/NoMsgSender.ts index 1c81e6ef51..fb3751c4dd 100644 --- a/packages/solhint-plugin-mud/src/rules/NoMsgSender.ts +++ b/packages/solhint-plugin-mud/src/rules/NoMsgSender.ts @@ -29,7 +29,7 @@ export class NoMsgSender implements SolhintRule { this.reporter.error( node, this.ruleId, - `Systems and their libraries should use "_msgSender()" or "_world()" instead of "msg.sender".` + `Systems and their libraries should use "_msgSender()" or "_world()" instead of "msg.sender".`, ); } } diff --git a/packages/solhint-plugin-mud/src/rules/SystemFileName.ts b/packages/solhint-plugin-mud/src/rules/SystemFileName.ts index 2e8706fbba..337cebb1d5 100644 --- a/packages/solhint-plugin-mud/src/rules/SystemFileName.ts +++ b/packages/solhint-plugin-mud/src/rules/SystemFileName.ts @@ -46,7 +46,7 @@ export class SystemFileName implements SolhintRule { this.reporter.error( node, this.ruleId, - `System file must contain a contract with a matching name "${expectedContractName}"` + `System file must contain a contract with a matching name "${expectedContractName}"`, ); } } diff --git a/packages/store-indexer/CHANGELOG.md b/packages/store-indexer/CHANGELOG.md index 10ee41a923..f5b485fae7 100644 --- a/packages/store-indexer/CHANGELOG.md +++ b/packages/store-indexer/CHANGELOG.md @@ -594,7 +594,7 @@ .pipe( map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block - filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct ) .subscribe(clock.update); // Update the local clock ``` diff --git a/packages/store-indexer/bin/parseEnv.ts b/packages/store-indexer/bin/parseEnv.ts index 19be86cf8f..5a001a61a3 100644 --- a/packages/store-indexer/bin/parseEnv.ts +++ b/packages/store-indexer/bin/parseEnv.ts @@ -23,7 +23,7 @@ export const indexerEnvSchema = z.intersection( RPC_HTTP_URL: z.string().optional(), RPC_WS_URL: z.string(), }), - ]) + ]), ); export function parseEnv(envSchema: TSchema): z.infer { diff --git a/packages/store-indexer/bin/postgres-decoded-indexer.ts b/packages/store-indexer/bin/postgres-decoded-indexer.ts index 11339892ea..70bce8a446 100644 --- a/packages/store-indexer/bin/postgres-decoded-indexer.ts +++ b/packages/store-indexer/bin/postgres-decoded-indexer.ts @@ -22,8 +22,8 @@ const env = parseEnv( HEALTHCHECK_HOST: z.string().optional(), HEALTHCHECK_PORT: z.coerce.number().optional(), SENTRY_DSN: z.string().optional(), - }) - ) + }), + ), ); const transports: Transport[] = [ @@ -81,9 +81,10 @@ let isCaughtUp = false; combineLatest([latestBlockNumber$, storedBlockLogs$]) .pipe( filter( - ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => latestBlockNumber === lastBlockNumberProcessed + ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => + latestBlockNumber === lastBlockNumberProcessed, ), - first() + first(), ) .subscribe(() => { isCaughtUp = true; @@ -104,12 +105,12 @@ if (env.HEALTHCHECK_HOST != null || env.HEALTHCHECK_PORT != null) { server.use( healthcheck({ isReady: () => isCaughtUp, - }) + }), ); server.use(helloWorld()); server.listen({ host: env.HEALTHCHECK_HOST, port: env.HEALTHCHECK_PORT }); console.log( - `postgres indexer healthcheck server listening on http://${env.HEALTHCHECK_HOST}:${env.HEALTHCHECK_PORT}` + `postgres indexer healthcheck server listening on http://${env.HEALTHCHECK_HOST}:${env.HEALTHCHECK_PORT}`, ); } diff --git a/packages/store-indexer/bin/postgres-frontend.ts b/packages/store-indexer/bin/postgres-frontend.ts index 037a53cddf..f95d80919c 100644 --- a/packages/store-indexer/bin/postgres-frontend.ts +++ b/packages/store-indexer/bin/postgres-frontend.ts @@ -20,8 +20,8 @@ const env = parseEnv( z.object({ DATABASE_URL: z.string(), SENTRY_DSN: z.string().optional(), - }) - ) + }), + ), ); const database = postgres(env.DATABASE_URL, { prepare: false }); @@ -44,7 +44,7 @@ server.use( createContext: async () => ({ queryAdapter: await createQueryAdapter(drizzle(database)), }), - }) + }), ); server.listen({ host: env.HOST, port: env.PORT }); diff --git a/packages/store-indexer/bin/postgres-indexer.ts b/packages/store-indexer/bin/postgres-indexer.ts index 3bcffa9803..28b0ee2482 100644 --- a/packages/store-indexer/bin/postgres-indexer.ts +++ b/packages/store-indexer/bin/postgres-indexer.ts @@ -18,8 +18,8 @@ const env = parseEnv( DATABASE_URL: z.string(), HEALTHCHECK_HOST: z.string().optional(), HEALTHCHECK_PORT: z.coerce.number().optional(), - }) - ) + }), + ), ); const transports: Transport[] = [ @@ -82,9 +82,10 @@ let isCaughtUp = false; combineLatest([latestBlockNumber$, storedBlockLogs$]) .pipe( filter( - ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => latestBlockNumber === lastBlockNumberProcessed + ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => + latestBlockNumber === lastBlockNumberProcessed, ), - first() + first(), ) .subscribe(() => { isCaughtUp = true; @@ -103,12 +104,12 @@ if (env.HEALTHCHECK_HOST != null || env.HEALTHCHECK_PORT != null) { server.use( healthcheck({ isReady: () => isCaughtUp, - }) + }), ); server.use(helloWorld()); server.listen({ host: env.HEALTHCHECK_HOST, port: env.HEALTHCHECK_PORT }); console.log( - `postgres indexer healthcheck server listening on http://${env.HEALTHCHECK_HOST}:${env.HEALTHCHECK_PORT}` + `postgres indexer healthcheck server listening on http://${env.HEALTHCHECK_HOST}:${env.HEALTHCHECK_PORT}`, ); } diff --git a/packages/store-indexer/bin/sqlite-indexer.ts b/packages/store-indexer/bin/sqlite-indexer.ts index 416dc8d8ef..a544fea7d6 100644 --- a/packages/store-indexer/bin/sqlite-indexer.ts +++ b/packages/store-indexer/bin/sqlite-indexer.ts @@ -26,8 +26,8 @@ const env = parseEnv( z.object({ SQLITE_FILENAME: z.string().default("indexer.db"), SENTRY_DSN: z.string().optional(), - }) - ) + }), + ), ); const transports: Transport[] = [ @@ -60,7 +60,7 @@ try { currentChainState.schemaVersion, "to", schemaVersion, - "recreating database" + "recreating database", ); fs.truncateSync(env.SQLITE_FILENAME); } else if (currentChainState.lastUpdatedBlockNumber != null) { @@ -85,9 +85,10 @@ let isCaughtUp = false; combineLatest([latestBlockNumber$, storedBlockLogs$]) .pipe( filter( - ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => latestBlockNumber === lastBlockNumberProcessed + ([latestBlockNumber, { blockNumber: lastBlockNumberProcessed }]) => + latestBlockNumber === lastBlockNumberProcessed, ), - first() + first(), ) .subscribe(() => { isCaughtUp = true; @@ -104,7 +105,7 @@ server.use(cors()); server.use( healthcheck({ isReady: () => isCaughtUp, - }) + }), ); server.use(helloWorld()); server.use(apiRoutes(database)); @@ -116,7 +117,7 @@ server.use( createContext: async () => ({ queryAdapter: await createQueryAdapter(database), }), - }) + }), ); server.listen({ host: env.HOST, port: env.PORT }); diff --git a/packages/store-indexer/src/koa-middleware/sentry.ts b/packages/store-indexer/src/koa-middleware/sentry.ts index ea59ea7492..e8999dffcd 100644 --- a/packages/store-indexer/src/koa-middleware/sentry.ts +++ b/packages/store-indexer/src/koa-middleware/sentry.ts @@ -31,8 +31,8 @@ export function requestHandler(): Koa.Middleware { include: { user: false, }, - }) - ) + }), + ), ); await next(); }); diff --git a/packages/store-indexer/src/postgres/apiRoutes.ts b/packages/store-indexer/src/postgres/apiRoutes.ts index 383700fc5f..66f5d63397 100644 --- a/packages/store-indexer/src/postgres/apiRoutes.ts +++ b/packages/store-indexer/src/postgres/apiRoutes.ts @@ -38,8 +38,8 @@ export function apiRoutes(database: Sql): Middleware { ctx.body = "no logs found"; error( `no logs found for chainId ${options.chainId}, address ${options.address}, filters ${JSON.stringify( - options.filters - )}` + options.filters, + )}`, ); return; } diff --git a/packages/store-indexer/src/postgres/deprecated/getLogs.ts b/packages/store-indexer/src/postgres/deprecated/getLogs.ts index e6138fef2e..a883e9b011 100644 --- a/packages/store-indexer/src/postgres/deprecated/getLogs.ts +++ b/packages/store-indexer/src/postgres/deprecated/getLogs.ts @@ -20,7 +20,7 @@ export async function getLogs( readonly chainId: number; readonly address?: Hex; readonly filters?: readonly SyncFilter[]; - } + }, ): Promise<{ blockNumber: bigint; logs: (StorageAdapterLog & { eventName: "Store_SetRecord" })[] }> { const benchmark = createBenchmark("drizzleGetLogs"); @@ -30,12 +30,12 @@ export async function getLogs( address != null ? eq(tables.recordsTable.address, address) : undefined, eq(tables.recordsTable.tableId, filter.tableId), filter.key0 != null ? eq(tables.recordsTable.key0, filter.key0) : undefined, - filter.key1 != null ? eq(tables.recordsTable.key1, filter.key1) : undefined - ) + filter.key1 != null ? eq(tables.recordsTable.key1, filter.key1) : undefined, + ), ) : address != null - ? [eq(tables.recordsTable.address, address)] - : []; + ? [eq(tables.recordsTable.address, address)] + : []; benchmark("parse config"); // Query for the block number that the indexer (i.e. chain) is at, in case the @@ -63,7 +63,7 @@ export async function getLogs( .from(tables.recordsTable) .where(or(...conditions)) .orderBy( - asc(tables.recordsTable.blockNumber) + asc(tables.recordsTable.blockNumber), // TODO: add logIndex (https://github.com/latticexyz/mud/issues/1979) ); benchmark("query records"); diff --git a/packages/store-indexer/src/postgres/queryLogs.ts b/packages/store-indexer/src/postgres/queryLogs.ts index b887a7a026..037f3bdc7b 100644 --- a/packages/store-indexer/src/postgres/queryLogs.ts +++ b/packages/store-indexer/src/postgres/queryLogs.ts @@ -26,16 +26,16 @@ export function queryLogs(sql: Sql, opts: z.infer): PendingQuery hex columns via custom types: https://github.com/porsager/postgres#custom-types diff --git a/packages/store-indexer/src/postgres/recordToLog.ts b/packages/store-indexer/src/postgres/recordToLog.ts index 097a7657f7..b74ec281d3 100644 --- a/packages/store-indexer/src/postgres/recordToLog.ts +++ b/packages/store-indexer/src/postgres/recordToLog.ts @@ -3,7 +3,7 @@ import { decodeDynamicField } from "@latticexyz/protocol-parser"; import { RecordData } from "./common"; export function recordToLog( - record: Omit + record: Omit, ): StorageAdapterLog & { eventName: "Store_SetRecord" } { return { address: record.address, diff --git a/packages/store-indexer/src/sqlite/getTablesWithRecords.ts b/packages/store-indexer/src/sqlite/getTablesWithRecords.ts index 987de4e641..10093c99ef 100644 --- a/packages/store-indexer/src/sqlite/getTablesWithRecords.ts +++ b/packages/store-indexer/src/sqlite/getTablesWithRecords.ts @@ -20,7 +20,7 @@ export function getTablesWithRecords( readonly chainId: number; readonly address?: Hex; readonly filters?: readonly SyncFilter[]; - } + }, ): { blockNumber: bigint | null; tables: readonly TableWithRecords[] } { const metadata = database .select() @@ -44,7 +44,7 @@ export function getTablesWithRecords( .from(sqliteTable) .where(eq(sqliteTable.__isDeleted, false)) .orderBy( - asc(sqliteTable.__lastUpdatedBlockNumber) + asc(sqliteTable.__lastUpdatedBlockNumber), // TODO: add logIndex (https://github.com/latticexyz/mud/issues/1979) ) .all(); @@ -56,7 +56,7 @@ export function getTablesWithRecords( (filter) => filter.tableId === table.tableId && (filter.key0 == null || filter.key0 === keyTuple[0]) && - (filter.key1 == null || filter.key1 === keyTuple[1]) + (filter.key1 == null || filter.key1 === keyTuple[1]), ); }); return { diff --git a/packages/store-sync/src/common.ts b/packages/store-sync/src/common.ts index 05aad07606..f0d05866e1 100644 --- a/packages/store-sync/src/common.ts +++ b/packages/store-sync/src/common.ts @@ -13,7 +13,7 @@ export const storeTables = resolveConfig(storeConfig).tables; export const worldTables = resolveConfig(worldConfig).tables; export const internalTableIds = [...Object.values(storeTables), ...Object.values(worldTables)].map( - (table) => table.tableId + (table) => table.tableId, ); export type ChainId = number; diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index 6b0fe1a628..ae2cf619be 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -73,7 +73,7 @@ export async function createStoreSync (filter) => filter.tableId === log.args.tableId && (filter.key0 == null || filter.key0 === log.args.keyTuple[0]) && - (filter.key1 == null || filter.key1 === log.args.keyTuple[1]) + (filter.key1 == null || filter.key1 === log.args.keyTuple[1]), ) : undefined; @@ -120,7 +120,7 @@ export async function createStoreSync return of(undefined); }), - shareReplay(1) + shareReplay(1), ); const storedInitialBlockLogs$ = initialBlockLogs$.pipe( @@ -168,13 +168,13 @@ export async function createStoreSync return { blockNumber, logs }; }), - shareReplay(1) + shareReplay(1), ); const startBlock$ = initialBlockLogs$.pipe( map((block) => bigIntMax(block?.blockNumber ?? 0n, initialStartBlock)), // TODO: if start block is still 0, find via deploy event - tap((startBlock) => debug("starting sync from block", startBlock)) + tap((startBlock) => debug("starting sync from block", startBlock)), ); const latestBlock$ = createBlockStream({ publicClient, blockTag: followBlockTag }).pipe(shareReplay(1)); @@ -183,7 +183,7 @@ export async function createStoreSync tap((blockNumber) => { debug("on block number", blockNumber, "for", followBlockTag, "block tag"); }), - shareReplay(1) + shareReplay(1), ); let startBlock: bigint | null = null; @@ -238,7 +238,7 @@ export async function createStoreSync } } }), - share() + share(), ); const storedBlockLogs$ = concat(storedInitialBlockLogs$, storedBlock$).pipe(share()); @@ -249,10 +249,10 @@ export async function createStoreSync const recentBlocks$ = storedBlockLogs$.pipe( scan( (recentBlocks, block) => [block, ...recentBlocks].slice(0, recentBlocksWindow), - [] + [], ), filter((recentBlocks) => recentBlocks.length > 0), - shareReplay(1) + shareReplay(1), ); // TODO: move to its own file so we can test it, have its own debug instance, etc. @@ -278,7 +278,7 @@ export async function createStoreSync throw error; } }), - tap((result) => debug("has tx?", tx, result)) + tap((result) => debug("has tx?", tx, result)), ); await firstValueFrom(hasTransaction$.pipe(filter(identity))); diff --git a/packages/store-sync/src/flattenSchema.ts b/packages/store-sync/src/flattenSchema.ts index 7cc9a92d90..dd2a61d019 100644 --- a/packages/store-sync/src/flattenSchema.ts +++ b/packages/store-sync/src/flattenSchema.ts @@ -2,7 +2,7 @@ import { mapObject } from "@latticexyz/common/utils"; import { ValueSchema } from "@latticexyz/store"; export function flattenSchema( - schema: schema + schema: schema, ): { readonly [k in keyof schema]: schema[k]["type"] } { return mapObject(schema, (value) => value.type); } diff --git a/packages/store-sync/src/getSnapshot.ts b/packages/store-sync/src/getSnapshot.ts index c79f2df255..f78d6e8cf0 100644 --- a/packages/store-sync/src/getSnapshot.ts +++ b/packages/store-sync/src/getSnapshot.ts @@ -63,7 +63,7 @@ export async function getSnapshot({ const result = await trpcIndexer.findAll.query({ chainId, address, filters }); // warn after we fetch from old endpoint so we know that the indexer is accessible console.warn( - `The indexer at ${indexerUrl} appears to be outdated. Consider upgrading to a recent version for better performance.` + `The indexer at ${indexerUrl} appears to be outdated. Consider upgrading to a recent version for better performance.`, ); // if the indexer returns no block number, it hasn't indexed this chain diff --git a/packages/store-sync/src/indexer-client/input.ts b/packages/store-sync/src/indexer-client/input.ts index 14107f1faa..643c88bf11 100644 --- a/packages/store-sync/src/indexer-client/input.ts +++ b/packages/store-sync/src/indexer-client/input.ts @@ -10,7 +10,7 @@ export const input = z.object({ tableId: z.string().refine(isHex), key0: z.string().refine(isHex).optional(), key1: z.string().refine(isHex).optional(), - }) + }), ) .default([]), }); diff --git a/packages/store-sync/src/isTableRegistrationLog.ts b/packages/store-sync/src/isTableRegistrationLog.ts index 8f6b6148d6..e7f9ac6acf 100644 --- a/packages/store-sync/src/isTableRegistrationLog.ts +++ b/packages/store-sync/src/isTableRegistrationLog.ts @@ -4,7 +4,7 @@ import { StorageAdapterLog, storeTables } from "./common"; * @internal */ export function isTableRegistrationLog( - log: StorageAdapterLog + log: StorageAdapterLog, ): log is StorageAdapterLog & { eventName: "Store_SetRecord" } { return log.eventName === "Store_SetRecord" && log.args.tableId === storeTables.Tables.tableId; } diff --git a/packages/store-sync/src/logToTable.test.ts b/packages/store-sync/src/logToTable.test.ts index f50e813bb5..0feb33c786 100644 --- a/packages/store-sync/src/logToTable.test.ts +++ b/packages/store-sync/src/logToTable.test.ts @@ -18,7 +18,7 @@ describe("logToTable", () => { // eslint-disable-next-line max-len "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000077461626c654964000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000b6669656c644c61796f757400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000096b6579536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b76616c7565536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012616269456e636f6465644b65794e616d657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014616269456e636f6465644669656c644e616d6573000000000000000000000000", }, - }) + }), ).toMatchInlineSnapshot(` { "address": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c", diff --git a/packages/store-sync/src/logToTable.ts b/packages/store-sync/src/logToTable.ts index 0d50dce3aa..c69e616186 100644 --- a/packages/store-sync/src/logToTable.ts +++ b/packages/store-sync/src/logToTable.ts @@ -17,7 +17,7 @@ export function logToTable(log: StorageAdapterLog & { eventName: "Store_SetRecor const value = decodeValue( // TODO: remove cast when we have strong types for user types schemasTable.valueSchema as ValueSchema, - concatHex([log.args.staticData, log.args.encodedLengths, log.args.dynamicData]) + concatHex([log.args.staticData, log.args.encodedLengths, log.args.dynamicData]), ); // TODO: remove cast when we have strong types for user types diff --git a/packages/store-sync/src/postgres-decoded/buildTable.test.ts b/packages/store-sync/src/postgres-decoded/buildTable.test.ts index f20f846392..b6369772f5 100644 --- a/packages/store-sync/src/postgres-decoded/buildTable.test.ts +++ b/packages/store-sync/src/postgres-decoded/buildTable.test.ts @@ -22,7 +22,7 @@ describe("buildTable", () => { dataType: column.dataType, sqlName: column.sqlName, notNull: column.notNull, - })) + })), ).toMatchInlineSnapshot(` { "__keyBytes": { @@ -81,7 +81,7 @@ describe("buildTable", () => { name: column.name, dataType: column.dataType, sqlName: column.sqlName, - })) + })), ).toMatchInlineSnapshot(` { "__keyBytes": { diff --git a/packages/store-sync/src/postgres-decoded/buildTable.ts b/packages/store-sync/src/postgres-decoded/buildTable.ts index 2f0a6f336c..56797a8438 100644 --- a/packages/store-sync/src/postgres-decoded/buildTable.ts +++ b/packages/store-sync/src/postgres-decoded/buildTable.ts @@ -56,10 +56,10 @@ export function buildTable [name, buildColumn(snakeCase(name), type).notNull()]) + Object.entries(keySchema).map(([name, type]) => [name, buildColumn(snakeCase(name), type).notNull()]), ); const valueColumns = Object.fromEntries( - Object.entries(valueSchema).map(([name, type]) => [name, buildColumn(snakeCase(name), type).notNull()]) + Object.entries(valueSchema).map(([name, type]) => [name, buildColumn(snakeCase(name), type).notNull()]), ); // TODO: make sure there are no meta columns that overlap with key/value columns diff --git a/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts b/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts index cf692f02a8..cb213fb258 100644 --- a/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts +++ b/packages/store-sync/src/postgres-decoded/createStorageAdapter.test.ts @@ -22,7 +22,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("createStorageAdapter", async () => { @@ -64,9 +64,9 @@ describe("createStorageAdapter", async () => { .where( eq( storageAdapter.tables.recordsTable.tableId, - resourceToHex({ type: "table", namespace: "", name: "NumberList" }) - ) - ) + resourceToHex({ type: "table", namespace: "", name: "NumberList" }), + ), + ), ).toMatchInlineSnapshot(` [ { diff --git a/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts b/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts index 227c0f39aa..d14401ef89 100644 --- a/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts +++ b/packages/store-sync/src/postgres-decoded/createStorageAdapter.ts @@ -44,7 +44,7 @@ export async function createStorageAdapter ({ address: log.address, tableId: log.args.tableId })) + logs.map((log) => ({ address: log.address, tableId: log.args.tableId })), ); // TODO: check if DB schema/table was created? @@ -56,7 +56,7 @@ export async function createStorageAdapter { for (const log of logs) { const table = tables.find( - (table) => getAddress(table.address) === getAddress(log.address) && table.tableId === log.args.tableId + (table) => getAddress(table.address) === getAddress(log.address) && table.tableId === log.args.tableId, ); if (!table) { const { namespace, name } = hexToResource(log.args.tableId); @@ -80,8 +80,8 @@ export async function createStorageAdapter, - filters: { address: Hex | null; tableId: Hex | null }[] = [] + filters: { address: Hex | null; tableId: Hex | null }[] = [], ): Promise { const conditions = filters.map((filter) => and( filter.address != null ? eq(internalTables.recordsTable.address, filter.address) : undefined, - filter.tableId != null ? eq(internalTables.recordsTable.key0, filter.tableId) : undefined - ) + filter.tableId != null ? eq(internalTables.recordsTable.key0, filter.tableId) : undefined, + ), ); const records = await db @@ -34,7 +34,7 @@ export async function getTables( encodedLengths: record.encodedLengths ?? "0x", dynamicData: record.dynamicData ?? "0x", }, - } as const) + }) as const, ); const tables = logs.map(logToTable); diff --git a/packages/store-sync/src/postgres/createStorageAdapter.test.ts b/packages/store-sync/src/postgres/createStorageAdapter.test.ts index c05928640f..bd368633b0 100644 --- a/packages/store-sync/src/postgres/createStorageAdapter.test.ts +++ b/packages/store-sync/src/postgres/createStorageAdapter.test.ts @@ -20,7 +20,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("createStorageAdapter", async () => { @@ -62,9 +62,9 @@ describe("createStorageAdapter", async () => { .where( eq( storageAdapter.tables.recordsTable.tableId, - resourceToHex({ type: "table", namespace: "", name: "NumberList" }) - ) - ) + resourceToHex({ type: "table", namespace: "", name: "NumberList" }), + ), + ), ).toMatchInlineSnapshot(` [ { diff --git a/packages/store-sync/src/postgres/createStorageAdapter.ts b/packages/store-sync/src/postgres/createStorageAdapter.ts index 43578e9ad9..91cfe6f225 100644 --- a/packages/store-sync/src/postgres/createStorageAdapter.ts +++ b/packages/store-sync/src/postgres/createStorageAdapter.ts @@ -80,8 +80,8 @@ export async function createStorageAdapter, - tables: PgTableWithColumns[] + tables: PgTableWithColumns[], ): Promise<() => Promise> { const schemaNames = unique(tables.map((table) => getTableConfig(table).schema).filter(isDefined)); @@ -49,7 +49,7 @@ export async function setupTables( if (primaryKeyColumns.length) { query = query.addPrimaryKeyConstraint( `${tableConfig.name}_${primaryKeyColumns.join("_")}_pk`, - primaryKeyColumns as any + primaryKeyColumns as any, ); } diff --git a/packages/store-sync/src/postgres/tables.ts b/packages/store-sync/src/postgres/tables.ts index b8871327d3..2f00011976 100644 --- a/packages/store-sync/src/postgres/tables.ts +++ b/packages/store-sync/src/postgres/tables.ts @@ -37,7 +37,7 @@ const recordsTable = pgSchema(schemaName).table( key1Index: index("key1_index").on(table.address, table.tableId, table.key1), // TODO: add indices for querying without table ID // TODO: add indices for querying multiple keys - }) + }), ); export const tables = { diff --git a/packages/store-sync/src/recs/decodeEntity.ts b/packages/store-sync/src/recs/decodeEntity.ts index ba2c084a7f..d4210de20b 100644 --- a/packages/store-sync/src/recs/decodeEntity.ts +++ b/packages/store-sync/src/recs/decodeEntity.ts @@ -5,18 +5,18 @@ import { KeySchema, SchemaToPrimitives } from "@latticexyz/protocol-parser"; export function decodeEntity( keySchema: TKeySchema, - entity: Entity + entity: Entity, ): SchemaToPrimitives { const hexKeyTuple = entityToHexKeyTuple(entity); if (hexKeyTuple.length !== Object.keys(keySchema).length) { throw new Error( - `entity key tuple length ${hexKeyTuple.length} does not match key schema length ${Object.keys(keySchema).length}` + `entity key tuple length ${hexKeyTuple.length} does not match key schema length ${Object.keys(keySchema).length}`, ); } return Object.fromEntries( Object.entries(keySchema).map(([key, type], index) => [ key, decodeAbiParameters([{ type }], hexKeyTuple[index] as Hex)[0], - ]) + ]), ) as SchemaToPrimitives; } diff --git a/packages/store-sync/src/recs/defineInternalComponents.ts b/packages/store-sync/src/recs/defineInternalComponents.ts index 992b878ce4..5b974cbd65 100644 --- a/packages/store-sync/src/recs/defineInternalComponents.ts +++ b/packages/store-sync/src/recs/defineInternalComponents.ts @@ -7,7 +7,7 @@ export function defineInternalComponents(world: World) { RegisteredTables: defineComponent<{ table: Type.T }, Metadata, Table>( world, { table: Type.T }, - { metadata: { componentName: "RegisteredTables" } } + { metadata: { componentName: "RegisteredTables" } }, ), SyncProgress: defineComponent( world, @@ -18,7 +18,7 @@ export function defineInternalComponents(world: World) { latestBlockNumber: Type.BigInt, lastBlockNumberProcessed: Type.BigInt, }, - { metadata: { componentName: "SyncProgress" } } + { metadata: { componentName: "SyncProgress" } }, ), } as const satisfies Record>; } diff --git a/packages/store-sync/src/recs/encodeEntity.ts b/packages/store-sync/src/recs/encodeEntity.ts index bef8a33c1b..061a630dee 100644 --- a/packages/store-sync/src/recs/encodeEntity.ts +++ b/packages/store-sync/src/recs/encodeEntity.ts @@ -5,14 +5,14 @@ import { KeySchema, SchemaToPrimitives } from "@latticexyz/protocol-parser"; export function encodeEntity( keySchema: TKeySchema, - key: SchemaToPrimitives + key: SchemaToPrimitives, ): Entity { if (Object.keys(keySchema).length !== Object.keys(key).length) { throw new Error( - `key length ${Object.keys(key).length} does not match key schema length ${Object.keys(keySchema).length}` + `key length ${Object.keys(key).length} does not match key schema length ${Object.keys(keySchema).length}`, ); } return hexKeyTupleToEntity( - Object.entries(keySchema).map(([keyName, type]) => encodeAbiParameters([{ type }], [key[keyName]])) + Object.entries(keySchema).map(([keyName, type]) => encodeAbiParameters([{ type }], [key[keyName]])), ); } diff --git a/packages/store-sync/src/recs/getTableEntity.ts b/packages/store-sync/src/recs/getTableEntity.ts index 5b92368da3..52ae66b6e3 100644 --- a/packages/store-sync/src/recs/getTableEntity.ts +++ b/packages/store-sync/src/recs/getTableEntity.ts @@ -10,6 +10,6 @@ export function getTableEntity(table: Pick( - component: Component + component: Component, ): component is Component { return ( component.metadata?.componentName != null && diff --git a/packages/store-sync/src/recs/recsStorage.test.ts b/packages/store-sync/src/recs/recsStorage.test.ts index afead84f6b..a1e5217cbe 100644 --- a/packages/store-sync/src/recs/recsStorage.test.ts +++ b/packages/store-sync/src/recs/recsStorage.test.ts @@ -21,7 +21,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("recsStorage", () => { @@ -29,7 +29,7 @@ describe("recsStorage", () => { const world = createWorld(); const { components } = recsStorage({ world, tables }); expect(components.NumberList.id).toMatchInlineSnapshot( - '"0x746200000000000000000000000000004e756d6265724c697374000000000000"' + '"0x746200000000000000000000000000004e756d6265724c697374000000000000"', ); }); @@ -60,7 +60,9 @@ describe("recsStorage", () => { `); expect( - [...getComponentEntities(components.NumberList)].map((entity) => getComponentValue(components.NumberList, entity)) + [...getComponentEntities(components.NumberList)].map((entity) => + getComponentValue(components.NumberList, entity), + ), ).toMatchInlineSnapshot(` [ { diff --git a/packages/store-sync/src/recs/recsStorage.ts b/packages/store-sync/src/recs/recsStorage.ts index 85a956c402..36849aa6f2 100644 --- a/packages/store-sync/src/recs/recsStorage.ts +++ b/packages/store-sync/src/recs/recsStorage.ts @@ -60,7 +60,7 @@ export function recsStorage>({ components.RegisteredTables, tableEntity, { table: newTable }, - { skipUpdateStream: shouldSkipUpdateStream?.() } + { skipUpdateStream: shouldSkipUpdateStream?.() }, ); } } @@ -69,7 +69,7 @@ export function recsStorage>({ const { namespace, name } = hexToResource(log.args.tableId); const table = getComponentValue( components.RegisteredTables, - getTableEntity({ address: log.address, namespace, name }) + getTableEntity({ address: log.address, namespace, name }), )?.table; if (!table) { debug(`skipping update for unknown table: ${resourceToLabel({ namespace, name })} at ${log.address}`); @@ -82,7 +82,7 @@ export function recsStorage>({ `skipping update for unknown component: ${table.tableId} (${resourceToLabel({ namespace, name, - })}). Available components: ${Object.keys(components)}` + })}). Available components: ${Object.keys(components)}`, ); continue; } @@ -106,7 +106,7 @@ export function recsStorage>({ __encodedLengths: log.args.encodedLengths, __dynamicData: log.args.dynamicData, }, - { skipUpdateStream: shouldSkipUpdateStream?.() } + { skipUpdateStream: shouldSkipUpdateStream?.() }, ); } else if (log.eventName === "Store_SpliceStaticData") { // TODO: add tests that this works when no record had been set before @@ -134,7 +134,7 @@ export function recsStorage>({ ...newValue, __staticData: newStaticData, }, - { skipUpdateStream: shouldSkipUpdateStream?.() } + { skipUpdateStream: shouldSkipUpdateStream?.() }, ); } else if (log.eventName === "Store_SpliceDynamicData") { // TODO: add tests that this works when no record had been set before @@ -164,7 +164,7 @@ export function recsStorage>({ __encodedLengths: log.args.encodedLengths, __dynamicData: newDynamicData, }, - { skipUpdateStream: shouldSkipUpdateStream?.() } + { skipUpdateStream: shouldSkipUpdateStream?.() }, ); } else if (log.eventName === "Store_DeleteRecord") { debug("deleting component", { diff --git a/packages/store-sync/src/recs/tableToComponent.ts b/packages/store-sync/src/recs/tableToComponent.ts index cfd07a9107..588163b6f1 100644 --- a/packages/store-sync/src/recs/tableToComponent.ts +++ b/packages/store-sync/src/recs/tableToComponent.ts @@ -31,7 +31,7 @@ export function tableToComponent
(world: World, table: table Object.entries(table.valueSchema).map(([fieldName, { type: schemaAbiType }]) => [ fieldName, schemaAbiTypeToRecsType[schemaAbiType as SchemaAbiType], - ]) + ]), ), __staticData: Type.OptionalString, __encodedLengths: Type.OptionalString, @@ -45,6 +45,6 @@ export function tableToComponent
(world: World, table: table keySchema: mapObject(table.keySchema, ({ type }) => type), valueSchema: mapObject(table.valueSchema, ({ type }) => type), }, - } + }, ) as TableToComponent
; } diff --git a/packages/store-sync/src/recs/tablesToComponents.ts b/packages/store-sync/src/recs/tablesToComponents.ts index be1a2cde4e..5952f6aa7a 100644 --- a/packages/store-sync/src/recs/tablesToComponents.ts +++ b/packages/store-sync/src/recs/tablesToComponents.ts @@ -9,7 +9,7 @@ export type TablesToComponents> = { export function tablesToComponents>( world: World, - tables: tables + tables: tables, ): TablesToComponents { return mapObject(tables, (table) => tableToComponent(world, table)); } diff --git a/packages/store-sync/src/schemaToDefaults.ts b/packages/store-sync/src/schemaToDefaults.ts index 278b4c77c7..f7658c15e0 100644 --- a/packages/store-sync/src/schemaToDefaults.ts +++ b/packages/store-sync/src/schemaToDefaults.ts @@ -3,6 +3,6 @@ import { schemaAbiTypeToDefaultValue } from "@latticexyz/schema-type"; export function schemaToDefaults(valueSchema: TSchema): SchemaToPrimitives { return Object.fromEntries( - Object.entries(valueSchema).map(([key, abiType]) => [key, schemaAbiTypeToDefaultValue[abiType]]) + Object.entries(valueSchema).map(([key, abiType]) => [key, schemaAbiTypeToDefaultValue[abiType]]), ) as SchemaToPrimitives; } diff --git a/packages/store-sync/src/sqlite/buildTable.ts b/packages/store-sync/src/sqlite/buildTable.ts index 2b9b0efd5c..d37d77d8e7 100644 --- a/packages/store-sync/src/sqlite/buildTable.ts +++ b/packages/store-sync/src/sqlite/buildTable.ts @@ -53,11 +53,11 @@ export function buildTable [name, buildColumn(name, type).notNull()]) + Object.entries(keySchema).map(([name, type]) => [name, buildColumn(name, type).notNull()]), ); const valueColumns = Object.fromEntries( - Object.entries(valueSchema).map(([name, type]) => [name, buildColumn(name, type).notNull()]) + Object.entries(valueSchema).map(([name, type]) => [name, buildColumn(name, type).notNull()]), ); // TODO: unique constraint on key columns? diff --git a/packages/store-sync/src/sqlite/getTables.ts b/packages/store-sync/src/sqlite/getTables.ts index 008a772167..01f9e90aa9 100644 --- a/packages/store-sync/src/sqlite/getTables.ts +++ b/packages/store-sync/src/sqlite/getTables.ts @@ -6,17 +6,17 @@ import { mudStoreTables } from "./internalTables"; export function getTables( db: BaseSQLiteDatabase<"sync", void>, - conditions: Pick[] = [] + conditions: Pick[] = [], ): Table[] { const ids = Array.from( - new Set(conditions.map((condition) => getTableName(condition.address, condition.namespace, condition.name))) + new Set(conditions.map((condition) => getTableName(condition.address, condition.namespace, condition.name))), ); const tables = db .select() .from(mudStoreTables) .where(ids.length ? inArray(mudStoreTables.id, ids) : undefined) .orderBy( - asc(mudStoreTables.lastUpdatedBlockNumber) + asc(mudStoreTables.lastUpdatedBlockNumber), // TODO: add logIndex (https://github.com/latticexyz/mud/issues/1979) ) .all(); diff --git a/packages/store-sync/src/sqlite/sqliteStorage.test.ts b/packages/store-sync/src/sqlite/sqliteStorage.test.ts index c8afe6a3d5..ed21a8dc58 100644 --- a/packages/store-sync/src/sqlite/sqliteStorage.test.ts +++ b/packages/store-sync/src/sqlite/sqliteStorage.test.ts @@ -24,7 +24,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("sqliteStorage", async () => { @@ -44,10 +44,10 @@ describe("sqliteStorage", async () => { it("should create tables and data from block log", async () => { expect(() => db.select().from(chainState).all()).toThrowErrorMatchingInlineSnapshot( - '"no such table: __chainState"' + '"no such table: __chainState"', ); expect(() => db.select().from(mudStoreTables).all()).toThrowErrorMatchingInlineSnapshot( - '"no such table: __mudStoreTables"' + '"no such table: __mudStoreTables"', ); const storageAdapter = await sqliteStorage({ database: db, publicClient }); diff --git a/packages/store-sync/src/sqlite/sqliteStorage.ts b/packages/store-sync/src/sqlite/sqliteStorage.ts index 6c369ab3b2..b29cd660aa 100644 --- a/packages/store-sync/src/sqlite/sqliteStorage.ts +++ b/packages/store-sync/src/sqlite/sqliteStorage.ts @@ -62,10 +62,10 @@ export async function sqliteStorage({ JSON.stringify({ address: getAddress(log.address), ...hexToResource(log.args.tableId), - }) - ) - ) - ).map((json) => JSON.parse(json)) + }), + ), + ), + ).map((json) => JSON.parse(json)), ); await database.transaction(async (tx) => { @@ -76,21 +76,21 @@ export async function sqliteStorage({ and( eq(mudStoreTables.address, address), eq(mudStoreTables.namespace, namespace), - eq(mudStoreTables.name, name) - ) + eq(mudStoreTables.name, name), + ), ) .run(); } for (const log of logs) { const table = tables.find( - (table) => table.address === getAddress(log.address) && table.tableId === log.args.tableId + (table) => table.address === getAddress(log.address) && table.tableId === log.args.tableId, ); if (!table) { const tableId = hexToResource(log.args.tableId); debug( `table ${resourceToLabel({ namespace: tableId.namespace, name: tableId.name })} not found, skipping log`, - log + log, ); continue; } diff --git a/packages/store-sync/src/sqlite/sqliteTableToSql.test.ts b/packages/store-sync/src/sqlite/sqliteTableToSql.test.ts index c07270f84e..cad8a1ca39 100644 --- a/packages/store-sync/src/sqlite/sqliteTableToSql.test.ts +++ b/packages/store-sync/src/sqlite/sqliteTableToSql.test.ts @@ -16,7 +16,7 @@ describe("sqliteTableToSql", () => { expect(sql).toMatchInlineSnapshot( // eslint-disable-next-line max-len - '"create table if not exists \\"some table\\" (\\"x\\" integer not null, \\"y\\" integer not null, \\"name\\" text default \'\' not null, \\"block_number\\" blob default \'1000\' not null, constraint \\"some table__primaryKey\\" primary key (\\"x\\", \\"y\\"))"' + '"create table if not exists \\"some table\\" (\\"x\\" integer not null, \\"y\\" integer not null, \\"name\\" text default \'\' not null, \\"block_number\\" blob default \'1000\' not null, constraint \\"some table__primaryKey\\" primary key (\\"x\\", \\"y\\"))"', ); }); @@ -29,7 +29,7 @@ describe("sqliteTableToSql", () => { const sql = sqliteTableToSql(table); expect(sql).toMatchInlineSnapshot( - '"create table if not exists \\"some table\\" (\\"name\\" text default \'\' not null)"' + '"create table if not exists \\"some table\\" (\\"name\\" text default \'\' not null)"', ); }); @@ -42,7 +42,7 @@ describe("sqliteTableToSql", () => { const sql = sqliteTableToSql(table); expect(sql).toMatchInlineSnapshot( - '"create table if not exists \\"some table\\" (\\"snake_case\\" text default \'\' not null, constraint \\"some table__primaryKey\\" primary key (\\"snake_case\\"))"' + '"create table if not exists \\"some table\\" (\\"snake_case\\" text default \'\' not null, constraint \\"some table__primaryKey\\" primary key (\\"snake_case\\"))"', ); }); }); diff --git a/packages/store-sync/src/tableToLog.test.ts b/packages/store-sync/src/tableToLog.test.ts index 0b58c4c45a..ca1f9de5f5 100644 --- a/packages/store-sync/src/tableToLog.test.ts +++ b/packages/store-sync/src/tableToLog.test.ts @@ -14,7 +14,7 @@ describe("tableToLog", () => { name: storeTables.Tables.name, keySchema: flattenSchema(storeTables.Tables.keySchema), valueSchema: flattenSchema(storeTables.Tables.valueSchema), - }) + }), ).toMatchInlineSnapshot(` { "address": "0x3Aa5ebB10DC797CAC828524e59A333d0A371443c", diff --git a/packages/store-sync/src/tablesWithRecordsToLogs.ts b/packages/store-sync/src/tablesWithRecordsToLogs.ts index a7e35d5a89..afd37437e5 100644 --- a/packages/store-sync/src/tablesWithRecordsToLogs.ts +++ b/packages/store-sync/src/tablesWithRecordsToLogs.ts @@ -18,8 +18,8 @@ export function tablesWithRecordsToLogs(tables: readonly TableWithRecords[]): St keyTuple: encodeKey(table.keySchema, record.key), ...encodeValueArgs(table.valueSchema, record.value), }, - }) - ) + }), + ), ), ]; } diff --git a/packages/store-sync/src/zustand/createStorageAdapter.test.ts b/packages/store-sync/src/zustand/createStorageAdapter.test.ts index 76fa8fc707..cdc089d051 100644 --- a/packages/store-sync/src/zustand/createStorageAdapter.test.ts +++ b/packages/store-sync/src/zustand/createStorageAdapter.test.ts @@ -20,7 +20,7 @@ const blocks = groupLogsByBlockNumber( strict: true, }); return formatLog(log as unknown as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); describe("createStorageAdapter", () => { diff --git a/packages/store-sync/src/zustand/createStorageAdapter.ts b/packages/store-sync/src/zustand/createStorageAdapter.ts index 7dcb55f20c..b8bb5f6974 100644 --- a/packages/store-sync/src/zustand/createStorageAdapter.ts +++ b/packages/store-sync/src/zustand/createStorageAdapter.ts @@ -32,7 +32,7 @@ export function createStorageAdapter({ debug( `skipping update for unknown table: ${resourceToLabel({ namespace, name })} (${log.args.tableId}) at ${ log.address - }` + }`, ); continue; } @@ -140,7 +140,7 @@ export function createStorageAdapter({ }, ]; }) - .filter(isDefined) + .filter(isDefined), ), }; diff --git a/packages/store-sync/src/zustand/createStore.ts b/packages/store-sync/src/zustand/createStore.ts index 77642e3eaa..93a2dd3258 100644 --- a/packages/store-sync/src/zustand/createStore.ts +++ b/packages/store-sync/src/zustand/createStore.ts @@ -36,11 +36,11 @@ export type ZustandState = { readonly getRecords:
(table: table) => TableRecords
; readonly getRecord:
( table: table, - key: SchemaToPrimitives + key: SchemaToPrimitives, ) => TableRecord
| undefined; readonly getValue:
( table: table, - key: SchemaToPrimitives + key: SchemaToPrimitives, ) => TableRecord
["value"] | undefined; }; @@ -65,12 +65,12 @@ export function createStore(opts: CreateStoreOptions(table: table): TableRecords
=> { const records = get().records; return Object.fromEntries( - Object.entries(records).filter(([id, record]) => record.table.tableId === table.tableId) + Object.entries(records).filter(([id, record]) => record.table.tableId === table.tableId), ) as unknown as TableRecords
; }, getRecord:
( table: table, - key: SchemaToPrimitives + key: SchemaToPrimitives, ): TableRecord
| undefined => { const keyTuple = encodeKey(flattenSchema(table.keySchema), key); const id = getId({ tableId: table.tableId, keyTuple }); @@ -78,7 +78,7 @@ export function createStore(opts: CreateStoreOptions( table: table, - key: SchemaToPrimitives + key: SchemaToPrimitives, ): TableRecord
["value"] | undefined => { return get().getRecord(table, key)?.value; }, diff --git a/packages/store-sync/src/zustand/getId.test.ts b/packages/store-sync/src/zustand/getId.test.ts index e47b398a4e..2016d318a0 100644 --- a/packages/store-sync/src/zustand/getId.test.ts +++ b/packages/store-sync/src/zustand/getId.test.ts @@ -7,9 +7,9 @@ describe("getId", () => { getId({ tableId: "0x74626d756473746f72650000000000005461626c657300000000000000000000", keyTuple: ["0x74626d756473746f72650000000000005461626c657300000000000000000000"], - }) + }), ).toMatchInlineSnapshot( - '"0x74626d756473746f72650000000000005461626c657300000000000000000000:0x74626d756473746f72650000000000005461626c657300000000000000000000"' + '"0x74626d756473746f72650000000000005461626c657300000000000000000000:0x74626d756473746f72650000000000005461626c657300000000000000000000"', ); }); }); diff --git a/packages/store-sync/src/zustand/logToTable.test.ts b/packages/store-sync/src/zustand/logToTable.test.ts index 010d25b7ed..fbaf89cd0c 100644 --- a/packages/store-sync/src/zustand/logToTable.test.ts +++ b/packages/store-sync/src/zustand/logToTable.test.ts @@ -18,7 +18,7 @@ describe("logToTable", () => { // eslint-disable-next-line max-len "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000077461626c654964000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000b6669656c644c61796f757400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000096b6579536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b76616c7565536368656d610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012616269456e636f6465644b65794e616d657300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014616269456e636f6465644669656c644e616d6573000000000000000000000000", }, - }) + }), ).toMatchInlineSnapshot(` { "keySchema": { diff --git a/packages/store-sync/src/zustand/logToTable.ts b/packages/store-sync/src/zustand/logToTable.ts index 8d2b32e4e7..703f276704 100644 --- a/packages/store-sync/src/zustand/logToTable.ts +++ b/packages/store-sync/src/zustand/logToTable.ts @@ -14,7 +14,7 @@ export function logToTable(log: StorageAdapterLog & { eventName: "Store_SetRecor const value = decodeValue( schemasTable.valueSchema, - concatHex([log.args.staticData, log.args.encodedLengths, log.args.dynamicData]) + concatHex([log.args.staticData, log.args.encodedLengths, log.args.dynamicData]), ); const keySchema = hexToSchema(value.keySchema); diff --git a/packages/store-sync/src/zustand/syncToZustand.ts b/packages/store-sync/src/zustand/syncToZustand.ts index 850bb1c231..d5df3c0e80 100644 --- a/packages/store-sync/src/zustand/syncToZustand.ts +++ b/packages/store-sync/src/zustand/syncToZustand.ts @@ -9,7 +9,7 @@ import { SyncStep } from "../SyncStep"; type AllTables< config extends StoreConfig, - extraTables extends Tables | undefined + extraTables extends Tables | undefined, > = ResolvedStoreConfig["tables"] & (extraTables extends Tables ? extraTables : Record) & typeof storeTables & diff --git a/packages/store-sync/test/logsToBlocks.ts b/packages/store-sync/test/logsToBlocks.ts index e3ffb8a9ac..2c92392316 100644 --- a/packages/store-sync/test/logsToBlocks.ts +++ b/packages/store-sync/test/logsToBlocks.ts @@ -4,7 +4,7 @@ import { RpcLog, formatLog, decodeEventLog, Hex } from "viem"; import { StoreEventsLog } from "../src/common"; export function logsToBlocks( - rpcLogs: { data: string; topics: string[] }[] + rpcLogs: { data: string; topics: string[] }[], ): GroupLogsByBlockNumberResult { return groupLogsByBlockNumber( rpcLogs.map((log) => { @@ -15,6 +15,6 @@ export function logsToBlocks( strict: true, }); return formatLog(log as any as RpcLog, { args, eventName: eventName as string }) as StoreEventsLog; - }) + }), ); } diff --git a/packages/store/src/IStore.sol b/packages/store/src/IStore.sol index 7f8e54a0b6..6510e115dc 100644 --- a/packages/store/src/IStore.sol +++ b/packages/store/src/IStore.sol @@ -9,6 +9,4 @@ import { IStoreRegistration } from "./IStoreRegistration.sol"; * @title IStore * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) */ -interface IStore is IStoreData, IStoreRegistration, IStoreErrors { - -} +interface IStore is IStoreData, IStoreRegistration, IStoreErrors {} diff --git a/packages/store/ts/codegen/field.ts b/packages/store/ts/codegen/field.ts index b9992e8ba7..ce62a59584 100644 --- a/packages/store/ts/codegen/field.ts +++ b/packages/store/ts/codegen/field.ts @@ -35,10 +35,10 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Get ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}get${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal view returns (${_typedFieldName}) { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal view returns (${_typedFieldName}) { ${_keyTupleDefinition} ${ field.isDynamic @@ -56,8 +56,8 @@ export function renderFieldMethods(options: RenderTableOptions): string { } return ${renderDecodeFieldSingle(field)}; } - ` - ) + `, + ), ); } @@ -79,7 +79,7 @@ export function renderFieldMethods(options: RenderTableOptions): string { ${_store}.${setFieldMethod}(${internalArguments}); } `; - }) + }), ); if (field.isDynamic) { @@ -97,14 +97,14 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Get the length of ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}length${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal pure returns (uint256) { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal pure returns (uint256) { return ${typeWrappingData.staticLength}; } - ` - ) + `, + ), ); } else { result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => @@ -115,18 +115,18 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Get the length of ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}length${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal view returns (uint256) { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal view returns (uint256) { ${_keyTupleDefinition} uint256 _byteLength = ${_store}.getDynamicFieldLength(_tableId, _keyTuple, ${dynamicSchemaIndex}); unchecked { return _byteLength / ${portionData.elementLength}; } } - ` - ) + `, + ), ); } @@ -139,11 +139,11 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @dev Reverts with Store_IndexOutOfBounds if \`_index\` is out of bounds for the array. */ function ${_methodNamePrefix}getItem${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - "uint256 _index", - ])}) internal view returns (${portionData.typeWithLocation}) { + _typedStore, + _typedTableId, + _typedKeyArgs, + "uint256 _index", + ])}) internal view returns (${portionData.typeWithLocation}) { ${_keyTupleDefinition} unchecked { bytes memory _blob = ${_store}.getDynamicFieldSlice( @@ -156,8 +156,8 @@ export function renderFieldMethods(options: RenderTableOptions): string { return ${portionData.decoded}; } } - ` - ) + `, + ), ); } @@ -170,16 +170,16 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Push ${portionData.title} to ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}push${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - `${portionData.typeWithLocation} ${portionData.name}`, - ])}) internal { + _typedStore, + _typedTableId, + _typedKeyArgs, + `${portionData.typeWithLocation} ${portionData.name}`, + ])}) internal { ${_keyTupleDefinition} ${_store}.pushToDynamicField(_tableId, _keyTuple, ${dynamicSchemaIndex}, ${portionData.encoded}); } - ` - ) + `, + ), ); result += renderWithFieldSuffix(options.withSuffixlessFieldMethods, field.name, (_methodNameSuffix) => @@ -190,15 +190,15 @@ export function renderFieldMethods(options: RenderTableOptions): string { * @notice Pop ${portionData.title} from ${field.name}${_commentSuffix}. */ function ${_methodNamePrefix}pop${_methodNameSuffix}(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal { ${_keyTupleDefinition} ${_store}.popFromDynamicField(_tableId, _keyTuple, ${dynamicSchemaIndex}, ${portionData.elementLength}); } - ` - ) + `, + ), ); } @@ -233,7 +233,7 @@ export function renderFieldMethods(options: RenderTableOptions): string { } } `; - }) + }), ); } } diff --git a/packages/store/ts/codegen/record.ts b/packages/store/ts/codegen/record.ts index 7d190b8185..bd540d7068 100644 --- a/packages/store/ts/codegen/record.ts +++ b/packages/store/ts/codegen/record.ts @@ -27,10 +27,10 @@ export function renderRecordMethods(options: RenderTableOptions) { * @notice Get the full data${_commentSuffix}. */ function ${_methodNamePrefix}get(${renderArguments([ - _typedStore, - _typedTableId, - _typedKeyArgs, - ])}) internal view returns (${renderDecodedRecord(options)}) { + _typedStore, + _typedTableId, + _typedKeyArgs, + ])}) internal view returns (${renderDecodedRecord(options)}) { ${_keyTupleDefinition} ( @@ -40,7 +40,7 @@ export function renderRecordMethods(options: RenderTableOptions) { ) = ${_store}.getRecord(_tableId, _keyTuple, _fieldLayout); return decode(_staticData, _encodedLengths, _dynamicData); } - ` + `, ); } @@ -70,7 +70,7 @@ export function renderRecordMethods(options: RenderTableOptions) { ${_store}.setRecord(${internalArguments}); } `; - } + }, ); if (structName !== undefined) { @@ -100,7 +100,7 @@ export function renderRecordMethods(options: RenderTableOptions) { ${_store}.setRecord(${internalArguments}); } `; - } + }, ); } @@ -170,7 +170,7 @@ export function renderDeleteRecordMethods(options: RenderTableOptions) { ${_store}.deleteRecord(${internalArguments}); } `; - } + }, ); } @@ -202,13 +202,13 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields * @notice Decode the tightly packed blob of static data using this table's field layout. */ function decodeStatic(bytes memory _blob) internal pure returns (${renderArguments( - staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) { ${renderList( staticFields, (field, index) => ` ${field.name} = ${renderDecodeValueType(field, staticOffsets[index])}; - ` + `, )} } `; @@ -220,7 +220,7 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic(PackedCounter _encodedLengths, bytes memory _blob) internal pure returns (${renderArguments( - dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) { ${renderList( dynamicFields, @@ -245,7 +245,7 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields ${field.name} = ${renderDecodeDynamicFieldPartial(field)}; `; } - } + }, )} } `; @@ -273,7 +273,7 @@ function renderDecodeFunctions({ structName, fields, staticFields, dynamicFields if (dynamicFields.length > 0) { result += ` (${renderArguments( - dynamicFields.map((field) => `${fieldNamePrefix}${field.name}`) + dynamicFields.map((field) => `${fieldNamePrefix}${field.name}`), )}) = decodeDynamic(_encodedLengths, _dynamicData); `; } diff --git a/packages/store/ts/codegen/renderFieldLayout.test.ts b/packages/store/ts/codegen/renderFieldLayout.test.ts index 38b8b4b6df..89c6663f74 100644 --- a/packages/store/ts/codegen/renderFieldLayout.test.ts +++ b/packages/store/ts/codegen/renderFieldLayout.test.ts @@ -35,23 +35,23 @@ describe("renderFieldLayout", () => { ]; expect(renderFieldLayout(fields)).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x013418040102030405060708090a0b0c0d0e0f10111213141516172000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x013418040102030405060708090a0b0c0d0e0f10111213141516172000000000);"', ); expect(renderFieldLayout([{ isDynamic: false, staticByteLength: 2 }])).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0002010002000000000000000000000000000000000000000000000000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0002010002000000000000000000000000000000000000000000000000000000);"', ); expect(renderFieldLayout([{ isDynamic: false, staticByteLength: 8 }])).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0008010008000000000000000000000000000000000000000000000000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0008010008000000000000000000000000000000000000000000000000000000);"', ); expect(renderFieldLayout([{ isDynamic: false, staticByteLength: 16 }])).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0010010010000000000000000000000000000000000000000000000000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0010010010000000000000000000000000000000000000000000000000000000);"', ); expect(renderFieldLayout([{ isDynamic: true, staticByteLength: 0 }])).toMatchInlineSnapshot( - '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000);"' + '"FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0000000100000000000000000000000000000000000000000000000000000000);"', ); }); diff --git a/packages/store/ts/codegen/renderTable.ts b/packages/store/ts/codegen/renderTable.ts index e7fba56e6b..b67fc87650 100644 --- a/packages/store/ts/codegen/renderTable.ts +++ b/packages/store/ts/codegen/renderTable.ts @@ -80,11 +80,11 @@ export function renderTable(options: RenderTableOptions) { // Hex-encoded key schema of (${keyTuple.map((field) => field.internalTypeId).join(", ")}) Schema constant _keySchema = Schema.wrap(${keySchemaToHex( - Object.fromEntries(keyTuple.map((field) => [field.name, field.internalTypeId])) as KeySchema + Object.fromEntries(keyTuple.map((field) => [field.name, field.internalTypeId])) as KeySchema, )}); // Hex-encoded value schema of (${fields.map((field) => field.internalTypeId).join(", ")}) Schema constant _valueSchema = Schema.wrap(${valueSchemaToHex( - Object.fromEntries(fields.map((field) => [field.name, field.internalTypeId])) as ValueSchema + Object.fromEntries(fields.map((field) => [field.name, field.internalTypeId])) as ValueSchema, )}); /** @@ -114,7 +114,7 @@ export function renderTable(options: RenderTableOptions) { function ${_methodNamePrefix}register(${renderArguments([_typedStore, _typedTableId])}) internal { ${_store}.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } - ` + `, )} ${renderFieldMethods(options)} @@ -136,7 +136,7 @@ export function renderTable(options: RenderTableOptions) { * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ function encode(${renderArguments( - options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + options.fields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) internal pure returns (bytes memory, PackedCounter, bytes memory) { ${renderRecordData(options)} @@ -171,7 +171,7 @@ function renderEncodeStatic(staticFields: RenderStaticField[]) { * @return The static data, encoded into a sequence of bytes. */ function encodeStatic(${renderArguments( - staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + staticFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) internal pure returns (bytes memory) { return abi.encodePacked(${renderArguments(staticFields.map(({ name }) => name))}); } @@ -193,7 +193,7 @@ function renderEncodeLengths(dynamicFields: RenderDynamicField[]) { * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ function encodeLengths(${renderArguments( - dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) internal pure returns (PackedCounter _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { @@ -205,7 +205,7 @@ function renderEncodeLengths(dynamicFields: RenderDynamicField[]) { } else { return `bytes(${name}).length`; } - }) + }), )} ); } @@ -228,7 +228,7 @@ function renderEncodeDynamic(dynamicFields: RenderDynamicField[]) { * @return The dynamic data, encoded into a sequence of bytes. */ function encodeDynamic(${renderArguments( - dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`) + dynamicFields.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`), )}) internal pure returns (bytes memory) { return abi.encodePacked(${renderArguments(dynamicFields.map((field) => renderEncodeFieldSingle(field)))}); } diff --git a/packages/store/ts/codegen/tableOptions.ts b/packages/store/ts/codegen/tableOptions.ts index b46b24d3d1..208fc42e6e 100644 --- a/packages/store/ts/codegen/tableOptions.ts +++ b/packages/store/ts/codegen/tableOptions.ts @@ -26,7 +26,7 @@ export interface TableOptions { */ export function getTableOptions( config: StoreConfig, - solidityUserTypes: Record + solidityUserTypes: Record, ): TableOptions[] { const storeImportPath = config.storeImportPath; diff --git a/packages/store/ts/codegen/tablegen.ts b/packages/store/ts/codegen/tablegen.ts index 18d0bcfb56..02cd7a62c2 100644 --- a/packages/store/ts/codegen/tablegen.ts +++ b/packages/store/ts/codegen/tablegen.ts @@ -15,7 +15,7 @@ export async function tablegen(config: StoreConfig, outputBaseDirectory: string, await Promise.all( uniqueTableDirectories.map(async (tableDir) => { await rm(path.join(outputBaseDirectory, tableDir), { recursive: true, force: true }); - }) + }), ); // write tables to files @@ -24,7 +24,7 @@ export async function tablegen(config: StoreConfig, outputBaseDirectory: string, const fullOutputPath = path.join(outputBaseDirectory, outputPath); const output = renderTable(renderOptions); await formatAndWriteSolidity(output, fullOutputPath, "Generated table"); - }) + }), ); // write table index diff --git a/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts b/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts index 77f088125d..1e1518eaec 100644 --- a/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts +++ b/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts @@ -25,7 +25,7 @@ export function renderDecodeSlice() { renderTightCoderDecode({ internalTypeId: staticAbiType, staticByteLength: staticAbiTypeToByteLength[staticAbiType], - }) + }), ) .join("\n")} } diff --git a/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts b/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts index 477445e1c6..27d894a2d4 100644 --- a/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts +++ b/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts @@ -23,7 +23,7 @@ export function renderEncodeArray() { renderTightCoderEncode({ internalTypeId: staticAbiType, staticByteLength: staticAbiTypeToByteLength[staticAbiType], - }) + }), ) .join("\n")} } diff --git a/packages/store/ts/codegen/userType.ts b/packages/store/ts/codegen/userType.ts index 72e613df37..62b371c8d9 100644 --- a/packages/store/ts/codegen/userType.ts +++ b/packages/store/ts/codegen/userType.ts @@ -14,7 +14,7 @@ import { StoreConfig } from "../config"; export function resolveAbiOrUserType( abiOrUserType: string, config: StoreConfig, - solidityUserTypes: Record + solidityUserTypes: Record, ): { schemaType: SchemaType; renderType: RenderType; @@ -47,7 +47,7 @@ export function importForAbiOrUserType( abiOrUserType: string, usedInDirectory: string, config: StoreConfig, - solidityUserTypes: Record + solidityUserTypes: Record, ): ImportDatum | undefined { // abi types which directly mirror a SchemaType if (abiOrUserType in AbiTypeToSchemaType) { @@ -103,7 +103,7 @@ export function getSchemaTypeInfo(schemaType: SchemaType): RenderType { export function getUserTypeInfo( userType: string, config: StoreConfig, - solidityUserTypes: Record + solidityUserTypes: Record, ): { schemaType: SchemaType; renderType: RenderType; diff --git a/packages/store/ts/common.ts b/packages/store/ts/common.ts index a4d57e182c..5a9d1ebeb9 100644 --- a/packages/store/ts/common.ts +++ b/packages/store/ts/common.ts @@ -33,14 +33,14 @@ export type SchemaToPrimitives = { export type ConfigFieldTypeToSchemaAbiType> = T extends SchemaAbiType ? T : T extends `${string}[${string}]` - ? "uint8[]" - : "uint8"; + ? "uint8[]" + : "uint8"; export type ConfigFieldTypeToPrimitiveType> = T extends SchemaAbiType ? SchemaAbiTypeToPrimitiveType : T extends `${string}[${string}]` // field type might include enums and enum arrays, which are mapped to uint8/uint8[] - ? number[] // map enum arrays to `number[]` - : number; // map enums to `number` + ? number[] // map enum arrays to `number[]` + : number; // map enums to `number` /** Map a table schema config like `{ value: "uint256", type: "SomeEnum" }` to its primitive types like `{ value: bigint, type: number }` */ export type SchemaConfigToPrimitives = { @@ -56,12 +56,12 @@ export type ConfigToTablesPrimitives = { export type ConfigToKeyPrimitives< C extends StoreConfig, - Table extends keyof ConfigToTablesPrimitives + Table extends keyof ConfigToTablesPrimitives, > = ConfigToTablesPrimitives[Table]["key"]; export type ConfigToValuePrimitives< C extends StoreConfig, - Table extends keyof ConfigToTablesPrimitives + Table extends keyof ConfigToTablesPrimitives, > = ConfigToTablesPrimitives[Table]["value"]; export type ConfigToRecordPrimitives> = { diff --git a/packages/store/ts/config/experimental/resolveConfig.test-d.ts b/packages/store/ts/config/experimental/resolveConfig.test-d.ts index 0c5f5e52a3..80d8c8a960 100644 --- a/packages/store/ts/config/experimental/resolveConfig.test-d.ts +++ b/packages/store/ts/config/experimental/resolveConfig.test-d.ts @@ -29,7 +29,7 @@ describe("resolveConfig", () => { valueSchema: "ResourceType", }, }, - }) + }), ); expectTypeOf().toEqualTypeOf<"the-namespace">(); diff --git a/packages/store/ts/config/experimental/resolveConfig.test.ts b/packages/store/ts/config/experimental/resolveConfig.test.ts index d6187ca73c..c011aa1d01 100644 --- a/packages/store/ts/config/experimental/resolveConfig.test.ts +++ b/packages/store/ts/config/experimental/resolveConfig.test.ts @@ -25,7 +25,7 @@ const config = resolveConfig( valueSchema: "ResourceType", }, }, - }) + }), ); describe("resolveConfig", () => { @@ -35,7 +35,7 @@ describe("resolveConfig", () => { expect(config.tables.Shorthand.name).toEqual("Shorthand"); expect(config.tables.Shorthand.tableId).toEqual( - resourceToHex({ type: "table", namespace: "the-namespace", name: "Shorthand" }) + resourceToHex({ type: "table", namespace: "the-namespace", name: "Shorthand" }), ); expect(config.tables.Shorthand.keySchema).toEqual({ diff --git a/packages/store/ts/config/experimental/resolveConfig.ts b/packages/store/ts/config/experimental/resolveConfig.ts index 83354fa8f5..0d03e36884 100644 --- a/packages/store/ts/config/experimental/resolveConfig.ts +++ b/packages/store/ts/config/experimental/resolveConfig.ts @@ -26,7 +26,7 @@ type ResolvedTableConfig< TUserTypes extends UserTypesConfig["userTypes"], TEnumNames extends StringForUnion, TNamespace extends string = string, - TName extends string = string + TName extends string = string, > = { keySchema: ResolvedKeySchema; valueSchema: ResolvedValueSchema; @@ -38,34 +38,34 @@ type ResolvedTableConfig< type ResolvedKeySchema< TKeySchema extends TableConfig["keySchema"], TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion + TEnumNames extends StringForUnion, > = ResolvedSchema; type ResolvedValueSchema< TValueSchema extends TableConfig["valueSchema"], TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion + TEnumNames extends StringForUnion, > = ResolvedSchema, TUserTypes, TEnumNames>; type ResolvedSchema< TSchema extends Exclude, TUserTypes extends UserTypesConfig["userTypes"], - TEnumNames extends StringForUnion + TEnumNames extends StringForUnion, > = { [key in keyof TSchema]: { type: TSchema[key] extends SchemaAbiType ? TSchema[key] : TSchema[key] extends keyof TUserTypes - ? TUserTypes[TSchema[key]] extends UserType - ? // Note: we mistakenly named the plain ABI type "internalType", - // while in Solidity ABIs the plain ABI type is called "type" and - // and the custom type "internalType". We're planning to - // change our version and align with Solidity ABIs going forward. - TUserTypes[TSchema[key]]["internalType"] - : never - : TSchema[key] extends TEnumNames - ? "uint8" - : never; + ? TUserTypes[TSchema[key]] extends UserType + ? // Note: we mistakenly named the plain ABI type "internalType", + // while in Solidity ABIs the plain ABI type is called "type" and + // and the custom type "internalType". We're planning to + // change our version and align with Solidity ABIs going forward. + TUserTypes[TSchema[key]]["internalType"] + : never + : TSchema[key] extends TEnumNames + ? "uint8" + : never; internalType: TSchema[key]; }; }; @@ -75,7 +75,7 @@ type ResolvedSchema< * @deprecated Internal only */ export function resolveConfig( - config: TStoreConfig + config: TStoreConfig, ): ResolvedStoreConfig { const resolvedTables: Record> = {}; @@ -85,7 +85,7 @@ export function resolveConfig( config.userTypes, Object.keys(config.enums), config.namespace, - key + key, ) as ReturnType; } @@ -99,13 +99,13 @@ function resolveTable< TUserTypes extends UserTypesConfig["userTypes"], TEnums extends StringForUnion[], TNamespace extends string, - TName extends string + TName extends string, >( tableConfig: TTableConfig, userTypes: TUserTypes, enums: TEnums, namespace: TNamespace, - name: TName + name: TName, ): ResolvedTableConfig { const { keySchema, valueSchema } = tableConfig; @@ -125,11 +125,11 @@ function resolveTable< function resolveKeySchema< TKeySchema extends TableConfig["keySchema"], TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[] + TEnums extends StringForUnion[], >( keySchema: TKeySchema, userTypes: TUserTypes, - enums: TEnums + enums: TEnums, ): ResolvedKeySchema { const schema = ( keySchema == null ? { key: "bytes32" } : typeof keySchema === "string" ? { key: keySchema } : keySchema @@ -140,11 +140,11 @@ function resolveKeySchema< function resolveValueSchema< TValueSchema extends TableConfig["valueSchema"], TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[] + TEnums extends StringForUnion[], >( valueSchema: TValueSchema, userTypes: TUserTypes, - enums: TEnums + enums: TEnums, ): ResolvedValueSchema { const schema = ( typeof valueSchema === "string" ? ({ value: valueSchema } as unknown as TValueSchema) : valueSchema @@ -155,7 +155,7 @@ function resolveValueSchema< function resolveSchema< TSchema extends Exclude | TableConfig["valueSchema"], string>, TUserTypes extends UserTypesConfig["userTypes"], - TEnums extends StringForUnion[] + TEnums extends StringForUnion[], >(schema: TSchema, userTypes: TUserTypes, enums: TEnums): ResolvedSchema { return mapObject>(schema, (value, key) => { const isUserType = userTypes && value in userTypes; diff --git a/packages/store/ts/config/storeConfig.ts b/packages/store/ts/config/storeConfig.ts index 01c2b5e002..dc474f4f49 100644 --- a/packages/store/ts/config/storeConfig.ts +++ b/packages/store/ts/config/storeConfig.ts @@ -73,7 +73,7 @@ export const zSchemaConfig = zFullSchemaConfig.or(zShorthandSchemaConfig); type ResolvedSchema< TSchema extends Record, - TUserTypes extends Record> + TUserTypes extends Record>, > = { [key in keyof TSchema]: TSchema[key] extends keyof TUserTypes ? TUserTypes[TSchema[key]]["internalType"] @@ -84,7 +84,7 @@ type ResolvedSchema< // (see https://github.com/latticexyz/mud/pull/1588) export function resolveUserTypes< TSchema extends Record, - TUserTypes extends Record> + TUserTypes extends Record>, >(schema: TSchema, userTypes: TUserTypes): ResolvedSchema { const resolvedSchema: Record = {}; for (const [key, value] of Object.entries(schema)) { @@ -109,7 +109,7 @@ export function resolveUserTypes< export interface TableConfig< UserTypes extends StringForUnion = StringForUnion, - StaticUserTypes extends StringForUnion = StringForUnion + StaticUserTypes extends StringForUnion = StringForUnion, > { /** Output directory path for the file. Default is "tables" */ directory?: string; @@ -136,7 +136,7 @@ export interface TableConfig< export type FullTableConfig< UserTypes extends StringForUnion = StringForUnion, - StaticUserTypes extends StringForUnion = StringForUnion + StaticUserTypes extends StringForUnion = StringForUnion, > = Required> & { valueSchema: FullSchemaConfig; }; @@ -197,7 +197,7 @@ export const zTableConfig = zFullTableConfig.or(zShorthandTableConfig); export type TablesConfig< UserTypes extends StringForUnion = StringForUnion, - StaticUserTypes extends StringForUnion = StringForUnion + StaticUserTypes extends StringForUnion = StringForUnion, > = Record | FieldData>; export const zTablesConfig = z.record(zTableName, zTableConfig).transform((tables) => { @@ -213,17 +213,17 @@ export const zTablesConfig = z.record(zTableName, zTableConfig).transform((table export type FullTablesConfig< UserTypes extends StringForUnion = StringForUnion, - StaticUserTypes extends StringForUnion = StringForUnion + StaticUserTypes extends StringForUnion = StringForUnion, > = Record>; export type ExpandTablesConfig> = { [TableName in keyof T]: T[TableName] extends FieldData ? ExpandTableConfig<{ valueSchema: { value: T[TableName] } }, TableName extends string ? TableName : never> : T[TableName] extends TableConfig - ? ExpandTableConfig - : // Weakly typed values get a weakly typed expansion. - // This shouldn't normally happen within `mudConfig`, but can be manually triggered via `ExpandMUDUserConfig` - ExpandTableConfig, TableName extends string ? TableName : string>; + ? ExpandTableConfig + : // Weakly typed values get a weakly typed expansion. + // This shouldn't normally happen within `mudConfig`, but can be manually triggered via `ExpandMUDUserConfig` + ExpandTableConfig, TableName extends string ? TableName : string>; }; /************************************************************************ @@ -242,22 +242,22 @@ export type EnumsConfig = never extends EnumNa enums?: Record; } : StringForUnion extends EnumNames - ? { - /** - * Enum names mapped to lists of their member names - * - * (enums aren't inferred - use `mudConfig` or `storeConfig` helper, and `as const` for variables) - */ - enums?: Record; - } - : { - /** - * Enum names mapped to lists of their member names - * - * Enums defined here can be used as types in table schemas/keys - */ - enums: Record; - }; + ? { + /** + * Enum names mapped to lists of their member names + * + * (enums aren't inferred - use `mudConfig` or `storeConfig` helper, and `as const` for variables) + */ + enums?: Record; + } + : { + /** + * Enum names mapped to lists of their member names + * + * Enums defined here can be used as types in table schemas/keys + */ + enums: Record; + }; export type FullEnumsConfig = { enums: Record; @@ -285,26 +285,26 @@ export type UserTypesConfig; } : StringForUnion extends UserTypeNames - ? { - /** - * User types mapped to file paths from which to import them. - * Paths are treated as relative to root. - * Paths that don't start with a "." have foundry remappings applied to them first. - * - * (user types aren't inferred - use `mudConfig` or `storeConfig` helper, and `as const` for variables) - */ - userTypes?: Record; - } - : { - /** - * User types mapped to file paths from which to import them. - * Paths are treated as relative to root. - * Paths that don't start with a "." have foundry remappings applied to them first. - * - * User types defined here can be used as types in table schemas/keys - */ - userTypes: Record; - }; + ? { + /** + * User types mapped to file paths from which to import them. + * Paths are treated as relative to root. + * Paths that don't start with a "." have foundry remappings applied to them first. + * + * (user types aren't inferred - use `mudConfig` or `storeConfig` helper, and `as const` for variables) + */ + userTypes?: Record; + } + : { + /** + * User types mapped to file paths from which to import them. + * Paths are treated as relative to root. + * Paths that don't start with a "." have foundry remappings applied to them first. + * + * User types defined here can be used as types in table schemas/keys + */ + userTypes: Record; + }; const zUserTypeConfig = z.object({ filePath: z.string(), @@ -327,7 +327,7 @@ export type MUDUserConfig< T extends MUDCoreUserConfig = MUDCoreUserConfig, EnumNames extends StringForUnion = StringForUnion, UserTypeNames extends StringForUnion = StringForUnion, - StaticUserTypes extends ExtractUserTypes = ExtractUserTypes + StaticUserTypes extends ExtractUserTypes = ExtractUserTypes, > = T & EnumsConfig & UserTypesConfig & { @@ -404,7 +404,7 @@ function validateStoreConfig(config: z.output, ctx: ctx.addIssue({ code: ZodIssueCode.custom, message: `Table library names, enum names, user type names must be globally unique: ${duplicateGlobalNames.join( - ", " + ", ", )}`, }); } @@ -432,7 +432,7 @@ function validateAbiOrUserType( userTypeNames: string[], staticUserTypeNames: string[], type: string, - ctx: RefinementCtx + ctx: RefinementCtx, ) { if (!(AbiTypes as string[]).includes(type) && !userTypeNames.includes(type)) { const staticArray = parseStaticArray(type); @@ -460,7 +460,7 @@ function validateStaticArray( staticUserTypeNames: string[], elementType: string, staticLength: number, - ctx: RefinementCtx + ctx: RefinementCtx, ) { validateStaticAbiOrUserType(staticUserTypeNames, elementType, ctx); diff --git a/packages/store/ts/register/mudConfig.ts b/packages/store/ts/register/mudConfig.ts index 907ef5fb1c..4ac0be54d4 100644 --- a/packages/store/ts/register/mudConfig.ts +++ b/packages/store/ts/register/mudConfig.ts @@ -9,7 +9,7 @@ export function mudConfig< // (`never` is overridden by inference, so only the defined enums can be used by default) EnumNames extends StringForUnion = never, UserTypeNames extends StringForUnion = never, - StaticUserTypes extends ExtractUserTypes = ExtractUserTypes + StaticUserTypes extends ExtractUserTypes = ExtractUserTypes, >(config: MUDUserConfig): ExpandMUDUserConfig { // eslint-disable-next-line @typescript-eslint/no-explicit-any return mudCoreConfig(config) as any; diff --git a/packages/store/ts/scripts/generate-tightcoder.ts b/packages/store/ts/scripts/generate-tightcoder.ts index dd95ddb9bb..d4f0a56579 100644 --- a/packages/store/ts/scripts/generate-tightcoder.ts +++ b/packages/store/ts/scripts/generate-tightcoder.ts @@ -6,5 +6,5 @@ await formatAndWriteSolidity(renderEncodeArray(), "src/tightcoder/EncodeArray.so await formatAndWriteSolidity( renderTightCoderAutoTest(), "test/tightcoder/TightCoderAuto.t.sol", - "Generated TightCoderAutoTest" + "Generated TightCoderAutoTest", ); diff --git a/packages/store/ts/storeEvents.test.ts b/packages/store/ts/storeEvents.test.ts index b7361f5664..e4e7c06daf 100644 --- a/packages/store/ts/storeEvents.test.ts +++ b/packages/store/ts/storeEvents.test.ts @@ -20,7 +20,7 @@ describe("Store events", () => { for (const storeEvent of storeEvents) { const parsedStoreEvent = parseAbiItem(storeEvent); const abiItem = IStoreAbi.find( - (item) => item.type === parsedStoreEvent.type && item.name === parsedStoreEvent.name + (item) => item.type === parsedStoreEvent.type && item.name === parsedStoreEvent.name, ); expect(abiItem).not.toBeUndefined(); expect(normalizeAbiEvent(parsedStoreEvent)).toMatchObject(normalizeAbiEvent(abiItem as AbiEvent)); diff --git a/packages/utils/src/bytes.ts b/packages/utils/src/bytes.ts index c90728e7b9..659cda462f 100644 --- a/packages/utils/src/bytes.ts +++ b/packages/utils/src/bytes.ts @@ -20,7 +20,7 @@ export function concatUint8Arrays(...arrays: Uint8Array[]): Uint8Array { return Uint8Array.from( arrays.reduce((acc, curr) => { return [...acc, ...curr]; - }, []) + }, []), ); } diff --git a/packages/utils/src/cubic.ts b/packages/utils/src/cubic.ts index 611da1a9b5..bddb47e232 100644 --- a/packages/utils/src/cubic.ts +++ b/packages/utils/src/cubic.ts @@ -30,7 +30,7 @@ export function cubicNoiseConfig( octave: number, scale: number, periodX = Number.MAX_SAFE_INTEGER, - periodY = Number.MAX_SAFE_INTEGER + periodY = Number.MAX_SAFE_INTEGER, ) { return { seed: Math.floor(seed * Number.MAX_SAFE_INTEGER), @@ -59,7 +59,7 @@ export function cubicNoiseSample1(config: ReturnType, x randomize(config.seed, tile(xi + 2, config.periodX), 0), lerp, 1, - 1 + 1, ) * 0.666666 + 0.166666 @@ -76,7 +76,7 @@ export function cubicNoiseSample1(config: ReturnType, x export function cubicNoiseSample2( { octave, periodX, periodY, seed, scale }: ReturnType, x: number, - y: number + y: number, ) { const xi = Math.floor(x / octave); const lerpX = Math.floor((x * ACCURACY) / octave) - xi * ACCURACY; @@ -99,11 +99,11 @@ export function cubicNoiseSample2( randomize(seed, x3, y), lerpX, ACCURACY, - 1 + 1, ); } return Math.floor( - interpolate(xSamples[0], xSamples[1], xSamples[2], xSamples[3], lerpY, ACCURACY, scale) / Math.pow(ACCURACY, 6) + interpolate(xSamples[0], xSamples[1], xSamples[2], xSamples[3], lerpY, ACCURACY, scale) / Math.pow(ACCURACY, 6), ); } diff --git a/packages/utils/src/mobx.ts b/packages/utils/src/mobx.ts index 659c28fa54..40583c831c 100644 --- a/packages/utils/src/mobx.ts +++ b/packages/utils/src/mobx.ts @@ -15,7 +15,7 @@ export async function awaitValue(comp: IComputedValue | IObser resolve(value); } }, - { fireImmediately: true } + { fireImmediately: true }, ); const value = await promise; diff --git a/packages/utils/src/objects.ts b/packages/utils/src/objects.ts index fc491bb3c5..8b75d21d22 100644 --- a/packages/utils/src/objects.ts +++ b/packages/utils/src/objects.ts @@ -6,7 +6,7 @@ */ export function mapObject( source: S, - valueMap: (value: S[keyof S], key: keyof S) => T[keyof S] + valueMap: (value: S[keyof S], key: keyof S) => T[keyof S], ): T { const target: Partial<{ [key in keyof typeof source]: T[keyof S] }> = {}; for (const key in source) { diff --git a/packages/utils/src/promise.ts b/packages/utils/src/promise.ts index fcd11bd2a6..0af015a14b 100644 --- a/packages/utils/src/promise.ts +++ b/packages/utils/src/promise.ts @@ -20,7 +20,7 @@ export const callWithRetry = ( fn: (...args: any[]) => Promise, args: any[] = [], maxRetries = 10, - retryInterval = 1000 + retryInterval = 1000, ): Promise => { const [resolve, reject, promise] = deferred(); const process = async () => { diff --git a/packages/utils/src/proxy.ts b/packages/utils/src/proxy.ts index dc41151af6..85c599c21c 100644 --- a/packages/utils/src/proxy.ts +++ b/packages/utils/src/proxy.ts @@ -20,7 +20,7 @@ function deepAccess(target: Record, path: string[]): any { * @returns Cached */ export function cacheUntilReady>( - target: IObservableValue | IComputedValue + target: IObservableValue | IComputedValue, ): Cached { // The call queue contains the path and arguments of calls to the // proxiedTarget while the target was not available yet. @@ -71,7 +71,7 @@ export function cacheUntilReady>( return promise; } }, - } + }, ); reaction( @@ -94,7 +94,7 @@ export function cacheUntilReady>( resolve(target); } } - } + }, ); return proxiedTarget as Cached; diff --git a/packages/utils/src/rx.ts b/packages/utils/src/rx.ts index b18835a6b4..7a37b1f24a 100644 --- a/packages/utils/src/rx.ts +++ b/packages/utils/src/rx.ts @@ -19,7 +19,7 @@ import { awaitValue } from "./mobx"; export function filterNullish(): OperatorFunction> { return pipe, Observable>>( - filter((x: T) => x != null) as OperatorFunction> + filter((x: T) => x != null) as OperatorFunction>, ); } @@ -50,7 +50,7 @@ export function stretch(spacingDelayMs: number) { }; }, null), filterNullish(), - mergeMap((i) => of(i.value).pipe(delay(i.delay)), 1) + mergeMap((i) => of(i.value).pipe(delay(i.delay)), 1), ); } @@ -65,7 +65,7 @@ export function computedToStream(comp: IComputedValue | IObservableValue { if (value != null) stream.next(value); }, - { fireImmediately: true } + { fireImmediately: true }, ); return stream; } @@ -77,7 +77,7 @@ export function observableToStream(obs: T): Observable { (value) => { if (value != null) stream.next(value); }, - { fireImmediately: true } + { fireImmediately: true }, ); return stream; } @@ -104,7 +104,7 @@ export async function streamToDefinedComputed(stream$: Observable): Promis */ export async function awaitStreamValue( stream$: Observable, - predicate: (value: T) => boolean = (value) => value != null + predicate: (value: T) => boolean = (value) => value != null, ): Promise { const [resolve, , promise] = deferred(); stream$.pipe(first(predicate)).subscribe(resolve); diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index 1649769316..b9c1f99a4a 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -8,13 +8,13 @@ export type CachedValue = Proxied extends true ? V extends Func ? AsyncFunc : V extends Record - ? Cached & { proxied: true } - : { proxied: true } + ? Cached & { proxied: true } + : { proxied: true } : V extends Func - ? Func - : V extends Record - ? V - : V & { proxied: false }; + ? Func + : V extends Record + ? V + : V & { proxied: false }; export type Cached = | ({ proxied: false } & { [key in keyof C]: CachedValue }) diff --git a/packages/world-modules/src/interfaces/IBaseWorld.sol b/packages/world-modules/src/interfaces/IBaseWorld.sol index 4f1b8656d3..c71f2becc9 100644 --- a/packages/world-modules/src/interfaces/IBaseWorld.sol +++ b/packages/world-modules/src/interfaces/IBaseWorld.sol @@ -13,6 +13,4 @@ import { IWorldKernel } from "@latticexyz/world/src/IWorldKernel.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IBaseWorld is IStore, IWorldKernel { - -} +interface IBaseWorld is IStore, IWorldKernel {} diff --git a/packages/world/src/codegen/interfaces/IBaseWorld.sol b/packages/world/src/codegen/interfaces/IBaseWorld.sol index df94bca083..a30241297a 100644 --- a/packages/world/src/codegen/interfaces/IBaseWorld.sol +++ b/packages/world/src/codegen/interfaces/IBaseWorld.sol @@ -29,6 +29,4 @@ interface IBaseWorld is IModuleInstallationSystem, IWorldRegistrationSystem, IRegistrationSystem -{ - -} +{} diff --git a/packages/world/src/codegen/interfaces/IRegistrationSystem.sol b/packages/world/src/codegen/interfaces/IRegistrationSystem.sol index 75389f6bfb..d4dd6649d8 100644 --- a/packages/world/src/codegen/interfaces/IRegistrationSystem.sol +++ b/packages/world/src/codegen/interfaces/IRegistrationSystem.sol @@ -8,6 +8,4 @@ pragma solidity >=0.8.24; * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. */ -interface IRegistrationSystem { - -} +interface IRegistrationSystem {} diff --git a/packages/world/ts/config/resolveWorldConfig.ts b/packages/world/ts/config/resolveWorldConfig.ts index d2b3830d19..db54d6f0f5 100644 --- a/packages/world/ts/config/resolveWorldConfig.ts +++ b/packages/world/ts/config/resolveWorldConfig.ts @@ -28,7 +28,7 @@ export function resolveWorldConfig(config: StoreConfig & WorldConfig, existingCo // Combine the default and overridden system names and filter out excluded systems const systemNames = [...new Set([...defaultSystemNames, ...overriddenSystemNames])].filter( - (name) => !config.excludeSystems.includes(name) + (name) => !config.excludeSystems.includes(name), ); // Resolve the config diff --git a/packages/world/ts/config/worldConfig.ts b/packages/world/ts/config/worldConfig.ts index ecd579ac7f..71d56c8de7 100644 --- a/packages/world/ts/config/worldConfig.ts +++ b/packages/world/ts/config/worldConfig.ts @@ -20,7 +20,7 @@ const zSystemConfig = z.intersection( openAccess: z.literal(false), accessList: zSystemAccessList, }), - ]) + ]), ); const zValueWithType = z.object({ diff --git a/packages/world/ts/encodeSystemCalls.ts b/packages/world/ts/encodeSystemCalls.ts index fe027924da..f93301da43 100644 --- a/packages/world/ts/encodeSystemCalls.ts +++ b/packages/world/ts/encodeSystemCalls.ts @@ -6,7 +6,7 @@ import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype" /** Encode system calls to be passed as arguments into `World.batchCall` */ export function encodeSystemCalls>( abi: abi, - systemCalls: readonly Omit, "abi">[] + systemCalls: readonly Omit, "abi">[], ): AbiParametersToPrimitiveTypes["inputs"]>[] { return systemCalls.map((systemCall) => encodeSystemCall({ ...systemCall, abi } as SystemCall)); } diff --git a/packages/world/ts/encodeSystemCallsFrom.ts b/packages/world/ts/encodeSystemCallsFrom.ts index f5c9bf548e..0e0b40d0da 100644 --- a/packages/world/ts/encodeSystemCallsFrom.ts +++ b/packages/world/ts/encodeSystemCallsFrom.ts @@ -7,9 +7,9 @@ import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype" export function encodeSystemCallsFrom>( abi: abi, from: Address, - systemCalls: readonly Omit, "abi" | "from">[] + systemCalls: readonly Omit, "abi" | "from">[], ): AbiParametersToPrimitiveTypes["inputs"]>[] { return systemCalls.map((systemCall) => - encodeSystemCallFrom({ ...systemCall, abi, from } as SystemCallFrom) + encodeSystemCallFrom({ ...systemCall, abi, from } as SystemCallFrom), ); } diff --git a/packages/world/ts/node/render-solidity/renderSystemInterface.ts b/packages/world/ts/node/render-solidity/renderSystemInterface.ts index 9f01bda718..ceb3be23da 100644 --- a/packages/world/ts/node/render-solidity/renderSystemInterface.ts +++ b/packages/world/ts/node/render-solidity/renderSystemInterface.ts @@ -23,7 +23,7 @@ export function renderSystemInterface(options: RenderSystemInterfaceOptions) { function ${functionPrefix}${name}( ${renderArguments(parameters)} ) external ${stateMutability} ${renderReturnParameters(returnParameters)}; - ` + `, )} } `; diff --git a/packages/world/ts/node/render-solidity/worldgen.ts b/packages/world/ts/node/render-solidity/worldgen.ts index f9dbf77d37..af5313ead3 100644 --- a/packages/world/ts/node/render-solidity/worldgen.ts +++ b/packages/world/ts/node/render-solidity/worldgen.ts @@ -10,11 +10,11 @@ import { WorldConfig } from "../../config/types"; export async function worldgen( config: StoreConfig & WorldConfig, existingContracts: { path: string; basename: string }[], - outputBaseDirectory: string + outputBaseDirectory: string, ) { const resolvedConfig = resolveWorldConfig( config, - existingContracts.map(({ basename }) => basename) + existingContracts.map(({ basename }) => basename), ); const worldgenBaseDirectory = path.join(outputBaseDirectory, config.worldgenDirectory); diff --git a/packages/world/ts/worldEvents.test.ts b/packages/world/ts/worldEvents.test.ts index 080a1740fa..477e61127e 100644 --- a/packages/world/ts/worldEvents.test.ts +++ b/packages/world/ts/worldEvents.test.ts @@ -19,7 +19,7 @@ function normalizeAbiEvent(event: AbiEvent) { describe("WorldFactory events", () => { it("should match the ABI", () => { const forgeAbiItem = IWorldFactoryAbi.find( - (item) => item.type === "event" && item.name === "WorldDeployed" + (item) => item.type === "event" && item.name === "WorldDeployed", ) as AbiEvent; expect(normalizeAbiEvent(parseAbiItem(worldDeployedEvent))).toMatchObject(normalizeAbiEvent(forgeAbiItem)); }); diff --git a/scripts/changelog.ts b/scripts/changelog.ts index 9daee85ea1..42e4c61049 100644 --- a/scripts/changelog.ts +++ b/scripts/changelog.ts @@ -116,7 +116,7 @@ async function getChanges(include: "diff" | "all") { const changeset = readFileSync(changesetPath).toString(); const gitLog = (await execa("git", ["log", changesetPath])).stdout; return { ...parseChangeset(changeset), ...parseGitLog(gitLog) }; - }) + }), ); // Sort the changesets into patch, minor and major updates diff --git a/scripts/render-api-docs.ts b/scripts/render-api-docs.ts index 28f67e4f7d..f0925af297 100644 --- a/scripts/render-api-docs.ts +++ b/scripts/render-api-docs.ts @@ -271,12 +271,12 @@ const PUBLIC_APIS: PublicApis = { content = addSampleCodeFunction( content, "grantAccess", - "/world/namespaces-access-control#modifying-access-control" + "/world/namespaces-access-control#modifying-access-control", ); content = addSampleCodeFunction( content, "revokeAccess", - "/world/namespaces-access-control#modifying-access-control" + "/world/namespaces-access-control#modifying-access-control", ); content = addSampleCodeFunction(content, "registerTable", "/store/tables#manually-register-a-table"); content = addSampleCodeFunction(content, "call", "/world/systems#using-call"); @@ -285,7 +285,7 @@ const PUBLIC_APIS: PublicApis = { content = addSampleCodeFunction( content, "registerRootFunctionSelector", - "/world/function-selectors#root-function-selectors" + "/world/function-selectors#root-function-selectors", ); content = addSampleCodeFunction(content, "transferBalanceToAddress", "/world/balance"); @@ -294,7 +294,7 @@ const PUBLIC_APIS: PublicApis = { .replaceAll("This is an autogenerated file; do not edit manually", "") .replaceAll( "*This interface is automatically generated from the corresponding system contract. Do not edit manually.*", - "" + "", ) .replace(/## StoreData((.|\n)*?)### Functions/m, "### Functions") .replace(/#### constructor((.|\n)*?)#### storeVersion/m, "#### storeVersion") @@ -393,7 +393,7 @@ const PUBLIC_APIS: PublicApis = { content = addSampleCodeFunction( content, "registerRootFunctionSelector", - "/world/function-selectors#root-function-selectors" + "/world/function-selectors#root-function-selectors", ); content = addSampleCodeFunction(content, "transferBalanceToAddress", "/world/balance"); @@ -484,9 +484,9 @@ function addSampleCodeContract(content: string, contract: string, url: string): .replace( ")", `) | - | - | - |` + | - | - |`, ) - .replace("[Git Source](", `| [Usage Sample](${url}) | [Git Source](`) + .replace("[Git Source](", `| [Usage Sample](${url}) | [Git Source](`), ); } @@ -497,8 +497,8 @@ function addSampleCodeFunction(content: string, heading: string, url: string): s "\n", ` [Usage Sample](${url}) - ` - ) + `, + ), ); } @@ -525,7 +525,7 @@ function getPackages() { Object.values(PUBLIC_APIS) .map(({ inputFiles }) => inputFiles) .flat() - .map((input) => input.source.split("/")[0]) + .map((input) => input.source.split("/")[0]), ), ]; } @@ -575,7 +575,7 @@ async function renderDocs() { .map((fileName) => readFileSync(path.join(docsPath, fileName), { encoding: "utf8" })); }) .flat() - .join("\n") + .join("\n"), ); // Write the output file diff --git a/templates/phaser/packages/client/src/mud/createSystemCalls.ts b/templates/phaser/packages/client/src/mud/createSystemCalls.ts index f3c72c4e9f..fef3e78936 100644 --- a/templates/phaser/packages/client/src/mud/createSystemCalls.ts +++ b/templates/phaser/packages/client/src/mud/createSystemCalls.ts @@ -37,7 +37,7 @@ export function createSystemCalls( * (https://github.com/latticexyz/mud/blob/main/templates/phaser/packages/client/src/mud/setupNetwork.ts#L75-L81). */ { worldContract, waitForTransaction }: SetupNetworkResult, - { Counter }: ClientComponents + { Counter }: ClientComponents, ) { const increment = async () => { /* diff --git a/templates/phaser/packages/client/src/ui/App.tsx b/templates/phaser/packages/client/src/ui/App.tsx index a61f2ba87e..7dd4d29641 100644 --- a/templates/phaser/packages/client/src/ui/App.tsx +++ b/templates/phaser/packages/client/src/ui/App.tsx @@ -26,7 +26,7 @@ export const App = () => { worldAbi: networkLayer.network.worldContract.abi, write$: networkLayer.network.write$, recsWorld: networkLayer.world, - }) + }), ); } }, [networkLayer]); diff --git a/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx b/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx index ff47610f2c..2d428b0c24 100644 --- a/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx +++ b/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx @@ -80,7 +80,7 @@ export const usePhaserLayer = ({ networkLayer }: Props) => { } } }, - [container] + [container], ); return useMemo(() => ({ ref, phaserLayer }), [ref, phaserLayer]); diff --git a/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol b/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol index 27ea70acda..34615b56ae 100644 --- a/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol @@ -14,6 +14,4 @@ import { IIncrementSystem } from "./IIncrementSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IIncrementSystem { - -} +interface IWorld is IBaseWorld, IIncrementSystem {} diff --git a/templates/react-ecs/packages/client/src/index.tsx b/templates/react-ecs/packages/client/src/index.tsx index da8d70f020..1b005dc561 100644 --- a/templates/react-ecs/packages/client/src/index.tsx +++ b/templates/react-ecs/packages/client/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts b/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts index 09e7807c6f..30b4f7f6b7 100644 --- a/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +++ b/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts @@ -31,7 +31,7 @@ export function createSystemCalls( * (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83). */ { worldContract, waitForTransaction }: SetupNetworkResult, - { Counter }: ClientComponents + { Counter }: ClientComponents, ) { const increment = async () => { /* diff --git a/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol b/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol index 27ea70acda..34615b56ae 100644 --- a/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol @@ -14,6 +14,4 @@ import { IIncrementSystem } from "./IIncrementSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IIncrementSystem { - -} +interface IWorld is IBaseWorld, IIncrementSystem {} diff --git a/templates/react/packages/client/src/index.tsx b/templates/react/packages/client/src/index.tsx index 3ba2a44052..c9b662c9f0 100644 --- a/templates/react/packages/client/src/index.tsx +++ b/templates/react/packages/client/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/templates/react/packages/client/src/mud/createSystemCalls.ts b/templates/react/packages/client/src/mud/createSystemCalls.ts index 7f9cb42e04..d7714ec453 100644 --- a/templates/react/packages/client/src/mud/createSystemCalls.ts +++ b/templates/react/packages/client/src/mud/createSystemCalls.ts @@ -28,7 +28,7 @@ export function createSystemCalls( * syncToRecs * (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83). */ - { tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult + { tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult, ) { const addTask = async (label: string) => { const tx = await worldContract.write.addTask([label]); diff --git a/templates/react/packages/contracts/src/codegen/world/IWorld.sol b/templates/react/packages/contracts/src/codegen/world/IWorld.sol index 227796ea2e..b3848a4577 100644 --- a/templates/react/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/react/packages/contracts/src/codegen/world/IWorld.sol @@ -14,6 +14,4 @@ import { ITasksSystem } from "./ITasksSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, ITasksSystem { - -} +interface IWorld is IBaseWorld, ITasksSystem {} diff --git a/templates/threejs/packages/client/src/index.tsx b/templates/threejs/packages/client/src/index.tsx index da8d70f020..1b005dc561 100644 --- a/templates/threejs/packages/client/src/index.tsx +++ b/templates/threejs/packages/client/src/index.tsx @@ -13,7 +13,7 @@ setup().then(async (result) => { root.render( - + , ); // https://vitejs.dev/guide/env-and-mode.html diff --git a/templates/threejs/packages/client/src/mud/createSystemCalls.ts b/templates/threejs/packages/client/src/mud/createSystemCalls.ts index 145e2ef1e5..d537c578fb 100644 --- a/templates/threejs/packages/client/src/mud/createSystemCalls.ts +++ b/templates/threejs/packages/client/src/mud/createSystemCalls.ts @@ -30,7 +30,7 @@ export function createSystemCalls( * (https://github.com/latticexyz/mud/blob/main/templates/threejs/packages/client/src/mud/setupNetwork.ts#L75-L81). */ { worldContract, waitForTransaction, playerEntity }: SetupNetworkResult, - { Position }: ClientComponents + { Position }: ClientComponents, ) { const moveTo = async (x: number, y: number, z: number) => { /* diff --git a/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol b/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol index 576ff1607e..d27f33eb9a 100644 --- a/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol @@ -14,6 +14,4 @@ import { IMoveSystem } from "./IMoveSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IMoveSystem { - -} +interface IWorld is IBaseWorld, IMoveSystem {} diff --git a/templates/vanilla/packages/client/src/mud/createSystemCalls.ts b/templates/vanilla/packages/client/src/mud/createSystemCalls.ts index ebff84233d..f153b51e86 100644 --- a/templates/vanilla/packages/client/src/mud/createSystemCalls.ts +++ b/templates/vanilla/packages/client/src/mud/createSystemCalls.ts @@ -31,7 +31,7 @@ export function createSystemCalls( * (https://github.com/latticexyz/mud/blob/main/templates/vanilla/packages/client/src/mud/setupNetwork.ts#L77-L83). */ { worldContract, waitForTransaction }: SetupNetworkResult, - { Counter }: ClientComponents + { Counter }: ClientComponents, ) { const increment = async () => { /* diff --git a/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol b/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol index 27ea70acda..34615b56ae 100644 --- a/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol +++ b/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol @@ -14,6 +14,4 @@ import { IIncrementSystem } from "./IIncrementSystem.sol"; * that are dynamically registered in the World during deployment. * @dev This is an autogenerated file; do not edit manually. */ -interface IWorld is IBaseWorld, IIncrementSystem { - -} +interface IWorld is IBaseWorld, IIncrementSystem {} From 9d6b44304c0a7ec99cdffa1c2caad32769a30b4a Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Thu, 29 Feb 2024 11:58:10 +0000 Subject: [PATCH 8/8] chore: remove docs page --- docs/pages/store/reference/misc.mdx | 84 ----------------------------- 1 file changed, 84 deletions(-) diff --git a/docs/pages/store/reference/misc.mdx b/docs/pages/store/reference/misc.mdx index 721b093860..1d26769632 100644 --- a/docs/pages/store/reference/misc.mdx +++ b/docs/pages/store/reference/misc.mdx @@ -269,62 +269,6 @@ function slice32(bytes memory data, uint256 start) internal pure returns (bytes3 | -------- | --------- | -------------------------------------------------------------------------- | | `output` | `bytes32` | The extracted bytes32 value from the specified position in the bytes blob. | -## FieldLayout_Empty - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_Empty(); -``` - -## FieldLayout_InvalidStaticDataLength - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength); -``` - -## FieldLayout_StaticLengthDoesNotFitInAWord - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_StaticLengthDoesNotFitInAWord(uint256 index); -``` - -## FieldLayout_StaticLengthIsNotZero - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_StaticLengthIsNotZero(uint256 index); -``` - -## FieldLayout_StaticLengthIsZero - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_StaticLengthIsZero(uint256 index); -``` - -## FieldLayout_TooManyDynamicFields - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_TooManyDynamicFields(uint256 numFields, uint256 maxFields); -``` - -## FieldLayout_TooManyFields - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) - -```solidity -error FieldLayout_TooManyFields(uint256 numFields, uint256 maxFields); -``` - ## FieldLayoutInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol) @@ -855,26 +799,6 @@ type and a name_ type ResourceId is bytes32; ``` -## Schema_InvalidLength - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) - -_Error raised when the provided schema has an invalid length._ - -```solidity -error Schema_InvalidLength(uint256 length); -``` - -## Schema_StaticTypeAfterDynamicType - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) - -_Error raised when a static type is placed after a dynamic type in a schema._ - -```solidity -error Schema_StaticTypeAfterDynamicType(); -``` - ## SchemaInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol) @@ -1099,14 +1023,6 @@ _Defines and handles the encoding/decoding of Schemas which describe the layout type Schema is bytes32; ``` -## Slice_OutOfBounds - -[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol) - -```solidity -error Slice_OutOfBounds(bytes data, uint256 start, uint256 end); -``` - ## SliceInstance [Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol)