Make default parser enum and define getter/setter
This commit is contained in:
parent
4e219d8f7d
commit
3e1021b144
Notes:
git
2024-10-02 11:43:59 +00:00
@ -19522,6 +19522,7 @@ version.$(OBJEXT): $(top_srcdir)/internal/cmdlineopt.h
|
|||||||
version.$(OBJEXT): $(top_srcdir)/internal/compilers.h
|
version.$(OBJEXT): $(top_srcdir)/internal/compilers.h
|
||||||
version.$(OBJEXT): $(top_srcdir)/internal/gc.h
|
version.$(OBJEXT): $(top_srcdir)/internal/gc.h
|
||||||
version.$(OBJEXT): $(top_srcdir)/internal/imemo.h
|
version.$(OBJEXT): $(top_srcdir)/internal/imemo.h
|
||||||
|
version.$(OBJEXT): $(top_srcdir)/internal/parse.h
|
||||||
version.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
|
version.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
|
||||||
version.$(OBJEXT): $(top_srcdir)/internal/serial.h
|
version.$(OBJEXT): $(top_srcdir)/internal/serial.h
|
||||||
version.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
|
version.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
|
||||||
|
@ -13,11 +13,15 @@
|
|||||||
#include "internal/static_assert.h"
|
#include "internal/static_assert.h"
|
||||||
|
|
||||||
// The default parser to use for Ruby code.
|
// The default parser to use for Ruby code.
|
||||||
// 0: parse.y
|
typedef enum {
|
||||||
// 1: Prism
|
RB_DEFAULT_PARSER_PARSE_Y,
|
||||||
#ifndef RB_DEFAULT_PARSER
|
RB_DEFAULT_PARSER_PRISM,
|
||||||
#define RB_DEFAULT_PARSER 1
|
} ruby_default_parser_enum;
|
||||||
#endif
|
|
||||||
|
ruby_default_parser_enum rb_ruby_default_parser(void);
|
||||||
|
void rb_ruby_default_parser_set(ruby_default_parser_enum parser);
|
||||||
|
|
||||||
|
#define rb_ruby_prism_p() (rb_ruby_default_parser() == RB_DEFAULT_PARSER_PRISM)
|
||||||
|
|
||||||
#ifdef UNIVERSAL_PARSER
|
#ifdef UNIVERSAL_PARSER
|
||||||
#define rb_encoding const void
|
#define rb_encoding const void
|
||||||
|
2
iseq.c
2
iseq.c
@ -1564,7 +1564,7 @@ iseqw_s_compile_parser(int argc, VALUE *argv, VALUE self, bool prism)
|
|||||||
static VALUE
|
static VALUE
|
||||||
iseqw_s_compile(int argc, VALUE *argv, VALUE self)
|
iseqw_s_compile(int argc, VALUE *argv, VALUE self)
|
||||||
{
|
{
|
||||||
return iseqw_s_compile_parser(argc, argv, self, *rb_ruby_prism_ptr());
|
return iseqw_s_compile_parser(argc, argv, self, rb_ruby_prism_p());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
2
load.c
2
load.c
@ -743,7 +743,7 @@ load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
|
|||||||
rb_thread_t *th = rb_ec_thread_ptr(ec);
|
rb_thread_t *th = rb_ec_thread_ptr(ec);
|
||||||
VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
|
VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
|
||||||
|
|
||||||
if (*rb_ruby_prism_ptr()) {
|
if (rb_ruby_prism_p()) {
|
||||||
pm_parse_result_t result = { 0 };
|
pm_parse_result_t result = { 0 };
|
||||||
result.options.line = 1;
|
result.options.line = 1;
|
||||||
result.node.coverage_enabled = 1;
|
result.node.coverage_enabled = 1;
|
||||||
|
@ -58,7 +58,7 @@ builtin_iseq_load(const char *feature_name, const struct rb_builtin_function *ta
|
|||||||
.debug_level = 0,
|
.debug_level = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (*rb_ruby_prism_ptr()) {
|
if (rb_ruby_prism_p()) {
|
||||||
pm_parse_result_t result = { 0 };
|
pm_parse_result_t result = { 0 };
|
||||||
pm_prelude_load(&result, name_str, code, start_line);
|
pm_prelude_load(&result, name_str, code, start_line);
|
||||||
|
|
||||||
|
@ -65,7 +65,6 @@ typedef struct pm_scope_node {
|
|||||||
|
|
||||||
void pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous);
|
void pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous);
|
||||||
void pm_scope_node_destroy(pm_scope_node_t *scope_node);
|
void pm_scope_node_destroy(pm_scope_node_t *scope_node);
|
||||||
bool *rb_ruby_prism_ptr(void);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/** The parser that will do the actual parsing. */
|
/** The parser that will do the actual parsing. */
|
||||||
|
6
ruby.c
6
ruby.c
@ -1430,10 +1430,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_default_parser_set(RB_DEFAULT_PARSER_PRISM);
|
||||||
}
|
}
|
||||||
else if (strcmp("parse.y", s) == 0) {
|
else if (strcmp("parse.y", s) == 0) {
|
||||||
*rb_ruby_prism_ptr() = false;
|
rb_ruby_default_parser_set(RB_DEFAULT_PARSER_PARSE_Y);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_raise(rb_eRuntimeError, "unknown parser %s", s);
|
rb_raise(rb_eRuntimeError, "unknown parser %s", s);
|
||||||
@ -2522,7 +2522,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
|
|||||||
rb_enc_associate(opt->e_script, eenc);
|
rb_enc_associate(opt->e_script, eenc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(*rb_ruby_prism_ptr())) {
|
if (!rb_ruby_prism_p()) {
|
||||||
ast_value = process_script(opt);
|
ast_value = process_script(opt);
|
||||||
if (!(result.ast = rb_ruby_ast_data_get(ast_value))) return Qfalse;
|
if (!(result.ast = rb_ruby_ast_data_get(ast_value))) return Qfalse;
|
||||||
}
|
}
|
||||||
|
20
version.c
20
version.c
@ -10,6 +10,7 @@
|
|||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
#include "internal/cmdlineopt.h"
|
#include "internal/cmdlineopt.h"
|
||||||
|
#include "internal/parse.h"
|
||||||
#include "ruby/ruby.h"
|
#include "ruby/ruby.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "vm_core.h"
|
#include "vm_core.h"
|
||||||
@ -141,7 +142,22 @@ Init_version(void)
|
|||||||
|
|
||||||
int ruby_mn_threads_enabled;
|
int ruby_mn_threads_enabled;
|
||||||
|
|
||||||
bool * rb_ruby_prism_ptr(void);
|
#ifndef RB_DEFAULT_PARSER
|
||||||
|
#define RB_DEFAULT_PARSER RB_DEFAULT_PARSER_PRISM
|
||||||
|
#endif
|
||||||
|
static ruby_default_parser_enum default_parser = RB_DEFAULT_PARSER;
|
||||||
|
|
||||||
|
ruby_default_parser_enum
|
||||||
|
rb_ruby_default_parser(void)
|
||||||
|
{
|
||||||
|
return default_parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_ruby_default_parser_set(ruby_default_parser_enum parser)
|
||||||
|
{
|
||||||
|
default_parser = parser;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
define_ruby_description(const char *const jit_opt)
|
define_ruby_description(const char *const jit_opt)
|
||||||
@ -158,7 +174,7 @@ define_ruby_description(const char *const jit_opt)
|
|||||||
# define append(s) (n += (int)strlcpy(desc + n, s, sizeof(desc) - n), assert(n < sizeof(desc)))
|
# define append(s) (n += (int)strlcpy(desc + n, s, sizeof(desc) - n), assert(n < sizeof(desc)))
|
||||||
if (*jit_opt) append(jit_opt);
|
if (*jit_opt) append(jit_opt);
|
||||||
if (ruby_mn_threads_enabled) append(" +MN");
|
if (ruby_mn_threads_enabled) append(" +MN");
|
||||||
if (*rb_ruby_prism_ptr()) append(" +PRISM");
|
if (rb_ruby_prism_p()) append(" +PRISM");
|
||||||
append(ruby_description + ruby_description_opt_point);
|
append(ruby_description + ruby_description_opt_point);
|
||||||
# undef append
|
# undef append
|
||||||
|
|
||||||
|
8
vm.c
8
vm.c
@ -4456,14 +4456,6 @@ rb_ruby_verbose_ptr(void)
|
|||||||
return &cr->verbose;
|
return &cr->verbose;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool prism = (RB_DEFAULT_PARSER == 1);
|
|
||||||
|
|
||||||
bool *
|
|
||||||
rb_ruby_prism_ptr(void)
|
|
||||||
{
|
|
||||||
return &prism;
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE *
|
VALUE *
|
||||||
rb_ruby_debug_ptr(void)
|
rb_ruby_debug_ptr(void)
|
||||||
{
|
{
|
||||||
|
@ -1787,7 +1787,7 @@ static const rb_iseq_t *
|
|||||||
eval_make_iseq(VALUE src, VALUE fname, int line,
|
eval_make_iseq(VALUE src, VALUE fname, int line,
|
||||||
const struct rb_block *base_block)
|
const struct rb_block *base_block)
|
||||||
{
|
{
|
||||||
if (*rb_ruby_prism_ptr()) {
|
if (rb_ruby_prism_p()) {
|
||||||
return pm_eval_make_iseq(src, fname, line, base_block);
|
return pm_eval_make_iseq(src, fname, line, base_block);
|
||||||
}
|
}
|
||||||
const VALUE parser = rb_parser_new();
|
const VALUE parser = rb_parser_new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user