2015-10-22 14:34:47 +02:00
|
|
|
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
|
2015-10-22 17:16:29 +02:00
|
|
|
machine = Register.machine.boot
|
2015-10-22 14:34:47 +02:00
|
|
|
syntax = Parser::Salama.new.parse_with_debug(@string_input)
|
|
|
|
parts = Parser::Transform.new.apply(syntax)
|
|
|
|
#puts parts.inspect
|
2015-10-28 20:40:22 +01:00
|
|
|
Soml.compile( parts )
|
2015-10-22 14:34:47 +02:00
|
|
|
machine.collect
|
|
|
|
@interpreter = Interpreter::Interpreter.new
|
2015-10-22 17:16:29 +02:00
|
|
|
@interpreter.start Register.machine.init
|
2015-10-22 14:34:47 +02:00
|
|
|
#show_ticks # get output of what is
|
2015-10-23 20:27:36 +02:00
|
|
|
["Branch","Label","LoadConstant","GetSlot","SetSlot",
|
2015-11-03 10:25:02 +01:00
|
|
|
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","Label",
|
|
|
|
"GetSlot","GetSlot","SetSlot","LoadConstant","SetSlot",
|
|
|
|
"LoadConstant","SetSlot","LoadConstant","SetSlot","LoadConstant",
|
|
|
|
"SetSlot","RegisterTransfer","FunctionCall","Label","GetSlot",
|
|
|
|
"LoadConstant","OperatorInstruction","IsZero","GetSlot","LoadConstant",
|
|
|
|
"SetSlot","LoadConstant","SetSlot","LoadConstant","SetSlot",
|
|
|
|
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","Label",
|
|
|
|
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
|
|
|
|
"SetSlot","Label","RegisterTransfer","GetSlot","FunctionReturn",
|
|
|
|
"GetSlot","Branch","Label","Label","RegisterTransfer",
|
|
|
|
"GetSlot","FunctionReturn","GetSlot","Label","RegisterTransfer",
|
|
|
|
"GetSlot","FunctionReturn","RegisterTransfer","Syscall","NilClass"].each_with_index do |name , index|
|
2015-10-22 14:34:47 +02:00
|
|
|
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
|