summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2024-03-29 11:16:45 -0400
committerKevin Newton <kddnewton@gmail.com>2024-03-29 12:28:54 -0400
commitf57c7fef6b260ca7d04458efd2f9e9fd784c9d89 (patch)
treebbd652f7d99b1d7968f64e948e33e15dee530b9b
parent729a39685b68a53a9f91ca972e6c7c393aed1b52 (diff)
[PRISM] Have RubyVM::InstructionSequence.compile respect --parser=prism
-rw-r--r--.github/workflows/prism.yml2
-rw-r--r--iseq.c80
-rw-r--r--test/.excludes-prism/TestCall.rb3
-rw-r--r--test/.excludes-prism/TestClass.rb3
-rw-r--r--test/.excludes-prism/TestIRB/RubyLexTest.rb1
-rw-r--r--test/.excludes-prism/TestISeq.rb6
-rw-r--r--test/.excludes-prism/TestIseqLoad.rb5
-rw-r--r--test/.excludes-prism/TestParse.rb37
-rw-r--r--test/.excludes-prism/TestPatternMatching.rb4
-rw-r--r--test/.excludes-prism/TestRubyLiteral.rb4
-rw-r--r--test/.excludes-prism/TestRubyOptimization.rb1
-rw-r--r--test/.excludes-prism/TestRubyVM.rb1
-rw-r--r--test/.excludes-prism/TestSyntax.rb45
13 files changed, 151 insertions, 41 deletions
diff --git a/.github/workflows/prism.yml b/.github/workflows/prism.yml
index 8b295f7f81..7fc10e2ab1 100644
--- a/.github/workflows/prism.yml
+++ b/.github/workflows/prism.yml
@@ -92,7 +92,7 @@ jobs:
timeout-minutes: 40
env:
GNUMAKEFLAGS: ''
- RUBY_TESTOPTS: '-q --tty=no --excludes-dir="../src/test/.excludes-prism" --exclude="test_ast.rb" --exclude="error_highlight/test_error_highlight.rb" --exclude="prism/encoding_test.rb"'
+ RUBY_TESTOPTS: '-q --tty=no --excludes-dir="../src/test/.excludes-prism" --exclude="test_ast.rb" --exclude="error_highlight/test_error_highlight.rb" --exclude="prism/encoding_test.rb" --exclude="prism/locals_test.rb" --exclude="prism/newline_test.rb"'
RUN_OPTS: ${{ matrix.run_opts }}
- name: make test-prism-spec
diff --git a/iseq.c b/iseq.c
index 2d412dfcc9..fffdb79edc 100644
--- a/iseq.c
+++ b/iseq.c
@@ -1430,6 +1430,44 @@ rb_iseqw_new(const rb_iseq_t *iseq)
return iseqw_new(iseq);
}
+/**
+ * Accept the options given to InstructionSequence.compile and
+ * InstructionSequence.compile_prism and share the logic for creating the
+ * instruction sequence.
+ */
+static VALUE
+iseqw_s_compile_parser(int argc, VALUE *argv, VALUE self, bool prism)
+{
+ VALUE src, file = Qnil, path = Qnil, line = Qnil, opt = Qnil;
+ int i;
+
+ i = rb_scan_args(argc, argv, "1*:", &src, NULL, &opt);
+ if (i > 4+NIL_P(opt)) rb_error_arity(argc, 1, 5);
+ switch (i) {
+ case 5: opt = argv[--i];
+ case 4: line = argv[--i];
+ case 3: path = argv[--i];
+ case 2: file = argv[--i];
+ }
+
+ if (NIL_P(file)) file = rb_fstring_lit("<compiled>");
+ if (NIL_P(path)) path = file;
+ if (NIL_P(line)) line = INT2FIX(1);
+
+ Check_Type(path, T_STRING);
+ Check_Type(file, T_STRING);
+
+ rb_iseq_t *iseq;
+ if (prism) {
+ iseq = pm_iseq_compile_with_option(src, file, path, line, opt);
+ }
+ else {
+ iseq = rb_iseq_compile_with_option(src, file, path, line, opt);
+ }
+
+ return iseqw_new(iseq);
+}
+
/*
* call-seq:
* InstructionSequence.compile(source[, file[, path[, line[, options]]]]) -> iseq
@@ -1470,26 +1508,7 @@ rb_iseqw_new(const rb_iseq_t *iseq)
static VALUE
iseqw_s_compile(int argc, VALUE *argv, VALUE self)
{
- VALUE src, file = Qnil, path = Qnil, line = Qnil, opt = Qnil;
- int i;
-
- i = rb_scan_args(argc, argv, "1*:", &src, NULL, &opt);
- if (i > 4+NIL_P(opt)) rb_error_arity(argc, 1, 5);
- switch (i) {
- case 5: opt = argv[--i];
- case 4: line = argv[--i];
- case 3: path = argv[--i];
- case 2: file = argv[--i];
- }
-
- if (NIL_P(file)) file = rb_fstring_lit("<compiled>");
- if (NIL_P(path)) path = file;
- if (NIL_P(line)) line = INT2FIX(1);
-
- Check_Type(path, T_STRING);
- Check_Type(file, T_STRING);
-
- return iseqw_new(rb_iseq_compile_with_option(src, file, path, line, opt));
+ return iseqw_s_compile_parser(argc, argv, self, *rb_ruby_prism_ptr());
}
/*
@@ -1531,26 +1550,7 @@ iseqw_s_compile(int argc, VALUE *argv, VALUE self)
static VALUE
iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self)
{
- VALUE src, file = Qnil, path = Qnil, line = Qnil, opt = Qnil;
- int i;
-
- i = rb_scan_args(argc, argv, "1*:", &src, NULL, &opt);
- if (i > 4+NIL_P(opt)) rb_error_arity(argc, 1, 5);
- switch (i) {
- case 5: opt = argv[--i];
- case 4: line = argv[--i];
- case 3: path = argv[--i];
- case 2: file = argv[--i];
- }
-
- if (NIL_P(file)) file = rb_fstring_lit("<compiled>");
- if (NIL_P(path)) path = file;
- if (NIL_P(line)) line = INT2FIX(1);
-
- Check_Type(path, T_STRING);
- Check_Type(file, T_STRING);
-
- return iseqw_new(pm_iseq_compile_with_option(src, file, path, line, opt));
+ return iseqw_s_compile_parser(argc, argv, self, true);
}
/*
diff --git a/test/.excludes-prism/TestCall.rb b/test/.excludes-prism/TestCall.rb
new file mode 100644
index 0000000000..08a949fc01
--- /dev/null
+++ b/test/.excludes-prism/TestCall.rb
@@ -0,0 +1,3 @@
+exclude(:test_call_op_asgn_keywords, "unknown")
+exclude(:test_kwsplat_block_order_op_asgn, "unknown")
+exclude(:test_call_op_asgn_keywords_mutable, "unknown")
diff --git a/test/.excludes-prism/TestClass.rb b/test/.excludes-prism/TestClass.rb
new file mode 100644
index 0000000000..14b768b9b7
--- /dev/null
+++ b/test/.excludes-prism/TestClass.rb
@@ -0,0 +1,3 @@
+exclude(:test_invalid_break_from_class_definition, "unknown")
+exclude(:test_invalid_next_from_class_definition, "unknown")
+exclude(:test_invalid_return_from_class_definition, "unknown")
diff --git a/test/.excludes-prism/TestIRB/RubyLexTest.rb b/test/.excludes-prism/TestIRB/RubyLexTest.rb
new file mode 100644
index 0000000000..2274ae62cf
--- /dev/null
+++ b/test/.excludes-prism/TestIRB/RubyLexTest.rb
@@ -0,0 +1 @@
+exclude(:test_code_block_open_with_should_continue, "symbol encoding")
diff --git a/test/.excludes-prism/TestISeq.rb b/test/.excludes-prism/TestISeq.rb
index de7052cb11..71d1583677 100644
--- a/test/.excludes-prism/TestISeq.rb
+++ b/test/.excludes-prism/TestISeq.rb
@@ -1 +1,7 @@
+exclude(:test_each_child, "unknown")
+exclude(:test_frozen_string_literal_compile_option, "unknown")
exclude(:test_syntax_error_message, "unknown")
+exclude(:test_to_binary_class_tracepoint, "unknown")
+exclude(:test_to_binary_end_tracepoint, "unknown")
+exclude(:test_trace_points, "unknown")
+exclude(:test_unreachable_syntax_error, "unknown")
diff --git a/test/.excludes-prism/TestIseqLoad.rb b/test/.excludes-prism/TestIseqLoad.rb
new file mode 100644
index 0000000000..036e03f7e4
--- /dev/null
+++ b/test/.excludes-prism/TestIseqLoad.rb
@@ -0,0 +1,5 @@
+exclude(:test_bug8543, "unknown")
+exclude(:test_case_when, "unknown")
+exclude(:test_hidden, "unknown")
+exclude(:test_kwarg, "unknown")
+exclude(:test_splatsplat, "unknown")
diff --git a/test/.excludes-prism/TestParse.rb b/test/.excludes-prism/TestParse.rb
index f2ef81cd11..126ead1800 100644
--- a/test/.excludes-prism/TestParse.rb
+++ b/test/.excludes-prism/TestParse.rb
@@ -1,7 +1,44 @@
+exclude(:test_alias_backref, "unknown")
+exclude(:test_bad_arg, "unknown")
+exclude(:test_block_dup, "unknown")
+exclude(:test_class_module, "unknown")
+exclude(:test_disallowed_class_variable, "unknown")
+exclude(:test_disallowed_gloal_variable, "unknown")
+exclude(:test_disallowed_instance_variable, "unknown")
+exclude(:test_duplicate_argument, "unknown")
+exclude(:test_dynamic_constant_assignment, "unknown")
+exclude(:test_else_without_rescue, "unknown")
+exclude(:test_embedded_rd_error, "unknown")
+exclude(:test_embedded_rd, "unknown")
+exclude(:test_error_def_in_argument, "unknown")
+exclude(:test_float, "unknown")
+exclude(:test_global_variable, "unknown")
+exclude(:test_here_document, "unknown")
+exclude(:test_heredoc_unterminated_interpolation, "unknown")
+exclude(:test_invalid_break_from_class_definition, "unknown")
+exclude(:test_invalid_char, "unknown")
+exclude(:test_invalid_class_variable, "unknown")
+exclude(:test_invalid_instance_variable, "unknown")
+exclude(:test_invalid_next_from_class_definition, "unknown")
+exclude(:test_location_of_invalid_token, "unknown")
+exclude(:test_no_blockarg, "unknown")
+exclude(:test_op_asgn1_with_block, "unknown")
+exclude(:test_parse_string, "unknown")
+exclude(:test_percent, "unknown")
+exclude(:test_question, "unknown")
+exclude(:test_shareable_constant_value_ignored, "unknown")
exclude(:test_shareable_constant_value_nested, "ractor support")
exclude(:test_shareable_constant_value_nonliteral, "ractor support")
exclude(:test_shareable_constant_value_simple, "ractor support")
exclude(:test_shareable_constant_value_unfrozen, "ractor support")
exclude(:test_shareable_constant_value_unshareable_literal, "ractor support")
+exclude(:test_string, "unknown")
+exclude(:test_truncated_source_line, "unknown")
+exclude(:test_unassignable, "unknown")
+exclude(:test_unexpected_eof, "unknown")
+exclude(:test_unexpected_token_after_numeric, "unknown")
+exclude(:test_unterminated_regexp_error, "unknown")
exclude(:test_unused_variable, "missing warning")
exclude(:test_void_expr_stmts_value, "missing warning")
+exclude(:test_void_value_in_rhs, "unknown")
+exclude(:test_words, "unknown")
diff --git a/test/.excludes-prism/TestPatternMatching.rb b/test/.excludes-prism/TestPatternMatching.rb
index cb64a6d818..40d9d6d99c 100644
--- a/test/.excludes-prism/TestPatternMatching.rb
+++ b/test/.excludes-prism/TestPatternMatching.rb
@@ -1 +1,5 @@
+exclude(:test_array_pattern, "duplicated variable error missing")
+exclude(:test_find_pattern, "duplicated variable error missing")
exclude(:test_hash_pattern, "useless literal warning missing")
+exclude(:test_invalid_syntax, "duplicated variable error missing")
+exclude(:test_var_pattern, "duplicated variable error missing")
diff --git a/test/.excludes-prism/TestRubyLiteral.rb b/test/.excludes-prism/TestRubyLiteral.rb
index a5ad6d6d9d..1174baa95f 100644
--- a/test/.excludes-prism/TestRubyLiteral.rb
+++ b/test/.excludes-prism/TestRubyLiteral.rb
@@ -1,2 +1,6 @@
+exclude(:test_debug_frozen_string_in_array_literal, "unknown")
+exclude(:test_debug_frozen_string, "unknown")
exclude(:test_dregexp, "unknown")
+exclude(:test_hash_value_omission, "unknown")
+exclude(:test_integer, "unknown")
exclude(:test_string, "https://github.com/ruby/prism/issues/2331")
diff --git a/test/.excludes-prism/TestRubyOptimization.rb b/test/.excludes-prism/TestRubyOptimization.rb
new file mode 100644
index 0000000000..df22ca4f71
--- /dev/null
+++ b/test/.excludes-prism/TestRubyOptimization.rb
@@ -0,0 +1 @@
+exclude(:test_peephole_string_literal_range, "unknown")
diff --git a/test/.excludes-prism/TestRubyVM.rb b/test/.excludes-prism/TestRubyVM.rb
new file mode 100644
index 0000000000..6d4c3ca6fe
--- /dev/null
+++ b/test/.excludes-prism/TestRubyVM.rb
@@ -0,0 +1 @@
+exclude(:test_keep_script_lines, "unknown")
diff --git a/test/.excludes-prism/TestSyntax.rb b/test/.excludes-prism/TestSyntax.rb
index 680974906b..8f0cfcf4f4 100644
--- a/test/.excludes-prism/TestSyntax.rb
+++ b/test/.excludes-prism/TestSyntax.rb
@@ -1,4 +1,49 @@
+exclude(:test__END___cr, "unknown")
+exclude(:test_anonymous_block_forwarding, "unknown")
+exclude(:test_anonymous_keyword_rest_forwarding, "unknown")
+exclude(:test_anonymous_rest_forwarding, "unknown")
+exclude(:test_argument_forwarding_with_anon_rest_kwrest_and_block, "unknown")
+exclude(:test_argument_forwarding_with_super, "unknown")
+exclude(:test_argument_forwarding, "unknown")
+exclude(:test_brace_after_literal_argument, "unknown")
exclude(:test_dedented_heredoc_concatenation, "unknown")
exclude(:test_dedented_heredoc_continued_line, "unknown")
+exclude(:test_dedented_heredoc_invalid_identifer, "unknown")
+exclude(:test_duplicated_arg, "unknown")
+exclude(:test_duplicated_kw_kwrest, "unknown")
+exclude(:test_duplicated_kw, "unknown")
+exclude(:test_duplicated_opt_kw, "unknown")
+exclude(:test_duplicated_opt_kwrest, "unknown")
+exclude(:test_duplicated_opt_post, "unknown")
+exclude(:test_duplicated_opt_rest, "unknown")
+exclude(:test_duplicated_opt, "unknown")
+exclude(:test_duplicated_rest_kw, "unknown")
+exclude(:test_duplicated_rest_kwrest, "unknown")
+exclude(:test_duplicated_rest_opt, "unknown")
+exclude(:test_duplicated_rest_post, "unknown")
+exclude(:test_duplicated_rest, "unknown")
exclude(:test_duplicated_when, "unknown")
+exclude(:test_error_message_encoding, "unknown")
+exclude(:test_heredoc_cr, "unknown")
+exclude(:test_heredoc_no_terminator, "unknown")
+exclude(:test_invalid_break, "unknown")
+exclude(:test_invalid_encoding_symbol, "unknown")
+exclude(:test_invalid_literal_message, "unknown")
+exclude(:test_invalid_next, "unknown")
exclude(:test_it, "https://github.com/ruby/prism/issues/2323")
+exclude(:test_keyword_invalid_name, "unknown")
+exclude(:test_keyword_self_reference, "unknown")
+exclude(:test_keywords_specified_and_not_accepted, "unknown")
+exclude(:test_methoddef_endless_command, "unknown")
+exclude(:test_numbered_parameter, "unknown")
+exclude(:test_optional_self_reference, "unknown")
+exclude(:test_parenthesised_statement_argument, "unknown")
+exclude(:test_range_at_eol, "unknown")
+exclude(:test_safe_call_in_massign_lhs, "unknown")
+exclude(:test_syntax_error_at_newline, "unknown")
+exclude(:test_unassignable, "unknown")
+exclude(:test_unexpected_fraction, "unknown")
+exclude(:test_unterminated_heredoc_cr, "unknown")
+exclude(:test_unterminated_heredoc, "unknown")
+exclude(:test_warn_balanced, "unknown")
+exclude(:test_warn_unreachable, "unknown")