whilespace in s-exps

This commit is contained in:
Torsten Ruger 2016-12-10 23:07:04 +02:00
parent 99454b3efe
commit fa0e279620
17 changed files with 55 additions and 345 deletions

View File

@ -13,27 +13,7 @@ class HelloTest < MiniTest::Test
end end
def test_string_put def test_string_put
@string_input = <<HERE @input = s(:statements, s(:class, :Object, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :main), s(:parameters), s(:statements, s(:return, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "Hello again\\n")))))))))
class Object
int main()
return "Hello again\n".putstring()
end
end
HERE
@input = s(:statements,
s(:class, :Object,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :main),
s(:parameters),
s(:statements,
s(:return,
s(:call,
s(:name, :putstring),
s(:arguments),
s(:receiver,
s(:string, "Hello again\\n")))))))))
check check
end end
end end

View File

@ -11,18 +11,7 @@ class Space
end end
end end
HERE HERE
@input = s(:statements, @input = s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :main), s(:parameters), s(:statements, s(:return, s(:operator_value, :+, s(:int, 5), s(:int, 7))))))))
s(:class, :Space,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :main),
s(:parameters),
s(:statements,
s(:return,
s(:operator_value, :+,
s(:int, 5),
s(:int, 7))))))))
super super
end end

View File

@ -19,40 +19,7 @@ class Space
end end
end end
HERE HERE
@input = s(:statements, @input = s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :itest), s(:parameters, s(:parameter, :Integer, :n)), s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:name, :n), s(:int, 12))), s(:true_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "then")))), s(:false_statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "else"))))))), s(:function, :Integer, s(:name, :main), s(:parameters), s(:statements, s(:call, s(:name, :itest), s(:arguments, s(:int, 20))))))))
s(:class, :Space,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :itest),
s(:parameters,
s(:parameter, :Integer, :n)),
s(:statements,
s(:if_statement, :zero,
s(:condition,
s(:operator_value, :-,
s(:name, :n),
s(:int, 12))),
s(:true_statements,
s(:call,
s(:name, :putstring),
s(:arguments),
s(:receiver,
s(:string, "then")))),
s(:false_statements,
s(:call,
s(:name, :putstring),
s(:arguments),
s(:receiver,
s(:string, "else"))))))),
s(:function, :Integer,
s(:name, :main),
s(:parameters),
s(:statements,
s(:call,
s(:name, :itest),
s(:arguments,
s(:int, 20))))))))
super super
end end

View File

@ -13,18 +13,7 @@ class Space
end end
HERE HERE
@input = s(:statements, @input = s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :main), s(:parameters), s(:statements, s(:return, s(:operator_value, :*, s(:int, 2147483648), s(:int, 2147483648))))))))
s(:class, :Space,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :main),
s(:parameters),
s(:statements,
s(:return,
s(:operator_value, :*,
s(:int, 2147483648),
s(:int, 2147483648))))))))
super super
end end

View File

@ -11,18 +11,7 @@ class Space
end end
end end
HERE HERE
@input = s(:statements, @input = s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :main), s(:parameters), s(:statements, s(:return, s(:operator_value, :+, s(:int, 4611686018427387903), s(:int, 1))))))))
s(:class, :Space,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :main),
s(:parameters),
s(:statements,
s(:return,
s(:operator_value, :+,
s(:int, 4611686018427387903),
s(:int, 1))))))))
super super
end end

View File

@ -11,19 +11,7 @@ class Space
end end
end end
HERE HERE
@input = s(:statements, @input = s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :main), s(:parameters), s(:statements, s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "Hello again"))))))))
s(:class, :Space,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :main),
s(:parameters),
s(:statements,
s(:call,
s(:name, :putstring),
s(:arguments),
s(:receiver,
s(:string, "Hello again"))))))))
super super
end end

View File

