Add RB_DEFAULT_PARSER preprocessor macro

This way there is one place to change for switching the default.
This also allows for building the same commit with different cppflags.
This commit is contained in:
Alan Wu 2024-08-27 19:15:37 -04:00 committed by GitHub
parent 1729f47e72
commit f2ac013009
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2024-08-27 23:15:57 +00:00
Merged: https://github.com/ruby/ruby/pull/11473

Merged-By: XrXr
3 changed files with 10 additions and 5 deletions

View File

@ -12,6 +12,13 @@
#include "rubyparser.h" #include "rubyparser.h"
#include "internal/static_assert.h" #include "internal/static_assert.h"
// The default parser to use for Ruby code.
// 0: parse.y
// 1: Prism
#ifndef RB_DEFAULT_PARSER
#define RB_DEFAULT_PARSER 0
#endif
#ifdef UNIVERSAL_PARSER #ifdef UNIVERSAL_PARSER
#define rb_encoding const void #define rb_encoding const void
#endif #endif

6
ruby.c
View File

@ -1428,10 +1428,10 @@ proc_long_options(ruby_cmdline_options_t *opt, const char *s, long argc, char **
} }
else if (is_option_with_arg("parser", Qfalse, Qtrue)) { else if (is_option_with_arg("parser", Qfalse, Qtrue)) {
if (strcmp("prism", s) == 0) { if (strcmp("prism", s) == 0) {
(*rb_ruby_prism_ptr()) = true; *rb_ruby_prism_ptr() = true;
} }
else if (strcmp("parse.y", s) == 0) { else if (strcmp("parse.y", s) == 0) {
// default behavior *rb_ruby_prism_ptr() = false;
} }
else { else {
rb_raise(rb_eRuntimeError, "unknown parser %s", s); rb_raise(rb_eRuntimeError, "unknown parser %s", s);
@ -3114,8 +3114,6 @@ ruby_process_options(int argc, char **argv)
VALUE iseq; VALUE iseq;
const char *script_name = (argc > 0 && argv[0]) ? argv[0] : ruby_engine; const char *script_name = (argc > 0 && argv[0]) ? argv[0] : ruby_engine;
(*rb_ruby_prism_ptr()) = false;
if (!origarg.argv || origarg.argc <= 0) { if (!origarg.argv || origarg.argc <= 0) {
origarg.argc = argc; origarg.argc = argc;
origarg.argv = argv; origarg.argv = argv;

2
vm.c
View File

@ -4456,7 +4456,7 @@ rb_ruby_verbose_ptr(void)
return &cr->verbose; return &cr->verbose;
} }
static bool prism; static bool prism = (RB_DEFAULT_PARSER == 1);
bool * bool *
rb_ruby_prism_ptr(void) rb_ruby_prism_ptr(void)