2015-10-23 13:22:55 +02:00
|
|
|
module Soml
|
2015-10-15 12:08:53 +02:00
|
|
|
Compiler.class_eval do
|
|
|
|
|
|
|
|
def on_assignment statement
|
|
|
|
reset_regs # statements reset registers, ie have all at their disposal
|
2015-10-16 12:12:52 +02:00
|
|
|
#puts statement.inspect
|
2015-10-15 12:08:53 +02:00
|
|
|
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
|
2015-10-22 10:02:46 +02:00
|
|
|
code = Register.set_slot(statement , v , :message , index + Parfait::Message.offset )
|
2015-10-15 12:08:53 +02:00
|
|
|
else # or a local so it is in the frame
|
|
|
|
index = @method.has_local( name )
|
|
|
|
if(index)
|
|
|
|
# TODO, check type @method.locals[index].type
|
2015-10-18 16:20:19 +02:00
|
|
|
frame = use_reg(:Frame)
|
2015-10-23 13:08:12 +02:00
|
|
|
add_code Register.get_slot(statement , :message , :frame , frame )
|
2015-10-22 10:02:46 +02:00
|
|
|
code = Register.set_slot(statement , v , frame , index + Parfait::Frame.offset )
|
2015-10-15 12:08:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if( code )
|
2015-10-16 12:20:21 +02:00
|
|
|
#puts "addin code #{code}"
|
2015-10-23 13:08:12 +02:00
|
|
|
add_code code
|
2015-10-15 12:08:53 +02:00
|
|
|
else
|
|
|
|
raise "must define variable #{name} before using it in #{@method.inspect}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|