23#define PUSH_ADJUST(seq, location, label) \
24 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), (int) (location).line))
26#define PUSH_ADJUST_RESTORE(seq, label) \
27 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), -1))
29#define PUSH_INSN(seq, location, insn) \
30 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 0))
32#define PUSH_INSN1(seq, location, insn, op1) \
33 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 1, (VALUE)(op1)))
35#define PUSH_INSN2(seq, location, insn, op1, op2) \
36 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 2, (VALUE)(op1), (VALUE)(op2)))
38#define PUSH_INSN3(seq, location, insn, op1, op2, op3) \
39 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 3, (VALUE)(op1), (VALUE)(op2), (VALUE)(op3)))
41#define PUSH_INSNL(seq, location, insn, label) \
42 (PUSH_INSN1(seq, location, insn, label), LABEL_REF(label))
44#define PUSH_LABEL(seq, label) \
45 ADD_ELEM((seq), (LINK_ELEMENT *) (label))
47#define PUSH_SEND_R(seq, location, id, argc, block, flag, keywords) \
48 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_send(iseq, (int) (location).line, (int) (location).node_id, (id), (VALUE)(argc), (block), (VALUE)(flag), (keywords)))
50#define PUSH_SEND(seq, location, id, argc) \
51 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(0), NULL)
53#define PUSH_SEND_WITH_FLAG(seq, location, id, argc, flag) \
54 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)(flag), NULL)
56#define PUSH_SEND_WITH_BLOCK(seq, location, id, argc, block) \
57 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(0), NULL)
59#define PUSH_CALL(seq, location, id, argc) \
60 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
62#define PUSH_CALL_WITH_BLOCK(seq, location, id, argc, block) \
63 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
65#define PUSH_TRACE(seq, event) \
66 ADD_ELEM((seq), (LINK_ELEMENT *) new_trace_body(iseq, (event), 0))
68#define PUSH_CATCH_ENTRY(type, ls, le, iseqv, lc) \
69 ADD_CATCH_ENTRY((type), (ls), (le), (iseqv), (lc))
71#define PUSH_SEQ(seq1, seq2) \
72 APPEND_LIST((seq1), (seq2))
74#define PUSH_SYNTHETIC_PUTNIL(seq, iseq) \
76 int lineno = ISEQ_COMPILE_DATA(iseq)->last_line; \
77 if (lineno == 0) lineno = FIX2INT(rb_iseq_first_lineno(iseq)); \
78 ADD_SYNTHETIC_INSN(seq, lineno, -1, putnil); \
87pm_iseq_add_getlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
89 if (iseq_local_block_param_p(iseq, idx, level)) {
90 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
93 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
95 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qfalse);
99pm_iseq_add_setlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
101 if (iseq_local_block_param_p(iseq, idx, level)) {
102 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
105 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
107 update_lvar_state(iseq, level, idx);
108 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qtrue);
111#define PUSH_GETLOCAL(seq, location, idx, level) \
112 pm_iseq_add_getlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
114#define PUSH_SETLOCAL(seq, location, idx, level) \
115 pm_iseq_add_setlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
121#define OLD_ISEQ NEW_ISEQ
124#define NEW_ISEQ(node, name, type, line_no) \
125 pm_new_child_iseq(iseq, (node), rb_fstring(name), 0, (type), (line_no))
127#define OLD_CHILD_ISEQ NEW_CHILD_ISEQ
130#define NEW_CHILD_ISEQ(node, name, type, line_no) \
131 pm_new_child_iseq(iseq, (node), rb_fstring(name), iseq, (type), (line_no))
133#define PM_COMPILE(node) \
134 pm_compile_node(iseq, (node), ret, popped, scope_node)
136#define PM_COMPILE_INTO_ANCHOR(_ret, node) \
137 pm_compile_node(iseq, (node), _ret, popped, scope_node)
139#define PM_COMPILE_POPPED(node) \
140 pm_compile_node(iseq, (node), ret, true, scope_node)
142#define PM_COMPILE_NOT_POPPED(node) \
143 pm_compile_node(iseq, (node), ret, false, scope_node)
146#define PM_INDEX_LOOKUP_TABLE_INIT { .values = NULL, .capacity = 0, .owned = false }
151 int capacity = constants_size + PM_INDEX_LOOKUP_SPECIALS;
152 table->
values = compile_data_alloc2_type(iseq,
int, capacity);
153 memset(table->
values, -1, capacity *
sizeof(
int));
155 table->
owned =
false;
165pm_line_offset_list_line_column_cached(
const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line,
size_t *last_line)
167 size_t hint = *last_line;
168 size_t size = list->
size;
169 const uint32_t *offsets = list->
offsets;
174 if (offsets[hint] <= cursor) {
175 if (hint + 1 >= size || offsets[hint + 1] > cursor) {
178 .line = ((int32_t) hint) + start_line,
179 .column = cursor - offsets[hint]
184 size_t limit = hint + 9;
185 if (limit > size) limit = size;
186 for (
size_t idx = hint + 1; idx < limit; idx++) {
187 if (offsets[idx] > cursor) {
188 *last_line = idx - 1;
190 .line = ((int32_t) (idx - 1)) + start_line,
191 .column = cursor - offsets[idx - 1]
194 if (offsets[idx] == cursor) {
202 size_t limit = hint > 8 ? hint - 8 : 0;
203 for (
size_t idx = hint; idx > limit; idx--) {
204 if (offsets[idx - 1] <= cursor) {
205 *last_line = idx - 1;
207 .line = ((int32_t) (idx - 1)) + start_line,
208 .column = cursor - offsets[idx - 1]
215 pm_line_column_t result = pm_line_offset_list_line_column(list, cursor, start_line);
216 *last_line = (size_t) (result.
line - start_line);
225pm_line_offset_list_line_cached(
const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line,
size_t *last_line)
227 return pm_line_offset_list_line_column_cached(list, cursor, start_line, last_line).
line;
230#define PM_NODE_START_LOCATION(node) \
231 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start, scope_node->start_line, &scope_node->last_line), .node_id = ((const pm_node_t *) (node))->node_id })
233#define PM_NODE_END_LOCATION(node) \
234 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start + ((const pm_node_t *) (node))->location.length, scope_node->start_line, &scope_node->last_line), .node_id = ((const pm_node_t *) (node))->node_id })
236#define PM_LOCATION_START_LOCATION(location, id) \
237 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, (location)->start, scope_node->start_line, &scope_node->last_line), .node_id = id })
239#define PM_NODE_START_LINE_COLUMN(node) \
240 pm_line_offset_list_line_column_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start, scope_node->start_line, &scope_node->last_line)
242#define PM_NODE_END_LINE_COLUMN(node) \
243 pm_line_offset_list_line_column_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start + ((const pm_node_t *) (node))->location.length, scope_node->start_line, &scope_node->last_line)
245#define PM_LOCATION_START_LINE_COLUMN(location) \
246 pm_line_offset_list_line_column_cached(scope_node->line_offsets, (location)->start, scope_node->start_line, &scope_node->last_line)
250 return (
int) pm_line_offset_list_line_column(pm_parser_line_offsets(parser), location->
start, pm_parser_start_line(parser)).
line;
260 return (
int) pm_line_offset_list_line_cached(scope_node->line_offsets, node->
location.
start, scope_node->start_line, &scope_node->
last_line);
265 return (
int) pm_line_offset_list_line_cached(scope_node->line_offsets, location->
start, scope_node->start_line, &scope_node->
last_line);
276 if (integer->
values == NULL) {
284 result = rb_integer_unpack(
294 result = rb_int_uminus(result);
310 return parse_integer_value(&node->
value);
350 VALUE imaginary_part;
351 switch (PM_NODE_TYPE(node->
numeric)) {
352 case PM_FLOAT_NODE: {
356 case PM_INTEGER_NODE: {
360 case PM_RATIONAL_NODE: {
365 rb_bug(
"Unexpected numeric type on imaginary number %s\n", pm_node_type(PM_NODE_TYPE(node->
numeric)));
374 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), scope_node->encoding);
387 if (node->
flags & PM_ENCODING_FLAGS_FORCED_BINARY_ENCODING) {
388 encoding = rb_ascii8bit_encoding();
390 else if (node->
flags & PM_ENCODING_FLAGS_FORCED_UTF8_ENCODING) {
391 encoding = rb_utf8_encoding();
397 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
405 if (node->
flags & PM_STRING_FLAGS_FORCED_BINARY_ENCODING) {
406 encoding = rb_ascii8bit_encoding();
408 else if (node->
flags & PM_STRING_FLAGS_FORCED_UTF8_ENCODING) {
409 encoding = rb_utf8_encoding();
412 encoding = scope_node->encoding;
415 VALUE value = rb_enc_literal_str((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
416 rb_enc_str_coderange(value);
418 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
419 int line_number = pm_node_line_number_cached(node, scope_node);
430 if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_UTF8_ENCODING) {
431 encoding = rb_utf8_encoding();
433 else if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_BINARY_ENCODING) {
434 encoding = rb_ascii8bit_encoding();
436 else if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_US_ASCII_ENCODING) {
437 encoding = rb_usascii_encoding();
440 encoding = scope_node->encoding;
443 return rb_intern3((
const char *) pm_string_source(&symbol->
unescaped), pm_string_length(&symbol->
unescaped), encoding);
447pm_optimizable_range_item_p(
const pm_node_t *node)
449 return (!node || PM_NODE_TYPE_P(node, PM_INTEGER_NODE) || PM_NODE_TYPE_P(node, PM_NIL_NODE));
454parse_regexp_error(
rb_iseq_t *iseq, int32_t line_number,
const char *fmt, ...)
458 VALUE error = rb_syntax_error_append(
Qnil, rb_iseq_path(iseq), line_number, -1, NULL,
"%" PRIsVALUE, args);
470 if (explicit_regexp_encoding != NULL) {
471 encoding = explicit_regexp_encoding;
473 else if (node->
flags & PM_STRING_FLAGS_FORCED_BINARY_ENCODING) {
474 encoding = rb_ascii8bit_encoding();
476 else if (node->
flags & PM_STRING_FLAGS_FORCED_UTF8_ENCODING) {
477 encoding = rb_utf8_encoding();
480 encoding = implicit_regexp_encoding;
483 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), encoding);
484 VALUE error = rb_reg_check_preprocess(
string);
486 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number_cached(node, scope_node),
"%" PRIsVALUE,
rb_obj_as_string(error));
495 for (
size_t index = 0; index < nodes->
size; index++) {
499 switch (PM_NODE_TYPE(part)) {
501 if (implicit_regexp_encoding != NULL) {
503 string = parse_regexp_string_part(iseq, scope_node, part, &((
const pm_string_node_t *) part)->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
506 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
507 VALUE error = rb_reg_check_preprocess(
string);
508 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number_cached(part, scope_node),
"%" PRIsVALUE,
rb_obj_as_string(error));
512 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
515 case PM_INTERPOLATED_STRING_NODE:
516 string = pm_static_literal_concat(iseq, &((
const pm_interpolated_string_node_t *) part)->parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
518 case PM_EMBEDDED_STATEMENTS_NODE: {
520 string = pm_static_literal_concat(iseq, &cast->
statements->
body, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
524 RUBY_ASSERT(
false &&
"unexpected node type in pm_static_literal_concat");
528 if (current !=
Qnil) {
536 return top ? rb_fstring(current) : current;
539#define RE_OPTION_ENCODING_SHIFT 8
540#define RE_OPTION_ENCODING(encoding) (((encoding) & 0xFF) << RE_OPTION_ENCODING_SHIFT)
541#define ARG_ENCODING_NONE 32
542#define ARG_ENCODING_FIXED 16
543#define ENC_ASCII8BIT 1
545#define ENC_Windows_31J 3
560 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) {
561 flags |= ARG_ENCODING_NONE;
564 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EUC_JP)) {
565 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_EUC_JP));
568 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J)) {
569 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_Windows_31J));
572 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_UTF_8)) {
573 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_UTF8));
576 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE)) {
577 flags |= ONIG_OPTION_IGNORECASE;
580 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE)) {
581 flags |= ONIG_OPTION_MULTILINE;
584 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EXTENDED)) {
585 flags |= ONIG_OPTION_EXTEND;
591#undef RE_OPTION_ENCODING_SHIFT
592#undef RE_OPTION_ENCODING
593#undef ARG_ENCODING_FIXED
594#undef ARG_ENCODING_NONE
597#undef ENC_Windows_31J
603 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_FORCED_BINARY_ENCODING) || PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) {
604 return rb_ascii8bit_encoding();
606 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_UTF_8)) {
607 return rb_utf8_encoding();
609 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EUC_JP)) {
610 return rb_enc_get_from_index(ENCINDEX_EUC_JP);
612 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J)) {
613 return rb_enc_get_from_index(ENCINDEX_Windows_31J);
623 VALUE errinfo = rb_errinfo();
625 int32_t line_number = pm_node_line_number_cached(node, scope_node);
626 VALUE regexp = rb_reg_compile(
string, parse_regexp_flags(node), (
const char *) pm_string_source(pm_parser_filepath(scope_node->parser)), line_number);
629 VALUE message = rb_attr_get(rb_errinfo(), idMesg);
630 rb_set_errinfo(errinfo);
632 parse_regexp_error(iseq, line_number,
"%" PRIsVALUE, message);
642 rb_encoding *regexp_encoding = parse_regexp_encoding(scope_node, node);
643 if (regexp_encoding == NULL) regexp_encoding = scope_node->encoding;
645 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), regexp_encoding);
647 return parse_regexp(iseq, scope_node, node,
string);
653 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
654 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
656 VALUE string = pm_static_literal_concat(iseq, parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
657 return parse_regexp(iseq, scope_node, node,
string);
666 size_t parts_size = parts->
size;
667 bool interpolated =
false;
669 if (parts_size > 0) {
673 for (
size_t index = 0; index < parts_size; index++) {
676 if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
680 if (implicit_regexp_encoding == NULL) {
681 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
684 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
687 if (
RTEST(current_string)) {
688 current_string =
rb_str_concat(current_string, string_value);
691 current_string = string_value;
692 if (index != 0) current_location = PM_NODE_END_LOCATION(part);
699 PM_NODE_TYPE_P(part, PM_EMBEDDED_STATEMENTS_NODE) &&
707 if (implicit_regexp_encoding == NULL) {
708 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
711 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
714 if (
RTEST(current_string)) {
715 current_string =
rb_str_concat(current_string, string_value);
718 current_string = string_value;
719 current_location = PM_NODE_START_LOCATION(part);
723 if (!
RTEST(current_string)) {
726 if (implicit_regexp_encoding != NULL) {
727 if (explicit_regexp_encoding != NULL) {
728 encoding = explicit_regexp_encoding;
730 else if (pm_parser_encoding_us_ascii(scope_node->parser)) {
731 encoding = rb_ascii8bit_encoding();
734 encoding = implicit_regexp_encoding;
738 encoding = scope_node->encoding;
741 if (parts_size == 1) {
742 current_string = rb_enc_str_new(NULL, 0, encoding);
746 if (
RTEST(current_string)) {
747 VALUE operand = rb_fstring(current_string);
748 PUSH_INSN1(ret, current_location, putobject, operand);
752 PM_COMPILE_NOT_POPPED(part);
755 PUSH_INSN(ret, current_location, dup);
758 const struct rb_callinfo *callinfo = new_callinfo(iseq, idTo_s, 0, VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE, NULL, FALSE);
759 PUSH_INSN1(ret, current_location, objtostring, callinfo);
762 PUSH_INSN(ret, current_location, anytostring);
764 current_string =
Qnil;
770 if (
RTEST(current_string)) {
771 current_string = rb_fstring(current_string);
773 if (stack_size == 0) {
775 PUSH_INSN1(ret, current_location, putobject, current_string);
776 }
else if (mutable_result || interpolated) {
777 PUSH_INSN1(ret, current_location, dupstring, current_string);
779 PUSH_INSN1(ret, current_location, dupchilledstring, current_string);
782 PUSH_INSN1(ret, current_location, putobject, current_string);
785 current_string =
Qnil;
790 PUSH_INSN(ret, *node_location, putnil);
799 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
800 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
802 int length = pm_interpolated_node_compile(iseq, parts, node_location, ret, popped, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false,
false);
803 PUSH_INSN2(ret, *node_location, toregexp,
INT2FIX(parse_regexp_flags(node) & 0xFF),
INT2FIX(length));
810 size_t length = pm_string_length(filepath);
814 return rb_enc_interned_str((
const char *) pm_string_source(filepath), length, filepath_encoding);
817 return rb_fstring_lit(
"<compiled>");
826pm_static_literal_string(
rb_iseq_t *iseq,
VALUE string,
int line_number)
828 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
829 VALUE str = rb_str_with_debug_created_info(
string, rb_iseq_path(iseq), line_number);
834 return rb_fstring(
string);
848 RUBY_ASSERT(PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL));
850 switch (PM_NODE_TYPE(node)) {
851 case PM_ARRAY_NODE: {
856 for (
size_t index = 0; index < elements->
size; index++) {
857 rb_ary_push(value, pm_static_literal_value(iseq, elements->
nodes[index], scope_node));
872 for (
size_t index = 0; index < elements->
size; index++) {
875 VALUE pair[2] = { pm_static_literal_value(iseq, cast->key, scope_node), pm_static_literal_value(iseq, cast->value, scope_node) };
886 case PM_IMAGINARY_NODE:
888 case PM_INTEGER_NODE:
890 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
892 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
894 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
896 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
898 case PM_INTERPOLATED_STRING_NODE: {
900 int line_number = pm_node_line_number_cached(node, scope_node);
901 return pm_static_literal_string(iseq,
string, line_number);
903 case PM_INTERPOLATED_SYMBOL_NODE: {
905 VALUE string = pm_static_literal_concat(iseq, &cast->
parts, scope_node, NULL, NULL,
true);
907 return ID2SYM(rb_intern_str(
string));
909 case PM_MATCH_LAST_LINE_NODE: {
911 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
915 case PM_RATIONAL_NODE:
917 case PM_REGULAR_EXPRESSION_NODE: {
919 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
921 case PM_SOURCE_ENCODING_NODE:
922 return rb_enc_from_encoding(scope_node->encoding);
923 case PM_SOURCE_LINE_NODE:
924 return INT2FIX(pm_node_line_number_cached(node, scope_node));
925 case PM_STRING_NODE: {
927 return parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
934 rb_bug(
"Don't have a literal value for node type %s", pm_node_type(PM_NODE_TYPE(node)));
949 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
950 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
959#define PM_BRANCH_COVERAGE_P(iseq) (ISEQ_COVERAGE(iseq) && ISEQ_BRANCH_COVERAGE(iseq))
973 if (!then_label) then_label = label;
974 else if (!else_label) else_label = label;
976 pm_compile_branch_condition(iseq, seq, cond, then_label, else_label, scope_node);
978 if (LIST_INSN_SIZE_ONE(seq)) {
979 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(seq));
980 if (insn->insn_id == BIN(jump) && (
LABEL *)(insn->operands[0]) == label)
return;
984 PUSH_LABEL(seq, label);
996 if (PM_NODE_TYPE_P(node, PM_INTEGER_NODE)) {
997 PM_COMPILE_NOT_POPPED(node);
1000 PUSH_INSN1(ret, location, getglobal, operand);
1002 PUSH_SEND(ret, location, idEq,
INT2FIX(1));
1003 if (popped) PUSH_INSN(ret, location, pop);
1016 int again = !(flip_flop_node->
base.
flags & PM_RANGE_FLAGS_EXCLUDE_END);
1018 rb_num_t count = ISEQ_FLIP_CNT_INCREMENT(ISEQ_BODY(iseq)->local_iseq) + VM_SVAR_FLIPFLOP_START;
1021 PUSH_INSN2(ret, location, getspecial, key,
INT2FIX(0));
1022 PUSH_INSNL(ret, location, branchif, lend);
1024 if (flip_flop_node->
left) {
1025 pm_compile_flip_flop_bound(iseq, flip_flop_node->
left, ret, popped, scope_node);
1028 PUSH_INSN(ret, location, putnil);
1031 PUSH_INSNL(ret, location, branchunless, else_label);
1032 PUSH_INSN1(ret, location, putobject,
Qtrue);
1033 PUSH_INSN1(ret, location, setspecial, key);
1035 PUSH_INSNL(ret, location, jump, then_label);
1038 PUSH_LABEL(ret, lend);
1039 if (flip_flop_node->
right) {
1040 pm_compile_flip_flop_bound(iseq, flip_flop_node->
right, ret, popped, scope_node);
1043 PUSH_INSN(ret, location, putnil);
1046 PUSH_INSNL(ret, location, branchunless, then_label);
1047 PUSH_INSN1(ret, location, putobject,
Qfalse);
1048 PUSH_INSN1(ret, location, setspecial, key);
1049 PUSH_INSNL(ret, location, jump, then_label);
1060 switch (PM_NODE_TYPE(cond)) {
1063 pm_compile_logical(iseq, ret, cast->
left, NULL, else_label, scope_node);
1070 pm_compile_logical(iseq, ret, cast->
left, then_label, NULL, scope_node);
1077 PUSH_INSNL(ret, location, jump, else_label);
1080 case PM_IMAGINARY_NODE:
1081 case PM_INTEGER_NODE:
1082 case PM_LAMBDA_NODE:
1083 case PM_RATIONAL_NODE:
1084 case PM_REGULAR_EXPRESSION_NODE:
1085 case PM_STRING_NODE:
1086 case PM_SYMBOL_NODE:
1088 PUSH_INSNL(ret, location, jump, then_label);
1090 case PM_FLIP_FLOP_NODE:
1091 pm_compile_flip_flop((
const pm_flip_flop_node_t *) cond, else_label, then_label, iseq, location.
line, ret,
false, scope_node);
1093 case PM_DEFINED_NODE: {
1095 pm_compile_defined_expr(iseq, cast->
value, &location, ret,
false, scope_node,
true);
1099 DECL_ANCHOR(cond_seq);
1100 pm_compile_node(iseq, cond, cond_seq,
false, scope_node);
1102 if (LIST_INSN_SIZE_ONE(cond_seq)) {
1103 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(cond_seq));
1105 if (insn->insn_id == BIN(putobject)) {
1106 if (
RTEST(insn->operands[0])) {
1107 PUSH_INSNL(ret, location, jump, then_label);
1112 PUSH_INSNL(ret, location, jump, else_label);
1118 PUSH_SEQ(ret, cond_seq);
1123 PUSH_INSNL(ret, location, branchunless, else_label);
1124 PUSH_INSNL(ret, location, jump, then_label);
1134 LABEL *then_label = NEW_LABEL(location.
line);
1135 LABEL *else_label = NEW_LABEL(location.
line);
1136 LABEL *end_label = NULL;
1138 DECL_ANCHOR(cond_seq);
1139 pm_compile_branch_condition(iseq, cond_seq, predicate, then_label, else_label, scope_node);
1140 PUSH_SEQ(ret, cond_seq);
1145 if (then_label->refcnt && else_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1146 conditional_location = pm_code_location(scope_node, node);
1147 branches = decl_branch_base(iseq, (
int) node->
node_id, &conditional_location,
type == PM_IF_NODE ?
"if" :
"unless");
1150 if (then_label->refcnt) {
1151 PUSH_LABEL(ret, then_label);
1153 DECL_ANCHOR(then_seq);
1155 if (statements != NULL) {
1156 pm_compile_node(iseq, (
const pm_node_t *) statements, then_seq, popped, scope_node);
1159 PUSH_SYNTHETIC_PUTNIL(then_seq, iseq);
1162 if (else_label->refcnt) {
1164 if (PM_BRANCH_COVERAGE_P(iseq)) {
1167 if (statements != NULL) {
1168 branch_location = pm_code_location(scope_node, (
const pm_node_t *) statements);
1169 }
else if (
type == PM_IF_NODE) {
1172 .beg_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column },
1173 .end_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column }
1176 branch_location = conditional_location;
1179 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
type == PM_IF_NODE ?
"then" :
"else", branches);
1182 end_label = NEW_LABEL(location.
line);
1183 PUSH_INSNL(then_seq, location, jump, end_label);
1184 if (!popped) PUSH_INSN(then_seq, location, pop);
1187 PUSH_SEQ(ret, then_seq);
1190 if (else_label->refcnt) {
1191 PUSH_LABEL(ret, else_label);
1193 DECL_ANCHOR(else_seq);
1195 if (subsequent != NULL) {
1196 pm_compile_node(iseq, subsequent, else_seq, popped, scope_node);
1199 PUSH_SYNTHETIC_PUTNIL(else_seq, iseq);
1203 if (then_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1206 if (subsequent == NULL) {
1207 branch_location = conditional_location;
1208 }
else if (PM_NODE_TYPE_P(subsequent, PM_ELSE_NODE)) {
1212 branch_location = pm_code_location(scope_node, (
const pm_node_t *) subsequent);
1215 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 1,
type == PM_IF_NODE ?
"else" :
"then", branches);
1218 PUSH_SEQ(ret, else_seq);
1222 PUSH_LABEL(ret, end_label);
1236 LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
1237 LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
1238 LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
1240 LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(location.
line);
1241 LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(location.
line);
1242 LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(location.
line);
1243 LABEL *end_label = NEW_LABEL(location.
line);
1244 LABEL *adjust_label = NEW_LABEL(location.
line);
1246 LABEL *next_catch_label = NEW_LABEL(location.
line);
1247 LABEL *tmp_label = NULL;
1253 push_ensure_entry(iseq, &enl, NULL, NULL);
1256 if (flags & PM_LOOP_FLAGS_BEGIN_MODIFIER) {
1257 tmp_label = NEW_LABEL(location.
line);
1258 PUSH_INSNL(ret, location, jump, tmp_label);
1262 PUSH_INSNL(ret, location, jump, next_label);
1265 PUSH_LABEL(ret, adjust_label);
1266 PUSH_INSN(ret, location, putnil);
1267 PUSH_LABEL(ret, next_catch_label);
1268 PUSH_INSN(ret, location, pop);
1269 PUSH_INSNL(ret, location, jump, next_label);
1270 if (tmp_label) PUSH_LABEL(ret, tmp_label);
1272 PUSH_LABEL(ret, redo_label);
1275 if (PM_BRANCH_COVERAGE_P(iseq)) {
1277 VALUE branches = decl_branch_base(iseq, (
int) node->
node_id, &loop_location,
type == PM_WHILE_NODE ?
"while" :
"until");
1279 rb_code_location_t branch_location = statements != NULL ? pm_code_location(scope_node, (
const pm_node_t *) statements) : loop_location;
1280 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
"body", branches);
1283 if (statements != NULL) PM_COMPILE_POPPED((
const pm_node_t *) statements);
1284 PUSH_LABEL(ret, next_label);
1286 if (
type == PM_WHILE_NODE) {
1287 pm_compile_branch_condition(iseq, ret, predicate, redo_label, end_label, scope_node);
1289 else if (
type == PM_UNTIL_NODE) {
1290 pm_compile_branch_condition(iseq, ret, predicate, end_label, redo_label, scope_node);
1293 PUSH_LABEL(ret, end_label);
1294 PUSH_ADJUST_RESTORE(ret, adjust_label);
1295 PUSH_INSN(ret, location, putnil);
1297 PUSH_LABEL(ret, break_label);
1298 if (popped) PUSH_INSN(ret, location, pop);
1300 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, NULL, break_label);
1301 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label, NULL, next_catch_label);
1302 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, NULL, ISEQ_COMPILE_DATA(iseq)->redo_label);
1304 ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
1305 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
1306 ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
1307 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->prev;
1322 for (level = 0; level < start_depth; level++) {
1323 scope_node = scope_node->previous;
1326 while (!pm_index_lookup_table_lookup(&scope_node->
index_lookup_table, constant_id, &local_index))
1330 if (scope_node->previous) {
1331 scope_node = scope_node->previous;
1336 rb_bug(
"Local with constant_id %u does not exist", (
unsigned int) constant_id);
1340 lindex.level = level;
1341 lindex.index = scope_node->local_table_for_iseq_size - (int) local_index;
1354 RUBY_ASSERT(constant_id >= 1 && constant_id <= pm_parser_constants_size(scope_node->parser));
1355 return scope_node->constants[constant_id - 1];
1361 debugs(
"[new_child_iseq]> ---------------------------------------\n");
1362 int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
1363 rb_iseq_t *ret_iseq = pm_iseq_build(node, name,
1364 rb_iseq_path(iseq), rb_iseq_realpath(iseq),
1366 isolated_depth ? isolated_depth + 1 : 0,
1367 type, ISEQ_COMPILE_DATA(iseq)->option);
1368 debugs(
"[new_child_iseq]< ---------------------------------------\n");
1375 switch (PM_NODE_TYPE(node)) {
1376 case PM_CONSTANT_READ_NODE:
1378 case PM_CONSTANT_PATH_NODE:
1381 if (!parent)
return TRUE;
1382 return pm_cpath_const_p(parent);
1392 if (PM_NODE_TYPE_P(node, PM_CONSTANT_PATH_NODE)) {
1398 int flags = VM_DEFINECLASS_FLAG_SCOPED;
1399 if (!pm_cpath_const_p(parent)) {
1400 flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
1406 PUSH_INSN1(ret, *node_location, putobject,
rb_cObject);
1407 return VM_DEFINECLASS_FLAG_SCOPED;
1412 PUSH_INSN1(ret, *node_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
1422pm_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)
1426 LABEL *lcfin = NEW_LABEL(location.
line);
1427 LABEL *lskip = NULL;
1429 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
1430 ID id_read_name = pm_constant_id_lookup(scope_node, read_name);
1432 PM_COMPILE_NOT_POPPED(receiver);
1434 lskip = NEW_LABEL(location.
line);
1435 PUSH_INSN(ret, location, dup);
1436 PUSH_INSNL(ret, location, branchnil, lskip);
1439 PUSH_INSN(ret, location, dup);
1440 PUSH_SEND_WITH_FLAG(ret, location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
1441 if (!popped) PUSH_INSN(ret, location, dup);
1444 PUSH_INSNL(ret, location, branchunless, lcfin);
1447 PUSH_INSNL(ret, location, branchif, lcfin);
1450 if (!popped) PUSH_INSN(ret, location, pop);
1451 PM_COMPILE_NOT_POPPED(value);
1454 PUSH_INSN(ret, location, swap);
1455 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
1458 ID id_write_name = pm_constant_id_lookup(scope_node, write_name);
1459 PUSH_SEND_WITH_FLAG(ret, location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
1460 PUSH_INSNL(ret, location, jump, lfin);
1462 PUSH_LABEL(ret, lcfin);
1463 if (!popped) PUSH_INSN(ret, location, swap);
1465 PUSH_LABEL(ret, lfin);
1467 if (lskip && popped) PUSH_LABEL(ret, lskip);
1468 PUSH_INSN(ret, location, pop);
1469 if (lskip && !popped) PUSH_LABEL(ret, lskip);
1488 const int max_stack_length = 0x100;
1489 const unsigned int min_tmp_hash_length = 0x800;
1491 int stack_length = 0;
1492 bool first_chunk =
true;
1493 bool owned_hash =
false;
1499 bool static_literal =
false;
1501 DECL_ANCHOR(anchor);
1504#define FLUSH_CHUNK \
1505 if (stack_length) { \
1506 if (first_chunk) { \
1507 PUSH_SEQ(ret, anchor); \
1508 PUSH_INSN1(ret, location, newhash, INT2FIX(stack_length)); \
1509 first_chunk = false; \
1512 PUSH_INSN1(ret, location, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); \
1513 PUSH_INSN(ret, location, swap); \
1514 PUSH_SEQ(ret, anchor); \
1516 PUSH_SEND(ret, location, id_core_hash_merge_bang_ptr, INT2FIX(stack_length + 1)); \
1519 PUSH_SEND(ret, location, id_core_hash_merge_ptr, INT2FIX(stack_length + 1)); \
1520 owned_hash = true; \
1523 INIT_ANCHOR(anchor); \
1527 for (
size_t index = 0; index < elements->
size; index++) {
1530 switch (PM_NODE_TYPE(element)) {
1531 case PM_ASSOC_NODE: {
1534 (shareability == 0) &&
1535 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && (
1536 (!static_literal && ((index + min_tmp_hash_length) < elements->
size)) ||
1537 (first_chunk && stack_length == 0)
1542 while (index + count < elements->size && PM_NODE_FLAG_P(elements->
nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++;
1544 bool first_element = first_chunk && stack_length == 0;
1546 if (first_element || count >= min_tmp_hash_length) {
1552 for (
size_t tmp_end = index + count; index < tmp_end; index++) {
1556 pm_static_literal_value(iseq, assoc->key, scope_node),
1557 pm_static_literal_value(iseq, assoc->value, scope_node)
1572 if (count == elements->
size) {
1574 PUSH_INSN1(ret, location, duphash, hash);
1580 first_chunk =
false;
1583 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1584 PUSH_INSN(ret, location, swap);
1585 PUSH_INSN1(ret, location, putobject, hash);
1586 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1592 static_literal =
true;
1596 static_literal =
false;
1601 if (shareability == 0) {
1602 pm_compile_node(iseq, element, anchor,
false, scope_node);
1606 pm_compile_shareable_constant_value(iseq, assoc->
key, shareability, path, ret, scope_node,
false);
1607 pm_compile_shareable_constant_value(iseq, assoc->
value, shareability, path, ret, scope_node,
false);
1610 if ((stack_length += 2) >= max_stack_length) FLUSH_CHUNK;
1613 case PM_ASSOC_SPLAT_NODE: {
1617 bool empty_hash = assoc_splat->
value != NULL && (
1618 (PM_NODE_TYPE_P(assoc_splat->
value, PM_HASH_NODE) && ((
const pm_hash_node_t *) assoc_splat->
value)->elements.size == 0) ||
1619 PM_NODE_TYPE_P(assoc_splat->
value, PM_NIL_NODE)
1622 bool first_element = first_chunk && stack_length == 0;
1623 bool last_element = index == elements->
size - 1;
1624 bool only_element = first_element && last_element;
1631 PUSH_INSN(ret, location, putnil);
1637 if (shareability == 0) {
1638 PM_COMPILE_NOT_POPPED(element);
1641 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1649 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1650 if (shareability == 0) {
1651 PM_COMPILE_NOT_POPPED(element);
1654 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1656 PUSH_SEND(ret, location, id_core_hash_coerce,
INT2FIX(1));
1660 if (!first_element) {
1661 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1662 PUSH_INSN(ret, location, swap);
1665 if (shareability == 0) {
1666 PM_COMPILE_NOT_POPPED(element);
1669 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1672 if (!first_element) {
1674 PUSH_SEND(ret, location, id_core_hash_merge_bang_kwd,
INT2FIX(2));
1677 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1683 first_chunk =
false;
1684 static_literal =
false;
1688 RUBY_ASSERT(
"Invalid node type for hash" &&
false);
1697#define SPLATARRAY_FALSE 0
1698#define SPLATARRAY_TRUE 1
1699#define DUP_SINGLE_KW_SPLAT 2
1708 bool has_splat =
false;
1709 bool has_keyword_splat =
false;
1711 if (arguments_node == NULL) {
1712 if (*flags & VM_CALL_FCALL) {
1713 *flags |= VM_CALL_VCALL;
1718 has_keyword_splat = PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT);
1722 int post_splat_counter = 0;
1726 switch (PM_NODE_TYPE(argument)) {
1728 case PM_KEYWORD_HASH_NODE: {
1732 if (has_keyword_splat || has_splat) {
1733 *flags |= VM_CALL_KW_SPLAT;
1734 has_keyword_splat =
true;
1736 if (elements->
size > 1 || !(elements->
size == 1 && PM_NODE_TYPE_P(elements->
nodes[0], PM_ASSOC_SPLAT_NODE))) {
1740 *flags |= VM_CALL_KW_SPLAT_MUT;
1741 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1743 else if (*dup_rest & DUP_SINGLE_KW_SPLAT) {
1744 *flags |= VM_CALL_KW_SPLAT_MUT;
1745 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1746 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1747 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1748 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1751 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1757 if (PM_NODE_FLAG_P(keyword_arg, PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS)) {
1762 VALUE stored_indices = rb_hash_new();
1766 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1771 VALUE keyword = pm_static_literal_value(iseq, assoc->key, scope_node);
1772 VALUE stored_index = rb_hash_aref(stored_indices, keyword);
1777 if (!
NIL_P(stored_index)) {
1785 rb_hash_aset(stored_indices, keyword,
ULONG2NUM(element_index));
1790 if (size > VM_CALL_KW_LEN_MAX) {
1791 COMPILE_ERROR(iseq, node_location->
line,
"too many keyword arguments (%d, maximum is %d)",
1792 (
int) size, (
int) VM_CALL_KW_LEN_MAX);
1796 *flags |= VM_CALL_KWARG;
1798 VALUE *keywords = (*kw_arg)->keywords;
1799 (*kw_arg)->references = 0;
1800 (*kw_arg)->keyword_len = (int) size;
1802 size_t keyword_index = 0;
1803 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1808 keywords[keyword_index++] = pm_static_literal_value(iseq, assoc->key, scope_node);
1812 PM_COMPILE(assoc->value);
1821 *flags |= VM_CALL_KW_SPLAT;
1823 size_t size = elements->
size;
1828 *flags |= VM_CALL_KW_SPLAT_MUT;
1831 for (
size_t element_index = 0; element_index < size; element_index++) {
1833 PM_COMPILE_NOT_POPPED(assoc->key);
1834 PM_COMPILE_NOT_POPPED(assoc->value);
1837 PUSH_INSN1(ret, location, newhash,
INT2FIX(size * 2));
1842 case PM_SPLAT_NODE: {
1843 *flags |= VM_CALL_ARGS_SPLAT;
1847 PM_COMPILE_NOT_POPPED(splat_node->
expression);
1850 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1851 PUSH_GETLOCAL(ret, location, index.index, index.level);
1854 bool first_splat = !has_splat;
1862 if (index + 1 < arguments->
size || has_regular_blockarg) {
1863 PUSH_INSN1(ret, location, splatarray, (*dup_rest & SPLATARRAY_TRUE) ?
Qtrue :
Qfalse);
1864 if (*dup_rest & SPLATARRAY_TRUE) *dup_rest &= ~SPLATARRAY_TRUE;
1872 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1882 PUSH_INSN(ret, location, concattoarray);
1886 post_splat_counter = 0;
1890 case PM_FORWARDING_ARGUMENTS_NODE: {
1891 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
1893 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
1894 *flags |= VM_CALL_FORWARDING;
1896 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
1897 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1909 *flags |= VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_BLOCKARG | VM_CALL_KW_SPLAT;
1916 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1917 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1921 PUSH_INSN(ret, location, concattoarray);
1923 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1927 pm_local_index_t pow_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1928 PUSH_GETLOCAL(ret, location, pow_local.index, pow_local.level);
1931 pm_local_index_t and_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
1932 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(and_local.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(and_local.level));
1937 post_splat_counter++;
1938 PM_COMPILE_NOT_POPPED(argument);
1962 if (index == arguments->
size - 1) {
1964 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1969 switch (PM_NODE_TYPE(next_arg)) {
1971 case PM_KEYWORD_HASH_NODE: {
1972 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1973 PUSH_INSN(ret, location, concatarray);
1976 case PM_SPLAT_NODE: {
1977 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1978 PUSH_INSN(ret, location, concatarray);
1981 case PM_FORWARDING_ARGUMENTS_NODE: {
1982 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1998 if (has_splat) orig_argc++;
1999 if (has_keyword_splat) orig_argc++;
2008pm_setup_args_dup_rest_p(
const pm_node_t *node)
2010 switch (PM_NODE_TYPE(node)) {
2011 case PM_BACK_REFERENCE_READ_NODE:
2012 case PM_CLASS_VARIABLE_READ_NODE:
2013 case PM_CONSTANT_READ_NODE:
2016 case PM_GLOBAL_VARIABLE_READ_NODE:
2017 case PM_IMAGINARY_NODE:
2018 case PM_INSTANCE_VARIABLE_READ_NODE:
2019 case PM_INTEGER_NODE:
2020 case PM_LAMBDA_NODE:
2021 case PM_LOCAL_VARIABLE_READ_NODE:
2023 case PM_NUMBERED_REFERENCE_READ_NODE:
2024 case PM_RATIONAL_NODE:
2025 case PM_REGULAR_EXPRESSION_NODE:
2027 case PM_STRING_NODE:
2028 case PM_SYMBOL_NODE:
2031 case PM_CONSTANT_PATH_NODE: {
2033 if (cast->
parent != NULL) {
2034 return pm_setup_args_dup_rest_p(cast->
parent);
2038 case PM_IMPLICIT_NODE:
2040 case PM_ARRAY_NODE: {
2042 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2043 if (pm_setup_args_dup_rest_p(cast->
elements.
nodes[index])) {
2060 int dup_rest = SPLATARRAY_TRUE;
2063 size_t arguments_size;
2068 arguments_node != NULL &&
2069 (arguments = &arguments_node->
arguments, arguments_size = arguments->
size) >= 2 &&
2070 PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_SPLAT) &&
2071 !PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_MULTIPLE_SPLATS) &&
2072 PM_NODE_TYPE_P(arguments->
nodes[arguments_size - 1], PM_KEYWORD_HASH_NODE)
2077 dup_rest = SPLATARRAY_FALSE;
2082 for (
size_t index = 0; dup_rest == SPLATARRAY_FALSE && index < elements->
size; index++) {
2085 switch (PM_NODE_TYPE(element)) {
2086 case PM_ASSOC_NODE: {
2088 if (pm_setup_args_dup_rest_p(assoc->
key) || pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2091 case PM_ASSOC_SPLAT_NODE: {
2093 if (assoc->
value != NULL && pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2102 int initial_dup_rest = dup_rest;
2105 if (block && PM_NODE_TYPE_P(block, PM_BLOCK_ARGUMENT_NODE)) {
2109 bool regular_block_arg =
true;
2112 if (block_expr && pm_setup_args_dup_rest_p(block_expr)) {
2113 dup_rest = SPLATARRAY_TRUE | DUP_SINGLE_KW_SPLAT;
2114 initial_dup_rest = dup_rest;
2117 DECL_ANCHOR(block_arg);
2118 pm_compile_node(iseq, block, block_arg,
false, scope_node);
2120 *flags |= VM_CALL_ARGS_BLOCKARG;
2122 if (LIST_INSN_SIZE_ONE(block_arg)) {
2124 if (IS_INSN(elem)) {
2126 if (iobj->insn_id == BIN(getblockparam)) {
2127 iobj->insn_id = BIN(getblockparamproxy);
2134 regular_block_arg =
false;
2138 argc = pm_setup_args_core(arguments_node, block, flags, regular_block_arg, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2139 PUSH_SEQ(ret, block_arg);
2142 argc = pm_setup_args_core(arguments_node, block, flags,
false, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2149 if (*flags & VM_CALL_ARGS_SPLAT && dup_rest != initial_dup_rest) {
2150 *flags |= VM_CALL_ARGS_SPLAT_MUT;
2170 if (!popped) PUSH_INSN(ret, location, putnil);
2172 PM_COMPILE_NOT_POPPED(node->
receiver);
2174 int boff = (node->
block == NULL ? 0 : 1);
2175 int flag = PM_NODE_TYPE_P(node->
receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2177 int argc = pm_setup_args(node->
arguments, (
const pm_node_t *) node->
block, &flag, &keywords, iseq, ret, scope_node, node_location);
2179 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2181 PUSH_INSN(ret, location, splatkw);
2184 PUSH_INSN(ret, location, dup);
2185 PUSH_INSN(ret, location, splatkw);
2186 PUSH_INSN(ret, location, pop);
2190 int dup_argn = argc + 1 + boff;
2191 int keyword_len = 0;
2194 keyword_len = keywords->keyword_len;
2195 dup_argn += keyword_len;
2198 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2199 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2200 PM_COMPILE_NOT_POPPED(node->
value);
2203 PUSH_SEND(ret, location, id_operator,
INT2FIX(1));
2206 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2208 if (flag & VM_CALL_ARGS_SPLAT) {
2209 if (flag & VM_CALL_KW_SPLAT) {
2210 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2212 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2213 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2214 flag |= VM_CALL_ARGS_SPLAT_MUT;
2217 PUSH_INSN(ret, location, swap);
2218 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2219 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2220 PUSH_INSN(ret, location, pop);
2224 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2225 PUSH_INSN(ret, location, swap);
2226 PUSH_INSN(ret, location, pop);
2228 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2229 PUSH_INSN(ret, location, swap);
2230 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2231 PUSH_INSN(ret, location, swap);
2232 flag |= VM_CALL_ARGS_SPLAT_MUT;
2234 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2236 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2237 PUSH_INSN(ret, location, pop);
2238 PUSH_INSN(ret, location, pop);
2242 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2244 else if (flag & VM_CALL_KW_SPLAT) {
2246 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2247 PUSH_INSN(ret, location, swap);
2248 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2249 PUSH_INSN(ret, location, pop);
2251 PUSH_INSN(ret, location, swap);
2252 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2254 else if (keyword_len) {
2255 PUSH_INSN(ret, location, dup);
2256 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 2));
2257 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2258 PUSH_INSN(ret, location, pop);
2259 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2263 PUSH_INSN(ret, location, swap);
2265 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2268 PUSH_INSN(ret, location, pop);
2287 if (!popped) PUSH_INSN(ret, location, putnil);
2288 PM_COMPILE_NOT_POPPED(receiver);
2290 int boff = (block == NULL ? 0 : 1);
2291 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2293 int argc = pm_setup_args(arguments, (
const pm_node_t *) block, &flag, &keywords, iseq, ret, scope_node, node_location);
2295 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2297 PUSH_INSN(ret, location, splatkw);
2300 PUSH_INSN(ret, location, dup);
2301 PUSH_INSN(ret, location, splatkw);
2302 PUSH_INSN(ret, location, pop);
2306 int dup_argn = argc + 1 + boff;
2307 int keyword_len = 0;
2310 keyword_len = keywords->keyword_len;
2311 dup_argn += keyword_len;
2314 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2315 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2317 LABEL *label = NEW_LABEL(location.
line);
2320 PUSH_INSN(ret, location, dup);
2321 if (PM_NODE_TYPE_P(node, PM_INDEX_AND_WRITE_NODE)) {
2322 PUSH_INSNL(ret, location, branchunless, label);
2325 PUSH_INSNL(ret, location, branchif, label);
2328 PUSH_INSN(ret, location, pop);
2329 PM_COMPILE_NOT_POPPED(value);
2332 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2335 if (flag & VM_CALL_ARGS_SPLAT) {
2336 if (flag & VM_CALL_KW_SPLAT) {
2337 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2338 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2339 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2340 flag |= VM_CALL_ARGS_SPLAT_MUT;
2343 PUSH_INSN(ret, location, swap);
2344 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2345 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2346 PUSH_INSN(ret, location, pop);
2350 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2351 PUSH_INSN(ret, location, swap);
2352 PUSH_INSN(ret, location, pop);
2354 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2355 PUSH_INSN(ret, location, swap);
2356 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2357 PUSH_INSN(ret, location, swap);
2358 flag |= VM_CALL_ARGS_SPLAT_MUT;
2360 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2362 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2363 PUSH_INSN(ret, location, pop);
2364 PUSH_INSN(ret, location, pop);
2368 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2370 else if (flag & VM_CALL_KW_SPLAT) {
2372 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2373 PUSH_INSN(ret, location, swap);
2374 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2375 PUSH_INSN(ret, location, pop);
2378 PUSH_INSN(ret, location, swap);
2379 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2381 else if (keyword_len) {
2382 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2383 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 0));
2384 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2388 PUSH_INSN(ret, location, swap);
2390 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2393 PUSH_INSN(ret, location, pop);
2394 PUSH_INSNL(ret, location, jump, lfin);
2395 PUSH_LABEL(ret, label);
2397 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2399 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(dup_argn + 1));
2400 PUSH_LABEL(ret, lfin);
2409#define PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE 0
2410#define PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING 1
2411#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P 2
2412#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE 3
2413#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY 4
2428 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2430 PUSH_INSN(ret, location, dup);
2431 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2433 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2434 PUSH_INSN1(ret, location, putobject, message);
2435 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2436 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2437 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2439 PUSH_INSN1(ret, location, putobject,
Qfalse);
2440 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2442 PUSH_INSN(ret, location, pop);
2443 PUSH_INSN(ret, location, pop);
2444 PUSH_LABEL(ret, match_succeeded_label);
2458 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2460 PUSH_INSN(ret, location, dup);
2461 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2463 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2464 PUSH_INSN1(ret, location, putobject, message);
2465 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2466 PUSH_INSN(ret, location, dup);
2467 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2468 PUSH_INSN1(ret, location, putobject, length);
2469 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(4));
2470 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2472 PUSH_INSN1(ret, location, putobject,
Qfalse);
2473 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2475 PUSH_INSN(ret, location, pop);
2476 PUSH_INSN(ret, location, pop);
2477 PUSH_LABEL(ret, match_succeeded_label);
2491 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2493 PUSH_INSN(ret, location, dup);
2494 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2495 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2497 VALUE operand = rb_fstring_lit(
"%p === %p does not return true");
2498 PUSH_INSN1(ret, location, putobject, operand);
2500 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2501 PUSH_INSN1(ret, location, topn,
INT2FIX(5));
2502 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2503 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2504 PUSH_INSN1(ret, location, putobject,
Qfalse);
2505 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2506 PUSH_INSN(ret, location, pop);
2507 PUSH_INSN(ret, location, pop);
2509 PUSH_LABEL(ret, match_succeeded_label);
2510 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2511 PUSH_INSN(ret, location, pop);
2512 PUSH_INSN(ret, location, pop);
2526 LABEL *matched_label = NEW_LABEL(pm_node_line_number_cached(node, scope_node));
2527 CHECK(pm_compile_pattern(iseq, scope_node, node, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
2528 PUSH_LABEL(ret, matched_label);
2538pm_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)
2542 if (use_deconstructed_cache) {
2543 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2544 PUSH_INSNL(ret, location, branchnil, deconstruct_label);
2546 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2547 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2549 PUSH_INSN(ret, location, pop);
2550 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE - 1));
2551 PUSH_INSNL(ret, location, jump, deconstructed_label);
2554 PUSH_INSNL(ret, location, jump, deconstruct_label);
2557 PUSH_LABEL(ret, deconstruct_label);
2558 PUSH_INSN(ret, location, dup);
2561 PUSH_INSN1(ret, location, putobject, operand);
2562 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2564 if (use_deconstructed_cache) {
2565 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE + 1));
2568 if (in_single_pattern) {
2569 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct"), base_index + 1));
2572 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2573 PUSH_SEND(ret, location, rb_intern(
"deconstruct"),
INT2FIX(0));
2575 if (use_deconstructed_cache) {
2576 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2579 PUSH_INSN(ret, location, dup);
2581 PUSH_INSNL(ret, location, branchunless, type_error_label);
2582 PUSH_LABEL(ret, deconstructed_label);
2596 PUSH_INSN(ret, location, dup);
2597 PM_COMPILE_NOT_POPPED(node);
2599 if (in_single_pattern) {
2600 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
2602 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
2603 if (in_single_pattern) {
2604 CHECK(pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 3));
2606 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2618 LABEL *key_error_label = NEW_LABEL(location.
line);
2619 LABEL *cleanup_label = NEW_LABEL(location.
line);
2622 kw_arg->references = 0;
2623 kw_arg->keyword_len = 2;
2624 kw_arg->keywords[0] =
ID2SYM(rb_intern(
"matchee"));
2625 kw_arg->keywords[1] =
ID2SYM(rb_intern(
"key"));
2627 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2628 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2629 PUSH_INSNL(ret, location, branchif, key_error_label);
2632 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2635 VALUE operand = rb_fstring_lit(
"%p: %s");
2636 PUSH_INSN1(ret, location, putobject, operand);
2639 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2640 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2641 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2642 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2643 PUSH_INSNL(ret, location, jump, cleanup_label);
2645 PUSH_LABEL(ret, key_error_label);
2647 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2650 VALUE operand = rb_fstring_lit(
"%p: %s");
2651 PUSH_INSN1(ret, location, putobject, operand);
2654 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2655 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2656 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2657 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2658 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2659 PUSH_SEND_R(ret, location, rb_intern(
"new"),
INT2FIX(1), NULL,
INT2FIX(VM_CALL_KWARG), kw_arg);
2660 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(1));
2661 PUSH_LABEL(ret, cleanup_label);
2663 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(7));
2664 if (!popped) PUSH_INSN(ret, location, putnil);
2665 PUSH_INSNL(ret, location, jump, done_label);
2666 PUSH_INSN1(ret, location, dupn,
INT2FIX(5));
2667 if (popped) PUSH_INSN(ret, location, putnil);
2678 switch (PM_NODE_TYPE(node)) {
2679 case PM_ARRAY_PATTERN_NODE: {
2691 const size_t posts_size = cast->
posts.
size;
2692 const size_t minimum_size = requireds_size + posts_size;
2694 bool rest_named =
false;
2695 bool use_rest_size =
false;
2697 if (cast->
rest != NULL) {
2698 rest_named = (PM_NODE_TYPE_P(cast->
rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) cast->
rest)->expression != NULL);
2699 use_rest_size = (rest_named || (!rest_named && posts_size > 0));
2702 LABEL *match_failed_label = NEW_LABEL(location.
line);
2703 LABEL *type_error_label = NEW_LABEL(location.
line);
2704 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2705 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2707 if (use_rest_size) {
2708 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2709 PUSH_INSN(ret, location, swap);
2714 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2717 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));
2719 PUSH_INSN(ret, location, dup);
2720 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2721 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2722 PUSH_SEND(ret, location, cast->
rest == NULL ? idEq : idGE,
INT2FIX(1));
2723 if (in_single_pattern) {
2724 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+)");
2725 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, message,
INT2FIX(minimum_size), base_index + 1));
2727 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2729 for (
size_t index = 0; index < requireds_size; index++) {
2731 PUSH_INSN(ret, location, dup);
2732 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2733 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2734 CHECK(pm_compile_pattern_match(iseq, scope_node, required, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2737 if (cast->
rest != NULL) {
2739 PUSH_INSN(ret, location, dup);
2740 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size));
2741 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2742 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2743 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2744 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2745 PUSH_INSN1(ret, location, setn,
INT2FIX(4));
2746 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2747 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));
2749 else if (posts_size > 0) {
2750 PUSH_INSN(ret, location, dup);
2751 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2752 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2753 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2754 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2755 PUSH_INSN(ret, location, pop);
2759 for (
size_t index = 0; index < posts_size; index++) {
2761 PUSH_INSN(ret, location, dup);
2763 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size + index));
2764 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2765 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2766 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2767 CHECK(pm_compile_pattern_match(iseq, scope_node, post, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2770 PUSH_INSN(ret, location, pop);
2771 if (use_rest_size) {
2772 PUSH_INSN(ret, location, pop);
2775 PUSH_INSNL(ret, location, jump, matched_label);
2776 PUSH_INSN(ret, location, putnil);
2777 if (use_rest_size) {
2778 PUSH_INSN(ret, location, putnil);
2781 PUSH_LABEL(ret, type_error_label);
2782 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2786 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2787 PUSH_INSN1(ret, location, putobject, operand);
2790 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2791 PUSH_INSN(ret, location, pop);
2793 PUSH_LABEL(ret, match_failed_label);
2794 PUSH_INSN(ret, location, pop);
2795 if (use_rest_size) {
2796 PUSH_INSN(ret, location, pop);
2799 PUSH_INSNL(ret, location, jump, unmatched_label);
2802 case PM_FIND_PATTERN_NODE: {
2814 LABEL *match_failed_label = NEW_LABEL(location.
line);
2815 LABEL *type_error_label = NEW_LABEL(location.
line);
2816 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2817 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2820 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2823 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));
2825 PUSH_INSN(ret, location, dup);
2826 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2827 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2828 PUSH_SEND(ret, location, idGE,
INT2FIX(1));
2829 if (in_single_pattern) {
2830 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));
2832 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2835 LABEL *while_begin_label = NEW_LABEL(location.
line);
2836 LABEL *next_loop_label = NEW_LABEL(location.
line);
2837 LABEL *find_succeeded_label = NEW_LABEL(location.
line);
2838 LABEL *find_failed_label = NEW_LABEL(location.
line);
2840 PUSH_INSN(ret, location, dup);
2841 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2843 PUSH_INSN(ret, location, dup);
2844 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2845 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2846 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2847 PUSH_LABEL(ret, while_begin_label);
2849 PUSH_INSN(ret, location, dup);
2850 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2851 PUSH_SEND(ret, location, idLE,
INT2FIX(1));
2852 PUSH_INSNL(ret, location, branchunless, find_failed_label);
2854 for (
size_t index = 0; index < size; index++) {
2855 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2856 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2859 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2860 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2863 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2864 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
requireds.
nodes[index], ret, next_loop_label, in_single_pattern,
false, base_index + 4));
2870 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2871 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2872 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2873 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2874 CHECK(pm_compile_pattern_match(iseq, scope_node, left->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4));
2880 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2881 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2882 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2883 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2884 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2885 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2886 pm_compile_pattern_match(iseq, scope_node, right->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4);
2889 PUSH_INSNL(ret, location, jump, find_succeeded_label);
2891 PUSH_LABEL(ret, next_loop_label);
2892 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
2893 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2894 PUSH_INSNL(ret, location, jump, while_begin_label);
2896 PUSH_LABEL(ret, find_failed_label);
2897 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2898 if (in_single_pattern) {
2899 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2902 VALUE operand = rb_fstring_lit(
"%p does not match to find pattern");
2903 PUSH_INSN1(ret, location, putobject, operand);
2906 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2907 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2908 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2910 PUSH_INSN1(ret, location, putobject,
Qfalse);
2911 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2913 PUSH_INSN(ret, location, pop);
2914 PUSH_INSN(ret, location, pop);
2916 PUSH_INSNL(ret, location, jump, match_failed_label);
2917 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2919 PUSH_LABEL(ret, find_succeeded_label);
2920 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2923 PUSH_INSN(ret, location, pop);
2924 PUSH_INSNL(ret, location, jump, matched_label);
2925 PUSH_INSN(ret, location, putnil);
2927 PUSH_LABEL(ret, type_error_label);
2928 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2932 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2933 PUSH_INSN1(ret, location, putobject, operand);
2936 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2937 PUSH_INSN(ret, location, pop);
2939 PUSH_LABEL(ret, match_failed_label);
2940 PUSH_INSN(ret, location, pop);
2941 PUSH_INSNL(ret, location, jump, unmatched_label);
2945 case PM_HASH_PATTERN_NODE: {
2960 LABEL *match_failed_label = NEW_LABEL(location.
line);
2961 LABEL *type_error_label = NEW_LABEL(location.
line);
2964 if (has_keys && !has_rest) {
2967 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2969 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
2980 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2983 PUSH_INSN(ret, location, dup);
2986 VALUE operand =
ID2SYM(rb_intern(
"deconstruct_keys"));
2987 PUSH_INSN1(ret, location, putobject, operand);
2990 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2991 if (in_single_pattern) {
2992 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct_keys"), base_index + 1));
2994 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2997 PUSH_INSN(ret, location, putnil);
3002 PUSH_INSN1(ret, location, duparray, keys);
3005 PUSH_SEND(ret, location, rb_intern(
"deconstruct_keys"),
INT2FIX(1));
3007 PUSH_INSN(ret, location, dup);
3009 PUSH_INSNL(ret, location, branchunless, type_error_label);
3012 PUSH_SEND(ret, location, rb_intern(
"dup"),
INT2FIX(0));
3016 DECL_ANCHOR(match_values);
3018 for (
size_t index = 0; index < cast->
elements.
size; index++) {
3020 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
3027 PUSH_INSN(ret, location, dup);
3028 PUSH_INSN1(ret, location, putobject, symbol);
3029 PUSH_SEND(ret, location, rb_intern(
"key?"),
INT2FIX(1));
3031 if (in_single_pattern) {
3032 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3034 PUSH_INSN(ret, location, dup);
3035 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3040 PUSH_INSN1(ret, location, putobject, operand);
3043 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 2));
3044 PUSH_INSN1(ret, location, putobject,
Qtrue);
3045 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 3));
3046 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
3047 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
3048 PUSH_INSN1(ret, location, putobject, symbol);
3049 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
3051 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(4));
3052 PUSH_LABEL(ret, match_succeeded_label);
3055 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3056 PUSH_INSN(match_values, location, dup);
3057 PUSH_INSN1(match_values, location, putobject, symbol);
3058 PUSH_SEND(match_values, location, has_rest ? rb_intern(
"delete") : idAREF,
INT2FIX(1));
3061 if (PM_NODE_TYPE_P(value, PM_IMPLICIT_NODE)) {
3065 CHECK(pm_compile_pattern_match(iseq, scope_node, value, match_values, match_failed_label, in_single_pattern,
false, base_index + 1));
3068 PUSH_SEQ(ret, match_values);
3071 PUSH_INSN(ret, location, dup);
3072 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3073 if (in_single_pattern) {
3074 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p is not empty"), base_index + 1));
3076 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3080 switch (PM_NODE_TYPE(cast->
rest)) {
3081 case PM_NO_KEYWORDS_PARAMETER_NODE: {
3082 PUSH_INSN(ret, location, dup);
3083 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3084 if (in_single_pattern) {
3085 pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"rest of %p is not empty"), base_index + 1);
3087 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3090 case PM_ASSOC_SPLAT_NODE: {
3092 PUSH_INSN(ret, location, dup);
3093 pm_compile_pattern_match(iseq, scope_node, splat->value, ret, match_failed_label, in_single_pattern,
false, base_index + 1);
3097 rb_bug(
"unreachable");
3102 PUSH_INSN(ret, location, pop);
3103 PUSH_INSNL(ret, location, jump, matched_label);
3104 PUSH_INSN(ret, location, putnil);
3106 PUSH_LABEL(ret, type_error_label);
3107 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
3111 VALUE operand = rb_fstring_lit(
"deconstruct_keys must return Hash");
3112 PUSH_INSN1(ret, location, putobject, operand);
3115 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
3116 PUSH_INSN(ret, location, pop);
3118 PUSH_LABEL(ret, match_failed_label);
3119 PUSH_INSN(ret, location, pop);
3120 PUSH_INSNL(ret, location, jump, unmatched_label);
3123 case PM_CAPTURE_PATTERN_NODE: {
3135 LABEL *match_failed_label = NEW_LABEL(location.
line);
3137 PUSH_INSN(ret, location, dup);
3138 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
value, ret, match_failed_label, in_single_pattern, use_deconstructed_cache, base_index + 1));
3139 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));
3140 PUSH_INSN(ret, location, putnil);
3142 PUSH_LABEL(ret, match_failed_label);
3143 PUSH_INSN(ret, location, pop);
3144 PUSH_INSNL(ret, location, jump, unmatched_label);
3148 case PM_LOCAL_VARIABLE_TARGET_NODE: {
3155 PUSH_SETLOCAL(ret, location, index.index, index.level);
3156 PUSH_INSNL(ret, location, jump, matched_label);
3159 case PM_ALTERNATION_PATTERN_NODE: {
3164 LABEL *matched_left_label = NEW_LABEL(location.
line);
3165 LABEL *unmatched_left_label = NEW_LABEL(location.
line);
3169 PUSH_INSN(ret, location, dup);
3170 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));
3175 PUSH_LABEL(ret, matched_left_label);
3176 PUSH_INSN(ret, location, pop);
3177 PUSH_INSNL(ret, location, jump, matched_label);
3178 PUSH_INSN(ret, location, putnil);
3182 PUSH_LABEL(ret, unmatched_left_label);
3183 CHECK(pm_compile_pattern(iseq, scope_node, cast->
right, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3186 case PM_PARENTHESES_NODE:
3191 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);
3192 case PM_PINNED_EXPRESSION_NODE:
3200 case PM_CLASS_VARIABLE_READ_NODE:
3201 case PM_CONSTANT_PATH_NODE:
3202 case PM_CONSTANT_READ_NODE:
3205 case PM_GLOBAL_VARIABLE_READ_NODE:
3206 case PM_IMAGINARY_NODE:
3207 case PM_INSTANCE_VARIABLE_READ_NODE:
3208 case PM_IT_LOCAL_VARIABLE_READ_NODE:
3209 case PM_INTEGER_NODE:
3210 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
3211 case PM_INTERPOLATED_STRING_NODE:
3212 case PM_INTERPOLATED_SYMBOL_NODE:
3213 case PM_INTERPOLATED_X_STRING_NODE:
3214 case PM_LAMBDA_NODE:
3215 case PM_LOCAL_VARIABLE_READ_NODE:
3217 case PM_SOURCE_ENCODING_NODE:
3218 case PM_SOURCE_FILE_NODE:
3219 case PM_SOURCE_LINE_NODE:
3221 case PM_RATIONAL_NODE:
3222 case PM_REGULAR_EXPRESSION_NODE:
3224 case PM_STRING_NODE:
3225 case PM_SYMBOL_NODE:
3227 case PM_X_STRING_NODE: {
3231 PM_COMPILE_NOT_POPPED(node);
3232 if (in_single_pattern) {
3233 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
3236 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
3238 if (in_single_pattern) {
3239 pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 2);
3242 PUSH_INSNL(ret, location, branchif, matched_label);
3243 PUSH_INSNL(ret, location, jump, unmatched_label);
3246 case PM_PINNED_VARIABLE_NODE: {
3252 CHECK(pm_compile_pattern(iseq, scope_node, cast->
variable, ret, matched_label, unmatched_label, in_single_pattern,
true, base_index));
3256 case PM_UNLESS_NODE: {
3271 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3286 CHECK(pm_compile_pattern_match(iseq, scope_node, statement, ret, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3287 PM_COMPILE_NOT_POPPED(predicate);
3289 if (in_single_pattern) {
3290 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3292 PUSH_INSN(ret, location, dup);
3293 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3294 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3297 PUSH_INSNL(ret, location, branchunless, match_succeeded_label);
3301 VALUE operand = rb_fstring_lit(
"guard clause does not return true");
3302 PUSH_INSN1(ret, location, putobject, operand);
3305 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
3306 PUSH_INSN1(ret, location, putobject,
Qfalse);
3307 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
3309 PUSH_INSN(ret, location, pop);
3310 PUSH_INSN(ret, location, pop);
3312 PUSH_LABEL(ret, match_succeeded_label);
3315 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3316 PUSH_INSNL(ret, location, branchunless, unmatched_label);
3319 PUSH_INSNL(ret, location, branchif, unmatched_label);
3322 PUSH_INSNL(ret, location, jump, matched_label);
3329 rb_bug(
"Unexpected node type in pattern matching expression: %s", pm_node_type(PM_NODE_TYPE(node)));
3336#undef PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE
3337#undef PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING
3338#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P
3339#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE
3340#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY
3351 scope->parameters = NULL;
3353 scope->local_table_for_iseq_size = 0;
3361 scope->base.
type = PM_SCOPE_NODE;
3364 scope->previous = previous;
3367 switch (PM_NODE_TYPE(node)) {
3368 case PM_BLOCK_NODE: {
3370 scope->body = cast->
body;
3371 scope->locals = cast->
locals;
3375 case PM_CLASS_NODE: {
3377 scope->body = cast->
body;
3378 scope->locals = cast->
locals;
3384 scope->body = cast->body;
3385 scope->locals = cast->locals;
3388 case PM_ENSURE_NODE: {
3404 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
3409 case PM_LAMBDA_NODE: {
3412 scope->body = cast->
body;
3413 scope->locals = cast->
locals;
3416 case PM_MODULE_NODE: {
3418 scope->body = cast->
body;
3419 scope->locals = cast->
locals;
3422 case PM_POST_EXECUTION_NODE: {
3427 case PM_PROGRAM_NODE: {
3430 scope->locals = cast->locals;
3433 case PM_RESCUE_NODE: {
3438 case PM_RESCUE_MODIFIER_NODE: {
3443 case PM_SINGLETON_CLASS_NODE: {
3445 scope->body = cast->
body;
3446 scope->locals = cast->
locals;
3449 case PM_STATEMENTS_NODE: {
3455 rb_bug(
"unreachable");
3484 iobj = IS_INSN(last_elem) ? (
INSN*) last_elem : (
INSN*) get_prev_insn((
INSN*) last_elem);
3485 while (!IS_INSN_ID(iobj, send) && !IS_INSN_ID(iobj, invokesuper) && !IS_INSN_ID(iobj, sendforward) && !IS_INSN_ID(iobj, invokesuperforward)) {
3486 iobj = (
INSN*) get_prev_insn(iobj);
3488 ELEM_INSERT_NEXT(&iobj->link, (
LINK_ELEMENT*) retry_end_l);
3493 if (&iobj->link == LAST_ELEMENT(ret)) {
3501 const char *name = rb_id2name(method_id);
3502 static const char prefix[] =
"__builtin_";
3503 const size_t prefix_len =
sizeof(prefix) - 1;
3505 if (receiver == NULL) {
3506 if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) {
3508 return &name[prefix_len];
3511 else if (PM_NODE_TYPE_P(receiver, PM_CALL_NODE)) {
3512 if (PM_NODE_FLAG_P(receiver, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3520 else if (PM_NODE_TYPE_P(receiver, PM_CONSTANT_READ_NODE)) {
3535 if (arguments == NULL) {
3536 COMPILE_ERROR(iseq, node_location->
line,
"attr!: no argument");
3542 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3543 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to attr!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3547 VALUE symbol = pm_static_literal_value(iseq, argument, scope_node);
3548 if (compile_builtin_attr_symbol(iseq, symbol) != COMPILE_OK) {
3549 COMPILE_ERROR(iseq, node_location->
line,
"unknown argument to attr!: %" PRIsVALUE, symbol);
3560 if (arguments == NULL) {
3561 COMPILE_ERROR(iseq, node_location->
line,
"arg!: no argument");
3566 COMPILE_ERROR(iseq, node_location->
line,
"arg!: too many argument");
3571 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3572 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to arg!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3578 int index = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->local_table_size - get_local_var_idx(iseq, name);
3580 debugs(
"id: %s idx: %d\n", rb_id2name(name), index);
3581 PUSH_GETLOCAL(ret, *node_location, index, get_lvar_level(iseq));
3590 const pm_node_t *ast_node = scope_node->ast_node;
3591 if (!PM_NODE_TYPE_P(ast_node, PM_DEF_NODE)) {
3592 rb_bug(
"mandatory_only?: not in method definition");
3598 if (parameters_node == NULL) {
3599 rb_bug(
"mandatory_only?: in method definition with no parameters");
3604 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)) {
3605 rb_bug(
"mandatory_only?: not in method definition with plain statements");
3611 rb_bug(
"mandatory_only?: can't find mandatory node");
3622 .name = def_node->
name,
3624 .parameters = ¶meters,
3634 pm_scope_node_init(&def.base, &next_scope_node, scope_node);
3636 const rb_iseq_t *mandatory_only_iseq = pm_iseq_build(
3638 rb_iseq_base_label(iseq),
3640 rb_iseq_realpath(iseq),
3641 node_location->
line,
3645 ISEQ_COMPILE_DATA(iseq)->option
3647 RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->mandatory_only_iseq, (
VALUE)mandatory_only_iseq);
3649 pm_scope_node_destroy(&next_scope_node);
3658 if (parent_block != NULL) {
3659 COMPILE_ERROR(iseq, node_location->
line,
"should not call builtins here.");
3663#define BUILTIN_INLINE_PREFIX "_bi"
3664 char inline_func[
sizeof(BUILTIN_INLINE_PREFIX) +
DECIMAL_SIZE_OF(
int)];
3665 bool cconst =
false;
3670 if (strcmp(
"cstmt!", builtin_func) == 0 || strcmp(
"cexpr!", builtin_func) == 0) {
3673 else if (strcmp(
"cconst!", builtin_func) == 0) {
3676 else if (strcmp(
"cinit!", builtin_func) == 0) {
3680 else if (strcmp(
"attr!", builtin_func) == 0) {
3681 return pm_compile_builtin_attr(iseq, scope_node, arguments, node_location);
3683 else if (strcmp(
"arg!", builtin_func) == 0) {
3684 return pm_compile_builtin_arg(iseq, ret, scope_node, arguments, node_location, popped);
3686 else if (strcmp(
"mandatory_only?", builtin_func) == 0) {
3688 rb_bug(
"mandatory_only? should be in if condition");
3690 else if (!LIST_INSN_SIZE_ZERO(ret)) {
3691 rb_bug(
"mandatory_only? should be put on top");
3694 PUSH_INSN1(ret, *node_location, putobject,
Qfalse);
3695 return pm_compile_builtin_mandatory_only_method(iseq, scope_node, call_node, node_location);
3697 else if (strcmp(
"local_self!", builtin_func) == 0) {
3700 pm_constant_id_t self_id = pm_parser_constant_find(scope_node->parser, (
const uint8_t *)
"self", 4);
3702 COMPILE_ERROR(iseq, node_location->
line,
"local_self! called but 'self' not found in local table");
3705 pm_local_index_t self_index = pm_lookup_local_index(iseq, scope_node, self_id, 0);
3706 PUSH_GETLOCAL(ret, *node_location, self_index.index, self_index.level);
3710 rb_bug(
"can't find builtin function:%s", builtin_func);
3713 COMPILE_ERROR(iseq, node_location->
line,
"can't find builtin function:%s", builtin_func);
3717 int inline_index = node_location->
line;
3718 snprintf(inline_func,
sizeof(inline_func), BUILTIN_INLINE_PREFIX
"%d", inline_index);
3719 builtin_func = inline_func;
3725 typedef VALUE(*builtin_func0)(
void *,
VALUE);
3726 VALUE const_val = (*(builtin_func0)(uintptr_t)bf->func_ptr)(NULL,
Qnil);
3727 PUSH_INSN1(ret, *node_location, putobject, const_val);
3733 DECL_ANCHOR(args_seq);
3737 int argc = pm_setup_args(arguments, call_node->
block, &flags, &keywords, iseq, args_seq, scope_node, node_location);
3739 if (argc != bf->argc) {
3740 COMPILE_ERROR(iseq, node_location->
line,
"argc is not match for builtin function:%s (expect %d but %d)", builtin_func, bf->argc, argc);
3744 unsigned int start_index;
3745 if (delegate_call_p(iseq, argc, args_seq, &start_index)) {
3746 PUSH_INSN2(ret, *node_location, opt_invokebuiltin_delegate, bf,
INT2FIX(start_index));
3749 PUSH_SEQ(ret, args_seq);
3750 PUSH_INSN1(ret, *node_location, invokebuiltin, bf);
3753 if (popped) PUSH_INSN(ret, *node_location, pop);
3768 LABEL *else_label = NEW_LABEL(location.
line);
3769 LABEL *end_label = NEW_LABEL(location.
line);
3770 LABEL *retry_end_l = NEW_LABEL(location.
line);
3774 int node_id = location.
node_id;
3776 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3777 if (PM_BRANCH_COVERAGE_P(iseq)) {
3778 uint32_t end_cursor = 0;
3779 bool end_found =
false;
3783 end_cursor = cursor;
3789 if (!end_found || cursor > end_cursor) {
3790 end_cursor = cursor;
3797 if (!end_found || cursor > end_cursor) {
3798 end_cursor = cursor;
3807 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(call_node);
3808 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);
3811 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
3812 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
3815 branches = decl_branch_base(iseq, (
int) call_node->
base.
node_id, &code_location,
"&.");
3818 PUSH_INSN(ret, location, dup);
3819 PUSH_INSNL(ret, location, branchnil, else_label);
3821 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0,
"then", branches);
3829 int orig_argc = pm_setup_args(call_node->
arguments, call_node->
block, &flags, &kw_arg, iseq, ret, scope_node, &location);
3830 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
3833 if (call_node->
block != NULL && PM_NODE_TYPE_P(call_node->
block, PM_BLOCK_NODE)) {
3836 pm_scope_node_init(call_node->
block, &next_scope_node, scope_node);
3838 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));
3839 pm_scope_node_destroy(&next_scope_node);
3840 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
3843 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3844 flags |= VM_CALL_VCALL;
3848 flags |= VM_CALL_ARGS_SIMPLE;
3852 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
3853 flags |= VM_CALL_FCALL;
3856 if (!popped && PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE)) {
3857 if (flags & VM_CALL_ARGS_BLOCKARG) {
3858 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
3859 if (flags & VM_CALL_ARGS_SPLAT) {
3860 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3861 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3863 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 3));
3864 PUSH_INSN(ret, location, pop);
3866 else if (flags & VM_CALL_ARGS_SPLAT) {
3867 PUSH_INSN(ret, location, dup);
3868 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3869 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3870 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 2));
3871 PUSH_INSN(ret, location, pop);
3874 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 1));
3878 if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
3879 PUSH_INSN(ret, location, splatkw);
3882 LABEL *not_basic_new = NEW_LABEL(location.
line);
3883 LABEL *not_basic_new_finish = NEW_LABEL(location.
line);
3885 bool inline_new = ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction &&
3886 method_id == rb_intern(
"new") &&
3887 call_node->
block == NULL &&
3888 (flags & VM_CALL_ARGS_BLOCKARG) == 0;
3891 if (LAST_ELEMENT(ret) == opt_new_prelude) {
3892 PUSH_INSN(ret, location, putnil);
3893 PUSH_INSN(ret, location, swap);
3896 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(swap), 0)->link);
3897 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(putnil), 0)->link);
3900 rb_callinfo_kwarg_retain(kw_arg);
3904 if (flags & VM_CALL_FORWARDING) {
3905 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc + 1, flags, kw_arg, 0);
3908 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc, flags, kw_arg, 0);
3911 PUSH_INSN2(ret, location, opt_new, ci, not_basic_new);
3912 LABEL_REF(not_basic_new);
3914 PUSH_SEND_R(ret, location, rb_intern(
"initialize"),
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags | VM_CALL_FCALL), kw_arg);
3915 PUSH_INSNL(ret, location, jump, not_basic_new_finish);
3917 PUSH_LABEL(ret, not_basic_new);
3919 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3920 PUSH_INSN(ret, location, swap);
3922 PUSH_LABEL(ret, not_basic_new_finish);
3923 PUSH_INSN(ret, location, pop);
3925 rb_callinfo_kwarg_release(kw_arg);
3928 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3931 if (block_iseq && ISEQ_BODY(block_iseq)->catch_table) {
3932 pm_compile_retry_end_label(iseq, ret, retry_end_l);
3933 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, start, retry_end_l, block_iseq, retry_end_l);
3936 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3937 PUSH_INSNL(ret, location, jump, end_label);
3938 PUSH_LABEL(ret, else_label);
3939 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 1,
"else", branches);
3940 PUSH_LABEL(ret, end_label);
3943 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
3944 PUSH_INSN(ret, location, pop);
3947 if (popped) PUSH_INSN(ret, location, pop);
3948 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
3958 const char *
type = (
const char *) (pm_parser_start(scope_node->parser) + node->
base.
location.
start + 1);
3978#define PUSH_VAL(type) (in_condition ? Qtrue : rb_iseq_defined_string(type))
3981 enum defined_type dtype = DEFINED_NOT_DEFINED;
3984 switch (PM_NODE_TYPE(node)) {
3989 dtype = DEFINED_NIL;
3992 case PM_INSTANCE_VARIABLE_READ_NODE: {
3996 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3998 PUSH_INSN3(ret, location, definedivar,
ID2SYM(name), get_ivar_ic_value(iseq, name), PUSH_VAL(DEFINED_IVAR));
4003 case PM_LOCAL_VARIABLE_READ_NODE:
4006 case PM_IT_LOCAL_VARIABLE_READ_NODE:
4009 dtype = DEFINED_LVAR;
4012 case PM_GLOBAL_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_GVAR),
ID2SYM(name), PUSH_VAL(DEFINED_GVAR));
4024 case PM_CLASS_VARIABLE_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_CVAR),
ID2SYM(name), PUSH_VAL(DEFINED_CVAR));
4036 case PM_CONSTANT_READ_NODE: {
4040 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4042 PUSH_INSN(ret, location, putnil);
4043 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4051 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
4053 PUSH_INSN(ret, location, putnil);
4054 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
4058 case PM_SUPER_NODE: {
4063 if (cast->
block != NULL && !PM_NODE_TYPE_P(cast->
block, PM_BLOCK_ARGUMENT_NODE)) {
4064 dtype = DEFINED_EXPR;
4068 PUSH_INSN(ret, location, putnil);
4069 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4072 case PM_FORWARDING_SUPER_NODE: {
4077 if (cast->
block != NULL) {
4078 dtype = DEFINED_EXPR;
4082 PUSH_INSN(ret, location, putnil);
4083 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4090 dtype = DEFINED_SELF;
4096 dtype = DEFINED_TRUE;
4102 dtype = DEFINED_FALSE;
4105 case PM_CALL_AND_WRITE_NODE:
4108 case PM_CALL_OPERATOR_WRITE_NODE:
4111 case PM_CALL_OR_WRITE_NODE:
4114 case PM_CLASS_VARIABLE_AND_WRITE_NODE:
4117 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE:
4120 case PM_CLASS_VARIABLE_OR_WRITE_NODE:
4123 case PM_CLASS_VARIABLE_WRITE_NODE:
4126 case PM_CONSTANT_AND_WRITE_NODE:
4129 case PM_CONSTANT_OPERATOR_WRITE_NODE:
4132 case PM_CONSTANT_OR_WRITE_NODE:
4135 case PM_CONSTANT_PATH_AND_WRITE_NODE:
4138 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
4141 case PM_CONSTANT_PATH_OR_WRITE_NODE:
4144 case PM_CONSTANT_PATH_WRITE_NODE:
4147 case PM_CONSTANT_WRITE_NODE:
4150 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE:
4153 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE:
4156 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE:
4159 case PM_GLOBAL_VARIABLE_WRITE_NODE:
4162 case PM_INDEX_AND_WRITE_NODE:
4165 case PM_INDEX_OPERATOR_WRITE_NODE:
4168 case PM_INDEX_OR_WRITE_NODE:
4171 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE:
4174 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE:
4177 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE:
4180 case PM_INSTANCE_VARIABLE_WRITE_NODE:
4183 case PM_LOCAL_VARIABLE_AND_WRITE_NODE:
4186 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE:
4189 case PM_LOCAL_VARIABLE_OR_WRITE_NODE:
4192 case PM_LOCAL_VARIABLE_WRITE_NODE:
4195 case PM_MULTI_WRITE_NODE:
4198 dtype = DEFINED_ASGN;
4201 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
4204 case PM_ALIAS_METHOD_NODE:
4213 case PM_CASE_MATCH_NODE:
4225 case PM_DEFINED_NODE:
4228 case PM_FLIP_FLOP_NODE:
4240 case PM_IMAGINARY_NODE:
4243 case PM_INTEGER_NODE:
4246 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE:
4249 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
4252 case PM_INTERPOLATED_STRING_NODE:
4255 case PM_INTERPOLATED_SYMBOL_NODE:
4258 case PM_INTERPOLATED_X_STRING_NODE:
4261 case PM_LAMBDA_NODE:
4264 case PM_MATCH_LAST_LINE_NODE:
4267 case PM_MATCH_PREDICATE_NODE:
4270 case PM_MATCH_REQUIRED_NODE:
4273 case PM_MATCH_WRITE_NODE:
4276 case PM_MODULE_NODE:
4285 case PM_POST_EXECUTION_NODE:
4291 case PM_RATIONAL_NODE:
4297 case PM_REGULAR_EXPRESSION_NODE:
4300 case PM_RESCUE_MODIFIER_NODE:
4306 case PM_RETURN_NODE:
4309 case PM_SINGLETON_CLASS_NODE:
4312 case PM_SOURCE_ENCODING_NODE:
4315 case PM_SOURCE_FILE_NODE:
4318 case PM_SOURCE_LINE_NODE:
4321 case PM_STRING_NODE:
4324 case PM_SYMBOL_NODE:
4330 case PM_UNLESS_NODE:
4339 case PM_X_STRING_NODE:
4342 dtype = DEFINED_EXPR;
4345 case PM_BACK_REFERENCE_READ_NODE: {
4349 VALUE ref = pm_compile_back_reference_ref(scope_node, cast);
4351 PUSH_INSN(ret, location, putnil);
4352 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4356 case PM_NUMBERED_REFERENCE_READ_NODE: {
4360 VALUE ref = pm_compile_numbered_reference_ref(cast);
4362 PUSH_INSN(ret, location, putnil);
4363 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4368 case PM_CONSTANT_PATH_NODE: {
4372 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4374 if (cast->
parent != NULL) {
4375 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4376 pm_compile_defined_expr0(iseq, cast->
parent, node_location, ret, popped, scope_node,
true, lfinish,
false);
4378 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4379 PM_COMPILE(cast->
parent);
4382 PUSH_INSN1(ret, location, putobject,
rb_cObject);
4385 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4389 case PM_BEGIN_NODE: {
4397 dtype = DEFINED_NIL;
4403 pm_compile_defined_expr0(iseq, cast->
statements->
body.
nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4409 dtype = DEFINED_EXPR;
4414 dtype = DEFINED_EXPR;
4419 case PM_PARENTHESES_NODE: {
4424 if (cast->
body == NULL) {
4426 dtype = DEFINED_NIL;
4428 else if (PM_NODE_TYPE_P(cast->
body, PM_STATEMENTS_NODE) && !PM_NODE_FLAG_P(cast, PM_PARENTHESES_NODE_FLAGS_MULTIPLE_STATEMENTS)) {
4431 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);
4437 dtype = DEFINED_EXPR;
4442 case PM_ARRAY_NODE: {
4448 lfinish[1] = NEW_LABEL(location.
line);
4451 for (
size_t index = 0; index < cast->
elements.
size; index++) {
4452 pm_compile_defined_expr0(iseq, cast->
elements.
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4453 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4456 dtype = DEFINED_EXPR;
4462 case PM_KEYWORD_HASH_NODE: {
4467 if (PM_NODE_TYPE_P(node, PM_HASH_NODE)) {
4474 if (elements->
size > 0 && !lfinish[1]) {
4475 lfinish[1] = NEW_LABEL(location.
line);
4478 for (
size_t index = 0; index < elements->
size; index++) {
4479 pm_compile_defined_expr0(iseq, elements->
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4480 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4483 dtype = DEFINED_EXPR;
4486 case PM_ASSOC_NODE: {
4491 pm_compile_defined_expr0(iseq, cast->
key, node_location, ret, popped, scope_node,
true, lfinish,
false);
4492 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4493 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4497 case PM_ASSOC_SPLAT_NODE: {
4502 if (cast->
value == NULL) {
4503 dtype = DEFINED_EXPR;
4507 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4510 case PM_IMPLICIT_NODE: {
4514 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4517 case PM_CALL_NODE: {
4518#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE))
4524 if (BLOCK_P(cast)) {
4525 dtype = DEFINED_EXPR;
4530 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4531 if (!lfinish[2]) lfinish[2] = NEW_LABEL(location.
line);
4535 pm_compile_defined_expr0(iseq, (
const pm_node_t *) cast->
arguments, node_location, ret, popped, scope_node,
true, lfinish,
false);
4536 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4539 if (cast->
block && PM_NODE_TYPE_P(cast->
block, PM_BLOCK_ARGUMENT_NODE)) {
4540 pm_compile_defined_expr0(iseq, cast->
block, node_location, ret, popped, scope_node,
true, lfinish,
false);
4541 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4548 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
true);
4549 PUSH_INSNL(ret, location, branchunless, lfinish[2]);
4552 ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
4554 pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
4557 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
false);
4558 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4562 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4564 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4565 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_METHOD),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4568 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4570 PUSH_INSN(ret, location, putself);
4571 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4573 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_FUNC),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4580 case PM_ARGUMENTS_NODE: {
4585 for (
size_t index = 0; index < cast->
arguments.
size; index++) {
4586 pm_compile_defined_expr0(iseq, cast->
arguments.
nodes[index], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4587 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4590 dtype = DEFINED_EXPR;
4593 case PM_BLOCK_ARGUMENT_NODE:
4596 dtype = DEFINED_EXPR;
4598 case PM_FORWARDING_ARGUMENTS_NODE:
4601 dtype = DEFINED_EXPR;
4603 case PM_SPLAT_NODE: {
4609 dtype = DEFINED_EXPR;
4613 pm_compile_defined_expr0(iseq, cast->
expression, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4615 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4616 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4618 dtype = DEFINED_EXPR;
4621 case PM_SHAREABLE_CONSTANT_NODE:
4625 pm_compile_defined_expr0(iseq, ((
const pm_shareable_constant_node_t *) node)->write, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4628 case PM_BLOCK_LOCAL_VARIABLE_NODE:
4629 case PM_BLOCK_PARAMETER_NODE:
4630 case PM_BLOCK_PARAMETERS_NODE:
4631 case PM_FORWARDING_PARAMETER_NODE:
4632 case PM_IMPLICIT_REST_NODE:
4633 case PM_IT_PARAMETERS_NODE:
4634 case PM_PARAMETERS_NODE:
4635 case PM_KEYWORD_REST_PARAMETER_NODE:
4636 case PM_NO_KEYWORDS_PARAMETER_NODE:
4637 case PM_NO_BLOCK_PARAMETER_NODE:
4638 case PM_NUMBERED_PARAMETERS_NODE:
4639 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE:
4640 case PM_OPTIONAL_PARAMETER_NODE:
4641 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
4642 case PM_REQUIRED_PARAMETER_NODE:
4643 case PM_REST_PARAMETER_NODE:
4645 case PM_ALTERNATION_PATTERN_NODE:
4646 case PM_ARRAY_PATTERN_NODE:
4647 case PM_CAPTURE_PATTERN_NODE:
4648 case PM_FIND_PATTERN_NODE:
4649 case PM_HASH_PATTERN_NODE:
4650 case PM_PINNED_EXPRESSION_NODE:
4651 case PM_PINNED_VARIABLE_NODE:
4653 case PM_CALL_TARGET_NODE:
4654 case PM_CLASS_VARIABLE_TARGET_NODE:
4655 case PM_CONSTANT_PATH_TARGET_NODE:
4656 case PM_CONSTANT_TARGET_NODE:
4657 case PM_GLOBAL_VARIABLE_TARGET_NODE:
4658 case PM_INDEX_TARGET_NODE:
4659 case PM_INSTANCE_VARIABLE_TARGET_NODE:
4660 case PM_LOCAL_VARIABLE_TARGET_NODE:
4661 case PM_MULTI_TARGET_NODE:
4664 case PM_ENSURE_NODE:
4666 case PM_RESCUE_NODE:
4670 case PM_EMBEDDED_STATEMENTS_NODE:
4671 case PM_EMBEDDED_VARIABLE_NODE:
4672 case PM_ERROR_RECOVERY_NODE:
4673 case PM_PRE_EXECUTION_NODE:
4674 case PM_PROGRAM_NODE:
4676 case PM_STATEMENTS_NODE:
4677 rb_bug(
"Unreachable node in defined?: %s", pm_node_type(PM_NODE_TYPE(node)));
4681 PUSH_INSN1(ret, location, putobject, PUSH_VAL(dtype));
4690 pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4693 LABEL *lstart = NEW_LABEL(node_location->
line);
4694 LABEL *lend = NEW_LABEL(node_location->
line);
4697 rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
4699 const rb_iseq_t *rescue = new_child_iseq_with_callback(
4708 lstart->rescued = LABEL_RESCUE_BEG;
4709 lend->rescued = LABEL_RESCUE_END;
4711 APPEND_LABEL(ret, lcur, lstart);
4712 PUSH_LABEL(ret, lend);
4713 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
4723 lfinish[0] = NEW_LABEL(node_location->
line);
4728 pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish);
4732 ELEM_INSERT_NEXT(last, &new_insn_body(iseq, node_location->
line, node_location->
node_id, BIN(putnil), 0)->link);
4733 PUSH_INSN(ret, *node_location, swap);
4735 if (lfinish[2]) PUSH_LABEL(ret, lfinish[2]);
4736 PUSH_INSN(ret, *node_location, pop);
4737 PUSH_LABEL(ret, lfinish[1]);
4741 PUSH_LABEL(ret, lfinish[0]);
4752 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
4754 DECL_ANCHOR(ensure);
4757 if (enlp->erange != NULL) {
4758 DECL_ANCHOR(ensure_part);
4759 LABEL *lstart = NEW_LABEL(0);
4760 LABEL *lend = NEW_LABEL(0);
4762 add_ensure_range(iseq, enlp->erange, lstart, lend);
4764 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
4765 PUSH_LABEL(ensure_part, lstart);
4767 PM_COMPILE_INTO_ANCHOR(ensure_part, (
const pm_node_t *) enlp->ensure_node);
4768 PUSH_LABEL(ensure_part, lend);
4769 PUSH_SEQ(ensure, ensure_part);
4778 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
4779 PUSH_SEQ(ret, ensure);
4792 RUBY_ASSERT((constant_id & PM_SPECIAL_CONSTANT_FLAG) == 0);
4794 ID local = pm_constant_id_lookup(scope_node, constant_id);
4795 local_table_for_iseq->ids[local_index] = local;
4796 pm_index_lookup_table_insert(index_lookup_table, constant_id, local_index);
4805 local_table_for_iseq->ids[local_index] = local_name;
4806 pm_index_lookup_table_insert(index_lookup_table, special_id, local_index);
4818 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4821 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4822 if (!PM_NODE_FLAG_P(left, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4823 pm_insert_local_index(((
const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4828 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4829 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);
4833 if (node->
rest != NULL && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE)) {
4836 if (rest->expression != NULL) {
4837 RUBY_ASSERT(PM_NODE_TYPE_P(rest->expression, PM_REQUIRED_PARAMETER_NODE));
4839 if (!PM_NODE_FLAG_P(rest->expression, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4840 pm_insert_local_index(((
const pm_required_parameter_node_t *) rest->expression)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4846 for (
size_t index = 0; index < node->
rights.
size; index++) {
4849 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4850 if (!PM_NODE_FLAG_P(right, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4851 pm_insert_local_index(((
const pm_required_parameter_node_t *) right)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4856 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4857 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);
4873 PUSH_SETLOCAL(ret, location, index.index, index.level);
4888 bool has_rest = (node->
rest && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE) && (((
const pm_splat_node_t *) node->
rest)->expression) != NULL);
4891 int flag = (has_rest || has_rights) ? 1 : 0;
4894 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4897 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4901 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4912 RUBY_ASSERT(PM_NODE_TYPE_P(rest, PM_REQUIRED_PARAMETER_NODE));
4922 for (
size_t index = 0; index < node->
rights.
size; index++) {
4925 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4929 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4989 node->stack_index = state->stack_size + 1;
4990 node->stack_size = stack_size;
4991 node->position = state->position;
4994 if (state->head == NULL) {
4999 state->tail->next = node;
5003 state->stack_size += stack_size;
5016 if (state->stack_size == 0)
return;
5021 while (current != NULL) {
5022 VALUE offset =
INT2FIX(state->stack_size - current->stack_index + current->position);
5023 current->topn->operands[0] = offset;
5029 if (current->stack_size > 1) {
5030 INSN *insn = current->topn;
5032 for (
size_t index = 1; index < current->stack_size; index += 1) {
5036 insn = (
INSN *) element;
5039 insn->operands[0] = offset;
5044 current = current->next;
5046 SIZED_FREE(previous);
5086 switch (PM_NODE_TYPE(node)) {
5087 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5096 PUSH_SETLOCAL(writes, location, index.index, index.level);
5099 case PM_CLASS_VARIABLE_TARGET_NODE: {
5106 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5109 PUSH_INSN2(writes, location, setclassvariable, operand, get_cvar_ic_value(iseq, name));
5112 case PM_CONSTANT_TARGET_NODE: {
5119 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5122 PUSH_INSN1(writes, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5123 PUSH_INSN1(writes, location, setconstant, operand);
5126 case PM_GLOBAL_VARIABLE_TARGET_NODE: {
5133 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5136 PUSH_INSN1(writes, location, setglobal, operand);
5139 case PM_INSTANCE_VARIABLE_TARGET_NODE: {
5146 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5149 PUSH_INSN2(writes, location, setinstancevariable, operand, get_ivar_ic_value(iseq, name));
5152 case PM_CONSTANT_PATH_TARGET_NODE: {
5162 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5164 if (cast->
parent != NULL) {
5165 pm_compile_node(iseq, cast->
parent, parents,
false, scope_node);
5168 PUSH_INSN1(parents, location, putobject,
rb_cObject);
5171 if (state == NULL) {
5172 PUSH_INSN(writes, location, swap);
5175 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5176 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5180 PUSH_INSN1(writes, location, setconstant, operand);
5182 if (state != NULL) {
5183 PUSH_INSN(cleanup, location, pop);
5188 case PM_CALL_TARGET_NODE: {
5198 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
5200 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5202 LABEL *safe_label = NULL;
5203 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
5204 safe_label = NEW_LABEL(location.
line);
5205 PUSH_INSN(parents, location, dup);
5206 PUSH_INSNL(parents, location, branchnil, safe_label);
5209 if (state != NULL) {
5210 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5211 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5212 PUSH_INSN(writes, location, swap);
5215 int flags = VM_CALL_ARGS_SIMPLE;
5216 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) flags |= VM_CALL_FCALL;
5218 PUSH_SEND_WITH_FLAG(writes, location, method_id,
INT2FIX(1),
INT2FIX(flags));
5219 if (safe_label != NULL && state == NULL) PUSH_LABEL(writes, safe_label);
5220 PUSH_INSN(writes, location, pop);
5221 if (safe_label != NULL && state != NULL) PUSH_LABEL(writes, safe_label);
5223 if (state != NULL) {
5224 PUSH_INSN(cleanup, location, pop);
5229 case PM_INDEX_TARGET_NODE: {
5241 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5245 int argc = pm_setup_args(cast->
arguments, (
const pm_node_t *) cast->
block, &flags, &kwargs, iseq, parents, scope_node, &location);
5247 if (state != NULL) {
5248 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5249 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), argc + 1);
5252 PUSH_INSN(writes, location, swap);
5255 for (
int index = 0; index < argc; index++) {
5256 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5258 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5266 int ci_argc = argc + 1;
5267 if (flags & VM_CALL_ARGS_SPLAT) {
5269 PUSH_INSN1(writes, location, newarray,
INT2FIX(1));
5270 PUSH_INSN(writes, location, concatarray);
5273 PUSH_SEND_R(writes, location, idASET,
INT2NUM(ci_argc), NULL,
INT2FIX(flags), kwargs);
5274 PUSH_INSN(writes, location, pop);
5276 if (state != NULL) {
5278 PUSH_INSN(writes, location, pop);
5281 for (
int index = 0; index < argc + 1; index++) {
5282 PUSH_INSN(cleanup, location, pop);
5288 case PM_MULTI_TARGET_NODE: {
5295 size_t before_position;
5296 if (state != NULL) {
5297 before_position = state->position;
5301 pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, scope_node, state);
5302 if (state != NULL) state->position = before_position;
5306 case PM_SPLAT_NODE: {
5315 pm_compile_target_node(iseq, cast->
expression, parents, writes, cleanup, scope_node, state);
5321 rb_bug(
"Unexpected node type: %s", pm_node_type(PM_NODE_TYPE(node)));
5339 switch (PM_NODE_TYPE(node)) {
5340 case PM_MULTI_TARGET_NODE: {
5342 lefts = &cast->
lefts;
5347 case PM_MULTI_WRITE_NODE: {
5349 lefts = &cast->
lefts;
5355 rb_bug(
"Unsupported node %s", pm_node_type(PM_NODE_TYPE(node)));
5359 bool has_rest = (rest != NULL) && PM_NODE_TYPE_P(rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) rest)->expression != NULL;
5360 bool has_posts = rights->
size > 0;
5365 PUSH_INSN2(writes, location, expandarray,
INT2FIX(lefts->
size),
INT2FIX((has_rest || has_posts) ? 1 : 0));
5371 if (state == NULL) state = &target_state;
5373 size_t base_position = state->position;
5374 size_t splat_position = (has_rest || has_posts) ? 1 : 0;
5377 for (
size_t index = 0; index < lefts->
size; index++) {
5379 state->position = lefts->
size - index + splat_position + base_position;
5380 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5386 state->position = 1 + rights->
size + base_position;
5392 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5397 if (!has_rest && rest != NULL) {
5401 for (
size_t index = 0; index < rights->
size; index++) {
5403 state->position = rights->
size - index + base_position;
5404 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5419 switch (PM_NODE_TYPE(node)) {
5420 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5423 PUSH_GETLOCAL(ret, location, 1, 0);
5424 pm_compile_target_node(iseq, node, ret, ret, ret, scope_node, NULL);
5427 case PM_CLASS_VARIABLE_TARGET_NODE:
5428 case PM_CONSTANT_TARGET_NODE:
5429 case PM_GLOBAL_VARIABLE_TARGET_NODE:
5430 case PM_INSTANCE_VARIABLE_TARGET_NODE:
5431 case PM_CONSTANT_PATH_TARGET_NODE:
5432 case PM_CALL_TARGET_NODE:
5433 case PM_INDEX_TARGET_NODE: {
5437 DECL_ANCHOR(writes);
5438 DECL_ANCHOR(cleanup);
5442 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
5444 PUSH_GETLOCAL(ret, location, 1, 0);
5447 PUSH_SEQ(ret, writes);
5448 PUSH_SEQ(ret, cleanup);
5450 pm_multi_target_state_update(&state);
5454 case PM_MULTI_TARGET_NODE: {
5455 DECL_ANCHOR(writes);
5456 DECL_ANCHOR(cleanup);
5458 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, NULL);
5460 LABEL *not_single = NEW_LABEL(location.
line);
5461 LABEL *not_ary = NEW_LABEL(location.
line);
5469 PUSH_GETLOCAL(ret, location, 1, 0);
5470 PUSH_INSN(ret, location, dup);
5471 PUSH_CALL(ret, location, idLength,
INT2FIX(0));
5472 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
5473 PUSH_CALL(ret, location, idEq,
INT2FIX(1));
5474 PUSH_INSNL(ret, location, branchunless, not_single);
5475 PUSH_INSN(ret, location, dup);
5476 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
5477 PUSH_CALL(ret, location, idAREF,
INT2FIX(1));
5478 PUSH_INSN1(ret, location, putobject,
rb_cArray);
5479 PUSH_INSN(ret, location, swap);
5480 PUSH_CALL(ret, location, rb_intern(
"try_convert"),
INT2FIX(1));
5481 PUSH_INSN(ret, location, dup);
5482 PUSH_INSNL(ret, location, branchunless, not_ary);
5483 PUSH_INSN(ret, location, swap);
5485 PUSH_LABEL(ret, not_ary);
5486 PUSH_INSN(ret, location, pop);
5488 PUSH_LABEL(ret, not_single);
5490 if (PM_NODE_TYPE_P(node, PM_SPLAT_NODE)) {
5495 PUSH_SEQ(ret, writes);
5496 PUSH_SEQ(ret, cleanup);
5500 rb_bug(
"Unexpected node type for index in for node: %s", pm_node_type(PM_NODE_TYPE(node)));
5508 LABEL *lstart = NEW_LABEL(node_location->
line);
5509 LABEL *lend = NEW_LABEL(node_location->
line);
5510 LABEL *lcont = NEW_LABEL(node_location->
line);
5515 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
5522 pm_scope_node_destroy(&rescue_scope_node);
5524 lstart->rescued = LABEL_RESCUE_BEG;
5525 lend->rescued = LABEL_RESCUE_END;
5526 PUSH_LABEL(ret, lstart);
5528 bool prev_in_rescue = ISEQ_COMPILE_DATA(iseq)->in_rescue;
5529 ISEQ_COMPILE_DATA(iseq)->in_rescue =
true;
5536 PUSH_INSN(ret, location, putnil);
5539 ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;
5540 PUSH_LABEL(ret, lend);
5543 if (!popped) PUSH_INSN(ret, *node_location, pop);
5547 PUSH_INSN(ret, *node_location, nop);
5548 PUSH_LABEL(ret, lcont);
5550 if (popped) PUSH_INSN(ret, *node_location, pop);
5551 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
5552 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
5561 if (statements != NULL) {
5562 location = PM_NODE_START_LOCATION(statements);
5565 location = *node_location;
5568 LABEL *lstart = NEW_LABEL(location.
line);
5570 LABEL *lcont = NEW_LABEL(location.
line);
5577 if (statements != NULL) {
5578 pm_compile_node(iseq, (
const pm_node_t *) statements, ensr,
true, scope_node);
5582 bool last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
5587 push_ensure_entry(iseq, &enl, &er, (
void *) cast->
ensure_clause);
5589 PUSH_LABEL(ret, lstart);
5591 pm_compile_rescue(iseq, cast, node_location, ret, popped | last_leave, scope_node);
5594 pm_compile_node(iseq, (
const pm_node_t *) cast->
statements, ret, popped | last_leave, scope_node);
5596 else if (!(popped | last_leave)) {
5597 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
5600 PUSH_LABEL(ret, lend);
5601 PUSH_SEQ(ret, ensr);
5602 if (!popped && last_leave) PUSH_INSN(ret, *node_location, putnil);
5603 PUSH_LABEL(ret, lcont);
5604 if (last_leave) PUSH_INSN(ret, *node_location, pop);
5616 pm_scope_node_destroy(&next_scope_node);
5618 erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
5619 if (lstart->link.next != &lend->link) {
5621 PUSH_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, child_iseq, lcont);
5622 erange = erange->next;
5625 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
5636 !PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION) &&
5638 PM_NODE_TYPE_P(node->
receiver, PM_STRING_NODE) &&
5640 node->
block == NULL &&
5641 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5654 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
5655 ISEQ_BODY(iseq)->ic_size++;
5656 VALUE segments = rb_ary_new_from_args(1, name);
5658 PUSH_INSN1(ret, location, opt_getconstant_path, segments);
5661 PUSH_INSN(ret, location, putnil);
5662 PUSH_INSN1(ret, location, putobject,
Qtrue);
5663 PUSH_INSN1(ret, location, getconstant, name);
5677 switch (PM_NODE_TYPE(node)) {
5678 case PM_CONSTANT_READ_NODE: {
5682 rb_ary_unshift(parts, name);
5685 case PM_CONSTANT_PATH_NODE: {
5689 rb_ary_unshift(parts, name);
5690 if (cast->
parent == NULL) {
5691 rb_ary_unshift(parts,
ID2SYM(idNULL));
5714 switch (PM_NODE_TYPE(node)) {
5715 case PM_CONSTANT_READ_NODE: {
5719 PUSH_INSN1(body, location, putobject,
Qtrue);
5720 PUSH_INSN1(body, location, getconstant, name);
5723 case PM_CONSTANT_PATH_NODE: {
5727 if (cast->
parent == NULL) {
5728 PUSH_INSN(body, location, pop);
5729 PUSH_INSN1(body, location, putobject,
rb_cObject);
5730 PUSH_INSN1(body, location, putobject,
Qtrue);
5731 PUSH_INSN1(body, location, getconstant, name);
5734 pm_compile_constant_path(iseq, cast->
parent, prefix, body,
false, scope_node);
5735 PUSH_INSN1(body, location, putobject,
Qfalse);
5736 PUSH_INSN1(body, location, getconstant, name);
5741 PM_COMPILE_INTO_ANCHOR(prefix, node);
5752 switch (PM_NODE_TYPE(node)) {
5756 case PM_SYMBOL_NODE:
5757 case PM_REGULAR_EXPRESSION_NODE:
5758 case PM_SOURCE_LINE_NODE:
5759 case PM_INTEGER_NODE:
5761 case PM_RATIONAL_NODE:
5762 case PM_IMAGINARY_NODE:
5763 case PM_SOURCE_ENCODING_NODE:
5764 return pm_static_literal_value(iseq, node, scope_node);
5765 case PM_STRING_NODE:
5766 return parse_static_literal_string(iseq, scope_node, node, &((
const pm_string_node_t *) node)->unescaped);
5767 case PM_SOURCE_FILE_NODE:
5769 case PM_ARRAY_NODE: {
5773 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5774 VALUE element = pm_compile_shareable_constant_literal(iseq, cast->
elements.
nodes[index], scope_node);
5782 case PM_HASH_NODE: {
5786 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5788 if (!PM_NODE_TYPE_P(element, PM_ASSOC_NODE))
return Qundef;
5792 VALUE key = pm_compile_shareable_constant_literal(iseq, assoc->
key, scope_node);
5795 VALUE value = pm_compile_shareable_constant_literal(iseq, assoc->
value, scope_node);
5798 rb_hash_aset(result, key, value);
5815 VALUE literal = pm_compile_shareable_constant_literal(iseq, node, scope_node);
5818 PUSH_INSN1(ret, location, putobject, literal);
5823 switch (PM_NODE_TYPE(node)) {
5824 case PM_ARRAY_NODE: {
5828 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5831 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5832 pm_compile_shareable_constant_value(iseq, cast->
elements.
nodes[index], shareability, path, ret, scope_node,
false);
5838 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5839 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5844 case PM_HASH_NODE: {
5848 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5851 pm_compile_hash_elements(iseq, (
const pm_node_t *) cast, &cast->elements, shareability, path,
false, ret, scope_node);
5854 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5855 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5861 DECL_ANCHOR(value_seq);
5863 pm_compile_node(iseq, node, value_seq,
false, scope_node);
5864 if (PM_NODE_TYPE_P(node, PM_INTERPOLATED_STRING_NODE)) {
5865 PUSH_SEND_WITH_FLAG(value_seq, location, idUMinus,
INT2FIX(0),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5868 if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_LITERAL) {
5869 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5870 PUSH_SEQ(ret, value_seq);
5874 PUSH_INSN1(ret, location, putobject, path);
5875 PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"ensure_shareable"),
INT2FIX(2),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5877 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) {
5878 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5879 PUSH_SEQ(ret, value_seq);
5880 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable_copy"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5882 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_EVERYTHING) {
5883 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5884 PUSH_SEQ(ret, value_seq);
5885 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5901 ID name_id = pm_constant_id_lookup(scope_node, node->
name);
5903 if (shareability != 0) {
5904 pm_compile_shareable_constant_value(iseq, node->
value, shareability, rb_id2str(name_id), ret, scope_node,
true);
5907 PM_COMPILE_NOT_POPPED(node->
value);
5910 if (!popped) PUSH_INSN(ret, location, dup);
5911 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5914 PUSH_INSN1(ret, location, setconstant, operand);
5927 LABEL *end_label = NEW_LABEL(location.
line);
5929 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5930 if (!popped) PUSH_INSN(ret, location, dup);
5932 PUSH_INSNL(ret, location, branchunless, end_label);
5933 if (!popped) PUSH_INSN(ret, location, pop);
5935 if (shareability != 0) {
5936 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5939 PM_COMPILE_NOT_POPPED(node->
value);
5942 if (!popped) PUSH_INSN(ret, location, dup);
5943 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5944 PUSH_INSN1(ret, location, setconstant, name);
5945 PUSH_LABEL(ret, end_label);
5958 LABEL *set_label = NEW_LABEL(location.
line);
5959 LABEL *end_label = NEW_LABEL(location.
line);
5961 PUSH_INSN(ret, location, putnil);
5962 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name,
Qtrue);
5963 PUSH_INSNL(ret, location, branchunless, set_label);
5965 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5966 if (!popped) PUSH_INSN(ret, location, dup);
5968 PUSH_INSNL(ret, location, branchif, end_label);
5969 if (!popped) PUSH_INSN(ret, location, pop);
5970 PUSH_LABEL(ret, set_label);
5972 if (shareability != 0) {
5973 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5976 PM_COMPILE_NOT_POPPED(node->
value);
5979 if (!popped) PUSH_INSN(ret, location, dup);
5980 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5981 PUSH_INSN1(ret, location, setconstant, name);
5982 PUSH_LABEL(ret, end_label);
5997 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5999 if (shareability != 0) {
6000 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
6003 PM_COMPILE_NOT_POPPED(node->
value);
6006 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
6007 if (!popped) PUSH_INSN(ret, location, dup);
6009 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
6010 PUSH_INSN1(ret, location, setconstant, name);
6021 rb_ary_push(parts, rb_id2str(pm_constant_id_lookup(scope_node, node->
name)));
6024 while (current != NULL && PM_NODE_TYPE_P(current, PM_CONSTANT_PATH_NODE)) {
6026 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, cast->
name)));
6030 if (current == NULL) {
6031 rb_ary_unshift(parts, rb_id2str(idNULL));
6033 else if (PM_NODE_TYPE_P(current, PM_CONSTANT_READ_NODE)) {
6034 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, ((
const pm_constant_read_node_t *) current)->name)));
6058 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6061 if (shareability != 0) {
6062 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6065 PM_COMPILE_NOT_POPPED(node->
value);
6069 PUSH_INSN(ret, location, swap);
6070 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6073 PUSH_INSN(ret, location, swap);
6074 PUSH_INSN1(ret, location, setconstant, name);
6091 PM_COMPILE_NOT_POPPED(target->
parent);
6094 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6097 PUSH_INSN(ret, location, dup);
6098 PUSH_INSN1(ret, location, putobject,
Qtrue);
6099 PUSH_INSN1(ret, location, getconstant, name);
6101 if (!popped) PUSH_INSN(ret, location, dup);
6102 PUSH_INSNL(ret, location, branchunless, lfin);
6104 if (!popped) PUSH_INSN(ret, location, pop);
6106 if (shareability != 0) {
6107 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6110 PM_COMPILE_NOT_POPPED(node->
value);
6114 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6117 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6118 PUSH_INSN(ret, location, swap);
6121 PUSH_INSN1(ret, location, setconstant, name);
6122 PUSH_LABEL(ret, lfin);
6124 if (!popped) PUSH_INSN(ret, location, swap);
6125 PUSH_INSN(ret, location, pop);
6139 LABEL *lassign = NEW_LABEL(location.
line);
6143 PM_COMPILE_NOT_POPPED(target->
parent);
6146 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6149 PUSH_INSN(ret, location, dup);
6150 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name,
Qtrue);
6151 PUSH_INSNL(ret, location, branchunless, lassign);
6153 PUSH_INSN(ret, location, dup);
6154 PUSH_INSN1(ret, location, putobject,
Qtrue);
6155 PUSH_INSN1(ret, location, getconstant, name);
6157 if (!popped) PUSH_INSN(ret, location, dup);
6158 PUSH_INSNL(ret, location, branchif, lfin);
6160 if (!popped) PUSH_INSN(ret, location, pop);
6161 PUSH_LABEL(ret, lassign);
6163 if (shareability != 0) {
6164 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6167 PM_COMPILE_NOT_POPPED(node->
value);
6171 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6174 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6175 PUSH_INSN(ret, location, swap);
6178 PUSH_INSN1(ret, location, setconstant, name);
6179 PUSH_LABEL(ret, lfin);
6181 if (!popped) PUSH_INSN(ret, location, swap);
6182 PUSH_INSN(ret, location, pop);
6199 PM_COMPILE_NOT_POPPED(target->
parent);
6202 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6205 PUSH_INSN(ret, location, dup);
6206 PUSH_INSN1(ret, location, putobject,
Qtrue);
6207 PUSH_INSN1(ret, location, getconstant, name);
6209 if (shareability != 0) {
6210 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6213 PM_COMPILE_NOT_POPPED(node->
value);
6216 PUSH_CALL(ret, location, method_id,
INT2FIX(1));
6217 PUSH_INSN(ret, location, swap);
6220 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6221 PUSH_INSN(ret, location, swap);
6224 PUSH_INSN1(ret, location, setconstant, name);
6233#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))
6252 bool trailing_comma =
false;
6254 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
6258 if (scope_node->parameters != NULL) {
6259 switch (PM_NODE_TYPE(scope_node->parameters)) {
6260 case PM_BLOCK_PARAMETERS_NODE: {
6262 parameters_node = cast->parameters;
6263 block_locals = &cast->locals;
6265 if (parameters_node) {
6266 if (parameters_node->
rest && PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE)) {
6267 trailing_comma =
true;
6272 case PM_PARAMETERS_NODE: {
6276 case PM_NUMBERED_PARAMETERS_NODE: {
6278 body->param.lead_num = maximum;
6279 body->param.flags.ambiguous_param0 = maximum == 1;
6282 case PM_IT_PARAMETERS_NODE:
6283 body->param.lead_num = 1;
6284 body->param.flags.ambiguous_param0 =
true;
6287 rb_bug(
"Unexpected node type for parameters: %s", pm_node_type(PM_NODE_TYPE(scope_node->parameters)));
6291 struct rb_iseq_param_keyword *keyword = NULL;
6293 if (parameters_node) {
6294 optionals_list = ¶meters_node->
optionals;
6295 requireds_list = ¶meters_node->
requireds;
6296 keywords_list = ¶meters_node->
keywords;
6297 posts_list = ¶meters_node->
posts;
6299 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))) {
6300 body->param.opt_num = 0;
6303 body->param.lead_num = 0;
6304 body->param.opt_num = 0;
6310 size_t locals_size = locals->
size;
6316 int table_size = (int) locals_size;
6320 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) table_size++;
6322 if (keywords_list && keywords_list->
size) {
6326 if (requireds_list) {
6327 for (
size_t i = 0; i < requireds_list->
size; i++) {
6332 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6335 else if (PM_NODE_TYPE_P(required, PM_REQUIRED_PARAMETER_NODE)) {
6336 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6345 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6353 if (optionals_list && optionals_list->
size) {
6354 for (
size_t i = 0; i < optionals_list->
size; i++) {
6356 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6366 if (parameters_node) {
6367 if (parameters_node->
rest) {
6368 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6382 if (PM_NODE_TYPE_P(parameters_node->
keyword_rest, PM_FORWARDING_PARAMETER_NODE)) {
6384 if (requireds_list->
size == 0 && optionals_list->
size == 0 && keywords_list->
size == 0) {
6385 ISEQ_BODY(iseq)->param.flags.use_block = TRUE;
6386 ISEQ_BODY(iseq)->param.flags.forwardable = TRUE;
6397 if (!kw_rest->name || PM_NODE_FLAG_P(kw_rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6405 for (
size_t i = 0; i < posts_list->
size; i++) {
6410 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE) || PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6416 if (keywords_list && keywords_list->
size) {
6417 for (
size_t i = 0; i < keywords_list->
size; i++) {
6419 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6425 if (parameters_node && parameters_node->
block && PM_NODE_TYPE_P(parameters_node->
block, PM_BLOCK_PARAMETER_NODE)) {
6428 if (PM_NODE_FLAG_P(block_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER) || !block_node->name) {
6436 local_table_for_iseq->size = table_size;
6440 pm_index_lookup_table_init(&index_lookup_table, (
int) pm_parser_constants_size(scope_node->parser), iseq);
6460 int local_index = 0;
6467 if (requireds_list && requireds_list->
size) {
6468 for (
size_t i = 0; i < requireds_list->
size; i++, local_index++) {
6476 switch (PM_NODE_TYPE(required)) {
6477 case PM_MULTI_TARGET_NODE: {
6480 local = rb_make_temporary_id(local_index);
6481 local_table_for_iseq->ids[local_index] = local;
6484 case PM_REQUIRED_PARAMETER_NODE: {
6489 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6490 ID local = pm_constant_id_lookup(scope_node, param->
name);
6491 local_table_for_iseq->ids[local_index] = local;
6494 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6500 rb_bug(
"Unsupported node in requireds in parameters %s", pm_node_type(PM_NODE_TYPE(required)));
6504 body->param.lead_num = (int) requireds_list->
size;
6505 body->param.flags.has_lead =
true;
6508 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6509 local_table_for_iseq->ids[local_index++] = idItImplicit;
6514 if (optionals_list && optionals_list->
size) {
6515 body->param.opt_num = (int) optionals_list->
size;
6516 body->param.flags.has_opt =
true;
6518 for (
size_t i = 0; i < optionals_list->
size; i++, local_index++) {
6522 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6523 ID local = pm_constant_id_lookup(scope_node, name);
6524 local_table_for_iseq->ids[local_index] = local;
6527 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6534 if (parameters_node && parameters_node->
rest) {
6535 body->param.rest_start = local_index;
6539 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6540 body->param.flags.has_rest =
true;
6548 if (PM_NODE_FLAG_P(parameters_node->
rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6549 ID local = pm_constant_id_lookup(scope_node, name);
6550 local_table_for_iseq->ids[local_index] = local;
6553 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6559 body->param.flags.anon_rest =
true;
6560 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index, &index_lookup_table, local_table_for_iseq);
6569 if (posts_list && posts_list->
size) {
6570 body->param.post_num = (int) posts_list->
size;
6571 body->param.post_start = local_index;
6572 body->param.flags.has_post =
true;
6574 for (
size_t i = 0; i < posts_list->
size; i++, local_index++) {
6582 switch (PM_NODE_TYPE(post_node)) {
6583 case PM_MULTI_TARGET_NODE: {
6586 local = rb_make_temporary_id(local_index);
6587 local_table_for_iseq->ids[local_index] = local;
6590 case PM_REQUIRED_PARAMETER_NODE: {
6595 if (PM_NODE_FLAG_P(param, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6596 ID local = pm_constant_id_lookup(scope_node, param->
name);
6597 local_table_for_iseq->ids[local_index] = local;
6600 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6605 rb_bug(
"Unsupported node in posts in parameters %s", pm_node_type(PM_NODE_TYPE(post_node)));
6613 if (keywords_list && keywords_list->
size) {
6614 if (keywords_list->
size > VM_CALL_KW_LEN_MAX) {
6615 COMPILE_ERROR(iseq, node_location->
line,
"too many keyword parameters (%d, maximum is %d)",
6616 (
int) keywords_list->
size, (
int) VM_CALL_KW_LEN_MAX);
6619 keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6620 keyword->num = (int) keywords_list->
size;
6625 for (
size_t i = 0; i < keywords_list->
size; i++) {
6631 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_REQUIRED_KEYWORD_PARAMETER_NODE)) {
6633 keyword->required_num++;
6634 ID local = pm_constant_id_lookup(scope_node, name);
6636 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6637 local_table_for_iseq->ids[local_index] = local;
6640 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6646 for (
size_t i = 0; i < keywords_list->
size; i++) {
6652 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_OPTIONAL_KEYWORD_PARAMETER_NODE)) {
6658 if (PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) {
6659 rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node));
6665 ID local = pm_constant_id_lookup(scope_node, name);
6666 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6667 local_table_for_iseq->ids[local_index] = local;
6670 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6680 for (
int i = 0; i <
RARRAY_LEN(default_values); i++) {
6682 if (dv == complex_mark) dv =
Qundef;
6686 keyword->default_values = dvs;
6690 keyword->bits_start = local_index;
6691 ID local = rb_make_temporary_id(local_index);
6692 local_table_for_iseq->ids[local_index] = local;
6695 body->param.keyword = keyword;
6696 body->param.flags.has_kw =
true;
6699 if (body->type == ISEQ_TYPE_BLOCK && local_index == 1 && requireds_list && requireds_list->
size == 1 && !trailing_comma) {
6700 body->param.flags.ambiguous_param0 =
true;
6703 if (parameters_node) {
6708 case PM_NO_KEYWORDS_PARAMETER_NODE: {
6711 body->param.flags.accepts_no_kwarg =
true;
6714 case PM_KEYWORD_REST_PARAMETER_NODE: {
6718 if (!body->param.flags.has_kw) {
6719 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6722 keyword->rest_start = local_index;
6723 body->param.flags.has_kwrest =
true;
6727 if (PM_NODE_FLAG_P(kw_rest_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6728 ID local = pm_constant_id_lookup(scope_node, constant_id);
6729 local_table_for_iseq->ids[local_index] = local;
6732 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6736 body->param.flags.anon_kwrest =
true;
6737 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index, &index_lookup_table, local_table_for_iseq);
6743 case PM_FORWARDING_PARAMETER_NODE: {
6746 if (!ISEQ_BODY(iseq)->param.
flags.forwardable) {
6748 body->param.rest_start = local_index;
6749 body->param.flags.has_rest =
true;
6750 body->param.flags.anon_rest =
true;
6751 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index++, &index_lookup_table, local_table_for_iseq);
6755 body->param.flags.has_kw =
false;
6756 body->param.flags.has_kwrest =
true;
6757 body->param.flags.anon_kwrest =
true;
6758 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6759 keyword->rest_start = local_index;
6760 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index++, &index_lookup_table, local_table_for_iseq);
6763 body->param.block_start = local_index;
6764 body->param.flags.has_block =
true;
6765 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index++, &index_lookup_table, local_table_for_iseq);
6769 pm_insert_local_special(PM_CONSTANT_DOT3, idDot3, local_index++, &index_lookup_table, local_table_for_iseq);
6773 rb_bug(
"node type %s not expected as keyword_rest", pm_node_type(PM_NODE_TYPE(parameters_node->
keyword_rest)));
6779 if (parameters_node->
block) {
6780 switch (PM_NODE_TYPE(parameters_node->
block)) {
6781 case PM_BLOCK_PARAMETER_NODE: {
6782 body->param.block_start = local_index;
6783 body->param.flags.has_block =
true;
6785 iseq_set_use_block(iseq);
6790 if (PM_NODE_FLAG_P(parameters_node->
block, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6791 ID local = pm_constant_id_lookup(scope_node, name);
6792 local_table_for_iseq->ids[local_index] = local;
6795 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6799 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index, &index_lookup_table, local_table_for_iseq);
6805 case PM_NO_BLOCK_PARAMETER_NODE: {
6806 body->param.flags.accepts_no_block =
true;
6810 rb_bug(
"node type %s not expected as block parameter", pm_node_type(PM_NODE_TYPE(parameters_node->
block)));
6827 if (requireds_list && requireds_list->
size) {
6828 for (
size_t i = 0; i < requireds_list->
size; i++) {
6834 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6835 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);
6841 if (posts_list && posts_list->
size) {
6842 for (
size_t i = 0; i < posts_list->
size; i++) {
6848 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
6849 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);
6855 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
6856 if (PM_NODE_TYPE_P(((
const pm_for_node_t *) scope_node->ast_node)->index, PM_LOCAL_VARIABLE_TARGET_NODE)) {
6857 body->param.lead_num++;
6860 body->param.rest_start = local_index;
6861 body->param.flags.has_rest =
true;
6864 ID local = rb_make_temporary_id(local_index);
6865 local_table_for_iseq->ids[local_index] = local;
6870 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_NUMBERED_PARAMETERS_NODE)) {
6873 for (
int i = 0; i < maximum; i++, local_index++) {
6874 const uint8_t param_name[] = {
'_',
'1' + i };
6875 pm_constant_id_t constant_id = pm_parser_constant_find(scope_node->parser, param_name, 2);
6876 RUBY_ASSERT(constant_id &&
"parser should fill in any gaps in numbered parameters");
6877 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6879 body->param.lead_num = maximum;
6880 body->param.flags.has_lead =
true;
6884 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6885 body->param.lead_num = 1;
6886 body->param.flags.has_lead =
true;
6897 if (block_locals && block_locals->
size) {
6898 for (
size_t i = 0; i < block_locals->
size; i++, local_index++) {
6900 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6905 if (scope_node->locals.
size) {
6906 for (
size_t i = 0; i < scope_node->locals.
size; i++) {
6910 if (!pm_index_lookup_table_lookup(&index_lookup_table, constant_id, &existing)) {
6911 ID local = pm_constant_id_lookup(scope_node, constant_id);
6912 local_table_for_iseq->ids[local_index] = local;
6913 pm_index_lookup_table_insert(&index_lookup_table, constant_id, local_index);
6925 iseq_calc_param_size(iseq);
6927 if (ISEQ_BODY(iseq)->param.
flags.forwardable) {
6930 ISEQ_BODY(iseq)->param.size += 1;
6934 iseq_set_local_table(iseq, local_table_for_iseq, 0);
6935 iseq_set_parameters_lvar_state(iseq);
6937 scope_node->local_table_for_iseq_size = local_table_for_iseq->size;
6939 if (keyword != NULL) {
6940 size_t keyword_start_index = keyword->bits_start - keyword->num;
6941 keyword->table = (
ID *)&ISEQ_BODY(iseq)->local_table[keyword_start_index];
6946 if (optionals_list && optionals_list->
size) {
6954 for (
size_t i = 0; i < optionals_list->
size; i++) {
6955 label = NEW_LABEL(location.
line);
6956 opt_table[i] = label;
6957 PUSH_LABEL(ret, label);
6959 PM_COMPILE_NOT_POPPED(optional_node);
6963 label = NEW_LABEL(location.
line);
6964 opt_table[optionals_list->
size] = label;
6965 PUSH_LABEL(ret, label);
6967 body->param.opt_table = (
const VALUE *) opt_table;
6970 if (keywords_list && keywords_list->
size) {
6971 size_t optional_index = 0;
6972 for (
size_t i = 0; i < keywords_list->
size; i++) {
6976 switch (PM_NODE_TYPE(keyword_parameter_node)) {
6977 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
6985 if (!PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) {
6986 LABEL *end_label = NEW_LABEL(location.
line);
6989 int kw_bits_idx = table_size - body->param.keyword->bits_start;
6990 PUSH_INSN2(ret, location, checkkeyword,
INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1),
INT2FIX(optional_index));
6991 PUSH_INSNL(ret, location, branchif, end_label);
6993 PUSH_SETLOCAL(ret, location, index.index, index.level);
6994 PUSH_LABEL(ret, end_label);
6999 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
7004 rb_bug(
"Unexpected keyword parameter node type %s", pm_node_type(PM_NODE_TYPE(keyword_parameter_node)));
7009 if (requireds_list && requireds_list->
size) {
7010 for (
size_t i = 0; i < requireds_list->
size; i++) {
7016 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
7017 PUSH_GETLOCAL(ret, location, table_size - (
int)i, 0);
7023 if (posts_list && posts_list->
size) {
7024 for (
size_t i = 0; i < posts_list->
size; i++) {
7030 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
7031 PUSH_GETLOCAL(ret, location, table_size - body->param.post_start - (
int) i, 0);
7037 switch (body->type) {
7038 case ISEQ_TYPE_PLAIN: {
7039 RUBY_ASSERT(PM_NODE_TYPE_P(scope_node->ast_node, PM_INTERPOLATED_REGULAR_EXPRESSION_NODE));
7042 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
7046 case ISEQ_TYPE_BLOCK: {
7047 LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
7048 LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
7051 start->rescued = LABEL_RESCUE_BEG;
7052 end->rescued = LABEL_RESCUE_END;
7058 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
7059 pm_compile_for_node_index(iseq, ((
const pm_for_node_t *) scope_node->ast_node)->index, ret, scope_node);
7063 PUSH_INSN(ret, block_location, nop);
7064 PUSH_LABEL(ret, start);
7066 if (scope_node->body != NULL) {
7067 switch (PM_NODE_TYPE(scope_node->ast_node)) {
7068 case PM_POST_EXECUTION_NODE: {
7070 PUSH_INSN1(ret, block_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7074 pm_scope_node_init((
const pm_node_t *) cast->statements, &next_scope_node, scope_node);
7076 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(body->parent_iseq), ISEQ_TYPE_BLOCK, location.
line);
7077 pm_scope_node_destroy(&next_scope_node);
7079 PUSH_CALL_WITH_BLOCK(ret, block_location, id_core_set_postexe,
INT2FIX(0), block);
7082 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
7084 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
7088 pm_compile_node(iseq, scope_node->body, ret, popped, scope_node);
7093 PUSH_INSN(ret, block_location, putnil);
7096 PUSH_LABEL(ret, end);
7098 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7101 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
7102 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
7105 case ISEQ_TYPE_ENSURE: {
7106 const pm_node_location_t statements_location = (scope_node->body != NULL ? PM_NODE_START_LOCATION(scope_node->body) : location);
7107 iseq_set_exception_local_table(iseq);
7109 if (scope_node->body != NULL) {
7110 PM_COMPILE_POPPED((
const pm_node_t *) scope_node->body);
7113 PUSH_GETLOCAL(ret, statements_location, 1, 0);
7114 PUSH_INSN1(ret, statements_location,
throw,
INT2FIX(0));
7117 case ISEQ_TYPE_METHOD: {
7118 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7121 if (scope_node->body) {
7122 PM_COMPILE((
const pm_node_t *) scope_node->body);
7125 PUSH_INSN(ret, location, putnil);
7128 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7131 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7134 case ISEQ_TYPE_RESCUE: {
7135 iseq_set_exception_local_table(iseq);
7136 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_RESCUE_MODIFIER_NODE)) {
7138 LABEL *rescue_end = NEW_LABEL(location.
line);
7139 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7141 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
7142 PUSH_INSNL(ret, location, branchif, lab);
7143 PUSH_INSNL(ret, location, jump, rescue_end);
7144 PUSH_LABEL(ret, lab);
7146 PM_COMPILE((
const pm_node_t *) scope_node->body);
7147 PUSH_INSN(ret, location, leave);
7148 PUSH_LABEL(ret, rescue_end);
7149 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7152 PM_COMPILE((
const pm_node_t *) scope_node->ast_node);
7154 PUSH_INSN1(ret, location,
throw,
INT2FIX(0));
7159 if (scope_node->body) {
7160 PM_COMPILE((
const pm_node_t *) scope_node->body);
7163 PUSH_INSN(ret, location, putnil);
7168 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
7171 ISEQ_COMPILE_DATA(iseq)->last_line = end_location.
line;
7174 if (!PM_NODE_TYPE_P(scope_node->ast_node, PM_ENSURE_NODE)) {
7176 PUSH_INSN(ret, location, leave);
7185 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7189 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7190 PUSH_INSN1(ret, *location, putobject, operand);
7195 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7196 PUSH_INSN1(ret, *location, putobject, operand);
7199 PUSH_SEND(ret, *location, id_core_set_variable_alias,
INT2FIX(2));
7200 if (popped) PUSH_INSN(ret, *location, pop);
7206 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7207 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
7208 PM_COMPILE_NOT_POPPED(node->
new_name);
7209 PM_COMPILE_NOT_POPPED(node->
old_name);
7211 PUSH_SEND(ret, *location, id_core_set_method_alias,
INT2FIX(3));
7212 if (popped) PUSH_INSN(ret, *location, pop);
7218 LABEL *end_label = NEW_LABEL(location->
line);
7220 PM_COMPILE_NOT_POPPED(node->
left);
7221 if (!popped) PUSH_INSN(ret, *location, dup);
7222 PUSH_INSNL(ret, *location, branchunless, end_label);
7224 if (!popped) PUSH_INSN(ret, *location, pop);
7225 PM_COMPILE(node->
right);
7226 PUSH_LABEL(ret, end_label);
7234 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
7239 if (elements->
size) {
7240 VALUE value = pm_static_literal_value(iseq, node, scope_node);
7242 PUSH_INSN1(ret, *location, duparray, value);
7245 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7263 const int max_new_array_size = 0x100;
7264 const unsigned int min_tmp_array_size = 0x40;
7266 int new_array_size = 0;
7267 bool first_chunk =
true;
7273 bool static_literal =
false;
7276#define FLUSH_CHUNK \
7277 if (new_array_size) { \
7278 if (first_chunk) PUSH_INSN1(ret, *location, newarray, INT2FIX(new_array_size)); \
7279 else PUSH_INSN1(ret, *location, pushtoarray, INT2FIX(new_array_size)); \
7280 first_chunk = false; \
7281 new_array_size = 0; \
7284 for (
size_t index = 0; index < elements->
size; index++) {
7287 if (PM_NODE_TYPE_P(element, PM_SPLAT_NODE)) {
7292 PM_COMPILE_NOT_POPPED(splat_element->
expression);
7295 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
7296 PUSH_GETLOCAL(ret, *location, index.index, index.level);
7302 PUSH_INSN1(ret, *location, splatarray,
Qtrue);
7303 first_chunk =
false;
7306 PUSH_INSN(ret, *location, concattoarray);
7309 static_literal =
false;
7311 else if (PM_NODE_TYPE_P(element, PM_KEYWORD_HASH_NODE)) {
7312 if (new_array_size == 0 && first_chunk) {
7313 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7314 first_chunk =
false;
7331 pm_compile_hash_elements(iseq, element, &keyword_hash->
elements, 0,
Qundef,
false, ret, scope_node);
7338 while (splats < keyword_hash->elements.
size && PM_NODE_TYPE_P(keyword_hash->
elements.
nodes[splats], PM_ASSOC_SPLAT_NODE)) splats++;
7341 PUSH_INSN(ret, *location, pushtoarraykwsplat);
7348 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) &&
7349 !PM_CONTAINER_P(element) &&
7351 ((index + min_tmp_array_size) < elements->
size)
7356 size_t right_index = index + 1;
7358 right_index < elements->size &&
7359 PM_NODE_FLAG_P(elements->
nodes[right_index], PM_NODE_FLAG_STATIC_LITERAL) &&
7360 !PM_CONTAINER_P(elements->
nodes[right_index])
7363 size_t tmp_array_size = right_index - index;
7364 if (tmp_array_size >= min_tmp_array_size) {
7368 for (; tmp_array_size; tmp_array_size--)
7369 rb_ary_push(tmp_array, pm_static_literal_value(iseq, elements->
nodes[index++], scope_node));
7377 PUSH_INSN1(ret, *location, duparray, tmp_array);
7378 first_chunk =
false;
7381 PUSH_INSN1(ret, *location, putobject, tmp_array);
7382 PUSH_INSN(ret, *location, concattoarray);
7386 PM_COMPILE_NOT_POPPED(element);
7387 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7388 static_literal =
true;
7391 PM_COMPILE_NOT_POPPED(element);
7392 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7393 static_literal =
false;
7398 if (popped) PUSH_INSN(ret, *location, pop);
7406 unsigned long throw_flag = 0;
7408 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
7410 LABEL *splabel = NEW_LABEL(0);
7411 PUSH_LABEL(ret, splabel);
7412 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7418 PUSH_INSN(ret, *location, putnil);
7421 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7422 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
7423 PUSH_ADJUST_RESTORE(ret, splabel);
7424 if (!popped) PUSH_INSN(ret, *location, putnil);
7430 if (!ISEQ_COMPILE_DATA(ip)) {
7435 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7436 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
7438 else if (ISEQ_BODY(ip)->type == ISEQ_TYPE_BLOCK) {
7441 else if (ISEQ_BODY(ip)->type == ISEQ_TYPE_EVAL) {
7442 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7446 ip = ISEQ_BODY(ip)->parent_iseq;
7455 PUSH_INSN(ret, *location, putnil);
7458 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_BREAK));
7459 if (popped) PUSH_INSN(ret, *location, pop);
7464 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7471 ID method_id = pm_constant_id_lookup(scope_node, node->
name);
7477 const char *builtin_func;
7479 if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && (builtin_func = pm_iseq_builtin_function_name(scope_node, node->
receiver, method_id)) != NULL) {
7480 pm_compile_builtin_function_call(iseq, ret, scope_node, node, &location, popped, ISEQ_COMPILE_DATA(iseq)->current_block, builtin_func);
7484 LABEL *start = NEW_LABEL(location.
line);
7485 if (node->
block) PUSH_LABEL(ret, start);
7487 switch (method_id) {
7489 if (pm_opt_str_freeze_p(iseq, node)) {
7491 const struct rb_callinfo *callinfo = new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE);
7492 PUSH_INSN2(ret, location, opt_str_uminus, value, callinfo);
7493 if (popped) PUSH_INSN(ret, location, pop);
7499 if (pm_opt_str_freeze_p(iseq, node)) {
7501 const struct rb_callinfo *callinfo = new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE);
7502 PUSH_INSN2(ret, location, opt_str_freeze, value, callinfo);
7503 if (popped) PUSH_INSN(ret, location, pop);
7510 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
7511 PUSH_INSN(ret, location, putnil);
7515 PUSH_INSN(ret, location, putself);
7518 if ((method_id == idCall || method_id == idAREF || method_id == idYield || method_id == idEqq) && PM_NODE_TYPE_P(node->
receiver, PM_LOCAL_VARIABLE_READ_NODE)) {
7523 if (iseq_block_param_id_p(iseq, pm_constant_id_lookup(scope_node, read_node_cast->name), &idx, &level)) {
7524 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)));
7527 PM_COMPILE_NOT_POPPED(node->
receiver);
7531 PM_COMPILE_NOT_POPPED(node->
receiver);
7535 pm_compile_call(iseq, node, ret, popped, scope_node, method_id, start);
7544 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
7545 flag = VM_CALL_FCALL;
7548 PM_COMPILE_NOT_POPPED(node->
receiver);
7550 LABEL *safe_label = NULL;
7551 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
7552 safe_label = NEW_LABEL(location->
line);
7553 PUSH_INSN(ret, *location, dup);
7554 PUSH_INSNL(ret, *location, branchnil, safe_label);
7557 PUSH_INSN(ret, *location, dup);
7559 ID id_read_name = pm_constant_id_lookup(scope_node, node->
read_name);
7560 PUSH_SEND_WITH_FLAG(ret, *location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
7562 PM_COMPILE_NOT_POPPED(node->
value);
7564 PUSH_SEND(ret, *location, id_operator,
INT2FIX(1));
7567 PUSH_INSN(ret, *location, swap);
7568 PUSH_INSN1(ret, *location, topn,
INT2FIX(1));
7571 ID id_write_name = pm_constant_id_lookup(scope_node, node->
write_name);
7572 PUSH_SEND_WITH_FLAG(ret, *location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
7574 if (safe_label != NULL && popped) PUSH_LABEL(ret, safe_label);
7575 PUSH_INSN(ret, *location, pop);
7576 if (safe_label != NULL && !popped) PUSH_LABEL(ret, safe_label);
7599 switch (PM_NODE_TYPE(node)) {
7600 case PM_FLOAT_NODE: {
7601 key = pm_static_literal_value(iseq, node, scope_node);
7605 key = (
FIXABLE(intptr) ?
LONG2FIX((
long) intptr) : rb_dbl2big(intptr));
7611 case PM_INTEGER_NODE:
7613 case PM_SOURCE_LINE_NODE:
7614 case PM_SYMBOL_NODE:
7616 key = pm_static_literal_value(iseq, node, scope_node);
7618 case PM_STRING_NODE: {
7620 key = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
7627 cdhash_aset_if_missing(dispatch, key, (
VALUE)label);
7643 DECL_ANCHOR(cond_seq);
7648 DECL_ANCHOR(body_seq);
7652 LABEL *end_label = NEW_LABEL(location.
line);
7663 if (PM_BRANCH_COVERAGE_P(iseq)) {
7664 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7665 branches = decl_branch_base(iseq, (
int) cast->
base.
node_id, &case_location,
"case");
7671 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7675 int clause_lineno = pm_node_line_number_cached((
const pm_node_t *) clause, scope_node);
7676 LABEL *label = NEW_LABEL(clause_lineno);
7677 PUSH_LABEL(body_seq, label);
7680 if (PM_BRANCH_COVERAGE_P(iseq)) {
7682 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7685 if (clause->statements != NULL) {
7686 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7689 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7692 PUSH_INSNL(body_seq, location, jump, end_label);
7697 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7700 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7702 PUSH_INSN(cond_seq, cond_location, putnil);
7703 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7704 PUSH_INSN1(cond_seq, cond_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
7705 PUSH_INSNL(cond_seq, cond_location, branchif, label);
7708 LABEL *next_label = NEW_LABEL(pm_node_line_number_cached(condition, scope_node));
7709 pm_compile_branch_condition(iseq, cond_seq, condition, label, next_label, scope_node);
7710 PUSH_LABEL(cond_seq, next_label);
7717 if (PM_BRANCH_COVERAGE_P(iseq)) {
7721 branch_location = case_location;
7728 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7736 PUSH_SYNTHETIC_PUTNIL(cond_seq, iseq);
7741 PUSH_INSNL(cond_seq, location, jump, end_label);
7742 PUSH_SEQ(ret, cond_seq);
7750 if (PM_BRANCH_COVERAGE_P(iseq)) {
7751 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7752 branches = decl_branch_base(iseq, (
int) cast->
base.
node_id, &case_location,
"case");
7757 LABEL *else_label = NEW_LABEL(location.
line);
7765 if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
7766 dispatch = cdhash_new(0);
7777 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7782 LABEL *label = NEW_LABEL(clause_location.
line);
7787 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7794 if (dispatch !=
Qundef) {
7795 dispatch = pm_compile_case_node_dispatch(iseq, dispatch, condition, label, scope_node);
7798 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7799 PUSH_INSN(cond_seq, condition_location, dup);
7800 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7801 PUSH_INSN1(cond_seq, condition_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
7804 if (PM_NODE_TYPE_P(condition, PM_STRING_NODE)) {
7806 VALUE value = parse_static_literal_string(iseq, scope_node, condition, &string->
unescaped);
7807 PUSH_INSN1(cond_seq, condition_location, putobject, value);
7810 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7813 PUSH_INSN1(cond_seq, condition_location, topn,
INT2FIX(1));
7814 PUSH_SEND_WITH_FLAG(cond_seq, condition_location, idEqq,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
7817 PUSH_INSNL(cond_seq, condition_location, branchif, label);
7824 PUSH_LABEL(body_seq, label);
7825 PUSH_INSN(body_seq, clause_location, pop);
7828 if (PM_BRANCH_COVERAGE_P(iseq)) {
7830 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7833 if (clause->statements != NULL) {
7834 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7837 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7840 PUSH_INSNL(body_seq, clause_location, jump, end_label);
7851 if (dispatch !=
Qundef) {
7852 PUSH_INSN(ret, location, dup);
7854 PUSH_INSN2(ret, location, opt_case_dispatch, dispatch, else_label);
7855 LABEL_REF(else_label);
7858 PUSH_SEQ(ret, cond_seq);
7862 PUSH_LABEL(ret, else_label);
7866 PUSH_INSN(ret, else_location, pop);
7869 if (PM_BRANCH_COVERAGE_P(iseq)) {
7871 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7875 PUSH_INSNL(ret, else_location, jump, end_label);
7878 PUSH_INSN(ret, location, pop);
7881 if (PM_BRANCH_COVERAGE_P(iseq)) {
7882 add_trace_branch_coverage(iseq, ret, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7885 if (!popped) PUSH_INSN(ret, location, putnil);
7886 PUSH_INSNL(ret, location, jump, end_label);
7890 PUSH_SEQ(ret, body_seq);
7891 PUSH_LABEL(ret, end_label);
7900 DECL_ANCHOR(body_seq);
7905 DECL_ANCHOR(cond_seq);
7909 LABEL *end_label = NEW_LABEL(location->
line);
7914 LABEL *else_label = NEW_LABEL(location->
line);
7922 if (PM_BRANCH_COVERAGE_P(iseq)) {
7923 case_location = pm_code_location(scope_node, (
const pm_node_t *) node);
7924 branches = decl_branch_base(iseq, (
int) node->
base.
node_id, &case_location,
"case");
7934 if (in_single_pattern) {
7935 PUSH_INSN(ret, *location, putnil);
7936 PUSH_INSN(ret, *location, putnil);
7937 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7938 PUSH_INSN(ret, *location, putnil);
7942 PUSH_INSN(ret, *location, putnil);
7951 RUBY_ASSERT(PM_NODE_TYPE_P(condition, PM_IN_NODE));
7958 PUSH_INSN(body_seq, in_location, putnil);
7961 LABEL *body_label = NEW_LABEL(in_location.
line);
7962 PUSH_LABEL(body_seq, body_label);
7963 PUSH_INSN1(body_seq, in_location, adjuststack,
INT2FIX(in_single_pattern ? 6 : 2));
7966 if (PM_BRANCH_COVERAGE_P(iseq)) {
7968 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"in", branches);
7975 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7978 PUSH_INSNL(body_seq, in_location, jump, end_label);
7979 LABEL *next_pattern_label = NEW_LABEL(pattern_location.
line);
7981 PUSH_INSN(cond_seq, pattern_location, dup);
7982 pm_compile_pattern(iseq, scope_node, in_node->
pattern, cond_seq, body_label, next_pattern_label, in_single_pattern,
true, 2);
7983 PUSH_LABEL(cond_seq, next_pattern_label);
7984 LABEL_UNREMOVABLE(next_pattern_label);
7993 PUSH_LABEL(cond_seq, else_label);
7994 PUSH_INSN(cond_seq, *location, pop);
7995 PUSH_INSN(cond_seq, *location, pop);
7998 if (PM_BRANCH_COVERAGE_P(iseq)) {
8000 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
8003 PM_COMPILE_INTO_ANCHOR(cond_seq, (
const pm_node_t *) else_node);
8004 PUSH_INSNL(cond_seq, *location, jump, end_label);
8005 PUSH_INSN(cond_seq, *location, putnil);
8006 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8011 PUSH_LABEL(cond_seq, else_label);
8014 add_trace_branch_coverage(iseq, cond_seq, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
8016 if (in_single_pattern) {
8017 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, cond_seq, end_label, popped);
8020 PUSH_INSN1(cond_seq, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8022 PUSH_INSN1(cond_seq, *location, topn,
INT2FIX(2));
8023 PUSH_SEND(cond_seq, *location, id_core_raise,
INT2FIX(2));
8025 PUSH_INSN1(cond_seq, *location, adjuststack,
INT2FIX(3));
8026 if (!popped) PUSH_INSN(cond_seq, *location, putnil);
8027 PUSH_INSNL(cond_seq, *location, jump, end_label);
8028 PUSH_INSN1(cond_seq, *location, dupn,
INT2FIX(1));
8029 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8036 PUSH_SEQ(ret, cond_seq);
8037 PUSH_SEQ(ret, body_seq);
8038 PUSH_LABEL(ret, end_label);
8046 LABEL *retry_label = NULL;
8047 LABEL *retry_end_l = NULL;
8049 if (node->
block != NULL) {
8050 previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8051 ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
8053 retry_label = NEW_LABEL(location->
line);
8054 retry_end_l = NEW_LABEL(location->
line);
8056 PUSH_LABEL(ret, retry_label);
8059 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8062 PUSH_INSN(ret, *location, putself);
8063 int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
8065 if (node->
block != NULL) {
8067 pm_scope_node_init((
const pm_node_t *) node->
block, &next_scope_node, scope_node);
8069 ISEQ_COMPILE_DATA(iseq)->current_block = block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8070 pm_scope_node_destroy(&next_scope_node);
8077 const rb_iseq_t *local_iseq = body->local_iseq;
8081 int depth = get_lvar_level(iseq);
8083 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8084 flag |= VM_CALL_FORWARDING;
8085 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
8086 PUSH_GETLOCAL(ret, *location, mult_local.index, mult_local.level);
8088 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, 0, flag, NULL, block != NULL);
8089 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, block);
8091 if (popped) PUSH_INSN(ret, *location, pop);
8093 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8098 if (local_body->param.flags.has_lead) {
8100 for (
int i = 0; i < local_body->param.lead_num; i++) {
8101 int idx = local_body->local_table_size - i;
8102 PUSH_GETLOCAL(args, *location, idx, depth);
8104 argc += local_body->param.lead_num;
8107 if (local_body->param.flags.has_opt) {
8109 for (
int j = 0; j < local_body->param.opt_num; j++) {
8110 int idx = local_body->local_table_size - (argc + j);
8111 PUSH_GETLOCAL(args, *location, idx, depth);
8113 argc += local_body->param.opt_num;
8116 if (local_body->param.flags.has_rest) {
8118 int idx = local_body->local_table_size - local_body->param.rest_start;
8119 PUSH_GETLOCAL(args, *location, idx, depth);
8120 PUSH_INSN1(args, *location, splatarray,
Qfalse);
8122 argc = local_body->param.rest_start + 1;
8123 flag |= VM_CALL_ARGS_SPLAT;
8126 if (local_body->param.flags.has_post) {
8128 int post_len = local_body->param.post_num;
8129 int post_start = local_body->param.post_start;
8132 for (; j < post_len; j++) {
8133 int idx = local_body->local_table_size - (post_start + j);
8134 PUSH_GETLOCAL(args, *location, idx, depth);
8137 if (local_body->param.flags.has_rest) {
8139 PUSH_INSN1(args, *location, newarray,
INT2FIX(j));
8140 PUSH_INSN(args, *location, concatarray);
8143 argc = post_len + post_start;
8147 const struct rb_iseq_param_keyword *
const local_keyword = local_body->param.keyword;
8148 if (local_body->param.flags.has_kw) {
8149 int local_size = local_body->local_table_size;
8152 PUSH_INSN1(args, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8154 if (local_body->param.flags.has_kwrest) {
8155 int idx = local_body->local_table_size - local_keyword->rest_start;
8156 PUSH_GETLOCAL(args, *location, idx, depth);
8158 PUSH_SEND(args, *location, rb_intern(
"dup"),
INT2FIX(0));
8161 PUSH_INSN1(args, *location, newhash,
INT2FIX(0));
8164 for (; i < local_keyword->num; ++i) {
8165 ID id = local_keyword->table[i];
8166 int idx = local_size - get_local_var_idx(local_iseq,
id);
8170 PUSH_INSN1(args, *location, putobject, operand);
8173 PUSH_GETLOCAL(args, *location, idx, depth);
8176 PUSH_SEND(args, *location, id_core_hash_merge_ptr,
INT2FIX(i * 2 + 1));
8177 flag |= VM_CALL_KW_SPLAT| VM_CALL_KW_SPLAT_MUT;
8179 else if (local_body->param.flags.has_kwrest) {
8180 int idx = local_body->local_table_size - local_keyword->rest_start;
8181 PUSH_GETLOCAL(args, *location, idx, depth);
8183 flag |= VM_CALL_KW_SPLAT;
8186 PUSH_SEQ(ret, args);
8189 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flag, NULL, block != NULL);
8190 PUSH_INSN2(ret, *location, invokesuper, callinfo, block);
8193 if (node->
block != NULL) {
8194 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8195 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, block, retry_end_l);
8196 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8199 if (popped) PUSH_INSN(ret, *location, pop);
8205 LABEL *matched_label = NEW_LABEL(location->
line);
8206 LABEL *unmatched_label = NEW_LABEL(location->
line);
8207 LABEL *done_label = NEW_LABEL(location->
line);
8211 PUSH_INSN(ret, *location, putnil);
8212 PUSH_INSN(ret, *location, putnil);
8213 PUSH_INSN1(ret, *location, putobject,
Qfalse);
8214 PUSH_INSN(ret, *location, putnil);
8215 PUSH_INSN(ret, *location, putnil);
8219 PM_COMPILE_NOT_POPPED(node->
value);
8223 PUSH_INSN(ret, *location, dup);
8230 pm_compile_pattern(iseq, scope_node, node->
pattern, ret, matched_label, unmatched_label,
true,
true, 2);
8235 PUSH_LABEL(ret, unmatched_label);
8236 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, ret, done_label, popped);
8240 PUSH_LABEL(ret, matched_label);
8241 PUSH_INSN1(ret, *location, adjuststack,
INT2FIX(6));
8242 if (!popped) PUSH_INSN(ret, *location, putnil);
8243 PUSH_INSNL(ret, *location, jump, done_label);
8245 PUSH_LABEL(ret, done_label);
8251 LABEL *fail_label = NEW_LABEL(location->
line);
8252 LABEL *end_label = NEW_LABEL(location->
line);
8263 PUSH_INSN1(ret, *location, getglobal, operand);
8266 PUSH_INSN(ret, *location, dup);
8267 PUSH_INSNL(ret, *location, branchunless, fail_label);
8273 if (targets_count == 1) {
8275 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8282 PUSH_INSN1(ret, *location, putobject, operand);
8285 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8286 PUSH_LABEL(ret, fail_label);
8287 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8288 if (popped) PUSH_INSN(ret, *location, pop);
8292 DECL_ANCHOR(fail_anchor);
8296 for (
size_t targets_index = 0; targets_index < targets_count; targets_index++) {
8298 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8303 if (((
size_t) targets_index) < (targets_count - 1)) {
8304 PUSH_INSN(ret, *location, dup);
8309 PUSH_INSN1(ret, *location, putobject, operand);
8312 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8313 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8315 PUSH_INSN(fail_anchor, *location, putnil);
8316 PUSH_SETLOCAL(fail_anchor, *location, index.index, index.level);
8320 PUSH_INSNL(ret, *location, jump, end_label);
8324 PUSH_LABEL(ret, fail_label);
8325 PUSH_INSN(ret, *location, pop);
8326 PUSH_SEQ(ret, fail_anchor);
8329 PUSH_LABEL(ret, end_label);
8330 if (popped) PUSH_INSN(ret, *location, pop);
8336 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
8337 LABEL *splabel = NEW_LABEL(0);
8338 PUSH_LABEL(ret, splabel);
8344 PUSH_INSN(ret, *location, putnil);
8346 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8348 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8349 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8351 PUSH_ADJUST_RESTORE(ret, splabel);
8352 if (!popped) PUSH_INSN(ret, *location, putnil);
8354 else if (ISEQ_COMPILE_DATA(iseq)->end_label && can_add_ensure_iseq(iseq)) {
8355 LABEL *splabel = NEW_LABEL(0);
8357 PUSH_LABEL(ret, splabel);
8358 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8364 PUSH_INSN(ret, *location, putnil);
8367 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8368 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
8369 PUSH_ADJUST_RESTORE(ret, splabel);
8370 splabel->unremovable = FALSE;
8372 if (!popped) PUSH_INSN(ret, *location, putnil);
8376 unsigned long throw_flag = 0;
8379 if (!ISEQ_COMPILE_DATA(ip)) {
8384 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
8385 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8389 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8392 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8393 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8397 ip = ISEQ_BODY(ip)->parent_iseq;
8405 PUSH_INSN(ret, *location, putnil);
8408 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_NEXT));
8409 if (popped) PUSH_INSN(ret, *location, pop);
8412 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8420 if (ISEQ_COMPILE_DATA(iseq)->redo_label && can_add_ensure_iseq(iseq)) {
8421 LABEL *splabel = NEW_LABEL(0);
8423 PUSH_LABEL(ret, splabel);
8424 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8425 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8427 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
8428 PUSH_ADJUST_RESTORE(ret, splabel);
8429 if (!popped) PUSH_INSN(ret, *location, putnil);
8431 else if (ISEQ_BODY(iseq)->
type != ISEQ_TYPE_EVAL && ISEQ_COMPILE_DATA(iseq)->start_label && can_add_ensure_iseq(iseq)) {
8432 LABEL *splabel = NEW_LABEL(0);
8434 PUSH_LABEL(ret, splabel);
8435 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8436 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8438 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8439 PUSH_ADJUST_RESTORE(ret, splabel);
8440 if (!popped) PUSH_INSN(ret, *location, putnil);
8446 if (!ISEQ_COMPILE_DATA(ip)) {
8451 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8454 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8457 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8458 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8462 ip = ISEQ_BODY(ip)->parent_iseq;
8466 PUSH_INSN(ret, *location, putnil);
8467 PUSH_INSN1(ret, *location,
throw,
INT2FIX(VM_THROW_NO_ESCAPE_FLAG | TAG_REDO));
8468 if (popped) PUSH_INSN(ret, *location, pop);
8471 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8479 iseq_set_exception_local_table(iseq);
8483 LABEL *exception_match_label = NEW_LABEL(location->
line);
8484 LABEL *rescue_end_label = NEW_LABEL(location->
line);
8494 if (exceptions->
size > 0) {
8495 for (
size_t index = 0; index < exceptions->
size; index++) {
8496 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8497 PM_COMPILE(exceptions->
nodes[index]);
8498 int checkmatch_flags = VM_CHECKMATCH_TYPE_RESCUE;
8499 if (PM_NODE_TYPE_P(exceptions->
nodes[index], PM_SPLAT_NODE)) {
8500 checkmatch_flags |= VM_CHECKMATCH_ARRAY;
8502 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(checkmatch_flags));
8503 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8507 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8509 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
8510 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8515 PUSH_INSNL(ret, *location, jump, rescue_end_label);
8520 PUSH_LABEL(ret, exception_match_label);
8527 DECL_ANCHOR(writes);
8528 DECL_ANCHOR(cleanup);
8530 pm_compile_target_node(iseq, node->
reference, ret, writes, cleanup, scope_node, NULL);
8531 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8533 PUSH_SEQ(ret, writes);
8534 PUSH_SEQ(ret, cleanup);
8544 LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
8545 ISEQ_COMPILE_DATA(iseq)->end_label = NULL;
8550 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
8553 PUSH_INSN(ret, *location, putnil);
8556 PUSH_INSN(ret, *location, leave);
8562 PUSH_LABEL(ret, rescue_end_label);
8567 PUSH_GETLOCAL(ret, *location, 1, 0);
8575 enum rb_iseq_type
type = ISEQ_BODY(iseq)->type;
8579 enum rb_iseq_type parent_type = ISEQ_BODY(parent_iseq)->type;
8580 while (parent_type == ISEQ_TYPE_RESCUE || parent_type == ISEQ_TYPE_ENSURE) {
8581 if (!(parent_iseq = ISEQ_BODY(parent_iseq)->parent_iseq))
break;
8582 parent_type = ISEQ_BODY(parent_iseq)->type;
8585 switch (parent_type) {
8587 case ISEQ_TYPE_MAIN:
8589 rb_warn(
"argument of top-level return is ignored");
8591 if (parent_iseq == iseq) {
8592 type = ISEQ_TYPE_METHOD;
8599 if (
type == ISEQ_TYPE_METHOD) {
8600 splabel = NEW_LABEL(0);
8601 PUSH_LABEL(ret, splabel);
8602 PUSH_ADJUST(ret, *location, 0);
8605 if (arguments != NULL) {
8606 PM_COMPILE_NOT_POPPED((
const pm_node_t *) arguments);
8609 PUSH_INSN(ret, *location, putnil);
8612 if (
type == ISEQ_TYPE_METHOD && can_add_ensure_iseq(iseq)) {
8613 pm_add_ensure_iseq(ret, iseq, 1, scope_node);
8615 PUSH_INSN(ret, *location, leave);
8616 PUSH_ADJUST_RESTORE(ret, splabel);
8617 if (!popped) PUSH_INSN(ret, *location, putnil);
8620 PUSH_INSN1(ret, *location,
throw,
INT2FIX(TAG_RETURN));
8621 if (popped) PUSH_INSN(ret, *location, pop);
8630 LABEL *retry_label = NEW_LABEL(location->
line);
8631 LABEL *retry_end_l = NEW_LABEL(location->
line);
8633 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8635 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NULL;
8637 PUSH_LABEL(ret, retry_label);
8638 PUSH_INSN(ret, *location, putself);
8642 int argc = pm_setup_args(node->
arguments, node->
block, &flags, &keywords, iseq, ret, scope_node, location);
8643 bool is_forwardable = (node->
arguments != NULL) && PM_NODE_FLAG_P(node->
arguments, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING);
8644 flags |= VM_CALL_SUPER | VM_CALL_FCALL;
8646 if (node->
block && PM_NODE_TYPE_P(node->
block, PM_BLOCK_NODE)) {
8648 pm_scope_node_init(node->
block, &next_scope_node, scope_node);
8650 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8651 pm_scope_node_destroy(&next_scope_node);
8655 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8658 if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
8659 PUSH_INSN(args, *location, splatkw);
8662 PUSH_SEQ(ret, args);
8663 if (is_forwardable && ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8664 flags |= VM_CALL_FORWARDING;
8667 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8668 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, current_block);
8673 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8674 PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
8679 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8681 if (popped) PUSH_INSN(ret, *location, pop);
8682 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8683 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);
8689 switch (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
type) {
8691 case ISEQ_TYPE_MAIN:
8692 case ISEQ_TYPE_CLASS:
8693 COMPILE_ERROR(iseq, location->
line,
"Invalid yield");
8703 argc = pm_setup_args(node->
arguments, NULL, &flags, &keywords, iseq, ret, scope_node, location);
8706 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, FALSE);
8707 PUSH_INSN1(ret, *location, invokeblock, callinfo);
8709 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8710 if (popped) PUSH_INSN(ret, *location, pop);
8713 for (
const rb_iseq_t *tmp_iseq = iseq; tmp_iseq != ISEQ_BODY(iseq)->local_iseq; level++) {
8714 tmp_iseq = ISEQ_BODY(tmp_iseq)->parent_iseq;
8717 if (level > 0) access_outer_variables(iseq, level, rb_intern(
"yield"),
true);
8734 int lineno = (int) location.
line;
8736 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)) {
8741 lineno = (int) PM_NODE_START_LINE_COLUMN(((
const pm_begin_node_t *) node)->rescue_clause).line;
8744 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_NEWLINE) && ISEQ_COMPILE_DATA(iseq)->last_line != lineno) {
8750 ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8751 if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8752 event |= RUBY_EVENT_COVERAGE_LINE;
8754 PUSH_TRACE(ret, event);
8757 switch (PM_NODE_TYPE(node)) {
8758 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
8763 case PM_ALIAS_METHOD_NODE:
8766 pm_compile_alias_method_node(iseq, (
const pm_alias_method_node_t *) node, &location, ret, popped, scope_node);
8771 pm_compile_and_node(iseq, (
const pm_and_node_t *) node, &location, ret, popped, scope_node);
8773 case PM_ARGUMENTS_NODE: {
8783 if (elements->
size == 1) {
8786 PM_COMPILE(elements->
nodes[0]);
8789 pm_compile_array_node(iseq, (
const pm_node_t *) cast, elements, &location, ret, popped, scope_node);
8793 case PM_ARRAY_NODE: {
8797 pm_compile_array_node(iseq, (
const pm_node_t *) cast, &cast->elements, &location, ret, popped, scope_node);
8800 case PM_ASSOC_NODE: {
8808 PM_COMPILE(cast->
key);
8809 PM_COMPILE(cast->
value);
8813 case PM_ASSOC_SPLAT_NODE: {
8821 if (cast->
value != NULL) {
8822 PM_COMPILE(cast->
value);
8825 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
8826 PUSH_GETLOCAL(ret, location, index.index, index.level);
8831 case PM_BACK_REFERENCE_READ_NODE: {
8836 VALUE backref = pm_compile_back_reference_ref(scope_node, cast);
8838 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), backref);
8842 case PM_BEGIN_NODE: {
8850 pm_compile_ensure(iseq, cast, &location, ret, popped, scope_node);
8854 pm_compile_rescue(iseq, cast, &location, ret, popped, scope_node);
8863 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8868 case PM_BLOCK_ARGUMENT_NODE: {
8878 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
8879 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(local_index.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(local_index.level));
8889 pm_compile_break_node(iseq, (
const pm_break_node_t *) node, &location, ret, popped, scope_node);
8900 pm_compile_call_node(iseq, (
const pm_call_node_t *) node, ret, popped, scope_node);
8902 case PM_CALL_AND_WRITE_NODE: {
8906 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);
8909 case PM_CALL_OR_WRITE_NODE: {
8913 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);
8916 case PM_CALL_OPERATOR_WRITE_NODE:
8931 pm_compile_case_node(iseq, (
const pm_case_node_t *) node, &location, ret, popped, scope_node);
8933 case PM_CASE_MATCH_NODE:
8942 pm_compile_case_match_node(iseq, (
const pm_case_match_node_t *) node, &location, ret, popped, scope_node);
8944 case PM_CLASS_NODE: {
8949 ID class_id = pm_constant_id_lookup(scope_node, cast->
name);
8950 VALUE class_name =
rb_str_freeze(rb_sprintf(
"<class:%"PRIsVALUE
">", rb_id2str(class_id)));
8953 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
8955 const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(&next_scope_node, class_name, ISEQ_TYPE_CLASS, location.
line);
8956 pm_scope_node_destroy(&next_scope_node);
8959 const int flags = VM_DEFINECLASS_TYPE_CLASS |
8960 (cast->
superclass ? VM_DEFINECLASS_FLAG_HAS_SUPERCLASS : 0) |
8961 pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
8967 PUSH_INSN(ret, location, putnil);
8972 PUSH_INSN3(ret, location, defineclass, operand, class_iseq,
INT2FIX(flags));
8976 if (popped) PUSH_INSN(ret, location, pop);
8979 case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
8983 LABEL *end_label = NEW_LABEL(location.
line);
8985 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8988 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8989 if (!popped) PUSH_INSN(ret, location, dup);
8991 PUSH_INSNL(ret, location, branchunless, end_label);
8992 if (!popped) PUSH_INSN(ret, location, pop);
8994 PM_COMPILE_NOT_POPPED(cast->
value);
8995 if (!popped) PUSH_INSN(ret, location, dup);
8997 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8998 PUSH_LABEL(ret, end_label);
9002 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
9007 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9010 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9011 PM_COMPILE_NOT_POPPED(cast->
value);
9014 int flags = VM_CALL_ARGS_SIMPLE;
9015 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9017 if (!popped) PUSH_INSN(ret, location, dup);
9018 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9022 case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
9026 LABEL *end_label = NEW_LABEL(location.
line);
9027 LABEL *start_label = NEW_LABEL(location.
line);
9029 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9032 PUSH_INSN(ret, location, putnil);
9033 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name,
Qtrue);
9034 PUSH_INSNL(ret, location, branchunless, start_label);
9036 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9037 if (!popped) PUSH_INSN(ret, location, dup);
9039 PUSH_INSNL(ret, location, branchif, end_label);
9040 if (!popped) PUSH_INSN(ret, location, pop);
9042 PUSH_LABEL(ret, start_label);
9043 PM_COMPILE_NOT_POPPED(cast->
value);
9044 if (!popped) PUSH_INSN(ret, location, dup);
9046 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9047 PUSH_LABEL(ret, end_label);
9051 case PM_CLASS_VARIABLE_READ_NODE: {
9056 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9057 PUSH_INSN2(ret, location, getclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9061 case PM_CLASS_VARIABLE_WRITE_NODE: {
9065 PM_COMPILE_NOT_POPPED(cast->
value);
9066 if (!popped) PUSH_INSN(ret, location, dup);
9068 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9069 PUSH_INSN2(ret, location, setclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9073 case PM_CONSTANT_PATH_NODE: {
9078 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache && ((parts = pm_constant_path_parts(node, scope_node)) !=
Qnil)) {
9079 ISEQ_BODY(iseq)->ic_size++;
9081 PUSH_INSN1(ret, location, opt_getconstant_path, parts);
9084 DECL_ANCHOR(prefix);
9087 pm_compile_constant_path(iseq, node, prefix, body, popped, scope_node);
9088 if (LIST_INSN_SIZE_ZERO(prefix)) {
9089 PUSH_INSN(ret, location, putnil);
9092 PUSH_SEQ(ret, prefix);
9095 PUSH_SEQ(ret, body);
9098 if (popped) PUSH_INSN(ret, location, pop);
9101 case PM_CONSTANT_PATH_AND_WRITE_NODE: {
9105 pm_compile_constant_path_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9108 case PM_CONSTANT_PATH_OR_WRITE_NODE: {
9112 pm_compile_constant_path_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9115 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
9119 pm_compile_constant_path_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9122 case PM_CONSTANT_PATH_WRITE_NODE: {
9126 pm_compile_constant_path_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9129 case PM_CONSTANT_READ_NODE: {
9135 pm_compile_constant_read(iseq, name, &cast->
base.
location, location.
node_id, ret, scope_node);
9136 if (popped) PUSH_INSN(ret, location, pop);
9140 case PM_CONSTANT_AND_WRITE_NODE: {
9144 pm_compile_constant_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9147 case PM_CONSTANT_OR_WRITE_NODE: {
9151 pm_compile_constant_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9154 case PM_CONSTANT_OPERATOR_WRITE_NODE: {
9158 pm_compile_constant_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9161 case PM_CONSTANT_WRITE_NODE: {
9165 pm_compile_constant_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9175 ID method_name = pm_constant_id_lookup(scope_node, cast->
name);
9178 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9180 rb_iseq_t *method_iseq = NEW_ISEQ(&next_scope_node, rb_id2str(method_name), ISEQ_TYPE_METHOD, location.
line);
9181 pm_scope_node_destroy(&next_scope_node);
9184 PM_COMPILE_NOT_POPPED(cast->
receiver);
9185 PUSH_INSN2(ret, location, definesmethod,
ID2SYM(method_name), method_iseq);
9188 PUSH_INSN2(ret, location, definemethod,
ID2SYM(method_name), method_iseq);
9193 PUSH_INSN1(ret, location, putobject,
ID2SYM(method_name));
9198 case PM_DEFINED_NODE: {
9202 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
false);
9205 case PM_EMBEDDED_STATEMENTS_NODE: {
9214 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9217 if (popped) PUSH_INSN(ret, location, pop);
9220 case PM_EMBEDDED_VARIABLE_NODE: {
9227 case PM_FALSE_NODE: {
9231 PUSH_INSN1(ret, location, putobject,
Qfalse);
9235 case PM_ENSURE_NODE: {
9244 case PM_ELSE_NODE: {
9253 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9258 case PM_FLIP_FLOP_NODE: {
9263 LABEL *final_label = NEW_LABEL(location.
line);
9264 LABEL *then_label = NEW_LABEL(location.
line);
9265 LABEL *else_label = NEW_LABEL(location.
line);
9267 pm_compile_flip_flop(cast, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
9269 PUSH_LABEL(ret, then_label);
9270 PUSH_INSN1(ret, location, putobject,
Qtrue);
9271 PUSH_INSNL(ret, location, jump, final_label);
9272 PUSH_LABEL(ret, else_label);
9273 PUSH_INSN1(ret, location, putobject,
Qfalse);
9274 PUSH_LABEL(ret, final_label);
9278 case PM_FLOAT_NODE: {
9283 PUSH_INSN1(ret, location, putobject, operand);
9292 LABEL *retry_label = NEW_LABEL(location.
line);
9293 LABEL *retry_end_l = NEW_LABEL(location.
line);
9296 PUSH_LABEL(ret, retry_label);
9302 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9304 const rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location.
line);
9305 pm_scope_node_destroy(&next_scope_node);
9307 const rb_iseq_t *prev_block = ISEQ_COMPILE_DATA(iseq)->current_block;
9308 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
9312 PUSH_SEND_WITH_BLOCK(ret, location, idEach,
INT2FIX(0), child_iseq);
9313 pm_compile_retry_end_label(iseq, ret, retry_end_l);
9315 if (popped) PUSH_INSN(ret, location, pop);
9316 ISEQ_COMPILE_DATA(iseq)->current_block = prev_block;
9317 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
9320 case PM_FORWARDING_ARGUMENTS_NODE:
9321 rb_bug(
"Cannot compile a ForwardingArgumentsNode directly\n");
9323 case PM_FORWARDING_SUPER_NODE:
9331 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
9335 LABEL *end_label = NEW_LABEL(location.
line);
9338 PUSH_INSN1(ret, location, getglobal, name);
9339 if (!popped) PUSH_INSN(ret, location, dup);
9341 PUSH_INSNL(ret, location, branchunless, end_label);
9342 if (!popped) PUSH_INSN(ret, location, pop);
9344 PM_COMPILE_NOT_POPPED(cast->
value);
9345 if (!popped) PUSH_INSN(ret, location, dup);
9347 PUSH_INSN1(ret, location, setglobal, name);
9348 PUSH_LABEL(ret, end_label);
9352 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
9358 PUSH_INSN1(ret, location, getglobal, name);
9359 PM_COMPILE_NOT_POPPED(cast->
value);
9362 int flags = VM_CALL_ARGS_SIMPLE;
9363 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9365 if (!popped) PUSH_INSN(ret, location, dup);
9366 PUSH_INSN1(ret, location, setglobal, name);
9370 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
9374 LABEL *set_label = NEW_LABEL(location.
line);
9375 LABEL *end_label = NEW_LABEL(location.
line);
9377 PUSH_INSN(ret, location, putnil);
9380 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name,
Qtrue);
9381 PUSH_INSNL(ret, location, branchunless, set_label);
9383 PUSH_INSN1(ret, location, getglobal, name);
9384 if (!popped) PUSH_INSN(ret, location, dup);
9386 PUSH_INSNL(ret, location, branchif, end_label);
9387 if (!popped) PUSH_INSN(ret, location, pop);
9389 PUSH_LABEL(ret, set_label);
9390 PM_COMPILE_NOT_POPPED(cast->
value);
9391 if (!popped) PUSH_INSN(ret, location, dup);
9393 PUSH_INSN1(ret, location, setglobal, name);
9394 PUSH_LABEL(ret, end_label);
9398 case PM_GLOBAL_VARIABLE_READ_NODE: {
9404 PUSH_INSN1(ret, location, getglobal, name);
9405 if (popped) PUSH_INSN(ret, location, pop);
9409 case PM_GLOBAL_VARIABLE_WRITE_NODE: {
9413 PM_COMPILE_NOT_POPPED(cast->
value);
9414 if (!popped) PUSH_INSN(ret, location, dup);
9416 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9417 PUSH_INSN1(ret, location, setglobal,
ID2SYM(name));
9421 case PM_HASH_NODE: {
9427 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9435 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
9438 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9439 PUSH_INSN1(ret, location, duphash, value);
9460 for (
size_t index = 0; index < elements->
size; index++) {
9461 PM_COMPILE_POPPED(elements->
nodes[index]);
9465 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9481 pm_compile_conditional(iseq, &location, PM_IF_NODE, (
const pm_node_t *) cast, cast->statements, cast->subsequent, cast->predicate, ret, popped, scope_node);
9484 case PM_IMAGINARY_NODE: {
9489 PUSH_INSN1(ret, location, putobject, operand);
9493 case PM_IMPLICIT_NODE: {
9503 PM_COMPILE(cast->
value);
9509 rb_bug(
"Should not ever enter an in node directly");
9512 case PM_INDEX_OPERATOR_WRITE_NODE: {
9516 pm_compile_index_operator_write_node(iseq, cast, &location, ret, popped, scope_node);
9519 case PM_INDEX_AND_WRITE_NODE: {
9523 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9526 case PM_INDEX_OR_WRITE_NODE: {
9530 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9533 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
9537 LABEL *end_label = NEW_LABEL(location.
line);
9539 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9542 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9543 if (!popped) PUSH_INSN(ret, location, dup);
9545 PUSH_INSNL(ret, location, branchunless, end_label);
9546 if (!popped) PUSH_INSN(ret, location, pop);
9548 PM_COMPILE_NOT_POPPED(cast->
value);
9549 if (!popped) PUSH_INSN(ret, location, dup);
9551 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9552 PUSH_LABEL(ret, end_label);
9556 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
9561 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9564 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9565 PM_COMPILE_NOT_POPPED(cast->
value);
9568 int flags = VM_CALL_ARGS_SIMPLE;
9569 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9571 if (!popped) PUSH_INSN(ret, location, dup);
9572 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9576 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
9580 LABEL *end_label = NEW_LABEL(location.
line);
9582 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9585 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9586 if (!popped) PUSH_INSN(ret, location, dup);
9588 PUSH_INSNL(ret, location, branchif, end_label);
9589 if (!popped) PUSH_INSN(ret, location, pop);
9591 PM_COMPILE_NOT_POPPED(cast->
value);
9592 if (!popped) PUSH_INSN(ret, location, dup);
9594 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9595 PUSH_LABEL(ret, end_label);
9599 case PM_INSTANCE_VARIABLE_READ_NODE: {
9604 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9605 PUSH_INSN2(ret, location, getinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9609 case PM_INSTANCE_VARIABLE_WRITE_NODE: {
9613 PM_COMPILE_NOT_POPPED(cast->
value);
9614 if (!popped) PUSH_INSN(ret, location, dup);
9616 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9617 PUSH_INSN2(ret, location, setinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9621 case PM_INTEGER_NODE: {
9626 PUSH_INSN1(ret, location, putobject, operand);
9630 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
9633 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9635 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9636 PUSH_INSN1(ret, location, putobject, regexp);
9643 PUSH_INSN1(ret, location, getglobal,
rb_id2sym(idLASTLINE));
9644 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9645 if (popped) PUSH_INSN(ret, location, pop);
9649 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
9652 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ONCE)) {
9653 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9655 int ise_index = ISEQ_BODY(iseq)->ise_size++;
9658 pm_scope_node_init(node, &next_scope_node, scope_node);
9660 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, location.
line);
9661 pm_scope_node_destroy(&next_scope_node);
9663 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
9664 PUSH_INSN2(ret, location, once, block_iseq,
INT2FIX(ise_index));
9665 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9667 if (popped) PUSH_INSN(ret, location, pop);
9671 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9673 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9674 PUSH_INSN1(ret, location, putobject, regexp);
9679 if (popped) PUSH_INSN(ret, location, pop);
9684 case PM_INTERPOLATED_STRING_NODE: {
9687 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9689 VALUE string = pm_static_literal_value(iseq, node, scope_node);
9691 if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN)) {
9692 PUSH_INSN1(ret, location, putobject,
string);
9694 else if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE)) {
9695 PUSH_INSN1(ret, location, dupstring,
string);
9698 PUSH_INSN1(ret, location, dupchilledstring,
string);
9704 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));
9705 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9706 if (popped) PUSH_INSN(ret, location, pop);
9711 case PM_INTERPOLATED_SYMBOL_NODE: {
9715 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL,
false,
false);
9718 PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9722 PUSH_INSN(ret, location, intern);
9725 PUSH_INSN(ret, location, pop);
9730 case PM_INTERPOLATED_X_STRING_NODE: {
9735 PUSH_INSN(ret, location, putself);
9737 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret,
false, scope_node, NULL, NULL,
false,
false);
9738 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9740 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
9741 if (popped) PUSH_INSN(ret, location, pop);
9745 case PM_IT_LOCAL_VARIABLE_READ_NODE: {
9752 while (current_scope_node) {
9753 if (current_scope_node->parameters && PM_NODE_TYPE_P(current_scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
9754 PUSH_GETLOCAL(ret, location, current_scope_node->local_table_for_iseq_size, level);
9758 current_scope_node = current_scope_node->previous;
9761 rb_bug(
"Local `it` does not exist");
9766 case PM_KEYWORD_HASH_NODE: {
9772 bool has_splat =
false;
9773 for (
size_t index = 0; index < elements->
size; index++) {
9774 if (PM_NODE_TYPE_P(elements->
nodes[index], PM_ASSOC_SPLAT_NODE)) {
9781 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9786 PM_COMPILE(element);
9789 if (!popped) PUSH_INSN1(ret, location, newhash,
INT2FIX(elements->
size * 2));
9793 case PM_LAMBDA_NODE: {
9799 pm_scope_node_init(node, &next_scope_node, scope_node);
9801 int opening_lineno = pm_location_line_number_cached(&cast->
opening_loc, scope_node);
9802 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, opening_lineno);
9803 pm_scope_node_destroy(&next_scope_node);
9806 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9807 PUSH_CALL_WITH_BLOCK(ret, location, idLambda, argc, block);
9810 if (popped) PUSH_INSN(ret, location, pop);
9813 case PM_LOCAL_VARIABLE_AND_WRITE_NODE: {
9817 LABEL *end_label = NEW_LABEL(location.
line);
9820 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9821 if (!popped) PUSH_INSN(ret, location, dup);
9823 PUSH_INSNL(ret, location, branchunless, end_label);
9824 if (!popped) PUSH_INSN(ret, location, pop);
9826 PM_COMPILE_NOT_POPPED(cast->
value);
9827 if (!popped) PUSH_INSN(ret, location, dup);
9829 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9830 PUSH_LABEL(ret, end_label);
9834 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
9840 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9842 PM_COMPILE_NOT_POPPED(cast->
value);
9845 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
9847 if (!popped) PUSH_INSN(ret, location, dup);
9848 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9852 case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
9857 LABEL *set_label = NEW_LABEL(location.
line);
9858 LABEL *end_label = NEW_LABEL(location.
line);
9860 PUSH_INSN1(ret, location, putobject,
Qtrue);
9861 PUSH_INSNL(ret, location, branchunless, set_label);
9864 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9865 if (!popped) PUSH_INSN(ret, location, dup);
9867 PUSH_INSNL(ret, location, branchif, end_label);
9868 if (!popped) PUSH_INSN(ret, location, pop);
9870 PUSH_LABEL(ret, set_label);
9871 PM_COMPILE_NOT_POPPED(cast->
value);
9872 if (!popped) PUSH_INSN(ret, location, dup);
9874 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9875 PUSH_LABEL(ret, end_label);
9879 case PM_LOCAL_VARIABLE_READ_NODE: {
9885 PUSH_GETLOCAL(ret, location, index.index, index.level);
9890 case PM_LOCAL_VARIABLE_WRITE_NODE: {
9894 PM_COMPILE_NOT_POPPED(cast->
value);
9895 if (!popped) PUSH_INSN(ret, location, dup);
9898 PUSH_SETLOCAL(ret, location, index.index, index.level);
9901 case PM_MATCH_LAST_LINE_NODE: {
9904 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9906 PUSH_INSN1(ret, location, putobject, regexp);
9908 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9909 if (popped) PUSH_INSN(ret, location, pop);
9913 case PM_MATCH_PREDICATE_NODE: {
9920 PUSH_INSN(ret, location, putnil);
9923 PM_COMPILE_NOT_POPPED(cast->
value);
9924 PUSH_INSN(ret, location, dup);
9928 LABEL *matched_label = NEW_LABEL(location.
line);
9929 LABEL *unmatched_label = NEW_LABEL(location.
line);
9930 LABEL *done_label = NEW_LABEL(location.
line);
9931 pm_compile_pattern(iseq, scope_node, cast->
pattern, ret, matched_label, unmatched_label,
false,
true, 2);
9935 PUSH_LABEL(ret, unmatched_label);
9936 PUSH_INSN(ret, location, pop);
9937 PUSH_INSN(ret, location, pop);
9939 if (!popped) PUSH_INSN1(ret, location, putobject,
Qfalse);
9940 PUSH_INSNL(ret, location, jump, done_label);
9941 PUSH_INSN(ret, location, putnil);
9945 PUSH_LABEL(ret, matched_label);
9946 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(2));
9947 if (!popped) PUSH_INSN1(ret, location, putobject,
Qtrue);
9948 PUSH_INSNL(ret, location, jump, done_label);
9950 PUSH_LABEL(ret, done_label);
9953 case PM_MATCH_REQUIRED_NODE:
9967 case PM_MATCH_WRITE_NODE:
9976 pm_compile_match_write_node(iseq, (
const pm_match_write_node_t *) node, &location, ret, popped, scope_node);
9978 case PM_ERROR_RECOVERY_NODE:
9979 rb_bug(
"A pm_error_recovery_node_t should not exist in prism's AST.");
9981 case PM_MODULE_NODE: {
9986 ID module_id = pm_constant_id_lookup(scope_node, cast->
name);
9987 VALUE module_name =
rb_str_freeze(rb_sprintf(
"<module:%"PRIsVALUE
">", rb_id2str(module_id)));
9990 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9992 const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&next_scope_node, module_name, ISEQ_TYPE_CLASS, location.
line);
9993 pm_scope_node_destroy(&next_scope_node);
9995 const int flags = VM_DEFINECLASS_TYPE_MODULE | pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
9996 PUSH_INSN(ret, location, putnil);
9997 PUSH_INSN3(ret, location, defineclass,
ID2SYM(module_id), module_iseq,
INT2FIX(flags));
10000 if (popped) PUSH_INSN(ret, location, pop);
10003 case PM_REQUIRED_PARAMETER_NODE: {
10009 PUSH_SETLOCAL(ret, location, index.index, index.level);
10012 case PM_MULTI_WRITE_NODE: {
10023 DECL_ANCHOR(writes);
10024 DECL_ANCHOR(cleanup);
10027 state.position = popped ? 0 : 1;
10028 pm_compile_multi_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
10030 PM_COMPILE_NOT_POPPED(cast->
value);
10031 if (!popped) PUSH_INSN(ret, location, dup);
10033 PUSH_SEQ(ret, writes);
10034 if (!popped && state.stack_size >= 1) {
10037 PUSH_INSN1(ret, location, setn,
INT2FIX(state.stack_size));
10042 pm_multi_target_state_update(&state);
10044 PUSH_SEQ(ret, cleanup);
10053 pm_compile_next_node(iseq, (
const pm_next_node_t *) node, &location, ret, popped, scope_node);
10055 case PM_NIL_NODE: {
10059 PUSH_INSN(ret, location, putnil);
10064 case PM_NO_BLOCK_PARAMETER_NODE: {
10067 ISEQ_BODY(iseq)->param.flags.accepts_no_block = TRUE;
10070 case PM_NO_KEYWORDS_PARAMETER_NODE: {
10073 ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg = TRUE;
10076 case PM_NUMBERED_REFERENCE_READ_NODE: {
10082 if (cast->
number != 0) {
10083 VALUE ref = pm_compile_numbered_reference_ref(cast);
10084 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), ref);
10087 PUSH_INSN(ret, location, putnil);
10098 LABEL *end_label = NEW_LABEL(location.
line);
10099 PM_COMPILE_NOT_POPPED(cast->
left);
10101 if (!popped) PUSH_INSN(ret, location, dup);
10102 PUSH_INSNL(ret, location, branchif, end_label);
10104 if (!popped) PUSH_INSN(ret, location, pop);
10105 PM_COMPILE(cast->
right);
10106 PUSH_LABEL(ret, end_label);
10110 case PM_OPTIONAL_PARAMETER_NODE: {
10114 PM_COMPILE_NOT_POPPED(cast->
value);
10117 PUSH_SETLOCAL(ret, location, index.index, index.level);
10121 case PM_PARENTHESES_NODE: {
10129 if (cast->
body != NULL) {
10130 PM_COMPILE(cast->
body);
10132 else if (!popped) {
10133 PUSH_INSN(ret, location, putnil);
10138 case PM_PRE_EXECUTION_NODE: {
10150 DECL_ANCHOR(inner_pre);
10153 DECL_ANCHOR(inner_body);
10158 for (
size_t index = 0; index < body->
size; index++) {
10159 pm_compile_node(iseq, body->
nodes[index], inner_body,
true, scope_node);
10164 PUSH_INSN(inner_body, location, putnil);
10170 PUSH_SEQ(outer_pre, inner_pre);
10171 PUSH_SEQ(outer_pre, inner_body);
10176 case PM_POST_EXECUTION_NODE: {
10180 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
10183 pm_scope_node_init(node, &next_scope_node, scope_node);
10184 child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
10185 pm_scope_node_destroy(&next_scope_node);
10187 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
10189 int is_index = ISEQ_BODY(iseq)->ise_size++;
10190 PUSH_INSN2(ret, location, once, child_iseq,
INT2FIX(is_index));
10192 if (popped) PUSH_INSN(ret, location, pop);
10194 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
10198 case PM_RANGE_NODE: {
10202 bool exclude_end = PM_NODE_FLAG_P(cast, PM_RANGE_FLAGS_EXCLUDE_END);
10204 if (pm_optimizable_range_item_p(cast->
left) && pm_optimizable_range_item_p(cast->
right)) {
10210 (left && PM_NODE_TYPE_P(left, PM_INTEGER_NODE)) ? parse_integer((
const pm_integer_node_t *) left) :
Qnil,
10211 (right && PM_NODE_TYPE_P(right, PM_INTEGER_NODE)) ? parse_integer((const
pm_integer_node_t *) right) :
Qnil,
10216 PUSH_INSN1(ret, location, putobject, val);
10220 if (cast->
left != NULL) {
10221 PM_COMPILE(cast->
left);
10223 else if (!popped) {
10224 PUSH_INSN(ret, location, putnil);
10227 if (cast->
right != NULL) {
10228 PM_COMPILE(cast->
right);
10230 else if (!popped) {
10231 PUSH_INSN(ret, location, putnil);
10235 PUSH_INSN1(ret, location, newrange,
INT2FIX(exclude_end ? 1 : 0));
10240 case PM_RATIONAL_NODE: {
10244 PUSH_INSN1(ret, location, putobject, parse_rational((
const pm_rational_node_t *) node));
10251 pm_compile_redo_node(iseq, &location, ret, popped, scope_node);
10253 case PM_REGULAR_EXPRESSION_NODE: {
10257 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
10258 PUSH_INSN1(ret, location, putobject, regexp);
10262 case PM_RESCUE_NODE:
10265 pm_compile_rescue_node(iseq, (
const pm_rescue_node_t *) node, &location, ret, popped, scope_node);
10267 case PM_RESCUE_MODIFIER_NODE: {
10273 pm_scope_node_init((
const pm_node_t *) cast, &rescue_scope_node, scope_node);
10275 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
10276 &rescue_scope_node,
10282 pm_scope_node_destroy(&rescue_scope_node);
10284 LABEL *lstart = NEW_LABEL(location.
line);
10285 LABEL *lend = NEW_LABEL(location.
line);
10286 LABEL *lcont = NEW_LABEL(location.
line);
10288 lstart->rescued = LABEL_RESCUE_BEG;
10289 lend->rescued = LABEL_RESCUE_END;
10291 PUSH_LABEL(ret, lstart);
10293 PUSH_LABEL(ret, lend);
10295 PUSH_INSN(ret, location, nop);
10296 PUSH_LABEL(ret, lcont);
10297 if (popped) PUSH_INSN(ret, location, pop);
10299 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
10300 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
10303 case PM_RETURN_NODE:
10309 pm_compile_return_node(iseq, (
const pm_return_node_t *) node, &location, ret, popped, scope_node);
10311 case PM_RETRY_NODE: {
10314 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_RESCUE) {
10315 PUSH_INSN(ret, location, putnil);
10316 PUSH_INSN1(ret, location,
throw,
INT2FIX(TAG_RETRY));
10317 if (popped) PUSH_INSN(ret, location, pop);
10320 COMPILE_ERROR(iseq, location.
line,
"Invalid retry");
10325 case PM_SCOPE_NODE:
10326 pm_compile_scope_node(iseq, (
pm_scope_node_t *) node, &location, ret, popped);
10328 case PM_SELF_NODE: {
10332 PUSH_INSN(ret, location, putself);
10336 case PM_SHAREABLE_CONSTANT_NODE: {
10340 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));
10342 switch (PM_NODE_TYPE(cast->
write)) {
10343 case PM_CONSTANT_WRITE_NODE:
10346 case PM_CONSTANT_AND_WRITE_NODE:
10349 case PM_CONSTANT_OR_WRITE_NODE:
10352 case PM_CONSTANT_OPERATOR_WRITE_NODE:
10355 case PM_CONSTANT_PATH_WRITE_NODE:
10358 case PM_CONSTANT_PATH_AND_WRITE_NODE:
10361 case PM_CONSTANT_PATH_OR_WRITE_NODE:
10364 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
10368 rb_bug(
"Unexpected node type for shareable constant write: %s", pm_node_type(PM_NODE_TYPE(cast->
write)));
10374 case PM_SINGLETON_CLASS_NODE: {
10380 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10381 const rb_iseq_t *child_iseq = NEW_ISEQ(&next_scope_node, rb_fstring_lit(
"singleton class"), ISEQ_TYPE_CLASS, location.
line);
10382 pm_scope_node_destroy(&next_scope_node);
10385 PUSH_INSN(ret, location, putnil);
10388 CONST_ID(singletonclass,
"singletonclass");
10392 int sclass_flags = VM_DEFINECLASS_TYPE_SINGLETON_CLASS;
10393 if (!(PM_NODE_TYPE_P(cast->
expression, PM_SELF_NODE) &&
10394 ISEQ_BODY(iseq)->
type == ISEQ_TYPE_CLASS) &&
10396 sclass_flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
10399 PUSH_INSN3(ret, location, defineclass,
ID2SYM(singletonclass), child_iseq,
INT2FIX(sclass_flags));
10401 if (popped) PUSH_INSN(ret, location, pop);
10406 case PM_SOURCE_ENCODING_NODE: {
10410 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10411 PUSH_INSN1(ret, location, putobject, value);
10415 case PM_SOURCE_FILE_NODE: {
10420 VALUE string = pm_source_file_value(cast, scope_node);
10422 if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_FROZEN)) {
10423 PUSH_INSN1(ret, location, putobject,
string);
10425 else if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_MUTABLE)) {
10426 PUSH_INSN1(ret, location, dupstring,
string);
10429 PUSH_INSN1(ret, location, dupchilledstring,
string);
10434 case PM_SOURCE_LINE_NODE: {
10438 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10439 PUSH_INSN1(ret, location, putobject, value);
10443 case PM_SPLAT_NODE: {
10452 PUSH_INSN1(ret, location, splatarray,
Qtrue);
10456 case PM_STATEMENTS_NODE: {
10461 if (body->
size > 0) {
10462 for (
size_t index = 0; index < body->
size - 1; index++) {
10463 PM_COMPILE_POPPED(body->
nodes[index]);
10465 PM_COMPILE(body->
nodes[body->
size - 1]);
10468 PUSH_INSN(ret, location, putnil);
10472 case PM_STRING_NODE: {
10477 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10479 if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_FROZEN)) {
10480 PUSH_INSN1(ret, location, putobject, value);
10482 else if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_MUTABLE)) {
10483 PUSH_INSN1(ret, location, dupstring, value);
10486 PUSH_INSN1(ret, location, dupchilledstring, value);
10491 case PM_SUPER_NODE:
10495 pm_compile_super_node(iseq, (
const pm_super_node_t *) node, &location, ret, popped, scope_node);
10497 case PM_SYMBOL_NODE: {
10501 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10502 PUSH_INSN1(ret, location, putobject, value);
10506 case PM_TRUE_NODE: {
10510 PUSH_INSN1(ret, location, putobject,
Qtrue);
10514 case PM_UNDEF_NODE: {
10520 for (
size_t index = 0; index < names->
size; index++) {
10521 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10522 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
10524 PM_COMPILE_NOT_POPPED(names->
nodes[index]);
10525 PUSH_SEND(ret, location, id_core_undef_method,
INT2NUM(2));
10527 if (index < names->size - 1) {
10528 PUSH_INSN(ret, location, pop);
10532 if (popped) PUSH_INSN(ret, location, pop);
10535 case PM_UNLESS_NODE: {
10547 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);
10550 case PM_UNTIL_NODE: {
10557 pm_compile_loop(iseq, &location, cast->
base.
flags, PM_UNTIL_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10560 case PM_WHILE_NODE: {
10567 pm_compile_loop(iseq, &location, cast->
base.
flags, PM_WHILE_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10570 case PM_X_STRING_NODE: {
10574 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10576 PUSH_INSN(ret, location, putself);
10577 PUSH_INSN1(ret, location, putobject, value);
10578 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
10579 if (popped) PUSH_INSN(ret, location, pop);
10583 case PM_YIELD_NODE:
10589 pm_compile_yield_node(iseq, (
const pm_yield_node_t *) node, &location, ret, popped, scope_node);
10592 rb_raise(
rb_eNotImpError,
"node type %s not implemented", pm_node_type(PM_NODE_TYPE(node)));
10597#undef PM_CONTAINER_P
10601pm_iseq_pre_execution_p(
rb_iseq_t *iseq)
10603 switch (ISEQ_BODY(iseq)->
type) {
10604 case ISEQ_TYPE_TOP:
10605 case ISEQ_TYPE_EVAL:
10606 case ISEQ_TYPE_MAIN:
10625 if (pm_iseq_pre_execution_p(iseq)) {
10637 pm_compile_node(iseq, (
const pm_node_t *) node, body,
false, node);
10641 PUSH_SEQ(ret, pre);
10642 PUSH_SEQ(ret, body);
10647 pm_compile_node(iseq, (
const pm_node_t *) node, ret,
false, node);
10650 CHECK(iseq_setup_insn(iseq, ret));
10651 return iseq_setup(iseq, ret);
10658 result->
arena = pm_arena_new();
10659 result->
options = pm_options_new();
10660 pm_options_line_set(result->
options, 1);
10671 SIZED_FREE_N(result->
node.constants, pm_parser_constants_size(result->
node.parser));
10672 pm_scope_node_destroy(&result->
node);
10676 pm_arena_free(result->
arena);
10678 pm_options_free(result->
options);
10690 if (buffer == NULL) {
10695 if (rb_stderr_tty_p()) {
10696 const char *no_color = getenv(
"NO_COLOR");
10697 if (no_color == NULL || no_color[0] ==
'\0') {
10706 pm_error_level_t error_level = pm_errors_format(parser, buffer, format_type);
10709 VALUE message = rb_enc_str_new(pm_buffer_value(buffer), (
long) pm_buffer_length(buffer), message_encoding);
10710 pm_buffer_free(buffer);
10713 switch (error_level) {
10720 VALUE path = rb_enc_str_new((
const char *) pm_string_source(filepath), pm_string_length(filepath), filepath_encoding);
10744pm_intern_constants_callback(
const pm_constant_t *constant,
void *data)
10747 ctx->constants[ctx->index++] = rb_intern3((
const char *) pm_constant_start(constant), pm_constant_length(constant), ctx->encoding);
10754 const char *filepath;
10758pm_warning_emit_callback(
const pm_diagnostic_t *diagnostic,
void *data) {
10761 int line = pm_location_line_number(ctx->parser, &loc);
10764 rb_enc_compile_warning(ctx->encoding, ctx->filepath, line,
"%s", pm_diagnostic_message(diagnostic));
10767 rb_enc_compile_warn(ctx->encoding, ctx->filepath, line,
"%s", pm_diagnostic_message(diagnostic));
10785 const uint8_t *start = pm_parser_start(parser);
10786 const uint8_t *end = pm_parser_end(parser);
10787 const pm_location_t *data_loc = pm_parser_data_loc(parser);
10789 if (data_loc->
length != 0) {
10790 const uint8_t *cursor = start + data_loc->
start;
10791 while (cursor < end && *cursor !=
'\n') cursor++;
10792 if (cursor < end) cursor++;
10797 rb_source_hash_init(&state);
10798 rb_source_hash_update(&state, start, (
size_t) (end - start));
10799 return rb_source_hash_finalize(&state);
10811 int coverage_enabled = scope_node->coverage_enabled;
10813 pm_scope_node_init(node, scope_node, NULL);
10816 const char *encoding_name = pm_parser_encoding_name(parser);
10817 scope_node->encoding = rb_enc_find(encoding_name);
10818 if (!scope_node->encoding) rb_bug(
"Encoding not found %s!", encoding_name);
10820 scope_node->coverage_enabled = coverage_enabled;
10824 if (script_lines != NULL) {
10828 for (
size_t index = 0; index < line_offsets->
size; index++) {
10829 size_t offset = line_offsets->
offsets[index];
10830 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);
10831 rb_ary_push(*script_lines, rb_enc_str_new((
const char *) pm_parser_start(parser) + offset, length, scope_node->encoding));
10840 .encoding = scope_node->encoding,
10841 .filepath = (
const char *) pm_string_source(pm_parser_filepath(parser))
10843 pm_parser_warnings_each(parser, pm_warning_emit_callback, &warning_ctx);
10846 if (pm_parser_errors_size(parser) > 0) {
10847 VALUE error = pm_parse_process_error(result);
10856 scope_node->parser = parser;
10857 scope_node->
source_hash = pm_source_hash(parser);
10858 scope_node->options = result->
options;
10859 scope_node->line_offsets = pm_parser_line_offsets(parser);
10860 scope_node->start_line = pm_parser_start_line(parser);
10861 size_t constants_size = pm_parser_constants_size(parser);
10862 scope_node->constants = constants_size ?
xmalloc(constants_size *
sizeof(
ID)) : NULL;
10864 pm_intern_constants_ctx_t intern_ctx = { .constants = scope_node->constants, .encoding = scope_node->encoding, .index = 0 };
10865 pm_parser_constants_each(parser, pm_intern_constants_callback, &intern_ctx);
10878pm_options_frozen_string_literal_init(
pm_options_t *options)
10880 int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
10882 switch (frozen_string_literal) {
10883 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
10885 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
10886 pm_options_frozen_string_literal_set(options,
false);
10888 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
10889 pm_options_frozen_string_literal_set(options,
true);
10892 rb_bug(
"pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
10905 const char *start = (
const char *) pm_parser_start(parser);
10906 const char *end = (
const char *) pm_parser_end(parser);
10911 size_t last_offset = line_offsets->
offsets[line_offsets->
size - 1];
10912 bool last_push = start + last_offset != end;
10917 for (
size_t index = 0; index < line_offsets->
size - 1; index++) {
10918 size_t offset = line_offsets->
offsets[index];
10919 size_t length = line_offsets->
offsets[index + 1] - offset;
10921 rb_ary_push(lines, rb_enc_str_new(start + offset, length, scope_node->encoding));
10926 rb_ary_push(lines, rb_enc_str_new(start + last_offset, end - (start + last_offset), scope_node->encoding));
10940close_file(
VALUE args)
10943 if (arg->fd != -1) {
10946 else if (!
NIL_P(arg->io)) {
10953load_content(
VALUE args)
10960 return rb_funcall(io, rb_intern(
"read"), 0);
10971 result->
source = pm_source_mapped_new(RSTRING_PTR(filepath), O_RDONLY | O_NONBLOCK, &init_result);
10974 pm_options_frozen_string_literal_init(result->
options);
10985 .open_mode = O_RDONLY | O_NONBLOCK,
10989 if (args.fd == -1)
goto error_generic;
10994 long len = RSTRING_LEN(contents);
10995 if (
len < 0)
goto error_generic;
10997 size_t length = (size_t)
len;
10998 uint8_t *source_data =
xmalloc(length);
10999 memcpy(source_data, RSTRING_PTR(contents), length);
11000 result->
source = pm_source_owned_new(source_data, length);
11002 pm_options_frozen_string_literal_init(result->
options);
11011 err = rb_w32_map_errno(GetLastError());
11042 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11045 pm_options_version_for_current_ruby_set(result->
options);
11050 VALUE error = pm_parse_process(result, node, script_lines);
11055 ID id_script_lines = rb_intern(
"SCRIPT_LINES__");
11061 rb_hash_aset(constant_script_lines, filepath, pm_parse_file_script_lines(&result->
node, result->
parser));
11075 VALUE error = pm_load_file(result, filepath,
false);
11076 if (
NIL_P(error)) {
11077 error = pm_parse_file(result, filepath, script_lines);
11093 if (!rb_enc_asciicompat(encoding)) {
11097 pm_options_frozen_string_literal_init(result->
options);
11098 result->
source = pm_source_constant_new((
const uint8_t *) RSTRING_PTR(source), (
size_t) RSTRING_LEN(source));
11099 pm_options_encoding_set(result->
options, rb_enc_name(encoding));
11102 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11104 pm_options_version_for_current_ruby_set(result->
options);
11109 VALUE error = pm_parse_process(result, node, script_lines);
11122pm_node_find(
const pm_node_t *node,
void *data)
11126 if (context->node == NULL && node->
node_id == context->node_id) {
11127 context->node = node;
11131 return context->node == NULL;
11135pm_node_source_location(
VALUE source,
VALUE filepath,
int start_line,
11139 pm_parse_result_init(&result);
11141 pm_options_line_set(result.
options, start_line);
11142 VALUE error = pm_parse_string(&result, source, filepath, NULL);
11144 if (!
NIL_P(error)) {
11145 pm_parse_result_free(&result);
11150 .node_id = (uint32_t) node_id,
11153 pm_visit_node(result.
node.ast_node, pm_node_find, &context);
11155 bool found = context.node != NULL;
11157 *location = pm_code_location(&result.
node, context.node);
11163 pm_parse_result_free(&result);
11167VALUE rb_io_gets_limit_internal(
VALUE io,
long limit);
11177pm_parse_stdin_eof(
void *stream)
11190#define MAX_ENC_LEN 6
11198pm_parse_stdin_fgets(
char *
string,
int size,
void *stream)
11208 VALUE line = rb_io_gets_limit_internal((
VALUE) stream, size - MAX_ENC_LEN);
11213 const char *cstr = RSTRING_PTR(line);
11214 long length = RSTRING_LEN(line);
11222 if (length > (
long) (size - 1)) {
11223 length = (long) (size - 1);
11226 memcpy(
string, cstr, (
size_t) length);
11227 string[length] =
'\0';
11235void rb_reset_argf_lineno(
long n);
11245 pm_options_frozen_string_literal_init(result->
options);
11247 result->
source = pm_source_stream_new((
void *)
rb_stdin, pm_parse_stdin_fgets, pm_parse_stdin_eof);
11252 rb_reset_argf_lineno(0);
11254 return pm_parse_process(result, node, NULL);
11257#define PM_VERSION_FOR_RELEASE(major, minor) PM_VERSION_FOR_RELEASE_IMPL(major, minor)
11258#define PM_VERSION_FOR_RELEASE_IMPL(major, minor) #major "." #minor
11260void pm_options_version_for_current_ruby_set(
pm_options_t *options) {
11262 pm_options_version_set(options, version, strlen(version));
11266#define NEW_ISEQ OLD_ISEQ
11268#undef NEW_CHILD_ISEQ
11269#define NEW_CHILD_ISEQ OLD_CHILD_ISEQ
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
@ PM_WARNING_LEVEL_VERBOSE
For warnings which should be emitted if $VERBOSE == true.
pm_error_level_t
The levels of errors generated during parsing.
@ PM_ERROR_LEVEL_ARGUMENT
For errors that should raise an argument error.
@ PM_ERROR_LEVEL_LOAD
For errors that should raise a load error.
@ PM_ERROR_LEVEL_SYNTAX
For errors that should raise a syntax error.
#define RUBY_EVENT_END
Encountered an end of a class clause.
#define RUBY_EVENT_B_RETURN
Encountered a next statement.
#define RUBY_EVENT_CLASS
Encountered a new class.
#define RUBY_EVENT_LINE
Encountered a new line.
#define RUBY_EVENT_RETURN
Encountered a return statement.
#define RUBY_EVENT_B_CALL
Encountered an yield statement.
#define RUBY_EVENT_CALL
A method, written in Ruby, is called.
#define RUBY_EVENT_RESCUE
Encountered a rescue statement.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define ALLOCV
Old name of RB_ALLOCV.
#define ALLOC
Old name of RB_ALLOC.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define T_STRING
Old name of RUBY_T_STRING.
#define xfree
Old name of ruby_xfree.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define ID2SYM
Old name of RB_ID2SYM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define ULONG2NUM
Old name of RB_ULONG2NUM.
#define FIXABLE
Old name of RB_FIXABLE.
#define xmalloc
Old name of ruby_xmalloc.
#define LONG2FIX
Old name of RB_INT2FIX.
#define ZALLOC_N
Old name of RB_ZALLOC_N.
#define T_HASH
Old name of RUBY_T_HASH.
#define ALLOC_N
Old name of RB_ALLOC_N.
#define rb_exc_new3
Old name of rb_exc_new_str.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define DBL2NUM
Old name of rb_float_new.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define UINT2NUM
Old name of RB_UINT2NUM.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define ruby_debug
This variable controls whether the interpreter is in debug mode.
VALUE rb_eNotImpError
NotImplementedError exception.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
VALUE rb_eStandardError
StandardError exception.
VALUE rb_syserr_new_str(int n, VALUE arg)
Identical to rb_syserr_new(), except it takes the message in Ruby's String instead of C's.
VALUE rb_eNoMemError
NoMemoryError exception.
VALUE rb_eLoadError
LoadError exception.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eNoMatchingPatternError
NoMatchingPatternError exception.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_eNoMatchingPatternKeyError
NoMatchingPatternKeyError exception.
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Identical to rb_exc_new_cstr(), except it takes a Ruby's string instead of C's.
VALUE rb_ensure(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
An equivalent to ensure clause.
VALUE rb_eSyntaxError
SyntaxError exception.
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Make a hidden object visible again.
VALUE rb_cArray
Array class.
VALUE rb_cObject
Object class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_stdin
STDIN constant.
VALUE rb_cHash
Hash class.
VALUE rb_obj_freeze(VALUE obj)
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_enc_interned_str(const char *ptr, long len, rb_encoding *enc)
Identical to rb_enc_str_new(), except it returns a "f"string.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_ary_cat(VALUE ary, const VALUE *train, long len)
Destructively appends multiple elements at the end of the array.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_hidden_new(long capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
VALUE rb_ary_join(VALUE ary, VALUE sep)
Recursively stringises the elements of the passed array, flattens that result, then joins the sequenc...
void rb_ary_store(VALUE ary, long key, VALUE val)
Destructively stores the passed value to the passed array's passed index.
#define INTEGER_PACK_NATIVE_BYTE_ORDER
Means either INTEGER_PACK_MSBYTE_FIRST or INTEGER_PACK_LSBYTE_FIRST, depending on the host processor'...
#define INTEGER_PACK_LSWORD_FIRST
Stores/interprets the least significant word as the first word.
VALUE rb_io_fdopen(int fd, int flags, const char *path)
Creates an IO instance whose backend is the given file descriptor.
int rb_cloexec_open(const char *pathname, int flags, mode_t mode)
Opens a file that closes on exec.
VALUE rb_io_eof(VALUE io)
Queries if the passed IO is at the end of file.
VALUE rb_io_close(VALUE io)
Closes the IO.
VALUE rb_range_new(VALUE beg, VALUE end, int excl)
Creates a new Range.
VALUE rb_rational_new(VALUE num, VALUE den)
Constructs a Rational, with reduction.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_tmp_new(long len)
Allocates a "temporary" string.
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
#define rb_str_buf_new_cstr(str)
Identical to rb_str_new_cstr, except done differently.
VALUE rb_str_concat(VALUE dst, VALUE src)
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
VALUE rb_str_freeze(VALUE str)
This is the implementation of String#freeze.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_const_get_at(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
int rb_const_defined_at(VALUE space, ID name)
Identical to rb_const_defined(), except it doesn't look for parent classes.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
VALUE rb_id2sym(ID id)
Allocates an instance of rb_cSymbol that has the given id.
@ RUBY_IO_READABLE
IO::READABLE
VALUE rb_io_wait(VALUE io, VALUE events, VALUE timeout)
Blocks until the passed IO is ready for the passed events.
int len
Length of the buffer.
#define RB_OBJ_SET_SHAREABLE(obj)
Wrapper of rb_obj_set_shareable().
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
static VALUE RB_OBJ_SET_FROZEN_SHAREABLE(VALUE obj)
Freezes and marks the object as shareable.
VALUE rb_ractor_make_shareable(VALUE obj)
Destructively transforms the passed object so that multiple Ractors can share it.
#define DECIMAL_SIZE_OF(expr)
An approximation of decimal representation size.
#define RUBY_API_VERSION_MAJOR
Major version.
#define RUBY_API_VERSION_MINOR
Minor version.
#define RB_INT2NUM
Just another name of rb_int2num_inline.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
PRISM_NODISCARD PRISM_EXPORTED_FUNCTION pm_parser_t * pm_parser_new(pm_arena_t *arena, const uint8_t *source, size_t size, const pm_options_t *options) PRISM_NONNULL(1)
Allocate and initialize a parser with the given start and end pointers.
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser) PRISM_NONNULL(1)
Free both the memory held by the given parser and the parser itself.
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser) PRISM_NONNULL(1)
Initiate the parser with the given parser.
#define PM_NODE_LIST_FOREACH(list, index, node)
Loop through each node in the node list, writing each node to the given pm_node_t pointer.
The main header file for the prism parser.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define errno
Ractor-aware version of errno.
pm_source_init_result_t
Represents the result of initializing a source from a file.
@ PM_SOURCE_INIT_SUCCESS
Indicates that the source was successfully initialized.
@ PM_SOURCE_INIT_ERROR_NON_REGULAR
Indicates that the file is not a regular file (e.g.
@ PM_SOURCE_INIT_ERROR_DIRECTORY
Indicates that the file that was attempted to be opened was a directory.
#define RTEST
This is an old name of RB_TEST.
PM_NODE_ALIGNAS struct pm_node * new_name
AliasGlobalVariableNode::new_name.
PM_NODE_ALIGNAS struct pm_node * old_name
AliasGlobalVariableNode::old_name.
PM_NODE_ALIGNAS struct pm_node * old_name
AliasMethodNode::old_name.
PM_NODE_ALIGNAS struct pm_node * new_name
AliasMethodNode::new_name.
PM_NODE_ALIGNAS struct pm_node * left
AlternationPatternNode::left.
PM_NODE_ALIGNAS struct pm_node * right
AlternationPatternNode::right.
PM_NODE_ALIGNAS struct pm_node * left
AndNode::left.
PM_NODE_ALIGNAS struct pm_node * right
AndNode::right.
pm_node_t base
The embedded base node.
struct pm_node_list arguments
ArgumentsNode::arguments.
struct pm_node_list elements
ArrayNode::elements.
struct pm_node_list requireds
ArrayPatternNode::requireds.
PM_NODE_ALIGNAS struct pm_node * rest
ArrayPatternNode::rest.
PM_NODE_ALIGNAS struct pm_node * constant
ArrayPatternNode::constant.
struct pm_node_list posts
ArrayPatternNode::posts.
PM_NODE_ALIGNAS struct pm_node * value
AssocNode::value.
PM_NODE_ALIGNAS struct pm_node * key
AssocNode::key.
PM_NODE_ALIGNAS struct pm_node * value
AssocSplatNode::value.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
BeginNode::else_clause.
PM_NODE_ALIGNAS struct pm_ensure_node * ensure_clause
BeginNode::ensure_clause.
PM_NODE_ALIGNAS struct pm_statements_node * statements
BeginNode::statements.
PM_NODE_ALIGNAS struct pm_rescue_node * rescue_clause
BeginNode::rescue_clause.
PM_NODE_ALIGNAS struct pm_node * expression
BlockArgumentNode::expression.
PM_NODE_ALIGNAS struct pm_node * parameters
BlockNode::parameters.
pm_constant_id_list_t locals
BlockNode::locals.
PM_NODE_ALIGNAS struct pm_node * body
BlockNode::body.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
BreakNode::arguments.
PM_NODE_ALIGNAS struct pm_node * receiver
CallAndWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallAndWriteNode::value.
pm_constant_id_t read_name
CallAndWriteNode::read_name.
pm_constant_id_t write_name
CallAndWriteNode::write_name.
pm_location_t closing_loc
CallNode::closing_loc.
pm_constant_id_t name
CallNode::name.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
CallNode::arguments.
pm_location_t message_loc
CallNode::message_loc.
PM_NODE_ALIGNAS struct pm_node * block
CallNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
CallNode::receiver.
pm_constant_id_t read_name
CallOperatorWriteNode::read_name.
pm_constant_id_t binary_operator
CallOperatorWriteNode::binary_operator.
pm_constant_id_t write_name
CallOperatorWriteNode::write_name.
PM_NODE_ALIGNAS struct pm_node * receiver
CallOperatorWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * receiver
CallOrWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallOrWriteNode::value.
pm_constant_id_t write_name
CallOrWriteNode::write_name.
pm_constant_id_t read_name
CallOrWriteNode::read_name.
pm_constant_id_t name
CallTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * receiver
CallTargetNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CapturePatternNode::value.
PM_NODE_ALIGNAS struct pm_local_variable_target_node * target
CapturePatternNode::target.
struct pm_node_list conditions
CaseMatchNode::conditions.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * predicate
CaseMatchNode::predicate.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
CaseMatchNode::else_clause.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
CaseNode::else_clause.
struct pm_node_list conditions
CaseNode::conditions.
PM_NODE_ALIGNAS struct pm_node * predicate
CaseNode::predicate.
pm_node_t base
The embedded base node.
pm_constant_id_list_t locals
ClassNode::locals.
PM_NODE_ALIGNAS struct pm_node * superclass
ClassNode::superclass.
pm_constant_id_t name
ClassNode::name.
PM_NODE_ALIGNAS struct pm_node * constant_path
ClassNode::constant_path.
PM_NODE_ALIGNAS struct pm_node * body
ClassNode::body.
ClassVariableAndWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
ClassVariableAndWriteNode::value.
pm_constant_id_t name
ClassVariableAndWriteNode::name.
ClassVariableOperatorWriteNode.
pm_constant_id_t name
ClassVariableOperatorWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
ClassVariableOperatorWriteNode::value.
pm_constant_id_t binary_operator
ClassVariableOperatorWriteNode::binary_operator.
ClassVariableOrWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
ClassVariableOrWriteNode::value.
pm_constant_id_t name
ClassVariableOrWriteNode::name.
pm_constant_id_t name
ClassVariableReadNode::name.
pm_constant_id_t name
ClassVariableTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * value
ClassVariableWriteNode::value.
pm_constant_id_t name
ClassVariableWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
ConstantAndWriteNode::value.
pm_location_t name_loc
ConstantAndWriteNode::name_loc.
pm_constant_id_t name
ConstantAndWriteNode::name.
size_t size
The number of constant ids in the list.
size_t capacity
The number of constant ids that have been allocated in the list.
pm_constant_id_t * ids
The constant ids in the list.
ConstantOperatorWriteNode.
pm_constant_id_t name
ConstantOperatorWriteNode::name.
pm_location_t name_loc
ConstantOperatorWriteNode::name_loc.
pm_constant_id_t binary_operator
ConstantOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_node * value
ConstantOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * value
ConstantOrWriteNode::value.
pm_location_t name_loc
ConstantOrWriteNode::name_loc.
pm_constant_id_t name
ConstantOrWriteNode::name.
ConstantPathAndWriteNode.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathAndWriteNode::target.
PM_NODE_ALIGNAS struct pm_node * value
ConstantPathAndWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * parent
ConstantPathNode::parent.
pm_constant_id_t name
ConstantPathNode::name.
ConstantPathOperatorWriteNode.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathOperatorWriteNode::target.
pm_constant_id_t binary_operator
ConstantPathOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_node * value
ConstantPathOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * value
ConstantPathOrWriteNode::value.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathOrWriteNode::target.
pm_constant_id_t name
ConstantPathTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * parent
ConstantPathTargetNode::parent.
PM_NODE_ALIGNAS struct pm_node * value
ConstantPathWriteNode::value.
PM_NODE_ALIGNAS struct pm_constant_path_node * target
ConstantPathWriteNode::target.
pm_node_t base
The embedded base node.
pm_constant_id_t name
ConstantReadNode::name.
pm_constant_id_t name
ConstantTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * value
ConstantWriteNode::value.
pm_constant_id_t name
ConstantWriteNode::name.
pm_constant_id_t name
DefNode::name.
PM_NODE_ALIGNAS struct pm_parameters_node * parameters
DefNode::parameters.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * receiver
DefNode::receiver.
PM_NODE_ALIGNAS struct pm_node * body
DefNode::body.
pm_constant_id_list_t locals
DefNode::locals.
PM_NODE_ALIGNAS struct pm_node * value
DefinedNode::value.
PM_NODE_ALIGNAS struct pm_statements_node * statements
ElseNode::statements.
PM_NODE_ALIGNAS struct pm_statements_node * statements
EmbeddedStatementsNode::statements.
PM_NODE_ALIGNAS struct pm_node * variable
EmbeddedVariableNode::variable.
PM_NODE_ALIGNAS struct pm_statements_node * statements
EnsureNode::statements.
PM_NODE_ALIGNAS struct pm_splat_node * left
FindPatternNode::left.
PM_NODE_ALIGNAS struct pm_splat_node * right
FindPatternNode::right.
PM_NODE_ALIGNAS struct pm_node * constant
FindPatternNode::constant.
struct pm_node_list requireds
FindPatternNode::requireds.
PM_NODE_ALIGNAS struct pm_node * left
FlipFlopNode::left.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * right
FlipFlopNode::right.
double value
FloatNode::value.
PM_NODE_ALIGNAS struct pm_node * collection
ForNode::collection.
PM_NODE_ALIGNAS struct pm_statements_node * statements
ForNode::statements.
PM_NODE_ALIGNAS struct pm_block_node * block
ForwardingSuperNode::block.
GlobalVariableAndWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
GlobalVariableAndWriteNode::value.
pm_constant_id_t name
GlobalVariableAndWriteNode::name.
GlobalVariableOperatorWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
GlobalVariableOperatorWriteNode::value.
pm_constant_id_t name
GlobalVariableOperatorWriteNode::name.
pm_constant_id_t binary_operator
GlobalVariableOperatorWriteNode::binary_operator.
GlobalVariableOrWriteNode.
pm_constant_id_t name
GlobalVariableOrWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
GlobalVariableOrWriteNode::value.
pm_constant_id_t name
GlobalVariableReadNode::name.
GlobalVariableTargetNode.
pm_constant_id_t name
GlobalVariableTargetNode::name.
pm_constant_id_t name
GlobalVariableWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
GlobalVariableWriteNode::value.
struct pm_node_list elements
HashNode::elements.
PM_NODE_ALIGNAS struct pm_node * constant
HashPatternNode::constant.
struct pm_node_list elements
HashPatternNode::elements.
PM_NODE_ALIGNAS struct pm_node * rest
HashPatternNode::rest.
PM_NODE_ALIGNAS struct pm_node * predicate
IfNode::predicate.
PM_NODE_ALIGNAS struct pm_statements_node * statements
IfNode::statements.
PM_NODE_ALIGNAS struct pm_node * numeric
ImaginaryNode::numeric.
PM_NODE_ALIGNAS struct pm_node * value
ImplicitNode::value.
PM_NODE_ALIGNAS struct pm_node * pattern
InNode::pattern.
PM_NODE_ALIGNAS struct pm_statements_node * statements
InNode::statements.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
IndexAndWriteNode::arguments.
PM_NODE_ALIGNAS struct pm_block_argument_node * block
IndexAndWriteNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
IndexAndWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
IndexAndWriteNode::value.
A direct-indexed lookup table mapping constant IDs to local variable indices.
int capacity
Total number of slots (constants_size + PM_INDEX_LOOKUP_SPECIALS).
bool owned
Whether the values array is heap-allocated and needs explicit free.
int * values
Array of local indices, indexed by constant_id.
PM_NODE_ALIGNAS struct pm_block_argument_node * block
IndexOperatorWriteNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
IndexOperatorWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
IndexOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
IndexOperatorWriteNode::arguments.
pm_constant_id_t binary_operator
IndexOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
IndexOrWriteNode::arguments.
PM_NODE_ALIGNAS struct pm_node * value
IndexOrWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * receiver
IndexOrWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_block_argument_node * block
IndexOrWriteNode::block.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
IndexTargetNode::arguments.
PM_NODE_ALIGNAS struct pm_block_argument_node * block
IndexTargetNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
IndexTargetNode::receiver.
InstanceVariableAndWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
InstanceVariableAndWriteNode::value.
pm_constant_id_t name
InstanceVariableAndWriteNode::name.
InstanceVariableOperatorWriteNode.
pm_constant_id_t binary_operator
InstanceVariableOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_node * value
InstanceVariableOperatorWriteNode::value.
pm_constant_id_t name
InstanceVariableOperatorWriteNode::name.
InstanceVariableOrWriteNode.
pm_constant_id_t name
InstanceVariableOrWriteNode::name.
PM_NODE_ALIGNAS struct pm_node * value
InstanceVariableOrWriteNode::value.
InstanceVariableReadNode.
pm_constant_id_t name
InstanceVariableReadNode::name.
InstanceVariableTargetNode.
pm_constant_id_t name
InstanceVariableTargetNode::name.
InstanceVariableWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
InstanceVariableWriteNode::value.
pm_constant_id_t name
InstanceVariableWriteNode::name.
pm_integer_t value
IntegerNode::value.
A structure represents an arbitrary-sized integer.
size_t length
The number of allocated values.
uint32_t value
Embedded value for small integer.
uint32_t * values
List of 32-bit integers.
bool negative
Whether or not the integer is negative.
Context for interning constants via callback.
InterpolatedMatchLastLineNode.
InterpolatedRegularExpressionNode.
struct pm_node_list parts
InterpolatedStringNode::parts.
struct pm_node_list parts
InterpolatedSymbolNode::parts.
struct pm_node_list parts
InterpolatedXStringNode::parts.
struct pm_node_list elements
KeywordHashNode::elements.
KeywordRestParameterNode.
pm_location_t opening_loc
LambdaNode::opening_loc.
pm_constant_id_list_t locals
LambdaNode::locals.
PM_NODE_ALIGNAS struct pm_node * body
LambdaNode::body.
PM_NODE_ALIGNAS struct pm_node * parameters
LambdaNode::parameters.
A line and column in a string.
uint32_t column
The column in bytes.
int32_t line
The line number.
A list of offsets of the start of lines in a string.
uint32_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.
the getlocal and setlocal instructions require two parameters.
LocalVariableAndWriteNode.
pm_constant_id_t name
LocalVariableAndWriteNode::name.
uint32_t depth
LocalVariableAndWriteNode::depth.
PM_NODE_ALIGNAS struct pm_node * value
LocalVariableAndWriteNode::value.
LocalVariableOperatorWriteNode.
uint32_t depth
LocalVariableOperatorWriteNode::depth.
pm_constant_id_t binary_operator
LocalVariableOperatorWriteNode::binary_operator.
PM_NODE_ALIGNAS struct pm_node * value
LocalVariableOperatorWriteNode::value.
pm_constant_id_t name
LocalVariableOperatorWriteNode::name.
LocalVariableOrWriteNode.
PM_NODE_ALIGNAS struct pm_node * value
LocalVariableOrWriteNode::value.
uint32_t depth
LocalVariableOrWriteNode::depth.
pm_constant_id_t name
LocalVariableOrWriteNode::name.
uint32_t depth
LocalVariableReadNode::depth.
pm_constant_id_t name
LocalVariableReadNode::name.
uint32_t depth
LocalVariableTargetNode::depth.
pm_constant_id_t name
LocalVariableTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * value
LocalVariableWriteNode::value.
uint32_t depth
LocalVariableWriteNode::depth.
pm_constant_id_t name
LocalVariableWriteNode::name.
This struct represents a slice in the source code, defined by an offset and a length.
uint32_t start
The offset of the location from the start of the source.
uint32_t length
The length of the location.
PM_NODE_ALIGNAS struct pm_node * pattern
MatchPredicateNode::pattern.
PM_NODE_ALIGNAS struct pm_node * value
MatchPredicateNode::value.
PM_NODE_ALIGNAS struct pm_node * pattern
MatchRequiredNode::pattern.
PM_NODE_ALIGNAS struct pm_node * value
MatchRequiredNode::value.
PM_NODE_ALIGNAS struct pm_call_node * call
MatchWriteNode::call.
struct pm_node_list targets
MatchWriteNode::targets.
PM_NODE_ALIGNAS struct pm_node * constant_path
ModuleNode::constant_path.
PM_NODE_ALIGNAS struct pm_node * body
ModuleNode::body.
pm_constant_id_list_t locals
ModuleNode::locals.
pm_constant_id_t name
ModuleNode::name.
PM_NODE_ALIGNAS struct pm_node * rest
MultiTargetNode::rest.
struct pm_node_list lefts
MultiTargetNode::lefts.
struct pm_node_list rights
MultiTargetNode::rights.
This is a node in the multi target state linked list.
As we're compiling a multi target, we need to track additional information whenever there is a parent...
PM_NODE_ALIGNAS struct pm_node * rest
MultiWriteNode::rest.
struct pm_node_list rights
MultiWriteNode::rights.
PM_NODE_ALIGNAS struct pm_node * value
MultiWriteNode::value.
struct pm_node_list lefts
MultiWriteNode::lefts.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
NextNode::arguments.
A list of nodes in the source, most often used for lists of children.
size_t size
The number of nodes in the list.
struct pm_node ** nodes
The nodes in the list.
This compiler defines its own concept of the location of a node.
int32_t line
This is the line number of a node.
uint32_t node_id
This is a unique identifier for the node.
This is the base structure that represents a node in the syntax tree.
pm_node_type_t type
This represents the type of the node.
uint32_t node_id
The unique identifier for this node, which is deterministic based on the source.
pm_node_flags_t flags
This represents any flags on the node.
pm_location_t location
This is the location of the node in the source.
NumberedReferenceReadNode.
uint32_t number
NumberedReferenceReadNode::number.
OptionalKeywordParameterNode.
pm_constant_id_t name
OptionalKeywordParameterNode::name.
PM_NODE_ALIGNAS struct pm_node * value
OptionalKeywordParameterNode::value.
pm_constant_id_t name
OptionalParameterNode::name.
PM_NODE_ALIGNAS struct pm_node * value
OptionalParameterNode::value.
PM_NODE_ALIGNAS struct pm_node * right
OrNode::right.
PM_NODE_ALIGNAS struct pm_node * left
OrNode::left.
PM_NODE_ALIGNAS struct pm_node * block
ParametersNode::block.
struct pm_node_list requireds
ParametersNode::requireds.
struct pm_node_list optionals
ParametersNode::optionals.
struct pm_node_list posts
ParametersNode::posts.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * rest
ParametersNode::rest.
struct pm_node_list keywords
ParametersNode::keywords.
PM_NODE_ALIGNAS struct pm_node * keyword_rest
ParametersNode::keyword_rest.
PM_NODE_ALIGNAS struct pm_node * body
ParenthesesNode::body.
bool parsed
Whether or not this parse result has performed its parsing yet.
pm_parser_t * parser
The parser that will do the actual parsing.
pm_source_t * source
The source backing the parse (file, string, or stream).
pm_scope_node_t node
The resulting scope node that will hold the generated AST.
pm_options_t * options
The options that will be passed to the parser.
pm_arena_t * arena
The arena allocator for AST-lifetime memory.
PM_NODE_ALIGNAS struct pm_node * variable
PinnedVariableNode::variable.
PM_NODE_ALIGNAS struct pm_statements_node * statements
PostExecutionNode::statements.
PM_NODE_ALIGNAS struct pm_statements_node * statements
PreExecutionNode::statements.
PM_NODE_ALIGNAS struct pm_statements_node * statements
ProgramNode::statements.
PM_NODE_ALIGNAS struct pm_node * right
RangeNode::right.
PM_NODE_ALIGNAS struct pm_node * left
RangeNode::left.
pm_integer_t denominator
RationalNode::denominator.
pm_integer_t numerator
RationalNode::numerator.
RequiredKeywordParameterNode.
pm_constant_id_t name
RequiredParameterNode::name.
PM_NODE_ALIGNAS struct pm_node * expression
RescueModifierNode::expression.
PM_NODE_ALIGNAS struct pm_node * rescue_expression
RescueModifierNode::rescue_expression.
PM_NODE_ALIGNAS struct pm_statements_node * statements
RescueNode::statements.
PM_NODE_ALIGNAS struct pm_rescue_node * subsequent
RescueNode::subsequent.
PM_NODE_ALIGNAS struct pm_node * reference
RescueNode::reference.
struct pm_node_list exceptions
RescueNode::exceptions.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
ReturnNode::arguments.
uint64_t source_hash
The source hash of the parsed source, propagated to every iseq.
rb_encoding * filepath_encoding
This is the encoding of the actual filepath object that will be used when a FILE node is compiled or ...
pm_index_lookup_table_t index_lookup_table
A flat lookup table mapping constant IDs (or special IDs) to local variable indices.
size_t last_line
Cached line hint for line offset list lookups.
struct iseq_link_anchor * pre_execution_anchor
This will only be set on the top-level scope node.
VALUE * script_lines
This is a pointer to the list of script lines for the ISEQs that will be associated with this scope n...
PM_NODE_ALIGNAS struct pm_node * write
ShareableConstantNode::write.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_node * body
SingletonClassNode::body.
pm_constant_id_list_t locals
SingletonClassNode::locals.
PM_NODE_ALIGNAS struct pm_node * expression
SingletonClassNode::expression.
pm_string_t filepath
SourceFileNode::filepath.
PM_NODE_ALIGNAS struct pm_node * expression
SplatNode::expression.
struct pm_node_list body
StatementsNode::body.
pm_node_t base
The embedded base node.
pm_string_t unescaped
StringNode::unescaped.
A generic string type that can have various ownership semantics.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
SuperNode::arguments.
PM_NODE_ALIGNAS struct pm_node * block
SuperNode::block.
pm_string_t unescaped
SymbolNode::unescaped.
pm_node_t base
The embedded base node.
struct pm_node_list names
UndefNode::names.
PM_NODE_ALIGNAS struct pm_node * predicate
UnlessNode::predicate.
PM_NODE_ALIGNAS struct pm_statements_node * statements
UnlessNode::statements.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
UnlessNode::else_clause.
pm_node_t base
The embedded base node.
Context for emitting warnings via callback.
pm_node_t base
The embedded base node.
pm_string_t unescaped
XStringNode::unescaped.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
YieldNode::arguments.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.