Commit Graph

8 Commits

Author SHA1 Message Date
55777a0735 feat: Implement field visibility (public/private) system
## Major Features Added

### Field Visibility System
- Added `private { ... }` and `public { ... }` blocks in box declarations
- Default visibility is now handled explicitly (fields must be in either block)
- Visibility checks enforced at both interpreter and VM levels

### Parser Enhancements
- Extended AST with public_fields and private_fields vectors
- Added parsing for visibility blocks in box definitions
- Maintained backward compatibility with existing `init { ... }` syntax

### Interpreter Implementation
- Added visibility checks in field access (get_field/set_field)
- External access to private fields now throws appropriate errors
- Internal access (within methods) always allowed

### VM Implementation
- Extended VM with object_class tracking for visibility checks
- RefGet/RefSet instructions now enforce field visibility
- Fixed nested box declaration collection (boxes defined inside methods)

### Test Examples Added
- docs/examples/visibility_ok.nyash - demonstrates correct usage
- docs/examples/visibility_error.nyash - tests private field access errors

## Technical Details

### Error Messages
- Interpreter: "Field 'X' is private in Y"
- VM: Same error message for consistency

### Current Limitations
- All RefGet/RefSet treated as external access in VM (internal flag future work)
- Legacy `init { ... }` fields treated as having unspecified visibility

## Test Results
 Interpreter: Both test cases pass correctly
 VM: Both test cases pass correctly after nested declaration fix

This implements the foundation for proper encapsulation in Nyash,
following the "explicit is better than implicit" philosophy.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-21 03:08:13 +09:00
69a07cbb1f fix: fini後のアクセスエラーを削除(ユーザー要求対応)
ユーザーからの明確な要求「finiは何回呼ばれてもエラーにならないしよう」に従い、
fini後のインスタンスアクセスを禁止するエラーチェックをすべて削除しました。

変更内容:
- interpreter/statements.rs: is_finalized()チェック削除(3箇所)
- interpreter/field_access.rs: is_finalized()チェック削除
- interpreter/expressions/calls.rs: is_finalized()チェック削除
- interpreter/expressions/access.rs: is_finalized()チェック削除

動作確認:
- test_fini_multiple_calls.nyash: finiを3回呼んでもエラーなし
- fini後のフィールドアクセスも正常動作
- CHIP-8エミュレータも正常動作

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-20 14:34:46 +09:00
46836680b9 Phase 2 Complete: Conditional debug system + Final verification
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
2025-08-20 00:12:35 +00:00
ce16f592b8 Phase 1 Complete: Remove critical debug statements - Major performance improvement
Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
2025-08-20 00:07:47 +00:00
5582ad45c0 feat: Phase 9.78e complete - instance_v2 migration with legacy compatibility
- instance_v2 now includes legacy compatibility layer
- All interpreter code migrated to use instance_v2
- Added legacy field access methods (get_fields, set_field_legacy, etc.)
- Fixed type conversion issues (NyashValue vs SharedNyashBox)
- instance.rs still exists but no longer used in interpreter
- TODO: Remove instance.rs completely in next phase
- TODO: Implement proper SharedNyashBox -> NyashValue conversion

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-19 22:35:34 +09:00
fa1a3ad644 feat(Phase 9.75j): Complete warning elimination - 106→0 warnings (100% improvement)
 Major code quality improvements:
• Fixed all unused variable and parameter warnings
• Added appropriate #[allow(dead_code)] annotations
• Renamed constants to follow Rust naming conventions
• Achieved completely warning-free codebase

🔧 Key changes:
• Parser expressions: Fixed arg_count and statement_count usage
• MIR modules: Added dead_code allows for future-use code
• Backend modules: Prefixed unused parameters with underscore
• Effect constants: Renamed 'read' to 'READ_ALIAS' for conventions

📊 Results:
• Before: 106 warnings (noisy build output)
• After: 0 warnings (clean build)
• Improvement: 100% warning reduction

🎯 This continues the bug fixing initiative "つづきのしゅうせいおねがいにゃ!"
from Phase 9.75i (birth() fixes, static methods, Copilot apps).

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-16 17:39:04 +09:00
ef14f44825 refactor(interpreter): Step 5 - Extract builtins module
- Move execute_builtin_box_method() to expressions/builtins.rs (88 lines)
- Move execute_builtin_birth_method() to expressions/builtins.rs (74 lines)
- Complete expressions module refactoring (5/5 steps)
- Remove orphaned doc comment that prevented compilation
- Total extracted: ~380 lines from mod.rs to 4 specialized modules
- Improved maintainability with single responsibility principle
2025-08-16 13:11:53 +09:00
b0ed2920fd refactor(interpreter): Step 1 - Setup expressions module structure
- Move expressions.rs to expressions/mod.rs
- Create empty module files: operators.rs, calls.rs, access.rs, builtins.rs
- Add module declarations to mod.rs
- Build passes successfully

Next: Step 2 - Extract operator functions
2025-08-16 12:41:19 +09:00