bool support · RustPython/RustPython@70b05cf · GitHub
Skip to content

Commit 70b05cf

Browse files
committed
bool support
1 parent abf5ab4 commit 70b05cf

3 files changed

Lines changed: 39 additions & 9 deletions

File tree

jit/src/instructions.rs

Lines changed: 24 additions & 6 deletions

jit/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,23 @@ impl JitSig {
166166
pub enum JitType {
167167
Int,
168168
Float,
169+
Bool,
169170
}
170171

171172
impl JitType {
172173
fn to_cranelift(&self) -> types::Type {
173174
match self {
174175
Self::Int => types::I64,
175176
Self::Float => types::F64,
177+
Self::Bool => types::I8,
176178
}
177179
}
178180

179181
fn to_libffi(&self) -> libffi::middle::Type {
180182
match self {
181183
Self::Int => libffi::middle::Type::i64(),
182184
Self::Float => libffi::middle::Type::f64(),
185+
Self::Bool => libffi::middle::Type::u8(),
183186
}
184187
}
185188
}
@@ -188,13 +191,15 @@ impl JitType {
188191
pub enum AbiValue {
189192
Float(f64),
190193
Int(i64),
194+
Bool(bool),
191195
}
192196

193197
impl AbiValue {
194198
fn to_libffi_arg(&self) -> libffi::middle::Arg {
195199
match self {
196200
AbiValue::Int(ref i) => libffi::middle::Arg::new(i),
197201
AbiValue::Float(ref f) => libffi::middle::Arg::new(f),
202+
AbiValue::Bool(ref b) => libffi::middle::Arg::new(b),
198203
}
199204
}
200205
}
@@ -217,7 +222,7 @@ impl TryFrom<AbiValue> for i64 {
217222
fn try_from(value: AbiValue) -> Result<Self, Self::Error> {
218223
match value {
219224
AbiValue::Int(i) => Ok(i),
220-
AbiValue::Float(_) => Err(()),
225+
_ => Err(()),
221226
}
222227
}
223228
}
@@ -227,8 +232,8 @@ impl TryFrom<AbiValue> for f64 {
227232

228233
fn try_from(value: AbiValue) -> Result<Self, Self::Error> {
229234
match value {
230-
AbiValue::Int(_) => Err(()),
231235
AbiValue::Float(f) => Ok(f),
236+
_ => Err(()),
232237
}
233238
}
234239
}
@@ -244,6 +249,7 @@ fn type_check(ty: &JitType, val: &AbiValue) -> Result<(), JitArgumentError> {
244249
union UnTypedAbiValue {
245250
float: f64,
246251
int: i64,
252+
boolean: u8,
247253
_void: (),
248254
}
249255

@@ -252,6 +258,7 @@ impl UnTypedAbiValue {
252258
match ty {
253259
JitType::Int => AbiValue::Int(self.int),
254260
JitType::Float => AbiValue::Float(self.float),
261+
JitType::Bool => AbiValue::Bool(self.boolean != 0),
255262
}
256263
}
257264
}

vm/src/builtins/function/jitfunc.rs

Lines changed: 6 additions & 1 deletion

0 commit comments

Comments
 (0)