From d6a2ea4cfc84ea7e941a7984ff89dcf7fbbc504b Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 10 Mar 2018 19:01:38 +0530 Subject: [PATCH] fix dynamic resolve patch more like, real resolve method will have to be written and put in there --- lib/mom/statement.rb | 4 ++ lib/risc/boot.rb | 2 +- lib/risc/builtin/word.rb | 15 ++++++++ lib/vool/statements/statements.rb | 4 ++ test/parfait/test_space.rb | 2 +- .../to_mom/send/test_send_cached_simple.rb | 37 ++++++------------- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/lib/mom/statement.rb b/lib/mom/statement.rb index 421adcfe..d9c65b6a 100644 --- a/lib/mom/statement.rb +++ b/lib/mom/statement.rb @@ -18,6 +18,10 @@ module Mom flat end + def <<(o) + @statements << o + end + end end diff --git a/lib/risc/boot.rb b/lib/risc/boot.rb index 709cd61f..13824a5c 100644 --- a/lib/risc/boot.rb +++ b/lib/risc/boot.rb @@ -167,7 +167,7 @@ module Risc end obj = space.get_class_by_name(:Word) - [:putstring , :get_internal_byte , :set_internal_byte ].each do |f| + [:putstring , :get_internal_byte , :set_internal_byte , :resolve_method].each do |f| obj.instance_type.add_method Builtin::Word.send(f , nil) end diff --git a/lib/risc/builtin/word.rb b/lib/risc/builtin/word.rb index 44993a99..739c2cd6 100644 --- a/lib/risc/builtin/word.rb +++ b/lib/risc/builtin/word.rb @@ -45,6 +45,21 @@ module Risc return compiler.method end + # resolve the method name of self, on the given object + # may seem wrong way around at first sight, but we know the type of string And + # thus resolving this method happens at compile time, whereas any method on an + # unknown self (the object given) needs resolving and that is just what we are doing + # ( ie the snake bites it's tail) + # This method is just a placeholder until boot is over and the real method is + # parsed. + def resolve_method context + compiler = compiler_for(:Word, :resolve_method , {:value => :Object} ) + args = compiler.method.arguments + len = args.instance_length + raise "Compiler arg number mismatch, method=#{args} " if len != 3 + return compiler.method + end + end extend ClassMethods end diff --git a/lib/vool/statements/statements.rb b/lib/vool/statements/statements.rb index 9df88aed..b39720e3 100644 --- a/lib/vool/statements/statements.rb +++ b/lib/vool/statements/statements.rb @@ -11,6 +11,10 @@ module Vool def create_objects @statements.each{ |s| s.create_objects } end + + def <<(o) + @statements << o + end end class ScopeStatement < Statements diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index 04d6005b..0c71c6d4 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -17,7 +17,7 @@ class TestSpace < MiniTest::Test def test_methods_booted word = @space.get_class_by_name(:Word).instance_type - assert_equal 3 , word.method_names.get_length + assert_equal 4 , word.method_names.get_length assert word.get_method(:putstring) , "no putstring" end diff --git a/test/vool/to_mom/send/test_send_cached_simple.rb b/test/vool/to_mom/send/test_send_cached_simple.rb index 5865dcf1..bc68cc3a 100644 --- a/test/vool/to_mom/send/test_send_cached_simple.rb +++ b/test/vool/to_mom/send/test_send_cached_simple.rb @@ -23,14 +23,20 @@ module Vool assert_equal Mom::NotSameCheck , @first.condition.class , @first end def test_if_true_moves_type - assert_equal @first.if_true[0].class, Mom::SlotMove , @first.to_rxf + assert_equal @first.if_true[0].class, Mom::SlotMove , @first.if_true.to_rxf end - def test_if_true_resolves - assert_equal @first.if_true[1] , 2, @first.if_true.to_rxf + def test_if_true_resolves_setup + assert_equal @first.if_true[1].class , Mom::MessageSetup, @first.if_true.to_rxf + end + def test_if_true_resolves_transfer + assert_equal @first.if_true[2].class , Mom::ArgumentTransfer, @first.if_true.to_rxf + end + def test_if_true_resolves_call + assert_equal @first.if_true[3].class , Mom::SimpleCall, @first.if_true.to_rxf + end + def test_if_true_resolves_move + assert_equal @first.if_true[4].class , Mom::SlotMove, @first.if_true.to_rxf end - - - def test_setup_second assert_equal Mom::MessageSetup , @second.class , @second.to_rxf @@ -44,24 +50,5 @@ module Vool assert_equal Mom::DynamicCall , @fourth.class , @fourth.to_rxf end - def est_receiver_move_class - assert_equal Mom::SlotConstant, @first.class - end - def est_receiver_move - assert_equal :receiver, @first.left[2] - end - def est_receiver - assert_equal IntegerStatement, @first.right.class - assert_equal 5, @stats.first.right.value - end - def est_call_is - assert_equal Mom::SimpleCall, @stats[1].class - end - def est_call_has_method - assert_equal Parfait::TypedMethod, @stats[1].method.class - end - def est_call_has_right_method - assert_equal :mod4, @stats[1].method.name - end end end