2019-11-07 02:58:00 -05:00
|
|
|
#include "internal.h"
|
|
|
|
#include "vm_core.h"
|
|
|
|
#include "iseq.h"
|
|
|
|
#include "builtin.h"
|
|
|
|
|
2021-04-29 08:31:05 -04:00
|
|
|
#ifdef CROSS_COMPILING
|
2019-12-10 03:39:04 -05:00
|
|
|
|
|
|
|
#define INCLUDED_BY_BUILTIN_C 1
|
|
|
|
#include "mini_builtin.c"
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2019-11-07 02:58:00 -05:00
|
|
|
#include "builtin_binary.inc"
|
|
|
|
|
2020-06-11 00:23:56 -04:00
|
|
|
static const unsigned char *
|
|
|
|
bin4feature(const struct builtin_binary *bb, const char *feature, size_t *psize)
|
|
|
|
{
|
|
|
|
*psize = bb->bin_size;
|
|
|
|
return strcmp(bb->feature, feature) ? NULL : bb->bin;
|
|
|
|
}
|
|
|
|
|
2019-11-07 02:58:00 -05:00
|
|
|
static const unsigned char*
|
|
|
|
builtin_lookup(const char *feature, size_t *psize)
|
|
|
|
{
|
2019-12-11 01:45:23 -05:00
|
|
|
static int index = 0;
|
2020-06-11 00:23:56 -04:00
|
|
|
const unsigned char *bin = bin4feature(&builtin_binary[index++], feature, psize);
|
2019-12-11 01:45:23 -05:00
|
|
|
|
|
|
|
// usually, `builtin_binary` order is loading order at miniruby.
|
2020-06-11 00:23:56 -04:00
|
|
|
for (const struct builtin_binary *bb = &builtin_binary[0]; bb->feature &&! bin; bb++) {
|
|
|
|
bin = bin4feature(bb++, feature, psize);
|
2019-12-11 01:45:23 -05:00
|
|
|
}
|
2020-06-11 00:23:56 -04:00
|
|
|
return bin;
|
2019-11-07 02:58:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-11-09 05:43:14 -05:00
|
|
|
rb_load_with_builtin_functions(const char *feature_name, const struct rb_builtin_function *table)
|
2019-11-07 02:58:00 -05:00
|
|
|
{
|
|
|
|
// search binary
|
|
|
|
size_t size;
|
|
|
|
const unsigned char *bin = builtin_lookup(feature_name, &size);
|
2020-06-11 00:23:56 -04:00
|
|
|
if (! bin) {
|
|
|
|
rb_bug("builtin_lookup: can not find %s\n", feature_name);
|
|
|
|
}
|
2019-11-07 02:58:00 -05:00
|
|
|
|
|
|
|
// load binary
|
2019-11-11 02:38:46 -05:00
|
|
|
rb_vm_t *vm = GET_VM();
|
|
|
|
if (vm->builtin_function_table != NULL) rb_bug("vm->builtin_function_table should be NULL.");
|
|
|
|
vm->builtin_function_table = table;
|
|
|
|
vm->builtin_inline_index = 0;
|
2019-11-08 02:16:25 -05:00
|
|
|
const rb_iseq_t *iseq = rb_iseq_ibf_load_bytes((const char *)bin, size);
|
2019-11-11 02:38:46 -05:00
|
|
|
vm->builtin_function_table = NULL;
|
2019-11-07 02:58:00 -05:00
|
|
|
|
|
|
|
// exec
|
2019-12-25 00:10:35 -05:00
|
|
|
rb_iseq_eval(rb_iseq_check(iseq));
|
2019-11-07 02:58:00 -05:00
|
|
|
}
|
|
|
|
|
2019-12-10 03:39:04 -05:00
|
|
|
#endif
|
|
|
|
|
2019-11-07 02:58:00 -05:00
|
|
|
void
|
|
|
|
Init_builtin(void)
|
|
|
|
{
|
2019-12-10 02:19:13 -05:00
|
|
|
// nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Init_builtin_features(void)
|
|
|
|
{
|
|
|
|
rb_load_with_builtin_functions("gem_prelude", NULL);
|
2019-11-07 02:58:00 -05:00
|
|
|
}
|