Ruby 4.1.0dev (2026-10-28 revision 130c9ec44bd35c7319cdc99c301419188510e3a9)
prism_init.c (130c9ec44bd35c7319cdc99c301419188510e3a9)
1#include "prism/extension.h"
2
3void ruby_init_ext(const char *name, void (*init)(void));
4void rb_autoload_str(VALUE mod, ID id, VALUE file);
5
6/*
7 * The prism parser is linked into the interpreter and exposed as the
8 * Ruby::Prism module. It is the very parser that parsed the running
9 * code, independent of any version of the prism gem that may be installed.
10 *
11 * `require "ruby/prism"` loads the Ruby part of the library
12 * (lib/ruby/prism.rb), which in turn requires "ruby/prism/prism", the
13 * statically linked extension registered here.
14 */
15void
16Init_Prism(void)
17{
18#if 0 /* for RDoc; Ruby::Prism is defined by lib/ruby/prism.rb via autoload */
19 VALUE rb_mRuby = rb_define_module("Ruby");
20 /*
21 * Document-module: Ruby::Prism
22 *
23 * \Ruby::Prism is the prism parser built into the interpreter, i.e., the
24 * very parser that parsed the running program.
25 *
26 * Its API and behavior will be identical to the version of prism bundled with this Ruby.
27 * In most cases, use the prism gem instead. Use \Ruby::Prism only when you
28 * need the very parser of the running interpreter.
29 *
30 * \Ruby::Prism is autoloaded when it is first referenced. Do not
31 * <code>require "ruby/prism"</code> explicitly, as it does not work well
32 * with Ruby::Box for a technical reason.
33 */
34 VALUE rb_mPrism = rb_define_module_under(rb_mRuby, "Prism");
35#endif
36 ruby_init_ext("ruby/prism/prism.so", Init_prism);
37}
38
39/*
40 * Set up the autoload of Ruby::Prism, so that programs that do not use it
41 * pay nothing. This is called after the command line options are processed,
42 * and only when prism is the parser that parses the program: with
43 * --parser=parse.y, Ruby::Prism is not defined.
44 */
45void
46rb_prism_init_autoload(void)
47{
48 rb_autoload_str(rb_define_module("Ruby"), rb_intern("Prism"), rb_str_new_cstr("ruby/prism"));
49}
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
Definition string.h:1539
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40