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

[Tolk] Implement logical operators && ||

Unary logical NOT was already implemented earlier.
Logical AND OR are expressed via conditional expression:
* a && b  ->  a ? (b != 0) : 0
* a || b  ->  a ? 1 : (b != 0)
They work as expected in any expressions. For instance, having
`cond && f()`, f is called only if cond is true.
For primitive cases, like `a > 0 && b > 0`, Fift code is not optimal,
it could potentially be without IFs.
These are moments of future optimizations. For now, it's more than enough.
This commit is contained in:
tolk-vm 2024-10-31 11:22:18 +04:00
parent 16824fcfe3
commit d110022731
No known key found for this signature in database
GPG key ID: 7905DD7FE0324B12
4 changed files with 204 additions and 46 deletions

View file

@ -67,8 +67,8 @@ private:
public:
static constexpr sym_idx_t not_found = 0;
sym_idx_t lookup(std::string_view str, int mode = 0) {
return gen_lookup(str, mode);
sym_idx_t lookup(std::string_view str) {
return gen_lookup(str, 0);
}
sym_idx_t lookup_add(std::string_view str) {
return gen_lookup(str, 1);