diff --git a/lib/typed/compiler/field_access.rb b/lib/typed/compiler/field_access.rb index 15b3976f..0a77081a 100644 --- a/lib/typed/compiler/field_access.rb +++ b/lib/typed/compiler/field_access.rb @@ -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) diff --git a/lib/typed/compiler/name_expression.rb b/lib/typed/compiler/name_expression.rb index fecfad6f..bd4ea197 100644 --- a/lib/typed/compiler/name_expression.rb +++ b/lib/typed/compiler/name_expression.rb @@ -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 ) diff --git a/test/typed/expressions/helper.rb b/test/typed/expressions/helper.rb index 67de4f1d..22152ce0 100644 --- a/test/typed/expressions/helper.rb +++ b/test/typed/expressions/helper.rb @@ -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 diff --git a/test/typed/expressions/test_all.rb b/test/typed/expressions/test_all.rb index 1c8dda15..6b2411ac 100644 --- a/test/typed/expressions/test_all.rb +++ b/test/typed/expressions/test_all.rb @@ -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" diff --git a/test/typed/expressions/test_call.rb b/test/typed/expressions/test_call.rb index c13634c1..45b908e7 100644 --- a/test/typed/expressions/test_call.rb +++ b/test/typed/expressions/test_call.rb @@ -6,7 +6,6 @@ module Register def setup Register.machine.boot - @root = :call_site @output = Register::RegisterValue end diff --git a/test/typed/expressions/test_field_access.rb b/test/typed/expressions/test_field_access.rb index 8ba3be86..f612d041 100644 --- a/test/typed/expressions/test_field_access.rb +++ b/test/typed/expressions/test_field_access.rb @@ -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 = <