135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 135
def constructor_gen(ct)
return if enum?(ct)
self[:tvalues].each_with_index do |tvalue, i|
params = tvalue[:params].each_with_index.map do |param, i|
[ct.tref(param), "member#{i}"]
end
ct.define_func(ref_name(ct), tvalue.constructor_name(ct), params) do |s|
while_stmts = []
while_stmts << "#{memory_counter_name(ct)}++;"
while_stmts << "#{memory_counter_name(ct)} %= #{memory_size_name(ct)};"
mn = "#{memory_name(ct)}[#{memory_counter_name(ct)}].mark"
while_stmts << "if (#{mn} < Counter) { x = #{memory_name(ct)} + #{memory_counter_name(ct)}; break; }"
s << "#{ref_name(ct)} x;"
s << ct.make_block("while (1) {", while_stmts, "}")
s << "x->mark = 0;"
s << "x->tvalue_id = #{i};" if self[:tvalues].length > 1
tvalue[:params].each_with_index do |param, i|
s << "x->value.#{tvalue.struct_name(ct)}.member#{i} = member#{i};"
end
s << "return x;"
end
end
end
|