2015-09-19 16:28:41 +03:00
|
|
|
module Bosl
|
2015-09-19 18:56:18 +03:00
|
|
|
Compiler.class_eval do
|
2015-09-19 16:28:41 +03:00
|
|
|
# operator attr_reader :operator, :left, :right
|
2015-09-19 18:56:18 +03:00
|
|
|
def on_operator expression
|
2015-09-19 17:57:44 +03:00
|
|
|
operator , left , right = *expression
|
2015-09-23 18:35:37 +03:00
|
|
|
Virtual::Return.new(:int)
|
2015-09-19 16:28:41 +03:00
|
|
|
end
|
|
|
|
|
2015-09-19 18:56:18 +03:00
|
|
|
def on_assign expression
|
2015-09-19 16:28:41 +03:00
|
|
|
name , value = *expression
|
|
|
|
name = name.to_a.first
|
2015-09-20 16:52:26 +03:00
|
|
|
v = process(value)
|
2015-09-27 16:06:48 +03:00
|
|
|
index = method.has_local( name )
|
|
|
|
if(index)
|
|
|
|
method.source.add_code Virtual::Set.new(Virtual::FrameSlot.new(:int,index ) , v )
|
|
|
|
else
|
|
|
|
index = method.has_arg( name )
|
|
|
|
if(index)
|
|
|
|
method.source.add_code Virtual::Set.new(Virtual::ArgSlot.new(:int,index ) , v )
|
|
|
|
else
|
|
|
|
raise "must define variable #{name} before using it in #{@method.inspect}"
|
|
|
|
end
|
|
|
|
end
|
2015-09-19 16:28:41 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|