rubyx/lib/bosl/compiler/operator_expressions.rb

30 lines
831 B
Ruby
Raw Normal View History

module Bosl
Compiler.class_eval do
# operator attr_reader :operator, :left, :right
def on_operator expression
2015-09-19 16:57:44 +02:00
operator , left , right = *expression
#raise "not quite there"
2015-09-23 17:35:37 +02:00
Virtual::Return.new(:int)
end
def on_assign expression
2015-10-06 14:26:57 +02:00
puts expression.inspect
name , value = *expression
name = name.to_a.first
2015-09-20 15:52:26 +02:00
v = process(value)
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
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
end
end
end