2015-10-07 15:22:47 +03:00
|
|
|
module Phisol
|
2015-09-19 18:56:18 +03:00
|
|
|
Compiler.class_eval do
|
2015-09-19 16:28:41 +03: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-10-09 17:51:14 +03:00
|
|
|
def on_name statement
|
|
|
|
name = statement.to_a.first
|
2015-10-06 00:27:13 +03:00
|
|
|
return Virtual::Self.new( Virtual::Reference.new(@clazz)) if name == :self
|
2015-09-19 16:28:41 +03:00
|
|
|
# either an argument, so it's stored in message
|
2015-10-06 00:27:13 +03:00
|
|
|
if( index = @method.has_arg(name))
|
2015-10-06 15:26:57 +03:00
|
|
|
type = @method.arguments[index].type
|
|
|
|
return Virtual::ArgSlot.new(index , type )
|
2015-09-19 16:28:41 +03:00
|
|
|
else # or a local so it is in the frame
|
2015-10-06 00:27:13 +03:00
|
|
|
index = @method.has_local( name )
|
2015-09-27 16:06:48 +03:00
|
|
|
if(index)
|
2015-10-06 15:26:57 +03:00
|
|
|
type = @method.locals[index].type
|
|
|
|
return Virtual::FrameSlot.new(index, type )
|
2015-09-27 16:06:48 +03:00
|
|
|
end
|
2015-09-19 16:28:41 +03:00
|
|
|
end
|
2015-10-06 15:26:57 +03:00
|
|
|
raise "must define variable #{name} before using it"
|
2015-09-19 16:28:41 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
end #module
|
|
|
|
end
|