Skip to content

Commit 9f9be75

Browse files
committed
Update yarv compiler and decompiler to stop using Elsif node
1 parent 4e88d83 commit 9f9be75

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

Diff for: lib/syntax_tree/yarv/compiler.rb

+6-16
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ def visit_array(node)
382382
if (compiled = RubyVisitor.compile(node))
383383
iseq.duparray(compiled)
384384
elsif node.contents && node.contents.parts.length == 1 &&
385-
node.contents.parts.first.is_a?(BareAssocHash) &&
386-
node.contents.parts.first.assocs.length == 1 &&
387-
node.contents.parts.first.assocs.first.is_a?(AssocSplat)
385+
node.contents.parts.first.is_a?(BareAssocHash) &&
386+
node.contents.parts.first.assocs.length == 1 &&
387+
node.contents.parts.first.assocs.first.is_a?(AssocSplat)
388388
iseq.putspecialobject(PutSpecialObject::OBJECT_VMCORE)
389389
iseq.newhash(0)
390390
visit(node.contents.parts.first)
@@ -911,17 +911,6 @@ def visit_else(node)
911911
iseq.pop unless last_statement?
912912
end
913913

914-
def visit_elsif(node)
915-
visit_if(
916-
IfNode.new(
917-
predicate: node.predicate,
918-
statements: node.statements,
919-
consequent: node.consequent,
920-
location: node.location
921-
)
922-
)
923-
end
924-
925914
def visit_ensure(node)
926915
end
927916

@@ -1062,7 +1051,8 @@ def visit_if_op(node)
10621051
),
10631052
location: Location.default
10641053
),
1065-
location: Location.default
1054+
location: Location.default,
1055+
beginning: "if"
10661056
)
10671057
)
10681058
end
@@ -1218,7 +1208,7 @@ def visit_opassign(node)
12181208
iseq.swap
12191209
iseq.pop
12201210
elsif node.target.is_a?(VarField) &&
1221-
[Const, CVar, GVar].include?(node.target.value.class)
1211+
[Const, CVar, GVar].include?(node.target.value.class)
12221212
opassign_defined(node)
12231213
else
12241214
skip_value_label = iseq.label

Diff for: lib/syntax_tree/yarv/decompiler.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def decompile(iseq)
7777
Next(Args([]))
7878
]
7979

80-
clause << IfNode(clause.pop, Statements(body), nil)
80+
clause << IfNode(clause.pop, Statements(body), nil, "if")
8181
when Dup
8282
clause << clause.last
8383
when DupHash

0 commit comments

Comments
 (0)