2017-04-01 20:28:57 +02:00
|
|
|
module Vool
|
2017-04-12 19:29:45 +02:00
|
|
|
|
2019-08-16 19:39:08 +02:00
|
|
|
# Base class for assignments (local/ivar), works just as you'd expect
|
|
|
|
# Only "quirk" maybe, that arguments are like locals
|
|
|
|
#
|
|
|
|
# Only actual functionality here is the compile_assign_call which compiles
|
|
|
|
# the call, should the assigned value be a call.
|
2017-04-01 20:28:57 +02:00
|
|
|
class Assignment < Statement
|
2017-04-06 15:06:51 +02:00
|
|
|
attr_reader :name , :value
|
2017-04-02 11:59:07 +02:00
|
|
|
def initialize(name , value )
|
2019-08-13 18:32:17 +02:00
|
|
|
raise "Name nil #{self}" unless name
|
|
|
|
raise "Value nil #{self}" unless value
|
2019-08-15 20:30:36 +02:00
|
|
|
raise "Value cant be Assignment #{value}" if value.is_a?(Assignment)
|
|
|
|
raise "Value cant be Statements #{value}" if value.is_a?(Statements)
|
2017-04-02 11:59:07 +02:00
|
|
|
@name , @value = name , value
|
2017-04-01 20:28:57 +02:00
|
|
|
end
|
2018-03-15 06:54:14 +01:00
|
|
|
|
2018-03-15 16:03:38 +01:00
|
|
|
def each(&block)
|
|
|
|
block.call(self)
|
|
|
|
@value.each(&block)
|
2017-04-08 11:10:42 +02:00
|
|
|
end
|
2018-07-03 21:18:19 +02:00
|
|
|
|
|
|
|
def to_s(depth = 0)
|
|
|
|
at_depth(depth , "#{@name} = #{@value}")
|
|
|
|
end
|
|
|
|
|
2019-08-16 19:39:08 +02:00
|
|
|
# The assign instruction (a slot_load) is produced by delegating the slot to derived
|
|
|
|
# class
|
|
|
|
#
|
|
|
|
# When the right hand side is a CallStatement, it must be compiled, before the assign
|
|
|
|
# is executed
|
|
|
|
#
|
|
|
|
# Derived classes do not implement to_mom, only slot_position
|
|
|
|
def to_mom(compiler)
|
|
|
|
to = Mom::SlotDefinition.new(:message , self.slot_position(compiler))
|
|
|
|
from = @value.slot_definition(compiler)
|
|
|
|
assign = Mom::SlotLoad.new(self,to,from)
|
2018-07-30 19:11:52 +02:00
|
|
|
return assign unless @value.is_a?(CallStatement)
|
2018-07-20 19:06:14 +02:00
|
|
|
@value.to_mom(compiler) << assign
|
|
|
|
end
|
2017-04-01 20:28:57 +02:00
|
|
|
end
|
|
|
|
end
|