lib/prism/serialize.rb in prism-0.19.0 vs lib/prism/serialize.rb in prism-0.20.0

- old
+ new

@@ -25,11 +25,11 @@ # strings. MAJOR_VERSION = 0 # The minor version of prism that we are expecting to find in the serialized # strings. - MINOR_VERSION = 19 + MINOR_VERSION = 20 # The patch version of prism that we are expecting to find in the serialized # strings. PATCH_VERSION = 0 @@ -101,12 +101,12 @@ def load_metadata comments = load_comments magic_comments = load_varuint.times.map { MagicComment.new(load_location, load_location) } data_loc = load_optional_location - errors = load_varuint.times.map { ParseError.new(load_embedded_string, load_location) } - warnings = load_varuint.times.map { ParseWarning.new(load_embedded_string, load_location) } + errors = load_varuint.times.map { ParseError.new(load_embedded_string, load_location, load_error_level) } + warnings = load_varuint.times.map { ParseWarning.new(load_embedded_string, load_location, load_warning_level) } [comments, magic_comments, data_loc, errors, warnings] end def load_tokens tokens = [] @@ -216,13 +216,13 @@ start = serialized.unpack1("L", offset: offset) length = serialized.unpack1("L", offset: offset + 4) constant = if start.nobits?(1 << 31) - input.byteslice(start, length).to_sym + input.byteslice(start, length).force_encoding(@encoding).to_sym else - serialized.byteslice(start & ((1 << 31) - 1), length).to_sym + serialized.byteslice(start & ((1 << 31) - 1), length).force_encoding(@encoding).to_sym end constant_pool[index] = constant end @@ -236,10 +236,34 @@ def load_optional_constant index = load_varuint load_constant(index - 1) if index != 0 end + def load_error_level + level = io.getbyte + + case level + when 0 + :fatal + else + raise "Unknown level: #{level}" + end + end + + def load_warning_level + level = io.getbyte + + case level + when 0 + :default + when 1 + :verbose + else + raise "Unknown level: #{level}" + end + end + if RUBY_ENGINE == 'ruby' def load_node type = io.getbyte location = load_location @@ -257,25 +281,25 @@ when 6 then ArrayNode.new(load_varuint, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_location, location) when 7 then ArrayPatternNode.new(load_optional_node, Array.new(load_varuint) { load_node }, load_optional_node, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_location, location) when 8 then - AssocNode.new(load_node, load_optional_node, load_optional_location, location) + AssocNode.new(load_node, load_node, load_optional_location, location) when 9 then AssocSplatNode.new(load_optional_node, load_location, location) when 10 then BackReferenceReadNode.new(load_required_constant, location) when 11 then BeginNode.new(load_optional_location, load_optional_node, load_optional_node, load_optional_node, load_optional_node, load_optional_location, location) when 12 then BlockArgumentNode.new(load_optional_node, load_location, location) when 13 then - BlockLocalVariableNode.new(load_required_constant, location) + BlockLocalVariableNode.new(load_varuint, load_required_constant, location) when 14 then - BlockNode.new(Array.new(load_varuint) { load_required_constant }, load_varuint, load_optional_node, load_optional_node, load_location, load_location, location) + BlockNode.new(Array.new(load_varuint) { load_required_constant }, load_optional_node, load_optional_node, load_location, load_location, location) when 15 then - BlockParameterNode.new(load_optional_constant, load_optional_location, load_location, location) + BlockParameterNode.new(load_varuint, load_optional_constant, load_optional_location, load_location, location) when 16 then BlockParametersNode.new(load_optional_node, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_location, location) when 17 then BreakNode.new(load_optional_node, load_location, location) when 18 then @@ -332,11 +356,11 @@ ConstantTargetNode.new(load_required_constant, location) when 44 then ConstantWriteNode.new(load_required_constant, load_location, load_node, load_location, location) when 45 then load_serialized_length - DefNode.new(load_required_constant, load_location, load_optional_node, load_optional_node, load_optional_node, Array.new(load_varuint) { load_required_constant }, load_varuint, load_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, location) + DefNode.new(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) when 46 then DefinedNode.new(load_optional_location, load_node, load_optional_location, load_location, location) when 47 then ElseNode.new(load_location, load_optional_node, load_optional_location, location) when 48 then @@ -420,13 +444,13 @@ when 87 then InterpolatedXStringNode.new(load_location, Array.new(load_varuint) { load_node }, load_location, location) when 88 then KeywordHashNode.new(load_varuint, Array.new(load_varuint) { load_node }, location) when 89 then - KeywordRestParameterNode.new(load_optional_constant, load_optional_location, load_location, location) + KeywordRestParameterNode.new(load_varuint, load_optional_constant, load_optional_location, load_location, location) when 90 then - LambdaNode.new(Array.new(load_varuint) { load_required_constant }, load_varuint, load_location, load_location, load_location, load_optional_node, load_optional_node, location) + LambdaNode.new(Array.new(load_varuint) { load_required_constant }, load_location, load_location, load_location, load_optional_node, load_optional_node, location) when 91 then LocalVariableAndWriteNode.new(load_location, load_location, load_node, load_required_constant, load_varuint, location) when 92 then LocalVariableOperatorWriteNode.new(load_location, load_location, load_node, load_required_constant, load_required_constant, load_varuint, location) when 93 then @@ -462,13 +486,13 @@ when 108 then NumberedParametersNode.new(io.getbyte, location) when 109 then NumberedReferenceReadNode.new(load_varuint, location) when 110 then - OptionalKeywordParameterNode.new(load_required_constant, load_location, load_node, location) + OptionalKeywordParameterNode.new(load_varuint, load_required_constant, load_location, load_node, location) when 111 then - OptionalParameterNode.new(load_required_constant, load_location, load_location, load_node, location) + OptionalParameterNode.new(load_varuint, load_required_constant, load_location, load_location, load_node, location) when 112 then OrNode.new(load_node, load_node, load_location, location) when 113 then ParametersNode.new(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) when 114 then @@ -490,19 +514,19 @@ when 122 then RedoNode.new(location) when 123 then RegularExpressionNode.new(load_varuint, load_location, load_location, load_location, load_string, location) when 124 then - RequiredKeywordParameterNode.new(load_required_constant, load_location, location) + RequiredKeywordParameterNode.new(load_varuint, load_required_constant, load_location, location) when 125 then - RequiredParameterNode.new(load_required_constant, location) + RequiredParameterNode.new(load_varuint, load_required_constant, location) when 126 then RescueModifierNode.new(load_node, load_location, load_node, location) when 127 then RescueNode.new(load_location, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location) when 128 then - RestParameterNode.new(load_optional_constant, load_optional_location, load_location, location) + RestParameterNode.new(load_varuint, load_optional_constant, load_optional_location, load_location, location) when 129 then RetryNode.new(location) when 130 then ReturnNode.new(load_location, load_optional_node, location) when 131 then @@ -580,11 +604,11 @@ location = load_location ArrayPatternNode.new(load_optional_node, Array.new(load_varuint) { load_node }, load_optional_node, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_location, location) }, -> { location = load_location - AssocNode.new(load_node, load_optional_node, load_optional_location, location) + AssocNode.new(load_node, load_node, load_optional_location, location) }, -> { location = load_location AssocSplatNode.new(load_optional_node, load_location, location) }, @@ -600,19 +624,19 @@ location = load_location BlockArgumentNode.new(load_optional_node, load_location, location) }, -> { location = load_location - BlockLocalVariableNode.new(load_required_constant, location) + BlockLocalVariableNode.new(load_varuint, load_required_constant, location) }, -> { location = load_location - BlockNode.new(Array.new(load_varuint) { load_required_constant }, load_varuint, load_optional_node, load_optional_node, load_location, load_location, location) + BlockNode.new(Array.new(load_varuint) { load_required_constant }, load_optional_node, load_optional_node, load_location, load_location, location) }, -> { location = load_location - BlockParameterNode.new(load_optional_constant, load_optional_location, load_location, location) + BlockParameterNode.new(load_varuint, load_optional_constant, load_optional_location, load_location, location) }, -> { location = load_location BlockParametersNode.new(load_optional_node, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_location, location) }, @@ -729,11 +753,11 @@ ConstantWriteNode.new(load_required_constant, load_location, load_node, load_location, location) }, -> { location = load_location load_serialized_length - DefNode.new(load_required_constant, load_location, load_optional_node, load_optional_node, load_optional_node, Array.new(load_varuint) { load_required_constant }, load_varuint, load_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, load_optional_location, location) + DefNode.new(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) }, -> { location = load_location DefinedNode.new(load_optional_location, load_node, load_optional_location, load_location, location) }, @@ -905,15 +929,15 @@ location = load_location KeywordHashNode.new(load_varuint, Array.new(load_varuint) { load_node }, location) }, -> { location = load_location - KeywordRestParameterNode.new(load_optional_constant, load_optional_location, load_location, location) + KeywordRestParameterNode.new(load_varuint, load_optional_constant, load_optional_location, load_location, location) }, -> { location = load_location - LambdaNode.new(Array.new(load_varuint) { load_required_constant }, load_varuint, load_location, load_location, load_location, load_optional_node, load_optional_node, location) + LambdaNode.new(Array.new(load_varuint) { load_required_constant }, load_location, load_location, load_location, load_optional_node, load_optional_node, location) }, -> { location = load_location LocalVariableAndWriteNode.new(load_location, load_location, load_node, load_required_constant, load_varuint, location) }, @@ -989,15 +1013,15 @@ location = load_location NumberedReferenceReadNode.new(load_varuint, location) }, -> { location = load_location - OptionalKeywordParameterNode.new(load_required_constant, load_location, load_node, location) + OptionalKeywordParameterNode.new(load_varuint, load_required_constant, load_location, load_node, location) }, -> { location = load_location - OptionalParameterNode.new(load_required_constant, load_location, load_location, load_node, location) + OptionalParameterNode.new(load_varuint, load_required_constant, load_location, load_location, load_node, location) }, -> { location = load_location OrNode.new(load_node, load_node, load_location, location) }, @@ -1045,15 +1069,15 @@ location = load_location RegularExpressionNode.new(load_varuint, load_location, load_location, load_location, load_string, location) }, -> { location = load_location - RequiredKeywordParameterNode.new(load_required_constant, load_location, location) + RequiredKeywordParameterNode.new(load_varuint, load_required_constant, load_location, location) }, -> { location = load_location - RequiredParameterNode.new(load_required_constant, location) + RequiredParameterNode.new(load_varuint, load_required_constant, location) }, -> { location = load_location RescueModifierNode.new(load_node, load_location, load_node, location) }, @@ -1061,10 +1085,10 @@ location = load_location RescueNode.new(load_location, Array.new(load_varuint) { load_node }, load_optional_location, load_optional_node, load_optional_node, load_optional_node, location) }, -> { location = load_location - RestParameterNode.new(load_optional_constant, load_optional_location, load_location, location) + RestParameterNode.new(load_varuint, load_optional_constant, load_optional_location, load_location, location) }, -> { location = load_location RetryNode.new(location) },