move soml tests out, small cleanup

This commit is contained in:
Torsten Ruger
2016-12-06 15:08:29 +02:00
parent 5ac14ddccc
commit adca8b21c1
41 changed files with 32 additions and 21 deletions

View File

@ -3,7 +3,7 @@ require_relative "../helper"
class TestSpace < MiniTest::Test
def setup
@machine = Register.machine
@machine = Register.machine.boot
end
def classes
[:Kernel,:Word,:List,:Message,:Frame,:Type,:Object,:Class,:Dictionary,:Method , :Integer]

View File

@ -1,34 +0,0 @@
require_relative '../../helper'
require 'parslet/convenience'
Soml::Compiler.class_eval do
def set_main main
@clazz = Register.machine.space.get_class_by_name :Object
@method = main
@current = main.instructions.next
end
end
module ExpressionHelper
def set_main compiler
compiler.set_main Register.machine.space.get_main
end
def check
machine = Register.machine
machine.boot unless machine.booted
parser = Parser::Salama.new
parser = parser.send @root
syntax = parser.parse_with_debug(@string_input, reporter: Parslet::ErrorReporter::Deepest.new)
parts = Parser::Transform.new.apply(syntax)
codes = Soml.ast_to_code parts
#puts parts.inspect
compiler = Soml::Compiler.new
set_main(compiler)
produced = compiler.process( codes )
assert @output , "No output given"
assert_equal produced.class, @output , "Wrong class"
produced
end
end

View File

@ -1,4 +0,0 @@
require_relative "test_basic"
require_relative "test_call"
require_relative "test_field_access"
require_relative "test_ops"

View File

@ -1,52 +0,0 @@
require_relative "helper"
class TestBasic < MiniTest::Test
include ExpressionHelper
def setup
@root = :basic_type
@output = Register::RegisterValue
end
def test_number
@string_input = '42 '
assert_equal 42 , check.value
end
def test_true
@string_input = 'true'
check
end
def test_false
@string_input = 'false '
check
end
def test_nil
@string_input = 'nil '
check
end
def test_var
@string_input = 'int foo '
@root = :field_def
@output = NilClass
check
end
def test_self
@string_input = 'self '
check
end
def test_space
@string_input = 'self '
check
end
def test_string
@string_input = "\"hello\""
check
end
end

View File

@ -1,40 +0,0 @@
require_relative "helper"
module Register
class TestCall < MiniTest::Test
include ExpressionHelper
def setup
Register.machine.boot
@root = :call_site
@output = Register::RegisterValue
end
def test_call_main_plain
@string_input = 'main()'
check
end
def test_call_main_int
@string_input = 'main(1)'
check
end
def test_call_main_string
@string_input = 'main("1")'
check
end
def test_call_main_op
Register.machine.space.get_main.ensure_local(:bar , :Integer)
@string_input = 'main( bar )'
check
end
def test_call_string_put
@string_input = '"Hello Raisa, I am salama".putstring()'
check
end
end
end

View File

@ -1,61 +0,0 @@
require_relative "helper"
module Register
class TestFields < MiniTest::Test
include ExpressionHelper
def setup
Register.machine.boot
end
def test_field_not_defined
@root = :field_access
@string_input = <<HERE
self.a
HERE
assert_raises(RuntimeError) { check }
end
def test_field_not_space
@root = :field_access
@string_input = <<HERE
self.space
HERE
assert_raises(RuntimeError) { check }
end
def test_field
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:Object)
@root = :field_access
@string_input = <<HERE
self.bro
HERE
@output = Register::RegisterValue
check
end
def test_local
Register.machine.space.get_main.ensure_local(:bar , :Integer)
@root = :name
@string_input = 'bar '
@output = Register::RegisterValue
check
end
def test_space
@root = :name
@string_input = 'space '
@output = Register::RegisterValue
check
end
def test_args
Register.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :bar)
@root = :name
@string_input = 'bar '
@output = Register::RegisterValue
check
end
end
end

View File

