2015-09-19 15:28:41 +02:00
|
|
|
module Bosl
|
2015-09-19 17:56:18 +02:00
|
|
|
Compiler.class_eval do
|
2015-09-19 15:28:41 +02:00
|
|
|
|
|
|
|
# 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)
|
2015-09-19 21:24:57 +02:00
|
|
|
def on_name expression
|
2015-09-19 15:28:41 +02:00
|
|
|
name = expression.to_a.first
|
2015-09-19 21:24:57 +02:00
|
|
|
return Virtual::Self.new( Virtual::Reference.new(method.for_class)) if name == :self
|
2015-09-19 15:28:41 +02:00
|
|
|
# either an argument, so it's stored in message
|
2015-09-23 17:35:37 +02:00
|
|
|
ret = Virtual::Return.new :int
|
2015-09-19 15:28:41 +02:00
|
|
|
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)
|
2015-09-19 15:28:41 +02:00
|
|
|
else # or a local so it is in the frame
|
2015-09-27 15:06:48 +02:00
|
|
|
index = method.has_local( name )
|
|
|
|
if(index)
|
|
|
|
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index,:int ) , ret )
|
|
|
|
else
|
|
|
|
raise "must define variable #{name} before using it"
|
|
|
|
end
|
2015-09-19 15:28:41 +02:00
|
|
|
end
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
end #module
|
|
|
|
end
|