mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #4278 from evilpie/jit-none
JIT: add internal support for None
This commit is contained in:
@@ -25,6 +25,7 @@ enum JitValue {
|
||||
Int(Value),
|
||||
Float(Value),
|
||||
Bool(Value),
|
||||
None,
|
||||
}
|
||||
|
||||
impl JitValue {
|
||||
@@ -41,12 +42,14 @@ impl JitValue {
|
||||
JitValue::Int(_) => Some(JitType::Int),
|
||||
JitValue::Float(_) => Some(JitType::Float),
|
||||
JitValue::Bool(_) => Some(JitType::Bool),
|
||||
JitValue::None => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn into_value(self) -> Option<Value> {
|
||||
match self {
|
||||
JitValue::Int(val) | JitValue::Float(val) | JitValue::Bool(val) => Some(val),
|
||||
JitValue::None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,6 +125,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
|
||||
Ok(self.builder.ins().bint(types::I8, val))
|
||||
}
|
||||
JitValue::Bool(val) => Ok(val),
|
||||
JitValue::None => Ok(self.builder.ins().iconst(types::I8, 0)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,6 +197,10 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
|
||||
self.stack.push(JitValue::Bool(val));
|
||||
Ok(())
|
||||
}
|
||||
BorrowedConstant::None => {
|
||||
self.stack.push(JitValue::None);
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(JitCompileError::NotSupported),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,3 +4,4 @@ mod bool_tests;
|
||||
mod float_tests;
|
||||
mod int_tests;
|
||||
mod misc_tests;
|
||||
mod none_tests;
|
||||
|
||||
24
jit/tests/none_tests.rs
Normal file
24
jit/tests/none_tests.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
#[test]
|
||||
fn test_not() {
|
||||
let not_ = jit_function! { not_(x: i64) -> bool => r##"
|
||||
def not_(x: int):
|
||||
return not None
|
||||
"## };
|
||||
|
||||
assert_eq!(not_(0), Ok(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_not() {
|
||||
let if_not = jit_function! { if_not(x: i64) -> i64 => r##"
|
||||
def if_not(x: int):
|
||||
if not None:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
return -1
|
||||
"## };
|
||||
|
||||
assert_eq!(if_not(0), Ok(1));
|
||||
}
|
||||
Reference in New Issue
Block a user