@ -1,45 +0,0 @@
require_relative "helper"
module Register
class TestOps < MiniTest::Test
include ExpressionHelper
def setup
Register.machine.boot
@root = :operator_value
@output = Register::RegisterValue
end
def operators
["+" , "-" , "*" , "/" , "=="]
end
def test_ints
operators.each do |op|
@string_input = '2 + 3'.sub("+" , op)
check
end
end
def test_local_int
Register.machine.space.get_main.ensure_local(:bar , :Integer)
@string_input = 'bar + 3'
check
end
def test_int_local
Register.machine.space.get_main.ensure_local(:bar , :Integer)
@string_input = '3 + bar'
check
end
def test_field_int
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:int)
@string_input = "self.bro + 3"
check
end
def test_int_field
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:int)
@string_input = "3 + self.bro"
check
end
end
end

View File

@ -1,20 +0,0 @@
require_relative '../helper'
# Fragments are small programs that we run through the interpreter and really only check
# - the no. of instructions processed
# - the stdout output
module Fragments
include RuntimeTests
# define setup to NOT load parfait.
def setup
@stdout = ""
@machine = Register.machine.boot
end
def main()
@string_input
end
end

View File

@ -1,11 +0,0 @@
require_relative "test_if"
require_relative "test_class"
require_relative "test_functions"
require_relative "test_hello"
require_relative "test_if"
require_relative "test_putint"
require_relative "test_recursive_fibo"
require_relative "test_return"
require_relative "test_while_fibo"
require_relative "test_word"

View File

@ -1,24 +0,0 @@
require_relative 'helper'
module Register
class TestBasicClass < MiniTest::Test
include Fragments
def test_class_def
@string_input = <<HERE
class Bar
int buh()
return 1
end
end
class Space
int main()
return 1
end
end
HERE
@length = 15
check
end
end
end

View File

@ -1,65 +0,0 @@
require_relative 'helper'
class TestFunctions < MiniTest::Test
include Fragments
def test_functions
@string_input = <<HERE
class Space
int times(int a, int b)
if_zero( b + 0)
a = 0
else
int m = b - 1
int t = times(a, m)
a = a + t
end
return a
end
int t_seven()
int tim = times(8,10)
tim.putint()
return tim
end
int main()
return t_seven()
end
end
HERE
@length = 505
check 80
end
def test_class_method
@string_input = <<HERE
class Space
int self.some()
return 5
end
int main()
return Object.some()
end
end
HERE
@length = 33
check 5
end
def test_class_method_fails
@string_input = <<HERE
class Space
int main()
return Object.som()
end
end
HERE
assert_raises {check}
end
end

View File

@ -1,18 +0,0 @@
require_relative 'helper'
class TestHello < MiniTest::Test
include Fragments
def test_hello
@string_input = <<HERE
class Space
int main()
"Hello Raisa, I am salama".putstring()
end
end
HERE
@length = 37
@stdout = "Hello Raisa, I am salama"
check
end
end

View File

@ -1,60 +0,0 @@
require_relative 'helper'
class TestIf < MiniTest::Test
include Fragments
def test_if_plus
@string_input = <<HERE
class Space
int main()
int n = 10
if_plus( n - 12)
return 3
else
return 4
end
end
end
HERE
@length = 25
check 4
end
def test_if_zero
@string_input = <<HERE
class Space
int main()
int n = 10
if_zero(n - 10 )
"10".putstring()
end
end
end
HERE
@length = 47
@stdout = "10"
check
end
def test_if_minus
@string_input = <<HERE
class Space
int itest(int n)
if_minus( n - 12)
"then".putstring()
else
"else".putstring()
end
end
int main()
itest(20)
end
end
HERE
@length = 62
@stdout = "else"
check
end
end

View File

@ -1,22 +0,0 @@
require_relative 'helper'
class TestPutint < MiniTest::Test
include Fragments
def test_putint
@string_input = <<HERE
class Integer
int putint()
return 1
end
end
class Space
int main()
42.putint()
end
end
HERE
@length = 32
check
end
end

View File

@ -1,34 +0,0 @@
require_relative 'helper'
class TestRecursinveFibo < MiniTest::Test
include Fragments
def test_recursive_fibo
@string_input = <<HERE
class Space
int fibonaccir( int n )
if_plus( n - 2 )
int tmp
tmp = n - 1
int a = fibonaccir( tmp )
tmp = n - 2
int b = fibonaccir( tmp )
return a + b
else
return n
end
end
int fib_print(int n)
int fib = fibonaccir( n )
fib.putint()
return fib
end
int main()
return fib_print(8)
end
end
HERE
@length = 2525
check 21
end
end

View File

