rubyx/stash/vm/method_compiler/basic_values.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

2017-01-14 18:28:44 +01:00
module Vm
# collection of the simple ones, int and strings and such
2016-12-09 12:40:10 +01:00
module BasicValues
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_
# So expressions move the data into a Risc.
2015-10-26 21:23:06 +01:00
# 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
add_load_constant( expression, int , reg )
return reg
2015-09-27 19:28:34 +02:00
end
def on_TrueExpression expression
reg = use_reg :Boolean
add_load_constant( expression, true , reg )
return reg
2015-09-27 19:28:34 +02:00
end
def on_FalseExpression expression
reg = use_reg :Boolean
add_load_constant( expression, false , reg )
return reg
2015-09-27 19:28:34 +02:00
end
def on_NilExpression expression
reg = use_reg :NilClass
add_load_constant( 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
Risc.machine.constants << value
add_load_constant( 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
2016-12-29 17:39:59 +01:00
raise "No meta class #{name}"
2015-10-26 21:23:06 +01:00
end
end
end