2015-10-23 13:22:55 +02:00
|
|
|
module Soml
|
2015-09-27 10:28:06 +02:00
|
|
|
Compiler.class_eval do
|
|
|
|
|
2015-10-09 16:51:14 +02:00
|
|
|
def on_field_access statement
|
|
|
|
receiver_ast , field_ast = *statement
|
2015-11-09 22:26:37 +01:00
|
|
|
receiver = process(receiver_ast)
|
|
|
|
|
|
|
|
clazz = Register.machine.space.get_class_by_name receiver.type
|
|
|
|
|
2015-09-27 10:28:06 +02:00
|
|
|
field_name = field_ast.first_from(:name)
|
|
|
|
|
2015-11-09 22:26:37 +01:00
|
|
|
|
|
|
|
index = clazz.object_layout.variable_index(field_name)
|
|
|
|
raise "field access, but no such field:#{field_name} for class #{clazz.name}" unless index
|
|
|
|
value = use_reg(clazz.object_layout.type_at(index))
|
|
|
|
|
|
|
|
add_code Register.get_slot(statement , receiver , index, value)
|
2015-09-27 10:28:06 +02:00
|
|
|
|
2015-09-27 11:59:50 +02:00
|
|
|
value
|
2015-09-27 10:28:06 +02:00
|
|
|
end
|
2015-11-09 22:26:37 +01:00
|
|
|
|
|
|
|
def on_receiver expression
|
|
|
|
process expression.first
|
|
|
|
end
|
2015-09-27 10:28:06 +02:00
|
|
|
end
|
|
|
|
end
|