diff --git a/CHANGELOG.md b/CHANGELOG.md index 456c1df20..a761d4fce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The bitwise NOT operation (`~`): PR [#337](https://github.com/tact-lang/tact/pull/337) - Augmented assignment bitwise operators `|=`, `&=`, `^=`: PR [#350](https://github.com/tact-lang/tact/pull/350) - Traversing maps from contract storage and structs is now allowed: PR [#389](https://github.com/tact-lang/tact/pull/389) +- The `loadBool` method for `Slice` type: PR [#412](https://github.com/tact-lang/tact/pull/412) ### Changed diff --git a/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap b/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap index d0e9886df..ed0c66a0f 100644 --- a/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap +++ b/src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap @@ -75,6 +75,18 @@ return address;", "name": "__tact_verify_address", "signature": "slice __tact_verify_address(slice address)", }, + { + "code": { + "code": "asm( -> 1 0) "1 LDI"", + "kind": "asm", + }, + "comment": null, + "context": "stdlib", + "depends": Set {}, + "flags": Set {}, + "name": "__tact_load_bool", + "signature": "(slice, int) __tact_load_bool(slice s)", + }, { "code": { "code": "slice raw = cs~load_msg_addr(); @@ -4664,6 +4676,18 @@ return address;", "name": "__tact_verify_address", "signature": "slice __tact_verify_address(slice address)", }, + { + "code": { + "code": "asm( -> 1 0) "1 LDI"", + "kind": "asm", + }, + "comment": null, + "context": "stdlib", + "depends": Set {}, + "flags": Set {}, + "name": "__tact_load_bool", + "signature": "(slice, int) __tact_load_bool(slice s)", + }, { "code": { "code": "slice raw = cs~load_msg_addr(); @@ -9253,6 +9277,18 @@ return address;", "name": "__tact_verify_address", "signature": "slice __tact_verify_address(slice address)", }, + { + "code": { + "code": "asm( -> 1 0) "1 LDI"", + "kind": "asm", + }, + "comment": null, + "context": "stdlib", + "depends": Set {}, + "flags": Set {}, + "name": "__tact_load_bool", + "signature": "(slice, int) __tact_load_bool(slice s)", + }, { "code": { "code": "slice raw = cs~load_msg_addr(); diff --git a/src/generator/writers/writeStdlib.ts b/src/generator/writers/writeStdlib.ts index e57f0b405..7069fa1d1 100644 --- a/src/generator/writers/writeStdlib.ts +++ b/src/generator/writers/writeStdlib.ts @@ -43,6 +43,12 @@ export function writeStdlib(ctx: WriterContext) { }); }); + ctx.fun("__tact_load_bool", () => { + ctx.signature(`(slice, int) __tact_load_bool(slice s)`); + ctx.context("stdlib"); + ctx.asm(`asm( -> 1 0) "1 LDI"`); + }); + ctx.fun("__tact_load_address", () => { ctx.signature(`(slice, slice) __tact_load_address(slice cs)`); ctx.flag("inline"); diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index b638161e9..1ba6d83b0 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -139,19 +139,19 @@ files['std/cells.tact'] = 'b2FkX2ludCkKZXh0ZW5kcyBtdXRhdGVzIG5hdGl2ZSBsb2FkSW50KHNlbGY6IFNsaWNlLCBsOiBJbnQpOiBJbnQ7CgpAbmFtZShwcmVsb2FkX2ludCkKZXh0ZW5kcyBu' + 'YXRpdmUgcHJlbG9hZEludChzZWxmOiBTbGljZSwgbDogSW50KTogSW50OwoKQG5hbWUobG9hZF91aW50KQpleHRlbmRzIG11dGF0ZXMgbmF0aXZlIGxvYWRVaW50KHNl' + 'bGY6IFNsaWNlLCBsOiBJbnQpOiBJbnQ7CgpAbmFtZShwcmVsb2FkX3VpbnQpCmV4dGVuZHMgbmF0aXZlIHByZWxvYWRVaW50KHNlbGY6IFNsaWNlLCBsOiBJbnQpOiBJ' + - 'bnQ7CgpAbmFtZShsb2FkX2NvaW5zKQpleHRlbmRzIG11dGF0ZXMgbmF0aXZlIGxvYWRDb2lucyhzZWxmOiBTbGljZSk6IEludDsKCkBuYW1lKF9fdGFjdF9sb2FkX2Fk' + - 'ZHJlc3MpCmV4dGVuZHMgbXV0YXRlcyBuYXRp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mlnX3BhcmFtKQpuYXRpdmUgZ2V0Q29uZmlnUGFyYW0oaWQ6IEludCk6IENlbGw/Ow=='; files['std/context.tact'] = diff --git a/src/test/e2e-emulated/contracts/stdlib.tact b/src/test/e2e-emulated/contracts/stdlib.tact index 1214b2389..1fe3c3284 100644 --- a/src/test/e2e-emulated/contracts/stdlib.tact +++ b/src/test/e2e-emulated/contracts/stdlib.tact @@ -21,4 +21,8 @@ contract StdlibTest { get fun sliceRefs(sc: Slice): Int { return sc.refs(); } + + get fun loadBool(sc: Slice): Bool { + return sc.loadBool(); + } } \ No newline at end of file diff --git a/src/test/e2e-emulated/stdlib.spec.ts b/src/test/e2e-emulated/stdlib.spec.ts index ecc34711d..c6f48cbac 100644 --- a/src/test/e2e-emulated/stdlib.spec.ts +++ b/src/test/e2e-emulated/stdlib.spec.ts @@ -17,11 +17,9 @@ describe("stdlib", () => { .storeBit(1) .storeRef(beginCell().storeBit(1).endCell()) .endCell(); - const bits = await contract.getSliceBits(slice); - const refs = await contract.getSliceRefs(slice); - const empty = await contract.getSliceEmpty(slice); - expect(bits).toBe(2n); - expect(refs).toBe(1n); - expect(empty).toBe(false); + expect(await contract.getSliceBits(slice)).toBe(2n); + expect(await contract.getSliceRefs(slice)).toBe(1n); + expect(await contract.getSliceEmpty(slice)).toBe(false); + expect(await contract.getLoadBool(slice)).toBe(true); }); }); diff --git a/stdlib/std/cells.tact b/stdlib/std/cells.tact index f05cbe109..dac5b89a2 100644 --- a/stdlib/std/cells.tact +++ b/stdlib/std/cells.tact @@ -66,6 +66,9 @@ extends mutates native loadUint(self: Slice, l: Int): Int; @name(preload_uint) extends native preloadUint(self: Slice, l: Int): Int; +@name(__tact_load_bool) +extends mutates native loadBool(self: Slice): Bool; + @name(load_coins) extends mutates native loadCoins(self: Slice): Int;