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;
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;
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;
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;
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)
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)
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);
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;
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);
1268 pm_scope_node_destroy(node);
1270 rb_jump_tag(error_state);
1272 debugs(
"[new_child_iseq]< ---------------------------------------\n");
1277pm_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)
1285 return VM_DEFINECLASS_FLAG_SCOPED;
1289 PUSH_INSN1(ret, *node_location, putobject, rb_cObject);
1290 return VM_DEFINECLASS_FLAG_SCOPED;
1295 PUSH_INSN1(ret, *node_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
1305pm_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)
1308 LABEL *lfin = NEW_LABEL(location.
line);
1309 LABEL *lcfin = NEW_LABEL(location.
line);
1310 LABEL *lskip = NULL;
1313 ID id_read_name = pm_constant_id_lookup(scope_node, read_name);
1315 PM_COMPILE_NOT_POPPED(receiver);
1317 lskip = NEW_LABEL(location.
line);
1318 PUSH_INSN(ret, location, dup);
1319 PUSH_INSNL(ret, location, branchnil, lskip);
1322 PUSH_INSN(ret, location, dup);
1323 PUSH_SEND_WITH_FLAG(ret, location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
1324 if (!popped) PUSH_INSN(ret, location, dup);
1327 PUSH_INSNL(ret, location, branchunless, lcfin);
1330 PUSH_INSNL(ret, location, branchif, lcfin);
1333 if (!popped) PUSH_INSN(ret, location, pop);
1334 PM_COMPILE_NOT_POPPED(value);
1337 PUSH_INSN(ret, location, swap);
1338 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
1341 ID id_write_name = pm_constant_id_lookup(scope_node, write_name);
1342 PUSH_SEND_WITH_FLAG(ret, location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
1343 PUSH_INSNL(ret, location, jump, lfin);
1345 PUSH_LABEL(ret, lcfin);
1346 if (!popped) PUSH_INSN(ret, location, swap);
1348 PUSH_LABEL(ret, lfin);
1350 if (lskip && popped) PUSH_LABEL(ret, lskip);
1351 PUSH_INSN(ret, location, pop);
1352 if (lskip && !popped) PUSH_LABEL(ret, lskip);
1355static 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);
1363pm_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)
1365 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
1371 const int max_stack_length = 0x100;
1372 const unsigned int min_tmp_hash_length = 0x800;
1374 int stack_length = 0;
1375 bool first_chunk =
true;
1381 bool static_literal =
false;
1383 DECL_ANCHOR(anchor);
1386#define FLUSH_CHUNK \
1387 if (stack_length) { \
1388 if (first_chunk) { \
1389 PUSH_SEQ(ret, anchor); \
1390 PUSH_INSN1(ret, location, newhash, INT2FIX(stack_length)); \
1391 first_chunk = false; \
1394 PUSH_INSN1(ret, location, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); \
1395 PUSH_INSN(ret, location, swap); \
1396 PUSH_SEQ(ret, anchor); \
1397 PUSH_SEND(ret, location, id_core_hash_merge_ptr, INT2FIX(stack_length + 1)); \
1399 INIT_ANCHOR(anchor); \
1403 for (
size_t index = 0; index < elements->
size; index++) {
1410 (shareability == 0) &&
1412 (!static_literal && ((index + min_tmp_hash_length) < elements->
size)) ||
1413 (first_chunk && stack_length == 0)
1418 while (index + count < elements->size &&
PM_NODE_FLAG_P(elements->
nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++;
1420 if ((first_chunk && stack_length == 0) || count >= min_tmp_hash_length) {
1423 VALUE ary = rb_ary_hidden_new(count);
1426 for (
size_t tmp_end = index + count; index < tmp_end; index++) {
1430 pm_static_literal_value(iseq, assoc->key, scope_node),
1431 pm_static_literal_value(iseq, assoc->value, scope_node)
1434 rb_ary_cat(ary, elem, 2);
1446 PUSH_INSN1(ret, location, duphash, hash);
1447 first_chunk =
false;
1450 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1451 PUSH_INSN(ret, location, swap);
1452 PUSH_INSN1(ret, location, putobject, hash);
1453 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1459 static_literal =
true;
1463 static_literal =
false;
1468 if (shareability == 0) {
1469 pm_compile_node(iseq, element, anchor,
false, scope_node);
1473 pm_compile_shareable_constant_value(iseq, assoc->
key, shareability, path, ret, scope_node,
false);
1474 pm_compile_shareable_constant_value(iseq, assoc->
value, shareability, path, ret, scope_node,
false);
1477 if ((stack_length += 2) >= max_stack_length) FLUSH_CHUNK;
1484 bool empty_hash = assoc_splat->
value != NULL && (
1489 bool first_element = first_chunk && stack_length == 0;
1490 bool last_element = index == elements->
size - 1;
1491 bool only_element = first_element && last_element;
1494 if (only_element && argument) {
1501 PUSH_INSN(ret, location, putnil);
1503 else if (first_element) {
1506 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1513 if (only_element && argument) {
1519 if (shareability == 0) {
1520 PM_COMPILE_NOT_POPPED(element);
1523 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1531 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1533 if (first_element) {
1534 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1537 PUSH_INSN(ret, location, swap);
1540 if (shareability == 0) {
1541 PM_COMPILE_NOT_POPPED(element);
1544 pm_compile_shareable_constant_value(iseq, element, shareability, path, ret, scope_node,
false);
1547 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1551 first_chunk =
false;
1552 static_literal =
false;
1556 RUBY_ASSERT(
"Invalid node type for hash" &&
false);
1565#define SPLATARRAY_FALSE 0
1566#define SPLATARRAY_TRUE 1
1567#define DUP_SINGLE_KW_SPLAT 2
1576 bool has_splat =
false;
1577 bool has_keyword_splat =
false;
1579 if (arguments_node == NULL) {
1580 if (*flags & VM_CALL_FCALL) {
1581 *flags |= VM_CALL_VCALL;
1590 int post_splat_counter = 0;
1600 if (has_keyword_splat || has_splat) {
1601 *flags |= VM_CALL_KW_SPLAT;
1602 has_keyword_splat =
true;
1608 *flags |= VM_CALL_KW_SPLAT_MUT;
1609 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1611 else if (*dup_rest & DUP_SINGLE_KW_SPLAT) {
1612 *flags |= VM_CALL_KW_SPLAT_MUT;
1613 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
1614 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
1615 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1616 PUSH_SEND(ret, location, id_core_hash_merge_kwd,
INT2FIX(2));
1619 pm_compile_hash_elements(iseq, argument, elements, 0,
Qundef,
true, ret, scope_node);
1631 VALUE keyword_indices = rb_ary_new_capa(elements->
size);
1634 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1639 VALUE keyword = pm_static_literal_value(iseq, assoc->key, scope_node);
1640 VALUE stored_index = rb_hash_aref(stored_indices, keyword);
1645 if (!
NIL_P(stored_index)) {
1653 rb_hash_aset(stored_indices, keyword,
ULONG2NUM(element_index));
1654 rb_ary_store(keyword_indices, (
long) element_index,
Qtrue);
1659 *flags |= VM_CALL_KWARG;
1661 VALUE *keywords = (*kw_arg)->keywords;
1662 (*kw_arg)->references = 0;
1663 (*kw_arg)->keyword_len = (int) size;
1665 size_t keyword_index = 0;
1666 for (
size_t element_index = 0; element_index < elements->
size; element_index++) {
1670 if (rb_ary_entry(keyword_indices, (
long) element_index) ==
Qtrue) {
1671 keywords[keyword_index++] = pm_static_literal_value(iseq, assoc->key, scope_node);
1675 PM_COMPILE(assoc->value);
1684 *flags |= VM_CALL_KW_SPLAT;
1686 size_t size = elements->
size;
1691 *flags |= VM_CALL_KW_SPLAT_MUT;
1694 for (
size_t element_index = 0; element_index < size; element_index++) {
1696 PM_COMPILE_NOT_POPPED(assoc->key);
1697 PM_COMPILE_NOT_POPPED(assoc->value);
1700 PUSH_INSN1(ret, location, newhash,
INT2FIX(size * 2));
1706 *flags |= VM_CALL_ARGS_SPLAT;
1710 PM_COMPILE_NOT_POPPED(splat_node->
expression);
1713 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1714 PUSH_GETLOCAL(ret, location, index.index, index.level);
1717 bool first_splat = !has_splat;
1725 if (index + 1 < arguments->
size || has_regular_blockarg) {
1726 PUSH_INSN1(ret, location, splatarray, (*dup_rest & SPLATARRAY_TRUE) ?
Qtrue :
Qfalse);
1727 if (*dup_rest & SPLATARRAY_TRUE) *dup_rest &= ~SPLATARRAY_TRUE;
1735 PUSH_INSN1(ret, location, splatarray,
Qfalse);
1745 PUSH_INSN(ret, location, concattoarray);
1749 post_splat_counter = 0;
1754 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
1756 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.forwardable) {
1757 *flags |= VM_CALL_FORWARDING;
1759 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
1760 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1767 *flags |= VM_CALL_ARGS_SPLAT | VM_CALL_ARGS_SPLAT_MUT | VM_CALL_ARGS_BLOCKARG | VM_CALL_KW_SPLAT;
1774 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
1775 PUSH_GETLOCAL(ret, location, mult_local.index, mult_local.level);
1776 PUSH_INSN1(ret, location, splatarray,
Qtrue);
1779 pm_local_index_t pow_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1780 PUSH_GETLOCAL(ret, location, pow_local.index, pow_local.level);
1783 pm_local_index_t and_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
1784 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(and_local.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(and_local.level));
1785 PUSH_INSN(ret, location, splatkw);
1790 post_splat_counter++;
1791 PM_COMPILE_NOT_POPPED(argument);
1811 if (index == arguments->
size - 1) {
1813 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(post_splat_counter));
1821 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1822 PUSH_INSN(ret, location, concatarray);
1826 PUSH_INSN1(ret, location, newarray,
INT2FIX(post_splat_counter));
1827 PUSH_INSN(ret, location, concatarray);
1843 if (has_splat) orig_argc++;
1844 if (has_keyword_splat) orig_argc++;
1853pm_setup_args_dup_rest_p(
const pm_node_t *node)
1878 if (cast->
parent != NULL) {
1879 return pm_setup_args_dup_rest_p(cast->
parent);
1896 int dup_rest = SPLATARRAY_TRUE;
1899 size_t arguments_size;
1904 arguments_node != NULL &&
1905 (arguments = &arguments_node->
arguments, arguments_size = arguments->
size) >= 2 &&
1913 dup_rest = SPLATARRAY_FALSE;
1918 for (
size_t index = 0; dup_rest == SPLATARRAY_FALSE && index < elements->
size; index++) {
1924 if (pm_setup_args_dup_rest_p(assoc->
key) || pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
1929 if (assoc->
value != NULL && pm_setup_args_dup_rest_p(assoc->
value)) dup_rest = SPLATARRAY_TRUE;
1938 int initial_dup_rest = dup_rest;
1945 bool regular_block_arg =
true;
1948 if (block_expr && pm_setup_args_dup_rest_p(block_expr)) {
1949 dup_rest = SPLATARRAY_TRUE | DUP_SINGLE_KW_SPLAT;
1950 initial_dup_rest = dup_rest;
1953 DECL_ANCHOR(block_arg);
1954 pm_compile_node(iseq, block, block_arg,
false, scope_node);
1956 *flags |= VM_CALL_ARGS_BLOCKARG;
1958 if (LIST_INSN_SIZE_ONE(block_arg)) {
1959 LINK_ELEMENT *elem = FIRST_ELEMENT(block_arg);
1960 if (IS_INSN(elem)) {
1961 INSN *iobj = (INSN *) elem;
1962 if (iobj->insn_id == BIN(getblockparam)) {
1963 iobj->insn_id = BIN(getblockparamproxy);
1970 regular_block_arg =
false;
1974 argc = pm_setup_args_core(arguments_node, block, flags, regular_block_arg, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
1975 PUSH_SEQ(ret, block_arg);
1978 argc = pm_setup_args_core(arguments_node, block, flags,
false, kw_arg, &dup_rest, iseq, ret, scope_node, node_location);
1985 if (*flags & VM_CALL_ARGS_SPLAT && dup_rest != initial_dup_rest) {
1986 *flags |= VM_CALL_ARGS_SPLAT_MUT;
2006 if (!popped) PUSH_INSN(ret, location, putnil);
2008 PM_COMPILE_NOT_POPPED(node->
receiver);
2010 int boff = (node->
block == NULL ? 0 : 1);
2013 int argc = pm_setup_args(node->
arguments, (
const pm_node_t *) node->
block, &flag, &keywords, iseq, ret, scope_node, node_location);
2015 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2017 PUSH_INSN(ret, location, splatkw);
2020 PUSH_INSN(ret, location, dup);
2021 PUSH_INSN(ret, location, splatkw);
2022 PUSH_INSN(ret, location, pop);
2026 int dup_argn = argc + 1 + boff;
2027 int keyword_len = 0;
2030 keyword_len = keywords->keyword_len;
2031 dup_argn += keyword_len;
2034 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2035 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2036 PM_COMPILE_NOT_POPPED(node->
value);
2039 PUSH_SEND(ret, location, id_operator,
INT2FIX(1));
2042 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2044 if (flag & VM_CALL_ARGS_SPLAT) {
2045 if (flag & VM_CALL_KW_SPLAT) {
2046 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2048 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2049 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2050 flag |= VM_CALL_ARGS_SPLAT_MUT;
2053 PUSH_INSN(ret, location, swap);
2054 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2055 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2056 PUSH_INSN(ret, location, pop);
2060 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2061 PUSH_INSN(ret, location, swap);
2062 PUSH_INSN(ret, location, pop);
2064 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2065 PUSH_INSN(ret, location, swap);
2066 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2067 PUSH_INSN(ret, location, swap);
2068 flag |= VM_CALL_ARGS_SPLAT_MUT;
2070 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2072 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2073 PUSH_INSN(ret, location, pop);
2074 PUSH_INSN(ret, location, pop);
2078 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2080 else if (flag & VM_CALL_KW_SPLAT) {
2082 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2083 PUSH_INSN(ret, location, swap);
2084 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2085 PUSH_INSN(ret, location, pop);
2087 PUSH_INSN(ret, location, swap);
2088 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2090 else if (keyword_len) {
2091 PUSH_INSN(ret, location, dup);
2092 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 2));
2093 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2094 PUSH_INSN(ret, location, pop);
2095 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2099 PUSH_INSN(ret, location, swap);
2101 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2104 PUSH_INSN(ret, location, pop);
2123 if (!popped) PUSH_INSN(ret, location, putnil);
2124 PM_COMPILE_NOT_POPPED(receiver);
2126 int boff = (block == NULL ? 0 : 1);
2129 int argc = pm_setup_args(arguments, (
const pm_node_t *) block, &flag, &keywords, iseq, ret, scope_node, node_location);
2131 if ((argc > 0 || boff) && (flag & VM_CALL_KW_SPLAT)) {
2133 PUSH_INSN(ret, location, splatkw);
2136 PUSH_INSN(ret, location, dup);
2137 PUSH_INSN(ret, location, splatkw);
2138 PUSH_INSN(ret, location, pop);
2142 int dup_argn = argc + 1 + boff;
2143 int keyword_len = 0;
2146 keyword_len = keywords->keyword_len;
2147 dup_argn += keyword_len;
2150 PUSH_INSN1(ret, location, dupn,
INT2FIX(dup_argn));
2151 PUSH_SEND_R(ret, location, idAREF,
INT2FIX(argc), NULL,
INT2FIX(flag & ~(VM_CALL_ARGS_SPLAT_MUT | VM_CALL_KW_SPLAT_MUT)), keywords);
2153 LABEL *label = NEW_LABEL(location.
line);
2154 LABEL *lfin = NEW_LABEL(location.
line);
2156 PUSH_INSN(ret, location, dup);
2158 PUSH_INSNL(ret, location, branchunless, label);
2161 PUSH_INSNL(ret, location, branchif, label);
2164 PUSH_INSN(ret, location, pop);
2165 PM_COMPILE_NOT_POPPED(value);
2168 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2171 if (flag & VM_CALL_ARGS_SPLAT) {
2172 if (flag & VM_CALL_KW_SPLAT) {
2173 PUSH_INSN1(ret, location, topn,
INT2FIX(2 + boff));
2174 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2175 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2176 flag |= VM_CALL_ARGS_SPLAT_MUT;
2179 PUSH_INSN(ret, location, swap);
2180 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2181 PUSH_INSN1(ret, location, setn,
INT2FIX(2 + boff));
2182 PUSH_INSN(ret, location, pop);
2186 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2187 PUSH_INSN(ret, location, swap);
2188 PUSH_INSN(ret, location, pop);
2190 if (!(flag & VM_CALL_ARGS_SPLAT_MUT)) {
2191 PUSH_INSN(ret, location, swap);
2192 PUSH_INSN1(ret, location, splatarray,
Qtrue);
2193 PUSH_INSN(ret, location, swap);
2194 flag |= VM_CALL_ARGS_SPLAT_MUT;
2196 PUSH_INSN1(ret, location, pushtoarray,
INT2FIX(1));
2198 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2199 PUSH_INSN(ret, location, pop);
2200 PUSH_INSN(ret, location, pop);
2204 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc), NULL,
INT2FIX(flag), keywords);
2206 else if (flag & VM_CALL_KW_SPLAT) {
2208 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2209 PUSH_INSN(ret, location, swap);
2210 PUSH_INSN1(ret, location, setn,
INT2FIX(3));
2211 PUSH_INSN(ret, location, pop);
2214 PUSH_INSN(ret, location, swap);
2215 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2217 else if (keyword_len) {
2218 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 1));
2219 PUSH_INSN1(ret, location, opt_reverse,
INT2FIX(keyword_len + boff + 0));
2220 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2224 PUSH_INSN(ret, location, swap);
2226 PUSH_SEND_R(ret, location, idASET,
INT2FIX(argc + 1), NULL,
INT2FIX(flag), keywords);
2229 PUSH_INSN(ret, location, pop);
2230 PUSH_INSNL(ret, location, jump, lfin);
2231 PUSH_LABEL(ret, label);
2233 PUSH_INSN1(ret, location, setn,
INT2FIX(dup_argn + 1));
2235 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(dup_argn + 1));
2236 PUSH_LABEL(ret, lfin);
2245#define PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE 0
2246#define PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING 1
2247#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P 2
2248#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE 3
2249#define PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY 4
2254static 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);
2261pm_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)
2263 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2264 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2266 PUSH_INSN(ret, location, dup);
2267 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2269 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2270 PUSH_INSN1(ret, location, putobject, message);
2271 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2272 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2273 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2275 PUSH_INSN1(ret, location, putobject,
Qfalse);
2276 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2278 PUSH_INSN(ret, location, pop);
2279 PUSH_INSN(ret, location, pop);
2280 PUSH_LABEL(ret, match_succeeded_label);
2291pm_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)
2293 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2294 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2296 PUSH_INSN(ret, location, dup);
2297 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2299 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2300 PUSH_INSN1(ret, location, putobject, message);
2301 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2302 PUSH_INSN(ret, location, dup);
2303 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2304 PUSH_INSN1(ret, location, putobject, length);
2305 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(4));
2306 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2308 PUSH_INSN1(ret, location, putobject,
Qfalse);
2309 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2311 PUSH_INSN(ret, location, pop);
2312 PUSH_INSN(ret, location, pop);
2313 PUSH_LABEL(ret, match_succeeded_label);
2324pm_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)
2326 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2327 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2329 PUSH_INSN(ret, location, dup);
2330 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2331 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2333 VALUE operand = rb_fstring_lit(
"%p === %p does not return true");
2334 PUSH_INSN1(ret, location, putobject, operand);
2336 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2337 PUSH_INSN1(ret, location, topn,
INT2FIX(5));
2338 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2339 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2340 PUSH_INSN1(ret, location, putobject,
Qfalse);
2341 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2342 PUSH_INSN(ret, location, pop);
2343 PUSH_INSN(ret, location, pop);
2345 PUSH_LABEL(ret, match_succeeded_label);
2346 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2347 PUSH_INSN(ret, location, pop);
2348 PUSH_INSN(ret, location, pop);
2360pm_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)
2362 LABEL *matched_label = NEW_LABEL(pm_node_line_number(scope_node->parser, node));
2363 CHECK(pm_compile_pattern(iseq, scope_node, node, ret, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern, use_deconstructed_cache, base_index));
2364 PUSH_LABEL(ret, matched_label);
2374pm_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)
2376 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2378 if (use_deconstructed_cache) {
2379 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2380 PUSH_INSNL(ret, location, branchnil, deconstruct_label);
2382 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2383 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2385 PUSH_INSN(ret, location, pop);
2386 PUSH_INSN1(ret, location, topn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE - 1));
2387 PUSH_INSNL(ret, location, jump, deconstructed_label);
2390 PUSH_INSNL(ret, location, jump, deconstruct_label);
2393 PUSH_LABEL(ret, deconstruct_label);
2394 PUSH_INSN(ret, location, dup);
2397 PUSH_INSN1(ret, location, putobject, operand);
2398 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2400 if (use_deconstructed_cache) {
2401 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE + 1));
2404 if (in_single_pattern) {
2405 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct"), base_index + 1));
2408 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2409 PUSH_SEND(ret, location, rb_intern(
"deconstruct"),
INT2FIX(0));
2411 if (use_deconstructed_cache) {
2412 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE));
2415 PUSH_INSN(ret, location, dup);
2417 PUSH_INSNL(ret, location, branchunless, type_error_label);
2418 PUSH_LABEL(ret, deconstructed_label);
2428pm_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)
2430 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2432 PUSH_INSN(ret, location, dup);
2433 PM_COMPILE_NOT_POPPED(node);
2435 if (in_single_pattern) {
2436 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
2438 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
2439 if (in_single_pattern) {
2440 CHECK(pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 3));
2442 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2451pm_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)
2453 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2454 LABEL *key_error_label = NEW_LABEL(location.
line);
2455 LABEL *cleanup_label = NEW_LABEL(location.
line);
2458 kw_arg->references = 0;
2459 kw_arg->keyword_len = 2;
2460 kw_arg->keywords[0] =
ID2SYM(rb_intern(
"matchee"));
2461 kw_arg->keywords[1] =
ID2SYM(rb_intern(
"key"));
2463 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2464 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2465 PUSH_INSNL(ret, location, branchif, key_error_label);
2468 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2471 VALUE operand = rb_fstring_lit(
"%p: %s");
2472 PUSH_INSN1(ret, location, putobject, operand);
2475 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2476 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2477 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2478 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2479 PUSH_INSNL(ret, location, jump, cleanup_label);
2481 PUSH_LABEL(ret, key_error_label);
2483 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2486 VALUE operand = rb_fstring_lit(
"%p: %s");
2487 PUSH_INSN1(ret, location, putobject, operand);
2490 PUSH_INSN1(ret, location, topn,
INT2FIX(4));
2491 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 6));
2492 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(3));
2493 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2494 PUSH_INSN1(ret, location, topn,
INT2FIX(PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2495 PUSH_SEND_R(ret, location, rb_intern(
"new"),
INT2FIX(1), NULL,
INT2FIX(VM_CALL_KWARG), kw_arg);
2496 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(1));
2497 PUSH_LABEL(ret, cleanup_label);
2499 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(7));
2500 if (!popped) PUSH_INSN(ret, location, putnil);
2501 PUSH_INSNL(ret, location, jump, done_label);
2502 PUSH_INSN1(ret, location, dupn,
INT2FIX(5));
2503 if (popped) PUSH_INSN(ret, location, putnil);
2510pm_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)
2512 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
2527 const size_t posts_size = cast->
posts.
size;
2528 const size_t minimum_size = requireds_size + posts_size;
2530 bool rest_named =
false;
2531 bool use_rest_size =
false;
2533 if (cast->
rest != NULL) {
2535 use_rest_size = (rest_named || (!rest_named && posts_size > 0));
2538 LABEL *match_failed_label = NEW_LABEL(location.
line);
2539 LABEL *type_error_label = NEW_LABEL(location.
line);
2540 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2541 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2543 if (use_rest_size) {
2544 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2545 PUSH_INSN(ret, location, swap);
2550 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2553 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));
2555 PUSH_INSN(ret, location, dup);
2556 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2557 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2558 PUSH_SEND(ret, location, cast->
rest == NULL ? idEq : idGE,
INT2FIX(1));
2559 if (in_single_pattern) {
2560 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+)");
2561 CHECK(pm_compile_pattern_length_error(iseq, scope_node, node, ret, message,
INT2FIX(minimum_size), base_index + 1));
2563 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2565 for (
size_t index = 0; index < requireds_size; index++) {
2567 PUSH_INSN(ret, location, dup);
2568 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2569 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2570 CHECK(pm_compile_pattern_match(iseq, scope_node, required, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2573 if (cast->
rest != NULL) {
2575 PUSH_INSN(ret, location, dup);
2576 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size));
2577 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2578 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2579 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2580 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2581 PUSH_INSN1(ret, location, setn,
INT2FIX(4));
2582 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2583 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));
2585 else if (posts_size > 0) {
2586 PUSH_INSN(ret, location, dup);
2587 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2588 PUSH_INSN1(ret, location, putobject,
INT2FIX(minimum_size));
2589 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2590 PUSH_INSN1(ret, location, setn,
INT2FIX(2));
2591 PUSH_INSN(ret, location, pop);
2595 for (
size_t index = 0; index < posts_size; index++) {
2597 PUSH_INSN(ret, location, dup);
2599 PUSH_INSN1(ret, location, putobject,
INT2FIX(requireds_size + index));
2600 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2601 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2602 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2603 CHECK(pm_compile_pattern_match(iseq, scope_node, post, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2606 PUSH_INSN(ret, location, pop);
2607 if (use_rest_size) {
2608 PUSH_INSN(ret, location, pop);
2611 PUSH_INSNL(ret, location, jump, matched_label);
2612 PUSH_INSN(ret, location, putnil);
2613 if (use_rest_size) {
2614 PUSH_INSN(ret, location, putnil);
2617 PUSH_LABEL(ret, type_error_label);
2618 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2622 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2623 PUSH_INSN1(ret, location, putobject, operand);
2626 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2627 PUSH_INSN(ret, location, pop);
2629 PUSH_LABEL(ret, match_failed_label);
2630 PUSH_INSN(ret, location, pop);
2631 if (use_rest_size) {
2632 PUSH_INSN(ret, location, pop);
2635 PUSH_INSNL(ret, location, jump, unmatched_label);
2650 LABEL *match_failed_label = NEW_LABEL(location.
line);
2651 LABEL *type_error_label = NEW_LABEL(location.
line);
2652 LABEL *deconstruct_label = NEW_LABEL(location.
line);
2653 LABEL *deconstructed_label = NEW_LABEL(location.
line);
2656 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2659 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));
2661 PUSH_INSN(ret, location, dup);
2662 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2663 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2664 PUSH_SEND(ret, location, idGE,
INT2FIX(1));
2665 if (in_single_pattern) {
2666 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));
2668 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2671 LABEL *while_begin_label = NEW_LABEL(location.
line);
2672 LABEL *next_loop_label = NEW_LABEL(location.
line);
2673 LABEL *find_succeeded_label = NEW_LABEL(location.
line);
2674 LABEL *find_failed_label = NEW_LABEL(location.
line);
2676 PUSH_INSN(ret, location, dup);
2677 PUSH_SEND(ret, location, idLength,
INT2FIX(0));
2679 PUSH_INSN(ret, location, dup);
2680 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2681 PUSH_SEND(ret, location, idMINUS,
INT2FIX(1));
2682 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2683 PUSH_LABEL(ret, while_begin_label);
2685 PUSH_INSN(ret, location, dup);
2686 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2687 PUSH_SEND(ret, location, idLE,
INT2FIX(1));
2688 PUSH_INSNL(ret, location, branchunless, find_failed_label);
2690 for (
size_t index = 0; index < size; index++) {
2691 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2692 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2695 PUSH_INSN1(ret, location, putobject,
INT2FIX(index));
2696 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2699 PUSH_SEND(ret, location, idAREF,
INT2FIX(1));
2700 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));
2706 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2707 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
2708 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2709 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2710 CHECK(pm_compile_pattern_match(iseq, scope_node, left->
expression, ret, find_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 4));
2716 if (right->expression != NULL) {
2717 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2718 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
2719 PUSH_INSN1(ret, location, putobject,
INT2FIX(size));
2720 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2721 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2722 PUSH_SEND(ret, location, idAREF,
INT2FIX(2));
2723 pm_compile_pattern_match(iseq, scope_node, right->expression, ret, find_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 4);
2726 PUSH_INSNL(ret, location, jump, find_succeeded_label);
2728 PUSH_LABEL(ret, next_loop_label);
2729 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
2730 PUSH_SEND(ret, location, idPLUS,
INT2FIX(1));
2731 PUSH_INSNL(ret, location, jump, while_begin_label);
2733 PUSH_LABEL(ret, find_failed_label);
2734 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2735 if (in_single_pattern) {
2736 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2739 VALUE operand = rb_fstring_lit(
"%p does not match to find pattern");
2740 PUSH_INSN1(ret, location, putobject, operand);
2743 PUSH_INSN1(ret, location, topn,
INT2FIX(2));
2744 PUSH_SEND(ret, location, id_core_sprintf,
INT2FIX(2));
2745 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
2747 PUSH_INSN1(ret, location, putobject,
Qfalse);
2748 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
2750 PUSH_INSN(ret, location, pop);
2751 PUSH_INSN(ret, location, pop);
2753 PUSH_INSNL(ret, location, jump, match_failed_label);
2754 PUSH_INSN1(ret, location, dupn,
INT2FIX(3));
2756 PUSH_LABEL(ret, find_succeeded_label);
2757 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(3));
2760 PUSH_INSN(ret, location, pop);
2761 PUSH_INSNL(ret, location, jump, matched_label);
2762 PUSH_INSN(ret, location, putnil);
2764 PUSH_LABEL(ret, type_error_label);
2765 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2769 VALUE operand = rb_fstring_lit(
"deconstruct must return Array");
2770 PUSH_INSN1(ret, location, putobject, operand);
2773 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2774 PUSH_INSN(ret, location, pop);
2776 PUSH_LABEL(ret, match_failed_label);
2777 PUSH_INSN(ret, location, pop);
2778 PUSH_INSNL(ret, location, jump, unmatched_label);
2797 LABEL *match_failed_label = NEW_LABEL(location.
line);
2798 LABEL *type_error_label = NEW_LABEL(location.
line);
2801 if (has_keys && !has_rest) {
2804 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2812 rb_ary_push(keys, symbol);
2817 CHECK(pm_compile_pattern_constant(iseq, scope_node, cast->
constant, ret, match_failed_label, in_single_pattern, base_index));
2820 PUSH_INSN(ret, location, dup);
2823 VALUE operand =
ID2SYM(rb_intern(
"deconstruct_keys"));
2824 PUSH_INSN1(ret, location, putobject, operand);
2827 PUSH_SEND(ret, location, idRespond_to,
INT2FIX(1));
2828 if (in_single_pattern) {
2829 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p does not respond to #deconstruct_keys"), base_index + 1));
2831 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2834 PUSH_INSN(ret, location, putnil);
2837 PUSH_INSN1(ret, location, duparray, keys);
2840 PUSH_SEND(ret, location, rb_intern(
"deconstruct_keys"),
INT2FIX(1));
2842 PUSH_INSN(ret, location, dup);
2844 PUSH_INSNL(ret, location, branchunless, type_error_label);
2847 PUSH_SEND(ret, location, rb_intern(
"dup"),
INT2FIX(0));
2851 DECL_ANCHOR(match_values);
2853 for (
size_t index = 0; index < cast->
elements.
size; index++) {
2862 PUSH_INSN(ret, location, dup);
2863 PUSH_INSN1(ret, location, putobject, symbol);
2864 PUSH_SEND(ret, location, rb_intern(
"key?"),
INT2FIX(1));
2866 if (in_single_pattern) {
2867 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
2869 PUSH_INSN(ret, location, dup);
2870 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
2874 PUSH_INSN1(ret, location, putobject, operand);
2877 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 2));
2878 PUSH_INSN1(ret, location, putobject,
Qtrue);
2879 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 3));
2880 PUSH_INSN1(ret, location, topn,
INT2FIX(3));
2881 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE + 4));
2882 PUSH_INSN1(ret, location, putobject, symbol);
2883 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY + 5));
2885 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(4));
2886 PUSH_LABEL(ret, match_succeeded_label);
2889 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2890 PUSH_INSN(match_values, location, dup);
2891 PUSH_INSN1(match_values, location, putobject, symbol);
2892 PUSH_SEND(match_values, location, has_rest ? rb_intern(
"delete") : idAREF,
INT2FIX(1));
2899 CHECK(pm_compile_pattern_match(iseq, scope_node, value, match_values, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1));
2902 PUSH_SEQ(ret, match_values);
2905 PUSH_INSN(ret, location, dup);
2906 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
2907 if (in_single_pattern) {
2908 CHECK(pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"%p is not empty"), base_index + 1));
2910 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2916 PUSH_INSN(ret, location, dup);
2917 PUSH_SEND(ret, location, idEmptyP,
INT2FIX(0));
2918 if (in_single_pattern) {
2919 pm_compile_pattern_generic_error(iseq, scope_node, node, ret, rb_fstring_lit(
"rest of %p is not empty"), base_index + 1);
2921 PUSH_INSNL(ret, location, branchunless, match_failed_label);
2926 PUSH_INSN(ret, location, dup);
2927 pm_compile_pattern_match(iseq, scope_node, splat->value, ret, match_failed_label, in_single_pattern, in_alternation_pattern,
false, base_index + 1);
2931 rb_bug(
"unreachable");
2936 PUSH_INSN(ret, location, pop);
2937 PUSH_INSNL(ret, location, jump, matched_label);
2938 PUSH_INSN(ret, location, putnil);
2940 PUSH_LABEL(ret, type_error_label);
2941 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
2945 VALUE operand = rb_fstring_lit(
"deconstruct_keys must return Hash");
2946 PUSH_INSN1(ret, location, putobject, operand);
2949 PUSH_SEND(ret, location, id_core_raise,
INT2FIX(2));
2950 PUSH_INSN(ret, location, pop);
2952 PUSH_LABEL(ret, match_failed_label);
2953 PUSH_INSN(ret, location, pop);
2954 PUSH_INSNL(ret, location, jump, unmatched_label);
2969 LABEL *match_failed_label = NEW_LABEL(location.
line);
2971 PUSH_INSN(ret, location, dup);
2972 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));
2973 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));
2974 PUSH_INSN(ret, location, putnil);
2976 PUSH_LABEL(ret, match_failed_label);
2977 PUSH_INSN(ret, location, pop);
2978 PUSH_INSNL(ret, location, jump, unmatched_label);
2987 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
2993 if (in_alternation_pattern) {
2994 ID id = pm_constant_id_lookup(scope_node, cast->
name);
2995 const char *name = rb_id2name(
id);
2997 if (name && strlen(name) > 0 && name[0] !=
'_') {
2998 COMPILE_ERROR(iseq, location.
line,
"illegal variable in alternative pattern (%"PRIsVALUE
")", rb_id2str(
id));
3003 PUSH_SETLOCAL(ret, location, index.index, index.level);
3004 PUSH_INSNL(ret, location, jump, matched_label);
3012 LABEL *matched_left_label = NEW_LABEL(location.
line);
3013 LABEL *unmatched_left_label = NEW_LABEL(location.
line);
3017 PUSH_INSN(ret, location, dup);
3018 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));
3023 PUSH_LABEL(ret, matched_left_label);
3024 PUSH_INSN(ret, location, pop);
3025 PUSH_INSNL(ret, location, jump, matched_label);
3026 PUSH_INSN(ret, location, putnil);
3030 PUSH_LABEL(ret, unmatched_left_label);
3031 CHECK(pm_compile_pattern(iseq, scope_node, cast->
right, ret, matched_label, unmatched_label, in_single_pattern,
true, use_deconstructed_cache, base_index));
3039 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);
3079 PM_COMPILE_NOT_POPPED(node);
3080 if (in_single_pattern) {
3081 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
3084 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE));
3086 if (in_single_pattern) {
3087 pm_compile_pattern_eqq_error(iseq, scope_node, node, ret, base_index + 2);
3090 PUSH_INSNL(ret, location, branchif, matched_label);
3091 PUSH_INSNL(ret, location, jump, unmatched_label);
3100 CHECK(pm_compile_pattern(iseq, scope_node, cast->
variable, ret, matched_label, unmatched_label, in_single_pattern, in_alternation_pattern,
true, base_index));
3134 CHECK(pm_compile_pattern_match(iseq, scope_node, statement, ret, unmatched_label, in_single_pattern, in_alternation_pattern, use_deconstructed_cache, base_index));
3135 PM_COMPILE_NOT_POPPED(predicate);
3137 if (in_single_pattern) {
3138 LABEL *match_succeeded_label = NEW_LABEL(location.
line);
3140 PUSH_INSN(ret, location, dup);
3142 PUSH_INSNL(ret, location, branchif, match_succeeded_label);
3145 PUSH_INSNL(ret, location, branchunless, match_succeeded_label);
3149 VALUE operand = rb_fstring_lit(
"guard clause does not return true");
3150 PUSH_INSN1(ret, location, putobject, operand);
3153 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING + 1));
3154 PUSH_INSN1(ret, location, putobject,
Qfalse);
3155 PUSH_INSN1(ret, location, setn,
INT2FIX(base_index + PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P + 2));
3157 PUSH_INSN(ret, location, pop);
3158 PUSH_INSN(ret, location, pop);
3160 PUSH_LABEL(ret, match_succeeded_label);
3164 PUSH_INSNL(ret, location, branchunless, unmatched_label);
3167 PUSH_INSNL(ret, location, branchif, unmatched_label);
3170 PUSH_INSNL(ret, location, jump, matched_label);
3177 rb_bug(
"Unexpected node type in pattern matching expression: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
3184#undef PM_PATTERN_BASE_INDEX_OFFSET_DECONSTRUCTED_CACHE
3185#undef PM_PATTERN_BASE_INDEX_OFFSET_ERROR_STRING
3186#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_P
3187#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_MATCHEE
3188#undef PM_PATTERN_BASE_INDEX_OFFSET_KEY_ERROR_KEY
3192pm_scope_node_init(
const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous)
3196 memset(scope, 0,
sizeof(pm_scope_node_t));
3202 scope->previous = previous;
3206 scope->parser = previous->parser;
3207 scope->encoding = previous->encoding;
3209 scope->constants = previous->constants;
3210 scope->coverage_enabled = previous->coverage_enabled;
3217 scope->body = cast->
body;
3218 scope->locals = cast->
locals;
3224 scope->body = cast->
body;
3225 scope->locals = cast->
locals;
3231 scope->body = cast->body;
3232 scope->locals = cast->locals;
3259 scope->body = cast->
body;
3260 scope->locals = cast->
locals;
3272 scope->body = cast->
body;
3273 scope->locals = cast->
locals;
3284 scope->locals = cast->locals;
3299 scope->body = cast->
body;
3300 scope->locals = cast->
locals;
3309 rb_bug(
"unreachable");
3315pm_scope_node_destroy(pm_scope_node_t *scope_node)
3317 if (scope_node->index_lookup_table) {
3318 st_free_table(scope_node->index_lookup_table);
3334pm_compile_retry_end_label(rb_iseq_t *iseq, LINK_ANCHOR *
const ret, LABEL *retry_end_l)
3337 LINK_ELEMENT *last_elem = LAST_ELEMENT(ret);
3338 iobj = IS_INSN(last_elem) ? (INSN*) last_elem : (INSN*) get_prev_insn((INSN*) last_elem);
3339 while (!IS_INSN_ID(iobj, send) && !IS_INSN_ID(iobj, invokesuper) && !IS_INSN_ID(iobj, sendforward) && !IS_INSN_ID(iobj, invokesuperforward)) {
3340 iobj = (INSN*) get_prev_insn(iobj);
3342 ELEM_INSERT_NEXT(&iobj->link, (LINK_ELEMENT*) retry_end_l);
3347 if (&iobj->link == LAST_ELEMENT(ret)) {
3348 ret->last = (LINK_ELEMENT*) retry_end_l;
3353pm_iseq_builtin_function_name(
const pm_scope_node_t *scope_node,
const pm_node_t *receiver,
ID method_id)
3355 const char *name = rb_id2name(method_id);
3356 static const char prefix[] =
"__builtin_";
3357 const size_t prefix_len =
sizeof(prefix) - 1;
3359 if (receiver == NULL) {
3360 if (UNLIKELY(strncmp(prefix, name, prefix_len) == 0)) {
3362 return &name[prefix_len];
3389 if (arguments == NULL) {
3390 COMPILE_ERROR(iseq, node_location->
line,
"attr!: no argument");
3397 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to attr!: %s", pm_node_type_to_str(
PM_NODE_TYPE(argument)));
3401 VALUE symbol = pm_static_literal_value(iseq, argument, scope_node);
3404 if (strcmp(RSTRING_PTR(
string),
"leaf") == 0) {
3405 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_LEAF;
3407 else if (strcmp(RSTRING_PTR(
string),
"inline_block") == 0) {
3408 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_INLINE_BLOCK;
3410 else if (strcmp(RSTRING_PTR(
string),
"use_block") == 0) {
3411 iseq_set_use_block(iseq);
3413 else if (strcmp(RSTRING_PTR(
string),
"c_trace") == 0) {
3415 ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_C_TRACE;
3418 COMPILE_ERROR(iseq, node_location->
line,
"unknown argument to attr!: %s", RSTRING_PTR(
string));
3427pm_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)
3429 if (arguments == NULL) {
3430 COMPILE_ERROR(iseq, node_location->
line,
"arg!: no argument");
3435 COMPILE_ERROR(iseq, node_location->
line,
"arg!: too many argument");
3441 COMPILE_ERROR(iseq, node_location->
line,
"non symbol argument to arg!: %s", pm_node_type_to_str(
PM_NODE_TYPE(argument)));
3447 int index = ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->local_table_size - get_local_var_idx(iseq, name);
3449 debugs(
"id: %s idx: %d\n", rb_id2name(name), index);
3450 PUSH_GETLOCAL(ret, *node_location, index, get_lvar_level(iseq));
3457pm_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)
3459 const pm_node_t *ast_node = scope_node->ast_node;
3461 rb_bug(
"mandatory_only?: not in method definition");
3467 if (parameters_node == NULL) {
3468 rb_bug(
"mandatory_only?: in method definition with no parameters");
3474 rb_bug(
"mandatory_only?: not in method definition with plain statements");
3480 rb_bug(
"mandatory_only?: can't find mandatory node");
3485 .base = parameters_node->
base,
3490 .base = def_node->
base,
3491 .name = def_node->
name,
3493 .parameters = ¶meters,
3502 pm_scope_node_t next_scope_node;
3503 pm_scope_node_init(&def.base, &next_scope_node, scope_node);
3506 ISEQ_BODY(iseq)->mandatory_only_iseq = pm_iseq_new_with_opt(
3508 rb_iseq_base_label(iseq),
3510 rb_iseq_realpath(iseq),
3511 node_location->
line,
3515 ISEQ_COMPILE_DATA(iseq)->option,
3520 RUBY_ASSERT(ISEQ_BODY(iseq)->mandatory_only_iseq == NULL);
3521 rb_jump_tag(error_state);
3524 pm_scope_node_destroy(&next_scope_node);
3529pm_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)
3533 if (parent_block != NULL) {
3534 COMPILE_ERROR(iseq, node_location->
line,
"should not call builtins here.");
3538#define BUILTIN_INLINE_PREFIX "_bi"
3539 char inline_func[
sizeof(BUILTIN_INLINE_PREFIX) +
DECIMAL_SIZE_OF(
int)];
3540 bool cconst =
false;
3545 if (strcmp(
"cstmt!", builtin_func) == 0 || strcmp(
"cexpr!", builtin_func) == 0) {
3548 else if (strcmp(
"cconst!", builtin_func) == 0) {
3551 else if (strcmp(
"cinit!", builtin_func) == 0) {
3555 else if (strcmp(
"attr!", builtin_func) == 0) {
3556 return pm_compile_builtin_attr(iseq, scope_node, arguments, node_location);
3558 else if (strcmp(
"arg!", builtin_func) == 0) {
3559 return pm_compile_builtin_arg(iseq, ret, scope_node, arguments, node_location, popped);
3561 else if (strcmp(
"mandatory_only?", builtin_func) == 0) {
3563 rb_bug(
"mandatory_only? should be in if condition");
3565 else if (!LIST_INSN_SIZE_ZERO(ret)) {
3566 rb_bug(
"mandatory_only? should be put on top");
3569 PUSH_INSN1(ret, *node_location, putobject,
Qfalse);
3570 return pm_compile_builtin_mandatory_only_method(iseq, scope_node, call_node, node_location);
3573 rb_bug(
"can't find builtin function:%s", builtin_func);
3576 COMPILE_ERROR(iseq, node_location->
line,
"can't find builtin function:%s", builtin_func);
3580 int inline_index = node_location->
line;
3581 snprintf(inline_func,
sizeof(inline_func), BUILTIN_INLINE_PREFIX
"%d", inline_index);
3582 builtin_func = inline_func;
3588 typedef VALUE(*builtin_func0)(
void *,
VALUE);
3589 VALUE const_val = (*(builtin_func0)(uintptr_t)bf->func_ptr)(NULL,
Qnil);
3590 PUSH_INSN1(ret, *node_location, putobject, const_val);
3596 DECL_ANCHOR(args_seq);
3600 int argc = pm_setup_args(arguments, call_node->
block, &flags, &keywords, iseq, args_seq, scope_node, node_location);
3602 if (argc != bf->argc) {
3603 COMPILE_ERROR(iseq, node_location->
line,
"argc is not match for builtin function:%s (expect %d but %d)", builtin_func, bf->argc, argc);
3607 unsigned int start_index;
3608 if (delegate_call_p(iseq, argc, args_seq, &start_index)) {
3609 PUSH_INSN2(ret, *node_location, opt_invokebuiltin_delegate, bf,
INT2FIX(start_index));
3612 PUSH_SEQ(ret, args_seq);
3613 PUSH_INSN1(ret, *node_location, invokebuiltin, bf);
3616 if (popped) PUSH_INSN(ret, *node_location, pop);
3624pm_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)
3630 LABEL *else_label = NEW_LABEL(location.
line);
3631 LABEL *end_label = NEW_LABEL(location.
line);
3632 LABEL *retry_end_l = NEW_LABEL(location.
line);
3635 rb_code_location_t code_location = { 0 };
3636 int node_id = location.
node_id;
3639 if (PM_BRANCH_COVERAGE_P(iseq)) {
3640 const uint8_t *cursors[3] = {
3646 const uint8_t *end_cursor = cursors[0];
3647 end_cursor = (end_cursor == NULL || cursors[1] == NULL) ? cursors[1] : (end_cursor > cursors[1] ? end_cursor : cursors[1]);
3648 end_cursor = (end_cursor == NULL || cursors[2] == NULL) ? cursors[2] : (end_cursor > cursors[2] ? end_cursor : cursors[2]);
3651 const pm_line_column_t start_location = PM_NODE_START_LINE_COLUMN(scope_node->parser, call_node);
3654 code_location = (rb_code_location_t) {
3655 .beg_pos = { .lineno = start_location.line, .column = start_location.column },
3656 .end_pos = { .lineno = end_location.line, .column = end_location.column }
3659 branches = decl_branch_base(iseq, PTR2NUM(call_node), &code_location,
"&.");
3662 PUSH_INSN(ret, location, dup);
3663 PUSH_INSNL(ret, location, branchnil, else_label);
3665 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 0,
"then", branches);
3671 int orig_argc = pm_setup_args(call_node->
arguments, call_node->
block, &flags, &kw_arg, iseq, ret, scope_node, &location);
3672 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
3673 const rb_iseq_t *block_iseq = NULL;
3677 pm_scope_node_t next_scope_node;
3678 pm_scope_node_init(call_node->
block, &next_scope_node, scope_node);
3680 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));
3681 pm_scope_node_destroy(&next_scope_node);
3682 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
3686 flags |= VM_CALL_VCALL;
3690 flags |= VM_CALL_ARGS_SIMPLE;
3695 flags |= VM_CALL_FCALL;
3699 if (flags & VM_CALL_ARGS_BLOCKARG) {
3700 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
3701 if (flags & VM_CALL_ARGS_SPLAT) {
3702 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3703 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3705 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 3));
3706 PUSH_INSN(ret, location, pop);
3708 else if (flags & VM_CALL_ARGS_SPLAT) {
3709 PUSH_INSN(ret, location, dup);
3710 PUSH_INSN1(ret, location, putobject,
INT2FIX(-1));
3711 PUSH_SEND_WITH_FLAG(ret, location, idAREF,
INT2FIX(1),
INT2FIX(0));
3712 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 2));
3713 PUSH_INSN(ret, location, pop);
3716 PUSH_INSN1(ret, location, setn,
INT2FIX(orig_argc + 1));
3720 if ((flags & VM_CALL_KW_SPLAT) && (flags & VM_CALL_ARGS_BLOCKARG) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
3721 PUSH_INSN(ret, location, splatkw);
3724 PUSH_SEND_R(ret, location, method_id,
INT2FIX(orig_argc), block_iseq,
INT2FIX(flags), kw_arg);
3726 if (block_iseq && ISEQ_BODY(block_iseq)->catch_table) {
3727 pm_compile_retry_end_label(iseq, ret, retry_end_l);
3728 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, start, retry_end_l, block_iseq, retry_end_l);
3732 PUSH_INSNL(ret, location, jump, end_label);
3733 PUSH_LABEL(ret, else_label);
3734 add_trace_branch_coverage(iseq, ret, &code_location, node_id, 1,
"else", branches);
3735 PUSH_LABEL(ret, end_label);
3739 PUSH_INSN(ret, location, pop);
3742 if (popped) PUSH_INSN(ret, location, pop);
3743 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
3771pm_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)
3773#define PUSH_VAL(type) (in_condition ? Qtrue : rb_iseq_defined_string(type))
3776 enum defined_type dtype = DEFINED_NOT_DEFINED;
3784 dtype = DEFINED_NIL;
3791 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3793 PUSH_INSN3(ret, location, definedivar,
ID2SYM(name), get_ivar_ic_value(iseq, name), PUSH_VAL(DEFINED_IVAR));
3804 dtype = DEFINED_LVAR;
3811 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3813 PUSH_INSN(ret, location, putnil);
3814 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR),
ID2SYM(name), PUSH_VAL(DEFINED_GVAR));
3823 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3825 PUSH_INSN(ret, location, putnil);
3826 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR),
ID2SYM(name), PUSH_VAL(DEFINED_CVAR));
3835 ID name = pm_constant_id_lookup(scope_node, cast->
name);
3837 PUSH_INSN(ret, location, putnil);
3838 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
3846 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
3848 PUSH_INSN(ret, location, putnil);
3849 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
3859 dtype = DEFINED_EXPR;
3863 PUSH_INSN(ret, location, putnil);
3864 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
3872 if (cast->
block != NULL) {
3873 dtype = DEFINED_EXPR;
3877 PUSH_INSN(ret, location, putnil);
3878 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_ZSUPER), 0, PUSH_VAL(DEFINED_ZSUPER));
3885 dtype = DEFINED_SELF;
3891 dtype = DEFINED_TRUE;
3897 dtype = DEFINED_FALSE;
3993 dtype = DEFINED_ASGN;
4137 dtype = DEFINED_EXPR;
4144 VALUE ref = pm_compile_back_reference_ref(cast);
4146 PUSH_INSN(ret, location, putnil);
4147 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4155 VALUE ref = pm_compile_numbered_reference_ref(cast);
4157 PUSH_INSN(ret, location, putnil);
4158 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_REF), ref, PUSH_VAL(DEFINED_GVAR));
4167 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4169 if (cast->
parent != NULL) {
4170 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4171 pm_compile_defined_expr0(iseq, cast->
parent, node_location, ret, popped, scope_node,
true, lfinish,
false);
4173 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4174 PM_COMPILE(cast->
parent);
4177 PUSH_INSN1(ret, location, putobject, rb_cObject);
4180 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM),
ID2SYM(name), PUSH_VAL(DEFINED_CONST));
4192 dtype = DEFINED_NIL;
4198 pm_compile_defined_expr0(iseq, cast->
statements->
body.
nodes[0], node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4204 dtype = DEFINED_EXPR;
4209 dtype = DEFINED_EXPR;
4219 if (cast->
body == NULL) {
4221 dtype = DEFINED_NIL;
4226 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);
4232 dtype = DEFINED_EXPR;
4243 lfinish[1] = NEW_LABEL(location.
line);
4246 for (
size_t index = 0; index < cast->
elements.
size; index++) {
4247 pm_compile_defined_expr0(iseq, cast->
elements.
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4248 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4251 dtype = DEFINED_EXPR;
4269 if (elements->
size > 0 && !lfinish[1]) {
4270 lfinish[1] = NEW_LABEL(location.
line);
4273 for (
size_t index = 0; index < elements->
size; index++) {
4274 pm_compile_defined_expr0(iseq, elements->
nodes[index], node_location, ret, popped, scope_node,
true, lfinish,
false);
4275 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4278 dtype = DEFINED_EXPR;
4286 pm_compile_defined_expr0(iseq, cast->
key, node_location, ret, popped, scope_node,
true, lfinish,
false);
4287 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4288 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4297 if (cast->
value == NULL) {
4298 dtype = DEFINED_EXPR;
4302 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node,
true, lfinish,
false);
4309 pm_compile_defined_expr0(iseq, cast->
value, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4313#define BLOCK_P(cast) ((cast)->block != NULL && PM_NODE_TYPE_P((cast)->block, PM_BLOCK_NODE))
4320 dtype = DEFINED_EXPR;
4325 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4326 if (!lfinish[2]) lfinish[2] = NEW_LABEL(location.
line);
4330 pm_compile_defined_expr0(iseq, (
const pm_node_t *) cast->
arguments, node_location, ret, popped, scope_node,
true, lfinish,
false);
4331 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4335 pm_compile_defined_expr0(iseq, cast->
block, node_location, ret, popped, scope_node,
true, lfinish,
false);
4336 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4343 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
true);
4344 PUSH_INSNL(ret, location, branchunless, lfinish[2]);
4347 ID method_id = pm_constant_id_lookup(scope_node, receiver->name);
4349 pm_compile_call(iseq, receiver, ret, popped, scope_node, method_id, NULL);
4352 pm_compile_defined_expr0(iseq, cast->
receiver, node_location, ret, popped, scope_node,
true, lfinish,
false);
4353 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4357 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4359 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4360 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_METHOD),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4363 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
4365 PUSH_INSN(ret, location, putself);
4366 if (explicit_receiver) PUSH_INSN(ret, location, dup);
4368 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_FUNC),
rb_id2sym(method_id), PUSH_VAL(DEFINED_METHOD));
4378 for (
size_t index = 0; index < cast->
arguments.
size; index++) {
4379 pm_compile_defined_expr0(iseq, cast->
arguments.
nodes[index], node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4382 lfinish[1] = NEW_LABEL(location.
line);
4384 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4387 dtype = DEFINED_TRUE;
4393 dtype = DEFINED_EXPR;
4398 dtype = DEFINED_EXPR;
4406 dtype = DEFINED_EXPR;
4410 pm_compile_defined_expr0(iseq, cast->
expression, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4412 if (!lfinish[1]) lfinish[1] = NEW_LABEL(location.
line);
4413 PUSH_INSNL(ret, location, branchunless, lfinish[1]);
4415 dtype = DEFINED_EXPR;
4422 pm_compile_defined_expr0(iseq, ((
const pm_shareable_constant_node_t *) node)->write, node_location, ret, popped, scope_node, in_condition, lfinish, explicit_receiver);
4473 rb_bug(
"Unreachable node in defined?: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
4477 PUSH_INSN1(ret, location, putobject, PUSH_VAL(dtype));
4483pm_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)
4485 LINK_ELEMENT *lcur = ret->last;
4486 pm_compile_defined_expr0(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4489 LABEL *lstart = NEW_LABEL(node_location->
line);
4490 LABEL *lend = NEW_LABEL(node_location->
line);
4493 rb_iseq_new_with_callback_new_callback(build_defined_rescue_iseq, NULL);
4495 const rb_iseq_t *rescue = new_child_iseq_with_callback(
4504 lstart->rescued = LABEL_RESCUE_BEG;
4505 lend->rescued = LABEL_RESCUE_END;
4507 APPEND_LABEL(ret, lcur, lstart);
4508 PUSH_LABEL(ret, lend);
4509 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lfinish[1]);
4514pm_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)
4517 LINK_ELEMENT *last = ret->last;
4519 lfinish[0] = NEW_LABEL(node_location->
line);
4524 pm_defined_expr(iseq, node, node_location, ret, popped, scope_node, in_condition, lfinish,
false);
4528 ELEM_INSERT_NEXT(last, &new_insn_body(iseq, node_location->
line, node_location->
node_id, BIN(putnil), 0)->link);
4529 PUSH_INSN(ret, *node_location, swap);
4531 if (lfinish[2]) PUSH_LABEL(ret, lfinish[2]);
4532 PUSH_INSN(ret, *node_location, pop);
4533 PUSH_LABEL(ret, lfinish[1]);
4537 PUSH_LABEL(ret, lfinish[0]);
4543pm_add_ensure_iseq(LINK_ANCHOR *
const ret, rb_iseq_t *iseq,
int is_return, pm_scope_node_t *scope_node)
4548 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack;
4550 DECL_ANCHOR(ensure);
4553 if (enlp->erange != NULL) {
4554 DECL_ANCHOR(ensure_part);
4555 LABEL *lstart = NEW_LABEL(0);
4556 LABEL *lend = NEW_LABEL(0);
4558 add_ensure_range(iseq, enlp->erange, lstart, lend);
4560 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enlp->prev;
4561 PUSH_LABEL(ensure_part, lstart);
4563 PM_COMPILE_INTO_ANCHOR(ensure_part, (
const pm_node_t *) enlp->ensure_node);
4564 PUSH_LABEL(ensure_part, lend);
4565 PUSH_SEQ(ensure, ensure_part);
4574 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = prev_enlp;
4575 PUSH_SEQ(ret, ensure);
4579 pm_scope_node_t *scope_node;
4580 rb_ast_id_table_t *local_table_for_iseq;
4585pm_local_table_insert_func(st_data_t *key, st_data_t *value, st_data_t arg,
int existing)
4591 pm_scope_node_t *scope_node = ctx->scope_node;
4592 rb_ast_id_table_t *local_table_for_iseq = ctx->local_table_for_iseq;
4593 int local_index = ctx->local_index;
4595 ID local = pm_constant_id_lookup(scope_node, constant_id);
4596 local_table_for_iseq->ids[local_index] = local;
4598 *value = (st_data_t)local_index;
4612pm_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)
4614 RUBY_ASSERT((constant_id & PM_SPECIAL_CONSTANT_FLAG) == 0);
4616 ID local = pm_constant_id_lookup(scope_node, constant_id);
4617 local_table_for_iseq->ids[local_index] = local;
4618 st_insert(index_lookup_table, (st_data_t) constant_id, (st_data_t) local_index);
4626pm_insert_local_special(
ID local_name,
int local_index, st_table *index_lookup_table, rb_ast_id_table_t *local_table_for_iseq)
4628 local_table_for_iseq->ids[local_index] = local_name;
4629 st_insert(index_lookup_table, (st_data_t) (local_name | PM_SPECIAL_CONSTANT_FLAG), (st_data_t) local_index);
4639pm_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)
4641 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4646 pm_insert_local_index(((
const pm_required_parameter_node_t *) left)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4652 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);
4659 if (rest->expression != NULL) {
4663 pm_insert_local_index(((
const pm_required_parameter_node_t *) rest->expression)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4669 for (
size_t index = 0; index < node->
rights.
size; index++) {
4674 pm_insert_local_index(((
const pm_required_parameter_node_t *) right)->name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
4680 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);
4692pm_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)
4694 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4695 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, node->
name, 0);
4696 PUSH_SETLOCAL(ret, location, index.index, index.level);
4708pm_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)
4710 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4714 int flag = (has_rest || has_rights) ? 1 : 0;
4717 for (
size_t index = 0; index < node->
lefts.
size; index++) {
4745 for (
size_t index = 0; index < node->
rights.
size; index++) {
4780} pm_multi_target_state_node_t;
4798 pm_multi_target_state_node_t *head;
4801 pm_multi_target_state_node_t *tail;
4810 pm_multi_target_state_node_t *node =
ALLOC(pm_multi_target_state_node_t);
4812 node->stack_index = state->stack_size + 1;
4813 node->stack_size = stack_size;
4814 node->position = state->position;
4817 if (state->head == NULL) {
4822 state->tail->next = node;
4826 state->stack_size += stack_size;
4839 if (state->stack_size == 0)
return;
4841 pm_multi_target_state_node_t *current = state->head;
4842 pm_multi_target_state_node_t *previous;
4844 while (current != NULL) {
4845 VALUE offset =
INT2FIX(state->stack_size - current->stack_index + current->position);
4846 current->topn->operands[0] = offset;
4852 if (current->stack_size > 1) {
4853 INSN *insn = current->topn;
4855 for (
size_t index = 1; index < current->stack_size; index += 1) {
4856 LINK_ELEMENT *element = get_next_insn(insn);
4859 insn = (INSN *) element;
4862 insn->operands[0] = offset;
4867 current = current->next;
4874pm_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);
4905pm_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)
4907 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
4917 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
4919 PUSH_SETLOCAL(writes, location, index.index, index.level);
4929 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4932 PUSH_INSN2(writes, location, setclassvariable, operand, get_cvar_ic_value(iseq, name));
4942 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4945 PUSH_INSN1(writes, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
4946 PUSH_INSN1(writes, location, setconstant, operand);
4956 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4959 PUSH_INSN1(writes, location, setglobal, operand);
4969 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4972 PUSH_INSN2(writes, location, setinstancevariable, operand, get_ivar_ic_value(iseq, name));
4985 ID name = pm_constant_id_lookup(scope_node, cast->
name);
4987 if (cast->
parent != NULL) {
4988 pm_compile_node(iseq, cast->
parent, parents,
false, scope_node);
4991 PUSH_INSN1(parents, location, putobject, rb_cObject);
4994 if (state == NULL) {
4995 PUSH_INSN(writes, location, swap);
4998 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
4999 pm_multi_target_state_push(state, (INSN *) LAST_ELEMENT(writes), 1);
5003 PUSH_INSN1(writes, location, setconstant, operand);
5005 if (state != NULL) {
5006 PUSH_INSN(cleanup, location, pop);
5021 ID method_id = pm_constant_id_lookup(scope_node, cast->
name);
5023 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5025 LABEL *safe_label = NULL;
5027 safe_label = NEW_LABEL(location.
line);
5028 PUSH_INSN(parents, location, dup);
5029 PUSH_INSNL(parents, location, branchnil, safe_label);
5032 if (state != NULL) {
5033 PUSH_INSN1(writes, location, topn,
INT2FIX(1));
5034 pm_multi_target_state_push(state, (INSN *) LAST_ELEMENT(writes), 1);
5035 PUSH_INSN(writes, location, swap);
5038 int flags = VM_CALL_ARGS_SIMPLE;
5041 PUSH_SEND_WITH_FLAG(writes, location, method_id,
INT2FIX(1),
INT2FIX(flags));
5042 if (safe_label != NULL && state == NULL) PUSH_LABEL(writes, safe_label);
5043 PUSH_INSN(writes, location, pop);
5044 if (safe_label != NULL && state != NULL) PUSH_LABEL(writes, safe_label);
5046 if (state != NULL) {
5047 PUSH_INSN(cleanup, location, pop);
5064 pm_compile_node(iseq, cast->
receiver, parents,
false, scope_node);
5068 int argc = pm_setup_args(cast->
arguments, (
const pm_node_t *) cast->
block, &flags, &kwargs, iseq, parents, scope_node, &location);
5070 if (state != NULL) {
5071 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5072 pm_multi_target_state_push(state, (INSN *) LAST_ELEMENT(writes), argc + 1);
5075 PUSH_INSN(writes, location, swap);
5078 for (
int index = 0; index < argc; index++) {
5079 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5081 PUSH_INSN1(writes, location, topn,
INT2FIX(argc + 1));
5089 int ci_argc = argc + 1;
5090 if (flags & VM_CALL_ARGS_SPLAT) {
5092 PUSH_INSN1(writes, location, newarray,
INT2FIX(1));
5093 PUSH_INSN(writes, location, concatarray);
5096 PUSH_SEND_R(writes, location, idASET,
INT2NUM(ci_argc), NULL,
INT2FIX(flags), kwargs);
5097 PUSH_INSN(writes, location, pop);
5099 if (state != NULL) {
5101 PUSH_INSN(writes, location, pop);
5104 for (
int index = 0; index < argc + 1; index++) {
5105 PUSH_INSN(cleanup, location, pop);
5118 size_t before_position;
5119 if (state != NULL) {
5120 before_position = state->position;
5124 pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, scope_node, state);
5125 if (state != NULL) state->position = before_position;
5138 pm_compile_target_node(iseq, cast->
expression, parents, writes, cleanup, scope_node, state);
5144 rb_bug(
"Unexpected node type: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
5155pm_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)
5157 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5165 lefts = &cast->
lefts;
5172 lefts = &cast->
lefts;
5178 rb_bug(
"Unsupported node %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
5183 bool has_posts = rights->
size > 0;
5188 PUSH_INSN2(writes, location, expandarray,
INT2FIX(lefts->
size),
INT2FIX((has_rest || has_posts) ? 1 : 0));
5194 if (state == NULL) state = &target_state;
5196 size_t base_position = state->position;
5197 size_t splat_position = (has_rest || has_posts) ? 1 : 0;
5200 for (
size_t index = 0; index < lefts->
size; index++) {
5202 state->position = lefts->
size - index + splat_position + base_position;
5203 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5209 state->position = 1 + rights->
size + base_position;
5215 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5220 if (!has_rest && rest != NULL) {
5224 for (
size_t index = 0; index < rights->
size; index++) {
5226 state->position = rights->
size - index + base_position;
5227 pm_compile_target_node(iseq, target, parents, writes, cleanup, scope_node, state);
5238pm_compile_for_node_index(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const ret, pm_scope_node_t *scope_node)
5240 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5246 PUSH_GETLOCAL(ret, location, 1, 0);
5247 pm_compile_target_node(iseq, node, ret, ret, ret, scope_node, NULL);
5261 DECL_ANCHOR(writes);
5262 DECL_ANCHOR(cleanup);
5266 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
5268 PUSH_GETLOCAL(ret, location, 1, 0);
5271 PUSH_SEQ(ret, writes);
5272 PUSH_SEQ(ret, cleanup);
5274 pm_multi_target_state_update(&state);
5278 DECL_ANCHOR(writes);
5279 DECL_ANCHOR(cleanup);
5281 pm_compile_target_node(iseq, node, ret, writes, cleanup, scope_node, NULL);
5283 LABEL *not_single = NEW_LABEL(location.
line);
5284 LABEL *not_ary = NEW_LABEL(location.
line);
5292 PUSH_GETLOCAL(ret, location, 1, 0);
5293 PUSH_INSN(ret, location, dup);
5294 PUSH_CALL(ret, location, idLength,
INT2FIX(0));
5295 PUSH_INSN1(ret, location, putobject,
INT2FIX(1));
5296 PUSH_CALL(ret, location, idEq,
INT2FIX(1));
5297 PUSH_INSNL(ret, location, branchunless, not_single);
5298 PUSH_INSN(ret, location, dup);
5299 PUSH_INSN1(ret, location, putobject,
INT2FIX(0));
5300 PUSH_CALL(ret, location, idAREF,
INT2FIX(1));
5301 PUSH_INSN1(ret, location, putobject,
rb_cArray);
5302 PUSH_INSN(ret, location, swap);
5303 PUSH_CALL(ret, location, rb_intern(
"try_convert"),
INT2FIX(1));
5304 PUSH_INSN(ret, location, dup);
5305 PUSH_INSNL(ret, location, branchunless, not_ary);
5306 PUSH_INSN(ret, location, swap);
5308 PUSH_LABEL(ret, not_ary);
5309 PUSH_INSN(ret, location, pop);
5311 PUSH_LABEL(ret, not_single);
5312 PUSH_SEQ(ret, writes);
5313 PUSH_SEQ(ret, cleanup);
5317 rb_bug(
"Unexpected node type for index in for node: %s", pm_node_type_to_str(
PM_NODE_TYPE(node)));
5323pm_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)
5327 LABEL *lstart = NEW_LABEL(node_location->
line);
5328 LABEL *lend = NEW_LABEL(node_location->
line);
5329 LABEL *lcont = NEW_LABEL(node_location->
line);
5331 pm_scope_node_t rescue_scope_node;
5334 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
5341 pm_scope_node_destroy(&rescue_scope_node);
5343 lstart->rescued = LABEL_RESCUE_BEG;
5344 lend->rescued = LABEL_RESCUE_END;
5345 PUSH_LABEL(ret, lstart);
5347 bool prev_in_rescue = ISEQ_COMPILE_DATA(iseq)->in_rescue;
5348 ISEQ_COMPILE_DATA(iseq)->in_rescue =
true;
5355 PUSH_INSN(ret, location, putnil);
5358 ISEQ_COMPILE_DATA(iseq)->in_rescue = prev_in_rescue;
5359 PUSH_LABEL(ret, lend);
5362 if (!popped) PUSH_INSN(ret, *node_location, pop);
5366 PUSH_INSN(ret, *node_location, nop);
5367 PUSH_LABEL(ret, lcont);
5369 if (popped) PUSH_INSN(ret, *node_location, pop);
5370 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
5371 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
5375pm_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)
5381 if (statements != NULL) {
5382 location = PM_NODE_START_LOCATION(parser, statements);
5385 location = *node_location;
5388 LABEL *lstart = NEW_LABEL(location.
line);
5389 LABEL *lend = NEW_LABEL(location.
line);
5390 LABEL *lcont = NEW_LABEL(location.
line);
5397 if (statements != NULL) {
5398 pm_compile_node(iseq, (
const pm_node_t *) statements, ensr,
true, scope_node);
5401 LINK_ELEMENT *last = ensr->last;
5402 bool last_leave = last && IS_INSN(last) && IS_INSN_ID(last, leave);
5407 push_ensure_entry(iseq, &enl, &er, (
void *) cast->
ensure_clause);
5409 PUSH_LABEL(ret, lstart);
5411 pm_compile_rescue(iseq, cast, node_location, ret, popped | last_leave, scope_node);
5414 pm_compile_node(iseq, (
const pm_node_t *) cast->
statements, ret, popped | last_leave, scope_node);
5416 else if (!(popped | last_leave)) {
5417 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
5420 PUSH_LABEL(ret, lend);
5421 PUSH_SEQ(ret, ensr);
5422 if (!popped && last_leave) PUSH_INSN(ret, *node_location, putnil);
5423 PUSH_LABEL(ret, lcont);
5424 if (last_leave) PUSH_INSN(ret, *node_location, pop);
5426 pm_scope_node_t next_scope_node;
5429 rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(
5436 pm_scope_node_destroy(&next_scope_node);
5438 erange = ISEQ_COMPILE_DATA(iseq)->ensure_node_stack->erange;
5439 if (lstart->link.next != &lend->link) {
5441 PUSH_CATCH_ENTRY(CATCH_TYPE_ENSURE, erange->begin, erange->end, child_iseq, lcont);
5442 erange = erange->next;
5445 ISEQ_COMPILE_DATA(iseq)->ensure_node_stack = enl.prev;
5453pm_opt_str_freeze_p(
const rb_iseq_t *iseq,
const pm_call_node_t *node)
5460 node->
block == NULL &&
5461 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5470pm_opt_aref_with_p(
const rb_iseq_t *iseq,
const pm_call_node_t *node)
5478 node->
block == NULL &&
5480 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5489pm_opt_aset_with_p(
const rb_iseq_t *iseq,
const pm_call_node_t *node)
5497 node->
block == NULL &&
5499 ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction
5508pm_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)
5510 const pm_node_location_t location = PM_LOCATION_START_LOCATION(scope_node->parser, name_loc, node_id);
5512 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache) {
5513 ISEQ_BODY(iseq)->ic_size++;
5514 VALUE segments = rb_ary_new_from_args(1, name);
5515 PUSH_INSN1(ret, location, opt_getconstant_path, segments);
5518 PUSH_INSN(ret, location, putnil);
5519 PUSH_INSN1(ret, location, putobject,
Qtrue);
5520 PUSH_INSN1(ret, location, getconstant, name);
5529pm_constant_path_parts(
const pm_node_t *node,
const pm_scope_node_t *scope_node)
5539 rb_ary_unshift(parts, name);
5546 rb_ary_unshift(parts, name);
5547 if (cast->
parent == NULL) {
5548 rb_ary_unshift(parts,
ID2SYM(idNULL));
5567pm_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)
5569 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5576 PUSH_INSN1(body, location, putobject,
Qtrue);
5577 PUSH_INSN1(body, location, getconstant, name);
5584 if (cast->
parent == NULL) {
5585 PUSH_INSN(body, location, pop);
5586 PUSH_INSN1(body, location, putobject, rb_cObject);
5587 PUSH_INSN1(body, location, putobject,
Qtrue);
5588 PUSH_INSN1(body, location, getconstant, name);
5591 pm_compile_constant_path(iseq, cast->
parent, prefix, body,
false, scope_node);
5592 PUSH_INSN1(body, location, putobject,
Qfalse);
5593 PUSH_INSN1(body, location, getconstant, name);
5598 PM_COMPILE_INTO_ANCHOR(prefix, node);
5607pm_compile_shareable_constant_literal(rb_iseq_t *iseq,
const pm_node_t *node,
const pm_scope_node_t *scope_node)
5621 return pm_static_literal_value(iseq, node, scope_node);
5623 return parse_static_literal_string(iseq, scope_node, node, &((
const pm_string_node_t *) node)->unescaped);
5630 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5631 VALUE element = pm_compile_shareable_constant_literal(iseq, cast->
elements.
nodes[index], scope_node);
5634 rb_ary_push(result, element);
5643 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5649 VALUE key = pm_compile_shareable_constant_literal(iseq, assoc->
key, scope_node);
5652 VALUE value = pm_compile_shareable_constant_literal(iseq, assoc->
value, scope_node);
5655 rb_hash_aset(result, key, value);
5670pm_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)
5672 VALUE literal = pm_compile_shareable_constant_literal(iseq, node, scope_node);
5674 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5675 PUSH_INSN1(ret, location, putobject, literal);
5679 const pm_node_location_t location = PM_NODE_START_LOCATION(scope_node->parser, node);
5685 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5688 for (
size_t index = 0; index < cast->
elements.
size; index++) {
5689 pm_compile_shareable_constant_value(iseq, cast->
elements.
nodes[index], shareability, path, ret, scope_node,
false);
5696 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5705 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5708 pm_compile_hash_elements(iseq, (
const pm_node_t *) cast, &cast->elements, shareability, path,
false, ret, scope_node);
5712 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5718 DECL_ANCHOR(value_seq);
5720 pm_compile_node(iseq, node, value_seq,
false, scope_node);
5722 PUSH_SEND_WITH_FLAG(value_seq, location, idUMinus,
INT2FIX(0),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5726 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5727 PUSH_SEQ(ret, value_seq);
5728 PUSH_INSN1(ret, location, putobject, path);
5729 PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"ensure_shareable"),
INT2FIX(2),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5732 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5733 PUSH_SEQ(ret, value_seq);
5734 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable_copy"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5737 if (top) PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
5738 PUSH_SEQ(ret, value_seq);
5739 if (top) PUSH_SEND_WITH_FLAG(ret, location, rb_intern(
"make_shareable"),
INT2FIX(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5755 ID name_id = pm_constant_id_lookup(scope_node, node->
name);
5757 if (shareability != 0) {
5758 pm_compile_shareable_constant_value(iseq, node->
value, shareability, rb_id2str(name_id), ret, scope_node,
true);
5761 PM_COMPILE_NOT_POPPED(node->
value);
5764 if (!popped) PUSH_INSN(ret, location, dup);
5765 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5768 PUSH_INSN1(ret, location, setconstant, operand);
5781 LABEL *end_label = NEW_LABEL(location.
line);
5783 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5784 if (!popped) PUSH_INSN(ret, location, dup);
5786 PUSH_INSNL(ret, location, branchunless, end_label);
5787 if (!popped) PUSH_INSN(ret, location, pop);
5789 if (shareability != 0) {
5790 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5793 PM_COMPILE_NOT_POPPED(node->
value);
5796 if (!popped) PUSH_INSN(ret, location, dup);
5797 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5798 PUSH_INSN1(ret, location, setconstant, name);
5799 PUSH_LABEL(ret, end_label);
5812 LABEL *set_label = NEW_LABEL(location.
line);
5813 LABEL *end_label = NEW_LABEL(location.
line);
5815 PUSH_INSN(ret, location, putnil);
5816 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST), name,
Qtrue);
5817 PUSH_INSNL(ret, location, branchunless, set_label);
5819 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5820 if (!popped) PUSH_INSN(ret, location, dup);
5822 PUSH_INSNL(ret, location, branchif, end_label);
5823 if (!popped) PUSH_INSN(ret, location, pop);
5824 PUSH_LABEL(ret, set_label);
5826 if (shareability != 0) {
5827 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5830 PM_COMPILE_NOT_POPPED(node->
value);
5833 if (!popped) PUSH_INSN(ret, location, dup);
5834 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5835 PUSH_INSN1(ret, location, setconstant, name);
5836 PUSH_LABEL(ret, end_label);
5851 pm_compile_constant_read(iseq, name, &node->
name_loc, location.
node_id, ret, scope_node);
5853 if (shareability != 0) {
5854 pm_compile_shareable_constant_value(iseq, node->
value, shareability, name, ret, scope_node,
true);
5857 PM_COMPILE_NOT_POPPED(node->
value);
5860 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
5861 if (!popped) PUSH_INSN(ret, location, dup);
5863 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CONST_BASE));
5864 PUSH_INSN1(ret, location, setconstant, name);
5875 rb_ary_push(parts, rb_id2str(pm_constant_id_lookup(scope_node, node->
name)));
5880 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, cast->
name)));
5884 if (current == NULL) {
5885 rb_ary_unshift(parts, rb_id2str(idNULL));
5888 rb_ary_unshift(parts, rb_id2str(pm_constant_id_lookup(scope_node, ((
const pm_constant_read_node_t *) current)->name)));
5912 PUSH_INSN1(ret, location, putobject, rb_cObject);
5915 if (shareability != 0) {
5916 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5919 PM_COMPILE_NOT_POPPED(node->
value);
5923 PUSH_INSN(ret, location, swap);
5924 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
5927 PUSH_INSN(ret, location, swap);
5928 PUSH_INSN1(ret, location, setconstant, name);
5942 LABEL *lfin = NEW_LABEL(location.
line);
5945 PM_COMPILE_NOT_POPPED(target->
parent);
5948 PUSH_INSN1(ret, location, putobject, rb_cObject);
5951 PUSH_INSN(ret, location, dup);
5952 PUSH_INSN1(ret, location, putobject,
Qtrue);
5953 PUSH_INSN1(ret, location, getconstant, name);
5955 if (!popped) PUSH_INSN(ret, location, dup);
5956 PUSH_INSNL(ret, location, branchunless, lfin);
5958 if (!popped) PUSH_INSN(ret, location, pop);
5960 if (shareability != 0) {
5961 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
5964 PM_COMPILE_NOT_POPPED(node->
value);
5968 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
5971 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
5972 PUSH_INSN(ret, location, swap);
5975 PUSH_INSN1(ret, location, setconstant, name);
5976 PUSH_LABEL(ret, lfin);
5978 if (!popped) PUSH_INSN(ret, location, swap);
5979 PUSH_INSN(ret, location, pop);
5993 LABEL *lassign = NEW_LABEL(location.
line);
5994 LABEL *lfin = NEW_LABEL(location.
line);
5997 PM_COMPILE_NOT_POPPED(target->
parent);
6000 PUSH_INSN1(ret, location, putobject, rb_cObject);
6003 PUSH_INSN(ret, location, dup);
6004 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CONST_FROM), name,
Qtrue);
6005 PUSH_INSNL(ret, location, branchunless, lassign);
6007 PUSH_INSN(ret, location, dup);
6008 PUSH_INSN1(ret, location, putobject,
Qtrue);
6009 PUSH_INSN1(ret, location, getconstant, name);
6011 if (!popped) PUSH_INSN(ret, location, dup);
6012 PUSH_INSNL(ret, location, branchif, lfin);
6014 if (!popped) PUSH_INSN(ret, location, pop);
6015 PUSH_LABEL(ret, lassign);
6017 if (shareability != 0) {
6018 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6021 PM_COMPILE_NOT_POPPED(node->
value);
6025 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6028 PUSH_INSN1(ret, location, dupn,
INT2FIX(2));
6029 PUSH_INSN(ret, location, swap);
6032 PUSH_INSN1(ret, location, setconstant, name);
6033 PUSH_LABEL(ret, lfin);
6035 if (!popped) PUSH_INSN(ret, location, swap);
6036 PUSH_INSN(ret, location, pop);
6053 PM_COMPILE_NOT_POPPED(target->
parent);
6056 PUSH_INSN1(ret, location, putobject, rb_cObject);
6059 PUSH_INSN(ret, location, dup);
6060 PUSH_INSN1(ret, location, putobject,
Qtrue);
6061 PUSH_INSN1(ret, location, getconstant, name);
6063 if (shareability != 0) {
6064 pm_compile_shareable_constant_value(iseq, node->
value, shareability, pm_constant_path_path(node->
target, scope_node), ret, scope_node,
true);
6067 PM_COMPILE_NOT_POPPED(node->
value);
6070 PUSH_CALL(ret, location, method_id,
INT2FIX(1));
6071 PUSH_INSN(ret, location, swap);
6074 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
6075 PUSH_INSN(ret, location, swap);
6078 PUSH_INSN1(ret, location, setconstant, name);
6087#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))
6094pm_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)
6106 bool trailing_comma =
false;
6112 if (scope_node->parameters != NULL) {
6116 parameters_node = cast->parameters;
6117 block_locals = &cast->locals;
6119 if (parameters_node) {
6121 trailing_comma =
true;
6132 body->
param.lead_num = maximum;
6133 body->
param.flags.ambiguous_param0 = maximum == 1;
6137 body->
param.lead_num = 1;
6138 body->
param.flags.ambiguous_param0 =
true;
6141 rb_bug(
"Unexpected node type for parameters: %s", pm_node_type_to_str(
PM_NODE_TYPE(scope_node->parameters)));
6145 struct rb_iseq_param_keyword *keyword = NULL;
6147 if (parameters_node) {
6148 optionals_list = ¶meters_node->
optionals;
6149 requireds_list = ¶meters_node->
requireds;
6150 keywords_list = ¶meters_node->
keywords;
6151 posts_list = ¶meters_node->
posts;
6154 body->
param.opt_num = 0;
6157 body->
param.lead_num = 0;
6158 body->
param.opt_num = 0;
6164 size_t locals_size = locals->
size;
6167 st_table *index_lookup_table = st_init_numtable();
6169 int table_size = (int) locals_size;
6175 if (keywords_list && keywords_list->
size) {
6179 if (requireds_list) {
6180 for (
size_t i = 0; i < requireds_list->
size; i++) {
6206 if (optionals_list && optionals_list->
size) {
6207 for (
size_t i = 0; i < optionals_list->
size; i++) {
6219 if (parameters_node) {
6220 if (parameters_node->
rest) {
6237 if (requireds_list->
size == 0 && optionals_list->
size == 0 && keywords_list->
size == 0) {
6238 ISEQ_BODY(iseq)->param.flags.use_block = TRUE;
6239 ISEQ_BODY(iseq)->param.flags.forwardable = TRUE;
6258 for (
size_t i = 0; i < posts_list->
size; i++) {
6269 if (keywords_list && keywords_list->
size) {
6270 for (
size_t i = 0; i < keywords_list->
size; i++) {
6278 if (parameters_node && parameters_node->
block) {
6288 rb_ast_id_table_t *local_table_for_iseq =
ALLOCV(idtmp,
sizeof(rb_ast_id_table_t) + table_size *
sizeof(
ID));
6289 local_table_for_iseq->size = table_size;
6309 int local_index = 0;
6316 if (requireds_list && requireds_list->
size) {
6317 for (
size_t i = 0; i < requireds_list->
size; i++, local_index++) {
6329 local = rb_make_temporary_id(local_index);
6330 local_table_for_iseq->ids[local_index] = local;
6339 ID local = pm_constant_id_lookup(scope_node, param->
name);
6340 local_table_for_iseq->ids[local_index] = local;
6343 pm_insert_local_index(param->
name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6349 rb_bug(
"Unsupported node in requireds in parameters %s", pm_node_type_to_str(
PM_NODE_TYPE(required)));
6353 body->
param.lead_num = (int) requireds_list->
size;
6354 body->
param.flags.has_lead =
true;
6358 ID local = rb_make_temporary_id(local_index);
6359 local_table_for_iseq->ids[local_index++] = local;
6364 if (optionals_list && optionals_list->
size) {
6365 body->
param.opt_num = (int) optionals_list->
size;
6366 body->
param.flags.has_opt =
true;
6368 for (
size_t i = 0; i < optionals_list->
size; i++, local_index++) {
6373 ID local = pm_constant_id_lookup(scope_node, name);
6374 local_table_for_iseq->ids[local_index] = local;
6377 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6384 if (parameters_node && parameters_node->
rest) {
6385 body->
param.rest_start = local_index;
6390 body->
param.flags.has_rest =
true;
6399 ID local = pm_constant_id_lookup(scope_node, name);
6400 local_table_for_iseq->ids[local_index] = local;
6403 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6409 body->
param.flags.anon_rest =
true;
6410 pm_insert_local_special(idMULT, local_index, index_lookup_table, local_table_for_iseq);
6419 if (posts_list && posts_list->
size) {
6420 body->
param.post_num = (int) posts_list->
size;
6421 body->
param.post_start = local_index;
6422 body->
param.flags.has_post =
true;
6424 for (
size_t i = 0; i < posts_list->
size; i++, local_index++) {
6436 local = rb_make_temporary_id(local_index);
6437 local_table_for_iseq->ids[local_index] = local;
6446 ID local = pm_constant_id_lookup(scope_node, param->
name);
6447 local_table_for_iseq->ids[local_index] = local;
6450 pm_insert_local_index(param->
name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6455 rb_bug(
"Unsupported node in posts in parameters %s", pm_node_type_to_str(
PM_NODE_TYPE(post_node)));
6463 if (keywords_list && keywords_list->
size) {
6464 keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6465 keyword->num = (int) keywords_list->
size;
6467 const VALUE default_values = rb_ary_hidden_new(1);
6470 for (
size_t i = 0; i < keywords_list->
size; i++) {
6478 keyword->required_num++;
6479 ID local = pm_constant_id_lookup(scope_node, name);
6482 local_table_for_iseq->ids[local_index] = local;
6485 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6491 for (
size_t i = 0; i < keywords_list->
size; i++) {
6503 if (
PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) {
6504 rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node));
6507 rb_ary_push(default_values, complex_mark);
6510 ID local = pm_constant_id_lookup(scope_node, name);
6512 local_table_for_iseq->ids[local_index] = local;
6515 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6525 for (
int i = 0; i <
RARRAY_LEN(default_values); i++) {
6527 if (dv == complex_mark) dv =
Qundef;
6531 keyword->default_values = dvs;
6535 keyword->bits_start = local_index;
6536 ID local = rb_make_temporary_id(local_index);
6537 local_table_for_iseq->ids[local_index] = local;
6540 body->
param.keyword = keyword;
6541 body->
param.flags.has_kw =
true;
6544 if (body->type == ISEQ_TYPE_BLOCK && local_index == 1 && requireds_list && requireds_list->
size == 1 && !trailing_comma) {
6545 body->
param.flags.ambiguous_param0 =
true;
6548 if (parameters_node) {
6556 body->
param.flags.accepts_no_kwarg =
true;
6563 if (!body->
param.flags.has_kw) {
6564 body->
param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6567 keyword->rest_start = local_index;
6568 body->
param.flags.has_kwrest =
true;
6573 ID local = pm_constant_id_lookup(scope_node, constant_id);
6574 local_table_for_iseq->ids[local_index] = local;
6577 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6581 body->
param.flags.anon_kwrest =
true;
6582 pm_insert_local_special(idPow, local_index, index_lookup_table, local_table_for_iseq);
6591 if (!ISEQ_BODY(iseq)->param.
flags.forwardable) {
6593 body->
param.rest_start = local_index;
6594 body->
param.flags.has_rest =
true;
6595 body->
param.flags.anon_rest =
true;
6596 pm_insert_local_special(idMULT, local_index++, index_lookup_table, local_table_for_iseq);
6600 body->
param.flags.has_kw =
false;
6601 body->
param.flags.has_kwrest =
true;
6602 body->
param.flags.anon_kwrest =
true;
6603 body->
param.keyword = keyword =
ZALLOC_N(
struct rb_iseq_param_keyword, 1);
6604 keyword->rest_start = local_index;
6605 pm_insert_local_special(idPow, local_index++, index_lookup_table, local_table_for_iseq);
6608 body->
param.block_start = local_index;
6609 body->
param.flags.has_block =
true;
6610 pm_insert_local_special(idAnd, local_index++, index_lookup_table, local_table_for_iseq);
6614 pm_insert_local_special(idDot3, local_index++, index_lookup_table, local_table_for_iseq);
6618 rb_bug(
"node type %s not expected as keyword_rest", pm_node_type_to_str(
PM_NODE_TYPE(parameters_node->
keyword_rest)));
6624 if (parameters_node->
block) {
6625 body->
param.block_start = local_index;
6626 body->
param.flags.has_block =
true;
6627 iseq_set_use_block(iseq);
6633 ID local = pm_constant_id_lookup(scope_node, name);
6634 local_table_for_iseq->ids[local_index] = local;
6637 pm_insert_local_index(name, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6641 pm_insert_local_special(idAnd, local_index, index_lookup_table, local_table_for_iseq);
6660 if (requireds_list && requireds_list->
size) {
6661 for (
size_t i = 0; i < requireds_list->
size; i++) {
6668 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);
6674 if (posts_list && posts_list->
size) {
6675 for (
size_t i = 0; i < posts_list->
size; i++) {
6682 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);
6690 body->
param.lead_num++;
6693 body->
param.rest_start = local_index;
6694 body->
param.flags.has_rest =
true;
6697 ID local = rb_make_temporary_id(local_index);
6698 local_table_for_iseq->ids[local_index] = local;
6706 for (
int i = 0; i < maximum; i++, local_index++) {
6707 const uint8_t param_name[] = {
'_',
'1' + i };
6709 RUBY_ASSERT(constant_id &&
"parser should fill in any gaps in numbered parameters");
6710 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6712 body->
param.lead_num = maximum;
6713 body->
param.flags.has_lead =
true;
6724 if (block_locals && block_locals->
size) {
6725 for (
size_t i = 0; i < block_locals->
size; i++, local_index++) {
6727 pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
6732 if (scope_node->locals.
size) {
6733 for (
size_t i = 0; i < scope_node->locals.
size; i++) {
6737 ctx.scope_node = scope_node;
6738 ctx.local_table_for_iseq = local_table_for_iseq;
6739 ctx.local_index = local_index;
6741 st_update(index_lookup_table, (st_data_t)constant_id, pm_local_table_insert_func, (st_data_t)&ctx);
6743 local_index = ctx.local_index;
6752 if (scope_node->index_lookup_table) {
6753 st_free_table(scope_node->index_lookup_table);
6755 scope_node->index_lookup_table = index_lookup_table;
6756 iseq_calc_param_size(iseq);
6758 if (ISEQ_BODY(iseq)->param.
flags.forwardable) {
6761 ISEQ_BODY(iseq)->param.size += 1;
6765 iseq_set_local_table(iseq, local_table_for_iseq, 0);
6766 scope_node->local_table_for_iseq_size = local_table_for_iseq->size;
6768 if (keyword != NULL) {
6769 size_t keyword_start_index = keyword->bits_start - keyword->num;
6770 keyword->table = (
ID *)&ISEQ_BODY(iseq)->local_table[keyword_start_index];
6775 if (optionals_list && optionals_list->
size) {
6783 for (
size_t i = 0; i < optionals_list->
size; i++) {
6784 label = NEW_LABEL(location.
line);
6785 opt_table[i] = label;
6786 PUSH_LABEL(ret, label);
6788 PM_COMPILE_NOT_POPPED(optional_node);
6792 label = NEW_LABEL(location.
line);
6793 opt_table[optionals_list->
size] = label;
6794 PUSH_LABEL(ret, label);
6796 body->
param.opt_table = (
const VALUE *) opt_table;
6799 if (keywords_list && keywords_list->
size) {
6800 size_t optional_index = 0;
6801 for (
size_t i = 0; i < keywords_list->
size; i++) {
6814 if (!
PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) {
6815 LABEL *end_label = NEW_LABEL(location.
line);
6817 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, name, 0);
6818 int kw_bits_idx = table_size - body->
param.keyword->bits_start;
6819 PUSH_INSN2(ret, location, checkkeyword,
INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1),
INT2FIX(optional_index));
6820 PUSH_INSNL(ret, location, branchif, end_label);
6822 PUSH_SETLOCAL(ret, location, index.index, index.level);
6823 PUSH_LABEL(ret, end_label);
6833 rb_bug(
"Unexpected keyword parameter node type %s", pm_node_type_to_str(
PM_NODE_TYPE(keyword_parameter_node)));
6838 if (requireds_list && requireds_list->
size) {
6839 for (
size_t i = 0; i < requireds_list->
size; i++) {
6846 PUSH_GETLOCAL(ret, location, table_size - (
int)i, 0);
6852 if (posts_list && posts_list->
size) {
6853 for (
size_t i = 0; i < posts_list->
size; i++) {
6860 PUSH_GETLOCAL(ret, location, table_size - body->
param.post_start - (
int) i, 0);
6866 switch (body->type) {
6867 case ISEQ_TYPE_PLAIN: {
6871 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
6875 case ISEQ_TYPE_BLOCK: {
6876 LABEL *start = ISEQ_COMPILE_DATA(iseq)->start_label = NEW_LABEL(0);
6877 LABEL *end = ISEQ_COMPILE_DATA(iseq)->end_label = NEW_LABEL(0);
6878 const pm_node_location_t block_location = { .line = body->location.first_lineno, .node_id = scope_node->ast_node->
node_id };
6880 start->rescued = LABEL_RESCUE_BEG;
6881 end->rescued = LABEL_RESCUE_END;
6888 pm_compile_for_node_index(iseq, ((
const pm_for_node_t *) scope_node->ast_node)->index, ret, scope_node);
6892 PUSH_INSN(ret, block_location, nop);
6893 PUSH_LABEL(ret, start);
6895 if (scope_node->body != NULL) {
6899 PUSH_INSN1(ret, block_location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
6902 pm_scope_node_t next_scope_node;
6903 pm_scope_node_init((
const pm_node_t *) cast->statements, &next_scope_node, scope_node);
6905 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(body->parent_iseq), ISEQ_TYPE_BLOCK, location.
line);
6906 pm_scope_node_destroy(&next_scope_node);
6908 PUSH_CALL_WITH_BLOCK(ret, block_location, id_core_set_postexe,
INT2FIX(0), block);
6913 pm_compile_regexp_dynamic(iseq, (
const pm_node_t *) cast, &cast->parts, &location, ret, popped, scope_node);
6917 pm_compile_node(iseq, scope_node->body, ret, popped, scope_node);
6922 PUSH_INSN(ret, block_location, putnil);
6925 PUSH_LABEL(ret, end);
6927 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
6930 PUSH_CATCH_ENTRY(CATCH_TYPE_REDO, start, end, NULL, start);
6931 PUSH_CATCH_ENTRY(CATCH_TYPE_NEXT, start, end, NULL, end);
6934 case ISEQ_TYPE_ENSURE: {
6935 const pm_node_location_t statements_location = (scope_node->body != NULL ? PM_NODE_START_LOCATION(scope_node->parser, scope_node->body) : location);
6936 iseq_set_exception_local_table(iseq);
6938 if (scope_node->body != NULL) {
6939 PM_COMPILE_POPPED((
const pm_node_t *) scope_node->body);
6942 PUSH_GETLOCAL(ret, statements_location, 1, 0);
6943 PUSH_INSN1(ret, statements_location,
throw,
INT2FIX(0));
6946 case ISEQ_TYPE_METHOD: {
6947 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
6950 if (scope_node->body) {
6951 PM_COMPILE((
const pm_node_t *) scope_node->body);
6954 PUSH_INSN(ret, location, putnil);
6957 ISEQ_COMPILE_DATA(iseq)->root_node = (
const void *) scope_node->body;
6960 ISEQ_COMPILE_DATA(iseq)->last_line = body->location.code_location.end_pos.lineno;
6963 case ISEQ_TYPE_RESCUE: {
6964 iseq_set_exception_local_table(iseq);
6966 LABEL *lab = NEW_LABEL(location.
line);
6967 LABEL *rescue_end = NEW_LABEL(location.
line);
6968 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
6970 PUSH_INSN1(ret, location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
6971 PUSH_INSNL(ret, location, branchif, lab);
6972 PUSH_INSNL(ret, location, jump, rescue_end);
6973 PUSH_LABEL(ret, lab);
6975 PM_COMPILE((
const pm_node_t *) scope_node->body);
6976 PUSH_INSN(ret, location, leave);
6977 PUSH_LABEL(ret, rescue_end);
6978 PUSH_GETLOCAL(ret, location, LVAR_ERRINFO, 0);
6981 PM_COMPILE((
const pm_node_t *) scope_node->ast_node);
6983 PUSH_INSN1(ret, location,
throw,
INT2FIX(0));
6988 if (scope_node->body) {
6989 PM_COMPILE((
const pm_node_t *) scope_node->body);
6992 PUSH_INSN(ret, location, putnil);
6998 const pm_node_location_t end_location = PM_NODE_END_LOCATION(scope_node->parser, scope_node->ast_node);
7000 ISEQ_COMPILE_DATA(iseq)->last_line = end_location.
line;
7004 const pm_node_location_t location = { .line = ISEQ_COMPILE_DATA(iseq)->last_line, .node_id = scope_node->ast_node->
node_id };
7005 PUSH_INSN(ret, location, leave);
7014 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7018 VALUE operand =
ID2SYM(rb_intern3((
const char *) name_loc->
start, name_loc->
end - name_loc->
start, scope_node->encoding));
7019 PUSH_INSN1(ret, *location, putobject, operand);
7024 VALUE operand =
ID2SYM(rb_intern3((
const char *) name_loc->
start, name_loc->
end - name_loc->
start, scope_node->encoding));
7025 PUSH_INSN1(ret, *location, putobject, operand);
7028 PUSH_SEND(ret, *location, id_core_set_variable_alias,
INT2FIX(2));
7029 if (popped) PUSH_INSN(ret, *location, pop);
7035 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7036 PUSH_INSN1(ret, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
7037 PM_COMPILE_NOT_POPPED(node->
new_name);
7038 PM_COMPILE_NOT_POPPED(node->
old_name);
7040 PUSH_SEND(ret, *location, id_core_set_method_alias,
INT2FIX(3));
7041 if (popped) PUSH_INSN(ret, *location, pop);
7045pm_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)
7047 LABEL *end_label = NEW_LABEL(location->
line);
7049 PM_COMPILE_NOT_POPPED(node->
left);
7050 if (!popped) PUSH_INSN(ret, *location, dup);
7051 PUSH_INSNL(ret, *location, branchunless, end_label);
7053 if (!popped) PUSH_INSN(ret, *location, pop);
7054 PM_COMPILE(node->
right);
7055 PUSH_LABEL(ret, end_label);
7068 if (elements->
size) {
7069 VALUE value = pm_static_literal_value(iseq, node, scope_node);
7070 PUSH_INSN1(ret, *location, duparray, value);
7073 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7091 const int max_new_array_size = 0x100;
7092 const unsigned int min_tmp_array_size = 0x40;
7094 int new_array_size = 0;
7095 bool first_chunk =
true;
7101 bool static_literal =
false;
7104#define FLUSH_CHUNK \
7105 if (new_array_size) { \
7106 if (first_chunk) PUSH_INSN1(ret, *location, newarray, INT2FIX(new_array_size)); \
7107 else PUSH_INSN1(ret, *location, pushtoarray, INT2FIX(new_array_size)); \
7108 first_chunk = false; \
7109 new_array_size = 0; \
7112 for (
size_t index = 0; index < elements->
size; index++) {
7120 PM_COMPILE_NOT_POPPED(splat_element->
expression);
7123 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_MULT, 0);
7124 PUSH_GETLOCAL(ret, *location, index.index, index.level);
7130 PUSH_INSN1(ret, *location, splatarray,
Qtrue);
7131 first_chunk =
false;
7134 PUSH_INSN(ret, *location, concattoarray);
7137 static_literal =
false;
7140 if (new_array_size == 0 && first_chunk) {
7141 PUSH_INSN1(ret, *location, newarray,
INT2FIX(0));
7142 first_chunk =
false;
7159 pm_compile_hash_elements(iseq, element, &keyword_hash->
elements, 0,
Qundef,
false, ret, scope_node);
7169 PUSH_INSN(ret, *location, pushtoarraykwsplat);
7177 !PM_CONTAINER_P(element) &&
7179 ((index + min_tmp_array_size) < elements->
size)
7184 size_t right_index = index + 1;
7186 right_index < elements->size &&
7188 !PM_CONTAINER_P(elements->
nodes[right_index])
7191 size_t tmp_array_size = right_index - index;
7192 if (tmp_array_size >= min_tmp_array_size) {
7193 VALUE tmp_array = rb_ary_hidden_new(tmp_array_size);
7196 for (; tmp_array_size; tmp_array_size--)
7197 rb_ary_push(tmp_array, pm_static_literal_value(iseq, elements->
nodes[index++], scope_node));
7205 PUSH_INSN1(ret, *location, duparray, tmp_array);
7206 first_chunk =
false;
7209 PUSH_INSN1(ret, *location, putobject, tmp_array);
7210 PUSH_INSN(ret, *location, concattoarray);
7214 PM_COMPILE_NOT_POPPED(element);
7215 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7216 static_literal =
true;
7219 PM_COMPILE_NOT_POPPED(element);
7220 if (++new_array_size >= max_new_array_size) FLUSH_CHUNK;
7221 static_literal =
false;
7226 if (popped) PUSH_INSN(ret, *location, pop);
7232pm_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)
7234 unsigned long throw_flag = 0;
7236 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
7238 LABEL *splabel = NEW_LABEL(0);
7239 PUSH_LABEL(ret, splabel);
7240 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
7246 PUSH_INSN(ret, *location, putnil);
7249 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
7250 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
7251 PUSH_ADJUST_RESTORE(ret, splabel);
7252 if (!popped) PUSH_INSN(ret, *location, putnil);
7255 const rb_iseq_t *ip = iseq;
7258 if (!ISEQ_COMPILE_DATA(ip)) {
7263 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
7264 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
7266 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
7269 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
7270 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7274 ip = ISEQ_BODY(ip)->parent_iseq;
7283 PUSH_INSN(ret, *location, putnil);
7286 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_BREAK));
7287 if (popped) PUSH_INSN(ret, *location, pop);
7292 COMPILE_ERROR(iseq, location->
line,
"Invalid break");
7297pm_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)
7299 ID method_id = pm_constant_id_lookup(scope_node, node->
name);
7305 const char *builtin_func;
7307 if (UNLIKELY(iseq_has_builtin_function_table(iseq)) && (builtin_func = pm_iseq_builtin_function_name(scope_node, node->
receiver, method_id)) != NULL) {
7308 pm_compile_builtin_function_call(iseq, ret, scope_node, node, &location, popped, ISEQ_COMPILE_DATA(iseq)->current_block, builtin_func);
7312 LABEL *start = NEW_LABEL(location.
line);
7313 if (node->
block) PUSH_LABEL(ret, start);
7315 switch (method_id) {
7317 if (pm_opt_str_freeze_p(iseq, node)) {
7319 const struct rb_callinfo *callinfo = new_callinfo(iseq, idUMinus, 0, 0, NULL, FALSE);
7320 PUSH_INSN2(ret, location, opt_str_uminus, value, callinfo);
7321 if (popped) PUSH_INSN(ret, location, pop);
7327 if (pm_opt_str_freeze_p(iseq, node)) {
7329 const struct rb_callinfo *callinfo = new_callinfo(iseq, idFreeze, 0, 0, NULL, FALSE);
7330 PUSH_INSN2(ret, location, opt_str_freeze, value, callinfo);
7331 if (popped) PUSH_INSN(ret, location, pop);
7337 if (pm_opt_aref_with_p(iseq, node)) {
7339 VALUE value = parse_static_literal_string(iseq, scope_node, (
const pm_node_t *)
string, &string->unescaped);
7341 PM_COMPILE_NOT_POPPED(node->
receiver);
7343 const struct rb_callinfo *callinfo = new_callinfo(iseq, idAREF, 1, 0, NULL, FALSE);
7344 PUSH_INSN2(ret, location, opt_aref_with, value, callinfo);
7347 PUSH_INSN(ret, location, pop);
7355 if (pm_opt_aset_with_p(iseq, node)) {
7357 VALUE value = parse_static_literal_string(iseq, scope_node, (
const pm_node_t *)
string, &string->unescaped);
7359 PM_COMPILE_NOT_POPPED(node->
receiver);
7363 PUSH_INSN(ret, location, swap);
7364 PUSH_INSN1(ret, location, topn,
INT2FIX(1));
7367 const struct rb_callinfo *callinfo = new_callinfo(iseq, idASET, 2, 0, NULL, FALSE);
7368 PUSH_INSN2(ret, location, opt_aset_with, value, callinfo);
7369 PUSH_INSN(ret, location, pop);
7377 PUSH_INSN(ret, location, putnil);
7381 PUSH_INSN(ret, location, putself);
7389 if (iseq_block_param_id_p(iseq, pm_constant_id_lookup(scope_node, read_node_cast->name), &idx, &level)) {
7390 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)));
7393 PM_COMPILE_NOT_POPPED(node->
receiver);
7397 PM_COMPILE_NOT_POPPED(node->
receiver);
7401 pm_compile_call(iseq, node, ret, popped, scope_node, method_id, start);
7411 flag = VM_CALL_FCALL;
7414 PM_COMPILE_NOT_POPPED(node->
receiver);
7416 LABEL *safe_label = NULL;
7418 safe_label = NEW_LABEL(location->
line);
7419 PUSH_INSN(ret, *location, dup);
7420 PUSH_INSNL(ret, *location, branchnil, safe_label);
7423 PUSH_INSN(ret, *location, dup);
7425 ID id_read_name = pm_constant_id_lookup(scope_node, node->
read_name);
7426 PUSH_SEND_WITH_FLAG(ret, *location, id_read_name,
INT2FIX(0),
INT2FIX(flag));
7428 PM_COMPILE_NOT_POPPED(node->
value);
7430 PUSH_SEND(ret, *location, id_operator,
INT2FIX(1));
7433 PUSH_INSN(ret, *location, swap);
7434 PUSH_INSN1(ret, *location, topn,
INT2FIX(1));
7437 ID id_write_name = pm_constant_id_lookup(scope_node, node->
write_name);
7438 PUSH_SEND_WITH_FLAG(ret, *location, id_write_name,
INT2FIX(1),
INT2FIX(flag));
7440 if (safe_label != NULL && popped) PUSH_LABEL(ret, safe_label);
7441 PUSH_INSN(ret, *location, pop);
7442 if (safe_label != NULL && !popped) PUSH_LABEL(ret, safe_label);
7462pm_compile_case_node_dispatch(rb_iseq_t *iseq,
VALUE dispatch,
const pm_node_t *node, LABEL *label,
const pm_scope_node_t *scope_node)
7468 key = pm_static_literal_value(iseq, node, scope_node);
7472 key = (
FIXABLE(intptr) ?
LONG2FIX((
long) intptr) : rb_dbl2big(intptr));
7484 key = pm_static_literal_value(iseq, node, scope_node);
7488 key = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
7495 if (
NIL_P(rb_hash_lookup(dispatch, key))) {
7496 rb_hash_aset(dispatch, key, ((
VALUE) label) | 1);
7506pm_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)
7515 DECL_ANCHOR(cond_seq);
7520 DECL_ANCHOR(body_seq);
7524 LABEL *end_label = NEW_LABEL(location.
line);
7532 rb_code_location_t case_location = { 0 };
7535 if (PM_BRANCH_COVERAGE_P(iseq)) {
7536 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7537 branches = decl_branch_base(iseq, PTR2NUM(cast), &case_location,
"case");
7543 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7547 int clause_lineno = pm_node_line_number(parser, (
const pm_node_t *) clause);
7548 LABEL *label = NEW_LABEL(clause_lineno);
7549 PUSH_LABEL(body_seq, label);
7552 if (PM_BRANCH_COVERAGE_P(iseq)) {
7553 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));
7554 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7557 if (clause->statements != NULL) {
7558 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7561 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7564 PUSH_INSNL(body_seq, location, jump, end_label);
7569 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7574 PUSH_INSN(cond_seq, cond_location, putnil);
7575 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7576 PUSH_INSN1(cond_seq, cond_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_WHEN | VM_CHECKMATCH_ARRAY));
7577 PUSH_INSNL(cond_seq, cond_location, branchif, label);
7580 LABEL *next_label = NEW_LABEL(pm_node_line_number(parser, condition));
7581 pm_compile_branch_condition(iseq, cond_seq, condition, label, next_label,
false, scope_node);
7582 PUSH_LABEL(cond_seq, next_label);
7589 if (PM_BRANCH_COVERAGE_P(iseq)) {
7590 rb_code_location_t branch_location;
7593 branch_location = case_location;
7600 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7608 PUSH_SYNTHETIC_PUTNIL(cond_seq, iseq);
7613 PUSH_INSNL(cond_seq, location, jump, end_label);
7614 PUSH_SEQ(ret, cond_seq);
7619 rb_code_location_t case_location = { 0 };
7622 if (PM_BRANCH_COVERAGE_P(iseq)) {
7623 case_location = pm_code_location(scope_node, (
const pm_node_t *) cast);
7624 branches = decl_branch_base(iseq, PTR2NUM(cast), &case_location,
"case");
7629 LABEL *else_label = NEW_LABEL(location.
line);
7637 if (ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
7639 RHASH_TBL_RAW(dispatch)->type = &cdhash_type;
7650 for (
size_t clause_index = 0; clause_index < conditions->
size; clause_index++) {
7655 LABEL *label = NEW_LABEL(clause_location.
line);
7660 for (
size_t condition_index = 0; condition_index < conditions->
size; condition_index++) {
7662 const pm_node_location_t condition_location = PM_NODE_START_LOCATION(parser, condition);
7667 if (dispatch !=
Qundef) {
7668 dispatch = pm_compile_case_node_dispatch(iseq, dispatch, condition, label, scope_node);
7672 PUSH_INSN(cond_seq, condition_location, dup);
7673 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7674 PUSH_INSN1(cond_seq, condition_location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_CASE | VM_CHECKMATCH_ARRAY));
7679 VALUE value = parse_static_literal_string(iseq, scope_node, condition, &string->
unescaped);
7680 PUSH_INSN1(cond_seq, condition_location, putobject, value);
7683 pm_compile_node(iseq, condition, cond_seq,
false, scope_node);
7686 PUSH_INSN1(cond_seq, condition_location, topn,
INT2FIX(1));
7687 PUSH_SEND_WITH_FLAG(cond_seq, condition_location, idEqq,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
7690 PUSH_INSNL(cond_seq, condition_location, branchif, label);
7697 PUSH_LABEL(body_seq, label);
7698 PUSH_INSN(body_seq, clause_location, pop);
7701 if (PM_BRANCH_COVERAGE_P(iseq)) {
7702 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));
7703 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"when", branches);
7706 if (clause->statements != NULL) {
7707 pm_compile_node(iseq, (
const pm_node_t *) clause->statements, body_seq, popped, scope_node);
7710 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7713 PUSH_INSNL(body_seq, clause_location, jump, end_label);
7724 if (dispatch !=
Qundef) {
7725 PUSH_INSN(ret, location, dup);
7726 PUSH_INSN2(ret, location, opt_case_dispatch, dispatch, else_label);
7727 LABEL_REF(else_label);
7730 PUSH_SEQ(ret, cond_seq);
7734 PUSH_LABEL(ret, else_label);
7738 PUSH_INSN(ret, else_location, pop);
7741 if (PM_BRANCH_COVERAGE_P(iseq)) {
7743 add_trace_branch_coverage(iseq, ret, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7747 PUSH_INSNL(ret, else_location, jump, end_label);
7750 PUSH_INSN(ret, location, pop);
7753 if (PM_BRANCH_COVERAGE_P(iseq)) {
7754 add_trace_branch_coverage(iseq, ret, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7757 if (!popped) PUSH_INSN(ret, location, putnil);
7758 PUSH_INSNL(ret, location, jump, end_label);
7762 PUSH_SEQ(ret, body_seq);
7763 PUSH_LABEL(ret, end_label);
7772 DECL_ANCHOR(body_seq);
7777 DECL_ANCHOR(cond_seq);
7781 LABEL *end_label = NEW_LABEL(location->
line);
7786 LABEL *else_label = NEW_LABEL(location->
line);
7790 rb_code_location_t case_location = { 0 };
7794 if (PM_BRANCH_COVERAGE_P(iseq)) {
7795 case_location = pm_code_location(scope_node, (
const pm_node_t *) node);
7796 branches = decl_branch_base(iseq, PTR2NUM(node), &case_location,
"case");
7806 if (in_single_pattern) {
7807 PUSH_INSN(ret, *location, putnil);
7808 PUSH_INSN(ret, *location, putnil);
7809 PUSH_INSN1(ret, *location, putobject,
Qfalse);
7810 PUSH_INSN(ret, *location, putnil);
7814 PUSH_INSN(ret, *location, putnil);
7826 const pm_node_location_t in_location = PM_NODE_START_LOCATION(scope_node->parser, in_node);
7830 PUSH_INSN(body_seq, in_location, putnil);
7833 LABEL *body_label = NEW_LABEL(in_location.
line);
7834 PUSH_LABEL(body_seq, body_label);
7835 PUSH_INSN1(body_seq, in_location, adjuststack,
INT2FIX(in_single_pattern ? 6 : 2));
7838 if (PM_BRANCH_COVERAGE_P(iseq)) {
7840 add_trace_branch_coverage(iseq, body_seq, &branch_location, branch_location.beg_pos.column, branch_id++,
"in", branches);
7847 PUSH_SYNTHETIC_PUTNIL(body_seq, iseq);
7850 PUSH_INSNL(body_seq, in_location, jump, end_label);
7851 LABEL *next_pattern_label = NEW_LABEL(pattern_location.
line);
7853 PUSH_INSN(cond_seq, pattern_location, dup);
7854 pm_compile_pattern(iseq, scope_node, in_node->
pattern, cond_seq, body_label, next_pattern_label, in_single_pattern,
false,
true, 2);
7855 PUSH_LABEL(cond_seq, next_pattern_label);
7856 LABEL_UNREMOVABLE(next_pattern_label);
7865 PUSH_LABEL(cond_seq, else_label);
7866 PUSH_INSN(cond_seq, *location, pop);
7867 PUSH_INSN(cond_seq, *location, pop);
7870 if (PM_BRANCH_COVERAGE_P(iseq)) {
7872 add_trace_branch_coverage(iseq, cond_seq, &branch_location, branch_location.beg_pos.column, branch_id,
"else", branches);
7875 PM_COMPILE_INTO_ANCHOR(cond_seq, (
const pm_node_t *) else_node);
7876 PUSH_INSNL(cond_seq, *location, jump, end_label);
7877 PUSH_INSN(cond_seq, *location, putnil);
7878 if (popped) PUSH_INSN(cond_seq, *location, putnil);
7883 PUSH_LABEL(cond_seq, else_label);
7886 add_trace_branch_coverage(iseq, cond_seq, &case_location, case_location.beg_pos.column, branch_id,
"else", branches);
7888 if (in_single_pattern) {
7889 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, cond_seq, end_label, popped);
7892 PUSH_INSN1(cond_seq, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
7894 PUSH_INSN1(cond_seq, *location, topn,
INT2FIX(2));
7895 PUSH_SEND(cond_seq, *location, id_core_raise,
INT2FIX(2));
7897 PUSH_INSN1(cond_seq, *location, adjuststack,
INT2FIX(3));
7898 if (!popped) PUSH_INSN(cond_seq, *location, putnil);
7899 PUSH_INSNL(cond_seq, *location, jump, end_label);
7900 PUSH_INSN1(cond_seq, *location, dupn,
INT2FIX(1));
7901 if (popped) PUSH_INSN(cond_seq, *location, putnil);
7908 PUSH_SEQ(ret, cond_seq);
7909 PUSH_SEQ(ret, body_seq);
7910 PUSH_LABEL(ret, end_label);
7916 const rb_iseq_t *block = NULL;
7917 const rb_iseq_t *previous_block = NULL;
7918 LABEL *retry_label = NULL;
7919 LABEL *retry_end_l = NULL;
7921 if (node->
block != NULL) {
7922 previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
7923 ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
7925 retry_label = NEW_LABEL(location->
line);
7926 retry_end_l = NEW_LABEL(location->
line);
7928 PUSH_LABEL(ret, retry_label);
7931 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
7934 PUSH_INSN(ret, *location, putself);
7935 int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
7937 if (node->
block != NULL) {
7938 pm_scope_node_t next_scope_node;
7939 pm_scope_node_init((
const pm_node_t *) node->
block, &next_scope_node, scope_node);
7941 ISEQ_COMPILE_DATA(iseq)->current_block = block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
7942 pm_scope_node_destroy(&next_scope_node);
7949 const rb_iseq_t *local_iseq = body->local_iseq;
7953 int depth = get_lvar_level(iseq);
7955 if (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
param.flags.forwardable) {
7956 flag |= VM_CALL_FORWARDING;
7957 pm_local_index_t mult_local = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_DOT3, 0);
7958 PUSH_GETLOCAL(ret, *location, mult_local.index, mult_local.level);
7960 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, 0, flag, NULL, block != NULL);
7961 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, block);
7963 if (popped) PUSH_INSN(ret, *location, pop);
7965 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
7970 if (local_body->
param.flags.has_lead) {
7972 for (
int i = 0; i < local_body->
param.lead_num; i++) {
7973 int idx = local_body->local_table_size - i;
7974 PUSH_GETLOCAL(args, *location, idx, depth);
7976 argc += local_body->
param.lead_num;
7979 if (local_body->
param.flags.has_opt) {
7981 for (
int j = 0; j < local_body->
param.opt_num; j++) {
7982 int idx = local_body->local_table_size - (argc + j);
7983 PUSH_GETLOCAL(args, *location, idx, depth);
7985 argc += local_body->
param.opt_num;
7988 if (local_body->
param.flags.has_rest) {
7990 int idx = local_body->local_table_size - local_body->
param.rest_start;
7991 PUSH_GETLOCAL(args, *location, idx, depth);
7992 PUSH_INSN1(args, *location, splatarray,
Qfalse);
7994 argc = local_body->
param.rest_start + 1;
7995 flag |= VM_CALL_ARGS_SPLAT;
7998 if (local_body->
param.flags.has_post) {
8000 int post_len = local_body->
param.post_num;
8001 int post_start = local_body->
param.post_start;
8004 for (; j < post_len; j++) {
8005 int idx = local_body->local_table_size - (post_start + j);
8006 PUSH_GETLOCAL(args, *location, idx, depth);
8009 if (local_body->
param.flags.has_rest) {
8011 PUSH_INSN1(args, *location, newarray,
INT2FIX(j));
8012 PUSH_INSN(args, *location, concatarray);
8015 argc = post_len + post_start;
8019 const struct rb_iseq_param_keyword *
const local_keyword = local_body->
param.keyword;
8020 if (local_body->
param.flags.has_kw) {
8021 int local_size = local_body->local_table_size;
8024 PUSH_INSN1(args, *location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
8026 if (local_body->
param.flags.has_kwrest) {
8027 int idx = local_body->local_table_size - local_keyword->rest_start;
8028 PUSH_GETLOCAL(args, *location, idx, depth);
8030 PUSH_SEND(args, *location, rb_intern(
"dup"),
INT2FIX(0));
8033 PUSH_INSN1(args, *location, newhash,
INT2FIX(0));
8036 for (; i < local_keyword->num; ++i) {
8037 ID id = local_keyword->table[i];
8038 int idx = local_size - get_local_var_idx(local_iseq,
id);
8042 PUSH_INSN1(args, *location, putobject, operand);
8045 PUSH_GETLOCAL(args, *location, idx, depth);
8048 PUSH_SEND(args, *location, id_core_hash_merge_ptr,
INT2FIX(i * 2 + 1));
8049 flag |= VM_CALL_KW_SPLAT| VM_CALL_KW_SPLAT_MUT;
8051 else if (local_body->
param.flags.has_kwrest) {
8052 int idx = local_body->local_table_size - local_keyword->rest_start;
8053 PUSH_GETLOCAL(args, *location, idx, depth);
8055 flag |= VM_CALL_KW_SPLAT;
8058 PUSH_SEQ(ret, args);
8061 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flag, NULL, block != NULL);
8062 PUSH_INSN2(ret, *location, invokesuper, callinfo, block);
8065 if (node->
block != NULL) {
8066 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8067 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, block, retry_end_l);
8068 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8071 if (popped) PUSH_INSN(ret, *location, pop);
8077 LABEL *matched_label = NEW_LABEL(location->
line);
8078 LABEL *unmatched_label = NEW_LABEL(location->
line);
8079 LABEL *done_label = NEW_LABEL(location->
line);
8083 PUSH_INSN(ret, *location, putnil);
8084 PUSH_INSN(ret, *location, putnil);
8085 PUSH_INSN1(ret, *location, putobject,
Qfalse);
8086 PUSH_INSN(ret, *location, putnil);
8087 PUSH_INSN(ret, *location, putnil);
8091 PM_COMPILE_NOT_POPPED(node->
value);
8095 PUSH_INSN(ret, *location, dup);
8102 pm_compile_pattern(iseq, scope_node, node->
pattern, ret, matched_label, unmatched_label,
true,
false,
true, 2);
8107 PUSH_LABEL(ret, unmatched_label);
8108 pm_compile_pattern_error_handler(iseq, scope_node, (
const pm_node_t *) node, ret, done_label, popped);
8112 PUSH_LABEL(ret, matched_label);
8113 PUSH_INSN1(ret, *location, adjuststack,
INT2FIX(6));
8114 if (!popped) PUSH_INSN(ret, *location, putnil);
8115 PUSH_INSNL(ret, *location, jump, done_label);
8117 PUSH_LABEL(ret, done_label);
8123 LABEL *fail_label = NEW_LABEL(location->
line);
8124 LABEL *end_label = NEW_LABEL(location->
line);
8135 PUSH_INSN1(ret, *location, getglobal, operand);
8138 PUSH_INSN(ret, *location, dup);
8139 PUSH_INSNL(ret, *location, branchunless, fail_label);
8145 if (targets_count == 1) {
8150 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->
name, local_target->
depth);
8154 PUSH_INSN1(ret, *location, putobject, operand);
8157 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8158 PUSH_LABEL(ret, fail_label);
8159 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8160 if (popped) PUSH_INSN(ret, *location, pop);
8164 DECL_ANCHOR(fail_anchor);
8168 for (
size_t targets_index = 0; targets_index < targets_count; targets_index++) {
8173 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, local_target->
name, local_target->
depth);
8175 if (((
size_t) targets_index) < (targets_count - 1)) {
8176 PUSH_INSN(ret, *location, dup);
8181 PUSH_INSN1(ret, *location, putobject, operand);
8184 PUSH_SEND(ret, *location, idAREF,
INT2FIX(1));
8185 PUSH_SETLOCAL(ret, *location, index.index, index.level);
8187 PUSH_INSN(fail_anchor, *location, putnil);
8188 PUSH_SETLOCAL(fail_anchor, *location, index.index, index.level);
8192 PUSH_INSNL(ret, *location, jump, end_label);
8196 PUSH_LABEL(ret, fail_label);
8197 PUSH_INSN(ret, *location, pop);
8198 PUSH_SEQ(ret, fail_anchor);
8201 PUSH_LABEL(ret, end_label);
8202 if (popped) PUSH_INSN(ret, *location, pop);
8206pm_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)
8208 if (ISEQ_COMPILE_DATA(iseq)->redo_label != 0 && can_add_ensure_iseq(iseq)) {
8209 LABEL *splabel = NEW_LABEL(0);
8210 PUSH_LABEL(ret, splabel);
8216 PUSH_INSN(ret, *location, putnil);
8218 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8220 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8221 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8223 PUSH_ADJUST_RESTORE(ret, splabel);
8224 if (!popped) PUSH_INSN(ret, *location, putnil);
8226 else if (ISEQ_COMPILE_DATA(iseq)->end_label && can_add_ensure_iseq(iseq)) {
8227 LABEL *splabel = NEW_LABEL(0);
8229 PUSH_LABEL(ret, splabel);
8230 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8236 PUSH_INSN(ret, *location, putnil);
8239 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8240 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->end_label);
8241 PUSH_ADJUST_RESTORE(ret, splabel);
8242 splabel->unremovable = FALSE;
8244 if (!popped) PUSH_INSN(ret, *location, putnil);
8247 const rb_iseq_t *ip = iseq;
8248 unsigned long throw_flag = 0;
8251 if (!ISEQ_COMPILE_DATA(ip)) {
8256 throw_flag = VM_THROW_NO_ESCAPE_FLAG;
8257 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8261 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8264 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8265 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8269 ip = ISEQ_BODY(ip)->parent_iseq;
8277 PUSH_INSN(ret, *location, putnil);
8280 PUSH_INSN1(ret, *location,
throw,
INT2FIX(throw_flag | TAG_NEXT));
8281 if (popped) PUSH_INSN(ret, *location, pop);
8284 COMPILE_ERROR(iseq, location->
line,
"Invalid next");
8290pm_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)
8292 if (ISEQ_COMPILE_DATA(iseq)->redo_label && can_add_ensure_iseq(iseq)) {
8293 LABEL *splabel = NEW_LABEL(0);
8295 PUSH_LABEL(ret, splabel);
8296 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->redo_label);
8297 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8299 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->redo_label);
8300 PUSH_ADJUST_RESTORE(ret, splabel);
8301 if (!popped) PUSH_INSN(ret, *location, putnil);
8303 else if (ISEQ_BODY(iseq)->
type != ISEQ_TYPE_EVAL && ISEQ_COMPILE_DATA(iseq)->start_label && can_add_ensure_iseq(iseq)) {
8304 LABEL *splabel = NEW_LABEL(0);
8306 PUSH_LABEL(ret, splabel);
8307 pm_add_ensure_iseq(ret, iseq, 0, scope_node);
8308 PUSH_ADJUST(ret, *location, ISEQ_COMPILE_DATA(iseq)->start_label);
8310 PUSH_INSNL(ret, *location, jump, ISEQ_COMPILE_DATA(iseq)->start_label);
8311 PUSH_ADJUST_RESTORE(ret, splabel);
8312 if (!popped) PUSH_INSN(ret, *location, putnil);
8315 const rb_iseq_t *ip = iseq;
8318 if (!ISEQ_COMPILE_DATA(ip)) {
8323 if (ISEQ_COMPILE_DATA(ip)->redo_label != 0) {
8326 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_BLOCK) {
8329 else if (ISEQ_BODY(ip)->
type == ISEQ_TYPE_EVAL) {
8330 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8334 ip = ISEQ_BODY(ip)->parent_iseq;
8338 PUSH_INSN(ret, *location, putnil);
8339 PUSH_INSN1(ret, *location,
throw,
INT2FIX(VM_THROW_NO_ESCAPE_FLAG | TAG_REDO));
8340 if (popped) PUSH_INSN(ret, *location, pop);
8343 COMPILE_ERROR(iseq, location->
line,
"Invalid redo");
8349pm_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)
8351 iseq_set_exception_local_table(iseq);
8355 LABEL *exception_match_label = NEW_LABEL(location->
line);
8356 LABEL *rescue_end_label = NEW_LABEL(location->
line);
8366 if (exceptions->
size > 0) {
8367 for (
size_t index = 0; index < exceptions->
size; index++) {
8368 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8369 PM_COMPILE(exceptions->
nodes[index]);
8370 int checkmatch_flags = VM_CHECKMATCH_TYPE_RESCUE;
8372 checkmatch_flags |= VM_CHECKMATCH_ARRAY;
8374 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(checkmatch_flags));
8375 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8379 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8381 PUSH_INSN1(ret, *location, checkmatch,
INT2FIX(VM_CHECKMATCH_TYPE_RESCUE));
8382 PUSH_INSNL(ret, *location, branchif, exception_match_label);
8387 PUSH_INSNL(ret, *location, jump, rescue_end_label);
8392 PUSH_LABEL(ret, exception_match_label);
8399 DECL_ANCHOR(writes);
8400 DECL_ANCHOR(cleanup);
8402 pm_compile_target_node(iseq, node->
reference, ret, writes, cleanup, scope_node, NULL);
8403 PUSH_GETLOCAL(ret, *location, LVAR_ERRINFO, 0);
8405 PUSH_SEQ(ret, writes);
8406 PUSH_SEQ(ret, cleanup);
8416 LABEL *prev_end = ISEQ_COMPILE_DATA(iseq)->end_label;
8417 ISEQ_COMPILE_DATA(iseq)->end_label = NULL;
8422 ISEQ_COMPILE_DATA(iseq)->end_label = prev_end;
8425 PUSH_INSN(ret, *location, putnil);
8428 PUSH_INSN(ret, *location, leave);
8434 PUSH_LABEL(ret, rescue_end_label);
8439 PUSH_GETLOCAL(ret, *location, 1, 0);
8444pm_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)
8447 enum rb_iseq_type
type = ISEQ_BODY(iseq)->type;
8450 const rb_iseq_t *parent_iseq = iseq;
8451 enum rb_iseq_type parent_type = ISEQ_BODY(parent_iseq)->type;
8452 while (parent_type == ISEQ_TYPE_RESCUE || parent_type == ISEQ_TYPE_ENSURE) {
8453 if (!(parent_iseq = ISEQ_BODY(parent_iseq)->parent_iseq))
break;
8454 parent_type = ISEQ_BODY(parent_iseq)->type;
8457 switch (parent_type) {
8459 case ISEQ_TYPE_MAIN:
8461 rb_warn(
"argument of top-level return is ignored");
8463 if (parent_iseq == iseq) {
8464 type = ISEQ_TYPE_METHOD;
8471 if (
type == ISEQ_TYPE_METHOD) {
8472 splabel = NEW_LABEL(0);
8473 PUSH_LABEL(ret, splabel);
8474 PUSH_ADJUST(ret, *location, 0);
8477 if (arguments != NULL) {
8478 PM_COMPILE_NOT_POPPED((
const pm_node_t *) arguments);
8481 PUSH_INSN(ret, *location, putnil);
8484 if (
type == ISEQ_TYPE_METHOD && can_add_ensure_iseq(iseq)) {
8485 pm_add_ensure_iseq(ret, iseq, 1, scope_node);
8487 PUSH_INSN(ret, *location, leave);
8488 PUSH_ADJUST_RESTORE(ret, splabel);
8489 if (!popped) PUSH_INSN(ret, *location, putnil);
8492 PUSH_INSN1(ret, *location,
throw,
INT2FIX(TAG_RETURN));
8493 if (popped) PUSH_INSN(ret, *location, pop);
8498pm_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)
8502 LABEL *retry_label = NEW_LABEL(location->
line);
8503 LABEL *retry_end_l = NEW_LABEL(location->
line);
8505 const rb_iseq_t *previous_block = ISEQ_COMPILE_DATA(iseq)->current_block;
8506 const rb_iseq_t *current_block;
8507 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NULL;
8509 PUSH_LABEL(ret, retry_label);
8510 PUSH_INSN(ret, *location, putself);
8514 int argc = pm_setup_args(node->
arguments, node->
block, &flags, &keywords, iseq, ret, scope_node, location);
8516 flags |= VM_CALL_SUPER | VM_CALL_FCALL;
8519 pm_scope_node_t next_scope_node;
8520 pm_scope_node_init(node->
block, &next_scope_node, scope_node);
8522 ISEQ_COMPILE_DATA(iseq)->current_block = current_block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location->
line);
8523 pm_scope_node_destroy(&next_scope_node);
8527 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8530 if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
8531 PUSH_INSN(args, *location, splatkw);
8534 PUSH_SEQ(ret, args);
8535 if (is_forwardable && ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.
flags.forwardable) {
8536 flags |= VM_CALL_FORWARDING;
8539 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8540 PUSH_INSN2(ret, *location, invokesuperforward, callinfo, current_block);
8545 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, current_block != NULL);
8546 PUSH_INSN2(ret, *location, invokesuper, callinfo, current_block);
8551 pm_compile_retry_end_label(iseq, ret, retry_end_l);
8553 if (popped) PUSH_INSN(ret, *location, pop);
8554 ISEQ_COMPILE_DATA(iseq)->current_block = previous_block;
8555 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, current_block, retry_end_l);
8559pm_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)
8561 switch (ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->
type) {
8563 case ISEQ_TYPE_MAIN:
8564 case ISEQ_TYPE_CLASS:
8565 COMPILE_ERROR(iseq, location->
line,
"Invalid yield");
8575 argc = pm_setup_args(node->
arguments, NULL, &flags, &keywords, iseq, ret, scope_node, location);
8578 const struct rb_callinfo *callinfo = new_callinfo(iseq, 0, argc, flags, keywords, FALSE);
8579 PUSH_INSN1(ret, *location, invokeblock, callinfo);
8581 iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
8582 if (popped) PUSH_INSN(ret, *location, pop);
8585 for (
const rb_iseq_t *tmp_iseq = iseq; tmp_iseq != ISEQ_BODY(iseq)->local_iseq; level++) {
8586 tmp_iseq = ISEQ_BODY(tmp_iseq)->parent_iseq;
8589 if (level > 0) access_outer_variables(iseq, level, rb_intern(
"yield"),
true);
8603pm_compile_node(rb_iseq_t *iseq,
const pm_node_t *node, LINK_ANCHOR *
const ret,
bool popped, pm_scope_node_t *scope_node)
8607 int lineno = (int) location.
line;
8614 lineno = (int) PM_NODE_START_LINE_COLUMN(parser, ((
const pm_begin_node_t *) node)->rescue_clause).line;
8623 ISEQ_COMPILE_DATA(iseq)->last_line = lineno;
8624 if (lineno > 0 && ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {
8625 event |= RUBY_EVENT_COVERAGE_LINE;
8627 PUSH_TRACE(ret, event);
8639 pm_compile_alias_method_node(iseq, (
const pm_alias_method_node_t *) node, &location, ret, popped, scope_node);
8644 pm_compile_and_node(iseq, (
const pm_and_node_t *) node, &location, ret, popped, scope_node);
8656 if (elements->
size == 1) {
8659 PM_COMPILE(elements->
nodes[0]);
8662 pm_compile_array_node(iseq, (
const pm_node_t *) cast, elements, &location, ret, popped, scope_node);
8670 pm_compile_array_node(iseq, (
const pm_node_t *) cast, &cast->elements, &location, ret, popped, scope_node);
8681 PM_COMPILE(cast->
key);
8682 PM_COMPILE(cast->
value);
8694 if (cast->
value != NULL) {
8695 PM_COMPILE(cast->
value);
8698 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
8699 PUSH_GETLOCAL(ret, location, index.index, index.level);
8709 VALUE backref = pm_compile_back_reference_ref(cast);
8711 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), backref);
8723 pm_compile_ensure(iseq, cast, &location, ret, popped, scope_node);
8727 pm_compile_rescue(iseq, cast, &location, ret, popped, scope_node);
8736 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
8751 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_AND, 0);
8752 PUSH_INSN2(ret, location, getblockparamproxy,
INT2FIX(local_index.index + VM_ENV_DATA_SIZE - 1),
INT2FIX(local_index.level));
8762 pm_compile_break_node(iseq, (
const pm_break_node_t *) node, &location, ret, popped, scope_node);
8773 pm_compile_call_node(iseq, (
const pm_call_node_t *) node, ret, popped, scope_node);
8779 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);
8786 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);
8804 pm_compile_case_node(iseq, (
const pm_case_node_t *) node, &location, ret, popped, scope_node);
8815 pm_compile_case_match_node(iseq, (
const pm_case_match_node_t *) node, &location, ret, popped, scope_node);
8822 ID class_id = pm_constant_id_lookup(scope_node, cast->
name);
8823 VALUE class_name =
rb_str_freeze(rb_sprintf(
"<class:%"PRIsVALUE
">", rb_id2str(class_id)));
8825 pm_scope_node_t next_scope_node;
8826 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
8828 const rb_iseq_t *class_iseq = NEW_CHILD_ISEQ(&next_scope_node, class_name, ISEQ_TYPE_CLASS, location.
line);
8829 pm_scope_node_destroy(&next_scope_node);
8832 const int flags = VM_DEFINECLASS_TYPE_CLASS |
8833 (cast->
superclass ? VM_DEFINECLASS_FLAG_HAS_SUPERCLASS : 0) |
8834 pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
8840 PUSH_INSN(ret, location, putnil);
8845 PUSH_INSN3(ret, location, defineclass, operand, class_iseq,
INT2FIX(flags));
8849 if (popped) PUSH_INSN(ret, location, pop);
8856 LABEL *end_label = NEW_LABEL(location.
line);
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 if (!popped) PUSH_INSN(ret, location, dup);
8864 PUSH_INSNL(ret, location, branchunless, end_label);
8865 if (!popped) PUSH_INSN(ret, location, pop);
8867 PM_COMPILE_NOT_POPPED(cast->
value);
8868 if (!popped) PUSH_INSN(ret, location, dup);
8870 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8871 PUSH_LABEL(ret, end_label);
8880 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8883 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8884 PM_COMPILE_NOT_POPPED(cast->
value);
8887 int flags = VM_CALL_ARGS_SIMPLE;
8888 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
8890 if (!popped) PUSH_INSN(ret, location, dup);
8891 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8899 LABEL *end_label = NEW_LABEL(location.
line);
8900 LABEL *start_label = NEW_LABEL(location.
line);
8902 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
8905 PUSH_INSN(ret, location, putnil);
8906 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_CVAR), name,
Qtrue);
8907 PUSH_INSNL(ret, location, branchunless, start_label);
8909 PUSH_INSN2(ret, location, getclassvariable, name, get_cvar_ic_value(iseq, name_id));
8910 if (!popped) PUSH_INSN(ret, location, dup);
8912 PUSH_INSNL(ret, location, branchif, end_label);
8913 if (!popped) PUSH_INSN(ret, location, pop);
8915 PUSH_LABEL(ret, start_label);
8916 PM_COMPILE_NOT_POPPED(cast->
value);
8917 if (!popped) PUSH_INSN(ret, location, dup);
8919 PUSH_INSN2(ret, location, setclassvariable, name, get_cvar_ic_value(iseq, name_id));
8920 PUSH_LABEL(ret, end_label);
8929 ID name = pm_constant_id_lookup(scope_node, cast->
name);
8930 PUSH_INSN2(ret, location, getclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
8938 PM_COMPILE_NOT_POPPED(cast->
value);
8939 if (!popped) PUSH_INSN(ret, location, dup);
8941 ID name = pm_constant_id_lookup(scope_node, cast->
name);
8942 PUSH_INSN2(ret, location, setclassvariable,
ID2SYM(name), get_cvar_ic_value(iseq, name));
8951 if (ISEQ_COMPILE_DATA(iseq)->option->inline_const_cache && ((parts = pm_constant_path_parts(node, scope_node)) !=
Qnil)) {
8952 ISEQ_BODY(iseq)->ic_size++;
8953 PUSH_INSN1(ret, location, opt_getconstant_path, parts);
8956 DECL_ANCHOR(prefix);
8959 pm_compile_constant_path(iseq, node, prefix, body, popped, scope_node);
8960 if (LIST_INSN_SIZE_ZERO(prefix)) {
8961 PUSH_INSN(ret, location, putnil);
8964 PUSH_SEQ(ret, prefix);
8967 PUSH_SEQ(ret, body);
8970 if (popped) PUSH_INSN(ret, location, pop);
8977 pm_compile_constant_path_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8984 pm_compile_constant_path_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8991 pm_compile_constant_path_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
8998 pm_compile_constant_path_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9007 pm_compile_constant_read(iseq, name, &cast->
base.
location, location.
node_id, ret, scope_node);
9008 if (popped) PUSH_INSN(ret, location, pop);
9016 pm_compile_constant_and_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9023 pm_compile_constant_or_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9030 pm_compile_constant_operator_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9037 pm_compile_constant_write_node(iseq, cast, 0, &location, ret, popped, scope_node);
9047 ID method_name = pm_constant_id_lookup(scope_node, cast->
name);
9049 pm_scope_node_t next_scope_node;
9050 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9052 rb_iseq_t *method_iseq = NEW_ISEQ(&next_scope_node, rb_id2str(method_name), ISEQ_TYPE_METHOD, location.
line);
9053 pm_scope_node_destroy(&next_scope_node);
9056 PM_COMPILE_NOT_POPPED(cast->
receiver);
9057 PUSH_INSN2(ret, location, definesmethod,
ID2SYM(method_name), method_iseq);
9060 PUSH_INSN2(ret, location, definemethod,
ID2SYM(method_name), method_iseq);
9065 PUSH_INSN1(ret, location, putobject,
ID2SYM(method_name));
9074 pm_compile_defined_expr(iseq, cast->
value, &location, ret, popped, scope_node,
false);
9086 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9089 if (popped) PUSH_INSN(ret, location, pop);
9103 PUSH_INSN1(ret, location, putobject,
Qfalse);
9125 PUSH_SYNTHETIC_PUTNIL(ret, iseq);
9135 LABEL *final_label = NEW_LABEL(location.
line);
9136 LABEL *then_label = NEW_LABEL(location.
line);
9137 LABEL *else_label = NEW_LABEL(location.
line);
9139 pm_compile_flip_flop(cast, else_label, then_label, iseq, location.
line, ret, popped, scope_node);
9141 PUSH_LABEL(ret, then_label);
9142 PUSH_INSN1(ret, location, putobject,
Qtrue);
9143 PUSH_INSNL(ret, location, jump, final_label);
9144 PUSH_LABEL(ret, else_label);
9145 PUSH_INSN1(ret, location, putobject,
Qfalse);
9146 PUSH_LABEL(ret, final_label);
9155 PUSH_INSN1(ret, location, putobject, operand);
9164 LABEL *retry_label = NEW_LABEL(location.
line);
9165 LABEL *retry_end_l = NEW_LABEL(location.
line);
9168 PUSH_LABEL(ret, retry_label);
9173 pm_scope_node_t next_scope_node;
9174 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9176 const rb_iseq_t *child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, location.
line);
9177 pm_scope_node_destroy(&next_scope_node);
9179 const rb_iseq_t *prev_block = ISEQ_COMPILE_DATA(iseq)->current_block;
9180 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
9184 PUSH_SEND_WITH_BLOCK(ret, location, idEach,
INT2FIX(0), child_iseq);
9185 pm_compile_retry_end_label(iseq, ret, retry_end_l);
9187 if (popped) PUSH_INSN(ret, location, pop);
9188 ISEQ_COMPILE_DATA(iseq)->current_block = prev_block;
9189 PUSH_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
9193 rb_bug(
"Cannot compile a ForwardingArgumentsNode directly\n");
9207 LABEL *end_label = NEW_LABEL(location.
line);
9210 PUSH_INSN1(ret, location, getglobal, name);
9211 if (!popped) PUSH_INSN(ret, location, dup);
9213 PUSH_INSNL(ret, location, branchunless, end_label);
9214 if (!popped) PUSH_INSN(ret, location, pop);
9216 PM_COMPILE_NOT_POPPED(cast->
value);
9217 if (!popped) PUSH_INSN(ret, location, dup);
9219 PUSH_INSN1(ret, location, setglobal, name);
9220 PUSH_LABEL(ret, end_label);
9230 PUSH_INSN1(ret, location, getglobal, name);
9231 PM_COMPILE_NOT_POPPED(cast->
value);
9234 int flags = VM_CALL_ARGS_SIMPLE;
9235 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9237 if (!popped) PUSH_INSN(ret, location, dup);
9238 PUSH_INSN1(ret, location, setglobal, name);
9246 LABEL *set_label = NEW_LABEL(location.
line);
9247 LABEL *end_label = NEW_LABEL(location.
line);
9249 PUSH_INSN(ret, location, putnil);
9252 PUSH_INSN3(ret, location, defined,
INT2FIX(DEFINED_GVAR), name,
Qtrue);
9253 PUSH_INSNL(ret, location, branchunless, set_label);
9255 PUSH_INSN1(ret, location, getglobal, name);
9256 if (!popped) PUSH_INSN(ret, location, dup);
9258 PUSH_INSNL(ret, location, branchif, end_label);
9259 if (!popped) PUSH_INSN(ret, location, pop);
9261 PUSH_LABEL(ret, set_label);
9262 PM_COMPILE_NOT_POPPED(cast->
value);
9263 if (!popped) PUSH_INSN(ret, location, dup);
9265 PUSH_INSN1(ret, location, setglobal, name);
9266 PUSH_LABEL(ret, end_label);
9276 PUSH_INSN1(ret, location, getglobal, name);
9277 if (popped) PUSH_INSN(ret, location, pop);
9285 PM_COMPILE_NOT_POPPED(cast->
value);
9286 if (!popped) PUSH_INSN(ret, location, dup);
9288 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9289 PUSH_INSN1(ret, location, setglobal,
ID2SYM(name));
9307 PUSH_INSN1(ret, location, newhash,
INT2FIX(0));
9310 VALUE value = pm_static_literal_value(iseq, node, scope_node);
9311 PUSH_INSN1(ret, location, duphash, value);
9332 for (
size_t index = 0; index < elements->
size; index++) {
9333 PM_COMPILE_POPPED(elements->
nodes[index]);
9337 pm_compile_hash_elements(iseq, node, elements, 0,
Qundef,
false, ret, scope_node);
9353 pm_compile_conditional(iseq, &location,
PM_IF_NODE, (
const pm_node_t *) cast, cast->statements, cast->subsequent, cast->predicate, ret, popped, scope_node);
9361 PUSH_INSN1(ret, location, putobject, operand);
9375 PM_COMPILE(cast->
value);
9381 rb_bug(
"Should not ever enter an in node directly");
9388 pm_compile_index_operator_write_node(iseq, cast, &location, ret, popped, scope_node);
9395 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9402 pm_compile_index_control_flow_write_node(iseq, node, cast->
receiver, cast->
arguments, cast->
block, cast->
value, &location, ret, popped, scope_node);
9409 LABEL *end_label = NEW_LABEL(location.
line);
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 if (!popped) PUSH_INSN(ret, location, dup);
9417 PUSH_INSNL(ret, location, branchunless, end_label);
9418 if (!popped) PUSH_INSN(ret, location, pop);
9420 PM_COMPILE_NOT_POPPED(cast->
value);
9421 if (!popped) PUSH_INSN(ret, location, dup);
9423 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9424 PUSH_LABEL(ret, end_label);
9433 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9436 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9437 PM_COMPILE_NOT_POPPED(cast->
value);
9440 int flags = VM_CALL_ARGS_SIMPLE;
9441 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(flags));
9443 if (!popped) PUSH_INSN(ret, location, dup);
9444 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9452 LABEL *end_label = NEW_LABEL(location.
line);
9454 ID name_id = pm_constant_id_lookup(scope_node, cast->
name);
9457 PUSH_INSN2(ret, location, getinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9458 if (!popped) PUSH_INSN(ret, location, dup);
9460 PUSH_INSNL(ret, location, branchif, end_label);
9461 if (!popped) PUSH_INSN(ret, location, pop);
9463 PM_COMPILE_NOT_POPPED(cast->
value);
9464 if (!popped) PUSH_INSN(ret, location, dup);
9466 PUSH_INSN2(ret, location, setinstancevariable, name, get_ivar_ic_value(iseq, name_id));
9467 PUSH_LABEL(ret, end_label);
9476 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9477 PUSH_INSN2(ret, location, getinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9485 PM_COMPILE_NOT_POPPED(cast->
value);
9486 if (!popped) PUSH_INSN(ret, location, dup);
9488 ID name = pm_constant_id_lookup(scope_node, cast->
name);
9489 PUSH_INSN2(ret, location, setinstancevariable,
ID2SYM(name), get_ivar_ic_value(iseq, name));
9498 PUSH_INSN1(ret, location, putobject, operand);
9507 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9508 PUSH_INSN1(ret, location, putobject, regexp);
9515 PUSH_INSN1(ret, location, getglobal,
rb_id2sym(idLASTLINE));
9516 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9517 if (popped) PUSH_INSN(ret, location, pop);
9525 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
9526 const rb_iseq_t *block_iseq = NULL;
9527 int ise_index = ISEQ_BODY(iseq)->ise_size++;
9529 pm_scope_node_t next_scope_node;
9530 pm_scope_node_init(node, &next_scope_node, scope_node);
9532 block_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_PLAIN, location.
line);
9533 pm_scope_node_destroy(&next_scope_node);
9535 ISEQ_COMPILE_DATA(iseq)->current_block = block_iseq;
9536 PUSH_INSN2(ret, location, once, block_iseq,
INT2FIX(ise_index));
9537 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
9539 if (popped) PUSH_INSN(ret, location, pop);
9545 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9546 PUSH_INSN1(ret, location, putobject, regexp);
9551 if (popped) PUSH_INSN(ret, location, pop);
9561 VALUE string = pm_static_literal_value(iseq, node, scope_node);
9564 PUSH_INSN1(ret, location, putobject,
string);
9567 PUSH_INSN1(ret, location, putstring,
string);
9570 PUSH_INSN1(ret, location, putchilledstring,
string);
9576 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL);
9577 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9578 if (popped) PUSH_INSN(ret, location, pop);
9587 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret, popped, scope_node, NULL, NULL);
9590 PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9594 PUSH_INSN(ret, location, intern);
9597 PUSH_INSN(ret, location, pop);
9607 PUSH_INSN(ret, location, putself);
9609 int length = pm_interpolated_node_compile(iseq, &cast->
parts, &location, ret,
false, scope_node, NULL, NULL);
9610 if (length > 1) PUSH_INSN1(ret, location, concatstrings,
INT2FIX(length));
9612 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
9613 if (popped) PUSH_INSN(ret, location, pop);
9621 PUSH_GETLOCAL(ret, location, scope_node->local_table_for_iseq_size, 0);
9634 PM_COMPILE(element);
9637 if (!popped) PUSH_INSN1(ret, location, newhash,
INT2FIX(elements->
size * 2));
9645 pm_scope_node_t next_scope_node;
9646 pm_scope_node_init(node, &next_scope_node, scope_node);
9648 int opening_lineno = pm_location_line_number(parser, &cast->
opening_loc);
9649 const rb_iseq_t *block = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, opening_lineno);
9650 pm_scope_node_destroy(&next_scope_node);
9653 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
9654 PUSH_CALL_WITH_BLOCK(ret, location, idLambda, argc, block);
9657 if (popped) PUSH_INSN(ret, location, pop);
9664 LABEL *end_label = NEW_LABEL(location.
line);
9666 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9667 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9668 if (!popped) PUSH_INSN(ret, location, dup);
9670 PUSH_INSNL(ret, location, branchunless, end_label);
9671 if (!popped) PUSH_INSN(ret, location, pop);
9673 PM_COMPILE_NOT_POPPED(cast->
value);
9674 if (!popped) PUSH_INSN(ret, location, dup);
9676 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9677 PUSH_LABEL(ret, end_label);
9686 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9687 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9689 PM_COMPILE_NOT_POPPED(cast->
value);
9692 PUSH_SEND_WITH_FLAG(ret, location, method_id,
INT2NUM(1),
INT2FIX(VM_CALL_ARGS_SIMPLE));
9694 if (!popped) PUSH_INSN(ret, location, dup);
9695 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9704 LABEL *set_label = NEW_LABEL(location.
line);
9705 LABEL *end_label = NEW_LABEL(location.
line);
9707 PUSH_INSN1(ret, location, putobject,
Qtrue);
9708 PUSH_INSNL(ret, location, branchunless, set_label);
9710 pm_local_index_t local_index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9711 PUSH_GETLOCAL(ret, location, local_index.index, local_index.level);
9712 if (!popped) PUSH_INSN(ret, location, dup);
9714 PUSH_INSNL(ret, location, branchif, end_label);
9715 if (!popped) PUSH_INSN(ret, location, pop);
9717 PUSH_LABEL(ret, set_label);
9718 PM_COMPILE_NOT_POPPED(cast->
value);
9719 if (!popped) PUSH_INSN(ret, location, dup);
9721 PUSH_SETLOCAL(ret, location, local_index.index, local_index.level);
9722 PUSH_LABEL(ret, end_label);
9731 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9732 PUSH_GETLOCAL(ret, location, index.index, index.level);
9741 PM_COMPILE_NOT_POPPED(cast->
value);
9742 if (!popped) PUSH_INSN(ret, location, dup);
9744 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, cast->
depth);
9745 PUSH_SETLOCAL(ret, location, index.index, index.level);
9751 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
9753 PUSH_INSN1(ret, location, putobject, regexp);
9755 PUSH_SEND(ret, location, idEqTilde,
INT2NUM(1));
9756 if (popped) PUSH_INSN(ret, location, pop);
9767 PUSH_INSN(ret, location, putnil);
9770 PM_COMPILE_NOT_POPPED(cast->
value);
9771 PUSH_INSN(ret, location, dup);
9775 LABEL *matched_label = NEW_LABEL(location.
line);
9776 LABEL *unmatched_label = NEW_LABEL(location.
line);
9777 LABEL *done_label = NEW_LABEL(location.
line);
9778 pm_compile_pattern(iseq, scope_node, cast->
pattern, ret, matched_label, unmatched_label,
false,
false,
true, 2);
9782 PUSH_LABEL(ret, unmatched_label);
9783 PUSH_INSN(ret, location, pop);
9784 PUSH_INSN(ret, location, pop);
9786 if (!popped) PUSH_INSN1(ret, location, putobject,
Qfalse);
9787 PUSH_INSNL(ret, location, jump, done_label);
9788 PUSH_INSN(ret, location, putnil);
9792 PUSH_LABEL(ret, matched_label);
9793 PUSH_INSN1(ret, location, adjuststack,
INT2FIX(2));
9794 if (!popped) PUSH_INSN1(ret, location, putobject,
Qtrue);
9795 PUSH_INSNL(ret, location, jump, done_label);
9797 PUSH_LABEL(ret, done_label);
9823 pm_compile_match_write_node(iseq, (
const pm_match_write_node_t *) node, &location, ret, popped, scope_node);
9826 rb_bug(
"A pm_missing_node_t should not exist in prism's AST.");
9833 ID module_id = pm_constant_id_lookup(scope_node, cast->
name);
9834 VALUE module_name =
rb_str_freeze(rb_sprintf(
"<module:%"PRIsVALUE
">", rb_id2str(module_id)));
9836 pm_scope_node_t next_scope_node;
9837 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
9839 const rb_iseq_t *module_iseq = NEW_CHILD_ISEQ(&next_scope_node, module_name, ISEQ_TYPE_CLASS, location.
line);
9840 pm_scope_node_destroy(&next_scope_node);
9842 const int flags = VM_DEFINECLASS_TYPE_MODULE | pm_compile_class_path(iseq, cast->
constant_path, &location, ret,
false, scope_node);
9843 PUSH_INSN(ret, location, putnil);
9844 PUSH_INSN3(ret, location, defineclass,
ID2SYM(module_id), module_iseq,
INT2FIX(flags));
9847 if (popped) PUSH_INSN(ret, location, pop);
9854 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, 0);
9856 PUSH_SETLOCAL(ret, location, index.index, index.level);
9870 DECL_ANCHOR(writes);
9871 DECL_ANCHOR(cleanup);
9874 state.position = popped ? 0 : 1;
9875 pm_compile_multi_target_node(iseq, node, ret, writes, cleanup, scope_node, &state);
9877 PM_COMPILE_NOT_POPPED(cast->
value);
9878 if (!popped) PUSH_INSN(ret, location, dup);
9880 PUSH_SEQ(ret, writes);
9881 if (!popped && state.stack_size >= 1) {
9884 PUSH_INSN1(ret, location, setn,
INT2FIX(state.stack_size));
9889 pm_multi_target_state_update(&state);
9891 PUSH_SEQ(ret, cleanup);
9900 pm_compile_next_node(iseq, (
const pm_next_node_t *) node, &location, ret, popped, scope_node);
9906 PUSH_INSN(ret, location, putnil);
9914 ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg = TRUE;
9924 VALUE ref = pm_compile_numbered_reference_ref(cast);
9925 PUSH_INSN2(ret, location, getspecial,
INT2FIX(1), ref);
9928 PUSH_INSN(ret, location, putnil);
9939 LABEL *end_label = NEW_LABEL(location.
line);
9940 PM_COMPILE_NOT_POPPED(cast->
left);
9942 if (!popped) PUSH_INSN(ret, location, dup);
9943 PUSH_INSNL(ret, location, branchif, end_label);
9945 if (!popped) PUSH_INSN(ret, location, pop);
9946 PM_COMPILE(cast->
right);
9947 PUSH_LABEL(ret, end_label);
9955 PM_COMPILE_NOT_POPPED(cast->
value);
9957 pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, cast->
name, 0);
9958 PUSH_SETLOCAL(ret, location, index.index, index.level);
9970 if (cast->
body != NULL) {
9971 PM_COMPILE(cast->
body);
9974 PUSH_INSN(ret, location, putnil);
9991 DECL_ANCHOR(inner_pre);
9994 DECL_ANCHOR(inner_body);
9999 for (
size_t index = 0; index < body->
size; index++) {
10000 pm_compile_node(iseq, body->
nodes[index], inner_body,
true, scope_node);
10005 PUSH_INSN(inner_body, location, putnil);
10011 PUSH_SEQ(outer_pre, inner_pre);
10012 PUSH_SEQ(outer_pre, inner_body);
10020 const rb_iseq_t *child_iseq;
10021 const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
10023 pm_scope_node_t next_scope_node;
10024 pm_scope_node_init(node, &next_scope_node, scope_node);
10025 child_iseq = NEW_CHILD_ISEQ(&next_scope_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, lineno);
10026 pm_scope_node_destroy(&next_scope_node);
10028 ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq;
10030 int is_index = ISEQ_BODY(iseq)->ise_size++;
10031 PUSH_INSN2(ret, location, once, child_iseq,
INT2FIX(is_index));
10033 if (popped) PUSH_INSN(ret, location, pop);
10035 ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
10045 if (pm_optimizable_range_item_p(cast->
left) && pm_optimizable_range_item_p(cast->
right)) {
10056 PUSH_INSN1(ret, location, putobject, val);
10060 if (cast->
left != NULL) {
10061 PM_COMPILE(cast->
left);
10063 else if (!popped) {
10064 PUSH_INSN(ret, location, putnil);
10067 if (cast->
right != NULL) {
10068 PM_COMPILE(cast->
right);
10070 else if (!popped) {
10071 PUSH_INSN(ret, location, putnil);
10075 PUSH_INSN1(ret, location, newrange,
INT2FIX(exclude_end ? 1 : 0));
10084 PUSH_INSN1(ret, location, putobject, parse_rational((
const pm_rational_node_t *) node));
10091 pm_compile_redo_node(iseq, &location, ret, popped, scope_node);
10097 VALUE regexp = pm_static_literal_value(iseq, node, scope_node);
10098 PUSH_INSN1(ret, location, putobject, regexp);
10105 pm_compile_rescue_node(iseq, (
const pm_rescue_node_t *) node, &location, ret, popped, scope_node);
10112 pm_scope_node_t rescue_scope_node;
10113 pm_scope_node_init((
const pm_node_t *) cast, &rescue_scope_node, scope_node);
10115 rb_iseq_t *rescue_iseq = NEW_CHILD_ISEQ(
10116 &rescue_scope_node,
10122 pm_scope_node_destroy(&rescue_scope_node);
10124 LABEL *lstart = NEW_LABEL(location.
line);
10125 LABEL *lend = NEW_LABEL(location.
line);
10126 LABEL *lcont = NEW_LABEL(location.
line);
10128 lstart->rescued = LABEL_RESCUE_BEG;
10129 lend->rescued = LABEL_RESCUE_END;
10131 PUSH_LABEL(ret, lstart);
10133 PUSH_LABEL(ret, lend);
10135 PUSH_INSN(ret, location, nop);
10136 PUSH_LABEL(ret, lcont);
10137 if (popped) PUSH_INSN(ret, location, pop);
10139 PUSH_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue_iseq, lcont);
10140 PUSH_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart);
10149 pm_compile_return_node(iseq, (
const pm_return_node_t *) node, &location, ret, popped, scope_node);
10154 if (ISEQ_BODY(iseq)->
type == ISEQ_TYPE_RESCUE) {
10155 PUSH_INSN(ret, location, putnil);
10156 PUSH_INSN1(ret, location,
throw,
INT2FIX(TAG_RETRY));
10157 if (popped) PUSH_INSN(ret, location, pop);
10160 COMPILE_ERROR(iseq, location.
line,
"Invalid retry");
10166 pm_compile_scope_node(iseq, (pm_scope_node_t *) node, &location, ret, popped);
10172 PUSH_INSN(ret, location, putself);
10208 rb_bug(
"Unexpected node type for shareable constant write: %s", pm_node_type_to_str(
PM_NODE_TYPE(cast->
write)));
10219 pm_scope_node_t next_scope_node;
10220 pm_scope_node_init((
const pm_node_t *) cast, &next_scope_node, scope_node);
10221 const rb_iseq_t *child_iseq = NEW_ISEQ(&next_scope_node, rb_fstring_lit(
"singleton class"), ISEQ_TYPE_CLASS, location.
line);
10222 pm_scope_node_destroy(&next_scope_node);
10225 PUSH_INSN(ret, location, putnil);
10228 CONST_ID(singletonclass,
"singletonclass");
10229 PUSH_INSN3(ret, location, defineclass,
ID2SYM(singletonclass), child_iseq,
INT2FIX(VM_DEFINECLASS_TYPE_SINGLETON_CLASS));
10231 if (popped) PUSH_INSN(ret, location, pop);
10240 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10241 PUSH_INSN1(ret, location, putobject, value);
10250 VALUE string = pm_source_file_value(cast, scope_node);
10253 PUSH_INSN1(ret, location, putobject,
string);
10256 PUSH_INSN1(ret, location, putstring,
string);
10259 PUSH_INSN1(ret, location, putchilledstring,
string);
10268 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10269 PUSH_INSN1(ret, location, putobject, value);
10282 PUSH_INSN1(ret, location, splatarray,
Qtrue);
10291 if (body->
size > 0) {
10292 for (
size_t index = 0; index < body->
size - 1; index++) {
10293 PM_COMPILE_POPPED(body->
nodes[index]);
10295 PM_COMPILE(body->
nodes[body->
size - 1]);
10298 PUSH_INSN(ret, location, putnil);
10307 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10310 PUSH_INSN1(ret, location, putobject, value);
10313 PUSH_INSN1(ret, location, putstring, value);
10316 PUSH_INSN1(ret, location, putchilledstring, value);
10325 pm_compile_super_node(iseq, (
const pm_super_node_t *) node, &location, ret, popped, scope_node);
10331 VALUE value = pm_static_literal_value(iseq, node, scope_node);
10332 PUSH_INSN1(ret, location, putobject, value);
10340 PUSH_INSN1(ret, location, putobject,
Qtrue);
10350 for (
size_t index = 0; index < names->
size; index++) {
10351 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
10352 PUSH_INSN1(ret, location, putspecialobject,
INT2FIX(VM_SPECIAL_OBJECT_CBASE));
10354 PM_COMPILE_NOT_POPPED(names->
nodes[index]);
10355 PUSH_SEND(ret, location, id_core_undef_method,
INT2NUM(2));
10357 if (index < names->size - 1) {
10358 PUSH_INSN(ret, location, pop);
10362 if (popped) PUSH_INSN(ret, location, pop);
10377 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);
10387 pm_compile_loop(iseq, &location, cast->
base.
flags,
PM_UNTIL_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10397 pm_compile_loop(iseq, &location, cast->
base.
flags,
PM_WHILE_NODE, (
const pm_node_t *) cast, cast->statements, cast->predicate, ret, popped, scope_node);
10404 VALUE value = parse_static_literal_string(iseq, scope_node, node, &cast->
unescaped);
10406 PUSH_INSN(ret, location, putself);
10407 PUSH_INSN1(ret, location, putobject, value);
10408 PUSH_SEND_WITH_FLAG(ret, location, idBackquote,
INT2NUM(1),
INT2FIX(VM_CALL_FCALL | VM_CALL_ARGS_SIMPLE));
10409 if (popped) PUSH_INSN(ret, location, pop);
10419 pm_compile_yield_node(iseq, (
const pm_yield_node_t *) node, &location, ret, popped, scope_node);
10427#undef PM_CONTAINER_P
10431pm_iseq_pre_execution_p(rb_iseq_t *iseq)
10433 switch (ISEQ_BODY(iseq)->
type) {
10434 case ISEQ_TYPE_TOP:
10435 case ISEQ_TYPE_EVAL:
10436 case ISEQ_TYPE_MAIN:
10451pm_iseq_compile_node(rb_iseq_t *iseq, pm_scope_node_t *node)
10455 if (pm_iseq_pre_execution_p(iseq)) {
10467 pm_compile_node(iseq, (
const pm_node_t *) node, body,
false, node);
10471 PUSH_SEQ(ret, pre);
10472 PUSH_SEQ(ret, body);
10477 pm_compile_node(iseq, (
const pm_node_t *) node, ret,
false, node);
10480 CHECK(iseq_setup_insn(iseq, ret));
10481 return iseq_setup(iseq, ret);
10491 if (result->
node.ast_node != NULL) {
10492 pm_node_destroy(&result->
parser, result->
node.ast_node);
10497 pm_scope_node_destroy(&result->
node);
10500 pm_parser_free(&result->
parser);
10501 pm_string_free(&result->
input);
10502 pm_options_free(&result->
options);
10538#define PM_COLOR_BOLD "\033[1m"
10539#define PM_COLOR_GRAY "\033[2m"
10540#define PM_COLOR_RED "\033[1;31m"
10541#define PM_COLOR_RESET "\033[m"
10542#define PM_ERROR_TRUNCATE 30
10547 if (errors == NULL)
return NULL;
10551 pm_line_column_t start = pm_newline_list_line_column(newline_list, error->location.
start, start_line);
10552 pm_line_column_t end = pm_newline_list_line_column(newline_list, error->location.end, start_line);
10560 (index < error_list->size) &&
10561 (errors[index].error != NULL) &&
10563 (errors[index].line < start.
line) ||
10570 if (index + 1 < error_list->
size) {
10571 memmove(&errors[index + 1], &errors[index],
sizeof(
pm_parse_error_t) * (error_list->
size - index - 1));
10575 uint32_t column_end;
10577 column_end = end.
column;
10579 column_end = (uint32_t) (newline_list->
offsets[start.
line - start_line + 1] - newline_list->
offsets[start.
line - start_line] - 1);
10583 if (start.
column == column_end) column_end++;
10587 .line = start.
line,
10588 .column_start = start.
column,
10589 .column_end = column_end
10597#define pm_buffer_append_literal(buffer, str) pm_buffer_append_string(buffer, str, rb_strlen_lit(str))
10600pm_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) {
10601 int32_t line_delta = line - parser->
start_line;
10602 assert(line_delta >= 0);
10604 size_t index = (size_t) line_delta;
10605 assert(index < newline_list->size);
10607 const uint8_t *start = &parser->
start[newline_list->
offsets[index]];
10608 const uint8_t *end;
10610 if (index >= newline_list->
size - 1) {
10613 end = &parser->
start[newline_list->
offsets[index + 1]];
10616 pm_buffer_append_format(buffer, number_prefix, line);
10619 bool truncate_end =
false;
10620 if ((column_end != 0) && ((end - (start + column_end)) >= PM_ERROR_TRUNCATE)) {
10621 end = start + column_end + PM_ERROR_TRUNCATE;
10622 truncate_end =
true;
10626 if (column_start >= PM_ERROR_TRUNCATE) {
10627 pm_buffer_append_string(buffer,
"... ", 4);
10628 start += column_start;
10631 pm_buffer_append_string(buffer, (
const char *) start, (
size_t) (end - start));
10633 if (truncate_end) {
10634 pm_buffer_append_string(buffer,
" ...\n", 5);
10635 }
else if (end == parser->
end && end[-1] !=
'\n') {
10636 pm_buffer_append_string(buffer,
"\n", 1);
10645 assert(error_list->
size != 0);
10649 const int32_t start_line = parser->
start_line;
10652 pm_parse_error_t *errors = pm_parse_errors_format_sort(parser, error_list, newline_list);
10653 if (errors == NULL)
return;
10659 int32_t first_line_number = errors[0].
line;
10660 int32_t last_line_number = errors[error_list->
size - 1].
line;
10665 if (first_line_number < 0) first_line_number = (-first_line_number) * 10;
10666 if (last_line_number < 0) last_line_number = (-last_line_number) * 10;
10667 int32_t max_line_number = first_line_number > last_line_number ? first_line_number : last_line_number;
10669 if (max_line_number < 10) {
10670 if (highlight > 0) {
10672 .number_prefix = PM_COLOR_GRAY
"%1" PRIi32
" | " PM_COLOR_RESET,
10673 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10674 .divider = PM_COLOR_GRAY
" ~~~~~" PM_COLOR_RESET
"\n"
10678 .number_prefix =
"%1" PRIi32
" | ",
10679 .blank_prefix =
" | ",
10680 .divider =
" ~~~~~\n"
10683 }
else if (max_line_number < 100) {
10684 if (highlight > 0) {
10686 .number_prefix = PM_COLOR_GRAY
"%2" PRIi32
" | " PM_COLOR_RESET,
10687 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10688 .divider = PM_COLOR_GRAY
" ~~~~~~" PM_COLOR_RESET
"\n"
10692 .number_prefix =
"%2" PRIi32
" | ",
10693 .blank_prefix =
" | ",
10694 .divider =
" ~~~~~~\n"
10697 }
else if (max_line_number < 1000) {
10698 if (highlight > 0) {
10700 .number_prefix = PM_COLOR_GRAY
"%3" PRIi32
" | " PM_COLOR_RESET,
10701 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10702 .divider = PM_COLOR_GRAY
" ~~~~~~~" PM_COLOR_RESET
"\n"
10706 .number_prefix =
"%3" PRIi32
" | ",
10707 .blank_prefix =
" | ",
10708 .divider =
" ~~~~~~~\n"
10711 }
else if (max_line_number < 10000) {
10712 if (highlight > 0) {
10714 .number_prefix = PM_COLOR_GRAY
"%4" PRIi32
" | " PM_COLOR_RESET,
10715 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10716 .divider = PM_COLOR_GRAY
" ~~~~~~~~" PM_COLOR_RESET
"\n"
10720 .number_prefix =
"%4" PRIi32
" | ",
10721 .blank_prefix =
" | ",
10722 .divider =
" ~~~~~~~~\n"
10726 if (highlight > 0) {
10728 .number_prefix = PM_COLOR_GRAY
"%5" PRIi32
" | " PM_COLOR_RESET,
10729 .blank_prefix = PM_COLOR_GRAY
" | " PM_COLOR_RESET,
10730 .divider = PM_COLOR_GRAY
" ~~~~~~~~" PM_COLOR_RESET
"\n"
10734 .number_prefix =
"%5" PRIi32
" | ",
10735 .blank_prefix =
" | ",
10736 .divider =
" ~~~~~~~~\n"
10750 uint32_t last_column_start = 0;
10753 for (
size_t index = 0; index < error_list->
size; index++) {
10758 if (error->
line - last_line > 1) {
10759 if (error->
line - last_line > 2) {
10760 if ((index != 0) && (error->
line - last_line > 3)) {
10764 pm_buffer_append_string(buffer,
" ", 2);
10765 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, error->
line - 2, 0, 0, buffer);
10768 pm_buffer_append_string(buffer,
" ", 2);
10769 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, error->
line - 1, 0, 0, buffer);
10774 if ((index == 0) || (error->
line != last_line)) {
10775 if (highlight > 1) {
10776 pm_buffer_append_literal(buffer, PM_COLOR_RED
"> " PM_COLOR_RESET);
10777 }
else if (highlight > 0) {
10778 pm_buffer_append_literal(buffer, PM_COLOR_BOLD
"> " PM_COLOR_RESET);
10780 pm_buffer_append_literal(buffer,
"> ");
10787 for (
size_t next_index = index + 1; next_index < error_list->
size; next_index++) {
10788 if (errors[next_index].line != error->
line)
break;
10789 if (errors[next_index].column_end > column_end) column_end = errors[next_index].
column_end;
10795 const uint8_t *start = &parser->
start[newline_list->
offsets[error->
line - start_line]];
10796 if (start == parser->
end) pm_buffer_append_byte(buffer,
'\n');
10807 pm_buffer_append_string(buffer,
" ", 2);
10811 if (last_column_start >= PM_ERROR_TRUNCATE) {
10812 pm_buffer_append_string(buffer,
" ", 4);
10813 column = last_column_start;
10816 while (column < error->column_start) {
10817 pm_buffer_append_byte(buffer,
' ');
10819 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10820 column += (char_width == 0 ? 1 : char_width);
10823 if (highlight > 1) pm_buffer_append_literal(buffer, PM_COLOR_RED);
10824 else if (highlight > 0) pm_buffer_append_literal(buffer, PM_COLOR_BOLD);
10825 pm_buffer_append_byte(buffer,
'^');
10827 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10828 column += (char_width == 0 ? 1 : char_width);
10830 while (column < error->column_end) {
10831 pm_buffer_append_byte(buffer,
'~');
10833 size_t char_width = encoding->
char_width(start + column, parser->
end - (start + column));
10834 column += (char_width == 0 ? 1 : char_width);
10837 if (highlight > 0) pm_buffer_append_literal(buffer, PM_COLOR_RESET);
10839 if (inline_messages) {
10840 pm_buffer_append_byte(buffer,
' ');
10841 assert(error->
error != NULL);
10844 pm_buffer_append_string(buffer, message, strlen(message));
10847 pm_buffer_append_byte(buffer,
'\n');
10851 last_line = error->
line;
10854 if (index == error_list->
size - 1) {
10855 next_line = (((int32_t) newline_list->
size) + parser->
start_line);
10864 next_line = errors[index + 1].
line;
10867 if (next_line - last_line > 1) {
10868 pm_buffer_append_string(buffer,
" ", 2);
10869 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, ++last_line, 0, 0, buffer);
10872 if (next_line - last_line > 1) {
10873 pm_buffer_append_string(buffer,
" ", 2);
10874 pm_parse_errors_format_line(parser, newline_list, error_format.
number_prefix, ++last_line, 0, 0, buffer);
10882#undef PM_ERROR_TRUNCATE
10883#undef PM_COLOR_GRAY
10885#undef PM_COLOR_RESET
10896 const size_t start_line = pm_newline_list_line_column(&parser->
newline_list, location->
start, 1).line;
10897 const size_t end_line = pm_newline_list_line_column(&parser->
newline_list, location->
end, 1).line;
10903 while (start < end) {
10904 if ((width = pm_encoding_utf_8_char_width(start, end - start)) == 0)
return false;
10920 bool valid_utf8 =
true;
10925 int highlight = rb_stderr_tty_p();
10927 const char *no_color = getenv(
"NO_COLOR");
10928 highlight = (no_color == NULL || no_color[0] ==
'\0') ? 2 : 1;
10932 switch (error->level) {
10939 if (valid_utf8 && !pm_parse_process_error_utf8_p(parser, &error->location)) {
10940 valid_utf8 =
false;
10947 int32_t line_number = (int32_t) pm_location_line_number(parser, &error->location);
10949 pm_buffer_append_format(
10951 "%.*s:%" PRIi32
": %s",
10952 (
int) pm_string_length(filepath),
10953 pm_string_source(filepath),
10958 if (pm_parse_process_error_utf8_p(parser, &error->location)) {
10959 pm_buffer_append_byte(&buffer,
'\n');
10962 pm_list_t error_list = { .size = 1, .head = list_node, .tail = list_node };
10964 pm_parse_errors_format(parser, &error_list, &buffer, highlight,
false);
10967 VALUE value =
rb_exc_new(rb_eArgError, pm_buffer_value(&buffer), pm_buffer_length(&buffer));
10968 pm_buffer_free(&buffer);
10984 pm_buffer_append_format(
10986 "%.*s:%" PRIi32
": syntax error%s found\n",
10987 (
int) pm_string_length(filepath),
10988 pm_string_source(filepath),
10989 (int32_t) pm_location_line_number(parser, &head->location),
10994 pm_parse_errors_format(parser, &parser->
error_list, &buffer, highlight,
true);
10998 if (error != head) pm_buffer_append_byte(&buffer,
'\n');
10999 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);
11003 VALUE message = rb_enc_str_new(pm_buffer_value(&buffer), pm_buffer_length(&buffer), result->
node.encoding);
11007 VALUE path = rb_enc_str_new((
const char *) pm_string_source(filepath), pm_string_length(filepath), filepath_encoding);
11010 pm_buffer_free(&buffer);
11027 pm_scope_node_t *scope_node = &result->
node;
11029 int coverage_enabled = scope_node->coverage_enabled;
11031 pm_scope_node_init(node, scope_node, NULL);
11034 scope_node->encoding = rb_enc_find(parser->
encoding->
name);
11035 if (!scope_node->encoding) rb_bug(
"Encoding not found %s!", parser->
encoding->
name);
11037 scope_node->coverage_enabled = coverage_enabled;
11041 if (script_lines != NULL) {
11046 size_t length = index == parser->
newline_list.
size - 1 ? ((size_t) (parser->
end - (parser->
start + offset))) : (parser->newline_list.offsets[index + 1] - offset);
11047 rb_ary_push(*script_lines, rb_enc_str_new((
const char *) parser->
start + offset, length, scope_node->encoding));
11055 const char *warning_filepath = (
const char *) pm_string_source(&parser->
filepath);
11058 int line = pm_location_line_number(parser, &warning->
location);
11061 rb_enc_compile_warning(scope_node->encoding, warning_filepath, line,
"%s", warning->
message);
11064 rb_enc_compile_warn(scope_node->encoding, warning_filepath, line,
"%s", warning->
message);
11070 VALUE error = pm_parse_process_error(result);
11079 scope_node->parser = parser;
11084 scope_node->constants[index] = rb_intern3((
const char *) constant->
start, constant->
length, scope_node->encoding);
11087 scope_node->index_lookup_table = st_init_numtable();
11089 for (
size_t index = 0; index < locals->
size; index++) {
11090 st_insert(scope_node->index_lookup_table, locals->
ids[index], index);
11104pm_options_frozen_string_literal_init(
pm_options_t *options)
11106 int frozen_string_literal = rb_iseq_opt_frozen_string_literal();
11108 switch (frozen_string_literal) {
11109 case ISEQ_FROZEN_STRING_LITERAL_UNSET:
11111 case ISEQ_FROZEN_STRING_LITERAL_DISABLED:
11112 pm_options_frozen_string_literal_set(options,
false);
11114 case ISEQ_FROZEN_STRING_LITERAL_ENABLED:
11115 pm_options_frozen_string_literal_set(options,
true);
11118 rb_bug(
"pm_options_frozen_string_literal_init: invalid frozen_string_literal=%d", frozen_string_literal);
11128pm_parse_file_script_lines(
const pm_scope_node_t *scope_node,
const pm_parser_t *parser)
11131 const char *start = (
const char *) parser->
start;
11132 const char *end = (
const char *) parser->
end;
11137 size_t last_offset = newline_list->
offsets[newline_list->
size - 1];
11138 bool last_push = start + last_offset != end;
11141 VALUE lines = rb_ary_new_capa(newline_list->
size - (last_push ? 0 : 1));
11143 for (
size_t index = 0; index < newline_list->
size - 1; index++) {
11144 size_t offset = newline_list->
offsets[index];
11145 size_t length = newline_list->
offsets[index + 1] - offset;
11147 rb_ary_push(lines, rb_enc_str_new(start + offset, length, scope_node->encoding));
11152 rb_ary_push(lines, rb_enc_str_new(start + last_offset, end - (start + last_offset), scope_node->encoding));
11162pm_read_file(
pm_string_t *
string,
const char *filepath)
11166 int length = MultiByteToWideChar(CP_UTF8, 0, filepath, -1, NULL, 0);
11169 WCHAR *wfilepath =
xmalloc(
sizeof(WCHAR) * ((
size_t) length));
11170 if ((wfilepath == NULL) || (MultiByteToWideChar(CP_UTF8, 0, filepath, -1, wfilepath, length) == 0)) {
11175 HANDLE file = CreateFileW(wfilepath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
11176 if (file == INVALID_HANDLE_VALUE) {
11179 if (GetLastError() == ERROR_ACCESS_DENIED) {
11180 DWORD attributes = GetFileAttributesW(wfilepath);
11181 if ((attributes != INVALID_FILE_ATTRIBUTES) && (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
11191 DWORD file_size = GetFileSize(file, NULL);
11192 if (file_size == INVALID_FILE_SIZE) {
11200 if (file_size == 0) {
11203 const uint8_t source[] =
"";
11204 *
string = (
pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
11209 HANDLE mapping = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL);
11210 if (mapping == NULL) {
11217 uint8_t *source = (uint8_t *) MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, 0);
11218 CloseHandle(mapping);
11222 if (source == NULL) {
11226 *
string = (
pm_string_t) { .type = PM_STRING_MAPPED, .source = source, .length = (size_t) file_size };
11228#elif defined(_POSIX_MAPPED_FILES)
11230 const int open_mode = O_RDONLY | O_NONBLOCK;
11231 int fd = open(filepath, open_mode);
11238 if (fstat(fd, &sb) == -1) {
11244 if (S_ISDIR(sb.st_mode)) {
11252 if (S_ISFIFO(sb.st_mode) || S_ISCHR(sb.st_mode)) {
11261 long len = RSTRING_LEN(contents);
11266 size_t length = (size_t)
len;
11267 uint8_t *source = malloc(length);
11268 memcpy(source, RSTRING_PTR(contents), length);
11269 *
string = (
pm_string_t) { .type = PM_STRING_OWNED, .source = source, .length = length };
11275 size_t size = (size_t) sb.st_size;
11276 uint8_t *source = NULL;
11280 const uint8_t source[] =
"";
11281 *
string = (
pm_string_t) { .type = PM_STRING_CONSTANT, .source = source, .length = 0 };
11285 source = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
11286 if (source == MAP_FAILED) {
11292 *
string = (
pm_string_t) { .type = PM_STRING_MAPPED, .source = source, .length = size };
11295 return pm_string_file_init(
string, filepath);
11309 pm_options_frozen_string_literal_init(&result->
options);
11318 err = rb_w32_map_errno(GetLastError());
11350 pm_options_filepath_set(&result->
options, RSTRING_PTR(filepath));
11353 pm_parser_init(&result->
parser, pm_string_source(&result->
input), pm_string_length(&result->
input), &result->
options);
11356 VALUE error = pm_parse_process(result, node, script_lines);
11361 ID id_script_lines = rb_intern(
"SCRIPT_LINES__");
11367 rb_hash_aset(constant_script_lines, filepath, pm_parse_file_script_lines(&result->
node, &result->
parser));
11381 VALUE error = pm_load_file(result, filepath,
false);
11382 if (
NIL_P(error)) {
11383 error = pm_parse_file(result, filepath, script_lines);
11398 rb_encoding *encoding = rb_enc_get(source);
11399 if (!rb_enc_asciicompat(encoding)) {
11403 pm_options_frozen_string_literal_init(&result->
options);
11404 pm_string_constant_init(&result->
input, RSTRING_PTR(source), RSTRING_LEN(source));
11405 pm_options_encoding_set(&result->
options, rb_enc_name(encoding));
11408 pm_options_filepath_set(&result->
options, RSTRING_PTR(filepath));
11411 pm_parser_init(&result->
parser, pm_string_source(&result->
input), pm_string_length(&result->
input), &result->
options);
11414 return pm_parse_process(result, node, script_lines);
11421pm_parse_stdin_fgets(
char *
string,
int size,
void *stream)
11430 const char *cstr = RSTRING_PTR(line);
11431 long length = RSTRING_LEN(line);
11433 memcpy(
string, cstr, length);
11434 string[length] =
'\0';
11440void rb_reset_argf_lineno(
long n);
11450 pm_options_frozen_string_literal_init(&result->
options);
11458 pm_string_owned_init(&result->
input, (uint8_t *) pm_buffer_value(&buffer), pm_buffer_length(&buffer));
11462 rb_reset_argf_lineno(0);
11464 return pm_parse_process(result, node, NULL);
11468#define NEW_ISEQ OLD_ISEQ
11470#undef NEW_CHILD_ISEQ
11471#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_errinfo(void)
This is the same as $! in Ruby.
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.
rb_encoding * rb_utf8_encoding(void)
Queries the encoding that represents UTF-8.
rb_encoding * rb_ascii8bit_encoding(void)
Queries the encoding that represents ASCII-8BIT a.k.a.
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
int rb_enc_str_coderange(VALUE str)
Scans the passed string to collect its code range.
VALUE rb_enc_interned_str(const char *ptr, long len, rb_encoding *enc)
Identical to rb_enc_str_new(), except it returns a "f"string.
VALUE rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
Identical to rb_enc_str_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
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.