class TypeProf::Type::Cell

The most basic container type for default type parameter class

Attributes

base_type[R]
elems[R]

Public Class Methods

new(elems, base_type) click to toggle source
# File typeprof-0.21.2/lib/typeprof/container-type.rb, line 58
def initialize(elems, base_type)
  raise if !elems.is_a?(Cell::Elements)
  @elems = elems # Cell::Elements
  raise unless base_type
  @base_type = base_type
  if base_type.klass.type_params.size != elems.elems.size
    raise
  end
end

Public Instance Methods

generate_substitution() click to toggle source
# File typeprof-0.21.2/lib/typeprof/container-type.rb, line 106
def generate_substitution
  subst = {}
  tyvars = @base_type.klass.type_params.map {|name,| Type::Var.new(name) }
  tyvars.zip(@elems.elems) do |tyvar, elem|
    if subst[tyvar]
      subst[tyvar] = subst[tyvar].union(elem)
    else
      subst[tyvar] = elem
    end
  end
  subst
end
inspect() click to toggle source
# File typeprof-0.21.2/lib/typeprof/container-type.rb, line 70
def inspect
  "Type::Cell[#{ @elems.inspect }, base_type: #{ @base_type.inspect }]"
end
limit_size(limit) click to toggle source
# File typeprof-0.21.2/lib/typeprof/container-type.rb, line 91
def limit_size(limit)
  return Type.any if limit <= 0
  Cell.new(@elems.limit_size(limit - 1), @base_type)
end
localize(env, alloc_site, depth) click to toggle source
# File typeprof-0.21.2/lib/typeprof/container-type.rb, line 82
def localize(env, alloc_site, depth)
  return env, Type.any if depth <= 0
  alloc_site = alloc_site.add_id(:cell).add_id(@base_type)
  env, elems = @elems.localize(env, alloc_site, depth)
  ty = Local.new(Cell, alloc_site, @base_type)
  env = env.deploy_type(alloc_site, elems)
  return env, ty
end
method_dispatch_info() click to toggle source
# File typeprof-0.21.2/lib/typeprof/container-type.rb, line 96
def method_dispatch_info
  raise
end
screen_name(scratch) click to toggle source
# File typeprof-0.21.2/lib/typeprof/container-type.rb, line 74
def screen_name(scratch)
  str = @elems.screen_name(scratch)
  if str.start_with?("*")
    str = @base_type.screen_name(scratch) + str[1..]
  end
  str
end
substitute(subst, depth) click to toggle source
# File typeprof-0.21.2/lib/typeprof/container-type.rb, line 100
def substitute(subst, depth)
  return Type.any if depth <= 0
  elems = @elems.substitute(subst, depth)
  Cell.new(elems, @base_type)
end