rubyx/stash/vm/method_compiler/field_access.rb

28 lines
669 B
Ruby
Raw Normal View History

2017-01-14 18:28:44 +01:00
module Vm
2016-12-09 13:04:06 +01:00
module FieldAccess
def on_FieldAccess statement
# receiver_ast , field_ast = *statement
receiver = process(statement.receiver)
2016-02-25 21:03:11 +01:00
2016-12-14 12:24:42 +01:00
type = receiver.type
if(type.is_a?(Symbol))
type = Parfait.object_space.get_class_by_name(type).instance_type
2016-12-14 12:24:42 +01:00
end
field_name = statement.field.name
2016-12-14 12:24:42 +01:00
index = type.variable_index(field_name)
raise "no such field:#{field_name} for class #{type.inspect}" unless index
value = use_reg(type.type_at(index))
add_slot_to_reg(statement , receiver , index, value)
value
end
def on_receiver expression
process expression.first
end
end
end