2017-01-14 19:28:44 +02:00
|
|
|
module Vm
|
2015-05-08 15:10:30 +03:00
|
|
|
# collection of the simple ones, int and strings and such
|
|
|
|
|
2016-12-09 13:40:10 +02:00
|
|
|
module BasicValues
|
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_
|
2017-01-19 09:02:29 +02:00
|
|
|
# So expressions move the data into a Risc.
|
2015-10-26 22:23:06 +02:00
|
|
|
# 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
|
|
|
|
|
2016-03-07 11:55:28 +02:00
|
|
|
def on_IntegerExpression expression
|
|
|
|
int = expression.value
|
2015-10-15 09:07:47 +03:00
|
|
|
reg = use_reg :Integer , int
|
2016-12-28 20:37:54 +02:00
|
|
|
add_load_constant( expression, int , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
|
|
|
|
2016-03-07 11:55:28 +02:00
|
|
|
def on_TrueExpression expression
|
2015-10-14 16:16:03 +03:00
|
|
|
reg = use_reg :Boolean
|
2016-12-28 20:37:54 +02:00
|
|
|
add_load_constant( expression, true , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
|
|
|
|
2016-03-07 11:55:28 +02:00
|
|
|
def on_FalseExpression expression
|
2015-10-14 16:16:03 +03:00
|
|
|
reg = use_reg :Boolean
|
2016-12-28 20:37:54 +02:00
|
|
|
add_load_constant( expression, false , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
|
|
|
|
2016-03-07 11:55:28 +02:00
|
|
|
def on_NilExpression expression
|
2015-10-14 16:16:03 +03:00
|
|
|
reg = use_reg :NilClass
|
2016-12-28 20:37:54 +02:00
|
|
|
add_load_constant( expression, nil , reg )
|
2015-10-13 16:42:53 +03:00
|
|
|
return reg
|
2015-09-27 20:28:34 +03:00
|
|
|
end
|
|
|
|
|
2016-03-07 11:55:28 +02:00
|
|
|
def on_StringExpression expression
|
|
|
|
value = Parfait.new_word expression.value.to_sym
|
2015-10-14 16:16:03 +03:00
|
|
|
reg = use_reg :Word
|
2017-01-19 09:02:29 +02:00
|
|
|
Risc.machine.constants << value
|
2016-12-28 20:37:54 +02:00
|
|
|
add_load_constant( 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
|
|
|
|
2016-03-07 11:55:28 +02:00
|
|
|
def on_ClassExpression expression
|
|
|
|
name = expression.value
|
2016-12-29 18:39:59 +02:00
|
|
|
raise "No meta class #{name}"
|
2015-10-26 22:23:06 +02:00
|
|
|
end
|
|
|
|
|
2015-05-08 15:10:30 +03:00
|
|
|
end
|
|
|
|
end
|