Fix and test checked binops
This commit is contained in:
parent
4ee2a864b5
commit
b9d7164eff
4 changed files with 19 additions and 2 deletions
2
build.sh
2
build.sh
|
@ -14,7 +14,7 @@ else
|
|||
exit 1
|
||||
fi
|
||||
|
||||
RUSTC="rustc -Zcodegen-backend=$(pwd)/../target/debug/librustc_codegen_cranelift.$dylib_ext -L crate=. -Og"
|
||||
RUSTC="rustc -Zcodegen-backend=$(pwd)/../target/debug/librustc_codegen_cranelift.$dylib_ext -L crate=."
|
||||
|
||||
$RUSTC mini_core.rs --crate-name mini_core --crate-type lib &&
|
||||
$RUSTC example.rs --crate-type lib &&
|
||||
|
|
|
@ -65,6 +65,21 @@ impl Mul for u8 {
|
|||
}
|
||||
}
|
||||
|
||||
#[lang = "add"]
|
||||
pub trait Add<RHS = Self> {
|
||||
type Output;
|
||||
|
||||
fn add(self, rhs: RHS) -> Self::Output;
|
||||
}
|
||||
|
||||
impl Add for u8 {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self {
|
||||
self + rhs
|
||||
}
|
||||
}
|
||||
|
||||
#[lang = "sub"]
|
||||
pub trait Sub<RHS = Self> {
|
||||
type Output;
|
||||
|
|
|
@ -27,7 +27,7 @@ fn start(_main: *const u8, i: isize, _: *const *const u8) -> isize {
|
|||
}
|
||||
|
||||
unsafe {
|
||||
NUM = 43;
|
||||
NUM = 6 * 7 + 5;
|
||||
*NUM_REF as isize
|
||||
}
|
||||
}
|
||||
|
|
|
@ -152,6 +152,8 @@ pub fn trans_fn<'a, 'tcx: 'a>(
|
|||
cleanup: _,
|
||||
} => {
|
||||
let cond = trans_operand(fx, cond).load_value(fx);
|
||||
// TODO HACK brz/brnz for i8/i16 is not yet implemented
|
||||
let cond = fx.bcx.ins().uextend(types::I32, cond);
|
||||
let target = fx.get_ebb(*target);
|
||||
if *expected {
|
||||
fx.bcx.ins().brnz(cond, target, &[]);
|
||||
|
|
Loading…
Add table
Reference in a new issue