rubyx/lib/phisol/compiler/basic_values.rb
2015-10-10 19:14:27 +03:00

50 lines
1.6 KiB
Ruby

module Phisol
# collection of the simple ones, int and strings and such
Compiler.class_eval do
# Constant statements can by definition be evaluated at compile time.
# But that does not solve their storage, ie they need to be accessible at runtime from _somewhere_
# So we view ConstantExpressions like functions that return the value of the constant.
# In other words, their storage is the return slot as it would be for a method
# The current approach moves the constant into a variable before using it
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
def on_int statement
int = statement.first
# reg =
to = Virtual::Return.new(Phisol::Integer , int)
@method.source.add_code Virtual::Set.new( int , to )
to
end
def on_true statement
to = Virtual::Return.new(Phisol::Reference , true )
@method.source.add_code Virtual::Set.new( true , to )
to
end
def on_false statement
to = Virtual::Return.new(Phisol::Reference , false)
@method.source.add_code Virtual::Set.new( false , to )
to
end
def on_nil statement
to = Virtual::Return.new(Phisol::Reference , nil)
@method.source.add_code Virtual::Set.new( nil , to )
to
end
def on_string statement
# Clearly a TODO here to implement strings rather than reusing symbols
value = statement.first.to_sym
to = Virtual::Return.new(Phisol::Reference , value)
@method.source.constants << value
@method.source.add_code Virtual::Set.new( value , to )
to
end
end
end