rubyx/lib/soml/compiler/basic_values.rb

57 lines
1.7 KiB
Ruby
Raw Normal View History

2015-10-23 13:22:55 +02:00
module Soml
# collection of the simple ones, int and strings and such
Compiler.class_eval do
2015-10-26 21:23:06 +01: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_
2015-10-26 21:23:06 +01:00
# So expressions move the data into a Register.
# All expressions return registers
# But in the future (in the one that holds great things) we optimize those unneccesay moves away
def on_IntegerExpression expression
int = expression.value
reg = use_reg :Integer , int
2015-10-26 21:23:06 +01:00
add_code Register::LoadConstant.new( expression, int , reg )
return reg
2015-09-27 19:28:34 +02:00
end
def on_TrueExpression expression
reg = use_reg :Boolean
2015-10-26 21:23:06 +01:00
add_code Register::LoadConstant.new( expression, true , reg )
return reg
2015-09-27 19:28:34 +02:00
end
def on_FalseExpression expression
reg = use_reg :Boolean
2015-10-26 21:23:06 +01:00
add_code Register::LoadConstant.new( expression, false , reg )
return reg
2015-09-27 19:28:34 +02:00
end
def on_NilExpression expression
reg = use_reg :NilClass
2015-10-26 21:23:06 +01:00
add_code Register::LoadConstant.new( expression, nil , reg )
return reg
2015-09-27 19:28:34 +02:00
end
def on_StringExpression expression
value = Parfait.new_word expression.value.to_sym
reg = use_reg :Word
2015-10-28 12:00:23 +01:00
Register.machine.constants << value
2015-10-26 21:23:06 +01:00
add_code Register::LoadConstant.new( expression, value , reg )
return reg
2015-09-27 19:28:34 +02:00
end
2015-10-26 21:23:06 +01:00
def on_ClassExpression expression
name = expression.value
2015-10-26 21:23:06 +01:00
clazz = Parfait::Space.object_space.get_class_by_name! name
raise "No such class #{name}" unless clazz
2015-11-07 23:55:10 +01:00
reg = use_reg :MetaClass , clazz
2015-10-26 21:23:06 +01:00
add_code Register::LoadConstant.new( expression, clazz , reg )
return reg
end
end
end