fix test result, but not test yet
This commit is contained in:
parent
4afd7f78ca
commit
ca14ef8914
@ -170,5 +170,17 @@ module Interpreter
|
||||
# we jump back to the call instruction. so it is as if the call never happened and we continue
|
||||
true
|
||||
end
|
||||
|
||||
def execute_OperatorInstruction
|
||||
case @instruction.operator
|
||||
when :add
|
||||
puts @instruction
|
||||
|
||||
else
|
||||
raise "unimplemented operator #{@instruction}"
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -7,9 +7,15 @@ module Register
|
||||
plus_function = Virtual::MethodSource.create_method(:Integer,:plus , [:Integer] )
|
||||
plus_function.source.return_type = Virtual::Integer
|
||||
plus_function.source.receiver = Virtual::Integer
|
||||
plus_function.source.add_code Register::OperatorInstruction.new( plus_function, :add , 0 , 0 )
|
||||
|
||||
tmp = Register.tmp_reg
|
||||
index = Register.arg_index 1
|
||||
plus_function.source.add_code Register.get_slot( plus_function , :message , index , tmp )
|
||||
add = Register::OperatorInstruction.new( plus_function, :add , tmp , Register.self_reg )
|
||||
plus_function.source.add_code add
|
||||
return plus_function
|
||||
end
|
||||
|
||||
# The conversion to base10 is quite a bit more complicated than i thought.
|
||||
# The bulk of it is in div10
|
||||
# We set up variables, do the devision and write the result to the string
|
||||
|
@ -7,7 +7,7 @@ module Register
|
||||
@left = left
|
||||
@right = right
|
||||
end
|
||||
attr_reader :left , :right
|
||||
attr_reader :operator, :left , :right
|
||||
|
||||
def to_s
|
||||
"OperatorInstruction: #{left} #{operator} #{right}"
|
||||
|
@ -126,4 +126,11 @@ module Register
|
||||
end
|
||||
return register
|
||||
end
|
||||
|
||||
# when knowing the index of the argument, return the index into the message
|
||||
# index passed is parfait, ie stats at 1
|
||||
def self.arg_index i
|
||||
last = resolve_index :message , :name
|
||||
return last + i
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,7 @@ 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 )
|
||||
code =Ast::OperatorExpression.new("+", Ast::IntegerExpression.new(2),Ast::IntegerExpression.new(5))
|
||||
Virtual::Compiler.compile( code , Virtual.machine.space.get_main )
|
||||
Virtual.machine.run_before "Register::CallImplementation"
|
||||
@interpreter = Interpreter::Interpreter.new
|
||||
@ -44,24 +44,23 @@ class AddTest < MiniTest::Test
|
||||
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
|
||||
def test_adding
|
||||
done = ticks(23)
|
||||
assert_equal Register::OperatorInstruction , done.class
|
||||
assert @interpreter.get_register done.left.symbol
|
||||
puts @interpreter.get_register(done.left.symbol).class
|
||||
done = ticks(1)
|
||||
assert_equal Register::GetSlot , done.class
|
||||
assert @interpreter.get_register done.register.symbol
|
||||
assert_equal Register::RegisterTransfer , done.class
|
||||
assert @interpreter.get_register done.from.symbol
|
||||
end
|
||||
|
||||
def test_chain
|
||||
["Branch" , "LoadConstant" , "GetSlot" , "SetSlot" , "RegisterTransfer" ,
|
||||
"GetSlot" , "FunctionCall" , "SaveReturn" , "RegisterTransfer" , "GetSlot" ,
|
||||
"GetSlot" , "FunctionCall" , "SaveReturn" , "LoadConstant" , "SetSlot" ,
|
||||
"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|
|
||||
"LoadConstant" , "SetSlot" , "RegisterTransfer" , "GetSlot" , "FunctionCall" ,
|
||||
"SaveReturn" , "GetSlot", "OperatorInstruction" , "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}"
|
||||
|
@ -1,2 +1,2 @@
|
||||
require_relative "test_puts"
|
||||
#require_relative "test_add"
|
||||
require_relative "test_add"
|
||||
|
Loading…
Reference in New Issue
Block a user