2015-10-07 14:22:47 +02:00
|
|
|
module Phisol
|
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
|
|
|
|
2015-10-09 16:51:14 +02:00
|
|
|
# Constant statements can by definition be evaluated at compile time.
|
2015-05-08 14:10:30 +02:00
|
|
|
# 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-10-09 16:51:14 +02:00
|
|
|
def on_int statement
|
|
|
|
int = statement.first
|
2015-10-13 15:42:53 +02:00
|
|
|
reg = use_reg :int
|
|
|
|
@method.source.add_code Register::LoadConstant.new( statement, int , reg )
|
|
|
|
return reg
|
2015-09-27 19:28:34 +02:00
|
|
|
end
|
|
|
|
|
2015-10-09 16:51:14 +02:00
|
|
|
def on_true statement
|
2015-10-13 15:42:53 +02:00
|
|
|
reg = use_reg :ref
|
|
|
|
@method.source.add_code Register::LoadConstant.new( statement, true , reg )
|
|
|
|
return reg
|
2015-09-27 19:28:34 +02:00
|
|
|
end
|
|
|
|
|
2015-10-09 16:51:14 +02:00
|
|
|
def on_false statement
|
2015-10-13 15:42:53 +02:00
|
|
|
reg = use_reg :ref
|
|
|
|
@method.source.add_code Register::LoadConstant.new( statement, false , reg )
|
|
|
|
return reg
|
2015-09-27 19:28:34 +02:00
|
|
|
end
|
|
|
|
|
2015-10-09 16:51:14 +02:00
|
|
|
def on_nil statement
|
2015-10-13 15:42:53 +02:00
|
|
|
reg = use_reg :ref
|
|
|
|
@method.source.add_code Register::LoadConstant.new( statement, nil , reg )
|
|
|
|
return reg
|
2015-09-27 19:28:34 +02:00
|
|
|
end
|
|
|
|
|
2015-10-09 16:51:14 +02:00
|
|
|
def on_string statement
|
|
|
|
value = statement.first.to_sym
|
2015-10-13 15:42:53 +02:00
|
|
|
reg = use_reg :ref
|
2015-10-05 23:27:13 +02:00
|
|
|
@method.source.constants << value
|
2015-10-13 15:42:53 +02:00
|
|
|
@method.source.add_code Register::LoadConstant.new( statement, value , reg )
|
|
|
|
return reg
|
2015-09-27 19:28:34 +02:00
|
|
|
end
|
2015-05-08 14:10:30 +02:00
|
|
|
end
|
|
|
|
end
|