rubyx/lib/risc/block_compiler.rb
Torsten Ruger 4ac89ece66 start delegating scope matters to the compiler(s)
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
2018-07-09 17:53:56 +03:00

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