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
|
||||
|
Reference in New Issue
Block a user