Skip to content

Commit 7b2a052

Browse files
authored
implemented short-circuiting of conditionals (WerWolv#202)
* implemented short-circuiting of conditionals that supports type conversions. This addresses WerWolv#201 feature request. * fixes for macos compilation * fixes for macos compilation * fixes for macos compilation * fixes for macos compilation * fixes for macos compilation * fixes for macos compilation * undoing changes to try to fix mac os builds.
1 parent 7908b49 commit 7b2a052

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979

8080
- name: ⬇️ Install dependencies
8181
run: |
82-
brew install llvm ccache ninja
82+
brew install llvm@20 ccache ninja
8383
8484
- name: 📜 Setup ccache
8585
uses: hendrikmuhs/ccache-action@v1
@@ -92,10 +92,10 @@ jobs:
9292
run: |
9393
mkdir -p build
9494
cd build
95-
CC=$(brew --prefix llvm)/bin/clang \
96-
CXX=$(brew --prefix llvm)/bin/clang++ \
97-
OBJC=$(brew --prefix llvm)/bin/clang \
98-
OBJCXX=$(brew --prefix llvm)/bin/clang++ \
95+
CC=$(brew --prefix llvm@20)/bin/clang \
96+
CXX=$(brew --prefix llvm@20)/bin/clang++ \
97+
OBJC=$(brew --prefix llvm@20)/bin/clang \
98+
OBJCXX=$(brew --prefix llvm@20)/bin/clang++ \
9999
cmake \
100100
-DCMAKE_BUILD_TYPE=Debug \
101101
-DCMAKE_INSTALL_PREFIX="$PWD/install" \

lib/source/pl/core/ast/ast_node_mathematical_expression.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,26 @@ namespace pl::core::ast {
6767
};
6868

6969
auto leftNode = this->getLeftOperand()->evaluate(evaluator);
70-
auto rightNode = this->getRightOperand()->evaluate(evaluator);
71-
7270
auto leftLiteral = dynamic_cast<ASTNodeLiteral *>(leftNode.get());
73-
auto rightLiteral = dynamic_cast<ASTNodeLiteral *>(rightNode.get());
71+
if (leftLiteral == nullptr)
72+
throwInvalidOperandError();
7473

75-
if (leftLiteral == nullptr || rightLiteral == nullptr)
74+
if (this->getOperator() == Token::Operator::BoolAnd || this->getOperator() == Token::Operator::BoolOr) {
75+
auto leftBool = std::visit(wolv::util::overloaded {
76+
[](const std::string &value) -> bool { return !value.empty(); },
77+
[this](ptrn::Pattern *const &pattern) -> bool { err::E0004.throwError(fmt::format("Cannot cast value of type '{}' to type 'bool'.", pattern->getTypeName()), {}, this->getLocation()); },
78+
[](auto &&value) -> bool { return value != 0; }
79+
}, leftLiteral->getValue());
80+
81+
if (this->getOperator() == Token::Operator::BoolAnd && !leftBool)
82+
return std::unique_ptr<ASTNode>(new ASTNodeLiteral(false));
83+
if (this->getOperator() == Token::Operator::BoolOr && leftBool)
84+
return std::unique_ptr<ASTNode>(new ASTNodeLiteral(true));
85+
}
86+
87+
auto rightNode = this->getRightOperand()->evaluate(evaluator);
88+
auto rightLiteral = dynamic_cast<ASTNodeLiteral *>(rightNode.get());
89+
if (rightLiteral == nullptr)
7690
throwInvalidOperandError();
7791

7892
auto leftValue = leftLiteral->getValue();

0 commit comments

Comments
 (0)