2015-10-23 14:22:55 +03:00
|
|
|
module Soml
|
2015-05-08 15:10:30 +03:00
|
|
|
# collection of the simple ones, int and strings and such
|
|
|
|
|
2015-09-19 18:56:18 +03:00
|
|
|
Compiler.class_eval do
|
2015-05-08 15:10:30 +03:00
|
|
|
|
2015-10-26 22:23:06 +02:00
|
|
|
# Constant expressions can by definition be evaluated at compile time.
|
2015-05-08 15:10:30 +03:00
|
|
|
# But that does not solve their storage, ie they need to be accessible at runtime from _somewhere_
|
2015-10-26 22:23:06 +02:00
|
|
|
# So expressions move the data into a Register.
|
|
|
|
# All expressions return registers
|
2015-05-08 15:10:30 +03:00
|
|
|
|
|
|
|
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
|
|
|
|
|
2015-10-26 22:23:06 +02:00
|
|
|
def on_int expression
|
|
|
|
int = expression.first
|
2015-10-15 09:07:47 +03:00
|
|
|
reg = use_reg :Integer , int
|
2015-10-26 22:23:06 +02:00
|
|
|
add_code Register::LoadConstant.new( expression, int , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
|
|
|
|
2015-10-26 22:23:06 +02:00
|
|
|
def on_true expression
|
2015-10-14 16:16:03 +03:00
|
|
|
reg = use_reg :Boolean
|
2015-10-26 22:23:06 +02:00
|
|
|
add_code Register::LoadConstant.new( expression, true , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
|
|
|
|
2015-10-26 22:23:06 +02:00
|
|
|
def on_false expression
|
2015-10-14 16:16:03 +03:00
|
|
|
reg = use_reg :Boolean
|
2015-10-26 22:23:06 +02:00
|
|
|
add_code Register::LoadConstant.new( expression, false , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
|
|
|
|
2015-10-26 22:23:06 +02:00
|
|
|
def on_nil expression
|
2015-10-14 16:16:03 +03:00
|
|
|
reg = use_reg :NilClass
|
2015-10-26 22:23:06 +02:00
|
|
|
add_code Register::LoadConstant.new( expression, nil , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
|
|
|
|
2015-10-26 22:23:06 +02:00
|
|
|
def on_string expression
|
2015-11-18 11:55:29 +02:00
|
|
|
value = Parfait.new_word expression.first.to_sym
|
2015-10-14 16:16:03 +03:00
|
|
|
reg = use_reg :Word
|
2015-10-28 13:00:23 +02:00
|
|
|
Register.machine.constants << value
|
2015-10-26 22:23:06 +02:00
|
|
|
add_code Register::LoadConstant.new( expression, value , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
2015-10-26 22:23:06 +02:00
|
|
|
|
|
|
|
def on_class_name expression
|
|
|
|
name = expression.first
|
|
|
|
clazz = Parfait::Space.object_space.get_class_by_name! name
|
|
|
|
raise "No such class #{name}" unless clazz
|
2015-11-08 00:55:10 +02:00
|
|
|
reg = use_reg :MetaClass , clazz
|
2015-10-26 22:23:06 +02:00
|
|
|
add_code Register::LoadConstant.new( expression, clazz , reg )
|
|
|
|
return reg
|
|
|
|
end
|
|
|
|
|
2015-05-08 15:10:30 +03:00
|
|
|
end
|
|
|
|
end
|