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)
This commit is contained in:
2019-08-25 14:40:59 +03:00
parent c0a3c9b65c
commit b9bdc55059
10 changed files with 158 additions and 8 deletions

View File

@ -15,12 +15,11 @@ module Vool
false_label = Mom::Label.new( self , "false_label_#{object_id.to_s(16)}")
merge_label = Mom::Label.new( self , "merge_label_#{object_id.to_s(16)}")
check = Mom::TruthCheck.new(condition.to_slot(compiler) , false_label)
if @condition.is_a?(CallStatement)
head = @condition.to_mom(compiler)
head << check
head << check_slot(compiler , false_label)
else
head = check
head = check_slot(compiler , false_label)
end
head << true_label
head << if_true.to_mom(compiler) if @if_true
@ -31,6 +30,11 @@ module Vool
head
end
# create the slot lazily, so to_mom gets called first
def check_slot(compiler , false_label)
Mom::TruthCheck.new(@condition.to_slot(compiler) , false_label)
end
def each(&block)
block.call(condition)
@if_true.each(&block) if @if_true