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