reuse dished out names
so they become like variables
This commit is contained in:
parent
29f43eba3b
commit
c02576b239
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user