rubyx/lib/bosl/compiler/name_expression.rb

24 lines
940 B
Ruby
Raw Normal View History

module Bosl
Compiler.class_eval do
# attr_reader :name
# compiling name needs to check if it's a variable and if so resolve it
# otherwise it's a method without args and a send is issued.
# whichever way this goes the result is stored in the return slot (as all compiles)
def on_name expression
name = expression.to_a.first
return Virtual::Self.new( Virtual::Reference.new(method.for_class)) if name == :self
# either an argument, so it's stored in message
2015-09-23 17:35:37 +02:00
ret = Virtual::Return.new :int
if( index = method.has_arg(name))
2015-09-27 11:59:26 +02:00
method.source.add_code Virtual::Set.new( Virtual::ArgSlot.new(index,:int ) , ret)
else # or a local so it is in the frame
index = method.ensure_local( name )
2015-09-27 11:59:26 +02:00
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index,:int ) , ret )
end
return ret
end
end #module
end