feat(repl): Phase 288 P3 - Minimal UX (print() displays, .reset works)

UX improvements:
- print() output displays correctly (Main box entry point fix)
- .reset command clears session state
- _ variable stores last VMValue (ready for access)
- Statements execute silently (no auto-display)

Complete REPL workflow verified:
  >>> .help
  Commands:
    .exit / .quit - Exit REPL
    .reset - Clear session
    .help - Show this help
  >>> print("Hello REPL!")
  Hello REPL!
  >>> print(42 + 1)
  43
  >>> x = 42
  >>>                    # Silent (implicit local creation)
  >>> .reset
  Session reset

Key fix:
- Changed wrapper from "__Repl" to "Main" for VM entry point
- VM execute_module() looks for Main.main/0, not __Repl.main/0

Files modified:
- src/runner/mod.rs: Main box wrapper (+3 lines), .reset impl (+7 lines)

Test results:
   print() displays output
   .reset clears session
   .help shows commands
   Statements silent (no auto-display)
   File mode regression: 154/154 tests pass

Deferred to Phase 288.1+:
- Expression auto-display (1+1 → 2)
- Variable persistence across lines
- _ variable access in user code

Phase 288 P0-P3 COMPLETE 

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-25 13:47:54 +09:00
parent 934a774b50
commit 79608bce64

View File

@ -120,12 +120,19 @@ impl NyashRunner {
".help" => {
println!("Commands:");
println!(" .exit / .quit - Exit REPL");
println!(" .reset - Clear session (Phase 288 P2)");
println!(" .reset - Clear session");
println!(" .help - Show this help");
continue;
}
".reset" => {
println!("Session reset (Phase 288 P2 implementation)");
// Phase 288 P3: Reset session
let mut session_ref = self.repl_session.borrow_mut();
if let Some(ref mut session) = *session_ref {
session.reset();
println!("Session reset");
} else {
println!("Session reset (no active session)");
}
continue;
}
"" => continue,
@ -168,8 +175,8 @@ impl NyashRunner {
}
}
// Parse (minimal wrapper for REPL context)
let code = format!("static box __Repl {{ main() {{ {} }} }}", line);
// Parse (minimal wrapper for REPL context - use Main for VM entry point)
let code = format!("static box Main {{ main() {{ {} }} }}", line);
let ast = NyashParser::parse_from_string(&code)
.map_err(|e| format!("Parse error: {}", e))?;
@ -185,7 +192,7 @@ impl NyashRunner {
let result_box = vm.execute_module(&mir_result.module)
.map_err(|e| format!("Runtime error: {}", e))?;
// Phase 288 P2: Convert to VMValue and store in session
// Phase 288 P3: Convert to VMValue and store in session
use crate::backend::VMValue;
let vm_value = VMValue::from_nyash_box(result_box);
@ -197,7 +204,9 @@ impl NyashRunner {
}
}
Ok("(execution Phase 288 P3)".to_string())
// Phase 288 P3: print() output already displayed via ExternCall
// Expression auto-display deferred to Phase 288.1
Ok(String::new())
}
}