update: use debug colors

This commit is contained in:
GreasrySlug 2023-01-26 14:46:44 +09:00
parent db12bb1e2d
commit 97cde41592
5 changed files with 21 additions and 19 deletions

View file

@ -356,11 +356,11 @@ macro_rules! debug_enum_assert {
macro_rules! debug_info {
($output:ident) => {{
#[allow(unused_imports)]
use $crate::style::{CYAN, RESET};
use $crate::style::{colors::DEBUG, RESET};
write!(
$output,
"[{}DEBUG{}] {}:{:04}: ",
CYAN,
DEBUG,
RESET,
file!(),
line!()
@ -369,8 +369,8 @@ macro_rules! debug_info {
}};
() => {{
#[allow(unused_imports)]
use $crate::style::{CYAN, RESET};
print!("[{}DEBUG{}] {}:{:04}: ", CYAN, RESET, file!(), line!());
use $crate::style::{colors::DEBUG, RESET};
print!("[{}DEBUG{}] {}:{:04}: ", DEBUG, RESET, file!(), line!());
}};
}
@ -386,25 +386,25 @@ macro_rules! debug_info {
#[macro_export]
macro_rules! log {
(info $($arg: tt)*) => {{
$crate::log!(c GREEN, $($arg)*);
$crate::log!(c DEBUG_MAIN, $($arg)*);
}};
(err $($arg: tt)*) => {{
$crate::log!(c RED, $($arg)*);
$crate::log!(c DEBUG_ERROR, $($arg)*);
}};
(info_f $output:ident, $($arg: tt)*) => {{
$crate::log!(f+c $output, GREEN, $($arg)*);
$crate::log!(f+c $output, DEBUG_MAIN, $($arg)*);
}};
(err_f $output:ident, $($arg: tt)*) => {{
$crate::log!(f+c $output, RED, $($arg)*);
$crate::log!(f+c $output, DEBUG_ERROR, $($arg)*);
}};
(f $output: ident, $($arg: tt)*) => {{
if cfg!(feature = "debug") {
#[allow(unused_imports)]
use $crate::color::{RESET, GREEN, RED};
use $crate::color::{RESET, colors::DEBUG_MAIN, colors::DEBUG_ERROR};
$crate::debug_info!($output);
write!($output, $($arg)*).unwrap();
write!($output, "{}", RESET).unwrap(); // color color anyway
@ -415,7 +415,7 @@ macro_rules! log {
(c $color:ident, $($arg: tt)*) => {{
if cfg!(feature = "debug") {
#[allow(unused_imports)]
use $crate::style::{RESET, GREEN, RED};
use $crate::style::{RESET, colors::DEBUG_MAIN, colors::DEBUG_ERROR};
$crate::debug_info!();
print!("{}", $color);
println!($($arg)*);
@ -426,7 +426,7 @@ macro_rules! log {
(f+c $output:ident, $color:ident, $($arg: tt)*) => {{
if cfg!(feature = "debug") {
#[allow(unused_imports)]
use $crate::style::{RESET, GREEN};
use $crate::style::{RESET, colors::DEBUG_MAIN};
$crate::debug_info!($output);
write!($output, "{}{}{}", $color, $($arg)*, RESET).unwrap();
write!($output, $($arg)*).unwrap();

View file

@ -2,6 +2,7 @@
use std::option::Option; // conflicting to Type::Option
use erg_common::error::{Location, MultiErrorDisplay};
use erg_common::style::colors::DEBUG_ERROR;
use crate::ty::constructors::{and, not, or, poly};
use crate::ty::free::{Constraint, FreeKind};
@ -131,7 +132,7 @@ impl Context {
|| self.nominal_supertype_of(lhs, rhs)
}
};
log!("answer: {lhs} {RED}:>{RESET} {rhs} == {res}");
log!("answer: {lhs} {DEBUG_ERROR}:>{RESET} {rhs} == {res}");
res
}

View file

@ -4,6 +4,7 @@ use erg_common::config::ErgConfig;
use erg_common::dict::Dict;
use erg_common::error::Location;
use erg_common::set::Set;
use erg_common::style::colors::DEBUG_MAIN;
use erg_common::traits::{Locational, Stream};
use erg_common::vis::Visibility;
use erg_common::Str;
@ -78,7 +79,7 @@ impl OwnershipChecker {
self.check_expr(chunk, Ownership::Owned, true);
}
log!(
"{GREEN}[DEBUG] the ownership checking process has completed, found errors: {}{RESET}",
"{DEBUG_MAIN}[DEBUG] the ownership checking process has completed, found errors: {}{RESET}",
self.errs.len()
);
if self.errs.is_empty() {

View file

@ -33,7 +33,7 @@ macro_rules! debug_call_info {
($self: ident) => {
$self.level += 1;
log!(
c GREEN,
c DEBUG_MAIN,
"\n{} ({}) entered {}, cur: {}",
"".repeat(($self.level as f32 / 4.0).floor() as usize),
$self.level,
@ -48,7 +48,7 @@ macro_rules! debug_exit_info {
($self: ident) => {
$self.level -= 1;
log!(
c GREEN,
c DEBUG_MAIN,
"\n{} ({}) exit {}, cur: {}",
"".repeat(($self.level as f32 / 4.0).floor() as usize),
$self.level,
@ -228,7 +228,7 @@ impl Parser {
pub(crate) fn stack_dec(&mut self, fn_name: &str) {
self.level -= 1;
log!(
c GREEN,
c DEBUG_MAIN,
"\n{} ({}) exit {}, cur: {}",
"".repeat((self.level as f32 / 4.0).floor() as usize),
self.level,

View file

@ -5,7 +5,7 @@ use erg_common::config::{DummyStdin, ErgConfig, Input};
use erg_common::error::MultiErrorDisplay;
use erg_common::python_util::PythonVersion;
use erg_common::spawn::exec_new_thread;
use erg_common::style::{GREEN, RESET};
use erg_common::style::{colors::DEBUG_MAIN, RESET};
use erg_common::traits::{ExitStatus, Runnable, Stream};
use erg_compiler::error::CompileErrors;
@ -107,7 +107,7 @@ fn set_cfg(mut cfg: ErgConfig) -> ErgConfig {
/// The test is intend to run only on 3.11 for fast execution.
/// To execute on other versions, change the version and magic number.
fn _exec_file(file_path: &'static str) -> Result<i32, CompileErrors> {
println!("{GREEN}[test] exec {file_path}{RESET}");
println!("{DEBUG_MAIN}[test] exec {file_path}{RESET}");
let cfg = ErgConfig::with_main_path(PathBuf::from(file_path));
let mut vm = DummyVM::new(set_cfg(cfg));
vm.exec()
@ -115,7 +115,7 @@ fn _exec_file(file_path: &'static str) -> Result<i32, CompileErrors> {
/// WARN: You must quit REPL manually (use `:exit`, `:quit` or call something shutdowns the interpreter)
pub fn _exec_repl(name: &'static str, lines: Vec<String>) -> Result<ExitStatus, CompileErrors> {
println!("{GREEN}[test] exec dummy REPL: {lines:?}{RESET}");
println!("{DEBUG_MAIN}[test] exec dummy REPL: {lines:?}{RESET}");
let cfg = ErgConfig {
input: Input::DummyREPL(DummyStdin::new(name.to_string(), lines)),
quiet_repl: true,