fix more expression tests
This commit is contained in:
parent
98bc0f6e40
commit
4054b61752
@ -8,7 +8,7 @@ module Typed
|
||||
clazz = Register.machine.space.get_class_by_name receiver.type
|
||||
field_name = statement.field.name
|
||||
index = clazz.instance_type.variable_index(field_name)
|
||||
raise "field access, but no such field:#{field_name} for class #{clazz.name}" unless index
|
||||
raise "no such field:#{field_name} for class #{clazz.name}:#{clazz.instance_type.inspect}" unless index
|
||||
value = use_reg(clazz.instance_type.type_at(index))
|
||||
|
||||
add_code Register.get_slot(statement , receiver , index, value)
|
||||
|
@ -23,7 +23,7 @@ module Typed
|
||||
private
|
||||
|
||||
def handle_local statement
|
||||
index = @method.has_local( name )
|
||||
index = @method.has_local( statement.name )
|
||||
raise "must define variable '#{name}' before using it" unless index
|
||||
frame = use_reg :Frame
|
||||
add_code Register.get_slot(statement , :message , :frame , frame )
|
||||
|
@ -25,4 +25,9 @@ module ExpressionHelper
|
||||
produced
|
||||
end
|
||||
|
||||
# test hack to in place change object type
|
||||
def add_object_field(name,type)
|
||||
class_type = Register.machine.space.get_class_by_name(:Object).instance_type
|
||||
class_type.send(:private_add_instance_variable, name , type)
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,4 @@
|
||||
require_relative "test_basic"
|
||||
require_relative "test_field_access"
|
||||
require_relative "test_ops"
|
||||
#require_relative "test_call"
|
||||
#require_relative "test_field_access"
|
||||
#require_relative "test_ops"
|
||||
|
@ -6,7 +6,6 @@ module Register
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@root = :call_site
|
||||
@output = Register::RegisterValue
|
||||
end
|
||||
|
||||
|
@ -3,6 +3,7 @@ require_relative "helper"
|
||||
module Register
|
||||
class TestFields < MiniTest::Test
|
||||
include ExpressionHelper
|
||||
include AST::Sexp
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@ -10,49 +11,25 @@ module Register
|
||||
|
||||
def test_field_not_defined
|
||||
@root = :field_access
|
||||
@input = <<HERE
|
||||
self.a
|
||||
HERE
|
||||
@input = s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :a)))
|
||||
assert_raises(RuntimeError) { check }
|
||||
end
|
||||
|
||||
def test_field_not_space
|
||||
@root = :field_access
|
||||
@input = <<HERE
|
||||
self.space
|
||||
HERE
|
||||
@input = s(:field_access,
|
||||
s(:receiver,
|
||||
s(:name, :self)),
|
||||
s(:field,
|
||||
s(:name, :space)))
|
||||
|
||||
assert_raises(RuntimeError) { check }
|
||||
end
|
||||
|
||||
def test_field
|
||||
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:Object)
|
||||
add_object_field(:bro,:Object)
|
||||
@root = :field_access
|
||||
@input = <<HERE
|
||||
self.bro
|
||||
HERE
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
end
|
||||
|
||||
def test_local
|
||||
Register.machine.space.get_main.ensure_local(:bar , :Integer)
|
||||
@root = :name
|
||||
@input = 'bar '
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
end
|
||||
|
||||
def test_space
|
||||
@root = :name
|
||||
@input = 'space '
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
end
|
||||
|
||||
def test_args
|
||||
Register.machine.space.get_main.arguments.push Parfait::Variable.new(:Integer , :bar)
|
||||
@root = :name
|
||||
@input = 'bar '
|
||||
@input = s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :bro)))
|
||||
@output = Register::RegisterValue
|
||||
check
|
||||
end
|
||||
|
@ -3,6 +3,7 @@ require_relative "helper"
|
||||
module Register
|
||||
class TestOps < MiniTest::Test
|
||||
include ExpressionHelper
|
||||
include AST::Sexp
|
||||
|
||||
def setup
|
||||
Register.machine.boot
|
||||
@ -11,34 +12,37 @@ module Register
|
||||
end
|
||||
|
||||
def operators
|
||||
["+" , "-" , "*" , "/" , "=="]
|
||||
[:+ , :- , :* , :/ , :== ]
|
||||
end
|
||||
def test_ints
|
||||
operators.each do |op|
|
||||
@input = '2 + 3'.sub("+" , op)
|
||||
@input = s(:operator_value, op , s(:int, 2), s(:int, 3))
|
||||
check
|
||||
end
|
||||
end
|
||||
def test_local_int
|
||||
Register.machine.space.get_main.ensure_local(:bar , :Integer)
|
||||
@input = 'bar + 3'
|
||||
@input = s(:operator_value, :+, s(:name, :bar), s(:int, 3))
|
||||
check
|
||||
end
|
||||
def test_int_local
|
||||
Register.machine.space.get_main.ensure_local(:bar , :Integer)
|
||||
@input = '3 + bar'
|
||||
@input = s(:operator_value, :+, s(:int, 3), s(:name, :bar))
|
||||
check
|
||||
end
|
||||
|
||||
def test_field_int
|
||||
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:int)
|
||||
@input = "self.bro + 3"
|
||||
add_object_field(:bro,:int)
|
||||
@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
|
||||
Register.machine.space.get_class_by_name(:Object).instance_type.add_instance_variable(:bro,:int)
|
||||
@input = "3 + self.bro"
|
||||
add_object_field(:bro,:int)
|
||||
@input = s(:operator_value, :+, s(:int, 3), s(:field_access, s(:receiver, s(:name, :self)),
|
||||
s(:field,s(:name, :bro))))
|
||||
check
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user