more class test and misc
This commit is contained in:
parent
113ba8607c
commit
3b7248df4e
@ -44,6 +44,9 @@ module Parfait
|
|||||||
def inspect
|
def inspect
|
||||||
"Class(#{name})"
|
"Class(#{name})"
|
||||||
end
|
end
|
||||||
|
def to_s
|
||||||
|
inspect
|
||||||
|
end
|
||||||
|
|
||||||
def add_method_for(name , type , frame , body )
|
def add_method_for(name , type , frame , body )
|
||||||
method = Parfait::VoolMethod.new(name , type , frame , body )
|
method = Parfait::VoolMethod.new(name , type , frame , body )
|
||||||
|
@ -29,7 +29,6 @@ module Parfait
|
|||||||
def initialize( clazz )
|
def initialize( clazz )
|
||||||
super()
|
super()
|
||||||
@clazz = clazz
|
@clazz = clazz
|
||||||
@instance_methods = List.new
|
|
||||||
@instance_type = Object.object_space.get_type_by_class_name(:Object)
|
@instance_type = Object.object_space.get_type_by_class_name(:Object)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -41,6 +40,9 @@ module Parfait
|
|||||||
"MetaClass(#{@clazz.name})"
|
"MetaClass(#{@clazz.name})"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
inspect
|
||||||
|
end
|
||||||
def add_method_for(name , type , frame , body )
|
def add_method_for(name , type , frame , body )
|
||||||
method = Parfait::VoolMethod.new(name , type , frame , body )
|
method = Parfait::VoolMethod.new(name , type , frame , body )
|
||||||
add_method( method )
|
add_method( method )
|
||||||
|
@ -127,7 +127,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
method.set_next( @methods )
|
method.set_next( @methods )
|
||||||
@methods = method
|
@methods = method
|
||||||
#puts "#{self.name} add #{method.name}"
|
# puts "ADD method to #{self.inspect}:#{method.name}"
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -167,9 +167,9 @@ module Parfait
|
|||||||
def resolve_method( fname )
|
def resolve_method( fname )
|
||||||
method = get_method(fname)
|
method = get_method(fname)
|
||||||
return method if method
|
return method if method
|
||||||
|
return nil if object_class.name == :Object
|
||||||
sup = object_class.super_class
|
sup = object_class.super_class
|
||||||
return nil unless sup
|
return nil unless sup
|
||||||
return nil if object_class.name == :Object
|
|
||||||
sup.instance_type.resolve_method(fname)
|
sup.instance_type.resolve_method(fname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ module Vool
|
|||||||
raise "not meta" unless clazz.class == Parfait::MetaClass
|
raise "not meta" unless clazz.class == Parfait::MetaClass
|
||||||
raise( "no class in #{self}") unless clazz
|
raise( "no class in #{self}") unless clazz
|
||||||
method = clazz.add_method_for(name , make_arg_type , make_frame , body )
|
method = clazz.add_method_for(name , make_arg_type , make_frame , body )
|
||||||
|
#puts "CLass method Class:#{clazz}:#{name}"
|
||||||
compiler = method.compiler_for(clazz.instance_type)
|
compiler = method.compiler_for(clazz.instance_type)
|
||||||
each {|node| raise "Blocks not implemented" if node.is_a?(LambdaExpression)}
|
each {|node| raise "Blocks not implemented" if node.is_a?(LambdaExpression)}
|
||||||
compiler
|
compiler
|
||||||
|
46
test/vool/class_send/test_class_send_inherited.rb
Normal file
46
test/vool/class_send/test_class_send_inherited.rb
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Vool
|
||||||
|
class TestClassSendInherited < MiniTest::Test
|
||||||
|
include Mom
|
||||||
|
include VoolCompile
|
||||||
|
|
||||||
|
def class_main
|
||||||
|
<<-eos
|
||||||
|
class Object
|
||||||
|
def self.one_plus()
|
||||||
|
return 1 + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class Space
|
||||||
|
def main(arg)
|
||||||
|
return Space.one_plus
|
||||||
|
end
|
||||||
|
end
|
||||||
|
eos
|
||||||
|
end
|
||||||
|
|
||||||
|
def setup
|
||||||
|
source = "class Integer;def +(other);X.int_operator(:+);end;end;" + class_main
|
||||||
|
ret = RubyX::RubyXCompiler.new(RubyX.default_test_options).ruby_to_mom(source)
|
||||||
|
@ins = ret.compilers.find{|c|c.callable.name==:main}.mom_instructions.next
|
||||||
|
end
|
||||||
|
def test_array
|
||||||
|
check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,
|
||||||
|
ReturnJump,Label, ReturnSequence , Label] , @ins
|
||||||
|
end
|
||||||
|
def test_receiver
|
||||||
|
assert_equal Mom::ArgumentTransfer, @ins.next(1).class
|
||||||
|
assert_equal 0, @ins.next(1).arguments.length
|
||||||
|
assert_equal SlotDefinition, @ins.next(1).receiver.class
|
||||||
|
assert_equal Parfait::Class, @ins.next(1).receiver.known_object.class
|
||||||
|
assert_equal :Space, @ins.next(1).receiver.known_object.name
|
||||||
|
end
|
||||||
|
def test_call
|
||||||
|
assert_equal SimpleCall, @ins.next(2).class
|
||||||
|
assert_equal :one_plus, @ins.next(2).method.name
|
||||||
|
assert_equal Parfait::Type, @ins.next(2).method.self_type.class
|
||||||
|
assert_equal :Object, @ins.next(2).method.self_type.object_class.name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user