diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index 448bd5ff..80a467a8 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -50,13 +50,20 @@ module Risc # infer the type from a symbol. In the simplest case the sybbol is the class name # But in building sometimes variations are needed, so next_message or caller work # too (and return Message) + # A general "_reg" or "_obj" at the end of the name will be removed # An error is raised if the symbol/object can not be inferred def infer_type( name ) - name = :word if name == :name - name = :message if name == :next_message - name = :message if name == :caller - name = :named_list if name == :arguments - sym = name.to_s.camelise.to_sym + as_string = name.to_s + parts = as_string.split("_") + if(parts.last == "reg" or parts.last == "obj") + parts.pop + as_string = parts.join("_") + end + as_string = "word" if as_string == "name" + as_string = "message" if as_string == "next_message" + as_string = "message" if as_string == "caller" + as_string = "named_list" if as_string == "arguments" + sym = as_string.camelise.to_sym clazz = Parfait.object_space.get_class_by_name(sym) raise "Not implemented/found object #{name}:#{sym}" unless clazz return clazz.instance_type diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index f50c8f55..adc35735 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -98,20 +98,4 @@ module Risc assert_equal :Space , op.left.type.class_name end end - class TestCompilerBuilder < MiniTest::Test - - def setup - Parfait.boot! - Risc.boot! - @init = Parfait.object_space.get_init - @compiler = Risc::MethodCompiler.new( @init ) - @builder = @compiler.compiler_builder(@init) - end - def test_inserts_built - r1 = RegisterValue.new(:r1 , :Space) - @builder.build{ space << r1 } - assert_equal Transfer , @compiler.risc_instructions.next.class - end - - end end diff --git a/test/risc/test_builder1.rb b/test/risc/test_builder1.rb new file mode 100644 index 00000000..1b3aac16 --- /dev/null +++ b/test/risc/test_builder1.rb @@ -0,0 +1,20 @@ +require_relative "../helper" + +module Risc + class TestCompilerBuilder < MiniTest::Test + + def setup + Parfait.boot! + Risc.boot! + @init = Parfait.object_space.get_init + @compiler = Risc::MethodCompiler.new( @init ) + @builder = @compiler.compiler_builder(@init) + end + def test_inserts_built + r1 = RegisterValue.new(:r1 , :Space) + @builder.build{ space << r1 } + assert_equal Transfer , @compiler.risc_instructions.next.class + end + + end +end diff --git a/test/risc/test_builder2.rb b/test/risc/test_builder2.rb new file mode 100644 index 00000000..3929d4ae --- /dev/null +++ b/test/risc/test_builder2.rb @@ -0,0 +1,39 @@ +require_relative "../helper" + +module Risc + class TestBuilderInfer < MiniTest::Test + + def setup + Parfait.boot! + Risc.boot! + @init = Parfait.object_space.get_init + @compiler = Risc::MethodCompiler.new( @init ) + @builder = @compiler.compiler_builder(@init) + end + def test_list + assert_equal :List , @builder.infer_type(:list).class_name + end + def test_name + assert_equal :Word , @builder.infer_type(:name).class_name + end + def test_word + assert_equal :Word , @builder.infer_type(:word).class_name + end + def test_caller + assert_equal :Message , @builder.infer_type(:caller).class_name + end + def test_caller_reg + assert_equal :Message , @builder.infer_type(:caller_reg).class_name + end + def test_caller_obj + assert_equal :Message , @builder.infer_type(:caller_obj).class_name + end + def test_message + assert_equal :Message , @builder.infer_type(:message).class_name + end + def test_next_message + assert_equal :Message , @builder.infer_type(:next_message).class_name + end + + end +end