4ac89ece66
slot_type_for to return the slot way to access variable this is off course version 0.0.1 alpha, no types are checked or errors handled
40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
module Risc
|
|
|
|
# A BlockCompiler is much like a Mehtodcompiler, exept for blocks
|
|
#
|
|
class BlockCompiler
|
|
|
|
attr_reader :block , :risc_instructions , :constants
|
|
|
|
def initialize( block , method)
|
|
@method = method
|
|
@regs = []
|
|
@block = block
|
|
name = "#{method.self_type.name}.init"
|
|
@risc_instructions = Risc.label(name, name)
|
|
@risc_instructions << Risc.label( name, "unreachable")
|
|
@current = @risc_instructions
|
|
@constants = []
|
|
end
|
|
|
|
# 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)
|
|
slot_def = [ :arguments]
|
|
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
|
|
|
|
end
|
|
end
|