From 5a2a8574859e353f4ecf38f4b674dc8a13311f1b Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 27 Sep 2015 12:59:50 +0300 Subject: [PATCH] finish the field access now that fields can be defined --- lib/bosl/compiler/field_access.rb | 10 +++++----- test/compiler/test_all.rb | 1 + test/compiler/test_field_access.rb | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/bosl/compiler/field_access.rb b/lib/bosl/compiler/field_access.rb index 7efb76c1..03ceb45b 100644 --- a/lib/bosl/compiler/field_access.rb +++ b/lib/bosl/compiler/field_access.rb @@ -2,7 +2,7 @@ module Bosl Compiler.class_eval do def on_field_access expression - puts expression.inspect + #puts expression.inspect receiver_ast , field_ast = *expression receiver = receiver_ast.first_from(:name) field_name = field_ast.first_from(:name) @@ -11,9 +11,9 @@ module Bosl when :self for_class = self.method.for_class index = for_class.object_layout.variable_index(field_name) - raise "field access, but no such field:#{field_name} for class #{for_class.name}" - method.source.add_code Virtual::Set.new( Virtual::ArgSlot.new(:int,index ) , ret) - + raise "field access, but no such field:#{field_name} for class #{for_class.name}" unless index + value = Virtual::Return.new(:int) + method.source.add_code Virtual::Set.new( Virtual::SelfSlot.new(index, :int ) , value ) when :message #message Slot raise "message not yet" @@ -22,7 +22,7 @@ module Bosl raise "frame not implemented" end - Virtual::Return.new( value ) + value end end end diff --git a/test/compiler/test_all.rb b/test/compiler/test_all.rb index bc9fce80..cd863bb4 100644 --- a/test/compiler/test_all.rb +++ b/test/compiler/test_all.rb @@ -2,3 +2,4 @@ require_relative "test_basic" require_relative "test_methods" require_relative "test_hello" require_relative "test_compiler" +require_relative "test_field_access" diff --git a/test/compiler/test_field_access.rb b/test/compiler/test_field_access.rb index c719093d..419f541f 100644 --- a/test/compiler/test_field_access.rb +++ b/test/compiler/test_field_access.rb @@ -7,13 +7,13 @@ module Virtual def test_foo2 @string_input = <