Redoing ruby block conversion

Since the block is actually a constant, it does not need assignment or special hoisting
Just use the send and stick the lambda in as last arg
This commit is contained in:
2019-08-19 14:23:55 +03:00
parent f87526f86f
commit 3ddf2e3837
7 changed files with 37 additions and 72 deletions

View File

@ -11,26 +11,13 @@ module Ruby
case value
when Variable , Constant
return self.vool_brother.new(name,@value.to_vool)
when SendStatement , YieldStatement
when SendStatement , YieldStatement , RubyBlockStatement
return normalize_send
when RubyBlockStatement
return normalize_block
else
raise "unsupported right #{value}"
end
end
# Ruby BlockStatements have the block and the send. Normalize the send
# and assign it (it is the last in the list)
def normalize_block
statements = value.to_vool
index = statements.length - 1
snd = statements.statements[index]
raise "Expecting Send #{snd.class}:#{snd}" unless snd.is_a?( Vool::SendStatement)
statements.statements[index] = assignment( snd )
statements
end
# sends may have complex args that get hoisted in vool:ing them
# in which case we have to assign the simplified, otherwise the
# plain send