rewrite of field access using on_name
much cleaner and revealed a bug
This commit is contained in:
parent
dd7973875c
commit
368263d5a5
@ -2,41 +2,25 @@ module Soml
|
||||
Compiler.class_eval do
|
||||
|
||||
def on_field_access statement
|
||||
#puts statement.inspect
|
||||
receiver_ast , field_ast = *statement
|
||||
receiver = receiver_ast.first_from(:name)
|
||||
receiver = process(receiver_ast)
|
||||
|
||||
clazz = Register.machine.space.get_class_by_name receiver.type
|
||||
|
||||
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
|
||||
value = use_reg(@clazz.name) #TODO incorrect, this is the self, but should be the type of variable at index
|
||||
add_code Register.get_slot(statement , :message , :receiver , value )
|
||||
# reuse the register for next move
|
||||
move = Register.get_slot(statement, value , index , value )
|
||||
add_code move
|
||||
when :message
|
||||
#message Slot
|
||||
value = Register.message_reg
|
||||
else
|
||||
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
|
||||
raise "Variable not defined #{receiver}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
value
|
||||
end
|
||||
|
||||
def on_receiver expression
|
||||
process expression.first
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user