diff options
author | Jean Boussier <[email protected]> | 2023-11-29 11:46:33 +0100 |
---|---|---|
committer | git <[email protected]> | 2023-11-29 13:56:19 +0000 |
commit | 2af82e23165180f20ca2af374aedb7a45dedcc20 (patch) | |
tree | 1bd829f6f15140c645496167a208d38736ac8d81 /prism/util/pm_buffer.c | |
parent | 2653404840952d25bbdd7deaf599fbfb1f5287f0 (diff) |
[ruby/prism] Convert start line to signed integers
Ruby allows for 0 or negative line start, this is often used
with `eval` calls to get a correct offset when prefixing a snippet.
e.g.
```ruby
caller = caller_locations(1, 1).first
class_eval <<~RUBY, caller.path, caller.line - 2
# frozen_string_literal: true
def some_method
#{caller_provided_code_snippet}
end
RUBY
```
https://github.com/ruby/prism/commit/0d14ed1452
Diffstat (limited to 'prism/util/pm_buffer.c')
-rw-r--r-- | prism/util/pm_buffer.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/prism/util/pm_buffer.c b/prism/util/pm_buffer.c index dcdf1770bb..307b55d030 100644 --- a/prism/util/pm_buffer.c +++ b/prism/util/pm_buffer.c @@ -152,6 +152,15 @@ pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value) { } /** + * Append a 32-bit signed integer to the buffer as a variable-length integer. + */ +void +pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value) { + uint32_t unsigned_int = ((uint32_t)(value) << 1) ^ ((uint32_t)(value >> 31)); + pm_buffer_append_varuint(buffer, unsigned_int); +} + +/** * Concatenate one buffer onto another. */ void |