2015-10-23 13:22:55 +02:00
|
|
|
module Soml
|
2015-10-15 12:08:53 +02:00
|
|
|
Compiler.class_eval do
|
|
|
|
|
2016-03-07 10:55:28 +01:00
|
|
|
def on_Assignment statement
|
2015-10-15 12:08:53 +02:00
|
|
|
reset_regs # statements reset registers, ie have all at their disposal
|
2015-10-16 12:12:52 +02:00
|
|
|
#puts statement.inspect
|
2016-03-07 10:55:28 +01:00
|
|
|
# name , value = *statement
|
|
|
|
name_s = no_space statement.name
|
|
|
|
v = process(statement.value)
|
2015-10-15 12:08:53 +02:00
|
|
|
raise "Not register #{v}" unless v.is_a?(Register::RegisterValue)
|
|
|
|
code = nil
|
2016-03-07 10:55:28 +01:00
|
|
|
if( index = @method.has_arg(name_s.name))
|
2015-10-15 12:08:53 +02:00
|
|
|
# TODO, check type @method.arguments[index].type
|
2015-10-27 15:05:50 +01:00
|
|
|
code = Register.set_slot(statement , v , :message , Parfait::Message.get_indexed(index) )
|
2015-10-15 12:08:53 +02:00
|
|
|
else # or a local so it is in the frame
|
2016-03-07 10:55:28 +01:00
|
|
|
index = @method.has_local( name_s.name )
|
2015-10-15 12:08:53 +02:00
|
|
|
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-27 15:05:50 +01:00
|
|
|
code = Register.set_slot(statement , v , frame , Parfait::Frame.get_indexed(index) )
|
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
|