@ -1,51 +0,0 @@
require_relative 'helper'
class TestReturn < MiniTest::Test
include Fragments
def test_return1
@string_input = <<HERE
class Space
int main()
return 5
end
end
HERE
@length = 15
check 5
end
def test_return2
@string_input = <<HERE
class Space
int foo(int x)
return x
end
int main()
return foo( 5 )
end
end
HERE
@length = 35
check 5
end
def test_return3
@string_input = <<HERE
class Space
int foo(int x)
int a = 5
return a
end
int main()
return foo( 4 )
end
end
HERE
@length = 39
check 5
end
end

View File

@ -1,44 +0,0 @@
require_relative 'helper'
class TestWhileFragment < MiniTest::Test
include Fragments
def fibo num
@string_input = <<HERE
class Space
int fibonaccit(int n)
int a = 0
int b = 1
while_plus( n - 2)
n = n - 1
int tmp = a
a = b
b = tmp + b
end
b.putint()
return b
end
int main()
return fibonaccit( 100 )
end
end
HERE
@string_input.sub!( "100" , num.to_s )
end
def test_while_fibo48
fibo 48
@length = 1241
# this is not the correct fibo, just what comes from wrapping (smaller than below)
check 512559680
end
# highest 32 bit fibo
def test_while_fibo47
fibo 47
@length = 1216
check 2971215073
end
end

View File

@ -1,25 +0,0 @@
require_relative 'helper'
module Soml
class TestWord < MiniTest::Test
include Fragments
def test_word_new
@string_input = <<HERE
class Space
Word self.new()
return nil
end
end
class Space
int main()
Word w = Word.new()
end
end
HERE
@length = 34
@stdout = ""
check
end
end
end

View File

@ -1,99 +0,0 @@
require_relative '../helper'
require "register/interpreter"
require "rye"
Rye::Cmd.add_command :ld, '/usr/bin/ld'
Rye::Cmd.add_command :aout, './a.out'
# machinery to run a soml program in 2 ways
# - first by running it through the interpreter
# - second by assembling to arm , pushing the binary to a remote machine and executing it there
#
# The second obviously takes a fair bit of time so it's only done when an REMOTE_PI is set
# REMOTE_PI has to be set to user@machine:port or it will default to an emulator
# the minimum is REMOTE_PI=username , and off course ssh keys have to be set up
# btw can't test with ruby on a PI as code creation only works on 64bit
# that's because ruby nibbles 2 bits from a word, and soml code doesn't work around that
module RuntimeTests
def setup
@stdout = ""
end
def load_program
@machine = Register.machine.boot
Soml::Compiler.load_parfait
@machine.parse_and_compile main()
@machine.collect
end
def check ret = nil
i = check_local
check_r ret
i
end
def check_local ret = nil
load_program
interpreter = Register::Interpreter.new
interpreter.start @machine.init
count = 0
begin
count += 1
#puts interpreter.instruction
interpreter.tick
end while( ! interpreter.instruction.nil?)
assert_equal @stdout , interpreter.stdout , "stdout wrong locally"
if ret
assert_equal Parfait::Message , interpreter.get_register(:r0).class
assert_equal ret , interpreter.get_register(:r0).return_value , "exit wrong #{@string_input}"
end
interpreter
end
def connected
return false if ENV["REMOTE_PI"].nil? or (ENV["REMOTE_PI"] == "")
return @@conn if defined?(@@conn)
puts "remote " + ENV["REMOTE_PI"]
user , rest = ENV["REMOTE_PI"].split("@")
machine , port = rest.to_s.split(":")
make_box machine , port , user
end
def make_box machine = nil , port = nil , user = nil
@@conn = Rye::Box.new(machine || "localhost" , :port => (port || 2222) , :user => (user || "pi"))
end
def check_r ret_val , dont_run = false
return unless box = connected
load_program
file = write_object_file
r_file = file.sub("./" , "salama/")
box.file_upload file , r_file
print "\nfile #{file} "
return if dont_run
box.ld "-N", r_file
begin #need to rescue here as rye throws if no return 0
ret = box.aout # and we use return to mean something
rescue Rye::Err => e # so it's basically never 0
ret = e.rap
end
assert_equal @stdout , ret.stdout.join , "remote std was #{ret.stdout}" if @stdout
assert_equal "" , ret.stderr.join , "remote had error"
if ret_val
ret_val &= 0xFF # don't knwo why exit codes are restricted but there you are
assert_equal ret_val , ret.exit_status.to_i , "remote exit failed for #{@string_input}"
end
end
def write_object_file
file_name = caller(3).first.split("in ").last.chop.sub("`","")
return if file_name.include?("run")
file_name = "./tmp/" + file_name + ".o"
Register.machine.translate_arm
writer = Elf::ObjectWriter.new
writer.save file_name
file_name
end
end

