prism 0.24.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BSDmakefile +58 -0
- data/CHANGELOG.md +50 -1
- data/Makefile +5 -2
- data/README.md +45 -6
- data/config.yml +499 -4
- data/docs/build_system.md +31 -0
- data/docs/configuration.md +2 -0
- data/docs/cruby_compilation.md +1 -1
- data/docs/parser_translation.md +14 -9
- data/docs/releasing.md +2 -2
- data/docs/ripper_translation.md +50 -0
- data/docs/ruby_api.md +1 -0
- data/docs/serialization.md +26 -5
- data/ext/prism/api_node.c +911 -815
- data/ext/prism/api_pack.c +9 -0
- data/ext/prism/extconf.rb +27 -11
- data/ext/prism/extension.c +313 -66
- data/ext/prism/extension.h +5 -4
- data/include/prism/ast.h +213 -64
- data/include/prism/defines.h +106 -2
- data/include/prism/diagnostic.h +134 -71
- data/include/prism/encoding.h +22 -4
- data/include/prism/node.h +93 -0
- data/include/prism/options.h +82 -7
- data/include/prism/pack.h +11 -0
- data/include/prism/parser.h +198 -53
- data/include/prism/prettyprint.h +8 -0
- data/include/prism/static_literals.h +118 -0
- data/include/prism/util/pm_buffer.h +65 -2
- data/include/prism/util/pm_constant_pool.h +18 -1
- data/include/prism/util/pm_integer.h +119 -0
- data/include/prism/util/pm_list.h +1 -1
- data/include/prism/util/pm_newline_list.h +8 -0
- data/include/prism/util/pm_string.h +26 -2
- data/include/prism/version.h +2 -2
- data/include/prism.h +59 -1
- data/lib/prism/compiler.rb +8 -1
- data/lib/prism/debug.rb +46 -3
- data/lib/prism/desugar_compiler.rb +1 -1
- data/lib/prism/dispatcher.rb +29 -0
- data/lib/prism/dot_visitor.rb +87 -16
- data/lib/prism/dsl.rb +24 -12
- data/lib/prism/ffi.rb +67 -12
- data/lib/prism/lex_compat.rb +17 -15
- data/lib/prism/mutation_compiler.rb +11 -0
- data/lib/prism/node.rb +2096 -2499
- data/lib/prism/node_ext.rb +77 -29
- data/lib/prism/pack.rb +4 -0
- data/lib/prism/parse_result/comments.rb +34 -17
- data/lib/prism/parse_result/newlines.rb +3 -1
- data/lib/prism/parse_result.rb +78 -32
- data/lib/prism/pattern.rb +16 -4
- data/lib/prism/polyfill/string.rb +12 -0
- data/lib/prism/serialize.rb +439 -102
- data/lib/prism/translation/parser/compiler.rb +152 -50
- data/lib/prism/translation/parser/lexer.rb +103 -22
- data/lib/prism/translation/parser/rubocop.rb +41 -13
- data/lib/prism/translation/parser.rb +119 -7
- data/lib/prism/translation/parser33.rb +1 -1
- data/lib/prism/translation/parser34.rb +1 -1
- data/lib/prism/translation/ripper/sexp.rb +125 -0
- data/lib/prism/translation/ripper/shim.rb +5 -0
- data/lib/prism/translation/ripper.rb +3212 -462
- data/lib/prism/translation/ruby_parser.rb +35 -18
- data/lib/prism/translation.rb +3 -1
- data/lib/prism/visitor.rb +10 -0
- data/lib/prism.rb +8 -2
- data/prism.gemspec +33 -4
- data/rbi/prism/compiler.rbi +14 -0
- data/rbi/prism/desugar_compiler.rbi +5 -0
- data/rbi/prism/mutation_compiler.rbi +5 -0
- data/rbi/prism/node.rbi +8221 -0
- data/rbi/prism/node_ext.rbi +102 -0
- data/rbi/prism/parse_result.rbi +304 -0
- data/rbi/prism/translation/parser/compiler.rbi +13 -0
- data/rbi/prism/translation/ripper/ripper_compiler.rbi +5 -0
- data/rbi/prism/translation/ripper.rbi +25 -0
- data/rbi/prism/translation/ruby_parser.rbi +11 -0
- data/rbi/prism/visitor.rbi +470 -0
- data/rbi/prism.rbi +39 -7749
- data/sig/prism/compiler.rbs +9 -0
- data/sig/prism/dispatcher.rbs +16 -0
- data/sig/prism/dot_visitor.rbs +6 -0
- data/sig/prism/dsl.rbs +462 -0
- data/sig/prism/mutation_compiler.rbs +158 -0
- data/sig/prism/node.rbs +3529 -0
- data/sig/prism/node_ext.rbs +78 -0
- data/sig/prism/pack.rbs +43 -0
- data/sig/prism/parse_result.rbs +127 -0
- data/sig/prism/pattern.rbs +13 -0
- data/sig/prism/serialize.rbs +7 -0
- data/sig/prism/visitor.rbs +168 -0
- data/sig/prism.rbs +188 -4767
- data/src/diagnostic.c +575 -230
- data/src/encoding.c +211 -108
- data/src/node.c +7526 -447
- data/src/options.c +36 -12
- data/src/pack.c +33 -17
- data/src/prettyprint.c +1294 -1385
- data/src/prism.c +3628 -1099
- data/src/regexp.c +17 -2
- data/src/serialize.c +47 -28
- data/src/static_literals.c +552 -0
- data/src/token_type.c +1 -0
- data/src/util/pm_buffer.c +147 -20
- data/src/util/pm_char.c +4 -4
- data/src/util/pm_constant_pool.c +35 -11
- data/src/util/pm_integer.c +629 -0
- data/src/util/pm_list.c +1 -1
- data/src/util/pm_newline_list.c +14 -5
- data/src/util/pm_string.c +134 -5
- data/src/util/pm_string_list.c +2 -2
- metadata +35 -6
- data/docs/ripper.md +0 -36
- data/rbi/prism_static.rbi +0 -207
- data/sig/prism_static.rbs +0 -201
data/lib/prism/serialize.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
=begin
|
3
4
|
This file is generated by the templates/template.rb script and should not be
|
4
5
|
modified manually. See templates/lib/prism/serialize.rb.erb
|
@@ -6,17 +7,7 @@ if you are looking to modify the template
|
|
6
7
|
=end
|
7
8
|
|
8
9
|
require "stringio"
|
9
|
-
|
10
|
-
# Polyfill for String#unpack1 with the offset parameter.
|
11
|
-
if String.instance_method(:unpack1).parameters.none? { |_, name| name == :offset }
|
12
|
-
String.prepend(
|
13
|
-
Module.new {
|
14
|
-
def unpack1(format, offset: 0) # :nodoc:
|
15
|
-
offset == 0 ? super(format) : self[offset..].unpack1(format)
|
16
|
-
end
|
17
|
-
}
|
18
|
-
)
|
19
|
-
end
|
10
|
+
require_relative "polyfill/string"
|
20
11
|
|
21
12
|
module Prism
|
22
13
|
# A module responsible for deserializing parse results.
|
@@ -27,7 +18,7 @@ module Prism
|
|
27
18
|
|
28
19
|
# The minor version of prism that we are expecting to find in the serialized
|
29
20
|
# strings.
|
30
|
-
MINOR_VERSION =
|
21
|
+
MINOR_VERSION = 25
|
31
22
|
|
32
23
|
# The patch version of prism that we are expecting to find in the serialized
|
33
24
|
# strings.
|
@@ -51,6 +42,37 @@ module Prism
|
|
51
42
|
end
|
52
43
|
|
53
44
|
class Loader # :nodoc:
|
45
|
+
if RUBY_ENGINE == "truffleruby"
|
46
|
+
# StringIO is synchronized and that adds a high overhead on TruffleRuby.
|
47
|
+
class FastStringIO # :nodoc:
|
48
|
+
attr_accessor :pos
|
49
|
+
|
50
|
+
def initialize(string)
|
51
|
+
@string = string
|
52
|
+
@pos = 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def getbyte
|
56
|
+
byte = @string.getbyte(@pos)
|
57
|
+
@pos += 1
|
58
|
+
byte
|
59
|
+
end
|
60
|
+
|
61
|
+
def read(n)
|
62
|
+
slice = @string.byteslice(@pos, n)
|
63
|
+
@pos += n
|
64
|
+
slice
|
65
|
+
end
|
66
|
+
|
67
|
+
def eof?
|
68
|
+
@pos >= @string.bytesize
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
FastStringIO = ::StringIO
|
73
|
+
end
|
74
|
+
private_constant :FastStringIO
|
75
|
+
|
54
76
|
attr_reader :encoding, :input, :serialized, :io
|
55
77
|
attr_reader :constant_pool_offset, :constant_pool, :source
|
56
78
|
attr_reader :start_line
|
@@ -59,9 +81,9 @@ module Prism
|
|
59
81
|
@encoding = Encoding::UTF_8
|
60
82
|
|
61
83
|
@input = source.source.dup
|
84
|
+
raise unless serialized.encoding == Encoding::BINARY
|
62
85
|
@serialized = serialized
|
63
|
-
@io =
|
64
|
-
@io.set_encoding(Encoding::BINARY)
|
86
|
+
@io = FastStringIO.new(serialized)
|
65
87
|
|
66
88
|
@constant_pool_offset = nil
|
67
89
|
@constant_pool = nil
|
@@ -73,7 +95,7 @@ module Prism
|
|
73
95
|
def load_header
|
74
96
|
raise "Invalid serialization" if io.read(5) != "PRISM"
|
75
97
|
raise "Invalid serialization" if io.read(3).unpack("C3") != [MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION]
|
76
|
-
only_semantic_fields = io.
|
98
|
+
only_semantic_fields = io.getbyte
|
77
99
|
unless only_semantic_fields == 0
|
78
100
|
raise "Invalid serialization (location fields must be included but are not)"
|
79
101
|
end
|
@@ -96,19 +118,293 @@ module Prism
|
|
96
118
|
def load_comments
|
97
119
|
Array.new(load_varuint) do
|
98
120
|
case load_varuint
|
99
|
-
when 0 then InlineComment.new(
|
100
|
-
when 1 then EmbDocComment.new(
|
101
|
-
when 2 then DATAComment.new(load_location)
|
121
|
+
when 0 then InlineComment.new(load_location_object)
|
122
|
+
when 1 then EmbDocComment.new(load_location_object)
|
102
123
|
end
|
103
124
|
end
|
104
125
|
end
|
105
126
|
|
127
|
+
DIAGNOSTIC_TYPES = [
|
128
|
+
:alias_argument,
|
129
|
+
:alias_argument_numbered_reference,
|
130
|
+
:ampampeq_multi_assign,
|
131
|
+
:argument_after_block,
|
132
|
+
:argument_after_forwarding_ellipses,
|
133
|
+
:argument_bare_hash,
|
134
|
+
:argument_block_forwarding,
|
135
|
+
:argument_block_multi,
|
136
|
+
:argument_formal_class,
|
137
|
+
:argument_formal_constant,
|
138
|
+
:argument_formal_global,
|
139
|
+
:argument_formal_ivar,
|
140
|
+
:argument_forwarding_unbound,
|
141
|
+
:argument_in,
|
142
|
+
:argument_no_forwarding_amp,
|
143
|
+
:argument_no_forwarding_ellipses,
|
144
|
+
:argument_no_forwarding_star,
|
145
|
+
:argument_no_forwarding_star_star,
|
146
|
+
:argument_splat_after_assoc_splat,
|
147
|
+
:argument_splat_after_splat,
|
148
|
+
:argument_term_paren,
|
149
|
+
:argument_unexpected_block,
|
150
|
+
:array_element,
|
151
|
+
:array_expression,
|
152
|
+
:array_expression_after_star,
|
153
|
+
:array_separator,
|
154
|
+
:array_term,
|
155
|
+
:begin_lonely_else,
|
156
|
+
:begin_term,
|
157
|
+
:begin_upcase_brace,
|
158
|
+
:begin_upcase_term,
|
159
|
+
:begin_upcase_toplevel,
|
160
|
+
:block_param_local_variable,
|
161
|
+
:block_param_pipe_term,
|
162
|
+
:block_term_brace,
|
163
|
+
:block_term_end,
|
164
|
+
:cannot_parse_expression,
|
165
|
+
:cannot_parse_string_part,
|
166
|
+
:case_expression_after_case,
|
167
|
+
:case_expression_after_when,
|
168
|
+
:case_match_missing_predicate,
|
169
|
+
:case_missing_conditions,
|
170
|
+
:case_term,
|
171
|
+
:class_in_method,
|
172
|
+
:class_name,
|
173
|
+
:class_superclass,
|
174
|
+
:class_term,
|
175
|
+
:class_unexpected_end,
|
176
|
+
:class_variable_bare,
|
177
|
+
:conditional_elsif_predicate,
|
178
|
+
:conditional_if_predicate,
|
179
|
+
:conditional_predicate_term,
|
180
|
+
:conditional_term,
|
181
|
+
:conditional_term_else,
|
182
|
+
:conditional_unless_predicate,
|
183
|
+
:conditional_until_predicate,
|
184
|
+
:conditional_while_predicate,
|
185
|
+
:constant_path_colon_colon_constant,
|
186
|
+
:def_endless,
|
187
|
+
:def_endless_setter,
|
188
|
+
:def_name,
|
189
|
+
:def_name_after_receiver,
|
190
|
+
:def_params_term,
|
191
|
+
:def_params_term_paren,
|
192
|
+
:def_receiver,
|
193
|
+
:def_receiver_term,
|
194
|
+
:def_term,
|
195
|
+
:defined_expression,
|
196
|
+
:embdoc_term,
|
197
|
+
:embexpr_end,
|
198
|
+
:embvar_invalid,
|
199
|
+
:end_upcase_brace,
|
200
|
+
:end_upcase_term,
|
201
|
+
:escape_invalid_control,
|
202
|
+
:escape_invalid_control_repeat,
|
203
|
+
:escape_invalid_hexadecimal,
|
204
|
+
:escape_invalid_meta,
|
205
|
+
:escape_invalid_meta_repeat,
|
206
|
+
:escape_invalid_unicode,
|
207
|
+
:escape_invalid_unicode_cm_flags,
|
208
|
+
:escape_invalid_unicode_literal,
|
209
|
+
:escape_invalid_unicode_long,
|
210
|
+
:escape_invalid_unicode_term,
|
211
|
+
:expect_argument,
|
212
|
+
:expect_eol_after_statement,
|
213
|
+
:expect_expression_after_ampampeq,
|
214
|
+
:expect_expression_after_comma,
|
215
|
+
:expect_expression_after_equal,
|
216
|
+
:expect_expression_after_less_less,
|
217
|
+
:expect_expression_after_lparen,
|
218
|
+
:expect_expression_after_operator,
|
219
|
+
:expect_expression_after_pipepipeeq,
|
220
|
+
:expect_expression_after_question,
|
221
|
+
:expect_expression_after_splat,
|
222
|
+
:expect_expression_after_splat_hash,
|
223
|
+
:expect_expression_after_star,
|
224
|
+
:expect_ident_req_parameter,
|
225
|
+
:expect_lparen_req_parameter,
|
226
|
+
:expect_rbracket,
|
227
|
+
:expect_rparen,
|
228
|
+
:expect_rparen_after_multi,
|
229
|
+
:expect_rparen_req_parameter,
|
230
|
+
:expect_string_content,
|
231
|
+
:expect_when_delimiter,
|
232
|
+
:expression_bare_hash,
|
233
|
+
:float_parse,
|
234
|
+
:for_collection,
|
235
|
+
:for_in,
|
236
|
+
:for_index,
|
237
|
+
:for_term,
|
238
|
+
:global_variable_bare,
|
239
|
+
:hash_expression_after_label,
|
240
|
+
:hash_key,
|
241
|
+
:hash_rocket,
|
242
|
+
:hash_term,
|
243
|
+
:hash_value,
|
244
|
+
:heredoc_term,
|
245
|
+
:incomplete_question_mark,
|
246
|
+
:incomplete_variable_class,
|
247
|
+
:incomplete_variable_class_3_3_0,
|
248
|
+
:incomplete_variable_instance,
|
249
|
+
:incomplete_variable_instance_3_3_0,
|
250
|
+
:instance_variable_bare,
|
251
|
+
:invalid_block_exit,
|
252
|
+
:invalid_character,
|
253
|
+
:invalid_encoding_magic_comment,
|
254
|
+
:invalid_float_exponent,
|
255
|
+
:invalid_multibyte_char,
|
256
|
+
:invalid_multibyte_character,
|
257
|
+
:invalid_multibyte_escape,
|
258
|
+
:invalid_number_binary,
|
259
|
+
:invalid_number_decimal,
|
260
|
+
:invalid_number_hexadecimal,
|
261
|
+
:invalid_number_octal,
|
262
|
+
:invalid_number_underscore,
|
263
|
+
:invalid_percent,
|
264
|
+
:invalid_printable_character,
|
265
|
+
:invalid_retry_after_else,
|
266
|
+
:invalid_retry_after_ensure,
|
267
|
+
:invalid_retry_without_rescue,
|
268
|
+
:invalid_variable_global,
|
269
|
+
:invalid_variable_global_3_3_0,
|
270
|
+
:invalid_yield,
|
271
|
+
:it_not_allowed_numbered,
|
272
|
+
:it_not_allowed_ordinary,
|
273
|
+
:lambda_open,
|
274
|
+
:lambda_term_brace,
|
275
|
+
:lambda_term_end,
|
276
|
+
:list_i_lower_element,
|
277
|
+
:list_i_lower_term,
|
278
|
+
:list_i_upper_element,
|
279
|
+
:list_i_upper_term,
|
280
|
+
:list_w_lower_element,
|
281
|
+
:list_w_lower_term,
|
282
|
+
:list_w_upper_element,
|
283
|
+
:list_w_upper_term,
|
284
|
+
:malloc_failed,
|
285
|
+
:mixed_encoding,
|
286
|
+
:module_in_method,
|
287
|
+
:module_name,
|
288
|
+
:module_term,
|
289
|
+
:multi_assign_multi_splats,
|
290
|
+
:multi_assign_unexpected_rest,
|
291
|
+
:no_local_variable,
|
292
|
+
:not_expression,
|
293
|
+
:number_literal_underscore,
|
294
|
+
:numbered_parameter_it,
|
295
|
+
:numbered_parameter_ordinary,
|
296
|
+
:numbered_parameter_outer_scope,
|
297
|
+
:operator_multi_assign,
|
298
|
+
:operator_write_arguments,
|
299
|
+
:operator_write_block,
|
300
|
+
:parameter_assoc_splat_multi,
|
301
|
+
:parameter_block_multi,
|
302
|
+
:parameter_circular,
|
303
|
+
:parameter_method_name,
|
304
|
+
:parameter_name_duplicated,
|
305
|
+
:parameter_no_default,
|
306
|
+
:parameter_no_default_kw,
|
307
|
+
:parameter_numbered_reserved,
|
308
|
+
:parameter_order,
|
309
|
+
:parameter_splat_multi,
|
310
|
+
:parameter_star,
|
311
|
+
:parameter_unexpected_fwd,
|
312
|
+
:parameter_wild_loose_comma,
|
313
|
+
:pattern_capture_duplicate,
|
314
|
+
:pattern_expression_after_bracket,
|
315
|
+
:pattern_expression_after_comma,
|
316
|
+
:pattern_expression_after_hrocket,
|
317
|
+
:pattern_expression_after_in,
|
318
|
+
:pattern_expression_after_key,
|
319
|
+
:pattern_expression_after_paren,
|
320
|
+
:pattern_expression_after_pin,
|
321
|
+
:pattern_expression_after_pipe,
|
322
|
+
:pattern_expression_after_range,
|
323
|
+
:pattern_expression_after_rest,
|
324
|
+
:pattern_hash_key,
|
325
|
+
:pattern_hash_key_duplicate,
|
326
|
+
:pattern_hash_key_label,
|
327
|
+
:pattern_ident_after_hrocket,
|
328
|
+
:pattern_label_after_comma,
|
329
|
+
:pattern_rest,
|
330
|
+
:pattern_term_brace,
|
331
|
+
:pattern_term_bracket,
|
332
|
+
:pattern_term_paren,
|
333
|
+
:pipepipeeq_multi_assign,
|
334
|
+
:regexp_encoding_option_mismatch,
|
335
|
+
:regexp_incompat_char_encoding,
|
336
|
+
:regexp_invalid_unicode_range,
|
337
|
+
:regexp_non_escaped_mbc,
|
338
|
+
:regexp_term,
|
339
|
+
:regexp_unknown_options,
|
340
|
+
:regexp_utf8_char_non_utf8_regexp,
|
341
|
+
:rescue_expression,
|
342
|
+
:rescue_modifier_value,
|
343
|
+
:rescue_term,
|
344
|
+
:rescue_variable,
|
345
|
+
:return_invalid,
|
346
|
+
:script_not_found,
|
347
|
+
:singleton_for_literals,
|
348
|
+
:statement_alias,
|
349
|
+
:statement_postexe_end,
|
350
|
+
:statement_preexe_begin,
|
351
|
+
:statement_undef,
|
352
|
+
:string_concatenation,
|
353
|
+
:string_interpolated_term,
|
354
|
+
:string_literal_eof,
|
355
|
+
:string_literal_term,
|
356
|
+
:symbol_invalid,
|
357
|
+
:symbol_term_dynamic,
|
358
|
+
:symbol_term_interpolated,
|
359
|
+
:ternary_colon,
|
360
|
+
:ternary_expression_false,
|
361
|
+
:ternary_expression_true,
|
362
|
+
:unary_receiver,
|
363
|
+
:undef_argument,
|
364
|
+
:unexpected_token_close_context,
|
365
|
+
:unexpected_token_ignore,
|
366
|
+
:until_term,
|
367
|
+
:void_expression,
|
368
|
+
:while_term,
|
369
|
+
:write_target_in_method,
|
370
|
+
:write_target_readonly,
|
371
|
+
:write_target_unexpected,
|
372
|
+
:xstring_term,
|
373
|
+
:ambiguous_first_argument_minus,
|
374
|
+
:ambiguous_first_argument_plus,
|
375
|
+
:ambiguous_prefix_ampersand,
|
376
|
+
:ambiguous_prefix_star,
|
377
|
+
:ambiguous_prefix_star_star,
|
378
|
+
:ambiguous_slash,
|
379
|
+
:comparison_after_comparison,
|
380
|
+
:dot_dot_dot_eol,
|
381
|
+
:equal_in_conditional,
|
382
|
+
:equal_in_conditional_3_3_0,
|
383
|
+
:end_in_method,
|
384
|
+
:duplicated_hash_key,
|
385
|
+
:duplicated_when_clause,
|
386
|
+
:float_out_of_range,
|
387
|
+
:ignored_frozen_string_literal,
|
388
|
+
:integer_in_flip_flop,
|
389
|
+
:invalid_character,
|
390
|
+
:invalid_numbered_reference,
|
391
|
+
:invalid_shareable_constant_value,
|
392
|
+
:keyword_eol,
|
393
|
+
:literal_in_condition_default,
|
394
|
+
:literal_in_condition_verbose,
|
395
|
+
:shebang_carriage_return,
|
396
|
+
:unexpected_carriage_return,
|
397
|
+
:unused_local_variable,
|
398
|
+
].freeze
|
399
|
+
|
400
|
+
private_constant :DIAGNOSTIC_TYPES
|
401
|
+
|
106
402
|
def load_metadata
|
107
403
|
comments = load_comments
|
108
|
-
magic_comments = Array.new(load_varuint) { MagicComment.new(
|
109
|
-
data_loc =
|
110
|
-
errors = Array.new(load_varuint) { ParseError.new(load_embedded_string,
|
111
|
-
warnings = Array.new(load_varuint) { ParseWarning.new(load_embedded_string,
|
404
|
+
magic_comments = Array.new(load_varuint) { MagicComment.new(load_location_object, load_location_object) }
|
405
|
+
data_loc = load_optional_location_object
|
406
|
+
errors = Array.new(load_varuint) { ParseError.new(DIAGNOSTIC_TYPES[load_varuint], load_embedded_string, load_location_object, load_error_level) }
|
407
|
+
warnings = Array.new(load_varuint) { ParseWarning.new(DIAGNOSTIC_TYPES[load_varuint], load_embedded_string, load_location_object, load_warning_level) }
|
112
408
|
[comments, magic_comments, data_loc, errors, warnings]
|
113
409
|
end
|
114
410
|
|
@@ -145,7 +441,7 @@ module Prism
|
|
145
441
|
|
146
442
|
comments, magic_comments, data_loc, errors, warnings = load_metadata
|
147
443
|
|
148
|
-
@constant_pool_offset =
|
444
|
+
@constant_pool_offset = load_uint32
|
149
445
|
@constant_pool = Array.new(load_varuint, nil)
|
150
446
|
|
151
447
|
[load_node, comments, magic_comments, data_loc, errors, warnings]
|
@@ -179,7 +475,22 @@ module Prism
|
|
179
475
|
(n >> 1) ^ (-(n & 1))
|
180
476
|
end
|
181
477
|
|
182
|
-
def
|
478
|
+
def load_integer
|
479
|
+
negative = io.getbyte != 0
|
480
|
+
length = load_varuint
|
481
|
+
|
482
|
+
value = 0
|
483
|
+
length.times { |index| value |= (load_varuint << (index * 32)) }
|
484
|
+
|
485
|
+
value = -value if negative
|
486
|
+
value
|
487
|
+
end
|
488
|
+
|
489
|
+
def load_double
|
490
|
+
io.read(8).unpack1("D")
|
491
|
+
end
|
492
|
+
|
493
|
+
def load_uint32
|
183
494
|
io.read(4).unpack1("L")
|
184
495
|
end
|
185
496
|
|
@@ -207,6 +518,10 @@ module Prism
|
|
207
518
|
end
|
208
519
|
|
209
520
|
def load_location
|
521
|
+
(load_varuint << 32) | load_varuint
|
522
|
+
end
|
523
|
+
|
524
|
+
def load_location_object
|
210
525
|
Location.new(source, load_varuint, load_varuint)
|
211
526
|
end
|
212
527
|
|
@@ -214,19 +529,23 @@ module Prism
|
|
214
529
|
load_location if io.getbyte != 0
|
215
530
|
end
|
216
531
|
|
532
|
+
def load_optional_location_object
|
533
|
+
load_location_object if io.getbyte != 0
|
534
|
+
end
|
535
|
+
|
217
536
|
def load_constant(index)
|
218
537
|
constant = constant_pool[index]
|
219
538
|
|
220
539
|
unless constant
|
221
540
|
offset = constant_pool_offset + index * 8
|
222
|
-
start = serialized.unpack1("L", offset: offset)
|
223
|
-
length = serialized.unpack1("L", offset: offset + 4)
|
541
|
+
start = @serialized.unpack1("L", offset: offset)
|
542
|
+
length = @serialized.unpack1("L", offset: offset + 4)
|
224
543
|
|
225
544
|
constant =
|
226
545
|
if start.nobits?(1 << 31)
|
227
546
|
input.byteslice(start, length).force_encoding(@encoding).to_sym
|
228
547
|
else
|
229
|
-
serialized.byteslice(start & ((1 << 31) - 1), length).force_encoding(@encoding).to_sym
|
548
|
+
@serialized.byteslice(start & ((1 << 31) - 1), length).force_encoding(@encoding).to_sym
|
230
549
|
end
|
231
550
|
|
232
551
|
constant_pool[index] = constant
|
@@ -249,9 +568,11 @@ module Prism
|
|
249
568
|
|
250
569
|
case level
|
251
570
|
when 0
|
252
|
-
:
|
571
|
+
:syntax
|
253
572
|
when 1
|
254
573
|
:argument
|
574
|
+
when 2
|
575
|
+
:load
|
255
576
|
else
|
256
577
|
raise "Unknown level: #{level}"
|
257
578
|
end
|
@@ -371,7 +692,7 @@ module Prism
|
|
371
692
|
source, load_required_constant, location)
|
372
693
|
when 32 then
|
373
694
|
ClassVariableWriteNode.new(
|
374
|
-
source, load_required_constant, load_location, load_node,
|
695
|
+
source, load_required_constant, load_location, load_node, load_location, location)
|
375
696
|
when 33 then
|
376
697
|
ConstantAndWriteNode.new(
|
377
698
|
source, load_required_constant, load_location, load_location, load_node, location)
|
@@ -409,7 +730,7 @@ module Prism
|
|
409
730
|
ConstantWriteNode.new(
|
410
731
|
source, load_required_constant, load_location, load_node, load_location, location)
|
411
732
|
when 45 then
|
412
|
-
|
733
|
+
load_uint32
|
413
734
|
DefNode.new(
|
414
735
|
source, load_required_constant, load_location, load_optional_node, load_optional_node, load_optional_node, Array.new(load_varuint) { load_required_constant }, load_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, location)
|
415
736
|
when 46 then
|
@@ -438,7 +759,7 @@ module Prism
|
|
438
759
|
source, load_varuint, load_optional_node, load_optional_node, load_location, location)
|
439
760
|
when 54 then
|
440
761
|
FloatNode.new(
|
441
|
-
source, location)
|
762
|
+
source, load_double, location)
|
442
763
|
when 55 then
|
443
764
|
ForNode.new(
|
444
765
|
source, load_node, load_node, load_optional_node, load_location, load_location, load_optional_location, load_location, location)
|
@@ -522,7 +843,7 @@ module Prism
|
|
522
843
|
source, load_required_constant, load_location, load_node, load_location, location)
|
523
844
|
when 82 then
|
524
845
|
IntegerNode.new(
|
525
|
-
source, load_varuint, location)
|
846
|
+
source, load_varuint, load_integer, location)
|
526
847
|
when 83 then
|
527
848
|
InterpolatedMatchLastLineNode.new(
|
528
849
|
source, load_varuint, load_location, Array.new(load_varuint) { load_node }, load_location, location)
|
@@ -531,7 +852,7 @@ module Prism
|
|
531
852
|
source, load_varuint, load_location, Array.new(load_varuint) { load_node }, load_location, location)
|
532
853
|
when 85 then
|
533
854
|
InterpolatedStringNode.new(
|
534
|
-
source, load_optional_location, Array.new(load_varuint) { load_node }, load_optional_location, location)
|
855
|
+
source, load_varuint, load_optional_location, Array.new(load_varuint) { load_node }, load_optional_location, location)
|
535
856
|
when 86 then
|
536
857
|
InterpolatedSymbolNode.new(
|
537
858
|
source, load_optional_location, Array.new(load_varuint) { load_node }, load_optional_location, location)
|
@@ -539,186 +860,192 @@ module Prism
|
|
539
860
|
InterpolatedXStringNode.new(
|
540
861
|
source, load_location, Array.new(load_varuint) { load_node }, load_location, location)
|
541
862
|
when 88 then
|
863
|
+
ItParametersNode.new(
|
864
|
+
source, location)
|
865
|
+
when 89 then
|
542
866
|
KeywordHashNode.new(
|
543
867
|
source, load_varuint, Array.new(load_varuint) { load_node }, location)
|
544
|
-
when
|
868
|
+
when 90 then
|
545
869
|
KeywordRestParameterNode.new(
|
546
870
|
source, load_varuint, load_optional_constant, load_optional_location, load_location, location)
|
547
|
-
when
|
871
|
+
when 91 then
|
548
872
|
LambdaNode.new(
|
549
873
|
source, Array.new(load_varuint) { load_required_constant }, load_location, load_location, load_location, load_optional_node, load_optional_node, location)
|
550
|
-
when
|
874
|
+
when 92 then
|
551
875
|
LocalVariableAndWriteNode.new(
|
552
876
|
source, load_location, load_location, load_node, load_required_constant, load_varuint, location)
|
553
|
-
when
|
877
|
+
when 93 then
|
554
878
|
LocalVariableOperatorWriteNode.new(
|
555
879
|
source, load_location, load_location, load_node, load_required_constant, load_required_constant, load_varuint, location)
|
556
|
-
when
|
880
|
+
when 94 then
|
557
881
|
LocalVariableOrWriteNode.new(
|
558
882
|
source, load_location, load_location, load_node, load_required_constant, load_varuint, location)
|
559
|
-
when
|
883
|
+
when 95 then
|
560
884
|
LocalVariableReadNode.new(
|
561
885
|
source, load_required_constant, load_varuint, location)
|
562
|
-
when
|
886
|
+
when 96 then
|
563
887
|
LocalVariableTargetNode.new(
|
564
888
|
source, load_required_constant, load_varuint, location)
|
565
|
-
when
|
889
|
+
when 97 then
|
566
890
|
LocalVariableWriteNode.new(
|
567
891
|
source, load_required_constant, load_varuint, load_location, load_node, load_location, location)
|
568
|
-
when
|
892
|
+
when 98 then
|
569
893
|
MatchLastLineNode.new(
|
570
894
|
source, load_varuint, load_location, load_location, load_location, load_string, location)
|
571
|
-
when
|
895
|
+
when 99 then
|
572
896
|
MatchPredicateNode.new(
|
573
897
|
source, load_node, load_node, load_location, location)
|
574
|
-
when
|
898
|
+
when 100 then
|
575
899
|
MatchRequiredNode.new(
|
576
900
|
source, load_node, load_node, load_location, location)
|
577
|
-
when
|
901
|
+
when 101 then
|
578
902
|
MatchWriteNode.new(
|
579
903
|
source, load_node, Array.new(load_varuint) { load_node }, location)
|
580
|
-
when
|
904
|
+
when 102 then
|
581
905
|
MissingNode.new(
|
582
906
|
source, location)
|
583
|
-
when
|
907
|
+
when 103 then
|
584
908
|
ModuleNode.new(
|
585
909
|
source, Array.new(load_varuint) { load_required_constant }, load_location, load_node, load_optional_node, load_location, load_required_constant, location)
|
586
|
-
when
|
910
|
+
when 104 then
|
587
911
|
MultiTargetNode.new(
|
588
912
|
source, Array.new(load_varuint) { load_node }, load_optional_node, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_location, location)
|
589
|
-
when
|
913
|
+
when 105 then
|
590
914
|
MultiWriteNode.new(
|
591
915
|
source, Array.new(load_varuint) { load_node }, load_optional_node, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_location, load_location, load_node, location)
|
592
|
-
when
|
916
|
+
when 106 then
|
593
917
|
NextNode.new(
|
594
918
|
source, load_optional_node, load_location, location)
|
595
|
-
when
|
919
|
+
when 107 then
|
596
920
|
NilNode.new(
|
597
921
|
source, location)
|
598
|
-
when
|
922
|
+
when 108 then
|
599
923
|
NoKeywordsParameterNode.new(
|
600
924
|
source, load_location, load_location, location)
|
601
|
-
when
|
925
|
+
when 109 then
|
602
926
|
NumberedParametersNode.new(
|
603
927
|
source, io.getbyte, location)
|
604
|
-
when
|
928
|
+
when 110 then
|
605
929
|
NumberedReferenceReadNode.new(
|
606
930
|
source, load_varuint, location)
|
607
|
-
when
|
931
|
+
when 111 then
|
608
932
|
OptionalKeywordParameterNode.new(
|
609
933
|
source, load_varuint, load_required_constant, load_location, load_node, location)
|
610
|
-
when
|
934
|
+
when 112 then
|
611
935
|
OptionalParameterNode.new(
|
612
936
|
source, load_varuint, load_required_constant, load_location, load_location, load_node, location)
|
613
|
-
when
|
937
|
+
when 113 then
|
614
938
|
OrNode.new(
|
615
939
|
source, load_node, load_node, load_location, location)
|
616
|
-
when
|
940
|
+
when 114 then
|
617
941
|
ParametersNode.new(
|
618
942
|
source, Array.new(load_varuint) { load_node }, Array.new(load_varuint) { load_node }, load_optional_node, Array.new(load_varuint) { load_node }, Array.new(load_varuint) { load_node }, load_optional_node, load_optional_node, location)
|
619
|
-
when
|
943
|
+
when 115 then
|
620
944
|
ParenthesesNode.new(
|
621
945
|
source, load_optional_node, load_location, load_location, location)
|
622
|
-
when
|
946
|
+
when 116 then
|
623
947
|
PinnedExpressionNode.new(
|
624
948
|
source, load_node, load_location, load_location, load_location, location)
|
625
|
-
when
|
949
|
+
when 117 then
|
626
950
|
PinnedVariableNode.new(
|
627
951
|
source, load_node, load_location, location)
|
628
|
-
when
|
952
|
+
when 118 then
|
629
953
|
PostExecutionNode.new(
|
630
954
|
source, load_optional_node, load_location, load_location, load_location, location)
|
631
|
-
when
|
955
|
+
when 119 then
|
632
956
|
PreExecutionNode.new(
|
633
957
|
source, load_optional_node, load_location, load_location, load_location, location)
|
634
|
-
when
|
958
|
+
when 120 then
|
635
959
|
ProgramNode.new(
|
636
960
|
source, Array.new(load_varuint) { load_required_constant }, load_node, location)
|
637
|
-
when
|
961
|
+
when 121 then
|
638
962
|
RangeNode.new(
|
639
963
|
source, load_varuint, load_optional_node, load_optional_node, load_location, location)
|
640
|
-
when
|
964
|
+
when 122 then
|
641
965
|
RationalNode.new(
|
642
966
|
source, load_node, location)
|
643
|
-
when
|
967
|
+
when 123 then
|
644
968
|
RedoNode.new(
|
645
969
|
source, location)
|
646
|
-
when
|
970
|
+
when 124 then
|
647
971
|
RegularExpressionNode.new(
|
648
972
|
source, load_varuint, load_location, load_location, load_location, load_string, location)
|
649
|
-
when
|
973
|
+
when 125 then
|
650
974
|
RequiredKeywordParameterNode.new(
|
651
975
|
source, load_varuint, load_required_constant, load_location, location)
|
652
|
-
when
|
976
|
+
when 126 then
|
653
977
|
RequiredParameterNode.new(
|
654
978
|
source, load_varuint, load_required_constant, location)
|
655
|
-
when
|
979
|
+
when 127 then
|
656
980
|
RescueModifierNode.new(
|
657
981
|
source, load_node, load_location, load_node, location)
|
658
|
-
when
|
982
|
+
when 128 then
|
659
983
|
RescueNode.new(
|
660
984
|
source, load_location, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location)
|
661
|
-
when
|
985
|
+
when 129 then
|
662
986
|
RestParameterNode.new(
|
663
987
|
source, load_varuint, load_optional_constant, load_optional_location, load_location, location)
|
664
|
-
when
|
988
|
+
when 130 then
|
665
989
|
RetryNode.new(
|
666
990
|
source, location)
|
667
|
-
when
|
991
|
+
when 131 then
|
668
992
|
ReturnNode.new(
|
669
993
|
source, load_location, load_optional_node, location)
|
670
|
-
when
|
994
|
+
when 132 then
|
671
995
|
SelfNode.new(
|
672
996
|
source, location)
|
673
|
-
when
|
997
|
+
when 133 then
|
998
|
+
ShareableConstantNode.new(
|
999
|
+
source, load_varuint, load_node, location)
|
1000
|
+
when 134 then
|
674
1001
|
SingletonClassNode.new(
|
675
1002
|
source, Array.new(load_varuint) { load_required_constant }, load_location, load_location, load_node, load_optional_node, load_location, location)
|
676
|
-
when
|
1003
|
+
when 135 then
|
677
1004
|
SourceEncodingNode.new(
|
678
1005
|
source, location)
|
679
|
-
when
|
1006
|
+
when 136 then
|
680
1007
|
SourceFileNode.new(
|
681
|
-
source, load_string, location)
|
682
|
-
when
|
1008
|
+
source, load_varuint, load_string, location)
|
1009
|
+
when 137 then
|
683
1010
|
SourceLineNode.new(
|
684
1011
|
source, location)
|
685
|
-
when
|
1012
|
+
when 138 then
|
686
1013
|
SplatNode.new(
|
687
1014
|
source, load_location, load_optional_node, location)
|
688
|
-
when
|
1015
|
+
when 139 then
|
689
1016
|
StatementsNode.new(
|
690
1017
|
source, Array.new(load_varuint) { load_node }, location)
|
691
|
-
when
|
1018
|
+
when 140 then
|
692
1019
|
StringNode.new(
|
693
1020
|
source, load_varuint, load_optional_location, load_location, load_optional_location, load_string, location)
|
694
|
-
when
|
1021
|
+
when 141 then
|
695
1022
|
SuperNode.new(
|
696
1023
|
source, load_location, load_optional_location, load_optional_node, load_optional_location, load_optional_node, location)
|
697
|
-
when
|
1024
|
+
when 142 then
|
698
1025
|
SymbolNode.new(
|
699
1026
|
source, load_varuint, load_optional_location, load_optional_location, load_optional_location, load_string, location)
|
700
|
-
when
|
1027
|
+
when 143 then
|
701
1028
|
TrueNode.new(
|
702
1029
|
source, location)
|
703
|
-
when
|
1030
|
+
when 144 then
|
704
1031
|
UndefNode.new(
|
705
1032
|
source, Array.new(load_varuint) { load_node }, load_location, location)
|
706
|
-
when
|
1033
|
+
when 145 then
|
707
1034
|
UnlessNode.new(
|
708
1035
|
source, load_location, load_node, load_optional_location, load_optional_node, load_optional_node, load_optional_location, location)
|
709
|
-
when
|
1036
|
+
when 146 then
|
710
1037
|
UntilNode.new(
|
711
1038
|
source, load_varuint, load_location, load_optional_location, load_node, load_optional_node, location)
|
712
|
-
when
|
1039
|
+
when 147 then
|
713
1040
|
WhenNode.new(
|
714
|
-
source, load_location, Array.new(load_varuint) { load_node }, load_optional_node, location)
|
715
|
-
when
|
1041
|
+
source, load_location, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_node, location)
|
1042
|
+
when 148 then
|
716
1043
|
WhileNode.new(
|
717
1044
|
source, load_varuint, load_location, load_optional_location, load_node, load_optional_node, location)
|
718
|
-
when
|
1045
|
+
when 149 then
|
719
1046
|
XStringNode.new(
|
720
1047
|
source, load_varuint, load_location, load_location, load_location, load_string, location)
|
721
|
-
when
|
1048
|
+
when 150 then
|
722
1049
|
YieldNode.new(
|
723
1050
|
source, load_location, load_optional_location, load_optional_node, load_optional_location, location)
|
724
1051
|
end
|
@@ -890,7 +1217,7 @@ module Prism
|
|
890
1217
|
-> {
|
891
1218
|
location = load_location
|
892
1219
|
ClassVariableWriteNode.new(
|
893
|
-
source, load_required_constant, load_location, load_node,
|
1220
|
+
source, load_required_constant, load_location, load_node, load_location, location)
|
894
1221
|
},
|
895
1222
|
-> {
|
896
1223
|
location = load_location
|
@@ -954,7 +1281,7 @@ module Prism
|
|
954
1281
|
},
|
955
1282
|
-> {
|
956
1283
|
location = load_location
|
957
|
-
|
1284
|
+
load_uint32
|
958
1285
|
DefNode.new(
|
959
1286
|
source, load_required_constant, load_location, load_optional_node, load_optional_node, load_optional_node, Array.new(load_varuint) { load_required_constant }, load_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, location)
|
960
1287
|
},
|
@@ -1001,7 +1328,7 @@ module Prism
|
|
1001
1328
|
-> {
|
1002
1329
|
location = load_location
|
1003
1330
|
FloatNode.new(
|
1004
|
-
source, location)
|
1331
|
+
source, load_double, location)
|
1005
1332
|
},
|
1006
1333
|
-> {
|
1007
1334
|
location = load_location
|
@@ -1141,7 +1468,7 @@ module Prism
|
|
1141
1468
|
-> {
|
1142
1469
|
location = load_location
|
1143
1470
|
IntegerNode.new(
|
1144
|
-
source, load_varuint, location)
|
1471
|
+
source, load_varuint, load_integer, location)
|
1145
1472
|
},
|
1146
1473
|
-> {
|
1147
1474
|
location = load_location
|
@@ -1156,7 +1483,7 @@ module Prism
|
|
1156
1483
|
-> {
|
1157
1484
|
location = load_location
|
1158
1485
|
InterpolatedStringNode.new(
|
1159
|
-
source, load_optional_location, Array.new(load_varuint) { load_node }, load_optional_location, location)
|
1486
|
+
source, load_varuint, load_optional_location, Array.new(load_varuint) { load_node }, load_optional_location, location)
|
1160
1487
|
},
|
1161
1488
|
-> {
|
1162
1489
|
location = load_location
|
@@ -1168,6 +1495,11 @@ module Prism
|
|
1168
1495
|
InterpolatedXStringNode.new(
|
1169
1496
|
source, load_location, Array.new(load_varuint) { load_node }, load_location, location)
|
1170
1497
|
},
|
1498
|
+
-> {
|
1499
|
+
location = load_location
|
1500
|
+
ItParametersNode.new(
|
1501
|
+
source, location)
|
1502
|
+
},
|
1171
1503
|
-> {
|
1172
1504
|
location = load_location
|
1173
1505
|
KeywordHashNode.new(
|
@@ -1388,6 +1720,11 @@ module Prism
|
|
1388
1720
|
SelfNode.new(
|
1389
1721
|
source, location)
|
1390
1722
|
},
|
1723
|
+
-> {
|
1724
|
+
location = load_location
|
1725
|
+
ShareableConstantNode.new(
|
1726
|
+
source, load_varuint, load_node, location)
|
1727
|
+
},
|
1391
1728
|
-> {
|
1392
1729
|
location = load_location
|
1393
1730
|
SingletonClassNode.new(
|
@@ -1401,7 +1738,7 @@ module Prism
|
|
1401
1738
|
-> {
|
1402
1739
|
location = load_location
|
1403
1740
|
SourceFileNode.new(
|
1404
|
-
source, load_string, location)
|
1741
|
+
source, load_varuint, load_string, location)
|
1405
1742
|
},
|
1406
1743
|
-> {
|
1407
1744
|
location = load_location
|
@@ -1456,7 +1793,7 @@ module Prism
|
|
1456
1793
|
-> {
|
1457
1794
|
location = load_location
|
1458
1795
|
WhenNode.new(
|
1459
|
-
source, load_location, Array.new(load_varuint) { load_node }, load_optional_node, location)
|
1796
|
+
source, load_location, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_node, location)
|
1460
1797
|
},
|
1461
1798
|
-> {
|
1462
1799
|
location = load_location
|