rubyx/test/risc/test_builder1.rb
Torsten Ruger 37461a1727 add the ! syntax to create variables in builder, fix #8
now a variable has to be created before being used
thus it is save to develop contracts where a certain name
must exist in the scope
Maybe the syntax starts getting a bit weird, but at least the ! is a common symbol in ruby
2018-08-14 19:39:46 +03:00

37 lines
1.2 KiB
Ruby

require_relative "../helper"
module Risc
class TestCompilerBuilder < MiniTest::Test
def setup
Parfait.boot!
Risc.boot!
@init = Parfait.object_space.get_init
@compiler = Risc::MethodCompiler.new( @init )
@builder = @compiler.compiler_builder(@init)
end
def test_inserts_built
r1 = RegisterValue.new(:r1 , :Space)
@builder.build{ space! << r1 }
assert_equal Transfer , @compiler.risc_instructions.next.class
assert_equal RegisterValue , @builder.space.class
end
def test_loads
@builder.build{ space! << Parfait.object_space }
assert_equal LoadConstant , @compiler.risc_instructions.next.class
assert_equal RegisterValue , @builder.space.class
end
def test_two
@builder.build{ space! << Parfait.object_space ; integer! << 1}
assert_equal LoadConstant , @compiler.risc_instructions.next.class
assert_equal LoadData , @compiler.risc_instructions.next(2).class
end
def test_swap
test_two
@builder.swap_names( :space , :integer)
assert_equal :Integer , @builder.space.type.class_name
assert_equal :Space , @builder.integer.type.class_name
end
end
end