2015-10-07 14:22:47 +02:00
|
|
|
module Phisol
|
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-10-09 16:51:14 +02:00
|
|
|
def on_name statement
|
|
|
|
name = statement.to_a.first
|
2015-10-14 20:34:18 +02:00
|
|
|
return Register.self_reg(@clazz.name ) if(name == :self)
|
2015-09-19 15:28:41 +02:00
|
|
|
# either an argument, so it's stored in message
|
2015-10-05 23:27:13 +02:00
|
|
|
if( index = @method.has_arg(name))
|
2015-10-14 20:34:18 +02:00
|
|
|
ret = use_reg @method.arguments[index].type
|
|
|
|
@method.source.add_code Register.get_slot(statement , :message , index , ret )
|
|
|
|
return ret
|
2015-09-19 15:28:41 +02:00
|
|
|
else # or a local so it is in the frame
|
2015-10-05 23:27:13 +02:00
|
|
|
index = @method.has_local( name )
|
2015-09-27 15:06:48 +02:00
|
|
|
if(index)
|
2015-10-14 20:34:18 +02:00
|
|
|
ret = use_reg @method.locals[index].type
|
|
|
|
@method.source.add_code Register.get_slot(statement , :frame , index , ret )
|
|
|
|
return ret
|
2015-09-27 15:06:48 +02:00
|
|
|
end
|
2015-09-19 15:28:41 +02:00
|
|
|
end
|
2015-10-06 14:26:57 +02:00
|
|
|
raise "must define variable #{name} before using it"
|
2015-09-19 15:28:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end #module
|
|
|
|
end
|