summaryrefslogtreecommitdiff
path: root/ruby.c
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2026-01-26 21:36:20 -0500
committerKevin Newton <kddnewton@gmail.com>2026-01-27 15:30:45 -0500
commitaf4a1ca021845837fd7bfb1e1b4b5abd7e336c34 (patch)
tree08d5929c5c3239b9e742c8b5906f8964949a6ff2 /ruby.c
parentec154654a99c07d065108e9c31793eb9ccbd9ad0 (diff)
Use slices instead of locations
In the C API, we want to use slices instead of locations in the AST. In this case a "slice" is effectively the same thing as the location, expect it is represented using a 32-bit offset and a 32-bit length. This will cut down on half of the space of all of the locations in the AST. Note that from the Ruby/Java/JavaScript side, this is effectively an invisible change. This only impacts the C/Rust side.
Diffstat (limited to 'ruby.c')
-rw-r--r--ruby.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/ruby.c b/ruby.c
index 28f43176d6..cd5c8d1d15 100644
--- a/ruby.c
+++ b/ruby.c
@@ -2200,7 +2200,7 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
// If we found an __END__ marker, then we're going to define a global
// DATA constant that is a file object that can be read to read the
// contents after the marker.
- if (NIL_P(error) && result->parser.data_loc.start != NULL) {
+ if (NIL_P(error) && result->parser.data_loc.length != 0) {
rb_define_global_const("DATA", rb_stdin);
}
}
@@ -2237,17 +2237,17 @@ prism_script(ruby_cmdline_options_t *opt, pm_parse_result_t *result)
// If we found an __END__ marker, then we're going to define a global
// DATA constant that is a file object that can be read to read the
// contents after the marker.
- if (NIL_P(error) && result->parser.data_loc.start != NULL) {
+ if (NIL_P(error) && result->parser.data_loc.length != 0) {
int xflag = opt->xflag;
VALUE file = open_load_file(script_name, &xflag);
const pm_parser_t *parser = &result->parser;
- size_t offset = parser->data_loc.start - parser->start + 7;
+ uint32_t offset = parser->data_loc.start + 7;
if ((parser->start + offset < parser->end) && parser->start[offset] == '\r') offset++;
if ((parser->start + offset < parser->end) && parser->start[offset] == '\n') offset++;
- rb_funcall(file, rb_intern_const("seek"), 2, SIZET2NUM(offset), INT2FIX(SEEK_SET));
+ rb_funcall(file, rb_intern_const("seek"), 2, UINT2NUM(offset), INT2FIX(SEEK_SET));
rb_define_global_const("DATA", file);
}
}