Class: Rubber::C_GCRefPool

Inherits:
Object
  • Object
show all
Includes:
RegisterChildren
Defined in:
lib/rubber/codegen/gcrefpool.rb

Instance Attribute Summary

Attributes included from RegisterChildren

#child_names, #source_file, #source_line

Instance Method Summary collapse

Methods included from RegisterChildren

#cname, #register_children

Instance Method Details

#code(io) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rubber/codegen/gcrefpool.rb', line 5

def code(io)
  io.puts "static void _#{cname}_add(VALUE val)
  {
    if (#{cname} == Qnil)
    {
      #{cname} = rb_ary_new3(1, val);
    }
    else
    {
      rb_ary_push(#{cname}, val);
    }
  }
  
  static void _#{cname}_del(VALUE val)
  {
    if (#{cname} == Qnil)
    {
      rb_warn(\"Trying to remove object from empty GC queue #{name}\");
      return;
    }
    rb_ary_delete(#{cname}, val);
    // If nothing is referenced, don't keep an empty array in the pool...
    if (RARRAY_LEN(#{cname}) == 0)
      #{cname} = Qnil;
  }
  "
end

#declare(io) ⇒ Object


35
36
37
38
39
40
41
# File 'lib/rubber/codegen/gcrefpool.rb', line 35

def declare(io)
  io.puts "static VALUE #{cname} = Qnil;"
  io.puts "static void _#{cname}_add(VALUE val);"
  io.puts "static void _#{cname}_del(VALUE val);"
  io.puts "#define #{name.upcase}_ADD(val) _#{cname}_add(val)"
  io.puts "#define #{name.upcase}_DEL(val) _#{cname}_del(val)"
end

#default_cnameObject


43
44
45
# File 'lib/rubber/codegen/gcrefpool.rb', line 43

def default_cname
  "_gcpool_"+name
end

#doc_rd(io) ⇒ Object


46
47
48
# File 'lib/rubber/codegen/gcrefpool.rb', line 46

def doc_rd(io)
  # No doc 
end

#fullnameObject


49
50
# File 'lib/rubber/codegen/gcrefpool.rb', line 49

def fullname()
end

#parentObject


32
33
34
# File 'lib/rubber/codegen/gcrefpool.rb', line 32

def parent
 nil
end

#register(io, already_defined = false) ⇒ Object


51
52
53
# File 'lib/rubber/codegen/gcrefpool.rb', line 51

def register(io, already_defined=false)
  io.puts "rb_gc_register_address(&#{cname});"
end