2929#include "internal/set_table.h"
3030#include "internal/struct.h"
3131#include "variable.h"
32+ #include "vm_insnhelper.h" // @kaan: remove, something else is including but clangd can't see it
3233
3334/* finish iseq array */
3435#include "insns.inc"
@@ -5301,6 +5302,23 @@ vm_invoke_iseq_block_cc_arg1_param1_local1(rb_execution_context_t *ec, rb_contro
53015302 return vm_invoke_iseq_positional_block (ec , reg_cfp , calling , 1 , 1 , 1 );
53025303}
53035304
5305+ static VALUE
5306+ vm_invoke_iseq_block_cc_arg1_param1_local2 (rb_execution_context_t * ec , rb_control_frame_t * reg_cfp ,
5307+ struct rb_calling_info * calling ) {
5308+ return vm_invoke_iseq_positional_block (ec , reg_cfp , calling , 1 , 1 , 2 );
5309+ }
5310+
5311+ static VALUE
5312+ vm_invoke_iseq_block_cc_arg1_param1_local3 (rb_execution_context_t * ec , rb_control_frame_t * reg_cfp ,
5313+ struct rb_calling_info * calling ) {
5314+ return vm_invoke_iseq_positional_block (ec , reg_cfp , calling , 1 , 1 , 3 );
5315+ }
5316+ static VALUE
5317+ vm_invoke_iseq_block_cc_arg1_param1_local4 (rb_execution_context_t * ec , rb_control_frame_t * reg_cfp ,
5318+ struct rb_calling_info * calling ) {
5319+ return vm_invoke_iseq_positional_block (ec , reg_cfp , calling , 1 , 1 , 4 );
5320+ }
5321+
53045322static VALUE
53055323vm_invoke_iseq_block_cc (rb_execution_context_t * ec , rb_control_frame_t * reg_cfp ,
53065324 struct rb_calling_info * calling ) {
@@ -5995,7 +6013,7 @@ static const struct rb_callcache vm_invokeblock_hardcoded = {
59956013};
59966014
59976015static const struct rb_callcache *
5998- vm_invokeblock_fastpath (struct rb_execution_context_struct * ec ,
6016+ vm_invokeblock_fastpath (struct rb_execution_context_struct * ec , // @kaan: unused parameter
59996017 struct rb_control_frame_struct * reg_cfp ,
60006018 struct rb_call_data * cd ,
60016019 VALUE block_handler )
@@ -6011,15 +6029,20 @@ vm_invokeblock_fastpath(struct rb_execution_context_struct *ec,
60116029 if (vm_block_handler_type (block_handler ) == block_handler_type_iseq ) {
60126030 // what to do
60136031 const struct rb_captured_block * captured = VM_BH_TO_ISEQ_BLOCK (block_handler );
6032+ // printf("captured->code.iseq: %p\n", captured->code.iseq);
60146033 const rb_iseq_t * callee_iseq = rb_iseq_check (captured -> code .iseq );
6034+ // printf("If 6011\n");
60156035
60166036 // check cache
60176037 if (LIKELY (cd -> cc -> klass == (VALUE )callee_iseq )) {
60186038 ret = cd -> cc ;
60196039 }
60206040 else {
6041+ // printf("Else 6018\n");
60216042 if (rb_simple_iseq_p (callee_iseq )) {
6043+ // printf("If 6020\n");
60226044 if (vm_ci_flag (ci ) & VM_CALL_ARGS_SIMPLE ) {
6045+ // printf("If 6022\n");
60236046 /*
60246047 if ((unsigned int)ISEQ_BODY(callee_iseq)->param.size == 0 && vm_ci_argc(ci) > 0) {
60256048 fprintf(stderr, "ignored params %d %d\n", vm_ci_argc(ci), ISEQ_BODY(callee_iseq)->local_table_size);
@@ -6028,30 +6051,53 @@ vm_invokeblock_fastpath(struct rb_execution_context_struct *ec,
60286051
60296052 if (vm_ci_argc (ci ) == (unsigned int )ISEQ_BODY (callee_iseq )-> param .size &&
60306053 ISEQ_BODY (callee_iseq )-> param .flags .ambiguous_param0 ) {
6031-
6054+ // printf("If 6033\n");
60326055 if (!ISEQ_BODY (callee_iseq )-> block_ccs ) {
60336056 ISEQ_BODY (callee_iseq )-> block_ccs = ZALLOC (struct rb_class_cc_entries );
6057+ // printf("Allocated block_ccs 6035\n");
60346058 }
60356059
6060+ // printf("callee_iseq->block_ccs: %p\n", callee_iseq);
60366061 struct rb_class_cc_entries * ccs = ISEQ_BODY (callee_iseq )-> block_ccs ;
60376062 unsigned int argc = vm_ci_argc (ci );
60386063 unsigned int flag = vm_ci_flag (ci );
6064+ // Ensure flags are correct and specialized
60396065
6066+ // There exists a Similar loop, we could call that instead of repeat
6067+ // Probably until the end (RUBY_ASSERT)
6068+ // printf("ccs->len: %d\n", ccs->len);
60406069 for (int i = 0 ; i < ccs -> len ; i ++ ) {
6070+ // printf("For 6031\n");
60416071 if (ccs -> entries [i ].argc == argc && ccs -> entries [i ].flag == flag ) {
6072+ // printf("CACHED 6043\n");
60426073 return ccs -> entries [i ].cc ;
60436074 }
60446075 }
60456076
6046- if (argc == 1 && ISEQ_BODY (callee_iseq )-> local_table_size == 1 ) {
6077+ if (argc == 1 && ISEQ_BODY (callee_iseq )-> local_table_size == 1 ) { // Once per block
6078+ // printf("1 arg\n");
60476079 ret = vm_cc_new ((VALUE )callee_iseq , NULL , vm_invoke_iseq_block_cc_arg1_param1_local1 , cc_type_block );
60486080 }
6081+ else if (argc == 1 && ISEQ_BODY (callee_iseq )-> local_table_size == 2 ) { // Once per block
6082+ // printf("1 arg\n");
6083+ ret = vm_cc_new ((VALUE )callee_iseq , NULL , vm_invoke_iseq_block_cc_arg1_param1_local2 , cc_type_block );
6084+ }
6085+ else if (argc == 1 && ISEQ_BODY (callee_iseq )-> local_table_size == 3 ) { // Once per block
6086+ // printf("1 arg\n");
6087+ ret = vm_cc_new ((VALUE )callee_iseq , NULL , vm_invoke_iseq_block_cc_arg1_param1_local3 , cc_type_block );
6088+ } else if (argc == 1 && ISEQ_BODY (callee_iseq )-> local_table_size == 4 ) { // Once per block
6089+ // printf("1 arg\n");
6090+ ret = vm_cc_new ((VALUE )callee_iseq , NULL , vm_invoke_iseq_block_cc_arg1_param1_local4 , cc_type_block );
6091+ }
60496092 else {
6093+ // printf("else 6061 \n");
6094+ fprintf (stderr , "argc: %d, local_table_size: %d, flag: %d\n" , argc , ISEQ_BODY (callee_iseq )-> local_table_size , flag );
60506095 ret = vm_cc_new ((VALUE )callee_iseq , NULL , vm_invoke_iseq_block_cc , cc_type_block );
60516096 }
60526097
60536098 cd -> cc = ret ;
60546099 RB_OBJ_WRITTEN (reg_cfp -> iseq , Qundef , ret );
6100+ // printf("Pushing to cache 6059\n");
60556101 vm_ccs_push ((VALUE )callee_iseq , ISEQ_BODY (callee_iseq )-> block_ccs , ci , ret );
60566102 RUBY_ASSERT (ret -> klass == (VALUE )callee_iseq );
60576103 }
@@ -6063,6 +6109,7 @@ vm_invokeblock_fastpath(struct rb_execution_context_struct *ec,
60636109 ISEQ_BODY(callee_iseq)->param.size);
60646110 }
60656111 */
6112+ // printf("Else 6071\n");
60666113 }
60676114 }
60686115 else {
@@ -6076,6 +6123,7 @@ vm_invokeblock_fastpath(struct rb_execution_context_struct *ec,
60766123 fprintf(stderr, "not ambiguous param?\n");
60776124 }
60786125 */
6126+ // printf("Else 6077\n");
60796127 }
60806128 }
60816129 else {
@@ -6084,10 +6132,12 @@ vm_invokeblock_fastpath(struct rb_execution_context_struct *ec,
60846132 fprintf(stderr, "iseq not simple\n");
60856133 }
60866134 */
6135+ // printf("Else 6085\n");
60876136 }
60886137 }
60896138 }
60906139 }
6140+ // printf("returning ret\n");
60916141 return ret ;
60926142}
60936143
@@ -6122,6 +6172,8 @@ vm_sendish(
61226172 val = vm_cc_call (cc )(ec , GET_CFP (), & calling );
61236173 break ;
61246174 case mexp_search_invokeblock :
6175+ // val = vm_invokeblock_i(ec, GET_CFP(), &calling);
6176+
61256177 calling .cc = cc = vm_invokeblock_fastpath (ec , GET_CFP (), cd , VM_CF_BLOCK_HANDLER (GET_CFP ()));
61266178 val = vm_cc_call (cc )(ec , GET_CFP (), & calling );
61276179 break ;
0 commit comments