finish the field access
now that fields can be defined
This commit is contained in:
parent
964abe1e32
commit
5a2a857485
@ -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
|
||||||
|
@ -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"
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user