reuse dished out names

so they become like variables
This commit is contained in:
Torsten Ruger 2018-04-06 20:55:21 +03:00
parent 29f43eba3b
commit c02576b239
3 changed files with 14 additions and 6 deletions

View File

@ -6,15 +6,20 @@ module Risc
def initialize(compiler) def initialize(compiler)
@compiler = compiler @compiler = compiler
@names = {}
end end
def method_missing(*args) def method_missing(*args)
super if args.length != 1 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 ) reg = @compiler.use_reg( type.object_class.name )
@names[name] = reg
reg.builder = self reg.builder = self
reg reg
end end
def build(&block) def build(&block)
instance_eval(&block) instance_eval(&block)
return built return built
@ -66,8 +71,7 @@ module Risc
when Parfait::Object when Parfait::Object
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
when Symbol when Symbol
# object = object.to_s.split('_').map(&:capitalize).join.to_sym object = object.camelize
object = :Space if object == :space
clazz = Parfait.object_space.get_class_by_name(object) clazz = Parfait.object_space.get_class_by_name(object)
raise "Not implemented/found object #{object}:#{object.class}" unless clazz raise "Not implemented/found object #{object}:#{object.class}" unless clazz
type = clazz.instance_type type = clazz.instance_type

View File

@ -29,8 +29,7 @@ module Util
def last def last
code = self code = self
while( code.next ) while( code.next )
puts "code #{code.class} #{code}" raise "Circular list #{code.class}:#{code}" if code == code.next
raise "UUPS #{code.class}:#{code}" if code == code.next
code = code.next code = code.next
end end
return code return code

View File

@ -1,7 +1,7 @@
require_relative "../helper" require_relative "../helper"
module Risc module Risc
class TestBuilderBoot #< MiniTest::Test class TestBuilderBoot < MiniTest::Test
def setup def setup
Risc.machine.boot Risc.machine.boot
@ -35,6 +35,11 @@ module Risc
assert_equal SlotToReg , built.class assert_equal SlotToReg , built.class
assert_equal :r1 , built.array.symbol assert_equal :r1 , built.array.symbol
end 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 end
class TestBuilderNoBoot < MiniTest::Test class TestBuilderNoBoot < MiniTest::Test