rubyx/lib/vool/macro_expression.rb
Torsten Rüger b9bdc55059 A good start on the macro idea
I call it macro because it lets you insert basically arbitrary risc code into the ruby level. The way it works:
Reserve namespace X
map any X.some_call to a Mom instruction
by the name SomeCall
which must take the same args in constructor as given
And obviously produce whatever risc it wants
Hoping to rewrite builtin around this idea (with the existing Mom builtn instructions)
2019-08-25 14:40:59 +03:00

28 lines
718 B
Ruby

module Vool
class MacroExpression < CallStatement
def initialize(name , arguments )
super(name , SelfExpression.new , arguments)
end
def to_mom(compiler)
parts = name.to_s.split("_")
class_name = "Mom::#{parts.collect{|s| s.capitalize}.join}"
eval(class_name).new( self , *arguments)
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
def to_slot(_)
Mom::SlotDefinition.new(:message ,[ :return_value])
end
def to_s(depth = 0)
sen = "X.#{name}(#{@arguments.collect{|a| a.to_s}.join(', ')})"
at_depth(depth , sen)
end
end
end