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
|
||||
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
|
||||
def flatten( options = {} )
|
||||
return self
|
||||
|
@ -32,11 +32,11 @@ module Mom
|
||||
@left , @right = left , right
|
||||
end
|
||||
|
||||
def to_risc_load(context)
|
||||
reg = context.use_reg( @right.ct_type)
|
||||
def to_risc(compiler)
|
||||
reg = compiler.use_reg( @right.ct_type)
|
||||
const = Risc.load_constant(self, @right , reg)
|
||||
const.set_next Risc.reg_to_slot(self, reg , @left.known_object, @left.slots.first)
|
||||
context.release_reg(reg)
|
||||
const << Risc.reg_to_slot(self, reg , @left.known_object, @left.slots.first)
|
||||
compiler.release_reg(reg)
|
||||
return const
|
||||
end
|
||||
|
||||
|
@ -94,8 +94,8 @@ module Risc
|
||||
# (adding moves the insertion point so the whole mom chain is added as a risc chain)
|
||||
def add_mom( instruction )
|
||||
raise "whats this a #{instruction}" unless instruction.is_a?(Mom::Instruction)
|
||||
return
|
||||
while( instruction )
|
||||
#puts "adding #{instruction.to_s}:#{instruction.next.to_s}"
|
||||
risc = instruction.to_risc( self )
|
||||
add_code(risc)
|
||||
instruction = instruction.next
|
||||
@ -104,7 +104,7 @@ module Risc
|
||||
# add a risc instruction after the current (insertion point)
|
||||
# the added instruction will become the new insertion point
|
||||
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")
|
||||
@current.insert(instruction) #insert after current
|
||||
@current = instruction
|
||||
|
@ -21,11 +21,18 @@ module Risc
|
||||
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
class_type.send(:private_add_instance_variable, name , type)
|
||||
end
|
||||
|
||||
def check_nil
|
||||
def produce_body
|
||||
produced = produce_instructions
|
||||
preamble.each{ produced = produced.next }
|
||||
produced
|
||||
end
|
||||
def produce_instructions
|
||||
assert @expect , "No output given"
|
||||
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
|
||||
end
|
||||
def check_return
|
||||
@ -33,7 +40,9 @@ module Risc
|
||||
raise was if was
|
||||
Parfait.object_space.get_main.instructions
|
||||
end
|
||||
|
||||
def real_index(index)
|
||||
index - preamble.length + 1
|
||||
end
|
||||
def compare_instructions( instruction , expect )
|
||||
index = 0
|
||||
all = instruction.to_arr
|
||||
@ -42,8 +51,8 @@ module Risc
|
||||
begin
|
||||
should = full_expect[index]
|
||||
return "No instruction at #{index}\n#{should(all)}" unless should
|
||||
return "Expected at #{index+1}\n#{should(all)}" unless instruction.class == should
|
||||
#puts instruction.to_s
|
||||
return "Expected at #{real_index(index)}\n#{should(all)} was #{instruction.to_s}" unless instruction.class == should
|
||||
#puts instruction.to_s if (index > preamble.length) and (index + postamble.length <= full_expect.length)
|
||||
index += 1
|
||||
instruction = instruction.next
|
||||
end while( instruction )
|
||||
|
@ -4,33 +4,16 @@ module Risc
|
||||
class TestAssignStatement < MiniTest::Test
|
||||
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
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input = "r = 10.mod4"
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def pest_assign_ivar_notpresent
|
||||
@input = "@r = 5"
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
@expect = [Label, Label, Label, Label, Label]
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
|
||||
def pest_assign_ivar
|
||||
add_space_field(:r , :Integer)
|
||||
|
||||
@input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5)))
|
||||
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
|
||||
RegToSlot, Label, FunctionReturn]
|
||||
@input = "@r = 5"
|
||||
@expect = [Label]
|
||||
assert_nil msg = check_nil , msg
|
||||
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