From f105b1eb3ca179b5df9e712c8747f6ad2aa46bf4 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 14 Oct 2015 21:34:18 +0300 Subject: [PATCH] fix name expression --- lib/phisol/compiler/name_expression.rb | 12 +++++++----- lib/register/register_value.rb | 2 +- test/compiler/test_basic.rb | 1 - test/compiler/test_call.rb | 2 +- test/compiler/test_field_access.rb | 18 +++++++++++++++++- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/phisol/compiler/name_expression.rb b/lib/phisol/compiler/name_expression.rb index 5c431f43..73e6849a 100644 --- a/lib/phisol/compiler/name_expression.rb +++ b/lib/phisol/compiler/name_expression.rb @@ -7,16 +7,18 @@ module Phisol # whichever way this goes the result is stored in the return slot (as all compiles) def on_name statement name = statement.to_a.first - return Virtual::Self.new( @clazz) if name == :self + return Register.self_reg(@clazz.name ) if(name == :self) # either an argument, so it's stored in message if( index = @method.has_arg(name)) - type = @method.arguments[index].type - return Virtual::ArgSlot.new(index , type ) + ret = use_reg @method.arguments[index].type + @method.source.add_code Register.get_slot(statement , :message , index , ret ) + return ret else # or a local so it is in the frame index = @method.has_local( name ) if(index) - type = @method.locals[index].type - return Virtual::FrameSlot.new(index, type ) + ret = use_reg @method.locals[index].type + @method.source.add_code Register.get_slot(statement , :frame , index , ret ) + return ret end end raise "must define variable #{name} before using it" diff --git a/lib/register/register_value.rb b/lib/register/register_value.rb index 8ff12128..be4dda38 100644 --- a/lib/register/register_value.rb +++ b/lib/register/register_value.rb @@ -116,7 +116,7 @@ module Register when :new_message register = new_message_reg when :self - register = self_reg(:Object) #TODO , prpbably have to get rid of this resolve method + register = self_reg(:Object) #TODO , probably have to get rid of this resolve method when :frame register = frame_reg else diff --git a/test/compiler/test_basic.rb b/test/compiler/test_basic.rb index 5c221d81..f6e213e2 100644 --- a/test/compiler/test_basic.rb +++ b/test/compiler/test_basic.rb @@ -36,7 +36,6 @@ class TestBasic < MiniTest::Test def test_self @string_input = 'self ' - @output = Virtual::Self check end diff --git a/test/compiler/test_call.rb b/test/compiler/test_call.rb index 3e853c94..ee06c615 100644 --- a/test/compiler/test_call.rb +++ b/test/compiler/test_call.rb @@ -36,7 +36,7 @@ module Virtual check end - def ttest_call_main_op + def test_call_main_op Virtual.machine.space.get_main.ensure_local(:bar , :Integer) @root = :call_site @string_input = 'main( bar )' diff --git a/test/compiler/test_field_access.rb b/test/compiler/test_field_access.rb index d5ba9e6b..d86d3b30 100644 --- a/test/compiler/test_field_access.rb +++ b/test/compiler/test_field_access.rb @@ -23,7 +23,23 @@ HERE self.bro HERE @output = Register::RegisterValue - check + check + end + + def test_local + Virtual.machine.space.get_main.ensure_local(:bar , :Integer) + @root = :name + @string_input = 'bar ' + @output = Register::RegisterValue + check + end + + def test_args + Virtual.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :bar) + @root = :name + @string_input = 'bar ' + @output = Register::RegisterValue + check end end