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