refactor(rewrite): Phase 287 P5 - Code cleanup after toString SSOT
Three targeted cleanups following Phase 287 P4 toString normalization:
1. known.rs: Extract primitive guard into helper function
- Unified 4 duplicate guard blocks (60 lines) into single function (15 lines)
- 75% code reduction with improved testability
- Function: should_block_primitive_str_rewrite()
2. special.rs: Extract trace helper
- Unified 3 duplicate NYASH_STATIC_CALL_TRACE checks
- Function: trace_tostring()
3. boxcall.py: Constant-ify magic numbers
- UNIVERSAL_SLOT_TOSTRING = 0 (self-documenting)
- TOSTRING_METHODS = ("toString", "stringify", "str")
Total impact: ~45 lines reduced, improved maintainability.
SSOT maintained: toString always uses universal slot #0.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -4,6 +4,10 @@ Core of Nyash's "Everything is Box" philosophy
|
||||
"""
|
||||
|
||||
import llvmlite.ir as ir
|
||||
|
||||
# Phase 287 P5: Universal slot constants (SSOT)
|
||||
UNIVERSAL_SLOT_TOSTRING = 0 # toString/stringify/str (all types)
|
||||
TOSTRING_METHODS = ("toString", "stringify", "str")
|
||||
from typing import Dict, List, Optional, Any
|
||||
from instructions.safepoint import insert_automatic_safepoint
|
||||
from naming_helper import encode_static_method
|
||||
@ -93,7 +97,7 @@ def lower_boxcall(
|
||||
|
||||
# Phase 287 P4: Universal slot #0 handling (toString/stringify/str)
|
||||
# SSOT: toString is ALWAYS slot #0, works on ALL types including primitives
|
||||
if method_id == 0 and method_name in ("toString", "stringify", "str"):
|
||||
if method_id == UNIVERSAL_SLOT_TOSTRING and method_name in TOSTRING_METHODS:
|
||||
import os, sys
|
||||
if os.environ.get('NYASH_LLVM_TRACE_SLOT') == '1':
|
||||
print(f"[llvm-py/slot] Universal slot #0: {method_name} on box_vid={box_vid}", file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user