stop pinning self and frame

before: r0-message , r1-self , r2-frame , r3-new_message , r4 + tmps
now: r0-message , r1-new_message , r2 + tmps
programs got smaller, less fuss
also fix in return implementation that got the address from the wrong
message
This commit is contained in:
Torsten Ruger
2015-10-18 17:20:19 +03:00
parent da5502e301
commit 6c7e4c0fe2
19 changed files with 98 additions and 94 deletions

View File

@ -29,7 +29,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot] , [Virtual::MethodReturn]]
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [Virtual::MethodReturn]]
check
end
@ -42,7 +42,7 @@ end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant,LoadConstant,
OperatorInstruction,SetSlot],[Virtual::MethodReturn]]
OperatorInstruction,GetSlot,SetSlot],[Virtual::MethodReturn]]
check
end
@ -55,7 +55,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot] , [Virtual::MethodReturn]]
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot] , [Virtual::MethodReturn]]
check
end
@ -67,7 +67,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant, SetSlot] , [Virtual::MethodReturn]]
@expect = [[Virtual::MethodEnter,LoadConstant, GetSlot,SetSlot] , [Virtual::MethodReturn]]
check
end
@ -79,8 +79,8 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,GetSlot,SetSlot, LoadConstant,
SetSlot,Virtual::MethodCall,GetSlot,SetSlot] , [Virtual::MethodReturn]]
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,SetSlot,
Virtual::MethodCall,GetSlot,GetSlot,SetSlot] , [Virtual::MethodReturn]]
check
end
end

View File

@ -17,7 +17,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,
@expect = [[Virtual::MethodEnter,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
[Virtual::MethodReturn]]
check
@ -37,7 +37,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,
@expect = [[Virtual::MethodEnter,GetSlot,LoadConstant,
SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,GetSlot] ,
[Virtual::MethodReturn]]
check
@ -57,8 +57,8 @@ class Object
end
end
HERE
@expect = [ [Virtual::MethodEnter,LoadConstant,SetSlot,GetSlot,
GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
@expect = [ [Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,
GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,Virtual::MethodCall,
GetSlot] ,[Virtual::MethodReturn] ]
check
end
@ -77,13 +77,13 @@ class Object
end
end
HERE
@expect = [ [Virtual::MethodEnter,GetSlot,GetSlot,SetSlot,
@expect = [ [Virtual::MethodEnter,GetSlot,GetSlot,GetSlot,SetSlot,
LoadConstant,SetSlot,Virtual::MethodCall,
GetSlot] ,[Virtual::MethodReturn] ]
check
end
def test_puts_string
def test_call_puts
@string_input = <<HERE
class Object
int puts(Word str)
@ -94,7 +94,7 @@ int main()
end
end
HERE
@expect = [ [Virtual::MethodEnter , GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
@expect = [ [Virtual::MethodEnter , GetSlot,GetSlot,SetSlot,LoadConstant,SetSlot,LoadConstant,
SetSlot,Virtual::MethodCall,GetSlot],
[Virtual::MethodReturn]]
check

View File

@ -26,7 +26,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,GetSlot] , [Virtual::MethodReturn]]
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [Virtual::MethodReturn]]
check
end
@ -39,7 +39,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant, SetSlot,GetSlot] , [Virtual::MethodReturn]]
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot] , [Virtual::MethodReturn]]
check
end
@ -52,7 +52,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,GetSlot] , [Virtual::MethodReturn]]
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot] , [Virtual::MethodReturn]]
check
end
@ -64,7 +64,7 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,GetSlot,SetSlot, LoadConstant,
@expect = [[Virtual::MethodEnter,GetSlot,GetSlot,SetSlot, LoadConstant,
SetSlot,Virtual::MethodCall,GetSlot] , [Virtual::MethodReturn]]
check
end

View File

