start a new ruby layer to do the to_vool conversion
the "normalization" is getting more and more complicated and is not tested And it seems i really don't like working with the untyped ast
This commit is contained in:
39
lib/ruby/send_statement.rb
Normal file
39
lib/ruby/send_statement.rb
Normal file
@ -0,0 +1,39 @@
|
||||
module Ruby
|
||||
|
||||
class SendStatement < Statement
|
||||
attr_reader :name , :receiver , :arguments
|
||||
|
||||
def initialize(name , receiver , arguments )
|
||||
@name , @receiver , @arguments = name , receiver , arguments
|
||||
@arguments ||= []
|
||||
end
|
||||
|
||||
def normalize
|
||||
statements = Statements.new([])
|
||||
arguments = []
|
||||
@arguments.each_with_index do |arg , index |
|
||||
normalize_arg(arg , arguments , statements)
|
||||
end
|
||||
if statements.empty?
|
||||
return SendStatement.new(@name, @receiver , @arguments)
|
||||
else
|
||||
statements << SendStatement.new(@name, @receiver , arguments)
|
||||
return statements
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_arg(arg , arguments , statements)
|
||||
if arg.respond_to?(:slot_definition) and !arg.is_a?(SendStatement)
|
||||
arguments << arg
|
||||
return
|
||||
end
|
||||
assign = LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg)
|
||||
statements << assign
|
||||
arguments << LocalVariable.new(assign.name)
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{receiver}.#{name}(#{arguments.join(', ')})"
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user