2019-11-07 02:58:00 -05:00
|
|
|
#include "internal.h"
|
|
|
|
#include "vm_core.h"
|
|
|
|
#include "iseq.h"
|
|
|
|
#include "builtin.h"
|
|
|
|
|
|
|
|
#include "builtin_binary.inc"
|
|
|
|
|
|
|
|
static const unsigned char*
|
|
|
|
builtin_lookup(const char *feature, size_t *psize)
|
|
|
|
{
|
|
|
|
for (int i=0; i<BUILTIN_BINARY_SIZE; i++) {
|
|
|
|
if (strcmp(builtin_binary[i].feature, feature) == 0) {
|
|
|
|
*psize = builtin_binary[i].bin_size;
|
|
|
|
return builtin_binary[i].bin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rb_bug("builtin_lookup: can not find %s\n", feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
rb_iseq_eval(iseq);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Init_builtin(void)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|