Class: CGenerator::Library::RbDefineAllocAccumulator

Inherits:
Accumulator
  • Object
show all
Defined in:
lib/cgen/cgen.rb

Instance Attribute Summary

Attributes inherited from Accumulator

#name, #parent

Instance Method Summary collapse

Methods inherited from Accumulator

#accept?, #add_one, #add_one_really, #initialize, #inspect, #inspect_one, #output, #output_one, #separator

Constructor Details

This class inherits a constructor from CGenerator::Accumulator

Instance Method Details

#add(spec) ⇒ Object



1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
# File 'lib/cgen/cgen.rb', line 1115

def add spec
  klass = spec[:class]
  cfile = spec[:cfile]
  
  if @pile.find {|s| s[:class] == klass}
    raise ArgumentError, "Duplicate alloc func definition for #{klass}"
  end

  klass_c_name =
    spec[:class_c_name] ||= @parent.declare_class(klass, cfile) ## @parent ?
  spec[:c_name] ||= "alloc_func_#{klass_c_name}".intern
  @pile << spec
  
  spec[:c_name]
end

#to_sObject



1131
1132
1133
1134
1135
1136
1137
# File 'lib/cgen/cgen.rb', line 1131

def to_s
  @pile.collect { |spec|
    c_name        = spec[:c_name]
    klass_c_name  = spec[:class_c_name]
    "rb_define_alloc_func(#{klass_c_name}, #{c_name});"
  }.join "\n"
end