Class: Emfrp::AllocTable
- Inherits:
-
Object
- Object
- Emfrp::AllocTable
- Defined in:
- lib/emfrp/compile/c/alloc.rb
Instance Method Summary collapse
- #exp_alloc(exp) ⇒ Object
-
#initialize(top) ⇒ AllocTable
constructor
A new instance of AllocTable.
- #type_alloc(type_def) ⇒ Object
- #utype_to_type_def(utype) ⇒ Object
Constructor Details
#initialize(top) ⇒ AllocTable
Returns a new instance of AllocTable.
107 108 109 110 111 |
# File 'lib/emfrp/compile/c/alloc.rb', line 107 def initialize(top) @top = top @tbl = {} @type_tbl = {} end |
Instance Method Details
#exp_alloc(exp) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# 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) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# 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) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# 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 |