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
- #locals readonly
- #stack readonly
- #static_env readonly
- #type_params readonly
Instance Method Summary
Constructor Details
.new(static_env, locals, stack, type_params) ⇒ Env
# File 'lib/typeprof/analyzer.rb', line 135
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 142
attr_reader :static_env, :locals, :stack, :type_params
#stack (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 142
attr_reader :static_env, :locals, :stack, :type_params
#static_env (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 142
attr_reader :static_env, :locals, :stack, :type_params
#type_params (readonly)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 142
attr_reader :static_env, :locals, :stack, :type_params
Instance Method Details
#deploy_type(id, elems)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 217
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 ]#get_container_elem_types(id)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 213
def get_container_elem_types(id) @type_params.internal_hash[id] end
#get_local(idx)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 205
def get_local(idx) @locals[idx] end
#inspect
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 242
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 209
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 144
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 ]#pop(n)
[ GitHub ]#push(*tys)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 176
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 ]#replace_recv_ty(ty)
[ GitHub ]#setn(i, ty)
[ GitHub ]# File 'lib/typeprof/analyzer.rb', line 196
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 201
def topn(i) push(@stack[-i - 1]) end