2019-08-25 13:40:59 +02:00
|
|
|
require_relative "helper"
|
|
|
|
module Mom
|
|
|
|
class PlusEquals < Instruction
|
|
|
|
attr_reader :a , :b
|
|
|
|
def initialize(source , arg , b)
|
|
|
|
super(source)
|
|
|
|
@a = arg
|
|
|
|
@b = b
|
|
|
|
end
|
2019-09-13 19:34:41 +02:00
|
|
|
def to_risc(compiler)
|
|
|
|
Risc.label("some" , "thing")
|
|
|
|
end
|
2019-08-25 13:40:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module Vool
|
|
|
|
class TestMacroMom < MiniTest::Test
|
|
|
|
include VoolCompile
|
|
|
|
|
|
|
|
def setup
|
2019-09-12 12:10:31 +02:00
|
|
|
@compiler = compile_main( "X.plus_equals(arg,1)")
|
2019-08-25 13:40:59 +02:00
|
|
|
@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
|
2019-09-13 19:34:41 +02:00
|
|
|
def test_to_risc
|
|
|
|
comp = @compiler.to_risc
|
|
|
|
assert_equal Risc::MethodCompiler , comp.class
|
|
|
|
assert_equal :main , comp.callable.name
|
|
|
|
end
|
2019-08-25 13:40:59 +02:00
|
|
|
end
|
|
|
|
end
|