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
|
|
|
|
#puts statement.inspect
|
|
|
|
receiver_ast , field_ast = *statement
|
2015-09-27 10:28:06 +02:00
|
|
|
receiver = receiver_ast.first_from(:name)
|
|
|
|
field_name = field_ast.first_from(:name)
|
|
|
|
|
|
|
|
case receiver
|
|
|
|
when :self
|
2015-10-05 23:27:13 +02:00
|
|
|
index = @clazz.object_layout.variable_index(field_name)
|
|
|
|
raise "field access, but no such field:#{field_name} for class #{@clazz.name}" unless index
|
2015-11-08 12:39:13 +01:00
|
|
|
value = use_reg(@clazz.name) #TODO incorrect, this is the self, but should be the type of variable at index
|
2015-10-23 13:08:12 +02:00
|
|
|
add_code Register.get_slot(statement , :message , :receiver , value )
|
2015-10-18 16:20:19 +02:00
|
|
|
# reuse the register for next move
|
|
|
|
move = Register.get_slot(statement, value , index , value )
|
2015-10-23 13:08:12 +02:00
|
|
|
add_code move
|
2015-09-27 10:28:06 +02:00
|
|
|
when :message
|
|
|
|
#message Slot
|
2015-11-08 12:55:38 +01:00
|
|
|
value = Register.message_reg
|
2015-09-27 10:28:06 +02:00
|
|
|
else
|
2015-11-08 12:39:13 +01:00
|
|
|
if( index = @method.has_arg(receiver)) #argument
|
|
|
|
value = use_reg @method.arguments[index].type
|
|
|
|
code = Register.get_slot(statement , :message , Parfait::Message.get_indexed(index), value)
|
|
|
|
else # or a local so it is in the frame
|
|
|
|
index = @method.has_local( receiver )
|
|
|
|
if(index)
|
|
|
|
value = use_reg @method.locals[index].type
|
|
|
|
frame = use_reg :Frame
|
|
|
|
add_code Register.get_slot(statement , :message , :frame , frame )
|
|
|
|
code = Register.get_slot(statement ,frame , Parfait::Frame.get_indexed(index) , value )
|
|
|
|
else
|
2015-11-08 12:55:38 +01:00
|
|
|
raise "Variable not defined #{receiver}"
|
2015-11-08 12:39:13 +01:00
|
|
|
end
|
|
|
|
end
|
2015-09-27 10:28:06 +02:00
|
|
|
end
|
|
|
|
|
2015-09-27 11:59:50 +02:00
|
|
|
value
|
2015-09-27 10:28:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|