summaryrefslogtreecommitdiff
path: root/load.c
diff options
context:
space:
mode:
authorHParker <HParker@github.com>2023-12-07 15:47:36 -0800
committerKevin Newton <kddnewton@gmail.com>2023-12-15 13:42:19 -0500
commit55326a915f25608be1d40ab32baa9fc57762615d (patch)
tree69dc288dcadf3e09206c287919be5c7d9711edc2 /load.c
parent655c02790ee5aca122d3593fadab5b41a42a1899 (diff)
Introduce --parser runtime flag
Introduce runtime flag for specifying the parser, ``` ruby --parser=prism ``` also update the description: ``` $ ruby --parser=prism --version ruby 3.3.0dev (2023-12-08T04:47:14Z add-parser-runtime.. 0616384c9f) +PRISM [x86_64-darwin23] ``` [Bug #20044]
Diffstat (limited to 'load.c')
-rw-r--r--load.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/load.c b/load.c
index 35b80a6b4a..71bd3c7c1e 100644
--- a/load.c
+++ b/load.c
@@ -737,21 +737,37 @@ load_iseq_eval(rb_execution_context_t *ec, VALUE fname)
const rb_iseq_t *iseq = rb_iseq_load_iseq(fname);
if (!iseq) {
- rb_execution_context_t *ec = GET_EC();
- VALUE v = rb_vm_push_frame_fname(ec, fname);
- rb_ast_t *ast;
- VALUE parser = rb_parser_new();
- rb_parser_set_context(parser, NULL, FALSE);
- ast = (rb_ast_t *)rb_parser_load_file(parser, fname);
-
- rb_thread_t *th = rb_ec_thread_ptr(ec);
- VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
-
- iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"),
- fname, realpath_internal_cached(realpath_map, fname), NULL);
- rb_ast_dispose(ast);
- rb_vm_pop_frame(ec);
- RB_GC_GUARD(v);
+ if (*rb_ruby_prism_ptr()) {
+ pm_string_t input;
+ pm_options_t options = { 0 };
+
+ pm_string_mapped_init(&input, RSTRING_PTR(fname));
+ pm_options_filepath_set(&options, RSTRING_PTR(fname));
+
+ pm_parser_t parser;
+ pm_parser_init(&parser, pm_string_source(&input), pm_string_length(&input), &options);
+
+ iseq = rb_iseq_new_main_prism(&input, &options, fname);
+
+ pm_string_free(&input);
+ pm_options_free(&options);
+ } else {
+ rb_execution_context_t *ec = GET_EC();
+ VALUE v = rb_vm_push_frame_fname(ec, fname);
+ rb_ast_t *ast;
+ VALUE parser = rb_parser_new();
+ rb_parser_set_context(parser, NULL, FALSE);
+ ast = (rb_ast_t *)rb_parser_load_file(parser, fname);
+
+ rb_thread_t *th = rb_ec_thread_ptr(ec);
+ VALUE realpath_map = get_loaded_features_realpath_map(th->vm);
+
+ iseq = rb_iseq_new_top(&ast->body, rb_fstring_lit("<top (required)>"),
+ fname, realpath_internal_cached(realpath_map, fname), NULL);
+ rb_ast_dispose(ast);
+ rb_vm_pop_frame(ec);
+ RB_GC_GUARD(v);
+ }
}
rb_exec_event_hook_script_compiled(ec, iseq, Qnil);
rb_iseq_eval(iseq);