mains tests can include any code

not wrapping as main anymore
(must still include mains)
first part of #11
This commit is contained in:
Torsten Ruger 2018-08-18 19:42:14 +03:00
parent 233b83510f
commit 80264c5322
7 changed files with 52 additions and 24 deletions

View File

@ -1 +1,5 @@
return 2 +2
class Space
def main(arg)
return 2 +2
end
end

View File

@ -1,7 +1,11 @@
a = 0
b = 20
while( a < b )
a = a + 1
b = b - 1
class Space
def main(arg)
a = 0
b = 20
while( a < b )
a = a + 1
b = b - 1
end
return a
end
end
return a

View File

@ -1,11 +1,15 @@
n = 6
a = 0
b = 1
i = 1
while( i < n )
result = a + b
a = b
b = result
i = i + 1
class Space
def main(arg)
n = 6
a = 0
b = 1
i = 1
while( i < n )
result = a + b
a = b
b = result
i = i + 1
end
return result
end
end
return result

View File

@ -1 +1,5 @@
return "Hello-there".putstring
class Space
def main(arg)
return "Hello-there".putstring
end
end

View File

@ -1,5 +1,9 @@
b = 10
while( b >= 1 )
b = b - 1
class Space
def main(arg)
b = 10
while( b >= 1 )
b = b - 1
end
return b
end
end
return b

View File

@ -16,7 +16,7 @@ module Mains
tests << method_name
input = File.read(file_name)
self.send(:define_method, method_name ) do
ticks = run_main(input)
ticks = run_input(input)
#puts "Ticks for #{method_name}=#{ticks}"
assert_equal stdout , @interpreter.stdout , "Wrong stdout #{name}"
assert_equal exit_code , get_return.to_s , "Wrong exit code #{name}"

View File

@ -92,8 +92,16 @@ module Risc
def get_message_return
@interpreter.get_register(:r8).return_value
end
# wrap the input so it is a main, compile and run it
def run_main(input)
@string_input = as_main(input)
run_input as_main(input)
end
# use the input as it, compile and run it
# input muts contain a Space.main, but may contain more classes and methods
def run_input(input)
@string_input = input
do_setup
run_all
end