Commit ea8f1c63

ea8f1c634d34Merged

Ryan Seys <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

feat(codegen): support redo in the each-family blocks

Wraps every loop-body emit site in the each family with the redo-label helpers — covering Array#each (across all 13 typed-array branches: int_array / str_array / float_array / sym_array / ptr_array / range / poly_array, plus the 7 hash-keys-each branches and the hash.keys.each fusion fast path), Array#each_with_index, Array#each_slice, Array#each_cons, Array#each_with_object, and the orthogonal String#each_byte (whose 4-line body-emit pattern matched the canonical shape and got swept up by the same replace).

Each typed-array branch in compile_each_block emits its own C label via push_redo_label — emitting the same name twice in one function would fail to compile, so the counter-driven sp_redo_ uniqueness is load-bearing here.

Block-param assignments (lv_ = sp__get(...)) stay outside the redo label so redo re-runs the body with the same value without re-fetching from the iterator.

🤖 Generated with Claude Code

Details

Commit
ea8f1c634d34
Parent
ecd8b347e965

spinel_codegen.rbmodifiedView file

@@ -20325,7 +20325,10 @@
2032520325 @indent = @indent + 1
2032620326 push_scope
2032720327 declare_var(bp, "int")
20328+ redo_label = push_redo_label
20329+ emit_redo_label(redo_label)
2032820330 compile_stmts_body(@nd_body[@nd_block[nid]])
20331+ pop_redo_label
2032920332 pop_scope
2033020333 @indent = @indent - 1
2033120334 emit(" }")
@@ -29375,7 +29378,10 @@
2937529378 @indent = @indent + 1
2937629379 push_scope
2937729380 declare_var(bp1, rt)
29381+ redo_label = push_redo_label
29382+ emit_redo_label(redo_label)
2937829383 compile_stmts_body(@nd_body[@nd_block[nid]])
29384+ pop_redo_label
2937929385 pop_scope
2938029386 @indent = @indent - 1
2938129387 emit(" }")
@@ -29414,7 +29420,10 @@
2941429420 @indent = @indent + 1
2941529421 push_scope
2941629422 declare_var(bp1, rt)
29423+ redo_label = push_redo_label
29424+ emit_redo_label(redo_label)
2941729425 compile_stmts_body(@nd_body[@nd_block[nid]])
29426+ pop_redo_label
2941829427 pop_scope
2941929428 @indent = @indent - 1
2942029429 emit(" }")
@@ -29467,7 +29476,10 @@
2946729476 push_scope
2946829477 declare_var(bp1, elem_type_of_array(rt))
2946929478 declare_var(bp2, obj_t)
29479+ redo_label = push_redo_label
29480+ emit_redo_label(redo_label)
2947029481 compile_stmts_body(@nd_body[@nd_block[nid]])
29482+ pop_redo_label
2947129483 pop_scope
2947229484 @indent = @indent - 1
2947329485 emit(" }")
@@ -29501,7 +29513,10 @@
2950129513 push_scope
2950229514 declare_var(bp1, elem_type_of_array(rt))
2950329515 declare_var(bp2, "int")
29516+ redo_label = push_redo_label
29517+ emit_redo_label(redo_label)
2950429518 compile_stmts_body(@nd_body[@nd_block[nid]])
29519+ pop_redo_label
2950529520 pop_scope
2950629521 @indent = @indent - 1
2950729522 emit(" }")
@@ -29559,7 +29574,10 @@
2955929574 if has_bp == 1
2956029575 declare_var(bp1, key_type)
2956129576 end
29577+ redo_label = push_redo_label
29578+ emit_redo_label(redo_label)
2956229579 compile_stmts_body(@nd_body[@nd_block[nid]])
29580+ pop_redo_label
2956329581 pop_scope
2956429582 @indent = @indent - 1
2956529583 emit(" }")
@@ -29590,7 +29608,10 @@
2959029608 if has_bp == 1
2959129609 declare_var(bp1, elem_type_of_array(rt))
2959229610 end
29611+ redo_label = push_redo_label
29612+ emit_redo_label(redo_label)
2959329613 compile_stmts_body(@nd_body[@nd_block[nid]])
29614+ pop_redo_label
2959429615 pop_scope
2959529616 @indent = @indent - 1
2959629617 emit(" }")
@@ -29606,7 +29627,10 @@
2960629627 if has_bp == 1
2960729628 declare_var(bp1, "symbol")
2960829629 end
29630+ redo_label = push_redo_label
29631+ emit_redo_label(redo_label)
2960929632 compile_stmts_body(@nd_body[@nd_block[nid]])
29633+ pop_redo_label
2961029634 pop_scope
2961129635 @indent = @indent - 1
2961229636 emit(" }")
@@ -29662,7 +29686,10 @@
2966229686 declare_var(bp1, elem_type)
2966329687 end
2966429688 end
29689+ redo_label = push_redo_label
29690+ emit_redo_label(redo_label)
2966529691 compile_stmts_body(@nd_body[@nd_block[nid]])
29692+ pop_redo_label
2966629693 pop_scope
2966729694 @indent = @indent - 1
2966829695 emit(" }")
@@ -29680,7 +29707,10 @@
2968029707 if bp2 != ""
2968129708 declare_var(bp2, "int")
2968229709 end
29710+ redo_label = push_redo_label
29711+ emit_redo_label(redo_label)
2968329712 compile_stmts_body(@nd_body[@nd_block[nid]])
29713+ pop_redo_label
2968429714 pop_scope
2968529715 @indent = @indent - 1
2968629716 emit(" }")
@@ -29698,7 +29728,10 @@
2969829728 if bp2 != ""
2969929729 declare_var(bp2, "string")
2970029730 end
29731+ redo_label = push_redo_label
29732+ emit_redo_label(redo_label)
2970129733 compile_stmts_body(@nd_body[@nd_block[nid]])
29734+ pop_redo_label
2970229735 pop_scope
2970329736 @indent = @indent - 1
2970429737 emit(" }")
@@ -29716,7 +29749,10 @@
2971629749 if bp2 != ""
2971729750 declare_var(bp2, "string")
2971829751 end
29752+ redo_label = push_redo_label
29753+ emit_redo_label(redo_label)
2971929754 compile_stmts_body(@nd_body[@nd_block[nid]])
29755+ pop_redo_label
2972029756 pop_scope
2972129757 @indent = @indent - 1
2972229758 emit(" }")
@@ -29734,7 +29770,10 @@
2973429770 if bp2 != ""
2973529771 declare_var(bp2, "int")
2973629772 end
29773+ redo_label = push_redo_label
29774+ emit_redo_label(redo_label)
2973729775 compile_stmts_body(@nd_body[@nd_block[nid]])
29776+ pop_redo_label
2973829777 pop_scope
2973929778 @indent = @indent - 1
2974029779 emit(" }")
@@ -29752,7 +29791,10 @@
2975229791 if bp2 != ""
2975329792 declare_var(bp2, "string")
2975429793 end
29794+ redo_label = push_redo_label
29795+ emit_redo_label(redo_label)
2975529796 compile_stmts_body(@nd_body[@nd_block[nid]])
29797+ pop_redo_label
2975629798 pop_scope
2975729799 @indent = @indent - 1
2975829800 emit(" }")
@@ -29770,7 +29812,10 @@
2977029812 if bp2 != ""
2977129813 declare_var(bp2, "poly")
2977229814 end
29815+ redo_label = push_redo_label
29816+ emit_redo_label(redo_label)
2977329817 compile_stmts_body(@nd_body[@nd_block[nid]])
29818+ pop_redo_label
2977429819 pop_scope
2977529820 @indent = @indent - 1
2977629821 emit(" }")
@@ -29788,7 +29833,10 @@
2978829833 if bp2 != ""
2978929834 declare_var(bp2, "poly")
2979029835 end
29836+ redo_label = push_redo_label
29837+ emit_redo_label(redo_label)
2979129838 compile_stmts_body(@nd_body[@nd_block[nid]])
29839+ pop_redo_label
2979229840 pop_scope
2979329841 @indent = @indent - 1
2979429842 emit(" }")
@@ -29803,7 +29851,10 @@
2980329851 if has_bp == 1
2980429852 declare_var(bp1, "int")
2980529853 end
29854+ redo_label = push_redo_label
29855+ emit_redo_label(redo_label)
2980629856 compile_stmts_body(@nd_body[@nd_block[nid]])
29857+ pop_redo_label
2980729858 pop_scope
2980829859 @indent = @indent - 1
2980929860 emit(" }")
@@ -29817,7 +29868,10 @@
2981729868 if has_bp == 1
2981829869 declare_var(bp1, "poly")
2981929870 end
29871+ redo_label = push_redo_label
29872+ emit_redo_label(redo_label)
2982029873 compile_stmts_body(@nd_body[@nd_block[nid]])
29874+ pop_redo_label
2982129875 pop_scope
2982229876 @indent = @indent - 1
2982329877 emit(" }")