return works
This commit is contained in:
@ -10,7 +10,7 @@ module Vool
|
||||
if( condition.is_a?(ScopeStatement) and condition.single?)
|
||||
condition = condition.first
|
||||
end
|
||||
return [condition] if condition.is_a?(Named)
|
||||
return [condition] if condition.respond_to?(:slot_definition)
|
||||
condition = condition.normalize
|
||||
local = "tmp_#{object_id}"
|
||||
assign = Statements.new [LocalAssignment.new( local , condition)]
|
||||
|
@ -1,24 +1,32 @@
|
||||
module Vool
|
||||
class ReturnStatement < Statement
|
||||
include Normalizer
|
||||
|
||||
attr_reader :return_value
|
||||
|
||||
def initialize(value)
|
||||
@return_value = value
|
||||
end
|
||||
|
||||
def collect(arr)
|
||||
@return_value.collect(arr)
|
||||
super
|
||||
def normalize
|
||||
val , rest = *normalize_name(@return_value)
|
||||
me = ReturnStatement.new(val)
|
||||
return me unless rest
|
||||
rest << me
|
||||
rest
|
||||
end
|
||||
|
||||
# To return form a method in mom instructions we need to do two things:
|
||||
# - store the given return value, this is a SlotMove / SlotConstant
|
||||
def each(&block)
|
||||
block.call(@return_value)
|
||||
end
|
||||
|
||||
# Since the return is normalized to only allow simple values it is simple.
|
||||
# To return form a method in mom instructions we only need to do two things:
|
||||
# - store the given return value, this is a SlotMove
|
||||
# - activate return sequence (reinstantiate old message and jump to return address)
|
||||
def to_mom( method )
|
||||
statements = @return_value.to_mom(method)
|
||||
statements << @return_value.slot_class.new( [:message , :return_value] , @return_value.slot_definition )
|
||||
statements << Mom::ReturnSequence.new
|
||||
return statements
|
||||
ret = Mom::SlotLoad.new( [:message , :return_value] , @return_value.slot_definition(method) )
|
||||
ret << Mom::ReturnSequence.new
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user