implement assignment normalisation
especially when the value is a send that needs normalising fixes several broken tests
This commit is contained in:
parent
1685ba5a44
commit
d84d208192
@ -7,9 +7,28 @@ module Vool
|
||||
end
|
||||
|
||||
def normalize()
|
||||
raise "not named left #{name.class}" unless @name.is_a?(Symbol)
|
||||
raise "unsupported right #{value}" unless @value.is_a?(Named) or
|
||||
@value.is_a?(SendStatement) or @value.is_a?(Constant)
|
||||
raise "not named left #{name.class}" unless name.is_a?(Symbol)
|
||||
case value
|
||||
when Named , Constant
|
||||
return copy
|
||||
when SendStatement
|
||||
return normalize_send
|
||||
else
|
||||
raise "unsupported right #{value}"
|
||||
end
|
||||
end
|
||||
|
||||
def copy(value = nil)
|
||||
value ||= @value
|
||||
self.class.new(name,value)
|
||||
end
|
||||
|
||||
def normalize_send
|
||||
statements = value.normalize()
|
||||
return copy( statements ) if statements.is_a?(SendStatement)
|
||||
assign = statements.statements.pop
|
||||
statements << copy(assign)
|
||||
statements
|
||||
end
|
||||
|
||||
def chain_assign(assign , method)
|
||||
|
@ -2,11 +2,6 @@ module Vool
|
||||
|
||||
class LocalAssignment < Assignment
|
||||
|
||||
def normalize
|
||||
super
|
||||
return LocalAssignment.new(@name , @value)
|
||||
end
|
||||
|
||||
def to_mom( method )
|
||||
if method.arguments_type.variable_index(@name)
|
||||
type = :arguments
|
||||
|
@ -3,7 +3,26 @@ require_relative 'helper'
|
||||
module Methods
|
||||
class TestFibo < MethodsTest
|
||||
|
||||
def est_ruby_adds
|
||||
def test_count_down
|
||||
run_space <<HERE
|
||||
def down( n )
|
||||
if( n < 2 )
|
||||
return n
|
||||
else
|
||||
a = down(n - 1)
|
||||
return a
|
||||
end
|
||||
end
|
||||
|
||||
def main(arg)
|
||||
return down(8)
|
||||
end
|
||||
HERE
|
||||
assert_equal Parfait::Integer , get_return.class
|
||||
assert_equal 1 , get_return.value
|
||||
end
|
||||
|
||||
def est_fibo
|
||||
run_space <<HERE
|
||||
def fibo_r( n )
|
||||
if( n < 2 )
|
||||
|
@ -3,17 +3,31 @@ require_relative 'helper'
|
||||
module Methods
|
||||
class TestCallSimple < MethodsTest
|
||||
|
||||
def test_call
|
||||
def test_simple
|
||||
run_space <<HERE
|
||||
def called( n )
|
||||
def same( n )
|
||||
return n
|
||||
end
|
||||
def main(arg)
|
||||
return called(8)
|
||||
return same(8)
|
||||
end
|
||||
HERE
|
||||
assert_equal Parfait::Integer , get_return.class
|
||||
assert_equal 8 , get_return.value
|
||||
end
|
||||
|
||||
def test_call_with_call
|
||||
run_space <<HERE
|
||||
def same( n )
|
||||
return n
|
||||
end
|
||||
def main(arg)
|
||||
a = same(8 - 1)
|
||||
return a
|
||||
end
|
||||
HERE
|
||||
assert_equal Parfait::Integer , get_return.class
|
||||
assert_equal 7 , get_return.value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
42
test/vool/normalization/test_assignment.rb
Normal file
42
test/vool/normalization/test_assignment.rb
Normal file
@ -0,0 +1,42 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
module Norm
|
||||
|
||||
class TestAssignSend < NormTest
|
||||
def setup
|
||||
super
|
||||
@stm = normalize("a = foo(1 - 2)")
|
||||
end
|
||||
def test_many
|
||||
assert_equal Statements , @stm.class
|
||||
end
|
||||
def test_assignment
|
||||
assert_equal LocalAssignment , @stm.first.class
|
||||
end
|
||||
def test_assignment_value
|
||||
assert_equal SendStatement , @stm.first.value.class
|
||||
end
|
||||
def test_assignment_method
|
||||
assert_equal :- , @stm.first.value.name
|
||||
end
|
||||
def test_length
|
||||
assert_equal 2 , @stm.length
|
||||
end
|
||||
def test_name
|
||||
assert @stm.first.name.to_s.start_with?("tmp_") , @stm.first.name
|
||||
end
|
||||
def test_assignment2
|
||||
assert_equal LocalAssignment , @stm.last.class
|
||||
end
|
||||
def test_name
|
||||
assert_equal :a , @stm.last.name
|
||||
end
|
||||
def test_assignment_method2
|
||||
assert_equal :foo , @stm.last.value.name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
33
test/vool/to_mom/send/test_send_args_send.rb
Normal file
33
test/vool/to_mom/send/test_send_args_send.rb
Normal file
@ -0,0 +1,33 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestSendArgsSendMom < MiniTest::Test
|
||||
include MomCompile
|
||||
include Mom
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@ins = compile_first_method( "a = main(1 + 2)" )
|
||||
end
|
||||
|
||||
def test_array
|
||||
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, MessageSetup ,
|
||||
ArgumentTransfer, SimpleCall, SlotLoad] , @ins
|
||||
end
|
||||
|
||||
def test_one_call
|
||||
assert_equal SimpleCall, @ins.next(2).class
|
||||
assert_equal :+, @ins.next(2).method.name
|
||||
end
|
||||
def test_two_call
|
||||
assert_equal SimpleCall, @ins.next(6).class
|
||||
assert_equal :main, @ins.next(6).method.name
|
||||
end
|
||||
def test_args_one_l
|
||||
left = @ins.next(1).arguments[0].left
|
||||
assert_equal Symbol, left.known_object.class
|
||||
assert_equal :message, left.known_object
|
||||
assert_equal [:next_message, :arguments, 2], left.slots
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user