core: rename `PrimitiveDefinition` and refactor `get_builtins()`
This commit is contained in:
parent
84fc379ef4
commit
3aaf21fcf9
|
@ -6,7 +6,7 @@ use nac3core::{
|
||||||
CodeGenContext, CodeGenerator,
|
CodeGenContext, CodeGenerator,
|
||||||
},
|
},
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{DefinitionId, GenCall, helper::PrimitiveDefinition},
|
toplevel::{DefinitionId, GenCall, helper::PrimDef},
|
||||||
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, PrimitiveDefinition::Int32.id()), args, generator) {
|
if let Err(e) = rpc_codegen_callback_fn(ctx, None, (&fun, PrimDef::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::PrimitiveDefinition,
|
helper::PrimDef,
|
||||||
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 == PrimitiveDefinition::NDArray.id() => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::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 == PrimitiveDefinition::NDArray.id() => {
|
(TypeEnum::TObj { obj_id, .. }, false) if *obj_id == PrimDef::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 {
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl From<&str> for StrRef {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<StrRef> for String{
|
impl From<StrRef> for String {
|
||||||
fn from(s: StrRef) -> Self {
|
fn from(s: StrRef) -> Self {
|
||||||
get_str_from_ref(&get_str_ref_lock(), s).to_string()
|
get_str_from_ref(&get_str_ref_lock(), s).to_string()
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::codegen::{CodeGenContext, CodeGenerator, extern_fns, irrt, llvm_intri
|
||||||
use crate::codegen::classes::{NDArrayValue, ProxyValue, UntypedArrayLikeAccessor};
|
use crate::codegen::classes::{NDArrayValue, ProxyValue, 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::PrimitiveDefinition;
|
use crate::toplevel::helper::PrimDef;
|
||||||
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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if a_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if a_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(n) if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(z) if z_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(z) if z_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) => {
|
BasicValueEnum::PointerValue(x) if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) => {
|
(x1, x2) if [&x1_ty, &x2_ty].into_iter().any(|ty| ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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);
|
||||||
|
|
|
@ -26,7 +26,7 @@ use crate::{
|
||||||
symbol_resolver::{SymbolValue, ValueEnum},
|
symbol_resolver::{SymbolValue, ValueEnum},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
DefinitionId,
|
DefinitionId,
|
||||||
helper::PrimitiveDefinition,
|
helper::PrimDef,
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
TopLevelDef,
|
TopLevelDef,
|
||||||
},
|
},
|
||||||
|
@ -1133,13 +1133,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 == PrimitiveDefinition::NDArray.id()) || ty2.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
} else if ty1.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id()) || ty2.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 = ty2.obj_id(&ctx.unifier)
|
let is_ndarray2 = ty2.obj_id(&ctx.unifier)
|
||||||
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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);
|
||||||
|
@ -1373,7 +1373,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 == PrimitiveDefinition::NDArray.id()) {
|
} else if ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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);
|
||||||
|
|
||||||
|
@ -1385,7 +1385,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 == PrimitiveDefinition::Bool.id()) {
|
let op = if ndarray_dtype.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::Bool.id()) {
|
||||||
if *op == ast::Unaryop::Invert {
|
if *op == ast::Unaryop::Invert {
|
||||||
&ast::Unaryop::Not
|
&ast::Unaryop::Not
|
||||||
} else {
|
} else {
|
||||||
|
@ -1451,7 +1451,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 == PrimitiveDefinition::NDArray.id()) || right_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
if left_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id()) || right_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::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!() };
|
||||||
|
@ -1459,9 +1459,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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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);
|
||||||
|
@ -2452,7 +2452,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 == PrimitiveDefinition::NDArray.id() => {
|
TypeEnum::TObj { obj_id, params, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
let (ty, ndims) = params.iter()
|
let (ty, ndims) = params.iter()
|
||||||
.map(|(_, ty)| ty)
|
.map(|(_, ty)| ty)
|
||||||
.collect_tuple()
|
.collect_tuple()
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
symbol_resolver::{StaticValue, SymbolResolver},
|
symbol_resolver::{StaticValue, SymbolResolver},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PrimitiveDefinition,
|
helper::PrimDef,
|
||||||
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 PrimitiveDefinition::contains_id(*obj_id) {
|
if PrimDef::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 == PrimitiveDefinition::Option.id() => {
|
TObj { obj_id, params, .. } if *obj_id == PrimDef::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 == PrimitiveDefinition::NDArray.id() => {
|
TObj { obj_id, .. } if *obj_id == PrimDef::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::PrimitiveDefinition,
|
helper::PrimDef,
|
||||||
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 == PrimitiveDefinition::NDArray.id() => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::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 == PrimitiveDefinition::NDArray.id() => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::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!(),
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,41 +3,259 @@ 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 strum::IntoEnumIterator;
|
||||||
|
use strum_macros::EnumIter;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// All primitive types and functions in nac3core.
|
/// All primitive types and functions in nac3core.
|
||||||
#[derive(Clone, Copy, Debug, EnumIter)]
|
#[derive(Clone, Copy, Debug, EnumIter, PartialEq, Eq)]
|
||||||
pub enum PrimitiveDefinition {
|
pub enum PrimDef {
|
||||||
Int32, // 0
|
Int32,
|
||||||
Int64, // 1
|
Int64,
|
||||||
Float, // 2
|
Float,
|
||||||
Bool, // 3
|
Bool,
|
||||||
None, // 4
|
None,
|
||||||
Range, // 5
|
Range,
|
||||||
Str, // 6
|
Str,
|
||||||
Exception, // 7
|
Exception,
|
||||||
UInt32, // 8
|
UInt32,
|
||||||
UInt64, // 9
|
UInt64,
|
||||||
Option, // 10
|
Option,
|
||||||
OptionIsSome, // 11
|
OptionIsSome,
|
||||||
OptionIsNone, // 12
|
OptionIsNone,
|
||||||
OptionUnwrap, // 13
|
OptionUnwrap,
|
||||||
NDArray, // 14
|
NDArray,
|
||||||
NDArrayCopy, // 15
|
NDArrayCopy,
|
||||||
NDArrayFill, // 16
|
NDArrayFill,
|
||||||
|
FunInt32,
|
||||||
|
FunInt64,
|
||||||
|
FunUInt32,
|
||||||
|
FunUInt64,
|
||||||
|
FunFloat,
|
||||||
|
FunNpNDArray,
|
||||||
|
FunNpEmpty,
|
||||||
|
FunNpZeros,
|
||||||
|
FunNpOnes,
|
||||||
|
FunNpFull,
|
||||||
|
FunNpEye,
|
||||||
|
FunNpIdentity,
|
||||||
|
FunRound,
|
||||||
|
FunRound64,
|
||||||
|
FunNpRound,
|
||||||
|
FunRange,
|
||||||
|
FunStr,
|
||||||
|
FunBool,
|
||||||
|
FunFloor,
|
||||||
|
FunFloor64,
|
||||||
|
FunNpFloor,
|
||||||
|
FunCeil,
|
||||||
|
FunCeil64,
|
||||||
|
FunNpCeil,
|
||||||
|
FunLen,
|
||||||
|
FunMin,
|
||||||
|
FunNpMin,
|
||||||
|
FunNpMinimum,
|
||||||
|
FunMax,
|
||||||
|
FunNpMax,
|
||||||
|
FunNpMaximum,
|
||||||
|
FunAbs,
|
||||||
|
FunNpIsNan,
|
||||||
|
FunNpIsInf,
|
||||||
|
FunNpSin,
|
||||||
|
FunNpCos,
|
||||||
|
FunNpExp,
|
||||||
|
FunNpExp2,
|
||||||
|
FunNpLog,
|
||||||
|
FunNpLog10,
|
||||||
|
FunNpLog2,
|
||||||
|
FunNpFabs,
|
||||||
|
FunNpSqrt,
|
||||||
|
FunNpRint,
|
||||||
|
FunNpTan,
|
||||||
|
FunNpArcsin,
|
||||||
|
FunNpArccos,
|
||||||
|
FunNpArctan,
|
||||||
|
FunNpSinh,
|
||||||
|
FunNpCosh,
|
||||||
|
FunNpTanh,
|
||||||
|
FunNpArcsinh,
|
||||||
|
FunNpArccosh,
|
||||||
|
FunNpArctanh,
|
||||||
|
FunNpExpm1,
|
||||||
|
FunNpCbrt,
|
||||||
|
FunSpSpecErf,
|
||||||
|
FunSpSpecErfc,
|
||||||
|
FunSpSpecGamma,
|
||||||
|
FunSpSpecGammaln,
|
||||||
|
FunSpSpecJ0,
|
||||||
|
FunSpSpecJ1,
|
||||||
|
FunNpArctan2,
|
||||||
|
FunNpCopysign,
|
||||||
|
FunNpFmax,
|
||||||
|
FunNpFmin,
|
||||||
|
FunNpLdExp,
|
||||||
|
FunNpHypot,
|
||||||
|
FunNpNextAfter,
|
||||||
|
FunSome,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrimitiveDefinition {
|
/// Associated details of a [`PrimDef`]
|
||||||
pub fn id(self) -> DefinitionId {
|
struct PrimDefDetails {
|
||||||
return DefinitionId(self as usize);
|
name: &'static str,
|
||||||
|
simple_name: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PrimDef {
|
||||||
|
/// Get the assigned [`DefinitionId`] of this [`PrimDef`].
|
||||||
|
///
|
||||||
|
/// The assigned definition ID is defined by the position this [`PrimDef`] enum unit variant is defined at,
|
||||||
|
/// with the first `PrimDef`'s definition id being `0`.
|
||||||
|
pub fn id(&self) -> DefinitionId {
|
||||||
|
return DefinitionId(*self as usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check if a definition ID is that of a [`PrimDef`].
|
||||||
pub fn contains_id(id: DefinitionId) -> bool {
|
pub fn contains_id(id: DefinitionId) -> bool {
|
||||||
Self::iter().any(|prim| prim.id() == id)
|
Self::iter().any(|prim| prim.id() == id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the definition "simple_name" of this [`PrimDef`].
|
||||||
|
///
|
||||||
|
/// If the [`PrimDef`] is a function, this corresponds to [`TopLevelDef::Function::simple_name`].
|
||||||
|
///
|
||||||
|
/// If the [`PrimDef`] is a class, this is equal to [`PrimDef::name`].
|
||||||
|
pub fn simple_name<'a>(&'a self) -> &'static str {
|
||||||
|
self.details().simple_name
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the definition "name" of this [`PrimDef`].
|
||||||
|
///
|
||||||
|
/// If the [`PrimDef`] is a function, this corresponds to [`TopLevelDef::Function::name`].
|
||||||
|
///
|
||||||
|
/// If the [`PrimDef`] is a class, this corresponds to [`TopLevelDef::Class::name`].
|
||||||
|
pub fn name<'a>(&'a self) -> &'static str {
|
||||||
|
self.details().name
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the associated details of this [`PrimDef`]
|
||||||
|
fn details(&self) -> PrimDefDetails {
|
||||||
|
use PrimDef::*;
|
||||||
|
|
||||||
|
fn new(name: &'static str) -> PrimDefDetails {
|
||||||
|
PrimDefDetails { name, simple_name: name }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new2(simple_name: &'static str, name: &'static str) -> PrimDefDetails {
|
||||||
|
PrimDefDetails { name, simple_name }
|
||||||
|
}
|
||||||
|
|
||||||
|
match self {
|
||||||
|
Int32 => new("int32"),
|
||||||
|
Int64 => new("int64"),
|
||||||
|
Float => new("float"),
|
||||||
|
Bool => new("bool"),
|
||||||
|
None => new("none"),
|
||||||
|
Range => new("range"),
|
||||||
|
Str => new("str"),
|
||||||
|
Exception => new("Exception"),
|
||||||
|
UInt32 => new("uint32"),
|
||||||
|
UInt64 => new("uint64"),
|
||||||
|
Option => new("Option"),
|
||||||
|
OptionIsSome => new2("is_some", "Option.is_some"),
|
||||||
|
OptionIsNone => new2("is_none", "Option.is_none"),
|
||||||
|
OptionUnwrap => new2("unwrap", "Option.unwrap"),
|
||||||
|
NDArray => new("ndarray"),
|
||||||
|
NDArrayCopy => new2("copy", "ndarray.copy"),
|
||||||
|
NDArrayFill => new2("fill", "ndarray.fill"),
|
||||||
|
FunInt32 => new("int32"),
|
||||||
|
FunInt64 => new("int64"),
|
||||||
|
FunUInt32 => new("uint32"),
|
||||||
|
FunUInt64 => new("uint64"),
|
||||||
|
FunFloat => new("float"),
|
||||||
|
FunNpNDArray => new("np_ndarray"),
|
||||||
|
FunNpEmpty => new("np_empty"),
|
||||||
|
FunNpZeros => new("np_zeros"),
|
||||||
|
FunNpOnes => new("np_ones"),
|
||||||
|
FunNpFull => new("np_full"),
|
||||||
|
FunNpEye => new("np_eye"),
|
||||||
|
FunNpIdentity => new("np_identity"),
|
||||||
|
FunRound => new("round"),
|
||||||
|
FunRound64 => new("round64"),
|
||||||
|
FunNpRound => new("np_round"),
|
||||||
|
FunRange => new("range"),
|
||||||
|
FunStr => new("str"),
|
||||||
|
FunBool => new("bool"),
|
||||||
|
FunFloor => new("floor"),
|
||||||
|
FunFloor64 => new("floor64"),
|
||||||
|
FunNpFloor => new("np_floor"),
|
||||||
|
FunCeil => new("ceil"),
|
||||||
|
FunCeil64 => new("ceil64"),
|
||||||
|
FunNpCeil => new("np_ceil"),
|
||||||
|
FunLen => new("len"),
|
||||||
|
FunMin => new("min"),
|
||||||
|
FunNpMin => new("np_min"),
|
||||||
|
FunNpMinimum => new("np_minimum"),
|
||||||
|
FunMax => new("max"),
|
||||||
|
FunNpMax => new("np_max"),
|
||||||
|
FunNpMaximum => new("np_maximum"),
|
||||||
|
FunAbs => new("abs"),
|
||||||
|
FunNpIsNan => new("np_isnan"),
|
||||||
|
FunNpIsInf => new("np_isinf"),
|
||||||
|
FunNpSin => new("np_sin"),
|
||||||
|
FunNpCos => new("np_cos"),
|
||||||
|
FunNpExp => new("np_exp"),
|
||||||
|
FunNpExp2 => new("np_exp2"),
|
||||||
|
FunNpLog => new("np_log"),
|
||||||
|
FunNpLog10 => new("np_log10"),
|
||||||
|
FunNpLog2 => new("np_log2"),
|
||||||
|
FunNpFabs => new("np_fabs"),
|
||||||
|
FunNpSqrt => new("np_sqrt"),
|
||||||
|
FunNpRint => new("np_rint"),
|
||||||
|
FunNpTan => new("np_tan"),
|
||||||
|
FunNpArcsin => new("np_arcsin"),
|
||||||
|
FunNpArccos => new("np_arccos"),
|
||||||
|
FunNpArctan => new("np_arctan"),
|
||||||
|
FunNpSinh => new("np_sinh"),
|
||||||
|
FunNpCosh => new("np_cosh"),
|
||||||
|
FunNpTanh => new("np_tanh"),
|
||||||
|
FunNpArcsinh => new("np_arcsinh"),
|
||||||
|
FunNpArccosh => new("np_arccosh"),
|
||||||
|
FunNpArctanh => new("np_arctanh"),
|
||||||
|
FunNpExpm1 => new("np_expm1"),
|
||||||
|
FunNpCbrt => new("np_cbrt"),
|
||||||
|
FunSpSpecErf => new("sp_spec_erf"),
|
||||||
|
FunSpSpecErfc => new("sp_spec_erfc"),
|
||||||
|
FunSpSpecGamma => new("sp_spec_gamma"),
|
||||||
|
FunSpSpecGammaln => new("sp_spec_gammaln"),
|
||||||
|
FunSpSpecJ0 => new("sp_spec_j0"),
|
||||||
|
FunSpSpecJ1 => new("sp_spec_j1"),
|
||||||
|
FunNpArctan2 => new("np_arctan2"),
|
||||||
|
FunNpCopysign => new("np_copysign"),
|
||||||
|
FunNpFmax => new("np_fmax"),
|
||||||
|
FunNpFmin => new("np_fmin"),
|
||||||
|
FunNpLdExp => new("np_ldexp"),
|
||||||
|
FunNpHypot => new("np_hypot"),
|
||||||
|
FunNpNextAfter => new("np_nextafter"),
|
||||||
|
FunSome => new("Some"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Asserts that a [`PrimDef`] is in an allowlist.
|
||||||
|
///
|
||||||
|
/// Like `debug_assert!`, this statements of this function are only
|
||||||
|
/// enabled if `cfg!(debug_assertions)` is true.
|
||||||
|
pub fn debug_assert_prim_is_allowed<const N: usize>(prim: PrimDef, allowlist: [PrimDef; N]) {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
let allowed = allowlist.iter().any(|p| *p == prim);
|
||||||
|
if !allowed {
|
||||||
|
panic!(
|
||||||
|
"Disallowed primitive definition. Got {:?}, but expects it to be in {:?}",
|
||||||
|
prim, allowlist
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopLevelDef {
|
impl TopLevelDef {
|
||||||
|
@ -82,42 +300,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: PrimitiveDefinition::Int32.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Int64.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Float.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Bool.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::None.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Range.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Str.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Exception.id(),
|
obj_id: PrimDef::Exception.id(),
|
||||||
fields: vec![
|
fields: vec![
|
||||||
("__name__".into(), (int32, true)),
|
("__name__".into(), (int32, true)),
|
||||||
("__file__".into(), (str, true)),
|
("__file__".into(), (str, true)),
|
||||||
|
@ -134,12 +352,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: PrimitiveDefinition::UInt32.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::UInt64.id(),
|
obj_id: PrimDef::UInt64.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
@ -156,7 +374,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: PrimitiveDefinition::Option.id(),
|
obj_id: PrimDef::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)),
|
||||||
|
@ -174,7 +392,8 @@ impl TopLevelComposer {
|
||||||
};
|
};
|
||||||
|
|
||||||
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(size_t_ty, Some("ndarray_ndims".into()), None);
|
let ndarray_ndims_tvar =
|
||||||
|
unifier.get_fresh_const_generic_var(size_t_ty, Some("ndarray_ndims".into()), None);
|
||||||
let ndarray_copy_fun_ret_ty = unifier.get_fresh_var(None, None);
|
let ndarray_copy_fun_ret_ty = unifier.get_fresh_var(None, None);
|
||||||
let ndarray_copy_fun_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature {
|
let ndarray_copy_fun_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature {
|
||||||
args: vec![],
|
args: vec![],
|
||||||
|
@ -185,13 +404,11 @@ impl TopLevelComposer {
|
||||||
]),
|
]),
|
||||||
}));
|
}));
|
||||||
let ndarray_fill_fun_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature {
|
let ndarray_fill_fun_ty = unifier.add_ty(TypeEnum::TFunc(FunSignature {
|
||||||
args: vec![
|
args: vec![FuncArg {
|
||||||
FuncArg {
|
name: "value".into(),
|
||||||
name: "value".into(),
|
ty: ndarray_dtype_tvar.0,
|
||||||
ty: ndarray_dtype_tvar.0,
|
default_value: None,
|
||||||
default_value: None,
|
}],
|
||||||
},
|
|
||||||
],
|
|
||||||
ret: none,
|
ret: none,
|
||||||
vars: VarMap::from([
|
vars: VarMap::from([
|
||||||
(ndarray_dtype_tvar.1, ndarray_dtype_tvar.0),
|
(ndarray_dtype_tvar.1, ndarray_dtype_tvar.0),
|
||||||
|
@ -199,7 +416,7 @@ impl TopLevelComposer {
|
||||||
]),
|
]),
|
||||||
}));
|
}));
|
||||||
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PrimitiveDefinition::NDArray.id(),
|
obj_id: PrimDef::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)),
|
||||||
|
@ -359,9 +576,7 @@ impl TopLevelComposer {
|
||||||
if let TypeEnum::TVar { id, .. } = unifier.get_ty(var_ty).as_ref() {
|
if let TypeEnum::TVar { id, .. } = unifier.get_ty(var_ty).as_ref() {
|
||||||
Ok(*id)
|
Ok(*id)
|
||||||
} else {
|
} else {
|
||||||
Err(HashSet::from([
|
Err(HashSet::from(["not type var".to_string()]))
|
||||||
"not type var".to_string(),
|
|
||||||
]))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,25 +593,27 @@ impl TopLevelComposer {
|
||||||
let (
|
let (
|
||||||
TypeEnum::TFunc(FunSignature { args: this_args, ret: this_ret, .. }),
|
TypeEnum::TFunc(FunSignature { args: this_args, ret: this_ret, .. }),
|
||||||
TypeEnum::TFunc(FunSignature { args: other_args, ret: other_ret, .. }),
|
TypeEnum::TFunc(FunSignature { args: other_args, ret: other_ret, .. }),
|
||||||
) = (this, other) else {
|
) = (this, other)
|
||||||
|
else {
|
||||||
unreachable!("this function must be called with function type")
|
unreachable!("this function must be called with function type")
|
||||||
};
|
};
|
||||||
|
|
||||||
// check args
|
// check args
|
||||||
let args_ok = this_args
|
let args_ok =
|
||||||
.iter()
|
this_args
|
||||||
.map(|FuncArg { name, ty, .. }| (name, type_var_to_concrete_def.get(ty).unwrap()))
|
.iter()
|
||||||
.zip(other_args.iter().map(|FuncArg { name, ty, .. }| {
|
.map(|FuncArg { name, ty, .. }| (name, type_var_to_concrete_def.get(ty).unwrap()))
|
||||||
(name, type_var_to_concrete_def.get(ty).unwrap())
|
.zip(other_args.iter().map(|FuncArg { name, ty, .. }| {
|
||||||
}))
|
(name, type_var_to_concrete_def.get(ty).unwrap())
|
||||||
.all(|(this, other)| {
|
}))
|
||||||
if this.0 == &"self".into() && this.0 == other.0 {
|
.all(|(this, other)| {
|
||||||
true
|
if this.0 == &"self".into() && this.0 == other.0 {
|
||||||
} else {
|
true
|
||||||
this.0 == other.0
|
} else {
|
||||||
&& check_overload_type_annotation_compatible(this.1, other.1, unifier)
|
this.0 == other.0
|
||||||
}
|
&& check_overload_type_annotation_compatible(this.1, other.1, unifier)
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// check rets
|
// check rets
|
||||||
let ret_ok = check_overload_type_annotation_compatible(
|
let ret_ok = check_overload_type_annotation_compatible(
|
||||||
|
@ -439,12 +656,10 @@ impl TopLevelComposer {
|
||||||
}
|
}
|
||||||
} =>
|
} =>
|
||||||
{
|
{
|
||||||
return Err(HashSet::from([
|
return Err(HashSet::from([format!(
|
||||||
format!(
|
"redundant type annotation for class fields at {}",
|
||||||
"redundant type annotation for class fields at {}",
|
s.location
|
||||||
s.location
|
)]))
|
||||||
),
|
|
||||||
]))
|
|
||||||
}
|
}
|
||||||
ast::StmtKind::Assign { targets, .. } => {
|
ast::StmtKind::Assign { targets, .. } => {
|
||||||
for t in targets {
|
for t in targets {
|
||||||
|
@ -568,93 +783,89 @@ pub fn parse_parameter_default_value(
|
||||||
Constant::Tuple(tuple) => Ok(SymbolValue::Tuple(
|
Constant::Tuple(tuple) => Ok(SymbolValue::Tuple(
|
||||||
tuple.iter().map(|x| handle_constant(x, loc)).collect::<Result<Vec<_>, _>>()?,
|
tuple.iter().map(|x| handle_constant(x, loc)).collect::<Result<Vec<_>, _>>()?,
|
||||||
)),
|
)),
|
||||||
Constant::None => Err(HashSet::from([
|
Constant::None => Err(HashSet::from([format!(
|
||||||
format!(
|
"`None` is not supported, use `none` for option type instead ({loc})"
|
||||||
"`None` is not supported, use `none` for option type instead ({loc})"
|
)])),
|
||||||
),
|
|
||||||
])),
|
|
||||||
_ => unimplemented!("this constant is not supported at {}", loc),
|
_ => unimplemented!("this constant is not supported at {}", loc),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match &default.node {
|
match &default.node {
|
||||||
ast::ExprKind::Constant { value, .. } => handle_constant(value, &default.location),
|
ast::ExprKind::Constant { value, .. } => handle_constant(value, &default.location),
|
||||||
ast::ExprKind::Call { func, args, .. } if args.len() == 1 => {
|
ast::ExprKind::Call { func, args, .. } if args.len() == 1 => match &func.node {
|
||||||
match &func.node {
|
ast::ExprKind::Name { id, .. } if *id == "int64".into() => match &args[0].node {
|
||||||
ast::ExprKind::Name { id, .. } if *id == "int64".into() => match &args[0].node {
|
ast::ExprKind::Constant { value: Constant::Int(v), .. } => {
|
||||||
ast::ExprKind::Constant { value: Constant::Int(v), .. } => {
|
let v: Result<i64, _> = (*v).try_into();
|
||||||
let v: Result<i64, _> = (*v).try_into();
|
match v {
|
||||||
match v {
|
Ok(v) => Ok(SymbolValue::I64(v)),
|
||||||
Ok(v) => Ok(SymbolValue::I64(v)),
|
_ => Err(HashSet::from([format!(
|
||||||
_ => Err(HashSet::from([
|
"default param value out of range at {}",
|
||||||
format!("default param value out of range at {}", default.location)
|
default.location
|
||||||
])),
|
)])),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => Err(HashSet::from([
|
|
||||||
format!("only allow constant integer here at {}", default.location),
|
|
||||||
]))
|
|
||||||
}
|
}
|
||||||
ast::ExprKind::Name { id, .. } if *id == "uint32".into() => match &args[0].node {
|
_ => Err(HashSet::from([format!(
|
||||||
ast::ExprKind::Constant { value: Constant::Int(v), .. } => {
|
"only allow constant integer here at {}",
|
||||||
let v: Result<u32, _> = (*v).try_into();
|
default.location
|
||||||
match v {
|
)])),
|
||||||
Ok(v) => Ok(SymbolValue::U32(v)),
|
},
|
||||||
_ => Err(HashSet::from([
|
ast::ExprKind::Name { id, .. } if *id == "uint32".into() => match &args[0].node {
|
||||||
format!("default param value out of range at {}", default.location),
|
ast::ExprKind::Constant { value: Constant::Int(v), .. } => {
|
||||||
])),
|
let v: Result<u32, _> = (*v).try_into();
|
||||||
}
|
match v {
|
||||||
|
Ok(v) => Ok(SymbolValue::U32(v)),
|
||||||
|
_ => Err(HashSet::from([format!(
|
||||||
|
"default param value out of range at {}",
|
||||||
|
default.location
|
||||||
|
)])),
|
||||||
}
|
}
|
||||||
_ => Err(HashSet::from([
|
|
||||||
format!("only allow constant integer here at {}", default.location),
|
|
||||||
]))
|
|
||||||
}
|
}
|
||||||
ast::ExprKind::Name { id, .. } if *id == "uint64".into() => match &args[0].node {
|
_ => Err(HashSet::from([format!(
|
||||||
ast::ExprKind::Constant { value: Constant::Int(v), .. } => {
|
"only allow constant integer here at {}",
|
||||||
let v: Result<u64, _> = (*v).try_into();
|
default.location
|
||||||
match v {
|
)])),
|
||||||
Ok(v) => Ok(SymbolValue::U64(v)),
|
},
|
||||||
_ => Err(HashSet::from([
|
ast::ExprKind::Name { id, .. } if *id == "uint64".into() => match &args[0].node {
|
||||||
format!("default param value out of range at {}", default.location),
|
ast::ExprKind::Constant { value: Constant::Int(v), .. } => {
|
||||||
])),
|
let v: Result<u64, _> = (*v).try_into();
|
||||||
}
|
match v {
|
||||||
|
Ok(v) => Ok(SymbolValue::U64(v)),
|
||||||
|
_ => Err(HashSet::from([format!(
|
||||||
|
"default param value out of range at {}",
|
||||||
|
default.location
|
||||||
|
)])),
|
||||||
}
|
}
|
||||||
_ => Err(HashSet::from([
|
|
||||||
format!("only allow constant integer here at {}", default.location),
|
|
||||||
]))
|
|
||||||
}
|
}
|
||||||
ast::ExprKind::Name { id, .. } if *id == "Some".into() => Ok(
|
_ => Err(HashSet::from([format!(
|
||||||
SymbolValue::OptionSome(
|
"only allow constant integer here at {}",
|
||||||
Box::new(parse_parameter_default_value(&args[0], resolver)?)
|
default.location
|
||||||
)
|
)])),
|
||||||
),
|
},
|
||||||
_ => Err(HashSet::from([
|
ast::ExprKind::Name { id, .. } if *id == "Some".into() => Ok(SymbolValue::OptionSome(
|
||||||
format!("unsupported default parameter at {}", default.location),
|
Box::new(parse_parameter_default_value(&args[0], resolver)?),
|
||||||
])),
|
)),
|
||||||
}
|
_ => Err(HashSet::from([format!(
|
||||||
}
|
"unsupported default parameter at {}",
|
||||||
ast::ExprKind::Tuple { elts, .. } => Ok(SymbolValue::Tuple(elts
|
default.location
|
||||||
.iter()
|
)])),
|
||||||
.map(|x| parse_parameter_default_value(x, resolver))
|
},
|
||||||
.collect::<Result<Vec<_>, _>>()?
|
ast::ExprKind::Tuple { elts, .. } => Ok(SymbolValue::Tuple(
|
||||||
|
elts.iter()
|
||||||
|
.map(|x| parse_parameter_default_value(x, resolver))
|
||||||
|
.collect::<Result<Vec<_>, _>>()?,
|
||||||
)),
|
)),
|
||||||
ast::ExprKind::Name { id, .. } if id == &"none".into() => Ok(SymbolValue::OptionNone),
|
ast::ExprKind::Name { id, .. } if id == &"none".into() => Ok(SymbolValue::OptionNone),
|
||||||
ast::ExprKind::Name { id, .. } => {
|
ast::ExprKind::Name { id, .. } => {
|
||||||
resolver.get_default_param_value(default).ok_or_else(
|
resolver.get_default_param_value(default).ok_or_else(|| {
|
||||||
|| HashSet::from([
|
HashSet::from([format!(
|
||||||
format!(
|
"`{}` cannot be used as a default parameter at {} \
|
||||||
"`{}` cannot be used as a default parameter at {} \
|
|
||||||
(not primitive type, option or tuple / not defined?)",
|
(not primitive type, option or tuple / not defined?)",
|
||||||
id,
|
id, default.location
|
||||||
default.location
|
)])
|
||||||
),
|
})
|
||||||
])
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
_ => Err(HashSet::from([
|
_ => Err(HashSet::from([format!(
|
||||||
format!(
|
"unsupported default parameter (not primitive type, option or tuple) at {}",
|
||||||
"unsupported default parameter (not primitive type, option or tuple) at {}",
|
default.location
|
||||||
default.location
|
)])),
|
||||||
),
|
|
||||||
]))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use crate::{
|
use crate::{
|
||||||
toplevel::helper::PrimitiveDefinition,
|
toplevel::helper::PrimDef,
|
||||||
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, PrimitiveDefinition::NDArray.id());
|
debug_assert_eq!(*obj_id, PrimDef::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, PrimitiveDefinition::NDArray.id());
|
debug_assert_eq!(*obj_id, PrimDef::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::PrimitiveDefinition;
|
use crate::toplevel::helper::PrimDef;
|
||||||
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: PrimitiveDefinition::Exception.id(), params: Vec::default() })
|
Ok(TypeAnnotation::CustomClass { id: PrimDef::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::PrimitiveDefinition;
|
use crate::toplevel::helper::PrimDef;
|
||||||
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::*,
|
||||||
|
@ -354,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 == PrimitiveDefinition::NDArray.id());
|
let is_left_ndarray = left.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_right_ndarray = right.obj_id(unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
let is_right_ndarray = right.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
|
|
||||||
assert!(is_left_ndarray || is_right_ndarray);
|
assert!(is_left_ndarray || is_right_ndarray);
|
||||||
|
|
||||||
|
@ -425,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 == PrimitiveDefinition::NDArray.id());
|
let is_left_ndarray = lhs.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_right_ndarray = rhs.obj_id(unifier).is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
let is_right_ndarray = rhs.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
|
|
||||||
Ok(Some(match op {
|
Ok(Some(match op {
|
||||||
Operator::Add
|
Operator::Add
|
||||||
|
@ -524,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 == PrimitiveDefinition::NDArray.id() => Some(operand),
|
Some(v) if v == PrimDef::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 == PrimitiveDefinition::Bool.id()) {
|
if operand_obj_id.is_some_and(|id| id == PrimDef::Bool.id()) {
|
||||||
Some(primitives.int32)
|
Some(primitives.int32)
|
||||||
} else if operand_obj_id.is_some_and(|id| PrimitiveDefinition::iter().any(|prim| id == prim.id())) {
|
} else if operand_obj_id.is_some_and(|id| PrimDef::iter().any(|prim| id == prim.id())) {
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -542,9 +542,9 @@ pub fn typeof_unaryop(
|
||||||
|
|
||||||
Unaryop::UAdd
|
Unaryop::UAdd
|
||||||
| Unaryop::USub => {
|
| Unaryop::USub => {
|
||||||
if operand_obj_id.is_some_and(|id| id == PrimitiveDefinition::NDArray.id()) {
|
if operand_obj_id.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::Bool.id()) {
|
if dtype.obj_id(unifier).is_some_and(|id| id == PrimDef::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 {
|
||||||
|
@ -553,9 +553,9 @@ pub fn typeof_unaryop(
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else if operand_obj_id.is_some_and(|id| id == PrimitiveDefinition::Bool.id()) {
|
} else if operand_obj_id.is_some_and(|id| id == PrimDef::Bool.id()) {
|
||||||
Some(primitives.int32)
|
Some(primitives.int32)
|
||||||
} else if operand_obj_id.is_some_and(|id| PrimitiveDefinition::iter().any(|prim| id == prim.id())) {
|
} else if operand_obj_id.is_some_and(|id| PrimDef::iter().any(|prim| id == prim.id())) {
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -574,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 == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_right_ndarray = rhs
|
let is_right_ndarray = rhs
|
||||||
.obj_id(unifier)
|
.obj_id(unifier)
|
||||||
.is_some_and(|id| id == PrimitiveDefinition::NDArray.id());
|
.is_some_and(|id| id == PrimDef::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::PrimitiveDefinition,
|
helper::PrimDef,
|
||||||
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 == PrimitiveDefinition::NDArray.id() => todo!(),
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) {
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) {
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) {
|
let arg0_dtype = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) {
|
let arg1_dtype = if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) {
|
].into_iter().any(|arg_ty| arg_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) {
|
if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id()) {
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id())) {
|
if ops.len() > 1 && once(left).chain(comparators).any(|expr| expr.custom.unwrap().obj_id(self.unifier).is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id() => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::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 == PrimitiveDefinition::NDArray.id() => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::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 == PrimitiveDefinition::NDArray.id())
|
.is_some_and(|id| id == PrimDef::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 == PrimitiveDefinition::NDArray.id() => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::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::PrimitiveDefinition, TopLevelDef},
|
toplevel::{DefinitionId, helper::PrimDef, 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: PrimitiveDefinition::Int32.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Int64.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Float.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Bool.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::None.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Range.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Str.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Exception.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::UInt32.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::UInt64.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Option.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::NDArray.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Int32.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Int64.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Float.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Bool.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::None.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Range.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Str.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Exception.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::UInt32.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::UInt64.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::Option.id(),
|
obj_id: PrimDef::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: PrimitiveDefinition::NDArray.id(),
|
obj_id: PrimDef::NDArray.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue