fix tests (just using local gem)
This commit is contained in:
parent
9680ff2a71
commit
21b0702154
4
Gemfile
4
Gemfile
@ -4,8 +4,8 @@ gem "salama" , :path => "."
|
|||||||
|
|
||||||
gem "rake"
|
gem "rake"
|
||||||
|
|
||||||
#gem "salama-reader" , :github => "salama/salama-reader"
|
gem "salama-reader" , :github => "salama/salama-reader"
|
||||||
gem "salama-reader" , :path => "../salama-reader"
|
#gem "salama-reader" , :path => "../salama-reader"
|
||||||
gem "salama-object-file" , :github => "salama/salama-object-file"
|
gem "salama-object-file" , :github => "salama/salama-object-file"
|
||||||
#gem "salama-object-file" , :path => "../salama-object-file"
|
#gem "salama-object-file" , :path => "../salama-object-file"
|
||||||
gem "salama-arm" , :github => "salama/salama-arm"
|
gem "salama-arm" , :github => "salama/salama-arm"
|
||||||
|
13
Gemfile.lock
13
Gemfile.lock
@ -10,6 +10,13 @@ GIT
|
|||||||
specs:
|
specs:
|
||||||
salama-object-file (0.2.0)
|
salama-object-file (0.2.0)
|
||||||
|
|
||||||
|
GIT
|
||||||
|
remote: git://github.com/salama/salama-reader.git
|
||||||
|
revision: 841592c667acea1e796f950851262e6938b231bc
|
||||||
|
specs:
|
||||||
|
salama-reader (0.2.0)
|
||||||
|
parslet (~> 1.7.0)
|
||||||
|
|
||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
@ -17,12 +24,6 @@ PATH
|
|||||||
salama-object-file (~> 0.2)
|
salama-object-file (~> 0.2)
|
||||||
salama-reader (~> 0.2)
|
salama-reader (~> 0.2)
|
||||||
|
|
||||||
PATH
|
|
||||||
remote: ../salama-reader
|
|
||||||
specs:
|
|
||||||
salama-reader (0.2.0)
|
|
||||||
parslet (~> 1.7.0)
|
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
@ -7,7 +7,7 @@ module Register
|
|||||||
plus_function = Virtual::MethodSource.create_method(:Integer,:plus , [Virtual::Integer] )
|
plus_function = Virtual::MethodSource.create_method(:Integer,:plus , [Virtual::Integer] )
|
||||||
plus_function.source.return_type = Virtual::Integer
|
plus_function.source.return_type = Virtual::Integer
|
||||||
plus_function.source.receiver = Virtual::Integer
|
plus_function.source.receiver = Virtual::Integer
|
||||||
plus_function.source.add_code Register::Math.new( plus_function, :add , 0 )
|
plus_function.source.add_code Register::OperatorInstruction.new( plus_function, :add , 0 , 0 )
|
||||||
|
|
||||||
return plus_function
|
return plus_function
|
||||||
end
|
end
|
||||||
|
@ -49,3 +49,4 @@ require_relative "instructions/function_return"
|
|||||||
require_relative "instructions/save_return"
|
require_relative "instructions/save_return"
|
||||||
require_relative "instructions/register_transfer"
|
require_relative "instructions/register_transfer"
|
||||||
require_relative "instructions/branch"
|
require_relative "instructions/branch"
|
||||||
|
require_relative "instructions/operator_instruction"
|
||||||
|
18
lib/register/instructions/operator_instruction.rb
Normal file
18
lib/register/instructions/operator_instruction.rb
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
module Register
|
||||||
|
|
||||||
|
class OperatorInstruction < Instruction
|
||||||
|
def initialize source , operator , left , right
|
||||||
|
super(source)
|
||||||
|
@operator = operator
|
||||||
|
@left = left
|
||||||
|
@right = right
|
||||||
|
end
|
||||||
|
attr_reader :left , :right
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
"OperatorInstruction: #{left} #{operator} #{right}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -157,9 +157,10 @@ module Virtual
|
|||||||
@space.get_class_by_name(:Word).add_instance_method Register::Builtin::Word.send(:putstring , nil)
|
@space.get_class_by_name(:Word).add_instance_method Register::Builtin::Word.send(:putstring , nil)
|
||||||
|
|
||||||
obj = @space.get_class_by_name(:Integer)
|
obj = @space.get_class_by_name(:Integer)
|
||||||
[:putint,:fibo].each do |f|
|
[:putint,:fibo , :plus].each do |f|
|
||||||
obj.add_instance_method Register::Builtin::Integer.send(f , nil)
|
obj.add_instance_method Register::Builtin::Integer.send(f , nil)
|
||||||
end
|
end
|
||||||
|
# obj.alias :plus , :+
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
76
test/interpreter/test_add.rb
Normal file
76
test/interpreter/test_add.rb
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
class AddTest < MiniTest::Test
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Virtual.machine.boot
|
||||||
|
code = Ast::FunctionExpression.new(:foo, [] , [Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(2),Ast::IntegerExpression.new(5))] ,nil )
|
||||||
|
Virtual::Compiler.compile( code , Virtual.machine.space.get_main )
|
||||||
|
Virtual.machine.run_before "Register::CallImplementation"
|
||||||
|
@interpreter = Interpreter::Interpreter.new
|
||||||
|
@interpreter.start Virtual.machine.init
|
||||||
|
end
|
||||||
|
|
||||||
|
def ticks num
|
||||||
|
last = nil
|
||||||
|
num.times do
|
||||||
|
last = @interpreter.instruction
|
||||||
|
@interpreter.tick
|
||||||
|
end
|
||||||
|
return last
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_branch
|
||||||
|
was = @interpreter.block
|
||||||
|
assert_equal Register::Branch , ticks(1).class
|
||||||
|
assert was != @interpreter.block
|
||||||
|
end
|
||||||
|
def test_load
|
||||||
|
assert_equal Register::LoadConstant , ticks(2).class
|
||||||
|
assert_equal Parfait::Space , Virtual.machine.objects[ @interpreter.get_register(:r1)].class
|
||||||
|
assert_equal :r1, @interpreter.instruction.array.symbol
|
||||||
|
end
|
||||||
|
def test_get
|
||||||
|
assert_equal Register::GetSlot , ticks(3).class
|
||||||
|
assert @interpreter.get_register( :r3 )
|
||||||
|
assert @interpreter.get_register( :r3 ).is_a? Integer
|
||||||
|
end
|
||||||
|
def test_transfer
|
||||||
|
transfer = ticks 5
|
||||||
|
assert_equal Register::RegisterTransfer , transfer.class
|
||||||
|
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
|
||||||
|
end
|
||||||
|
def test_call
|
||||||
|
assert_equal Register::FunctionCall , ticks(7).class
|
||||||
|
assert @interpreter.link
|
||||||
|
end
|
||||||
|
def test_get
|
||||||
|
done = ticks(10)
|
||||||
|
assert_equal Register::GetSlot , done.class
|
||||||
|
assert @interpreter.get_register done.register.symbol
|
||||||
|
puts @interpreter.get_register(done.register.symbol).class
|
||||||
|
done = ticks(1)
|
||||||
|
assert_equal Register::GetSlot , done.class
|
||||||
|
assert @interpreter.get_register done.register.symbol
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_chain
|
||||||
|
["Branch" , "LoadConstant" , "GetSlot" , "SetSlot" , "RegisterTransfer" ,
|
||||||
|
"GetSlot" , "FunctionCall" , "SaveReturn" , "RegisterTransfer" , "GetSlot" ,
|
||||||
|
"GetSlot" , "GetSlot" , "SetSlot" , "LoadConstant" , "SetSlot" ,
|
||||||
|
"RegisterTransfer" , "GetSlot" , "FunctionCall" , "SaveReturn" , "RegisterTransfer" ,
|
||||||
|
"Syscall" , "RegisterTransfer" , "RegisterTransfer" , "SetSlot" , "GetSlot" ,
|
||||||
|
"GetSlot" , "RegisterTransfer" ,"GetSlot" , "GetSlot","GetSlot",
|
||||||
|
"FunctionReturn" , "RegisterTransfer" , "Syscall" , "NilClass"].each_with_index do |name , index|
|
||||||
|
got = ticks(1)
|
||||||
|
puts got
|
||||||
|
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# def test_exit
|
||||||
|
# done = ticks(34)
|
||||||
|
# assert_equal NilClass , done.class
|
||||||
|
# end
|
||||||
|
end
|
@ -1 +1,2 @@
|
|||||||
require_relative "test_puts"
|
require_relative "test_puts"
|
||||||
|
#require_relative "test_add"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
class InterpreterTest < MiniTest::Test
|
class TestPuts < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
Virtual.machine.boot
|
Virtual.machine.boot
|
||||||
|
Loading…
Reference in New Issue
Block a user