6c7e4c0fe2
before: r0-message , r1-self , r2-frame , r3-new_message , r4 + tmps now: r0-message , r1-new_message , r2 + tmps programs got smaller, less fuss also fix in return implementation that got the address from the wrong message
35 lines
1.3 KiB
Ruby
35 lines
1.3 KiB
Ruby
module Phisol
|
|
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 statement
|
|
name = statement.to_a.first
|
|
if( name == :self)
|
|
ret = use_reg @clazz.name
|
|
@method.source.add_code Register.get_slot(statement , :message , :receiver , ret )
|
|
return ret
|
|
end
|
|
# either an argument, so it's stored in message
|
|
if( index = @method.has_arg(name))
|
|
ret = use_reg @method.arguments[index].type
|
|
@method.source.add_code Register.get_slot(statement , :message , index , ret )
|
|
return ret
|
|
else # or a local so it is in the frame
|
|
index = @method.has_local( name )
|
|
if(index)
|
|
frame = use_reg :Frame
|
|
@method.source.add_code Register.get_slot(statement , :message , :frame , frame )
|
|
ret = use_reg @method.locals[index].type
|
|
@method.source.add_code Register.get_slot(statement , frame , index , ret )
|
|
return ret
|
|
end
|
|
end
|
|
raise "must define variable #{name} before using it"
|
|
end
|
|
|
|
end #module
|
|
end
|