Compare commits
9 Commits
01ea93706d
...
2c9b1f5330
Author | SHA1 | Date |
---|---|---|
|
2c9b1f5330 | |
|
bd13630f9a | |
|
467ce051ec | |
|
f78a0ca8ee | |
|
d151ed48a7 | |
|
ccbd4bfe55 | |
|
c4420e6ab9 | |
|
fd36f78005 | |
|
8168692cc3 |
|
@ -0,0 +1,6 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,5 @@
|
||||||
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
|
<state>
|
||||||
|
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||||
|
</state>
|
||||||
|
</component>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="clangTidyChecks" value="-*,cert-dcl21-cpp,cert-dcl58-cpp,cert-err34-c,cert-err52-cpp,cert-err60-cpp,cert-flp30-c,cert-msc50-cpp,cert-msc51-cpp,cert-str34-c,google-default-arguments,google-explicit-constructor,google-runtime-operator,hicpp-exception-baseclass,hicpp-multiway-paths-covered,misc-misplaced-const,misc-new-delete-overloads,misc-no-recursion,misc-non-copyable-objects,misc-throw-by-value-catch-by-reference,misc-unconventional-assign-operator,misc-uniqueptr-reset-release,mpi-buffer-deref,mpi-type-mismatch,openmp-use-default-none,portability-simd-intrinsics,bugprone-*,cppcoreguidelines-*,modernize-*,performance-*" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/nac3.iml" filepath="$PROJECT_DIR$/.idea/nac3.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="CPP_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/nac3artiq/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/nac3ast/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/nac3core/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/nac3ld/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/nac3parser/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/nac3standalone/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/runkernel/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/nac3standalone/demo/lib/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Build All (Debug)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
|
<option name="command" value="build" />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
|
<envs />
|
||||||
|
<option name="emulateTerminal" value="false" />
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="requiredFeatures" value="true" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="withSudo" value="false" />
|
||||||
|
<option name="buildTarget" value="REMOTE" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<option name="isRedirectInput" value="false" />
|
||||||
|
<option name="redirectInputPath" value="" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Build All (Release)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
|
<option name="command" value="build --release" />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
|
<option name="emulateTerminal" value="false" />
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="requiredFeatures" value="true" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="withSudo" value="false" />
|
||||||
|
<option name="buildTarget" value="REMOTE" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<envs />
|
||||||
|
<option name="isRedirectInput" value="false" />
|
||||||
|
<option name="redirectInputPath" value="" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Build Standalone (Debug)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
|
<option name="command" value="build --bin nac3standalone" />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
|
<envs />
|
||||||
|
<option name="emulateTerminal" value="false" />
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="requiredFeatures" value="true" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="withSudo" value="false" />
|
||||||
|
<option name="buildTarget" value="REMOTE" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<option name="isRedirectInput" value="false" />
|
||||||
|
<option name="redirectInputPath" value="" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Build Standalone (Release)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
|
<option name="command" value="build --release --bin nac3standalone" />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
|
<envs />
|
||||||
|
<option name="emulateTerminal" value="false" />
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="requiredFeatures" value="true" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="withSudo" value="false" />
|
||||||
|
<option name="buildTarget" value="REMOTE" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<option name="isRedirectInput" value="false" />
|
||||||
|
<option name="redirectInputPath" value="" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Clean" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
|
<option name="command" value="clean " />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
|
<option name="emulateTerminal" value="false" />
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="requiredFeatures" value="true" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="withSudo" value="false" />
|
||||||
|
<option name="buildTarget" value="REMOTE" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<envs />
|
||||||
|
<option name="isRedirectInput" value="false" />
|
||||||
|
<option name="redirectInputPath" value="" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,17 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Nix Build (nac3artiq)" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_TEXT" value="nix build -L .#packages.x86_64-linux.nac3artiq" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="SCRIPT_PATH" value="" />
|
||||||
|
<option name="SCRIPT_OPTIONS" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||||
|
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="/bin/sh" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="EXECUTE_IN_TERMINAL" value="false" />
|
||||||
|
<option name="EXECUTE_SCRIPT_FILE" value="false" />
|
||||||
|
<envs />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Test" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
|
||||||
|
<option name="command" value="test" />
|
||||||
|
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
|
||||||
|
<option name="emulateTerminal" value="false" />
|
||||||
|
<option name="channel" value="DEFAULT" />
|
||||||
|
<option name="requiredFeatures" value="true" />
|
||||||
|
<option name="allFeatures" value="false" />
|
||||||
|
<option name="withSudo" value="false" />
|
||||||
|
<option name="buildTarget" value="REMOTE" />
|
||||||
|
<option name="backtrace" value="SHORT" />
|
||||||
|
<envs />
|
||||||
|
<option name="isRedirectInput" value="false" />
|
||||||
|
<option name="redirectInputPath" value="" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,21 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="check_demos.sh (Debug, -O0)" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_TEXT" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/nac3standalone/demo/check_demos.sh" />
|
||||||
|
<option name="SCRIPT_OPTIONS" value="--debug -- -O0" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/nac3standalone/demo" />
|
||||||
|
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="/bin/bash" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="EXECUTE_IN_TERMINAL" value="false" />
|
||||||
|
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||||
|
<envs>
|
||||||
|
<env name="RUST_BACKTRACE" value="1" />
|
||||||
|
</envs>
|
||||||
|
<method v="2">
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Build Standalone (Debug)" run_configuration_type="CargoCommandRunConfiguration" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="check_demos.sh (Debug, -O2)" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_TEXT" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/nac3standalone/demo/check_demos.sh" />
|
||||||
|
<option name="SCRIPT_OPTIONS" value="--debug" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/nac3standalone/demo" />
|
||||||
|
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="/bin/bash" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="EXECUTE_IN_TERMINAL" value="false" />
|
||||||
|
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||||
|
<envs />
|
||||||
|
<method v="2">
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Build Standalone (Debug)" run_configuration_type="CargoCommandRunConfiguration" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="check_demos.sh (Release, -O0)" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_TEXT" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/nac3standalone/demo/check_demos.sh" />
|
||||||
|
<option name="SCRIPT_OPTIONS" value="-- -O0" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/nac3standalone/demo" />
|
||||||
|
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="/bin/bash" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="EXECUTE_IN_TERMINAL" value="false" />
|
||||||
|
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||||
|
<envs />
|
||||||
|
<method v="2">
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Build Standalone (Release)" run_configuration_type="CargoCommandRunConfiguration" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,19 @@
|
||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="check_demos.sh (Release, -O2)" type="ShConfigurationType">
|
||||||
|
<option name="SCRIPT_TEXT" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
|
||||||
|
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/nac3standalone/demo/check_demos.sh" />
|
||||||
|
<option name="SCRIPT_OPTIONS" value="" />
|
||||||
|
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
|
||||||
|
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/nac3standalone/demo" />
|
||||||
|
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
|
||||||
|
<option name="INTERPRETER_PATH" value="/bin/bash" />
|
||||||
|
<option name="INTERPRETER_OPTIONS" value="" />
|
||||||
|
<option name="EXECUTE_IN_TERMINAL" value="false" />
|
||||||
|
<option name="EXECUTE_SCRIPT_FILE" value="true" />
|
||||||
|
<envs />
|
||||||
|
<method v="2">
|
||||||
|
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Build Standalone (Release)" run_configuration_type="CargoCommandRunConfiguration" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CommitMessageInspectionProfile">
|
||||||
|
<profile version="1.0">
|
||||||
|
<inspection_tool class="BodyLimit" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="SubjectBodySeparation" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="SubjectLimit" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -625,6 +625,8 @@ dependencies = [
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"rayon",
|
"rayon",
|
||||||
"regex",
|
"regex",
|
||||||
|
"strum",
|
||||||
|
"strum_macros",
|
||||||
"test-case",
|
"test-case",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1116,6 +1118,25 @@ version = "0.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strum"
|
||||||
|
version = "0.26.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strum_macros"
|
||||||
|
version = "0.26.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be"
|
||||||
|
dependencies = [
|
||||||
|
"heck 0.5.0",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"rustversion",
|
||||||
|
"syn 2.0.66",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
|
|
|
@ -6,7 +6,7 @@ use nac3core::{
|
||||||
CodeGenContext, CodeGenerator,
|
CodeGenContext, CodeGenerator,
|
||||||
},
|
},
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{helper::PRIMITIVE_DEF_IDS, DefinitionId, GenCall},
|
toplevel::{helper::PrimDef, DefinitionId, GenCall},
|
||||||
typecheck::typedef::{FunSignature, FuncArg, Type, TypeEnum, VarMap},
|
typecheck::typedef::{FunSignature, FuncArg, Type, TypeEnum, VarMap},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -683,7 +683,7 @@ pub fn attributes_writeback(
|
||||||
let args: Vec<_> =
|
let args: Vec<_> =
|
||||||
values.into_iter().map(|(_, val)| (None, ValueEnum::Dynamic(val))).collect();
|
values.into_iter().map(|(_, val)| (None, ValueEnum::Dynamic(val))).collect();
|
||||||
if let Err(e) =
|
if let Err(e) =
|
||||||
rpc_codegen_callback_fn(ctx, None, (&fun, PRIMITIVE_DEF_IDS.int32), args, generator)
|
rpc_codegen_callback_fn(ctx, None, (&fun, PrimDef::Int32.id()), args, generator)
|
||||||
{
|
{
|
||||||
return Ok(Err(e));
|
return Ok(Err(e));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use nac3core::{
|
||||||
codegen::{CodeGenContext, CodeGenerator},
|
codegen::{CodeGenContext, CodeGenerator},
|
||||||
symbol_resolver::{StaticValue, SymbolResolver, SymbolValue, ValueEnum},
|
symbol_resolver::{StaticValue, SymbolResolver, SymbolValue, ValueEnum},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimDef,
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
DefinitionId, TopLevelDef,
|
DefinitionId, TopLevelDef,
|
||||||
},
|
},
|
||||||
|
@ -473,7 +473,7 @@ impl InnerResolver {
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
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 == PRIMITIVE_DEF_IDS.ndarray => {
|
(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 {
|
||||||
|
|
|
@ -11,6 +11,8 @@ indexmap = "2.2"
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
rayon = "1.8"
|
rayon = "1.8"
|
||||||
nac3parser = { path = "../nac3parser" }
|
nac3parser = { path = "../nac3parser" }
|
||||||
|
strum = "0.26.2"
|
||||||
|
strum_macros = "0.26.4"
|
||||||
|
|
||||||
[dependencies.inkwell]
|
[dependencies.inkwell]
|
||||||
version = "0.4"
|
version = "0.4"
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::codegen::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::codegen::{extern_fns, irrt, llvm_intrinsics, numpy, CodeGenContext, CodeGenerator};
|
use crate::codegen::{extern_fns, irrt, llvm_intrinsics, numpy, CodeGenContext, CodeGenerator};
|
||||||
use crate::toplevel::helper::PRIMITIVE_DEF_IDS;
|
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;
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ pub fn call_int32<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ pub fn call_int64<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ pub fn call_uint32<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ pub fn call_uint64<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ pub fn call_float<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -383,7 +383,7 @@ pub fn call_round<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -423,7 +423,7 @@ pub fn call_numpy_round<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -488,7 +488,7 @@ pub fn call_bool<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -542,7 +542,7 @@ pub fn call_floor<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -592,7 +592,7 @@ pub fn call_ceil<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -690,7 +690,7 @@ pub fn call_numpy_min<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if a_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
@ -783,13 +783,13 @@ pub fn call_numpy_minimum<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).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);
|
||||||
|
@ -906,7 +906,7 @@ pub fn call_numpy_max<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if a_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
@ -999,13 +999,13 @@ pub fn call_numpy_maximum<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).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);
|
||||||
|
@ -1086,7 +1086,7 @@ pub fn call_abs<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(n)
|
BasicValueEnum::PointerValue(n)
|
||||||
if n_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1126,7 +1126,7 @@ pub fn call_numpy_isnan<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1170,7 +1170,7 @@ pub fn call_numpy_isinf<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1214,7 +1214,7 @@ pub fn call_numpy_sin<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1254,7 +1254,7 @@ pub fn call_numpy_cos<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1294,7 +1294,7 @@ pub fn call_numpy_exp<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1334,7 +1334,7 @@ pub fn call_numpy_exp2<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1374,7 +1374,7 @@ pub fn call_numpy_log<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1414,7 +1414,7 @@ pub fn call_numpy_log10<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1454,7 +1454,7 @@ pub fn call_numpy_log2<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1494,7 +1494,7 @@ pub fn call_numpy_fabs<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1534,7 +1534,7 @@ pub fn call_numpy_sqrt<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1574,7 +1574,7 @@ pub fn call_numpy_rint<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1614,7 +1614,7 @@ pub fn call_numpy_tan<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1654,7 +1654,7 @@ pub fn call_numpy_arcsin<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1694,7 +1694,7 @@ pub fn call_numpy_arccos<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1734,7 +1734,7 @@ pub fn call_numpy_arctan<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1774,7 +1774,7 @@ pub fn call_numpy_sinh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1814,7 +1814,7 @@ pub fn call_numpy_cosh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1854,7 +1854,7 @@ pub fn call_numpy_tanh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1894,7 +1894,7 @@ pub fn call_numpy_arcsinh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1934,7 +1934,7 @@ pub fn call_numpy_arccosh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -1974,7 +1974,7 @@ pub fn call_numpy_arctanh<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2014,7 +2014,7 @@ pub fn call_numpy_expm1<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2054,7 +2054,7 @@ pub fn call_numpy_cbrt<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2094,7 +2094,7 @@ pub fn call_scipy_special_erf<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(z)
|
BasicValueEnum::PointerValue(z)
|
||||||
if z_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2134,7 +2134,7 @@ pub fn call_scipy_special_erfc<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2174,7 +2174,7 @@ pub fn call_scipy_special_gamma<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(z)
|
BasicValueEnum::PointerValue(z)
|
||||||
if z_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2214,7 +2214,7 @@ pub fn call_scipy_special_gammaln<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2254,7 +2254,7 @@ pub fn call_scipy_special_j0<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2294,7 +2294,7 @@ pub fn call_scipy_special_j1<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicValueEnum::PointerValue(x)
|
BasicValueEnum::PointerValue(x)
|
||||||
if x_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) =>
|
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);
|
||||||
|
|
||||||
|
@ -2336,13 +2336,13 @@ pub fn call_numpy_arctan2<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).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);
|
||||||
|
@ -2403,13 +2403,13 @@ pub fn call_numpy_copysign<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).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);
|
||||||
|
@ -2470,13 +2470,13 @@ pub fn call_numpy_fmax<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).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);
|
||||||
|
@ -2537,13 +2537,13 @@ pub fn call_numpy_fmin<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).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);
|
||||||
|
@ -2604,13 +2604,13 @@ pub fn call_numpy_ldexp<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
|
|
||||||
let dtype =
|
let dtype =
|
||||||
if is_ndarray1 { unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty).0 } else { x1_ty };
|
if is_ndarray1 { unpack_ndarray_var_tys(&mut ctx.unifier, x1_ty).0 } else { x1_ty };
|
||||||
|
@ -2660,13 +2660,13 @@ pub fn call_numpy_hypot<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).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);
|
||||||
|
@ -2727,13 +2727,13 @@ pub fn call_numpy_nextafter<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
|
|
||||||
(x1, x2)
|
(x1, x2)
|
||||||
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
if [&x1_ty, &x2_ty].into_iter().any(|ty| {
|
||||||
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
}) =>
|
}) =>
|
||||||
{
|
{
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x1_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
x2_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
x2_ty.obj_id(&ctx.unifier).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);
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
symbol_resolver::{SymbolValue, ValueEnum},
|
symbol_resolver::{SymbolValue, ValueEnum},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimDef,
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
DefinitionId, TopLevelDef,
|
DefinitionId, TopLevelDef,
|
||||||
},
|
},
|
||||||
|
@ -1181,15 +1181,13 @@ pub fn gen_binop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
Some("f_pow_i"),
|
Some("f_pow_i"),
|
||||||
);
|
);
|
||||||
Ok(Some(res.into()))
|
Ok(Some(res.into()))
|
||||||
} else if ty1.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
} 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 == PRIMITIVE_DEF_IDS.ndarray)
|
|| 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 =
|
let is_ndarray1 = ty1.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
ty1.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_ndarray2 = ty2.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
|
||||||
ty2.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -1427,7 +1425,7 @@ pub fn gen_unaryop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
_ => val.into(),
|
_ => val.into(),
|
||||||
}
|
}
|
||||||
} else if ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
} else if ty.obj_id(&ctx.unifier).is_some_and(|id| id == 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);
|
||||||
|
|
||||||
|
@ -1435,16 +1433,15 @@ 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 =
|
let op = if ndarray_dtype.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::Bool.id()) {
|
||||||
if ndarray_dtype.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.bool) {
|
if op == ast::Unaryop::Invert {
|
||||||
if op == ast::Unaryop::Invert {
|
ast::Unaryop::Not
|
||||||
ast::Unaryop::Not
|
|
||||||
} else {
|
|
||||||
unreachable!("ufunc {} not supported for ndarray[bool, N]", unaryop_name(op))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
op
|
unreachable!("ufunc {} not supported for ndarray[bool, N]", unaryop_name(op))
|
||||||
};
|
}
|
||||||
|
} else {
|
||||||
|
op
|
||||||
|
};
|
||||||
|
|
||||||
let res = numpy::ndarray_elementwise_unaryop_impl(
|
let res = numpy::ndarray_elementwise_unaryop_impl(
|
||||||
generator,
|
generator,
|
||||||
|
@ -1499,8 +1496,8 @@ pub fn gen_cmpop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
let left_ty = ctx.unifier.get_representative(left.0.unwrap());
|
let left_ty = ctx.unifier.get_representative(left.0.unwrap());
|
||||||
let right_ty = ctx.unifier.get_representative(comparators[0].0.unwrap());
|
let right_ty = ctx.unifier.get_representative(comparators[0].0.unwrap());
|
||||||
|
|
||||||
if left_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
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 == PRIMITIVE_DEF_IDS.ndarray)
|
|| 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);
|
||||||
|
|
||||||
|
@ -1509,9 +1506,9 @@ pub fn gen_cmpop_expr_with_values<'ctx, G: CodeGenerator>(
|
||||||
let op = ops[0];
|
let op = ops[0];
|
||||||
|
|
||||||
let is_ndarray1 =
|
let is_ndarray1 =
|
||||||
left_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
left_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_ndarray2 =
|
let is_ndarray2 =
|
||||||
right_ty.obj_id(&ctx.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
right_ty.obj_id(&ctx.unifier).is_some_and(|id| id == 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);
|
||||||
|
@ -2518,7 +2515,7 @@ pub fn gen_expr<'ctx, G: CodeGenerator>(
|
||||||
v.data().get(ctx, generator, &index, None).into()
|
v.data().get(ctx, generator, &index, None).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, params, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, params, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
let (ty, ndims) = params.iter().map(|(_, ty)| ty).collect_tuple().unwrap();
|
let (ty, ndims) = params.iter().map(|(_, ty)| ty).collect_tuple().unwrap();
|
||||||
|
|
||||||
let v = if let Some(v) = generator.gen_expr(ctx, value)? {
|
let v = if let Some(v) = generator.gen_expr(ctx, value)? {
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
codegen::classes::{ListType, NDArrayType, ProxyType, RangeType},
|
codegen::classes::{ListType, NDArrayType, ProxyType, RangeType},
|
||||||
symbol_resolver::{StaticValue, SymbolResolver},
|
symbol_resolver::{StaticValue, SymbolResolver},
|
||||||
toplevel::{
|
toplevel::{helper::PrimDef, numpy::unpack_ndarray_var_tys, TopLevelContext, TopLevelDef},
|
||||||
helper::PRIMITIVE_DEF_IDS, numpy::unpack_ndarray_var_tys, TopLevelContext, TopLevelDef,
|
|
||||||
},
|
|
||||||
typecheck::{
|
typecheck::{
|
||||||
type_inferencer::{CodeLocation, PrimitiveStore},
|
type_inferencer::{CodeLocation, PrimitiveStore},
|
||||||
typedef::{CallId, FuncArg, Type, TypeEnum, Unifier},
|
typedef::{CallId, FuncArg, Type, TypeEnum, Unifier},
|
||||||
|
@ -437,9 +435,9 @@ fn get_llvm_type<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
let result = match &*ty_enum {
|
let result = match &*ty_enum {
|
||||||
TObj { obj_id, fields, .. } => {
|
TObj { obj_id, fields, .. } => {
|
||||||
// check to avoid treating non-class primitives as classes
|
// check to avoid treating non-class primitives as classes
|
||||||
if obj_id.0 <= PRIMITIVE_DEF_IDS.max_id().0 {
|
if 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 == PRIMITIVE_DEF_IDS.option => {
|
TObj { obj_id, params, .. } if *obj_id == PrimDef::Option.id() => {
|
||||||
get_llvm_type(
|
get_llvm_type(
|
||||||
ctx,
|
ctx,
|
||||||
module,
|
module,
|
||||||
|
@ -453,7 +451,7 @@ fn get_llvm_type<'ctx, G: CodeGenerator + ?Sized>(
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
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(
|
||||||
ctx, module, generator, unifier, top_level, type_cache, dtype,
|
ctx, module, generator, unifier, top_level, type_cache, dtype,
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PRIMITIVE_DEF_IDS,
|
helper::PrimDef,
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
DefinitionId,
|
DefinitionId,
|
||||||
},
|
},
|
||||||
|
@ -1775,7 +1775,7 @@ pub fn gen_ndarray_array<'ctx>(
|
||||||
|
|
||||||
let obj_ty = fun.0.args[0].ty;
|
let obj_ty = fun.0.args[0].ty;
|
||||||
let obj_elem_ty = match &*context.unifier.get_ty(obj_ty) {
|
let obj_elem_ty = match &*context.unifier.get_ty(obj_ty) {
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
unpack_ndarray_var_tys(&mut context.unifier, obj_ty).0
|
unpack_ndarray_var_tys(&mut context.unifier, obj_ty).0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,7 @@ use crate::{
|
||||||
expr::gen_binop_expr,
|
expr::gen_binop_expr,
|
||||||
gen_in_range_check,
|
gen_in_range_check,
|
||||||
},
|
},
|
||||||
toplevel::{
|
toplevel::{helper::PrimDef, numpy::unpack_ndarray_var_tys, DefinitionId, TopLevelDef},
|
||||||
helper::PRIMITIVE_DEF_IDS, numpy::unpack_ndarray_var_tys, DefinitionId, TopLevelDef,
|
|
||||||
},
|
|
||||||
typecheck::typedef::{FunSignature, Type, TypeEnum},
|
typecheck::typedef::{FunSignature, Type, TypeEnum},
|
||||||
};
|
};
|
||||||
use inkwell::{
|
use inkwell::{
|
||||||
|
@ -188,7 +186,7 @@ pub fn gen_store_target<'ctx, G: CodeGenerator>(
|
||||||
v.data().ptr_offset(ctx, generator, &index, name)
|
v.data().ptr_offset(ctx, generator, &index, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +244,7 @@ pub fn gen_assign<'ctx, G: CodeGenerator>(
|
||||||
let value = ListValue::from_ptr_val(value, llvm_usize, None);
|
let value = ListValue::from_ptr_val(value, llvm_usize, None);
|
||||||
let ty = match &*ctx.unifier.get_ty_immutable(target.custom.unwrap()) {
|
let ty = match &*ctx.unifier.get_ty_immutable(target.custom.unwrap()) {
|
||||||
TypeEnum::TList { ty } => *ty,
|
TypeEnum::TList { ty } => *ty,
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == 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
|
@ -4,75 +4,270 @@ use crate::symbol_resolver::SymbolValue;
|
||||||
use crate::toplevel::numpy::unpack_ndarray_var_tys;
|
use crate::toplevel::numpy::unpack_ndarray_var_tys;
|
||||||
use crate::typecheck::typedef::{Mapping, VarMap};
|
use crate::typecheck::typedef::{Mapping, VarMap};
|
||||||
use nac3parser::ast::{Constant, Location};
|
use nac3parser::ast::{Constant, Location};
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
use strum_macros::EnumIter;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// Structure storing [`DefinitionId`] for primitive types.
|
/// All primitive types and functions in nac3core.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug, EnumIter, PartialEq, Eq)]
|
||||||
pub struct PrimitiveDefinitionIds {
|
pub enum PrimDef {
|
||||||
pub int32: DefinitionId,
|
Int32,
|
||||||
pub int64: DefinitionId,
|
Int64,
|
||||||
pub uint32: DefinitionId,
|
Float,
|
||||||
pub uint64: DefinitionId,
|
Bool,
|
||||||
pub float: DefinitionId,
|
None,
|
||||||
pub bool: DefinitionId,
|
Range,
|
||||||
pub none: DefinitionId,
|
Str,
|
||||||
pub range: DefinitionId,
|
Exception,
|
||||||
pub str: DefinitionId,
|
UInt32,
|
||||||
pub exception: DefinitionId,
|
UInt64,
|
||||||
pub option: DefinitionId,
|
Option,
|
||||||
pub ndarray: DefinitionId,
|
OptionIsSome,
|
||||||
|
OptionIsNone,
|
||||||
|
OptionUnwrap,
|
||||||
|
NDArray,
|
||||||
|
NDArrayCopy,
|
||||||
|
NDArrayFill,
|
||||||
|
FunInt32,
|
||||||
|
FunInt64,
|
||||||
|
FunUInt32,
|
||||||
|
FunUInt64,
|
||||||
|
FunFloat,
|
||||||
|
FunNpNDArray,
|
||||||
|
FunNpEmpty,
|
||||||
|
FunNpZeros,
|
||||||
|
FunNpOnes,
|
||||||
|
FunNpFull,
|
||||||
|
FunNpArray,
|
||||||
|
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 PrimitiveDefinitionIds {
|
/// Associated details of a [`PrimDef`]
|
||||||
/// Returns all [`DefinitionId`] of primitives as a [`Vec`].
|
pub enum PrimDefDetails {
|
||||||
|
PrimFunction { name: &'static str, simple_name: &'static str },
|
||||||
|
PrimClass { name: &'static str },
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PrimDef {
|
||||||
|
/// Get the assigned [`DefinitionId`] of this [`PrimDef`].
|
||||||
///
|
///
|
||||||
/// There are no guarantees on ordering of the IDs.
|
/// 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`.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn as_vec(&self) -> Vec<DefinitionId> {
|
pub fn id(&self) -> DefinitionId {
|
||||||
vec![
|
DefinitionId(*self as usize)
|
||||||
self.int32,
|
|
||||||
self.int64,
|
|
||||||
self.uint32,
|
|
||||||
self.uint64,
|
|
||||||
self.float,
|
|
||||||
self.bool,
|
|
||||||
self.none,
|
|
||||||
self.range,
|
|
||||||
self.str,
|
|
||||||
self.exception,
|
|
||||||
self.option,
|
|
||||||
self.ndarray,
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all [`DefinitionId`]s of this instance in indeterminate order.
|
/// Check if a definition ID is that of a [`PrimDef`].
|
||||||
pub fn iter(&self) -> impl Iterator<Item = DefinitionId> {
|
#[must_use]
|
||||||
self.as_vec().into_iter()
|
pub fn contains_id(id: DefinitionId) -> bool {
|
||||||
|
Self::iter().any(|prim| prim.id() == id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the primitive with the largest [`DefinitionId`].
|
/// 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 returns [`None`].
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn max_id(&self) -> DefinitionId {
|
pub fn simple_name(&self) -> &'static str {
|
||||||
self.iter().max().unwrap()
|
match self.details() {
|
||||||
|
PrimDefDetails::PrimFunction { simple_name, .. } => simple_name,
|
||||||
|
PrimDefDetails::PrimClass { .. } => {
|
||||||
|
panic!("PrimDef {self:?} has no simple_name as it is not a function.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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`].
|
||||||
|
#[must_use]
|
||||||
|
pub fn name(&self) -> &'static str {
|
||||||
|
match self.details() {
|
||||||
|
PrimDefDetails::PrimFunction { name, .. } | PrimDefDetails::PrimClass { name } => name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the associated details of this [`PrimDef`]
|
||||||
|
#[must_use]
|
||||||
|
pub fn details(self) -> PrimDefDetails {
|
||||||
|
fn class(name: &'static str) -> PrimDefDetails {
|
||||||
|
PrimDefDetails::PrimClass { name }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fun(name: &'static str, simple_name: Option<&'static str>) -> PrimDefDetails {
|
||||||
|
PrimDefDetails::PrimFunction { simple_name: simple_name.unwrap_or(name), name }
|
||||||
|
}
|
||||||
|
|
||||||
|
match self {
|
||||||
|
PrimDef::Int32 => class("int32"),
|
||||||
|
PrimDef::Int64 => class("int64"),
|
||||||
|
PrimDef::Float => class("float"),
|
||||||
|
PrimDef::Bool => class("bool"),
|
||||||
|
PrimDef::None => class("none"),
|
||||||
|
PrimDef::Range => class("range"),
|
||||||
|
PrimDef::Str => class("str"),
|
||||||
|
PrimDef::Exception => class("Exception"),
|
||||||
|
PrimDef::UInt32 => class("uint32"),
|
||||||
|
PrimDef::UInt64 => class("uint64"),
|
||||||
|
PrimDef::Option => class("Option"),
|
||||||
|
PrimDef::OptionIsSome => fun("Option.is_some", Some("is_some")),
|
||||||
|
PrimDef::OptionIsNone => fun("Option.is_none", Some("is_none")),
|
||||||
|
PrimDef::OptionUnwrap => fun("Option.unwrap", Some("unwrap")),
|
||||||
|
PrimDef::NDArray => class("ndarray"),
|
||||||
|
PrimDef::NDArrayCopy => fun("ndarray.copy", Some("copy")),
|
||||||
|
PrimDef::NDArrayFill => fun("ndarray.fill", Some("fill")),
|
||||||
|
PrimDef::FunInt32 => fun("int32", None),
|
||||||
|
PrimDef::FunInt64 => fun("int64", None),
|
||||||
|
PrimDef::FunUInt32 => fun("uint32", None),
|
||||||
|
PrimDef::FunUInt64 => fun("uint64", None),
|
||||||
|
PrimDef::FunFloat => fun("float", None),
|
||||||
|
PrimDef::FunNpNDArray => fun("np_ndarray", None),
|
||||||
|
PrimDef::FunNpEmpty => fun("np_empty", None),
|
||||||
|
PrimDef::FunNpZeros => fun("np_zeros", None),
|
||||||
|
PrimDef::FunNpOnes => fun("np_ones", None),
|
||||||
|
PrimDef::FunNpFull => fun("np_full", None),
|
||||||
|
PrimDef::FunNpArray => fun("np_array", None),
|
||||||
|
PrimDef::FunNpEye => fun("np_eye", None),
|
||||||
|
PrimDef::FunNpIdentity => fun("np_identity", None),
|
||||||
|
PrimDef::FunRound => fun("round", None),
|
||||||
|
PrimDef::FunRound64 => fun("round64", None),
|
||||||
|
PrimDef::FunNpRound => fun("np_round", None),
|
||||||
|
PrimDef::FunRange => fun("range", None),
|
||||||
|
PrimDef::FunStr => fun("str", None),
|
||||||
|
PrimDef::FunBool => fun("bool", None),
|
||||||
|
PrimDef::FunFloor => fun("floor", None),
|
||||||
|
PrimDef::FunFloor64 => fun("floor64", None),
|
||||||
|
PrimDef::FunNpFloor => fun("np_floor", None),
|
||||||
|
PrimDef::FunCeil => fun("ceil", None),
|
||||||
|
PrimDef::FunCeil64 => fun("ceil64", None),
|
||||||
|
PrimDef::FunNpCeil => fun("np_ceil", None),
|
||||||
|
PrimDef::FunLen => fun("len", None),
|
||||||
|
PrimDef::FunMin => fun("min", None),
|
||||||
|
PrimDef::FunNpMin => fun("np_min", None),
|
||||||
|
PrimDef::FunNpMinimum => fun("np_minimum", None),
|
||||||
|
PrimDef::FunMax => fun("max", None),
|
||||||
|
PrimDef::FunNpMax => fun("np_max", None),
|
||||||
|
PrimDef::FunNpMaximum => fun("np_maximum", None),
|
||||||
|
PrimDef::FunAbs => fun("abs", None),
|
||||||
|
PrimDef::FunNpIsNan => fun("np_isnan", None),
|
||||||
|
PrimDef::FunNpIsInf => fun("np_isinf", None),
|
||||||
|
PrimDef::FunNpSin => fun("np_sin", None),
|
||||||
|
PrimDef::FunNpCos => fun("np_cos", None),
|
||||||
|
PrimDef::FunNpExp => fun("np_exp", None),
|
||||||
|
PrimDef::FunNpExp2 => fun("np_exp2", None),
|
||||||
|
PrimDef::FunNpLog => fun("np_log", None),
|
||||||
|
PrimDef::FunNpLog10 => fun("np_log10", None),
|
||||||
|
PrimDef::FunNpLog2 => fun("np_log2", None),
|
||||||
|
PrimDef::FunNpFabs => fun("np_fabs", None),
|
||||||
|
PrimDef::FunNpSqrt => fun("np_sqrt", None),
|
||||||
|
PrimDef::FunNpRint => fun("np_rint", None),
|
||||||
|
PrimDef::FunNpTan => fun("np_tan", None),
|
||||||
|
PrimDef::FunNpArcsin => fun("np_arcsin", None),
|
||||||
|
PrimDef::FunNpArccos => fun("np_arccos", None),
|
||||||
|
PrimDef::FunNpArctan => fun("np_arctan", None),
|
||||||
|
PrimDef::FunNpSinh => fun("np_sinh", None),
|
||||||
|
PrimDef::FunNpCosh => fun("np_cosh", None),
|
||||||
|
PrimDef::FunNpTanh => fun("np_tanh", None),
|
||||||
|
PrimDef::FunNpArcsinh => fun("np_arcsinh", None),
|
||||||
|
PrimDef::FunNpArccosh => fun("np_arccosh", None),
|
||||||
|
PrimDef::FunNpArctanh => fun("np_arctanh", None),
|
||||||
|
PrimDef::FunNpExpm1 => fun("np_expm1", None),
|
||||||
|
PrimDef::FunNpCbrt => fun("np_cbrt", None),
|
||||||
|
PrimDef::FunSpSpecErf => fun("sp_spec_erf", None),
|
||||||
|
PrimDef::FunSpSpecErfc => fun("sp_spec_erfc", None),
|
||||||
|
PrimDef::FunSpSpecGamma => fun("sp_spec_gamma", None),
|
||||||
|
PrimDef::FunSpSpecGammaln => fun("sp_spec_gammaln", None),
|
||||||
|
PrimDef::FunSpSpecJ0 => fun("sp_spec_j0", None),
|
||||||
|
PrimDef::FunSpSpecJ1 => fun("sp_spec_j1", None),
|
||||||
|
PrimDef::FunNpArctan2 => fun("np_arctan2", None),
|
||||||
|
PrimDef::FunNpCopysign => fun("np_copysign", None),
|
||||||
|
PrimDef::FunNpFmax => fun("np_fmax", None),
|
||||||
|
PrimDef::FunNpFmin => fun("np_fmin", None),
|
||||||
|
PrimDef::FunNpLdExp => fun("np_ldexp", None),
|
||||||
|
PrimDef::FunNpHypot => fun("np_hypot", None),
|
||||||
|
PrimDef::FunNpNextAfter => fun("np_nextafter", None),
|
||||||
|
PrimDef::FunSome => fun("Some", None),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The [definition IDs][DefinitionId] for primitive types.
|
/// Asserts that a [`PrimDef`] is in an allowlist.
|
||||||
pub const PRIMITIVE_DEF_IDS: PrimitiveDefinitionIds = PrimitiveDefinitionIds {
|
///
|
||||||
int32: DefinitionId(0),
|
/// Like `debug_assert!`, this statements of this function are only
|
||||||
int64: DefinitionId(1),
|
/// enabled if `cfg!(debug_assertions)` is true.
|
||||||
uint32: DefinitionId(8),
|
pub fn debug_assert_prim_is_allowed(prim: PrimDef, allowlist: &[PrimDef]) {
|
||||||
uint64: DefinitionId(9),
|
if cfg!(debug_assertions) {
|
||||||
float: DefinitionId(2),
|
let allowed = allowlist.iter().any(|p| *p == prim);
|
||||||
bool: DefinitionId(3),
|
assert!(
|
||||||
none: DefinitionId(4),
|
allowed,
|
||||||
range: DefinitionId(5),
|
"Disallowed primitive definition. Got {prim:?}, but expects it to be in {allowlist:?}"
|
||||||
str: DefinitionId(6),
|
);
|
||||||
exception: DefinitionId(7),
|
}
|
||||||
option: DefinitionId(10),
|
}
|
||||||
ndarray: DefinitionId(14),
|
|
||||||
};
|
|
||||||
|
|
||||||
impl TopLevelDef {
|
impl TopLevelDef {
|
||||||
pub fn to_string(&self, unifier: &mut Unifier) -> String {
|
pub fn to_string(&self, unifier: &mut Unifier) -> String {
|
||||||
|
@ -116,42 +311,42 @@ impl TopLevelComposer {
|
||||||
pub fn make_primitives(size_t: u32) -> (PrimitiveStore, Unifier) {
|
pub fn make_primitives(size_t: u32) -> (PrimitiveStore, Unifier) {
|
||||||
let mut unifier = Unifier::new();
|
let mut unifier = Unifier::new();
|
||||||
let int32 = unifier.add_ty(TypeEnum::TObj {
|
let int32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int32,
|
obj_id: 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: PRIMITIVE_DEF_IDS.int64,
|
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: PRIMITIVE_DEF_IDS.float,
|
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: PRIMITIVE_DEF_IDS.bool,
|
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: PRIMITIVE_DEF_IDS.none,
|
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: PRIMITIVE_DEF_IDS.range,
|
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: PRIMITIVE_DEF_IDS.str,
|
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: PRIMITIVE_DEF_IDS.exception,
|
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)),
|
||||||
|
@ -168,12 +363,12 @@ impl TopLevelComposer {
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
let uint32 = unifier.add_ty(TypeEnum::TObj {
|
let uint32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.uint32,
|
obj_id: 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: PRIMITIVE_DEF_IDS.uint64,
|
obj_id: PrimDef::UInt64.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
@ -190,7 +385,7 @@ impl TopLevelComposer {
|
||||||
vars: VarMap::from([(option_type_var.1, option_type_var.0)]),
|
vars: VarMap::from([(option_type_var.1, option_type_var.0)]),
|
||||||
}));
|
}));
|
||||||
let option = unifier.add_ty(TypeEnum::TObj {
|
let option = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.option,
|
obj_id: 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)),
|
||||||
|
@ -232,7 +427,7 @@ impl TopLevelComposer {
|
||||||
]),
|
]),
|
||||||
}));
|
}));
|
||||||
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.ndarray,
|
obj_id: 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)),
|
||||||
|
@ -689,7 +884,7 @@ pub fn parse_parameter_default_value(
|
||||||
/// Obtains the element type of an array-like type.
|
/// Obtains the element type of an array-like type.
|
||||||
pub fn arraylike_flatten_element_type(unifier: &mut Unifier, ty: Type) -> Type {
|
pub fn arraylike_flatten_element_type(unifier: &mut Unifier, ty: Type) -> Type {
|
||||||
match &*unifier.get_ty(ty) {
|
match &*unifier.get_ty(ty) {
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
unpack_ndarray_var_tys(unifier, ty).0
|
unpack_ndarray_var_tys(unifier, ty).0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,7 +896,7 @@ pub fn arraylike_flatten_element_type(unifier: &mut Unifier, ty: Type) -> Type {
|
||||||
/// Obtains the number of dimensions of an array-like type.
|
/// Obtains the number of dimensions of an array-like type.
|
||||||
pub fn arraylike_get_ndims(unifier: &mut Unifier, ty: Type) -> u64 {
|
pub fn arraylike_get_ndims(unifier: &mut Unifier, ty: Type) -> u64 {
|
||||||
match &*unifier.get_ty(ty) {
|
match &*unifier.get_ty(ty) {
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
let ndims = unpack_ndarray_var_tys(unifier, ty).1;
|
let ndims = unpack_ndarray_var_tys(unifier, ty).1;
|
||||||
let TypeEnum::TLiteral { values, .. } = &*unifier.get_ty_immutable(ndims) else {
|
let TypeEnum::TLiteral { values, .. } = &*unifier.get_ty_immutable(ndims) else {
|
||||||
panic!("Expected TLiteral for ndarray.ndims, got {}", unifier.stringify(ndims))
|
panic!("Expected TLiteral for ndarray.ndims, got {}", unifier.stringify(ndims))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
toplevel::helper::PRIMITIVE_DEF_IDS,
|
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, PRIMITIVE_DEF_IDS.ndarray);
|
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;
|
||||||
|
@ -61,7 +61,7 @@ fn unpack_ndarray_tvars(unifier: &mut Unifier, ndarray: Type) -> Vec<(u32, Type)
|
||||||
let TypeEnum::TObj { obj_id, params, .. } = &*unifier.get_ty_immutable(ndarray) else {
|
let TypeEnum::TObj { obj_id, params, .. } = &*unifier.get_ty_immutable(ndarray) else {
|
||||||
panic!("Expected `ndarray` to be TObj, but got {}", unifier.stringify(ndarray))
|
panic!("Expected `ndarray` to be TObj, but got {}", unifier.stringify(ndarray))
|
||||||
};
|
};
|
||||||
debug_assert_eq!(*obj_id, PRIMITIVE_DEF_IDS.ndarray);
|
debug_assert_eq!(*obj_id, PrimDef::NDArray.id());
|
||||||
debug_assert_eq!(params.len(), 2);
|
debug_assert_eq!(params.len(), 2);
|
||||||
|
|
||||||
params
|
params
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::symbol_resolver::SymbolValue;
|
use crate::symbol_resolver::SymbolValue;
|
||||||
use crate::toplevel::helper::PRIMITIVE_DEF_IDS;
|
use crate::toplevel::helper::PrimDef;
|
||||||
use crate::typecheck::typedef::VarMap;
|
use crate::typecheck::typedef::VarMap;
|
||||||
use nac3parser::ast::Constant;
|
use nac3parser::ast::Constant;
|
||||||
|
|
||||||
|
@ -95,10 +95,7 @@ pub fn parse_ast_to_type_annotation_kinds<T, S: std::hash::BuildHasher + Clone>(
|
||||||
} 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 {
|
Ok(TypeAnnotation::CustomClass { id: PrimDef::Exception.id(), params: Vec::default() })
|
||||||
id: PRIMITIVE_DEF_IDS.exception,
|
|
||||||
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,5 +1,5 @@
|
||||||
use crate::symbol_resolver::SymbolValue;
|
use crate::symbol_resolver::SymbolValue;
|
||||||
use crate::toplevel::helper::PRIMITIVE_DEF_IDS;
|
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::*,
|
||||||
|
@ -11,6 +11,7 @@ use nac3parser::ast::{Cmpop, Operator, Unaryop};
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn binop_name(op: Operator) -> &'static str {
|
pub fn binop_name(op: Operator) -> &'static str {
|
||||||
|
@ -360,8 +361,8 @@ pub fn typeof_ndarray_broadcast(
|
||||||
left: Type,
|
left: Type,
|
||||||
right: Type,
|
right: Type,
|
||||||
) -> Result<Type, String> {
|
) -> Result<Type, String> {
|
||||||
let is_left_ndarray = left.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_left_ndarray = left.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_right_ndarray = right.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_right_ndarray = right.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
|
|
||||||
assert!(is_left_ndarray || is_right_ndarray);
|
assert!(is_left_ndarray || is_right_ndarray);
|
||||||
|
|
||||||
|
@ -428,8 +429,8 @@ pub fn typeof_binop(
|
||||||
lhs: Type,
|
lhs: Type,
|
||||||
rhs: Type,
|
rhs: Type,
|
||||||
) -> Result<Option<Type>, String> {
|
) -> Result<Option<Type>, String> {
|
||||||
let is_left_ndarray = lhs.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_left_ndarray = lhs.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_right_ndarray = rhs.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_right_ndarray = rhs.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
|
|
||||||
Ok(Some(match op {
|
Ok(Some(match op {
|
||||||
Operator::Add | Operator::Sub | Operator::Mult | Operator::Mod | Operator::FloorDiv => {
|
Operator::Add | Operator::Sub | Operator::Mult | Operator::Mod | Operator::FloorDiv => {
|
||||||
|
@ -534,17 +535,15 @@ pub fn typeof_unaryop(
|
||||||
|
|
||||||
Ok(match op {
|
Ok(match op {
|
||||||
Unaryop::Not => match operand_obj_id {
|
Unaryop::Not => match operand_obj_id {
|
||||||
Some(v) if v == PRIMITIVE_DEF_IDS.ndarray => 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 == PRIMITIVE_DEF_IDS.bool) {
|
if operand_obj_id.is_some_and(|id| id == PrimDef::Bool.id()) {
|
||||||
Some(primitives.int32)
|
Some(primitives.int32)
|
||||||
} else if operand_obj_id
|
} else if operand_obj_id.is_some_and(|id| PrimDef::iter().any(|prim| id == prim.id())) {
|
||||||
.is_some_and(|id| PRIMITIVE_DEF_IDS.iter().any(|prim_id| id == prim_id))
|
|
||||||
{
|
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -552,9 +551,9 @@ pub fn typeof_unaryop(
|
||||||
}
|
}
|
||||||
|
|
||||||
Unaryop::UAdd | Unaryop::USub => {
|
Unaryop::UAdd | Unaryop::USub => {
|
||||||
if operand_obj_id.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
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 == PRIMITIVE_DEF_IDS.bool) {
|
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 {
|
||||||
|
@ -563,11 +562,9 @@ pub fn typeof_unaryop(
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else if operand_obj_id.is_some_and(|id| id == PRIMITIVE_DEF_IDS.bool) {
|
} else if operand_obj_id.is_some_and(|id| id == PrimDef::Bool.id()) {
|
||||||
Some(primitives.int32)
|
Some(primitives.int32)
|
||||||
} else if operand_obj_id
|
} else if operand_obj_id.is_some_and(|id| PrimDef::iter().any(|prim| id == prim.id())) {
|
||||||
.is_some_and(|id| PRIMITIVE_DEF_IDS.iter().any(|prim_id| id == prim_id))
|
|
||||||
{
|
|
||||||
Some(operand)
|
Some(operand)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -584,8 +581,8 @@ pub fn typeof_cmpop(
|
||||||
lhs: Type,
|
lhs: Type,
|
||||||
rhs: Type,
|
rhs: Type,
|
||||||
) -> Result<Option<Type>, String> {
|
) -> Result<Option<Type>, String> {
|
||||||
let is_left_ndarray = lhs.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_left_ndarray = lhs.obj_id(unifier).is_some_and(|id| id == PrimDef::NDArray.id());
|
||||||
let is_right_ndarray = rhs.obj_id(unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray);
|
let is_right_ndarray = rhs.obj_id(unifier).is_some_and(|id| id == 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::{arraylike_flatten_element_type, arraylike_get_ndims, PRIMITIVE_DEF_IDS},
|
helper::{arraylike_flatten_element_type, arraylike_get_ndims, PrimDef},
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
TopLevelContext,
|
TopLevelContext,
|
||||||
},
|
},
|
||||||
|
@ -244,7 +244,7 @@ impl<'a> Fold<()> for Inferencer<'a> {
|
||||||
TypeEnum::TList { .. } => {
|
TypeEnum::TList { .. } => {
|
||||||
self.unifier.add_ty(TypeEnum::TList { ty: target.custom.unwrap() })
|
self.unifier.add_ty(TypeEnum::TList { ty: target.custom.unwrap() })
|
||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -892,9 +892,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
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
.obj_id(self.unifier)
|
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
|
||||||
{
|
{
|
||||||
let (_, ndarray_ndims) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
let (_, ndarray_ndims) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
||||||
|
|
||||||
|
@ -932,14 +930,14 @@ 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 =
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
{
|
||||||
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
|
||||||
} else {
|
} else {
|
||||||
arg0_ty
|
arg0_ty
|
||||||
};
|
};
|
||||||
|
|
||||||
let custom = self.unifier.add_ty(TypeEnum::TFunc(FunSignature {
|
let custom = self.unifier.add_ty(TypeEnum::TFunc(FunSignature {
|
||||||
args: vec![FuncArg {
|
args: vec![FuncArg {
|
||||||
|
@ -987,14 +985,14 @@ impl<'a> Inferencer<'a> {
|
||||||
let arg1_ty = arg1.custom.unwrap();
|
let arg1_ty = arg1.custom.unwrap();
|
||||||
|
|
||||||
let arg0_dtype =
|
let arg0_dtype =
|
||||||
if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
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 =
|
let arg1_dtype =
|
||||||
if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray) {
|
if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == 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
|
||||||
|
@ -1020,15 +1018,12 @@ impl<'a> Inferencer<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret = if [&arg0_ty, &arg1_ty].into_iter().any(|arg_ty| {
|
let ret = if [&arg0_ty, &arg1_ty].into_iter().any(|arg_ty| {
|
||||||
arg_ty.obj_id(self.unifier).is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
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
|
if arg1_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::NDArray.id()) {
|
||||||
.obj_id(self.unifier)
|
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
|
||||||
{
|
|
||||||
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))
|
||||||
|
@ -1116,9 +1111,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
|
let ret = if arg0_ty.obj_id(self.unifier).is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
.obj_id(self.unifier)
|
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
|
||||||
{
|
{
|
||||||
let (_, ndarray_ndims) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
let (_, ndarray_ndims) = unpack_ndarray_var_tys(self.unifier, arg0_ty);
|
||||||
|
|
||||||
|
@ -1552,7 +1545,7 @@ impl<'a> Inferencer<'a> {
|
||||||
expr.custom
|
expr.custom
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.obj_id(self.unifier)
|
.obj_id(self.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
.is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
return Err(HashSet::from([String::from(
|
return Err(HashSet::from([String::from(
|
||||||
|
@ -1670,7 +1663,7 @@ impl<'a> Inferencer<'a> {
|
||||||
}
|
}
|
||||||
let list_like_ty = match &*self.unifier.get_ty(value.custom.unwrap()) {
|
let list_like_ty = match &*self.unifier.get_ty(value.custom.unwrap()) {
|
||||||
TypeEnum::TList { .. } => self.unifier.add_ty(TypeEnum::TList { ty }),
|
TypeEnum::TList { .. } => self.unifier.add_ty(TypeEnum::TList { ty }),
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
let (_, ndims) =
|
let (_, ndims) =
|
||||||
unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
||||||
|
|
||||||
|
@ -1684,7 +1677,7 @@ impl<'a> Inferencer<'a> {
|
||||||
}
|
}
|
||||||
ExprKind::Constant { value: ast::Constant::Int(val), .. } => {
|
ExprKind::Constant { value: ast::Constant::Int(val), .. } => {
|
||||||
match &*self.unifier.get_ty(value.custom.unwrap()) {
|
match &*self.unifier.get_ty(value.custom.unwrap()) {
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
let (_, ndims) =
|
let (_, ndims) =
|
||||||
unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
||||||
self.infer_subscript_ndarray(value, ty, ndims)
|
self.infer_subscript_ndarray(value, ty, ndims)
|
||||||
|
@ -1710,7 +1703,7 @@ impl<'a> Inferencer<'a> {
|
||||||
.custom
|
.custom
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.obj_id(self.unifier)
|
.obj_id(self.unifier)
|
||||||
.is_some_and(|id| id == PRIMITIVE_DEF_IDS.ndarray)
|
.is_some_and(|id| id == PrimDef::NDArray.id())
|
||||||
.not()
|
.not()
|
||||||
{
|
{
|
||||||
return report_error(
|
return report_error(
|
||||||
|
@ -1755,7 +1748,7 @@ impl<'a> Inferencer<'a> {
|
||||||
self.constrain(value.custom.unwrap(), list, &value.location)?;
|
self.constrain(value.custom.unwrap(), list, &value.location)?;
|
||||||
Ok(ty)
|
Ok(ty)
|
||||||
}
|
}
|
||||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {
|
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||||
let (_, ndims) =
|
let (_, ndims) =
|
||||||
unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
unpack_ndarray_var_tys(self.unifier, value.custom.unwrap());
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
codegen::CodeGenContext,
|
codegen::CodeGenContext,
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{helper::PRIMITIVE_DEF_IDS, DefinitionId, TopLevelDef},
|
toplevel::{helper::PrimDef, DefinitionId, TopLevelDef},
|
||||||
};
|
};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use nac3parser::parser::parse_program;
|
use nac3parser::parser::parse_program;
|
||||||
|
@ -75,7 +75,7 @@ impl TestEnvironment {
|
||||||
let mut unifier = Unifier::new();
|
let mut unifier = Unifier::new();
|
||||||
|
|
||||||
let int32 = unifier.add_ty(TypeEnum::TObj {
|
let int32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int32,
|
obj_id: PrimDef::Int32.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
@ -88,52 +88,52 @@ impl TestEnvironment {
|
||||||
fields.insert("__add__".into(), (add_ty, false));
|
fields.insert("__add__".into(), (add_ty, false));
|
||||||
});
|
});
|
||||||
let int64 = unifier.add_ty(TypeEnum::TObj {
|
let int64 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int64,
|
obj_id: 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: PRIMITIVE_DEF_IDS.float,
|
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: PRIMITIVE_DEF_IDS.bool,
|
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: PRIMITIVE_DEF_IDS.none,
|
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: PRIMITIVE_DEF_IDS.range,
|
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: PRIMITIVE_DEF_IDS.str,
|
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: PRIMITIVE_DEF_IDS.exception,
|
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: PRIMITIVE_DEF_IDS.uint32,
|
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: PRIMITIVE_DEF_IDS.uint64,
|
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: PRIMITIVE_DEF_IDS.option,
|
obj_id: PrimDef::Option.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
@ -141,7 +141,7 @@ impl TestEnvironment {
|
||||||
let ndarray_ndims_tvar =
|
let ndarray_ndims_tvar =
|
||||||
unifier.get_fresh_const_generic_var(uint64, Some("ndarray_ndims".into()), None);
|
unifier.get_fresh_const_generic_var(uint64, Some("ndarray_ndims".into()), None);
|
||||||
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
let ndarray = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.ndarray,
|
obj_id: 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),
|
||||||
|
@ -214,7 +214,7 @@ impl TestEnvironment {
|
||||||
let mut identifier_mapping = HashMap::new();
|
let mut identifier_mapping = HashMap::new();
|
||||||
let mut top_level_defs: Vec<Arc<RwLock<TopLevelDef>>> = Vec::new();
|
let mut top_level_defs: Vec<Arc<RwLock<TopLevelDef>>> = Vec::new();
|
||||||
let int32 = unifier.add_ty(TypeEnum::TObj {
|
let int32 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int32,
|
obj_id: PrimDef::Int32.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
@ -227,57 +227,57 @@ impl TestEnvironment {
|
||||||
fields.insert("__add__".into(), (add_ty, false));
|
fields.insert("__add__".into(), (add_ty, false));
|
||||||
});
|
});
|
||||||
let int64 = unifier.add_ty(TypeEnum::TObj {
|
let int64 = unifier.add_ty(TypeEnum::TObj {
|
||||||
obj_id: PRIMITIVE_DEF_IDS.int64,
|
obj_id: 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: PRIMITIVE_DEF_IDS.float,
|
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: PRIMITIVE_DEF_IDS.bool,
|
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: PRIMITIVE_DEF_IDS.none,
|
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: PRIMITIVE_DEF_IDS.range,
|
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: PRIMITIVE_DEF_IDS.str,
|
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: PRIMITIVE_DEF_IDS.exception,
|
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: PRIMITIVE_DEF_IDS.uint32,
|
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: PRIMITIVE_DEF_IDS.uint64,
|
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: PRIMITIVE_DEF_IDS.option,
|
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: PRIMITIVE_DEF_IDS.ndarray,
|
obj_id: PrimDef::NDArray.id(),
|
||||||
fields: HashMap::new(),
|
fields: HashMap::new(),
|
||||||
params: VarMap::new(),
|
params: VarMap::new(),
|
||||||
});
|
});
|
||||||
|
|
|
@ -144,22 +144,16 @@ pub enum ParseErrorType {
|
||||||
impl From<LalrpopError<Location, Tok, LexicalError>> for ParseError {
|
impl From<LalrpopError<Location, Tok, LexicalError>> for ParseError {
|
||||||
fn from(err: LalrpopError<Location, Tok, LexicalError>) -> Self {
|
fn from(err: LalrpopError<Location, Tok, LexicalError>) -> Self {
|
||||||
match err {
|
match err {
|
||||||
LalrpopError::ExtraToken { token } => ParseError {
|
LalrpopError::ExtraToken { token } => {
|
||||||
error: ParseErrorType::ExtraToken(token.1),
|
ParseError { error: ParseErrorType::ExtraToken(token.1), location: token.0 }
|
||||||
location: token.0,
|
}
|
||||||
},
|
LalrpopError::User { error } => {
|
||||||
LalrpopError::User { error } => ParseError {
|
ParseError { error: ParseErrorType::Lexical(error.error), location: error.location }
|
||||||
error: ParseErrorType::Lexical(error.error),
|
}
|
||||||
location: error.location,
|
|
||||||
},
|
|
||||||
LalrpopError::UnrecognizedToken { token, expected } => {
|
LalrpopError::UnrecognizedToken { token, expected } => {
|
||||||
// Hacky, but it's how CPython does it. See PyParser_AddToken,
|
// Hacky, but it's how CPython does it. See PyParser_AddToken,
|
||||||
// in particular "Only one possible expected token" comment.
|
// in particular "Only one possible expected token" comment.
|
||||||
let expected = if expected.len() == 1 {
|
let expected = if expected.len() == 1 { Some(expected[0].clone()) } else { None };
|
||||||
Some(expected[0].clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
ParseError {
|
ParseError {
|
||||||
error: ParseErrorType::UnrecognizedToken(token.1, expected),
|
error: ParseErrorType::UnrecognizedToken(token.1, expected),
|
||||||
location: token.0,
|
location: token.0,
|
||||||
|
@ -168,10 +162,9 @@ impl From<LalrpopError<Location, Tok, LexicalError>> for ParseError {
|
||||||
|
|
||||||
LalrpopError::UnrecognizedEof { location, .. }
|
LalrpopError::UnrecognizedEof { location, .. }
|
||||||
// TODO: Are there cases where this isn't an EOF?
|
// TODO: Are there cases where this isn't an EOF?
|
||||||
| LalrpopError::InvalidToken { location } => ParseError {
|
| LalrpopError::InvalidToken { location } => {
|
||||||
error: ParseErrorType::Eof,
|
ParseError { error: ParseErrorType::Eof, location }
|
||||||
location,
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
clippy::all
|
clippy::all
|
||||||
)]
|
)]
|
||||||
#![warn(clippy::pedantic)]
|
#![warn(clippy::pedantic)]
|
||||||
|
#![allow(clippy::semicolon_if_nothing_returned, clippy::uninlined_format_args)]
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue