actually adding risc instructions
fix test harness 1 working test (yeh)
This commit is contained in:
parent
79b4b07ac4
commit
7db329fa6b
@ -24,6 +24,12 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_objects
|
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 )
|
@clazz = Parfait.object_space.get_class_by_name(@name )
|
||||||
if(@clazz)
|
if(@clazz)
|
||||||
#FIXME super class check with "sup"
|
#FIXME super class check with "sup"
|
||||||
@ -36,9 +42,6 @@ module Vool
|
|||||||
vars.each { |var| ivar_hash[var] = :Object }
|
vars.each { |var| ivar_hash[var] = :Object }
|
||||||
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
|
@clazz.set_instance_type( Parfait::Type.for_hash( @clazz , ivar_hash ) )
|
||||||
end
|
end
|
||||||
body.collect([]).each {|node| node.set_class(@clazz) }
|
|
||||||
body.create_objects
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,7 +36,7 @@ module Vool
|
|||||||
typed_method = method.create_parfait_method(clazz.instance_type)
|
typed_method = method.create_parfait_method(clazz.instance_type)
|
||||||
compiler = Risc::MethodCompiler.new( typed_method ).init_method
|
compiler = Risc::MethodCompiler.new( typed_method ).init_method
|
||||||
head = @body.to_mom( method ).flatten
|
head = @body.to_mom( method ).flatten
|
||||||
head.to_risc(compiler)
|
compiler.add_mom(head)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -34,7 +34,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def preamble
|
def preamble
|
||||||
[Label, SlotToReg , LoadConstant, RegToSlot, LoadConstant,RegToSlot, LoadConstant, SlotToReg, SlotToReg ]
|
[Label, LoadConstant, SlotToReg, RegToSlot ]
|
||||||
end
|
end
|
||||||
def postamble
|
def postamble
|
||||||
[ Label, FunctionReturn]
|
[ Label, FunctionReturn]
|
||||||
@ -57,19 +57,20 @@ module Risc
|
|||||||
index = 0
|
index = 0
|
||||||
all = instruction.to_arr
|
all = instruction.to_arr
|
||||||
full_expect = preamble + expect + postamble
|
full_expect = preamble + expect + postamble
|
||||||
full_expect = expect
|
#full_expect = expect
|
||||||
begin
|
begin
|
||||||
should = full_expect[index]
|
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
|
return "Expected at #{index+1}\n#{should(all)}" unless instruction.class == should
|
||||||
|
puts instruction.to_s
|
||||||
index += 1
|
index += 1
|
||||||
instruction = instruction.next
|
instruction = instruction.next
|
||||||
end while( instruction )
|
end while( instruction )
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
def should( all )
|
def should( all )
|
||||||
#preamble.each {all.shift}
|
preamble.each {all.shift}
|
||||||
#postamble.each {all.pop}
|
postamble.each {all.pop}
|
||||||
str = all.to_s.gsub("Risc::","")
|
str = all.to_s.gsub("Risc::","")
|
||||||
ret = ""
|
ret = ""
|
||||||
str.split(",").each_slice(6).each do |line|
|
str.split(",").each_slice(6).each do |line|
|
||||||
|
@ -5,7 +5,18 @@ module Risc
|
|||||||
class TestAssignStatement < MiniTest::Test
|
class TestAssignStatement < MiniTest::Test
|
||||||
include Statements
|
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)
|
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||||
|
|
||||||
@input = "r = 10.mod4"
|
@input = "r = 10.mod4"
|
||||||
@ -15,9 +26,9 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def pest_assign_ivar_notpresent
|
def pest_assign_ivar_notpresent
|
||||||
@input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5)))
|
@input = "@r = 5"
|
||||||
@expect = []
|
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||||
assert_raises{ check_nil }
|
assert_nil msg = check_nil , msg
|
||||||
end
|
end
|
||||||
|
|
||||||
def pest_assign_ivar
|
def pest_assign_ivar
|
||||||
@ -30,16 +41,6 @@ module Risc
|
|||||||
assert_nil msg = check_nil , msg
|
assert_nil msg = check_nil , msg
|
||||||
end
|
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
|
def pest_assign_call
|
||||||
Parfait.object_space.get_main.add_local(:r , :Object)
|
Parfait.object_space.get_main.add_local(:r , :Object)
|
||||||
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments))))
|
@input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments))))
|
||||||
|
Loading…
Reference in New Issue
Block a user