2019-08-25 13:40:59 +02:00
|
|
|
require_relative "helper"
|
2019-10-03 19:55:41 +02:00
|
|
|
module SlotMachine
|
2019-08-25 13:40:59 +02:00
|
|
|
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
|
|
|
|
|
2019-10-03 23:36:49 +02:00
|
|
|
module Sol
|
2019-10-03 19:55:41 +02:00
|
|
|
class TestMacroSlotMachine < MiniTest::Test
|
2019-10-03 23:36:49 +02:00
|
|
|
include SolCompile
|
2019-08-25 13:40:59 +02:00
|
|
|
|
|
|
|
def setup
|
2019-09-12 12:10:31 +02:00
|
|
|
@compiler = compile_main( "X.plus_equals(arg,1)")
|
2019-10-03 19:55:41 +02:00
|
|
|
@ins = @compiler.slot_instructions.next
|
2019-08-25 13:40:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_compiles
|
2019-10-03 19:55:41 +02:00
|
|
|
assert_equal SlotMachine::PlusEquals , @ins.class , @ins
|
2019-08-25 13:40:59 +02:00
|
|
|
end
|
|
|
|
def test_arg1
|
2020-03-17 10:01:37 +01:00
|
|
|
assert_equal Symbol , @ins.a.class
|
|
|
|
assert_equal :arg , @ins.a
|
2019-08-25 13:40:59 +02:00
|
|
|
end
|
|
|
|
def test_arg2
|
2020-03-17 10:01:37 +01:00
|
|
|
assert_equal Integer , @ins.b.class
|
|
|
|
assert_equal 1 , @ins.b
|
2019-08-25 13:40:59 +02:00
|
|
|
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
|