From 6ac339d99812759ef9b93e375e4c91556a098b26 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 22 Oct 2015 15:34:47 +0300 Subject: [PATCH] catching empty blocks should really clean those away --- lib/interpreter/interpreter.rb | 5 ++++ test/interpreter/test_if.rb | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/interpreter/test_if.rb diff --git a/lib/interpreter/interpreter.rb b/lib/interpreter/interpreter.rb index a70a87cb..083719ba 100644 --- a/lib/interpreter/interpreter.rb +++ b/lib/interpreter/interpreter.rb @@ -47,6 +47,11 @@ module Interpreter return if @block == bl raise "Error, nil block" unless bl old = @block + if bl.codes.empty? + next_b = @block.method.source.blocks.index(bl) + 1 + bl = @block.method.source.blocks[next_b] + end + raise "Block #{bl.codes.empty?}" if bl.codes.empty? #just fixed, leave for next time @block = bl trigger(:block_changed , old , bl) set_instruction bl.codes.first diff --git a/test/interpreter/test_if.rb b/test/interpreter/test_if.rb new file mode 100644 index 00000000..a0fb25f0 --- /dev/null +++ b/test/interpreter/test_if.rb @@ -0,0 +1,50 @@ +require_relative "helper" + +class AddTest < MiniTest::Test + include Ticker + include AST::Sexp + + def test_if + @string_input = <