@ -11,28 +11,28 @@ module Register
end end
def test_call_main_plain def test_call_main_plain
@input = s(:call, s(:name, :main), s(:arguments)) @input = s(:call,s(:name, :main),s(:arguments))
check check
end end
def test_call_main_int def test_call_main_int
@input = s(:call, s(:name, :main), s(:arguments , s(:int, 1))) @input =s(:call,s(:name, :main),s(:arguments , s(:int, 1)))
check check
end end
def test_call_main_string def test_call_main_string
@input = s(:call, s(:name, :main), s(:arguments , s(:string, "1") )) @input =s(:call,s(:name, :main),s(:arguments , s(:string, "1") ))
check check
end end
def test_call_main_op def test_call_main_op
Register.machine.space.get_main.ensure_local(:bar , :Integer) Register.machine.space.get_main.ensure_local(:bar , :Integer)
@input = s(:call, s(:name, :main), s(:arguments , s(:name, :bar) )) @input =s(:call,s(:name, :main),s(:arguments , s(:name, :bar) ))
check check
end end
def test_call_string_put def test_call_string_put
@input = s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "Hello Raisa, I am salama"))) @input = s(:call,s(:name, :putstring),s(:arguments),s(:receiver,s(:string, "Hello Raisa, I am salama")))
check check
end end

View File

@ -17,11 +17,7 @@ module Register
def test_field_not_space def test_field_not_space
@root = :field_access @root = :field_access
@input = s(:field_access, @input = s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :space)))
s(:receiver,
s(:name, :self)),
s(:field,
s(:name, :space)))
assert_raises(RuntimeError) { check } assert_raises(RuntimeError) { check }
end end
@ -29,7 +25,7 @@ module Register
def test_field def test_field
add_space_field(:bro,:Object) add_space_field(:bro,:Object)
@root = :field_access @root = :field_access
@input = s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :bro))) @input = s(:field_access,s(:receiver, s(:name, :self)),s(:field,s(:name, :bro)))
@output = Register::RegisterValue @output = Register::RegisterValue
check check
end end

View File

@ -33,16 +33,13 @@ module Register
def test_field_int def test_field_int
add_space_field(:bro,:int) add_space_field(:bro,:int)
@input = s(:operator_value, :+, s(:field_access, s(:receiver, s(:name, :self)), @input = s(:operator_value, :+, s(:field_access,s(:receiver, s(:name, :self)), s(:field, s(:name, :bro))), s(:int, 3))
s(:field, s(:name, :bro))),
s(:int, 3))
check check
end end
def test_int_field def test_int_field
add_space_field(:bro,:int) add_space_field(:bro,:int)
@input = s(:operator_value, :+, s(:int, 3), s(:field_access, s(:receiver, s(:name, :self)), @input = s(:operator_value, :+, s(:int, 3), s(:field_access, s(:receiver, s(:name, :self)), s(:field,s(:name, :bro))))
s(:field,s(:name, :bro))))
check check
end end
end end

View File

