import sys
from typing import Callable, List

_EXPLAIN_MODE = False
_DEBUG_COMPILER = False
_explain_interceptors: List[Callable[[str, str], None]] = []

def register_interceptor(cb: Callable[[str, str], None]):
    _explain_interceptors.append(cb)

def unregister_interceptor(cb: Callable[[str, str], None]):
    if cb in _explain_interceptors:
        _explain_interceptors.remove(cb)

def set_explain_mode(mode: bool):
    global _EXPLAIN_MODE
    _EXPLAIN_MODE = mode

def set_debug_compiler(mode: bool):
    global _DEBUG_COMPILER
    _DEBUG_COMPILER = mode

def explain(tag: str, msg: str):
    for interceptor in _explain_interceptors:
        interceptor(tag, msg)
    if _EXPLAIN_MODE and not _explain_interceptors:
        print(f"[{tag}] {msg}")

def debug_compiler(tag: str, msg: str):
    if _DEBUG_COMPILER:
        print(f"DEBUG: [{tag}] {msg}")
