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_NODE_START_LOCATION(parser, node) \
142 ((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 })
144#define PM_NODE_END_LOCATION(parser, node) \
145 ((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 })
147#define PM_LOCATION_START_LOCATION(parser, location, id) \
148 ((pm_node_location_t) { .line = pm_newline_list_line(&(parser)->newline_list, (location)->start, (parser)->start_line), .node_id = id })
150#define PM_NODE_START_LINE_COLUMN(parser, node) \
151 pm_newline_list_line_column(&(parser)->newline_list, ((const pm_node_t *) (node))->location.start, (parser)->start_line)
153#define PM_NODE_END_LINE_COLUMN(parser, node) \
154 pm_newline_list_line_column(&(parser)->newline_list, ((const pm_node_t *) (node))->location.end, (parser)->start_line)
156#define PM_LOCATION_START_LINE_COLUMN(parser, location) \
157 pm_newline_list_line_column(&(parser)->newline_list, (location)->start, (parser)->start_line)
178 if (integer->
values == NULL) {
183 unsigned char *bytes = (
unsigned char *) RSTRING_PTR(
string);
185 size_t offset = integer->
length * 8;
186 for (
size_t value_index = 0; value_index < integer->
length; value_index++) {
187 uint32_t value = integer->
values[value_index];
189 for (
int index = 0; index < 8; index++) {
190 int byte = (value >> (4 * index)) & 0xf;
191 bytes[--offset] =
byte < 10 ?
byte +
'0' :
byte - 10 +
'a';
199 result =
rb_funcall(result, rb_intern(
"-@"), 0);
211 return parse_integer_value(&node->
value);
246 VALUE imaginary_part;
261 rb_bug(
"Unexpected numeric type on imaginary number %s\n", pm_node_type_to_str(
PM_NODE_TYPE(node->
numeric)));
264 return rb_complex_raw(
INT2FIX(0), imaginary_part);
268parse_string(
const pm_scope_node_t *scope_node,
const pm_string_t *
string)
270 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), scope_node->encoding);
281 rb_encoding *encoding;
284 encoding = rb_ascii8bit_encoding();
287 encoding = rb_utf8_encoding();
293 return rb_enc_str_new((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
297parse_static_literal_string(rb_iseq_t *iseq,
const pm_scope_node_t *scope_node,
const pm_node_t *node,
const pm_string_t *
string)
299 rb_encoding *encoding;
302 encoding = rb_ascii8bit_encoding();
305 encoding = rb_utf8_encoding();
308 encoding = scope_node->encoding;
311 VALUE value = rb_enc_literal_str((
const char *) pm_string_source(
string), pm_string_length(
string), encoding);
314 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
315 int line_number = pm_node_line_number(scope_node->parser, node);
316 value = rb_str_with_debug_created_info(value, rb_iseq_path(iseq), line_number);
323parse_string_symbol(
const pm_scope_node_t *scope_node,
const pm_symbol_node_t *symbol)
325 rb_encoding *encoding;
327 encoding = rb_utf8_encoding();
330 encoding = rb_ascii8bit_encoding();
333 encoding = rb_usascii_encoding();
336 encoding = scope_node->encoding;
339 return rb_intern3((
const char *) pm_string_source(&symbol->
unescaped), pm_string_length(&symbol->
unescaped), encoding);
343pm_optimizable_range_item_p(
const pm_node_t *node)
350parse_regexp_error(rb_iseq_t *iseq, int32_t line_number,
const char *fmt, ...)
354 VALUE error = rb_syntax_error_append(
Qnil, rb_iseq_path(iseq), line_number, -1, NULL,
"%" PRIsVALUE, args);
360parse_regexp_string_part(rb_iseq_t *iseq,
const pm_scope_node_t *scope_node,
const pm_node_t *node,
const pm_string_t *unescaped, rb_encoding *implicit_regexp_encoding, rb_encoding *explicit_regexp_encoding)
364 rb_encoding *encoding;
366 if (explicit_regexp_encoding != NULL) {
367 encoding = explicit_regexp_encoding;
370 encoding = rb_ascii8bit_encoding();
373 encoding = rb_utf8_encoding();
376 encoding = implicit_regexp_encoding;
379 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), encoding);
380 VALUE error = rb_reg_check_preprocess(
string);
382 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number(scope_node->parser, node),
"%" PRIsVALUE, rb_obj_as_string(error));
387pm_static_literal_concat(rb_iseq_t *iseq,
const pm_node_list_t *nodes,
const pm_scope_node_t *scope_node, rb_encoding *implicit_regexp_encoding, rb_encoding *explicit_regexp_encoding,
bool top)
391 for (
size_t index = 0; index < nodes->
size; index++) {
397 if (implicit_regexp_encoding != NULL) {
399 string = parse_regexp_string_part(iseq, scope_node, part, &((
const pm_string_node_t *) part)->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
402 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
403 VALUE error = rb_reg_check_preprocess(
string);
404 if (error !=
Qnil) parse_regexp_error(iseq, pm_node_line_number(scope_node->parser, part),
"%" PRIsVALUE, rb_obj_as_string(error));
408 string = parse_string_encoded(part, &((
const pm_string_node_t *) part)->unescaped, scope_node->encoding);
412 string = pm_static_literal_concat(iseq, &((
const pm_interpolated_string_node_t *) part)->parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
416 string = pm_static_literal_concat(iseq, &cast->
statements->
body, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
420 RUBY_ASSERT(
false &&
"unexpected node type in pm_static_literal_concat");
424 if (current !=
Qnil) {
432 return top ? rb_fstring(current) : current;
435#define RE_OPTION_ENCODING_SHIFT 8
436#define RE_OPTION_ENCODING(encoding) (((encoding) & 0xFF) << RE_OPTION_ENCODING_SHIFT)
437#define ARG_ENCODING_NONE 32
438#define ARG_ENCODING_FIXED 16
439#define ENC_ASCII8BIT 1
441#define ENC_Windows_31J 3
457 flags |= ARG_ENCODING_NONE;
461 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_EUC_JP));
465 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_Windows_31J));
469 flags |= (ARG_ENCODING_FIXED | RE_OPTION_ENCODING(ENC_UTF8));
473 flags |= ONIG_OPTION_IGNORECASE;
477 flags |= ONIG_OPTION_MULTILINE;
481 flags |= ONIG_OPTION_EXTEND;
487#undef RE_OPTION_ENCODING_SHIFT
488#undef RE_OPTION_ENCODING
489#undef ARG_ENCODING_FIXED
490#undef ARG_ENCODING_NONE
493#undef ENC_Windows_31J
497parse_regexp_encoding(
const pm_scope_node_t *scope_node,
const pm_node_t *node)
500 return rb_ascii8bit_encoding();
503 return rb_utf8_encoding();
506 return rb_enc_get_from_index(ENCINDEX_EUC_JP);
509 return rb_enc_get_from_index(ENCINDEX_Windows_31J);
517parse_regexp(rb_iseq_t *iseq,
const pm_scope_node_t *scope_node,
const pm_node_t *node,
VALUE string)
519 VALUE errinfo = rb_errinfo();
521 int32_t line_number = pm_node_line_number(scope_node->parser, node);
522 VALUE regexp = rb_reg_compile(
string, parse_regexp_flags(node), (
const char *) pm_string_source(&scope_node->parser->
filepath), line_number);
525 VALUE message = rb_attr_get(rb_errinfo(), idMesg);
526 rb_set_errinfo(errinfo);
528 parse_regexp_error(iseq, line_number,
"%" PRIsVALUE, message);
537parse_regexp_literal(rb_iseq_t *iseq,
const pm_scope_node_t *scope_node,
const pm_node_t *node,
const pm_string_t *unescaped)
539 rb_encoding *regexp_encoding = parse_regexp_encoding(scope_node, node);
540 if (regexp_encoding == NULL) regexp_encoding = scope_node->encoding;
542 VALUE string = rb_enc_str_new((
const char *) pm_string_source(unescaped), pm_string_length(unescaped), regexp_encoding);
543 return parse_regexp(iseq, scope_node, node,
string);
547parse_regexp_concat(rb_iseq_t *iseq,
const pm_scope_node_t *scope_node,
const pm_node_t *node,
const pm_node_list_t *parts)
549 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
550 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
552 VALUE string = pm_static_literal_concat(iseq, parts, scope_node, implicit_regexp_encoding, explicit_regexp_encoding,
false);
553 return parse_regexp(iseq, scope_node, node,
string);
556static void pm_compile_node(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node);
559pm_interpolated_node_compile(rb_iseq_t *iseq,
const pm_node_list_t *parts,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node, rb_encoding *implicit_regexp_encoding, rb_encoding *explicit_regexp_encoding)
562 size_t parts_size = parts->
size;
563 bool interpolated =
false;
565 if (parts_size > 0) {
569 for (
size_t index = 0; index < parts_size; index++) {
576 if (implicit_regexp_encoding == NULL) {
577 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
580 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
583 if (
RTEST(current_string)) {
584 current_string =
rb_str_concat(current_string, string_value);
587 current_string = string_value;
588 if (index != 0) current_location = PM_NODE_END_LOCATION(scope_node->parser, part);
603 if (implicit_regexp_encoding == NULL) {
604 string_value = parse_string_encoded(part, &string_node->
unescaped, scope_node->encoding);
607 string_value = parse_regexp_string_part(iseq, scope_node, (
const pm_node_t *) string_node, &string_node->unescaped, implicit_regexp_encoding, explicit_regexp_encoding);
610 if (
RTEST(current_string)) {
611 current_string =
rb_str_concat(current_string, string_value);
614 current_string = string_value;
615 current_location = PM_NODE_START_LOCATION(scope_node->parser, part);
619 if (!
RTEST(current_string)) {
620 rb_encoding *encoding;
622 if (implicit_regexp_encoding != NULL) {
623 if (explicit_regexp_encoding != NULL) {
624 encoding = explicit_regexp_encoding;
627 encoding = rb_ascii8bit_encoding();
630 encoding = implicit_regexp_encoding;
634 encoding = scope_node->encoding;
637 if (parts_size == 1) {
638 current_string = rb_enc_str_new(NULL, 0, encoding);
642 if (
RTEST(current_string)) {
643 VALUE operand = rb_fstring(current_string);
644 PUSH_INSN1(ret, current_location, putobject, operand);
648 PM_COMPILE_NOT_POPPED(part);
650 const pm_node_location_t current_location = PM_NODE_START_LOCATION(scope_node->parser, part);
651 PUSH_INSN(ret, current_location, dup);
654 const struct rb_callinfo *callinfo = new_callinfo(iseq, idTo_s, 0, VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE, NULL, FALSE);
655 PUSH_INSN1(ret, current_location, objtostring, callinfo);
658 PUSH_INSN(ret, current_location, anytostring);
660 current_string =
Qnil;
666 if (
RTEST(current_string)) {
667 current_string = rb_fstring(current_string);
669 if (stack_size == 0 && interpolated) {
670 PUSH_INSN1(ret, current_location, putstring, current_string);
673 PUSH_INSN1(ret, current_location, putobject, current_string);
676 current_string =
Qnil;
681 PUSH_INSN(ret, *node_location, putnil);
690 rb_encoding *explicit_regexp_encoding = parse_regexp_encoding(scope_node, node);
691 rb_encoding *implicit_regexp_encoding = explicit_regexp_encoding != NULL ? explicit_regexp_encoding : scope_node->encoding;
693 int length = pm_interpolated_node_compile(iseq, parts, node_location, ret, popped, scope_node, implicit_regexp_encoding, explicit_regexp_encoding);
694 PUSH_INSN2(ret, *node_location, toregexp,
INT2FIX(parse_regexp_flags(node) & 0xFF),
INT2FIX(length));
701 size_t length = pm_string_length(filepath);
705 return rb_enc_interned_str((
const char *) pm_string_source(filepath), length, filepath_encoding);
708 return rb_fstring_lit(
"<compiled>");
717pm_static_literal_string(rb_iseq_t *iseq,
VALUE string,
int line_number)
719 if (ISEQ_COMPILE_DATA(iseq)->option->debug_frozen_string_literal ||
RTEST(
ruby_debug)) {
720 return rb_str_with_debug_created_info(
string, rb_iseq_path(iseq), line_number);
723 return rb_fstring(
string);
733pm_static_literal_value(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_scope_node_t *scope_node)
744 VALUE value = rb_ary_hidden_new(elements->
size);
745 for (
size_t index = 0; index < elements->
size; index++) {
746 rb_ary_push(value, pm_static_literal_value(iseq, elements->
nodes[index], scope_node));
760 VALUE array = rb_ary_hidden_new(elements->
size * 2);
761 for (
size_t index = 0; index < elements->
size; index++) {
764 VALUE pair[2] = { pm_static_literal_value(iseq, cast->key, scope_node), pm_static_literal_value(iseq, cast->value, scope_node) };
765 rb_ary_cat(array, pair, 2);
768 VALUE value = rb_hash_new_with_size(elements->
size);
781 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
785 return parse_regexp_concat(iseq, scope_node, (
const pm_node_t *) cast, &cast->parts);
789 int line_number = pm_node_line_number(scope_node->parser, node);
790 return pm_static_literal_string(iseq,
string, line_number);
794 VALUE string = pm_static_literal_concat(iseq, &cast->
parts, scope_node, NULL, NULL,
true);
796 return ID2SYM(rb_intern_str(
string));
800 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
808 return parse_regexp_literal(iseq, scope_node, (
const pm_node_t *) cast, &cast->unescaped);
811 return rb_enc_from_encoding(scope_node->encoding);
814 return pm_source_file_value(cast, scope_node);
817 return INT2FIX(pm_node_line_number(scope_node->parser, node));
820 return parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
827 rb_bug(
"Don't have a literal value for node type %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
835static rb_code_location_t
836pm_code_location(
const pm_scope_node_t *scope_node,
const pm_node_t *node)
838 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(scope_node->parser, node);
839 const pm_line_column_t end_location = PM_NODE_END_LINE_COLUMN(scope_node->parser, node);
841 return (rb_code_location_t) {
842 .beg_pos = { .lineno = start_location.
line, .column = start_location.
column },
843 .end_pos = { .lineno = end_location.
line, .column = end_location.
column }
852#define PM_BRANCH_COVERAGE_P(iseq) (ISEQ_COVERAGE(iseq) && ISEQ_BRANCH_COVERAGE(iseq))
855pm_compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *
const ret,
const pm_node_t *cond,
856 LABEL *then_label, LABEL *else_label,
bool popped, pm_scope_node_t *scope_node);
859pm_compile_logical(rb_iseq_t *iseq, LINK_ANCHOR *
const ret,
pm_node_t *cond, LABEL *then_label, LABEL *else_label,
bool popped, pm_scope_node_t *scope_node)
865 LABEL *label = NEW_LABEL(location.
line);
866 if (!then_label) then_label = label;
867 else if (!else_label) else_label = label;
869 pm_compile_branch_condition(iseq, seq, cond, then_label, else_label, popped, scope_node);
871 if (LIST_INSN_SIZE_ONE(seq)) {
872 INSN *insn = (INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(seq));
873 if (insn->insn_id == BIN(jump) && (LABEL *)(insn->operands[0]) == label)
return;
876 if (!label->refcnt) {
877 if (popped) PUSH_INSN(ret, location, putnil);
880 PUSH_LABEL(seq, label);
888pm_compile_flip_flop_bound(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
890 const pm_node_location_t location = { .line = ISEQ_BODY(iseq)->location.first_lineno, .node_id = -1 };
893 PM_COMPILE_NOT_POPPED(node);
896 PUSH_INSN1(ret, location, getglobal, operand);
898 PUSH_SEND(ret, location, idEq,
INT2FIX(1));
899 if (popped) PUSH_INSN(ret, location, pop);
907pm_compile_flip_flop(
const pm_flip_flop_node_t *flip_flop_node, LABEL *else_label, LABEL *then_label, rb_iseq_t *iseq,
const int lineno, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
909 const pm_node_location_t location = { .line = ISEQ_BODY(iseq)->location.first_lineno, .node_id = -1 };
910 LABEL *lend = NEW_LABEL(location.
line);
914 rb_num_t count = ISEQ_FLIP_CNT_INCREMENT(ISEQ_BODY(iseq)->local_iseq) + VM_SVAR_FLIPFLOP_START;
917 PUSH_INSN2(ret, location, getspecial, key,
INT2FIX(0));
918 PUSH_INSNL(ret, location, branchif, lend);
920 if (flip_flop_node->
left) {
921 pm_compile_flip_flop_bound(iseq, flip_flop_node->
left, ret, popped, scope_node);
924 PUSH_INSN(ret, location, putnil);
927 PUSH_INSNL(ret, location, branchunless, else_label);
928 PUSH_INSN1(ret, location, putobject,
Qtrue);
929 PUSH_INSN1(ret, location, setspecial, key);
931 PUSH_INSNL(ret, location, jump, then_label);
934 PUSH_LABEL(ret, lend);
935 if (flip_flop_node->
right) {
936 pm_compile_flip_flop_bound(iseq, flip_flop_node->
right, ret, popped, scope_node);
939 PUSH_INSN(ret, location, putnil);
942 PUSH_INSNL(ret, location, branchunless, then_label);
943 PUSH_INSN1(ret, location, putobject,
Qfalse);
944 PUSH_INSN1(ret, location, setspecial, key);
945 PUSH_INSNL(ret, location, jump, then_label);
948static void pm_compile_defined_expr(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node,
bool in_condition);
951pm_compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *
const ret,
const pm_node_t *cond, LABEL *then_label, LABEL *else_label,
bool popped, pm_scope_node_t *scope_node)
959 pm_compile_logical(iseq, ret, cast->
left, NULL, else_label, popped, scope_node);
966 pm_compile_logical(iseq, ret, cast->
left, then_label, NULL, popped, scope_node);
973 PUSH_INSNL(ret, location, jump, else_label);
984 PUSH_INSNL(ret, location, jump, then_label);
987 pm_compile_flip_flop((
const pm_flip_flop_node_t *) cond, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
991 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
true);
995 DECL_ANCHOR(cond_seq);
996 pm_compile_node(iseq, cond, cond_seq,
false, scope_node);
998 if (LIST_INSN_SIZE_ONE(cond_seq)) {
999 INSN *insn = (INSN *) ELEM_FIRST_INSN(FIRST_ELEMENT(cond_seq));
1001 if (insn->insn_id == BIN(putobject)) {
1002 if (
RTEST(insn->operands[0])) {
1003 PUSH_INSNL(ret, location, jump, then_label);
1008 PUSH_INSNL(ret, location, jump, else_label);
1014 PUSH_SEQ(ret, cond_seq);
1019 PUSH_INSNL(ret, location, branchunless, else_label);
1020 PUSH_INSNL(ret, location, jump, then_label);
1030 LABEL *then_label = NEW_LABEL(location.
line);
1031 LABEL *else_label = NEW_LABEL(location.
line);
1032 LABEL *end_label = NULL;
1034 DECL_ANCHOR(cond_seq);
1035 pm_compile_branch_condition(iseq, cond_seq, predicate, then_label, else_label,
false, scope_node);
1036 PUSH_SEQ(ret, cond_seq);
1038 rb_code_location_t conditional_location = { 0 };
1041 if (then_label->refcnt && else_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1042 conditional_location = pm_code_location(scope_node, node);
1043 branches = decl_branch_base(iseq, PTR2NUM(node), &conditional_location,
type ==
PM_IF_NODE ?
"if" :
"unless");
1046 if (then_label->refcnt) {
1047 PUSH_LABEL(ret, then_label);
1049 DECL_ANCHOR(then_seq);
1051 if (statements != NULL) {
1052 pm_compile_node(iseq, (
const pm_node_t *) statements, then_seq, popped, scope_node);
1055 PUSH_SYNTHETIC_PUTNIL(then_seq, iseq);
1058 if (else_label->refcnt) {
1060 if (PM_BRANCH_COVERAGE_P(iseq)) {
1061 rb_code_location_t branch_location;
1063 if (statements != NULL) {
1064 branch_location = pm_code_location(scope_node, (
const pm_node_t *) statements);
1066 pm_line_column_t predicate_end = PM_NODE_END_LINE_COLUMN(scope_node->parser, predicate);
1067 branch_location = (rb_code_location_t) {
1068 .beg_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column },
1069 .end_pos = { .lineno = predicate_end.
line, .column = predicate_end.
column }
1072 branch_location = conditional_location;
1075 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
type ==
PM_IF_NODE ?
"then" :
"else", branches);
1078 end_label = NEW_LABEL(location.
line);
1079 PUSH_INSNL(then_seq, location, jump, end_label);
1080 if (!popped) PUSH_INSN(then_seq, location, pop);
1083 PUSH_SEQ(ret, then_seq);
1086 if (else_label->refcnt) {
1087 PUSH_LABEL(ret, else_label);
1089 DECL_ANCHOR(else_seq);
1091 if (subsequent != NULL) {
1092 pm_compile_node(iseq, subsequent, else_seq, popped, scope_node);
1095 PUSH_SYNTHETIC_PUTNIL(else_seq, iseq);
1099 if (then_label->refcnt && PM_BRANCH_COVERAGE_P(iseq)) {
1100 rb_code_location_t branch_location;
1102 if (subsequent == NULL) {
1103 branch_location = conditional_location;
1108 branch_location = pm_code_location(scope_node, (
const pm_node_t *) subsequent);
1111 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 1,
type ==
PM_IF_NODE ?
"else" :
"then", branches);
1114 PUSH_SEQ(ret, else_seq);
1118 PUSH_LABEL(ret, end_label);
1132 LABEL *prev_start_label = ISEQ_COMPILE_DATA(iseq)->start_label;
1133 LABEL *prev_end_label = ISEQ_COMPILE_DATA(iseq)->end_label;
1134 LABEL *prev_redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label;
1136 LABEL *next_label = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(location.
line);
1137 LABEL *redo_label = ISEQ_COMPILE_DATA(iseq)->redo_label = NEW_LABEL(location.
line);
1138 LABEL *break_label = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(location.
line);
1139 LABEL *end_label = NEW_LABEL(location.
line);
1140 LABEL *adjust_label = NEW_LABEL(location.
line);
1142 LABEL *next_catch_label = NEW_LABEL(location.
line);
1143 LABEL *tmp_label = NULL;
1149 push_ensure_entry(iseq, &enl, NULL, NULL);
1153 tmp_label = NEW_LABEL(location.
line);
1154 PUSH_INSNL(ret, location, jump, tmp_label);
1158 PUSH_INSNL(ret, location, jump, next_label);
1161 PUSH_LABEL(ret, adjust_label);
1162 PUSH_INSN(ret, location, putnil);
1163 PUSH_LABEL(ret, next_catch_label);
1164 PUSH_INSN(ret, location, pop);
1165 PUSH_INSNL(ret, location, jump, next_label);
1166 if (tmp_label) PUSH_LABEL(ret, tmp_label);
1168 PUSH_LABEL(ret, redo_label);
1171 if (PM_BRANCH_COVERAGE_P(iseq)) {
1172 rb_code_location_t loop_location = pm_code_location(scope_node, node);
1173 VALUE branches = decl_branch_base(iseq, PTR2NUM(node), &loop_location,
type ==
PM_WHILE_NODE ?
"while" :
"until");
1175 rb_code_location_t branch_location = statements != NULL ? pm_code_location(scope_node, (
const pm_node_t *) statements) : loop_location;
1176 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, 0,
"body", branches);
1179 if (statements != NULL) PM_COMPILE_POPPED((
const pm_node_t *) statements);
1180 PUSH_LABEL(ret, next_label);
1183 pm_compile_branch_condition(iseq, ret, predicate, redo_label, end_label, popped, scope_node);
1186 pm_compile_branch_condition(iseq, ret, predicate, end_label, redo_label, popped, scope_node);
1189 PUSH_LABEL(ret, end_label);
1190 PUSH_ADJUST_RESTORE(ret, adjust_label);
1191 PUSH_INSN(ret, location, putnil);
1193 PUSH_LABEL(ret, break_label);
1194 if (popped) PUSH_INSN(ret, location, pop);
1196 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, redo_label, break_label, NULL, break_label);
1197 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, redo_label, break_label, NULL, next_catch_label);
1198 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, redo_label, break_label, NULL, ISEQ_COMPILE_DATA(iseq)->redo_label);
1200 ISEQ_COMPILE_DATA(iseq)->start_label = prev_start_label;
1201 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end_label;
1202 ISEQ_COMPILE_DATA(iseq)->redo_label = prev_redo_label;
1203 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->prev;
1211static pm_local_index_t
1212pm_lookup_local_index(rb_iseq_t *iseq,
const pm_scope_node_t *scope_node,
pm_constant_id_t constant_id,
int start_depth)
1214 pm_local_index_t lindex = { 0 };
1215 st_data_t local_index;
1218 for (level = 0; level < start_depth; level++) {
1219 scope_node = scope_node->previous;
1222 while (!st_lookup(scope_node->index_lookup_table, constant_id, &local_index)) {
1225 if (scope_node->previous) {
1226 scope_node = scope_node->previous;
1231 rb_bug(
"Local with constant_id %u does not exist", (
unsigned int) constant_id);
1235 lindex.level = level;
1236 lindex.index = scope_node->local_table_for_iseq_size - (int) local_index;
1247pm_constant_id_lookup(
const pm_scope_node_t *scope_node,
pm_constant_id_t constant_id)
1250 rb_bug(
"constant_id out of range: %u", (
unsigned int)constant_id);
1252 return scope_node->constants[constant_id - 1];
1256pm_new_child_iseq(rb_iseq_t *iseq, pm_scope_node_t *node,
VALUE name,
const rb_iseq_t *parent,
enum rb_iseq_type
type,
int line_no)
1258 debugs(
"[new_child_iseq]> ---------------------------------------\n");
1259 int isolated_depth = ISEQ_COMPILE_DATA(iseq)->isolated_depth;
1261 rb_iseq_t *ret_iseq = pm_iseq_new_with_opt(node, name,
1262 rb_iseq_path(iseq), rb_iseq_realpath(iseq),
1264 isolated_depth ? isolated_depth + 1 : 0,
1265 type, ISEQ_COMPILE_DATA(iseq)->option, &error_state);
1269 rb_jump_tag(error_state);
1271 debugs(
"[new_child_iseq]< ---------------------------------------\n");
1276pm_compile_class_path(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
1284 return VM_DEFINECLASS_FLAG_SCOPED;
1288 PUSH_INSN1(ret, *node_location, putobject, rb_cObject);
1289 return VM_DEFINECLASS_FLAG_SCOPED;
1294 PUSH_INSN1(ret, *node_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
1304pm_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)
1307 LABEL *lfin = NEW_LABEL(location.
line);
1308 LABEL *lcfin = NEW_LABEL(location.
line);
1309 LABEL *lskip = NULL;
1312 ID id_read_name = pm_constant_id_lookup(scope_node, read_name);
1314 PM_COMPILE_NOT_POPPED(receiver);
1316 lskip = NEW_LABEL(location.
line);
1317 PUSH_INSN(ret, location, dup);
1318 PUSH_INSNL(ret, location, branchnil, lskip);
1321 PUSH_INSN(ret, location, dup);
1322 PUSH_SEND_WITH_FLAG(ret, location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
1323 if (!popped) PUSH_INSN(ret, location, dup);
1326 PUSH_INSNL(ret, location, branchunless, lcfin);
1329 PUSH_INSNL(ret, location, branchif, lcfin);
1332 if (!popped) PUSH_INSN(ret, location, pop);
1333 PM_COMPILE_NOT_POPPED(value);
1336 PUSH_INSN(ret, location, swap);
1337 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
1340 ID id_write_name = pm_constant_id_lookup(scope_node, write_name);
1341 PUSH_SEND_WITH_FLAG(ret, location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
1342 PUSH_INSNL(ret, location, jump, lfin);
1344 PUSH_LABEL(ret, lcfin);
1345 if (!popped) PUSH_INSN(ret, location, swap);
1347 PUSH_LABEL(ret, lfin);
1349 if (lskip && popped) PUSH_LABEL(ret, lskip);
1350 PUSH_INSN(ret, location, pop);
1351 if (lskip && !popped) PUSH_LABEL(ret, lskip);
1354static void pm_compile_shareable_constant_value(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_node_flags_t shareability,
VALUE path, LINK_ANCHOR *
const ret, pm_scope_node_t *scope_node,
bool top);
1362pm_compile_hash_elements(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_node_list_t *elements,
const pm_node_flags_t shareability,
VALUE path,
bool argument, LINK_ANCHOR *
const ret, pm_scope_node_t *scope_node)
1364 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
1370 const int max_stack_length = 0x100;
1371 const unsigned int min_tmp_hash_length = 0x800;
1373 int stack_length = 0;
1374 bool first_chunk =
true;
1380 bool static_literal =
false;
1382 DECL_ANCHOR(anchor);
1385#define FLUSH_CHUNK \
1386 if (stack_length) { \
1387 if (first_chunk) { \
1388 PUSH_SEQ(ret, anchor); \
1389 PUSH_INSN1(ret, location, newhash, INT2FIX(stack_length)); \
1390 first_chunk = false; \
1393 PUSH_INSN1(ret, location, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); \
1394 PUSH_INSN(ret, location, swap); \
1395 PUSH_SEQ(ret, anchor); \
1396 PUSH_SEND(ret, location, id_core_hash_merge_ptr, INT2FIX(stack_length + 1)); \
1398 INIT_ANCHOR(anchor); \
1402 for (
size_t index = 0; index < elements->
size; index++) {
1409 (shareability == 0) &&
1411 (!static_literal && ((index + min_tmp_hash_length) < elements->
size)) ||
1412 (first_chunk && stack_length == 0)
1417 while (index + count < elements->size &&
PM_NODE_FLAG_P(elements->
nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++;
1419 if ((first_chunk && stack_length == 0) || count >= min_tmp_hash_length) {
1422 VALUE ary = rb_ary_hidden_new(count);
1425 for (
size_t tmp_end = index + count; index < tmp_end; index++) {
1429 pm_static_literal_value(iseq, assoc->key, scope_node),
1430 pm_static_literal_value(iseq, assoc->value, scope_node)
1433 rb_ary_cat(ary, elem, 2);
1445 PUSH_INSN1(ret, location, duphash, hash);
1446 first_chunk =
false;
1449 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1450 PUSH_INSN(ret, location, swap);
1451 PUSH_INSN1(ret, location, putobject, hash);
1452 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1458 static_literal =
true;
1462 static_literal =
false;
1467 if (shareability == 0) {
1468 pm_compile_node(iseq, element, anchor,
false, scope_node);
1472 pm_compile_shareable_constant_value(iseq, assoc->
key, shareability, path, ret, scope_node,
false);
1473 pm_compile_shareable_constant_value(iseq, assoc->
value, shareability, path, ret, scope_node,
false);
1476 if ((stack_length += 2) >= max_stack_length) FLUSH_CHUNK;
1483 bool empty_hash = assoc_splat->
value != NULL && (
1488 bool first_element = first_chunk && stack_length == 0;
1489 bool last_element = index == elements->
size - 1;
1490 bool only_element = first_element && last_element;
1493 if (only_element && argument) {
1500 PUSH_INSN(ret, location, putnil);
1502 else if (first_element) {
1505 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1512 if (only_element && argument) {
1518 if (shareability == 0) {
1519 PM_COMPILE_NOT_POPPED(element);
1522 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1530 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1532 if (first_element) {
1533 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1536 PUSH_INSN(ret, location, swap);
1539 if (shareability == 0) {
1540 PM_COMPILE_NOT_POPPED(element);
1543 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1546 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1550 first_chunk =
false;
1551 static_literal =
false;
1555 RUBY_ASSERT(
"Invalid node type for hash" &&
false);
1564#define SPLATARRAY_FALSE 0
1565#define SPLATARRAY_TRUE 1
1566#define DUP_SINGLE_KW_SPLAT 2
1575 bool has_splat =
false;
1576 bool has_keyword_splat =
false;
1578 if (arguments_node == NULL) {
1579 if (*flags & VM_CALL_FCALL) {
1580 *flags |= VM_CALL_VCALL;
1589 int post_splat_counter = 0;
1599 if (has_keyword_splat || has_splat) {
1600 *flags |= VM_CALL_KW_SPLAT;
1601 has_keyword_splat =
true;
1607 *flags |= VM_CALL_KW_SPLAT_MUT;
1608 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1610 else if (*dup_rest & DUP_SINGLE_KW_SPLAT) {
1611 *flags |= VM_CALL_KW_SPLAT_MUT;
1612 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1613 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1614 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1615 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1618 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1629 VALUE stored_indices = rb_hash_new();
1630 VALUE keyword_indices = rb_ary_new_capa(elements->
size);
1633 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1638 VALUE keyword = pm_static_literal_value(iseq, assoc->key, scope_node);
1639 VALUE stored_index = rb_hash_aref(stored_indices, keyword);
1644 if (!
NIL_P(stored_index)) {
1652 rb_hash_aset(stored_indices, keyword,
ULONG2NUM(element_index));
1653 rb_ary_store(keyword_indices, (
long) element_index,
Qtrue);
1658 *flags |= VM_CALL_KWARG;
1660 VALUE *keywords = (*kw_arg)->keywords;
1661 (*kw_arg)->references = 0;
1662 (*kw_arg)->keyword_len = (int) size;
1664 size_t keyword_index = 0;
1665 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1669 if (rb_ary_entry(keyword_indices, (
long) element_index) ==
Qtrue) {
1670 keywords[keyword_index++] = pm_static_literal_value(iseq, assoc->key, scope_node);
1674 PM_COMPILE(assoc->value);
1683 *flags |= VM_CALL_KW_SPLAT;
1685 size_t size = elements->
size;
1690 *flags |= VM_CALL_KW_SPLAT_MUT;
1693 for (
size_t element_index = 0; element_index < size; element_index++) {
1695 PM_COMPILE_NOT_POPPED(assoc->key);
1696 PM_COMPILE_NOT_POPPED(assoc->value);
1699 PUSH_INSN1(ret, location, newhash,
INT2FIX(size * 2));
1705 *flags |= VM_CALL_ARGS_SPLAT;
1709 PM_COMPILE_NOT_POPPED(splat_node->
expression);
1712 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1713 PUSH_GETLOCAL(ret, location, index.index, index.level);
1716 bool first_splat = !has_splat;
1724 if (index + 1 < arguments->
size || has_regular_blockarg) {
1725 PUSH_INSN1(ret, location, splatarray, (*dup_rest & SPLATARRAY_TRUE) ?
Qtrue :
Qfalse);
1726 if (*dup_rest & SPLATARRAY_TRUE) *dup_rest &= ~SPLATARRAY_TRUE;
1734 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1744 PUSH_INSN(ret, location, concattoarray);
1748 post_splat_counter = 0;
1753 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
1755 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
1756 *flags |= VM_CALL_FORWARDING;
1758 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
1759 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1766 *flags |= VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_SPLAT_MUT | VM_CALL_ARGS_BLOCKARG | VM_CALL_KW_SPLAT;
1773 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1774 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1775 PUSH_INSN1(ret, location, splatarray,
Qtrue);
1778 pm_local_index_t pow_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1779 PUSH_GETLOCAL(ret, location, pow_local.index, pow_local.level);
1782 pm_local_index_t and_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
1783 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(and_local.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(and_local.level));
1784 PUSH_INSN(ret, location, splatkw);
1789 post_splat_counter++;
1790 PM_COMPILE_NOT_POPPED(argument);
1810 if (index == arguments->
size - 1) {
1812 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1820 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1821 PUSH_INSN(ret, location, concatarray);
1825 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1826 PUSH_INSN(ret, location, concatarray);
1842 if (has_splat) orig_argc++;
1843 if (has_keyword_splat) orig_argc++;
1852pm_setup_args_dup_rest_p(
const pm_node_t *node)
1889 int dup_rest = SPLATARRAY_TRUE;
1892 size_t arguments_size;
1897 arguments_node != NULL &&
1898 (arguments = &arguments_node->
arguments, arguments_size = arguments->
size) >= 2 &&
1906 dup_rest = SPLATARRAY_FALSE;
1911 for (
size_t index = 0; dup_rest == SPLATARRAY_FALSE && index < elements->
size; index++) {
1917 if (pm_setup_args_dup_rest_p(assoc->
key) || pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
1922 if (assoc->
value != NULL && pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
1931 int initial_dup_rest = dup_rest;
1938 bool regular_block_arg =
true;
1941 if (block_expr && pm_setup_args_dup_rest_p(block_expr)) {
1942 dup_rest = SPLATARRAY_TRUE | DUP_SINGLE_KW_SPLAT;
1943 initial_dup_rest = dup_rest;
1946 DECL_ANCHOR(block_arg);
1947 pm_compile_node(iseq, block, block_arg,
false, scope_node);
1949 *flags |= VM_CALL_ARGS_BLOCKARG;
1951 if (LIST_INSN_SIZE_ONE(block_arg)) {
1952 LINK_ELEMENT *elem = FIRST_ELEMENT(block_arg);
1953 if (IS_INSN(elem)) {
1954 INSN *iobj = (INSN *) elem;
1955 if (iobj->insn_id == BIN(getblockparam)) {
1956 iobj->insn_id = BIN(getblockparamproxy);
1963 regular_block_arg =
false;
1967 argc = pm_setup_args_core(arguments_node, block, flags, regular_block_arg, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
1968 PUSH_SEQ(ret, block_arg);
1971 argc = pm_setup_args_core(arguments_node, block, flags,
false, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
1978 if (*flags & VM_CALL_ARGS_SPLAT && dup_rest != initial_dup_rest) {
1979 *flags |= VM_CALL_ARGS_SPLAT_MUT;
1999 if (!popped) PUSH_INSN(ret, location, putnil);
2001 PM_COMPILE_NOT_POPPED(node->
receiver);
2003 int boff = (node->
block == NULL ? 0 : 1);
2006 int argc = pm_setup_args(node->
arguments, (
const pm_node_t *) node->
block, &flag, &keywords, iseq, ret, scope_node, node_location);
2008 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2010 PUSH_INSN(ret, location, splatkw);
2013 PUSH_INSN(ret, location, dup);
2014 PUSH_INSN(ret, location, splatkw);
2015 PUSH_INSN(ret, location, pop);
2019 int dup_argn = argc + 1 + boff;
2020 int keyword_len = 0;
2023 keyword_len = keywords->keyword_len;
2024 dup_argn += keyword_len;
2027 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2028 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2029 PM_COMPILE_NOT_POPPED(node->
value);
2032 PUSH_SEND(ret, location, id_operator,
INT2FIX(1));
2035 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2037 if (flag & VM_CALL_ARGS_SPLAT) {
2038 if (flag & VM_CALL_KW_SPLAT) {
2039 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2041 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2042 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2043 flag |= VM_CALL_ARGS_SPLAT_MUT;
2046 PUSH_INSN(ret, location, swap);
2047 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2048 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2049 PUSH_INSN(ret, location, pop);
2053 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2054 PUSH_INSN(ret, location, swap);
2055 PUSH_INSN(ret, location, pop);
2057 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2058 PUSH_INSN(ret, location, swap);
2059 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2060 PUSH_INSN(ret, location, swap);
2061 flag |= VM_CALL_ARGS_SPLAT_MUT;
2063 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2065 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2066 PUSH_INSN(ret, location, pop);
2067 PUSH_INSN(ret, location, pop);
2071 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2073 else if (flag & VM_CALL_KW_SPLAT) {
2075 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2076 PUSH_INSN(ret, location, swap);
2077 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2078 PUSH_INSN(ret, location, pop);
2080 PUSH_INSN(ret, location, swap);
2081 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2083 else if (keyword_len) {
2084 PUSH_INSN(ret, location, dup);
2085 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 2));
2086 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2087 PUSH_INSN(ret, location, pop);
2088 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2092 PUSH_INSN(ret, location, swap);
2094 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2097 PUSH_INSN(ret, location, pop);
2116 if (!popped) PUSH_INSN(ret, location, putnil);
2117 PM_COMPILE_NOT_POPPED(receiver);
2119 int boff = (block == NULL ? 0 : 1);
2122 int argc = pm_setup_args(arguments, (
const pm_node_t *) block, &flag, &keywords, iseq, ret, scope_node, node_location);
2124 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2126 PUSH_INSN(ret, location, splatkw);
2129 PUSH_INSN(ret, location, dup);
2130 PUSH_INSN(ret, location, splatkw);
2131 PUSH_INSN(ret, location, pop);
2135 int dup_argn = argc + 1 + boff;
2136 int keyword_len = 0;
2139 keyword_len = keywords->keyword_len;
2140 dup_argn += keyword_len;
2143 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2144 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2146 LABEL *label = NEW_LABEL(location.
line);
2147 LABEL *lfin = NEW_LABEL(location.
line);
2149 PUSH_INSN(ret, location, dup);
2151 PUSH_INSNL(ret, location, branchunless, label);
2154 PUSH_INSNL(ret, location, branchif, label);
2157 PUSH_INSN(ret, location, pop);
2158 PM_COMPILE_NOT_POPPED(value);
2161 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2164 if (flag & VM_CALL_ARGS_SPLAT) {
2165 if (flag & VM_CALL_KW_SPLAT) {
2166 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2167 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2168 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2169 flag |= VM_CALL_ARGS_SPLAT_MUT;
2172 PUSH_INSN(ret, location, swap);
2173 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2174 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2175 PUSH_INSN(ret, location, pop);
2179 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2180 PUSH_INSN(ret, location, swap);
2181 PUSH_INSN(ret, location, pop);
2183 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2184 PUSH_INSN(ret, location, swap);
2185 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2186 PUSH_INSN(ret, location, swap);
2187 flag |= VM_CALL_ARGS_SPLAT_MUT;
2189 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2191 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2192 PUSH_INSN(ret, location, pop);
2193 PUSH_INSN(ret, location, pop);
2197 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2199 else if (flag & VM_CALL_KW_SPLAT) {
2201 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2202 PUSH_INSN(ret, location, swap);
2203 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2204 PUSH_INSN(ret, location, pop);
2207 PUSH_INSN(ret, location, swap);
2208 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2210 else if (keyword_len) {
2211 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2212 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 0));
2213 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2217 PUSH_INSN(ret, location, swap);
2219 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2222 PUSH_INSN(ret, location, pop);
2223 PUSH_INSNL(ret, location, jump, lfin);
2224 PUSH_LABEL(ret, label);
2226 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2228 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(dup_argn + 1));
2229 PUSH_LABEL(ret, lfin);
2238#define PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE 0
2239#define PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING 1
2240#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P 2
2241#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE 3
2242#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY 4
2247static 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);
2254pm_compile_pattern_generic_error(rb_iseq_t *iseq, pm_scope_node_t *scope_node,
const pm_node_t *node, LINK_ANCHOR *
const ret,
VALUE message,
unsigned int base_index)
2256 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2257 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2259 PUSH_INSN(ret, location, dup);
2260 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2262 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2263 PUSH_INSN1(ret, location, putobject, message);
2264 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2265 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2266 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2268 PUSH_INSN1(ret, location, putobject,
Qfalse);
2269 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2271 PUSH_INSN(ret, location, pop);
2272 PUSH_INSN(ret, location, pop);
2273 PUSH_LABEL(ret, match_succeeded_label);
2284pm_compile_pattern_length_error(rb_iseq_t *iseq, pm_scope_node_t *scope_node,
const pm_node_t *node, LINK_ANCHOR *
const ret,
VALUE message,
VALUE length,
unsigned int base_index)
2286 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2287 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2289 PUSH_INSN(ret, location, dup);
2290 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2292 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2293 PUSH_INSN1(ret, location, putobject, message);
2294 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2295 PUSH_INSN(ret, location, dup);
2296 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2297 PUSH_INSN1(ret, location, putobject, length);
2298 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(4));
2299 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2301 PUSH_INSN1(ret, location, putobject,
Qfalse);
2302 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2304 PUSH_INSN(ret, location, pop);
2305 PUSH_INSN(ret, location, pop);
2306 PUSH_LABEL(ret, match_succeeded_label);
2317pm_compile_pattern_eqq_error(rb_iseq_t *iseq, pm_scope_node_t *scope_node,
const pm_node_t *node, LINK_ANCHOR *
const ret,
unsigned int base_index)
2319 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2320 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2322 PUSH_INSN(ret, location, dup);
2323 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2324 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2326 VALUE operand = rb_fstring_lit(
"%p === %p does not return true");
2327 PUSH_INSN1(ret, location, putobject, operand);
2329 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2330 PUSH_INSN1(ret, location, topn,
INT2FIX(5));
2331 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2332 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2333 PUSH_INSN1(ret, location, putobject,
Qfalse);
2334 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2335 PUSH_INSN(ret, location, pop);
2336 PUSH_INSN(ret, location, pop);
2338 PUSH_LABEL(ret, match_succeeded_label);
2339 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2340 PUSH_INSN(ret, location, pop);
2341 PUSH_INSN(ret, location, pop);
2353pm_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)
2355 LABEL *matched_label = NEW_LABEL(pm_node_line_number(scope_node->parser, node));
2356 CHECK(pm_compile_pattern(iseq, scope_node, node, ret, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern, use_deconstructed_cache, base_index));
2357 PUSH_LABEL(ret, matched_label);
2367pm_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)
2369 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2371 if (use_deconstructed_cache) {
2372 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2373 PUSH_INSNL(ret, location, branchnil, deconstruct_label);
2375 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2376 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2378 PUSH_INSN(ret, location, pop);
2379 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE - 1));
2380 PUSH_INSNL(ret, location, jump, deconstructed_label);
2383 PUSH_INSNL(ret, location, jump, deconstruct_label);
2386 PUSH_LABEL(ret, deconstruct_label);
2387 PUSH_INSN(ret, location, dup);
2390 PUSH_INSN1(ret, location, putobject, operand);
2391 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2393 if (use_deconstructed_cache) {
2394 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE + 1));
2397 if (in_single_pattern) {
2398 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct"), base_index + 1));
2401 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2402 PUSH_SEND(ret, location, rb_intern(
"deconstruct"),
INT2FIX(0));
2404 if (use_deconstructed_cache) {
2405 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2408 PUSH_INSN(ret, location, dup);
2410 PUSH_INSNL(ret, location, branchunless, type_error_label);
2411 PUSH_LABEL(ret, deconstructed_label);
2421pm_compile_pattern_constant(rb_iseq_t *iseq, pm_scope_node_t *scope_node,
const pm_node_t *node, LINK_ANCHOR *
const ret, LABEL *match_failed_label,
bool in_single_pattern,
unsigned int base_index)
2423 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2425 PUSH_INSN(ret, location, dup);
2426 PM_COMPILE_NOT_POPPED(node);
2428 if (in_single_pattern) {
2429 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
2431 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
2432 if (in_single_pattern) {
2433 CHECK(pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 3));
2435 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2444pm_compile_pattern_error_handler(rb_iseq_t *iseq,
const pm_scope_node_t *scope_node,
const pm_node_t *node, LINK_ANCHOR *
const ret, LABEL *done_label,
bool popped)
2446 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2447 LABEL *key_error_label = NEW_LABEL(location.
line);
2448 LABEL *cleanup_label = NEW_LABEL(location.
line);
2451 kw_arg->references = 0;
2452 kw_arg->keyword_len = 2;
2453 kw_arg->keywords[0] =
ID2SYM(rb_intern(
"matchee"));
2454 kw_arg->keywords[1] =
ID2SYM(rb_intern(
"key"));
2456 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2457 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2458 PUSH_INSNL(ret, location, branchif, key_error_label);
2461 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2464 VALUE operand = rb_fstring_lit(
"%p: %s");
2465 PUSH_INSN1(ret, location, putobject, operand);
2468 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2469 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2470 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2471 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2472 PUSH_INSNL(ret, location, jump, cleanup_label);
2474 PUSH_LABEL(ret, key_error_label);
2476 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2479 VALUE operand = rb_fstring_lit(
"%p: %s");
2480 PUSH_INSN1(ret, location, putobject, operand);
2483 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2484 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2485 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2486 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2487 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2488 PUSH_SEND_R(ret, location, rb_intern(
"new"),
INT2FIX(1), NULL,
INT2FIX(VM_CALL_KWARG), kw_arg);
2489 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(1));
2490 PUSH_LABEL(ret, cleanup_label);
2492 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(7));
2493 if (!popped) PUSH_INSN(ret, location, putnil);
2494 PUSH_INSNL(ret, location, jump, done_label);
2495 PUSH_INSN1(ret, location, dupn,
INT2FIX(5));
2496 if (popped) PUSH_INSN(ret, location, putnil);
2503pm_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)
2505 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2520 const size_t posts_size = cast->
posts.
size;
2521 const size_t minimum_size = requireds_size + posts_size;
2523 bool rest_named =
false;
2524 bool use_rest_size =
false;
2526 if (cast->
rest != NULL) {
2528 use_rest_size = (rest_named || (!rest_named && posts_size > 0));
2531 LABEL *match_failed_label = NEW_LABEL(location.
line);
2532 LABEL *type_error_label = NEW_LABEL(location.
line);
2533 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2534 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2536 if (use_rest_size) {
2537 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2538 PUSH_INSN(ret, location, swap);
2543 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2546 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));
2548 PUSH_INSN(ret, location, dup);
2549 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2550 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2551 PUSH_SEND(ret, location, cast->
rest == NULL ? idEq : idGE,
INT2FIX(1));
2552 if (in_single_pattern) {
2553 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+)");
2554 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, message,
INT2FIX(minimum_size), base_index + 1));
2556 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2558 for (
size_t index = 0; index < requireds_size; index++) {
2560 PUSH_INSN(ret, location, dup);
2561 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2562 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2563 CHECK(pm_compile_pattern_match(iseq, scope_node, required, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2566 if (cast->
rest != NULL) {
2568 PUSH_INSN(ret, location, dup);
2569 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size));
2570 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2571 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2572 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2573 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2574 PUSH_INSN1(ret, location, setn,
INT2FIX(4));
2575 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2576 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));
2578 else if (posts_size > 0) {
2579 PUSH_INSN(ret, location, dup);
2580 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2581 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2582 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2583 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2584 PUSH_INSN(ret, location, pop);
2588 for (
size_t index = 0; index < posts_size; index++) {
2590 PUSH_INSN(ret, location, dup);
2592 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size + index));
2593 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2594 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2595 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2596 CHECK(pm_compile_pattern_match(iseq, scope_node, post, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2599 PUSH_INSN(ret, location, pop);
2600 if (use_rest_size) {
2601 PUSH_INSN(ret, location, pop);
2604 PUSH_INSNL(ret, location, jump, matched_label);
2605 PUSH_INSN(ret, location, putnil);
2606 if (use_rest_size) {
2607 PUSH_INSN(ret, location, putnil);
2610 PUSH_LABEL(ret, type_error_label);
2611 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2615 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2616 PUSH_INSN1(ret, location, putobject, operand);
2619 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2620 PUSH_INSN(ret, location, pop);
2622 PUSH_LABEL(ret, match_failed_label);
2623 PUSH_INSN(ret, location, pop);
2624 if (use_rest_size) {
2625 PUSH_INSN(ret, location, pop);
2628 PUSH_INSNL(ret, location, jump, unmatched_label);
2643 LABEL *match_failed_label = NEW_LABEL(location.
line);
2644 LABEL *type_error_label = NEW_LABEL(location.
line);
2645 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2646 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2649 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2652 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));
2654 PUSH_INSN(ret, location, dup);
2655 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2656 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2657 PUSH_SEND(ret, location, idGE,
INT2FIX(1));
2658 if (in_single_pattern) {
2659 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));
2661 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2664 LABEL *while_begin_label = NEW_LABEL(location.
line);
2665 LABEL *next_loop_label = NEW_LABEL(location.
line);
2666 LABEL *find_succeeded_label = NEW_LABEL(location.
line);
2667 LABEL *find_failed_label = NEW_LABEL(location.
line);
2669 PUSH_INSN(ret, location, dup);
2670 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2672 PUSH_INSN(ret, location, dup);
2673 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2674 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2675 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2676 PUSH_LABEL(ret, while_begin_label);
2678 PUSH_INSN(ret, location, dup);
2679 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2680 PUSH_SEND(ret, location, idLE,
INT2FIX(1));
2681 PUSH_INSNL(ret, location, branchunless, find_failed_label);
2683 for (
size_t index = 0; index < size; index++) {
2684 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2685 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2688 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2689 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2692 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2693 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));
2699 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2700 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2701 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2702 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2703 CHECK(pm_compile_pattern_match(iseq, scope_node, left->
expression, ret, find_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 4));
2709 if (right->expression != NULL) {
2710 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2711 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2712 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2713 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2714 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2715 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2716 pm_compile_pattern_match(iseq, scope_node, right->expression, ret, find_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 4);
2719 PUSH_INSNL(ret, location, jump, find_succeeded_label);
2721 PUSH_LABEL(ret, next_loop_label);
2722 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
2723 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2724 PUSH_INSNL(ret, location, jump, while_begin_label);
2726 PUSH_LABEL(ret, find_failed_label);
2727 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2728 if (in_single_pattern) {
2729 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2732 VALUE operand = rb_fstring_lit(
"%p does not match to find pattern");
2733 PUSH_INSN1(ret, location, putobject, operand);
2736 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2737 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2738 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2740 PUSH_INSN1(ret, location, putobject,
Qfalse);
2741 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2743 PUSH_INSN(ret, location, pop);
2744 PUSH_INSN(ret, location, pop);
2746 PUSH_INSNL(ret, location, jump, match_failed_label);
2747 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2749 PUSH_LABEL(ret, find_succeeded_label);
2750 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2753 PUSH_INSN(ret, location, pop);
2754 PUSH_INSNL(ret, location, jump, matched_label);
2755 PUSH_INSN(ret, location, putnil);
2757 PUSH_LABEL(ret, type_error_label);
2758 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2762 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2763 PUSH_INSN1(ret, location, putobject, operand);
2766 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2767 PUSH_INSN(ret, location, pop);
2769 PUSH_LABEL(ret, match_failed_label);
2770 PUSH_INSN(ret, location, pop);
2771 PUSH_INSNL(ret, location, jump, unmatched_label);
2790 LABEL *match_failed_label = NEW_LABEL(location.
line);
2791 LABEL *type_error_label = NEW_LABEL(location.
line);
2794 if (has_keys && !has_rest) {
2797 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2805 rb_ary_push(keys, symbol);
2810 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2813 PUSH_INSN(ret, location, dup);
2816 VALUE operand =
ID2SYM(rb_intern(
"deconstruct_keys"));
2817 PUSH_INSN1(ret, location, putobject, operand);
2820 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2821 if (in_single_pattern) {
2822 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct_keys"), base_index + 1));
2824 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2827 PUSH_INSN(ret, location, putnil);
2830 PUSH_INSN1(ret, location, duparray, keys);
2833 PUSH_SEND(ret, location, rb_intern(
"deconstruct_keys"),
INT2FIX(1));
2835 PUSH_INSN(ret, location, dup);
2837 PUSH_INSNL(ret, location, branchunless, type_error_label);
2840 PUSH_SEND(ret, location, rb_intern(
"dup"),
INT2FIX(0));
2844 DECL_ANCHOR(match_values);
2846 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2855 PUSH_INSN(ret, location, dup);
2856 PUSH_INSN1(ret, location, putobject, symbol);
2857 PUSH_SEND(ret, location, rb_intern(
"key?"),
INT2FIX(1));
2859 if (in_single_pattern) {
2860 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2862 PUSH_INSN(ret, location, dup);
2863 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2867 PUSH_INSN1(ret, location, putobject, operand);
2870 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 2));
2871 PUSH_INSN1(ret, location, putobject,
Qtrue);
2872 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 3));
2873 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2874 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2875 PUSH_INSN1(ret, location, putobject, symbol);
2876 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2878 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(4));
2879 PUSH_LABEL(ret, match_succeeded_label);
2882 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2883 PUSH_INSN(match_values, location, dup);
2884 PUSH_INSN1(match_values, location, putobject, symbol);
2885 PUSH_SEND(match_values, location, has_rest ? rb_intern(
"delete") : idAREF,
INT2FIX(1));
2892 CHECK(pm_compile_pattern_match(iseq, scope_node, value, match_values, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2895 PUSH_SEQ(ret, match_values);
2898 PUSH_INSN(ret, location, dup);
2899 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
2900 if (in_single_pattern) {
2901 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p is not empty"), base_index + 1));
2903 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2909 PUSH_INSN(ret, location, dup);
2910 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
2911 if (in_single_pattern) {
2912 pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"rest of %p is not empty"), base_index + 1);
2914 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2919 PUSH_INSN(ret, location, dup);
2920 pm_compile_pattern_match(iseq, scope_node, splat->value, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1);
2924 rb_bug(
"unreachable");
2929 PUSH_INSN(ret, location, pop);
2930 PUSH_INSNL(ret, location, jump, matched_label);
2931 PUSH_INSN(ret, location, putnil);
2933 PUSH_LABEL(ret, type_error_label);
2934 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2938 VALUE operand = rb_fstring_lit(
"deconstruct_keys must return Hash");
2939 PUSH_INSN1(ret, location, putobject, operand);
2942 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2943 PUSH_INSN(ret, location, pop);
2945 PUSH_LABEL(ret, match_failed_label);
2946 PUSH_INSN(ret, location, pop);
2947 PUSH_INSNL(ret, location, jump, unmatched_label);
2962 LABEL *match_failed_label = NEW_LABEL(location.
line);
2964 PUSH_INSN(ret, location, dup);
2965 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));
2966 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));
2967 PUSH_INSN(ret, location, putnil);
2969 PUSH_LABEL(ret, match_failed_label);
2970 PUSH_INSN(ret, location, pop);
2971 PUSH_INSNL(ret, location, jump, unmatched_label);
2980 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
2986 if (in_alternation_pattern) {
2987 ID id = pm_constant_id_lookup(scope_node, cast->
name);
2988 const char *name = rb_id2name(
id);
2990 if (name && strlen(name) > 0 && name[0] !=
'_') {
2991 COMPILE_ERROR(iseq, location.
line,
"illegal variable in alternative pattern (%"PRIsVALUE
")", rb_id2str(
id));
2996 PUSH_SETLOCAL(ret, location, index.index, index.level);
2997 PUSH_INSNL(ret, location, jump, matched_label);
3005 LABEL *matched_left_label = NEW_LABEL(location.
line);
3006 LABEL *unmatched_left_label = NEW_LABEL(location.
line);
3010 PUSH_INSN(ret, location, dup);
3011 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));
3016 PUSH_LABEL(ret, matched_left_label);
3017 PUSH_INSN(ret, location, pop);
3018 PUSH_INSNL(ret, location, jump, matched_label);
3019 PUSH_INSN(ret, location, putnil);
3023 PUSH_LABEL(ret, unmatched_left_label);
3024 CHECK(pm_compile_pattern(iseq, scope_node, cast->
right, ret, matched_label, unmatched_label, in_single_pattern,
true, use_deconstructed_cache, base_index));
3032 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);
3072 PM_COMPILE_NOT_POPPED(node);
3073 if (in_single_pattern) {
3074 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
3077 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
3079 if (in_single_pattern) {
3080 pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 2);
3083 PUSH_INSNL(ret, location, branchif, matched_label);
3084 PUSH_INSNL(ret, location, jump, unmatched_label);
3093 CHECK(pm_compile_pattern(iseq, scope_node, cast->
variable, ret, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern,
true, base_index));
3127 CHECK(pm_compile_pattern_match(iseq, scope_node, statement, ret, unmatched_label, in_single_pattern, in_alternation_pattern, use_deconstructed_cache, base_index));
3128 PM_COMPILE_NOT_POPPED(predicate);
3130 if (in_single_pattern) {
3131 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3133 PUSH_INSN(ret, location, dup);
3135 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3138 PUSH_INSNL(ret, location, branchunless, match_succeeded_label);
3142 VALUE operand = rb_fstring_lit(
"guard clause does not return true");
3143 PUSH_INSN1(ret, location, putobject, operand);
3146 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
3147 PUSH_INSN1(ret, location, putobject,
Qfalse);
3148 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
3150 PUSH_INSN(ret, location, pop);
3151 PUSH_INSN(ret, location, pop);
3153 PUSH_LABEL(ret, match_succeeded_label);
3157 PUSH_INSNL(ret, location, branchunless, unmatched_label);
3160 PUSH_INSNL(ret, location, branchif, unmatched_label);
3163 PUSH_INSNL(ret, location, jump, matched_label);
3170 rb_bug(
"Unexpected node type in pattern matching expression: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
3177#undef PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE
3178#undef PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING
3179#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P
3180#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE
3181#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY
3185pm_scope_node_init(
const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous)
3189 memset(scope, 0,
sizeof(pm_scope_node_t));
3195 scope->previous = previous;
3199 scope->parser = previous->parser;
3200 scope->encoding = previous->encoding;
3202 scope->constants = previous->constants;
3203 scope->coverage_enabled = previous->coverage_enabled;
3210 scope->body = cast->
body;
3211 scope->locals = cast->
locals;
3217 scope->body = cast->
body;
3218 scope->locals = cast->
locals;
3224 scope->body = cast->body;
3225 scope->locals = cast->locals;
3252 scope->body = cast->
body;
3253 scope->locals = cast->
locals;
3265 scope->body = cast->
body;
3266 scope->locals = cast->
locals;
3277 scope->locals = cast->locals;
3292 scope->body = cast->
body;
3293 scope->locals = cast->
locals;
3302 rb_bug(
"unreachable");
3308pm_scope_node_destroy(pm_scope_node_t *scope_node)
3310 if (scope_node->index_lookup_table) {
3311 st_free_table(scope_node->index_lookup_table);
3327pm_compile_retry_end_label(rb_iseq_t *iseq, LINK_ANCHOR *
const ret, LABEL *retry_end_l)
3330 LINK_ELEMENT *last_elem = LAST_ELEMENT(ret);
3331 iobj = IS_INSN(last_elem) ? (INSN*) last_elem : (INSN*) get_prev_insn((INSN*) last_elem);
3332 while (!IS_INSN_ID(iobj, send) && !IS_INSN_ID(iobj, invokesuper) && !IS_INSN_ID(iobj, sendforward) && !IS_INSN_ID(iobj, invokesuperforward)) {
3333 iobj = (INSN*) get_prev_insn(iobj);
3335 ELEM_INSERT_NEXT(&iobj->link, (LINK_ELEMENT*) retry_end_l);
3340 if (&iobj->link == LAST_ELEMENT(ret)) {
3341 ret->last = (LINK_ELEMENT*) retry_end_l;
3346pm_iseq_builtin_function_name(
const pm_scope_node_t *scope_node,
const pm_node_t *receiver,
ID method_id)
3348 const char *name = rb_id2name(method_id);
3349 static const char prefix[] =
"__builtin_";
3350 const size_t prefix_len =
sizeof(prefix) - 1;
3352 if (receiver == NULL) {
3353 if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) {
3355 return &name[prefix_len];
3382 if (arguments == NULL) {
3383 COMPILE_ERROR(iseq, node_location->
line,
"attr!: no argument");
3390 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to attr!: %s", pm_node_type_to_str(
PM_NODE_TYPE(argument)));
3394 VALUE symbol = pm_static_literal_value(iseq, argument, scope_node);
3397 if (strcmp(RSTRING_PTR(
string),
"leaf") == 0) {
3398 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_LEAF;
3400 else if (strcmp(RSTRING_PTR(
string),
"inline_block") == 0) {
3401 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_INLINE_BLOCK;
3403 else if (strcmp(RSTRING_PTR(
string),
"use_block") == 0) {
3404 iseq_set_use_block(iseq);
3406 else if (strcmp(RSTRING_PTR(
string),
"c_trace") == 0) {
3408 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_C_TRACE;
3411 COMPILE_ERROR(iseq, node_location->
line,
"unknown argument to attr!: %s", RSTRING_PTR(
string));
3420pm_compile_builtin_arg(rb_iseq_t *iseq, LINK_ANCHOR *
const ret,
const pm_scope_node_t *scope_node,
const pm_arguments_node_t *arguments,
const pm_node_location_t *node_location,
int popped)
3422 if (arguments == NULL) {
3423 COMPILE_ERROR(iseq, node_location->
line,
"arg!: no argument");
3428 COMPILE_ERROR(iseq, node_location->
line,
"arg!: too many argument");
3434 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to arg!: %s", pm_node_type_to_str(
PM_NODE_TYPE(argument)));
3440 int index = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->local_table_size - get_local_var_idx(iseq, name);
3442 debugs(
"id: %s idx: %d\n", rb_id2name(name), index);
3443 PUSH_GETLOCAL(ret, *node_location, index, get_lvar_level(iseq));
3450pm_compile_builtin_mandatory_only_method(rb_iseq_t *iseq, pm_scope_node_t *scope_node,
const pm_call_node_t *call_node,
const pm_node_location_t *node_location)
3452 const pm_node_t *ast_node = scope_node->ast_node;
3454 rb_bug(
"mandatory_only?: not in method definition");
3460 if (parameters_node == NULL) {
3461 rb_bug(
"mandatory_only?: in method definition with no parameters");
3467 rb_bug(
"mandatory_only?: not in method definition with plain statements");
3473 rb_bug(
"mandatory_only?: can't find mandatory node");
3478 .base = parameters_node->
base,
3483 .base = def_node->
base,
3484 .name = def_node->
name,
3486 .parameters = ¶meters,
3495 pm_scope_node_t next_scope_node;
3496 pm_scope_node_init(&def.base, &next_scope_node, scope_node);
3499 ISEQ_BODY(iseq)->mandatory_only_iseq = pm_iseq_new_with_opt(
3501 rb_iseq_base_label(iseq),
3503 rb_iseq_realpath(iseq),
3504 node_location->
line,
3508 ISEQ_COMPILE_DATA(iseq)->option,
3513 RUBY_ASSERT(ISEQ_BODY(iseq)->mandatory_only_iseq == NULL);
3514 rb_jump_tag(error_state);
3517 pm_scope_node_destroy(&next_scope_node);
3522pm_compile_builtin_function_call(rb_iseq_t *iseq, LINK_ANCHOR *
const ret, pm_scope_node_t *scope_node,
const pm_call_node_t *call_node,
const pm_node_location_t *node_location,
int popped,
const rb_iseq_t *parent_block,
const char *builtin_func)
3526 if (parent_block != NULL) {
3527 COMPILE_ERROR(iseq, node_location->
line,
"should not call builtins here.");
3531#define BUILTIN_INLINE_PREFIX "_bi"
3532 char inline_func[
sizeof(BUILTIN_INLINE_PREFIX) +
DECIMAL_SIZE_OF(
int)];
3533 bool cconst =
false;
3538 if (strcmp(
"cstmt!", builtin_func) == 0 || strcmp(
"cexpr!", builtin_func) == 0) {
3541 else if (strcmp(
"cconst!", builtin_func) == 0) {
3544 else if (strcmp(
"cinit!", builtin_func) == 0) {
3548 else if (strcmp(
"attr!", builtin_func) == 0) {
3549 return pm_compile_builtin_attr(iseq, scope_node, arguments, node_location);
3551 else if (strcmp(
"arg!", builtin_func) == 0) {
3552 return pm_compile_builtin_arg(iseq, ret, scope_node, arguments, node_location, popped);
3554 else if (strcmp(
"mandatory_only?", builtin_func) == 0) {
3556 rb_bug(
"mandatory_only? should be in if condition");
3558 else if (!LIST_INSN_SIZE_ZERO(ret)) {
3559 rb_bug(
"mandatory_only? should be put on top");
3562 PUSH_INSN1(ret, *node_location, putobject,
Qfalse);
3563 return pm_compile_builtin_mandatory_only_method(iseq, scope_node, call_node, node_location);
3566 rb_bug(
"can't find builtin function:%s", builtin_func);
3569 COMPILE_ERROR(iseq, node_location->
line,
"can't find builtin function:%s", builtin_func);
3573 int inline_index = node_location->
line;
3574 snprintf(inline_func,
sizeof(inline_func), BUILTIN_INLINE_PREFIX
"%d", inline_index);
3575 builtin_func = inline_func;
3581 typedef VALUE(*builtin_func0)(
void *,
VALUE);
3582 VALUE const_val = (*(builtin_func0)(uintptr_t)bf->func_ptr)(NULL,
Qnil);
3583 PUSH_INSN1(ret, *node_location, putobject, const_val);
3589 DECL_ANCHOR(args_seq);
3593 int argc = pm_setup_args(arguments, call_node->
block, &flags, &keywords, iseq, args_seq, scope_node, node_location);
3595 if (argc != bf->argc) {
3596 COMPILE_ERROR(iseq, node_location->
line,
"argc is not match for builtin function:%s (expect %d but %d)", builtin_func, bf->argc, argc);
3600 unsigned int start_index;
3601 if (delegate_call_p(iseq, argc, args_seq, &start_index)) {
3602 PUSH_INSN2(ret, *node_location, opt_invokebuiltin_delegate, bf,
INT2FIX(start_index));
3605 PUSH_SEQ(ret, args_seq);
3606 PUSH_INSN1(ret, *node_location, invokebuiltin, bf);
3609 if (popped) PUSH_INSN(ret, *node_location, pop);
3617pm_compile_call(rb_iseq_t *iseq,
const pm_call_node_t *call_node, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node,
ID method_id, LABEL *start)
3623 LABEL *else_label = NEW_LABEL(location.
line);
3624 LABEL *end_label = NEW_LABEL(location.
line);
3625 LABEL *retry_end_l = NEW_LABEL(location.
line);
3628 rb_code_location_t code_location = { 0 };
3629 int node_id = location.
node_id;
3632 if (PM_BRANCH_COVERAGE_P(iseq)) {
3633 const uint8_t *cursors[3] = {
3639 const uint8_t *end_cursor = cursors[0];
3640 end_cursor = (end_cursor == NULL || cursors[1] == NULL) ? cursors[1] : (end_cursor > cursors[1] ? end_cursor : cursors[1]);
3641 end_cursor = (end_cursor == NULL || cursors[2] == NULL) ? cursors[2] : (end_cursor > cursors[2] ? end_cursor : cursors[2]);
3644 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(scope_node->parser, call_node);
3647 code_location = (rb_code_location_t) {
3648 .beg_pos = { .lineno = start_location.line, .column = start_location.column },
3649 .end_pos = { .lineno = end_location.line, .column = end_location.column }
3652 branches = decl_branch_base(iseq, PTR2NUM(call_node), &code_location,
"&.");
3655 PUSH_INSN(ret, location, dup);
3656 PUSH_INSNL(ret, location, branchnil, else_label);
3658 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0,
"then", branches);
3664 int orig_argc = pm_setup_args(call_node->
arguments, call_node->
block, &flags, &kw_arg, iseq, ret, scope_node, &location);
3665 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
3666 const rb_iseq_t *block_iseq = NULL;
3670 pm_scope_node_t next_scope_node;
3671 pm_scope_node_init(call_node->
block, &next_scope_node, scope_node);
3673 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));
3674 pm_scope_node_destroy(&next_scope_node);
3675 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
3679 flags |= VM_CALL_VCALL;
3683 flags |= VM_CALL_ARGS_SIMPLE;
3688 flags |= VM_CALL_FCALL;
3692 if (flags & VM_CALL_ARGS_BLOCKARG) {
3693 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
3694 if (flags & VM_CALL_ARGS_SPLAT) {
3695 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3696 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3698 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 3));
3699 PUSH_INSN(ret, location, pop);
3701 else if (flags & VM_CALL_ARGS_SPLAT) {
3702 PUSH_INSN(ret, location, dup);
3703 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3704 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3705 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 2));
3706 PUSH_INSN(ret, location, pop);
3709 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 1));
3713 if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
3714 PUSH_INSN(ret, location, splatkw);
3717 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3719 if (block_iseq && ISEQ_BODY(block_iseq)->catch_table) {
3720 pm_compile_retry_end_label(iseq, ret, retry_end_l);
3721 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, start, retry_end_l, block_iseq, retry_end_l);
3725 PUSH_INSNL(ret, location, jump, end_label);
3726 PUSH_LABEL(ret, else_label);
3727 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 1,
"else", branches);
3728 PUSH_LABEL(ret, end_label);
3732 PUSH_INSN(ret, location, pop);
3735 if (popped) PUSH_INSN(ret, location, pop);
3736 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
3764pm_compile_defined_expr0(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node,
bool in_condition, LABEL **lfinish,
bool explicit_receiver)
3766#define PUSH_VAL(type) (in_condition ? Qtrue : rb_iseq_defined_string(type))
3769 enum defined_type dtype = DEFINED_NOT_DEFINED;
3777 dtype = DEFINED_NIL;
3784 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3786 PUSH_INSN3(ret, location, definedivar,
ID2SYM(name), get_ivar_ic_value(iseq, name), PUSH_VAL(DEFINED_IVAR));
3797 dtype = DEFINED_LVAR;
3804 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3806 PUSH_INSN(ret, location, putnil);
3807 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR),
ID2SYM(name), PUSH_VAL(DEFINED_GVAR));
3816 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3818 PUSH_INSN(ret, location, putnil);
3819 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR),
ID2SYM(name), PUSH_VAL(DEFINED_CVAR));
3828 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3830 PUSH_INSN(ret, location, putnil);
3831 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
3839 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
3841 PUSH_INSN(ret, location, putnil);
3842 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
3852 dtype = DEFINED_EXPR;
3856 PUSH_INSN(ret, location, putnil);
3857 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
3865 if (cast->
block != NULL) {
3866 dtype = DEFINED_EXPR;
3870 PUSH_INSN(ret, location, putnil);
3871 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
3878 dtype = DEFINED_SELF;
3884 dtype = DEFINED_TRUE;
3890 dtype = DEFINED_FALSE;
3986 dtype = DEFINED_ASGN;
4130 dtype = DEFINED_EXPR;
4137 VALUE ref = pm_compile_back_reference_ref(cast);
4139 PUSH_INSN(ret, location, putnil);
4140 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4148 VALUE ref = pm_compile_numbered_reference_ref(cast);
4150 PUSH_INSN(ret, location, putnil);
4151 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4160 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4162 if (cast->
parent != NULL) {
4163 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4164 pm_compile_defined_expr0(iseq, cast->
parent, node_location, ret, popped, scope_node,
true, lfinish,
false);
4166 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4167 PM_COMPILE(cast->
parent);
4170 PUSH_INSN1(ret, location, putobject, rb_cObject);
4173 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4185 dtype = DEFINED_NIL;
4191 pm_compile_defined_expr0(iseq, cast->
statements->
body.
nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4197 dtype = DEFINED_EXPR;
4202 dtype = DEFINED_EXPR;
4212 if (cast->
body == NULL) {
4214 dtype = DEFINED_NIL;
4219 pm_compile_defined_expr0(iseq, ((
const pm_statements_node_t *) cast->
body)->body.nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4225 dtype = DEFINED_EXPR;
4236 lfinish[1] = NEW_LABEL(location.
line);
4239 for (
size_t index = 0; index < cast->
elements.
size; index++) {
4240 pm_compile_defined_expr0(iseq, cast->
elements.
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4241 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4244 dtype = DEFINED_EXPR;
4262 if (elements->
size > 0 && !lfinish[1]) {
4263 lfinish[1] = NEW_LABEL(location.
line);
4266 for (
size_t index = 0; index < elements->
size; index++) {
4267 pm_compile_defined_expr0(iseq, elements->
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4268 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4271 dtype = DEFINED_EXPR;
4279 pm_compile_defined_expr0(iseq, cast->
key, node_location, ret, popped, scope_node,
true, lfinish,
false);
4280 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4281 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4290 if (cast->
value == NULL) {
4291 dtype = DEFINED_EXPR;
4295 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4302 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4306#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE))
4313 dtype = DEFINED_EXPR;
4318 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4319 if (!lfinish[2]) lfinish[2] = NEW_LABEL(location.
line);
4323 pm_compile_defined_expr0(iseq, (
const pm_node_t *) cast->
arguments, node_location, ret, popped, scope_node,
true, lfinish,
false);
4324 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4328 pm_compile_defined_expr0(iseq, cast->
block, node_location, ret, popped, scope_node,
true, lfinish,
false);
4329 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4336 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
true);
4337 PUSH_INSNL(ret, location, branchunless, lfinish[2]);
4340 ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
4342 pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
4345 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
false);
4346 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4350 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4352 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4353 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_METHOD),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4356 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4358 PUSH_INSN(ret, location, putself);
4359 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4361 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_FUNC),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4371 for (
size_t index = 0; index < cast->
arguments.
size; index++) {
4372 pm_compile_defined_expr0(iseq, cast->
arguments.
nodes[index], node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4375 lfinish[1] = NEW_LABEL(location.
line);
4377 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4380 dtype = DEFINED_TRUE;
4386 dtype = DEFINED_EXPR;
4391 dtype = DEFINED_EXPR;
4399 dtype = DEFINED_EXPR;
4403 pm_compile_defined_expr0(iseq, cast->
expression, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4405 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4406 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4408 dtype = DEFINED_EXPR;
4415 pm_compile_defined_expr0(iseq, ((
const pm_shareable_constant_node_t *) node)->write, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4466 rb_bug(
"Unreachable node in defined?: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
4470 PUSH_INSN1(ret, location, putobject, PUSH_VAL(dtype));
4476pm_defined_expr(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node,
bool in_condition, LABEL **lfinish,
bool explicit_receiver)
4478 LINK_ELEMENT *lcur = ret->last;
4479 pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4482 LABEL *lstart = NEW_LABEL(node_location->
line);
4483 LABEL *lend = NEW_LABEL(node_location->
line);
4486 rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
4488 const rb_iseq_t *rescue = new_child_iseq_with_callback(
4497 lstart->rescued = LABEL_RESCUE_BEG;
4498 lend->rescued = LABEL_RESCUE_END;
4500 APPEND_LABEL(ret, lcur, lstart);
4501 PUSH_LABEL(ret, lend);
4502 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
4507pm_compile_defined_expr(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node,
bool in_condition)
4510 LINK_ELEMENT *last = ret->last;
4512 lfinish[0] = NEW_LABEL(node_location->
line);
4517 pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4521 ELEM_INSERT_NEXT(last, &new_insn_body(iseq, node_location->
line, node_location->
node_id, BIN(putnil), 0)->link);
4522 PUSH_INSN(ret, *node_location, swap);
4524 if (lfinish[2]) PUSH_LABEL(ret, lfinish[2]);
4525 PUSH_INSN(ret, *node_location, pop);
4526 PUSH_LABEL(ret, lfinish[1]);
4530 PUSH_LABEL(ret, lfinish[0]);
4536pm_add_ensure_iseq(LINK_ANCHOR *
const ret, rb_iseq_t *iseq,
int is_return, pm_scope_node_t *scope_node)
4541 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
4543 DECL_ANCHOR(ensure);
4546 if (enlp->erange != NULL) {
4547 DECL_ANCHOR(ensure_part);
4548 LABEL *lstart = NEW_LABEL(0);
4549 LABEL *lend = NEW_LABEL(0);
4551 add_ensure_range(iseq, enlp->erange, lstart, lend);
4553 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
4554 PUSH_LABEL(ensure_part, lstart);
4556 PM_COMPILE_INTO_ANCHOR(ensure_part, (
const pm_node_t *) enlp->ensure_node);
4557 PUSH_LABEL(ensure_part, lend);
4558 PUSH_SEQ(ensure, ensure_part);
4567 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
4568 PUSH_SEQ(ret, ensure);
4572 pm_scope_node_t *scope_node;
4573 rb_ast_id_table_t *local_table_for_iseq;
4578pm_local_table_insert_func(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
4584 pm_scope_node_t *scope_node = ctx->scope_node;
4585 rb_ast_id_table_t *local_table_for_iseq = ctx->local_table_for_iseq;
4586 int local_index = ctx->local_index;
4588 ID local = pm_constant_id_lookup(scope_node, constant_id);
4589 local_table_for_iseq->ids[local_index] = local;
4591 *value = (st_data_t)local_index;
4605pm_insert_local_index(
pm_constant_id_t constant_id,
int local_index, st_table *index_lookup_table, rb_ast_id_table_t *local_table_for_iseq, pm_scope_node_t *scope_node)
4607 RUBY_ASSERT((constant_id & PM_SPECIAL_CONSTANT_FLAG) == 0);
4609 ID local = pm_constant_id_lookup(scope_node, constant_id);
4610 local_table_for_iseq->ids[local_index] = local;
4611 st_insert(index_lookup_table, (st_data_t) constant_id, (st_data_t) local_index);
4619pm_insert_local_special(
ID local_name,
int local_index, st_table *index_lookup_table, rb_ast_id_table_t *local_table_for_iseq)
4621 local_table_for_iseq->ids[local_index] = local_name;
4622 st_insert(index_lookup_table, (st_data_t) (local_name | PM_SPECIAL_CONSTANT_FLAG), (st_data_t) local_index);
4632pm_compile_destructured_param_locals(
const pm_multi_target_node_t *node, st_table *index_lookup_table, rb_ast_id_table_t *local_table_for_iseq, pm_scope_node_t *scope_node,
int local_index)
4634 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4639 pm_insert_local_index(((
const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4645 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);
4652 if (rest->expression != NULL) {
4656 pm_insert_local_index(((
const pm_required_parameter_node_t *) rest->expression)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4662 for (
size_t index = 0; index < node->
rights.
size; index++) {
4667 pm_insert_local_index(((
const pm_required_parameter_node_t *) right)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4673 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);
4685pm_compile_destructured_param_write(rb_iseq_t *iseq,
const pm_required_parameter_node_t *node, LINK_ANCHOR *
const ret,
const pm_scope_node_t *scope_node)
4687 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4688 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, node->
name, 0);
4689 PUSH_SETLOCAL(ret, location, index.index, index.level);
4701pm_compile_destructured_param_writes(rb_iseq_t *iseq,
const pm_multi_target_node_t *node, LINK_ANCHOR *
const ret,
const pm_scope_node_t *scope_node)
4703 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4707 int flag = (has_rest || has_rights) ? 1 : 0;
4710 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4738 for (
size_t index = 0; index < node->
rights.
size; index++) {
4773} pm_multi_target_state_node_t;
4791 pm_multi_target_state_node_t *head;
4794 pm_multi_target_state_node_t *tail;
4803 pm_multi_target_state_node_t *node =
ALLOC(pm_multi_target_state_node_t);
4805 node->stack_index = state->stack_size + 1;
4806 node->stack_size = stack_size;
4807 node->position = state->position;
4810 if (state->head == NULL) {
4815 state->tail->next = node;
4819 state->stack_size += stack_size;
4832 if (state->stack_size == 0)
return;
4834 pm_multi_target_state_node_t *current = state->head;
4835 pm_multi_target_state_node_t *previous;
4837 while (current != NULL) {
4838 VALUE offset =
INT2FIX(state->stack_size - current->stack_index + current->position);
4839 current->topn->operands[0] = offset;
4845 if (current->stack_size > 1) {
4846 INSN *insn = current->topn;
4848 for (
size_t index = 1; index < current->stack_size; index += 1) {
4849 LINK_ELEMENT *element = get_next_insn(insn);
4852 insn = (INSN *) element;
4855 insn->operands[0] = offset;
4860 current = current->next;
4867pm_compile_multi_target_node(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const parents, LINK_ANCHOR *
const writes, LINK_ANCHOR *
const cleanup, pm_scope_node_t *scope_node,
pm_multi_target_state_t *state);
4898pm_compile_target_node(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const parents, LINK_ANCHOR *
const writes, LINK_ANCHOR *
const cleanup, pm_scope_node_t *scope_node,
pm_multi_target_state_t *state)
4900 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4910 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
4912 PUSH_SETLOCAL(writes, location, index.index, index.level);
4922 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4925 PUSH_INSN2(writes, location, setclassvariable, operand, get_cvar_ic_value(iseq, name));
4935 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4938 PUSH_INSN1(writes, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
4939 PUSH_INSN1(writes, location, setconstant, operand);
4949 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4952 PUSH_INSN1(writes, location, setglobal, operand);
4962 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4965 PUSH_INSN2(writes, location, setinstancevariable, operand, get_ivar_ic_value(iseq, name));
4978 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4980 if (cast->
parent != NULL) {
4981 pm_compile_node(iseq, cast->
parent, parents,
false, scope_node);
4984 PUSH_INSN1(parents, location, putobject, rb_cObject);
4987 if (state == NULL) {
4988 PUSH_INSN(writes, location, swap);
4991 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
4992 pm_multi_target_state_push(state, (INSN *) LAST_ELEMENT(writes), 1);
4996 PUSH_INSN1(writes, location, setconstant, operand);
4998 if (state != NULL) {
4999 PUSH_INSN(cleanup, location, pop);
5014 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
5016 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5018 LABEL *safe_label = NULL;
5020 safe_label = NEW_LABEL(location.
line);
5021 PUSH_INSN(parents, location, dup);
5022 PUSH_INSNL(parents, location, branchnil, safe_label);
5025 if (state != NULL) {
5026 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5027 pm_multi_target_state_push(state, (INSN *) LAST_ELEMENT(writes), 1);
5028 PUSH_INSN(writes, location, swap);
5031 int flags = VM_CALL_ARGS_SIMPLE;
5034 PUSH_SEND_WITH_FLAG(writes, location, method_id,
INT2FIX(1),
INT2FIX(flags));
5035 if (safe_label != NULL && state == NULL) PUSH_LABEL(writes, safe_label);
5036 PUSH_INSN(writes, location, pop);
5037 if (safe_label != NULL && state != NULL) PUSH_LABEL(writes, safe_label);
5039 if (state != NULL) {
5040 PUSH_INSN(cleanup, location, pop);
5057 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5061 int argc = pm_setup_args(cast->
arguments, (
const pm_node_t *) cast->
block, &flags, &kwargs, iseq, parents, scope_node, &location);
5063 if (state != NULL) {
5064 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5065 pm_multi_target_state_push(state, (INSN *) LAST_ELEMENT(writes), argc + 1);
5068 PUSH_INSN(writes, location, swap);
5071 for (
int index = 0; index < argc; index++) {
5072 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5074 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5082 int ci_argc = argc + 1;
5083 if (flags & VM_CALL_ARGS_SPLAT) {
5085 PUSH_INSN1(writes, location, newarray,
INT2FIX(1));
5086 PUSH_INSN(writes, location, concatarray);
5089 PUSH_SEND_R(writes, location, idASET,
INT2NUM(ci_argc), NULL,
INT2FIX(flags), kwargs);
5090 PUSH_INSN(writes, location, pop);
5092 if (state != NULL) {
5094 PUSH_INSN(writes, location, pop);
5097 for (
int index = 0; index < argc + 1; index++) {
5098 PUSH_INSN(cleanup, location, pop);
5111 size_t before_position;
5112 if (state != NULL) {
5113 before_position = state->position;
5117 pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, scope_node, state);
5118 if (state != NULL) state->position = before_position;
5123 rb_bug(
"Unexpected node type: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
5134pm_compile_multi_target_node(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const parents, LINK_ANCHOR *
const writes, LINK_ANCHOR *
const cleanup, pm_scope_node_t *scope_node,
pm_multi_target_state_t *state)
5136 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5144 lefts = &cast->
lefts;
5151 lefts = &cast->
lefts;
5157 rb_bug(
"Unsupported node %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
5162 bool has_posts = rights->
size > 0;
5167 PUSH_INSN2(writes, location, expandarray,
INT2FIX(lefts->
size),
INT2FIX((has_rest || has_posts) ? 1 : 0));
5173 if (state == NULL) state = &target_state;
5175 size_t base_position = state->position;
5176 size_t splat_position = (has_rest || has_posts) ? 1 : 0;
5179 for (
size_t index = 0; index < lefts->
size; index++) {
5181 state->position = lefts->
size - index + splat_position + base_position;
5182 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5188 state->position = 1 + rights->
size + base_position;
5194 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5199 if (!has_rest && rest != NULL) {
5203 for (
size_t index = 0; index < rights->
size; index++) {
5205 state->position = rights->
size - index + base_position;
5206 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5217pm_compile_for_node_index(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const ret, pm_scope_node_t *scope_node)
5219 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5225 PUSH_GETLOCAL(ret, location, 1, 0);
5226 pm_compile_target_node(iseq, node, ret, ret, ret, scope_node, NULL);
5239 DECL_ANCHOR(writes);
5240 DECL_ANCHOR(cleanup);
5244 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
5246 PUSH_GETLOCAL(ret, location, 1, 0);
5249 PUSH_SEQ(ret, writes);
5250 PUSH_SEQ(ret, cleanup);
5252 pm_multi_target_state_update(&state);
5256 DECL_ANCHOR(writes);
5257 DECL_ANCHOR(cleanup);
5259 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, NULL);
5261 LABEL *not_single = NEW_LABEL(location.
line);
5262 LABEL *not_ary = NEW_LABEL(location.
line);
5270 PUSH_GETLOCAL(ret, location, 1, 0);
5271 PUSH_INSN(ret, location, dup);
5272 PUSH_CALL(ret, location, idLength,
INT2FIX(0));
5273 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
5274 PUSH_CALL(ret, location, idEq,
INT2FIX(1));
5275 PUSH_INSNL(ret, location, branchunless, not_single);
5276 PUSH_INSN(ret, location, dup);
5277 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
5278 PUSH_CALL(ret, location, idAREF,
INT2FIX(1));
5279 PUSH_INSN1(ret, location, putobject,
rb_cArray);
5280 PUSH_INSN(ret, location, swap);
5281 PUSH_CALL(ret, location, rb_intern(
"try_convert"),
INT2FIX(1));
5282 PUSH_INSN(ret, location, dup);
5283 PUSH_INSNL(ret, location, branchunless, not_ary);
5284 PUSH_INSN(ret, location, swap);
5286 PUSH_LABEL(ret, not_ary);
5287 PUSH_INSN(ret, location, pop);
5289 PUSH_LABEL(ret, not_single);
5290 PUSH_SEQ(ret, writes);
5291 PUSH_SEQ(ret, cleanup);
5295 rb_bug(
"Unexpected node type for index in for node: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
5301pm_compile_rescue(rb_iseq_t *iseq,
const pm_begin_node_t *cast,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
5305 LABEL *lstart = NEW_LABEL(node_location->
line);
5306 LABEL *lend = NEW_LABEL(node_location->
line);
5307 LABEL *lcont = NEW_LABEL(node_location->
line);
5309 pm_scope_node_t rescue_scope_node;
5312 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
5319 pm_scope_node_destroy(&rescue_scope_node);
5321 lstart->rescued = LABEL_RESCUE_BEG;
5322 lend->rescued = LABEL_RESCUE_END;
5323 PUSH_LABEL(ret, lstart);
5325 bool prev_in_rescue = ISEQ_COMPILE_DATA(iseq)->in_rescue;
5326 ISEQ_COMPILE_DATA(iseq)->in_rescue =
true;
5333 PUSH_INSN(ret, location, putnil);
5336 ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;
5337 PUSH_LABEL(ret, lend);
5340 if (!popped) PUSH_INSN(ret, *node_location, pop);
5344 PUSH_INSN(ret, *node_location, nop);
5345 PUSH_LABEL(ret, lcont);
5347 if (popped) PUSH_INSN(ret, *node_location, pop);
5348 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
5349 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
5353pm_compile_ensure(rb_iseq_t *iseq,
const pm_begin_node_t *cast,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
5359 if (statements != NULL) {
5360 location = PM_NODE_START_LOCATION(parser, statements);
5363 location = *node_location;
5366 LABEL *lstart = NEW_LABEL(location.
line);
5367 LABEL *lend = NEW_LABEL(location.
line);
5368 LABEL *lcont = NEW_LABEL(location.
line);
5375 if (statements != NULL) {
5376 pm_compile_node(iseq, (
const pm_node_t *) statements, ensr,
true, scope_node);
5379 LINK_ELEMENT *last = ensr->last;
5380 bool last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
5385 push_ensure_entry(iseq, &enl, &er, (
void *) cast->
ensure_clause);
5387 PUSH_LABEL(ret, lstart);
5389 pm_compile_rescue(iseq, cast, node_location, ret, popped | last_leave, scope_node);
5392 pm_compile_node(iseq, (
const pm_node_t *) cast->
statements, ret, popped | last_leave, scope_node);
5394 else if (!(popped | last_leave)) {
5395 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
5398 PUSH_LABEL(ret, lend);
5399 PUSH_SEQ(ret, ensr);
5400 if (!popped && last_leave) PUSH_INSN(ret, *node_location, putnil);
5401 PUSH_LABEL(ret, lcont);
5402 if (last_leave) PUSH_INSN(ret, *node_location, pop);
5404 pm_scope_node_t next_scope_node;
5407 rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(
5414 pm_scope_node_destroy(&next_scope_node);
5416 erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
5417 if (lstart->link.next != &lend->link) {
5419 PUSH_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, child_iseq, lcont);
5420 erange = erange->next;
5423 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
5431pm_opt_str_freeze_p(
const rb_iseq_t *iseq,
const pm_call_node_t *node)
5438 node->
block == NULL &&
5439 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5448pm_opt_aref_with_p(
const rb_iseq_t *iseq,
const pm_call_node_t *node)
5456 node->
block == NULL &&
5458 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5467pm_opt_aset_with_p(
const rb_iseq_t *iseq,
const pm_call_node_t *node)
5475 node->
block == NULL &&
5477 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5486pm_compile_constant_read(rb_iseq_t *iseq,
VALUE name,
const pm_location_t *name_loc, uint32_t node_id, LINK_ANCHOR *
const ret,
const pm_scope_node_t *scope_node)
5488 const pm_node_location_t location = PM_LOCATION_START_LOCATION(scope_node->parser, name_loc, node_id);
5490 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
5491 ISEQ_BODY(iseq)->ic_size++;
5492 VALUE segments = rb_ary_new_from_args(1, name);
5493 PUSH_INSN1(ret, location, opt_getconstant_path, segments);
5496 PUSH_INSN(ret, location, putnil);
5497 PUSH_INSN1(ret, location, putobject,
Qtrue);
5498 PUSH_INSN1(ret, location, getconstant, name);
5507pm_constant_path_parts(
const pm_node_t *node,
const pm_scope_node_t *scope_node)
5509 VALUE parts = rb_ary_new();
5517 rb_ary_unshift(parts, name);
5524 rb_ary_unshift(parts, name);
5525 if (cast->
parent == NULL) {
5526 rb_ary_unshift(parts,
ID2SYM(idNULL));
5545pm_compile_constant_path(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const prefix, LINK_ANCHOR *
const body,
bool popped, pm_scope_node_t *scope_node)
5547 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5554 PUSH_INSN1(body, location, putobject,
Qtrue);
5555 PUSH_INSN1(body, location, getconstant, name);
5562 if (cast->
parent == NULL) {
5563 PUSH_INSN(body, location, pop);
5564 PUSH_INSN1(body, location, putobject, rb_cObject);
5565 PUSH_INSN1(body, location, putobject,
Qtrue);
5566 PUSH_INSN1(body, location, getconstant, name);
5569 pm_compile_constant_path(iseq, cast->
parent, prefix, body,
false, scope_node);
5570 PUSH_INSN1(body, location, putobject,
Qfalse);
5571 PUSH_INSN1(body, location, getconstant, name);
5576 PM_COMPILE_INTO_ANCHOR(prefix, node);
5585pm_compile_shareable_constant_literal(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_scope_node_t *scope_node)
5599 return pm_static_literal_value(iseq, node, scope_node);
5601 return parse_static_literal_string(iseq, scope_node, node, &((
const pm_string_node_t *) node)->unescaped);
5608 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5609 VALUE element = pm_compile_shareable_constant_literal(iseq, cast->
elements.
nodes[index], scope_node);
5612 rb_ary_push(result, element);
5621 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5627 VALUE key = pm_compile_shareable_constant_literal(iseq, assoc->
key, scope_node);
5630 VALUE value = pm_compile_shareable_constant_literal(iseq, assoc->
value, scope_node);
5633 rb_hash_aset(result, key, value);
5648pm_compile_shareable_constant_value(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_node_flags_t shareability,
VALUE path, LINK_ANCHOR *
const ret, pm_scope_node_t *scope_node,
bool top)
5650 VALUE literal = pm_compile_shareable_constant_literal(iseq, node, scope_node);
5652 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5653 PUSH_INSN1(ret, location, putobject, literal);
5657 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5663 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5666 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5667 pm_compile_shareable_constant_value(iseq, cast->
elements.
nodes[index], shareability, path, ret, scope_node,
false);
5674 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5683 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5686 pm_compile_hash_elements(iseq, (
const pm_node_t *) cast, &cast->elements, shareability, path,
false, ret, scope_node);
5690 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5696 DECL_ANCHOR(value_seq);
5698 pm_compile_node(iseq, node, value_seq,
false, scope_node);
5700 PUSH_SEND_WITH_FLAG(value_seq, location, idUMinus,
INT2FIX(0),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5704 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5705 PUSH_SEQ(ret, value_seq);
5706 PUSH_INSN1(ret, location, putobject, path);
5707 PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"ensure_shareable"),
INT2FIX(2),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5710 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5711 PUSH_SEQ(ret, value_seq);
5712 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable_copy"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5715 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5716 PUSH_SEQ(ret, value_seq);
5717 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5733 ID name_id = pm_constant_id_lookup(scope_node, node->
name);
5735 if (shareability != 0) {
5736 pm_compile_shareable_constant_value(iseq, node->
value, shareability, rb_id2str(name_id), ret, scope_node,
true);
5739 PM_COMPILE_NOT_POPPED(node->
value);
5742 if (!popped) PUSH_INSN(ret, location, dup);
5743 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5746 PUSH_INSN1(ret, location, setconstant, operand);
5759 LABEL *end_label = NEW_LABEL(location.
line);
5761 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5762 if (!popped) PUSH_INSN(ret, location, dup);
5764 PUSH_INSNL(ret, location, branchunless, end_label);
5765 if (!popped) PUSH_INSN(ret, location, pop);
5767 if (shareability != 0) {
5768 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5771 PM_COMPILE_NOT_POPPED(node->
value);
5774 if (!popped) PUSH_INSN(ret, location, dup);
5775 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5776 PUSH_INSN1(ret, location, setconstant, name);
5777 PUSH_LABEL(ret, end_label);
5790 LABEL *set_label = NEW_LABEL(location.
line);
5791 LABEL *end_label = NEW_LABEL(location.
line);
5793 PUSH_INSN(ret, location, putnil);
5794 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name,
Qtrue);
5795 PUSH_INSNL(ret, location, branchunless, set_label);
5797 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5798 if (!popped) PUSH_INSN(ret, location, dup);
5800 PUSH_INSNL(ret, location, branchif, end_label);
5801 if (!popped) PUSH_INSN(ret, location, pop);
5802 PUSH_LABEL(ret, set_label);
5804 if (shareability != 0) {
5805 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5808 PM_COMPILE_NOT_POPPED(node->
value);
5811 if (!popped) PUSH_INSN(ret, location, dup);
5812 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5813 PUSH_INSN1(ret, location, setconstant, name);
5814 PUSH_LABEL(ret, end_label);
5829 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5831 if (shareability != 0) {
5832 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5835 PM_COMPILE_NOT_POPPED(node->
value);
5838 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5839 if (!popped) PUSH_INSN(ret, location, dup);
5841 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5842 PUSH_INSN1(ret, location, setconstant, name);
5852 VALUE parts = rb_ary_new();
5853 rb_ary_push(parts, rb_id2str(pm_constant_id_lookup(scope_node, node->
name)));
5858 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, cast->
name)));
5862 if (current == NULL) {
5863 rb_ary_unshift(parts, rb_id2str(idNULL));
5866 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, ((
const pm_constant_read_node_t *) current)->name)));
5890 PUSH_INSN1(ret, location, putobject, rb_cObject);
5893 if (shareability != 0) {
5894 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5897 PM_COMPILE_NOT_POPPED(node->
value);
5901 PUSH_INSN(ret, location, swap);
5902 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
5905 PUSH_INSN(ret, location, swap);
5906 PUSH_INSN1(ret, location, setconstant, name);
5920 LABEL *lfin = NEW_LABEL(location.
line);
5923 PM_COMPILE_NOT_POPPED(target->
parent);
5926 PUSH_INSN1(ret, location, putobject, rb_cObject);
5929 PUSH_INSN(ret, location, dup);
5930 PUSH_INSN1(ret, location, putobject,
Qtrue);
5931 PUSH_INSN1(ret, location, getconstant, name);
5933 if (!popped) PUSH_INSN(ret, location, dup);
5934 PUSH_INSNL(ret, location, branchunless, lfin);
5936 if (!popped) PUSH_INSN(ret, location, pop);
5938 if (shareability != 0) {
5939 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5942 PM_COMPILE_NOT_POPPED(node->
value);
5946 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
5949 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
5950 PUSH_INSN(ret, location, swap);
5953 PUSH_INSN1(ret, location, setconstant, name);
5954 PUSH_LABEL(ret, lfin);
5956 if (!popped) PUSH_INSN(ret, location, swap);
5957 PUSH_INSN(ret, location, pop);
5971 LABEL *lassign = NEW_LABEL(location.
line);
5972 LABEL *lfin = NEW_LABEL(location.
line);
5975 PM_COMPILE_NOT_POPPED(target->
parent);
5978 PUSH_INSN1(ret, location, putobject, rb_cObject);
5981 PUSH_INSN(ret, location, dup);
5982 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name,
Qtrue);
5983 PUSH_INSNL(ret, location, branchunless, lassign);
5985 PUSH_INSN(ret, location, dup);
5986 PUSH_INSN1(ret, location, putobject,
Qtrue);
5987 PUSH_INSN1(ret, location, getconstant, name);
5989 if (!popped) PUSH_INSN(ret, location, dup);
5990 PUSH_INSNL(ret, location, branchif, lfin);
5992 if (!popped) PUSH_INSN(ret, location, pop);
5993 PUSH_LABEL(ret, lassign);
5995 if (shareability != 0) {
5996 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5999 PM_COMPILE_NOT_POPPED(node->
value);
6003 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6006 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6007 PUSH_INSN(ret, location, swap);
6010 PUSH_INSN1(ret, location, setconstant, name);
6011 PUSH_LABEL(ret, lfin);
6013 if (!popped) PUSH_INSN(ret, location, swap);
6014 PUSH_INSN(ret, location, pop);
6031 PM_COMPILE_NOT_POPPED(target->
parent);
6034 PUSH_INSN1(ret, location, putobject, rb_cObject);
6037 PUSH_INSN(ret, location, dup);
6038 PUSH_INSN1(ret, location, putobject,
Qtrue);
6039 PUSH_INSN1(ret, location, getconstant, name);
6041 if (shareability != 0) {
6042 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6045 PM_COMPILE_NOT_POPPED(node->
value);
6048 PUSH_CALL(ret, location, method_id,
INT2FIX(1));
6049 PUSH_INSN(ret, location, swap);
6052 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6053 PUSH_INSN(ret, location, swap);
6056 PUSH_INSN1(ret, location, setconstant, name);
6065#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))
6072pm_compile_scope_node(rb_iseq_t *iseq, pm_scope_node_t *scope_node,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped)
6084 bool trailing_comma =
false;
6090 if (scope_node->parameters != NULL) {
6094 parameters_node = cast->parameters;
6095 block_locals = &cast->locals;
6097 if (parameters_node) {
6099 trailing_comma =
true;
6110 body->
param.lead_num = maximum;
6111 body->
param.flags.ambiguous_param0 = maximum == 1;
6115 body->
param.lead_num = 1;
6116 body->
param.flags.ambiguous_param0 =
true;
6119 rb_bug(
"Unexpected node type for parameters: %s", pm_node_type_to_str(
PM_NODE_TYPE(scope_node->parameters)));
6123 struct rb_iseq_param_keyword *keyword = NULL;
6125 if (parameters_node) {
6126 optionals_list = ¶meters_node->
optionals;
6127 requireds_list = ¶meters_node->
requireds;
6128 keywords_list = ¶meters_node->
keywords;
6129 posts_list = ¶meters_node->
posts;
6132 body->
param.opt_num = 0;
6135 body->
param.lead_num = 0;
6136 body->
param.opt_num = 0;
6142 size_t locals_size = locals->
size;
6145 st_table *index_lookup_table = st_init_numtable();
6147 int table_size = (int) locals_size;
6153 if (keywords_list && keywords_list->
size) {
6157 if (requireds_list) {
6158 for (
size_t i = 0; i < requireds_list->
size; i++) {
6184 if (optionals_list && optionals_list->
size) {
6185 for (
size_t i = 0; i < optionals_list->
size; i++) {
6197 if (parameters_node) {
6198 if (parameters_node->
rest) {
6215 if (requireds_list->
size == 0 && optionals_list->
size == 0 && keywords_list->
size == 0) {
6216 ISEQ_BODY(iseq)->param.flags.use_block = TRUE;
6217 ISEQ_BODY(iseq)->param.flags.forwardable = TRUE;
6236 for (
size_t i = 0; i < posts_list->
size; i++) {
6247 if (keywords_list && keywords_list->
size) {
6248 for (
size_t i = 0; i < keywords_list->
size; i++) {
6256 if (parameters_node && parameters_node->
block) {
6266 rb_ast_id_table_t *local_table_for_iseq =
ALLOCV(idtmp,
sizeof(rb_ast_id_table_t) + table_size *
sizeof(
ID));
6267 local_table_for_iseq->size = table_size;
6287 int local_index = 0;
6294 if (requireds_list && requireds_list->
size) {
6295 for (
size_t i = 0; i < requireds_list->
size; i++, local_index++) {
6307 local = rb_make_temporary_id(local_index);
6308 local_table_for_iseq->ids[local_index] = local;
6317 ID local = pm_constant_id_lookup(scope_node, param->
name);
6318 local_table_for_iseq->ids[local_index] = local;
6321 pm_insert_local_index(param->
name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6327 rb_bug(
"Unsupported node in requireds in parameters %s", pm_node_type_to_str(
PM_NODE_TYPE(required)));
6331 body->
param.lead_num = (int) requireds_list->
size;
6332 body->
param.flags.has_lead =
true;
6336 ID local = rb_make_temporary_id(local_index);
6337 local_table_for_iseq->ids[local_index++] = local;
6342 if (optionals_list && optionals_list->
size) {
6343 body->
param.opt_num = (int) optionals_list->
size;
6344 body->
param.flags.has_opt =
true;
6346 for (
size_t i = 0; i < optionals_list->
size; i++, local_index++) {
6351 ID local = pm_constant_id_lookup(scope_node, name);
6352 local_table_for_iseq->ids[local_index] = local;
6355 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6362 if (parameters_node && parameters_node->
rest) {
6363 body->
param.rest_start = local_index;
6368 body->
param.flags.has_rest =
true;
6377 ID local = pm_constant_id_lookup(scope_node, name);
6378 local_table_for_iseq->ids[local_index] = local;
6381 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6387 body->
param.flags.anon_rest =
true;
6388 pm_insert_local_special(idMULT, local_index, index_lookup_table, local_table_for_iseq);
6397 if (posts_list && posts_list->
size) {
6398 body->
param.post_num = (int) posts_list->
size;
6399 body->
param.post_start = local_index;
6400 body->
param.flags.has_post =
true;
6402 for (
size_t i = 0; i < posts_list->
size; i++, local_index++) {
6414 local = rb_make_temporary_id(local_index);
6415 local_table_for_iseq->ids[local_index] = local;
6424 ID local = pm_constant_id_lookup(scope_node, param->
name);
6425 local_table_for_iseq->ids[local_index] = local;
6428 pm_insert_local_index(param->
name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6433 rb_bug(
"Unsupported node in posts in parameters %s", pm_node_type_to_str(
PM_NODE_TYPE(post_node)));
6441 if (keywords_list && keywords_list->
size) {
6442 keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6443 keyword->num = (int) keywords_list->
size;
6445 const VALUE default_values = rb_ary_hidden_new(1);
6448 for (
size_t i = 0; i < keywords_list->
size; i++) {
6456 keyword->required_num++;
6457 ID local = pm_constant_id_lookup(scope_node, name);
6460 local_table_for_iseq->ids[local_index] = local;
6463 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6469 for (
size_t i = 0; i < keywords_list->
size; i++) {
6481 if (
PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) {
6482 rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node));
6485 rb_ary_push(default_values, complex_mark);
6488 ID local = pm_constant_id_lookup(scope_node, name);
6490 local_table_for_iseq->ids[local_index] = local;
6493 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6503 for (
int i = 0; i <
RARRAY_LEN(default_values); i++) {
6505 if (dv == complex_mark) dv =
Qundef;
6509 keyword->default_values = dvs;
6513 keyword->bits_start = local_index;
6514 ID local = rb_make_temporary_id(local_index);
6515 local_table_for_iseq->ids[local_index] = local;
6518 body->
param.keyword = keyword;
6519 body->
param.flags.has_kw =
true;
6522 if (body->type == ISEQ_TYPE_BLOCK && local_index == 1 && requireds_list && requireds_list->
size == 1 && !trailing_comma) {
6523 body->
param.flags.ambiguous_param0 =
true;
6526 if (parameters_node) {
6534 body->
param.flags.accepts_no_kwarg =
true;
6541 if (!body->
param.flags.has_kw) {
6542 body->
param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6545 keyword->rest_start = local_index;
6546 body->
param.flags.has_kwrest =
true;
6551 ID local = pm_constant_id_lookup(scope_node, constant_id);
6552 local_table_for_iseq->ids[local_index] = local;
6555 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6559 body->
param.flags.anon_kwrest =
true;
6560 pm_insert_local_special(idPow, local_index, index_lookup_table, local_table_for_iseq);
6569 if (!ISEQ_BODY(iseq)->param.
flags.forwardable) {
6571 body->
param.rest_start = local_index;
6572 body->
param.flags.has_rest =
true;
6573 body->
param.flags.anon_rest =
true;
6574 pm_insert_local_special(idMULT, local_index++, index_lookup_table, local_table_for_iseq);
6578 body->
param.flags.has_kw =
false;
6579 body->
param.flags.has_kwrest =
true;
6580 body->
param.flags.anon_kwrest =
true;
6581 body->
param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6582 keyword->rest_start = local_index;
6583 pm_insert_local_special(idPow, local_index++, index_lookup_table, local_table_for_iseq);
6586 body->
param.block_start = local_index;
6587 body->
param.flags.has_block =
true;
6588 pm_insert_local_special(idAnd, local_index++, index_lookup_table, local_table_for_iseq);
6592 pm_insert_local_special(idDot3, local_index++, index_lookup_table, local_table_for_iseq);
6596 rb_bug(
"node type %s not expected as keyword_rest", pm_node_type_to_str(
PM_NODE_TYPE(parameters_node->
keyword_rest)));
6602 if (parameters_node->
block) {
6603 body->
param.block_start = local_index;
6604 body->
param.flags.has_block =
true;
6605 iseq_set_use_block(iseq);
6611 ID local = pm_constant_id_lookup(scope_node, name);
6612 local_table_for_iseq->ids[local_index] = local;
6615 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6619 pm_insert_local_special(idAnd, local_index, index_lookup_table, local_table_for_iseq);
6638 if (requireds_list && requireds_list->
size) {
6639 for (
size_t i = 0; i < requireds_list->
size; i++) {
6646 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);
6652 if (posts_list && posts_list->
size) {
6653 for (
size_t i = 0; i < posts_list->
size; i++) {
6660 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);
6668 body->
param.lead_num++;
6671 body->
param.rest_start = local_index;
6672 body->
param.flags.has_rest =
true;
6675 ID local = rb_make_temporary_id(local_index);
6676 local_table_for_iseq->ids[local_index] = local;
6684 for (
int i = 0; i < maximum; i++, local_index++) {
6685 const uint8_t param_name[] = {
'_',
'1' + i };
6687 RUBY_ASSERT(constant_id &&
"parser should fill in any gaps in numbered parameters");
6688 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6690 body->
param.lead_num = maximum;
6691 body->
param.flags.has_lead =
true;
6702 if (block_locals && block_locals->
size) {
6703 for (
size_t i = 0; i < block_locals->
size; i++, local_index++) {
6705 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6710 if (scope_node->locals.
size) {
6711 for (
size_t i = 0; i < scope_node->locals.
size; i++) {
6715 ctx.scope_node = scope_node;
6716 ctx.local_table_for_iseq = local_table_for_iseq;
6717 ctx.local_index = local_index;
6719 st_update(index_lookup_table, (st_data_t)constant_id, pm_local_table_insert_func, (st_data_t)&ctx);
6721 local_index = ctx.local_index;
6730 if (scope_node->index_lookup_table) {
6731 st_free_table(scope_node->index_lookup_table);
6733 scope_node->index_lookup_table = index_lookup_table;
6734 iseq_calc_param_size(iseq);
6736 if (ISEQ_BODY(iseq)->param.
flags.forwardable) {
6739 ISEQ_BODY(iseq)->param.size += 1;
6743 iseq_set_local_table(iseq, local_table_for_iseq, 0);
6744 scope_node->local_table_for_iseq_size = local_table_for_iseq->size;
6746 if (keyword != NULL) {
6747 size_t keyword_start_index = keyword->bits_start - keyword->num;
6748 keyword->table = (
ID *)&ISEQ_BODY(iseq)->local_table[keyword_start_index];
6753 if (optionals_list && optionals_list->
size) {
6761 for (
size_t i = 0; i < optionals_list->
size; i++) {
6762 label = NEW_LABEL(location.
line);
6763 opt_table[i] = label;
6764 PUSH_LABEL(ret, label);
6766 PM_COMPILE_NOT_POPPED(optional_node);
6770 label = NEW_LABEL(location.
line);
6771 opt_table[optionals_list->
size] = label;
6772 PUSH_LABEL(ret, label);
6774 body->
param.opt_table = (
const VALUE *) opt_table;
6777 if (keywords_list && keywords_list->
size) {
6778 size_t optional_index = 0;
6779 for (
size_t i = 0; i < keywords_list->
size; i++) {
6792 if (!
PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) {
6793 LABEL *end_label = NEW_LABEL(location.
line);
6795 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, name, 0);
6796 int kw_bits_idx = table_size - body->
param.keyword->bits_start;
6797 PUSH_INSN2(ret, location, checkkeyword,
INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1),
INT2FIX(optional_index));
6798 PUSH_INSNL(ret, location, branchif, end_label);
6800 PUSH_SETLOCAL(ret, location, index.index, index.level);
6801 PUSH_LABEL(ret, end_label);
6811 rb_bug(
"Unexpected keyword parameter node type %s", pm_node_type_to_str(
PM_NODE_TYPE(keyword_parameter_node)));
6816 if (requireds_list && requireds_list->
size) {
6817 for (
size_t i = 0; i < requireds_list->
size; i++) {
6824 PUSH_GETLOCAL(ret, location, table_size - (
int)i, 0);
6830 if (posts_list && posts_list->
size) {
6831 for (
size_t i = 0; i < posts_list->
size; i++) {
6838 PUSH_GETLOCAL(ret, location, table_size - body->
param.post_start - (
int) i, 0);
6844 switch (body->type) {
6845 case ISEQ_TYPE_PLAIN: {
6849 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
6853 case ISEQ_TYPE_BLOCK: {
6854 LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
6855 LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
6856 const pm_node_location_t block_location = { .line = body->location.first_lineno, .node_id = scope_node->ast_node->
node_id };
6858 start->rescued = LABEL_RESCUE_BEG;
6859 end->rescued = LABEL_RESCUE_END;
6866 pm_compile_for_node_index(iseq, ((
const pm_for_node_t *) scope_node->ast_node)->index, ret, scope_node);
6870 PUSH_INSN(ret, block_location, nop);
6871 PUSH_LABEL(ret, start);
6873 if (scope_node->body != NULL) {
6877 PUSH_INSN1(ret, block_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
6880 pm_scope_node_t next_scope_node;
6881 pm_scope_node_init((
const pm_node_t *) cast->statements, &next_scope_node, scope_node);
6883 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(body->parent_iseq), ISEQ_TYPE_BLOCK, location.
line);
6884 pm_scope_node_destroy(&next_scope_node);
6886 PUSH_CALL_WITH_BLOCK(ret, block_location, id_core_set_postexe,
INT2FIX(0), block);
6891 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
6895 pm_compile_node(iseq, scope_node->body, ret, popped, scope_node);
6900 PUSH_INSN(ret, block_location, putnil);
6903 PUSH_LABEL(ret, end);
6905 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
6908 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
6909 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
6912 case ISEQ_TYPE_ENSURE: {
6913 const pm_node_location_t statements_location = (scope_node->body != NULL ? PM_NODE_START_LOCATION(scope_node->parser, scope_node->body) : location);
6914 iseq_set_exception_local_table(iseq);
6916 if (scope_node->body != NULL) {
6917 PM_COMPILE_POPPED((
const pm_node_t *) scope_node->body);
6920 PUSH_GETLOCAL(ret, statements_location, 1, 0);
6921 PUSH_INSN1(ret, statements_location,
throw,
INT2FIX(0));
6924 case ISEQ_TYPE_METHOD: {
6925 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
6928 if (scope_node->body) {
6929 PM_COMPILE((
const pm_node_t *) scope_node->body);
6932 PUSH_INSN(ret, location, putnil);
6935 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
6938 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
6941 case ISEQ_TYPE_RESCUE: {
6942 iseq_set_exception_local_table(iseq);
6944 LABEL *lab = NEW_LABEL(location.
line);
6945 LABEL *rescue_end = NEW_LABEL(location.
line);
6946 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
6948 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
6949 PUSH_INSNL(ret, location, branchif, lab);
6950 PUSH_INSNL(ret, location, jump, rescue_end);
6951 PUSH_LABEL(ret, lab);
6953 PM_COMPILE((
const pm_node_t *) scope_node->body);
6954 PUSH_INSN(ret, location, leave);
6955 PUSH_LABEL(ret, rescue_end);
6956 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
6959 PM_COMPILE((
const pm_node_t *) scope_node->ast_node);
6961 PUSH_INSN1(ret, location,
throw,
INT2FIX(0));
6966 if (scope_node->body) {
6967 PM_COMPILE((
const pm_node_t *) scope_node->body);
6970 PUSH_INSN(ret, location, putnil);
6976 const pm_node_location_t end_location = PM_NODE_END_LOCATION(scope_node->parser, scope_node->ast_node);
6978 ISEQ_COMPILE_DATA(iseq)->last_line = end_location.
line;
6982 const pm_node_location_t location = { .line = ISEQ_COMPILE_DATA(iseq)->last_line, .node_id = scope_node->ast_node->
node_id };
6983 PUSH_INSN(ret, location, leave);
6992 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
6996 VALUE operand =
ID2SYM(rb_intern3((
const char *) name_loc->
start, name_loc->
end - name_loc->
start, scope_node->encoding));
6997 PUSH_INSN1(ret, *location, putobject, operand);
7002 VALUE operand =
ID2SYM(rb_intern3((
const char *) name_loc->
start, name_loc->
end - name_loc->
start, scope_node->encoding));
7003 PUSH_INSN1(ret, *location, putobject, operand);
7006 PUSH_SEND(ret, *location, id_core_set_variable_alias,
INT2FIX(2));
7007 if (popped) PUSH_INSN(ret, *location, pop);
7013 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7014 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
7015 PM_COMPILE_NOT_POPPED(node->
new_name);
7016 PM_COMPILE_NOT_POPPED(node->
old_name);
7018 PUSH_SEND(ret, *location, id_core_set_method_alias,
INT2FIX(3));
7019 if (popped) PUSH_INSN(ret, *location, pop);
7023pm_compile_and_node(rb_iseq_t *iseq,
const pm_and_node_t *node,
const pm_node_location_t *location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
7025 LABEL *end_label = NEW_LABEL(location->
line);
7027 PM_COMPILE_NOT_POPPED(node->
left);
7028 if (!popped) PUSH_INSN(ret, *location, dup);
7029 PUSH_INSNL(ret, *location, branchunless, end_label);
7031 if (!popped) PUSH_INSN(ret, *location, pop);
7032 PM_COMPILE(node->
right);
7033 PUSH_LABEL(ret, end_label);
7046 if (elements->
size) {
7047 VALUE value = pm_static_literal_value(iseq, node, scope_node);
7048 PUSH_INSN1(ret, *location, duparray, value);
7051 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7069 const int max_new_array_size = 0x100;
7070 const unsigned int min_tmp_array_size = 0x40;
7072 int new_array_size = 0;
7073 bool first_chunk =
true;
7079 bool static_literal =
false;
7082#define FLUSH_CHUNK \
7083 if (new_array_size) { \
7084 if (first_chunk) PUSH_INSN1(ret, *location, newarray, INT2FIX(new_array_size)); \
7085 else PUSH_INSN1(ret, *location, pushtoarray, INT2FIX(new_array_size)); \
7086 first_chunk = false; \
7087 new_array_size = 0; \
7090 for (
size_t index = 0; index < elements->
size; index++) {
7098 PM_COMPILE_NOT_POPPED(splat_element->
expression);
7101 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
7102 PUSH_GETLOCAL(ret, *location, index.index, index.level);
7108 PUSH_INSN1(ret, *location, splatarray,
Qtrue);
7109 first_chunk =
false;
7112 PUSH_INSN(ret, *location, concattoarray);
7115 static_literal =
false;
7118 if (new_array_size == 0 && first_chunk) {
7119 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7120 first_chunk =
false;
7137 pm_compile_hash_elements(iseq, element, &keyword_hash->
elements, 0,
Qundef,
false, ret, scope_node);
7147 PUSH_INSN(ret, *location, pushtoarraykwsplat);
7155 !PM_CONTAINER_P(element) &&
7157 ((index + min_tmp_array_size) < elements->
size)
7162 size_t right_index = index + 1;
7164 right_index < elements->size &&
7166 !PM_CONTAINER_P(elements->
nodes[right_index])
7169 size_t tmp_array_size = right_index - index;
7170 if (tmp_array_size >= min_tmp_array_size) {
7171 VALUE tmp_array = rb_ary_hidden_new(tmp_array_size);
7174 for (; tmp_array_size; tmp_array_size--)
7175 rb_ary_push(tmp_array, pm_static_literal_value(iseq, elements->
nodes[index++], scope_node));
7183 PUSH_INSN1(ret, *location, duparray, tmp_array);
7184 first_chunk =
false;
7187 PUSH_INSN1(ret, *location, putobject, tmp_array);
7188 PUSH_INSN(ret, *location, concattoarray);
7192 PM_COMPILE_NOT_POPPED(element);
7193 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7194 static_literal =
true;
7197 PM_COMPILE_NOT_POPPED(element);
7198 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7199 static_literal =
false;
7204 if (popped) PUSH_INSN(ret, *location, pop);
7210pm_compile_break_node(rb_iseq_t *iseq,
const pm_break_node_t *node,
const pm_node_location_t *location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
7212 unsigned long throw_flag = 0;
7214 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
7216 LABEL *splabel = NEW_LABEL(0);
7217 PUSH_LABEL(ret, splabel);
7218 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7224 PUSH_INSN(ret, *location, putnil);
7227 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7228 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
7229 PUSH_ADJUST_RESTORE(ret, splabel);
7230 if (!popped) PUSH_INSN(ret, *location, putnil);
7233 const rb_iseq_t *ip = iseq;
7236 if (!ISEQ_COMPILE_DATA(ip)) {
7241 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7242 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
7244 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
7247 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
7248 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7252 ip = ISEQ_BODY(ip)->parent_iseq;
7261 PUSH_INSN(ret, *location, putnil);
7264 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_BREAK));
7265 if (popped) PUSH_INSN(ret, *location, pop);
7270 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7275pm_compile_call_node(rb_iseq_t *iseq,
const pm_call_node_t *node, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
7277 ID method_id = pm_constant_id_lookup(scope_node, node->
name);
7283 const char *builtin_func;
7285 if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && (builtin_func = pm_iseq_builtin_function_name(scope_node, node->
receiver, method_id)) != NULL) {
7286 pm_compile_builtin_function_call(iseq, ret, scope_node, node, &location, popped, ISEQ_COMPILE_DATA(iseq)->current_block, builtin_func);
7290 LABEL *start = NEW_LABEL(location.
line);
7291 if (node->
block) PUSH_LABEL(ret, start);
7293 switch (method_id) {
7295 if (pm_opt_str_freeze_p(iseq, node)) {
7297 const struct rb_callinfo *callinfo = new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE);
7298 PUSH_INSN2(ret, location, opt_str_uminus, value, callinfo);
7299 if (popped) PUSH_INSN(ret, location, pop);
7305 if (pm_opt_str_freeze_p(iseq, node)) {
7307 const struct rb_callinfo *callinfo = new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE);
7308 PUSH_INSN2(ret, location, opt_str_freeze, value, callinfo);
7309 if (popped) PUSH_INSN(ret, location, pop);
7315 if (pm_opt_aref_with_p(iseq, node)) {
7317 VALUE value = parse_static_literal_string(iseq, scope_node, (
const pm_node_t *)
string, &string->unescaped);
7319 PM_COMPILE_NOT_POPPED(node->
receiver);
7321 const struct rb_callinfo *callinfo = new_callinfo(iseq, idAREF, 1, 0, NULL, FALSE);
7322 PUSH_INSN2(ret, location, opt_aref_with, value, callinfo);
7325 PUSH_INSN(ret, location, pop);
7333 if (pm_opt_aset_with_p(iseq, node)) {
7335 VALUE value = parse_static_literal_string(iseq, scope_node, (
const pm_node_t *)
string, &string->unescaped);
7337 PM_COMPILE_NOT_POPPED(node->
receiver);
7341 PUSH_INSN(ret, location, swap);
7342 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
7345 const struct rb_callinfo *callinfo = new_callinfo(iseq, idASET, 2, 0, NULL, FALSE);
7346 PUSH_INSN2(ret, location, opt_aset_with, value, callinfo);
7347 PUSH_INSN(ret, location, pop);
7355 PUSH_INSN(ret, location, putnil);
7359 PUSH_INSN(ret, location, putself);
7367 if (iseq_block_param_id_p(iseq, pm_constant_id_lookup(scope_node, read_node_cast->name), &idx, &level)) {
7368 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)));
7371 PM_COMPILE_NOT_POPPED(node->
receiver);
7375 PM_COMPILE_NOT_POPPED(node->
receiver);
7379 pm_compile_call(iseq, node, ret, popped, scope_node, method_id, start);
7389 flag = VM_CALL_FCALL;
7392 PM_COMPILE_NOT_POPPED(node->
receiver);
7394 LABEL *safe_label = NULL;
7396 safe_label = NEW_LABEL(location->
line);
7397 PUSH_INSN(ret, *location, dup);
7398 PUSH_INSNL(ret, *location, branchnil, safe_label);
7401 PUSH_INSN(ret, *location, dup);
7403 ID id_read_name = pm_constant_id_lookup(scope_node, node->
read_name);
7404 PUSH_SEND_WITH_FLAG(ret, *location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
7406 PM_COMPILE_NOT_POPPED(node->
value);
7408 PUSH_SEND(ret, *location, id_operator,
INT2FIX(1));
7411 PUSH_INSN(ret, *location, swap);
7412 PUSH_INSN1(ret, *location, topn,
INT2FIX(1));
7415 ID id_write_name = pm_constant_id_lookup(scope_node, node->
write_name);
7416 PUSH_SEND_WITH_FLAG(ret, *location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
7418 if (safe_label != NULL && popped) PUSH_LABEL(ret, safe_label);
7419 PUSH_INSN(ret, *location, pop);
7420 if (safe_label != NULL && !popped) PUSH_LABEL(ret, safe_label);
7440pm_compile_case_node_dispatch(rb_iseq_t *iseq,
VALUE dispatch,
const pm_node_t *node, LABEL *label,
const pm_scope_node_t *scope_node)
7446 key = pm_static_literal_value(iseq, node, scope_node);
7450 key = (
FIXABLE(intptr) ?
LONG2FIX((
long) intptr) : rb_dbl2big(intptr));
7462 key = pm_static_literal_value(iseq, node, scope_node);
7466 key = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
7473 if (
NIL_P(rb_hash_lookup(dispatch, key))) {
7474 rb_hash_aset(dispatch, key, ((
VALUE) label) | 1);
7484pm_compile_case_node(rb_iseq_t *iseq,
const pm_case_node_t *cast,
const pm_node_location_t *node_location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
7493 DECL_ANCHOR(cond_seq);
7498 DECL_ANCHOR(body_seq);
7502 LABEL *end_label = NEW_LABEL(location.
line);
7510 rb_code_location_t case_location = { 0 };
7513 if (PM_BRANCH_COVERAGE_P(iseq)) {
7514 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7515 branches = decl_branch_base(iseq, PTR2NUM(cast), &case_location,
"case");
7521 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7525 int clause_lineno = pm_node_line_number(parser, (
const pm_node_t *) clause);
7526 LABEL *label = NEW_LABEL(clause_lineno);
7527 PUSH_LABEL(body_seq, label);
7530 if (PM_BRANCH_COVERAGE_P(iseq)) {
7531 rb_code_location_t branch_location = pm_code_location(scope_node, clause->statements != NULL ? ((
const pm_node_t *) clause->statements) : ((
const pm_node_t *) clause));
7532 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7535 if (clause->statements != NULL) {
7536 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7539 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7542 PUSH_INSNL(body_seq, location, jump, end_label);
7547 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7552 PUSH_INSN(cond_seq, cond_location, putnil);
7553 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7554 PUSH_INSN1(cond_seq, cond_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
7555 PUSH_INSNL(cond_seq, cond_location, branchif, label);
7558 LABEL *next_label = NEW_LABEL(pm_node_line_number(parser, condition));
7559 pm_compile_branch_condition(iseq, cond_seq, condition, label, next_label,
false, scope_node);
7560 PUSH_LABEL(cond_seq, next_label);
7567 if (PM_BRANCH_COVERAGE_P(iseq)) {
7568 rb_code_location_t branch_location;
7571 branch_location = case_location;
7578 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7586 PUSH_SYNTHETIC_PUTNIL(cond_seq, iseq);
7591 PUSH_INSNL(cond_seq, location, jump, end_label);
7592 PUSH_SEQ(ret, cond_seq);
7597 rb_code_location_t case_location = { 0 };
7600 if (PM_BRANCH_COVERAGE_P(iseq)) {
7601 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7602 branches = decl_branch_base(iseq, PTR2NUM(cast), &case_location,
"case");
7607 LABEL *else_label = NEW_LABEL(location.
line);
7615 if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
7616 dispatch = rb_hash_new();
7617 RHASH_TBL_RAW(dispatch)->type = &cdhash_type;
7628 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7633 LABEL *label = NEW_LABEL(clause_location.
line);
7638 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7640 const pm_node_location_t condition_location = PM_NODE_START_LOCATION(parser, condition);
7645 if (dispatch !=
Qundef) {
7646 dispatch = pm_compile_case_node_dispatch(iseq, dispatch, condition, label, scope_node);
7650 PUSH_INSN(cond_seq, condition_location, dup);
7651 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7652 PUSH_INSN1(cond_seq, condition_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
7657 VALUE value = parse_static_literal_string(iseq, scope_node, condition, &string->
unescaped);
7658 PUSH_INSN1(cond_seq, condition_location, putobject, value);
7661 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7664 PUSH_INSN1(cond_seq, condition_location, topn,
INT2FIX(1));
7665 PUSH_SEND_WITH_FLAG(cond_seq, condition_location, idEqq,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
7668 PUSH_INSNL(cond_seq, condition_location, branchif, label);
7675 PUSH_LABEL(body_seq, label);
7676 PUSH_INSN(body_seq, clause_location, pop);
7679 if (PM_BRANCH_COVERAGE_P(iseq)) {
7680 rb_code_location_t branch_location = pm_code_location(scope_node, clause->statements != NULL ? ((
const pm_node_t *) clause->statements) : ((
const pm_node_t *) clause));
7681 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7684 if (clause->statements != NULL) {
7685 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7688 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7691 PUSH_INSNL(body_seq, clause_location, jump, end_label);
7702 if (dispatch !=
Qundef) {
7703 PUSH_INSN(ret, location, dup);
7704 PUSH_INSN2(ret, location, opt_case_dispatch, dispatch, else_label);
7705 LABEL_REF(else_label);
7708 PUSH_SEQ(ret, cond_seq);
7712 PUSH_LABEL(ret, else_label);
7716 PUSH_INSN(ret, else_location, pop);
7719 if (PM_BRANCH_COVERAGE_P(iseq)) {
7721 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7725 PUSH_INSNL(ret, else_location, jump, end_label);
7728 PUSH_INSN(ret, location, pop);
7731 if (PM_BRANCH_COVERAGE_P(iseq)) {
7732 add_trace_branch_coverage(iseq, ret, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7735 if (!popped) PUSH_INSN(ret, location, putnil);
7736 PUSH_INSNL(ret, location, jump, end_label);
7740 PUSH_SEQ(ret, body_seq);
7741 PUSH_LABEL(ret, end_label);
7750 DECL_ANCHOR(body_seq);
7755 DECL_ANCHOR(cond_seq);
7759 LABEL *end_label = NEW_LABEL(location->
line);
7764 LABEL *else_label = NEW_LABEL(location->
line);
7768 rb_code_location_t case_location = { 0 };
7772 if (PM_BRANCH_COVERAGE_P(iseq)) {
7773 case_location = pm_code_location(scope_node, (
const pm_node_t *) node);
7774 branches = decl_branch_base(iseq, PTR2NUM(node), &case_location,
"case");
7784 if (in_single_pattern) {
7785 PUSH_INSN(ret, *location, putnil);
7786 PUSH_INSN(ret, *location, putnil);
7787 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7788 PUSH_INSN(ret, *location, putnil);
7792 PUSH_INSN(ret, *location, putnil);
7804 const pm_node_location_t in_location = PM_NODE_START_LOCATION(scope_node->parser, in_node);
7808 PUSH_INSN(body_seq, in_location, putnil);
7811 LABEL *body_label = NEW_LABEL(in_location.
line);
7812 PUSH_LABEL(body_seq, body_label);
7813 PUSH_INSN1(body_seq, in_location, adjuststack,
INT2FIX(in_single_pattern ? 6 : 2));
7816 if (PM_BRANCH_COVERAGE_P(iseq)) {
7818 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"in", branches);
7825 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7828 PUSH_INSNL(body_seq, in_location, jump, end_label);
7829 LABEL *next_pattern_label = NEW_LABEL(pattern_location.
line);
7831 PUSH_INSN(cond_seq, pattern_location, dup);
7832 pm_compile_pattern(iseq, scope_node, in_node->
pattern, cond_seq, body_label, next_pattern_label, in_single_pattern,
false,
true, 2);
7833 PUSH_LABEL(cond_seq, next_pattern_label);
7834 LABEL_UNREMOVABLE(next_pattern_label);
7843 PUSH_LABEL(cond_seq, else_label);
7844 PUSH_INSN(cond_seq, *location, pop);
7845 PUSH_INSN(cond_seq, *location, pop);
7848 if (PM_BRANCH_COVERAGE_P(iseq)) {
7850 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7853 PM_COMPILE_INTO_ANCHOR(cond_seq, (
const pm_node_t *) else_node);
7854 PUSH_INSNL(cond_seq, *location, jump, end_label);
7855 PUSH_INSN(cond_seq, *location, putnil);
7856 if (popped) PUSH_INSN(cond_seq, *location, putnil);
7861 PUSH_LABEL(cond_seq, else_label);
7864 add_trace_branch_coverage(iseq, cond_seq, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7866 if (in_single_pattern) {
7867 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, cond_seq, end_label, popped);
7870 PUSH_INSN1(cond_seq, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7872 PUSH_INSN1(cond_seq, *location, topn,
INT2FIX(2));
7873 PUSH_SEND(cond_seq, *location, id_core_raise,
INT2FIX(2));
7875 PUSH_INSN1(cond_seq, *location, adjuststack,
INT2FIX(3));
7876 if (!popped) PUSH_INSN(cond_seq, *location, putnil);
7877 PUSH_INSNL(cond_seq, *location, jump, end_label);
7878 PUSH_INSN1(cond_seq, *location, dupn,
INT2FIX(1));
7879 if (popped) PUSH_INSN(cond_seq, *location, putnil);
7886 PUSH_SEQ(ret, cond_seq);
7887 PUSH_SEQ(ret, body_seq);
7888 PUSH_LABEL(ret, end_label);
7894 const rb_iseq_t *block = NULL;
7895 const rb_iseq_t *previous_block = NULL;
7896 LABEL *retry_label = NULL;
7897 LABEL *retry_end_l = NULL;
7899 if (node->
block != NULL) {
7900 previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
7901 ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
7903 retry_label = NEW_LABEL(location->
line);
7904 retry_end_l = NEW_LABEL(location->
line);
7906 PUSH_LABEL(ret, retry_label);
7909 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
7912 PUSH_INSN(ret, *location, putself);
7913 int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
7915 if (node->
block != NULL) {
7916 pm_scope_node_t next_scope_node;
7917 pm_scope_node_init((
const pm_node_t *) node->
block, &next_scope_node, scope_node);
7919 ISEQ_COMPILE_DATA(iseq)->current_block = block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
7920 pm_scope_node_destroy(&next_scope_node);
7927 const rb_iseq_t *local_iseq = body->local_iseq;
7931 int depth = get_lvar_level(iseq);
7933 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
param.flags.forwardable) {
7934 flag |= VM_CALL_FORWARDING;
7935 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
7936 PUSH_GETLOCAL(ret, *location, mult_local.index, mult_local.level);
7938 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, 0, flag, NULL, block != NULL);
7939 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, block);
7941 if (popped) PUSH_INSN(ret, *location, pop);
7943 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
7948 if (local_body->
param.flags.has_lead) {
7950 for (
int i = 0; i < local_body->
param.lead_num; i++) {
7951 int idx = local_body->local_table_size - i;
7952 PUSH_GETLOCAL(args, *location, idx, depth);
7954 argc += local_body->
param.lead_num;
7957 if (local_body->
param.flags.has_opt) {
7959 for (
int j = 0; j < local_body->
param.opt_num; j++) {
7960 int idx = local_body->local_table_size - (argc + j);
7961 PUSH_GETLOCAL(args, *location, idx, depth);
7963 argc += local_body->
param.opt_num;
7966 if (local_body->
param.flags.has_rest) {
7968 int idx = local_body->local_table_size - local_body->
param.rest_start;
7969 PUSH_GETLOCAL(args, *location, idx, depth);
7970 PUSH_INSN1(args, *location, splatarray,
Qfalse);
7972 argc = local_body->
param.rest_start + 1;
7973 flag |= VM_CALL_ARGS_SPLAT;
7976 if (local_body->
param.flags.has_post) {
7978 int post_len = local_body->
param.post_num;
7979 int post_start = local_body->
param.post_start;
7982 for (; j < post_len; j++) {
7983 int idx = local_body->local_table_size - (post_start + j);
7984 PUSH_GETLOCAL(args, *location, idx, depth);
7987 if (local_body->
param.flags.has_rest) {
7989 PUSH_INSN1(args, *location, newarray,
INT2FIX(j));
7990 PUSH_INSN(args, *location, concatarray);
7993 argc = post_len + post_start;
7997 const struct rb_iseq_param_keyword *
const local_keyword = local_body->
param.keyword;
7998 if (local_body->
param.flags.has_kw) {
7999 int local_size = local_body->local_table_size;
8002 PUSH_INSN1(args, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8004 if (local_body->
param.flags.has_kwrest) {
8005 int idx = local_body->local_table_size - local_keyword->rest_start;
8006 PUSH_GETLOCAL(args, *location, idx, depth);
8008 PUSH_SEND(args, *location, rb_intern(
"dup"),
INT2FIX(0));
8011 PUSH_INSN1(args, *location, newhash,
INT2FIX(0));
8014 for (; i < local_keyword->num; ++i) {
8015 ID id = local_keyword->table[i];
8016 int idx = local_size - get_local_var_idx(local_iseq,
id);
8020 PUSH_INSN1(args, *location, putobject, operand);
8023 PUSH_GETLOCAL(args, *location, idx, depth);
8026 PUSH_SEND(args, *location, id_core_hash_merge_ptr,
INT2FIX(i * 2 + 1));
8027 flag |= VM_CALL_KW_SPLAT| VM_CALL_KW_SPLAT_MUT;
8029 else if (local_body->
param.flags.has_kwrest) {
8030 int idx = local_body->local_table_size - local_keyword->rest_start;
8031 PUSH_GETLOCAL(args, *location, idx, depth);
8033 flag |= VM_CALL_KW_SPLAT;
8036 PUSH_SEQ(ret, args);
8039 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flag, NULL, block != NULL);
8040 PUSH_INSN2(ret, *location, invokesuper, callinfo, block);
8043 if (node->
block != NULL) {
8044 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8045 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, block, retry_end_l);
8046 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8049 if (popped) PUSH_INSN(ret, *location, pop);
8055 LABEL *matched_label = NEW_LABEL(location->
line);
8056 LABEL *unmatched_label = NEW_LABEL(location->
line);
8057 LABEL *done_label = NEW_LABEL(location->
line);
8061 PUSH_INSN(ret, *location, putnil);
8062 PUSH_INSN(ret, *location, putnil);
8063 PUSH_INSN1(ret, *location, putobject,
Qfalse);
8064 PUSH_INSN(ret, *location, putnil);
8065 PUSH_INSN(ret, *location, putnil);
8069 PM_COMPILE_NOT_POPPED(node->
value);
8073 PUSH_INSN(ret, *location, dup);
8080 pm_compile_pattern(iseq, scope_node, node->
pattern, ret, matched_label, unmatched_label,
true,
false,
true, 2);
8085 PUSH_LABEL(ret, unmatched_label);
8086 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, ret, done_label, popped);
8090 PUSH_LABEL(ret, matched_label);
8091 PUSH_INSN1(ret, *location, adjuststack,
INT2FIX(6));
8092 if (!popped) PUSH_INSN(ret, *location, putnil);
8093 PUSH_INSNL(ret, *location, jump, done_label);
8095 PUSH_LABEL(ret, done_label);
8101 LABEL *fail_label = NEW_LABEL(location->
line);
8102 LABEL *end_label = NEW_LABEL(location->
line);
8113 PUSH_INSN1(ret, *location, getglobal, operand);
8116 PUSH_INSN(ret, *location, dup);
8117 PUSH_INSNL(ret, *location, branchunless, fail_label);
8123 if (targets_count == 1) {
8128 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->
name, local_target->
depth);
8132 PUSH_INSN1(ret, *location, putobject, operand);
8135 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8136 PUSH_LABEL(ret, fail_label);
8137 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8138 if (popped) PUSH_INSN(ret, *location, pop);
8142 DECL_ANCHOR(fail_anchor);
8146 for (
size_t targets_index = 0; targets_index < targets_count; targets_index++) {
8151 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->
name, local_target->
depth);
8153 if (((
size_t) targets_index) < (targets_count - 1)) {
8154 PUSH_INSN(ret, *location, dup);
8159 PUSH_INSN1(ret, *location, putobject, operand);
8162 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8163 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8165 PUSH_INSN(fail_anchor, *location, putnil);
8166 PUSH_SETLOCAL(fail_anchor, *location, index.index, index.level);
8170 PUSH_INSNL(ret, *location, jump, end_label);
8174 PUSH_LABEL(ret, fail_label);
8175 PUSH_INSN(ret, *location, pop);
8176 PUSH_SEQ(ret, fail_anchor);
8179 PUSH_LABEL(ret, end_label);
8180 if (popped) PUSH_INSN(ret, *location, pop);
8184pm_compile_next_node(rb_iseq_t *iseq,
const pm_next_node_t *node,
const pm_node_location_t *location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
8186 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
8187 LABEL *splabel = NEW_LABEL(0);
8188 PUSH_LABEL(ret, splabel);
8194 PUSH_INSN(ret, *location, putnil);
8196 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8198 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8199 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8201 PUSH_ADJUST_RESTORE(ret, splabel);
8202 if (!popped) PUSH_INSN(ret, *location, putnil);
8204 else if (ISEQ_COMPILE_DATA(iseq)->end_label && can_add_ensure_iseq(iseq)) {
8205 LABEL *splabel = NEW_LABEL(0);
8207 PUSH_LABEL(ret, splabel);
8208 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8214 PUSH_INSN(ret, *location, putnil);
8217 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8218 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
8219 PUSH_ADJUST_RESTORE(ret, splabel);
8220 splabel->unremovable = FALSE;
8222 if (!popped) PUSH_INSN(ret, *location, putnil);
8225 const rb_iseq_t *ip = iseq;
8226 unsigned long throw_flag = 0;
8229 if (!ISEQ_COMPILE_DATA(ip)) {
8234 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
8235 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8239 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8242 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8243 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8247 ip = ISEQ_BODY(ip)->parent_iseq;
8255 PUSH_INSN(ret, *location, putnil);
8258 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_NEXT));
8259 if (popped) PUSH_INSN(ret, *location, pop);
8262 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8268pm_compile_redo_node(rb_iseq_t *iseq,
const pm_node_location_t *location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
8270 if (ISEQ_COMPILE_DATA(iseq)->redo_label && can_add_ensure_iseq(iseq)) {
8271 LABEL *splabel = NEW_LABEL(0);
8273 PUSH_LABEL(ret, splabel);
8274 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8275 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8277 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
8278 PUSH_ADJUST_RESTORE(ret, splabel);
8279 if (!popped) PUSH_INSN(ret, *location, putnil);
8281 else if (ISEQ_BODY(iseq)->
type != ISEQ_TYPE_EVAL && ISEQ_COMPILE_DATA(iseq)->start_label && can_add_ensure_iseq(iseq)) {
8282 LABEL *splabel = NEW_LABEL(0);
8284 PUSH_LABEL(ret, splabel);
8285 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8286 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8288 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8289 PUSH_ADJUST_RESTORE(ret, splabel);
8290 if (!popped) PUSH_INSN(ret, *location, putnil);
8293 const rb_iseq_t *ip = iseq;
8296 if (!ISEQ_COMPILE_DATA(ip)) {
8301 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8304 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8307 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8308 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8312 ip = ISEQ_BODY(ip)->parent_iseq;
8316 PUSH_INSN(ret, *location, putnil);
8317 PUSH_INSN1(ret, *location,
throw,
INT2FIX(VM_THROW_NO_ESCAPE_FLAG | TAG_REDO));
8318 if (popped) PUSH_INSN(ret, *location, pop);
8321 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8327pm_compile_rescue_node(rb_iseq_t *iseq,
const pm_rescue_node_t *node,
const pm_node_location_t *location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
8329 iseq_set_exception_local_table(iseq);
8333 LABEL *exception_match_label = NEW_LABEL(location->
line);
8334 LABEL *rescue_end_label = NEW_LABEL(location->
line);
8344 if (exceptions->
size > 0) {
8345 for (
size_t index = 0; index < exceptions->
size; index++) {
8346 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8347 PM_COMPILE(exceptions->
nodes[index]);
8348 int checkmatch_flags = VM_CHECKMATCH_TYPE_RESCUE;
8350 checkmatch_flags |= VM_CHECKMATCH_ARRAY;
8352 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(checkmatch_flags));
8353 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8357 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8359 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
8360 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8365 PUSH_INSNL(ret, *location, jump, rescue_end_label);
8370 PUSH_LABEL(ret, exception_match_label);
8377 DECL_ANCHOR(writes);
8378 DECL_ANCHOR(cleanup);
8380 pm_compile_target_node(iseq, node->
reference, ret, writes, cleanup, scope_node, NULL);
8381 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8383 PUSH_SEQ(ret, writes);
8384 PUSH_SEQ(ret, cleanup);
8394 LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
8395 ISEQ_COMPILE_DATA(iseq)->end_label = NULL;
8400 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
8403 PUSH_INSN(ret, *location, putnil);
8406 PUSH_INSN(ret, *location, leave);
8412 PUSH_LABEL(ret, rescue_end_label);
8417 PUSH_GETLOCAL(ret, *location, 1, 0);
8422pm_compile_return_node(rb_iseq_t *iseq,
const pm_return_node_t *node,
const pm_node_location_t *location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
8425 enum rb_iseq_type
type = ISEQ_BODY(iseq)->type;
8428 const rb_iseq_t *parent_iseq = iseq;
8429 enum rb_iseq_type parent_type = ISEQ_BODY(parent_iseq)->type;
8430 while (parent_type == ISEQ_TYPE_RESCUE || parent_type == ISEQ_TYPE_ENSURE) {
8431 if (!(parent_iseq = ISEQ_BODY(parent_iseq)->parent_iseq))
break;
8432 parent_type = ISEQ_BODY(parent_iseq)->type;
8435 switch (parent_type) {
8437 case ISEQ_TYPE_MAIN:
8439 rb_warn(
"argument of top-level return is ignored");
8441 if (parent_iseq == iseq) {
8442 type = ISEQ_TYPE_METHOD;
8449 if (
type == ISEQ_TYPE_METHOD) {
8450 splabel = NEW_LABEL(0);
8451 PUSH_LABEL(ret, splabel);
8452 PUSH_ADJUST(ret, *location, 0);
8455 if (arguments != NULL) {
8456 PM_COMPILE_NOT_POPPED((
const pm_node_t *) arguments);
8459 PUSH_INSN(ret, *location, putnil);
8462 if (
type == ISEQ_TYPE_METHOD && can_add_ensure_iseq(iseq)) {
8463 pm_add_ensure_iseq(ret, iseq, 1, scope_node);
8465 PUSH_INSN(ret, *location, leave);
8466 PUSH_ADJUST_RESTORE(ret, splabel);
8467 if (!popped) PUSH_INSN(ret, *location, putnil);
8470 PUSH_INSN1(ret, *location,
throw,
INT2FIX(TAG_RETURN));
8471 if (popped) PUSH_INSN(ret, *location, pop);
8476pm_compile_super_node(rb_iseq_t *iseq,
const pm_super_node_t *node,
const pm_node_location_t *location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
8480 LABEL *retry_label = NEW_LABEL(location->
line);
8481 LABEL *retry_end_l = NEW_LABEL(location->
line);
8483 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8484 const rb_iseq_t *current_block;
8485 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NULL;
8487 PUSH_LABEL(ret, retry_label);
8488 PUSH_INSN(ret, *location, putself);
8492 int argc = pm_setup_args(node->
arguments, node->
block, &flags, &keywords, iseq, ret, scope_node, location);
8494 flags |= VM_CALL_SUPER | VM_CALL_FCALL;
8497 pm_scope_node_t next_scope_node;
8498 pm_scope_node_init(node->
block, &next_scope_node, scope_node);
8500 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8501 pm_scope_node_destroy(&next_scope_node);
8505 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8508 if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
8509 PUSH_INSN(args, *location, splatkw);
8512 PUSH_SEQ(ret, args);
8513 if (is_forwardable && ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8514 flags |= VM_CALL_FORWARDING;
8517 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8518 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, current_block);
8523 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8524 PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
8529 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8531 if (popped) PUSH_INSN(ret, *location, pop);
8532 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8533 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);
8537pm_compile_yield_node(rb_iseq_t *iseq,
const pm_yield_node_t *node,
const pm_node_location_t *location, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
8539 switch (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
type) {
8541 case ISEQ_TYPE_MAIN:
8542 case ISEQ_TYPE_CLASS:
8543 COMPILE_ERROR(iseq, location->
line,
"Invalid yield");
8553 argc = pm_setup_args(node->
arguments, NULL, &flags, &keywords, iseq, ret, scope_node, location);
8556 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, FALSE);
8557 PUSH_INSN1(ret, *location, invokeblock, callinfo);
8559 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8560 if (popped) PUSH_INSN(ret, *location, pop);
8563 for (
const rb_iseq_t *tmp_iseq = iseq; tmp_iseq != ISEQ_BODY(iseq)->local_iseq; level++) {
8564 tmp_iseq = ISEQ_BODY(tmp_iseq)->parent_iseq;
8567 if (level > 0) access_outer_variables(iseq, level, rb_intern(
"yield"),
true);
8581pm_compile_node(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
8585 int lineno = (int) location.
line;
8592 lineno = (int) PM_NODE_START_LINE_COLUMN(parser, ((
const pm_begin_node_t *) node)->rescue_clause).line;
8601 ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8602 if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8603 event |= RUBY_EVENT_COVERAGE_LINE;
8605 PUSH_TRACE(ret, event);
8617 pm_compile_alias_method_node(iseq, (
const pm_alias_method_node_t *) node, &location, ret, popped, scope_node);
8622 pm_compile_and_node(iseq, (
const pm_and_node_t *) node, &location, ret, popped, scope_node);
8634 if (elements->
size == 1) {
8637 PM_COMPILE(elements->
nodes[0]);
8640 pm_compile_array_node(iseq, (
const pm_node_t *) cast, elements, &location, ret, popped, scope_node);
8648 pm_compile_array_node(iseq, (
const pm_node_t *) cast, &cast->elements, &location, ret, popped, scope_node);
8659 PM_COMPILE(cast->
key);
8660 PM_COMPILE(cast->
value);
8672 if (cast->
value != NULL) {
8673 PM_COMPILE(cast->
value);
8676 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
8677 PUSH_GETLOCAL(ret, location, index.index, index.level);
8687 VALUE backref = pm_compile_back_reference_ref(cast);
8689 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), backref);
8701 pm_compile_ensure(iseq, cast, &location, ret, popped, scope_node);
8705 pm_compile_rescue(iseq, cast, &location, ret, popped, scope_node);
8714 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8729 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
8730 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(local_index.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(local_index.level));
8740 pm_compile_break_node(iseq, (
const pm_break_node_t *) node, &location, ret, popped, scope_node);
8751 pm_compile_call_node(iseq, (
const pm_call_node_t *) node, ret, popped, scope_node);
8757 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);
8764 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);
8782 pm_compile_case_node(iseq, (
const pm_case_node_t *) node, &location, ret, popped, scope_node);
8793 pm_compile_case_match_node(iseq, (
const pm_case_match_node_t *) node, &location, ret, popped, scope_node);
8800 ID class_id = pm_constant_id_lookup(scope_node, cast->
name);
8801 VALUE class_name =
rb_str_freeze(rb_sprintf(
"<class:%"PRIsVALUE
">", rb_id2str(class_id)));
8803 pm_scope_node_t next_scope_node;
8804 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
8806 const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(&next_scope_node, class_name, ISEQ_TYPE_CLASS, location.
line);
8807 pm_scope_node_destroy(&next_scope_node);
8810 const int flags = VM_DEFINECLASS_TYPE_CLASS |
8811 (cast->
superclass ? VM_DEFINECLASS_FLAG_HAS_SUPERCLASS : 0) |
8812 pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
8818 PUSH_INSN(ret, location, putnil);
8823 PUSH_INSN3(ret, location, defineclass, operand, class_iseq,
INT2FIX(flags));
8827 if (popped) PUSH_INSN(ret, location, pop);
8834 LABEL *end_label = NEW_LABEL(location.
line);
8836 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8839 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8840 if (!popped) PUSH_INSN(ret, location, dup);
8842 PUSH_INSNL(ret, location, branchunless, end_label);
8843 if (!popped) PUSH_INSN(ret, location, pop);
8845 PM_COMPILE_NOT_POPPED(cast->
value);
8846 if (!popped) PUSH_INSN(ret, location, dup);
8848 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8849 PUSH_LABEL(ret, end_label);
8858 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8861 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8862 PM_COMPILE_NOT_POPPED(cast->
value);
8865 int flags = VM_CALL_ARGS_SIMPLE;
8866 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
8868 if (!popped) PUSH_INSN(ret, location, dup);
8869 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8877 LABEL *end_label = NEW_LABEL(location.
line);
8878 LABEL *start_label = NEW_LABEL(location.
line);
8880 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8883 PUSH_INSN(ret, location, putnil);
8884 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name,
Qtrue);
8885 PUSH_INSNL(ret, location, branchunless, start_label);
8887 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8888 if (!popped) PUSH_INSN(ret, location, dup);
8890 PUSH_INSNL(ret, location, branchif, end_label);
8891 if (!popped) PUSH_INSN(ret, location, pop);
8893 PUSH_LABEL(ret, start_label);
8894 PM_COMPILE_NOT_POPPED(cast->
value);
8895 if (!popped) PUSH_INSN(ret, location, dup);
8897 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8898 PUSH_LABEL(ret, end_label);
8907 ID name = pm_constant_id_lookup(scope_node, cast->
name);
8908 PUSH_INSN2(ret, location, getclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
8916 PM_COMPILE_NOT_POPPED(cast->
value);
8917 if (!popped) PUSH_INSN(ret, location, dup);
8919 ID name = pm_constant_id_lookup(scope_node, cast->
name);
8920 PUSH_INSN2(ret, location, setclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
8929 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache && ((parts = pm_constant_path_parts(node, scope_node)) !=
Qnil)) {
8930 ISEQ_BODY(iseq)->ic_size++;
8931 PUSH_INSN1(ret, location, opt_getconstant_path, parts);
8934 DECL_ANCHOR(prefix);
8937 pm_compile_constant_path(iseq, node, prefix, body, popped, scope_node);
8938 if (LIST_INSN_SIZE_ZERO(prefix)) {
8939 PUSH_INSN(ret, location, putnil);
8942 PUSH_SEQ(ret, prefix);
8945 PUSH_SEQ(ret, body);
8948 if (popped) PUSH_INSN(ret, location, pop);
8955 pm_compile_constant_path_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8962 pm_compile_constant_path_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8969 pm_compile_constant_path_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8976 pm_compile_constant_path_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8985 pm_compile_constant_read(iseq, name, &cast->
base.
location, location.
node_id, ret, scope_node);
8986 if (popped) PUSH_INSN(ret, location, pop);
8994 pm_compile_constant_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9001 pm_compile_constant_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9008 pm_compile_constant_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9015 pm_compile_constant_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9025 ID method_name = pm_constant_id_lookup(scope_node, cast->
name);
9027 pm_scope_node_t next_scope_node;
9028 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9030 rb_iseq_t *method_iseq = NEW_ISEQ(&next_scope_node, rb_id2str(method_name), ISEQ_TYPE_METHOD, location.
line);
9031 pm_scope_node_destroy(&next_scope_node);
9034 PM_COMPILE_NOT_POPPED(cast->
receiver);
9035 PUSH_INSN2(ret, location, definesmethod,
ID2SYM(method_name), method_iseq);
9038 PUSH_INSN2(ret, location, definemethod,
ID2SYM(method_name), method_iseq);
9043 PUSH_INSN1(ret, location, putobject,
ID2SYM(method_name));
9052 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
false);
9064 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9067 if (popped) PUSH_INSN(ret, location, pop);
9081 PUSH_INSN1(ret, location, putobject,
Qfalse);
9103 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9113 LABEL *final_label = NEW_LABEL(location.
line);
9114 LABEL *then_label = NEW_LABEL(location.
line);
9115 LABEL *else_label = NEW_LABEL(location.
line);
9117 pm_compile_flip_flop(cast, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
9119 PUSH_LABEL(ret, then_label);
9120 PUSH_INSN1(ret, location, putobject,
Qtrue);
9121 PUSH_INSNL(ret, location, jump, final_label);
9122 PUSH_LABEL(ret, else_label);
9123 PUSH_INSN1(ret, location, putobject,
Qfalse);
9124 PUSH_LABEL(ret, final_label);
9133 PUSH_INSN1(ret, location, putobject, operand);
9142 LABEL *retry_label = NEW_LABEL(location.
line);
9143 LABEL *retry_end_l = NEW_LABEL(location.
line);
9146 PUSH_LABEL(ret, retry_label);
9151 pm_scope_node_t next_scope_node;
9152 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9154 const rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location.
line);
9155 pm_scope_node_destroy(&next_scope_node);
9157 const rb_iseq_t *prev_block = ISEQ_COMPILE_DATA(iseq)->current_block;
9158 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
9162 PUSH_SEND_WITH_BLOCK(ret, location, idEach,
INT2FIX(0), child_iseq);
9163 pm_compile_retry_end_label(iseq, ret, retry_end_l);
9165 if (popped) PUSH_INSN(ret, location, pop);
9166 ISEQ_COMPILE_DATA(iseq)->current_block = prev_block;
9167 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
9171 rb_bug(
"Cannot compile a ForwardingArgumentsNode directly\n");
9185 LABEL *end_label = NEW_LABEL(location.
line);
9188 PUSH_INSN1(ret, location, getglobal, name);
9189 if (!popped) PUSH_INSN(ret, location, dup);
9191 PUSH_INSNL(ret, location, branchunless, end_label);
9192 if (!popped) PUSH_INSN(ret, location, pop);
9194 PM_COMPILE_NOT_POPPED(cast->
value);
9195 if (!popped) PUSH_INSN(ret, location, dup);
9197 PUSH_INSN1(ret, location, setglobal, name);
9198 PUSH_LABEL(ret, end_label);
9208 PUSH_INSN1(ret, location, getglobal, name);
9209 PM_COMPILE_NOT_POPPED(cast->
value);
9212 int flags = VM_CALL_ARGS_SIMPLE;
9213 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9215 if (!popped) PUSH_INSN(ret, location, dup);
9216 PUSH_INSN1(ret, location, setglobal, name);
9224 LABEL *set_label = NEW_LABEL(location.
line);
9225 LABEL *end_label = NEW_LABEL(location.
line);
9227 PUSH_INSN(ret, location, putnil);
9230 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name,
Qtrue);
9231 PUSH_INSNL(ret, location, branchunless, set_label);
9233 PUSH_INSN1(ret, location, getglobal, name);
9234 if (!popped) PUSH_INSN(ret, location, dup);
9236 PUSH_INSNL(ret, location, branchif, end_label);
9237 if (!popped) PUSH_INSN(ret, location, pop);
9239 PUSH_LABEL(ret, set_label);
9240 PM_COMPILE_NOT_POPPED(cast->
value);
9241 if (!popped) PUSH_INSN(ret, location, dup);
9243 PUSH_INSN1(ret, location, setglobal, name);
9244 PUSH_LABEL(ret, end_label);
9254 PUSH_INSN1(ret, location, getglobal, name);
9255 if (popped) PUSH_INSN(ret, location, pop);
9263 PM_COMPILE_NOT_POPPED(cast->
value);
9264 if (!popped) PUSH_INSN(ret, location, dup);
9266 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9267 PUSH_INSN1(ret, location, setglobal,
ID2SYM(name));
9285 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
9288 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9289 PUSH_INSN1(ret, location, duphash, value);
9310 for (
size_t index = 0; index < elements->
size; index++) {
9311 PM_COMPILE_POPPED(elements->
nodes[index]);
9315 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9331 pm_compile_conditional(iseq, &location,
PM_IF_NODE, (
const pm_node_t *) cast, cast->statements, cast->subsequent, cast->predicate, ret, popped, scope_node);
9339 PUSH_INSN1(ret, location, putobject, operand);
9353 PM_COMPILE(cast->
value);
9359 rb_bug(
"Should not ever enter an in node directly");
9366 pm_compile_index_operator_write_node(iseq, cast, &location, ret, popped, scope_node);
9373 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9380 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9387 LABEL *end_label = NEW_LABEL(location.
line);
9389 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9392 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9393 if (!popped) PUSH_INSN(ret, location, dup);
9395 PUSH_INSNL(ret, location, branchunless, end_label);
9396 if (!popped) PUSH_INSN(ret, location, pop);
9398 PM_COMPILE_NOT_POPPED(cast->
value);
9399 if (!popped) PUSH_INSN(ret, location, dup);
9401 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9402 PUSH_LABEL(ret, end_label);
9411 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9414 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9415 PM_COMPILE_NOT_POPPED(cast->
value);
9418 int flags = VM_CALL_ARGS_SIMPLE;
9419 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9421 if (!popped) PUSH_INSN(ret, location, dup);
9422 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9430 LABEL *end_label = NEW_LABEL(location.
line);
9432 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9435 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9436 if (!popped) PUSH_INSN(ret, location, dup);
9438 PUSH_INSNL(ret, location, branchif, end_label);
9439 if (!popped) PUSH_INSN(ret, location, pop);
9441 PM_COMPILE_NOT_POPPED(cast->
value);
9442 if (!popped) PUSH_INSN(ret, location, dup);
9444 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9445 PUSH_LABEL(ret, end_label);
9454 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9455 PUSH_INSN2(ret, location, getinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9463 PM_COMPILE_NOT_POPPED(cast->
value);
9464 if (!popped) PUSH_INSN(ret, location, dup);
9466 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9467 PUSH_INSN2(ret, location, setinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9476 PUSH_INSN1(ret, location, putobject, operand);
9485 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9486 PUSH_INSN1(ret, location, putobject, regexp);
9493 PUSH_INSN1(ret, location, getglobal,
rb_id2sym(idLASTLINE));
9494 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9495 if (popped) PUSH_INSN(ret, location, pop);
9503 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9504 const rb_iseq_t *block_iseq = NULL;
9505 int ise_index = ISEQ_BODY(iseq)->ise_size++;
9507 pm_scope_node_t next_scope_node;
9508 pm_scope_node_init(node, &next_scope_node, scope_node);
9510 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, location.
line);
9511 pm_scope_node_destroy(&next_scope_node);
9513 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
9514 PUSH_INSN2(ret, location, once, block_iseq,
INT2FIX(ise_index));
9515 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9517 if (popped) PUSH_INSN(ret, location, pop);
9523 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9524 PUSH_INSN1(ret, location, putobject, regexp);
9529 if (popped) PUSH_INSN(ret, location, pop);
9539 VALUE string = pm_static_literal_value(iseq, node, scope_node);
9542 PUSH_INSN1(ret, location, putobject,
string);
9545 PUSH_INSN1(ret, location, putstring,
string);
9548 PUSH_INSN1(ret, location, putchilledstring,
string);
9554 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL);
9555 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9556 if (popped) PUSH_INSN(ret, location, pop);
9565 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL);
9568 PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9572 PUSH_INSN(ret, location, intern);
9575 PUSH_INSN(ret, location, pop);
9585 PUSH_INSN(ret, location, putself);
9587 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret,
false, scope_node, NULL, NULL);
9588 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9590 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
9591 if (popped) PUSH_INSN(ret, location, pop);
9599 PUSH_GETLOCAL(ret, location, scope_node->local_table_for_iseq_size, 0);
9612 PM_COMPILE(element);
9615 if (!popped) PUSH_INSN1(ret, location, newhash,
INT2FIX(elements->
size * 2));
9623 pm_scope_node_t next_scope_node;
9624 pm_scope_node_init(node, &next_scope_node, scope_node);
9626 int opening_lineno = pm_location_line_number(parser, &cast->
opening_loc);
9627 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, opening_lineno);
9628 pm_scope_node_destroy(&next_scope_node);
9631 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9632 PUSH_CALL_WITH_BLOCK(ret, location, idLambda, argc, block);
9635 if (popped) PUSH_INSN(ret, location, pop);
9642 LABEL *end_label = NEW_LABEL(location.
line);
9644 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9645 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9646 if (!popped) PUSH_INSN(ret, location, dup);
9648 PUSH_INSNL(ret, location, branchunless, end_label);
9649 if (!popped) PUSH_INSN(ret, location, pop);
9651 PM_COMPILE_NOT_POPPED(cast->
value);
9652 if (!popped) PUSH_INSN(ret, location, dup);
9654 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9655 PUSH_LABEL(ret, end_label);
9664 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9665 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9667 PM_COMPILE_NOT_POPPED(cast->
value);
9670 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
9672 if (!popped) PUSH_INSN(ret, location, dup);
9673 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9682 LABEL *set_label = NEW_LABEL(location.
line);
9683 LABEL *end_label = NEW_LABEL(location.
line);
9685 PUSH_INSN1(ret, location, putobject,
Qtrue);
9686 PUSH_INSNL(ret, location, branchunless, set_label);
9688 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9689 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9690 if (!popped) PUSH_INSN(ret, location, dup);
9692 PUSH_INSNL(ret, location, branchif, end_label);
9693 if (!popped) PUSH_INSN(ret, location, pop);
9695 PUSH_LABEL(ret, set_label);
9696 PM_COMPILE_NOT_POPPED(cast->
value);
9697 if (!popped) PUSH_INSN(ret, location, dup);
9699 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9700 PUSH_LABEL(ret, end_label);
9709 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9710 PUSH_GETLOCAL(ret, location, index.index, index.level);
9719 PM_COMPILE_NOT_POPPED(cast->
value);
9720 if (!popped) PUSH_INSN(ret, location, dup);
9722 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9723 PUSH_SETLOCAL(ret, location, index.index, index.level);
9729 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9731 PUSH_INSN1(ret, location, putobject, regexp);
9733 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9734 if (popped) PUSH_INSN(ret, location, pop);
9745 PUSH_INSN(ret, location, putnil);
9748 PM_COMPILE_NOT_POPPED(cast->
value);
9749 PUSH_INSN(ret, location, dup);
9753 LABEL *matched_label = NEW_LABEL(location.
line);
9754 LABEL *unmatched_label = NEW_LABEL(location.
line);
9755 LABEL *done_label = NEW_LABEL(location.
line);
9756 pm_compile_pattern(iseq, scope_node, cast->
pattern, ret, matched_label, unmatched_label,
false,
false,
true, 2);
9760 PUSH_LABEL(ret, unmatched_label);
9761 PUSH_INSN(ret, location, pop);
9762 PUSH_INSN(ret, location, pop);
9764 if (!popped) PUSH_INSN1(ret, location, putobject,
Qfalse);
9765 PUSH_INSNL(ret, location, jump, done_label);
9766 PUSH_INSN(ret, location, putnil);
9770 PUSH_LABEL(ret, matched_label);
9771 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(2));
9772 if (!popped) PUSH_INSN1(ret, location, putobject,
Qtrue);
9773 PUSH_INSNL(ret, location, jump, done_label);
9775 PUSH_LABEL(ret, done_label);
9801 pm_compile_match_write_node(iseq, (
const pm_match_write_node_t *) node, &location, ret, popped, scope_node);
9804 rb_bug(
"A pm_missing_node_t should not exist in prism's AST.");
9811 ID module_id = pm_constant_id_lookup(scope_node, cast->
name);
9812 VALUE module_name =
rb_str_freeze(rb_sprintf(
"<module:%"PRIsVALUE
">", rb_id2str(module_id)));
9814 pm_scope_node_t next_scope_node;
9815 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9817 const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&next_scope_node, module_name, ISEQ_TYPE_CLASS, location.
line);
9818 pm_scope_node_destroy(&next_scope_node);
9820 const int flags = VM_DEFINECLASS_TYPE_MODULE | pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
9821 PUSH_INSN(ret, location, putnil);
9822 PUSH_INSN3(ret, location, defineclass,
ID2SYM(module_id), module_iseq,
INT2FIX(flags));
9825 if (popped) PUSH_INSN(ret, location, pop);
9832 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, 0);
9834 PUSH_SETLOCAL(ret, location, index.index, index.level);
9848 DECL_ANCHOR(writes);
9849 DECL_ANCHOR(cleanup);
9852 state.position = popped ? 0 : 1;
9853 pm_compile_multi_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
9855 PM_COMPILE_NOT_POPPED(cast->
value);
9856 if (!popped) PUSH_INSN(ret, location, dup);
9858 PUSH_SEQ(ret, writes);
9859 if (!popped && state.stack_size >= 1) {
9862 PUSH_INSN1(ret, location, setn,
INT2FIX(state.stack_size));
9867 pm_multi_target_state_update(&state);
9869 PUSH_SEQ(ret, cleanup);
9878 pm_compile_next_node(iseq, (
const pm_next_node_t *) node, &location, ret, popped, scope_node);
9884 PUSH_INSN(ret, location, putnil);
9892 ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg = TRUE;
9902 VALUE ref = pm_compile_numbered_reference_ref(cast);
9903 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), ref);
9906 PUSH_INSN(ret, location, putnil);
9917 LABEL *end_label = NEW_LABEL(location.
line);
9918 PM_COMPILE_NOT_POPPED(cast->
left);
9920 if (!popped) PUSH_INSN(ret, location, dup);
9921 PUSH_INSNL(ret, location, branchif, end_label);
9923 if (!popped) PUSH_INSN(ret, location, pop);
9924 PM_COMPILE(cast->
right);
9925 PUSH_LABEL(ret, end_label);
9933 PM_COMPILE_NOT_POPPED(cast->
value);
9935 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, 0);
9936 PUSH_SETLOCAL(ret, location, index.index, index.level);
9948 if (cast->
body != NULL) {
9949 PM_COMPILE(cast->
body);
9952 PUSH_INSN(ret, location, putnil);
9969 DECL_ANCHOR(inner_pre);
9972 DECL_ANCHOR(inner_body);
9977 for (
size_t index = 0; index < body->
size; index++) {
9978 pm_compile_node(iseq, body->
nodes[index], inner_body,
true, scope_node);
9983 PUSH_INSN(inner_body, location, putnil);
9989 PUSH_SEQ(outer_pre, inner_pre);
9990 PUSH_SEQ(outer_pre, inner_body);
9998 const rb_iseq_t *child_iseq;
9999 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
10001 pm_scope_node_t next_scope_node;
10002 pm_scope_node_init(node, &next_scope_node, scope_node);
10003 child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
10004 pm_scope_node_destroy(&next_scope_node);
10006 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
10008 int is_index = ISEQ_BODY(iseq)->ise_size++;
10009 PUSH_INSN2(ret, location, once, child_iseq,
INT2FIX(is_index));
10011 if (popped) PUSH_INSN(ret, location, pop);
10013 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
10023 if (pm_optimizable_range_item_p(cast->
left) && pm_optimizable_range_item_p(cast->
right)) {
10034 PUSH_INSN1(ret, location, putobject, val);
10038 if (cast->
left != NULL) {
10039 PM_COMPILE(cast->
left);
10041 else if (!popped) {
10042 PUSH_INSN(ret, location, putnil);
10045 if (cast->
right != NULL) {
10046 PM_COMPILE(cast->
right);
10048 else if (!popped) {
10049 PUSH_INSN(ret, location, putnil);
10053 PUSH_INSN1(ret, location, newrange,
INT2FIX(exclude_end ? 1 : 0));
10062 PUSH_INSN1(ret, location, putobject, parse_rational((
const pm_rational_node_t *) node));
10069 pm_compile_redo_node(iseq, &location, ret, popped, scope_node);
10075 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
10076 PUSH_INSN1(ret, location, putobject, regexp);
10083 pm_compile_rescue_node(iseq, (
const pm_rescue_node_t *) node, &location, ret, popped, scope_node);
10090 pm_scope_node_t rescue_scope_node;
10091 pm_scope_node_init((
const pm_node_t *) cast, &rescue_scope_node, scope_node);
10093 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
10094 &rescue_scope_node,
10100 pm_scope_node_destroy(&rescue_scope_node);
10102 LABEL *lstart = NEW_LABEL(location.
line);
10103 LABEL *lend = NEW_LABEL(location.
line);
10104 LABEL *lcont = NEW_LABEL(location.
line);
10106 lstart->rescued = LABEL_RESCUE_BEG;
10107 lend->rescued = LABEL_RESCUE_END;
10109 PUSH_LABEL(ret, lstart);
10111 PUSH_LABEL(ret, lend);
10113 PUSH_INSN(ret, location, nop);
10114 PUSH_LABEL(ret, lcont);
10115 if (popped) PUSH_INSN(ret, location, pop);
10117 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
10118 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
10127 pm_compile_return_node(iseq, (
const pm_return_node_t *) node, &location, ret, popped, scope_node);
10132 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_RESCUE) {
10133 PUSH_INSN(ret, location, putnil);
10134 PUSH_INSN1(ret, location,
throw,
INT2FIX(TAG_RETRY));
10135 if (popped) PUSH_INSN(ret, location, pop);
10138 COMPILE_ERROR(iseq, location.
line,
"Invalid retry");
10144 pm_compile_scope_node(iseq, (pm_scope_node_t *) node, &location, ret, popped);
10150 PUSH_INSN(ret, location, putself);
10186 rb_bug(
"Unexpected node type for shareable constant write: %s", pm_node_type_to_str(
PM_NODE_TYPE(cast->
write)));
10197 pm_scope_node_t next_scope_node;
10198 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10199 const rb_iseq_t *child_iseq = NEW_ISEQ(&next_scope_node, rb_fstring_lit(
"singleton class"), ISEQ_TYPE_CLASS, location.
line);
10200 pm_scope_node_destroy(&next_scope_node);
10203 PUSH_INSN(ret, location, putnil);
10206 CONST_ID(singletonclass,
"singletonclass");
10207 PUSH_INSN3(ret, location, defineclass,
ID2SYM(singletonclass), child_iseq,
INT2FIX(VM_DEFINECLASS_TYPE_SINGLETON_CLASS));
10209 if (popped) PUSH_INSN(ret, location, pop);
10218 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10219 PUSH_INSN1(ret, location, putobject, value);
10228 VALUE string = pm_source_file_value(cast, scope_node);
10231 PUSH_INSN1(ret, location, putobject,
string);
10234 PUSH_INSN1(ret, location, putstring,
string);
10237 PUSH_INSN1(ret, location, putchilledstring,
string);
10246 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10247 PUSH_INSN1(ret, location, putobject, value);
10260 PUSH_INSN1(ret, location, splatarray,
Qtrue);
10269 if (body->
size > 0) {
10270 for (
size_t index = 0; index < body->
size - 1; index++) {
10271 PM_COMPILE_POPPED(body->
nodes[index]);
10273 PM_COMPILE(body->
nodes[body->
size - 1]);
10276 PUSH_INSN(ret, location, putnil);
10285 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10288 PUSH_INSN1(ret, location, putobject, value);
10291 PUSH_INSN1(ret, location, putstring, value);
10294 PUSH_INSN1(ret, location, putchilledstring, value);
10303 pm_compile_super_node(iseq, (
const pm_super_node_t *) node, &location, ret, popped, scope_node);
10309 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10310 PUSH_INSN1(ret, location, putobject, value);
10318 PUSH_INSN1(ret, location, putobject,
Qtrue);
10328 for (
size_t index = 0; index < names->
size; index++) {
10329 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10330 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
10332 PM_COMPILE_NOT_POPPED(names->
nodes[index]);
10333 PUSH_SEND(ret, location, id_core_undef_method,
INT2NUM(2));
10335 if (index < names->size - 1) {
10336 PUSH_INSN(ret, location, pop);
10340 if (popped) PUSH_INSN(ret, location, pop);
10355 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);
10365 pm_compile_loop(iseq, &location, cast->
base.
flags,
PM_UNTIL_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10375 pm_compile_loop(iseq, &location, cast->
base.
flags,
PM_WHILE_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10382 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10384 PUSH_INSN(ret, location, putself);
10385 PUSH_INSN1(ret, location, putobject, value);
10386 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
10387 if (popped) PUSH_INSN(ret, location, pop);
10397 pm_compile_yield_node(iseq, (
const pm_yield_node_t *) node, &location, ret, popped, scope_node);
10405#undef PM_CONTAINER_P
10409pm_iseq_pre_execution_p(rb_iseq_t *iseq)
10411 switch (ISEQ_BODY(iseq)->
type) {
10412 case ISEQ_TYPE_TOP:
10413 case ISEQ_TYPE_EVAL:
10414 case ISEQ_TYPE_MAIN:
10429pm_iseq_compile_node(rb_iseq_t *iseq, pm_scope_node_t *node)
10433 if (pm_iseq_pre_execution_p(iseq)) {
10445 pm_compile_node(iseq, (
const pm_node_t *) node, body,
false, node);
10449 PUSH_SEQ(ret, pre);
10450 PUSH_SEQ(ret, body);
10455 pm_compile_node(iseq, (
const pm_node_t *) node, ret,
false, node);
10458 CHECK(iseq_setup_insn(iseq, ret));
10459 return iseq_setup(iseq, ret);
10469 if (result->
node.ast_node != NULL) {
10470 pm_node_destroy(&result->
parser, result->
node.ast_node);
10475 pm_scope_node_destroy(&result->
node);
10478 pm_parser_free(&result->
parser);
10479 pm_string_free(&result->
input);
10480 pm_options_free(&result->
options);
10516#define PM_COLOR_BOLD "\033[1m"
10517#define PM_COLOR_GRAY "\033[2m"
10518#define PM_COLOR_RED "\033[1;31m"
10519#define PM_COLOR_RESET "\033[m"
10520#define PM_ERROR_TRUNCATE 30
10525 if (errors == NULL)
return NULL;
10529 pm_line_column_t start = pm_newline_list_line_column(newline_list, error->location.
start, start_line);
10530 pm_line_column_t end = pm_newline_list_line_column(newline_list, error->location.end, start_line);
10538 (index < error_list->size) &&
10539 (errors[index].error != NULL) &&
10541 (errors[index].line < start.
line) ||
10548 if (index + 1 < error_list->
size) {
10549 memmove(&errors[index + 1], &errors[index],
sizeof(
pm_parse_error_t) * (error_list->
size - index - 1));
10553 uint32_t column_end;
10555 column_end = end.
column;
10557 column_end = (uint32_t) (newline_list->
offsets[start.
line - start_line + 1] - newline_list->
offsets[start.
line - start_line] - 1);
10561 if (start.
column == column_end) column_end++;
10565 .line = start.
line,
10566 .column_start = start.
column,
10567 .column_end = column_end
10575#define pm_buffer_append_literal(buffer, str) pm_buffer_append_string(buffer, str, rb_strlen_lit(str))
10578pm_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) {
10579 int32_t line_delta = line - parser->
start_line;
10580 assert(line_delta >= 0);
10582 size_t index = (size_t) line_delta;
10583 assert(index < newline_list->size);
10585 const uint8_t *start = &parser->
start[newline_list->
offsets[index]];
10586 const uint8_t *end;
10588 if (index >= newline_list->
size - 1) {
10591 end = &parser->
start[newline_list->
offsets[index + 1]];
10594 pm_buffer_append_format(buffer, number_prefix, line);
10597 bool truncate_end =
false;
10598 if ((column_end != 0) && ((end - (start + column_end)) >= PM_ERROR_TRUNCATE)) {
10599 end = start + column_end + PM_ERROR_TRUNCATE;
10600 truncate_end =
true;
10604 if (column_start >= PM_ERROR_TRUNCATE) {
10605 pm_buffer_append_string(buffer,
"... ", 4);
10606 start += column_start;
10609 pm_buffer_append_string(buffer, (
const char *) start, (
size_t) (end - start));
10611 if (truncate_end) {
10612 pm_buffer_append_string(buffer,
" ...\n", 5);
10613 }
else if (end == parser->
end && end[-1] !=
'\n') {
10614 pm_buffer_append_string(buffer,
"\n", 1);
10623 assert(error_list->
size != 0);
10627 const int32_t start_line = parser->
start_line;
10630 pm_parse_error_t *errors = pm_parse_errors_format_sort(parser, error_list, newline_list);
10631 if (errors == NULL)
return;
10637 int32_t first_line_number = errors[0].
line;
10638 int32_t last_line_number = errors[error_list->
size - 1].
line;
10643 if (first_line_number < 0) first_line_number = (-first_line_number) * 10;
10644 if (last_line_number < 0) last_line_number = (-last_line_number) * 10;
10645 int32_t max_line_number = first_line_number > last_line_number ? first_line_number : last_line_number;
10647 if (max_line_number < 10) {
10648 if (highlight > 0) {
10650 .number_prefix = PM_COLOR_GRAY
"%1" PRIi32
" | " PM_COLOR_RESET,
10651 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10652 .divider = PM_COLOR_GRAY
" ~~~~~" PM_COLOR_RESET
"\n"
10656 .number_prefix =
"%1" PRIi32
" | ",
10657 .blank_prefix =
" | ",
10658 .divider =
" ~~~~~\n"
10661 }
else if (max_line_number < 100) {
10662 if (highlight > 0) {
10664 .number_prefix = PM_COLOR_GRAY
"%2" PRIi32
" | " PM_COLOR_RESET,
10665 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10666 .divider = PM_COLOR_GRAY
" ~~~~~~" PM_COLOR_RESET
"\n"
10670 .number_prefix =
"%2" PRIi32
" | ",
10671 .blank_prefix =
" | ",
10672 .divider =
" ~~~~~~\n"
10675 }
else if (max_line_number < 1000) {
10676 if (highlight > 0) {
10678 .number_prefix = PM_COLOR_GRAY
"%3" PRIi32
" | " PM_COLOR_RESET,
10679 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10680 .divider = PM_COLOR_GRAY
" ~~~~~~~" PM_COLOR_RESET
"\n"
10684 .number_prefix =
"%3" PRIi32
" | ",
10685 .blank_prefix =
" | ",
10686 .divider =
" ~~~~~~~\n"
10689 }
else if (max_line_number < 10000) {
10690 if (highlight > 0) {
10692 .number_prefix = PM_COLOR_GRAY
"%4" PRIi32
" | " PM_COLOR_RESET,
10693 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10694 .divider = PM_COLOR_GRAY
" ~~~~~~~~" PM_COLOR_RESET
"\n"
10698 .number_prefix =
"%4" PRIi32
" | ",
10699 .blank_prefix =
" | ",
10700 .divider =
" ~~~~~~~~\n"
10704 if (highlight > 0) {
10706 .number_prefix = PM_COLOR_GRAY
"%5" PRIi32
" | " PM_COLOR_RESET,
10707 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10708 .divider = PM_COLOR_GRAY
" ~~~~~~~~" PM_COLOR_RESET
"\n"
10712 .number_prefix =
"%5" PRIi32
" | ",
10713 .blank_prefix =
" | ",
10714 .divider =
" ~~~~~~~~\n"
10728 uint32_t last_column_start = 0;
10731 for (
size_t index = 0; index < error_list->
size; index++) {
10736 if (error->
line - last_line > 1) {
10737 if (error->
line - last_line > 2) {
10738 if ((index != 0) && (error->
line - last_line > 3)) {
10742 pm_buffer_append_string(buffer,
" ", 2);
10743 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, error->
line - 2, 0, 0, buffer);
10746 pm_buffer_append_string(buffer,
" ", 2);
10747 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, error->
line - 1, 0, 0, buffer);
10752 if ((index == 0) || (error->
line != last_line)) {
10753 if (highlight > 1) {
10754 pm_buffer_append_literal(buffer, PM_COLOR_RED
"> " PM_COLOR_RESET);
10755 }
else if (highlight > 0) {
10756 pm_buffer_append_literal(buffer, PM_COLOR_BOLD
"> " PM_COLOR_RESET);
10758 pm_buffer_append_literal(buffer,
"> ");
10765 for (
size_t next_index = index + 1; next_index < error_list->
size; next_index++) {
10766 if (errors[next_index].line != error->
line)
break;
10767 if (errors[next_index].column_end > column_end) column_end = errors[next_index].
column_end;
10773 const uint8_t *start = &parser->
start[newline_list->
offsets[error->
line - start_line]];
10774 if (start == parser->
end) pm_buffer_append_byte(buffer,
'\n');
10785 pm_buffer_append_string(buffer,
" ", 2);
10789 if (last_column_start >= PM_ERROR_TRUNCATE) {
10790 pm_buffer_append_string(buffer,
" ", 4);
10791 column = last_column_start;
10794 while (column < error->column_start) {
10795 pm_buffer_append_byte(buffer,
' ');
10797 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10798 column += (char_width == 0 ? 1 : char_width);
10801 if (highlight > 1) pm_buffer_append_literal(buffer, PM_COLOR_RED);
10802 else if (highlight > 0) pm_buffer_append_literal(buffer, PM_COLOR_BOLD);
10803 pm_buffer_append_byte(buffer,
'^');
10805 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10806 column += (char_width == 0 ? 1 : char_width);
10808 while (column < error->column_end) {
10809 pm_buffer_append_byte(buffer,
'~');
10811 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10812 column += (char_width == 0 ? 1 : char_width);
10815 if (highlight > 0) pm_buffer_append_literal(buffer, PM_COLOR_RESET);
10817 if (inline_messages) {
10818 pm_buffer_append_byte(buffer,
' ');
10819 assert(error->
error != NULL);
10822 pm_buffer_append_string(buffer, message, strlen(message));
10825 pm_buffer_append_byte(buffer,
'\n');
10829 last_line = error->
line;
10832 if (index == error_list->
size - 1) {
10833 next_line = (((int32_t) newline_list->
size) + parser->
start_line);
10842 next_line = errors[index + 1].
line;
10845 if (next_line - last_line > 1) {
10846 pm_buffer_append_string(buffer,
" ", 2);
10847 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, ++last_line, 0, 0, buffer);
10850 if (next_line - last_line > 1) {
10851 pm_buffer_append_string(buffer,
" ", 2);
10852 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, ++last_line, 0, 0, buffer);
10860#undef PM_ERROR_TRUNCATE
10861#undef PM_COLOR_GRAY
10863#undef PM_COLOR_RESET
10874 const size_t start_line = pm_newline_list_line_column(&parser->
newline_list, location->
start, 1).line;
10875 const size_t end_line = pm_newline_list_line_column(&parser->
newline_list, location->
end, 1).line;
10881 while (start < end) {
10882 if ((width = pm_encoding_utf_8_char_width(start, end - start)) == 0)
return false;
10898 bool valid_utf8 =
true;
10903 int highlight = rb_stderr_tty_p();
10905 const char *no_color = getenv(
"NO_COLOR");
10906 highlight = (no_color == NULL || no_color[0] ==
'\0') ? 2 : 1;
10910 switch (error->level) {
10917 if (valid_utf8 && !pm_parse_process_error_utf8_p(parser, &error->location)) {
10918 valid_utf8 =
false;
10925 int32_t line_number = (int32_t) pm_location_line_number(parser, &error->location);
10927 pm_buffer_append_format(
10929 "%.*s:%" PRIi32
": %s",
10930 (
int) pm_string_length(filepath),
10931 pm_string_source(filepath),
10936 if (pm_parse_process_error_utf8_p(parser, &error->location)) {
10937 pm_buffer_append_byte(&buffer,
'\n');
10940 pm_list_t error_list = { .size = 1, .head = list_node, .tail = list_node };
10942 pm_parse_errors_format(parser, &error_list, &buffer, highlight,
false);
10945 VALUE value =
rb_exc_new(rb_eArgError, pm_buffer_value(&buffer), pm_buffer_length(&buffer));
10946 pm_buffer_free(&buffer);
10962 pm_buffer_append_format(
10964 "%.*s:%" PRIi32
": syntax error%s found\n",
10965 (
int) pm_string_length(filepath),
10966 pm_string_source(filepath),
10967 (int32_t) pm_location_line_number(parser, &head->location),
10972 pm_parse_errors_format(parser, &parser->
error_list, &buffer, highlight,
true);
10976 if (error != head) pm_buffer_append_byte(&buffer,
'\n');
10977 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);
10981 VALUE message = rb_enc_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer), result->
node.encoding);
10985 VALUE path = rb_enc_str_new((
const char *) pm_string_source(filepath), pm_string_length(filepath), filepath_encoding);
10988 pm_buffer_free(&buffer);
11005 pm_scope_node_t *scope_node = &result->
node;
11007 int coverage_enabled = scope_node->coverage_enabled;
11009 pm_scope_node_init(node, scope_node, NULL);
11012 scope_node->encoding = rb_enc_find(parser->
encoding->
name);
11013 if (!scope_node->encoding) rb_bug(
"Encoding not found %s!", parser->
encoding->
name);
11015 scope_node->coverage_enabled = coverage_enabled;
11019 if (script_lines != NULL) {
11024 size_t length = index == parser->
newline_list.
size - 1 ? ((size_t) (parser->
end - (parser->
start + offset))) : (parser->newline_list.offsets[index + 1] - offset);
11025 rb_ary_push(*script_lines, rb_enc_str_new((
const char *) parser->
start + offset, length, scope_node->encoding));
11033 const char *warning_filepath = (
const char *) pm_string_source(&parser->
filepath);
11036 int line = pm_location_line_number(parser, &warning->
location);
11039 rb_enc_compile_warning(scope_node->encoding, warning_filepath, line,
"%s", warning->
message);
11042 rb_enc_compile_warn(scope_node->encoding, warning_filepath, line,
"%s", warning->
message);
11048 VALUE error = pm_parse_process_error(result);
11057 scope_node->parser = parser;
11062 scope_node->constants[index] = rb_intern3((
const char *) constant->
start, constant->
length, scope_node->encoding);
11065 scope_node->index_lookup_table = st_init_numtable();
11067 for (
size_t index = 0; index < locals->
size; index++) {
11068 st_insert(scope_node->index_lookup_table, locals->
ids[index], index);
11082pm_options_frozen_string_literal_init(
pm_options_t *options)
11084 int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
11086 switch (frozen_string_literal) {
11087 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
11089 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
11090 pm_options_frozen_string_literal_set(options,
false);
11092 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
11093 pm_options_frozen_string_literal_set(options,
true);
11096 rb_bug(
"pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
11106pm_parse_file_script_lines(
const pm_scope_node_t *scope_node,
const pm_parser_t *parser)
11109 const char *start = (
const char *) parser->
start;
11110 const char *end = (
const char *) parser->
end;
11115 size_t last_offset = newline_list->
offsets[newline_list->
size - 1];
11116 bool last_push = start + last_offset != end;
11119 VALUE lines = rb_ary_new_capa(newline_list->
size - (last_push ? 0 : 1));
11121 for (
size_t index = 0; index < newline_list->
size - 1; index++) {
11122 size_t offset = newline_list->
offsets[index];
11123 size_t length = newline_list->
offsets[index + 1] - offset;
11125 rb_ary_push(lines, rb_enc_str_new(start + offset, length, scope_node->encoding));
11130 rb_ary_push(lines, rb_enc_str_new(start + last_offset, end - (start + last_offset), scope_node->encoding));
11140pm_read_file(
pm_string_t *
string,
const char *filepath)
11144 int length = MultiByteToWideChar(CP_UTF8, 0, filepath, -1, NULL, 0);
11147 WCHAR *wfilepath =
xmalloc(
sizeof(WCHAR) * ((
size_t) length));
11148 if ((wfilepath == NULL) || (MultiByteToWideChar(CP_UTF8, 0, filepath, -1, wfilepath, length) == 0)) {
11153 HANDLE file = CreateFileW(wfilepath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
11154 if (file == INVALID_HANDLE_VALUE) {
11157 if (GetLastError() == ERROR_ACCESS_DENIED) {
11158 DWORD attributes = GetFileAttributesW(wfilepath);
11159 if ((attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
11169 DWORD file_size = GetFileSize(file, NULL);
11170 if (file_size == INVALID_FILE_SIZE) {
11178 if (file_size == 0) {
11181 const uint8_t source[] =
"";
11182 *
string = (
pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
11187 HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
11188 if (mapping == NULL) {
11195 uint8_t *source = (uint8_t *) MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
11196 CloseHandle(mapping);
11200 if (source == NULL) {
11204 *
string = (
pm_string_t) { .type = PM_STRING_MAPPED, .source = source, .length = (size_t) file_size };
11206#elif defined(_POSIX_MAPPED_FILES)
11208 const int open_mode = O_RDONLY | O_NONBLOCK;
11209 int fd = open(filepath, open_mode);
11216 if (fstat(fd, &sb) == -1) {
11222 if (S_ISDIR(sb.st_mode)) {
11230 if (S_ISFIFO(sb.st_mode) || S_ISCHR(sb.st_mode)) {
11239 long len = RSTRING_LEN(contents);
11244 size_t length = (size_t)
len;
11245 uint8_t *source = malloc(length);
11246 memcpy(source, RSTRING_PTR(contents), length);
11247 *
string = (
pm_string_t) { .type = PM_STRING_OWNED, .source = source, .length = length };
11253 size_t size = (size_t) sb.st_size;
11254 uint8_t *source = NULL;
11258 const uint8_t source[] =
"";
11259 *
string = (
pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
11263 source = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
11264 if (source == MAP_FAILED) {
11270 *
string = (
pm_string_t) { .type = PM_STRING_MAPPED, .source = source, .length = size };
11273 return pm_string_file_init(
string, filepath);
11287 pm_options_frozen_string_literal_init(&result->
options);
11296 err = rb_w32_map_errno(GetLastError());
11328 pm_options_filepath_set(&result->
options, RSTRING_PTR(filepath));
11331 pm_parser_init(&result->
parser, pm_string_source(&result->
input), pm_string_length(&result->
input), &result->
options);
11334 VALUE error = pm_parse_process(result, node, script_lines);
11339 ID id_script_lines = rb_intern(
"SCRIPT_LINES__");
11345 rb_hash_aset(constant_script_lines, filepath, pm_parse_file_script_lines(&result->
node, &result->
parser));
11359 VALUE error = pm_load_file(result, filepath,
false);
11360 if (
NIL_P(error)) {
11361 error = pm_parse_file(result, filepath, script_lines);
11376 rb_encoding *encoding = rb_enc_get(source);
11377 if (!rb_enc_asciicompat(encoding)) {
11381 pm_options_frozen_string_literal_init(&result->
options);
11382 pm_string_constant_init(&result->
input, RSTRING_PTR(source), RSTRING_LEN(source));
11383 pm_options_encoding_set(&result->
options, rb_enc_name(encoding));
11386 pm_options_filepath_set(&result->
options, RSTRING_PTR(filepath));
11389 pm_parser_init(&result->
parser, pm_string_source(&result->
input), pm_string_length(&result->
input), &result->
options);
11392 return pm_parse_process(result, node, script_lines);
11399pm_parse_stdin_fgets(
char *
string,
int size,
void *stream)
11408 const char *cstr = RSTRING_PTR(line);
11409 long length = RSTRING_LEN(line);
11411 memcpy(
string, cstr, length);
11412 string[length] =
'\0';
11418void rb_reset_argf_lineno(
long n);
11428 pm_options_frozen_string_literal_init(&result->
options);
11436 pm_string_owned_init(&result->
input, (uint8_t *) pm_buffer_value(&buffer), pm_buffer_length(&buffer));
11440 rb_reset_argf_lineno(0);
11442 return pm_parse_process(result, node, NULL);
11446#define NEW_ISEQ OLD_ISEQ
11448#undef NEW_CHILD_ISEQ
11449#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.
struct pm_block_parameter_node pm_block_parameter_node_t
BlockParameterNode.
struct pm_call_target_node pm_call_target_node_t
CallTargetNode.
struct pm_else_node pm_else_node_t
ElseNode.
struct pm_assoc_node pm_assoc_node_t
AssocNode.
struct pm_undef_node pm_undef_node_t
UndefNode.
struct pm_class_variable_and_write_node pm_class_variable_and_write_node_t
ClassVariableAndWriteNode.
struct pm_index_and_write_node pm_index_and_write_node_t
IndexAndWriteNode.
struct pm_index_target_node pm_index_target_node_t
IndexTargetNode.
struct pm_local_variable_target_node pm_local_variable_target_node_t
LocalVariableTargetNode.
struct pm_constant_path_or_write_node pm_constant_path_or_write_node_t
ConstantPathOrWriteNode.
struct pm_embedded_statements_node pm_embedded_statements_node_t
EmbeddedStatementsNode.
struct pm_block_node pm_block_node_t
BlockNode.
struct pm_hash_pattern_node pm_hash_pattern_node_t
HashPatternNode.
struct pm_optional_parameter_node pm_optional_parameter_node_t
OptionalParameterNode.
struct pm_x_string_node pm_x_string_node_t
XStringNode.
struct pm_forwarding_super_node pm_forwarding_super_node_t
ForwardingSuperNode.
struct pm_numbered_reference_read_node pm_numbered_reference_read_node_t
NumberedReferenceReadNode.
struct pm_embedded_variable_node pm_embedded_variable_node_t
EmbeddedVariableNode.
struct pm_class_variable_write_node pm_class_variable_write_node_t
ClassVariableWriteNode.
struct pm_interpolated_string_node pm_interpolated_string_node_t
InterpolatedStringNode.
struct pm_class_variable_or_write_node pm_class_variable_or_write_node_t
ClassVariableOrWriteNode.
struct pm_optional_keyword_parameter_node pm_optional_keyword_parameter_node_t
OptionalKeywordParameterNode.
struct pm_call_or_write_node pm_call_or_write_node_t
CallOrWriteNode.
struct pm_call_node pm_call_node_t
CallNode.
struct pm_class_variable_read_node pm_class_variable_read_node_t
ClassVariableReadNode.
struct pm_match_required_node pm_match_required_node_t
MatchRequiredNode.
struct pm_shareable_constant_node pm_shareable_constant_node_t
ShareableConstantNode.
struct pm_constant_and_write_node pm_constant_and_write_node_t
ConstantAndWriteNode.
@ 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...
struct pm_constant_path_operator_write_node pm_constant_path_operator_write_node_t
ConstantPathOperatorWriteNode.
@ PM_RANGE_FLAGS_EXCLUDE_END
... operator
struct pm_local_variable_or_write_node pm_local_variable_or_write_node_t
LocalVariableOrWriteNode.
struct pm_local_variable_read_node pm_local_variable_read_node_t
LocalVariableReadNode.
struct pm_global_variable_and_write_node pm_global_variable_and_write_node_t
GlobalVariableAndWriteNode.
struct pm_arguments_node pm_arguments_node_t
ArgumentsNode.
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_BLOCK_LOCAL_VARIABLE_NODE
BlockLocalVariableNode.
@ 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_BLOCK_PARAMETER_NODE
BlockParameterNode.
@ 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_REST_PARAMETER_NODE
RestParameterNode.
@ PM_EMBEDDED_STATEMENTS_NODE
EmbeddedStatementsNode.
@ PM_INTERPOLATED_REGULAR_EXPRESSION_NODE
InterpolatedRegularExpressionNode.
@ PM_INDEX_TARGET_NODE
IndexTargetNode.
@ PM_KEYWORD_REST_PARAMETER_NODE
KeywordRestParameterNode.
struct pm_begin_node pm_begin_node_t
BeginNode.
struct pm_statements_node pm_statements_node_t
StatementsNode.
struct pm_instance_variable_write_node pm_instance_variable_write_node_t
InstanceVariableWriteNode.
struct pm_keyword_hash_node pm_keyword_hash_node_t
KeywordHashNode.
struct pm_return_node pm_return_node_t
ReturnNode.
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
struct pm_constant_path_node pm_constant_path_node_t
ConstantPathNode.
struct pm_local_variable_write_node pm_local_variable_write_node_t
LocalVariableWriteNode.
@ 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
struct pm_implicit_node pm_implicit_node_t
ImplicitNode.
struct pm_yield_node pm_yield_node_t
YieldNode.
@ 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
struct pm_local_variable_and_write_node pm_local_variable_and_write_node_t
LocalVariableAndWriteNode.
struct pm_parameters_node pm_parameters_node_t
ParametersNode.
struct pm_lambda_node pm_lambda_node_t
LambdaNode.
#define PM_NODE_FLAG_P(node, flag)
Return true if the given flag is set on the given node.
struct pm_module_node pm_module_node_t
ModuleNode.
struct pm_case_node pm_case_node_t
CaseNode.
struct pm_in_node pm_in_node_t
InNode.
struct pm_if_node pm_if_node_t
IfNode.
struct pm_constant_path_write_node pm_constant_path_write_node_t
ConstantPathWriteNode.
struct pm_pre_execution_node pm_pre_execution_node_t
PreExecutionNode.
struct pm_rescue_modifier_node pm_rescue_modifier_node_t
RescueModifierNode.
struct pm_splat_node pm_splat_node_t
SplatNode.
struct pm_match_write_node pm_match_write_node_t
MatchWriteNode.
struct pm_multi_write_node pm_multi_write_node_t
MultiWriteNode.
struct pm_local_variable_operator_write_node pm_local_variable_operator_write_node_t
LocalVariableOperatorWriteNode.
struct pm_block_argument_node pm_block_argument_node_t
BlockArgumentNode.
struct pm_interpolated_x_string_node pm_interpolated_x_string_node_t
InterpolatedXStringNode.
struct pm_constant_write_node pm_constant_write_node_t
ConstantWriteNode.
struct pm_flip_flop_node pm_flip_flop_node_t
FlipFlopNode.
struct pm_required_keyword_parameter_node pm_required_keyword_parameter_node_t
RequiredKeywordParameterNode.
#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.
struct pm_alias_global_variable_node pm_alias_global_variable_node_t
AliasGlobalVariableNode.
struct pm_post_execution_node pm_post_execution_node_t
PostExecutionNode.
struct pm_alias_method_node pm_alias_method_node_t
AliasMethodNode.
struct pm_keyword_rest_parameter_node pm_keyword_rest_parameter_node_t
KeywordRestParameterNode.
struct pm_global_variable_read_node pm_global_variable_read_node_t
GlobalVariableReadNode.
struct pm_back_reference_read_node pm_back_reference_read_node_t
BackReferenceReadNode.
struct pm_match_last_line_node pm_match_last_line_node_t
MatchLastLineNode.
struct pm_hash_node pm_hash_node_t
HashNode.
struct pm_block_local_variable_node pm_block_local_variable_node_t
BlockLocalVariableNode.
struct pm_multi_target_node pm_multi_target_node_t
MultiTargetNode.
struct pm_rational_node pm_rational_node_t
RationalNode.
struct pm_class_node pm_class_node_t
ClassNode.
struct pm_pinned_expression_node pm_pinned_expression_node_t
PinnedExpressionNode.
struct pm_constant_operator_write_node pm_constant_operator_write_node_t
ConstantOperatorWriteNode.
struct pm_ensure_node pm_ensure_node_t
EnsureNode.
struct pm_index_or_write_node pm_index_or_write_node_t
IndexOrWriteNode.
struct pm_constant_or_write_node pm_constant_or_write_node_t
ConstantOrWriteNode.
struct pm_index_operator_write_node pm_index_operator_write_node_t
IndexOperatorWriteNode.
struct pm_when_node pm_when_node_t
WhenNode.
struct pm_super_node pm_super_node_t
SuperNode.
struct pm_range_node pm_range_node_t
RangeNode.
struct pm_and_node pm_and_node_t
AndNode.
struct pm_constant_path_and_write_node pm_constant_path_and_write_node_t
ConstantPathAndWriteNode.
struct pm_rest_parameter_node pm_rest_parameter_node_t
RestParameterNode.
struct pm_assoc_splat_node pm_assoc_splat_node_t
AssocSplatNode.
@ 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
struct pm_constant_read_node pm_constant_read_node_t
ConstantReadNode.
struct pm_match_predicate_node pm_match_predicate_node_t
MatchPredicateNode.
struct pm_or_node pm_or_node_t
OrNode.
struct pm_case_match_node pm_case_match_node_t
CaseMatchNode.
struct pm_call_and_write_node pm_call_and_write_node_t
CallAndWriteNode.
@ 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
struct pm_until_node pm_until_node_t
UntilNode.
uint16_t pm_node_type_t
This is the type of node embedded in the node struct.
struct pm_imaginary_node pm_imaginary_node_t
ImaginaryNode.
struct pm_array_pattern_node pm_array_pattern_node_t
ArrayPatternNode.
@ 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...
struct pm_break_node pm_break_node_t
BreakNode.
struct pm_integer_node pm_integer_node_t
IntegerNode.
struct pm_constant_path_target_node pm_constant_path_target_node_t
ConstantPathTargetNode.
struct pm_call_operator_write_node pm_call_operator_write_node_t
CallOperatorWriteNode.
struct pm_for_node pm_for_node_t
ForNode.
struct pm_global_variable_target_node pm_global_variable_target_node_t
GlobalVariableTargetNode.
struct pm_node_list pm_node_list_t
A list of nodes in the source, most often used for lists of children.
struct pm_required_parameter_node pm_required_parameter_node_t
RequiredParameterNode.
struct pm_symbol_node pm_symbol_node_t
SymbolNode.
struct pm_block_parameters_node pm_block_parameters_node_t
BlockParametersNode.
struct pm_alternation_pattern_node pm_alternation_pattern_node_t
AlternationPatternNode.
struct pm_parentheses_node pm_parentheses_node_t
ParenthesesNode.
@ 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
struct pm_instance_variable_read_node pm_instance_variable_read_node_t
InstanceVariableReadNode.
struct pm_constant_target_node pm_constant_target_node_t
ConstantTargetNode.
struct pm_node pm_node_t
This is the base structure that represents a node in the syntax tree.
struct pm_defined_node pm_defined_node_t
DefinedNode.
struct pm_interpolated_symbol_node pm_interpolated_symbol_node_t
InterpolatedSymbolNode.
struct pm_class_variable_target_node pm_class_variable_target_node_t
ClassVariableTargetNode.
struct pm_def_node pm_def_node_t
DefNode.
struct pm_singleton_class_node pm_singleton_class_node_t
SingletonClassNode.
uint16_t pm_node_flags_t
These are the flags embedded in the node struct.
struct pm_capture_pattern_node pm_capture_pattern_node_t
CapturePatternNode.
struct pm_source_file_node pm_source_file_node_t
SourceFileNode.
struct pm_regular_expression_node pm_regular_expression_node_t
RegularExpressionNode.
struct pm_global_variable_or_write_node pm_global_variable_or_write_node_t
GlobalVariableOrWriteNode.
struct pm_rescue_node pm_rescue_node_t
RescueNode.
struct pm_array_node pm_array_node_t
ArrayNode.
struct pm_while_node pm_while_node_t
WhileNode.
struct pm_global_variable_write_node pm_global_variable_write_node_t
GlobalVariableWriteNode.
struct pm_instance_variable_or_write_node pm_instance_variable_or_write_node_t
InstanceVariableOrWriteNode.
@ 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
struct pm_interpolated_match_last_line_node pm_interpolated_match_last_line_node_t
InterpolatedMatchLastLineNode.
struct pm_numbered_parameters_node pm_numbered_parameters_node_t
NumberedParametersNode.
struct pm_class_variable_operator_write_node pm_class_variable_operator_write_node_t
ClassVariableOperatorWriteNode.
struct pm_next_node pm_next_node_t
NextNode.
struct pm_unless_node pm_unless_node_t
UnlessNode.
struct pm_interpolated_regular_expression_node pm_interpolated_regular_expression_node_t
InterpolatedRegularExpressionNode.
struct pm_instance_variable_target_node pm_instance_variable_target_node_t
InstanceVariableTargetNode.
struct pm_string_node pm_string_node_t
StringNode.
struct pm_float_node pm_float_node_t
FloatNode.
struct pm_global_variable_operator_write_node pm_global_variable_operator_write_node_t
GlobalVariableOperatorWriteNode.
struct pm_instance_variable_operator_write_node pm_instance_variable_operator_write_node_t
InstanceVariableOperatorWriteNode.
@ PM_LOOP_FLAGS_BEGIN_MODIFIER
a loop after a begin statement, so the body is executed first before the condition
struct pm_pinned_variable_node pm_pinned_variable_node_t
PinnedVariableNode.
struct pm_instance_variable_and_write_node pm_instance_variable_and_write_node_t
InstanceVariableAndWriteNode.
struct pm_program_node pm_program_node_t
ProgramNode.
struct pm_find_pattern_node pm_find_pattern_node_t
FindPatternNode.
@ 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.
struct pm_options pm_options_t
The options that can be passed to the parser.
struct pm_parser pm_parser_t
The parser used to parse Ruby source.
uint32_t pm_constant_id_t
A constant id is a unique identifier for a constant in the constant pool.
struct pm_list_node pm_list_node_t
This struct represents an abstract linked list that provides common functionality.
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.
pm_node_t base
The embedded base node.
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.
struct pm_node * value
ClassVariableAndWriteNode#value.
pm_constant_id_t name
ClassVariableAndWriteNode#name.
pm_constant_id_t name
ClassVariableOperatorWriteNode#name.
pm_constant_id_t binary_operator
ClassVariableOperatorWriteNode#binary_operator.
struct pm_node * value
ClassVariableOperatorWriteNode#value.
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.
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.
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.
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.
struct pm_node * value
GlobalVariableAndWriteNode#value.
pm_constant_id_t name
GlobalVariableAndWriteNode#name.
pm_constant_id_t name
GlobalVariableOperatorWriteNode#name.
pm_constant_id_t binary_operator
GlobalVariableOperatorWriteNode#binary_operator.
struct pm_node * value
GlobalVariableOperatorWriteNode#value.
pm_constant_id_t name
GlobalVariableOrWriteNode#name.
struct pm_node * value
GlobalVariableOrWriteNode#value.
pm_constant_id_t name
GlobalVariableReadNode#name.
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.
struct pm_node * value
InstanceVariableAndWriteNode#value.
pm_constant_id_t name
InstanceVariableAndWriteNode#name.
struct pm_node * value
InstanceVariableOperatorWriteNode#value.
pm_constant_id_t binary_operator
InstanceVariableOperatorWriteNode#binary_operator.
pm_constant_id_t name
InstanceVariableOperatorWriteNode#name.
struct pm_node * value
InstanceVariableOrWriteNode#value.
pm_constant_id_t name
InstanceVariableOrWriteNode#name.
pm_constant_id_t name
InstanceVariableReadNode#name.
pm_constant_id_t name
InstanceVariableTargetNode#name.
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.
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.
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.
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.
pm_constant_id_t name
LocalVariableAndWriteNode#name.
uint32_t depth
LocalVariableAndWriteNode#depth.
struct pm_node * value
LocalVariableAndWriteNode#value.
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.
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.
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.
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.
uint32_t number
NumberedReferenceReadNode#number.
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.
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.
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.
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::@000024342312237062266020177166377106262102236123 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.