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);
310 return parse_integer_value(&node->
value);
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)));
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);
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));
811pm_static_literal_string(
rb_iseq_t *iseq,
VALUE string,
int line_number)
813 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
814 VALUE str = rb_str_with_debug_created_info(
string, rb_iseq_path(iseq), line_number);
819 return rb_fstring(
string);
833 RUBY_ASSERT(PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL));
835 switch (PM_NODE_TYPE(node)) {
836 case PM_ARRAY_NODE: {
841 for (
size_t index = 0; index < elements->
size; index++) {
842 rb_ary_push(value, pm_static_literal_value(iseq, elements->
nodes[index], scope_node));
857 for (
size_t index = 0; index < elements->
size; index++) {
860 VALUE pair[2] = { pm_static_literal_value(iseq, cast->key, scope_node), pm_static_literal_value(iseq, cast->value, scope_node) };
871 case PM_IMAGINARY_NODE:
873 case PM_INTEGER_NODE:
875 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
877 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
879 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
881 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
883 case PM_INTERPOLATED_STRING_NODE: {
885 int line_number = pm_node_line_number_cached(node, scope_node);
886 return pm_static_literal_string(iseq,
string, line_number);
888 case PM_INTERPOLATED_SYMBOL_NODE: {
890 VALUE string = pm_static_literal_concat(iseq, &cast->
parts, scope_node, NULL, NULL,
true);
892 return ID2SYM(rb_intern_str(
string));
894 case PM_MATCH_LAST_LINE_NODE: {
896 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
900 case PM_RATIONAL_NODE:
902 case PM_REGULAR_EXPRESSION_NODE: {
904 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
906 case PM_SOURCE_ENCODING_NODE:
907 return rb_enc_from_encoding(scope_node->encoding);
908 case PM_SOURCE_LINE_NODE:
909 return INT2FIX(pm_node_line_number_cached(node, scope_node));
910 case PM_STRING_NODE: {
912 return parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
919 rb_bug(
"Don't have a literal value for node type %s", pm_node_type(PM_NODE_TYPE(node)));
934 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
935 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
944#define PM_BRANCH_COVERAGE_P(iseq) (ISEQ_COVERAGE(iseq) && ISEQ_BRANCH_COVERAGE(iseq))
958 if (!then_label) then_label = label;
959 else if (!else_label) else_label = label;
961 pm_compile_branch_condition(iseq, seq, cond, then_label, else_label, scope_node);
963 if (LIST_INSN_SIZE_ONE(seq)) {
964 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(seq));
965 if (insn->insn_id == BIN(jump) && (
LABEL *)(insn->operands[0]) == label)
return;
969 PUSH_LABEL(seq, label);
981 if (PM_NODE_TYPE_P(node, PM_INTEGER_NODE)) {
982 PM_COMPILE_NOT_POPPED(node);
985 PUSH_INSN1(ret, location, getglobal, operand);
987 PUSH_SEND(ret, location, idEq,
INT2FIX(1));
988 if (popped) PUSH_INSN(ret, location, pop);
1001 int again = !(flip_flop_node->
base.
flags & PM_RANGE_FLAGS_EXCLUDE_END);
1003 rb_num_t count = ISEQ_FLIP_CNT_INCREMENT(ISEQ_BODY(iseq)->local_iseq) + VM_SVAR_FLIPFLOP_START;
1006 PUSH_INSN2(ret, location, getspecial, key,
INT2FIX(0));
1007 PUSH_INSNL(ret, location, branchif, lend);
1009 if (flip_flop_node->
left) {
1010 pm_compile_flip_flop_bound(iseq, flip_flop_node->
left, ret, popped, scope_node);
1013 PUSH_INSN(ret, location, putnil);
1016 PUSH_INSNL(ret, location, branchunless, else_label);
1017 PUSH_INSN1(ret, location, putobject,
Qtrue);
1018 PUSH_INSN1(ret, location, setspecial, key);
1020 PUSH_INSNL(ret, location, jump, then_label);
1023 PUSH_LABEL(ret, lend);
1024 if (flip_flop_node->
right) {
1025 pm_compile_flip_flop_bound(iseq, flip_flop_node->
right, ret, popped, scope_node);
1028 PUSH_INSN(ret, location, putnil);
1031 PUSH_INSNL(ret, location, branchunless, then_label);
1032 PUSH_INSN1(ret, location, putobject,
Qfalse);
1033 PUSH_INSN1(ret, location, setspecial, key);
1034 PUSH_INSNL(ret, location, jump, then_label);
1045 switch (PM_NODE_TYPE(cond)) {
1048 pm_compile_logical(iseq, ret, cast->
left, NULL, else_label, scope_node);
1055 pm_compile_logical(iseq, ret, cast->
left, then_label, NULL, scope_node);
1062 PUSH_INSNL(ret, location, jump, else_label);
1065 case PM_IMAGINARY_NODE:
1066 case PM_INTEGER_NODE:
1067 case PM_LAMBDA_NODE:
1068 case PM_RATIONAL_NODE:
1069 case PM_REGULAR_EXPRESSION_NODE:
1070 case PM_STRING_NODE:
1071 case PM_SYMBOL_NODE:
1073 PUSH_INSNL(ret, location, jump, then_label);
1075 case PM_FLIP_FLOP_NODE:
1076 pm_compile_flip_flop((
const pm_flip_flop_node_t *) cond, else_label, then_label, iseq, location.
line, ret,
false, scope_node);
1078 case PM_DEFINED_NODE: {
1080 pm_compile_defined_expr(iseq, cast->
value, &location, ret,
false, scope_node,
true);
1084 DECL_ANCHOR(cond_seq);
1085 pm_compile_node(iseq, cond, cond_seq,
false, scope_node);
1087 if (LIST_INSN_SIZE_ONE(cond_seq)) {
1088 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(cond_seq));
1090 if (insn->insn_id == BIN(putobject)) {
1091 if (
RTEST(insn->operands[0])) {
1092 PUSH_INSNL(ret, location, jump, then_label);
1097 PUSH_INSNL(ret, location, jump, else_label);
1103 PUSH_SEQ(ret, cond_seq);
1108 PUSH_INSNL(ret, location, branchunless, else_label);
1109 PUSH_INSNL(ret, location, jump, then_label);
1119 LABEL *then_label = NEW_LABEL(location.
line);
1120 LABEL *else_label = NEW_LABEL(location.
line);
1121 LABEL *end_label = NULL;
1123 DECL_ANCHOR(cond_seq);
1124 pm_compile_branch_condition(iseq, cond_seq, predicate, then_label, else_label, scope_node);
1125 PUSH_SEQ(ret, cond_seq);
1130 if (then_label->refcnt && else_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1131 conditional_location = pm_code_location(scope_node, node);
1132 branches = decl_branch_base(iseq, (
int) node->
node_id, &conditional_location,
type == PM_IF_NODE ?
"if" :
"unless");
1135 if (then_label->refcnt) {
1136 PUSH_LABEL(ret, then_label);
1138 DECL_ANCHOR(then_seq);
1140 if (statements != NULL) {
1141 pm_compile_node(iseq, (
const pm_node_t *) statements, then_seq, popped, scope_node);
1144 PUSH_SYNTHETIC_PUTNIL(then_seq, iseq);
1147 if (else_label->refcnt) {
1149 if (PM_BRANCH_COVERAGE_P(iseq)) {
1152 if (statements != NULL) {
1153 branch_location = pm_code_location(scope_node, (
const pm_node_t *) statements);
1154 }
else if (
type == PM_IF_NODE) {
1157 .beg_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column },
1158 .end_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column }
1161 branch_location = conditional_location;
1164 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
type == PM_IF_NODE ?
"then" :
"else", branches);
1167 end_label = NEW_LABEL(location.
line);
1168 PUSH_INSNL(then_seq, location, jump, end_label);
1169 if (!popped) PUSH_INSN(then_seq, location, pop);
1172 PUSH_SEQ(ret, then_seq);
1175 if (else_label->refcnt) {
1176 PUSH_LABEL(ret, else_label);
1178 DECL_ANCHOR(else_seq);
1180 if (subsequent != NULL) {
1181 pm_compile_node(iseq, subsequent, else_seq, popped, scope_node);
1184 PUSH_SYNTHETIC_PUTNIL(else_seq, iseq);
1188 if (then_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1191 if (subsequent == NULL) {
1192 branch_location = conditional_location;
1193 }
else if (PM_NODE_TYPE_P(subsequent, PM_ELSE_NODE)) {
1197 branch_location = pm_code_location(scope_node, (
const pm_node_t *) subsequent);
1200 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 1,
type == PM_IF_NODE ?
"else" :
"then", branches);
1203 PUSH_SEQ(ret, else_seq);
1207 PUSH_LABEL(ret, end_label);
1221 LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
1222 LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
1223 LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
1225 LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(location.
line);
1226 LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(location.
line);
1227 LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(location.
line);
1228 LABEL *end_label = NEW_LABEL(location.
line);
1229 LABEL *adjust_label = NEW_LABEL(location.
line);
1231 LABEL *next_catch_label = NEW_LABEL(location.
line);
1232 LABEL *tmp_label = NULL;
1238 push_ensure_entry(iseq, &enl, NULL, NULL);
1241 if (flags & PM_LOOP_FLAGS_BEGIN_MODIFIER) {
1242 tmp_label = NEW_LABEL(location.
line);
1243 PUSH_INSNL(ret, location, jump, tmp_label);
1247 PUSH_INSNL(ret, location, jump, next_label);
1250 PUSH_LABEL(ret, adjust_label);
1251 PUSH_INSN(ret, location, putnil);
1252 PUSH_LABEL(ret, next_catch_label);
1253 PUSH_INSN(ret, location, pop);
1254 PUSH_INSNL(ret, location, jump, next_label);
1255 if (tmp_label) PUSH_LABEL(ret, tmp_label);
1257 PUSH_LABEL(ret, redo_label);
1260 if (PM_BRANCH_COVERAGE_P(iseq)) {
1262 VALUE branches = decl_branch_base(iseq, (
int) node->
node_id, &loop_location,
type == PM_WHILE_NODE ?
"while" :
"until");
1264 rb_code_location_t branch_location = statements != NULL ? pm_code_location(scope_node, (
const pm_node_t *) statements) : loop_location;
1265 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
"body", branches);
1268 if (statements != NULL) PM_COMPILE_POPPED((
const pm_node_t *) statements);
1269 PUSH_LABEL(ret, next_label);
1271 if (
type == PM_WHILE_NODE) {
1272 pm_compile_branch_condition(iseq, ret, predicate, redo_label, end_label, scope_node);
1274 else if (
type == PM_UNTIL_NODE) {
1275 pm_compile_branch_condition(iseq, ret, predicate, end_label, redo_label, scope_node);
1278 PUSH_LABEL(ret, end_label);
1279 PUSH_ADJUST_RESTORE(ret, adjust_label);
1280 PUSH_INSN(ret, location, putnil);
1282 PUSH_LABEL(ret, break_label);
1283 if (popped) PUSH_INSN(ret, location, pop);
1285 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, NULL, break_label);
1286 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label, NULL, next_catch_label);
1287 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, NULL, ISEQ_COMPILE_DATA(iseq)->redo_label);
1289 ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
1290 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
1291 ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
1292 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->prev;
1307 for (level = 0; level < start_depth; level++) {
1308 scope_node = scope_node->previous;
1311 while (!pm_index_lookup_table_lookup(&scope_node->
index_lookup_table, constant_id, &local_index))
1315 if (scope_node->previous) {
1316 scope_node = scope_node->previous;
1321 rb_bug(
"Local with constant_id %u does not exist", (
unsigned int) constant_id);
1325 lindex.level = level;
1326 lindex.index = scope_node->local_table_for_iseq_size - (int) local_index;
1339 RUBY_ASSERT(constant_id >= 1 && constant_id <= pm_parser_constants_size(scope_node->parser));
1340 return scope_node->constants[constant_id - 1];
1346 debugs(
"[new_child_iseq]> ---------------------------------------\n");
1347 int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
1348 rb_iseq_t *ret_iseq = pm_iseq_build(node, name,
1349 rb_iseq_path(iseq), rb_iseq_realpath(iseq),
1351 isolated_depth ? isolated_depth + 1 : 0,
1352 type, ISEQ_COMPILE_DATA(iseq)->option);
1353 debugs(
"[new_child_iseq]< ---------------------------------------\n");
1360 switch (PM_NODE_TYPE(node)) {
1361 case PM_CONSTANT_READ_NODE:
1363 case PM_CONSTANT_PATH_NODE:
1366 if (!parent)
return TRUE;
1367 return pm_cpath_const_p(parent);
1377 if (PM_NODE_TYPE_P(node, PM_CONSTANT_PATH_NODE)) {
1383 int flags = VM_DEFINECLASS_FLAG_SCOPED;
1384 if (!pm_cpath_const_p(parent)) {
1385 flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
1391 PUSH_INSN1(ret, *node_location, putobject,
rb_cObject);
1392 return VM_DEFINECLASS_FLAG_SCOPED;
1397 PUSH_INSN1(ret, *node_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
1407pm_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)
1411 LABEL *lcfin = NEW_LABEL(location.
line);
1412 LABEL *lskip = NULL;
1414 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
1415 ID id_read_name = pm_constant_id_lookup(scope_node, read_name);
1417 PM_COMPILE_NOT_POPPED(receiver);
1419 lskip = NEW_LABEL(location.
line);
1420 PUSH_INSN(ret, location, dup);
1421 PUSH_INSNL(ret, location, branchnil, lskip);
1424 PUSH_INSN(ret, location, dup);
1425 PUSH_SEND_WITH_FLAG(ret, location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
1426 if (!popped) PUSH_INSN(ret, location, dup);
1429 PUSH_INSNL(ret, location, branchunless, lcfin);
1432 PUSH_INSNL(ret, location, branchif, lcfin);
1435 if (!popped) PUSH_INSN(ret, location, pop);
1436 PM_COMPILE_NOT_POPPED(value);
1439 PUSH_INSN(ret, location, swap);
1440 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
1443 ID id_write_name = pm_constant_id_lookup(scope_node, write_name);
1444 PUSH_SEND_WITH_FLAG(ret, location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
1445 PUSH_INSNL(ret, location, jump, lfin);
1447 PUSH_LABEL(ret, lcfin);
1448 if (!popped) PUSH_INSN(ret, location, swap);
1450 PUSH_LABEL(ret, lfin);
1452 if (lskip && popped) PUSH_LABEL(ret, lskip);
1453 PUSH_INSN(ret, location, pop);
1454 if (lskip && !popped) PUSH_LABEL(ret, lskip);
1473 const int max_stack_length = 0x100;
1474 const unsigned int min_tmp_hash_length = 0x800;
1476 int stack_length = 0;
1477 bool first_chunk =
true;
1478 bool owned_hash =
false;
1484 bool static_literal =
false;
1486 DECL_ANCHOR(anchor);
1489#define FLUSH_CHUNK \
1490 if (stack_length) { \
1491 if (first_chunk) { \
1492 PUSH_SEQ(ret, anchor); \
1493 PUSH_INSN1(ret, location, newhash, INT2FIX(stack_length)); \
1494 first_chunk = false; \
1497 PUSH_INSN1(ret, location, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); \
1498 PUSH_INSN(ret, location, swap); \
1499 PUSH_SEQ(ret, anchor); \
1501 PUSH_SEND(ret, location, id_core_hash_merge_bang_ptr, INT2FIX(stack_length + 1)); \
1504 PUSH_SEND(ret, location, id_core_hash_merge_ptr, INT2FIX(stack_length + 1)); \
1505 owned_hash = true; \
1508 INIT_ANCHOR(anchor); \
1512 for (
size_t index = 0; index < elements->
size; index++) {
1515 switch (PM_NODE_TYPE(element)) {
1516 case PM_ASSOC_NODE: {
1519 (shareability == 0) &&
1520 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && (
1521 (!static_literal && ((index + min_tmp_hash_length) < elements->
size)) ||
1522 (first_chunk && stack_length == 0)
1527 while (index + count < elements->size && PM_NODE_FLAG_P(elements->
nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++;
1529 bool first_element = first_chunk && stack_length == 0;
1531 if (first_element || count >= min_tmp_hash_length) {
1537 for (
size_t tmp_end = index + count; index < tmp_end; index++) {
1541 pm_static_literal_value(iseq, assoc->key, scope_node),
1542 pm_static_literal_value(iseq, assoc->value, scope_node)
1557 if (count == elements->
size) {
1559 PUSH_INSN1(ret, location, duphash, hash);
1565 first_chunk =
false;
1568 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1569 PUSH_INSN(ret, location, swap);
1570 PUSH_INSN1(ret, location, putobject, hash);
1571 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1577 static_literal =
true;
1581 static_literal =
false;
1586 if (shareability == 0) {
1587 pm_compile_node(iseq, element, anchor,
false, scope_node);
1591 pm_compile_shareable_constant_value(iseq, assoc->
key, shareability, path, ret, scope_node,
false);
1592 pm_compile_shareable_constant_value(iseq, assoc->
value, shareability, path, ret, scope_node,
false);
1595 if ((stack_length += 2) >= max_stack_length) FLUSH_CHUNK;
1598 case PM_ASSOC_SPLAT_NODE: {
1602 bool empty_hash = assoc_splat->
value != NULL && (
1603 (PM_NODE_TYPE_P(assoc_splat->
value, PM_HASH_NODE) && ((
const pm_hash_node_t *) assoc_splat->
value)->elements.size == 0) ||
1604 PM_NODE_TYPE_P(assoc_splat->
value, PM_NIL_NODE)
1607 bool first_element = first_chunk && stack_length == 0;
1608 bool last_element = index == elements->
size - 1;
1609 bool only_element = first_element && last_element;
1616 PUSH_INSN(ret, location, putnil);
1622 if (shareability == 0) {
1623 PM_COMPILE_NOT_POPPED(element);
1626 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1634 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1635 if (shareability == 0) {
1636 PM_COMPILE_NOT_POPPED(element);
1639 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1641 PUSH_SEND(ret, location, id_core_hash_coerce,
INT2FIX(1));
1645 if (!first_element) {
1646 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1647 PUSH_INSN(ret, location, swap);
1650 if (shareability == 0) {
1651 PM_COMPILE_NOT_POPPED(element);
1654 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1657 if (!first_element) {
1659 PUSH_SEND(ret, location, id_core_hash_merge_bang_kwd,
INT2FIX(2));
1662 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1668 first_chunk =
false;
1669 static_literal =
false;
1673 RUBY_ASSERT(
"Invalid node type for hash" &&
false);
1682#define SPLATARRAY_FALSE 0
1683#define SPLATARRAY_TRUE 1
1684#define DUP_SINGLE_KW_SPLAT 2
1693 bool has_splat =
false;
1694 bool has_keyword_splat =
false;
1696 if (arguments_node == NULL) {
1697 if (*flags & VM_CALL_FCALL) {
1698 *flags |= VM_CALL_VCALL;
1703 has_keyword_splat = PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT);
1707 int post_splat_counter = 0;
1711 switch (PM_NODE_TYPE(argument)) {
1713 case PM_KEYWORD_HASH_NODE: {
1717 if (has_keyword_splat || has_splat) {
1718 *flags |= VM_CALL_KW_SPLAT;
1719 has_keyword_splat =
true;
1721 if (elements->
size > 1 || !(elements->
size == 1 && PM_NODE_TYPE_P(elements->
nodes[0], PM_ASSOC_SPLAT_NODE))) {
1725 *flags |= VM_CALL_KW_SPLAT_MUT;
1726 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1728 else if (*dup_rest & DUP_SINGLE_KW_SPLAT) {
1729 *flags |= VM_CALL_KW_SPLAT_MUT;
1730 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1731 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1732 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1733 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1736 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1742 if (PM_NODE_FLAG_P(keyword_arg, PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS)) {
1747 VALUE stored_indices = rb_hash_new();
1751 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1756 VALUE keyword = pm_static_literal_value(iseq, assoc->key, scope_node);
1757 VALUE stored_index = rb_hash_aref(stored_indices, keyword);
1762 if (!
NIL_P(stored_index)) {
1770 rb_hash_aset(stored_indices, keyword,
ULONG2NUM(element_index));
1775 if (size > VM_CALL_KW_LEN_MAX) {
1776 COMPILE_ERROR(iseq, node_location->
line,
"too many keyword arguments (%d, maximum is %d)",
1777 (
int) size, (
int) VM_CALL_KW_LEN_MAX);
1781 *flags |= VM_CALL_KWARG;
1783 VALUE *keywords = (*kw_arg)->keywords;
1784 (*kw_arg)->references = 0;
1785 (*kw_arg)->keyword_len = (int) size;
1787 size_t keyword_index = 0;
1788 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1793 keywords[keyword_index++] = pm_static_literal_value(iseq, assoc->key, scope_node);
1797 PM_COMPILE(assoc->value);
1806 *flags |= VM_CALL_KW_SPLAT;
1808 size_t size = elements->
size;
1813 *flags |= VM_CALL_KW_SPLAT_MUT;
1816 for (
size_t element_index = 0; element_index < size; element_index++) {
1818 PM_COMPILE_NOT_POPPED(assoc->key);
1819 PM_COMPILE_NOT_POPPED(assoc->value);
1822 PUSH_INSN1(ret, location, newhash,
INT2FIX(size * 2));
1827 case PM_SPLAT_NODE: {
1828 *flags |= VM_CALL_ARGS_SPLAT;
1832 PM_COMPILE_NOT_POPPED(splat_node->
expression);
1835 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1836 PUSH_GETLOCAL(ret, location, index.index, index.level);
1839 bool first_splat = !has_splat;
1847 if (index + 1 < arguments->
size || has_regular_blockarg) {
1848 PUSH_INSN1(ret, location, splatarray, (*dup_rest & SPLATARRAY_TRUE) ?
Qtrue :
Qfalse);
1849 if (*dup_rest & SPLATARRAY_TRUE) *dup_rest &= ~SPLATARRAY_TRUE;
1857 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1867 PUSH_INSN(ret, location, concattoarray);
1871 post_splat_counter = 0;
1875 case PM_FORWARDING_ARGUMENTS_NODE: {
1876 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
1878 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
1879 *flags |= VM_CALL_FORWARDING;
1881 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
1882 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1894 *flags |= VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_BLOCKARG | VM_CALL_KW_SPLAT;
1901 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1902 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1906 PUSH_INSN(ret, location, concattoarray);
1908 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1912 pm_local_index_t pow_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1913 PUSH_GETLOCAL(ret, location, pow_local.index, pow_local.level);
1916 pm_local_index_t and_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
1917 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(and_local.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(and_local.level));
1922 post_splat_counter++;
1923 PM_COMPILE_NOT_POPPED(argument);
1947 if (index == arguments->
size - 1) {
1949 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1954 switch (PM_NODE_TYPE(next_arg)) {
1956 case PM_KEYWORD_HASH_NODE: {
1957 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1958 PUSH_INSN(ret, location, concatarray);
1961 case PM_SPLAT_NODE: {
1962 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1963 PUSH_INSN(ret, location, concatarray);
1966 case PM_FORWARDING_ARGUMENTS_NODE: {
1967 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1983 if (has_splat) orig_argc++;
1984 if (has_keyword_splat) orig_argc++;
1993pm_setup_args_dup_rest_p(
const pm_node_t *node)
1995 switch (PM_NODE_TYPE(node)) {
1996 case PM_BACK_REFERENCE_READ_NODE:
1997 case PM_CLASS_VARIABLE_READ_NODE:
1998 case PM_CONSTANT_READ_NODE:
2001 case PM_GLOBAL_VARIABLE_READ_NODE:
2002 case PM_IMAGINARY_NODE:
2003 case PM_INSTANCE_VARIABLE_READ_NODE:
2004 case PM_INTEGER_NODE:
2005 case PM_LAMBDA_NODE:
2006 case PM_LOCAL_VARIABLE_READ_NODE:
2008 case PM_NUMBERED_REFERENCE_READ_NODE:
2009 case PM_RATIONAL_NODE:
2010 case PM_REGULAR_EXPRESSION_NODE:
2012 case PM_STRING_NODE:
2013 case PM_SYMBOL_NODE:
2016 case PM_CONSTANT_PATH_NODE: {
2018 if (cast->
parent != NULL) {
2019 return pm_setup_args_dup_rest_p(cast->
parent);
2023 case PM_IMPLICIT_NODE:
2025 case PM_ARRAY_NODE: {
2027 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2028 if (pm_setup_args_dup_rest_p(cast->
elements.
nodes[index])) {
2045 int dup_rest = SPLATARRAY_TRUE;
2048 size_t arguments_size;
2053 arguments_node != NULL &&
2054 (arguments = &arguments_node->
arguments, arguments_size = arguments->
size) >= 2 &&
2055 PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_SPLAT) &&
2056 !PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_MULTIPLE_SPLATS) &&
2057 PM_NODE_TYPE_P(arguments->
nodes[arguments_size - 1], PM_KEYWORD_HASH_NODE)
2062 dup_rest = SPLATARRAY_FALSE;
2067 for (
size_t index = 0; dup_rest == SPLATARRAY_FALSE && index < elements->
size; index++) {
2070 switch (PM_NODE_TYPE(element)) {
2071 case PM_ASSOC_NODE: {
2073 if (pm_setup_args_dup_rest_p(assoc->
key) || pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2076 case PM_ASSOC_SPLAT_NODE: {
2078 if (assoc->
value != NULL && pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2087 int initial_dup_rest = dup_rest;
2090 if (block && PM_NODE_TYPE_P(block, PM_BLOCK_ARGUMENT_NODE)) {
2094 bool regular_block_arg =
true;
2097 if (block_expr && pm_setup_args_dup_rest_p(block_expr)) {
2098 dup_rest = SPLATARRAY_TRUE | DUP_SINGLE_KW_SPLAT;
2099 initial_dup_rest = dup_rest;
2102 DECL_ANCHOR(block_arg);
2103 pm_compile_node(iseq, block, block_arg,
false, scope_node);
2105 *flags |= VM_CALL_ARGS_BLOCKARG;
2107 if (LIST_INSN_SIZE_ONE(block_arg)) {
2109 if (IS_INSN(elem)) {
2111 if (iobj->insn_id == BIN(getblockparam)) {
2112 iobj->insn_id = BIN(getblockparamproxy);
2119 regular_block_arg =
false;
2123 argc = pm_setup_args_core(arguments_node, block, flags, regular_block_arg, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2124 PUSH_SEQ(ret, block_arg);
2127 argc = pm_setup_args_core(arguments_node, block, flags,
false, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2134 if (*flags & VM_CALL_ARGS_SPLAT && dup_rest != initial_dup_rest) {
2135 *flags |= VM_CALL_ARGS_SPLAT_MUT;
2155 if (!popped) PUSH_INSN(ret, location, putnil);
2157 PM_COMPILE_NOT_POPPED(node->
receiver);
2159 int boff = (node->
block == NULL ? 0 : 1);
2160 int flag = PM_NODE_TYPE_P(node->
receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2162 int argc = pm_setup_args(node->
arguments, (
const pm_node_t *) node->
block, &flag, &keywords, iseq, ret, scope_node, node_location);
2164 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2166 PUSH_INSN(ret, location, splatkw);
2169 PUSH_INSN(ret, location, dup);
2170 PUSH_INSN(ret, location, splatkw);
2171 PUSH_INSN(ret, location, pop);
2175 int dup_argn = argc + 1 + boff;
2176 int keyword_len = 0;
2179 keyword_len = keywords->keyword_len;
2180 dup_argn += keyword_len;
2183 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2184 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2185 PM_COMPILE_NOT_POPPED(node->
value);
2188 PUSH_SEND(ret, location, id_operator,
INT2FIX(1));
2191 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2193 if (flag & VM_CALL_ARGS_SPLAT) {
2194 if (flag & VM_CALL_KW_SPLAT) {
2195 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2197 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2198 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2199 flag |= VM_CALL_ARGS_SPLAT_MUT;
2202 PUSH_INSN(ret, location, swap);
2203 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2204 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2205 PUSH_INSN(ret, location, pop);
2209 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2210 PUSH_INSN(ret, location, swap);
2211 PUSH_INSN(ret, location, pop);
2213 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2214 PUSH_INSN(ret, location, swap);
2215 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2216 PUSH_INSN(ret, location, swap);
2217 flag |= VM_CALL_ARGS_SPLAT_MUT;
2219 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2221 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2222 PUSH_INSN(ret, location, pop);
2223 PUSH_INSN(ret, location, pop);
2227 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2229 else if (flag & VM_CALL_KW_SPLAT) {
2231 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2232 PUSH_INSN(ret, location, swap);
2233 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2234 PUSH_INSN(ret, location, pop);
2236 PUSH_INSN(ret, location, swap);
2237 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2239 else if (keyword_len) {
2240 PUSH_INSN(ret, location, dup);
2241 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 2));
2242 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2243 PUSH_INSN(ret, location, pop);
2244 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2248 PUSH_INSN(ret, location, swap);
2250 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2253 PUSH_INSN(ret, location, pop);
2272 if (!popped) PUSH_INSN(ret, location, putnil);
2273 PM_COMPILE_NOT_POPPED(receiver);
2275 int boff = (block == NULL ? 0 : 1);
2276 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2278 int argc = pm_setup_args(arguments, (
const pm_node_t *) block, &flag, &keywords, iseq, ret, scope_node, node_location);
2280 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2282 PUSH_INSN(ret, location, splatkw);
2285 PUSH_INSN(ret, location, dup);
2286 PUSH_INSN(ret, location, splatkw);
2287 PUSH_INSN(ret, location, pop);
2291 int dup_argn = argc + 1 + boff;
2292 int keyword_len = 0;
2295 keyword_len = keywords->keyword_len;
2296 dup_argn += keyword_len;
2299 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2300 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2302 LABEL *label = NEW_LABEL(location.
line);
2305 PUSH_INSN(ret, location, dup);
2306 if (PM_NODE_TYPE_P(node, PM_INDEX_AND_WRITE_NODE)) {
2307 PUSH_INSNL(ret, location, branchunless, label);
2310 PUSH_INSNL(ret, location, branchif, label);
2313 PUSH_INSN(ret, location, pop);
2314 PM_COMPILE_NOT_POPPED(value);
2317 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2320 if (flag & VM_CALL_ARGS_SPLAT) {
2321 if (flag & VM_CALL_KW_SPLAT) {
2322 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2323 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2324 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2325 flag |= VM_CALL_ARGS_SPLAT_MUT;
2328 PUSH_INSN(ret, location, swap);
2329 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2330 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2331 PUSH_INSN(ret, location, pop);
2335 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2336 PUSH_INSN(ret, location, swap);
2337 PUSH_INSN(ret, location, pop);
2339 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2340 PUSH_INSN(ret, location, swap);
2341 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2342 PUSH_INSN(ret, location, swap);
2343 flag |= VM_CALL_ARGS_SPLAT_MUT;
2345 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2347 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2348 PUSH_INSN(ret, location, pop);
2349 PUSH_INSN(ret, location, pop);
2353 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2355 else if (flag & VM_CALL_KW_SPLAT) {
2357 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2358 PUSH_INSN(ret, location, swap);
2359 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2360 PUSH_INSN(ret, location, pop);
2363 PUSH_INSN(ret, location, swap);
2364 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2366 else if (keyword_len) {
2367 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2368 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 0));
2369 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2373 PUSH_INSN(ret, location, swap);
2375 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2378 PUSH_INSN(ret, location, pop);
2379 PUSH_INSNL(ret, location, jump, lfin);
2380 PUSH_LABEL(ret, label);
2382 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2384 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(dup_argn + 1));
2385 PUSH_LABEL(ret, lfin);
2394#define PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE 0
2395#define PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING 1
2396#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P 2
2397#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE 3
2398#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY 4
2413 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2415 PUSH_INSN(ret, location, dup);
2416 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2418 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2419 PUSH_INSN1(ret, location, putobject, message);
2420 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2421 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2422 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2424 PUSH_INSN1(ret, location, putobject,
Qfalse);
2425 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2427 PUSH_INSN(ret, location, pop);
2428 PUSH_INSN(ret, location, pop);
2429 PUSH_LABEL(ret, match_succeeded_label);
2443 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2445 PUSH_INSN(ret, location, dup);
2446 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2448 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2449 PUSH_INSN1(ret, location, putobject, message);
2450 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2451 PUSH_INSN(ret, location, dup);
2452 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2453 PUSH_INSN1(ret, location, putobject, length);
2454 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(4));
2455 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2457 PUSH_INSN1(ret, location, putobject,
Qfalse);
2458 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2460 PUSH_INSN(ret, location, pop);
2461 PUSH_INSN(ret, location, pop);
2462 PUSH_LABEL(ret, match_succeeded_label);
2476 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2478 PUSH_INSN(ret, location, dup);
2479 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2480 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2482 VALUE operand = rb_fstring_lit(
"%p === %p does not return true");
2483 PUSH_INSN1(ret, location, putobject, operand);
2485 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2486 PUSH_INSN1(ret, location, topn,
INT2FIX(5));
2487 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2488 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2489 PUSH_INSN1(ret, location, putobject,
Qfalse);
2490 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2491 PUSH_INSN(ret, location, pop);
2492 PUSH_INSN(ret, location, pop);
2494 PUSH_LABEL(ret, match_succeeded_label);
2495 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2496 PUSH_INSN(ret, location, pop);
2497 PUSH_INSN(ret, location, pop);
2511 LABEL *matched_label = NEW_LABEL(pm_node_line_number_cached(node, scope_node));
2512 CHECK(pm_compile_pattern(iseq, scope_node, node, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
2513 PUSH_LABEL(ret, matched_label);
2523pm_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)
2527 if (use_deconstructed_cache) {
2528 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2529 PUSH_INSNL(ret, location, branchnil, deconstruct_label);
2531 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2532 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2534 PUSH_INSN(ret, location, pop);
2535 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE - 1));
2536 PUSH_INSNL(ret, location, jump, deconstructed_label);
2539 PUSH_INSNL(ret, location, jump, deconstruct_label);
2542 PUSH_LABEL(ret, deconstruct_label);
2543 PUSH_INSN(ret, location, dup);
2546 PUSH_INSN1(ret, location, putobject, operand);
2547 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2549 if (use_deconstructed_cache) {
2550 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE + 1));
2553 if (in_single_pattern) {
2554 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct"), base_index + 1));
2557 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2558 PUSH_SEND(ret, location, rb_intern(
"deconstruct"),
INT2FIX(0));
2560 if (use_deconstructed_cache) {
2561 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2564 PUSH_INSN(ret, location, dup);
2566 PUSH_INSNL(ret, location, branchunless, type_error_label);
2567 PUSH_LABEL(ret, deconstructed_label);
2581 PUSH_INSN(ret, location, dup);
2582 PM_COMPILE_NOT_POPPED(node);
2584 if (in_single_pattern) {
2585 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
2587 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
2588 if (in_single_pattern) {
2589 CHECK(pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 3));
2591 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2603 LABEL *key_error_label = NEW_LABEL(location.
line);
2604 LABEL *cleanup_label = NEW_LABEL(location.
line);
2607 kw_arg->references = 0;
2608 kw_arg->keyword_len = 2;
2609 kw_arg->keywords[0] =
ID2SYM(rb_intern(
"matchee"));
2610 kw_arg->keywords[1] =
ID2SYM(rb_intern(
"key"));
2612 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2613 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2614 PUSH_INSNL(ret, location, branchif, key_error_label);
2617 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2620 VALUE operand = rb_fstring_lit(
"%p: %s");
2621 PUSH_INSN1(ret, location, putobject, operand);
2624 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2625 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2626 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2627 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2628 PUSH_INSNL(ret, location, jump, cleanup_label);
2630 PUSH_LABEL(ret, key_error_label);
2632 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2635 VALUE operand = rb_fstring_lit(
"%p: %s");
2636 PUSH_INSN1(ret, location, putobject, operand);
2639 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2640 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2641 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2642 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2643 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2644 PUSH_SEND_R(ret, location, rb_intern(
"new"),
INT2FIX(1), NULL,
INT2FIX(VM_CALL_KWARG), kw_arg);
2645 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(1));
2646 PUSH_LABEL(ret, cleanup_label);
2648 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(7));
2649 if (!popped) PUSH_INSN(ret, location, putnil);
2650 PUSH_INSNL(ret, location, jump, done_label);
2651 PUSH_INSN1(ret, location, dupn,
INT2FIX(5));
2652 if (popped) PUSH_INSN(ret, location, putnil);
2663 switch (PM_NODE_TYPE(node)) {
2664 case PM_ARRAY_PATTERN_NODE: {
2676 const size_t posts_size = cast->
posts.
size;
2677 const size_t minimum_size = requireds_size + posts_size;
2679 bool rest_named =
false;
2680 bool use_rest_size =
false;
2682 if (cast->
rest != NULL) {
2683 rest_named = (PM_NODE_TYPE_P(cast->
rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) cast->
rest)->expression != NULL);
2684 use_rest_size = (rest_named || (!rest_named && posts_size > 0));
2687 LABEL *match_failed_label = NEW_LABEL(location.
line);
2688 LABEL *type_error_label = NEW_LABEL(location.
line);
2689 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2690 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2692 if (use_rest_size) {
2693 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2694 PUSH_INSN(ret, location, swap);
2699 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2702 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));
2704 PUSH_INSN(ret, location, dup);
2705 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2706 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2707 PUSH_SEND(ret, location, cast->
rest == NULL ? idEq : idGE,
INT2FIX(1));
2708 if (in_single_pattern) {
2709 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+)");
2710 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, message,
INT2FIX(minimum_size), base_index + 1));
2712 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2714 for (
size_t index = 0; index < requireds_size; index++) {
2716 PUSH_INSN(ret, location, dup);
2717 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2718 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2719 CHECK(pm_compile_pattern_match(iseq, scope_node, required, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2722 if (cast->
rest != NULL) {
2724 PUSH_INSN(ret, location, dup);
2725 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size));
2726 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2727 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2728 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2729 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2730 PUSH_INSN1(ret, location, setn,
INT2FIX(4));
2731 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2732 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));
2734 else if (posts_size > 0) {
2735 PUSH_INSN(ret, location, dup);
2736 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2737 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2738 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2739 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2740 PUSH_INSN(ret, location, pop);
2744 for (
size_t index = 0; index < posts_size; index++) {
2746 PUSH_INSN(ret, location, dup);
2748 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size + index));
2749 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2750 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2751 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2752 CHECK(pm_compile_pattern_match(iseq, scope_node, post, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2755 PUSH_INSN(ret, location, pop);
2756 if (use_rest_size) {
2757 PUSH_INSN(ret, location, pop);
2760 PUSH_INSNL(ret, location, jump, matched_label);
2761 PUSH_INSN(ret, location, putnil);
2762 if (use_rest_size) {
2763 PUSH_INSN(ret, location, putnil);
2766 PUSH_LABEL(ret, type_error_label);
2767 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2771 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2772 PUSH_INSN1(ret, location, putobject, operand);
2775 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2776 PUSH_INSN(ret, location, pop);
2778 PUSH_LABEL(ret, match_failed_label);
2779 PUSH_INSN(ret, location, pop);
2780 if (use_rest_size) {
2781 PUSH_INSN(ret, location, pop);
2784 PUSH_INSNL(ret, location, jump, unmatched_label);
2787 case PM_FIND_PATTERN_NODE: {
2799 LABEL *match_failed_label = NEW_LABEL(location.
line);
2800 LABEL *type_error_label = NEW_LABEL(location.
line);
2801 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2802 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2805 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2808 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));
2810 PUSH_INSN(ret, location, dup);
2811 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2812 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2813 PUSH_SEND(ret, location, idGE,
INT2FIX(1));
2814 if (in_single_pattern) {
2815 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));
2817 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2820 LABEL *while_begin_label = NEW_LABEL(location.
line);
2821 LABEL *next_loop_label = NEW_LABEL(location.
line);
2822 LABEL *find_succeeded_label = NEW_LABEL(location.
line);
2823 LABEL *find_failed_label = NEW_LABEL(location.
line);
2825 PUSH_INSN(ret, location, dup);
2826 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2828 PUSH_INSN(ret, location, dup);
2829 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2830 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2831 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2832 PUSH_LABEL(ret, while_begin_label);
2834 PUSH_INSN(ret, location, dup);
2835 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2836 PUSH_SEND(ret, location, idLE,
INT2FIX(1));
2837 PUSH_INSNL(ret, location, branchunless, find_failed_label);
2839 for (
size_t index = 0; index < size; index++) {
2840 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2841 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2844 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2845 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2848 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2849 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
requireds.
nodes[index], ret, next_loop_label, in_single_pattern,
false, base_index + 4));
2855 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2856 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2857 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2858 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2859 CHECK(pm_compile_pattern_match(iseq, scope_node, left->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4));
2865 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2866 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2867 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2868 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2869 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2870 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2871 pm_compile_pattern_match(iseq, scope_node, right->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4);
2874 PUSH_INSNL(ret, location, jump, find_succeeded_label);
2876 PUSH_LABEL(ret, next_loop_label);
2877 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
2878 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2879 PUSH_INSNL(ret, location, jump, while_begin_label);
2881 PUSH_LABEL(ret, find_failed_label);
2882 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2883 if (in_single_pattern) {
2884 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2887 VALUE operand = rb_fstring_lit(
"%p does not match to find pattern");
2888 PUSH_INSN1(ret, location, putobject, operand);
2891 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2892 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2893 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2895 PUSH_INSN1(ret, location, putobject,
Qfalse);
2896 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2898 PUSH_INSN(ret, location, pop);
2899 PUSH_INSN(ret, location, pop);
2901 PUSH_INSNL(ret, location, jump, match_failed_label);
2902 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2904 PUSH_LABEL(ret, find_succeeded_label);
2905 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2908 PUSH_INSN(ret, location, pop);
2909 PUSH_INSNL(ret, location, jump, matched_label);
2910 PUSH_INSN(ret, location, putnil);
2912 PUSH_LABEL(ret, type_error_label);
2913 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2917 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2918 PUSH_INSN1(ret, location, putobject, operand);
2921 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2922 PUSH_INSN(ret, location, pop);
2924 PUSH_LABEL(ret, match_failed_label);
2925 PUSH_INSN(ret, location, pop);
2926 PUSH_INSNL(ret, location, jump, unmatched_label);
2930 case PM_HASH_PATTERN_NODE: {
2945 LABEL *match_failed_label = NEW_LABEL(location.
line);
2946 LABEL *type_error_label = NEW_LABEL(location.
line);
2949 if (has_keys && !has_rest) {
2952 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2954 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
2965 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2968 PUSH_INSN(ret, location, dup);
2971 VALUE operand =
ID2SYM(rb_intern(
"deconstruct_keys"));
2972 PUSH_INSN1(ret, location, putobject, operand);
2975 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2976 if (in_single_pattern) {
2977 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct_keys"), base_index + 1));
2979 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2982 PUSH_INSN(ret, location, putnil);
2987 PUSH_INSN1(ret, location, duparray, keys);
2990 PUSH_SEND(ret, location, rb_intern(
"deconstruct_keys"),
INT2FIX(1));
2992 PUSH_INSN(ret, location, dup);
2994 PUSH_INSNL(ret, location, branchunless, type_error_label);
2997 PUSH_SEND(ret, location, rb_intern(
"dup"),
INT2FIX(0));
3001 DECL_ANCHOR(match_values);
3003 for (
size_t index = 0; index < cast->
elements.
size; index++) {
3005 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
3012 PUSH_INSN(ret, location, dup);
3013 PUSH_INSN1(ret, location, putobject, symbol);
3014 PUSH_SEND(ret, location, rb_intern(
"key?"),
INT2FIX(1));
3016 if (in_single_pattern) {
3017 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3019 PUSH_INSN(ret, location, dup);
3020 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3025 PUSH_INSN1(ret, location, putobject, operand);
3028 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 2));
3029 PUSH_INSN1(ret, location, putobject,
Qtrue);
3030 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 3));
3031 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
3032 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
3033 PUSH_INSN1(ret, location, putobject, symbol);
3034 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
3036 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(4));
3037 PUSH_LABEL(ret, match_succeeded_label);
3040 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3041 PUSH_INSN(match_values, location, dup);
3042 PUSH_INSN1(match_values, location, putobject, symbol);
3043 PUSH_SEND(match_values, location, has_rest ? rb_intern(
"delete") : idAREF,
INT2FIX(1));
3046 if (PM_NODE_TYPE_P(value, PM_IMPLICIT_NODE)) {
3050 CHECK(pm_compile_pattern_match(iseq, scope_node, value, match_values, match_failed_label, in_single_pattern,
false, base_index + 1));
3053 PUSH_SEQ(ret, match_values);
3056 PUSH_INSN(ret, location, dup);
3057 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3058 if (in_single_pattern) {
3059 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p is not empty"), base_index + 1));
3061 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3065 switch (PM_NODE_TYPE(cast->
rest)) {
3066 case PM_NO_KEYWORDS_PARAMETER_NODE: {
3067 PUSH_INSN(ret, location, dup);
3068 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3069 if (in_single_pattern) {
3070 pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"rest of %p is not empty"), base_index + 1);
3072 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3075 case PM_ASSOC_SPLAT_NODE: {
3077 PUSH_INSN(ret, location, dup);
3078 pm_compile_pattern_match(iseq, scope_node, splat->value, ret, match_failed_label, in_single_pattern,
false, base_index + 1);
3082 rb_bug(
"unreachable");
3087 PUSH_INSN(ret, location, pop);
3088 PUSH_INSNL(ret, location, jump, matched_label);
3089 PUSH_INSN(ret, location, putnil);
3091 PUSH_LABEL(ret, type_error_label);
3092 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
3096 VALUE operand = rb_fstring_lit(
"deconstruct_keys must return Hash");
3097 PUSH_INSN1(ret, location, putobject, operand);
3100 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
3101 PUSH_INSN(ret, location, pop);
3103 PUSH_LABEL(ret, match_failed_label);
3104 PUSH_INSN(ret, location, pop);
3105 PUSH_INSNL(ret, location, jump, unmatched_label);
3108 case PM_CAPTURE_PATTERN_NODE: {
3120 LABEL *match_failed_label = NEW_LABEL(location.
line);
3122 PUSH_INSN(ret, location, dup);
3123 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
value, ret, match_failed_label, in_single_pattern, use_deconstructed_cache, base_index + 1));
3124 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));
3125 PUSH_INSN(ret, location, putnil);
3127 PUSH_LABEL(ret, match_failed_label);
3128 PUSH_INSN(ret, location, pop);
3129 PUSH_INSNL(ret, location, jump, unmatched_label);
3133 case PM_LOCAL_VARIABLE_TARGET_NODE: {
3140 PUSH_SETLOCAL(ret, location, index.index, index.level);
3141 PUSH_INSNL(ret, location, jump, matched_label);
3144 case PM_ALTERNATION_PATTERN_NODE: {
3149 LABEL *matched_left_label = NEW_LABEL(location.
line);
3150 LABEL *unmatched_left_label = NEW_LABEL(location.
line);
3154 PUSH_INSN(ret, location, dup);
3155 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));
3160 PUSH_LABEL(ret, matched_left_label);
3161 PUSH_INSN(ret, location, pop);
3162 PUSH_INSNL(ret, location, jump, matched_label);
3163 PUSH_INSN(ret, location, putnil);
3167 PUSH_LABEL(ret, unmatched_left_label);
3168 CHECK(pm_compile_pattern(iseq, scope_node, cast->
right, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3171 case PM_PARENTHESES_NODE:
3176 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);
3177 case PM_PINNED_EXPRESSION_NODE:
3185 case PM_CLASS_VARIABLE_READ_NODE:
3186 case PM_CONSTANT_PATH_NODE:
3187 case PM_CONSTANT_READ_NODE:
3190 case PM_GLOBAL_VARIABLE_READ_NODE:
3191 case PM_IMAGINARY_NODE:
3192 case PM_INSTANCE_VARIABLE_READ_NODE:
3193 case PM_IT_LOCAL_VARIABLE_READ_NODE:
3194 case PM_INTEGER_NODE:
3195 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
3196 case PM_INTERPOLATED_STRING_NODE:
3197 case PM_INTERPOLATED_SYMBOL_NODE:
3198 case PM_INTERPOLATED_X_STRING_NODE:
3199 case PM_LAMBDA_NODE:
3200 case PM_LOCAL_VARIABLE_READ_NODE:
3202 case PM_SOURCE_ENCODING_NODE:
3203 case PM_SOURCE_FILE_NODE:
3204 case PM_SOURCE_LINE_NODE:
3206 case PM_RATIONAL_NODE:
3207 case PM_REGULAR_EXPRESSION_NODE:
3209 case PM_STRING_NODE:
3210 case PM_SYMBOL_NODE:
3212 case PM_X_STRING_NODE: {
3216 PM_COMPILE_NOT_POPPED(node);
3217 if (in_single_pattern) {
3218 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
3221 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
3223 if (in_single_pattern) {
3224 pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 2);
3227 PUSH_INSNL(ret, location, branchif, matched_label);
3228 PUSH_INSNL(ret, location, jump, unmatched_label);
3231 case PM_PINNED_VARIABLE_NODE: {
3237 CHECK(pm_compile_pattern(iseq, scope_node, cast->
variable, ret, matched_label, unmatched_label, in_single_pattern,
true, base_index));
3241 case PM_UNLESS_NODE: {
3256 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3271 CHECK(pm_compile_pattern_match(iseq, scope_node, statement, ret, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3272 PM_COMPILE_NOT_POPPED(predicate);
3274 if (in_single_pattern) {
3275 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3277 PUSH_INSN(ret, location, dup);
3278 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3279 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3282 PUSH_INSNL(ret, location, branchunless, match_succeeded_label);
3286 VALUE operand = rb_fstring_lit(
"guard clause does not return true");
3287 PUSH_INSN1(ret, location, putobject, operand);
3290 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
3291 PUSH_INSN1(ret, location, putobject,
Qfalse);
3292 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
3294 PUSH_INSN(ret, location, pop);
3295 PUSH_INSN(ret, location, pop);
3297 PUSH_LABEL(ret, match_succeeded_label);
3300 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3301 PUSH_INSNL(ret, location, branchunless, unmatched_label);
3304 PUSH_INSNL(ret, location, branchif, unmatched_label);
3307 PUSH_INSNL(ret, location, jump, matched_label);
3314 rb_bug(
"Unexpected node type in pattern matching expression: %s", pm_node_type(PM_NODE_TYPE(node)));
3321#undef PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE
3322#undef PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING
3323#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P
3324#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE
3325#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY
3336 scope->parameters = NULL;
3338 scope->local_table_for_iseq_size = 0;
3346 scope->base.
type = PM_SCOPE_NODE;
3349 scope->previous = previous;
3352 switch (PM_NODE_TYPE(node)) {
3353 case PM_BLOCK_NODE: {
3355 scope->body = cast->
body;
3356 scope->locals = cast->
locals;
3360 case PM_CLASS_NODE: {
3362 scope->body = cast->
body;
3363 scope->locals = cast->
locals;
3369 scope->body = cast->body;
3370 scope->locals = cast->locals;
3373 case PM_ENSURE_NODE: {
3389 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
3394 case PM_LAMBDA_NODE: {
3397 scope->body = cast->
body;
3398 scope->locals = cast->
locals;
3401 case PM_MODULE_NODE: {
3403 scope->body = cast->
body;
3404 scope->locals = cast->
locals;
3407 case PM_POST_EXECUTION_NODE: {
3412 case PM_PROGRAM_NODE: {
3415 scope->locals = cast->locals;
3418 case PM_RESCUE_NODE: {
3423 case PM_RESCUE_MODIFIER_NODE: {
3428 case PM_SINGLETON_CLASS_NODE: {
3430 scope->body = cast->
body;
3431 scope->locals = cast->
locals;
3434 case PM_STATEMENTS_NODE: {
3440 rb_bug(
"unreachable");
3469 iobj = IS_INSN(last_elem) ? (
INSN*) last_elem : (
INSN*) get_prev_insn((
INSN*) last_elem);
3470 while (!IS_INSN_ID(iobj, send) && !IS_INSN_ID(iobj, invokesuper) && !IS_INSN_ID(iobj, sendforward) && !IS_INSN_ID(iobj, invokesuperforward)) {
3471 iobj = (
INSN*) get_prev_insn(iobj);
3473 ELEM_INSERT_NEXT(&iobj->link, (
LINK_ELEMENT*) retry_end_l);
3478 if (&iobj->link == LAST_ELEMENT(ret)) {
3486 const char *name = rb_id2name(method_id);
3487 static const char prefix[] =
"__builtin_";
3488 const size_t prefix_len =
sizeof(prefix) - 1;
3490 if (receiver == NULL) {
3491 if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) {
3493 return &name[prefix_len];
3496 else if (PM_NODE_TYPE_P(receiver, PM_CALL_NODE)) {
3497 if (PM_NODE_FLAG_P(receiver, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3505 else if (PM_NODE_TYPE_P(receiver, PM_CONSTANT_READ_NODE)) {
3520 if (arguments == NULL) {
3521 COMPILE_ERROR(iseq, node_location->
line,
"attr!: no argument");
3527 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3528 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to attr!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3532 VALUE symbol = pm_static_literal_value(iseq, argument, scope_node);
3533 if (compile_builtin_attr_symbol(iseq, symbol) != COMPILE_OK) {
3534 COMPILE_ERROR(iseq, node_location->
line,
"unknown argument to attr!: %" PRIsVALUE, symbol);
3545 if (arguments == NULL) {
3546 COMPILE_ERROR(iseq, node_location->
line,
"arg!: no argument");
3551 COMPILE_ERROR(iseq, node_location->
line,
"arg!: too many argument");
3556 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3557 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to arg!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3563 int index = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->local_table_size - get_local_var_idx(iseq, name);
3565 debugs(
"id: %s idx: %d\n", rb_id2name(name), index);
3566 PUSH_GETLOCAL(ret, *node_location, index, get_lvar_level(iseq));
3575 const pm_node_t *ast_node = scope_node->ast_node;
3576 if (!PM_NODE_TYPE_P(ast_node, PM_DEF_NODE)) {
3577 rb_bug(
"mandatory_only?: not in method definition");
3583 if (parameters_node == NULL) {
3584 rb_bug(
"mandatory_only?: in method definition with no parameters");
3589 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)) {
3590 rb_bug(
"mandatory_only?: not in method definition with plain statements");
3596 rb_bug(
"mandatory_only?: can't find mandatory node");
3607 .name = def_node->
name,
3609 .parameters = ¶meters,
3619 pm_scope_node_init(&def.base, &next_scope_node, scope_node);
3621 const rb_iseq_t *mandatory_only_iseq = pm_iseq_build(
3623 rb_iseq_base_label(iseq),
3625 rb_iseq_realpath(iseq),
3626 node_location->
line,
3630 ISEQ_COMPILE_DATA(iseq)->option
3632 RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->mandatory_only_iseq, (
VALUE)mandatory_only_iseq);
3634 pm_scope_node_destroy(&next_scope_node);
3643 if (parent_block != NULL) {
3644 COMPILE_ERROR(iseq, node_location->
line,
"should not call builtins here.");
3648#define BUILTIN_INLINE_PREFIX "_bi"
3649 char inline_func[
sizeof(BUILTIN_INLINE_PREFIX) +
DECIMAL_SIZE_OF(
int)];
3650 bool cconst =
false;
3655 if (strcmp(
"cstmt!", builtin_func) == 0 || strcmp(
"cexpr!", builtin_func) == 0) {
3658 else if (strcmp(
"cconst!", builtin_func) == 0) {
3661 else if (strcmp(
"cinit!", builtin_func) == 0) {
3665 else if (strcmp(
"attr!", builtin_func) == 0) {
3666 return pm_compile_builtin_attr(iseq, scope_node, arguments, node_location);
3668 else if (strcmp(
"arg!", builtin_func) == 0) {
3669 return pm_compile_builtin_arg(iseq, ret, scope_node, arguments, node_location, popped);
3671 else if (strcmp(
"mandatory_only?", builtin_func) == 0) {
3673 rb_bug(
"mandatory_only? should be in if condition");
3675 else if (!LIST_INSN_SIZE_ZERO(ret)) {
3676 rb_bug(
"mandatory_only? should be put on top");
3679 PUSH_INSN1(ret, *node_location, putobject,
Qfalse);
3680 return pm_compile_builtin_mandatory_only_method(iseq, scope_node, call_node, node_location);
3682 else if (strcmp(
"local_self!", builtin_func) == 0) {
3685 pm_constant_id_t self_id = pm_parser_constant_find(scope_node->parser, (
const uint8_t *)
"self", 4);
3687 COMPILE_ERROR(iseq, node_location->
line,
"local_self! called but 'self' not found in local table");
3690 pm_local_index_t self_index = pm_lookup_local_index(iseq, scope_node, self_id, 0);
3691 PUSH_GETLOCAL(ret, *node_location, self_index.index, self_index.level);
3695 rb_bug(
"can't find builtin function:%s", builtin_func);
3698 COMPILE_ERROR(iseq, node_location->
line,
"can't find builtin function:%s", builtin_func);
3702 int inline_index = node_location->
line;
3703 snprintf(inline_func,
sizeof(inline_func), BUILTIN_INLINE_PREFIX
"%d", inline_index);
3704 builtin_func = inline_func;
3710 typedef VALUE(*builtin_func0)(
void *,
VALUE);
3711 VALUE const_val = (*(builtin_func0)(uintptr_t)bf->func_ptr)(NULL,
Qnil);
3712 PUSH_INSN1(ret, *node_location, putobject, const_val);
3718 DECL_ANCHOR(args_seq);
3722 int argc = pm_setup_args(arguments, call_node->
block, &flags, &keywords, iseq, args_seq, scope_node, node_location);
3724 if (argc != bf->argc) {
3725 COMPILE_ERROR(iseq, node_location->
line,
"argc is not match for builtin function:%s (expect %d but %d)", builtin_func, bf->argc, argc);
3729 unsigned int start_index;
3730 if (delegate_call_p(iseq, argc, args_seq, &start_index)) {
3731 PUSH_INSN2(ret, *node_location, opt_invokebuiltin_delegate, bf,
INT2FIX(start_index));
3734 PUSH_SEQ(ret, args_seq);
3735 PUSH_INSN1(ret, *node_location, invokebuiltin, bf);
3738 if (popped) PUSH_INSN(ret, *node_location, pop);
3753 LABEL *else_label = NEW_LABEL(location.
line);
3754 LABEL *end_label = NEW_LABEL(location.
line);
3755 LABEL *retry_end_l = NEW_LABEL(location.
line);
3759 int node_id = location.
node_id;
3761 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3762 if (PM_BRANCH_COVERAGE_P(iseq)) {
3763 uint32_t end_cursor = 0;
3764 bool end_found =
false;
3768 end_cursor = cursor;
3774 if (!end_found || cursor > end_cursor) {
3775 end_cursor = cursor;
3782 if (!end_found || cursor > end_cursor) {
3783 end_cursor = cursor;
3792 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(call_node);
3793 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);
3796 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
3797 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
3800 branches = decl_branch_base(iseq, (
int) call_node->
base.
node_id, &code_location,
"&.");
3803 PUSH_INSN(ret, location, dup);
3804 PUSH_INSNL(ret, location, branchnil, else_label);
3806 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0,
"then", branches);
3814 int orig_argc = pm_setup_args(call_node->
arguments, call_node->
block, &flags, &kw_arg, iseq, ret, scope_node, &location);
3815 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
3818 if (call_node->
block != NULL && PM_NODE_TYPE_P(call_node->
block, PM_BLOCK_NODE)) {
3821 pm_scope_node_init(call_node->
block, &next_scope_node, scope_node);
3823 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));
3824 pm_scope_node_destroy(&next_scope_node);
3825 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
3828 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3829 flags |= VM_CALL_VCALL;
3833 flags |= VM_CALL_ARGS_SIMPLE;
3837 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
3838 flags |= VM_CALL_FCALL;
3841 if (!popped && PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE)) {
3842 if (flags & VM_CALL_ARGS_BLOCKARG) {
3843 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
3844 if (flags & VM_CALL_ARGS_SPLAT) {
3845 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3846 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3848 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 3));
3849 PUSH_INSN(ret, location, pop);
3851 else if (flags & VM_CALL_ARGS_SPLAT) {
3852 PUSH_INSN(ret, location, dup);
3853 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3854 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3855 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 2));
3856 PUSH_INSN(ret, location, pop);
3859 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 1));
3863 if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
3864 PUSH_INSN(ret, location, splatkw);
3867 LABEL *not_basic_new = NEW_LABEL(location.
line);
3868 LABEL *not_basic_new_finish = NEW_LABEL(location.
line);
3870 bool inline_new = ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction &&
3871 method_id == rb_intern(
"new") &&
3872 call_node->
block == NULL &&
3873 (flags & VM_CALL_ARGS_BLOCKARG) == 0;
3876 if (LAST_ELEMENT(ret) == opt_new_prelude) {
3877 PUSH_INSN(ret, location, putnil);
3878 PUSH_INSN(ret, location, swap);
3881 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(swap), 0)->link);
3882 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(putnil), 0)->link);
3885 rb_callinfo_kwarg_retain(kw_arg);
3889 if (flags & VM_CALL_FORWARDING) {
3890 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc + 1, flags, kw_arg, 0);
3893 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc, flags, kw_arg, 0);
3896 PUSH_INSN2(ret, location, opt_new, ci, not_basic_new);
3897 LABEL_REF(not_basic_new);
3899 PUSH_SEND_R(ret, location, rb_intern(
"initialize"),
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags | VM_CALL_FCALL), kw_arg);
3900 PUSH_INSNL(ret, location, jump, not_basic_new_finish);
3902 PUSH_LABEL(ret, not_basic_new);
3904 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3905 PUSH_INSN(ret, location, swap);
3907 PUSH_LABEL(ret, not_basic_new_finish);
3908 PUSH_INSN(ret, location, pop);
3910 rb_callinfo_kwarg_release(kw_arg);
3913 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3916 if (block_iseq && ISEQ_BODY(block_iseq)->catch_table) {
3917 pm_compile_retry_end_label(iseq, ret, retry_end_l);
3918 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, start, retry_end_l, block_iseq, retry_end_l);
3921 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3922 PUSH_INSNL(ret, location, jump, end_label);
3923 PUSH_LABEL(ret, else_label);
3924 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 1,
"else", branches);
3925 PUSH_LABEL(ret, end_label);
3928 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
3929 PUSH_INSN(ret, location, pop);
3932 if (popped) PUSH_INSN(ret, location, pop);
3933 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
3943 const char *
type = (
const char *) (pm_parser_start(scope_node->parser) + node->
base.
location.
start + 1);
3963#define PUSH_VAL(type) (in_condition ? Qtrue : rb_iseq_defined_string(type))
3966 enum defined_type dtype = DEFINED_NOT_DEFINED;
3969 switch (PM_NODE_TYPE(node)) {
3974 dtype = DEFINED_NIL;
3977 case PM_INSTANCE_VARIABLE_READ_NODE: {
3981 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3983 PUSH_INSN3(ret, location, definedivar,
ID2SYM(name), get_ivar_ic_value(iseq, name), PUSH_VAL(DEFINED_IVAR));
3988 case PM_LOCAL_VARIABLE_READ_NODE:
3991 case PM_IT_LOCAL_VARIABLE_READ_NODE:
3994 dtype = DEFINED_LVAR;
3997 case PM_GLOBAL_VARIABLE_READ_NODE: {
4001 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4003 PUSH_INSN(ret, location, putnil);
4004 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR),
ID2SYM(name), PUSH_VAL(DEFINED_GVAR));
4009 case PM_CLASS_VARIABLE_READ_NODE: {
4013 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4015 PUSH_INSN(ret, location, putnil);
4016 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR),
ID2SYM(name), PUSH_VAL(DEFINED_CVAR));
4021 case PM_CONSTANT_READ_NODE: {
4025 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4027 PUSH_INSN(ret, location, putnil);
4028 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4036 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
4038 PUSH_INSN(ret, location, putnil);
4039 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
4043 case PM_SUPER_NODE: {
4048 if (cast->
block != NULL && !PM_NODE_TYPE_P(cast->
block, PM_BLOCK_ARGUMENT_NODE)) {
4049 dtype = DEFINED_EXPR;
4053 PUSH_INSN(ret, location, putnil);
4054 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4057 case PM_FORWARDING_SUPER_NODE: {
4062 if (cast->
block != NULL) {
4063 dtype = DEFINED_EXPR;
4067 PUSH_INSN(ret, location, putnil);
4068 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4075 dtype = DEFINED_SELF;
4081 dtype = DEFINED_TRUE;
4087 dtype = DEFINED_FALSE;
4090 case PM_CALL_AND_WRITE_NODE:
4093 case PM_CALL_OPERATOR_WRITE_NODE:
4096 case PM_CALL_OR_WRITE_NODE:
4099 case PM_CLASS_VARIABLE_AND_WRITE_NODE:
4102 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE:
4105 case PM_CLASS_VARIABLE_OR_WRITE_NODE:
4108 case PM_CLASS_VARIABLE_WRITE_NODE:
4111 case PM_CONSTANT_AND_WRITE_NODE:
4114 case PM_CONSTANT_OPERATOR_WRITE_NODE:
4117 case PM_CONSTANT_OR_WRITE_NODE:
4120 case PM_CONSTANT_PATH_AND_WRITE_NODE:
4123 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
4126 case PM_CONSTANT_PATH_OR_WRITE_NODE:
4129 case PM_CONSTANT_PATH_WRITE_NODE:
4132 case PM_CONSTANT_WRITE_NODE:
4135 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE:
4138 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE:
4141 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE:
4144 case PM_GLOBAL_VARIABLE_WRITE_NODE:
4147 case PM_INDEX_AND_WRITE_NODE:
4150 case PM_INDEX_OPERATOR_WRITE_NODE:
4153 case PM_INDEX_OR_WRITE_NODE:
4156 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE:
4159 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE:
4162 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE:
4165 case PM_INSTANCE_VARIABLE_WRITE_NODE:
4168 case PM_LOCAL_VARIABLE_AND_WRITE_NODE:
4171 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE:
4174 case PM_LOCAL_VARIABLE_OR_WRITE_NODE:
4177 case PM_LOCAL_VARIABLE_WRITE_NODE:
4180 case PM_MULTI_WRITE_NODE:
4183 dtype = DEFINED_ASGN;
4186 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
4189 case PM_ALIAS_METHOD_NODE:
4198 case PM_CASE_MATCH_NODE:
4210 case PM_DEFINED_NODE:
4213 case PM_FLIP_FLOP_NODE:
4225 case PM_IMAGINARY_NODE:
4228 case PM_INTEGER_NODE:
4231 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE:
4234 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
4237 case PM_INTERPOLATED_STRING_NODE:
4240 case PM_INTERPOLATED_SYMBOL_NODE:
4243 case PM_INTERPOLATED_X_STRING_NODE:
4246 case PM_LAMBDA_NODE:
4249 case PM_MATCH_LAST_LINE_NODE:
4252 case PM_MATCH_PREDICATE_NODE:
4255 case PM_MATCH_REQUIRED_NODE:
4258 case PM_MATCH_WRITE_NODE:
4261 case PM_MODULE_NODE:
4270 case PM_POST_EXECUTION_NODE:
4276 case PM_RATIONAL_NODE:
4282 case PM_REGULAR_EXPRESSION_NODE:
4285 case PM_RESCUE_MODIFIER_NODE:
4291 case PM_RETURN_NODE:
4294 case PM_SINGLETON_CLASS_NODE:
4297 case PM_SOURCE_ENCODING_NODE:
4300 case PM_SOURCE_FILE_NODE:
4303 case PM_SOURCE_LINE_NODE:
4306 case PM_STRING_NODE:
4309 case PM_SYMBOL_NODE:
4315 case PM_UNLESS_NODE:
4324 case PM_X_STRING_NODE:
4327 dtype = DEFINED_EXPR;
4330 case PM_BACK_REFERENCE_READ_NODE: {
4334 VALUE ref = pm_compile_back_reference_ref(scope_node, cast);
4336 PUSH_INSN(ret, location, putnil);
4337 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4341 case PM_NUMBERED_REFERENCE_READ_NODE: {
4345 VALUE ref = pm_compile_numbered_reference_ref(cast);
4347 PUSH_INSN(ret, location, putnil);
4348 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4353 case PM_CONSTANT_PATH_NODE: {
4357 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4359 if (cast->
parent != NULL) {
4360 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4361 pm_compile_defined_expr0(iseq, cast->
parent, node_location, ret, popped, scope_node,
true, lfinish,
false);
4363 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4364 PM_COMPILE(cast->
parent);
4367 PUSH_INSN1(ret, location, putobject,
rb_cObject);
4370 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4374 case PM_BEGIN_NODE: {
4382 dtype = DEFINED_NIL;
4388 pm_compile_defined_expr0(iseq, cast->
statements->
body.
nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4394 dtype = DEFINED_EXPR;
4399 dtype = DEFINED_EXPR;
4404 case PM_PARENTHESES_NODE: {
4409 if (cast->
body == NULL) {
4411 dtype = DEFINED_NIL;
4413 else if (PM_NODE_TYPE_P(cast->
body, PM_STATEMENTS_NODE) && !PM_NODE_FLAG_P(cast, PM_PARENTHESES_NODE_FLAGS_MULTIPLE_STATEMENTS)) {
4416 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);
4422 dtype = DEFINED_EXPR;
4427 case PM_ARRAY_NODE: {
4433 lfinish[1] = NEW_LABEL(location.
line);
4436 for (
size_t index = 0; index < cast->
elements.
size; index++) {
4437 pm_compile_defined_expr0(iseq, cast->
elements.
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4438 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4441 dtype = DEFINED_EXPR;
4447 case PM_KEYWORD_HASH_NODE: {
4452 if (PM_NODE_TYPE_P(node, PM_HASH_NODE)) {
4459 if (elements->
size > 0 && !lfinish[1]) {
4460 lfinish[1] = NEW_LABEL(location.
line);
4463 for (
size_t index = 0; index < elements->
size; index++) {
4464 pm_compile_defined_expr0(iseq, elements->
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4465 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4468 dtype = DEFINED_EXPR;
4471 case PM_ASSOC_NODE: {
4476 pm_compile_defined_expr0(iseq, cast->
key, node_location, ret, popped, scope_node,
true, lfinish,
false);
4477 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4478 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4482 case PM_ASSOC_SPLAT_NODE: {
4487 if (cast->
value == NULL) {
4488 dtype = DEFINED_EXPR;
4492 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4495 case PM_IMPLICIT_NODE: {
4499 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4502 case PM_CALL_NODE: {
4503#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE))
4509 if (BLOCK_P(cast)) {
4510 dtype = DEFINED_EXPR;
4515 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4516 if (!lfinish[2]) lfinish[2] = NEW_LABEL(location.
line);
4520 pm_compile_defined_expr0(iseq, (
const pm_node_t *) cast->
arguments, node_location, ret, popped, scope_node,
true, lfinish,
false);
4521 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4524 if (cast->
block && PM_NODE_TYPE_P(cast->
block, PM_BLOCK_ARGUMENT_NODE)) {
4525 pm_compile_defined_expr0(iseq, cast->
block, node_location, ret, popped, scope_node,
true, lfinish,
false);
4526 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4533 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
true);
4534 PUSH_INSNL(ret, location, branchunless, lfinish[2]);
4537 ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
4539 pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
4542 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
false);
4543 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4547 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4549 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4550 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_METHOD),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4553 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4555 PUSH_INSN(ret, location, putself);
4556 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4558 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_FUNC),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4565 case PM_ARGUMENTS_NODE: {
4570 for (
size_t index = 0; index < cast->
arguments.
size; index++) {
4571 pm_compile_defined_expr0(iseq, cast->
arguments.
nodes[index], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4572 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4575 dtype = DEFINED_EXPR;
4578 case PM_BLOCK_ARGUMENT_NODE:
4581 dtype = DEFINED_EXPR;
4583 case PM_FORWARDING_ARGUMENTS_NODE:
4586 dtype = DEFINED_EXPR;
4588 case PM_SPLAT_NODE: {
4594 dtype = DEFINED_EXPR;
4598 pm_compile_defined_expr0(iseq, cast->
expression, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4600 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4601 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4603 dtype = DEFINED_EXPR;
4606 case PM_SHAREABLE_CONSTANT_NODE:
4610 pm_compile_defined_expr0(iseq, ((
const pm_shareable_constant_node_t *) node)->write, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4613 case PM_BLOCK_LOCAL_VARIABLE_NODE:
4614 case PM_BLOCK_PARAMETER_NODE:
4615 case PM_BLOCK_PARAMETERS_NODE:
4616 case PM_FORWARDING_PARAMETER_NODE:
4617 case PM_IMPLICIT_REST_NODE:
4618 case PM_IT_PARAMETERS_NODE:
4619 case PM_PARAMETERS_NODE:
4620 case PM_KEYWORD_REST_PARAMETER_NODE:
4621 case PM_NO_KEYWORDS_PARAMETER_NODE:
4622 case PM_NO_BLOCK_PARAMETER_NODE:
4623 case PM_NUMBERED_PARAMETERS_NODE:
4624 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE:
4625 case PM_OPTIONAL_PARAMETER_NODE:
4626 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
4627 case PM_REQUIRED_PARAMETER_NODE:
4628 case PM_REST_PARAMETER_NODE:
4630 case PM_ALTERNATION_PATTERN_NODE:
4631 case PM_ARRAY_PATTERN_NODE:
4632 case PM_CAPTURE_PATTERN_NODE:
4633 case PM_FIND_PATTERN_NODE:
4634 case PM_HASH_PATTERN_NODE:
4635 case PM_PINNED_EXPRESSION_NODE:
4636 case PM_PINNED_VARIABLE_NODE:
4638 case PM_CALL_TARGET_NODE:
4639 case PM_CLASS_VARIABLE_TARGET_NODE:
4640 case PM_CONSTANT_PATH_TARGET_NODE:
4641 case PM_CONSTANT_TARGET_NODE:
4642 case PM_GLOBAL_VARIABLE_TARGET_NODE:
4643 case PM_INDEX_TARGET_NODE:
4644 case PM_INSTANCE_VARIABLE_TARGET_NODE:
4645 case PM_LOCAL_VARIABLE_TARGET_NODE:
4646 case PM_MULTI_TARGET_NODE:
4649 case PM_ENSURE_NODE:
4651 case PM_RESCUE_NODE:
4655 case PM_EMBEDDED_STATEMENTS_NODE:
4656 case PM_EMBEDDED_VARIABLE_NODE:
4657 case PM_ERROR_RECOVERY_NODE:
4658 case PM_PRE_EXECUTION_NODE:
4659 case PM_PROGRAM_NODE:
4661 case PM_STATEMENTS_NODE:
4662 rb_bug(
"Unreachable node in defined?: %s", pm_node_type(PM_NODE_TYPE(node)));
4666 PUSH_INSN1(ret, location, putobject, PUSH_VAL(dtype));
4675 pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4678 LABEL *lstart = NEW_LABEL(node_location->
line);
4679 LABEL *lend = NEW_LABEL(node_location->
line);
4682 rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
4684 const rb_iseq_t *rescue = new_child_iseq_with_callback(
4693 lstart->rescued = LABEL_RESCUE_BEG;
4694 lend->rescued = LABEL_RESCUE_END;
4696 APPEND_LABEL(ret, lcur, lstart);
4697 PUSH_LABEL(ret, lend);
4698 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
4708 lfinish[0] = NEW_LABEL(node_location->
line);
4713 pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish);
4717 ELEM_INSERT_NEXT(last, &new_insn_body(iseq, node_location->
line, node_location->
node_id, BIN(putnil), 0)->link);
4718 PUSH_INSN(ret, *node_location, swap);
4720 if (lfinish[2]) PUSH_LABEL(ret, lfinish[2]);
4721 PUSH_INSN(ret, *node_location, pop);
4722 PUSH_LABEL(ret, lfinish[1]);
4726 PUSH_LABEL(ret, lfinish[0]);
4737 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
4739 DECL_ANCHOR(ensure);
4742 if (enlp->erange != NULL) {
4743 DECL_ANCHOR(ensure_part);
4744 LABEL *lstart = NEW_LABEL(0);
4745 LABEL *lend = NEW_LABEL(0);
4747 add_ensure_range(iseq, enlp->erange, lstart, lend);
4749 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
4750 PUSH_LABEL(ensure_part, lstart);
4752 PM_COMPILE_INTO_ANCHOR(ensure_part, (
const pm_node_t *) enlp->ensure_node);
4753 PUSH_LABEL(ensure_part, lend);
4754 PUSH_SEQ(ensure, ensure_part);
4763 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
4764 PUSH_SEQ(ret, ensure);
4777 RUBY_ASSERT((constant_id & PM_SPECIAL_CONSTANT_FLAG) == 0);
4779 ID local = pm_constant_id_lookup(scope_node, constant_id);
4780 local_table_for_iseq->ids[local_index] = local;
4781 pm_index_lookup_table_insert(index_lookup_table, constant_id, local_index);
4790 local_table_for_iseq->ids[local_index] = local_name;
4791 pm_index_lookup_table_insert(index_lookup_table, special_id, local_index);
4803 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4806 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4807 if (!PM_NODE_FLAG_P(left, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4808 pm_insert_local_index(((
const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4813 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4814 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);
4818 if (node->
rest != NULL && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE)) {
4821 if (rest->expression != NULL) {
4822 RUBY_ASSERT(PM_NODE_TYPE_P(rest->expression, PM_REQUIRED_PARAMETER_NODE));
4824 if (!PM_NODE_FLAG_P(rest->expression, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4825 pm_insert_local_index(((
const pm_required_parameter_node_t *) rest->expression)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4831 for (
size_t index = 0; index < node->
rights.
size; index++) {
4834 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4835 if (!PM_NODE_FLAG_P(right, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4836 pm_insert_local_index(((
const pm_required_parameter_node_t *) right)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4841 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4842 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);
4858 PUSH_SETLOCAL(ret, location, index.index, index.level);
4873 bool has_rest = (node->
rest && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE) && (((
const pm_splat_node_t *) node->
rest)->expression) != NULL);
4876 int flag = (has_rest || has_rights) ? 1 : 0;
4879 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4882 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4886 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4897 RUBY_ASSERT(PM_NODE_TYPE_P(rest, PM_REQUIRED_PARAMETER_NODE));
4907 for (
size_t index = 0; index < node->
rights.
size; index++) {
4910 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4914 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4974 node->stack_index = state->stack_size + 1;
4975 node->stack_size = stack_size;
4976 node->position = state->position;
4979 if (state->head == NULL) {
4984 state->tail->next = node;
4988 state->stack_size += stack_size;
5001 if (state->stack_size == 0)
return;
5006 while (current != NULL) {
5007 VALUE offset =
INT2FIX(state->stack_size - current->stack_index + current->position);
5008 current->topn->operands[0] = offset;
5014 if (current->stack_size > 1) {
5015 INSN *insn = current->topn;
5017 for (
size_t index = 1; index < current->stack_size; index += 1) {
5021 insn = (
INSN *) element;
5024 insn->operands[0] = offset;
5029 current = current->next;
5031 SIZED_FREE(previous);
5071 switch (PM_NODE_TYPE(node)) {
5072 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5081 PUSH_SETLOCAL(writes, location, index.index, index.level);
5084 case PM_CLASS_VARIABLE_TARGET_NODE: {
5091 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5094 PUSH_INSN2(writes, location, setclassvariable, operand, get_cvar_ic_value(iseq, name));
5097 case PM_CONSTANT_TARGET_NODE: {
5104 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5107 PUSH_INSN1(writes, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5108 PUSH_INSN1(writes, location, setconstant, operand);
5111 case PM_GLOBAL_VARIABLE_TARGET_NODE: {
5118 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5121 PUSH_INSN1(writes, location, setglobal, operand);
5124 case PM_INSTANCE_VARIABLE_TARGET_NODE: {
5131 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5134 PUSH_INSN2(writes, location, setinstancevariable, operand, get_ivar_ic_value(iseq, name));
5137 case PM_CONSTANT_PATH_TARGET_NODE: {
5147 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5149 if (cast->
parent != NULL) {
5150 pm_compile_node(iseq, cast->
parent, parents,
false, scope_node);
5153 PUSH_INSN1(parents, location, putobject,
rb_cObject);
5156 if (state == NULL) {
5157 PUSH_INSN(writes, location, swap);
5160 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5161 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5165 PUSH_INSN1(writes, location, setconstant, operand);
5167 if (state != NULL) {
5168 PUSH_INSN(cleanup, location, pop);
5173 case PM_CALL_TARGET_NODE: {
5183 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
5185 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5187 LABEL *safe_label = NULL;
5188 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
5189 safe_label = NEW_LABEL(location.
line);
5190 PUSH_INSN(parents, location, dup);
5191 PUSH_INSNL(parents, location, branchnil, safe_label);
5194 if (state != NULL) {
5195 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5196 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5197 PUSH_INSN(writes, location, swap);
5200 int flags = VM_CALL_ARGS_SIMPLE;
5201 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) flags |= VM_CALL_FCALL;
5203 PUSH_SEND_WITH_FLAG(writes, location, method_id,
INT2FIX(1),
INT2FIX(flags));
5204 if (safe_label != NULL && state == NULL) PUSH_LABEL(writes, safe_label);
5205 PUSH_INSN(writes, location, pop);
5206 if (safe_label != NULL && state != NULL) PUSH_LABEL(writes, safe_label);
5208 if (state != NULL) {
5209 PUSH_INSN(cleanup, location, pop);
5214 case PM_INDEX_TARGET_NODE: {
5226 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5230 int argc = pm_setup_args(cast->
arguments, (
const pm_node_t *) cast->
block, &flags, &kwargs, iseq, parents, scope_node, &location);
5232 if (state != NULL) {
5233 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5234 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), argc + 1);
5237 PUSH_INSN(writes, location, swap);
5240 for (
int index = 0; index < argc; index++) {
5241 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5243 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5251 int ci_argc = argc + 1;
5252 if (flags & VM_CALL_ARGS_SPLAT) {
5254 PUSH_INSN1(writes, location, newarray,
INT2FIX(1));
5255 PUSH_INSN(writes, location, concatarray);
5258 PUSH_SEND_R(writes, location, idASET,
INT2NUM(ci_argc), NULL,
INT2FIX(flags), kwargs);
5259 PUSH_INSN(writes, location, pop);
5261 if (state != NULL) {
5263 PUSH_INSN(writes, location, pop);
5266 for (
int index = 0; index < argc + 1; index++) {
5267 PUSH_INSN(cleanup, location, pop);
5273 case PM_MULTI_TARGET_NODE: {
5280 size_t before_position;
5281 if (state != NULL) {
5282 before_position = state->position;
5286 pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, scope_node, state);
5287 if (state != NULL) state->position = before_position;
5291 case PM_SPLAT_NODE: {
5300 pm_compile_target_node(iseq, cast->
expression, parents, writes, cleanup, scope_node, state);
5306 rb_bug(
"Unexpected node type: %s", pm_node_type(PM_NODE_TYPE(node)));
5324 switch (PM_NODE_TYPE(node)) {
5325 case PM_MULTI_TARGET_NODE: {
5327 lefts = &cast->
lefts;
5332 case PM_MULTI_WRITE_NODE: {
5334 lefts = &cast->
lefts;
5340 rb_bug(
"Unsupported node %s", pm_node_type(PM_NODE_TYPE(node)));
5344 bool has_rest = (rest != NULL) && PM_NODE_TYPE_P(rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) rest)->expression != NULL;
5345 bool has_posts = rights->
size > 0;
5350 PUSH_INSN2(writes, location, expandarray,
INT2FIX(lefts->
size),
INT2FIX((has_rest || has_posts) ? 1 : 0));
5356 if (state == NULL) state = &target_state;
5358 size_t base_position = state->position;
5359 size_t splat_position = (has_rest || has_posts) ? 1 : 0;
5362 for (
size_t index = 0; index < lefts->
size; index++) {
5364 state->position = lefts->
size - index + splat_position + base_position;
5365 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5371 state->position = 1 + rights->
size + base_position;
5377 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5382 if (!has_rest && rest != NULL) {
5386 for (
size_t index = 0; index < rights->
size; index++) {
5388 state->position = rights->
size - index + base_position;
5389 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5404 switch (PM_NODE_TYPE(node)) {
5405 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5408 PUSH_GETLOCAL(ret, location, 1, 0);
5409 pm_compile_target_node(iseq, node, ret, ret, ret, scope_node, NULL);
5412 case PM_CLASS_VARIABLE_TARGET_NODE:
5413 case PM_CONSTANT_TARGET_NODE:
5414 case PM_GLOBAL_VARIABLE_TARGET_NODE:
5415 case PM_INSTANCE_VARIABLE_TARGET_NODE:
5416 case PM_CONSTANT_PATH_TARGET_NODE:
5417 case PM_CALL_TARGET_NODE:
5418 case PM_INDEX_TARGET_NODE: {
5422 DECL_ANCHOR(writes);
5423 DECL_ANCHOR(cleanup);
5427 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
5429 PUSH_GETLOCAL(ret, location, 1, 0);
5432 PUSH_SEQ(ret, writes);
5433 PUSH_SEQ(ret, cleanup);
5435 pm_multi_target_state_update(&state);
5439 case PM_MULTI_TARGET_NODE: {
5440 DECL_ANCHOR(writes);
5441 DECL_ANCHOR(cleanup);
5443 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, NULL);
5445 LABEL *not_single = NEW_LABEL(location.
line);
5446 LABEL *not_ary = NEW_LABEL(location.
line);
5454 PUSH_GETLOCAL(ret, location, 1, 0);
5455 PUSH_INSN(ret, location, dup);
5456 PUSH_CALL(ret, location, idLength,
INT2FIX(0));
5457 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
5458 PUSH_CALL(ret, location, idEq,
INT2FIX(1));
5459 PUSH_INSNL(ret, location, branchunless, not_single);
5460 PUSH_INSN(ret, location, dup);
5461 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
5462 PUSH_CALL(ret, location, idAREF,
INT2FIX(1));
5463 PUSH_INSN1(ret, location, putobject,
rb_cArray);
5464 PUSH_INSN(ret, location, swap);
5465 PUSH_CALL(ret, location, rb_intern(
"try_convert"),
INT2FIX(1));
5466 PUSH_INSN(ret, location, dup);
5467 PUSH_INSNL(ret, location, branchunless, not_ary);
5468 PUSH_INSN(ret, location, swap);
5470 PUSH_LABEL(ret, not_ary);
5471 PUSH_INSN(ret, location, pop);
5473 PUSH_LABEL(ret, not_single);
5475 if (PM_NODE_TYPE_P(node, PM_SPLAT_NODE)) {
5480 PUSH_SEQ(ret, writes);
5481 PUSH_SEQ(ret, cleanup);
5485 rb_bug(
"Unexpected node type for index in for node: %s", pm_node_type(PM_NODE_TYPE(node)));
5493 LABEL *lstart = NEW_LABEL(node_location->
line);
5494 LABEL *lend = NEW_LABEL(node_location->
line);
5495 LABEL *lcont = NEW_LABEL(node_location->
line);
5500 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
5507 pm_scope_node_destroy(&rescue_scope_node);
5509 lstart->rescued = LABEL_RESCUE_BEG;
5510 lend->rescued = LABEL_RESCUE_END;
5511 PUSH_LABEL(ret, lstart);
5513 bool prev_in_rescue = ISEQ_COMPILE_DATA(iseq)->in_rescue;
5514 ISEQ_COMPILE_DATA(iseq)->in_rescue =
true;
5521 PUSH_INSN(ret, location, putnil);
5524 ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;
5525 PUSH_LABEL(ret, lend);
5528 if (!popped) PUSH_INSN(ret, *node_location, pop);
5532 PUSH_INSN(ret, *node_location, nop);
5533 PUSH_LABEL(ret, lcont);
5535 if (popped) PUSH_INSN(ret, *node_location, pop);
5536 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
5537 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
5546 if (statements != NULL) {
5547 location = PM_NODE_START_LOCATION(statements);
5550 location = *node_location;
5553 LABEL *lstart = NEW_LABEL(location.
line);
5555 LABEL *lcont = NEW_LABEL(location.
line);
5562 if (statements != NULL) {
5563 pm_compile_node(iseq, (
const pm_node_t *) statements, ensr,
true, scope_node);
5567 bool last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
5572 push_ensure_entry(iseq, &enl, &er, (
void *) cast->
ensure_clause);
5574 PUSH_LABEL(ret, lstart);
5576 pm_compile_rescue(iseq, cast, node_location, ret, popped | last_leave, scope_node);
5579 pm_compile_node(iseq, (
const pm_node_t *) cast->
statements, ret, popped | last_leave, scope_node);
5581 else if (!(popped | last_leave)) {
5582 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
5585 PUSH_LABEL(ret, lend);
5586 PUSH_SEQ(ret, ensr);
5587 if (!popped && last_leave) PUSH_INSN(ret, *node_location, putnil);
5588 PUSH_LABEL(ret, lcont);
5589 if (last_leave) PUSH_INSN(ret, *node_location, pop);
5601 pm_scope_node_destroy(&next_scope_node);
5603 erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
5604 if (lstart->link.next != &lend->link) {
5606 PUSH_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, child_iseq, lcont);
5607 erange = erange->next;
5610 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
5621 !PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION) &&
5623 PM_NODE_TYPE_P(node->
receiver, PM_STRING_NODE) &&
5625 node->
block == NULL &&
5626 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5639 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
5640 ISEQ_BODY(iseq)->ic_size++;
5641 VALUE segments = rb_ary_new_from_args(1, name);
5643 PUSH_INSN1(ret, location, opt_getconstant_path, segments);
5646 PUSH_INSN(ret, location, putnil);
5647 PUSH_INSN1(ret, location, putobject,
Qtrue);
5648 PUSH_INSN1(ret, location, getconstant, name);
5662 switch (PM_NODE_TYPE(node)) {
5663 case PM_CONSTANT_READ_NODE: {
5667 rb_ary_unshift(parts, name);
5670 case PM_CONSTANT_PATH_NODE: {
5674 rb_ary_unshift(parts, name);
5675 if (cast->
parent == NULL) {
5676 rb_ary_unshift(parts,
ID2SYM(idNULL));
5699 switch (PM_NODE_TYPE(node)) {
5700 case PM_CONSTANT_READ_NODE: {
5704 PUSH_INSN1(body, location, putobject,
Qtrue);
5705 PUSH_INSN1(body, location, getconstant, name);
5708 case PM_CONSTANT_PATH_NODE: {
5712 if (cast->
parent == NULL) {
5713 PUSH_INSN(body, location, pop);
5714 PUSH_INSN1(body, location, putobject,
rb_cObject);
5715 PUSH_INSN1(body, location, putobject,
Qtrue);
5716 PUSH_INSN1(body, location, getconstant, name);
5719 pm_compile_constant_path(iseq, cast->
parent, prefix, body,
false, scope_node);
5720 PUSH_INSN1(body, location, putobject,
Qfalse);
5721 PUSH_INSN1(body, location, getconstant, name);
5726 PM_COMPILE_INTO_ANCHOR(prefix, node);
5737 switch (PM_NODE_TYPE(node)) {
5741 case PM_SYMBOL_NODE:
5742 case PM_REGULAR_EXPRESSION_NODE:
5743 case PM_SOURCE_LINE_NODE:
5744 case PM_INTEGER_NODE:
5746 case PM_RATIONAL_NODE:
5747 case PM_IMAGINARY_NODE:
5748 case PM_SOURCE_ENCODING_NODE:
5749 return pm_static_literal_value(iseq, node, scope_node);
5750 case PM_STRING_NODE:
5751 return parse_static_literal_string(iseq, scope_node, node, &((
const pm_string_node_t *) node)->unescaped);
5752 case PM_ARRAY_NODE: {
5756 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5757 VALUE element = pm_compile_shareable_constant_literal(iseq, cast->
elements.
nodes[index], scope_node);
5765 case PM_HASH_NODE: {
5769 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5771 if (!PM_NODE_TYPE_P(element, PM_ASSOC_NODE))
return Qundef;
5775 VALUE key = pm_compile_shareable_constant_literal(iseq, assoc->
key, scope_node);
5778 VALUE value = pm_compile_shareable_constant_literal(iseq, assoc->
value, scope_node);
5781 rb_hash_aset(result, key, value);
5798 VALUE literal = pm_compile_shareable_constant_literal(iseq, node, scope_node);
5801 PUSH_INSN1(ret, location, putobject, literal);
5806 switch (PM_NODE_TYPE(node)) {
5807 case PM_ARRAY_NODE: {
5811 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5814 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5815 pm_compile_shareable_constant_value(iseq, cast->
elements.
nodes[index], shareability, path, ret, scope_node,
false);
5821 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5822 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5827 case PM_HASH_NODE: {
5831 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5834 pm_compile_hash_elements(iseq, (
const pm_node_t *) cast, &cast->elements, shareability, path,
false, ret, scope_node);
5837 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5838 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5844 DECL_ANCHOR(value_seq);
5846 pm_compile_node(iseq, node, value_seq,
false, scope_node);
5847 if (PM_NODE_TYPE_P(node, PM_INTERPOLATED_STRING_NODE)) {
5848 PUSH_SEND_WITH_FLAG(value_seq, location, idUMinus,
INT2FIX(0),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5851 if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_LITERAL) {
5852 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5853 PUSH_SEQ(ret, value_seq);
5857 PUSH_INSN1(ret, location, putobject, path);
5858 PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"ensure_shareable"),
INT2FIX(2),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5860 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) {
5861 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5862 PUSH_SEQ(ret, value_seq);
5863 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable_copy"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5865 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_EVERYTHING) {
5866 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5867 PUSH_SEQ(ret, value_seq);
5868 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5884 ID name_id = pm_constant_id_lookup(scope_node, node->
name);
5886 if (shareability != 0) {
5887 pm_compile_shareable_constant_value(iseq, node->
value, shareability, rb_id2str(name_id), ret, scope_node,
true);
5890 PM_COMPILE_NOT_POPPED(node->
value);
5893 if (!popped) PUSH_INSN(ret, location, dup);
5894 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5897 PUSH_INSN1(ret, location, setconstant, operand);
5910 LABEL *end_label = NEW_LABEL(location.
line);
5912 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5913 if (!popped) PUSH_INSN(ret, location, dup);
5915 PUSH_INSNL(ret, location, branchunless, end_label);
5916 if (!popped) PUSH_INSN(ret, location, pop);
5918 if (shareability != 0) {
5919 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5922 PM_COMPILE_NOT_POPPED(node->
value);
5925 if (!popped) PUSH_INSN(ret, location, dup);
5926 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5927 PUSH_INSN1(ret, location, setconstant, name);
5928 PUSH_LABEL(ret, end_label);
5941 LABEL *set_label = NEW_LABEL(location.
line);
5942 LABEL *end_label = NEW_LABEL(location.
line);
5944 PUSH_INSN(ret, location, putnil);
5945 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name,
Qtrue);
5946 PUSH_INSNL(ret, location, branchunless, set_label);
5948 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5949 if (!popped) PUSH_INSN(ret, location, dup);
5951 PUSH_INSNL(ret, location, branchif, end_label);
5952 if (!popped) PUSH_INSN(ret, location, pop);
5953 PUSH_LABEL(ret, set_label);
5955 if (shareability != 0) {
5956 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5959 PM_COMPILE_NOT_POPPED(node->
value);
5962 if (!popped) PUSH_INSN(ret, location, dup);
5963 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5964 PUSH_INSN1(ret, location, setconstant, name);
5965 PUSH_LABEL(ret, end_label);
5980 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5982 if (shareability != 0) {
5983 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5986 PM_COMPILE_NOT_POPPED(node->
value);
5989 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5990 if (!popped) PUSH_INSN(ret, location, dup);
5992 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5993 PUSH_INSN1(ret, location, setconstant, name);
6004 rb_ary_push(parts, rb_id2str(pm_constant_id_lookup(scope_node, node->
name)));
6007 while (current != NULL && PM_NODE_TYPE_P(current, PM_CONSTANT_PATH_NODE)) {
6009 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, cast->
name)));
6013 if (current == NULL) {
6014 rb_ary_unshift(parts, rb_id2str(idNULL));
6016 else if (PM_NODE_TYPE_P(current, PM_CONSTANT_READ_NODE)) {
6017 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, ((
const pm_constant_read_node_t *) current)->name)));
6041 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6044 if (shareability != 0) {
6045 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6048 PM_COMPILE_NOT_POPPED(node->
value);
6052 PUSH_INSN(ret, location, swap);
6053 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6056 PUSH_INSN(ret, location, swap);
6057 PUSH_INSN1(ret, location, setconstant, name);
6074 PM_COMPILE_NOT_POPPED(target->
parent);
6077 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6080 PUSH_INSN(ret, location, dup);
6081 PUSH_INSN1(ret, location, putobject,
Qtrue);
6082 PUSH_INSN1(ret, location, getconstant, name);
6084 if (!popped) PUSH_INSN(ret, location, dup);
6085 PUSH_INSNL(ret, location, branchunless, lfin);
6087 if (!popped) PUSH_INSN(ret, location, pop);
6089 if (shareability != 0) {
6090 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6093 PM_COMPILE_NOT_POPPED(node->
value);
6097 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6100 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6101 PUSH_INSN(ret, location, swap);
6104 PUSH_INSN1(ret, location, setconstant, name);
6105 PUSH_LABEL(ret, lfin);
6107 if (!popped) PUSH_INSN(ret, location, swap);
6108 PUSH_INSN(ret, location, pop);
6122 LABEL *lassign = NEW_LABEL(location.
line);
6126 PM_COMPILE_NOT_POPPED(target->
parent);
6129 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6132 PUSH_INSN(ret, location, dup);
6133 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name,
Qtrue);
6134 PUSH_INSNL(ret, location, branchunless, lassign);
6136 PUSH_INSN(ret, location, dup);
6137 PUSH_INSN1(ret, location, putobject,
Qtrue);
6138 PUSH_INSN1(ret, location, getconstant, name);
6140 if (!popped) PUSH_INSN(ret, location, dup);
6141 PUSH_INSNL(ret, location, branchif, lfin);
6143 if (!popped) PUSH_INSN(ret, location, pop);
6144 PUSH_LABEL(ret, lassign);
6146 if (shareability != 0) {
6147 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6150 PM_COMPILE_NOT_POPPED(node->
value);
6154 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6157 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6158 PUSH_INSN(ret, location, swap);
6161 PUSH_INSN1(ret, location, setconstant, name);
6162 PUSH_LABEL(ret, lfin);
6164 if (!popped) PUSH_INSN(ret, location, swap);
6165 PUSH_INSN(ret, location, pop);
6182 PM_COMPILE_NOT_POPPED(target->
parent);
6185 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6188 PUSH_INSN(ret, location, dup);
6189 PUSH_INSN1(ret, location, putobject,
Qtrue);
6190 PUSH_INSN1(ret, location, getconstant, name);
6192 if (shareability != 0) {
6193 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6196 PM_COMPILE_NOT_POPPED(node->
value);
6199 PUSH_CALL(ret, location, method_id,
INT2FIX(1));
6200 PUSH_INSN(ret, location, swap);
6203 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6204 PUSH_INSN(ret, location, swap);
6207 PUSH_INSN1(ret, location, setconstant, name);
6216#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))
6235 bool trailing_comma =
false;
6237 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
6241 if (scope_node->parameters != NULL) {
6242 switch (PM_NODE_TYPE(scope_node->parameters)) {
6243 case PM_BLOCK_PARAMETERS_NODE: {
6245 parameters_node = cast->parameters;
6246 block_locals = &cast->locals;
6248 if (parameters_node) {
6249 if (parameters_node->
rest && PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE)) {
6250 trailing_comma =
true;
6255 case PM_PARAMETERS_NODE: {
6259 case PM_NUMBERED_PARAMETERS_NODE: {
6261 body->param.lead_num = maximum;
6262 body->param.flags.ambiguous_param0 = maximum == 1;
6265 case PM_IT_PARAMETERS_NODE:
6266 body->param.lead_num = 1;
6267 body->param.flags.ambiguous_param0 =
true;
6270 rb_bug(
"Unexpected node type for parameters: %s", pm_node_type(PM_NODE_TYPE(scope_node->parameters)));
6274 struct rb_iseq_param_keyword *keyword = NULL;
6276 if (parameters_node) {
6277 optionals_list = ¶meters_node->
optionals;
6278 requireds_list = ¶meters_node->
requireds;
6279 keywords_list = ¶meters_node->
keywords;
6280 posts_list = ¶meters_node->
posts;
6282 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))) {
6283 body->param.opt_num = 0;
6286 body->param.lead_num = 0;
6287 body->param.opt_num = 0;
6293 size_t locals_size = locals->
size;
6299 int table_size = (int) locals_size;
6303 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) table_size++;
6305 if (keywords_list && keywords_list->
size) {
6309 if (requireds_list) {
6310 for (
size_t i = 0; i < requireds_list->
size; i++) {
6315 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6318 else if (PM_NODE_TYPE_P(required, PM_REQUIRED_PARAMETER_NODE)) {
6319 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6328 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6336 if (optionals_list && optionals_list->
size) {
6337 for (
size_t i = 0; i < optionals_list->
size; i++) {
6339 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6349 if (parameters_node) {
6350 if (parameters_node->
rest) {
6351 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6365 if (PM_NODE_TYPE_P(parameters_node->
keyword_rest, PM_FORWARDING_PARAMETER_NODE)) {
6367 if (requireds_list->
size == 0 && optionals_list->
size == 0 && keywords_list->
size == 0) {
6368 ISEQ_BODY(iseq)->param.flags.use_block = TRUE;
6369 ISEQ_BODY(iseq)->param.flags.forwardable = TRUE;
6380 if (!kw_rest->name || PM_NODE_FLAG_P(kw_rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6388 for (
size_t i = 0; i < posts_list->
size; i++) {
6393 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE) || PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6399 if (keywords_list && keywords_list->
size) {
6400 for (
size_t i = 0; i < keywords_list->
size; i++) {
6402 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6408 if (parameters_node && parameters_node->
block && PM_NODE_TYPE_P(parameters_node->
block, PM_BLOCK_PARAMETER_NODE)) {
6411 if (PM_NODE_FLAG_P(block_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER) || !block_node->name) {
6419 local_table_for_iseq->size = table_size;
6423 pm_index_lookup_table_init(&index_lookup_table, (
int) pm_parser_constants_size(scope_node->parser), iseq);
6443 int local_index = 0;
6450 if (requireds_list && requireds_list->
size) {
6451 for (
size_t i = 0; i < requireds_list->
size; i++, local_index++) {
6459 switch (PM_NODE_TYPE(required)) {
6460 case PM_MULTI_TARGET_NODE: {
6463 local = rb_make_temporary_id(local_index);
6464 local_table_for_iseq->ids[local_index] = local;
6467 case PM_REQUIRED_PARAMETER_NODE: {
6472 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6473 ID local = pm_constant_id_lookup(scope_node, param->
name);
6474 local_table_for_iseq->ids[local_index] = local;
6477 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6483 rb_bug(
"Unsupported node in requireds in parameters %s", pm_node_type(PM_NODE_TYPE(required)));
6487 body->param.lead_num = (int) requireds_list->
size;
6488 body->param.flags.has_lead =
true;
6491 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6492 local_table_for_iseq->ids[local_index++] = idItImplicit;
6497 if (optionals_list && optionals_list->
size) {
6498 body->param.opt_num = (int) optionals_list->
size;
6499 body->param.flags.has_opt =
true;
6501 for (
size_t i = 0; i < optionals_list->
size; i++, local_index++) {
6505 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6506 ID local = pm_constant_id_lookup(scope_node, name);
6507 local_table_for_iseq->ids[local_index] = local;
6510 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6517 if (parameters_node && parameters_node->
rest) {
6518 body->param.rest_start = local_index;
6522 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6523 body->param.flags.has_rest =
true;
6531 if (PM_NODE_FLAG_P(parameters_node->
rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6532 ID local = pm_constant_id_lookup(scope_node, name);
6533 local_table_for_iseq->ids[local_index] = local;
6536 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6542 body->param.flags.anon_rest =
true;
6543 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index, &index_lookup_table, local_table_for_iseq);
6552 if (posts_list && posts_list->
size) {
6553 body->param.post_num = (int) posts_list->
size;
6554 body->param.post_start = local_index;
6555 body->param.flags.has_post =
true;
6557 for (
size_t i = 0; i < posts_list->
size; i++, local_index++) {
6565 switch (PM_NODE_TYPE(post_node)) {
6566 case PM_MULTI_TARGET_NODE: {
6569 local = rb_make_temporary_id(local_index);
6570 local_table_for_iseq->ids[local_index] = local;
6573 case PM_REQUIRED_PARAMETER_NODE: {
6578 if (PM_NODE_FLAG_P(param, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6579 ID local = pm_constant_id_lookup(scope_node, param->
name);
6580 local_table_for_iseq->ids[local_index] = local;
6583 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6588 rb_bug(
"Unsupported node in posts in parameters %s", pm_node_type(PM_NODE_TYPE(post_node)));
6596 if (keywords_list && keywords_list->
size) {
6597 if (keywords_list->
size > VM_CALL_KW_LEN_MAX) {
6598 COMPILE_ERROR(iseq, node_location->
line,
"too many keyword parameters (%d, maximum is %d)",
6599 (
int) keywords_list->
size, (
int) VM_CALL_KW_LEN_MAX);
6602 keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6603 keyword->num = (int) keywords_list->
size;
6608 for (
size_t i = 0; i < keywords_list->
size; i++) {
6614 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_REQUIRED_KEYWORD_PARAMETER_NODE)) {
6616 keyword->required_num++;
6617 ID local = pm_constant_id_lookup(scope_node, name);
6619 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6620 local_table_for_iseq->ids[local_index] = local;
6623 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6629 for (
size_t i = 0; i < keywords_list->
size; i++) {
6635 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_OPTIONAL_KEYWORD_PARAMETER_NODE)) {
6641 if (PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) {
6642 rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node));
6648 ID local = pm_constant_id_lookup(scope_node, name);
6649 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6650 local_table_for_iseq->ids[local_index] = local;
6653 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6663 for (
int i = 0; i <
RARRAY_LEN(default_values); i++) {
6665 if (dv == complex_mark) dv =
Qundef;
6669 keyword->default_values = dvs;
6673 keyword->bits_start = local_index;
6674 ID local = rb_make_temporary_id(local_index);
6675 local_table_for_iseq->ids[local_index] = local;
6678 body->param.keyword = keyword;
6679 body->param.flags.has_kw =
true;
6682 if (body->type == ISEQ_TYPE_BLOCK && local_index == 1 && requireds_list && requireds_list->
size == 1 && !trailing_comma) {
6683 body->param.flags.ambiguous_param0 =
true;
6686 if (parameters_node) {
6691 case PM_NO_KEYWORDS_PARAMETER_NODE: {
6694 body->param.flags.accepts_no_kwarg =
true;
6697 case PM_KEYWORD_REST_PARAMETER_NODE: {
6701 if (!body->param.flags.has_kw) {
6702 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6705 keyword->rest_start = local_index;
6706 body->param.flags.has_kwrest =
true;
6710 if (PM_NODE_FLAG_P(kw_rest_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6711 ID local = pm_constant_id_lookup(scope_node, constant_id);
6712 local_table_for_iseq->ids[local_index] = local;
6715 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6719 body->param.flags.anon_kwrest =
true;
6720 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index, &index_lookup_table, local_table_for_iseq);
6726 case PM_FORWARDING_PARAMETER_NODE: {
6729 if (!ISEQ_BODY(iseq)->param.
flags.forwardable) {
6731 body->param.rest_start = local_index;
6732 body->param.flags.has_rest =
true;
6733 body->param.flags.anon_rest =
true;
6734 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index++, &index_lookup_table, local_table_for_iseq);
6738 body->param.flags.has_kw =
false;
6739 body->param.flags.has_kwrest =
true;
6740 body->param.flags.anon_kwrest =
true;
6741 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6742 keyword->rest_start = local_index;
6743 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index++, &index_lookup_table, local_table_for_iseq);
6746 body->param.block_start = local_index;
6747 body->param.flags.has_block =
true;
6748 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index++, &index_lookup_table, local_table_for_iseq);
6752 pm_insert_local_special(PM_CONSTANT_DOT3, idDot3, local_index++, &index_lookup_table, local_table_for_iseq);
6756 rb_bug(
"node type %s not expected as keyword_rest", pm_node_type(PM_NODE_TYPE(parameters_node->
keyword_rest)));
6762 if (parameters_node->
block) {
6763 switch (PM_NODE_TYPE(parameters_node->
block)) {
6764 case PM_BLOCK_PARAMETER_NODE: {
6765 body->param.block_start = local_index;
6766 body->param.flags.has_block =
true;
6768 iseq_set_use_block(iseq);
6773 if (PM_NODE_FLAG_P(parameters_node->
block, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6774 ID local = pm_constant_id_lookup(scope_node, name);
6775 local_table_for_iseq->ids[local_index] = local;
6778 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6782 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index, &index_lookup_table, local_table_for_iseq);
6788 case PM_NO_BLOCK_PARAMETER_NODE: {
6789 body->param.flags.accepts_no_block =
true;
6793 rb_bug(
"node type %s not expected as block parameter", pm_node_type(PM_NODE_TYPE(parameters_node->
block)));
6810 if (requireds_list && requireds_list->
size) {
6811 for (
size_t i = 0; i < requireds_list->
size; i++) {
6817 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6818 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);
6824 if (posts_list && posts_list->
size) {
6825 for (
size_t i = 0; i < posts_list->
size; i++) {
6831 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
6832 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);
6838 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
6839 if (PM_NODE_TYPE_P(((
const pm_for_node_t *) scope_node->ast_node)->index, PM_LOCAL_VARIABLE_TARGET_NODE)) {
6840 body->param.lead_num++;
6843 body->param.rest_start = local_index;
6844 body->param.flags.has_rest =
true;
6847 ID local = rb_make_temporary_id(local_index);
6848 local_table_for_iseq->ids[local_index] = local;
6853 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_NUMBERED_PARAMETERS_NODE)) {
6856 for (
int i = 0; i < maximum; i++, local_index++) {
6857 const uint8_t param_name[] = {
'_',
'1' + i };
6858 pm_constant_id_t constant_id = pm_parser_constant_find(scope_node->parser, param_name, 2);
6859 RUBY_ASSERT(constant_id &&
"parser should fill in any gaps in numbered parameters");
6860 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6862 body->param.lead_num = maximum;
6863 body->param.flags.has_lead =
true;
6867 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6868 body->param.lead_num = 1;
6869 body->param.flags.has_lead =
true;
6880 if (block_locals && block_locals->
size) {
6881 for (
size_t i = 0; i < block_locals->
size; i++, local_index++) {
6883 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6888 if (scope_node->locals.
size) {
6889 for (
size_t i = 0; i < scope_node->locals.
size; i++) {
6893 if (!pm_index_lookup_table_lookup(&index_lookup_table, constant_id, &existing)) {
6894 ID local = pm_constant_id_lookup(scope_node, constant_id);
6895 local_table_for_iseq->ids[local_index] = local;
6896 pm_index_lookup_table_insert(&index_lookup_table, constant_id, local_index);
6908 iseq_calc_param_size(iseq);
6910 if (ISEQ_BODY(iseq)->param.
flags.forwardable) {
6913 ISEQ_BODY(iseq)->param.size += 1;
6917 iseq_set_local_table(iseq, local_table_for_iseq, 0);
6918 iseq_set_parameters_lvar_state(iseq);
6920 scope_node->local_table_for_iseq_size = local_table_for_iseq->size;
6922 if (keyword != NULL) {
6923 size_t keyword_start_index = keyword->bits_start - keyword->num;
6924 keyword->table = (
ID *)&ISEQ_BODY(iseq)->local_table[keyword_start_index];
6927 local_table_for_iseq = NULL;
6932 if (optionals_list && optionals_list->
size) {
6940 for (
size_t i = 0; i < optionals_list->
size; i++) {
6941 label = NEW_LABEL(location.
line);
6942 opt_table[i] = label;
6943 PUSH_LABEL(ret, label);
6945 PM_COMPILE_NOT_POPPED(optional_node);
6949 label = NEW_LABEL(location.
line);
6950 opt_table[optionals_list->
size] = label;
6951 PUSH_LABEL(ret, label);
6953 body->param.opt_table = (
const VALUE *) opt_table;
6956 if (keywords_list && keywords_list->
size) {
6957 size_t optional_index = 0;
6958 for (
size_t i = 0; i < keywords_list->
size; i++) {
6962 switch (PM_NODE_TYPE(keyword_parameter_node)) {
6963 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
6971 if (!PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) {
6972 LABEL *end_label = NEW_LABEL(location.
line);
6975 int kw_bits_idx = table_size - body->param.keyword->bits_start;
6976 PUSH_INSN2(ret, location, checkkeyword,
INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1),
INT2FIX(optional_index));
6977 PUSH_INSNL(ret, location, branchif, end_label);
6979 PUSH_SETLOCAL(ret, location, index.index, index.level);
6980 PUSH_LABEL(ret, end_label);
6985 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
6990 rb_bug(
"Unexpected keyword parameter node type %s", pm_node_type(PM_NODE_TYPE(keyword_parameter_node)));
6995 if (requireds_list && requireds_list->
size) {
6996 for (
size_t i = 0; i < requireds_list->
size; i++) {
7002 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
7003 PUSH_GETLOCAL(ret, location, table_size - (
int)i, 0);
7009 if (posts_list && posts_list->
size) {
7010 for (
size_t i = 0; i < posts_list->
size; i++) {
7016 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
7017 PUSH_GETLOCAL(ret, location, table_size - body->param.post_start - (
int) i, 0);
7023 switch (body->type) {
7024 case ISEQ_TYPE_PLAIN: {
7025 RUBY_ASSERT(PM_NODE_TYPE_P(scope_node->ast_node, PM_INTERPOLATED_REGULAR_EXPRESSION_NODE));
7028 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
7032 case ISEQ_TYPE_BLOCK: {
7033 LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
7034 LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
7037 start->rescued = LABEL_RESCUE_BEG;
7038 end->rescued = LABEL_RESCUE_END;
7044 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
7045 pm_compile_for_node_index(iseq, ((
const pm_for_node_t *) scope_node->ast_node)->index, ret, scope_node);
7049 PUSH_INSN(ret, block_location, nop);
7050 PUSH_LABEL(ret, start);
7052 if (scope_node->body != NULL) {
7053 switch (PM_NODE_TYPE(scope_node->ast_node)) {
7054 case PM_POST_EXECUTION_NODE: {
7056 PUSH_INSN1(ret, block_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7060 pm_scope_node_init((
const pm_node_t *) cast->statements, &next_scope_node, scope_node);
7062 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(body->parent_iseq), ISEQ_TYPE_BLOCK, location.
line);
7063 pm_scope_node_destroy(&next_scope_node);
7065 PUSH_CALL_WITH_BLOCK(ret, block_location, id_core_set_postexe,
INT2FIX(0), block);
7068 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
7070 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
7074 pm_compile_node(iseq, scope_node->body, ret, popped, scope_node);
7079 PUSH_INSN(ret, block_location, putnil);
7082 PUSH_LABEL(ret, end);
7084 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7087 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
7088 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
7091 case ISEQ_TYPE_ENSURE: {
7092 const pm_node_location_t statements_location = (scope_node->body != NULL ? PM_NODE_START_LOCATION(scope_node->body) : location);
7093 iseq_set_exception_local_table(iseq);
7095 if (scope_node->body != NULL) {
7096 PM_COMPILE_POPPED((
const pm_node_t *) scope_node->body);
7099 PUSH_GETLOCAL(ret, statements_location, 1, 0);
7100 PUSH_INSN1(ret, statements_location,
throw,
INT2FIX(0));
7103 case ISEQ_TYPE_METHOD: {
7104 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7107 if (scope_node->body) {
7108 PM_COMPILE((
const pm_node_t *) scope_node->body);
7111 PUSH_INSN(ret, location, putnil);
7114 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7117 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7120 case ISEQ_TYPE_RESCUE: {
7121 iseq_set_exception_local_table(iseq);
7122 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_RESCUE_MODIFIER_NODE)) {
7124 LABEL *rescue_end = NEW_LABEL(location.
line);
7125 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7127 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
7128 PUSH_INSNL(ret, location, branchif, lab);
7129 PUSH_INSNL(ret, location, jump, rescue_end);
7130 PUSH_LABEL(ret, lab);
7132 PM_COMPILE((
const pm_node_t *) scope_node->body);
7133 PUSH_INSN(ret, location, leave);
7134 PUSH_LABEL(ret, rescue_end);
7135 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7138 PM_COMPILE((
const pm_node_t *) scope_node->ast_node);
7140 PUSH_INSN1(ret, location,
throw,
INT2FIX(0));
7145 if (scope_node->body) {
7146 PM_COMPILE((
const pm_node_t *) scope_node->body);
7149 PUSH_INSN(ret, location, putnil);
7154 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
7157 ISEQ_COMPILE_DATA(iseq)->last_line = end_location.
line;
7160 if (!PM_NODE_TYPE_P(scope_node->ast_node, PM_ENSURE_NODE)) {
7162 PUSH_INSN(ret, location, leave);
7171 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7175 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7176 PUSH_INSN1(ret, *location, putobject, operand);
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);
7185 PUSH_SEND(ret, *location, id_core_set_variable_alias,
INT2FIX(2));
7186 if (popped) PUSH_INSN(ret, *location, pop);
7192 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7193 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
7194 PM_COMPILE_NOT_POPPED(node->
new_name);
7195 PM_COMPILE_NOT_POPPED(node->
old_name);
7197 PUSH_SEND(ret, *location, id_core_set_method_alias,
INT2FIX(3));
7198 if (popped) PUSH_INSN(ret, *location, pop);
7218 const pm_node_type_t
type = PM_NODE_TYPE(nodes[1]);
7219 LABEL *end_label = NEW_LABEL(location->
line);
7221 for (
size_t index = 0; index + 1 < size; index += 2) {
7222 PM_COMPILE_NOT_POPPED(nodes[index]);
7228 .node_id = nodes[index + 1]->
node_id
7231 if (!popped) PUSH_INSN(ret, operator_location, dup);
7232 if (type == PM_AND_NODE)
7234 PUSH_INSNL(ret, operator_location, branchunless, end_label);
7237 PUSH_INSNL(ret, operator_location, branchif, end_label);
7239 if (!popped) PUSH_INSN(ret, operator_location, pop);
7242 PM_COMPILE(nodes[size - 1]);
7243 PUSH_LABEL(ret, end_label);
7252 while (PM_NODE_TYPE_P(cursor, PM_AND_NODE)) {
7261 size_t index = size;
7263 while (PM_NODE_TYPE_P(cursor, PM_AND_NODE)) {
7265 nodes[--index] = cast->
right;
7266 nodes[--index] = cursor;
7267 cursor = cast->
left;
7271 pm_compile_logical_chain(iseq, size, nodes, location, ret, popped, scope_node);
7280 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
7285 if (elements->
size) {
7286 VALUE value = pm_static_literal_value(iseq, node, scope_node);
7288 PUSH_INSN1(ret, *location, duparray, value);
7291 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7309 const int max_new_array_size = 0x100;
7310 const unsigned int min_tmp_array_size = 0x40;
7312 int new_array_size = 0;
7313 bool first_chunk =
true;
7319 bool static_literal =
false;
7322#define FLUSH_CHUNK \
7323 if (new_array_size) { \
7324 if (first_chunk) PUSH_INSN1(ret, *location, newarray, INT2FIX(new_array_size)); \
7325 else PUSH_INSN1(ret, *location, pushtoarray, INT2FIX(new_array_size)); \
7326 first_chunk = false; \
7327 new_array_size = 0; \
7330 for (
size_t index = 0; index < elements->
size; index++) {
7333 if (PM_NODE_TYPE_P(element, PM_SPLAT_NODE)) {
7338 PM_COMPILE_NOT_POPPED(splat_element->
expression);
7341 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
7342 PUSH_GETLOCAL(ret, *location, index.index, index.level);
7348 PUSH_INSN1(ret, *location, splatarray,
Qtrue);
7349 first_chunk =
false;
7352 PUSH_INSN(ret, *location, concattoarray);
7355 static_literal =
false;
7357 else if (PM_NODE_TYPE_P(element, PM_KEYWORD_HASH_NODE)) {
7358 if (new_array_size == 0 && first_chunk) {
7359 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7360 first_chunk =
false;
7377 pm_compile_hash_elements(iseq, element, &keyword_hash->
elements, 0,
Qundef,
false, ret, scope_node);
7384 while (splats < keyword_hash->elements.
size && PM_NODE_TYPE_P(keyword_hash->
elements.
nodes[splats], PM_ASSOC_SPLAT_NODE)) splats++;
7387 PUSH_INSN(ret, *location, pushtoarraykwsplat);
7394 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) &&
7395 !PM_CONTAINER_P(element) &&
7397 ((index + min_tmp_array_size) < elements->
size)
7402 size_t right_index = index + 1;
7404 right_index < elements->size &&
7405 PM_NODE_FLAG_P(elements->
nodes[right_index], PM_NODE_FLAG_STATIC_LITERAL) &&
7406 !PM_CONTAINER_P(elements->
nodes[right_index])
7409 size_t tmp_array_size = right_index - index;
7410 if (tmp_array_size >= min_tmp_array_size) {
7414 for (; tmp_array_size; tmp_array_size--)
7415 rb_ary_push(tmp_array, pm_static_literal_value(iseq, elements->
nodes[index++], scope_node));
7423 PUSH_INSN1(ret, *location, duparray, tmp_array);
7424 first_chunk =
false;
7427 PUSH_INSN1(ret, *location, putobject, tmp_array);
7428 PUSH_INSN(ret, *location, concattoarray);
7432 PM_COMPILE_NOT_POPPED(element);
7433 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7434 static_literal =
true;
7437 PM_COMPILE_NOT_POPPED(element);
7438 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7439 static_literal =
false;
7444 if (popped) PUSH_INSN(ret, *location, pop);
7452 unsigned long throw_flag = 0;
7454 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
7456 LABEL *splabel = NEW_LABEL(0);
7457 PUSH_LABEL(ret, splabel);
7458 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7464 PUSH_INSN(ret, *location, putnil);
7467 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7468 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
7469 PUSH_ADJUST_RESTORE(ret, splabel);
7470 if (!popped) PUSH_INSN(ret, *location, putnil);
7476 if (!ISEQ_COMPILE_DATA(ip)) {
7481 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7482 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
7484 else if (ISEQ_BODY(ip)->type == ISEQ_TYPE_BLOCK) {
7487 else if (ISEQ_BODY(ip)->type == ISEQ_TYPE_EVAL) {
7488 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7492 ip = ISEQ_BODY(ip)->parent_iseq;
7501 PUSH_INSN(ret, *location, putnil);
7504 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_BREAK));
7505 if (popped) PUSH_INSN(ret, *location, pop);
7510 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7517 ID method_id = pm_constant_id_lookup(scope_node, node->
name);
7523 const char *builtin_func;
7525 if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && (builtin_func = pm_iseq_builtin_function_name(scope_node, node->
receiver, method_id)) != NULL) {
7526 pm_compile_builtin_function_call(iseq, ret, scope_node, node, &location, popped, ISEQ_COMPILE_DATA(iseq)->current_block, builtin_func);
7530 LABEL *start = NEW_LABEL(location.
line);
7531 if (node->
block) PUSH_LABEL(ret, start);
7533 switch (method_id) {
7535 if (pm_opt_str_freeze_p(iseq, node)) {
7537 const struct rb_callinfo *callinfo = new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE);
7538 PUSH_INSN2(ret, location, opt_str_uminus, value, callinfo);
7539 if (popped) PUSH_INSN(ret, location, pop);
7545 if (pm_opt_str_freeze_p(iseq, node)) {
7547 const struct rb_callinfo *callinfo = new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE);
7548 PUSH_INSN2(ret, location, opt_str_freeze, value, callinfo);
7549 if (popped) PUSH_INSN(ret, location, pop);
7556 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
7557 PUSH_INSN(ret, location, putnil);
7561 PUSH_INSN(ret, location, putself);
7564 if ((method_id == idCall || method_id == idAREF || method_id == idYield || method_id == idEqq) && PM_NODE_TYPE_P(node->
receiver, PM_LOCAL_VARIABLE_READ_NODE)) {
7569 if (iseq_block_param_id_p(iseq, pm_constant_id_lookup(scope_node, read_node_cast->name), &idx, &level)) {
7570 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)));
7573 PM_COMPILE_NOT_POPPED(node->
receiver);
7577 PM_COMPILE_NOT_POPPED(node->
receiver);
7581 pm_compile_call(iseq, node, ret, popped, scope_node, method_id, start);
7590 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
7591 flag = VM_CALL_FCALL;
7594 PM_COMPILE_NOT_POPPED(node->
receiver);
7596 LABEL *safe_label = NULL;
7597 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
7598 safe_label = NEW_LABEL(location->
line);
7599 PUSH_INSN(ret, *location, dup);
7600 PUSH_INSNL(ret, *location, branchnil, safe_label);
7603 PUSH_INSN(ret, *location, dup);
7605 ID id_read_name = pm_constant_id_lookup(scope_node, node->
read_name);
7606 PUSH_SEND_WITH_FLAG(ret, *location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
7608 PM_COMPILE_NOT_POPPED(node->
value);
7610 PUSH_SEND(ret, *location, id_operator,
INT2FIX(1));
7613 PUSH_INSN(ret, *location, swap);
7614 PUSH_INSN1(ret, *location, topn,
INT2FIX(1));
7617 ID id_write_name = pm_constant_id_lookup(scope_node, node->
write_name);
7618 PUSH_SEND_WITH_FLAG(ret, *location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
7620 if (safe_label != NULL && popped) PUSH_LABEL(ret, safe_label);
7621 PUSH_INSN(ret, *location, pop);
7622 if (safe_label != NULL && !popped) PUSH_LABEL(ret, safe_label);
7645 switch (PM_NODE_TYPE(node)) {
7646 case PM_FLOAT_NODE: {
7647 key = pm_static_literal_value(iseq, node, scope_node);
7651 key = (
FIXABLE(intptr) ?
LONG2FIX((
long) intptr) : rb_dbl2big(intptr));
7657 case PM_INTEGER_NODE:
7659 case PM_SOURCE_LINE_NODE:
7660 case PM_SYMBOL_NODE:
7662 key = pm_static_literal_value(iseq, node, scope_node);
7664 case PM_STRING_NODE: {
7666 key = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
7673 cdhash_aset_if_missing(dispatch, key, (
VALUE)label);
7689 DECL_ANCHOR(cond_seq);
7694 DECL_ANCHOR(body_seq);
7698 LABEL *end_label = NEW_LABEL(location.
line);
7709 if (PM_BRANCH_COVERAGE_P(iseq)) {
7710 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7711 branches = decl_branch_base(iseq, (
int) cast->
base.
node_id, &case_location,
"case");
7717 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7721 int clause_lineno = pm_node_line_number_cached((
const pm_node_t *) clause, scope_node);
7722 LABEL *label = NEW_LABEL(clause_lineno);
7723 PUSH_LABEL(body_seq, label);
7726 if (PM_BRANCH_COVERAGE_P(iseq)) {
7728 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7731 if (clause->statements != NULL) {
7732 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7735 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7738 PUSH_INSNL(body_seq, location, jump, end_label);
7743 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7746 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7748 PUSH_INSN(cond_seq, cond_location, putnil);
7749 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7750 PUSH_INSN1(cond_seq, cond_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
7751 PUSH_INSNL(cond_seq, cond_location, branchif, label);
7754 LABEL *next_label = NEW_LABEL(pm_node_line_number_cached(condition, scope_node));
7755 pm_compile_branch_condition(iseq, cond_seq, condition, label, next_label, scope_node);
7756 PUSH_LABEL(cond_seq, next_label);
7763 if (PM_BRANCH_COVERAGE_P(iseq)) {
7767 branch_location = case_location;
7774 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7782 PUSH_SYNTHETIC_PUTNIL(cond_seq, iseq);
7787 PUSH_INSNL(cond_seq, location, jump, end_label);
7788 PUSH_SEQ(ret, cond_seq);
7796 if (PM_BRANCH_COVERAGE_P(iseq)) {
7797 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7798 branches = decl_branch_base(iseq, (
int) cast->
base.
node_id, &case_location,
"case");
7803 LABEL *else_label = NEW_LABEL(location.
line);
7811 if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
7812 dispatch = cdhash_new(0);
7823 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7828 LABEL *label = NEW_LABEL(clause_location.
line);
7833 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7840 if (dispatch !=
Qundef) {
7841 dispatch = pm_compile_case_node_dispatch(iseq, dispatch, condition, label, scope_node);
7844 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7845 PUSH_INSN(cond_seq, condition_location, dup);
7846 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7847 PUSH_INSN1(cond_seq, condition_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
7850 if (PM_NODE_TYPE_P(condition, PM_STRING_NODE)) {
7852 VALUE value = parse_static_literal_string(iseq, scope_node, condition, &string->
unescaped);
7853 PUSH_INSN1(cond_seq, condition_location, putobject, value);
7856 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7859 PUSH_INSN1(cond_seq, condition_location, topn,
INT2FIX(1));
7860 PUSH_SEND_WITH_FLAG(cond_seq, condition_location, idEqq,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
7863 PUSH_INSNL(cond_seq, condition_location, branchif, label);
7870 PUSH_LABEL(body_seq, label);
7871 PUSH_INSN(body_seq, clause_location, pop);
7874 if (PM_BRANCH_COVERAGE_P(iseq)) {
7876 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7879 if (clause->statements != NULL) {
7880 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7883 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7886 PUSH_INSNL(body_seq, clause_location, jump, end_label);
7897 if (dispatch !=
Qundef) {
7898 PUSH_INSN(ret, location, dup);
7900 PUSH_INSN2(ret, location, opt_case_dispatch, dispatch, else_label);
7901 LABEL_REF(else_label);
7904 PUSH_SEQ(ret, cond_seq);
7908 PUSH_LABEL(ret, else_label);
7912 PUSH_INSN(ret, else_location, pop);
7915 if (PM_BRANCH_COVERAGE_P(iseq)) {
7917 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7921 PUSH_INSNL(ret, else_location, jump, end_label);
7924 PUSH_INSN(ret, location, pop);
7927 if (PM_BRANCH_COVERAGE_P(iseq)) {
7928 add_trace_branch_coverage(iseq, ret, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7931 if (!popped) PUSH_INSN(ret, location, putnil);
7932 PUSH_INSNL(ret, location, jump, end_label);
7936 PUSH_SEQ(ret, body_seq);
7937 PUSH_LABEL(ret, end_label);
7946 DECL_ANCHOR(body_seq);
7951 DECL_ANCHOR(cond_seq);
7955 LABEL *end_label = NEW_LABEL(location->
line);
7960 LABEL *else_label = NEW_LABEL(location->
line);
7968 if (PM_BRANCH_COVERAGE_P(iseq)) {
7969 case_location = pm_code_location(scope_node, (
const pm_node_t *) node);
7970 branches = decl_branch_base(iseq, (
int) node->
base.
node_id, &case_location,
"case");
7980 if (in_single_pattern) {
7981 PUSH_INSN(ret, *location, putnil);
7982 PUSH_INSN(ret, *location, putnil);
7983 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7984 PUSH_INSN(ret, *location, putnil);
7988 PUSH_INSN(ret, *location, putnil);
7997 RUBY_ASSERT(PM_NODE_TYPE_P(condition, PM_IN_NODE));
8004 PUSH_INSN(body_seq, in_location, putnil);
8007 LABEL *body_label = NEW_LABEL(in_location.
line);
8008 PUSH_LABEL(body_seq, body_label);
8009 PUSH_INSN1(body_seq, in_location, adjuststack,
INT2FIX(in_single_pattern ? 6 : 2));
8012 if (PM_BRANCH_COVERAGE_P(iseq)) {
8014 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"in", branches);
8021 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
8024 PUSH_INSNL(body_seq, in_location, jump, end_label);
8025 LABEL *next_pattern_label = NEW_LABEL(pattern_location.
line);
8027 PUSH_INSN(cond_seq, pattern_location, dup);
8028 pm_compile_pattern(iseq, scope_node, in_node->
pattern, cond_seq, body_label, next_pattern_label, in_single_pattern,
true, 2);
8029 PUSH_LABEL(cond_seq, next_pattern_label);
8030 LABEL_UNREMOVABLE(next_pattern_label);
8039 PUSH_LABEL(cond_seq, else_label);
8040 PUSH_INSN(cond_seq, *location, pop);
8041 PUSH_INSN(cond_seq, *location, pop);
8044 if (PM_BRANCH_COVERAGE_P(iseq)) {
8046 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
8049 PM_COMPILE_INTO_ANCHOR(cond_seq, (
const pm_node_t *) else_node);
8050 PUSH_INSNL(cond_seq, *location, jump, end_label);
8051 PUSH_INSN(cond_seq, *location, putnil);
8052 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8057 PUSH_LABEL(cond_seq, else_label);
8060 add_trace_branch_coverage(iseq, cond_seq, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
8062 if (in_single_pattern) {
8063 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, cond_seq, end_label, popped);
8066 PUSH_INSN1(cond_seq, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8068 PUSH_INSN1(cond_seq, *location, topn,
INT2FIX(2));
8069 PUSH_SEND(cond_seq, *location, id_core_raise,
INT2FIX(2));
8071 PUSH_INSN1(cond_seq, *location, adjuststack,
INT2FIX(3));
8072 if (!popped) PUSH_INSN(cond_seq, *location, putnil);
8073 PUSH_INSNL(cond_seq, *location, jump, end_label);
8074 PUSH_INSN1(cond_seq, *location, dupn,
INT2FIX(1));
8075 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8082 PUSH_SEQ(ret, cond_seq);
8083 PUSH_SEQ(ret, body_seq);
8084 PUSH_LABEL(ret, end_label);
8092 LABEL *retry_label = NULL;
8093 LABEL *retry_end_l = NULL;
8095 if (node->
block != NULL) {
8096 previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8097 ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
8099 retry_label = NEW_LABEL(location->
line);
8100 retry_end_l = NEW_LABEL(location->
line);
8102 PUSH_LABEL(ret, retry_label);
8105 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8108 PUSH_INSN(ret, *location, putself);
8109 int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
8111 if (node->
block != NULL) {
8113 pm_scope_node_init((
const pm_node_t *) node->
block, &next_scope_node, scope_node);
8115 ISEQ_COMPILE_DATA(iseq)->current_block = block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8116 pm_scope_node_destroy(&next_scope_node);
8123 const rb_iseq_t *local_iseq = body->local_iseq;
8127 int depth = get_lvar_level(iseq);
8129 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8130 flag |= VM_CALL_FORWARDING;
8131 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
8132 PUSH_GETLOCAL(ret, *location, mult_local.index, mult_local.level);
8134 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, 0, flag, NULL, block != NULL);
8135 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, block);
8137 if (popped) PUSH_INSN(ret, *location, pop);
8139 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8144 if (local_body->param.flags.has_lead) {
8146 for (
int i = 0; i < local_body->param.lead_num; i++) {
8147 int idx = local_body->local_table_size - i;
8148 PUSH_GETLOCAL(args, *location, idx, depth);
8150 argc += local_body->param.lead_num;
8153 if (local_body->param.flags.has_opt) {
8155 for (
int j = 0; j < local_body->param.opt_num; j++) {
8156 int idx = local_body->local_table_size - (argc + j);
8157 PUSH_GETLOCAL(args, *location, idx, depth);
8159 argc += local_body->param.opt_num;
8162 if (local_body->param.flags.has_rest) {
8164 int idx = local_body->local_table_size - local_body->param.rest_start;
8165 PUSH_GETLOCAL(args, *location, idx, depth);
8166 PUSH_INSN1(args, *location, splatarray,
Qfalse);
8168 argc = local_body->param.rest_start + 1;
8169 flag |= VM_CALL_ARGS_SPLAT;
8172 if (local_body->param.flags.has_post) {
8174 int post_len = local_body->param.post_num;
8175 int post_start = local_body->param.post_start;
8178 for (; j < post_len; j++) {
8179 int idx = local_body->local_table_size - (post_start + j);
8180 PUSH_GETLOCAL(args, *location, idx, depth);
8183 if (local_body->param.flags.has_rest) {
8185 PUSH_INSN1(args, *location, newarray,
INT2FIX(j));
8186 PUSH_INSN(args, *location, concatarray);
8189 argc = post_len + post_start;
8193 const struct rb_iseq_param_keyword *
const local_keyword = local_body->param.keyword;
8194 if (local_body->param.flags.has_kw) {
8195 int local_size = local_body->local_table_size;
8198 PUSH_INSN1(args, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8200 if (local_body->param.flags.has_kwrest) {
8201 int idx = local_body->local_table_size - local_keyword->rest_start;
8202 PUSH_GETLOCAL(args, *location, idx, depth);
8204 PUSH_SEND(args, *location, rb_intern(
"dup"),
INT2FIX(0));
8207 PUSH_INSN1(args, *location, newhash,
INT2FIX(0));
8210 for (; i < local_keyword->num; ++i) {
8211 ID id = local_keyword->table[i];
8212 int idx = local_size - get_local_var_idx(local_iseq,
id);
8216 PUSH_INSN1(args, *location, putobject, operand);
8219 PUSH_GETLOCAL(args, *location, idx, depth);
8222 PUSH_SEND(args, *location, id_core_hash_merge_ptr,
INT2FIX(i * 2 + 1));
8223 flag |= VM_CALL_KW_SPLAT| VM_CALL_KW_SPLAT_MUT;
8225 else if (local_body->param.flags.has_kwrest) {
8226 int idx = local_body->local_table_size - local_keyword->rest_start;
8227 PUSH_GETLOCAL(args, *location, idx, depth);
8229 flag |= VM_CALL_KW_SPLAT;
8232 PUSH_SEQ(ret, args);
8235 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flag, NULL, block != NULL);
8236 PUSH_INSN2(ret, *location, invokesuper, callinfo, block);
8239 if (node->
block != NULL) {
8240 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8241 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, block, retry_end_l);
8242 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8245 if (popped) PUSH_INSN(ret, *location, pop);
8251 LABEL *matched_label = NEW_LABEL(location->
line);
8252 LABEL *unmatched_label = NEW_LABEL(location->
line);
8253 LABEL *done_label = NEW_LABEL(location->
line);
8257 PUSH_INSN(ret, *location, putnil);
8258 PUSH_INSN(ret, *location, putnil);
8259 PUSH_INSN1(ret, *location, putobject,
Qfalse);
8260 PUSH_INSN(ret, *location, putnil);
8261 PUSH_INSN(ret, *location, putnil);
8265 PM_COMPILE_NOT_POPPED(node->
value);
8269 PUSH_INSN(ret, *location, dup);
8276 pm_compile_pattern(iseq, scope_node, node->
pattern, ret, matched_label, unmatched_label,
true,
true, 2);
8281 PUSH_LABEL(ret, unmatched_label);
8282 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, ret, done_label, popped);
8286 PUSH_LABEL(ret, matched_label);
8287 PUSH_INSN1(ret, *location, adjuststack,
INT2FIX(6));
8288 if (!popped) PUSH_INSN(ret, *location, putnil);
8289 PUSH_INSNL(ret, *location, jump, done_label);
8291 PUSH_LABEL(ret, done_label);
8297 LABEL *fail_label = NEW_LABEL(location->
line);
8298 LABEL *end_label = NEW_LABEL(location->
line);
8309 PUSH_INSN1(ret, *location, getglobal, operand);
8312 PUSH_INSN(ret, *location, dup);
8313 PUSH_INSNL(ret, *location, branchunless, fail_label);
8319 if (targets_count == 1) {
8321 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8328 PUSH_INSN1(ret, *location, putobject, operand);
8331 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8332 PUSH_LABEL(ret, fail_label);
8333 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8334 if (popped) PUSH_INSN(ret, *location, pop);
8338 DECL_ANCHOR(fail_anchor);
8342 for (
size_t targets_index = 0; targets_index < targets_count; targets_index++) {
8344 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8349 if (((
size_t) targets_index) < (targets_count - 1)) {
8350 PUSH_INSN(ret, *location, dup);
8355 PUSH_INSN1(ret, *location, putobject, operand);
8358 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8359 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8361 PUSH_INSN(fail_anchor, *location, putnil);
8362 PUSH_SETLOCAL(fail_anchor, *location, index.index, index.level);
8366 PUSH_INSNL(ret, *location, jump, end_label);
8370 PUSH_LABEL(ret, fail_label);
8371 PUSH_INSN(ret, *location, pop);
8372 PUSH_SEQ(ret, fail_anchor);
8375 PUSH_LABEL(ret, end_label);
8376 if (popped) PUSH_INSN(ret, *location, pop);
8382 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
8383 LABEL *splabel = NEW_LABEL(0);
8384 PUSH_LABEL(ret, splabel);
8390 PUSH_INSN(ret, *location, putnil);
8392 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8394 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8395 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8397 PUSH_ADJUST_RESTORE(ret, splabel);
8398 if (!popped) PUSH_INSN(ret, *location, putnil);
8400 else if (ISEQ_COMPILE_DATA(iseq)->end_label && can_add_ensure_iseq(iseq)) {
8401 LABEL *splabel = NEW_LABEL(0);
8403 PUSH_LABEL(ret, splabel);
8404 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8410 PUSH_INSN(ret, *location, putnil);
8413 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8414 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
8415 PUSH_ADJUST_RESTORE(ret, splabel);
8416 splabel->unremovable = FALSE;
8418 if (!popped) PUSH_INSN(ret, *location, putnil);
8422 unsigned long throw_flag = 0;
8425 if (!ISEQ_COMPILE_DATA(ip)) {
8430 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
8431 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8435 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8438 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8439 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8443 ip = ISEQ_BODY(ip)->parent_iseq;
8451 PUSH_INSN(ret, *location, putnil);
8454 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_NEXT));
8455 if (popped) PUSH_INSN(ret, *location, pop);
8458 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8469 while (PM_NODE_TYPE_P(cursor, PM_OR_NODE)) {
8478 size_t index = size;
8480 while (PM_NODE_TYPE_P(cursor, PM_OR_NODE)) {
8482 nodes[--index] = cast->
right;
8483 nodes[--index] = cursor;
8484 cursor = cast->
left;
8488 pm_compile_logical_chain(iseq, size, nodes, location, ret, popped, scope_node);
8495 if (ISEQ_COMPILE_DATA(iseq)->redo_label && can_add_ensure_iseq(iseq)) {
8496 LABEL *splabel = NEW_LABEL(0);
8498 PUSH_LABEL(ret, splabel);
8499 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8500 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8502 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
8503 PUSH_ADJUST_RESTORE(ret, splabel);
8504 if (!popped) PUSH_INSN(ret, *location, putnil);
8506 else if (ISEQ_BODY(iseq)->
type != ISEQ_TYPE_EVAL && ISEQ_COMPILE_DATA(iseq)->start_label && can_add_ensure_iseq(iseq)) {
8507 LABEL *splabel = NEW_LABEL(0);
8509 PUSH_LABEL(ret, splabel);
8510 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8511 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8513 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8514 PUSH_ADJUST_RESTORE(ret, splabel);
8515 if (!popped) PUSH_INSN(ret, *location, putnil);
8521 if (!ISEQ_COMPILE_DATA(ip)) {
8526 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8529 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8532 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8533 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8537 ip = ISEQ_BODY(ip)->parent_iseq;
8541 PUSH_INSN(ret, *location, putnil);
8542 PUSH_INSN1(ret, *location,
throw,
INT2FIX(VM_THROW_NO_ESCAPE_FLAG | TAG_REDO));
8543 if (popped) PUSH_INSN(ret, *location, pop);
8546 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8554 iseq_set_exception_local_table(iseq);
8558 LABEL *exception_match_label = NEW_LABEL(location->
line);
8559 LABEL *rescue_end_label = NEW_LABEL(location->
line);
8569 if (exceptions->
size > 0) {
8570 for (
size_t index = 0; index < exceptions->
size; index++) {
8571 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8572 PM_COMPILE(exceptions->
nodes[index]);
8573 int checkmatch_flags = VM_CHECKMATCH_TYPE_RESCUE;
8574 if (PM_NODE_TYPE_P(exceptions->
nodes[index], PM_SPLAT_NODE)) {
8575 checkmatch_flags |= VM_CHECKMATCH_ARRAY;
8577 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(checkmatch_flags));
8578 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8582 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8584 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
8585 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8590 PUSH_INSNL(ret, *location, jump, rescue_end_label);
8595 PUSH_LABEL(ret, exception_match_label);
8602 DECL_ANCHOR(writes);
8603 DECL_ANCHOR(cleanup);
8605 pm_compile_target_node(iseq, node->
reference, ret, writes, cleanup, scope_node, NULL);
8606 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8608 PUSH_SEQ(ret, writes);
8609 PUSH_SEQ(ret, cleanup);
8619 LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
8620 ISEQ_COMPILE_DATA(iseq)->end_label = NULL;
8625 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
8628 PUSH_INSN(ret, *location, putnil);
8631 PUSH_INSN(ret, *location, leave);
8637 PUSH_LABEL(ret, rescue_end_label);
8642 PUSH_GETLOCAL(ret, *location, 1, 0);
8650 enum rb_iseq_type
type = ISEQ_BODY(iseq)->type;
8654 enum rb_iseq_type parent_type = ISEQ_BODY(parent_iseq)->type;
8655 while (parent_type == ISEQ_TYPE_RESCUE || parent_type == ISEQ_TYPE_ENSURE) {
8656 if (!(parent_iseq = ISEQ_BODY(parent_iseq)->parent_iseq))
break;
8657 parent_type = ISEQ_BODY(parent_iseq)->type;
8660 switch (parent_type) {
8662 case ISEQ_TYPE_MAIN:
8664 rb_warn(
"argument of top-level return is ignored");
8666 if (parent_iseq == iseq) {
8667 type = ISEQ_TYPE_METHOD;
8674 if (
type == ISEQ_TYPE_METHOD) {
8675 splabel = NEW_LABEL(0);
8676 PUSH_LABEL(ret, splabel);
8677 PUSH_ADJUST(ret, *location, 0);
8680 if (arguments != NULL) {
8681 PM_COMPILE_NOT_POPPED((
const pm_node_t *) arguments);
8684 PUSH_INSN(ret, *location, putnil);
8687 if (
type == ISEQ_TYPE_METHOD && can_add_ensure_iseq(iseq)) {
8688 pm_add_ensure_iseq(ret, iseq, 1, scope_node);
8690 PUSH_INSN(ret, *location, leave);
8691 PUSH_ADJUST_RESTORE(ret, splabel);
8692 if (!popped) PUSH_INSN(ret, *location, putnil);
8695 PUSH_INSN1(ret, *location,
throw,
INT2FIX(TAG_RETURN));
8696 if (popped) PUSH_INSN(ret, *location, pop);
8705 LABEL *retry_label = NEW_LABEL(location->
line);
8706 LABEL *retry_end_l = NEW_LABEL(location->
line);
8708 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8710 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NULL;
8712 PUSH_LABEL(ret, retry_label);
8713 PUSH_INSN(ret, *location, putself);
8717 int argc = pm_setup_args(node->
arguments, node->
block, &flags, &keywords, iseq, ret, scope_node, location);
8718 bool is_forwardable = (node->
arguments != NULL) && PM_NODE_FLAG_P(node->
arguments, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING);
8719 flags |= VM_CALL_SUPER | VM_CALL_FCALL;
8721 if (node->
block && PM_NODE_TYPE_P(node->
block, PM_BLOCK_NODE)) {
8723 pm_scope_node_init(node->
block, &next_scope_node, scope_node);
8725 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8726 pm_scope_node_destroy(&next_scope_node);
8730 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8733 if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
8734 PUSH_INSN(args, *location, splatkw);
8737 PUSH_SEQ(ret, args);
8738 if (is_forwardable && ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8739 flags |= VM_CALL_FORWARDING;
8742 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8743 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, current_block);
8748 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8749 PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
8754 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8756 if (popped) PUSH_INSN(ret, *location, pop);
8757 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8758 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);
8764 switch (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
type) {
8766 case ISEQ_TYPE_MAIN:
8767 case ISEQ_TYPE_CLASS:
8768 COMPILE_ERROR(iseq, location->
line,
"Invalid yield");
8778 argc = pm_setup_args(node->
arguments, NULL, &flags, &keywords, iseq, ret, scope_node, location);
8781 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, FALSE);
8782 PUSH_INSN1(ret, *location, invokeblock, callinfo);
8784 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8785 if (popped) PUSH_INSN(ret, *location, pop);
8788 for (
const rb_iseq_t *tmp_iseq = iseq; tmp_iseq != ISEQ_BODY(iseq)->local_iseq; level++) {
8789 tmp_iseq = ISEQ_BODY(tmp_iseq)->parent_iseq;
8792 if (level > 0) access_outer_variables(iseq, level, rb_intern(
"yield"),
true);
8809 int lineno = (int) location.
line;
8811 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)) {
8816 lineno = (int) PM_NODE_START_LINE_COLUMN(((
const pm_begin_node_t *) node)->rescue_clause).line;
8819 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_NEWLINE) && ISEQ_COMPILE_DATA(iseq)->last_line != lineno) {
8825 ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8826 if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8827 event |= RUBY_EVENT_COVERAGE_LINE;
8829 PUSH_TRACE(ret, event);
8832 switch (PM_NODE_TYPE(node)) {
8833 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
8838 case PM_ALIAS_METHOD_NODE:
8841 pm_compile_alias_method_node(iseq, (
const pm_alias_method_node_t *) node, &location, ret, popped, scope_node);
8846 pm_compile_and_node(iseq, (
const pm_and_node_t *) node, &location, ret, popped, scope_node);
8848 case PM_ARGUMENTS_NODE: {
8858 if (elements->
size == 1) {
8861 PM_COMPILE(elements->
nodes[0]);
8864 pm_compile_array_node(iseq, (
const pm_node_t *) cast, elements, &location, ret, popped, scope_node);
8868 case PM_ARRAY_NODE: {
8872 pm_compile_array_node(iseq, (
const pm_node_t *) cast, &cast->elements, &location, ret, popped, scope_node);
8875 case PM_ASSOC_NODE: {
8883 PM_COMPILE(cast->
key);
8884 PM_COMPILE(cast->
value);
8888 case PM_ASSOC_SPLAT_NODE: {
8896 if (cast->
value != NULL) {
8897 PM_COMPILE(cast->
value);
8900 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
8901 PUSH_GETLOCAL(ret, location, index.index, index.level);
8906 case PM_BACK_REFERENCE_READ_NODE: {
8911 VALUE backref = pm_compile_back_reference_ref(scope_node, cast);
8913 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), backref);
8917 case PM_BEGIN_NODE: {
8925 pm_compile_ensure(iseq, cast, &location, ret, popped, scope_node);
8929 pm_compile_rescue(iseq, cast, &location, ret, popped, scope_node);
8938 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8943 case PM_BLOCK_ARGUMENT_NODE: {
8953 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
8954 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(local_index.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(local_index.level));
8964 pm_compile_break_node(iseq, (
const pm_break_node_t *) node, &location, ret, popped, scope_node);
8975 pm_compile_call_node(iseq, (
const pm_call_node_t *) node, ret, popped, scope_node);
8977 case PM_CALL_AND_WRITE_NODE: {
8981 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);
8984 case PM_CALL_OR_WRITE_NODE: {
8988 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);
8991 case PM_CALL_OPERATOR_WRITE_NODE:
9006 pm_compile_case_node(iseq, (
const pm_case_node_t *) node, &location, ret, popped, scope_node);
9008 case PM_CASE_MATCH_NODE:
9017 pm_compile_case_match_node(iseq, (
const pm_case_match_node_t *) node, &location, ret, popped, scope_node);
9019 case PM_CLASS_NODE: {
9024 ID class_id = pm_constant_id_lookup(scope_node, cast->
name);
9025 VALUE class_name =
rb_str_freeze(rb_sprintf(
"<class:%"PRIsVALUE
">", rb_id2str(class_id)));
9028 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9030 const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(&next_scope_node, class_name, ISEQ_TYPE_CLASS, location.
line);
9031 pm_scope_node_destroy(&next_scope_node);
9034 const int flags = VM_DEFINECLASS_TYPE_CLASS |
9035 (cast->
superclass ? VM_DEFINECLASS_FLAG_HAS_SUPERCLASS : 0) |
9036 pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
9042 PUSH_INSN(ret, location, putnil);
9047 PUSH_INSN3(ret, location, defineclass, operand, class_iseq,
INT2FIX(flags));
9051 if (popped) PUSH_INSN(ret, location, pop);
9054 case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
9058 LABEL *end_label = NEW_LABEL(location.
line);
9060 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9063 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9064 if (!popped) PUSH_INSN(ret, location, dup);
9066 PUSH_INSNL(ret, location, branchunless, end_label);
9067 if (!popped) PUSH_INSN(ret, location, pop);
9069 PM_COMPILE_NOT_POPPED(cast->
value);
9070 if (!popped) PUSH_INSN(ret, location, dup);
9072 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9073 PUSH_LABEL(ret, end_label);
9077 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
9082 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9085 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9086 PM_COMPILE_NOT_POPPED(cast->
value);
9089 int flags = VM_CALL_ARGS_SIMPLE;
9090 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9092 if (!popped) PUSH_INSN(ret, location, dup);
9093 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9097 case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
9101 LABEL *end_label = NEW_LABEL(location.
line);
9102 LABEL *start_label = NEW_LABEL(location.
line);
9104 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9107 PUSH_INSN(ret, location, putnil);
9108 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name,
Qtrue);
9109 PUSH_INSNL(ret, location, branchunless, start_label);
9111 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9112 if (!popped) PUSH_INSN(ret, location, dup);
9114 PUSH_INSNL(ret, location, branchif, end_label);
9115 if (!popped) PUSH_INSN(ret, location, pop);
9117 PUSH_LABEL(ret, start_label);
9118 PM_COMPILE_NOT_POPPED(cast->
value);
9119 if (!popped) PUSH_INSN(ret, location, dup);
9121 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9122 PUSH_LABEL(ret, end_label);
9126 case PM_CLASS_VARIABLE_READ_NODE: {
9131 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9132 PUSH_INSN2(ret, location, getclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9136 case PM_CLASS_VARIABLE_WRITE_NODE: {
9140 PM_COMPILE_NOT_POPPED(cast->
value);
9141 if (!popped) PUSH_INSN(ret, location, dup);
9143 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9144 PUSH_INSN2(ret, location, setclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9148 case PM_CONSTANT_PATH_NODE: {
9153 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache && ((parts = pm_constant_path_parts(node, scope_node)) !=
Qnil)) {
9154 ISEQ_BODY(iseq)->ic_size++;
9156 PUSH_INSN1(ret, location, opt_getconstant_path, parts);
9159 DECL_ANCHOR(prefix);
9162 pm_compile_constant_path(iseq, node, prefix, body, popped, scope_node);
9163 if (LIST_INSN_SIZE_ZERO(prefix)) {
9164 PUSH_INSN(ret, location, putnil);
9167 PUSH_SEQ(ret, prefix);
9170 PUSH_SEQ(ret, body);
9173 if (popped) PUSH_INSN(ret, location, pop);
9176 case PM_CONSTANT_PATH_AND_WRITE_NODE: {
9180 pm_compile_constant_path_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9183 case PM_CONSTANT_PATH_OR_WRITE_NODE: {
9187 pm_compile_constant_path_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9190 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
9194 pm_compile_constant_path_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9197 case PM_CONSTANT_PATH_WRITE_NODE: {
9201 pm_compile_constant_path_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9204 case PM_CONSTANT_READ_NODE: {
9210 pm_compile_constant_read(iseq, name, &cast->
base.
location, location.
node_id, ret, scope_node);
9211 if (popped) PUSH_INSN(ret, location, pop);
9215 case PM_CONSTANT_AND_WRITE_NODE: {
9219 pm_compile_constant_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9222 case PM_CONSTANT_OR_WRITE_NODE: {
9226 pm_compile_constant_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9229 case PM_CONSTANT_OPERATOR_WRITE_NODE: {
9233 pm_compile_constant_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9236 case PM_CONSTANT_WRITE_NODE: {
9240 pm_compile_constant_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9250 ID method_name = pm_constant_id_lookup(scope_node, cast->
name);
9253 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9255 rb_iseq_t *method_iseq = NEW_ISEQ(&next_scope_node, rb_id2str(method_name), ISEQ_TYPE_METHOD, location.
line);
9256 pm_scope_node_destroy(&next_scope_node);
9259 PM_COMPILE_NOT_POPPED(cast->
receiver);
9260 PUSH_INSN2(ret, location, definesmethod,
ID2SYM(method_name), method_iseq);
9263 PUSH_INSN2(ret, location, definemethod,
ID2SYM(method_name), method_iseq);
9268 PUSH_INSN1(ret, location, putobject,
ID2SYM(method_name));
9273 case PM_DEFINED_NODE: {
9277 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
false);
9280 case PM_EMBEDDED_STATEMENTS_NODE: {
9289 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9292 if (popped) PUSH_INSN(ret, location, pop);
9295 case PM_EMBEDDED_VARIABLE_NODE: {
9302 case PM_FALSE_NODE: {
9306 PUSH_INSN1(ret, location, putobject,
Qfalse);
9310 case PM_ENSURE_NODE: {
9319 case PM_ELSE_NODE: {
9328 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9333 case PM_FLIP_FLOP_NODE: {
9338 LABEL *final_label = NEW_LABEL(location.
line);
9339 LABEL *then_label = NEW_LABEL(location.
line);
9340 LABEL *else_label = NEW_LABEL(location.
line);
9342 pm_compile_flip_flop(cast, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
9344 PUSH_LABEL(ret, then_label);
9345 PUSH_INSN1(ret, location, putobject,
Qtrue);
9346 PUSH_INSNL(ret, location, jump, final_label);
9347 PUSH_LABEL(ret, else_label);
9348 PUSH_INSN1(ret, location, putobject,
Qfalse);
9349 PUSH_LABEL(ret, final_label);
9353 case PM_FLOAT_NODE: {
9358 PUSH_INSN1(ret, location, putobject, operand);
9367 LABEL *retry_label = NEW_LABEL(location.
line);
9368 LABEL *retry_end_l = NEW_LABEL(location.
line);
9371 PUSH_LABEL(ret, retry_label);
9377 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9379 const rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location.
line);
9380 pm_scope_node_destroy(&next_scope_node);
9382 const rb_iseq_t *prev_block = ISEQ_COMPILE_DATA(iseq)->current_block;
9383 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
9387 PUSH_SEND_WITH_BLOCK(ret, location, idEach,
INT2FIX(0), child_iseq);
9388 pm_compile_retry_end_label(iseq, ret, retry_end_l);
9390 if (popped) PUSH_INSN(ret, location, pop);
9391 ISEQ_COMPILE_DATA(iseq)->current_block = prev_block;
9392 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
9395 case PM_FORWARDING_ARGUMENTS_NODE:
9396 rb_bug(
"Cannot compile a ForwardingArgumentsNode directly\n");
9398 case PM_FORWARDING_SUPER_NODE:
9406 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
9410 LABEL *end_label = NEW_LABEL(location.
line);
9413 PUSH_INSN1(ret, location, getglobal, name);
9414 if (!popped) PUSH_INSN(ret, location, dup);
9416 PUSH_INSNL(ret, location, branchunless, end_label);
9417 if (!popped) PUSH_INSN(ret, location, pop);
9419 PM_COMPILE_NOT_POPPED(cast->
value);
9420 if (!popped) PUSH_INSN(ret, location, dup);
9422 PUSH_INSN1(ret, location, setglobal, name);
9423 PUSH_LABEL(ret, end_label);
9427 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
9433 PUSH_INSN1(ret, location, getglobal, name);
9434 PM_COMPILE_NOT_POPPED(cast->
value);
9437 int flags = VM_CALL_ARGS_SIMPLE;
9438 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9440 if (!popped) PUSH_INSN(ret, location, dup);
9441 PUSH_INSN1(ret, location, setglobal, name);
9445 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
9449 LABEL *set_label = NEW_LABEL(location.
line);
9450 LABEL *end_label = NEW_LABEL(location.
line);
9452 PUSH_INSN(ret, location, putnil);
9455 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name,
Qtrue);
9456 PUSH_INSNL(ret, location, branchunless, set_label);
9458 PUSH_INSN1(ret, location, getglobal, name);
9459 if (!popped) PUSH_INSN(ret, location, dup);
9461 PUSH_INSNL(ret, location, branchif, end_label);
9462 if (!popped) PUSH_INSN(ret, location, pop);
9464 PUSH_LABEL(ret, set_label);
9465 PM_COMPILE_NOT_POPPED(cast->
value);
9466 if (!popped) PUSH_INSN(ret, location, dup);
9468 PUSH_INSN1(ret, location, setglobal, name);
9469 PUSH_LABEL(ret, end_label);
9473 case PM_GLOBAL_VARIABLE_READ_NODE: {
9479 PUSH_INSN1(ret, location, getglobal, name);
9480 if (popped) PUSH_INSN(ret, location, pop);
9484 case PM_GLOBAL_VARIABLE_WRITE_NODE: {
9488 PM_COMPILE_NOT_POPPED(cast->
value);
9489 if (!popped) PUSH_INSN(ret, location, dup);
9491 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9492 PUSH_INSN1(ret, location, setglobal,
ID2SYM(name));
9496 case PM_HASH_NODE: {
9502 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9510 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
9513 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9514 PUSH_INSN1(ret, location, duphash, value);
9535 for (
size_t index = 0; index < elements->
size; index++) {
9536 PM_COMPILE_POPPED(elements->
nodes[index]);
9540 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9556 pm_compile_conditional(iseq, &location, PM_IF_NODE, (
const pm_node_t *) cast, cast->statements, cast->subsequent, cast->predicate, ret, popped, scope_node);
9559 case PM_IMAGINARY_NODE: {
9564 PUSH_INSN1(ret, location, putobject, operand);
9568 case PM_IMPLICIT_NODE: {
9578 PM_COMPILE(cast->
value);
9584 rb_bug(
"Should not ever enter an in node directly");
9587 case PM_INDEX_OPERATOR_WRITE_NODE: {
9591 pm_compile_index_operator_write_node(iseq, cast, &location, ret, popped, scope_node);
9594 case PM_INDEX_AND_WRITE_NODE: {
9598 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9601 case PM_INDEX_OR_WRITE_NODE: {
9605 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9608 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
9612 LABEL *end_label = NEW_LABEL(location.
line);
9614 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9617 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9618 if (!popped) PUSH_INSN(ret, location, dup);
9620 PUSH_INSNL(ret, location, branchunless, end_label);
9621 if (!popped) PUSH_INSN(ret, location, pop);
9623 PM_COMPILE_NOT_POPPED(cast->
value);
9624 if (!popped) PUSH_INSN(ret, location, dup);
9626 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9627 PUSH_LABEL(ret, end_label);
9631 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
9636 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9639 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9640 PM_COMPILE_NOT_POPPED(cast->
value);
9643 int flags = VM_CALL_ARGS_SIMPLE;
9644 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9646 if (!popped) PUSH_INSN(ret, location, dup);
9647 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9651 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
9655 LABEL *end_label = NEW_LABEL(location.
line);
9657 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9660 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9661 if (!popped) PUSH_INSN(ret, location, dup);
9663 PUSH_INSNL(ret, location, branchif, end_label);
9664 if (!popped) PUSH_INSN(ret, location, pop);
9666 PM_COMPILE_NOT_POPPED(cast->
value);
9667 if (!popped) PUSH_INSN(ret, location, dup);
9669 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9670 PUSH_LABEL(ret, end_label);
9674 case PM_INSTANCE_VARIABLE_READ_NODE: {
9679 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9680 PUSH_INSN2(ret, location, getinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9684 case PM_INSTANCE_VARIABLE_WRITE_NODE: {
9688 PM_COMPILE_NOT_POPPED(cast->
value);
9689 if (!popped) PUSH_INSN(ret, location, dup);
9691 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9692 PUSH_INSN2(ret, location, setinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9696 case PM_INTEGER_NODE: {
9701 PUSH_INSN1(ret, location, putobject, operand);
9705 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
9708 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9710 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9711 PUSH_INSN1(ret, location, putobject, regexp);
9718 PUSH_INSN1(ret, location, getglobal,
rb_id2sym(idLASTLINE));
9719 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9720 if (popped) PUSH_INSN(ret, location, pop);
9724 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
9727 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ONCE)) {
9728 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9730 int ise_index = ISEQ_BODY(iseq)->ise_size++;
9733 pm_scope_node_init(node, &next_scope_node, scope_node);
9735 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, location.
line);
9736 pm_scope_node_destroy(&next_scope_node);
9738 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
9739 PUSH_INSN2(ret, location, once, block_iseq,
INT2FIX(ise_index));
9740 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9742 if (popped) PUSH_INSN(ret, location, pop);
9746 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9748 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9749 PUSH_INSN1(ret, location, putobject, regexp);
9754 if (popped) PUSH_INSN(ret, location, pop);
9759 case PM_INTERPOLATED_STRING_NODE: {
9762 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9764 VALUE string = pm_static_literal_value(iseq, node, scope_node);
9766 if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN)) {
9767 PUSH_INSN1(ret, location, putobject,
string);
9769 else if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE)) {
9770 PUSH_INSN1(ret, location, dupstring,
string);
9773 PUSH_INSN1(ret, location, dupchilledstring,
string);
9779 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));
9780 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9781 if (popped) PUSH_INSN(ret, location, pop);
9786 case PM_INTERPOLATED_SYMBOL_NODE: {
9790 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL,
false,
false);
9793 PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9797 PUSH_INSN(ret, location, intern);
9800 PUSH_INSN(ret, location, pop);
9805 case PM_INTERPOLATED_X_STRING_NODE: {
9810 PUSH_INSN(ret, location, putself);
9812 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret,
false, scope_node, NULL, NULL,
false,
false);
9813 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9815 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
9816 if (popped) PUSH_INSN(ret, location, pop);
9820 case PM_IT_LOCAL_VARIABLE_READ_NODE: {
9827 while (current_scope_node) {
9828 if (current_scope_node->parameters && PM_NODE_TYPE_P(current_scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
9829 PUSH_GETLOCAL(ret, location, current_scope_node->local_table_for_iseq_size, level);
9833 current_scope_node = current_scope_node->previous;
9836 rb_bug(
"Local `it` does not exist");
9841 case PM_KEYWORD_HASH_NODE: {
9847 bool has_splat =
false;
9848 for (
size_t index = 0; index < elements->
size; index++) {
9849 if (PM_NODE_TYPE_P(elements->
nodes[index], PM_ASSOC_SPLAT_NODE)) {
9856 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9861 PM_COMPILE(element);
9864 if (!popped) PUSH_INSN1(ret, location, newhash,
INT2FIX(elements->
size * 2));
9868 case PM_LAMBDA_NODE: {
9874 pm_scope_node_init(node, &next_scope_node, scope_node);
9876 int opening_lineno = pm_location_line_number_cached(&cast->
opening_loc, scope_node);
9877 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, opening_lineno);
9878 pm_scope_node_destroy(&next_scope_node);
9881 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9882 PUSH_CALL_WITH_BLOCK(ret, location, idLambda, argc, block);
9885 if (popped) PUSH_INSN(ret, location, pop);
9888 case PM_LOCAL_VARIABLE_AND_WRITE_NODE: {
9892 LABEL *end_label = NEW_LABEL(location.
line);
9895 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9896 if (!popped) PUSH_INSN(ret, location, dup);
9898 PUSH_INSNL(ret, location, branchunless, end_label);
9899 if (!popped) PUSH_INSN(ret, location, pop);
9901 PM_COMPILE_NOT_POPPED(cast->
value);
9902 if (!popped) PUSH_INSN(ret, location, dup);
9904 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9905 PUSH_LABEL(ret, end_label);
9909 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
9915 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9917 PM_COMPILE_NOT_POPPED(cast->
value);
9920 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
9922 if (!popped) PUSH_INSN(ret, location, dup);
9923 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9927 case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
9932 LABEL *set_label = NEW_LABEL(location.
line);
9933 LABEL *end_label = NEW_LABEL(location.
line);
9935 PUSH_INSN1(ret, location, putobject,
Qtrue);
9936 PUSH_INSNL(ret, location, branchunless, set_label);
9939 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9940 if (!popped) PUSH_INSN(ret, location, dup);
9942 PUSH_INSNL(ret, location, branchif, end_label);
9943 if (!popped) PUSH_INSN(ret, location, pop);
9945 PUSH_LABEL(ret, set_label);
9946 PM_COMPILE_NOT_POPPED(cast->
value);
9947 if (!popped) PUSH_INSN(ret, location, dup);
9949 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9950 PUSH_LABEL(ret, end_label);
9954 case PM_LOCAL_VARIABLE_READ_NODE: {
9960 PUSH_GETLOCAL(ret, location, index.index, index.level);
9965 case PM_LOCAL_VARIABLE_WRITE_NODE: {
9969 PM_COMPILE_NOT_POPPED(cast->
value);
9970 if (!popped) PUSH_INSN(ret, location, dup);
9973 PUSH_SETLOCAL(ret, location, index.index, index.level);
9976 case PM_MATCH_LAST_LINE_NODE: {
9979 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9981 PUSH_INSN1(ret, location, putobject, regexp);
9983 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9984 if (popped) PUSH_INSN(ret, location, pop);
9988 case PM_MATCH_PREDICATE_NODE: {
9995 PUSH_INSN(ret, location, putnil);
9998 PM_COMPILE_NOT_POPPED(cast->
value);
9999 PUSH_INSN(ret, location, dup);
10003 LABEL *matched_label = NEW_LABEL(location.
line);
10004 LABEL *unmatched_label = NEW_LABEL(location.
line);
10005 LABEL *done_label = NEW_LABEL(location.
line);
10006 pm_compile_pattern(iseq, scope_node, cast->
pattern, ret, matched_label, unmatched_label,
false,
true, 2);
10010 PUSH_LABEL(ret, unmatched_label);
10011 PUSH_INSN(ret, location, pop);
10012 PUSH_INSN(ret, location, pop);
10014 if (!popped) PUSH_INSN1(ret, location, putobject,
Qfalse);
10015 PUSH_INSNL(ret, location, jump, done_label);
10016 PUSH_INSN(ret, location, putnil);
10020 PUSH_LABEL(ret, matched_label);
10021 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(2));
10022 if (!popped) PUSH_INSN1(ret, location, putobject,
Qtrue);
10023 PUSH_INSNL(ret, location, jump, done_label);
10025 PUSH_LABEL(ret, done_label);
10028 case PM_MATCH_REQUIRED_NODE:
10040 pm_compile_match_required_node(iseq, (
const pm_match_required_node_t *) node, &location, ret, popped, scope_node);
10042 case PM_MATCH_WRITE_NODE:
10051 pm_compile_match_write_node(iseq, (
const pm_match_write_node_t *) node, &location, ret, popped, scope_node);
10053 case PM_ERROR_RECOVERY_NODE:
10054 rb_bug(
"A pm_error_recovery_node_t should not exist in prism's AST.");
10056 case PM_MODULE_NODE: {
10061 ID module_id = pm_constant_id_lookup(scope_node, cast->
name);
10062 VALUE module_name =
rb_str_freeze(rb_sprintf(
"<module:%"PRIsVALUE
">", rb_id2str(module_id)));
10065 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10067 const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&next_scope_node, module_name, ISEQ_TYPE_CLASS, location.
line);
10068 pm_scope_node_destroy(&next_scope_node);
10070 const int flags = VM_DEFINECLASS_TYPE_MODULE | pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
10071 PUSH_INSN(ret, location, putnil);
10072 PUSH_INSN3(ret, location, defineclass,
ID2SYM(module_id), module_iseq,
INT2FIX(flags));
10075 if (popped) PUSH_INSN(ret, location, pop);
10078 case PM_REQUIRED_PARAMETER_NODE: {
10084 PUSH_SETLOCAL(ret, location, index.index, index.level);
10087 case PM_MULTI_WRITE_NODE: {
10098 DECL_ANCHOR(writes);
10099 DECL_ANCHOR(cleanup);
10102 state.position = popped ? 0 : 1;
10103 pm_compile_multi_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
10105 PM_COMPILE_NOT_POPPED(cast->
value);
10106 if (!popped) PUSH_INSN(ret, location, dup);
10108 PUSH_SEQ(ret, writes);
10109 if (!popped && state.stack_size >= 1) {
10112 PUSH_INSN1(ret, location, setn,
INT2FIX(state.stack_size));
10117 pm_multi_target_state_update(&state);
10119 PUSH_SEQ(ret, cleanup);
10128 pm_compile_next_node(iseq, (
const pm_next_node_t *) node, &location, ret, popped, scope_node);
10130 case PM_NIL_NODE: {
10134 PUSH_INSN(ret, location, putnil);
10139 case PM_NO_BLOCK_PARAMETER_NODE: {
10142 ISEQ_BODY(iseq)->param.flags.accepts_no_block = TRUE;
10145 case PM_NO_KEYWORDS_PARAMETER_NODE: {
10148 ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg = TRUE;
10151 case PM_NUMBERED_REFERENCE_READ_NODE: {
10157 if (cast->
number != 0) {
10158 VALUE ref = pm_compile_numbered_reference_ref(cast);
10159 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), ref);
10162 PUSH_INSN(ret, location, putnil);
10171 pm_compile_or_node(iseq, (
const pm_or_node_t *) node, &location, ret, popped, scope_node);
10173 case PM_OPTIONAL_PARAMETER_NODE: {
10177 PM_COMPILE_NOT_POPPED(cast->
value);
10180 PUSH_SETLOCAL(ret, location, index.index, index.level);
10184 case PM_PARENTHESES_NODE: {
10192 if (cast->
body != NULL) {
10193 PM_COMPILE(cast->
body);
10195 else if (!popped) {
10196 PUSH_INSN(ret, location, putnil);
10201 case PM_PRE_EXECUTION_NODE: {
10213 DECL_ANCHOR(inner_pre);
10216 DECL_ANCHOR(inner_body);
10221 for (
size_t index = 0; index < body->
size; index++) {
10222 pm_compile_node(iseq, body->
nodes[index], inner_body,
true, scope_node);
10227 PUSH_INSN(inner_body, location, putnil);
10233 PUSH_SEQ(outer_pre, inner_pre);
10234 PUSH_SEQ(outer_pre, inner_body);
10239 case PM_POST_EXECUTION_NODE: {
10243 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
10246 pm_scope_node_init(node, &next_scope_node, scope_node);
10247 child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
10248 pm_scope_node_destroy(&next_scope_node);
10250 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
10252 int is_index = ISEQ_BODY(iseq)->ise_size++;
10253 PUSH_INSN2(ret, location, once, child_iseq,
INT2FIX(is_index));
10255 if (popped) PUSH_INSN(ret, location, pop);
10257 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
10261 case PM_RANGE_NODE: {
10265 bool exclude_end = PM_NODE_FLAG_P(cast, PM_RANGE_FLAGS_EXCLUDE_END);
10267 if (pm_optimizable_range_item_p(cast->
left) && pm_optimizable_range_item_p(cast->
right)) {
10273 (left && PM_NODE_TYPE_P(left, PM_INTEGER_NODE)) ? parse_integer((
const pm_integer_node_t *) left) :
Qnil,
10274 (right && PM_NODE_TYPE_P(right, PM_INTEGER_NODE)) ? parse_integer((const
pm_integer_node_t *) right) :
Qnil,
10279 PUSH_INSN1(ret, location, putobject, val);
10283 if (cast->
left != NULL) {
10284 PM_COMPILE(cast->
left);
10286 else if (!popped) {
10287 PUSH_INSN(ret, location, putnil);
10290 if (cast->
right != NULL) {
10291 PM_COMPILE(cast->
right);
10293 else if (!popped) {
10294 PUSH_INSN(ret, location, putnil);
10298 PUSH_INSN1(ret, location, newrange,
INT2FIX(exclude_end ? 1 : 0));
10303 case PM_RATIONAL_NODE: {
10307 PUSH_INSN1(ret, location, putobject, parse_rational((
const pm_rational_node_t *) node));
10314 pm_compile_redo_node(iseq, &location, ret, popped, scope_node);
10316 case PM_REGULAR_EXPRESSION_NODE: {
10320 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
10321 PUSH_INSN1(ret, location, putobject, regexp);
10325 case PM_RESCUE_NODE:
10328 pm_compile_rescue_node(iseq, (
const pm_rescue_node_t *) node, &location, ret, popped, scope_node);
10330 case PM_RESCUE_MODIFIER_NODE: {
10336 pm_scope_node_init((
const pm_node_t *) cast, &rescue_scope_node, scope_node);
10338 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
10339 &rescue_scope_node,
10345 pm_scope_node_destroy(&rescue_scope_node);
10347 LABEL *lstart = NEW_LABEL(location.
line);
10348 LABEL *lend = NEW_LABEL(location.
line);
10349 LABEL *lcont = NEW_LABEL(location.
line);
10351 lstart->rescued = LABEL_RESCUE_BEG;
10352 lend->rescued = LABEL_RESCUE_END;
10354 PUSH_LABEL(ret, lstart);
10356 PUSH_LABEL(ret, lend);
10358 PUSH_INSN(ret, location, nop);
10359 PUSH_LABEL(ret, lcont);
10360 if (popped) PUSH_INSN(ret, location, pop);
10362 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
10363 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
10366 case PM_RETURN_NODE:
10372 pm_compile_return_node(iseq, (
const pm_return_node_t *) node, &location, ret, popped, scope_node);
10374 case PM_RETRY_NODE: {
10377 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_RESCUE) {
10378 PUSH_INSN(ret, location, putnil);
10379 PUSH_INSN1(ret, location,
throw,
INT2FIX(TAG_RETRY));
10380 if (popped) PUSH_INSN(ret, location, pop);
10383 COMPILE_ERROR(iseq, location.
line,
"Invalid retry");
10388 case PM_SCOPE_NODE:
10389 pm_compile_scope_node(iseq, (
pm_scope_node_t *) node, &location, ret, popped);
10391 case PM_SELF_NODE: {
10395 PUSH_INSN(ret, location, putself);
10399 case PM_SHAREABLE_CONSTANT_NODE: {
10403 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));
10405 switch (PM_NODE_TYPE(cast->
write)) {
10406 case PM_CONSTANT_WRITE_NODE:
10409 case PM_CONSTANT_AND_WRITE_NODE:
10412 case PM_CONSTANT_OR_WRITE_NODE:
10415 case PM_CONSTANT_OPERATOR_WRITE_NODE:
10418 case PM_CONSTANT_PATH_WRITE_NODE:
10421 case PM_CONSTANT_PATH_AND_WRITE_NODE:
10424 case PM_CONSTANT_PATH_OR_WRITE_NODE:
10427 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
10431 rb_bug(
"Unexpected node type for shareable constant write: %s", pm_node_type(PM_NODE_TYPE(cast->
write)));
10437 case PM_SINGLETON_CLASS_NODE: {
10443 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10444 const rb_iseq_t *child_iseq = NEW_ISEQ(&next_scope_node, rb_fstring_lit(
"singleton class"), ISEQ_TYPE_CLASS, location.
line);
10445 pm_scope_node_destroy(&next_scope_node);
10448 PUSH_INSN(ret, location, putnil);
10451 CONST_ID(singletonclass,
"singletonclass");
10455 int sclass_flags = VM_DEFINECLASS_TYPE_SINGLETON_CLASS;
10456 if (!(PM_NODE_TYPE_P(cast->
expression, PM_SELF_NODE) &&
10457 ISEQ_BODY(iseq)->
type == ISEQ_TYPE_CLASS) &&
10459 sclass_flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
10462 PUSH_INSN3(ret, location, defineclass,
ID2SYM(singletonclass), child_iseq,
INT2FIX(sclass_flags));
10464 if (popped) PUSH_INSN(ret, location, pop);
10469 case PM_SOURCE_ENCODING_NODE: {
10473 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10474 PUSH_INSN1(ret, location, putobject, value);
10478 case PM_SOURCE_FILE_NODE: {
10485 if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_FROZEN)) {
10486 string_type = ISEQ_FROZEN_STRING_LITERAL_ENABLED;
10488 else if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_MUTABLE)) {
10489 string_type = ISEQ_FROZEN_STRING_LITERAL_DISABLED;
10492 string_type = ISEQ_FROZEN_STRING_LITERAL_UNSET;
10495 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10496 PUSH_INSN1(ret, location, putobject,
INT2FIX(string_type));
10497 PUSH_SEND(ret, location, id_core_iseq_path,
INT2FIX(1));
10501 case PM_SOURCE_LINE_NODE: {
10505 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10506 PUSH_INSN1(ret, location, putobject, value);
10510 case PM_SPLAT_NODE: {
10519 PUSH_INSN1(ret, location, splatarray,
Qtrue);
10523 case PM_STATEMENTS_NODE: {
10528 if (body->
size > 0) {
10529 for (
size_t index = 0; index < body->
size - 1; index++) {
10530 PM_COMPILE_POPPED(body->
nodes[index]);
10532 PM_COMPILE(body->
nodes[body->
size - 1]);
10535 PUSH_INSN(ret, location, putnil);
10539 case PM_STRING_NODE: {
10544 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10546 if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_FROZEN)) {
10547 PUSH_INSN1(ret, location, putobject, value);
10549 else if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_MUTABLE)) {
10550 PUSH_INSN1(ret, location, dupstring, value);
10553 PUSH_INSN1(ret, location, dupchilledstring, value);
10558 case PM_SUPER_NODE:
10562 pm_compile_super_node(iseq, (
const pm_super_node_t *) node, &location, ret, popped, scope_node);
10564 case PM_SYMBOL_NODE: {
10568 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10569 PUSH_INSN1(ret, location, putobject, value);
10573 case PM_TRUE_NODE: {
10577 PUSH_INSN1(ret, location, putobject,
Qtrue);
10581 case PM_UNDEF_NODE: {
10587 for (
size_t index = 0; index < names->
size; index++) {
10588 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10589 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
10591 PM_COMPILE_NOT_POPPED(names->
nodes[index]);
10592 PUSH_SEND(ret, location, id_core_undef_method,
INT2NUM(2));
10594 if (index < names->size - 1) {
10595 PUSH_INSN(ret, location, pop);
10599 if (popped) PUSH_INSN(ret, location, pop);
10602 case PM_UNLESS_NODE: {
10614 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);
10617 case PM_UNTIL_NODE: {
10624 pm_compile_loop(iseq, &location, cast->
base.
flags, PM_UNTIL_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10627 case PM_WHILE_NODE: {
10634 pm_compile_loop(iseq, &location, cast->
base.
flags, PM_WHILE_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10637 case PM_X_STRING_NODE: {
10641 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10643 PUSH_INSN(ret, location, putself);
10644 PUSH_INSN1(ret, location, putobject, value);
10645 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
10646 if (popped) PUSH_INSN(ret, location, pop);
10650 case PM_YIELD_NODE:
10656 pm_compile_yield_node(iseq, (
const pm_yield_node_t *) node, &location, ret, popped, scope_node);
10659 rb_raise(
rb_eNotImpError,
"node type %s not implemented", pm_node_type(PM_NODE_TYPE(node)));
10664#undef PM_CONTAINER_P
10668pm_iseq_pre_execution_p(
rb_iseq_t *iseq)
10670 switch (ISEQ_BODY(iseq)->
type) {
10671 case ISEQ_TYPE_TOP:
10672 case ISEQ_TYPE_EVAL:
10673 case ISEQ_TYPE_MAIN:
10692 if (pm_iseq_pre_execution_p(iseq)) {
10704 pm_compile_node(iseq, (
const pm_node_t *) node, body,
false, node);
10708 PUSH_SEQ(ret, pre);
10709 PUSH_SEQ(ret, body);
10714 pm_compile_node(iseq, (
const pm_node_t *) node, ret,
false, node);
10717 CHECK(iseq_setup_insn(iseq, ret));
10718 return iseq_setup(iseq, ret);
10725 result->
arena = pm_arena_new();
10726 result->
options = pm_options_new();
10727 pm_options_line_set(result->
options, 1);
10738 SIZED_FREE_N(result->
node.constants, pm_parser_constants_size(result->
node.parser));
10739 pm_scope_node_destroy(&result->
node);
10743 pm_arena_free(result->
arena);
10745 pm_options_free(result->
options);
10757 if (buffer == NULL) {
10762 if (rb_stderr_tty_p()) {
10763 const char *no_color = getenv(
"NO_COLOR");
10764 if (no_color == NULL || no_color[0] ==
'\0') {
10773 pm_error_level_t error_level = pm_errors_format(parser, buffer, format_type);
10776 VALUE message = rb_enc_str_new(pm_buffer_value(buffer), (
long) pm_buffer_length(buffer), message_encoding);
10777 pm_buffer_free(buffer);
10780 switch (error_level) {
10787 VALUE path = rb_enc_str_new((
const char *) pm_string_source(filepath), pm_string_length(filepath), filepath_encoding);
10811pm_intern_constants_callback(
const pm_constant_t *constant,
void *data)
10814 ctx->constants[ctx->index++] = rb_intern3((
const char *) pm_constant_start(constant), pm_constant_length(constant), ctx->encoding);
10821 const char *filepath;
10825pm_warning_emit_callback(
const pm_diagnostic_t *diagnostic,
void *data) {
10828 int line = pm_location_line_number(ctx->parser, &loc);
10831 rb_enc_compile_warning(ctx->encoding, ctx->filepath, line,
"%s", pm_diagnostic_message(diagnostic));
10834 rb_enc_compile_warn(ctx->encoding, ctx->filepath, line,
"%s", pm_diagnostic_message(diagnostic));
10852 const uint8_t *start = pm_parser_start(parser);
10853 const uint8_t *end = pm_parser_end(parser);
10854 const pm_location_t *data_loc = pm_parser_data_loc(parser);
10856 if (data_loc->
length != 0) {
10857 const uint8_t *cursor = start + data_loc->
start;
10858 while (cursor < end && *cursor !=
'\n') cursor++;
10859 if (cursor < end) cursor++;
10864 rb_source_hash_init(&state);
10865 rb_source_hash_update(&state, start, (
size_t) (end - start));
10866 return rb_source_hash_finalize(&state);
10878 int coverage_enabled = scope_node->coverage_enabled;
10880 pm_scope_node_init(node, scope_node, NULL);
10883 const char *encoding_name = pm_parser_encoding_name(parser);
10884 scope_node->encoding = rb_enc_find(encoding_name);
10885 if (!scope_node->encoding) rb_bug(
"Encoding not found %s!", encoding_name);
10887 scope_node->coverage_enabled = coverage_enabled;
10891 if (script_lines != NULL) {
10895 for (
size_t index = 0; index < line_offsets->
size; index++) {
10896 size_t offset = line_offsets->
offsets[index];
10897 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);
10898 rb_ary_push(*script_lines, rb_enc_str_new((
const char *) pm_parser_start(parser) + offset, length, scope_node->encoding));
10907 .encoding = scope_node->encoding,
10908 .filepath = (
const char *) pm_string_source(pm_parser_filepath(parser))
10910 pm_parser_warnings_each(parser, pm_warning_emit_callback, &warning_ctx);
10913 if (pm_parser_errors_size(parser) > 0) {
10914 VALUE error = pm_parse_process_error(result);
10923 scope_node->parser = parser;
10924 scope_node->
source_hash = pm_source_hash(parser);
10925 scope_node->options = result->
options;
10926 scope_node->line_offsets = pm_parser_line_offsets(parser);
10927 scope_node->start_line = pm_parser_start_line(parser);
10928 size_t constants_size = pm_parser_constants_size(parser);
10929 scope_node->constants = constants_size ?
xmalloc(constants_size *
sizeof(
ID)) : NULL;
10931 pm_intern_constants_ctx_t intern_ctx = { .constants = scope_node->constants, .encoding = scope_node->encoding, .index = 0 };
10932 pm_parser_constants_each(parser, pm_intern_constants_callback, &intern_ctx);
10945pm_options_frozen_string_literal_init(
pm_options_t *options)
10947 int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
10949 switch (frozen_string_literal) {
10950 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
10952 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
10953 pm_options_frozen_string_literal_set(options,
false);
10955 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
10956 pm_options_frozen_string_literal_set(options,
true);
10959 rb_bug(
"pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
10972 const char *start = (
const char *) pm_parser_start(parser);
10973 const char *end = (
const char *) pm_parser_end(parser);
10978 size_t last_offset = line_offsets->
offsets[line_offsets->
size - 1];
10979 bool last_push = start + last_offset != end;
10984 for (
size_t index = 0; index < line_offsets->
size - 1; index++) {
10985 size_t offset = line_offsets->
offsets[index];
10986 size_t length = line_offsets->
offsets[index + 1] - offset;
10988 rb_ary_push(lines, rb_enc_str_new(start + offset, length, scope_node->encoding));
10993 rb_ary_push(lines, rb_enc_str_new(start + last_offset, end - (start + last_offset), scope_node->encoding));
11007close_file(
VALUE args)
11010 if (arg->fd != -1) {
11013 else if (!
NIL_P(arg->io)) {
11020load_content(
VALUE args)
11027 return rb_funcall(io, rb_intern(
"read"), 0);
11038 result->
source = pm_source_mapped_new(RSTRING_PTR(filepath), O_RDONLY | O_NONBLOCK, &init_result);
11041 pm_options_frozen_string_literal_init(result->
options);
11052 .open_mode = O_RDONLY | O_NONBLOCK,
11056 if (args.fd == -1)
goto error_generic;
11061 long len = RSTRING_LEN(contents);
11062 if (
len < 0)
goto error_generic;
11064 size_t length = (size_t)
len;
11065 uint8_t *source_data =
xmalloc(length);
11066 memcpy(source_data, RSTRING_PTR(contents), length);
11067 result->
source = pm_source_owned_new(source_data, length);
11069 pm_options_frozen_string_literal_init(result->
options);
11078 err = rb_w32_map_errno(GetLastError());
11109 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11112 pm_options_version_for_current_ruby_set(result->
options);
11117 VALUE error = pm_parse_process(result, node, script_lines);
11122 ID id_script_lines = rb_intern(
"SCRIPT_LINES__");
11128 rb_hash_aset(constant_script_lines, filepath, pm_parse_file_script_lines(&result->
node, result->
parser));
11142 VALUE error = pm_load_file(result, filepath,
false);
11143 if (
NIL_P(error)) {
11144 error = pm_parse_file(result, filepath, script_lines);
11160 if (!rb_enc_asciicompat(encoding)) {
11164 pm_options_frozen_string_literal_init(result->
options);
11165 result->
source = pm_source_constant_new((
const uint8_t *) RSTRING_PTR(source), (
size_t) RSTRING_LEN(source));
11166 pm_options_encoding_set(result->
options, rb_enc_name(encoding));
11169 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11171 pm_options_version_for_current_ruby_set(result->
options);
11176 VALUE error = pm_parse_process(result, node, script_lines);
11189pm_node_find(
const pm_node_t *node,
void *data)
11193 if (context->node == NULL && node->
node_id == context->node_id) {
11194 context->node = node;
11198 return context->node == NULL;
11202pm_node_source_location(
VALUE source,
VALUE filepath,
int start_line,
11206 pm_parse_result_init(&result);
11208 pm_options_line_set(result.
options, start_line);
11209 VALUE error = pm_parse_string(&result, source, filepath, NULL);
11211 if (!
NIL_P(error)) {
11212 pm_parse_result_free(&result);
11217 .node_id = (uint32_t) node_id,
11220 pm_visit_node(result.
node.ast_node, pm_node_find, &context);
11222 bool found = context.node != NULL;
11224 *location = pm_code_location(&result.
node, context.node);
11230 pm_parse_result_free(&result);
11234VALUE rb_io_gets_limit_internal(
VALUE io,
long limit);
11244pm_parse_stdin_eof(
void *stream)
11257#define MAX_ENC_LEN 6
11265pm_parse_stdin_fgets(
char *
string,
int size,
void *stream)
11275 VALUE line = rb_io_gets_limit_internal((
VALUE) stream, size - MAX_ENC_LEN);
11280 const char *cstr = RSTRING_PTR(line);
11281 long length = RSTRING_LEN(line);
11289 if (length > (
long) (size - 1)) {
11290 length = (long) (size - 1);
11293 memcpy(
string, cstr, (
size_t) length);
11294 string[length] =
'\0';
11302void rb_reset_argf_lineno(
long n);
11312 pm_options_frozen_string_literal_init(result->
options);
11314 result->
source = pm_source_stream_new((
void *)
rb_stdin, pm_parse_stdin_fgets, pm_parse_stdin_eof);
11319 rb_reset_argf_lineno(0);
11321 return pm_parse_process(result, node, NULL);
11324#define PM_VERSION_FOR_RELEASE(major, minor) PM_VERSION_FOR_RELEASE_IMPL(major, minor)
11325#define PM_VERSION_FOR_RELEASE_IMPL(major, minor) #major "." #minor
11327void pm_options_version_for_current_ruby_set(
pm_options_t *options) {
11329 pm_options_version_set(options, version, strlen(version));
11333#define NEW_ISEQ OLD_ISEQ
11335#undef NEW_CHILD_ISEQ
11336#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 ALLOCV_N
Old name of RB_ALLOCV_N.
#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 ALLOCV_END
Old name of RB_ALLOCV_END.
#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)
Same as RB_OBJ_FREEZE(), but returns the given object.
#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_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_SET_SHAREABLE(obj)
Wrapper of rb_obj_set_shareable().
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
static VALUE RB_OBJ_SET_FROZEN_SHAREABLE(VALUE obj)
Freezes and marks the object as shareable.
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_NODISCARD PRISM_EXPORTED_FUNCTION 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_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.