Skip to content

Commit

Permalink
Replce lazy_static with once_cell
Browse files Browse the repository at this point in the history
Once_cell seems to be preferable method with path toward stabilization
via rust-lang/rfcs#2788
  • Loading branch information
KnucklesAni committed Dec 24, 2022
1 parent 541954a commit ea1a791
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ proc-macro = true

[dependencies]
futures = "0.3"
lazy_static = "1.4"
maplit = "1.0"
once_cell = "1.0"
sqlx = { version = "0.5", features = [ "runtime-tokio-rustls", "sqlite" ] }
tokio = { version = "1.10.0", features = [ "macros" ] }
66 changes: 43 additions & 23 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ extern crate proc_macro;
extern crate maplit;

use futures::TryStreamExt;
use lazy_static::lazy_static;
use proc_macro::{Delimiter, Group, Ident, TokenStream, TokenTree};
use sqlx::{Connection, Row};

Expand Down Expand Up @@ -537,9 +536,11 @@ fn marker_is_compatible<'ᵉˣᵗʳᵃ>(
}
}

lazy_static! {
static ref 𝔦𝔫𝔰𝔱𝔯𝔲𝔠𝔱𝔦𝔬𝔫𝔰_𝔦𝔫𝔣𝔬: (String, String) = get_instrution_info();
static ref 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔩𝔢𝔤𝔞𝔠𝔶: std::collections::HashMap<&'static str, std::vec::Vec<&'static str>> = hashmap! {
static 𝔦𝔫𝔰𝔱𝔯𝔲𝔠𝔱𝔦𝔬𝔫𝔰_𝔦𝔫𝔣𝔬: once_cell::sync::Lazy<(String, String)> = once_cell::sync::Lazy::new(get_instrution_info);
static 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔩𝔢𝔤𝔞𝔠𝔶: once_cell::sync::Lazy<
std::collections::HashMap<&'static str, std::vec::Vec<&'static str>>,
> = once_cell::sync::Lazy::new(|| {
hashmap! {
"reg8" => vec!["𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗ"],
"reg16" => vec!["𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_16ᵇⁱᵗ"],
"reg32" => vec!["𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_32ᵇⁱᵗ"],
Expand All @@ -548,8 +549,12 @@ lazy_static! {
"reg/acc16" => vec!["𝐚𝐜𝐜𝐮𝐦𝐮𝐥𝐚𝐭𝐨𝐫_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_16ᵇⁱᵗ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_16ᵇⁱᵗ"],
"reg/acc32" => vec!["𝐚𝐜𝐜𝐮𝐦𝐮𝐥𝐚𝐭𝐨𝐫_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_32ᵇⁱᵗ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_32ᵇⁱᵗ"],
"reg/acc64" => vec![],
};
static ref 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔵86_64: std::collections::HashMap<&'static str, std::vec::Vec<&'static str>> = hashmap! {
}
});
static 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔵86_64: once_cell::sync::Lazy<
std::collections::HashMap<&'static str, std::vec::Vec<&'static str>>,
> = once_cell::sync::Lazy::new(|| {
hashmap! {
"reg8" => vec!["𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗₗₒ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗₙₒᵣₑₓ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗᵣₑₓ"],
"reg16" => vec!["𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_16ᵇⁱᵗₙₒᵣₑₓ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_16ᵇⁱᵗ"],
"reg32" => vec!["𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_32ᵇⁱᵗₙₒᵣₑₓ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_32ᵇⁱᵗ"],
Expand All @@ -558,8 +563,8 @@ lazy_static! {
"reg/acc16" => vec!["𝐚𝐜𝐜𝐮𝐦𝐮𝐥𝐚𝐭𝐨𝐫_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_16ᵇⁱᵗ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_16ᵇⁱᵗₙₒᵣₑₓ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_16ᵇⁱᵗ"],
"reg/acc32" => vec!["𝐚𝐜𝐜𝐮𝐦𝐮𝐥𝐚𝐭𝐨𝐫_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_32ᵇⁱᵗ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_32ᵇⁱᵗₙₒᵣₑₓ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_32ᵇⁱᵗ"],
"reg/acc64" => vec!["𝐚𝐜𝐜𝐮𝐦𝐮𝐥𝐚𝐭𝐨𝐫_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_64ᵇⁱᵗ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_64ᵇⁱᵗₙₒᵣₑₓ", "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_64ᵇⁱᵗ"],
};
}
}
});

#[tokio::main]
async fn get_instrution_info() -> (String, String) {
Expand All @@ -576,30 +581,45 @@ async fn get_instrution_info() -> (String, String) {
.await
.expect("Failed to connect to test.db database")
};
let mut rows = sqlx::query("SELECT * FROM instructions")
.fetch(&mut pool);
let mut instruction_info_legacy = Vec::new();
let mut instruction_info_x64 = Vec::new();
while let Some (row) = rows.try_next().await.expect("Heh") {
let instruction_name: &str =row.try_get("instruction_name").expect("whatever");
let instruction_argument0: &str =row.try_get("instruction_argument0").expect("whatever");
let instruction_argument1: &str =row.try_get("instruction_argument1").expect("whatever");
if let Some(instruction_argument_cases0) = 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔩𝔢𝔤𝔞𝔠𝔶.get(instruction_argument0) {
let mut rows = sqlx::query("SELECT * FROM instructions").fetch(&mut pool);
let mut instruction_info_legacy = Vec::new();
let mut instruction_info_x64 = Vec::new();
while let Some(row) = rows.try_next().await.expect("Heh") {
let instruction_name: &str = row.try_get("instruction_name").expect("whatever");
let instruction_argument0: &str = row.try_get("instruction_argument0").expect("whatever");
let instruction_argument1: &str = row.try_get("instruction_argument1").expect("whatever");
if let Some(instruction_argument_cases0) = 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔩𝔢𝔤𝔞𝔠𝔶.get(instruction_argument0)
{
for instruction_argument_case0 in instruction_argument_cases0 {
if let Some(instruction_argument_cases1) = 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔩𝔢𝔤𝔞𝔠𝔶.get(instruction_argument1) {
if let Some(instruction_argument_cases1) = 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔩𝔢𝔤𝔞𝔠𝔶.get(instruction_argument1)
{
for instruction_argument_case1 in instruction_argument_cases1 {
instruction_info_legacy.push(format!("{}_𝒊𝒏𝒔𝒕𝒓𝒖𝒄𝒕𝒊𝒐𝒏<(Self::{}, Self::{})>", 𝗍𝗋𝖺𝗂𝗍_𝗇𝖺𝗆𝖾(instruction_name), instruction_argument_case0, instruction_argument_case1));
instruction_info_legacy.push(format!(
"{}_𝒊𝒏𝒔𝒕𝒓𝒖𝒄𝒕𝒊𝒐𝒏<(Self::{}, Self::{})>",
𝗍𝗋𝖺𝗂𝗍_𝗇𝖺𝗆𝖾(instruction_name),
instruction_argument_case0,
instruction_argument_case1
));
}
}
}
}
if let Some(instruction_argument_cases0) = 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔵86_64.get(instruction_argument0) {
for instruction_argument_case0 in instruction_argument_cases0 {
if let Some(instruction_argument_cases1) = 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔵86_64.get(instruction_argument1) {
if let Some(instruction_argument_cases1) = 𝔱𝔞𝔯𝔤𝔢𝔱𝔰_𝔪𝔞𝔭_𝔵86_64.get(instruction_argument1)
{
for instruction_argument_case1 in instruction_argument_cases1 {
if (*instruction_argument_case0 != "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗᵣₑₓ" || *instruction_argument_case1 != "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗₙₒᵣₑₓ") &&
(*instruction_argument_case0 != "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗₙₒᵣₑₓ" || *instruction_argument_case1 != "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗᵣₑₓ") {
instruction_info_x64.push(format!("{}_𝒊𝒏𝒔𝒕𝒓𝒖𝒄𝒕𝒊𝒐𝒏<(Self::{}, Self::{})>", 𝗍𝗋𝖺𝗂𝗍_𝗇𝖺𝗆𝖾(instruction_name), instruction_argument_case0, instruction_argument_case1));
if (*instruction_argument_case0 != "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗᵣₑₓ"
|| *instruction_argument_case1 != "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗₙₒᵣₑₓ")
&& (*instruction_argument_case0 != "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗₙₒᵣₑₓ"
|| *instruction_argument_case1 != "𝐠𝐩_𝐫𝐞𝐠𝐢𝐬𝐭𝐞𝐫_8ᵇⁱᵗᵣₑₓ")
{
instruction_info_x64.push(format!(
"{}_𝒊𝒏𝒔𝒕𝒓𝒖𝒄𝒕𝒊𝒐𝒏<(Self::{}, Self::{})>",
𝗍𝗋𝖺𝗂𝗍_𝗇𝖺𝗆𝖾(instruction_name),
instruction_argument_case0,
instruction_argument_case1
));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/onwer_vs_unique_ptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Why is that a problem? Let's conside a very simple example:
}
~~~

Here we just ass ownership from one object to another. There are no change to produce exceptions, memory allocations and so on.
Here we just pass ownership from one object to another. There are no change to produce exceptions, memory allocations and so on.
And, indeed,
[code produced](https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAM1QDsCBlZAQwBtMQBGAFlICsupVs1qhkAUgBMAISnTSAZ0ztkBPHUqZa6AMKpWAVwC2tQVvQAZPLUwA5YwCNMxEJM6kADqgWF1tPYYmgl4%2BanRWNvZGTi5uisqYqn4MBMzEBAHGpu5KKmG0KWkEEXaOziAAzIqp6ZlBOTXF1qXR5RUAlIqoBsTIHADkUhXWyIZYANTiFTpGmEYkAJ5T2OIADACCa%2BujzAoKkwBiq%2BIAnAAip8fSx0enFyfH65Lit%2BeXdy/Hbw/i6zdf9y%2BK1egN%2BZ0mAHZZBtxh4DA5WHhkCAtuNDgD3tdPh8fk9sd8MSD3n98aCTsCMbizhB2lNoes0QA/UmY/44x7PIk/N5cx5sgmnCnssE0umo8YAN1QeHQ43QqAA%2BgpULMCAhrMBRRV6eIIRdtVstjs9ujhetOCzcQAOS2PACsto%2BvMFjvW0kh9Nh8MRyPFrotzvWNsDDudPMpQNd0ggCgI6BAIAMtDwAEcDJgFR4CMQpjpHVjA5yI07iySw0KBet9dhxgB3GXATAEdrjECm74Q95cztWos4gBs4mkF274it/Pug%2BkFfuPep9fQjYIADpiAldpgaS3dZ7IRcYR5iHgJcwCBxxbH44nk2mM1mc9N8xPiX2BeGzc/uTPidX27Ou5SPavpOQ4joBY6flO34nHOYobLq%2Bo6vBgYBqWwalqGxbvm%2B0GPO6RjMAA1hmCD6FgxAxnGCZJqm6aZtmuZPq6wHvNhoJllhuFgssdYNk225QuKa4ED0tB/sSqFmuhZqYcKbGsVxbqUVe8wSpuC5Lu0tIGvBepbP0nSsCA/R2v0pCmP0qxmagxl5jIcjjMqPR9JMkgVJwZkEMZVlaaQCCYMw5GUJ0hEgHaqxCMZ3BmUYYURRZVmkDZ/RmQoIARV5lkGaQcCwEgaBGB4eDsGQFAQAVRUlSgwiiJwqyrO4VDFWexBpRADjeWZDjWGkCzGR5pAFbM9AAPK0KwfVZaQWAEaI7CddNeBrkkalpVNmAAB6JAYZ79WZ1hnkZU2Ig4xC9XoWB7aQ2Z4LF/QeZ0ND0EwbAcDw/CCDVYhyHIQh4A4aWQJ0qBZn4a0ALQjZI4zg5eUxnBI9kyJwEKpQkSQaBA5h1NkpDmCUUQxME3i%2BHQOPE6EfgE2ULg5Oj%2BSFLU%2BhZIIuSJAzjTU60tPVEU5MNEUXNE5wnROb0b2GcZpnmQtyUbVa/bg/23DjDsojjHVy6rMunDjBAuCECQrnuaQ4x6IVxXOMbItmz9MieZ1vn%2BYF5Q0qQoXhZF/TRTLU3Jal6XXY7kv9JIMVcPVvuJf7QdZb5amtX4IDcEAA)
does precisely that.
Expand Down
2 changes: 1 addition & 1 deletion docs/style_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ We are repurposing them to help us distinguish different entities of C++.

## The define Guard ## {#The_define_Guard}

All header files should have #define guards to prevent multiple inclusion. The format of the symbol name should be
All header files should have \#define guards to prevent multiple inclusion. The format of the symbol name should be
`“𝔓ℜ𝔒𝔍𝔈ℭ𝔗”_“𝔓𝔄𝔗ℌ”_“𝔉ℑ𝔏𝔈”_ℌ`. Note: we are using ALL_CAPS — and not just ALL_CAPS, but
[fraktur-style](https://en.wikipedia.org/wiki/Fraktur)
[𝔄𝔏𝔏 ℭ𝔄𝔓𝔖](https://en.wikipedia.org/wiki/Mathematical_Alphanumeric_Symbols#Latin_letters). This makes include guard different from
Expand Down

0 comments on commit ea1a791

Please sign in to comment.