rubyx/lib/bosl/compiler/field_access.rb
Torsten Ruger f4a4ccb98e several larger changes came together, bit of cleaning too
- all code must be in functions (which must be in classes).
— changes a fair few tests
— also changes api, as method is not recursive, not passed around
- all state in instance vars in compiler (no accessors)
- class is another such variable, surely more coming
all green again
2015-10-06 00:27:13 +03:00

28 lines
774 B
Ruby

module Bosl
Compiler.class_eval do
def on_field_access expression
#puts expression.inspect
receiver_ast , field_ast = *expression
receiver = receiver_ast.first_from(:name)
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 = Virtual::Return.new(:int)
@method.source.add_code Virtual::Set.new( Virtual::SelfSlot.new(index, :int ) , value )
when :message
#message Slot
raise "message not yet"
else
#arg / frame Slot
raise "frame not implemented"
end
value
end
end
end