diff --git a/lib/register/instruction.rb b/lib/register/instruction.rb index 0002d751..2123f7cf 100644 --- a/lib/register/instruction.rb +++ b/lib/register/instruction.rb @@ -16,8 +16,10 @@ module Register include Positioned def initialize source , nekst = nil - @source = source - @next = nekst + @source = source + @next = nekst + return unless source + raise "Source must be string or ast node, not #{source.class}" unless source.is_a?(String) or source.is_a?(AST::Node) end attr_reader :source diff --git a/test/register/test_instructions.rb b/test/register/test_instructions.rb index 4e286a55..d904fd61 100644 --- a/test/register/test_instructions.rb +++ b/test/register/test_instructions.rb @@ -3,9 +3,9 @@ require_relative "../helper" module Register class TestInstructions < MiniTest::Test def setup - @label = Label.new(nil , "test") - @branch = Branch.new(nil , @label) - @instruction = Instruction.new(nil) + @label = Label.new("test" , "test") + @branch = Branch.new("test" , @label) + @instruction = Instruction.new("test") end def test_branch_tos1 assert @branch.to_s.include?("Branch")