1// ========================================
2// PyBool
3// ========================================
4///|
5pub struct PyBool {
6 priv PyObject
obj : struct PyObject {
obj: @cpython.PyObjectRef
// private fields
}
PyObject
7}
8
9///| Create a python boolean object from a python object.
10/// If the object is not a boolean, it will raise a TypeMisMatchError.
11pub fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(obj : PyObject) -> PyBool!PyRuntimeError
Create a python boolean object from a python object.
If the object is not a boolean, it will raise a TypeMisMatchError.
create(PyObject
obj : struct PyObject {
obj: @cpython.PyObjectRef
// private fields
}
PyObject) -> struct PyBool {
obj: PyObject
// private fields
}
PyBool!type! PyRuntimeError {
TypeMisMatchError
IndexOutOfBoundsError
KeyIsUnHashableError
InVokeError
}
PyRuntimeError {
12 guard PyObject
obj.(self : PyObject) -> Bool
is_bool() else { raise PyRuntimeError
TypeMisMatchError }
13 struct PyBool {
obj: PyObject
// private fields
}
PyBool::{ PyObject
obj, }
14}
15
16///|
17fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(obj : PyObject) -> PyBool
create_unchecked(PyObject
obj : struct PyObject {
obj: @cpython.PyObjectRef
// private fields
}
PyObject) -> struct PyBool {
obj: PyObject
// private fields
}
PyBool {
18 struct PyBool {
obj: PyObject
// private fields
}
PyBool::{ PyObject
obj, }
19}
20
21///| Create a python boolean object from a python object reference.
22/// If the object is not a boolean, it will raise a TypeMisMatchError.
23pub fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(obj_ref : @cpython.PyObjectRef) -> PyBool!PyRuntimeError
Create a python boolean object from a python object reference.
If the object is not a boolean, it will raise a TypeMisMatchError.
create_by_ref(
24 @cpython.PyObjectRef
obj_ref : type @cpython.PyObjectRef
@cpython.PyObjectRef
25) -> struct PyBool {
obj: PyObject
// private fields
}
PyBool!type! PyRuntimeError {
TypeMisMatchError
IndexOutOfBoundsError
KeyIsUnHashableError
InVokeError
}
PyRuntimeError {
26 guard (obj : @cpython.PyObjectRef) -> Bool
@cpython.py_bool_check(@cpython.PyObjectRef
obj_ref) else { raise PyRuntimeError
TypeMisMatchError }
27 struct PyBool {
obj: PyObject
// private fields
}
PyBool::{ PyObject
obj: struct PyObject {
obj: @cpython.PyObjectRef
// private fields
}
PyObject::(obj : @cpython.PyObjectRef) -> PyObject
create(@cpython.PyObjectRef
obj_ref) }
28}
29
30///|
31fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(obj_ref : @cpython.PyObjectRef) -> PyBool
create_by_ref_unchecked(@cpython.PyObjectRef
obj_ref : type @cpython.PyObjectRef
@cpython.PyObjectRef) -> struct PyBool {
obj: PyObject
// private fields
}
PyBool {
32 struct PyBool {
obj: PyObject
// private fields
}
PyBool::{ PyObject
obj: struct PyObject {
obj: @cpython.PyObjectRef
// private fields
}
PyObject::(obj : @cpython.PyObjectRef) -> PyObject
create(@cpython.PyObjectRef
obj_ref) }
33}
34
35///|
36pub fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(self : PyBool) -> Unit
dump(PyBool
self : struct PyBool {
obj: PyObject
// private fields
}
PyBool) -> Unit
Unit {
37 PyBool
self.PyObject
obj.(self : PyObject) -> Unit
dump()
38}
39
40///| Create a python boolean object from moonbit bool.
41///
42/// ## Example
43///
44/// ```moonbit
45/// test "PyBool::from" {
46/// let t = PyBool::from(true);
47///
48/// inspect!(t, content="True")
49/// }
50/// ```
51///
52/// The above code is equivalent to:
53///
54/// ```python
55/// t = True
56///
57/// print(t) # Output: True
58/// ```
59pub fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(value : Bool) -> PyBool
Create a python boolean object from moonbit bool.
Example
test "PyBool::from" {
let t = PyBool::from(true);
inspect!(t, content="True")
}
The above code is equivalent to:
t = True
print(t) # Output: True
from(Bool
value : Bool
Bool) -> struct PyBool {
obj: PyObject
// private fields
}
PyBool {
60 let Int64
value = Bool
value.(self : Bool) -> Int64
Converts a boolean value to a 64-bit integer. Returns 1 for true
and 0 for
false
.
Parameters:
bool
: The boolean value to be converted.
Returns a 64-bit integer representation of the boolean value.
Example:
test "to_int64" {
inspect(true.to_int64(), content="1")
inspect(false.to_int64(), content="0")
}
to_int64()
61 let @cpython.PyObjectRef
obj_ref = (value : Int64) -> @cpython.PyObjectRef
@cpython.py_bool_from_long(Int64
value)
62 struct PyBool {
obj: PyObject
// private fields
}
PyBool::(obj_ref : @cpython.PyObjectRef) -> PyBool
create_by_ref_unchecked(@cpython.PyObjectRef
obj_ref)
63}
64
65///| Return `true` if it is true, using python interpreter.
66///
67/// ## Example
68///
69/// ```moonbit
70/// test "PyBool::is_true" {
71/// let t = PyBool::from(true);
72/// let f = PyBool::from(false);
73///
74/// assert_true!(t.is_true());
75/// assert_false!(f.is_true());
76/// }
77/// ```
78pub fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(self : PyBool) -> Bool
Return true
if it is true, using python interpreter.
Example
test "PyBool::is_true" {
let t = PyBool::from(true);
let f = PyBool::from(false);
assert_true!(t.is_true());
assert_false!(f.is_true());
}
is_true(PyBool
self : struct PyBool {
obj: PyObject
// private fields
}
PyBool) -> Bool
Bool {
79 let @cpython.PyObjectRef
obj = PyBool
self.(self : PyBool) -> @cpython.PyObjectRef
obj_ref()
80 (a : @cpython.PyObjectRef) -> Bool
@cpython.py_object_is_true(@cpython.PyObjectRef
obj)
81}
82
83///|
84pub fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(self : PyBool) -> Bool
to_bool(PyBool
self : struct PyBool {
obj: PyObject
// private fields
}
PyBool) -> Bool
Bool {
85 PyBool
self.(self : PyBool) -> Bool
Return true
if it is true, using python interpreter.
Example
test "PyBool::is_true" {
let t = PyBool::from(true);
let f = PyBool::from(false);
assert_true!(t.is_true());
assert_false!(f.is_true());
}
is_true()
86}
87
88///| Return `true` if it is false, using python interpreter.
89///
90/// ## Example
91///
92/// ```moonbit
93/// test "PyBool::is_false" {
94/// let t = PyBool::from(true);
95/// let f = PyBool::from(false);
96///
97/// assert_false!(t.is_false());
98/// assert_true!(f.is_false());
99/// }
100/// ```
101pub fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(self : PyBool) -> Bool
Return true
if it is false, using python interpreter.
Example
test "PyBool::is_false" {
let t = PyBool::from(true);
let f = PyBool::from(false);
assert_false!(t.is_false());
assert_true!(f.is_false());
}
is_false(PyBool
self : struct PyBool {
obj: PyObject
// private fields
}
PyBool) -> Bool
Bool {
102 PyBool
self.(self : PyBool) -> Bool
Return true
if it is true, using python interpreter.
Example
test "PyBool::is_true" {
let t = PyBool::from(true);
let f = PyBool::from(false);
assert_true!(t.is_true());
assert_false!(f.is_true());
}
is_true() |> (x : Bool) -> Bool
Performs logical negation on a boolean value.
Parameters:
value
: The boolean value to negate.
Returns the logical NOT of the input value: true
if the input is false
,
and false
if the input is true
.
Example:
test "not" {
inspect(not(true), content="false")
inspect(not(false), content="true")
}
not
103}
104
105///| Return the reverse of the boolean value.
106///
107/// ## Example
108///
109/// ```moonbit
110/// test "PyBool::not" {
111/// let t = PyBool::from(true);
112/// let f = t.not();
113///
114/// assert_true!(f.is_false());
115/// }
116/// ```
117pub fn struct PyBool {
obj: PyObject
// private fields
}
PyBool::(self : PyBool) -> PyBool
Return the reverse of the boolean value.
Example
test "PyBool::not" {
let t = PyBool::from(true);
let f = t.not();
assert_true!(f.is_false());
}
not(PyBool
self : struct PyBool {
obj: PyObject
// private fields
}
PyBool) -> struct PyBool {
obj: PyObject
// private fields
}
PyBool {
118 if PyBool
self.(self : PyBool) -> Bool
Return true
if it is true, using python interpreter.
Example
test "PyBool::is_true" {
let t = PyBool::from(true);
let f = PyBool::from(false);
assert_true!(t.is_true());
assert_false!(f.is_true());
}
is_true() {
119 return struct PyBool {
obj: PyObject
// private fields
}
PyBool::(value : Bool) -> PyBool
Create a python boolean object from moonbit bool.
Example
test "PyBool::from" {
let t = PyBool::from(true);
inspect!(t, content="True")
}
The above code is equivalent to:
t = True
print(t) # Output: True
from(false)
120 } else {
121 return struct PyBool {
obj: PyObject
// private fields
}
PyBool::(value : Bool) -> PyBool
Create a python boolean object from moonbit bool.
Example
test "PyBool::from" {
let t = PyBool::from(true);
inspect!(t, content="True")
}
The above code is equivalent to:
t = True
print(t) # Output: True
from(true)
122 }
123}
124
125///|
126pub impl trait IsPyObject {
obj(Self) -> PyObject
obj_ref(Self) -> @cpython.PyObjectRef
type_name(Self) -> String
}
IsPyObject for struct PyBool {
obj: PyObject
// private fields
}
PyBool with (self : PyBool) -> PyObject
obj(PyBool
self) {
127 PyBool
self.PyObject
obj
128}
129
130///|
131pub impl trait Show {
output(Self, &Logger) -> Unit
to_string(Self) -> String
}
Trait for types that can be converted to String
Show for struct PyBool {
obj: PyObject
// private fields
}
PyBool with (self : PyBool) -> String
to_string(PyBool
self) {
132 PyBool
self.PyObject
obj.(self : PyObject) -> String
to_string()
133}
134
135///|
136pub impl trait Show {
output(Self, &Logger) -> Unit
to_string(Self) -> String
}
Trait for types that can be converted to String
Show for struct PyBool {
obj: PyObject
// private fields
}
PyBool with (self : PyBool, logger : &Logger) -> Unit
output(PyBool
self, &Logger
logger) {
137 &Logger
logger.(&Logger, String) -> Unit
write_string(PyBool
self.(self : PyBool) -> String
to_string())
138}
139