nac3core: use signed extension to convert i32 to i64

This commit is contained in:
ychenfo 2022-03-06 04:49:02 +08:00
parent 42fbe8e383
commit 8602852241

View File

@ -255,9 +255,7 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
let arg_ty = fun.0.args[0].ty; let arg_ty = fun.0.args[0].ty;
let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?; let arg = args[0].1.clone().to_basic_value_enum(ctx, generator)?;
Ok( Ok(
if ctx.unifier.unioned(arg_ty, boolean) if ctx.unifier.unioned(arg_ty, boolean) {
|| ctx.unifier.unioned(arg_ty, int32)
{
Some( Some(
ctx.builder ctx.builder
.build_int_z_extend( .build_int_z_extend(
@ -267,6 +265,16 @@ pub fn get_builtins(primitives: &mut (PrimitiveStore, Unifier)) -> BuiltinInfo {
) )
.into(), .into(),
) )
} else if ctx.unifier.unioned(arg_ty, int32) {
Some(
ctx.builder
.build_int_s_extend(
arg.into_int_value(),
ctx.ctx.i64_type(),
"sext",
)
.into(),
)
} else if ctx.unifier.unioned(arg_ty, int64) { } else if ctx.unifier.unioned(arg_ty, int64) {
Some(arg) Some(arg)
} else if ctx.unifier.unioned(arg_ty, float) { } else if ctx.unifier.unioned(arg_ty, float) {