Implement char to uint cast

This commit is contained in:
bjorn3 2018-07-19 19:37:34 +02:00
parent 1138d38d87
commit bf2c35f05d
3 changed files with 7 additions and 1 deletions

View File

@ -135,6 +135,10 @@ fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize) {
)
}
fn char_cast(c: char) -> u8 {
c as u8
}
struct DebugTuple(());
fn debug_tuple() -> DebugTuple {

View File

@ -298,6 +298,7 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx
(TypeVariants::TyRawPtr(..), TypeVariants::TyRawPtr(..)) => {
lval.write_cvalue(fx, operand.unchecked_cast_to(dest_layout));
}
(TypeVariants::TyChar, TypeVariants::TyUint(_)) |
(TypeVariants::TyUint(_), TypeVariants::TyInt(_)) |
(TypeVariants::TyUint(_), TypeVariants::TyUint(_)) => {
let from = operand.load_value(fx);

View File

@ -48,6 +48,7 @@ pub fn cton_type_from_ty<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>
IntTy::Isize => types::I64,
}
}
TypeVariants::TyChar => types::I32,
TypeVariants::TyFnPtr(_) => types::I64,
TypeVariants::TyRawPtr(TypeAndMut { ty, mutbl: _ }) | TypeVariants::TyRef(_, ty, _) => {
if ty.is_sized(tcx.at(DUMMY_SP), ParamEnv::reveal_all()) {
@ -100,7 +101,7 @@ impl<'tcx> CValue<'tcx> {
pub fn load_value<'a>(self, fx: &mut FunctionCx<'a, 'tcx>) -> Value where 'tcx: 'a{
match self {
CValue::ByRef(addr, layout) => {
let cton_ty = fx.cton_type(layout.ty).expect(&format!("{:?}", layout.ty));
let cton_ty = fx.cton_type(layout.ty).expect(&format!("load_value of type {:?}", layout.ty));
fx.bcx.ins().load(cton_ty, MemFlags::new(), addr, 0)
}
CValue::ByVal(value, _layout) => value,