Ruby 4.1.0dev (2026-05-15 revision fff4b3ef2e3e309e7a84288de53c189aa3d45fed)
builtin.h (fff4b3ef2e3e309e7a84288de53c189aa3d45fed)
1#ifndef BUILTIN_H_INCLUDED
2#define BUILTIN_H_INCLUDED
3
4// invoke
5
7 // for invocation
8 const void * const func_ptr;
9 const int argc;
10
11 // for load
12 const int index;
13 const char * const name;
14};
15
16#define RB_BUILTIN_FUNCTION(_i, _name, _fname, _arity) {\
17 .name = _i < 0 ? NULL : #_name, \
18 .func_ptr = (void *)(uintptr_t)_fname, \
19 .argc = _arity, \
20 .index = _i, \
21}
22
23void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table);
24VALUE rb_define_gem_modules(VALUE, VALUE);
25void rb_load_gem_prelude(VALUE box);
26
27#ifndef rb_execution_context_t
29#define rb_execution_context_t rb_execution_context_t
30#endif
31
32/* The following code is generated by the following Ruby script:
33
34typedef = proc {|i, args|
35 "typedef VALUE (*rb_builtin_arity#{i}_function_type)(rb_execution_context_t *ec, VALUE self#{args});"
36}
37puts typedef[0, ""]
38(1..15).each {|i|
39 puts typedef[i, ",\n " + (0...i).map{"VALUE"}.join(", ")]
40}
4116.times{|i|
42 puts "static inline void rb_builtin_function_check_arity#{i}(rb_builtin_arity#{i}_function_type f){}"
43}
44*/
45
46typedef VALUE (*rb_builtin_arity0_function_type)(rb_execution_context_t *ec, VALUE self);
47typedef VALUE (*rb_builtin_arity1_function_type)(rb_execution_context_t *ec, VALUE self,
48 VALUE);
49typedef VALUE (*rb_builtin_arity2_function_type)(rb_execution_context_t *ec, VALUE self,
50 VALUE, VALUE);
51typedef VALUE (*rb_builtin_arity3_function_type)(rb_execution_context_t *ec, VALUE self,
52 VALUE, VALUE, VALUE);
53typedef VALUE (*rb_builtin_arity4_function_type)(rb_execution_context_t *ec, VALUE self,
55typedef VALUE (*rb_builtin_arity5_function_type)(rb_execution_context_t *ec, VALUE self,
57typedef VALUE (*rb_builtin_arity6_function_type)(rb_execution_context_t *ec, VALUE self,
59typedef VALUE (*rb_builtin_arity7_function_type)(rb_execution_context_t *ec, VALUE self,
61typedef VALUE (*rb_builtin_arity8_function_type)(rb_execution_context_t *ec, VALUE self,
63typedef VALUE (*rb_builtin_arity9_function_type)(rb_execution_context_t *ec, VALUE self,
65typedef VALUE (*rb_builtin_arity10_function_type)(rb_execution_context_t *ec, VALUE self,
67typedef VALUE (*rb_builtin_arity11_function_type)(rb_execution_context_t *ec, VALUE self,
69typedef VALUE (*rb_builtin_arity12_function_type)(rb_execution_context_t *ec, VALUE self,
71typedef VALUE (*rb_builtin_arity13_function_type)(rb_execution_context_t *ec, VALUE self,
73typedef VALUE (*rb_builtin_arity14_function_type)(rb_execution_context_t *ec, VALUE self,
75typedef VALUE (*rb_builtin_arity15_function_type)(rb_execution_context_t *ec, VALUE self,
77static inline void rb_builtin_function_check_arity0(rb_builtin_arity0_function_type f){}
78static inline void rb_builtin_function_check_arity1(rb_builtin_arity1_function_type f){}
79static inline void rb_builtin_function_check_arity2(rb_builtin_arity2_function_type f){}
80static inline void rb_builtin_function_check_arity3(rb_builtin_arity3_function_type f){}
81static inline void rb_builtin_function_check_arity4(rb_builtin_arity4_function_type f){}
82static inline void rb_builtin_function_check_arity5(rb_builtin_arity5_function_type f){}
83static inline void rb_builtin_function_check_arity6(rb_builtin_arity6_function_type f){}
84static inline void rb_builtin_function_check_arity7(rb_builtin_arity7_function_type f){}
85static inline void rb_builtin_function_check_arity8(rb_builtin_arity8_function_type f){}
86static inline void rb_builtin_function_check_arity9(rb_builtin_arity9_function_type f){}
87static inline void rb_builtin_function_check_arity10(rb_builtin_arity10_function_type f){}
88static inline void rb_builtin_function_check_arity11(rb_builtin_arity11_function_type f){}
89static inline void rb_builtin_function_check_arity12(rb_builtin_arity12_function_type f){}
90static inline void rb_builtin_function_check_arity13(rb_builtin_arity13_function_type f){}
91static inline void rb_builtin_function_check_arity14(rb_builtin_arity14_function_type f){}
92static inline void rb_builtin_function_check_arity15(rb_builtin_arity15_function_type f){}
93
94PUREFUNC(VALUE rb_vm_lvar_exposed(rb_execution_context_t *ec, int index));
95VALUE rb_vm_lvar_exposed(rb_execution_context_t *ec, int index);
96
97// __builtin_inline!
98
99PUREFUNC(static inline VALUE rb_vm_lvar(rb_execution_context_t *ec, int index));
100
101static inline VALUE
102rb_vm_lvar(rb_execution_context_t *ec, int index)
103{
104#if defined(VM_CORE_H_EC_DEFINED) && VM_CORE_H_EC_DEFINED
105 return ec->cfp->ep[index];
106#else
107 return rb_vm_lvar_exposed(ec, index);
108#endif
109}
110
111static inline VALUE
112rb_builtin_basic_definition_p(rb_execution_context_t *ec, VALUE klass, VALUE id_sym)
113{
114 return rb_method_basic_definition_p(klass, rb_sym2id(id_sym)) ? Qtrue : Qfalse;
115}
116
117#define LOCAL_PTR(local) local ## __ptr
118
119// dump/load
120
122 const char *feature; // feature name
123 const unsigned char *bin; // binary by ISeq#to_binary
124 size_t bin_size;
125};
126
127#endif // BUILTIN_H_INCLUDED
#define Qtrue
Old name of RUBY_Qtrue.
#define Qfalse
Old name of RUBY_Qfalse.
ID rb_sym2id(VALUE obj)
Converts an instance of rb_cSymbol into an ID.
Definition symbol.c:974
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40