2017-01-14 18:28:44 +01:00
|
|
|
module Vm
|
2016-12-09 12:20:48 +01:00
|
|
|
module Assignment
|
2015-10-15 12:08:53 +02:00
|
|
|
|
2016-12-09 12:20:48 +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
|
2016-12-10 17:08:21 +01:00
|
|
|
value = process(statement.value)
|
|
|
|
raise "Not register #{v}" unless value.is_a?(Register::RegisterValue)
|
2016-12-28 18:20:16 +01:00
|
|
|
name = check_name(statement.name.name)
|
2016-12-21 21:35:36 +01:00
|
|
|
named_list = use_reg(:NamedList)
|
2016-12-10 17:48:18 +01:00
|
|
|
if( index = @method.has_arg(name))
|
2016-12-21 21:35:36 +01:00
|
|
|
type = :arguments
|
2016-12-28 18:20:16 +01:00
|
|
|
value_type = @method.argument_type( index )
|
2016-12-21 21:35:36 +01:00
|
|
|
else
|
|
|
|
index = @method.has_local( name )
|
|
|
|
type = :locals
|
2016-12-28 18:20:16 +01:00
|
|
|
raise "must define variable #{statement.name.name} before using it in #{@method.inspect}" unless index
|
|
|
|
value_type = @method.locals_type( index )
|
2015-10-15 12:08:53 +02:00
|
|
|
end
|
2016-12-28 18:20:16 +01:00
|
|
|
raise "Type mismatch for #{type} access #{value.type}!=#{value_type}" unless value.type == value_type
|
2016-12-28 19:37:54 +01:00
|
|
|
add_slot_to_reg(statement , :message , type , named_list )
|
|
|
|
add_reg_to_slot(statement , value , named_list , index + 1 ) # one for type
|
2015-10-15 12:08:53 +02:00
|
|
|
end
|
2016-12-28 18:20:16 +01:00
|
|
|
|
|
|
|
# ensure the name given is not space and raise exception otherwise
|
|
|
|
# return the name
|
|
|
|
def check_name( name )
|
|
|
|
raise "space is a reserved name" if name == :space
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
2015-10-15 12:08:53 +02:00
|
|
|
end
|
|
|
|
end
|