@ -9,8 +9,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_assign_op def test_assign_op
@input = s(:statements, s(:field_def, :Integer, s(:name, :n), @input = s(:statements, s(:field_def, :Integer, s(:name, :n), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
s(:operator_value, :+, s(:int, 10), s(:int, 1))))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label , @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label ,
FunctionReturn] FunctionReturn]
@ -18,8 +17,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_assign_local def test_assign_local
@input = s(:statements, s(:field_def, :Integer, s(:name, :runner)), @input =s(:statements, s(:field_def, :Integer, s(:name, :runner)), s(:assignment, s(:name, :runner), s(:int, 5)))
s(:assignment, s(:name, :runner), s(:int, 5)))
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
check check
@ -33,8 +31,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_assign_call def test_assign_call
@input = s(:statements, s(:field_def, :Integer, s(:name, :r), @input = s(:statements, s(:field_def, :Integer, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant , @expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn] GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
@ -42,8 +39,7 @@ class TestAssignStatement < MiniTest::Test
end end
def test_frame_get def test_frame_get
@input = s(:statements, s(:field_def, :Integer, s(:name, :r), s(:int, 5)), @input = s(:statements, s(:field_def, :Integer, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
s(:return, s(:name, :r)))
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, SetSlot , @expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, SetSlot ,
Label, FunctionReturn] Label, FunctionReturn]
was = check was = check

View File

@ -5,9 +5,7 @@ class TestCallStatement < MiniTest::Test
include Statements include Statements
def test_call_constant_int def test_call_constant_int
clean_compile s(:statements, s(:class, :Integer, s(:derives, nil), s(:statements, clean_compile s(:statements, s(:class, :Integer, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :putint), s(:parameters), s(:statements, s(:return, s(:int, 1)))))))
s(:function, :Integer, s(:name, :putint), s(:parameters),
s(:statements, s(:return, s(:int, 1)))))))
@input = s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:int, 42))) @input = s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:int, 42)))
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant , @expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
@ -17,22 +15,9 @@ class TestCallStatement < MiniTest::Test
def test_call_constant_string def test_call_constant_string
clean_compile s(:statements, clean_compile s(:statements, s(:class, :Word, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :putstring), s(:parameters), s(:statements, s(:return, s(:int, 1)))))))
s(:class, :Word,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :putstring),
s(:parameters),
s(:statements,
s(:return,
s(:int, 1)))))))
@input = s(:call, @input =s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "Hello")))
s(:name, :putstring),
s(:arguments),
s(:receiver,
s(:string, "Hello")))
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant , @expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn] GetSlot, GetSlot, Label, FunctionReturn]
@ -40,18 +25,8 @@ class TestCallStatement < MiniTest::Test
end end
def _test_call_local_int def _test_call_local_int
clean_compile s(:statements, clean_compile s(:statements, s(:class, :Integer, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :putint), s(:parameters), s(:statements, s(:return, s(:int, 1)))))))
s(:class, :Integer, @input = s(:statements, s(:field_def, :Integer, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :putint),
s(:parameters),
s(:statements,
s(:return,
s(:int, 1)))))))
@input = s(:statements, s(:field_def, :Integer, s(:name, :testi), s(:int, 20)),
s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, GetSlot , @expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, GetSlot ,
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot , SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot ,
@ -61,25 +36,9 @@ class TestCallStatement < MiniTest::Test
end end
def test_call_local_class def test_call_local_class
clean_compile s(:statements, clean_compile s(:statements, s(:class, :List, s(:derives, :Object), s(:statements, s(:function, :Integer, s(:name, :add), s(:parameters), s(:statements, s(:return, s(:int, 1)))))))
s(:class, :List,
s(:derives, :Object),
s(:statements,
s(:function, :Integer,
s(:name, :add),
s(:parameters),
s(:statements,
s(:return,
s(:int, 1)))))))
@input = s(:statements, @input =s(:statements, s(:field_def, :List, s(:name, :test_l)), s(:call, s(:name, :add), s(:arguments), s(:receiver, s(:name, :test_l))))
s(:field_def, :List,
s(:name, :test_l)),
s(:call,
s(:name, :add),
s(:arguments),
s(:receiver,
s(:name, :test_l))))
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot , @expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label , LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label ,
RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn] RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]

View File

@ -5,35 +5,19 @@ class TestClassStatements < MiniTest::Test
include Statements include Statements
def class_def def class_def
clean_compile s(:statements, clean_compile s(:statements, s(:class, :Bar, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :buh), s(:parameters), s(:statements, s(:return, s(:int, 1))), s(:receiver, :self)))))
s(:class, :Bar,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :buh),
s(:parameters),
s(:statements,
s(:return,
s(:int, 1))),
s(:receiver, :self)))))
end end
def test_class_defs def test_class_defs
class_def class_def
@input = s(:statements, s(:return, s(:int, 1))) @input =s(:statements, s(:return, s(:int, 1)))
@expect = [Label, LoadConstant,SetSlot,Label,FunctionReturn] @expect = [Label, LoadConstant,SetSlot,Label,FunctionReturn]
check check
end end
def test_class_call def test_class_call
class_def class_def
@input = s(:statements, @input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar)))))
s(:return,
s(:call,
s(:name, :buh),
s(:arguments),
s(:receiver,
s(:class_name, :Bar)))))
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant , @expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
@ -42,16 +26,10 @@ class TestClassStatements < MiniTest::Test
end end
def test_class_field def test_class_field
clean_compile s(:statements, clean_compile s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:class_field, :Integer, :boo2))))
s(:class, :Space,
s(:derives, nil),
s(:statements,
s(:class_field, :Integer, :boo2))))
@input = s(:statements, @input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)),
s(:return, s(:field,s(:name, :boo2)))))
s(:field_access, s(:receiver, s(:name, :self)),
s(:field, s(:name, :boo2)))))
@expect = [Label, GetSlot,GetSlot,SetSlot,Label,FunctionReturn] @expect = [Label, GetSlot,GetSlot,SetSlot,Label,FunctionReturn]
check check
end end

