From 201a89b6d3baa349cf02cd5154175a946c85faa3 Mon Sep 17 00:00:00 2001 From: mwojcik Date: Thu, 12 Sep 2024 16:31:01 +0800 Subject: [PATCH] cargo fmt --- Cargo.lock | 1 + nac3artiq/Cargo.toml | 1 + nac3artiq/src/codegen.rs | 11 +++++--- nac3artiq/src/lib.rs | 45 +++++++++++++++++++------------ nac3core/src/toplevel/composer.rs | 16 ++++++----- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 20306b84..2b4dae69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -597,6 +597,7 @@ dependencies = [ "itertools 0.13.0", "nac3core", "nac3ld", + "nac3parser", "parking_lot", "pyo3", "tempfile", diff --git a/nac3artiq/Cargo.toml b/nac3artiq/Cargo.toml index 4e0dd086..7eb1021c 100644 --- a/nac3artiq/Cargo.toml +++ b/nac3artiq/Cargo.toml @@ -15,6 +15,7 @@ parking_lot = "0.12" tempfile = "3.10" nac3core = { path = "../nac3core" } nac3ld = { path = "../nac3ld" } +nac3parser = { path = "../nac3parser" } [features] init-llvm-profile = [] diff --git a/nac3artiq/src/codegen.rs b/nac3artiq/src/codegen.rs index 4d471050..62dbda11 100644 --- a/nac3artiq/src/codegen.rs +++ b/nac3artiq/src/codegen.rs @@ -832,7 +832,6 @@ fn rpc_codegen_callback_fn<'ctx>( let ptr_type = int8.ptr_type(AddressSpace::default()); let tag_ptr_type = ctx.ctx.struct_type(&[ptr_type.into(), size_type.into()], false); - let service_id = int32.const_int(fun.1 .0 as u64, false); // -- setup rpc tags let mut tag = Vec::new(); @@ -950,7 +949,11 @@ fn rpc_codegen_callback_fn<'ctx>( ) }); ctx.builder - .build_call(rpc_send_async, &[service_id.into(), tag_ptr.into(), args_ptr.into()], "rpc.send") + .build_call( + rpc_send_async, + &[service_id.into(), tag_ptr.into(), args_ptr.into()], + "rpc.send", + ) .unwrap(); } else { let rpc_send = ctx.module.get_function("rpc_send").unwrap_or_else(|| { @@ -980,12 +983,12 @@ fn rpc_codegen_callback_fn<'ctx>( Ok(None) } else { let result = format_rpc_ret(generator, ctx, fun.0.ret); - + if !result.is_some_and(|res| res.get_type().is_pointer_type()) { // An RPC returning an NDArray would not touch here. call_stackrestore(ctx, stackptr); } - + Ok(result) } } diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index eb39a03d..1734117d 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -34,16 +34,12 @@ use nac3core::inkwell::{ targets::*, OptimizationLevel, }; -use itertools::Itertools; -use nac3core::codegen::{gen_func_impl, CodeGenLLVMOptions, CodeGenTargetMachineOptions}; use nac3core::toplevel::builtins::get_exn_constructor; use nac3core::typecheck::typedef::{into_var_map, TypeEnum, Unifier, VarMap}; use nac3parser::{ ast::{Constant, ExprKind, Located, Stmt, StmtKind, StrRef}, parser::parse_program, }; -use nac3core::toplevel::builtins::get_exn_constructor; -use nac3core::typecheck::typedef::{into_var_map, TypeEnum, Unifier, VarMap}; use pyo3::create_exception; use pyo3::prelude::*; use pyo3::{exceptions, types::PyBytes, types::PyDict, types::PySet}; @@ -139,7 +135,7 @@ struct Nac3 { string_store: Arc>>, exception_ids: Arc>>, deferred_eval_store: DeferredEvaluationStore, - /// LLVM-related options for code generzation. + /// LLVM-related options for code generation. llvm_options: CodeGenLLVMOptions, } @@ -479,12 +475,24 @@ impl Nac3 { match &stmt.node { StmtKind::FunctionDef { decorator_list, .. } => { - if decorator_list.iter().any(|decorator| decorator_id_string(decorator) == Some("rpc".to_string())) { - store_fun.call1(py, (def_id.0.into_py(py), module.getattr(py, name.to_string().as_str()).unwrap())).unwrap(); - let is_async = decorator_list.iter().any( - |decorator| decorator_get_flags(decorator).iter().any( - |constant| *constant == Constant::Str("async".into()) - )); + if decorator_list + .iter() + .any(|decorator| decorator_id_string(decorator) == Some("rpc".to_string())) + { + store_fun + .call1( + py, + ( + def_id.0.into_py(py), + module.getattr(py, name.to_string().as_str()).unwrap(), + ), + ) + .unwrap(); + let is_async = decorator_list.iter().any(|decorator| { + decorator_get_flags(decorator) + .iter() + .any(|constant| *constant == Constant::Str("async".into())) + }); rpc_ids.push((None, def_id, is_async)); } } @@ -493,11 +501,14 @@ impl Nac3 { let class_obj = module.getattr(py, class_name.as_str()).unwrap(); for stmt in body { if let StmtKind::FunctionDef { name, decorator_list, .. } = &stmt.node { - if decorator_list.iter().any(|decorator| decorator_id_string(decorator) == Some("rpc".to_string())) { - let is_async = decorator_list.iter().any( - |decorator| decorator_get_flags(decorator).iter().any( - |constant| *constant == Constant::Str("async".into()) - )); + if decorator_list.iter().any(|decorator| { + decorator_id_string(decorator) == Some("rpc".to_string()) + }) { + let is_async = decorator_list.iter().any(|decorator| { + decorator_get_flags(decorator) + .iter() + .any(|constant| *constant == Constant::Str("async".into())) + }); if name == &"__init__".into() { return Err(CompileError::new_err(format!( "compilation failed\n----------\nThe constructor of class {} should not be decorated with rpc decorator (at {})", @@ -509,7 +520,7 @@ impl Nac3 { } } } - _ => () + _ => (), } let id = *name_to_pyid.get(&name).unwrap(); diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index 98eeebe3..125e137a 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -1673,7 +1673,7 @@ impl TopLevelComposer { // they may be changed with our use of placeholders for (def, _) in definition_ast_list.iter().skip(self.builtin_num) { if let TopLevelDef::Function { signature, var_id, .. } = &mut *def.write() { - if let TypeEnum::TFunc(FunSignature { args, ret, vars}) = + if let TypeEnum::TFunc(FunSignature { args, ret, vars }) = unifier.get_ty(*signature).as_ref() { let new_var_ids = vars @@ -1894,7 +1894,8 @@ impl TopLevelComposer { } = &mut *function_def { let signature_ty_enum = unifier.get_ty(*signature); - let TypeEnum::TFunc(FunSignature { args, ret, vars, .. }) = signature_ty_enum.as_ref() + let TypeEnum::TFunc(FunSignature { args, ret, vars, .. }) = + signature_ty_enum.as_ref() else { unreachable!("must be typeenum::tfunc") }; @@ -2059,11 +2060,12 @@ impl TopLevelComposer { } if !decorator_list.is_empty() { if let ast::ExprKind::Call { func, .. } = &decorator_list[0].node { - if matches!(&func.node, - ast::ExprKind::Name{ id, .. } if id == &"rpc".into()) { - instance_to_symbol.insert(String::new(), simple_name.to_string()); - continue; - } + if matches!(&func.node, + ast::ExprKind::Name{ id, .. } if id == &"rpc".into()) + { + instance_to_symbol.insert(String::new(), simple_name.to_string()); + continue; + } } }