Move the space instance to the parfait module
A better fit, maybe even a pattern for singletons
This commit is contained in:
@ -16,7 +16,7 @@ module Statements
|
||||
code = Typed.ast_to_code( @input )
|
||||
assert code.to_s , @input
|
||||
produced = compiler.process( code )
|
||||
produced = Parfait::Space.object_space.get_main.instructions
|
||||
produced = Parfait.object_space.get_main.instructions
|
||||
compare_instructions produced , @expect
|
||||
produced
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def test_assign_op
|
||||
Parfait::Space.object_space.get_main.add_local(:r , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
|
||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
|
||||
|
||||
@ -15,7 +15,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_assign_local
|
||||
Parfait::Space.object_space.get_main.add_local(:r , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
|
||||
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
@ -23,7 +23,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_assign_local_assign
|
||||
Parfait::Space.object_space.get_main.add_local(:r , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
|
||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)))
|
||||
|
||||
@ -32,7 +32,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_assign_call
|
||||
Parfait::Space.object_space.get_main.add_local(:r , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
|
||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, LoadConstant ,
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall ,
|
||||
@ -42,7 +42,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_named_list_get
|
||||
Parfait::Space.object_space.get_main.add_local(:r , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot ,
|
||||
Label, FunctionReturn]
|
||||
@ -53,7 +53,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_assign_local_int
|
||||
Parfait::Space.object_space.get_main.add_local(:r , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) )
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
@ -63,14 +63,14 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_misassign_local
|
||||
Parfait::Space.object_space.get_main.add_local(:r , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:r , :Integer)
|
||||
@input = s(:statements, s(:assignment, s(:name, :r), s(:string, "5")) )
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
assert_raises {check }
|
||||
end
|
||||
|
||||
def test_assign_arg
|
||||
Parfait::Space.object_space.get_main.add_argument(:blar , :Integer)
|
||||
Parfait.object_space.get_main.add_argument(:blar , :Integer)
|
||||
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5)))
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
@ -80,7 +80,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_misassign_arg
|
||||
Parfait::Space.object_space.get_main.add_argument(:blar , :Integer)
|
||||
Parfait.object_space.get_main.add_argument(:blar , :Integer)
|
||||
@input = s(:statements, s(:assignment, s(:name, :blar), s(:string, "5")))
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
assert_raises {check }
|
||||
@ -88,7 +88,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
|
||||
def test_arg_get
|
||||
# have to define bar externally, just because redefining main. Otherwise that would be automatic
|
||||
Parfait::Space.object_space.get_main.add_argument(:balr , :Integer)
|
||||
Parfait.object_space.get_main.add_argument(:balr , :Integer)
|
||||
@input = s(:statements, s(:return, s(:name, :balr)))
|
||||
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
was = check
|
||||
|
@ -25,7 +25,7 @@ class TestCallStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def _test_call_local_int
|
||||
Parfait::Space.object_space.get_main.add_local(:testi , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:testi , :Integer)
|
||||
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
|
||||
@input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
|
||||
|
||||
@ -37,7 +37,7 @@ class TestCallStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_call_local_class
|
||||
Parfait::Space.object_space.get_main.add_local(:test_l , :List)
|
||||
Parfait.object_space.get_main.add_local(:test_l , :List)
|
||||
clean_compile :List, :add, {}, s(:statements, s(:return, s(:int, 1)))
|
||||
|
||||
@input =s(:statements, s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
|
||||
|
@ -6,7 +6,7 @@ module Register
|
||||
include Statements
|
||||
|
||||
def test_field_named_list
|
||||
Parfait::Space.object_space.get_main.add_local( :m , :Message)
|
||||
Parfait.object_space.get_main.add_local( :m , :Message)
|
||||
@input = s(:statements, s(:return, s(:field_access,
|
||||
s(:receiver, s(:name, :m)), s(:field, s(:name, :name)))))
|
||||
@expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn]
|
||||
@ -14,7 +14,7 @@ module Register
|
||||
end
|
||||
|
||||
def test_field_arg
|
||||
Parfait::Space.object_space.get_main.add_local( :m , :Message)
|
||||
Parfait.object_space.get_main.add_local( :m , :Message)
|
||||
clean_compile :Space, :get_name, { :main => :Message},
|
||||
s(:statements, s(:return, s(:field_access,
|
||||
s(:receiver, s(:name, :main)), s(:field, s(:name, :name)))))
|
||||
@ -28,7 +28,7 @@ module Register
|
||||
end
|
||||
|
||||
def test_message_field
|
||||
Parfait::Space.object_space.get_main.add_local(:name , :Word)
|
||||
Parfait.object_space.get_main.add_local(:name , :Word)
|
||||
@input = s(:statements, s(:assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name)))
|
||||
|
||||
@expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
|
||||
|
@ -11,14 +11,14 @@ class TestReturnStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_return_local
|
||||
Parfait::Space.object_space.get_main.add_local(:runner , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:runner , :Integer)
|
||||
@input = s(:statements, s(:return, s(:name, :runner)))
|
||||
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
def test_return_local_assign
|
||||
Parfait::Space.object_space.get_main.add_local(:runner , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:runner , :Integer)
|
||||
@input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
|
||||
@expect = [Label, LoadConstant,SlotToReg,RegToSlot,SlotToReg,SlotToReg ,RegToSlot,
|
||||
Label,FunctionReturn]
|
||||
@ -34,7 +34,7 @@ class TestReturnStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def pest_return_space_length # need to add runtime first
|
||||
Parfait::Space.object_space.get_main.add_local(:l , :Type)
|
||||
Parfait.object_space.get_main.add_local(:l , :Type)
|
||||
@input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
|
||||
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
|
||||
check
|
||||
|
@ -14,7 +14,7 @@ module Register
|
||||
end
|
||||
|
||||
def test_while_assign
|
||||
Parfait::Space.object_space.get_main.add_local(:n , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:n , :Integer)
|
||||
|
||||
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n)))
|
||||
|
||||
@ -26,7 +26,7 @@ module Register
|
||||
|
||||
|
||||
def test_while_return
|
||||
Parfait::Space.object_space.get_main.add_local(:n , :Integer)
|
||||
Parfait.object_space.get_main.add_local(:n , :Integer)
|
||||
|
||||
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n)))))
|
||||
|
||||
|
Reference in New Issue
Block a user