From 0fe346106d2e74ad7f755b49fd020a63fa0f7bf7 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Tue, 30 Nov 2021 03:02:26 +0800 Subject: [PATCH] nac3core: fix converting int to bool (#119) --- nac3core/src/toplevel/composer.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index a8faf130b..a059362a6 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -1,7 +1,7 @@ use std::cell::RefCell; use nac3parser::ast::fold::Fold; -use inkwell::FloatPredicate; +use inkwell::{FloatPredicate, IntPredicate}; use crate::{ symbol_resolver::SymbolValue, @@ -415,15 +415,12 @@ impl TopLevelComposer { if ctx.unifier.unioned(arg_ty, boolean) { Some(arg) } else if ctx.unifier.unioned(arg_ty, int32) || ctx.unifier.unioned(arg_ty, int64) { - Some( - ctx.builder - .build_int_truncate( - arg.into_int_value(), - ctx.ctx.bool_type(), - "trunc", - ) - .into(), - ) + Some(ctx.builder.build_int_compare( + IntPredicate::NE, + ctx.ctx.i64_type().const_zero(), + arg.into_int_value(), + "bool", + ).into()) } else if ctx.unifier.unioned(arg_ty, float) { let val = ctx.builder. build_float_compare(