From db5c37bc553fc298b48070a31f16f2b74fb2553f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 19 Oct 2015 16:37:12 +0300 Subject: [PATCH] fix while syntax and test --- lib/phisol/compiler/while_statement.rb | 3 ++- test/compiler/statements/test_while.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/phisol/compiler/while_statement.rb b/lib/phisol/compiler/while_statement.rb index 3745bffa..592422b8 100644 --- a/lib/phisol/compiler/while_statement.rb +++ b/lib/phisol/compiler/while_statement.rb @@ -14,7 +14,8 @@ module Phisol cond = process(condition) - @method.source.add_code Register::IsZero.new(condition,merge) + branch_class = Object.const_get "Register::Is#{branch_type.capitalize}" + @method.source.add_code branch_class.new( condition , merge ) last = process_all(statements).last diff --git a/test/compiler/statements/test_while.rb b/test/compiler/statements/test_while.rb index 9f4bb468..17ed89cc 100644 --- a/test/compiler/statements/test_while.rb +++ b/test/compiler/statements/test_while.rb @@ -15,7 +15,7 @@ class Object end end HERE - @expect = [[SaveReturn],[LoadConstant,IsZero,LoadConstant,Branch], + @expect = [[SaveReturn],[LoadConstant,IsPlus,LoadConstant,Branch], [],[RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -25,14 +25,14 @@ HERE class Object int main() int n = 5 - while_minus(n > 0) + while_plus(n) n = n - 1 end end end HERE - @expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction, - IsZero,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch], + @expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot, IsPlus,GetSlot, + GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch], [],[RegisterTransfer,GetSlot,FunctionReturn]] check end @@ -43,7 +43,7 @@ HERE class Object int main() int n = 10 - while_notzero( n > 5) + while_plus( n - 5) n = n + 1 return n end @@ -51,7 +51,7 @@ class Object end HERE @expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot], - [GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZero,GetSlot, + [GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsPlus,GetSlot, GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot, GetSlot,Branch] , [],[RegisterTransfer,GetSlot,FunctionReturn]]