From 695ae5ad99ad284c84c254fb98b7e764b6a1aa0c Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 8 Apr 2018 00:39:35 +0300 Subject: [PATCH] add label generation to builder --- lib/risc/builder.rb | 5 ++++- lib/risc/builtin/word.rb | 8 ++------ test/risc/test_builder.rb | 10 ++++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index 452f42b3..4d3c69c3 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -20,12 +20,15 @@ module Risc return @names[name] if @names.has_key?(name) if name == :message reg = Risc.message_reg + reg.builder = self + elsif name.to_s.index("label") + reg = Risc.label( name.to_s , "#{name}_#{object_id}") else type = Risc.resolve_type(name , @compiler) #checking reg = @compiler.use_reg( type.object_class.name ) + reg.builder = self end @names[name] = reg - reg.builder = self reg end diff --git a/lib/risc/builtin/word.rb b/lib/risc/builtin/word.rb index 993a8502..263c43d2 100644 --- a/lib/risc/builtin/word.rb +++ b/lib/risc/builtin/word.rb @@ -58,10 +58,6 @@ module Risc compiler = compiler_for(:Word, :resolve_method , {:value => :Type} ) source = "resolve_method " - while_start = Risc.label( source , source + "while_start_#{object_id}") - exit_label = Risc.label( source , source + "exit_label_#{object_id}") - false_label = Risc.label( source , source + "fal_label_#{object_id}") - compiler.build do word << message[ :receiver ] @@ -69,7 +65,7 @@ module Risc type << type[2] type << type[:type] typed_method << type[:methods] - add while_start + add while_start_label space << Parfait.object_space space << space[:nil_object] @@ -87,7 +83,7 @@ module Risc add false_label typed_method << typed_method[:next_method] - add Risc::Branch.new(source + "back to while", while_start) + add Risc::Branch.new(source + "back to while", while_start_label) add exit_label end diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index 53b549d7..a9881460 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -64,5 +64,15 @@ module Risc assert_equal RegToSlot , built.class assert_equal :r0 , built.array.symbol end + def test_label + label = @builder.exit_label + assert_equal Label , label.class + assert label.name.index("exit") + end + def test_two_label + label1 = @builder.exit_label + label2 = @builder.exit_label + assert_equal label1 , label2 + end end end