prism 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +20 -1
 - data/Makefile +17 -14
 - data/config.yml +12 -1
 - data/docs/configuration.md +1 -0
 - data/docs/releasing.md +7 -9
 - data/ext/prism/extconf.rb +8 -3
 - data/ext/prism/extension.c +28 -2
 - data/ext/prism/extension.h +1 -1
 - data/include/prism/diagnostic.h +12 -1
 - data/include/prism/parser.h +5 -1
 - data/include/prism/version.h +2 -2
 - data/lib/prism/desugar_compiler.rb +4 -2
 - data/lib/prism/ffi.rb +10 -0
 - data/lib/prism/node.rb +16 -0
 - data/lib/prism/parse_result.rb +5 -0
 - data/lib/prism/reflection.rb +421 -0
 - data/lib/prism/serialize.rb +13 -2
 - data/lib/prism/translation/parser/compiler.rb +48 -11
 - data/lib/prism.rb +1 -16
 - data/prism.gemspec +7 -3
 - data/rbi/prism/node.rbi +453 -0
 - data/rbi/prism/parse_result.rbi +3 -0
 - data/rbi/prism/reflection.rbi +64 -0
 - data/rbi/prism/translation/parser.rbi +11 -0
 - data/rbi/prism/translation/parser33.rbi +6 -0
 - data/rbi/prism/translation/parser34.rbi +6 -0
 - data/rbi/prism.rbi +33 -33
 - data/sig/prism/node.rbs +10 -1
 - data/sig/prism/parse_result.rbs +1 -0
 - data/sig/prism/reflection.rbs +56 -0
 - data/sig/prism.rbs +2 -2
 - data/src/diagnostic.c +30 -8
 - data/src/options.c +30 -19
 - data/src/prism.c +404 -67
 - data/src/token_type.c +3 -3
 - data/src/util/pm_integer.c +14 -8
 - metadata +8 -4
 - data/include/prism/util/pm_state_stack.h +0 -42
 - data/src/util/pm_state_stack.c +0 -25
 
    
        data/src/token_type.c
    CHANGED
    
    | 
         @@ -540,7 +540,7 @@ pm_token_type_human(pm_token_type_t token_type) { 
     | 
|
| 
       540 
540 
     | 
    
         
             
                    case PM_TOKEN_KEYWORD_RESCUE:
         
     | 
| 
       541 
541 
     | 
    
         
             
                        return "'rescue'";
         
     | 
| 
       542 
542 
     | 
    
         
             
                    case PM_TOKEN_KEYWORD_RESCUE_MODIFIER:
         
     | 
| 
       543 
     | 
    
         
            -
                        return "'rescue'";
         
     | 
| 
      
 543 
     | 
    
         
            +
                        return "'rescue' modifier";
         
     | 
| 
       544 
544 
     | 
    
         
             
                    case PM_TOKEN_KEYWORD_RETRY:
         
     | 
| 
       545 
545 
     | 
    
         
             
                        return "'retry'";
         
     | 
| 
       546 
546 
     | 
    
         
             
                    case PM_TOKEN_KEYWORD_RETURN:
         
     | 
| 
         @@ -658,13 +658,13 @@ pm_token_type_human(pm_token_type_t token_type) { 
     | 
|
| 
       658 
658 
     | 
    
         
             
                    case PM_TOKEN_STAR_STAR_EQUAL:
         
     | 
| 
       659 
659 
     | 
    
         
             
                        return "'**='";
         
     | 
| 
       660 
660 
     | 
    
         
             
                    case PM_TOKEN_STRING_BEGIN:
         
     | 
| 
       661 
     | 
    
         
            -
                        return "string  
     | 
| 
      
 661 
     | 
    
         
            +
                        return "string literal";
         
     | 
| 
       662 
662 
     | 
    
         
             
                    case PM_TOKEN_STRING_CONTENT:
         
     | 
| 
       663 
663 
     | 
    
         
             
                        return "string content";
         
     | 
| 
       664 
664 
     | 
    
         
             
                    case PM_TOKEN_STRING_END:
         
     | 
| 
       665 
665 
     | 
    
         
             
                        return "string ending";
         
     | 
| 
       666 
666 
     | 
    
         
             
                    case PM_TOKEN_SYMBOL_BEGIN:
         
     | 
| 
       667 
     | 
    
         
            -
                        return "symbol  
     | 
| 
      
 667 
     | 
    
         
            +
                        return "symbol literal";
         
     | 
| 
       668 
668 
     | 
    
         
             
                    case PM_TOKEN_TILDE:
         
     | 
| 
       669 
669 
     | 
    
         
             
                        return "'~'";
         
     | 
| 
       670 
670 
     | 
    
         
             
                    case PM_TOKEN_UAMPERSAND:
         
     | 
    
        data/src/util/pm_integer.c
    CHANGED
    
    | 
         @@ -172,21 +172,21 @@ karatsuba_multiply(pm_integer_t *destination, pm_integer_t *left, pm_integer_t * 
     | 
|
| 
       172 
172 
     | 
    
         
             
                pm_integer_t y0 = { 0, half, right_values, false };
         
     | 
| 
       173 
173 
     | 
    
         
             
                pm_integer_t y1 = { 0, right_length - half, right_values + half, false };
         
     | 
| 
       174 
174 
     | 
    
         | 
| 
       175 
     | 
    
         
            -
                pm_integer_t z0;
         
     | 
| 
      
 175 
     | 
    
         
            +
                pm_integer_t z0 = { 0 };
         
     | 
| 
       176 
176 
     | 
    
         
             
                karatsuba_multiply(&z0, &x0, &y0, base);
         
     | 
| 
       177 
177 
     | 
    
         | 
| 
       178 
     | 
    
         
            -
                pm_integer_t z2;
         
     | 
| 
      
 178 
     | 
    
         
            +
                pm_integer_t z2 = { 0 };
         
     | 
| 
       179 
179 
     | 
    
         
             
                karatsuba_multiply(&z2, &x1, &y1, base);
         
     | 
| 
       180 
180 
     | 
    
         | 
| 
       181 
181 
     | 
    
         
             
                // For simplicity to avoid considering negative values,
         
     | 
| 
       182 
182 
     | 
    
         
             
                // use `z1 = (x0 + x1) * (y0 + y1) - z0 - z2` instead of original karatsuba algorithm.
         
     | 
| 
       183 
     | 
    
         
            -
                pm_integer_t x01;
         
     | 
| 
      
 183 
     | 
    
         
            +
                pm_integer_t x01 = { 0 };
         
     | 
| 
       184 
184 
     | 
    
         
             
                big_add(&x01, &x0, &x1, base);
         
     | 
| 
       185 
185 
     | 
    
         | 
| 
       186 
     | 
    
         
            -
                pm_integer_t y01;
         
     | 
| 
      
 186 
     | 
    
         
            +
                pm_integer_t y01 = { 0 };
         
     | 
| 
       187 
187 
     | 
    
         
             
                big_add(&y01, &y0, &y1, base);
         
     | 
| 
       188 
188 
     | 
    
         | 
| 
       189 
     | 
    
         
            -
                pm_integer_t xy;
         
     | 
| 
      
 189 
     | 
    
         
            +
                pm_integer_t xy = { 0 };
         
     | 
| 
       190 
190 
     | 
    
         
             
                karatsuba_multiply(&xy, &x01, &y01, base);
         
     | 
| 
       191 
191 
     | 
    
         | 
| 
       192 
192 
     | 
    
         
             
                pm_integer_t z1;
         
     | 
| 
         @@ -194,7 +194,11 @@ karatsuba_multiply(pm_integer_t *destination, pm_integer_t *left, pm_integer_t * 
     | 
|
| 
       194 
194 
     | 
    
         | 
| 
       195 
195 
     | 
    
         
             
                size_t length = left_length + right_length;
         
     | 
| 
       196 
196 
     | 
    
         
             
                uint32_t *values = (uint32_t*) xcalloc(length, sizeof(uint32_t));
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
                assert(z0.values != NULL);
         
     | 
| 
       197 
199 
     | 
    
         
             
                memcpy(values, z0.values, sizeof(uint32_t) * z0.length);
         
     | 
| 
      
 200 
     | 
    
         
            +
             
     | 
| 
      
 201 
     | 
    
         
            +
                assert(z2.values != NULL);
         
     | 
| 
       198 
202 
     | 
    
         
             
                memcpy(values + 2 * half, z2.values, sizeof(uint32_t) * z2.length);
         
     | 
| 
       199 
203 
     | 
    
         | 
| 
       200 
204 
     | 
    
         
             
                uint32_t carry = 0;
         
     | 
| 
         @@ -326,6 +330,8 @@ pm_integer_convert_base(pm_integer_t *destination, const pm_integer_t *source, u 
     | 
|
| 
       326 
330 
     | 
    
         
             
                INTEGER_EXTRACT(source, source_length, source_values)
         
     | 
| 
       327 
331 
     | 
    
         | 
| 
       328 
332 
     | 
    
         
             
                size_t bigints_length = (source_length + 1) / 2;
         
     | 
| 
      
 333 
     | 
    
         
            +
                assert(bigints_length > 0);
         
     | 
| 
      
 334 
     | 
    
         
            +
             
     | 
| 
       329 
335 
     | 
    
         
             
                pm_integer_t *bigints = (pm_integer_t *) xcalloc(bigints_length, sizeof(pm_integer_t));
         
     | 
| 
       330 
336 
     | 
    
         
             
                if (bigints == NULL) return;
         
     | 
| 
       331 
337 
     | 
    
         | 
| 
         @@ -345,13 +351,13 @@ pm_integer_convert_base(pm_integer_t *destination, const pm_integer_t *source, u 
     | 
|
| 
       345 
351 
     | 
    
         
             
                    base = next_base;
         
     | 
| 
       346 
352 
     | 
    
         | 
| 
       347 
353 
     | 
    
         
             
                    size_t next_length = (bigints_length + 1) / 2;
         
     | 
| 
       348 
     | 
    
         
            -
                    pm_integer_t *next_bigints = (pm_integer_t *)  
     | 
| 
      
 354 
     | 
    
         
            +
                    pm_integer_t *next_bigints = (pm_integer_t *) xcalloc(next_length, sizeof(pm_integer_t));
         
     | 
| 
       349 
355 
     | 
    
         | 
| 
       350 
356 
     | 
    
         
             
                    for (size_t bigints_index = 0; bigints_index < bigints_length; bigints_index += 2) {
         
     | 
| 
       351 
357 
     | 
    
         
             
                        if (bigints_index + 1 == bigints_length) {
         
     | 
| 
       352 
358 
     | 
    
         
             
                            next_bigints[bigints_index / 2] = bigints[bigints_index];
         
     | 
| 
       353 
359 
     | 
    
         
             
                        } else {
         
     | 
| 
       354 
     | 
    
         
            -
                            pm_integer_t multiplied;
         
     | 
| 
      
 360 
     | 
    
         
            +
                            pm_integer_t multiplied = { 0 };
         
     | 
| 
       355 
361 
     | 
    
         
             
                            karatsuba_multiply(&multiplied, &base, &bigints[bigints_index + 1], base_to);
         
     | 
| 
       356 
362 
     | 
    
         | 
| 
       357 
363 
     | 
    
         
             
                            big_add(&next_bigints[bigints_index / 2], &bigints[bigints_index], &multiplied, base_to);
         
     | 
| 
         @@ -584,7 +590,7 @@ pm_integer_string(pm_buffer_t *buffer, const pm_integer_t *integer) { 
     | 
|
| 
       584 
590 
     | 
    
         
             
                }
         
     | 
| 
       585 
591 
     | 
    
         | 
| 
       586 
592 
     | 
    
         
             
                // Otherwise, first we'll convert the base from 1<<32 to 10**9.
         
     | 
| 
       587 
     | 
    
         
            -
                pm_integer_t converted;
         
     | 
| 
      
 593 
     | 
    
         
            +
                pm_integer_t converted = { 0 };
         
     | 
| 
       588 
594 
     | 
    
         
             
                pm_integer_convert_base(&converted, integer, (uint64_t) 1 << 32, 1000000000);
         
     | 
| 
       589 
595 
     | 
    
         | 
| 
       590 
596 
     | 
    
         
             
                if (converted.values == NULL) {
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: prism
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.26.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Shopify
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-04- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-04-18 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description:
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     | 
| 
         @@ -68,7 +68,6 @@ files: 
     | 
|
| 
       68 
68 
     | 
    
         
             
            - include/prism/util/pm_list.h
         
     | 
| 
       69 
69 
     | 
    
         
             
            - include/prism/util/pm_memchr.h
         
     | 
| 
       70 
70 
     | 
    
         
             
            - include/prism/util/pm_newline_list.h
         
     | 
| 
       71 
     | 
    
         
            -
            - include/prism/util/pm_state_stack.h
         
     | 
| 
       72 
71 
     | 
    
         
             
            - include/prism/util/pm_string.h
         
     | 
| 
       73 
72 
     | 
    
         
             
            - include/prism/util/pm_string_list.h
         
     | 
| 
       74 
73 
     | 
    
         
             
            - include/prism/util/pm_strncasecmp.h
         
     | 
| 
         @@ -93,6 +92,7 @@ files: 
     | 
|
| 
       93 
92 
     | 
    
         
             
            - lib/prism/parse_result/newlines.rb
         
     | 
| 
       94 
93 
     | 
    
         
             
            - lib/prism/pattern.rb
         
     | 
| 
       95 
94 
     | 
    
         
             
            - lib/prism/polyfill/string.rb
         
     | 
| 
      
 95 
     | 
    
         
            +
            - lib/prism/reflection.rb
         
     | 
| 
       96 
96 
     | 
    
         
             
            - lib/prism/serialize.rb
         
     | 
| 
       97 
97 
     | 
    
         
             
            - lib/prism/translation.rb
         
     | 
| 
       98 
98 
     | 
    
         
             
            - lib/prism/translation/parser.rb
         
     | 
| 
         @@ -114,7 +114,11 @@ files: 
     | 
|
| 
       114 
114 
     | 
    
         
             
            - rbi/prism/node.rbi
         
     | 
| 
       115 
115 
     | 
    
         
             
            - rbi/prism/node_ext.rbi
         
     | 
| 
       116 
116 
     | 
    
         
             
            - rbi/prism/parse_result.rbi
         
     | 
| 
      
 117 
     | 
    
         
            +
            - rbi/prism/reflection.rbi
         
     | 
| 
      
 118 
     | 
    
         
            +
            - rbi/prism/translation/parser.rbi
         
     | 
| 
       117 
119 
     | 
    
         
             
            - rbi/prism/translation/parser/compiler.rbi
         
     | 
| 
      
 120 
     | 
    
         
            +
            - rbi/prism/translation/parser33.rbi
         
     | 
| 
      
 121 
     | 
    
         
            +
            - rbi/prism/translation/parser34.rbi
         
     | 
| 
       118 
122 
     | 
    
         
             
            - rbi/prism/translation/ripper.rbi
         
     | 
| 
       119 
123 
     | 
    
         
             
            - rbi/prism/translation/ripper/ripper_compiler.rbi
         
     | 
| 
       120 
124 
     | 
    
         
             
            - rbi/prism/translation/ruby_parser.rbi
         
     | 
| 
         @@ -130,6 +134,7 @@ files: 
     | 
|
| 
       130 
134 
     | 
    
         
             
            - sig/prism/pack.rbs
         
     | 
| 
       131 
135 
     | 
    
         
             
            - sig/prism/parse_result.rbs
         
     | 
| 
       132 
136 
     | 
    
         
             
            - sig/prism/pattern.rbs
         
     | 
| 
      
 137 
     | 
    
         
            +
            - sig/prism/reflection.rbs
         
     | 
| 
       133 
138 
     | 
    
         
             
            - sig/prism/serialize.rbs
         
     | 
| 
       134 
139 
     | 
    
         
             
            - sig/prism/visitor.rbs
         
     | 
| 
       135 
140 
     | 
    
         
             
            - src/diagnostic.c
         
     | 
| 
         @@ -150,7 +155,6 @@ files: 
     | 
|
| 
       150 
155 
     | 
    
         
             
            - src/util/pm_list.c
         
     | 
| 
       151 
156 
     | 
    
         
             
            - src/util/pm_memchr.c
         
     | 
| 
       152 
157 
     | 
    
         
             
            - src/util/pm_newline_list.c
         
     | 
| 
       153 
     | 
    
         
            -
            - src/util/pm_state_stack.c
         
     | 
| 
       154 
158 
     | 
    
         
             
            - src/util/pm_string.c
         
     | 
| 
       155 
159 
     | 
    
         
             
            - src/util/pm_string_list.c
         
     | 
| 
       156 
160 
     | 
    
         
             
            - src/util/pm_strncasecmp.c
         
     | 
| 
         @@ -1,42 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            /**
         
     | 
| 
       2 
     | 
    
         
            -
             * @file pm_state_stack.h
         
     | 
| 
       3 
     | 
    
         
            -
             *
         
     | 
| 
       4 
     | 
    
         
            -
             * A stack of boolean values.
         
     | 
| 
       5 
     | 
    
         
            -
             */
         
     | 
| 
       6 
     | 
    
         
            -
            #ifndef PRISM_STATE_STACK_H
         
     | 
| 
       7 
     | 
    
         
            -
            #define PRISM_STATE_STACK_H
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            #include "prism/defines.h"
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            #include <stdbool.h>
         
     | 
| 
       12 
     | 
    
         
            -
            #include <stdint.h>
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            /**
         
     | 
| 
       15 
     | 
    
         
            -
             * A struct that represents a stack of boolean values.
         
     | 
| 
       16 
     | 
    
         
            -
             */
         
     | 
| 
       17 
     | 
    
         
            -
            typedef uint32_t pm_state_stack_t;
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            /**
         
     | 
| 
       20 
     | 
    
         
            -
             * Pushes a value onto the stack.
         
     | 
| 
       21 
     | 
    
         
            -
             *
         
     | 
| 
       22 
     | 
    
         
            -
             * @param stack The stack to push the value onto.
         
     | 
| 
       23 
     | 
    
         
            -
             * @param value The value to push onto the stack.
         
     | 
| 
       24 
     | 
    
         
            -
             */
         
     | 
| 
       25 
     | 
    
         
            -
            void pm_state_stack_push(pm_state_stack_t *stack, bool value);
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
            /**
         
     | 
| 
       28 
     | 
    
         
            -
             * Pops a value off the stack.
         
     | 
| 
       29 
     | 
    
         
            -
             *
         
     | 
| 
       30 
     | 
    
         
            -
             * @param stack The stack to pop the value off of.
         
     | 
| 
       31 
     | 
    
         
            -
             */
         
     | 
| 
       32 
     | 
    
         
            -
            void pm_state_stack_pop(pm_state_stack_t *stack);
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
            /**
         
     | 
| 
       35 
     | 
    
         
            -
             * Returns the value at the top of the stack.
         
     | 
| 
       36 
     | 
    
         
            -
             *
         
     | 
| 
       37 
     | 
    
         
            -
             * @param stack The stack to get the value from.
         
     | 
| 
       38 
     | 
    
         
            -
             * @return The value at the top of the stack.
         
     | 
| 
       39 
     | 
    
         
            -
             */
         
     | 
| 
       40 
     | 
    
         
            -
            bool pm_state_stack_p(pm_state_stack_t *stack);
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
            #endif
         
     | 
    
        data/src/util/pm_state_stack.c
    DELETED
    
    | 
         @@ -1,25 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            #include "prism/util/pm_state_stack.h"
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            /**
         
     | 
| 
       4 
     | 
    
         
            -
             * Pushes a value onto the stack.
         
     | 
| 
       5 
     | 
    
         
            -
             */
         
     | 
| 
       6 
     | 
    
         
            -
            void
         
     | 
| 
       7 
     | 
    
         
            -
            pm_state_stack_push(pm_state_stack_t *stack, bool value) {
         
     | 
| 
       8 
     | 
    
         
            -
                *stack = (*stack << 1) | (value & 1);
         
     | 
| 
       9 
     | 
    
         
            -
            }
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            /**
         
     | 
| 
       12 
     | 
    
         
            -
             * Pops a value off the stack.
         
     | 
| 
       13 
     | 
    
         
            -
             */
         
     | 
| 
       14 
     | 
    
         
            -
            void
         
     | 
| 
       15 
     | 
    
         
            -
            pm_state_stack_pop(pm_state_stack_t *stack) {
         
     | 
| 
       16 
     | 
    
         
            -
                *stack >>= 1;
         
     | 
| 
       17 
     | 
    
         
            -
            }
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            /**
         
     | 
| 
       20 
     | 
    
         
            -
             * Returns the value at the top of the stack.
         
     | 
| 
       21 
     | 
    
         
            -
             */
         
     | 
| 
       22 
     | 
    
         
            -
            bool
         
     | 
| 
       23 
     | 
    
         
            -
            pm_state_stack_p(pm_state_stack_t *stack) {
         
     | 
| 
       24 
     | 
    
         
            -
                return *stack & 1;
         
     | 
| 
       25 
     | 
    
         
            -
            }
         
     |