class Emfrp::AllocTable

Public Class Methods

new(top) click to toggle source
# File lib/emfrp/compile/c/alloc.rb, line 107
def initialize(top)
  @top = top
  @tbl = {}
  @type_tbl = {}
end

Public Instance Methods

exp_alloc(exp) click to toggle source
# File lib/emfrp/compile/c/alloc.rb, line 140
def exp_alloc(exp)
  return @tbl[exp] if @tbl[exp]
  case exp
  when MatchExp
    @tbl[exp] = exp[:cases].map{|c| exp_alloc(c[:exp])}.inject(&:|) & exp_alloc(exp[:exp])
  when FuncCall
    args_alloc = exp[:args].map{|x| exp_alloc(x)}.inject(&:&)
    key = ([exp] + exp[:args]).map{|x| x[:typing].to_uniq_str} + [exp[:name][:desc]]
    if @top[:dict][:ifunc_space][key]
      f = @top[:dict][:ifunc_space][key].get
      @tbl[exp] = args_alloc & exp_alloc(f[:exp])
    elsif f = @top[:dict][:func_space][exp[:name][:desc]]
      if f.get.is_a?(PrimFuncDef)
        @tbl[exp] = args_alloc
      else
        raise "Assertion error"
      end
    else
      raise "Assertion error"
    end
  when ValueConst
    args_alloc = exp[:args].map{|x| exp_alloc(x)}.inject(Alloc.empty, &:&)
    key = exp[:typing].to_uniq_str
    raise "Assertion error" unless @top[:dict][:itype_space][key]
    type_def = @top[:dict][:itype_space][key].get
    @tbl[exp] = args_alloc & Alloc.one(Link.new(type_def))
  when Syntax
    @tbl[exp] = Alloc.empty
  else
    raise "Assertion error"
  end
end
type_alloc(type_def) click to toggle source
# File lib/emfrp/compile/c/alloc.rb, line 123
def type_alloc(type_def)
  return @type_tbl[type_def] if @type_tbl[type_def]
  case type_def
  when TypeDef
    tvalue_type_max_allocs = type_def[:tvalues].map do |tval|
      param_type_max_allocs = tval[:params].map do |param|
        type_alloc(utype_to_type_def(param[:typing]))
      end
      param_type_max_allocs.inject(Alloc.empty, &:&)
    end
    self_type_alloc = type_def[:static] ? Alloc.empty : Alloc.one(Link.new(type_def))
    @type_tbl[type_def] = tvalue_type_max_allocs.inject(&:|) & self_type_alloc
  when PrimTypeDef
    @type_tbl[type_def] = Alloc.empty
  end
end
utype_to_type_def(utype) click to toggle source
# File lib/emfrp/compile/c/alloc.rb, line 113
def utype_to_type_def(utype)
  if t = @top[:dict][:itype_space][utype.to_uniq_str]
    t.get
  elsif t = @top[:dict][:type_space][utype.typename]
    t.get
  else
    raise "Assertion error"
  end
end