feat(joinir): Phase 52-53 LoopFrontendBinding JSON + Statement Handlers

Phase 52: LoopFrontendBinding JSON generation fixes
- Add receiver_to_json() for Field node structure (me.tokens)
- Add needs_me_receiver() for instance method detection
- Fix "condition" → "cond" key for JoinIR Frontend
- Add me parameter propagation in loop_patterns.rs
- Add JoinIR-compatible type fields in ast_json.rs
  - Variable → "type": "Var"
  - Literal → "type": "Int"/"Bool" (literal_to_joinir_json)
  - BinaryOp → "type": "Binary"/"Compare" (is_compare_op)
  - MethodCall → "type": "Method"

Phase 53: Statement Handler module for loop body
- NEW: stmt_handlers.rs with StatementEffect type
- Support: Local, Assignment, Print, Method, If statements
- If lowering: single variable update → Select instruction
- Remove hardcoded assert in loop_patterns.rs
- Replace with generic lower_statement() calls

Test results: 56 JoinIR tests PASS, 7 loop_frontend_binding tests PASS

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-29 04:42:16 +09:00
parent 6bb6f38a1c
commit e27934d91a
6 changed files with 545 additions and 53 deletions

View File

@ -173,6 +173,17 @@ impl super::MirBuilder {
// Phase 50: Generate Local declarations from binding
let (i_local, acc_local, n_local) = binding.generate_local_declarations();
// Phase 52: Check if `me` receiver is needed
// Instance methods (like print_tokens) need `me` to be passed as a parameter
let params: Vec<serde_json::Value> = if binding.needs_me_receiver() {
if debug {
eprintln!("[cf_loop/joinir] Adding 'me' to params (instance method)");
}
vec![serde_json::json!("me")]
} else {
vec![]
};
// Step 2: Construct JSON v0 format with "defs" array
// The function is named "simple" to match JoinIR Frontend's pattern matching
// Phase 50: Include i/acc/n Local declarations to satisfy JoinIR Frontend expectations
@ -180,7 +191,7 @@ impl super::MirBuilder {
"defs": [
{
"name": "simple",
"params": [],
"params": params,
"body": {
"type": "Block",
"body": [
@ -190,7 +201,7 @@ impl super::MirBuilder {
n_local,
{
"type": "Loop",
"condition": condition_json,
"cond": condition_json, // JoinIR Frontend expects "cond" not "condition"
"body": body_json
},
// Return the accumulator (or null for side-effect loops)