first local assignment risc test
comes with casualties slot_load needs more work
This commit is contained in:
parent
3eef27be76
commit
16c8fcbf66
@ -4,6 +4,9 @@ module Mom
|
|||||||
class Instruction
|
class Instruction
|
||||||
include Common::List
|
include Common::List
|
||||||
|
|
||||||
|
def to_risc(m)
|
||||||
|
Risc::Label.new(self.class.name, self.class.name + "_todo")
|
||||||
|
end
|
||||||
# implement flatten as noop to avoid condition
|
# implement flatten as noop to avoid condition
|
||||||
def flatten( options = {} )
|
def flatten( options = {} )
|
||||||
return self
|
return self
|
||||||
|
@ -32,11 +32,11 @@ module Mom
|
|||||||
@left , @right = left , right
|
@left , @right = left , right
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_risc_load(context)
|
def to_risc(compiler)
|
||||||
reg = context.use_reg( @right.ct_type)
|
reg = compiler.use_reg( @right.ct_type)
|
||||||
const = Risc.load_constant(self, @right , reg)
|
const = Risc.load_constant(self, @right , reg)
|
||||||
const.set_next Risc.reg_to_slot(self, reg , @left.known_object, @left.slots.first)
|
const << Risc.reg_to_slot(self, reg , @left.known_object, @left.slots.first)
|
||||||
context.release_reg(reg)
|
compiler.release_reg(reg)
|
||||||
return const
|
return const
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -94,8 +94,8 @@ module Risc
|
|||||||
# (adding moves the insertion point so the whole mom chain is added as a risc chain)
|
# (adding moves the insertion point so the whole mom chain is added as a risc chain)
|
||||||
def add_mom( instruction )
|
def add_mom( instruction )
|
||||||
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction)
|
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction)
|
||||||
return
|
|
||||||
while( instruction )
|
while( instruction )
|
||||||
|
#puts "adding #{instruction.to_s}:#{instruction.next.to_s}"
|
||||||
risc = instruction.to_risc( self )
|
risc = instruction.to_risc( self )
|
||||||
add_code(risc)
|
add_code(risc)
|
||||||
instruction = instruction.next
|
instruction = instruction.next
|
||||||
@ -104,7 +104,7 @@ module Risc
|
|||||||
# add a risc instruction after the current (insertion point)
|
# add a risc instruction after the current (insertion point)
|
||||||
# the added instruction will become the new insertion point
|
# the added instruction will become the new insertion point
|
||||||
def add_code( instruction )
|
def add_code( instruction )
|
||||||
raise instruction.to_s unless instruction.is_a?(Risc::Instruction)
|
raise "Not an instruction:#{instruction.to_s}" unless instruction.is_a?(Risc::Instruction)
|
||||||
raise instruction.to_s if( instruction.class.name.split("::").first == "Arm")
|
raise instruction.to_s if( instruction.class.name.split("::").first == "Arm")
|
||||||
@current.insert(instruction) #insert after current
|
@current.insert(instruction) #insert after current
|
||||||
@current = instruction
|
@current = instruction
|
||||||
|
@ -21,11 +21,18 @@ module Risc
|
|||||||
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
|
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||||
class_type.send(:private_add_instance_variable, name , type)
|
class_type.send(:private_add_instance_variable, name , type)
|
||||||
end
|
end
|
||||||
|
def produce_body
|
||||||
def check_nil
|
produced = produce_instructions
|
||||||
|
preamble.each{ produced = produced.next }
|
||||||
|
produced
|
||||||
|
end
|
||||||
|
def produce_instructions
|
||||||
assert @expect , "No output given"
|
assert @expect , "No output given"
|
||||||
Vool::VoolCompiler.ruby_to_vool "class Space; def main(arg);#{@input};end;end"
|
Vool::VoolCompiler.ruby_to_vool "class Space; def main(arg);#{@input};end;end"
|
||||||
produced = Parfait.object_space.get_main.instructions
|
Parfait.object_space.get_main.instructions
|
||||||
|
end
|
||||||
|
def check_nil
|
||||||
|
produced = produce_instructions
|
||||||
compare_instructions produced , @expect
|
compare_instructions produced , @expect
|
||||||
end
|
end
|
||||||
def check_return
|
def check_return
|
||||||
@ -33,7 +40,9 @@ module Risc
|
|||||||
raise was if was
|
raise was if was
|
||||||
Parfait.object_space.get_main.instructions
|
Parfait.object_space.get_main.instructions
|
||||||
end
|
end
|
||||||
|
def real_index(index)
|
||||||
|
index - preamble.length + 1
|
||||||
|
end
|
||||||
def compare_instructions( instruction , expect )
|
def compare_instructions( instruction , expect )
|
||||||
index = 0
|
index = 0
|
||||||
all = instruction.to_arr
|
all = instruction.to_arr
|
||||||
@ -42,8 +51,8 @@ module Risc
|
|||||||
begin
|
begin
|
||||||
should = full_expect[index]
|
should = full_expect[index]
|
||||||
return "No instruction at #{index}\n#{should(all)}" unless should
|
return "No instruction at #{index}\n#{should(all)}" unless should
|
||||||
return "Expected at #{index+1}\n#{should(all)}" unless instruction.class == should
|
return "Expected at #{real_index(index)}\n#{should(all)} was #{instruction.to_s}" unless instruction.class == should
|
||||||
#puts instruction.to_s
|
#puts instruction.to_s if (index > preamble.length) and (index + postamble.length <= full_expect.length)
|
||||||
index += 1
|
index += 1
|
||||||
instruction = instruction.next
|
instruction = instruction.next
|
||||||
end while( instruction )
|
end while( instruction )
|
||||||
|
@ -4,33 +4,16 @@ module Risc
|
|||||||
class TestAssignStatement < MiniTest::Test
|
class TestAssignStatement < MiniTest::Test
|
||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def pest_assign_local_assign
|
|
||||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
|
||||||
@input = "r = 5"
|
|
||||||
@expect = [LoadConstant, RegToSlot]
|
|
||||||
assert_nil msg = check_nil , msg
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_assign_op
|
def pest_assign_op
|
||||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||||
@input = "r = 10.mod4"
|
@input = "r = 10.mod4"
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
@expect = [Label, Label, Label, Label, Label]
|
||||||
assert_nil msg = check_nil , msg
|
|
||||||
end
|
|
||||||
|
|
||||||
def pest_assign_ivar_notpresent
|
|
||||||
@input = "@r = 5"
|
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def pest_assign_ivar
|
def pest_assign_ivar
|
||||||
add_space_field(:r , :Integer)
|
@input = "@r = 5"
|
||||||
|
@expect = [Label]
|
||||||
@input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5)))
|
|
||||||
|
|
||||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
|
||||||
RegToSlot, Label, FunctionReturn]
|
|
||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
27
test/mom/test_local_assignment.rb
Normal file
27
test/mom/test_local_assignment.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
require_relative 'helper'
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestLocalAssign < MiniTest::Test
|
||||||
|
include Statements
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
@input = "r = 5"
|
||||||
|
@expect = [LoadConstant, RegToSlot]
|
||||||
|
end
|
||||||
|
def test_local_assign_instructions
|
||||||
|
assert_nil msg = check_nil , msg
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_constant_load
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal 5 , produced.constant.value
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_slot_move
|
||||||
|
produced = produce_body
|
||||||
|
assert_equal produced.next.register , produced.register
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user