[core] codegen: Normalize RangeType factory functions
Better matches factory functions of other ProxyTypes.
This commit is contained in:
parent
13aa590429
commit
c36aac323d
@ -800,7 +800,7 @@ pub fn gen_func_impl<
|
|||||||
Some(t) => t.as_basic_type_enum(),
|
Some(t) => t.as_basic_type_enum(),
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
(primitives.range, RangeType::new(context).as_base_type().into()),
|
(primitives.range, RangeType::new_with_generator(generator, context).as_base_type().into()),
|
||||||
(primitives.exception, {
|
(primitives.exception, {
|
||||||
let name = "Exception";
|
let name = "Exception";
|
||||||
if let Some(t) = module.get_struct_type(name) {
|
if let Some(t) = module.get_struct_type(name) {
|
||||||
|
@ -453,8 +453,9 @@ fn test_classes_list_type_new() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_classes_range_type_new() {
|
fn test_classes_range_type_new() {
|
||||||
let ctx = inkwell::context::Context::create();
|
let ctx = inkwell::context::Context::create();
|
||||||
|
let generator = DefaultCodeGenerator::new(String::new(), ctx.i64_type());
|
||||||
|
|
||||||
let llvm_range = RangeType::new(&ctx);
|
let llvm_range = RangeType::new_with_generator(&generator, &ctx);
|
||||||
assert!(RangeType::is_representable(llvm_range.as_base_type()).is_ok());
|
assert!(RangeType::is_representable(llvm_range.as_base_type()).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,12 @@ use inkwell::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::ProxyType;
|
use super::ProxyType;
|
||||||
use crate::codegen::{
|
use crate::{
|
||||||
values::{ProxyValue, RangeValue},
|
codegen::{
|
||||||
{CodeGenContext, CodeGenerator},
|
values::{ProxyValue, RangeValue},
|
||||||
|
{CodeGenContext, CodeGenerator},
|
||||||
|
},
|
||||||
|
typecheck::typedef::{Type, TypeEnum},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Proxy type for a `range` type in LLVM.
|
/// Proxy type for a `range` type in LLVM.
|
||||||
@ -54,12 +57,33 @@ impl<'ctx> RangeType<'ctx> {
|
|||||||
llvm_i32.array_type(3).ptr_type(AddressSpace::default())
|
llvm_i32.array_type(3).ptr_type(AddressSpace::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an instance of [`RangeType`].
|
fn new_impl(ctx: &'ctx Context) -> Self {
|
||||||
#[must_use]
|
|
||||||
pub fn new(ctx: &'ctx Context) -> Self {
|
|
||||||
let llvm_range = Self::llvm_type(ctx);
|
let llvm_range = Self::llvm_type(ctx);
|
||||||
|
|
||||||
RangeType::from_type(llvm_range)
|
RangeType { ty: llvm_range }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates an instance of [`RangeType`].
|
||||||
|
#[must_use]
|
||||||
|
pub fn new(ctx: &CodeGenContext<'ctx, '_>) -> Self {
|
||||||
|
RangeType::new_impl(ctx.ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates an instance of [`RangeType`].
|
||||||
|
#[must_use]
|
||||||
|
pub fn new_with_generator<G: CodeGenerator + ?Sized>(_: &G, ctx: &'ctx Context) -> Self {
|
||||||
|
Self::new_impl(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates an [`RangeType`] from a [unifier type][Type].
|
||||||
|
#[must_use]
|
||||||
|
pub fn from_unifier_type(ctx: &mut CodeGenContext<'ctx, '_>, ty: Type) -> Self {
|
||||||
|
// Check unifier type
|
||||||
|
assert!(
|
||||||
|
matches!(&*ctx.unifier.get_ty_immutable(ty), TypeEnum::TObj { obj_id, .. } if *obj_id == ctx.primitives.range.obj_id(&ctx.unifier).unwrap())
|
||||||
|
);
|
||||||
|
|
||||||
|
Self::new(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an [`RangeType`] from a [`PointerType`].
|
/// Creates an [`RangeType`] from a [`PointerType`].
|
||||||
|
Loading…
Reference in New Issue
Block a user