feat(phase-9.75g): Complete expressions.rs modularization
Successfully split 1457-line expressions.rs into 7 focused modules: - operators.rs (334 lines) - Binary/unary operations - method_dispatch.rs (456 lines) - Method call dispatch - field_access.rs (126 lines) - Field access handling - delegation.rs (325 lines) - from calls and delegation - async_ops.rs (16 lines) - await expressions - utils.rs (34 lines) - Utility functions - expressions.rs (179 lines) - Main dispatcher ✅ All functionality preserved - tested with using nyashstd 🎯 Code organization dramatically improved with single responsibility principle 🚀 Maintenance and development efficiency significantly enhanced 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
49
src/interpreter/utils.rs
Normal file
49
src/interpreter/utils.rs
Normal file
@ -0,0 +1,49 @@
|
||||
/*!
|
||||
* Utility Functions Module
|
||||
*
|
||||
* Extracted from expressions.rs lines 1033-1085 (~52 lines)
|
||||
* Handles utility functions for object identification and hash calculations
|
||||
* Core philosophy: "Everything is Box" with helper utilities
|
||||
*/
|
||||
|
||||
use super::*;
|
||||
|
||||
impl NyashInterpreter {
|
||||
/// 🔄 循環参照検出: オブジェクトの一意IDを取得
|
||||
pub(super) fn get_object_id(&self, node: &ASTNode) -> Option<usize> {
|
||||
match node {
|
||||
ASTNode::Variable { name, .. } => {
|
||||
// 変数名のハッシュをIDとして使用
|
||||
Some(self.hash_string(name))
|
||||
}
|
||||
ASTNode::Me { .. } => {
|
||||
// 'me'参照の特別なID
|
||||
Some(usize::MAX)
|
||||
}
|
||||
ASTNode::This { .. } => {
|
||||
// 'this'参照の特別なID
|
||||
Some(usize::MAX - 1)
|
||||
}
|
||||
_ => None, // 他のノードタイプはID追跡しない
|
||||
}
|
||||
}
|
||||
|
||||
/// 🔄 文字列のシンプルなハッシュ関数
|
||||
pub(super) fn hash_string(&self, s: &str) -> usize {
|
||||
let mut hash = 0usize;
|
||||
for byte in s.bytes() {
|
||||
hash = hash.wrapping_mul(31).wrapping_add(byte as usize);
|
||||
}
|
||||
hash
|
||||
}
|
||||
|
||||
/// 🔗 Convert NyashBox to NyashValue for weak reference operations
|
||||
/// Note: Currently commented out due to complexity, to be implemented in future phases
|
||||
#[allow(dead_code)]
|
||||
fn box_to_nyash_value(&self, _box_val: &Box<dyn NyashBox>) -> Option<crate::value::NyashValue> {
|
||||
// This is a placeholder for future weak reference implementation
|
||||
// When implemented, this will convert Box types back to NyashValue
|
||||
// for proper weak reference storage and management
|
||||
None
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user