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)
|
2016-02-25 21:03:11 +01:00
|
|
|
|
2015-11-09 22:26:37 +01:00
|
|
|
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
|
|
|
|
2016-02-25 21:16:13 +01:00
|
|
|
index = clazz.instance_type.variable_index(field_name)
|
2015-11-09 22:26:37 +01:00
|
|
|
raise "field access, but no such field:#{field_name} for class #{clazz.name}" unless index
|
2016-02-25 21:16:13 +01:00
|
|
|
value = use_reg(clazz.instance_type.type_at(index))
|
2015-11-09 22:26:37 +01:00
|
|
|
|
|
|
|
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
|