whilespace in s-exps
This commit is contained in:
parent
99454b3efe
commit
fa0e279620
@ -13,27 +13,7 @@ class HelloTest < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_string_put
|
||||
@string_input = <<HERE
|
||||
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")))))))))
|
||||
@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
|
||||
end
|
||||
end
|
||||
|
@ -11,18 +11,7 @@ class Space
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@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))))))))
|
||||
@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))))))))
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -19,40 +19,7 @@ class Space
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@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))))))))
|
||||
@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))))))))
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -13,18 +13,7 @@ class Space
|
||||
end
|
||||
|
||||
HERE
|
||||
@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))))))))
|
||||
@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))))))))
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -11,18 +11,7 @@ class Space
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@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))))))))
|
||||
@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))))))))
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -11,19 +11,7 @@ class Space
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@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"))))))))
|
||||
@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"))))))))
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -11,28 +11,28 @@ module Register
|
||||
end
|
||||
|
||||
def test_call_main_plain
|
||||
@input = s(:call, s(:name, :main), s(:arguments))
|
||||
@input = s(:call,s(:name, :main),s(:arguments))
|
||||
check
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
def test_call_main_op
|
||||
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
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -17,11 +17,7 @@ module Register
|
||||
|
||||
def test_field_not_space
|
||||
@root = :field_access
|
||||
@input = s(:field_access,
|
||||
s(:receiver,
|
||||
s(:name, :self)),
|
||||
s(:field,
|
||||
s(:name, :space)))
|
||||
@input = s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :space)))
|
||||
|
||||
assert_raises(RuntimeError) { check }
|
||||
end
|
||||
@ -29,7 +25,7 @@ module Register
|
||||
def test_field
|
||||
add_space_field(:bro,:Object)
|
||||
@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
|
||||
check
|
||||
end
|
||||
|
@ -33,16 +33,13 @@ module Register
|
||||
|
||||
def test_field_int
|
||||
add_space_field(:bro,:int)
|
||||
@input = s(:operator_value, :+, s(:field_access, s(:receiver, s(:name, :self)),
|
||||
s(:field, s(:name, :bro))),
|
||||
s(:int, 3))
|
||||
@input = s(:operator_value, :+, s(:field_access,s(:receiver, s(:name, :self)), s(:field, s(:name, :bro))), s(:int, 3))
|
||||
check
|
||||
end
|
||||
|
||||
def test_int_field
|
||||
add_space_field(:bro,:int)
|
||||
@input = s(:operator_value, :+, s(:int, 3), s(:field_access, s(:receiver, s(:name, :self)),
|
||||
s(:field,s(:name, :bro))))
|
||||
@input = s(:operator_value, :+, s(:int, 3), s(:field_access, s(:receiver, s(:name, :self)), s(:field,s(:name, :bro))))
|
||||
check
|
||||
end
|
||||
end
|
||||
|
@ -9,8 +9,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_assign_op
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :n),
|
||||
s(:operator_value, :+, s(:int, 10), s(:int, 1))))
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :n), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
|
||||
|
||||
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label ,
|
||||
FunctionReturn]
|
||||
@ -18,8 +17,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_assign_local
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :runner)),
|
||||
s(:assignment, s(:name, :runner), s(:int, 5)))
|
||||
@input =s(:statements, s(:field_def, :Integer, s(:name, :runner)), s(:assignment, s(:name, :runner), s(:int, 5)))
|
||||
|
||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, Label, FunctionReturn]
|
||||
check
|
||||
@ -33,8 +31,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_assign_call
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :r),
|
||||
s(:call, s(:name, :main), s(:arguments))))
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
|
||||
@expect = [Label, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||
GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
||||
@ -42,8 +39,7 @@ class TestAssignStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_frame_get
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :r), s(:int, 5)),
|
||||
s(:return, s(:name, :r)))
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
|
||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, GetSlot, GetSlot, SetSlot ,
|
||||
Label, FunctionReturn]
|
||||
was = check
|
||||
|
@ -5,9 +5,7 @@ class TestCallStatement < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def test_call_constant_int
|
||||
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)))))))
|
||||
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)))))))
|
||||
@input = s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:int, 42)))
|
||||
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||
@ -17,22 +15,9 @@ class TestCallStatement < MiniTest::Test
|
||||
|
||||
|
||||
def test_call_constant_string
|
||||
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)))))))
|
||||
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)))))))
|
||||
|
||||
@input = s(:call,
|
||||
s(:name, :putstring),
|
||||
s(:arguments),
|
||||
s(:receiver,
|
||||
s(:string, "Hello")))
|
||||
@input =s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "Hello")))
|
||||
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||
GetSlot, GetSlot, Label, FunctionReturn]
|
||||
@ -40,18 +25,8 @@ class TestCallStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def _test_call_local_int
|
||||
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)))))))
|
||||
@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))))
|
||||
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)))))))
|
||||
@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 ,
|
||||
SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot ,
|
||||
@ -61,25 +36,9 @@ class TestCallStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_call_local_class
|
||||
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)))))))
|
||||
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)))))))
|
||||
|
||||
@input = s(:statements,
|
||||
s(:field_def, :List,
|
||||
s(:name, :test_l)),
|
||||
s(:call,
|
||||
s(:name, :add),
|
||||
s(:arguments),
|
||||
s(:receiver,
|
||||
s(:name, :test_l))))
|
||||
@input =s(:statements, 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 ,
|
||||
LoadConstant, SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label ,
|
||||
RegisterTransfer, GetSlot, GetSlot, Label, FunctionReturn]
|
||||
|
@ -5,35 +5,19 @@ class TestClassStatements < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def class_def
|
||||
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)))))
|
||||
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)))))
|
||||
end
|
||||
|
||||
def test_class_defs
|
||||
class_def
|
||||
@input = s(:statements, s(:return, s(:int, 1)))
|
||||
@input =s(:statements, s(:return, s(:int, 1)))
|
||||
@expect = [Label, LoadConstant,SetSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
def test_class_call
|
||||
class_def
|
||||
@input = s(:statements,
|
||||
s(:return,
|
||||
s(:call,
|
||||
s(:name, :buh),
|
||||
s(:arguments),
|
||||
s(:receiver,
|
||||
s(:class_name, :Bar)))))
|
||||
@input = s(:statements, s(:return, s(:call, s(:name, :buh), s(:arguments), s(:receiver, s(:class_name, :Bar)))))
|
||||
|
||||
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||
@ -42,16 +26,10 @@ class TestClassStatements < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_class_field
|
||||
clean_compile s(:statements,
|
||||
s(:class, :Space,
|
||||
s(:derives, nil),
|
||||
s(:statements,
|
||||
s(:class_field, :Integer, :boo2))))
|
||||
clean_compile s(:statements, s(:class, :Space, s(:derives, nil), s(:statements, s(:class_field, :Integer, :boo2))))
|
||||
|
||||
@input = s(:statements,
|
||||
s(:return,
|
||||
s(:field_access, s(:receiver, s(:name, :self)),
|
||||
s(:field, s(:name, :boo2)))))
|
||||
@input =s(:statements, s(:return, s(:field_access, s(:receiver, s(:name, :self)),
|
||||
s(:field,s(:name, :boo2)))))
|
||||
@expect = [Label, GetSlot,GetSlot,SetSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
@ -6,45 +6,16 @@ module Register
|
||||
include Statements
|
||||
|
||||
def test_field_frame
|
||||
@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)))))
|
||||
@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)))))
|
||||
|
||||
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
def test_field_arg
|
||||
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)))))))))
|
||||
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)))))))))
|
||||
|
||||
@input = s(:statements,
|
||||
s(:field_def, :Message,
|
||||
s(:name, :m)),
|
||||
s(:return,
|
||||
s(:call,
|
||||
s(:name, :get_name),
|
||||
s(:arguments,
|
||||
s(:name, :m)))))
|
||||
@input =s(:statements, 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 ,
|
||||
SetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot, RegisterTransfer ,
|
||||
@ -54,16 +25,7 @@ module Register
|
||||
end
|
||||
|
||||
def test_self_field
|
||||
@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)))
|
||||
@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)))
|
||||
|
||||
@expect = [Label, GetSlot, GetSlot, GetSlot, SetSlot, LoadConstant, SetSlot ,
|
||||
Label, FunctionReturn]
|
||||
@ -71,16 +33,7 @@ module Register
|
||||
end
|
||||
|
||||
def test_message_field
|
||||
@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)))
|
||||
@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)))
|
||||
|
||||
@expect = [Label, RegisterTransfer, GetSlot, GetSlot, SetSlot, GetSlot, GetSlot ,
|
||||
SetSlot, Label, FunctionReturn]
|
||||
|
@ -5,18 +5,7 @@ class TestIfStatement < MiniTest::Test
|
||||
include Statements
|
||||
|
||||
def test_if_basicr
|
||||
@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)))))
|
||||
@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)))))
|
||||
|
||||
@expect = [Label, LoadConstant,LoadConstant, OperatorInstruction,IsPlus ,
|
||||
LoadConstant,SetSlot,Branch , Label , LoadConstant ,SetSlot,
|
||||
@ -26,16 +15,7 @@ class TestIfStatement < MiniTest::Test
|
||||
|
||||
|
||||
def test_if_small_minus
|
||||
@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)))
|
||||
@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)))
|
||||
|
||||
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, IsMinus, Branch, Label ,
|
||||
LoadConstant, SetSlot, Label, Label, FunctionReturn]
|
||||
@ -44,16 +24,7 @@ class TestIfStatement < MiniTest::Test
|
||||
|
||||
|
||||
def test_if_small_zero
|
||||
@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)))
|
||||
@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)))
|
||||
|
||||
@expect = [Label, LoadConstant,LoadConstant,OperatorInstruction,IsZero ,
|
||||
Branch , Label , LoadConstant ,SetSlot,
|
||||
|
@ -11,22 +11,20 @@ class TestReturnStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def test_return_local
|
||||
@input = s(:statements,s(:field_def, :Integer, s(:name, :runner)),
|
||||
s(:return, s(:name, :runner)))
|
||||
@input = s(:statements,s(:field_def, :Integer, s(:name, :runner)), s(:return, s(:name, :runner)))
|
||||
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
def test_return_local_assign
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :runner), s(:int, 5)),
|
||||
s(:return, s(:name, :runner)))
|
||||
@input = s(:statements, s(:field_def, :Integer, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
|
||||
@expect = [Label, LoadConstant,GetSlot,SetSlot,GetSlot,GetSlot ,SetSlot,
|
||||
Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
||||
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 ,
|
||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||
GetSlot, GetSlot, SetSlot, Label, FunctionReturn]
|
||||
@ -34,11 +32,7 @@ class TestReturnStatement < MiniTest::Test
|
||||
end
|
||||
|
||||
def pest_return_space_length # need to add runtime first
|
||||
@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)))))
|
||||
@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)))))
|
||||
@expect = [Label, GetSlot,GetSlot ,SetSlot,Label,FunctionReturn]
|
||||
check
|
||||
end
|
||||
|
@ -6,13 +6,7 @@ module Register
|
||||
|
||||
|
||||
def test_while_mini
|
||||
@input = s(:statements,
|
||||
s(:while_statement, :plus,
|
||||
s(:conditional,
|
||||
s(:int, 1)),
|
||||
s(:statements,
|
||||
s(:return,
|
||||
s(:int, 3)))))
|
||||
@input = s(:statements, s(:while_statement, :plus, s(:conditional, s(:int, 1)), s(:statements, s(:return, s(:int, 3)))))
|
||||
|
||||
@expect = [Label, Branch, Label, LoadConstant, SetSlot, Label, LoadConstant ,
|
||||
IsPlus, Label, FunctionReturn]
|
||||
@ -20,21 +14,7 @@ module Register
|
||||
end
|
||||
|
||||
def test_while_assign
|
||||
@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)))
|
||||
@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)))
|
||||
|
||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
|
||||
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, Label, GetSlot ,
|
||||
@ -44,23 +24,7 @@ module Register
|
||||
|
||||
|
||||
def test_while_return
|
||||
@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)))))
|
||||
@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)))))
|
||||
|
||||
@expect = [Label, LoadConstant, GetSlot, SetSlot, Branch, Label, GetSlot ,
|
||||
GetSlot, LoadConstant, OperatorInstruction, GetSlot, SetSlot, GetSlot, GetSlot ,
|
||||
|
@ -45,7 +45,7 @@ class ToCodeTest < MiniTest::Test
|
||||
check "NameExpression"
|
||||
end
|
||||
def test_class_name
|
||||
@statement = s(:class_name, :FooBar)
|
||||
@statement =s(:class_name, :FooBar)
|
||||
check "ClassExpression"
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user