12#include "internal/cmdlineopt.h"
13#include "internal/parse.h"
14#include "internal/gc.h"
26# if RUBY_PATCHLEVEL == -1
27# define RUBY_API_VERSION_NAME "master"
28# ifndef RUBY_BRANCH_NAME
29# define RUBY_BRANCH_NAME RUBY_API_VERSION_NAME
31# define RUBY_REVISION_STR " "RUBY_BRANCH_NAME" "RUBY_REVISION
33# define RUBY_API_VERSION_NAME RUBY_API_VERSION_STR
34# define RUBY_REVISION_STR " revision "RUBY_REVISION
37# define RUBY_REVISION "HEAD"
38# define RUBY_REVISION_STR ""
40#if !defined RUBY_RELEASE_DATETIME || RUBY_PATCHLEVEL != -1
41# undef RUBY_RELEASE_DATETIME
42# define RUBY_RELEASE_DATETIME RUBY_RELEASE_DATE
45#define PRINT(type) puts(ruby_##type)
46#define MKSTR(type) rb_obj_freeze(rb_usascii_str_new_static(ruby_##type, sizeof(ruby_##type)-1))
47#define MKINT(name) INT2FIX(ruby_##name)
49#define RUBY_API_VERSION_STR \
50 STRINGIZE(RUBY_API_VERSION_MAJOR) "." \
51 STRINGIZE(RUBY_API_VERSION_MINOR) "." \
59 STRINGIZE(RUBY_VERSION_MAJOR) "." \
60 STRINGIZE(RUBY_VERSION_MINOR) "." \
61 STRINGIZE(RUBY_VERSION_TEENY) ""
62#ifndef RUBY_FULL_REVISION
63# define RUBY_FULL_REVISION RUBY_REVISION
66#define YJIT_DESCRIPTION " +YJIT " STRINGIZE(YJIT_SUPPORT)
68#define YJIT_DESCRIPTION " +YJIT"
71#define ZJIT_DESCRIPTION " +ZJIT " STRINGIZE(ZJIT_SUPPORT)
73#define ZJIT_DESCRIPTION " +ZJIT"
76#define GC_DESCRIPTION " +GC"
78#define GC_DESCRIPTION ""
81const char ruby_revision[] = RUBY_FULL_REVISION;
85const char ruby_api_version_name[] = RUBY_API_VERSION_NAME;
87 "ruby " RUBY_VERSION RUBY_PATCHLEVEL_STR
" "
88 "(" RUBY_RELEASE_DATETIME RUBY_REVISION_STR
") "
89 "[" RUBY_PLATFORM
"]";
90static const int ruby_description_opt_point =
91 (int)(
sizeof(ruby_description) -
sizeof(
" [" RUBY_PLATFORM
"]"));
94 RUBY_BIRTH_YEAR_STR
"-" RUBY_RELEASE_YEAR_STR
" "
102define_ruby_const(
VALUE mod,
const char *name,
VALUE value,
bool toplevel)
108 rb_define_const(mod, name, value);
112#define rb_define_const(mod, name, value) \
113 define_ruby_const(mod, (mod == mRuby ? "RUBY_" name : name), value, (mod == mRuby))
129 VALUE version = MKSTR(version);
130 VALUE ruby_engine_name = MKSTR(engine);
136 rb_define_const(mRuby,
"VERSION", version);
140 rb_define_const(mRuby,
"RELEASE_DATE", MKSTR(release_date));
144 rb_define_const(mRuby,
"PLATFORM", MKSTR(platform));
149 rb_define_const(mRuby,
"PATCHLEVEL", MKINT(patchlevel));
153 rb_define_const(mRuby,
"REVISION", MKSTR(revision));
157 rb_define_const(mRuby,
"COPYRIGHT", MKSTR(copyright));
161 rb_define_const(mRuby,
"ENGINE", ruby_engine_name);
166 rb_define_const(mRuby,
"ENGINE_VERSION", version);
172#define YJIT_OPTS_ON opt->yjit
174#define YJIT_OPTS_ON 0
178#define ZJIT_OPTS_ON opt->zjit
180#define ZJIT_OPTS_ON 0
183int ruby_mn_threads_enabled;
185#ifndef RB_DEFAULT_PARSER
186#define RB_DEFAULT_PARSER RB_DEFAULT_PARSER_PRISM
188static ruby_default_parser_enum default_parser = RB_DEFAULT_PARSER;
190ruby_default_parser_enum
191rb_ruby_default_parser(
void)
193 return default_parser;
197rb_ruby_default_parser_set(ruby_default_parser_enum parser)
199 default_parser = parser;
203define_ruby_description(
const char *
const jit_opt)
205#define JIT_DESCRIPTION YJIT_DESCRIPTION ZJIT_DESCRIPTION
217 + RB_GC_MAX_NAME_LEN + 3
222 int n = ruby_description_opt_point;
223 memcpy(desc, ruby_description, n);
224# define append(s) (n += (int)strlcpy(desc + n, s, sizeof(desc) - n))
225 if (*jit_opt) append(jit_opt);
227 if (ruby_mn_threads_enabled) append(
" +MN");
228 if (rb_ruby_prism_p()) append(
" +PRISM");
230 append(GC_DESCRIPTION);
231 if (rb_gc_modular_gc_loaded_p()) {
233 append(rb_gc_active_gc_name());
237 append(ruby_description + ruby_description_opt_point);
242 rb_dynamic_description = desc;
247 rb_define_const(mRuby,
"DESCRIPTION", description);
248#undef JIT_DESCRIPTION
254 const char *
const jit_opt =
255 YJIT_OPTS_ON ? YJIT_DESCRIPTION :
256 ZJIT_OPTS_ON ? ZJIT_DESCRIPTION :
258 define_ruby_description(jit_opt);
262ruby_set_yjit_description(
void)
267 define_ruby_description(YJIT_DESCRIPTION);
273 puts(rb_dynamic_description);
275#ifdef RUBY_LAST_COMMIT_TITLE
276 fputs(
"last_commit=" RUBY_LAST_COMMIT_TITLE, stdout);
278#ifdef HAVE_MALLOC_CONF
279 if (malloc_conf) printf(
"malloc_conf=%s\n", malloc_conf);
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
VALUE rb_define_module(const char *name)
Defines a top-level module.
void ruby_set_script_name(VALUE name)
Identical to ruby_script(), except it takes the name as a Ruby String instance.
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
void ruby_show_copyright(void)
Prints the copyright notice of the CRuby interpreter to stdout.
void ruby_show_version(void)
Prints the version information of the CRuby interpreter to stdout.
void rb_provide(const char *feature)
Declares that the given feature is already provided by someone else.
#define rb_strlen_lit(str)
Length of a string literal.
VALUE rb_usascii_str_new_static(const char *ptr, long len)
Identical to rb_str_new_static(), except it generates a string of "US ASCII" encoding instead of "bin...
VALUE rb_path2class(const char *path)
Resolves a Q::W::E::R-style path string to the actual class it points.
VALUE rb_const_remove(VALUE space, ID name)
Identical to rb_mod_remove_const(), except it takes the name as ID instead of VALUE.
void rb_define_global_const(const char *name, VALUE val)
Identical to rb_define_const(), except it defines that of "global", i.e.
const int ruby_api_version[3]
API versions, in { major, minor, teeny } order.
const char ruby_engine[]
This is just "ruby" for us.
#define RUBY_API_VERSION_TEENY
Teeny version.
const char ruby_platform[]
Target platform identifier, in a C string.
const char ruby_version[]
Stringised version.
#define RUBY_API_VERSION_MAJOR
Major version.
#define RUBY_API_VERSION_MINOR
Minor version.
#define RUBY_AUTHOR
Author of this project.
const char ruby_copyright[]
Copyright notice.
const char ruby_release_date[]
Date of release, in a C string.
const int ruby_patchlevel
This is a monotonic increasing integer that describes specific "patch" level.
const char ruby_description[]
This is what ruby -v prints to the standard error.
uintptr_t VALUE
Type that represents a Ruby object.