some class send test changes

also ivar, which is still wip
This commit is contained in:
Torsten Rüger 2019-09-18 22:07:58 +03:00
parent 38491d120b
commit 41617519d9
10 changed files with 79 additions and 83 deletions

View File

@ -59,8 +59,8 @@ module Mom
end
def self.compiler_for( clazz_name , method_name , arguments , locals = {})
frame = Parfait::NamedList.type_for( locals )
args = Parfait::NamedList.type_for( arguments )
frame = Parfait::Type.for_hash( locals )
args = Parfait::Type.for_hash( arguments )
MethodCompiler.compiler_for_class(clazz_name , method_name , args, frame )
end

View File

@ -40,5 +40,4 @@ require_relative "parfait/dictionary"
require_relative "parfait/type"
require_relative "parfait/cache_entry"
require_relative "parfait/message"
require_relative "parfait/named_list"
require_relative "parfait/space"

View File

@ -4,15 +4,12 @@
# A Class in general can be viewed as a way to generate methods for a group of objects.
# A MetaClass serves the same function, but just for one object, the class object that
# A MetaClass serves the same function, but just for one object, the class object that it
# is the meta_class of.
# This is slightnly different in the way that the type of the class must actually
# This is slightly different in the way that the type of the class must actually
# change, whereas for a class the instance type changes and only objects generated
# henceafter have a different type.
# This is still a first version, this change is not implemeted, also classes at boot don't
# have metaclasses yet, so still a bit TODO
# Another current difference is that a metaclass has no superclass. Also no name.
# There is a one to one relationship between a class instance and it's meta_class instance.

View File

@ -1,44 +1 @@
require_relative "../helper"
module Vool
# relies on @ins and receiver_type method
module ClassHarness
include VoolCompile
def setup
@compiler = compile_main( send_method , "Object.get" )
@ins = @compiler.mom_instructions.next
end
def test_first_not_array
assert Array != @ins.class , @ins
end
def test_class_compiles
assert_equal Mom::MessageSetup , @ins.class , @ins
end
def test_two_instructions_are_returned
assert_equal 8 , @ins.length , @ins
end
def test_receiver_move_class
assert_equal Mom::ArgumentTransfer, @ins.next(1).class
end
def test_receiver_move
assert_equal Mom::SlotDefinition, @ins.next.receiver.class
end
def test_receiver
assert_equal Parfait::Class, @ins.next.receiver.known_object.class
end
def test_call_is
assert_equal Mom::SimpleCall, @ins.next(2).class
end
def test_call_has_method
assert_equal Parfait::CallableMethod, @ins.next(2).method.class
end
def test_array
check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,
ReturnJump,Label, ReturnSequence , Label] , @ins
end
end
end

View File

@ -3,6 +3,8 @@ require_relative "helper"
module Vool
class TestClassDef < MiniTest::Test
include Mom
include VoolCompile
def class_main
<<-eos
class Space
@ -21,11 +23,14 @@ module Vool
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_any
assert_equal Mom::MessageSetup , @ins.class
end
def test_no_arg
assert_equal Mom::ArgumentTransfer, @ins.next(1).class
assert_equal 0, @ins.next(1).arguments.length

View File

@ -0,0 +1,41 @@
require_relative "helper"
module Vool
class TestClassInstance < MiniTest::Test
include Mom
include VoolCompile
def class_main
<<-eos
class Space
def self.some_inst
return @inst
end
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==:some_inst}.mom_instructions.next
end
def test_array
check_array [SlotLoad, ReturnJump, Label, ReturnSequence, Label] , @ins
end
def test_load_inst
assert_equal SlotLoad, @ins.class
end
def test_left
assert_equal SlotDefinition , @ins.left.class
assert_equal [:return_value] , @ins.left.slots
end
def test_right
assert_equal SlotDefinition , @ins.right.class
assert_equal [:receiver , :inst] , @ins.right.slots
end
end
end

View File

@ -1,12 +0,0 @@
require_relative "helper"
module Vool
class ClassSendHarness < MiniTest::Test
include ClassHarness
def send_method
"Object.get_internal_word(0)"
end
end
end

View File

@ -2,27 +2,41 @@ require_relative "helper"
module Vool
class TestSendClassMom < MiniTest::Test
include ClassHarness
include VoolCompile
def send_method
"Object.get_internal_word(0)"
def setup
@compiler = compile_main( "Object.get_internal_word(0)" , "Object.get" )
@ins = @compiler.mom_instructions.next
end
def test_array
check_array [MessageSetup,ArgumentTransfer,SimpleCall,SlotLoad,
ReturnJump,Label, ReturnSequence , Label] , @ins
end
def test_class_compiles
assert_equal MessageSetup , @ins.class , @ins
end
def test_receiver
assert_equal SlotDefinition, @ins.next.receiver.class
assert_equal Parfait::Class, @ins.next.receiver.known_object.class
assert_equal :Object , @ins.next.receiver.known_object.name
end
def test_receiver_move
assert_equal SlotDefinition, @ins.next.receiver.class
end
def test_receiver
assert_equal Parfait::Class, @ins.next.receiver.known_object.class
end
def test_arg_one
assert_equal SlotLoad, @ins.next(1).arguments[0].class
end
def test_call_two
def test_receiver_move_class
assert_equal ArgumentTransfer, @ins.next(1).class
end
def test_call_is
assert_equal SimpleCall, @ins.next(2).class
end
def test_call_has_method
assert_equal Parfait::CallableMethod, @ins.next(2).method.class
end
def test_call_has_right_method
assert_equal :get_internal_word, @ins.next(2).method.name
end
def test_call_has_right_receiver

View File

@ -64,7 +64,7 @@ module Vool
check_type_for("return @a.call()")
end
end
class TestClassStatementCompile# < MiniTest::Test
class TestClassStatementCompile < MiniTest::Test
include VoolCompile
def setup
@ -74,7 +74,7 @@ module Vool
def test_label
assert_equal Label , @ins.class , @ins
assert_equal "Test_Type.main" , @ins.name , @ins
assert_equal "Space_Type.main" , @ins.name , @ins
end
def test_condition_compiles_to_check
assert_equal TruthCheck , @ins.next.class , @ins

View File

@ -9,16 +9,13 @@ module Vool
@ins = @compiler.mom_instructions.next
end
def test_compiles_not_array
assert Array != @stats.class , @stats
def test_array
check_array [SlotLoad, SlotLoad, ReturnJump, Label, ReturnSequence ,
Label] , @ins
end
def test_class_compiles
assert_equal Mom::SlotLoad , @ins.class , @ins
end
def test_slot_is_set
assert_equal SlotLoad , @ins.class , @ins
assert @ins.left
end
def test_slot_starts_at_message
assert_equal :message , @ins.left.known_object
end
def test_slot_gets_self
@ -29,8 +26,6 @@ module Vool
end
def test_slot_assigns_something
assert @ins.right
end
def test_slot_assigns_int
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
end
end