23#define PUSH_ADJUST(seq, location, label) \
24 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), (int) (location).line))
26#define PUSH_ADJUST_RESTORE(seq, label) \
27 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), -1))
29#define PUSH_INSN(seq, location, insn) \
30 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 0))
32#define PUSH_INSN1(seq, location, insn, op1) \
33 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 1, (VALUE)(op1)))
35#define PUSH_INSN2(seq, location, insn, op1, op2) \
36 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 2, (VALUE)(op1), (VALUE)(op2)))
38#define PUSH_INSN3(seq, location, insn, op1, op2, op3) \
39 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 3, (VALUE)(op1), (VALUE)(op2), (VALUE)(op3)))
41#define PUSH_INSNL(seq, location, insn, label) \
42 (PUSH_INSN1(seq, location, insn, label), LABEL_REF(label))
44#define PUSH_LABEL(seq, label) \
45 ADD_ELEM((seq), (LINK_ELEMENT *) (label))
47#define PUSH_SEND_R(seq, location, id, argc, block, flag, keywords) \
48 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_send(iseq, (int) (location).line, (int) (location).node_id, (id), (VALUE)(argc), (block), (VALUE)(flag), (keywords)))
50#define PUSH_SEND(seq, location, id, argc) \
51 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(0), NULL)
53#define PUSH_SEND_WITH_FLAG(seq, location, id, argc, flag) \
54 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)(flag), NULL)
56#define PUSH_SEND_WITH_BLOCK(seq, location, id, argc, block) \
57 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(0), NULL)
59#define PUSH_CALL(seq, location, id, argc) \
60 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
62#define PUSH_CALL_WITH_BLOCK(seq, location, id, argc, block) \
63 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
65#define PUSH_TRACE(seq, event) \
66 ADD_ELEM((seq), (LINK_ELEMENT *) new_trace_body(iseq, (event), 0))
68#define PUSH_CATCH_ENTRY(type, ls, le, iseqv, lc) \
69 ADD_CATCH_ENTRY((type), (ls), (le), (iseqv), (lc))
71#define PUSH_SEQ(seq1, seq2) \
72 APPEND_LIST((seq1), (seq2))
74#define PUSH_SYNTHETIC_PUTNIL(seq, iseq) \
76 int lineno = ISEQ_COMPILE_DATA(iseq)->last_line; \
77 if (lineno == 0) lineno = FIX2INT(rb_iseq_first_lineno(iseq)); \
78 ADD_SYNTHETIC_INSN(seq, lineno, -1, putnil); \
87pm_iseq_add_getlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
89 if (iseq_local_block_param_p(iseq, idx, level)) {
90 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
93 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
95 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qfalse);
99pm_iseq_add_setlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
101 if (iseq_local_block_param_p(iseq, idx, level)) {
102 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
105 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
107 update_lvar_state(iseq, level, idx);
108 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qtrue);
111#define PUSH_GETLOCAL(seq, location, idx, level) \
112 pm_iseq_add_getlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
114#define PUSH_SETLOCAL(seq, location, idx, level) \
115 pm_iseq_add_setlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
121#define OLD_ISEQ NEW_ISEQ
124#define NEW_ISEQ(node, name, type, line_no) \
125 pm_new_child_iseq(iseq, (node), rb_fstring(name), 0, (type), (line_no))
127#define OLD_CHILD_ISEQ NEW_CHILD_ISEQ
130#define NEW_CHILD_ISEQ(node, name, type, line_no) \
131 pm_new_child_iseq(iseq, (node), rb_fstring(name), iseq, (type), (line_no))
133#define PM_COMPILE(node) \
134 pm_compile_node(iseq, (node), ret, popped, scope_node)
136#define PM_COMPILE_INTO_ANCHOR(_ret, node) \
137 pm_compile_node(iseq, (node), _ret, popped, scope_node)
139#define PM_COMPILE_POPPED(node) \
140 pm_compile_node(iseq, (node), ret, true, scope_node)
142#define PM_COMPILE_NOT_POPPED(node) \
143 pm_compile_node(iseq, (node), ret, false, scope_node)
146#define PM_INDEX_LOOKUP_TABLE_INIT { .values = NULL, .capacity = 0, .owned = false }
151 int capacity = constants_size + PM_INDEX_LOOKUP_SPECIALS;
152 table->
values = compile_data_alloc2_type(iseq,
int, capacity);
153 memset(table->
values, -1, capacity *
sizeof(
int));
155 table->
owned =
false;
165pm_line_offset_list_line_column_cached(
const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line,
size_t *last_line)
167 size_t hint = *last_line;
168 size_t size = list->
size;
169 const uint32_t *offsets = list->
offsets;
174 if (offsets[hint] <= cursor) {
175 if (hint + 1 >= size || offsets[hint + 1] > cursor) {
178 .line = ((int32_t) hint) + start_line,
179 .column = cursor - offsets[hint]
184 size_t limit = hint + 9;
185 if (limit > size) limit = size;
186 for (
size_t idx = hint + 1; idx < limit; idx++) {
187 if (offsets[idx] > cursor) {
188 *last_line = idx - 1;
190 .line = ((int32_t) (idx - 1)) + start_line,
191 .column = cursor - offsets[idx - 1]
194 if (offsets[idx] == cursor) {
202 size_t limit = hint > 8 ? hint - 8 : 0;
203 for (
size_t idx = hint; idx > limit; idx--) {
204 if (offsets[idx - 1] <= cursor) {
205 *last_line = idx - 1;
207 .line = ((int32_t) (idx - 1)) + start_line,
208 .column = cursor - offsets[idx - 1]
215 pm_line_column_t result = pm_line_offset_list_line_column(list, cursor, start_line);
216 *last_line = (size_t) (result.
line - start_line);
225pm_line_offset_list_line_cached(
const pm_line_offset_list_t *list, uint32_t cursor, int32_t start_line,
size_t *last_line)
227 return pm_line_offset_list_line_column_cached(list, cursor, start_line, last_line).
line;
230#define PM_NODE_START_LOCATION(node) \
231 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start, scope_node->start_line, &scope_node->last_line), .node_id = ((const pm_node_t *) (node))->node_id })
233#define PM_NODE_END_LOCATION(node) \
234 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start + ((const pm_node_t *) (node))->location.length, scope_node->start_line, &scope_node->last_line), .node_id = ((const pm_node_t *) (node))->node_id })
236#define PM_LOCATION_START_LOCATION(location, id) \
237 ((pm_node_location_t) { .line = pm_line_offset_list_line_cached(scope_node->line_offsets, (location)->start, scope_node->start_line, &scope_node->last_line), .node_id = id })
239#define PM_NODE_START_LINE_COLUMN(node) \
240 pm_line_offset_list_line_column_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start, scope_node->start_line, &scope_node->last_line)
242#define PM_NODE_END_LINE_COLUMN(node) \
243 pm_line_offset_list_line_column_cached(scope_node->line_offsets, ((const pm_node_t *) (node))->location.start + ((const pm_node_t *) (node))->location.length, scope_node->start_line, &scope_node->last_line)
245#define PM_LOCATION_START_LINE_COLUMN(location) \
246 pm_line_offset_list_line_column_cached(scope_node->line_offsets, (location)->start, scope_node->start_line, &scope_node->last_line)
250 return (
int) pm_line_offset_list_line_column(pm_parser_line_offsets(parser), location->
start, pm_parser_start_line(parser)).
line;
260 return (
int) pm_line_offset_list_line_cached(scope_node->line_offsets, node->
location.
start, scope_node->start_line, &scope_node->
last_line);
265 return (
int) pm_line_offset_list_line_cached(scope_node->line_offsets, location->
start, scope_node->start_line, &scope_node->
last_line);
276 if (integer->
values == NULL) {
284 result = rb_integer_unpack(
294 result = rb_int_uminus(result);
298 RB_OBJ_SET_SHAREABLE(result);
310 return parse_integer_value(&node->
value);
321 RB_OBJ_SET_SHAREABLE(val);
350 VALUE imaginary_part;
351 switch (PM_NODE_TYPE(node->
numeric)) {
352 case PM_FLOAT_NODE: {
356 case PM_INTEGER_NODE: {
360 case PM_RATIONAL_NODE: {
365 rb_bug(
"Unexpected numeric type on imaginary number %s\n", pm_node_type(PM_NODE_TYPE(node->
numeric)));
368 return RB_OBJ_SET_SHAREABLE(rb_complex_raw(
INT2FIX(0), imaginary_part));
374 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), scope_node->encoding);
387 if (node->
flags & PM_ENCODING_FLAGS_FORCED_BINARY_ENCODING) {
388 encoding = rb_ascii8bit_encoding();
390 else if (node->
flags & PM_ENCODING_FLAGS_FORCED_UTF8_ENCODING) {
391 encoding = rb_utf8_encoding();
397 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
405 if (node->
flags & PM_STRING_FLAGS_FORCED_BINARY_ENCODING) {
406 encoding = rb_ascii8bit_encoding();
408 else if (node->
flags & PM_STRING_FLAGS_FORCED_UTF8_ENCODING) {
409 encoding = rb_utf8_encoding();
412 encoding = scope_node->encoding;
415 VALUE value = rb_enc_literal_str((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
418 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
419 int line_number = pm_node_line_number_cached(node, scope_node);
430 if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_UTF8_ENCODING) {
431 encoding = rb_utf8_encoding();
433 else if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_BINARY_ENCODING) {
434 encoding = rb_ascii8bit_encoding();
436 else if (symbol->
base.
flags & PM_SYMBOL_FLAGS_FORCED_US_ASCII_ENCODING) {
437 encoding = rb_usascii_encoding();
440 encoding = scope_node->encoding;
443 return rb_intern3((
const char *) pm_string_source(&symbol->
unescaped), pm_string_length(&symbol->
unescaped), encoding);
447pm_optimizable_range_item_p(
const pm_node_t *node)
449 return (!node || PM_NODE_TYPE_P(node, PM_INTEGER_NODE) || PM_NODE_TYPE_P(node, PM_NIL_NODE));
454parse_regexp_error(
rb_iseq_t *iseq, int32_t line_number,
const char *fmt, ...)
458 VALUE error = rb_syntax_error_append(
Qnil, rb_iseq_path(iseq), line_number, -1, NULL,
"%" PRIsVALUE, args);
470 if (explicit_regexp_encoding != NULL) {
471 encoding = explicit_regexp_encoding;
473 else if (node->
flags & PM_STRING_FLAGS_FORCED_BINARY_ENCODING) {
474 encoding = rb_ascii8bit_encoding();
476 else if (node->
flags & PM_STRING_FLAGS_FORCED_UTF8_ENCODING) {
477 encoding = rb_utf8_encoding();
480 encoding = implicit_regexp_encoding;
483 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), encoding);
484 VALUE error = rb_reg_check_preprocess(
string);
486 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number_cached(node, scope_node),
"%" PRIsVALUE,
rb_obj_as_string(error));
495 for (
size_t index = 0; index < nodes->
size; index++) {
499 switch (PM_NODE_TYPE(part)) {
501 if (implicit_regexp_encoding != NULL) {
503 string = parse_regexp_string_part(iseq, scope_node, part, &((
const pm_string_node_t *) part)->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
506 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
507 VALUE error = rb_reg_check_preprocess(
string);
508 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number_cached(part, scope_node),
"%" PRIsVALUE,
rb_obj_as_string(error));
512 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
515 case PM_INTERPOLATED_STRING_NODE:
516 string = pm_static_literal_concat(iseq, &((
const pm_interpolated_string_node_t *) part)->parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
518 case PM_EMBEDDED_STATEMENTS_NODE: {
520 string = pm_static_literal_concat(iseq, &cast->
statements->
body, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
524 RUBY_ASSERT(
false &&
"unexpected node type in pm_static_literal_concat");
528 if (current !=
Qnil) {
536 return top ? rb_fstring(current) : current;
539#define RE_OPTION_ENCODING_SHIFT 8
540#define RE_OPTION_ENCODING(encoding) (((encoding) & 0xFF) << RE_OPTION_ENCODING_SHIFT)
541#define ARG_ENCODING_NONE 32
542#define ARG_ENCODING_FIXED 16
543#define ENC_ASCII8BIT 1
545#define ENC_Windows_31J 3
560 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) {
561 flags |= ARG_ENCODING_NONE;
564 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EUC_JP)) {
565 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_EUC_JP));
568 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J)) {
569 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_Windows_31J));
572 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_UTF_8)) {
573 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_UTF8));
576 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE)) {
577 flags |= ONIG_OPTION_IGNORECASE;
580 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE)) {
581 flags |= ONIG_OPTION_MULTILINE;
584 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EXTENDED)) {
585 flags |= ONIG_OPTION_EXTEND;
591#undef RE_OPTION_ENCODING_SHIFT
592#undef RE_OPTION_ENCODING
593#undef ARG_ENCODING_FIXED
594#undef ARG_ENCODING_NONE
597#undef ENC_Windows_31J
603 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_FORCED_BINARY_ENCODING) || PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT)) {
604 return rb_ascii8bit_encoding();
606 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_UTF_8)) {
607 return rb_utf8_encoding();
609 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_EUC_JP)) {
610 return rb_enc_get_from_index(ENCINDEX_EUC_JP);
612 else if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J)) {
613 return rb_enc_get_from_index(ENCINDEX_Windows_31J);
623 VALUE errinfo = rb_errinfo();
625 int32_t line_number = pm_node_line_number_cached(node, scope_node);
626 VALUE regexp = rb_reg_compile(
string, parse_regexp_flags(node), (
const char *) pm_string_source(pm_parser_filepath(scope_node->parser)), line_number);
629 VALUE message = rb_attr_get(rb_errinfo(), idMesg);
630 rb_set_errinfo(errinfo);
632 parse_regexp_error(iseq, line_number,
"%" PRIsVALUE, message);
642 rb_encoding *regexp_encoding = parse_regexp_encoding(scope_node, node);
643 if (regexp_encoding == NULL) regexp_encoding = scope_node->encoding;
645 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), regexp_encoding);
646 RB_OBJ_SET_SHAREABLE(
string);
647 return parse_regexp(iseq, scope_node, node,
string);
653 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
654 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
656 VALUE string = pm_static_literal_concat(iseq, parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
657 return parse_regexp(iseq, scope_node, node,
string);
666 size_t parts_size = parts->
size;
667 bool interpolated =
false;
669 if (parts_size > 0) {
673 for (
size_t index = 0; index < parts_size; index++) {
676 if (PM_NODE_TYPE_P(part, PM_STRING_NODE)) {
680 if (implicit_regexp_encoding == NULL) {
681 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
684 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
687 if (
RTEST(current_string)) {
688 current_string =
rb_str_concat(current_string, string_value);
691 current_string = string_value;
692 if (index != 0) current_location = PM_NODE_END_LOCATION(part);
699 PM_NODE_TYPE_P(part, PM_EMBEDDED_STATEMENTS_NODE) &&
707 if (implicit_regexp_encoding == NULL) {
708 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
711 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
714 if (
RTEST(current_string)) {
715 current_string =
rb_str_concat(current_string, string_value);
718 current_string = string_value;
719 current_location = PM_NODE_START_LOCATION(part);
723 if (!
RTEST(current_string)) {
726 if (implicit_regexp_encoding != NULL) {
727 if (explicit_regexp_encoding != NULL) {
728 encoding = explicit_regexp_encoding;
730 else if (pm_parser_encoding_us_ascii(scope_node->parser)) {
731 encoding = rb_ascii8bit_encoding();
734 encoding = implicit_regexp_encoding;
738 encoding = scope_node->encoding;
741 if (parts_size == 1) {
742 current_string = rb_enc_str_new(NULL, 0, encoding);
746 if (
RTEST(current_string)) {
747 VALUE operand = rb_fstring(current_string);
748 PUSH_INSN1(ret, current_location, putobject, operand);
752 PM_COMPILE_NOT_POPPED(part);
755 PUSH_INSN(ret, current_location, dup);
758 const struct rb_callinfo *callinfo = new_callinfo(iseq, idTo_s, 0, VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE, NULL, FALSE);
759 PUSH_INSN1(ret, current_location, objtostring, callinfo);
762 PUSH_INSN(ret, current_location, anytostring);
764 current_string =
Qnil;
770 if (
RTEST(current_string)) {
771 current_string = rb_fstring(current_string);
773 if (stack_size == 0) {
775 PUSH_INSN1(ret, current_location, putobject, current_string);
776 }
else if (mutable_result || interpolated) {
777 PUSH_INSN1(ret, current_location, putstring, current_string);
779 PUSH_INSN1(ret, current_location, putchilledstring, current_string);
782 PUSH_INSN1(ret, current_location, putobject, current_string);
785 current_string =
Qnil;
790 PUSH_INSN(ret, *node_location, putnil);
799 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
800 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
802 int length = pm_interpolated_node_compile(iseq, parts, node_location, ret, popped, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false,
false);
803 PUSH_INSN2(ret, *node_location, toregexp,
INT2FIX(parse_regexp_flags(node) & 0xFF),
INT2FIX(length));
810 size_t length = pm_string_length(filepath);
814 return rb_enc_interned_str((
const char *) pm_string_source(filepath), length, filepath_encoding);
817 return rb_fstring_lit(
"<compiled>");
826pm_static_literal_string(
rb_iseq_t *iseq,
VALUE string,
int line_number)
828 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
829 VALUE str = rb_str_with_debug_created_info(
string, rb_iseq_path(iseq), line_number);
830 RB_OBJ_SET_SHAREABLE(str);
834 return rb_fstring(
string);
848 RUBY_ASSERT(PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL));
850 switch (PM_NODE_TYPE(node)) {
851 case PM_ARRAY_NODE: {
856 for (
size_t index = 0; index < elements->
size; index++) {
857 rb_ary_push(value, pm_static_literal_value(iseq, elements->
nodes[index], scope_node));
860 RB_OBJ_SET_FROZEN_SHAREABLE(value);
872 for (
size_t index = 0; index < elements->
size; index++) {
875 VALUE pair[2] = { pm_static_literal_value(iseq, cast->key, scope_node), pm_static_literal_value(iseq, cast->value, scope_node) };
883 RB_OBJ_SET_FROZEN_SHAREABLE(value);
886 case PM_IMAGINARY_NODE:
888 case PM_INTEGER_NODE:
890 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
892 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
894 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
896 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
898 case PM_INTERPOLATED_STRING_NODE: {
900 int line_number = pm_node_line_number_cached(node, scope_node);
901 return pm_static_literal_string(iseq,
string, line_number);
903 case PM_INTERPOLATED_SYMBOL_NODE: {
905 VALUE string = pm_static_literal_concat(iseq, &cast->
parts, scope_node, NULL, NULL,
true);
907 return ID2SYM(rb_intern_str(
string));
909 case PM_MATCH_LAST_LINE_NODE: {
911 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
915 case PM_RATIONAL_NODE:
917 case PM_REGULAR_EXPRESSION_NODE: {
919 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
921 case PM_SOURCE_ENCODING_NODE:
922 return rb_enc_from_encoding(scope_node->encoding);
923 case PM_SOURCE_FILE_NODE: {
925 return pm_source_file_value(cast, scope_node);
927 case PM_SOURCE_LINE_NODE:
928 return INT2FIX(pm_node_line_number_cached(node, scope_node));
929 case PM_STRING_NODE: {
931 return parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
938 rb_bug(
"Don't have a literal value for node type %s", pm_node_type(PM_NODE_TYPE(node)));
953 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
954 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
963#define PM_BRANCH_COVERAGE_P(iseq) (ISEQ_COVERAGE(iseq) && ISEQ_BRANCH_COVERAGE(iseq))
977 if (!then_label) then_label = label;
978 else if (!else_label) else_label = label;
980 pm_compile_branch_condition(iseq, seq, cond, then_label, else_label, scope_node);
982 if (LIST_INSN_SIZE_ONE(seq)) {
983 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(seq));
984 if (insn->insn_id == BIN(jump) && (
LABEL *)(insn->operands[0]) == label)
return;
988 PUSH_LABEL(seq, label);
1000 if (PM_NODE_TYPE_P(node, PM_INTEGER_NODE)) {
1001 PM_COMPILE_NOT_POPPED(node);
1004 PUSH_INSN1(ret, location, getglobal, operand);
1006 PUSH_SEND(ret, location, idEq,
INT2FIX(1));
1007 if (popped) PUSH_INSN(ret, location, pop);
1020 int again = !(flip_flop_node->
base.
flags & PM_RANGE_FLAGS_EXCLUDE_END);
1022 rb_num_t count = ISEQ_FLIP_CNT_INCREMENT(ISEQ_BODY(iseq)->local_iseq) + VM_SVAR_FLIPFLOP_START;
1025 PUSH_INSN2(ret, location, getspecial, key,
INT2FIX(0));
1026 PUSH_INSNL(ret, location, branchif, lend);
1028 if (flip_flop_node->
left) {
1029 pm_compile_flip_flop_bound(iseq, flip_flop_node->
left, ret, popped, scope_node);
1032 PUSH_INSN(ret, location, putnil);
1035 PUSH_INSNL(ret, location, branchunless, else_label);
1036 PUSH_INSN1(ret, location, putobject,
Qtrue);
1037 PUSH_INSN1(ret, location, setspecial, key);
1039 PUSH_INSNL(ret, location, jump, then_label);
1042 PUSH_LABEL(ret, lend);
1043 if (flip_flop_node->
right) {
1044 pm_compile_flip_flop_bound(iseq, flip_flop_node->
right, ret, popped, scope_node);
1047 PUSH_INSN(ret, location, putnil);
1050 PUSH_INSNL(ret, location, branchunless, then_label);
1051 PUSH_INSN1(ret, location, putobject,
Qfalse);
1052 PUSH_INSN1(ret, location, setspecial, key);
1053 PUSH_INSNL(ret, location, jump, then_label);
1064 switch (PM_NODE_TYPE(cond)) {
1067 pm_compile_logical(iseq, ret, cast->
left, NULL, else_label, scope_node);
1074 pm_compile_logical(iseq, ret, cast->
left, then_label, NULL, scope_node);
1081 PUSH_INSNL(ret, location, jump, else_label);
1084 case PM_IMAGINARY_NODE:
1085 case PM_INTEGER_NODE:
1086 case PM_LAMBDA_NODE:
1087 case PM_RATIONAL_NODE:
1088 case PM_REGULAR_EXPRESSION_NODE:
1089 case PM_STRING_NODE:
1090 case PM_SYMBOL_NODE:
1092 PUSH_INSNL(ret, location, jump, then_label);
1094 case PM_FLIP_FLOP_NODE:
1095 pm_compile_flip_flop((
const pm_flip_flop_node_t *) cond, else_label, then_label, iseq, location.
line, ret,
false, scope_node);
1097 case PM_DEFINED_NODE: {
1099 pm_compile_defined_expr(iseq, cast->
value, &location, ret,
false, scope_node,
true);
1103 DECL_ANCHOR(cond_seq);
1104 pm_compile_node(iseq, cond, cond_seq,
false, scope_node);
1106 if (LIST_INSN_SIZE_ONE(cond_seq)) {
1107 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(cond_seq));
1109 if (insn->insn_id == BIN(putobject)) {
1110 if (
RTEST(insn->operands[0])) {
1111 PUSH_INSNL(ret, location, jump, then_label);
1116 PUSH_INSNL(ret, location, jump, else_label);
1122 PUSH_SEQ(ret, cond_seq);
1127 PUSH_INSNL(ret, location, branchunless, else_label);
1128 PUSH_INSNL(ret, location, jump, then_label);
1138 LABEL *then_label = NEW_LABEL(location.
line);
1139 LABEL *else_label = NEW_LABEL(location.
line);
1140 LABEL *end_label = NULL;
1142 DECL_ANCHOR(cond_seq);
1143 pm_compile_branch_condition(iseq, cond_seq, predicate, then_label, else_label, scope_node);
1144 PUSH_SEQ(ret, cond_seq);
1149 if (then_label->refcnt && else_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1150 conditional_location = pm_code_location(scope_node, node);
1151 branches = decl_branch_base(iseq, PTR2NUM(node), &conditional_location,
type == PM_IF_NODE ?
"if" :
"unless");
1154 if (then_label->refcnt) {
1155 PUSH_LABEL(ret, then_label);
1157 DECL_ANCHOR(then_seq);
1159 if (statements != NULL) {
1160 pm_compile_node(iseq, (
const pm_node_t *) statements, then_seq, popped, scope_node);
1163 PUSH_SYNTHETIC_PUTNIL(then_seq, iseq);
1166 if (else_label->refcnt) {
1168 if (PM_BRANCH_COVERAGE_P(iseq)) {
1171 if (statements != NULL) {
1172 branch_location = pm_code_location(scope_node, (
const pm_node_t *) statements);
1173 }
else if (
type == PM_IF_NODE) {
1176 .beg_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column },
1177 .end_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column }
1180 branch_location = conditional_location;
1183 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
type == PM_IF_NODE ?
"then" :
"else", branches);
1186 end_label = NEW_LABEL(location.
line);
1187 PUSH_INSNL(then_seq, location, jump, end_label);
1188 if (!popped) PUSH_INSN(then_seq, location, pop);
1191 PUSH_SEQ(ret, then_seq);
1194 if (else_label->refcnt) {
1195 PUSH_LABEL(ret, else_label);
1197 DECL_ANCHOR(else_seq);
1199 if (subsequent != NULL) {
1200 pm_compile_node(iseq, subsequent, else_seq, popped, scope_node);
1203 PUSH_SYNTHETIC_PUTNIL(else_seq, iseq);
1207 if (then_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1210 if (subsequent == NULL) {
1211 branch_location = conditional_location;
1212 }
else if (PM_NODE_TYPE_P(subsequent, PM_ELSE_NODE)) {
1216 branch_location = pm_code_location(scope_node, (
const pm_node_t *) subsequent);
1219 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 1,
type == PM_IF_NODE ?
"else" :
"then", branches);
1222 PUSH_SEQ(ret, else_seq);
1226 PUSH_LABEL(ret, end_label);
1240 LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
1241 LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
1242 LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
1244 LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(location.
line);
1245 LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(location.
line);
1246 LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(location.
line);
1247 LABEL *end_label = NEW_LABEL(location.
line);
1248 LABEL *adjust_label = NEW_LABEL(location.
line);
1250 LABEL *next_catch_label = NEW_LABEL(location.
line);
1251 LABEL *tmp_label = NULL;
1257 push_ensure_entry(iseq, &enl, NULL, NULL);
1260 if (flags & PM_LOOP_FLAGS_BEGIN_MODIFIER) {
1261 tmp_label = NEW_LABEL(location.
line);
1262 PUSH_INSNL(ret, location, jump, tmp_label);
1266 PUSH_INSNL(ret, location, jump, next_label);
1269 PUSH_LABEL(ret, adjust_label);
1270 PUSH_INSN(ret, location, putnil);
1271 PUSH_LABEL(ret, next_catch_label);
1272 PUSH_INSN(ret, location, pop);
1273 PUSH_INSNL(ret, location, jump, next_label);
1274 if (tmp_label) PUSH_LABEL(ret, tmp_label);
1276 PUSH_LABEL(ret, redo_label);
1279 if (PM_BRANCH_COVERAGE_P(iseq)) {
1281 VALUE branches = decl_branch_base(iseq, PTR2NUM(node), &loop_location,
type == PM_WHILE_NODE ?
"while" :
"until");
1283 rb_code_location_t branch_location = statements != NULL ? pm_code_location(scope_node, (
const pm_node_t *) statements) : loop_location;
1284 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
"body", branches);
1287 if (statements != NULL) PM_COMPILE_POPPED((
const pm_node_t *) statements);
1288 PUSH_LABEL(ret, next_label);
1290 if (
type == PM_WHILE_NODE) {
1291 pm_compile_branch_condition(iseq, ret, predicate, redo_label, end_label, scope_node);
1293 else if (
type == PM_UNTIL_NODE) {
1294 pm_compile_branch_condition(iseq, ret, predicate, end_label, redo_label, scope_node);
1297 PUSH_LABEL(ret, end_label);
1298 PUSH_ADJUST_RESTORE(ret, adjust_label);
1299 PUSH_INSN(ret, location, putnil);
1301 PUSH_LABEL(ret, break_label);
1302 if (popped) PUSH_INSN(ret, location, pop);
1304 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, NULL, break_label);
1305 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label, NULL, next_catch_label);
1306 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, NULL, ISEQ_COMPILE_DATA(iseq)->redo_label);
1308 ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
1309 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
1310 ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
1311 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->prev;
1326 for (level = 0; level < start_depth; level++) {
1327 scope_node = scope_node->previous;
1330 while (!pm_index_lookup_table_lookup(&scope_node->
index_lookup_table, constant_id, &local_index))
1334 if (scope_node->previous) {
1335 scope_node = scope_node->previous;
1340 rb_bug(
"Local with constant_id %u does not exist", (
unsigned int) constant_id);
1344 lindex.level = level;
1345 lindex.index = scope_node->local_table_for_iseq_size - (int) local_index;
1358 RUBY_ASSERT(constant_id >= 1 && constant_id <= pm_parser_constants_size(scope_node->parser));
1359 return scope_node->constants[constant_id - 1];
1365 debugs(
"[new_child_iseq]> ---------------------------------------\n");
1366 int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
1367 rb_iseq_t *ret_iseq = pm_iseq_build(node, name,
1368 rb_iseq_path(iseq), rb_iseq_realpath(iseq),
1370 isolated_depth ? isolated_depth + 1 : 0,
1371 type, ISEQ_COMPILE_DATA(iseq)->option);
1372 debugs(
"[new_child_iseq]< ---------------------------------------\n");
1379 switch (PM_NODE_TYPE(node)) {
1380 case PM_CONSTANT_READ_NODE:
1382 case PM_CONSTANT_PATH_NODE:
1385 if (!parent)
return TRUE;
1386 return pm_cpath_const_p(parent);
1396 if (PM_NODE_TYPE_P(node, PM_CONSTANT_PATH_NODE)) {
1402 int flags = VM_DEFINECLASS_FLAG_SCOPED;
1403 if (!pm_cpath_const_p(parent)) {
1404 flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
1410 PUSH_INSN1(ret, *node_location, putobject,
rb_cObject);
1411 return VM_DEFINECLASS_FLAG_SCOPED;
1416 PUSH_INSN1(ret, *node_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
1426pm_compile_call_and_or_write_node(
rb_iseq_t *iseq,
bool and_node,
const pm_node_t *receiver,
const pm_node_t *value,
pm_constant_id_t write_name,
pm_constant_id_t read_name,
bool safe_nav,
const pm_node_location_t *node_location,
LINK_ANCHOR *
const ret,
bool popped,
pm_scope_node_t *scope_node)
1430 LABEL *lcfin = NEW_LABEL(location.
line);
1431 LABEL *lskip = NULL;
1433 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
1434 ID id_read_name = pm_constant_id_lookup(scope_node, read_name);
1436 PM_COMPILE_NOT_POPPED(receiver);
1438 lskip = NEW_LABEL(location.
line);
1439 PUSH_INSN(ret, location, dup);
1440 PUSH_INSNL(ret, location, branchnil, lskip);
1443 PUSH_INSN(ret, location, dup);
1444 PUSH_SEND_WITH_FLAG(ret, location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
1445 if (!popped) PUSH_INSN(ret, location, dup);
1448 PUSH_INSNL(ret, location, branchunless, lcfin);
1451 PUSH_INSNL(ret, location, branchif, lcfin);
1454 if (!popped) PUSH_INSN(ret, location, pop);
1455 PM_COMPILE_NOT_POPPED(value);
1458 PUSH_INSN(ret, location, swap);
1459 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
1462 ID id_write_name = pm_constant_id_lookup(scope_node, write_name);
1463 PUSH_SEND_WITH_FLAG(ret, location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
1464 PUSH_INSNL(ret, location, jump, lfin);
1466 PUSH_LABEL(ret, lcfin);
1467 if (!popped) PUSH_INSN(ret, location, swap);
1469 PUSH_LABEL(ret, lfin);
1471 if (lskip && popped) PUSH_LABEL(ret, lskip);
1472 PUSH_INSN(ret, location, pop);
1473 if (lskip && !popped) PUSH_LABEL(ret, lskip);
1492 const int max_stack_length = 0x100;
1493 const unsigned int min_tmp_hash_length = 0x800;
1495 int stack_length = 0;
1496 bool first_chunk =
true;
1502 bool static_literal =
false;
1504 DECL_ANCHOR(anchor);
1507#define FLUSH_CHUNK \
1508 if (stack_length) { \
1509 if (first_chunk) { \
1510 PUSH_SEQ(ret, anchor); \
1511 PUSH_INSN1(ret, location, newhash, INT2FIX(stack_length)); \
1512 first_chunk = false; \
1515 PUSH_INSN1(ret, location, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); \
1516 PUSH_INSN(ret, location, swap); \
1517 PUSH_SEQ(ret, anchor); \
1518 PUSH_SEND(ret, location, id_core_hash_merge_ptr, INT2FIX(stack_length + 1)); \
1520 INIT_ANCHOR(anchor); \
1524 for (
size_t index = 0; index < elements->
size; index++) {
1527 switch (PM_NODE_TYPE(element)) {
1528 case PM_ASSOC_NODE: {
1531 (shareability == 0) &&
1532 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && (
1533 (!static_literal && ((index + min_tmp_hash_length) < elements->
size)) ||
1534 (first_chunk && stack_length == 0)
1539 while (index + count < elements->size && PM_NODE_FLAG_P(elements->
nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++;
1541 if ((first_chunk && stack_length == 0) || count >= min_tmp_hash_length) {
1547 for (
size_t tmp_end = index + count; index < tmp_end; index++) {
1551 pm_static_literal_value(iseq, assoc->key, scope_node),
1552 pm_static_literal_value(iseq, assoc->value, scope_node)
1562 RB_OBJ_SET_FROZEN_SHAREABLE(hash);
1567 PUSH_INSN1(ret, location, duphash, hash);
1568 first_chunk =
false;
1571 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1572 PUSH_INSN(ret, location, swap);
1573 PUSH_INSN1(ret, location, putobject, hash);
1574 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1580 static_literal =
true;
1584 static_literal =
false;
1589 if (shareability == 0) {
1590 pm_compile_node(iseq, element, anchor,
false, scope_node);
1594 pm_compile_shareable_constant_value(iseq, assoc->
key, shareability, path, ret, scope_node,
false);
1595 pm_compile_shareable_constant_value(iseq, assoc->
value, shareability, path, ret, scope_node,
false);
1598 if ((stack_length += 2) >= max_stack_length) FLUSH_CHUNK;
1601 case PM_ASSOC_SPLAT_NODE: {
1605 bool empty_hash = assoc_splat->
value != NULL && (
1606 (PM_NODE_TYPE_P(assoc_splat->
value, PM_HASH_NODE) && ((
const pm_hash_node_t *) assoc_splat->
value)->elements.size == 0) ||
1607 PM_NODE_TYPE_P(assoc_splat->
value, PM_NIL_NODE)
1610 bool first_element = first_chunk && stack_length == 0;
1611 bool last_element = index == elements->
size - 1;
1612 bool only_element = first_element && last_element;
1615 if (only_element && argument) {
1622 PUSH_INSN(ret, location, putnil);
1624 else if (first_element) {
1627 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1634 if (only_element && argument) {
1640 if (shareability == 0) {
1641 PM_COMPILE_NOT_POPPED(element);
1644 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1652 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1654 if (first_element) {
1655 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1658 PUSH_INSN(ret, location, swap);
1661 if (shareability == 0) {
1662 PM_COMPILE_NOT_POPPED(element);
1665 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1668 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1672 first_chunk =
false;
1673 static_literal =
false;
1677 RUBY_ASSERT(
"Invalid node type for hash" &&
false);
1686#define SPLATARRAY_FALSE 0
1687#define SPLATARRAY_TRUE 1
1688#define DUP_SINGLE_KW_SPLAT 2
1697 bool has_splat =
false;
1698 bool has_keyword_splat =
false;
1700 if (arguments_node == NULL) {
1701 if (*flags & VM_CALL_FCALL) {
1702 *flags |= VM_CALL_VCALL;
1707 has_keyword_splat = PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT);
1711 int post_splat_counter = 0;
1715 switch (PM_NODE_TYPE(argument)) {
1717 case PM_KEYWORD_HASH_NODE: {
1721 if (has_keyword_splat || has_splat) {
1722 *flags |= VM_CALL_KW_SPLAT;
1723 has_keyword_splat =
true;
1725 if (elements->
size > 1 || !(elements->
size == 1 && PM_NODE_TYPE_P(elements->
nodes[0], PM_ASSOC_SPLAT_NODE))) {
1729 *flags |= VM_CALL_KW_SPLAT_MUT;
1730 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1732 else if (*dup_rest & DUP_SINGLE_KW_SPLAT) {
1733 *flags |= VM_CALL_KW_SPLAT_MUT;
1734 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1735 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1736 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1737 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1740 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1746 if (PM_NODE_FLAG_P(keyword_arg, PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS)) {
1751 VALUE stored_indices = rb_hash_new();
1755 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1760 VALUE keyword = pm_static_literal_value(iseq, assoc->key, scope_node);
1761 VALUE stored_index = rb_hash_aref(stored_indices, keyword);
1766 if (!
NIL_P(stored_index)) {
1774 rb_hash_aset(stored_indices, keyword,
ULONG2NUM(element_index));
1780 *flags |= VM_CALL_KWARG;
1782 VALUE *keywords = (*kw_arg)->keywords;
1783 (*kw_arg)->references = 0;
1784 (*kw_arg)->keyword_len = (int) size;
1786 size_t keyword_index = 0;
1787 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1792 keywords[keyword_index++] = pm_static_literal_value(iseq, assoc->key, scope_node);
1796 PM_COMPILE(assoc->value);
1805 *flags |= VM_CALL_KW_SPLAT;
1807 size_t size = elements->
size;
1812 *flags |= VM_CALL_KW_SPLAT_MUT;
1815 for (
size_t element_index = 0; element_index < size; element_index++) {
1817 PM_COMPILE_NOT_POPPED(assoc->key);
1818 PM_COMPILE_NOT_POPPED(assoc->value);
1821 PUSH_INSN1(ret, location, newhash,
INT2FIX(size * 2));
1826 case PM_SPLAT_NODE: {
1827 *flags |= VM_CALL_ARGS_SPLAT;
1831 PM_COMPILE_NOT_POPPED(splat_node->
expression);
1834 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1835 PUSH_GETLOCAL(ret, location, index.index, index.level);
1838 bool first_splat = !has_splat;
1846 if (index + 1 < arguments->
size || has_regular_blockarg) {
1847 PUSH_INSN1(ret, location, splatarray, (*dup_rest & SPLATARRAY_TRUE) ?
Qtrue :
Qfalse);
1848 if (*dup_rest & SPLATARRAY_TRUE) *dup_rest &= ~SPLATARRAY_TRUE;
1856 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1866 PUSH_INSN(ret, location, concattoarray);
1870 post_splat_counter = 0;
1874 case PM_FORWARDING_ARGUMENTS_NODE: {
1875 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
1877 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
1878 *flags |= VM_CALL_FORWARDING;
1880 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
1881 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1893 *flags |= VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_BLOCKARG | VM_CALL_KW_SPLAT;
1900 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1901 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1905 PUSH_INSN(ret, location, concattoarray);
1907 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1911 pm_local_index_t pow_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1912 PUSH_GETLOCAL(ret, location, pow_local.index, pow_local.level);
1915 pm_local_index_t and_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
1916 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(and_local.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(and_local.level));
1921 post_splat_counter++;
1922 PM_COMPILE_NOT_POPPED(argument);
1946 if (index == arguments->
size - 1) {
1948 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1953 switch (PM_NODE_TYPE(next_arg)) {
1955 case PM_KEYWORD_HASH_NODE: {
1956 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1957 PUSH_INSN(ret, location, concatarray);
1960 case PM_SPLAT_NODE: {
1961 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1962 PUSH_INSN(ret, location, concatarray);
1965 case PM_FORWARDING_ARGUMENTS_NODE: {
1966 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1982 if (has_splat) orig_argc++;
1983 if (has_keyword_splat) orig_argc++;
1992pm_setup_args_dup_rest_p(
const pm_node_t *node)
1994 switch (PM_NODE_TYPE(node)) {
1995 case PM_BACK_REFERENCE_READ_NODE:
1996 case PM_CLASS_VARIABLE_READ_NODE:
1997 case PM_CONSTANT_READ_NODE:
2000 case PM_GLOBAL_VARIABLE_READ_NODE:
2001 case PM_IMAGINARY_NODE:
2002 case PM_INSTANCE_VARIABLE_READ_NODE:
2003 case PM_INTEGER_NODE:
2004 case PM_LAMBDA_NODE:
2005 case PM_LOCAL_VARIABLE_READ_NODE:
2007 case PM_NUMBERED_REFERENCE_READ_NODE:
2008 case PM_RATIONAL_NODE:
2009 case PM_REGULAR_EXPRESSION_NODE:
2011 case PM_STRING_NODE:
2012 case PM_SYMBOL_NODE:
2015 case PM_CONSTANT_PATH_NODE: {
2017 if (cast->
parent != NULL) {
2018 return pm_setup_args_dup_rest_p(cast->
parent);
2022 case PM_IMPLICIT_NODE:
2024 case PM_ARRAY_NODE: {
2026 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2027 if (pm_setup_args_dup_rest_p(cast->
elements.
nodes[index])) {
2044 int dup_rest = SPLATARRAY_TRUE;
2047 size_t arguments_size;
2052 arguments_node != NULL &&
2053 (arguments = &arguments_node->
arguments, arguments_size = arguments->
size) >= 2 &&
2054 PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_SPLAT) &&
2055 !PM_NODE_FLAG_P(arguments_node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_MULTIPLE_SPLATS) &&
2056 PM_NODE_TYPE_P(arguments->
nodes[arguments_size - 1], PM_KEYWORD_HASH_NODE)
2061 dup_rest = SPLATARRAY_FALSE;
2066 for (
size_t index = 0; dup_rest == SPLATARRAY_FALSE && index < elements->
size; index++) {
2069 switch (PM_NODE_TYPE(element)) {
2070 case PM_ASSOC_NODE: {
2072 if (pm_setup_args_dup_rest_p(assoc->
key) || pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2075 case PM_ASSOC_SPLAT_NODE: {
2077 if (assoc->
value != NULL && pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
2086 int initial_dup_rest = dup_rest;
2089 if (block && PM_NODE_TYPE_P(block, PM_BLOCK_ARGUMENT_NODE)) {
2093 bool regular_block_arg =
true;
2096 if (block_expr && pm_setup_args_dup_rest_p(block_expr)) {
2097 dup_rest = SPLATARRAY_TRUE | DUP_SINGLE_KW_SPLAT;
2098 initial_dup_rest = dup_rest;
2101 DECL_ANCHOR(block_arg);
2102 pm_compile_node(iseq, block, block_arg,
false, scope_node);
2104 *flags |= VM_CALL_ARGS_BLOCKARG;
2106 if (LIST_INSN_SIZE_ONE(block_arg)) {
2108 if (IS_INSN(elem)) {
2110 if (iobj->insn_id == BIN(getblockparam)) {
2111 iobj->insn_id = BIN(getblockparamproxy);
2118 regular_block_arg =
false;
2122 argc = pm_setup_args_core(arguments_node, block, flags, regular_block_arg, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2123 PUSH_SEQ(ret, block_arg);
2126 argc = pm_setup_args_core(arguments_node, block, flags,
false, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
2133 if (*flags & VM_CALL_ARGS_SPLAT && dup_rest != initial_dup_rest) {
2134 *flags |= VM_CALL_ARGS_SPLAT_MUT;
2154 if (!popped) PUSH_INSN(ret, location, putnil);
2156 PM_COMPILE_NOT_POPPED(node->
receiver);
2158 int boff = (node->
block == NULL ? 0 : 1);
2159 int flag = PM_NODE_TYPE_P(node->
receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2161 int argc = pm_setup_args(node->
arguments, (
const pm_node_t *) node->
block, &flag, &keywords, iseq, ret, scope_node, node_location);
2163 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2165 PUSH_INSN(ret, location, splatkw);
2168 PUSH_INSN(ret, location, dup);
2169 PUSH_INSN(ret, location, splatkw);
2170 PUSH_INSN(ret, location, pop);
2174 int dup_argn = argc + 1 + boff;
2175 int keyword_len = 0;
2178 keyword_len = keywords->keyword_len;
2179 dup_argn += keyword_len;
2182 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2183 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2184 PM_COMPILE_NOT_POPPED(node->
value);
2187 PUSH_SEND(ret, location, id_operator,
INT2FIX(1));
2190 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2192 if (flag & VM_CALL_ARGS_SPLAT) {
2193 if (flag & VM_CALL_KW_SPLAT) {
2194 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2196 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2197 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2198 flag |= VM_CALL_ARGS_SPLAT_MUT;
2201 PUSH_INSN(ret, location, swap);
2202 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2203 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2204 PUSH_INSN(ret, location, pop);
2208 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2209 PUSH_INSN(ret, location, swap);
2210 PUSH_INSN(ret, location, pop);
2212 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2213 PUSH_INSN(ret, location, swap);
2214 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2215 PUSH_INSN(ret, location, swap);
2216 flag |= VM_CALL_ARGS_SPLAT_MUT;
2218 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2220 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2221 PUSH_INSN(ret, location, pop);
2222 PUSH_INSN(ret, location, pop);
2226 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2228 else if (flag & VM_CALL_KW_SPLAT) {
2230 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2231 PUSH_INSN(ret, location, swap);
2232 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2233 PUSH_INSN(ret, location, pop);
2235 PUSH_INSN(ret, location, swap);
2236 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2238 else if (keyword_len) {
2239 PUSH_INSN(ret, location, dup);
2240 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 2));
2241 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2242 PUSH_INSN(ret, location, pop);
2243 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2247 PUSH_INSN(ret, location, swap);
2249 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2252 PUSH_INSN(ret, location, pop);
2271 if (!popped) PUSH_INSN(ret, location, putnil);
2272 PM_COMPILE_NOT_POPPED(receiver);
2274 int boff = (block == NULL ? 0 : 1);
2275 int flag = PM_NODE_TYPE_P(receiver, PM_SELF_NODE) ? VM_CALL_FCALL : 0;
2277 int argc = pm_setup_args(arguments, (
const pm_node_t *) block, &flag, &keywords, iseq, ret, scope_node, node_location);
2279 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2281 PUSH_INSN(ret, location, splatkw);
2284 PUSH_INSN(ret, location, dup);
2285 PUSH_INSN(ret, location, splatkw);
2286 PUSH_INSN(ret, location, pop);
2290 int dup_argn = argc + 1 + boff;
2291 int keyword_len = 0;
2294 keyword_len = keywords->keyword_len;
2295 dup_argn += keyword_len;
2298 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2299 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2301 LABEL *label = NEW_LABEL(location.
line);
2304 PUSH_INSN(ret, location, dup);
2305 if (PM_NODE_TYPE_P(node, PM_INDEX_AND_WRITE_NODE)) {
2306 PUSH_INSNL(ret, location, branchunless, label);
2309 PUSH_INSNL(ret, location, branchif, label);
2312 PUSH_INSN(ret, location, pop);
2313 PM_COMPILE_NOT_POPPED(value);
2316 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2319 if (flag & VM_CALL_ARGS_SPLAT) {
2320 if (flag & VM_CALL_KW_SPLAT) {
2321 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2322 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2323 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2324 flag |= VM_CALL_ARGS_SPLAT_MUT;
2327 PUSH_INSN(ret, location, swap);
2328 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2329 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2330 PUSH_INSN(ret, location, pop);
2334 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2335 PUSH_INSN(ret, location, swap);
2336 PUSH_INSN(ret, location, pop);
2338 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2339 PUSH_INSN(ret, location, swap);
2340 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2341 PUSH_INSN(ret, location, swap);
2342 flag |= VM_CALL_ARGS_SPLAT_MUT;
2344 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2346 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2347 PUSH_INSN(ret, location, pop);
2348 PUSH_INSN(ret, location, pop);
2352 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2354 else if (flag & VM_CALL_KW_SPLAT) {
2356 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2357 PUSH_INSN(ret, location, swap);
2358 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2359 PUSH_INSN(ret, location, pop);
2362 PUSH_INSN(ret, location, swap);
2363 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2365 else if (keyword_len) {
2366 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2367 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 0));
2368 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2372 PUSH_INSN(ret, location, swap);
2374 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2377 PUSH_INSN(ret, location, pop);
2378 PUSH_INSNL(ret, location, jump, lfin);
2379 PUSH_LABEL(ret, label);
2381 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2383 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(dup_argn + 1));
2384 PUSH_LABEL(ret, lfin);
2393#define PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE 0
2394#define PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING 1
2395#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P 2
2396#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE 3
2397#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY 4
2412 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2414 PUSH_INSN(ret, location, dup);
2415 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2417 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2418 PUSH_INSN1(ret, location, putobject, message);
2419 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2420 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2421 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2423 PUSH_INSN1(ret, location, putobject,
Qfalse);
2424 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2426 PUSH_INSN(ret, location, pop);
2427 PUSH_INSN(ret, location, pop);
2428 PUSH_LABEL(ret, match_succeeded_label);
2442 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2444 PUSH_INSN(ret, location, dup);
2445 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2447 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2448 PUSH_INSN1(ret, location, putobject, message);
2449 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2450 PUSH_INSN(ret, location, dup);
2451 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2452 PUSH_INSN1(ret, location, putobject, length);
2453 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(4));
2454 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2456 PUSH_INSN1(ret, location, putobject,
Qfalse);
2457 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2459 PUSH_INSN(ret, location, pop);
2460 PUSH_INSN(ret, location, pop);
2461 PUSH_LABEL(ret, match_succeeded_label);
2475 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2477 PUSH_INSN(ret, location, dup);
2478 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2479 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2481 VALUE operand = rb_fstring_lit(
"%p === %p does not return true");
2482 PUSH_INSN1(ret, location, putobject, operand);
2484 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2485 PUSH_INSN1(ret, location, topn,
INT2FIX(5));
2486 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2487 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2488 PUSH_INSN1(ret, location, putobject,
Qfalse);
2489 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2490 PUSH_INSN(ret, location, pop);
2491 PUSH_INSN(ret, location, pop);
2493 PUSH_LABEL(ret, match_succeeded_label);
2494 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2495 PUSH_INSN(ret, location, pop);
2496 PUSH_INSN(ret, location, pop);
2510 LABEL *matched_label = NEW_LABEL(pm_node_line_number_cached(node, scope_node));
2511 CHECK(pm_compile_pattern(iseq, scope_node, node, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
2512 PUSH_LABEL(ret, matched_label);
2522pm_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)
2526 if (use_deconstructed_cache) {
2527 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2528 PUSH_INSNL(ret, location, branchnil, deconstruct_label);
2530 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2531 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2533 PUSH_INSN(ret, location, pop);
2534 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE - 1));
2535 PUSH_INSNL(ret, location, jump, deconstructed_label);
2538 PUSH_INSNL(ret, location, jump, deconstruct_label);
2541 PUSH_LABEL(ret, deconstruct_label);
2542 PUSH_INSN(ret, location, dup);
2545 PUSH_INSN1(ret, location, putobject, operand);
2546 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2548 if (use_deconstructed_cache) {
2549 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE + 1));
2552 if (in_single_pattern) {
2553 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct"), base_index + 1));
2556 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2557 PUSH_SEND(ret, location, rb_intern(
"deconstruct"),
INT2FIX(0));
2559 if (use_deconstructed_cache) {
2560 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2563 PUSH_INSN(ret, location, dup);
2565 PUSH_INSNL(ret, location, branchunless, type_error_label);
2566 PUSH_LABEL(ret, deconstructed_label);
2580 PUSH_INSN(ret, location, dup);
2581 PM_COMPILE_NOT_POPPED(node);
2583 if (in_single_pattern) {
2584 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
2586 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
2587 if (in_single_pattern) {
2588 CHECK(pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 3));
2590 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2602 LABEL *key_error_label = NEW_LABEL(location.
line);
2603 LABEL *cleanup_label = NEW_LABEL(location.
line);
2606 kw_arg->references = 0;
2607 kw_arg->keyword_len = 2;
2608 kw_arg->keywords[0] =
ID2SYM(rb_intern(
"matchee"));
2609 kw_arg->keywords[1] =
ID2SYM(rb_intern(
"key"));
2611 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2612 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2613 PUSH_INSNL(ret, location, branchif, key_error_label);
2616 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2619 VALUE operand = rb_fstring_lit(
"%p: %s");
2620 PUSH_INSN1(ret, location, putobject, operand);
2623 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2624 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2625 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2626 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2627 PUSH_INSNL(ret, location, jump, cleanup_label);
2629 PUSH_LABEL(ret, key_error_label);
2631 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2634 VALUE operand = rb_fstring_lit(
"%p: %s");
2635 PUSH_INSN1(ret, location, putobject, operand);
2638 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2639 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2640 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2641 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2642 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2643 PUSH_SEND_R(ret, location, rb_intern(
"new"),
INT2FIX(1), NULL,
INT2FIX(VM_CALL_KWARG), kw_arg);
2644 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(1));
2645 PUSH_LABEL(ret, cleanup_label);
2647 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(7));
2648 if (!popped) PUSH_INSN(ret, location, putnil);
2649 PUSH_INSNL(ret, location, jump, done_label);
2650 PUSH_INSN1(ret, location, dupn,
INT2FIX(5));
2651 if (popped) PUSH_INSN(ret, location, putnil);
2662 switch (PM_NODE_TYPE(node)) {
2663 case PM_ARRAY_PATTERN_NODE: {
2675 const size_t posts_size = cast->
posts.
size;
2676 const size_t minimum_size = requireds_size + posts_size;
2678 bool rest_named =
false;
2679 bool use_rest_size =
false;
2681 if (cast->
rest != NULL) {
2682 rest_named = (PM_NODE_TYPE_P(cast->
rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) cast->
rest)->expression != NULL);
2683 use_rest_size = (rest_named || (!rest_named && posts_size > 0));
2686 LABEL *match_failed_label = NEW_LABEL(location.
line);
2687 LABEL *type_error_label = NEW_LABEL(location.
line);
2688 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2689 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2691 if (use_rest_size) {
2692 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2693 PUSH_INSN(ret, location, swap);
2698 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2701 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));
2703 PUSH_INSN(ret, location, dup);
2704 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2705 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2706 PUSH_SEND(ret, location, cast->
rest == NULL ? idEq : idGE,
INT2FIX(1));
2707 if (in_single_pattern) {
2708 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+)");
2709 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, message,
INT2FIX(minimum_size), base_index + 1));
2711 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2713 for (
size_t index = 0; index < requireds_size; index++) {
2715 PUSH_INSN(ret, location, dup);
2716 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2717 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2718 CHECK(pm_compile_pattern_match(iseq, scope_node, required, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2721 if (cast->
rest != NULL) {
2723 PUSH_INSN(ret, location, dup);
2724 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size));
2725 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2726 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2727 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2728 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2729 PUSH_INSN1(ret, location, setn,
INT2FIX(4));
2730 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2731 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));
2733 else if (posts_size > 0) {
2734 PUSH_INSN(ret, location, dup);
2735 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2736 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2737 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2738 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2739 PUSH_INSN(ret, location, pop);
2743 for (
size_t index = 0; index < posts_size; index++) {
2745 PUSH_INSN(ret, location, dup);
2747 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size + index));
2748 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2749 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2750 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2751 CHECK(pm_compile_pattern_match(iseq, scope_node, post, ret, match_failed_label, in_single_pattern,
false, base_index + 1));
2754 PUSH_INSN(ret, location, pop);
2755 if (use_rest_size) {
2756 PUSH_INSN(ret, location, pop);
2759 PUSH_INSNL(ret, location, jump, matched_label);
2760 PUSH_INSN(ret, location, putnil);
2761 if (use_rest_size) {
2762 PUSH_INSN(ret, location, putnil);
2765 PUSH_LABEL(ret, type_error_label);
2766 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2770 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2771 PUSH_INSN1(ret, location, putobject, operand);
2774 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2775 PUSH_INSN(ret, location, pop);
2777 PUSH_LABEL(ret, match_failed_label);
2778 PUSH_INSN(ret, location, pop);
2779 if (use_rest_size) {
2780 PUSH_INSN(ret, location, pop);
2783 PUSH_INSNL(ret, location, jump, unmatched_label);
2786 case PM_FIND_PATTERN_NODE: {
2798 LABEL *match_failed_label = NEW_LABEL(location.
line);
2799 LABEL *type_error_label = NEW_LABEL(location.
line);
2800 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2801 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2804 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2807 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));
2809 PUSH_INSN(ret, location, dup);
2810 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2811 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2812 PUSH_SEND(ret, location, idGE,
INT2FIX(1));
2813 if (in_single_pattern) {
2814 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));
2816 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2819 LABEL *while_begin_label = NEW_LABEL(location.
line);
2820 LABEL *next_loop_label = NEW_LABEL(location.
line);
2821 LABEL *find_succeeded_label = NEW_LABEL(location.
line);
2822 LABEL *find_failed_label = NEW_LABEL(location.
line);
2824 PUSH_INSN(ret, location, dup);
2825 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2827 PUSH_INSN(ret, location, dup);
2828 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2829 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2830 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2831 PUSH_LABEL(ret, while_begin_label);
2833 PUSH_INSN(ret, location, dup);
2834 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2835 PUSH_SEND(ret, location, idLE,
INT2FIX(1));
2836 PUSH_INSNL(ret, location, branchunless, find_failed_label);
2838 for (
size_t index = 0; index < size; index++) {
2839 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2840 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2843 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2844 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2847 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2848 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
requireds.
nodes[index], ret, next_loop_label, in_single_pattern,
false, base_index + 4));
2854 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2855 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2856 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2857 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2858 CHECK(pm_compile_pattern_match(iseq, scope_node, left->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4));
2864 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2865 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2866 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2867 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2868 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2869 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2870 pm_compile_pattern_match(iseq, scope_node, right->
expression, ret, find_failed_label, in_single_pattern,
false, base_index + 4);
2873 PUSH_INSNL(ret, location, jump, find_succeeded_label);
2875 PUSH_LABEL(ret, next_loop_label);
2876 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
2877 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2878 PUSH_INSNL(ret, location, jump, while_begin_label);
2880 PUSH_LABEL(ret, find_failed_label);
2881 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2882 if (in_single_pattern) {
2883 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2886 VALUE operand = rb_fstring_lit(
"%p does not match to find pattern");
2887 PUSH_INSN1(ret, location, putobject, operand);
2890 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2891 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2892 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2894 PUSH_INSN1(ret, location, putobject,
Qfalse);
2895 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2897 PUSH_INSN(ret, location, pop);
2898 PUSH_INSN(ret, location, pop);
2900 PUSH_INSNL(ret, location, jump, match_failed_label);
2901 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2903 PUSH_LABEL(ret, find_succeeded_label);
2904 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2907 PUSH_INSN(ret, location, pop);
2908 PUSH_INSNL(ret, location, jump, matched_label);
2909 PUSH_INSN(ret, location, putnil);
2911 PUSH_LABEL(ret, type_error_label);
2912 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2916 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2917 PUSH_INSN1(ret, location, putobject, operand);
2920 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2921 PUSH_INSN(ret, location, pop);
2923 PUSH_LABEL(ret, match_failed_label);
2924 PUSH_INSN(ret, location, pop);
2925 PUSH_INSNL(ret, location, jump, unmatched_label);
2929 case PM_HASH_PATTERN_NODE: {
2944 LABEL *match_failed_label = NEW_LABEL(location.
line);
2945 LABEL *type_error_label = NEW_LABEL(location.
line);
2948 if (has_keys && !has_rest) {
2951 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2953 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
2964 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2967 PUSH_INSN(ret, location, dup);
2970 VALUE operand =
ID2SYM(rb_intern(
"deconstruct_keys"));
2971 PUSH_INSN1(ret, location, putobject, operand);
2974 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2975 if (in_single_pattern) {
2976 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct_keys"), base_index + 1));
2978 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2981 PUSH_INSN(ret, location, putnil);
2985 RB_OBJ_SET_FROZEN_SHAREABLE(keys);
2986 PUSH_INSN1(ret, location, duparray, keys);
2989 PUSH_SEND(ret, location, rb_intern(
"deconstruct_keys"),
INT2FIX(1));
2991 PUSH_INSN(ret, location, dup);
2993 PUSH_INSNL(ret, location, branchunless, type_error_label);
2996 PUSH_SEND(ret, location, rb_intern(
"dup"),
INT2FIX(0));
3000 DECL_ANCHOR(match_values);
3002 for (
size_t index = 0; index < cast->
elements.
size; index++) {
3004 RUBY_ASSERT(PM_NODE_TYPE_P(element, PM_ASSOC_NODE));
3011 PUSH_INSN(ret, location, dup);
3012 PUSH_INSN1(ret, location, putobject, symbol);
3013 PUSH_SEND(ret, location, rb_intern(
"key?"),
INT2FIX(1));
3015 if (in_single_pattern) {
3016 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3018 PUSH_INSN(ret, location, dup);
3019 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3023 RB_OBJ_SET_SHAREABLE(operand);
3024 PUSH_INSN1(ret, location, putobject, operand);
3027 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 2));
3028 PUSH_INSN1(ret, location, putobject,
Qtrue);
3029 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 3));
3030 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
3031 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
3032 PUSH_INSN1(ret, location, putobject, symbol);
3033 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
3035 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(4));
3036 PUSH_LABEL(ret, match_succeeded_label);
3039 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3040 PUSH_INSN(match_values, location, dup);
3041 PUSH_INSN1(match_values, location, putobject, symbol);
3042 PUSH_SEND(match_values, location, has_rest ? rb_intern(
"delete") : idAREF,
INT2FIX(1));
3045 if (PM_NODE_TYPE_P(value, PM_IMPLICIT_NODE)) {
3049 CHECK(pm_compile_pattern_match(iseq, scope_node, value, match_values, match_failed_label, in_single_pattern,
false, base_index + 1));
3052 PUSH_SEQ(ret, match_values);
3055 PUSH_INSN(ret, location, dup);
3056 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3057 if (in_single_pattern) {
3058 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p is not empty"), base_index + 1));
3060 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3064 switch (PM_NODE_TYPE(cast->
rest)) {
3065 case PM_NO_KEYWORDS_PARAMETER_NODE: {
3066 PUSH_INSN(ret, location, dup);
3067 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
3068 if (in_single_pattern) {
3069 pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"rest of %p is not empty"), base_index + 1);
3071 PUSH_INSNL(ret, location, branchunless, match_failed_label);
3074 case PM_ASSOC_SPLAT_NODE: {
3076 PUSH_INSN(ret, location, dup);
3077 pm_compile_pattern_match(iseq, scope_node, splat->value, ret, match_failed_label, in_single_pattern,
false, base_index + 1);
3081 rb_bug(
"unreachable");
3086 PUSH_INSN(ret, location, pop);
3087 PUSH_INSNL(ret, location, jump, matched_label);
3088 PUSH_INSN(ret, location, putnil);
3090 PUSH_LABEL(ret, type_error_label);
3091 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
3095 VALUE operand = rb_fstring_lit(
"deconstruct_keys must return Hash");
3096 PUSH_INSN1(ret, location, putobject, operand);
3099 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
3100 PUSH_INSN(ret, location, pop);
3102 PUSH_LABEL(ret, match_failed_label);
3103 PUSH_INSN(ret, location, pop);
3104 PUSH_INSNL(ret, location, jump, unmatched_label);
3107 case PM_CAPTURE_PATTERN_NODE: {
3119 LABEL *match_failed_label = NEW_LABEL(location.
line);
3121 PUSH_INSN(ret, location, dup);
3122 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
value, ret, match_failed_label, in_single_pattern, use_deconstructed_cache, base_index + 1));
3123 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));
3124 PUSH_INSN(ret, location, putnil);
3126 PUSH_LABEL(ret, match_failed_label);
3127 PUSH_INSN(ret, location, pop);
3128 PUSH_INSNL(ret, location, jump, unmatched_label);
3132 case PM_LOCAL_VARIABLE_TARGET_NODE: {
3139 PUSH_SETLOCAL(ret, location, index.index, index.level);
3140 PUSH_INSNL(ret, location, jump, matched_label);
3143 case PM_ALTERNATION_PATTERN_NODE: {
3148 LABEL *matched_left_label = NEW_LABEL(location.
line);
3149 LABEL *unmatched_left_label = NEW_LABEL(location.
line);
3153 PUSH_INSN(ret, location, dup);
3154 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));
3159 PUSH_LABEL(ret, matched_left_label);
3160 PUSH_INSN(ret, location, pop);
3161 PUSH_INSNL(ret, location, jump, matched_label);
3162 PUSH_INSN(ret, location, putnil);
3166 PUSH_LABEL(ret, unmatched_left_label);
3167 CHECK(pm_compile_pattern(iseq, scope_node, cast->
right, ret, matched_label, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3170 case PM_PARENTHESES_NODE:
3175 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);
3176 case PM_PINNED_EXPRESSION_NODE:
3184 case PM_CLASS_VARIABLE_READ_NODE:
3185 case PM_CONSTANT_PATH_NODE:
3186 case PM_CONSTANT_READ_NODE:
3189 case PM_GLOBAL_VARIABLE_READ_NODE:
3190 case PM_IMAGINARY_NODE:
3191 case PM_INSTANCE_VARIABLE_READ_NODE:
3192 case PM_IT_LOCAL_VARIABLE_READ_NODE:
3193 case PM_INTEGER_NODE:
3194 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
3195 case PM_INTERPOLATED_STRING_NODE:
3196 case PM_INTERPOLATED_SYMBOL_NODE:
3197 case PM_INTERPOLATED_X_STRING_NODE:
3198 case PM_LAMBDA_NODE:
3199 case PM_LOCAL_VARIABLE_READ_NODE:
3201 case PM_SOURCE_ENCODING_NODE:
3202 case PM_SOURCE_FILE_NODE:
3203 case PM_SOURCE_LINE_NODE:
3205 case PM_RATIONAL_NODE:
3206 case PM_REGULAR_EXPRESSION_NODE:
3208 case PM_STRING_NODE:
3209 case PM_SYMBOL_NODE:
3211 case PM_X_STRING_NODE: {
3215 PM_COMPILE_NOT_POPPED(node);
3216 if (in_single_pattern) {
3217 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
3220 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
3222 if (in_single_pattern) {
3223 pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 2);
3226 PUSH_INSNL(ret, location, branchif, matched_label);
3227 PUSH_INSNL(ret, location, jump, unmatched_label);
3230 case PM_PINNED_VARIABLE_NODE: {
3236 CHECK(pm_compile_pattern(iseq, scope_node, cast->
variable, ret, matched_label, unmatched_label, in_single_pattern,
true, base_index));
3240 case PM_UNLESS_NODE: {
3255 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3270 CHECK(pm_compile_pattern_match(iseq, scope_node, statement, ret, unmatched_label, in_single_pattern, use_deconstructed_cache, base_index));
3271 PM_COMPILE_NOT_POPPED(predicate);
3273 if (in_single_pattern) {
3274 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3276 PUSH_INSN(ret, location, dup);
3277 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3278 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3281 PUSH_INSNL(ret, location, branchunless, match_succeeded_label);
3285 VALUE operand = rb_fstring_lit(
"guard clause does not return true");
3286 PUSH_INSN1(ret, location, putobject, operand);
3289 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
3290 PUSH_INSN1(ret, location, putobject,
Qfalse);
3291 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
3293 PUSH_INSN(ret, location, pop);
3294 PUSH_INSN(ret, location, pop);
3296 PUSH_LABEL(ret, match_succeeded_label);
3299 if (PM_NODE_TYPE_P(node, PM_IF_NODE)) {
3300 PUSH_INSNL(ret, location, branchunless, unmatched_label);
3303 PUSH_INSNL(ret, location, branchif, unmatched_label);
3306 PUSH_INSNL(ret, location, jump, matched_label);
3313 rb_bug(
"Unexpected node type in pattern matching expression: %s", pm_node_type(PM_NODE_TYPE(node)));
3320#undef PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE
3321#undef PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING
3322#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P
3323#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE
3324#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY
3335 scope->parameters = NULL;
3337 scope->local_table_for_iseq_size = 0;
3345 scope->base.
type = PM_SCOPE_NODE;
3348 scope->previous = previous;
3351 switch (PM_NODE_TYPE(node)) {
3352 case PM_BLOCK_NODE: {
3354 scope->body = cast->
body;
3355 scope->locals = cast->
locals;
3359 case PM_CLASS_NODE: {
3361 scope->body = cast->
body;
3362 scope->locals = cast->
locals;
3368 scope->body = cast->body;
3369 scope->locals = cast->locals;
3372 case PM_ENSURE_NODE: {
3388 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
3393 case PM_LAMBDA_NODE: {
3396 scope->body = cast->
body;
3397 scope->locals = cast->
locals;
3400 case PM_MODULE_NODE: {
3402 scope->body = cast->
body;
3403 scope->locals = cast->
locals;
3406 case PM_POST_EXECUTION_NODE: {
3411 case PM_PROGRAM_NODE: {
3414 scope->locals = cast->locals;
3417 case PM_RESCUE_NODE: {
3422 case PM_RESCUE_MODIFIER_NODE: {
3427 case PM_SINGLETON_CLASS_NODE: {
3429 scope->body = cast->
body;
3430 scope->locals = cast->
locals;
3433 case PM_STATEMENTS_NODE: {
3439 rb_bug(
"unreachable");
3468 iobj = IS_INSN(last_elem) ? (
INSN*) last_elem : (
INSN*) get_prev_insn((
INSN*) last_elem);
3469 while (!IS_INSN_ID(iobj, send) && !IS_INSN_ID(iobj, invokesuper) && !IS_INSN_ID(iobj, sendforward) && !IS_INSN_ID(iobj, invokesuperforward)) {
3470 iobj = (
INSN*) get_prev_insn(iobj);
3472 ELEM_INSERT_NEXT(&iobj->link, (
LINK_ELEMENT*) retry_end_l);
3477 if (&iobj->link == LAST_ELEMENT(ret)) {
3485 const char *name = rb_id2name(method_id);
3486 static const char prefix[] =
"__builtin_";
3487 const size_t prefix_len =
sizeof(prefix) - 1;
3489 if (receiver == NULL) {
3490 if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) {
3492 return &name[prefix_len];
3495 else if (PM_NODE_TYPE_P(receiver, PM_CALL_NODE)) {
3496 if (PM_NODE_FLAG_P(receiver, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3504 else if (PM_NODE_TYPE_P(receiver, PM_CONSTANT_READ_NODE)) {
3519 if (arguments == NULL) {
3520 COMPILE_ERROR(iseq, node_location->
line,
"attr!: no argument");
3526 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3527 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to attr!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3531 VALUE symbol = pm_static_literal_value(iseq, argument, scope_node);
3534 if (strcmp(RSTRING_PTR(
string),
"leaf") == 0) {
3535 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_LEAF;
3537 else if (strcmp(RSTRING_PTR(
string),
"inline_block") == 0) {
3538 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_INLINE_BLOCK;
3540 else if (strcmp(RSTRING_PTR(
string),
"use_block") == 0) {
3541 iseq_set_use_block(iseq);
3543 else if (strcmp(RSTRING_PTR(
string),
"c_trace") == 0) {
3545 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_C_TRACE;
3547 else if (strcmp(RSTRING_PTR(
string),
"without_interrupts") == 0) {
3548 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_WITHOUT_INTERRUPTS;
3551 COMPILE_ERROR(iseq, node_location->
line,
"unknown argument to attr!: %s", RSTRING_PTR(
string));
3562 if (arguments == NULL) {
3563 COMPILE_ERROR(iseq, node_location->
line,
"arg!: no argument");
3568 COMPILE_ERROR(iseq, node_location->
line,
"arg!: too many argument");
3573 if (!PM_NODE_TYPE_P(argument, PM_SYMBOL_NODE)) {
3574 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to arg!: %s", pm_node_type(PM_NODE_TYPE(argument)));
3580 int index = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->local_table_size - get_local_var_idx(iseq, name);
3582 debugs(
"id: %s idx: %d\n", rb_id2name(name), index);
3583 PUSH_GETLOCAL(ret, *node_location, index, get_lvar_level(iseq));
3592 const pm_node_t *ast_node = scope_node->ast_node;
3593 if (!PM_NODE_TYPE_P(ast_node, PM_DEF_NODE)) {
3594 rb_bug(
"mandatory_only?: not in method definition");
3600 if (parameters_node == NULL) {
3601 rb_bug(
"mandatory_only?: in method definition with no parameters");
3606 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)) {
3607 rb_bug(
"mandatory_only?: not in method definition with plain statements");
3613 rb_bug(
"mandatory_only?: can't find mandatory node");
3624 .name = def_node->
name,
3626 .parameters = ¶meters,
3636 pm_scope_node_init(&def.base, &next_scope_node, scope_node);
3638 const rb_iseq_t *mandatory_only_iseq = pm_iseq_build(
3640 rb_iseq_base_label(iseq),
3642 rb_iseq_realpath(iseq),
3643 node_location->
line,
3647 ISEQ_COMPILE_DATA(iseq)->option
3649 RB_OBJ_WRITE(iseq, &ISEQ_BODY(iseq)->mandatory_only_iseq, (
VALUE)mandatory_only_iseq);
3651 pm_scope_node_destroy(&next_scope_node);
3660 if (parent_block != NULL) {
3661 COMPILE_ERROR(iseq, node_location->
line,
"should not call builtins here.");
3665#define BUILTIN_INLINE_PREFIX "_bi"
3666 char inline_func[
sizeof(BUILTIN_INLINE_PREFIX) +
DECIMAL_SIZE_OF(
int)];
3667 bool cconst =
false;
3672 if (strcmp(
"cstmt!", builtin_func) == 0 || strcmp(
"cexpr!", builtin_func) == 0) {
3675 else if (strcmp(
"cconst!", builtin_func) == 0) {
3678 else if (strcmp(
"cinit!", builtin_func) == 0) {
3682 else if (strcmp(
"attr!", builtin_func) == 0) {
3683 return pm_compile_builtin_attr(iseq, scope_node, arguments, node_location);
3685 else if (strcmp(
"arg!", builtin_func) == 0) {
3686 return pm_compile_builtin_arg(iseq, ret, scope_node, arguments, node_location, popped);
3688 else if (strcmp(
"mandatory_only?", builtin_func) == 0) {
3690 rb_bug(
"mandatory_only? should be in if condition");
3692 else if (!LIST_INSN_SIZE_ZERO(ret)) {
3693 rb_bug(
"mandatory_only? should be put on top");
3696 PUSH_INSN1(ret, *node_location, putobject,
Qfalse);
3697 return pm_compile_builtin_mandatory_only_method(iseq, scope_node, call_node, node_location);
3700 rb_bug(
"can't find builtin function:%s", builtin_func);
3703 COMPILE_ERROR(iseq, node_location->
line,
"can't find builtin function:%s", builtin_func);
3707 int inline_index = node_location->
line;
3708 snprintf(inline_func,
sizeof(inline_func), BUILTIN_INLINE_PREFIX
"%d", inline_index);
3709 builtin_func = inline_func;
3715 typedef VALUE(*builtin_func0)(
void *,
VALUE);
3716 VALUE const_val = (*(builtin_func0)(uintptr_t)bf->func_ptr)(NULL,
Qnil);
3717 PUSH_INSN1(ret, *node_location, putobject, const_val);
3723 DECL_ANCHOR(args_seq);
3727 int argc = pm_setup_args(arguments, call_node->
block, &flags, &keywords, iseq, args_seq, scope_node, node_location);
3729 if (argc != bf->argc) {
3730 COMPILE_ERROR(iseq, node_location->
line,
"argc is not match for builtin function:%s (expect %d but %d)", builtin_func, bf->argc, argc);
3734 unsigned int start_index;
3735 if (delegate_call_p(iseq, argc, args_seq, &start_index)) {
3736 PUSH_INSN2(ret, *node_location, opt_invokebuiltin_delegate, bf,
INT2FIX(start_index));
3739 PUSH_SEQ(ret, args_seq);
3740 PUSH_INSN1(ret, *node_location, invokebuiltin, bf);
3743 if (popped) PUSH_INSN(ret, *node_location, pop);
3758 LABEL *else_label = NEW_LABEL(location.
line);
3759 LABEL *end_label = NEW_LABEL(location.
line);
3760 LABEL *retry_end_l = NEW_LABEL(location.
line);
3764 int node_id = location.
node_id;
3766 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3767 if (PM_BRANCH_COVERAGE_P(iseq)) {
3768 uint32_t end_cursor = 0;
3769 bool end_found =
false;
3773 end_cursor = cursor;
3779 if (!end_found || cursor > end_cursor) {
3780 end_cursor = cursor;
3787 if (!end_found || cursor > end_cursor) {
3788 end_cursor = cursor;
3797 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(call_node);
3798 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);
3801 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
3802 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
3805 branches = decl_branch_base(iseq, PTR2NUM(call_node), &code_location,
"&.");
3808 PUSH_INSN(ret, location, dup);
3809 PUSH_INSNL(ret, location, branchnil, else_label);
3811 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0,
"then", branches);
3819 int orig_argc = pm_setup_args(call_node->
arguments, call_node->
block, &flags, &kw_arg, iseq, ret, scope_node, &location);
3820 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
3823 if (call_node->
block != NULL && PM_NODE_TYPE_P(call_node->
block, PM_BLOCK_NODE)) {
3826 pm_scope_node_init(call_node->
block, &next_scope_node, scope_node);
3828 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));
3829 pm_scope_node_destroy(&next_scope_node);
3830 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
3833 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_VARIABLE_CALL)) {
3834 flags |= VM_CALL_VCALL;
3838 flags |= VM_CALL_ARGS_SIMPLE;
3842 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
3843 flags |= VM_CALL_FCALL;
3846 if (!popped && PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE)) {
3847 if (flags & VM_CALL_ARGS_BLOCKARG) {
3848 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
3849 if (flags & VM_CALL_ARGS_SPLAT) {
3850 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3851 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3853 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 3));
3854 PUSH_INSN(ret, location, pop);
3856 else if (flags & VM_CALL_ARGS_SPLAT) {
3857 PUSH_INSN(ret, location, dup);
3858 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3859 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3860 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 2));
3861 PUSH_INSN(ret, location, pop);
3864 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 1));
3868 if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
3869 PUSH_INSN(ret, location, splatkw);
3872 LABEL *not_basic_new = NEW_LABEL(location.
line);
3873 LABEL *not_basic_new_finish = NEW_LABEL(location.
line);
3875 bool inline_new = ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction &&
3876 method_id == rb_intern(
"new") &&
3877 call_node->
block == NULL &&
3878 (flags & VM_CALL_ARGS_BLOCKARG) == 0;
3881 if (LAST_ELEMENT(ret) == opt_new_prelude) {
3882 PUSH_INSN(ret, location, putnil);
3883 PUSH_INSN(ret, location, swap);
3886 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(swap), 0)->link);
3887 ELEM_INSERT_NEXT(opt_new_prelude, &new_insn_body(iseq, location.
line, location.
node_id, BIN(putnil), 0)->link);
3892 if (flags & VM_CALL_FORWARDING) {
3893 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc + 1, flags, kw_arg, 0);
3896 ci = (
VALUE)new_callinfo(iseq, method_id, orig_argc, flags, kw_arg, 0);
3899 PUSH_INSN2(ret, location, opt_new, ci, not_basic_new);
3900 LABEL_REF(not_basic_new);
3902 PUSH_SEND_R(ret, location, rb_intern(
"initialize"),
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags | VM_CALL_FCALL), kw_arg);
3903 PUSH_INSNL(ret, location, jump, not_basic_new_finish);
3905 PUSH_LABEL(ret, not_basic_new);
3907 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3908 PUSH_INSN(ret, location, swap);
3910 PUSH_LABEL(ret, not_basic_new_finish);
3911 PUSH_INSN(ret, location, pop);
3914 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3917 if (block_iseq && ISEQ_BODY(block_iseq)->catch_table) {
3918 pm_compile_retry_end_label(iseq, ret, retry_end_l);
3919 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, start, retry_end_l, block_iseq, retry_end_l);
3922 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
3923 PUSH_INSNL(ret, location, jump, end_label);
3924 PUSH_LABEL(ret, else_label);
3925 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 1,
"else", branches);
3926 PUSH_LABEL(ret, end_label);
3929 if (PM_NODE_FLAG_P(call_node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
3930 PUSH_INSN(ret, location, pop);
3933 if (popped) PUSH_INSN(ret, location, pop);
3934 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
3944 const char *
type = (
const char *) (pm_parser_start(scope_node->parser) + node->
base.
location.
start + 1);
3964#define PUSH_VAL(type) (in_condition ? Qtrue : rb_iseq_defined_string(type))
3967 enum defined_type dtype = DEFINED_NOT_DEFINED;
3970 switch (PM_NODE_TYPE(node)) {
3975 dtype = DEFINED_NIL;
3978 case PM_INSTANCE_VARIABLE_READ_NODE: {
3982 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3984 PUSH_INSN3(ret, location, definedivar,
ID2SYM(name), get_ivar_ic_value(iseq, name), PUSH_VAL(DEFINED_IVAR));
3989 case PM_LOCAL_VARIABLE_READ_NODE:
3992 case PM_IT_LOCAL_VARIABLE_READ_NODE:
3995 dtype = DEFINED_LVAR;
3998 case PM_GLOBAL_VARIABLE_READ_NODE: {
4002 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4004 PUSH_INSN(ret, location, putnil);
4005 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR),
ID2SYM(name), PUSH_VAL(DEFINED_GVAR));
4010 case PM_CLASS_VARIABLE_READ_NODE: {
4014 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4016 PUSH_INSN(ret, location, putnil);
4017 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR),
ID2SYM(name), PUSH_VAL(DEFINED_CVAR));
4022 case PM_CONSTANT_READ_NODE: {
4026 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4028 PUSH_INSN(ret, location, putnil);
4029 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4037 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
4039 PUSH_INSN(ret, location, putnil);
4040 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
4044 case PM_SUPER_NODE: {
4049 if (cast->
block != NULL && !PM_NODE_TYPE_P(cast->
block, PM_BLOCK_ARGUMENT_NODE)) {
4050 dtype = DEFINED_EXPR;
4054 PUSH_INSN(ret, location, putnil);
4055 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4058 case PM_FORWARDING_SUPER_NODE: {
4063 if (cast->
block != NULL) {
4064 dtype = DEFINED_EXPR;
4068 PUSH_INSN(ret, location, putnil);
4069 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4076 dtype = DEFINED_SELF;
4082 dtype = DEFINED_TRUE;
4088 dtype = DEFINED_FALSE;
4091 case PM_CALL_AND_WRITE_NODE:
4094 case PM_CALL_OPERATOR_WRITE_NODE:
4097 case PM_CALL_OR_WRITE_NODE:
4100 case PM_CLASS_VARIABLE_AND_WRITE_NODE:
4103 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE:
4106 case PM_CLASS_VARIABLE_OR_WRITE_NODE:
4109 case PM_CLASS_VARIABLE_WRITE_NODE:
4112 case PM_CONSTANT_AND_WRITE_NODE:
4115 case PM_CONSTANT_OPERATOR_WRITE_NODE:
4118 case PM_CONSTANT_OR_WRITE_NODE:
4121 case PM_CONSTANT_PATH_AND_WRITE_NODE:
4124 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
4127 case PM_CONSTANT_PATH_OR_WRITE_NODE:
4130 case PM_CONSTANT_PATH_WRITE_NODE:
4133 case PM_CONSTANT_WRITE_NODE:
4136 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE:
4139 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE:
4142 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE:
4145 case PM_GLOBAL_VARIABLE_WRITE_NODE:
4148 case PM_INDEX_AND_WRITE_NODE:
4151 case PM_INDEX_OPERATOR_WRITE_NODE:
4154 case PM_INDEX_OR_WRITE_NODE:
4157 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE:
4160 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE:
4163 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE:
4166 case PM_INSTANCE_VARIABLE_WRITE_NODE:
4169 case PM_LOCAL_VARIABLE_AND_WRITE_NODE:
4172 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE:
4175 case PM_LOCAL_VARIABLE_OR_WRITE_NODE:
4178 case PM_LOCAL_VARIABLE_WRITE_NODE:
4181 case PM_MULTI_WRITE_NODE:
4184 dtype = DEFINED_ASGN;
4187 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
4190 case PM_ALIAS_METHOD_NODE:
4199 case PM_CASE_MATCH_NODE:
4211 case PM_DEFINED_NODE:
4214 case PM_FLIP_FLOP_NODE:
4226 case PM_IMAGINARY_NODE:
4229 case PM_INTEGER_NODE:
4232 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE:
4235 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE:
4238 case PM_INTERPOLATED_STRING_NODE:
4241 case PM_INTERPOLATED_SYMBOL_NODE:
4244 case PM_INTERPOLATED_X_STRING_NODE:
4247 case PM_LAMBDA_NODE:
4250 case PM_MATCH_LAST_LINE_NODE:
4253 case PM_MATCH_PREDICATE_NODE:
4256 case PM_MATCH_REQUIRED_NODE:
4259 case PM_MATCH_WRITE_NODE:
4262 case PM_MODULE_NODE:
4271 case PM_POST_EXECUTION_NODE:
4277 case PM_RATIONAL_NODE:
4283 case PM_REGULAR_EXPRESSION_NODE:
4286 case PM_RESCUE_MODIFIER_NODE:
4292 case PM_RETURN_NODE:
4295 case PM_SINGLETON_CLASS_NODE:
4298 case PM_SOURCE_ENCODING_NODE:
4301 case PM_SOURCE_FILE_NODE:
4304 case PM_SOURCE_LINE_NODE:
4307 case PM_STRING_NODE:
4310 case PM_SYMBOL_NODE:
4316 case PM_UNLESS_NODE:
4325 case PM_X_STRING_NODE:
4328 dtype = DEFINED_EXPR;
4331 case PM_BACK_REFERENCE_READ_NODE: {
4335 VALUE ref = pm_compile_back_reference_ref(scope_node, cast);
4337 PUSH_INSN(ret, location, putnil);
4338 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4342 case PM_NUMBERED_REFERENCE_READ_NODE: {
4346 VALUE ref = pm_compile_numbered_reference_ref(cast);
4348 PUSH_INSN(ret, location, putnil);
4349 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4354 case PM_CONSTANT_PATH_NODE: {
4358 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4360 if (cast->
parent != NULL) {
4361 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4362 pm_compile_defined_expr0(iseq, cast->
parent, node_location, ret, popped, scope_node,
true, lfinish,
false);
4364 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4365 PM_COMPILE(cast->
parent);
4368 PUSH_INSN1(ret, location, putobject,
rb_cObject);
4371 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4375 case PM_BEGIN_NODE: {
4383 dtype = DEFINED_NIL;
4389 pm_compile_defined_expr0(iseq, cast->
statements->
body.
nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4395 dtype = DEFINED_EXPR;
4400 dtype = DEFINED_EXPR;
4405 case PM_PARENTHESES_NODE: {
4410 if (cast->
body == NULL) {
4412 dtype = DEFINED_NIL;
4414 else if (PM_NODE_TYPE_P(cast->
body, PM_STATEMENTS_NODE) && !PM_NODE_FLAG_P(cast, PM_PARENTHESES_NODE_FLAGS_MULTIPLE_STATEMENTS)) {
4417 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);
4423 dtype = DEFINED_EXPR;
4428 case PM_ARRAY_NODE: {
4434 lfinish[1] = NEW_LABEL(location.
line);
4437 for (
size_t index = 0; index < cast->
elements.
size; index++) {
4438 pm_compile_defined_expr0(iseq, cast->
elements.
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4439 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4442 dtype = DEFINED_EXPR;
4448 case PM_KEYWORD_HASH_NODE: {
4453 if (PM_NODE_TYPE_P(node, PM_HASH_NODE)) {
4460 if (elements->
size > 0 && !lfinish[1]) {
4461 lfinish[1] = NEW_LABEL(location.
line);
4464 for (
size_t index = 0; index < elements->
size; index++) {
4465 pm_compile_defined_expr0(iseq, elements->
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4466 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4469 dtype = DEFINED_EXPR;
4472 case PM_ASSOC_NODE: {
4477 pm_compile_defined_expr0(iseq, cast->
key, node_location, ret, popped, scope_node,
true, lfinish,
false);
4478 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4479 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4483 case PM_ASSOC_SPLAT_NODE: {
4488 if (cast->
value == NULL) {
4489 dtype = DEFINED_EXPR;
4493 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4496 case PM_IMPLICIT_NODE: {
4500 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4503 case PM_CALL_NODE: {
4504#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE))
4510 if (BLOCK_P(cast)) {
4511 dtype = DEFINED_EXPR;
4516 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4517 if (!lfinish[2]) lfinish[2] = NEW_LABEL(location.
line);
4521 pm_compile_defined_expr0(iseq, (
const pm_node_t *) cast->
arguments, node_location, ret, popped, scope_node,
true, lfinish,
false);
4522 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4525 if (cast->
block && PM_NODE_TYPE_P(cast->
block, PM_BLOCK_ARGUMENT_NODE)) {
4526 pm_compile_defined_expr0(iseq, cast->
block, node_location, ret, popped, scope_node,
true, lfinish,
false);
4527 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4534 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
true);
4535 PUSH_INSNL(ret, location, branchunless, lfinish[2]);
4538 ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
4540 pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
4543 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
false);
4544 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4548 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4550 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4551 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_METHOD),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4554 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4556 PUSH_INSN(ret, location, putself);
4557 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4559 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_FUNC),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4566 case PM_ARGUMENTS_NODE: {
4571 for (
size_t index = 0; index < cast->
arguments.
size; index++) {
4572 pm_compile_defined_expr0(iseq, cast->
arguments.
nodes[index], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4573 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4576 dtype = DEFINED_EXPR;
4579 case PM_BLOCK_ARGUMENT_NODE:
4582 dtype = DEFINED_EXPR;
4584 case PM_FORWARDING_ARGUMENTS_NODE:
4587 dtype = DEFINED_EXPR;
4589 case PM_SPLAT_NODE: {
4595 dtype = DEFINED_EXPR;
4599 pm_compile_defined_expr0(iseq, cast->
expression, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4601 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4602 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4604 dtype = DEFINED_EXPR;
4607 case PM_SHAREABLE_CONSTANT_NODE:
4611 pm_compile_defined_expr0(iseq, ((
const pm_shareable_constant_node_t *) node)->write, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4614 case PM_BLOCK_LOCAL_VARIABLE_NODE:
4615 case PM_BLOCK_PARAMETER_NODE:
4616 case PM_BLOCK_PARAMETERS_NODE:
4617 case PM_FORWARDING_PARAMETER_NODE:
4618 case PM_IMPLICIT_REST_NODE:
4619 case PM_IT_PARAMETERS_NODE:
4620 case PM_PARAMETERS_NODE:
4621 case PM_KEYWORD_REST_PARAMETER_NODE:
4622 case PM_NO_KEYWORDS_PARAMETER_NODE:
4623 case PM_NO_BLOCK_PARAMETER_NODE:
4624 case PM_NUMBERED_PARAMETERS_NODE:
4625 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE:
4626 case PM_OPTIONAL_PARAMETER_NODE:
4627 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
4628 case PM_REQUIRED_PARAMETER_NODE:
4629 case PM_REST_PARAMETER_NODE:
4631 case PM_ALTERNATION_PATTERN_NODE:
4632 case PM_ARRAY_PATTERN_NODE:
4633 case PM_CAPTURE_PATTERN_NODE:
4634 case PM_FIND_PATTERN_NODE:
4635 case PM_HASH_PATTERN_NODE:
4636 case PM_PINNED_EXPRESSION_NODE:
4637 case PM_PINNED_VARIABLE_NODE:
4639 case PM_CALL_TARGET_NODE:
4640 case PM_CLASS_VARIABLE_TARGET_NODE:
4641 case PM_CONSTANT_PATH_TARGET_NODE:
4642 case PM_CONSTANT_TARGET_NODE:
4643 case PM_GLOBAL_VARIABLE_TARGET_NODE:
4644 case PM_INDEX_TARGET_NODE:
4645 case PM_INSTANCE_VARIABLE_TARGET_NODE:
4646 case PM_LOCAL_VARIABLE_TARGET_NODE:
4647 case PM_MULTI_TARGET_NODE:
4650 case PM_ENSURE_NODE:
4652 case PM_RESCUE_NODE:
4656 case PM_EMBEDDED_STATEMENTS_NODE:
4657 case PM_EMBEDDED_VARIABLE_NODE:
4658 case PM_ERROR_RECOVERY_NODE:
4659 case PM_PRE_EXECUTION_NODE:
4660 case PM_PROGRAM_NODE:
4662 case PM_STATEMENTS_NODE:
4663 rb_bug(
"Unreachable node in defined?: %s", pm_node_type(PM_NODE_TYPE(node)));
4667 PUSH_INSN1(ret, location, putobject, PUSH_VAL(dtype));
4676 pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4679 LABEL *lstart = NEW_LABEL(node_location->
line);
4680 LABEL *lend = NEW_LABEL(node_location->
line);
4683 rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
4685 const rb_iseq_t *rescue = new_child_iseq_with_callback(
4694 lstart->rescued = LABEL_RESCUE_BEG;
4695 lend->rescued = LABEL_RESCUE_END;
4697 APPEND_LABEL(ret, lcur, lstart);
4698 PUSH_LABEL(ret, lend);
4699 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
4709 lfinish[0] = NEW_LABEL(node_location->
line);
4714 pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish);
4718 ELEM_INSERT_NEXT(last, &new_insn_body(iseq, node_location->
line, node_location->
node_id, BIN(putnil), 0)->link);
4719 PUSH_INSN(ret, *node_location, swap);
4721 if (lfinish[2]) PUSH_LABEL(ret, lfinish[2]);
4722 PUSH_INSN(ret, *node_location, pop);
4723 PUSH_LABEL(ret, lfinish[1]);
4727 PUSH_LABEL(ret, lfinish[0]);
4738 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
4740 DECL_ANCHOR(ensure);
4743 if (enlp->erange != NULL) {
4744 DECL_ANCHOR(ensure_part);
4745 LABEL *lstart = NEW_LABEL(0);
4746 LABEL *lend = NEW_LABEL(0);
4748 add_ensure_range(iseq, enlp->erange, lstart, lend);
4750 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
4751 PUSH_LABEL(ensure_part, lstart);
4753 PM_COMPILE_INTO_ANCHOR(ensure_part, (
const pm_node_t *) enlp->ensure_node);
4754 PUSH_LABEL(ensure_part, lend);
4755 PUSH_SEQ(ensure, ensure_part);
4764 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
4765 PUSH_SEQ(ret, ensure);
4778 RUBY_ASSERT((constant_id & PM_SPECIAL_CONSTANT_FLAG) == 0);
4780 ID local = pm_constant_id_lookup(scope_node, constant_id);
4781 local_table_for_iseq->ids[local_index] = local;
4782 pm_index_lookup_table_insert(index_lookup_table, constant_id, local_index);
4791 local_table_for_iseq->ids[local_index] = local_name;
4792 pm_index_lookup_table_insert(index_lookup_table, special_id, local_index);
4804 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4807 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4808 if (!PM_NODE_FLAG_P(left, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4809 pm_insert_local_index(((
const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4814 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4815 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);
4819 if (node->
rest != NULL && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE)) {
4822 if (rest->expression != NULL) {
4823 RUBY_ASSERT(PM_NODE_TYPE_P(rest->expression, PM_REQUIRED_PARAMETER_NODE));
4825 if (!PM_NODE_FLAG_P(rest->expression, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4826 pm_insert_local_index(((
const pm_required_parameter_node_t *) rest->expression)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4832 for (
size_t index = 0; index < node->
rights.
size; index++) {
4835 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4836 if (!PM_NODE_FLAG_P(right, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
4837 pm_insert_local_index(((
const pm_required_parameter_node_t *) right)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4842 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4843 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);
4859 PUSH_SETLOCAL(ret, location, index.index, index.level);
4874 bool has_rest = (node->
rest && PM_NODE_TYPE_P(node->
rest, PM_SPLAT_NODE) && (((
const pm_splat_node_t *) node->
rest)->expression) != NULL);
4877 int flag = (has_rest || has_rights) ? 1 : 0;
4880 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4883 if (PM_NODE_TYPE_P(left, PM_REQUIRED_PARAMETER_NODE)) {
4887 RUBY_ASSERT(PM_NODE_TYPE_P(left, PM_MULTI_TARGET_NODE));
4898 RUBY_ASSERT(PM_NODE_TYPE_P(rest, PM_REQUIRED_PARAMETER_NODE));
4908 for (
size_t index = 0; index < node->
rights.
size; index++) {
4911 if (PM_NODE_TYPE_P(right, PM_REQUIRED_PARAMETER_NODE)) {
4915 RUBY_ASSERT(PM_NODE_TYPE_P(right, PM_MULTI_TARGET_NODE));
4975 node->stack_index = state->stack_size + 1;
4976 node->stack_size = stack_size;
4977 node->position = state->position;
4980 if (state->head == NULL) {
4985 state->tail->next = node;
4989 state->stack_size += stack_size;
5002 if (state->stack_size == 0)
return;
5007 while (current != NULL) {
5008 VALUE offset =
INT2FIX(state->stack_size - current->stack_index + current->position);
5009 current->topn->operands[0] = offset;
5015 if (current->stack_size > 1) {
5016 INSN *insn = current->topn;
5018 for (
size_t index = 1; index < current->stack_size; index += 1) {
5022 insn = (
INSN *) element;
5025 insn->operands[0] = offset;
5030 current = current->next;
5032 SIZED_FREE(previous);
5072 switch (PM_NODE_TYPE(node)) {
5073 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5082 PUSH_SETLOCAL(writes, location, index.index, index.level);
5085 case PM_CLASS_VARIABLE_TARGET_NODE: {
5092 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5095 PUSH_INSN2(writes, location, setclassvariable, operand, get_cvar_ic_value(iseq, name));
5098 case PM_CONSTANT_TARGET_NODE: {
5105 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5108 PUSH_INSN1(writes, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5109 PUSH_INSN1(writes, location, setconstant, operand);
5112 case PM_GLOBAL_VARIABLE_TARGET_NODE: {
5119 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5122 PUSH_INSN1(writes, location, setglobal, operand);
5125 case PM_INSTANCE_VARIABLE_TARGET_NODE: {
5132 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5135 PUSH_INSN2(writes, location, setinstancevariable, operand, get_ivar_ic_value(iseq, name));
5138 case PM_CONSTANT_PATH_TARGET_NODE: {
5148 ID name = pm_constant_id_lookup(scope_node, cast->
name);
5150 if (cast->
parent != NULL) {
5151 pm_compile_node(iseq, cast->
parent, parents,
false, scope_node);
5154 PUSH_INSN1(parents, location, putobject,
rb_cObject);
5157 if (state == NULL) {
5158 PUSH_INSN(writes, location, swap);
5161 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5162 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5166 PUSH_INSN1(writes, location, setconstant, operand);
5168 if (state != NULL) {
5169 PUSH_INSN(cleanup, location, pop);
5174 case PM_CALL_TARGET_NODE: {
5184 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
5186 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5188 LABEL *safe_label = NULL;
5189 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
5190 safe_label = NEW_LABEL(location.
line);
5191 PUSH_INSN(parents, location, dup);
5192 PUSH_INSNL(parents, location, branchnil, safe_label);
5195 if (state != NULL) {
5196 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5197 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
5198 PUSH_INSN(writes, location, swap);
5201 int flags = VM_CALL_ARGS_SIMPLE;
5202 if (PM_NODE_FLAG_P(cast, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) flags |= VM_CALL_FCALL;
5204 PUSH_SEND_WITH_FLAG(writes, location, method_id,
INT2FIX(1),
INT2FIX(flags));
5205 if (safe_label != NULL && state == NULL) PUSH_LABEL(writes, safe_label);
5206 PUSH_INSN(writes, location, pop);
5207 if (safe_label != NULL && state != NULL) PUSH_LABEL(writes, safe_label);
5209 if (state != NULL) {
5210 PUSH_INSN(cleanup, location, pop);
5215 case PM_INDEX_TARGET_NODE: {
5227 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5231 int argc = pm_setup_args(cast->
arguments, (
const pm_node_t *) cast->
block, &flags, &kwargs, iseq, parents, scope_node, &location);
5233 if (state != NULL) {
5234 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5235 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), argc + 1);
5238 PUSH_INSN(writes, location, swap);
5241 for (
int index = 0; index < argc; index++) {
5242 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5244 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5252 int ci_argc = argc + 1;
5253 if (flags & VM_CALL_ARGS_SPLAT) {
5255 PUSH_INSN1(writes, location, newarray,
INT2FIX(1));
5256 PUSH_INSN(writes, location, concatarray);
5259 PUSH_SEND_R(writes, location, idASET,
INT2NUM(ci_argc), NULL,
INT2FIX(flags), kwargs);
5260 PUSH_INSN(writes, location, pop);
5262 if (state != NULL) {
5264 PUSH_INSN(writes, location, pop);
5267 for (
int index = 0; index < argc + 1; index++) {
5268 PUSH_INSN(cleanup, location, pop);
5274 case PM_MULTI_TARGET_NODE: {
5281 size_t before_position;
5282 if (state != NULL) {
5283 before_position = state->position;
5287 pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, scope_node, state);
5288 if (state != NULL) state->position = before_position;
5292 case PM_SPLAT_NODE: {
5301 pm_compile_target_node(iseq, cast->
expression, parents, writes, cleanup, scope_node, state);
5307 rb_bug(
"Unexpected node type: %s", pm_node_type(PM_NODE_TYPE(node)));
5325 switch (PM_NODE_TYPE(node)) {
5326 case PM_MULTI_TARGET_NODE: {
5328 lefts = &cast->
lefts;
5333 case PM_MULTI_WRITE_NODE: {
5335 lefts = &cast->
lefts;
5341 rb_bug(
"Unsupported node %s", pm_node_type(PM_NODE_TYPE(node)));
5345 bool has_rest = (rest != NULL) && PM_NODE_TYPE_P(rest, PM_SPLAT_NODE) && ((
const pm_splat_node_t *) rest)->expression != NULL;
5346 bool has_posts = rights->
size > 0;
5351 PUSH_INSN2(writes, location, expandarray,
INT2FIX(lefts->
size),
INT2FIX((has_rest || has_posts) ? 1 : 0));
5357 if (state == NULL) state = &target_state;
5359 size_t base_position = state->position;
5360 size_t splat_position = (has_rest || has_posts) ? 1 : 0;
5363 for (
size_t index = 0; index < lefts->
size; index++) {
5365 state->position = lefts->
size - index + splat_position + base_position;
5366 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5372 state->position = 1 + rights->
size + base_position;
5378 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5383 if (!has_rest && rest != NULL) {
5387 for (
size_t index = 0; index < rights->
size; index++) {
5389 state->position = rights->
size - index + base_position;
5390 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5405 switch (PM_NODE_TYPE(node)) {
5406 case PM_LOCAL_VARIABLE_TARGET_NODE: {
5409 PUSH_GETLOCAL(ret, location, 1, 0);
5410 pm_compile_target_node(iseq, node, ret, ret, ret, scope_node, NULL);
5413 case PM_CLASS_VARIABLE_TARGET_NODE:
5414 case PM_CONSTANT_TARGET_NODE:
5415 case PM_GLOBAL_VARIABLE_TARGET_NODE:
5416 case PM_INSTANCE_VARIABLE_TARGET_NODE:
5417 case PM_CONSTANT_PATH_TARGET_NODE:
5418 case PM_CALL_TARGET_NODE:
5419 case PM_INDEX_TARGET_NODE: {
5423 DECL_ANCHOR(writes);
5424 DECL_ANCHOR(cleanup);
5428 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
5430 PUSH_GETLOCAL(ret, location, 1, 0);
5433 PUSH_SEQ(ret, writes);
5434 PUSH_SEQ(ret, cleanup);
5436 pm_multi_target_state_update(&state);
5440 case PM_MULTI_TARGET_NODE: {
5441 DECL_ANCHOR(writes);
5442 DECL_ANCHOR(cleanup);
5444 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, NULL);
5446 LABEL *not_single = NEW_LABEL(location.
line);
5447 LABEL *not_ary = NEW_LABEL(location.
line);
5455 PUSH_GETLOCAL(ret, location, 1, 0);
5456 PUSH_INSN(ret, location, dup);
5457 PUSH_CALL(ret, location, idLength,
INT2FIX(0));
5458 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
5459 PUSH_CALL(ret, location, idEq,
INT2FIX(1));
5460 PUSH_INSNL(ret, location, branchunless, not_single);
5461 PUSH_INSN(ret, location, dup);
5462 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
5463 PUSH_CALL(ret, location, idAREF,
INT2FIX(1));
5464 PUSH_INSN1(ret, location, putobject,
rb_cArray);
5465 PUSH_INSN(ret, location, swap);
5466 PUSH_CALL(ret, location, rb_intern(
"try_convert"),
INT2FIX(1));
5467 PUSH_INSN(ret, location, dup);
5468 PUSH_INSNL(ret, location, branchunless, not_ary);
5469 PUSH_INSN(ret, location, swap);
5471 PUSH_LABEL(ret, not_ary);
5472 PUSH_INSN(ret, location, pop);
5474 PUSH_LABEL(ret, not_single);
5476 if (PM_NODE_TYPE_P(node, PM_SPLAT_NODE)) {
5481 PUSH_SEQ(ret, writes);
5482 PUSH_SEQ(ret, cleanup);
5486 rb_bug(
"Unexpected node type for index in for node: %s", pm_node_type(PM_NODE_TYPE(node)));
5494 LABEL *lstart = NEW_LABEL(node_location->
line);
5495 LABEL *lend = NEW_LABEL(node_location->
line);
5496 LABEL *lcont = NEW_LABEL(node_location->
line);
5501 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
5508 pm_scope_node_destroy(&rescue_scope_node);
5510 lstart->rescued = LABEL_RESCUE_BEG;
5511 lend->rescued = LABEL_RESCUE_END;
5512 PUSH_LABEL(ret, lstart);
5514 bool prev_in_rescue = ISEQ_COMPILE_DATA(iseq)->in_rescue;
5515 ISEQ_COMPILE_DATA(iseq)->in_rescue =
true;
5522 PUSH_INSN(ret, location, putnil);
5525 ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;
5526 PUSH_LABEL(ret, lend);
5529 if (!popped) PUSH_INSN(ret, *node_location, pop);
5533 PUSH_INSN(ret, *node_location, nop);
5534 PUSH_LABEL(ret, lcont);
5536 if (popped) PUSH_INSN(ret, *node_location, pop);
5537 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
5538 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
5547 if (statements != NULL) {
5548 location = PM_NODE_START_LOCATION(statements);
5551 location = *node_location;
5554 LABEL *lstart = NEW_LABEL(location.
line);
5556 LABEL *lcont = NEW_LABEL(location.
line);
5563 if (statements != NULL) {
5564 pm_compile_node(iseq, (
const pm_node_t *) statements, ensr,
true, scope_node);
5568 bool last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
5573 push_ensure_entry(iseq, &enl, &er, (
void *) cast->
ensure_clause);
5575 PUSH_LABEL(ret, lstart);
5577 pm_compile_rescue(iseq, cast, node_location, ret, popped | last_leave, scope_node);
5580 pm_compile_node(iseq, (
const pm_node_t *) cast->
statements, ret, popped | last_leave, scope_node);
5582 else if (!(popped | last_leave)) {
5583 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
5586 PUSH_LABEL(ret, lend);
5587 PUSH_SEQ(ret, ensr);
5588 if (!popped && last_leave) PUSH_INSN(ret, *node_location, putnil);
5589 PUSH_LABEL(ret, lcont);
5590 if (last_leave) PUSH_INSN(ret, *node_location, pop);
5602 pm_scope_node_destroy(&next_scope_node);
5604 erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
5605 if (lstart->link.next != &lend->link) {
5607 PUSH_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, child_iseq, lcont);
5608 erange = erange->next;
5611 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
5622 !PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION) &&
5624 PM_NODE_TYPE_P(node->
receiver, PM_STRING_NODE) &&
5626 node->
block == NULL &&
5627 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5640 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
5641 ISEQ_BODY(iseq)->ic_size++;
5642 VALUE segments = rb_ary_new_from_args(1, name);
5643 RB_OBJ_SET_SHAREABLE(segments);
5644 PUSH_INSN1(ret, location, opt_getconstant_path, segments);
5647 PUSH_INSN(ret, location, putnil);
5648 PUSH_INSN1(ret, location, putobject,
Qtrue);
5649 PUSH_INSN1(ret, location, getconstant, name);
5663 switch (PM_NODE_TYPE(node)) {
5664 case PM_CONSTANT_READ_NODE: {
5668 rb_ary_unshift(parts, name);
5671 case PM_CONSTANT_PATH_NODE: {
5675 rb_ary_unshift(parts, name);
5676 if (cast->
parent == NULL) {
5677 rb_ary_unshift(parts,
ID2SYM(idNULL));
5700 switch (PM_NODE_TYPE(node)) {
5701 case PM_CONSTANT_READ_NODE: {
5705 PUSH_INSN1(body, location, putobject,
Qtrue);
5706 PUSH_INSN1(body, location, getconstant, name);
5709 case PM_CONSTANT_PATH_NODE: {
5713 if (cast->
parent == NULL) {
5714 PUSH_INSN(body, location, pop);
5715 PUSH_INSN1(body, location, putobject,
rb_cObject);
5716 PUSH_INSN1(body, location, putobject,
Qtrue);
5717 PUSH_INSN1(body, location, getconstant, name);
5720 pm_compile_constant_path(iseq, cast->
parent, prefix, body,
false, scope_node);
5721 PUSH_INSN1(body, location, putobject,
Qfalse);
5722 PUSH_INSN1(body, location, getconstant, name);
5727 PM_COMPILE_INTO_ANCHOR(prefix, node);
5738 switch (PM_NODE_TYPE(node)) {
5742 case PM_SYMBOL_NODE:
5743 case PM_REGULAR_EXPRESSION_NODE:
5744 case PM_SOURCE_LINE_NODE:
5745 case PM_INTEGER_NODE:
5747 case PM_RATIONAL_NODE:
5748 case PM_IMAGINARY_NODE:
5749 case PM_SOURCE_ENCODING_NODE:
5750 return pm_static_literal_value(iseq, node, scope_node);
5751 case PM_STRING_NODE:
5752 return parse_static_literal_string(iseq, scope_node, node, &((
const pm_string_node_t *) node)->unescaped);
5753 case PM_SOURCE_FILE_NODE:
5755 case PM_ARRAY_NODE: {
5759 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5760 VALUE element = pm_compile_shareable_constant_literal(iseq, cast->
elements.
nodes[index], scope_node);
5768 case PM_HASH_NODE: {
5772 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5774 if (!PM_NODE_TYPE_P(element, PM_ASSOC_NODE))
return Qundef;
5778 VALUE key = pm_compile_shareable_constant_literal(iseq, assoc->
key, scope_node);
5781 VALUE value = pm_compile_shareable_constant_literal(iseq, assoc->
value, scope_node);
5784 rb_hash_aset(result, key, value);
5801 VALUE literal = pm_compile_shareable_constant_literal(iseq, node, scope_node);
5804 PUSH_INSN1(ret, location, putobject, literal);
5809 switch (PM_NODE_TYPE(node)) {
5810 case PM_ARRAY_NODE: {
5814 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5817 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5818 pm_compile_shareable_constant_value(iseq, cast->
elements.
nodes[index], shareability, path, ret, scope_node,
false);
5824 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5825 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5830 case PM_HASH_NODE: {
5834 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5837 pm_compile_hash_elements(iseq, (
const pm_node_t *) cast, &cast->elements, shareability, path,
false, ret, scope_node);
5840 ID method_id = (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) ? rb_intern(
"make_shareable_copy") : rb_intern(
"make_shareable");
5841 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5847 DECL_ANCHOR(value_seq);
5849 pm_compile_node(iseq, node, value_seq,
false, scope_node);
5850 if (PM_NODE_TYPE_P(node, PM_INTERPOLATED_STRING_NODE)) {
5851 PUSH_SEND_WITH_FLAG(value_seq, location, idUMinus,
INT2FIX(0),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5854 if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_LITERAL) {
5855 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5856 PUSH_SEQ(ret, value_seq);
5858 RB_OBJ_SET_SHAREABLE(path);
5860 PUSH_INSN1(ret, location, putobject, path);
5861 PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"ensure_shareable"),
INT2FIX(2),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5863 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY) {
5864 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5865 PUSH_SEQ(ret, value_seq);
5866 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable_copy"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5868 else if (shareability & PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_EVERYTHING) {
5869 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5870 PUSH_SEQ(ret, value_seq);
5871 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5887 ID name_id = pm_constant_id_lookup(scope_node, node->
name);
5889 if (shareability != 0) {
5890 pm_compile_shareable_constant_value(iseq, node->
value, shareability, rb_id2str(name_id), ret, scope_node,
true);
5893 PM_COMPILE_NOT_POPPED(node->
value);
5896 if (!popped) PUSH_INSN(ret, location, dup);
5897 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5900 PUSH_INSN1(ret, location, setconstant, operand);
5913 LABEL *end_label = NEW_LABEL(location.
line);
5915 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5916 if (!popped) PUSH_INSN(ret, location, dup);
5918 PUSH_INSNL(ret, location, branchunless, end_label);
5919 if (!popped) PUSH_INSN(ret, location, pop);
5921 if (shareability != 0) {
5922 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5925 PM_COMPILE_NOT_POPPED(node->
value);
5928 if (!popped) PUSH_INSN(ret, location, dup);
5929 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5930 PUSH_INSN1(ret, location, setconstant, name);
5931 PUSH_LABEL(ret, end_label);
5944 LABEL *set_label = NEW_LABEL(location.
line);
5945 LABEL *end_label = NEW_LABEL(location.
line);
5947 PUSH_INSN(ret, location, putnil);
5948 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name,
Qtrue);
5949 PUSH_INSNL(ret, location, branchunless, set_label);
5951 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5952 if (!popped) PUSH_INSN(ret, location, dup);
5954 PUSH_INSNL(ret, location, branchif, end_label);
5955 if (!popped) PUSH_INSN(ret, location, pop);
5956 PUSH_LABEL(ret, set_label);
5958 if (shareability != 0) {
5959 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5962 PM_COMPILE_NOT_POPPED(node->
value);
5965 if (!popped) PUSH_INSN(ret, location, dup);
5966 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5967 PUSH_INSN1(ret, location, setconstant, name);
5968 PUSH_LABEL(ret, end_label);
5983 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5985 if (shareability != 0) {
5986 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5989 PM_COMPILE_NOT_POPPED(node->
value);
5992 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5993 if (!popped) PUSH_INSN(ret, location, dup);
5995 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5996 PUSH_INSN1(ret, location, setconstant, name);
6007 rb_ary_push(parts, rb_id2str(pm_constant_id_lookup(scope_node, node->
name)));
6010 while (current != NULL && PM_NODE_TYPE_P(current, PM_CONSTANT_PATH_NODE)) {
6012 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, cast->
name)));
6016 if (current == NULL) {
6017 rb_ary_unshift(parts, rb_id2str(idNULL));
6019 else if (PM_NODE_TYPE_P(current, PM_CONSTANT_READ_NODE)) {
6020 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, ((
const pm_constant_read_node_t *) current)->name)));
6044 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6047 if (shareability != 0) {
6048 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6051 PM_COMPILE_NOT_POPPED(node->
value);
6055 PUSH_INSN(ret, location, swap);
6056 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6059 PUSH_INSN(ret, location, swap);
6060 PUSH_INSN1(ret, location, setconstant, name);
6077 PM_COMPILE_NOT_POPPED(target->
parent);
6080 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6083 PUSH_INSN(ret, location, dup);
6084 PUSH_INSN1(ret, location, putobject,
Qtrue);
6085 PUSH_INSN1(ret, location, getconstant, name);
6087 if (!popped) PUSH_INSN(ret, location, dup);
6088 PUSH_INSNL(ret, location, branchunless, lfin);
6090 if (!popped) PUSH_INSN(ret, location, pop);
6092 if (shareability != 0) {
6093 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6096 PM_COMPILE_NOT_POPPED(node->
value);
6100 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6103 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6104 PUSH_INSN(ret, location, swap);
6107 PUSH_INSN1(ret, location, setconstant, name);
6108 PUSH_LABEL(ret, lfin);
6110 if (!popped) PUSH_INSN(ret, location, swap);
6111 PUSH_INSN(ret, location, pop);
6125 LABEL *lassign = NEW_LABEL(location.
line);
6129 PM_COMPILE_NOT_POPPED(target->
parent);
6132 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6135 PUSH_INSN(ret, location, dup);
6136 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name,
Qtrue);
6137 PUSH_INSNL(ret, location, branchunless, lassign);
6139 PUSH_INSN(ret, location, dup);
6140 PUSH_INSN1(ret, location, putobject,
Qtrue);
6141 PUSH_INSN1(ret, location, getconstant, name);
6143 if (!popped) PUSH_INSN(ret, location, dup);
6144 PUSH_INSNL(ret, location, branchif, lfin);
6146 if (!popped) PUSH_INSN(ret, location, pop);
6147 PUSH_LABEL(ret, lassign);
6149 if (shareability != 0) {
6150 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6153 PM_COMPILE_NOT_POPPED(node->
value);
6157 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6160 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6161 PUSH_INSN(ret, location, swap);
6164 PUSH_INSN1(ret, location, setconstant, name);
6165 PUSH_LABEL(ret, lfin);
6167 if (!popped) PUSH_INSN(ret, location, swap);
6168 PUSH_INSN(ret, location, pop);
6185 PM_COMPILE_NOT_POPPED(target->
parent);
6188 PUSH_INSN1(ret, location, putobject,
rb_cObject);
6191 PUSH_INSN(ret, location, dup);
6192 PUSH_INSN1(ret, location, putobject,
Qtrue);
6193 PUSH_INSN1(ret, location, getconstant, name);
6195 if (shareability != 0) {
6196 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6199 PM_COMPILE_NOT_POPPED(node->
value);
6202 PUSH_CALL(ret, location, method_id,
INT2FIX(1));
6203 PUSH_INSN(ret, location, swap);
6206 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6207 PUSH_INSN(ret, location, swap);
6210 PUSH_INSN1(ret, location, setconstant, name);
6219#define PM_CONTAINER_P(node) (PM_NODE_TYPE_P(node, PM_ARRAY_NODE) || PM_NODE_TYPE_P(node, PM_HASH_NODE) || PM_NODE_TYPE_P(node, PM_RANGE_NODE))
6238 bool trailing_comma =
false;
6240 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
6244 if (scope_node->parameters != NULL) {
6245 switch (PM_NODE_TYPE(scope_node->parameters)) {
6246 case PM_BLOCK_PARAMETERS_NODE: {
6248 parameters_node = cast->parameters;
6249 block_locals = &cast->locals;
6251 if (parameters_node) {
6252 if (parameters_node->
rest && PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE)) {
6253 trailing_comma =
true;
6258 case PM_PARAMETERS_NODE: {
6262 case PM_NUMBERED_PARAMETERS_NODE: {
6264 body->param.lead_num = maximum;
6265 body->param.flags.ambiguous_param0 = maximum == 1;
6268 case PM_IT_PARAMETERS_NODE:
6269 body->param.lead_num = 1;
6270 body->param.flags.ambiguous_param0 =
true;
6273 rb_bug(
"Unexpected node type for parameters: %s", pm_node_type(PM_NODE_TYPE(scope_node->parameters)));
6277 struct rb_iseq_param_keyword *keyword = NULL;
6279 if (parameters_node) {
6280 optionals_list = ¶meters_node->
optionals;
6281 requireds_list = ¶meters_node->
requireds;
6282 keywords_list = ¶meters_node->
keywords;
6283 posts_list = ¶meters_node->
posts;
6285 else if (scope_node->parameters && (PM_NODE_TYPE_P(scope_node->parameters, PM_NUMBERED_PARAMETERS_NODE) || PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE))) {
6286 body->param.opt_num = 0;
6289 body->param.lead_num = 0;
6290 body->param.opt_num = 0;
6296 size_t locals_size = locals->
size;
6302 int table_size = (int) locals_size;
6306 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) table_size++;
6308 if (keywords_list && keywords_list->
size) {
6312 if (requireds_list) {
6313 for (
size_t i = 0; i < requireds_list->
size; i++) {
6318 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6321 else if (PM_NODE_TYPE_P(required, PM_REQUIRED_PARAMETER_NODE)) {
6322 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6331 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6339 if (optionals_list && optionals_list->
size) {
6340 for (
size_t i = 0; i < optionals_list->
size; i++) {
6342 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6352 if (parameters_node) {
6353 if (parameters_node->
rest) {
6354 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6368 if (PM_NODE_TYPE_P(parameters_node->
keyword_rest, PM_FORWARDING_PARAMETER_NODE)) {
6370 if (requireds_list->
size == 0 && optionals_list->
size == 0 && keywords_list->
size == 0) {
6371 ISEQ_BODY(iseq)->param.flags.use_block = TRUE;
6372 ISEQ_BODY(iseq)->param.flags.forwardable = TRUE;
6383 if (!kw_rest->name || PM_NODE_FLAG_P(kw_rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6391 for (
size_t i = 0; i < posts_list->
size; i++) {
6396 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE) || PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6402 if (keywords_list && keywords_list->
size) {
6403 for (
size_t i = 0; i < keywords_list->
size; i++) {
6405 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6411 if (parameters_node && parameters_node->
block && PM_NODE_TYPE_P(parameters_node->
block, PM_BLOCK_PARAMETER_NODE)) {
6414 if (PM_NODE_FLAG_P(block_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER) || !block_node->name) {
6422 local_table_for_iseq->size = table_size;
6426 pm_index_lookup_table_init(&index_lookup_table, (
int) pm_parser_constants_size(scope_node->parser), iseq);
6446 int local_index = 0;
6453 if (requireds_list && requireds_list->
size) {
6454 for (
size_t i = 0; i < requireds_list->
size; i++, local_index++) {
6462 switch (PM_NODE_TYPE(required)) {
6463 case PM_MULTI_TARGET_NODE: {
6466 local = rb_make_temporary_id(local_index);
6467 local_table_for_iseq->ids[local_index] = local;
6470 case PM_REQUIRED_PARAMETER_NODE: {
6475 if (PM_NODE_FLAG_P(required, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6476 ID local = pm_constant_id_lookup(scope_node, param->
name);
6477 local_table_for_iseq->ids[local_index] = local;
6480 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6486 rb_bug(
"Unsupported node in requireds in parameters %s", pm_node_type(PM_NODE_TYPE(required)));
6490 body->param.lead_num = (int) requireds_list->
size;
6491 body->param.flags.has_lead =
true;
6494 if (scope_node->parameters != NULL && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6495 local_table_for_iseq->ids[local_index++] = idItImplicit;
6500 if (optionals_list && optionals_list->
size) {
6501 body->param.opt_num = (int) optionals_list->
size;
6502 body->param.flags.has_opt =
true;
6504 for (
size_t i = 0; i < optionals_list->
size; i++, local_index++) {
6508 if (PM_NODE_FLAG_P(node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6509 ID local = pm_constant_id_lookup(scope_node, name);
6510 local_table_for_iseq->ids[local_index] = local;
6513 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6520 if (parameters_node && parameters_node->
rest) {
6521 body->param.rest_start = local_index;
6525 if (!(PM_NODE_TYPE_P(parameters_node->
rest, PM_IMPLICIT_REST_NODE))) {
6526 body->param.flags.has_rest =
true;
6534 if (PM_NODE_FLAG_P(parameters_node->
rest, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6535 ID local = pm_constant_id_lookup(scope_node, name);
6536 local_table_for_iseq->ids[local_index] = local;
6539 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6545 body->param.flags.anon_rest =
true;
6546 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index, &index_lookup_table, local_table_for_iseq);
6555 if (posts_list && posts_list->
size) {
6556 body->param.post_num = (int) posts_list->
size;
6557 body->param.post_start = local_index;
6558 body->param.flags.has_post =
true;
6560 for (
size_t i = 0; i < posts_list->
size; i++, local_index++) {
6568 switch (PM_NODE_TYPE(post_node)) {
6569 case PM_MULTI_TARGET_NODE: {
6572 local = rb_make_temporary_id(local_index);
6573 local_table_for_iseq->ids[local_index] = local;
6576 case PM_REQUIRED_PARAMETER_NODE: {
6581 if (PM_NODE_FLAG_P(param, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6582 ID local = pm_constant_id_lookup(scope_node, param->
name);
6583 local_table_for_iseq->ids[local_index] = local;
6586 pm_insert_local_index(param->
name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6591 rb_bug(
"Unsupported node in posts in parameters %s", pm_node_type(PM_NODE_TYPE(post_node)));
6599 if (keywords_list && keywords_list->
size) {
6600 keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6601 keyword->num = (int) keywords_list->
size;
6606 for (
size_t i = 0; i < keywords_list->
size; i++) {
6612 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_REQUIRED_KEYWORD_PARAMETER_NODE)) {
6614 keyword->required_num++;
6615 ID local = pm_constant_id_lookup(scope_node, name);
6617 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6618 local_table_for_iseq->ids[local_index] = local;
6621 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6627 for (
size_t i = 0; i < keywords_list->
size; i++) {
6633 if (PM_NODE_TYPE_P(keyword_parameter_node, PM_OPTIONAL_KEYWORD_PARAMETER_NODE)) {
6639 if (PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) {
6640 rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node));
6646 ID local = pm_constant_id_lookup(scope_node, name);
6647 if (PM_NODE_FLAG_P(keyword_parameter_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6648 local_table_for_iseq->ids[local_index] = local;
6651 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6661 for (
int i = 0; i <
RARRAY_LEN(default_values); i++) {
6663 if (dv == complex_mark) dv =
Qundef;
6667 keyword->default_values = dvs;
6671 keyword->bits_start = local_index;
6672 ID local = rb_make_temporary_id(local_index);
6673 local_table_for_iseq->ids[local_index] = local;
6676 body->param.keyword = keyword;
6677 body->param.flags.has_kw =
true;
6680 if (body->type == ISEQ_TYPE_BLOCK && local_index == 1 && requireds_list && requireds_list->
size == 1 && !trailing_comma) {
6681 body->param.flags.ambiguous_param0 =
true;
6684 if (parameters_node) {
6689 case PM_NO_KEYWORDS_PARAMETER_NODE: {
6692 body->param.flags.accepts_no_kwarg =
true;
6695 case PM_KEYWORD_REST_PARAMETER_NODE: {
6699 if (!body->param.flags.has_kw) {
6700 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6703 keyword->rest_start = local_index;
6704 body->param.flags.has_kwrest =
true;
6708 if (PM_NODE_FLAG_P(kw_rest_node, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6709 ID local = pm_constant_id_lookup(scope_node, constant_id);
6710 local_table_for_iseq->ids[local_index] = local;
6713 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6717 body->param.flags.anon_kwrest =
true;
6718 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index, &index_lookup_table, local_table_for_iseq);
6724 case PM_FORWARDING_PARAMETER_NODE: {
6727 if (!ISEQ_BODY(iseq)->param.
flags.forwardable) {
6729 body->param.rest_start = local_index;
6730 body->param.flags.has_rest =
true;
6731 body->param.flags.anon_rest =
true;
6732 pm_insert_local_special(PM_CONSTANT_MULT, idMULT, local_index++, &index_lookup_table, local_table_for_iseq);
6736 body->param.flags.has_kw =
false;
6737 body->param.flags.has_kwrest =
true;
6738 body->param.flags.anon_kwrest =
true;
6739 body->param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6740 keyword->rest_start = local_index;
6741 pm_insert_local_special(PM_CONSTANT_POW, idPow, local_index++, &index_lookup_table, local_table_for_iseq);
6744 body->param.block_start = local_index;
6745 body->param.flags.has_block =
true;
6746 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index++, &index_lookup_table, local_table_for_iseq);
6750 pm_insert_local_special(PM_CONSTANT_DOT3, idDot3, local_index++, &index_lookup_table, local_table_for_iseq);
6754 rb_bug(
"node type %s not expected as keyword_rest", pm_node_type(PM_NODE_TYPE(parameters_node->
keyword_rest)));
6760 if (parameters_node->
block) {
6761 switch (PM_NODE_TYPE(parameters_node->
block)) {
6762 case PM_BLOCK_PARAMETER_NODE: {
6763 body->param.block_start = local_index;
6764 body->param.flags.has_block =
true;
6766 iseq_set_use_block(iseq);
6771 if (PM_NODE_FLAG_P(parameters_node->
block, PM_PARAMETER_FLAGS_REPEATED_PARAMETER)) {
6772 ID local = pm_constant_id_lookup(scope_node, name);
6773 local_table_for_iseq->ids[local_index] = local;
6776 pm_insert_local_index(name, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6780 pm_insert_local_special(PM_CONSTANT_AND, idAnd, local_index, &index_lookup_table, local_table_for_iseq);
6786 case PM_NO_BLOCK_PARAMETER_NODE: {
6787 body->param.flags.accepts_no_block =
true;
6791 rb_bug(
"node type %s not expected as block parameter", pm_node_type(PM_NODE_TYPE(parameters_node->
block)));
6808 if (requireds_list && requireds_list->
size) {
6809 for (
size_t i = 0; i < requireds_list->
size; i++) {
6815 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6816 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);
6822 if (posts_list && posts_list->
size) {
6823 for (
size_t i = 0; i < posts_list->
size; i++) {
6829 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
6830 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);
6836 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
6837 if (PM_NODE_TYPE_P(((
const pm_for_node_t *) scope_node->ast_node)->index, PM_LOCAL_VARIABLE_TARGET_NODE)) {
6838 body->param.lead_num++;
6841 body->param.rest_start = local_index;
6842 body->param.flags.has_rest =
true;
6845 ID local = rb_make_temporary_id(local_index);
6846 local_table_for_iseq->ids[local_index] = local;
6851 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_NUMBERED_PARAMETERS_NODE)) {
6854 for (
int i = 0; i < maximum; i++, local_index++) {
6855 const uint8_t param_name[] = {
'_',
'1' + i };
6856 pm_constant_id_t constant_id = pm_parser_constant_find(scope_node->parser, param_name, 2);
6857 RUBY_ASSERT(constant_id &&
"parser should fill in any gaps in numbered parameters");
6858 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6860 body->param.lead_num = maximum;
6861 body->param.flags.has_lead =
true;
6865 if (scope_node->parameters && PM_NODE_TYPE_P(scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
6866 body->param.lead_num = 1;
6867 body->param.flags.has_lead =
true;
6878 if (block_locals && block_locals->
size) {
6879 for (
size_t i = 0; i < block_locals->
size; i++, local_index++) {
6881 pm_insert_local_index(constant_id, local_index, &index_lookup_table, local_table_for_iseq, scope_node);
6886 if (scope_node->locals.
size) {
6887 for (
size_t i = 0; i < scope_node->locals.
size; i++) {
6891 if (!pm_index_lookup_table_lookup(&index_lookup_table, constant_id, &existing)) {
6892 ID local = pm_constant_id_lookup(scope_node, constant_id);
6893 local_table_for_iseq->ids[local_index] = local;
6894 pm_index_lookup_table_insert(&index_lookup_table, constant_id, local_index);
6906 iseq_calc_param_size(iseq);
6908 if (ISEQ_BODY(iseq)->param.
flags.forwardable) {
6911 ISEQ_BODY(iseq)->param.size += 1;
6915 iseq_set_local_table(iseq, local_table_for_iseq, 0);
6916 iseq_set_parameters_lvar_state(iseq);
6918 scope_node->local_table_for_iseq_size = local_table_for_iseq->size;
6920 if (keyword != NULL) {
6921 size_t keyword_start_index = keyword->bits_start - keyword->num;
6922 keyword->table = (
ID *)&ISEQ_BODY(iseq)->local_table[keyword_start_index];
6927 if (optionals_list && optionals_list->
size) {
6935 for (
size_t i = 0; i < optionals_list->
size; i++) {
6936 label = NEW_LABEL(location.
line);
6937 opt_table[i] = label;
6938 PUSH_LABEL(ret, label);
6940 PM_COMPILE_NOT_POPPED(optional_node);
6944 label = NEW_LABEL(location.
line);
6945 opt_table[optionals_list->
size] = label;
6946 PUSH_LABEL(ret, label);
6948 body->param.opt_table = (
const VALUE *) opt_table;
6951 if (keywords_list && keywords_list->
size) {
6952 size_t optional_index = 0;
6953 for (
size_t i = 0; i < keywords_list->
size; i++) {
6957 switch (PM_NODE_TYPE(keyword_parameter_node)) {
6958 case PM_OPTIONAL_KEYWORD_PARAMETER_NODE: {
6966 if (!PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) {
6967 LABEL *end_label = NEW_LABEL(location.
line);
6970 int kw_bits_idx = table_size - body->param.keyword->bits_start;
6971 PUSH_INSN2(ret, location, checkkeyword,
INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1),
INT2FIX(optional_index));
6972 PUSH_INSNL(ret, location, branchif, end_label);
6974 PUSH_SETLOCAL(ret, location, index.index, index.level);
6975 PUSH_LABEL(ret, end_label);
6980 case PM_REQUIRED_KEYWORD_PARAMETER_NODE:
6985 rb_bug(
"Unexpected keyword parameter node type %s", pm_node_type(PM_NODE_TYPE(keyword_parameter_node)));
6990 if (requireds_list && requireds_list->
size) {
6991 for (
size_t i = 0; i < requireds_list->
size; i++) {
6997 if (PM_NODE_TYPE_P(required, PM_MULTI_TARGET_NODE)) {
6998 PUSH_GETLOCAL(ret, location, table_size - (
int)i, 0);
7004 if (posts_list && posts_list->
size) {
7005 for (
size_t i = 0; i < posts_list->
size; i++) {
7011 if (PM_NODE_TYPE_P(post, PM_MULTI_TARGET_NODE)) {
7012 PUSH_GETLOCAL(ret, location, table_size - body->param.post_start - (
int) i, 0);
7018 switch (body->type) {
7019 case ISEQ_TYPE_PLAIN: {
7020 RUBY_ASSERT(PM_NODE_TYPE_P(scope_node->ast_node, PM_INTERPOLATED_REGULAR_EXPRESSION_NODE));
7023 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
7027 case ISEQ_TYPE_BLOCK: {
7028 LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
7029 LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
7032 start->rescued = LABEL_RESCUE_BEG;
7033 end->rescued = LABEL_RESCUE_END;
7039 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_FOR_NODE)) {
7040 pm_compile_for_node_index(iseq, ((
const pm_for_node_t *) scope_node->ast_node)->index, ret, scope_node);
7044 PUSH_INSN(ret, block_location, nop);
7045 PUSH_LABEL(ret, start);
7047 if (scope_node->body != NULL) {
7048 switch (PM_NODE_TYPE(scope_node->ast_node)) {
7049 case PM_POST_EXECUTION_NODE: {
7051 PUSH_INSN1(ret, block_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7055 pm_scope_node_init((
const pm_node_t *) cast->statements, &next_scope_node, scope_node);
7057 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(body->parent_iseq), ISEQ_TYPE_BLOCK, location.
line);
7058 pm_scope_node_destroy(&next_scope_node);
7060 PUSH_CALL_WITH_BLOCK(ret, block_location, id_core_set_postexe,
INT2FIX(0), block);
7063 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
7065 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
7069 pm_compile_node(iseq, scope_node->body, ret, popped, scope_node);
7074 PUSH_INSN(ret, block_location, putnil);
7077 PUSH_LABEL(ret, end);
7079 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7082 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
7083 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
7086 case ISEQ_TYPE_ENSURE: {
7087 const pm_node_location_t statements_location = (scope_node->body != NULL ? PM_NODE_START_LOCATION(scope_node->body) : location);
7088 iseq_set_exception_local_table(iseq);
7090 if (scope_node->body != NULL) {
7091 PM_COMPILE_POPPED((
const pm_node_t *) scope_node->body);
7094 PUSH_GETLOCAL(ret, statements_location, 1, 0);
7095 PUSH_INSN1(ret, statements_location,
throw,
INT2FIX(0));
7098 case ISEQ_TYPE_METHOD: {
7099 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7102 if (scope_node->body) {
7103 PM_COMPILE((
const pm_node_t *) scope_node->body);
7106 PUSH_INSN(ret, location, putnil);
7109 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
7112 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
7115 case ISEQ_TYPE_RESCUE: {
7116 iseq_set_exception_local_table(iseq);
7117 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_RESCUE_MODIFIER_NODE)) {
7119 LABEL *rescue_end = NEW_LABEL(location.
line);
7120 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7122 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
7123 PUSH_INSNL(ret, location, branchif, lab);
7124 PUSH_INSNL(ret, location, jump, rescue_end);
7125 PUSH_LABEL(ret, lab);
7127 PM_COMPILE((
const pm_node_t *) scope_node->body);
7128 PUSH_INSN(ret, location, leave);
7129 PUSH_LABEL(ret, rescue_end);
7130 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
7133 PM_COMPILE((
const pm_node_t *) scope_node->ast_node);
7135 PUSH_INSN1(ret, location,
throw,
INT2FIX(0));
7140 if (scope_node->body) {
7141 PM_COMPILE((
const pm_node_t *) scope_node->body);
7144 PUSH_INSN(ret, location, putnil);
7149 if (PM_NODE_TYPE_P(scope_node->ast_node, PM_CLASS_NODE) || PM_NODE_TYPE_P(scope_node->ast_node, PM_MODULE_NODE)) {
7152 ISEQ_COMPILE_DATA(iseq)->last_line = end_location.
line;
7155 if (!PM_NODE_TYPE_P(scope_node->ast_node, PM_ENSURE_NODE)) {
7157 PUSH_INSN(ret, location, leave);
7166 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7170 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7171 PUSH_INSN1(ret, *location, putobject, operand);
7176 VALUE operand =
ID2SYM(rb_intern3((
const char *) (pm_parser_start(scope_node->parser) + name_loc->
start), name_loc->
length, scope_node->encoding));
7177 PUSH_INSN1(ret, *location, putobject, operand);
7180 PUSH_SEND(ret, *location, id_core_set_variable_alias,
INT2FIX(2));
7181 if (popped) PUSH_INSN(ret, *location, pop);
7187 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7188 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
7189 PM_COMPILE_NOT_POPPED(node->
new_name);
7190 PM_COMPILE_NOT_POPPED(node->
old_name);
7192 PUSH_SEND(ret, *location, id_core_set_method_alias,
INT2FIX(3));
7193 if (popped) PUSH_INSN(ret, *location, pop);
7199 LABEL *end_label = NEW_LABEL(location->
line);
7201 PM_COMPILE_NOT_POPPED(node->
left);
7202 if (!popped) PUSH_INSN(ret, *location, dup);
7203 PUSH_INSNL(ret, *location, branchunless, end_label);
7205 if (!popped) PUSH_INSN(ret, *location, pop);
7206 PM_COMPILE(node->
right);
7207 PUSH_LABEL(ret, end_label);
7215 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
7220 if (elements->
size) {
7221 VALUE value = pm_static_literal_value(iseq, node, scope_node);
7222 RB_OBJ_SET_FROZEN_SHAREABLE(value);
7223 PUSH_INSN1(ret, *location, duparray, value);
7226 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7244 const int max_new_array_size = 0x100;
7245 const unsigned int min_tmp_array_size = 0x40;
7247 int new_array_size = 0;
7248 bool first_chunk =
true;
7254 bool static_literal =
false;
7257#define FLUSH_CHUNK \
7258 if (new_array_size) { \
7259 if (first_chunk) PUSH_INSN1(ret, *location, newarray, INT2FIX(new_array_size)); \
7260 else PUSH_INSN1(ret, *location, pushtoarray, INT2FIX(new_array_size)); \
7261 first_chunk = false; \
7262 new_array_size = 0; \
7265 for (
size_t index = 0; index < elements->
size; index++) {
7268 if (PM_NODE_TYPE_P(element, PM_SPLAT_NODE)) {
7273 PM_COMPILE_NOT_POPPED(splat_element->
expression);
7276 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
7277 PUSH_GETLOCAL(ret, *location, index.index, index.level);
7283 PUSH_INSN1(ret, *location, splatarray,
Qtrue);
7284 first_chunk =
false;
7287 PUSH_INSN(ret, *location, concattoarray);
7290 static_literal =
false;
7292 else if (PM_NODE_TYPE_P(element, PM_KEYWORD_HASH_NODE)) {
7293 if (new_array_size == 0 && first_chunk) {
7294 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7295 first_chunk =
false;
7312 pm_compile_hash_elements(iseq, element, &keyword_hash->
elements, 0,
Qundef,
false, ret, scope_node);
7319 while (splats < keyword_hash->elements.
size && PM_NODE_TYPE_P(keyword_hash->
elements.
nodes[splats], PM_ASSOC_SPLAT_NODE)) splats++;
7322 PUSH_INSN(ret, *location, pushtoarraykwsplat);
7329 PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) &&
7330 !PM_CONTAINER_P(element) &&
7332 ((index + min_tmp_array_size) < elements->
size)
7337 size_t right_index = index + 1;
7339 right_index < elements->size &&
7340 PM_NODE_FLAG_P(elements->
nodes[right_index], PM_NODE_FLAG_STATIC_LITERAL) &&
7341 !PM_CONTAINER_P(elements->
nodes[right_index])
7344 size_t tmp_array_size = right_index - index;
7345 if (tmp_array_size >= min_tmp_array_size) {
7349 for (; tmp_array_size; tmp_array_size--)
7350 rb_ary_push(tmp_array, pm_static_literal_value(iseq, elements->
nodes[index++], scope_node));
7353 RB_OBJ_SET_FROZEN_SHAREABLE(tmp_array);
7358 PUSH_INSN1(ret, *location, duparray, tmp_array);
7359 first_chunk =
false;
7362 PUSH_INSN1(ret, *location, putobject, tmp_array);
7363 PUSH_INSN(ret, *location, concattoarray);
7367 PM_COMPILE_NOT_POPPED(element);
7368 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7369 static_literal =
true;
7372 PM_COMPILE_NOT_POPPED(element);
7373 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7374 static_literal =
false;
7379 if (popped) PUSH_INSN(ret, *location, pop);
7387 unsigned long throw_flag = 0;
7389 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
7391 LABEL *splabel = NEW_LABEL(0);
7392 PUSH_LABEL(ret, splabel);
7393 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7399 PUSH_INSN(ret, *location, putnil);
7402 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7403 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
7404 PUSH_ADJUST_RESTORE(ret, splabel);
7405 if (!popped) PUSH_INSN(ret, *location, putnil);
7411 if (!ISEQ_COMPILE_DATA(ip)) {
7416 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7417 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
7419 else if (ISEQ_BODY(ip)->type == ISEQ_TYPE_BLOCK) {
7422 else if (ISEQ_BODY(ip)->type == ISEQ_TYPE_EVAL) {
7423 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7427 ip = ISEQ_BODY(ip)->parent_iseq;
7436 PUSH_INSN(ret, *location, putnil);
7439 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_BREAK));
7440 if (popped) PUSH_INSN(ret, *location, pop);
7445 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7452 ID method_id = pm_constant_id_lookup(scope_node, node->
name);
7458 const char *builtin_func;
7460 if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && (builtin_func = pm_iseq_builtin_function_name(scope_node, node->
receiver, method_id)) != NULL) {
7461 pm_compile_builtin_function_call(iseq, ret, scope_node, node, &location, popped, ISEQ_COMPILE_DATA(iseq)->current_block, builtin_func);
7465 LABEL *start = NEW_LABEL(location.
line);
7466 if (node->
block) PUSH_LABEL(ret, start);
7468 switch (method_id) {
7470 if (pm_opt_str_freeze_p(iseq, node)) {
7472 const struct rb_callinfo *callinfo = new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE);
7473 PUSH_INSN2(ret, location, opt_str_uminus, value, callinfo);
7474 if (popped) PUSH_INSN(ret, location, pop);
7480 if (pm_opt_str_freeze_p(iseq, node)) {
7482 const struct rb_callinfo *callinfo = new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE);
7483 PUSH_INSN2(ret, location, opt_str_freeze, value, callinfo);
7484 if (popped) PUSH_INSN(ret, location, pop);
7491 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE) && !popped) {
7492 PUSH_INSN(ret, location, putnil);
7496 PUSH_INSN(ret, location, putself);
7499 if (method_id == idCall && PM_NODE_TYPE_P(node->
receiver, PM_LOCAL_VARIABLE_READ_NODE)) {
7504 if (iseq_block_param_id_p(iseq, pm_constant_id_lookup(scope_node, read_node_cast->name), &idx, &level)) {
7505 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)));
7508 PM_COMPILE_NOT_POPPED(node->
receiver);
7512 PM_COMPILE_NOT_POPPED(node->
receiver);
7516 pm_compile_call(iseq, node, ret, popped, scope_node, method_id, start);
7525 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY)) {
7526 flag = VM_CALL_FCALL;
7529 PM_COMPILE_NOT_POPPED(node->
receiver);
7531 LABEL *safe_label = NULL;
7532 if (PM_NODE_FLAG_P(node, PM_CALL_NODE_FLAGS_SAFE_NAVIGATION)) {
7533 safe_label = NEW_LABEL(location->
line);
7534 PUSH_INSN(ret, *location, dup);
7535 PUSH_INSNL(ret, *location, branchnil, safe_label);
7538 PUSH_INSN(ret, *location, dup);
7540 ID id_read_name = pm_constant_id_lookup(scope_node, node->
read_name);
7541 PUSH_SEND_WITH_FLAG(ret, *location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
7543 PM_COMPILE_NOT_POPPED(node->
value);
7545 PUSH_SEND(ret, *location, id_operator,
INT2FIX(1));
7548 PUSH_INSN(ret, *location, swap);
7549 PUSH_INSN1(ret, *location, topn,
INT2FIX(1));
7552 ID id_write_name = pm_constant_id_lookup(scope_node, node->
write_name);
7553 PUSH_SEND_WITH_FLAG(ret, *location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
7555 if (safe_label != NULL && popped) PUSH_LABEL(ret, safe_label);
7556 PUSH_INSN(ret, *location, pop);
7557 if (safe_label != NULL && !popped) PUSH_LABEL(ret, safe_label);
7580 switch (PM_NODE_TYPE(node)) {
7581 case PM_FLOAT_NODE: {
7582 key = pm_static_literal_value(iseq, node, scope_node);
7586 key = (
FIXABLE(intptr) ?
LONG2FIX((
long) intptr) : rb_dbl2big(intptr));
7592 case PM_INTEGER_NODE:
7594 case PM_SOURCE_FILE_NODE:
7595 case PM_SOURCE_LINE_NODE:
7596 case PM_SYMBOL_NODE:
7598 key = pm_static_literal_value(iseq, node, scope_node);
7600 case PM_STRING_NODE: {
7602 key = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
7609 if (
NIL_P(rb_hash_lookup(dispatch, key))) {
7610 rb_hash_aset(dispatch, key, ((
VALUE) label) | 1);
7627 DECL_ANCHOR(cond_seq);
7632 DECL_ANCHOR(body_seq);
7636 LABEL *end_label = NEW_LABEL(location.
line);
7647 if (PM_BRANCH_COVERAGE_P(iseq)) {
7648 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7649 branches = decl_branch_base(iseq, PTR2NUM(cast), &case_location,
"case");
7655 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7659 int clause_lineno = pm_node_line_number_cached((
const pm_node_t *) clause, scope_node);
7660 LABEL *label = NEW_LABEL(clause_lineno);
7661 PUSH_LABEL(body_seq, label);
7664 if (PM_BRANCH_COVERAGE_P(iseq)) {
7666 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7669 if (clause->statements != NULL) {
7670 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7673 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7676 PUSH_INSNL(body_seq, location, jump, end_label);
7681 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7684 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7686 PUSH_INSN(cond_seq, cond_location, putnil);
7687 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7688 PUSH_INSN1(cond_seq, cond_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
7689 PUSH_INSNL(cond_seq, cond_location, branchif, label);
7692 LABEL *next_label = NEW_LABEL(pm_node_line_number_cached(condition, scope_node));
7693 pm_compile_branch_condition(iseq, cond_seq, condition, label, next_label, scope_node);
7694 PUSH_LABEL(cond_seq, next_label);
7701 if (PM_BRANCH_COVERAGE_P(iseq)) {
7705 branch_location = case_location;
7712 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7720 PUSH_SYNTHETIC_PUTNIL(cond_seq, iseq);
7725 PUSH_INSNL(cond_seq, location, jump, end_label);
7726 PUSH_SEQ(ret, cond_seq);
7734 if (PM_BRANCH_COVERAGE_P(iseq)) {
7735 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7736 branches = decl_branch_base(iseq, PTR2NUM(cast), &case_location,
"case");
7741 LABEL *else_label = NEW_LABEL(location.
line);
7749 if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
7750 dispatch = rb_hash_new();
7751 RHASH_TBL_RAW(dispatch)->type = &cdhash_type;
7762 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7767 LABEL *label = NEW_LABEL(clause_location.
line);
7772 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7779 if (dispatch !=
Qundef) {
7780 dispatch = pm_compile_case_node_dispatch(iseq, dispatch, condition, label, scope_node);
7783 if (PM_NODE_TYPE_P(condition, PM_SPLAT_NODE)) {
7784 PUSH_INSN(cond_seq, condition_location, dup);
7785 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7786 PUSH_INSN1(cond_seq, condition_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
7789 if (PM_NODE_TYPE_P(condition, PM_STRING_NODE)) {
7791 VALUE value = parse_static_literal_string(iseq, scope_node, condition, &string->
unescaped);
7792 PUSH_INSN1(cond_seq, condition_location, putobject, value);
7795 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7798 PUSH_INSN1(cond_seq, condition_location, topn,
INT2FIX(1));
7799 PUSH_SEND_WITH_FLAG(cond_seq, condition_location, idEqq,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
7802 PUSH_INSNL(cond_seq, condition_location, branchif, label);
7809 PUSH_LABEL(body_seq, label);
7810 PUSH_INSN(body_seq, clause_location, pop);
7813 if (PM_BRANCH_COVERAGE_P(iseq)) {
7815 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7818 if (clause->statements != NULL) {
7819 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7822 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7825 PUSH_INSNL(body_seq, clause_location, jump, end_label);
7836 if (dispatch !=
Qundef) {
7837 PUSH_INSN(ret, location, dup);
7838 RB_OBJ_SET_SHAREABLE(dispatch);
7839 PUSH_INSN2(ret, location, opt_case_dispatch, dispatch, else_label);
7840 LABEL_REF(else_label);
7843 PUSH_SEQ(ret, cond_seq);
7847 PUSH_LABEL(ret, else_label);
7851 PUSH_INSN(ret, else_location, pop);
7854 if (PM_BRANCH_COVERAGE_P(iseq)) {
7856 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7860 PUSH_INSNL(ret, else_location, jump, end_label);
7863 PUSH_INSN(ret, location, pop);
7866 if (PM_BRANCH_COVERAGE_P(iseq)) {
7867 add_trace_branch_coverage(iseq, ret, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7870 if (!popped) PUSH_INSN(ret, location, putnil);
7871 PUSH_INSNL(ret, location, jump, end_label);
7875 PUSH_SEQ(ret, body_seq);
7876 PUSH_LABEL(ret, end_label);
7885 DECL_ANCHOR(body_seq);
7890 DECL_ANCHOR(cond_seq);
7894 LABEL *end_label = NEW_LABEL(location->
line);
7899 LABEL *else_label = NEW_LABEL(location->
line);
7907 if (PM_BRANCH_COVERAGE_P(iseq)) {
7908 case_location = pm_code_location(scope_node, (
const pm_node_t *) node);
7909 branches = decl_branch_base(iseq, PTR2NUM(node), &case_location,
"case");
7919 if (in_single_pattern) {
7920 PUSH_INSN(ret, *location, putnil);
7921 PUSH_INSN(ret, *location, putnil);
7922 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7923 PUSH_INSN(ret, *location, putnil);
7927 PUSH_INSN(ret, *location, putnil);
7936 RUBY_ASSERT(PM_NODE_TYPE_P(condition, PM_IN_NODE));
7943 PUSH_INSN(body_seq, in_location, putnil);
7946 LABEL *body_label = NEW_LABEL(in_location.
line);
7947 PUSH_LABEL(body_seq, body_label);
7948 PUSH_INSN1(body_seq, in_location, adjuststack,
INT2FIX(in_single_pattern ? 6 : 2));
7951 if (PM_BRANCH_COVERAGE_P(iseq)) {
7953 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"in", branches);
7960 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7963 PUSH_INSNL(body_seq, in_location, jump, end_label);
7964 LABEL *next_pattern_label = NEW_LABEL(pattern_location.
line);
7966 PUSH_INSN(cond_seq, pattern_location, dup);
7967 pm_compile_pattern(iseq, scope_node, in_node->
pattern, cond_seq, body_label, next_pattern_label, in_single_pattern,
true, 2);
7968 PUSH_LABEL(cond_seq, next_pattern_label);
7969 LABEL_UNREMOVABLE(next_pattern_label);
7978 PUSH_LABEL(cond_seq, else_label);
7979 PUSH_INSN(cond_seq, *location, pop);
7980 PUSH_INSN(cond_seq, *location, pop);
7983 if (PM_BRANCH_COVERAGE_P(iseq)) {
7985 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7988 PM_COMPILE_INTO_ANCHOR(cond_seq, (
const pm_node_t *) else_node);
7989 PUSH_INSNL(cond_seq, *location, jump, end_label);
7990 PUSH_INSN(cond_seq, *location, putnil);
7991 if (popped) PUSH_INSN(cond_seq, *location, putnil);
7996 PUSH_LABEL(cond_seq, else_label);
7999 add_trace_branch_coverage(iseq, cond_seq, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
8001 if (in_single_pattern) {
8002 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, cond_seq, end_label, popped);
8005 PUSH_INSN1(cond_seq, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8007 PUSH_INSN1(cond_seq, *location, topn,
INT2FIX(2));
8008 PUSH_SEND(cond_seq, *location, id_core_raise,
INT2FIX(2));
8010 PUSH_INSN1(cond_seq, *location, adjuststack,
INT2FIX(3));
8011 if (!popped) PUSH_INSN(cond_seq, *location, putnil);
8012 PUSH_INSNL(cond_seq, *location, jump, end_label);
8013 PUSH_INSN1(cond_seq, *location, dupn,
INT2FIX(1));
8014 if (popped) PUSH_INSN(cond_seq, *location, putnil);
8021 PUSH_SEQ(ret, cond_seq);
8022 PUSH_SEQ(ret, body_seq);
8023 PUSH_LABEL(ret, end_label);
8031 LABEL *retry_label = NULL;
8032 LABEL *retry_end_l = NULL;
8034 if (node->
block != NULL) {
8035 previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8036 ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
8038 retry_label = NEW_LABEL(location->
line);
8039 retry_end_l = NEW_LABEL(location->
line);
8041 PUSH_LABEL(ret, retry_label);
8044 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8047 PUSH_INSN(ret, *location, putself);
8048 int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
8050 if (node->
block != NULL) {
8052 pm_scope_node_init((
const pm_node_t *) node->
block, &next_scope_node, scope_node);
8054 ISEQ_COMPILE_DATA(iseq)->current_block = block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8055 pm_scope_node_destroy(&next_scope_node);
8062 const rb_iseq_t *local_iseq = body->local_iseq;
8066 int depth = get_lvar_level(iseq);
8068 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8069 flag |= VM_CALL_FORWARDING;
8070 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
8071 PUSH_GETLOCAL(ret, *location, mult_local.index, mult_local.level);
8073 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, 0, flag, NULL, block != NULL);
8074 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, block);
8076 if (popped) PUSH_INSN(ret, *location, pop);
8078 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8083 if (local_body->param.flags.has_lead) {
8085 for (
int i = 0; i < local_body->param.lead_num; i++) {
8086 int idx = local_body->local_table_size - i;
8087 PUSH_GETLOCAL(args, *location, idx, depth);
8089 argc += local_body->param.lead_num;
8092 if (local_body->param.flags.has_opt) {
8094 for (
int j = 0; j < local_body->param.opt_num; j++) {
8095 int idx = local_body->local_table_size - (argc + j);
8096 PUSH_GETLOCAL(args, *location, idx, depth);
8098 argc += local_body->param.opt_num;
8101 if (local_body->param.flags.has_rest) {
8103 int idx = local_body->local_table_size - local_body->param.rest_start;
8104 PUSH_GETLOCAL(args, *location, idx, depth);
8105 PUSH_INSN1(args, *location, splatarray,
Qfalse);
8107 argc = local_body->param.rest_start + 1;
8108 flag |= VM_CALL_ARGS_SPLAT;
8111 if (local_body->param.flags.has_post) {
8113 int post_len = local_body->param.post_num;
8114 int post_start = local_body->param.post_start;
8117 for (; j < post_len; j++) {
8118 int idx = local_body->local_table_size - (post_start + j);
8119 PUSH_GETLOCAL(args, *location, idx, depth);
8122 if (local_body->param.flags.has_rest) {
8124 PUSH_INSN1(args, *location, newarray,
INT2FIX(j));
8125 PUSH_INSN(args, *location, concatarray);
8128 argc = post_len + post_start;
8132 const struct rb_iseq_param_keyword *
const local_keyword = local_body->param.keyword;
8133 if (local_body->param.flags.has_kw) {
8134 int local_size = local_body->local_table_size;
8137 PUSH_INSN1(args, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8139 if (local_body->param.flags.has_kwrest) {
8140 int idx = local_body->local_table_size - local_keyword->rest_start;
8141 PUSH_GETLOCAL(args, *location, idx, depth);
8143 PUSH_SEND(args, *location, rb_intern(
"dup"),
INT2FIX(0));
8146 PUSH_INSN1(args, *location, newhash,
INT2FIX(0));
8149 for (; i < local_keyword->num; ++i) {
8150 ID id = local_keyword->table[i];
8151 int idx = local_size - get_local_var_idx(local_iseq,
id);
8155 PUSH_INSN1(args, *location, putobject, operand);
8158 PUSH_GETLOCAL(args, *location, idx, depth);
8161 PUSH_SEND(args, *location, id_core_hash_merge_ptr,
INT2FIX(i * 2 + 1));
8162 flag |= VM_CALL_KW_SPLAT| VM_CALL_KW_SPLAT_MUT;
8164 else if (local_body->param.flags.has_kwrest) {
8165 int idx = local_body->local_table_size - local_keyword->rest_start;
8166 PUSH_GETLOCAL(args, *location, idx, depth);
8168 flag |= VM_CALL_KW_SPLAT;
8171 PUSH_SEQ(ret, args);
8174 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flag, NULL, block != NULL);
8175 PUSH_INSN2(ret, *location, invokesuper, callinfo, block);
8178 if (node->
block != NULL) {
8179 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8180 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, block, retry_end_l);
8181 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8184 if (popped) PUSH_INSN(ret, *location, pop);
8190 LABEL *matched_label = NEW_LABEL(location->
line);
8191 LABEL *unmatched_label = NEW_LABEL(location->
line);
8192 LABEL *done_label = NEW_LABEL(location->
line);
8196 PUSH_INSN(ret, *location, putnil);
8197 PUSH_INSN(ret, *location, putnil);
8198 PUSH_INSN1(ret, *location, putobject,
Qfalse);
8199 PUSH_INSN(ret, *location, putnil);
8200 PUSH_INSN(ret, *location, putnil);
8204 PM_COMPILE_NOT_POPPED(node->
value);
8208 PUSH_INSN(ret, *location, dup);
8215 pm_compile_pattern(iseq, scope_node, node->
pattern, ret, matched_label, unmatched_label,
true,
true, 2);
8220 PUSH_LABEL(ret, unmatched_label);
8221 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, ret, done_label, popped);
8225 PUSH_LABEL(ret, matched_label);
8226 PUSH_INSN1(ret, *location, adjuststack,
INT2FIX(6));
8227 if (!popped) PUSH_INSN(ret, *location, putnil);
8228 PUSH_INSNL(ret, *location, jump, done_label);
8230 PUSH_LABEL(ret, done_label);
8236 LABEL *fail_label = NEW_LABEL(location->
line);
8237 LABEL *end_label = NEW_LABEL(location->
line);
8248 PUSH_INSN1(ret, *location, getglobal, operand);
8251 PUSH_INSN(ret, *location, dup);
8252 PUSH_INSNL(ret, *location, branchunless, fail_label);
8258 if (targets_count == 1) {
8260 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8267 PUSH_INSN1(ret, *location, putobject, operand);
8270 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8271 PUSH_LABEL(ret, fail_label);
8272 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8273 if (popped) PUSH_INSN(ret, *location, pop);
8277 DECL_ANCHOR(fail_anchor);
8281 for (
size_t targets_index = 0; targets_index < targets_count; targets_index++) {
8283 RUBY_ASSERT(PM_NODE_TYPE_P(target, PM_LOCAL_VARIABLE_TARGET_NODE));
8288 if (((
size_t) targets_index) < (targets_count - 1)) {
8289 PUSH_INSN(ret, *location, dup);
8294 PUSH_INSN1(ret, *location, putobject, operand);
8297 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8298 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8300 PUSH_INSN(fail_anchor, *location, putnil);
8301 PUSH_SETLOCAL(fail_anchor, *location, index.index, index.level);
8305 PUSH_INSNL(ret, *location, jump, end_label);
8309 PUSH_LABEL(ret, fail_label);
8310 PUSH_INSN(ret, *location, pop);
8311 PUSH_SEQ(ret, fail_anchor);
8314 PUSH_LABEL(ret, end_label);
8315 if (popped) PUSH_INSN(ret, *location, pop);
8321 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
8322 LABEL *splabel = NEW_LABEL(0);
8323 PUSH_LABEL(ret, splabel);
8329 PUSH_INSN(ret, *location, putnil);
8331 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8333 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8334 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8336 PUSH_ADJUST_RESTORE(ret, splabel);
8337 if (!popped) PUSH_INSN(ret, *location, putnil);
8339 else if (ISEQ_COMPILE_DATA(iseq)->end_label && can_add_ensure_iseq(iseq)) {
8340 LABEL *splabel = NEW_LABEL(0);
8342 PUSH_LABEL(ret, splabel);
8343 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8349 PUSH_INSN(ret, *location, putnil);
8352 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8353 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
8354 PUSH_ADJUST_RESTORE(ret, splabel);
8355 splabel->unremovable = FALSE;
8357 if (!popped) PUSH_INSN(ret, *location, putnil);
8361 unsigned long throw_flag = 0;
8364 if (!ISEQ_COMPILE_DATA(ip)) {
8369 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
8370 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8374 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8377 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8378 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8382 ip = ISEQ_BODY(ip)->parent_iseq;
8390 PUSH_INSN(ret, *location, putnil);
8393 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_NEXT));
8394 if (popped) PUSH_INSN(ret, *location, pop);
8397 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8405 if (ISEQ_COMPILE_DATA(iseq)->redo_label && can_add_ensure_iseq(iseq)) {
8406 LABEL *splabel = NEW_LABEL(0);
8408 PUSH_LABEL(ret, splabel);
8409 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8410 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8412 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
8413 PUSH_ADJUST_RESTORE(ret, splabel);
8414 if (!popped) PUSH_INSN(ret, *location, putnil);
8416 else if (ISEQ_BODY(iseq)->
type != ISEQ_TYPE_EVAL && ISEQ_COMPILE_DATA(iseq)->start_label && can_add_ensure_iseq(iseq)) {
8417 LABEL *splabel = NEW_LABEL(0);
8419 PUSH_LABEL(ret, splabel);
8420 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8421 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8423 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8424 PUSH_ADJUST_RESTORE(ret, splabel);
8425 if (!popped) PUSH_INSN(ret, *location, putnil);
8431 if (!ISEQ_COMPILE_DATA(ip)) {
8436 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8439 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8442 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8443 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8447 ip = ISEQ_BODY(ip)->parent_iseq;
8451 PUSH_INSN(ret, *location, putnil);
8452 PUSH_INSN1(ret, *location,
throw,
INT2FIX(VM_THROW_NO_ESCAPE_FLAG | TAG_REDO));
8453 if (popped) PUSH_INSN(ret, *location, pop);
8456 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8464 iseq_set_exception_local_table(iseq);
8468 LABEL *exception_match_label = NEW_LABEL(location->
line);
8469 LABEL *rescue_end_label = NEW_LABEL(location->
line);
8479 if (exceptions->
size > 0) {
8480 for (
size_t index = 0; index < exceptions->
size; index++) {
8481 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8482 PM_COMPILE(exceptions->
nodes[index]);
8483 int checkmatch_flags = VM_CHECKMATCH_TYPE_RESCUE;
8484 if (PM_NODE_TYPE_P(exceptions->
nodes[index], PM_SPLAT_NODE)) {
8485 checkmatch_flags |= VM_CHECKMATCH_ARRAY;
8487 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(checkmatch_flags));
8488 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8492 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8494 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
8495 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8500 PUSH_INSNL(ret, *location, jump, rescue_end_label);
8505 PUSH_LABEL(ret, exception_match_label);
8512 DECL_ANCHOR(writes);
8513 DECL_ANCHOR(cleanup);
8515 pm_compile_target_node(iseq, node->
reference, ret, writes, cleanup, scope_node, NULL);
8516 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8518 PUSH_SEQ(ret, writes);
8519 PUSH_SEQ(ret, cleanup);
8529 LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
8530 ISEQ_COMPILE_DATA(iseq)->end_label = NULL;
8535 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
8538 PUSH_INSN(ret, *location, putnil);
8541 PUSH_INSN(ret, *location, leave);
8547 PUSH_LABEL(ret, rescue_end_label);
8552 PUSH_GETLOCAL(ret, *location, 1, 0);
8560 enum rb_iseq_type
type = ISEQ_BODY(iseq)->type;
8564 enum rb_iseq_type parent_type = ISEQ_BODY(parent_iseq)->type;
8565 while (parent_type == ISEQ_TYPE_RESCUE || parent_type == ISEQ_TYPE_ENSURE) {
8566 if (!(parent_iseq = ISEQ_BODY(parent_iseq)->parent_iseq))
break;
8567 parent_type = ISEQ_BODY(parent_iseq)->type;
8570 switch (parent_type) {
8572 case ISEQ_TYPE_MAIN:
8574 rb_warn(
"argument of top-level return is ignored");
8576 if (parent_iseq == iseq) {
8577 type = ISEQ_TYPE_METHOD;
8584 if (
type == ISEQ_TYPE_METHOD) {
8585 splabel = NEW_LABEL(0);
8586 PUSH_LABEL(ret, splabel);
8587 PUSH_ADJUST(ret, *location, 0);
8590 if (arguments != NULL) {
8591 PM_COMPILE_NOT_POPPED((
const pm_node_t *) arguments);
8594 PUSH_INSN(ret, *location, putnil);
8597 if (
type == ISEQ_TYPE_METHOD && can_add_ensure_iseq(iseq)) {
8598 pm_add_ensure_iseq(ret, iseq, 1, scope_node);
8600 PUSH_INSN(ret, *location, leave);
8601 PUSH_ADJUST_RESTORE(ret, splabel);
8602 if (!popped) PUSH_INSN(ret, *location, putnil);
8605 PUSH_INSN1(ret, *location,
throw,
INT2FIX(TAG_RETURN));
8606 if (popped) PUSH_INSN(ret, *location, pop);
8615 LABEL *retry_label = NEW_LABEL(location->
line);
8616 LABEL *retry_end_l = NEW_LABEL(location->
line);
8618 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8620 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NULL;
8622 PUSH_LABEL(ret, retry_label);
8623 PUSH_INSN(ret, *location, putself);
8627 int argc = pm_setup_args(node->
arguments, node->
block, &flags, &keywords, iseq, ret, scope_node, location);
8628 bool is_forwardable = (node->
arguments != NULL) && PM_NODE_FLAG_P(node->
arguments, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING);
8629 flags |= VM_CALL_SUPER | VM_CALL_FCALL;
8631 if (node->
block && PM_NODE_TYPE_P(node->
block, PM_BLOCK_NODE)) {
8633 pm_scope_node_init(node->
block, &next_scope_node, scope_node);
8635 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8636 pm_scope_node_destroy(&next_scope_node);
8640 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8643 if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
8644 PUSH_INSN(args, *location, splatkw);
8647 PUSH_SEQ(ret, args);
8648 if (is_forwardable && ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8649 flags |= VM_CALL_FORWARDING;
8652 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8653 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, current_block);
8658 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8659 PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
8664 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8666 if (popped) PUSH_INSN(ret, *location, pop);
8667 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8668 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);
8674 switch (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
type) {
8676 case ISEQ_TYPE_MAIN:
8677 case ISEQ_TYPE_CLASS:
8678 COMPILE_ERROR(iseq, location->
line,
"Invalid yield");
8688 argc = pm_setup_args(node->
arguments, NULL, &flags, &keywords, iseq, ret, scope_node, location);
8691 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, FALSE);
8692 PUSH_INSN1(ret, *location, invokeblock, callinfo);
8694 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8695 if (popped) PUSH_INSN(ret, *location, pop);
8698 for (
const rb_iseq_t *tmp_iseq = iseq; tmp_iseq != ISEQ_BODY(iseq)->local_iseq; level++) {
8699 tmp_iseq = ISEQ_BODY(tmp_iseq)->parent_iseq;
8702 if (level > 0) access_outer_variables(iseq, level, rb_intern(
"yield"),
true);
8719 int lineno = (int) location.
line;
8721 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)) {
8726 lineno = (int) PM_NODE_START_LINE_COLUMN(((
const pm_begin_node_t *) node)->rescue_clause).line;
8729 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_NEWLINE) && ISEQ_COMPILE_DATA(iseq)->last_line != lineno) {
8735 ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8736 if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8737 event |= RUBY_EVENT_COVERAGE_LINE;
8739 PUSH_TRACE(ret, event);
8742 switch (PM_NODE_TYPE(node)) {
8743 case PM_ALIAS_GLOBAL_VARIABLE_NODE:
8748 case PM_ALIAS_METHOD_NODE:
8751 pm_compile_alias_method_node(iseq, (
const pm_alias_method_node_t *) node, &location, ret, popped, scope_node);
8756 pm_compile_and_node(iseq, (
const pm_and_node_t *) node, &location, ret, popped, scope_node);
8758 case PM_ARGUMENTS_NODE: {
8768 if (elements->
size == 1) {
8771 PM_COMPILE(elements->
nodes[0]);
8774 pm_compile_array_node(iseq, (
const pm_node_t *) cast, elements, &location, ret, popped, scope_node);
8778 case PM_ARRAY_NODE: {
8782 pm_compile_array_node(iseq, (
const pm_node_t *) cast, &cast->elements, &location, ret, popped, scope_node);
8785 case PM_ASSOC_NODE: {
8793 PM_COMPILE(cast->
key);
8794 PM_COMPILE(cast->
value);
8798 case PM_ASSOC_SPLAT_NODE: {
8806 if (cast->
value != NULL) {
8807 PM_COMPILE(cast->
value);
8810 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
8811 PUSH_GETLOCAL(ret, location, index.index, index.level);
8816 case PM_BACK_REFERENCE_READ_NODE: {
8821 VALUE backref = pm_compile_back_reference_ref(scope_node, cast);
8823 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), backref);
8827 case PM_BEGIN_NODE: {
8835 pm_compile_ensure(iseq, cast, &location, ret, popped, scope_node);
8839 pm_compile_rescue(iseq, cast, &location, ret, popped, scope_node);
8848 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8853 case PM_BLOCK_ARGUMENT_NODE: {
8863 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
8864 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(local_index.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(local_index.level));
8874 pm_compile_break_node(iseq, (
const pm_break_node_t *) node, &location, ret, popped, scope_node);
8885 pm_compile_call_node(iseq, (
const pm_call_node_t *) node, ret, popped, scope_node);
8887 case PM_CALL_AND_WRITE_NODE: {
8891 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);
8894 case PM_CALL_OR_WRITE_NODE: {
8898 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);
8901 case PM_CALL_OPERATOR_WRITE_NODE:
8916 pm_compile_case_node(iseq, (
const pm_case_node_t *) node, &location, ret, popped, scope_node);
8918 case PM_CASE_MATCH_NODE:
8927 pm_compile_case_match_node(iseq, (
const pm_case_match_node_t *) node, &location, ret, popped, scope_node);
8929 case PM_CLASS_NODE: {
8934 ID class_id = pm_constant_id_lookup(scope_node, cast->
name);
8935 VALUE class_name =
rb_str_freeze(rb_sprintf(
"<class:%"PRIsVALUE
">", rb_id2str(class_id)));
8938 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
8940 const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(&next_scope_node, class_name, ISEQ_TYPE_CLASS, location.
line);
8941 pm_scope_node_destroy(&next_scope_node);
8944 const int flags = VM_DEFINECLASS_TYPE_CLASS |
8945 (cast->
superclass ? VM_DEFINECLASS_FLAG_HAS_SUPERCLASS : 0) |
8946 pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
8952 PUSH_INSN(ret, location, putnil);
8957 PUSH_INSN3(ret, location, defineclass, operand, class_iseq,
INT2FIX(flags));
8961 if (popped) PUSH_INSN(ret, location, pop);
8964 case PM_CLASS_VARIABLE_AND_WRITE_NODE: {
8968 LABEL *end_label = NEW_LABEL(location.
line);
8970 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8973 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8974 if (!popped) PUSH_INSN(ret, location, dup);
8976 PUSH_INSNL(ret, location, branchunless, end_label);
8977 if (!popped) PUSH_INSN(ret, location, pop);
8979 PM_COMPILE_NOT_POPPED(cast->
value);
8980 if (!popped) PUSH_INSN(ret, location, dup);
8982 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8983 PUSH_LABEL(ret, end_label);
8987 case PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE: {
8992 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8995 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8996 PM_COMPILE_NOT_POPPED(cast->
value);
8999 int flags = VM_CALL_ARGS_SIMPLE;
9000 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9002 if (!popped) PUSH_INSN(ret, location, dup);
9003 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9007 case PM_CLASS_VARIABLE_OR_WRITE_NODE: {
9011 LABEL *end_label = NEW_LABEL(location.
line);
9012 LABEL *start_label = NEW_LABEL(location.
line);
9014 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9017 PUSH_INSN(ret, location, putnil);
9018 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name,
Qtrue);
9019 PUSH_INSNL(ret, location, branchunless, start_label);
9021 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
9022 if (!popped) PUSH_INSN(ret, location, dup);
9024 PUSH_INSNL(ret, location, branchif, end_label);
9025 if (!popped) PUSH_INSN(ret, location, pop);
9027 PUSH_LABEL(ret, start_label);
9028 PM_COMPILE_NOT_POPPED(cast->
value);
9029 if (!popped) PUSH_INSN(ret, location, dup);
9031 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
9032 PUSH_LABEL(ret, end_label);
9036 case PM_CLASS_VARIABLE_READ_NODE: {
9041 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9042 PUSH_INSN2(ret, location, getclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9046 case PM_CLASS_VARIABLE_WRITE_NODE: {
9050 PM_COMPILE_NOT_POPPED(cast->
value);
9051 if (!popped) PUSH_INSN(ret, location, dup);
9053 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9054 PUSH_INSN2(ret, location, setclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
9058 case PM_CONSTANT_PATH_NODE: {
9063 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache && ((parts = pm_constant_path_parts(node, scope_node)) !=
Qnil)) {
9064 ISEQ_BODY(iseq)->ic_size++;
9065 RB_OBJ_SET_SHAREABLE(parts);
9066 PUSH_INSN1(ret, location, opt_getconstant_path, parts);
9069 DECL_ANCHOR(prefix);
9072 pm_compile_constant_path(iseq, node, prefix, body, popped, scope_node);
9073 if (LIST_INSN_SIZE_ZERO(prefix)) {
9074 PUSH_INSN(ret, location, putnil);
9077 PUSH_SEQ(ret, prefix);
9080 PUSH_SEQ(ret, body);
9083 if (popped) PUSH_INSN(ret, location, pop);
9086 case PM_CONSTANT_PATH_AND_WRITE_NODE: {
9090 pm_compile_constant_path_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9093 case PM_CONSTANT_PATH_OR_WRITE_NODE: {
9097 pm_compile_constant_path_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9100 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE: {
9104 pm_compile_constant_path_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9107 case PM_CONSTANT_PATH_WRITE_NODE: {
9111 pm_compile_constant_path_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9114 case PM_CONSTANT_READ_NODE: {
9120 pm_compile_constant_read(iseq, name, &cast->
base.
location, location.
node_id, ret, scope_node);
9121 if (popped) PUSH_INSN(ret, location, pop);
9125 case PM_CONSTANT_AND_WRITE_NODE: {
9129 pm_compile_constant_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9132 case PM_CONSTANT_OR_WRITE_NODE: {
9136 pm_compile_constant_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9139 case PM_CONSTANT_OPERATOR_WRITE_NODE: {
9143 pm_compile_constant_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9146 case PM_CONSTANT_WRITE_NODE: {
9150 pm_compile_constant_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9160 ID method_name = pm_constant_id_lookup(scope_node, cast->
name);
9163 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9165 rb_iseq_t *method_iseq = NEW_ISEQ(&next_scope_node, rb_id2str(method_name), ISEQ_TYPE_METHOD, location.
line);
9166 pm_scope_node_destroy(&next_scope_node);
9169 PM_COMPILE_NOT_POPPED(cast->
receiver);
9170 PUSH_INSN2(ret, location, definesmethod,
ID2SYM(method_name), method_iseq);
9173 PUSH_INSN2(ret, location, definemethod,
ID2SYM(method_name), method_iseq);
9178 PUSH_INSN1(ret, location, putobject,
ID2SYM(method_name));
9183 case PM_DEFINED_NODE: {
9187 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
false);
9190 case PM_EMBEDDED_STATEMENTS_NODE: {
9199 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9202 if (popped) PUSH_INSN(ret, location, pop);
9205 case PM_EMBEDDED_VARIABLE_NODE: {
9212 case PM_FALSE_NODE: {
9216 PUSH_INSN1(ret, location, putobject,
Qfalse);
9220 case PM_ENSURE_NODE: {
9229 case PM_ELSE_NODE: {
9238 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9243 case PM_FLIP_FLOP_NODE: {
9248 LABEL *final_label = NEW_LABEL(location.
line);
9249 LABEL *then_label = NEW_LABEL(location.
line);
9250 LABEL *else_label = NEW_LABEL(location.
line);
9252 pm_compile_flip_flop(cast, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
9254 PUSH_LABEL(ret, then_label);
9255 PUSH_INSN1(ret, location, putobject,
Qtrue);
9256 PUSH_INSNL(ret, location, jump, final_label);
9257 PUSH_LABEL(ret, else_label);
9258 PUSH_INSN1(ret, location, putobject,
Qfalse);
9259 PUSH_LABEL(ret, final_label);
9263 case PM_FLOAT_NODE: {
9268 PUSH_INSN1(ret, location, putobject, operand);
9277 LABEL *retry_label = NEW_LABEL(location.
line);
9278 LABEL *retry_end_l = NEW_LABEL(location.
line);
9281 PUSH_LABEL(ret, retry_label);
9287 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9289 const rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location.
line);
9290 pm_scope_node_destroy(&next_scope_node);
9292 const rb_iseq_t *prev_block = ISEQ_COMPILE_DATA(iseq)->current_block;
9293 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
9297 PUSH_SEND_WITH_BLOCK(ret, location, idEach,
INT2FIX(0), child_iseq);
9298 pm_compile_retry_end_label(iseq, ret, retry_end_l);
9300 if (popped) PUSH_INSN(ret, location, pop);
9301 ISEQ_COMPILE_DATA(iseq)->current_block = prev_block;
9302 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
9305 case PM_FORWARDING_ARGUMENTS_NODE:
9306 rb_bug(
"Cannot compile a ForwardingArgumentsNode directly\n");
9308 case PM_FORWARDING_SUPER_NODE:
9316 case PM_GLOBAL_VARIABLE_AND_WRITE_NODE: {
9320 LABEL *end_label = NEW_LABEL(location.
line);
9323 PUSH_INSN1(ret, location, getglobal, name);
9324 if (!popped) PUSH_INSN(ret, location, dup);
9326 PUSH_INSNL(ret, location, branchunless, end_label);
9327 if (!popped) PUSH_INSN(ret, location, pop);
9329 PM_COMPILE_NOT_POPPED(cast->
value);
9330 if (!popped) PUSH_INSN(ret, location, dup);
9332 PUSH_INSN1(ret, location, setglobal, name);
9333 PUSH_LABEL(ret, end_label);
9337 case PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE: {
9343 PUSH_INSN1(ret, location, getglobal, name);
9344 PM_COMPILE_NOT_POPPED(cast->
value);
9347 int flags = VM_CALL_ARGS_SIMPLE;
9348 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9350 if (!popped) PUSH_INSN(ret, location, dup);
9351 PUSH_INSN1(ret, location, setglobal, name);
9355 case PM_GLOBAL_VARIABLE_OR_WRITE_NODE: {
9359 LABEL *set_label = NEW_LABEL(location.
line);
9360 LABEL *end_label = NEW_LABEL(location.
line);
9362 PUSH_INSN(ret, location, putnil);
9365 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name,
Qtrue);
9366 PUSH_INSNL(ret, location, branchunless, set_label);
9368 PUSH_INSN1(ret, location, getglobal, name);
9369 if (!popped) PUSH_INSN(ret, location, dup);
9371 PUSH_INSNL(ret, location, branchif, end_label);
9372 if (!popped) PUSH_INSN(ret, location, pop);
9374 PUSH_LABEL(ret, set_label);
9375 PM_COMPILE_NOT_POPPED(cast->
value);
9376 if (!popped) PUSH_INSN(ret, location, dup);
9378 PUSH_INSN1(ret, location, setglobal, name);
9379 PUSH_LABEL(ret, end_label);
9383 case PM_GLOBAL_VARIABLE_READ_NODE: {
9389 PUSH_INSN1(ret, location, getglobal, name);
9390 if (popped) PUSH_INSN(ret, location, pop);
9394 case PM_GLOBAL_VARIABLE_WRITE_NODE: {
9398 PM_COMPILE_NOT_POPPED(cast->
value);
9399 if (!popped) PUSH_INSN(ret, location, dup);
9401 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9402 PUSH_INSN1(ret, location, setglobal,
ID2SYM(name));
9406 case PM_HASH_NODE: {
9412 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9420 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
9423 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9424 PUSH_INSN1(ret, location, duphash, value);
9445 for (
size_t index = 0; index < elements->
size; index++) {
9446 PM_COMPILE_POPPED(elements->
nodes[index]);
9450 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9466 pm_compile_conditional(iseq, &location, PM_IF_NODE, (
const pm_node_t *) cast, cast->statements, cast->subsequent, cast->predicate, ret, popped, scope_node);
9469 case PM_IMAGINARY_NODE: {
9474 PUSH_INSN1(ret, location, putobject, operand);
9478 case PM_IMPLICIT_NODE: {
9488 PM_COMPILE(cast->
value);
9494 rb_bug(
"Should not ever enter an in node directly");
9497 case PM_INDEX_OPERATOR_WRITE_NODE: {
9501 pm_compile_index_operator_write_node(iseq, cast, &location, ret, popped, scope_node);
9504 case PM_INDEX_AND_WRITE_NODE: {
9508 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9511 case PM_INDEX_OR_WRITE_NODE: {
9515 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9518 case PM_INSTANCE_VARIABLE_AND_WRITE_NODE: {
9522 LABEL *end_label = NEW_LABEL(location.
line);
9524 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9527 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9528 if (!popped) PUSH_INSN(ret, location, dup);
9530 PUSH_INSNL(ret, location, branchunless, end_label);
9531 if (!popped) PUSH_INSN(ret, location, pop);
9533 PM_COMPILE_NOT_POPPED(cast->
value);
9534 if (!popped) PUSH_INSN(ret, location, dup);
9536 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9537 PUSH_LABEL(ret, end_label);
9541 case PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE: {
9546 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9549 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9550 PM_COMPILE_NOT_POPPED(cast->
value);
9553 int flags = VM_CALL_ARGS_SIMPLE;
9554 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9556 if (!popped) PUSH_INSN(ret, location, dup);
9557 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9561 case PM_INSTANCE_VARIABLE_OR_WRITE_NODE: {
9565 LABEL *end_label = NEW_LABEL(location.
line);
9567 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9570 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9571 if (!popped) PUSH_INSN(ret, location, dup);
9573 PUSH_INSNL(ret, location, branchif, end_label);
9574 if (!popped) PUSH_INSN(ret, location, pop);
9576 PM_COMPILE_NOT_POPPED(cast->
value);
9577 if (!popped) PUSH_INSN(ret, location, dup);
9579 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9580 PUSH_LABEL(ret, end_label);
9584 case PM_INSTANCE_VARIABLE_READ_NODE: {
9589 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9590 PUSH_INSN2(ret, location, getinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9594 case PM_INSTANCE_VARIABLE_WRITE_NODE: {
9598 PM_COMPILE_NOT_POPPED(cast->
value);
9599 if (!popped) PUSH_INSN(ret, location, dup);
9601 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9602 PUSH_INSN2(ret, location, setinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9606 case PM_INTEGER_NODE: {
9611 PUSH_INSN1(ret, location, putobject, operand);
9615 case PM_INTERPOLATED_MATCH_LAST_LINE_NODE: {
9618 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9620 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9621 PUSH_INSN1(ret, location, putobject, regexp);
9628 PUSH_INSN1(ret, location, getglobal,
rb_id2sym(idLASTLINE));
9629 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9630 if (popped) PUSH_INSN(ret, location, pop);
9634 case PM_INTERPOLATED_REGULAR_EXPRESSION_NODE: {
9637 if (PM_NODE_FLAG_P(node, PM_REGULAR_EXPRESSION_FLAGS_ONCE)) {
9638 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9640 int ise_index = ISEQ_BODY(iseq)->ise_size++;
9643 pm_scope_node_init(node, &next_scope_node, scope_node);
9645 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, location.
line);
9646 pm_scope_node_destroy(&next_scope_node);
9648 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
9649 PUSH_INSN2(ret, location, once, block_iseq,
INT2FIX(ise_index));
9650 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9652 if (popped) PUSH_INSN(ret, location, pop);
9656 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9658 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9659 PUSH_INSN1(ret, location, putobject, regexp);
9664 if (popped) PUSH_INSN(ret, location, pop);
9669 case PM_INTERPOLATED_STRING_NODE: {
9672 if (PM_NODE_FLAG_P(node, PM_NODE_FLAG_STATIC_LITERAL)) {
9674 VALUE string = pm_static_literal_value(iseq, node, scope_node);
9676 if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN)) {
9677 PUSH_INSN1(ret, location, putobject,
string);
9679 else if (PM_NODE_FLAG_P(node, PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE)) {
9680 PUSH_INSN1(ret, location, putstring,
string);
9683 PUSH_INSN1(ret, location, putchilledstring,
string);
9689 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));
9690 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9691 if (popped) PUSH_INSN(ret, location, pop);
9696 case PM_INTERPOLATED_SYMBOL_NODE: {
9700 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL,
false,
false);
9703 PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9707 PUSH_INSN(ret, location, intern);
9710 PUSH_INSN(ret, location, pop);
9715 case PM_INTERPOLATED_X_STRING_NODE: {
9720 PUSH_INSN(ret, location, putself);
9722 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret,
false, scope_node, NULL, NULL,
false,
false);
9723 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9725 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
9726 if (popped) PUSH_INSN(ret, location, pop);
9730 case PM_IT_LOCAL_VARIABLE_READ_NODE: {
9737 while (current_scope_node) {
9738 if (current_scope_node->parameters && PM_NODE_TYPE_P(current_scope_node->parameters, PM_IT_PARAMETERS_NODE)) {
9739 PUSH_GETLOCAL(ret, location, current_scope_node->local_table_for_iseq_size, level);
9743 current_scope_node = current_scope_node->previous;
9746 rb_bug(
"Local `it` does not exist");
9751 case PM_KEYWORD_HASH_NODE: {
9759 PM_COMPILE(element);
9762 if (!popped) PUSH_INSN1(ret, location, newhash,
INT2FIX(elements->
size * 2));
9765 case PM_LAMBDA_NODE: {
9771 pm_scope_node_init(node, &next_scope_node, scope_node);
9773 int opening_lineno = pm_location_line_number_cached(&cast->
opening_loc, scope_node);
9774 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, opening_lineno);
9775 pm_scope_node_destroy(&next_scope_node);
9778 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9779 PUSH_CALL_WITH_BLOCK(ret, location, idLambda, argc, block);
9782 if (popped) PUSH_INSN(ret, location, pop);
9785 case PM_LOCAL_VARIABLE_AND_WRITE_NODE: {
9789 LABEL *end_label = NEW_LABEL(location.
line);
9792 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9793 if (!popped) PUSH_INSN(ret, location, dup);
9795 PUSH_INSNL(ret, location, branchunless, end_label);
9796 if (!popped) PUSH_INSN(ret, location, pop);
9798 PM_COMPILE_NOT_POPPED(cast->
value);
9799 if (!popped) PUSH_INSN(ret, location, dup);
9801 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9802 PUSH_LABEL(ret, end_label);
9806 case PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE: {
9812 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9814 PM_COMPILE_NOT_POPPED(cast->
value);
9817 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
9819 if (!popped) PUSH_INSN(ret, location, dup);
9820 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9824 case PM_LOCAL_VARIABLE_OR_WRITE_NODE: {
9829 LABEL *set_label = NEW_LABEL(location.
line);
9830 LABEL *end_label = NEW_LABEL(location.
line);
9832 PUSH_INSN1(ret, location, putobject,
Qtrue);
9833 PUSH_INSNL(ret, location, branchunless, set_label);
9836 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9837 if (!popped) PUSH_INSN(ret, location, dup);
9839 PUSH_INSNL(ret, location, branchif, end_label);
9840 if (!popped) PUSH_INSN(ret, location, pop);
9842 PUSH_LABEL(ret, set_label);
9843 PM_COMPILE_NOT_POPPED(cast->
value);
9844 if (!popped) PUSH_INSN(ret, location, dup);
9846 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9847 PUSH_LABEL(ret, end_label);
9851 case PM_LOCAL_VARIABLE_READ_NODE: {
9857 PUSH_GETLOCAL(ret, location, index.index, index.level);
9862 case PM_LOCAL_VARIABLE_WRITE_NODE: {
9866 PM_COMPILE_NOT_POPPED(cast->
value);
9867 if (!popped) PUSH_INSN(ret, location, dup);
9870 PUSH_SETLOCAL(ret, location, index.index, index.level);
9873 case PM_MATCH_LAST_LINE_NODE: {
9876 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9878 PUSH_INSN1(ret, location, putobject, regexp);
9880 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9881 if (popped) PUSH_INSN(ret, location, pop);
9885 case PM_MATCH_PREDICATE_NODE: {
9892 PUSH_INSN(ret, location, putnil);
9895 PM_COMPILE_NOT_POPPED(cast->
value);
9896 PUSH_INSN(ret, location, dup);
9900 LABEL *matched_label = NEW_LABEL(location.
line);
9901 LABEL *unmatched_label = NEW_LABEL(location.
line);
9902 LABEL *done_label = NEW_LABEL(location.
line);
9903 pm_compile_pattern(iseq, scope_node, cast->
pattern, ret, matched_label, unmatched_label,
false,
true, 2);
9907 PUSH_LABEL(ret, unmatched_label);
9908 PUSH_INSN(ret, location, pop);
9909 PUSH_INSN(ret, location, pop);
9911 if (!popped) PUSH_INSN1(ret, location, putobject,
Qfalse);
9912 PUSH_INSNL(ret, location, jump, done_label);
9913 PUSH_INSN(ret, location, putnil);
9917 PUSH_LABEL(ret, matched_label);
9918 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(2));
9919 if (!popped) PUSH_INSN1(ret, location, putobject,
Qtrue);
9920 PUSH_INSNL(ret, location, jump, done_label);
9922 PUSH_LABEL(ret, done_label);
9925 case PM_MATCH_REQUIRED_NODE:
9939 case PM_MATCH_WRITE_NODE:
9948 pm_compile_match_write_node(iseq, (
const pm_match_write_node_t *) node, &location, ret, popped, scope_node);
9950 case PM_ERROR_RECOVERY_NODE:
9951 rb_bug(
"A pm_error_recovery_node_t should not exist in prism's AST.");
9953 case PM_MODULE_NODE: {
9958 ID module_id = pm_constant_id_lookup(scope_node, cast->
name);
9959 VALUE module_name =
rb_str_freeze(rb_sprintf(
"<module:%"PRIsVALUE
">", rb_id2str(module_id)));
9962 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9964 const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&next_scope_node, module_name, ISEQ_TYPE_CLASS, location.
line);
9965 pm_scope_node_destroy(&next_scope_node);
9967 const int flags = VM_DEFINECLASS_TYPE_MODULE | pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
9968 PUSH_INSN(ret, location, putnil);
9969 PUSH_INSN3(ret, location, defineclass,
ID2SYM(module_id), module_iseq,
INT2FIX(flags));
9972 if (popped) PUSH_INSN(ret, location, pop);
9975 case PM_REQUIRED_PARAMETER_NODE: {
9981 PUSH_SETLOCAL(ret, location, index.index, index.level);
9984 case PM_MULTI_WRITE_NODE: {
9995 DECL_ANCHOR(writes);
9996 DECL_ANCHOR(cleanup);
9999 state.position = popped ? 0 : 1;
10000 pm_compile_multi_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
10002 PM_COMPILE_NOT_POPPED(cast->
value);
10003 if (!popped) PUSH_INSN(ret, location, dup);
10005 PUSH_SEQ(ret, writes);
10006 if (!popped && state.stack_size >= 1) {
10009 PUSH_INSN1(ret, location, setn,
INT2FIX(state.stack_size));
10014 pm_multi_target_state_update(&state);
10016 PUSH_SEQ(ret, cleanup);
10025 pm_compile_next_node(iseq, (
const pm_next_node_t *) node, &location, ret, popped, scope_node);
10027 case PM_NIL_NODE: {
10031 PUSH_INSN(ret, location, putnil);
10036 case PM_NO_BLOCK_PARAMETER_NODE: {
10039 ISEQ_BODY(iseq)->param.flags.accepts_no_block = TRUE;
10042 case PM_NO_KEYWORDS_PARAMETER_NODE: {
10045 ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg = TRUE;
10048 case PM_NUMBERED_REFERENCE_READ_NODE: {
10054 if (cast->
number != 0) {
10055 VALUE ref = pm_compile_numbered_reference_ref(cast);
10056 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), ref);
10059 PUSH_INSN(ret, location, putnil);
10070 LABEL *end_label = NEW_LABEL(location.
line);
10071 PM_COMPILE_NOT_POPPED(cast->
left);
10073 if (!popped) PUSH_INSN(ret, location, dup);
10074 PUSH_INSNL(ret, location, branchif, end_label);
10076 if (!popped) PUSH_INSN(ret, location, pop);
10077 PM_COMPILE(cast->
right);
10078 PUSH_LABEL(ret, end_label);
10082 case PM_OPTIONAL_PARAMETER_NODE: {
10086 PM_COMPILE_NOT_POPPED(cast->
value);
10089 PUSH_SETLOCAL(ret, location, index.index, index.level);
10093 case PM_PARENTHESES_NODE: {
10101 if (cast->
body != NULL) {
10102 PM_COMPILE(cast->
body);
10104 else if (!popped) {
10105 PUSH_INSN(ret, location, putnil);
10110 case PM_PRE_EXECUTION_NODE: {
10122 DECL_ANCHOR(inner_pre);
10125 DECL_ANCHOR(inner_body);
10130 for (
size_t index = 0; index < body->
size; index++) {
10131 pm_compile_node(iseq, body->
nodes[index], inner_body,
true, scope_node);
10136 PUSH_INSN(inner_body, location, putnil);
10142 PUSH_SEQ(outer_pre, inner_pre);
10143 PUSH_SEQ(outer_pre, inner_body);
10148 case PM_POST_EXECUTION_NODE: {
10152 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
10155 pm_scope_node_init(node, &next_scope_node, scope_node);
10156 child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
10157 pm_scope_node_destroy(&next_scope_node);
10159 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
10161 int is_index = ISEQ_BODY(iseq)->ise_size++;
10162 PUSH_INSN2(ret, location, once, child_iseq,
INT2FIX(is_index));
10164 if (popped) PUSH_INSN(ret, location, pop);
10166 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
10170 case PM_RANGE_NODE: {
10174 bool exclude_end = PM_NODE_FLAG_P(cast, PM_RANGE_FLAGS_EXCLUDE_END);
10176 if (pm_optimizable_range_item_p(cast->
left) && pm_optimizable_range_item_p(cast->
right)) {
10182 (left && PM_NODE_TYPE_P(left, PM_INTEGER_NODE)) ? parse_integer((
const pm_integer_node_t *) left) :
Qnil,
10183 (right && PM_NODE_TYPE_P(right, PM_INTEGER_NODE)) ? parse_integer((const
pm_integer_node_t *) right) :
Qnil,
10187 RB_OBJ_SET_SHAREABLE(val);
10188 PUSH_INSN1(ret, location, putobject, val);
10192 if (cast->
left != NULL) {
10193 PM_COMPILE(cast->
left);
10195 else if (!popped) {
10196 PUSH_INSN(ret, location, putnil);
10199 if (cast->
right != NULL) {
10200 PM_COMPILE(cast->
right);
10202 else if (!popped) {
10203 PUSH_INSN(ret, location, putnil);
10207 PUSH_INSN1(ret, location, newrange,
INT2FIX(exclude_end ? 1 : 0));
10212 case PM_RATIONAL_NODE: {
10216 PUSH_INSN1(ret, location, putobject, parse_rational((
const pm_rational_node_t *) node));
10223 pm_compile_redo_node(iseq, &location, ret, popped, scope_node);
10225 case PM_REGULAR_EXPRESSION_NODE: {
10229 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
10230 PUSH_INSN1(ret, location, putobject, regexp);
10234 case PM_RESCUE_NODE:
10237 pm_compile_rescue_node(iseq, (
const pm_rescue_node_t *) node, &location, ret, popped, scope_node);
10239 case PM_RESCUE_MODIFIER_NODE: {
10245 pm_scope_node_init((
const pm_node_t *) cast, &rescue_scope_node, scope_node);
10247 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
10248 &rescue_scope_node,
10254 pm_scope_node_destroy(&rescue_scope_node);
10256 LABEL *lstart = NEW_LABEL(location.
line);
10257 LABEL *lend = NEW_LABEL(location.
line);
10258 LABEL *lcont = NEW_LABEL(location.
line);
10260 lstart->rescued = LABEL_RESCUE_BEG;
10261 lend->rescued = LABEL_RESCUE_END;
10263 PUSH_LABEL(ret, lstart);
10265 PUSH_LABEL(ret, lend);
10267 PUSH_INSN(ret, location, nop);
10268 PUSH_LABEL(ret, lcont);
10269 if (popped) PUSH_INSN(ret, location, pop);
10271 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
10272 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
10275 case PM_RETURN_NODE:
10281 pm_compile_return_node(iseq, (
const pm_return_node_t *) node, &location, ret, popped, scope_node);
10283 case PM_RETRY_NODE: {
10286 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_RESCUE) {
10287 PUSH_INSN(ret, location, putnil);
10288 PUSH_INSN1(ret, location,
throw,
INT2FIX(TAG_RETRY));
10289 if (popped) PUSH_INSN(ret, location, pop);
10292 COMPILE_ERROR(iseq, location.
line,
"Invalid retry");
10297 case PM_SCOPE_NODE:
10298 pm_compile_scope_node(iseq, (
pm_scope_node_t *) node, &location, ret, popped);
10300 case PM_SELF_NODE: {
10304 PUSH_INSN(ret, location, putself);
10308 case PM_SHAREABLE_CONSTANT_NODE: {
10312 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));
10314 switch (PM_NODE_TYPE(cast->
write)) {
10315 case PM_CONSTANT_WRITE_NODE:
10318 case PM_CONSTANT_AND_WRITE_NODE:
10321 case PM_CONSTANT_OR_WRITE_NODE:
10324 case PM_CONSTANT_OPERATOR_WRITE_NODE:
10327 case PM_CONSTANT_PATH_WRITE_NODE:
10330 case PM_CONSTANT_PATH_AND_WRITE_NODE:
10333 case PM_CONSTANT_PATH_OR_WRITE_NODE:
10336 case PM_CONSTANT_PATH_OPERATOR_WRITE_NODE:
10340 rb_bug(
"Unexpected node type for shareable constant write: %s", pm_node_type(PM_NODE_TYPE(cast->
write)));
10346 case PM_SINGLETON_CLASS_NODE: {
10352 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10353 const rb_iseq_t *child_iseq = NEW_ISEQ(&next_scope_node, rb_fstring_lit(
"singleton class"), ISEQ_TYPE_CLASS, location.
line);
10354 pm_scope_node_destroy(&next_scope_node);
10357 PUSH_INSN(ret, location, putnil);
10360 CONST_ID(singletonclass,
"singletonclass");
10364 int sclass_flags = VM_DEFINECLASS_TYPE_SINGLETON_CLASS;
10365 if (!(PM_NODE_TYPE_P(cast->
expression, PM_SELF_NODE) &&
10366 ISEQ_BODY(iseq)->
type == ISEQ_TYPE_CLASS) &&
10368 sclass_flags |= VM_DEFINECLASS_FLAG_DYNAMIC_CREF;
10371 PUSH_INSN3(ret, location, defineclass,
ID2SYM(singletonclass), child_iseq,
INT2FIX(sclass_flags));
10373 if (popped) PUSH_INSN(ret, location, pop);
10378 case PM_SOURCE_ENCODING_NODE: {
10382 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10383 PUSH_INSN1(ret, location, putobject, value);
10387 case PM_SOURCE_FILE_NODE: {
10392 VALUE string = pm_source_file_value(cast, scope_node);
10394 if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_FROZEN)) {
10395 PUSH_INSN1(ret, location, putobject,
string);
10397 else if (PM_NODE_FLAG_P(cast, PM_STRING_FLAGS_MUTABLE)) {
10398 PUSH_INSN1(ret, location, putstring,
string);
10401 PUSH_INSN1(ret, location, putchilledstring,
string);
10406 case PM_SOURCE_LINE_NODE: {
10410 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10411 PUSH_INSN1(ret, location, putobject, value);
10415 case PM_SPLAT_NODE: {
10424 PUSH_INSN1(ret, location, splatarray,
Qtrue);
10428 case PM_STATEMENTS_NODE: {
10433 if (body->
size > 0) {
10434 for (
size_t index = 0; index < body->
size - 1; index++) {
10435 PM_COMPILE_POPPED(body->
nodes[index]);
10437 PM_COMPILE(body->
nodes[body->
size - 1]);
10440 PUSH_INSN(ret, location, putnil);
10444 case PM_STRING_NODE: {
10449 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10451 if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_FROZEN)) {
10452 PUSH_INSN1(ret, location, putobject, value);
10454 else if (PM_NODE_FLAG_P(node, PM_STRING_FLAGS_MUTABLE)) {
10455 PUSH_INSN1(ret, location, putstring, value);
10458 PUSH_INSN1(ret, location, putchilledstring, value);
10463 case PM_SUPER_NODE:
10467 pm_compile_super_node(iseq, (
const pm_super_node_t *) node, &location, ret, popped, scope_node);
10469 case PM_SYMBOL_NODE: {
10473 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10474 PUSH_INSN1(ret, location, putobject, value);
10478 case PM_TRUE_NODE: {
10482 PUSH_INSN1(ret, location, putobject,
Qtrue);
10486 case PM_UNDEF_NODE: {
10492 for (
size_t index = 0; index < names->
size; index++) {
10493 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10494 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
10496 PM_COMPILE_NOT_POPPED(names->
nodes[index]);
10497 PUSH_SEND(ret, location, id_core_undef_method,
INT2NUM(2));
10499 if (index < names->size - 1) {
10500 PUSH_INSN(ret, location, pop);
10504 if (popped) PUSH_INSN(ret, location, pop);
10507 case PM_UNLESS_NODE: {
10519 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);
10522 case PM_UNTIL_NODE: {
10529 pm_compile_loop(iseq, &location, cast->
base.
flags, PM_UNTIL_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10532 case PM_WHILE_NODE: {
10539 pm_compile_loop(iseq, &location, cast->
base.
flags, PM_WHILE_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10542 case PM_X_STRING_NODE: {
10546 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10548 PUSH_INSN(ret, location, putself);
10549 PUSH_INSN1(ret, location, putobject, value);
10550 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
10551 if (popped) PUSH_INSN(ret, location, pop);
10555 case PM_YIELD_NODE:
10561 pm_compile_yield_node(iseq, (
const pm_yield_node_t *) node, &location, ret, popped, scope_node);
10564 rb_raise(
rb_eNotImpError,
"node type %s not implemented", pm_node_type(PM_NODE_TYPE(node)));
10569#undef PM_CONTAINER_P
10573pm_iseq_pre_execution_p(
rb_iseq_t *iseq)
10575 switch (ISEQ_BODY(iseq)->
type) {
10576 case ISEQ_TYPE_TOP:
10577 case ISEQ_TYPE_EVAL:
10578 case ISEQ_TYPE_MAIN:
10597 if (pm_iseq_pre_execution_p(iseq)) {
10609 pm_compile_node(iseq, (
const pm_node_t *) node, body,
false, node);
10613 PUSH_SEQ(ret, pre);
10614 PUSH_SEQ(ret, body);
10619 pm_compile_node(iseq, (
const pm_node_t *) node, ret,
false, node);
10622 CHECK(iseq_setup_insn(iseq, ret));
10623 return iseq_setup(iseq, ret);
10630 result->
arena = pm_arena_new();
10631 result->
options = pm_options_new();
10632 pm_options_line_set(result->
options, 1);
10643 SIZED_FREE_N(result->
node.constants, pm_parser_constants_size(result->
node.parser));
10644 pm_scope_node_destroy(&result->
node);
10648 pm_arena_free(result->
arena);
10650 pm_options_free(result->
options);
10686#define PM_COLOR_BOLD "\033[1m"
10687#define PM_COLOR_GRAY "\033[2m"
10688#define PM_COLOR_RED "\033[1;31m"
10689#define PM_COLOR_RESET "\033[m"
10690#define PM_ERROR_TRUNCATE 30
10698 int32_t start_line;
10702pm_error_collect_callback(
const pm_diagnostic_t *diagnostic,
void *data)
10707 pm_line_column_t start = pm_line_offset_list_line_column(ctx->line_offsets, loc.
start, ctx->start_line);
10710 uint32_t column_end;
10712 column_end = end.
column;
10714 column_end = (uint32_t) (ctx->line_offsets->
offsets[start.
line - ctx->start_line + 1] - ctx->line_offsets->
offsets[start.
line - ctx->start_line] - 1);
10718 if (start.
column == column_end) column_end++;
10723 (index < ctx->count) &&
10725 (ctx->errors[index].
line < start.
line) ||
10730 if (index < ctx->count) {
10731 memmove(&ctx->errors[index + 1], &ctx->errors[index],
sizeof(
pm_parse_error_t) * (ctx->count - index));
10735 .
error = diagnostic,
10736 .line = start.
line,
10737 .column_start = start.
column,
10738 .column_end = column_end
10746 if (errors == NULL)
return NULL;
10751 .capacity = error_count,
10752 .line_offsets = line_offsets,
10753 .start_line = pm_parser_start_line(parser)
10756 pm_parser_errors_each(parser, pm_error_collect_callback, &ctx);
10762pm_parse_errors_format_line(
const pm_parser_t *parser,
const pm_line_offset_list_t *line_offsets,
const char *number_prefix, int32_t line, uint32_t column_start, uint32_t column_end,
VALUE buffer) {
10763 int32_t line_delta = line - pm_parser_start_line(parser);
10764 assert(line_delta >= 0);
10766 size_t index = (size_t) line_delta;
10767 assert(index < line_offsets->size);
10769 const uint8_t *start = &pm_parser_start(parser)[line_offsets->
offsets[index]];
10770 const uint8_t *end;
10772 if (index >= line_offsets->
size - 1) {
10773 end = pm_parser_end(parser);
10775 end = &pm_parser_start(parser)[line_offsets->
offsets[index + 1]];
10778 rb_str_catf(buffer, number_prefix, line);
10781 bool truncate_end =
false;
10782 if ((column_end != 0) && ((end - (start + column_end)) >= PM_ERROR_TRUNCATE)) {
10783 const uint8_t *end_candidate = start + column_end + PM_ERROR_TRUNCATE;
10785 for (
const uint8_t *ptr = start; ptr < end_candidate;) {
10786 size_t char_width = pm_parser_encoding_char_width(parser, ptr, pm_parser_end(parser) - ptr);
10790 if (char_width == 0)
break;
10794 if (ptr + char_width > end_candidate) {
10795 end_candidate = ptr;
10802 end = end_candidate;
10803 truncate_end =
true;
10807 if (column_start >= PM_ERROR_TRUNCATE) {
10809 start += column_start;
10812 rb_str_cat(buffer, (
const char *) start, (
size_t) (end - start));
10814 if (truncate_end) {
10816 }
else if (end == pm_parser_end(parser) && end[-1] !=
'\n') {
10826 assert(error_count != 0);
10828 const int32_t start_line = pm_parser_start_line(parser);
10835 int32_t first_line_number = errors[0].
line;
10836 int32_t last_line_number = errors[error_count - 1].
line;
10841 if (first_line_number < 0) first_line_number = (-first_line_number) * 10;
10842 if (last_line_number < 0) last_line_number = (-last_line_number) * 10;
10843 int32_t max_line_number = first_line_number > last_line_number ? first_line_number : last_line_number;
10845 if (max_line_number < 10) {
10846 if (highlight > 0) {
10848 .
number_prefix = PM_COLOR_GRAY
"%1" PRIi32
" | " PM_COLOR_RESET,
10849 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10850 .divider = PM_COLOR_GRAY
" ~~~~~" PM_COLOR_RESET
"\n"
10855 .blank_prefix =
" | ",
10856 .divider =
" ~~~~~\n"
10859 }
else if (max_line_number < 100) {
10860 if (highlight > 0) {
10862 .
number_prefix = PM_COLOR_GRAY
"%2" PRIi32
" | " PM_COLOR_RESET,
10863 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10864 .divider = PM_COLOR_GRAY
" ~~~~~~" PM_COLOR_RESET
"\n"
10869 .blank_prefix =
" | ",
10870 .divider =
" ~~~~~~\n"
10873 }
else if (max_line_number < 1000) {
10874 if (highlight > 0) {
10876 .
number_prefix = PM_COLOR_GRAY
"%3" PRIi32
" | " PM_COLOR_RESET,
10877 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10878 .divider = PM_COLOR_GRAY
" ~~~~~~~" PM_COLOR_RESET
"\n"
10883 .blank_prefix =
" | ",
10884 .divider =
" ~~~~~~~\n"
10887 }
else if (max_line_number < 10000) {
10888 if (highlight > 0) {
10890 .
number_prefix = PM_COLOR_GRAY
"%4" PRIi32
" | " PM_COLOR_RESET,
10891 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10892 .divider = PM_COLOR_GRAY
" ~~~~~~~~" PM_COLOR_RESET
"\n"
10897 .blank_prefix =
" | ",
10898 .divider =
" ~~~~~~~~\n"
10902 if (highlight > 0) {
10904 .
number_prefix = PM_COLOR_GRAY
"%5" PRIi32
" | " PM_COLOR_RESET,
10905 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10906 .divider = PM_COLOR_GRAY
" ~~~~~~~~" PM_COLOR_RESET
"\n"
10911 .blank_prefix =
" | ",
10912 .divider =
" ~~~~~~~~\n"
10925 int32_t last_line = pm_parser_start_line(parser) - 1;
10926 uint32_t last_column_start = 0;
10928 for (
size_t index = 0; index < error_count; index++) {
10933 if (error->
line - last_line > 1) {
10934 if (error->
line - last_line > 2) {
10935 if ((index != 0) && (error->
line - last_line > 3)) {
10940 pm_parse_errors_format_line(parser, line_offsets, error_format.
number_prefix, error->
line - 2, 0, 0, buffer);
10944 pm_parse_errors_format_line(parser, line_offsets, error_format.
number_prefix, error->
line - 1, 0, 0, buffer);
10949 if ((index == 0) || (error->
line != last_line)) {
10950 if (highlight > 1) {
10952 }
else if (highlight > 0) {
10962 for (
size_t next_index = index + 1; next_index < error_count; next_index++) {
10963 if (errors[next_index].line != error->
line)
break;
10964 if (errors[next_index].column_end > column_end) column_end = errors[next_index].
column_end;
10970 const uint8_t *start = &pm_parser_start(parser)[line_offsets->
offsets[error->
line - start_line]];
10971 if (start == pm_parser_end(parser))
rb_str_cat(buffer,
"\n", 1);
10986 if (last_column_start >= PM_ERROR_TRUNCATE) {
10988 column = last_column_start;
10991 while (column < error->column_start) {
10994 size_t char_width = pm_parser_encoding_char_width(parser, start + column, pm_parser_end(parser) - (start + column));
10995 column += (char_width == 0 ? 1 : char_width);
11002 size_t char_width = pm_parser_encoding_char_width(parser, start + column, pm_parser_end(parser) - (start + column));
11003 column += (char_width == 0 ? 1 : char_width);
11005 while (column < error->column_end) {
11008 size_t char_width = pm_parser_encoding_char_width(parser, start + column, pm_parser_end(parser) - (start + column));
11009 column += (char_width == 0 ? 1 : char_width);
11014 if (inline_messages) {
11016 assert(error->
error != NULL);
11018 const char *message = pm_diagnostic_message(error->
error);
11019 rb_str_cat(buffer, message, strlen(message));
11026 last_line = error->
line;
11029 if (index == error_count - 1) {
11030 next_line = (((int32_t) line_offsets->
size) + pm_parser_start_line(parser));
11034 if ((pm_parser_start(parser) + line_offsets->
offsets[line_offsets->
size - 1]) == pm_parser_end(parser)) {
11039 next_line = errors[index + 1].
line;
11042 if (next_line - last_line > 1) {
11044 pm_parse_errors_format_line(parser, line_offsets, error_format.
number_prefix, ++last_line, 0, 0, buffer);
11047 if (next_line - last_line > 1) {
11049 pm_parse_errors_format_line(parser, line_offsets, error_format.
number_prefix, ++last_line, 0, 0, buffer);
11059pm_parse_errors_format(
const pm_parser_t *parser,
size_t error_count,
VALUE buffer,
int highlight,
bool inline_messages) {
11062 pm_parse_error_t *errors = pm_parse_errors_format_sort(parser, error_count, line_offsets);
11063 if (errors == NULL)
return;
11065 pm_parse_errors_format_with(parser, errors, error_count, buffer, highlight, inline_messages);
11066 SIZED_FREE_N(errors, error_count);
11069#undef PM_ERROR_TRUNCATE
11070#undef PM_COLOR_GRAY
11072#undef PM_COLOR_RESET
11083 const size_t start_line = pm_line_offset_list_line_column(pm_parser_line_offsets(parser), location.
start, 1).
line;
11084 const size_t end_line = pm_line_offset_list_line_column(pm_parser_line_offsets(parser), location.
start + location.
length, 1).
line;
11087 const uint8_t *start = pm_parser_start(parser) + line_offsets->
offsets[start_line - 1];
11088 const uint8_t *end = ((end_line == line_offsets->
size) ? pm_parser_end(parser) : (pm_parser_start(parser) + line_offsets->
offsets[end_line]));
11091 while (start < end) {
11092 int width = rb_enc_precise_mbclen((
const char *) start, (
const char *) end, utf8);
11108 bool found_argument_error;
11109 bool found_load_error;
11110 VALUE early_return;
11112 size_t error_count;
11116pm_process_error_check_callback(
const pm_diagnostic_t *diagnostic,
void *data)
11121 if (ctx->first_error == NULL) ctx->first_error = diagnostic;
11122 ctx->error_count++;
11124 switch (pm_diagnostic_error_level(diagnostic)) {
11126 if (ctx->valid_utf8 && !pm_parse_process_error_utf8_p(ctx->parser, loc)) {
11127 ctx->valid_utf8 =
false;
11131 if (ctx->found_argument_error || ctx->found_load_error)
break;
11132 ctx->found_argument_error =
true;
11134 int32_t line_number = (int32_t) pm_location_line_number(ctx->parser, &loc);
11138 "%.*s:%" PRIi32
": %s",
11139 (
int) pm_string_length(ctx->filepath),
11140 pm_string_source(ctx->filepath),
11142 pm_diagnostic_message(diagnostic)
11145 if (pm_parse_process_error_utf8_p(ctx->parser, loc)) {
11150 int32_t start_line = pm_parser_start_line(ctx->parser);
11155 if (start_lc.
line == end_lc.
line) {
11156 col_end = end_lc.
column;
11158 col_end = (uint32_t) (line_offsets->
offsets[start_lc.
line - start_line + 1] - line_offsets->
offsets[start_lc.
line - start_line] - 1);
11160 if (start_lc.
column == col_end) col_end++;
11163 .
error = diagnostic,
11164 .line = start_lc.
line,
11165 .column_start = start_lc.
column,
11166 .column_end = col_end
11168 pm_parse_errors_format_with(ctx->parser, &single_error, 1, ctx->buffer, ctx->highlight,
false);
11175 if (ctx->found_argument_error || ctx->found_load_error)
break;
11176 ctx->found_load_error =
true;
11181 ctx->early_return = value;
11196pm_error_simple_format_callback(
const pm_diagnostic_t *diagnostic,
void *data)
11201 if (!ctx->first)
rb_str_cat(ctx->buffer,
"\n", 1);
11202 ctx->first =
false;
11204 rb_str_catf(ctx->buffer,
"%.*s:%" PRIi32
": %s",
11205 (
int) pm_string_length(ctx->filepath),
11206 pm_string_source(ctx->filepath),
11207 (int32_t) pm_location_line_number(ctx->parser, &loc),
11208 pm_diagnostic_message(diagnostic));
11219 size_t error_count = pm_parser_errors_size(parser);
11222 const pm_string_t *filepath = pm_parser_filepath(parser);
11224 int highlight = rb_stderr_tty_p();
11226 const char *no_color = getenv(
"NO_COLOR");
11227 highlight = (no_color == NULL || no_color[0] ==
'\0') ? 2 : 1;
11234 .filepath = filepath,
11236 .highlight = highlight,
11237 .valid_utf8 =
true,
11238 .found_argument_error =
false,
11239 .found_load_error =
false,
11241 .first_error = NULL,
11245 pm_parser_errors_each(parser, pm_process_error_check_callback, &ctx);
11248 if (ctx.early_return !=
Qundef) {
11249 return ctx.early_return;
11253 pm_location_t first_loc = pm_diagnostic_location(ctx.first_error);
11256 "%.*s:%" PRIi32
": syntax error%s found\n",
11257 (
int) pm_string_length(filepath),
11258 pm_string_source(filepath),
11259 (int32_t) pm_location_line_number(parser, &first_loc),
11260 (error_count > 1) ?
"s" :
""
11263 if (ctx.valid_utf8) {
11264 pm_parse_errors_format(parser, error_count, buffer, highlight,
true);
11269 .filepath = filepath,
11273 pm_parser_errors_each(parser, pm_error_simple_format_callback, &simple_ctx);
11276 rb_enc_associate(buffer, result->
node.encoding);
11280 VALUE path = rb_enc_str_new((
const char *) pm_string_source(filepath), pm_string_length(filepath), filepath_encoding);
11295pm_intern_constants_callback(
const pm_constant_t *constant,
void *data)
11298 ctx->constants[ctx->index++] = rb_intern3((
const char *) pm_constant_start(constant), pm_constant_length(constant), ctx->encoding);
11305 const char *filepath;
11309pm_warning_emit_callback(
const pm_diagnostic_t *diagnostic,
void *data) {
11312 int line = pm_location_line_number(ctx->parser, &loc);
11315 rb_enc_compile_warning(ctx->encoding, ctx->filepath, line,
"%s", pm_diagnostic_message(diagnostic));
11318 rb_enc_compile_warn(ctx->encoding, ctx->filepath, line,
"%s", pm_diagnostic_message(diagnostic));
11336 int coverage_enabled = scope_node->coverage_enabled;
11338 pm_scope_node_init(node, scope_node, NULL);
11341 const char *encoding_name = pm_parser_encoding_name(parser);
11342 scope_node->encoding = rb_enc_find(encoding_name);
11343 if (!scope_node->encoding) rb_bug(
"Encoding not found %s!", encoding_name);
11345 scope_node->coverage_enabled = coverage_enabled;
11349 if (script_lines != NULL) {
11353 for (
size_t index = 0; index < line_offsets->
size; index++) {
11354 size_t offset = line_offsets->
offsets[index];
11355 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);
11356 rb_ary_push(*script_lines, rb_enc_str_new((
const char *) pm_parser_start(parser) + offset, length, scope_node->encoding));
11365 .encoding = scope_node->encoding,
11366 .filepath = (
const char *) pm_string_source(pm_parser_filepath(parser))
11368 pm_parser_warnings_each(parser, pm_warning_emit_callback, &warning_ctx);
11371 if (pm_parser_errors_size(parser) > 0) {
11372 VALUE error = pm_parse_process_error(result);
11381 scope_node->parser = parser;
11382 scope_node->options = result->
options;
11383 scope_node->line_offsets = pm_parser_line_offsets(parser);
11384 scope_node->start_line = pm_parser_start_line(parser);
11385 size_t constants_size = pm_parser_constants_size(parser);
11386 scope_node->constants = constants_size ?
xmalloc(constants_size *
sizeof(
ID)) : NULL;
11388 pm_intern_constants_ctx_t intern_ctx = { .constants = scope_node->constants, .encoding = scope_node->encoding, .index = 0 };
11389 pm_parser_constants_each(parser, pm_intern_constants_callback, &intern_ctx);
11402pm_options_frozen_string_literal_init(
pm_options_t *options)
11404 int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
11406 switch (frozen_string_literal) {
11407 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
11409 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
11410 pm_options_frozen_string_literal_set(options,
false);
11412 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
11413 pm_options_frozen_string_literal_set(options,
true);
11416 rb_bug(
"pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
11429 const char *start = (
const char *) pm_parser_start(parser);
11430 const char *end = (
const char *) pm_parser_end(parser);
11435 size_t last_offset = line_offsets->
offsets[line_offsets->
size - 1];
11436 bool last_push = start + last_offset != end;
11441 for (
size_t index = 0; index < line_offsets->
size - 1; index++) {
11442 size_t offset = line_offsets->
offsets[index];
11443 size_t length = line_offsets->
offsets[index + 1] - offset;
11445 rb_ary_push(lines, rb_enc_str_new(start + offset, length, scope_node->encoding));
11450 rb_ary_push(lines, rb_enc_str_new(start + last_offset, end - (start + last_offset), scope_node->encoding));
11464close_file(
VALUE args)
11467 if (arg->fd != -1) {
11470 else if (!
NIL_P(arg->io)) {
11477load_content(
VALUE args)
11484 return rb_funcall(io, rb_intern(
"read"), 0);
11495 result->
source = pm_source_mapped_new(RSTRING_PTR(filepath), O_RDONLY | O_NONBLOCK, &init_result);
11498 pm_options_frozen_string_literal_init(result->
options);
11509 .open_mode = O_RDONLY | O_NONBLOCK,
11513 if (args.fd == -1)
goto error_generic;
11518 long len = RSTRING_LEN(contents);
11519 if (
len < 0)
goto error_generic;
11521 size_t length = (size_t)
len;
11522 uint8_t *source_data =
xmalloc(length);
11523 memcpy(source_data, RSTRING_PTR(contents), length);
11524 result->
source = pm_source_owned_new(source_data, length);
11526 pm_options_frozen_string_literal_init(result->
options);
11535 err = rb_w32_map_errno(GetLastError());
11567 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11570 pm_options_version_for_current_ruby_set(result->
options);
11575 VALUE error = pm_parse_process(result, node, script_lines);
11580 ID id_script_lines = rb_intern(
"SCRIPT_LINES__");
11586 rb_hash_aset(constant_script_lines, filepath, pm_parse_file_script_lines(&result->
node, result->
parser));
11600 VALUE error = pm_load_file(result, filepath,
false);
11601 if (
NIL_P(error)) {
11602 error = pm_parse_file(result, filepath, script_lines);
11618 if (!rb_enc_asciicompat(encoding)) {
11622 pm_options_frozen_string_literal_init(result->
options);
11623 result->
source = pm_source_constant_new((
const uint8_t *) RSTRING_PTR(source), (
size_t) RSTRING_LEN(source));
11624 pm_options_encoding_set(result->
options, rb_enc_name(encoding));
11627 pm_options_filepath_set(result->
options, RSTRING_PTR(filepath));
11630 pm_options_version_for_current_ruby_set(result->
options);
11635 return pm_parse_process(result, node, script_lines);
11644pm_parse_stdin_eof(
void *stream)
11647 return wrapped_stdin->eof_seen;
11650VALUE rb_io_gets_limit_internal(
VALUE io,
long limit);
11656pm_parse_stdin_fgets(
char *
string,
int size,
void *stream)
11662 VALUE line = rb_io_gets_limit_internal(wrapped_stdin->rb_stdin, size - 1);
11667 const char *cstr = RSTRING_PTR(line);
11668 long length = RSTRING_LEN(line);
11670 memcpy(
string, cstr, length);
11671 string[length] =
'\0';
11676 if (length < (size - 1) &&
string[length - 1] !=
'\n') {
11677 wrapped_stdin->eof_seen = 1;
11684void rb_reset_argf_lineno(
long n);
11694 pm_options_frozen_string_literal_init(result->
options);
11701 result->
source = pm_source_stream_new((
void *) &wrapped_stdin, pm_parse_stdin_fgets, pm_parse_stdin_eof);
11706 rb_reset_argf_lineno(0);
11708 return pm_parse_process(result, node, NULL);
11711#define PM_VERSION_FOR_RELEASE(major, minor) PM_VERSION_FOR_RELEASE_IMPL(major, minor)
11712#define PM_VERSION_FOR_RELEASE_IMPL(major, minor) #major "." #minor
11714void pm_options_version_for_current_ruby_set(
pm_options_t *options) {
11716 pm_options_version_set(options, version, strlen(version));
11720#define NEW_ISEQ OLD_ISEQ
11722#undef NEW_CHILD_ISEQ
11723#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_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 MBCLEN_CHARFOUND_LEN(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_LEN.
#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 MBCLEN_CHARFOUND_P(ret)
Old name of ONIGENC_MBCLEN_CHARFOUND_P.
#define DBL2NUM
Old name of rb_float_new.
#define xcalloc
Old name of ruby_xcalloc.
#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_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_syserr_new(int n, const char *mesg)
Creates an exception object that represents the given C errno.
VALUE rb_cArray
Array class.
VALUE rb_cObject
Object class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_stdin
STDIN constant.
VALUE rb_cHash
Hash class.
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
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_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
Identical to rb_enc_str_new(), except it assumes the passed pointer is a pointer to a C 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_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.
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the 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_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_buf_new(long capa)
Allocates a "string buffer".
#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.
VALUE rb_sym2str(VALUE symbol)
Obtain a frozen string representation of a symbol (not including the leading colon).
@ RUBY_IO_READABLE
IO::READABLE
VALUE rb_io_wait(VALUE io, VALUE events, VALUE timeout)
Blocks until the passed IO is ready for the passed events.
int len
Length of the buffer.
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
VALUE rb_ractor_make_shareable(VALUE obj)
Destructively transforms the passed object so that multiple Ractors can share it.
#define DECIMAL_SIZE_OF(expr)
An approximation of decimal representation size.
#define RUBY_API_VERSION_MAJOR
Major version.
#define RUBY_API_VERSION_MINOR
Minor version.
#define RB_INT2NUM
Just another name of rb_int2num_inline.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_parser_t * pm_parser_new(pm_arena_t *arena, const uint8_t *source, size_t size, const pm_options_t *options) PRISM_NONNULL(1)
Allocate and initialize a parser with the given start and end pointers.
PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser) PRISM_NONNULL(1)
Free both the memory held by the given parser and the parser itself.
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser) PRISM_NONNULL(1)
Initiate the parser with the given parser.
#define PM_NODE_LIST_FOREACH(list, index, node)
Loop through each node in the node list, writing each node to the given pm_node_t pointer.
The main header file for the prism parser.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define errno
Ractor-aware version of errno.
pm_source_init_result_t
Represents the result of initializing a source from a file.
@ PM_SOURCE_INIT_SUCCESS
Indicates that the source was successfully initialized.
@ PM_SOURCE_INIT_ERROR_NON_REGULAR
Indicates that the file is not a regular file (e.g.
@ PM_SOURCE_INIT_ERROR_DIRECTORY
Indicates that the file that was attempted to be opened was a directory.
#define RTEST
This is an old name of RB_TEST.
PM_NODE_ALIGNAS struct pm_node * new_name
AliasGlobalVariableNode::new_name.
PM_NODE_ALIGNAS struct pm_node * old_name
AliasGlobalVariableNode::old_name.
PM_NODE_ALIGNAS struct pm_node * old_name
AliasMethodNode::old_name.
PM_NODE_ALIGNAS struct pm_node * new_name
AliasMethodNode::new_name.
PM_NODE_ALIGNAS struct pm_node * left
AlternationPatternNode::left.
PM_NODE_ALIGNAS struct pm_node * right
AlternationPatternNode::right.
PM_NODE_ALIGNAS struct pm_node * left
AndNode::left.
PM_NODE_ALIGNAS struct pm_node * right
AndNode::right.
pm_node_t base
The embedded base node.
struct pm_node_list arguments
ArgumentsNode::arguments.
struct pm_node_list elements
ArrayNode::elements.
struct pm_node_list requireds
ArrayPatternNode::requireds.
PM_NODE_ALIGNAS struct pm_node * rest
ArrayPatternNode::rest.
PM_NODE_ALIGNAS struct pm_node * constant
ArrayPatternNode::constant.
struct pm_node_list posts
ArrayPatternNode::posts.
PM_NODE_ALIGNAS struct pm_node * value
AssocNode::value.
PM_NODE_ALIGNAS struct pm_node * key
AssocNode::key.
PM_NODE_ALIGNAS struct pm_node * value
AssocSplatNode::value.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_else_node * else_clause
BeginNode::else_clause.
PM_NODE_ALIGNAS struct pm_ensure_node * ensure_clause
BeginNode::ensure_clause.
PM_NODE_ALIGNAS struct pm_statements_node * statements
BeginNode::statements.
PM_NODE_ALIGNAS struct pm_rescue_node * rescue_clause
BeginNode::rescue_clause.
PM_NODE_ALIGNAS struct pm_node * expression
BlockArgumentNode::expression.
PM_NODE_ALIGNAS struct pm_node * parameters
BlockNode::parameters.
pm_constant_id_list_t locals
BlockNode::locals.
PM_NODE_ALIGNAS struct pm_node * body
BlockNode::body.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
BreakNode::arguments.
PM_NODE_ALIGNAS struct pm_node * receiver
CallAndWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallAndWriteNode::value.
pm_constant_id_t read_name
CallAndWriteNode::read_name.
pm_constant_id_t write_name
CallAndWriteNode::write_name.
pm_location_t closing_loc
CallNode::closing_loc.
pm_constant_id_t name
CallNode::name.
pm_node_t base
The embedded base node.
PM_NODE_ALIGNAS struct pm_arguments_node * arguments
CallNode::arguments.
pm_location_t message_loc
CallNode::message_loc.
PM_NODE_ALIGNAS struct pm_node * block
CallNode::block.
PM_NODE_ALIGNAS struct pm_node * receiver
CallNode::receiver.
pm_constant_id_t read_name
CallOperatorWriteNode::read_name.
pm_constant_id_t binary_operator
CallOperatorWriteNode::binary_operator.
pm_constant_id_t write_name
CallOperatorWriteNode::write_name.
PM_NODE_ALIGNAS struct pm_node * receiver
CallOperatorWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallOperatorWriteNode::value.
PM_NODE_ALIGNAS struct pm_node * receiver
CallOrWriteNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CallOrWriteNode::value.
pm_constant_id_t write_name
CallOrWriteNode::write_name.
pm_constant_id_t read_name
CallOrWriteNode::read_name.
pm_constant_id_t name
CallTargetNode::name.
PM_NODE_ALIGNAS struct pm_node * receiver
CallTargetNode::receiver.
PM_NODE_ALIGNAS struct pm_node * value
CapturePatternNode::value.
PM_NODE_ALIGNAS struct pm_local_variable_target_node * target
CapturePatternNode::target.
struct pm_node_list conditions
CaseMatchNode::conditions.
PM_NODE_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_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.
Context struct for collecting errors via callback.
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.
An error that is going to be formatted into the output.
uint32_t column_end
The column end of the diagnostic message.
int32_t line
The start line of the diagnostic message.
const pm_diagnostic_t * error
A pointer to the diagnostic that was generated during parsing.
uint32_t column_start
The column start of the diagnostic message.
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.
Context for the error processing callback used in pm_parse_process_error.
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.
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.