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:
35
test/vool/test_macro_expression.rb
Normal file
35
test/vool/test_macro_expression.rb
Normal file
@ -0,0 +1,35 @@
|
||||
require_relative "helper"
|
||||
module Mom
|
||||
class PlusEquals < Instruction
|
||||
attr_reader :a , :b
|
||||
def initialize(source , arg , b)
|
||||
super(source)
|
||||
@a = arg
|
||||
@b = b
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Vool
|
||||
class TestMacroMom < MiniTest::Test
|
||||
include VoolCompile
|
||||
|
||||
def setup
|
||||
@compiler = compile_first_method( "X.plus_equals(arg,1)")
|
||||
@ins = @compiler.mom_instructions.next
|
||||
end
|
||||
|
||||
def test_class_compiles
|
||||
assert_equal Mom::PlusEquals , @ins.class , @ins
|
||||
end
|
||||
def test_arg1
|
||||
assert_equal Vool::LocalVariable , @ins.a.class
|
||||
assert_equal :arg , @ins.a.name
|
||||
end
|
||||
def test_arg2
|
||||
assert_equal Vool::IntegerConstant , @ins.b.class
|
||||
assert_equal 1 , @ins.b.value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user