Fixing self type creation
When compiling a classs, we pick up all instance variables. Now that conditions and returns can be calls, that was broken, now fixed
This commit is contained in:
@ -7,19 +7,19 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "return @a.div4"
|
||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
|
||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
|
||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
||||
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #20
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #25
|
||||
Label, LoadConstant, SlotToReg, Transfer, Syscall, #30
|
||||
Transfer, Transfer, SlotToReg, RegToSlot, Label, #35
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, LoadConstant, #40
|
||||
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #45
|
||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #50
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #55
|
||||
SlotToReg, DynamicJump, Label, SlotToReg, SlotToReg, #60
|
||||
RegToSlot, SlotToReg, SlotToReg, RegToSlot, Branch] #65
|
||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4
|
||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9
|
||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14
|
||||
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24
|
||||
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29
|
||||
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, LoadConstant, #39
|
||||
SlotToReg, SlotToReg, RegToSlot, RegToSlot, RegToSlot, #44
|
||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #49
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #54
|
||||
SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #59
|
||||
Branch] #64
|
||||
end
|
||||
|
||||
def test_return_instructions
|
||||
@ -27,7 +27,7 @@ module Risc
|
||||
end
|
||||
def test_function_return
|
||||
produced = produce_body
|
||||
assert_equal Branch , produced.next(64).class
|
||||
assert_equal Branch , produced.next(60).class
|
||||
end
|
||||
def test_cache_check
|
||||
produced = produce_body
|
||||
|
@ -5,8 +5,8 @@ module Vool
|
||||
class TestClassStatement < MiniTest::Test
|
||||
include ScopeHelper
|
||||
def setup
|
||||
Parfait.boot!({})
|
||||
ruby_tree = Ruby::RubyCompiler.compile( as_test_main("a = 5") )
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
ruby_tree = Ruby::RubyCompiler.compile( as_test_main("@a = 5") )
|
||||
@vool = ruby_tree.to_vool
|
||||
end
|
||||
def test_class
|
||||
@ -21,6 +21,47 @@ module Vool
|
||||
def test_create_class
|
||||
assert_equal :Test , @vool.create_class_object.name
|
||||
end
|
||||
def test_class_instance
|
||||
assert_equal :a , @vool.create_class_object.instance_type.names[1]
|
||||
end
|
||||
end
|
||||
class TestClassStatementTypeCreation < MiniTest::Test
|
||||
include ScopeHelper
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
end
|
||||
def assert_type_for(input)
|
||||
ruby_tree = Ruby::RubyCompiler.compile( as_test_main(input) )
|
||||
vool = ruby_tree.to_vool
|
||||
assert_equal ClassStatement , vool.class
|
||||
clazz = vool.create_class_object
|
||||
assert_equal Parfait::Class , clazz.class
|
||||
assert_equal :a , clazz.instance_type.names[1]
|
||||
end
|
||||
def test_while_cond
|
||||
assert_type_for("while(@a) ; 1 == 1 ; end")
|
||||
end
|
||||
def test_while_cond_eq
|
||||
assert_type_for("while(@a==1); 1 == 1 ; end")
|
||||
end
|
||||
def test_if_cond
|
||||
assert_type_for("if(@a); 1 == 1 ; end")
|
||||
end
|
||||
def test_send_1
|
||||
assert_type_for("@a.call")
|
||||
end
|
||||
def test_send_arg
|
||||
assert_type_for("call(@a)")
|
||||
end
|
||||
def test_return
|
||||
assert_type_for("return @a")
|
||||
end
|
||||
def test_return_call
|
||||
assert_type_for("return call(@a)")
|
||||
end
|
||||
def test_return_rec
|
||||
assert_type_for("return @a.call()")
|
||||
end
|
||||
end
|
||||
class TestClassStatementCompile < MiniTest::Test
|
||||
include VoolCompile
|
||||
|
Reference in New Issue
Block a user