Ruby
2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
builtin.c
Go to the documentation of this file.
1
#include "
internal.h
"
2
#include "
vm_core.h
"
3
#include "
iseq.h
"
4
#include "
builtin.h
"
5
6
#if CROSS_COMPILING
7
8
#define INCLUDED_BY_BUILTIN_C 1
9
#include "
mini_builtin.c
"
10
11
#else
12
13
#include "builtin_binary.inc"
14
15
static
const
unsigned
char
*
16
builtin_lookup(
const
char
*feature,
size_t
*psize)
17
{
18
static
int
index
= 0;
19
int
i
=
index
++;
20
21
// usually, `builtin_binary` order is loading order at miniruby.
22
if
(
LIKELY
(
strcmp
(
builtin_binary
[
i
].feature, feature) == 0)) {
23
found:
24
*psize =
builtin_binary
[
i
].
bin_size
;
25
return
builtin_binary
[
i
].
bin
;
26
}
27
else
{
28
if
(0)
fprintf
(
stderr
,
"builtin_lookup: cached index miss (index:%d)\n"
,
i
);
29
for
(
i
=0;
i
<BUILTIN_BINARY_SIZE;
i
++) {
30
if
(
strcmp
(
builtin_binary
[
i
].feature, feature) == 0) {
31
goto
found;
32
}
33
}
34
}
35
rb_bug
(
"builtin_lookup: can not find %s\n"
, feature);
36
}
37
38
void
39
rb_load_with_builtin_functions
(
const
char
*feature_name,
const
struct
rb_builtin_function
*table)
40
{
41
// search binary
42
size_t
size
;
43
const
unsigned
char
*
bin
= builtin_lookup(feature_name, &
size
);
44
45
// load binary
46
rb_vm_t
*vm =
GET_VM
();
47
if
(vm->
builtin_function_table
!=
NULL
)
rb_bug
(
"vm->builtin_function_table should be NULL."
);
48
vm->
builtin_function_table
= table;
49
vm->
builtin_inline_index
= 0;
50
const
rb_iseq_t
*
iseq
=
rb_iseq_ibf_load_bytes
((
const
char
*)
bin
,
size
);
51
vm->
builtin_function_table
=
NULL
;
52
53
// exec
54
rb_iseq_eval
(rb_iseq_check(
iseq
));
55
}
56
57
#endif
58
59
void
60
Init_builtin
(
void
)
61
{
62
// nothing
63
}
64
65
void
66
Init_builtin_features
(
void
)
67
{
68
rb_load_with_builtin_functions
(
"gem_prelude"
,
NULL
);
69
}
strcmp
int strcmp(const char *, const char *)
i
uint32_t i
Definition:
rb_mjit_min_header-2.7.1.h:5425
rb_iseq_eval
VALUE rb_iseq_eval(const rb_iseq_t *iseq)
Definition:
vm.c:2163
rb_builtin_function
Definition:
builtin.h:6
rb_iseq_struct
Definition:
vm_core.h:456
GET_VM
#define GET_VM()
Definition:
vm_core.h:1764
rb_load_with_builtin_functions
void rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table)
Definition:
builtin.c:39
rb_iseq_ibf_load_bytes
const rb_iseq_t * rb_iseq_ibf_load_bytes(const char *bytes, size_t size)
Definition:
compile.c:11616
iseq
const rb_iseq_t * iseq
Definition:
rb_mjit_min_header-2.7.1.h:13426
builtin_binary::bin
const unsigned char * bin
Definition:
builtin.h:74
builtin_binary::bin_size
size_t bin_size
Definition:
builtin.h:75
NULL
#define NULL
Definition:
_sdbm.c:101
Init_builtin_features
void Init_builtin_features(void)
Definition:
builtin.c:66
LIKELY
#define LIKELY(x)
Definition:
ffi_common.h:125
iseq.h
bin
char bin[32]
Definition:
siphash.c:135
vm_core.h
size
int size
Definition:
encoding.c:58
rb_vm_struct::builtin_inline_index
int builtin_inline_index
Definition:
vm_core.h:659
rb_vm_struct::builtin_function_table
const struct rb_builtin_function * builtin_function_table
Definition:
vm_core.h:658
builtin_binary
Definition:
builtin.h:72
index
int index
Definition:
rb_mjit_min_header-2.7.1.h:11171
rb_bug
void rb_bug(const char *fmt,...)
Definition:
error.c:634
internal.h
mini_builtin.c
rb_vm_struct
Definition:
vm_core.h:576
stderr
#define stderr
Definition:
rb_mjit_min_header-2.7.1.h:1479
builtin.h
Init_builtin
void Init_builtin(void)
Definition:
builtin.c:60
fprintf
int fprintf(FILE *__restrict, const char *__restrict,...) __attribute__((__format__(__printf__
Generated by
1.8.17