8000 Add true_value and false_value to context. · rmliddle/RustPython@1bb7579 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1bb7579

Browse files
committed
Add true_value and false_value to context.
1 parent 9394fec commit 1bb7579

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

vm/src/pyobject.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub struct PyContext {
5656
pub float_type: PyObjectRef,
5757
pub bytes_type: PyObjectRef,
5858
pub bool_type: PyObjectRef,
59+
pub true_value: PyObjectRef,
60+
pub false_value: PyObjectRef,
5961
pub list_type: PyObjectRef,
6062
pub tuple_type: PyObjectRef,
6163
pub str_type: PyObjectRef,
@@ -127,12 +129,16 @@ impl PyContext {
127129
create_type("NoneType", &type_type, &object_type, &dict_type),
128130
);
129131

132+
let true_value = PyObject::new(PyObjectKind::Integer { value: 1 }, bool_type.clone());
133+
let false_value = PyObject::new(PyObjectKind::Integer { value: 0 }, bool_type.clone());
130134
let context = PyContext {
131135
int_type: int_type,
132136
float_type: float_type,
133137
bytes_type: bytes_type,
134138
list_type: list_type,
135139
bool_type: bool_type,
140+
true_value: true_value,
141+
false_value: false_value,
136142
tuple_type: tuple_type,
137143
dict_type: dict_type,
138144
none: none,
@@ -220,12 +226,11 @@ impl PyContext {
220226
}
221227

222228
pub fn new_bool(&self, b: bool) -> PyObjectRef {
223-
PyObject::new(
224-
PyObjectKind::Integer {
225-
value: if b { 1 } else { 0 },
226-
},
227-
self.bool_type(),
228-
)
229+
if b {
230+
self.true_value.clone()
231+
} else {
232+
self.false_value.clone()
233+
}
229234
}
230235

231236
pub fn new_tuple(&self, elements: Vec<PyObjectRef>) -> PyObjectRef {

0 commit comments

Comments
 (0)
0