View File

@ -6,45 +6,16 @@ module Register
include Statements include Statements
def test_field_frame def test_field_frame
@input = s(:statements, @input = s(:statements, s(:field_def, :Message, s(:name, :m)), s(:return, s(:field_access, s(:receiver, s(:name, :m)), s(:field, s(:name, :name)))))
s(:field_def, :Message,
s(:name, :m)),
s(:return,
s(:field_access,
s(:receiver,
s(:name, :m)),
s(:field,
s(:name, :name)))))
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn] @expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
check check
end end
def test_field_arg def test_field_arg
clean_compile s(:statements, clean_compile s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:function, :Integer, s(:name, :get_name), s(:parameters, s(:parameter, :Message, :main)), s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :main)), s(:field, s(:name, :name)))))))))
s(:class, :Space,
s(:derives, nil),
s(:statements,
s(:function, :Integer,
s(:name, :get_name),
s(:parameters,
s(:parameter, :Message, :main)),
s(:statements,
s(:return,
s(:field_access,
s(:receiver,
s(:name, :main)),
s(:field,
s(:name, :name)))))))))
@input = s(:statements, @input =s(:statements, s(:field_def, :Message, s(:name, :m)), s(:return, s(:call, s(:name, :get_name), s(:arguments, s(:name, :m)))))
s(:field_def, :Message,
s(:name, :m)),
s(:return,
s(:call,
s(:name, :get_name),
s(:arguments,
s(:name, :m)))))
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant , @expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, RegisterTransfer , SetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, RegisterTransfer ,
@ -54,16 +25,7 @@ module Register
end end
def test_self_field def test_self_field
@input = s(:statements, @input = s(:statements, s(:field_def, :Type, s(:name, :l), s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :type)))), s(:return, s(:int, 1)))
s(:field_def, :Type,
s(:name, :l),
s(:field_access,
s(:receiver,
s(:name, :self)),
s(:field,
s(:name, :type)))),
s(:return,
s(:int, 1)))
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot , @expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
Label, FunctionReturn] Label, FunctionReturn]
@ -71,16 +33,7 @@ module Register
end end
def test_message_field def test_message_field
@input = s(:statements, @input = s(:statements, s(:field_def, :Word, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name)))
s(:field_def, :Word,
s(:name, :name),
s(:field_access,
s(:receiver,
s(:name, :message)),
s(:field,
s(:name, :name)))),
s(:return,
s(:name, :name)))
@expect = [Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, GetSlot, GetSlot , @expect = [Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, GetSlot, GetSlot ,
SetSlot, Label, FunctionReturn] SetSlot, Label, FunctionReturn]

View File

@ -5,18 +5,7 @@ class TestIfStatement < MiniTest::Test
include Statements include Statements
def test_if_basicr def test_if_basicr
@input = s(:statements, @input = s(:statements, s(:if_statement, :plus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, s(:return, s(:int, 4)))))
s(:if_statement, :plus,
s(:condition,
s(:operator_value, :-,
s(:int, 10),
s(:int, 12))),
s(:true_statements,
s(:return,
s(:int, 3))),
s(:false_statements,
s(:return,
s(:int, 4)))))
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus , @expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot, LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot,
@ -26,16 +15,7 @@ class TestIfStatement < MiniTest::Test
def test_if_small_minus def test_if_small_minus
@input = s(:statements, @input = s(:statements, s(:if_statement, :minus, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
s(:if_statement, :minus,
s(:condition,
s(:operator_value, :-,
s(:int, 10),
s(:int, 12))),
s(:true_statements,
s(:return,
s(:int, 3))),
s(:false_statements, nil)))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label , @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
LoadConstant, SetSlot, Label, Label, FunctionReturn] LoadConstant, SetSlot, Label, Label, FunctionReturn]
@ -44,16 +24,7 @@ class TestIfStatement < MiniTest::Test
def test_if_small_zero def test_if_small_zero
@input = s(:statements, @input = s(:statements, s(:if_statement, :zero, s(:condition, s(:operator_value, :-, s(:int, 10), s(:int, 12))), s(:true_statements, s(:return, s(:int, 3))), s(:false_statements, nil)))
s(:if_statement, :zero,
s(:condition,
s(:operator_value, :-,
s(:int, 10),
s(:int, 12))),
s(:true_statements,
s(:return,
s(:int, 3))),
s(:false_statements, nil)))
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero , @expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
Branch , Label , LoadConstant ,SetSlot, Branch , Label , LoadConstant ,SetSlot,

