catching empty blocks
should really clean those away
This commit is contained in:
parent
b932f67da0
commit
6ac339d998
@ -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
|
||||
|
50
test/interpreter/test_if.rb
Normal file
50
test/interpreter/test_if.rb
Normal file
@ -0,0 +1,50 @@
|
||||
require_relative "helper"
|
||||
|
||||
class AddTest < MiniTest::Test
|
||||
include Ticker
|
||||
include AST::Sexp
|
||||
|
||||
def test_if
|
||||
@string_input = <<HERE
|
||||
class Object
|
||||
int itest(int n)
|
||||
if_zero( n - 12)
|
||||
"then".putstring()
|
||||
else
|
||||
"else".putstring()
|
||||
end
|
||||
end
|
||||
|
||||
int main()
|
||||
itest(20)
|
||||
end
|
||||
end
|
||||
HERE
|
||||
machine = Virtual.machine.boot
|
||||
syntax = Parser::Salama.new.parse_with_debug(@string_input)
|
||||
parts = Parser::Transform.new.apply(syntax)
|
||||
#puts parts.inspect
|
||||
Phisol::Compiler.compile( parts )
|
||||
machine.collect
|
||||
# statements = Virtual.machine.boot.parse_and_compile @string_input
|
||||
# Phisol::Compiler.compile( statements , Virtual.machine.space.get_main )
|
||||
@interpreter = Interpreter::Interpreter.new
|
||||
@interpreter.start Virtual.machine.init
|
||||
#show_ticks # get output of what is
|
||||
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
||||
"FunctionCall","SaveReturn","GetSlot","GetSlot","SetSlot",
|
||||
"LoadConstant","SetSlot","LoadConstant","SetSlot","RegisterTransfer",
|
||||
"FunctionCall","SaveReturn","GetSlot","LoadConstant","OperatorInstruction",
|
||||
"IsZero","GetSlot","LoadConstant","SetSlot","LoadConstant",
|
||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||
"RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer","SetSlot",
|
||||
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","Branch",
|
||||
"RegisterTransfer","GetSlot","FunctionReturn","GetSlot","RegisterTransfer",
|
||||
"GetSlot","FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
|
||||
got = ticks(1)
|
||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||
end
|
||||
#puts @interpreter.block.inspect
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user