Compare commits
4 Commits
b6ded9a869
...
3fc8aa8981
Author | SHA1 | Date |
---|---|---|
lyken | 3fc8aa8981 | |
lyken | 4250a0d15a | |
lyken | 08129cc635 | |
David Mak | ad4832dcf4 |
|
@ -625,6 +625,8 @@ dependencies = [
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"rayon",
|
"rayon",
|
||||||
"regex",
|
"regex",
|
||||||
|
"strum",
|
||||||
|
"strum_macros",
|
||||||
"test-case",
|
"test-case",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1116,6 +1118,25 @@ version = "0.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strum"
|
||||||
|
version = "0.26.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strum_macros"
|
||||||
|
version = "0.26.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
|
||||||
|
dependencies = [
|
||||||
|
"heck 0.5.0",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rustversion",
|
||||||
|
"syn 2.0.66",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
|
|
|
@ -6,7 +6,7 @@ use nac3core::{
|
||||||
CodeGenContext, CodeGenerator,
|
CodeGenContext, CodeGenerator,
|
||||||
},
|
},
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{DefinitionId, GenCall, helper::PRIMITIVE_DEF_IDS},
|
toplevel::{DefinitionId, GenCall, helper::PrimitiveDefinition},
|
||||||
typecheck::typedef::{FunSignature, FuncArg, Type, TypeEnum, VarMap}
|
typecheck::typedef::{FunSignature, FuncArg, Type, TypeEnum, VarMap}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -670,7 +670,7 @@ pub fn attributes_writeback(
|
||||||
vars: VarMap::default()
|
vars: VarMap::default()
|
||||||
};
|
};
|
||||||
let args: Vec<_> = values.into_iter().map(|(_, val)| (None, ValueEnum::Dynamic(val))).collect();
|
let args: Vec<_> = values.into_iter().map(|(_, val)| (None, ValueEnum::Dynamic(val))).collect();
|
||||||
if let Err(e) = rpc_codegen_callback_fn(ctx, None, (&fun, PRIMITIVE_DEF_IDS.int32), args, generator) {
|
if let Err(e) = rpc_codegen_callback_fn(ctx, None, (&fun, PrimitiveDefinition::Int32.id()), args, generator) {
|
||||||
return Ok(Err(e));
|
return Ok(Err(e));
|
||||||
}
|
}
|
||||||
Ok(Ok(()))
|
Ok(Ok(()))
|
||||||
|
|
|
@ -4,7 +4,7 @@ use nac3core::{
|
||||||
symbol_resolver::{StaticValue, SymbolResolver, SymbolValue, ValueEnum},
|
symbol_resolver::{StaticValue, SymbolResolver, SymbolValue, ValueEnum},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
DefinitionId,
|
DefinitionId,
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimitiveDefinition,
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
TopLevelDef,
|
TopLevelDef,
|
||||||
},
|
},
|
||||||
|
@ -468,7 +468,7 @@ impl InnerResolver {
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
if args.len() != 2 {
|
if args.len() != 2 {
|
||||||
return Ok(Err(format!(
|
return Ok(Err(format!(
|
||||||
"type list needs exactly 2 type parameters, found {}",
|
"type list needs exactly 2 type parameters, found {}",
|
||||||
|
@ -664,7 +664,7 @@ impl InnerResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(TypeEnum::TObj { obj_id, .. }, false) if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
(TypeEnum::TObj { obj_id, .. }, false) if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
let (ty, ndims) = unpack_ndarray_var_tys(unifier, extracted_ty);
|
let (ty, ndims) = unpack_ndarray_var_tys(unifier, extracted_ty);
|
||||||
let len: usize = self.helper.len_fn.call1(py, (obj,))?.extract(py)?;
|
let len: usize = self.helper.len_fn.call1(py, (obj,))?.extract(py)?;
|
||||||
if len == 0 {
|
if len == 0 {
|
||||||
|
|
|
@ -11,6 +11,8 @@ indexmap = "2.2"
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
rayon = "1.8"
|
rayon = "1.8"
|
||||||
nac3parser = { path = "../nac3parser" }
|
nac3parser = { path = "../nac3parser" }
|
||||||
|
strum = "0.26.2"
|
||||||
|
strum_macros = "0.26.4"
|
||||||
|
|
||||||
[dependencies.inkwell]
|
[dependencies.inkwell]
|
||||||
version = "0.4"
|
version = "0.4"
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::codegen::{CodeGenContext, CodeGenerator, extern_fns, irrt, llvm_intri
|
||||||
use crate::codegen::classes::{NDArrayValue, UntypedArrayLikeAccessor};
|
use crate::codegen::classes::{NDArrayValue, UntypedArrayLikeAccessor};
|
||||||
use crate::codegen::numpy::ndarray_elementwise_unaryop_impl;
|
use crate::codegen::numpy::ndarray_elementwise_unaryop_impl;
|
||||||
use crate::codegen::stmt::gen_for_callback_incrementing;
|
use crate::codegen::stmt::gen_for_callback_incrementing;
|
||||||
use crate::toplevel::helper::PRIMITIVE_DEF_IDS;
|
use crate::toplevel::helper::PrimitiveDefinition;
|
||||||
use crate::toplevel::numpy::unpack_ndarray_var_tys;
|
use crate::toplevel::numpy::unpack_ndarray_var_tys;
|
||||||
use crate::typecheck::typedef::Type;
|
use crate::typecheck::typedef::Type;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ pub fn call_int32<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -150,7 +150,7 @@ pub fn call_int64<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -237,7 +237,7 @@ pub fn call_uint32<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -318,7 +318,7 @@ pub fn call_uint64<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -383,7 +383,7 @@ pub fn call_float<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
n.into()
|
n.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -429,7 +429,7 @@ pub fn call_round<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -469,7 +469,7 @@ pub fn call_numpy_round<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_roundeven(ctx, n, None).into()
|
llvm_intrinsics::call_float_roundeven(ctx, n, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -532,7 +532,7 @@ pub fn call_bool<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -588,7 +588,7 @@ pub fn call_floor<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -638,7 +638,7 @@ pub fn call_ceil<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -732,7 +732,7 @@ pub fn call_numpy_min<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if a_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if a_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, a_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, a_ty);
|
||||||
let llvm_ndarray_ty = ctx.get_llvm_type(generator, elem_ty);
|
let llvm_ndarray_ty = ctx.get_llvm_type(generator, elem_ty);
|
||||||
|
|
||||||
|
@ -830,11 +830,11 @@ pub fn call_numpy_minimum<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
call_min(ctx, (x1_ty, x1.into()), (x2_ty, x2.into()))
|
call_min(ctx, (x1_ty, x1.into()), (x2_ty, x2.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 && is_ndarray2 {
|
let dtype = if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
||||||
|
@ -950,7 +950,7 @@ pub fn call_numpy_max<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if a_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if a_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, a_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, a_ty);
|
||||||
let llvm_ndarray_ty = ctx.get_llvm_type(generator, elem_ty);
|
let llvm_ndarray_ty = ctx.get_llvm_type(generator, elem_ty);
|
||||||
|
|
||||||
|
@ -1048,11 +1048,11 @@ pub fn call_numpy_maximum<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
call_max(ctx, (x1_ty, x1.into()), (x2_ty, x2.into()))
|
call_max(ctx, (x1_ty, x1.into()), (x2_ty, x2.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 && is_ndarray2 {
|
let dtype = if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
||||||
|
@ -1139,7 +1139,7 @@ pub fn call_abs<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_fabs(ctx, n, Some(FN_NAME)).into()
|
llvm_intrinsics::call_float_fabs(ctx, n, Some(FN_NAME)).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, n_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1179,7 +1179,7 @@ pub fn call_numpy_isnan<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
irrt::call_isnan(generator, ctx, x).into()
|
irrt::call_isnan(generator, ctx, x).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1221,7 +1221,7 @@ pub fn call_numpy_isinf<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
irrt::call_isinf(generator, ctx, x).into()
|
irrt::call_isinf(generator, ctx, x).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1263,7 +1263,7 @@ pub fn call_numpy_sin<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_sin(ctx, x, None).into()
|
llvm_intrinsics::call_float_sin(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1303,7 +1303,7 @@ pub fn call_numpy_cos<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_cos(ctx, x, None).into()
|
llvm_intrinsics::call_float_cos(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1343,7 +1343,7 @@ pub fn call_numpy_exp<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_exp(ctx, x, None).into()
|
llvm_intrinsics::call_float_exp(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1383,7 +1383,7 @@ pub fn call_numpy_exp2<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_exp2(ctx, x, None).into()
|
llvm_intrinsics::call_float_exp2(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1423,7 +1423,7 @@ pub fn call_numpy_log<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_log(ctx, x, None).into()
|
llvm_intrinsics::call_float_log(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1463,7 +1463,7 @@ pub fn call_numpy_log10<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_log10(ctx, x, None).into()
|
llvm_intrinsics::call_float_log10(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1503,7 +1503,7 @@ pub fn call_numpy_log2<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_log2(ctx, x, None).into()
|
llvm_intrinsics::call_float_log2(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1543,7 +1543,7 @@ pub fn call_numpy_fabs<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_fabs(ctx, x, None).into()
|
llvm_intrinsics::call_float_fabs(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1583,7 +1583,7 @@ pub fn call_numpy_sqrt<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_sqrt(ctx, x, None).into()
|
llvm_intrinsics::call_float_sqrt(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1623,7 +1623,7 @@ pub fn call_numpy_rint<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_roundeven(ctx, x, None).into()
|
llvm_intrinsics::call_float_roundeven(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1663,7 +1663,7 @@ pub fn call_numpy_tan<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_tan(ctx, x, None).into()
|
extern_fns::call_tan(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1703,7 +1703,7 @@ pub fn call_numpy_arcsin<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_asin(ctx, x, None).into()
|
extern_fns::call_asin(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1743,7 +1743,7 @@ pub fn call_numpy_arccos<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_acos(ctx, x, None).into()
|
extern_fns::call_acos(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1783,7 +1783,7 @@ pub fn call_numpy_arctan<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_atan(ctx, x, None).into()
|
extern_fns::call_atan(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1823,7 +1823,7 @@ pub fn call_numpy_sinh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_sinh(ctx, x, None).into()
|
extern_fns::call_sinh(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1863,7 +1863,7 @@ pub fn call_numpy_cosh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_cosh(ctx, x, None).into()
|
extern_fns::call_cosh(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1903,7 +1903,7 @@ pub fn call_numpy_tanh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_tanh(ctx, x, None).into()
|
extern_fns::call_tanh(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1943,7 +1943,7 @@ pub fn call_numpy_arcsinh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_asinh(ctx, x, None).into()
|
extern_fns::call_asinh(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -1983,7 +1983,7 @@ pub fn call_numpy_arccosh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_acosh(ctx, x, None).into()
|
extern_fns::call_acosh(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2023,7 +2023,7 @@ pub fn call_numpy_arctanh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_atanh(ctx, x, None).into()
|
extern_fns::call_atanh(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2063,7 +2063,7 @@ pub fn call_numpy_expm1<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_expm1(ctx, x, None).into()
|
extern_fns::call_expm1(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2103,7 +2103,7 @@ pub fn call_numpy_cbrt<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_cbrt(ctx, x, None).into()
|
extern_fns::call_cbrt(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2143,7 +2143,7 @@ pub fn call_scipy_special_erf<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_erf(ctx, z, None).into()
|
extern_fns::call_erf(ctx, z, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(z) if z_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(z) if z_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, z_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, z_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2183,7 +2183,7 @@ pub fn call_scipy_special_erfc<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_erfc(ctx, x, None).into()
|
extern_fns::call_erfc(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2223,7 +2223,7 @@ pub fn call_scipy_special_gamma<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
irrt::call_gamma(ctx, z).into()
|
irrt::call_gamma(ctx, z).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(z) if z_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(z) if z_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, z_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, z_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2263,7 +2263,7 @@ pub fn call_scipy_special_gammaln<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
irrt::call_gammaln(ctx, x).into()
|
irrt::call_gammaln(ctx, x).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2303,7 +2303,7 @@ pub fn call_scipy_special_j0<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
irrt::call_j0(ctx, x).into()
|
irrt::call_j0(ctx, x).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2343,7 +2343,7 @@ pub fn call_scipy_special_j1<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_j1(ctx, x, None).into()
|
extern_fns::call_j1(ctx, x, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) => {
|
||||||
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
let (elem_ty, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x_ty);
|
||||||
|
|
||||||
let ndarray = ndarray_elementwise_unaryop_impl(
|
let ndarray = ndarray_elementwise_unaryop_impl(
|
||||||
|
@ -2384,11 +2384,11 @@ pub fn call_numpy_arctan2<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_atan2(ctx, x1, x2, None).into()
|
extern_fns::call_atan2(ctx, x1, x2, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 && is_ndarray2 {
|
let dtype = if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
||||||
|
@ -2451,11 +2451,11 @@ pub fn call_numpy_copysign<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_copysign(ctx, x1, x2, None).into()
|
llvm_intrinsics::call_float_copysign(ctx, x1, x2, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 && is_ndarray2 {
|
let dtype = if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
||||||
|
@ -2518,11 +2518,11 @@ pub fn call_numpy_fmax<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_maxnum(ctx, x1, x2, None).into()
|
llvm_intrinsics::call_float_maxnum(ctx, x1, x2, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 && is_ndarray2 {
|
let dtype = if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
||||||
|
@ -2585,11 +2585,11 @@ pub fn call_numpy_fmin<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
llvm_intrinsics::call_float_minnum(ctx, x1, x2, None).into()
|
llvm_intrinsics::call_float_minnum(ctx, x1, x2, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 && is_ndarray2 {
|
let dtype = if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
||||||
|
@ -2652,11 +2652,11 @@ pub fn call_numpy_ldexp<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_ldexp(ctx, x1, x2, None).into()
|
extern_fns::call_ldexp(ctx, x1, x2, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 {
|
let dtype = if is_ndarray1 {
|
||||||
unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty).0
|
unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty).0
|
||||||
|
@ -2708,11 +2708,11 @@ pub fn call_numpy_hypot<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_hypot(ctx, x1, x2, None).into()
|
extern_fns::call_hypot(ctx, x1, x2, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 && is_ndarray2 {
|
let dtype = if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
||||||
|
@ -2775,11 +2775,11 @@ pub fn call_numpy_nextafter<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
extern_fns::call_nextafter(ctx, x1, x2, None).into()
|
extern_fns::call_nextafter(ctx, x1, x2, None).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) => {
|
||||||
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = x1_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = x2_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
let dtype = if is_ndarray1 && is_ndarray2 {
|
let dtype = if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty);
|
||||||
|
|
|
@ -25,7 +25,7 @@ use crate::{
|
||||||
symbol_resolver::{SymbolValue, ValueEnum},
|
symbol_resolver::{SymbolValue, ValueEnum},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
DefinitionId,
|
DefinitionId,
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimitiveDefinition,
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
TopLevelDef,
|
TopLevelDef,
|
||||||
},
|
},
|
||||||
|
@ -1132,13 +1132,13 @@ pub fn gen_binop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
Some("f_pow_i")
|
Some("f_pow_i")
|
||||||
);
|
);
|
||||||
Ok(Some(res.into()))
|
Ok(Some(res.into()))
|
||||||
} else if ty1.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) || ty2.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
} else if ty1.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) || ty2.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
let llvm_usize = generator.get_size_type(ctx.ctx);
|
let llvm_usize = generator.get_size_type(ctx.ctx);
|
||||||
|
|
||||||
let is_ndarray1 = ty1.obj_id(&ctx.unifier)
|
let is_ndarray1 = ty1.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = ty2.obj_id(&ctx.unifier)
|
let is_ndarray2 = ty2.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
if is_ndarray1 && is_ndarray2 {
|
if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, ty1);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, ty1);
|
||||||
|
@ -1372,7 +1372,7 @@ pub fn gen_unaryop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
_ => val.into(),
|
_ => val.into(),
|
||||||
}
|
}
|
||||||
} else if ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
} else if ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
let llvm_usize = generator.get_size_type(ctx.ctx);
|
let llvm_usize = generator.get_size_type(ctx.ctx);
|
||||||
let (ndarray_dtype, _) = unpack_ndarray_var_tys(&mut ctx.unifier, ty);
|
let (ndarray_dtype, _) = unpack_ndarray_var_tys(&mut ctx.unifier, ty);
|
||||||
|
|
||||||
|
@ -1384,7 +1384,7 @@ pub fn gen_unaryop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
|
|
||||||
// ndarray uses `~` rather than `not` to perform elementwise inversion, convert it before
|
// ndarray uses `~` rather than `not` to perform elementwise inversion, convert it before
|
||||||
// passing it to the elementwise codegen function
|
// passing it to the elementwise codegen function
|
||||||
let op = if ndarray_dtype.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.bool) {
|
let op = if ndarray_dtype.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::Bool.id()) {
|
||||||
if *op == ast::Unaryop::Invert {
|
if *op == ast::Unaryop::Invert {
|
||||||
&ast::Unaryop::Not
|
&ast::Unaryop::Not
|
||||||
} else {
|
} else {
|
||||||
|
@ -1450,7 +1450,7 @@ pub fn gen_cmpop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
let left_ty = ctx.unifier.get_representative(left.0.unwrap());
|
let left_ty = ctx.unifier.get_representative(left.0.unwrap());
|
||||||
let right_ty = ctx.unifier.get_representative(comparators[0].0.unwrap());
|
let right_ty = ctx.unifier.get_representative(comparators[0].0.unwrap());
|
||||||
|
|
||||||
if left_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) || right_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
if left_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) || right_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
let llvm_usize = generator.get_size_type(ctx.ctx);
|
let llvm_usize = generator.get_size_type(ctx.ctx);
|
||||||
|
|
||||||
let (Some(left_ty), lhs) = left else { unreachable!() };
|
let (Some(left_ty), lhs) = left else { unreachable!() };
|
||||||
|
@ -1458,9 +1458,9 @@ pub fn gen_cmpop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
let op = ops[0].clone();
|
let op = ops[0].clone();
|
||||||
|
|
||||||
let is_ndarray1 = left_ty.obj_id(&ctx.unifier)
|
let is_ndarray1 = left_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_ndarray2 = right_ty.obj_id(&ctx.unifier)
|
let is_ndarray2 = right_ty.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
return if is_ndarray1 && is_ndarray2 {
|
return if is_ndarray1 && is_ndarray2 {
|
||||||
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, left_ty);
|
let (ndarray_dtype1, _) = unpack_ndarray_var_tys(&mut ctx.unifier, left_ty);
|
||||||
|
@ -2451,7 +2451,7 @@ pub fn gen_expr<'ctx, G: CodeGenerator>(
|
||||||
v.data().get(ctx, generator, &index, None).into()
|
v.data().get(ctx, generator, &index, None).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, params, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, params, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
let (ty, ndims) = params.iter()
|
let (ty, ndims) = params.iter()
|
||||||
.map(|(_, ty)| ty)
|
.map(|(_, ty)| ty)
|
||||||
.collect_tuple()
|
.collect_tuple()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use inkwell::AddressSpace;
|
use inkwell::AddressSpace;
|
||||||
use inkwell::context::Context;
|
use inkwell::context::Context;
|
||||||
|
use inkwell::intrinsics::Intrinsic;
|
||||||
use inkwell::types::AnyTypeEnum::IntType;
|
use inkwell::types::AnyTypeEnum::IntType;
|
||||||
use inkwell::types::FloatType;
|
use inkwell::types::FloatType;
|
||||||
use inkwell::values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue, PointerValue};
|
use inkwell::values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue, PointerValue};
|
||||||
|
@ -42,14 +43,9 @@ pub fn call_stacksave<'ctx>(
|
||||||
) -> PointerValue<'ctx> {
|
) -> PointerValue<'ctx> {
|
||||||
const FN_NAME: &str = "llvm.stacksave";
|
const FN_NAME: &str = "llvm.stacksave";
|
||||||
|
|
||||||
let intrinsic_fn = ctx.module.get_function(FN_NAME).unwrap_or_else(|| {
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let llvm_i8 = ctx.ctx.i8_type();
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[]))
|
||||||
let llvm_p0i8 = llvm_i8.ptr_type(AddressSpace::default());
|
.unwrap();
|
||||||
|
|
||||||
let fn_type = llvm_p0i8.fn_type(&[], false);
|
|
||||||
|
|
||||||
ctx.module.add_function(FN_NAME, fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[], name.unwrap_or_default())
|
||||||
|
@ -61,18 +57,17 @@ pub fn call_stacksave<'ctx>(
|
||||||
|
|
||||||
/// Invokes the
|
/// Invokes the
|
||||||
/// [`llvm.stackrestore`](https://llvm.org/docs/LangRef.html#llvm-stackrestore-intrinsic) intrinsic.
|
/// [`llvm.stackrestore`](https://llvm.org/docs/LangRef.html#llvm-stackrestore-intrinsic) intrinsic.
|
||||||
|
///
|
||||||
|
/// - `ptr`: The pointer storing the address to restore the stack to.
|
||||||
pub fn call_stackrestore<'ctx>(ctx: &CodeGenContext<'ctx, '_>, ptr: PointerValue<'ctx>) {
|
pub fn call_stackrestore<'ctx>(ctx: &CodeGenContext<'ctx, '_>, ptr: PointerValue<'ctx>) {
|
||||||
const FN_NAME: &str = "llvm.stackrestore";
|
const FN_NAME: &str = "llvm.stackrestore";
|
||||||
|
|
||||||
let intrinsic_fn = ctx.module.get_function(FN_NAME).unwrap_or_else(|| {
|
let llvm_i8 = ctx.ctx.i8_type();
|
||||||
let llvm_void = ctx.ctx.void_type();
|
let llvm_p0i8 = llvm_i8.ptr_type(AddressSpace::default());
|
||||||
let llvm_i8 = ctx.ctx.i8_type();
|
|
||||||
let llvm_p0i8 = llvm_i8.ptr_type(AddressSpace::default());
|
|
||||||
|
|
||||||
let fn_type = llvm_void.fn_type(&[llvm_p0i8.into()], false);
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_p0i8.into()]))
|
||||||
ctx.module.add_function(FN_NAME, fn_type, None)
|
.unwrap();
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[ptr.into()], "")
|
.build_call(intrinsic_fn, &[ptr.into()], "")
|
||||||
|
@ -89,20 +84,16 @@ pub fn call_int_abs<'ctx>(
|
||||||
is_int_min_poison: IntValue<'ctx>,
|
is_int_min_poison: IntValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> IntValue<'ctx> {
|
) -> IntValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.abs";
|
||||||
|
|
||||||
debug_assert_eq!(is_int_min_poison.get_type().get_bit_width(), 1);
|
debug_assert_eq!(is_int_min_poison.get_type().get_bit_width(), 1);
|
||||||
debug_assert!(is_int_min_poison.is_const());
|
debug_assert!(is_int_min_poison.is_const());
|
||||||
|
|
||||||
let llvm_src_t = src.get_type();
|
let llvm_src_t = src.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.abs.i{}", llvm_src_t.get_bit_width());
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_src_t.into()]))
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.unwrap();
|
||||||
let llvm_i1 = ctx.ctx.bool_type();
|
|
||||||
|
|
||||||
let fn_type = llvm_src_t.fn_type(&[llvm_src_t.into(), llvm_i1.into()], false);
|
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[src.into(), is_int_min_poison.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[src.into(), is_int_min_poison.into()], name.unwrap_or_default())
|
||||||
|
@ -119,17 +110,15 @@ pub fn call_int_smax<'ctx>(
|
||||||
b: IntValue<'ctx>,
|
b: IntValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> IntValue<'ctx> {
|
) -> IntValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.smax";
|
||||||
|
|
||||||
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
||||||
|
|
||||||
let llvm_int_t = a.get_type();
|
let llvm_int_t = a.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.smax.i{}", llvm_int_t.get_bit_width());
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.unwrap();
|
||||||
let fn_type = llvm_int_t.fn_type(&[llvm_int_t.into(), llvm_int_t.into()], false);
|
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
||||||
|
@ -146,17 +135,15 @@ pub fn call_int_smin<'ctx>(
|
||||||
b: IntValue<'ctx>,
|
b: IntValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> IntValue<'ctx> {
|
) -> IntValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.smin";
|
||||||
|
|
||||||
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
||||||
|
|
||||||
let llvm_int_t = a.get_type();
|
let llvm_int_t = a.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.smin.i{}", llvm_int_t.get_bit_width());
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.unwrap();
|
||||||
let fn_type = llvm_int_t.fn_type(&[llvm_int_t.into(), llvm_int_t.into()], false);
|
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
||||||
|
@ -173,17 +160,15 @@ pub fn call_int_umax<'ctx>(
|
||||||
b: IntValue<'ctx>,
|
b: IntValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> IntValue<'ctx> {
|
) -> IntValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.umax";
|
||||||
|
|
||||||
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
||||||
|
|
||||||
let llvm_int_t = a.get_type();
|
let llvm_int_t = a.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.umax.i{}", llvm_int_t.get_bit_width());
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.unwrap();
|
||||||
let fn_type = llvm_int_t.fn_type(&[llvm_int_t.into(), llvm_int_t.into()], false);
|
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
||||||
|
@ -200,17 +185,15 @@ pub fn call_int_umin<'ctx>(
|
||||||
b: IntValue<'ctx>,
|
b: IntValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> IntValue<'ctx> {
|
) -> IntValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.umin";
|
||||||
|
|
||||||
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
||||||
|
|
||||||
let llvm_int_t = a.get_type();
|
let llvm_int_t = a.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.umin.i{}", llvm_int_t.get_bit_width());
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.unwrap();
|
||||||
let fn_type = llvm_int_t.fn_type(&[llvm_int_t.into(), llvm_int_t.into()], false);
|
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
||||||
|
@ -233,6 +216,8 @@ pub fn call_memcpy<'ctx>(
|
||||||
len: IntValue<'ctx>,
|
len: IntValue<'ctx>,
|
||||||
is_volatile: IntValue<'ctx>,
|
is_volatile: IntValue<'ctx>,
|
||||||
) {
|
) {
|
||||||
|
const FN_NAME: &str = "llvm.memcpy";
|
||||||
|
|
||||||
debug_assert!(dest.get_type().get_element_type().is_int_type());
|
debug_assert!(dest.get_type().get_element_type().is_int_type());
|
||||||
debug_assert!(src.get_type().get_element_type().is_int_type());
|
debug_assert!(src.get_type().get_element_type().is_int_type());
|
||||||
debug_assert_eq!(
|
debug_assert_eq!(
|
||||||
|
@ -246,28 +231,12 @@ pub fn call_memcpy<'ctx>(
|
||||||
let llvm_src_t = src.get_type();
|
let llvm_src_t = src.get_type();
|
||||||
let llvm_len_t = len.get_type();
|
let llvm_len_t = len.get_type();
|
||||||
|
|
||||||
let fn_name = format!(
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
"llvm.memcpy.p0i{}.p0i{}.i{}",
|
.and_then(|intrinsic| intrinsic.get_declaration(
|
||||||
llvm_dest_t.get_element_type().into_int_type().get_bit_width(),
|
&ctx.module,
|
||||||
llvm_src_t.get_element_type().into_int_type().get_bit_width(),
|
&[llvm_dest_t.into(), llvm_src_t.into(), llvm_len_t.into()],
|
||||||
llvm_len_t.get_bit_width(),
|
))
|
||||||
);
|
.unwrap();
|
||||||
|
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
|
||||||
let llvm_void = ctx.ctx.void_type();
|
|
||||||
|
|
||||||
let fn_type = llvm_void.fn_type(
|
|
||||||
&[
|
|
||||||
llvm_dest_t.into(),
|
|
||||||
llvm_src_t.into(),
|
|
||||||
llvm_len_t.into(),
|
|
||||||
is_volatile.get_type().into(),
|
|
||||||
],
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[dest.into(), src.into(), len.into(), is_volatile.into()], "")
|
.build_call(intrinsic_fn, &[dest.into(), src.into(), len.into(), is_volatile.into()], "")
|
||||||
|
@ -317,14 +286,13 @@ pub fn call_float_sqrt<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.sqrt";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.sqrt.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -341,19 +309,17 @@ pub fn call_float_powi<'ctx>(
|
||||||
power: IntValue<'ctx>,
|
power: IntValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.powi";
|
||||||
|
|
||||||
let llvm_val_t = val.get_type();
|
let llvm_val_t = val.get_type();
|
||||||
let llvm_power_t = power.get_type();
|
let llvm_power_t = power.get_type();
|
||||||
|
|
||||||
let fn_name = format!(
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
"llvm.powi.{}.i{}",
|
.and_then(|intrinsic| intrinsic.get_declaration(
|
||||||
get_float_intrinsic_repr(ctx.ctx, llvm_val_t),
|
&ctx.module,
|
||||||
llvm_power_t.get_bit_width(),
|
&[llvm_val_t.into(), llvm_power_t.into()],
|
||||||
);
|
))
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.unwrap();
|
||||||
let fn_type = llvm_val_t.fn_type(&[llvm_val_t.into(), llvm_power_t.into()], false);
|
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into(), power.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into(), power.into()], name.unwrap_or_default())
|
||||||
|
@ -369,14 +335,13 @@ pub fn call_float_sin<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.sin";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.sin.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -392,14 +357,13 @@ pub fn call_float_cos<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.cos";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.cos.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -416,16 +380,15 @@ pub fn call_float_pow<'ctx>(
|
||||||
power: FloatValue<'ctx>,
|
power: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.pow";
|
||||||
|
|
||||||
debug_assert_eq!(val.get_type(), power.get_type());
|
debug_assert_eq!(val.get_type(), power.get_type());
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.pow.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into(), llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into(), power.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into(), power.into()], name.unwrap_or_default())
|
||||||
|
@ -441,14 +404,13 @@ pub fn call_float_exp<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.exp";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.exp.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -464,14 +426,13 @@ pub fn call_float_exp2<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.exp2";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.exp2.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -488,14 +449,13 @@ pub fn call_float_log<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.log";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.log.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -511,14 +471,13 @@ pub fn call_float_log10<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.log10";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.log10.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -534,14 +493,13 @@ pub fn call_float_log2<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.log2";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.log2.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -557,15 +515,13 @@ pub fn call_float_fabs<'ctx>(
|
||||||
src: FloatValue<'ctx>,
|
src: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.fabs";
|
||||||
|
|
||||||
let llvm_src_t = src.get_type();
|
let llvm_src_t = src.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.fabs.{}", get_float_intrinsic_repr(ctx.ctx, llvm_src_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_src_t.into()]))
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.unwrap();
|
||||||
let fn_type = llvm_src_t.fn_type(&[llvm_src_t.into()], false);
|
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[src.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[src.into()], name.unwrap_or_default())
|
||||||
|
@ -582,16 +538,15 @@ pub fn call_float_minnum<'ctx>(
|
||||||
val2: FloatValue<'ctx>,
|
val2: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.minnum";
|
||||||
|
|
||||||
debug_assert_eq!(val1.get_type(), val2.get_type());
|
debug_assert_eq!(val1.get_type(), val2.get_type());
|
||||||
|
|
||||||
let llvm_float_t = val1.get_type();
|
let llvm_float_t = val1.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.minnum.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into(), llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val1.into(), val2.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val1.into(), val2.into()], name.unwrap_or_default())
|
||||||
|
@ -608,16 +563,15 @@ pub fn call_float_maxnum<'ctx>(
|
||||||
val2: FloatValue<'ctx>,
|
val2: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.maxnum";
|
||||||
|
|
||||||
debug_assert_eq!(val1.get_type(), val2.get_type());
|
debug_assert_eq!(val1.get_type(), val2.get_type());
|
||||||
|
|
||||||
let llvm_float_t = val1.get_type();
|
let llvm_float_t = val1.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.maxnum.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into(), llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val1.into(), val2.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val1.into(), val2.into()], name.unwrap_or_default())
|
||||||
|
@ -634,16 +588,15 @@ pub fn call_float_copysign<'ctx>(
|
||||||
sgn: FloatValue<'ctx>,
|
sgn: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.copysign";
|
||||||
|
|
||||||
debug_assert_eq!(mag.get_type(), sgn.get_type());
|
debug_assert_eq!(mag.get_type(), sgn.get_type());
|
||||||
|
|
||||||
let llvm_float_t = mag.get_type();
|
let llvm_float_t = mag.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.copysign.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into(), llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[mag.into(), sgn.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[mag.into(), sgn.into()], name.unwrap_or_default())
|
||||||
|
@ -659,14 +612,13 @@ pub fn call_float_floor<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.floor";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.floor.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -682,14 +634,13 @@ pub fn call_float_ceil<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.ceil";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.ceil.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -705,14 +656,13 @@ pub fn call_float_round<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.round";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.round.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -729,14 +679,13 @@ pub fn call_float_roundeven<'ctx>(
|
||||||
val: FloatValue<'ctx>,
|
val: FloatValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> FloatValue<'ctx> {
|
) -> FloatValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.roundeven";
|
||||||
|
|
||||||
let llvm_float_t = val.get_type();
|
let llvm_float_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.roundeven.{}", get_float_intrinsic_repr(ctx.ctx, llvm_float_t));
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
||||||
let fn_type = llvm_float_t.fn_type(&[llvm_float_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
||||||
|
@ -753,16 +702,15 @@ pub fn call_expect<'ctx>(
|
||||||
expected_val: IntValue<'ctx>,
|
expected_val: IntValue<'ctx>,
|
||||||
name: Option<&str>,
|
name: Option<&str>,
|
||||||
) -> IntValue<'ctx> {
|
) -> IntValue<'ctx> {
|
||||||
|
const FN_NAME: &str = "llvm.expect";
|
||||||
|
|
||||||
debug_assert_eq!(val.get_type().get_bit_width(), expected_val.get_type().get_bit_width());
|
debug_assert_eq!(val.get_type().get_bit_width(), expected_val.get_type().get_bit_width());
|
||||||
|
|
||||||
let llvm_int_t = val.get_type();
|
let llvm_int_t = val.get_type();
|
||||||
|
|
||||||
let fn_name = format!("llvm.expect.i{}", llvm_int_t.get_bit_width());
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
||||||
let intrinsic_fn = ctx.module.get_function(fn_name.as_str()).unwrap_or_else(|| {
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
||||||
let fn_type = llvm_int_t.fn_type(&[llvm_int_t.into(), llvm_int_t.into()], false);
|
.unwrap();
|
||||||
|
|
||||||
ctx.module.add_function(fn_name.as_str(), fn_type, None)
|
|
||||||
});
|
|
||||||
|
|
||||||
ctx.builder
|
ctx.builder
|
||||||
.build_call(intrinsic_fn, &[val.into(), expected_val.into()], name.unwrap_or_default())
|
.build_call(intrinsic_fn, &[val.into(), expected_val.into()], name.unwrap_or_default())
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
symbol_resolver::{StaticValue, SymbolResolver},
|
symbol_resolver::{StaticValue, SymbolResolver},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimitiveDefinition,
|
||||||
numpy::unpack_ndarray_var_tys,
|
numpy::unpack_ndarray_var_tys,
|
||||||
TopLevelContext,
|
TopLevelContext,
|
||||||
TopLevelDef,
|
TopLevelDef,
|
||||||
},
|
},
|
||||||
|
@ -435,9 +435,9 @@ fn get_llvm_type<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
let result = match &*ty_enum {
|
let result = match &*ty_enum {
|
||||||
TObj { obj_id, fields, .. } => {
|
TObj { obj_id, fields, .. } => {
|
||||||
// check to avoid treating non-class primitives as classes
|
// check to avoid treating non-class primitives as classes
|
||||||
if obj_id.0 <= PRIMITIVE_DEF_IDS.max_id().0 {
|
if PrimitiveDefinition::contains_id(*obj_id) {
|
||||||
return match &*unifier.get_ty_immutable(ty) {
|
return match &*unifier.get_ty_immutable(ty) {
|
||||||
TObj { obj_id, params, .. } if *obj_id == PRIMITIVE_DEF_IDS.option => {
|
TObj { obj_id, params, .. } if *obj_id == PrimitiveDefinition::Option.id() => {
|
||||||
get_llvm_type(
|
get_llvm_type(
|
||||||
ctx,
|
ctx,
|
||||||
module,
|
module,
|
||||||
|
@ -451,7 +451,7 @@ fn get_llvm_type<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
let llvm_usize = generator.get_size_type(ctx);
|
let llvm_usize = generator.get_size_type(ctx);
|
||||||
let (dtype, _) = unpack_ndarray_var_tys(unifier, ty);
|
let (dtype, _) = unpack_ndarray_var_tys(unifier, ty);
|
||||||
let element_type = get_llvm_type(
|
let element_type = get_llvm_type(
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
DefinitionId,
|
DefinitionId,
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimitiveDefinition,
|
||||||
numpy::unpack_ndarray_var_tys,
|
numpy::unpack_ndarray_var_tys,
|
||||||
TopLevelDef,
|
TopLevelDef,
|
||||||
},
|
},
|
||||||
|
@ -192,7 +192,7 @@ pub fn gen_store_target<'ctx, G: CodeGenerator>(
|
||||||
v.data().ptr_offset(ctx, generator, &index, name)
|
v.data().ptr_offset(ctx, generator, &index, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ pub fn gen_assign<'ctx, G: CodeGenerator>(
|
||||||
let value = ListValue::from_ptr_val(value, llvm_usize, None);
|
let value = ListValue::from_ptr_val(value, llvm_usize, None);
|
||||||
let ty = match &*ctx.unifier.get_ty_immutable(target.custom.unwrap()) {
|
let ty = match &*ctx.unifier.get_ty_immutable(target.custom.unwrap()) {
|
||||||
TypeEnum::TList { ty } => *ty,
|
TypeEnum::TList { ty } => *ty,
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
unpack_ndarray_var_tys(&mut ctx.unifier, target.custom.unwrap()).0
|
unpack_ndarray_var_tys(&mut ctx.unifier, target.custom.unwrap()).0
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
|
|
@ -20,7 +20,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
symbol_resolver::SymbolValue,
|
symbol_resolver::SymbolValue,
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimitiveDefinition,
|
||||||
numpy::make_ndarray_ty,
|
numpy::make_ndarray_ty,
|
||||||
},
|
},
|
||||||
typecheck::typedef::VarMap,
|
typecheck::typedef::VarMap,
|
||||||
|
@ -90,7 +90,7 @@ pub fn get_exn_constructor(
|
||||||
methods: vec![("__init__".into(), signature, DefinitionId(cons_id))],
|
methods: vec![("__init__".into(), signature, DefinitionId(cons_id))],
|
||||||
ancestors: vec![
|
ancestors: vec![
|
||||||
TypeAnnotation::CustomClass { id: DefinitionId(class_id), params: Vec::default() },
|
TypeAnnotation::CustomClass { id: DefinitionId(class_id), params: Vec::default() },
|
||||||
TypeAnnotation::CustomClass { id: PRIMITIVE_DEF_IDS.exception, params: Vec::default() },
|
TypeAnnotation::CustomClass { id: PrimitiveDefinition::Exception.id(), params: Vec::default() },
|
||||||
],
|
],
|
||||||
constructor: Some(signature),
|
constructor: Some(signature),
|
||||||
resolver: None,
|
resolver: None,
|
||||||
|
@ -391,49 +391,49 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
||||||
|
|
||||||
let top_level_def_list = vec![
|
let top_level_def_list = vec![
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.int32,
|
PrimitiveDefinition::Int32.id(),
|
||||||
None,
|
None,
|
||||||
"int32".into(),
|
"int32".into(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
))),
|
))),
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.int64,
|
PrimitiveDefinition::Int64.id(),
|
||||||
None,
|
None,
|
||||||
"int64".into(),
|
"int64".into(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
))),
|
))),
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.float,
|
PrimitiveDefinition::Float.id(),
|
||||||
None,
|
None,
|
||||||
"float".into(),
|
"float".into(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
))),
|
))),
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.bool,
|
PrimitiveDefinition::Bool.id(),
|
||||||
None,
|
None,
|
||||||
"bool".into(),
|
"bool".into(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
))),
|
))),
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.none,
|
PrimitiveDefinition::None.id(),
|
||||||
None,
|
None,
|
||||||
"none".into(),
|
"none".into(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
))),
|
))),
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.range,
|
PrimitiveDefinition::Range.id(),
|
||||||
None,
|
None,
|
||||||
"range".into(),
|
"range".into(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
))),
|
))),
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.str,
|
PrimitiveDefinition::Str.id(),
|
||||||
None,
|
None,
|
||||||
"str".into(),
|
"str".into(),
|
||||||
None,
|
None,
|
||||||
|
@ -441,7 +441,7 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
||||||
))),
|
))),
|
||||||
Arc::new(RwLock::new(TopLevelDef::Class {
|
Arc::new(RwLock::new(TopLevelDef::Class {
|
||||||
name: "Exception".into(),
|
name: "Exception".into(),
|
||||||
object_id: PRIMITIVE_DEF_IDS.exception,
|
object_id: PrimitiveDefinition::Exception.id(),
|
||||||
type_vars: Vec::default(),
|
type_vars: Vec::default(),
|
||||||
fields: exception_fields,
|
fields: exception_fields,
|
||||||
methods: Vec::default(),
|
methods: Vec::default(),
|
||||||
|
@ -451,14 +451,14 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
||||||
loc: None,
|
loc: None,
|
||||||
})),
|
})),
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.uint32,
|
PrimitiveDefinition::UInt32.id(),
|
||||||
None,
|
None,
|
||||||
"uint32".into(),
|
"uint32".into(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
))),
|
))),
|
||||||
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
Arc::new(RwLock::new(TopLevelComposer::make_top_level_class_def(
|
||||||
PRIMITIVE_DEF_IDS.uint64,
|
PrimitiveDefinition::UInt64.id(),
|
||||||
None,
|
None,
|
||||||
"uint64".into(),
|
"uint64".into(),
|
||||||
None,
|
None,
|
||||||
|
@ -467,16 +467,16 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
||||||
Arc::new(RwLock::new({
|
Arc::new(RwLock::new({
|
||||||
TopLevelDef::Class {
|
TopLevelDef::Class {
|
||||||
name: "Option".into(),
|
name: "Option".into(),
|
||||||
object_id: PRIMITIVE_DEF_IDS.option,
|
object_id: PrimitiveDefinition::Option.id(),
|
||||||
type_vars: vec![option_ty_var],
|
type_vars: vec![option_ty_var],
|
||||||
fields: vec![],
|
fields: vec![],
|
||||||
methods: vec![
|
methods: vec![
|
||||||
("is_some".into(), is_some_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.option.0 + 1)),
|
("is_some".into(), is_some_ty.0, PrimitiveDefinition::OptionIsSome.id()),
|
||||||
("is_none".into(), is_some_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.option.0 + 2)),
|
("is_none".into(), is_some_ty.0, PrimitiveDefinition::OptionIsNone.id()),
|
||||||
("unwrap".into(), unwrap_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.option.0 + 3)),
|
("unwrap".into(), unwrap_ty.0, PrimitiveDefinition::OptionUnwrap.id()),
|
||||||
],
|
],
|
||||||
ancestors: vec![TypeAnnotation::CustomClass {
|
ancestors: vec![TypeAnnotation::CustomClass {
|
||||||
id: PRIMITIVE_DEF_IDS.option,
|
id: PrimitiveDefinition::Option.id(),
|
||||||
params: Vec::default(),
|
params: Vec::default(),
|
||||||
}],
|
}],
|
||||||
constructor: None,
|
constructor: None,
|
||||||
|
@ -557,12 +557,12 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
||||||
})),
|
})),
|
||||||
Arc::new(RwLock::new(TopLevelDef::Class {
|
Arc::new(RwLock::new(TopLevelDef::Class {
|
||||||
name: "ndarray".into(),
|
name: "ndarray".into(),
|
||||||
object_id: PRIMITIVE_DEF_IDS.ndarray,
|
object_id: PrimitiveDefinition::NDArray.id(),
|
||||||
type_vars: vec![ndarray_dtype_ty, ndarray_ndims_ty],
|
type_vars: vec![ndarray_dtype_ty, ndarray_ndims_ty],
|
||||||
fields: Vec::default(),
|
fields: Vec::default(),
|
||||||
methods: vec![
|
methods: vec![
|
||||||
("copy".into(), ndarray_copy_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.ndarray.0 + 1)),
|
("copy".into(), ndarray_copy_ty.0, PrimitiveDefinition::NDArrayCopy.id()),
|
||||||
("fill".into(), ndarray_fill_ty.0, DefinitionId(PRIMITIVE_DEF_IDS.ndarray.0 + 2)),
|
("fill".into(), ndarray_fill_ty.0, PrimitiveDefinition::NDArrayFill.id()),
|
||||||
],
|
],
|
||||||
ancestors: Vec::default(),
|
ancestors: Vec::default(),
|
||||||
constructor: None,
|
constructor: None,
|
||||||
|
@ -1304,7 +1304,7 @@ pub fn get_builtins(unifier: &mut Unifier, primitives: &PrimitiveStore) -> Built
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
let llvm_i32 = ctx.ctx.i32_type();
|
let llvm_i32 = ctx.ctx.i32_type();
|
||||||
let llvm_usize = generator.get_size_type(ctx.ctx);
|
let llvm_usize = generator.get_size_type(ctx.ctx);
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl TopLevelComposer {
|
||||||
builtin_id.insert(name, DefinitionId(id));
|
builtin_id.insert(name, DefinitionId(id));
|
||||||
} else if let TopLevelDef::Class { name, constructor, object_id, .. } = &*def
|
} else if let TopLevelDef::Class { name, constructor, object_id, .. } = &*def
|
||||||
{
|
{
|
||||||
assert_eq!(id, object_id.0);
|
assert_eq!(id, object_id.0, "Object id of class '{}' should match its index in builtin name list", name);
|
||||||
if let Some(constructor) = constructor {
|
if let Some(constructor) = constructor {
|
||||||
builtin_ty.insert(*name, *constructor);
|
builtin_ty.insert(*name, *constructor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,76 +3,43 @@ use std::convert::TryInto;
|
||||||
use crate::symbol_resolver::SymbolValue;
|
use crate::symbol_resolver::SymbolValue;
|
||||||
use crate::typecheck::typedef::{Mapping, VarMap};
|
use crate::typecheck::typedef::{Mapping, VarMap};
|
||||||
use nac3parser::ast::{Constant, Location};
|
use nac3parser::ast::{Constant, Location};
|
||||||
|
use strum_macros::EnumIter;
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// Structure storing [`DefinitionId`] for primitive types.
|
/// All primitive types and functions in nac3core.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug, EnumIter)]
|
||||||
pub struct PrimitiveDefinitionIds {
|
pub enum PrimitiveDefinition {
|
||||||
pub int32: DefinitionId,
|
Int32, // 0
|
||||||
pub int64: DefinitionId,
|
Int64, // 1
|
||||||
pub uint32: DefinitionId,
|
Float, // 2
|
||||||
pub uint64: DefinitionId,
|
Bool, // 3
|
||||||
pub float: DefinitionId,
|
None, // 4
|
||||||
pub bool: DefinitionId,
|
Range, // 5
|
||||||
pub none: DefinitionId,
|
Str, // 6
|
||||||
pub range: DefinitionId,
|
Exception, // 7
|
||||||
pub str: DefinitionId,
|
UInt32, // 8
|
||||||
pub exception: DefinitionId,
|
UInt64, // 9
|
||||||
pub option: DefinitionId,
|
Option, // 10
|
||||||
pub ndarray: DefinitionId,
|
OptionIsSome, // 11
|
||||||
|
OptionIsNone, // 12
|
||||||
|
OptionUnwrap, // 13
|
||||||
|
NDArray, // 14
|
||||||
|
NDArrayCopy, // 15
|
||||||
|
NDArrayFill, // 16
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrimitiveDefinitionIds {
|
impl PrimitiveDefinition {
|
||||||
/// Returns all [`DefinitionId`] of primitives as a [`Vec`].
|
pub fn id(self) -> DefinitionId {
|
||||||
///
|
return DefinitionId(self as usize);
|
||||||
/// There are no guarantees on ordering of the IDs.
|
|
||||||
#[must_use]
|
|
||||||
fn as_vec(&self) -> Vec<DefinitionId> {
|
|
||||||
vec![
|
|
||||||
self.int32,
|
|
||||||
self.int64,
|
|
||||||
self.uint32,
|
|
||||||
self.uint64,
|
|
||||||
self.float,
|
|
||||||
self.bool,
|
|
||||||
self.none,
|
|
||||||
self.range,
|
|
||||||
self.str,
|
|
||||||
self.exception,
|
|
||||||
self.option,
|
|
||||||
self.ndarray,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all [`DefinitionId`]s of this instance in indeterminate order.
|
pub fn contains_id(id: DefinitionId) -> bool {
|
||||||
pub fn iter(&self) -> impl Iterator<Item=DefinitionId> {
|
Self::iter().any(|prim| prim.id() == id)
|
||||||
self.as_vec().into_iter()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the primitive with the largest [`DefinitionId`].
|
|
||||||
#[must_use]
|
|
||||||
pub fn max_id(&self) -> DefinitionId {
|
|
||||||
self.iter().max().unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [definition IDs][DefinitionId] for primitive types.
|
|
||||||
pub const PRIMITIVE_DEF_IDS: PrimitiveDefinitionIds = PrimitiveDefinitionIds {
|
|
||||||
int32: DefinitionId(0),
|
|
||||||
int64: DefinitionId(1),
|
|
||||||
uint32: DefinitionId(8),
|
|
||||||
uint64: DefinitionId(9),
|
|
||||||
float: DefinitionId(2),
|
|
||||||
bool: DefinitionId(3),
|
|
||||||
none: DefinitionId(4),
|
|
||||||
range: DefinitionId(5),
|
|
||||||
str: DefinitionId(6),
|
|
||||||
exception: DefinitionId(7),
|
|
||||||
option: DefinitionId(10),
|
|
||||||
ndarray: DefinitionId(14),
|
|
||||||
};
|
|
||||||
|
|
||||||
impl TopLevelDef {
|
impl TopLevelDef {
|
||||||
pub fn to_string(&self, unifier: &mut Unifier) -> String {
|
pub fn to_string(&self, unifier: &mut Unifier) -> String {
|
||||||
match self {
|
match self {
|
||||||
|
@ -115,42 +82,42 @@ impl TopLevelComposer {
|
||||||
pub fn make_primitives(size_t: u32) -> (PrimitiveStore, Unifier) {
|
pub fn make_primitives(size_t: u32) -> (PrimitiveStore, Unifier) {
|
||||||
let mut unifier = Unifier::new();
|
let mut unifier = Unifier::new();
|
||||||
let int32 = unifier.add_ty(TypeEnum::TObj {
|
let int32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int32,
|
obj_id: PrimitiveDefinition::Int32.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let int64 = unifier.add_ty(TypeEnum::TObj {
|
let int64 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int64,
|
obj_id: PrimitiveDefinition::Int64.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let float = unifier.add_ty(TypeEnum::TObj {
|
let float = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.float,
|
obj_id: PrimitiveDefinition::Float.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let bool = unifier.add_ty(TypeEnum::TObj {
|
let bool = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.bool,
|
obj_id: PrimitiveDefinition::Bool.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let none = unifier.add_ty(TypeEnum::TObj {
|
let none = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.none,
|
obj_id: PrimitiveDefinition::None.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let range = unifier.add_ty(TypeEnum::TObj {
|
let range = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.range,
|
obj_id: PrimitiveDefinition::Range.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let str = unifier.add_ty(TypeEnum::TObj {
|
let str = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.str,
|
obj_id: PrimitiveDefinition::Str.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let exception = unifier.add_ty(TypeEnum::TObj {
|
let exception = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.exception,
|
obj_id: PrimitiveDefinition::Exception.id(),
|
||||||
fields: vec![
|
fields: vec![
|
||||||
("__name__".into(), (int32, true)),
|
("__name__".into(), (int32, true)),
|
||||||
("__file__".into(), (str, true)),
|
("__file__".into(), (str, true)),
|
||||||
|
@ -167,12 +134,12 @@ impl TopLevelComposer {
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let uint32 = unifier.add_ty(TypeEnum::TObj {
|
let uint32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.uint32,
|
obj_id: PrimitiveDefinition::UInt32.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let uint64 = unifier.add_ty(TypeEnum::TObj {
|
let uint64 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.uint64,
|
obj_id: PrimitiveDefinition::UInt64.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
@ -189,7 +156,7 @@ impl TopLevelComposer {
|
||||||
vars: VarMap::from([(option_type_var.1, option_type_var.0)]),
|
vars: VarMap::from([(option_type_var.1, option_type_var.0)]),
|
||||||
}));
|
}));
|
||||||
let option = unifier.add_ty(TypeEnum::TObj {
|
let option = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.option,
|
obj_id: PrimitiveDefinition::Option.id(),
|
||||||
fields: vec![
|
fields: vec![
|
||||||
("is_some".into(), (is_some_type_fun_ty, true)),
|
("is_some".into(), (is_some_type_fun_ty, true)),
|
||||||
("is_none".into(), (is_some_type_fun_ty, true)),
|
("is_none".into(), (is_some_type_fun_ty, true)),
|
||||||
|
@ -232,7 +199,7 @@ impl TopLevelComposer {
|
||||||
]),
|
]),
|
||||||
}));
|
}));
|
||||||
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.ndarray,
|
obj_id: PrimitiveDefinition::NDArray.id(),
|
||||||
fields: Mapping::from([
|
fields: Mapping::from([
|
||||||
("copy".into(), (ndarray_copy_fun_ty, true)),
|
("copy".into(), (ndarray_copy_fun_ty, true)),
|
||||||
("fill".into(), (ndarray_fill_fun_ty, true)),
|
("fill".into(), (ndarray_fill_fun_ty, true)),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use crate::{
|
use crate::{
|
||||||
toplevel::helper::PRIMITIVE_DEF_IDS,
|
toplevel::helper::PrimitiveDefinition,
|
||||||
typecheck::{
|
typecheck::{
|
||||||
type_inferencer::PrimitiveStore,
|
type_inferencer::PrimitiveStore,
|
||||||
typedef::{Type, TypeEnum, Unifier, VarMap},
|
typedef::{Type, TypeEnum, Unifier, VarMap},
|
||||||
|
@ -37,7 +37,7 @@ pub fn subst_ndarray_tvars(
|
||||||
let TypeEnum::TObj { obj_id, params, .. } = &*unifier.get_ty_immutable(ndarray) else {
|
let TypeEnum::TObj { obj_id, params, .. } = &*unifier.get_ty_immutable(ndarray) else {
|
||||||
panic!("Expected `ndarray` to be TObj, but got {}", unifier.stringify(ndarray))
|
panic!("Expected `ndarray` to be TObj, but got {}", unifier.stringify(ndarray))
|
||||||
};
|
};
|
||||||
debug_assert_eq!(*obj_id, PRIMITIVE_DEF_IDS.ndarray);
|
debug_assert_eq!(*obj_id, PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
if dtype.is_none() && ndims.is_none() {
|
if dtype.is_none() && ndims.is_none() {
|
||||||
return ndarray
|
return ndarray
|
||||||
|
@ -66,7 +66,7 @@ fn unpack_ndarray_tvars(
|
||||||
let TypeEnum::TObj { obj_id, params, .. } = &*unifier.get_ty_immutable(ndarray) else {
|
let TypeEnum::TObj { obj_id, params, .. } = &*unifier.get_ty_immutable(ndarray) else {
|
||||||
panic!("Expected `ndarray` to be TObj, but got {}", unifier.stringify(ndarray))
|
panic!("Expected `ndarray` to be TObj, but got {}", unifier.stringify(ndarray))
|
||||||
};
|
};
|
||||||
debug_assert_eq!(*obj_id, PRIMITIVE_DEF_IDS.ndarray);
|
debug_assert_eq!(*obj_id, PrimitiveDefinition::NDArray.id());
|
||||||
debug_assert_eq!(params.len(), 2);
|
debug_assert_eq!(params.len(), 2);
|
||||||
|
|
||||||
params.iter()
|
params.iter()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::symbol_resolver::SymbolValue;
|
use crate::symbol_resolver::SymbolValue;
|
||||||
use crate::toplevel::helper::PRIMITIVE_DEF_IDS;
|
use crate::toplevel::helper::PrimitiveDefinition;
|
||||||
use crate::typecheck::typedef::VarMap;
|
use crate::typecheck::typedef::VarMap;
|
||||||
use super::*;
|
use super::*;
|
||||||
use nac3parser::ast::Constant;
|
use nac3parser::ast::Constant;
|
||||||
|
@ -95,7 +95,7 @@ pub fn parse_ast_to_type_annotation_kinds<T>(
|
||||||
} else if id == &"str".into() {
|
} else if id == &"str".into() {
|
||||||
Ok(TypeAnnotation::Primitive(primitives.str))
|
Ok(TypeAnnotation::Primitive(primitives.str))
|
||||||
} else if id == &"Exception".into() {
|
} else if id == &"Exception".into() {
|
||||||
Ok(TypeAnnotation::CustomClass { id: PRIMITIVE_DEF_IDS.exception, params: Vec::default() })
|
Ok(TypeAnnotation::CustomClass { id: PrimitiveDefinition::Exception.id(), params: Vec::default() })
|
||||||
} else if let Ok(obj_id) = resolver.get_identifier_def(*id) {
|
} else if let Ok(obj_id) = resolver.get_identifier_def(*id) {
|
||||||
let type_vars = {
|
let type_vars = {
|
||||||
let def_read = top_level_defs[obj_id.0].try_read();
|
let def_read = top_level_defs[obj_id.0].try_read();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use crate::symbol_resolver::SymbolValue;
|
use crate::symbol_resolver::SymbolValue;
|
||||||
use crate::toplevel::helper::PRIMITIVE_DEF_IDS;
|
use crate::toplevel::helper::PrimitiveDefinition;
|
||||||
use crate::toplevel::numpy::{make_ndarray_ty, unpack_ndarray_var_tys};
|
use crate::toplevel::numpy::{make_ndarray_ty, unpack_ndarray_var_tys};
|
||||||
use crate::typecheck::{
|
use crate::typecheck::{
|
||||||
type_inferencer::*,
|
type_inferencer::*,
|
||||||
|
@ -11,6 +11,7 @@ use nac3parser::ast::{Cmpop, Operator, Unaryop};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn binop_name(op: &Operator) -> &'static str {
|
pub fn binop_name(op: &Operator) -> &'static str {
|
||||||
|
@ -353,8 +354,8 @@ pub fn typeof_ndarray_broadcast(
|
||||||
left: Type,
|
left: Type,
|
||||||
right: Type,
|
right: Type,
|
||||||
) -> Result<Type, String> {
|
) -> Result<Type, String> {
|
||||||
let is_left_ndarray = left.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_left_ndarray = left.obj_id(unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_right_ndarray = right.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_right_ndarray = right.obj_id(unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
assert!(is_left_ndarray || is_right_ndarray);
|
assert!(is_left_ndarray || is_right_ndarray);
|
||||||
|
|
||||||
|
@ -424,8 +425,8 @@ pub fn typeof_binop(
|
||||||
lhs: Type,
|
lhs: Type,
|
||||||
rhs: Type,
|
rhs: Type,
|
||||||
) -> Result<Option<Type>, String> {
|
) -> Result<Option<Type>, String> {
|
||||||
let is_left_ndarray = lhs.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_left_ndarray = lhs.obj_id(unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_right_ndarray = rhs.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_right_ndarray = rhs.obj_id(unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
Ok(Some(match op {
|
Ok(Some(match op {
|
||||||
Operator::Add
|
Operator::Add
|
||||||
|
@ -523,16 +524,16 @@ pub fn typeof_unaryop(
|
||||||
Ok(match *op {
|
Ok(match *op {
|
||||||
Unaryop::Not => {
|
Unaryop::Not => {
|
||||||
match operand_obj_id {
|
match operand_obj_id {
|
||||||
Some(v) if v == PRIMITIVE_DEF_IDS.ndarray => Some(operand),
|
Some(v) if v == PrimitiveDefinition::NDArray.id() => Some(operand),
|
||||||
Some(_) => Some(primitives.bool),
|
Some(_) => Some(primitives.bool),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Unaryop::Invert => {
|
Unaryop::Invert => {
|
||||||
if operand_obj_id.is_some_and(|id| id == PRIMITIVE_DEF_IDS.bool) {
|
if operand_obj_id.is_some_and(|id| id == PrimitiveDefinition::Bool.id()) {
|
||||||
Some(primitives.int32)
|
Some(primitives.int32)
|
||||||
} else if operand_obj_id.is_some_and(|id| PRIMITIVE_DEF_IDS.iter().any(|prim_id| id == prim_id)) {
|
} else if operand_obj_id.is_some_and(|id| PrimitiveDefinition::iter().any(|prim| id == prim.id())) {
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -541,9 +542,9 @@ pub fn typeof_unaryop(
|
||||||
|
|
||||||
Unaryop::UAdd
|
Unaryop::UAdd
|
||||||
| Unaryop::USub => {
|
| Unaryop::USub => {
|
||||||
if operand_obj_id.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
if operand_obj_id.is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
let (dtype, _) = unpack_ndarray_var_tys(unifier, operand);
|
let (dtype, _) = unpack_ndarray_var_tys(unifier, operand);
|
||||||
if dtype.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.bool) {
|
if dtype.obj_id(unifier).is_some_and(|id| id == PrimitiveDefinition::Bool.id()) {
|
||||||
return Err(if *op == Unaryop::UAdd {
|
return Err(if *op == Unaryop::UAdd {
|
||||||
"The ufunc 'positive' cannot be applied to ndarray[bool, N]".to_string()
|
"The ufunc 'positive' cannot be applied to ndarray[bool, N]".to_string()
|
||||||
} else {
|
} else {
|
||||||
|
@ -552,9 +553,9 @@ pub fn typeof_unaryop(
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else if operand_obj_id.is_some_and(|id| id == PRIMITIVE_DEF_IDS.bool) {
|
} else if operand_obj_id.is_some_and(|id| id == PrimitiveDefinition::Bool.id()) {
|
||||||
Some(primitives.int32)
|
Some(primitives.int32)
|
||||||
} else if operand_obj_id.is_some_and(|id| PRIMITIVE_DEF_IDS.iter().any(|prim_id| id == prim_id)) {
|
} else if operand_obj_id.is_some_and(|id| PrimitiveDefinition::iter().any(|prim| id == prim.id())) {
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -573,10 +574,10 @@ pub fn typeof_cmpop(
|
||||||
) -> Result<Option<Type>, String> {
|
) -> Result<Option<Type>, String> {
|
||||||
let is_left_ndarray = lhs
|
let is_left_ndarray = lhs
|
||||||
.obj_id(unifier)
|
.obj_id(unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
let is_right_ndarray = rhs
|
let is_right_ndarray = rhs
|
||||||
.obj_id(unifier)
|
.obj_id(unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
||||||
|
|
||||||
Ok(Some(if is_left_ndarray || is_right_ndarray {
|
Ok(Some(if is_left_ndarray || is_right_ndarray {
|
||||||
let brd = typeof_ndarray_broadcast(unifier, primitives, lhs, rhs)?;
|
let brd = typeof_ndarray_broadcast(unifier, primitives, lhs, rhs)?;
|
||||||
|
|
|
@ -9,7 +9,7 @@ use super::{magic_methods::*, type_error::TypeError, typedef::CallId};
|
||||||
use crate::{
|
use crate::{
|
||||||
symbol_resolver::{SymbolResolver, SymbolValue},
|
symbol_resolver::{SymbolResolver, SymbolValue},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimitiveDefinition,
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
TopLevelContext,
|
TopLevelContext,
|
||||||
},
|
},
|
||||||
|
@ -235,7 +235,7 @@ impl<'a> Fold<()> for Inferencer<'a> {
|
||||||
} else {
|
} else {
|
||||||
let list_like_ty = match &*self.unifier.get_ty(iter.custom.unwrap()) {
|
let list_like_ty = match &*self.unifier.get_ty(iter.custom.unwrap()) {
|
||||||
TypeEnum::TList { .. } => self.unifier.add_ty(TypeEnum::TList { ty: target.custom.unwrap() }),
|
TypeEnum::TList { .. } => self.unifier.add_ty(TypeEnum::TList { ty: target.custom.unwrap() }),
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => todo!(),
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => todo!(),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
self.unify(list_like_ty, iter.custom.unwrap(), &iter.location)?;
|
self.unify(list_like_ty, iter.custom.unwrap(), &iter.location)?;
|
||||||
|
@ -877,7 +877,7 @@ impl<'a> Inferencer<'a> {
|
||||||
let arg0 = self.fold_expr(args.remove(0))?;
|
let arg0 = self.fold_expr(args.remove(0))?;
|
||||||
let arg0_ty = arg0.custom.unwrap();
|
let arg0_ty = arg0.custom.unwrap();
|
||||||
|
|
||||||
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
let (_, ndarray_ndims) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
let (_, ndarray_ndims) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
||||||
|
|
||||||
make_ndarray_ty(self.unifier, self.primitives, Some(target_ty), Some(ndarray_ndims))
|
make_ndarray_ty(self.unifier, self.primitives, Some(target_ty), Some(ndarray_ndims))
|
||||||
|
@ -919,7 +919,7 @@ impl<'a> Inferencer<'a> {
|
||||||
let arg0 = self.fold_expr(args.remove(0))?;
|
let arg0 = self.fold_expr(args.remove(0))?;
|
||||||
let arg0_ty = arg0.custom.unwrap();
|
let arg0_ty = arg0.custom.unwrap();
|
||||||
|
|
||||||
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
let (ndarray_dtype, _) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
let (ndarray_dtype, _) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
||||||
|
|
||||||
ndarray_dtype
|
ndarray_dtype
|
||||||
|
@ -970,13 +970,13 @@ impl<'a> Inferencer<'a> {
|
||||||
let arg1 = self.fold_expr(args.remove(0))?;
|
let arg1 = self.fold_expr(args.remove(0))?;
|
||||||
let arg1_ty = arg1.custom.unwrap();
|
let arg1_ty = arg1.custom.unwrap();
|
||||||
|
|
||||||
let arg0_dtype = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
let arg0_dtype = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
unpack_ndarray_var_tys(self.unifier, arg0_ty).0
|
unpack_ndarray_var_tys(self.unifier, arg0_ty).0
|
||||||
} else {
|
} else {
|
||||||
arg0_ty
|
arg0_ty
|
||||||
};
|
};
|
||||||
|
|
||||||
let arg1_dtype = if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
let arg1_dtype = if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
unpack_ndarray_var_tys(self.unifier, arg1_ty).0
|
unpack_ndarray_var_tys(self.unifier, arg1_ty).0
|
||||||
} else {
|
} else {
|
||||||
arg1_ty
|
arg1_ty
|
||||||
|
@ -1007,11 +1007,11 @@ impl<'a> Inferencer<'a> {
|
||||||
let ret = if [
|
let ret = if [
|
||||||
&arg0_ty,
|
&arg0_ty,
|
||||||
&arg1_ty,
|
&arg1_ty,
|
||||||
].into_iter().any(|arg_ty| arg_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) {
|
].into_iter().any(|arg_ty| arg_ty.obj_id(self.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) {
|
||||||
// typeof_ndarray_broadcast requires both dtypes to be the same, but ldexp accepts
|
// typeof_ndarray_broadcast requires both dtypes to be the same, but ldexp accepts
|
||||||
// (float, int32), so convert it to align with the dtype of the first arg
|
// (float, int32), so convert it to align with the dtype of the first arg
|
||||||
let arg1_ty = if id == &"np_ldexp".into() {
|
let arg1_ty = if id == &"np_ldexp".into() {
|
||||||
if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
let (_, ndims) = unpack_ndarray_var_tys(self.unifier, arg1_ty);
|
let (_, ndims) = unpack_ndarray_var_tys(self.unifier, arg1_ty);
|
||||||
|
|
||||||
make_ndarray_ty(self.unifier, self.primitives, Some(target_ty), Some(ndims))
|
make_ndarray_ty(self.unifier, self.primitives, Some(target_ty), Some(ndims))
|
||||||
|
@ -1108,7 +1108,7 @@ impl<'a> Inferencer<'a> {
|
||||||
let arg0 = self.fold_expr(args.remove(0))?;
|
let arg0 = self.fold_expr(args.remove(0))?;
|
||||||
let arg0_ty = arg0.custom.unwrap();
|
let arg0_ty = arg0.custom.unwrap();
|
||||||
|
|
||||||
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
||||||
let (_, ndarray_ndims) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
let (_, ndarray_ndims) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
||||||
|
|
||||||
make_ndarray_ty(self.unifier, self.primitives, Some(target_ty), Some(ndarray_ndims))
|
make_ndarray_ty(self.unifier, self.primitives, Some(target_ty), Some(ndarray_ndims))
|
||||||
|
@ -1500,7 +1500,7 @@ impl<'a> Inferencer<'a> {
|
||||||
ops: &[ast::Cmpop],
|
ops: &[ast::Cmpop],
|
||||||
comparators: &[ast::Expr<Option<Type>>],
|
comparators: &[ast::Expr<Option<Type>>],
|
||||||
) -> InferenceResult {
|
) -> InferenceResult {
|
||||||
if ops.len() > 1 && once(left).chain(comparators).any(|expr| expr.custom.unwrap().obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)) {
|
if ops.len() > 1 && once(left).chain(comparators).any(|expr| expr.custom.unwrap().obj_id(self.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id())) {
|
||||||
return Err(HashSet::from([String::from("Comparator chaining with ndarray types not supported")]))
|
return Err(HashSet::from([String::from("Comparator chaining with ndarray types not supported")]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1614,7 +1614,7 @@ impl<'a> Inferencer<'a> {
|
||||||
}
|
}
|
||||||
let list_like_ty = match &*self.unifier.get_ty(value.custom.unwrap()) {
|
let list_like_ty = match &*self.unifier.get_ty(value.custom.unwrap()) {
|
||||||
TypeEnum::TList { .. } => self.unifier.add_ty(TypeEnum::TList { ty }),
|
TypeEnum::TList { .. } => self.unifier.add_ty(TypeEnum::TList { ty }),
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
let (_, ndims) = unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
let (_, ndims) = unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
||||||
|
|
||||||
make_ndarray_ty(self.unifier, self.primitives, Some(ty), Some(ndims))
|
make_ndarray_ty(self.unifier, self.primitives, Some(ty), Some(ndims))
|
||||||
|
@ -1627,7 +1627,7 @@ impl<'a> Inferencer<'a> {
|
||||||
}
|
}
|
||||||
ExprKind::Constant { value: ast::Constant::Int(val), .. } => {
|
ExprKind::Constant { value: ast::Constant::Int(val), .. } => {
|
||||||
match &*self.unifier.get_ty(value.custom.unwrap()) {
|
match &*self.unifier.get_ty(value.custom.unwrap()) {
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
let (_, ndims) = unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
let (_, ndims) = unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
||||||
self.infer_subscript_ndarray(value, ty, ndims)
|
self.infer_subscript_ndarray(value, ty, ndims)
|
||||||
}
|
}
|
||||||
|
@ -1650,7 +1650,7 @@ impl<'a> Inferencer<'a> {
|
||||||
if value.custom
|
if value.custom
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.obj_id(self.unifier)
|
.obj_id(self.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id())
|
||||||
.not() {
|
.not() {
|
||||||
return report_error("Tuple slices are only supported for ndarrays", slice.location)
|
return report_error("Tuple slices are only supported for ndarrays", slice.location)
|
||||||
}
|
}
|
||||||
|
@ -1683,7 +1683,7 @@ impl<'a> Inferencer<'a> {
|
||||||
self.constrain(value.custom.unwrap(), list, &value.location)?;
|
self.constrain(value.custom.unwrap(), list, &value.location)?;
|
||||||
Ok(ty)
|
Ok(ty)
|
||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimitiveDefinition::NDArray.id() => {
|
||||||
let (_, ndims) = unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
let (_, ndims) = unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
||||||
|
|
||||||
let valid_index_tys = [
|
let valid_index_tys = [
|
||||||
|
|
|
@ -3,7 +3,7 @@ use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
codegen::CodeGenContext,
|
codegen::CodeGenContext,
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{DefinitionId, helper::PRIMITIVE_DEF_IDS, TopLevelDef},
|
toplevel::{DefinitionId, helper::PrimitiveDefinition, TopLevelDef},
|
||||||
};
|
};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use std::iter::zip;
|
use std::iter::zip;
|
||||||
|
@ -73,7 +73,7 @@ impl TestEnvironment {
|
||||||
let mut unifier = Unifier::new();
|
let mut unifier = Unifier::new();
|
||||||
|
|
||||||
let int32 = unifier.add_ty(TypeEnum::TObj {
|
let int32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int32,
|
obj_id: PrimitiveDefinition::Int32.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
@ -86,59 +86,59 @@ impl TestEnvironment {
|
||||||
fields.insert("__add__".into(), (add_ty, false));
|
fields.insert("__add__".into(), (add_ty, false));
|
||||||
});
|
});
|
||||||
let int64 = unifier.add_ty(TypeEnum::TObj {
|
let int64 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int64,
|
obj_id: PrimitiveDefinition::Int64.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let float = unifier.add_ty(TypeEnum::TObj {
|
let float = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.float,
|
obj_id: PrimitiveDefinition::Float.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let bool = unifier.add_ty(TypeEnum::TObj {
|
let bool = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.bool,
|
obj_id: PrimitiveDefinition::Bool.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let none = unifier.add_ty(TypeEnum::TObj {
|
let none = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.none,
|
obj_id: PrimitiveDefinition::None.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let range = unifier.add_ty(TypeEnum::TObj {
|
let range = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.range,
|
obj_id: PrimitiveDefinition::Range.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let str = unifier.add_ty(TypeEnum::TObj {
|
let str = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.str,
|
obj_id: PrimitiveDefinition::Str.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let exception = unifier.add_ty(TypeEnum::TObj {
|
let exception = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.exception,
|
obj_id: PrimitiveDefinition::Exception.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let uint32 = unifier.add_ty(TypeEnum::TObj {
|
let uint32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.uint32,
|
obj_id: PrimitiveDefinition::UInt32.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let uint64 = unifier.add_ty(TypeEnum::TObj {
|
let uint64 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.uint64,
|
obj_id: PrimitiveDefinition::UInt64.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let option = unifier.add_ty(TypeEnum::TObj {
|
let option = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.option,
|
obj_id: PrimitiveDefinition::Option.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let ndarray_dtype_tvar = unifier.get_fresh_var(Some("ndarray_dtype".into()), None);
|
let ndarray_dtype_tvar = unifier.get_fresh_var(Some("ndarray_dtype".into()), None);
|
||||||
let ndarray_ndims_tvar = unifier.get_fresh_const_generic_var(uint64, Some("ndarray_ndims".into()), None);
|
let ndarray_ndims_tvar = unifier.get_fresh_const_generic_var(uint64, Some("ndarray_ndims".into()), None);
|
||||||
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.ndarray,
|
obj_id: PrimitiveDefinition::NDArray.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::from([
|
params: VarMap::from([
|
||||||
(ndarray_dtype_tvar.1, ndarray_dtype_tvar.0),
|
(ndarray_dtype_tvar.1, ndarray_dtype_tvar.0),
|
||||||
|
@ -211,7 +211,7 @@ impl TestEnvironment {
|
||||||
let mut identifier_mapping = HashMap::new();
|
let mut identifier_mapping = HashMap::new();
|
||||||
let mut top_level_defs: Vec<Arc<RwLock<TopLevelDef>>> = Vec::new();
|
let mut top_level_defs: Vec<Arc<RwLock<TopLevelDef>>> = Vec::new();
|
||||||
let int32 = unifier.add_ty(TypeEnum::TObj {
|
let int32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int32,
|
obj_id: PrimitiveDefinition::Int32.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
@ -224,57 +224,57 @@ impl TestEnvironment {
|
||||||
fields.insert("__add__".into(), (add_ty, false));
|
fields.insert("__add__".into(), (add_ty, false));
|
||||||
});
|
});
|
||||||
let int64 = unifier.add_ty(TypeEnum::TObj {
|
let int64 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int64,
|
obj_id: PrimitiveDefinition::Int64.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let float = unifier.add_ty(TypeEnum::TObj {
|
let float = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.float,
|
obj_id: PrimitiveDefinition::Float.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let bool = unifier.add_ty(TypeEnum::TObj {
|
let bool = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.bool,
|
obj_id: PrimitiveDefinition::Bool.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let none = unifier.add_ty(TypeEnum::TObj {
|
let none = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.none,
|
obj_id: PrimitiveDefinition::None.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let range = unifier.add_ty(TypeEnum::TObj {
|
let range = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.range,
|
obj_id: PrimitiveDefinition::Range.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let str = unifier.add_ty(TypeEnum::TObj {
|
let str = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.str,
|
obj_id: PrimitiveDefinition::Str.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let exception = unifier.add_ty(TypeEnum::TObj {
|
let exception = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.exception,
|
obj_id: PrimitiveDefinition::Exception.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let uint32 = unifier.add_ty(TypeEnum::TObj {
|
let uint32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.uint32,
|
obj_id: PrimitiveDefinition::UInt32.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let uint64 = unifier.add_ty(TypeEnum::TObj {
|
let uint64 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.uint64,
|
obj_id: PrimitiveDefinition::UInt64.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let option = unifier.add_ty(TypeEnum::TObj {
|
let option = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.option,
|
obj_id: PrimitiveDefinition::Option.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.ndarray,
|
obj_id: PrimitiveDefinition::NDArray.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue