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
34 lines
1.1 KiB
Ruby
34 lines
1.1 KiB
Ruby
module Phisol
|
|
Compiler.class_eval do
|
|
|
|
def on_assignment statement
|
|
reset_regs # statements reset registers, ie have all at their disposal
|
|
#puts statement.inspect
|
|
name , value = *statement
|
|
name = name.to_a.first
|
|
v = process(value)
|
|
raise "Not register #{v}" unless v.is_a?(Register::RegisterValue)
|
|
code = nil
|
|
if( index = @method.has_arg(name))
|
|
# TODO, check type @method.arguments[index].type
|
|
code = Register.set_slot(statement , v , :message , index )
|
|
else # or a local so it is in the frame
|
|
index = @method.has_local( name )
|
|
if(index)
|
|
# TODO, check type @method.locals[index].type
|
|
frame = use_reg(:Frame)
|
|
@method.source.add_code Register.get_slot(statement , :message , :frame , frame )
|
|
code = Register.set_slot(statement , v , frame , index )
|
|
end
|
|
end
|
|
if( code )
|
|
#puts "addin code #{code}"
|
|
@method.source.add_code code
|
|
else
|
|
raise "must define variable #{name} before using it in #{@method.inspect}"
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|