bring the blocks down to mom level

reusing message_setup, but adding yield specific instructions
This commit is contained in:
Torsten Ruger
2018-07-24 11:35:49 +03:00
parent d80ef4bf4e
commit f5c284b3a0
10 changed files with 131 additions and 36 deletions

View File

@ -0,0 +1,31 @@
module Mom
# A BlockYield calls an argument block. All we need to know is the index
# of the argument, and the rest is almost as simple as a SimpleCall
class BlockYield < Instruction
attr :arg_index
def initialize(index)
@arg_index = index
end
def to_s
"BlockYield[#{arg_index}] "
end
def to_risc(compiler)
block = compiler.use_reg( :Block )
return_label = Risc.label(self, "continue_#{object_id}")
save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self)
moves = save_return.to_risc(compiler)
moves << Risc.slot_to_reg( self , Risc.message_reg ,:arguments , block)
moves << Risc.slot_to_reg( self , block ,arg_index , block)
moves << Risc.slot_to_reg(self, Risc.message_reg , :next_message , Risc.message_reg)
moves << Risc::DynamicJump.new(self, block )
moves << return_label
end
end
end

View File

@ -32,6 +32,7 @@ require_relative "check"
require_relative "basic_values"
require_relative "simple_call"
require_relative "dynamic_call"
require_relative "block_yield"
require_relative "resolve_method"
require_relative "truth_check"
require_relative "not_same_check"

View File

@ -42,8 +42,13 @@ module Mom
cache_entry << from
callable_method << cache_entry[:cached_method]
end
when Integer
builder.build do
arguments << message[:arguments]
callable_method << arguments[ from ]
end
else
raise "unknown source #{method_source}"
raise "unknown source #{method_source.class}:#{method_source}"
end
build_message_data(builder)
return builder.built