Skip to content

Commit 270ad20

Browse files
committed
Updates
* Update fixtures to handle invalid jumps * Update YARV to handle newer instructions * Update whitequark fixtures * Update dependencies and fix rubocop violations
1 parent 6642b40 commit 270ad20

25 files changed

+1527
-1295
lines changed

.rubocop.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ Style/KeywordParametersOrder:
136136
Style/MissingRespondToMissing:
137137
Enabled: false
138138

139+
Style/MultipleComparison:
140+
Enabled: false
141+
139142
Style/MutableConstant:
140143
Enabled: false
141144

@@ -157,6 +160,9 @@ Style/PerlBackrefs:
157160
Style/RedundantArrayConstructor:
158161
Enabled: false
159162

163+
Style/RedundantParentheses:
164+
Enabled: false
165+
160166
Style/SafeNavigation:
161167
Enabled: false
162168

.ruby-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

Gemfile.lock

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,46 @@ PATH
77
GEM
88
remote: https://rubygems.org/
99
specs:
10-
ast (2.4.2)
11-
docile (1.4.0)
12-
json (2.6.3)
13-
language_server-protocol (3.17.0.3)
10+
ast (2.4.3)
11+
docile (1.4.1)
12+
json (2.12.2)
13+
language_server-protocol (3.17.0.5)
14+
lint_roller (1.1.0)
1415
minitest (5.25.5)
15-
parallel (1.23.0)
16-
parser (3.2.2.4)
16+
parallel (1.27.0)
17+
parser (3.3.8.0)
1718
ast (~> 2.4.1)
1819
racc
1920
prettier_print (1.2.1)
20-
racc (1.7.1)
21+
prism (1.4.0)
22+
racc (1.8.1)
2123
rainbow (3.1.1)
2224
rake (13.3.0)
23-
regexp_parser (2.8.2)
24-
rexml (3.2.6)
25-
rubocop (1.57.2)
25+
regexp_parser (2.10.0)
26+
rubocop (1.78.0)
2627
json (~> 2.3)
27-
language_server-protocol (>= 3.17.0)
28+
language_server-protocol (~> 3.17.0.2)
29+
lint_roller (~> 1.1.0)
2830
parallel (~> 1.10)
29-
parser (>= 3.2.2.4)
31+
parser (>= 3.3.0.2)
3032
rainbow (>= 2.2.2, < 4.0)
31-
regexp_parser (>= 1.8, < 3.0)
32-
rexml (>= 3.2.5, < 4.0)
33-
rubocop-ast (>= 1.28.1, < 2.0)
33+
regexp_parser (>= 2.9.3, < 3.0)
34+
rubocop-ast (>= 1.45.1, < 2.0)
3435
ruby-progressbar (~> 1.7)
35-
unicode-display_width (>= 2.4.0, < 3.0)
36-
rubocop-ast (1.30.0)
37-
parser (>= 3.2.1.0)
36+
unicode-display_width (>= 2.4.0, < 4.0)
37+
rubocop-ast (1.45.1)
38+
parser (>= 3.3.7.2)
39+
prism (~> 1.4)
3840
ruby-progressbar (1.13.0)
3941
simplecov (0.22.0)
4042
docile (~> 1.1)
4143
simplecov-html (~> 0.11)
4244
simplecov_json_formatter (~> 0.1)
43-
simplecov-html (0.12.3)
45+
simplecov-html (0.13.1)
4446
simplecov_json_formatter (0.1.4)
45-
unicode-display_width (2.5.0)
47+
unicode-display_width (3.1.4)
48+
unicode-emoji (~> 4.0, >= 4.0.4)
49+
unicode-emoji (4.0.4)
4650

4751
PLATFORMS
4852
arm64-darwin-21

lib/syntax_tree/cli.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class CTags < Action
159159
attr_reader :entries
160160

161161
def initialize(options)
162-
super(options)
162+
super
163163
@entries = []
164164
end
165165

lib/syntax_tree/pattern.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def compile
7070
raise CompilationError, query
7171
end
7272

73+
raise CompilationError, query if program.nil?
7374
compile_node(program.statements.body.first.consequent.pattern)
7475
end
7576

lib/syntax_tree/yarv/assembler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def assemble_iseq(iseq, lines)
408408
def find_local(iseq, operands)
409409
name_string, level_string = operands.split(/,\s*/)
410410
name = name_string.to_sym
411-
level = level_string&.to_i || 0
411+
level = level_string.to_i
412412

413413
iseq.local_table.plain(name)
414414
iseq.local_table.find(name, level)
@@ -455,7 +455,7 @@ def parse_calldata(value)
455455
CallData::CALL_ARGS_SIMPLE
456456
end
457457

458-
YARV.calldata(message.to_sym, argc_value&.to_i || 0, flags)
458+
YARV.calldata(message.to_sym, argc_value.to_i, flags)
459459
end
460460
end
461461
end

