20#define PUSH_ADJUST(seq, location, label) \
21 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), (int) (location).line))
23#define PUSH_ADJUST_RESTORE(seq, label) \
24 ADD_ELEM((seq), (LINK_ELEMENT *) new_adjust_body(iseq, (label), -1))
26#define PUSH_INSN(seq, location, insn) \
27 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 0))
29#define PUSH_INSN1(seq, location, insn, op1) \
30 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 1, (VALUE)(op1)))
32#define PUSH_INSN2(seq, location, insn, op1, op2) \
33 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_body(iseq, (int) (location).line, (int) (location).node_id, BIN(insn), 2, (VALUE)(op1), (VALUE)(op2)))
35#define PUSH_INSN3(seq, location, insn, op1, op2, op3) \
36 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)))
38#define PUSH_INSNL(seq, location, insn, label) \
39 (PUSH_INSN1(seq, location, insn, label), LABEL_REF(label))
41#define PUSH_LABEL(seq, label) \
42 ADD_ELEM((seq), (LINK_ELEMENT *) (label))
44#define PUSH_SEND_R(seq, location, id, argc, block, flag, keywords) \
45 ADD_ELEM((seq), (LINK_ELEMENT *) new_insn_send(iseq, (int) (location).line, (int) (location).node_id, (id), (VALUE)(argc), (block), (VALUE)(flag), (keywords)))
47#define PUSH_SEND(seq, location, id, argc) \
48 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(0), NULL)
50#define PUSH_SEND_WITH_FLAG(seq, location, id, argc, flag) \
51 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)(flag), NULL)
53#define PUSH_SEND_WITH_BLOCK(seq, location, id, argc, block) \
54 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(0), NULL)
56#define PUSH_CALL(seq, location, id, argc) \
57 PUSH_SEND_R((seq), location, (id), (argc), NULL, (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
59#define PUSH_CALL_WITH_BLOCK(seq, location, id, argc, block) \
60 PUSH_SEND_R((seq), location, (id), (argc), (block), (VALUE)INT2FIX(VM_CALL_FCALL), NULL)
62#define PUSH_TRACE(seq, event) \
63 ADD_ELEM((seq), (LINK_ELEMENT *) new_trace_body(iseq, (event), 0))
65#define PUSH_CATCH_ENTRY(type, ls, le, iseqv, lc) \
66 ADD_CATCH_ENTRY((type), (ls), (le), (iseqv), (lc))
68#define PUSH_SEQ(seq1, seq2) \
69 APPEND_LIST((seq1), (seq2))
71#define PUSH_SYNTHETIC_PUTNIL(seq, iseq) \
73 int lineno = ISEQ_COMPILE_DATA(iseq)->last_line; \
74 if (lineno == 0) lineno = FIX2INT(rb_iseq_first_lineno(iseq)); \
75 ADD_SYNTHETIC_INSN(seq, lineno, -1, putnil); \
84pm_iseq_add_getlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
86 if (iseq_local_block_param_p(iseq, idx, level)) {
87 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
90 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(getlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
92 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qfalse);
96pm_iseq_add_setlocal(
rb_iseq_t *iseq,
LINK_ANCHOR *
const seq,
int line,
int node_id,
int idx,
int level)
98 if (iseq_local_block_param_p(iseq, idx, level)) {
99 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setblockparam), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
102 ADD_ELEM(seq, (
LINK_ELEMENT *) new_insn_body(iseq, line, node_id, BIN(setlocal), 2,
INT2FIX((idx) + VM_ENV_DATA_SIZE - 1),
INT2FIX(level)));
104 if (level > 0) access_outer_variables(iseq, level, iseq_lvar_id(iseq, idx, level),
Qtrue);
107#define PUSH_GETLOCAL(seq, location, idx, level) \
108 pm_iseq_add_getlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
110#define PUSH_SETLOCAL(seq, location, idx, level) \
111 pm_iseq_add_setlocal(iseq, (seq), (int) (location).line, (int) (location).node_id, (idx), (level))
117#define OLD_ISEQ NEW_ISEQ
120#define NEW_ISEQ(node, name, type, line_no) \
121 pm_new_child_iseq(iseq, (node), rb_fstring(name), 0, (type), (line_no))
123#define OLD_CHILD_ISEQ NEW_CHILD_ISEQ
126#define NEW_CHILD_ISEQ(node, name, type, line_no) \
127 pm_new_child_iseq(iseq, (node), rb_fstring(name), iseq, (type), (line_no))
129#define PM_COMPILE(node) \
130 pm_compile_node(iseq, (node), ret, popped, scope_node)
132#define PM_COMPILE_INTO_ANCHOR(_ret, node) \
133 pm_compile_node(iseq, (node), _ret, popped, scope_node)
135#define PM_COMPILE_POPPED(node) \
136 pm_compile_node(iseq, (node), ret, true, scope_node)
138#define PM_COMPILE_NOT_POPPED(node) \
139 pm_compile_node(iseq, (node), ret, false, scope_node)
141#define PM_SPECIAL_CONSTANT_FLAG ((pm_constant_id_t)(1 << 31))
142#define PM_CONSTANT_AND ((pm_constant_id_t)(idAnd | PM_SPECIAL_CONSTANT_FLAG))
143#define PM_CONSTANT_DOT3 ((pm_constant_id_t)(idDot3 | PM_SPECIAL_CONSTANT_FLAG))
144#define PM_CONSTANT_MULT ((pm_constant_id_t)(idMULT | PM_SPECIAL_CONSTANT_FLAG))
145#define PM_CONSTANT_POW ((pm_constant_id_t)(idPow | PM_SPECIAL_CONSTANT_FLAG))
147#define PM_NODE_START_LOCATION(parser, node) \
148 ((pm_node_location_t) { .line = pm_newline_list_line(&(parser)->newline_list, ((const pm_node_t *) (node))->location.start, (parser)->start_line), .node_id = ((const pm_node_t *) (node))->node_id })
150#define PM_NODE_END_LOCATION(parser, node) \
151 ((pm_node_location_t) { .line = pm_newline_list_line(&(parser)->newline_list, ((const pm_node_t *) (node))->location.end, (parser)->start_line), .node_id = ((const pm_node_t *) (node))->node_id })
153#define PM_LOCATION_START_LOCATION(parser, location, id) \
154 ((pm_node_location_t) { .line = pm_newline_list_line(&(parser)->newline_list, (location)->start, (parser)->start_line), .node_id = id })
156#define PM_NODE_START_LINE_COLUMN(parser, node) \
157 pm_newline_list_line_column(&(parser)->newline_list, ((const pm_node_t *) (node))->location.start, (parser)->start_line)
159#define PM_NODE_END_LINE_COLUMN(parser, node) \
160 pm_newline_list_line_column(&(parser)->newline_list, ((const pm_node_t *) (node))->location.end, (parser)->start_line)
162#define PM_LOCATION_START_LINE_COLUMN(parser, location) \
163 pm_newline_list_line_column(&(parser)->newline_list, (location)->start, (parser)->start_line)
184 if (integer->
values == NULL) {
189 unsigned char *bytes = (
unsigned char *) RSTRING_PTR(
string);
191 size_t offset = integer->
length * 8;
192 for (
size_t value_index = 0; value_index < integer->
length; value_index++) {
193 uint32_t value = integer->
values[value_index];
195 for (
int index = 0; index < 8; index++) {
196 int byte = (value >> (4 * index)) & 0xf;
197 bytes[--offset] =
byte < 10 ?
byte +
'0' :
byte - 10 +
'a';
205 result =
rb_funcall(result, rb_intern(
"-@"), 0);
217 return parse_integer_value(&node->
value);
252 VALUE imaginary_part;
267 rb_bug(
"Unexpected numeric type on imaginary number %s\n", pm_node_type_to_str(
PM_NODE_TYPE(node->
numeric)));
270 return rb_complex_raw(
INT2FIX(0), imaginary_part);
276 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), scope_node->encoding);
290 encoding = rb_ascii8bit_encoding();
293 encoding = rb_utf8_encoding();
299 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
308 encoding = rb_ascii8bit_encoding();
311 encoding = rb_utf8_encoding();
314 encoding = scope_node->encoding;
317 VALUE value = rb_enc_literal_str((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
320 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
321 int line_number = pm_node_line_number(scope_node->parser, node);
322 value = rb_str_with_debug_created_info(value, rb_iseq_path(iseq), line_number);
333 encoding = rb_utf8_encoding();
336 encoding = rb_ascii8bit_encoding();
339 encoding = rb_usascii_encoding();
342 encoding = scope_node->encoding;
345 return rb_intern3((
const char *) pm_string_source(&symbol->
unescaped), pm_string_length(&symbol->
unescaped), encoding);
349pm_optimizable_range_item_p(
const pm_node_t *node)
356parse_regexp_error(
rb_iseq_t *iseq, int32_t line_number,
const char *fmt, ...)
360 VALUE error = rb_syntax_error_append(
Qnil, rb_iseq_path(iseq), line_number, -1, NULL,
"%" PRIsVALUE, args);
372 if (explicit_regexp_encoding != NULL) {
373 encoding = explicit_regexp_encoding;
376 encoding = rb_ascii8bit_encoding();
379 encoding = rb_utf8_encoding();
382 encoding = implicit_regexp_encoding;
385 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), encoding);
386 VALUE error = rb_reg_check_preprocess(
string);
388 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number(scope_node->parser, node),
"%" PRIsVALUE, rb_obj_as_string(error));
397 for (
size_t index = 0; index < nodes->
size; index++) {
403 if (implicit_regexp_encoding != NULL) {
405 string = parse_regexp_string_part(iseq, scope_node, part, &((
const pm_string_node_t *) part)->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
408 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
409 VALUE error = rb_reg_check_preprocess(
string);
410 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number(scope_node->parser, part),
"%" PRIsVALUE, rb_obj_as_string(error));
414 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
418 string = pm_static_literal_concat(iseq, &((
const pm_interpolated_string_node_t *) part)->parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
422 string = pm_static_literal_concat(iseq, &cast->
statements->
body, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
426 RUBY_ASSERT(
false &&
"unexpected node type in pm_static_literal_concat");
430 if (current !=
Qnil) {
438 return top ? rb_fstring(current) : current;
441#define RE_OPTION_ENCODING_SHIFT 8
442#define RE_OPTION_ENCODING(encoding) (((encoding) & 0xFF) << RE_OPTION_ENCODING_SHIFT)
443#define ARG_ENCODING_NONE 32
444#define ARG_ENCODING_FIXED 16
445#define ENC_ASCII8BIT 1
447#define ENC_Windows_31J 3
463 flags |= ARG_ENCODING_NONE;
467 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_EUC_JP));
471 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_Windows_31J));
475 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_UTF8));
479 flags |= ONIG_OPTION_IGNORECASE;
483 flags |= ONIG_OPTION_MULTILINE;
487 flags |= ONIG_OPTION_EXTEND;
493#undef RE_OPTION_ENCODING_SHIFT
494#undef RE_OPTION_ENCODING
495#undef ARG_ENCODING_FIXED
496#undef ARG_ENCODING_NONE
499#undef ENC_Windows_31J
506 return rb_ascii8bit_encoding();
509 return rb_utf8_encoding();
512 return rb_enc_get_from_index(ENCINDEX_EUC_JP);
515 return rb_enc_get_from_index(ENCINDEX_Windows_31J);
525 VALUE errinfo = rb_errinfo();
527 int32_t line_number = pm_node_line_number(scope_node->parser, node);
528 VALUE regexp = rb_reg_compile(
string, parse_regexp_flags(node), (
const char *) pm_string_source(&scope_node->parser->
filepath), line_number);
531 VALUE message = rb_attr_get(rb_errinfo(), idMesg);
532 rb_set_errinfo(errinfo);
534 parse_regexp_error(iseq, line_number,
"%" PRIsVALUE, message);
545 rb_encoding *regexp_encoding = parse_regexp_encoding(scope_node, node);
546 if (regexp_encoding == NULL) regexp_encoding = scope_node->encoding;
548 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), regexp_encoding);
549 return parse_regexp(iseq, scope_node, node,
string);
555 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
556 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
558 VALUE string = pm_static_literal_concat(iseq, parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
559 return parse_regexp(iseq, scope_node, node,
string);
568 size_t parts_size = parts->
size;
569 bool interpolated =
false;
571 if (parts_size > 0) {
575 for (
size_t index = 0; index < parts_size; index++) {
582 if (implicit_regexp_encoding == NULL) {
583 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
586 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
589 if (
RTEST(current_string)) {
590 current_string =
rb_str_concat(current_string, string_value);
593 current_string = string_value;
594 if (index != 0) current_location = PM_NODE_END_LOCATION(scope_node->parser, part);
609 if (implicit_regexp_encoding == NULL) {
610 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
613 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
616 if (
RTEST(current_string)) {
617 current_string =
rb_str_concat(current_string, string_value);
620 current_string = string_value;
621 current_location = PM_NODE_START_LOCATION(scope_node->parser, part);
625 if (!
RTEST(current_string)) {
628 if (implicit_regexp_encoding != NULL) {
629 if (explicit_regexp_encoding != NULL) {
630 encoding = explicit_regexp_encoding;
633 encoding = rb_ascii8bit_encoding();
636 encoding = implicit_regexp_encoding;
640 encoding = scope_node->encoding;
643 if (parts_size == 1) {
644 current_string = rb_enc_str_new(NULL, 0, encoding);
648 if (
RTEST(current_string)) {
649 VALUE operand = rb_fstring(current_string);
650 PUSH_INSN1(ret, current_location, putobject, operand);
654 PM_COMPILE_NOT_POPPED(part);
656 const pm_node_location_t current_location = PM_NODE_START_LOCATION(scope_node->parser, part);
657 PUSH_INSN(ret, current_location, dup);
660 const struct rb_callinfo *callinfo = new_callinfo(iseq, idTo_s, 0, VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE, NULL, FALSE);
661 PUSH_INSN1(ret, current_location, objtostring, callinfo);
664 PUSH_INSN(ret, current_location, anytostring);
666 current_string =
Qnil;
672 if (
RTEST(current_string)) {
673 current_string = rb_fstring(current_string);
675 if (stack_size == 0 && interpolated) {
676 PUSH_INSN1(ret, current_location, putstring, current_string);
679 PUSH_INSN1(ret, current_location, putobject, current_string);
682 current_string =
Qnil;
687 PUSH_INSN(ret, *node_location, putnil);
696 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
697 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
699 int length = pm_interpolated_node_compile(iseq, parts, node_location, ret, popped, scope_node, implicit_regexp_encoding, explicit_regexp_encoding);
700 PUSH_INSN2(ret, *node_location, toregexp,
INT2FIX(parse_regexp_flags(node) & 0xFF),
INT2FIX(length));
707 size_t length = pm_string_length(filepath);
711 return rb_enc_interned_str((
const char *) pm_string_source(filepath), length, filepath_encoding);
714 return rb_fstring_lit(
"<compiled>");
723pm_static_literal_string(
rb_iseq_t *iseq,
VALUE string,
int line_number)
725 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
726 return rb_str_with_debug_created_info(
string, rb_iseq_path(iseq), line_number);
729 return rb_fstring(
string);
750 VALUE value = rb_ary_hidden_new(elements->
size);
751 for (
size_t index = 0; index < elements->
size; index++) {
752 rb_ary_push(value, pm_static_literal_value(iseq, elements->
nodes[index], scope_node));
766 VALUE array = rb_ary_hidden_new(elements->
size * 2);
767 for (
size_t index = 0; index < elements->
size; index++) {
770 VALUE pair[2] = { pm_static_literal_value(iseq, cast->key, scope_node), pm_static_literal_value(iseq, cast->value, scope_node) };
771 rb_ary_cat(array, pair, 2);
774 VALUE value = rb_hash_new_with_size(elements->
size);
787 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
791 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
795 int line_number = pm_node_line_number(scope_node->parser, node);
796 return pm_static_literal_string(iseq,
string, line_number);
800 VALUE string = pm_static_literal_concat(iseq, &cast->
parts, scope_node, NULL, NULL,
true);
802 return ID2SYM(rb_intern_str(
string));
806 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
814 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
817 return rb_enc_from_encoding(scope_node->encoding);
820 return pm_source_file_value(cast, scope_node);
823 return INT2FIX(pm_node_line_number(scope_node->parser, node));
826 return parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
833 rb_bug(
"Don't have a literal value for node type %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
844 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(scope_node->parser, node);
845 const pm_line_column_t end_location = PM_NODE_END_LINE_COLUMN(scope_node->parser, node);
848 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
849 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
858#define PM_BRANCH_COVERAGE_P(iseq) (ISEQ_COVERAGE(iseq) && ISEQ_BRANCH_COVERAGE(iseq))
872 if (!then_label) then_label = label;
873 else if (!else_label) else_label = label;
875 pm_compile_branch_condition(iseq, seq, cond, then_label, else_label, popped, scope_node);
877 if (LIST_INSN_SIZE_ONE(seq)) {
878 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(seq));
879 if (insn->insn_id == BIN(jump) && (
LABEL *)(insn->operands[0]) == label)
return;
882 if (!label->refcnt) {
883 if (popped) PUSH_INSN(ret, location, putnil);
886 PUSH_LABEL(seq, label);
899 PM_COMPILE_NOT_POPPED(node);
902 PUSH_INSN1(ret, location, getglobal, operand);
904 PUSH_SEND(ret, location, idEq,
INT2FIX(1));
905 if (popped) PUSH_INSN(ret, location, pop);
920 rb_num_t count = ISEQ_FLIP_CNT_INCREMENT(ISEQ_BODY(iseq)->local_iseq) + VM_SVAR_FLIPFLOP_START;
923 PUSH_INSN2(ret, location, getspecial, key,
INT2FIX(0));
924 PUSH_INSNL(ret, location, branchif, lend);
926 if (flip_flop_node->
left) {
927 pm_compile_flip_flop_bound(iseq, flip_flop_node->
left, ret, popped, scope_node);
930 PUSH_INSN(ret, location, putnil);
933 PUSH_INSNL(ret, location, branchunless, else_label);
934 PUSH_INSN1(ret, location, putobject,
Qtrue);
935 PUSH_INSN1(ret, location, setspecial, key);
937 PUSH_INSNL(ret, location, jump, then_label);
940 PUSH_LABEL(ret, lend);
941 if (flip_flop_node->
right) {
942 pm_compile_flip_flop_bound(iseq, flip_flop_node->
right, ret, popped, scope_node);
945 PUSH_INSN(ret, location, putnil);
948 PUSH_INSNL(ret, location, branchunless, then_label);
949 PUSH_INSN1(ret, location, putobject,
Qfalse);
950 PUSH_INSN1(ret, location, setspecial, key);
951 PUSH_INSNL(ret, location, jump, then_label);
965 pm_compile_logical(iseq, ret, cast->
left, NULL, else_label, popped, scope_node);
972 pm_compile_logical(iseq, ret, cast->
left, then_label, NULL, popped, scope_node);
979 PUSH_INSNL(ret, location, jump, else_label);
990 PUSH_INSNL(ret, location, jump, then_label);
993 pm_compile_flip_flop((
const pm_flip_flop_node_t *) cond, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
997 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
true);
1001 DECL_ANCHOR(cond_seq);
1002 pm_compile_node(iseq, cond, cond_seq,
false, scope_node);
1004 if (LIST_INSN_SIZE_ONE(cond_seq)) {
1005 INSN *insn = (
INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(cond_seq));
1007 if (insn->insn_id == BIN(putobject)) {
1008 if (
RTEST(insn->operands[0])) {
1009 PUSH_INSNL(ret, location, jump, then_label);
1014 PUSH_INSNL(ret, location, jump, else_label);
1020 PUSH_SEQ(ret, cond_seq);
1025 PUSH_INSNL(ret, location, branchunless, else_label);
1026 PUSH_INSNL(ret, location, jump, then_label);
1036 LABEL *then_label = NEW_LABEL(location.
line);
1037 LABEL *else_label = NEW_LABEL(location.
line);
1038 LABEL *end_label = NULL;
1040 DECL_ANCHOR(cond_seq);
1041 pm_compile_branch_condition(iseq, cond_seq, predicate, then_label, else_label,
false, scope_node);
1042 PUSH_SEQ(ret, cond_seq);
1047 if (then_label->refcnt && else_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1048 conditional_location = pm_code_location(scope_node, node);
1049 branches = decl_branch_base(iseq, PTR2NUM(node), &conditional_location,
type ==
PM_IF_NODE ?
"if" :
"unless");
1052 if (then_label->refcnt) {
1053 PUSH_LABEL(ret, then_label);
1055 DECL_ANCHOR(then_seq);
1057 if (statements != NULL) {
1058 pm_compile_node(iseq, (
const pm_node_t *) statements, then_seq, popped, scope_node);
1061 PUSH_SYNTHETIC_PUTNIL(then_seq, iseq);
1064 if (else_label->refcnt) {
1066 if (PM_BRANCH_COVERAGE_P(iseq)) {
1069 if (statements != NULL) {
1070 branch_location = pm_code_location(scope_node, (
const pm_node_t *) statements);
1072 pm_line_column_t predicate_end = PM_NODE_END_LINE_COLUMN(scope_node->parser, predicate);
1074 .beg_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column },
1075 .end_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column }
1078 branch_location = conditional_location;
1081 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
type ==
PM_IF_NODE ?
"then" :
"else", branches);
1084 end_label = NEW_LABEL(location.
line);
1085 PUSH_INSNL(then_seq, location, jump, end_label);
1086 if (!popped) PUSH_INSN(then_seq, location, pop);
1089 PUSH_SEQ(ret, then_seq);
1092 if (else_label->refcnt) {
1093 PUSH_LABEL(ret, else_label);
1095 DECL_ANCHOR(else_seq);
1097 if (subsequent != NULL) {
1098 pm_compile_node(iseq, subsequent, else_seq, popped, scope_node);
1101 PUSH_SYNTHETIC_PUTNIL(else_seq, iseq);
1105 if (then_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1108 if (subsequent == NULL) {
1109 branch_location = conditional_location;
1114 branch_location = pm_code_location(scope_node, (
const pm_node_t *) subsequent);
1117 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 1,
type ==
PM_IF_NODE ?
"else" :
"then", branches);
1120 PUSH_SEQ(ret, else_seq);
1124 PUSH_LABEL(ret, end_label);
1138 LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
1139 LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
1140 LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
1142 LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(location.
line);
1143 LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(location.
line);
1144 LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(location.
line);
1145 LABEL *end_label = NEW_LABEL(location.
line);
1146 LABEL *adjust_label = NEW_LABEL(location.
line);
1148 LABEL *next_catch_label = NEW_LABEL(location.
line);
1149 LABEL *tmp_label = NULL;
1155 push_ensure_entry(iseq, &enl, NULL, NULL);
1159 tmp_label = NEW_LABEL(location.
line);
1160 PUSH_INSNL(ret, location, jump, tmp_label);
1164 PUSH_INSNL(ret, location, jump, next_label);
1167 PUSH_LABEL(ret, adjust_label);
1168 PUSH_INSN(ret, location, putnil);
1169 PUSH_LABEL(ret, next_catch_label);
1170 PUSH_INSN(ret, location, pop);
1171 PUSH_INSNL(ret, location, jump, next_label);
1172 if (tmp_label) PUSH_LABEL(ret, tmp_label);
1174 PUSH_LABEL(ret, redo_label);
1177 if (PM_BRANCH_COVERAGE_P(iseq)) {
1179 VALUE branches = decl_branch_base(iseq, PTR2NUM(node), &loop_location,
type ==
PM_WHILE_NODE ?
"while" :
"until");
1181 rb_code_location_t branch_location = statements != NULL ? pm_code_location(scope_node, (
const pm_node_t *) statements) : loop_location;
1182 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
"body", branches);
1185 if (statements != NULL) PM_COMPILE_POPPED((
const pm_node_t *) statements);
1186 PUSH_LABEL(ret, next_label);
1189 pm_compile_branch_condition(iseq, ret, predicate, redo_label, end_label, popped, scope_node);
1192 pm_compile_branch_condition(iseq, ret, predicate, end_label, redo_label, popped, scope_node);
1195 PUSH_LABEL(ret, end_label);
1196 PUSH_ADJUST_RESTORE(ret, adjust_label);
1197 PUSH_INSN(ret, location, putnil);
1199 PUSH_LABEL(ret, break_label);
1200 if (popped) PUSH_INSN(ret, location, pop);
1202 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, NULL, break_label);
1203 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label, NULL, next_catch_label);
1204 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, NULL, ISEQ_COMPILE_DATA(iseq)->redo_label);
1206 ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
1207 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
1208 ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
1209 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->prev;
1221 st_data_t local_index;
1224 for (level = 0; level < start_depth; level++) {
1225 scope_node = scope_node->previous;
1228 while (!st_lookup(scope_node->index_lookup_table, constant_id, &local_index)) {
1231 if (scope_node->previous) {
1232 scope_node = scope_node->previous;
1237 rb_bug(
"Local with constant_id %u does not exist", (
unsigned int) constant_id);
1241 lindex.level = level;
1242 lindex.index = scope_node->local_table_for_iseq_size - (int) local_index;
1256 rb_bug(
"constant_id out of range: %u", (
unsigned int)constant_id);
1258 return scope_node->constants[constant_id - 1];
1264 debugs(
"[new_child_iseq]> ---------------------------------------\n");
1265 int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
1267 rb_iseq_t *ret_iseq = pm_iseq_new_with_opt(node, name,
1268 rb_iseq_path(iseq), rb_iseq_realpath(iseq),
1270 isolated_depth ? isolated_depth + 1 : 0,
1271 type, ISEQ_COMPILE_DATA(iseq)->option, &error_state);
1275 rb_jump_tag(error_state);
1277 debugs(
"[new_child_iseq]< ---------------------------------------\n");
1290 return VM_DEFINECLASS_FLAG_SCOPED;
1294 PUSH_INSN1(ret, *node_location, putobject, rb_cObject);
1295 return VM_DEFINECLASS_FLAG_SCOPED;
1300 PUSH_INSN1(ret, *node_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
1310pm_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)
1314 LABEL *lcfin = NEW_LABEL(location.
line);
1315 LABEL *lskip = NULL;
1318 ID id_read_name = pm_constant_id_lookup(scope_node, read_name);
1320 PM_COMPILE_NOT_POPPED(receiver);
1322 lskip = NEW_LABEL(location.
line);
1323 PUSH_INSN(ret, location, dup);
1324 PUSH_INSNL(ret, location, branchnil, lskip);
1327 PUSH_INSN(ret, location, dup);
1328 PUSH_SEND_WITH_FLAG(ret, location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
1329 if (!popped) PUSH_INSN(ret, location, dup);
1332 PUSH_INSNL(ret, location, branchunless, lcfin);
1335 PUSH_INSNL(ret, location, branchif, lcfin);
1338 if (!popped) PUSH_INSN(ret, location, pop);
1339 PM_COMPILE_NOT_POPPED(value);
1342 PUSH_INSN(ret, location, swap);
1343 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
1346 ID id_write_name = pm_constant_id_lookup(scope_node, write_name);
1347 PUSH_SEND_WITH_FLAG(ret, location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
1348 PUSH_INSNL(ret, location, jump, lfin);
1350 PUSH_LABEL(ret, lcfin);
1351 if (!popped) PUSH_INSN(ret, location, swap);
1353 PUSH_LABEL(ret, lfin);
1355 if (lskip && popped) PUSH_LABEL(ret, lskip);
1356 PUSH_INSN(ret, location, pop);
1357 if (lskip && !popped) PUSH_LABEL(ret, lskip);
1370 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
1376 const int max_stack_length = 0x100;
1377 const unsigned int min_tmp_hash_length = 0x800;
1379 int stack_length = 0;
1380 bool first_chunk =
true;
1386 bool static_literal =
false;
1388 DECL_ANCHOR(anchor);
1391#define FLUSH_CHUNK \
1392 if (stack_length) { \
1393 if (first_chunk) { \
1394 PUSH_SEQ(ret, anchor); \
1395 PUSH_INSN1(ret, location, newhash, INT2FIX(stack_length)); \
1396 first_chunk = false; \
1399 PUSH_INSN1(ret, location, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); \
1400 PUSH_INSN(ret, location, swap); \
1401 PUSH_SEQ(ret, anchor); \
1402 PUSH_SEND(ret, location, id_core_hash_merge_ptr, INT2FIX(stack_length + 1)); \
1404 INIT_ANCHOR(anchor); \
1408 for (
size_t index = 0; index < elements->
size; index++) {
1415 (shareability == 0) &&
1417 (!static_literal && ((index + min_tmp_hash_length) < elements->
size)) ||
1418 (first_chunk && stack_length == 0)
1423 while (index + count < elements->size &&
PM_NODE_FLAG_P(elements->
nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++;
1425 if ((first_chunk && stack_length == 0) || count >= min_tmp_hash_length) {
1428 VALUE ary = rb_ary_hidden_new(count);
1431 for (
size_t tmp_end = index + count; index < tmp_end; index++) {
1435 pm_static_literal_value(iseq, assoc->key, scope_node),
1436 pm_static_literal_value(iseq, assoc->value, scope_node)
1439 rb_ary_cat(ary, elem, 2);
1451 PUSH_INSN1(ret, location, duphash, hash);
1452 first_chunk =
false;
1455 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1456 PUSH_INSN(ret, location, swap);
1457 PUSH_INSN1(ret, location, putobject, hash);
1458 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1464 static_literal =
true;
1468 static_literal =
false;
1473 if (shareability == 0) {
1474 pm_compile_node(iseq, element, anchor,
false, scope_node);
1478 pm_compile_shareable_constant_value(iseq, assoc->
key, shareability, path, ret, scope_node,
false);
1479 pm_compile_shareable_constant_value(iseq, assoc->
value, shareability, path, ret, scope_node,
false);
1482 if ((stack_length += 2) >= max_stack_length) FLUSH_CHUNK;
1489 bool empty_hash = assoc_splat->
value != NULL && (
1494 bool first_element = first_chunk && stack_length == 0;
1495 bool last_element = index == elements->
size - 1;
1496 bool only_element = first_element && last_element;
1499 if (only_element && argument) {
1506 PUSH_INSN(ret, location, putnil);
1508 else if (first_element) {
1511 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1518 if (only_element && argument) {
1524 if (shareability == 0) {
1525 PM_COMPILE_NOT_POPPED(element);
1528 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1536 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1538 if (first_element) {
1539 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1542 PUSH_INSN(ret, location, swap);
1545 if (shareability == 0) {
1546 PM_COMPILE_NOT_POPPED(element);
1549 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1552 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1556 first_chunk =
false;
1557 static_literal =
false;
1561 RUBY_ASSERT(
"Invalid node type for hash" &&
false);
1570#define SPLATARRAY_FALSE 0
1571#define SPLATARRAY_TRUE 1
1572#define DUP_SINGLE_KW_SPLAT 2
1581 bool has_splat =
false;
1582 bool has_keyword_splat =
false;
1584 if (arguments_node == NULL) {
1585 if (*flags & VM_CALL_FCALL) {
1586 *flags |= VM_CALL_VCALL;
1595 int post_splat_counter = 0;
1605 if (has_keyword_splat || has_splat) {
1606 *flags |= VM_CALL_KW_SPLAT;
1607 has_keyword_splat =
true;
1613 *flags |= VM_CALL_KW_SPLAT_MUT;
1614 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1616 else if (*dup_rest & DUP_SINGLE_KW_SPLAT) {
1617 *flags |= VM_CALL_KW_SPLAT_MUT;
1618 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1619 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1620 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1621 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1624 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1635 VALUE stored_indices = rb_hash_new();
1636 VALUE keyword_indices = rb_ary_new_capa(elements->
size);
1639 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1644 VALUE keyword = pm_static_literal_value(iseq, assoc->key, scope_node);
1645 VALUE stored_index = rb_hash_aref(stored_indices, keyword);
1650 if (!
NIL_P(stored_index)) {
1658 rb_hash_aset(stored_indices, keyword,
ULONG2NUM(element_index));
1659 rb_ary_store(keyword_indices, (
long) element_index,
Qtrue);
1664 *flags |= VM_CALL_KWARG;
1666 VALUE *keywords = (*kw_arg)->keywords;
1667 (*kw_arg)->references = 0;
1668 (*kw_arg)->keyword_len = (int) size;
1670 size_t keyword_index = 0;
1671 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1675 if (rb_ary_entry(keyword_indices, (
long) element_index) ==
Qtrue) {
1676 keywords[keyword_index++] = pm_static_literal_value(iseq, assoc->key, scope_node);
1680 PM_COMPILE(assoc->value);
1689 *flags |= VM_CALL_KW_SPLAT;
1691 size_t size = elements->
size;
1696 *flags |= VM_CALL_KW_SPLAT_MUT;
1699 for (
size_t element_index = 0; element_index < size; element_index++) {
1701 PM_COMPILE_NOT_POPPED(assoc->key);
1702 PM_COMPILE_NOT_POPPED(assoc->value);
1705 PUSH_INSN1(ret, location, newhash,
INT2FIX(size * 2));
1711 *flags |= VM_CALL_ARGS_SPLAT;
1715 PM_COMPILE_NOT_POPPED(splat_node->
expression);
1718 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1719 PUSH_GETLOCAL(ret, location, index.index, index.level);
1722 bool first_splat = !has_splat;
1730 if (index + 1 < arguments->
size || has_regular_blockarg) {
1731 PUSH_INSN1(ret, location, splatarray, (*dup_rest & SPLATARRAY_TRUE) ?
Qtrue :
Qfalse);
1732 if (*dup_rest & SPLATARRAY_TRUE) *dup_rest &= ~SPLATARRAY_TRUE;
1740 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1750 PUSH_INSN(ret, location, concattoarray);
1754 post_splat_counter = 0;
1759 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
1761 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
1762 *flags |= VM_CALL_FORWARDING;
1764 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
1765 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1772 *flags |= VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_SPLAT_MUT | VM_CALL_ARGS_BLOCKARG | VM_CALL_KW_SPLAT;
1779 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1780 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1781 PUSH_INSN1(ret, location, splatarray,
Qtrue);
1784 pm_local_index_t pow_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1785 PUSH_GETLOCAL(ret, location, pow_local.index, pow_local.level);
1788 pm_local_index_t and_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
1789 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(and_local.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(and_local.level));
1790 PUSH_INSN(ret, location, splatkw);
1795 post_splat_counter++;
1796 PM_COMPILE_NOT_POPPED(argument);
1816 if (index == arguments->
size - 1) {
1818 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1826 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1827 PUSH_INSN(ret, location, concatarray);
1831 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1832 PUSH_INSN(ret, location, concatarray);
1848 if (has_splat) orig_argc++;
1849 if (has_keyword_splat) orig_argc++;
1858pm_setup_args_dup_rest_p(
const pm_node_t *node)
1895 int dup_rest = SPLATARRAY_TRUE;
1898 size_t arguments_size;
1903 arguments_node != NULL &&
1904 (arguments = &arguments_node->
arguments, arguments_size = arguments->
size) >= 2 &&
1912 dup_rest = SPLATARRAY_FALSE;
1917 for (
size_t index = 0; dup_rest == SPLATARRAY_FALSE && index < elements->
size; index++) {
1923 if (pm_setup_args_dup_rest_p(assoc->
key) || pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
1928 if (assoc->
value != NULL && pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
1937 int initial_dup_rest = dup_rest;
1944 bool regular_block_arg =
true;
1947 if (block_expr && pm_setup_args_dup_rest_p(block_expr)) {
1948 dup_rest = SPLATARRAY_TRUE | DUP_SINGLE_KW_SPLAT;
1949 initial_dup_rest = dup_rest;
1952 DECL_ANCHOR(block_arg);
1953 pm_compile_node(iseq, block, block_arg,
false, scope_node);
1955 *flags |= VM_CALL_ARGS_BLOCKARG;
1957 if (LIST_INSN_SIZE_ONE(block_arg)) {
1959 if (IS_INSN(elem)) {
1961 if (iobj->insn_id == BIN(getblockparam)) {
1962 iobj->insn_id = BIN(getblockparamproxy);
1969 regular_block_arg =
false;
1973 argc = pm_setup_args_core(arguments_node, block, flags, regular_block_arg, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
1974 PUSH_SEQ(ret, block_arg);
1977 argc = pm_setup_args_core(arguments_node, block, flags,
false, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
1984 if (*flags & VM_CALL_ARGS_SPLAT && dup_rest != initial_dup_rest) {
1985 *flags |= VM_CALL_ARGS_SPLAT_MUT;
2005 if (!popped) PUSH_INSN(ret, location, putnil);
2007 PM_COMPILE_NOT_POPPED(node->
receiver);
2009 int boff = (node->
block == NULL ? 0 : 1);
2012 int argc = pm_setup_args(node->
arguments, (
const pm_node_t *) node->
block, &flag, &keywords, iseq, ret, scope_node, node_location);
2014 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2016 PUSH_INSN(ret, location, splatkw);
2019 PUSH_INSN(ret, location, dup);
2020 PUSH_INSN(ret, location, splatkw);
2021 PUSH_INSN(ret, location, pop);
2025 int dup_argn = argc + 1 + boff;
2026 int keyword_len = 0;
2029 keyword_len = keywords->keyword_len;
2030 dup_argn += keyword_len;
2033 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2034 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2035 PM_COMPILE_NOT_POPPED(node->
value);
2038 PUSH_SEND(ret, location, id_operator,
INT2FIX(1));
2041 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2043 if (flag & VM_CALL_ARGS_SPLAT) {
2044 if (flag & VM_CALL_KW_SPLAT) {
2045 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2047 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2048 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2049 flag |= VM_CALL_ARGS_SPLAT_MUT;
2052 PUSH_INSN(ret, location, swap);
2053 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2054 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2055 PUSH_INSN(ret, location, pop);
2059 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2060 PUSH_INSN(ret, location, swap);
2061 PUSH_INSN(ret, location, pop);
2063 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2064 PUSH_INSN(ret, location, swap);
2065 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2066 PUSH_INSN(ret, location, swap);
2067 flag |= VM_CALL_ARGS_SPLAT_MUT;
2069 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2071 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2072 PUSH_INSN(ret, location, pop);
2073 PUSH_INSN(ret, location, pop);
2077 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2079 else if (flag & VM_CALL_KW_SPLAT) {
2081 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2082 PUSH_INSN(ret, location, swap);
2083 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2084 PUSH_INSN(ret, location, pop);
2086 PUSH_INSN(ret, location, swap);
2087 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2089 else if (keyword_len) {
2090 PUSH_INSN(ret, location, dup);
2091 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 2));
2092 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2093 PUSH_INSN(ret, location, pop);
2094 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2098 PUSH_INSN(ret, location, swap);
2100 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2103 PUSH_INSN(ret, location, pop);
2122 if (!popped) PUSH_INSN(ret, location, putnil);
2123 PM_COMPILE_NOT_POPPED(receiver);
2125 int boff = (block == NULL ? 0 : 1);
2128 int argc = pm_setup_args(arguments, (
const pm_node_t *) block, &flag, &keywords, iseq, ret, scope_node, node_location);
2130 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2132 PUSH_INSN(ret, location, splatkw);
2135 PUSH_INSN(ret, location, dup);
2136 PUSH_INSN(ret, location, splatkw);
2137 PUSH_INSN(ret, location, pop);
2141 int dup_argn = argc + 1 + boff;
2142 int keyword_len = 0;
2145 keyword_len = keywords->keyword_len;
2146 dup_argn += keyword_len;
2149 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2150 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2152 LABEL *label = NEW_LABEL(location.
line);
2155 PUSH_INSN(ret, location, dup);
2157 PUSH_INSNL(ret, location, branchunless, label);
2160 PUSH_INSNL(ret, location, branchif, label);
2163 PUSH_INSN(ret, location, pop);
2164 PM_COMPILE_NOT_POPPED(value);
2167 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2170 if (flag & VM_CALL_ARGS_SPLAT) {
2171 if (flag & VM_CALL_KW_SPLAT) {
2172 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2173 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2174 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2175 flag |= VM_CALL_ARGS_SPLAT_MUT;
2178 PUSH_INSN(ret, location, swap);
2179 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2180 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2181 PUSH_INSN(ret, location, pop);
2185 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2186 PUSH_INSN(ret, location, swap);
2187 PUSH_INSN(ret, location, pop);
2189 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2190 PUSH_INSN(ret, location, swap);
2191 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2192 PUSH_INSN(ret, location, swap);
2193 flag |= VM_CALL_ARGS_SPLAT_MUT;
2195 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2197 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2198 PUSH_INSN(ret, location, pop);
2199 PUSH_INSN(ret, location, pop);
2203 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2205 else if (flag & VM_CALL_KW_SPLAT) {
2207 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2208 PUSH_INSN(ret, location, swap);
2209 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2210 PUSH_INSN(ret, location, pop);
2213 PUSH_INSN(ret, location, swap);
2214 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2216 else if (keyword_len) {
2217 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2218 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 0));
2219 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2223 PUSH_INSN(ret, location, swap);
2225 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2228 PUSH_INSN(ret, location, pop);
2229 PUSH_INSNL(ret, location, jump, lfin);
2230 PUSH_LABEL(ret, label);
2232 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2234 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(dup_argn + 1));
2235 PUSH_LABEL(ret, lfin);
2244#define PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE 0
2245#define PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING 1
2246#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P 2
2247#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE 3
2248#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY 4
2253static int pm_compile_pattern(
rb_iseq_t *iseq,
pm_scope_node_t *scope_node,
const pm_node_t *node,
LINK_ANCHOR *
const ret,
LABEL *matched_label,
LABEL *unmatched_label,
bool in_single_pattern,
bool in_alternation_pattern,
bool use_deconstructed_cache,
unsigned int base_index);
2262 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2263 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2265 PUSH_INSN(ret, location, dup);
2266 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2268 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2269 PUSH_INSN1(ret, location, putobject, message);
2270 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2271 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2272 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2274 PUSH_INSN1(ret, location, putobject,
Qfalse);
2275 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2277 PUSH_INSN(ret, location, pop);
2278 PUSH_INSN(ret, location, pop);
2279 PUSH_LABEL(ret, match_succeeded_label);
2292 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2293 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2295 PUSH_INSN(ret, location, dup);
2296 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2298 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2299 PUSH_INSN1(ret, location, putobject, message);
2300 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2301 PUSH_INSN(ret, location, dup);
2302 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2303 PUSH_INSN1(ret, location, putobject, length);
2304 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(4));
2305 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2307 PUSH_INSN1(ret, location, putobject,
Qfalse);
2308 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2310 PUSH_INSN(ret, location, pop);
2311 PUSH_INSN(ret, location, pop);
2312 PUSH_LABEL(ret, match_succeeded_label);
2325 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2326 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2328 PUSH_INSN(ret, location, dup);
2329 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2330 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2332 VALUE operand = rb_fstring_lit(
"%p === %p does not return true");
2333 PUSH_INSN1(ret, location, putobject, operand);
2335 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2336 PUSH_INSN1(ret, location, topn,
INT2FIX(5));
2337 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2338 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2339 PUSH_INSN1(ret, location, putobject,
Qfalse);
2340 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2341 PUSH_INSN(ret, location, pop);
2342 PUSH_INSN(ret, location, pop);
2344 PUSH_LABEL(ret, match_succeeded_label);
2345 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2346 PUSH_INSN(ret, location, pop);
2347 PUSH_INSN(ret, location, pop);
2359pm_compile_pattern_match(
rb_iseq_t *iseq,
pm_scope_node_t *scope_node,
const pm_node_t *node,
LINK_ANCHOR *
const ret,
LABEL *unmatched_label,
bool in_single_pattern,
bool in_alternation_pattern,
bool use_deconstructed_cache,
unsigned int base_index)
2361 LABEL *matched_label = NEW_LABEL(pm_node_line_number(scope_node->parser, node));
2362 CHECK(pm_compile_pattern(iseq, scope_node, node, ret, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern, use_deconstructed_cache, base_index));
2363 PUSH_LABEL(ret, matched_label);
2373pm_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)
2375 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2377 if (use_deconstructed_cache) {
2378 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2379 PUSH_INSNL(ret, location, branchnil, deconstruct_label);
2381 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2382 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2384 PUSH_INSN(ret, location, pop);
2385 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE - 1));
2386 PUSH_INSNL(ret, location, jump, deconstructed_label);
2389 PUSH_INSNL(ret, location, jump, deconstruct_label);
2392 PUSH_LABEL(ret, deconstruct_label);
2393 PUSH_INSN(ret, location, dup);
2396 PUSH_INSN1(ret, location, putobject, operand);
2397 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2399 if (use_deconstructed_cache) {
2400 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE + 1));
2403 if (in_single_pattern) {
2404 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct"), base_index + 1));
2407 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2408 PUSH_SEND(ret, location, rb_intern(
"deconstruct"),
INT2FIX(0));
2410 if (use_deconstructed_cache) {
2411 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2414 PUSH_INSN(ret, location, dup);
2416 PUSH_INSNL(ret, location, branchunless, type_error_label);
2417 PUSH_LABEL(ret, deconstructed_label);
2429 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2431 PUSH_INSN(ret, location, dup);
2432 PM_COMPILE_NOT_POPPED(node);
2434 if (in_single_pattern) {
2435 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
2437 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
2438 if (in_single_pattern) {
2439 CHECK(pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 3));
2441 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2452 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2453 LABEL *key_error_label = NEW_LABEL(location.
line);
2454 LABEL *cleanup_label = NEW_LABEL(location.
line);
2457 kw_arg->references = 0;
2458 kw_arg->keyword_len = 2;
2459 kw_arg->keywords[0] =
ID2SYM(rb_intern(
"matchee"));
2460 kw_arg->keywords[1] =
ID2SYM(rb_intern(
"key"));
2462 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2463 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2464 PUSH_INSNL(ret, location, branchif, key_error_label);
2467 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2470 VALUE operand = rb_fstring_lit(
"%p: %s");
2471 PUSH_INSN1(ret, location, putobject, operand);
2474 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2475 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2476 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2477 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2478 PUSH_INSNL(ret, location, jump, cleanup_label);
2480 PUSH_LABEL(ret, key_error_label);
2482 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2485 VALUE operand = rb_fstring_lit(
"%p: %s");
2486 PUSH_INSN1(ret, location, putobject, operand);
2489 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2490 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2491 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2492 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2493 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2494 PUSH_SEND_R(ret, location, rb_intern(
"new"),
INT2FIX(1), NULL,
INT2FIX(VM_CALL_KWARG), kw_arg);
2495 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(1));
2496 PUSH_LABEL(ret, cleanup_label);
2498 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(7));
2499 if (!popped) PUSH_INSN(ret, location, putnil);
2500 PUSH_INSNL(ret, location, jump, done_label);
2501 PUSH_INSN1(ret, location, dupn,
INT2FIX(5));
2502 if (popped) PUSH_INSN(ret, location, putnil);
2511 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2526 const size_t posts_size = cast->
posts.
size;
2527 const size_t minimum_size = requireds_size + posts_size;
2529 bool rest_named =
false;
2530 bool use_rest_size =
false;
2532 if (cast->
rest != NULL) {
2534 use_rest_size = (rest_named || (!rest_named && posts_size > 0));
2537 LABEL *match_failed_label = NEW_LABEL(location.
line);
2538 LABEL *type_error_label = NEW_LABEL(location.
line);
2539 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2540 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2542 if (use_rest_size) {
2543 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2544 PUSH_INSN(ret, location, swap);
2549 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2552 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));
2554 PUSH_INSN(ret, location, dup);
2555 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2556 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2557 PUSH_SEND(ret, location, cast->
rest == NULL ? idEq : idGE,
INT2FIX(1));
2558 if (in_single_pattern) {
2559 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+)");
2560 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, message,
INT2FIX(minimum_size), base_index + 1));
2562 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2564 for (
size_t index = 0; index < requireds_size; index++) {
2566 PUSH_INSN(ret, location, dup);
2567 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2568 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2569 CHECK(pm_compile_pattern_match(iseq, scope_node, required, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2572 if (cast->
rest != NULL) {
2574 PUSH_INSN(ret, location, dup);
2575 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size));
2576 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2577 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2578 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2579 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2580 PUSH_INSN1(ret, location, setn,
INT2FIX(4));
2581 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2582 CHECK(pm_compile_pattern_match(iseq, scope_node, ((
const pm_splat_node_t *) cast->
rest)->expression, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2584 else if (posts_size > 0) {
2585 PUSH_INSN(ret, location, dup);
2586 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2587 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2588 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2589 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2590 PUSH_INSN(ret, location, pop);
2594 for (
size_t index = 0; index < posts_size; index++) {
2596 PUSH_INSN(ret, location, dup);
2598 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size + index));
2599 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2600 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2601 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2602 CHECK(pm_compile_pattern_match(iseq, scope_node, post, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2605 PUSH_INSN(ret, location, pop);
2606 if (use_rest_size) {
2607 PUSH_INSN(ret, location, pop);
2610 PUSH_INSNL(ret, location, jump, matched_label);
2611 PUSH_INSN(ret, location, putnil);
2612 if (use_rest_size) {
2613 PUSH_INSN(ret, location, putnil);
2616 PUSH_LABEL(ret, type_error_label);
2617 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2621 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2622 PUSH_INSN1(ret, location, putobject, operand);
2625 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2626 PUSH_INSN(ret, location, pop);
2628 PUSH_LABEL(ret, match_failed_label);
2629 PUSH_INSN(ret, location, pop);
2630 if (use_rest_size) {
2631 PUSH_INSN(ret, location, pop);
2634 PUSH_INSNL(ret, location, jump, unmatched_label);
2649 LABEL *match_failed_label = NEW_LABEL(location.
line);
2650 LABEL *type_error_label = NEW_LABEL(location.
line);
2651 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2652 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2655 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2658 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));
2660 PUSH_INSN(ret, location, dup);
2661 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2662 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2663 PUSH_SEND(ret, location, idGE,
INT2FIX(1));
2664 if (in_single_pattern) {
2665 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));
2667 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2670 LABEL *while_begin_label = NEW_LABEL(location.
line);
2671 LABEL *next_loop_label = NEW_LABEL(location.
line);
2672 LABEL *find_succeeded_label = NEW_LABEL(location.
line);
2673 LABEL *find_failed_label = NEW_LABEL(location.
line);
2675 PUSH_INSN(ret, location, dup);
2676 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2678 PUSH_INSN(ret, location, dup);
2679 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2680 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2681 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2682 PUSH_LABEL(ret, while_begin_label);
2684 PUSH_INSN(ret, location, dup);
2685 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2686 PUSH_SEND(ret, location, idLE,
INT2FIX(1));
2687 PUSH_INSNL(ret, location, branchunless, find_failed_label);
2689 for (
size_t index = 0; index < size; index++) {
2690 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2691 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2694 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2695 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2698 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2699 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
requireds.
nodes[index], ret, next_loop_label, in_single_pattern, in_alternation_pattern,
false, base_index + 4));
2705 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2706 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2707 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2708 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2709 CHECK(pm_compile_pattern_match(iseq, scope_node, left->
expression, ret, find_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 4));
2715 if (right->expression != NULL) {
2716 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2717 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2718 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2719 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2720 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2721 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2722 pm_compile_pattern_match(iseq, scope_node, right->expression, ret, find_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 4);
2725 PUSH_INSNL(ret, location, jump, find_succeeded_label);
2727 PUSH_LABEL(ret, next_loop_label);
2728 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
2729 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2730 PUSH_INSNL(ret, location, jump, while_begin_label);
2732 PUSH_LABEL(ret, find_failed_label);
2733 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2734 if (in_single_pattern) {
2735 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2738 VALUE operand = rb_fstring_lit(
"%p does not match to find pattern");
2739 PUSH_INSN1(ret, location, putobject, operand);
2742 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2743 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2744 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2746 PUSH_INSN1(ret, location, putobject,
Qfalse);
2747 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2749 PUSH_INSN(ret, location, pop);
2750 PUSH_INSN(ret, location, pop);
2752 PUSH_INSNL(ret, location, jump, match_failed_label);
2753 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2755 PUSH_LABEL(ret, find_succeeded_label);
2756 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2759 PUSH_INSN(ret, location, pop);
2760 PUSH_INSNL(ret, location, jump, matched_label);
2761 PUSH_INSN(ret, location, putnil);
2763 PUSH_LABEL(ret, type_error_label);
2764 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2768 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2769 PUSH_INSN1(ret, location, putobject, operand);
2772 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2773 PUSH_INSN(ret, location, pop);
2775 PUSH_LABEL(ret, match_failed_label);
2776 PUSH_INSN(ret, location, pop);
2777 PUSH_INSNL(ret, location, jump, unmatched_label);
2796 LABEL *match_failed_label = NEW_LABEL(location.
line);
2797 LABEL *type_error_label = NEW_LABEL(location.
line);
2800 if (has_keys && !has_rest) {
2803 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2811 rb_ary_push(keys, symbol);
2816 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2819 PUSH_INSN(ret, location, dup);
2822 VALUE operand =
ID2SYM(rb_intern(
"deconstruct_keys"));
2823 PUSH_INSN1(ret, location, putobject, operand);
2826 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2827 if (in_single_pattern) {
2828 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct_keys"), base_index + 1));
2830 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2833 PUSH_INSN(ret, location, putnil);
2836 PUSH_INSN1(ret, location, duparray, keys);
2839 PUSH_SEND(ret, location, rb_intern(
"deconstruct_keys"),
INT2FIX(1));
2841 PUSH_INSN(ret, location, dup);
2843 PUSH_INSNL(ret, location, branchunless, type_error_label);
2846 PUSH_SEND(ret, location, rb_intern(
"dup"),
INT2FIX(0));
2850 DECL_ANCHOR(match_values);
2852 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2861 PUSH_INSN(ret, location, dup);
2862 PUSH_INSN1(ret, location, putobject, symbol);
2863 PUSH_SEND(ret, location, rb_intern(
"key?"),
INT2FIX(1));
2865 if (in_single_pattern) {
2866 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2868 PUSH_INSN(ret, location, dup);
2869 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2873 PUSH_INSN1(ret, location, putobject, operand);
2876 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 2));
2877 PUSH_INSN1(ret, location, putobject,
Qtrue);
2878 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 3));
2879 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2880 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2881 PUSH_INSN1(ret, location, putobject, symbol);
2882 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2884 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(4));
2885 PUSH_LABEL(ret, match_succeeded_label);
2888 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2889 PUSH_INSN(match_values, location, dup);
2890 PUSH_INSN1(match_values, location, putobject, symbol);
2891 PUSH_SEND(match_values, location, has_rest ? rb_intern(
"delete") : idAREF,
INT2FIX(1));
2898 CHECK(pm_compile_pattern_match(iseq, scope_node, value, match_values, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2901 PUSH_SEQ(ret, match_values);
2904 PUSH_INSN(ret, location, dup);
2905 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
2906 if (in_single_pattern) {
2907 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p is not empty"), base_index + 1));
2909 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2915 PUSH_INSN(ret, location, dup);
2916 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
2917 if (in_single_pattern) {
2918 pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"rest of %p is not empty"), base_index + 1);
2920 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2925 PUSH_INSN(ret, location, dup);
2926 pm_compile_pattern_match(iseq, scope_node, splat->value, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1);
2930 rb_bug(
"unreachable");
2935 PUSH_INSN(ret, location, pop);
2936 PUSH_INSNL(ret, location, jump, matched_label);
2937 PUSH_INSN(ret, location, putnil);
2939 PUSH_LABEL(ret, type_error_label);
2940 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2944 VALUE operand = rb_fstring_lit(
"deconstruct_keys must return Hash");
2945 PUSH_INSN1(ret, location, putobject, operand);
2948 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2949 PUSH_INSN(ret, location, pop);
2951 PUSH_LABEL(ret, match_failed_label);
2952 PUSH_INSN(ret, location, pop);
2953 PUSH_INSNL(ret, location, jump, unmatched_label);
2968 LABEL *match_failed_label = NEW_LABEL(location.
line);
2970 PUSH_INSN(ret, location, dup);
2971 CHECK(pm_compile_pattern_match(iseq, scope_node, cast->
value, ret, match_failed_label, in_single_pattern, in_alternation_pattern, use_deconstructed_cache, base_index + 1));
2972 CHECK(pm_compile_pattern(iseq, scope_node, (
const pm_node_t *) cast->
target, ret, matched_label, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index));
2973 PUSH_INSN(ret, location, putnil);
2975 PUSH_LABEL(ret, match_failed_label);
2976 PUSH_INSN(ret, location, pop);
2977 PUSH_INSNL(ret, location, jump, unmatched_label);
2992 if (in_alternation_pattern) {
2993 ID id = pm_constant_id_lookup(scope_node, cast->
name);
2994 const char *name = rb_id2name(
id);
2996 if (name && strlen(name) > 0 && name[0] !=
'_') {
2997 COMPILE_ERROR(iseq, location.
line,
"illegal variable in alternative pattern (%"PRIsVALUE
")", rb_id2str(
id));
3002 PUSH_SETLOCAL(ret, location, index.index, index.level);
3003 PUSH_INSNL(ret, location, jump, matched_label);
3011 LABEL *matched_left_label = NEW_LABEL(location.
line);
3012 LABEL *unmatched_left_label = NEW_LABEL(location.
line);
3016 PUSH_INSN(ret, location, dup);
3017 CHECK(pm_compile_pattern(iseq, scope_node, cast->
left, ret, matched_left_label, unmatched_left_label, in_single_pattern,
true, use_deconstructed_cache, base_index + 1));
3022 PUSH_LABEL(ret, matched_left_label);
3023 PUSH_INSN(ret, location, pop);
3024 PUSH_INSNL(ret, location, jump, matched_label);
3025 PUSH_INSN(ret, location, putnil);
3029 PUSH_LABEL(ret, unmatched_left_label);
3030 CHECK(pm_compile_pattern(iseq, scope_node, cast->
right, ret, matched_label, unmatched_label, in_single_pattern,
true, use_deconstructed_cache, base_index));
3038 return pm_compile_pattern(iseq, scope_node, ((
const pm_parentheses_node_t *) node)->body, ret, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern, use_deconstructed_cache, base_index);
3078 PM_COMPILE_NOT_POPPED(node);
3079 if (in_single_pattern) {
3080 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
3083 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
3085 if (in_single_pattern) {
3086 pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 2);
3089 PUSH_INSNL(ret, location, branchif, matched_label);
3090 PUSH_INSNL(ret, location, jump, unmatched_label);
3099 CHECK(pm_compile_pattern(iseq, scope_node, cast->
variable, ret, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern,
true, base_index));
3133 CHECK(pm_compile_pattern_match(iseq, scope_node, statement, ret, unmatched_label, in_single_pattern, in_alternation_pattern, use_deconstructed_cache, base_index));
3134 PM_COMPILE_NOT_POPPED(predicate);
3136 if (in_single_pattern) {
3137 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3139 PUSH_INSN(ret, location, dup);
3141 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3144 PUSH_INSNL(ret, location, branchunless, match_succeeded_label);
3148 VALUE operand = rb_fstring_lit(
"guard clause does not return true");
3149 PUSH_INSN1(ret, location, putobject, operand);
3152 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
3153 PUSH_INSN1(ret, location, putobject,
Qfalse);
3154 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
3156 PUSH_INSN(ret, location, pop);
3157 PUSH_INSN(ret, location, pop);
3159 PUSH_LABEL(ret, match_succeeded_label);
3163 PUSH_INSNL(ret, location, branchunless, unmatched_label);
3166 PUSH_INSNL(ret, location, branchif, unmatched_label);
3169 PUSH_INSNL(ret, location, jump, matched_label);
3176 rb_bug(
"Unexpected node type in pattern matching expression: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
3183#undef PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE
3184#undef PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING
3185#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P
3186#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE
3187#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY
3201 scope->previous = previous;
3205 scope->parser = previous->parser;
3206 scope->encoding = previous->encoding;
3208 scope->constants = previous->constants;
3209 scope->coverage_enabled = previous->coverage_enabled;
3216 scope->body = cast->
body;
3217 scope->locals = cast->
locals;
3223 scope->body = cast->
body;
3224 scope->locals = cast->
locals;
3230 scope->body = cast->body;
3231 scope->locals = cast->locals;
3258 scope->body = cast->
body;
3259 scope->locals = cast->
locals;
3271 scope->body = cast->
body;
3272 scope->locals = cast->
locals;
3283 scope->locals = cast->locals;
3298 scope->body = cast->
body;
3299 scope->locals = cast->
locals;
3308 rb_bug(
"unreachable");
3316 if (scope_node->index_lookup_table) {
3317 st_free_table(scope_node->index_lookup_table);
3337 iobj = IS_INSN(last_elem) ? (
INSN*) last_elem : (
INSN*) get_prev_insn((
INSN*) last_elem);
3338 while (!IS_INSN_ID(iobj, send) && !IS_INSN_ID(iobj, invokesuper) && !IS_INSN_ID(iobj, sendforward) && !IS_INSN_ID(iobj, invokesuperforward)) {
3339 iobj = (
INSN*) get_prev_insn(iobj);
3341 ELEM_INSERT_NEXT(&iobj->link, (
LINK_ELEMENT*) retry_end_l);
3346 if (&iobj->link == LAST_ELEMENT(ret)) {
3354 const char *name = rb_id2name(method_id);
3355 static const char prefix[] =
"__builtin_";
3356 const size_t prefix_len =
sizeof(prefix) - 1;
3358 if (receiver == NULL) {
3359 if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) {
3361 return &name[prefix_len];
3388 if (arguments == NULL) {
3389 COMPILE_ERROR(iseq, node_location->
line,
"attr!: no argument");
3396 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to attr!: %s", pm_node_type_to_str(
PM_NODE_TYPE(argument)));
3400 VALUE symbol = pm_static_literal_value(iseq, argument, scope_node);
3403 if (strcmp(RSTRING_PTR(
string),
"leaf") == 0) {
3404 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_LEAF;
3406 else if (strcmp(RSTRING_PTR(
string),
"inline_block") == 0) {
3407 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_INLINE_BLOCK;
3409 else if (strcmp(RSTRING_PTR(
string),
"use_block") == 0) {
3410 iseq_set_use_block(iseq);
3412 else if (strcmp(RSTRING_PTR(
string),
"c_trace") == 0) {
3414 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_C_TRACE;
3417 COMPILE_ERROR(iseq, node_location->
line,
"unknown argument to attr!: %s", RSTRING_PTR(
string));
3428 if (arguments == NULL) {
3429 COMPILE_ERROR(iseq, node_location->
line,
"arg!: no argument");
3434 COMPILE_ERROR(iseq, node_location->
line,
"arg!: too many argument");
3440 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to arg!: %s", pm_node_type_to_str(
PM_NODE_TYPE(argument)));
3446 int index = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->local_table_size - get_local_var_idx(iseq, name);
3448 debugs(
"id: %s idx: %d\n", rb_id2name(name), index);
3449 PUSH_GETLOCAL(ret, *node_location, index, get_lvar_level(iseq));
3458 const pm_node_t *ast_node = scope_node->ast_node;
3460 rb_bug(
"mandatory_only?: not in method definition");
3466 if (parameters_node == NULL) {
3467 rb_bug(
"mandatory_only?: in method definition with no parameters");
3473 rb_bug(
"mandatory_only?: not in method definition with plain statements");
3479 rb_bug(
"mandatory_only?: can't find mandatory node");
3490 .name = def_node->
name,
3492 .parameters = ¶meters,
3502 pm_scope_node_init(&def.base, &next_scope_node, scope_node);
3505 ISEQ_BODY(iseq)->mandatory_only_iseq = pm_iseq_new_with_opt(
3507 rb_iseq_base_label(iseq),
3509 rb_iseq_realpath(iseq),
3510 node_location->
line,
3514 ISEQ_COMPILE_DATA(iseq)->option,
3519 RUBY_ASSERT(ISEQ_BODY(iseq)->mandatory_only_iseq == NULL);
3520 rb_jump_tag(error_state);
3523 pm_scope_node_destroy(&next_scope_node);
3532 if (parent_block != NULL) {
3533 COMPILE_ERROR(iseq, node_location->
line,
"should not call builtins here.");
3537#define BUILTIN_INLINE_PREFIX "_bi"
3538 char inline_func[
sizeof(BUILTIN_INLINE_PREFIX) +
DECIMAL_SIZE_OF(
int)];
3539 bool cconst =
false;
3544 if (strcmp(
"cstmt!", builtin_func) == 0 || strcmp(
"cexpr!", builtin_func) == 0) {
3547 else if (strcmp(
"cconst!", builtin_func) == 0) {
3550 else if (strcmp(
"cinit!", builtin_func) == 0) {
3554 else if (strcmp(
"attr!", builtin_func) == 0) {
3555 return pm_compile_builtin_attr(iseq, scope_node, arguments, node_location);
3557 else if (strcmp(
"arg!", builtin_func) == 0) {
3558 return pm_compile_builtin_arg(iseq, ret, scope_node, arguments, node_location, popped);
3560 else if (strcmp(
"mandatory_only?", builtin_func) == 0) {
3562 rb_bug(
"mandatory_only? should be in if condition");
3564 else if (!LIST_INSN_SIZE_ZERO(ret)) {
3565 rb_bug(
"mandatory_only? should be put on top");
3568 PUSH_INSN1(ret, *node_location, putobject,
Qfalse);
3569 return pm_compile_builtin_mandatory_only_method(iseq, scope_node, call_node, node_location);
3572 rb_bug(
"can't find builtin function:%s", builtin_func);
3575 COMPILE_ERROR(iseq, node_location->
line,
"can't find builtin function:%s", builtin_func);
3579 int inline_index = node_location->
line;
3580 snprintf(inline_func,
sizeof(inline_func), BUILTIN_INLINE_PREFIX
"%d", inline_index);
3581 builtin_func = inline_func;
3587 typedef VALUE(*builtin_func0)(
void *,
VALUE);
3588 VALUE const_val = (*(builtin_func0)(uintptr_t)bf->func_ptr)(NULL,
Qnil);
3589 PUSH_INSN1(ret, *node_location, putobject, const_val);
3595 DECL_ANCHOR(args_seq);
3599 int argc = pm_setup_args(arguments, call_node->
block, &flags, &keywords, iseq, args_seq, scope_node, node_location);
3601 if (argc != bf->argc) {
3602 COMPILE_ERROR(iseq, node_location->
line,
"argc is not match for builtin function:%s (expect %d but %d)", builtin_func, bf->argc, argc);
3606 unsigned int start_index;
3607 if (delegate_call_p(iseq, argc, args_seq, &start_index)) {
3608 PUSH_INSN2(ret, *node_location, opt_invokebuiltin_delegate, bf,
INT2FIX(start_index));
3611 PUSH_SEQ(ret, args_seq);
3612 PUSH_INSN1(ret, *node_location, invokebuiltin, bf);
3615 if (popped) PUSH_INSN(ret, *node_location, pop);
3629 LABEL *else_label = NEW_LABEL(location.
line);
3630 LABEL *end_label = NEW_LABEL(location.
line);
3631 LABEL *retry_end_l = NEW_LABEL(location.
line);
3635 int node_id = location.
node_id;
3638 if (PM_BRANCH_COVERAGE_P(iseq)) {
3639 const uint8_t *cursors[3] = {
3645 const uint8_t *end_cursor = cursors[0];
3646 end_cursor = (end_cursor == NULL || cursors[1] == NULL) ? cursors[1] : (end_cursor > cursors[1] ? end_cursor : cursors[1]);
3647 end_cursor = (end_cursor == NULL || cursors[2] == NULL) ? cursors[2] : (end_cursor > cursors[2] ? end_cursor : cursors[2]);
3650 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(scope_node->parser, call_node);
3654 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
3655 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
3658 branches = decl_branch_base(iseq, PTR2NUM(call_node), &code_location,
"&.");
3661 PUSH_INSN(ret, location, dup);
3662 PUSH_INSNL(ret, location, branchnil, else_label);
3664 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0,
"then", branches);
3670 int orig_argc = pm_setup_args(call_node->
arguments, call_node->
block, &flags, &kw_arg, iseq, ret, scope_node, &location);
3671 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
3677 pm_scope_node_init(call_node->
block, &next_scope_node, scope_node);
3679 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, pm_node_line_number(scope_node->parser, call_node->
block));
3680 pm_scope_node_destroy(&next_scope_node);
3681 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
3685 flags |= VM_CALL_VCALL;
3689 flags |= VM_CALL_ARGS_SIMPLE;
3694 flags |= VM_CALL_FCALL;
3698 if (flags & VM_CALL_ARGS_BLOCKARG) {
3699 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
3700 if (flags & VM_CALL_ARGS_SPLAT) {
3701 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3702 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3704 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 3));
3705 PUSH_INSN(ret, location, pop);
3707 else if (flags & VM_CALL_ARGS_SPLAT) {
3708 PUSH_INSN(ret, location, dup);
3709 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3710 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3711 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 2));
3712 PUSH_INSN(ret, location, pop);
3715 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 1));
3719 if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
3720 PUSH_INSN(ret, location, splatkw);
3723 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3725 if (block_iseq && ISEQ_BODY(block_iseq)->catch_table) {
3726 pm_compile_retry_end_label(iseq, ret, retry_end_l);
3727 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, start, retry_end_l, block_iseq, retry_end_l);
3731 PUSH_INSNL(ret, location, jump, end_label);
3732 PUSH_LABEL(ret, else_label);
3733 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 1,
"else", branches);
3734 PUSH_LABEL(ret, end_label);
3738 PUSH_INSN(ret, location, pop);
3741 if (popped) PUSH_INSN(ret, location, pop);
3742 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
3749 enum defined_type dtype = DEFINED_NOT_DEFINED;
3756 for (
size_t idx = 0; idx < arguments->
size; idx++) {
3758 pm_compile_defined_expr0(iseq, argument, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
3761 lfinish[1] = NEW_LABEL(location.
line);
3763 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
3765 dtype = DEFINED_TRUE;
3769 dtype = DEFINED_NIL;
3774 if (cast->
body == NULL) {
3776 dtype = DEFINED_NIL;
3781 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);
3787 dtype = DEFINED_EXPR;
3793 dtype = DEFINED_SELF;
3796 dtype = DEFINED_TRUE;
3799 dtype = DEFINED_FALSE;
3805 lfinish[1] = NEW_LABEL(location.
line);
3808 for (
size_t index = 0; index < cast->
elements.
size; index++) {
3809 pm_compile_defined_expr0(iseq, cast->
elements.
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
3810 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
3813 dtype = DEFINED_EXPR;
3827 if (elements->
size > 0 && !lfinish[1]) {
3828 lfinish[1] = NEW_LABEL(location.
line);
3831 for (
size_t index = 0; index < elements->
size; index++) {
3838 pm_compile_defined_expr0(iseq, assoc->
key, node_location, ret, popped, scope_node,
true, lfinish,
false);
3839 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
3841 pm_compile_defined_expr0(iseq, assoc->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
3842 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
3849 pm_compile_defined_expr0(iseq, assoc_splat->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
3850 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
3855 rb_bug(
"unexpected node type in hash node: %s", pm_node_type_to_str(
PM_NODE_TYPE(element)));
3860 dtype = DEFINED_EXPR;
3865 pm_compile_defined_expr0(iseq, cast->
expression, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
3868 lfinish[1] = NEW_LABEL(location.
line);
3871 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
3872 dtype = DEFINED_EXPR;
3877 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
3920 dtype = DEFINED_EXPR;
3923 dtype = DEFINED_LVAR;
3926#define PUSH_VAL(type) (in_condition ? Qtrue : rb_iseq_defined_string(type))
3931 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3932 PUSH_INSN3(ret, location, definedivar,
ID2SYM(name), get_ivar_ic_value(iseq, name), PUSH_VAL(DEFINED_IVAR));
3937 const char *char_ptr = (
const char *) (node->
location.
start + 1);
3938 ID backref_val =
INT2FIX(rb_intern2(char_ptr, 1)) << 1 | 1;
3940 PUSH_INSN(ret, location, putnil);
3941 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), backref_val, PUSH_VAL(DEFINED_GVAR));
3948 PUSH_INSN(ret, location, putnil);
3949 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF),
INT2FIX(reference_number << 1), PUSH_VAL(DEFINED_GVAR));
3957 PUSH_INSN(ret, location, putnil);
3958 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name, PUSH_VAL(DEFINED_GVAR));
3966 PUSH_INSN(ret, location, putnil);
3967 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name, PUSH_VAL(DEFINED_CVAR));
3975 PUSH_INSN(ret, location, putnil);
3976 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name, PUSH_VAL(DEFINED_CONST));
3984 if (cast->
parent != NULL) {
3985 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
3986 pm_compile_defined_expr0(iseq, cast->
parent, node_location, ret, popped, scope_node,
true, lfinish,
false);
3988 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
3989 PM_COMPILE(cast->
parent);
3992 PUSH_INSN1(ret, location, putobject, rb_cObject);
3995 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name, PUSH_VAL(DEFINED_CONST));
3999#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE))
4003 if (BLOCK_P(cast)) {
4004 dtype = DEFINED_EXPR;
4008 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4011 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4012 if (!lfinish[2]) lfinish[2] = NEW_LABEL(location.
line);
4016 pm_compile_defined_expr0(iseq, (
const pm_node_t *) cast->
arguments, node_location, ret, popped, scope_node,
true, lfinish,
false);
4017 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4022 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
true);
4023 PUSH_INSNL(ret, location, branchunless, lfinish[2]);
4026 ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
4027 pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
4030 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
false);
4031 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4035 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4036 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_METHOD),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4039 PUSH_INSN(ret, location, putself);
4040 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4041 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_FUNC),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4049 PUSH_INSN(ret, location, putnil);
4050 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
4051 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
4055 PUSH_INSN(ret, location, putnil);
4056 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
4097 dtype = DEFINED_ASGN;
4100 rb_bug(
"Unsupported node %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
4104 PUSH_INSN1(ret, location, putobject, PUSH_VAL(dtype));
4112 pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4115 LABEL *lstart = NEW_LABEL(node_location->
line);
4116 LABEL *lend = NEW_LABEL(node_location->
line);
4119 rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
4121 const rb_iseq_t *rescue = new_child_iseq_with_callback(
4130 lstart->rescued = LABEL_RESCUE_BEG;
4131 lend->rescued = LABEL_RESCUE_END;
4133 APPEND_LABEL(ret, lcur, lstart);
4134 PUSH_LABEL(ret, lend);
4135 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
4145 lfinish[0] = NEW_LABEL(node_location->
line);
4150 pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish);
4154 ELEM_INSERT_NEXT(last, &new_insn_body(iseq, node_location->
line, node_location->
node_id, BIN(putnil), 0)->link);
4155 PUSH_INSN(ret, *node_location, swap);
4157 if (lfinish[2]) PUSH_LABEL(ret, lfinish[2]);
4158 PUSH_INSN(ret, *node_location, pop);
4159 PUSH_LABEL(ret, lfinish[1]);
4163 PUSH_LABEL(ret, lfinish[0]);
4174 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
4176 DECL_ANCHOR(ensure);
4179 if (enlp->erange != NULL) {
4180 DECL_ANCHOR(ensure_part);
4181 LABEL *lstart = NEW_LABEL(0);
4182 LABEL *lend = NEW_LABEL(0);
4184 add_ensure_range(iseq, enlp->erange, lstart, lend);
4186 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
4187 PUSH_LABEL(ensure_part, lstart);
4189 PM_COMPILE_INTO_ANCHOR(ensure_part, (
const pm_node_t *) enlp->ensure_node);
4190 PUSH_LABEL(ensure_part, lend);
4191 PUSH_SEQ(ensure, ensure_part);
4200 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
4201 PUSH_SEQ(ret, ensure);
4211pm_local_table_insert_func(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
4219 int local_index = ctx->local_index;
4221 ID local = pm_constant_id_lookup(scope_node, constant_id);
4222 local_table_for_iseq->ids[local_index] = local;
4224 *value = (st_data_t)local_index;
4240 RUBY_ASSERT((constant_id & PM_SPECIAL_CONSTANT_FLAG) == 0);
4242 ID local = pm_constant_id_lookup(scope_node, constant_id);
4243 local_table_for_iseq->ids[local_index] = local;
4244 st_insert(index_lookup_table, (st_data_t) constant_id, (st_data_t) local_index);
4254 local_table_for_iseq->ids[local_index] = local_name;
4255 st_insert(index_lookup_table, (st_data_t) (local_name | PM_SPECIAL_CONSTANT_FLAG), (st_data_t) local_index);
4267 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4272 pm_insert_local_index(((
const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4278 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);
4285 if (rest->expression != NULL) {
4289 pm_insert_local_index(((
const pm_required_parameter_node_t *) rest->expression)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4295 for (
size_t index = 0; index < node->
rights.
size; index++) {
4300 pm_insert_local_index(((
const pm_required_parameter_node_t *) right)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4306 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);
4320 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4322 PUSH_SETLOCAL(ret, location, index.index, index.level);
4336 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4340 int flag = (has_rest || has_rights) ? 1 : 0;
4343 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4371 for (
size_t index = 0; index < node->
rights.
size; index++) {
4438 node->stack_index = state->stack_size + 1;
4439 node->stack_size = stack_size;
4440 node->position = state->position;
4443 if (state->head == NULL) {
4448 state->tail->next = node;
4452 state->stack_size += stack_size;
4465 if (state->stack_size == 0)
return;
4470 while (current != NULL) {
4471 VALUE offset =
INT2FIX(state->stack_size - current->stack_index + current->position);
4472 current->topn->operands[0] = offset;
4478 if (current->stack_size > 1) {
4479 INSN *insn = current->topn;
4481 for (
size_t index = 1; index < current->stack_size; index += 1) {
4485 insn = (
INSN *) element;
4488 insn->operands[0] = offset;
4493 current = current->next;
4533 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4545 PUSH_SETLOCAL(writes, location, index.index, index.level);
4555 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4558 PUSH_INSN2(writes, location, setclassvariable, operand, get_cvar_ic_value(iseq, name));
4568 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4571 PUSH_INSN1(writes, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
4572 PUSH_INSN1(writes, location, setconstant, operand);
4582 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4585 PUSH_INSN1(writes, location, setglobal, operand);
4595 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4598 PUSH_INSN2(writes, location, setinstancevariable, operand, get_ivar_ic_value(iseq, name));
4611 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4613 if (cast->
parent != NULL) {
4614 pm_compile_node(iseq, cast->
parent, parents,
false, scope_node);
4617 PUSH_INSN1(parents, location, putobject, rb_cObject);
4620 if (state == NULL) {
4621 PUSH_INSN(writes, location, swap);
4624 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
4625 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
4629 PUSH_INSN1(writes, location, setconstant, operand);
4631 if (state != NULL) {
4632 PUSH_INSN(cleanup, location, pop);
4647 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4649 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
4651 LABEL *safe_label = NULL;
4653 safe_label = NEW_LABEL(location.
line);
4654 PUSH_INSN(parents, location, dup);
4655 PUSH_INSNL(parents, location, branchnil, safe_label);
4658 if (state != NULL) {
4659 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
4660 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), 1);
4661 PUSH_INSN(writes, location, swap);
4664 int flags = VM_CALL_ARGS_SIMPLE;
4667 PUSH_SEND_WITH_FLAG(writes, location, method_id,
INT2FIX(1),
INT2FIX(flags));
4668 if (safe_label != NULL && state == NULL) PUSH_LABEL(writes, safe_label);
4669 PUSH_INSN(writes, location, pop);
4670 if (safe_label != NULL && state != NULL) PUSH_LABEL(writes, safe_label);
4672 if (state != NULL) {
4673 PUSH_INSN(cleanup, location, pop);
4690 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
4694 int argc = pm_setup_args(cast->
arguments, (
const pm_node_t *) cast->
block, &flags, &kwargs, iseq, parents, scope_node, &location);
4696 if (state != NULL) {
4697 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
4698 pm_multi_target_state_push(state, (
INSN *) LAST_ELEMENT(writes), argc + 1);
4701 PUSH_INSN(writes, location, swap);
4704 for (
int index = 0; index < argc; index++) {
4705 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
4707 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
4715 int ci_argc = argc + 1;
4716 if (flags & VM_CALL_ARGS_SPLAT) {
4718 PUSH_INSN1(writes, location, newarray,
INT2FIX(1));
4719 PUSH_INSN(writes, location, concatarray);
4722 PUSH_SEND_R(writes, location, idASET,
INT2NUM(ci_argc), NULL,
INT2FIX(flags), kwargs);
4723 PUSH_INSN(writes, location, pop);
4725 if (state != NULL) {
4727 PUSH_INSN(writes, location, pop);
4730 for (
int index = 0; index < argc + 1; index++) {
4731 PUSH_INSN(cleanup, location, pop);
4744 size_t before_position;
4745 if (state != NULL) {
4746 before_position = state->position;
4750 pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, scope_node, state);
4751 if (state != NULL) state->position = before_position;
4756 rb_bug(
"Unexpected node type: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
4769 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4777 lefts = &cast->
lefts;
4784 lefts = &cast->
lefts;
4790 rb_bug(
"Unsupported node %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
4795 bool has_posts = rights->
size > 0;
4800 PUSH_INSN2(writes, location, expandarray,
INT2FIX(lefts->
size),
INT2FIX((has_rest || has_posts) ? 1 : 0));
4806 if (state == NULL) state = &target_state;
4808 size_t base_position = state->position;
4809 size_t splat_position = (has_rest || has_posts) ? 1 : 0;
4812 for (
size_t index = 0; index < lefts->
size; index++) {
4814 state->position = lefts->
size - index + splat_position + base_position;
4815 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
4821 state->position = 1 + rights->
size + base_position;
4827 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
4832 if (!has_rest && rest != NULL) {
4836 for (
size_t index = 0; index < rights->
size; index++) {
4838 state->position = rights->
size - index + base_position;
4839 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
4852 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4858 PUSH_GETLOCAL(ret, location, 1, 0);
4859 pm_compile_target_node(iseq, node, ret, ret, ret, scope_node, NULL);
4872 DECL_ANCHOR(writes);
4873 DECL_ANCHOR(cleanup);
4877 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
4879 PUSH_GETLOCAL(ret, location, 1, 0);
4882 PUSH_SEQ(ret, writes);
4883 PUSH_SEQ(ret, cleanup);
4885 pm_multi_target_state_update(&state);
4889 DECL_ANCHOR(writes);
4890 DECL_ANCHOR(cleanup);
4892 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, NULL);
4894 LABEL *not_single = NEW_LABEL(location.
line);
4895 LABEL *not_ary = NEW_LABEL(location.
line);
4903 PUSH_GETLOCAL(ret, location, 1, 0);
4904 PUSH_INSN(ret, location, dup);
4905 PUSH_CALL(ret, location, idLength,
INT2FIX(0));
4906 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
4907 PUSH_CALL(ret, location, idEq,
INT2FIX(1));
4908 PUSH_INSNL(ret, location, branchunless, not_single);
4909 PUSH_INSN(ret, location, dup);
4910 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
4911 PUSH_CALL(ret, location, idAREF,
INT2FIX(1));
4912 PUSH_INSN1(ret, location, putobject,
rb_cArray);
4913 PUSH_INSN(ret, location, swap);
4914 PUSH_CALL(ret, location, rb_intern(
"try_convert"),
INT2FIX(1));
4915 PUSH_INSN(ret, location, dup);
4916 PUSH_INSNL(ret, location, branchunless, not_ary);
4917 PUSH_INSN(ret, location, swap);
4919 PUSH_LABEL(ret, not_ary);
4920 PUSH_INSN(ret, location, pop);
4922 PUSH_LABEL(ret, not_single);
4923 PUSH_SEQ(ret, writes);
4924 PUSH_SEQ(ret, cleanup);
4928 rb_bug(
"Unexpected node type for index in for node: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
4938 LABEL *lstart = NEW_LABEL(node_location->
line);
4939 LABEL *lend = NEW_LABEL(node_location->
line);
4940 LABEL *lcont = NEW_LABEL(node_location->
line);
4945 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
4952 pm_scope_node_destroy(&rescue_scope_node);
4954 lstart->rescued = LABEL_RESCUE_BEG;
4955 lend->rescued = LABEL_RESCUE_END;
4956 PUSH_LABEL(ret, lstart);
4958 bool prev_in_rescue = ISEQ_COMPILE_DATA(iseq)->in_rescue;
4959 ISEQ_COMPILE_DATA(iseq)->in_rescue =
true;
4966 PUSH_INSN(ret, location, putnil);
4969 ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;
4970 PUSH_LABEL(ret, lend);
4973 if (!popped) PUSH_INSN(ret, *node_location, pop);
4977 PUSH_INSN(ret, *node_location, nop);
4978 PUSH_LABEL(ret, lcont);
4980 if (popped) PUSH_INSN(ret, *node_location, pop);
4981 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
4982 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
4992 if (statements != NULL) {
4993 location = PM_NODE_START_LOCATION(parser, statements);
4996 location = *node_location;
4999 LABEL *lstart = NEW_LABEL(location.
line);
5001 LABEL *lcont = NEW_LABEL(location.
line);
5008 if (statements != NULL) {
5009 pm_compile_node(iseq, (
const pm_node_t *) statements, ensr,
true, scope_node);
5013 bool last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
5018 push_ensure_entry(iseq, &enl, &er, (
void *) cast->
ensure_clause);
5020 PUSH_LABEL(ret, lstart);
5022 pm_compile_rescue(iseq, cast, node_location, ret, popped | last_leave, scope_node);
5025 pm_compile_node(iseq, (
const pm_node_t *) cast->
statements, ret, popped | last_leave, scope_node);
5027 else if (!(popped | last_leave)) {
5028 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
5031 PUSH_LABEL(ret, lend);
5032 PUSH_SEQ(ret, ensr);
5033 if (!popped && last_leave) PUSH_INSN(ret, *node_location, putnil);
5034 PUSH_LABEL(ret, lcont);
5035 if (last_leave) PUSH_INSN(ret, *node_location, pop);
5047 pm_scope_node_destroy(&next_scope_node);
5049 erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
5050 if (lstart->link.next != &lend->link) {
5052 PUSH_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, child_iseq, lcont);
5053 erange = erange->next;
5056 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
5071 node->
block == NULL &&
5072 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5089 node->
block == NULL &&
5091 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5108 node->
block == NULL &&
5110 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5121 const pm_node_location_t location = PM_LOCATION_START_LOCATION(scope_node->parser, name_loc, node_id);
5123 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
5124 ISEQ_BODY(iseq)->ic_size++;
5125 VALUE segments = rb_ary_new_from_args(1, name);
5126 PUSH_INSN1(ret, location, opt_getconstant_path, segments);
5129 PUSH_INSN(ret, location, putnil);
5130 PUSH_INSN1(ret, location, putobject,
Qtrue);
5131 PUSH_INSN1(ret, location, getconstant, name);
5142 VALUE parts = rb_ary_new();
5150 rb_ary_unshift(parts, name);
5157 rb_ary_unshift(parts, name);
5158 if (cast->
parent == NULL) {
5159 rb_ary_unshift(parts,
ID2SYM(idNULL));
5180 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5187 PUSH_INSN1(body, location, putobject,
Qtrue);
5188 PUSH_INSN1(body, location, getconstant, name);
5195 if (cast->
parent == NULL) {
5196 PUSH_INSN(body, location, pop);
5197 PUSH_INSN1(body, location, putobject, rb_cObject);
5198 PUSH_INSN1(body, location, putobject,
Qtrue);
5199 PUSH_INSN1(body, location, getconstant, name);
5202 pm_compile_constant_path(iseq, cast->
parent, prefix, body,
false, scope_node);
5203 PUSH_INSN1(body, location, putobject,
Qfalse);
5204 PUSH_INSN1(body, location, getconstant, name);
5209 PM_COMPILE_INTO_ANCHOR(prefix, node);
5232 return pm_static_literal_value(iseq, node, scope_node);
5234 return parse_static_literal_string(iseq, scope_node, node, &((
const pm_string_node_t *) node)->unescaped);
5241 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5242 VALUE element = pm_compile_shareable_constant_literal(iseq, cast->
elements.
nodes[index], scope_node);
5245 rb_ary_push(result, element);
5254 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5260 VALUE key = pm_compile_shareable_constant_literal(iseq, assoc->
key, scope_node);
5263 VALUE value = pm_compile_shareable_constant_literal(iseq, assoc->
value, scope_node);
5266 rb_hash_aset(result, key, value);
5283 VALUE literal = pm_compile_shareable_constant_literal(iseq, node, scope_node);
5285 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5286 PUSH_INSN1(ret, location, putobject, literal);
5290 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5296 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5299 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5300 pm_compile_shareable_constant_value(iseq, cast->
elements.
nodes[index], shareability, path, ret, scope_node,
false);
5307 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5316 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5319 pm_compile_hash_elements(iseq, (
const pm_node_t *) cast, &cast->elements, shareability, path,
false, ret, scope_node);
5323 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5329 DECL_ANCHOR(value_seq);
5331 pm_compile_node(iseq, node, value_seq,
false, scope_node);
5333 PUSH_SEND_WITH_FLAG(value_seq, location, idUMinus,
INT2FIX(0),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5337 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5338 PUSH_SEQ(ret, value_seq);
5339 PUSH_INSN1(ret, location, putobject, path);
5340 PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"ensure_shareable"),
INT2FIX(2),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5343 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5344 PUSH_SEQ(ret, value_seq);
5345 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable_copy"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5348 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5349 PUSH_SEQ(ret, value_seq);
5350 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5366 ID name_id = pm_constant_id_lookup(scope_node, node->
name);
5368 if (shareability != 0) {
5369 pm_compile_shareable_constant_value(iseq, node->
value, shareability, rb_id2str(name_id), ret, scope_node,
true);
5372 PM_COMPILE_NOT_POPPED(node->
value);
5375 if (!popped) PUSH_INSN(ret, location, dup);
5376 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5379 PUSH_INSN1(ret, location, setconstant, operand);
5392 LABEL *end_label = NEW_LABEL(location.
line);
5394 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5395 if (!popped) PUSH_INSN(ret, location, dup);
5397 PUSH_INSNL(ret, location, branchunless, end_label);
5398 if (!popped) PUSH_INSN(ret, location, pop);
5400 if (shareability != 0) {
5401 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5404 PM_COMPILE_NOT_POPPED(node->
value);
5407 if (!popped) PUSH_INSN(ret, location, dup);
5408 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5409 PUSH_INSN1(ret, location, setconstant, name);
5410 PUSH_LABEL(ret, end_label);
5423 LABEL *set_label = NEW_LABEL(location.
line);
5424 LABEL *end_label = NEW_LABEL(location.
line);
5426 PUSH_INSN(ret, location, putnil);
5427 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name,
Qtrue);
5428 PUSH_INSNL(ret, location, branchunless, set_label);
5430 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5431 if (!popped) PUSH_INSN(ret, location, dup);
5433 PUSH_INSNL(ret, location, branchif, end_label);
5434 if (!popped) PUSH_INSN(ret, location, pop);
5435 PUSH_LABEL(ret, set_label);
5437 if (shareability != 0) {
5438 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5441 PM_COMPILE_NOT_POPPED(node->
value);
5444 if (!popped) PUSH_INSN(ret, location, dup);
5445 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5446 PUSH_INSN1(ret, location, setconstant, name);
5447 PUSH_LABEL(ret, end_label);
5462 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5464 if (shareability != 0) {
5465 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5468 PM_COMPILE_NOT_POPPED(node->
value);
5471 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5472 if (!popped) PUSH_INSN(ret, location, dup);
5474 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5475 PUSH_INSN1(ret, location, setconstant, name);
5485 VALUE parts = rb_ary_new();
5486 rb_ary_push(parts, rb_id2str(pm_constant_id_lookup(scope_node, node->
name)));
5491 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, cast->
name)));
5495 if (current == NULL) {
5496 rb_ary_unshift(parts, rb_id2str(idNULL));
5499 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, ((
const pm_constant_read_node_t *) current)->name)));
5523 PUSH_INSN1(ret, location, putobject, rb_cObject);
5526 if (shareability != 0) {
5527 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5530 PM_COMPILE_NOT_POPPED(node->
value);
5534 PUSH_INSN(ret, location, swap);
5535 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
5538 PUSH_INSN(ret, location, swap);
5539 PUSH_INSN1(ret, location, setconstant, name);
5556 PM_COMPILE_NOT_POPPED(target->
parent);
5559 PUSH_INSN1(ret, location, putobject, rb_cObject);
5562 PUSH_INSN(ret, location, dup);
5563 PUSH_INSN1(ret, location, putobject,
Qtrue);
5564 PUSH_INSN1(ret, location, getconstant, name);
5566 if (!popped) PUSH_INSN(ret, location, dup);
5567 PUSH_INSNL(ret, location, branchunless, lfin);
5569 if (!popped) PUSH_INSN(ret, location, pop);
5571 if (shareability != 0) {
5572 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5575 PM_COMPILE_NOT_POPPED(node->
value);
5579 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
5582 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
5583 PUSH_INSN(ret, location, swap);
5586 PUSH_INSN1(ret, location, setconstant, name);
5587 PUSH_LABEL(ret, lfin);
5589 if (!popped) PUSH_INSN(ret, location, swap);
5590 PUSH_INSN(ret, location, pop);
5604 LABEL *lassign = NEW_LABEL(location.
line);
5608 PM_COMPILE_NOT_POPPED(target->
parent);
5611 PUSH_INSN1(ret, location, putobject, rb_cObject);
5614 PUSH_INSN(ret, location, dup);
5615 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name,
Qtrue);
5616 PUSH_INSNL(ret, location, branchunless, lassign);
5618 PUSH_INSN(ret, location, dup);
5619 PUSH_INSN1(ret, location, putobject,
Qtrue);
5620 PUSH_INSN1(ret, location, getconstant, name);
5622 if (!popped) PUSH_INSN(ret, location, dup);
5623 PUSH_INSNL(ret, location, branchif, lfin);
5625 if (!popped) PUSH_INSN(ret, location, pop);
5626 PUSH_LABEL(ret, lassign);
5628 if (shareability != 0) {
5629 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5632 PM_COMPILE_NOT_POPPED(node->
value);
5636 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
5639 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
5640 PUSH_INSN(ret, location, swap);
5643 PUSH_INSN1(ret, location, setconstant, name);
5644 PUSH_LABEL(ret, lfin);
5646 if (!popped) PUSH_INSN(ret, location, swap);
5647 PUSH_INSN(ret, location, pop);
5664 PM_COMPILE_NOT_POPPED(target->
parent);
5667 PUSH_INSN1(ret, location, putobject, rb_cObject);
5670 PUSH_INSN(ret, location, dup);
5671 PUSH_INSN1(ret, location, putobject,
Qtrue);
5672 PUSH_INSN1(ret, location, getconstant, name);
5674 if (shareability != 0) {
5675 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5678 PM_COMPILE_NOT_POPPED(node->
value);
5681 PUSH_CALL(ret, location, method_id,
INT2FIX(1));
5682 PUSH_INSN(ret, location, swap);
5685 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
5686 PUSH_INSN(ret, location, swap);
5689 PUSH_INSN1(ret, location, setconstant, name);
5698#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))
5717 bool trailing_comma =
false;
5723 if (scope_node->parameters != NULL) {
5727 parameters_node = cast->parameters;
5728 block_locals = &cast->locals;
5730 if (parameters_node) {
5732 trailing_comma =
true;
5743 body->
param.lead_num = maximum;
5744 body->
param.flags.ambiguous_param0 = maximum == 1;
5748 body->
param.lead_num = 1;
5749 body->
param.flags.ambiguous_param0 =
true;
5752 rb_bug(
"Unexpected node type for parameters: %s", pm_node_type_to_str(
PM_NODE_TYPE(scope_node->parameters)));
5756 struct rb_iseq_param_keyword *keyword = NULL;
5758 if (parameters_node) {
5759 optionals_list = ¶meters_node->
optionals;
5760 requireds_list = ¶meters_node->
requireds;
5761 keywords_list = ¶meters_node->
keywords;
5762 posts_list = ¶meters_node->
posts;
5765 body->
param.opt_num = 0;
5768 body->
param.lead_num = 0;
5769 body->
param.opt_num = 0;
5775 size_t locals_size = locals->
size;
5778 st_table *index_lookup_table = st_init_numtable();
5780 int table_size = (int) locals_size;
5786 if (keywords_list && keywords_list->
size) {
5790 if (requireds_list) {
5791 for (
size_t i = 0; i < requireds_list->
size; i++) {
5817 if (optionals_list && optionals_list->
size) {
5818 for (
size_t i = 0; i < optionals_list->
size; i++) {
5830 if (parameters_node) {
5831 if (parameters_node->
rest) {
5848 if (requireds_list->
size == 0 && optionals_list->
size == 0 && keywords_list->
size == 0) {
5849 ISEQ_BODY(iseq)->param.flags.use_block = TRUE;
5850 ISEQ_BODY(iseq)->param.flags.forwardable = TRUE;
5869 for (
size_t i = 0; i < posts_list->
size; i++) {
5880 if (keywords_list && keywords_list->
size) {
5881 for (
size_t i = 0; i < keywords_list->
size; i++) {
5889 if (parameters_node && parameters_node->
block) {
5900 local_table_for_iseq->size = table_size;
5920 int local_index = 0;
5927 if (requireds_list && requireds_list->
size) {
5928 for (
size_t i = 0; i < requireds_list->
size; i++, local_index++) {
5940 local = rb_make_temporary_id(local_index);
5941 local_table_for_iseq->ids[local_index] = local;
5950 ID local = pm_constant_id_lookup(scope_node, param->
name);
5951 local_table_for_iseq->ids[local_index] = local;
5954 pm_insert_local_index(param->
name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
5960 rb_bug(
"Unsupported node in requireds in parameters %s", pm_node_type_to_str(
PM_NODE_TYPE(required)));
5964 body->
param.lead_num = (int) requireds_list->
size;
5965 body->
param.flags.has_lead =
true;
5969 ID local = rb_make_temporary_id(local_index);
5970 local_table_for_iseq->ids[local_index++] = local;
5975 if (optionals_list && optionals_list->
size) {
5976 body->
param.opt_num = (int) optionals_list->
size;
5977 body->
param.flags.has_opt =
true;
5979 for (
size_t i = 0; i < optionals_list->
size; i++, local_index++) {
5984 ID local = pm_constant_id_lookup(scope_node, name);
5985 local_table_for_iseq->ids[local_index] = local;
5988 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
5995 if (parameters_node && parameters_node->
rest) {
5996 body->
param.rest_start = local_index;
6001 body->
param.flags.has_rest =
true;
6010 ID local = pm_constant_id_lookup(scope_node, name);
6011 local_table_for_iseq->ids[local_index] = local;
6014 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6020 body->
param.flags.anon_rest =
true;
6021 pm_insert_local_special(idMULT, local_index, index_lookup_table, local_table_for_iseq);
6030 if (posts_list && posts_list->
size) {
6031 body->
param.post_num = (int) posts_list->
size;
6032 body->
param.post_start = local_index;
6033 body->
param.flags.has_post =
true;
6035 for (
size_t i = 0; i < posts_list->
size; i++, local_index++) {
6047 local = rb_make_temporary_id(local_index);
6048 local_table_for_iseq->ids[local_index] = local;
6057 ID local = pm_constant_id_lookup(scope_node, param->
name);
6058 local_table_for_iseq->ids[local_index] = local;
6061 pm_insert_local_index(param->
name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6066 rb_bug(
"Unsupported node in posts in parameters %s", pm_node_type_to_str(
PM_NODE_TYPE(post_node)));
6074 if (keywords_list && keywords_list->
size) {
6075 keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6076 keyword->num = (int) keywords_list->
size;
6078 const VALUE default_values = rb_ary_hidden_new(1);
6081 for (
size_t i = 0; i < keywords_list->
size; i++) {
6089 keyword->required_num++;
6090 ID local = pm_constant_id_lookup(scope_node, name);
6093 local_table_for_iseq->ids[local_index] = local;
6096 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6102 for (
size_t i = 0; i < keywords_list->
size; i++) {
6114 if (
PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) {
6115 rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node));
6118 rb_ary_push(default_values, complex_mark);
6121 ID local = pm_constant_id_lookup(scope_node, name);
6123 local_table_for_iseq->ids[local_index] = local;
6126 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6136 for (
int i = 0; i <
RARRAY_LEN(default_values); i++) {
6138 if (dv == complex_mark) dv =
Qundef;
6142 keyword->default_values = dvs;
6146 keyword->bits_start = local_index;
6147 ID local = rb_make_temporary_id(local_index);
6148 local_table_for_iseq->ids[local_index] = local;
6151 body->
param.keyword = keyword;
6152 body->
param.flags.has_kw =
true;
6155 if (body->type == ISEQ_TYPE_BLOCK && local_index == 1 && requireds_list && requireds_list->
size == 1 && !trailing_comma) {
6156 body->
param.flags.ambiguous_param0 =
true;
6159 if (parameters_node) {
6167 body->
param.flags.accepts_no_kwarg =
true;
6174 if (!body->
param.flags.has_kw) {
6175 body->
param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6178 keyword->rest_start = local_index;
6179 body->
param.flags.has_kwrest =
true;
6184 ID local = pm_constant_id_lookup(scope_node, constant_id);
6185 local_table_for_iseq->ids[local_index] = local;
6188 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6192 body->
param.flags.anon_kwrest =
true;
6193 pm_insert_local_special(idPow, local_index, index_lookup_table, local_table_for_iseq);
6202 if (!ISEQ_BODY(iseq)->param.
flags.forwardable) {
6204 body->
param.rest_start = local_index;
6205 body->
param.flags.has_rest =
true;
6206 body->
param.flags.anon_rest =
true;
6207 pm_insert_local_special(idMULT, local_index++, index_lookup_table, local_table_for_iseq);
6211 body->
param.flags.has_kw =
false;
6212 body->
param.flags.has_kwrest =
true;
6213 body->
param.flags.anon_kwrest =
true;
6214 body->
param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6215 keyword->rest_start = local_index;
6216 pm_insert_local_special(idPow, local_index++, index_lookup_table, local_table_for_iseq);
6219 body->
param.block_start = local_index;
6220 body->
param.flags.has_block =
true;
6221 pm_insert_local_special(idAnd, local_index++, index_lookup_table, local_table_for_iseq);
6225 pm_insert_local_special(idDot3, local_index++, index_lookup_table, local_table_for_iseq);
6229 rb_bug(
"node type %s not expected as keyword_rest", pm_node_type_to_str(
PM_NODE_TYPE(parameters_node->
keyword_rest)));
6235 if (parameters_node->
block) {
6236 body->
param.block_start = local_index;
6237 body->
param.flags.has_block =
true;
6238 iseq_set_use_block(iseq);
6244 ID local = pm_constant_id_lookup(scope_node, name);
6245 local_table_for_iseq->ids[local_index] = local;
6248 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6252 pm_insert_local_special(idAnd, local_index, index_lookup_table, local_table_for_iseq);
6271 if (requireds_list && requireds_list->
size) {
6272 for (
size_t i = 0; i < requireds_list->
size; i++) {
6279 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);
6285 if (posts_list && posts_list->
size) {
6286 for (
size_t i = 0; i < posts_list->
size; i++) {
6293 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);
6301 body->
param.lead_num++;
6304 body->
param.rest_start = local_index;
6305 body->
param.flags.has_rest =
true;
6308 ID local = rb_make_temporary_id(local_index);
6309 local_table_for_iseq->ids[local_index] = local;
6317 for (
int i = 0; i < maximum; i++, local_index++) {
6318 const uint8_t param_name[] = {
'_',
'1' + i };
6320 RUBY_ASSERT(constant_id &&
"parser should fill in any gaps in numbered parameters");
6321 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6323 body->
param.lead_num = maximum;
6324 body->
param.flags.has_lead =
true;
6335 if (block_locals && block_locals->
size) {
6336 for (
size_t i = 0; i < block_locals->
size; i++, local_index++) {
6338 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6343 if (scope_node->locals.
size) {
6344 for (
size_t i = 0; i < scope_node->locals.
size; i++) {
6348 ctx.scope_node = scope_node;
6349 ctx.local_table_for_iseq = local_table_for_iseq;
6350 ctx.local_index = local_index;
6352 st_update(index_lookup_table, (st_data_t)constant_id, pm_local_table_insert_func, (st_data_t)&ctx);
6354 local_index = ctx.local_index;
6363 if (scope_node->index_lookup_table) {
6364 st_free_table(scope_node->index_lookup_table);
6366 scope_node->index_lookup_table = index_lookup_table;
6367 iseq_calc_param_size(iseq);
6369 if (ISEQ_BODY(iseq)->param.
flags.forwardable) {
6372 ISEQ_BODY(iseq)->param.size += 1;
6376 iseq_set_local_table(iseq, local_table_for_iseq, 0);
6377 scope_node->local_table_for_iseq_size = local_table_for_iseq->size;
6379 if (keyword != NULL) {
6380 size_t keyword_start_index = keyword->bits_start - keyword->num;
6381 keyword->table = (
ID *)&ISEQ_BODY(iseq)->local_table[keyword_start_index];
6386 if (optionals_list && optionals_list->
size) {
6394 for (
size_t i = 0; i < optionals_list->
size; i++) {
6395 label = NEW_LABEL(location.
line);
6396 opt_table[i] = label;
6397 PUSH_LABEL(ret, label);
6399 PM_COMPILE_NOT_POPPED(optional_node);
6403 label = NEW_LABEL(location.
line);
6404 opt_table[optionals_list->
size] = label;
6405 PUSH_LABEL(ret, label);
6407 body->
param.opt_table = (
const VALUE *) opt_table;
6410 if (keywords_list && keywords_list->
size) {
6411 size_t optional_index = 0;
6412 for (
size_t i = 0; i < keywords_list->
size; i++) {
6425 if (!
PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) {
6426 LABEL *end_label = NEW_LABEL(location.
line);
6429 int kw_bits_idx = table_size - body->
param.keyword->bits_start;
6430 PUSH_INSN2(ret, location, checkkeyword,
INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1),
INT2FIX(optional_index));
6431 PUSH_INSNL(ret, location, branchif, end_label);
6433 PUSH_SETLOCAL(ret, location, index.index, index.level);
6434 PUSH_LABEL(ret, end_label);
6444 rb_bug(
"Unexpected keyword parameter node type %s", pm_node_type_to_str(
PM_NODE_TYPE(keyword_parameter_node)));
6449 if (requireds_list && requireds_list->
size) {
6450 for (
size_t i = 0; i < requireds_list->
size; i++) {
6457 PUSH_GETLOCAL(ret, location, table_size - (
int)i, 0);
6463 if (posts_list && posts_list->
size) {
6464 for (
size_t i = 0; i < posts_list->
size; i++) {
6471 PUSH_GETLOCAL(ret, location, table_size - body->
param.post_start - (
int) i, 0);
6477 switch (body->type) {
6478 case ISEQ_TYPE_PLAIN: {
6482 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
6486 case ISEQ_TYPE_BLOCK: {
6487 LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
6488 LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
6491 start->rescued = LABEL_RESCUE_BEG;
6492 end->rescued = LABEL_RESCUE_END;
6499 pm_compile_for_node_index(iseq, ((
const pm_for_node_t *) scope_node->ast_node)->index, ret, scope_node);
6503 PUSH_INSN(ret, block_location, nop);
6504 PUSH_LABEL(ret, start);
6506 if (scope_node->body != NULL) {
6510 PUSH_INSN1(ret, block_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
6514 pm_scope_node_init((
const pm_node_t *) cast->statements, &next_scope_node, scope_node);
6516 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(body->parent_iseq), ISEQ_TYPE_BLOCK, location.
line);
6517 pm_scope_node_destroy(&next_scope_node);
6519 PUSH_CALL_WITH_BLOCK(ret, block_location, id_core_set_postexe,
INT2FIX(0), block);
6524 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
6528 pm_compile_node(iseq, scope_node->body, ret, popped, scope_node);
6533 PUSH_INSN(ret, block_location, putnil);
6536 PUSH_LABEL(ret, end);
6538 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
6541 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
6542 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
6545 case ISEQ_TYPE_ENSURE: {
6546 const pm_node_location_t statements_location = (scope_node->body != NULL ? PM_NODE_START_LOCATION(scope_node->parser, scope_node->body) : location);
6547 iseq_set_exception_local_table(iseq);
6549 if (scope_node->body != NULL) {
6550 PM_COMPILE_POPPED((
const pm_node_t *) scope_node->body);
6553 PUSH_GETLOCAL(ret, statements_location, 1, 0);
6554 PUSH_INSN1(ret, statements_location,
throw,
INT2FIX(0));
6557 case ISEQ_TYPE_METHOD: {
6558 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
6561 if (scope_node->body) {
6562 PM_COMPILE((
const pm_node_t *) scope_node->body);
6565 PUSH_INSN(ret, location, putnil);
6568 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
6571 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
6574 case ISEQ_TYPE_RESCUE: {
6575 iseq_set_exception_local_table(iseq);
6578 LABEL *rescue_end = NEW_LABEL(location.
line);
6579 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
6581 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
6582 PUSH_INSNL(ret, location, branchif, lab);
6583 PUSH_INSNL(ret, location, jump, rescue_end);
6584 PUSH_LABEL(ret, lab);
6586 PM_COMPILE((
const pm_node_t *) scope_node->body);
6587 PUSH_INSN(ret, location, leave);
6588 PUSH_LABEL(ret, rescue_end);
6589 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
6592 PM_COMPILE((
const pm_node_t *) scope_node->ast_node);
6594 PUSH_INSN1(ret, location,
throw,
INT2FIX(0));
6599 if (scope_node->body) {
6600 PM_COMPILE((
const pm_node_t *) scope_node->body);
6603 PUSH_INSN(ret, location, putnil);
6609 const pm_node_location_t end_location = PM_NODE_END_LOCATION(scope_node->parser, scope_node->ast_node);
6611 ISEQ_COMPILE_DATA(iseq)->last_line = end_location.
line;
6616 PUSH_INSN(ret, location, leave);
6625 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
6629 VALUE operand =
ID2SYM(rb_intern3((
const char *) name_loc->
start, name_loc->
end - name_loc->
start, scope_node->encoding));
6630 PUSH_INSN1(ret, *location, putobject, operand);
6635 VALUE operand =
ID2SYM(rb_intern3((
const char *) name_loc->
start, name_loc->
end - name_loc->
start, scope_node->encoding));
6636 PUSH_INSN1(ret, *location, putobject, operand);
6639 PUSH_SEND(ret, *location, id_core_set_variable_alias,
INT2FIX(2));
6640 if (popped) PUSH_INSN(ret, *location, pop);
6646 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
6647 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
6648 PM_COMPILE_NOT_POPPED(node->
new_name);
6649 PM_COMPILE_NOT_POPPED(node->
old_name);
6651 PUSH_SEND(ret, *location, id_core_set_method_alias,
INT2FIX(3));
6652 if (popped) PUSH_INSN(ret, *location, pop);
6658 LABEL *end_label = NEW_LABEL(location->
line);
6660 PM_COMPILE_NOT_POPPED(node->
left);
6661 if (!popped) PUSH_INSN(ret, *location, dup);
6662 PUSH_INSNL(ret, *location, branchunless, end_label);
6664 if (!popped) PUSH_INSN(ret, *location, pop);
6665 PM_COMPILE(node->
right);
6666 PUSH_LABEL(ret, end_label);
6679 if (elements->
size) {
6680 VALUE value = pm_static_literal_value(iseq, node, scope_node);
6681 PUSH_INSN1(ret, *location, duparray, value);
6684 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
6702 const int max_new_array_size = 0x100;
6703 const unsigned int min_tmp_array_size = 0x40;
6705 int new_array_size = 0;
6706 bool first_chunk =
true;
6712 bool static_literal =
false;
6715#define FLUSH_CHUNK \
6716 if (new_array_size) { \
6717 if (first_chunk) PUSH_INSN1(ret, *location, newarray, INT2FIX(new_array_size)); \
6718 else PUSH_INSN1(ret, *location, pushtoarray, INT2FIX(new_array_size)); \
6719 first_chunk = false; \
6720 new_array_size = 0; \
6723 for (
size_t index = 0; index < elements->
size; index++) {
6731 PM_COMPILE_NOT_POPPED(splat_element->
expression);
6734 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
6735 PUSH_GETLOCAL(ret, *location, index.index, index.level);
6741 PUSH_INSN1(ret, *location, splatarray,
Qtrue);
6742 first_chunk =
false;
6745 PUSH_INSN(ret, *location, concattoarray);
6748 static_literal =
false;
6751 if (new_array_size == 0 && first_chunk) {
6752 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
6753 first_chunk =
false;
6770 pm_compile_hash_elements(iseq, element, &keyword_hash->
elements, 0,
Qundef,
false, ret, scope_node);
6780 PUSH_INSN(ret, *location, pushtoarraykwsplat);
6788 !PM_CONTAINER_P(element) &&
6790 ((index + min_tmp_array_size) < elements->
size)
6795 size_t right_index = index + 1;
6797 right_index < elements->size &&
6799 !PM_CONTAINER_P(elements->
nodes[right_index])
6802 size_t tmp_array_size = right_index - index;
6803 if (tmp_array_size >= min_tmp_array_size) {
6804 VALUE tmp_array = rb_ary_hidden_new(tmp_array_size);
6807 for (; tmp_array_size; tmp_array_size--)
6808 rb_ary_push(tmp_array, pm_static_literal_value(iseq, elements->
nodes[index++], scope_node));
6816 PUSH_INSN1(ret, *location, duparray, tmp_array);
6817 first_chunk =
false;
6820 PUSH_INSN1(ret, *location, putobject, tmp_array);
6821 PUSH_INSN(ret, *location, concattoarray);
6825 PM_COMPILE_NOT_POPPED(element);
6826 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
6827 static_literal =
true;
6830 PM_COMPILE_NOT_POPPED(element);
6831 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
6832 static_literal =
false;
6837 if (popped) PUSH_INSN(ret, *location, pop);
6845 unsigned long throw_flag = 0;
6847 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
6849 LABEL *splabel = NEW_LABEL(0);
6850 PUSH_LABEL(ret, splabel);
6851 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
6857 PUSH_INSN(ret, *location, putnil);
6860 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
6861 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
6862 PUSH_ADJUST_RESTORE(ret, splabel);
6863 if (!popped) PUSH_INSN(ret, *location, putnil);
6869 if (!ISEQ_COMPILE_DATA(ip)) {
6874 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
6875 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
6877 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
6880 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
6881 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
6885 ip = ISEQ_BODY(ip)->parent_iseq;
6894 PUSH_INSN(ret, *location, putnil);
6897 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_BREAK));
6898 if (popped) PUSH_INSN(ret, *location, pop);
6903 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
6910 ID method_id = pm_constant_id_lookup(scope_node, node->
name);
6916 const char *builtin_func;
6918 if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && (builtin_func = pm_iseq_builtin_function_name(scope_node, node->
receiver, method_id)) != NULL) {
6919 pm_compile_builtin_function_call(iseq, ret, scope_node, node, &location, popped, ISEQ_COMPILE_DATA(iseq)->current_block, builtin_func);
6923 LABEL *start = NEW_LABEL(location.
line);
6924 if (node->
block) PUSH_LABEL(ret, start);
6926 switch (method_id) {
6928 if (pm_opt_str_freeze_p(iseq, node)) {
6930 const struct rb_callinfo *callinfo = new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE);
6931 PUSH_INSN2(ret, location, opt_str_uminus, value, callinfo);
6932 if (popped) PUSH_INSN(ret, location, pop);
6938 if (pm_opt_str_freeze_p(iseq, node)) {
6940 const struct rb_callinfo *callinfo = new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE);
6941 PUSH_INSN2(ret, location, opt_str_freeze, value, callinfo);
6942 if (popped) PUSH_INSN(ret, location, pop);
6948 if (pm_opt_aref_with_p(iseq, node)) {
6950 VALUE value = parse_static_literal_string(iseq, scope_node, (
const pm_node_t *)
string, &string->unescaped);
6952 PM_COMPILE_NOT_POPPED(node->
receiver);
6954 const struct rb_callinfo *callinfo = new_callinfo(iseq, idAREF, 1, 0, NULL, FALSE);
6955 PUSH_INSN2(ret, location, opt_aref_with, value, callinfo);
6958 PUSH_INSN(ret, location, pop);
6966 if (pm_opt_aset_with_p(iseq, node)) {
6968 VALUE value = parse_static_literal_string(iseq, scope_node, (
const pm_node_t *)
string, &string->unescaped);
6970 PM_COMPILE_NOT_POPPED(node->
receiver);
6974 PUSH_INSN(ret, location, swap);
6975 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6978 const struct rb_callinfo *callinfo = new_callinfo(iseq, idASET, 2, 0, NULL, FALSE);
6979 PUSH_INSN2(ret, location, opt_aset_with, value, callinfo);
6980 PUSH_INSN(ret, location, pop);
6988 PUSH_INSN(ret, location, putnil);
6992 PUSH_INSN(ret, location, putself);
7000 if (iseq_block_param_id_p(iseq, pm_constant_id_lookup(scope_node, read_node_cast->name), &idx, &level)) {
7001 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)));
7004 PM_COMPILE_NOT_POPPED(node->
receiver);
7008 PM_COMPILE_NOT_POPPED(node->
receiver);
7012 pm_compile_call(iseq, node, ret, popped, scope_node, method_id, start);
7022 flag = VM_CALL_FCALL;
7025 PM_COMPILE_NOT_POPPED(node->
receiver);
7027 LABEL *safe_label = NULL;
7029 safe_label = NEW_LABEL(location->
line);
7030 PUSH_INSN(ret, *location, dup);
7031 PUSH_INSNL(ret, *location, branchnil, safe_label);
7034 PUSH_INSN(ret, *location, dup);
7036 ID id_read_name = pm_constant_id_lookup(scope_node, node->
read_name);
7037 PUSH_SEND_WITH_FLAG(ret, *location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
7039 PM_COMPILE_NOT_POPPED(node->
value);
7041 PUSH_SEND(ret, *location, id_operator,
INT2FIX(1));
7044 PUSH_INSN(ret, *location, swap);
7045 PUSH_INSN1(ret, *location, topn,
INT2FIX(1));
7048 ID id_write_name = pm_constant_id_lookup(scope_node, node->
write_name);
7049 PUSH_SEND_WITH_FLAG(ret, *location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
7051 if (safe_label != NULL && popped) PUSH_LABEL(ret, safe_label);
7052 PUSH_INSN(ret, *location, pop);
7053 if (safe_label != NULL && !popped) PUSH_LABEL(ret, safe_label);
7079 key = pm_static_literal_value(iseq, node, scope_node);
7083 key = (
FIXABLE(intptr) ?
LONG2FIX((
long) intptr) : rb_dbl2big(intptr));
7095 key = pm_static_literal_value(iseq, node, scope_node);
7099 key = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
7106 if (
NIL_P(rb_hash_lookup(dispatch, key))) {
7107 rb_hash_aset(dispatch, key, ((
VALUE) label) | 1);
7126 DECL_ANCHOR(cond_seq);
7131 DECL_ANCHOR(body_seq);
7135 LABEL *end_label = NEW_LABEL(location.
line);
7146 if (PM_BRANCH_COVERAGE_P(iseq)) {
7147 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7148 branches = decl_branch_base(iseq, PTR2NUM(cast), &case_location,
"case");
7154 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7158 int clause_lineno = pm_node_line_number(parser, (
const pm_node_t *) clause);
7159 LABEL *label = NEW_LABEL(clause_lineno);
7160 PUSH_LABEL(body_seq, label);
7163 if (PM_BRANCH_COVERAGE_P(iseq)) {
7165 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7168 if (clause->statements != NULL) {
7169 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7172 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7175 PUSH_INSNL(body_seq, location, jump, end_label);
7180 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7185 PUSH_INSN(cond_seq, cond_location, putnil);
7186 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7187 PUSH_INSN1(cond_seq, cond_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
7188 PUSH_INSNL(cond_seq, cond_location, branchif, label);
7191 LABEL *next_label = NEW_LABEL(pm_node_line_number(parser, condition));
7192 pm_compile_branch_condition(iseq, cond_seq, condition, label, next_label,
false, scope_node);
7193 PUSH_LABEL(cond_seq, next_label);
7200 if (PM_BRANCH_COVERAGE_P(iseq)) {
7204 branch_location = case_location;
7211 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7219 PUSH_SYNTHETIC_PUTNIL(cond_seq, iseq);
7224 PUSH_INSNL(cond_seq, location, jump, end_label);
7225 PUSH_SEQ(ret, cond_seq);
7233 if (PM_BRANCH_COVERAGE_P(iseq)) {
7234 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7235 branches = decl_branch_base(iseq, PTR2NUM(cast), &case_location,
"case");
7240 LABEL *else_label = NEW_LABEL(location.
line);
7248 if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
7249 dispatch = rb_hash_new();
7250 RHASH_TBL_RAW(dispatch)->type = &cdhash_type;
7261 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7266 LABEL *label = NEW_LABEL(clause_location.
line);
7271 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7273 const pm_node_location_t condition_location = PM_NODE_START_LOCATION(parser, condition);
7278 if (dispatch !=
Qundef) {
7279 dispatch = pm_compile_case_node_dispatch(iseq, dispatch, condition, label, scope_node);
7283 PUSH_INSN(cond_seq, condition_location, dup);
7284 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7285 PUSH_INSN1(cond_seq, condition_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
7290 VALUE value = parse_static_literal_string(iseq, scope_node, condition, &string->
unescaped);
7291 PUSH_INSN1(cond_seq, condition_location, putobject, value);
7294 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7297 PUSH_INSN1(cond_seq, condition_location, topn,
INT2FIX(1));
7298 PUSH_SEND_WITH_FLAG(cond_seq, condition_location, idEqq,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
7301 PUSH_INSNL(cond_seq, condition_location, branchif, label);
7308 PUSH_LABEL(body_seq, label);
7309 PUSH_INSN(body_seq, clause_location, pop);
7312 if (PM_BRANCH_COVERAGE_P(iseq)) {
7314 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7317 if (clause->statements != NULL) {
7318 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7321 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7324 PUSH_INSNL(body_seq, clause_location, jump, end_label);
7335 if (dispatch !=
Qundef) {
7336 PUSH_INSN(ret, location, dup);
7337 PUSH_INSN2(ret, location, opt_case_dispatch, dispatch, else_label);
7338 LABEL_REF(else_label);
7341 PUSH_SEQ(ret, cond_seq);
7345 PUSH_LABEL(ret, else_label);
7349 PUSH_INSN(ret, else_location, pop);
7352 if (PM_BRANCH_COVERAGE_P(iseq)) {
7354 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7358 PUSH_INSNL(ret, else_location, jump, end_label);
7361 PUSH_INSN(ret, location, pop);
7364 if (PM_BRANCH_COVERAGE_P(iseq)) {
7365 add_trace_branch_coverage(iseq, ret, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7368 if (!popped) PUSH_INSN(ret, location, putnil);
7369 PUSH_INSNL(ret, location, jump, end_label);
7373 PUSH_SEQ(ret, body_seq);
7374 PUSH_LABEL(ret, end_label);
7383 DECL_ANCHOR(body_seq);
7388 DECL_ANCHOR(cond_seq);
7392 LABEL *end_label = NEW_LABEL(location->
line);
7397 LABEL *else_label = NEW_LABEL(location->
line);
7405 if (PM_BRANCH_COVERAGE_P(iseq)) {
7406 case_location = pm_code_location(scope_node, (
const pm_node_t *) node);
7407 branches = decl_branch_base(iseq, PTR2NUM(node), &case_location,
"case");
7417 if (in_single_pattern) {
7418 PUSH_INSN(ret, *location, putnil);
7419 PUSH_INSN(ret, *location, putnil);
7420 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7421 PUSH_INSN(ret, *location, putnil);
7425 PUSH_INSN(ret, *location, putnil);
7437 const pm_node_location_t in_location = PM_NODE_START_LOCATION(scope_node->parser, in_node);
7441 PUSH_INSN(body_seq, in_location, putnil);
7444 LABEL *body_label = NEW_LABEL(in_location.
line);
7445 PUSH_LABEL(body_seq, body_label);
7446 PUSH_INSN1(body_seq, in_location, adjuststack,
INT2FIX(in_single_pattern ? 6 : 2));
7449 if (PM_BRANCH_COVERAGE_P(iseq)) {
7451 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"in", branches);
7458 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7461 PUSH_INSNL(body_seq, in_location, jump, end_label);
7462 LABEL *next_pattern_label = NEW_LABEL(pattern_location.
line);
7464 PUSH_INSN(cond_seq, pattern_location, dup);
7465 pm_compile_pattern(iseq, scope_node, in_node->
pattern, cond_seq, body_label, next_pattern_label, in_single_pattern,
false,
true, 2);
7466 PUSH_LABEL(cond_seq, next_pattern_label);
7467 LABEL_UNREMOVABLE(next_pattern_label);
7476 PUSH_LABEL(cond_seq, else_label);
7477 PUSH_INSN(cond_seq, *location, pop);
7478 PUSH_INSN(cond_seq, *location, pop);
7481 if (PM_BRANCH_COVERAGE_P(iseq)) {
7483 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7486 PM_COMPILE_INTO_ANCHOR(cond_seq, (
const pm_node_t *) else_node);
7487 PUSH_INSNL(cond_seq, *location, jump, end_label);
7488 PUSH_INSN(cond_seq, *location, putnil);
7489 if (popped) PUSH_INSN(cond_seq, *location, putnil);
7494 PUSH_LABEL(cond_seq, else_label);
7497 add_trace_branch_coverage(iseq, cond_seq, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7499 if (in_single_pattern) {
7500 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, cond_seq, end_label, popped);
7503 PUSH_INSN1(cond_seq, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7505 PUSH_INSN1(cond_seq, *location, topn,
INT2FIX(2));
7506 PUSH_SEND(cond_seq, *location, id_core_raise,
INT2FIX(2));
7508 PUSH_INSN1(cond_seq, *location, adjuststack,
INT2FIX(3));
7509 if (!popped) PUSH_INSN(cond_seq, *location, putnil);
7510 PUSH_INSNL(cond_seq, *location, jump, end_label);
7511 PUSH_INSN1(cond_seq, *location, dupn,
INT2FIX(1));
7512 if (popped) PUSH_INSN(cond_seq, *location, putnil);
7519 PUSH_SEQ(ret, cond_seq);
7520 PUSH_SEQ(ret, body_seq);
7521 PUSH_LABEL(ret, end_label);
7529 LABEL *retry_label = NULL;
7530 LABEL *retry_end_l = NULL;
7532 if (node->
block != NULL) {
7533 previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
7534 ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
7536 retry_label = NEW_LABEL(location->
line);
7537 retry_end_l = NEW_LABEL(location->
line);
7539 PUSH_LABEL(ret, retry_label);
7542 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
7545 PUSH_INSN(ret, *location, putself);
7546 int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
7548 if (node->
block != NULL) {
7550 pm_scope_node_init((
const pm_node_t *) node->
block, &next_scope_node, scope_node);
7552 ISEQ_COMPILE_DATA(iseq)->current_block = block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
7553 pm_scope_node_destroy(&next_scope_node);
7560 const rb_iseq_t *local_iseq = body->local_iseq;
7564 int depth = get_lvar_level(iseq);
7566 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
param.flags.forwardable) {
7567 flag |= VM_CALL_FORWARDING;
7568 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
7569 PUSH_GETLOCAL(ret, *location, mult_local.index, mult_local.level);
7571 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, 0, flag, NULL, block != NULL);
7572 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, block);
7574 if (popped) PUSH_INSN(ret, *location, pop);
7576 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
7581 if (local_body->
param.flags.has_lead) {
7583 for (
int i = 0; i < local_body->
param.lead_num; i++) {
7584 int idx = local_body->local_table_size - i;
7585 PUSH_GETLOCAL(args, *location, idx, depth);
7587 argc += local_body->
param.lead_num;
7590 if (local_body->
param.flags.has_opt) {
7592 for (
int j = 0; j < local_body->
param.opt_num; j++) {
7593 int idx = local_body->local_table_size - (argc + j);
7594 PUSH_GETLOCAL(args, *location, idx, depth);
7596 argc += local_body->
param.opt_num;
7599 if (local_body->
param.flags.has_rest) {
7601 int idx = local_body->local_table_size - local_body->
param.rest_start;
7602 PUSH_GETLOCAL(args, *location, idx, depth);
7603 PUSH_INSN1(args, *location, splatarray,
Qfalse);
7605 argc = local_body->
param.rest_start + 1;
7606 flag |= VM_CALL_ARGS_SPLAT;
7609 if (local_body->
param.flags.has_post) {
7611 int post_len = local_body->
param.post_num;
7612 int post_start = local_body->
param.post_start;
7615 for (; j < post_len; j++) {
7616 int idx = local_body->local_table_size - (post_start + j);
7617 PUSH_GETLOCAL(args, *location, idx, depth);
7620 if (local_body->
param.flags.has_rest) {
7622 PUSH_INSN1(args, *location, newarray,
INT2FIX(j));
7623 PUSH_INSN(args, *location, concatarray);
7626 argc = post_len + post_start;
7630 const struct rb_iseq_param_keyword *
const local_keyword = local_body->
param.keyword;
7631 if (local_body->
param.flags.has_kw) {
7632 int local_size = local_body->local_table_size;
7635 PUSH_INSN1(args, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7637 if (local_body->
param.flags.has_kwrest) {
7638 int idx = local_body->local_table_size - local_keyword->rest_start;
7639 PUSH_GETLOCAL(args, *location, idx, depth);
7641 PUSH_SEND(args, *location, rb_intern(
"dup"),
INT2FIX(0));
7644 PUSH_INSN1(args, *location, newhash,
INT2FIX(0));
7647 for (; i < local_keyword->num; ++i) {
7648 ID id = local_keyword->table[i];
7649 int idx = local_size - get_local_var_idx(local_iseq,
id);
7653 PUSH_INSN1(args, *location, putobject, operand);
7656 PUSH_GETLOCAL(args, *location, idx, depth);
7659 PUSH_SEND(args, *location, id_core_hash_merge_ptr,
INT2FIX(i * 2 + 1));
7660 flag |= VM_CALL_KW_SPLAT| VM_CALL_KW_SPLAT_MUT;
7662 else if (local_body->
param.flags.has_kwrest) {
7663 int idx = local_body->local_table_size - local_keyword->rest_start;
7664 PUSH_GETLOCAL(args, *location, idx, depth);
7666 flag |= VM_CALL_KW_SPLAT;
7669 PUSH_SEQ(ret, args);
7672 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flag, NULL, block != NULL);
7673 PUSH_INSN2(ret, *location, invokesuper, callinfo, block);
7676 if (node->
block != NULL) {
7677 pm_compile_retry_end_label(iseq, ret, retry_end_l);
7678 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, block, retry_end_l);
7679 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
7682 if (popped) PUSH_INSN(ret, *location, pop);
7688 LABEL *matched_label = NEW_LABEL(location->
line);
7689 LABEL *unmatched_label = NEW_LABEL(location->
line);
7690 LABEL *done_label = NEW_LABEL(location->
line);
7694 PUSH_INSN(ret, *location, putnil);
7695 PUSH_INSN(ret, *location, putnil);
7696 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7697 PUSH_INSN(ret, *location, putnil);
7698 PUSH_INSN(ret, *location, putnil);
7702 PM_COMPILE_NOT_POPPED(node->
value);
7706 PUSH_INSN(ret, *location, dup);
7713 pm_compile_pattern(iseq, scope_node, node->
pattern, ret, matched_label, unmatched_label,
true,
false,
true, 2);
7718 PUSH_LABEL(ret, unmatched_label);
7719 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, ret, done_label, popped);
7723 PUSH_LABEL(ret, matched_label);
7724 PUSH_INSN1(ret, *location, adjuststack,
INT2FIX(6));
7725 if (!popped) PUSH_INSN(ret, *location, putnil);
7726 PUSH_INSNL(ret, *location, jump, done_label);
7728 PUSH_LABEL(ret, done_label);
7734 LABEL *fail_label = NEW_LABEL(location->
line);
7735 LABEL *end_label = NEW_LABEL(location->
line);
7746 PUSH_INSN1(ret, *location, getglobal, operand);
7749 PUSH_INSN(ret, *location, dup);
7750 PUSH_INSNL(ret, *location, branchunless, fail_label);
7756 if (targets_count == 1) {
7765 PUSH_INSN1(ret, *location, putobject, operand);
7768 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
7769 PUSH_LABEL(ret, fail_label);
7770 PUSH_SETLOCAL(ret, *location, index.index, index.level);
7771 if (popped) PUSH_INSN(ret, *location, pop);
7775 DECL_ANCHOR(fail_anchor);
7779 for (
size_t targets_index = 0; targets_index < targets_count; targets_index++) {
7786 if (((
size_t) targets_index) < (targets_count - 1)) {
7787 PUSH_INSN(ret, *location, dup);
7792 PUSH_INSN1(ret, *location, putobject, operand);
7795 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
7796 PUSH_SETLOCAL(ret, *location, index.index, index.level);
7798 PUSH_INSN(fail_anchor, *location, putnil);
7799 PUSH_SETLOCAL(fail_anchor, *location, index.index, index.level);
7803 PUSH_INSNL(ret, *location, jump, end_label);
7807 PUSH_LABEL(ret, fail_label);
7808 PUSH_INSN(ret, *location, pop);
7809 PUSH_SEQ(ret, fail_anchor);
7812 PUSH_LABEL(ret, end_label);
7813 if (popped) PUSH_INSN(ret, *location, pop);
7819 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
7820 LABEL *splabel = NEW_LABEL(0);
7821 PUSH_LABEL(ret, splabel);
7827 PUSH_INSN(ret, *location, putnil);
7829 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7831 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7832 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
7834 PUSH_ADJUST_RESTORE(ret, splabel);
7835 if (!popped) PUSH_INSN(ret, *location, putnil);
7837 else if (ISEQ_COMPILE_DATA(iseq)->end_label && can_add_ensure_iseq(iseq)) {
7838 LABEL *splabel = NEW_LABEL(0);
7840 PUSH_LABEL(ret, splabel);
7841 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
7847 PUSH_INSN(ret, *location, putnil);
7850 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7851 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
7852 PUSH_ADJUST_RESTORE(ret, splabel);
7853 splabel->unremovable = FALSE;
7855 if (!popped) PUSH_INSN(ret, *location, putnil);
7859 unsigned long throw_flag = 0;
7862 if (!ISEQ_COMPILE_DATA(ip)) {
7867 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
7868 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7872 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
7875 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
7876 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
7880 ip = ISEQ_BODY(ip)->parent_iseq;
7888 PUSH_INSN(ret, *location, putnil);
7891 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_NEXT));
7892 if (popped) PUSH_INSN(ret, *location, pop);
7895 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
7903 if (ISEQ_COMPILE_DATA(iseq)->redo_label && can_add_ensure_iseq(iseq)) {
7904 LABEL *splabel = NEW_LABEL(0);
7906 PUSH_LABEL(ret, splabel);
7907 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7908 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7910 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
7911 PUSH_ADJUST_RESTORE(ret, splabel);
7912 if (!popped) PUSH_INSN(ret, *location, putnil);
7914 else if (ISEQ_BODY(iseq)->
type != ISEQ_TYPE_EVAL && ISEQ_COMPILE_DATA(iseq)->start_label && can_add_ensure_iseq(iseq)) {
7915 LABEL *splabel = NEW_LABEL(0);
7917 PUSH_LABEL(ret, splabel);
7918 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7919 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
7921 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
7922 PUSH_ADJUST_RESTORE(ret, splabel);
7923 if (!popped) PUSH_INSN(ret, *location, putnil);
7929 if (!ISEQ_COMPILE_DATA(ip)) {
7934 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7937 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
7940 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
7941 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
7945 ip = ISEQ_BODY(ip)->parent_iseq;
7949 PUSH_INSN(ret, *location, putnil);
7950 PUSH_INSN1(ret, *location,
throw,
INT2FIX(VM_THROW_NO_ESCAPE_FLAG | TAG_REDO));
7951 if (popped) PUSH_INSN(ret, *location, pop);
7954 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
7962 iseq_set_exception_local_table(iseq);
7966 LABEL *exception_match_label = NEW_LABEL(location->
line);
7967 LABEL *rescue_end_label = NEW_LABEL(location->
line);
7977 if (exceptions->
size > 0) {
7978 for (
size_t index = 0; index < exceptions->
size; index++) {
7979 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
7980 PM_COMPILE(exceptions->
nodes[index]);
7981 int checkmatch_flags = VM_CHECKMATCH_TYPE_RESCUE;
7983 checkmatch_flags |= VM_CHECKMATCH_ARRAY;
7985 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(checkmatch_flags));
7986 PUSH_INSNL(ret, *location, branchif, exception_match_label);
7990 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
7992 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
7993 PUSH_INSNL(ret, *location, branchif, exception_match_label);
7998 PUSH_INSNL(ret, *location, jump, rescue_end_label);
8003 PUSH_LABEL(ret, exception_match_label);
8010 DECL_ANCHOR(writes);
8011 DECL_ANCHOR(cleanup);
8013 pm_compile_target_node(iseq, node->
reference, ret, writes, cleanup, scope_node, NULL);
8014 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8016 PUSH_SEQ(ret, writes);
8017 PUSH_SEQ(ret, cleanup);
8027 LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
8028 ISEQ_COMPILE_DATA(iseq)->end_label = NULL;
8033 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
8036 PUSH_INSN(ret, *location, putnil);
8039 PUSH_INSN(ret, *location, leave);
8045 PUSH_LABEL(ret, rescue_end_label);
8050 PUSH_GETLOCAL(ret, *location, 1, 0);
8058 enum rb_iseq_type
type = ISEQ_BODY(iseq)->type;
8062 enum rb_iseq_type parent_type = ISEQ_BODY(parent_iseq)->type;
8063 while (parent_type == ISEQ_TYPE_RESCUE || parent_type == ISEQ_TYPE_ENSURE) {
8064 if (!(parent_iseq = ISEQ_BODY(parent_iseq)->parent_iseq))
break;
8065 parent_type = ISEQ_BODY(parent_iseq)->type;
8068 switch (parent_type) {
8070 case ISEQ_TYPE_MAIN:
8072 rb_warn(
"argument of top-level return is ignored");
8074 if (parent_iseq == iseq) {
8075 type = ISEQ_TYPE_METHOD;
8082 if (
type == ISEQ_TYPE_METHOD) {
8083 splabel = NEW_LABEL(0);
8084 PUSH_LABEL(ret, splabel);
8085 PUSH_ADJUST(ret, *location, 0);
8088 if (arguments != NULL) {
8089 PM_COMPILE_NOT_POPPED((
const pm_node_t *) arguments);
8092 PUSH_INSN(ret, *location, putnil);
8095 if (
type == ISEQ_TYPE_METHOD && can_add_ensure_iseq(iseq)) {
8096 pm_add_ensure_iseq(ret, iseq, 1, scope_node);
8098 PUSH_INSN(ret, *location, leave);
8099 PUSH_ADJUST_RESTORE(ret, splabel);
8100 if (!popped) PUSH_INSN(ret, *location, putnil);
8103 PUSH_INSN1(ret, *location,
throw,
INT2FIX(TAG_RETURN));
8104 if (popped) PUSH_INSN(ret, *location, pop);
8113 LABEL *retry_label = NEW_LABEL(location->
line);
8114 LABEL *retry_end_l = NEW_LABEL(location->
line);
8116 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8118 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NULL;
8120 PUSH_LABEL(ret, retry_label);
8121 PUSH_INSN(ret, *location, putself);
8125 int argc = pm_setup_args(node->
arguments, node->
block, &flags, &keywords, iseq, ret, scope_node, location);
8127 flags |= VM_CALL_SUPER | VM_CALL_FCALL;
8131 pm_scope_node_init(node->
block, &next_scope_node, scope_node);
8133 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8134 pm_scope_node_destroy(&next_scope_node);
8138 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8141 if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
8142 PUSH_INSN(args, *location, splatkw);
8145 PUSH_SEQ(ret, args);
8146 if (is_forwardable && ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8147 flags |= VM_CALL_FORWARDING;
8150 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8151 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, current_block);
8156 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8157 PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
8162 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8164 if (popped) PUSH_INSN(ret, *location, pop);
8165 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8166 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);
8172 switch (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
type) {
8174 case ISEQ_TYPE_MAIN:
8175 case ISEQ_TYPE_CLASS:
8176 COMPILE_ERROR(iseq, location->
line,
"Invalid yield");
8186 argc = pm_setup_args(node->
arguments, NULL, &flags, &keywords, iseq, ret, scope_node, location);
8189 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, FALSE);
8190 PUSH_INSN1(ret, *location, invokeblock, callinfo);
8192 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8193 if (popped) PUSH_INSN(ret, *location, pop);
8196 for (
const rb_iseq_t *tmp_iseq = iseq; tmp_iseq != ISEQ_BODY(iseq)->local_iseq; level++) {
8197 tmp_iseq = ISEQ_BODY(tmp_iseq)->parent_iseq;
8200 if (level > 0) access_outer_variables(iseq, level, rb_intern(
"yield"),
true);
8218 int lineno = (int) location.
line;
8225 lineno = (int) PM_NODE_START_LINE_COLUMN(parser, ((
const pm_begin_node_t *) node)->rescue_clause).line;
8234 ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8235 if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8236 event |= RUBY_EVENT_COVERAGE_LINE;
8238 PUSH_TRACE(ret, event);
8250 pm_compile_alias_method_node(iseq, (
const pm_alias_method_node_t *) node, &location, ret, popped, scope_node);
8255 pm_compile_and_node(iseq, (
const pm_and_node_t *) node, &location, ret, popped, scope_node);
8267 if (elements->
size == 1) {
8270 PM_COMPILE(elements->
nodes[0]);
8273 pm_compile_array_node(iseq, (
const pm_node_t *) cast, elements, &location, ret, popped, scope_node);
8281 pm_compile_array_node(iseq, (
const pm_node_t *) cast, &cast->elements, &location, ret, popped, scope_node);
8292 PM_COMPILE(cast->
key);
8293 PM_COMPILE(cast->
value);
8305 if (cast->
value != NULL) {
8306 PM_COMPILE(cast->
value);
8309 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
8310 PUSH_GETLOCAL(ret, location, index.index, index.level);
8322 ID backref_val =
INT2FIX(rb_intern2(char_ptr, 1)) << 1 | 1;
8323 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), backref_val);
8335 pm_compile_ensure(iseq, cast, &location, ret, popped, scope_node);
8339 pm_compile_rescue(iseq, cast, &location, ret, popped, scope_node);
8348 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8363 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
8364 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(local_index.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(local_index.level));
8374 pm_compile_break_node(iseq, (
const pm_break_node_t *) node, &location, ret, popped, scope_node);
8385 pm_compile_call_node(iseq, (
const pm_call_node_t *) node, ret, popped, scope_node);
8391 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);
8398 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);
8416 pm_compile_case_node(iseq, (
const pm_case_node_t *) node, &location, ret, popped, scope_node);
8427 pm_compile_case_match_node(iseq, (
const pm_case_match_node_t *) node, &location, ret, popped, scope_node);
8434 ID class_id = pm_constant_id_lookup(scope_node, cast->
name);
8435 VALUE class_name =
rb_str_freeze(rb_sprintf(
"<class:%"PRIsVALUE
">", rb_id2str(class_id)));
8438 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
8440 const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(&next_scope_node, class_name, ISEQ_TYPE_CLASS, location.
line);
8441 pm_scope_node_destroy(&next_scope_node);
8444 const int flags = VM_DEFINECLASS_TYPE_CLASS |
8445 (cast->
superclass ? VM_DEFINECLASS_FLAG_HAS_SUPERCLASS : 0) |
8446 pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
8452 PUSH_INSN(ret, location, putnil);
8457 PUSH_INSN3(ret, location, defineclass, operand, class_iseq,
INT2FIX(flags));
8461 if (popped) PUSH_INSN(ret, location, pop);
8468 LABEL *end_label = NEW_LABEL(location.
line);
8470 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8473 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8474 if (!popped) PUSH_INSN(ret, location, dup);
8476 PUSH_INSNL(ret, location, branchunless, end_label);
8477 if (!popped) PUSH_INSN(ret, location, pop);
8479 PM_COMPILE_NOT_POPPED(cast->
value);
8480 if (!popped) PUSH_INSN(ret, location, dup);
8482 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8483 PUSH_LABEL(ret, end_label);
8492 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8495 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8496 PM_COMPILE_NOT_POPPED(cast->
value);
8499 int flags = VM_CALL_ARGS_SIMPLE;
8500 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
8502 if (!popped) PUSH_INSN(ret, location, dup);
8503 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8511 LABEL *end_label = NEW_LABEL(location.
line);
8512 LABEL *start_label = NEW_LABEL(location.
line);
8514 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8517 PUSH_INSN(ret, location, putnil);
8518 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name,
Qtrue);
8519 PUSH_INSNL(ret, location, branchunless, start_label);
8521 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8522 if (!popped) PUSH_INSN(ret, location, dup);
8524 PUSH_INSNL(ret, location, branchif, end_label);
8525 if (!popped) PUSH_INSN(ret, location, pop);
8527 PUSH_LABEL(ret, start_label);
8528 PM_COMPILE_NOT_POPPED(cast->
value);
8529 if (!popped) PUSH_INSN(ret, location, dup);
8531 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8532 PUSH_LABEL(ret, end_label);
8541 ID name = pm_constant_id_lookup(scope_node, cast->
name);
8542 PUSH_INSN2(ret, location, getclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
8550 PM_COMPILE_NOT_POPPED(cast->
value);
8551 if (!popped) PUSH_INSN(ret, location, dup);
8553 ID name = pm_constant_id_lookup(scope_node, cast->
name);
8554 PUSH_INSN2(ret, location, setclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
8563 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache && ((parts = pm_constant_path_parts(node, scope_node)) !=
Qnil)) {
8564 ISEQ_BODY(iseq)->ic_size++;
8565 PUSH_INSN1(ret, location, opt_getconstant_path, parts);
8568 DECL_ANCHOR(prefix);
8571 pm_compile_constant_path(iseq, node, prefix, body, popped, scope_node);
8572 if (LIST_INSN_SIZE_ZERO(prefix)) {
8573 PUSH_INSN(ret, location, putnil);
8576 PUSH_SEQ(ret, prefix);
8579 PUSH_SEQ(ret, body);
8582 if (popped) PUSH_INSN(ret, location, pop);
8589 pm_compile_constant_path_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8596 pm_compile_constant_path_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8603 pm_compile_constant_path_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8610 pm_compile_constant_path_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8619 pm_compile_constant_read(iseq, name, &cast->
base.
location, location.
node_id, ret, scope_node);
8620 if (popped) PUSH_INSN(ret, location, pop);
8628 pm_compile_constant_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8635 pm_compile_constant_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8642 pm_compile_constant_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8649 pm_compile_constant_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8659 ID method_name = pm_constant_id_lookup(scope_node, cast->
name);
8662 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
8664 rb_iseq_t *method_iseq = NEW_ISEQ(&next_scope_node, rb_id2str(method_name), ISEQ_TYPE_METHOD, location.
line);
8665 pm_scope_node_destroy(&next_scope_node);
8668 PM_COMPILE_NOT_POPPED(cast->
receiver);
8669 PUSH_INSN2(ret, location, definesmethod,
ID2SYM(method_name), method_iseq);
8672 PUSH_INSN2(ret, location, definemethod,
ID2SYM(method_name), method_iseq);
8677 PUSH_INSN1(ret, location, putobject,
ID2SYM(method_name));
8686 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
false);
8698 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8701 if (popped) PUSH_INSN(ret, location, pop);
8715 PUSH_INSN1(ret, location, putobject,
Qfalse);
8737 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8747 LABEL *final_label = NEW_LABEL(location.
line);
8748 LABEL *then_label = NEW_LABEL(location.
line);
8749 LABEL *else_label = NEW_LABEL(location.
line);
8751 pm_compile_flip_flop(cast, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
8753 PUSH_LABEL(ret, then_label);
8754 PUSH_INSN1(ret, location, putobject,
Qtrue);
8755 PUSH_INSNL(ret, location, jump, final_label);
8756 PUSH_LABEL(ret, else_label);
8757 PUSH_INSN1(ret, location, putobject,
Qfalse);
8758 PUSH_LABEL(ret, final_label);
8767 PUSH_INSN1(ret, location, putobject, operand);
8776 LABEL *retry_label = NEW_LABEL(location.
line);
8777 LABEL *retry_end_l = NEW_LABEL(location.
line);
8780 PUSH_LABEL(ret, retry_label);
8786 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
8788 const rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location.
line);
8789 pm_scope_node_destroy(&next_scope_node);
8791 const rb_iseq_t *prev_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8792 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
8796 PUSH_SEND_WITH_BLOCK(ret, location, idEach,
INT2FIX(0), child_iseq);
8797 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8799 if (popped) PUSH_INSN(ret, location, pop);
8800 ISEQ_COMPILE_DATA(iseq)->current_block = prev_block;
8801 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
8805 rb_bug(
"Cannot compile a ForwardingArgumentsNode directly\n");
8819 LABEL *end_label = NEW_LABEL(location.
line);
8822 PUSH_INSN1(ret, location, getglobal, name);
8823 if (!popped) PUSH_INSN(ret, location, dup);
8825 PUSH_INSNL(ret, location, branchunless, end_label);
8826 if (!popped) PUSH_INSN(ret, location, pop);
8828 PM_COMPILE_NOT_POPPED(cast->
value);
8829 if (!popped) PUSH_INSN(ret, location, dup);
8831 PUSH_INSN1(ret, location, setglobal, name);
8832 PUSH_LABEL(ret, end_label);
8842 PUSH_INSN1(ret, location, getglobal, name);
8843 PM_COMPILE_NOT_POPPED(cast->
value);
8846 int flags = VM_CALL_ARGS_SIMPLE;
8847 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
8849 if (!popped) PUSH_INSN(ret, location, dup);
8850 PUSH_INSN1(ret, location, setglobal, name);
8858 LABEL *set_label = NEW_LABEL(location.
line);
8859 LABEL *end_label = NEW_LABEL(location.
line);
8861 PUSH_INSN(ret, location, putnil);
8864 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name,
Qtrue);
8865 PUSH_INSNL(ret, location, branchunless, set_label);
8867 PUSH_INSN1(ret, location, getglobal, name);
8868 if (!popped) PUSH_INSN(ret, location, dup);
8870 PUSH_INSNL(ret, location, branchif, end_label);
8871 if (!popped) PUSH_INSN(ret, location, pop);
8873 PUSH_LABEL(ret, set_label);
8874 PM_COMPILE_NOT_POPPED(cast->
value);
8875 if (!popped) PUSH_INSN(ret, location, dup);
8877 PUSH_INSN1(ret, location, setglobal, name);
8878 PUSH_LABEL(ret, end_label);
8888 PUSH_INSN1(ret, location, getglobal, name);
8889 if (popped) PUSH_INSN(ret, location, pop);
8897 PM_COMPILE_NOT_POPPED(cast->
value);
8898 if (!popped) PUSH_INSN(ret, location, dup);
8900 ID name = pm_constant_id_lookup(scope_node, cast->
name);
8901 PUSH_INSN1(ret, location, setglobal,
ID2SYM(name));
8919 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
8922 VALUE value = pm_static_literal_value(iseq, node, scope_node);
8923 PUSH_INSN1(ret, location, duphash, value);
8944 for (
size_t index = 0; index < elements->
size; index++) {
8945 PM_COMPILE_POPPED(elements->
nodes[index]);
8949 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
8965 pm_compile_conditional(iseq, &location,
PM_IF_NODE, (
const pm_node_t *) cast, cast->statements, cast->subsequent, cast->predicate, ret, popped, scope_node);
8973 PUSH_INSN1(ret, location, putobject, operand);
8987 PM_COMPILE(cast->
value);
8993 rb_bug(
"Should not ever enter an in node directly");
9000 pm_compile_index_operator_write_node(iseq, cast, &location, ret, popped, scope_node);
9007 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9014 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9021 LABEL *end_label = NEW_LABEL(location.
line);
9023 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9026 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9027 if (!popped) PUSH_INSN(ret, location, dup);
9029 PUSH_INSNL(ret, location, branchunless, end_label);
9030 if (!popped) PUSH_INSN(ret, location, pop);
9032 PM_COMPILE_NOT_POPPED(cast->
value);
9033 if (!popped) PUSH_INSN(ret, location, dup);
9035 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9036 PUSH_LABEL(ret, end_label);
9045 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9048 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9049 PM_COMPILE_NOT_POPPED(cast->
value);
9052 int flags = VM_CALL_ARGS_SIMPLE;
9053 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9055 if (!popped) PUSH_INSN(ret, location, dup);
9056 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9064 LABEL *end_label = NEW_LABEL(location.
line);
9066 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9069 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9070 if (!popped) PUSH_INSN(ret, location, dup);
9072 PUSH_INSNL(ret, location, branchif, end_label);
9073 if (!popped) PUSH_INSN(ret, location, pop);
9075 PM_COMPILE_NOT_POPPED(cast->
value);
9076 if (!popped) PUSH_INSN(ret, location, dup);
9078 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9079 PUSH_LABEL(ret, end_label);
9088 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9089 PUSH_INSN2(ret, location, getinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9097 PM_COMPILE_NOT_POPPED(cast->
value);
9098 if (!popped) PUSH_INSN(ret, location, dup);
9100 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9101 PUSH_INSN2(ret, location, setinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9110 PUSH_INSN1(ret, location, putobject, operand);
9119 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9120 PUSH_INSN1(ret, location, putobject, regexp);
9127 PUSH_INSN1(ret, location, getglobal,
rb_id2sym(idLASTLINE));
9128 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9129 if (popped) PUSH_INSN(ret, location, pop);
9137 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9139 int ise_index = ISEQ_BODY(iseq)->ise_size++;
9142 pm_scope_node_init(node, &next_scope_node, scope_node);
9144 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, location.
line);
9145 pm_scope_node_destroy(&next_scope_node);
9147 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
9148 PUSH_INSN2(ret, location, once, block_iseq,
INT2FIX(ise_index));
9149 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9151 if (popped) PUSH_INSN(ret, location, pop);
9157 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9158 PUSH_INSN1(ret, location, putobject, regexp);
9163 if (popped) PUSH_INSN(ret, location, pop);
9173 VALUE string = pm_static_literal_value(iseq, node, scope_node);
9176 PUSH_INSN1(ret, location, putobject,
string);
9179 PUSH_INSN1(ret, location, putstring,
string);
9182 PUSH_INSN1(ret, location, putchilledstring,
string);
9188 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL);
9189 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9190 if (popped) PUSH_INSN(ret, location, pop);
9199 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL);
9202 PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9206 PUSH_INSN(ret, location, intern);
9209 PUSH_INSN(ret, location, pop);
9219 PUSH_INSN(ret, location, putself);
9221 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret,
false, scope_node, NULL, NULL);
9222 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9224 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
9225 if (popped) PUSH_INSN(ret, location, pop);
9233 PUSH_GETLOCAL(ret, location, scope_node->local_table_for_iseq_size, 0);
9246 PM_COMPILE(element);
9249 if (!popped) PUSH_INSN1(ret, location, newhash,
INT2FIX(elements->
size * 2));
9258 pm_scope_node_init(node, &next_scope_node, scope_node);
9260 int opening_lineno = pm_location_line_number(parser, &cast->
opening_loc);
9261 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, opening_lineno);
9262 pm_scope_node_destroy(&next_scope_node);
9265 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9266 PUSH_CALL_WITH_BLOCK(ret, location, idLambda, argc, block);
9269 if (popped) PUSH_INSN(ret, location, pop);
9276 LABEL *end_label = NEW_LABEL(location.
line);
9279 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9280 if (!popped) PUSH_INSN(ret, location, dup);
9282 PUSH_INSNL(ret, location, branchunless, end_label);
9283 if (!popped) PUSH_INSN(ret, location, pop);
9285 PM_COMPILE_NOT_POPPED(cast->
value);
9286 if (!popped) PUSH_INSN(ret, location, dup);
9288 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9289 PUSH_LABEL(ret, end_label);
9299 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9301 PM_COMPILE_NOT_POPPED(cast->
value);
9304 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
9306 if (!popped) PUSH_INSN(ret, location, dup);
9307 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9316 LABEL *set_label = NEW_LABEL(location.
line);
9317 LABEL *end_label = NEW_LABEL(location.
line);
9319 PUSH_INSN1(ret, location, putobject,
Qtrue);
9320 PUSH_INSNL(ret, location, branchunless, set_label);
9323 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9324 if (!popped) PUSH_INSN(ret, location, dup);
9326 PUSH_INSNL(ret, location, branchif, end_label);
9327 if (!popped) PUSH_INSN(ret, location, pop);
9329 PUSH_LABEL(ret, set_label);
9330 PM_COMPILE_NOT_POPPED(cast->
value);
9331 if (!popped) PUSH_INSN(ret, location, dup);
9333 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9334 PUSH_LABEL(ret, end_label);
9344 PUSH_GETLOCAL(ret, location, index.index, index.level);
9353 PM_COMPILE_NOT_POPPED(cast->
value);
9354 if (!popped) PUSH_INSN(ret, location, dup);
9357 PUSH_SETLOCAL(ret, location, index.index, index.level);
9363 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9365 PUSH_INSN1(ret, location, putobject, regexp);
9367 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9368 if (popped) PUSH_INSN(ret, location, pop);
9379 PUSH_INSN(ret, location, putnil);
9382 PM_COMPILE_NOT_POPPED(cast->
value);
9383 PUSH_INSN(ret, location, dup);
9387 LABEL *matched_label = NEW_LABEL(location.
line);
9388 LABEL *unmatched_label = NEW_LABEL(location.
line);
9389 LABEL *done_label = NEW_LABEL(location.
line);
9390 pm_compile_pattern(iseq, scope_node, cast->
pattern, ret, matched_label, unmatched_label,
false,
false,
true, 2);
9394 PUSH_LABEL(ret, unmatched_label);
9395 PUSH_INSN(ret, location, pop);
9396 PUSH_INSN(ret, location, pop);
9398 if (!popped) PUSH_INSN1(ret, location, putobject,
Qfalse);
9399 PUSH_INSNL(ret, location, jump, done_label);
9400 PUSH_INSN(ret, location, putnil);
9404 PUSH_LABEL(ret, matched_label);
9405 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(2));
9406 if (!popped) PUSH_INSN1(ret, location, putobject,
Qtrue);
9407 PUSH_INSNL(ret, location, jump, done_label);
9409 PUSH_LABEL(ret, done_label);
9435 pm_compile_match_write_node(iseq, (
const pm_match_write_node_t *) node, &location, ret, popped, scope_node);
9438 rb_bug(
"A pm_missing_node_t should not exist in prism's AST.");
9445 ID module_id = pm_constant_id_lookup(scope_node, cast->
name);
9446 VALUE module_name =
rb_str_freeze(rb_sprintf(
"<module:%"PRIsVALUE
">", rb_id2str(module_id)));
9449 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9451 const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&next_scope_node, module_name, ISEQ_TYPE_CLASS, location.
line);
9452 pm_scope_node_destroy(&next_scope_node);
9454 const int flags = VM_DEFINECLASS_TYPE_MODULE | pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
9455 PUSH_INSN(ret, location, putnil);
9456 PUSH_INSN3(ret, location, defineclass,
ID2SYM(module_id), module_iseq,
INT2FIX(flags));
9459 if (popped) PUSH_INSN(ret, location, pop);
9468 PUSH_SETLOCAL(ret, location, index.index, index.level);
9482 DECL_ANCHOR(writes);
9483 DECL_ANCHOR(cleanup);
9486 state.position = popped ? 0 : 1;
9487 pm_compile_multi_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
9489 PM_COMPILE_NOT_POPPED(cast->
value);
9490 if (!popped) PUSH_INSN(ret, location, dup);
9492 PUSH_SEQ(ret, writes);
9493 if (!popped && state.stack_size >= 1) {
9496 PUSH_INSN1(ret, location, setn,
INT2FIX(state.stack_size));
9501 pm_multi_target_state_update(&state);
9503 PUSH_SEQ(ret, cleanup);
9512 pm_compile_next_node(iseq, (
const pm_next_node_t *) node, &location, ret, popped, scope_node);
9518 PUSH_INSN(ret, location, putnil);
9526 ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg = TRUE;
9535 if (reference_number > 0) {
9536 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1),
INT2FIX(reference_number << 1));
9539 PUSH_INSN(ret, location, putnil);
9550 LABEL *end_label = NEW_LABEL(location.
line);
9551 PM_COMPILE_NOT_POPPED(cast->
left);
9553 if (!popped) PUSH_INSN(ret, location, dup);
9554 PUSH_INSNL(ret, location, branchif, end_label);
9556 if (!popped) PUSH_INSN(ret, location, pop);
9557 PM_COMPILE(cast->
right);
9558 PUSH_LABEL(ret, end_label);
9566 PM_COMPILE_NOT_POPPED(cast->
value);
9569 PUSH_SETLOCAL(ret, location, index.index, index.level);
9581 if (cast->
body != NULL) {
9582 PM_COMPILE(cast->
body);
9585 PUSH_INSN(ret, location, putnil);
9602 DECL_ANCHOR(inner_pre);
9605 DECL_ANCHOR(inner_body);
9610 for (
size_t index = 0; index < body->
size; index++) {
9611 pm_compile_node(iseq, body->
nodes[index], inner_body,
true, scope_node);
9616 PUSH_INSN(inner_body, location, putnil);
9622 PUSH_SEQ(outer_pre, inner_pre);
9623 PUSH_SEQ(outer_pre, inner_body);
9632 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9635 pm_scope_node_init(node, &next_scope_node, scope_node);
9636 child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
9637 pm_scope_node_destroy(&next_scope_node);
9639 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
9641 int is_index = ISEQ_BODY(iseq)->ise_size++;
9642 PUSH_INSN2(ret, location, once, child_iseq,
INT2FIX(is_index));
9644 if (popped) PUSH_INSN(ret, location, pop);
9646 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9656 if (pm_optimizable_range_item_p(cast->
left) && pm_optimizable_range_item_p(cast->
right)) {
9667 PUSH_INSN1(ret, location, putobject, val);
9671 if (cast->
left != NULL) {
9672 PM_COMPILE(cast->
left);
9675 PUSH_INSN(ret, location, putnil);
9678 if (cast->
right != NULL) {
9679 PM_COMPILE(cast->
right);
9682 PUSH_INSN(ret, location, putnil);
9686 PUSH_INSN1(ret, location, newrange,
INT2FIX(exclude_end ? 1 : 0));
9695 PUSH_INSN1(ret, location, putobject, parse_rational((
const pm_rational_node_t *) node));
9702 pm_compile_redo_node(iseq, &location, ret, popped, scope_node);
9708 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9709 PUSH_INSN1(ret, location, putobject, regexp);
9716 pm_compile_rescue_node(iseq, (
const pm_rescue_node_t *) node, &location, ret, popped, scope_node);
9724 pm_scope_node_init((
const pm_node_t *) cast, &rescue_scope_node, scope_node);
9726 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
9733 pm_scope_node_destroy(&rescue_scope_node);
9735 LABEL *lstart = NEW_LABEL(location.
line);
9737 LABEL *lcont = NEW_LABEL(location.
line);
9739 lstart->rescued = LABEL_RESCUE_BEG;
9740 lend->rescued = LABEL_RESCUE_END;
9742 PUSH_LABEL(ret, lstart);
9744 PUSH_LABEL(ret, lend);
9746 PUSH_INSN(ret, location, nop);
9747 PUSH_LABEL(ret, lcont);
9748 if (popped) PUSH_INSN(ret, location, pop);
9750 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
9751 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
9760 pm_compile_return_node(iseq, (
const pm_return_node_t *) node, &location, ret, popped, scope_node);
9765 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_RESCUE) {
9766 PUSH_INSN(ret, location, putnil);
9767 PUSH_INSN1(ret, location,
throw,
INT2FIX(TAG_RETRY));
9768 if (popped) PUSH_INSN(ret, location, pop);
9771 COMPILE_ERROR(iseq, location.
line,
"Invalid retry");
9777 pm_compile_scope_node(iseq, (
pm_scope_node_t *) node, &location, ret, popped);
9783 PUSH_INSN(ret, location, putself);
9819 rb_bug(
"Unexpected node type for shareable constant write: %s", pm_node_type_to_str(
PM_NODE_TYPE(cast->
write)));
9831 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9832 const rb_iseq_t *child_iseq = NEW_ISEQ(&next_scope_node, rb_fstring_lit(
"singleton class"), ISEQ_TYPE_CLASS, location.
line);
9833 pm_scope_node_destroy(&next_scope_node);
9836 PUSH_INSN(ret, location, putnil);
9839 CONST_ID(singletonclass,
"singletonclass");
9840 PUSH_INSN3(ret, location, defineclass,
ID2SYM(singletonclass), child_iseq,
INT2FIX(VM_DEFINECLASS_TYPE_SINGLETON_CLASS));
9842 if (popped) PUSH_INSN(ret, location, pop);
9851 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9852 PUSH_INSN1(ret, location, putobject, value);
9861 VALUE string = pm_source_file_value(cast, scope_node);
9864 PUSH_INSN1(ret, location, putobject,
string);
9867 PUSH_INSN1(ret, location, putstring,
string);
9870 PUSH_INSN1(ret, location, putchilledstring,
string);
9879 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9880 PUSH_INSN1(ret, location, putobject, value);
9893 PUSH_INSN1(ret, location, splatarray,
Qtrue);
9902 if (body->
size > 0) {
9903 for (
size_t index = 0; index < body->
size - 1; index++) {
9904 PM_COMPILE_POPPED(body->
nodes[index]);
9906 PM_COMPILE(body->
nodes[body->
size - 1]);
9909 PUSH_INSN(ret, location, putnil);
9918 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
9921 PUSH_INSN1(ret, location, putobject, value);
9924 PUSH_INSN1(ret, location, putstring, value);
9927 PUSH_INSN1(ret, location, putchilledstring, value);
9936 pm_compile_super_node(iseq, (
const pm_super_node_t *) node, &location, ret, popped, scope_node);
9942 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9943 PUSH_INSN1(ret, location, putobject, value);
9951 PUSH_INSN1(ret, location, putobject,
Qtrue);
9961 for (
size_t index = 0; index < names->
size; index++) {
9962 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9963 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
9965 PM_COMPILE_NOT_POPPED(names->
nodes[index]);
9966 PUSH_SEND(ret, location, id_core_undef_method,
INT2NUM(2));
9968 if (index < names->size - 1) {
9969 PUSH_INSN(ret, location, pop);
9973 if (popped) PUSH_INSN(ret, location, pop);
9988 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);
9998 pm_compile_loop(iseq, &location, cast->
base.
flags,
PM_UNTIL_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10008 pm_compile_loop(iseq, &location, cast->
base.
flags,
PM_WHILE_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10015 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10017 PUSH_INSN(ret, location, putself);
10018 PUSH_INSN1(ret, location, putobject, value);
10019 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
10020 if (popped) PUSH_INSN(ret, location, pop);
10030 pm_compile_yield_node(iseq, (
const pm_yield_node_t *) node, &location, ret, popped, scope_node);
10038#undef PM_CONTAINER_P
10042pm_iseq_pre_execution_p(
rb_iseq_t *iseq)
10044 switch (ISEQ_BODY(iseq)->
type) {
10045 case ISEQ_TYPE_TOP:
10046 case ISEQ_TYPE_EVAL:
10047 case ISEQ_TYPE_MAIN:
10066 if (pm_iseq_pre_execution_p(iseq)) {
10078 pm_compile_node(iseq, (
const pm_node_t *) node, body,
false, node);
10082 PUSH_SEQ(ret, pre);
10083 PUSH_SEQ(ret, body);
10088 pm_compile_node(iseq, (
const pm_node_t *) node, ret,
false, node);
10091 CHECK(iseq_setup_insn(iseq, ret));
10092 return iseq_setup(iseq, ret);
10102 if (result->
node.ast_node != NULL) {
10103 pm_node_destroy(&result->
parser, result->
node.ast_node);
10108 pm_scope_node_destroy(&result->
node);
10111 pm_parser_free(&result->
parser);
10112 pm_string_free(&result->
input);
10113 pm_options_free(&result->
options);
10149#define PM_COLOR_BOLD "\033[1m"
10150#define PM_COLOR_GRAY "\033[2m"
10151#define PM_COLOR_RED "\033[1;31m"
10152#define PM_COLOR_RESET "\033[m"
10153#define PM_ERROR_TRUNCATE 30
10158 if (errors == NULL)
return NULL;
10162 pm_line_column_t start = pm_newline_list_line_column(newline_list, error->location.
start, start_line);
10163 pm_line_column_t end = pm_newline_list_line_column(newline_list, error->location.end, start_line);
10171 (index < error_list->size) &&
10172 (errors[index].error != NULL) &&
10174 (errors[index].line < start.
line) ||
10181 if (index + 1 < error_list->
size) {
10182 memmove(&errors[index + 1], &errors[index],
sizeof(
pm_parse_error_t) * (error_list->
size - index - 1));
10186 uint32_t column_end;
10188 column_end = end.
column;
10190 column_end = (uint32_t) (newline_list->
offsets[start.
line - start_line + 1] - newline_list->
offsets[start.
line - start_line] - 1);
10194 if (start.
column == column_end) column_end++;
10198 .line = start.
line,
10199 .column_start = start.
column,
10200 .column_end = column_end
10208#define pm_buffer_append_literal(buffer, str) pm_buffer_append_string(buffer, str, rb_strlen_lit(str))
10211pm_parse_errors_format_line(
const pm_parser_t *parser,
const pm_newline_list_t *newline_list,
const char *number_prefix, int32_t line, uint32_t column_start, uint32_t column_end,
pm_buffer_t *buffer) {
10212 int32_t line_delta = line - parser->
start_line;
10213 assert(line_delta >= 0);
10215 size_t index = (size_t) line_delta;
10216 assert(index < newline_list->size);
10218 const uint8_t *start = &parser->
start[newline_list->
offsets[index]];
10219 const uint8_t *end;
10221 if (index >= newline_list->
size - 1) {
10224 end = &parser->
start[newline_list->
offsets[index + 1]];
10227 pm_buffer_append_format(buffer, number_prefix, line);
10230 bool truncate_end =
false;
10231 if ((column_end != 0) && ((end - (start + column_end)) >= PM_ERROR_TRUNCATE)) {
10232 end = start + column_end + PM_ERROR_TRUNCATE;
10233 truncate_end =
true;
10237 if (column_start >= PM_ERROR_TRUNCATE) {
10238 pm_buffer_append_string(buffer,
"... ", 4);
10239 start += column_start;
10242 pm_buffer_append_string(buffer, (
const char *) start, (
size_t) (end - start));
10244 if (truncate_end) {
10245 pm_buffer_append_string(buffer,
" ...\n", 5);
10246 }
else if (end == parser->
end && end[-1] !=
'\n') {
10247 pm_buffer_append_string(buffer,
"\n", 1);
10256 assert(error_list->
size != 0);
10260 const int32_t start_line = parser->
start_line;
10263 pm_parse_error_t *errors = pm_parse_errors_format_sort(parser, error_list, newline_list);
10264 if (errors == NULL)
return;
10270 int32_t first_line_number = errors[0].
line;
10271 int32_t last_line_number = errors[error_list->
size - 1].
line;
10276 if (first_line_number < 0) first_line_number = (-first_line_number) * 10;
10277 if (last_line_number < 0) last_line_number = (-last_line_number) * 10;
10278 int32_t max_line_number = first_line_number > last_line_number ? first_line_number : last_line_number;
10280 if (max_line_number < 10) {
10281 if (highlight > 0) {
10283 .
number_prefix = PM_COLOR_GRAY
"%1" PRIi32
" | " PM_COLOR_RESET,
10284 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10285 .divider = PM_COLOR_GRAY
" ~~~~~" PM_COLOR_RESET
"\n"
10290 .blank_prefix =
" | ",
10291 .divider =
" ~~~~~\n"
10294 }
else if (max_line_number < 100) {
10295 if (highlight > 0) {
10297 .
number_prefix = PM_COLOR_GRAY
"%2" PRIi32
" | " PM_COLOR_RESET,
10298 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10299 .divider = PM_COLOR_GRAY
" ~~~~~~" PM_COLOR_RESET
"\n"
10304 .blank_prefix =
" | ",
10305 .divider =
" ~~~~~~\n"
10308 }
else if (max_line_number < 1000) {
10309 if (highlight > 0) {
10311 .
number_prefix = PM_COLOR_GRAY
"%3" PRIi32
" | " PM_COLOR_RESET,
10312 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10313 .divider = PM_COLOR_GRAY
" ~~~~~~~" PM_COLOR_RESET
"\n"
10318 .blank_prefix =
" | ",
10319 .divider =
" ~~~~~~~\n"
10322 }
else if (max_line_number < 10000) {
10323 if (highlight > 0) {
10325 .
number_prefix = PM_COLOR_GRAY
"%4" PRIi32
" | " PM_COLOR_RESET,
10326 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10327 .divider = PM_COLOR_GRAY
" ~~~~~~~~" PM_COLOR_RESET
"\n"
10332 .blank_prefix =
" | ",
10333 .divider =
" ~~~~~~~~\n"
10337 if (highlight > 0) {
10339 .
number_prefix = PM_COLOR_GRAY
"%5" PRIi32
" | " PM_COLOR_RESET,
10340 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10341 .divider = PM_COLOR_GRAY
" ~~~~~~~~" PM_COLOR_RESET
"\n"
10346 .blank_prefix =
" | ",
10347 .divider =
" ~~~~~~~~\n"
10361 uint32_t last_column_start = 0;
10364 for (
size_t index = 0; index < error_list->
size; index++) {
10369 if (error->
line - last_line > 1) {
10370 if (error->
line - last_line > 2) {
10371 if ((index != 0) && (error->
line - last_line > 3)) {
10375 pm_buffer_append_string(buffer,
" ", 2);
10376 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, error->
line - 2, 0, 0, buffer);
10379 pm_buffer_append_string(buffer,
" ", 2);
10380 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, error->
line - 1, 0, 0, buffer);
10385 if ((index == 0) || (error->
line != last_line)) {
10386 if (highlight > 1) {
10387 pm_buffer_append_literal(buffer, PM_COLOR_RED
"> " PM_COLOR_RESET);
10388 }
else if (highlight > 0) {
10389 pm_buffer_append_literal(buffer, PM_COLOR_BOLD
"> " PM_COLOR_RESET);
10391 pm_buffer_append_literal(buffer,
"> ");
10398 for (
size_t next_index = index + 1; next_index < error_list->
size; next_index++) {
10399 if (errors[next_index].line != error->
line)
break;
10400 if (errors[next_index].column_end > column_end) column_end = errors[next_index].
column_end;
10406 const uint8_t *start = &parser->
start[newline_list->
offsets[error->
line - start_line]];
10407 if (start == parser->
end) pm_buffer_append_byte(buffer,
'\n');
10418 pm_buffer_append_string(buffer,
" ", 2);
10422 if (last_column_start >= PM_ERROR_TRUNCATE) {
10423 pm_buffer_append_string(buffer,
" ", 4);
10424 column = last_column_start;
10427 while (column < error->column_start) {
10428 pm_buffer_append_byte(buffer,
' ');
10430 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10431 column += (char_width == 0 ? 1 : char_width);
10434 if (highlight > 1) pm_buffer_append_literal(buffer, PM_COLOR_RED);
10435 else if (highlight > 0) pm_buffer_append_literal(buffer, PM_COLOR_BOLD);
10436 pm_buffer_append_byte(buffer,
'^');
10438 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10439 column += (char_width == 0 ? 1 : char_width);
10441 while (column < error->column_end) {
10442 pm_buffer_append_byte(buffer,
'~');
10444 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10445 column += (char_width == 0 ? 1 : char_width);
10448 if (highlight > 0) pm_buffer_append_literal(buffer, PM_COLOR_RESET);
10450 if (inline_messages) {
10451 pm_buffer_append_byte(buffer,
' ');
10452 assert(error->
error != NULL);
10455 pm_buffer_append_string(buffer, message, strlen(message));
10458 pm_buffer_append_byte(buffer,
'\n');
10462 last_line = error->
line;
10465 if (index == error_list->
size - 1) {
10466 next_line = (((int32_t) newline_list->
size) + parser->
start_line);
10475 next_line = errors[index + 1].
line;
10478 if (next_line - last_line > 1) {
10479 pm_buffer_append_string(buffer,
" ", 2);
10480 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, ++last_line, 0, 0, buffer);
10483 if (next_line - last_line > 1) {
10484 pm_buffer_append_string(buffer,
" ", 2);
10485 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, ++last_line, 0, 0, buffer);
10493#undef PM_ERROR_TRUNCATE
10494#undef PM_COLOR_GRAY
10496#undef PM_COLOR_RESET
10507 const size_t start_line = pm_newline_list_line_column(&parser->
newline_list, location->
start, 1).
line;
10508 const size_t end_line = pm_newline_list_line_column(&parser->
newline_list, location->
end, 1).
line;
10511 const uint8_t *end = ((end_line == parser->
newline_list.
size) ? parser->
end : (parser->start + parser->newline_list.offsets[end_line]));
10514 while (start < end) {
10515 if ((width = pm_encoding_utf_8_char_width(start, end - start)) == 0)
return false;
10531 bool valid_utf8 =
true;
10536 int highlight = rb_stderr_tty_p();
10538 const char *no_color = getenv(
"NO_COLOR");
10539 highlight = (no_color == NULL || no_color[0] ==
'\0') ? 2 : 1;
10543 switch (error->level) {
10550 if (valid_utf8 && !pm_parse_process_error_utf8_p(parser, &error->location)) {
10551 valid_utf8 =
false;
10558 int32_t line_number = (int32_t) pm_location_line_number(parser, &error->location);
10560 pm_buffer_append_format(
10562 "%.*s:%" PRIi32
": %s",
10563 (
int) pm_string_length(filepath),
10564 pm_string_source(filepath),
10569 if (pm_parse_process_error_utf8_p(parser, &error->location)) {
10570 pm_buffer_append_byte(&buffer,
'\n');
10573 pm_list_t error_list = { .
size = 1, .head = list_node, .tail = list_node };
10575 pm_parse_errors_format(parser, &error_list, &buffer, highlight,
false);
10578 VALUE value =
rb_exc_new(rb_eArgError, pm_buffer_value(&buffer), pm_buffer_length(&buffer));
10579 pm_buffer_free(&buffer);
10595 pm_buffer_append_format(
10597 "%.*s:%" PRIi32
": syntax error%s found\n",
10598 (
int) pm_string_length(filepath),
10599 pm_string_source(filepath),
10600 (int32_t) pm_location_line_number(parser, &head->location),
10605 pm_parse_errors_format(parser, &parser->
error_list, &buffer, highlight,
true);
10609 if (error != head) pm_buffer_append_byte(&buffer,
'\n');
10610 pm_buffer_append_format(&buffer,
"%.*s:%" PRIi32
": %s", (
int) pm_string_length(filepath), pm_string_source(filepath), (int32_t) pm_location_line_number(parser, &error->location), error->message);
10614 VALUE message = rb_enc_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer), result->
node.encoding);
10618 VALUE path = rb_enc_str_new((
const char *) pm_string_source(filepath), pm_string_length(filepath), filepath_encoding);
10621 pm_buffer_free(&buffer);
10640 int coverage_enabled = scope_node->coverage_enabled;
10642 pm_scope_node_init(node, scope_node, NULL);
10645 scope_node->encoding = rb_enc_find(parser->
encoding->
name);
10646 if (!scope_node->encoding) rb_bug(
"Encoding not found %s!", parser->
encoding->
name);
10648 scope_node->coverage_enabled = coverage_enabled;
10652 if (script_lines != NULL) {
10658 rb_ary_push(*script_lines, rb_enc_str_new((
const char *) parser->
start + offset, length, scope_node->encoding));
10666 const char *warning_filepath = (
const char *) pm_string_source(&parser->
filepath);
10669 int line = pm_location_line_number(parser, &warning->
location);
10672 rb_enc_compile_warning(scope_node->encoding, warning_filepath, line,
"%s", warning->
message);
10675 rb_enc_compile_warn(scope_node->encoding, warning_filepath, line,
"%s", warning->
message);
10681 VALUE error = pm_parse_process_error(result);
10690 scope_node->parser = parser;
10695 scope_node->constants[index] = rb_intern3((
const char *) constant->
start, constant->
length, scope_node->encoding);
10698 scope_node->index_lookup_table = st_init_numtable();
10700 for (
size_t index = 0; index < locals->
size; index++) {
10701 st_insert(scope_node->index_lookup_table, locals->
ids[index], index);
10715pm_options_frozen_string_literal_init(
pm_options_t *options)
10717 int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
10719 switch (frozen_string_literal) {
10720 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
10722 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
10723 pm_options_frozen_string_literal_set(options,
false);
10725 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
10726 pm_options_frozen_string_literal_set(options,
true);
10729 rb_bug(
"pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
10742 const char *start = (
const char *) parser->
start;
10743 const char *end = (
const char *) parser->
end;
10748 size_t last_offset = newline_list->
offsets[newline_list->
size - 1];
10749 bool last_push = start + last_offset != end;
10752 VALUE lines = rb_ary_new_capa(newline_list->
size - (last_push ? 0 : 1));
10754 for (
size_t index = 0; index < newline_list->
size - 1; index++) {
10755 size_t offset = newline_list->
offsets[index];
10756 size_t length = newline_list->
offsets[index + 1] - offset;
10758 rb_ary_push(lines, rb_enc_str_new(start + offset, length, scope_node->encoding));
10763 rb_ary_push(lines, rb_enc_str_new(start + last_offset, end - (start + last_offset), scope_node->encoding));
10773pm_read_file(
pm_string_t *
string,
const char *filepath)
10777 int length = MultiByteToWideChar(CP_UTF8, 0, filepath, -1, NULL, 0);
10780 WCHAR *wfilepath =
xmalloc(
sizeof(WCHAR) * ((
size_t) length));
10781 if ((wfilepath == NULL) || (MultiByteToWideChar(CP_UTF8, 0, filepath, -1, wfilepath, length) == 0)) {
10786 HANDLE file = CreateFileW(wfilepath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
10787 if (file == INVALID_HANDLE_VALUE) {
10790 if (GetLastError() == ERROR_ACCESS_DENIED) {
10791 DWORD attributes = GetFileAttributesW(wfilepath);
10792 if ((attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
10802 DWORD file_size = GetFileSize(file, NULL);
10803 if (file_size == INVALID_FILE_SIZE) {
10811 if (file_size == 0) {
10814 const uint8_t source[] =
"";
10815 *
string = (
pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
10820 HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
10821 if (mapping == NULL) {
10828 uint8_t *source = (uint8_t *) MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
10829 CloseHandle(mapping);
10833 if (source == NULL) {
10837 *
string = (
pm_string_t) { .type = PM_STRING_MAPPED, .source = source, .length = (size_t) file_size };
10839#elif defined(_POSIX_MAPPED_FILES)
10841 const int open_mode = O_RDONLY | O_NONBLOCK;
10842 int fd = open(filepath, open_mode);
10849 if (fstat(fd, &sb) == -1) {
10855 if (S_ISDIR(sb.st_mode)) {
10863 if (S_ISFIFO(sb.st_mode) || S_ISCHR(sb.st_mode)) {
10872 long len = RSTRING_LEN(contents);
10877 size_t length = (size_t)
len;
10878 uint8_t *source = malloc(length);
10879 memcpy(source, RSTRING_PTR(contents), length);
10880 *
string = (
pm_string_t) { .type = PM_STRING_OWNED, .source = source, .length = length };
10886 size_t size = (size_t) sb.st_size;
10887 uint8_t *source = NULL;
10891 const uint8_t source[] =
"";
10892 *
string = (
pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
10896 source = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
10897 if (source == MAP_FAILED) {
10903 *
string = (
pm_string_t) { .type = PM_STRING_MAPPED, .source = source, .length = size };
10906 return pm_string_file_init(
string, filepath);
10920 pm_options_frozen_string_literal_init(&result->
options);
10929 err = rb_w32_map_errno(GetLastError());
10961 pm_options_filepath_set(&result->
options, RSTRING_PTR(filepath));
10964 pm_parser_init(&result->
parser, pm_string_source(&result->
input), pm_string_length(&result->
input), &result->
options);
10967 VALUE error = pm_parse_process(result, node, script_lines);
10972 ID id_script_lines = rb_intern(
"SCRIPT_LINES__");
10978 rb_hash_aset(constant_script_lines, filepath, pm_parse_file_script_lines(&result->
node, &result->
parser));
10992 VALUE error = pm_load_file(result, filepath,
false);
10993 if (
NIL_P(error)) {
10994 error = pm_parse_file(result, filepath, script_lines);
11010 if (!rb_enc_asciicompat(encoding)) {
11014 pm_options_frozen_string_literal_init(&result->
options);
11015 pm_string_constant_init(&result->
input, RSTRING_PTR(source), RSTRING_LEN(source));
11016 pm_options_encoding_set(&result->
options, rb_enc_name(encoding));
11019 pm_options_filepath_set(&result->
options, RSTRING_PTR(filepath));
11022 pm_parser_init(&result->
parser, pm_string_source(&result->
input), pm_string_length(&result->
input), &result->
options);
11025 return pm_parse_process(result, node, script_lines);
11032pm_parse_stdin_fgets(
char *
string,
int size,
void *stream)
11041 const char *cstr = RSTRING_PTR(line);
11042 long length = RSTRING_LEN(line);
11044 memcpy(
string, cstr, length);
11045 string[length] =
'\0';
11051void rb_reset_argf_lineno(
long n);
11061 pm_options_frozen_string_literal_init(&result->
options);
11069 pm_string_owned_init(&result->
input, (uint8_t *) pm_buffer_value(&buffer), pm_buffer_length(&buffer));
11073 rb_reset_argf_lineno(0);
11075 return pm_parse_process(result, node, NULL);
11079#define NEW_ISEQ OLD_ISEQ
11081#undef NEW_CHILD_ISEQ
11082#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.
@ PM_INTERPOLATED_STRING_NODE_FLAGS_MUTABLE
mutable by virtue of a frozen_string_literal: false comment or --disable-frozen-string-literal; only ...
@ PM_INTERPOLATED_STRING_NODE_FLAGS_FROZEN
frozen by virtue of a frozen_string_literal: true comment or --enable-frozen-string-literal; only for...
@ PM_RANGE_FLAGS_EXCLUDE_END
... operator
pm_node_type
This enum represents every type of node in the Ruby syntax tree.
@ PM_DEFINED_NODE
DefinedNode.
@ PM_PRE_EXECUTION_NODE
PreExecutionNode.
@ PM_RETRY_NODE
RetryNode.
@ PM_CONSTANT_PATH_WRITE_NODE
ConstantPathWriteNode.
@ PM_INDEX_AND_WRITE_NODE
IndexAndWriteNode.
@ PM_SOURCE_LINE_NODE
SourceLineNode.
@ PM_UNLESS_NODE
UnlessNode.
@ PM_EMBEDDED_VARIABLE_NODE
EmbeddedVariableNode.
@ PM_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE
GlobalVariableOperatorWriteNode.
@ PM_GLOBAL_VARIABLE_READ_NODE
GlobalVariableReadNode.
@ PM_RATIONAL_NODE
RationalNode.
@ PM_YIELD_NODE
YieldNode.
@ PM_LOCAL_VARIABLE_AND_WRITE_NODE
LocalVariableAndWriteNode.
@ PM_CONSTANT_AND_WRITE_NODE
ConstantAndWriteNode.
@ PM_CLASS_NODE
ClassNode.
@ PM_FIND_PATTERN_NODE
FindPatternNode.
@ PM_CALL_OPERATOR_WRITE_NODE
CallOperatorWriteNode.
@ PM_MATCH_WRITE_NODE
MatchWriteNode.
@ PM_ARRAY_NODE
ArrayNode.
@ PM_CONSTANT_PATH_TARGET_NODE
ConstantPathTargetNode.
@ PM_PROGRAM_NODE
ProgramNode.
@ PM_MULTI_WRITE_NODE
MultiWriteNode.
@ PM_IMPLICIT_NODE
ImplicitNode.
@ PM_ARGUMENTS_NODE
ArgumentsNode.
@ PM_FORWARDING_SUPER_NODE
ForwardingSuperNode.
@ PM_WHILE_NODE
WhileNode.
@ PM_INTERPOLATED_STRING_NODE
InterpolatedStringNode.
@ PM_FALSE_NODE
FalseNode.
@ PM_FORWARDING_PARAMETER_NODE
ForwardingParameterNode.
@ PM_UNTIL_NODE
UntilNode.
@ PM_MATCH_PREDICATE_NODE
MatchPredicateNode.
@ PM_X_STRING_NODE
XStringNode.
@ PM_LOCAL_VARIABLE_OPERATOR_WRITE_NODE
LocalVariableOperatorWriteNode.
@ PM_LOCAL_VARIABLE_OR_WRITE_NODE
LocalVariableOrWriteNode.
@ PM_INSTANCE_VARIABLE_AND_WRITE_NODE
InstanceVariableAndWriteNode.
@ PM_GLOBAL_VARIABLE_TARGET_NODE
GlobalVariableTargetNode.
@ PM_CONSTANT_TARGET_NODE
ConstantTargetNode.
@ PM_IT_LOCAL_VARIABLE_READ_NODE
ItLocalVariableReadNode.
@ PM_CONSTANT_PATH_AND_WRITE_NODE
ConstantPathAndWriteNode.
@ PM_CAPTURE_PATTERN_NODE
CapturePatternNode.
@ PM_SOURCE_FILE_NODE
SourceFileNode.
@ PM_NO_KEYWORDS_PARAMETER_NODE
NoKeywordsParameterNode.
@ PM_CONSTANT_PATH_OPERATOR_WRITE_NODE
ConstantPathOperatorWriteNode.
@ PM_MULTI_TARGET_NODE
MultiTargetNode.
@ PM_SPLAT_NODE
SplatNode.
@ PM_LAMBDA_NODE
LambdaNode.
@ PM_CLASS_VARIABLE_READ_NODE
ClassVariableReadNode.
@ PM_REQUIRED_KEYWORD_PARAMETER_NODE
RequiredKeywordParameterNode.
@ PM_CALL_TARGET_NODE
CallTargetNode.
@ PM_INTERPOLATED_MATCH_LAST_LINE_NODE
InterpolatedMatchLastLineNode.
@ PM_NUMBERED_PARAMETERS_NODE
NumberedParametersNode.
@ PM_SYMBOL_NODE
SymbolNode.
@ PM_RESCUE_MODIFIER_NODE
RescueModifierNode.
@ PM_ALIAS_METHOD_NODE
AliasMethodNode.
@ PM_MATCH_REQUIRED_NODE
MatchRequiredNode.
@ PM_FORWARDING_ARGUMENTS_NODE
ForwardingArgumentsNode.
@ PM_BACK_REFERENCE_READ_NODE
BackReferenceReadNode.
@ PM_SCOPE_NODE
A special kind of node used for compilation.
@ PM_BLOCK_ARGUMENT_NODE
BlockArgumentNode.
@ PM_MISSING_NODE
MissingNode.
@ PM_IMPLICIT_REST_NODE
ImplicitRestNode.
@ PM_ASSOC_SPLAT_NODE
AssocSplatNode.
@ PM_CLASS_VARIABLE_AND_WRITE_NODE
ClassVariableAndWriteNode.
@ PM_RANGE_NODE
RangeNode.
@ PM_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE
InstanceVariableOperatorWriteNode.
@ PM_LOCAL_VARIABLE_READ_NODE
LocalVariableReadNode.
@ PM_SHAREABLE_CONSTANT_NODE
ShareableConstantNode.
@ PM_INSTANCE_VARIABLE_OR_WRITE_NODE
InstanceVariableOrWriteNode.
@ PM_REGULAR_EXPRESSION_NODE
RegularExpressionNode.
@ PM_CLASS_VARIABLE_OR_WRITE_NODE
ClassVariableOrWriteNode.
@ PM_BLOCK_PARAMETERS_NODE
BlockParametersNode.
@ PM_CONSTANT_WRITE_NODE
ConstantWriteNode.
@ PM_HASH_PATTERN_NODE
HashPatternNode.
@ PM_INDEX_OPERATOR_WRITE_NODE
IndexOperatorWriteNode.
@ PM_UNDEF_NODE
UndefNode.
@ PM_ALTERNATION_PATTERN_NODE
AlternationPatternNode.
@ PM_ENSURE_NODE
EnsureNode.
@ PM_LOCAL_VARIABLE_WRITE_NODE
LocalVariableWriteNode.
@ PM_SINGLETON_CLASS_NODE
SingletonClassNode.
@ PM_KEYWORD_HASH_NODE
KeywordHashNode.
@ PM_PARENTHESES_NODE
ParenthesesNode.
@ PM_CLASS_VARIABLE_WRITE_NODE
ClassVariableWriteNode.
@ PM_POST_EXECUTION_NODE
PostExecutionNode.
@ PM_CONSTANT_OPERATOR_WRITE_NODE
ConstantOperatorWriteNode.
@ PM_RETURN_NODE
ReturnNode.
@ PM_MODULE_NODE
ModuleNode.
@ PM_ARRAY_PATTERN_NODE
ArrayPatternNode.
@ PM_SUPER_NODE
SuperNode.
@ PM_MATCH_LAST_LINE_NODE
MatchLastLineNode.
@ PM_CONSTANT_PATH_NODE
ConstantPathNode.
@ PM_INTERPOLATED_SYMBOL_NODE
InterpolatedSymbolNode.
@ PM_CALL_AND_WRITE_NODE
CallAndWriteNode.
@ PM_OPTIONAL_KEYWORD_PARAMETER_NODE
OptionalKeywordParameterNode.
@ PM_CLASS_VARIABLE_TARGET_NODE
ClassVariableTargetNode.
@ PM_CASE_MATCH_NODE
CaseMatchNode.
@ PM_BREAK_NODE
BreakNode.
@ PM_CALL_OR_WRITE_NODE
CallOrWriteNode.
@ PM_IMAGINARY_NODE
ImaginaryNode.
@ PM_CONSTANT_READ_NODE
ConstantReadNode.
@ PM_GLOBAL_VARIABLE_WRITE_NODE
GlobalVariableWriteNode.
@ PM_SOURCE_ENCODING_NODE
SourceEncodingNode.
@ PM_BEGIN_NODE
BeginNode.
@ PM_INTERPOLATED_X_STRING_NODE
InterpolatedXStringNode.
@ PM_INSTANCE_VARIABLE_READ_NODE
InstanceVariableReadNode.
@ PM_FLIP_FLOP_NODE
FlipFlopNode.
@ PM_PINNED_VARIABLE_NODE
PinnedVariableNode.
@ PM_REQUIRED_PARAMETER_NODE
RequiredParameterNode.
@ PM_INSTANCE_VARIABLE_WRITE_NODE
InstanceVariableWriteNode.
@ PM_INSTANCE_VARIABLE_TARGET_NODE
InstanceVariableTargetNode.
@ PM_GLOBAL_VARIABLE_AND_WRITE_NODE
GlobalVariableAndWriteNode.
@ PM_RESCUE_NODE
RescueNode.
@ PM_FLOAT_NODE
FloatNode.
@ PM_ASSOC_NODE
AssocNode.
@ PM_IT_PARAMETERS_NODE
ItParametersNode.
@ PM_INTEGER_NODE
IntegerNode.
@ PM_LOCAL_VARIABLE_TARGET_NODE
LocalVariableTargetNode.
@ PM_STRING_NODE
StringNode.
@ PM_INDEX_OR_WRITE_NODE
IndexOrWriteNode.
@ PM_ALIAS_GLOBAL_VARIABLE_NODE
AliasGlobalVariableNode.
@ PM_PARAMETERS_NODE
ParametersNode.
@ PM_NUMBERED_REFERENCE_READ_NODE
NumberedReferenceReadNode.
@ PM_CONSTANT_PATH_OR_WRITE_NODE
ConstantPathOrWriteNode.
@ PM_GLOBAL_VARIABLE_OR_WRITE_NODE
GlobalVariableOrWriteNode.
@ PM_CONSTANT_OR_WRITE_NODE
ConstantOrWriteNode.
@ PM_STATEMENTS_NODE
StatementsNode.
@ PM_OPTIONAL_PARAMETER_NODE
OptionalParameterNode.
@ PM_PINNED_EXPRESSION_NODE
PinnedExpressionNode.
@ PM_BLOCK_NODE
BlockNode.
@ PM_CLASS_VARIABLE_OPERATOR_WRITE_NODE
ClassVariableOperatorWriteNode.
@ PM_EMBEDDED_STATEMENTS_NODE
EmbeddedStatementsNode.
@ PM_INTERPOLATED_REGULAR_EXPRESSION_NODE
InterpolatedRegularExpressionNode.
@ PM_INDEX_TARGET_NODE
IndexTargetNode.
@ PM_KEYWORD_REST_PARAMETER_NODE
KeywordRestParameterNode.
static const pm_node_flags_t PM_NODE_FLAG_NEWLINE
We store the flags enum in every node in the tree.
@ PM_SYMBOL_FLAGS_FORCED_UTF8_ENCODING
internal bytes forced the encoding to UTF-8
@ PM_SYMBOL_FLAGS_FORCED_US_ASCII_ENCODING
internal bytes forced the encoding to US-ASCII
@ PM_SYMBOL_FLAGS_FORCED_BINARY_ENCODING
internal bytes forced the encoding to binary
@ PM_STRING_FLAGS_FROZEN
frozen by virtue of a frozen_string_literal: true comment or --enable-frozen-string-literal
@ PM_STRING_FLAGS_FORCED_BINARY_ENCODING
internal bytes forced the encoding to binary
@ PM_STRING_FLAGS_MUTABLE
mutable by virtue of a frozen_string_literal: false comment or --disable-frozen-string-literal
@ PM_STRING_FLAGS_FORCED_UTF8_ENCODING
internal bytes forced the encoding to UTF-8
@ PM_ARGUMENTS_NODE_FLAGS_CONTAINS_SPLAT
if the arguments contain a splat
@ PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING
if the arguments contain forwarding
@ PM_ARGUMENTS_NODE_FLAGS_CONTAINS_KEYWORD_SPLAT
if the arguments contain a keyword splat
@ PM_ARGUMENTS_NODE_FLAGS_CONTAINS_MULTIPLE_SPLATS
if the arguments contain multiple splats
#define PM_NODE_FLAG_P(node, flag)
Return true if the given flag is set on the given node.
#define PM_NODE_TYPE_P(node, type)
Return true if the type of the given node matches the given type.
#define PM_NODE_TYPE(node)
Cast the type to an enum to allow the compiler to provide exhaustiveness checking.
@ PM_CALL_NODE_FLAGS_IGNORE_VISIBILITY
a call that ignores method visibility
@ PM_CALL_NODE_FLAGS_SAFE_NAVIGATION
&.
@ PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE
a call that is an attribute write, so the value being written should be returned
@ PM_CALL_NODE_FLAGS_VARIABLE_CALL
a call that could have been a local variable
@ PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_EVERYTHING
constant writes that should be modified with shareable constant value experimental everything
@ PM_SHAREABLE_CONSTANT_NODE_FLAGS_LITERAL
constant writes that should be modified with shareable constant value literal
@ PM_SHAREABLE_CONSTANT_NODE_FLAGS_EXPERIMENTAL_COPY
constant writes that should be modified with shareable constant value experimental copy
uint16_t pm_node_type_t
This is the type of node embedded in the node struct.
@ PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS
a keyword hash which only has AssocNode elements all with symbol keys, which means the elements can b...
@ PM_REGULAR_EXPRESSION_FLAGS_FORCED_BINARY_ENCODING
internal bytes forced the encoding to binary
@ PM_REGULAR_EXPRESSION_FLAGS_EUC_JP
e - forces the EUC-JP encoding
@ PM_REGULAR_EXPRESSION_FLAGS_IGNORE_CASE
i - ignores the case of characters when matching
@ PM_REGULAR_EXPRESSION_FLAGS_ASCII_8BIT
n - forces the ASCII-8BIT encoding
@ PM_REGULAR_EXPRESSION_FLAGS_MULTI_LINE
m - allows $ to match the end of lines within strings
@ PM_REGULAR_EXPRESSION_FLAGS_EXTENDED
x - ignores whitespace and allows comments in regular expressions
@ PM_REGULAR_EXPRESSION_FLAGS_ONCE
o - only interpolates values into the regular expression once
@ PM_REGULAR_EXPRESSION_FLAGS_WINDOWS_31J
s - forces the Windows-31J encoding
@ PM_REGULAR_EXPRESSION_FLAGS_UTF_8
u - forces the UTF-8 encoding
uint16_t pm_node_flags_t
These are the flags embedded in the node struct.
@ PM_PARAMETER_FLAGS_REPEATED_PARAMETER
a parameter name that has been repeated in the method signature
@ PM_ENCODING_FLAGS_FORCED_BINARY_ENCODING
internal bytes forced the encoding to binary
@ PM_ENCODING_FLAGS_FORCED_UTF8_ENCODING
internal bytes forced the encoding to UTF-8
@ PM_LOOP_FLAGS_BEGIN_MODIFIER
a loop after a begin statement, so the body is executed first before the condition
@ 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 OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define ULONG2NUM
Old name of RB_ULONG2NUM.
#define FIXABLE
Old name of RB_FIXABLE.
#define xmalloc
Old name of ruby_xmalloc.
#define LONG2FIX
Old name of RB_INT2FIX.
#define ZALLOC_N
Old name of RB_ZALLOC_N.
#define T_HASH
Old name of RUBY_T_HASH.
#define ALLOC_N
Old name of RB_ALLOC_N.
#define rb_exc_new3
Old name of rb_exc_new_str.
#define Qtrue
Old name of RUBY_Qtrue.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define NIL_P
Old name of RB_NIL_P.
#define DBL2NUM
Old name of rb_float_new.
#define 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.
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_exc_new(VALUE etype, const char *ptr, long len)
Creates an instance of the passed exception class.
VALUE rb_eNoMatchingPatternKeyError
NoMatchingPatternKeyError exception.
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Identical to rb_exc_new_cstr(), except it takes a Ruby's string instead of C's.
VALUE rb_eSyntaxError
SyntaxError exception.
VALUE rb_syserr_new(int n, const char *mesg)
Creates an exception object that represents the given C errno.
VALUE rb_cArray
Array class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_stdin
STDIN constant.
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_io_fdopen(int fd, int flags, const char *path)
Creates an IO instance whose backend is the given file descriptor.
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_str_new(str, len)
Allocates an instance of rb_cString.
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
#define rb_str_buf_new_cstr(str)
Identical to rb_str_new_cstr, except done differently.
VALUE rb_str_concat(VALUE dst, VALUE src)
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
VALUE rb_str_freeze(VALUE str)
This is the implementation of String#freeze.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_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.
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 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.
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
pm_string_init_result_t
Represents the result of calling pm_string_mapped_init or pm_string_file_init.
@ PM_STRING_INIT_SUCCESS
Indicates that the string was successfully initialized.
@ PM_STRING_INIT_ERROR_GENERIC
Indicates a generic error from a string_*_init function, where the type of error should be read from ...
@ PM_STRING_INIT_ERROR_DIRECTORY
Indicates that the file that was attempted to be opened was a directory.
#define PM_ENCODING_US_ASCII_ENTRY
This is the US-ASCII encoding.
#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.
#define RTEST
This is an old name of RB_TEST.
struct pm_node * old_name
AliasGlobalVariableNode::old_name.
struct pm_node * new_name
AliasGlobalVariableNode::new_name.
struct pm_node * old_name
AliasMethodNode::old_name.
struct pm_node * new_name
AliasMethodNode::new_name.
struct pm_node * left
AlternationPatternNode::left.
struct pm_node * right
AlternationPatternNode::right.
struct pm_node * left
AndNode::left.
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.
struct pm_node * rest
ArrayPatternNode::rest.
struct pm_node * constant
ArrayPatternNode::constant.
struct pm_node_list posts
ArrayPatternNode::posts.
struct pm_node * value
AssocNode::value.
struct pm_node * key
AssocNode::key.
struct pm_node * value
AssocSplatNode::value.
struct pm_ensure_node * ensure_clause
BeginNode::ensure_clause.
struct pm_rescue_node * rescue_clause
BeginNode::rescue_clause.
struct pm_statements_node * statements
BeginNode::statements.
struct pm_else_node * else_clause
BeginNode::else_clause.
struct pm_node * expression
BlockArgumentNode::expression.
struct pm_node * parameters
BlockNode::parameters.
struct pm_node * body
BlockNode::body.
pm_constant_id_list_t locals
BlockNode::locals.
struct pm_arguments_node * arguments
BreakNode::arguments.
A pm_buffer_t is a simple memory buffer that stores data in a contiguous block of memory.
struct pm_node * value
CallAndWriteNode::value.
pm_constant_id_t read_name
CallAndWriteNode::read_name.
pm_constant_id_t write_name
CallAndWriteNode::write_name.
struct pm_node * receiver
CallAndWriteNode::receiver.
pm_location_t closing_loc
CallNode::closing_loc.
struct pm_node * receiver
CallNode::receiver.
pm_constant_id_t name
CallNode::name.
pm_node_t base
The embedded base node.
pm_location_t message_loc
CallNode::message_loc.
struct pm_arguments_node * arguments
CallNode::arguments.
struct pm_node * block
CallNode::block.
pm_constant_id_t read_name
CallOperatorWriteNode::read_name.
pm_constant_id_t binary_operator
CallOperatorWriteNode::binary_operator.
struct pm_node * receiver
CallOperatorWriteNode::receiver.
pm_constant_id_t write_name
CallOperatorWriteNode::write_name.
struct pm_node * value
CallOperatorWriteNode::value.
struct pm_node * receiver
CallOrWriteNode::receiver.
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.
struct pm_node * receiver
CallTargetNode::receiver.
struct pm_local_variable_target_node * target
CapturePatternNode::target.
struct pm_node * value
CapturePatternNode::value.
struct pm_node_list conditions
CaseMatchNode::conditions.
struct pm_else_node * else_clause
CaseMatchNode::else_clause.
struct pm_node * predicate
CaseMatchNode::predicate.
struct pm_node * predicate
CaseNode::predicate.
struct pm_else_node * else_clause
CaseNode::else_clause.
struct pm_node_list conditions
CaseNode::conditions.
struct pm_node * constant_path
ClassNode::constant_path.
pm_constant_id_list_t locals
ClassNode::locals.
pm_constant_id_t name
ClassNode::name.
struct pm_node * body
ClassNode::body.
struct pm_node * superclass
ClassNode::superclass.
ClassVariableAndWriteNode.
struct pm_node * value
ClassVariableAndWriteNode::value.
pm_constant_id_t name
ClassVariableAndWriteNode::name.
ClassVariableOperatorWriteNode.
pm_constant_id_t name
ClassVariableOperatorWriteNode::name.
pm_constant_id_t binary_operator
ClassVariableOperatorWriteNode::binary_operator.
struct pm_node * value
ClassVariableOperatorWriteNode::value.
ClassVariableOrWriteNode.
pm_constant_id_t name
ClassVariableOrWriteNode::name.
struct pm_node * value
ClassVariableOrWriteNode::value.
pm_constant_id_t name
ClassVariableReadNode::name.
pm_constant_id_t name
ClassVariableTargetNode::name.
struct pm_node * value
ClassVariableWriteNode::value.
pm_constant_id_t name
ClassVariableWriteNode::name.
pm_location_t name_loc
ConstantAndWriteNode::name_loc.
pm_constant_id_t name
ConstantAndWriteNode::name.
struct pm_node * value
ConstantAndWriteNode::value.
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.
struct pm_node * value
ConstantOperatorWriteNode::value.
pm_location_t name_loc
ConstantOrWriteNode::name_loc.
pm_constant_id_t name
ConstantOrWriteNode::name.
struct pm_node * value
ConstantOrWriteNode::value.
ConstantPathAndWriteNode.
struct pm_constant_path_node * target
ConstantPathAndWriteNode::target.
struct pm_node * value
ConstantPathAndWriteNode::value.
pm_constant_id_t name
ConstantPathNode::name.
struct pm_node * parent
ConstantPathNode::parent.
ConstantPathOperatorWriteNode.
struct pm_constant_path_node * target
ConstantPathOperatorWriteNode::target.
struct pm_node * value
ConstantPathOperatorWriteNode::value.
pm_constant_id_t binary_operator
ConstantPathOperatorWriteNode::binary_operator.
struct pm_node * value
ConstantPathOrWriteNode::value.
struct pm_constant_path_node * target
ConstantPathOrWriteNode::target.
struct pm_node * parent
ConstantPathTargetNode::parent.
pm_constant_id_t name
ConstantPathTargetNode::name.
struct pm_constant_path_node * target
ConstantPathWriteNode::target.
struct pm_node * value
ConstantPathWriteNode::value.
uint32_t size
The number of buckets in the hash map.
pm_constant_t * constants
The constants that are stored in the buckets.
pm_node_t base
The embedded base node.
pm_constant_id_t name
ConstantReadNode::name.
A constant in the pool which effectively stores a string.
size_t length
The length of the string.
const uint8_t * start
A pointer to the start of the string.
pm_constant_id_t name
ConstantTargetNode::name.
struct pm_node * value
ConstantWriteNode::value.
pm_constant_id_t name
ConstantWriteNode::name.
struct pm_parameters_node * parameters
DefNode::parameters.
pm_constant_id_t name
DefNode::name.
struct pm_node * body
DefNode::body.
struct pm_node * receiver
DefNode::receiver.
pm_node_t base
The embedded base node.
pm_constant_id_list_t locals
DefNode::locals.
struct pm_node * value
DefinedNode::value.
This struct represents a diagnostic generated during parsing.
pm_location_t location
The location of the diagnostic in the source.
const char * message
The message associated with the diagnostic.
pm_list_node_t node
The embedded base node.
uint8_t level
The level of the diagnostic, see pm_error_level_t and pm_warning_level_t for possible values.
struct pm_statements_node * statements
ElseNode::statements.
struct pm_statements_node * statements
EmbeddedStatementsNode::statements.
struct pm_node * variable
EmbeddedVariableNode::variable.
This struct defines the functions necessary to implement the encoding interface so we can determine h...
size_t(* char_width)(const uint8_t *b, ptrdiff_t n)
Return the number of bytes that the next character takes if it is valid in the encoding.
const char * name
The name of the encoding.
struct pm_statements_node * statements
EnsureNode::statements.
struct pm_node * constant
FindPatternNode::constant.
struct pm_node * right
FindPatternNode::right.
struct pm_node_list requireds
FindPatternNode::requireds.
struct pm_splat_node * left
FindPatternNode::left.
pm_node_t base
The embedded base node.
struct pm_node * left
FlipFlopNode::left.
struct pm_node * right
FlipFlopNode::right.
double value
FloatNode::value.
struct pm_statements_node * statements
ForNode::statements.
struct pm_node * collection
ForNode::collection.
struct pm_block_node * block
ForwardingSuperNode::block.
GlobalVariableAndWriteNode.
struct pm_node * value
GlobalVariableAndWriteNode::value.
pm_constant_id_t name
GlobalVariableAndWriteNode::name.
GlobalVariableOperatorWriteNode.
pm_constant_id_t name
GlobalVariableOperatorWriteNode::name.
pm_constant_id_t binary_operator
GlobalVariableOperatorWriteNode::binary_operator.
struct pm_node * value
GlobalVariableOperatorWriteNode::value.
GlobalVariableOrWriteNode.
pm_constant_id_t name
GlobalVariableOrWriteNode::name.
struct pm_node * value
GlobalVariableOrWriteNode::value.
pm_constant_id_t name
GlobalVariableReadNode::name.
GlobalVariableTargetNode.
pm_constant_id_t name
GlobalVariableTargetNode::name.
struct pm_node * value
GlobalVariableWriteNode::value.
pm_constant_id_t name
GlobalVariableWriteNode::name.
struct pm_node_list elements
HashNode::elements.
struct pm_node_list elements
HashPatternNode::elements.
struct pm_node * rest
HashPatternNode::rest.
struct pm_node * constant
HashPatternNode::constant.
struct pm_node * predicate
IfNode::predicate.
struct pm_statements_node * statements
IfNode::statements.
struct pm_node * numeric
ImaginaryNode::numeric.
struct pm_node * value
ImplicitNode::value.
struct pm_statements_node * statements
InNode::statements.
struct pm_node * pattern
InNode::pattern.
struct pm_arguments_node * arguments
IndexAndWriteNode::arguments.
struct pm_node * receiver
IndexAndWriteNode::receiver.
struct pm_block_argument_node * block
IndexAndWriteNode::block.
struct pm_node * value
IndexAndWriteNode::value.
struct pm_block_argument_node * block
IndexOperatorWriteNode::block.
struct pm_node * value
IndexOperatorWriteNode::value.
struct pm_arguments_node * arguments
IndexOperatorWriteNode::arguments.
pm_constant_id_t binary_operator
IndexOperatorWriteNode::binary_operator.
struct pm_node * receiver
IndexOperatorWriteNode::receiver.
struct pm_block_argument_node * block
IndexOrWriteNode::block.
struct pm_node * receiver
IndexOrWriteNode::receiver.
struct pm_node * value
IndexOrWriteNode::value.
struct pm_arguments_node * arguments
IndexOrWriteNode::arguments.
struct pm_node * receiver
IndexTargetNode::receiver.
struct pm_arguments_node * arguments
IndexTargetNode::arguments.
struct pm_block_argument_node * block
IndexTargetNode::block.
InstanceVariableAndWriteNode.
struct pm_node * value
InstanceVariableAndWriteNode::value.
pm_constant_id_t name
InstanceVariableAndWriteNode::name.
InstanceVariableOperatorWriteNode.
struct pm_node * value
InstanceVariableOperatorWriteNode::value.
pm_constant_id_t binary_operator
InstanceVariableOperatorWriteNode::binary_operator.
pm_constant_id_t name
InstanceVariableOperatorWriteNode::name.
InstanceVariableOrWriteNode.
struct pm_node * value
InstanceVariableOrWriteNode::value.
pm_constant_id_t name
InstanceVariableOrWriteNode::name.
InstanceVariableReadNode.
pm_constant_id_t name
InstanceVariableReadNode::name.
InstanceVariableTargetNode.
pm_constant_id_t name
InstanceVariableTargetNode::name.
InstanceVariableWriteNode.
pm_constant_id_t name
InstanceVariableWriteNode::name.
struct pm_node * value
InstanceVariableWriteNode::value.
pm_integer_t value
IntegerNode::value.
A structure represents an arbitrary-sized integer.
size_t length
The number of allocated values.
uint32_t value
Embedded value for small integer.
uint32_t * values
List of 32-bit integers.
bool negative
Whether or not the integer is negative.
InterpolatedMatchLastLineNode.
InterpolatedRegularExpressionNode.
struct pm_node_list 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.
struct pm_node * body
LambdaNode::body.
pm_location_t opening_loc
LambdaNode::opening_loc.
struct pm_node * parameters
LambdaNode::parameters.
pm_location_t operator_loc
LambdaNode::operator_loc.
pm_constant_id_list_t locals
LambdaNode::locals.
A line and column in a string.
uint32_t column
The column number.
int32_t line
The line number.
This struct represents an abstract linked list that provides common functionality.
struct pm_list_node * next
A pointer to the next node in the list.
This represents the overall linked list.
pm_list_node_t * head
A pointer to the head of the list.
size_t size
The size of the list.
the getlocal and setlocal instructions require two parameters.
LocalVariableAndWriteNode.
pm_constant_id_t name
LocalVariableAndWriteNode::name.
uint32_t depth
LocalVariableAndWriteNode::depth.
struct pm_node * value
LocalVariableAndWriteNode::value.
LocalVariableOperatorWriteNode.
uint32_t depth
LocalVariableOperatorWriteNode::depth.
pm_constant_id_t binary_operator
LocalVariableOperatorWriteNode::binary_operator.
struct pm_node * value
LocalVariableOperatorWriteNode::value.
pm_constant_id_t name
LocalVariableOperatorWriteNode::name.
LocalVariableOrWriteNode.
uint32_t depth
LocalVariableOrWriteNode::depth.
struct pm_node * value
LocalVariableOrWriteNode::value.
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.
struct pm_node * value
LocalVariableWriteNode::value.
uint32_t depth
LocalVariableWriteNode::depth.
pm_constant_id_t name
LocalVariableWriteNode::name.
This represents a range of bytes in the source string to which a node or token corresponds.
const uint8_t * start
A pointer to the start location of the range in the source.
const uint8_t * end
A pointer to the end location of the range in the source.
struct pm_node * pattern
MatchPredicateNode::pattern.
struct pm_node * value
MatchPredicateNode::value.
struct pm_node * value
MatchRequiredNode::value.
struct pm_node * pattern
MatchRequiredNode::pattern.
struct pm_node_list targets
MatchWriteNode::targets.
struct pm_call_node * call
MatchWriteNode::call.
struct pm_node * constant_path
ModuleNode::constant_path.
struct pm_node * body
ModuleNode::body.
pm_constant_id_list_t locals
ModuleNode::locals.
pm_constant_id_t name
ModuleNode::name.
struct pm_node_list lefts
MultiTargetNode::lefts.
struct pm_node * rest
MultiTargetNode::rest.
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...
struct pm_node * value
MultiWriteNode::value.
struct pm_node * rest
MultiWriteNode::rest.
struct pm_node_list rights
MultiWriteNode::rights.
struct pm_node_list lefts
MultiWriteNode::lefts.
A list of offsets of newlines in a string.
const uint8_t * start
A pointer to the start of the source string.
size_t * offsets
The list of offsets.
size_t size
The number of offsets in the list.
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.
OptionalKeywordParameterNode.
pm_constant_id_t name
OptionalKeywordParameterNode::name.
struct pm_node * value
OptionalKeywordParameterNode::value.
struct pm_node * value
OptionalParameterNode::value.
pm_constant_id_t name
OptionalParameterNode::name.
The options that can be passed to the parser.
struct pm_node * left
OrNode::left.
struct pm_node * right
OrNode::right.
struct pm_node * rest
ParametersNode::rest.
struct pm_node_list requireds
ParametersNode::requireds.
struct pm_block_parameter_node * block
ParametersNode::block.
struct pm_node_list optionals
ParametersNode::optionals.
struct pm_node_list posts
ParametersNode::posts.
pm_node_t base
The embedded base node.
struct pm_node * keyword_rest
ParametersNode::keyword_rest.
struct pm_node_list keywords
ParametersNode::keywords.
struct pm_node * body
ParenthesesNode::body.
An error that is going to be formatted into the output.
pm_diagnostic_t * error
A pointer to the diagnostic that was generated during parsing.
uint32_t column_end
The column end of the diagnostic message.
int32_t line
The start line of the diagnostic message.
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_scope_node_t node
The resulting scope node that will hold the generated AST.
pm_string_t input
The input that represents the source to be parsed.
pm_parser_t parser
The parser that will do the actual parsing.
pm_options_t options
The options that will be passed to the parser.
This struct represents the overall parser.
const pm_encoding_t * encoding
The encoding functions for the current file is attached to the parser as it's parsing so that it can ...
const uint8_t * end
The pointer to the end of the source.
pm_constant_pool_t constant_pool
This constant pool keeps all of the constants defined throughout the file so that we can reference th...
const uint8_t * start
The pointer to the start of the source.
pm_list_t error_list
The list of errors that have been found while parsing.
pm_list_t warning_list
The list of warnings that have been found while parsing.
int32_t start_line
The line number at the start of the parse.
pm_string_t filepath
This is the path of the file being parsed.
pm_newline_list_t newline_list
This is the list of newline offsets in the source file.
struct pm_node * variable
PinnedVariableNode::variable.
struct pm_statements_node * statements
PostExecutionNode::statements.
struct pm_statements_node * statements
PreExecutionNode::statements.
struct pm_statements_node * statements
ProgramNode::statements.
struct pm_node * right
RangeNode::right.
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.
struct pm_node * rescue_expression
RescueModifierNode::rescue_expression.
struct pm_node * expression
RescueModifierNode::expression.
struct pm_rescue_node * subsequent
RescueNode::subsequent.
struct pm_node * reference
RescueNode::reference.
struct pm_node_list exceptions
RescueNode::exceptions.
struct pm_statements_node * statements
RescueNode::statements.
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 ...
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...
struct pm_node * write
ShareableConstantNode::write.
pm_node_t base
The embedded base node.
pm_constant_id_list_t locals
SingletonClassNode::locals.
struct pm_node * expression
SingletonClassNode::expression.
struct pm_node * body
SingletonClassNode::body.
pm_string_t filepath
SourceFileNode::filepath.
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.
struct pm_arguments_node * arguments
SuperNode::arguments.
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.
struct pm_statements_node * statements
UnlessNode::statements.
struct pm_node * predicate
UnlessNode::predicate.
struct pm_else_node * else_clause
UnlessNode::else_clause.
pm_node_t base
The embedded base node.
pm_node_t base
The embedded base node.
pm_string_t unescaped
XStringNode::unescaped.
struct pm_arguments_node * arguments
YieldNode::arguments.
struct rb_iseq_constant_body::@154 param
parameter information
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.