new i_to_s test
This commit is contained in:
parent
259b0afa96
commit
4186405930
@ -135,7 +135,7 @@ module Virtual
|
|||||||
def compile_main bytes
|
def compile_main bytes
|
||||||
syntax = @parser.parse_with_debug(bytes)
|
syntax = @parser.parse_with_debug(bytes)
|
||||||
parts = Parser::Transform.new.apply(syntax)
|
parts = Parser::Transform.new.apply(syntax)
|
||||||
#puts parts.to_s
|
#puts parts.inspect
|
||||||
Bosl::Compiler.compile( parts , @space.get_main )
|
Bosl::Compiler.compile( parts , @space.get_main )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,2 +1,13 @@
|
|||||||
require_relative "../helper"
|
require_relative "../helper"
|
||||||
require "interpreter/interpreter"
|
require "interpreter/interpreter"
|
||||||
|
|
||||||
|
module Ticker
|
||||||
|
def ticks num
|
||||||
|
last = nil
|
||||||
|
num.times do
|
||||||
|
last = @interpreter.instruction
|
||||||
|
@interpreter.tick
|
||||||
|
end
|
||||||
|
return last
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -2,6 +2,8 @@ require_relative "helper"
|
|||||||
|
|
||||||
class AddTest < MiniTest::Test
|
class AddTest < MiniTest::Test
|
||||||
include AST::Sexp
|
include AST::Sexp
|
||||||
|
include Ticker
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Virtual.machine.boot
|
Virtual.machine.boot
|
||||||
code = s(:call,
|
code = s(:call,
|
||||||
@ -14,15 +16,6 @@ class AddTest < MiniTest::Test
|
|||||||
@interpreter.start Virtual.machine.init
|
@interpreter.start Virtual.machine.init
|
||||||
end
|
end
|
||||||
|
|
||||||
def ticks num
|
|
||||||
last = nil
|
|
||||||
num.times do
|
|
||||||
last = @interpreter.instruction
|
|
||||||
@interpreter.tick
|
|
||||||
end
|
|
||||||
return last
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_branch
|
def test_branch
|
||||||
was = @interpreter.block
|
was = @interpreter.block
|
||||||
assert_equal Register::Branch , ticks(1).class
|
assert_equal Register::Branch , ticks(1).class
|
||||||
@ -47,7 +40,7 @@ class AddTest < MiniTest::Test
|
|||||||
assert_equal Register::FunctionCall , ticks(7).class
|
assert_equal Register::FunctionCall , ticks(7).class
|
||||||
assert @interpreter.link
|
assert @interpreter.link
|
||||||
end
|
end
|
||||||
def ttest_adding
|
def test_adding
|
||||||
done = ticks(23)
|
done = ticks(23)
|
||||||
assert_equal Register::OperatorInstruction , done.class
|
assert_equal Register::OperatorInstruction , done.class
|
||||||
left = @interpreter.get_register(done.left)
|
left = @interpreter.get_register(done.left)
|
||||||
@ -55,11 +48,12 @@ class AddTest < MiniTest::Test
|
|||||||
right = @interpreter.get_register(rr)
|
right = @interpreter.get_register(rr)
|
||||||
assert_equal Fixnum , left.class
|
assert_equal Fixnum , left.class
|
||||||
assert_equal Fixnum , right.class
|
assert_equal Fixnum , right.class
|
||||||
assert_equal 5 , right
|
assert_equal 16 , right
|
||||||
|
assert_equal 8 , left
|
||||||
done = ticks(1)
|
done = ticks(1)
|
||||||
assert_equal Register::RegisterTransfer , done.class
|
assert_equal Register::RegisterTransfer , done.class
|
||||||
result = @interpreter.get_register(rr)
|
result = @interpreter.get_register(rr)
|
||||||
assert_equal result , left + right
|
assert_equal result , 16
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
|
48
test/interpreter/test_puti.rb
Normal file
48
test/interpreter/test_puti.rb
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
class AddTest < MiniTest::Test
|
||||||
|
include Ticker
|
||||||
|
|
||||||
|
def test_puti
|
||||||
|
@string_input = <<HERE
|
||||||
|
class Integer < Object
|
||||||
|
ref add_string(ref str)
|
||||||
|
int div
|
||||||
|
div = self / 10
|
||||||
|
int rest
|
||||||
|
rest = self - div
|
||||||
|
if( rest < 0)
|
||||||
|
str = str + digit( rest )
|
||||||
|
else
|
||||||
|
str = div.add_string(str)
|
||||||
|
end
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
ref to_string()
|
||||||
|
ref start = " "
|
||||||
|
return add_string( start )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
HERE
|
||||||
|
expressions = Virtual.machine.boot.compile_main @string_input
|
||||||
|
puts expressions
|
||||||
|
# Bosl::Compiler.compile( expressions , Virtual.machine.space.get_main )
|
||||||
|
Virtual.machine.run_before "Register::CallImplementation"
|
||||||
|
@interpreter = Interpreter::Interpreter.new
|
||||||
|
@interpreter.start Virtual.machine.init
|
||||||
|
# done = ticks(34)
|
||||||
|
["Branch" , "LoadConstant" , "GetSlot" , "SetSlot" , "RegisterTransfer" ,
|
||||||
|
"GetSlot" , "FunctionCall" , "SaveReturn" , "RegisterTransfer" , "GetSlot" ,
|
||||||
|
"GetSlot" , "GetSlot" , "SetSlot" , "LoadConstant" , "SetSlot" ,
|
||||||
|
"LoadConstant" , "SetSlot" , "RegisterTransfer" , "GetSlot" , "FunctionCall" ,
|
||||||
|
"SaveReturn" , "GetSlot", "OperatorInstruction" , "RegisterTransfer" , "GetSlot" , "GetSlot" ,
|
||||||
|
"GetSlot" , "FunctionReturn" ,"RegisterTransfer" , "Syscall", "NilClass"].each_with_index do |name , index|
|
||||||
|
return if index == 10
|
||||||
|
got = ticks(1)
|
||||||
|
puts got
|
||||||
|
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -2,6 +2,7 @@ require_relative "helper"
|
|||||||
|
|
||||||
class TestPuts < MiniTest::Test
|
class TestPuts < MiniTest::Test
|
||||||
include AST::Sexp
|
include AST::Sexp
|
||||||
|
include Ticker
|
||||||
def setup
|
def setup
|
||||||
Virtual.machine.boot
|
Virtual.machine.boot
|
||||||
code = s(:call,
|
code = s(:call,
|
||||||
@ -16,15 +17,6 @@ class TestPuts < MiniTest::Test
|
|||||||
@interpreter.start Virtual.machine.init
|
@interpreter.start Virtual.machine.init
|
||||||
end
|
end
|
||||||
|
|
||||||
def ticks num
|
|
||||||
last = nil
|
|
||||||
num.times do
|
|
||||||
last = @interpreter.instruction
|
|
||||||
@interpreter.tick
|
|
||||||
end
|
|
||||||
return last
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_branch
|
def test_branch
|
||||||
was = @interpreter.block
|
was = @interpreter.block
|
||||||
assert_equal Register::Branch , ticks(1).class
|
assert_equal Register::Branch , ticks(1).class
|
||||||
@ -85,5 +77,6 @@ class TestPuts < MiniTest::Test
|
|||||||
def test_exit
|
def test_exit
|
||||||
done = ticks(34)
|
done = ticks(34)
|
||||||
assert_equal NilClass , done.class
|
assert_equal NilClass , done.class
|
||||||
|
assert_equal "Hello again" , @interpreter.stdout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user