Module: FastRuby::BuilderModule

Defined in:
lib/fastruby/builder.rb

Defined Under Namespace

Modules: MethodExtent

Instance Method Summary collapse

Instance Method Details

#build(signature, method_name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/fastruby/builder.rb', line 27

def build(signature, method_name)
  tree = self.method_tree[method_name]
  locals = self.method_locals[method_name]
  options = self.method_options[method_name]
  mname = "_" + method_name.to_s + signature.map(&:internal_value).map(&:to_s).join

  FastRuby.logger.info mname.to_s

  begin
    if (self.instance_method(mname))
      FastRuby.logger.info "NOT Building #{self}::#{method_name} for signature #{signature.inspect}, it's already done"
      return
    end
  rescue NameError
    FastRuby.logger.info "Building #{self}::#{method_name} for signature #{signature.inspect}"
  end

  context = FastRuby::Context.new
  context.locals = locals
  context.options = options

  args_tree = tree[2]

  # create random method name
  context.alt_method_name = mname

  (1..signature.size).each do |i|
    arg = args_tree[i]
    context.infer_lvar_map[arg] = signature[i]
  end

  context.infer_self = signature[0]

  c_code = context.to_c(tree)

  inline :C  do |builder|
    builder.inc << context.extra_code
    builder.include "<node.h>"
    builder.c c_code
  end


  ret = instance_method(mname)

  ret.extend MethodExtent
  ret.yield_signature = context.yield_signature

  ret
end

#method_localsObject



86
87
88
89
# File 'lib/fastruby/builder.rb', line 86

def method_locals
  @method_locals = Hash.new unless @method_locals
  @method_locals
end

#method_optionsObject



91
92
93
94
# File 'lib/fastruby/builder.rb', line 91

def method_options
  @method_options = Hash.new unless @method_options
  @method_options
end

#method_treeObject



81
82
83
84
# File 'lib/fastruby/builder.rb', line 81

def method_tree
  @method_tree = Hash.new unless @method_tree
  @method_tree
end