delegate resolve to compiler when needed

and forgotten space test
This commit is contained in:
Torsten Ruger 2018-07-13 21:55:27 +03:00
parent a095515b0e
commit 21009b0e9b
2 changed files with 14 additions and 11 deletions

View File

@ -180,17 +180,13 @@ module Risc
object = object.type if object.is_a?(RegisterValue) object = object.type if object.is_a?(RegisterValue)
case object case object
when :name when :name
type = Parfait.object_space.get_class_by_name( :Word ).instance_type type = Parfait.object_space.get_type_by_class_name( :Word )
when :frame when :frame , :arguments , :receiver
type = compiler.method.frame_type type = compiler.resolve_type(object)
when :message , :next_message , :caller when :message , :next_message , :caller
type = Parfait.object_space.get_class_by_name(:Message).instance_type type = Parfait.object_space.get_type_by_class_name(:Message)
when :arguments
type = compiler.method.arguments_type
when :receiver
type = compiler.method.self_type
when Parfait::Object when Parfait::Object
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type type = Parfait.object_space.get_type_by_class_name( object.class.name.split("::").last.to_sym)
when Symbol when Symbol
object = object.to_s.camelise.to_sym object = object.to_s.camelise.to_sym
clazz = Parfait.object_space.get_class_by_name(object) clazz = Parfait.object_space.get_class_by_name(object)
@ -211,6 +207,7 @@ module Risc
return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RegisterValue) return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RegisterValue)
type = compiler.resolve_type( object) if compiler type = compiler.resolve_type( object) if compiler
type = resolve_type(object , compiler) unless type type = resolve_type(object , compiler) unless type
#puts "TYPE #{type} obj:#{object} var:#{variable_name} comp:#{compiler}"
index = type.variable_index(variable_name) index = type.variable_index(variable_name)
raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index
return index return index

View File

@ -22,6 +22,12 @@ module Parfait
assert_equal Parfait::Space , Parfait.object_space.class assert_equal Parfait::Space , Parfait.object_space.class
end end
def test_get_class_by_name
assert_equal Parfait::Class , Parfait.object_space.get_class_by_name(:Space).class
end
def test_get_type_by_class_name
assert_equal Parfait::Type , Parfait.object_space.get_type_by_class_name(:Space).class
end
def test_get_integer_instance def test_get_integer_instance
int = @space.get_integer int = @space.get_integer
assert_equal Integer , int.class assert_equal Integer , int.class
@ -169,7 +175,7 @@ module Parfait
end end
end end
end end
class TestMethods < ParfaitTest class TestMethods #< ParfaitTest
def setup def setup
super super
Risc::Builtin.boot_functions Risc::Builtin.boot_functions
@ -179,7 +185,7 @@ module Parfait
assert_equal 14, int.instance_type.method_names.get_length assert_equal 14, int.instance_type.method_names.get_length
end end
def test_methods_booted def test_methods_booted
word = @space.get_class_by_name(:Word).instance_type word = @space.get_type_by_class_name(:Word)
assert_equal 3 , word.method_names.get_length assert_equal 3 , word.method_names.get_length
assert word.get_method(:putstring) , "no putstring" assert word.get_method(:putstring) , "no putstring"
end end