Class: Function

Inherits:
ErbPP show all
Defined in:
lib/erbpp.rb

Overview


Direct Known Subclasses

Allocate, ModuleFunction, NodefFunction, Store

Constant Summary collapse

DEFS =
[]

Constants inherited from ErbPP

ErbPP::ATTRS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ErbPP

#attr_method, #attrs, #check_params, define_attrs, #has_attr?, #load_erb, #method_missing, #method_missing_alias, #parents, #result, #run, #search_method_in_parents

Constructor Details

#initialize(parent, tmpl, **opts) ⇒ Function

Returns a new instance of Function.



168
169
170
171
172
173
# File 'lib/erbpp.rb', line 168

def initialize(parent,tmpl,**opts)
  super
  @aliases = opts[:aliases] || []
  @erb_path = File.join(parent.tmpl_dir, tmpl+".c")
  DEFS.push(self)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ErbPP

Class Method Details

.codesObject



218
219
220
221
222
223
224
225
# File 'lib/erbpp.rb', line 218

def self.codes
  a = []
  DEFS.each do |i|
    x = i.code
    a.push(x) if x
  end
  a
end

.definitionsObject



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/erbpp.rb', line 227

def self.definitions
  a = []
  DEFS.each do |i|
    case x = i.definition
    when Array
      a.concat(x)
    when String
      a.push(x)
    else
      raise "unknown definition: #{x}" if x
    end
  end
  a
end

Instance Method Details

#c_funcObject Also known as: c_function, c_instance_method



189
190
191
192
193
194
195
196
197
# File 'lib/erbpp.rb', line 189

def c_func
  s = singleton ? "_s" : ""
  begin
    t = "_"+type_name
  rescue
    t = ""
  end
  "numo#{t}#{s}_#{method}"
end

#c_iterObject Also known as: c_iterator



179
180
181
182
183
184
185
186
# File 'lib/erbpp.rb', line 179

def c_iter
  begin
    t = "_"+type_name
  rescue
    t = ""
  end
  "iter#{t}_#{method}"
end

#c_methodObject



175
176
177
# File 'lib/erbpp.rb', line 175

def c_method
  "#{m_prefix}#{method}"
end

#codeObject



205
206
207
# File 'lib/erbpp.rb', line 205

def code
  result + "\n\n"
end

#definitionObject



209
210
211
212
213
214
215
216
# File 'lib/erbpp.rb', line 209

def definition
  s = singleton ? "_singleton" : ""
  check_params(:mod_var, :op_map, :c_func, :n_arg)
  m = op_map
  a = ["rb_define#{s}_method(#{mod_var}, \"#{m}\", #{c_func}, #{n_arg});"]
  @aliases.map{|x| a << "rb_define_alias(#{mod_var}, \"#{x}\", \"#{m}\");"}
  a
end

#id_opObject



156
157
158
159
160
161
162
# File 'lib/erbpp.rb', line 156

def id_op
  if op.size == 1
    "'#{op}'"
  else
    "id_#{method}"
  end
end

#methodObject



164
165
166
# File 'lib/erbpp.rb', line 164

def method
  meth.gsub(/\?/,"_p").gsub(/\!/,"_bang")
end

#op_mapObject



201
202
203
# File 'lib/erbpp.rb', line 201

def op_map
  @op || meth
end