Skip to content

Commit 4e36abb

Browse files
committed
[PRISM] Support for compiling builtins
1 parent 4558abe commit 4e36abb

File tree

3 files changed

+377
-37
lines changed

3 files changed

+377
-37
lines changed

mini_builtin.c

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,16 @@
1212
static struct st_table *loaded_builtin_table;
1313
#endif
1414

15+
bool pm_builtin_ast_value(pm_parse_result_t *result, const char *feature_name, VALUE *name_str);
1516
VALUE rb_builtin_ast_value(const char *feature_name, VALUE *name_str);
1617

1718
static const rb_iseq_t *
1819
builtin_iseq_load(const char *feature_name, const struct rb_builtin_function *table)
1920
{
2021
VALUE name_str = 0;
21-
rb_ast_t *ast;
22-
VALUE ast_value = rb_builtin_ast_value(feature_name, &name_str);
23-
rb_vm_t *vm = GET_VM();
22+
const rb_iseq_t *iseq;
2423

25-
if (NIL_P(ast_value)) {
26-
rb_fatal("builtin_iseq_load: can not find %s; "
27-
"probably miniprelude.c is out of date",
28-
feature_name);
29-
}
30-
vm->builtin_function_table = table;
24+
rb_vm_t *vm = GET_VM();
3125
static const rb_compile_option_t optimization = {
3226
.inline_const_cache = TRUE,
3327
.peephole_optimization = TRUE,
@@ -40,11 +34,38 @@ builtin_iseq_load(const char *feature_name, const struct rb_builtin_function *ta
4034
.coverage_enabled = FALSE,
4135
.debug_level = 0,
4236
};
43-
ast = rb_ruby_ast_data_get(ast_value);
44-
const rb_iseq_t *iseq = rb_iseq_new_with_opt(ast_value, name_str, name_str, Qnil, 0, NULL, 0, ISEQ_TYPE_TOP, &optimization, Qnil);
45-
GET_VM()->builtin_function_table = NULL;
4637

47-
rb_ast_dispose(ast);
38+
if (*rb_ruby_prism_ptr()) {
39+
pm_parse_result_t result = { 0 };
40+
if (!pm_builtin_ast_value(&result, feature_name, &name_str)) {
41+
rb_fatal("builtin_iseq_load: can not find %s; "
42+
"probably miniprelude.c is out of date",
43+
feature_name);
44+
}
45+
46+
vm->builtin_function_table = table;
47+
iseq = pm_iseq_new_with_opt(&result.node, name_str, name_str, Qnil, 0, NULL, 0, ISEQ_TYPE_TOP, &optimization);
48+
49+
GET_VM()->builtin_function_table = NULL;
50+
pm_parse_result_free(&result);
51+
}
52+
else {
53+
VALUE ast_value = rb_builtin_ast_value(feature_name, &name_str);
54+
55+
if (NIL_P(ast_value)) {
56+
rb_fatal("builtin_iseq_load: can not find %s; "
57+
"probably miniprelude.c is out of date",
58+
feature_name);
59+
}
60+
61+
rb_ast_t *ast = rb_ruby_ast_data_get(ast_value);
62+
63+
vm->builtin_function_table = table;
64+
iseq = rb_iseq_new_with_opt(ast_value, name_str, name_str, Qnil, 0, NULL, 0, ISEQ_TYPE_TOP, &optimization, Qnil);
65+
66+
GET_VM()->builtin_function_table = NULL;
67+
rb_ast_dispose(ast);
68+
}
4869

4970
// for debug
5071
if (0 && strcmp("prelude", feature_name) == 0) {

0 commit comments

Comments
 (0)