Ruby 3.5.0dev (2025-01-10 revision 5fab31b15e32622c4b71d1d347a41937e9f9c212)
miniinit.c (5fab31b15e32622c4b71d1d347a41937e9f9c212)
1/**********************************************************************
2
3 miniinit.c -
4
5 $Author$
6 created at: Thu Jul 11 22:09:57 JST 2013
7
8 Copyright (C) 2013 Yukihiro Matsumoto
9
10**********************************************************************/
11
12#include "ruby/ruby.h"
13#include "ruby/encoding.h"
14
15/* loadpath.c */
16const char ruby_exec_prefix[] = "";
17const char ruby_initial_load_paths[] = "";
18
19/* localeinit.c */
22{
23 /* never used */
24 return Qnil;
25}
26
27int
28rb_locale_charmap_index(void)
29{
30 return -1;
31}
32
33int
34Init_enc_set_filesystem_encoding(void)
35{
36 return rb_enc_to_index(rb_default_external_encoding());
37}
38
39void rb_encdb_declare(const char *name);
40int rb_encdb_alias(const char *alias, const char *orig);
41void
42Init_enc(void)
43{
44 rb_encdb_declare("ASCII-8BIT");
45 rb_encdb_declare("US-ASCII");
46 rb_encdb_declare("UTF-8");
47 rb_encdb_alias("BINARY", "ASCII-8BIT");
48 rb_encdb_alias("ASCII", "US-ASCII");
49}
50
51/* miniruby does not support dynamic loading. */
52void
53Init_ext(void)
54{
55}
56
57static void builtin_loaded(const char *feature_name, VALUE iseq);
58#define BUILTIN_LOADED(feature_name, iseq) builtin_loaded(feature_name, (VALUE)(iseq))
59
60#include "mini_builtin.c"
61
62static struct st_table *loaded_builtin_table;
63
64static void
65builtin_loaded(const char *feature_name, VALUE iseq)
66{
67 st_insert(loaded_builtin_table, (st_data_t)feature_name, (st_data_t)iseq);
68 rb_vm_register_global_object(iseq);
69}
70
71static int
72each_builtin_i(st_data_t key, st_data_t val, st_data_t dmy)
73{
74 const char *feature = (const char *)key;
75 const rb_iseq_t *iseq = (const rb_iseq_t *)val;
76
77 rb_yield_values(2, rb_str_new2(feature), rb_iseqw_new(iseq));
78
79 return ST_CONTINUE;
80}
81
82/* :nodoc: */
83static VALUE
84each_builtin(VALUE self)
85{
86 st_foreach(loaded_builtin_table, each_builtin_i, 0);
87 return Qnil;
88}
89
90void
91Init_builtin(void)
92{
93 rb_define_singleton_method(rb_cRubyVM, "each_builtin", each_builtin, 0);
94 loaded_builtin_table = st_init_strtable();
95}
96
97void
98Init_builtin_features(void)
99{
100 // register for ruby
101 builtin_iseq_load("gem_prelude", NULL);
102}
103
104void
105rb_free_loaded_builtin_table(void)
106{
107 if (loaded_builtin_table)
108 st_free_table(loaded_builtin_table);
109}
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
#define rb_str_new2
Old name of rb_str_new_cstr.
Definition string.h:1675
#define Qnil
Old name of RUBY_Qnil.
Encoding relates APIs.
VALUE rb_locale_charmap(VALUE klass)
Returns a platform-depended "charmap" of the current locale.
Definition localeinit.c:91
VALUE rb_yield_values(int n,...)
Identical to rb_yield(), except it takes variadic number of parameters and pass them to the block.
Definition vm_eval.c:1366
Definition st.h:79
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40