Skip to content

Commit

Permalink
fix: Fixed different enums operators
Browse files Browse the repository at this point in the history
  • Loading branch information
alinalihassan committed May 21, 2022
1 parent 212fbcb commit 3e9dea7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/liblesma/Backend/Codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,9 @@ llvm::Value *Codegen::visit(BinaryOp *node) {
left = Cast(node->getSpan(), left, finalType);
right = Cast(node->getSpan(), right, finalType);

if (finalType->isFloatingPointTy())
if (finalType == nullptr && left->getType()->getPointerElementType()->isStructTy() && right->getType()->getPointerElementType()->isStructTy())
return ConstantInt::getBool(*TheContext, false);
else if (finalType->isFloatingPointTy())
return Builder->CreateFCmpOEQ(left, right, ".tmp");
else if (finalType->isIntegerTy())
return Builder->CreateICmpEQ(left, right, ".tmp");
Expand All @@ -774,7 +776,9 @@ llvm::Value *Codegen::visit(BinaryOp *node) {
left = Cast(node->getSpan(), left, finalType);
right = Cast(node->getSpan(), right, finalType);

if (finalType->isFloatingPointTy())
if (finalType == nullptr && left->getType()->getPointerElementType()->isStructTy() && right->getType()->getPointerElementType()->isStructTy())
return ConstantInt::getBool(*TheContext, true);
else if (finalType->isFloatingPointTy())
return Builder->CreateFCmpONE(left, right, ".tmp");
else if (finalType->isIntegerTy())
return Builder->CreateICmpNE(left, right, ".tmp");
Expand Down Expand Up @@ -1068,7 +1072,7 @@ llvm::Value *Codegen::Cast(llvm::SMRange span, llvm::Value *val, llvm::Type *typ
}

llvm::Value *Codegen::Cast(llvm::SMRange span, llvm::Value *val, llvm::Type *type, bool isStore) {
if (val->getType() == type || (isStore && val->getType() == type->getPointerTo()))
if (val->getType() == type || (isStore && val->getType() == type->getPointerTo()) || val->getType()->getPointerElementType()->isStructTy())
return val;

if (type->isIntegerTy()) {
Expand Down
16 changes: 16 additions & 0 deletions tests/lesma/enum_compare.les
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ret=101
def extern exit(x: int)

enum Color
RED
BLUE
GREEN

enum Color2
RED
BLUE
GREEN

#var x: Color = Color.RED
if Color.RED != Color2.RED
exit(101)

0 comments on commit 3e9dea7

Please sign in to comment.