rubyx/lib/bosl/compiler/operator_expressions.rb
Torsten Ruger f4a4ccb98e several larger changes came together, bit of cleaning too
- all code must be in functions (which must be in classes).
— changes a fair few tests
— also changes api, as method is not recursive, not passed around
- all state in instance vars in compiler (no accessors)
- class is another such variable, surely more coming
all green again
2015-10-06 00:27:13 +03:00

29 lines
798 B
Ruby

module Bosl
Compiler.class_eval do
# operator attr_reader :operator, :left, :right
def on_operator expression
operator , left , right = *expression
#raise "not quite there"
Virtual::Return.new(:int)
end
def on_assign expression
name , value = *expression
name = name.to_a.first
v = process(value)
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
end
end
end