forked from M-Labs/nac3
WIP6 - gen_string returns StructValue
This commit is contained in:
parent
64741d47bf
commit
fffa0bac27
|
@ -762,11 +762,12 @@ fn polymorphic_print<'ctx>(
|
||||||
});
|
});
|
||||||
|
|
||||||
let fmt = ctx.gen_string(generator, fmt);
|
let fmt = ctx.gen_string(generator, fmt);
|
||||||
|
let fmt = unsafe { fmt.get_field_at_index_unchecked(0) }.into_pointer_value();
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(
|
.build_call(
|
||||||
print_fn,
|
print_fn,
|
||||||
&once(fmt).chain(args).map(BasicValueEnum::into).collect_vec(),
|
&once(fmt.into()).chain(args).map(BasicValueEnum::into).collect_vec(),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -29,6 +29,7 @@ use crate::{
|
||||||
typedef::{FunSignature, FuncArg, Type, TypeEnum, TypeVarId, Unifier, VarMap},
|
typedef::{FunSignature, FuncArg, Type, TypeEnum, TypeVarId, Unifier, VarMap},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
use inkwell::values::StructValue;
|
||||||
use inkwell::{
|
use inkwell::{
|
||||||
attributes::{Attribute, AttributeLoc},
|
attributes::{Attribute, AttributeLoc},
|
||||||
types::{AnyType, BasicType, BasicTypeEnum},
|
types::{AnyType, BasicType, BasicTypeEnum},
|
||||||
|
@ -322,7 +323,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
self.raise_exn(
|
self.raise_exn(
|
||||||
generator,
|
generator,
|
||||||
"0:NotImplementedError",
|
"0:NotImplementedError",
|
||||||
msg,
|
msg.into(),
|
||||||
[None, None, None],
|
[None, None, None],
|
||||||
self.current_loc,
|
self.current_loc,
|
||||||
);
|
);
|
||||||
|
@ -582,12 +583,14 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function for generating a LLVM variable storing a [String].
|
/// Helper function for generating a LLVM variable storing a [String].
|
||||||
pub fn gen_string<G, S>(&mut self, generator: &mut G, s: S) -> BasicValueEnum<'ctx>
|
pub fn gen_string<G, S>(&mut self, generator: &mut G, s: S) -> StructValue<'ctx>
|
||||||
where
|
where
|
||||||
G: CodeGenerator + ?Sized,
|
G: CodeGenerator + ?Sized,
|
||||||
S: Into<String>,
|
S: Into<String>,
|
||||||
{
|
{
|
||||||
self.gen_const(generator, &Constant::Str(s.into()), self.primitives.str).unwrap()
|
self.gen_const(generator, &Constant::Str(s.into()), self.primitives.str)
|
||||||
|
.map(BasicValueEnum::into_struct_value)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raise_exn<G: CodeGenerator + ?Sized>(
|
pub fn raise_exn<G: CodeGenerator + ?Sized>(
|
||||||
|
@ -646,7 +649,7 @@ impl<'ctx, 'a> CodeGenContext<'ctx, 'a> {
|
||||||
loc: Location,
|
loc: Location,
|
||||||
) {
|
) {
|
||||||
let err_msg = self.gen_string(generator, err_msg);
|
let err_msg = self.gen_string(generator, err_msg);
|
||||||
self.make_assert_impl(generator, cond, err_name, err_msg, params, loc);
|
self.make_assert_impl(generator, cond, err_name, err_msg.into(), params, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_assert_impl<G: CodeGenerator + ?Sized>(
|
pub fn make_assert_impl<G: CodeGenerator + ?Sized>(
|
||||||
|
@ -3067,7 +3070,7 @@ pub fn gen_expr<'ctx, G: CodeGenerator>(
|
||||||
ctx.raise_exn(
|
ctx.raise_exn(
|
||||||
generator,
|
generator,
|
||||||
"0:UnwrapNoneError",
|
"0:UnwrapNoneError",
|
||||||
err_msg,
|
err_msg.into(),
|
||||||
[None, None, None],
|
[None, None, None],
|
||||||
ctx.current_loc,
|
ctx.current_loc,
|
||||||
);
|
);
|
||||||
|
|
|
@ -257,7 +257,7 @@ fn ndarray_zero_value<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
} else if ctx.unifier.unioned(elem_ty, ctx.primitives.bool) {
|
} else if ctx.unifier.unioned(elem_ty, ctx.primitives.bool) {
|
||||||
ctx.ctx.bool_type().const_zero().into()
|
ctx.ctx.bool_type().const_zero().into()
|
||||||
} else if ctx.unifier.unioned(elem_ty, ctx.primitives.str) {
|
} else if ctx.unifier.unioned(elem_ty, ctx.primitives.str) {
|
||||||
ctx.gen_string(generator, "")
|
ctx.gen_string(generator, "").into()
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ fn ndarray_one_value<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
} else if ctx.unifier.unioned(elem_ty, ctx.primitives.bool) {
|
} else if ctx.unifier.unioned(elem_ty, ctx.primitives.bool) {
|
||||||
ctx.ctx.bool_type().const_int(1, false).into()
|
ctx.ctx.bool_type().const_int(1, false).into()
|
||||||
} else if ctx.unifier.unioned(elem_ty, ctx.primitives.str) {
|
} else if ctx.unifier.unioned(elem_ty, ctx.primitives.str) {
|
||||||
ctx.gen_string(generator, "1")
|
ctx.gen_string(generator, "1").into()
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1780,7 +1780,7 @@ pub fn gen_stmt<G: CodeGenerator>(
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => ctx.gen_string(generator, ""),
|
None => ctx.gen_string(generator, "").into(),
|
||||||
};
|
};
|
||||||
ctx.make_assert_impl(
|
ctx.make_assert_impl(
|
||||||
generator,
|
generator,
|
||||||
|
|
Loading…
Reference in New Issue