fix and test return
return was in the wrong message better tests now
This commit is contained in:
parent
ff759bf0c1
commit
4014ad27fe
@ -30,7 +30,7 @@ module Soml
|
|||||||
ret = use_reg( :Integer )
|
ret = use_reg( :Integer )
|
||||||
# the effect of the method is that the NewMessage Return slot will be filled, return it
|
# the effect of the method is that the NewMessage Return slot will be filled, return it
|
||||||
# but move it into a register too
|
# but move it into a register too
|
||||||
add_code Register.get_slot(statement, :message , :return_value , ret )
|
add_code Register.get_slot(statement, :new_message , :return_value , ret )
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,16 +16,16 @@ module Fragments
|
|||||||
machine = Register.machine.boot
|
machine = Register.machine.boot
|
||||||
machine.parse_and_compile @string_input
|
machine.parse_and_compile @string_input
|
||||||
machine.collect
|
machine.collect
|
||||||
interpreter = Interpreter::Interpreter.new
|
@interpreter = Interpreter::Interpreter.new
|
||||||
interpreter.start machine.init
|
@interpreter.start machine.init
|
||||||
count = 0
|
count = 0
|
||||||
begin
|
begin
|
||||||
count += 1
|
count += 1
|
||||||
#puts interpreter.instruction
|
#puts interpreter.instruction
|
||||||
interpreter.tick
|
@interpreter.tick
|
||||||
end while( ! interpreter.instruction.nil?)
|
end while( ! @interpreter.instruction.nil?)
|
||||||
assert_equal @length , count
|
assert_equal @length , count
|
||||||
assert_equal @stdout , interpreter.stdout
|
assert_equal @stdout , @interpreter.stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
require_relative "test_if"
|
require_relative "test_if"
|
||||||
require_relative "test_class"
|
require_relative "test_class"
|
||||||
require_relative "test_foo"
|
|
||||||
require_relative "test_functions"
|
require_relative "test_functions"
|
||||||
require_relative "test_hello"
|
require_relative "test_hello"
|
||||||
require_relative "test_if"
|
require_relative "test_if"
|
||||||
require_relative "test_putint"
|
require_relative "test_putint"
|
||||||
require_relative "test_recursive_fibo"
|
require_relative "test_recursive_fibo"
|
||||||
|
require_relative "test_return"
|
||||||
#require_relative "test_while_fibo"
|
#require_relative "test_while_fibo"
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
require_relative 'helper'
|
|
||||||
|
|
||||||
class TestFoo < MiniTest::Test
|
|
||||||
include Fragments
|
|
||||||
|
|
||||||
def test_foo2
|
|
||||||
@string_input = <<HERE
|
|
||||||
class Object
|
|
||||||
int foo(int x)
|
|
||||||
int a = 5
|
|
||||||
return a
|
|
||||||
end
|
|
||||||
|
|
||||||
int main()
|
|
||||||
foo( 4 )
|
|
||||||
end
|
|
||||||
end
|
|
||||||
HERE
|
|
||||||
@length = 41
|
|
||||||
check
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
56
test/compiler/fragments/test_return.rb
Normal file
56
test/compiler/fragments/test_return.rb
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
require_relative 'helper'
|
||||||
|
|
||||||
|
class TestReturn < MiniTest::Test
|
||||||
|
include Fragments
|
||||||
|
|
||||||
|
def check_return val
|
||||||
|
check
|
||||||
|
assert_equal Parfait::Message , @interpreter.get_register(:r1).class
|
||||||
|
assert_equal val , @interpreter.get_register(:r1).return_value
|
||||||
|
end
|
||||||
|
def test_return1
|
||||||
|
@string_input = <<HERE
|
||||||
|
class Object
|
||||||
|
int main()
|
||||||
|
return 5
|
||||||
|
end
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@length = 18
|
||||||
|
check_return 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_return2
|
||||||
|
@string_input = <<HERE
|
||||||
|
class Object
|
||||||
|
int foo(int x)
|
||||||
|
return x
|
||||||
|
end
|
||||||
|
|
||||||
|
int main()
|
||||||
|
return foo( 5 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@length = 38
|
||||||
|
check_return 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_return3
|
||||||
|
@string_input = <<HERE
|
||||||
|
class Object
|
||||||
|
int foo(int x)
|
||||||
|
int a = 5
|
||||||
|
return a
|
||||||
|
end
|
||||||
|
|
||||||
|
int main()
|
||||||
|
return foo( 4 )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
HERE
|
||||||
|
@length = 42
|
||||||
|
check_return 5
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user