123456789_123456789_123456789_123456789_123456789_

Class: TypeProf::Env

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/typeprof/analyzer.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(static_env, locals, stack, type_params) ⇒ Env

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 159

def initialize(static_env, locals, stack, type_params)
  @static_env = static_env
  @locals = locals
  @stack = stack
  @type_params = type_params
end

Instance Attribute Details

#locals (readonly)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 166

attr_reader :static_env, :locals, :stack, :type_params

#stack (readonly)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 166

attr_reader :static_env, :locals, :stack, :type_params

#static_env (readonly)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 166

attr_reader :static_env, :locals, :stack, :type_params

#type_params (readonly)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 166

attr_reader :static_env, :locals, :stack, :type_params

Instance Method Details

#deploy_type(id, elems)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 241

def deploy_type(id, elems)
  type_params = Utils::HashWrapper.new(@type_params.internal_hash.merge({ id => elems }))
  Env.new(@static_env, @locals, @stack, type_params)
end

#enable_module_function

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 246

def enable_module_function
  senv = StaticEnv.new(@static_env.recv_ty, @static_env.blk_ty, true, @static_env.pub_meth)
  Env.new(senv, @locals, @stack, @type_params)
end

#get_container_elem_types(id)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 237

def get_container_elem_types(id)
  @type_params.internal_hash[id]
end

#get_local(idx)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 229

def get_local(idx)
  @locals[idx]
end

#inspect

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 266

def inspect
  "Env[#{ @static_env.inspect }, locals:#{ @locals.inspect }, stack:#{ @stack.inspect }, type_params:#{ (@type_params&.internal_hash).inspect }]"
end

#local_update(idx, ty)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 233

def local_update(idx, ty)
  Env.new(@static_env, Utils.array_update(@locals, idx, ty), @stack, @type_params)
end

#merge(other)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 168

def merge(other)
  raise if @locals.size != other.locals.size
  raise if @stack.size != other.stack.size
  static_env = @static_env.merge(other.static_env)
  locals = []
  @locals.zip(other.locals) {|ty1, ty2| locals << ty1.union(ty2) }
  stack = []
  @stack.zip(other.stack) {|ty1, ty2| stack << ty1.union(ty2) }
  if @type_params
    raise if !other.type_params
    if @type_params == other.type_params
      type_params = @type_params
    else
      type_params = @type_params.internal_hash.dup
      other.type_params.internal_hash.each do |id, elems|
        elems2 = type_params[id]
        if elems2
          if elems != elems2
            type_params[id] = elems.union(elems2)
          end
        else
          type_params[id] = elems
        end
      end
      type_params = Utils::HashWrapper.new(type_params)
    end
  else
    raise if other.type_params
  end
  Env.new(static_env, locals, stack, type_params)
end

#method_public_set(flag)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 251

def method_public_set(flag)
  senv = StaticEnv.new(@static_env.recv_ty, @static_env.blk_ty, @static_env.mod_func, flag)
  Env.new(senv, @locals, @stack, @type_params)
end

#pop(n)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 213

def pop(n)
  stack = @stack.dup
  tys = stack.pop(n)
  nenv = Env.new(@static_env, @locals, stack, @type_params)
  return nenv, tys
end

#push(*tys)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 200

def push(*tys)
  tys.each do |ty|
    raise "nil cannot be pushed to the stack" if ty.nil?
    ty.each_child do |ty|
      raise if ty.is_a?(Type::Var)
      #raise if ty.is_a?(Type::Instance) && ty.klass.type_params.size > 1
      raise "Array cannot be pushed to the stack" if ty.is_a?(Type::Array)
      raise "Hash cannot be pushed to the stack" if ty.is_a?(Type::Hash)
    end
  end
  Env.new(@static_env, @locals, @stack + tys, @type_params)
end

#replace_blk_ty(ty)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 261

def replace_blk_ty(ty)
  senv = StaticEnv.new(@static_env.recv_ty, ty, @static_env.mod_func, @static_env.pub_meth)
  Env.new(senv, @locals, @stack, @type_params)
end

#replace_recv_ty(ty)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 256

def replace_recv_ty(ty)
  senv = StaticEnv.new(ty, @static_env.blk_ty, @static_env.mod_func, @static_env.pub_meth)
  Env.new(senv, @locals, @stack, @type_params)
end

#setn(i, ty)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 220

def setn(i, ty)
  stack = Utils.array_update(@stack, -i, ty)
  Env.new(@static_env, @locals, stack, @type_params)
end

#topn(i)

[ GitHub ]

  
# File 'lib/typeprof/analyzer.rb', line 225

def topn(i)
  push(@stack[-i - 1])
end