From ada9ba98cca5ea9b01998b3ffa535bd60b514123 Mon Sep 17 00:00:00 2001 From: bakaq Date: Fri, 6 Sep 2024 16:51:10 -0300 Subject: [PATCH] Make macros private --- build/instructions_template.rs | 4 +- build/static_string_indexing.rs | 1 - src/arena.rs | 2 - src/atom_table.rs | 1 - src/codegen.rs | 2 - src/heap_print.rs | 5 --- src/machine/arithmetic_ops.rs | 3 -- src/machine/attributed_variables.rs | 1 - src/machine/dispatch.rs | 2 - src/machine/loader.rs | 1 - src/machine/mod.rs | 1 + src/machine/term_stream.rs | 2 - src/macros.rs | 1 - src/parser/ast.rs | 13 ------ src/parser/macros.rs | 67 ++++++++--------------------- 15 files changed, 20 insertions(+), 86 deletions(-) diff --git a/build/instructions_template.rs b/build/instructions_template.rs index 86cde2f3..100d3d4f 100644 --- a/build/instructions_template.rs +++ b/build/instructions_template.rs @@ -3281,14 +3281,14 @@ pub fn generate_instructions_rs() -> TokenStream { } } - #[macro_export] macro_rules! _instr { #( #instr_macro_arms );* } - pub use _instr as instr; // https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997 + // https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997 + pub(crate) use _instr as instr; } } diff --git a/build/static_string_indexing.rs b/build/static_string_indexing.rs index e6ed11eb..02b853f6 100644 --- a/build/static_string_indexing.rs +++ b/build/static_string_indexing.rs @@ -164,7 +164,6 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea )* ]; - #[macro_export] macro_rules! atom { #((#static_strs) => { Atom { index: #indices_iter } };)* } diff --git a/src/arena.rs b/src/arena.rs index 3d1293a6..01d45758 100644 --- a/src/arena.rs +++ b/src/arena.rs @@ -29,7 +29,6 @@ use std::ptr::addr_of_mut; use std::ptr::NonNull; use std::sync::RwLock; -#[macro_export] macro_rules! arena_alloc { ($e:expr, $arena:expr) => {{ let result = $e; @@ -37,7 +36,6 @@ macro_rules! arena_alloc { }}; } -#[macro_export] macro_rules! float_alloc { ($e:expr, $arena:expr) => {{ let result = $e; diff --git a/src/atom_table.rs b/src/atom_table.rs index ea3a3a78..b84cfbfd 100644 --- a/src/atom_table.rs +++ b/src/atom_table.rs @@ -124,7 +124,6 @@ impl Hash for Atom { } } -#[macro_export] macro_rules! is_char { ($s:expr) => { !$s.is_empty() && $s.chars().nth(1).is_none() diff --git a/src/codegen.rs b/src/codegen.rs index 23c59238..a8049d68 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -8,11 +8,9 @@ use crate::instructions::*; use crate::iterators::*; use crate::parser::ast::*; use crate::targets::*; -use crate::temp_v; use crate::types::*; use crate::variable_records::*; -use crate::instr; use crate::machine::disjuncts::*; use crate::machine::machine_errors::*; diff --git a/src/heap_print.rs b/src/heap_print.rs index a2540617..3c83b029 100644 --- a/src/heap_print.rs +++ b/src/heap_print.rs @@ -4,11 +4,6 @@ use crate::parser::ast::*; use crate::parser::dashu::base::RemEuclid; use crate::parser::dashu::integer::Sign; use crate::parser::dashu::{ibig, Integer, Rational}; -use crate::{ - alpha_numeric_char, capital_letter_char, cut_char, decimal_digit_char, graphic_token_char, - semicolon_char, sign_char, single_quote_char, small_letter_char, solo_char, - variable_indicator_char, -}; use crate::forms::*; use crate::heap_iter::*; diff --git a/src/machine/arithmetic_ops.rs b/src/machine/arithmetic_ops.rs index a1e715e3..64e66f4d 100644 --- a/src/machine/arithmetic_ops.rs +++ b/src/machine/arithmetic_ops.rs @@ -15,8 +15,6 @@ use crate::parser::ast::*; use crate::parser::dashu::{Integer, Rational}; use crate::types::*; -use crate::fixnum; - use ordered_float::{Float, OrderedFloat}; use std::cmp; @@ -24,7 +22,6 @@ use std::convert::TryFrom; use std::f64; use std::mem; -#[macro_export] macro_rules! try_numeric_result { ($e: expr, $stub_gen: expr) => { match $e { diff --git a/src/machine/attributed_variables.rs b/src/machine/attributed_variables.rs index 2f117afc..d84822fe 100644 --- a/src/machine/attributed_variables.rs +++ b/src/machine/attributed_variables.rs @@ -1,7 +1,6 @@ use crate::heap_iter::*; use crate::machine::*; use crate::parser::ast::*; -use crate::temp_v; use crate::types::*; use indexmap::IndexSet; diff --git a/src/machine/dispatch.rs b/src/machine/dispatch.rs index 7fac8993..25c0cc01 100644 --- a/src/machine/dispatch.rs +++ b/src/machine/dispatch.rs @@ -7,8 +7,6 @@ use crate::machine::machine_state::*; use crate::machine::*; use crate::types::*; -use crate::try_numeric_result; - use fxhash::FxBuildHasher; macro_rules! step_or_fail { diff --git a/src/machine/loader.rs b/src/machine/loader.rs index b3e1fdde..bf754bd0 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -211,7 +211,6 @@ impl PredicateQueue { } } -#[macro_export] macro_rules! predicate_queue { [$($v:expr),*] => ( PredicateQueue { diff --git a/src/machine/mod.rs b/src/machine/mod.rs index cb89edc7..dfc6cd3a 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -1,4 +1,5 @@ pub mod args; +#[macro_use] pub mod arithmetic_ops; pub mod attributed_variables; pub mod code_walker; diff --git a/src/machine/term_stream.rs b/src/machine/term_stream.rs index c2361937..686a8c19 100644 --- a/src/machine/term_stream.rs +++ b/src/machine/term_stream.rs @@ -7,8 +7,6 @@ use crate::parser::ast::*; use crate::parser::parser::*; use crate::read::devour_whitespace; -use crate::predicate_queue; - use fxhash::FxBuildHasher; use indexmap::IndexSet; diff --git a/src/macros.rs b/src/macros.rs index ca556513..30a863ca 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -144,7 +144,6 @@ macro_rules! stack_loc_as_cell { }; } -#[macro_export] macro_rules! heap_loc_as_cell { ($h:expr) => { HeapCellValue::build_with(HeapCellValueTag::Var, $h as u64) diff --git a/src/parser/ast.rs b/src/parser/ast.rs index ec699c21..a9c3f2fb 100644 --- a/src/parser/ast.rs +++ b/src/parser/ast.rs @@ -139,7 +139,6 @@ pub const BTERM: u32 = 0x11000; pub const NEGATIVE_SIGN: u32 = 0x0200; -#[macro_export] macro_rules! fixnum { ($wrapper:tt, $n:expr, $arena:expr) => { Fixnum::build_with_checked($n) @@ -180,21 +179,18 @@ macro_rules! is_negate { }; } -#[macro_export] macro_rules! is_prefix { ($x:expr) => { $x as u32 & ($crate::parser::ast::FX as u32 | $crate::parser::ast::FY as u32) != 0 }; } -#[macro_export] macro_rules! is_postfix { ($x:expr) => { $x as u32 & ($crate::parser::ast::XF as u32 | $crate::parser::ast::YF as u32) != 0 }; } -#[macro_export] macro_rules! is_infix { ($x:expr) => { ($x as u32 @@ -205,48 +201,41 @@ macro_rules! is_infix { }; } -#[macro_export] macro_rules! is_xfx { ($x:expr) => { ($x as u32 & $crate::parser::ast::XFX as u32) != 0 }; } -#[macro_export] macro_rules! is_xfy { ($x:expr) => { ($x as u32 & $crate::parser::ast::XFY as u32) != 0 }; } -#[macro_export] macro_rules! is_yfx { ($x:expr) => { ($x as u32 & $crate::parser::ast::YFX as u32) != 0 }; } -#[macro_export] macro_rules! is_yf { ($x:expr) => { ($x as u32 & $crate::parser::ast::YF as u32) != 0 }; } -#[macro_export] macro_rules! is_xf { ($x:expr) => { ($x as u32 & $crate::parser::ast::XF as u32) != 0 }; } -#[macro_export] macro_rules! is_fx { ($x:expr) => { ($x as u32 & $crate::parser::ast::FX as u32) != 0 }; } -#[macro_export] macro_rules! is_fy { ($x:expr) => { ($x as u32 & $crate::parser::ast::FY as u32) != 0 @@ -317,14 +306,12 @@ impl Default for VarReg { } } -#[macro_export] macro_rules! temp_v { ($x:expr) => { $crate::parser::ast::RegType::Temp($x) }; } -#[macro_export] macro_rules! perm_v { ($x:expr) => { $crate::parser::ast::RegType::Perm($x) diff --git a/src/parser/macros.rs b/src/parser/macros.rs index ecf629f8..7027ebe8 100644 --- a/src/parser/macros.rs +++ b/src/parser/macros.rs @@ -1,237 +1,204 @@ -#[macro_export] macro_rules! char_class { ($c: expr, [$head:expr]) => ($c == $head); - ($c: expr, [$head:expr $(, $cs:expr)+]) => ($c == $head || $crate::char_class!($c, [$($cs),*])); + ($c: expr, [$head:expr $(, $cs:expr)+]) => ($c == $head || char_class!($c, [$($cs),*])); } -#[macro_export] macro_rules! alpha_char { ($c: expr) => { (!$c.is_numeric() && !$c.is_whitespace() && !$c.is_control() - && !$crate::graphic_token_char!($c) - && !$crate::layout_char!($c) - && !$crate::meta_char!($c) - && !$crate::solo_char!($c)) + && !graphic_token_char!($c) + && !layout_char!($c) + && !meta_char!($c) + && !solo_char!($c)) || $c == '_' }; } -#[macro_export] macro_rules! alpha_numeric_char { ($c: expr) => { - $crate::alpha_char!($c) || $c.is_numeric() + alpha_char!($c) || $c.is_numeric() }; } -#[macro_export] macro_rules! backslash_char { ($c: expr) => { $c == '\\' }; } -#[macro_export] macro_rules! back_quote_char { ($c: expr) => { $c == '`' }; } -#[macro_export] macro_rules! octet_char { ($c: expr) => { ('\u{0000}'..='\u{00FF}').contains(&$c) }; } -#[macro_export] macro_rules! capital_letter_char { ($c: expr) => { $c.is_uppercase() }; } -#[macro_export] macro_rules! comment_1_char { ($c: expr) => { $c == '/' }; } -#[macro_export] macro_rules! comment_2_char { ($c: expr) => { $c == '*' }; } -#[macro_export] macro_rules! cut_char { ($c: expr) => { $c == '!' }; } -#[macro_export] macro_rules! decimal_digit_char { ($c: expr) => { $c.is_ascii_digit() }; } -#[macro_export] macro_rules! decimal_point_char { ($c: expr) => { $c == '.' }; } -#[macro_export] macro_rules! double_quote_char { ($c: expr) => { $c == '"' }; } -#[macro_export] macro_rules! end_line_comment_char { ($c: expr) => { $c == '%' }; } -#[macro_export] macro_rules! exponent_char { ($c: expr) => { $c == 'e' || $c == 'E' }; } -#[macro_export] macro_rules! graphic_char { - ($c: expr) => ($crate::char_class!($c, ['#', '$', '&', '*', '+', '-', '.', '/', ':', + ($c: expr) => (char_class!($c, ['#', '$', '&', '*', '+', '-', '.', '/', ':', '<', '=', '>', '?', '@', '^', '~'])) } -#[macro_export] macro_rules! graphic_token_char { ($c: expr) => { - $crate::graphic_char!($c) || $crate::backslash_char!($c) + graphic_char!($c) || backslash_char!($c) }; } -#[macro_export] macro_rules! hexadecimal_digit_char { ($c: expr) => { $c.is_ascii_digit() || ('A'..='F').contains(&$c) || ('a'..='f').contains(&$c) }; } -#[macro_export] macro_rules! layout_char { ($c: expr) => { - $crate::char_class!($c, [' ', '\r', '\n', '\t', '\u{0B}', '\u{0C}']) + char_class!($c, [' ', '\r', '\n', '\t', '\u{0B}', '\u{0C}']) }; } -#[macro_export] macro_rules! meta_char { ($c: expr) => { - $crate::char_class!($c, ['\\', '\'', '"', '`']) + char_class!($c, ['\\', '\'', '"', '`']) }; } -#[macro_export] macro_rules! new_line_char { ($c: expr) => { $c == '\n' }; } -#[macro_export] macro_rules! octal_digit_char { ($c: expr) => { ('0'..='7').contains(&$c) }; } -#[macro_export] macro_rules! binary_digit_char { ($c: expr) => { $c == '0' || $c == '1' }; } -#[macro_export] macro_rules! prolog_char { ($c: expr) => { - $crate::graphic_char!($c) - || $crate::alpha_numeric_char!($c) - || $crate::solo_char!($c) - || $crate::layout_char!($c) - || $crate::meta_char!($c) + graphic_char!($c) + || alpha_numeric_char!($c) + || solo_char!($c) + || layout_char!($c) + || meta_char!($c) }; } -#[macro_export] macro_rules! semicolon_char { ($c: expr) => { $c == ';' }; } -#[macro_export] macro_rules! sign_char { ($c: expr) => { $c == '-' || $c == '+' }; } -#[macro_export] macro_rules! single_quote_char { ($c: expr) => { $c == '\'' }; } -#[macro_export] macro_rules! small_letter_char { ($c: expr) => { $c.is_alphabetic() && !$c.is_uppercase() }; } -#[macro_export] macro_rules! solo_char { ($c: expr) => { - $crate::char_class!($c, ['!', '(', ')', ',', ';', '[', ']', '{', '}', '|', '%']) + char_class!($c, ['!', '(', ')', ',', ';', '[', ']', '{', '}', '|', '%']) }; } -#[macro_export] macro_rules! space_char { ($c: expr) => { $c == ' ' }; } -#[macro_export] macro_rules! symbolic_control_char { ($c: expr) => { - $crate::char_class!($c, ['a', 'b', 'f', 'n', 'r', 't', 'v', '0']) + char_class!($c, ['a', 'b', 'f', 'n', 'r', 't', 'v', '0']) }; } -#[macro_export] macro_rules! symbolic_hexadecimal_char { ($c: expr) => { $c == 'x' }; } -#[macro_export] macro_rules! variable_indicator_char { ($c: expr) => { $c == '_' -- 2.54.0