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
|
from internal.attributes import commutative, associative
|
||||||
|
|
||||||
|
|
||||||
@extend
|
@extend
|
||||||
class bool:
|
class bool:
|
||||||
def __new__() -> bool:
|
def __new__() -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __new__(what) -> bool:
|
def __new__(what) -> bool:
|
||||||
return what.__bool__()
|
return what.__bool__()
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return "True" if self else "False"
|
return "True" if self else "False"
|
||||||
|
|
||||||
def __copy__(self) -> bool:
|
def __copy__(self) -> bool:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __deepcopy__(self) -> bool:
|
def __deepcopy__(self) -> bool:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __bool__(self) -> bool:
|
def __bool__(self) -> bool:
|
||||||
return self
|
return self
|
||||||
def __hash__(self):
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
return int(self)
|
return int(self)
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __invert__(self) -> bool:
|
def __invert__(self) -> bool:
|
||||||
@ -23,42 +33,49 @@ class bool:
|
|||||||
%1 = xor i1 %0, true
|
%1 = xor i1 %0, true
|
||||||
%2 = zext i1 %1 to i8
|
%2 = zext i1 %1 to i8
|
||||||
ret i8 %2
|
ret i8 %2
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __eq__(self, other: bool) -> bool:
|
def __eq__(self, other: bool) -> bool:
|
||||||
%0 = icmp eq i8 %self, %other
|
%0 = icmp eq i8 %self, %other
|
||||||
%1 = zext i1 %0 to i8
|
%1 = zext i1 %0 to i8
|
||||||
ret i8 %1
|
ret i8 %1
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __ne__(self, other: bool) -> bool:
|
def __ne__(self, other: bool) -> bool:
|
||||||
%0 = icmp ne i8 %self, %other
|
%0 = icmp ne i8 %self, %other
|
||||||
%1 = zext i1 %0 to i8
|
%1 = zext i1 %0 to i8
|
||||||
ret i8 %1
|
ret i8 %1
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __lt__(self, other: bool) -> bool:
|
def __lt__(self, other: bool) -> bool:
|
||||||
%0 = icmp ult i8 %self, %other
|
%0 = icmp ult i8 %self, %other
|
||||||
%1 = zext i1 %0 to i8
|
%1 = zext i1 %0 to i8
|
||||||
ret i8 %1
|
ret i8 %1
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __gt__(self, other: bool) -> bool:
|
def __gt__(self, other: bool) -> bool:
|
||||||
%0 = icmp ugt i8 %self, %other
|
%0 = icmp ugt i8 %self, %other
|
||||||
%1 = zext i1 %0 to i8
|
%1 = zext i1 %0 to i8
|
||||||
ret i8 %1
|
ret i8 %1
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __le__(self, other: bool) -> bool:
|
def __le__(self, other: bool) -> bool:
|
||||||
%0 = icmp ule i8 %self, %other
|
%0 = icmp ule i8 %self, %other
|
||||||
%1 = zext i1 %0 to i8
|
%1 = zext i1 %0 to i8
|
||||||
ret i8 %1
|
ret i8 %1
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __ge__(self, other: bool) -> bool:
|
def __ge__(self, other: bool) -> bool:
|
||||||
%0 = icmp uge i8 %self, %other
|
%0 = icmp uge i8 %self, %other
|
||||||
%1 = zext i1 %0 to i8
|
%1 = zext i1 %0 to i8
|
||||||
ret i8 %1
|
ret i8 %1
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@commutative
|
@commutative
|
||||||
@associative
|
@associative
|
||||||
@ -66,6 +83,7 @@ class bool:
|
|||||||
def __and__(self, other: bool) -> bool:
|
def __and__(self, other: bool) -> bool:
|
||||||
%0 = and i8 %self, %other
|
%0 = and i8 %self, %other
|
||||||
ret i8 %0
|
ret i8 %0
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@commutative
|
@commutative
|
||||||
@associative
|
@associative
|
||||||
@ -73,6 +91,7 @@ class bool:
|
|||||||
def __or__(self, other: bool) -> bool:
|
def __or__(self, other: bool) -> bool:
|
||||||
%0 = or i8 %self, %other
|
%0 = or i8 %self, %other
|
||||||
ret i8 %0
|
ret i8 %0
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@commutative
|
@commutative
|
||||||
@associative
|
@associative
|
||||||
@ -80,11 +99,13 @@ class bool:
|
|||||||
def __xor__(self, other: bool) -> bool:
|
def __xor__(self, other: bool) -> bool:
|
||||||
%0 = xor i8 %self, %other
|
%0 = xor i8 %self, %other
|
||||||
ret i8 %0
|
ret i8 %0
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __int__(self) -> int:
|
def __int__(self) -> int:
|
||||||
%0 = zext i8 %self to i64
|
%0 = zext i8 %self to i64
|
||||||
ret i64 %0
|
ret i64 %0
|
||||||
|
|
||||||
@pure
|
@pure
|
||||||
@llvm
|
@llvm
|
||||||
def __float__(self) -> float:
|
def __float__(self) -> float:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user