From 8dbbffd58ec7d57cd338ad2b002a8ee37f3bf471 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 16 Jan 2017 09:34:47 +0200 Subject: [PATCH] fix tests for NameExpression split also necessitates giving method name without the wrapping expression which is simpler anyway --- test/elf/test_hello.rb | 2 +- test/register/interpreter/test_byte_to_reg.rb | 2 +- test/register/interpreter/test_called_if.rb | 8 ++--- test/register/interpreter/test_puts.rb | 2 +- test/register/interpreter/test_reg_to_byte.rb | 2 +- test/register/interpreter/test_simple_if.rb | 4 +-- test/vm/method_compiler/test_all.rb | 1 - test/vm/method_compiler/test_assignment.rb | 24 +++++++------- test/vm/method_compiler/test_basic_values.rb | 2 +- .../method_compiler/test_call_expression.rb | 10 +++--- test/vm/method_compiler/test_call_site.rb | 12 +++---- test/vm/method_compiler/test_class.rb | 31 ------------------- test/vm/method_compiler/test_field_access.rb | 6 ++-- test/vm/method_compiler/test_fields.rb | 8 ++--- .../method_compiler/test_name_expression.rb | 6 ++-- .../test_operator_expression.rb | 8 ++--- .../method_compiler/test_return_statement.rb | 8 ++--- .../method_compiler/test_while_statement.rb | 10 ++++-- test/vm/test_to_code.rb | 18 ++++++----- 19 files changed, 71 insertions(+), 93 deletions(-) delete mode 100644 test/vm/method_compiler/test_class.rb diff --git a/test/elf/test_hello.rb b/test/elf/test_hello.rb index ac82044c..21baa71f 100644 --- a/test/elf/test_hello.rb +++ b/test/elf/test_hello.rb @@ -13,7 +13,7 @@ class HelloTest < MiniTest::Test end def test_string_put - @input = s(:statements, s(:return, s(:call, s(:name, :putstring), s(:arguments), + @input = s(:statements, s(:return, s(:call, :putstring, s(:arguments), s(:receiver, s(:string, "Hello again\\n"))))) check end diff --git a/test/register/interpreter/test_byte_to_reg.rb b/test/register/interpreter/test_byte_to_reg.rb index 49833fc7..a4be3f22 100644 --- a/test/register/interpreter/test_byte_to_reg.rb +++ b/test/register/interpreter/test_byte_to_reg.rb @@ -13,7 +13,7 @@ module Register end HERE @input = s(:statements, s(:call, - s(:name, :set_internal_byte), + :set_internal_byte , s(:arguments, s(:int, 1), s(:int, 104)), s(:receiver, s(:string, "Hello")))) super diff --git a/test/register/interpreter/test_called_if.rb b/test/register/interpreter/test_called_if.rb index ea2a7948..80c15580 100644 --- a/test/register/interpreter/test_called_if.rb +++ b/test/register/interpreter/test_called_if.rb @@ -21,16 +21,16 @@ module Register end end HERE - @input = s(:statements, s(:call, s(:name, :itest), s(:arguments, s(:int, 20)))) + @input = s(:statements, s(:call, :itest , s(:arguments, s(:int, 20)))) super end # must be after boot, but before main compile, to define method def do_clean_compile clean_compile :Space , :itest , {:n => :Integer} , - s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:name, :n), s(:int, 12))), - s(:true_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "then")))), - s(:false_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "else")))))) + s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:arg, :n), s(:int, 12))), + s(:true_statements, s(:call, :putstring , s(:arguments), s(:receiver, s(:string, "then")))), + s(:false_statements, s(:call, :putstring , s(:arguments), s(:receiver, s(:string, "else")))))) end def test_if #show_ticks # get output of what is diff --git a/test/register/interpreter/test_puts.rb b/test/register/interpreter/test_puts.rb index 35b5080f..a497249d 100644 --- a/test/register/interpreter/test_puts.rb +++ b/test/register/interpreter/test_puts.rb @@ -12,7 +12,7 @@ module Register end end HERE - @input = s(:statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "Hello again")))) + @input = s(:statements, s(:call, :putstring, s(:arguments), s(:receiver, s(:string, "Hello again")))) super end diff --git a/test/register/interpreter/test_reg_to_byte.rb b/test/register/interpreter/test_reg_to_byte.rb index cbbd1cb3..e4f64042 100644 --- a/test/register/interpreter/test_reg_to_byte.rb +++ b/test/register/interpreter/test_reg_to_byte.rb @@ -13,7 +13,7 @@ module Register end HERE @input = s(:statements, s(:call, - s(:name, :get_internal_byte), + :get_internal_byte, s(:arguments, s(:int, 1)), s(:receiver, s(:string, "Hello")))) super diff --git a/test/register/interpreter/test_simple_if.rb b/test/register/interpreter/test_simple_if.rb index 18d8c1c5..628e94d3 100644 --- a/test/register/interpreter/test_simple_if.rb +++ b/test/register/interpreter/test_simple_if.rb @@ -18,8 +18,8 @@ module Register end HERE @input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), - s(:true_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "then")))), - s(:false_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "else")))))) + s(:true_statements, s(:call, :putstring, s(:arguments), s(:receiver, s(:string, "then")))), + s(:false_statements, s(:call, :putstring, s(:arguments), s(:receiver, s(:string, "else")))))) super end diff --git a/test/vm/method_compiler/test_all.rb b/test/vm/method_compiler/test_all.rb index 15b31640..a1baf0cf 100644 --- a/test/vm/method_compiler/test_all.rb +++ b/test/vm/method_compiler/test_all.rb @@ -1,7 +1,6 @@ #statements require_relative "test_assignment" require_relative "test_call_site" -require_relative "test_class" require_relative "test_fields" require_relative "test_if_statement" require_relative "test_return_statement" diff --git a/test/vm/method_compiler/test_assignment.rb b/test/vm/method_compiler/test_assignment.rb index 08262e6d..2c8c94e6 100644 --- a/test/vm/method_compiler/test_assignment.rb +++ b/test/vm/method_compiler/test_assignment.rb @@ -7,7 +7,7 @@ module Register def test_assign_op Parfait.object_space.get_main.add_local(:r , :Integer) - @input = s(:statements, s(:l_assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1)))) + @input = s(:statements, s(:l_assignment, s(:local, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1)))) @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot , LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] @@ -15,15 +15,15 @@ module Register end def test_assign_ivar_notpresent - @input =s(:statements, s(:i_assignment, s(:name, :r), s(:int, 5))) + @input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5))) @expect = [] assert_raises{ check_nil } end def test_assign_ivar add_space_field(:r , :Integer) - - @input =s(:statements, s(:i_assignment, s(:name, :r), s(:int, 5))) + + @input =s(:statements, s(:i_assignment, s(:ivar, :r), s(:int, 5))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , RegToSlot, Label, FunctionReturn] @@ -33,7 +33,7 @@ module Register def test_assign_local_assign Parfait.object_space.get_main.add_local(:r , :Integer) - @input = s(:statements, s(:l_assignment, s(:name, :r), s(:int, 5))) + @input = s(:statements, s(:l_assignment, s(:local, :r), s(:int, 5))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , RegToSlot, Label, FunctionReturn] @@ -42,7 +42,7 @@ module Register def test_assign_call Parfait.object_space.get_main.add_local(:r , :Integer) - @input = s(:statements, s(:l_assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments)))) + @input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments)))) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, SlotToReg , @@ -52,7 +52,7 @@ module Register def test_named_list_get Parfait.object_space.get_main.add_local(:r , :Integer) - @input = s(:statements, s(:l_assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r))) + @input = s(:statements, s(:l_assignment, s(:local, :r), s(:int, 5)), s(:return, s(:local, :r))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg , RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] was = check_return @@ -63,7 +63,7 @@ module Register def test_assign_local_int Parfait.object_space.get_main.add_local(:r , :Integer) - @input = s(:statements, s(:l_assignment, s(:name, :r), s(:int, 5)) ) + @input = s(:statements, s(:l_assignment, s(:local, :r), s(:int, 5)) ) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , RegToSlot, Label, FunctionReturn] was = check_return @@ -74,14 +74,14 @@ module Register def test_misassign_local Parfait.object_space.get_main.add_local(:r , :Integer) - @input = s(:statements, s(:l_assignment, s(:name, :r), s(:string, "5")) ) + @input = s(:statements, s(:l_assignment, s(:local, :r), s(:string, "5")) ) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] assert_raises {check } end def test_assign_arg Parfait.object_space.get_main.add_argument(:blar , :Integer) - @input = s(:statements, s(:a_assignment, s(:name, :blar), s(:int, 5))) + @input = s(:statements, s(:a_assignment, s(:arg, :blar), s(:int, 5))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , RegToSlot, Label, FunctionReturn] was = check_return @@ -92,7 +92,7 @@ module Register def test_misassign_arg Parfait.object_space.get_main.add_argument(:blar , :Integer) - @input = s(:statements, s(:a_assignment, s(:name, :blar), s(:string, "5"))) + @input = s(:statements, s(:a_assignment, s(:arg, :blar), s(:string, "5"))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] assert_raises {check } end @@ -100,7 +100,7 @@ module Register def test_arg_get # have to define bar externally, just because redefining main. Otherwise that would be automatic Parfait.object_space.get_main.add_argument(:balr , :Integer) - @input = s(:statements, s(:return, s(:name, :balr))) + @input = s(:statements, s(:return, s(:arg, :balr))) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg , RegToSlot, Label, FunctionReturn] was = check_return diff --git a/test/vm/method_compiler/test_basic_values.rb b/test/vm/method_compiler/test_basic_values.rb index 3eeb97e8..96b40d3a 100644 --- a/test/vm/method_compiler/test_basic_values.rb +++ b/test/vm/method_compiler/test_basic_values.rb @@ -29,7 +29,7 @@ module Register check end def test_self - @input = s(:name, :self) + @input = s(:known, :self) check end def test_string diff --git a/test/vm/method_compiler/test_call_expression.rb b/test/vm/method_compiler/test_call_expression.rb index 5b728f26..1e0f1ce0 100644 --- a/test/vm/method_compiler/test_call_expression.rb +++ b/test/vm/method_compiler/test_call_expression.rb @@ -11,31 +11,31 @@ module Register end def test_call_main_plain - @input = s(:call,s(:name, :main),s(:arguments)) + @input = s(:call , :main ,s(:arguments)) check end def test_call_main_int Parfait.object_space.get_main.add_argument(:blar , :Integer) - @input =s(:call,s(:name, :main),s(:arguments , s(:int, 1))) + @input =s(:call, :main ,s(:arguments , s(:int, 1))) check end def test_call_main_string Parfait.object_space.get_main.add_argument(:blar , :Word) - @input =s(:call,s(:name, :main),s(:arguments , s(:string, "1") )) + @input =s(:call, :main ,s(:arguments , s(:string, "1") )) check end def test_call_main_op Parfait.object_space.get_main.add_local(:bar , :Integer) Parfait.object_space.get_main.add_argument(:blar , :Integer) - @input =s(:call,s(:name, :main),s(:arguments , s(:name, :bar) )) + @input =s(:call, :main ,s(:arguments , s(:local, :bar) )) check end def test_call_string_put - @input = s(:call,s(:name, :putstring),s(:arguments),s(:receiver,s(:string, "Hello Raisa, I am salama"))) + @input = s(:call, :putstring,s(:arguments),s(:receiver,s(:string, "Hello Raisa, I am salama"))) check end diff --git a/test/vm/method_compiler/test_call_site.rb b/test/vm/method_compiler/test_call_site.rb index 38cee5d6..caddfcf5 100644 --- a/test/vm/method_compiler/test_call_site.rb +++ b/test/vm/method_compiler/test_call_site.rb @@ -7,7 +7,7 @@ module Register def test_call_constant_int clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1))) - @input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42))) + @input = s(:call, :puti , s(:arguments), s(:receiver, s(:int, 42))) @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label , RegisterTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot, Label , @@ -19,7 +19,7 @@ module Register def test_call_constant_string clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1))) - @input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello"))) + @input =s(:call, :putstr, s(:arguments), s(:receiver, s(:string, "Hello"))) @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label , RegisterTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot, Label , @@ -30,7 +30,7 @@ module Register def test_call_local_int Parfait.object_space.get_main.add_local(:testi , :Integer) clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1))) - @input = s(:statements, s(:l_assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi)))) + @input = s(:statements, s(:l_assignment, s(:local, :testi), s(:int, 20)), s(:call, :putint, s(:arguments), s(:receiver, s(:local, :testi)))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg , RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant , @@ -43,7 +43,7 @@ module Register 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)))) + @input =s(:statements, s(:call, :add, s(:arguments), s(:receiver, s(:local, :test_l)))) @expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall , Label, RegisterTransfer, SlotToReg, SlotToReg, LoadConstant, SlotToReg, RegToSlot , @@ -52,8 +52,8 @@ module Register end def test_call_puts - clean_compile :Space, :putstr, {str: :Word}, s(:statements, s(:return, s(:name, :str))) - @input =s(:call, s(:name, :putstr), s(:arguments, s(:string, "Hello") ) ) + clean_compile :Space, :putstr, {str: :Word}, s(:statements, s(:return, s(:arg, :str))) + @input =s(:call, :putstr , s(:arguments, s(:string, "Hello") ) ) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot , LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , diff --git a/test/vm/method_compiler/test_class.rb b/test/vm/method_compiler/test_class.rb deleted file mode 100644 index 7cb47014..00000000 --- a/test/vm/method_compiler/test_class.rb +++ /dev/null @@ -1,31 +0,0 @@ -require_relative 'helper' - -module Register - class TestClassStatements < MiniTest::Test - include Statements - - def class_def - clean_compile :Bar, :buh, {}, s(:statements, s(:return, s(:int, 1))) - end - - def test_class_call - #FIXME class call - # class_def - # @input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar))))) - # - # @expect = [Label, SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot, LoadConstant , - # RegToSlot, LoadConstant, RegToSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , - # SlotToReg, SlotToReg, RegToSlot, Label, FunctionReturn] - # check - end - - def test_class_field - # clean_compile :Space, s(:class_field, :Integer, :boo2) - #FIXME class_field handling unclear at the moment - # @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)), - # s(:field,s(:name, :boo2))))) - # @expect = [Label, SlotToReg,SlotToReg,RegToSlot,Label,FunctionReturn] - # check - end - end -end diff --git a/test/vm/method_compiler/test_field_access.rb b/test/vm/method_compiler/test_field_access.rb index 24083072..261feab3 100644 --- a/test/vm/method_compiler/test_field_access.rb +++ b/test/vm/method_compiler/test_field_access.rb @@ -11,13 +11,13 @@ module Register def test_field_not_defined @root = :field_access - @input = s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :a))) + @input = s(:field_access, s(:receiver, s(:known, :self)), s(:field, s(:ivar, :a))) assert_raises(RuntimeError) { check } end def test_field_not_space @root = :field_access - @input = s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :space))) + @input = s(:field_access, s(:receiver, s(:known, :self)), s(:field, s(:ivar, :space))) assert_raises(RuntimeError) { check } end @@ -25,7 +25,7 @@ module Register def test_field add_space_field(:bro,:Object) @root = :field_access - @input = s(:field_access,s(:receiver, s(:name, :self)),s(:field,s(:name, :bro))) + @input = s(:field_access,s(:receiver, s(:known, :self)),s(:field,s(:ivar, :bro))) @output = Register::RegisterValue check end diff --git a/test/vm/method_compiler/test_fields.rb b/test/vm/method_compiler/test_fields.rb index afea1bd6..b71238b8 100644 --- a/test/vm/method_compiler/test_fields.rb +++ b/test/vm/method_compiler/test_fields.rb @@ -8,7 +8,7 @@ module Register def test_field_named_list 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))))) + s(:receiver, s(:local, :m)), s(:field, s(:ivar, :name))))) @expect = [Label, SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant , SlotToReg, RegToSlot, Label, FunctionReturn] assert_nil msg = check_nil , msg @@ -18,8 +18,8 @@ module Register 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))))) - @input =s(:statements, s(:return, s(:call, s(:name, :get_name), s(:arguments, s(:name, :m))))) + s(:receiver, s(:arg, :main)), s(:field, s(:ivar, :name))))) + @input =s(:statements, s(:return, s(:call, :get_name, s(:arguments, s(:local, :m))))) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg , @@ -31,7 +31,7 @@ module Register def test_message_field Parfait.object_space.get_main.add_local(:name , :Word) - @input = s(:statements, s(:l_assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name))) + @input = s(:statements, s(:l_assignment, s(:local, :name), s(:field_access, s(:receiver, s(:known, :message)), s(:field, s(:ivar, :name)))), s(:return, s(:local, :name))) @expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg , SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label , diff --git a/test/vm/method_compiler/test_name_expression.rb b/test/vm/method_compiler/test_name_expression.rb index 9f931c78..a7a27e53 100644 --- a/test/vm/method_compiler/test_name_expression.rb +++ b/test/vm/method_compiler/test_name_expression.rb @@ -11,21 +11,21 @@ module Register def test_local Parfait.object_space.get_main.add_local(:bar , :Integer) - @input = s(:name, :bar) + @input = s(:local, :bar) @output = Register::RegisterValue check end def test_space @root = :name - @input = s(:name, :space) + @input = s(:known, :space) @output = Register::RegisterValue check end def test_args Parfait.object_space.get_main.add_argument(:bar , :Integer) - @input = s(:name, :bar) + @input = s(:arg, :bar) @output = Register::RegisterValue check end diff --git a/test/vm/method_compiler/test_operator_expression.rb b/test/vm/method_compiler/test_operator_expression.rb index 5522e058..9b5d237b 100644 --- a/test/vm/method_compiler/test_operator_expression.rb +++ b/test/vm/method_compiler/test_operator_expression.rb @@ -22,24 +22,24 @@ module Register end def test_local_int Parfait.object_space.get_main.add_local(:bar , :Integer) - @input = s(:operator_value, :+, s(:name, :bar), s(:int, 3)) + @input = s(:operator_value, :+, s(:local, :bar), s(:int, 3)) check end def test_int_local Parfait.object_space.get_main.add_local(:bar , :Integer) - @input = s(:operator_value, :+, s(:int, 3), s(:name, :bar)) + @input = s(:operator_value, :+, s(:int, 3), s(:local, :bar)) check end def test_field_int add_space_field(:bro,:Integer) - @input = s(:operator_value, :+, s(:field_access,s(:receiver, s(:name, :self)), s(:field, s(:name, :bro))), s(:int, 3)) + @input = s(:operator_value, :+, s(:field_access,s(:receiver, s(:known, :self)), s(:field, s(:ivar, :bro))), s(:int, 3)) check end def test_int_field add_space_field(:bro,:Integer) - @input = s(:operator_value, :+, s(:int, 3), s(:field_access, s(:receiver, s(:name, :self)), s(:field,s(:name, :bro)))) + @input = s(:operator_value, :+, s(:int, 3), s(:field_access, s(:receiver, s(:known, :self)), s(:field,s(:ivar, :bro)))) check end end diff --git a/test/vm/method_compiler/test_return_statement.rb b/test/vm/method_compiler/test_return_statement.rb index 5d81a2af..2ca32c31 100644 --- a/test/vm/method_compiler/test_return_statement.rb +++ b/test/vm/method_compiler/test_return_statement.rb @@ -13,7 +13,7 @@ module Register def test_return_local Parfait.object_space.get_main.add_local(:runner , :Integer) - @input = s(:statements, s(:return, s(:name, :runner))) + @input = s(:statements, s(:return, s(:local , :runner))) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg , RegToSlot, Label, FunctionReturn] assert_nil msg = check_nil , msg @@ -21,14 +21,14 @@ module Register def test_return_local_assign Parfait.object_space.get_main.add_local(:runner , :Integer) - @input = s(:statements, s(:l_assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner))) + @input = s(:statements, s(:l_assignment, s(:local, :runner), s(:int, 5)), s(:return, s(:local, :runner))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg , RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] assert_nil msg = check_nil , msg end def test_return_call - @input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments)))) + @input =s(:statements, s(:return, s(:call, :main, s(:arguments)))) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot , @@ -38,7 +38,7 @@ module Register def pest_return_space_length # need to add runtime first Parfait.object_space.get_main.add_local(:l , :Type) - @input = s(:statements, s(:l_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))))) + @input = s(:statements, s(:l_assignment, s(:local, :l), s(:call, :get_type, s(:arguments), s(:receiver, s(:known, :space)))), s(:return, s(:field_access, s(:receiver, s(:known, :self)), s(:field, s(:ivar, :runner))))) @expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn] assert_nil msg = check_nil , msg end diff --git a/test/vm/method_compiler/test_while_statement.rb b/test/vm/method_compiler/test_while_statement.rb index 887e5ac0..b6d9b09f 100644 --- a/test/vm/method_compiler/test_while_statement.rb +++ b/test/vm/method_compiler/test_while_statement.rb @@ -17,7 +17,11 @@ module Register def test_while_assign Parfait.object_space.get_main.add_local(:n , :Integer) - @input = s(:statements, s(:l_assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:l_assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n))) + @input = s(:statements, s(:l_assignment, s(:local, :n), s(:int, 5)), + s(:while_statement, :plus, s(:conditional, s(:local, :n)), + s(:statements, s(:l_assignment, s(:local, :n), + s(:operator_value, :-, s(:local, :n), s(:int, 1))))), + s(:return, s(:local, :n))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label , SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot , @@ -30,7 +34,9 @@ module Register def test_while_return Parfait.object_space.get_main.add_local(:n , :Integer) - @input = s(:statements, s(:l_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(:l_assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n))))) + @input = s(:statements, s(:l_assignment, s(:local, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:local, :n), s(:int, 5))), + s(:statements, s(:l_assignment, s(:local, :n), s(:operator_value, :+, s(:local, :n), s(:int, 1))), + s(:return, s(:local, :n))))) @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label , SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot , diff --git a/test/vm/test_to_code.rb b/test/vm/test_to_code.rb index e3860b52..963f0831 100644 --- a/test/vm/test_to_code.rb +++ b/test/vm/test_to_code.rb @@ -9,7 +9,7 @@ class ToCodeTest < MiniTest::Test end def test_field_access - @statement = s(:field_access, s(:receiver, s(:name, :m)), s(:field, s(:name, :index))) + @statement = s(:field_access, s(:receiver, s(:ivar, :m)), s(:field, s(:ivar, :index))) check "FieldAccess" end def test_simple_while @@ -17,15 +17,15 @@ class ToCodeTest < MiniTest::Test check "WhileStatement" end def test_l_assignment - @statement = s(:l_assignment, s(:name, :i), s(:int, 0)) + @statement = s(:l_assignment, s(:local, :i), s(:int, 0)) check "LocalAssignment" end def test_a_assignment - @statement = s(:a_assignment, s(:name, :i), s(:int, 0)) + @statement = s(:a_assignment, s(:arg, :i), s(:int, 0)) check "ArgAssignment" end def test_i_assignment - @statement = s(:i_assignment, s(:name, :i), s(:int, 0)) + @statement = s(:i_assignment, s(:ivar, :i), s(:int, 0)) check "IvarAssignment" end def test_nil @@ -40,9 +40,13 @@ class ToCodeTest < MiniTest::Test @statement = s(:false) check "FalseExpression" end - def test_name - @statement = s(:name, :foo) - check "NameExpression" + def test_known + @statement = s(:known, :self) + check "KnownName" + end + def test_ivar + @statement = s(:ivar, :you) + check "InstanceName" end def test_class_name @statement =s(:class_name, :FooBar)