deploy_type(id, elems)
click to toggle source
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()
click to toggle source
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)
click to toggle source
def get_container_elem_types(id)
@type_params.internal_hash[id]
end
get_local(idx)
click to toggle source
def get_local(idx)
@locals[idx]
end
inspect()
click to toggle source
def inspect
"Env[#{ @static_env.inspect }, locals:#{ @locals.inspect }, stack:#{ @stack.inspect }, type_params:#{ (@type_params&.internal_hash).inspect }]"
end
local_update(idx, ty)
click to toggle source
def local_update(idx, ty)
Env.new(@static_env, Utils.array_update(@locals, idx, ty), @stack, @type_params)
end
merge(other)
click to toggle source
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)
click to toggle source
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)
click to toggle source
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)
click to toggle source
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 "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)
click to toggle source
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)
click to toggle source
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)
click to toggle source
def setn(i, ty)
stack = Utils.array_update(@stack, -i, ty)
Env.new(@static_env, @locals, stack, @type_params)
end
topn(i)
click to toggle source
def topn(i)
push(@stack[-i - 1])
end