2017-04-01 21:28:57 +03:00
|
|
|
module Vool
|
2017-04-12 20:29:45 +03:00
|
|
|
|
2017-04-01 21:28:57 +03:00
|
|
|
class Assignment < Statement
|
2017-04-06 16:06:51 +03:00
|
|
|
attr_reader :name , :value
|
2017-04-02 12:59:07 +03:00
|
|
|
def initialize(name , value )
|
|
|
|
@name , @value = name , value
|
2017-04-01 21:28:57 +03:00
|
|
|
end
|
2018-03-15 11:24:14 +05:30
|
|
|
|
|
|
|
def normalize()
|
2018-03-15 12:46:56 +05:30
|
|
|
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)
|
2018-03-15 11:24:14 +05:30
|
|
|
end
|
|
|
|
|
2018-03-15 20:33:38 +05:30
|
|
|
def chain_assign(assign , method)
|
|
|
|
return assign unless @value.is_a?(SendStatement)
|
2018-03-16 12:33:11 +05:30
|
|
|
@value.to_mom(method) << assign
|
2018-03-15 20:33:38 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def each(&block)
|
|
|
|
block.call(self)
|
|
|
|
@value.each(&block)
|
2017-04-08 12:10:42 +03:00
|
|
|
end
|
2017-04-01 21:28:57 +03:00
|
|
|
end
|
2017-04-12 14:45:02 +03:00
|
|
|
|
2017-04-12 20:29:45 +03:00
|
|
|
class IvarAssignment < Assignment
|
2018-03-15 20:33:38 +05:30
|
|
|
|
|
|
|
def normalize()
|
|
|
|
super()
|
|
|
|
return IvarAssignment.new(@name , @value)
|
2017-04-08 12:18:10 +03:00
|
|
|
end
|
2017-04-12 20:29:45 +03:00
|
|
|
|
|
|
|
def to_mom( method )
|
2018-03-15 20:33:38 +05:30
|
|
|
to = Mom::SlotDefinition.new(:message ,[ :receiver , @name])
|
|
|
|
from = @value.slot_definition(method)
|
|
|
|
return chain_assign( Mom::SlotLoad.new(to,from) , method)
|
2017-04-12 20:29:45 +03:00
|
|
|
end
|
|
|
|
|
2017-04-04 18:10:28 +03:00
|
|
|
end
|
2017-04-01 21:28:57 +03:00
|
|
|
end
|