actually adding risc instructions

fix test harness
1 working test (yeh)
This commit is contained in:
Torsten Ruger 2018-03-14 17:41:09 +05:30
parent 79b4b07ac4
commit 7db329fa6b
4 changed files with 28 additions and 23 deletions

View File

@ -24,6 +24,12 @@ module Vool
end
def create_objects
create_class_object
body.collect([]).each {|node| node.set_class(@clazz) }
body.create_objects
end
def create_class_object
@clazz = Parfait.object_space.get_class_by_name(@name )
if(@clazz)
#FIXME super class check with "sup"
@ -36,9 +42,6 @@ module Vool
vars.each { |var| ivar_hash[var] = :Object }
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
end
body.collect([]).each {|node| node.set_class(@clazz) }
body.create_objects
end
end
end

View File

@ -36,7 +36,7 @@ module Vool
typed_method = method.create_parfait_method(clazz.instance_type)
compiler = Risc::MethodCompiler.new( typed_method ).init_method
head = @body.to_mom( method ).flatten
head.to_risc(compiler)
compiler.add_mom(head)
end
private

View File

@ -34,7 +34,7 @@ module Risc
end
def preamble
[Label, SlotToReg , LoadConstant, RegToSlot, LoadConstant,RegToSlot, LoadConstant, SlotToReg, SlotToReg ]
[Label, LoadConstant, SlotToReg, RegToSlot ]
end
def postamble
[ Label, FunctionReturn]
@ -57,19 +57,20 @@ module Risc
index = 0
all = instruction.to_arr
full_expect = preamble + expect + postamble
full_expect = expect
#full_expect = expect
begin
should = full_expect[index]
return "No instruction at #{index}" unless should
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
index += 1
instruction = instruction.next
end while( instruction )
nil
end
def should( all )
#preamble.each {all.shift}
#postamble.each {all.pop}
preamble.each {all.shift}
postamble.each {all.pop}
str = all.to_s.gsub("Risc::","")
ret = ""
str.split(",").each_slice(6).each do |line|

View File

@ -5,7 +5,18 @@ module Risc
class TestAssignStatement < MiniTest::Test
include Statements
def test_assign_op
def test_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"
@ -15,9 +26,9 @@ module Risc
end
def pest_assign_ivar_notpresent
@input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5)))
@expect = []
assert_raises{ check_nil }
@input = "@r = 5"
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_nil msg = check_nil , msg
end
def pest_assign_ivar
@ -30,16 +41,6 @@ module Risc
assert_nil msg = check_nil , msg
end
def pest_assign_local_assign
Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, Label, FunctionReturn]
assert_nil msg = check_nil , msg
end
def pest_assign_call
Parfait.object_space.get_main.add_local(:r , :Object)
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments))))