View File

@ -1,28 +0,0 @@
require_relative '../helper'
# Parfait test test just that, parfait.
#
# The idea is to have really really small main programs that test one very small thing
# AND return an exit code (or write stdout) that can be checked by
# compiling and running the thing remotely
#
module ParfaitTests
include RuntimeTests
def setup
@stdout = ""
@machine = Register.machine.boot
Soml::Compiler.load_parfait
end
def main
runko = <<HERE
class Space < Object
int main()
PROGRAM
end
end
HERE
runko.sub("PROGRAM" , @main )
end
end

View File

@ -1,3 +0,0 @@
require_relative "test_integer"
require_relative "test_type"
require_relative "test_word"

View File

@ -1,156 +0,0 @@
require_relative 'helper'
class TestPutiRT < MiniTest::Test
include ParfaitTests
def test_mod4_2
@main = "return 2.mod4()"
check 2 % 4
end
def test_mod4_3
@main = "return 3.mod4()"
check 3 % 4
end
def test_mod4_4
@main = "return 4.mod4()"
check 4 % 4
end
def test_mod4_5
@main = "return 5.mod4()"
check 5 % 4
end
def test_mod4_12
@main = "return 12.mod4()"
check 12 % 4
end
def test_mod4_10
@main = "return 10.mod4()"
check 10 % 4
end
# finally settled on the long hackers delight version http://www.hackersdelight.org/divcMore.pdf
def test_div10_random
20.times do
i = rand 0xfffff
@main = "return #{i}.div10()"
check_local i / 10
end
end
def test_div10_2
@main = "return 2.div10()"
check 2 / 10
end
def test_div10_10
@main = "return 10.div10()"
check 10 / 10
end
def test_div10_12345
@main = "return 12345.div10()"
check 12345 / 10
end
def test_div10_234567
@main = "return 234567.div10()"
check 234567 / 10
end
def test_as_char1
@main = "return 5.as_char()"
check 53
end
def test_as_char2
@main = "return 10.as_char()"
check 32
end
def test_tos_one_digit
@main = "Word five = 5.to_s()
five.putstring()"
@stdout = "5"
check
end
def test_tos_one_digit_length
@main = "Word five = 5.to_s()
return five.char_length"
check 2
end
def test_tos_zero
@main = "Word five = 0.to_s()
five.putstring()"
@stdout = "0"
check
end
def test_tos_two_digit
@main = "Word five = 15.to_s()
five.putstring()"
@stdout = "15"
check
end
def test_tos_two_digit_length
@main = "Word five = 15.to_s()
return five.char_length"
check 3
end
def test_tos_three_digit
@main = "Word five = 150.to_s()
five.putstring()"
@stdout = "150"
check
end
def test_puti_four_digit
@main = "return 1234.puti()"
@stdout = "1234"
check 1234
end
def test_puti_seven_digit
@main = "int i = 301 * 4096
i = i + 1671
return i.puti()"
@stdout = "1234567"
check 1234567
end
def test_puti_seven_digit_length
@main = "int i = 301 * 4096
Word str = i.to_s()
return str.char_length"
check 8
end
def test_puti_eight_digit
@main = "int i = 3014 * 4096
i = i + 334
return i.puti()"
@stdout = "12345678"
check 12345678
end
def test_fibr8
@main = "int fib = 8.fibr( )
return fib.puti()"
@stdout = "21"
check 21
end
def test_fibw8
@main = "int fib = 8.fibw( )
return fib.puti()"
@stdout = "21"
check 21
end
def test_fibw20
@main = "int fib = 20.fibw( )
return fib.puti()"
@stdout = "6765"
check 6765
end
end

View File

