use more instances in parfait
and misc
This commit is contained in:
parent
c3c2ab606c
commit
63323376e4
@ -7,13 +7,13 @@ module Parfait
|
|||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super()
|
super()
|
||||||
instance_methods = List.new
|
@instance_methods = List.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def methods
|
def methods
|
||||||
m = instance_methods
|
m = @instance_methods
|
||||||
return m if m
|
return m if m
|
||||||
instance_methods = List.new
|
@instance_methods = List.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_names
|
def method_names
|
||||||
@ -26,12 +26,13 @@ module Parfait
|
|||||||
|
|
||||||
def add_instance_method( method )
|
def add_instance_method( method )
|
||||||
raise "not implemented #{method.class} #{method.inspect}" unless method.is_a? VoolMethod
|
raise "not implemented #{method.class} #{method.inspect}" unless method.is_a? VoolMethod
|
||||||
|
raise "HMM"
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_instance_method( method_name )
|
def remove_instance_method( method_name )
|
||||||
found = get_instance_method( method_name )
|
found = get_instance_method( method_name )
|
||||||
found ? @methods.delete(found) : false
|
found ? methods.delete(found) : false
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_instance_method( fname )
|
def get_instance_method( fname )
|
||||||
|
@ -49,17 +49,17 @@ module Parfait
|
|||||||
# determine if method has a local variable or tmp (anonymous local) by given name
|
# determine if method has a local variable or tmp (anonymous local) by given name
|
||||||
def has_local( name )
|
def has_local( name )
|
||||||
raise "has_local #{name}.#{name.class}" unless name.is_a? Symbol
|
raise "has_local #{name}.#{name.class}" unless name.is_a? Symbol
|
||||||
frame_type.variable_index( name )
|
@frame_type.variable_index( name )
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_local( name , type )
|
def add_local( name , type )
|
||||||
index = has_local( name )
|
index = has_local( name )
|
||||||
return index if index
|
return index if index
|
||||||
@frame_type = frame_type.add_instance_variable(name,type)
|
@frame_type = @frame_type.add_instance_variable(name,type)
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_binary( &block )
|
def each_binary( &block )
|
||||||
bin = binary
|
bin = @binary
|
||||||
while(bin) do
|
while(bin) do
|
||||||
block.call( bin )
|
block.call( bin )
|
||||||
bin = bin.next_code
|
bin = bin.next_code
|
||||||
|
@ -28,7 +28,7 @@ module Parfait
|
|||||||
|
|
||||||
def each_method( &block )
|
def each_method( &block )
|
||||||
block.call( self )
|
block.call( self )
|
||||||
next_callable.each_method( &block ) if next_callable
|
@next_callable.each_method( &block ) if @next_callable
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_block(args , frame)
|
def create_block(args , frame)
|
||||||
|
@ -53,16 +53,16 @@ module Parfait
|
|||||||
|
|
||||||
def add_method(method)
|
def add_method(method)
|
||||||
raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod
|
raise "Must be untyped method #{method}" unless method.is_a? Parfait::VoolMethod
|
||||||
instance_methods.push(method)
|
@instance_methods.push(method)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_method(name)
|
def get_method(name)
|
||||||
instance_methods.find{|m| m.name == name }
|
@instance_methods.find{|m| m.name == name }
|
||||||
end
|
end
|
||||||
|
|
||||||
# adding an instance changes the instance_type to include that variable
|
# adding an instance changes the instance_type to include that variable
|
||||||
def add_instance_variable( name , type)
|
def add_instance_variable( name , type)
|
||||||
@instance_type = instance_type.add_instance_variable( name , type )
|
@instance_type = @instance_type.add_instance_variable( name , type )
|
||||||
end
|
end
|
||||||
|
|
||||||
# setting the type generates all methods for this type
|
# setting the type generates all methods for this type
|
||||||
@ -76,9 +76,9 @@ module Parfait
|
|||||||
# or the super classs is nil.
|
# or the super classs is nil.
|
||||||
# Use only for non Object base class
|
# Use only for non Object base class
|
||||||
def super_class!
|
def super_class!
|
||||||
raise "No super_class for class #{name}" unless super_class_name
|
raise "No super_class for class #{@name}" unless @super_class_name
|
||||||
s = super_class
|
s = super_class
|
||||||
raise "superclass not found for class #{name} (#{super_class_name})" unless s
|
raise "superclass not found for class #{@name} (#{@super_class_name})" unless s
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -86,8 +86,8 @@ module Parfait
|
|||||||
# we only store the name, and so have to resolve.
|
# we only store the name, and so have to resolve.
|
||||||
# Nil name means no superclass, and so nil is a valid return value
|
# Nil name means no superclass, and so nil is a valid return value
|
||||||
def super_class
|
def super_class
|
||||||
return nil unless super_class_name
|
return nil unless @super_class_name
|
||||||
Parfait.object_space.get_class_by_name(super_class_name)
|
Parfait.object_space.get_class_by_name(@super_class_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# ruby 2.1 list (just for reference, keep at bottom)
|
# ruby 2.1 list (just for reference, keep at bottom)
|
||||||
|
@ -88,7 +88,7 @@ module Parfait
|
|||||||
def method_names
|
def method_names
|
||||||
names = List.new
|
names = List.new
|
||||||
return names unless @methods
|
return names unless @methods
|
||||||
methods.each_method do |method|
|
@methods.each_method do |method|
|
||||||
names.push method.name
|
names.push method.name
|
||||||
end
|
end
|
||||||
names
|
names
|
||||||
@ -118,19 +118,19 @@ module Parfait
|
|||||||
if get_method( method.name )
|
if get_method( method.name )
|
||||||
remove_method(method.name)
|
remove_method(method.name)
|
||||||
end
|
end
|
||||||
method.set_next( methods )
|
method.set_next( @methods )
|
||||||
@methods = method
|
@methods = method
|
||||||
#puts "#{self.name} add #{method.name}"
|
#puts "#{self.name} add #{method.name}"
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_method( method_name )
|
def remove_method( method_name )
|
||||||
raise "No such method #{method_name} in #{self.name}" unless methods
|
raise "No such method #{method_name} in #{self.name}" unless @methods
|
||||||
if( methods.name == method_name)
|
if( @methods.name == method_name)
|
||||||
@methods = methods.next_callable
|
@methods = @methods.next_callable
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
method = methods
|
method = @methods
|
||||||
while(method && method.next_callable)
|
while(method && method.next_callable)
|
||||||
if( method.next_callable.name == method_name)
|
if( method.next_callable.name == method_name)
|
||||||
method.set_next( method.next_callable.next_callable )
|
method.set_next( method.next_callable.next_callable )
|
||||||
@ -144,8 +144,8 @@ module Parfait
|
|||||||
|
|
||||||
def get_method( fname )
|
def get_method( fname )
|
||||||
raise "get_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
|
raise "get_method #{fname}.#{fname.class}" unless fname.is_a?(Symbol)
|
||||||
return nil unless methods
|
return nil unless @methods
|
||||||
methods.each_method do |m|
|
@methods.each_method do |m|
|
||||||
return m if(m.name == fname )
|
return m if(m.name == fname )
|
||||||
end
|
end
|
||||||
nil
|
nil
|
||||||
@ -167,9 +167,9 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def methods_length
|
def methods_length
|
||||||
return 0 unless methods
|
return 0 unless @methods
|
||||||
len = 0
|
len = 0
|
||||||
methods.each_method { len += 1}
|
@methods.each_method { len += 1}
|
||||||
return len
|
return len
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -194,29 +194,29 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def instance_length
|
def instance_length
|
||||||
names.get_length()
|
@names.get_length()
|
||||||
end
|
end
|
||||||
|
|
||||||
# index of the variable when using get_internal_word
|
# index of the variable when using get_internal_word
|
||||||
# (get_internal_word is 0 based and 0 is always the type)
|
# (get_internal_word is 0 based and 0 is always the type)
|
||||||
def variable_index( name )
|
def variable_index( name )
|
||||||
has = names.index_of(name)
|
has = @names.index_of(name)
|
||||||
return nil unless has
|
return nil unless has
|
||||||
raise "internal error #{name}:#{has}" if has < 0
|
raise "internal error #{name}:#{has}" if has < 0
|
||||||
has
|
has
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_length()
|
def get_length()
|
||||||
names.get_length()
|
@names.get_length()
|
||||||
end
|
end
|
||||||
|
|
||||||
def name_at( index )
|
def name_at( index )
|
||||||
raise "No names #{index}" unless names
|
raise "No names #{index}" unless @names
|
||||||
names.get(index)
|
@names.get(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
def type_at( index )
|
def type_at( index )
|
||||||
types.get(index)
|
@types.get(index)
|
||||||
end
|
end
|
||||||
|
|
||||||
def type_for( name )
|
def type_for( name )
|
||||||
@ -226,11 +226,11 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"Type[#{names.inspect}]"
|
"Type[#{@names.inspect}]"
|
||||||
end
|
end
|
||||||
|
|
||||||
def rxf_reference_name
|
def rxf_reference_name
|
||||||
"#{object_class.name}_Type"
|
"#{@object_class.name}_Type"
|
||||||
end
|
end
|
||||||
alias :name :rxf_reference_name
|
alias :name :rxf_reference_name
|
||||||
|
|
||||||
@ -243,9 +243,10 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def each_method(&block)
|
def each_method(&block)
|
||||||
return unless methods
|
return unless @methods
|
||||||
methods.each_method(&block)
|
@methods.each_method(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_hash
|
def to_hash
|
||||||
hash = {}
|
hash = {}
|
||||||
each do |name , type|
|
each do |name , type|
|
||||||
@ -284,8 +285,8 @@ module Parfait
|
|||||||
def private_add_instance_variable( name , type)
|
def private_add_instance_variable( name , type)
|
||||||
raise "Name shouldn't be nil" unless name
|
raise "Name shouldn't be nil" unless name
|
||||||
raise "Value Type shouldn't be nil" unless type
|
raise "Value Type shouldn't be nil" unless type
|
||||||
names.push(name)
|
@names.push(name)
|
||||||
types.push(type)
|
@types.push(type)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -27,13 +27,13 @@ module Parfait
|
|||||||
raise "Empty bod" if(@source.is_a?(Vool::Statements) and @source.empty?)
|
raise "Empty bod" if(@source.is_a?(Vool::Statements) and @source.empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_callable_method( type )
|
def create_callable_method_for( type )
|
||||||
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
|
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
|
||||||
type.create_method( @name , @args_type , @frame_type)
|
type.create_method( @name , @args_type , @frame_type)
|
||||||
end
|
end
|
||||||
|
|
||||||
def compiler_for(self_type)
|
def compiler_for(self_type)
|
||||||
callable_method = create_callable_method(self_type)
|
callable_method = create_callable_method_for(self_type)
|
||||||
compiler = Mom::MethodCompiler.new( callable_method )
|
compiler = Mom::MethodCompiler.new( callable_method )
|
||||||
head = @source.to_mom( compiler )
|
head = @source.to_mom( compiler )
|
||||||
compiler.add_code(head)
|
compiler.add_code(head)
|
||||||
|
@ -43,6 +43,10 @@ module Risc
|
|||||||
@register = register
|
@register = register
|
||||||
end
|
end
|
||||||
attr_reader :register
|
attr_reader :register
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
class_source( register.to_s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# A Dynamic yield is very much like a DynamicJump, especially in it's idea
|
# A Dynamic yield is very much like a DynamicJump, especially in it's idea
|
||||||
|
@ -37,7 +37,7 @@ module Risc
|
|||||||
ret = main_ticks(46)
|
ret = main_ticks(46)
|
||||||
assert_equal FunctionReturn , ret.class
|
assert_equal FunctionReturn , ret.class
|
||||||
assert_equal :r3 , ret.register.symbol
|
assert_equal :r3 , ret.register.symbol
|
||||||
assert_equal 40220 , @interpreter.get_register(ret.register)
|
assert_equal 23404 , @interpreter.get_register(ret.register)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module Risc
|
|||||||
|
|
||||||
def test_simple_collect
|
def test_simple_collect
|
||||||
objects = Collector.collect_space(@linker)
|
objects = Collector.collect_space(@linker)
|
||||||
assert_equal 1564 , objects.length , objects.length.to_s
|
assert_equal 564 , objects.length , objects.length.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_collect_all_types
|
def test_collect_all_types
|
||||||
@ -38,8 +38,10 @@ module Risc
|
|||||||
def test_integer_positions
|
def test_integer_positions
|
||||||
objects = Collector.collect_space(@linker)
|
objects = Collector.collect_space(@linker)
|
||||||
int = Parfait.object_space.get_next_for(:Integer)
|
int = Parfait.object_space.get_next_for(:Integer)
|
||||||
|
count = 0
|
||||||
while(int)
|
while(int)
|
||||||
assert Position.set?(int) , "INt #{int.object_id}"
|
count += 1
|
||||||
|
assert Position.set?(int) , "INT #{int.object_id.to_s(16)} , count #{count}"
|
||||||
int = int.next_integer
|
int = int.next_integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -57,7 +59,7 @@ module Risc
|
|||||||
|
|
||||||
def test_simple_collect
|
def test_simple_collect
|
||||||
objects = Collector.collect_space(@linker)
|
objects = Collector.collect_space(@linker)
|
||||||
assert_equal 1564, objects.length , objects.length.to_s
|
assert_equal 564, objects.length , objects.length.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_integer_positions
|
def test_integer_positions
|
||||||
@ -66,7 +68,7 @@ module Risc
|
|||||||
count = 0
|
count = 0
|
||||||
while(int)
|
while(int)
|
||||||
count += 1
|
count += 1
|
||||||
assert Position.set?(int) , "INT #{int.object_id} , count #{count}"
|
assert Position.set?(int) , "INT #{int.object_id.to_s(16)} , count #{count}"
|
||||||
int = int.next_integer
|
int = int.next_integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -55,12 +55,12 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_pc1
|
def test_pc1
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 40168 , @interpreter.pc
|
assert_equal 23320 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_pc2
|
def test_pc2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 40172 , @interpreter.pc
|
assert_equal 23324 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_tick2
|
def test_tick2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
|
Loading…
x
Reference in New Issue
Block a user