View File

@ -11,22 +11,20 @@ class TestReturnStatement < MiniTest::Test
end end
def test_return_local def test_return_local
@input = s(:statements,s(:field_def, :Integer, s(:name, :runner)), @input = s(:statements,s(:field_def, :Integer, s(:name, :runner)), s(:return, s(:name, :runner)))
s(:return, s(:name, :runner)))
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn] @expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
check check
end end
def test_return_local_assign def test_return_local_assign
@input = s(:statements, s(:field_def, :Integer, s(:name, :runner), s(:int, 5)), @input = s(:statements, s(:field_def, :Integer, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
s(:return, s(:name, :runner)))
@expect = [Label, LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot, @expect = [Label, LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
Label,FunctionReturn] Label,FunctionReturn]
check check
end end
def test_return_call def test_return_call
@input = s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments)))) @input =s(:statements, s(:return, s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant , @expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer , SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, SetSlot, Label, FunctionReturn] GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
@ -34,11 +32,7 @@ class TestReturnStatement < MiniTest::Test
end end
def pest_return_space_length # need to add runtime first def pest_return_space_length # need to add runtime first
@input = s(:statements, s(:field_def, :Type, s(:name, :l), @input = s(:statements, s(:field_def, :Type, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))),
s(:return, s(:field_access,
s(:receiver, s(:name, :self)),
s(:field, s(:name, :runner)))))
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn] @expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
check check
end end

View File

@ -6,13 +6,7 @@ module Register
def test_while_mini def test_while_mini
@input = s(:statements, @input = s(:statements, s(:while_statement, :plus, s(:conditional, s(:int, 1)), s(:statements, s(:return, s(:int, 3)))))
s(:while_statement, :plus,
s(:conditional,
s(:int, 1)),
s(:statements,
s(:return,
s(:int, 3)))))
@expect = [Label, Branch, Label, LoadConstant, SetSlot, Label, LoadConstant , @expect = [Label, Branch, Label, LoadConstant, SetSlot, Label, LoadConstant ,
IsPlus, Label, FunctionReturn] IsPlus, Label, FunctionReturn]
@ -20,21 +14,7 @@ module Register
end end
def test_while_assign def test_while_assign
@input = s(:statements, @input = s(:statements, s(:field_def, :Integer, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n)))
s(:field_def, :Integer,
s(:name, :n),
s(:int, 5)),
s(:while_statement, :plus,
s(:conditional,
s(:name, :n)),
s(:statements,
s(:assignment,
s(:name, :n),
s(:operator_value, :-,
s(:name, :n),
s(:int, 1))))),
s(:return,
s(:name, :n)))
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot , @expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label, GetSlot , GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label, GetSlot ,
@ -44,23 +24,7 @@ module Register
def test_while_return def test_while_return
@input = s(:statements, @input = s(:statements, s(:field_def, :Integer, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n)))))
s(:field_def, :Integer,
s(:name, :n),
s(:int, 10)),
s(:while_statement, :plus,
s(:conditional,
s(:operator_value, :-,
s(:name, :n),
s(:int, 5))),
s(:statements,
s(:assignment,
s(:name, :n),
s(:operator_value, :+,
s(:name, :n),
s(:int, 1))),
s(:return,
s(:name, :n)))))
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot , @expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, GetSlot, GetSlot , GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, GetSlot, GetSlot ,

View File

@ -45,7 +45,7 @@ class ToCodeTest < MiniTest::Test
check "NameExpression" check "NameExpression"
end end
def test_class_name def test_class_name
@statement = s(:class_name, :FooBar) @statement =s(:class_name, :FooBar)
check "ClassExpression" check "ClassExpression"
end end
end end