diff options
author | Peter Zhu <[email protected]> | 2022-03-23 15:19:48 -0400 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2022-03-24 10:03:51 -0400 |
commit | 5f10bd634fb6ae8f74a4ea730176233b0ca96954 (patch) | |
tree | 170c1c81ea63184290c9e021cc45bffbfc3f4f41 /vm_args.c | |
parent | 04591e1be7618f64bd3bed8c53c0fcde5fcbddb8 (diff) |
Add ISEQ_BODY macro
Use ISEQ_BODY macro to get the rb_iseq_constant_body of the ISeq. Using
this macro will make it easier for us to change the allocation strategy
of rb_iseq_constant_body when using Variable Width Allocation.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5698
Diffstat (limited to 'vm_args.c')
-rw-r--r-- | vm_args.c | 86 |
1 files changed, 43 insertions, 43 deletions
@@ -328,10 +328,10 @@ args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *cons VALUE *const passed_values, const int passed_keyword_len, const VALUE *const passed_keywords, VALUE *const locals) { - const ID *acceptable_keywords = iseq->body->param.keyword->table; - const int req_key_num = iseq->body->param.keyword->required_num; - const int key_num = iseq->body->param.keyword->num; - const VALUE * const default_values = iseq->body->param.keyword->default_values; + const ID *acceptable_keywords = ISEQ_BODY(iseq)->param.keyword->table; + const int req_key_num = ISEQ_BODY(iseq)->param.keyword->required_num; + const int key_num = ISEQ_BODY(iseq)->param.keyword->num; + const VALUE * const default_values = ISEQ_BODY(iseq)->param.keyword->default_values; VALUE missing = 0; int i, di, found = 0; int unspecified_bits = 0; @@ -382,7 +382,7 @@ args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *cons } } - if (iseq->body->param.flags.has_kwrest) { + if (ISEQ_BODY(iseq)->param.flags.has_kwrest) { const int rest_hash_index = key_num + 1; locals[rest_hash_index] = make_rest_kw_hash(passed_keywords, passed_keyword_len, passed_values); } @@ -441,14 +441,14 @@ ignore_keyword_hash_p(VALUE keyword_hash, const rb_iseq_t * const iseq, unsigned keyword_hash = rb_to_hash_type(keyword_hash); } if (!(*kw_flag & VM_CALL_KW_SPLAT_MUT) && - (iseq->body->param.flags.has_kwrest || - iseq->body->param.flags.ruby2_keywords)) { + (ISEQ_BODY(iseq)->param.flags.has_kwrest || + ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) { *kw_flag |= VM_CALL_KW_SPLAT_MUT; keyword_hash = rb_hash_dup(keyword_hash); } *converted_keyword_hash = keyword_hash; - return !(iseq->body->param.flags.has_kw) && - !(iseq->body->param.flags.has_kwrest) && + return !(ISEQ_BODY(iseq)->param.flags.has_kw) && + !(ISEQ_BODY(iseq)->param.flags.has_kwrest) && RHASH_EMPTY_P(keyword_hash); } @@ -458,8 +458,8 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co const struct rb_callinfo *ci, VALUE * const locals, const enum arg_setup_type arg_setup_type) { - const int min_argc = iseq->body->param.lead_num + iseq->body->param.post_num; - const int max_argc = (iseq->body->param.flags.has_rest == FALSE) ? min_argc + iseq->body->param.opt_num : UNLIMITED_ARGUMENTS; + const int min_argc = ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.post_num; + const int max_argc = (ISEQ_BODY(iseq)->param.flags.has_rest == FALSE) ? min_argc + ISEQ_BODY(iseq)->param.opt_num : UNLIMITED_ARGUMENTS; int given_argc; unsigned int kw_flag = vm_ci_flag(ci) & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT); int opt_pc = 0, allow_autosplat = !kw_flag; @@ -476,16 +476,16 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co * * [pushed values] [uninitialized values] * <- ci->argc --> - * <- iseq->body->param.size------------> + * <- ISEQ_BODY(iseq)->param.size------------> * ^ locals ^ sp * * => * [pushed values] [initialized values ] * <- ci->argc --> - * <- iseq->body->param.size------------> + * <- ISEQ_BODY(iseq)->param.size------------> * ^ locals ^ sp */ - for (i=calling->argc; i<iseq->body->param.size; i++) { + for (i=calling->argc; i<ISEQ_BODY(iseq)->param.size; i++) { locals[i] = Qnil; } ec->cfp->sp = &locals[i]; @@ -499,7 +499,7 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co if (kw_flag & VM_CALL_KWARG) { args->kw_arg = vm_ci_kwarg(ci); - if (iseq->body->param.flags.has_kw) { + if (ISEQ_BODY(iseq)->param.flags.has_kw) { int kw_len = args->kw_arg->keyword_len; /* copy kw_argv */ args->kw_argv = ALLOCA_N(VALUE, kw_len); @@ -552,10 +552,10 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co RARRAY_ASET(args->rest, len - 1, rest_last); } - if (iseq->body->param.flags.ruby2_keywords && rest_last) { + if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords && rest_last) { flag_keyword_hash = rest_last; } - else if (iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest) { + else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) { arg_rest_dup(args); rb_ary_pop(args->rest); given_argc--; @@ -578,10 +578,10 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co args->argv[args->argc-1] = last_arg; } - if (iseq->body->param.flags.ruby2_keywords) { + if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords) { flag_keyword_hash = last_arg; } - else if (iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest) { + else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) { args->argc--; given_argc--; keyword_hash = last_arg; @@ -595,7 +595,7 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co ((struct RHash *)flag_keyword_hash)->basic.flags |= RHASH_PASS_AS_KEYWORDS; } - if (kw_flag && iseq->body->param.flags.accepts_no_kwarg) { + if (kw_flag && ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) { rb_raise(rb_eArgError, "no keywords accepted"); } @@ -606,8 +606,8 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co case arg_setup_block: if (given_argc == (NIL_P(keyword_hash) ? 1 : 2) && allow_autosplat && - (min_argc > 0 || iseq->body->param.opt_num > 1) && - !iseq->body->param.flags.ambiguous_param0 && + (min_argc > 0 || ISEQ_BODY(iseq)->param.opt_num > 1) && + !ISEQ_BODY(iseq)->param.flags.ambiguous_param0 && args_check_block_arg0(args)) { given_argc = RARRAY_LENINT(args->rest); } @@ -637,29 +637,29 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co } } - if (iseq->body->param.flags.has_lead) { - args_setup_lead_parameters(args, iseq->body->param.lead_num, locals + 0); + if (ISEQ_BODY(iseq)->param.flags.has_lead) { + args_setup_lead_parameters(args, ISEQ_BODY(iseq)->param.lead_num, locals + 0); } - if (iseq->body->param.flags.has_rest || iseq->body->param.flags.has_post){ + if (ISEQ_BODY(iseq)->param.flags.has_rest || ISEQ_BODY(iseq)->param.flags.has_post){ args_copy(args); } - if (iseq->body->param.flags.has_post) { - args_setup_post_parameters(args, iseq->body->param.post_num, locals + iseq->body->param.post_start); + if (ISEQ_BODY(iseq)->param.flags.has_post) { + args_setup_post_parameters(args, ISEQ_BODY(iseq)->param.post_num, locals + ISEQ_BODY(iseq)->param.post_start); } - if (iseq->body->param.flags.has_opt) { - int opt = args_setup_opt_parameters(args, iseq->body->param.opt_num, locals + iseq->body->param.lead_num); - opt_pc = (int)iseq->body->param.opt_table[opt]; + if (ISEQ_BODY(iseq)->param.flags.has_opt) { + int opt = args_setup_opt_parameters(args, ISEQ_BODY(iseq)->param.opt_num, locals + ISEQ_BODY(iseq)->param.lead_num); + opt_pc = (int)ISEQ_BODY(iseq)->param.opt_table[opt]; } - if (iseq->body->param.flags.has_rest) { - args_setup_rest_parameter(args, locals + iseq->body->param.rest_start); + if (ISEQ_BODY(iseq)->param.flags.has_rest) { + args_setup_rest_parameter(args, locals + ISEQ_BODY(iseq)->param.rest_start); } - if (iseq->body->param.flags.has_kw) { - VALUE * const klocals = locals + iseq->body->param.keyword->bits_start - iseq->body->param.keyword->num; + if (ISEQ_BODY(iseq)->param.flags.has_kw) { + VALUE * const klocals = locals + ISEQ_BODY(iseq)->param.keyword->bits_start - ISEQ_BODY(iseq)->param.keyword->num; if (args->kw_argv != NULL) { const struct rb_callinfo_kwarg *kw_arg = args->kw_arg; @@ -681,26 +681,26 @@ setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * co args_setup_kw_parameters(ec, iseq, NULL, 0, NULL, klocals); } } - else if (iseq->body->param.flags.has_kwrest) { - args_setup_kw_rest_parameter(keyword_hash, locals + iseq->body->param.keyword->rest_start, kw_flag); + else if (ISEQ_BODY(iseq)->param.flags.has_kwrest) { + args_setup_kw_rest_parameter(keyword_hash, locals + ISEQ_BODY(iseq)->param.keyword->rest_start, kw_flag); } else if (!NIL_P(keyword_hash) && RHASH_SIZE(keyword_hash) > 0 && arg_setup_type == arg_setup_method) { argument_kw_error(ec, iseq, "unknown", rb_hash_keys(keyword_hash)); } - if (iseq->body->param.flags.has_block) { - if (iseq->body->local_iseq == iseq) { + if (ISEQ_BODY(iseq)->param.flags.has_block) { + if (ISEQ_BODY(iseq)->local_iseq == iseq) { /* Do nothing */ } else { - args_setup_block_parameter(ec, calling, locals + iseq->body->param.block_start); + args_setup_block_parameter(ec, calling, locals + ISEQ_BODY(iseq)->param.block_start); } } #if 0 { int i; - for (i=0; i<iseq->body->param.size; i++) { + for (i=0; i<ISEQ_BODY(iseq)->param.size; i++) { ruby_debug_printf("local[%d] = %p\n", i, (void *)locals[i]); } } @@ -718,7 +718,7 @@ raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const VA if (iseq) { vm_push_frame(ec, iseq, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL, Qnil /* self */, VM_BLOCK_HANDLER_NONE /* specval*/, Qfalse /* me or cref */, - iseq->body->iseq_encoded, + ISEQ_BODY(iseq)->iseq_encoded, ec->cfp->sp, 0, 0 /* stack_max */); at = rb_ec_backtrace_object(ec); rb_backtrace_use_iseq_first_lineno_for_last_location(at); @@ -737,8 +737,8 @@ static void argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const int miss_argc, const int min_argc, const int max_argc) { VALUE exc = rb_arity_error_new(miss_argc, min_argc, max_argc); - if (iseq->body->param.flags.has_kw) { - const struct rb_iseq_param_keyword *const kw = iseq->body->param.keyword; + if (ISEQ_BODY(iseq)->param.flags.has_kw) { + const struct rb_iseq_param_keyword *const kw = ISEQ_BODY(iseq)->param.keyword; const ID *keywords = kw->table; int req_key_num = kw->required_num; if (req_key_num > 0) { |