new get_type_by_class_name helper for space
sorely needed, with 36 occurences replaced
This commit is contained in:
parent
27a142f2a3
commit
a095515b0e
@ -69,7 +69,7 @@ module Arm
|
||||
ArmMachine.mov( :pc , code.register)
|
||||
end
|
||||
def translate_DynamicJump(code)
|
||||
index = Parfait.object_space.get_class_by_name(:CallableMethod).instance_type.variable_index(:binary)
|
||||
index = Parfait.object_space.get_type_by_class_name(:CallableMethod).variable_index(:binary)
|
||||
codes = ArmMachine.ldr( code.register , code.register , arm_index(index) )
|
||||
codes << ArmMachine.mov( :pc , code.register)
|
||||
codes
|
||||
|
@ -27,7 +27,7 @@ module Mom
|
||||
value
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:Integer)
|
||||
end
|
||||
end
|
||||
class FloatConstant < Constant
|
||||
@ -44,7 +44,7 @@ module Mom
|
||||
Parfait.object_space.true_object
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:TrueClass).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:TrueClass)
|
||||
end
|
||||
end
|
||||
class FalseConstant < Constant
|
||||
@ -52,7 +52,7 @@ module Mom
|
||||
Parfait.object_space.false_object
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:FalseClass).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:FalseClass)
|
||||
end
|
||||
end
|
||||
class NilConstant < Constant
|
||||
@ -60,7 +60,7 @@ module Mom
|
||||
Parfait.object_space.nil_object
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:NilClass).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:NilClass)
|
||||
end
|
||||
end
|
||||
class StringConstant < Constant
|
||||
@ -74,12 +74,12 @@ module Mom
|
||||
value
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:Word)
|
||||
end
|
||||
end
|
||||
class SymbolConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:Word)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -113,6 +113,11 @@ module Parfait
|
||||
object.instance_type.get_method :__init__
|
||||
end
|
||||
|
||||
# get the current instance_typ of the class with the given name
|
||||
def get_type_by_class_name(name)
|
||||
get_class_by_name(name).instance_type
|
||||
end
|
||||
|
||||
# get a class by name (symbol)
|
||||
# return nili if no such class. Use bang version if create should be implicit
|
||||
def get_class_by_name( name )
|
||||
@ -137,7 +142,7 @@ module Parfait
|
||||
raise "create_class #{name.class}" unless name.is_a? Symbol
|
||||
superclass = :Object unless superclass
|
||||
raise "create_class #{superclass.class}" unless superclass.is_a? Symbol
|
||||
type = get_class_by_name(superclass).instance_type
|
||||
type = get_type_by_class_name(superclass)
|
||||
c = Class.new(name , superclass , type )
|
||||
@classes[name] = c
|
||||
end
|
||||
|
@ -24,18 +24,18 @@ module Risc
|
||||
compilers << compiler_for( space_type , Space , :main)
|
||||
end
|
||||
|
||||
obj_type = space.get_class_by_name(:Object).instance_type
|
||||
obj_type = space.get_type_by_class_name(:Object)
|
||||
[ :get_internal_word , :set_internal_word , :_method_missing,
|
||||
:exit , :__init__].each do |f|
|
||||
compilers << compiler_for( obj_type , Object , f)
|
||||
end
|
||||
|
||||
word_type = space.get_class_by_name(:Word).instance_type
|
||||
word_type = space.get_type_by_class_name(:Word)
|
||||
[:putstring , :get_internal_byte , :set_internal_byte ].each do |f|
|
||||
compilers << compiler_for( word_type , Word , f)
|
||||
end
|
||||
|
||||
int_type = space.get_class_by_name(:Integer).instance_type
|
||||
int_type = space.get_type_by_class_name(:Integer)
|
||||
Risc.operators.each do |op|
|
||||
compilers << operator_compiler( int_type , op)
|
||||
end
|
||||
|
@ -14,7 +14,7 @@ module Vool
|
||||
return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , [])
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:Integer)
|
||||
end
|
||||
def to_s
|
||||
value.to_s
|
||||
@ -33,7 +33,7 @@ module Vool
|
||||
end
|
||||
class TrueConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:True).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:True)
|
||||
end
|
||||
def slot_definition(compiler)
|
||||
return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
|
||||
@ -44,7 +44,7 @@ module Vool
|
||||
end
|
||||
class FalseConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:False).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:False)
|
||||
end
|
||||
def slot_definition(compiler)
|
||||
return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
|
||||
@ -55,7 +55,7 @@ module Vool
|
||||
end
|
||||
class NilConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Nil).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:Nil)
|
||||
end
|
||||
def slot_definition(compiler)
|
||||
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
|
||||
@ -94,7 +94,7 @@ module Vool
|
||||
return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[])
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:Word)
|
||||
end
|
||||
def to_s(depth = 0)
|
||||
"'#{@value}'"
|
||||
@ -102,7 +102,7 @@ module Vool
|
||||
end
|
||||
class SymbolConstant < StringConstant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
Parfait.object_space.get_type_by_class_name(:Word)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ module Risc
|
||||
end
|
||||
# test hack to in place change object type
|
||||
def add_space_field(name,type)
|
||||
class_type = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
class_type = Parfait.object_space.get_type_by_class_name(:Space)
|
||||
class_type.send(:private_add_instance_variable, name , type)
|
||||
end
|
||||
def produce_body
|
||||
|
@ -8,7 +8,7 @@ module Parfait
|
||||
@space = Parfait.object_space
|
||||
end
|
||||
def make_method
|
||||
@obj = Parfait.object_space.get_class_by_name(:Object).instance_type
|
||||
@obj = Parfait.object_space.get_type_by_class_name(:Object)
|
||||
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
|
||||
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
|
||||
@method = Parfait::CallableMethod.new( @obj , :meth , @args , @frame)
|
||||
|
@ -14,15 +14,15 @@ module Parfait
|
||||
end
|
||||
def foo_method( for_class = :Try)
|
||||
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
|
||||
::Parfait::CallableMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame)
|
||||
::Parfait::CallableMethod.new( @space.get_type_by_class_name(for_class) , :foo , args,empty_frame)
|
||||
end
|
||||
def add_foo_to( clazz = :Try )
|
||||
foo = foo_method( clazz )
|
||||
assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo)
|
||||
assert_equal foo , @space.get_type_by_class_name(clazz).add_method(foo)
|
||||
foo
|
||||
end
|
||||
def object_type
|
||||
@space.get_class_by_name(:Object).instance_type
|
||||
@space.get_type_by_class_name(:Object)
|
||||
end
|
||||
def test_new_methods
|
||||
assert_equal Parfait::List , @try_type.method_names.class
|
||||
@ -59,7 +59,7 @@ module Parfait
|
||||
end
|
||||
def test_get_instance
|
||||
foo = foo_method :Object
|
||||
type = @space.get_class_by_name(:Object).instance_type
|
||||
type = @space.get_type_by_class_name(:Object)
|
||||
type.add_method(foo)
|
||||
assert_equal :foo , type.get_method(:foo).name
|
||||
end
|
||||
|
@ -36,9 +36,9 @@ module RubyX
|
||||
end
|
||||
|
||||
def test_space_type_is_unchanged_by_compile
|
||||
space1 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
space1 = Parfait.object_space.get_type_by_class_name(:Space)
|
||||
ruby_to_vool "class Space ;end"
|
||||
space2 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
space2 = Parfait.object_space.get_type_by_class_name(:Space)
|
||||
assert_equal space1 , space2
|
||||
end
|
||||
|
||||
|
@ -25,9 +25,9 @@ module RubyX
|
||||
end
|
||||
|
||||
def test_space_type_is_unchanged_by_compile
|
||||
space1 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
space1 = Parfait.object_space.get_type_by_class_name(:Space)
|
||||
ruby_to_vool "class Space ;end"
|
||||
space2 = Parfait.object_space.get_class_by_name(:Space).instance_type
|
||||
space2 = Parfait.object_space.get_type_by_class_name(:Space)
|
||||
assert_equal space1 , space2
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user