adjust branch names
IsXXX with xxx as condition, same as after if_xxx AlwaysBranch is back to Branch
This commit is contained in:
parent
50379a1fea
commit
1fd937927c
@ -96,13 +96,13 @@ module Interpreter
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Instruction interpretation starts here
|
# Instruction interpretation starts here
|
||||||
def execute_AlwaysBranch
|
def execute_Branch
|
||||||
target = @instruction.block
|
target = @instruction.block
|
||||||
set_block target
|
set_block target
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_IsZeroBranch
|
def execute_IsZero
|
||||||
#puts @instruction.inspect
|
#puts @instruction.inspect
|
||||||
if( @flags[:zero] )
|
if( @flags[:zero] )
|
||||||
target = @instruction.block
|
target = @instruction.block
|
||||||
|
@ -15,7 +15,7 @@ module Phisol
|
|||||||
is = process(condition)
|
is = process(condition)
|
||||||
# TODO should/will use different branches for different conditions.
|
# TODO should/will use different branches for different conditions.
|
||||||
# just a scetch : cond_val = cond_val.is_true?(method) unless cond_val.is_a? BranchCondition
|
# just a scetch : cond_val = cond_val.is_true?(method) unless cond_val.is_a? BranchCondition
|
||||||
@method.source.add_code Register::IsZeroBranch.new( condition , true_block )
|
@method.source.add_code Register::IsZero.new( condition , true_block )
|
||||||
|
|
||||||
# compile the true block (as we think of it first, even it is second in sequential order)
|
# compile the true block (as we think of it first, even it is second in sequential order)
|
||||||
@method.source.current true_block
|
@method.source.current true_block
|
||||||
@ -25,7 +25,7 @@ module Phisol
|
|||||||
# compile the false block
|
# compile the false block
|
||||||
@method.source.current false_block
|
@method.source.current false_block
|
||||||
last = process_all(if_false).last if if_false
|
last = process_all(if_false).last if if_false
|
||||||
@method.source.add_code Register::AlwaysBranch.new(statement, merge_block )
|
@method.source.add_code Register::Branch.new(statement, merge_block )
|
||||||
|
|
||||||
#puts "compiled if: end"
|
#puts "compiled if: end"
|
||||||
@method.source.current merge_block
|
@method.source.current merge_block
|
||||||
|
@ -14,12 +14,12 @@ module Phisol
|
|||||||
|
|
||||||
cond = process(condition)
|
cond = process(condition)
|
||||||
|
|
||||||
@method.source.add_code Register::IsZeroBranch.new(condition,merge)
|
@method.source.add_code Register::IsZero.new(condition,merge)
|
||||||
|
|
||||||
last = process_all(statements).last
|
last = process_all(statements).last
|
||||||
|
|
||||||
# unconditionally branch to the start
|
# unconditionally branch to the start
|
||||||
@method.source.add_code Register::AlwaysBranch.new(statement,start)
|
@method.source.add_code Register::Branch.new(statement,start)
|
||||||
|
|
||||||
# continue execution / compiling at the merge block
|
# continue execution / compiling at the merge block
|
||||||
@method.source.current merge
|
@method.source.current merge
|
||||||
|
@ -16,16 +16,16 @@ module Register
|
|||||||
alias :inspect :to_s
|
alias :inspect :to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
class IsZeroBranch < Branch
|
class IsZero < Branch
|
||||||
end
|
end
|
||||||
|
|
||||||
class IsNegativeBranch < Branch
|
class IsNotzero < Branch
|
||||||
end
|
end
|
||||||
|
|
||||||
class IsPositiveBranch < Branch
|
class IsMinus < Branch
|
||||||
end
|
end
|
||||||
|
|
||||||
class AlwaysBranch < Branch
|
class IsPlus < Branch
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -118,7 +118,7 @@ module Virtual
|
|||||||
def boot
|
def boot
|
||||||
boot_parfait!
|
boot_parfait!
|
||||||
@init = Block.new("init", :__init__ )
|
@init = Block.new("init", :__init__ )
|
||||||
branch = Register::AlwaysBranch.new( "__init__" , self.space.get_init.source.blocks.first )
|
branch = Register::Branch.new( "__init__" , self.space.get_init.source.blocks.first )
|
||||||
@init.add_code branch
|
@init.add_code branch
|
||||||
@booted = true
|
@booted = true
|
||||||
self
|
self
|
||||||
|
@ -17,8 +17,8 @@ class Object
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
||||||
OperatorInstruction,IsZeroBranch] ,
|
OperatorInstruction,IsZero] ,
|
||||||
[LoadConstant,AlwaysBranch] ,[LoadConstant] ,[] ,
|
[LoadConstant,Branch] ,[LoadConstant] ,[] ,
|
||||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -35,8 +35,8 @@ class Object
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
@expect = [[SaveReturn,LoadConstant,LoadConstant,
|
||||||
OperatorInstruction,IsZeroBranch] ,
|
OperatorInstruction,IsZero] ,
|
||||||
[AlwaysBranch] ,[LoadConstant] ,[] ,
|
[Branch] ,[LoadConstant] ,[] ,
|
||||||
[RegisterTransfer,GetSlot,FunctionReturn]]
|
[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[SaveReturn],[LoadConstant,IsZeroBranch,LoadConstant,AlwaysBranch],
|
@expect = [[SaveReturn],[LoadConstant,IsZero,LoadConstant,Branch],
|
||||||
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -32,7 +32,7 @@ class Object
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
|
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
|
||||||
IsZeroBranch,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,AlwaysBranch],
|
IsZero,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch],
|
||||||
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
@ -51,9 +51,9 @@ class Object
|
|||||||
end
|
end
|
||||||
HERE
|
HERE
|
||||||
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],
|
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],
|
||||||
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZeroBranch,GetSlot,
|
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZero,GetSlot,
|
||||||
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
|
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
|
||||||
GetSlot,AlwaysBranch] ,
|
GetSlot,Branch] ,
|
||||||
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
@ -26,7 +26,7 @@ class AddTest < MiniTest::Test
|
|||||||
|
|
||||||
def test_branch
|
def test_branch
|
||||||
was = @interpreter.block
|
was = @interpreter.block
|
||||||
assert_equal Register::AlwaysBranch , ticks(1).class
|
assert_equal Register::Branch , ticks(1).class
|
||||||
assert was != @interpreter.block
|
assert was != @interpreter.block
|
||||||
end
|
end
|
||||||
def test_load
|
def test_load
|
||||||
@ -66,7 +66,7 @@ class AddTest < MiniTest::Test
|
|||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
["AlwaysBranch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
||||||
"FunctionCall","SaveReturn","LoadConstant","LoadConstant","OperatorInstruction",
|
"FunctionCall","SaveReturn","LoadConstant","LoadConstant","OperatorInstruction",
|
||||||
"RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall",
|
"RegisterTransfer","GetSlot","FunctionReturn","RegisterTransfer","Syscall",
|
||||||
"NilClass"].each_with_index do |name , index|
|
"NilClass"].each_with_index do |name , index|
|
||||||
|
@ -59,7 +59,7 @@ HERE
|
|||||||
@interpreter = Interpreter::Interpreter.new
|
@interpreter = Interpreter::Interpreter.new
|
||||||
@interpreter.start Virtual.machine.init
|
@interpreter.start Virtual.machine.init
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
["AlwaysBranch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
||||||
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
|
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
|
||||||
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
|
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
|
||||||
"LoadConstant","GetSlot","SetSlot","GetSlot","GetSlot",
|
"LoadConstant","GetSlot","SetSlot","GetSlot","GetSlot",
|
||||||
@ -67,22 +67,22 @@ HERE
|
|||||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||||
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||||
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||||
"GetSlot","GetSlot","IsZeroBranch","GetSlot","GetSlot",
|
"GetSlot","GetSlot","IsZero","GetSlot","GetSlot",
|
||||||
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
||||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||||
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||||
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||||
"GetSlot","GetSlot","IsZeroBranch","GetSlot","GetSlot",
|
"GetSlot","GetSlot","IsZero","GetSlot","GetSlot",
|
||||||
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
||||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||||
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||||
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||||
"GetSlot","GetSlot","IsZeroBranch","GetSlot","GetSlot",
|
"GetSlot","GetSlot","IsZero","GetSlot","GetSlot",
|
||||||
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
"GetSlot","SetSlot","LoadConstant","SetSlot","GetSlot",
|
||||||
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
"SetSlot","RegisterTransfer","FunctionCall","SaveReturn","GetSlot",
|
||||||
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
"LoadConstant","OperatorInstruction","GetSlot","SetSlot","GetSlot",
|
||||||
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
"GetSlot","GetSlot","OperatorInstruction","GetSlot","SetSlot",
|
||||||
"GetSlot","GetSlot","IsZeroBranch","GetSlot","GetSlot",
|
"GetSlot","GetSlot","IsZero","GetSlot","GetSlot",
|
||||||
"GetSlot"].each_with_index do |name , index|
|
"GetSlot"].each_with_index do |name , index|
|
||||||
got = ticks(1)
|
got = ticks(1)
|
||||||
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
||||||
|
@ -26,7 +26,7 @@ class TestPuts < MiniTest::Test
|
|||||||
|
|
||||||
def test_branch
|
def test_branch
|
||||||
was = @interpreter.block
|
was = @interpreter.block
|
||||||
assert_equal Register::AlwaysBranch , ticks(1).class
|
assert_equal Register::Branch , ticks(1).class
|
||||||
assert was != @interpreter.block
|
assert was != @interpreter.block
|
||||||
end
|
end
|
||||||
def test_load
|
def test_load
|
||||||
@ -56,7 +56,7 @@ class TestPuts < MiniTest::Test
|
|||||||
|
|
||||||
def test_chain
|
def test_chain
|
||||||
#show_ticks # get output of what is
|
#show_ticks # get output of what is
|
||||||
["AlwaysBranch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
["Branch","LoadConstant","GetSlot","SetSlot","RegisterTransfer",
|
||||||
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
|
"FunctionCall","SaveReturn","GetSlot","LoadConstant","SetSlot",
|
||||||
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
|
"LoadConstant","SetSlot","RegisterTransfer","FunctionCall","SaveReturn",
|
||||||
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
|
"GetSlot","RegisterTransfer","Syscall","RegisterTransfer","RegisterTransfer",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user