Introduce singleton types
Just for future, as this gives us a way to know immediately in the type, which represent normal, and which singleton classes Also instantiate singleton class lazily (with singleton type) This makes the type of class single, ie unique, immediately when it is used, ie methods or variables defined. Fixes a design mistake, where all singletonn classes shared the same type, and thus unique methods per class were impossible (Also some misc in commit)
This commit is contained in:
@ -40,7 +40,7 @@ module Vool
|
||||
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 :Class, @ins.next(2).method.self_type.object_class.name
|
||||
assert_equal :"Space.Single", @ins.next(2).method.self_type.object_class.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,9 +4,25 @@ module Vool
|
||||
class TestSendClassMom < MiniTest::Test
|
||||
include VoolCompile
|
||||
|
||||
def class_main
|
||||
<<-eos
|
||||
class Space
|
||||
def self.one_plus(one)
|
||||
return 1 + 1
|
||||
end
|
||||
end
|
||||
class Space
|
||||
def main(arg)
|
||||
return Space.one_plus(1)
|
||||
end
|
||||
end
|
||||
eos
|
||||
end
|
||||
|
||||
def setup
|
||||
@compiler = compile_main( "Object.get_internal_word(0)" , "Object.get" )
|
||||
@ins = @compiler.mom_instructions.next
|
||||
source = "class Integer < Data4;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_compiler_name(:main).mom_instructions.next
|
||||
end
|
||||
|
||||
def test_array
|
||||
@ -37,10 +53,10 @@ module Vool
|
||||
def test_call_is
|
||||
assert_equal SimpleCall, @ins.next(2).class
|
||||
assert_equal Parfait::CallableMethod, @ins.next(2).method.class
|
||||
assert_equal :get_internal_word, @ins.next(2).method.name
|
||||
assert_equal :one_plus, @ins.next(2).method.name
|
||||
end
|
||||
def test_call_has_right_receiver
|
||||
assert_equal "Class_Type", @ins.next(2).method.self_type.name
|
||||
assert_equal "Space.Single_Type", @ins.next(2).method.self_type.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Vool
|
||||
include VoolCompile
|
||||
|
||||
def class_code
|
||||
"class Space;def self.meth;return 1 ; end;end"
|
||||
"class Space;def self.meth; return meth(22 + 22) ; end;end"
|
||||
end
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
@ -33,5 +33,16 @@ module Vool
|
||||
m = clazz.single_class.instance_type.get_method(:meth)
|
||||
assert m , "no type method :meth"
|
||||
end
|
||||
def as_mom
|
||||
@clazz.to_parfait
|
||||
@clazz.to_mom(nil)
|
||||
end
|
||||
def test_mom
|
||||
assert_equal :meth , as_mom.method_compilers.callable.name
|
||||
end
|
||||
def test_mom_frame
|
||||
callable = as_mom.method_compilers.callable
|
||||
assert callable.frame_type.names.last.to_s.start_with?("tmp_") , "no tmp_ variable #{callable.frame_type.names}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user