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
|
||||
|
||||
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
|
||||
|
@ -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"
|
||||
|
@ -7,13 +7,13 @@ module Virtual
|
||||
|
||||
def test_foo2
|
||||
@string_input = <<HERE
|
||||
int a
|
||||
field int a
|
||||
int foo(int x)
|
||||
int b = self.a
|
||||
return b +x
|
||||
end
|
||||
HERE
|
||||
@expect = [ Virtual::Return ]
|
||||
@output = [ [Virtual::MethodEnter] , [Virtual::MethodReturn] ]
|
||||
check
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user