"""
RPy — Python-to-Roblox Luau transpiler.
"""
__version__ = "1.0.0"

from transpiler.frontend import node_registry
from transpiler.frontend import handlers
from transpiler.infrastructure import errors
from transpiler.infrastructure import flags

# ── Backwards-compatible re-exports ──────────────────────────────
# After refactoring the transpiler into sub-packages (frontend, middleend,
# backend, optimization, infrastructure), many existing files still import
# from the old flat paths like `transpiler.generator` or `transpiler.flags`.
# The shim modules below keep those paths working:
#
#   Old path                    → Re-exported from
#   transpiler.ir               → transpiler.middleend.ir
#   transpiler.generator        → transpiler.backend.generator
#   transpiler.flags            → transpiler.infrastructure.flags
#   transpiler.errors           → transpiler.infrastructure.errors
#   transpiler.parser           → transpiler.frontend.parser
#   transpiler.ast_utils        → transpiler.frontend.ast_utils
#   transpiler.node_registry    → transpiler.frontend.node_registry
#   transpiler.ir_optimizer     → transpiler.optimization.ir_optimizer
#   transpiler.query_service    → transpiler.middleend.query_service
#
# These are provided for backwards compatibility only. New code should use
# the fully-qualified sub-package paths.

import importlib as _importlib
import sys as _sys

_COMPAT_MAP = {
    "transpiler.ir":             "transpiler.middleend.ir",
    "transpiler.generator":      "transpiler.backend.generator",
    "transpiler.parser":         "transpiler.frontend.parser",
    "transpiler.ast_utils":      "transpiler.frontend.ast_utils",
    "transpiler.ir_optimizer":   "transpiler.optimization.ir_optimizer",
    "transpiler.query_service":  "transpiler.middleend.query_service",
}

for _alias, _real in _COMPAT_MAP.items():
    if _alias not in _sys.modules:
        try:
            _sys.modules[_alias] = _importlib.import_module(_real)
        except ImportError:
            pass  # Don't crash if a sub-module has its own issues

# `transpiler.flags` and `transpiler.errors` are already importable because
# we import them in this file above together with the sub-packages. But the
# modules themselves are registered under the sub-package name.  We alias
# them so that `from transpiler.flags import CompilerFlags` works:
_sys.modules.setdefault("transpiler.flags", flags)
_sys.modules.setdefault("transpiler.errors", errors)