@ -1,58 +0,0 @@
require_relative 'helper'
class TestTypeRT < MiniTest::Test
include ParfaitTests
def test_main
@main = "return 1"
check 1
end
def check_return_class val
end
def test_get_type
@main = "return get_type()"
interpreter = check
assert_equal Parfait::Type , interpreter.get_register(:r0).return_value.class
end
def test_get_class
@main = "return get_class()"
interpreter = check
assert_equal Parfait::Class , interpreter.get_register(:r0).return_value.class
end
def test_puts_class
@main = <<HERE
Word w = get_class_name()
w.putstring()
HERE
@stdout = "Space"
check
end
def test_puts_type_space
@main = <<HERE
Type l = get_type()
Word w = l.get_class_name()
w.putstring()
HERE
@stdout = "Type"
check
end
# copy of register parfait tests, in order
def test_message_type
@main = <<HERE
Message m = self.first_message
m = m.next_message
Word w = m.get_class_name()
w.putstring()
HERE
@stdout = "Message"
check
end
end

View File

@ -1,180 +0,0 @@
require_relative 'helper'
class TestwordRT < MiniTest::Test
include ParfaitTests
def test_len
@main = <<HERE
Word w = " "
return w.char_length
HERE
check 1
end
def test_set_len
@main = <<HERE
Word w = " "
w.set_length(2)
return w.char_length
HERE
check 2
end
def test_set_char_len
@main = <<HERE
Word w = " "
w.set_char_at(1 , 30)
return w.char_length
HERE
check 1
end
def test_set_char_len2
@main = <<HERE
Word w = " "
w.set_length(2)
w.set_char_at(2 , 30)
return w.char_length
HERE
check 2
end
def test_set_char_len3
@main = <<HERE
Word w = " "
w.set_length(2)
w.set_char_at(2 , 30)
return w.get_char_at(2)
HERE
check 30
end
def test_set_char_len4
@main = <<HERE
Word w = " "
w.set_char_at(1 , 20)
w.set_length(2)
return w.get_char_at(1)
HERE
check 20
end
def test_space
@main = <<HERE
Word w = " "
return w.get_char_at(1)
HERE
assert_equal 32 , " ".codepoints[0] # just checking
check 32
end
def test_add_doesnt_change1
@main = <<HERE
Word w = " "
w.push_char(48)
return w.get_char_at(1)
HERE
check 32
end
def test_after_add_get_works
@main = <<HERE
Word w = " "
w.push_char(48)
return w.get_char_at(2)
HERE
check 48
end
def test_after_add_length_works
@main = <<HERE
Word w = " "
w.push_char(32)
return w.char_length
HERE
check 2
end
def test_get1
@main = <<HERE
Word w = "12345"
return w.get_char_at(1)
HERE
check 49
end
def test_get2
@main = <<HERE
Word w = "12345"
return w.get_char_at(2)
HERE
check 50
end
def test_set2
@main = <<HERE
Word w = "12345"
w.set_char_at(2 , 51)
return w.get_char_at(2)
HERE
check 51
end
def test_push
@main = <<HERE
Word w = "1"
w.push_char(56)
return w.get_char_at(2)
HERE
check 56
end
def test_push1
@main = <<HERE
Word w = "1"
w.push_char(56)
return w.get_char_at(1)
HERE
check 49
end
def test_push_inlined
@main = <<HERE
Word w = "1"
int index = w.char_length + 1
w.set_length(index)
w.set_char_at(index , 56)
return w.char_length
HERE
check 2
end
def test_push_inlined2
@main = <<HERE
Word w = "1"
int index = w.char_length + 1
w.set_length(index)
return w.char_length
HERE
check 2
end
def test_push_len
@main = <<HERE
Word w = "1"
w.push_char(56)
return w.char_length
HERE
check 2
end
def test_push3_len
@main = <<HERE
Word w = "1"
w.push_char(56)
w.push_char(56)
w.push_char(56)
return w.char_length
HERE
check 4
end
end

View File

@ -1,37 +0,0 @@
require_relative '../../helper'
module Statements
def check
machine = Register.machine
machine.boot unless machine.booted
machine.parse_and_compile @string_input
produced = Register.machine.space.get_main.instructions
assert @expect , "No output given"
#assert_equal @expect.length , produced.instructions.length , "instructions length #{produced.instructions.to_ac}"
compare_instructions produced , @expect
produced
end
def compare_instructions instruction , expect
index = 0
start = instruction
begin
should = expect[index]
assert should , "No instruction at #{index}"
assert_equal instruction.class , should , "Expected at #{index+1}\n#{should(start)}"
index += 1
instruction = instruction.next
end while( instruction )
end
def should start
str = start.to_ac.to_s
str.gsub!("Register::","")
ret = ""
str.split(",").each_slice(7).each do |line|
ret += " " + line.join(",") + " ,\n"
end
ret
end
end

