"""
Spork - A Lisp to Python transpiler with persistent data structures.
"""

import sys

# Import persistent data structures from runtime (wraps C extension)
try:
    from spork.runtime import (
        _MISSING,
        EMPTY_DOUBLE_VECTOR,
        EMPTY_LONG_VECTOR,
        EMPTY_MAP,
        EMPTY_SET,
        # Empty constants
        EMPTY_VECTOR,
        Cons,
        Decorated,
        DoubleVector,
        IntVector,
        Keyword,
        Map,
        MapLiteral,
        MatchError,
        Set,
        SetLiteral,
        # AST/Reader types
        Symbol,
        TransientDoubleVector,
        TransientIntVector,
        TransientMap,
        TransientSet,
        TransientVector,
        # PDS types
        Vector,
        VectorLiteral,
        add,
        assoc,
        assoc_bang,
        bit_and,
        bit_and_not,
        bit_not,
        # Bitwise
        bit_or,
        bit_shift_left,
        bit_shift_right,
        bit_xor,
        concat,
        conj,
        conj_bang,
        cons,
        contains_q,
        count,
        cycle,
        dec,
        dedupe,
        disj,
        disj_bang,
        dissoc,
        dissoc_bang,
        distinct,
        div,
        doall,
        dorun,
        drop,
        drop_while,
        empty,
        even_q,
        every,
        # Sequence operations
        first,
        flatten,
        frequencies,
        get,
        group_by,
        hash_map,
        hash_set,
        # Math
        inc,
        interleave,
        interpose,
        into,
        iterate,
        keep,
        keep_indexed,
        map_indexed,
        mapcat,
        mod,
        mul,
        neg_q,
        not_any,
        not_every,
        nth,
        odd_q,
        partition,
        partition_all,
        persistent_bang,
        pop_bang,
        pos_q,
        quot,
        realized_q,
        reduce,
        reductions,
        rest,
        reverse,
        seq,
        # Runtime utilities
        setup_runtime_env,
        # Predicates and reducers
        some,
        sort,
        sort_by,
        split_at,
        split_with,
        spork_abs,
        spork_filter,
        # Lazy sequences
        spork_map,
        spork_max,
        spork_min,
        spork_raise,
        spork_range,
        spork_repeat,
        spork_setattr,
        spork_try,
        sub,
        take,
        take_while,
        # Transients
        transient,
        # Constructors
        vec,
        vec_f64,
        vec_i64,
        zero_q,
        # Collection utilities
        zipmap,
    )
except ImportError as e:
    print("Error: Spork runtime could not be loaded.", file=sys.stderr)
    print(f"  {e}", file=sys.stderr)
    print("", file=sys.stderr)
    print("The C extension (pds) may not be built. Try:", file=sys.stderr)
    print("  make build", file=sys.stderr)
    print("", file=sys.stderr)
    sys.exit(1)

# Import compiler functions
from spork.compiler import (
    MACRO_ENV,
    Reader,
    compile_forms_to_code,
    eval_str,
    exec_file,
    export_file,
    install_import_hook,
    # Macros
    macroexpand,
    macroexpand_all,
    # Reader
    read_str,
    tokenize,
)

install_import_hook()

__version__ = "0.1.0"

__all__ = [
    # Data structures
    "Vector",
    "Map",
    "Set",
    "DoubleVector",
    "IntVector",
    "Cons",
    "TransientVector",
    "TransientDoubleVector",
    "TransientIntVector",
    "TransientMap",
    "TransientSet",
    "EMPTY_VECTOR",
    "EMPTY_DOUBLE_VECTOR",
    "EMPTY_LONG_VECTOR",
    "EMPTY_MAP",
    "EMPTY_SET",
    "cons",
    "vec",
    "vec_f64",
    "vec_i64",
    "hash_map",
    "hash_set",
    # AST/Reader types
    "Symbol",
    "Keyword",
    "VectorLiteral",
    "MapLiteral",
    "SetLiteral",
    "Decorated",
    "MatchError",
    "_MISSING",
    # Compilation
    "compile_forms_to_code",
    "eval_str",
    "exec_file",
    "export_file",
    "install_import_hook",
    "read_str",
    "tokenize",
    "Reader",
    "macroexpand",
    "macroexpand_all",
    "MACRO_ENV",
    # Sequence operations
    "first",
    "rest",
    "seq",
    "nth",
    "conj",
    "assoc",
    "dissoc",
    "disj",
    "get",
    "count",
    "contains_q",
    "drop",
    "concat",
    "into",
    "empty",
    "spork_map",
    "spork_filter",
    "take",
    "take_while",
    "drop_while",
    "spork_repeat",
    "cycle",
    "iterate",
    "spork_range",
    "interleave",
    "interpose",
    "partition",
    "partition_all",
    "keep",
    "keep_indexed",
    "map_indexed",
    "dedupe",
    "distinct",
    "flatten",
    "mapcat",
    "some",
    "every",
    "not_every",
    "not_any",
    "reduce",
    "reductions",
    "zipmap",
    "group_by",
    "frequencies",
    "reverse",
    "sort",
    "sort_by",
    "split_at",
    "split_with",
    "doall",
    "dorun",
    "realized_q",
    # Math
    "inc",
    "dec",
    "even_q",
    "odd_q",
    "pos_q",
    "neg_q",
    "zero_q",
    "add",
    "sub",
    "mul",
    "div",
    "mod",
    "quot",
    "spork_max",
    "spork_min",
    "spork_abs",
    # Bitwise
    "bit_or",
    "bit_and",
    "bit_and_not",
    "bit_xor",
    "bit_not",
    "bit_shift_left",
    "bit_shift_right",
    # Transients
    "transient",
    "persistent_bang",
    "conj_bang",
    "assoc_bang",
    "dissoc_bang",
    "disj_bang",
    "pop_bang",
    # Runtime utilities
    "setup_runtime_env",
    "spork_try",
    "spork_raise",
    "spork_setattr",
]
