fix the if syntax and branches

This commit is contained in:
Torsten Ruger
2015-10-19 16:22:24 +03:00
parent 1fd937927c
commit 99cff3aa32
5 changed files with 44 additions and 53 deletions

View File

@ -103,14 +103,16 @@ module Interpreter
end
def execute_IsZero
#puts @instruction.inspect
if( @flags[:zero] )
target = @instruction.block
set_block target
return false
else
return true
end
@flags[:zero] ? execute_Branch : true
end
def execute_IsNotzero
@flags[:zero] ? true : execute_Branch
end
def execute_IsPlus
@flags[:plus] ? execute_Branch : true
end
def execute_IsMinus
@flags[:minus] ? execute_Branch : true
end
def execute_LoadConstant

View File

@ -13,9 +13,8 @@ module Phisol
false_block = @method.source.new_block "if_false" # directly next in order, ie if we don't jump we land here
is = process(condition)
# 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
@method.source.add_code Register::IsZero.new( condition , true_block )
branch_class = Object.const_get "Register::Is#{branch_type.capitalize}"
@method.source.add_code branch_class.new( condition , true_block )
# compile the true block (as we think of it first, even it is second in sequential order)
@method.source.current true_block