Skip to content

Commit

Permalink
[ruby/prism] Expose main_script in serialization API
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Sep 13, 2024
1 parent 77521af commit f85efc9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ def dump_options(options)
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
Expand Down
5 changes: 5 additions & 0 deletions prism/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions prism/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f85efc9

Please sign in to comment.