rubyx/lib/vool/statements/assign_statement.rb
Torsten Ruger 35a0952943 first while test working
fixed logic error in test framework
2018-03-16 12:33:11 +05:30

41 lines
964 B
Ruby

module Vool
class Assignment < Statement
attr_reader :name , :value
def initialize(name , value )
@name , @value = name , value
end
def normalize()
raise "not named left #{name.class}" unless @name.is_a?(Symbol)
raise "unsupported right #{value}" unless @value.is_a?(Named) or
@value.is_a?(SendStatement) or @value.is_a?(Constant)
end
def chain_assign(assign , method)
return assign unless @value.is_a?(SendStatement)
@value.to_mom(method) << assign
end
def each(&block)
block.call(self)
@value.each(&block)
end
end
class IvarAssignment < Assignment
def normalize()
super()
return IvarAssignment.new(@name , @value)
end
def to_mom( method )
to = Mom::SlotDefinition.new(:message ,[ :receiver , @name])
from = @value.slot_definition(method)
return chain_assign( Mom::SlotLoad.new(to,from) , method)
end
end
end