Ruby: builtin.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

builtin.h
Go to the documentation of this file.
1#ifndef BUILTIN_H_INCLUDED
2#define BUILTIN_H_INCLUDED
3
4// invoke
5
6 struct rb_builtin_function {
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 // for jit
16 void (*compiler)(FILE *, long, unsigned, bool);
17};
18
19#define RB_BUILTIN_FUNCTION(_i, _name, _fname, _arity, _compiler) {\
20 .name = #_name, \
21 .func_ptr = (void *)_fname, \
22 .argc = _arity, \
23 .index = _i, \
24 .compiler = _compiler, \
25}
26
27void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table);
28
29#ifndef rb_execution_context_t
30 typedef struct rb_execution_context_struct rb_execution_context_t;
31#define rb_execution_context_t rb_execution_context_t
32#endif
33
34/* The following code is generated by the following Ruby script:
35
3616.times{|i|
37 args = (i > 0 ? ', ' : '') + (0...i).map{"VALUE"}.join(', ')
38 puts "static inline void rb_builtin_function_check_arity#{i}(VALUE (*f)(rb_execution_context_t *ec, VALUE self#{args})){}"
39}
40*/
41
42static inline void rb_builtin_function_check_arity0(VALUE (*f)(rb_execution_context_t *ec, VALUE self)){}
43static inline void rb_builtin_function_check_arity1(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE)){}
44static inline void rb_builtin_function_check_arity2(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE)){}
45static inline void rb_builtin_function_check_arity3(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE)){}
46static inline void rb_builtin_function_check_arity4(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE)){}
47static inline void rb_builtin_function_check_arity5(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE)){}
48static inline void rb_builtin_function_check_arity6(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
49static inline void rb_builtin_function_check_arity7(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
50static inline void rb_builtin_function_check_arity8(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
51static inline void rb_builtin_function_check_arity9(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
52static inline void rb_builtin_function_check_arity10(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
53static inline void rb_builtin_function_check_arity11(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
54static inline void rb_builtin_function_check_arity12(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
55static inline void rb_builtin_function_check_arity13(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
56static inline void rb_builtin_function_check_arity14(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
57static inline void rb_builtin_function_check_arity15(VALUE (*f)(rb_execution_context_t *ec, VALUE self, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE)){}
58
59 VALUE rb_vm_lvar_exposed(rb_execution_context_t *ec, int index);
60
61// __builtin_inline!
62
63 PUREFUNC(static inline VALUE rb_vm_lvar(rb_execution_context_t *ec, int index));
64
65static inline VALUE
66rb_vm_lvar(rb_execution_context_t *ec, int index)
67{
68#if VM_CORE_H_EC_DEFINED
69 return ec->cfp->ep[index];
70#else
71 return rb_vm_lvar_exposed(ec, index);
72#endif
73}
74
75// dump/load
76
77 struct builtin_binary {
78 const char *feature; // feature name
79 const unsigned char *bin; // binary by ISeq#to_binary
80 size_t bin_size;
81};
82
83#endif // BUILTIN_H_INCLUDED
PUREFUNC
#define PUREFUNC(x)
Definition: attributes.h:54
rb_load_with_builtin_functions
void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table)
Definition: builtin.c:36
rb_vm_lvar_exposed
VALUE rb_vm_lvar_exposed(rb_execution_context_t *ec, int index)
Definition: vm_insnhelper.c:5617
long
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
f
#define f
__sFILE
Definition: vsnprintf.c:169
builtin_binary
Definition: builtin.h:77
builtin_binary::bin
const unsigned char * bin
Definition: builtin.h:79
builtin_binary::feature
const char * feature
Definition: builtin.h:78
builtin_binary::bin_size
size_t bin_size
Definition: builtin.h:80
rb_builtin_function
Definition: builtin.h:6
rb_builtin_function::index
const int index
Definition: builtin.h:12
rb_builtin_function::func_ptr
const void *const func_ptr
Definition: builtin.h:8
rb_builtin_function::argc
const int argc
Definition: builtin.h:9
rb_builtin_function::name
const char *const name
Definition: builtin.h:13
rb_builtin_function::compiler
void(* compiler)(FILE *, long, unsigned, bool)
Definition: builtin.h:16
rb_control_frame_struct::ep
const VALUE * ep
Definition: vm_core.h:774
rb_execution_context_struct
Definition: vm_core.h:854
rb_execution_context_struct::cfp
rb_control_frame_t * cfp
Definition: vm_core.h:858
VALUE
unsigned long VALUE
Definition: value.h:38