lib/syntax_tree/yarv/calldata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def initialize(
4141
end
4242

4343
def flag?(mask)
44-
(flags & mask) > 0
44+
flags.anybits?(mask)
4545
end
4646

4747
def to_h

lib/syntax_tree/yarv/decompiler.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def node_for(value)
4545
when Integer
4646
Int(value.to_s)
4747
when Symbol
48-
SymbolLiteral(Ident(value.to_s))
48+
SymbolLiteral(Ident(value.name))
4949
end
5050
end
5151

@@ -88,10 +88,10 @@ def decompile(iseq)
8888

8989
clause << HashLiteral(LBrace("{"), assocs)
9090
when GetGlobal
91-
clause << VarRef(GVar(insn.name.to_s))
91+
clause << VarRef(GVar(insn.name.name))
9292
when GetLocalWC0
9393
local = iseq.local_table.locals[insn.index]
94-
clause << VarRef(Ident(local.name.to_s))
94+
clause << VarRef(Ident(local.name.name))
9595
when Jump
9696
clause << Assign(block_label.field, node_for(insn.label.name))
9797
clause << Next(Args([]))
@@ -123,7 +123,7 @@ def decompile(iseq)
123123
left, right = clause.pop(2)
124124
clause << Binary(left, :"!=", right)
125125
when OptSendWithoutBlock
126-
method = insn.calldata.method.to_s
126+
method = insn.calldata.method.name
127127
argc = insn.calldata.argc
128128

129129
if insn.calldata.flag?(CallData::CALL_FCALL)
@@ -182,7 +182,7 @@ def decompile(iseq)
182182
when PutSelf
183183
clause << VarRef(Kw("self"))
184184
when SetGlobal
185-
target = GVar(insn.name.to_s)
185+
target = GVar(insn.name.name)
186186
value = clause.pop
187187

188188
clause << if value.is_a?(Binary) && VarRef(target) === value.left
@@ -256,7 +256,7 @@ def decompile(iseq)
256256
def local_name(index, level)
257257
current = iseq
258258
level.times { current = current.parent_iseq }
259-
current.local_table.locals[index].name.to_s
259+
current.local_table.locals[index].name.name
260260
end
261261
end
262262
end

lib/syntax_tree/yarv/instruction_sequence.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ def to_a
263263
local_size: local_table.size,
264264
stack_max: stack.maximum_size,
265265
node_id: -1,
266-
node_ids: [-1] * insns.length
266+
node_ids: [-1] * insns.length,
267+
parser: :prism
267268
},
268269
name,
269270
file,
@@ -689,6 +690,10 @@ def concatstrings(number)
689690
push(ConcatStrings.new(number))
690691
end
691692

693+
def concattoarray(object)
694+
push(ConcatToArray.new(object))
695+
end
696+
692697
def defineclass(name, class_iseq, flags)
693698
push(DefineClass.new(name, class_iseq, flags))
694699
end
@@ -897,6 +902,14 @@ def pop
897902
push(Pop.new)
898903
end
899904

905+
def pushtoarraykwsplat
906+
push(PushToArrayKwSplat.new)
907+
end
908+
909+
def putchilledstring(object)
910+
push(PutChilledString.new(object))
911+
end
912+
900913
def putnil
901914
push(PutNil.new)
902915
end
@@ -1079,6 +1092,8 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
10791092
iseq.concatarray
10801093
when :concatstrings
10811094
iseq.concatstrings(opnds[0])
1095+
when :concattoarray
1096+
iseq.concattoarray(opnds[0])
10821097
when :defineclass
10831098
iseq.defineclass(opnds[0], from(opnds[1], options, iseq), opnds[2])
10841099
when :defined
@@ -1191,8 +1206,13 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
11911206
iseq.newarray(opnds[0])
11921207
iseq.send(YARV.calldata(:min))
11931208
when :opt_newarray_send
1209+
mid = opnds[1]
1210+
if RUBY_VERSION >= "3.4"
1211+
mid = %i[max min hash pack pack_buffer include?][mid - 1]
1212+
end
1213+
11941214
iseq.newarray(opnds[0])
1195-
iseq.send(CallData.new(opnds[1]))
1215+
iseq.send(CallData.new(mid))
11961216
when :opt_neq
11971217
iseq.push(
11981218
OptNEq.new(CallData.from(opnds[0]), CallData.from(opnds[1]))
@@ -1207,6 +1227,10 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
12071227
iseq.send(YARV.calldata(:-@))
12081228
when :pop
12091229
iseq.pop
1230+
when :pushtoarraykwsplat
1231+
iseq.pushtoarraykwsplat
1232+
when :putchilledstring
1233+
iseq.putchilledstring(opnds[0])
12101234
when :putnil
12111235
iseq.putnil
12121236
when :putobject

0 commit comments

Comments
 (0)