Skip to content

Commit

Permalink
feat: add .storeBit and .loadBit functions to stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich committed Aug 22, 2024
1 parent 8112eeb commit 656651d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- The `exists` method for the `Map` type: PR [#581](https://github.com/tact-lang/tact/pull/581)
- The `storeBit` method for `Builder` type and the `loadBit` method for `Slice` type: PR [#699](https://github.com/tact-lang/tact/pull/699)

### Changed

Expand Down
54 changes: 28 additions & 26 deletions src/imports/stdlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,34 @@ files['std/cells.tact'] =
'Ly8KLy8gQnVpbGRlcgovLwoKQG5hbWUoYmVnaW5fY2VsbCkKbmF0aXZlIGJlZ2luQ2VsbCgpOiBCdWlsZGVyOwoKQG5hbWUoc3RvcmVfaW50KQpleHRlbmRzIG5hdGl2' +
'ZSBzdG9yZUludChzZWxmOiBCdWlsZGVyLCB2YWx1ZTogSW50LCBiaXRzOiBJbnQpOiBCdWlsZGVyOwoKQG5hbWUoc3RvcmVfdWludCkKZXh0ZW5kcyBuYXRpdmUgc3Rv' +
'cmVVaW50KHNlbGY6IEJ1aWxkZXIsIHZhbHVlOiBJbnQsIGJpdHM6IEludCk6IEJ1aWxkZXI7CgpAbmFtZShfX3RhY3Rfc3RvcmVfYm9vbCkKZXh0ZW5kcyBuYXRpdmUg' +
'c3RvcmVCb29sKHNlbGY6IEJ1aWxkZXIsIHZhbHVlOiBCb29sKTogQnVpbGRlcjsKCkBuYW1lKHN0b3JlX2NvaW5zKQpleHRlbmRzIG5hdGl2ZSBzdG9yZUNvaW5zKHNl' +
'bGY6IEJ1aWxkZXIsIHZhbHVlOiBJbnQpOiBCdWlsZGVyOwoKQG5hbWUoc3RvcmVfcmVmKQp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CiAgICByZXR1cm4gc2VsZi5iZWdp' +
'blBhcnNlKCk7Cn0KCmlubGluZSBleHRlbmRzIGZ1biBhc0NlbGwoc2VsZjogU2xpY2UpOiBDZWxsIHsKICAgIHJldHVybiBiZWdpbkNlbGwoKQogICAgICAgIC5zdG9y' +
'ZVNsaWNlKHNlbGYpCiAgICAgICAgLmVuZENlbGwoKTsKfQoKaW5saW5lIGV4dGVuZHMgZnVuIGFzQ2VsbChzZWxmOiBCdWlsZGVyKTogQ2VsbCB7CiAgICByZXR1cm4g' +
'c2VsZi5lbmRDZWxsKCk7Cn0KCmlubGluZSBmdW4gZW1wdHlDZWxsKCk6IENlbGwgewogICAgcmV0dXJuIGJlZ2luQ2VsbCgpLmVuZENlbGwoKTsKfQoKaW5saW5lIGZ1' +
'biBlbXB0eVNsaWNlKCk6IFNsaWNlIHsKICAgIHJldHVybiBlbXB0eUNlbGwoKS5hc1NsaWNlKCk7Cn0=';
files['std/config.tact'] =
'QG5hbWUoY29uZmlnX3BhcmFtKQpuYXRpdmUgZ2V0Q29uZmlnUGFyYW0oaWQ6IEludCk6IENlbGw/Ow==';
files['std/context.tact'] =
Expand Down
12 changes: 12 additions & 0 deletions src/test/e2e-emulated/contracts/stdlib.tact
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@ contract StdlibTest {
get fun sliceRefs(sc: Slice): Int {
return sc.refs();
}

get fun storeBool(bl: Builder, b: Bool): Builder {
return bl.storeBool(b);
}

get fun loadBool(sc: Slice): Bool {
return sc.loadBool();
}

get fun storeBit(bl: Builder, b: Bool): Builder {
return bl.storeBit(b);
}

get fun loadBit(sc: Slice): Bool {
return sc.loadBit();
}
}
11 changes: 11 additions & 0 deletions src/test/e2e-emulated/stdlib.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ describe("stdlib", () => {
expect(await contract.getSliceRefs(slice)).toBe(1n);
expect(await contract.getSliceEmpty(slice)).toBe(false);
expect(await contract.getLoadBool(slice)).toBe(true);
expect(await contract.getLoadBit(slice)).toBe(true);
expect(
(await contract.getStoreBool(beginCell(), true))
.endCell()
.toString(),
).toBe(beginCell().storeBit(true).endCell().toString());
expect(
(await contract.getStoreBit(beginCell(), true))
.endCell()
.toString(),
).toBe(beginCell().storeBit(true).endCell().toString());
});
});
6 changes: 6 additions & 0 deletions stdlib/std/cells.tact
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ extends native storeUint(self: Builder, value: Int, bits: Int): Builder;
@name(__tact_store_bool)
extends native storeBool(self: Builder, value: Bool): Builder;

@name(__tact_store_bool)
extends native storeBit(self: Builder, value: Bool): Builder;

@name(store_coins)
extends native storeCoins(self: Builder, value: Int): Builder;

Expand Down Expand Up @@ -69,6 +72,9 @@ extends native preloadUint(self: Slice, l: Int): Int;
@name(__tact_load_bool)
extends mutates native loadBool(self: Slice): Bool;

@name(__tact_load_bool)
extends mutates native loadBit(self: Slice): Bool;

@name(load_coins)
extends mutates native loadCoins(self: Slice): Int;

Expand Down

0 comments on commit 656651d

Please sign in to comment.