fix while.to_vool
sanitize normalizer on the way - return ruby, let caller to_vool - return single statement, not single? statements
This commit is contained in:
parent
9b8bd57db4
commit
6a58a71c0a
@ -14,11 +14,9 @@ module Ruby
|
|||||||
|
|
||||||
def to_vool
|
def to_vool
|
||||||
cond , rest = *normalize_name(@condition)
|
cond , rest = *normalize_name(@condition)
|
||||||
fals = @if_false ? @if_false.to_vool : nil
|
me = Vool::IfStatement.new(cond.to_vool , @if_true.to_vool, @if_false&.to_vool)
|
||||||
me = Vool::IfStatement.new(cond , @if_true.to_vool, fals)
|
|
||||||
return me unless rest
|
return me unless rest
|
||||||
rest << me
|
Vool::Statements.new([ rest.to_vool , me])
|
||||||
rest
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_false?
|
def has_false?
|
||||||
|
@ -12,11 +12,10 @@ module Ruby
|
|||||||
if( condition.is_a?(ScopeStatement) and condition.single?)
|
if( condition.is_a?(ScopeStatement) and condition.single?)
|
||||||
condition = condition.first
|
condition = condition.first
|
||||||
end
|
end
|
||||||
return [condition.to_vool] if condition.is_a?(Named) or condition.is_a?(Constant)
|
return [condition] if condition.is_a?(Named) or condition.is_a?(Constant)
|
||||||
condition = condition.to_vool
|
|
||||||
local = "tmp_#{object_id}".to_sym
|
local = "tmp_#{object_id}".to_sym
|
||||||
assign = Vool::Statements.new [Vool::LocalAssignment.new( local , condition)]
|
assign = LocalAssignment.new( local , condition)
|
||||||
[Vool::LocalVariable.new(local) , assign]
|
[LocalVariable.new(local) , assign]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -13,7 +13,7 @@ module Ruby
|
|||||||
|
|
||||||
def to_vool
|
def to_vool
|
||||||
cond , rest = *normalize_name(@condition)
|
cond , rest = *normalize_name(@condition)
|
||||||
WhileStatement.new(cond , @body.normalize , rest)
|
Vool::WhileStatement.new(cond.to_vool , @body.to_vool , rest&.to_vool)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
|
@ -19,7 +19,6 @@ module Ruby
|
|||||||
lst = compile( basic_while )
|
lst = compile( basic_while )
|
||||||
assert_equal TrueConstant , lst.body.class
|
assert_equal TrueConstant , lst.body.class
|
||||||
end
|
end
|
||||||
|
|
||||||
def reverse_while
|
def reverse_while
|
||||||
"true while(false)"
|
"true while(false)"
|
||||||
end
|
end
|
||||||
|
41
test/ruby/test_while_statement1.rb
Normal file
41
test/ruby/test_while_statement1.rb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
require_relative 'helper'
|
||||||
|
|
||||||
|
module Ruby
|
||||||
|
class TestWhileStatementVool < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
def setup
|
||||||
|
@lst = compile( "while(@arg) ; @arg = 1 ; end" ).to_vool
|
||||||
|
end
|
||||||
|
def test_class
|
||||||
|
assert_equal Vool::WhileStatement , @lst.class
|
||||||
|
end
|
||||||
|
def test_body_class
|
||||||
|
assert_equal Vool::IvarAssignment , @lst.body.class
|
||||||
|
end
|
||||||
|
def test_condition_class
|
||||||
|
assert_equal Vool::InstanceVariable , @lst.condition.class
|
||||||
|
end
|
||||||
|
def test_no_hoist
|
||||||
|
assert_nil @lst.hoisted
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class TestWhileStatementHoist < MiniTest::Test
|
||||||
|
include RubyTests
|
||||||
|
def setup
|
||||||
|
@lst = compile( "while(arg > 1) ; arg = 1 ; end" ).to_vool
|
||||||
|
end
|
||||||
|
def test_class
|
||||||
|
assert_equal Vool::WhileStatement , @lst.class
|
||||||
|
assert_equal Vool::LocalAssignment , @lst.body.class
|
||||||
|
end
|
||||||
|
def test_condition_class
|
||||||
|
assert_equal Vool::LocalVariable , @lst.condition.class
|
||||||
|
end
|
||||||
|
def test_hoist
|
||||||
|
assert_equal Vool::LocalAssignment , @lst.hoisted.class
|
||||||
|
end
|
||||||
|
def test_hoist_is_cond
|
||||||
|
assert_equal @lst.hoisted.name , @lst.condition.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user