2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2019-08-25 13:40:59 +02:00
|
|
|
|
|
|
|
class MacroExpression < CallStatement
|
|
|
|
|
|
|
|
def initialize(name , arguments )
|
|
|
|
super(name , SelfExpression.new , arguments)
|
|
|
|
end
|
|
|
|
|
2019-10-03 19:55:41 +02:00
|
|
|
def to_slot(compiler)
|
2019-08-25 13:40:59 +02:00
|
|
|
parts = name.to_s.split("_")
|
2019-10-03 19:55:41 +02:00
|
|
|
class_name = "SlotMachine::#{parts.collect{|s| s.capitalize}.join}"
|
2020-03-17 10:01:37 +01:00
|
|
|
# Hmm, slightly open issue how to pass args from sol to macro
|
|
|
|
# WIP, hack for comparison
|
|
|
|
args = arguments.collect {|arg|
|
|
|
|
case arg
|
|
|
|
when Sol::SymbolConstant
|
|
|
|
arg.value
|
|
|
|
when Sol::IntegerConstant
|
|
|
|
arg.value
|
|
|
|
when Sol::LocalVariable
|
|
|
|
arg.name
|
|
|
|
else
|
|
|
|
puts "unhandled #{arg}:#{arg.class}"
|
|
|
|
arg
|
|
|
|
end
|
|
|
|
}
|
|
|
|
eval(class_name).new( self , *args)
|
2019-08-25 13:40:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# When used as right hand side, this tells what data to move to get the result into
|
|
|
|
# a varaible. It is (off course) the return value of the message
|
2020-02-17 08:29:45 +01:00
|
|
|
def to_slotted(_)
|
2020-02-15 15:02:03 +01:00
|
|
|
SlotMachine::Slotted.for(:message ,[ :return_value])
|
2019-08-25 13:40:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s(depth = 0)
|
|
|
|
sen = "X.#{name}(#{@arguments.collect{|a| a.to_s}.join(', ')})"
|
|
|
|
at_depth(depth , sen)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|