From 14a3dbb8f56b6bde09ce6c726fa17d9ecb554a73 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Fri, 25 Oct 2024 09:15:11 +0400 Subject: [PATCH 01/19] feat: add missing functions from `stdlib.fc` --- src/imports/stdlib.ts | 106 +++++++++++------- .../local-type-inference.spec.ts.snap | 33 ++++++ stdlib/std/cells.tact | 25 +++++ stdlib/std/contract.tact | 12 ++ stdlib/stdlib.fc | 23 +++- 5 files changed, 155 insertions(+), 44 deletions(-) diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index a79113eed..03f145a30 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -146,44 +146,51 @@ files['std/cells.tact'] = 'Ly8vIGBgYAovLy8KLy8vIEBzaW5jZSBUYWN0IDEuNS4wCi8vLyBAc2VlIGh0dHBzOi8vZG9jcy50YWN0LWxhbmcub3JnL3JlZi9jb3JlLWNlbGxzI2J1aWxkZXJzdG9y' + 'ZW1heWJlcmVmCi8vLwphc20oY2VsbCBzZWxmKSBleHRlbmRzIGZ1biBzdG9yZU1heWJlUmVmKHNlbGY6IEJ1aWxkZXIsIGNlbGw6IENlbGw/KTogQnVpbGRlciB7IFNU' + 'T1BUUkVGIH0KCmFzbSBleHRlbmRzIGZ1biBlbmRDZWxsKHNlbGY6IEJ1aWxkZXIpOiBDZWxsIHsgRU5EQyB9Cgphc20gZXh0ZW5kcyBmdW4gcmVmcyhzZWxmOiBCdWls' + - 'ZGVyKTogSW50IHsgQlJFRlMgfQoKYXNtIGV4dGVuZHMgZnVuIGJpdHMoc2VsZjogQnVpbGRlcik6IEludCB7IEJCSVRTIH0KCi8vCi8vIFNsaWNlCi8vCgphc20gZXh0' + - 'ZW5kcyBmdW4gYmVnaW5QYXJzZShzZWxmOiBDZWxsKTogU2xpY2UgeyBDVE9TIH0KCmFzbSgtPiAxIDApIGV4dGVuZHMgbXV0YXRlcyBmdW4gbG9hZFJlZihzZWxmOiBT' + - 'bGljZSk6IENlbGwgeyB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B7IENERVBUSCB9Cgo='; files['std/config.tact'] = 'YXNtIGZ1biBnZXRDb25maWdQYXJhbShpZDogSW50KTogQ2VsbD8geyBDT05GSUdPUFRQQVJBTSB9Cg=='; files['std/context.tact'] = @@ -246,7 +253,10 @@ files['std/contract.tact'] = 'Ly8gcGFyc2VkVmFyQWRkci53b3JrY2hhaW47ICAgICAgICAgICAgIC8vIDIzNAovLy8gcGFyc2VkVmFyQWRkci5hZGRyZXNzOyAgICAgICAgICAgICAgIC8vIENTe0Nl' + 'bGx7MDAyLi4uMmIzfSBiaXRzOiA0NC4uMTY3OyByZWZzOiAwLi4wfQovLy8gcGFyc2VkVmFyQWRkci5hZGRyZXNzLmxvYWRVaW50KDEyMyk7IC8vIDM0NQovLy8gYGBg' + 'Ci8vLwovLy8gQHNpbmNlIFRhY3QgMS41LjAKLy8vIEBzZWUgaHR0cHM6Ly9kb2NzLnRhY3QtbGFuZy5vcmcvcmVmL2NvcmUtYWR2YW5jZWQjcGFyc2V2YXJhZGRyZXNz' + - 'Ci8vLwphc20gZnVuIHBhcnNlVmFyQWRkcmVzcyhzbGljZTogU2xpY2UpOiBWYXJBZGRyZXNzIHsgUkVXUklURVZBUkFERFIgfQo='; + 'Ci8vLwphc20gZnVuIHBhcnNlVmFyQWRkcmVzcyhzbGljZTogU2xpY2UpOiBWYXJBZGRyZXNzIHsgUkVXUklURVZBUkFERFIgfQoKYXNtIGZ1biBjdXJMdCgpOiBJbnQg' + + 'eyBMVElNRSB9Cgphc20gZnVuIGJsb2NrTHQoKTogSW50IHsgQkxPQ0tMVCB9Cgphc20gZnVuIHNldEdhc0xpbWl0KGxpbWl0OiBJbnQpIHsgU0VUR0FTTElNSVQgfQoK' + + 'YXNtIGZ1biBnZXRTZWVkKCk6IEludCB7IFJBTkRTRUVEIH0KCmFzbSBmdW4gc2V0U2VlZChzZWVkOiBJbnQpIHsgU0VUUkFORCB9Cgphc20gZnVuIG15Q29kZSgpOiBD' + + 'ZWxsIHsgTVlDT0RF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sIGludCBjZWxscykgYXNtKGNlbGxzIGJpdHMgd29ya2NoYWluKSAiR0VURk9SV0FS' + + 'REZFRVNJTVBMRSI7CmludCBnZXRfb3JpZ2luYWxfZndkX2ZlZShpbnQgd29ya2NoYWluLCBpbnQgZndkX2ZlZSkgYXNtKGZ3ZF9mZWUgd29ya2NoYWluKSAiR0VUT1JJ' + + 'R0lOQUxGV0RGRUUiOwppbnQgbXlfc3RvcmFnZV9kdWUoKSBhc20gIkRVRVBBWU1FTlQiOwoKdHVwbGUgZ2V0X2ZlZV9jb2ZpZ3MoKSBhc20gIlVOUEFDS0VEQ09ORklH' + + 'VFVQTEUiOwo='; files['stdlib.tact'] = 'aW1wb3J0ICIuL3N0ZC9wcmltaXRpdmVzIjsKaW1wb3J0ICIuL3N0ZC9jZWxscyI7CmltcG9ydCAiLi9zdGQvY3J5cHRvIjsKaW1wb3J0ICIuL3N0ZC90ZXh0IjsKaW1w' + 'b3J0ICIuL3N0ZC9tYXRoIjsKaW1wb3J0ICIuL3N0ZC9jb250cmFjdCI7CmltcG9ydCAiLi9zdGQvZGVidWciOwppbXBvcnQgIi4vc3RkL2NvbnRleHQiOwppbXBvcnQg' + diff --git a/src/test/e2e-emulated/__snapshots__/local-type-inference.spec.ts.snap b/src/test/e2e-emulated/__snapshots__/local-type-inference.spec.ts.snap index 5573c4ad8..c03922a12 100644 --- a/src/test/e2e-emulated/__snapshots__/local-type-inference.spec.ts.snap +++ b/src/test/e2e-emulated/__snapshots__/local-type-inference.spec.ts.snap @@ -321,6 +321,39 @@ exports[`local-type-inference should automatically set types for let statements }, ], "types": [ + { + "fields": [ + { + "name": "cells", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + { + "name": "bits", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + { + "name": "refs", + "type": { + "format": 257, + "kind": "simple", + "optional": false, + "type": "int", + }, + }, + ], + "header": null, + "name": "DataSize", + }, { "fields": [ { diff --git a/stdlib/std/cells.tact b/stdlib/std/cells.tact index 2bb474d1a..176f75672 100644 --- a/stdlib/std/cells.tact +++ b/stdlib/std/cells.tact @@ -66,6 +66,8 @@ asm extends fun refs(self: Builder): Int { BREFS } asm extends fun bits(self: Builder): Int { BBITS } +asm fun builderDepth(builder: Builder): Int { BDEPTH } + // // Slice // @@ -148,6 +150,14 @@ asm extends mutates fun skipBits(self: Slice, l: Int) { SDSKIPFIRST } asm extends fun endParse(self: Slice) { ENDS } +asm extends fun skipLastBits(self: Slice, len: Int): Slice { SDSKIPLAST } + +asm extends fun firstBits(self: Slice, len: Int): Slice { SDCUTFIRST } + +asm extends fun sliceLast(self: Slice, len: Int): Slice { SDCUTLAST } + +asm fun sliceDepth(slice: Slice): Int { SDEPTH } + // // Slice size // @@ -191,3 +201,18 @@ inline fun emptyCell(): Cell { inline fun emptySlice(): Slice { return emptyCell().asSlice(); } + +asm fun stringHash(data: Slice): Int { SHA256U } + +struct DataSize { + cells: Int; + bits: Int; + refs: Int; +} + +asm fun computeDataSize(cell: Cell, maxCells: Int): DataSize { CDATASIZE TRIPLE } + +asm fun computeSliceDataSize(slice: Slice, maxCells: Int): DataSize { SDATASIZE TRIPLE } + +asm fun cellDepth(cell: Cell): Int { CDEPTH } + diff --git a/stdlib/std/contract.tact b/stdlib/std/contract.tact index 5a782dfa8..08884a81b 100644 --- a/stdlib/std/contract.tact +++ b/stdlib/std/contract.tact @@ -105,3 +105,15 @@ asm fun parseStdAddress(slice: Slice): StdAddress { REWRITESTDADDR } /// @see https://docs.tact-lang.org/ref/core-advanced#parsevaraddress /// asm fun parseVarAddress(slice: Slice): VarAddress { REWRITEVARADDR } + +asm fun curLt(): Int { LTIME } + +asm fun blockLt(): Int { BLOCKLT } + +asm fun setGasLimit(limit: Int) { SETGASLIMIT } + +asm fun getSeed(): Int { RANDSEED } + +asm fun setSeed(seed: Int) { SETRAND } + +asm fun myCode(): Cell { MYCODE } diff --git a/stdlib/stdlib.fc b/stdlib/stdlib.fc index 91d461649..0eda659de 100644 --- a/stdlib/stdlib.fc +++ b/stdlib/stdlib.fc @@ -323,7 +323,7 @@ cell preload_ref(slice s) asm "PLDREF"; ;;; Preloads the first `0 ≤ len ≤ 1023` bits from slice [s] into a separate `slice s''`. ;; slice preload_bits(slice s, int len) asm "PLDSLICEX"; -;;; Loads serialized amount of TonCoins (any unsigned integer up to `2^120 - 1`). +;;; Loads serialized amount of TonCoins (any unsigned integer up to `2^128 - 1`). (slice, int) load_grams(slice s) asm(-> 1 0) "LDGRAMS"; (slice, int) load_coins(slice s) asm(-> 1 0) "LDVARUINT16"; @@ -440,7 +440,7 @@ builder store_ref(builder b, cell c) asm(c b) "STREF"; ;;; Stores `slice` [s] into `builder` [b] builder store_slice(builder b, slice s) asm "STSLICER"; -;;; Stores (serializes) an integer [x] in the range `0..2^120 − 1` into `builder` [b]. +;;; Stores (serializes) an integer [x] in the range `0..2^128 − 1` into `builder` [b]. ;;; The serialization of [x] consists of a 4-bit unsigned big-endian integer `l`, ;;; which is the smallest integer `l ≥ 0`, such that `x < 2^8l`, ;;; followed by an `8l`-bit unsigned big-endian representation of [x]. @@ -668,3 +668,22 @@ builder store_builder(builder to, builder from) asm "STBR"; ;;; Retrieves code of smart-contract from c7 cell my_code() asm "MYCODE"; + +;;; Creates an output action and returns a fee for creating a message. Mode has the same effect as in the case of SENDRAWMSG +int send_message(cell msg, int mode) impure asm "SENDMSG"; + +int gas_consumed() asm "GASCONSUMED"; + +;; TVM V6 https://github.com/ton-blockchain/ton/blob/testnet/doc/GlobalVersions.md#version-6 + +int get_compute_fee(int workchain, int gas_used) asm(gas_used workchain) "GETGASFEE"; +int get_storage_fee(int workchain, int seconds, int bits, int cells) asm(cells bits seconds workchain) "GETSTORAGEFEE"; +int get_forward_fee(int workchain, int bits, int cells) asm(cells bits workchain) "GETFORWARDFEE"; +int get_precompiled_gas_consumption() asm "GETPRECOMPILEDGAS"; + +int get_simple_compute_fee(int workchain, int gas_used) asm(gas_used workchain) "GETGASFEESIMPLE"; +int get_simple_forward_fee(int workchain, int bits, int cells) asm(cells bits workchain) "GETFORWARDFEESIMPLE"; +int get_original_fwd_fee(int workchain, int fwd_fee) asm(fwd_fee workchain) "GETORIGINALFWDFEE"; +int my_storage_due() asm "DUEPAYMENT"; + +tuple get_fee_cofigs() asm "UNPACKEDCONFIGTUPLE"; From 9191f445b02b9d4a526329565872d20aff67b023 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Fri, 25 Oct 2024 09:30:27 +0400 Subject: [PATCH 02/19] feat: add `sgn` math function --- src/imports/stdlib.ts | 3 ++- stdlib/std/math.tact | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index 03f145a30..37989c978 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -286,7 +286,8 @@ files['std/math.tact'] = 'aW4pOwp9CgovLyBNYXRoCgphc20gZnVuIG1pbih4OiBJbnQsIHk6IEludCk6IEludCB7IE1JTiB9Cgphc20gZnVuIG1heCh4OiBJbnQsIHk6IEludCk6IEludCB7IE1B' + 'WCB9Cgphc20gZnVuIGFicyh4OiBJbnQpOiBJbnQgeyBBQlMgfQoKYXNtIGZ1biBub3coKTogSW50IHsgTk9XIH0KCmFzbSBmdW4gbG9nMihudW06IEludCk6IEludCB7' + 'CiAgICBEVVAgNSBUSFJPV0lGTk9UIFVCSVRTSVpFIERFQwp9CgpAbmFtZShfX3RhY3RfbG9nKQpuYXRpdmUgbG9nKG51bTogSW50LCBiYXNlOiBJbnQpOiBJbnQ7CgpA' + - 'bmFtZShfX3RhY3RfcG93KQpuYXRpdmUgcG93KGJhc2U6IEludCwgZXhwOiBJbnQpOiBJbnQ7Cgphc20gZnVuIHBvdzIoZXhwOiBJbnQpOiBJbnQgeyBQT1cyIH0='; + 'bmFtZShfX3RhY3RfcG93KQpuYXRpdmUgcG93KGJhc2U6IEludCwgZXhwOiBJbnQpOiBJbnQ7Cgphc20gZnVuIHBvdzIoZXhwOiBJbnQpOiBJbnQgeyBQT1cyIH0KCmFz' + + 'bSBmdW4gc2duKHg6IEludCk6IEludCB7IFNHTiB9Cg=='; files['std/primitives.tact'] = 'cHJpbWl0aXZlIEludDsKcHJpbWl0aXZlIEJvb2w7CnByaW1pdGl2ZSBCdWlsZGVyOwpwcmltaXRpdmUgU2xpY2U7CnByaW1pdGl2ZSBDZWxsOwpwcmltaXRpdmUgQWRk' + 'cmVzczsKcHJpbWl0aXZlIFN0cmluZzsKcHJpbWl0aXZlIFN0cmluZ0J1aWxkZXI7'; diff --git a/stdlib/std/math.tact b/stdlib/std/math.tact index 2186bd633..ed0fb36b5 100644 --- a/stdlib/std/math.tact +++ b/stdlib/std/math.tact @@ -59,4 +59,6 @@ native log(num: Int, base: Int): Int; @name(__tact_pow) native pow(base: Int, exp: Int): Int; -asm fun pow2(exp: Int): Int { POW2 } \ No newline at end of file +asm fun pow2(exp: Int): Int { POW2 } + +asm fun sgn(x: Int): Int { SGN } From 91bbb16f3b88e1fb2a5e4226f0e9337fb7603f05 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Fri, 25 Oct 2024 09:31:51 +0400 Subject: [PATCH 03/19] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 861dda719..237fb597c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `replace` and `replaceGet` methods for the `Map` type: PR [#941](https://github.com/tact-lang/tact/pull/941) - Utility for logging errors in code that was supposed to be unreachable: PR [#991](https://github.com/tact-lang/tact/pull/991) - Docs: `preloadRef` method for the `Slice` type: PR [#1044](https://github.com/tact-lang/tact/pull/1044) +- New functions in stdlib from `stdlib.fc` and `math.fc`: PR [#985](https://github.com/tact-lang/tact/pull/985) ### Changed From c33fbc746b5800099e7e5e1cd65d28d410e1208b Mon Sep 17 00:00:00 2001 From: Gusarich Date: Fri, 25 Oct 2024 09:44:57 +0400 Subject: [PATCH 04/19] chore: fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 237fb597c..acba5df01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `replace` and `replaceGet` methods for the `Map` type: PR [#941](https://github.com/tact-lang/tact/pull/941) - Utility for logging errors in code that was supposed to be unreachable: PR [#991](https://github.com/tact-lang/tact/pull/991) - Docs: `preloadRef` method for the `Slice` type: PR [#1044](https://github.com/tact-lang/tact/pull/1044) -- New functions in stdlib from `stdlib.fc` and `math.fc`: PR [#985](https://github.com/tact-lang/tact/pull/985) +- New functions in stdlib from `stdlib.fc` and `math.fc`: PR [#986](https://github.com/tact-lang/tact/pull/986) ### Changed From 63434735216d93b1c079811ff461a82ccbe5b1ea Mon Sep 17 00:00:00 2001 From: Daniil Sedov Date: Sun, 17 Nov 2024 10:31:18 +0300 Subject: [PATCH 05/19] feat: apply suggestions from code review Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- stdlib/std/cells.tact | 6 +++--- stdlib/std/math.tact | 2 +- stdlib/stdlib.fc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/std/cells.tact b/stdlib/std/cells.tact index 176f75672..d14651bc1 100644 --- a/stdlib/std/cells.tact +++ b/stdlib/std/cells.tact @@ -66,7 +66,7 @@ asm extends fun refs(self: Builder): Int { BREFS } asm extends fun bits(self: Builder): Int { BBITS } -asm fun builderDepth(builder: Builder): Int { BDEPTH } +asm extends fun depth(self: Builder): Int { BDEPTH } // // Slice @@ -156,7 +156,7 @@ asm extends fun firstBits(self: Slice, len: Int): Slice { SDCUTFIRST } asm extends fun sliceLast(self: Slice, len: Int): Slice { SDCUTLAST } -asm fun sliceDepth(slice: Slice): Int { SDEPTH } +asm extends fun depth(self: Slice): Int { SDEPTH } // // Slice size @@ -214,5 +214,5 @@ asm fun computeDataSize(cell: Cell, maxCells: Int): DataSize { CDATASIZE TRIPLE asm fun computeSliceDataSize(slice: Slice, maxCells: Int): DataSize { SDATASIZE TRIPLE } -asm fun cellDepth(cell: Cell): Int { CDEPTH } +asm extends fun depth(self: Cell): Int { CDEPTH } diff --git a/stdlib/std/math.tact b/stdlib/std/math.tact index ed0fb36b5..0141d78d1 100644 --- a/stdlib/std/math.tact +++ b/stdlib/std/math.tact @@ -61,4 +61,4 @@ native pow(base: Int, exp: Int): Int; asm fun pow2(exp: Int): Int { POW2 } -asm fun sgn(x: Int): Int { SGN } +asm fun sign(x: Int): Int { SGN } diff --git a/stdlib/stdlib.fc b/stdlib/stdlib.fc index 0eda659de..3135b95d8 100644 --- a/stdlib/stdlib.fc +++ b/stdlib/stdlib.fc @@ -686,4 +686,4 @@ int get_simple_forward_fee(int workchain, int bits, int cells) asm(cells bits wo int get_original_fwd_fee(int workchain, int fwd_fee) asm(fwd_fee workchain) "GETORIGINALFWDFEE"; int my_storage_due() asm "DUEPAYMENT"; -tuple get_fee_cofigs() asm "UNPACKEDCONFIGTUPLE"; +tuple get_fee_configs() asm "UNPACKEDCONFIGTUPLE"; From 21d0c61aba0caadfe9eca7bca4ebd057c52080cc Mon Sep 17 00:00:00 2001 From: Gusarich Date: Sun, 17 Nov 2024 10:36:20 +0300 Subject: [PATCH 06/19] chore: fix varuint comment in stdlib --- stdlib/stdlib.fc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/stdlib.fc b/stdlib/stdlib.fc index 3135b95d8..7761b68f6 100644 --- a/stdlib/stdlib.fc +++ b/stdlib/stdlib.fc @@ -323,7 +323,7 @@ cell preload_ref(slice s) asm "PLDREF"; ;;; Preloads the first `0 ≤ len ≤ 1023` bits from slice [s] into a separate `slice s''`. ;; slice preload_bits(slice s, int len) asm "PLDSLICEX"; -;;; Loads serialized amount of TonCoins (any unsigned integer up to `2^128 - 1`). +;;; Loads serialized amount of TonCoins (any unsigned integer up to `2^120 - 1`). (slice, int) load_grams(slice s) asm(-> 1 0) "LDGRAMS"; (slice, int) load_coins(slice s) asm(-> 1 0) "LDVARUINT16"; @@ -440,7 +440,7 @@ builder store_ref(builder b, cell c) asm(c b) "STREF"; ;;; Stores `slice` [s] into `builder` [b] builder store_slice(builder b, slice s) asm "STSLICER"; -;;; Stores (serializes) an integer [x] in the range `0..2^128 − 1` into `builder` [b]. +;;; Stores (serializes) an integer [x] in the range `0..2^120 − 1` into `builder` [b]. ;;; The serialization of [x] consists of a 4-bit unsigned big-endian integer `l`, ;;; which is the smallest integer `l ≥ 0`, such that `x < 2^8l`, ;;; followed by an `8l`-bit unsigned big-endian representation of [x]. From b9b6206b193934c178901a5a0ec7a9613aed1238 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Sun, 17 Nov 2024 10:38:10 +0300 Subject: [PATCH 07/19] feat: remove `stringHash` due to existence of `.hash` method --- stdlib/std/cells.tact | 2 -- 1 file changed, 2 deletions(-) diff --git a/stdlib/std/cells.tact b/stdlib/std/cells.tact index d14651bc1..dd0d5baf5 100644 --- a/stdlib/std/cells.tact +++ b/stdlib/std/cells.tact @@ -202,8 +202,6 @@ inline fun emptySlice(): Slice { return emptyCell().asSlice(); } -asm fun stringHash(data: Slice): Int { SHA256U } - struct DataSize { cells: Int; bits: Int; From 203905bfb2284e2d15085dad3e7689285ac29d21 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Sun, 17 Nov 2024 10:45:57 +0300 Subject: [PATCH 08/19] feat: update `stdlib.ts` --- src/imports/stdlib.ts | 84 +++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index 37989c978..2889b3cd1 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -146,39 +146,39 @@ files['std/cells.tact'] = 'Ly8vIGBgYAovLy8KLy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emUgeyBDREFUQVNJWkUgVFJJUExFIH0KCmFzbSBmdW4gY29tcHV0ZVNsaWNlRGF0YVNp' + + 'emUoc2xpY2U6IFNsaWNlLCBtYXhDZWxsczogSW50KTogRGF0YVNpemUgeyBTREFUQVNJWkUgVFJJUExFIH0KCmFzbSBleHRlbmRzIGZ1biBkZXB0aChzZWxmOiBDZWxs' + + 'KTogSW50IHsgQ0RFUFRIIH0KCg=='; files['std/config.tact'] = 'YXNtIGZ1biBnZXRDb25maWdQYXJhbShpZDogSW50KTogQ2VsbD8geyBDT05GSUdPUFRQQVJBTSB9Cg=='; files['std/context.tact'] = @@ -287,7 +287,7 @@ files['std/math.tact'] = 'WCB9Cgphc20gZnVuIGFicyh4OiBJbnQpOiBJbnQgeyBBQlMgfQoKYXNtIGZ1biBub3coKTogSW50IHsgTk9XIH0KCmFzbSBmdW4gbG9nMihudW06IEludCk6IEludCB7' + 'CiAgICBEVVAgNSBUSFJPV0lGTk9UIFVCSVRTSVpFIERFQwp9CgpAbmFtZShfX3RhY3RfbG9nKQpuYXRpdmUgbG9nKG51bTogSW50LCBiYXNlOiBJbnQpOiBJbnQ7CgpA' + 'bmFtZShfX3RhY3RfcG93KQpuYXRpdmUgcG93KGJhc2U6IEludCwgZXhwOiBJbnQpOiBJbnQ7Cgphc20gZnVuIHBvdzIoZXhwOiBJbnQpOiBJbnQgeyBQT1cyIH0KCmFz' + - 'bSBmdW4gc2duKHg6IEludCk6IEludCB7IFNHTiB9Cg=='; + 'bSBmdW4gc2lnbih4OiBJbnQpOiBJbnQgeyBTR04gfQo='; files['std/primitives.tact'] = 'cHJpbWl0aXZlIEludDsKcHJpbWl0aXZlIEJvb2w7CnByaW1pdGl2ZSBCdWlsZGVyOwpwcmltaXRpdmUgU2xpY2U7CnByaW1pdGl2ZSBDZWxsOwpwcmltaXRpdmUgQWRk' + 'cmVzczsKcHJpbWl0aXZlIFN0cmluZzsKcHJpbWl0aXZlIFN0cmluZ0J1aWxkZXI7'; @@ -509,7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987149e223c4f1555ee21ca37ae8cb9 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Sun, 17 Nov 2024 11:23:22 +0300 Subject: [PATCH 09/19] feat: add `MULRSHIFT` functions --- stdlib/std/math.tact | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/stdlib/std/math.tact b/stdlib/std/math.tact index 0141d78d1..edb05bff3 100644 --- a/stdlib/std/math.tact +++ b/stdlib/std/math.tact @@ -62,3 +62,12 @@ native pow(base: Int, exp: Int): Int; asm fun pow2(exp: Int): Int { POW2 } asm fun sign(x: Int): Int { SGN } + +// floor(x*y/2^z) +asm fun mulrshift(x: Int, y: Int, z: Int): Int { MULRSHIFT } + +// round(x*y/2^z) +asm fun mulrshift_round(x: Int, y: Int, z: Int): Int { MULRSHIFTR } + +// ceil(x*y/2^z) +asm fun mulrshift_ceil(x: Int, y: Int, z: Int): Int { MULRSHIFTC } From 1fcfc65dad861d77455bfb2dee037161e3a3a7a8 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Sun, 17 Nov 2024 11:27:40 +0300 Subject: [PATCH 10/19] feat: update `stdlib.ts` --- src/imports/stdlib.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index 2889b3cd1..2d888b9e1 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -287,7 +287,9 @@ files['std/math.tact'] = 'WCB9Cgphc20gZnVuIGFicyh4OiBJbnQpOiBJbnQgeyBBQlMgfQoKYXNtIGZ1biBub3coKTogSW50IHsgTk9XIH0KCmFzbSBmdW4gbG9nMihudW06IEludCk6IEludCB7' + 'CiAgICBEVVAgNSBUSFJPV0lGTk9UIFVCSVRTSVpFIERFQwp9CgpAbmFtZShfX3RhY3RfbG9nKQpuYXRpdmUgbG9nKG51bTogSW50LCBiYXNlOiBJbnQpOiBJbnQ7CgpA' + 'bmFtZShfX3RhY3RfcG93KQpuYXRpdmUgcG93KGJhc2U6IEludCwgZXhwOiBJbnQpOiBJbnQ7Cgphc20gZnVuIHBvdzIoZXhwOiBJbnQpOiBJbnQgeyBQT1cyIH0KCmFz' + - 'bSBmdW4gc2lnbih4OiBJbnQpOiBJbnQgeyBTR04gfQo='; + 'bSBmdW4gc2lnbih4OiBJbnQpOiBJbnQgeyBTR04gfQoKLy8gZmxvb3IoeCp5LzJeeikKYXNtIGZ1biBtdWxyc2hpZnQoeDogSW50LCB5OiBJbnQsIHo6IEludCk6IElu' + + 'dCB7IE1VTFJTSElGVCB9CgovLyByb3VuZCh4KnkvMl56KQphc20gZnVuIG11bHJzaGlmdF9yb3VuZCh4OiBJbnQsIHk6IEludCwgejogSW50KTogSW50IHsgTVVMUlNI' + + 'SUZUUiB9CgovLyBjZWlsKHgqeS8yXnopCmFzbSBmdW4gbXVscnNoaWZ0X2NlaWwoeDogSW50LCB5OiBJbnQsIHo6IEludCk6IEludCB7IE1VTFJTSElGVEMgfQo='; files['std/primitives.tact'] = 'cHJpbWl0aXZlIEludDsKcHJpbWl0aXZlIEJvb2w7CnByaW1pdGl2ZSBCdWlsZGVyOwpwcmltaXRpdmUgU2xpY2U7CnByaW1pdGl2ZSBDZWxsOwpwcmltaXRpdmUgQWRk' + 'cmVzczsKcHJpbWl0aXZlIFN0cmluZzsKcHJpbWl0aXZlIFN0cmluZ0J1aWxkZXI7'; From c88e882d38c154d1801fa826bc91547fc81abdea Mon Sep 17 00:00:00 2001 From: Gusarich Date: Mon, 18 Nov 2024 06:37:23 +0300 Subject: [PATCH 11/19] feat: add `sqrt` function --- .../writeSerialization.spec.ts.snap | 114 ++++++++++++++++++ src/generator/writers/writeStdlib.ts | 26 ++++ src/imports/stdlib.ts | 3 +- stdlib/std/math.tact | 3 + 4 files changed, 145 insertions(+), 1 deletion(-) diff --git a/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap b/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap index 30db3674f..738551146 100644 --- a/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap +++ b/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap @@ -1741,6 +1741,44 @@ return result;", "name": "__tact_pow", "signature": "int __tact_pow(int base, int exp)", }, + { + "code": { + "code": "UBITSIZE", + "kind": "asm", + "shuffle": "", + }, + "comment": null, + "context": "stdlib", + "depends": Set {}, + "flags": Set {}, + "name": "__tact_log2_floor_unsafe", + "signature": "int __tact_log2_floor_unsafe(int num)", + }, + { + "code": { + "code": "if (num == 0) { return 0; } +int s = __tact_log2_floor_unsafe(num); +int x = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); + +do { + int q = (muldivc(num, 1, x) - x) / 2; + x += q; +} until (q == 0); + +return x;", + "kind": "generic", + }, + "comment": null, + "context": "stdlib", + "depends": Set { + "__tact_log2_floor_unsafe", + }, + "flags": Set { + "inline", + }, + "name": "__tact_sqrt", + "signature": "int __tact_sqrt(int num)", + }, { "code": { "code": "var (r, ok) = __tact_dict_get(d, kl, k); @@ -6167,6 +6205,44 @@ return result;", "name": "__tact_pow", "signature": "int __tact_pow(int base, int exp)", }, + { + "code": { + "code": "UBITSIZE", + "kind": "asm", + "shuffle": "", + }, + "comment": null, + "context": "stdlib", + "depends": Set {}, + "flags": Set {}, + "name": "__tact_log2_floor_unsafe", + "signature": "int __tact_log2_floor_unsafe(int num)", + }, + { + "code": { + "code": "if (num == 0) { return 0; } +int s = __tact_log2_floor_unsafe(num); +int x = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); + +do { + int q = (muldivc(num, 1, x) - x) / 2; + x += q; +} until (q == 0); + +return x;", + "kind": "generic", + }, + "comment": null, + "context": "stdlib", + "depends": Set { + "__tact_log2_floor_unsafe", + }, + "flags": Set { + "inline", + }, + "name": "__tact_sqrt", + "signature": "int __tact_sqrt(int num)", + }, { "code": { "code": "var (r, ok) = __tact_dict_get(d, kl, k); @@ -10593,6 +10669,44 @@ return result;", "name": "__tact_pow", "signature": "int __tact_pow(int base, int exp)", }, + { + "code": { + "code": "UBITSIZE", + "kind": "asm", + "shuffle": "", + }, + "comment": null, + "context": "stdlib", + "depends": Set {}, + "flags": Set {}, + "name": "__tact_log2_floor_unsafe", + "signature": "int __tact_log2_floor_unsafe(int num)", + }, + { + "code": { + "code": "if (num == 0) { return 0; } +int s = __tact_log2_floor_unsafe(num); +int x = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); + +do { + int q = (muldivc(num, 1, x) - x) / 2; + x += q; +} until (q == 0); + +return x;", + "kind": "generic", + }, + "comment": null, + "context": "stdlib", + "depends": Set { + "__tact_log2_floor_unsafe", + }, + "flags": Set { + "inline", + }, + "name": "__tact_sqrt", + "signature": "int __tact_sqrt(int num)", + }, { "code": { "code": "var (r, ok) = __tact_dict_get(d, kl, k); diff --git a/src/generator/writers/writeStdlib.ts b/src/generator/writers/writeStdlib.ts index 4bd365603..8017451cd 100644 --- a/src/generator/writers/writeStdlib.ts +++ b/src/generator/writers/writeStdlib.ts @@ -1133,6 +1133,32 @@ export function writeStdlib(ctx: WriterContext): void { }); }); + ctx.fun(`__tact_log2_floor_unsafe`, () => { + ctx.signature(`int __tact_log2_floor_unsafe(int num)`); + ctx.context("stdlib"); + ctx.asm("", "UBITSIZE"); + }); + + ctx.fun(`__tact_sqrt`, () => { + ctx.signature(`int __tact_sqrt(int num)`); + ctx.flag("inline"); + ctx.context("stdlib"); + ctx.body(() => { + ctx.write(` + if (num == 0) { return 0; } + int s = ${ctx.used("__tact_log2_floor_unsafe")}(num); + int x = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); + + do { + int q = (muldivc(num, 1, x) - x) / 2; + x += q; + } until (q == 0); + + return x; + `); + }); + }); + // generate dict operations for all combinations of key/value types for (const key of keyTypes) { for (const val of valTypes) { diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index 2d888b9e1..6266faca3 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -289,7 +289,8 @@ files['std/math.tact'] = 'bmFtZShfX3RhY3RfcG93KQpuYXRpdmUgcG93KGJhc2U6IEludCwgZXhwOiBJbnQpOiBJbnQ7Cgphc20gZnVuIHBvdzIoZXhwOiBJbnQpOiBJbnQgeyBQT1cyIH0KCmFz' + 'bSBmdW4gc2lnbih4OiBJbnQpOiBJbnQgeyBTR04gfQoKLy8gZmxvb3IoeCp5LzJeeikKYXNtIGZ1biBtdWxyc2hpZnQoeDogSW50LCB5OiBJbnQsIHo6IEludCk6IElu' + 'dCB7IE1VTFJTSElGVCB9CgovLyByb3VuZCh4KnkvMl56KQphc20gZnVuIG11bHJzaGlmdF9yb3VuZCh4OiBJbnQsIHk6IEludCwgejogSW50KTogSW50IHsgTVVMUlNI' + - 'SUZUUiB9CgovLyBjZWlsKHgqeS8yXnopCmFzbSBmdW4gbXVscnNoaWZ0X2NlaWwoeDogSW50LCB5OiBJbnQsIHo6IEludCk6IEludCB7IE1VTFJTSElGVEMgfQo='; + 'SUZUUiB9CgovLyBjZWlsKHgqeS8yXnopCmFzbSBmdW4gbXVscnNoaWZ0X2NlaWwoeDogSW50LCB5OiBJbnQsIHo6IEludCk6IEludCB7IE1VTFJTSElGVEMgfQoKQG5h' + + 'bWUoX190YWN0X3NxcnQpCm5hdGl2ZSBzcXJ0KG51bTogSW50KTogSW50Owo='; files['std/primitives.tact'] = 'cHJpbWl0aXZlIEludDsKcHJpbWl0aXZlIEJvb2w7CnByaW1pdGl2ZSBCdWlsZGVyOwpwcmltaXRpdmUgU2xpY2U7CnByaW1pdGl2ZSBDZWxsOwpwcmltaXRpdmUgQWRk' + 'cmVzczsKcHJpbWl0aXZlIFN0cmluZzsKcHJpbWl0aXZlIFN0cmluZ0J1aWxkZXI7'; diff --git a/stdlib/std/math.tact b/stdlib/std/math.tact index edb05bff3..987698b8d 100644 --- a/stdlib/std/math.tact +++ b/stdlib/std/math.tact @@ -71,3 +71,6 @@ asm fun mulrshift_round(x: Int, y: Int, z: Int): Int { MULRSHIFTR } // ceil(x*y/2^z) asm fun mulrshift_ceil(x: Int, y: Int, z: Int): Int { MULRSHIFTC } + +@name(__tact_sqrt) +native sqrt(num: Int): Int; From 3d0e90eac8b77aa1c95e6648290d486942b3b75c Mon Sep 17 00:00:00 2001 From: Gusarich Date: Mon, 18 Nov 2024 11:30:59 +0300 Subject: [PATCH 12/19] feat: `sliceLast` -> `lastBits`, and make `computeDataSize` an extend function for both cell and slice --- src/imports/stdlib.ts | 28 ++++++++++++++-------------- stdlib/std/cells.tact | 6 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index 6266faca3..74dbc7196 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -177,20 +177,20 @@ files['std/cells.tact'] = 'IG11dGF0ZXMgbmF0aXZlIGxvYWRBZGRyZXNzKHNlbGY6IFNsaWNlKTogQWRkcmVzczsKCmFzbSBleHRlbmRzIG11dGF0ZXMgZnVuIHNraXBCaXRzKHNlbGY6IFNsaWNl' + 'LCBsOiBJbnQpIHsgU0RTS0lQRklSU1QgfQoKYXNtIGV4dGVuZHMgZnVuIGVuZFBhcnNlKHNlbGY6IFNsaWNlKSB7IEVORFMgfQoKYXNtIGV4dGVuZHMgZnVuIHNraXBM' + 'YXN0Qml0cyhzZWxmOiBTbGljZSwgbGVuOiBJbnQpOiBTbGljZSB7IFNEU0tJUExBU1QgfQoKYXNtIGV4dGVuZHMgZnVuIGZpcnN0Qml0cyhzZWxmOiBTbGljZSwgbGVu' + - 'OiBJbnQpOiBTbGljZSB7IFNEQ1VURklSU1QgfQoKYXNtIGV4dGVuZHMgZnVuIHNsaWNlTGFzdChzZWxmOiBTbGljZSwgbGVuOiBJbnQpOiBTbGljZSB7IFNEQ1VUTEFT' + - 'VCB9Cgphc20gZXh0ZW5kcyBmdW4gZGVwdGgoc2VsZjogU2xpY2UpOiBJbnQgeyBTREVQVEggfQoKLy8KLy8gU2xpY2Ugc2l6ZQovLwoKYXN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Z1biBkZXB0aChz' + + 'ZWxmOiBDZWxsKTogSW50IHsgQ0RFUFRIIH0KCg=='; files['std/config.tact'] = 'YXNtIGZ1biBnZXRDb25maWdQYXJhbShpZDogSW50KTogQ2VsbD8geyBDT05GSUdPUFRQQVJBTSB9Cg=='; files['std/context.tact'] = diff --git a/stdlib/std/cells.tact b/stdlib/std/cells.tact index dd0d5baf5..1b1f023a3 100644 --- a/stdlib/std/cells.tact +++ b/stdlib/std/cells.tact @@ -154,7 +154,7 @@ asm extends fun skipLastBits(self: Slice, len: Int): Slice { SDSKIPLAST } asm extends fun firstBits(self: Slice, len: Int): Slice { SDCUTFIRST } -asm extends fun sliceLast(self: Slice, len: Int): Slice { SDCUTLAST } +asm extends fun lastBits(self: Slice, len: Int): Slice { SDCUTLAST } asm extends fun depth(self: Slice): Int { SDEPTH } @@ -208,9 +208,9 @@ struct DataSize { refs: Int; } -asm fun computeDataSize(cell: Cell, maxCells: Int): DataSize { CDATASIZE TRIPLE } +asm extends fun computeDataSize(self: Cell, maxCells: Int): DataSize { CDATASIZE TRIPLE } -asm fun computeSliceDataSize(slice: Slice, maxCells: Int): DataSize { SDATASIZE TRIPLE } +asm extends fun computeDataSize(self: Slice, maxCells: Int): DataSize { SDATASIZE TRIPLE } asm extends fun depth(self: Cell): Int { CDEPTH } From a6cbf69d5b00c5336f4a621a537e611759af28ca Mon Sep 17 00:00:00 2001 From: Gusarich Date: Mon, 18 Nov 2024 11:31:07 +0300 Subject: [PATCH 13/19] chore: add all function names to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acba5df01..7bf2af3be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `replace` and `replaceGet` methods for the `Map` type: PR [#941](https://github.com/tact-lang/tact/pull/941) - Utility for logging errors in code that was supposed to be unreachable: PR [#991](https://github.com/tact-lang/tact/pull/991) - Docs: `preloadRef` method for the `Slice` type: PR [#1044](https://github.com/tact-lang/tact/pull/1044) -- New functions in stdlib from `stdlib.fc` and `math.fc`: PR [#986](https://github.com/tact-lang/tact/pull/986) +- New functions in stdlib from `stdlib.fc` and `math.fc`: `Builder.depth`, `Slice.skipLastBits`, `Slice.firstBits`, `Slice.lastBits`, `Slice.depth`, `Cell.computeDataSize`, `Slice.computeDataSize`, `Cell.depth`, `curLt`, `blockLt`, `setGasLimit`, `getSeed`, `setSeed`, `myCode`, `sign`, `mulrshift`, `mulrshift_round`, `mulrshift_ceil`, `sqrt`: PR [#986](https://github.com/tact-lang/tact/pull/986) ### Changed From 1d98c52172ee512a99be70606d91be4624bb4593 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Mon, 18 Nov 2024 11:43:03 +0300 Subject: [PATCH 14/19] feat: `addressNone` --- CHANGELOG.md | 2 +- src/imports/stdlib.ts | 8 ++++---- stdlib/std/cells.tact | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bf2af3be..9dd6d46c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `replace` and `replaceGet` methods for the `Map` type: PR [#941](https://github.com/tact-lang/tact/pull/941) - Utility for logging errors in code that was supposed to be unreachable: PR [#991](https://github.com/tact-lang/tact/pull/991) - Docs: `preloadRef` method for the `Slice` type: PR [#1044](https://github.com/tact-lang/tact/pull/1044) -- New functions in stdlib from `stdlib.fc` and `math.fc`: `Builder.depth`, `Slice.skipLastBits`, `Slice.firstBits`, `Slice.lastBits`, `Slice.depth`, `Cell.computeDataSize`, `Slice.computeDataSize`, `Cell.depth`, `curLt`, `blockLt`, `setGasLimit`, `getSeed`, `setSeed`, `myCode`, `sign`, `mulrshift`, `mulrshift_round`, `mulrshift_ceil`, `sqrt`: PR [#986](https://github.com/tact-lang/tact/pull/986) +- New functions in stdlib from `stdlib.fc` and `math.fc`: `Builder.depth`, `Slice.skipLastBits`, `Slice.firstBits`, `Slice.lastBits`, `Slice.depth`, `Cell.computeDataSize`, `Slice.computeDataSize`, `Cell.depth`, `curLt`, `blockLt`, `setGasLimit`, `getSeed`, `setSeed`, `myCode`, `sign`, `mulrshift`, `mulrshift_round`, `mulrshift_ceil`, `sqrt`, `addressNone`: PR [#986](https://github.com/tact-lang/tact/pull/986) ### Changed diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index 74dbc7196..180164681 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -187,10 +187,10 @@ files['std/cells.tact'] = 'bGljZSk6IENlbGwgewogICAgcmV0dXJuIGJlZ2luQ2VsbCgpCiAgICAgICAgLnN0b3JlU2xpY2Uoc2VsZikKICAgICAgICAuZW5kQ2VsbCgpOwp9CgppbmxpbmUgZXh0' + 'ZW5kcyBmdW4gYXNDZWxsKHNlbGY6IEJ1aWxkZXIpOiBDZWxsIHsKICAgIHJldHVybiBzZWxmLmVuZENlbGwoKTsKfQoKaW5saW5lIGZ1biBlbXB0eUNlbGwoKTogQ2Vs' + 'bCB7CiAgICByZXR1cm4gYmVnaW5DZWxsKCkuZW5kQ2VsbCgpOwp9CgppbmxpbmUgZnVuIGVtcHR5U2xpY2UoKTogU2xpY2UgewogICAgcmV0dXJuIGVtcHR5Q2VsbCgp' + - 'LmFzU2xpY2UoKTsKfQoKc3RydWN0IERhdGFTaXplIHsKICAgIGNlbGxzOiBJbnQ7CiAgICBiaXRzOiBJbnQ7CiAgICByZWZzOiBJbnQ7Cn0KCmFzbSBleHRlbmRzIGZ1' + - 'biBjb21wdXRlRGF0YVNpemUoc2VsZjogQ2VsbCwgbWF4Q2VsbHM6IEludCk6IERhdGFTaXplIHsgQ0RBVEFTSVpFIFRSSVBMRSB9Cgphc20gZXh0ZW5kcyBmdW4gY29t' + - 'cHV0ZURhdGFTaXplKHNlbGY6IFNsaWNlLCBtYXhDZWxsczogSW50KTogRGF0YVNpemUgeyBTREFUQVNJWkUgVFJJUExFIH0KCmFzbSBleHRlbmRzIGZ1biBkZXB0aChz' + - 'ZWxmOiBDZWxsKTogSW50IHsgQ0RFUFRIIH0KCg=='; + 'LmFzU2xpY2UoKTsKfQoKYXNtIGZ1biBhZGRyZXNzTm9uZSgpOiBBZGRyZXNzIHsgYnswMH0gUFVTSFNMSUNFIH0KCnN0cnVjdCBEYXRhU2l6ZSB7CiAgICBjZWxsczog' + + 'SW50OwogICAgYml0czogSW50OwogICAgcmVmczogSW50Owp9Cgphc20gZXh0ZW5kcyBmdW4gY29tcHV0ZURhdGFTaXplKHNlbGY6IENlbGwsIG1heENlbGxzOiBJbnQp' + + 'OiBEYXRhU2l6ZSB7IENEQVRBU0laRSBUUklQTEUgfQoKYXNtIGV4dGVuZHMgZnVuIGNvbXB1dGVEYXRhU2l6ZShzZWxmOiBTbGljZSwgbWF4Q2VsbHM6IEludCk6IERh' + + 'dGFTaXplIHsgU0RBVEFTSVpFIFRSSVBMRSB9Cgphc20gZXh0ZW5kcyBmdW4gZGVwdGgoc2VsZjogQ2VsbCk6IEludCB7IENERVBUSCB9Cgo='; files['std/config.tact'] = 'YXNtIGZ1biBnZXRDb25maWdQYXJhbShpZDogSW50KTogQ2VsbD8geyBDT05GSUdPUFRQQVJBTSB9Cg=='; files['std/context.tact'] = diff --git a/stdlib/std/cells.tact b/stdlib/std/cells.tact index 1b1f023a3..ff3e322d3 100644 --- a/stdlib/std/cells.tact +++ b/stdlib/std/cells.tact @@ -202,6 +202,8 @@ inline fun emptySlice(): Slice { return emptyCell().asSlice(); } +asm fun addressNone(): Address { b{00} PUSHSLICE } + struct DataSize { cells: Int; bits: Int; From 1154af78218d32831546ea6da89fd3b38bf491f1 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Thu, 21 Nov 2024 20:14:20 +0300 Subject: [PATCH 15/19] feat: rename mulrshift functions --- stdlib/std/math.tact | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/std/math.tact b/stdlib/std/math.tact index 987698b8d..1a2aecb2a 100644 --- a/stdlib/std/math.tact +++ b/stdlib/std/math.tact @@ -64,13 +64,13 @@ asm fun pow2(exp: Int): Int { POW2 } asm fun sign(x: Int): Int { SGN } // floor(x*y/2^z) -asm fun mulrshift(x: Int, y: Int, z: Int): Int { MULRSHIFT } +asm fun mulShiftRight(x: Int, y: Int, z: Int): Int { MULRSHIFT } // round(x*y/2^z) -asm fun mulrshift_round(x: Int, y: Int, z: Int): Int { MULRSHIFTR } +asm fun mulShiftRightRound(x: Int, y: Int, z: Int): Int { MULRSHIFTR } // ceil(x*y/2^z) -asm fun mulrshift_ceil(x: Int, y: Int, z: Int): Int { MULRSHIFTC } +asm fun mulShiftRightCeil(x: Int, y: Int, z: Int): Int { MULRSHIFTC } @name(__tact_sqrt) native sqrt(num: Int): Int; From 99b488e5018035696da9280dd67e164fd2ae44ca Mon Sep 17 00:00:00 2001 From: Gusarich Date: Thu, 21 Nov 2024 20:22:53 +0300 Subject: [PATCH 16/19] feat: rewrite sqrt on tact --- src/generator/writers/writeStdlib.ts | 26 -------------------------- src/imports/stdlib.ts | 12 ++++++++---- stdlib/std/math.tact | 23 +++++++++++++++++++++-- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/generator/writers/writeStdlib.ts b/src/generator/writers/writeStdlib.ts index 8017451cd..4bd365603 100644 --- a/src/generator/writers/writeStdlib.ts +++ b/src/generator/writers/writeStdlib.ts @@ -1133,32 +1133,6 @@ export function writeStdlib(ctx: WriterContext): void { }); }); - ctx.fun(`__tact_log2_floor_unsafe`, () => { - ctx.signature(`int __tact_log2_floor_unsafe(int num)`); - ctx.context("stdlib"); - ctx.asm("", "UBITSIZE"); - }); - - ctx.fun(`__tact_sqrt`, () => { - ctx.signature(`int __tact_sqrt(int num)`); - ctx.flag("inline"); - ctx.context("stdlib"); - ctx.body(() => { - ctx.write(` - if (num == 0) { return 0; } - int s = ${ctx.used("__tact_log2_floor_unsafe")}(num); - int x = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); - - do { - int q = (muldivc(num, 1, x) - x) / 2; - x += q; - } until (q == 0); - - return x; - `); - }); - }); - // generate dict operations for all combinations of key/value types for (const key of keyTypes) { for (const val of valTypes) { diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index 180164681..9a6b91fb4 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -287,10 +287,14 @@ files['std/math.tact'] = 'WCB9Cgphc20gZnVuIGFicyh4OiBJbnQpOiBJbnQgeyBBQlMgfQoKYXNtIGZ1biBub3coKTogSW50IHsgTk9XIH0KCmFzbSBmdW4gbG9nMihudW06IEludCk6IEludCB7' + 'CiAgICBEVVAgNSBUSFJPV0lGTk9UIFVCSVRTSVpFIERFQwp9CgpAbmFtZShfX3RhY3RfbG9nKQpuYXRpdmUgbG9nKG51bTogSW50LCBiYXNlOiBJbnQpOiBJbnQ7CgpA' + 'bmFtZShfX3RhY3RfcG93KQpuYXRpdmUgcG93KGJhc2U6IEludCwgZXhwOiBJbnQpOiBJbnQ7Cgphc20gZnVuIHBvdzIoZXhwOiBJbnQpOiBJbnQgeyBQT1cyIH0KCmFz' + - 'bSBmdW4gc2lnbih4OiBJbnQpOiBJbnQgeyBTR04gfQoKLy8gZmxvb3IoeCp5LzJeeikKYXNtIGZ1biBtdWxyc2hpZnQoeDogSW50LCB5OiBJbnQsIHo6IEludCk6IElu' + - 'dCB7IE1VTFJTSElGVCB9CgovLyByb3VuZCh4KnkvMl56KQphc20gZnVuIG11bHJzaGlmdF9yb3VuZCh4OiBJbnQsIHk6IEludCwgejogSW50KTogSW50IHsgTVVMUlNI' + - 'SUZUUiB9CgovLyBjZWlsKHgqeS8yXnopCmFzbSBmdW4gbXVscnNoaWZ0X2NlaWwoeDogSW50LCB5OiBJbnQsIHo6IEludCk6IEludCB7IE1VTFJTSElGVEMgfQoKQG5h' + - 'bWUoX190YWN0X3NxcnQpCm5hdGl2ZSBzcXJ0KG51bTogSW50KTogSW50Owo='; + 'bSBmdW4gc2lnbih4OiBJbnQpOiBJbnQgeyBTR04gfQoKYXNtIGZ1biBkaXZjKHg6IEludCwgeTogSW50KTogSW50IHsgRElWQyB9Cgphc20gZnVuIG11bGRpdmMoeDog' + + 'SW50LCB5OiBJbnQsIHo6IEludCk6IEludCB7IE1VTERJVkMgfQoKLy8gZmxvb3IoeCp5LzJeeikKYXNtIGZ1biBtdWxTaGlmdFJpZ2h0KHg6IEludCwgeTogSW50LCB6' + + 'OiBJbnQpOiBJbnQgeyBNVUxSU0hJRlQgfQoKLy8gcm91bmQoeCp5LzJeeikKYXNtIGZ1biBtdWxTaGlmdFJpZ2h0Um91bmQoeDogSW50LCB5OiBJbnQsIHo6IEludCk6' + + 'IEludCB7IE1VTFJTSElGVFIgfQoKLy8gY2VpbCh4KnkvMl56KQphc20gZnVuIG11bFNoaWZ0UmlnaHRDZWlsKHg6IEludCwgeTogSW50LCB6OiBJbnQpOiBJbnQgeyBN' + + 'VUxSU0hJRlRDIH0KCmZ1biBzcXJ0KG51bTogSW50KTogSW50IHsKICAgIGlmIChudW0gPT0gMCkgewogICAgICAgIHJldHVybiAwOwogICAgfQoKICAgIGxldCBzOiBJ' + + 'bnQgPSBsb2cyKG51bSk7CiAgICBsZXQgeDogSW50ID0gKHMgPT0gMSA/IChudW0gLSAxKSAvIDIgKyAxIDogMSA8PCAoKHMgKyAxKSAvIDIpKTsKCiAgICBsZXQgcTog' + + 'SW50ID0gMDsKCiAgICBkbyB7CiAgICAgICAgcSA9IChkaXZjKG51bSwgeCkgLSB4KSAvIDI7CiAgICAgICAgeCArPSBxOwogICAgfSB1bnRpbCAocSA9PSAwKTsKCiAg' + + 'ICByZXR1cm4geDsKfQo='; files['std/primitives.tact'] = 'cHJpbWl0aXZlIEludDsKcHJpbWl0aXZlIEJvb2w7CnByaW1pdGl2ZSBCdWlsZGVyOwpwcmltaXRpdmUgU2xpY2U7CnByaW1pdGl2ZSBDZWxsOwpwcmltaXRpdmUgQWRk' + 'cmVzczsKcHJpbWl0aXZlIFN0cmluZzsKcHJpbWl0aXZlIFN0cmluZ0J1aWxkZXI7'; diff --git a/stdlib/std/math.tact b/stdlib/std/math.tact index 1a2aecb2a..d48b18c07 100644 --- a/stdlib/std/math.tact +++ b/stdlib/std/math.tact @@ -63,6 +63,10 @@ asm fun pow2(exp: Int): Int { POW2 } asm fun sign(x: Int): Int { SGN } +asm fun divc(x: Int, y: Int): Int { DIVC } + +asm fun muldivc(x: Int, y: Int, z: Int): Int { MULDIVC } + // floor(x*y/2^z) asm fun mulShiftRight(x: Int, y: Int, z: Int): Int { MULRSHIFT } @@ -72,5 +76,20 @@ asm fun mulShiftRightRound(x: Int, y: Int, z: Int): Int { MULRSHIFTR } // ceil(x*y/2^z) asm fun mulShiftRightCeil(x: Int, y: Int, z: Int): Int { MULRSHIFTC } -@name(__tact_sqrt) -native sqrt(num: Int): Int; +fun sqrt(num: Int): Int { + if (num == 0) { + return 0; + } + + let s: Int = log2(num); + let x: Int = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); + + let q: Int = 0; + + do { + q = (divc(num, x) - x) / 2; + x += q; + } until (q == 0); + + return x; +} From be80d9eb7ef0c210a205ef0b56567417d66b42b8 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Thu, 21 Nov 2024 20:26:00 +0300 Subject: [PATCH 17/19] chore: update serialization snapshots --- .../writeSerialization.spec.ts.snap | 114 ------------------ 1 file changed, 114 deletions(-) diff --git a/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap b/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap index 738551146..30db3674f 100644 --- a/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap +++ b/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap @@ -1741,44 +1741,6 @@ return result;", "name": "__tact_pow", "signature": "int __tact_pow(int base, int exp)", }, - { - "code": { - "code": "UBITSIZE", - "kind": "asm", - "shuffle": "", - }, - "comment": null, - "context": "stdlib", - "depends": Set {}, - "flags": Set {}, - "name": "__tact_log2_floor_unsafe", - "signature": "int __tact_log2_floor_unsafe(int num)", - }, - { - "code": { - "code": "if (num == 0) { return 0; } -int s = __tact_log2_floor_unsafe(num); -int x = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); - -do { - int q = (muldivc(num, 1, x) - x) / 2; - x += q; -} until (q == 0); - -return x;", - "kind": "generic", - }, - "comment": null, - "context": "stdlib", - "depends": Set { - "__tact_log2_floor_unsafe", - }, - "flags": Set { - "inline", - }, - "name": "__tact_sqrt", - "signature": "int __tact_sqrt(int num)", - }, { "code": { "code": "var (r, ok) = __tact_dict_get(d, kl, k); @@ -6205,44 +6167,6 @@ return result;", "name": "__tact_pow", "signature": "int __tact_pow(int base, int exp)", }, - { - "code": { - "code": "UBITSIZE", - "kind": "asm", - "shuffle": "", - }, - "comment": null, - "context": "stdlib", - "depends": Set {}, - "flags": Set {}, - "name": "__tact_log2_floor_unsafe", - "signature": "int __tact_log2_floor_unsafe(int num)", - }, - { - "code": { - "code": "if (num == 0) { return 0; } -int s = __tact_log2_floor_unsafe(num); -int x = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); - -do { - int q = (muldivc(num, 1, x) - x) / 2; - x += q; -} until (q == 0); - -return x;", - "kind": "generic", - }, - "comment": null, - "context": "stdlib", - "depends": Set { - "__tact_log2_floor_unsafe", - }, - "flags": Set { - "inline", - }, - "name": "__tact_sqrt", - "signature": "int __tact_sqrt(int num)", - }, { "code": { "code": "var (r, ok) = __tact_dict_get(d, kl, k); @@ -10669,44 +10593,6 @@ return result;", "name": "__tact_pow", "signature": "int __tact_pow(int base, int exp)", }, - { - "code": { - "code": "UBITSIZE", - "kind": "asm", - "shuffle": "", - }, - "comment": null, - "context": "stdlib", - "depends": Set {}, - "flags": Set {}, - "name": "__tact_log2_floor_unsafe", - "signature": "int __tact_log2_floor_unsafe(int num)", - }, - { - "code": { - "code": "if (num == 0) { return 0; } -int s = __tact_log2_floor_unsafe(num); -int x = (s == 1 ? (num - 1) / 2 + 1 : 1 << ((s + 1) / 2)); - -do { - int q = (muldivc(num, 1, x) - x) / 2; - x += q; -} until (q == 0); - -return x;", - "kind": "generic", - }, - "comment": null, - "context": "stdlib", - "depends": Set { - "__tact_log2_floor_unsafe", - }, - "flags": Set { - "inline", - }, - "name": "__tact_sqrt", - "signature": "int __tact_sqrt(int num)", - }, { "code": { "code": "var (r, ok) = __tact_dict_get(d, kl, k); From bfae7507cf73dffb8e8448ba59d883a4d5157dc0 Mon Sep 17 00:00:00 2001 From: Gusarich Date: Thu, 21 Nov 2024 20:26:08 +0300 Subject: [PATCH 18/19] chore: update cspell ignorelist --- cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.json b/cspell.json index 90d2f5036..7cec0d084 100644 --- a/cspell.json +++ b/cspell.json @@ -72,6 +72,7 @@ "minmax", "mintable", "mktemp", + "muldivc", "multiformats", "nanotons", "Neovim", From 4d778d0391751720f6eaa00cfafea901bf86a22e Mon Sep 17 00:00:00 2001 From: Daniil Sedov Date: Fri, 22 Nov 2024 10:23:01 +0300 Subject: [PATCH 19/19] chore: update CHANGELOG.md Co-authored-by: Novus Nota <68142933+novusnota@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dd6d46c1..fdd246f33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `replace` and `replaceGet` methods for the `Map` type: PR [#941](https://github.com/tact-lang/tact/pull/941) - Utility for logging errors in code that was supposed to be unreachable: PR [#991](https://github.com/tact-lang/tact/pull/991) - Docs: `preloadRef` method for the `Slice` type: PR [#1044](https://github.com/tact-lang/tact/pull/1044) -- New functions in stdlib from `stdlib.fc` and `math.fc`: `Builder.depth`, `Slice.skipLastBits`, `Slice.firstBits`, `Slice.lastBits`, `Slice.depth`, `Cell.computeDataSize`, `Slice.computeDataSize`, `Cell.depth`, `curLt`, `blockLt`, `setGasLimit`, `getSeed`, `setSeed`, `myCode`, `sign`, `mulrshift`, `mulrshift_round`, `mulrshift_ceil`, `sqrt`, `addressNone`: PR [#986](https://github.com/tact-lang/tact/pull/986) +- New functions in stdlib from `stdlib.fc` and `math.fc`: `Builder.depth`, `Slice.skipLastBits`, `Slice.firstBits`, `Slice.lastBits`, `Slice.depth`, `Cell.computeDataSize`, `Slice.computeDataSize`, `Cell.depth`, `curLt`, `blockLt`, `setGasLimit`, `getSeed`, `setSeed`, `myCode`, `sign`, `divc`, `muldivc`, `mulShiftRight`, `mulShiftRightRound`, `mulShiftRightCeil`, `sqrt`, `addressNone`: PR [#986](https://github.com/tact-lang/tact/pull/986) ### Changed