23#define PUSH_ADJUST(seq, location, label) \
24 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), (int) (location).line))
26#define PUSH_ADJUST_RESTORE(seq, label) \
27 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), -1))
29#define PUSH_INSN(seq, location, insn) \
30 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 0))
32#define PUSH_INSN1(seq, location, insn, op1) \
33 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 1, (VALUE)(op1)))
35#define PUSH_INSN2(seq, location, insn, op1, op2) \
36 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 2, (VALUE)(op1), (VALUE)(op2)))
38#define PUSH_INSN3(seq, location, insn, op1, op2, op3) \
39 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 3, (VALUE)(op1), (VALUE)(op2), (VALUE)(op3)))
41#define PUSH_INSNL(seq, location, insn, label) \
42 (PUSH_INSN1(seq, location, insn, label), LABEL_REF(label))
44#define PUSH_LABEL(seq, label) \
45 ADD_ELEM((seq), (LINK_ELEMENT *) (label))
47#define PUSH_SEND_R(seq, location, id, argc, block, flag, keywords) \
48 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_send(iseq, (int) (location).line, (int) (location).node_id, (id), (VALUE)(argc), (block), (VALUE)(flag), (keywords)))
50#define PUSH_SEND(seq, location, id, argc) \
51 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(0), NULL)
53#define PUSH_SEND_WITH_FLAG(seq, location, id, argc, flag) \
54 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)(flag), NULL)
56#define PUSH_SEND_WITH_BLOCK(seq, location, id, argc, block) \
57 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(0), NULL)
59#define PUSH_CALL(seq, location, id, argc) \
60 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
62#define PUSH_CALL_WITH_BLOCK(seq, location, id, argc, block) \
63 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
65#define PUSH_TRACE(seq, event) \
66 ADD_ELEM((seq), (LINK_ELEMENT *) new_trace_body(iseq, (event), 0))
68#define PUSH_CATCH_ENTRY(type, ls, le, iseqv, lc) \
69 ADD_CATCH_ENTRY((type), (ls), (le), (iseqv), (lc))
71#define PUSH_SEQ(seq1, seq2) \
72 APPEND_LIST((seq1), (seq2))
74#define PUSH_SYNTHETIC_PUTNIL(seq, iseq) \
76 int lineno = ISEQ_COMPILE_DATA(iseq)->last_line; \
77 if (lineno == 0) lineno = FIX2INT(rb_iseq_first_lineno(iseq)); \
78 ADD_SYNTHETIC_INSN(seq, lineno, -1, putnil); \
87pm_iseq_add_getlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
89 if (iseq_local_block_param_p(iseq, idx, level)) {
90 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
93 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
95 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qfalse);
99pm_iseq_add_setlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
101 if (iseq_local_block_param_p(iseq, idx, level)) {
102 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
105 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
107 update_lvar_state(iseq, level, idx);
108 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qtrue);
111#define PUSH_GETLOCAL(seq, location, idx, level) \
112 pm_iseq_add_getlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
114#define PUSH_SETLOCAL(seq, location, idx, level) \
115 pm_iseq_add_setlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
121#define OLD_ISEQ NEW_ISEQ
124#define NEW_ISEQ(node, name, type, line_no) \
125 pm_new_child_iseq(iseq, (node), rb_fstring(name), 0, (type), (line_no))
127#define OLD_CHILD_ISEQ NEW_CHILD_ISEQ
130#define NEW_CHILD_ISEQ(node, name, type, line_no) \
131 pm_new_child_iseq(iseq, (node), rb_fstring(name), iseq, (type), (line_no))
133#define PM_COMPILE(node) \
134 pm_compile_node(iseq, (node), ret, popped, scope_node)
136#define PM_COMPILE_INTO_ANCHOR(_ret, node) \
137 pm_compile_node(iseq, (node), _ret, popped, scope_node)
139#define PM_COMPILE_POPPED(node) \
140 pm_compile_node(iseq, (node), ret, true, scope_node)
142#define PM_COMPILE_NOT_POPPED(node) \
143 pm_compile_node(iseq, (node), ret, false, scope_node)
146#define PM_INDEX_LOOKUP_TABLE_INIT { .values = NULL, .capacity = 0, .owned = false }
151 int capacity = constants_size + PM_INDEX_LOOKUP_SPECIALS;
152 table->
values = compile_data_alloc2_type(iseq,
int, capacity);
153 memset(table->
values, -1, capacity *
sizeof(
int));
155 table->
owned =
false;
165pm_line_offset_list_line_column_cached(
const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line,
size_t *last_line)
167 size_t hint = *last_line;
168 size_t size = list->
size;
169 const uint32_t *offsets = list->
offsets;
174 if (offsets[hint] <= cursor) {
175 if (hint + 1 >= size || offsets[hint + 1] > cursor) {
178 .line = ((int32_t) hint) + start_line,
179 .column = cursor - offsets[hint]
184 size_t limit = hint + 9;
185 if (limit > size) limit = size;
186 for (
size_t idx = hint + 1; idx < limit; idx++) {
187 if (offsets[idx] > cursor) {
188 *last_line = idx - 1;
190 .line = ((int32_t) (idx - 1)) + start_line,
191 .column = cursor - offsets[idx - 1]
194 if (offsets[idx] == cursor) {
202 size_t limit = hint > 8 ? hint - 8 : 0;
203 for (
size_t idx = hint; idx > limit; idx--) {
204 if (offsets[idx - 1] <= cursor) {
205 *last_line = idx - 1;
207 .line = ((int32_t) (idx - 1)) + start_line,
208 .column = cursor - offsets[idx - 1]
215 pm_line_column_t result = pm_line_offset_list_line_column(list, cursor, start_line);
216 *last_line = (size_t) (result.
line - start_line);
225pm_line_offset_list_line_cached(
const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line,
size_t *last_line)
227 return pm_line_offset_list_line_column_cached(list, cursor, start_line, last_line).
line;
230#define PM_NODE_START_LOCATION(node) \
231 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start, scope_node->start_line, &scope_node->last_line), .node_id = ((const pm_node_t *) (node))->node_id })
233#define PM_NODE_END_LOCATION(node) \
234 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start + ((const pm_node_t *) (node))->location.length, scope_node->start_line, &scope_node->last_line), .node_id = ((const pm_node_t *) (node))->node_id })
236#define PM_LOCATION_START_LOCATION(location, id) \
237 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, (location)->start, scope_node->start_line, &scope_node->last_line), .node_id = id })
239#define PM_NODE_START_LINE_COLUMN(node) \
240 pm_line_offset_list_line_column_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start, scope_node->start_line, &scope_node->last_line)
242#define PM_NODE_END_LINE_COLUMN(node) \
243 pm_line_offset_list_line_column_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start + ((const pm_node_t *) (node))->location.length, scope_node->start_line, &scope_node->last_line)
245#define PM_LOCATION_START_LINE_COLUMN(location) \
246 pm_line_offset_list_line_column_cached(scope_node->line_offsets, (location)->start, scope_node->start_line, &scope_node->last_line)
250 return (
int) pm_line_offset_list_line_column(pm_parser_line_offsets(parser), location->
start, pm_parser_start_line(parser)).
line;
260 return (
int) pm_line_offset_list_line_cached(scope_node->line_offsets, node->
location.
start, scope_node->start_line, &scope_node->
last_line);
265 return (
int) pm_line_offset_list_line_cached(scope_node->line_offsets, location->
start, scope_node->start_line, &scope_node->
last_line);
276 if (integer->
values == NULL) {
284 result = rb_integer_unpack(
294 result = rb_int_uminus(result);
298 RB_OBJ_SET_SHAREABLE(result);
310 return parse_integer_value(&node->
value);
321 RB_OBJ_SET_SHAREABLE(val);
350 VALUE imaginary_part;
351 switch (PM_NODE_TYPE(node->
numeric)) {
352 case PM_FLOAT_NODE: {
356 case PM_INTEGER_NODE: {
360 case PM_RATIONAL_NODE: {
365 rb_bug(
"Unexpected numeric type on imaginary number %s\n", pm_node_type(PM_NODE_TYPE(node->
numeric)));
368 return RB_OBJ_SET_SHAREABLE(rb_complex_raw(
INT2FIX(0), imaginary_part));
374 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), scope_node->encoding);
387 if (node->
flags & PM_ENCODING_FLAGS_FORCED_BINARY_ENCODING) {
388 encoding = rb_ascii8bit_encoding();
390 else if (node->
flags & PM_ENCODING_FLAGS_FORCED_UTF8_ENCODING) {
391 encoding = rb_utf8_encoding();
397 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
405 if (node->
flags & PM_STRING_FLAGS_FORCED_BINARY_ENCODING) {
406 encoding = rb_ascii8bit_encoding();
408 else if (node->
flags & PM_STRING_FLAGS_FORCED_UTF8_ENCODING) {
409 encoding = rb_utf8_encoding();
412 encoding = scope_node->encoding;
415 VALUE value = rb_enc_literal_str((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
416 rb_enc_str_coderange(value);
418 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
419 int line_number = pm_node_line_number_cached(node, scope_node);
430 if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_UTF8_ENCODING) {
431 encoding = rb_utf8_encoding();
433 else if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_BINARY_ENCODING) {
434 encoding = rb_ascii8bit_encoding();
436 else if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_US_ASCII_ENCODING) {
437 encoding = rb_usascii_encoding();
440 encoding = scope_node->encoding;
443 return rb_intern3((
const char *) pm_string_source(&symbol->
unescaped), pm_string_length(&symbol->
unescaped), encoding);
447pm_optimizable_range_item_p(
const pm_node_t *node)
449 return (!node || PM_NODE_TYPE_P(node, PM_INTEGER_NODE) || PM_NODE_TYPE_P(node, PM_NIL_NODE));
454parse_regexp_error(
rb_iseq_t *iseq, int32_t line_number,
const char *fmt, ...)
458 VALUE error = rb_syntax_error_append(
Qnil, rb_iseq_path(iseq), line_number, -1, NULL,
"%" PRIsVALUE, args);
470 if (explicit_regexp_encoding != NULL) {
471 encoding = explicit_regexp_encoding;
473 else if (node->
flags & PM_STRING_FLAGS_FORCED_BINARY_ENCODING) {
474 encoding = rb_ascii8bit_encoding();
476 else if (node->
flags & PM_STRING_FLAGS_FORCED_UTF8_ENCODING) {
477 encoding = rb_utf8_encoding();
480 encoding = implicit_regexp_encoding;
483 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), encoding);
484 VALUE error = rb_reg_check_preprocess(
string);
486 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number_cached(node, scope_node),
"%" PRIsVALUE,
rb_obj_as_string(error));
495 for (
size_t index = 0; index < nodes->
size; index++) {
499 switch (PM_NODE_TYPE(part)) {
501 if (implicit_regexp_encoding != NULL) {
503 string = parse_regexp_string_part(iseq, scope_node, part, &((
const pm_string_node_t *) part)->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
506 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
507 VALUE error = rb_reg_check_preprocess(
string);
508 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number_cached(part, scope_node),
"%" PRIsVALUE,
rb_obj_as_string(error));
512 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
515 case PM_INTERPOLATED_STRING_NODE:
516 string = pm_static_literal_concat(iseq, &((
const pm_interpolated_string_node_t *) part)->parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
518 case PM_EMBEDDED_STATEMENTS_NODE: {
520 string = pm_static_literal_concat(iseq, &cast->
statements->
body, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
524 RUBY_ASSERT(
false &&
"unexpected node type in pm_static_literal_concat");
528 if (current !=
Qnil) {
536 return top ? rb_fstring(current) : current;
539#define RE_OPTION_ENCODING_SHIFT 8
540#define RE_OPTION_ENCODING(encoding) (((encoding) & 0xFF) << RE_OPTION_ENCODING_SHIFT)
541#define ARG_ENCODING_NONE 32
542#define ARG_ENCODING_FIXED 16
543#define ENC_ASCII8BIT 1
545#define ENC_Windows_31J 3
560 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) {
561 flags |= ARG_ENCODING_NONE;
564 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EUC_JP)) {
565 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_EUC_JP));
568 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J)) {
569 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_Windows_31J));
572 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_UTF_8)) {
573 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_UTF8));
576 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE)) {
577 flags |= ONIG_OPTION_IGNORECASE;
580 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE)) {
581 flags |= ONIG_OPTION_MULTILINE;
584 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EXTENDED)) {
585 flags |= ONIG_OPTION_EXTEND;
591#undef RE_OPTION_ENCODING_SHIFT
592#undef RE_OPTION_ENCODING
593#undef ARG_ENCODING_FIXED
594#undef ARG_ENCODING_NONE
597#undef ENC_Windows_31J
603 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_FORCED_BINARY_ENCODING) || PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) {
604 return rb_ascii8bit_encoding();
606 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_UTF_8)) {
607 return rb_utf8_encoding();
609 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EUC_JP)) {
610 return rb_enc_get_from_index(ENCINDEX_EUC_JP);
612 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J)) {
613 return rb_enc_get_from_index(ENCINDEX_Windows_31J);
623 VALUE errinfo = rb_errinfo();
625 int32_t line_number = pm_node_line_number_cached(node, scope_node);
626 VALUE regexp = rb_reg_compile(
string, parse_regexp_flags(node), (
const char *) pm_string_source(pm_parser_filepath(scope_node->parser)), line_number);
629 VALUE message = rb_attr_get(rb_errinfo(), idMesg);
630 rb_set_errinfo(errinfo);
632 parse_regexp_error(iseq, line_number,
"%" PRIsVALUE, message);
642 rb_encoding *regexp_encoding = parse_regexp_encoding(scope_node, node);
643 if (regexp_encoding == NULL) regexp_encoding = scope_node->encoding;
645 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), regexp_encoding);
646 RB_OBJ_SET_SHAREABLE(
string);
647 return parse_regexp(iseq, scope_node, node,
string);
653 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
654 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
656 VALUE string = pm_static_literal_concat(iseq, parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
657 return parse_regexp(iseq, scope_node, node,
string);
666 size_t parts_size = parts->
size;
667 bool interpolated =
false;
669 if (parts_size > 0) {
673 for (
size_t index = 0; index < parts_size; index++) {
676 if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
680 if (implicit_regexp_encoding == NULL) {
681 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
684 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
687 if (
RTEST(current_string)) {
688 current_string =
rb_str_concat(current_string, string_value);
691 current_string = string_value;
692 if (index != 0) current_location = PM_NODE_END_LOCATION(part);
699 PM_NODE_TYPE_P(part, PM_EMBEDDED_STATEMENTS_NODE) &&
707 if (implicit_regexp_encoding == NULL) {
708 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
711 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
714 if (
RTEST(current_string)) {
715 current_string =
rb_str_concat(current_string, string_value);
718 current_string = string_value;
719 current_location = PM_NODE_START_LOCATION(part);
723 if (!
RTEST(current_string)) {
726 if (implicit_regexp_encoding != NULL) {
727 if (explicit_regexp_encoding != NULL) {
728 encoding = explicit_regexp_encoding;
730 else if (pm_parser_encoding_us_ascii(scope_node->parser)) {
731 encoding = rb_ascii8bit_encoding();
734 encoding = implicit_regexp_encoding;
738 encoding = scope_node->encoding;
741 if (parts_size == 1) {
742 current_string = rb_enc_str_new(NULL, 0, encoding);
746 if (
RTEST(current_string)) {
747 VALUE operand = rb_fstring(current_string);
748 PUSH_INSN1(ret, current_location, putobject, operand);
752 PM_COMPILE_NOT_POPPED(part);
755 PUSH_INSN(ret, current_location, dup);
758 const struct rb_callinfo *callinfo = new_callinfo(iseq, idTo_s, 0, VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE, NULL, FALSE);
759 PUSH_INSN1(ret, current_location, objtostring, callinfo);
762 PUSH_INSN(ret, current_location, anytostring);
764 current_string =
Qnil;
770 if (
RTEST(current_string)) {
771 current_string = rb_fstring(current_string);
773 if (stack_size == 0) {
775 PUSH_INSN1(ret, current_location, putobject, current_string);
776 }
else if (mutable_result || interpolated) {
777 PUSH_INSN1(ret, current_location, dupstring, current_string);
779 PUSH_INSN1(ret, current_location, dupchilledstring, current_string);
782 PUSH_INSN1(ret, current_location, putobject, current_string);
785 current_string =
Qnil;
790 PUSH_INSN(ret, *node_location, putnil);
799 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
800 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
802 int length = pm_interpolated_node_compile(iseq, parts, node_location, ret, popped, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false,
false);
803 PUSH_INSN2(ret, *node_location, toregexp,
INT2FIX(parse_regexp_flags(node) & 0xFF),
INT2FIX(length));
810 size_t length = pm_string_length(filepath);
814 return rb_enc_interned_str((
const char *) pm_string_source(filepath), length, filepath_encoding);
817 return rb_fstring_lit(
"<compiled>");
826pm_static_literal_string(
rb_iseq_t *iseq,
VALUE string,
int line_number)
828 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
829 VALUE str = rb_str_with_debug_created_info(
string, rb_iseq_path(iseq), line_number);
830 RB_OBJ_SET_SHAREABLE(str);
834 return rb_fstring(
string);
848 RUBY_ASSERT(PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL));
850 switch (PM_NODE_TYPE(node)) {
851 case PM_ARRAY_NODE: {
856 for (
size_t index = 0; index < elements->
size; index++) {
857 rb_ary_push(value, pm_static_literal_value(iseq, elements->
nodes[index], scope_node));
860 RB_OBJ_SET_FROZEN_SHAREABLE(value);
872 for (
size_t index = 0; index < elements->
size; index++) {
875 VALUE pair[2] = { pm_static_literal_value(iseq, cast->key, scope_node), pm_static_literal_value(iseq, cast->value, scope_node) };
883 RB_OBJ_SET_FROZEN_SHAREABLE(value);
886 case PM_IMAGINARY_NODE:
888 case PM_INTEGER_NODE:
890 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
892 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
894 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
896 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
898 case PM_INTERPOLATED_STRING_NODE: {
900 int line_number = pm_node_line_number_cached(node, scope_node);
901 return pm_static_literal_string(iseq,
string, line_number);
903 case PM_INTERPOLATED_SYMBOL_NODE: {
905 VALUE string = pm_static_literal_concat(iseq, &cast->
parts, scope_node, NULL, NULL,
true);
907 return ID2SYM(rb_intern_str(
string));
909 case PM_MATCH_LAST_LINE_NODE: {
911 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
915 case PM_RATIONAL_NODE:
917 case PM_REGULAR_EXPRESSION_NODE: {
919 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
921 case PM_SOURCE_ENCODING_NODE:
922 return rb_enc_from_encoding(scope_node->encoding);
923 case PM_SOURCE_FILE_NODE: {
925 return pm_source_file_value(cast, scope_node);
927 case PM_SOURCE_LINE_NODE:
928 return INT2FIX(pm_node_line_number_cached(node, scope_node));
929 case PM_STRING_NODE: {
931 return parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
938 rb_bug(
"Don't have a literal value for node type %s", pm_node_type(PM_NODE_TYPE(node)));
953 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
954 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
963#define PM_BRANCH_COVERAGE_P(iseq) (ISEQ_COVERAGE(iseq) && ISEQ_BRANCH_COVERAGE(iseq))
977 if (!then_label) then_label = label;
978 else if (!else_label) else_label = label;
980 pm_compile_branch_condition(iseq, seq, cond, then_label, else_label, scope_node);
982 if (LIST_INSN_SIZE_ONE(seq)) {
983 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(seq));
984 if (insn->insn_id == BIN(jump) && (
LABEL *)(insn->operands[0]) == label)
return;
988 PUSH_LABEL(seq, label);
1000 if (PM_NODE_TYPE_P(node, PM_INTEGER_NODE)) {
1001 PM_COMPILE_NOT_POPPED(node);
1004 PUSH_INSN1(ret, location, getglobal, operand);
1006 PUSH_SEND(ret, location, idEq,
INT2FIX(1));
1007 if (popped) PUSH_INSN(ret, location, pop);
1020 int again = !(flip_flop_node->
base.
flags & PM_RANGE_FLAGS_EXCLUDE_END);
1022 rb_num_t count = ISEQ_FLIP_CNT_INCREMENT(ISEQ_BODY(iseq)->local_iseq) + VM_SVAR_FLIPFLOP_START;
1025 PUSH_INSN2(ret, location, getspecial, key,
INT2FIX(0));
1026 PUSH_INSNL(ret, location, branchif, lend);
1028 if (flip_flop_node->
left) {
1029 pm_compile_flip_flop_bound(iseq, flip_flop_node->
left, ret, popped, scope_node);
1032 PUSH_INSN(ret, location, putnil);
1035 PUSH_INSNL(ret, location, branchunless, else_label);
1036 PUSH_INSN1(ret, location, putobject,
Qtrue);
1037 PUSH_INSN1(ret, location, setspecial, key);
1039 PUSH_INSNL(ret, location, jump, then_label);
1042 PUSH_LABEL(ret, lend);
1043 if (flip_flop_node->
right) {
1044 pm_compile_flip_flop_bound(iseq, flip_flop_node->
right, ret, popped, scope_node);
1047 PUSH_INSN(ret, location, putnil);
1050 PUSH_INSNL(ret, location, branchunless, then_label);
1051 PUSH_INSN1(ret, location, putobject,
Qfalse);
1052 PUSH_INSN1(ret, location, setspecial, key);
1053 PUSH_INSNL(ret, location, jump, then_label);
1064 switch (PM_NODE_TYPE(cond)) {
1067 pm_compile_logical(iseq, ret, cast->
left, NULL, else_label, scope_node);
1074 pm_compile_logical(iseq, ret, cast->
left, then_label, NULL, scope_node);
1081 PUSH_INSNL(ret, location, jump, else_label);
1084 case PM_IMAGINARY_NODE:
1085 case PM_INTEGER_NODE:
1086 case PM_LAMBDA_NODE:
1087 case PM_RATIONAL_NODE:
1088 case PM_REGULAR_EXPRESSION_NODE:
1089 case PM_STRING_NODE:
1090 case PM_SYMBOL_NODE:
1092 PUSH_INSNL(ret, location, jump, then_label);
1094 case PM_FLIP_FLOP_NODE:
1095 pm_compile_flip_flop((
const pm_flip_flop_node_t *) cond, else_label, then_label, iseq, location.
line, ret,
false, scope_node);
1097 case PM_DEFINED_NODE: {
1099 pm_compile_defined_expr(iseq, cast->
value, &location, ret,
false, scope_node,
true);
1103 DECL_ANCHOR(cond_seq);
1104 pm_compile_node(iseq, cond, cond_seq,
false, scope_node);
1106 if (LIST_INSN_SIZE_ONE(cond_seq)) {
1107 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(cond_seq));
1109 if (insn->insn_id == BIN(putobject)) {
1110 if (
RTEST(insn->operands[0])) {
1111 PUSH_INSNL(ret, location, jump, then_label);
1116 PUSH_INSNL(ret, location, jump, else_label);
1122 PUSH_SEQ(ret, cond_seq);
1127 PUSH_INSNL(ret, location, branchunless, else_label);
1128 PUSH_INSNL(ret, location, jump, then_label);
1138 LABEL *then_label = NEW_LABEL(location.
line);
1139 LABEL *else_label = NEW_LABEL(location.
line);
1140 LABEL *end_label = NULL;
1142 DECL_ANCHOR(cond_seq);
1143 pm_compile_branch_condition(iseq, cond_seq, predicate, then_label, else_label, scope_node);
1144 PUSH_SEQ(ret, cond_seq);
1149 if (then_label->refcnt && else_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1150 conditional_location = pm_code_location(scope_node, node);
1151 branches = decl_branch_base(iseq, (
int) node->
node_id, &conditional_location,
type == PM_IF_NODE ?
"if" :
"unless");
1154 if (then_label->refcnt) {
1155 PUSH_LABEL(ret, then_label);
1157 DECL_ANCHOR(then_seq);
1159 if (statements != NULL) {
1160 pm_compile_node(iseq, (
const pm_node_t *) statements, then_seq, popped, scope_node);
1163 PUSH_SYNTHETIC_PUTNIL(then_seq, iseq);
1166 if (else_label->refcnt) {
1168 if (PM_BRANCH_COVERAGE_P(iseq)) {
1171 if (statements != NULL) {
1172 branch_location = pm_code_location(scope_node, (
const pm_node_t *) statements);
1173 }
else if (
type == PM_IF_NODE) {
1176 .beg_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column },
1177 .end_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column }
1180 branch_location = conditional_location;
1183 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
type == PM_IF_NODE ?
"then" :
"else", branches);
1186 end_label = NEW_LABEL(location.
line);
1187 PUSH_INSNL(then_seq, location, jump, end_label);
1188 if (!popped) PUSH_INSN(then_seq, location, pop);
1191 PUSH_SEQ(ret, then_seq);
1194 if (else_label->refcnt) {
1195 PUSH_LABEL(ret, else_label);
1197 DECL_ANCHOR(else_seq);
1199 if (subsequent != NULL) {
1200 pm_compile_node(iseq, subsequent, else_seq, popped, scope_node);
1203 PUSH_SYNTHETIC_PUTNIL(else_seq, iseq);
1207 if (then_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1210 if (subsequent == NULL) {
1211 branch_location = conditional_location;
1212 }
else if (PM_NODE_TYPE_P(subsequent, PM_ELSE_NODE)) {
1216 branch_location = pm_code_location(scope_node, (
const pm_node_t *) subsequent);
1219 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 1,
type == PM_IF_NODE ?
"else" :
"then", branches);
1222 PUSH_SEQ(ret, else_seq);
1226 PUSH_LABEL(ret, end_label);
1240 LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
1241 LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
1242 LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
1244 LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(location.
line);
1245 LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(location.
line);
1246 LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(location.
line);
1247 LABEL *end_label = NEW_LABEL(location.
line);
1248 LABEL *adjust_label = NEW_LABEL(location.
line);
1250 LABEL *next_catch_label = NEW_LABEL(location.
line);
1251 LABEL *tmp_label = NULL;
1257 push_ensure_entry(iseq, &enl, NULL, NULL);
1260 if (flags & PM_LOOP_FLAGS_BEGIN_MODIFIER) {
1261 tmp_label = NEW_LABEL(location.
line);
1262 PUSH_INSNL(ret, location, jump, tmp_label);
1266 PUSH_INSNL(ret, location, jump, next_label);
1269 PUSH_LABEL(ret, adjust_label);
1270 PUSH_INSN(ret, location, putnil);
1271 PUSH_LABEL(ret, next_catch_label);
1272 PUSH_INSN(ret, location, pop);
1273 PUSH_INSNL(ret, location, jump, next_label);
1274 if (tmp_label) PUSH_LABEL(ret, tmp_label);
1276 PUSH_LABEL(ret, redo_label);
1279 if (PM_BRANCH_COVERAGE_P(iseq)) {
1281 VALUE branches = decl_branch_base(iseq, (
int) node->
node_id, &loop_location,
type == PM_WHILE_NODE ?
"while" :
"until");
1283 rb_code_location_t branch_location = statements != NULL ? pm_code_location(scope_node, (
const pm_node_t *) statements) : loop_location;
1284 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
"body", branches);
1287 if (statements != NULL) PM_COMPILE_POPPED((
const pm_node_t *) statements);
1288 PUSH_LABEL(ret, next_label);
1290 if (
type == PM_WHILE_NODE) {
1291 pm_compile_branch_condition(iseq, ret, predicate, redo_label, end_label, scope_node);
1293 else if (
type == PM_UNTIL_NODE) {
1294 pm_compile_branch_condition(iseq, ret, predicate, end_label, redo_label, scope_node);
1297 PUSH_LABEL(ret, end_label);
1298 PUSH_ADJUST_RESTORE(ret, adjust_label);
1299 PUSH_INSN(ret, location, putnil);
1301 PUSH_LABEL(ret, break_label);
1302 if (popped) PUSH_INSN(ret, location, pop);
1304 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, NULL, break_label);
1305 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label, NULL, next_catch_label);
1306 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, NULL, ISEQ_COMPILE_DATA(iseq)->redo_label);
1308 ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
1309 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
1310 ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
1311 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->prev;
1326 for (level = 0; level < start_depth; level++) {
1327 scope_node = scope_node->previous;
1330 while (!pm_index_lookup_table_lookup(&scope_node->
index_lookup_table, constant_id, &local_index))
1334 if (scope_node->previous) {
1335 scope_node = scope_node->previous;
1340 rb_bug(
"Local with constant_id %u does not exist", (
unsigned int) constant_id);
1344 lindex.level = level;
1345 lindex.index = scope_node->local_table_for_iseq_size - (int) local_index;
1358 RUBY_ASSERT(constant_id >= 1 && constant_id <= pm_parser_constants_size(scope_node->parser));
1359 return scope_node->constants[constant_id - 1];
1365 debugs(
"[new_child_iseq]> ---------------------------------------\n");
1366 int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
1367 rb_iseq_t *ret_iseq = pm_iseq_build(node, name,
1368 rb_iseq_path(iseq), rb_iseq_realpath(iseq),
1370 isolated_depth ? isolated_depth + 1 : 0,
1371 type, ISEQ_COMPILE_DATA(iseq)->option);
1372 debugs(
"[new_child_iseq]< ---------------------------------------\n");
1379 switch (PM_NODE_TYPE(node)) {
1380 case PM_CONSTANT_READ_NODE:
1382 case PM_CONSTANT_PATH_NODE:
1385 if (!parent)
return TRUE;
1386 return pm_cpath_const_p(parent);
1396 if (PM_NODE_TYPE_P(node, PM_CONSTANT_PATH_NODE)) {
1402 int flags = VM_DEFINECLASS_FLAG_SCOPED;
1403 if (!pm_cpath_const_p(parent)) {
1404 flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
1410 PUSH_INSN1(ret, *node_location, putobject,
rb_cObject);
1411 return VM_DEFINECLASS_FLAG_SCOPED;
1416 PUSH_INSN1(ret, *node_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
1426pm_compile_call_and_or_write_node(
rb_iseq_t *iseq,
bool and_node,
const pm_node_t *receiver,
const pm_node_t *value,
pm_constant_id_t write_name,
pm_constant_id_t read_name,
bool safe_nav,
const pm_node_location_t *node_location,
LINK_ANCHOR *
const ret,
bool popped,
pm_scope_node_t *scope_node)
1430 LABEL *lcfin = NEW_LABEL(location.
line);
1431 LABEL *lskip = NULL;
1433 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
1434 ID id_read_name = pm_constant_id_lookup(scope_node, read_name);
1436 PM_COMPILE_NOT_POPPED(receiver);
1438 lskip = NEW_LABEL(location.
line);
1439 PUSH_INSN(ret, location, dup);
1440 PUSH_INSNL(ret, location, branchnil, lskip);
1443 PUSH_INSN(ret, location, dup);
1444 PUSH_SEND_WITH_FLAG(ret, location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
1445 if (!popped) PUSH_INSN(ret, location, dup);
1448 PUSH_INSNL(ret, location, branchunless, lcfin);
1451 PUSH_INSNL(ret, location, branchif, lcfin);
1454 if (!popped) PUSH_INSN(ret, location, pop);
1455 PM_COMPILE_NOT_POPPED(value);
1458 PUSH_INSN(ret, location, swap);
1459 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
1462 ID id_write_name = pm_constant_id_lookup(scope_node, write_name);
1463 PUSH_SEND_WITH_FLAG(ret, location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
1464 PUSH_INSNL(ret, location, jump, lfin);
1466 PUSH_LABEL(ret, lcfin);
1467 if (!popped) PUSH_INSN(ret, location, swap);
1469 PUSH_LABEL(ret, lfin);
1471 if (lskip && popped) PUSH_LABEL(ret, lskip);
1472 PUSH_INSN(ret, location, pop);
1473 if (lskip && !popped) PUSH_LABEL(ret, lskip);
1492 const int max_stack_length = 0x100;
1493 const unsigned int min_tmp_hash_length = 0x800;
1495 int stack_length = 0;
1496 bool first_chunk =
true;
1497 bool owned_hash =
false;
1503 bool static_literal =
false;
1505 DECL_ANCHOR(anchor);
1508#define FLUSH_CHUNK \
1509 if (stack_length) { \
1510 if (first_chunk) { \
1511 PUSH_SEQ(ret, anchor); \
1512 PUSH_INSN1(ret, location, newhash, INT2FIX(stack_length)); \
1513 first_chunk = false; \
1516 PUSH_INSN1(ret, location, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); \
1517 PUSH_INSN(ret, location, swap); \
1518 PUSH_SEQ(ret, anchor); \
1520 PUSH_SEND(ret, location, id_core_hash_merge_bang_ptr, INT2FIX(stack_length + 1)); \
1523 PUSH_SEND(ret, location, id_core_hash_merge_ptr, INT2FIX(stack_length + 1)); \
1524 owned_hash = true; \
1527 INIT_ANCHOR(anchor); \
1531 for (
size_t index = 0; index < elements->
size; index++) {
1534 switch (PM_NODE_TYPE(element)) {
1535 case PM_ASSOC_NODE: {
1538 (shareability == 0) &&
1539 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && (
1540 (!static_literal && ((index + min_tmp_hash_length) < elements->
size)) ||
1541 (first_chunk && stack_length == 0)
1546 while (index + count < elements->size && PM_NODE_FLAG_P(elements->
nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++;
1548 bool first_element = first_chunk && stack_length == 0;
1550 if (first_element || count >= min_tmp_hash_length) {
1556 for (
size_t tmp_end = index + count; index < tmp_end; index++) {
1560 pm_static_literal_value(iseq, assoc->key, scope_node),
1561 pm_static_literal_value(iseq, assoc->value, scope_node)
1571 RB_OBJ_SET_FROZEN_SHAREABLE(hash);
1576 if (count == elements->
size) {
1578 PUSH_INSN1(ret, location, duphash, hash);
1584 first_chunk =
false;
1587 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1588 PUSH_INSN(ret, location, swap);
1589 PUSH_INSN1(ret, location, putobject, hash);
1590 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1596 static_literal =
true;
1600 static_literal =
false;
1605 if (shareability == 0) {
1606 pm_compile_node(iseq, element, anchor,
false, scope_node);
1610 pm_compile_shareable_constant_value(iseq, assoc->
key, shareability, path, ret, scope_node,
false);
1611 pm_compile_shareable_constant_value(iseq, assoc->
value, shareability, path, ret, scope_node,
false);
1614 if ((stack_length += 2) >= max_stack_length) FLUSH_CHUNK;
1617 case PM_ASSOC_SPLAT_NODE: {
1621 bool empty_hash = assoc_splat->
value != NULL && (
1622 (PM_NODE_TYPE_P(assoc_splat->
value, PM_HASH_NODE) && ((
const pm_hash_node_t *) assoc_splat->
value)->elements.size == 0) ||
1623 PM_NODE_TYPE_P(assoc_splat->
value, PM_NIL_NODE)
1626 bool first_element = first_chunk && stack_length == 0;
1627 bool last_element = index == elements->
size - 1;
1628 bool only_element = first_element && last_element;
1635 PUSH_INSN(ret, location, putnil);
1641 if (shareability == 0) {
1642 PM_COMPILE_NOT_POPPED(element);
1645 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1653 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1654 if (shareability == 0) {
1655 PM_COMPILE_NOT_POPPED(element);
1658 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1660 PUSH_SEND(ret, location, id_core_hash_coerce,
INT2FIX(1));
1664 if (!first_element) {
1665 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1666 PUSH_INSN(ret, location, swap);
1669 if (shareability == 0) {
1670 PM_COMPILE_NOT_POPPED(element);
1673 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1676 if (!first_element) {
1678 PUSH_SEND(ret, location, id_core_hash_merge_bang_kwd,
INT2FIX(2));
1681 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1687 first_chunk =
false;
1688 static_literal =
false;
1692 RUBY_ASSERT(
"Invalid node type for hash" &&
false);
1701#define SPLATARRAY_FALSE 0
1702#define SPLATARRAY_TRUE 1
1703#define DUP_SINGLE_KW_SPLAT 2
1712 bool has_splat =
false;
1713 bool has_keyword_splat =
false;
1715 if (arguments_node == NULL) {
1716 if (*flags & VM_CALL_FCALL) {
1717 *flags |= VM_CALL_VCALL;
1722 has_keyword_splat = PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT);
1726 int post_splat_counter = 0;
1730 switch (PM_NODE_TYPE(argument)) {
1732 case PM_KEYWORD_HASH_NODE: {
1736 if (has_keyword_splat || has_splat) {
1737 *flags |= VM_CALL_KW_SPLAT;
1738 has_keyword_splat =
true;
1740 if (elements->
size > 1 || !(elements->
size == 1 && PM_NODE_TYPE_P(elements->
nodes[0], PM_ASSOC_SPLAT_NODE))) {
1744 *flags |= VM_CALL_KW_SPLAT_MUT;
1745 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1747 else if (*dup_rest & DUP_SINGLE_KW_SPLAT) {
1748 *flags |= VM_CALL_KW_SPLAT_MUT;
1749 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1750 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1751 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1752 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1755 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1761 if (PM_NODE_FLAG_P(keyword_arg, PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS)) {
1766 VALUE stored_indices = rb_hash_new();
1770 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1775 VALUE keyword = pm_static_literal_value(iseq, assoc->key, scope_node);
1776 VALUE stored_index = rb_hash_aref(stored_indices, keyword);
1781 if (!
NIL_P(stored_index)) {
1789 rb_hash_aset(stored_indices, keyword,
ULONG2NUM(element_index));
1794 if (size > VM_CALL_KW_LEN_MAX) {
1795 COMPILE_ERROR(iseq, node_location->
line,
"too many keyword arguments (%d, maximum is %d)",
1796 (
int) size, (
int) VM_CALL_KW_LEN_MAX);
1800 *flags |= VM_CALL_KWARG;
1802 VALUE *keywords = (*kw_arg)->keywords;
1803 (*kw_arg)->references = 0;
1804 (*kw_arg)->keyword_len = (int) size;
1806 size_t keyword_index = 0;
1807 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1812 keywords[keyword_index++] = pm_static_literal_value(iseq, assoc->key, scope_node);
1816 PM_COMPILE(assoc->value);
1825 *flags |= VM_CALL_KW_SPLAT;
1827 size_t size = elements->
size;
1832 *flags |= VM_CALL_KW_SPLAT_MUT;
1835 for (
size_t element_index = 0; element_index < size; element_index++) {
1837 PM_COMPILE_NOT_POPPED(assoc->key);
1838 PM_COMPILE_NOT_POPPED(assoc->value);
1841 PUSH_INSN1(ret, location, newhash,
INT2FIX(size * 2));
1846 case PM_SPLAT_NODE: {
1847 *flags |= VM_CALL_ARGS_SPLAT;
1851 PM_COMPILE_NOT_POPPED(splat_node->
expression);
1854 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1855 PUSH_GETLOCAL(ret, location, index.index, index.level);
1858 bool first_splat = !has_splat;
1866 if (index + 1 < arguments->
size || has_regular_blockarg) {
1867 PUSH_INSN1(ret, location, splatarray, (*dup_rest & SPLATARRAY_TRUE) ?
Qtrue :
Qfalse);
1868 if (*dup_rest & SPLATARRAY_TRUE) *dup_rest &= ~SPLATARRAY_TRUE;
1876 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1886 PUSH_INSN(ret, location, concattoarray);
1890 post_splat_counter = 0;
1894 case PM_FORWARDING_ARGUMENTS_NODE: {
1895 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
1897 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
1898 *flags |= VM_CALL_FORWARDING;
1900 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
1901 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1913 *flags |= VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_BLOCKARG | VM_CALL_KW_SPLAT;
1920 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1921 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1925 PUSH_INSN(ret, location, concattoarray);
1927 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1931 pm_local_index_t pow_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1932 PUSH_GETLOCAL(ret, location, pow_local.index, pow_local.level);
1935 pm_local_index_t and_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
1936 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(and_local.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(and_local.level));
1941 post_splat_counter++;
1942 PM_COMPILE_NOT_POPPED(argument);
1966 if (index == arguments->
size - 1) {
1968 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1973 switch (PM_NODE_TYPE(next_arg)) {
1975 case PM_KEYWORD_HASH_NODE: {
1976 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1977 PUSH_INSN(ret, location, concatarray);
1980 case PM_SPLAT_NODE: {
1981 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1982 PUSH_INSN(ret, location, concatarray);
1985 case PM_FORWARDING_ARGUMENTS_NODE: {
1986 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
2002 if (has_splat) orig_argc++;
2003 if (has_keyword_splat) orig_argc++;
2012pm_setup_args_dup_rest_p(
const pm_node_t *node)
2014 switch (PM_NODE_TYPE(node)) {
2015 case PM_BACK_REFERENCE_READ_NODE:
2016 case PM_CLASS_VARIABLE_READ_NODE:
2017 case PM_CONSTANT_READ_NODE:
2020 case PM_GLOBAL_VARIABLE_READ_NODE:
2021 case PM_IMAGINARY_NODE:
2022 case PM_INSTANCE_VARIABLE_READ_NODE:
2023 case PM_INTEGER_NODE:
2024 case PM_LAMBDA_NODE:
2025 case PM_LOCAL_VARIABLE_READ_NODE:
2027 case PM_NUMBERED_REFERENCE_READ_NODE:
2028 case PM_RATIONAL_NODE:
2029 case PM_REGULAR_EXPRESSION_NODE:
2031 case PM_STRING_NODE:
2032 case PM_SYMBOL_NODE:
2035 case PM_CONSTANT_PATH_NODE: {
2037 if (cast->
parent != NULL) {
2038 return pm_setup_args_dup_rest_p(cast->
parent);
2042 case PM_IMPLICIT_NODE:
2044 case PM_ARRAY_NODE: {
2046 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2047 if (pm_setup_args_dup_rest_p(cast->
elements.
nodes[index])) {
2064 int dup_rest = SPLATARRAY_TRUE;
2067 size_t arguments_size;
2072 arguments_node != NULL &&
2073 (arguments = &arguments_node->
arguments, arguments_size = arguments->
size) >= 2 &&
2074 PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_SPLAT) &&
2075 !PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_MULTIPLE_SPLATS) &&
2076 PM_NODE_TYPE_P(arguments->
nodes[arguments_size - 1], PM_KEYWORD_HASH_NODE)
2081 dup_rest = SPLATARRAY_FALSE;
2086 for (
size_t index = 0; dup_rest == SPLATARRAY_FALSE && index < elements->
size; index++) {
2089 switch (PM_NODE_TYPE(element)) {
2090 case PM_ASSOC_NODE: {
2092 if (pm_setup_args_dup_rest_p(assoc->
key) || pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2095 case PM_ASSOC_SPLAT_NODE: {
2097 if (assoc->
value != NULL && pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2106 int initial_dup_rest = dup_rest;
2109 if (block && PM_NODE_TYPE_P(block, PM_BLOCK_ARGUMENT_NODE)) {
2113 bool regular_block_arg =
true;
2116 if (block_expr && pm_setup_args_dup_rest_p(block_expr)) {
2117 dup_rest = SPLATARRAY_TRUE | DUP_SINGLE_KW_SPLAT;
2118 initial_dup_rest = dup_rest;
2121 DECL_ANCHOR(block_arg);
2122 pm_compile_node(iseq, block, block_arg,
false, scope_node);
2124 *flags |= VM_CALL_ARGS_BLOCKARG;
2126 if (LIST_INSN_SIZE_ONE(block_arg)) {
2128 if (IS_INSN(elem)) {
2130 if (iobj->insn_id == BIN(getblockparam)) {
2131 iobj->insn_id = BIN(getblockparamproxy);
2138 regular_block_arg =
false;
2142 argc = pm_setup_args_core(arguments_node, block, flags, regular_block_arg, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2143 PUSH_SEQ(ret, block_arg);
2146 argc = pm_setup_args_core(arguments_node, block, flags,
false, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2153 if (*flags & VM_CALL_ARGS_SPLAT && dup_rest != initial_dup_rest) {
2154 *flags |= VM_CALL_ARGS_SPLAT_MUT;
2174 if (!popped) PUSH_INSN(ret, location, putnil);
2176 PM_COMPILE_NOT_POPPED(node->
receiver);
2178 int boff = (node->
block == NULL ? 0 : 1);
2179 int flag = PM_NODE_TYPE_P(node->
receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2181 int argc = pm_setup_args(node->
arguments, (
const pm_node_t *) node->
block, &flag, &keywords, iseq, ret, scope_node, node_location);
2183 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2185 PUSH_INSN(ret, location, splatkw);
2188 PUSH_INSN(ret, location, dup);
2189 PUSH_INSN(ret, location, splatkw);
2190 PUSH_INSN(ret, location, pop);
2194 int dup_argn = argc + 1 + boff;
2195 int keyword_len = 0;
2198 keyword_len = keywords->keyword_len;
2199 dup_argn += keyword_len;
2202 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2203 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2204 PM_COMPILE_NOT_POPPED(node->
value);
2207 PUSH_SEND(ret, location, id_operator,
INT2FIX(1));
2210 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2212 if (flag & VM_CALL_ARGS_SPLAT) {
2213 if (flag & VM_CALL_KW_SPLAT) {
2214 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2216 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2217 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2218 flag |= VM_CALL_ARGS_SPLAT_MUT;
2221 PUSH_INSN(ret, location, swap);
2222 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2223 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2224 PUSH_INSN(ret, location, pop);
2228 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2229 PUSH_INSN(ret, location, swap);
2230 PUSH_INSN(ret, location, pop);
2232 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2233 PUSH_INSN(ret, location, swap);
2234 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2235 PUSH_INSN(ret, location, swap);
2236 flag |= VM_CALL_ARGS_SPLAT_MUT;
2238 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2240 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2241 PUSH_INSN(ret, location, pop);
2242 PUSH_INSN(ret, location, pop);
2246 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2248 else if (flag & VM_CALL_KW_SPLAT) {
2250 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2251 PUSH_INSN(ret, location, swap);
2252 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2253 PUSH_INSN(ret, location, pop);
2255 PUSH_INSN(ret, location, swap);
2256 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2258 else if (keyword_len) {
2259 PUSH_INSN(ret, location, dup);
2260 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 2));
2261 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2262 PUSH_INSN(ret, location, pop);
2263 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2267 PUSH_INSN(ret, location, swap);
2269 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2272 PUSH_INSN(ret, location, pop);
2291 if (!popped) PUSH_INSN(ret, location, putnil);
2292 PM_COMPILE_NOT_POPPED(receiver);
2294 int boff = (block == NULL ? 0 : 1);
2295 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2297 int argc = pm_setup_args(arguments, (
const pm_node_t *) block, &flag, &keywords, iseq, ret, scope_node, node_location);
2299 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2301 PUSH_INSN(ret, location, splatkw);
2304 PUSH_INSN(ret, location, dup);
2305 PUSH_INSN(ret, location, splatkw);
2306 PUSH_INSN(ret, location, pop);
2310 int dup_argn = argc + 1 + boff;
2311 int keyword_len = 0;
2314 keyword_len = keywords->keyword_len;
2315 dup_argn += keyword_len;
2318 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2319 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2321 LABEL *label = NEW_LABEL(location.
line);
2324 PUSH_INSN(ret, location, dup);
2325 if (PM_NODE_TYPE_P(node, PM_INDEX_AND_WRITE_NODE)) {
2326 PUSH_INSNL(ret, location, branchunless, label);
2329 PUSH_INSNL(ret, location, branchif, label);
2332 PUSH_INSN(ret, location, pop);
2333 PM_COMPILE_NOT_POPPED(value);
2336 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2339 if (flag & VM_CALL_ARGS_SPLAT) {
2340 if (flag & VM_CALL_KW_SPLAT) {
2341 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2342 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2343 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2344 flag |= VM_CALL_ARGS_SPLAT_MUT;
2347 PUSH_INSN(ret, location, swap);
2348 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2349 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2350 PUSH_INSN(ret, location, pop);
2354 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2355 PUSH_INSN(ret, location, swap);
2356 PUSH_INSN(ret, location, pop);
2358 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2359 PUSH_INSN(ret, location, swap);
2360 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2361 PUSH_INSN(ret, location, swap);
2362 flag |= VM_CALL_ARGS_SPLAT_MUT;
2364 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2366 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2367 PUSH_INSN(ret, location, pop);
2368 PUSH_INSN(ret, location, pop);
2372 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2374 else if (flag & VM_CALL_KW_SPLAT) {
2376 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2377 PUSH_INSN(ret, location, swap);
2378 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2379 PUSH_INSN(ret, location, pop);
2382 PUSH_INSN(ret, location, swap);
2383 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2385 else if (keyword_len) {
2386 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2387 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 0));
2388 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2392 PUSH_INSN(ret, location, swap);
2394 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2397 PUSH_INSN(ret, location, pop);
2398 PUSH_INSNL(ret, location, jump, lfin);
2399 PUSH_LABEL(ret, label);
2401 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2403 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(dup_argn + 1));
2404 PUSH_LABEL(ret, lfin);
2413#define PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE 0
2414#define PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING 1
2415#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P 2
2416#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE 3
2417#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY 4
2432 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2434 PUSH_INSN(ret, location, dup);
2435 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2437 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2438 PUSH_INSN1(ret, location, putobject, message);
2439 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2440 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2441 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2443 PUSH_INSN1(ret, location, putobject,
Qfalse);
2444 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2446 PUSH_INSN(ret, location, pop);
2447 PUSH_INSN(ret, location, pop);
2448 PUSH_LABEL(ret, match_succeeded_label);
2462 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2464 PUSH_INSN(ret, location, dup);
2465 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2467 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2468 PUSH_INSN1(ret, location, putobject, message);
2469 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2470 PUSH_INSN(ret, location, dup);
2471 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2472 PUSH_INSN1(ret, location, putobject, length);
2473 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(4));
2474 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2476 PUSH_INSN1(ret, location, putobject,
Qfalse);
2477 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2479 PUSH_INSN(ret, location, pop);
2480 PUSH_INSN(ret, location, pop);
2481 PUSH_LABEL(ret, match_succeeded_label);
2495 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2497 PUSH_INSN(ret, location, dup);
2498 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2499 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2501 VALUE operand = rb_fstring_lit(
"%p === %p does not return true");
2502 PUSH_INSN1(ret, location, putobject, operand);
2504 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2505 PUSH_INSN1(ret, location, topn,
INT2FIX(5));
2506 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2507 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2508 PUSH_INSN1(ret, location, putobject,
Qfalse);
2509 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2510 PUSH_INSN(ret, location, pop);
2511 PUSH_INSN(ret, location, pop);
2513 PUSH_LABEL(ret, match_succeeded_label);
2514 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2515 PUSH_INSN(ret, location, pop);
2516 PUSH_INSN(ret, location, pop);
2530 LABEL *matched_label = NEW_LABEL(pm_node_line_number_cached(node, scope_node));
2531 CHECK(pm_compile_pattern(iseq, scope_node, node, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
2532 PUSH_LABEL(ret, matched_label);
2542pm_compile_pattern_deconstruct(
rb_iseq_t *iseq,
pm_scope_node_t *scope_node,
const pm_node_t *node,
LINK_ANCHOR *
const ret,
LABEL *deconstruct_label,
LABEL *match_failed_label,
LABEL *deconstructed_label,
LABEL *type_error_label,
bool in_single_pattern,
bool use_deconstructed_cache,
unsigned int base_index)
2546 if (use_deconstructed_cache) {
2547 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2548 PUSH_INSNL(ret, location, branchnil, deconstruct_label);
2550 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2551 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2553 PUSH_INSN(ret, location, pop);
2554 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE - 1));
2555 PUSH_INSNL(ret, location, jump, deconstructed_label);
2558 PUSH_INSNL(ret, location, jump, deconstruct_label);
2561 PUSH_LABEL(ret, deconstruct_label);
2562 PUSH_INSN(ret, location, dup);
2565 PUSH_INSN1(ret, location, putobject, operand);
2566 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2568 if (use_deconstructed_cache) {
2569 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE + 1));
2572 if (in_single_pattern) {
2573 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct"), base_index + 1));
2576 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2577 PUSH_SEND(ret, location, rb_intern(
"deconstruct"),
INT2FIX(0));
2579 if (use_deconstructed_cache) {
2580 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2583 PUSH_INSN(ret, location, dup);
2585 PUSH_INSNL(ret, location, branchunless, type_error_label);
2586 PUSH_LABEL(ret, deconstructed_label);
2600 PUSH_INSN(ret, location, dup);
2601 PM_COMPILE_NOT_POPPED(node);
2603 if (in_single_pattern) {
2604 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
2606 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
2607 if (in_single_pattern) {
2608 CHECK(pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 3));
2610 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2622 LABEL *key_error_label = NEW_LABEL(location.
line);
2623 LABEL *cleanup_label = NEW_LABEL(location.
line);
2626 kw_arg->references = 0;
2627 kw_arg->keyword_len = 2;
2628 kw_arg->keywords[0] =
ID2SYM(rb_intern(
"matchee"));
2629 kw_arg->keywords[1] =
ID2SYM(rb_intern(
"key"));
2631 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2632 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2633 PUSH_INSNL(ret, location, branchif, key_error_label);
2636 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2639 VALUE operand = rb_fstring_lit(
"%p: %s");
2640 PUSH_INSN1(ret, location, putobject, operand);
2643 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2644 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2645 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2646 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2647 PUSH_INSNL(ret, location, jump, cleanup_label);
2649 PUSH_LABEL(ret, key_error_label);
2651 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2654 VALUE operand = rb_fstring_lit(
"%p: %s");
2655 PUSH_INSN1(ret, location, putobject, operand);
2658 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2659 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2660 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2661 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2662 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2663 PUSH_SEND_R(ret, location, rb_intern(
"new"),
INT2FIX(1), NULL,
INT2FIX(VM_CALL_KWARG), kw_arg);
2664 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(1));
2665 PUSH_LABEL(ret, cleanup_label);
2667 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(7));
2668 if (!popped) PUSH_INSN(ret, location, putnil);
2669 PUSH_INSNL(ret, location, jump, done_label);
2670 PUSH_INSN1(ret, location, dupn,
INT2FIX(5));
2671 if (popped) PUSH_INSN(ret, location, putnil);
2682 switch (PM_NODE_TYPE(node)) {
2683 case PM_ARRAY_PATTERN_NODE: {
2695 const size_t posts_size = cast->
posts.
size;
2696 const size_t minimum_size = requireds_size + posts_size;
2698 bool rest_named =
false;
2699 bool use_rest_size =
false;
2701 if (cast->
rest != NULL) {
2702 rest_named = (PM_NODE_TYPE_P(cast->
rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) cast->
rest)->expression != NULL);
2703 use_rest_size = (rest_named || (!rest_named && posts_size > 0));
2706 LABEL *match_failed_label = NEW_LABEL(location.
line);
2707 LABEL *type_error_label = NEW_LABEL(location.
line);
2708 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2709 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2711 if (use_rest_size) {
2712 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2713 PUSH_INSN(ret, location, swap);
2718 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2721 CHECK(pm_compile_pattern_deconstruct(iseq, scope_node, node, ret, deconstruct_label, match_failed_label, deconstructed_label, type_error_label, in_single_pattern, use_deconstructed_cache, base_index));
2723 PUSH_INSN(ret, location, dup);
2724 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2725 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2726 PUSH_SEND(ret, location, cast->
rest == NULL ? idEq : idGE,
INT2FIX(1));
2727 if (in_single_pattern) {
2728 VALUE message = cast->
rest == NULL ? rb_fstring_lit(
"%p length mismatch (given %p, expected %p)") : rb_fstring_lit(
"%p length mismatch (given %p, expected %p+)");
2729 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, message,
INT2FIX(minimum_size), base_index + 1));
2731 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2733 for (
size_t index = 0; index < requireds_size; index++) {
2735 PUSH_INSN(ret, location, dup);
2736 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2737 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2738 CHECK(pm_compile_pattern_match(iseq, scope_node, required, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2741 if (cast->
rest != NULL) {
2743 PUSH_INSN(ret, location, dup);
2744 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size));
2745 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2746 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2747 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2748 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2749 PUSH_INSN1(ret, location, setn,
INT2FIX(4));
2750 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2751 CHECK(pm_compile_pattern_match(iseq, scope_node, ((
const pm_splat_node_t *) cast->
rest)->expression, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2753 else if (posts_size > 0) {
2754 PUSH_INSN(ret, location, dup);
2755 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2756 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2757 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2758 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2759 PUSH_INSN(ret, location, pop);
2763 for (
size_t index = 0; index < posts_size; index++) {
2765 PUSH_INSN(ret, location, dup);
2767 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size + index));
2768 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2769 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2770 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2771 CHECK(pm_compile_pattern_match(iseq, scope_node, post, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2774 PUSH_INSN(ret, location, pop);
2775 if (use_rest_size) {
2776 PUSH_INSN(ret, location, pop);
2779 PUSH_INSNL(ret, location, jump, matched_label);
2780 PUSH_INSN(ret, location, putnil);
2781 if (use_rest_size) {
2782 PUSH_INSN(ret, location, putnil);
2785 PUSH_LABEL(ret, type_error_label);
2786 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2790 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2791 PUSH_INSN1(ret, location, putobject, operand);
2794 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2795 PUSH_INSN(ret, location, pop);
2797 PUSH_LABEL(ret, match_failed_label);
2798 PUSH_INSN(ret, location, pop);
2799 if (use_rest_size) {
2800 PUSH_INSN(ret, location, pop);
2803 PUSH_INSNL(ret, location, jump, unmatched_label);
2806 case PM_FIND_PATTERN_NODE: {
2818 LABEL *match_failed_label = NEW_LABEL(location.
line);
2819 LABEL *type_error_label = NEW_LABEL(location.
line);
2820 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2821 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2824 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2827 CHECK(pm_compile_pattern_deconstruct(iseq, scope_node, node, ret, deconstruct_label, match_failed_label, deconstructed_label, type_error_label, in_single_pattern, use_deconstructed_cache, base_index));
2829 PUSH_INSN(ret, location, dup);
2830 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2831 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2832 PUSH_SEND(ret, location, idGE,
INT2FIX(1));
2833 if (in_single_pattern) {
2834 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p length mismatch (given %p, expected %p+)"),
INT2FIX(size), base_index + 1));
2836 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2839 LABEL *while_begin_label = NEW_LABEL(location.
line);
2840 LABEL *next_loop_label = NEW_LABEL(location.
line);
2841 LABEL *find_succeeded_label = NEW_LABEL(location.
line);
2842 LABEL *find_failed_label = NEW_LABEL(location.
line);
2844 PUSH_INSN(ret, location, dup);
2845 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2847 PUSH_INSN(ret, location, dup);
2848 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2849 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2850 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2851 PUSH_LABEL(ret, while_begin_label);
2853 PUSH_INSN(ret, location, dup);
2854 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2855 PUSH_SEND(ret, location, idLE,
INT2FIX(1));
2856 PUSH_INSNL(ret, location, branchunless, find_failed_label);
2858 for (
size_t index = 0; index < size; index++) {
2859 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2860 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2863 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2864 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2867 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2868 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
requireds.
nodes[index], ret, next_loop_label, in_single_pattern,
false, base_index + 4));
2874 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2875 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2876 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2877 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2878 CHECK(pm_compile_pattern_match(iseq, scope_node, left->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4));
2884 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2885 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2886 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2887 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2888 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2889 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2890 pm_compile_pattern_match(iseq, scope_node, right->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4);
2893 PUSH_INSNL(ret, location, jump, find_succeeded_label);
2895 PUSH_LABEL(ret, next_loop_label);
2896 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
2897 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2898 PUSH_INSNL(ret, location, jump, while_begin_label);
2900 PUSH_LABEL(ret, find_failed_label);
2901 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2902 if (in_single_pattern) {
2903 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2906 VALUE operand = rb_fstring_lit(
"%p does not match to find pattern");
2907 PUSH_INSN1(ret, location, putobject, operand);
2910 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2911 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2912 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2914 PUSH_INSN1(ret, location, putobject,
Qfalse);
2915 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2917 PUSH_INSN(ret, location, pop);
2918 PUSH_INSN(ret, location, pop);
2920 PUSH_INSNL(ret, location, jump, match_failed_label);
2921 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2923 PUSH_LABEL(ret, find_succeeded_label);
2924 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2927 PUSH_INSN(ret, location, pop);
2928 PUSH_INSNL(ret, location, jump, matched_label);
2929 PUSH_INSN(ret, location, putnil);
2931 PUSH_LABEL(ret, type_error_label);
2932 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2936 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2937 PUSH_INSN1(ret, location, putobject, operand);
2940 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2941 PUSH_INSN(ret, location, pop);
2943 PUSH_LABEL(ret, match_failed_label);
2944 PUSH_INSN(ret, location, pop);
2945 PUSH_INSNL(ret, location, jump, unmatched_label);
2949 case PM_HASH_PATTERN_NODE: {
2964 LABEL *match_failed_label = NEW_LABEL(location.
line);
2965 LABEL *type_error_label = NEW_LABEL(location.
line);
2968 if (has_keys && !has_rest) {
2971 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2973 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
2984 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2987 PUSH_INSN(ret, location, dup);
2990 VALUE operand =
ID2SYM(rb_intern(
"deconstruct_keys"));
2991 PUSH_INSN1(ret, location, putobject, operand);
2994 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2995 if (in_single_pattern) {
2996 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct_keys"), base_index + 1));
2998 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3001 PUSH_INSN(ret, location, putnil);
3005 RB_OBJ_SET_FROZEN_SHAREABLE(keys);
3006 PUSH_INSN1(ret, location, duparray, keys);
3009 PUSH_SEND(ret, location, rb_intern(
"deconstruct_keys"),
INT2FIX(1));
3011 PUSH_INSN(ret, location, dup);
3013 PUSH_INSNL(ret, location, branchunless, type_error_label);
3016 PUSH_SEND(ret, location, rb_intern(
"dup"),
INT2FIX(0));
3020 DECL_ANCHOR(match_values);
3022 for (
size_t index = 0; index < cast->
elements.
size; index++) {
3024 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
3031 PUSH_INSN(ret, location, dup);
3032 PUSH_INSN1(ret, location, putobject, symbol);
3033 PUSH_SEND(ret, location, rb_intern(
"key?"),
INT2FIX(1));
3035 if (in_single_pattern) {
3036 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3038 PUSH_INSN(ret, location, dup);
3039 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3043 RB_OBJ_SET_SHAREABLE(operand);
3044 PUSH_INSN1(ret, location, putobject, operand);
3047 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 2));
3048 PUSH_INSN1(ret, location, putobject,
Qtrue);
3049 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 3));
3050 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
3051 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
3052 PUSH_INSN1(ret, location, putobject, symbol);
3053 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
3055 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(4));
3056 PUSH_LABEL(ret, match_succeeded_label);
3059 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3060 PUSH_INSN(match_values, location, dup);
3061 PUSH_INSN1(match_values, location, putobject, symbol);
3062 PUSH_SEND(match_values, location, has_rest ? rb_intern(
"delete") : idAREF,
INT2FIX(1));
3065 if (PM_NODE_TYPE_P(value, PM_IMPLICIT_NODE)) {
3069 CHECK(pm_compile_pattern_match(iseq, scope_node, value, match_values, match_failed_label, in_single_pattern,
false, base_index + 1));
3072 PUSH_SEQ(ret, match_values);
3075 PUSH_INSN(ret, location, dup);
3076 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3077 if (in_single_pattern) {
3078 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p is not empty"), base_index + 1));
3080 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3084 switch (PM_NODE_TYPE(cast->
rest)) {
3085 case PM_NO_KEYWORDS_PARAMETER_NODE: {
3086 PUSH_INSN(ret, location, dup);
3087 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3088 if (in_single_pattern) {
3089 pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"rest of %p is not empty"), base_index + 1);
3091 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3094 case PM_ASSOC_SPLAT_NODE: {
3096 PUSH_INSN(ret, location, dup);
3097 pm_compile_pattern_match(iseq, scope_node, splat->value, ret, match_failed_label, in_single_pattern,
false, base_index + 1);
3101 rb_bug(
"unreachable");
3106 PUSH_INSN(ret, location, pop);
3107 PUSH_INSNL(ret, location, jump, matched_label);
3108 PUSH_INSN(ret, location, putnil);
3110 PUSH_LABEL(ret, type_error_label);
3111 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
3115 VALUE operand = rb_fstring_lit(
"deconstruct_keys must return Hash");
3116 PUSH_INSN1(ret, location, putobject, operand);
3119 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
3120 PUSH_INSN(ret, location, pop);
3122 PUSH_LABEL(ret, match_failed_label);
3123 PUSH_INSN(ret, location, pop);
3124 PUSH_INSNL(ret, location, jump, unmatched_label);
3127 case PM_CAPTURE_PATTERN_NODE: {
3139 LABEL *match_failed_label = NEW_LABEL(location.
line);
3141 PUSH_INSN(ret, location, dup);
3142 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
value, ret, match_failed_label, in_single_pattern, use_deconstructed_cache, base_index + 1));
3143 CHECK(pm_compile_pattern(iseq, scope_node, (
const pm_node_t *) cast->
target, ret, matched_label, match_failed_label, in_single_pattern,
false, base_index));
3144 PUSH_INSN(ret, location, putnil);
3146 PUSH_LABEL(ret, match_failed_label);
3147 PUSH_INSN(ret, location, pop);
3148 PUSH_INSNL(ret, location, jump, unmatched_label);
3152 case PM_LOCAL_VARIABLE_TARGET_NODE: {
3159 PUSH_SETLOCAL(ret, location, index.index, index.level);
3160 PUSH_INSNL(ret, location, jump, matched_label);
3163 case PM_ALTERNATION_PATTERN_NODE: {
3168 LABEL *matched_left_label = NEW_LABEL(location.
line);
3169 LABEL *unmatched_left_label = NEW_LABEL(location.
line);
3173 PUSH_INSN(ret, location, dup);
3174 CHECK(pm_compile_pattern(iseq, scope_node, cast->
left, ret, matched_left_label, unmatched_left_label, in_single_pattern, use_deconstructed_cache, base_index + 1));
3179 PUSH_LABEL(ret, matched_left_label);
3180 PUSH_INSN(ret, location, pop);
3181 PUSH_INSNL(ret, location, jump, matched_label);
3182 PUSH_INSN(ret, location, putnil);
3186 PUSH_LABEL(ret, unmatched_left_label);
3187 CHECK(pm_compile_pattern(iseq, scope_node, cast->
right, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3190 case PM_PARENTHESES_NODE:
3195 return pm_compile_pattern(iseq, scope_node, ((
const pm_parentheses_node_t *) node)->body, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index);
3196 case PM_PINNED_EXPRESSION_NODE:
3204 case PM_CLASS_VARIABLE_READ_NODE:
3205 case PM_CONSTANT_PATH_NODE:
3206 case PM_CONSTANT_READ_NODE:
3209 case PM_GLOBAL_VARIABLE_READ_NODE:
3210 case PM_IMAGINARY_NODE:
3211 case PM_INSTANCE_VARIABLE_READ_NODE:
3212 case PM_IT_LOCAL_VARIABLE_READ_NODE:
3213 case PM_INTEGER_NODE:
3214 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
3215 case PM_INTERPOLATED_STRING_NODE:
3216 case PM_INTERPOLATED_SYMBOL_NODE:
3217 case PM_INTERPOLATED_X_STRING_NODE:
3218 case PM_LAMBDA_NODE:
3219 case PM_LOCAL_VARIABLE_READ_NODE:
3221 case PM_SOURCE_ENCODING_NODE:
3222 case PM_SOURCE_FILE_NODE:
3223 case PM_SOURCE_LINE_NODE:
3225 case PM_RATIONAL_NODE:
3226 case PM_REGULAR_EXPRESSION_NODE:
3228 case PM_STRING_NODE:
3229 case PM_SYMBOL_NODE:
3231 case PM_X_STRING_NODE: {
3235 PM_COMPILE_NOT_POPPED(node);
3236 if (in_single_pattern) {
3237 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
3240 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
3242 if (in_single_pattern) {
3243 pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 2);
3246 PUSH_INSNL(ret, location, branchif, matched_label);
3247 PUSH_INSNL(ret, location, jump, unmatched_label);
3250 case PM_PINNED_VARIABLE_NODE: {
3256 CHECK(pm_compile_pattern(iseq, scope_node, cast->
variable, ret, matched_label, unmatched_label, in_single_pattern,
true, base_index));
3260 case PM_UNLESS_NODE: {
3275 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3290 CHECK(pm_compile_pattern_match(iseq, scope_node, statement, ret, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3291 PM_COMPILE_NOT_POPPED(predicate);
3293 if (in_single_pattern) {
3294 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3296 PUSH_INSN(ret, location, dup);
3297 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3298 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3301 PUSH_INSNL(ret, location, branchunless, match_succeeded_label);
3305 VALUE operand = rb_fstring_lit(
"guard clause does not return true");
3306 PUSH_INSN1(ret, location, putobject, operand);
3309 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
3310 PUSH_INSN1(ret, location, putobject,
Qfalse);
3311 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
3313 PUSH_INSN(ret, location, pop);
3314 PUSH_INSN(ret, location, pop);
3316 PUSH_LABEL(ret, match_succeeded_label);
3319 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3320 PUSH_INSNL(ret, location, branchunless, unmatched_label);
3323 PUSH_INSNL(ret, location, branchif, unmatched_label);
3326 PUSH_INSNL(ret, location, jump, matched_label);
3333 rb_bug(
"Unexpected node type in pattern matching expression: %s", pm_node_type(PM_NODE_TYPE(node)));
3340#undef PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE
3341#undef PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING
3342#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P
3343#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE
3344#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY
3355 scope->parameters = NULL;
3357 scope->local_table_for_iseq_size = 0;
3365 scope->base.
type = PM_SCOPE_NODE;
3368 scope->previous = previous;
3371 switch (PM_NODE_TYPE(node)) {
3372 case PM_BLOCK_NODE: {
3374 scope->body = cast->
body;
3375 scope->locals = cast->
locals;
3379 case PM_CLASS_NODE: {
3381 scope->body = cast->
body;
3382 scope->locals = cast->
locals;
3388 scope->body = cast->body;
3389 scope->locals = cast->locals;
3392 case PM_ENSURE_NODE: {
3408 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
3413 case PM_LAMBDA_NODE: {
3416 scope->body = cast->
body;
3417 scope->locals = cast->
locals;
3420 case PM_MODULE_NODE: {
3422 scope->body = cast->
body;
3423 scope->locals = cast->
locals;
3426 case PM_POST_EXECUTION_NODE: {
3431 case PM_PROGRAM_NODE: {
3434 scope->locals = cast->locals;
3437 case PM_RESCUE_NODE: {
3442 case PM_RESCUE_MODIFIER_NODE: {
3447 case PM_SINGLETON_CLASS_NODE: {
3449 scope->body = cast->
body;
3450 scope->locals = cast->
locals;
3453 case PM_STATEMENTS_NODE: {
3459 rb_bug(
"unreachable");
3488 iobj = IS_INSN(last_elem) ? (
INSN*) last_elem : (
INSN*) get_prev_insn((
INSN*) last_elem);
3489 while (!IS_INSN_ID(iobj, send) && !IS_INSN_ID(iobj, invokesuper) && !IS_INSN_ID(iobj, sendforward) && !IS_INSN_ID(iobj, invokesuperforward)) {
3490 iobj = (
INSN*) get_prev_insn(iobj);
3492 ELEM_INSERT_NEXT(&iobj->link, (
LINK_ELEMENT*) retry_end_l);
3497 if (&iobj->link == LAST_ELEMENT(ret)) {
3505 const char *name = rb_id2name(method_id);
3506 static const char prefix[] =
"__builtin_";
3507 const size_t prefix_len =
sizeof(prefix) - 1;
3509 if (receiver == NULL) {
3510 if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) {
3512 return &name[prefix_len];
3515 else if (PM_NODE_TYPE_P(receiver, PM_CALL_NODE)) {
3516 if (PM_NODE_FLAG_P(receiver, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3524 else if (PM_NODE_TYPE_P(receiver, PM_CONSTANT_READ_NODE)) {
3539 if (arguments == NULL) {
3540 COMPILE_ERROR(iseq, node_location->
line,
"attr!: no argument");
3546 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3547 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to attr!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3551 VALUE symbol = pm_static_literal_value(iseq, argument, scope_node);
3552 if (compile_builtin_attr_symbol(iseq, symbol) != COMPILE_OK) {
3553 COMPILE_ERROR(iseq, node_location->
line,
"unknown argument to attr!: %" PRIsVALUE, symbol);
3564 if (arguments == NULL) {
3565 COMPILE_ERROR(iseq, node_location->
line,
"arg!: no argument");
3570 COMPILE_ERROR(iseq, node_location->
line,
"arg!: too many argument");
3575 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3576 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to arg!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3582 int index = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->local_table_size - get_local_var_idx(iseq, name);
3584 debugs(
"id: %s idx: %d\n", rb_id2name(name), index);
3585 PUSH_GETLOCAL(ret, *node_location, index, get_lvar_level(iseq));
3594 const pm_node_t *ast_node = scope_node->ast_node;
3595 if (!PM_NODE_TYPE_P(ast_node, PM_DEF_NODE)) {
3596 rb_bug(
"mandatory_only?: not in method definition");
3602 if (parameters_node == NULL) {
3603 rb_bug(
"mandatory_only?: in method definition with no parameters");
3608 if (body_node == NULL || !PM_NODE_TYPE_P(body_node, PM_STATEMENTS_NODE) || (((
const pm_statements_node_t *) body_node)->body.size != 1) || !PM_NODE_TYPE_P(((
const pm_statements_node_t *) body_node)->body.nodes[0], PM_IF_NODE)) {
3609 rb_bug(
"mandatory_only?: not in method definition with plain statements");
3615 rb_bug(
"mandatory_only?: can't find mandatory node");
3626 .name = def_node->
name,
3628 .parameters = ¶meters,
3638 pm_scope_node_init(&def.base, &next_scope_node, scope_node);
3640 const rb_iseq_t *mandatory_only_iseq = pm_iseq_build(
3642 rb_iseq_base_label(iseq),
3644 rb_iseq_realpath(iseq),
3645 node_location->
line,
3649 ISEQ_COMPILE_DATA(iseq)->option
3651 RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->mandatory_only_iseq, (
VALUE)mandatory_only_iseq);
3653 pm_scope_node_destroy(&next_scope_node);
3662 if (parent_block != NULL) {
3663 COMPILE_ERROR(iseq, node_location->
line,
"should not call builtins here.");
3667#define BUILTIN_INLINE_PREFIX "_bi"
3668 char inline_func[
sizeof(BUILTIN_INLINE_PREFIX) +
DECIMAL_SIZE_OF(
int)];
3669 bool cconst =
false;
3674 if (strcmp(
"cstmt!", builtin_func) == 0 || strcmp(
"cexpr!", builtin_func) == 0) {
3677 else if (strcmp(
"cconst!", builtin_func) == 0) {
3680 else if (strcmp(
"cinit!", builtin_func) == 0) {
3684 else if (strcmp(
"attr!", builtin_func) == 0) {
3685 return pm_compile_builtin_attr(iseq, scope_node, arguments, node_location);
3687 else if (strcmp(
"arg!", builtin_func) == 0) {
3688 return pm_compile_builtin_arg(iseq, ret, scope_node, arguments, node_location, popped);
3690 else if (strcmp(
"mandatory_only?", builtin_func) == 0) {
3692 rb_bug(
"mandatory_only? should be in if condition");
3694 else if (!LIST_INSN_SIZE_ZERO(ret)) {
3695 rb_bug(
"mandatory_only? should be put on top");
3698 PUSH_INSN1(ret, *node_location, putobject,
Qfalse);
3699 return pm_compile_builtin_mandatory_only_method(iseq, scope_node, call_node, node_location);
3702 rb_bug(
"can't find builtin function:%s", builtin_func);
3705 COMPILE_ERROR(iseq, node_location->
line,
"can't find builtin function:%s", builtin_func);
3709 int inline_index = node_location->
line;
3710 snprintf(inline_func,
sizeof(inline_func), BUILTIN_INLINE_PREFIX
"%d", inline_index);
3711 builtin_func = inline_func;
3717 typedef VALUE(*builtin_func0)(
void *,
VALUE);
3718 VALUE const_val = (*(builtin_func0)(uintptr_t)bf->func_ptr)(NULL,
Qnil);
3719 PUSH_INSN1(ret, *node_location, putobject, const_val);
3725 DECL_ANCHOR(args_seq);
3729 int argc = pm_setup_args(arguments, call_node->
block, &flags, &keywords, iseq, args_seq, scope_node, node_location);
3731 if (argc != bf->argc) {
3732 COMPILE_ERROR(iseq, node_location->
line,
"argc is not match for builtin function:%s (expect %d but %d)", builtin_func, bf->argc, argc);
3736 unsigned int start_index;
3737 if (delegate_call_p(iseq, argc, args_seq, &start_index)) {
3738 PUSH_INSN2(ret, *node_location, opt_invokebuiltin_delegate, bf,
INT2FIX(start_index));
3741 PUSH_SEQ(ret, args_seq);
3742 PUSH_INSN1(ret, *node_location, invokebuiltin, bf);
3745 if (popped) PUSH_INSN(ret, *node_location, pop);
3760 LABEL *else_label = NEW_LABEL(location.
line);
3761 LABEL *end_label = NEW_LABEL(location.
line);
3762 LABEL *retry_end_l = NEW_LABEL(location.
line);
3766 int node_id = location.
node_id;
3768 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3769 if (PM_BRANCH_COVERAGE_P(iseq)) {
3770 uint32_t end_cursor = 0;
3771 bool end_found =
false;
3775 end_cursor = cursor;
3781 if (!end_found || cursor > end_cursor) {
3782 end_cursor = cursor;
3789 if (!end_found || cursor > end_cursor) {
3790 end_cursor = cursor;
3799 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(call_node);
3800 const pm_line_column_t end_location = pm_line_offset_list_line_column_cached(scope_node->line_offsets, end_cursor, scope_node->start_line, &scope_node->
last_line);
3803 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
3804 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
3807 branches = decl_branch_base(iseq, (
int) call_node->
base.
node_id, &code_location,
"&.");
3810 PUSH_INSN(ret, location, dup);
3811 PUSH_INSNL(ret, location, branchnil, else_label);
3813 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0,
"then", branches);
3821 int orig_argc = pm_setup_args(call_node->
arguments, call_node->
block, &flags, &kw_arg, iseq, ret, scope_node, &location);
3822 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
3825 if (call_node->
block != NULL && PM_NODE_TYPE_P(call_node->
block, PM_BLOCK_NODE)) {
3828 pm_scope_node_init(call_node->
block, &next_scope_node, scope_node);
3830 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, pm_node_line_number_cached(call_node->
block, scope_node));
3831 pm_scope_node_destroy(&next_scope_node);
3832 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
3835 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3836 flags |= VM_CALL_VCALL;
3840 flags |= VM_CALL_ARGS_SIMPLE;
3844 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
3845 flags |= VM_CALL_FCALL;
3848 if (!popped && PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE)) {
3849 if (flags & VM_CALL_ARGS_BLOCKARG) {
3850 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
3851 if (flags & VM_CALL_ARGS_SPLAT) {
3852 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3853 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3855 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 3));
3856 PUSH_INSN(ret, location, pop);
3858 else if (flags & VM_CALL_ARGS_SPLAT) {
3859 PUSH_INSN(ret, location, dup);
3860 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3861 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3862 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 2));
3863 PUSH_INSN(ret, location, pop);
3866 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 1));
3870 if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
3871 PUSH_INSN(ret, location, splatkw);
3874 LABEL *not_basic_new = NEW_LABEL(location.
line);
3875 LABEL *not_basic_new_finish = NEW_LABEL(location.
line);
3877 bool inline_new = ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction &&
3878 method_id == rb_intern(
"new") &&
3879 call_node->
block == NULL &&
3880 (flags & VM_CALL_ARGS_BLOCKARG) == 0;
3883 if (LAST_ELEMENT(ret) == opt_new_prelude) {
3884 PUSH_INSN(ret, location, putnil);
3885 PUSH_INSN(ret, location, swap);
3888 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(swap), 0)->link);
3889 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(putnil), 0)->link);
3892 rb_callinfo_kwarg_retain(kw_arg);
3896 if (flags & VM_CALL_FORWARDING) {
3897 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc + 1, flags, kw_arg, 0);
3900 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc, flags, kw_arg, 0);
3903 PUSH_INSN2(ret, location, opt_new, ci, not_basic_new);
3904 LABEL_REF(not_basic_new);
3906 PUSH_SEND_R(ret, location, rb_intern(
"initialize"),
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags | VM_CALL_FCALL), kw_arg);
3907 PUSH_INSNL(ret, location, jump, not_basic_new_finish);
3909 PUSH_LABEL(ret, not_basic_new);
3911 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3912 PUSH_INSN(ret, location, swap);
3914 PUSH_LABEL(ret, not_basic_new_finish);
3915 PUSH_INSN(ret, location, pop);
3917 rb_callinfo_kwarg_release(kw_arg);
3920 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3923 if (block_iseq && ISEQ_BODY(block_iseq)->catch_table) {
3924 pm_compile_retry_end_label(iseq, ret, retry_end_l);
3925 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, start, retry_end_l, block_iseq, retry_end_l);
3928 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3929 PUSH_INSNL(ret, location, jump, end_label);
3930 PUSH_LABEL(ret, else_label);
3931 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 1,
"else", branches);
3932 PUSH_LABEL(ret, end_label);
3935 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
3936 PUSH_INSN(ret, location, pop);
3939 if (popped) PUSH_INSN(ret, location, pop);
3940 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
3950 const char *
type = (
const char *) (pm_parser_start(scope_node->parser) + node->
base.
location.
start + 1);
3970#define PUSH_VAL(type) (in_condition ? Qtrue : rb_iseq_defined_string(type))
3973 enum defined_type dtype = DEFINED_NOT_DEFINED;
3976 switch (PM_NODE_TYPE(node)) {
3981 dtype = DEFINED_NIL;
3984 case PM_INSTANCE_VARIABLE_READ_NODE: {
3988 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3990 PUSH_INSN3(ret, location, definedivar,
ID2SYM(name), get_ivar_ic_value(iseq, name), PUSH_VAL(DEFINED_IVAR));
3995 case PM_LOCAL_VARIABLE_READ_NODE:
3998 case PM_IT_LOCAL_VARIABLE_READ_NODE:
4001 dtype = DEFINED_LVAR;
4004 case PM_GLOBAL_VARIABLE_READ_NODE: {
4008 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4010 PUSH_INSN(ret, location, putnil);
4011 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR),
ID2SYM(name), PUSH_VAL(DEFINED_GVAR));
4016 case PM_CLASS_VARIABLE_READ_NODE: {
4020 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4022 PUSH_INSN(ret, location, putnil);
4023 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR),
ID2SYM(name), PUSH_VAL(DEFINED_CVAR));
4028 case PM_CONSTANT_READ_NODE: {
4032 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4034 PUSH_INSN(ret, location, putnil);
4035 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4043 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
4045 PUSH_INSN(ret, location, putnil);
4046 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
4050 case PM_SUPER_NODE: {
4055 if (cast->
block != NULL && !PM_NODE_TYPE_P(cast->
block, PM_BLOCK_ARGUMENT_NODE)) {
4056 dtype = DEFINED_EXPR;
4060 PUSH_INSN(ret, location, putnil);
4061 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4064 case PM_FORWARDING_SUPER_NODE: {
4069 if (cast->
block != NULL) {
4070 dtype = DEFINED_EXPR;
4074 PUSH_INSN(ret, location, putnil);
4075 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4082 dtype = DEFINED_SELF;
4088 dtype = DEFINED_TRUE;
4094 dtype = DEFINED_FALSE;
4097 case PM_CALL_AND_WRITE_NODE:
4100 case PM_CALL_OPERATOR_WRITE_NODE:
4103 case PM_CALL_OR_WRITE_NODE:
4106 case PM_CLASS_VARIABLE_AND_WRITE_NODE:
4109 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE:
4112 case PM_CLASS_VARIABLE_OR_WRITE_NODE:
4115 case PM_CLASS_VARIABLE_WRITE_NODE:
4118 case PM_CONSTANT_AND_WRITE_NODE:
4121 case PM_CONSTANT_OPERATOR_WRITE_NODE:
4124 case PM_CONSTANT_OR_WRITE_NODE:
4127 case PM_CONSTANT_PATH_AND_WRITE_NODE:
4130 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
4133 case PM_CONSTANT_PATH_OR_WRITE_NODE:
4136 case PM_CONSTANT_PATH_WRITE_NODE:
4139 case PM_CONSTANT_WRITE_NODE:
4142 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE:
4145 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE:
4148 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE:
4151 case PM_GLOBAL_VARIABLE_WRITE_NODE:
4154 case PM_INDEX_AND_WRITE_NODE:
4157 case PM_INDEX_OPERATOR_WRITE_NODE:
4160 case PM_INDEX_OR_WRITE_NODE:
4163 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE:
4166 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE:
4169 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE:
4172 case PM_INSTANCE_VARIABLE_WRITE_NODE:
4175 case PM_LOCAL_VARIABLE_AND_WRITE_NODE:
4178 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE:
4181 case PM_LOCAL_VARIABLE_OR_WRITE_NODE:
4184 case PM_LOCAL_VARIABLE_WRITE_NODE:
4187 case PM_MULTI_WRITE_NODE:
4190 dtype = DEFINED_ASGN;
4193 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
4196 case PM_ALIAS_METHOD_NODE:
4205 case PM_CASE_MATCH_NODE:
4217 case PM_DEFINED_NODE:
4220 case PM_FLIP_FLOP_NODE:
4232 case PM_IMAGINARY_NODE:
4235 case PM_INTEGER_NODE:
4238 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE:
4241 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
4244 case PM_INTERPOLATED_STRING_NODE:
4247 case PM_INTERPOLATED_SYMBOL_NODE:
4250 case PM_INTERPOLATED_X_STRING_NODE:
4253 case PM_LAMBDA_NODE:
4256 case PM_MATCH_LAST_LINE_NODE:
4259 case PM_MATCH_PREDICATE_NODE:
4262 case PM_MATCH_REQUIRED_NODE:
4265 case PM_MATCH_WRITE_NODE:
4268 case PM_MODULE_NODE:
4277 case PM_POST_EXECUTION_NODE:
4283 case PM_RATIONAL_NODE:
4289 case PM_REGULAR_EXPRESSION_NODE:
4292 case PM_RESCUE_MODIFIER_NODE:
4298 case PM_RETURN_NODE:
4301 case PM_SINGLETON_CLASS_NODE:
4304 case PM_SOURCE_ENCODING_NODE:
4307 case PM_SOURCE_FILE_NODE:
4310 case PM_SOURCE_LINE_NODE:
4313 case PM_STRING_NODE:
4316 case PM_SYMBOL_NODE:
4322 case PM_UNLESS_NODE:
4331 case PM_X_STRING_NODE:
4334 dtype = DEFINED_EXPR;
4337 case PM_BACK_REFERENCE_READ_NODE: {
4341 VALUE ref = pm_compile_back_reference_ref(scope_node, cast);
4343 PUSH_INSN(ret, location, putnil);
4344 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4348 case PM_NUMBERED_REFERENCE_READ_NODE: {
4352 VALUE ref = pm_compile_numbered_reference_ref(cast);
4354 PUSH_INSN(ret, location, putnil);
4355 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4360 case PM_CONSTANT_PATH_NODE: {
4364 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4366 if (cast->
parent != NULL) {
4367 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4368 pm_compile_defined_expr0(iseq, cast->
parent, node_location, ret, popped, scope_node,
true, lfinish,
false);
4370 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4371 PM_COMPILE(cast->
parent);
4374 PUSH_INSN1(ret, location, putobject,
rb_cObject);
4377 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4381 case PM_BEGIN_NODE: {
4389 dtype = DEFINED_NIL;
4395 pm_compile_defined_expr0(iseq, cast->
statements->
body.
nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4401 dtype = DEFINED_EXPR;
4406 dtype = DEFINED_EXPR;
4411 case PM_PARENTHESES_NODE: {
4416 if (cast->
body == NULL) {
4418 dtype = DEFINED_NIL;
4420 else if (PM_NODE_TYPE_P(cast->
body, PM_STATEMENTS_NODE) && !PM_NODE_FLAG_P(cast, PM_PARENTHESES_NODE_FLAGS_MULTIPLE_STATEMENTS)) {
4423 pm_compile_defined_expr0(iseq, ((
const pm_statements_node_t *) cast->
body)->body.nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4429 dtype = DEFINED_EXPR;
4434 case PM_ARRAY_NODE: {
4440 lfinish[1] = NEW_LABEL(location.
line);
4443 for (
size_t index = 0; index < cast->
elements.
size; index++) {
4444 pm_compile_defined_expr0(iseq, cast->
elements.
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4445 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4448 dtype = DEFINED_EXPR;
4454 case PM_KEYWORD_HASH_NODE: {
4459 if (PM_NODE_TYPE_P(node, PM_HASH_NODE)) {
4466 if (elements->
size > 0 && !lfinish[1]) {
4467 lfinish[1] = NEW_LABEL(location.
line);
4470 for (
size_t index = 0; index < elements->
size; index++) {
4471 pm_compile_defined_expr0(iseq, elements->
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4472 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4475 dtype = DEFINED_EXPR;
4478 case PM_ASSOC_NODE: {
4483 pm_compile_defined_expr0(iseq, cast->
key, node_location, ret, popped, scope_node,
true, lfinish,
false);
4484 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4485 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4489 case PM_ASSOC_SPLAT_NODE: {
4494 if (cast->
value == NULL) {
4495 dtype = DEFINED_EXPR;
4499 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4502 case PM_IMPLICIT_NODE: {
4506 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4509 case PM_CALL_NODE: {
4510#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE))
4516 if (BLOCK_P(cast)) {
4517 dtype = DEFINED_EXPR;
4522 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4523 if (!lfinish[2]) lfinish[2] = NEW_LABEL(location.
line);
4527 pm_compile_defined_expr0(iseq, (
const pm_node_t *) cast->
arguments, node_location, ret, popped, scope_node,
true, lfinish,
false);
4528 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4531 if (cast->
block && PM_NODE_TYPE_P(cast->
block, PM_BLOCK_ARGUMENT_NODE)) {
4532 pm_compile_defined_expr0(iseq, cast->
block, node_location, ret, popped, scope_node,
true, lfinish,
false);
4533 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4540 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
true);
4541 PUSH_INSNL(ret, location, branchunless, lfinish[2]);
4544 ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
4546 pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
4549 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
false);
4550 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4554 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4556 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4557 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_METHOD),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4560 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4562 PUSH_INSN(ret, location, putself);
4563 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4565 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_FUNC),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4572 case PM_ARGUMENTS_NODE: {
4577 for (
size_t index = 0; index < cast->
arguments.
size; index++) {
4578 pm_compile_defined_expr0(iseq, cast->
arguments.
nodes[index], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4579 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4582 dtype = DEFINED_EXPR;
4585 case PM_BLOCK_ARGUMENT_NODE:
4588 dtype = DEFINED_EXPR;
4590 case PM_FORWARDING_ARGUMENTS_NODE:
4593 dtype = DEFINED_EXPR;
4595 case PM_SPLAT_NODE: {
4601 dtype = DEFINED_EXPR;
4605 pm_compile_defined_expr0(iseq, cast->
expression, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4607 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4608 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4610 dtype = DEFINED_EXPR;
4613 case PM_SHAREABLE_CONSTANT_NODE:
4617 pm_compile_defined_expr0(iseq, ((
const pm_shareable_constant_node_t *) node)->write, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4620 case PM_BLOCK_LOCAL_VARIABLE_NODE:
4621 case PM_BLOCK_PARAMETER_NODE:
4622 case PM_BLOCK_PARAMETERS_NODE:
4623 case PM_FORWARDING_PARAMETER_NODE:
4624 case PM_IMPLICIT_REST_NODE:
4625 case PM_IT_PARAMETERS_NODE:
4626 case PM_PARAMETERS_NODE:
4627 case PM_KEYWORD_REST_PARAMETER_NODE:
4628 case PM_NO_KEYWORDS_PARAMETER_NODE:
4629 case PM_NO_BLOCK_PARAMETER_NODE:
4630 case PM_NUMBERED_PARAMETERS_NODE:
4631 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE:
4632 case PM_OPTIONAL_PARAMETER_NODE:
4633 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
4634 case PM_REQUIRED_PARAMETER_NODE:
4635 case PM_REST_PARAMETER_NODE:
4637 case PM_ALTERNATION_PATTERN_NODE:
4638 case PM_ARRAY_PATTERN_NODE:
4639 case PM_CAPTURE_PATTERN_NODE:
4640 case PM_FIND_PATTERN_NODE:
4641 case PM_HASH_PATTERN_NODE:
4642 case PM_PINNED_EXPRESSION_NODE:
4643 case PM_PINNED_VARIABLE_NODE:
4645 case PM_CALL_TARGET_NODE:
4646 case PM_CLASS_VARIABLE_TARGET_NODE:
4647 case PM_CONSTANT_PATH_TARGET_NODE:
4648 case PM_CONSTANT_TARGET_NODE:
4649 case PM_GLOBAL_VARIABLE_TARGET_NODE:
4650 case PM_INDEX_TARGET_NODE:
4651 case PM_INSTANCE_VARIABLE_TARGET_NODE:
4652 case PM_LOCAL_VARIABLE_TARGET_NODE:
4653 case PM_MULTI_TARGET_NODE:
4656 case PM_ENSURE_NODE:
4658 case PM_RESCUE_NODE:
4662 case PM_EMBEDDED_STATEMENTS_NODE:
4663 case PM_EMBEDDED_VARIABLE_NODE:
4664 case PM_ERROR_RECOVERY_NODE:
4665 case PM_PRE_EXECUTION_NODE:
4666 case PM_PROGRAM_NODE:
4668 case PM_STATEMENTS_NODE:
4669 rb_bug(
"Unreachable node in defined?: %s", pm_node_type(PM_NODE_TYPE(node)));
4673 PUSH_INSN1(ret, location, putobject, PUSH_VAL(dtype));
4682 pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4685 LABEL *lstart = NEW_LABEL(node_location->
line);
4686 LABEL *lend = NEW_LABEL(node_location->
line);
4689 rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
4691 const rb_iseq_t *rescue = new_child_iseq_with_callback(
4700 lstart->rescued = LABEL_RESCUE_BEG;
4701 lend->rescued = LABEL_RESCUE_END;
4703 APPEND_LABEL(ret, lcur, lstart);
4704 PUSH_LABEL(ret, lend);
4705 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
4715 lfinish[0] = NEW_LABEL(node_location->
line);
4720 pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish);
4724 ELEM_INSERT_NEXT(last, &new_insn_body(iseq, node_location->
line, node_location->
node_id, BIN(putnil), 0)->link);
4725 PUSH_INSN(ret, *node_location, swap);
4727 if (lfinish[2]) PUSH_LABEL(ret, lfinish[2]);
4728 PUSH_INSN(ret, *node_location, pop);
4729 PUSH_LABEL(ret, lfinish[1]);
4733 PUSH_LABEL(ret, lfinish[0]);
4744 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
4746 DECL_ANCHOR(ensure);
4749 if (enlp->erange != NULL) {
4750 DECL_ANCHOR(ensure_part);
4751 LABEL *lstart = NEW_LABEL(0);
4752 LABEL *lend = NEW_LABEL(0);
4754 add_ensure_range(iseq, enlp->erange, lstart, lend);
4756 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
4757 PUSH_LABEL(ensure_part, lstart);
4759 PM_COMPILE_INTO_ANCHOR(ensure_part, (
const pm_node_t *) enlp->ensure_node);
4760 PUSH_LABEL(ensure_part, lend);
4761 PUSH_SEQ(ensure, ensure_part);
4770 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
4771 PUSH_SEQ(ret, ensure);
4784 RUBY_ASSERT((constant_id & PM_SPECIAL_CONSTANT_FLAG) == 0);
4786 ID local = pm_constant_id_lookup(scope_node, constant_id);
4787 local_table_for_iseq->ids[local_index] = local;
4788 pm_index_lookup_table_insert(index_lookup_table, constant_id, local_index);
4797 local_table_for_iseq->ids[local_index] = local_name;
4798 pm_index_lookup_table_insert(index_lookup_table, special_id, local_index);
4810 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4813 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4814 if (!PM_NODE_FLAG_P(left, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4815 pm_insert_local_index(((
const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4820 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4821 local_index = pm_compile_destructured_param_locals((
const pm_multi_target_node_t *) left, index_lookup_table, local_table_for_iseq, scope_node, local_index);
4825 if (node->
rest != NULL && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE)) {
4828 if (rest->expression != NULL) {
4829 RUBY_ASSERT(PM_NODE_TYPE_P(rest->expression, PM_REQUIRED_PARAMETER_NODE));
4831 if (!PM_NODE_FLAG_P(rest->expression, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4832 pm_insert_local_index(((
const pm_required_parameter_node_t *) rest->expression)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4838 for (
size_t index = 0; index < node->
rights.
size; index++) {
4841 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4842 if (!PM_NODE_FLAG_P(right, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4843 pm_insert_local_index(((
const pm_required_parameter_node_t *) right)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4848 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4849 local_index = pm_compile_destructured_param_locals((
const pm_multi_target_node_t *) right, index_lookup_table, local_table_for_iseq, scope_node, local_index);
4865 PUSH_SETLOCAL(ret, location, index.index, index.level);
4880 bool has_rest = (node->
rest && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE) && (((
const pm_splat_node_t *) node->
rest)->expression) != NULL);
4883 int flag = (has_rest || has_rights) ? 1 : 0;
4886 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4889 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4893 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4904 RUBY_ASSERT(PM_NODE_TYPE_P(rest, PM_REQUIRED_PARAMETER_NODE));
4914 for (
size_t index = 0; index < node->
rights.
size; index++) {
4917 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4921 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4981 node->stack_index = state->stack_size + 1;
4982 node->stack_size = stack_size;
4983 node->position = state->position;
4986 if (state->head == NULL) {
4991 state->tail->next = node;
4995 state->stack_size += stack_size;
5008 if (state->stack_size == 0)
return;
5013 while (current != NULL) {
5014 VALUE offset =
INT2FIX(state->stack_size - current->stack_index + current->position);
5015 current->topn->operands[0] = offset;
5021 if (current->stack_size > 1) {
5022 INSN *insn = current->topn;
5024 for (
size_t index = 1; index < current->stack_size; index += 1) {
5028 insn = (
INSN *) element;
5031 insn->operands[0] = offset;
5036 current = current->next;
5038 SIZED_FREE(previous);
5078 switch (PM_NODE_TYPE(node)) {
5079 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5088 PUSH_SETLOCAL(writes, location, index.index, index.level);
5091 case PM_CLASS_VARIABLE_TARGET_NODE: {
5098 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5101 PUSH_INSN2(writes, location, setclassvariable, operand, get_cvar_ic_value(iseq, name));
5104 case PM_CONSTANT_TARGET_NODE: {
5111 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5114 PUSH_INSN1(writes, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5115 PUSH_INSN1(writes, location, setconstant, operand);
5118 case PM_GLOBAL_VARIABLE_TARGET_NODE: {
5125 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5128 PUSH_INSN1(writes, location, setglobal, operand);
5131 case PM_INSTANCE_VARIABLE_TARGET_NODE: {
5138 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5141 PUSH_INSN2(writes, location, setinstancevariable, operand, get_ivar_ic_value(iseq, name));
5144 case PM_CONSTANT_PATH_TARGET_NODE: {
5154 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5156 if (cast->
parent != NULL) {
5157 pm_compile_node(iseq, cast->
parent, parents,
false, scope_node);
5160 PUSH_INSN1(parents, location, putobject,
rb_cObject);
5163 if (state == NULL) {
5164 PUSH_INSN(writes, location, swap);
5167 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5168 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5172 PUSH_INSN1(writes, location, setconstant, operand);
5174 if (state != NULL) {
5175 PUSH_INSN(cleanup, location, pop);
5180 case PM_CALL_TARGET_NODE: {
5190 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
5192 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5194 LABEL *safe_label = NULL;
5195 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
5196 safe_label = NEW_LABEL(location.
line);
5197 PUSH_INSN(parents, location, dup);
5198 PUSH_INSNL(parents, location, branchnil, safe_label);
5201 if (state != NULL) {
5202 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5203 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5204 PUSH_INSN(writes, location, swap);
5207 int flags = VM_CALL_ARGS_SIMPLE;
5208 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) flags |= VM_CALL_FCALL;
5210 PUSH_SEND_WITH_FLAG(writes, location, method_id,
INT2FIX(1),
INT2FIX(flags));
5211 if (safe_label != NULL && state == NULL) PUSH_LABEL(writes, safe_label);
5212 PUSH_INSN(writes, location, pop);
5213 if (safe_label != NULL && state != NULL) PUSH_LABEL(writes, safe_label);
5215 if (state != NULL) {
5216 PUSH_INSN(cleanup, location, pop);
5221 case PM_INDEX_TARGET_NODE: {
5233 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5237 int argc = pm_setup_args(cast->
arguments, (
const pm_node_t *) cast->
block, &flags, &kwargs, iseq, parents, scope_node, &location);
5239 if (state != NULL) {
5240 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5241 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), argc + 1);
5244 PUSH_INSN(writes, location, swap);
5247 for (
int index = 0; index < argc; index++) {
5248 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5250 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5258 int ci_argc = argc + 1;
5259 if (flags & VM_CALL_ARGS_SPLAT) {
5261 PUSH_INSN1(writes, location, newarray,
INT2FIX(1));
5262 PUSH_INSN(writes, location, concatarray);
5265 PUSH_SEND_R(writes, location, idASET,
INT2NUM(ci_argc), NULL,
INT2FIX(flags), kwargs);
5266 PUSH_INSN(writes, location, pop);
5268 if (state != NULL) {
5270 PUSH_INSN(writes, location, pop);
5273 for (
int index = 0; index < argc + 1; index++) {
5274 PUSH_INSN(cleanup, location, pop);
5280 case PM_MULTI_TARGET_NODE: {
5287 size_t before_position;
5288 if (state != NULL) {
5289 before_position = state->position;
5293 pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, scope_node, state);
5294 if (state != NULL) state->position = before_position;
5298 case PM_SPLAT_NODE: {
5307 pm_compile_target_node(iseq, cast->
expression, parents, writes, cleanup, scope_node, state);
5313 rb_bug(
"Unexpected node type: %s", pm_node_type(PM_NODE_TYPE(node)));
5331 switch (PM_NODE_TYPE(node)) {
5332 case PM_MULTI_TARGET_NODE: {
5334 lefts = &cast->
lefts;
5339 case PM_MULTI_WRITE_NODE: {
5341 lefts = &cast->
lefts;
5347 rb_bug(
"Unsupported node %s", pm_node_type(PM_NODE_TYPE(node)));
5351 bool has_rest = (rest != NULL) && PM_NODE_TYPE_P(rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) rest)->expression != NULL;
5352 bool has_posts = rights->
size > 0;
5357 PUSH_INSN2(writes, location, expandarray,
INT2FIX(lefts->
size),
INT2FIX((has_rest || has_posts) ? 1 : 0));
5363 if (state == NULL) state = &target_state;
5365 size_t base_position = state->position;
5366 size_t splat_position = (has_rest || has_posts) ? 1 : 0;
5369 for (
size_t index = 0; index < lefts->
size; index++) {
5371 state->position = lefts->
size - index + splat_position + base_position;
5372 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5378 state->position = 1 + rights->
size + base_position;
5384 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5389 if (!has_rest && rest != NULL) {
5393 for (
size_t index = 0; index < rights->
size; index++) {
5395 state->position = rights->
size - index + base_position;
5396 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5411 switch (PM_NODE_TYPE(node)) {
5412 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5415 PUSH_GETLOCAL(ret, location, 1, 0);
5416 pm_compile_target_node(iseq, node, ret, ret, ret, scope_node, NULL);
5419 case PM_CLASS_VARIABLE_TARGET_NODE:
5420 case PM_CONSTANT_TARGET_NODE:
5421 case PM_GLOBAL_VARIABLE_TARGET_NODE:
5422 case PM_INSTANCE_VARIABLE_TARGET_NODE:
5423 case PM_CONSTANT_PATH_TARGET_NODE:
5424 case PM_CALL_TARGET_NODE:
5425 case PM_INDEX_TARGET_NODE: {
5429 DECL_ANCHOR(writes);
5430 DECL_ANCHOR(cleanup);
5434 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
5436 PUSH_GETLOCAL(ret, location, 1, 0);
5439 PUSH_SEQ(ret, writes);
5440 PUSH_SEQ(ret, cleanup);
5442 pm_multi_target_state_update(&state);
5446 case PM_MULTI_TARGET_NODE: {
5447 DECL_ANCHOR(writes);
5448 DECL_ANCHOR(cleanup);
5450 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, NULL);
5452 LABEL *not_single = NEW_LABEL(location.
line);
5453 LABEL *not_ary = NEW_LABEL(location.
line);
5461 PUSH_GETLOCAL(ret, location, 1, 0);
5462 PUSH_INSN(ret, location, dup);
5463 PUSH_CALL(ret, location, idLength,
INT2FIX(0));
5464 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
5465 PUSH_CALL(ret, location, idEq,
INT2FIX(1));
5466 PUSH_INSNL(ret, location, branchunless, not_single);
5467 PUSH_INSN(ret, location, dup);
5468 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
5469 PUSH_CALL(ret, location, idAREF,
INT2FIX(1));
5470 PUSH_INSN1(ret, location, putobject,
rb_cArray);
5471 PUSH_INSN(ret, location, swap);
5472 PUSH_CALL(ret, location, rb_intern(
"try_convert"),
INT2FIX(1));
5473 PUSH_INSN(ret, location, dup);
5474 PUSH_INSNL(ret, location, branchunless, not_ary);
5475 PUSH_INSN(ret, location, swap);
5477 PUSH_LABEL(ret, not_ary);
5478 PUSH_INSN(ret, location, pop);
5480 PUSH_LABEL(ret, not_single);
5482 if (PM_NODE_TYPE_P(node, PM_SPLAT_NODE)) {
5487 PUSH_SEQ(ret, writes);
5488 PUSH_SEQ(ret, cleanup);
5492 rb_bug(
"Unexpected node type for index in for node: %s", pm_node_type(PM_NODE_TYPE(node)));
5500 LABEL *lstart = NEW_LABEL(node_location->
line);
5501 LABEL *lend = NEW_LABEL(node_location->
line);
5502 LABEL *lcont = NEW_LABEL(node_location->
line);
5507 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
5514 pm_scope_node_destroy(&rescue_scope_node);
5516 lstart->rescued = LABEL_RESCUE_BEG;
5517 lend->rescued = LABEL_RESCUE_END;
5518 PUSH_LABEL(ret, lstart);
5520 bool prev_in_rescue = ISEQ_COMPILE_DATA(iseq)->in_rescue;
5521 ISEQ_COMPILE_DATA(iseq)->in_rescue =
true;
5528 PUSH_INSN(ret, location, putnil);
5531 ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;
5532 PUSH_LABEL(ret, lend);
5535 if (!popped) PUSH_INSN(ret, *node_location, pop);
5539 PUSH_INSN(ret, *node_location, nop);
5540 PUSH_LABEL(ret, lcont);
5542 if (popped) PUSH_INSN(ret, *node_location, pop);
5543 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
5544 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
5553 if (statements != NULL) {
5554 location = PM_NODE_START_LOCATION(statements);
5557 location = *node_location;
5560 LABEL *lstart = NEW_LABEL(location.
line);
5562 LABEL *lcont = NEW_LABEL(location.
line);
5569 if (statements != NULL) {
5570 pm_compile_node(iseq, (
const pm_node_t *) statements, ensr,
true, scope_node);
5574 bool last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
5579 push_ensure_entry(iseq, &enl, &er, (
void *) cast->
ensure_clause);
5581 PUSH_LABEL(ret, lstart);
5583 pm_compile_rescue(iseq, cast, node_location, ret, popped | last_leave, scope_node);
5586 pm_compile_node(iseq, (
const pm_node_t *) cast->
statements, ret, popped | last_leave, scope_node);
5588 else if (!(popped | last_leave)) {
5589 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
5592 PUSH_LABEL(ret, lend);
5593 PUSH_SEQ(ret, ensr);
5594 if (!popped && last_leave) PUSH_INSN(ret, *node_location, putnil);
5595 PUSH_LABEL(ret, lcont);
5596 if (last_leave) PUSH_INSN(ret, *node_location, pop);
5608 pm_scope_node_destroy(&next_scope_node);
5610 erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
5611 if (lstart->link.next != &lend->link) {
5613 PUSH_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, child_iseq, lcont);
5614 erange = erange->next;
5617 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
5628 !PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION) &&
5630 PM_NODE_TYPE_P(node->
receiver, PM_STRING_NODE) &&
5632 node->
block == NULL &&
5633 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5646 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
5647 ISEQ_BODY(iseq)->ic_size++;
5648 VALUE segments = rb_ary_new_from_args(1, name);
5649 RB_OBJ_SET_SHAREABLE(segments);
5650 PUSH_INSN1(ret, location, opt_getconstant_path, segments);
5653 PUSH_INSN(ret, location, putnil);
5654 PUSH_INSN1(ret, location, putobject,
Qtrue);
5655 PUSH_INSN1(ret, location, getconstant, name);
5669 switch (PM_NODE_TYPE(node)) {
5670 case PM_CONSTANT_READ_NODE: {
5674 rb_ary_unshift(parts, name);
5677 case PM_CONSTANT_PATH_NODE: {
5681 rb_ary_unshift(parts, name);
5682 if (cast->
parent == NULL) {
5683 rb_ary_unshift(parts,
ID2SYM(idNULL));
5706 switch (PM_NODE_TYPE(node)) {
5707 case PM_CONSTANT_READ_NODE: {
5711 PUSH_INSN1(body, location, putobject,
Qtrue);
5712 PUSH_INSN1(body, location, getconstant, name);
5715 case PM_CONSTANT_PATH_NODE: {
5719 if (cast->
parent == NULL) {
5720 PUSH_INSN(body, location, pop);
5721 PUSH_INSN1(body, location, putobject,
rb_cObject);
5722 PUSH_INSN1(body, location, putobject,
Qtrue);
5723 PUSH_INSN1(body, location, getconstant, name);
5726 pm_compile_constant_path(iseq, cast->
parent, prefix, body,
false, scope_node);
5727 PUSH_INSN1(body, location, putobject,
Qfalse);
5728 PUSH_INSN1(body, location, getconstant, name);
5733 PM_COMPILE_INTO_ANCHOR(prefix, node);
5744 switch (PM_NODE_TYPE(node)) {
5748 case PM_SYMBOL_NODE:
5749 case PM_REGULAR_EXPRESSION_NODE:
5750 case PM_SOURCE_LINE_NODE:
5751 case PM_INTEGER_NODE:
5753 case PM_RATIONAL_NODE:
5754 case PM_IMAGINARY_NODE:
5755 case PM_SOURCE_ENCODING_NODE:
5756 return pm_static_literal_value(iseq, node, scope_node);
5757 case PM_STRING_NODE:
5758 return parse_static_literal_string(iseq, scope_node, node, &((
const pm_string_node_t *) node)->unescaped);
5759 case PM_SOURCE_FILE_NODE:
5761 case PM_ARRAY_NODE: {
5765 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5766 VALUE element = pm_compile_shareable_constant_literal(iseq, cast->
elements.
nodes[index], scope_node);
5774 case PM_HASH_NODE: {
5778 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5780 if (!PM_NODE_TYPE_P(element, PM_ASSOC_NODE))
return Qundef;
5784 VALUE key = pm_compile_shareable_constant_literal(iseq, assoc->
key, scope_node);
5787 VALUE value = pm_compile_shareable_constant_literal(iseq, assoc->
value, scope_node);
5790 rb_hash_aset(result, key, value);
5807 VALUE literal = pm_compile_shareable_constant_literal(iseq, node, scope_node);
5810 PUSH_INSN1(ret, location, putobject, literal);
5815 switch (PM_NODE_TYPE(node)) {
5816 case PM_ARRAY_NODE: {
5820 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5823 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5824 pm_compile_shareable_constant_value(iseq, cast->
elements.
nodes[index], shareability, path, ret, scope_node,
false);
5830 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5831 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5836 case PM_HASH_NODE: {
5840 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5843 pm_compile_hash_elements(iseq, (
const pm_node_t *) cast, &cast->elements, shareability, path,
false, ret, scope_node);
5846 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5847 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5853 DECL_ANCHOR(value_seq);
5855 pm_compile_node(iseq, node, value_seq,
false, scope_node);
5856 if (PM_NODE_TYPE_P(node, PM_INTERPOLATED_STRING_NODE)) {
5857 PUSH_SEND_WITH_FLAG(value_seq, location, idUMinus,
INT2FIX(0),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5860 if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_LITERAL) {
5861 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5862 PUSH_SEQ(ret, value_seq);
5864 RB_OBJ_SET_SHAREABLE(path);
5866 PUSH_INSN1(ret, location, putobject, path);
5867 PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"ensure_shareable"),
INT2FIX(2),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5869 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) {
5870 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5871 PUSH_SEQ(ret, value_seq);
5872 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable_copy"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5874 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_EVERYTHING) {
5875 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5876 PUSH_SEQ(ret, value_seq);
5877 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5893 ID name_id = pm_constant_id_lookup(scope_node, node->
name);
5895 if (shareability != 0) {
5896 pm_compile_shareable_constant_value(iseq, node->
value, shareability, rb_id2str(name_id), ret, scope_node,
true);
5899 PM_COMPILE_NOT_POPPED(node->
value);
5902 if (!popped) PUSH_INSN(ret, location, dup);
5903 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5906 PUSH_INSN1(ret, location, setconstant, operand);
5919 LABEL *end_label = NEW_LABEL(location.
line);
5921 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5922 if (!popped) PUSH_INSN(ret, location, dup);
5924 PUSH_INSNL(ret, location, branchunless, end_label);
5925 if (!popped) PUSH_INSN(ret, location, pop);
5927 if (shareability != 0) {
5928 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5931 PM_COMPILE_NOT_POPPED(node->
value);
5934 if (!popped) PUSH_INSN(ret, location, dup);
5935 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5936 PUSH_INSN1(ret, location, setconstant, name);
5937 PUSH_LABEL(ret, end_label);
5950 LABEL *set_label = NEW_LABEL(location.
line);
5951 LABEL *end_label = NEW_LABEL(location.
line);
5953 PUSH_INSN(ret, location, putnil);
5954 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name,
Qtrue);
5955 PUSH_INSNL(ret, location, branchunless, set_label);
5957 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5958 if (!popped) PUSH_INSN(ret, location, dup);
5960 PUSH_INSNL(ret, location, branchif, end_label);
5961 if (!popped) PUSH_INSN(ret, location, pop);
5962 PUSH_LABEL(ret, set_label);
5964 if (shareability != 0) {
5965 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5968 PM_COMPILE_NOT_POPPED(node->
value);
5971 if (!popped) PUSH_INSN(ret, location, dup);
5972 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5973 PUSH_INSN1(ret, location, setconstant, name);
5974 PUSH_LABEL(ret, end_label);
5989 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5991 if (shareability != 0) {
5992 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5995 PM_COMPILE_NOT_POPPED(node->
value);
5998 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5999 if (!popped) PUSH_INSN(ret, location, dup);
6001 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
6002 PUSH_INSN1(ret, location, setconstant, name);
6013 rb_ary_push(parts, rb_id2str(pm_constant_id_lookup(scope_node, node->
name)));
6016 while (current != NULL && PM_NODE_TYPE_P(current, PM_CONSTANT_PATH_NODE)) {
6018 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, cast->
name)));
6022 if (current == NULL) {
6023 rb_ary_unshift(parts, rb_id2str(idNULL));
6025 else if (PM_NODE_TYPE_P(current, PM_CONSTANT_READ_NODE)) {
6026 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, ((
const pm_constant_read_node_t *) current)->name)));
6050 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6053 if (shareability != 0) {
6054 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6057 PM_COMPILE_NOT_POPPED(node->
value);
6061 PUSH_INSN(ret, location, swap);
6062 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6065 PUSH_INSN(ret, location, swap);
6066 PUSH_INSN1(ret, location, setconstant, name);
6083 PM_COMPILE_NOT_POPPED(target->
parent);
6086 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6089 PUSH_INSN(ret, location, dup);
6090 PUSH_INSN1(ret, location, putobject,
Qtrue);
6091 PUSH_INSN1(ret, location, getconstant, name);
6093 if (!popped) PUSH_INSN(ret, location, dup);
6094 PUSH_INSNL(ret, location, branchunless, lfin);
6096 if (!popped) PUSH_INSN(ret, location, pop);
6098 if (shareability != 0) {
6099 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6102 PM_COMPILE_NOT_POPPED(node->
value);
6106 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6109 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6110 PUSH_INSN(ret, location, swap);
6113 PUSH_INSN1(ret, location, setconstant, name);
6114 PUSH_LABEL(ret, lfin);
6116 if (!popped) PUSH_INSN(ret, location, swap);
6117 PUSH_INSN(ret, location, pop);
6131 LABEL *lassign = NEW_LABEL(location.
line);
6135 PM_COMPILE_NOT_POPPED(target->
parent);
6138 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6141 PUSH_INSN(ret, location, dup);
6142 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name,
Qtrue);
6143 PUSH_INSNL(ret, location, branchunless, lassign);
6145 PUSH_INSN(ret, location, dup);
6146 PUSH_INSN1(ret, location, putobject,
Qtrue);
6147 PUSH_INSN1(ret, location, getconstant, name);
6149 if (!popped) PUSH_INSN(ret, location, dup);
6150 PUSH_INSNL(ret, location, branchif, lfin);
6152 if (!popped) PUSH_INSN(ret, location, pop);
6153 PUSH_LABEL(ret, lassign);
6155 if (shareability != 0) {
6156 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6159 PM_COMPILE_NOT_POPPED(node->
value);
6163 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6166 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6167 PUSH_INSN(ret, location, swap);
6170 PUSH_INSN1(ret, location, setconstant, name);
6171 PUSH_LABEL(ret, lfin);
6173 if (!popped) PUSH_INSN(ret, location, swap);
6174 PUSH_INSN(ret, location, pop);
6191 PM_COMPILE_NOT_POPPED(target->
parent);
6194 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6197 PUSH_INSN(ret, location, dup);
6198 PUSH_INSN1(ret, location, putobject,
Qtrue);
6199 PUSH_INSN1(ret, location, getconstant, name);
6201 if (shareability != 0) {
6202 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6205 PM_COMPILE_NOT_POPPED(node->
value);
6208 PUSH_CALL(ret, location, method_id,
INT2FIX(1));
6209 PUSH_INSN(ret, location, swap);
6212 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6213 PUSH_INSN(ret, location, swap);
6216 PUSH_INSN1(ret, location, setconstant, name);
6225#define PM_CONTAINER_P(node) (PM_NODE_TYPE_P(node, PM_ARRAY_NODE) || PM_NODE_TYPE_P(node, PM_HASH_NODE) || PM_NODE_TYPE_P(node, PM_RANGE_NODE))
6244 bool trailing_comma =
false;
6246 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
6250 if (scope_node->parameters != NULL) {
6251 switch (PM_NODE_TYPE(scope_node->parameters)) {
6252 case PM_BLOCK_PARAMETERS_NODE: {
6254 parameters_node = cast->parameters;
6255 block_locals = &cast->locals;
6257 if (parameters_node) {
6258 if (parameters_node->
rest && PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE)) {
6259 trailing_comma =
true;
6264 case PM_PARAMETERS_NODE: {
6268 case PM_NUMBERED_PARAMETERS_NODE: {
6270 body->param.lead_num = maximum;
6271 body->param.flags.ambiguous_param0 = maximum == 1;
6274 case PM_IT_PARAMETERS_NODE:
6275 body->param.lead_num = 1;
6276 body->param.flags.ambiguous_param0 =
true;
6279 rb_bug(
"Unexpected node type for parameters: %s", pm_node_type(PM_NODE_TYPE(scope_node->parameters)));
6283 struct rb_iseq_param_keyword *keyword = NULL;
6285 if (parameters_node) {
6286 optionals_list = ¶meters_node->
optionals;
6287 requireds_list = ¶meters_node->
requireds;
6288 keywords_list = ¶meters_node->
keywords;
6289 posts_list = ¶meters_node->
posts;
6291 else if (scope_node->parameters && (PM_NODE_TYPE_P(scope_node->parameters, PM_NUMBERED_PARAMETERS_NODE) || PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE))) {
6292 body->param.opt_num = 0;
6295 body->param.lead_num = 0;
6296 body->param.opt_num = 0;
6302 size_t locals_size = locals->
size;
6308 int table_size = (int) locals_size;
6312 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) table_size++;
6314 if (keywords_list && keywords_list->
size) {
6318 if (requireds_list) {
6319 for (
size_t i = 0; i < requireds_list->
size; i++) {
6324 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6327 else if (PM_NODE_TYPE_P(required, PM_REQUIRED_PARAMETER_NODE)) {
6328 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6337 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6345 if (optionals_list && optionals_list->
size) {
6346 for (
size_t i = 0; i < optionals_list->
size; i++) {
6348 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6358 if (parameters_node) {
6359 if (parameters_node->
rest) {
6360 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6374 if (PM_NODE_TYPE_P(parameters_node->
keyword_rest, PM_FORWARDING_PARAMETER_NODE)) {
6376 if (requireds_list->
size == 0 && optionals_list->
size == 0 && keywords_list->
size == 0) {
6377 ISEQ_BODY(iseq)->param.flags.use_block = TRUE;
6378 ISEQ_BODY(iseq)->param.flags.forwardable = TRUE;
6389 if (!kw_rest->name || PM_NODE_FLAG_P(kw_rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6397 for (
size_t i = 0; i < posts_list->
size; i++) {
6402 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE) || PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6408 if (keywords_list && keywords_list->
size) {
6409 for (
size_t i = 0; i < keywords_list->
size; i++) {
6411 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6417 if (parameters_node && parameters_node->
block && PM_NODE_TYPE_P(parameters_node->
block, PM_BLOCK_PARAMETER_NODE)) {
6420 if (PM_NODE_FLAG_P(block_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER) || !block_node->name) {
6428 local_table_for_iseq->size = table_size;
6432 pm_index_lookup_table_init(&index_lookup_table, (
int) pm_parser_constants_size(scope_node->parser), iseq);
6452 int local_index = 0;
6459 if (requireds_list && requireds_list->
size) {
6460 for (
size_t i = 0; i < requireds_list->
size; i++, local_index++) {
6468 switch (PM_NODE_TYPE(required)) {
6469 case PM_MULTI_TARGET_NODE: {
6472 local = rb_make_temporary_id(local_index);
6473 local_table_for_iseq->ids[local_index] = local;
6476 case PM_REQUIRED_PARAMETER_NODE: {
6481 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6482 ID local = pm_constant_id_lookup(scope_node, param->
name);
6483 local_table_for_iseq->ids[local_index] = local;
6486 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6492 rb_bug(
"Unsupported node in requireds in parameters %s", pm_node_type(PM_NODE_TYPE(required)));
6496 body->param.lead_num = (int) requireds_list->
size;
6497 body->param.flags.has_lead =
true;
6500 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6501 local_table_for_iseq->ids[local_index++] = idItImplicit;
6506 if (optionals_list && optionals_list->
size) {
6507 body->param.opt_num = (int) optionals_list->
size;
6508 body->param.flags.has_opt =
true;
6510 for (
size_t i = 0; i < optionals_list->
size; i++, local_index++) {
6514 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6515 ID local = pm_constant_id_lookup(scope_node, name);
6516 local_table_for_iseq->ids[local_index] = local;
6519 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6526 if (parameters_node && parameters_node->
rest) {
6527 body->param.rest_start = local_index;
6531 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6532 body->param.flags.has_rest =
true;
6540 if (PM_NODE_FLAG_P(parameters_node->
rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6541 ID local = pm_constant_id_lookup(scope_node, name);
6542 local_table_for_iseq->ids[local_index] = local;
6545 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6551 body->param.flags.anon_rest =
true;
6552 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index, &index_lookup_table, local_table_for_iseq);
6561 if (posts_list && posts_list->
size) {
6562 body->param.post_num = (int) posts_list->
size;
6563 body->param.post_start = local_index;
6564 body->param.flags.has_post =
true;
6566 for (
size_t i = 0; i < posts_list->
size; i++, local_index++) {
6574 switch (PM_NODE_TYPE(post_node)) {
6575 case PM_MULTI_TARGET_NODE: {
6578 local = rb_make_temporary_id(local_index);
6579 local_table_for_iseq->ids[local_index] = local;
6582 case PM_REQUIRED_PARAMETER_NODE: {
6587 if (PM_NODE_FLAG_P(param, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6588 ID local = pm_constant_id_lookup(scope_node, param->
name);
6589 local_table_for_iseq->ids[local_index] = local;
6592 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6597 rb_bug(
"Unsupported node in posts in parameters %s", pm_node_type(PM_NODE_TYPE(post_node)));
6605 if (keywords_list && keywords_list->
size) {
6606 if (keywords_list->
size > VM_CALL_KW_LEN_MAX) {
6607 COMPILE_ERROR(iseq, node_location->
line,
"too many keyword parameters (%d, maximum is %d)",
6608 (
int) keywords_list->
size, (
int) VM_CALL_KW_LEN_MAX);
6611 keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6612 keyword->num = (int) keywords_list->
size;
6617 for (
size_t i = 0; i < keywords_list->
size; i++) {
6623 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_REQUIRED_KEYWORD_PARAMETER_NODE)) {
6625 keyword->required_num++;
6626 ID local = pm_constant_id_lookup(scope_node, name);
6628 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6629 local_table_for_iseq->ids[local_index] = local;
6632 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6638 for (
size_t i = 0; i < keywords_list->
size; i++) {
6644 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_OPTIONAL_KEYWORD_PARAMETER_NODE)) {
6650 if (PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) {
6651 rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node));
6657 ID local = pm_constant_id_lookup(scope_node, name);
6658 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6659 local_table_for_iseq->ids[local_index] = local;
6662 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6672 for (
int i = 0; i <
RARRAY_LEN(default_values); i++) {
6674 if (dv == complex_mark) dv =
Qundef;
6678 keyword->default_values = dvs;
6682 keyword->bits_start = local_index;
6683 ID local = rb_make_temporary_id(local_index);
6684 local_table_for_iseq->ids[local_index] = local;
6687 body->param.keyword = keyword;
6688 body->param.flags.has_kw =
true;
6691 if (body->type == ISEQ_TYPE_BLOCK && local_index == 1 && requireds_list && requireds_list->
size == 1 && !trailing_comma) {
6692 body->param.flags.ambiguous_param0 =
true;
6695 if (parameters_node) {
6700 case PM_NO_KEYWORDS_PARAMETER_NODE: {
6703 body->param.flags.accepts_no_kwarg =
true;
6706 case PM_KEYWORD_REST_PARAMETER_NODE: {
6710 if (!body->param.flags.has_kw) {
6711 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6714 keyword->rest_start = local_index;
6715 body->param.flags.has_kwrest =
true;
6719 if (PM_NODE_FLAG_P(kw_rest_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6720 ID local = pm_constant_id_lookup(scope_node, constant_id);
6721 local_table_for_iseq->ids[local_index] = local;
6724 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6728 body->param.flags.anon_kwrest =
true;
6729 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index, &index_lookup_table, local_table_for_iseq);
6735 case PM_FORWARDING_PARAMETER_NODE: {
6738 if (!ISEQ_BODY(iseq)->param.
flags.forwardable) {
6740 body->param.rest_start = local_index;
6741 body->param.flags.has_rest =
true;
6742 body->param.flags.anon_rest =
true;
6743 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index++, &index_lookup_table, local_table_for_iseq);
6747 body->param.flags.has_kw =
false;
6748 body->param.flags.has_kwrest =
true;
6749 body->param.flags.anon_kwrest =
true;
6750 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6751 keyword->rest_start = local_index;
6752 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index++, &index_lookup_table, local_table_for_iseq);
6755 body->param.block_start = local_index;
6756 body->param.flags.has_block =
true;
6757 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index++, &index_lookup_table, local_table_for_iseq);
6761 pm_insert_local_special(PM_CONSTANT_DOT3, idDot3, local_index++, &index_lookup_table, local_table_for_iseq);
6765 rb_bug(
"node type %s not expected as keyword_rest", pm_node_type(PM_NODE_TYPE(parameters_node->
keyword_rest)));
6771 if (parameters_node->
block) {
6772 switch (PM_NODE_TYPE(parameters_node->
block)) {
6773 case PM_BLOCK_PARAMETER_NODE: {
6774 body->param.block_start = local_index;
6775 body->param.flags.has_block =
true;
6777 iseq_set_use_block(iseq);
6782 if (PM_NODE_FLAG_P(parameters_node->
block, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6783 ID local = pm_constant_id_lookup(scope_node, name);
6784 local_table_for_iseq->ids[local_index] = local;
6787 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6791 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index, &index_lookup_table, local_table_for_iseq);
6797 case PM_NO_BLOCK_PARAMETER_NODE: {
6798 body->param.flags.accepts_no_block =
true;
6802 rb_bug(
"node type %s not expected as block parameter", pm_node_type(PM_NODE_TYPE(parameters_node->
block)));
6819 if (requireds_list && requireds_list->
size) {
6820 for (
size_t i = 0; i < requireds_list->
size; i++) {
6826 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6827 local_index = pm_compile_destructured_param_locals((
const pm_multi_target_node_t *) required, &index_lookup_table, local_table_for_iseq, scope_node, local_index);
6833 if (posts_list && posts_list->
size) {
6834 for (
size_t i = 0; i < posts_list->
size; i++) {
6840 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
6841 local_index = pm_compile_destructured_param_locals((
const pm_multi_target_node_t *) post, &index_lookup_table, local_table_for_iseq, scope_node, local_index);
6847 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
6848 if (PM_NODE_TYPE_P(((
const pm_for_node_t *) scope_node->ast_node)->index, PM_LOCAL_VARIABLE_TARGET_NODE)) {
6849 body->param.lead_num++;
6852 body->param.rest_start = local_index;
6853 body->param.flags.has_rest =
true;
6856 ID local = rb_make_temporary_id(local_index);
6857 local_table_for_iseq->ids[local_index] = local;
6862 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_NUMBERED_PARAMETERS_NODE)) {
6865 for (
int i = 0; i < maximum; i++, local_index++) {
6866 const uint8_t param_name[] = {
'_',
'1' + i };
6867 pm_constant_id_t constant_id = pm_parser_constant_find(scope_node->parser, param_name, 2);
6868 RUBY_ASSERT(constant_id &&
"parser should fill in any gaps in numbered parameters");
6869 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6871 body->param.lead_num = maximum;
6872 body->param.flags.has_lead =
true;
6876 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6877 body->param.lead_num = 1;
6878 body->param.flags.has_lead =
true;
6889 if (block_locals && block_locals->
size) {
6890 for (
size_t i = 0; i < block_locals->
size; i++, local_index++) {
6892 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6897 if (scope_node->locals.
size) {
6898 for (
size_t i = 0; i < scope_node->locals.
size; i++) {
6902 if (!pm_index_lookup_table_lookup(&index_lookup_table, constant_id, &existing)) {
6903 ID local = pm_constant_id_lookup(scope_node, constant_id);
6904 local_table_for_iseq->ids[local_index] = local;
6905 pm_index_lookup_table_insert(&index_lookup_table, constant_id, local_index);
6917 iseq_calc_param_size(iseq);
6919 if (ISEQ_BODY(iseq)->param.
flags.forwardable) {
6922 ISEQ_BODY(iseq)->param.size += 1;
6926 iseq_set_local_table(iseq, local_table_for_iseq, 0);
6927 iseq_set_parameters_lvar_state(iseq);
6929 scope_node->local_table_for_iseq_size = local_table_for_iseq->size;
6931 if (keyword != NULL) {
6932 size_t keyword_start_index = keyword->bits_start - keyword->num;
6933 keyword->table = (
ID *)&ISEQ_BODY(iseq)->local_table[keyword_start_index];
6938 if (optionals_list && optionals_list->
size) {
6946 for (
size_t i = 0; i < optionals_list->
size; i++) {
6947 label = NEW_LABEL(location.
line);
6948 opt_table[i] = label;
6949 PUSH_LABEL(ret, label);
6951 PM_COMPILE_NOT_POPPED(optional_node);
6955 label = NEW_LABEL(location.
line);
6956 opt_table[optionals_list->
size] = label;
6957 PUSH_LABEL(ret, label);
6959 body->param.opt_table = (
const VALUE *) opt_table;
6962 if (keywords_list && keywords_list->
size) {
6963 size_t optional_index = 0;
6964 for (
size_t i = 0; i < keywords_list->
size; i++) {
6968 switch (PM_NODE_TYPE(keyword_parameter_node)) {
6969 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
6977 if (!PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) {
6978 LABEL *end_label = NEW_LABEL(location.
line);
6981 int kw_bits_idx = table_size - body->param.keyword->bits_start;
6982 PUSH_INSN2(ret, location, checkkeyword,
INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1),
INT2FIX(optional_index));
6983 PUSH_INSNL(ret, location, branchif, end_label);
6985 PUSH_SETLOCAL(ret, location, index.index, index.level);
6986 PUSH_LABEL(ret, end_label);
6991 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
6996 rb_bug(
"Unexpected keyword parameter node type %s", pm_node_type(PM_NODE_TYPE(keyword_parameter_node)));
7001 if (requireds_list && requireds_list->
size) {
7002 for (
size_t i = 0; i < requireds_list->
size; i++) {
7008 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
7009 PUSH_GETLOCAL(ret, location, table_size - (
int)i, 0);
7015 if (posts_list && posts_list->
size) {
7016 for (
size_t i = 0; i < posts_list->
size; i++) {
7022 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
7023 PUSH_GETLOCAL(ret, location, table_size - body->param.post_start - (
int) i, 0);
7029 switch (body->type) {
7030 case ISEQ_TYPE_PLAIN: {
7031 RUBY_ASSERT(PM_NODE_TYPE_P(scope_node->ast_node, PM_INTERPOLATED_REGULAR_EXPRESSION_NODE));
7034 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
7038 case ISEQ_TYPE_BLOCK: {
7039 LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
7040 LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
7043 start->rescued = LABEL_RESCUE_BEG;
7044 end->rescued = LABEL_RESCUE_END;
7050 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
7051 pm_compile_for_node_index(iseq, ((
const pm_for_node_t *) scope_node->ast_node)->index, ret, scope_node);
7055 PUSH_INSN(ret, block_location, nop);
7056 PUSH_LABEL(ret, start);
7058 if (scope_node->body != NULL) {
7059 switch (PM_NODE_TYPE(scope_node->ast_node)) {
7060 case PM_POST_EXECUTION_NODE: {
7062 PUSH_INSN1(ret, block_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7066 pm_scope_node_init((
const pm_node_t *) cast->statements, &next_scope_node, scope_node);
7068 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(body->parent_iseq), ISEQ_TYPE_BLOCK, location.
line);
7069 pm_scope_node_destroy(&next_scope_node);
7071 PUSH_CALL_WITH_BLOCK(ret, block_location, id_core_set_postexe,
INT2FIX(0), block);
7074 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
7076 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
7080 pm_compile_node(iseq, scope_node->body, ret, popped, scope_node);
7085 PUSH_INSN(ret, block_location, putnil);
7088 PUSH_LABEL(ret, end);
7090 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7093 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
7094 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
7097 case ISEQ_TYPE_ENSURE: {
7098 const pm_node_location_t statements_location = (scope_node->body != NULL ? PM_NODE_START_LOCATION(scope_node->body) : location);
7099 iseq_set_exception_local_table(iseq);
7101 if (scope_node->body != NULL) {
7102 PM_COMPILE_POPPED((
const pm_node_t *) scope_node->body);
7105 PUSH_GETLOCAL(ret, statements_location, 1, 0);
7106 PUSH_INSN1(ret, statements_location,
throw,
INT2FIX(0));
7109 case ISEQ_TYPE_METHOD: {
7110 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7113 if (scope_node->body) {
7114 PM_COMPILE((
const pm_node_t *) scope_node->body);
7117 PUSH_INSN(ret, location, putnil);
7120 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7123 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7126 case ISEQ_TYPE_RESCUE: {
7127 iseq_set_exception_local_table(iseq);
7128 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_RESCUE_MODIFIER_NODE)) {
7130 LABEL *rescue_end = NEW_LABEL(location.
line);
7131 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7133 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
7134 PUSH_INSNL(ret, location, branchif, lab);
7135 PUSH_INSNL(ret, location, jump, rescue_end);
7136 PUSH_LABEL(ret, lab);
7138 PM_COMPILE((
const pm_node_t *) scope_node->body);
7139 PUSH_INSN(ret, location, leave);
7140 PUSH_LABEL(ret, rescue_end);
7141 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7144 PM_COMPILE((
const pm_node_t *) scope_node->ast_node);
7146 PUSH_INSN1(ret, location,
throw,
INT2FIX(0));
7151 if (scope_node->body) {
7152 PM_COMPILE((
const pm_node_t *) scope_node->body);
7155 PUSH_INSN(ret, location, putnil);
7160 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
7163 ISEQ_COMPILE_DATA(iseq)->last_line = end_location.
line;
7166 if (!PM_NODE_TYPE_P(scope_node->ast_node, PM_ENSURE_NODE)) {
7168 PUSH_INSN(ret, location, leave);
7177 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7181 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7182 PUSH_INSN1(ret, *location, putobject, operand);
7187 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7188 PUSH_INSN1(ret, *location, putobject, operand);
7191 PUSH_SEND(ret, *location, id_core_set_variable_alias,
INT2FIX(2));
7192 if (popped) PUSH_INSN(ret, *location, pop);
7198 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7199 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
7200 PM_COMPILE_NOT_POPPED(node->
new_name);
7201 PM_COMPILE_NOT_POPPED(node->
old_name);
7203 PUSH_SEND(ret, *location, id_core_set_method_alias,
INT2FIX(3));
7204 if (popped) PUSH_INSN(ret, *location, pop);
7210 LABEL *end_label = NEW_LABEL(location->
line);
7212 PM_COMPILE_NOT_POPPED(node->
left);
7213 if (!popped) PUSH_INSN(ret, *location, dup);
7214 PUSH_INSNL(ret, *location, branchunless, end_label);
7216 if (!popped) PUSH_INSN(ret, *location, pop);
7217 PM_COMPILE(node->
right);
7218 PUSH_LABEL(ret, end_label);
7226 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
7231 if (elements->
size) {
7232 VALUE value = pm_static_literal_value(iseq, node, scope_node);
7233 RB_OBJ_SET_FROZEN_SHAREABLE(value);
7234 PUSH_INSN1(ret, *location, duparray, value);
7237 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7255 const int max_new_array_size = 0x100;
7256 const unsigned int min_tmp_array_size = 0x40;
7258 int new_array_size = 0;
7259 bool first_chunk =
true;
7265 bool static_literal =
false;
7268#define FLUSH_CHUNK \
7269 if (new_array_size) { \
7270 if (first_chunk) PUSH_INSN1(ret, *location, newarray, INT2FIX(new_array_size)); \
7271 else PUSH_INSN1(ret, *location, pushtoarray, INT2FIX(new_array_size)); \
7272 first_chunk = false; \
7273 new_array_size = 0; \
7276 for (
size_t index = 0; index < elements->
size; index++) {
7279 if (PM_NODE_TYPE_P(element, PM_SPLAT_NODE)) {
7284 PM_COMPILE_NOT_POPPED(splat_element->
expression);
7287 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
7288 PUSH_GETLOCAL(ret, *location, index.index, index.level);
7294 PUSH_INSN1(ret, *location, splatarray,
Qtrue);
7295 first_chunk =
false;
7298 PUSH_INSN(ret, *location, concattoarray);
7301 static_literal =
false;
7303 else if (PM_NODE_TYPE_P(element, PM_KEYWORD_HASH_NODE)) {
7304 if (new_array_size == 0 && first_chunk) {
7305 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7306 first_chunk =
false;
7323 pm_compile_hash_elements(iseq, element, &keyword_hash->
elements, 0,
Qundef,
false, ret, scope_node);
7330 while (splats < keyword_hash->elements.
size && PM_NODE_TYPE_P(keyword_hash->
elements.
nodes[splats], PM_ASSOC_SPLAT_NODE)) splats++;
7333 PUSH_INSN(ret, *location, pushtoarraykwsplat);
7340 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) &&
7341 !PM_CONTAINER_P(element) &&
7343 ((index + min_tmp_array_size) < elements->
size)
7348 size_t right_index = index + 1;
7350 right_index < elements->size &&
7351 PM_NODE_FLAG_P(elements->
nodes[right_index], PM_NODE_FLAG_STATIC_LITERAL) &&
7352 !PM_CONTAINER_P(elements->
nodes[right_index])
7355 size_t tmp_array_size = right_index - index;
7356 if (tmp_array_size >= min_tmp_array_size) {
7360 for (; tmp_array_size; tmp_array_size--)
7361 rb_ary_push(tmp_array, pm_static_literal_value(iseq, elements->
nodes[index++], scope_node));
7364 RB_OBJ_SET_FROZEN_SHAREABLE(tmp_array);
7369 PUSH_INSN1(ret, *location, duparray, tmp_array);
7370 first_chunk =
false;
7373 PUSH_INSN1(ret, *location, putobject, tmp_array);
7374 PUSH_INSN(ret, *location, concattoarray);
7378 PM_COMPILE_NOT_POPPED(element);
7379 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7380 static_literal =
true;
7383 PM_COMPILE_NOT_POPPED(element);
7384 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7385 static_literal =
false;
7390 if (popped) PUSH_INSN(ret, *location, pop);
7398 unsigned long throw_flag = 0;
7400 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
7402 LABEL *splabel = NEW_LABEL(0);
7403 PUSH_LABEL(ret, splabel);
7404 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7410 PUSH_INSN(ret, *location, putnil);
7413 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7414 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
7415 PUSH_ADJUST_RESTORE(ret, splabel);
7416 if (!popped) PUSH_INSN(ret, *location, putnil);
7422 if (!ISEQ_COMPILE_DATA(ip)) {
7427 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7428 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
7430 else if (ISEQ_BODY(ip)->type == ISEQ_TYPE_BLOCK) {
7433 else if (ISEQ_BODY(ip)->type == ISEQ_TYPE_EVAL) {
7434 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7438 ip = ISEQ_BODY(ip)->parent_iseq;
7447 PUSH_INSN(ret, *location, putnil);
7450 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_BREAK));
7451 if (popped) PUSH_INSN(ret, *location, pop);
7456 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7463 ID method_id = pm_constant_id_lookup(scope_node, node->
name);
7469 const char *builtin_func;
7471 if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && (builtin_func = pm_iseq_builtin_function_name(scope_node, node->
receiver, method_id)) != NULL) {
7472 pm_compile_builtin_function_call(iseq, ret, scope_node, node, &location, popped, ISEQ_COMPILE_DATA(iseq)->current_block, builtin_func);
7476 LABEL *start = NEW_LABEL(location.
line);
7477 if (node->
block) PUSH_LABEL(ret, start);
7479 switch (method_id) {
7481 if (pm_opt_str_freeze_p(iseq, node)) {
7483 const struct rb_callinfo *callinfo = new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE);
7484 PUSH_INSN2(ret, location, opt_str_uminus, value, callinfo);
7485 if (popped) PUSH_INSN(ret, location, pop);
7491 if (pm_opt_str_freeze_p(iseq, node)) {
7493 const struct rb_callinfo *callinfo = new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE);
7494 PUSH_INSN2(ret, location, opt_str_freeze, value, callinfo);
7495 if (popped) PUSH_INSN(ret, location, pop);
7502 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
7503 PUSH_INSN(ret, location, putnil);
7507 PUSH_INSN(ret, location, putself);
7510 if ((method_id == idCall || method_id == idAREF || method_id == idYield || method_id == idEqq) && PM_NODE_TYPE_P(node->
receiver, PM_LOCAL_VARIABLE_READ_NODE)) {
7515 if (iseq_block_param_id_p(iseq, pm_constant_id_lookup(scope_node, read_node_cast->name), &idx, &level)) {
7516 ADD_ELEM(ret, (
LINK_ELEMENT *) new_insn_body(iseq, location.
line, node_id, BIN(getblockparamproxy), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
7519 PM_COMPILE_NOT_POPPED(node->
receiver);
7523 PM_COMPILE_NOT_POPPED(node->
receiver);
7527 pm_compile_call(iseq, node, ret, popped, scope_node, method_id, start);
7536 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
7537 flag = VM_CALL_FCALL;
7540 PM_COMPILE_NOT_POPPED(node->
receiver);
7542 LABEL *safe_label = NULL;
7543 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
7544 safe_label = NEW_LABEL(location->
line);
7545 PUSH_INSN(ret, *location, dup);
7546 PUSH_INSNL(ret, *location, branchnil, safe_label);
7549 PUSH_INSN(ret, *location, dup);
7551 ID id_read_name = pm_constant_id_lookup(scope_node, node->
read_name);
7552 PUSH_SEND_WITH_FLAG(ret, *location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
7554 PM_COMPILE_NOT_POPPED(node->
value);
7556 PUSH_SEND(ret, *location, id_operator,
INT2FIX(1));
7559 PUSH_INSN(ret, *location, swap);
7560 PUSH_INSN1(ret, *location, topn,
INT2FIX(1));
7563 ID id_write_name = pm_constant_id_lookup(scope_node, node->
write_name);
7564 PUSH_SEND_WITH_FLAG(ret, *location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
7566 if (safe_label != NULL && popped) PUSH_LABEL(ret, safe_label);
7567 PUSH_INSN(ret, *location, pop);
7568 if (safe_label != NULL && !popped) PUSH_LABEL(ret, safe_label);
7591 switch (PM_NODE_TYPE(node)) {
7592 case PM_FLOAT_NODE: {
7593 key = pm_static_literal_value(iseq, node, scope_node);
7597 key = (
FIXABLE(intptr) ?
LONG2FIX((
long) intptr) : rb_dbl2big(intptr));
7603 case PM_INTEGER_NODE:
7605 case PM_SOURCE_FILE_NODE:
7606 case PM_SOURCE_LINE_NODE:
7607 case PM_SYMBOL_NODE:
7609 key = pm_static_literal_value(iseq, node, scope_node);
7611 case PM_STRING_NODE: {
7613 key = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
7620 cdhash_aset_if_missing(dispatch, key, (
VALUE)label);
7636 DECL_ANCHOR(cond_seq);
7641 DECL_ANCHOR(body_seq);
7645 LABEL *end_label = NEW_LABEL(location.
line);
7656 if (PM_BRANCH_COVERAGE_P(iseq)) {
7657 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7658 branches = decl_branch_base(iseq, (
int) cast->
base.
node_id, &case_location,
"case");
7664 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7668 int clause_lineno = pm_node_line_number_cached((
const pm_node_t *) clause, scope_node);
7669 LABEL *label = NEW_LABEL(clause_lineno);
7670 PUSH_LABEL(body_seq, label);
7673 if (PM_BRANCH_COVERAGE_P(iseq)) {
7675 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7678 if (clause->statements != NULL) {
7679 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7682 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7685 PUSH_INSNL(body_seq, location, jump, end_label);
7690 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7693 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7695 PUSH_INSN(cond_seq, cond_location, putnil);
7696 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7697 PUSH_INSN1(cond_seq, cond_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
7698 PUSH_INSNL(cond_seq, cond_location, branchif, label);
7701 LABEL *next_label = NEW_LABEL(pm_node_line_number_cached(condition, scope_node));
7702 pm_compile_branch_condition(iseq, cond_seq, condition, label, next_label, scope_node);
7703 PUSH_LABEL(cond_seq, next_label);
7710 if (PM_BRANCH_COVERAGE_P(iseq)) {
7714 branch_location = case_location;
7721 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7729 PUSH_SYNTHETIC_PUTNIL(cond_seq, iseq);
7734 PUSH_INSNL(cond_seq, location, jump, end_label);
7735 PUSH_SEQ(ret, cond_seq);
7743 if (PM_BRANCH_COVERAGE_P(iseq)) {
7744 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7745 branches = decl_branch_base(iseq, (
int) cast->
base.
node_id, &case_location,
"case");
7750 LABEL *else_label = NEW_LABEL(location.
line);
7758 if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
7759 dispatch = cdhash_new(0);
7770 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7775 LABEL *label = NEW_LABEL(clause_location.
line);
7780 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7787 if (dispatch !=
Qundef) {
7788 dispatch = pm_compile_case_node_dispatch(iseq, dispatch, condition, label, scope_node);
7791 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7792 PUSH_INSN(cond_seq, condition_location, dup);
7793 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7794 PUSH_INSN1(cond_seq, condition_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
7797 if (PM_NODE_TYPE_P(condition, PM_STRING_NODE)) {
7799 VALUE value = parse_static_literal_string(iseq, scope_node, condition, &string->
unescaped);
7800 PUSH_INSN1(cond_seq, condition_location, putobject, value);
7803 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7806 PUSH_INSN1(cond_seq, condition_location, topn,
INT2FIX(1));
7807 PUSH_SEND_WITH_FLAG(cond_seq, condition_location, idEqq,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
7810 PUSH_INSNL(cond_seq, condition_location, branchif, label);
7817 PUSH_LABEL(body_seq, label);
7818 PUSH_INSN(body_seq, clause_location, pop);
7821 if (PM_BRANCH_COVERAGE_P(iseq)) {
7823 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7826 if (clause->statements != NULL) {
7827 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7830 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7833 PUSH_INSNL(body_seq, clause_location, jump, end_label);
7844 if (dispatch !=
Qundef) {
7845 PUSH_INSN(ret, location, dup);
7846 RB_OBJ_SET_SHAREABLE(dispatch);
7847 PUSH_INSN2(ret, location, opt_case_dispatch, dispatch, else_label);
7848 LABEL_REF(else_label);
7851 PUSH_SEQ(ret, cond_seq);
7855 PUSH_LABEL(ret, else_label);
7859 PUSH_INSN(ret, else_location, pop);
7862 if (PM_BRANCH_COVERAGE_P(iseq)) {
7864 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7868 PUSH_INSNL(ret, else_location, jump, end_label);
7871 PUSH_INSN(ret, location, pop);
7874 if (PM_BRANCH_COVERAGE_P(iseq)) {
7875 add_trace_branch_coverage(iseq, ret, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7878 if (!popped) PUSH_INSN(ret, location, putnil);
7879 PUSH_INSNL(ret, location, jump, end_label);
7883 PUSH_SEQ(ret, body_seq);
7884 PUSH_LABEL(ret, end_label);
7893 DECL_ANCHOR(body_seq);
7898 DECL_ANCHOR(cond_seq);
7902 LABEL *end_label = NEW_LABEL(location->
line);
7907 LABEL *else_label = NEW_LABEL(location->
line);
7915 if (PM_BRANCH_COVERAGE_P(iseq)) {
7916 case_location = pm_code_location(scope_node, (
const pm_node_t *) node);
7917 branches = decl_branch_base(iseq, (
int) node->
base.
node_id, &case_location,
"case");
7927 if (in_single_pattern) {
7928 PUSH_INSN(ret, *location, putnil);
7929 PUSH_INSN(ret, *location, putnil);
7930 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7931 PUSH_INSN(ret, *location, putnil);
7935 PUSH_INSN(ret, *location, putnil);
7944 RUBY_ASSERT(PM_NODE_TYPE_P(condition, PM_IN_NODE));
7951 PUSH_INSN(body_seq, in_location, putnil);
7954 LABEL *body_label = NEW_LABEL(in_location.
line);
7955 PUSH_LABEL(body_seq, body_label);
7956 PUSH_INSN1(body_seq, in_location, adjuststack,
INT2FIX(in_single_pattern ? 6 : 2));
7959 if (PM_BRANCH_COVERAGE_P(iseq)) {
7961 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"in", branches);
7968 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7971 PUSH_INSNL(body_seq, in_location, jump, end_label);
7972 LABEL *next_pattern_label = NEW_LABEL(pattern_location.
line);
7974 PUSH_INSN(cond_seq, pattern_location, dup);
7975 pm_compile_pattern(iseq, scope_node, in_node->
pattern, cond_seq, body_label, next_pattern_label, in_single_pattern,
true, 2);
7976 PUSH_LABEL(cond_seq, next_pattern_label);
7977 LABEL_UNREMOVABLE(next_pattern_label);
7986 PUSH_LABEL(cond_seq, else_label);
7987 PUSH_INSN(cond_seq, *location, pop);
7988 PUSH_INSN(cond_seq, *location, pop);
7991 if (PM_BRANCH_COVERAGE_P(iseq)) {
7993 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7996 PM_COMPILE_INTO_ANCHOR(cond_seq, (
const pm_node_t *) else_node);
7997 PUSH_INSNL(cond_seq, *location, jump, end_label);
7998 PUSH_INSN(cond_seq, *location, putnil);
7999 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8004 PUSH_LABEL(cond_seq, else_label);
8007 add_trace_branch_coverage(iseq, cond_seq, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
8009 if (in_single_pattern) {
8010 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, cond_seq, end_label, popped);
8013 PUSH_INSN1(cond_seq, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8015 PUSH_INSN1(cond_seq, *location, topn,
INT2FIX(2));
8016 PUSH_SEND(cond_seq, *location, id_core_raise,
INT2FIX(2));
8018 PUSH_INSN1(cond_seq, *location, adjuststack,
INT2FIX(3));
8019 if (!popped) PUSH_INSN(cond_seq, *location, putnil);
8020 PUSH_INSNL(cond_seq, *location, jump, end_label);
8021 PUSH_INSN1(cond_seq, *location, dupn,
INT2FIX(1));
8022 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8029 PUSH_SEQ(ret, cond_seq);
8030 PUSH_SEQ(ret, body_seq);
8031 PUSH_LABEL(ret, end_label);
8039 LABEL *retry_label = NULL;
8040 LABEL *retry_end_l = NULL;
8042 if (node->
block != NULL) {
8043 previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8044 ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
8046 retry_label = NEW_LABEL(location->
line);
8047 retry_end_l = NEW_LABEL(location->
line);
8049 PUSH_LABEL(ret, retry_label);
8052 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8055 PUSH_INSN(ret, *location, putself);
8056 int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
8058 if (node->
block != NULL) {
8060 pm_scope_node_init((
const pm_node_t *) node->
block, &next_scope_node, scope_node);
8062 ISEQ_COMPILE_DATA(iseq)->current_block = block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8063 pm_scope_node_destroy(&next_scope_node);
8070 const rb_iseq_t *local_iseq = body->local_iseq;
8074 int depth = get_lvar_level(iseq);
8076 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8077 flag |= VM_CALL_FORWARDING;
8078 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
8079 PUSH_GETLOCAL(ret, *location, mult_local.index, mult_local.level);
8081 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, 0, flag, NULL, block != NULL);
8082 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, block);
8084 if (popped) PUSH_INSN(ret, *location, pop);
8086 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8091 if (local_body->param.flags.has_lead) {
8093 for (
int i = 0; i < local_body->param.lead_num; i++) {
8094 int idx = local_body->local_table_size - i;
8095 PUSH_GETLOCAL(args, *location, idx, depth);
8097 argc += local_body->param.lead_num;
8100 if (local_body->param.flags.has_opt) {
8102 for (
int j = 0; j < local_body->param.opt_num; j++) {
8103 int idx = local_body->local_table_size - (argc + j);
8104 PUSH_GETLOCAL(args, *location, idx, depth);
8106 argc += local_body->param.opt_num;
8109 if (local_body->param.flags.has_rest) {
8111 int idx = local_body->local_table_size - local_body->param.rest_start;
8112 PUSH_GETLOCAL(args, *location, idx, depth);
8113 PUSH_INSN1(args, *location, splatarray,
Qfalse);
8115 argc = local_body->param.rest_start + 1;
8116 flag |= VM_CALL_ARGS_SPLAT;
8119 if (local_body->param.flags.has_post) {
8121 int post_len = local_body->param.post_num;
8122 int post_start = local_body->param.post_start;
8125 for (; j < post_len; j++) {
8126 int idx = local_body->local_table_size - (post_start + j);
8127 PUSH_GETLOCAL(args, *location, idx, depth);
8130 if (local_body->param.flags.has_rest) {
8132 PUSH_INSN1(args, *location, newarray,
INT2FIX(j));
8133 PUSH_INSN(args, *location, concatarray);
8136 argc = post_len + post_start;
8140 const struct rb_iseq_param_keyword *
const local_keyword = local_body->param.keyword;
8141 if (local_body->param.flags.has_kw) {
8142 int local_size = local_body->local_table_size;
8145 PUSH_INSN1(args, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8147 if (local_body->param.flags.has_kwrest) {
8148 int idx = local_body->local_table_size - local_keyword->rest_start;
8149 PUSH_GETLOCAL(args, *location, idx, depth);
8151 PUSH_SEND(args, *location, rb_intern(
"dup"),
INT2FIX(0));
8154 PUSH_INSN1(args, *location, newhash,
INT2FIX(0));
8157 for (; i < local_keyword->num; ++i) {
8158 ID id = local_keyword->table[i];
8159 int idx = local_size - get_local_var_idx(local_iseq,
id);
8163 PUSH_INSN1(args, *location, putobject, operand);
8166 PUSH_GETLOCAL(args, *location, idx, depth);
8169 PUSH_SEND(args, *location, id_core_hash_merge_ptr,
INT2FIX(i * 2 + 1));
8170 flag |= VM_CALL_KW_SPLAT| VM_CALL_KW_SPLAT_MUT;
8172 else if (local_body->param.flags.has_kwrest) {
8173 int idx = local_body->local_table_size - local_keyword->rest_start;
8174 PUSH_GETLOCAL(args, *location, idx, depth);
8176 flag |= VM_CALL_KW_SPLAT;
8179 PUSH_SEQ(ret, args);
8182 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flag, NULL, block != NULL);
8183 PUSH_INSN2(ret, *location, invokesuper, callinfo, block);
8186 if (node->
block != NULL) {
8187 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8188 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, block, retry_end_l);
8189 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8192 if (popped) PUSH_INSN(ret, *location, pop);
8198 LABEL *matched_label = NEW_LABEL(location->
line);
8199 LABEL *unmatched_label = NEW_LABEL(location->
line);
8200 LABEL *done_label = NEW_LABEL(location->
line);
8204 PUSH_INSN(ret, *location, putnil);
8205 PUSH_INSN(ret, *location, putnil);
8206 PUSH_INSN1(ret, *location, putobject,
Qfalse);
8207 PUSH_INSN(ret, *location, putnil);
8208 PUSH_INSN(ret, *location, putnil);
8212 PM_COMPILE_NOT_POPPED(node->
value);
8216 PUSH_INSN(ret, *location, dup);
8223 pm_compile_pattern(iseq, scope_node, node->
pattern, ret, matched_label, unmatched_label,
true,
true, 2);
8228 PUSH_LABEL(ret, unmatched_label);
8229 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, ret, done_label, popped);
8233 PUSH_LABEL(ret, matched_label);
8234 PUSH_INSN1(ret, *location, adjuststack,
INT2FIX(6));
8235 if (!popped) PUSH_INSN(ret, *location, putnil);
8236 PUSH_INSNL(ret, *location, jump, done_label);
8238 PUSH_LABEL(ret, done_label);
8244 LABEL *fail_label = NEW_LABEL(location->
line);
8245 LABEL *end_label = NEW_LABEL(location->
line);
8256 PUSH_INSN1(ret, *location, getglobal, operand);
8259 PUSH_INSN(ret, *location, dup);
8260 PUSH_INSNL(ret, *location, branchunless, fail_label);
8266 if (targets_count == 1) {
8268 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8275 PUSH_INSN1(ret, *location, putobject, operand);
8278 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8279 PUSH_LABEL(ret, fail_label);
8280 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8281 if (popped) PUSH_INSN(ret, *location, pop);
8285 DECL_ANCHOR(fail_anchor);
8289 for (
size_t targets_index = 0; targets_index < targets_count; targets_index++) {
8291 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8296 if (((
size_t) targets_index) < (targets_count - 1)) {
8297 PUSH_INSN(ret, *location, dup);
8302 PUSH_INSN1(ret, *location, putobject, operand);
8305 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8306 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8308 PUSH_INSN(fail_anchor, *location, putnil);
8309 PUSH_SETLOCAL(fail_anchor, *location, index.index, index.level);
8313 PUSH_INSNL(ret, *location, jump, end_label);
8317 PUSH_LABEL(ret, fail_label);
8318 PUSH_INSN(ret, *location, pop);
8319 PUSH_SEQ(ret, fail_anchor);
8322 PUSH_LABEL(ret, end_label);
8323 if (popped) PUSH_INSN(ret, *location, pop);
8329 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
8330 LABEL *splabel = NEW_LABEL(0);
8331 PUSH_LABEL(ret, splabel);
8337 PUSH_INSN(ret, *location, putnil);
8339 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8341 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8342 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8344 PUSH_ADJUST_RESTORE(ret, splabel);
8345 if (!popped) PUSH_INSN(ret, *location, putnil);
8347 else if (ISEQ_COMPILE_DATA(iseq)->end_label && can_add_ensure_iseq(iseq)) {
8348 LABEL *splabel = NEW_LABEL(0);
8350 PUSH_LABEL(ret, splabel);
8351 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8357 PUSH_INSN(ret, *location, putnil);
8360 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8361 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
8362 PUSH_ADJUST_RESTORE(ret, splabel);
8363 splabel->unremovable = FALSE;
8365 if (!popped) PUSH_INSN(ret, *location, putnil);
8369 unsigned long throw_flag = 0;
8372 if (!ISEQ_COMPILE_DATA(ip)) {
8377 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
8378 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8382 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8385 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8386 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8390 ip = ISEQ_BODY(ip)->parent_iseq;
8398 PUSH_INSN(ret, *location, putnil);
8401 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_NEXT));
8402 if (popped) PUSH_INSN(ret, *location, pop);
8405 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8413 if (ISEQ_COMPILE_DATA(iseq)->redo_label && can_add_ensure_iseq(iseq)) {
8414 LABEL *splabel = NEW_LABEL(0);
8416 PUSH_LABEL(ret, splabel);
8417 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8418 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8420 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
8421 PUSH_ADJUST_RESTORE(ret, splabel);
8422 if (!popped) PUSH_INSN(ret, *location, putnil);
8424 else if (ISEQ_BODY(iseq)->
type != ISEQ_TYPE_EVAL && ISEQ_COMPILE_DATA(iseq)->start_label && can_add_ensure_iseq(iseq)) {
8425 LABEL *splabel = NEW_LABEL(0);
8427 PUSH_LABEL(ret, splabel);
8428 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8429 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8431 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8432 PUSH_ADJUST_RESTORE(ret, splabel);
8433 if (!popped) PUSH_INSN(ret, *location, putnil);
8439 if (!ISEQ_COMPILE_DATA(ip)) {
8444 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8447 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8450 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8451 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8455 ip = ISEQ_BODY(ip)->parent_iseq;
8459 PUSH_INSN(ret, *location, putnil);
8460 PUSH_INSN1(ret, *location,
throw,
INT2FIX(VM_THROW_NO_ESCAPE_FLAG | TAG_REDO));
8461 if (popped) PUSH_INSN(ret, *location, pop);
8464 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8472 iseq_set_exception_local_table(iseq);
8476 LABEL *exception_match_label = NEW_LABEL(location->
line);
8477 LABEL *rescue_end_label = NEW_LABEL(location->
line);
8487 if (exceptions->
size > 0) {
8488 for (
size_t index = 0; index < exceptions->
size; index++) {
8489 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8490 PM_COMPILE(exceptions->
nodes[index]);
8491 int checkmatch_flags = VM_CHECKMATCH_TYPE_RESCUE;
8492 if (PM_NODE_TYPE_P(exceptions->
nodes[index], PM_SPLAT_NODE)) {
8493 checkmatch_flags |= VM_CHECKMATCH_ARRAY;
8495 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(checkmatch_flags));
8496 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8500 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8502 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
8503 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8508 PUSH_INSNL(ret, *location, jump, rescue_end_label);
8513 PUSH_LABEL(ret, exception_match_label);
8520 DECL_ANCHOR(writes);
8521 DECL_ANCHOR(cleanup);
8523 pm_compile_target_node(iseq, node->
reference, ret, writes, cleanup, scope_node, NULL);
8524 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8526 PUSH_SEQ(ret, writes);
8527 PUSH_SEQ(ret, cleanup);
8537 LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
8538 ISEQ_COMPILE_DATA(iseq)->end_label = NULL;
8543 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
8546 PUSH_INSN(ret, *location, putnil);
8549 PUSH_INSN(ret, *location, leave);
8555 PUSH_LABEL(ret, rescue_end_label);
8560 PUSH_GETLOCAL(ret, *location, 1, 0);
8568 enum rb_iseq_type
type = ISEQ_BODY(iseq)->type;
8572 enum rb_iseq_type parent_type = ISEQ_BODY(parent_iseq)->type;
8573 while (parent_type == ISEQ_TYPE_RESCUE || parent_type == ISEQ_TYPE_ENSURE) {
8574 if (!(parent_iseq = ISEQ_BODY(parent_iseq)->parent_iseq))
break;
8575 parent_type = ISEQ_BODY(parent_iseq)->type;
8578 switch (parent_type) {
8580 case ISEQ_TYPE_MAIN:
8582 rb_warn(
"argument of top-level return is ignored");
8584 if (parent_iseq == iseq) {
8585 type = ISEQ_TYPE_METHOD;
8592 if (
type == ISEQ_TYPE_METHOD) {
8593 splabel = NEW_LABEL(0);
8594 PUSH_LABEL(ret, splabel);
8595 PUSH_ADJUST(ret, *location, 0);
8598 if (arguments != NULL) {
8599 PM_COMPILE_NOT_POPPED((
const pm_node_t *) arguments);
8602 PUSH_INSN(ret, *location, putnil);
8605 if (
type == ISEQ_TYPE_METHOD && can_add_ensure_iseq(iseq)) {
8606 pm_add_ensure_iseq(ret, iseq, 1, scope_node);
8608 PUSH_INSN(ret, *location, leave);
8609 PUSH_ADJUST_RESTORE(ret, splabel);
8610 if (!popped) PUSH_INSN(ret, *location, putnil);
8613 PUSH_INSN1(ret, *location,
throw,
INT2FIX(TAG_RETURN));
8614 if (popped) PUSH_INSN(ret, *location, pop);
8623 LABEL *retry_label = NEW_LABEL(location->
line);
8624 LABEL *retry_end_l = NEW_LABEL(location->
line);
8626 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8628 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NULL;
8630 PUSH_LABEL(ret, retry_label);
8631 PUSH_INSN(ret, *location, putself);
8635 int argc = pm_setup_args(node->
arguments, node->
block, &flags, &keywords, iseq, ret, scope_node, location);
8636 bool is_forwardable = (node->
arguments != NULL) && PM_NODE_FLAG_P(node->
arguments, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING);
8637 flags |= VM_CALL_SUPER | VM_CALL_FCALL;
8639 if (node->
block && PM_NODE_TYPE_P(node->
block, PM_BLOCK_NODE)) {
8641 pm_scope_node_init(node->
block, &next_scope_node, scope_node);
8643 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8644 pm_scope_node_destroy(&next_scope_node);
8648 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8651 if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
8652 PUSH_INSN(args, *location, splatkw);
8655 PUSH_SEQ(ret, args);
8656 if (is_forwardable && ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8657 flags |= VM_CALL_FORWARDING;
8660 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8661 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, current_block);
8666 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8667 PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
8672 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8674 if (popped) PUSH_INSN(ret, *location, pop);
8675 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8676 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);
8682 switch (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
type) {
8684 case ISEQ_TYPE_MAIN:
8685 case ISEQ_TYPE_CLASS:
8686 COMPILE_ERROR(iseq, location->
line,
"Invalid yield");
8696 argc = pm_setup_args(node->
arguments, NULL, &flags, &keywords, iseq, ret, scope_node, location);
8699 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, FALSE);
8700 PUSH_INSN1(ret, *location, invokeblock, callinfo);
8702 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8703 if (popped) PUSH_INSN(ret, *location, pop);
8706 for (
const rb_iseq_t *tmp_iseq = iseq; tmp_iseq != ISEQ_BODY(iseq)->local_iseq; level++) {
8707 tmp_iseq = ISEQ_BODY(tmp_iseq)->parent_iseq;
8710 if (level > 0) access_outer_variables(iseq, level, rb_intern(
"yield"),
true);
8727 int lineno = (int) location.
line;
8729 if (PM_NODE_TYPE_P(node, PM_BEGIN_NODE) && (((
const pm_begin_node_t *) node)->statements == NULL) && (((
const pm_begin_node_t *) node)->rescue_clause != NULL)) {
8734 lineno = (int) PM_NODE_START_LINE_COLUMN(((
const pm_begin_node_t *) node)->rescue_clause).line;
8737 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_NEWLINE) && ISEQ_COMPILE_DATA(iseq)->last_line != lineno) {
8743 ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8744 if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8745 event |= RUBY_EVENT_COVERAGE_LINE;
8747 PUSH_TRACE(ret, event);
8750 switch (PM_NODE_TYPE(node)) {
8751 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
8756 case PM_ALIAS_METHOD_NODE:
8759 pm_compile_alias_method_node(iseq, (
const pm_alias_method_node_t *) node, &location, ret, popped, scope_node);
8764 pm_compile_and_node(iseq, (
const pm_and_node_t *) node, &location, ret, popped, scope_node);
8766 case PM_ARGUMENTS_NODE: {
8776 if (elements->
size == 1) {
8779 PM_COMPILE(elements->
nodes[0]);
8782 pm_compile_array_node(iseq, (
const pm_node_t *) cast, elements, &location, ret, popped, scope_node);
8786 case PM_ARRAY_NODE: {
8790 pm_compile_array_node(iseq, (
const pm_node_t *) cast, &cast->elements, &location, ret, popped, scope_node);
8793 case PM_ASSOC_NODE: {
8801 PM_COMPILE(cast->
key);
8802 PM_COMPILE(cast->
value);
8806 case PM_ASSOC_SPLAT_NODE: {
8814 if (cast->
value != NULL) {
8815 PM_COMPILE(cast->
value);
8818 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
8819 PUSH_GETLOCAL(ret, location, index.index, index.level);
8824 case PM_BACK_REFERENCE_READ_NODE: {
8829 VALUE backref = pm_compile_back_reference_ref(scope_node, cast);
8831 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), backref);
8835 case PM_BEGIN_NODE: {
8843 pm_compile_ensure(iseq, cast, &location, ret, popped, scope_node);
8847 pm_compile_rescue(iseq, cast, &location, ret, popped, scope_node);
8856 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8861 case PM_BLOCK_ARGUMENT_NODE: {
8871 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
8872 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(local_index.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(local_index.level));
8882 pm_compile_break_node(iseq, (
const pm_break_node_t *) node, &location, ret, popped, scope_node);
8893 pm_compile_call_node(iseq, (
const pm_call_node_t *) node, ret, popped, scope_node);
8895 case PM_CALL_AND_WRITE_NODE: {
8899 pm_compile_call_and_or_write_node(iseq,
true, cast->
receiver, cast->
value, cast->
write_name, cast->
read_name, PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION), &location, ret, popped, scope_node);
8902 case PM_CALL_OR_WRITE_NODE: {
8906 pm_compile_call_and_or_write_node(iseq,
false, cast->
receiver, cast->
value, cast->
write_name, cast->
read_name, PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION), &location, ret, popped, scope_node);
8909 case PM_CALL_OPERATOR_WRITE_NODE:
8924 pm_compile_case_node(iseq, (
const pm_case_node_t *) node, &location, ret, popped, scope_node);
8926 case PM_CASE_MATCH_NODE:
8935 pm_compile_case_match_node(iseq, (
const pm_case_match_node_t *) node, &location, ret, popped, scope_node);
8937 case PM_CLASS_NODE: {
8942 ID class_id = pm_constant_id_lookup(scope_node, cast->
name);
8943 VALUE class_name =
rb_str_freeze(rb_sprintf(
"<class:%"PRIsVALUE
">", rb_id2str(class_id)));
8946 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
8948 const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(&next_scope_node, class_name, ISEQ_TYPE_CLASS, location.
line);
8949 pm_scope_node_destroy(&next_scope_node);
8952 const int flags = VM_DEFINECLASS_TYPE_CLASS |
8953 (cast->
superclass ? VM_DEFINECLASS_FLAG_HAS_SUPERCLASS : 0) |
8954 pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
8960 PUSH_INSN(ret, location, putnil);
8965 PUSH_INSN3(ret, location, defineclass, operand, class_iseq,
INT2FIX(flags));
8969 if (popped) PUSH_INSN(ret, location, pop);
8972 case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
8976 LABEL *end_label = NEW_LABEL(location.
line);
8978 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8981 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8982 if (!popped) PUSH_INSN(ret, location, dup);
8984 PUSH_INSNL(ret, location, branchunless, end_label);
8985 if (!popped) PUSH_INSN(ret, location, pop);
8987 PM_COMPILE_NOT_POPPED(cast->
value);
8988 if (!popped) PUSH_INSN(ret, location, dup);
8990 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8991 PUSH_LABEL(ret, end_label);
8995 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
9000 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9003 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9004 PM_COMPILE_NOT_POPPED(cast->
value);
9007 int flags = VM_CALL_ARGS_SIMPLE;
9008 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9010 if (!popped) PUSH_INSN(ret, location, dup);
9011 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9015 case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
9019 LABEL *end_label = NEW_LABEL(location.
line);
9020 LABEL *start_label = NEW_LABEL(location.
line);
9022 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9025 PUSH_INSN(ret, location, putnil);
9026 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name,
Qtrue);
9027 PUSH_INSNL(ret, location, branchunless, start_label);
9029 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9030 if (!popped) PUSH_INSN(ret, location, dup);
9032 PUSH_INSNL(ret, location, branchif, end_label);
9033 if (!popped) PUSH_INSN(ret, location, pop);
9035 PUSH_LABEL(ret, start_label);
9036 PM_COMPILE_NOT_POPPED(cast->
value);
9037 if (!popped) PUSH_INSN(ret, location, dup);
9039 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9040 PUSH_LABEL(ret, end_label);
9044 case PM_CLASS_VARIABLE_READ_NODE: {
9049 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9050 PUSH_INSN2(ret, location, getclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9054 case PM_CLASS_VARIABLE_WRITE_NODE: {
9058 PM_COMPILE_NOT_POPPED(cast->
value);
9059 if (!popped) PUSH_INSN(ret, location, dup);
9061 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9062 PUSH_INSN2(ret, location, setclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9066 case PM_CONSTANT_PATH_NODE: {
9071 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache && ((parts = pm_constant_path_parts(node, scope_node)) !=
Qnil)) {
9072 ISEQ_BODY(iseq)->ic_size++;
9073 RB_OBJ_SET_SHAREABLE(parts);
9074 PUSH_INSN1(ret, location, opt_getconstant_path, parts);
9077 DECL_ANCHOR(prefix);
9080 pm_compile_constant_path(iseq, node, prefix, body, popped, scope_node);
9081 if (LIST_INSN_SIZE_ZERO(prefix)) {
9082 PUSH_INSN(ret, location, putnil);
9085 PUSH_SEQ(ret, prefix);
9088 PUSH_SEQ(ret, body);
9091 if (popped) PUSH_INSN(ret, location, pop);
9094 case PM_CONSTANT_PATH_AND_WRITE_NODE: {
9098 pm_compile_constant_path_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9101 case PM_CONSTANT_PATH_OR_WRITE_NODE: {
9105 pm_compile_constant_path_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9108 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
9112 pm_compile_constant_path_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9115 case PM_CONSTANT_PATH_WRITE_NODE: {
9119 pm_compile_constant_path_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9122 case PM_CONSTANT_READ_NODE: {
9128 pm_compile_constant_read(iseq, name, &cast->
base.
location, location.
node_id, ret, scope_node);
9129 if (popped) PUSH_INSN(ret, location, pop);
9133 case PM_CONSTANT_AND_WRITE_NODE: {
9137 pm_compile_constant_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9140 case PM_CONSTANT_OR_WRITE_NODE: {
9144 pm_compile_constant_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9147 case PM_CONSTANT_OPERATOR_WRITE_NODE: {
9151 pm_compile_constant_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9154 case PM_CONSTANT_WRITE_NODE: {
9158 pm_compile_constant_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9168 ID method_name = pm_constant_id_lookup(scope_node, cast->
name);
9171 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9173 rb_iseq_t *method_iseq = NEW_ISEQ(&next_scope_node, rb_id2str(method_name), ISEQ_TYPE_METHOD, location.
line);
9174 pm_scope_node_destroy(&next_scope_node);
9177 PM_COMPILE_NOT_POPPED(cast->
receiver);
9178 PUSH_INSN2(ret, location, definesmethod,
ID2SYM(method_name), method_iseq);
9181 PUSH_INSN2(ret, location, definemethod,
ID2SYM(method_name), method_iseq);
9186 PUSH_INSN1(ret, location, putobject,
ID2SYM(method_name));
9191 case PM_DEFINED_NODE: {
9195 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
false);
9198 case PM_EMBEDDED_STATEMENTS_NODE: {
9207 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9210 if (popped) PUSH_INSN(ret, location, pop);
9213 case PM_EMBEDDED_VARIABLE_NODE: {
9220 case PM_FALSE_NODE: {
9224 PUSH_INSN1(ret, location, putobject,
Qfalse);
9228 case PM_ENSURE_NODE: {
9237 case PM_ELSE_NODE: {
9246 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9251 case PM_FLIP_FLOP_NODE: {
9256 LABEL *final_label = NEW_LABEL(location.
line);
9257 LABEL *then_label = NEW_LABEL(location.
line);
9258 LABEL *else_label = NEW_LABEL(location.
line);
9260 pm_compile_flip_flop(cast, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
9262 PUSH_LABEL(ret, then_label);
9263 PUSH_INSN1(ret, location, putobject,
Qtrue);
9264 PUSH_INSNL(ret, location, jump, final_label);
9265 PUSH_LABEL(ret, else_label);
9266 PUSH_INSN1(ret, location, putobject,
Qfalse);
9267 PUSH_LABEL(ret, final_label);
9271 case PM_FLOAT_NODE: {
9276 PUSH_INSN1(ret, location, putobject, operand);
9285 LABEL *retry_label = NEW_LABEL(location.
line);
9286 LABEL *retry_end_l = NEW_LABEL(location.
line);
9289 PUSH_LABEL(ret, retry_label);
9295 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9297 const rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location.
line);
9298 pm_scope_node_destroy(&next_scope_node);
9300 const rb_iseq_t *prev_block = ISEQ_COMPILE_DATA(iseq)->current_block;
9301 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
9305 PUSH_SEND_WITH_BLOCK(ret, location, idEach,
INT2FIX(0), child_iseq);
9306 pm_compile_retry_end_label(iseq, ret, retry_end_l);
9308 if (popped) PUSH_INSN(ret, location, pop);
9309 ISEQ_COMPILE_DATA(iseq)->current_block = prev_block;
9310 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
9313 case PM_FORWARDING_ARGUMENTS_NODE:
9314 rb_bug(
"Cannot compile a ForwardingArgumentsNode directly\n");
9316 case PM_FORWARDING_SUPER_NODE:
9324 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
9328 LABEL *end_label = NEW_LABEL(location.
line);
9331 PUSH_INSN1(ret, location, getglobal, name);
9332 if (!popped) PUSH_INSN(ret, location, dup);
9334 PUSH_INSNL(ret, location, branchunless, end_label);
9335 if (!popped) PUSH_INSN(ret, location, pop);
9337 PM_COMPILE_NOT_POPPED(cast->
value);
9338 if (!popped) PUSH_INSN(ret, location, dup);
9340 PUSH_INSN1(ret, location, setglobal, name);
9341 PUSH_LABEL(ret, end_label);
9345 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
9351 PUSH_INSN1(ret, location, getglobal, name);
9352 PM_COMPILE_NOT_POPPED(cast->
value);
9355 int flags = VM_CALL_ARGS_SIMPLE;
9356 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9358 if (!popped) PUSH_INSN(ret, location, dup);
9359 PUSH_INSN1(ret, location, setglobal, name);
9363 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
9367 LABEL *set_label = NEW_LABEL(location.
line);
9368 LABEL *end_label = NEW_LABEL(location.
line);
9370 PUSH_INSN(ret, location, putnil);
9373 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name,
Qtrue);
9374 PUSH_INSNL(ret, location, branchunless, set_label);
9376 PUSH_INSN1(ret, location, getglobal, name);
9377 if (!popped) PUSH_INSN(ret, location, dup);
9379 PUSH_INSNL(ret, location, branchif, end_label);
9380 if (!popped) PUSH_INSN(ret, location, pop);
9382 PUSH_LABEL(ret, set_label);
9383 PM_COMPILE_NOT_POPPED(cast->
value);
9384 if (!popped) PUSH_INSN(ret, location, dup);
9386 PUSH_INSN1(ret, location, setglobal, name);
9387 PUSH_LABEL(ret, end_label);
9391 case PM_GLOBAL_VARIABLE_READ_NODE: {
9397 PUSH_INSN1(ret, location, getglobal, name);
9398 if (popped) PUSH_INSN(ret, location, pop);
9402 case PM_GLOBAL_VARIABLE_WRITE_NODE: {
9406 PM_COMPILE_NOT_POPPED(cast->
value);
9407 if (!popped) PUSH_INSN(ret, location, dup);
9409 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9410 PUSH_INSN1(ret, location, setglobal,
ID2SYM(name));
9414 case PM_HASH_NODE: {
9420 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9428 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
9431 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9432 PUSH_INSN1(ret, location, duphash, value);
9453 for (
size_t index = 0; index < elements->
size; index++) {
9454 PM_COMPILE_POPPED(elements->
nodes[index]);
9458 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9474 pm_compile_conditional(iseq, &location, PM_IF_NODE, (
const pm_node_t *) cast, cast->statements, cast->subsequent, cast->predicate, ret, popped, scope_node);
9477 case PM_IMAGINARY_NODE: {
9482 PUSH_INSN1(ret, location, putobject, operand);
9486 case PM_IMPLICIT_NODE: {
9496 PM_COMPILE(cast->
value);
9502 rb_bug(
"Should not ever enter an in node directly");
9505 case PM_INDEX_OPERATOR_WRITE_NODE: {
9509 pm_compile_index_operator_write_node(iseq, cast, &location, ret, popped, scope_node);
9512 case PM_INDEX_AND_WRITE_NODE: {
9516 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9519 case PM_INDEX_OR_WRITE_NODE: {
9523 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9526 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
9530 LABEL *end_label = NEW_LABEL(location.
line);
9532 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9535 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9536 if (!popped) PUSH_INSN(ret, location, dup);
9538 PUSH_INSNL(ret, location, branchunless, end_label);
9539 if (!popped) PUSH_INSN(ret, location, pop);
9541 PM_COMPILE_NOT_POPPED(cast->
value);
9542 if (!popped) PUSH_INSN(ret, location, dup);
9544 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9545 PUSH_LABEL(ret, end_label);
9549 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
9554 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9557 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9558 PM_COMPILE_NOT_POPPED(cast->
value);
9561 int flags = VM_CALL_ARGS_SIMPLE;
9562 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9564 if (!popped) PUSH_INSN(ret, location, dup);
9565 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9569 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
9573 LABEL *end_label = NEW_LABEL(location.
line);
9575 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9578 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9579 if (!popped) PUSH_INSN(ret, location, dup);
9581 PUSH_INSNL(ret, location, branchif, end_label);
9582 if (!popped) PUSH_INSN(ret, location, pop);
9584 PM_COMPILE_NOT_POPPED(cast->
value);
9585 if (!popped) PUSH_INSN(ret, location, dup);
9587 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9588 PUSH_LABEL(ret, end_label);
9592 case PM_INSTANCE_VARIABLE_READ_NODE: {
9597 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9598 PUSH_INSN2(ret, location, getinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9602 case PM_INSTANCE_VARIABLE_WRITE_NODE: {
9606 PM_COMPILE_NOT_POPPED(cast->
value);
9607 if (!popped) PUSH_INSN(ret, location, dup);
9609 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9610 PUSH_INSN2(ret, location, setinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9614 case PM_INTEGER_NODE: {
9619 PUSH_INSN1(ret, location, putobject, operand);
9623 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
9626 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9628 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9629 PUSH_INSN1(ret, location, putobject, regexp);
9636 PUSH_INSN1(ret, location, getglobal,
rb_id2sym(idLASTLINE));
9637 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9638 if (popped) PUSH_INSN(ret, location, pop);
9642 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
9645 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ONCE)) {
9646 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9648 int ise_index = ISEQ_BODY(iseq)->ise_size++;
9651 pm_scope_node_init(node, &next_scope_node, scope_node);
9653 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, location.
line);
9654 pm_scope_node_destroy(&next_scope_node);
9656 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
9657 PUSH_INSN2(ret, location, once, block_iseq,
INT2FIX(ise_index));
9658 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9660 if (popped) PUSH_INSN(ret, location, pop);
9664 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9666 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9667 PUSH_INSN1(ret, location, putobject, regexp);
9672 if (popped) PUSH_INSN(ret, location, pop);
9677 case PM_INTERPOLATED_STRING_NODE: {
9680 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9682 VALUE string = pm_static_literal_value(iseq, node, scope_node);
9684 if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN)) {
9685 PUSH_INSN1(ret, location, putobject,
string);
9687 else if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE)) {
9688 PUSH_INSN1(ret, location, dupstring,
string);
9691 PUSH_INSN1(ret, location, dupchilledstring,
string);
9697 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL, PM_NODE_FLAG_P(cast, PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE), PM_NODE_FLAG_P(cast, PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN));
9698 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9699 if (popped) PUSH_INSN(ret, location, pop);
9704 case PM_INTERPOLATED_SYMBOL_NODE: {
9708 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL,
false,
false);
9711 PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9715 PUSH_INSN(ret, location, intern);
9718 PUSH_INSN(ret, location, pop);
9723 case PM_INTERPOLATED_X_STRING_NODE: {
9728 PUSH_INSN(ret, location, putself);
9730 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret,
false, scope_node, NULL, NULL,
false,
false);
9731 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9733 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
9734 if (popped) PUSH_INSN(ret, location, pop);
9738 case PM_IT_LOCAL_VARIABLE_READ_NODE: {
9745 while (current_scope_node) {
9746 if (current_scope_node->parameters && PM_NODE_TYPE_P(current_scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
9747 PUSH_GETLOCAL(ret, location, current_scope_node->local_table_for_iseq_size, level);
9751 current_scope_node = current_scope_node->previous;
9754 rb_bug(
"Local `it` does not exist");
9759 case PM_KEYWORD_HASH_NODE: {
9767 PM_COMPILE(element);
9770 if (!popped) PUSH_INSN1(ret, location, newhash,
INT2FIX(elements->
size * 2));
9773 case PM_LAMBDA_NODE: {
9779 pm_scope_node_init(node, &next_scope_node, scope_node);
9781 int opening_lineno = pm_location_line_number_cached(&cast->
opening_loc, scope_node);
9782 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, opening_lineno);
9783 pm_scope_node_destroy(&next_scope_node);
9786 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9787 PUSH_CALL_WITH_BLOCK(ret, location, idLambda, argc, block);
9790 if (popped) PUSH_INSN(ret, location, pop);
9793 case PM_LOCAL_VARIABLE_AND_WRITE_NODE: {
9797 LABEL *end_label = NEW_LABEL(location.
line);
9800 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9801 if (!popped) PUSH_INSN(ret, location, dup);
9803 PUSH_INSNL(ret, location, branchunless, end_label);
9804 if (!popped) PUSH_INSN(ret, location, pop);
9806 PM_COMPILE_NOT_POPPED(cast->
value);
9807 if (!popped) PUSH_INSN(ret, location, dup);
9809 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9810 PUSH_LABEL(ret, end_label);
9814 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
9820 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9822 PM_COMPILE_NOT_POPPED(cast->
value);
9825 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
9827 if (!popped) PUSH_INSN(ret, location, dup);
9828 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9832 case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
9837 LABEL *set_label = NEW_LABEL(location.
line);
9838 LABEL *end_label = NEW_LABEL(location.
line);
9840 PUSH_INSN1(ret, location, putobject,
Qtrue);
9841 PUSH_INSNL(ret, location, branchunless, set_label);
9844 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9845 if (!popped) PUSH_INSN(ret, location, dup);
9847 PUSH_INSNL(ret, location, branchif, end_label);
9848 if (!popped) PUSH_INSN(ret, location, pop);
9850 PUSH_LABEL(ret, set_label);
9851 PM_COMPILE_NOT_POPPED(cast->
value);
9852 if (!popped) PUSH_INSN(ret, location, dup);
9854 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9855 PUSH_LABEL(ret, end_label);
9859 case PM_LOCAL_VARIABLE_READ_NODE: {
9865 PUSH_GETLOCAL(ret, location, index.index, index.level);
9870 case PM_LOCAL_VARIABLE_WRITE_NODE: {
9874 PM_COMPILE_NOT_POPPED(cast->
value);
9875 if (!popped) PUSH_INSN(ret, location, dup);
9878 PUSH_SETLOCAL(ret, location, index.index, index.level);
9881 case PM_MATCH_LAST_LINE_NODE: {
9884 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9886 PUSH_INSN1(ret, location, putobject, regexp);
9888 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9889 if (popped) PUSH_INSN(ret, location, pop);
9893 case PM_MATCH_PREDICATE_NODE: {
9900 PUSH_INSN(ret, location, putnil);
9903 PM_COMPILE_NOT_POPPED(cast->
value);
9904 PUSH_INSN(ret, location, dup);
9908 LABEL *matched_label = NEW_LABEL(location.
line);
9909 LABEL *unmatched_label = NEW_LABEL(location.
line);
9910 LABEL *done_label = NEW_LABEL(location.
line);
9911 pm_compile_pattern(iseq, scope_node, cast->
pattern, ret, matched_label, unmatched_label,
false,
true, 2);
9915 PUSH_LABEL(ret, unmatched_label);
9916 PUSH_INSN(ret, location, pop);
9917 PUSH_INSN(ret, location, pop);
9919 if (!popped) PUSH_INSN1(ret, location, putobject,
Qfalse);
9920 PUSH_INSNL(ret, location, jump, done_label);
9921 PUSH_INSN(ret, location, putnil);
9925 PUSH_LABEL(ret, matched_label);
9926 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(2));
9927 if (!popped) PUSH_INSN1(ret, location, putobject,
Qtrue);
9928 PUSH_INSNL(ret, location, jump, done_label);
9930 PUSH_LABEL(ret, done_label);
9933 case PM_MATCH_REQUIRED_NODE:
9947 case PM_MATCH_WRITE_NODE:
9956 pm_compile_match_write_node(iseq, (
const pm_match_write_node_t *) node, &location, ret, popped, scope_node);
9958 case PM_ERROR_RECOVERY_NODE:
9959 rb_bug(
"A pm_error_recovery_node_t should not exist in prism's AST.");
9961 case PM_MODULE_NODE: {
9966 ID module_id = pm_constant_id_lookup(scope_node, cast->
name);
9967 VALUE module_name =
rb_str_freeze(rb_sprintf(
"<module:%"PRIsVALUE
">", rb_id2str(module_id)));
9970 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9972 const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&next_scope_node, module_name, ISEQ_TYPE_CLASS, location.
line);
9973 pm_scope_node_destroy(&next_scope_node);
9975 const int flags = VM_DEFINECLASS_TYPE_MODULE | pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
9976 PUSH_INSN(ret, location, putnil);
9977 PUSH_INSN3(ret, location, defineclass,
ID2SYM(module_id), module_iseq,
INT2FIX(flags));
9980 if (popped) PUSH_INSN(ret, location, pop);
9983 case PM_REQUIRED_PARAMETER_NODE: {
9989 PUSH_SETLOCAL(ret, location, index.index, index.level);
9992 case PM_MULTI_WRITE_NODE: {
10003 DECL_ANCHOR(writes);
10004 DECL_ANCHOR(cleanup);
10007 state.position = popped ? 0 : 1;
10008 pm_compile_multi_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
10010 PM_COMPILE_NOT_POPPED(cast->
value);
10011 if (!popped) PUSH_INSN(ret, location, dup);
10013 PUSH_SEQ(ret, writes);
10014 if (!popped && state.stack_size >= 1) {
10017 PUSH_INSN1(ret, location, setn,
INT2FIX(state.stack_size));
10022 pm_multi_target_state_update(&state);
10024 PUSH_SEQ(ret, cleanup);
10033 pm_compile_next_node(iseq, (
const pm_next_node_t *) node, &location, ret, popped, scope_node);
10035 case PM_NIL_NODE: {
10039 PUSH_INSN(ret, location, putnil);
10044 case PM_NO_BLOCK_PARAMETER_NODE: {
10047 ISEQ_BODY(iseq)->param.flags.accepts_no_block = TRUE;
10050 case PM_NO_KEYWORDS_PARAMETER_NODE: {
10053 ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg = TRUE;
10056 case PM_NUMBERED_REFERENCE_READ_NODE: {
10062 if (cast->
number != 0) {
10063 VALUE ref = pm_compile_numbered_reference_ref(cast);
10064 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), ref);
10067 PUSH_INSN(ret, location, putnil);
10078 LABEL *end_label = NEW_LABEL(location.
line);
10079 PM_COMPILE_NOT_POPPED(cast->
left);
10081 if (!popped) PUSH_INSN(ret, location, dup);
10082 PUSH_INSNL(ret, location, branchif, end_label);
10084 if (!popped) PUSH_INSN(ret, location, pop);
10085 PM_COMPILE(cast->
right);
10086 PUSH_LABEL(ret, end_label);
10090 case PM_OPTIONAL_PARAMETER_NODE: {
10094 PM_COMPILE_NOT_POPPED(cast->
value);
10097 PUSH_SETLOCAL(ret, location, index.index, index.level);
10101 case PM_PARENTHESES_NODE: {
10109 if (cast->
body != NULL) {
10110 PM_COMPILE(cast->
body);
10112 else if (!popped) {
10113 PUSH_INSN(ret, location, putnil);
10118 case PM_PRE_EXECUTION_NODE: {
10130 DECL_ANCHOR(inner_pre);
10133 DECL_ANCHOR(inner_body);
10138 for (
size_t index = 0; index < body->
size; index++) {
10139 pm_compile_node(iseq, body->
nodes[index], inner_body,
true, scope_node);
10144 PUSH_INSN(inner_body, location, putnil);
10150 PUSH_SEQ(outer_pre, inner_pre);
10151 PUSH_SEQ(outer_pre, inner_body);
10156 case PM_POST_EXECUTION_NODE: {
10160 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
10163 pm_scope_node_init(node, &next_scope_node, scope_node);
10164 child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
10165 pm_scope_node_destroy(&next_scope_node);
10167 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
10169 int is_index = ISEQ_BODY(iseq)->ise_size++;
10170 PUSH_INSN2(ret, location, once, child_iseq,
INT2FIX(is_index));
10172 if (popped) PUSH_INSN(ret, location, pop);
10174 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
10178 case PM_RANGE_NODE: {
10182 bool exclude_end = PM_NODE_FLAG_P(cast, PM_RANGE_FLAGS_EXCLUDE_END);
10184 if (pm_optimizable_range_item_p(cast->
left) && pm_optimizable_range_item_p(cast->
right)) {
10190 (left && PM_NODE_TYPE_P(left, PM_INTEGER_NODE)) ? parse_integer((
const pm_integer_node_t *) left) :
Qnil,
10191 (right && PM_NODE_TYPE_P(right, PM_INTEGER_NODE)) ? parse_integer((const
pm_integer_node_t *) right) :
Qnil,
10195 RB_OBJ_SET_SHAREABLE(val);
10196 PUSH_INSN1(ret, location, putobject, val);
10200 if (cast->
left != NULL) {
10201 PM_COMPILE(cast->
left);
10203 else if (!popped) {
10204 PUSH_INSN(ret, location, putnil);
10207 if (cast->
right != NULL) {
10208 PM_COMPILE(cast->
right);
10210 else if (!popped) {
10211 PUSH_INSN(ret, location, putnil);
10215 PUSH_INSN1(ret, location, newrange,
INT2FIX(exclude_end ? 1 : 0));
10220 case PM_RATIONAL_NODE: {
10224 PUSH_INSN1(ret, location, putobject, parse_rational((
const pm_rational_node_t *) node));
10231 pm_compile_redo_node(iseq, &location, ret, popped, scope_node);
10233 case PM_REGULAR_EXPRESSION_NODE: {
10237 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
10238 PUSH_INSN1(ret, location, putobject, regexp);
10242 case PM_RESCUE_NODE:
10245 pm_compile_rescue_node(iseq, (
const pm_rescue_node_t *) node, &location, ret, popped, scope_node);
10247 case PM_RESCUE_MODIFIER_NODE: {
10253 pm_scope_node_init((
const pm_node_t *) cast, &rescue_scope_node, scope_node);
10255 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
10256 &rescue_scope_node,
10262 pm_scope_node_destroy(&rescue_scope_node);
10264 LABEL *lstart = NEW_LABEL(location.
line);
10265 LABEL *lend = NEW_LABEL(location.
line);
10266 LABEL *lcont = NEW_LABEL(location.
line);
10268 lstart->rescued = LABEL_RESCUE_BEG;
10269 lend->rescued = LABEL_RESCUE_END;
10271 PUSH_LABEL(ret, lstart);
10273 PUSH_LABEL(ret, lend);
10275 PUSH_INSN(ret, location, nop);
10276 PUSH_LABEL(ret, lcont);
10277 if (popped) PUSH_INSN(ret, location, pop);
10279 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
10280 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
10283 case PM_RETURN_NODE:
10289 pm_compile_return_node(iseq, (
const pm_return_node_t *) node, &location, ret, popped, scope_node);
10291 case PM_RETRY_NODE: {
10294 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_RESCUE) {
10295 PUSH_INSN(ret, location, putnil);
10296 PUSH_INSN1(ret, location,
throw,
INT2FIX(TAG_RETRY));
10297 if (popped) PUSH_INSN(ret, location, pop);
10300 COMPILE_ERROR(iseq, location.
line,
"Invalid retry");
10305 case PM_SCOPE_NODE:
10306 pm_compile_scope_node(iseq, (
pm_scope_node_t *) node, &location, ret, popped);
10308 case PM_SELF_NODE: {
10312 PUSH_INSN(ret, location, putself);
10316 case PM_SHAREABLE_CONSTANT_NODE: {
10320 pm_node_flags_t shareability = (cast->
base.
flags & (PM_SHAREABLE_CONSTANT_NODE_FLAGS_LITERAL | PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_EVERYTHING | PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY));
10322 switch (PM_NODE_TYPE(cast->
write)) {
10323 case PM_CONSTANT_WRITE_NODE:
10326 case PM_CONSTANT_AND_WRITE_NODE:
10329 case PM_CONSTANT_OR_WRITE_NODE:
10332 case PM_CONSTANT_OPERATOR_WRITE_NODE:
10335 case PM_CONSTANT_PATH_WRITE_NODE:
10338 case PM_CONSTANT_PATH_AND_WRITE_NODE:
10341 case PM_CONSTANT_PATH_OR_WRITE_NODE:
10344 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
10348 rb_bug(
"Unexpected node type for shareable constant write: %s", pm_node_type(PM_NODE_TYPE(cast->
write)));
10354 case PM_SINGLETON_CLASS_NODE: {
10360 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10361 const rb_iseq_t *child_iseq = NEW_ISEQ(&next_scope_node, rb_fstring_lit(
"singleton class"), ISEQ_TYPE_CLASS, location.
line);
10362 pm_scope_node_destroy(&next_scope_node);
10365 PUSH_INSN(ret, location, putnil);
10368 CONST_ID(singletonclass,
"singletonclass");
10372 int sclass_flags = VM_DEFINECLASS_TYPE_SINGLETON_CLASS;
10373 if (!(PM_NODE_TYPE_P(cast->
expression, PM_SELF_NODE) &&
10374 ISEQ_BODY(iseq)->
type == ISEQ_TYPE_CLASS) &&
10376 sclass_flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
10379 PUSH_INSN3(ret, location, defineclass,
ID2SYM(singletonclass), child_iseq,
INT2FIX(sclass_flags));
10381 if (popped) PUSH_INSN(ret, location, pop);
10386 case PM_SOURCE_ENCODING_NODE: {
10390 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10391 PUSH_INSN1(ret, location, putobject, value);
10395 case PM_SOURCE_FILE_NODE: {
10400 VALUE string = pm_source_file_value(cast, scope_node);
10402 if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_FROZEN)) {
10403 PUSH_INSN1(ret, location, putobject,
string);
10405 else if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_MUTABLE)) {
10406 PUSH_INSN1(ret, location, dupstring,
string);
10409 PUSH_INSN1(ret, location, dupchilledstring,
string);
10414 case PM_SOURCE_LINE_NODE: {
10418 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10419 PUSH_INSN1(ret, location, putobject, value);
10423 case PM_SPLAT_NODE: {
10432 PUSH_INSN1(ret, location, splatarray,
Qtrue);
10436 case PM_STATEMENTS_NODE: {
10441 if (body->
size > 0) {
10442 for (
size_t index = 0; index < body->
size - 1; index++) {
10443 PM_COMPILE_POPPED(body->
nodes[index]);
10445 PM_COMPILE(body->
nodes[body->
size - 1]);
10448 PUSH_INSN(ret, location, putnil);
10452 case PM_STRING_NODE: {
10457 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10459 if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_FROZEN)) {
10460 PUSH_INSN1(ret, location, putobject, value);
10462 else if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_MUTABLE)) {
10463 PUSH_INSN1(ret, location, dupstring, value);
10466 PUSH_INSN1(ret, location, dupchilledstring, value);
10471 case PM_SUPER_NODE:
10475 pm_compile_super_node(iseq, (
const pm_super_node_t *) node, &location, ret, popped, scope_node);
10477 case PM_SYMBOL_NODE: {
10481 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10482 PUSH_INSN1(ret, location, putobject, value);
10486 case PM_TRUE_NODE: {
10490 PUSH_INSN1(ret, location, putobject,
Qtrue);
10494 case PM_UNDEF_NODE: {
10500 for (
size_t index = 0; index < names->
size; index++) {
10501 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10502 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
10504 PM_COMPILE_NOT_POPPED(names->
nodes[index]);
10505 PUSH_SEND(ret, location, id_core_undef_method,
INT2NUM(2));
10507 if (index < names->size - 1) {
10508 PUSH_INSN(ret, location, pop);
10512 if (popped) PUSH_INSN(ret, location, pop);
10515 case PM_UNLESS_NODE: {
10527 pm_compile_conditional(iseq, &location, PM_UNLESS_NODE, (
const pm_node_t *) cast, statements, (
const pm_node_t *) cast->statements, cast->predicate, ret, popped, scope_node);
10530 case PM_UNTIL_NODE: {
10537 pm_compile_loop(iseq, &location, cast->
base.
flags, PM_UNTIL_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10540 case PM_WHILE_NODE: {
10547 pm_compile_loop(iseq, &location, cast->
base.
flags, PM_WHILE_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10550 case PM_X_STRING_NODE: {
10554 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10556 PUSH_INSN(ret, location, putself);
10557 PUSH_INSN1(ret, location, putobject, value);
10558 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
10559 if (popped) PUSH_INSN(ret, location, pop);
10563 case PM_YIELD_NODE:
10569 pm_compile_yield_node(iseq, (
const pm_yield_node_t *) node, &location, ret, popped, scope_node);
10572 rb_raise(
rb_eNotImpError,
"node type %s not implemented", pm_node_type(PM_NODE_TYPE(node)));
10577#undef PM_CONTAINER_P
10581pm_iseq_pre_execution_p(
rb_iseq_t *iseq)
10583 switch (ISEQ_BODY(iseq)->
type) {
10584 case ISEQ_TYPE_TOP:
10585 case ISEQ_TYPE_EVAL:
10586 case ISEQ_TYPE_MAIN:
10605 if (pm_iseq_pre_execution_p(iseq)) {
10617 pm_compile_node(iseq, (
const pm_node_t *) node, body,
false, node);
10621 PUSH_SEQ(ret, pre);
10622 PUSH_SEQ(ret, body);
10627 pm_compile_node(iseq, (
const pm_node_t *) node, ret,
false, node);
10630 CHECK(iseq_setup_insn(iseq, ret));
10631 return iseq_setup(iseq, ret);
10638 result->
arena = pm_arena_new();
10639 result->
options = pm_options_new();
10640 pm_options_line_set(result->
options, 1);
10651 SIZED_FREE_N(result->
node.constants, pm_parser_constants_size(result->
node.parser));
10652 pm_scope_node_destroy(&result->
node);
10656 pm_arena_free(result->
arena);
10658 pm_options_free(result->
options);
10670 if (buffer == NULL) {
10675 if (rb_stderr_tty_p()) {
10676 const char *no_color = getenv(
"NO_COLOR");
10677 if (no_color == NULL || no_color[0] ==
'\0') {
10686 pm_error_level_t error_level = pm_errors_format(parser, buffer, format_type);
10689 VALUE message = rb_enc_str_new(pm_buffer_value(buffer), (
long) pm_buffer_length(buffer), message_encoding);
10690 pm_buffer_free(buffer);
10693 switch (error_level) {
10700 VALUE path = rb_enc_str_new((
const char *) pm_string_source(filepath), pm_string_length(filepath), filepath_encoding);
10724pm_intern_constants_callback(
const pm_constant_t *constant,
void *data)
10727 ctx->constants[ctx->index++] = rb_intern3((
const char *) pm_constant_start(constant), pm_constant_length(constant), ctx->encoding);
10734 const char *filepath;
10738pm_warning_emit_callback(
const pm_diagnostic_t *diagnostic,
void *data) {
10741 int line = pm_location_line_number(ctx->parser, &loc);
10744 rb_enc_compile_warning(ctx->encoding, ctx->filepath, line,
"%s", pm_diagnostic_message(diagnostic));
10747 rb_enc_compile_warn(ctx->encoding, ctx->filepath, line,
"%s", pm_diagnostic_message(diagnostic));
10765 const uint8_t *start = pm_parser_start(parser);
10766 const uint8_t *end = pm_parser_end(parser);
10767 const pm_location_t *data_loc = pm_parser_data_loc(parser);
10769 if (data_loc->
length != 0) {
10770 const uint8_t *cursor = start + data_loc->
start;
10771 while (cursor < end && *cursor !=
'\n') cursor++;
10772 if (cursor < end) cursor++;
10777 rb_source_hash_init(&state);
10778 rb_source_hash_update(&state, start, (
size_t) (end - start));
10779 return rb_source_hash_finalize(&state);
10791 int coverage_enabled = scope_node->coverage_enabled;
10793 pm_scope_node_init(node, scope_node, NULL);
10796 const char *encoding_name = pm_parser_encoding_name(parser);
10797 scope_node->encoding = rb_enc_find(encoding_name);
10798 if (!scope_node->encoding) rb_bug(
"Encoding not found %s!", encoding_name);
10800 scope_node->coverage_enabled = coverage_enabled;
10804 if (script_lines != NULL) {
10808 for (
size_t index = 0; index < line_offsets->
size; index++) {
10809 size_t offset = line_offsets->
offsets[index];
10810 size_t length = index == line_offsets->
size - 1 ? ((size_t) (pm_parser_end(parser) - (pm_parser_start(parser) + offset))) : (line_offsets->offsets[index + 1] - offset);
10811 rb_ary_push(*script_lines, rb_enc_str_new((
const char *) pm_parser_start(parser) + offset, length, scope_node->encoding));
10820 .encoding = scope_node->encoding,
10821 .filepath = (
const char *) pm_string_source(pm_parser_filepath(parser))
10823 pm_parser_warnings_each(parser, pm_warning_emit_callback, &warning_ctx);
10826 if (pm_parser_errors_size(parser) > 0) {
10827 VALUE error = pm_parse_process_error(result);
10836 scope_node->parser = parser;
10837 scope_node->
source_hash = pm_source_hash(parser);
10838 scope_node->options = result->
options;
10839 scope_node->line_offsets = pm_parser_line_offsets(parser);
10840 scope_node->start_line = pm_parser_start_line(parser);
10841 size_t constants_size = pm_parser_constants_size(parser);
10842 scope_node->constants = constants_size ?
xmalloc(constants_size *
sizeof(
ID)) : NULL;
10844 pm_intern_constants_ctx_t intern_ctx = { .constants = scope_node->constants, .encoding = scope_node->encoding, .index = 0 };
10845 pm_parser_constants_each(parser, pm_intern_constants_callback, &intern_ctx);
10858pm_options_frozen_string_literal_init(
pm_options_t *options)
10860 int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
10862 switch (frozen_string_literal) {
10863 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
10865 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
10866 pm_options_frozen_string_literal_set(options,
false);
10868 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
10869 pm_options_frozen_string_literal_set(options,
true);
10872 rb_bug(
"pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
10885 const char *start = (
const char *) pm_parser_start(parser);
10886 const char *end = (
const char *) pm_parser_end(parser);
10891 size_t last_offset = line_offsets->
offsets[line_offsets->
size - 1];
10892 bool last_push = start + last_offset != end;
10897 for (
size_t index = 0; index < line_offsets->
size - 1; index++) {
10898 size_t offset = line_offsets->
offsets[index];
10899 size_t length = line_offsets->
offsets[index + 1] - offset;
10901 rb_ary_push(lines, rb_enc_str_new(start + offset, length, scope_node->encoding));
10906 rb_ary_push(lines, rb_enc_str_new(start + last_offset, end - (start + last_offset), scope_node->encoding));
10920close_file(
VALUE args)
10923 if (arg->fd != -1) {
10926 else if (!
NIL_P(arg->io)) {
10933load_content(
VALUE args)
10940 return rb_funcall(io, rb_intern(
"read"), 0);
10951 result->
source = pm_source_mapped_new(RSTRING_PTR(filepath), O_RDONLY | O_NONBLOCK, &init_result);
10954 pm_options_frozen_string_literal_init(result->
options);
10965 .open_mode = O_RDONLY | O_NONBLOCK,
10969 if (args.fd == -1)
goto error_generic;
10974 long len = RSTRING_LEN(contents);
10975 if (
len < 0)
goto error_generic;
10977 size_t length = (size_t)
len;
10978 uint8_t *source_data =
xmalloc(length);
10979 memcpy(source_data, RSTRING_PTR(contents), length);
10980 result->
source = pm_source_owned_new(source_data, length);
10982 pm_options_frozen_string_literal_init(result->
options);
10991 err = rb_w32_map_errno(GetLastError());
11022 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11025 pm_options_version_for_current_ruby_set(result->
options);
11030 VALUE error = pm_parse_process(result, node, script_lines);
11035 ID id_script_lines = rb_intern(
"SCRIPT_LINES__");
11041 rb_hash_aset(constant_script_lines, filepath, pm_parse_file_script_lines(&result->
node, result->
parser));
11055 VALUE error = pm_load_file(result, filepath,
false);
11056 if (
NIL_P(error)) {
11057 error = pm_parse_file(result, filepath, script_lines);
11073 if (!rb_enc_asciicompat(encoding)) {
11077 pm_options_frozen_string_literal_init(result->
options);
11078 result->
source = pm_source_constant_new((
const uint8_t *) RSTRING_PTR(source), (
size_t) RSTRING_LEN(source));
11079 pm_options_encoding_set(result->
options, rb_enc_name(encoding));
11082 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11084 pm_options_version_for_current_ruby_set(result->
options);
11089 VALUE error = pm_parse_process(result, node, script_lines);
11102pm_node_find(
const pm_node_t *node,
void *data)
11106 if (context->node == NULL && node->
node_id == context->node_id) {
11107 context->node = node;
11111 return context->node == NULL;
11115pm_node_source_location(
VALUE source,
VALUE filepath,
int start_line,
11119 pm_parse_result_init(&result);
11121 pm_options_line_set(result.
options, start_line);
11122 VALUE error = pm_parse_string(&result, source, filepath, NULL);
11124 if (!
NIL_P(error)) {
11125 pm_parse_result_free(&result);
11130 .node_id = (uint32_t) node_id,
11133 pm_visit_node(result.
node.ast_node, pm_node_find, &context);
11135 bool found = context.node != NULL;
11137 *location = pm_code_location(&result.
node, context.node);
11143 pm_parse_result_free(&result);
11147VALUE rb_io_gets_limit_internal(
VALUE io,
long limit);
11157pm_parse_stdin_eof(
void *stream)
11170#define MAX_ENC_LEN 6
11178pm_parse_stdin_fgets(
char *
string,
int size,
void *stream)
11188 VALUE line = rb_io_gets_limit_internal((
VALUE) stream, size - MAX_ENC_LEN);
11193 const char *cstr = RSTRING_PTR(line);
11194 long length = RSTRING_LEN(line);
11202 if (length > (
long) (size - 1)) {
11203 length = (long) (size - 1);
11206 memcpy(
string, cstr, (
size_t) length);
11207 string[length] =
'\0';
11215void rb_reset_argf_lineno(
long n);
11225 pm_options_frozen_string_literal_init(result->
options);
11227 result->
source = pm_source_stream_new((
void *)
rb_stdin, pm_parse_stdin_fgets, pm_parse_stdin_eof);
11232 rb_reset_argf_lineno(0);
11234 return pm_parse_process(result, node, NULL);
11237#define PM_VERSION_FOR_RELEASE(major, minor) PM_VERSION_FOR_RELEASE_IMPL(major, minor)
11238#define PM_VERSION_FOR_RELEASE_IMPL(major, minor) #major "." #minor
11240void pm_options_version_for_current_ruby_set(
pm_options_t *options) {
11242 pm_options_version_set(options, version, strlen(version));
11246#define NEW_ISEQ OLD_ISEQ
11248#undef NEW_CHILD_ISEQ
11249#define NEW_CHILD_ISEQ OLD_CHILD_ISEQ
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
@ PM_WARNING_LEVEL_VERBOSE
For warnings which should be emitted if $VERBOSE == true.
pm_error_level_t
The levels of errors generated during parsing.
@ PM_ERROR_LEVEL_ARGUMENT
For errors that should raise an argument error.
@ PM_ERROR_LEVEL_LOAD
For errors that should raise a load error.
@ PM_ERROR_LEVEL_SYNTAX
For errors that should raise a syntax error.
#define RUBY_EVENT_END
Encountered an end of a class clause.
#define RUBY_EVENT_B_RETURN
Encountered a next statement.
#define RUBY_EVENT_CLASS
Encountered a new class.
#define RUBY_EVENT_LINE
Encountered a new line.
#define RUBY_EVENT_RETURN
Encountered a return statement.
#define RUBY_EVENT_B_CALL
Encountered an yield statement.
#define RUBY_EVENT_CALL
A method, written in Ruby, is called.
#define RUBY_EVENT_RESCUE
Encountered a rescue statement.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define ALLOCV
Old name of RB_ALLOCV.
#define ALLOC
Old name of RB_ALLOC.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define T_STRING
Old name of RUBY_T_STRING.
#define xfree
Old name of ruby_xfree.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define ID2SYM
Old name of RB_ID2SYM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define ULONG2NUM
Old name of RB_ULONG2NUM.
#define FIXABLE
Old name of RB_FIXABLE.
#define xmalloc
Old name of ruby_xmalloc.
#define LONG2FIX
Old name of RB_INT2FIX.
#define ZALLOC_N
Old name of RB_ZALLOC_N.
#define T_HASH
Old name of RUBY_T_HASH.
#define ALLOC_N
Old name of RB_ALLOC_N.
#define rb_exc_new3
Old name of rb_exc_new_str.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define DBL2NUM
Old name of rb_float_new.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define UINT2NUM
Old name of RB_UINT2NUM.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define ruby_debug
This variable controls whether the interpreter is in debug mode.
VALUE rb_eNotImpError
NotImplementedError exception.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
VALUE rb_eStandardError
StandardError exception.
VALUE rb_syserr_new_str(int n, VALUE arg)
Identical to rb_syserr_new(), except it takes the message in Ruby's String instead of C's.
VALUE rb_eNoMemError
NoMemoryError exception.
VALUE rb_eLoadError
LoadError exception.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eNoMatchingPatternError
NoMatchingPatternError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_eNoMatchingPatternKeyError
NoMatchingPatternKeyError exception.
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Identical to rb_exc_new_cstr(), except it takes a Ruby's string instead of C's.
VALUE rb_ensure(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
An equivalent to ensure clause.
VALUE rb_eSyntaxError
SyntaxError exception.
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Make a hidden object visible again.
VALUE rb_cArray
Array class.
VALUE rb_cObject
Object class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_stdin
STDIN constant.
VALUE rb_cHash
Hash class.
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
VALUE rb_enc_interned_str(const char *ptr, long len, rb_encoding *enc)
Identical to rb_enc_str_new(), except it returns a "f"string.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_ary_cat(VALUE ary, const VALUE *train, long len)
Destructively appends multiple elements at the end of the array.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_hidden_new(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
VALUE rb_ary_join(VALUE ary, VALUE sep)
Recursively stringises the elements of the passed array, flattens that result, then joins the sequenc...
void rb_ary_store(VALUE ary, long key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
#define INTEGER_PACK_NATIVE_BYTE_ORDER
Means either INTEGER_PACK_MSBYTE_FIRST or INTEGER_PACK_LSBYTE_FIRST, depending on the host processor'...
#define INTEGER_PACK_LSWORD_FIRST
Stores/interprets the least significant word as the first word.
VALUE rb_io_fdopen(int fd, int flags, const char *path)
Creates an IO instance whose backend is the given file descriptor.
int rb_cloexec_open(const char *pathname, int flags, mode_t mode)
Opens a file that closes on exec.
VALUE rb_io_eof(VALUE io)
Queries if the passed IO is at the end of file.
VALUE rb_io_close(VALUE io)
Closes the IO.
VALUE rb_range_new(VALUE beg, VALUE end, int excl)
Creates a new Range.
VALUE rb_rational_new(VALUE num, VALUE den)
Constructs a Rational, with reduction.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_tmp_new(long len)
Allocates a "temporary" string.
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
#define rb_str_buf_new_cstr(str)
Identical to rb_str_new_cstr, except done differently.
VALUE rb_str_concat(VALUE dst, VALUE src)
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
VALUE rb_str_freeze(VALUE str)
This is the implementation of String#freeze.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_const_get_at(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
int rb_const_defined_at(VALUE space, ID name)
Identical to rb_const_defined(), except it doesn't look for parent classes.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
VALUE rb_id2sym(ID id)
Allocates an instance of rb_cSymbol that has the given id.
@ RUBY_IO_READABLE
IO::READABLE
VALUE rb_io_wait(VALUE io, VALUE events, VALUE timeout)
Blocks until the passed IO is ready for the passed events.
int len
Length of the buffer.
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
VALUE rb_ractor_make_shareable(VALUE obj)
Destructively transforms the passed object so that multiple Ractors can share it.
#define DECIMAL_SIZE_OF(expr)
An approximation of decimal representation size.
#define RUBY_API_VERSION_MAJOR
Major version.
#define RUBY_API_VERSION_MINOR
Minor version.
#define RB_INT2NUM
Just another name of rb_int2num_inline.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_parser_t * pm_parser_new(pm_arena_t *arena, const uint8_t *source, size_t size, const pm_options_t *options) PRISM_NONNULL(1)
Allocate and initialize a parser with the given start and end pointers.
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser) PRISM_NONNULL(1)
Free both the memory held by the given parser and the parser itself.
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser) PRISM_NONNULL(1)
Initiate the parser with the given parser.
#define PM_NODE_LIST_FOREACH(list, index, node)
Loop through each node in the node list, writing each node to the given pm_node_t pointer.
The main header file for the prism parser.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define errno
Ractor-aware version of errno.
pm_source_init_result_t
Represents the result of initializing a source from a file.
@ PM_SOURCE_INIT_SUCCESS
Indicates that the source was successfully initialized.
@ PM_SOURCE_INIT_ERROR_NON_REGULAR
Indicates that the file is not a regular file (e.g.
@ PM_SOURCE_INIT_ERROR_DIRECTORY
Indicates that the file that was attempted to be opened was a directory.
#define RTEST
This is an old name of RB_TEST.
PM_NODE_ALIGNAS struct pm_node * new_name
AliasGlobalVariableNode::new_name.
PM_NODE_ALIGNAS struct pm_node * old_name
AliasGlobalVariableNode::old_name.
PM_NODE_ALIGNAS struct pm_node * old_name
AliasMethodNode::old_name.
PM_NODE_ALIGNAS struct pm_node * new_name
AliasMethodNode::new_name.
PM_NODE_ALIGNAS struct pm_node * left
AlternationPatternNode::left.
PM_NODE_ALIGNAS struct pm_node * right
AlternationPatternNode::right.
PM_NODE_ALIGNAS struct pm_node * left
AndNode::left.
PM_NODE_ALIGNAS struct pm_node * right
AndNode::right.
pm_node_t base
The embedded base node.
struct pm_node_list arguments
ArgumentsNode::arguments.
struct pm_node_list elements
ArrayNode::elements.
struct pm_node_list requireds
ArrayPatternNode::requireds.
PM_NODE_ALIGNAS struct pm_node * rest
ArrayPatternNode::rest.
PM_NODE_ALIGNAS struct pm_node * constant
ArrayPatternNode::constant.
struct pm_node_list posts
ArrayPatternNode::posts.
PM_NODE_ALIGNAS struct pm_node * value
AssocNode::value.
PM_NODE_ALIGNAS struct pm_node * key
AssocNode::key.
PM_NODE_ALIGNAS struct pm_node * value
AssocSplatNode::value.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
BeginNode::else_clause.
PM_NODE_ALIGNAS struct pm_ensure_node * ensure_clause
BeginNode::ensure_clause.
PM_NODE_ALIGNAS struct pm_statements_node * statements
BeginNode::statements.
PM_NODE_ALIGNAS struct pm_rescue_node * rescue_clause
BeginNode::rescue_clause.
PM_NODE_ALIGNAS struct pm_node * expression
BlockArgumentNode::expression.
PM_NODE_ALIGNAS struct pm_node * parameters
BlockNode::parameters.
pm_constant_id_list_t locals
BlockNode::locals.
PM_NODE_ALIGNAS struct pm_node * body
BlockNode::body.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
BreakNode::arguments.
PM_NODE_ALIGNAS struct pm_node * receiver
CallAndWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallAndWriteNode::value.
pm_constant_id_t read_name
CallAndWriteNode::read_name.
pm_constant_id_t write_name
CallAndWriteNode::write_name.
pm_location_t closing_loc
CallNode::closing_loc.
pm_constant_id_t name
CallNode::name.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
CallNode::arguments.
pm_location_t message_loc
CallNode::message_loc.
PM_NODE_ALIGNAS struct pm_node * block
CallNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
CallNode::receiver.
pm_constant_id_t read_name
CallOperatorWriteNode::read_name.
pm_constant_id_t binary_operator
CallOperatorWriteNode::binary_operator.
pm_constant_id_t write_name
CallOperatorWriteNode::write_name.
PM_NODE_ALIGNAS struct pm_node * receiver
CallOperatorWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * receiver
CallOrWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallOrWriteNode::value.
pm_constant_id_t write_name
CallOrWriteNode::write_name.
pm_constant_id_t read_name
CallOrWriteNode::read_name.
pm_constant_id_t name
CallTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * receiver
CallTargetNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CapturePatternNode::value.
PM_NODE_ALIGNAS struct pm_local_variable_target_node * target
CapturePatternNode::target.
struct pm_node_list conditions
CaseMatchNode::conditions.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * predicate
CaseMatchNode::predicate.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
CaseMatchNode::else_clause.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
CaseNode::else_clause.
struct pm_node_list conditions
CaseNode::conditions.
PM_NODE_ALIGNAS struct pm_node * predicate
CaseNode::predicate.
pm_node_t base
The embedded base node.
pm_constant_id_list_t locals
ClassNode::locals.
PM_NODE_ALIGNAS struct pm_node * superclass
ClassNode::superclass.
pm_constant_id_t name
ClassNode::name.
PM_NODE_ALIGNAS struct pm_node * constant_path
ClassNode::constant_path.
PM_NODE_ALIGNAS struct pm_node * body
ClassNode::body.
ClassVariableAndWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
ClassVariableAndWriteNode::value.
pm_constant_id_t name
ClassVariableAndWriteNode::name.
ClassVariableOperatorWriteNode.
pm_constant_id_t name
ClassVariableOperatorWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
ClassVariableOperatorWriteNode::value.
pm_constant_id_t binary_operator
ClassVariableOperatorWriteNode::binary_operator.
ClassVariableOrWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
ClassVariableOrWriteNode::value.
pm_constant_id_t name
ClassVariableOrWriteNode::name.
pm_constant_id_t name
ClassVariableReadNode::name.
pm_constant_id_t name
ClassVariableTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * value
ClassVariableWriteNode::value.
pm_constant_id_t name
ClassVariableWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
ConstantAndWriteNode::value.
pm_location_t name_loc
ConstantAndWriteNode::name_loc.
pm_constant_id_t name
ConstantAndWriteNode::name.
size_t size
The number of constant ids in the list.
size_t capacity
The number of constant ids that have been allocated in the list.
pm_constant_id_t * ids
The constant ids in the list.
ConstantOperatorWriteNode.
pm_constant_id_t name
ConstantOperatorWriteNode::name.
pm_location_t name_loc
ConstantOperatorWriteNode::name_loc.
pm_constant_id_t binary_operator
ConstantOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_node * value
ConstantOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * value
ConstantOrWriteNode::value.
pm_location_t name_loc
ConstantOrWriteNode::name_loc.
pm_constant_id_t name
ConstantOrWriteNode::name.
ConstantPathAndWriteNode.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathAndWriteNode::target.
PM_NODE_ALIGNAS struct pm_node * value
ConstantPathAndWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * parent
ConstantPathNode::parent.
pm_constant_id_t name
ConstantPathNode::name.
ConstantPathOperatorWriteNode.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathOperatorWriteNode::target.
pm_constant_id_t binary_operator
ConstantPathOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_node * value
ConstantPathOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * value
ConstantPathOrWriteNode::value.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathOrWriteNode::target.
pm_constant_id_t name
ConstantPathTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * parent
ConstantPathTargetNode::parent.
PM_NODE_ALIGNAS struct pm_node * value
ConstantPathWriteNode::value.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathWriteNode::target.
pm_node_t base
The embedded base node.
pm_constant_id_t name
ConstantReadNode::name.
pm_constant_id_t name
ConstantTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * value
ConstantWriteNode::value.
pm_constant_id_t name
ConstantWriteNode::name.
pm_constant_id_t name
DefNode::name.
PM_NODE_ALIGNAS struct pm_parameters_node * parameters
DefNode::parameters.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * receiver
DefNode::receiver.
PM_NODE_ALIGNAS struct pm_node * body
DefNode::body.
pm_constant_id_list_t locals
DefNode::locals.
PM_NODE_ALIGNAS struct pm_node * value
DefinedNode::value.
PM_NODE_ALIGNAS struct pm_statements_node * statements
ElseNode::statements.
PM_NODE_ALIGNAS struct pm_statements_node * statements
EmbeddedStatementsNode::statements.
PM_NODE_ALIGNAS struct pm_node * variable
EmbeddedVariableNode::variable.
PM_NODE_ALIGNAS struct pm_statements_node * statements
EnsureNode::statements.
PM_NODE_ALIGNAS struct pm_splat_node * left
FindPatternNode::left.
PM_NODE_ALIGNAS struct pm_splat_node * right
FindPatternNode::right.
PM_NODE_ALIGNAS struct pm_node * constant
FindPatternNode::constant.
struct pm_node_list requireds
FindPatternNode::requireds.
PM_NODE_ALIGNAS struct pm_node * left
FlipFlopNode::left.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * right
FlipFlopNode::right.
double value
FloatNode::value.
PM_NODE_ALIGNAS struct pm_node * collection
ForNode::collection.
PM_NODE_ALIGNAS struct pm_statements_node * statements
ForNode::statements.
PM_NODE_ALIGNAS struct pm_block_node * block
ForwardingSuperNode::block.
GlobalVariableAndWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
GlobalVariableAndWriteNode::value.
pm_constant_id_t name
GlobalVariableAndWriteNode::name.
GlobalVariableOperatorWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
GlobalVariableOperatorWriteNode::value.
pm_constant_id_t name
GlobalVariableOperatorWriteNode::name.
pm_constant_id_t binary_operator
GlobalVariableOperatorWriteNode::binary_operator.
GlobalVariableOrWriteNode.
pm_constant_id_t name
GlobalVariableOrWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
GlobalVariableOrWriteNode::value.
pm_constant_id_t name
GlobalVariableReadNode::name.
GlobalVariableTargetNode.
pm_constant_id_t name
GlobalVariableTargetNode::name.
pm_constant_id_t name
GlobalVariableWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
GlobalVariableWriteNode::value.
struct pm_node_list elements
HashNode::elements.
PM_NODE_ALIGNAS struct pm_node * constant
HashPatternNode::constant.
struct pm_node_list elements
HashPatternNode::elements.
PM_NODE_ALIGNAS struct pm_node * rest
HashPatternNode::rest.
PM_NODE_ALIGNAS struct pm_node * predicate
IfNode::predicate.
PM_NODE_ALIGNAS struct pm_statements_node * statements
IfNode::statements.
PM_NODE_ALIGNAS struct pm_node * numeric
ImaginaryNode::numeric.
PM_NODE_ALIGNAS struct pm_node * value
ImplicitNode::value.
PM_NODE_ALIGNAS struct pm_node * pattern
InNode::pattern.
PM_NODE_ALIGNAS struct pm_statements_node * statements
InNode::statements.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
IndexAndWriteNode::arguments.
PM_NODE_ALIGNAS struct pm_block_argument_node * block
IndexAndWriteNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
IndexAndWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
IndexAndWriteNode::value.
A direct-indexed lookup table mapping constant IDs to local variable indices.
int capacity
Total number of slots (constants_size + PM_INDEX_LOOKUP_SPECIALS).
bool owned
Whether the values array is heap-allocated and needs explicit free.
int * values
Array of local indices, indexed by constant_id.
PM_NODE_ALIGNAS struct pm_block_argument_node * block
IndexOperatorWriteNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
IndexOperatorWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
IndexOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
IndexOperatorWriteNode::arguments.
pm_constant_id_t binary_operator
IndexOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
IndexOrWriteNode::arguments.
PM_NODE_ALIGNAS struct pm_node * value
IndexOrWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * receiver
IndexOrWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_block_argument_node * block
IndexOrWriteNode::block.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
IndexTargetNode::arguments.
PM_NODE_ALIGNAS struct pm_block_argument_node * block
IndexTargetNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
IndexTargetNode::receiver.
InstanceVariableAndWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
InstanceVariableAndWriteNode::value.
pm_constant_id_t name
InstanceVariableAndWriteNode::name.
InstanceVariableOperatorWriteNode.
pm_constant_id_t binary_operator
InstanceVariableOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_node * value
InstanceVariableOperatorWriteNode::value.
pm_constant_id_t name
InstanceVariableOperatorWriteNode::name.
InstanceVariableOrWriteNode.
pm_constant_id_t name
InstanceVariableOrWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
InstanceVariableOrWriteNode::value.
InstanceVariableReadNode.
pm_constant_id_t name
InstanceVariableReadNode::name.
InstanceVariableTargetNode.
pm_constant_id_t name
InstanceVariableTargetNode::name.
InstanceVariableWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
InstanceVariableWriteNode::value.
pm_constant_id_t name
InstanceVariableWriteNode::name.
pm_integer_t value
IntegerNode::value.
A structure represents an arbitrary-sized integer.
size_t length
The number of allocated values.
uint32_t value
Embedded value for small integer.
uint32_t * values
List of 32-bit integers.
bool negative
Whether or not the integer is negative.
Context for interning constants via callback.
InterpolatedMatchLastLineNode.
InterpolatedRegularExpressionNode.
struct pm_node_list parts
InterpolatedStringNode::parts.
struct pm_node_list parts
InterpolatedSymbolNode::parts.
struct pm_node_list parts
InterpolatedXStringNode::parts.
struct pm_node_list elements
KeywordHashNode::elements.
KeywordRestParameterNode.
pm_location_t opening_loc
LambdaNode::opening_loc.
pm_constant_id_list_t locals
LambdaNode::locals.
PM_NODE_ALIGNAS struct pm_node * body
LambdaNode::body.
PM_NODE_ALIGNAS struct pm_node * parameters
LambdaNode::parameters.
A line and column in a string.
uint32_t column
The column in bytes.
int32_t line
The line number.
A list of offsets of the start of lines in a string.
uint32_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.
the getlocal and setlocal instructions require two parameters.
LocalVariableAndWriteNode.
pm_constant_id_t name
LocalVariableAndWriteNode::name.
uint32_t depth
LocalVariableAndWriteNode::depth.
PM_NODE_ALIGNAS struct pm_node * value
LocalVariableAndWriteNode::value.
LocalVariableOperatorWriteNode.
uint32_t depth
LocalVariableOperatorWriteNode::depth.
pm_constant_id_t binary_operator
LocalVariableOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_node * value
LocalVariableOperatorWriteNode::value.
pm_constant_id_t name
LocalVariableOperatorWriteNode::name.
LocalVariableOrWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
LocalVariableOrWriteNode::value.
uint32_t depth
LocalVariableOrWriteNode::depth.
pm_constant_id_t name
LocalVariableOrWriteNode::name.
uint32_t depth
LocalVariableReadNode::depth.
pm_constant_id_t name
LocalVariableReadNode::name.
uint32_t depth
LocalVariableTargetNode::depth.
pm_constant_id_t name
LocalVariableTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * value
LocalVariableWriteNode::value.
uint32_t depth
LocalVariableWriteNode::depth.
pm_constant_id_t name
LocalVariableWriteNode::name.
This struct represents a slice in the source code, defined by an offset and a length.
uint32_t start
The offset of the location from the start of the source.
uint32_t length
The length of the location.
PM_NODE_ALIGNAS struct pm_node * pattern
MatchPredicateNode::pattern.
PM_NODE_ALIGNAS struct pm_node * value
MatchPredicateNode::value.
PM_NODE_ALIGNAS struct pm_node * pattern
MatchRequiredNode::pattern.
PM_NODE_ALIGNAS struct pm_node * value
MatchRequiredNode::value.
PM_NODE_ALIGNAS struct pm_call_node * call
MatchWriteNode::call.
struct pm_node_list targets
MatchWriteNode::targets.
PM_NODE_ALIGNAS struct pm_node * constant_path
ModuleNode::constant_path.
PM_NODE_ALIGNAS struct pm_node * body
ModuleNode::body.
pm_constant_id_list_t locals
ModuleNode::locals.
pm_constant_id_t name
ModuleNode::name.
PM_NODE_ALIGNAS struct pm_node * rest
MultiTargetNode::rest.
struct pm_node_list lefts
MultiTargetNode::lefts.
struct pm_node_list rights
MultiTargetNode::rights.
This is a node in the multi target state linked list.
As we're compiling a multi target, we need to track additional information whenever there is a parent...
PM_NODE_ALIGNAS struct pm_node * rest
MultiWriteNode::rest.
struct pm_node_list rights
MultiWriteNode::rights.
PM_NODE_ALIGNAS struct pm_node * value
MultiWriteNode::value.
struct pm_node_list lefts
MultiWriteNode::lefts.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
NextNode::arguments.
A list of nodes in the source, most often used for lists of children.
size_t size
The number of nodes in the list.
struct pm_node ** nodes
The nodes in the list.
This compiler defines its own concept of the location of a node.
int32_t line
This is the line number of a node.
uint32_t node_id
This is a unique identifier for the node.
This is the base structure that represents a node in the syntax tree.
pm_node_type_t type
This represents the type of the node.
uint32_t node_id
The unique identifier for this node, which is deterministic based on the source.
pm_node_flags_t flags
This represents any flags on the node.
pm_location_t location
This is the location of the node in the source.
NumberedReferenceReadNode.
uint32_t number
NumberedReferenceReadNode::number.
OptionalKeywordParameterNode.
pm_constant_id_t name
OptionalKeywordParameterNode::name.
PM_NODE_ALIGNAS struct pm_node * value
OptionalKeywordParameterNode::value.
pm_constant_id_t name
OptionalParameterNode::name.
PM_NODE_ALIGNAS struct pm_node * value
OptionalParameterNode::value.
PM_NODE_ALIGNAS struct pm_node * right
OrNode::right.
PM_NODE_ALIGNAS struct pm_node * left
OrNode::left.
PM_NODE_ALIGNAS struct pm_node * block
ParametersNode::block.
struct pm_node_list requireds
ParametersNode::requireds.
struct pm_node_list optionals
ParametersNode::optionals.
struct pm_node_list posts
ParametersNode::posts.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * rest
ParametersNode::rest.
struct pm_node_list keywords
ParametersNode::keywords.
PM_NODE_ALIGNAS struct pm_node * keyword_rest
ParametersNode::keyword_rest.
PM_NODE_ALIGNAS struct pm_node * body
ParenthesesNode::body.
bool parsed
Whether or not this parse result has performed its parsing yet.
pm_parser_t * parser
The parser that will do the actual parsing.
pm_source_t * source
The source backing the parse (file, string, or stream).
pm_scope_node_t node
The resulting scope node that will hold the generated AST.
pm_options_t * options
The options that will be passed to the parser.
pm_arena_t * arena
The arena allocator for AST-lifetime memory.
PM_NODE_ALIGNAS struct pm_node * variable
PinnedVariableNode::variable.
PM_NODE_ALIGNAS struct pm_statements_node * statements
PostExecutionNode::statements.
PM_NODE_ALIGNAS struct pm_statements_node * statements
PreExecutionNode::statements.
PM_NODE_ALIGNAS struct pm_statements_node * statements
ProgramNode::statements.
PM_NODE_ALIGNAS struct pm_node * right
RangeNode::right.
PM_NODE_ALIGNAS struct pm_node * left
RangeNode::left.
pm_integer_t denominator
RationalNode::denominator.
pm_integer_t numerator
RationalNode::numerator.
RequiredKeywordParameterNode.
pm_constant_id_t name
RequiredParameterNode::name.
PM_NODE_ALIGNAS struct pm_node * expression
RescueModifierNode::expression.
PM_NODE_ALIGNAS struct pm_node * rescue_expression
RescueModifierNode::rescue_expression.
PM_NODE_ALIGNAS struct pm_statements_node * statements
RescueNode::statements.
PM_NODE_ALIGNAS struct pm_rescue_node * subsequent
RescueNode::subsequent.
PM_NODE_ALIGNAS struct pm_node * reference
RescueNode::reference.
struct pm_node_list exceptions
RescueNode::exceptions.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
ReturnNode::arguments.
uint64_t source_hash
The source hash of the parsed source, propagated to every iseq.
rb_encoding * filepath_encoding
This is the encoding of the actual filepath object that will be used when a FILE node is compiled or ...
pm_index_lookup_table_t index_lookup_table
A flat lookup table mapping constant IDs (or special IDs) to local variable indices.
size_t last_line
Cached line hint for line offset list lookups.
struct iseq_link_anchor * pre_execution_anchor
This will only be set on the top-level scope node.
VALUE * script_lines
This is a pointer to the list of script lines for the ISEQs that will be associated with this scope n...
PM_NODE_ALIGNAS struct pm_node * write
ShareableConstantNode::write.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * body
SingletonClassNode::body.
pm_constant_id_list_t locals
SingletonClassNode::locals.
PM_NODE_ALIGNAS struct pm_node * expression
SingletonClassNode::expression.
pm_string_t filepath
SourceFileNode::filepath.
PM_NODE_ALIGNAS struct pm_node * expression
SplatNode::expression.
struct pm_node_list body
StatementsNode::body.
pm_node_t base
The embedded base node.
pm_string_t unescaped
StringNode::unescaped.
A generic string type that can have various ownership semantics.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
SuperNode::arguments.
PM_NODE_ALIGNAS struct pm_node * block
SuperNode::block.
pm_string_t unescaped
SymbolNode::unescaped.
pm_node_t base
The embedded base node.
struct pm_node_list names
UndefNode::names.
PM_NODE_ALIGNAS struct pm_node * predicate
UnlessNode::predicate.
PM_NODE_ALIGNAS struct pm_statements_node * statements
UnlessNode::statements.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
UnlessNode::else_clause.
pm_node_t base
The embedded base node.
Context for emitting warnings via callback.
pm_node_t base
The embedded base node.
pm_string_t unescaped
XStringNode::unescaped.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
YieldNode::arguments.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.