Compare commits
No commits in common. "b6e26443912d0715bc5e910aaaebeb369320813f" and "581b2f7bb283e74f73450012206846bacf52b19c" have entirely different histories.
b6e2644391
...
581b2f7bb2
|
@ -126,9 +126,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.1.30"
|
version = "1.1.24"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945"
|
checksum = "812acba72f0a070b003d3697490d2b55b837230ae7c6c6497f05cc2ddbb8d938"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"shlex",
|
"shlex",
|
||||||
]
|
]
|
||||||
|
@ -141,9 +141,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.20"
|
version = "4.5.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8"
|
checksum = "7be5744db7978a28d9df86a214130d106a89ce49644cbc4e3f0c22c3fba30615"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap_builder",
|
"clap_builder",
|
||||||
"clap_derive",
|
"clap_derive",
|
||||||
|
@ -151,9 +151,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_builder"
|
name = "clap_builder"
|
||||||
version = "4.5.20"
|
version = "4.5.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54"
|
checksum = "a5fbc17d3ef8278f55b282b2a2e75ae6f6c7d4bb70ed3d0382375104bfafdb4b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
|
@ -547,9 +547,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.161"
|
version = "0.2.159"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1"
|
checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
|
@ -698,9 +698,12 @@ checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.20.2"
|
version = "1.20.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1"
|
||||||
|
dependencies = [
|
||||||
|
"portable-atomic",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
|
@ -825,9 +828,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.88"
|
version = "1.0.86"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"
|
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unicode-ident",
|
"unicode-ident",
|
||||||
]
|
]
|
||||||
|
@ -1014,9 +1017,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.18"
|
version = "1.0.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248"
|
checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
|
@ -1067,9 +1070,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.129"
|
version = "1.0.128"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6dbcf9b78a125ee667ae19388837dd12294b858d101fdd393cb9d5501ef09eb2"
|
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|
|
@ -37,7 +37,7 @@ use nac3core::{
|
||||||
typecheck::typedef::{iter_type_vars, FunSignature, FuncArg, Type, TypeEnum, VarMap},
|
typecheck::typedef::{iter_type_vars, FunSignature, FuncArg, Type, TypeEnum, VarMap},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{symbol_resolver::InnerResolver, timeline::TimeFns};
|
use crate::{symbol_resolver::InnerResolver, timeline::TimeFns};
|
||||||
|
|
||||||
/// The parallelism mode within a block.
|
/// The parallelism mode within a block.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
|
|
|
@ -65,11 +65,13 @@ use nac3core::{
|
||||||
};
|
};
|
||||||
use nac3ld::Linker;
|
use nac3ld::Linker;
|
||||||
|
|
||||||
use codegen::{
|
use crate::{
|
||||||
|
codegen::{
|
||||||
attributes_writeback, gen_core_log, gen_rtio_log, rpc_codegen_callback, ArtiqCodeGenerator,
|
attributes_writeback, gen_core_log, gen_rtio_log, rpc_codegen_callback, ArtiqCodeGenerator,
|
||||||
|
},
|
||||||
|
symbol_resolver::{DeferredEvaluationStore, InnerResolver, PythonHelper, Resolver},
|
||||||
|
timeline::TimeFns,
|
||||||
};
|
};
|
||||||
use symbol_resolver::{DeferredEvaluationStore, InnerResolver, PythonHelper, Resolver};
|
|
||||||
use timeline::TimeFns;
|
|
||||||
|
|
||||||
mod codegen;
|
mod codegen;
|
||||||
mod symbol_resolver;
|
mod symbol_resolver;
|
||||||
|
|
|
@ -37,7 +37,7 @@ use nac3core::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::PrimitivePythonId;
|
use crate::PrimitivePythonId;
|
||||||
|
|
||||||
pub enum PrimitiveValue {
|
pub enum PrimitiveValue {
|
||||||
I32(i32),
|
I32(i32),
|
||||||
|
|
|
@ -5,7 +5,8 @@ use inkwell::{
|
||||||
};
|
};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use super::{
|
use crate::{
|
||||||
|
codegen::{
|
||||||
classes::{
|
classes::{
|
||||||
ArrayLikeValue, NDArrayValue, ProxyValue, RangeValue, TypedArrayLikeAccessor,
|
ArrayLikeValue, NDArrayValue, ProxyValue, RangeValue, TypedArrayLikeAccessor,
|
||||||
UntypedArrayLikeAccessor, UntypedArrayLikeMutator,
|
UntypedArrayLikeAccessor, UntypedArrayLikeMutator,
|
||||||
|
@ -19,9 +20,9 @@ use super::{
|
||||||
numpy::ndarray_elementwise_unaryop_impl,
|
numpy::ndarray_elementwise_unaryop_impl,
|
||||||
stmt::gen_for_callback_incrementing,
|
stmt::gen_for_callback_incrementing,
|
||||||
CodeGenContext, CodeGenerator,
|
CodeGenContext, CodeGenerator,
|
||||||
};
|
},
|
||||||
use crate::{
|
toplevel::helper::PrimDef,
|
||||||
toplevel::{helper::PrimDef, numpy::unpack_ndarray_var_tys},
|
toplevel::numpy::unpack_ndarray_var_tys,
|
||||||
typecheck::typedef::{Type, TypeEnum},
|
typecheck::typedef::{Type, TypeEnum},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use inkwell::{
|
||||||
AddressSpace, IntPredicate,
|
AddressSpace, IntPredicate,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use crate::codegen::{
|
||||||
irrt::{call_ndarray_calc_size, call_ndarray_flatten_index},
|
irrt::{call_ndarray_calc_size, call_ndarray_flatten_index},
|
||||||
llvm_intrinsics::call_int_umin,
|
llvm_intrinsics::call_int_umin,
|
||||||
stmt::gen_for_callback_incrementing,
|
stmt::gen_for_callback_incrementing,
|
||||||
|
|
|
@ -18,10 +18,11 @@ use nac3parser::ast::{
|
||||||
Unaryop,
|
Unaryop,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use crate::{
|
||||||
|
codegen::{
|
||||||
classes::{
|
classes::{
|
||||||
ArrayLikeIndexer, ArrayLikeValue, ListType, ListValue, NDArrayValue, ProxyType, ProxyValue,
|
ArrayLikeIndexer, ArrayLikeValue, ListType, ListValue, NDArrayValue, ProxyType,
|
||||||
RangeValue, TypedArrayLikeAccessor, UntypedArrayLikeAccessor,
|
ProxyValue, RangeValue, TypedArrayLikeAccessor, UntypedArrayLikeAccessor,
|
||||||
},
|
},
|
||||||
concrete_type::{ConcreteFuncArg, ConcreteTypeEnum, ConcreteTypeStore},
|
concrete_type::{ConcreteFuncArg, ConcreteTypeEnum, ConcreteTypeStore},
|
||||||
gen_in_range_check, get_llvm_abi_type, get_llvm_type, get_va_count_arg_name,
|
gen_in_range_check, get_llvm_abi_type, get_llvm_type, get_va_count_arg_name,
|
||||||
|
@ -37,8 +38,7 @@ use super::{
|
||||||
gen_var,
|
gen_var,
|
||||||
},
|
},
|
||||||
CodeGenContext, CodeGenTask, CodeGenerator,
|
CodeGenContext, CodeGenTask, CodeGenerator,
|
||||||
};
|
},
|
||||||
use crate::{
|
|
||||||
symbol_resolver::{SymbolValue, ValueEnum},
|
symbol_resolver::{SymbolValue, ValueEnum},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PrimDef,
|
helper::PrimDef,
|
||||||
|
@ -2886,31 +2886,7 @@ pub fn gen_expr<'ctx, G: CodeGenerator>(
|
||||||
Some((_, Some(static_value), _)) => ValueEnum::Static(static_value.clone()),
|
Some((_, Some(static_value), _)) => ValueEnum::Static(static_value.clone()),
|
||||||
None => {
|
None => {
|
||||||
let resolver = ctx.resolver.clone();
|
let resolver = ctx.resolver.clone();
|
||||||
let value = resolver.get_symbol_value(*id, ctx, generator).unwrap();
|
resolver.get_symbol_value(*id, ctx, generator).unwrap()
|
||||||
|
|
||||||
let globals = ctx
|
|
||||||
.top_level
|
|
||||||
.definitions
|
|
||||||
.read()
|
|
||||||
.iter()
|
|
||||||
.filter_map(|def| {
|
|
||||||
if let TopLevelDef::Variable { simple_name, ty, .. } = &*def.read() {
|
|
||||||
Some((*simple_name, *ty))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect_vec();
|
|
||||||
|
|
||||||
if let Some((_, ty)) = globals.iter().find(|(name, _)| name == id) {
|
|
||||||
let ptr = value
|
|
||||||
.to_basic_value_enum(ctx, generator, *ty)
|
|
||||||
.map(BasicValueEnum::into_pointer_value)?;
|
|
||||||
|
|
||||||
ctx.builder.build_load(ptr, id.to_string().as_str()).map(Into::into).unwrap()
|
|
||||||
} else {
|
|
||||||
value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::List { elts, .. } => {
|
ExprKind::List { elts, .. } => {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use inkwell::{
|
||||||
};
|
};
|
||||||
use itertools::Either;
|
use itertools::Either;
|
||||||
|
|
||||||
use super::CodeGenContext;
|
use crate::codegen::CodeGenContext;
|
||||||
|
|
||||||
/// Macro to generate extern function
|
/// Macro to generate extern function
|
||||||
/// Both function return type and function parameter type are `FloatValue`
|
/// Both function return type and function parameter type are `FloatValue`
|
||||||
|
|
|
@ -6,8 +6,8 @@ use inkwell::{
|
||||||
|
|
||||||
use nac3parser::ast::{Expr, Stmt, StrRef};
|
use nac3parser::ast::{Expr, Stmt, StrRef};
|
||||||
|
|
||||||
use super::{bool_to_i1, bool_to_i8, classes::ArraySliceValue, expr::*, stmt::*, CodeGenContext};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
codegen::{bool_to_i1, bool_to_i8, classes::ArraySliceValue, expr::*, stmt::*, CodeGenContext},
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{DefinitionId, TopLevelDef},
|
toplevel::{DefinitionId, TopLevelDef},
|
||||||
typecheck::typedef::{FunSignature, Type},
|
typecheck::typedef::{FunSignature, Type},
|
||||||
|
|
|
@ -7,7 +7,7 @@ use inkwell::{
|
||||||
};
|
};
|
||||||
use itertools::Either;
|
use itertools::Either;
|
||||||
|
|
||||||
use super::CodeGenContext;
|
use crate::codegen::CodeGenContext;
|
||||||
|
|
||||||
/// Returns the string representation for the floating-point type `ft` when used in intrinsic
|
/// Returns the string representation for the floating-point type `ft` when used in intrinsic
|
||||||
/// functions.
|
/// functions.
|
||||||
|
|
|
@ -29,6 +29,7 @@ use parking_lot::{Condvar, Mutex};
|
||||||
use nac3parser::ast::{Location, Stmt, StrRef};
|
use nac3parser::ast::{Location, Stmt, StrRef};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
codegen::classes::{ListType, NDArrayType, ProxyType, RangeType},
|
||||||
symbol_resolver::{StaticValue, SymbolResolver},
|
symbol_resolver::{StaticValue, SymbolResolver},
|
||||||
toplevel::{helper::PrimDef, numpy::unpack_ndarray_var_tys, TopLevelContext, TopLevelDef},
|
toplevel::{helper::PrimDef, numpy::unpack_ndarray_var_tys, TopLevelContext, TopLevelDef},
|
||||||
typecheck::{
|
typecheck::{
|
||||||
|
@ -36,9 +37,6 @@ use crate::{
|
||||||
typedef::{CallId, FuncArg, Type, TypeEnum, Unifier},
|
typedef::{CallId, FuncArg, Type, TypeEnum, Unifier},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use classes::{ListType, NDArrayType, ProxyType, RangeType};
|
|
||||||
use concrete_type::{ConcreteType, ConcreteTypeEnum, ConcreteTypeStore};
|
|
||||||
pub use generator::{CodeGenerator, DefaultCodeGenerator};
|
|
||||||
|
|
||||||
pub mod builtin_fns;
|
pub mod builtin_fns;
|
||||||
pub mod classes;
|
pub mod classes;
|
||||||
|
@ -54,6 +52,9 @@ pub mod stmt;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
||||||
|
use concrete_type::{ConcreteType, ConcreteTypeEnum, ConcreteTypeStore};
|
||||||
|
pub use generator::{CodeGenerator, DefaultCodeGenerator};
|
||||||
|
|
||||||
mod macros {
|
mod macros {
|
||||||
/// Codegen-variant of [`std::unreachable`] which accepts an instance of [`CodeGenContext`] as
|
/// Codegen-variant of [`std::unreachable`] which accepts an instance of [`CodeGenContext`] as
|
||||||
/// its first argument to provide Python source information to indicate the codegen location
|
/// its first argument to provide Python source information to indicate the codegen location
|
||||||
|
|
|
@ -6,7 +6,8 @@ use inkwell::{
|
||||||
|
|
||||||
use nac3parser::ast::{Operator, StrRef};
|
use nac3parser::ast::{Operator, StrRef};
|
||||||
|
|
||||||
use super::{
|
use crate::{
|
||||||
|
codegen::{
|
||||||
classes::{
|
classes::{
|
||||||
ArrayLikeIndexer, ArrayLikeValue, ListType, ListValue, NDArrayType, NDArrayValue,
|
ArrayLikeIndexer, ArrayLikeValue, ListType, ListValue, NDArrayType, NDArrayValue,
|
||||||
ProxyType, ProxyValue, TypedArrayLikeAccessor, TypedArrayLikeAdapter,
|
ProxyType, ProxyValue, TypedArrayLikeAccessor, TypedArrayLikeAdapter,
|
||||||
|
@ -15,14 +16,14 @@ use super::{
|
||||||
expr::gen_binop_expr_with_values,
|
expr::gen_binop_expr_with_values,
|
||||||
irrt::{
|
irrt::{
|
||||||
calculate_len_for_slice_range, call_ndarray_calc_broadcast,
|
calculate_len_for_slice_range, call_ndarray_calc_broadcast,
|
||||||
call_ndarray_calc_broadcast_index, call_ndarray_calc_nd_indices, call_ndarray_calc_size,
|
call_ndarray_calc_broadcast_index, call_ndarray_calc_nd_indices,
|
||||||
|
call_ndarray_calc_size,
|
||||||
},
|
},
|
||||||
llvm_intrinsics::{self, call_memcpy_generic},
|
llvm_intrinsics::{self, call_memcpy_generic},
|
||||||
macros::codegen_unreachable,
|
macros::codegen_unreachable,
|
||||||
stmt::{gen_for_callback_incrementing, gen_for_range_callback, gen_if_else_expr_callback},
|
stmt::{gen_for_callback_incrementing, gen_for_range_callback, gen_if_else_expr_callback},
|
||||||
CodeGenContext, CodeGenerator,
|
CodeGenContext, CodeGenerator,
|
||||||
};
|
},
|
||||||
use crate::{
|
|
||||||
symbol_resolver::ValueEnum,
|
symbol_resolver::ValueEnum,
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PrimDef,
|
helper::PrimDef,
|
||||||
|
|
|
@ -15,13 +15,13 @@ use nac3parser::{
|
||||||
};
|
};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
|
||||||
use super::{
|
use crate::{
|
||||||
|
codegen::{
|
||||||
classes::{ListType, NDArrayType, ProxyType, RangeType},
|
classes::{ListType, NDArrayType, ProxyType, RangeType},
|
||||||
concrete_type::ConcreteTypeStore,
|
concrete_type::ConcreteTypeStore,
|
||||||
CodeGenContext, CodeGenLLVMOptions, CodeGenTargetMachineOptions, CodeGenTask, CodeGenerator,
|
CodeGenContext, CodeGenLLVMOptions, CodeGenTargetMachineOptions, CodeGenTask,
|
||||||
DefaultCodeGenerator, WithCall, WorkerRegistry,
|
CodeGenerator, DefaultCodeGenerator, WithCall, WorkerRegistry,
|
||||||
};
|
},
|
||||||
use crate::{
|
|
||||||
symbol_resolver::{SymbolResolver, ValueEnum},
|
symbol_resolver::{SymbolResolver, ValueEnum},
|
||||||
toplevel::{
|
toplevel::{
|
||||||
composer::{ComposerConfig, TopLevelComposer},
|
composer::{ComposerConfig, TopLevelComposer},
|
||||||
|
|
|
@ -11,8 +11,7 @@ use itertools::Either;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
helper::{debug_assert_prim_is_allowed, make_exception_fields, PrimDef, PrimDefDetails},
|
helper::{debug_assert_prim_is_allowed, make_exception_fields, PrimDefDetails},
|
||||||
numpy::make_ndarray_ty,
|
|
||||||
*,
|
*,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -23,6 +22,7 @@ use crate::{
|
||||||
stmt::exn_constructor,
|
stmt::exn_constructor,
|
||||||
},
|
},
|
||||||
symbol_resolver::SymbolValue,
|
symbol_resolver::SymbolValue,
|
||||||
|
toplevel::{helper::PrimDef, numpy::make_ndarray_ty},
|
||||||
typecheck::typedef::{into_var_map, iter_type_vars, TypeVar, VarMap},
|
typecheck::typedef::{into_var_map, iter_type_vars, TypeVar, VarMap},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use nac3parser::ast::{fold::Fold, ExprKind, Ident};
|
use nac3parser::ast::{fold::Fold, ExprKind};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -382,66 +382,32 @@ impl TopLevelComposer {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::StmtKind::Assign { .. } => {
|
|
||||||
// Assignment statements can assign to (and therefore create) more than one
|
|
||||||
// variable, but this function only allows returning one set of symbol information.
|
|
||||||
// We want to avoid changing this to return a `Vec` of symbol info, as this would
|
|
||||||
// require `iter().next().unwrap()` on every variable created from a non-Assign
|
|
||||||
// statement.
|
|
||||||
//
|
|
||||||
// Make callers use `register_top_level_var` instead, as it provides more
|
|
||||||
// fine-grained control over which symbols to register, while also simplifying the
|
|
||||||
// usage of this function.
|
|
||||||
panic!("Registration of top-level Assign statements must use TopLevelComposer::register_top_level_var (at {})", ast.location);
|
|
||||||
}
|
|
||||||
|
|
||||||
ast::StmtKind::AnnAssign { target, annotation, .. } => {
|
ast::StmtKind::AnnAssign { target, annotation, .. } => {
|
||||||
let ExprKind::Name { id: name, .. } = target.node else {
|
let ExprKind::Name { id: name, .. } = target.node else {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"global variable declaration must be an identifier (at {})",
|
"global variable declaration must be an identifier (at {})",
|
||||||
target.location
|
ast.location
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
self.register_top_level_var(
|
|
||||||
name,
|
|
||||||
Some(annotation.as_ref().clone()),
|
|
||||||
resolver,
|
|
||||||
mod_path,
|
|
||||||
target.location,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => Err(format!(
|
|
||||||
"registrations of constructs other than top level classes/functions/variables are not supported (at {})",
|
|
||||||
ast.location
|
|
||||||
)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Registers a top-level variable with the given `name` into the composer.
|
|
||||||
///
|
|
||||||
/// `annotation` - The type annotation of the top-level variable, or [`None`] if no type
|
|
||||||
/// annotation is provided.
|
|
||||||
/// `location` - The location of the top-level variable.
|
|
||||||
pub fn register_top_level_var(
|
|
||||||
&mut self,
|
|
||||||
name: Ident,
|
|
||||||
annotation: Option<Expr>,
|
|
||||||
resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
|
|
||||||
mod_path: &str,
|
|
||||||
location: Location,
|
|
||||||
) -> Result<(StrRef, DefinitionId, Option<Type>), String> {
|
|
||||||
if self.keyword_list.contains(&name) {
|
if self.keyword_list.contains(&name) {
|
||||||
return Err(format!("cannot use keyword `{name}` as a class name (at {location})"));
|
return Err(format!(
|
||||||
|
"cannot use keyword `{}` as a class name (at {})",
|
||||||
|
name,
|
||||||
|
ast.location
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let global_var_name =
|
let global_var_name = if mod_path.is_empty() {
|
||||||
if mod_path.is_empty() { name.to_string() } else { format!("{mod_path}.{name}") };
|
name.to_string()
|
||||||
|
} else {
|
||||||
if !self.defined_names.insert(global_var_name.clone()) {
|
format!("{mod_path}.{name}")
|
||||||
|
};
|
||||||
|
if !defined_names.insert(global_var_name.clone()) {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
"global variable `{global_var_name}` defined twice (at {location})"
|
"global variable `{}` defined twice (at {})",
|
||||||
|
global_var_name,
|
||||||
|
ast.location
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -452,15 +418,25 @@ impl TopLevelComposer {
|
||||||
name,
|
name,
|
||||||
// dummy here, unify with correct type later,
|
// dummy here, unify with correct type later,
|
||||||
ty_to_be_unified,
|
ty_to_be_unified,
|
||||||
annotation,
|
*(annotation.clone()),
|
||||||
resolver,
|
resolver,
|
||||||
Some(location),
|
Some(ast.location),
|
||||||
))
|
)).into(),
|
||||||
.into(),
|
|
||||||
None,
|
None,
|
||||||
));
|
));
|
||||||
|
|
||||||
Ok((name, DefinitionId(self.definition_ast_list.len() - 1), Some(ty_to_be_unified)))
|
Ok((
|
||||||
|
name,
|
||||||
|
DefinitionId(self.definition_ast_list.len() - 1),
|
||||||
|
Some(ty_to_be_unified),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => Err(format!(
|
||||||
|
"registrations of constructs other than top level classes/functions/variables are not supported (at {})",
|
||||||
|
ast.location
|
||||||
|
)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_analysis(&mut self, inference: bool) -> Result<(), HashSet<String>> {
|
pub fn start_analysis(&mut self, inference: bool) -> Result<(), HashSet<String>> {
|
||||||
|
@ -509,7 +485,7 @@ impl TopLevelComposer {
|
||||||
// things like `class A(Generic[T, V, ImportedModule.T])` is not supported
|
// things like `class A(Generic[T, V, ImportedModule.T])` is not supported
|
||||||
// i.e. only simple names are allowed in the subscript
|
// i.e. only simple names are allowed in the subscript
|
||||||
// should update the TopLevelDef::Class.typevars and the TypeEnum::TObj.params
|
// should update the TopLevelDef::Class.typevars and the TypeEnum::TObj.params
|
||||||
ExprKind::Subscript { value, slice, .. }
|
ast::ExprKind::Subscript { value, slice, .. }
|
||||||
if {
|
if {
|
||||||
matches!(
|
matches!(
|
||||||
&value.node,
|
&value.node,
|
||||||
|
@ -525,9 +501,9 @@ impl TopLevelComposer {
|
||||||
}
|
}
|
||||||
is_generic = true;
|
is_generic = true;
|
||||||
|
|
||||||
let type_var_list: Vec<&Expr<()>>;
|
let type_var_list: Vec<&ast::Expr<()>>;
|
||||||
// if `class A(Generic[T, V, G])`
|
// if `class A(Generic[T, V, G])`
|
||||||
if let ExprKind::Tuple { elts, .. } = &slice.node {
|
if let ast::ExprKind::Tuple { elts, .. } = &slice.node {
|
||||||
type_var_list = elts.iter().collect_vec();
|
type_var_list = elts.iter().collect_vec();
|
||||||
// `class A(Generic[T])`
|
// `class A(Generic[T])`
|
||||||
} else {
|
} else {
|
||||||
|
@ -1038,15 +1014,15 @@ impl TopLevelComposer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let arg_with_default: Vec<(&ast::Located<ast::ArgData<()>>, Option<&Expr>)> = args
|
let arg_with_default: Vec<(&ast::Located<ast::ArgData<()>>, Option<&ast::Expr>)> =
|
||||||
.args
|
args.args
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.zip(
|
.zip(
|
||||||
args.defaults
|
args.defaults
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.map(|x| -> Option<&Expr> { Some(x) })
|
.map(|x| -> Option<&ast::Expr> { Some(x) })
|
||||||
.chain(std::iter::repeat(None)),
|
.chain(std::iter::repeat(None)),
|
||||||
)
|
)
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
@ -1307,7 +1283,7 @@ impl TopLevelComposer {
|
||||||
|
|
||||||
let arg_with_default: Vec<(
|
let arg_with_default: Vec<(
|
||||||
&ast::Located<ast::ArgData<()>>,
|
&ast::Located<ast::ArgData<()>>,
|
||||||
Option<&Expr>,
|
Option<&ast::Expr>,
|
||||||
)> = args
|
)> = args
|
||||||
.args
|
.args
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1316,7 +1292,7 @@ impl TopLevelComposer {
|
||||||
args.defaults
|
args.defaults
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.map(|x| -> Option<&Expr> { Some(x) })
|
.map(|x| -> Option<&ast::Expr> { Some(x) })
|
||||||
.chain(std::iter::repeat(None)),
|
.chain(std::iter::repeat(None)),
|
||||||
)
|
)
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
@ -1473,7 +1449,7 @@ impl TopLevelComposer {
|
||||||
.map_err(|e| HashSet::from([e.to_display(unifier).to_string()]))?;
|
.map_err(|e| HashSet::from([e.to_display(unifier).to_string()]))?;
|
||||||
}
|
}
|
||||||
ast::StmtKind::AnnAssign { target, annotation, value, .. } => {
|
ast::StmtKind::AnnAssign { target, annotation, value, .. } => {
|
||||||
if let ExprKind::Name { id: attr, .. } = &target.node {
|
if let ast::ExprKind::Name { id: attr, .. } = &target.node {
|
||||||
if defined_fields.insert(attr.to_string()) {
|
if defined_fields.insert(attr.to_string()) {
|
||||||
let dummy_field_type = unifier.get_dummy_var().ty;
|
let dummy_field_type = unifier.get_dummy_var().ty;
|
||||||
|
|
||||||
|
@ -1481,7 +1457,7 @@ impl TopLevelComposer {
|
||||||
None => {
|
None => {
|
||||||
// handle Kernel[T], KernelInvariant[T]
|
// handle Kernel[T], KernelInvariant[T]
|
||||||
let (annotation, mutable) = match &annotation.node {
|
let (annotation, mutable) = match &annotation.node {
|
||||||
ExprKind::Subscript { value, slice, .. }
|
ast::ExprKind::Subscript { value, slice, .. }
|
||||||
if matches!(
|
if matches!(
|
||||||
&value.node,
|
&value.node,
|
||||||
ast::ExprKind::Name { id, .. } if id == &core_config.kernel_invariant_ann.into()
|
ast::ExprKind::Name { id, .. } if id == &core_config.kernel_invariant_ann.into()
|
||||||
|
@ -1489,7 +1465,7 @@ impl TopLevelComposer {
|
||||||
{
|
{
|
||||||
(slice, false)
|
(slice, false)
|
||||||
}
|
}
|
||||||
ExprKind::Subscript { value, slice, .. }
|
ast::ExprKind::Subscript { value, slice, .. }
|
||||||
if matches!(
|
if matches!(
|
||||||
&value.node,
|
&value.node,
|
||||||
ast::ExprKind::Name { id, .. } if core_config.kernel_ann.map_or(false, |c| id == &c.into())
|
ast::ExprKind::Name { id, .. } if core_config.kernel_ann.map_or(false, |c| id == &c.into())
|
||||||
|
@ -1507,13 +1483,13 @@ impl TopLevelComposer {
|
||||||
Some(boxed_expr) => {
|
Some(boxed_expr) => {
|
||||||
// Class attributes are set as immutable regardless
|
// Class attributes are set as immutable regardless
|
||||||
let (annotation, _) = match &annotation.node {
|
let (annotation, _) = match &annotation.node {
|
||||||
ExprKind::Subscript { slice, .. } => (slice, false),
|
ast::ExprKind::Subscript { slice, .. } => (slice, false),
|
||||||
_ if core_config.kernel_ann.is_none() => (annotation, false),
|
_ if core_config.kernel_ann.is_none() => (annotation, false),
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
match &**boxed_expr {
|
match &**boxed_expr {
|
||||||
ast::Located {location: _, custom: (), node: ExprKind::Constant { value: v, kind: _ }} => {
|
ast::Located {location: _, custom: (), node: ast::ExprKind::Constant { value: v, kind: _ }} => {
|
||||||
// Restricting the types allowed to be defined as class attributes
|
// Restricting the types allowed to be defined as class attributes
|
||||||
match v {
|
match v {
|
||||||
ast::Constant::Bool(_) | ast::Constant::Str(_) | ast::Constant::Int(_) | ast::Constant::Float(_) => {}
|
ast::Constant::Bool(_) | ast::Constant::Str(_) | ast::Constant::Int(_) | ast::Constant::Float(_) => {}
|
||||||
|
@ -1961,20 +1937,20 @@ impl TopLevelComposer {
|
||||||
if ast.is_none() {
|
if ast.is_none() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
let mut function_def = def.write();
|
||||||
let (name, simple_name, signature, resolver) = {
|
if let TopLevelDef::Function {
|
||||||
let function_def = def.read();
|
instance_to_stmt,
|
||||||
let TopLevelDef::Function { name, simple_name, signature, resolver, .. } =
|
instance_to_symbol,
|
||||||
&*function_def
|
name,
|
||||||
else {
|
simple_name,
|
||||||
return Ok(());
|
signature,
|
||||||
};
|
resolver,
|
||||||
|
..
|
||||||
(name.clone(), *simple_name, *signature, resolver.clone())
|
} = &mut *function_def
|
||||||
};
|
{
|
||||||
|
let signature_ty_enum = unifier.get_ty(*signature);
|
||||||
let signature_ty_enum = unifier.get_ty(signature);
|
let TypeEnum::TFunc(FunSignature { args, ret, vars, .. }) =
|
||||||
let TypeEnum::TFunc(FunSignature { args, ret, vars, .. }) = signature_ty_enum.as_ref()
|
signature_ty_enum.as_ref()
|
||||||
else {
|
else {
|
||||||
unreachable!("must be typeenum::tfunc")
|
unreachable!("must be typeenum::tfunc")
|
||||||
};
|
};
|
||||||
|
@ -2086,7 +2062,8 @@ impl TopLevelComposer {
|
||||||
if self_type.is_some() {
|
if self_type.is_some() {
|
||||||
result.insert("self".into(), IdentifierInfo::default());
|
result.insert("self".into(), IdentifierInfo::default());
|
||||||
}
|
}
|
||||||
result.extend(inst_args.iter().map(|x| (x.name, IdentifierInfo::default())));
|
result
|
||||||
|
.extend(inst_args.iter().map(|x| (x.name, IdentifierInfo::default())));
|
||||||
result
|
result
|
||||||
};
|
};
|
||||||
let mut calls: HashMap<CodeLocation, CallId> = HashMap::new();
|
let mut calls: HashMap<CodeLocation, CallId> = HashMap::new();
|
||||||
|
@ -2123,43 +2100,33 @@ impl TopLevelComposer {
|
||||||
else {
|
else {
|
||||||
unreachable!("must be function def ast")
|
unreachable!("must be function def ast")
|
||||||
};
|
};
|
||||||
|
if !decorator_list.is_empty()
|
||||||
|
&& matches!(&decorator_list[0].node,
|
||||||
|
ast::ExprKind::Name{ id, .. } if id == &"extern".into())
|
||||||
|
{
|
||||||
|
instance_to_symbol.insert(String::new(), simple_name.to_string());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if !decorator_list.is_empty()
|
||||||
|
&& matches!(&decorator_list[0].node,
|
||||||
|
ast::ExprKind::Name{ id, .. } if id == &"rpc".into())
|
||||||
|
{
|
||||||
|
instance_to_symbol.insert(String::new(), simple_name.to_string());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if !decorator_list.is_empty() {
|
if !decorator_list.is_empty() {
|
||||||
if matches!(&decorator_list[0].node, ExprKind::Name { id, .. } if id == &"extern".into())
|
if let ast::ExprKind::Call { func, .. } = &decorator_list[0].node {
|
||||||
|
if matches!(&func.node,
|
||||||
|
ast::ExprKind::Name{ id, .. } if id == &"rpc".into())
|
||||||
{
|
{
|
||||||
let TopLevelDef::Function { instance_to_symbol, .. } = &mut *def.write()
|
|
||||||
else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
instance_to_symbol.insert(String::new(), simple_name.to_string());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if matches!(&decorator_list[0].node, ExprKind::Name { id, .. } if id == &"rpc".into())
|
|
||||||
{
|
|
||||||
let TopLevelDef::Function { instance_to_symbol, .. } = &mut *def.write()
|
|
||||||
else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
instance_to_symbol.insert(String::new(), simple_name.to_string());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let ExprKind::Call { func, .. } = &decorator_list[0].node {
|
|
||||||
if matches!(&func.node, ExprKind::Name { id, .. } if id == &"rpc".into()) {
|
|
||||||
let TopLevelDef::Function { instance_to_symbol, .. } =
|
|
||||||
&mut *def.write()
|
|
||||||
else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
instance_to_symbol.insert(String::new(), simple_name.to_string());
|
instance_to_symbol.insert(String::new(), simple_name.to_string());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let fun_body =
|
let fun_body = body
|
||||||
body.into_iter()
|
.into_iter()
|
||||||
.map(|b| inferencer.fold_stmt(b))
|
.map(|b| inferencer.fold_stmt(b))
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
|
|
||||||
|
@ -2229,9 +2196,6 @@ impl TopLevelComposer {
|
||||||
)]));
|
)]));
|
||||||
}
|
}
|
||||||
|
|
||||||
let TopLevelDef::Function { instance_to_stmt, .. } = &mut *def.write() else {
|
|
||||||
unreachable!()
|
|
||||||
};
|
|
||||||
instance_to_stmt.insert(
|
instance_to_stmt.insert(
|
||||||
get_subst_key(
|
get_subst_key(
|
||||||
unifier,
|
unifier,
|
||||||
|
@ -2247,10 +2211,10 @@ impl TopLevelComposer {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
for (id, (def, ast)) in self.definition_ast_list.iter().enumerate().skip(self.builtin_num) {
|
for (id, (def, ast)) in self.definition_ast_list.iter().enumerate().skip(self.builtin_num) {
|
||||||
if ast.is_none() {
|
if ast.is_none() {
|
||||||
continue;
|
continue;
|
||||||
|
@ -2273,8 +2237,9 @@ impl TopLevelComposer {
|
||||||
let primitives_store = &self.primitives_ty;
|
let primitives_store = &self.primitives_ty;
|
||||||
|
|
||||||
let mut analyze = |variable_def: &Arc<RwLock<TopLevelDef>>| -> Result<_, HashSet<String>> {
|
let mut analyze = |variable_def: &Arc<RwLock<TopLevelDef>>| -> Result<_, HashSet<String>> {
|
||||||
let TopLevelDef::Variable { ty: dummy_ty, ty_decl, resolver, loc, .. } =
|
let variable_def = &mut *variable_def.write();
|
||||||
&*variable_def.read()
|
|
||||||
|
let TopLevelDef::Variable { ty: dummy_ty, ty_decl, resolver, loc, .. } = variable_def
|
||||||
else {
|
else {
|
||||||
// not top level variable def, skip
|
// not top level variable def, skip
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -2282,7 +2247,6 @@ impl TopLevelComposer {
|
||||||
|
|
||||||
let resolver = &**resolver.as_ref().unwrap();
|
let resolver = &**resolver.as_ref().unwrap();
|
||||||
|
|
||||||
if let Some(ty_decl) = ty_decl {
|
|
||||||
let ty_annotation = parse_ast_to_type_annotation_kinds(
|
let ty_annotation = parse_ast_to_type_annotation_kinds(
|
||||||
resolver,
|
resolver,
|
||||||
&temp_def_list,
|
&temp_def_list,
|
||||||
|
@ -2302,8 +2266,6 @@ impl TopLevelComposer {
|
||||||
unifier.unify(*dummy_ty, ty_from_ty_annotation).map_err(|e| {
|
unifier.unify(*dummy_ty, ty_from_ty_annotation).map_err(|e| {
|
||||||
HashSet::from([e.at(Some(loc.unwrap())).to_display(unifier).to_string()])
|
HashSet::from([e.at(Some(loc.unwrap())).to_display(unifier).to_string()])
|
||||||
})?;
|
})?;
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,13 @@ use std::convert::TryInto;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
use strum_macros::EnumIter;
|
use strum_macros::EnumIter;
|
||||||
|
|
||||||
use nac3parser::ast::{Constant, ExprKind, Location};
|
use ast::ExprKind;
|
||||||
|
use nac3parser::ast::{Constant, Location};
|
||||||
|
|
||||||
use super::{numpy::unpack_ndarray_var_tys, *};
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
symbol_resolver::SymbolValue,
|
symbol_resolver::SymbolValue,
|
||||||
|
toplevel::numpy::unpack_ndarray_var_tys,
|
||||||
typecheck::typedef::{into_var_map, iter_type_vars, Mapping, TypeVarId, VarMap},
|
typecheck::typedef::{into_var_map, iter_type_vars, Mapping, TypeVarId, VarMap},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -598,7 +600,7 @@ impl TopLevelComposer {
|
||||||
name: String,
|
name: String,
|
||||||
simple_name: StrRef,
|
simple_name: StrRef,
|
||||||
ty: Type,
|
ty: Type,
|
||||||
ty_decl: Option<Expr>,
|
ty_decl: Expr,
|
||||||
resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
|
resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
|
||||||
loc: Option<Location>,
|
loc: Option<Location>,
|
||||||
) -> TopLevelDef {
|
) -> TopLevelDef {
|
||||||
|
|
|
@ -23,19 +23,19 @@ use crate::{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use composer::*;
|
|
||||||
use type_annotation::*;
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug)]
|
||||||
|
pub struct DefinitionId(pub usize);
|
||||||
|
|
||||||
pub mod builtins;
|
pub mod builtins;
|
||||||
pub mod composer;
|
pub mod composer;
|
||||||
pub mod helper;
|
pub mod helper;
|
||||||
pub mod numpy;
|
pub mod numpy;
|
||||||
|
pub mod type_annotation;
|
||||||
|
use composer::*;
|
||||||
|
use type_annotation::*;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
pub mod type_annotation;
|
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug)]
|
|
||||||
pub struct DefinitionId(pub usize);
|
|
||||||
|
|
||||||
type GenCallCallback = dyn for<'ctx, 'a> Fn(
|
type GenCallCallback = dyn for<'ctx, 'a> Fn(
|
||||||
&mut CodeGenContext<'ctx, 'a>,
|
&mut CodeGenContext<'ctx, 'a>,
|
||||||
|
@ -158,8 +158,8 @@ pub enum TopLevelDef {
|
||||||
/// Type of the global variable.
|
/// Type of the global variable.
|
||||||
ty: Type,
|
ty: Type,
|
||||||
|
|
||||||
/// The declared type of the global variable, or [`None`] if no type annotation is provided.
|
/// The declared type of the global variable.
|
||||||
ty_decl: Option<Expr>,
|
ty_decl: Expr,
|
||||||
|
|
||||||
/// Symbol resolver of the module defined the class.
|
/// Symbol resolver of the module defined the class.
|
||||||
resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
|
resolver: Option<Arc<dyn SymbolResolver + Send + Sync>>,
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use super::helper::PrimDef;
|
use crate::{
|
||||||
use crate::typecheck::{
|
toplevel::helper::PrimDef,
|
||||||
|
typecheck::{
|
||||||
type_inferencer::PrimitiveStore,
|
type_inferencer::PrimitiveStore,
|
||||||
typedef::{Type, TypeEnum, TypeVarId, Unifier, VarMap},
|
typedef::{Type, TypeEnum, TypeVarId, Unifier, VarMap},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Creates a `ndarray` [`Type`] with the given type arguments.
|
/// Creates a `ndarray` [`Type`] with the given type arguments.
|
||||||
|
|
|
@ -9,10 +9,11 @@ use nac3parser::{
|
||||||
parser::parse_program,
|
parser::parse_program,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{helper::PrimDef, DefinitionId, *};
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
codegen::CodeGenContext,
|
codegen::CodeGenContext,
|
||||||
symbol_resolver::{SymbolResolver, ValueEnum},
|
symbol_resolver::{SymbolResolver, ValueEnum},
|
||||||
|
toplevel::{helper::PrimDef, DefinitionId},
|
||||||
typecheck::{
|
typecheck::{
|
||||||
type_inferencer::PrimitiveStore,
|
type_inferencer::PrimitiveStore,
|
||||||
typedef::{into_var_map, Type, Unifier},
|
typedef::{into_var_map, Type, Unifier},
|
||||||
|
|
|
@ -2,11 +2,12 @@ use strum::IntoEnumIterator;
|
||||||
|
|
||||||
use nac3parser::ast::Constant;
|
use nac3parser::ast::Constant;
|
||||||
|
|
||||||
use super::{
|
use super::*;
|
||||||
helper::{PrimDef, PrimDefDetails},
|
use crate::{
|
||||||
*,
|
symbol_resolver::SymbolValue,
|
||||||
|
toplevel::helper::{PrimDef, PrimDefDetails},
|
||||||
|
typecheck::typedef::VarMap,
|
||||||
};
|
};
|
||||||
use crate::{symbol_resolver::SymbolValue, typecheck::typedef::VarMap};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum TypeAnnotation {
|
pub enum TypeAnnotation {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use nac3parser::ast::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
type_inferencer::{DeclarationSource, IdentifierInfo, Inferencer},
|
type_inferencer::{IdentifierInfo, Inferencer},
|
||||||
typedef::{Type, TypeEnum},
|
typedef::{Type, TypeEnum},
|
||||||
};
|
};
|
||||||
use crate::toplevel::helper::PrimDef;
|
use crate::toplevel::helper::PrimDef;
|
||||||
|
@ -34,20 +34,6 @@ impl<'a> Inferencer<'a> {
|
||||||
Err(HashSet::from([format!("cannot assign to a `none` (at {})", pattern.location)]))
|
Err(HashSet::from([format!("cannot assign to a `none` (at {})", pattern.location)]))
|
||||||
}
|
}
|
||||||
ExprKind::Name { id, .. } => {
|
ExprKind::Name { id, .. } => {
|
||||||
// If `id` refers to a declared symbol, reject this assignment if it is used in the
|
|
||||||
// context of an (implicit) global variable
|
|
||||||
if let Some(id_info) = defined_identifiers.get(id) {
|
|
||||||
if matches!(
|
|
||||||
id_info.source,
|
|
||||||
DeclarationSource::Global { is_explicit: Some(false) }
|
|
||||||
) {
|
|
||||||
return Err(HashSet::from([format!(
|
|
||||||
"cannot access local variable '{id}' before it is declared (at {})",
|
|
||||||
pattern.location
|
|
||||||
)]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !defined_identifiers.contains_key(id) {
|
if !defined_identifiers.contains_key(id) {
|
||||||
defined_identifiers.insert(*id, IdentifierInfo::default());
|
defined_identifiers.insert(*id, IdentifierInfo::default());
|
||||||
}
|
}
|
||||||
|
@ -118,22 +104,7 @@ impl<'a> Inferencer<'a> {
|
||||||
*id,
|
*id,
|
||||||
) {
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let is_global = self.is_id_global(*id);
|
self.defined_identifiers.insert(*id, IdentifierInfo::default());
|
||||||
|
|
||||||
defined_identifiers.insert(
|
|
||||||
*id,
|
|
||||||
IdentifierInfo {
|
|
||||||
source: match is_global {
|
|
||||||
Some(true) => {
|
|
||||||
DeclarationSource::Global { is_explicit: Some(false) }
|
|
||||||
}
|
|
||||||
Some(false) => {
|
|
||||||
DeclarationSource::Global { is_explicit: None }
|
|
||||||
}
|
|
||||||
None => DeclarationSource::Local,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(HashSet::from([format!(
|
return Err(HashSet::from([format!(
|
||||||
|
@ -397,9 +368,9 @@ impl<'a> Inferencer<'a> {
|
||||||
StmtKind::Global { names, .. } => {
|
StmtKind::Global { names, .. } => {
|
||||||
for id in names {
|
for id in names {
|
||||||
if let Some(id_info) = defined_identifiers.get(id) {
|
if let Some(id_info) = defined_identifiers.get(id) {
|
||||||
if id_info.source == DeclarationSource::Local {
|
if !id_info.is_global {
|
||||||
return Err(HashSet::from([format!(
|
return Err(HashSet::from([format!(
|
||||||
"name '{id}' is referenced prior to global declaration at {}",
|
"name '{id}' is assigned to before global declaration at {}",
|
||||||
stmt.location,
|
stmt.location,
|
||||||
)]));
|
)]));
|
||||||
}
|
}
|
||||||
|
@ -414,12 +385,8 @@ impl<'a> Inferencer<'a> {
|
||||||
*id,
|
*id,
|
||||||
) {
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
defined_identifiers.insert(
|
self.defined_identifiers
|
||||||
*id,
|
.insert(*id, IdentifierInfo { is_global: true });
|
||||||
IdentifierInfo {
|
|
||||||
source: DeclarationSource::Global { is_explicit: Some(true) },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(HashSet::from([format!(
|
return Err(HashSet::from([format!(
|
||||||
|
|
|
@ -5,16 +5,16 @@ use strum::IntoEnumIterator;
|
||||||
|
|
||||||
use nac3parser::ast::{Cmpop, Operator, StrRef, Unaryop};
|
use nac3parser::ast::{Cmpop, Operator, StrRef, Unaryop};
|
||||||
|
|
||||||
use super::{
|
|
||||||
type_inferencer::*,
|
|
||||||
typedef::{FunSignature, FuncArg, Type, TypeEnum, Unifier, VarMap},
|
|
||||||
};
|
|
||||||
use crate::{
|
use crate::{
|
||||||
symbol_resolver::SymbolValue,
|
symbol_resolver::SymbolValue,
|
||||||
toplevel::{
|
toplevel::{
|
||||||
helper::PrimDef,
|
helper::PrimDef,
|
||||||
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
numpy::{make_ndarray_ty, unpack_ndarray_var_tys},
|
||||||
},
|
},
|
||||||
|
typecheck::{
|
||||||
|
type_inferencer::*,
|
||||||
|
typedef::{FunSignature, FuncArg, Type, TypeEnum, Unifier, VarMap},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The variant of a binary operator.
|
/// The variant of a binary operator.
|
||||||
|
|
|
@ -5,9 +5,10 @@ use itertools::Itertools;
|
||||||
use nac3parser::ast::{Cmpop, Location, StrRef};
|
use nac3parser::ast::{Cmpop, Location, StrRef};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
magic_methods::{Binop, HasOpInfo},
|
magic_methods::Binop,
|
||||||
typedef::{RecordKey, Type, TypeEnum, Unifier},
|
typedef::{RecordKey, Type, Unifier},
|
||||||
};
|
};
|
||||||
|
use crate::typecheck::{magic_methods::HasOpInfo, typedef::TypeEnum};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TypeErrorKind {
|
pub enum TypeErrorKind {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use itertools::{izip, Itertools};
|
||||||
use nac3parser::ast::{
|
use nac3parser::ast::{
|
||||||
self,
|
self,
|
||||||
fold::{self, Fold},
|
fold::{self, Fold},
|
||||||
Arguments, Comprehension, ExprContext, ExprKind, Ident, Located, Location, StrRef,
|
Arguments, Comprehension, ExprContext, ExprKind, Located, Location, StrRef,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
|
@ -88,31 +88,11 @@ impl PrimitiveStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The location where an identifier declaration refers to.
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
||||||
pub enum DeclarationSource {
|
|
||||||
/// Local scope.
|
|
||||||
Local,
|
|
||||||
|
|
||||||
/// Global scope.
|
|
||||||
Global {
|
|
||||||
/// Whether the identifier is declared by the use of `global` statement. This field is
|
|
||||||
/// [`None`] if the identifier does not refer to a variable.
|
|
||||||
is_explicit: Option<bool>,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Information regarding a defined identifier.
|
/// Information regarding a defined identifier.
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct IdentifierInfo {
|
pub struct IdentifierInfo {
|
||||||
/// Whether this identifier refers to a global variable.
|
/// Whether this identifier refers to a global variable.
|
||||||
pub source: DeclarationSource,
|
pub is_global: bool,
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for IdentifierInfo {
|
|
||||||
fn default() -> Self {
|
|
||||||
IdentifierInfo { source: DeclarationSource::Local }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IdentifierInfo {
|
impl IdentifierInfo {
|
||||||
|
@ -594,22 +574,7 @@ impl<'a> Fold<()> for Inferencer<'a> {
|
||||||
*id,
|
*id,
|
||||||
) {
|
) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let is_global = self.is_id_global(*id);
|
self.defined_identifiers.insert(*id, IdentifierInfo::default());
|
||||||
|
|
||||||
self.defined_identifiers.insert(
|
|
||||||
*id,
|
|
||||||
IdentifierInfo {
|
|
||||||
source: match is_global {
|
|
||||||
Some(true) => DeclarationSource::Global {
|
|
||||||
is_explicit: Some(false),
|
|
||||||
},
|
|
||||||
Some(false) => {
|
|
||||||
DeclarationSource::Global { is_explicit: None }
|
|
||||||
}
|
|
||||||
None => DeclarationSource::Local,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return report_error(
|
return report_error(
|
||||||
|
@ -2685,22 +2650,4 @@ impl<'a> Inferencer<'a> {
|
||||||
self.constrain(body.custom.unwrap(), orelse.custom.unwrap(), &body.location)?;
|
self.constrain(body.custom.unwrap(), orelse.custom.unwrap(), &body.location)?;
|
||||||
Ok(body.custom.unwrap())
|
Ok(body.custom.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines whether the given `id` refers to a global symbol.
|
|
||||||
///
|
|
||||||
/// Returns `Some(true)` if `id` refers to a global variable, `Some(false)` if `id` refers to a
|
|
||||||
/// class/function, and `None` if `id` refers to a local symbol.
|
|
||||||
pub(super) fn is_id_global(&self, id: Ident) -> Option<bool> {
|
|
||||||
self.top_level
|
|
||||||
.definitions
|
|
||||||
.read()
|
|
||||||
.iter()
|
|
||||||
.map(|def| match *def.read() {
|
|
||||||
TopLevelDef::Class { name, .. } => (name, false),
|
|
||||||
TopLevelDef::Function { simple_name, .. } => (simple_name, false),
|
|
||||||
TopLevelDef::Variable { simple_name, .. } => (simple_name, true),
|
|
||||||
})
|
|
||||||
.find(|(global, _)| global == &id)
|
|
||||||
.map(|(_, has_explicit_prop)| has_explicit_prop)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,14 +14,14 @@ use itertools::{repeat_n, Itertools};
|
||||||
use nac3parser::ast::{Cmpop, Location, StrRef, Unaryop};
|
use nac3parser::ast::{Cmpop, Location, StrRef, Unaryop};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
magic_methods::{Binop, HasOpInfo, OpInfo},
|
magic_methods::{Binop, HasOpInfo},
|
||||||
type_error::{TypeError, TypeErrorKind},
|
type_error::{TypeError, TypeErrorKind},
|
||||||
type_inferencer::PrimitiveStore,
|
|
||||||
unification_table::{UnificationKey, UnificationTable},
|
unification_table::{UnificationKey, UnificationTable},
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
symbol_resolver::SymbolValue,
|
symbol_resolver::SymbolValue,
|
||||||
toplevel::{helper::PrimDef, DefinitionId, TopLevelContext, TopLevelDef},
|
toplevel::{helper::PrimDef, DefinitionId, TopLevelContext, TopLevelDef},
|
||||||
|
typecheck::{magic_methods::OpInfo, type_inferencer::PrimitiveStore},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -7,7 +7,7 @@ def output_int64(x: int64):
|
||||||
...
|
...
|
||||||
|
|
||||||
X: int32 = 0
|
X: int32 = 0
|
||||||
Y = int64(1)
|
Y: int64 = int64(1)
|
||||||
|
|
||||||
def f():
|
def f():
|
||||||
global X, Y
|
global X, Y
|
||||||
|
|
|
@ -45,9 +45,8 @@ use nac3core::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use basic_symbol_resolver::*;
|
|
||||||
|
|
||||||
mod basic_symbol_resolver;
|
mod basic_symbol_resolver;
|
||||||
|
use basic_symbol_resolver::*;
|
||||||
|
|
||||||
/// Command-line argument parser definition.
|
/// Command-line argument parser definition.
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -175,49 +174,46 @@ fn handle_typevar_definition(
|
||||||
fn handle_assignment_pattern(
|
fn handle_assignment_pattern(
|
||||||
targets: &[Expr],
|
targets: &[Expr],
|
||||||
value: &Expr,
|
value: &Expr,
|
||||||
resolver: Arc<dyn SymbolResolver + Send + Sync>,
|
resolver: &(dyn SymbolResolver + Send + Sync),
|
||||||
internal_resolver: &ResolverInternal,
|
internal_resolver: &ResolverInternal,
|
||||||
composer: &mut TopLevelComposer,
|
def_list: &[Arc<RwLock<TopLevelDef>>],
|
||||||
|
unifier: &mut Unifier,
|
||||||
|
primitives: &PrimitiveStore,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
if targets.len() == 1 {
|
if targets.len() == 1 {
|
||||||
let target = &targets[0];
|
match &targets[0].node {
|
||||||
|
|
||||||
match &target.node {
|
|
||||||
ExprKind::Name { id, .. } => {
|
ExprKind::Name { id, .. } => {
|
||||||
let def_list = composer.extract_def_list();
|
|
||||||
let unifier = &mut composer.unifier;
|
|
||||||
let primitives = &composer.primitives_ty;
|
|
||||||
|
|
||||||
if let Ok(var) =
|
if let Ok(var) =
|
||||||
handle_typevar_definition(value, &*resolver, &def_list, unifier, primitives)
|
handle_typevar_definition(value, resolver, def_list, unifier, primitives)
|
||||||
{
|
{
|
||||||
internal_resolver.add_id_type(*id, var);
|
internal_resolver.add_id_type(*id, var);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else if let Ok(val) = parse_parameter_default_value(value, &*resolver) {
|
} else if let Ok(val) = parse_parameter_default_value(value, resolver) {
|
||||||
internal_resolver.add_module_global(*id, val);
|
internal_resolver.add_module_global(*id, val);
|
||||||
let (name, def_id, _) = composer
|
|
||||||
.register_top_level_var(
|
|
||||||
*id,
|
|
||||||
None,
|
|
||||||
Some(resolver.clone()),
|
|
||||||
"__main__",
|
|
||||||
target.location,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
internal_resolver.add_id_def(name, def_id);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(format!("fails to evaluate this expression `{:?}` as a constant or generic parameter at {}",
|
Err(format!("fails to evaluate this expression `{:?}` as a constant or generic parameter at {}",
|
||||||
target.node,
|
targets[0].node,
|
||||||
target.location,
|
targets[0].location,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::List { elts, .. } | ExprKind::Tuple { elts, .. } => {
|
ExprKind::List { elts, .. } | ExprKind::Tuple { elts, .. } => {
|
||||||
handle_assignment_pattern(elts, value, resolver, internal_resolver, composer)?;
|
handle_assignment_pattern(
|
||||||
|
elts,
|
||||||
|
value,
|
||||||
|
resolver,
|
||||||
|
internal_resolver,
|
||||||
|
def_list,
|
||||||
|
unifier,
|
||||||
|
primitives,
|
||||||
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(format!("assignment to {target:?} is not supported at {}", target.location)),
|
_ => Err(format!(
|
||||||
|
"assignment to {:?} is not supported at {}",
|
||||||
|
targets[0], targets[0].location
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match &value.node {
|
match &value.node {
|
||||||
|
@ -227,9 +223,11 @@ fn handle_assignment_pattern(
|
||||||
handle_assignment_pattern(
|
handle_assignment_pattern(
|
||||||
std::slice::from_ref(tar),
|
std::slice::from_ref(tar),
|
||||||
val,
|
val,
|
||||||
resolver.clone(),
|
resolver,
|
||||||
internal_resolver,
|
internal_resolver,
|
||||||
composer,
|
def_list,
|
||||||
|
unifier,
|
||||||
|
primitives,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -250,9 +248,8 @@ fn handle_assignment_pattern(
|
||||||
fn handle_global_var(
|
fn handle_global_var(
|
||||||
target: &Expr,
|
target: &Expr,
|
||||||
value: Option<&Expr>,
|
value: Option<&Expr>,
|
||||||
resolver: &Arc<dyn SymbolResolver + Send + Sync>,
|
resolver: &(dyn SymbolResolver + Send + Sync),
|
||||||
internal_resolver: &ResolverInternal,
|
internal_resolver: &ResolverInternal,
|
||||||
composer: &mut TopLevelComposer,
|
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let ExprKind::Name { id, .. } = target.node else {
|
let ExprKind::Name { id, .. } = target.node else {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
|
@ -265,12 +262,8 @@ fn handle_global_var(
|
||||||
return Err(format!("global variable `{id}` must be initialized in its definition"));
|
return Err(format!("global variable `{id}` must be initialized in its definition"));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(val) = parse_parameter_default_value(value, &**resolver) {
|
if let Ok(val) = parse_parameter_default_value(value, resolver) {
|
||||||
internal_resolver.add_module_global(id, val);
|
internal_resolver.add_module_global(id, val);
|
||||||
let (name, def_id, _) = composer
|
|
||||||
.register_top_level_var(id, None, Some(resolver.clone()), "__main__", target.location)
|
|
||||||
.unwrap();
|
|
||||||
internal_resolver.add_id_def(name, def_id);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(format!(
|
Err(format!(
|
||||||
|
@ -362,12 +355,17 @@ fn main() {
|
||||||
for stmt in parser_result {
|
for stmt in parser_result {
|
||||||
match &stmt.node {
|
match &stmt.node {
|
||||||
StmtKind::Assign { targets, value, .. } => {
|
StmtKind::Assign { targets, value, .. } => {
|
||||||
|
let def_list = composer.extract_def_list();
|
||||||
|
let unifier = &mut composer.unifier;
|
||||||
|
let primitives = &composer.primitives_ty;
|
||||||
if let Err(err) = handle_assignment_pattern(
|
if let Err(err) = handle_assignment_pattern(
|
||||||
targets,
|
targets,
|
||||||
value,
|
value,
|
||||||
resolver.clone(),
|
resolver.as_ref(),
|
||||||
internal_resolver.as_ref(),
|
internal_resolver.as_ref(),
|
||||||
&mut composer,
|
&def_list,
|
||||||
|
unifier,
|
||||||
|
primitives,
|
||||||
) {
|
) {
|
||||||
panic!("{err}");
|
panic!("{err}");
|
||||||
}
|
}
|
||||||
|
@ -377,12 +375,16 @@ fn main() {
|
||||||
if let Err(err) = handle_global_var(
|
if let Err(err) = handle_global_var(
|
||||||
target,
|
target,
|
||||||
value.as_ref().map(Box::as_ref),
|
value.as_ref().map(Box::as_ref),
|
||||||
&resolver,
|
resolver.as_ref(),
|
||||||
internal_resolver.as_ref(),
|
internal_resolver.as_ref(),
|
||||||
&mut composer,
|
|
||||||
) {
|
) {
|
||||||
panic!("{err}");
|
panic!("{err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let (name, def_id, _) = composer
|
||||||
|
.register_top_level(stmt, Some(resolver.clone()), "__main__", true)
|
||||||
|
.unwrap();
|
||||||
|
internal_resolver.add_id_def(name, def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// allow (and ignore) "from __future__ import annotations"
|
// allow (and ignore) "from __future__ import annotations"
|
||||||
|
|
Loading…
Reference in New Issue