View File

@ -1,7 +0,0 @@
require_relative "test_assign"
require_relative "test_call"
require_relative "test_class"
require_relative "test_fields"
require_relative "test_if"
require_relative "test_return"
require_relative "test_while"

View File

@ -1,128 +0,0 @@
require_relative 'helper'
module Register
class TestAssignStatement < MiniTest::Test
include Statements
def setup
Register.machine.boot
end
def test_assign_op
@string_input = <<HERE
class Space
int main()
int n = 10 + 1
end
end
HERE
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label ,
FunctionReturn]
check
end
def test_assign_local
@string_input = <<HERE
class Space
int main()
int runner
runner = 5
end
end
HERE
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
check
end
def test_assign_local_assign
@string_input = <<HERE
class Space
int main()
int runner = 5
end
end
HERE
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
check
end
def test_assign_call
@string_input = <<HERE
class Space
int main()
int r = main()
end
end
HERE
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check
end
def test_frame_get
@string_input = <<HERE
class Space
int main()
int r = 5
return r
end
end
HERE
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, SetSlot ,
Label, FunctionReturn]
was = check
get = was.next(5)
assert_equal GetSlot , get.class
assert_equal 4, get.index , "Get to frame index must be offset, not #{get.index}"
end
def test_assign_arg
Register.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :blar)
@string_input = <<HERE
class Space
int main(int blar)
blar = 5
end
end
HERE
@expect = [Label, LoadConstant, SetSlot, Label, FunctionReturn]
was = check
set = was.next(2)
assert_equal SetSlot , set.class
assert_equal 10, set.index , "Set to args index must be offset, not #{set.index}"
end
def test_assign_int
@string_input = <<HERE
class Space
int main()
int r = 5
end
end
HERE
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
was = check
set = was.next(3)
assert_equal SetSlot , set.class
assert_equal 4, set.index , "Set to frame index must be offset, not #{set.index}"
end
def test_arg_get
# have to define bar externally, just because redefining main. Otherwise that would be automatic
Register.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :balr)
@string_input = <<HERE
class Space
int main(int balr)
return balr
end
end
HERE
@expect = [Label, GetSlot, SetSlot, Label, FunctionReturn]
was = check
get = was.next(1)
assert_equal GetSlot , get.class
assert_equal 10, get.index , "Get to frame index must be offset, not #{get.index}"
end
end
end

View File

@ -1,107 +0,0 @@
require_relative 'helper'
module Register
class TestCallStatement < MiniTest::Test
include Statements
def test_call_constant_int
@string_input = <<HERE
class Integer
int putint()
return 1
end
end
class Space
int main()
42.putint()
end
end
HERE
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn]
check
end
def test_call_constant_string
@string_input = <<HERE
class Word
int putstring()
return 1
end
end
class Space
int main()
"Hello".putstring()
end
end
HERE
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn]
check
end
def test_call_local_int
@string_input = <<HERE
class Integer
int putint()
return 1
end
end
class Space
int main()
int testi = 20
testi.putint()
end
end
HERE
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, GetSlot ,
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot ,
RegisterTransfer, FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, Label ,
FunctionReturn]
check
end
def test_call_local_class
@string_input = <<HERE
class List < Object
int add()
return 1
end
end
class Space
int main()
List test_l
test_l.add()
end
end
HERE
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label ,
RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
check
end
def test_call_puts
@string_input = <<HERE
class Space
int puts(Word str)
return str
end
int main()
puts("Hello")
end
end
HERE
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall ,
Label, RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
was = check
set = was.next(7)
assert_equal SetSlot , set.class
assert_equal 9, set.index , "Set to message must be offset, not #{set.index}"
end
end
end

View File

@ -1,56 +0,0 @@
require_relative 'helper'
module Register
class TestClassStatements < MiniTest::Test
include Statements
def test_class_defs
@string_input = <<HERE
class Bar
int self.buh()
return 1
end
end
class Space
int main()
return 1
end
end
HERE
@expect = [Label, LoadConstant,SetSlot,Label,FunctionReturn]
check
end
def test_class_call
@string_input = <<HERE
class Bar
int self.buh()
return 1
end
end
class Space
int main()
return Bar.buh()
end
end
HERE
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check
end
def test_class_field
@string_input = <<HERE
class Space
field int boo2
int main()
return self.boo2
end
end
HERE
@expect = [Label, GetSlot,GetSlot,SetSlot,Label,FunctionReturn]
check
end
end
end

