Skip to content

Commit 07dad4d

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 07dad4d

26 files changed

+1545
-1301
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
- '3.0'
1515
- '3.1'
1616
- '3.2'
17+
- '3.3'
18+
- '3.4'
1719
- head
1820
- truffleruby-head
1921
name: CI

.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: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,19 +252,23 @@ def to_a
252252
dumped_options = argument_options.dup
253253
dumped_options[:opt].map!(&:name) if dumped_options[:opt]
254254

255+
metadata = {
256+
arg_size: argument_size,
257+
local_size: local_table.size,
258+
stack_max: stack.maximum_size,
259+
node_id: -1,
260+
node_ids: [-1] * insns.length
261+
}
262+
263+
metadata[:parser] = :prism if RUBY_VERSION >= "3.3"
264+
255265
# Next, return the instruction sequence as an array.
256266
[
257267
MAGIC,
258268
versions[0],
259269
versions[1],
260270
1,
261-
{
262-
arg_size: argument_size,
263-
local_size: local_table.size,
264-
stack_max: stack.maximum_size,
265-
node_id: -1,
266-
node_ids: [-1] * insns.length
267-
},
271+
metadata,
268272
name,
269273
file,
270274
"<compiled>",
@@ -689,6 +693,10 @@ def concatstrings(number)
689693
push(ConcatStrings.new(number))
690694
end
691695

696+
def concattoarray(object)
697+
push(ConcatToArray.new(object))
698+
end
699+
692700
def defineclass(name, class_iseq, flags)
693701
push(DefineClass.new(name, class_iseq, flags))
694702
end
@@ -897,6 +905,14 @@ def pop
897905
push(Pop.new)
898906
end
899907

908+
def pushtoarraykwsplat
909+
push(PushToArrayKwSplat.new)
910+
end
911+
912+
def putchilledstring(object)
913+
push(PutChilledString.new(object))
914+
end
915+
900916
def putnil
901917
push(PutNil.new)
902918
end
@@ -1079,6 +1095,8 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
10791095
iseq.concatarray
10801096
when :concatstrings
10811097
iseq.concatstrings(opnds[0])
1098+
when :concattoarray
1099+
iseq.concattoarray(opnds[0])
10821100
when :defineclass
10831101
iseq.defineclass(opnds[0], from(opnds[1], options, iseq), opnds[2])
10841102
when :defined
@@ -1191,8 +1209,13 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
11911209
iseq.newarray(opnds[0])
11921210
iseq.send(YARV.calldata(:min))
11931211
when :opt_newarray_send
1212+
mid = opnds[1]
1213+
if RUBY_VERSION >= "3.4"
1214+
mid = %i[max min hash pack pack_buffer include?][mid - 1]
1215+
end
1216+
11941217
iseq.newarray(opnds[0])
1195-
iseq.send(CallData.new(opnds[1]))
1218+
iseq.send(CallData.new(mid))
11961219
when :opt_neq
11971220
iseq.push(
11981221
OptNEq.new(CallData.from(opnds[0]), CallData.from(opnds[1]))
@@ -1207,6 +1230,10 @@ def self.from(source, options = Compiler::Options.new, parent_iseq = nil)
12071230
iseq.send(YARV.calldata(:-@))
12081231
when :pop
12091232
iseq.pop
1233+
when :pushtoarraykwsplat
1234+
iseq.pushtoarraykwsplat
1235+
when :putchilledstring
1236+
iseq.putchilledstring(opnds[0])
12101237
when :putnil
12111238
iseq.putnil
12121239
when :putobject

0 commit comments

Comments
 (0)