move stashed tests
This commit is contained in:
@ -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
|
@ -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"
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
Reference in New Issue
Block a user