2015-09-19 15:28:41 +02:00
|
|
|
module Bosl
|
2015-05-08 14:10:30 +02:00
|
|
|
# collection of the simple ones, int and strings and such
|
|
|
|
|
2015-09-19 17:56:18 +02:00
|
|
|
Compiler.class_eval do
|
2015-05-08 14:10:30 +02:00
|
|
|
|
|
|
|
# Constant expressions 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
|
|
|
|
|
2015-09-27 19:28:34 +02:00
|
|
|
def on_int expression
|
|
|
|
int = expression.first
|
|
|
|
to = Virtual::Return.new(Virtual::Integer , int)
|
2015-10-05 23:27:13 +02:00
|
|
|
@method.source.add_code Virtual::Set.new( int , to )
|
2015-09-27 19:28:34 +02:00
|
|
|
to
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_true expression
|
|
|
|
to = Virtual::Return.new(Virtual::Reference , true )
|
2015-10-05 23:27:13 +02:00
|
|
|
@method.source.add_code Virtual::Set.new( true , to )
|
2015-09-27 19:28:34 +02:00
|
|
|
to
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_false expression
|
|
|
|
to = Virtual::Return.new(Virtual::Reference , false)
|
2015-10-05 23:27:13 +02:00
|
|
|
@method.source.add_code Virtual::Set.new( false , to )
|
2015-09-27 19:28:34 +02:00
|
|
|
to
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_nil expression
|
|
|
|
to = Virtual::Return.new(Virtual::Reference , nil)
|
2015-10-05 23:27:13 +02:00
|
|
|
@method.source.add_code Virtual::Set.new( nil , to )
|
2015-09-27 19:28:34 +02:00
|
|
|
to
|
|
|
|
end
|
|
|
|
|
|
|
|
def on_string expression
|
|
|
|
# Clearly a TODO here to implement strings rather than reusing symbols
|
|
|
|
value = expression.first.to_sym
|
|
|
|
to = Virtual::Return.new(Virtual::Reference , value)
|
2015-10-05 23:27:13 +02:00
|
|
|
@method.source.constants << value
|
|
|
|
@method.source.add_code Virtual::Set.new( value , to )
|
2015-09-27 19:28:34 +02:00
|
|
|
to
|
|
|
|
end
|
2015-05-08 14:10:30 +02:00
|
|
|
end
|
|
|
|
end
|