rubyx/lib/phisol/compiler/field_access.rb

30 lines
823 B
Ruby
Raw Normal View History

2015-10-07 14:22:47 +02:00
module Phisol
Compiler.class_eval do
def on_field_access statement
#puts statement.inspect
receiver_ast , field_ast = *statement
receiver = receiver_ast.first_from(:name)
field_name = field_ast.first_from(:name)
case receiver
when :self
index = @clazz.object_layout.variable_index(field_name)
raise "field access, but no such field:#{field_name} for class #{@clazz.name}" unless index
2015-10-15 08:32:47 +02:00
value = use_reg(:Integer) #TODO, need types in layout
move = Register.get_slot(statement, :self , index , value )
@method.source.add_code move
return value
when :message
#message Slot
raise "message not yet"
else
#arg / frame Slot
raise "frame not implemented"
end
value
end
end
end