@ -31,8 +31,8 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot],[GetSlot,LoadConstant,OperatorInstruction,
IsZeroBranch,GetSlot,LoadConstant,OperatorInstruction,SetSlot,AlwaysBranch],
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
IsZeroBranch,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,AlwaysBranch],
[],[Virtual::MethodReturn]]
check
end
@ -50,9 +50,9 @@ class Object
end
end
HERE
@expect = [[Virtual::MethodEnter,LoadConstant,SetSlot],
[GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,
GetSlot,LoadConstant,OperatorInstruction,SetSlot,
@expect = [[Virtual::MethodEnter,LoadConstant,GetSlot,SetSlot],
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,GetSlot,
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
GetSlot,AlwaysBranch] ,
[],[Virtual::MethodReturn]]
check

View File

@ -27,6 +27,7 @@ module Ticker
puts e
end
classes = classes.collect {|c| '"' + c.name.sub("Register::","") + '",' }
classes << "length = #{classes.length}"
classes.each_slice(5).each do |line|
puts " " + line.join
end

View File

@ -31,13 +31,13 @@ class AddTest < MiniTest::Test
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
assert_equal Parfait::Space , Virtual.machine.objects[ @interpreter.get_register(:r2)].class
assert_equal :r2, @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
assert @interpreter.get_register( :r2 )
assert @interpreter.get_register( :r2 ).is_a? Integer
end
def test_transfer
transfer = ticks 5
@ -45,11 +45,11 @@ class AddTest < MiniTest::Test
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
end
def test_call
assert_equal Register::FunctionCall , ticks(7).class
assert_equal Register::FunctionCall , ticks(6).class
assert @interpreter.link
end
def test_adding
done_op = ticks(11)
done_op = ticks(10)
assert_equal Register::OperatorInstruction , done_op.class
left = @interpreter.get_register(done_op.left)
rr = done_op.right
@ -65,9 +65,11 @@ class AddTest < MiniTest::Test
end
def test_chain
#show_ticks # get output of what is
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
"GetSlot","FunctionCall","SaveReturn","LoadConstant","LoadConstant",
"OperatorInstruction","RegisterTransfer","GetSlot"].each_with_index do |name , index|
"FunctionCall","SaveReturn","LoadConstant","LoadConstant","OperatorInstruction",
"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

View File

@ -51,7 +51,7 @@ HERE
Virtual.machine.boot
syntax = Parser::Salama.new.parse_with_debug(@string_input)
parts = Parser::Transform.new.apply(syntax)
puts parts.inspect
#puts parts.inspect
Phisol::Compiler.compile( parts )
# statements = Virtual.machine.boot.parse_and_compile @string_input
@ -59,16 +59,18 @@ HERE
Virtual.machine.run_before "Register::CallImplementation"
@interpreter = Interpreter::Interpreter.new
@interpreter.start Virtual.machine.init
#show_ticks # get output of what is
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
"GetSlot","FunctionCall","SaveReturn","LoadConstant","GetSlot",
"SetSlot","LoadConstant","SetSlot","RegisterTransfer","GetSlot",
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
"SetSlot","RegisterTransfer","GetSlot","FunctionCall","SaveReturn",
"GetSlot","LoadConstant","OperatorInstruction","SetSlot","GetSlot",
"OperatorInstruction","SetSlot","GetSlot","LoadConstant","OperatorInstruction",
"IsZeroBranch","GetSlot","SetSlot","LoadConstant","SetSlot",
"GetSlot","SetSlot","RegisterTransfer","GetSlot","FunctionCall",
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
"LoadConstant","GetSlot","SetSlot","GetSlot","GetSlot",
"SetSlot","LoadConstant","SetSlot","GetSlot","GetSlot",
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
"GetSlot","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
"GetSlot","GetSlot","SetSlot","LoadConstant","SetSlot",
"GetSlot","GetSlot","SetSlot","RegisterTransfer","FunctionCall",
"SaveReturn","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
"LoadConstant","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",
"LoadConstant","GetSlot","LoadConstant","OperatorInstruction","IsZeroBranch",

View File

@ -31,13 +31,13 @@ class TestPuts < MiniTest::Test
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
assert_equal Parfait::Space , Virtual.machine.objects[ @interpreter.get_register(:r2)].class
assert_equal :r2, @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
assert @interpreter.get_register( :r1 )
assert @interpreter.get_register( :r1 ).is_a? Integer
end
def test_transfer
transfer = ticks 5
@ -45,23 +45,24 @@ class TestPuts < MiniTest::Test
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
end
def test_call
assert_equal Register::FunctionCall , ticks(7).class
assert_equal Register::FunctionCall , ticks(6).class
assert @interpreter.link
end
def test_save
done = ticks(8)
done = ticks(7)
assert_equal Register::SaveReturn , done.class
assert @interpreter.get_register done.register.symbol
end
def test_chain
#show_ticks # get output of what is
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
"GetSlot","FunctionCall","SaveReturn","LoadConstant","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|
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
"SetSlot","RegisterTransfer","GetSlot","FunctionReturn","GetSlot",
"RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall",
"NilClass"].each_with_index do |name , index|
got = ticks(1)
#puts "TICK #{index}"
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
@ -69,20 +70,20 @@ class TestPuts < MiniTest::Test
end
def test_putstring
done = ticks(19)
done = ticks(18)
assert_equal Register::Syscall , done.class
assert_equal "Hello again" , @interpreter.stdout
end
def test_return
done = ticks(29)
done = ticks(24)
assert_equal Register::FunctionReturn , done.class
assert @interpreter.block.is_a?(Virtual::Block)
assert @interpreter.instruction.is_a?(Register::Instruction) , "not instruction #{@interpreter.instruction}"
end
def test_exit
done = ticks(32)
done = ticks(31)
assert_equal NilClass , done.class
assert_equal "Hello again" , @interpreter.stdout
end