finish the field access

now that fields can be defined
This commit is contained in:
Torsten Ruger 2015-09-27 12:59:50 +03:00
parent 964abe1e32
commit 5a2a857485
3 changed files with 8 additions and 7 deletions

View File

@ -2,7 +2,7 @@ module Bosl
Compiler.class_eval do Compiler.class_eval do
def on_field_access expression def on_field_access expression
puts expression.inspect #puts expression.inspect
receiver_ast , field_ast = *expression receiver_ast , field_ast = *expression
receiver = receiver_ast.first_from(:name) receiver = receiver_ast.first_from(:name)
field_name = field_ast.first_from(:name) field_name = field_ast.first_from(:name)
@ -11,9 +11,9 @@ module Bosl
when :self when :self
for_class = self.method.for_class for_class = self.method.for_class
index = for_class.object_layout.variable_index(field_name) index = for_class.object_layout.variable_index(field_name)
raise "field access, but no such field:#{field_name} for class #{for_class.name}" raise "field access, but no such field:#{field_name} for class #{for_class.name}" unless index
method.source.add_code Virtual::Set.new( Virtual::ArgSlot.new(:int,index ) , ret) value = Virtual::Return.new(:int)
method.source.add_code Virtual::Set.new( Virtual::SelfSlot.new(index, :int ) , value )
when :message when :message
#message Slot #message Slot
raise "message not yet" raise "message not yet"
@ -22,7 +22,7 @@ module Bosl
raise "frame not implemented" raise "frame not implemented"
end end
Virtual::Return.new( value ) value
end end
end end
end end

View File

@ -2,3 +2,4 @@ require_relative "test_basic"
require_relative "test_methods" require_relative "test_methods"
require_relative "test_hello" require_relative "test_hello"
require_relative "test_compiler" require_relative "test_compiler"
require_relative "test_field_access"

View File

@ -7,13 +7,13 @@ module Virtual
def test_foo2 def test_foo2
@string_input = <<HERE @string_input = <<HERE
int a field int a
int foo(int x) int foo(int x)
int b = self.a int b = self.a
return b +x return b +x
end end
HERE HERE
@expect = [ Virtual::Return ] @output = [ [Virtual::MethodEnter] , [Virtual::MethodReturn] ]
check check
end end