Compare commits

..

3 Commits

5 changed files with 87 additions and 86 deletions

67
Cargo.lock generated
View File

@ -4,9 +4,9 @@ version = 3
[[package]] [[package]]
name = "ab_glyph" name = "ab_glyph"
version = "0.2.28" version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79faae4620f45232f599d9bc7b290f88247a0834162c4495ab2f02d60004adfb" checksum = "ec3672c180e71eeaaac3a541fbbc5f5ad4def8b747c595ad30d674e43049f7b0"
dependencies = [ dependencies = [
"ab_glyph_rasterizer", "ab_glyph_rasterizer",
"owned_ttf_parser", "owned_ttf_parser",
@ -323,9 +323,9 @@ dependencies = [
[[package]] [[package]]
name = "async-once-cell" name = "async-once-cell"
version = "0.5.3" version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9338790e78aa95a416786ec8389546c4b6a1dfc3dc36071ed9518a9413a542eb" checksum = "4288f83726785267c6f2ef073a3d83dc3f9b81464e9f99898240cced85fce35a"
[[package]] [[package]]
name = "async-process" name = "async-process"
@ -599,9 +599,9 @@ dependencies = [
[[package]] [[package]]
name = "bytemuck_derive" name = "bytemuck_derive"
version = "1.7.1" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc8b54b395f2fcfbb3d90c47b01c7f444d94d05bdeb775811dec868ac3bbc26" checksum = "bcfcc3cd946cb52f0bbfdbbcfa2f4e24f75ebb6c0e1002f7c25904fada18b9ec"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -680,9 +680,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.1.25" version = "1.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8d9e0b4957f635b8d3da819d0db5603620467ecf1f692d22a8c2717ce27e6d8" checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1"
dependencies = [ dependencies = [
"jobserver", "jobserver",
"libc", "libc",
@ -1390,15 +1390,15 @@ dependencies = [
[[package]] [[package]]
name = "futures-core" name = "futures-core"
version = "0.3.30" version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
[[package]] [[package]]
name = "futures-io" name = "futures-io"
version = "0.3.30" version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
[[package]] [[package]]
name = "futures-lite" name = "futures-lite"
@ -1430,21 +1430,21 @@ dependencies = [
[[package]] [[package]]
name = "futures-sink" name = "futures-sink"
version = "0.3.30" version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"
[[package]] [[package]]
name = "futures-task" name = "futures-task"
version = "0.3.30" version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"
[[package]] [[package]]
name = "futures-util" name = "futures-util"
version = "0.3.30" version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-io", "futures-io",
@ -2098,7 +2098,7 @@ dependencies = [
[[package]] [[package]]
name = "nac3ast" name = "nac3ast"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.m-labs.hk/M-Labs/nac3?rev=581b2f7bb283e74f73450012206846bacf52b19c#581b2f7bb283e74f73450012206846bacf52b19c" source = "git+https://git.m-labs.hk/M-Labs/nac3?rev=5839badadd732262dc24af2971a94dde60f7103e#5839badadd732262dc24af2971a94dde60f7103e"
dependencies = [ dependencies = [
"fxhash", "fxhash",
"lazy_static", "lazy_static",
@ -2109,7 +2109,7 @@ dependencies = [
[[package]] [[package]]
name = "nac3core" name = "nac3core"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.m-labs.hk/M-Labs/nac3?rev=581b2f7bb283e74f73450012206846bacf52b19c#581b2f7bb283e74f73450012206846bacf52b19c" source = "git+https://git.m-labs.hk/M-Labs/nac3?rev=5839badadd732262dc24af2971a94dde60f7103e#5839badadd732262dc24af2971a94dde60f7103e"
dependencies = [ dependencies = [
"crossbeam", "crossbeam",
"indexmap", "indexmap",
@ -2126,7 +2126,7 @@ dependencies = [
[[package]] [[package]]
name = "nac3parser" name = "nac3parser"
version = "0.1.2" version = "0.1.2"
source = "git+https://git.m-labs.hk/M-Labs/nac3?rev=581b2f7bb283e74f73450012206846bacf52b19c#581b2f7bb283e74f73450012206846bacf52b19c" source = "git+https://git.m-labs.hk/M-Labs/nac3?rev=5839badadd732262dc24af2971a94dde60f7103e#5839badadd732262dc24af2971a94dde60f7103e"
dependencies = [ dependencies = [
"ahash", "ahash",
"lalrpop", "lalrpop",
@ -2421,12 +2421,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.20.1" version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
dependencies = [
"portable-atomic",
]
[[package]] [[package]]
name = "orbclient" name = "orbclient"
@ -2449,9 +2446,9 @@ dependencies = [
[[package]] [[package]]
name = "owned_ttf_parser" name = "owned_ttf_parser"
version = "0.24.0" version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "490d3a563d3122bf7c911a59b0add9389e5ec0f5f0c3ac6b91ff235a0e6a7f90" checksum = "22ec719bbf3b2a81c109a4e20b1f129b5566b7dce654bc3872f6a05abf82b2c4"
dependencies = [ dependencies = [
"ttf-parser", "ttf-parser",
] ]
@ -2660,12 +2657,6 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "portable-atomic"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2"
[[package]] [[package]]
name = "powerfmt" name = "powerfmt"
version = "0.2.0" version = "0.2.0"
@ -2723,9 +2714,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.86" version = "1.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -3490,9 +3481,9 @@ dependencies = [
[[package]] [[package]]
name = "ttf-parser" name = "ttf-parser"
version = "0.24.1" version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be21190ff5d38e8b4a2d3b6a3ae57f612cc39c96e83cedeaf7abc338a8bac4a" checksum = "5902c5d130972a0000f60860bfbf46f7ca3db5391eddfedd1b8728bd9dc96c0e"
[[package]] [[package]]
name = "type-map" name = "type-map"

View File

@ -15,4 +15,4 @@ rustfft = "6.2"
[dependencies.nac3core] [dependencies.nac3core]
git = "https://git.m-labs.hk/M-Labs/nac3" git = "https://git.m-labs.hk/M-Labs/nac3"
rev = "581b2f7bb283e74f73450012206846bacf52b19c" rev = "5839badadd732262dc24af2971a94dde60f7103e"

View File

@ -2,11 +2,11 @@
"nodes": { "nodes": {
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1727907660, "lastModified": 1728193676,
"narHash": "sha256-QftbyPoieM5M50WKUMzQmWtBWib/ZJbHo7mhj5riQec=", "narHash": "sha256-PbDWAIjKJdlVg+qQRhzdSor04bAPApDqIv2DofTyynk=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5966581aa04be7eff830b9e1457d56dc70a0b798", "rev": "ecbc1ca8ffd6aea8372ad16be9ebbb39889e55b6",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -20,7 +20,7 @@
cargoLock = { cargoLock = {
lockFile = ./Cargo.lock; lockFile = ./Cargo.lock;
outputHashes = { outputHashes = {
"nac3ast-0.1.0" = "sha256-3+e6JTlhepXyD/BfSqq8pgjakLCjiBZAhvOiCNMqe5c="; "nac3ast-0.1.0" = "sha256-38HCzhXPl3RG6hMs+Aq0iuuN58eK2cioAXWOzAGk4qU=";
}; };
}; };
nativeBuildInputs = [ nativeBuildInputs = [

View File

@ -121,48 +121,52 @@ fn handle_typevar_definition(
fn handle_assignment_pattern( fn handle_assignment_pattern(
targets: &[nac3parser::ast::Expr], targets: &[nac3parser::ast::Expr],
value: &nac3parser::ast::Expr, value: &nac3parser::ast::Expr,
resolver: &(dyn nac3core::symbol_resolver::SymbolResolver + Send + Sync), resolver: Arc<dyn nac3core::symbol_resolver::SymbolResolver + Send + Sync>,
internal_resolver: &ResolverInternal, internal_resolver: &ResolverInternal,
def_list: &[Arc<RwLock<toplevel::TopLevelDef>>], composer: &mut composer::TopLevelComposer,
unifier: &mut nac3core::typecheck::typedef::Unifier,
primitives: &type_inferencer::PrimitiveStore,
) -> Result<(), String> { ) -> Result<(), String> {
if targets.len() == 1 { if targets.len() == 1 {
match &targets[0].node { let target = &targets[0];
match &target.node {
nac3parser::ast::ExprKind::Name { id, .. } => { nac3parser::ast::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) = } else if let Ok(val) = toplevel::helper::parse_parameter_default_value(value, &*resolver) {
toplevel::helper::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 {}",
targets[0].node, target.node,
targets[0].location, target.location,
)) ))
} }
} }
nac3parser::ast::ExprKind::List { elts, .. } nac3parser::ast::ExprKind::List { elts, .. }
| nac3parser::ast::ExprKind::Tuple { elts, .. } => { | nac3parser::ast::ExprKind::Tuple { elts, .. } => {
handle_assignment_pattern( handle_assignment_pattern(elts, value, resolver, internal_resolver, composer)?;
elts,
value,
resolver,
internal_resolver,
def_list,
unifier,
primitives,
)?;
Ok(()) Ok(())
} }
_ => Err(format!( _ => Err(format!(
"assignment to {:?} is not supported at {}", "assignment to {target:?} is not supported at {}",
targets[0], targets[0].location target.location
)), )),
} }
} else { } else {
@ -174,11 +178,9 @@ fn handle_assignment_pattern(
handle_assignment_pattern( handle_assignment_pattern(
std::slice::from_ref(tar), std::slice::from_ref(tar),
val, val,
resolver, resolver.clone(),
internal_resolver, internal_resolver,
def_list, composer,
unifier,
primitives,
)?; )?;
} }
Ok(()) Ok(())
@ -202,8 +204,9 @@ fn handle_assignment_pattern(
fn handle_global_var( fn handle_global_var(
target: &nac3parser::ast::Expr, target: &nac3parser::ast::Expr,
value: Option<&nac3parser::ast::Expr>, value: Option<&nac3parser::ast::Expr>,
resolver: &(dyn nac3core::symbol_resolver::SymbolResolver + Send + Sync), resolver: &Arc<dyn nac3core::symbol_resolver::SymbolResolver + Send + Sync>,
internal_resolver: &ResolverInternal, internal_resolver: &ResolverInternal,
composer: &mut composer::TopLevelComposer,
) -> Result<(), String> { ) -> Result<(), String> {
let nac3parser::ast::ExprKind::Name { id, .. } = target.node else { let nac3parser::ast::ExprKind::Name { id, .. } = target.node else {
return Err(format!( return Err(format!(
@ -218,8 +221,18 @@ fn handle_global_var(
)); ));
}; };
if let Ok(val) = toplevel::helper::parse_parameter_default_value(value, resolver) { if let Ok(val) = toplevel::helper::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!(
@ -382,17 +395,12 @@ fn compile(code: &String, run_symbol: &String, output_filename: &Path) -> Result
for mut stmt in parser_result { for mut stmt in parser_result {
match stmt.node { match stmt.node {
nac3parser::ast::StmtKind::Assign { targets, value, .. } => { nac3parser::ast::StmtKind::Assign { targets, value, .. } => {
let def_list = composer.extract_def_list();
let unifier = &mut composer.unifier;
let primitives = &composer.primitives_ty;
handle_assignment_pattern( handle_assignment_pattern(
&targets, &targets,
&value, &value,
resolver.as_ref(), resolver.clone(),
internal_resolver.as_ref(), internal_resolver.as_ref(),
&def_list, &mut composer,
unifier,
primitives,
)?; )?;
} }
nac3parser::ast::StmtKind::AnnAssign { nac3parser::ast::StmtKind::AnnAssign {
@ -403,14 +411,10 @@ fn compile(code: &String, run_symbol: &String, output_filename: &Path) -> Result
handle_global_var( handle_global_var(
&target, &target,
value.as_ref().map(Box::as_ref), value.as_ref().map(Box::as_ref),
resolver.as_ref(), &resolver,
internal_resolver.as_ref(), internal_resolver.as_ref(),
&mut composer,
)?; )?;
let (name, def_id, _) = composer
.register_top_level(stmt, Some(resolver.clone()), "__main__", true)
.unwrap();
internal_resolver.add_id_def(name, def_id);
} }
_ => { _ => {
if let nac3parser::ast::StmtKind::FunctionDef { name, .. } = &mut stmt.node { if let nac3parser::ast::StmtKind::FunctionDef { name, .. } = &mut stmt.node {
@ -689,11 +693,17 @@ pub extern "C" fn __nac3_cells_fft(reals: *mut List, imags: *mut List) {
let mut planner = rustfft::FftPlanner::<f64>::new(); let mut planner = rustfft::FftPlanner::<f64>::new();
let fft = planner.plan_fft_forward(reals_slice.len()); let fft = planner.plan_fft_forward(reals_slice.len());
let mut buffer = vec![num_complex::Complex { re: 0.0, im: 0.0 }; reals_slice.len()]; let mut buffer = vec![num_complex::Complex { re: 0.0, im: 0.0 }; reals_slice.len()];
for (buf, (re, im)) in buffer.iter_mut().zip(reals_slice.iter().zip(imags_slice.iter())) { for (buf, (re, im)) in buffer
.iter_mut()
.zip(reals_slice.iter().zip(imags_slice.iter()))
{
*buf = num_complex::Complex { re: *re, im: *im }; *buf = num_complex::Complex { re: *re, im: *im };
} }
fft.process(&mut buffer); fft.process(&mut buffer);
for (buf, (re, im)) in buffer.iter().zip(reals_slice.iter_mut().zip(imags_slice.iter_mut())) { for (buf, (re, im)) in buffer
.iter()
.zip(reals_slice.iter_mut().zip(imags_slice.iter_mut()))
{
*re = buf.re; *re = buf.re;
*im = buf.im; *im = buf.im;
} }