2018-07-09 15:48:23 +02:00
|
|
|
module Risc
|
|
|
|
|
|
|
|
# A BlockCompiler is much like a Mehtodcompiler, exept for blocks
|
|
|
|
#
|
2018-07-10 21:03:32 +02:00
|
|
|
class BlockCompiler < CallableCompiler
|
2018-07-09 15:48:23 +02:00
|
|
|
|
|
|
|
attr_reader :block , :risc_instructions , :constants
|
|
|
|
|
|
|
|
def initialize( block , method)
|
|
|
|
@method = method
|
|
|
|
@block = block
|
2018-07-10 21:03:32 +02:00
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
|
|
|
def source_name
|
|
|
|
"#{@method.self_type.name}.init"
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
|
2018-07-09 16:53:56 +02:00
|
|
|
# determine how given name need to be accsessed.
|
|
|
|
# For blocks the options are args or frame
|
|
|
|
# or then the methods arg or frame
|
|
|
|
def slot_type_for(name)
|
|
|
|
if @block.arguments_type.variable_index(name)
|
2018-07-16 11:03:40 +02:00
|
|
|
slot_def = [:arguments]
|
2018-07-09 16:53:56 +02:00
|
|
|
elsif @block.frame_type.variable_index(name)
|
|
|
|
slot_def = [:frame]
|
|
|
|
elsif @method.arguments_type.variable_index(name)
|
|
|
|
slot_def = [:caller , :arguments ]
|
|
|
|
elsif @method.arguments_type.variable_index(name)
|
|
|
|
slot_def = [:caller , :frame ]
|
|
|
|
elsif
|
|
|
|
raise "no variable #{name} , need to resolve at runtime"
|
|
|
|
end
|
|
|
|
slot_def << name
|
|
|
|
end
|
|
|
|
|
2018-07-16 11:03:40 +02:00
|
|
|
# return the frame type, ie the blocks frame type
|
|
|
|
def frame_type
|
|
|
|
@block.frame_type
|
|
|
|
end
|
|
|
|
# return the frame type, ie the blocks arguments type
|
|
|
|
def arg_type
|
|
|
|
@block.arguments_type
|
|
|
|
end
|
|
|
|
# return the frame type, ie the blocks self_type
|
|
|
|
def receiver_type
|
|
|
|
@block.self_type
|
2018-07-10 21:03:32 +02:00
|
|
|
end
|
|
|
|
|
2018-07-09 15:48:23 +02:00
|
|
|
end
|
|
|
|
end
|