From c02576b2391bbd4fc8a3ee517fe6f67b05eea9a9 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 6 Apr 2018 20:55:21 +0300 Subject: [PATCH] reuse dished out names so they become like variables --- lib/risc/builder.rb | 10 +++++++--- lib/util/list.rb | 3 +-- test/risc/test_builder.rb | 7 ++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index 0b08ea4c..c5479332 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -6,15 +6,20 @@ module Risc def initialize(compiler) @compiler = compiler + @names = {} end def method_missing(*args) super if args.length != 1 - type = Risc.resolve_type(args[0] , @compiler) #checking + name = args[0] + return @names[name] if @names.has_key?(name) + type = Risc.resolve_type(name , @compiler) #checking reg = @compiler.use_reg( type.object_class.name ) + @names[name] = reg reg.builder = self reg end + def build(&block) instance_eval(&block) return built @@ -66,8 +71,7 @@ module Risc when Parfait::Object type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type when Symbol -# object = object.to_s.split('_').map(&:capitalize).join.to_sym - object = :Space if object == :space + object = object.camelize clazz = Parfait.object_space.get_class_by_name(object) raise "Not implemented/found object #{object}:#{object.class}" unless clazz type = clazz.instance_type diff --git a/lib/util/list.rb b/lib/util/list.rb index 5fc6cc26..03b69a2d 100644 --- a/lib/util/list.rb +++ b/lib/util/list.rb @@ -29,8 +29,7 @@ module Util def last code = self while( code.next ) - puts "code #{code.class} #{code}" - raise "UUPS #{code.class}:#{code}" if code == code.next + raise "Circular list #{code.class}:#{code}" if code == code.next code = code.next end return code diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index de183893..86e7d046 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -1,7 +1,7 @@ require_relative "../helper" module Risc - class TestBuilderBoot #< MiniTest::Test + class TestBuilderBoot < MiniTest::Test def setup Risc.machine.boot @@ -35,6 +35,11 @@ module Risc assert_equal SlotToReg , built.class assert_equal :r1 , built.array.symbol end + def test_reuses_names + r1 = RiscValue.new(:r1 , :Space) + built = @builder.build{ space << r1 ; space << r1} + assert_equal built.to.symbol , built.next.to.symbol + end end class TestBuilderNoBoot < MiniTest::Test