2015-10-07 14:22:47 +02:00
|
|
|
module Phisol
|
2015-09-19 17:56:18 +02:00
|
|
|
Compiler.class_eval do
|
2015-10-07 09:05:34 +02:00
|
|
|
|
2015-10-09 17:06:00 +02:00
|
|
|
def on_operator_value statement
|
2015-10-09 16:51:14 +02:00
|
|
|
puts "operator #{statement.inspect}"
|
|
|
|
operator , left_e , right_e = *statement
|
2015-10-07 09:05:34 +02:00
|
|
|
left_slot = process(left_e)
|
|
|
|
right_slot = process(right_e)
|
|
|
|
puts "left #{left_slot}"
|
|
|
|
puts "right #{right_slot}"
|
2015-10-10 10:05:55 +02:00
|
|
|
tmp1 = use_reg
|
|
|
|
tmp2 = use_reg
|
2015-10-09 16:51:14 +02:00
|
|
|
get = Register.get_slot_to(statement , left_slot , tmp1 )
|
|
|
|
get2 = Register.get_slot_to(statement , right_slot , tmp2 )
|
2015-10-07 09:05:34 +02:00
|
|
|
puts "GET #{get}"
|
|
|
|
puts "GET2 #{get2}"
|
|
|
|
@method.source.add_code get
|
|
|
|
@method.source.add_code get2
|
|
|
|
|
2015-10-09 16:51:14 +02:00
|
|
|
@method.source.add_code Register::OperatorInstruction.new(statement,operator, tmp1,tmp2)
|
2015-10-10 10:05:55 +02:00
|
|
|
release_reg tmp2
|
|
|
|
release_reg tmp1
|
2015-10-07 09:05:34 +02:00
|
|
|
Virtual::Return.new(:int )
|
2015-09-19 15:28:41 +02:00
|
|
|
end
|
|
|
|
|
2015-10-09 17:06:00 +02:00
|
|
|
def on_assignment statement
|
2015-10-09 16:51:14 +02:00
|
|
|
puts statement.inspect
|
|
|
|
name , value = *statement
|
2015-09-19 15:28:41 +02:00
|
|
|
name = name.to_a.first
|
2015-09-20 15:52:26 +02:00
|
|
|
v = process(value)
|
2015-10-05 23:27:13 +02:00
|
|
|
index = @method.has_local( name )
|
2015-09-27 15:06:48 +02:00
|
|
|
if(index)
|
2015-10-06 14:26:57 +02:00
|
|
|
@method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(index, :int ) , v )
|
2015-09-27 15:06:48 +02:00
|
|
|
else
|
2015-10-05 23:27:13 +02:00
|
|
|
index = @method.has_arg( name )
|
2015-09-27 15:06:48 +02:00
|
|
|
if(index)
|
2015-10-06 14:26:57 +02:00
|
|
|
@method.source.add_code Virtual::Set.new(Virtual::ArgSlot.new(index , :int ) , v )
|
2015-09-27 15:06:48 +02:00
|
|
|
else
|
|
|
|
raise "must define variable #{name} before using it in #{@method.inspect}"
|
|
|
|
end
|
|
|
|
end
|
2015-09-19 15:28:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|