mirror of
https://github.com/exaloop/codon.git
synced 2025-06-03 15:03:52 +08:00
stdlib/internal/types/bool.codon
This commit is contained in:
parent
5815686f54
commit
c5d5e254cf
@ -1,21 +1,31 @@
|
||||
# (c) 2022 Exaloop Inc. All rights reserved.
|
||||
|
||||
from internal.attributes import commutative, associative
|
||||
|
||||
|
||||
@extend
|
||||
class bool:
|
||||
def __new__() -> bool:
|
||||
return False
|
||||
|
||||
def __new__(what) -> bool:
|
||||
return what.__bool__()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "True" if self else "False"
|
||||
|
||||
def __copy__(self) -> bool:
|
||||
return self
|
||||
|
||||
def __deepcopy__(self) -> bool:
|
||||
return self
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return self
|
||||
def __hash__(self):
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return int(self)
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __invert__(self) -> bool:
|
||||
@ -23,42 +33,49 @@ class bool:
|
||||
%1 = xor i1 %0, true
|
||||
%2 = zext i1 %1 to i8
|
||||
ret i8 %2
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __eq__(self, other: bool) -> bool:
|
||||
%0 = icmp eq i8 %self, %other
|
||||
%1 = zext i1 %0 to i8
|
||||
ret i8 %1
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __ne__(self, other: bool) -> bool:
|
||||
%0 = icmp ne i8 %self, %other
|
||||
%1 = zext i1 %0 to i8
|
||||
ret i8 %1
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __lt__(self, other: bool) -> bool:
|
||||
%0 = icmp ult i8 %self, %other
|
||||
%1 = zext i1 %0 to i8
|
||||
ret i8 %1
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __gt__(self, other: bool) -> bool:
|
||||
%0 = icmp ugt i8 %self, %other
|
||||
%1 = zext i1 %0 to i8
|
||||
ret i8 %1
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __le__(self, other: bool) -> bool:
|
||||
%0 = icmp ule i8 %self, %other
|
||||
%1 = zext i1 %0 to i8
|
||||
ret i8 %1
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __ge__(self, other: bool) -> bool:
|
||||
%0 = icmp uge i8 %self, %other
|
||||
%1 = zext i1 %0 to i8
|
||||
ret i8 %1
|
||||
|
||||
@pure
|
||||
@commutative
|
||||
@associative
|
||||
@ -66,6 +83,7 @@ class bool:
|
||||
def __and__(self, other: bool) -> bool:
|
||||
%0 = and i8 %self, %other
|
||||
ret i8 %0
|
||||
|
||||
@pure
|
||||
@commutative
|
||||
@associative
|
||||
@ -73,6 +91,7 @@ class bool:
|
||||
def __or__(self, other: bool) -> bool:
|
||||
%0 = or i8 %self, %other
|
||||
ret i8 %0
|
||||
|
||||
@pure
|
||||
@commutative
|
||||
@associative
|
||||
@ -80,11 +99,13 @@ class bool:
|
||||
def __xor__(self, other: bool) -> bool:
|
||||
%0 = xor i8 %self, %other
|
||||
ret i8 %0
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __int__(self) -> int:
|
||||
%0 = zext i8 %self to i64
|
||||
ret i64 %0
|
||||
|
||||
@pure
|
||||
@llvm
|
||||
def __float__(self) -> float:
|
||||
|
Loading…
x
Reference in New Issue
Block a user