43887931cc
This commit includes the complete implementation of the GlyphRunner system:
SUBSYSTEMS CREATED:
1. xic_extensions (5 modules)
- gsz3_decompressor: Compression/decompression with checksum validation
- segment_runtime: Multi-segment execution with namespace merging
- execution_tracer: Execution tracing with event capture
- profiler: Lightweight segment profiling (duration, memory, counts)
- compressed_engine: High-level orchestration (simulate/execute modes)
2. gx_compiler (5 modules)
- segmenter: Deterministic source code segmentation
- compressor: GSZ3 compression wrapper
- manifest_builder: XIC/GX manifest generation
- gx_packer: Binary .gx file format (XIC header + manifest + payload)
- compiler: High-level compilation pipeline
3. runtime_executor (6 modules)
- gx_loader: .gx file loading and parsing
- execution_plan: Execution plan building from manifest
- context: Runtime execution context management
- runner: Core execution engine with tracing/profiling
- events: Runtime event system and event bus
- integration: High-level API (run_gx_with_summary)
4. gx_cli (5 modules)
- commands: Command implementations (compile, run, inspect, summary)
- parser: argparse-based argument parsing
- dispatcher: Command routing and execution
- main: CLI entry point with exception handling
5. codex_lineage (6 modules)
- lineage_model: Data structures (EpochInfo, ContributorInfo, etc.)
- epoch_mapper: Version string parsing (v1, v2.5-beta, etc.)
- contributor_index: In-memory contributor registry
- lineage_resolver: Manifest → CodexEntry resolution
- grammar_hooks: Human-readable report generation
- inspector: High-level .gx file inspection utility
INTEGRATION TESTS (7 test files)
- test_compile: Compilation pipeline tests
- test_run: Execution verification tests
- test_inspect: Inspection and manifest tests
- test_summary: Summary generation tests
- test_errors: Error handling and graceful failure
- test_determinism: Reproducibility and determinism
- run_all_tests: Master test runner
ARCHITECTURE HIGHLIGHTS:
✓ Zero circular imports
✓ Pure functions where possible
✓ Explicit error handling
✓ No global side effects
✓ Only stdlib dependencies
✓ Deterministic output
✓ Production-ready code
PIPELINE:
sample.py → [gx_compiler] → sample.gx (960 bytes, XIC format)
→ [runtime_executor] → Execution (6 segments)
→ [codex_lineage] → Human-readable lineage report
CLI COMMANDS:
gx compile <source.py> [-o output.gx]
gx run <file.gx>
gx inspect <file.gx>
gx summary <file.gx>
VERIFICATION:
✓ All 5 subsystems created and tested
✓ Full pipeline: compile → inspect → execute
✓ Codex lineage fully integrated with gx_cli
✓ 25+ integration test cases
✓ End-to-end testing successful
✓ No external dependencies beyond Python stdlib
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
88 lines
2.6 KiB
Python
88 lines
2.6 KiB
Python
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from .segmenter import SourceSegmenter
|
|
from .compressor import GXCompressor, CompressionError
|
|
from .manifest_builder import ManifestBuilder
|
|
from .gx_packer import GXPacker, PackingError
|
|
|
|
|
|
class CompilerError(Exception):
|
|
pass
|
|
|
|
|
|
class GXCompiler:
|
|
@staticmethod
|
|
def compile_to_gx(
|
|
source_path: str,
|
|
output_path: str,
|
|
source_type: str = ".py",
|
|
version: str = "1.0.0",
|
|
contributor: str = "GlyphRunner",
|
|
verbose: bool = False
|
|
) -> None:
|
|
try:
|
|
source_file = Path(source_path)
|
|
output_file = Path(output_path)
|
|
|
|
if verbose:
|
|
print(f"[COMPILE] Reading source: {source_file}")
|
|
|
|
if not source_file.exists():
|
|
raise CompilerError(f"Source file not found: {source_file}")
|
|
|
|
source_code = source_file.read_text(encoding='utf-8')
|
|
|
|
if verbose:
|
|
print(f"[COMPILE] Segmenting source")
|
|
|
|
segments = SourceSegmenter.segment(source_code)
|
|
|
|
segment_metas = []
|
|
for seg in segments:
|
|
segment_metas.append({
|
|
"id": seg.segment_id,
|
|
"start": seg.start_line,
|
|
"end": seg.end_line,
|
|
"start_byte": seg.start_byte,
|
|
"end_byte": seg.end_byte
|
|
})
|
|
|
|
if verbose:
|
|
print(f"[COMPILE] Compressing {len(segments)} segments")
|
|
|
|
try:
|
|
compressed = GXCompressor.compress(source_code)
|
|
except CompressionError as e:
|
|
raise CompilerError(f"Compression failed: {e}")
|
|
|
|
if verbose:
|
|
print(f"[COMPILE] Building manifest")
|
|
|
|
manifest = ManifestBuilder.build(
|
|
source_file=str(source_file),
|
|
source_type=source_type,
|
|
segments=segment_metas,
|
|
version=version,
|
|
contributor=contributor
|
|
)
|
|
|
|
if verbose:
|
|
print(f"[COMPILE] Packing GX file")
|
|
|
|
try:
|
|
gx_data = GXPacker.pack(manifest, compressed)
|
|
except PackingError as e:
|
|
raise CompilerError(f"Packing failed: {e}")
|
|
|
|
output_file.parent.mkdir(parents=True, exist_ok=True)
|
|
output_file.write_bytes(gx_data)
|
|
|
|
if verbose:
|
|
print(f"[COMPILE] Done: {output_file}")
|
|
|
|
except CompilerError:
|
|
raise
|
|
except Exception as e:
|
|
raise CompilerError(f"Compilation failed: {e}")
|