2#include "prism_compile.h"
24#define PUSH_ADJUST(seq, location, label) \
25 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), (int) (location).line))
27#define PUSH_ADJUST_RESTORE(seq, label) \
28 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), -1))
30#define PUSH_INSN(seq, location, insn) \
31 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 0))
33#define PUSH_INSN1(seq, location, insn, op1) \
34 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 1, (VALUE)(op1)))
36#define PUSH_INSN2(seq, location, insn, op1, op2) \
37 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 2, (VALUE)(op1), (VALUE)(op2)))
39#define PUSH_INSN3(seq, location, insn, op1, op2, op3) \
40 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)))
42#define PUSH_INSNL(seq, location, insn, label) \
43 (PUSH_INSN1(seq, location, insn, label), LABEL_REF(label))
45#define PUSH_LABEL(seq, label) \
46 ADD_ELEM((seq), (LINK_ELEMENT *) (label))
48#define PUSH_SEND_R(seq, location, id, argc, block, flag, keywords) \
49 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_send(iseq, (int) (location).line, (int) (location).node_id, (id), (VALUE)(argc), (block), (VALUE)(flag), (keywords)))
51#define PUSH_SEND(seq, location, id, argc) \
52 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(0), NULL)
54#define PUSH_SEND_WITH_FLAG(seq, location, id, argc, flag) \
55 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)(flag), NULL)
57#define PUSH_SEND_WITH_BLOCK(seq, location, id, argc, block) \
58 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(0), NULL)
60#define PUSH_CALL(seq, location, id, argc) \
61 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
63#define PUSH_CALL_WITH_BLOCK(seq, location, id, argc, block) \
64 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
66#define PUSH_TRACE(seq, event) \
67 ADD_ELEM((seq), (LINK_ELEMENT *) new_trace_body(iseq, (event), 0))
69#define PUSH_CATCH_ENTRY(type, ls, le, iseqv, lc) \
70 ADD_CATCH_ENTRY((type), (ls), (le), (iseqv), (lc))
72#define PUSH_SEQ(seq1, seq2) \
73 APPEND_LIST((seq1), (seq2))
75#define PUSH_SYNTHETIC_PUTNIL(seq, iseq) \
77 int lineno = ISEQ_COMPILE_DATA(iseq)->last_line; \
78 if (lineno == 0) lineno = FIX2INT(rb_iseq_first_lineno(iseq)); \
79 ADD_SYNTHETIC_INSN(seq, lineno, -1, putnil); \
88pm_iseq_add_getlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
90 if (iseq_local_block_param_p(iseq, idx, level)) {
91 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
94 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
96 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qfalse);
100pm_iseq_add_setlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
102 if (iseq_local_block_param_p(iseq, idx, level)) {
103 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
106 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
108 update_lvar_state(iseq, level, idx);
109 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qtrue);
112#define PUSH_GETLOCAL(seq, location, idx, level) \
113 pm_iseq_add_getlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
115#define PUSH_SETLOCAL(seq, location, idx, level) \
116 pm_iseq_add_setlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
122#define OLD_ISEQ NEW_ISEQ
125#define NEW_ISEQ(node, name, type, line_no) \
126 pm_new_child_iseq(iseq, (node), rb_fstring(name), 0, (type), (line_no))
128#define OLD_CHILD_ISEQ NEW_CHILD_ISEQ
131#define NEW_CHILD_ISEQ(node, name, type, line_no) \
132 pm_new_child_iseq(iseq, (node), rb_fstring(name), iseq, (type), (line_no))
134#define PM_COMPILE(node) \
135 pm_compile_node(iseq, (node), ret, popped, scope_node)
137#define PM_COMPILE_INTO_ANCHOR(_ret, node) \
138 pm_compile_node(iseq, (node), _ret, popped, scope_node)
140#define PM_COMPILE_POPPED(node) \
141 pm_compile_node(iseq, (node), ret, true, scope_node)
143#define PM_COMPILE_NOT_POPPED(node) \
144 pm_compile_node(iseq, (node), ret, false, scope_node)
147#define PM_INDEX_LOOKUP_TABLE_INIT { .values = NULL, .capacity = 0, .owned = false }
152 int capacity = constants_size + PM_INDEX_LOOKUP_SPECIALS;
153 table->
values = compile_data_alloc2_type(iseq,
int, capacity);
154 memset(table->
values, -1, capacity *
sizeof(
int));
156 table->
owned =
false;
166pm_line_offset_list_line_column_cached(
const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line,
size_t *last_line)
168 size_t hint = *last_line;
169 size_t size = list->
size;
170 const uint32_t *offsets = list->
offsets;
175 if (offsets[hint] <= cursor) {
176 if (hint + 1 >= size || offsets[hint + 1] > cursor) {
179 .line = ((int32_t) hint) + start_line,
180 .column = cursor - offsets[hint]
185 size_t limit = hint + 9;
186 if (limit > size) limit = size;
187 for (
size_t idx = hint + 1; idx < limit; idx++) {
188 if (offsets[idx] > cursor) {
189 *last_line = idx - 1;
191 .line = ((int32_t) (idx - 1)) + start_line,
192 .column = cursor - offsets[idx - 1]
195 if (offsets[idx] == cursor) {
203 size_t limit = hint > 8 ? hint - 8 : 0;
204 for (
size_t idx = hint; idx > limit; idx--) {
205 if (offsets[idx - 1] <= cursor) {
206 *last_line = idx - 1;
208 .line = ((int32_t) (idx - 1)) + start_line,
209 .column = cursor - offsets[idx - 1]
216 pm_line_column_t result = pm_line_offset_list_line_column(list, cursor, start_line);
217 *last_line = (size_t) (result.
line - start_line);
226pm_line_offset_list_line_cached(
const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line,
size_t *last_line)
228 return pm_line_offset_list_line_column_cached(list, cursor, start_line, last_line).
line;
231#define PM_NODE_START_LOCATION(node) \
232 ((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 })
234#define PM_NODE_END_LOCATION(node) \
235 ((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 })
237#define PM_LOCATION_START_LOCATION(location, id) \
238 ((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 })
240#define PM_NODE_START_LINE_COLUMN(node) \
241 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)
243#define PM_NODE_END_LINE_COLUMN(node) \
244 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)
246#define PM_LOCATION_START_LINE_COLUMN(location) \
247 pm_line_offset_list_line_column_cached(scope_node->line_offsets, (location)->start, scope_node->start_line, &scope_node->last_line)
251 return (
int) pm_line_offset_list_line_column(pm_parser_line_offsets(parser), location->
start, pm_parser_start_line(parser)).
line;
261 return (
int) pm_line_offset_list_line_cached(scope_node->line_offsets, node->
location.
start, scope_node->start_line, &scope_node->
last_line);
266 return (
int) pm_line_offset_list_line_cached(scope_node->line_offsets, location->
start, scope_node->start_line, &scope_node->
last_line);
277 if (integer->
values == NULL) {
285 result = rb_integer_unpack(
295 result = rb_int_uminus(result);
311 return parse_integer_value(&node->
value);
351 VALUE imaginary_part;
352 switch (PM_NODE_TYPE(node->
numeric)) {
353 case PM_FLOAT_NODE: {
357 case PM_INTEGER_NODE: {
361 case PM_RATIONAL_NODE: {
366 rb_bug(
"Unexpected numeric type on imaginary number %s\n", pm_node_type(PM_NODE_TYPE(node->
numeric)));
375 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), scope_node->encoding);
388 if (node->
flags & PM_ENCODING_FLAGS_FORCED_BINARY_ENCODING) {
389 encoding = rb_ascii8bit_encoding();
391 else if (node->
flags & PM_ENCODING_FLAGS_FORCED_UTF8_ENCODING) {
392 encoding = rb_utf8_encoding();
398 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
406 if (node->
flags & PM_STRING_FLAGS_FORCED_BINARY_ENCODING) {
407 encoding = rb_ascii8bit_encoding();
409 else if (node->
flags & PM_STRING_FLAGS_FORCED_UTF8_ENCODING) {
410 encoding = rb_utf8_encoding();
413 encoding = scope_node->encoding;
416 VALUE value = rb_enc_literal_str((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
417 rb_enc_str_coderange(value);
419 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
420 int line_number = pm_node_line_number_cached(node, scope_node);
431 if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_UTF8_ENCODING) {
432 encoding = rb_utf8_encoding();
434 else if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_BINARY_ENCODING) {
435 encoding = rb_ascii8bit_encoding();
437 else if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_US_ASCII_ENCODING) {
438 encoding = rb_usascii_encoding();
441 encoding = scope_node->encoding;
444 return rb_intern3((
const char *) pm_string_source(&symbol->
unescaped), pm_string_length(&symbol->
unescaped), encoding);
448pm_optimizable_range_item_p(
const pm_node_t *node)
450 return (!node || PM_NODE_TYPE_P(node, PM_INTEGER_NODE) || PM_NODE_TYPE_P(node, PM_NIL_NODE));
455parse_regexp_error(
rb_iseq_t *iseq, int32_t line_number,
const char *fmt, ...)
459 VALUE error = rb_syntax_error_append(
Qnil, rb_iseq_path(iseq), line_number, -1, NULL,
"%" PRIsVALUE, args);
471 if (explicit_regexp_encoding != NULL) {
472 encoding = explicit_regexp_encoding;
474 else if (node->
flags & PM_STRING_FLAGS_FORCED_BINARY_ENCODING) {
475 encoding = rb_ascii8bit_encoding();
477 else if (node->
flags & PM_STRING_FLAGS_FORCED_UTF8_ENCODING) {
478 encoding = rb_utf8_encoding();
481 encoding = implicit_regexp_encoding;
484 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), encoding);
485 VALUE error = rb_reg_check_preprocess(
string);
487 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number_cached(node, scope_node),
"%" PRIsVALUE,
rb_obj_as_string(error));
496 for (
size_t index = 0; index < nodes->
size; index++) {
500 switch (PM_NODE_TYPE(part)) {
502 if (implicit_regexp_encoding != NULL) {
504 string = parse_regexp_string_part(iseq, scope_node, part, &((
const pm_string_node_t *) part)->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
507 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
508 VALUE error = rb_reg_check_preprocess(
string);
509 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number_cached(part, scope_node),
"%" PRIsVALUE,
rb_obj_as_string(error));
513 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
516 case PM_INTERPOLATED_STRING_NODE:
517 string = pm_static_literal_concat(iseq, &((
const pm_interpolated_string_node_t *) part)->parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
519 case PM_EMBEDDED_STATEMENTS_NODE: {
521 string = pm_static_literal_concat(iseq, &
cast->statements->body, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
525 RUBY_ASSERT(
false &&
"unexpected node type in pm_static_literal_concat");
529 if (current !=
Qnil) {
537 return top ? rb_fstring(current) : current;
540#define RE_OPTION_ENCODING_SHIFT 8
541#define RE_OPTION_ENCODING(encoding) (((encoding) & 0xFF) << RE_OPTION_ENCODING_SHIFT)
542#define ARG_ENCODING_NONE 32
543#define ARG_ENCODING_FIXED 16
544#define ENC_ASCII8BIT 1
546#define ENC_Windows_31J 3
561 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) {
562 flags |= ARG_ENCODING_NONE;
565 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EUC_JP)) {
566 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_EUC_JP));
569 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J)) {
570 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_Windows_31J));
573 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_UTF_8)) {
574 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_UTF8));
577 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE)) {
578 flags |= ONIG_OPTION_IGNORECASE;
581 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE)) {
582 flags |= ONIG_OPTION_MULTILINE;
585 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EXTENDED)) {
586 flags |= ONIG_OPTION_EXTEND;
592#undef RE_OPTION_ENCODING_SHIFT
593#undef RE_OPTION_ENCODING
594#undef ARG_ENCODING_FIXED
595#undef ARG_ENCODING_NONE
598#undef ENC_Windows_31J
604 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_FORCED_BINARY_ENCODING) || PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) {
605 return rb_ascii8bit_encoding();
607 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_UTF_8)) {
608 return rb_utf8_encoding();
610 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EUC_JP)) {
611 return rb_enc_get_from_index(ENCINDEX_EUC_JP);
613 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J)) {
614 return rb_enc_get_from_index(ENCINDEX_Windows_31J);
624 VALUE errinfo = rb_errinfo();
626 int32_t line_number = pm_node_line_number_cached(node, scope_node);
627 VALUE regexp = rb_reg_compile(
string, parse_regexp_flags(node), (
const char *) pm_string_source(pm_parser_filepath(scope_node->parser)), line_number);
630 VALUE message = rb_attr_get(rb_errinfo(), idMesg);
631 rb_set_errinfo(errinfo);
633 parse_regexp_error(iseq, line_number,
"%" PRIsVALUE, message);
643 rb_encoding *regexp_encoding = parse_regexp_encoding(scope_node, node);
644 if (regexp_encoding == NULL) regexp_encoding = scope_node->encoding;
646 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), regexp_encoding);
648 return parse_regexp(iseq, scope_node, node,
string);
654 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
655 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
657 VALUE string = pm_static_literal_concat(iseq, parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
658 return parse_regexp(iseq, scope_node, node,
string);
667 size_t parts_size = parts->
size;
668 bool interpolated =
false;
670 if (parts_size > 0) {
674 for (
size_t index = 0; index < parts_size; index++) {
677 if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
681 if (implicit_regexp_encoding == NULL) {
682 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
685 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
688 if (
RTEST(current_string)) {
689 current_string =
rb_str_concat(current_string, string_value);
692 current_string = string_value;
693 if (index != 0) current_location = PM_NODE_END_LOCATION(part);
700 PM_NODE_TYPE_P(part, PM_EMBEDDED_STATEMENTS_NODE) &&
708 if (implicit_regexp_encoding == NULL) {
709 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
712 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
715 if (
RTEST(current_string)) {
716 current_string =
rb_str_concat(current_string, string_value);
719 current_string = string_value;
720 current_location = PM_NODE_START_LOCATION(part);
724 if (!
RTEST(current_string)) {
727 if (implicit_regexp_encoding != NULL) {
728 if (explicit_regexp_encoding != NULL) {
729 encoding = explicit_regexp_encoding;
731 else if (pm_parser_encoding_us_ascii(scope_node->parser)) {
732 encoding = rb_ascii8bit_encoding();
735 encoding = implicit_regexp_encoding;
739 encoding = scope_node->encoding;
742 if (parts_size == 1) {
743 current_string = rb_enc_str_new(NULL, 0, encoding);
747 if (
RTEST(current_string)) {
748 VALUE operand = rb_fstring(current_string);
749 PUSH_INSN1(ret, current_location, putobject, operand);
753 PM_COMPILE_NOT_POPPED(part);
756 PUSH_INSN(ret, current_location, dup);
759 const struct rb_callinfo *callinfo = new_callinfo(iseq, idTo_s, 0, VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE, NULL, FALSE);
760 PUSH_INSN1(ret, current_location, objtostring, callinfo);
763 PUSH_INSN(ret, current_location, anytostring);
765 current_string =
Qnil;
771 if (
RTEST(current_string)) {
772 current_string = rb_fstring(current_string);
774 if (stack_size == 0) {
776 PUSH_INSN1(ret, current_location, putobject, current_string);
777 }
else if (mutable_result || interpolated) {
778 PUSH_INSN1(ret, current_location, dupstring, current_string);
780 PUSH_INSN1(ret, current_location, dupchilledstring, current_string);
783 PUSH_INSN1(ret, current_location, putobject, current_string);
786 current_string =
Qnil;
791 PUSH_INSN(ret, *node_location, putnil);
800 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
801 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
803 int length = pm_interpolated_node_compile(iseq, parts, node_location, ret, popped, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false,
false);
804 PUSH_INSN2(ret, *node_location, toregexp,
INT2FIX(parse_regexp_flags(node) & 0xFF),
INT2FIX(length));
812pm_static_literal_string(
rb_iseq_t *iseq,
VALUE string,
int line_number)
814 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
815 VALUE str = rb_str_with_debug_created_info(
string, rb_iseq_path(iseq), line_number);
820 return rb_fstring(
string);
834 RUBY_ASSERT(PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL));
836 switch (PM_NODE_TYPE(node)) {
837 case PM_ARRAY_NODE: {
842 for (
size_t index = 0; index < elements->
size; index++) {
843 rb_ary_push(value, pm_static_literal_value(iseq, elements->
nodes[index], scope_node));
858 for (
size_t index = 0; index < elements->
size; index++) {
861 VALUE pair[2] = { pm_static_literal_value(iseq,
cast->key, scope_node), pm_static_literal_value(iseq,
cast->value, scope_node) };
872 case PM_IMAGINARY_NODE:
874 case PM_INTEGER_NODE:
876 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
878 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &
cast->parts);
880 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
882 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &
cast->parts);
884 case PM_INTERPOLATED_STRING_NODE: {
886 int line_number = pm_node_line_number_cached(node, scope_node);
887 return pm_static_literal_string(iseq,
string, line_number);
889 case PM_INTERPOLATED_SYMBOL_NODE: {
891 VALUE string = pm_static_literal_concat(iseq, &
cast->parts, scope_node, NULL, NULL,
true);
893 return ID2SYM(rb_intern_str(
string));
895 case PM_MATCH_LAST_LINE_NODE: {
897 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &
cast->unescaped);
901 case PM_RATIONAL_NODE:
903 case PM_REGULAR_EXPRESSION_NODE: {
905 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &
cast->unescaped);
907 case PM_SOURCE_ENCODING_NODE:
908 return rb_enc_from_encoding(scope_node->encoding);
909 case PM_SOURCE_LINE_NODE:
910 return INT2FIX(pm_node_line_number_cached(node, scope_node));
911 case PM_STRING_NODE: {
913 return parse_static_literal_string(iseq, scope_node, node, &
cast->unescaped);
920 rb_bug(
"Don't have a literal value for node type %s", pm_node_type(PM_NODE_TYPE(node)));
935 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
936 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
945#define PM_BRANCH_COVERAGE_P(iseq) (ISEQ_COVERAGE(iseq) && ISEQ_BRANCH_COVERAGE(iseq))
959 if (!then_label) then_label = label;
960 else if (!else_label) else_label = label;
962 pm_compile_branch_condition(iseq, seq, cond, then_label, else_label, scope_node);
964 if (LIST_INSN_SIZE_ONE(seq)) {
965 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(seq));
966 if (insn->insn_id == BIN(jump) && (
LABEL *)(insn->operands[0]) == label)
return;
970 PUSH_LABEL(seq, label);
982 if (PM_NODE_TYPE_P(node, PM_INTEGER_NODE)) {
983 PM_COMPILE_NOT_POPPED(node);
986 PUSH_INSN1(ret, location, getglobal, operand);
988 PUSH_SEND(ret, location, idEq,
INT2FIX(1));
989 if (popped) PUSH_INSN(ret, location, pop);
1002 int again = !(flip_flop_node->
base.
flags & PM_RANGE_FLAGS_EXCLUDE_END);
1004 rb_num_t count = ISEQ_FLIP_CNT_INCREMENT(ISEQ_BODY(iseq)->local_iseq) + VM_SVAR_FLIPFLOP_START;
1007 PUSH_INSN2(ret, location, getspecial, key,
INT2FIX(0));
1008 PUSH_INSNL(ret, location, branchif, lend);
1010 if (flip_flop_node->
left) {
1011 pm_compile_flip_flop_bound(iseq, flip_flop_node->
left, ret, popped, scope_node);
1014 PUSH_INSN(ret, location, putnil);
1017 PUSH_INSNL(ret, location, branchunless, else_label);
1018 PUSH_INSN1(ret, location, putobject,
Qtrue);
1019 PUSH_INSN1(ret, location, setspecial, key);
1021 PUSH_INSNL(ret, location, jump, then_label);
1024 PUSH_LABEL(ret, lend);
1025 if (flip_flop_node->
right) {
1026 pm_compile_flip_flop_bound(iseq, flip_flop_node->
right, ret, popped, scope_node);
1029 PUSH_INSN(ret, location, putnil);
1032 PUSH_INSNL(ret, location, branchunless, then_label);
1033 PUSH_INSN1(ret, location, putobject,
Qfalse);
1034 PUSH_INSN1(ret, location, setspecial, key);
1035 PUSH_INSNL(ret, location, jump, then_label);
1046 switch (PM_NODE_TYPE(cond)) {
1049 pm_compile_logical(iseq, ret,
cast->left, NULL, else_label, scope_node);
1056 pm_compile_logical(iseq, ret,
cast->left, then_label, NULL, scope_node);
1063 PUSH_INSNL(ret, location, jump, else_label);
1066 case PM_IMAGINARY_NODE:
1067 case PM_INTEGER_NODE:
1068 case PM_LAMBDA_NODE:
1069 case PM_RATIONAL_NODE:
1070 case PM_REGULAR_EXPRESSION_NODE:
1071 case PM_STRING_NODE:
1072 case PM_SYMBOL_NODE:
1074 PUSH_INSNL(ret, location, jump, then_label);
1076 case PM_FLIP_FLOP_NODE:
1077 pm_compile_flip_flop((
const pm_flip_flop_node_t *) cond, else_label, then_label, iseq, location.
line, ret,
false, scope_node);
1079 case PM_DEFINED_NODE: {
1081 pm_compile_defined_expr(iseq,
cast->value, &location, ret,
false, scope_node,
true);
1085 DECL_ANCHOR(cond_seq);
1086 pm_compile_node(iseq, cond, cond_seq,
false, scope_node);
1088 if (LIST_INSN_SIZE_ONE(cond_seq)) {
1089 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(cond_seq));
1091 if (insn->insn_id == BIN(putobject)) {
1092 if (
RTEST(insn->operands[0])) {
1093 PUSH_INSNL(ret, location, jump, then_label);
1098 PUSH_INSNL(ret, location, jump, else_label);
1104 PUSH_SEQ(ret, cond_seq);
1109 PUSH_INSNL(ret, location, branchunless, else_label);
1110 PUSH_INSNL(ret, location, jump, then_label);
1120 LABEL *then_label = NEW_LABEL(location.
line);
1121 LABEL *else_label = NEW_LABEL(location.
line);
1122 LABEL *end_label = NULL;
1124 DECL_ANCHOR(cond_seq);
1125 pm_compile_branch_condition(iseq, cond_seq, predicate, then_label, else_label, scope_node);
1126 PUSH_SEQ(ret, cond_seq);
1131 if (then_label->refcnt && else_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1132 conditional_location = pm_code_location(scope_node, node);
1133 branches = decl_branch_base(iseq, (
int) node->
node_id, &conditional_location,
type == PM_IF_NODE ?
"if" :
"unless");
1136 if (then_label->refcnt) {
1137 PUSH_LABEL(ret, then_label);
1139 DECL_ANCHOR(then_seq);
1141 if (statements != NULL) {
1142 pm_compile_node(iseq, (
const pm_node_t *) statements, then_seq, popped, scope_node);
1145 PUSH_SYNTHETIC_PUTNIL(then_seq, iseq);
1148 if (else_label->refcnt) {
1150 if (PM_BRANCH_COVERAGE_P(iseq)) {
1153 if (statements != NULL) {
1154 branch_location = pm_code_location(scope_node, (
const pm_node_t *) statements);
1155 }
else if (
type == PM_IF_NODE) {
1158 .beg_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column },
1159 .end_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column }
1162 branch_location = conditional_location;
1165 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
type == PM_IF_NODE ?
"then" :
"else", branches);
1168 end_label = NEW_LABEL(location.
line);
1169 PUSH_INSNL(then_seq, location, jump, end_label);
1170 if (!popped) PUSH_INSN(then_seq, location, pop);
1173 PUSH_SEQ(ret, then_seq);
1176 if (else_label->refcnt) {
1177 PUSH_LABEL(ret, else_label);
1179 DECL_ANCHOR(else_seq);
1181 if (subsequent != NULL) {
1182 pm_compile_node(iseq, subsequent, else_seq, popped, scope_node);
1185 PUSH_SYNTHETIC_PUTNIL(else_seq, iseq);
1189 if (then_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1192 if (subsequent == NULL) {
1193 branch_location = conditional_location;
1194 }
else if (PM_NODE_TYPE_P(subsequent, PM_ELSE_NODE)) {
1198 branch_location = pm_code_location(scope_node, (
const pm_node_t *) subsequent);
1201 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 1,
type == PM_IF_NODE ?
"else" :
"then", branches);
1204 PUSH_SEQ(ret, else_seq);
1208 PUSH_LABEL(ret, end_label);
1222 LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
1223 LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
1224 LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
1226 LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(location.
line);
1227 LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(location.
line);
1228 LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(location.
line);
1229 LABEL *end_label = NEW_LABEL(location.
line);
1230 LABEL *adjust_label = NEW_LABEL(location.
line);
1232 LABEL *next_catch_label = NEW_LABEL(location.
line);
1233 LABEL *tmp_label = NULL;
1239 push_ensure_entry(iseq, &enl, NULL, NULL);
1242 if (flags & PM_LOOP_FLAGS_BEGIN_MODIFIER) {
1243 tmp_label = NEW_LABEL(location.
line);
1244 PUSH_INSNL(ret, location, jump, tmp_label);
1248 PUSH_INSNL(ret, location, jump, next_label);
1251 PUSH_LABEL(ret, adjust_label);
1252 PUSH_INSN(ret, location, putnil);
1253 PUSH_LABEL(ret, next_catch_label);
1254 PUSH_INSN(ret, location, pop);
1255 PUSH_INSNL(ret, location, jump, next_label);
1256 if (tmp_label) PUSH_LABEL(ret, tmp_label);
1258 PUSH_LABEL(ret, redo_label);
1261 if (PM_BRANCH_COVERAGE_P(iseq)) {
1263 VALUE branches = decl_branch_base(iseq, (
int) node->
node_id, &loop_location,
type == PM_WHILE_NODE ?
"while" :
"until");
1265 rb_code_location_t branch_location = statements != NULL ? pm_code_location(scope_node, (
const pm_node_t *) statements) : loop_location;
1266 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
"body", branches);
1269 if (statements != NULL) PM_COMPILE_POPPED((
const pm_node_t *) statements);
1270 PUSH_LABEL(ret, next_label);
1272 if (
type == PM_WHILE_NODE) {
1273 pm_compile_branch_condition(iseq, ret, predicate, redo_label, end_label, scope_node);
1275 else if (
type == PM_UNTIL_NODE) {
1276 pm_compile_branch_condition(iseq, ret, predicate, end_label, redo_label, scope_node);
1279 PUSH_LABEL(ret, end_label);
1280 PUSH_ADJUST_RESTORE(ret, adjust_label);
1281 PUSH_INSN(ret, location, putnil);
1283 PUSH_LABEL(ret, break_label);
1284 if (popped) PUSH_INSN(ret, location, pop);
1286 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, NULL, break_label);
1287 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label, NULL, next_catch_label);
1288 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, NULL, ISEQ_COMPILE_DATA(iseq)->redo_label);
1290 ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
1291 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
1292 ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
1293 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->prev;
1308 for (level = 0; level < start_depth; level++) {
1309 scope_node = scope_node->previous;
1312 while (!pm_index_lookup_table_lookup(&scope_node->
index_lookup_table, constant_id, &local_index))
1316 if (scope_node->previous) {
1317 scope_node = scope_node->previous;
1322 rb_bug(
"Local with constant_id %u does not exist", (
unsigned int) constant_id);
1326 lindex.level = level;
1327 lindex.index = scope_node->local_table_for_iseq_size - (int) local_index;
1342 RUBY_ASSERT(index < pm_parser_constants_size(scope_node->parser));
1343 return scope_node->constants[index];
1349 debugs(
"[new_child_iseq]> ---------------------------------------\n");
1350 int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
1351 rb_iseq_t *ret_iseq = pm_iseq_build(node, name,
1352 rb_iseq_path(iseq), rb_iseq_realpath(iseq),
1354 isolated_depth ? isolated_depth + 1 : 0,
1355 type, ISEQ_COMPILE_DATA(iseq)->option);
1356 debugs(
"[new_child_iseq]< ---------------------------------------\n");
1363 switch (PM_NODE_TYPE(node)) {
1364 case PM_CONSTANT_READ_NODE:
1366 case PM_CONSTANT_PATH_NODE:
1369 if (!parent)
return TRUE;
1370 return pm_cpath_const_p(parent);
1380 if (PM_NODE_TYPE_P(node, PM_CONSTANT_PATH_NODE)) {
1386 int flags = VM_DEFINECLASS_FLAG_SCOPED;
1387 if (!pm_cpath_const_p(parent)) {
1388 flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
1394 PUSH_INSN1(ret, *node_location, putobject,
rb_cObject);
1395 return VM_DEFINECLASS_FLAG_SCOPED;
1400 PUSH_INSN1(ret, *node_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
1410pm_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)
1414 LABEL *lcfin = NEW_LABEL(location.
line);
1415 LABEL *lskip = NULL;
1417 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
1418 ID id_read_name = pm_constant_id_lookup(scope_node, read_name);
1420 PM_COMPILE_NOT_POPPED(receiver);
1422 lskip = NEW_LABEL(location.
line);
1423 PUSH_INSN(ret, location, dup);
1424 PUSH_INSNL(ret, location, branchnil, lskip);
1427 PUSH_INSN(ret, location, dup);
1428 PUSH_SEND_WITH_FLAG(ret, location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
1429 if (!popped) PUSH_INSN(ret, location, dup);
1432 PUSH_INSNL(ret, location, branchunless, lcfin);
1435 PUSH_INSNL(ret, location, branchif, lcfin);
1438 if (!popped) PUSH_INSN(ret, location, pop);
1439 PM_COMPILE_NOT_POPPED(value);
1442 PUSH_INSN(ret, location, swap);
1443 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
1446 ID id_write_name = pm_constant_id_lookup(scope_node, write_name);
1447 PUSH_SEND_WITH_FLAG(ret, location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
1448 PUSH_INSNL(ret, location, jump, lfin);
1450 PUSH_LABEL(ret, lcfin);
1451 if (!popped) PUSH_INSN(ret, location, swap);
1453 PUSH_LABEL(ret, lfin);
1455 if (lskip && popped) PUSH_LABEL(ret, lskip);
1456 PUSH_INSN(ret, location, pop);
1457 if (lskip && !popped) PUSH_LABEL(ret, lskip);
1476 const int max_stack_length = 0x100;
1477 const unsigned int min_tmp_hash_length = 0x800;
1479 int stack_length = 0;
1480 bool first_chunk =
true;
1481 bool owned_hash =
false;
1487 bool static_literal =
false;
1489 DECL_ANCHOR(anchor);
1492#define FLUSH_CHUNK \
1493 if (stack_length) { \
1494 if (first_chunk) { \
1495 PUSH_SEQ(ret, anchor); \
1496 PUSH_INSN1(ret, location, newhash, INT2FIX(stack_length)); \
1497 first_chunk = false; \
1500 PUSH_INSN1(ret, location, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); \
1501 PUSH_INSN(ret, location, swap); \
1502 PUSH_SEQ(ret, anchor); \
1504 PUSH_SEND(ret, location, id_core_hash_merge_bang_ptr, INT2FIX(stack_length + 1)); \
1507 PUSH_SEND(ret, location, id_core_hash_merge_ptr, INT2FIX(stack_length + 1)); \
1508 owned_hash = true; \
1511 INIT_ANCHOR(anchor); \
1515 for (
size_t index = 0; index < elements->
size; index++) {
1518 switch (PM_NODE_TYPE(element)) {
1519 case PM_ASSOC_NODE: {
1522 (shareability == 0) &&
1523 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && (
1524 (!static_literal && ((index + min_tmp_hash_length) < elements->
size)) ||
1525 (first_chunk && stack_length == 0)
1530 while (index + count < elements->size && PM_NODE_FLAG_P(elements->
nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++;
1532 bool first_element = first_chunk && stack_length == 0;
1534 if (first_element || count >= min_tmp_hash_length) {
1540 for (
size_t tmp_end = index + count; index < tmp_end; index++) {
1544 pm_static_literal_value(iseq, assoc->key, scope_node),
1545 pm_static_literal_value(iseq, assoc->value, scope_node)
1560 if (count == elements->
size) {
1562 PUSH_INSN1(ret, location, duphash, hash);
1568 first_chunk =
false;
1571 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1572 PUSH_INSN(ret, location, swap);
1573 PUSH_INSN1(ret, location, putobject, hash);
1574 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1580 static_literal =
true;
1584 static_literal =
false;
1589 if (shareability == 0) {
1590 pm_compile_node(iseq, element, anchor,
false, scope_node);
1594 pm_compile_shareable_constant_value(iseq, assoc->
key, shareability, path, ret, scope_node,
false);
1595 pm_compile_shareable_constant_value(iseq, assoc->
value, shareability, path, ret, scope_node,
false);
1598 if ((stack_length += 2) >= max_stack_length) FLUSH_CHUNK;
1601 case PM_ASSOC_SPLAT_NODE: {
1605 bool empty_hash = assoc_splat->
value != NULL && (
1606 (PM_NODE_TYPE_P(assoc_splat->
value, PM_HASH_NODE) && ((
const pm_hash_node_t *) assoc_splat->
value)->elements.size == 0) ||
1607 PM_NODE_TYPE_P(assoc_splat->
value, PM_NIL_NODE)
1610 bool first_element = first_chunk && stack_length == 0;
1611 bool last_element = index == elements->
size - 1;
1612 bool only_element = first_element && last_element;
1619 PUSH_INSN(ret, location, putnil);
1625 if (shareability == 0) {
1626 PM_COMPILE_NOT_POPPED(element);
1629 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1637 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1638 if (shareability == 0) {
1639 PM_COMPILE_NOT_POPPED(element);
1642 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1644 PUSH_SEND(ret, location, id_core_hash_coerce,
INT2FIX(1));
1648 if (!first_element) {
1649 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1650 PUSH_INSN(ret, location, swap);
1653 if (shareability == 0) {
1654 PM_COMPILE_NOT_POPPED(element);
1657 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1660 if (!first_element) {
1662 PUSH_SEND(ret, location, id_core_hash_merge_bang_kwd,
INT2FIX(2));
1665 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1671 first_chunk =
false;
1672 static_literal =
false;
1676 RUBY_ASSERT(
"Invalid node type for hash" &&
false);
1685#define SPLATARRAY_FALSE 0
1686#define SPLATARRAY_TRUE 1
1687#define DUP_SINGLE_KW_SPLAT 2
1696 bool has_splat =
false;
1697 bool has_keyword_splat =
false;
1699 if (arguments_node == NULL) {
1700 if (*flags & VM_CALL_FCALL) {
1701 *flags |= VM_CALL_VCALL;
1706 has_keyword_splat = PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT);
1710 int post_splat_counter = 0;
1714 switch (PM_NODE_TYPE(argument)) {
1716 case PM_KEYWORD_HASH_NODE: {
1720 if (has_keyword_splat || has_splat) {
1721 *flags |= VM_CALL_KW_SPLAT;
1722 has_keyword_splat =
true;
1724 if (elements->
size > 1 || !(elements->
size == 1 && PM_NODE_TYPE_P(elements->
nodes[0], PM_ASSOC_SPLAT_NODE))) {
1728 *flags |= VM_CALL_KW_SPLAT_MUT;
1729 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1731 else if (*dup_rest & DUP_SINGLE_KW_SPLAT) {
1732 *flags |= VM_CALL_KW_SPLAT_MUT;
1733 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1734 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1735 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1736 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1739 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1745 if (PM_NODE_FLAG_P(keyword_arg, PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS)) {
1750 VALUE stored_indices = rb_hash_new();
1754 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1759 VALUE keyword = pm_static_literal_value(iseq, assoc->key, scope_node);
1760 VALUE stored_index = rb_hash_aref(stored_indices, keyword);
1765 if (!
NIL_P(stored_index)) {
1773 rb_hash_aset(stored_indices, keyword,
ULONG2NUM(element_index));
1778 if (size > VM_CALL_KW_LEN_MAX) {
1779 COMPILE_ERROR(iseq, node_location->
line,
"too many keyword arguments (%d, maximum is %d)",
1780 (
int) size, (
int) VM_CALL_KW_LEN_MAX);
1784 *flags |= VM_CALL_KWARG;
1786 VALUE *keywords = (*kw_arg)->keywords;
1787 (*kw_arg)->references = 0;
1788 (*kw_arg)->keyword_len = (int) size;
1790 size_t keyword_index = 0;
1791 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1796 keywords[keyword_index++] = pm_static_literal_value(iseq, assoc->key, scope_node);
1800 PM_COMPILE(assoc->value);
1809 *flags |= VM_CALL_KW_SPLAT;
1811 size_t size = elements->
size;
1816 *flags |= VM_CALL_KW_SPLAT_MUT;
1819 for (
size_t element_index = 0; element_index < size; element_index++) {
1821 PM_COMPILE_NOT_POPPED(assoc->key);
1822 PM_COMPILE_NOT_POPPED(assoc->value);
1825 PUSH_INSN1(ret, location, newhash,
INT2FIX(size * 2));
1830 case PM_SPLAT_NODE: {
1831 *flags |= VM_CALL_ARGS_SPLAT;
1835 PM_COMPILE_NOT_POPPED(splat_node->
expression);
1838 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1839 PUSH_GETLOCAL(ret, location, index.index, index.level);
1842 bool first_splat = !has_splat;
1850 if (index + 1 < arguments->
size || has_regular_blockarg) {
1851 PUSH_INSN1(ret, location, splatarray, (*dup_rest & SPLATARRAY_TRUE) ?
Qtrue :
Qfalse);
1852 if (*dup_rest & SPLATARRAY_TRUE) *dup_rest &= ~SPLATARRAY_TRUE;
1860 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1870 PUSH_INSN(ret, location, concattoarray);
1874 post_splat_counter = 0;
1878 case PM_FORWARDING_ARGUMENTS_NODE: {
1879 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
1881 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
1882 *flags |= VM_CALL_FORWARDING;
1884 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
1885 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1897 *flags |= VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_BLOCKARG | VM_CALL_KW_SPLAT;
1904 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1905 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1909 PUSH_INSN(ret, location, concattoarray);
1911 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1915 pm_local_index_t pow_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1916 PUSH_GETLOCAL(ret, location, pow_local.index, pow_local.level);
1919 pm_local_index_t and_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
1920 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(and_local.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(and_local.level));
1925 post_splat_counter++;
1926 PM_COMPILE_NOT_POPPED(argument);
1950 if (index == arguments->
size - 1) {
1952 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1957 switch (PM_NODE_TYPE(next_arg)) {
1959 case PM_KEYWORD_HASH_NODE: {
1960 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1961 PUSH_INSN(ret, location, concatarray);
1964 case PM_SPLAT_NODE: {
1965 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1966 PUSH_INSN(ret, location, concatarray);
1969 case PM_FORWARDING_ARGUMENTS_NODE: {
1970 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1986 if (has_splat) orig_argc++;
1987 if (has_keyword_splat) orig_argc++;
1996pm_setup_args_dup_rest_p(
const pm_node_t *node)
1998 switch (PM_NODE_TYPE(node)) {
1999 case PM_BACK_REFERENCE_READ_NODE:
2000 case PM_CLASS_VARIABLE_READ_NODE:
2001 case PM_CONSTANT_READ_NODE:
2004 case PM_GLOBAL_VARIABLE_READ_NODE:
2005 case PM_IMAGINARY_NODE:
2006 case PM_INSTANCE_VARIABLE_READ_NODE:
2007 case PM_INTEGER_NODE:
2008 case PM_LAMBDA_NODE:
2009 case PM_LOCAL_VARIABLE_READ_NODE:
2011 case PM_NUMBERED_REFERENCE_READ_NODE:
2012 case PM_RATIONAL_NODE:
2013 case PM_REGULAR_EXPRESSION_NODE:
2015 case PM_STRING_NODE:
2016 case PM_SYMBOL_NODE:
2019 case PM_CONSTANT_PATH_NODE: {
2021 if (
cast->parent != NULL) {
2022 return pm_setup_args_dup_rest_p(
cast->parent);
2026 case PM_IMPLICIT_NODE:
2028 case PM_ARRAY_NODE: {
2030 for (
size_t index = 0; index <
cast->elements.size; index++) {
2031 if (pm_setup_args_dup_rest_p(
cast->elements.nodes[index])) {
2048 int dup_rest = SPLATARRAY_TRUE;
2051 size_t arguments_size;
2056 arguments_node != NULL &&
2057 (arguments = &arguments_node->
arguments, arguments_size = arguments->
size) >= 2 &&
2058 PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_SPLAT) &&
2059 !PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_MULTIPLE_SPLATS) &&
2060 PM_NODE_TYPE_P(arguments->
nodes[arguments_size - 1], PM_KEYWORD_HASH_NODE)
2065 dup_rest = SPLATARRAY_FALSE;
2070 for (
size_t index = 0; dup_rest == SPLATARRAY_FALSE && index < elements->
size; index++) {
2073 switch (PM_NODE_TYPE(element)) {
2074 case PM_ASSOC_NODE: {
2076 if (pm_setup_args_dup_rest_p(assoc->
key) || pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2079 case PM_ASSOC_SPLAT_NODE: {
2081 if (assoc->
value != NULL && pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2090 int initial_dup_rest = dup_rest;
2093 if (block && PM_NODE_TYPE_P(block, PM_BLOCK_ARGUMENT_NODE)) {
2097 bool regular_block_arg =
true;
2100 if (block_expr && pm_setup_args_dup_rest_p(block_expr)) {
2101 dup_rest = SPLATARRAY_TRUE | DUP_SINGLE_KW_SPLAT;
2102 initial_dup_rest = dup_rest;
2105 DECL_ANCHOR(block_arg);
2106 pm_compile_node(iseq, block, block_arg,
false, scope_node);
2108 *flags |= VM_CALL_ARGS_BLOCKARG;
2110 if (LIST_INSN_SIZE_ONE(block_arg)) {
2112 if (IS_INSN(elem)) {
2114 if (iobj->insn_id == BIN(getblockparam)) {
2115 iobj->insn_id = BIN(getblockparamproxy);
2122 regular_block_arg =
false;
2126 argc = pm_setup_args_core(arguments_node, block, flags, regular_block_arg, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2127 PUSH_SEQ(ret, block_arg);
2130 argc = pm_setup_args_core(arguments_node, block, flags,
false, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2137 if (*flags & VM_CALL_ARGS_SPLAT && dup_rest != initial_dup_rest) {
2138 *flags |= VM_CALL_ARGS_SPLAT_MUT;
2158 if (!popped) PUSH_INSN(ret, location, putnil);
2160 PM_COMPILE_NOT_POPPED(node->
receiver);
2162 int boff = (node->
block == NULL ? 0 : 1);
2163 int flag = PM_NODE_TYPE_P(node->
receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2165 int argc = pm_setup_args(node->
arguments, (
const pm_node_t *) node->
block, &flag, &keywords, iseq, ret, scope_node, node_location);
2167 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2169 PUSH_INSN(ret, location, splatkw);
2172 PUSH_INSN(ret, location, dup);
2173 PUSH_INSN(ret, location, splatkw);
2174 PUSH_INSN(ret, location, pop);
2178 int dup_argn = argc + 1 + boff;
2179 int keyword_len = 0;
2182 keyword_len = keywords->keyword_len;
2183 dup_argn += keyword_len;
2186 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2187 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2188 PM_COMPILE_NOT_POPPED(node->
value);
2191 PUSH_SEND(ret, location, id_operator,
INT2FIX(1));
2194 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2196 if (flag & VM_CALL_ARGS_SPLAT) {
2197 if (flag & VM_CALL_KW_SPLAT) {
2198 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2200 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2201 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2202 flag |= VM_CALL_ARGS_SPLAT_MUT;
2205 PUSH_INSN(ret, location, swap);
2206 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2207 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2208 PUSH_INSN(ret, location, pop);
2212 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2213 PUSH_INSN(ret, location, swap);
2214 PUSH_INSN(ret, location, pop);
2216 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2217 PUSH_INSN(ret, location, swap);
2218 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2219 PUSH_INSN(ret, location, swap);
2220 flag |= VM_CALL_ARGS_SPLAT_MUT;
2222 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2224 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2225 PUSH_INSN(ret, location, pop);
2226 PUSH_INSN(ret, location, pop);
2230 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2232 else if (flag & VM_CALL_KW_SPLAT) {
2234 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2235 PUSH_INSN(ret, location, swap);
2236 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2237 PUSH_INSN(ret, location, pop);
2239 PUSH_INSN(ret, location, swap);
2240 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2242 else if (keyword_len) {
2243 PUSH_INSN(ret, location, dup);
2244 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 2));
2245 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2246 PUSH_INSN(ret, location, pop);
2247 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2251 PUSH_INSN(ret, location, swap);
2253 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2256 PUSH_INSN(ret, location, pop);
2275 if (!popped) PUSH_INSN(ret, location, putnil);
2276 PM_COMPILE_NOT_POPPED(receiver);
2278 int boff = (block == NULL ? 0 : 1);
2279 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2281 int argc = pm_setup_args(arguments, (
const pm_node_t *) block, &flag, &keywords, iseq, ret, scope_node, node_location);
2283 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2285 PUSH_INSN(ret, location, splatkw);
2288 PUSH_INSN(ret, location, dup);
2289 PUSH_INSN(ret, location, splatkw);
2290 PUSH_INSN(ret, location, pop);
2294 int dup_argn = argc + 1 + boff;
2295 int keyword_len = 0;
2298 keyword_len = keywords->keyword_len;
2299 dup_argn += keyword_len;
2302 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2303 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2305 LABEL *label = NEW_LABEL(location.
line);
2308 PUSH_INSN(ret, location, dup);
2309 if (PM_NODE_TYPE_P(node, PM_INDEX_AND_WRITE_NODE)) {
2310 PUSH_INSNL(ret, location, branchunless, label);
2313 PUSH_INSNL(ret, location, branchif, label);
2316 PUSH_INSN(ret, location, pop);
2317 PM_COMPILE_NOT_POPPED(value);
2320 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2323 if (flag & VM_CALL_ARGS_SPLAT) {
2324 if (flag & VM_CALL_KW_SPLAT) {
2325 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2326 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2327 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2328 flag |= VM_CALL_ARGS_SPLAT_MUT;
2331 PUSH_INSN(ret, location, swap);
2332 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2333 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2334 PUSH_INSN(ret, location, pop);
2338 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2339 PUSH_INSN(ret, location, swap);
2340 PUSH_INSN(ret, location, pop);
2342 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2343 PUSH_INSN(ret, location, swap);
2344 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2345 PUSH_INSN(ret, location, swap);
2346 flag |= VM_CALL_ARGS_SPLAT_MUT;
2348 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2350 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2351 PUSH_INSN(ret, location, pop);
2352 PUSH_INSN(ret, location, pop);
2356 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2358 else if (flag & VM_CALL_KW_SPLAT) {
2360 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2361 PUSH_INSN(ret, location, swap);
2362 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2363 PUSH_INSN(ret, location, pop);
2366 PUSH_INSN(ret, location, swap);
2367 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2369 else if (keyword_len) {
2370 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2371 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 0));
2372 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2376 PUSH_INSN(ret, location, swap);
2378 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2381 PUSH_INSN(ret, location, pop);
2382 PUSH_INSNL(ret, location, jump, lfin);
2383 PUSH_LABEL(ret, label);
2385 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2387 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(dup_argn + 1));
2388 PUSH_LABEL(ret, lfin);
2397#define PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE 0
2398#define PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING 1
2399#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P 2
2400#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE 3
2401#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY 4
2416 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2418 PUSH_INSN(ret, location, dup);
2419 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2421 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2422 PUSH_INSN1(ret, location, putobject, message);
2423 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2424 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2425 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2427 PUSH_INSN1(ret, location, putobject,
Qfalse);
2428 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2430 PUSH_INSN(ret, location, pop);
2431 PUSH_INSN(ret, location, pop);
2432 PUSH_LABEL(ret, match_succeeded_label);
2446 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2448 PUSH_INSN(ret, location, dup);
2449 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2451 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2452 PUSH_INSN1(ret, location, putobject, message);
2453 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2454 PUSH_INSN(ret, location, dup);
2455 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2456 PUSH_INSN1(ret, location, putobject, length);
2457 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(4));
2458 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2460 PUSH_INSN1(ret, location, putobject,
Qfalse);
2461 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2463 PUSH_INSN(ret, location, pop);
2464 PUSH_INSN(ret, location, pop);
2465 PUSH_LABEL(ret, match_succeeded_label);
2479 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2481 PUSH_INSN(ret, location, dup);
2482 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2483 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2485 VALUE operand = rb_fstring_lit(
"%p === %p does not return true");
2486 PUSH_INSN1(ret, location, putobject, operand);
2488 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2489 PUSH_INSN1(ret, location, topn,
INT2FIX(5));
2490 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2491 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2492 PUSH_INSN1(ret, location, putobject,
Qfalse);
2493 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2494 PUSH_INSN(ret, location, pop);
2495 PUSH_INSN(ret, location, pop);
2497 PUSH_LABEL(ret, match_succeeded_label);
2498 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2499 PUSH_INSN(ret, location, pop);
2500 PUSH_INSN(ret, location, pop);
2514 LABEL *matched_label = NEW_LABEL(pm_node_line_number_cached(node, scope_node));
2515 CHECK(pm_compile_pattern(iseq, scope_node, node, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
2516 PUSH_LABEL(ret, matched_label);
2526pm_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)
2530 if (use_deconstructed_cache) {
2531 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2532 PUSH_INSNL(ret, location, branchnil, deconstruct_label);
2534 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2535 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2537 PUSH_INSN(ret, location, pop);
2538 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE - 1));
2539 PUSH_INSNL(ret, location, jump, deconstructed_label);
2542 PUSH_INSNL(ret, location, jump, deconstruct_label);
2545 PUSH_LABEL(ret, deconstruct_label);
2546 PUSH_INSN(ret, location, dup);
2549 PUSH_INSN1(ret, location, putobject, operand);
2550 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2552 if (use_deconstructed_cache) {
2553 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE + 1));
2556 if (in_single_pattern) {
2557 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct"), base_index + 1));
2560 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2561 PUSH_SEND(ret, location, rb_intern(
"deconstruct"),
INT2FIX(0));
2563 if (use_deconstructed_cache) {
2564 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2567 PUSH_INSN(ret, location, dup);
2569 PUSH_INSNL(ret, location, branchunless, type_error_label);
2570 PUSH_LABEL(ret, deconstructed_label);
2584 PUSH_INSN(ret, location, dup);
2585 PM_COMPILE_NOT_POPPED(node);
2587 if (in_single_pattern) {
2588 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
2590 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
2591 if (in_single_pattern) {
2592 CHECK(pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 3));
2594 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2606 LABEL *key_error_label = NEW_LABEL(location.
line);
2607 LABEL *cleanup_label = NEW_LABEL(location.
line);
2610 kw_arg->references = 0;
2611 kw_arg->keyword_len = 2;
2612 kw_arg->keywords[0] =
ID2SYM(rb_intern(
"matchee"));
2613 kw_arg->keywords[1] =
ID2SYM(rb_intern(
"key"));
2615 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2616 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2617 PUSH_INSNL(ret, location, branchif, key_error_label);
2620 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2623 VALUE operand = rb_fstring_lit(
"%p: %s");
2624 PUSH_INSN1(ret, location, putobject, operand);
2627 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2628 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2629 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2630 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2631 PUSH_INSNL(ret, location, jump, cleanup_label);
2633 PUSH_LABEL(ret, key_error_label);
2635 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2638 VALUE operand = rb_fstring_lit(
"%p: %s");
2639 PUSH_INSN1(ret, location, putobject, operand);
2642 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2643 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2644 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2645 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2646 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2647 PUSH_SEND_R(ret, location, rb_intern(
"new"),
INT2FIX(1), NULL,
INT2FIX(VM_CALL_KWARG), kw_arg);
2648 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(1));
2649 PUSH_LABEL(ret, cleanup_label);
2651 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(7));
2652 if (!popped) PUSH_INSN(ret, location, putnil);
2653 PUSH_INSNL(ret, location, jump, done_label);
2654 PUSH_INSN1(ret, location, dupn,
INT2FIX(5));
2655 if (popped) PUSH_INSN(ret, location, putnil);
2666 switch (PM_NODE_TYPE(node)) {
2667 case PM_ARRAY_PATTERN_NODE: {
2678 const size_t requireds_size =
cast->requireds.size;
2679 const size_t posts_size =
cast->posts.size;
2680 const size_t minimum_size = requireds_size + posts_size;
2682 bool rest_named =
false;
2683 bool use_rest_size =
false;
2685 if (
cast->rest != NULL) {
2686 rest_named = (PM_NODE_TYPE_P(
cast->rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *)
cast->rest)->expression != NULL);
2687 use_rest_size = (rest_named || (!rest_named && posts_size > 0));
2690 LABEL *match_failed_label = NEW_LABEL(location.
line);
2691 LABEL *type_error_label = NEW_LABEL(location.
line);
2692 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2693 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2695 if (use_rest_size) {
2696 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2697 PUSH_INSN(ret, location, swap);
2701 if (
cast->constant != NULL) {
2702 CHECK(pm_compile_pattern_constant(iseq, scope_node,
cast->constant, ret, match_failed_label, in_single_pattern, base_index));
2705 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));
2707 PUSH_INSN(ret, location, dup);
2708 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2709 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2710 PUSH_SEND(ret, location,
cast->rest == NULL ? idEq : idGE,
INT2FIX(1));
2711 if (in_single_pattern) {
2712 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+)");
2713 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, message,
INT2FIX(minimum_size), base_index + 1));
2715 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2717 for (
size_t index = 0; index < requireds_size; index++) {
2719 PUSH_INSN(ret, location, dup);
2720 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2721 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2722 CHECK(pm_compile_pattern_match(iseq, scope_node, required, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2725 if (
cast->rest != NULL) {
2727 PUSH_INSN(ret, location, dup);
2728 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size));
2729 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2730 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2731 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2732 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2733 PUSH_INSN1(ret, location, setn,
INT2FIX(4));
2734 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2735 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));
2737 else if (posts_size > 0) {
2738 PUSH_INSN(ret, location, dup);
2739 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2740 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2741 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2742 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2743 PUSH_INSN(ret, location, pop);
2747 for (
size_t index = 0; index < posts_size; index++) {
2749 PUSH_INSN(ret, location, dup);
2751 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size + index));
2752 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2753 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2754 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2755 CHECK(pm_compile_pattern_match(iseq, scope_node, post, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2758 PUSH_INSN(ret, location, pop);
2759 if (use_rest_size) {
2760 PUSH_INSN(ret, location, pop);
2763 PUSH_INSNL(ret, location, jump, matched_label);
2764 PUSH_INSN(ret, location, putnil);
2765 if (use_rest_size) {
2766 PUSH_INSN(ret, location, putnil);
2769 PUSH_LABEL(ret, type_error_label);
2770 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2774 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2775 PUSH_INSN1(ret, location, putobject, operand);
2778 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2779 PUSH_INSN(ret, location, pop);
2781 PUSH_LABEL(ret, match_failed_label);
2782 PUSH_INSN(ret, location, pop);
2783 if (use_rest_size) {
2784 PUSH_INSN(ret, location, pop);
2787 PUSH_INSNL(ret, location, jump, unmatched_label);
2790 case PM_FIND_PATTERN_NODE: {
2800 const size_t size =
cast->requireds.size;
2802 LABEL *match_failed_label = NEW_LABEL(location.
line);
2803 LABEL *type_error_label = NEW_LABEL(location.
line);
2804 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2805 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2807 if (
cast->constant) {
2808 CHECK(pm_compile_pattern_constant(iseq, scope_node,
cast->constant, ret, match_failed_label, in_single_pattern, base_index));
2811 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));
2813 PUSH_INSN(ret, location, dup);
2814 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2815 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2816 PUSH_SEND(ret, location, idGE,
INT2FIX(1));
2817 if (in_single_pattern) {
2818 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));
2820 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2823 LABEL *while_begin_label = NEW_LABEL(location.
line);
2824 LABEL *next_loop_label = NEW_LABEL(location.
line);
2825 LABEL *find_succeeded_label = NEW_LABEL(location.
line);
2826 LABEL *find_failed_label = NEW_LABEL(location.
line);
2828 PUSH_INSN(ret, location, dup);
2829 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2831 PUSH_INSN(ret, location, dup);
2832 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2833 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2834 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2835 PUSH_LABEL(ret, while_begin_label);
2837 PUSH_INSN(ret, location, dup);
2838 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2839 PUSH_SEND(ret, location, idLE,
INT2FIX(1));
2840 PUSH_INSNL(ret, location, branchunless, find_failed_label);
2842 for (
size_t index = 0; index < size; index++) {
2843 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2844 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2847 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2848 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2851 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2852 CHECK(pm_compile_pattern_match(iseq, scope_node,
cast->requireds.nodes[index], ret, next_loop_label, in_single_pattern,
false, base_index + 4));
2858 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2859 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2860 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2861 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2862 CHECK(pm_compile_pattern_match(iseq, scope_node, left->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4));
2868 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2869 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2870 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2871 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2872 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2873 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2874 pm_compile_pattern_match(iseq, scope_node, right->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4);
2877 PUSH_INSNL(ret, location, jump, find_succeeded_label);
2879 PUSH_LABEL(ret, next_loop_label);
2880 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
2881 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2882 PUSH_INSNL(ret, location, jump, while_begin_label);
2884 PUSH_LABEL(ret, find_failed_label);
2885 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2886 if (in_single_pattern) {
2887 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2890 VALUE operand = rb_fstring_lit(
"%p does not match to find pattern");
2891 PUSH_INSN1(ret, location, putobject, operand);
2894 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2895 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2896 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2898 PUSH_INSN1(ret, location, putobject,
Qfalse);
2899 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2901 PUSH_INSN(ret, location, pop);
2902 PUSH_INSN(ret, location, pop);
2904 PUSH_INSNL(ret, location, jump, match_failed_label);
2905 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2907 PUSH_LABEL(ret, find_succeeded_label);
2908 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2911 PUSH_INSN(ret, location, pop);
2912 PUSH_INSNL(ret, location, jump, matched_label);
2913 PUSH_INSN(ret, location, putnil);
2915 PUSH_LABEL(ret, type_error_label);
2916 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2920 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2921 PUSH_INSN1(ret, location, putobject, operand);
2924 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2925 PUSH_INSN(ret, location, pop);
2927 PUSH_LABEL(ret, match_failed_label);
2928 PUSH_INSN(ret, location, pop);
2929 PUSH_INSNL(ret, location, jump, unmatched_label);
2933 case PM_HASH_PATTERN_NODE: {
2946 bool has_keys =
cast->elements.size > 0 ||
cast->rest != NULL;
2948 LABEL *match_failed_label = NEW_LABEL(location.
line);
2949 LABEL *type_error_label = NEW_LABEL(location.
line);
2952 if (has_keys && !has_rest) {
2955 for (
size_t index = 0; index <
cast->elements.size; index++) {
2957 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
2967 if (
cast->constant) {
2968 CHECK(pm_compile_pattern_constant(iseq, scope_node,
cast->constant, ret, match_failed_label, in_single_pattern, base_index));
2971 PUSH_INSN(ret, location, dup);
2974 VALUE operand =
ID2SYM(rb_intern(
"deconstruct_keys"));
2975 PUSH_INSN1(ret, location, putobject, operand);
2978 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2979 if (in_single_pattern) {
2980 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct_keys"), base_index + 1));
2982 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2985 PUSH_INSN(ret, location, putnil);
2990 PUSH_INSN1(ret, location, duparray, keys);
2993 PUSH_SEND(ret, location, rb_intern(
"deconstruct_keys"),
INT2FIX(1));
2995 PUSH_INSN(ret, location, dup);
2997 PUSH_INSNL(ret, location, branchunless, type_error_label);
3000 PUSH_SEND(ret, location, rb_intern(
"dup"),
INT2FIX(0));
3004 DECL_ANCHOR(match_values);
3006 for (
size_t index = 0; index <
cast->elements.size; index++) {
3008 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
3015 PUSH_INSN(ret, location, dup);
3016 PUSH_INSN1(ret, location, putobject, symbol);
3017 PUSH_SEND(ret, location, rb_intern(
"key?"),
INT2FIX(1));
3019 if (in_single_pattern) {
3020 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3022 PUSH_INSN(ret, location, dup);
3023 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3028 PUSH_INSN1(ret, location, putobject, operand);
3031 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 2));
3032 PUSH_INSN1(ret, location, putobject,
Qtrue);
3033 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 3));
3034 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
3035 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
3036 PUSH_INSN1(ret, location, putobject, symbol);
3037 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
3039 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(4));
3040 PUSH_LABEL(ret, match_succeeded_label);
3043 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3044 PUSH_INSN(match_values, location, dup);
3045 PUSH_INSN1(match_values, location, putobject, symbol);
3046 PUSH_SEND(match_values, location, has_rest ? rb_intern(
"delete") : idAREF,
INT2FIX(1));
3049 if (PM_NODE_TYPE_P(value, PM_IMPLICIT_NODE)) {
3053 CHECK(pm_compile_pattern_match(iseq, scope_node, value, match_values, match_failed_label, in_single_pattern,
false, base_index + 1));
3056 PUSH_SEQ(ret, match_values);
3059 PUSH_INSN(ret, location, dup);
3060 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3061 if (in_single_pattern) {
3062 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p is not empty"), base_index + 1));
3064 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3068 switch (PM_NODE_TYPE(
cast->rest)) {
3069 case PM_NO_KEYWORDS_PARAMETER_NODE: {
3070 PUSH_INSN(ret, location, dup);
3071 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3072 if (in_single_pattern) {
3073 pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"rest of %p is not empty"), base_index + 1);
3075 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3078 case PM_ASSOC_SPLAT_NODE: {
3080 PUSH_INSN(ret, location, dup);
3081 pm_compile_pattern_match(iseq, scope_node, splat->value, ret, match_failed_label, in_single_pattern,
false, base_index + 1);
3085 rb_bug(
"unreachable");
3090 PUSH_INSN(ret, location, pop);
3091 PUSH_INSNL(ret, location, jump, matched_label);
3092 PUSH_INSN(ret, location, putnil);
3094 PUSH_LABEL(ret, type_error_label);
3095 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
3099 VALUE operand = rb_fstring_lit(
"deconstruct_keys must return Hash");
3100 PUSH_INSN1(ret, location, putobject, operand);
3103 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
3104 PUSH_INSN(ret, location, pop);
3106 PUSH_LABEL(ret, match_failed_label);
3107 PUSH_INSN(ret, location, pop);
3108 PUSH_INSNL(ret, location, jump, unmatched_label);
3111 case PM_CAPTURE_PATTERN_NODE: {
3123 LABEL *match_failed_label = NEW_LABEL(location.
line);
3125 PUSH_INSN(ret, location, dup);
3126 CHECK(pm_compile_pattern_match(iseq, scope_node,
cast->value, ret, match_failed_label, in_single_pattern, use_deconstructed_cache, base_index + 1));
3127 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));
3128 PUSH_INSN(ret, location, putnil);
3130 PUSH_LABEL(ret, match_failed_label);
3131 PUSH_INSN(ret, location, pop);
3132 PUSH_INSNL(ret, location, jump, unmatched_label);
3136 case PM_LOCAL_VARIABLE_TARGET_NODE: {
3143 PUSH_SETLOCAL(ret, location, index.index, index.level);
3144 PUSH_INSNL(ret, location, jump, matched_label);
3147 case PM_ALTERNATION_PATTERN_NODE: {
3152 LABEL *matched_left_label = NEW_LABEL(location.
line);
3153 LABEL *unmatched_left_label = NEW_LABEL(location.
line);
3157 PUSH_INSN(ret, location, dup);
3158 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));
3163 PUSH_LABEL(ret, matched_left_label);
3164 PUSH_INSN(ret, location, pop);
3165 PUSH_INSNL(ret, location, jump, matched_label);
3166 PUSH_INSN(ret, location, putnil);
3170 PUSH_LABEL(ret, unmatched_left_label);
3171 CHECK(pm_compile_pattern(iseq, scope_node,
cast->right, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3174 case PM_PARENTHESES_NODE:
3179 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);
3180 case PM_PINNED_EXPRESSION_NODE:
3188 case PM_CLASS_VARIABLE_READ_NODE:
3189 case PM_CONSTANT_PATH_NODE:
3190 case PM_CONSTANT_READ_NODE:
3193 case PM_GLOBAL_VARIABLE_READ_NODE:
3194 case PM_IMAGINARY_NODE:
3195 case PM_INSTANCE_VARIABLE_READ_NODE:
3196 case PM_IT_LOCAL_VARIABLE_READ_NODE:
3197 case PM_INTEGER_NODE:
3198 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
3199 case PM_INTERPOLATED_STRING_NODE:
3200 case PM_INTERPOLATED_SYMBOL_NODE:
3201 case PM_INTERPOLATED_X_STRING_NODE:
3202 case PM_LAMBDA_NODE:
3203 case PM_LOCAL_VARIABLE_READ_NODE:
3205 case PM_SOURCE_ENCODING_NODE:
3206 case PM_SOURCE_FILE_NODE:
3207 case PM_SOURCE_LINE_NODE:
3209 case PM_RATIONAL_NODE:
3210 case PM_REGULAR_EXPRESSION_NODE:
3212 case PM_STRING_NODE:
3213 case PM_SYMBOL_NODE:
3215 case PM_X_STRING_NODE: {
3219 PM_COMPILE_NOT_POPPED(node);
3220 if (in_single_pattern) {
3221 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
3224 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
3226 if (in_single_pattern) {
3227 pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 2);
3230 PUSH_INSNL(ret, location, branchif, matched_label);
3231 PUSH_INSNL(ret, location, jump, unmatched_label);
3234 case PM_PINNED_VARIABLE_NODE: {
3240 CHECK(pm_compile_pattern(iseq, scope_node,
cast->variable, ret, matched_label, unmatched_label, in_single_pattern,
true, base_index));
3244 case PM_UNLESS_NODE: {
3259 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3261 predicate =
cast->predicate;
3264 statement =
cast->statements->body.nodes[0];
3268 predicate =
cast->predicate;
3271 statement =
cast->statements->body.nodes[0];
3274 CHECK(pm_compile_pattern_match(iseq, scope_node, statement, ret, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3275 PM_COMPILE_NOT_POPPED(predicate);
3277 if (in_single_pattern) {
3278 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3280 PUSH_INSN(ret, location, dup);
3281 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3282 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3285 PUSH_INSNL(ret, location, branchunless, match_succeeded_label);
3289 VALUE operand = rb_fstring_lit(
"guard clause does not return true");
3290 PUSH_INSN1(ret, location, putobject, operand);
3293 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
3294 PUSH_INSN1(ret, location, putobject,
Qfalse);
3295 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
3297 PUSH_INSN(ret, location, pop);
3298 PUSH_INSN(ret, location, pop);
3300 PUSH_LABEL(ret, match_succeeded_label);
3303 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3304 PUSH_INSNL(ret, location, branchunless, unmatched_label);
3307 PUSH_INSNL(ret, location, branchif, unmatched_label);
3310 PUSH_INSNL(ret, location, jump, matched_label);
3317 rb_bug(
"Unexpected node type in pattern matching expression: %s", pm_node_type(PM_NODE_TYPE(node)));
3324#undef PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE
3325#undef PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING
3326#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P
3327#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE
3328#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY
3339 scope->parameters = NULL;
3341 scope->local_table_for_iseq_size = 0;
3349 scope->base.
type = PM_SCOPE_NODE;
3352 scope->previous = previous;
3355 switch (PM_NODE_TYPE(node)) {
3356 case PM_BLOCK_NODE: {
3358 scope->body =
cast->body;
3359 scope->locals =
cast->locals;
3360 scope->parameters =
cast->parameters;
3363 case PM_CLASS_NODE: {
3365 scope->body =
cast->body;
3366 scope->locals =
cast->locals;
3372 scope->body =
cast->body;
3373 scope->locals =
cast->locals;
3376 case PM_ENSURE_NODE: {
3380 if (
cast->statements != NULL) {
3392 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
3397 case PM_LAMBDA_NODE: {
3399 scope->parameters =
cast->parameters;
3400 scope->body =
cast->body;
3401 scope->locals =
cast->locals;
3404 case PM_MODULE_NODE: {
3406 scope->body =
cast->body;
3407 scope->locals =
cast->locals;
3410 case PM_POST_EXECUTION_NODE: {
3415 case PM_PROGRAM_NODE: {
3418 scope->locals =
cast->locals;
3421 case PM_RESCUE_NODE: {
3426 case PM_RESCUE_MODIFIER_NODE: {
3431 case PM_SINGLETON_CLASS_NODE: {
3433 scope->body =
cast->body;
3434 scope->locals =
cast->locals;
3437 case PM_STATEMENTS_NODE: {
3443 rb_bug(
"unreachable");
3472 iobj = IS_INSN(last_elem) ? (
INSN*) last_elem : (
INSN*) get_prev_insn((
INSN*) last_elem);
3473 while (!IS_INSN_ID(iobj, send) && !IS_INSN_ID(iobj, invokesuper) && !IS_INSN_ID(iobj, sendforward) && !IS_INSN_ID(iobj, invokesuperforward)) {
3474 iobj = (
INSN*) get_prev_insn(iobj);
3476 ELEM_INSERT_NEXT(&iobj->link, (
LINK_ELEMENT*) retry_end_l);
3481 if (&iobj->link == LAST_ELEMENT(ret)) {
3489 const char *name = rb_id2name(method_id);
3490 static const char prefix[] =
"__builtin_";
3491 const size_t prefix_len =
sizeof(prefix) - 1;
3493 if (receiver == NULL) {
3494 if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) {
3496 return &name[prefix_len];
3499 else if (PM_NODE_TYPE_P(receiver, PM_CALL_NODE)) {
3500 if (PM_NODE_FLAG_P(receiver, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3508 else if (PM_NODE_TYPE_P(receiver, PM_CONSTANT_READ_NODE)) {
3523 if (arguments == NULL) {
3524 COMPILE_ERROR(iseq, node_location->
line,
"attr!: no argument");
3530 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3531 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to attr!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3535 VALUE symbol = pm_static_literal_value(iseq, argument, scope_node);
3536 if (compile_builtin_attr_symbol(iseq, symbol) != COMPILE_OK) {
3537 COMPILE_ERROR(iseq, node_location->
line,
"unknown argument to attr!: %" PRIsVALUE, symbol);
3548 if (arguments == NULL) {
3549 COMPILE_ERROR(iseq, node_location->
line,
"arg!: no argument");
3554 COMPILE_ERROR(iseq, node_location->
line,
"arg!: too many argument");
3559 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3560 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to arg!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3566 int index = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->local_table_size - get_local_var_idx(iseq, name);
3568 debugs(
"id: %s idx: %d\n", rb_id2name(name), index);
3569 PUSH_GETLOCAL(ret, *node_location, index, get_lvar_level(iseq));
3578 const pm_node_t *ast_node = scope_node->ast_node;
3579 if (!PM_NODE_TYPE_P(ast_node, PM_DEF_NODE)) {
3580 rb_bug(
"mandatory_only?: not in method definition");
3586 if (parameters_node == NULL) {
3587 rb_bug(
"mandatory_only?: in method definition with no parameters");
3592 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)) {
3593 rb_bug(
"mandatory_only?: not in method definition with plain statements");
3599 rb_bug(
"mandatory_only?: can't find mandatory node");
3610 .name = def_node->
name,
3612 .parameters = ¶meters,
3622 pm_scope_node_init(&def.base, &next_scope_node, scope_node);
3624 const rb_iseq_t *mandatory_only_iseq = pm_iseq_build(
3626 rb_iseq_base_label(iseq),
3628 rb_iseq_realpath(iseq),
3629 node_location->
line,
3633 ISEQ_COMPILE_DATA(iseq)->option
3635 RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->mandatory_only_iseq, (
VALUE)mandatory_only_iseq);
3637 pm_scope_node_destroy(&next_scope_node);
3646 if (parent_block != NULL) {
3647 COMPILE_ERROR(iseq, node_location->
line,
"should not call builtins here.");
3651#define BUILTIN_INLINE_PREFIX "_bi"
3652 char inline_func[
sizeof(BUILTIN_INLINE_PREFIX) +
DECIMAL_SIZE_OF(
int)];
3653 bool cconst =
false;
3658 if (strcmp(
"cstmt!", builtin_func) == 0 || strcmp(
"cexpr!", builtin_func) == 0) {
3661 else if (strcmp(
"cconst!", builtin_func) == 0) {
3664 else if (strcmp(
"cinit!", builtin_func) == 0) {
3668 else if (strcmp(
"attr!", builtin_func) == 0) {
3669 return pm_compile_builtin_attr(iseq, scope_node, arguments, node_location);
3671 else if (strcmp(
"arg!", builtin_func) == 0) {
3672 return pm_compile_builtin_arg(iseq, ret, scope_node, arguments, node_location, popped);
3674 else if (strcmp(
"mandatory_only?", builtin_func) == 0) {
3676 rb_bug(
"mandatory_only? should be in if condition");
3678 else if (!LIST_INSN_SIZE_ZERO(ret)) {
3679 rb_bug(
"mandatory_only? should be put on top");
3682 PUSH_INSN1(ret, *node_location, putobject,
Qfalse);
3683 return pm_compile_builtin_mandatory_only_method(iseq, scope_node, call_node, node_location);
3685 else if (strcmp(
"local_self!", builtin_func) == 0) {
3688 pm_constant_id_t self_id = pm_parser_constant_find(scope_node->parser, (
const uint8_t *)
"self", 4);
3690 COMPILE_ERROR(iseq, node_location->
line,
"local_self! called but 'self' not found in local table");
3693 pm_local_index_t self_index = pm_lookup_local_index(iseq, scope_node, self_id, 0);
3694 PUSH_GETLOCAL(ret, *node_location, self_index.index, self_index.level);
3698 rb_bug(
"can't find builtin function:%s", builtin_func);
3701 COMPILE_ERROR(iseq, node_location->
line,
"can't find builtin function:%s", builtin_func);
3705 int inline_index = node_location->
line;
3706 snprintf(inline_func,
sizeof(inline_func), BUILTIN_INLINE_PREFIX
"%d", inline_index);
3707 builtin_func = inline_func;
3713 typedef VALUE(*builtin_func0)(
void *,
VALUE);
3714 VALUE const_val = (*(builtin_func0)(uintptr_t)bf->func_ptr)(NULL,
Qnil);
3715 PUSH_INSN1(ret, *node_location, putobject, const_val);
3721 DECL_ANCHOR(args_seq);
3725 int argc = pm_setup_args(arguments, call_node->
block, &flags, &keywords, iseq, args_seq, scope_node, node_location);
3727 if (argc != bf->argc) {
3728 COMPILE_ERROR(iseq, node_location->
line,
"argc is not match for builtin function:%s (expect %d but %d)", builtin_func, bf->argc, argc);
3732 unsigned int start_index;
3733 if (delegate_call_p(iseq, argc, args_seq, &start_index)) {
3734 PUSH_INSN2(ret, *node_location, opt_invokebuiltin_delegate, bf,
INT2FIX(start_index));
3737 PUSH_SEQ(ret, args_seq);
3738 PUSH_INSN1(ret, *node_location, invokebuiltin, bf);
3741 if (popped) PUSH_INSN(ret, *node_location, pop);
3756 LABEL *else_label = NEW_LABEL(location.
line);
3757 LABEL *end_label = NEW_LABEL(location.
line);
3758 LABEL *retry_end_l = NEW_LABEL(location.
line);
3762 int node_id = location.
node_id;
3764 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3765 if (PM_BRANCH_COVERAGE_P(iseq)) {
3766 uint32_t end_cursor = 0;
3767 bool end_found =
false;
3771 end_cursor = cursor;
3777 if (!end_found || cursor > end_cursor) {
3778 end_cursor = cursor;
3785 if (!end_found || cursor > end_cursor) {
3786 end_cursor = cursor;
3795 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(call_node);
3796 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);
3799 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
3800 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
3803 branches = decl_branch_base(iseq, (
int) call_node->
base.
node_id, &code_location,
"&.");
3806 PUSH_INSN(ret, location, dup);
3807 PUSH_INSNL(ret, location, branchnil, else_label);
3809 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0,
"then", branches);
3817 int orig_argc = pm_setup_args(call_node->
arguments, call_node->
block, &flags, &kw_arg, iseq, ret, scope_node, &location);
3818 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
3821 if (call_node->
block != NULL && PM_NODE_TYPE_P(call_node->
block, PM_BLOCK_NODE)) {
3824 pm_scope_node_init(call_node->
block, &next_scope_node, scope_node);
3826 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));
3827 pm_scope_node_destroy(&next_scope_node);
3828 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
3831 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3832 flags |= VM_CALL_VCALL;
3836 flags |= VM_CALL_ARGS_SIMPLE;
3840 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
3841 flags |= VM_CALL_FCALL;
3844 if (!popped && PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE)) {
3845 if (flags & VM_CALL_ARGS_BLOCKARG) {
3846 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
3847 if (flags & VM_CALL_ARGS_SPLAT) {
3848 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3849 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3851 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 3));
3852 PUSH_INSN(ret, location, pop);
3854 else if (flags & VM_CALL_ARGS_SPLAT) {
3855 PUSH_INSN(ret, location, dup);
3856 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3857 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3858 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 2));
3859 PUSH_INSN(ret, location, pop);
3862 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 1));
3866 if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
3867 PUSH_INSN(ret, location, splatkw);
3870 LABEL *not_basic_new = NEW_LABEL(location.
line);
3871 LABEL *not_basic_new_finish = NEW_LABEL(location.
line);
3873 bool inline_new = ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction &&
3874 method_id == rb_intern(
"new") &&
3875 call_node->
block == NULL &&
3876 (flags & VM_CALL_ARGS_BLOCKARG) == 0;
3879 if (LAST_ELEMENT(ret) == opt_new_prelude) {
3880 PUSH_INSN(ret, location, putnil);
3881 PUSH_INSN(ret, location, swap);
3884 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(swap), 0)->link);
3885 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(putnil), 0)->link);
3888 rb_callinfo_kwarg_retain(kw_arg);
3892 if (flags & VM_CALL_FORWARDING) {
3893 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc + 1, flags, kw_arg, 0);
3896 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc, flags, kw_arg, 0);
3899 PUSH_INSN2(ret, location, opt_new, ci, not_basic_new);
3900 LABEL_REF(not_basic_new);
3902 PUSH_SEND_R(ret, location, rb_intern(
"initialize"),
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags | VM_CALL_FCALL), kw_arg);
3903 PUSH_INSNL(ret, location, jump, not_basic_new_finish);
3905 PUSH_LABEL(ret, not_basic_new);
3907 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3908 PUSH_INSN(ret, location, swap);
3910 PUSH_LABEL(ret, not_basic_new_finish);
3911 PUSH_INSN(ret, location, pop);
3913 rb_callinfo_kwarg_release(kw_arg);
3916 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3919 if (block_iseq && ISEQ_BODY(block_iseq)->catch_table) {
3920 pm_compile_retry_end_label(iseq, ret, retry_end_l);
3921 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, start, retry_end_l, block_iseq, retry_end_l);
3924 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3925 PUSH_INSNL(ret, location, jump, end_label);
3926 PUSH_LABEL(ret, else_label);
3927 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 1,
"else", branches);
3928 PUSH_LABEL(ret, end_label);
3931 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
3932 PUSH_INSN(ret, location, pop);
3935 if (popped) PUSH_INSN(ret, location, pop);
3936 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
3946 const char *
type = (
const char *) (pm_parser_start(scope_node->parser) + node->
base.
location.
start + 1);
3966#define PUSH_VAL(type) (in_condition ? Qtrue : rb_iseq_defined_string(type))
3969 enum defined_type dtype = DEFINED_NOT_DEFINED;
3972 switch (PM_NODE_TYPE(node)) {
3977 dtype = DEFINED_NIL;
3980 case PM_INSTANCE_VARIABLE_READ_NODE: {
3984 ID name = pm_constant_id_lookup(scope_node,
cast->name);
3986 PUSH_INSN3(ret, location, definedivar,
ID2SYM(name), get_ivar_ic_value(iseq, name), PUSH_VAL(DEFINED_IVAR));
3991 case PM_LOCAL_VARIABLE_READ_NODE:
3994 case PM_IT_LOCAL_VARIABLE_READ_NODE:
3997 dtype = DEFINED_LVAR;
4000 case PM_GLOBAL_VARIABLE_READ_NODE: {
4004 ID name = pm_constant_id_lookup(scope_node,
cast->name);
4006 PUSH_INSN(ret, location, putnil);
4007 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR),
ID2SYM(name), PUSH_VAL(DEFINED_GVAR));
4012 case PM_CLASS_VARIABLE_READ_NODE: {
4016 ID name = pm_constant_id_lookup(scope_node,
cast->name);
4018 PUSH_INSN(ret, location, putnil);
4019 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR),
ID2SYM(name), PUSH_VAL(DEFINED_CVAR));
4024 case PM_CONSTANT_READ_NODE: {
4028 ID name = pm_constant_id_lookup(scope_node,
cast->name);
4030 PUSH_INSN(ret, location, putnil);
4031 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4039 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
4041 PUSH_INSN(ret, location, putnil);
4042 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
4046 case PM_SUPER_NODE: {
4051 if (
cast->block != NULL && !PM_NODE_TYPE_P(
cast->block, PM_BLOCK_ARGUMENT_NODE)) {
4052 dtype = DEFINED_EXPR;
4056 PUSH_INSN(ret, location, putnil);
4057 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4060 case PM_FORWARDING_SUPER_NODE: {
4065 if (
cast->block != NULL) {
4066 dtype = DEFINED_EXPR;
4070 PUSH_INSN(ret, location, putnil);
4071 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4078 dtype = DEFINED_SELF;
4084 dtype = DEFINED_TRUE;
4090 dtype = DEFINED_FALSE;
4093 case PM_CALL_AND_WRITE_NODE:
4096 case PM_CALL_OPERATOR_WRITE_NODE:
4099 case PM_CALL_OR_WRITE_NODE:
4102 case PM_CLASS_VARIABLE_AND_WRITE_NODE:
4105 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE:
4108 case PM_CLASS_VARIABLE_OR_WRITE_NODE:
4111 case PM_CLASS_VARIABLE_WRITE_NODE:
4114 case PM_CONSTANT_AND_WRITE_NODE:
4117 case PM_CONSTANT_OPERATOR_WRITE_NODE:
4120 case PM_CONSTANT_OR_WRITE_NODE:
4123 case PM_CONSTANT_PATH_AND_WRITE_NODE:
4126 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
4129 case PM_CONSTANT_PATH_OR_WRITE_NODE:
4132 case PM_CONSTANT_PATH_WRITE_NODE:
4135 case PM_CONSTANT_WRITE_NODE:
4138 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE:
4141 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE:
4144 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE:
4147 case PM_GLOBAL_VARIABLE_WRITE_NODE:
4150 case PM_INDEX_AND_WRITE_NODE:
4153 case PM_INDEX_OPERATOR_WRITE_NODE:
4156 case PM_INDEX_OR_WRITE_NODE:
4159 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE:
4162 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE:
4165 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE:
4168 case PM_INSTANCE_VARIABLE_WRITE_NODE:
4171 case PM_LOCAL_VARIABLE_AND_WRITE_NODE:
4174 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE:
4177 case PM_LOCAL_VARIABLE_OR_WRITE_NODE:
4180 case PM_LOCAL_VARIABLE_WRITE_NODE:
4183 case PM_MULTI_WRITE_NODE:
4186 dtype = DEFINED_ASGN;
4189 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
4192 case PM_ALIAS_METHOD_NODE:
4201 case PM_CASE_MATCH_NODE:
4213 case PM_DEFINED_NODE:
4216 case PM_FLIP_FLOP_NODE:
4228 case PM_IMAGINARY_NODE:
4231 case PM_INTEGER_NODE:
4234 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE:
4237 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
4240 case PM_INTERPOLATED_STRING_NODE:
4243 case PM_INTERPOLATED_SYMBOL_NODE:
4246 case PM_INTERPOLATED_X_STRING_NODE:
4249 case PM_LAMBDA_NODE:
4252 case PM_MATCH_LAST_LINE_NODE:
4255 case PM_MATCH_PREDICATE_NODE:
4258 case PM_MATCH_REQUIRED_NODE:
4261 case PM_MATCH_WRITE_NODE:
4264 case PM_MODULE_NODE:
4273 case PM_POST_EXECUTION_NODE:
4279 case PM_RATIONAL_NODE:
4285 case PM_REGULAR_EXPRESSION_NODE:
4288 case PM_RESCUE_MODIFIER_NODE:
4294 case PM_RETURN_NODE:
4297 case PM_SINGLETON_CLASS_NODE:
4300 case PM_SOURCE_ENCODING_NODE:
4303 case PM_SOURCE_FILE_NODE:
4306 case PM_SOURCE_LINE_NODE:
4309 case PM_STRING_NODE:
4312 case PM_SYMBOL_NODE:
4318 case PM_UNLESS_NODE:
4327 case PM_X_STRING_NODE:
4330 dtype = DEFINED_EXPR;
4333 case PM_BACK_REFERENCE_READ_NODE: {
4337 VALUE ref = pm_compile_back_reference_ref(scope_node, cast);
4339 PUSH_INSN(ret, location, putnil);
4340 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4344 case PM_NUMBERED_REFERENCE_READ_NODE: {
4348 VALUE ref = pm_compile_numbered_reference_ref(cast);
4350 PUSH_INSN(ret, location, putnil);
4351 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4356 case PM_CONSTANT_PATH_NODE: {
4360 ID name = pm_constant_id_lookup(scope_node,
cast->name);
4362 if (
cast->parent != NULL) {
4363 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4364 pm_compile_defined_expr0(iseq,
cast->parent, node_location, ret, popped, scope_node,
true, lfinish,
false);
4366 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4367 PM_COMPILE(
cast->parent);
4370 PUSH_INSN1(ret, location, putobject,
rb_cObject);
4373 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4377 case PM_BEGIN_NODE: {
4382 if (
cast->rescue_clause == NULL &&
cast->ensure_clause == NULL &&
cast->else_clause == NULL) {
4383 if (
cast->statements == NULL) {
4385 dtype = DEFINED_NIL;
4387 else if (
cast->statements->body.size == 1) {
4391 pm_compile_defined_expr0(iseq,
cast->statements->body.nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4397 dtype = DEFINED_EXPR;
4402 dtype = DEFINED_EXPR;
4407 case PM_PARENTHESES_NODE: {
4412 if (
cast->body == NULL) {
4414 dtype = DEFINED_NIL;
4416 else if (PM_NODE_TYPE_P(
cast->body, PM_STATEMENTS_NODE) && !PM_NODE_FLAG_P(cast, PM_PARENTHESES_NODE_FLAGS_MULTIPLE_STATEMENTS)) {
4419 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);
4425 dtype = DEFINED_EXPR;
4430 case PM_ARRAY_NODE: {
4435 if (
cast->elements.size > 0 && !lfinish[1]) {
4436 lfinish[1] = NEW_LABEL(location.
line);
4439 for (
size_t index = 0; index <
cast->elements.size; index++) {
4440 pm_compile_defined_expr0(iseq,
cast->elements.nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4441 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4444 dtype = DEFINED_EXPR;
4450 case PM_KEYWORD_HASH_NODE: {
4455 if (PM_NODE_TYPE_P(node, PM_HASH_NODE)) {
4462 if (elements->
size > 0 && !lfinish[1]) {
4463 lfinish[1] = NEW_LABEL(location.
line);
4466 for (
size_t index = 0; index < elements->
size; index++) {
4467 pm_compile_defined_expr0(iseq, elements->
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4468 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4471 dtype = DEFINED_EXPR;
4474 case PM_ASSOC_NODE: {
4479 pm_compile_defined_expr0(iseq,
cast->key, node_location, ret, popped, scope_node,
true, lfinish,
false);
4480 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4481 pm_compile_defined_expr0(iseq,
cast->value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4485 case PM_ASSOC_SPLAT_NODE: {
4490 if (
cast->value == NULL) {
4491 dtype = DEFINED_EXPR;
4495 pm_compile_defined_expr0(iseq,
cast->value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4498 case PM_IMPLICIT_NODE: {
4502 pm_compile_defined_expr0(iseq,
cast->value, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4505 case PM_CALL_NODE: {
4506#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE))
4512 if (BLOCK_P(cast)) {
4513 dtype = DEFINED_EXPR;
4517 if (
cast->receiver ||
cast->arguments || (
cast->block && PM_NODE_TYPE_P(
cast->block, PM_BLOCK_ARGUMENT_NODE))) {
4518 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4519 if (!lfinish[2]) lfinish[2] = NEW_LABEL(location.
line);
4522 if (
cast->arguments) {
4523 pm_compile_defined_expr0(iseq, (
const pm_node_t *)
cast->arguments, node_location, ret, popped, scope_node,
true, lfinish,
false);
4524 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4527 if (
cast->block && PM_NODE_TYPE_P(
cast->block, PM_BLOCK_ARGUMENT_NODE)) {
4528 pm_compile_defined_expr0(iseq,
cast->block, node_location, ret, popped, scope_node,
true, lfinish,
false);
4529 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4532 if (
cast->receiver) {
4536 pm_compile_defined_expr0(iseq,
cast->receiver, node_location, ret, popped, scope_node,
true, lfinish,
true);
4537 PUSH_INSNL(ret, location, branchunless, lfinish[2]);
4540 ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
4542 pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
4545 pm_compile_defined_expr0(iseq,
cast->receiver, node_location, ret, popped, scope_node,
true, lfinish,
false);
4546 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4547 PM_COMPILE(
cast->receiver);
4550 ID method_id = pm_constant_id_lookup(scope_node,
cast->name);
4552 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4553 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_METHOD),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4556 ID method_id = pm_constant_id_lookup(scope_node,
cast->name);
4558 PUSH_INSN(ret, location, putself);
4559 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4561 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_FUNC),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4568 case PM_ARGUMENTS_NODE: {
4573 for (
size_t index = 0; index <
cast->arguments.size; index++) {
4574 pm_compile_defined_expr0(iseq,
cast->arguments.nodes[index], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4575 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4578 dtype = DEFINED_EXPR;
4581 case PM_BLOCK_ARGUMENT_NODE:
4584 dtype = DEFINED_EXPR;
4586 case PM_FORWARDING_ARGUMENTS_NODE:
4589 dtype = DEFINED_EXPR;
4591 case PM_SPLAT_NODE: {
4596 if (
cast->expression == NULL) {
4597 dtype = DEFINED_EXPR;
4601 pm_compile_defined_expr0(iseq,
cast->expression, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4603 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4604 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4606 dtype = DEFINED_EXPR;
4609 case PM_SHAREABLE_CONSTANT_NODE:
4613 pm_compile_defined_expr0(iseq, ((
const pm_shareable_constant_node_t *) node)->write, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4616 case PM_BLOCK_LOCAL_VARIABLE_NODE:
4617 case PM_BLOCK_PARAMETER_NODE:
4618 case PM_BLOCK_PARAMETERS_NODE:
4619 case PM_FORWARDING_PARAMETER_NODE:
4620 case PM_IMPLICIT_REST_NODE:
4621 case PM_IT_PARAMETERS_NODE:
4622 case PM_PARAMETERS_NODE:
4623 case PM_KEYWORD_REST_PARAMETER_NODE:
4624 case PM_NO_KEYWORDS_PARAMETER_NODE:
4625 case PM_NO_BLOCK_PARAMETER_NODE:
4626 case PM_NUMBERED_PARAMETERS_NODE:
4627 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE:
4628 case PM_OPTIONAL_PARAMETER_NODE:
4629 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
4630 case PM_REQUIRED_PARAMETER_NODE:
4631 case PM_REST_PARAMETER_NODE:
4633 case PM_ALTERNATION_PATTERN_NODE:
4634 case PM_ARRAY_PATTERN_NODE:
4635 case PM_CAPTURE_PATTERN_NODE:
4636 case PM_FIND_PATTERN_NODE:
4637 case PM_HASH_PATTERN_NODE:
4638 case PM_PINNED_EXPRESSION_NODE:
4639 case PM_PINNED_VARIABLE_NODE:
4641 case PM_CALL_TARGET_NODE:
4642 case PM_CLASS_VARIABLE_TARGET_NODE:
4643 case PM_CONSTANT_PATH_TARGET_NODE:
4644 case PM_CONSTANT_TARGET_NODE:
4645 case PM_GLOBAL_VARIABLE_TARGET_NODE:
4646 case PM_INDEX_TARGET_NODE:
4647 case PM_INSTANCE_VARIABLE_TARGET_NODE:
4648 case PM_LOCAL_VARIABLE_TARGET_NODE:
4649 case PM_MULTI_TARGET_NODE:
4652 case PM_ENSURE_NODE:
4654 case PM_RESCUE_NODE:
4658 case PM_EMBEDDED_STATEMENTS_NODE:
4659 case PM_EMBEDDED_VARIABLE_NODE:
4660 case PM_ERROR_RECOVERY_NODE:
4661 case PM_PRE_EXECUTION_NODE:
4662 case PM_PROGRAM_NODE:
4664 case PM_STATEMENTS_NODE:
4665 rb_bug(
"Unreachable node in defined?: %s", pm_node_type(PM_NODE_TYPE(node)));
4669 PUSH_INSN1(ret, location, putobject, PUSH_VAL(dtype));
4678 pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4681 LABEL *lstart = NEW_LABEL(node_location->
line);
4682 LABEL *lend = NEW_LABEL(node_location->
line);
4685 rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
4687 const rb_iseq_t *rescue = new_child_iseq_with_callback(
4696 lstart->rescued = LABEL_RESCUE_BEG;
4697 lend->rescued = LABEL_RESCUE_END;
4699 APPEND_LABEL(ret, lcur, lstart);
4700 PUSH_LABEL(ret, lend);
4701 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
4711 lfinish[0] = NEW_LABEL(node_location->
line);
4716 pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish);
4720 ELEM_INSERT_NEXT(last, &new_insn_body(iseq, node_location->
line, node_location->
node_id, BIN(putnil), 0)->link);
4721 PUSH_INSN(ret, *node_location, swap);
4723 if (lfinish[2]) PUSH_LABEL(ret, lfinish[2]);
4724 PUSH_INSN(ret, *node_location, pop);
4725 PUSH_LABEL(ret, lfinish[1]);
4729 PUSH_LABEL(ret, lfinish[0]);
4740 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
4742 DECL_ANCHOR(ensure);
4745 if (enlp->erange != NULL) {
4746 DECL_ANCHOR(ensure_part);
4747 LABEL *lstart = NEW_LABEL(0);
4748 LABEL *lend = NEW_LABEL(0);
4750 add_ensure_range(iseq, enlp->erange, lstart, lend);
4752 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
4753 PUSH_LABEL(ensure_part, lstart);
4755 PM_COMPILE_INTO_ANCHOR(ensure_part, (
const pm_node_t *) enlp->ensure_node);
4756 PUSH_LABEL(ensure_part, lend);
4757 PUSH_SEQ(ensure, ensure_part);
4766 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
4767 PUSH_SEQ(ret, ensure);
4780 RUBY_ASSERT((constant_id & PM_SPECIAL_CONSTANT_FLAG) == 0);
4782 ID local = pm_constant_id_lookup(scope_node, constant_id);
4783 local_table_for_iseq->ids[local_index] = local;
4784 pm_index_lookup_table_insert(index_lookup_table, constant_id, local_index);
4793 local_table_for_iseq->ids[local_index] = local_name;
4794 pm_index_lookup_table_insert(index_lookup_table, special_id, local_index);
4806 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4809 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4810 if (!PM_NODE_FLAG_P(left, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4811 pm_insert_local_index(((
const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4816 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4817 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);
4821 if (node->
rest != NULL && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE)) {
4824 if (rest->expression != NULL) {
4825 RUBY_ASSERT(PM_NODE_TYPE_P(rest->expression, PM_REQUIRED_PARAMETER_NODE));
4827 if (!PM_NODE_FLAG_P(rest->expression, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4828 pm_insert_local_index(((
const pm_required_parameter_node_t *) rest->expression)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4834 for (
size_t index = 0; index < node->
rights.
size; index++) {
4837 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4838 if (!PM_NODE_FLAG_P(right, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4839 pm_insert_local_index(((
const pm_required_parameter_node_t *) right)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4844 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4845 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);
4861 PUSH_SETLOCAL(ret, location, index.index, index.level);
4876 bool has_rest = (node->
rest && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE) && (((
const pm_splat_node_t *) node->
rest)->expression) != NULL);
4879 int flag = (has_rest || has_rights) ? 1 : 0;
4882 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4885 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4889 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4900 RUBY_ASSERT(PM_NODE_TYPE_P(rest, PM_REQUIRED_PARAMETER_NODE));
4910 for (
size_t index = 0; index < node->
rights.
size; index++) {
4913 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4917 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4977 node->stack_index = state->stack_size + 1;
4978 node->stack_size = stack_size;
4979 node->position = state->position;
4982 if (state->head == NULL) {
4987 state->tail->next = node;
4991 state->stack_size += stack_size;
5004 if (state->stack_size == 0)
return;
5009 while (current != NULL) {
5010 VALUE offset =
INT2FIX(state->stack_size - current->stack_index + current->position);
5011 current->topn->operands[0] = offset;
5017 if (current->stack_size > 1) {
5018 INSN *insn = current->topn;
5020 for (
size_t index = 1; index < current->stack_size; index += 1) {
5024 insn = (
INSN *) element;
5027 insn->operands[0] = offset;
5032 current = current->next;
5034 SIZED_FREE(previous);
5074 switch (PM_NODE_TYPE(node)) {
5075 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5084 PUSH_SETLOCAL(writes, location, index.index, index.level);
5087 case PM_CLASS_VARIABLE_TARGET_NODE: {
5094 ID name = pm_constant_id_lookup(scope_node,
cast->name);
5097 PUSH_INSN2(writes, location, setclassvariable, operand, get_cvar_ic_value(iseq, name));
5100 case PM_CONSTANT_TARGET_NODE: {
5107 ID name = pm_constant_id_lookup(scope_node,
cast->name);
5110 PUSH_INSN1(writes, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5111 PUSH_INSN1(writes, location, setconstant, operand);
5114 case PM_GLOBAL_VARIABLE_TARGET_NODE: {
5121 ID name = pm_constant_id_lookup(scope_node,
cast->name);
5124 PUSH_INSN1(writes, location, setglobal, operand);
5127 case PM_INSTANCE_VARIABLE_TARGET_NODE: {
5134 ID name = pm_constant_id_lookup(scope_node,
cast->name);
5137 PUSH_INSN2(writes, location, setinstancevariable, operand, get_ivar_ic_value(iseq, name));
5140 case PM_CONSTANT_PATH_TARGET_NODE: {
5150 ID name = pm_constant_id_lookup(scope_node,
cast->name);
5152 if (
cast->parent != NULL) {
5153 pm_compile_node(iseq,
cast->parent, parents,
false, scope_node);
5156 PUSH_INSN1(parents, location, putobject,
rb_cObject);
5159 if (state == NULL) {
5160 PUSH_INSN(writes, location, swap);
5163 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5164 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5168 PUSH_INSN1(writes, location, setconstant, operand);
5170 if (state != NULL) {
5171 PUSH_INSN(cleanup, location, pop);
5176 case PM_CALL_TARGET_NODE: {
5186 ID method_id = pm_constant_id_lookup(scope_node,
cast->name);
5188 pm_compile_node(iseq,
cast->receiver, parents,
false, scope_node);
5190 LABEL *safe_label = NULL;
5191 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
5192 safe_label = NEW_LABEL(location.
line);
5193 PUSH_INSN(parents, location, dup);
5194 PUSH_INSNL(parents, location, branchnil, safe_label);
5197 if (state != NULL) {
5198 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5199 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5200 PUSH_INSN(writes, location, swap);
5203 int flags = VM_CALL_ARGS_SIMPLE;
5204 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) flags |= VM_CALL_FCALL;
5206 PUSH_SEND_WITH_FLAG(writes, location, method_id,
INT2FIX(1),
INT2FIX(flags));
5207 if (safe_label != NULL && state == NULL) PUSH_LABEL(writes, safe_label);
5208 PUSH_INSN(writes, location, pop);
5209 if (safe_label != NULL && state != NULL) PUSH_LABEL(writes, safe_label);
5211 if (state != NULL) {
5212 PUSH_INSN(cleanup, location, pop);
5217 case PM_INDEX_TARGET_NODE: {
5229 pm_compile_node(iseq,
cast->receiver, parents,
false, scope_node);
5233 int argc = pm_setup_args(
cast->arguments, (
const pm_node_t *)
cast->block, &flags, &kwargs, iseq, parents, scope_node, &location);
5235 if (state != NULL) {
5236 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5237 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), argc + 1);
5240 PUSH_INSN(writes, location, swap);
5243 for (
int index = 0; index < argc; index++) {
5244 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5246 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5254 int ci_argc = argc + 1;
5255 if (flags & VM_CALL_ARGS_SPLAT) {
5257 PUSH_INSN1(writes, location, newarray,
INT2FIX(1));
5258 PUSH_INSN(writes, location, concatarray);
5261 PUSH_SEND_R(writes, location, idASET,
INT2NUM(ci_argc), NULL,
INT2FIX(flags), kwargs);
5262 PUSH_INSN(writes, location, pop);
5264 if (state != NULL) {
5266 PUSH_INSN(writes, location, pop);
5269 for (
int index = 0; index < argc + 1; index++) {
5270 PUSH_INSN(cleanup, location, pop);
5276 case PM_MULTI_TARGET_NODE: {
5283 size_t before_position;
5284 if (state != NULL) {
5285 before_position = state->position;
5289 pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, scope_node, state);
5290 if (state != NULL) state->position = before_position;
5294 case PM_SPLAT_NODE: {
5302 if (
cast->expression != NULL) {
5303 pm_compile_target_node(iseq,
cast->expression, parents, writes, cleanup, scope_node, state);
5309 rb_bug(
"Unexpected node type: %s", pm_node_type(PM_NODE_TYPE(node)));
5327 switch (PM_NODE_TYPE(node)) {
5328 case PM_MULTI_TARGET_NODE: {
5330 lefts = &
cast->lefts;
5332 rights = &
cast->rights;
5335 case PM_MULTI_WRITE_NODE: {
5337 lefts = &
cast->lefts;
5339 rights = &
cast->rights;
5343 rb_bug(
"Unsupported node %s", pm_node_type(PM_NODE_TYPE(node)));
5347 bool has_rest = (rest != NULL) && PM_NODE_TYPE_P(rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) rest)->expression != NULL;
5348 bool has_posts = rights->
size > 0;
5353 PUSH_INSN2(writes, location, expandarray,
INT2FIX(lefts->
size),
INT2FIX((has_rest || has_posts) ? 1 : 0));
5359 if (state == NULL) state = &target_state;
5361 size_t base_position = state->position;
5362 size_t splat_position = (has_rest || has_posts) ? 1 : 0;
5365 for (
size_t index = 0; index < lefts->
size; index++) {
5367 state->position = lefts->
size - index + splat_position + base_position;
5368 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5374 state->position = 1 + rights->
size + base_position;
5380 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5385 if (!has_rest && rest != NULL) {
5389 for (
size_t index = 0; index < rights->
size; index++) {
5391 state->position = rights->
size - index + base_position;
5392 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5407 switch (PM_NODE_TYPE(node)) {
5408 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5411 PUSH_GETLOCAL(ret, location, 1, 0);
5412 pm_compile_target_node(iseq, node, ret, ret, ret, scope_node, NULL);
5415 case PM_CLASS_VARIABLE_TARGET_NODE:
5416 case PM_CONSTANT_TARGET_NODE:
5417 case PM_GLOBAL_VARIABLE_TARGET_NODE:
5418 case PM_INSTANCE_VARIABLE_TARGET_NODE:
5419 case PM_CONSTANT_PATH_TARGET_NODE:
5420 case PM_CALL_TARGET_NODE:
5421 case PM_INDEX_TARGET_NODE: {
5425 DECL_ANCHOR(writes);
5426 DECL_ANCHOR(cleanup);
5430 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
5432 PUSH_GETLOCAL(ret, location, 1, 0);
5435 PUSH_SEQ(ret, writes);
5436 PUSH_SEQ(ret, cleanup);
5438 pm_multi_target_state_update(&state);
5442 case PM_MULTI_TARGET_NODE: {
5443 DECL_ANCHOR(writes);
5444 DECL_ANCHOR(cleanup);
5446 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, NULL);
5448 LABEL *not_single = NEW_LABEL(location.
line);
5449 LABEL *not_ary = NEW_LABEL(location.
line);
5457 PUSH_GETLOCAL(ret, location, 1, 0);
5458 PUSH_INSN(ret, location, dup);
5459 PUSH_CALL(ret, location, idLength,
INT2FIX(0));
5460 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
5461 PUSH_CALL(ret, location, idEq,
INT2FIX(1));
5462 PUSH_INSNL(ret, location, branchunless, not_single);
5463 PUSH_INSN(ret, location, dup);
5464 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
5465 PUSH_CALL(ret, location, idAREF,
INT2FIX(1));
5466 PUSH_INSN1(ret, location, putobject,
rb_cArray);
5467 PUSH_INSN(ret, location, swap);
5468 PUSH_CALL(ret, location, rb_intern(
"try_convert"),
INT2FIX(1));
5469 PUSH_INSN(ret, location, dup);
5470 PUSH_INSNL(ret, location, branchunless, not_ary);
5471 PUSH_INSN(ret, location, swap);
5473 PUSH_LABEL(ret, not_ary);
5474 PUSH_INSN(ret, location, pop);
5476 PUSH_LABEL(ret, not_single);
5478 if (PM_NODE_TYPE_P(node, PM_SPLAT_NODE)) {
5480 PUSH_INSN2(ret, location, expandarray,
INT2FIX(0),
INT2FIX(
cast->expression == NULL ? 0 : 1));
5483 PUSH_SEQ(ret, writes);
5484 PUSH_SEQ(ret, cleanup);
5488 rb_bug(
"Unexpected node type for index in for node: %s", pm_node_type(PM_NODE_TYPE(node)));
5496 LABEL *lstart = NEW_LABEL(node_location->
line);
5497 LABEL *lend = NEW_LABEL(node_location->
line);
5498 LABEL *lcont = NEW_LABEL(node_location->
line);
5501 pm_scope_node_init((
const pm_node_t *)
cast->rescue_clause, &rescue_scope_node, scope_node);
5503 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
5507 pm_node_line_number_cached((
const pm_node_t *)
cast->rescue_clause, scope_node)
5510 pm_scope_node_destroy(&rescue_scope_node);
5512 lstart->rescued = LABEL_RESCUE_BEG;
5513 lend->rescued = LABEL_RESCUE_END;
5514 PUSH_LABEL(ret, lstart);
5516 bool prev_in_rescue = ISEQ_COMPILE_DATA(iseq)->in_rescue;
5517 ISEQ_COMPILE_DATA(iseq)->in_rescue =
true;
5519 if (
cast->statements != NULL) {
5520 PM_COMPILE_NOT_POPPED((
const pm_node_t *)
cast->statements);
5524 PUSH_INSN(ret, location, putnil);
5527 ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;
5528 PUSH_LABEL(ret, lend);
5530 if (
cast->else_clause != NULL) {
5531 if (!popped) PUSH_INSN(ret, *node_location, pop);
5535 PUSH_INSN(ret, *node_location, nop);
5536 PUSH_LABEL(ret, lcont);
5538 if (popped) PUSH_INSN(ret, *node_location, pop);
5539 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
5540 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
5549 if (statements != NULL) {
5550 location = PM_NODE_START_LOCATION(statements);
5553 location = *node_location;
5556 LABEL *lstart = NEW_LABEL(location.
line);
5558 LABEL *lcont = NEW_LABEL(location.
line);
5565 if (statements != NULL) {
5566 pm_compile_node(iseq, (
const pm_node_t *) statements, ensr,
true, scope_node);
5570 bool last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
5575 push_ensure_entry(iseq, &enl, &er, (
void *)
cast->ensure_clause);
5577 PUSH_LABEL(ret, lstart);
5578 if (
cast->rescue_clause != NULL) {
5579 pm_compile_rescue(iseq, cast, node_location, ret, popped | last_leave, scope_node);
5581 else if (
cast->statements != NULL) {
5582 pm_compile_node(iseq, (
const pm_node_t *)
cast->statements, ret, popped | last_leave, scope_node);
5584 else if (!(popped | last_leave)) {
5585 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
5588 PUSH_LABEL(ret, lend);
5589 PUSH_SEQ(ret, ensr);
5590 if (!popped && last_leave) PUSH_INSN(ret, *node_location, putnil);
5591 PUSH_LABEL(ret, lcont);
5592 if (last_leave) PUSH_INSN(ret, *node_location, pop);
5595 pm_scope_node_init((
const pm_node_t *)
cast->ensure_clause, &next_scope_node, scope_node);
5604 pm_scope_node_destroy(&next_scope_node);
5606 erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
5607 if (lstart->link.next != &lend->link) {
5609 PUSH_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, child_iseq, lcont);
5610 erange = erange->next;
5613 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
5624 !PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION) &&
5626 PM_NODE_TYPE_P(node->
receiver, PM_STRING_NODE) &&
5628 node->
block == NULL &&
5629 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5642 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
5643 ISEQ_BODY(iseq)->ic_size++;
5644 VALUE segments = rb_ary_new_from_args(1, name);
5646 PUSH_INSN1(ret, location, opt_getconstant_path, segments);
5649 PUSH_INSN(ret, location, putnil);
5650 PUSH_INSN1(ret, location, putobject,
Qtrue);
5651 PUSH_INSN1(ret, location, getconstant, name);
5665 switch (PM_NODE_TYPE(node)) {
5666 case PM_CONSTANT_READ_NODE: {
5670 rb_ary_unshift(parts, name);
5673 case PM_CONSTANT_PATH_NODE: {
5677 rb_ary_unshift(parts, name);
5678 if (
cast->parent == NULL) {
5679 rb_ary_unshift(parts,
ID2SYM(idNULL));
5683 node =
cast->parent;
5702 switch (PM_NODE_TYPE(node)) {
5703 case PM_CONSTANT_READ_NODE: {
5707 PUSH_INSN1(body, location, putobject,
Qtrue);
5708 PUSH_INSN1(body, location, getconstant, name);
5711 case PM_CONSTANT_PATH_NODE: {
5715 if (
cast->parent == NULL) {
5716 PUSH_INSN(body, location, pop);
5717 PUSH_INSN1(body, location, putobject,
rb_cObject);
5718 PUSH_INSN1(body, location, putobject,
Qtrue);
5719 PUSH_INSN1(body, location, getconstant, name);
5722 pm_compile_constant_path(iseq,
cast->parent, prefix, body,
false, scope_node);
5723 PUSH_INSN1(body, location, putobject,
Qfalse);
5724 PUSH_INSN1(body, location, getconstant, name);
5729 PM_COMPILE_INTO_ANCHOR(prefix, node);
5740 switch (PM_NODE_TYPE(node)) {
5744 case PM_SYMBOL_NODE:
5745 case PM_REGULAR_EXPRESSION_NODE:
5746 case PM_SOURCE_LINE_NODE:
5747 case PM_INTEGER_NODE:
5749 case PM_RATIONAL_NODE:
5750 case PM_IMAGINARY_NODE:
5751 case PM_SOURCE_ENCODING_NODE:
5752 return pm_static_literal_value(iseq, node, scope_node);
5753 case PM_STRING_NODE:
5754 return parse_static_literal_string(iseq, scope_node, node, &((
const pm_string_node_t *) node)->unescaped);
5755 case PM_ARRAY_NODE: {
5759 for (
size_t index = 0; index <
cast->elements.size; index++) {
5760 VALUE element = pm_compile_shareable_constant_literal(iseq,
cast->elements.nodes[index], scope_node);
5768 case PM_HASH_NODE: {
5772 for (
size_t index = 0; index <
cast->elements.size; index++) {
5774 if (!PM_NODE_TYPE_P(element, PM_ASSOC_NODE))
return Qundef;
5778 VALUE key = pm_compile_shareable_constant_literal(iseq, assoc->
key, scope_node);
5781 VALUE value = pm_compile_shareable_constant_literal(iseq, assoc->
value, scope_node);
5784 rb_hash_aset(result, key, value);
5801 VALUE literal = pm_compile_shareable_constant_literal(iseq, node, scope_node);
5804 PUSH_INSN1(ret, location, putobject, literal);
5809 switch (PM_NODE_TYPE(node)) {
5810 case PM_ARRAY_NODE: {
5814 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5817 for (
size_t index = 0; index <
cast->elements.size; index++) {
5818 pm_compile_shareable_constant_value(iseq,
cast->elements.nodes[index], shareability, path, ret, scope_node,
false);
5821 PUSH_INSN1(ret, location, newarray,
INT2FIX(
cast->elements.size));
5824 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5825 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5830 case PM_HASH_NODE: {
5834 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5837 pm_compile_hash_elements(iseq, (
const pm_node_t *) cast, &
cast->elements, shareability, path,
false, ret, scope_node);
5840 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5841 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5847 DECL_ANCHOR(value_seq);
5849 pm_compile_node(iseq, node, value_seq,
false, scope_node);
5850 if (PM_NODE_TYPE_P(node, PM_INTERPOLATED_STRING_NODE)) {
5851 PUSH_SEND_WITH_FLAG(value_seq, location, idUMinus,
INT2FIX(0),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5854 if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_LITERAL) {
5855 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5856 PUSH_SEQ(ret, value_seq);
5860 PUSH_INSN1(ret, location, putobject, path);
5861 PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"ensure_shareable"),
INT2FIX(2),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5863 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) {
5864 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5865 PUSH_SEQ(ret, value_seq);
5866 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable_copy"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5868 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_EVERYTHING) {
5869 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5870 PUSH_SEQ(ret, value_seq);
5871 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5887 ID name_id = pm_constant_id_lookup(scope_node, node->
name);
5889 if (shareability != 0) {
5890 pm_compile_shareable_constant_value(iseq, node->
value, shareability, rb_id2str(name_id), ret, scope_node,
true);
5893 PM_COMPILE_NOT_POPPED(node->
value);
5896 if (!popped) PUSH_INSN(ret, location, dup);
5897 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5900 PUSH_INSN1(ret, location, setconstant, operand);
5913 LABEL *end_label = NEW_LABEL(location.
line);
5915 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5916 if (!popped) PUSH_INSN(ret, location, dup);
5918 PUSH_INSNL(ret, location, branchunless, end_label);
5919 if (!popped) PUSH_INSN(ret, location, pop);
5921 if (shareability != 0) {
5922 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5925 PM_COMPILE_NOT_POPPED(node->
value);
5928 if (!popped) PUSH_INSN(ret, location, dup);
5929 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5930 PUSH_INSN1(ret, location, setconstant, name);
5931 PUSH_LABEL(ret, end_label);
5944 LABEL *set_label = NEW_LABEL(location.
line);
5945 LABEL *end_label = NEW_LABEL(location.
line);
5947 PUSH_INSN(ret, location, putnil);
5948 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name,
Qtrue);
5949 PUSH_INSNL(ret, location, branchunless, set_label);
5951 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5952 if (!popped) PUSH_INSN(ret, location, dup);
5954 PUSH_INSNL(ret, location, branchif, end_label);
5955 if (!popped) PUSH_INSN(ret, location, pop);
5956 PUSH_LABEL(ret, set_label);
5958 if (shareability != 0) {
5959 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5962 PM_COMPILE_NOT_POPPED(node->
value);
5965 if (!popped) PUSH_INSN(ret, location, dup);
5966 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5967 PUSH_INSN1(ret, location, setconstant, name);
5968 PUSH_LABEL(ret, end_label);
5983 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5985 if (shareability != 0) {
5986 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5989 PM_COMPILE_NOT_POPPED(node->
value);
5992 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5993 if (!popped) PUSH_INSN(ret, location, dup);
5995 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5996 PUSH_INSN1(ret, location, setconstant, name);
6007 rb_ary_push(parts, rb_id2str(pm_constant_id_lookup(scope_node, node->
name)));
6010 while (current != NULL && PM_NODE_TYPE_P(current, PM_CONSTANT_PATH_NODE)) {
6012 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node,
cast->name)));
6013 current =
cast->parent;
6016 if (current == NULL) {
6017 rb_ary_unshift(parts, rb_id2str(idNULL));
6019 else if (PM_NODE_TYPE_P(current, PM_CONSTANT_READ_NODE)) {
6020 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, ((
const pm_constant_read_node_t *) current)->name)));
6044 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6047 if (shareability != 0) {
6048 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6051 PM_COMPILE_NOT_POPPED(node->
value);
6055 PUSH_INSN(ret, location, swap);
6056 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6059 PUSH_INSN(ret, location, swap);
6060 PUSH_INSN1(ret, location, setconstant, name);
6077 PM_COMPILE_NOT_POPPED(target->
parent);
6080 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6083 PUSH_INSN(ret, location, dup);
6084 PUSH_INSN1(ret, location, putobject,
Qtrue);
6085 PUSH_INSN1(ret, location, getconstant, name);
6087 if (!popped) PUSH_INSN(ret, location, dup);
6088 PUSH_INSNL(ret, location, branchunless, lfin);
6090 if (!popped) PUSH_INSN(ret, location, pop);
6092 if (shareability != 0) {
6093 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6096 PM_COMPILE_NOT_POPPED(node->
value);
6100 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6103 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6104 PUSH_INSN(ret, location, swap);
6107 PUSH_INSN1(ret, location, setconstant, name);
6108 PUSH_LABEL(ret, lfin);
6110 if (!popped) PUSH_INSN(ret, location, swap);
6111 PUSH_INSN(ret, location, pop);
6125 LABEL *lassign = NEW_LABEL(location.
line);
6129 PM_COMPILE_NOT_POPPED(target->
parent);
6132 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6135 PUSH_INSN(ret, location, dup);
6136 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name,
Qtrue);
6137 PUSH_INSNL(ret, location, branchunless, lassign);
6139 PUSH_INSN(ret, location, dup);
6140 PUSH_INSN1(ret, location, putobject,
Qtrue);
6141 PUSH_INSN1(ret, location, getconstant, name);
6143 if (!popped) PUSH_INSN(ret, location, dup);
6144 PUSH_INSNL(ret, location, branchif, lfin);
6146 if (!popped) PUSH_INSN(ret, location, pop);
6147 PUSH_LABEL(ret, lassign);
6149 if (shareability != 0) {
6150 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6153 PM_COMPILE_NOT_POPPED(node->
value);
6157 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6160 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6161 PUSH_INSN(ret, location, swap);
6164 PUSH_INSN1(ret, location, setconstant, name);
6165 PUSH_LABEL(ret, lfin);
6167 if (!popped) PUSH_INSN(ret, location, swap);
6168 PUSH_INSN(ret, location, pop);
6185 PM_COMPILE_NOT_POPPED(target->
parent);
6188 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6191 PUSH_INSN(ret, location, dup);
6192 PUSH_INSN1(ret, location, putobject,
Qtrue);
6193 PUSH_INSN1(ret, location, getconstant, name);
6195 if (shareability != 0) {
6196 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6199 PM_COMPILE_NOT_POPPED(node->
value);
6202 PUSH_CALL(ret, location, method_id,
INT2FIX(1));
6203 PUSH_INSN(ret, location, swap);
6206 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6207 PUSH_INSN(ret, location, swap);
6210 PUSH_INSN1(ret, location, setconstant, name);
6219#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))
6238 bool trailing_comma =
false;
6240 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
6244 if (scope_node->parameters != NULL) {
6245 switch (PM_NODE_TYPE(scope_node->parameters)) {
6246 case PM_BLOCK_PARAMETERS_NODE: {
6248 parameters_node =
cast->parameters;
6249 block_locals = &
cast->locals;
6251 if (parameters_node) {
6252 if (parameters_node->
rest && PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE)) {
6253 trailing_comma =
true;
6258 case PM_PARAMETERS_NODE: {
6262 case PM_NUMBERED_PARAMETERS_NODE: {
6264 body->param.lead_num = maximum;
6265 body->param.flags.ambiguous_param0 = maximum == 1;
6268 case PM_IT_PARAMETERS_NODE:
6269 body->param.lead_num = 1;
6270 body->param.flags.ambiguous_param0 =
true;
6273 rb_bug(
"Unexpected node type for parameters: %s", pm_node_type(PM_NODE_TYPE(scope_node->parameters)));
6277 struct rb_iseq_param_keyword *keyword = NULL;
6279 if (parameters_node) {
6280 optionals_list = ¶meters_node->
optionals;
6281 requireds_list = ¶meters_node->
requireds;
6282 keywords_list = ¶meters_node->
keywords;
6283 posts_list = ¶meters_node->
posts;
6285 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))) {
6286 body->param.opt_num = 0;
6289 body->param.lead_num = 0;
6290 body->param.opt_num = 0;
6296 size_t locals_size = locals->
size;
6302 int table_size = (int) locals_size;
6306 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) table_size++;
6308 if (keywords_list && keywords_list->
size) {
6312 if (requireds_list) {
6313 for (
size_t i = 0; i < requireds_list->
size; i++) {
6318 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6321 else if (PM_NODE_TYPE_P(required, PM_REQUIRED_PARAMETER_NODE)) {
6322 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6331 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6339 if (optionals_list && optionals_list->
size) {
6340 for (
size_t i = 0; i < optionals_list->
size; i++) {
6342 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6352 if (parameters_node) {
6353 if (parameters_node->
rest) {
6354 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6368 if (PM_NODE_TYPE_P(parameters_node->
keyword_rest, PM_FORWARDING_PARAMETER_NODE)) {
6370 if (requireds_list->
size == 0 && optionals_list->
size == 0 && keywords_list->
size == 0) {
6371 ISEQ_BODY(iseq)->param.flags.use_block = TRUE;
6372 ISEQ_BODY(iseq)->param.flags.forwardable = TRUE;
6383 if (!kw_rest->name || PM_NODE_FLAG_P(kw_rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6391 for (
size_t i = 0; i < posts_list->
size; i++) {
6396 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE) || PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6402 if (keywords_list && keywords_list->
size) {
6403 for (
size_t i = 0; i < keywords_list->
size; i++) {
6405 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6411 if (parameters_node && parameters_node->
block && PM_NODE_TYPE_P(parameters_node->
block, PM_BLOCK_PARAMETER_NODE)) {
6414 if (PM_NODE_FLAG_P(block_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER) || !block_node->name) {
6422 local_table_for_iseq->size = table_size;
6426 pm_index_lookup_table_init(&index_lookup_table, (
int) pm_parser_constants_size(scope_node->parser), iseq);
6446 int local_index = 0;
6453 if (requireds_list && requireds_list->
size) {
6454 for (
size_t i = 0; i < requireds_list->
size; i++, local_index++) {
6462 switch (PM_NODE_TYPE(required)) {
6463 case PM_MULTI_TARGET_NODE: {
6466 local = rb_make_temporary_id(local_index);
6467 local_table_for_iseq->ids[local_index] = local;
6470 case PM_REQUIRED_PARAMETER_NODE: {
6475 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6476 ID local = pm_constant_id_lookup(scope_node, param->
name);
6477 local_table_for_iseq->ids[local_index] = local;
6480 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6486 rb_bug(
"Unsupported node in requireds in parameters %s", pm_node_type(PM_NODE_TYPE(required)));
6490 body->param.lead_num = (int) requireds_list->
size;
6491 body->param.flags.has_lead =
true;
6494 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6495 local_table_for_iseq->ids[local_index++] = idItImplicit;
6500 if (optionals_list && optionals_list->
size) {
6501 body->param.opt_num = (int) optionals_list->
size;
6502 body->param.flags.has_opt =
true;
6504 for (
size_t i = 0; i < optionals_list->
size; i++, local_index++) {
6508 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6509 ID local = pm_constant_id_lookup(scope_node, name);
6510 local_table_for_iseq->ids[local_index] = local;
6513 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6520 if (parameters_node && parameters_node->
rest) {
6521 body->param.rest_start = local_index;
6525 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6526 body->param.flags.has_rest =
true;
6534 if (PM_NODE_FLAG_P(parameters_node->
rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6535 ID local = pm_constant_id_lookup(scope_node, name);
6536 local_table_for_iseq->ids[local_index] = local;
6539 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6545 body->param.flags.anon_rest =
true;
6546 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index, &index_lookup_table, local_table_for_iseq);
6555 if (posts_list && posts_list->
size) {
6556 body->param.post_num = (int) posts_list->
size;
6557 body->param.post_start = local_index;
6558 body->param.flags.has_post =
true;
6560 for (
size_t i = 0; i < posts_list->
size; i++, local_index++) {
6568 switch (PM_NODE_TYPE(post_node)) {
6569 case PM_MULTI_TARGET_NODE: {
6572 local = rb_make_temporary_id(local_index);
6573 local_table_for_iseq->ids[local_index] = local;
6576 case PM_REQUIRED_PARAMETER_NODE: {
6581 if (PM_NODE_FLAG_P(param, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6582 ID local = pm_constant_id_lookup(scope_node, param->
name);
6583 local_table_for_iseq->ids[local_index] = local;
6586 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6591 rb_bug(
"Unsupported node in posts in parameters %s", pm_node_type(PM_NODE_TYPE(post_node)));
6599 if (keywords_list && keywords_list->
size) {
6600 if (keywords_list->
size > VM_CALL_KW_LEN_MAX) {
6601 COMPILE_ERROR(iseq, node_location->
line,
"too many keyword parameters (%d, maximum is %d)",
6602 (
int) keywords_list->
size, (
int) VM_CALL_KW_LEN_MAX);
6605 keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6606 keyword->num = (int) keywords_list->
size;
6611 for (
size_t i = 0; i < keywords_list->
size; i++) {
6617 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_REQUIRED_KEYWORD_PARAMETER_NODE)) {
6619 keyword->required_num++;
6620 ID local = pm_constant_id_lookup(scope_node, name);
6622 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6623 local_table_for_iseq->ids[local_index] = local;
6626 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6632 for (
size_t i = 0; i < keywords_list->
size; i++) {
6638 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_OPTIONAL_KEYWORD_PARAMETER_NODE)) {
6644 if (PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) {
6645 rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node));
6651 ID local = pm_constant_id_lookup(scope_node, name);
6652 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6653 local_table_for_iseq->ids[local_index] = local;
6656 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6666 for (
int i = 0; i <
RARRAY_LEN(default_values); i++) {
6668 if (dv == complex_mark) dv =
Qundef;
6672 keyword->default_values = dvs;
6676 keyword->bits_start = local_index;
6677 ID local = rb_make_temporary_id(local_index);
6678 local_table_for_iseq->ids[local_index] = local;
6681 body->param.keyword = keyword;
6682 body->param.flags.has_kw =
true;
6685 if (body->type == ISEQ_TYPE_BLOCK && local_index == 1 && requireds_list && requireds_list->
size == 1 && !trailing_comma) {
6686 body->param.flags.ambiguous_param0 =
true;
6689 if (parameters_node) {
6694 case PM_NO_KEYWORDS_PARAMETER_NODE: {
6697 body->param.flags.accepts_no_kwarg =
true;
6700 case PM_KEYWORD_REST_PARAMETER_NODE: {
6704 if (!body->param.flags.has_kw) {
6705 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6708 keyword->rest_start = local_index;
6709 body->param.flags.has_kwrest =
true;
6713 if (PM_NODE_FLAG_P(kw_rest_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6714 ID local = pm_constant_id_lookup(scope_node, constant_id);
6715 local_table_for_iseq->ids[local_index] = local;
6718 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6722 body->param.flags.anon_kwrest =
true;
6723 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index, &index_lookup_table, local_table_for_iseq);
6729 case PM_FORWARDING_PARAMETER_NODE: {
6732 if (!ISEQ_BODY(iseq)->param.
flags.forwardable) {
6734 body->param.rest_start = local_index;
6735 body->param.flags.has_rest =
true;
6736 body->param.flags.anon_rest =
true;
6737 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index++, &index_lookup_table, local_table_for_iseq);
6741 body->param.flags.has_kw =
false;
6742 body->param.flags.has_kwrest =
true;
6743 body->param.flags.anon_kwrest =
true;
6744 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6745 keyword->rest_start = local_index;
6746 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index++, &index_lookup_table, local_table_for_iseq);
6749 body->param.block_start = local_index;
6750 body->param.flags.has_block =
true;
6751 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index++, &index_lookup_table, local_table_for_iseq);
6755 pm_insert_local_special(PM_CONSTANT_DOT3, idDot3, local_index++, &index_lookup_table, local_table_for_iseq);
6759 rb_bug(
"node type %s not expected as keyword_rest", pm_node_type(PM_NODE_TYPE(parameters_node->
keyword_rest)));
6765 if (parameters_node->
block) {
6766 switch (PM_NODE_TYPE(parameters_node->
block)) {
6767 case PM_BLOCK_PARAMETER_NODE: {
6768 body->param.block_start = local_index;
6769 body->param.flags.has_block =
true;
6771 iseq_set_use_block(iseq);
6776 if (PM_NODE_FLAG_P(parameters_node->
block, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6777 ID local = pm_constant_id_lookup(scope_node, name);
6778 local_table_for_iseq->ids[local_index] = local;
6781 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6785 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index, &index_lookup_table, local_table_for_iseq);
6791 case PM_NO_BLOCK_PARAMETER_NODE: {
6792 body->param.flags.accepts_no_block =
true;
6796 rb_bug(
"node type %s not expected as block parameter", pm_node_type(PM_NODE_TYPE(parameters_node->
block)));
6813 if (requireds_list && requireds_list->
size) {
6814 for (
size_t i = 0; i < requireds_list->
size; i++) {
6820 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6821 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);
6827 if (posts_list && posts_list->
size) {
6828 for (
size_t i = 0; i < posts_list->
size; i++) {
6834 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
6835 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);
6841 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
6842 if (PM_NODE_TYPE_P(((
const pm_for_node_t *) scope_node->ast_node)->index, PM_LOCAL_VARIABLE_TARGET_NODE)) {
6843 body->param.lead_num++;
6846 body->param.rest_start = local_index;
6847 body->param.flags.has_rest =
true;
6850 ID local = rb_make_temporary_id(local_index);
6851 local_table_for_iseq->ids[local_index] = local;
6856 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_NUMBERED_PARAMETERS_NODE)) {
6859 for (
int i = 0; i < maximum; i++, local_index++) {
6860 const uint8_t param_name[] = {
'_',
'1' + i };
6861 pm_constant_id_t constant_id = pm_parser_constant_find(scope_node->parser, param_name, 2);
6862 RUBY_ASSERT(constant_id &&
"parser should fill in any gaps in numbered parameters");
6863 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6865 body->param.lead_num = maximum;
6866 body->param.flags.has_lead =
true;
6870 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6871 body->param.lead_num = 1;
6872 body->param.flags.has_lead =
true;
6883 if (block_locals && block_locals->
size) {
6884 for (
size_t i = 0; i < block_locals->
size; i++, local_index++) {
6886 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6891 if (scope_node->locals.
size) {
6892 for (
size_t i = 0; i < scope_node->locals.
size; i++) {
6896 if (!pm_index_lookup_table_lookup(&index_lookup_table, constant_id, &existing)) {
6897 ID local = pm_constant_id_lookup(scope_node, constant_id);
6898 local_table_for_iseq->ids[local_index] = local;
6899 pm_index_lookup_table_insert(&index_lookup_table, constant_id, local_index);
6911 iseq_calc_param_size(iseq);
6913 if (ISEQ_BODY(iseq)->param.
flags.forwardable) {
6916 ISEQ_BODY(iseq)->param.size += 1;
6920 iseq_set_local_table(iseq, local_table_for_iseq, 0);
6921 iseq_set_parameters_lvar_state(iseq);
6923 scope_node->local_table_for_iseq_size = local_table_for_iseq->size;
6925 if (keyword != NULL) {
6926 size_t keyword_start_index = keyword->bits_start - keyword->num;
6927 keyword->table = (
ID *)&ISEQ_BODY(iseq)->local_table[keyword_start_index];
6930 local_table_for_iseq = NULL;
6935 if (optionals_list && optionals_list->
size) {
6943 for (
size_t i = 0; i < optionals_list->
size; i++) {
6944 label = NEW_LABEL(location.
line);
6945 opt_table[i] = label;
6946 PUSH_LABEL(ret, label);
6948 PM_COMPILE_NOT_POPPED(optional_node);
6952 label = NEW_LABEL(location.
line);
6953 opt_table[optionals_list->
size] = label;
6954 PUSH_LABEL(ret, label);
6956 body->param.opt_table = (
const VALUE *) opt_table;
6959 if (keywords_list && keywords_list->
size) {
6960 size_t optional_index = 0;
6961 for (
size_t i = 0; i < keywords_list->
size; i++) {
6965 switch (PM_NODE_TYPE(keyword_parameter_node)) {
6966 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
6974 if (!PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) {
6975 LABEL *end_label = NEW_LABEL(location.
line);
6978 int kw_bits_idx = table_size - body->param.keyword->bits_start;
6979 PUSH_INSN2(ret, location, checkkeyword,
INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1),
INT2FIX(optional_index));
6980 PUSH_INSNL(ret, location, branchif, end_label);
6982 PUSH_SETLOCAL(ret, location, index.index, index.level);
6983 PUSH_LABEL(ret, end_label);
6988 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
6993 rb_bug(
"Unexpected keyword parameter node type %s", pm_node_type(PM_NODE_TYPE(keyword_parameter_node)));
6998 if (requireds_list && requireds_list->
size) {
6999 for (
size_t i = 0; i < requireds_list->
size; i++) {
7005 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
7006 PUSH_GETLOCAL(ret, location, table_size - (
int)i, 0);
7012 if (posts_list && posts_list->
size) {
7013 for (
size_t i = 0; i < posts_list->
size; i++) {
7019 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
7020 PUSH_GETLOCAL(ret, location, table_size - body->param.post_start - (
int) i, 0);
7026 switch (body->type) {
7027 case ISEQ_TYPE_PLAIN: {
7028 RUBY_ASSERT(PM_NODE_TYPE_P(scope_node->ast_node, PM_INTERPOLATED_REGULAR_EXPRESSION_NODE));
7031 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &
cast->parts, &location, ret, popped, scope_node);
7035 case ISEQ_TYPE_BLOCK: {
7036 LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
7037 LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
7040 start->rescued = LABEL_RESCUE_BEG;
7041 end->rescued = LABEL_RESCUE_END;
7047 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
7048 pm_compile_for_node_index(iseq, ((
const pm_for_node_t *) scope_node->ast_node)->index, ret, scope_node);
7052 PUSH_INSN(ret, block_location, nop);
7053 PUSH_LABEL(ret, start);
7055 if (scope_node->body != NULL) {
7056 switch (PM_NODE_TYPE(scope_node->ast_node)) {
7057 case PM_POST_EXECUTION_NODE: {
7059 PUSH_INSN1(ret, block_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7063 pm_scope_node_init((
const pm_node_t *)
cast->statements, &next_scope_node, scope_node);
7065 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(body->parent_iseq), ISEQ_TYPE_BLOCK, location.
line);
7066 pm_scope_node_destroy(&next_scope_node);
7068 PUSH_CALL_WITH_BLOCK(ret, block_location, id_core_set_postexe,
INT2FIX(0), block);
7071 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
7073 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &
cast->parts, &location, ret, popped, scope_node);
7077 pm_compile_node(iseq, scope_node->body, ret, popped, scope_node);
7082 PUSH_INSN(ret, block_location, putnil);
7085 PUSH_LABEL(ret, end);
7087 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7090 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
7091 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
7094 case ISEQ_TYPE_ENSURE: {
7095 const pm_node_location_t statements_location = (scope_node->body != NULL ? PM_NODE_START_LOCATION(scope_node->body) : location);
7096 iseq_set_exception_local_table(iseq);
7098 if (scope_node->body != NULL) {
7099 PM_COMPILE_POPPED((
const pm_node_t *) scope_node->body);
7102 PUSH_GETLOCAL(ret, statements_location, 1, 0);
7103 PUSH_INSN1(ret, statements_location,
throw,
INT2FIX(0));
7106 case ISEQ_TYPE_METHOD: {
7107 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7110 if (scope_node->body) {
7111 PM_COMPILE((
const pm_node_t *) scope_node->body);
7114 PUSH_INSN(ret, location, putnil);
7117 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7120 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7123 case ISEQ_TYPE_RESCUE: {
7124 iseq_set_exception_local_table(iseq);
7125 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_RESCUE_MODIFIER_NODE)) {
7127 LABEL *rescue_end = NEW_LABEL(location.
line);
7128 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7130 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
7131 PUSH_INSNL(ret, location, branchif, lab);
7132 PUSH_INSNL(ret, location, jump, rescue_end);
7133 PUSH_LABEL(ret, lab);
7135 PM_COMPILE((
const pm_node_t *) scope_node->body);
7136 PUSH_INSN(ret, location, leave);
7137 PUSH_LABEL(ret, rescue_end);
7138 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7141 PM_COMPILE((
const pm_node_t *) scope_node->ast_node);
7143 PUSH_INSN1(ret, location,
throw,
INT2FIX(0));
7148 if (scope_node->body) {
7149 PM_COMPILE((
const pm_node_t *) scope_node->body);
7152 PUSH_INSN(ret, location, putnil);
7157 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
7160 ISEQ_COMPILE_DATA(iseq)->last_line = end_location.
line;
7163 if (!PM_NODE_TYPE_P(scope_node->ast_node, PM_ENSURE_NODE)) {
7165 PUSH_INSN(ret, location, leave);
7174 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7178 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7179 PUSH_INSN1(ret, *location, putobject, operand);
7184 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7185 PUSH_INSN1(ret, *location, putobject, operand);
7188 PUSH_SEND(ret, *location, id_core_set_variable_alias,
INT2FIX(2));
7189 if (popped) PUSH_INSN(ret, *location, pop);
7195 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7196 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
7197 PM_COMPILE_NOT_POPPED(node->
new_name);
7198 PM_COMPILE_NOT_POPPED(node->
old_name);
7200 PUSH_SEND(ret, *location, id_core_set_method_alias,
INT2FIX(3));
7201 if (popped) PUSH_INSN(ret, *location, pop);
7221 const pm_node_type_t
type = PM_NODE_TYPE(nodes[1]);
7222 LABEL *end_label = NEW_LABEL(location->
line);
7224 for (
size_t index = 0; index + 1 < size; index += 2) {
7225 PM_COMPILE_NOT_POPPED(nodes[index]);
7231 .node_id = nodes[index + 1]->
node_id
7234 if (!popped) PUSH_INSN(ret, operator_location, dup);
7235 if (
type == PM_AND_NODE)
7237 PUSH_INSNL(ret, operator_location, branchunless, end_label);
7240 PUSH_INSNL(ret, operator_location, branchif, end_label);
7242 if (!popped) PUSH_INSN(ret, operator_location, pop);
7245 PM_COMPILE(nodes[size - 1]);
7246 PUSH_LABEL(ret, end_label);
7255 while (PM_NODE_TYPE_P(cursor, PM_AND_NODE)) {
7264 size_t index = size;
7266 while (PM_NODE_TYPE_P(cursor, PM_AND_NODE)) {
7268 nodes[--index] =
cast->right;
7269 nodes[--index] = cursor;
7270 cursor =
cast->left;
7274 pm_compile_logical_chain(iseq, size, nodes, location, ret, popped, scope_node);
7283 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
7288 if (elements->
size) {
7289 VALUE value = pm_static_literal_value(iseq, node, scope_node);
7291 PUSH_INSN1(ret, *location, duparray, value);
7294 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7312 const int max_new_array_size = 0x100;
7313 const unsigned int min_tmp_array_size = 0x40;
7315 int new_array_size = 0;
7316 bool first_chunk =
true;
7322 bool static_literal =
false;
7325#define FLUSH_CHUNK \
7326 if (new_array_size) { \
7327 if (first_chunk) PUSH_INSN1(ret, *location, newarray, INT2FIX(new_array_size)); \
7328 else PUSH_INSN1(ret, *location, pushtoarray, INT2FIX(new_array_size)); \
7329 first_chunk = false; \
7330 new_array_size = 0; \
7333 for (
size_t index = 0; index < elements->
size; index++) {
7336 if (PM_NODE_TYPE_P(element, PM_SPLAT_NODE)) {
7341 PM_COMPILE_NOT_POPPED(splat_element->
expression);
7344 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
7345 PUSH_GETLOCAL(ret, *location, index.index, index.level);
7351 PUSH_INSN1(ret, *location, splatarray,
Qtrue);
7352 first_chunk =
false;
7355 PUSH_INSN(ret, *location, concattoarray);
7358 static_literal =
false;
7360 else if (PM_NODE_TYPE_P(element, PM_KEYWORD_HASH_NODE)) {
7361 if (new_array_size == 0 && first_chunk) {
7362 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7363 first_chunk =
false;
7380 pm_compile_hash_elements(iseq, element, &keyword_hash->
elements, 0,
Qundef,
false, ret, scope_node);
7387 while (splats < keyword_hash->elements.
size && PM_NODE_TYPE_P(keyword_hash->
elements.
nodes[splats], PM_ASSOC_SPLAT_NODE)) splats++;
7390 PUSH_INSN(ret, *location, pushtoarraykwsplat);
7397 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) &&
7398 !PM_CONTAINER_P(element) &&
7400 ((index + min_tmp_array_size) < elements->
size)
7405 size_t right_index = index + 1;
7407 right_index < elements->size &&
7408 PM_NODE_FLAG_P(elements->
nodes[right_index], PM_NODE_FLAG_STATIC_LITERAL) &&
7409 !PM_CONTAINER_P(elements->
nodes[right_index])
7412 size_t tmp_array_size = right_index - index;
7413 if (tmp_array_size >= min_tmp_array_size) {
7417 for (; tmp_array_size; tmp_array_size--)
7418 rb_ary_push(tmp_array, pm_static_literal_value(iseq, elements->
nodes[index++], scope_node));
7426 PUSH_INSN1(ret, *location, duparray, tmp_array);
7427 first_chunk =
false;
7430 PUSH_INSN1(ret, *location, putobject, tmp_array);
7431 PUSH_INSN(ret, *location, concattoarray);
7435 PM_COMPILE_NOT_POPPED(element);
7436 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7437 static_literal =
true;
7440 PM_COMPILE_NOT_POPPED(element);
7441 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7442 static_literal =
false;
7447 if (popped) PUSH_INSN(ret, *location, pop);
7455 unsigned long throw_flag = 0;
7457 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
7459 LABEL *splabel = NEW_LABEL(0);
7460 PUSH_LABEL(ret, splabel);
7461 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7467 PUSH_INSN(ret, *location, putnil);
7470 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7471 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
7472 PUSH_ADJUST_RESTORE(ret, splabel);
7473 if (!popped) PUSH_INSN(ret, *location, putnil);
7479 if (!ISEQ_COMPILE_DATA(ip)) {
7484 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7485 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
7487 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
7490 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
7491 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7495 ip = ISEQ_BODY(ip)->parent_iseq;
7504 PUSH_INSN(ret, *location, putnil);
7507 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_BREAK));
7508 if (popped) PUSH_INSN(ret, *location, pop);
7513 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7520 ID method_id = pm_constant_id_lookup(scope_node, node->
name);
7526 const char *builtin_func;
7528 if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && (builtin_func = pm_iseq_builtin_function_name(scope_node, node->
receiver, method_id)) != NULL) {
7529 pm_compile_builtin_function_call(iseq, ret, scope_node, node, &location, popped, ISEQ_COMPILE_DATA(iseq)->current_block, builtin_func);
7533 LABEL *start = NEW_LABEL(location.
line);
7534 if (node->
block) PUSH_LABEL(ret, start);
7536 switch (method_id) {
7538 if (pm_opt_str_freeze_p(iseq, node)) {
7540 const struct rb_callinfo *callinfo = new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE);
7541 PUSH_INSN2(ret, location, opt_str_uminus, value, callinfo);
7542 if (popped) PUSH_INSN(ret, location, pop);
7548 if (pm_opt_str_freeze_p(iseq, node)) {
7550 const struct rb_callinfo *callinfo = new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE);
7551 PUSH_INSN2(ret, location, opt_str_freeze, value, callinfo);
7552 if (popped) PUSH_INSN(ret, location, pop);
7559 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
7560 PUSH_INSN(ret, location, putnil);
7564 PUSH_INSN(ret, location, putself);
7567 if ((method_id == idCall || method_id == idAREF || method_id == idYield || method_id == idEqq) && PM_NODE_TYPE_P(node->
receiver, PM_LOCAL_VARIABLE_READ_NODE)) {
7572 if (iseq_block_param_id_p(iseq, pm_constant_id_lookup(scope_node, read_node_cast->name), &idx, &level)) {
7573 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)));
7576 PM_COMPILE_NOT_POPPED(node->
receiver);
7580 PM_COMPILE_NOT_POPPED(node->
receiver);
7584 pm_compile_call(iseq, node, ret, popped, scope_node, method_id, start);
7593 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
7594 flag = VM_CALL_FCALL;
7597 PM_COMPILE_NOT_POPPED(node->
receiver);
7599 LABEL *safe_label = NULL;
7600 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
7601 safe_label = NEW_LABEL(location->
line);
7602 PUSH_INSN(ret, *location, dup);
7603 PUSH_INSNL(ret, *location, branchnil, safe_label);
7606 PUSH_INSN(ret, *location, dup);
7608 ID id_read_name = pm_constant_id_lookup(scope_node, node->
read_name);
7609 PUSH_SEND_WITH_FLAG(ret, *location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
7611 PM_COMPILE_NOT_POPPED(node->
value);
7613 PUSH_SEND(ret, *location, id_operator,
INT2FIX(1));
7616 PUSH_INSN(ret, *location, swap);
7617 PUSH_INSN1(ret, *location, topn,
INT2FIX(1));
7620 ID id_write_name = pm_constant_id_lookup(scope_node, node->
write_name);
7621 PUSH_SEND_WITH_FLAG(ret, *location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
7623 if (safe_label != NULL && popped) PUSH_LABEL(ret, safe_label);
7624 PUSH_INSN(ret, *location, pop);
7625 if (safe_label != NULL && !popped) PUSH_LABEL(ret, safe_label);
7648 switch (PM_NODE_TYPE(node)) {
7649 case PM_FLOAT_NODE: {
7650 key = pm_static_literal_value(iseq, node, scope_node);
7654 key = (
FIXABLE(intptr) ?
LONG2FIX((
long) intptr) : rb_dbl2big(intptr));
7660 case PM_INTEGER_NODE:
7662 case PM_SOURCE_LINE_NODE:
7663 case PM_SYMBOL_NODE:
7665 key = pm_static_literal_value(iseq, node, scope_node);
7667 case PM_STRING_NODE: {
7669 key = parse_static_literal_string(iseq, scope_node, node, &
cast->unescaped);
7676 cdhash_aset_if_missing(dispatch, key, (
VALUE)label);
7692 DECL_ANCHOR(cond_seq);
7697 DECL_ANCHOR(body_seq);
7701 LABEL *end_label = NEW_LABEL(location.
line);
7706 if (
cast->predicate == NULL) {
7712 if (PM_BRANCH_COVERAGE_P(iseq)) {
7713 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7714 branches = decl_branch_base(iseq, (
int)
cast->base.node_id, &case_location,
"case");
7720 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7724 int clause_lineno = pm_node_line_number_cached((
const pm_node_t *) clause, scope_node);
7725 LABEL *label = NEW_LABEL(clause_lineno);
7726 PUSH_LABEL(body_seq, label);
7729 if (PM_BRANCH_COVERAGE_P(iseq)) {
7731 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7734 if (clause->statements != NULL) {
7735 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7738 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7741 PUSH_INSNL(body_seq, location, jump, end_label);
7746 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7749 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7751 PUSH_INSN(cond_seq, cond_location, putnil);
7752 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7753 PUSH_INSN1(cond_seq, cond_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
7754 PUSH_INSNL(cond_seq, cond_location, branchif, label);
7757 LABEL *next_label = NEW_LABEL(pm_node_line_number_cached(condition, scope_node));
7758 pm_compile_branch_condition(iseq, cond_seq, condition, label, next_label, scope_node);
7759 PUSH_LABEL(cond_seq, next_label);
7766 if (PM_BRANCH_COVERAGE_P(iseq)) {
7769 if (
cast->else_clause == NULL) {
7770 branch_location = case_location;
7771 }
else if (
cast->else_clause->statements == NULL) {
7772 branch_location = pm_code_location(scope_node, (
const pm_node_t *)
cast->else_clause);
7774 branch_location = pm_code_location(scope_node, (
const pm_node_t *)
cast->else_clause->statements);
7777 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7781 if (
cast->else_clause != NULL) {
7782 pm_compile_node(iseq, (
const pm_node_t *)
cast->else_clause, cond_seq, popped, scope_node);
7785 PUSH_SYNTHETIC_PUTNIL(cond_seq, iseq);
7790 PUSH_INSNL(cond_seq, location, jump, end_label);
7791 PUSH_SEQ(ret, cond_seq);
7799 if (PM_BRANCH_COVERAGE_P(iseq)) {
7800 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7801 branches = decl_branch_base(iseq, (
int)
cast->base.node_id, &case_location,
"case");
7806 LABEL *else_label = NEW_LABEL(location.
line);
7814 if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
7815 dispatch = cdhash_new(0);
7826 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7831 LABEL *label = NEW_LABEL(clause_location.
line);
7836 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7843 if (dispatch !=
Qundef) {
7844 dispatch = pm_compile_case_node_dispatch(iseq, dispatch, condition, label, scope_node);
7847 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7848 PUSH_INSN(cond_seq, condition_location, dup);
7849 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7850 PUSH_INSN1(cond_seq, condition_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
7853 if (PM_NODE_TYPE_P(condition, PM_STRING_NODE)) {
7855 VALUE value = parse_static_literal_string(iseq, scope_node, condition, &string->
unescaped);
7856 PUSH_INSN1(cond_seq, condition_location, putobject, value);
7859 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7862 PUSH_INSN1(cond_seq, condition_location, topn,
INT2FIX(1));
7863 PUSH_SEND_WITH_FLAG(cond_seq, condition_location, idEqq,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
7866 PUSH_INSNL(cond_seq, condition_location, branchif, label);
7873 PUSH_LABEL(body_seq, label);
7874 PUSH_INSN(body_seq, clause_location, pop);
7877 if (PM_BRANCH_COVERAGE_P(iseq)) {
7879 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7882 if (clause->statements != NULL) {
7883 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7886 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7889 PUSH_INSNL(body_seq, clause_location, jump, end_label);
7896 PM_COMPILE_NOT_POPPED(
cast->predicate);
7900 if (dispatch !=
Qundef) {
7901 PUSH_INSN(ret, location, dup);
7903 PUSH_INSN2(ret, location, opt_case_dispatch, dispatch, else_label);
7904 LABEL_REF(else_label);
7907 PUSH_SEQ(ret, cond_seq);
7911 PUSH_LABEL(ret, else_label);
7913 if (
cast->else_clause != NULL) {
7915 PUSH_INSN(ret, else_location, pop);
7918 if (PM_BRANCH_COVERAGE_P(iseq)) {
7920 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7924 PUSH_INSNL(ret, else_location, jump, end_label);
7927 PUSH_INSN(ret, location, pop);
7930 if (PM_BRANCH_COVERAGE_P(iseq)) {
7931 add_trace_branch_coverage(iseq, ret, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7934 if (!popped) PUSH_INSN(ret, location, putnil);
7935 PUSH_INSNL(ret, location, jump, end_label);
7939 PUSH_SEQ(ret, body_seq);
7940 PUSH_LABEL(ret, end_label);
7949 DECL_ANCHOR(body_seq);
7954 DECL_ANCHOR(cond_seq);
7958 LABEL *end_label = NEW_LABEL(location->
line);
7963 LABEL *else_label = NEW_LABEL(location->
line);
7971 if (PM_BRANCH_COVERAGE_P(iseq)) {
7972 case_location = pm_code_location(scope_node, (
const pm_node_t *) node);
7973 branches = decl_branch_base(iseq, (
int) node->
base.
node_id, &case_location,
"case");
7983 if (in_single_pattern) {
7984 PUSH_INSN(ret, *location, putnil);
7985 PUSH_INSN(ret, *location, putnil);
7986 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7987 PUSH_INSN(ret, *location, putnil);
7991 PUSH_INSN(ret, *location, putnil);
8000 RUBY_ASSERT(PM_NODE_TYPE_P(condition, PM_IN_NODE));
8007 PUSH_INSN(body_seq, in_location, putnil);
8010 LABEL *body_label = NEW_LABEL(in_location.
line);
8011 PUSH_LABEL(body_seq, body_label);
8012 PUSH_INSN1(body_seq, in_location, adjuststack,
INT2FIX(in_single_pattern ? 6 : 2));
8015 if (PM_BRANCH_COVERAGE_P(iseq)) {
8017 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"in", branches);
8024 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
8027 PUSH_INSNL(body_seq, in_location, jump, end_label);
8028 LABEL *next_pattern_label = NEW_LABEL(pattern_location.
line);
8030 PUSH_INSN(cond_seq, pattern_location, dup);
8031 pm_compile_pattern(iseq, scope_node, in_node->
pattern, cond_seq, body_label, next_pattern_label, in_single_pattern,
true, 2);
8032 PUSH_LABEL(cond_seq, next_pattern_label);
8033 LABEL_UNREMOVABLE(next_pattern_label);
8042 PUSH_LABEL(cond_seq, else_label);
8043 PUSH_INSN(cond_seq, *location, pop);
8044 PUSH_INSN(cond_seq, *location, pop);
8047 if (PM_BRANCH_COVERAGE_P(iseq)) {
8049 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
8052 PM_COMPILE_INTO_ANCHOR(cond_seq, (
const pm_node_t *) else_node);
8053 PUSH_INSNL(cond_seq, *location, jump, end_label);
8054 PUSH_INSN(cond_seq, *location, putnil);
8055 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8060 PUSH_LABEL(cond_seq, else_label);
8063 add_trace_branch_coverage(iseq, cond_seq, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
8065 if (in_single_pattern) {
8066 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, cond_seq, end_label, popped);
8069 PUSH_INSN1(cond_seq, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8071 PUSH_INSN1(cond_seq, *location, topn,
INT2FIX(2));
8072 PUSH_SEND(cond_seq, *location, id_core_raise,
INT2FIX(2));
8074 PUSH_INSN1(cond_seq, *location, adjuststack,
INT2FIX(3));
8075 if (!popped) PUSH_INSN(cond_seq, *location, putnil);
8076 PUSH_INSNL(cond_seq, *location, jump, end_label);
8077 PUSH_INSN1(cond_seq, *location, dupn,
INT2FIX(1));
8078 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8085 PUSH_SEQ(ret, cond_seq);
8086 PUSH_SEQ(ret, body_seq);
8087 PUSH_LABEL(ret, end_label);
8095 LABEL *retry_label = NULL;
8096 LABEL *retry_end_l = NULL;
8098 if (node->
block != NULL) {
8099 previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8100 ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
8102 retry_label = NEW_LABEL(location->
line);
8103 retry_end_l = NEW_LABEL(location->
line);
8105 PUSH_LABEL(ret, retry_label);
8108 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8111 PUSH_INSN(ret, *location, putself);
8112 int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
8114 if (node->
block != NULL) {
8116 pm_scope_node_init((
const pm_node_t *) node->
block, &next_scope_node, scope_node);
8118 ISEQ_COMPILE_DATA(iseq)->current_block = block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8119 pm_scope_node_destroy(&next_scope_node);
8126 const rb_iseq_t *local_iseq = body->local_iseq;
8130 int depth = get_lvar_level(iseq);
8132 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8133 flag |= VM_CALL_FORWARDING;
8134 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
8135 PUSH_GETLOCAL(ret, *location, mult_local.index, mult_local.level);
8137 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, 0, flag, NULL, block != NULL);
8138 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, block);
8140 if (popped) PUSH_INSN(ret, *location, pop);
8142 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8147 if (local_body->param.flags.has_lead) {
8149 for (
int i = 0; i < local_body->param.lead_num; i++) {
8150 int idx = local_body->local_table_size - i;
8151 PUSH_GETLOCAL(args, *location, idx, depth);
8153 argc += local_body->param.lead_num;
8156 if (local_body->param.flags.has_opt) {
8158 for (
int j = 0; j < local_body->param.opt_num; j++) {
8159 int idx = local_body->local_table_size - (argc + j);
8160 PUSH_GETLOCAL(args, *location, idx, depth);
8162 argc += local_body->param.opt_num;
8165 if (local_body->param.flags.has_rest) {
8167 int idx = local_body->local_table_size - local_body->param.rest_start;
8168 PUSH_GETLOCAL(args, *location, idx, depth);
8169 PUSH_INSN1(args, *location, splatarray,
Qfalse);
8171 argc = local_body->param.rest_start + 1;
8172 flag |= VM_CALL_ARGS_SPLAT;
8175 if (local_body->param.flags.has_post) {
8177 int post_len = local_body->param.post_num;
8178 int post_start = local_body->param.post_start;
8181 for (; j < post_len; j++) {
8182 int idx = local_body->local_table_size - (post_start + j);
8183 PUSH_GETLOCAL(args, *location, idx, depth);
8186 if (local_body->param.flags.has_rest) {
8188 PUSH_INSN1(args, *location, newarray,
INT2FIX(j));
8189 PUSH_INSN(args, *location, concatarray);
8192 argc = post_len + post_start;
8196 const struct rb_iseq_param_keyword *
const local_keyword = local_body->param.keyword;
8197 if (local_body->param.flags.has_kw) {
8198 int local_size = local_body->local_table_size;
8201 PUSH_INSN1(args, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8203 if (local_body->param.flags.has_kwrest) {
8204 int idx = local_body->local_table_size - local_keyword->rest_start;
8205 PUSH_GETLOCAL(args, *location, idx, depth);
8207 PUSH_SEND(args, *location, rb_intern(
"dup"),
INT2FIX(0));
8210 PUSH_INSN1(args, *location, newhash,
INT2FIX(0));
8213 for (; i < local_keyword->num; ++i) {
8214 ID id = local_keyword->table[i];
8215 int idx = local_size - get_local_var_idx(local_iseq,
id);
8219 PUSH_INSN1(args, *location, putobject, operand);
8222 PUSH_GETLOCAL(args, *location, idx, depth);
8225 PUSH_SEND(args, *location, id_core_hash_merge_ptr,
INT2FIX(i * 2 + 1));
8226 flag |= VM_CALL_KW_SPLAT| VM_CALL_KW_SPLAT_MUT;
8228 else if (local_body->param.flags.has_kwrest) {
8229 int idx = local_body->local_table_size - local_keyword->rest_start;
8230 PUSH_GETLOCAL(args, *location, idx, depth);
8232 flag |= VM_CALL_KW_SPLAT;
8235 PUSH_SEQ(ret, args);
8238 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flag, NULL, block != NULL);
8239 PUSH_INSN2(ret, *location, invokesuper, callinfo, block);
8242 if (node->
block != NULL) {
8243 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8244 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, block, retry_end_l);
8245 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8248 if (popped) PUSH_INSN(ret, *location, pop);
8254 LABEL *matched_label = NEW_LABEL(location->
line);
8255 LABEL *unmatched_label = NEW_LABEL(location->
line);
8256 LABEL *done_label = NEW_LABEL(location->
line);
8260 PUSH_INSN(ret, *location, putnil);
8261 PUSH_INSN(ret, *location, putnil);
8262 PUSH_INSN1(ret, *location, putobject,
Qfalse);
8263 PUSH_INSN(ret, *location, putnil);
8264 PUSH_INSN(ret, *location, putnil);
8268 PM_COMPILE_NOT_POPPED(node->
value);
8272 PUSH_INSN(ret, *location, dup);
8279 pm_compile_pattern(iseq, scope_node, node->
pattern, ret, matched_label, unmatched_label,
true,
true, 2);
8284 PUSH_LABEL(ret, unmatched_label);
8285 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, ret, done_label, popped);
8289 PUSH_LABEL(ret, matched_label);
8290 PUSH_INSN1(ret, *location, adjuststack,
INT2FIX(6));
8291 if (!popped) PUSH_INSN(ret, *location, putnil);
8292 PUSH_INSNL(ret, *location, jump, done_label);
8294 PUSH_LABEL(ret, done_label);
8300 LABEL *fail_label = NEW_LABEL(location->
line);
8301 LABEL *end_label = NEW_LABEL(location->
line);
8312 PUSH_INSN1(ret, *location, getglobal, operand);
8315 PUSH_INSN(ret, *location, dup);
8316 PUSH_INSNL(ret, *location, branchunless, fail_label);
8322 if (targets_count == 1) {
8324 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8331 PUSH_INSN1(ret, *location, putobject, operand);
8334 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8335 PUSH_LABEL(ret, fail_label);
8336 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8337 if (popped) PUSH_INSN(ret, *location, pop);
8341 DECL_ANCHOR(fail_anchor);
8345 for (
size_t targets_index = 0; targets_index < targets_count; targets_index++) {
8347 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8352 if (((
size_t) targets_index) < (targets_count - 1)) {
8353 PUSH_INSN(ret, *location, dup);
8358 PUSH_INSN1(ret, *location, putobject, operand);
8361 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8362 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8364 PUSH_INSN(fail_anchor, *location, putnil);
8365 PUSH_SETLOCAL(fail_anchor, *location, index.index, index.level);
8369 PUSH_INSNL(ret, *location, jump, end_label);
8373 PUSH_LABEL(ret, fail_label);
8374 PUSH_INSN(ret, *location, pop);
8375 PUSH_SEQ(ret, fail_anchor);
8378 PUSH_LABEL(ret, end_label);
8379 if (popped) PUSH_INSN(ret, *location, pop);
8385 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
8386 LABEL *splabel = NEW_LABEL(0);
8387 PUSH_LABEL(ret, splabel);
8393 PUSH_INSN(ret, *location, putnil);
8395 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8397 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8398 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8400 PUSH_ADJUST_RESTORE(ret, splabel);
8401 if (!popped) PUSH_INSN(ret, *location, putnil);
8403 else if (ISEQ_COMPILE_DATA(iseq)->end_label && can_add_ensure_iseq(iseq)) {
8404 LABEL *splabel = NEW_LABEL(0);
8406 PUSH_LABEL(ret, splabel);
8407 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8413 PUSH_INSN(ret, *location, putnil);
8416 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8417 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
8418 PUSH_ADJUST_RESTORE(ret, splabel);
8419 splabel->unremovable = FALSE;
8421 if (!popped) PUSH_INSN(ret, *location, putnil);
8425 unsigned long throw_flag = 0;
8428 if (!ISEQ_COMPILE_DATA(ip)) {
8433 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
8434 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8438 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8441 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8442 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8446 ip = ISEQ_BODY(ip)->parent_iseq;
8454 PUSH_INSN(ret, *location, putnil);
8457 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_NEXT));
8458 if (popped) PUSH_INSN(ret, *location, pop);
8461 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8472 while (PM_NODE_TYPE_P(cursor, PM_OR_NODE)) {
8481 size_t index = size;
8483 while (PM_NODE_TYPE_P(cursor, PM_OR_NODE)) {
8485 nodes[--index] =
cast->right;
8486 nodes[--index] = cursor;
8487 cursor =
cast->left;
8491 pm_compile_logical_chain(iseq, size, nodes, location, ret, popped, scope_node);
8498 if (ISEQ_COMPILE_DATA(iseq)->redo_label && can_add_ensure_iseq(iseq)) {
8499 LABEL *splabel = NEW_LABEL(0);
8501 PUSH_LABEL(ret, splabel);
8502 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8503 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8505 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
8506 PUSH_ADJUST_RESTORE(ret, splabel);
8507 if (!popped) PUSH_INSN(ret, *location, putnil);
8509 else if (ISEQ_BODY(iseq)->
type != ISEQ_TYPE_EVAL && ISEQ_COMPILE_DATA(iseq)->start_label && can_add_ensure_iseq(iseq)) {
8510 LABEL *splabel = NEW_LABEL(0);
8512 PUSH_LABEL(ret, splabel);
8513 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8514 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8516 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8517 PUSH_ADJUST_RESTORE(ret, splabel);
8518 if (!popped) PUSH_INSN(ret, *location, putnil);
8524 if (!ISEQ_COMPILE_DATA(ip)) {
8529 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8532 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8535 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8536 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8540 ip = ISEQ_BODY(ip)->parent_iseq;
8544 PUSH_INSN(ret, *location, putnil);
8545 PUSH_INSN1(ret, *location,
throw,
INT2FIX(VM_THROW_NO_ESCAPE_FLAG | TAG_REDO));
8546 if (popped) PUSH_INSN(ret, *location, pop);
8549 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8557 iseq_set_exception_local_table(iseq);
8561 LABEL *exception_match_label = NEW_LABEL(location->
line);
8562 LABEL *rescue_end_label = NEW_LABEL(location->
line);
8572 if (exceptions->
size > 0) {
8573 for (
size_t index = 0; index < exceptions->
size; index++) {
8574 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8575 PM_COMPILE(exceptions->
nodes[index]);
8576 int checkmatch_flags = VM_CHECKMATCH_TYPE_RESCUE;
8577 if (PM_NODE_TYPE_P(exceptions->
nodes[index], PM_SPLAT_NODE)) {
8578 checkmatch_flags |= VM_CHECKMATCH_ARRAY;
8580 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(checkmatch_flags));
8581 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8585 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8587 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
8588 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8593 PUSH_INSNL(ret, *location, jump, rescue_end_label);
8598 PUSH_LABEL(ret, exception_match_label);
8605 DECL_ANCHOR(writes);
8606 DECL_ANCHOR(cleanup);
8608 pm_compile_target_node(iseq, node->
reference, ret, writes, cleanup, scope_node, NULL);
8609 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8611 PUSH_SEQ(ret, writes);
8612 PUSH_SEQ(ret, cleanup);
8622 LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
8623 ISEQ_COMPILE_DATA(iseq)->end_label = NULL;
8628 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
8631 PUSH_INSN(ret, *location, putnil);
8634 PUSH_INSN(ret, *location, leave);
8640 PUSH_LABEL(ret, rescue_end_label);
8645 PUSH_GETLOCAL(ret, *location, 1, 0);
8653 enum rb_iseq_type
type = ISEQ_BODY(iseq)->type;
8657 enum rb_iseq_type parent_type = ISEQ_BODY(parent_iseq)->type;
8658 while (parent_type == ISEQ_TYPE_RESCUE || parent_type == ISEQ_TYPE_ENSURE) {
8659 if (!(parent_iseq = ISEQ_BODY(parent_iseq)->parent_iseq))
break;
8660 parent_type = ISEQ_BODY(parent_iseq)->type;
8663 switch (parent_type) {
8665 case ISEQ_TYPE_MAIN:
8667 rb_warn(
"argument of top-level return is ignored");
8669 if (parent_iseq == iseq) {
8670 type = ISEQ_TYPE_METHOD;
8677 if (
type == ISEQ_TYPE_METHOD) {
8678 splabel = NEW_LABEL(0);
8679 PUSH_LABEL(ret, splabel);
8680 PUSH_ADJUST(ret, *location, 0);
8683 if (arguments != NULL) {
8684 PM_COMPILE_NOT_POPPED((
const pm_node_t *) arguments);
8687 PUSH_INSN(ret, *location, putnil);
8690 if (
type == ISEQ_TYPE_METHOD && can_add_ensure_iseq(iseq)) {
8691 pm_add_ensure_iseq(ret, iseq, 1, scope_node);
8693 PUSH_INSN(ret, *location, leave);
8694 PUSH_ADJUST_RESTORE(ret, splabel);
8695 if (!popped) PUSH_INSN(ret, *location, putnil);
8698 PUSH_INSN1(ret, *location,
throw,
INT2FIX(TAG_RETURN));
8699 if (popped) PUSH_INSN(ret, *location, pop);
8708 LABEL *retry_label = NEW_LABEL(location->
line);
8709 LABEL *retry_end_l = NEW_LABEL(location->
line);
8711 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8713 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NULL;
8715 PUSH_LABEL(ret, retry_label);
8716 PUSH_INSN(ret, *location, putself);
8720 int argc = pm_setup_args(node->
arguments, node->
block, &flags, &keywords, iseq, ret, scope_node, location);
8721 bool is_forwardable = (node->
arguments != NULL) && PM_NODE_FLAG_P(node->
arguments, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING);
8722 flags |= VM_CALL_SUPER | VM_CALL_FCALL;
8724 if (node->
block && PM_NODE_TYPE_P(node->
block, PM_BLOCK_NODE)) {
8726 pm_scope_node_init(node->
block, &next_scope_node, scope_node);
8728 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8729 pm_scope_node_destroy(&next_scope_node);
8733 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8736 if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
8737 PUSH_INSN(args, *location, splatkw);
8740 PUSH_SEQ(ret, args);
8741 if (is_forwardable && ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8742 flags |= VM_CALL_FORWARDING;
8745 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8746 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, current_block);
8751 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8752 PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
8757 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8759 if (popped) PUSH_INSN(ret, *location, pop);
8760 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8761 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);
8767 switch (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
type) {
8769 case ISEQ_TYPE_MAIN:
8770 case ISEQ_TYPE_CLASS:
8771 COMPILE_ERROR(iseq, location->
line,
"Invalid yield");
8781 argc = pm_setup_args(node->
arguments, NULL, &flags, &keywords, iseq, ret, scope_node, location);
8784 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, FALSE);
8785 PUSH_INSN1(ret, *location, invokeblock, callinfo);
8787 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8788 if (popped) PUSH_INSN(ret, *location, pop);
8791 for (
const rb_iseq_t *tmp_iseq = iseq; tmp_iseq != ISEQ_BODY(iseq)->local_iseq; level++) {
8792 tmp_iseq = ISEQ_BODY(tmp_iseq)->parent_iseq;
8795 if (level > 0) access_outer_variables(iseq, level, rb_intern(
"yield"),
true);
8812 int lineno = (int) location.
line;
8814 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)) {
8819 lineno = (int) PM_NODE_START_LINE_COLUMN(((
const pm_begin_node_t *) node)->rescue_clause).line;
8822 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_NEWLINE) && ISEQ_COMPILE_DATA(iseq)->last_line != lineno) {
8828 ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8829 if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8830 event |= RUBY_EVENT_COVERAGE_LINE;
8832 PUSH_TRACE(ret, event);
8835 switch (PM_NODE_TYPE(node)) {
8836 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
8841 case PM_ALIAS_METHOD_NODE:
8844 pm_compile_alias_method_node(iseq, (
const pm_alias_method_node_t *) node, &location, ret, popped, scope_node);
8849 pm_compile_and_node(iseq, (
const pm_and_node_t *) node, &location, ret, popped, scope_node);
8851 case PM_ARGUMENTS_NODE: {
8861 if (elements->
size == 1) {
8864 PM_COMPILE(elements->
nodes[0]);
8867 pm_compile_array_node(iseq, (
const pm_node_t *) cast, elements, &location, ret, popped, scope_node);
8871 case PM_ARRAY_NODE: {
8875 pm_compile_array_node(iseq, (
const pm_node_t *) cast, &
cast->elements, &location, ret, popped, scope_node);
8878 case PM_ASSOC_NODE: {
8886 PM_COMPILE(
cast->key);
8887 PM_COMPILE(
cast->value);
8891 case PM_ASSOC_SPLAT_NODE: {
8899 if (
cast->value != NULL) {
8900 PM_COMPILE(
cast->value);
8903 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
8904 PUSH_GETLOCAL(ret, location, index.index, index.level);
8909 case PM_BACK_REFERENCE_READ_NODE: {
8914 VALUE backref = pm_compile_back_reference_ref(scope_node, cast);
8916 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), backref);
8920 case PM_BEGIN_NODE: {
8925 if (
cast->ensure_clause) {
8928 pm_compile_ensure(iseq, cast, &location, ret, popped, scope_node);
8930 else if (
cast->rescue_clause) {
8932 pm_compile_rescue(iseq, cast, &location, ret, popped, scope_node);
8937 if (
cast->statements != NULL) {
8941 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8946 case PM_BLOCK_ARGUMENT_NODE: {
8951 if (
cast->expression != NULL) {
8952 PM_COMPILE(
cast->expression);
8956 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
8957 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(local_index.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(local_index.level));
8967 pm_compile_break_node(iseq, (
const pm_break_node_t *) node, &location, ret, popped, scope_node);
8978 pm_compile_call_node(iseq, (
const pm_call_node_t *) node, ret, popped, scope_node);
8980 case PM_CALL_AND_WRITE_NODE: {
8984 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);
8987 case PM_CALL_OR_WRITE_NODE: {
8991 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);
8994 case PM_CALL_OPERATOR_WRITE_NODE:
9009 pm_compile_case_node(iseq, (
const pm_case_node_t *) node, &location, ret, popped, scope_node);
9011 case PM_CASE_MATCH_NODE:
9020 pm_compile_case_match_node(iseq, (
const pm_case_match_node_t *) node, &location, ret, popped, scope_node);
9022 case PM_CLASS_NODE: {
9027 ID class_id = pm_constant_id_lookup(scope_node,
cast->name);
9028 VALUE class_name =
rb_str_freeze(rb_sprintf(
"<class:%"PRIsVALUE
">", rb_id2str(class_id)));
9031 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9033 const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(&next_scope_node, class_name, ISEQ_TYPE_CLASS, location.
line);
9034 pm_scope_node_destroy(&next_scope_node);
9037 const int flags = VM_DEFINECLASS_TYPE_CLASS |
9038 (
cast->superclass ? VM_DEFINECLASS_FLAG_HAS_SUPERCLASS : 0) |
9039 pm_compile_class_path(iseq,
cast->constant_path, &location, ret,
false, scope_node);
9041 if (
cast->superclass) {
9042 PM_COMPILE_NOT_POPPED(
cast->superclass);
9045 PUSH_INSN(ret, location, putnil);
9050 PUSH_INSN3(ret, location, defineclass, operand, class_iseq,
INT2FIX(flags));
9054 if (popped) PUSH_INSN(ret, location, pop);
9057 case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
9061 LABEL *end_label = NEW_LABEL(location.
line);
9063 ID name_id = pm_constant_id_lookup(scope_node,
cast->name);
9066 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9067 if (!popped) PUSH_INSN(ret, location, dup);
9069 PUSH_INSNL(ret, location, branchunless, end_label);
9070 if (!popped) PUSH_INSN(ret, location, pop);
9072 PM_COMPILE_NOT_POPPED(
cast->value);
9073 if (!popped) PUSH_INSN(ret, location, dup);
9075 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9076 PUSH_LABEL(ret, end_label);
9080 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
9085 ID name_id = pm_constant_id_lookup(scope_node,
cast->name);
9088 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9089 PM_COMPILE_NOT_POPPED(
cast->value);
9091 ID method_id = pm_constant_id_lookup(scope_node,
cast->binary_operator);
9092 int flags = VM_CALL_ARGS_SIMPLE;
9093 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9095 if (!popped) PUSH_INSN(ret, location, dup);
9096 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9100 case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
9104 LABEL *end_label = NEW_LABEL(location.
line);
9105 LABEL *start_label = NEW_LABEL(location.
line);
9107 ID name_id = pm_constant_id_lookup(scope_node,
cast->name);
9110 PUSH_INSN(ret, location, putnil);
9111 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name,
Qtrue);
9112 PUSH_INSNL(ret, location, branchunless, start_label);
9114 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9115 if (!popped) PUSH_INSN(ret, location, dup);
9117 PUSH_INSNL(ret, location, branchif, end_label);
9118 if (!popped) PUSH_INSN(ret, location, pop);
9120 PUSH_LABEL(ret, start_label);
9121 PM_COMPILE_NOT_POPPED(
cast->value);
9122 if (!popped) PUSH_INSN(ret, location, dup);
9124 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9125 PUSH_LABEL(ret, end_label);
9129 case PM_CLASS_VARIABLE_READ_NODE: {
9134 ID name = pm_constant_id_lookup(scope_node,
cast->name);
9135 PUSH_INSN2(ret, location, getclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9139 case PM_CLASS_VARIABLE_WRITE_NODE: {
9143 PM_COMPILE_NOT_POPPED(
cast->value);
9144 if (!popped) PUSH_INSN(ret, location, dup);
9146 ID name = pm_constant_id_lookup(scope_node,
cast->name);
9147 PUSH_INSN2(ret, location, setclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9151 case PM_CONSTANT_PATH_NODE: {
9156 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache && ((parts = pm_constant_path_parts(node, scope_node)) !=
Qnil)) {
9157 ISEQ_BODY(iseq)->ic_size++;
9159 PUSH_INSN1(ret, location, opt_getconstant_path, parts);
9162 DECL_ANCHOR(prefix);
9165 pm_compile_constant_path(iseq, node, prefix, body, popped, scope_node);
9166 if (LIST_INSN_SIZE_ZERO(prefix)) {
9167 PUSH_INSN(ret, location, putnil);
9170 PUSH_SEQ(ret, prefix);
9173 PUSH_SEQ(ret, body);
9176 if (popped) PUSH_INSN(ret, location, pop);
9179 case PM_CONSTANT_PATH_AND_WRITE_NODE: {
9183 pm_compile_constant_path_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9186 case PM_CONSTANT_PATH_OR_WRITE_NODE: {
9190 pm_compile_constant_path_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9193 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
9197 pm_compile_constant_path_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9200 case PM_CONSTANT_PATH_WRITE_NODE: {
9204 pm_compile_constant_path_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9207 case PM_CONSTANT_READ_NODE: {
9213 pm_compile_constant_read(iseq, name, &
cast->base.location, location.
node_id, ret, scope_node);
9214 if (popped) PUSH_INSN(ret, location, pop);
9218 case PM_CONSTANT_AND_WRITE_NODE: {
9222 pm_compile_constant_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9225 case PM_CONSTANT_OR_WRITE_NODE: {
9229 pm_compile_constant_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9232 case PM_CONSTANT_OPERATOR_WRITE_NODE: {
9236 pm_compile_constant_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9239 case PM_CONSTANT_WRITE_NODE: {
9243 pm_compile_constant_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9253 ID method_name = pm_constant_id_lookup(scope_node,
cast->name);
9256 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9258 rb_iseq_t *method_iseq = NEW_ISEQ(&next_scope_node, rb_id2str(method_name), ISEQ_TYPE_METHOD, location.
line);
9259 pm_scope_node_destroy(&next_scope_node);
9261 if (
cast->receiver) {
9262 PM_COMPILE_NOT_POPPED(
cast->receiver);
9263 PUSH_INSN2(ret, location, definesmethod,
ID2SYM(method_name), method_iseq);
9266 PUSH_INSN2(ret, location, definemethod,
ID2SYM(method_name), method_iseq);
9271 PUSH_INSN1(ret, location, putobject,
ID2SYM(method_name));
9276 case PM_DEFINED_NODE: {
9280 pm_compile_defined_expr(iseq,
cast->value, &location, ret, popped, scope_node,
false);
9283 case PM_EMBEDDED_STATEMENTS_NODE: {
9288 if (
cast->statements != NULL) {
9292 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9295 if (popped) PUSH_INSN(ret, location, pop);
9298 case PM_EMBEDDED_VARIABLE_NODE: {
9302 PM_COMPILE(
cast->variable);
9305 case PM_FALSE_NODE: {
9309 PUSH_INSN1(ret, location, putobject,
Qfalse);
9313 case PM_ENSURE_NODE: {
9316 if (
cast->statements != NULL) {
9322 case PM_ELSE_NODE: {
9327 if (
cast->statements != NULL) {
9331 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9336 case PM_FLIP_FLOP_NODE: {
9341 LABEL *final_label = NEW_LABEL(location.
line);
9342 LABEL *then_label = NEW_LABEL(location.
line);
9343 LABEL *else_label = NEW_LABEL(location.
line);
9345 pm_compile_flip_flop(cast, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
9347 PUSH_LABEL(ret, then_label);
9348 PUSH_INSN1(ret, location, putobject,
Qtrue);
9349 PUSH_INSNL(ret, location, jump, final_label);
9350 PUSH_LABEL(ret, else_label);
9351 PUSH_INSN1(ret, location, putobject,
Qfalse);
9352 PUSH_LABEL(ret, final_label);
9356 case PM_FLOAT_NODE: {
9361 PUSH_INSN1(ret, location, putobject, operand);
9370 LABEL *retry_label = NEW_LABEL(location.
line);
9371 LABEL *retry_end_l = NEW_LABEL(location.
line);
9374 PUSH_LABEL(ret, retry_label);
9375 PM_COMPILE_NOT_POPPED(
cast->collection);
9380 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9382 const rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location.
line);
9383 pm_scope_node_destroy(&next_scope_node);
9385 const rb_iseq_t *prev_block = ISEQ_COMPILE_DATA(iseq)->current_block;
9386 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
9390 PUSH_SEND_WITH_BLOCK(ret, location, idEach,
INT2FIX(0), child_iseq);
9391 pm_compile_retry_end_label(iseq, ret, retry_end_l);
9393 if (popped) PUSH_INSN(ret, location, pop);
9394 ISEQ_COMPILE_DATA(iseq)->current_block = prev_block;
9395 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
9398 case PM_FORWARDING_ARGUMENTS_NODE:
9399 rb_bug(
"Cannot compile a ForwardingArgumentsNode directly\n");
9401 case PM_FORWARDING_SUPER_NODE:
9409 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
9413 LABEL *end_label = NEW_LABEL(location.
line);
9416 PUSH_INSN1(ret, location, getglobal, name);
9417 if (!popped) PUSH_INSN(ret, location, dup);
9419 PUSH_INSNL(ret, location, branchunless, end_label);
9420 if (!popped) PUSH_INSN(ret, location, pop);
9422 PM_COMPILE_NOT_POPPED(
cast->value);
9423 if (!popped) PUSH_INSN(ret, location, dup);
9425 PUSH_INSN1(ret, location, setglobal, name);
9426 PUSH_LABEL(ret, end_label);
9430 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
9436 PUSH_INSN1(ret, location, getglobal, name);
9437 PM_COMPILE_NOT_POPPED(
cast->value);
9439 ID method_id = pm_constant_id_lookup(scope_node,
cast->binary_operator);
9440 int flags = VM_CALL_ARGS_SIMPLE;
9441 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9443 if (!popped) PUSH_INSN(ret, location, dup);
9444 PUSH_INSN1(ret, location, setglobal, name);
9448 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
9452 LABEL *set_label = NEW_LABEL(location.
line);
9453 LABEL *end_label = NEW_LABEL(location.
line);
9455 PUSH_INSN(ret, location, putnil);
9458 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name,
Qtrue);
9459 PUSH_INSNL(ret, location, branchunless, set_label);
9461 PUSH_INSN1(ret, location, getglobal, name);
9462 if (!popped) PUSH_INSN(ret, location, dup);
9464 PUSH_INSNL(ret, location, branchif, end_label);
9465 if (!popped) PUSH_INSN(ret, location, pop);
9467 PUSH_LABEL(ret, set_label);
9468 PM_COMPILE_NOT_POPPED(
cast->value);
9469 if (!popped) PUSH_INSN(ret, location, dup);
9471 PUSH_INSN1(ret, location, setglobal, name);
9472 PUSH_LABEL(ret, end_label);
9476 case PM_GLOBAL_VARIABLE_READ_NODE: {
9482 PUSH_INSN1(ret, location, getglobal, name);
9483 if (popped) PUSH_INSN(ret, location, pop);
9487 case PM_GLOBAL_VARIABLE_WRITE_NODE: {
9491 PM_COMPILE_NOT_POPPED(
cast->value);
9492 if (!popped) PUSH_INSN(ret, location, dup);
9494 ID name = pm_constant_id_lookup(scope_node,
cast->name);
9495 PUSH_INSN1(ret, location, setglobal,
ID2SYM(name));
9499 case PM_HASH_NODE: {
9505 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9512 if (
cast->elements.size == 0) {
9513 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
9516 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9517 PUSH_INSN1(ret, location, duphash, value);
9538 for (
size_t index = 0; index < elements->
size; index++) {
9539 PM_COMPILE_POPPED(elements->
nodes[index]);
9543 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9559 pm_compile_conditional(iseq, &location, PM_IF_NODE, (
const pm_node_t *) cast,
cast->statements,
cast->subsequent,
cast->predicate, ret, popped, scope_node);
9562 case PM_IMAGINARY_NODE: {
9567 PUSH_INSN1(ret, location, putobject, operand);
9571 case PM_IMPLICIT_NODE: {
9581 PM_COMPILE(
cast->value);
9587 rb_bug(
"Should not ever enter an in node directly");
9590 case PM_INDEX_OPERATOR_WRITE_NODE: {
9594 pm_compile_index_operator_write_node(iseq, cast, &location, ret, popped, scope_node);
9597 case PM_INDEX_AND_WRITE_NODE: {
9601 pm_compile_index_control_flow_write_node(iseq, node,
cast->receiver,
cast->arguments,
cast->block,
cast->value, &location, ret, popped, scope_node);
9604 case PM_INDEX_OR_WRITE_NODE: {
9608 pm_compile_index_control_flow_write_node(iseq, node,
cast->receiver,
cast->arguments,
cast->block,
cast->value, &location, ret, popped, scope_node);
9611 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
9615 LABEL *end_label = NEW_LABEL(location.
line);
9617 ID name_id = pm_constant_id_lookup(scope_node,
cast->name);
9620 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9621 if (!popped) PUSH_INSN(ret, location, dup);
9623 PUSH_INSNL(ret, location, branchunless, end_label);
9624 if (!popped) PUSH_INSN(ret, location, pop);
9626 PM_COMPILE_NOT_POPPED(
cast->value);
9627 if (!popped) PUSH_INSN(ret, location, dup);
9629 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9630 PUSH_LABEL(ret, end_label);
9634 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
9639 ID name_id = pm_constant_id_lookup(scope_node,
cast->name);
9642 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9643 PM_COMPILE_NOT_POPPED(
cast->value);
9645 ID method_id = pm_constant_id_lookup(scope_node,
cast->binary_operator);
9646 int flags = VM_CALL_ARGS_SIMPLE;
9647 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9649 if (!popped) PUSH_INSN(ret, location, dup);
9650 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9654 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
9658 LABEL *end_label = NEW_LABEL(location.
line);
9660 ID name_id = pm_constant_id_lookup(scope_node,
cast->name);
9663 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9664 if (!popped) PUSH_INSN(ret, location, dup);
9666 PUSH_INSNL(ret, location, branchif, end_label);
9667 if (!popped) PUSH_INSN(ret, location, pop);
9669 PM_COMPILE_NOT_POPPED(
cast->value);
9670 if (!popped) PUSH_INSN(ret, location, dup);
9672 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9673 PUSH_LABEL(ret, end_label);
9677 case PM_INSTANCE_VARIABLE_READ_NODE: {
9682 ID name = pm_constant_id_lookup(scope_node,
cast->name);
9683 PUSH_INSN2(ret, location, getinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9687 case PM_INSTANCE_VARIABLE_WRITE_NODE: {
9691 PM_COMPILE_NOT_POPPED(
cast->value);
9692 if (!popped) PUSH_INSN(ret, location, dup);
9694 ID name = pm_constant_id_lookup(scope_node,
cast->name);
9695 PUSH_INSN2(ret, location, setinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9699 case PM_INTEGER_NODE: {
9704 PUSH_INSN1(ret, location, putobject, operand);
9708 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
9711 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9713 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9714 PUSH_INSN1(ret, location, putobject, regexp);
9721 PUSH_INSN1(ret, location, getglobal,
rb_id2sym(idLASTLINE));
9722 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9723 if (popped) PUSH_INSN(ret, location, pop);
9727 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
9730 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ONCE)) {
9731 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9733 int ise_index = ISEQ_BODY(iseq)->ise_size++;
9736 pm_scope_node_init(node, &next_scope_node, scope_node);
9738 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, location.
line);
9739 pm_scope_node_destroy(&next_scope_node);
9741 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
9742 PUSH_INSN2(ret, location, once, block_iseq,
INT2FIX(ise_index));
9743 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9745 if (popped) PUSH_INSN(ret, location, pop);
9749 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9751 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9752 PUSH_INSN1(ret, location, putobject, regexp);
9757 if (popped) PUSH_INSN(ret, location, pop);
9762 case PM_INTERPOLATED_STRING_NODE: {
9765 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9767 VALUE string = pm_static_literal_value(iseq, node, scope_node);
9769 if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN)) {
9770 PUSH_INSN1(ret, location, putobject,
string);
9772 else if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE)) {
9773 PUSH_INSN1(ret, location, dupstring,
string);
9776 PUSH_INSN1(ret, location, dupchilledstring,
string);
9782 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));
9783 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9784 if (popped) PUSH_INSN(ret, location, pop);
9789 case PM_INTERPOLATED_SYMBOL_NODE: {
9793 int length = pm_interpolated_node_compile(iseq, &
cast->parts, &location, ret, popped, scope_node, NULL, NULL,
false,
false);
9796 PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9800 PUSH_INSN(ret, location, intern);
9803 PUSH_INSN(ret, location, pop);
9808 case PM_INTERPOLATED_X_STRING_NODE: {
9813 PUSH_INSN(ret, location, putself);
9815 int length = pm_interpolated_node_compile(iseq, &
cast->parts, &location, ret,
false, scope_node, NULL, NULL,
false,
false);
9816 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9818 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
9819 if (popped) PUSH_INSN(ret, location, pop);
9823 case PM_IT_LOCAL_VARIABLE_READ_NODE: {
9830 while (current_scope_node) {
9831 if (current_scope_node->parameters && PM_NODE_TYPE_P(current_scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
9832 PUSH_GETLOCAL(ret, location, current_scope_node->local_table_for_iseq_size, level);
9836 current_scope_node = current_scope_node->previous;
9839 rb_bug(
"Local `it` does not exist");
9844 case PM_KEYWORD_HASH_NODE: {
9850 bool has_splat =
false;
9851 for (
size_t index = 0; index < elements->
size; index++) {
9852 if (PM_NODE_TYPE_P(elements->
nodes[index], PM_ASSOC_SPLAT_NODE)) {
9859 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9864 PM_COMPILE(element);
9867 if (!popped) PUSH_INSN1(ret, location, newhash,
INT2FIX(elements->
size * 2));
9871 case PM_LAMBDA_NODE: {
9877 pm_scope_node_init(node, &next_scope_node, scope_node);
9879 int opening_lineno = pm_location_line_number_cached(&
cast->opening_loc, scope_node);
9880 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, opening_lineno);
9881 pm_scope_node_destroy(&next_scope_node);
9884 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9885 PUSH_CALL_WITH_BLOCK(ret, location, idLambda, argc, block);
9888 if (popped) PUSH_INSN(ret, location, pop);
9891 case PM_LOCAL_VARIABLE_AND_WRITE_NODE: {
9895 LABEL *end_label = NEW_LABEL(location.
line);
9898 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9899 if (!popped) PUSH_INSN(ret, location, dup);
9901 PUSH_INSNL(ret, location, branchunless, end_label);
9902 if (!popped) PUSH_INSN(ret, location, pop);
9904 PM_COMPILE_NOT_POPPED(
cast->value);
9905 if (!popped) PUSH_INSN(ret, location, dup);
9907 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9908 PUSH_LABEL(ret, end_label);
9912 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
9918 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9920 PM_COMPILE_NOT_POPPED(
cast->value);
9922 ID method_id = pm_constant_id_lookup(scope_node,
cast->binary_operator);
9923 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
9925 if (!popped) PUSH_INSN(ret, location, dup);
9926 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9930 case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
9935 LABEL *set_label = NEW_LABEL(location.
line);
9936 LABEL *end_label = NEW_LABEL(location.
line);
9938 PUSH_INSN1(ret, location, putobject,
Qtrue);
9939 PUSH_INSNL(ret, location, branchunless, set_label);
9942 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9943 if (!popped) PUSH_INSN(ret, location, dup);
9945 PUSH_INSNL(ret, location, branchif, end_label);
9946 if (!popped) PUSH_INSN(ret, location, pop);
9948 PUSH_LABEL(ret, set_label);
9949 PM_COMPILE_NOT_POPPED(
cast->value);
9950 if (!popped) PUSH_INSN(ret, location, dup);
9952 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9953 PUSH_LABEL(ret, end_label);
9957 case PM_LOCAL_VARIABLE_READ_NODE: {
9963 PUSH_GETLOCAL(ret, location, index.index, index.level);
9968 case PM_LOCAL_VARIABLE_WRITE_NODE: {
9972 PM_COMPILE_NOT_POPPED(
cast->value);
9973 if (!popped) PUSH_INSN(ret, location, dup);
9976 PUSH_SETLOCAL(ret, location, index.index, index.level);
9979 case PM_MATCH_LAST_LINE_NODE: {
9982 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9984 PUSH_INSN1(ret, location, putobject, regexp);
9986 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9987 if (popped) PUSH_INSN(ret, location, pop);
9991 case PM_MATCH_PREDICATE_NODE: {
9998 PUSH_INSN(ret, location, putnil);
10001 PM_COMPILE_NOT_POPPED(
cast->value);
10002 PUSH_INSN(ret, location, dup);
10006 LABEL *matched_label = NEW_LABEL(location.
line);
10007 LABEL *unmatched_label = NEW_LABEL(location.
line);
10008 LABEL *done_label = NEW_LABEL(location.
line);
10009 pm_compile_pattern(iseq, scope_node,
cast->pattern, ret, matched_label, unmatched_label,
false,
true, 2);
10013 PUSH_LABEL(ret, unmatched_label);
10014 PUSH_INSN(ret, location, pop);
10015 PUSH_INSN(ret, location, pop);
10017 if (!popped) PUSH_INSN1(ret, location, putobject,
Qfalse);
10018 PUSH_INSNL(ret, location, jump, done_label);
10019 PUSH_INSN(ret, location, putnil);
10023 PUSH_LABEL(ret, matched_label);
10024 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(2));
10025 if (!popped) PUSH_INSN1(ret, location, putobject,
Qtrue);
10026 PUSH_INSNL(ret, location, jump, done_label);
10028 PUSH_LABEL(ret, done_label);
10031 case PM_MATCH_REQUIRED_NODE:
10043 pm_compile_match_required_node(iseq, (
const pm_match_required_node_t *) node, &location, ret, popped, scope_node);
10045 case PM_MATCH_WRITE_NODE:
10054 pm_compile_match_write_node(iseq, (
const pm_match_write_node_t *) node, &location, ret, popped, scope_node);
10056 case PM_ERROR_RECOVERY_NODE:
10057 rb_bug(
"A pm_error_recovery_node_t should not exist in prism's AST.");
10059 case PM_MODULE_NODE: {
10064 ID module_id = pm_constant_id_lookup(scope_node,
cast->name);
10065 VALUE module_name =
rb_str_freeze(rb_sprintf(
"<module:%"PRIsVALUE
">", rb_id2str(module_id)));
10068 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10070 const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&next_scope_node, module_name, ISEQ_TYPE_CLASS, location.
line);
10071 pm_scope_node_destroy(&next_scope_node);
10073 const int flags = VM_DEFINECLASS_TYPE_MODULE | pm_compile_class_path(iseq,
cast->constant_path, &location, ret,
false, scope_node);
10074 PUSH_INSN(ret, location, putnil);
10075 PUSH_INSN3(ret, location, defineclass,
ID2SYM(module_id), module_iseq,
INT2FIX(flags));
10078 if (popped) PUSH_INSN(ret, location, pop);
10081 case PM_REQUIRED_PARAMETER_NODE: {
10087 PUSH_SETLOCAL(ret, location, index.index, index.level);
10090 case PM_MULTI_WRITE_NODE: {
10101 DECL_ANCHOR(writes);
10102 DECL_ANCHOR(cleanup);
10105 state.position = popped ? 0 : 1;
10106 pm_compile_multi_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
10108 PM_COMPILE_NOT_POPPED(
cast->value);
10109 if (!popped) PUSH_INSN(ret, location, dup);
10111 PUSH_SEQ(ret, writes);
10112 if (!popped && state.stack_size >= 1) {
10115 PUSH_INSN1(ret, location, setn,
INT2FIX(state.stack_size));
10120 pm_multi_target_state_update(&state);
10122 PUSH_SEQ(ret, cleanup);
10131 pm_compile_next_node(iseq, (
const pm_next_node_t *) node, &location, ret, popped, scope_node);
10133 case PM_NIL_NODE: {
10137 PUSH_INSN(ret, location, putnil);
10142 case PM_NO_BLOCK_PARAMETER_NODE: {
10145 ISEQ_BODY(iseq)->param.flags.accepts_no_block = TRUE;
10148 case PM_NO_KEYWORDS_PARAMETER_NODE: {
10151 ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg = TRUE;
10154 case PM_NUMBERED_REFERENCE_READ_NODE: {
10160 if (
cast->number != 0) {
10161 VALUE ref = pm_compile_numbered_reference_ref(cast);
10162 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), ref);
10165 PUSH_INSN(ret, location, putnil);
10174 pm_compile_or_node(iseq, (
const pm_or_node_t *) node, &location, ret, popped, scope_node);
10176 case PM_OPTIONAL_PARAMETER_NODE: {
10180 PM_COMPILE_NOT_POPPED(
cast->value);
10183 PUSH_SETLOCAL(ret, location, index.index, index.level);
10187 case PM_PARENTHESES_NODE: {
10195 if (
cast->body != NULL) {
10196 PM_COMPILE(
cast->body);
10198 else if (!popped) {
10199 PUSH_INSN(ret, location, putnil);
10204 case PM_PRE_EXECUTION_NODE: {
10216 DECL_ANCHOR(inner_pre);
10219 DECL_ANCHOR(inner_body);
10221 if (
cast->statements != NULL) {
10224 for (
size_t index = 0; index < body->
size; index++) {
10225 pm_compile_node(iseq, body->
nodes[index], inner_body,
true, scope_node);
10230 PUSH_INSN(inner_body, location, putnil);
10236 PUSH_SEQ(outer_pre, inner_pre);
10237 PUSH_SEQ(outer_pre, inner_body);
10242 case PM_POST_EXECUTION_NODE: {
10246 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
10249 pm_scope_node_init(node, &next_scope_node, scope_node);
10250 child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
10251 pm_scope_node_destroy(&next_scope_node);
10253 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
10255 int is_index = ISEQ_BODY(iseq)->ise_size++;
10256 PUSH_INSN2(ret, location, once, child_iseq,
INT2FIX(is_index));
10258 if (popped) PUSH_INSN(ret, location, pop);
10260 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
10264 case PM_RANGE_NODE: {
10268 bool exclude_end = PM_NODE_FLAG_P(cast, PM_RANGE_FLAGS_EXCLUDE_END);
10270 if (pm_optimizable_range_item_p(
cast->left) && pm_optimizable_range_item_p(
cast->right)) {
10276 (left && PM_NODE_TYPE_P(left, PM_INTEGER_NODE)) ? parse_integer((
const pm_integer_node_t *) left) :
Qnil,
10277 (right && PM_NODE_TYPE_P(right, PM_INTEGER_NODE)) ? parse_integer((const
pm_integer_node_t *) right) :
Qnil,
10282 PUSH_INSN1(ret, location, putobject, val);
10286 if (
cast->left != NULL) {
10287 PM_COMPILE(
cast->left);
10289 else if (!popped) {
10290 PUSH_INSN(ret, location, putnil);
10293 if (
cast->right != NULL) {
10294 PM_COMPILE(
cast->right);
10296 else if (!popped) {
10297 PUSH_INSN(ret, location, putnil);
10301 PUSH_INSN1(ret, location, newrange,
INT2FIX(exclude_end ? 1 : 0));
10306 case PM_RATIONAL_NODE: {
10310 PUSH_INSN1(ret, location, putobject, parse_rational((
const pm_rational_node_t *) node));
10317 pm_compile_redo_node(iseq, &location, ret, popped, scope_node);
10319 case PM_REGULAR_EXPRESSION_NODE: {
10323 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
10324 PUSH_INSN1(ret, location, putobject, regexp);
10328 case PM_RESCUE_NODE:
10331 pm_compile_rescue_node(iseq, (
const pm_rescue_node_t *) node, &location, ret, popped, scope_node);
10333 case PM_RESCUE_MODIFIER_NODE: {
10339 pm_scope_node_init((
const pm_node_t *) cast, &rescue_scope_node, scope_node);
10341 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
10342 &rescue_scope_node,
10345 pm_node_line_number_cached(
cast->rescue_expression, scope_node)
10348 pm_scope_node_destroy(&rescue_scope_node);
10350 LABEL *lstart = NEW_LABEL(location.
line);
10351 LABEL *lend = NEW_LABEL(location.
line);
10352 LABEL *lcont = NEW_LABEL(location.
line);
10354 lstart->rescued = LABEL_RESCUE_BEG;
10355 lend->rescued = LABEL_RESCUE_END;
10357 PUSH_LABEL(ret, lstart);
10358 PM_COMPILE_NOT_POPPED(
cast->expression);
10359 PUSH_LABEL(ret, lend);
10361 PUSH_INSN(ret, location, nop);
10362 PUSH_LABEL(ret, lcont);
10363 if (popped) PUSH_INSN(ret, location, pop);
10365 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
10366 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
10369 case PM_RETURN_NODE:
10375 pm_compile_return_node(iseq, (
const pm_return_node_t *) node, &location, ret, popped, scope_node);
10377 case PM_RETRY_NODE: {
10380 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_RESCUE) {
10381 PUSH_INSN(ret, location, putnil);
10382 PUSH_INSN1(ret, location,
throw,
INT2FIX(TAG_RETRY));
10383 if (popped) PUSH_INSN(ret, location, pop);
10386 COMPILE_ERROR(iseq, location.
line,
"Invalid retry");
10391 case PM_SCOPE_NODE:
10392 pm_compile_scope_node(iseq, (
pm_scope_node_t *) node, &location, ret, popped);
10394 case PM_SELF_NODE: {
10398 PUSH_INSN(ret, location, putself);
10402 case PM_SHAREABLE_CONSTANT_NODE: {
10406 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));
10408 switch (PM_NODE_TYPE(
cast->write)) {
10409 case PM_CONSTANT_WRITE_NODE:
10410 pm_compile_constant_write_node(iseq, (
const pm_constant_write_node_t *)
cast->write, shareability, &location, ret, popped, scope_node);
10412 case PM_CONSTANT_AND_WRITE_NODE:
10415 case PM_CONSTANT_OR_WRITE_NODE:
10418 case PM_CONSTANT_OPERATOR_WRITE_NODE:
10421 case PM_CONSTANT_PATH_WRITE_NODE:
10424 case PM_CONSTANT_PATH_AND_WRITE_NODE:
10427 case PM_CONSTANT_PATH_OR_WRITE_NODE:
10430 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
10434 rb_bug(
"Unexpected node type for shareable constant write: %s", pm_node_type(PM_NODE_TYPE(
cast->write)));
10440 case PM_SINGLETON_CLASS_NODE: {
10446 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10447 const rb_iseq_t *child_iseq = NEW_ISEQ(&next_scope_node, rb_fstring_lit(
"singleton class"), ISEQ_TYPE_CLASS, location.
line);
10448 pm_scope_node_destroy(&next_scope_node);
10450 PM_COMPILE_NOT_POPPED(
cast->expression);
10451 PUSH_INSN(ret, location, putnil);
10454 CONST_ID(singletonclass,
"singletonclass");
10458 int sclass_flags = VM_DEFINECLASS_TYPE_SINGLETON_CLASS;
10459 if (!(PM_NODE_TYPE_P(
cast->expression, PM_SELF_NODE) &&
10460 ISEQ_BODY(iseq)->
type == ISEQ_TYPE_CLASS) &&
10461 !pm_cpath_const_p(
cast->expression)) {
10462 sclass_flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
10465 PUSH_INSN3(ret, location, defineclass,
ID2SYM(singletonclass), child_iseq,
INT2FIX(sclass_flags));
10467 if (popped) PUSH_INSN(ret, location, pop);
10472 case PM_SOURCE_ENCODING_NODE: {
10476 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10477 PUSH_INSN1(ret, location, putobject, value);
10481 case PM_SOURCE_FILE_NODE: {
10488 if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_FROZEN)) {
10489 string_type = ISEQ_FROZEN_STRING_LITERAL_ENABLED;
10491 else if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_MUTABLE)) {
10492 string_type = ISEQ_FROZEN_STRING_LITERAL_DISABLED;
10495 string_type = ISEQ_FROZEN_STRING_LITERAL_UNSET;
10498 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10499 PUSH_INSN1(ret, location, putobject,
INT2FIX(string_type));
10500 PUSH_SEND(ret, location, id_core_iseq_path,
INT2FIX(1));
10504 case PM_SOURCE_LINE_NODE: {
10508 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10509 PUSH_INSN1(ret, location, putobject, value);
10513 case PM_SPLAT_NODE: {
10517 if (
cast->expression) {
10518 PM_COMPILE(
cast->expression);
10522 PUSH_INSN1(ret, location, splatarray,
Qtrue);
10526 case PM_STATEMENTS_NODE: {
10531 if (body->
size > 0) {
10532 for (
size_t index = 0; index < body->
size - 1; index++) {
10533 PM_COMPILE_POPPED(body->
nodes[index]);
10535 PM_COMPILE(body->
nodes[body->
size - 1]);
10538 PUSH_INSN(ret, location, putnil);
10542 case PM_STRING_NODE: {
10547 VALUE value = parse_static_literal_string(iseq, scope_node, node, &
cast->unescaped);
10549 if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_FROZEN)) {
10550 PUSH_INSN1(ret, location, putobject, value);
10552 else if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_MUTABLE)) {
10553 PUSH_INSN1(ret, location, dupstring, value);
10556 PUSH_INSN1(ret, location, dupchilledstring, value);
10561 case PM_SUPER_NODE:
10565 pm_compile_super_node(iseq, (
const pm_super_node_t *) node, &location, ret, popped, scope_node);
10567 case PM_SYMBOL_NODE: {
10571 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10572 PUSH_INSN1(ret, location, putobject, value);
10576 case PM_TRUE_NODE: {
10580 PUSH_INSN1(ret, location, putobject,
Qtrue);
10584 case PM_UNDEF_NODE: {
10590 for (
size_t index = 0; index < names->
size; index++) {
10591 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10592 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
10594 PM_COMPILE_NOT_POPPED(names->
nodes[index]);
10595 PUSH_SEND(ret, location, id_core_undef_method,
INT2NUM(2));
10597 if (index < names->size - 1) {
10598 PUSH_INSN(ret, location, pop);
10602 if (popped) PUSH_INSN(ret, location, pop);
10605 case PM_UNLESS_NODE: {
10613 if (
cast->else_clause != NULL) {
10617 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);
10620 case PM_UNTIL_NODE: {
10627 pm_compile_loop(iseq, &location,
cast->base.flags, PM_UNTIL_NODE, (
const pm_node_t *) cast,
cast->statements,
cast->predicate, ret, popped, scope_node);
10630 case PM_WHILE_NODE: {
10637 pm_compile_loop(iseq, &location,
cast->base.flags, PM_WHILE_NODE, (
const pm_node_t *) cast,
cast->statements,
cast->predicate, ret, popped, scope_node);
10640 case PM_X_STRING_NODE: {
10644 VALUE value = parse_static_literal_string(iseq, scope_node, node, &
cast->unescaped);
10646 PUSH_INSN(ret, location, putself);
10647 PUSH_INSN1(ret, location, putobject, value);
10648 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
10649 if (popped) PUSH_INSN(ret, location, pop);
10653 case PM_YIELD_NODE:
10659 pm_compile_yield_node(iseq, (
const pm_yield_node_t *) node, &location, ret, popped, scope_node);
10662 rb_raise(
rb_eNotImpError,
"node type %s not implemented", pm_node_type(PM_NODE_TYPE(node)));
10667#undef PM_CONTAINER_P
10671pm_iseq_pre_execution_p(
rb_iseq_t *iseq)
10673 switch (ISEQ_BODY(iseq)->
type) {
10674 case ISEQ_TYPE_TOP:
10675 case ISEQ_TYPE_EVAL:
10676 case ISEQ_TYPE_MAIN:
10695 if (pm_iseq_pre_execution_p(iseq)) {
10707 pm_compile_node(iseq, (
const pm_node_t *) node, body,
false, node);
10711 PUSH_SEQ(ret, pre);
10712 PUSH_SEQ(ret, body);
10717 pm_compile_node(iseq, (
const pm_node_t *) node, ret,
false, node);
10720 CHECK(iseq_setup_insn(iseq, ret));
10721 return iseq_setup(iseq, ret);
10728 result->
arena = pm_arena_new();
10729 result->
options = pm_options_new();
10730 pm_options_line_set(result->
options, 1);
10741 SIZED_FREE_N(result->
node.constants, pm_parser_constants_size(result->
node.parser));
10742 pm_scope_node_destroy(&result->
node);
10746 pm_arena_free(result->
arena);
10748 pm_options_free(result->
options);
10760 if (buffer == NULL) {
10765 if (rb_stderr_tty_p()) {
10766 const char *no_color = getenv(
"NO_COLOR");
10767 if (no_color == NULL || no_color[0] ==
'\0') {
10776 pm_error_level_t error_level = pm_errors_format(parser, buffer, format_type);
10779 VALUE message = rb_enc_str_new(pm_buffer_value(buffer), (
rb_len_t) pm_buffer_length(buffer), message_encoding);
10780 pm_buffer_free(buffer);
10783 switch (error_level) {
10790 VALUE path = rb_enc_str_new((
const char *) pm_string_source(filepath), pm_string_length(filepath), filepath_encoding);
10816 uint64_t checksum = pm_parser_checksum(parser);
10817 return checksum == 0 ? 1 : checksum;
10834 int coverage_enabled = scope_node->coverage_enabled;
10836 pm_scope_node_init(node, scope_node, NULL);
10839 const char *encoding_name = pm_parser_encoding_name(parser);
10840 rb_encoding *encoding = rb_enc_find(encoding_name);
10841 if (!encoding) rb_bug(
"Encoding not found %s!", encoding_name);
10842 scope_node->encoding = encoding;
10844 scope_node->coverage_enabled = coverage_enabled;
10848 if (script_lines != NULL) {
10852 for (
size_t index = 0; index < line_offsets->
size; index++) {
10853 size_t offset = line_offsets->
offsets[index];
10854 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);
10855 rb_ary_push(*script_lines, rb_enc_str_new((
const char *) pm_parser_start(parser) + offset, length, encoding));
10861 const char *filepath = (
const char *) pm_string_source(pm_parser_filepath(parser));
10864 const pm_diagnostic_t *diagnostic = pm_parser_warnings_first(parser);
10865 diagnostic != NULL;
10866 diagnostic = pm_diagnostic_next(diagnostic)
10869 int line = pm_location_line_number(parser, &loc);
10872 rb_enc_compile_warning(encoding, filepath, line,
"%s", pm_diagnostic_message(diagnostic));
10875 rb_enc_compile_warn(encoding, filepath, line,
"%s", pm_diagnostic_message(diagnostic));
10880 if (pm_parser_errors_size(parser) > 0) {
10881 VALUE error = pm_parse_process_error(result);
10890 scope_node->parser = parser;
10891 scope_node->
source_hash = pm_source_hash(parser);
10892 scope_node->options = result->
options;
10893 scope_node->line_offsets = pm_parser_line_offsets(parser);
10894 scope_node->start_line = pm_parser_start_line(parser);
10896 size_t constants_size = pm_parser_constants_size(parser);
10897 ID *constants = constants_size ?
xmalloc(constants_size *
sizeof(
ID)) : NULL;
10898 scope_node->constants = constants;
10900 for (
size_t index = 0; index < constants_size; index++) {
10902 constants[index] = rb_intern3((
const char *) pm_constant_start(constant), pm_constant_length(constant), encoding);
10916pm_options_frozen_string_literal_init(
pm_options_t *options)
10918 int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
10920 switch (frozen_string_literal) {
10921 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
10923 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
10924 pm_options_frozen_string_literal_set(options,
false);
10926 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
10927 pm_options_frozen_string_literal_set(options,
true);
10930 rb_bug(
"pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
10943 const char *start = (
const char *) pm_parser_start(parser);
10944 const char *end = (
const char *) pm_parser_end(parser);
10949 size_t last_offset = line_offsets->
offsets[line_offsets->
size - 1];
10950 bool last_push = start + last_offset != end;
10955 for (
size_t index = 0; index < line_offsets->
size - 1; index++) {
10956 size_t offset = line_offsets->
offsets[index];
10957 size_t length = line_offsets->
offsets[index + 1] - offset;
10959 rb_ary_push(lines, rb_enc_str_new(start + offset, length, scope_node->encoding));
10964 rb_ary_push(lines, rb_enc_str_new(start + last_offset, end - (start + last_offset), scope_node->encoding));
10978close_file(
VALUE args)
10981 if (arg->fd != -1) {
10984 else if (!
NIL_P(arg->io)) {
10991load_content(
VALUE args)
10998 return rb_funcall(io, rb_intern(
"read"), 0);
11009 result->
source = pm_source_mapped_new(RSTRING_PTR(filepath), O_RDONLY | O_NONBLOCK, &init_result);
11012 pm_options_frozen_string_literal_init(result->
options);
11023 .open_mode = O_RDONLY | O_NONBLOCK,
11027 if (args.fd == -1)
goto error_generic;
11033 if (
len < 0)
goto error_generic;
11035 size_t length = (size_t)
len;
11036 uint8_t *source_data =
xmalloc(length);
11037 memcpy(source_data, RSTRING_PTR(contents), length);
11038 result->
source = pm_source_owned_new(source_data, length);
11040 pm_options_frozen_string_literal_init(result->
options);
11049 err = rb_w32_map_errno(GetLastError());
11080 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11083 pm_options_version_for_current_ruby_set(result->
options);
11088 VALUE error = pm_parse_process(result, node, script_lines);
11093 ID id_script_lines = rb_intern(
"SCRIPT_LINES__");
11099 rb_hash_aset(constant_script_lines, filepath, pm_parse_file_script_lines(&result->
node, result->
parser));
11113 VALUE error = pm_load_file(result, filepath,
false);
11114 if (
NIL_P(error)) {
11115 error = pm_parse_file(result, filepath, script_lines);
11131 if (!rb_enc_asciicompat(encoding)) {
11135 pm_options_frozen_string_literal_init(result->
options);
11136 result->
source = pm_source_constant_new((
const uint8_t *) RSTRING_PTR(source), (
size_t) RSTRING_LEN(source));
11137 pm_options_encoding_set(result->
options, rb_enc_name(encoding));
11140 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11142 pm_options_version_for_current_ruby_set(result->
options);
11147 VALUE error = pm_parse_process(result, node, script_lines);
11160pm_node_find(
const pm_node_t *node,
void *data)
11164 if (node->
node_id == context->node_id) {
11165 context->node = node;
11176pm_source_hash_matches(
VALUE source,
VALUE filepath, uint64_t source_hash)
11179 pm_parse_result_init(&result);
11180 pm_parse_string(&result, source, filepath, NULL);
11182 bool matches = result.
parser != NULL && pm_source_hash(result.
parser) == source_hash;
11183 pm_parse_result_free(&result);
11197pm_node_source_location(
VALUE source,
VALUE filepath,
int start_line,
11201 pm_parse_result_init(&result);
11203 pm_options_line_set(result.
options, start_line);
11204 VALUE error = pm_parse_string(&result, source, filepath, NULL);
11206 if (result.
parser != NULL && pm_source_hash(result.
parser) != source_hash) {
11207 pm_parse_result_free(&result);
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);
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 rb_len_t length = RSTRING_LEN(line);
11289 if (length > (
rb_len_t) (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.
static PRISM_INLINE size_t pm_constant_id_index(pm_constant_id_t constant_id)
Returns the index of the constant with the given id among the constants of the parser that produced i...
@ 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 UINT2NUM
Old name of RB_UINT2NUM.
#define NUM2LEN
Old name of RB_NUM2LEN.
#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.
VALUE rb_eRuntimeError
RuntimeError 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_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_entry(VALUE ary, rb_len_t off)
Queries an element of an array.
VALUE rb_ary_new_capa(rb_len_t capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
void rb_ary_store(VALUE ary, rb_len_t key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_hidden_new(rb_len_t 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_cat(VALUE ary, const VALUE *train, rb_len_t len)
Destructively appends multiple elements at the end of the array.
VALUE rb_ary_join(VALUE ary, VALUE sep)
Recursively stringises the elements of the passed array, flattens that result, then joins the sequenc...
#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(rb_len_t 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.
VALUE rb_ensure(type *q, VALUE w, type *e, VALUE r)
An equivalent of ensure clause.
T * cast(pm_node_t *node) noexcept
Cast the given node, which must not be null and must be of the given struct, to that struct.
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.
std::string_view constant(const pm_parser_t *parser PRISM_LIFETIMEBOUND, pm_constant_id_t constant_id) noexcept
The name of the constant with the given id, which must not be zero.
pm_visit_result_t
The value returned by a visitor callback, which determines where the walk goes next.
@ PM_VISIT_STOP
End the walk without visiting any more nodes.
@ PM_VISIT_DESCEND
Continue the walk by visiting this node's children.
#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)
References an object in an array.
#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_t base
The embedded base node.
struct pm_node_list arguments
ArgumentsNode::arguments.
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_arguments_node * arguments
BreakNode::arguments.
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.
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.
ClassVariableAndWriteNode.
ClassVariableOperatorWriteNode.
ClassVariableOrWriteNode.
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_NODE_ALIGNAS struct pm_node * value
ConstantPathWriteNode::value.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathWriteNode::target.
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_statements_node * statements
ElseNode::statements.
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_block_node * block
ForwardingSuperNode::block.
GlobalVariableAndWriteNode.
GlobalVariableOperatorWriteNode.
GlobalVariableOrWriteNode.
GlobalVariableTargetNode.
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 * pattern
InNode::pattern.
PM_NODE_ALIGNAS struct pm_statements_node * statements
InNode::statements.
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 pm_index_lookup_table_index.
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.
InstanceVariableAndWriteNode.
InstanceVariableOperatorWriteNode.
InstanceVariableOrWriteNode.
InstanceVariableReadNode.
InstanceVariableTargetNode.
InstanceVariableWriteNode.
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.
InterpolatedMatchLastLineNode.
InterpolatedRegularExpressionNode.
struct pm_node_list elements
KeywordHashNode::elements.
KeywordRestParameterNode.
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.
LocalVariableOperatorWriteNode.
LocalVariableOrWriteNode.
uint32_t depth
LocalVariableTargetNode::depth.
pm_constant_id_t name
LocalVariableTargetNode::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
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 * 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_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_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.
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_integer_t denominator
RationalNode::denominator.
pm_integer_t numerator
RationalNode::numerator.
RequiredKeywordParameterNode.
pm_constant_id_t name
RequiredParameterNode::name.
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 * expression
SplatNode::expression.
pm_string_t unescaped
StringNode::unescaped.
A view of a sequence of bytes.
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.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
YieldNode::arguments.
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
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.