From 6d4347c7bab3926b3d850342ed5f5fd9118c45a5 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 10 Dec 2016 18:48:18 +0200 Subject: [PATCH] finish assignment tests and related code fixes --- lib/typed/compiler/assignment.rb | 12 ++--- test/typed/statements/test_assign.rb | 68 +++++++--------------------- 2 files changed, 23 insertions(+), 57 deletions(-) diff --git a/lib/typed/compiler/assignment.rb b/lib/typed/compiler/assignment.rb index 6b722aa8..9508c0da 100644 --- a/lib/typed/compiler/assignment.rb +++ b/lib/typed/compiler/assignment.rb @@ -4,23 +4,23 @@ module Typed def on_Assignment( statement ) # name , value = *statement reset_regs # statements reset registers, ie have all at their disposal - name_s = no_space statement.name value = process(statement.value) raise "Not register #{v}" unless value.is_a?(Register::RegisterValue) - code = get_code( statement , name_s , value) - raise "must define variable #{name} before using it in #{@method.inspect}" unless code + code = get_code( statement , value) + raise "must define variable #{statement.name.name} before using it in #{@method.inspect}" unless code add_code code end private - def get_code( statement , name_s , value) - if( index = @method.has_arg(name_s.name)) + def get_code( statement , value) + name = no_space(statement.name).name + if( index = @method.has_arg(name)) # TODO, check type @method.arguments[index].type return Register.set_slot(statement , value , :message , Parfait::Message.get_indexed(index) ) end # or a local so it is in the frame - index = @method.has_local( name_s.name ) + index = @method.has_local( name ) return nil unless index # TODO, check type @method.locals[index].type frame = use_reg(:Frame) diff --git a/test/typed/statements/test_assign.rb b/test/typed/statements/test_assign.rb index 273e54c2..90c9e54c 100644 --- a/test/typed/statements/test_assign.rb +++ b/test/typed/statements/test_assign.rb @@ -8,7 +8,7 @@ class TestAssignStatement < MiniTest::Test Register.machine.boot end - def _test_assign_op + def test_assign_op @input = s(:statements, s(:field_def, :Integer, s(:name, :n), s(:operator_value, :+, s(:int, 10), s(:int, 1)))) @@ -17,7 +17,7 @@ class TestAssignStatement < MiniTest::Test check end - def _test_assign_local + def test_assign_local @input = s(:statements, s(:field_def, :Integer, s(:name, :runner)), s(:assignment, s(:name, :runner), s(:int, 5))) @@ -25,41 +25,25 @@ class TestAssignStatement < MiniTest::Test check end - def _test_assign_local_assign - @input = <