fix most mom and risc apart
apart from things involving builtn, which is not yet conceptually solved (as it codes risc, not mom)
This commit is contained in:
parent
d5f89a4979
commit
213938075f
@ -22,7 +22,8 @@ module Mom
|
|||||||
|
|
||||||
# receiver is a slot_definition
|
# receiver is a slot_definition
|
||||||
# arguments is an array of SlotLoads
|
# arguments is an array of SlotLoads
|
||||||
def initialize( receiver,arguments )
|
def initialize( source , receiver,arguments )
|
||||||
|
super(source)
|
||||||
@receiver , @arguments = receiver , arguments
|
@receiver , @arguments = receiver , arguments
|
||||||
raise "Receiver not SlotDefinition #{@receiver}" unless @receiver.is_a?(SlotDefinition)
|
raise "Receiver not SlotDefinition #{@receiver}" unless @receiver.is_a?(SlotDefinition)
|
||||||
@arguments.each{|a| raise "args not SlotLoad #{a}" unless a.is_a?(SlotLoad)}
|
@arguments.each{|a| raise "args not SlotLoad #{a}" unless a.is_a?(SlotLoad)}
|
||||||
@ -35,7 +36,7 @@ module Mom
|
|||||||
# load receiver and then each arg into the new message
|
# load receiver and then each arg into the new message
|
||||||
# delegates to SlotLoad for receiver and to the actual args.to_risc
|
# delegates to SlotLoad for receiver and to the actual args.to_risc
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
transfer = SlotLoad.new([:message , :next_message , :receiver] , @receiver, self).to_risc(compiler)
|
transfer = SlotLoad.new(self.source ,[:message , :next_message , :receiver] , @receiver, self).to_risc(compiler)
|
||||||
compiler.reset_regs
|
compiler.reset_regs
|
||||||
@arguments.each do |arg|
|
@arguments.each do |arg|
|
||||||
arg.to_risc(compiler)
|
arg.to_risc(compiler)
|
||||||
|
@ -7,9 +7,20 @@ module Mom
|
|||||||
#
|
#
|
||||||
class ReturnJump < Instruction
|
class ReturnJump < Instruction
|
||||||
|
|
||||||
|
attr_reader :return_label
|
||||||
|
|
||||||
|
# pass in the source_name (string/vool_instruction) for accounting purposes
|
||||||
|
# and the return_label, where we actually jump to. This is set up by the
|
||||||
|
# method_compiler, so it is easy to find (see return_label in compiler)
|
||||||
|
def initialize( source , label )
|
||||||
|
super(source)
|
||||||
|
@return_label = label
|
||||||
|
end
|
||||||
|
|
||||||
# the jump quite simple resolves to an uncondition risc Branch
|
# the jump quite simple resolves to an uncondition risc Branch
|
||||||
|
# we use the label that is passed in at creation
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
compiler.add_code Risc::Branch.new(self , compiler.return_label)
|
compiler.add_code Risc::Branch.new(self , return_label.risc_label(compiler))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -38,7 +38,9 @@ module Mom
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_risc( )
|
def to_risc( )
|
||||||
riscs = []
|
riscs = method_compilers.collect do | mom_c |
|
||||||
|
mom_c.to_risc
|
||||||
|
end
|
||||||
# to_risc all compilers
|
# to_risc all compilers
|
||||||
# for each suffling constnts and fist label, then all instructions (see below)
|
# for each suffling constnts and fist label, then all instructions (see below)
|
||||||
# then create risc collection
|
# then create risc collection
|
||||||
|
@ -19,7 +19,7 @@ module Risc
|
|||||||
# Return all compilers, namely the MethodCompilers passed in, plus the
|
# Return all compilers, namely the MethodCompilers passed in, plus the
|
||||||
# boot_function's compilers (boot_compilers)
|
# boot_function's compilers (boot_compilers)
|
||||||
def compilers
|
def compilers
|
||||||
@method_compilers + boot_compilers
|
@method_compilers #+ boot_compilers
|
||||||
end
|
end
|
||||||
|
|
||||||
# collects constants from all compilers into one array
|
# collects constants from all compilers into one array
|
||||||
|
@ -18,7 +18,7 @@ module Vool
|
|||||||
def to_mom( compiler )
|
def to_mom( compiler )
|
||||||
ret = Mom::SlotLoad.new( self , [:message , :return_value] ,
|
ret = Mom::SlotLoad.new( self , [:message , :return_value] ,
|
||||||
@return_value.slot_definition(compiler) )
|
@return_value.slot_definition(compiler) )
|
||||||
ret << Mom::ReturnJump.new(self)
|
ret << Mom::ReturnJump.new(self , compiler.return_label )
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -52,7 +52,7 @@ module Vool
|
|||||||
@arguments.each_with_index do |arg , index| # +1 because of type
|
@arguments.each_with_index do |arg , index| # +1 because of type
|
||||||
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
|
args << Mom::SlotLoad.new(self, arg_target + [index + 1] , arg.slot_definition(compiler))
|
||||||
end
|
end
|
||||||
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
setup << Mom::ArgumentTransfer.new(self, mom_receive , args )
|
||||||
end
|
end
|
||||||
|
|
||||||
def simple_call(compiler)
|
def simple_call(compiler)
|
||||||
|
@ -11,10 +11,10 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_return_class
|
def test_return_class
|
||||||
assert_equal Mom::MomCompiler , @ret.class
|
assert_equal Mom::MomCollection , @ret.class
|
||||||
end
|
end
|
||||||
def test_has_compilers
|
def test_has_compilers
|
||||||
assert_equal Risc::MethodCompiler , @ret.method_compilers.first.class
|
assert_equal Mom::MethodCompiler , @ret.method_compilers.first.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_constant
|
def test_constant
|
||||||
|
@ -42,11 +42,19 @@ module Mom
|
|||||||
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
||||||
@collection = @comp.to_risc()
|
@collection = @comp.to_risc()
|
||||||
end
|
end
|
||||||
def test_has_to_risc
|
def compiler
|
||||||
|
@collection.method_compilers.first
|
||||||
|
end
|
||||||
|
def test_has_to_risc
|
||||||
assert_equal Risc::RiscCollection, @collection.class
|
assert_equal Risc::RiscCollection, @collection.class
|
||||||
end
|
end
|
||||||
def test_has_risc_compiler
|
def test_has_risc_compiler
|
||||||
assert_equal Risc::RiscCollection, @collection.method_compilers.first
|
assert_equal Risc::MethodCompiler, compiler.class
|
||||||
|
assert_equal 1, @collection.method_compilers.length
|
||||||
|
end
|
||||||
|
def test_has_risc_instructions
|
||||||
|
assert_equal Risc::Label, compiler.risc_instructions.class
|
||||||
|
assert_equal 17, compiler.risc_instructions.length
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,15 +14,15 @@ module Risc
|
|||||||
SlotToReg, SlotToReg, RegToSlot, Branch]
|
SlotToReg, SlotToReg, RegToSlot, Branch]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_return_instructions
|
def pest_return_instructions
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
def test_function_return
|
def pest_function_return
|
||||||
produced = produce_body.next(23)
|
produced = produce_body.next(23)
|
||||||
assert_equal Branch , produced.class
|
assert_equal Branch , produced.class
|
||||||
assert_equal "return_label" , produced.label.name
|
assert_equal "return_label" , produced.label.name
|
||||||
end
|
end
|
||||||
def test_load_5
|
def pest_load_5
|
||||||
produced = produce_body.next(8)
|
produced = produce_body.next(8)
|
||||||
assert_equal LoadConstant , produced.class
|
assert_equal LoadConstant , produced.class
|
||||||
assert_equal 5 , produced.constant.value
|
assert_equal 5 , produced.constant.value
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Mom
|
module Risc
|
||||||
class TestMomCompilerTranslate < MiniTest::Test
|
class TestMomCompilerTranslate < MiniTest::Test
|
||||||
include MomCompile
|
include MomCompile
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
@comp = compile_mom( "class Test ; def main(); main{return 'Ho'};return 'Hi'; end; end;")
|
@comp = compile_mom( "class Test ; def main(); main{return 'Ho'};return 'Hi'; end; end;")
|
||||||
@linker = @comp.translate(:interpreter)
|
@linker = @comp.to_risc.translate(:interpreter)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_translate_class
|
def test_translate_class
|
||||||
assert_equal Risc::Linker , @linker.class
|
assert_equal Linker , @linker.class
|
||||||
end
|
end
|
||||||
def test_linker_has_constants
|
def test_linker_has_constants
|
||||||
assert_equal Array , @linker.constants.class
|
assert_equal Array , @linker.constants.class
|
||||||
@ -26,16 +26,16 @@ module Mom
|
|||||||
assert @linker.constants.include?("Ho")
|
assert @linker.constants.include?("Ho")
|
||||||
end
|
end
|
||||||
def test_translate_platform
|
def test_translate_platform
|
||||||
assert_kind_of Risc::Platform , @linker.platform
|
assert_kind_of Platform , @linker.platform
|
||||||
end
|
end
|
||||||
def test_translate_assemblers
|
def test_translate_assemblers
|
||||||
assert_equal Risc::Assembler , @linker.assemblers.first.class
|
assert_equal Assembler , @linker.assemblers.first.class
|
||||||
end
|
end
|
||||||
def test_assembler_code
|
def test_assembler_code
|
||||||
assert_equal Risc::Label , @linker.assemblers.first.instructions.class
|
assert_equal Label , @linker.assemblers.first.instructions.class
|
||||||
end
|
end
|
||||||
def test_assembler_assembled
|
def test_assembler_assembled
|
||||||
assert_equal Risc::LoadConstant , @linker.assemblers.first.instructions.next.class
|
assert_equal LoadConstant , @linker.assemblers.first.instructions.next.class
|
||||||
end
|
end
|
||||||
def test_no_loops_in_chain
|
def test_no_loops_in_chain
|
||||||
@linker.assemblers.each do |asm|
|
@linker.assemblers.each do |asm|
|
Loading…
x
Reference in New Issue
Block a user