Fix forgotten block compiler
Especially on the way down to risc
This commit is contained in:
@ -4,7 +4,7 @@ module Mom
|
||||
#
|
||||
class BlockCompiler < CallableCompiler
|
||||
|
||||
attr_reader :block , :risc_instructions , :constants
|
||||
attr_reader :block , :mom_instructions
|
||||
alias :block :callable
|
||||
|
||||
def initialize( block , method)
|
||||
@ -16,6 +16,13 @@ module Mom
|
||||
"#{@method.self_type.name}.init"
|
||||
end
|
||||
|
||||
def to_risc(in_method)
|
||||
risc_compiler = Risc::BlockCompiler.new(@callable , in_method , mom_instructions)
|
||||
instructions_to_risc(risc_compiler)
|
||||
#recursive blocks not done
|
||||
risc_compiler
|
||||
end
|
||||
|
||||
# resolve the type of the slot, by inferring from it's name, using the type
|
||||
# scope related slots are resolved by the compiler by method/block
|
||||
#
|
||||
|
@ -84,5 +84,21 @@ module Mom
|
||||
@callable.self_type
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# convert al instruction to risc
|
||||
# method is called by Method/BlockCompiler from to_risc
|
||||
def instructions_to_risc(risc_compiler)
|
||||
instruction = mom_instructions.next
|
||||
while( instruction )
|
||||
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction)
|
||||
#puts "adding mom #{instruction.to_s}:#{instruction.next.to_s}"
|
||||
instruction.to_risc( risc_compiler )
|
||||
risc_compiler.reset_regs
|
||||
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}"
|
||||
instruction = instruction.next
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -4,16 +4,12 @@ module Mom
|
||||
# and to instantiate the methods correctly.
|
||||
|
||||
class MethodCompiler < CallableCompiler
|
||||
alias :callable :method
|
||||
|
||||
def initialize( method )
|
||||
super(method)
|
||||
end
|
||||
|
||||
#include block_compilers constants
|
||||
def constants
|
||||
block_compilers.inject(@constants.dup){|all, compiler| all += compiler.constants}
|
||||
end
|
||||
|
||||
def source_name
|
||||
"#{@callable.self_type.name}.#{@callable.name}"
|
||||
end
|
||||
@ -27,19 +23,16 @@ module Mom
|
||||
@callable
|
||||
end
|
||||
|
||||
# drop down to risc
|
||||
# drop down to risc by converting this compilers instructions to risc.
|
||||
# and the doing the same for any block_compilers
|
||||
def to_risc
|
||||
risc_comp = Risc::MethodCompiler.new(@callable , mom_instructions)
|
||||
instruction = mom_instructions.next
|
||||
while( instruction )
|
||||
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction)
|
||||
#puts "adding mom #{instruction.to_s}:#{instruction.next.to_s}"
|
||||
instruction.to_risc( risc_comp )
|
||||
risc_comp.reset_regs
|
||||
#puts "adding risc #{risc.to_s}:#{risc.next.to_s}"
|
||||
instruction = instruction.next
|
||||
risc_compiler = Risc::MethodCompiler.new(@callable , mom_instructions)
|
||||
instructions_to_risc(risc_compiler)
|
||||
block_compilers.each do |m_comp|
|
||||
puts "BLOCK #{m_comp}"
|
||||
risc_compiler.block_compilers << m_comp.to_risc(@callable)
|
||||
end
|
||||
risc_comp
|
||||
risc_compiler
|
||||
end
|
||||
|
||||
# helper method for builtin mainly
|
||||
|
@ -26,11 +26,6 @@ module Mom
|
||||
@method_compilers + boot_compilers
|
||||
end
|
||||
|
||||
# collects constants from all compilers into one array
|
||||
def constants
|
||||
compilers.inject([]){|sum ,comp| sum + comp.constants }
|
||||
end
|
||||
|
||||
# Append another MomCompilers method_compilers to this one.
|
||||
def append(mom_compiler)
|
||||
@method_compilers += mom_compiler.method_compilers
|
||||
|
@ -4,16 +4,15 @@ module Risc
|
||||
#
|
||||
class BlockCompiler < CallableCompiler
|
||||
|
||||
attr_reader :block , :risc_instructions , :constants
|
||||
alias :block :callable
|
||||
attr_reader :block , :risc_instructions , :constants , :in_method
|
||||
|
||||
def initialize( block , method)
|
||||
@method = method
|
||||
super(block)
|
||||
def initialize( block , in_method , mom_label)
|
||||
@in_method = in_method
|
||||
super(block , mom_label)
|
||||
end
|
||||
|
||||
def source_name
|
||||
"#{@method.self_type.name}.init"
|
||||
"#{@in_method.self_type.name}.init"
|
||||
end
|
||||
|
||||
# resolve the type of the slot, by inferring from it's name, using the type
|
||||
@ -24,9 +23,9 @@ module Risc
|
||||
def slot_type( slot , type)
|
||||
new_type = super
|
||||
if slot == :caller
|
||||
extra_info = { type_frame: @method.frame_type ,
|
||||
type_arguments: @method.arguments_type ,
|
||||
type_self: @method.self_type}
|
||||
extra_info = { type_frame: @in_method.frame_type ,
|
||||
type_arguments: @in_method.arguments_type ,
|
||||
type_self: @in_method.self_type}
|
||||
end
|
||||
return new_type , extra_info
|
||||
end
|
||||
@ -38,9 +37,9 @@ module Risc
|
||||
slot_def = [:arguments]
|
||||
elsif @callable.frame_type.variable_index(name)
|
||||
slot_def = [:frame]
|
||||
elsif @method.arguments_type.variable_index(name)
|
||||
elsif @in_method.arguments_type.variable_index(name)
|
||||
slot_def = [:caller , :caller ,:arguments ]
|
||||
elsif @method.frame_type.variable_index(name)
|
||||
elsif @in_method.frame_type.variable_index(name)
|
||||
slot_def = [:caller ,:caller , :frame ]
|
||||
elsif
|
||||
raise "no variable #{name} , need to resolve at runtime"
|
||||
|
@ -30,7 +30,6 @@ module Risc
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# add a constant (which get created during compilation and need to be linked)
|
||||
def add_constant(const)
|
||||
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
||||
|
@ -51,9 +51,9 @@ module RubyX
|
||||
#
|
||||
# After creating vool, we call to_target
|
||||
# Return a Linker
|
||||
def ruby_to_target(ruby)
|
||||
def ruby_to_target(ruby , platform)
|
||||
ruby_to_vool(ruby)
|
||||
to_target()
|
||||
to_target( platform )
|
||||
end
|
||||
|
||||
# ruby_to_risc creates Risc instructions
|
||||
|
@ -3,6 +3,8 @@ module Vool
|
||||
class Assignment < Statement
|
||||
attr_reader :name , :value
|
||||
def initialize(name , value )
|
||||
raise "Name nil #{self}" unless name
|
||||
raise "Value nil #{self}" unless value
|
||||
@name , @value = name , value
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user