diff --git a/cilly/src/bin/linker/patch.rs b/cilly/src/bin/linker/patch.rs index 220cb568..c77e55e5 100644 --- a/cilly/src/bin/linker/patch.rs +++ b/cilly/src/bin/linker/patch.rs @@ -20,18 +20,18 @@ pub fn call_alias( .iter() .zip(original_inputs.iter()) .enumerate() - .map(|(arg, (tpe, original_tpe))| { - if tpe == original_tpe { + .map(|(arg, (target_type, original_tpe))| { + if target_type == original_tpe { asm.alloc_node(CILNode::LdArg(arg as u32)) } else { - match (tpe, original_tpe) { + match (target_type, original_tpe) { ( Type::Ptr(_) | Type::Int(Int::ISize | Int::USize) | Type::FnPtr(_), Type::ClassRef(_), ) => { // Transmute to a pointer let ptr_address = asm.alloc_node(CILNode::LdArgA(arg as u32)); - let tpe = asm.alloc_type(*tpe); + let tpe = asm.alloc_type(*target_type); asm.alloc_node(CILNode::LdInd { addr: ptr_address, tpe, @@ -50,11 +50,24 @@ pub fn call_alias( extend: cilly::v2::cilnode::ExtendKind::ZeroExtend, }) } + ( + Type::Int(int @ (Int::ISize | Int::USize)), + Type::Int(Int::ISize | Int::USize) + ) => { + let src = asm.alloc_node(CILNode::LdArg(arg as u32)); + asm.alloc_node(CILNode::IntCast { input: src, target:*int, extend:cilly::cilnode::ExtendKind::ZeroExtend }) + + }, ( Type::Ptr(_) | Type::Int(Int::ISize | Int::USize) | Type::FnPtr(_), Type::Ptr(_) | Type::Int(Int::ISize | Int::USize) | Type::FnPtr(_), - ) | (Type::Int(Int::I64),Type::Int(Int::U64)) => asm.alloc_node(CILNode::LdArg(arg as u32)), - _ => todo!("can't auto convert {original_tpe:?} to {tpe:?} when autogenrating wrappers."), + ) => { + + asm.alloc_node(CILNode::LdArg(arg as u32)) + }, + + (Type::Int(Int::I64),Type::Int(Int::U64)) => asm.alloc_node(CILNode::LdArg(arg as u32)), + _ => todo!("can't auto convert {original_tpe:?} to {target_type:?} when autogenrating wrappers."), } } }) diff --git a/cilly/src/v2/builtins/mod.rs b/cilly/src/v2/builtins/mod.rs index c28f9aff..71d6a85f 100644 --- a/cilly/src/v2/builtins/mod.rs +++ b/cilly/src/v2/builtins/mod.rs @@ -248,10 +248,10 @@ pub fn insert_exception(asm: &mut Assembly, patcher: &mut MissingMethodPatcher) false, 0, extends, - vec![(Type::Int(Int::USize), data_pointer, Some(0))], + vec![(Type::Int(Int::USize), data_pointer, None)], vec![], Access::Public, - Some(NonZeroU32::new(8).unwrap()), + None, None, )); let ctor = asm.alloc_string(".ctor"); diff --git a/cilly/src/v2/c_exporter/c_header.h b/cilly/src/v2/c_exporter/c_header.h index 2e34d460..53a33809 100644 --- a/cilly/src/v2/c_exporter/c_header.h +++ b/cilly/src/v2/c_exporter/c_header.h @@ -371,7 +371,10 @@ uint64_t System_UInt64_RotateLeftu8i4u8(uint64_t val, int32_t ammount) fprintf(stderr, "Can't System_UInt64_RotateLeftu8i4u8 yet.\n"); abort(); } - +unsigned __int128 System_UInt128_RotateRightu16i4u16(unsigned __int128 val, int32_t amount){ + fprintf(stderr, "Can't System_UInt128_RotateRightu16i4u16 yet.\n"); + abort(); +} uint8_t System_Byte_RotateLeftu1i4u1(uint8_t val, int32_t ammount) { @@ -380,7 +383,7 @@ uint8_t System_Byte_RotateLeftu1i4u1(uint8_t val, int32_t ammount) } unsigned __int128 System_UInt128_LeadingZeroCountu16u16(unsigned __int128 val) { - fprintf(stderr, "Can't System_Byte_RotateLeftu1i4u1 yet.\n"); + fprintf(stderr, "Can't System_UInt128_LeadingZeroCountu16u16 yet.\n"); abort(); } uint32_t System_Math_Minu4u4u4(uint32_t lhs, uint32_t rhs) diff --git a/cilly/src/v2/c_exporter/mod.rs b/cilly/src/v2/c_exporter/mod.rs index dec989e1..14bf1f60 100644 --- a/cilly/src/v2/c_exporter/mod.rs +++ b/cilly/src/v2/c_exporter/mod.rs @@ -86,7 +86,7 @@ fn c_tpe(field_tpe: Type, asm: &Assembly) -> String { super::Float::F16 => todo!(), super::Float::F32 => "float".into(), super::Float::F64 => "double".into(), - super::Float::F128 => todo!(), + super::Float::F128 => "_Float128".into(), }, Type::PlatformString => "char*".into(), Type::PlatformChar => "char".into(), diff --git a/cilly/src/v2/tpe/mod.rs b/cilly/src/v2/tpe/mod.rs index 74a80193..69cf8767 100644 --- a/cilly/src/v2/tpe/mod.rs +++ b/cilly/src/v2/tpe/mod.rs @@ -214,6 +214,7 @@ impl Type { && cref.asm().map(|s| asm[s].as_ref()) == Some("System.Runtime") && &asm[cref.name()] == "System.UInt128" } + (Type::Int(Int::U16 | Int::I16), Type::PlatformChar) => true, (Type::Ptr(ptr), Type::Ref(rf)) => ptr == rf, // TODO: check generics propely? (_, Type::PlatformGeneric(_, _)) => true, diff --git a/cilly/src/v2/typecheck.rs b/cilly/src/v2/typecheck.rs index c00ffeb6..ba5ed699 100644 --- a/cilly/src/v2/typecheck.rs +++ b/cilly/src/v2/typecheck.rs @@ -97,6 +97,10 @@ pub enum TypeCheckError { got: Type, expected: Type, }, + ValueTypeCompare { + lhs: Type, + rhs: Type, + }, } pub fn typecheck_err_to_string( root_idx: super::RootIdx, @@ -201,7 +205,15 @@ impl BinOp { }, BinOp::Eq => { if lhs == rhs || lhs.is_assignable_to(rhs, asm) { - Ok(Type::Bool) + if let Type::ClassRef(cref) = lhs { + if asm[cref].is_valuetype() { + Err(TypeCheckError::ValueTypeCompare { lhs, rhs }) + } else { + Ok(Type::Bool) + } + } else { + Ok(Type::Bool) + } } else { Err(TypeCheckError::WrongBinopArgs { lhs, diff --git a/src/assembly.rs b/src/assembly.rs index 66701bc2..9efbb59a 100644 --- a/src/assembly.rs +++ b/src/assembly.rs @@ -133,8 +133,8 @@ fn allocation_initializer_method( local: 0, tree: Box::new(call!( asm.alloc_methodref(alloc), - [conv_isize!(CILNode::V2(asm.alloc_node( - i32::try_from(bytes.len()).expect("Static alloc too big") + [CILNode::V2(asm.alloc_node(Const::ISize( + i64::try_from(bytes.len()).expect("Static alloc too big") )))] )) .cast_ptr(asm.nptr(Type::Int(Int::U8))), diff --git a/src/rvalue.rs b/src/rvalue.rs index 132a2d5c..d98c1c02 100644 --- a/src/rvalue.rs +++ b/src/rvalue.rs @@ -86,7 +86,7 @@ pub fn handle_rvalue<'tcx>( } NullOp::AlignOf => { let algin = crate::utilis::align_of(ctx.monomorphize(*ty), ctx.tcx()); - CILNode::V2(ctx.alloc_node(algin)) + CILNode::V2(ctx.alloc_node(Const::USize(algin))) } NullOp::OffsetOf(fields) => { let layout = ctx.layout_of(*ty); @@ -94,7 +94,7 @@ pub fn handle_rvalue<'tcx>( .tcx() .offset_of_subfield(ParamEnv::reveal_all(), layout, fields.iter()) .bytes(); - CILNode::V2(ctx.alloc_node(offset)) + CILNode::V2(ctx.alloc_node(Const::USize(offset))) } rustc_middle::mir::NullOp::UbChecks => { let ub_checks = ctx.tcx().sess.ub_checks();