1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

[Tolk] bool type (-1/0 int under the hood)

Comparison operators `== / >= /...` return `bool`.
Logical operators `&& ||` return bool.
Constants `true` and `false` have the `bool` type.
Lots of stdlib functions return `bool`, not `int`.

Operator `!x` supports both `int` and `bool`.
Condition of `if` accepts both `int` and `bool`.
Arithmetic operators are restricted to integers.
Logical `&&` and `||` accept both `bool` and `int`.

No arithmetic operations with bools allowed (only bitwise and logical).
This commit is contained in:
tolk-vm 2025-01-13 15:21:24 +07:00
parent 799e2d1265
commit 974d76c5f6
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
33 changed files with 764 additions and 212 deletions

View file

@ -661,7 +661,7 @@ fun fixed248_pow(x: int, y: int): int {
return 1 << 248; // x^0 = 1
}
if (x <= 0) {
var bad: int = (x | y) < 0;
var bad: int = ((x | y) < 0) as int;
return 0 >> bad; // 0^y = 0 if x=0 and y>=0; "out of range" exception otherwise
}
var (l, s) = log2_aux_f256(x);
@ -677,7 +677,7 @@ fun fixed248_pow(x: int, y: int): int {
// now log_2(x^y) = y*log_2(x) = q + ll, ss integer, ll fixed257, -1/2<=ll<1/2
var sq: int = q + 248;
if (sq <= 0) {
return -(sq == 0); // underflow
return -((sq == 0) as int); // underflow
}
y = expm1_f257(mulrshiftr256(ll, log2_const_f256()));
return (y ~>> (9 - q)) - (-1 << sq);
@ -986,7 +986,7 @@ fun tset<X>(mutate self: tuple, idx: int, value: X): void
// fixed256 acos_prepare_slow(fixed255 x);
@inline
fun acos_prepare_slow_f255(x: int): int {
x -= (x == 0);
x -= (x == 0) as int;
var t: int = 1;
repeat (255) {
t = t * sign(x) * 2 + 1; // decode Gray code (sign(x_0), sign(x_1), ...)