View File

@ -1,68 +0,0 @@
require_relative 'helper'
module Register
class TestFieldStatement < MiniTest::Test
include Statements
def test_field_frame
@string_input = <<HERE
class Space
int main()
Message m
return m.name
end
end
HERE
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check
end
def test_field_arg
@string_input = <<HERE
class Space
int get_name(Message main)
return main.name
end
int main()
Message m
return get_name(m)
end
end
HERE
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, RegisterTransfer ,
FunctionCall, Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, Label ,
FunctionReturn]
check
end
def test_self_field
@string_input = <<HERE
class Space
int main()
Type l = self.type
return 1
end
end
HERE
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
Label, FunctionReturn]
check
end
def test_message_field
@string_input = <<HERE
class Space
int main()
Word name = message.name
return name
end
end
HERE
@expect = [Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, GetSlot, GetSlot ,
SetSlot, Label, FunctionReturn]
check
end
end
end

View File

@ -1,58 +0,0 @@
require_relative 'helper'
module Register
class TestIfStatement < MiniTest::Test
include Statements
def test_if_basicr
@string_input = <<HERE
class Space
int main()
if_plus( 10 - 12)
return 3
else
return 4
end
end
end
HERE
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot,
Label,Label,FunctionReturn]
check
end
def test_if_small_minus
@string_input = <<HERE
class Space
int main()
if_minus( 10 - 12)
return 3
end
end
end
HERE
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
LoadConstant, SetSlot, Label, Label, FunctionReturn]
check
end
def test_if_small_zero
@string_input = <<HERE
class Space
int main()
if_zero( 10 - 12)
return 3
end
end
end
HERE
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
Branch , Label , LoadConstant ,SetSlot,
Label,Label, FunctionReturn]
check
end
end
end

View File

@ -1,75 +0,0 @@
require_relative 'helper'
module Register
class TestReturnStatement < MiniTest::Test
include Statements
def test_return_int
@string_input = <<HERE
class Space
int main()
return 5
end
end
HERE
@expect = [Label, LoadConstant ,SetSlot,Label,FunctionReturn]
check
end
def test_return_local
@string_input = <<HERE
class Space
int main()
int runner
return runner
end
end
HERE
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
check
end
def test_return_local_assign
@string_input = <<HERE
class Space
int main()
int runner = 5
return runner
end
end
HERE
@expect = [Label, LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
Label,FunctionReturn]
check
end
def pest_return_space_length # need to add runtime first
@string_input = <<HERE
class Space
int main()
Type l = space.get_type()
return self.runner
end
end
HERE
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
check
end
def test_return_call
@string_input = <<HERE
class Space
int main()
return main()
end
end
HERE
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check
end
end
end

View File

@ -1,61 +0,0 @@
require_relative 'helper'
module Register
class TestWhile < MiniTest::Test
include Statements
def test_while_mini
@string_input = <<HERE
class Space
int main()
while_plus(1)
return 3
end
end
end
HERE
@expect = [Label, Branch, Label, LoadConstant, SetSlot, Label, LoadConstant ,
IsPlus, Label, FunctionReturn]
check
end
def test_while_assign
@string_input = <<HERE
class Space
int main()
int n = 5
while_plus(n)
n = n - 1
end
return n
end
end
HERE
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label, GetSlot ,
GetSlot, IsPlus, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check
end
def test_while_return
@string_input = <<HERE
class Space
int main()
int n = 10
while_plus( n - 5)
n = n + 1
return n
end
end
end
HERE
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, GetSlot, GetSlot ,
SetSlot, Label, GetSlot, GetSlot, LoadConstant, OperatorInstruction, IsPlus ,
Label, FunctionReturn]
check
end
end
end

View File

@ -1,7 +0,0 @@
require_relative "expressions/test_all"
require_relative "statements/test_all"
require_relative "fragments/test_all"
require_relative "parfait/test_all"

View File

@ -1,5 +1,3 @@
require_relative "soml/test_all"
require_relative "elf/test_all"
require_relative "register/test_all"