Class: Emfrp::NodeDef

Inherits:
Object
  • Object
show all
Defined in:
lib/emfrp/compile/c/syntax_codegen.rb

Instance Method Summary collapse

Instance Method Details

#func_gen(ct) ⇒ Object



249
250
251
252
253
254
255
256
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 249

def func_gen(ct)
  params = self[:params].map{|x| [ct.tref(x), ct.escape_name(x[:as][:desc])]}
  output_param = [ct.tref(self) + "*", "output"]
  ct.define_func("int", node_func_name(ct), params + [output_param]) do |x|
    x << "*output = #{self[:exp].codegen(ct, x)};"
    x << "return 1;"
  end
end

#init_func_gen(ct) ⇒ Object



258
259
260
261
262
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 258

def init_func_gen(ct)
  ct.define_func(ct.tref(self), init_func_name(ct), []) do |x|
    x << "return #{self[:init_exp].codegen(ct, x)};"
  end
end

#init_func_name(ct) ⇒ Object



268
269
270
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 268

def init_func_name(ct)
  "init_#{ct.escape_name(self[:name][:desc])}"
end

#node_func_name(ct) ⇒ Object



272
273
274
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 272

def node_func_name(ct)
  "node_#{ct.escape_name(self[:name][:desc])}"
end

#node_var_gen(ct) ⇒ Object



264
265
266
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 264

def node_var_gen(ct)
  ct.define_global_var(ct.tref(self), "#{node_var_name(ct)}[2]")
end

#node_var_name(ct) ⇒ Object



276
277
278
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 276

def node_var_name(ct)
  "node_memory_#{ct.escape_name(self[:name][:desc])}"
end

#var_name(ct, name) ⇒ Object



284
285
286
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 284

def var_name(ct, name)
  ct.escape_name(name)
end

#var_suffix(ct) ⇒ Object



280
281
282
# File 'lib/emfrp/compile/c/syntax_codegen.rb', line 280

def var_suffix(ct)
  "_nvar#{ct.serial(nil, self)}"
end