From f85efc9748b193bceaefd2e94293927404ac951f Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 13 Sep 2024 15:00:03 -0400 Subject: [PATCH] [ruby/prism] Expose main_script in serialization API https://github.com/ruby/prism/commit/0b527ca93f --- lib/prism/ffi.rb | 3 +++ prism/extension.c | 5 +++++ prism/options.c | 1 + 3 files changed, 9 insertions(+) diff --git a/lib/prism/ffi.rb b/lib/prism/ffi.rb index b972520be1..40a4b32621 100644 --- a/lib/prism/ffi.rb +++ b/lib/prism/ffi.rb @@ -448,6 +448,9 @@ module Prism template << "C" values << (options[:encoding] == false ? 1 : 0) + template << "C" + values << (options.fetch(:main_script, false) ? 1 : 0) + template << "L" if (scopes = options[:scopes]) values << scopes.length diff --git a/prism/extension.c b/prism/extension.c index 94fc5a104b..f08682e0f3 100644 --- a/prism/extension.c +++ b/prism/extension.c @@ -756,6 +756,11 @@ parse_input(pm_string_t *input, const pm_options_t *options) { * has been set. This should be a boolean or nil. * * `line` - the line number that the parse starts on. This should be an * integer or nil. Note that this is 1-indexed. + * * `main_script` - a boolean indicating whether or not the source being parsed + * is the main script being run by the interpreter. This controls whether + * or not shebangs are parsed for additional flags and whether or not the + * parser will attempt to find a matching shebang if the first one does + * not contain the word "ruby". * * `scopes` - the locals that are in scope surrounding the code that is being * parsed. This should be an array of arrays of symbols or nil. Scopes are * ordered from the outermost scope to the innermost one. diff --git a/prism/options.c b/prism/options.c index e0b4735e4a..67b257138c 100644 --- a/prism/options.c +++ b/prism/options.c @@ -241,6 +241,7 @@ pm_options_read(pm_options_t *options, const char *data) { options->command_line = (uint8_t) *data++; options->version = (pm_options_version_t) *data++; options->encoding_locked = ((uint8_t) *data++) > 0; + options->main_script = ((uint8_t) *data++) > 0; uint32_t scopes_count = pm_options_read_u32(data); data += 4;